From 1d3090326210c6e6f7ec5432799ded25b75bba46 Mon Sep 17 00:00:00 2001
From: Hans Hagen
Date: Thu, 28 May 2009 11:23:00 +0200
Subject: beta 2009.05.28 11:23
---
context/data/cont-pe-scite.properties | 97 +
context/data/context-bbedit-pe.xml | 1 +
context/data/context-jedit-pe.xml | 2 +
context/data/context.properties | 30 +-
doc/context/bib/bibmod-doc.pdf | Bin 281102 -> 284752 bytes
doc/context/bib/bibmod-doc.tex | 8 +-
fonts/enc/dvips/context/lm-ec-os.enc | 258 -
fonts/enc/dvips/context/lm-qx-os.enc | 258 -
fonts/enc/dvips/context/lm-qxtt-os.enc | 258 -
fonts/enc/dvips/context/lm-t5-os.enc | 258 -
fonts/enc/dvips/context/lm-texnansi-os.enc | 258 -
fonts/enc/dvips/context/q-8r.enc | 264 +
fonts/map/dvips/context/contnav.map | 1 +
fonts/map/dvips/jmn/hans.map | 2 +
fonts/map/pdftex/context/cs-qbk.map | 15 -
fonts/map/pdftex/context/cs-qcs.map | 15 -
fonts/map/pdftex/context/cs-qpl.map | 15 -
fonts/map/pdftex/context/cs-qtm.map | 15 -
fonts/map/pdftex/context/ec-public-lm.map | 3 -
fonts/map/pdftex/context/ec-qbk.map | 15 -
fonts/map/pdftex/context/ec-qcs.map | 15 -
fonts/map/pdftex/context/ec-qpl.map | 15 -
fonts/map/pdftex/context/ec-qtm.map | 15 -
fonts/map/pdftex/context/el-public-lm.map | 3 -
fonts/map/pdftex/context/el-qbk.map | 15 -
fonts/map/pdftex/context/el-qcs.map | 15 -
fonts/map/pdftex/context/el-qpl.map | 15 -
fonts/map/pdftex/context/el-qtm.map | 15 -
fonts/map/pdftex/context/l7x-qbk.map | 15 -
fonts/map/pdftex/context/l7x-qcs.map | 15 -
fonts/map/pdftex/context/l7x-qpl.map | 15 -
fonts/map/pdftex/context/l7x-qtm.map | 15 -
fonts/map/pdftex/context/original-youngryu-px.map | 17 +-
fonts/map/pdftex/context/original-youngryu-tx.map | 31 +-
fonts/map/pdftex/context/qx-public-lm.map | 3 -
fonts/map/pdftex/context/qx-qbk.map | 15 -
fonts/map/pdftex/context/qx-qcs.map | 15 -
fonts/map/pdftex/context/qx-qpl.map | 15 -
fonts/map/pdftex/context/qx-qtm.map | 15 -
fonts/map/pdftex/context/rm-qbk.map | 15 -
fonts/map/pdftex/context/rm-qcs.map | 15 -
fonts/map/pdftex/context/rm-qpl.map | 15 -
fonts/map/pdftex/context/rm-qtm.map | 15 -
fonts/map/pdftex/context/t2a-qbk.map | 11 -
fonts/map/pdftex/context/t2a-qcs.map | 11 -
fonts/map/pdftex/context/t2a-qpl.map | 11 -
fonts/map/pdftex/context/t2a-qtm.map | 11 -
fonts/map/pdftex/context/t2b-qbk.map | 11 -
fonts/map/pdftex/context/t2b-qcs.map | 11 -
fonts/map/pdftex/context/t2b-qpl.map | 11 -
fonts/map/pdftex/context/t2b-qtm.map | 11 -
fonts/map/pdftex/context/t2c-qbk.map | 11 -
fonts/map/pdftex/context/t2c-qcs.map | 11 -
fonts/map/pdftex/context/t2c-qpl.map | 11 -
fonts/map/pdftex/context/t2c-qtm.map | 11 -
fonts/map/pdftex/context/t5-public-lm.map | 3 -
fonts/map/pdftex/context/t5-qbk.map | 15 -
fonts/map/pdftex/context/t5-qcs.map | 15 -
fonts/map/pdftex/context/t5-qpl.map | 15 -
fonts/map/pdftex/context/t5-qtm.map | 15 -
fonts/map/pdftex/context/texnansi-public-lm.map | 3 -
fonts/map/pdftex/context/texnansi-qbk.map | 15 -
fonts/map/pdftex/context/texnansi-qcs.map | 15 -
fonts/map/pdftex/context/texnansi-qpl.map | 15 -
fonts/map/pdftex/context/texnansi-qtm.map | 15 -
fonts/map/pdftex/context/ts1-qbk.map | 11 -
fonts/map/pdftex/context/ts1-qcs.map | 11 -
fonts/map/pdftex/context/ts1-qpl.map | 11 -
fonts/map/pdftex/context/ts1-qtm.map | 11 -
metapost/context/base/metafun.mp | 2 +
metapost/context/base/mp-chem.mp | 729 ++
metapost/context/base/mp-core.mp | 125 +-
metapost/context/base/mp-mlib.mp | 90 +-
metapost/context/base/mp-page.mp | 2 +-
metapost/context/base/mp-text.mp | 3 +-
metapost/context/base/mp-tool.mp | 58 +-
scripts/context/lua/luatools.lua | 8503 +++++++-------
scripts/context/lua/mtx-babel.lua | 18 +-
scripts/context/lua/mtx-cache.lua | 4 +-
scripts/context/lua/mtx-chars.lua | 306 +-
scripts/context/lua/mtx-check.lua | 43 +-
scripts/context/lua/mtx-context.lua | 979 +-
scripts/context/lua/mtx-convert.lua | 8 +-
scripts/context/lua/mtx-fonts.lua | 117 +-
scripts/context/lua/mtx-grep.lua | 106 +-
scripts/context/lua/mtx-interface.lua | 64 +-
scripts/context/lua/mtx-metatex.lua | 69 +
scripts/context/lua/mtx-mptopdf.lua | 24 +-
scripts/context/lua/mtx-package.lua | 68 +
scripts/context/lua/mtx-patterns.lua | 101 +-
scripts/context/lua/mtx-profile.lua | 164 +
scripts/context/lua/mtx-server-ctx-fonttest.lua | 681 ++
scripts/context/lua/mtx-server-ctx-help.lua | 648 ++
scripts/context/lua/mtx-server-ctx-startup.lua | 53 +
scripts/context/lua/mtx-server.lua | 132 +-
scripts/context/lua/mtx-timing.lua | 201 +
scripts/context/lua/mtx-unzip.lua | 101 +
scripts/context/lua/mtx-update.lua | 419 +-
scripts/context/lua/mtx-watch.lua | 24 +-
scripts/context/lua/mtxrun.lua | 12057 +++++++++++---------
scripts/context/lua/x-ldx.lua | 4 +-
scripts/context/ruby/base/exa.rb | 9 +-
scripts/context/ruby/base/file.rb | 7 +-
scripts/context/ruby/base/kpse.rb | 8 +-
scripts/context/ruby/base/state.rb | 4 +-
scripts/context/ruby/base/tex.rb | 176 +-
scripts/context/ruby/base/texutil.rb | 33 +-
scripts/context/ruby/base/tool.rb | 15 +-
scripts/context/ruby/ctxtools.rb | 4 +-
scripts/context/ruby/fcd_start.rb | 19 +-
scripts/context/ruby/graphics/gs.rb | 20 +-
scripts/context/ruby/pdftools.rb | 3 +-
scripts/context/ruby/rlxtools.rb | 3 +-
scripts/context/ruby/rsfiltool.rb | 3 +-
scripts/context/ruby/runtools.rb | 3 +-
scripts/context/ruby/texexec.rb | 8 +-
scripts/context/ruby/texmfstart.rb | 1261 +-
scripts/context/ruby/textools.rb | 3 +-
scripts/context/ruby/www/admin.rb | 215 -
scripts/context/ruby/www/common.rb | 80 -
scripts/context/ruby/www/dir.rb | 155 -
scripts/context/ruby/www/exa.rb | 387 -
scripts/context/ruby/www/lib.rb | 1405 ---
scripts/context/ruby/www/login.rb | 13 -
scripts/context/ruby/wwwclient.rb | 677 --
scripts/context/ruby/wwwserver.rb | 293 -
scripts/context/ruby/wwwwatch.rb | 497 -
scripts/context/stubs/mswin/ctxtools.bat | 5 +-
scripts/context/stubs/mswin/exatools.bat | 2 -
scripts/context/stubs/mswin/luatools.lua | 6977 +++++++++++
scripts/context/stubs/mswin/makempy.bat | 5 +-
scripts/context/stubs/mswin/metatex.cmd | 5 +
scripts/context/stubs/mswin/mpstools.bat | 5 +-
scripts/context/stubs/mswin/mptopdf.bat | 5 +-
scripts/context/stubs/mswin/mtxrun.lua | 10190 +++++++++++++++++
scripts/context/stubs/mswin/mtxtools.bat | 5 +
scripts/context/stubs/mswin/pdftools.bat | 5 +-
scripts/context/stubs/mswin/pdftrimwhite.bat | 2 -
scripts/context/stubs/mswin/pstopdf.bat | 5 +-
scripts/context/stubs/mswin/rlxtools.bat | 5 +-
scripts/context/stubs/mswin/runtools.bat | 5 +-
scripts/context/stubs/mswin/texexec.bat | 5 +-
scripts/context/stubs/mswin/texexec.cmd | 5 +
scripts/context/stubs/mswin/texfind.bat | 2 -
scripts/context/stubs/mswin/texfont.bat | 5 +-
scripts/context/stubs/mswin/texmfstart.cmd | 5 +
scripts/context/stubs/mswin/texshow.bat | 2 -
scripts/context/stubs/mswin/textools.bat | 5 +-
scripts/context/stubs/mswin/texutil.bat | 5 +-
scripts/context/stubs/mswin/tmftools.bat | 5 +-
scripts/context/stubs/mswin/xmltools.bat | 5 +-
scripts/context/stubs/unix/ctxtools | 2 +-
scripts/context/stubs/unix/exatools | 2 -
scripts/context/stubs/unix/luatools | 6977 +++++++++++
scripts/context/stubs/unix/makempy | 2 +-
scripts/context/stubs/unix/metatex | 2 +
scripts/context/stubs/unix/mpstools | 2 +-
scripts/context/stubs/unix/mptopdf | 2 +-
scripts/context/stubs/unix/mtxrun | 10190 +++++++++++++++++
scripts/context/stubs/unix/mtxtools | 2 +
scripts/context/stubs/unix/pdftools | 2 +-
scripts/context/stubs/unix/pdftrimwhite | 2 -
scripts/context/stubs/unix/pstopdf | 2 +-
scripts/context/stubs/unix/rlxtools | 2 +-
scripts/context/stubs/unix/runtools | 2 +-
scripts/context/stubs/unix/texexec | 2 +-
scripts/context/stubs/unix/texfind | 2 -
scripts/context/stubs/unix/texfont | 2 +-
scripts/context/stubs/unix/texmfstart | 2 +
scripts/context/stubs/unix/texshow | 2 -
scripts/context/stubs/unix/textools | 2 +-
scripts/context/stubs/unix/texutil | 2 +-
scripts/context/stubs/unix/tmftools | 2 +-
scripts/context/stubs/unix/xmltools | 2 +-
tex/context/base/attr-ini.lua | 853 +-
tex/context/base/attr-ini.tex | 163 +-
tex/context/base/back-ini.lua | 75 +
tex/context/base/back-ini.tex | 896 ++
tex/context/base/back-pdf.lua | 189 +
tex/context/base/back-pdf.tex | 3226 ++++++
tex/context/base/bibl-bib.lua | 233 +
tex/context/base/bibl-bib.tex | 29 +
tex/context/base/bibl-tst.lua | 21 +
tex/context/base/catc-act.tex | 61 +
tex/context/base/catc-ctx.tex | 207 +
tex/context/base/catc-def.tex | 142 +
tex/context/base/catc-ini.lua | 28 +
tex/context/base/catc-ini.mkii | 229 +
tex/context/base/catc-ini.mkiv | 255 +
tex/context/base/catc-sym.tex | 118 +
tex/context/base/char-cmp.lua | 2 +
tex/context/base/char-def.lua | 1248 +-
tex/context/base/char-enc.lua | 163 +
tex/context/base/char-enc.tex | 18 +
tex/context/base/char-ini.lua | 619 +-
tex/context/base/char-ini.tex | 40 +-
tex/context/base/char-map.lua | 19 +-
tex/context/base/char-syn.lua | 140 -
tex/context/base/char-utf.lua | 146 +-
tex/context/base/char-utf.tex | 26 +-
tex/context/base/chem-ini.lua | 74 +
tex/context/base/chem-ini.mkiv | 42 +
tex/context/base/chem-str-test.tex | 560 +
tex/context/base/chem-str.lua | 488 +
tex/context/base/chem-str.mkiv | 526 +
tex/context/base/colo-ext.mkii | 57 +
tex/context/base/colo-ext.mkiv | 57 +
tex/context/base/colo-ext.tex | 57 -
tex/context/base/colo-hex.mkii | 115 +
tex/context/base/colo-hex.mkiv | 115 +
tex/context/base/colo-hex.tex | 120 +-
tex/context/base/colo-ini.lua | 181 +-
tex/context/base/colo-ini.mkii | 922 +-
tex/context/base/colo-ini.mkiv | 983 +-
tex/context/base/colo-ini.tex | 1051 --
tex/context/base/colo-run.tex | 3 +-
tex/context/base/cont-cs.tex | 10 +-
tex/context/base/cont-de.tex | 10 +-
tex/context/base/cont-en.tex | 8 +-
tex/context/base/cont-fil.tex | 2 +-
tex/context/base/cont-fr.tex | 10 +-
tex/context/base/cont-gb.tex | 10 +-
tex/context/base/cont-it.tex | 10 +-
tex/context/base/cont-log.tex | 71 +-
tex/context/base/cont-new.mkiv | 88 +-
tex/context/base/cont-new.tex | 100 +-
tex/context/base/cont-nl.tex | 10 +-
tex/context/base/cont-old.tex | 2 +-
tex/context/base/cont-pe.tex | 10 +-
tex/context/base/cont-ro.tex | 10 +-
tex/context/base/cont-sys.ori | 9 +-
tex/context/base/cont-usr.ori | 2 +-
tex/context/base/context-base.lmx | 38 +
tex/context/base/context-characters.lmx | 66 +-
tex/context/base/context-debug.lmx | 66 +-
tex/context/base/context-error.lmx | 46 +-
tex/context/base/context-fonttest.lmx | 47 +
tex/context/base/context-help.lmx | 88 +
tex/context/base/context-timing.lmx | 52 +
tex/context/base/context.css | 15 +
tex/context/base/context.mkii | 198 +-
tex/context/base/context.mkiv | 422 +-
tex/context/base/context.rme | 85 +
tex/context/base/context.tex | 15 +-
tex/context/base/core-bar.tex | 2 +-
tex/context/base/core-blk.lua | 145 -
tex/context/base/core-blk.mkiv | 109 -
tex/context/base/core-blk.tex | 130 +-
tex/context/base/core-box.tex | 3 +-
tex/context/base/core-buf.lua | 194 +-
tex/context/base/core-buf.mkii | 326 +-
tex/context/base/core-buf.mkiv | 308 +-
tex/context/base/core-buf.tex | 250 -
tex/context/base/core-con.lua | 281 +-
tex/context/base/core-con.mkii | 775 +-
tex/context/base/core-con.mkiv | 831 +-
tex/context/base/core-con.tex | 744 --
tex/context/base/core-ctx.lua | 41 +-
tex/context/base/core-ctx.mkii | 2 +-
tex/context/base/core-ctx.mkiv | 3 +-
tex/context/base/core-ctx.tex | 22 -
tex/context/base/core-dat.tex | 66 +-
tex/context/base/core-def.mkii | 77 +
tex/context/base/core-def.mkiv | 74 +
tex/context/base/core-def.tex | 27 -
tex/context/base/core-des.tex | 7 +-
tex/context/base/core-env.mkii | 543 +
tex/context/base/core-env.mkiv | 472 +
tex/context/base/core-fig.tex | 4 +-
tex/context/base/core-fil.tex | 56 +-
tex/context/base/core-fld.mkii | 1080 ++
tex/context/base/core-fld.mkiv | 1079 ++
tex/context/base/core-fld.tex | 1080 --
tex/context/base/core-fnt.mkii | 726 ++
tex/context/base/core-fnt.mkiv | 498 +
tex/context/base/core-fnt.tex | 726 --
tex/context/base/core-gen.tex | 137 +-
tex/context/base/core-grd.tex | 2 +-
tex/context/base/core-inc.lua | 608 +-
tex/context/base/core-inc.mkii | 95 +-
tex/context/base/core-inc.mkiv | 12 +-
tex/context/base/core-inc.tex | 18 -
tex/context/base/core-ini.tex | 2 +-
tex/context/base/core-ins.tex | 42 +-
tex/context/base/core-int.mkii | 2217 ++++
tex/context/base/core-int.mkiv | 2036 ++++
tex/context/base/core-int.tex | 2355 ----
tex/context/base/core-itm.tex | 36 +-
tex/context/base/core-job.lua | 154 +-
tex/context/base/core-job.mkii | 316 +-
tex/context/base/core-job.mkiv | 333 +-
tex/context/base/core-job.tex | 368 -
tex/context/base/core-lme.tex | 2 +-
tex/context/base/core-lnt.tex | 2 +-
tex/context/base/core-lst.tex | 3 +-
tex/context/base/core-ltb.tex | 856 --
tex/context/base/core-mak.tex | 2 +-
tex/context/base/core-mar.tex | 5 +-
tex/context/base/core-mat.tex | 60 +-
tex/context/base/core-mis.mkii | 2676 +++++
tex/context/base/core-mis.mkiv | 2606 +++++
tex/context/base/core-mis.tex | 2733 -----
tex/context/base/core-nav.mkii | 379 +
tex/context/base/core-nav.mkiv | 425 +
tex/context/base/core-nav.tex | 379 -
tex/context/base/core-new.tex | 304 -
tex/context/base/core-not.tex | 8 +-
tex/context/base/core-ntb.tex | 1573 ---
tex/context/base/core-num.tex | 2 +-
tex/context/base/core-obj.lua | 7 +-
tex/context/base/core-obj.mkii | 309 +-
tex/context/base/core-obj.mkiv | 220 +-
tex/context/base/core-obj.tex | 365 -
tex/context/base/core-par.tex | 2 +-
tex/context/base/core-pgr.tex | 12 +-
tex/context/base/core-pos.lua | 4 +-
tex/context/base/core-pos.mkii | 759 +-
tex/context/base/core-pos.mkiv | 789 +-
tex/context/base/core-pos.tex | 767 --
tex/context/base/core-ref.lua | 106 -
tex/context/base/core-ref.mkii | 90 -
tex/context/base/core-ref.mkiv | 107 -
tex/context/base/core-ref.tex | 261 +-
tex/context/base/core-reg.lua | 186 -
tex/context/base/core-reg.mkii | 33 -
tex/context/base/core-reg.mkiv | 40 -
tex/context/base/core-reg.tex | 55 +-
tex/context/base/core-rul.lua | 1 -
tex/context/base/core-rul.mkii | 3562 ++++++
tex/context/base/core-rul.mkiv | 3635 +++++-
tex/context/base/core-rul.tex | 3590 ------
tex/context/base/core-sec.mkii | 2620 -----
tex/context/base/core-sec.mkiv | 2621 -----
tex/context/base/core-sec.tex | 2572 +++++
tex/context/base/core-snc.tex | 4 +-
tex/context/base/core-spa.lua | 1979 +---
tex/context/base/core-spa.mkii | 4648 +++++++-
tex/context/base/core-spa.mkiv | 4176 ++++++-
tex/context/base/core-spa.tex | 4637 --------
tex/context/base/core-stg.tex | 4 +-
tex/context/base/core-syn.lua | 127 -
tex/context/base/core-syn.mkii | 28 -
tex/context/base/core-syn.mkiv | 34 -
tex/context/base/core-syn.tex | 42 +-
tex/context/base/core-sys.mkii | 384 +-
tex/context/base/core-sys.mkiv | 373 +-
tex/context/base/core-sys.tex | 401 -
tex/context/base/core-tab.tex | 2499 ----
tex/context/base/core-tbl.tex | 1436 ---
tex/context/base/core-trf.tex | 28 +-
tex/context/base/core-tsp.tex | 427 -
tex/context/base/core-two.lua | 20 +-
tex/context/base/core-two.mkii | 65 +-
tex/context/base/core-two.mkiv | 77 +-
tex/context/base/core-two.tex | 103 -
tex/context/base/core-uti.lua | 253 +-
tex/context/base/core-uti.mkii | 305 +-
tex/context/base/core-uti.mkiv | 95 +-
tex/context/base/core-uti.tex | 382 -
tex/context/base/core-var.tex | 568 +-
tex/context/base/core-ver.mkii | 1124 +-
tex/context/base/core-ver.mkiv | 1084 +-
tex/context/base/core-ver.tex | 1120 --
tex/context/base/core-vis.tex | 32 +-
tex/context/base/data-aux.lua | 57 +
tex/context/base/data-bin.lua | 26 +
tex/context/base/data-con.lua | 122 +
tex/context/base/data-crl.lua | 58 +
tex/context/base/data-ctx.lua | 29 +
tex/context/base/data-gen.lua | 9 +
tex/context/base/data-inp.lua | 15 +
tex/context/base/data-kps.lua | 101 +
tex/context/base/data-lst.lua | 58 +
tex/context/base/data-lua.lua | 55 +
tex/context/base/data-out.lua | 10 +
tex/context/base/data-pre.lua | 90 +
tex/context/base/data-res.lua | 2029 ++++
tex/context/base/data-tex.lua | 220 +
tex/context/base/data-tmf.lua | 72 +
tex/context/base/data-tmp.lua | 174 +
tex/context/base/data-tre.lua | 43 +
tex/context/base/data-use.lua | 127 +
tex/context/base/data-zip.lua | 241 +
tex/context/base/enco-cyr.tex | 2 +
tex/context/base/enco-def.tex | 6 +-
tex/context/base/enco-fpl.tex | 2 +-
tex/context/base/enco-ini.mkii | 1125 +-
tex/context/base/enco-ini.mkiv | 583 +-
tex/context/base/enco-ini.tex | 1228 --
tex/context/base/enco-mis.tex | 37 -
tex/context/base/enco-pfr.mkii | 20 -
tex/context/base/enco-pfr.mkiv | 22 -
tex/context/base/enco-pfr.tex | 18 +-
tex/context/base/enco-run.tex | 52 +-
tex/context/base/enco-t5.tex | 4 +-
tex/context/base/enco-utf.tex | 3126 -----
tex/context/base/enco-x5.tex | 34 +-
tex/context/base/filt-ini.tex | 62 +-
tex/context/base/font-afm.lua | 344 +-
tex/context/base/font-bfm.tex | 2 +-
tex/context/base/font-chi.tex | 2 +-
tex/context/base/font-chk.lua | 80 +
tex/context/base/font-cid.lua | 143 +
tex/context/base/font-col.lua | 98 +-
tex/context/base/font-col.mkiv | 146 +
tex/context/base/font-col.tex | 148 -
tex/context/base/font-ctx.lua | 387 +
tex/context/base/font-def.lua | 624 +-
tex/context/base/font-dum.lua | 113 +
tex/context/base/font-enc.lua | 16 +-
tex/context/base/font-ext.lua | 304 +-
tex/context/base/font-fbk.lua | 102 +-
tex/context/base/font-ini.lua | 53 +-
tex/context/base/font-ini.mkii | 671 +-
tex/context/base/font-ini.mkiv | 2515 ++--
tex/context/base/font-jap.tex | 2 +-
tex/context/base/font-log.lua | 53 +
tex/context/base/font-map.lua | 32 +-
tex/context/base/font-mis.lua | 91 +
tex/context/base/font-ota.lua | 320 +
tex/context/base/font-otb.lua | 364 +
tex/context/base/font-otc.lua | 238 +
tex/context/base/font-otd.lua | 78 +
tex/context/base/font-otf.lua | 5983 ++--------
tex/context/base/font-oti.lua | 57 +
tex/context/base/font-otn.lua | 2496 ++++
tex/context/base/font-otp.lua | 420 +
tex/context/base/font-ott.lua | 935 ++
tex/context/base/font-pat.lua | 53 +-
tex/context/base/font-run.tex | 3 +-
tex/context/base/font-syn.lua | 417 +-
tex/context/base/font-tfm.lua | 977 +-
tex/context/base/font-tra.mkiv | 113 +
tex/context/base/font-uni.mkii | 444 +
tex/context/base/font-uni.mkiv | 26 +
tex/context/base/font-uni.tex | 465 -
tex/context/base/font-unk.mkii | 187 +
tex/context/base/font-unk.mkiv | 162 +
tex/context/base/font-unk.tex | 185 -
tex/context/base/font-vf.lua | 72 +-
tex/context/base/font-xtx.lua | 115 +
tex/context/base/font-xtx.tex | 357 +
tex/context/base/hand-ini.mkii | 91 +-
tex/context/base/hand-ini.mkiv | 2 +-
tex/context/base/hand-ini.tex | 18 -
tex/context/base/java-ini.mkii | 713 ++
tex/context/base/java-ini.mkiv | 688 ++
tex/context/base/java-ini.tex | 742 --
tex/context/base/l-aux.lua | 128 +-
tex/context/base/l-boolean.lua | 17 +-
tex/context/base/l-dimen.lua | 13 +-
tex/context/base/l-dir.lua | 447 +-
tex/context/base/l-file.lua | 142 +-
tex/context/base/l-io.lua | 211 +-
tex/context/base/l-lpeg.lua | 58 +-
tex/context/base/l-math.lua | 30 +-
tex/context/base/l-md5.lua | 78 +-
tex/context/base/l-number.lua | 27 +-
tex/context/base/l-os.lua | 88 +-
tex/context/base/l-set.lua | 87 +-
tex/context/base/l-string.lua | 270 +-
tex/context/base/l-table.lua | 328 +-
tex/context/base/l-unicode.lua | 79 +-
tex/context/base/l-url.lua | 54 +-
tex/context/base/l-utils.lua | 62 +-
tex/context/base/l-xml.lua | 134 +-
tex/context/base/lang-alt.tex | 5 +-
tex/context/base/lang-ana.tex | 6 +-
tex/context/base/lang-ara.tex | 5 +-
tex/context/base/lang-art.tex | 6 +-
tex/context/base/lang-bal.tex | 6 +-
tex/context/base/lang-cel.tex | 6 +-
tex/context/base/lang-chi.tex | 6 +-
tex/context/base/lang-cjk.tex | 328 +
tex/context/base/lang-ctx.tex | 37 +-
tex/context/base/lang-cyr.tex | 14 +-
tex/context/base/lang-dis.tex | 8 +-
tex/context/base/lang-frq.tex | 4 +-
tex/context/base/lang-ger.tex | 44 +-
tex/context/base/lang-grk.tex | 9 +-
tex/context/base/lang-ind.tex | 2 +-
tex/context/base/lang-ini.lua | 131 +-
tex/context/base/lang-ini.mkii | 588 +-
tex/context/base/lang-ini.mkiv | 565 +-
tex/context/base/lang-ini.tex | 692 --
tex/context/base/lang-ita.tex | 57 +-
tex/context/base/lang-jap.tex | 5 +-
tex/context/base/lang-lab.mkii | 295 +
tex/context/base/lang-lab.mkiv | 266 +
tex/context/base/lang-lab.tex | 284 -
tex/context/base/lang-mis.tex | 6 +-
tex/context/base/lang-sla.tex | 23 +-
tex/context/base/lang-spa.tex | 2 +-
tex/context/base/lang-spe.mkii | 244 +
tex/context/base/lang-spe.mkiv | 111 +
tex/context/base/lang-spe.tex | 242 -
tex/context/base/lang-ura.tex | 6 +-
tex/context/base/lang-url.lua | 10 +-
tex/context/base/lang-url.mkii | 74 +
tex/context/base/lang-url.mkiv | 50 +-
tex/context/base/lang-url.tex | 70 -
tex/context/base/lang-vn.tex | 5 +-
tex/context/base/luat-bas.tex | 64 +
tex/context/base/luat-cbk.lua | 13 +-
tex/context/base/luat-cnf.lua | 114 +
tex/context/base/luat-cod.tex | 161 +
tex/context/base/luat-crl.lua | 53 -
tex/context/base/luat-deb.lua | 154 -
tex/context/base/luat-deb.tex | 49 -
tex/context/base/luat-dum.lua | 60 +
tex/context/base/luat-env.lua | 304 +-
tex/context/base/luat-env.tex | 172 -
tex/context/base/luat-exe.lua | 13 +-
tex/context/base/luat-fio.lua | 81 +
tex/context/base/luat-ini.lua | 129 +-
tex/context/base/luat-ini.tex | 222 +-
tex/context/base/luat-inp.lua | 2300 ----
tex/context/base/luat-iop.lua | 18 +-
tex/context/base/luat-kps.lua | 102 -
tex/context/base/luat-lib.lua | 174 -
tex/context/base/luat-lib.tex | 86 +-
tex/context/base/luat-lmx.lua | 141 -
tex/context/base/luat-lmx.tex | 16 -
tex/context/base/luat-log.lua | 155 -
tex/context/base/luat-lua.lua | 2 +-
tex/context/base/luat-run.lua | 69 +
tex/context/base/luat-soc.lua | 11 +
tex/context/base/luat-sta.lua | 44 +-
tex/context/base/luat-sto.lua | 134 +
tex/context/base/luat-tex.lua | 588 -
tex/context/base/luat-tmp.lua | 433 -
tex/context/base/luat-tra.lua | 145 -
tex/context/base/luat-tre.lua | 45 -
tex/context/base/luat-uni.lua | 21 -
tex/context/base/luat-uni.tex | 33 -
tex/context/base/luat-zip.lua | 249 -
tex/context/base/lxml-ent.lua | 115 +
tex/context/base/lxml-ini.lua | 588 +-
tex/context/base/lxml-ini.tex | 71 +-
tex/context/base/lxml-mis.lua | 106 +
tex/context/base/lxml-pth.lua | 1555 +++
tex/context/base/lxml-tab.lua | 783 ++
tex/context/base/m-arabtex.tex | 2 +-
tex/context/base/m-chemic.mkii | 21 +
tex/context/base/m-chemic.mkiv | 19 +
tex/context/base/m-chemic.tex | 10 +-
tex/context/base/m-database.tex | 2 +-
tex/context/base/m-educat.tex | 33 -
tex/context/base/m-gamma.tex | 230 -
tex/context/base/m-mkii.mkiv | 21 +
tex/context/base/m-newmat.tex | 14 +-
tex/context/base/m-pictex.tex | 11 +-
tex/context/base/m-subsub.tex | 47 -
tex/context/base/m-timing.tex | 197 +-
tex/context/base/m-track.tex | 5 +
tex/context/base/m-translate.tex | 6 +-
tex/context/base/m-visual.tex | 1 -
tex/context/base/math-ali.mkiv | 1059 ++
tex/context/base/math-ams.tex | 4 +-
tex/context/base/math-arr.mkii | 391 +
tex/context/base/math-arr.mkiv | 439 +
tex/context/base/math-def.mkiv | 338 +
tex/context/base/math-del.mkiv | 63 +
tex/context/base/math-dim.lua | 310 +
tex/context/base/math-dis.mkiv | 20 +
tex/context/base/math-ext.lua | 143 +
tex/context/base/math-ext.tex | 437 -
tex/context/base/math-for.mkiv | 73 +
tex/context/base/math-frc.mkii | 66 +
tex/context/base/math-frc.mkiv | 209 +
tex/context/base/math-ini.lua | 637 +-
tex/context/base/math-ini.mkii | 679 +-
tex/context/base/math-ini.mkiv | 544 +-
tex/context/base/math-ini.tex | 688 --
tex/context/base/math-inl.mkiv | 357 +
tex/context/base/math-int.mkiv | 87 +
tex/context/base/math-lbr.tex | 8 +-
tex/context/base/math-map.lua | 365 +
tex/context/base/math-mis.tex | 49 -
tex/context/base/math-noa.lua | 336 +
tex/context/base/math-pln.mkii | 360 +
tex/context/base/math-pln.mkiv | 298 +
tex/context/base/math-pln.tex | 355 -
tex/context/base/math-run.mkii | 97 +
tex/context/base/math-run.tex | 95 -
tex/context/base/math-scr.mkiv | 215 +
tex/context/base/math-tex.tex | 23 +-
tex/context/base/math-tim.tex | 106 +-
tex/context/base/math-vfu.lua | 1534 +++
tex/context/base/meta-ini.mkii | 91 +-
tex/context/base/meta-ini.mkiv | 431 +-
tex/context/base/meta-pdf.lua | 737 +-
tex/context/base/meta-pdf.mkii | 936 +-
tex/context/base/meta-pdf.mkiv | 833 +-
tex/context/base/meta-pdf.tex | 1020 --
tex/context/base/meta-pdh.lua | 630 +
tex/context/base/meta-tex.mkii | 2 +-
tex/context/base/metatex.tex | 145 +
tex/context/base/mlib-ctx.lua | 16 +-
tex/context/base/mlib-pdf.lua | 209 +-
tex/context/base/mlib-pdf.tex | 6 +-
tex/context/base/mlib-pps.lua | 177 +-
tex/context/base/mlib-pps.tex | 16 +-
tex/context/base/mlib-run.lua | 161 +-
tex/context/base/mtx-context-arrange.tex | 105 +
tex/context/base/mtx-context-combine.tex | 146 +
tex/context/base/mtx-context-ideas.tex | 54 +
tex/context/base/mtx-context-listing.tex | 76 +
tex/context/base/mtx-context-timing.tex | 46 +
tex/context/base/mult-chk.lua | 66 +
tex/context/base/mult-chk.mkii | 26 +
tex/context/base/mult-chk.mkiv | 103 +
tex/context/base/mult-de.tex | 57 +
tex/context/base/mult-def.lua | 270 +-
tex/context/base/mult-def.tex | 10 +-
tex/context/base/mult-en.tex | 57 +
tex/context/base/mult-fr.tex | 57 +
tex/context/base/mult-his.tex | 19 +-
tex/context/base/mult-ini.lua | 31 +-
tex/context/base/mult-ini.mkii | 15 +-
tex/context/base/mult-ini.mkiv | 34 +-
tex/context/base/mult-it.tex | 57 +
tex/context/base/mult-mcs.tex | 198 +
tex/context/base/mult-mde.tex | 198 +
tex/context/base/mult-men.tex | 198 +
tex/context/base/mult-mes.lua | 2005 ++++
tex/context/base/mult-mfr.tex | 198 +
tex/context/base/mult-mit.tex | 198 +
tex/context/base/mult-mnl.tex | 198 +
tex/context/base/mult-mno.tex | 198 +
tex/context/base/mult-mpe.tex | 198 +
tex/context/base/mult-mro.tex | 198 +
tex/context/base/mult-nl.tex | 57 +
tex/context/base/mult-ro.tex | 57 +
tex/context/base/mult-sys.tex | 116 +-
tex/context/base/node-dum.lua | 24 +
tex/context/base/node-ext.lua | 30 +
tex/context/base/node-fin.lua | 363 +
tex/context/base/node-fin.tex | 78 +
tex/context/base/node-fnt.lua | 206 +
tex/context/base/node-ini.lua | 1254 +-
tex/context/base/node-ini.tex | 59 +-
tex/context/base/node-inj.lua | 608 +
tex/context/base/node-par.lua | 2 +-
tex/context/base/node-par.tex | 6 +-
tex/context/base/node-pro.lua | 155 +
tex/context/base/node-res.lua | 110 +
tex/context/base/node-seq.lua | 47 +-
tex/context/base/node-ser.lua | 274 +
tex/context/base/node-shp.lua | 66 +
tex/context/base/node-tex.lua | 54 +
tex/context/base/node-tra.lua | 399 +
tex/context/base/node-tsk.lua | 113 +
tex/context/base/node-tst.lua | 108 +
tex/context/base/norm-alo.tex | 36 +
tex/context/base/norm-ctx.tex | 16 +
tex/context/base/norm-etx.tex | 79 +
tex/context/base/norm-ltx.tex | 177 +
tex/context/base/norm-ptx.tex | 130 +
tex/context/base/norm-tex.tex | 351 +
tex/context/base/norm-xtx.tex | 18 +
tex/context/base/page-app.tex | 4 +-
tex/context/base/page-bck.mkii | 593 +
tex/context/base/page-bck.mkiv | 521 +
tex/context/base/page-bck.tex | 615 -
tex/context/base/page-flt.tex | 460 +-
tex/context/base/page-flw.tex | 4 +-
tex/context/base/page-imp.tex | 29 +-
tex/context/base/page-ini.mkii | 1555 +++
tex/context/base/page-ini.mkiv | 1549 +++
tex/context/base/page-ini.tex | 2034 ----
tex/context/base/page-lay.tex | 5 +-
tex/context/base/page-lin.lua | 299 +-
tex/context/base/page-lin.mkii | 2 +-
tex/context/base/page-lin.mkiv | 16 +-
tex/context/base/page-log.tex | 34 +-
tex/context/base/page-lyr.tex | 8 +-
tex/context/base/page-mak.tex | 9 +-
tex/context/base/page-mar.tex | 10 +-
tex/context/base/page-mis.tex | 268 +
tex/context/base/page-mul.tex | 8 +-
tex/context/base/page-not.tex | 2 +-
tex/context/base/page-num.tex | 15 +-
tex/context/base/page-one.mkii | 659 ++
tex/context/base/page-one.mkiv | 662 ++
tex/context/base/page-one.tex | 659 --
tex/context/base/page-par.tex | 4 +-
tex/context/base/page-plg.tex | 4 +-
tex/context/base/page-run.tex | 2 +-
tex/context/base/page-set.tex | 24 +-
tex/context/base/page-sid.tex | 4 +-
tex/context/base/page-spr.tex | 2 +-
tex/context/base/page-str.tex | 6 +-
tex/context/base/page-txt.mkii | 784 ++
tex/context/base/page-txt.mkiv | 808 ++
tex/context/base/page-txt.tex | 784 --
tex/context/base/ppchtex.mkii | 3457 ++++++
tex/context/base/ppchtex.mkiv | 3359 ++++++
tex/context/base/ppchtex.tex | 3438 ------
tex/context/base/prop-ini.mkii | 150 +
tex/context/base/prop-ini.mkiv | 150 +
tex/context/base/prop-ini.tex | 151 -
tex/context/base/prop-lay.mkii | 99 +
tex/context/base/prop-lay.mkiv | 109 +-
tex/context/base/prop-lay.tex | 105 -
tex/context/base/prop-mis.mkii | 34 +
tex/context/base/prop-mis.mkiv | 34 +
tex/context/base/prop-mis.tex | 53 -
tex/context/base/prop-run.tex | 39 -
tex/context/base/regi-ini.lua | 88 +-
tex/context/base/regi-ini.mkii | 167 +-
tex/context/base/regi-ini.mkiv | 54 +-
tex/context/base/regi-ini.tex | 182 -
tex/context/base/regi-syn.tex | 2 +-
tex/context/base/regi-utf.tex | 12 +-
tex/context/base/s-fnt-01.tex | 4 +-
tex/context/base/s-fnt-10.tex | 100 +-
tex/context/base/s-fnt-11.tex | 61 +
tex/context/base/s-fnt-20.tex | 140 +
tex/context/base/s-fnt-21.tex | 46 +
tex/context/base/s-fnt-23.tex | 272 +
tex/context/base/s-fnt-24.tex | 83 +
tex/context/base/s-fnt-25.tex | 162 +
tex/context/base/s-fnt-30.tex | 42 +
tex/context/base/s-pre-60.tex | 46 +-
tex/context/base/s-pre-61.tex | 14 +-
tex/context/base/s-pre-62.tex | 20 +-
tex/context/base/s-pre-66.tex | 133 +
tex/context/base/s-pre-71.tex | 8 +-
tex/context/base/s-reg-01.tex | 50 +
tex/context/base/scrp-cjk.lua | 576 +
tex/context/base/scrp-ini.lua | 386 +
tex/context/base/scrp-ini.tex | 91 +
tex/context/base/sort-def.mkii | 450 -
tex/context/base/sort-def.mkiv | 16 -
tex/context/base/sort-def.tex | 432 +-
tex/context/base/sort-ini.lua | 135 +-
tex/context/base/sort-ini.mkii | 16 +-
tex/context/base/sort-ini.mkiv | 8 +-
tex/context/base/sort-ini.tex | 32 -
tex/context/base/sort-lan.lua | 19 +-
tex/context/base/sort-lan.mkii | 203 -
tex/context/base/sort-lan.mkiv | 16 -
tex/context/base/sort-lan.tex | 189 +-
tex/context/base/spec-def.mkii | 20 -
tex/context/base/spec-def.mkiv | 23 -
tex/context/base/spec-def.tex | 8 +-
tex/context/base/spec-dpx.tex | 4 +-
tex/context/base/spec-fdf.mkii | 146 -
tex/context/base/spec-fdf.mkiv | 31 -
tex/context/base/spec-fdf.tex | 205 +-
tex/context/base/spec-ini.tex | 154 +-
tex/context/base/spec-mis.tex | 26 +-
tex/context/base/spec-pdf.lua | 67 -
tex/context/base/spec-tpd.mkii | 18 -
tex/context/base/spec-tpd.mkiv | 37 -
tex/context/base/spec-tpd.tex | 40 +-
tex/context/base/spec-var.tex | 2 +-
tex/context/base/strc-bkm.lua | 133 +
tex/context/base/strc-bkm.tex | 90 +
tex/context/base/strc-blk.lua | 145 +
tex/context/base/strc-blk.tex | 110 +
tex/context/base/strc-def.tex | 302 +
tex/context/base/strc-des.lua | 9 +
tex/context/base/strc-des.tex | 1018 ++
tex/context/base/strc-doc.lua | 569 +
tex/context/base/strc-doc.tex | 166 +
tex/context/base/strc-flt.lua | 9 +
tex/context/base/strc-flt.tex | 2173 ++++
tex/context/base/strc-ini.lua | 276 +
tex/context/base/strc-ini.tex | 88 +
tex/context/base/strc-itm.lua | 24 +
tex/context/base/strc-itm.tex | 1195 ++
tex/context/base/strc-lst.lua | 392 +
tex/context/base/strc-lst.tex | 944 ++
tex/context/base/strc-mar.lua | 18 +
tex/context/base/strc-mar.tex | 493 +
tex/context/base/strc-mat.lua | 51 +
tex/context/base/strc-mat.tex | 933 ++
tex/context/base/strc-not.lua | 248 +
tex/context/base/strc-not.tex | 1154 ++
tex/context/base/strc-num.lua | 457 +
tex/context/base/strc-num.tex | 440 +
tex/context/base/strc-pag.lua | 206 +
tex/context/base/strc-pag.tex | 506 +
tex/context/base/strc-prc.lua | 9 +
tex/context/base/strc-prc.tex | 84 +
tex/context/base/strc-ref.lua | 875 ++
tex/context/base/strc-ref.tex | 1905 ++++
tex/context/base/strc-reg.lua | 578 +
tex/context/base/strc-reg.tex | 907 ++
tex/context/base/strc-ren.tex | 467 +
tex/context/base/strc-sbe.tex | 137 +
tex/context/base/strc-sec.tex | 667 ++
tex/context/base/strc-syn.lua | 185 +
tex/context/base/strc-syn.tex | 392 +
tex/context/base/strc-xml.tex | 87 +
tex/context/base/supp-box.tex | 357 +-
tex/context/base/supp-dir.mkii | 41 +
tex/context/base/supp-dir.mkiv | 21 +
tex/context/base/supp-dir.tex | 70 -
tex/context/base/supp-eps.tex | 2 +-
tex/context/base/supp-fil.lua | 49 +-
tex/context/base/supp-fil.mkii | 621 +-
tex/context/base/supp-fil.mkiv | 616 +-
tex/context/base/supp-fil.tex | 655 --
tex/context/base/supp-fun.tex | 10 +-
tex/context/base/supp-ini.tex | 18 -
tex/context/base/supp-lan.tex | 4 +-
tex/context/base/supp-mat.tex | 13 +-
tex/context/base/supp-mis.tex | 3 +-
tex/context/base/supp-mpe.tex | 2 +-
tex/context/base/supp-mps.tex | 24 +-
tex/context/base/supp-mrk.tex | 27 +-
tex/context/base/supp-num.tex | 31 +-
tex/context/base/supp-pat.tex | 6 +-
tex/context/base/supp-pdf.tex | 2 +-
tex/context/base/supp-ran.lua | 46 +
tex/context/base/supp-ran.mkii | 122 +
tex/context/base/supp-ran.mkiv | 30 +
tex/context/base/supp-ran.tex | 158 -
tex/context/base/supp-spe.tex | 94 +-
tex/context/base/supp-tpi.tex | 6 +-
tex/context/base/supp-vis.tex | 48 +-
tex/context/base/symb-ini.tex | 42 +-
tex/context/base/symb-jmn.tex | 1 -
tex/context/base/symb-mis.tex | 7 +-
tex/context/base/syst-aux.tex | 6841 +++++++++++
tex/context/base/syst-cat.mkii | 61 -
tex/context/base/syst-cat.mkiv | 124 -
tex/context/base/syst-cat.tex | 517 -
tex/context/base/syst-chr.tex | 131 -
tex/context/base/syst-con.lua | 28 +-
tex/context/base/syst-con.mkii | 109 +-
tex/context/base/syst-con.mkiv | 132 +-
tex/context/base/syst-con.tex | 144 -
tex/context/base/syst-etx.tex | 298 -
tex/context/base/syst-ext.tex | 165 +-
tex/context/base/syst-fnt.mkii | 46 +
tex/context/base/syst-fnt.mkiv | 46 +
tex/context/base/syst-fnt.tex | 43 -
tex/context/base/syst-gen.tex | 358 +-
tex/context/base/syst-ini.tex | 879 ++
tex/context/base/syst-lua.lua | 91 +
tex/context/base/syst-lua.tex | 37 +
tex/context/base/syst-mtx.tex | 80 -
tex/context/base/syst-new.tex | 21 +-
tex/context/base/syst-omg.tex | 79 -
tex/context/base/syst-pdt.tex | 50 -
tex/context/base/syst-pln.tex | 510 +-
tex/context/base/syst-prm.tex | 227 -
tex/context/base/syst-rtp.tex | 22 -
tex/context/base/syst-str.mkii | 7 +-
tex/context/base/syst-str.mkiv | 9 +
tex/context/base/syst-str.tex | 40 -
tex/context/base/syst-var.tex | 18 -
tex/context/base/syst-xtx.tex | 36 -
tex/context/base/tabl-ltb.tex | 856 ++
tex/context/base/tabl-ntb.mkii | 1584 +++
tex/context/base/tabl-ntb.mkiv | 1571 +++
tex/context/base/tabl-nte.tex | 107 +
tex/context/base/tabl-pln.tex | 91 +
tex/context/base/tabl-tab.tex | 2507 ++++
tex/context/base/tabl-tbl.tex | 1435 +++
tex/context/base/tabl-tsp.tex | 427 +
tex/context/base/task-ini.lua | 45 +
tex/context/base/task-ini.tex | 22 +
tex/context/base/thrd-ran.tex | 4 +-
tex/context/base/thrd-tab.tex | 50 +-
tex/context/base/thrd-trg.tex | 9 +-
tex/context/base/toks-ini.lua | 43 +-
tex/context/base/toks-ini.tex | 6 +-
tex/context/base/trac-deb.lua | 206 +
tex/context/base/trac-deb.tex | 43 +
tex/context/base/trac-inf.lua | 149 +
tex/context/base/trac-lmx.lua | 158 +
tex/context/base/trac-lmx.tex | 16 +
tex/context/base/trac-log.lua | 285 +
tex/context/base/trac-tim.lua | 163 +
tex/context/base/trac-tra.lua | 221 +
tex/context/base/type-cow.tex | 4 +-
tex/context/base/type-gyr.tex | 252 -
tex/context/base/type-ini.mkii | 743 ++
tex/context/base/type-ini.mkiv | 705 ++
tex/context/base/type-ini.tex | 721 --
tex/context/base/type-mac.mkii | 220 +
tex/context/base/type-mac.mkiv | 220 +
tex/context/base/type-mac.tex | 434 +
tex/context/base/type-map.tex | 48 +-
tex/context/base/type-one.tex | 494 +-
tex/context/base/type-otf.mkii | 535 +
tex/context/base/type-otf.mkiv | 628 +
tex/context/base/type-otf.tex | 739 +-
tex/context/base/type-siz.mkii | 583 +
tex/context/base/type-siz.mkiv | 375 +
tex/context/base/type-siz.tex | 688 +-
tex/context/base/type-syn.tex | 1 -
tex/context/base/type-tmf.tex | 103 +-
tex/context/base/type-win.tex | 120 +
tex/context/base/type-xtx.tex | 2 +-
tex/context/base/typo-brk.lua | 186 +
tex/context/base/typo-brk.tex | 77 +
tex/context/base/typo-cap.lua | 203 +
tex/context/base/typo-cap.tex | 214 +
tex/context/base/typo-ini.tex | 2 +-
tex/context/base/typo-krn.lua | 218 +
tex/context/base/typo-krn.tex | 59 +
tex/context/base/typo-mir.lua | 409 +
tex/context/base/typo-mir.tex | 144 +
tex/context/base/typo-spa.lua | 149 +
tex/context/base/typo-spa.tex | 69 +
tex/context/base/unic-035.tex | 32 +
tex/context/base/unic-exp.tex | 4 +-
tex/context/base/unic-ini.mkii | 10 +-
tex/context/base/unic-ini.mkiv | 19 +-
tex/context/base/verb-c.tex | 2 +-
tex/context/base/verb-eif.tex | 24 +-
tex/context/base/verb-ini.tex | 2 +-
tex/context/base/verb-js.tex | 18 +-
tex/context/base/verb-jv.tex | 50 +-
tex/context/base/verb-lua.lua | 10 +-
tex/context/base/verb-mp.lua | 6 +-
tex/context/base/verb-mp.tex | 2 +-
tex/context/base/verb-pas.tex | 6 +-
tex/context/base/verb-pl.tex | 58 +-
tex/context/base/verb-sql.tex | 2 +-
tex/context/base/verb-tex.lua | 6 +-
tex/context/base/verb-tex.tex | 2 +-
tex/context/base/verb-xml.tex | 2 +-
tex/context/base/x-calcmath.lua | 191 +-
tex/context/base/x-cals.mkiv | 15 +-
tex/context/base/x-chemml.mkiv | 2 +-
tex/context/base/x-ct.mkiv | 2 +-
tex/context/base/x-fo.tex | 8 +-
tex/context/base/x-mathml.lua | 77 +-
tex/context/base/x-mathml.mkiv | 88 +-
tex/context/base/x-newcml.tex | 8 +-
tex/context/base/x-newmme.tex | 4 +-
tex/context/base/x-newmml.mkii | 23 +-
tex/context/base/x-newmml.tex | 2 +-
tex/context/base/x-newmmo.tex | 2 +-
tex/context/base/x-newpml.tex | 2 +-
tex/context/base/x-set-02.tex | 11 +-
tex/context/base/x-set-11.mkii | 2 +-
tex/context/base/x-set-11.mkiv | 2 +-
tex/context/base/x-set-11.tex | 2 +-
tex/context/base/xetx-chr.tex | 1167 ++
tex/context/base/xetx-cls.tex | 378 +
tex/context/base/xetx-ini.tex | 132 +
tex/context/base/xetx-utf.tex | 1989 ++++
tex/context/base/xtag-cml.tex | 2 +
tex/context/base/xtag-ent.tex | 2 +-
tex/context/base/xtag-exp.tex | 6 +-
tex/context/base/xtag-ext.tex | 4 +-
tex/context/base/xtag-hyp.tex | 6 +-
tex/context/base/xtag-ini.mkii | 6 -
tex/context/base/xtag-ini.mkiv | 2 -
tex/context/base/xtag-ini.tex | 24 +-
tex/context/base/xtag-map.tex | 4 +-
tex/context/base/xtag-mmc.tex | 8 +-
tex/context/base/xtag-mml.tex | 8 +-
tex/context/base/xtag-mmp.tex | 31 +-
tex/context/base/xtag-pml.tex | 3 +-
tex/context/base/xtag-pmu.tex | 4 +-
tex/context/base/xtag-pre.tex | 4 +-
tex/context/base/xtag-prs.tex | 2 +-
tex/context/base/xtag-raw.tex | 6 +-
tex/context/base/xtag-rng.tex | 14 +-
tex/context/base/xtag-run.tex | 4 +-
tex/context/base/xtag-stk.tex | 4 +-
tex/context/base/xtag-utf.tex | 6 +-
tex/context/bib/bibl-apa-fr.tex | 2 +-
tex/context/bib/bibl-apa.tex | 6 +-
tex/context/bib/t-bib.mkii | 5 +
tex/context/bib/t-bib.mkiv | 64 +
tex/context/bib/t-bib.tex | 74 +-
tex/context/config/cont-usr.tex | 2 +-
tex/context/interface/cont-cs.xml | 32 +-
tex/context/interface/cont-cz.xml | 10033 ----------------
tex/context/interface/cont-de.xml | 32 +-
tex/context/interface/cont-en.xml | 32 +-
tex/context/interface/cont-fr.xml | 32 +-
tex/context/interface/cont-it.xml | 32 +-
tex/context/interface/cont-nl.xml | 32 +-
tex/context/interface/cont-pe.xml | 32 +-
tex/context/interface/cont-ro.xml | 32 +-
tex/context/interface/keys-cs.xml | 57 +
tex/context/interface/keys-de.xml | 57 +
tex/context/interface/keys-en.xml | 57 +
tex/context/interface/keys-fr.xml | 57 +
tex/context/interface/keys-it.xml | 57 +
tex/context/interface/keys-nl.xml | 57 +
tex/context/interface/keys-pe.xml | 57 +
tex/context/interface/keys-ro.xml | 57 +
tex/context/interface/t-bib.xml | 3 +
tex/context/patterns/lang-de.hyp | 4 +-
tex/context/patterns/lang-de.pat | 5446 ++++-----
tex/context/patterns/lang-de.rme | 8 +-
tex/context/patterns/lang-deo.hyp | 4 +-
tex/context/patterns/lang-deo.pat | 5446 +++++----
tex/context/patterns/lang-deo.rme | 8 +-
tex/context/patterns/lang-uk.hyp | 8 +
tex/context/patterns/lang-uk.pat | 1905 ++++
tex/context/patterns/lang-uk.rme | 70 +
tex/context/test/context-test.tex | 27 +
tex/context/user/cont-sys.rme | 9 +-
tex/generic/context/luatex-basics.tex | 21 +
tex/generic/context/luatex-fonts-merged.lua | 11070 ++++++++++++++++++
tex/generic/context/luatex-fonts.lua | 139 +
tex/generic/context/luatex-fonts.tex | 139 +
tex/generic/context/luatex-mplib.lua | 469 +
tex/generic/context/luatex-mplib.tex | 118 +
tex/generic/context/luatex-plain.tex | 25 +
tex/generic/context/luatex-test.tex | 47 +
tex/generic/context/ppchtex.noc | 4 +-
tpm/t-bib.tpm | 8 +-
web2c/context.cnf | 87 +-
1017 files changed, 240313 insertions(+), 120527 deletions(-)
create mode 100644 context/data/cont-pe-scite.properties
create mode 100644 context/data/context-bbedit-pe.xml
create mode 100644 context/data/context-jedit-pe.xml
delete mode 100644 fonts/enc/dvips/context/lm-ec-os.enc
delete mode 100644 fonts/enc/dvips/context/lm-qx-os.enc
delete mode 100644 fonts/enc/dvips/context/lm-qxtt-os.enc
delete mode 100644 fonts/enc/dvips/context/lm-t5-os.enc
delete mode 100644 fonts/enc/dvips/context/lm-texnansi-os.enc
create mode 100644 fonts/enc/dvips/context/q-8r.enc
create mode 100644 fonts/map/dvips/context/contnav.map
create mode 100644 fonts/map/dvips/jmn/hans.map
delete mode 100644 fonts/map/pdftex/context/cs-qbk.map
delete mode 100644 fonts/map/pdftex/context/cs-qcs.map
delete mode 100644 fonts/map/pdftex/context/cs-qpl.map
delete mode 100644 fonts/map/pdftex/context/cs-qtm.map
delete mode 100644 fonts/map/pdftex/context/ec-public-lm.map
delete mode 100644 fonts/map/pdftex/context/ec-qbk.map
delete mode 100644 fonts/map/pdftex/context/ec-qcs.map
delete mode 100644 fonts/map/pdftex/context/ec-qpl.map
delete mode 100644 fonts/map/pdftex/context/ec-qtm.map
delete mode 100644 fonts/map/pdftex/context/el-public-lm.map
delete mode 100644 fonts/map/pdftex/context/el-qbk.map
delete mode 100644 fonts/map/pdftex/context/el-qcs.map
delete mode 100644 fonts/map/pdftex/context/el-qpl.map
delete mode 100644 fonts/map/pdftex/context/el-qtm.map
delete mode 100644 fonts/map/pdftex/context/l7x-qbk.map
delete mode 100644 fonts/map/pdftex/context/l7x-qcs.map
delete mode 100644 fonts/map/pdftex/context/l7x-qpl.map
delete mode 100644 fonts/map/pdftex/context/l7x-qtm.map
delete mode 100644 fonts/map/pdftex/context/qx-public-lm.map
delete mode 100644 fonts/map/pdftex/context/qx-qbk.map
delete mode 100644 fonts/map/pdftex/context/qx-qcs.map
delete mode 100644 fonts/map/pdftex/context/qx-qpl.map
delete mode 100644 fonts/map/pdftex/context/qx-qtm.map
delete mode 100644 fonts/map/pdftex/context/rm-qbk.map
delete mode 100644 fonts/map/pdftex/context/rm-qcs.map
delete mode 100644 fonts/map/pdftex/context/rm-qpl.map
delete mode 100644 fonts/map/pdftex/context/rm-qtm.map
delete mode 100644 fonts/map/pdftex/context/t2a-qbk.map
delete mode 100644 fonts/map/pdftex/context/t2a-qcs.map
delete mode 100644 fonts/map/pdftex/context/t2a-qpl.map
delete mode 100644 fonts/map/pdftex/context/t2a-qtm.map
delete mode 100644 fonts/map/pdftex/context/t2b-qbk.map
delete mode 100644 fonts/map/pdftex/context/t2b-qcs.map
delete mode 100644 fonts/map/pdftex/context/t2b-qpl.map
delete mode 100644 fonts/map/pdftex/context/t2b-qtm.map
delete mode 100644 fonts/map/pdftex/context/t2c-qbk.map
delete mode 100644 fonts/map/pdftex/context/t2c-qcs.map
delete mode 100644 fonts/map/pdftex/context/t2c-qpl.map
delete mode 100644 fonts/map/pdftex/context/t2c-qtm.map
delete mode 100644 fonts/map/pdftex/context/t5-public-lm.map
delete mode 100644 fonts/map/pdftex/context/t5-qbk.map
delete mode 100644 fonts/map/pdftex/context/t5-qcs.map
delete mode 100644 fonts/map/pdftex/context/t5-qpl.map
delete mode 100644 fonts/map/pdftex/context/t5-qtm.map
delete mode 100644 fonts/map/pdftex/context/texnansi-public-lm.map
delete mode 100644 fonts/map/pdftex/context/texnansi-qbk.map
delete mode 100644 fonts/map/pdftex/context/texnansi-qcs.map
delete mode 100644 fonts/map/pdftex/context/texnansi-qpl.map
delete mode 100644 fonts/map/pdftex/context/texnansi-qtm.map
delete mode 100644 fonts/map/pdftex/context/ts1-qbk.map
delete mode 100644 fonts/map/pdftex/context/ts1-qcs.map
delete mode 100644 fonts/map/pdftex/context/ts1-qpl.map
delete mode 100644 fonts/map/pdftex/context/ts1-qtm.map
create mode 100644 metapost/context/base/mp-chem.mp
create mode 100644 scripts/context/lua/mtx-metatex.lua
create mode 100644 scripts/context/lua/mtx-package.lua
create mode 100644 scripts/context/lua/mtx-profile.lua
create mode 100644 scripts/context/lua/mtx-server-ctx-fonttest.lua
create mode 100644 scripts/context/lua/mtx-server-ctx-help.lua
create mode 100644 scripts/context/lua/mtx-server-ctx-startup.lua
create mode 100644 scripts/context/lua/mtx-timing.lua
create mode 100644 scripts/context/lua/mtx-unzip.lua
delete mode 100644 scripts/context/ruby/www/admin.rb
delete mode 100644 scripts/context/ruby/www/common.rb
delete mode 100644 scripts/context/ruby/www/dir.rb
delete mode 100644 scripts/context/ruby/www/exa.rb
delete mode 100644 scripts/context/ruby/www/lib.rb
delete mode 100644 scripts/context/ruby/www/login.rb
delete mode 100644 scripts/context/ruby/wwwclient.rb
delete mode 100644 scripts/context/ruby/wwwserver.rb
delete mode 100644 scripts/context/ruby/wwwwatch.rb
delete mode 100755 scripts/context/stubs/mswin/exatools.bat
create mode 100644 scripts/context/stubs/mswin/luatools.lua
create mode 100644 scripts/context/stubs/mswin/metatex.cmd
create mode 100644 scripts/context/stubs/mswin/mtxrun.lua
create mode 100755 scripts/context/stubs/mswin/mtxtools.bat
delete mode 100755 scripts/context/stubs/mswin/pdftrimwhite.bat
create mode 100644 scripts/context/stubs/mswin/texexec.cmd
delete mode 100755 scripts/context/stubs/mswin/texfind.bat
create mode 100644 scripts/context/stubs/mswin/texmfstart.cmd
delete mode 100755 scripts/context/stubs/mswin/texshow.bat
delete mode 100755 scripts/context/stubs/unix/exatools
create mode 100755 scripts/context/stubs/unix/luatools
create mode 100755 scripts/context/stubs/unix/metatex
create mode 100755 scripts/context/stubs/unix/mtxrun
create mode 100755 scripts/context/stubs/unix/mtxtools
delete mode 100755 scripts/context/stubs/unix/pdftrimwhite
delete mode 100755 scripts/context/stubs/unix/texfind
create mode 100755 scripts/context/stubs/unix/texmfstart
delete mode 100755 scripts/context/stubs/unix/texshow
create mode 100644 tex/context/base/back-ini.lua
create mode 100644 tex/context/base/back-ini.tex
create mode 100644 tex/context/base/back-pdf.lua
create mode 100644 tex/context/base/back-pdf.tex
create mode 100644 tex/context/base/bibl-bib.lua
create mode 100644 tex/context/base/bibl-bib.tex
create mode 100644 tex/context/base/bibl-tst.lua
create mode 100644 tex/context/base/catc-act.tex
create mode 100644 tex/context/base/catc-ctx.tex
create mode 100644 tex/context/base/catc-def.tex
create mode 100644 tex/context/base/catc-ini.lua
create mode 100644 tex/context/base/catc-ini.mkii
create mode 100644 tex/context/base/catc-ini.mkiv
create mode 100644 tex/context/base/catc-sym.tex
create mode 100644 tex/context/base/char-enc.lua
create mode 100644 tex/context/base/char-enc.tex
delete mode 100644 tex/context/base/char-syn.lua
create mode 100644 tex/context/base/chem-ini.lua
create mode 100644 tex/context/base/chem-ini.mkiv
create mode 100644 tex/context/base/chem-str-test.tex
create mode 100644 tex/context/base/chem-str.lua
create mode 100644 tex/context/base/chem-str.mkiv
create mode 100644 tex/context/base/colo-ext.mkii
create mode 100644 tex/context/base/colo-ext.mkiv
delete mode 100644 tex/context/base/colo-ext.tex
create mode 100644 tex/context/base/colo-hex.mkii
create mode 100644 tex/context/base/colo-hex.mkiv
delete mode 100644 tex/context/base/colo-ini.tex
create mode 100644 tex/context/base/context-base.lmx
create mode 100644 tex/context/base/context-fonttest.lmx
create mode 100644 tex/context/base/context-help.lmx
create mode 100644 tex/context/base/context-timing.lmx
create mode 100644 tex/context/base/context.rme
delete mode 100644 tex/context/base/core-blk.lua
delete mode 100644 tex/context/base/core-blk.mkiv
delete mode 100644 tex/context/base/core-buf.tex
delete mode 100644 tex/context/base/core-con.tex
delete mode 100644 tex/context/base/core-ctx.tex
create mode 100644 tex/context/base/core-def.mkii
create mode 100644 tex/context/base/core-def.mkiv
delete mode 100644 tex/context/base/core-def.tex
create mode 100644 tex/context/base/core-env.mkii
create mode 100644 tex/context/base/core-env.mkiv
create mode 100644 tex/context/base/core-fld.mkii
create mode 100644 tex/context/base/core-fld.mkiv
delete mode 100644 tex/context/base/core-fld.tex
create mode 100644 tex/context/base/core-fnt.mkii
create mode 100644 tex/context/base/core-fnt.mkiv
delete mode 100644 tex/context/base/core-fnt.tex
delete mode 100644 tex/context/base/core-inc.tex
create mode 100644 tex/context/base/core-int.mkii
create mode 100644 tex/context/base/core-int.mkiv
delete mode 100644 tex/context/base/core-int.tex
delete mode 100644 tex/context/base/core-job.tex
delete mode 100644 tex/context/base/core-ltb.tex
create mode 100644 tex/context/base/core-mis.mkii
create mode 100644 tex/context/base/core-mis.mkiv
delete mode 100644 tex/context/base/core-mis.tex
create mode 100644 tex/context/base/core-nav.mkii
create mode 100644 tex/context/base/core-nav.mkiv
delete mode 100644 tex/context/base/core-nav.tex
delete mode 100644 tex/context/base/core-new.tex
delete mode 100644 tex/context/base/core-ntb.tex
delete mode 100644 tex/context/base/core-obj.tex
delete mode 100644 tex/context/base/core-pos.tex
delete mode 100644 tex/context/base/core-ref.lua
delete mode 100644 tex/context/base/core-ref.mkii
delete mode 100644 tex/context/base/core-ref.mkiv
delete mode 100644 tex/context/base/core-reg.lua
delete mode 100644 tex/context/base/core-reg.mkii
delete mode 100644 tex/context/base/core-reg.mkiv
delete mode 100644 tex/context/base/core-rul.tex
delete mode 100644 tex/context/base/core-sec.mkii
delete mode 100644 tex/context/base/core-sec.mkiv
create mode 100644 tex/context/base/core-sec.tex
delete mode 100644 tex/context/base/core-spa.tex
delete mode 100644 tex/context/base/core-syn.lua
delete mode 100644 tex/context/base/core-syn.mkii
delete mode 100644 tex/context/base/core-syn.mkiv
delete mode 100644 tex/context/base/core-sys.tex
delete mode 100644 tex/context/base/core-tab.tex
delete mode 100644 tex/context/base/core-tbl.tex
delete mode 100644 tex/context/base/core-tsp.tex
delete mode 100644 tex/context/base/core-two.tex
delete mode 100644 tex/context/base/core-uti.tex
delete mode 100644 tex/context/base/core-ver.tex
create mode 100644 tex/context/base/data-aux.lua
create mode 100644 tex/context/base/data-bin.lua
create mode 100644 tex/context/base/data-con.lua
create mode 100644 tex/context/base/data-crl.lua
create mode 100644 tex/context/base/data-ctx.lua
create mode 100644 tex/context/base/data-gen.lua
create mode 100644 tex/context/base/data-inp.lua
create mode 100644 tex/context/base/data-kps.lua
create mode 100644 tex/context/base/data-lst.lua
create mode 100644 tex/context/base/data-lua.lua
create mode 100644 tex/context/base/data-out.lua
create mode 100644 tex/context/base/data-pre.lua
create mode 100644 tex/context/base/data-res.lua
create mode 100644 tex/context/base/data-tex.lua
create mode 100644 tex/context/base/data-tmf.lua
create mode 100644 tex/context/base/data-tmp.lua
create mode 100644 tex/context/base/data-tre.lua
create mode 100644 tex/context/base/data-use.lua
create mode 100644 tex/context/base/data-zip.lua
delete mode 100644 tex/context/base/enco-ini.tex
delete mode 100644 tex/context/base/enco-pfr.mkii
delete mode 100644 tex/context/base/enco-pfr.mkiv
delete mode 100644 tex/context/base/enco-utf.tex
create mode 100644 tex/context/base/font-chk.lua
create mode 100644 tex/context/base/font-cid.lua
create mode 100644 tex/context/base/font-col.mkiv
delete mode 100644 tex/context/base/font-col.tex
create mode 100644 tex/context/base/font-ctx.lua
create mode 100644 tex/context/base/font-dum.lua
create mode 100644 tex/context/base/font-log.lua
create mode 100644 tex/context/base/font-mis.lua
create mode 100644 tex/context/base/font-ota.lua
create mode 100644 tex/context/base/font-otb.lua
create mode 100644 tex/context/base/font-otc.lua
create mode 100644 tex/context/base/font-otd.lua
create mode 100644 tex/context/base/font-oti.lua
create mode 100644 tex/context/base/font-otn.lua
create mode 100644 tex/context/base/font-otp.lua
create mode 100644 tex/context/base/font-ott.lua
create mode 100644 tex/context/base/font-tra.mkiv
create mode 100644 tex/context/base/font-uni.mkii
create mode 100644 tex/context/base/font-uni.mkiv
delete mode 100644 tex/context/base/font-uni.tex
create mode 100644 tex/context/base/font-unk.mkii
create mode 100644 tex/context/base/font-unk.mkiv
delete mode 100644 tex/context/base/font-unk.tex
create mode 100644 tex/context/base/font-xtx.lua
create mode 100644 tex/context/base/font-xtx.tex
delete mode 100644 tex/context/base/hand-ini.tex
create mode 100644 tex/context/base/java-ini.mkii
create mode 100644 tex/context/base/java-ini.mkiv
delete mode 100644 tex/context/base/java-ini.tex
create mode 100644 tex/context/base/lang-cjk.tex
delete mode 100644 tex/context/base/lang-ini.tex
create mode 100644 tex/context/base/lang-lab.mkii
create mode 100644 tex/context/base/lang-lab.mkiv
delete mode 100644 tex/context/base/lang-lab.tex
create mode 100644 tex/context/base/lang-spe.mkii
create mode 100644 tex/context/base/lang-spe.mkiv
delete mode 100644 tex/context/base/lang-spe.tex
delete mode 100644 tex/context/base/lang-url.tex
create mode 100644 tex/context/base/luat-bas.tex
create mode 100644 tex/context/base/luat-cnf.lua
create mode 100644 tex/context/base/luat-cod.tex
delete mode 100644 tex/context/base/luat-crl.lua
delete mode 100644 tex/context/base/luat-deb.lua
delete mode 100644 tex/context/base/luat-deb.tex
create mode 100644 tex/context/base/luat-dum.lua
delete mode 100644 tex/context/base/luat-env.tex
create mode 100644 tex/context/base/luat-fio.lua
delete mode 100644 tex/context/base/luat-inp.lua
delete mode 100644 tex/context/base/luat-kps.lua
delete mode 100644 tex/context/base/luat-lib.lua
delete mode 100644 tex/context/base/luat-lmx.lua
delete mode 100644 tex/context/base/luat-lmx.tex
delete mode 100644 tex/context/base/luat-log.lua
create mode 100644 tex/context/base/luat-run.lua
create mode 100644 tex/context/base/luat-soc.lua
create mode 100644 tex/context/base/luat-sto.lua
delete mode 100644 tex/context/base/luat-tex.lua
delete mode 100644 tex/context/base/luat-tmp.lua
delete mode 100644 tex/context/base/luat-tra.lua
delete mode 100644 tex/context/base/luat-tre.lua
delete mode 100644 tex/context/base/luat-uni.lua
delete mode 100644 tex/context/base/luat-uni.tex
delete mode 100644 tex/context/base/luat-zip.lua
create mode 100644 tex/context/base/lxml-ent.lua
create mode 100644 tex/context/base/lxml-mis.lua
create mode 100644 tex/context/base/lxml-pth.lua
create mode 100644 tex/context/base/lxml-tab.lua
create mode 100644 tex/context/base/m-chemic.mkii
create mode 100644 tex/context/base/m-chemic.mkiv
delete mode 100644 tex/context/base/m-gamma.tex
create mode 100644 tex/context/base/m-mkii.mkiv
create mode 100644 tex/context/base/m-track.tex
create mode 100644 tex/context/base/math-ali.mkiv
create mode 100644 tex/context/base/math-arr.mkii
create mode 100644 tex/context/base/math-arr.mkiv
create mode 100644 tex/context/base/math-def.mkiv
create mode 100644 tex/context/base/math-del.mkiv
create mode 100644 tex/context/base/math-dim.lua
create mode 100644 tex/context/base/math-dis.mkiv
create mode 100644 tex/context/base/math-ext.lua
delete mode 100644 tex/context/base/math-ext.tex
create mode 100644 tex/context/base/math-for.mkiv
create mode 100644 tex/context/base/math-frc.mkii
create mode 100644 tex/context/base/math-frc.mkiv
delete mode 100644 tex/context/base/math-ini.tex
create mode 100644 tex/context/base/math-inl.mkiv
create mode 100644 tex/context/base/math-int.mkiv
create mode 100644 tex/context/base/math-map.lua
delete mode 100644 tex/context/base/math-mis.tex
create mode 100644 tex/context/base/math-noa.lua
create mode 100644 tex/context/base/math-pln.mkii
create mode 100644 tex/context/base/math-pln.mkiv
delete mode 100644 tex/context/base/math-pln.tex
create mode 100644 tex/context/base/math-run.mkii
delete mode 100644 tex/context/base/math-run.tex
create mode 100644 tex/context/base/math-scr.mkiv
create mode 100644 tex/context/base/math-vfu.lua
delete mode 100644 tex/context/base/meta-pdf.tex
create mode 100644 tex/context/base/meta-pdh.lua
create mode 100644 tex/context/base/metatex.tex
create mode 100644 tex/context/base/mtx-context-arrange.tex
create mode 100644 tex/context/base/mtx-context-combine.tex
create mode 100644 tex/context/base/mtx-context-ideas.tex
create mode 100644 tex/context/base/mtx-context-listing.tex
create mode 100644 tex/context/base/mtx-context-timing.tex
create mode 100644 tex/context/base/mult-chk.lua
create mode 100644 tex/context/base/mult-chk.mkii
create mode 100644 tex/context/base/mult-chk.mkiv
create mode 100644 tex/context/base/mult-mcs.tex
create mode 100644 tex/context/base/mult-mde.tex
create mode 100644 tex/context/base/mult-men.tex
create mode 100644 tex/context/base/mult-mes.lua
create mode 100644 tex/context/base/mult-mfr.tex
create mode 100644 tex/context/base/mult-mit.tex
create mode 100644 tex/context/base/mult-mnl.tex
create mode 100644 tex/context/base/mult-mno.tex
create mode 100644 tex/context/base/mult-mpe.tex
create mode 100644 tex/context/base/mult-mro.tex
create mode 100644 tex/context/base/node-dum.lua
create mode 100644 tex/context/base/node-ext.lua
create mode 100644 tex/context/base/node-fin.lua
create mode 100644 tex/context/base/node-fin.tex
create mode 100644 tex/context/base/node-fnt.lua
create mode 100644 tex/context/base/node-inj.lua
create mode 100644 tex/context/base/node-pro.lua
create mode 100644 tex/context/base/node-res.lua
create mode 100644 tex/context/base/node-ser.lua
create mode 100644 tex/context/base/node-shp.lua
create mode 100644 tex/context/base/node-tex.lua
create mode 100644 tex/context/base/node-tra.lua
create mode 100644 tex/context/base/node-tsk.lua
create mode 100644 tex/context/base/node-tst.lua
create mode 100644 tex/context/base/norm-alo.tex
create mode 100644 tex/context/base/norm-ctx.tex
create mode 100644 tex/context/base/norm-etx.tex
create mode 100644 tex/context/base/norm-ltx.tex
create mode 100644 tex/context/base/norm-ptx.tex
create mode 100644 tex/context/base/norm-tex.tex
create mode 100644 tex/context/base/norm-xtx.tex
create mode 100644 tex/context/base/page-bck.mkii
create mode 100644 tex/context/base/page-bck.mkiv
delete mode 100644 tex/context/base/page-bck.tex
create mode 100644 tex/context/base/page-ini.mkii
create mode 100644 tex/context/base/page-ini.mkiv
delete mode 100644 tex/context/base/page-ini.tex
create mode 100644 tex/context/base/page-mis.tex
create mode 100644 tex/context/base/page-one.mkii
create mode 100644 tex/context/base/page-one.mkiv
delete mode 100644 tex/context/base/page-one.tex
create mode 100644 tex/context/base/page-txt.mkii
create mode 100644 tex/context/base/page-txt.mkiv
delete mode 100644 tex/context/base/page-txt.tex
create mode 100644 tex/context/base/ppchtex.mkii
create mode 100644 tex/context/base/ppchtex.mkiv
delete mode 100644 tex/context/base/ppchtex.tex
create mode 100644 tex/context/base/prop-ini.mkii
create mode 100644 tex/context/base/prop-ini.mkiv
delete mode 100644 tex/context/base/prop-ini.tex
delete mode 100644 tex/context/base/prop-lay.tex
delete mode 100644 tex/context/base/prop-mis.tex
delete mode 100644 tex/context/base/prop-run.tex
delete mode 100644 tex/context/base/regi-ini.tex
create mode 100644 tex/context/base/s-fnt-11.tex
create mode 100644 tex/context/base/s-fnt-20.tex
create mode 100644 tex/context/base/s-fnt-21.tex
create mode 100644 tex/context/base/s-fnt-23.tex
create mode 100644 tex/context/base/s-fnt-24.tex
create mode 100644 tex/context/base/s-fnt-25.tex
create mode 100644 tex/context/base/s-fnt-30.tex
create mode 100644 tex/context/base/s-pre-66.tex
create mode 100644 tex/context/base/s-reg-01.tex
create mode 100644 tex/context/base/scrp-cjk.lua
create mode 100644 tex/context/base/scrp-ini.lua
create mode 100644 tex/context/base/scrp-ini.tex
delete mode 100644 tex/context/base/sort-def.mkii
delete mode 100644 tex/context/base/sort-def.mkiv
delete mode 100644 tex/context/base/sort-ini.tex
delete mode 100644 tex/context/base/sort-lan.mkii
delete mode 100644 tex/context/base/sort-lan.mkiv
delete mode 100644 tex/context/base/spec-def.mkii
delete mode 100644 tex/context/base/spec-def.mkiv
delete mode 100644 tex/context/base/spec-fdf.mkii
delete mode 100644 tex/context/base/spec-fdf.mkiv
delete mode 100644 tex/context/base/spec-pdf.lua
delete mode 100644 tex/context/base/spec-tpd.mkii
delete mode 100644 tex/context/base/spec-tpd.mkiv
create mode 100644 tex/context/base/strc-bkm.lua
create mode 100644 tex/context/base/strc-bkm.tex
create mode 100644 tex/context/base/strc-blk.lua
create mode 100644 tex/context/base/strc-blk.tex
create mode 100644 tex/context/base/strc-def.tex
create mode 100644 tex/context/base/strc-des.lua
create mode 100644 tex/context/base/strc-des.tex
create mode 100644 tex/context/base/strc-doc.lua
create mode 100644 tex/context/base/strc-doc.tex
create mode 100644 tex/context/base/strc-flt.lua
create mode 100644 tex/context/base/strc-flt.tex
create mode 100644 tex/context/base/strc-ini.lua
create mode 100644 tex/context/base/strc-ini.tex
create mode 100644 tex/context/base/strc-itm.lua
create mode 100644 tex/context/base/strc-itm.tex
create mode 100644 tex/context/base/strc-lst.lua
create mode 100644 tex/context/base/strc-lst.tex
create mode 100644 tex/context/base/strc-mar.lua
create mode 100644 tex/context/base/strc-mar.tex
create mode 100644 tex/context/base/strc-mat.lua
create mode 100644 tex/context/base/strc-mat.tex
create mode 100644 tex/context/base/strc-not.lua
create mode 100644 tex/context/base/strc-not.tex
create mode 100644 tex/context/base/strc-num.lua
create mode 100644 tex/context/base/strc-num.tex
create mode 100644 tex/context/base/strc-pag.lua
create mode 100644 tex/context/base/strc-pag.tex
create mode 100644 tex/context/base/strc-prc.lua
create mode 100644 tex/context/base/strc-prc.tex
create mode 100644 tex/context/base/strc-ref.lua
create mode 100644 tex/context/base/strc-ref.tex
create mode 100644 tex/context/base/strc-reg.lua
create mode 100644 tex/context/base/strc-reg.tex
create mode 100644 tex/context/base/strc-ren.tex
create mode 100644 tex/context/base/strc-sbe.tex
create mode 100644 tex/context/base/strc-sec.tex
create mode 100644 tex/context/base/strc-syn.lua
create mode 100644 tex/context/base/strc-syn.tex
create mode 100644 tex/context/base/strc-xml.tex
create mode 100644 tex/context/base/supp-dir.mkii
create mode 100644 tex/context/base/supp-dir.mkiv
delete mode 100644 tex/context/base/supp-dir.tex
delete mode 100644 tex/context/base/supp-fil.tex
delete mode 100644 tex/context/base/supp-ini.tex
create mode 100644 tex/context/base/supp-ran.lua
create mode 100644 tex/context/base/supp-ran.mkii
create mode 100644 tex/context/base/supp-ran.mkiv
delete mode 100644 tex/context/base/supp-ran.tex
create mode 100644 tex/context/base/syst-aux.tex
delete mode 100644 tex/context/base/syst-cat.mkii
delete mode 100644 tex/context/base/syst-cat.mkiv
delete mode 100644 tex/context/base/syst-cat.tex
delete mode 100644 tex/context/base/syst-chr.tex
delete mode 100644 tex/context/base/syst-con.tex
delete mode 100644 tex/context/base/syst-etx.tex
create mode 100644 tex/context/base/syst-fnt.mkii
create mode 100644 tex/context/base/syst-fnt.mkiv
delete mode 100644 tex/context/base/syst-fnt.tex
create mode 100644 tex/context/base/syst-ini.tex
create mode 100644 tex/context/base/syst-lua.lua
create mode 100644 tex/context/base/syst-lua.tex
delete mode 100644 tex/context/base/syst-mtx.tex
delete mode 100644 tex/context/base/syst-omg.tex
delete mode 100644 tex/context/base/syst-pdt.tex
delete mode 100644 tex/context/base/syst-prm.tex
delete mode 100644 tex/context/base/syst-rtp.tex
delete mode 100644 tex/context/base/syst-str.tex
delete mode 100644 tex/context/base/syst-var.tex
delete mode 100644 tex/context/base/syst-xtx.tex
create mode 100644 tex/context/base/tabl-ltb.tex
create mode 100644 tex/context/base/tabl-ntb.mkii
create mode 100644 tex/context/base/tabl-ntb.mkiv
create mode 100644 tex/context/base/tabl-nte.tex
create mode 100644 tex/context/base/tabl-pln.tex
create mode 100644 tex/context/base/tabl-tab.tex
create mode 100644 tex/context/base/tabl-tbl.tex
create mode 100644 tex/context/base/tabl-tsp.tex
create mode 100644 tex/context/base/task-ini.lua
create mode 100644 tex/context/base/task-ini.tex
create mode 100644 tex/context/base/trac-deb.lua
create mode 100644 tex/context/base/trac-deb.tex
create mode 100644 tex/context/base/trac-inf.lua
create mode 100644 tex/context/base/trac-lmx.lua
create mode 100644 tex/context/base/trac-lmx.tex
create mode 100644 tex/context/base/trac-log.lua
create mode 100644 tex/context/base/trac-tim.lua
create mode 100644 tex/context/base/trac-tra.lua
delete mode 100644 tex/context/base/type-gyr.tex
create mode 100644 tex/context/base/type-ini.mkii
create mode 100644 tex/context/base/type-ini.mkiv
delete mode 100644 tex/context/base/type-ini.tex
create mode 100644 tex/context/base/type-mac.mkii
create mode 100644 tex/context/base/type-mac.mkiv
create mode 100644 tex/context/base/type-mac.tex
create mode 100644 tex/context/base/type-otf.mkii
create mode 100644 tex/context/base/type-otf.mkiv
create mode 100644 tex/context/base/type-siz.mkii
create mode 100644 tex/context/base/type-siz.mkiv
create mode 100644 tex/context/base/type-win.tex
create mode 100644 tex/context/base/typo-brk.lua
create mode 100644 tex/context/base/typo-brk.tex
create mode 100644 tex/context/base/typo-cap.lua
create mode 100644 tex/context/base/typo-cap.tex
create mode 100644 tex/context/base/typo-krn.lua
create mode 100644 tex/context/base/typo-krn.tex
create mode 100644 tex/context/base/typo-mir.lua
create mode 100644 tex/context/base/typo-mir.tex
create mode 100644 tex/context/base/typo-spa.lua
create mode 100644 tex/context/base/typo-spa.tex
create mode 100644 tex/context/base/unic-035.tex
create mode 100644 tex/context/base/xetx-chr.tex
create mode 100644 tex/context/base/xetx-cls.tex
create mode 100644 tex/context/base/xetx-ini.tex
create mode 100644 tex/context/base/xetx-utf.tex
delete mode 100644 tex/context/base/xtag-ini.mkii
delete mode 100644 tex/context/base/xtag-ini.mkiv
create mode 100644 tex/context/bib/t-bib.mkii
create mode 100644 tex/context/bib/t-bib.mkiv
delete mode 100644 tex/context/interface/cont-cz.xml
create mode 100644 tex/context/patterns/lang-uk.hyp
create mode 100644 tex/context/patterns/lang-uk.pat
create mode 100644 tex/context/patterns/lang-uk.rme
create mode 100644 tex/context/test/context-test.tex
create mode 100644 tex/generic/context/luatex-basics.tex
create mode 100644 tex/generic/context/luatex-fonts-merged.lua
create mode 100644 tex/generic/context/luatex-fonts.lua
create mode 100644 tex/generic/context/luatex-fonts.tex
create mode 100644 tex/generic/context/luatex-mplib.lua
create mode 100644 tex/generic/context/luatex-mplib.tex
create mode 100644 tex/generic/context/luatex-plain.tex
create mode 100644 tex/generic/context/luatex-test.tex
diff --git a/context/data/cont-pe-scite.properties b/context/data/cont-pe-scite.properties
new file mode 100644
index 000000000..a9756b04c
--- /dev/null
+++ b/context/data/cont-pe-scite.properties
@@ -0,0 +1,97 @@
+keywordclass.macros.context.pe=\
+CAP Cap Caps Character Characters MONTH \
+Romannumerals WEEKDAY WORD WORDS Word Words \
+appendix cap chapter chem completecombinedlist completelistoffloats \
+completelistofsorts completelistofsynonyms coupledregister crlf definebodyfontDEF definebodyfontREF \
+definedfont definefontfeature definefonthandling definetypeface description enumeration \
+framedtext indentation its labeling loadsorts loadsynonyms \
+mapfontsize mediaeval name nextsection nocap paragraph \
+part placelistoffloats placelistofsorts placelistofsynonyms ran register \
+reservefloat resettextcontent section seeregister setupcapitals setupfonthandling \
+setupfontsynonym setupinterlinespace2 setuplistalternative setupurl sort startalignment \
+startbuffer startbuffer startcolumns startcombination startdescription startdocument \
+startenumeration startfigure startfloattext startformula startframedtext starthiding \
+startitemgroup startlegend startline startlinecorrection startlinenumbering startlines \
+startlocal startlocalenvironment startlocalfootnotes startmakeup startmarginblock startnamemakeup \
+startnarrower startopposite startoverlay startoverview startparagraph startpositioning \
+startpostponing startprofile startregister startsymbolset startsynchronization starttable \
+starttables starttabulate starttyping startunpacked startتوضیح startتولید \
+startحقیقت startخطحاشیه startخطمتن startرنگ startفشرده startمحیط \
+startمنویپانل startمولفه startنسخه startنقلقول startپروژه startپسزمینه \
+stopalignment stopbuffer stopbuffer stopcolumns stopcombination stopdescription \
+stopdocument stopenumeration stopfigure stopfloattext stopformula stopframedtext \
+stophiding stopitemgroup stoplegend stopline stoplinecorrection stoplinenumbering \
+stoplines stoplocal stoplocalenvironment stoplocalfootnotes stopmakeup stopmarginblock \
+stopnamemakeup stopnarrower stopopposite stopoverlay stopoverview stopparagraph \
+stoppositioning stoppostponing stopprofile stopsymbolset stopsynchronization stoptable \
+stoptables stoptabulate stoptyping stopunpacked stopتوضیح stopتولید \
+stopحقیقت stopخطحاشیه stopخطمتن stopرنگ stopفشرده stopمحیط \
+stopمنویپانل stopمولفه stopنسخه stopنقلقول stopپروژه stopپسزمینه \
+sub subject subsection subsubject subsubsection subsubsubject \
+synonym title tooltip typ useURL usedirectory \
+آیتم آیتمها آینه اجباربلوکها از ازکارانداختنمنویپانل \
+استفادهبلوکها استفادهدستخطتایپ استفادهرمزینه استفادهشکلخارجی استفادهفرمانها استفادهقطعهموزیکخارجی \
+استفادهمدول استفادهمرجعها استفادهنمادها استفادهنوشتارخارجی استفادهویژگیها استفادهپروندهخارجی \
+استفادهپروندهدستخطتایپ استفادهپروندههایخارجی اعدادلاتین اما انتخاببرگ انتخاببلوکها \
+انتخابنسخه انتقالبهتوری بارگذاریآرایش بارگذاریآیتمها بارگذاریارجاع بارگذاریاندازهبرگ \
+بارگذاریباریکتر بارگذاریبافر بارگذاریبالا بارگذاریبخش بارگذاریبردباری بارگذاریبرنامهها \
+بارگذاریبرگ بارگذاریبست بارگذاریبلوک بارگذاریبلوکهایحاشیه بارگذاریبلوکبخش بارگذاریتایپ \
+بارگذاریتایپکردن بارگذاریتب بارگذاریترتیب بارگذاریترتیب بارگذاریترکیبها بارگذاریتطابق \
+بارگذاریتعریفپانوشت بارگذاریتنظیم بارگذاریتهبرگ بارگذاریتورفتگی بارگذاریتورفتگیها بارگذاریتوضیح \
+بارگذاریثبت بارگذاریجدولها بارگذاریجدولبندی بارگذاریخالی بارگذاریخروجی بارگذاریخطها \
+بارگذاریخطهایحاشیه بارگذاریخطهایسیاه بارگذاریخطهایمتن بارگذاریخطهاینازک بارگذاریدرجدرخطها بارگذاریدرجمخالف \
+بارگذاریدرونحاشیه بارگذاریدوران بارگذاریدکمهها بارگذاریراهنما بارگذاریرنگ بارگذاریرنگها \
+بارگذاریزبان بارگذاریستونها بارگذاریسر بارگذاریسربرگ بارگذاریسرها بارگذاریسیستم \
+بارگذاریشرح بارگذاریشرح بارگذاریشرحها بارگذاریشمارهزیرصفحه بارگذاریشمارهسر بارگذاریشمارهصفحه \
+بارگذاریشمارهگذاری بارگذاریشمارهگذاریها بارگذاریشمارهگذاریصفحه بارگذاریشمارهگذاریپاراگراف بارگذاریشمارهگذاریخط بارگذاریشناور \
+بارگذاریشناورها بارگذاریشکافتنشناورها بارگذاریشکلهایخارجی بارگذاریطرح بارگذاریطرحبندی بارگذاریعرضخط \
+بارگذاریفاصلهبینخط بارگذاریفرمولها بارگذاریفضایسفید بارگذاریفضاگذاری بارگذاریقالبی بارگذاریقلممتن \
+بارگذاریلوح بارگذاریلیست بارگذاریلیستترکیبی بارگذاریلیستمرجع بارگذاریمترادفها بارگذاریمتن \
+بارگذاریمتنهایبالا بارگذاریمتنسر بارگذاریمتنسربرگ بارگذاریمتنقالبی بارگذاریمتنمتنها بارگذاریمتنپانوشت \
+بارگذاریمتنپایین بارگذاریمجموعهنماد بارگذاریمحیطقلممتن بارگذاریمنویپانل بارگذاریمکانگذاری بارگذاریمیدان \
+بارگذاریمیدانها بارگذاریمیلهتطابق بارگذاریمیلهزیر بارگذاریمیلهپانل بارگذارینسخهها بارگذارینشانهشکستن \
+بارگذارینشانهگذاری بارگذارینشرها بارگذارینقل بارگذاریپاراگرافها بارگذاریپانل بارگذاریپانوشتها \
+بارگذاریپایین بارگذاریپردهها بارگذاریپردهپانل بارگذاریپروفایلها بارگذاریپرکردنخطها بارگذاریپسزمینه \
+بارگذاریپسزمینهها بارگذاریچیدن بارگذاریگذارصفحه بارگذاریگروهآیتم بازنشانی بازنشانینشانهگذاری \
+باگذاریمتنبرچسب بدونبلوکهایبیشتر بدونتورفتگی بدونخطبالاوپایین بدونخطسروتهبرگ بدونفایلهایبیشتر \
+بدونفضا بدونفضایسفید بدونلیست بدوننشانهگذاری برنامه بروبه \
+بروبهجعبه بروپایین برچسبها بلند بلوکهایپردازش بلوکهاپنهان \
+بنویسبینلیست بنویسدرثبت بنویسدرلیستمرجع بنویسدرلیست تاریخ تاریخجاری \
+تاریخرجوع تایپ تایپبافر تایپپرونده تب ترجمه \
+تطابق تعریف تعریفآرایش تعریفآرم تعریفالگویجدول تعریفاندازهبرگ \
+تعریفبافر تعریفبخش تعریفبرنامه تعریفبرچسب تعریفبلوک تعریفبلوکبخش \
+تعریفتایپ تعریفتایپکردن تعریفتبدیل تعریفترتیب تعریفتودهمیدان تعریفتورفتگی \
+تعریفثبت تعریفجدولبندی تعریفخالی تعریفخروجی تعریفرنگ تعریفزیرمیدان \
+تعریفسر تعریفشرح تعریفشروعپایان تعریفشمارهبندی تعریفشمایلمرجع تعریفشناور \
+تعریفقالبی تعریفقلم تعریفقلممتن تعریفلوح تعریفلیست تعریفلیستترکیبی \
+تعریفلیستمرجع تعریفمترادفها تعریفمترادفقلم تعریفمتن تعریفمتنقالبی تعریفمحیطقلمبدنه \
+تعریفمرجع تعریفمنویپانل تعریفمنویپانل تعریفمیدان تعریفنسخه تعریفنشانهگذاری \
+تعریفنماد تعریفنمادشکل تعریفپاراگرافها تعریفپروفایل تعریفپوشش تعریفگروهرنگ \
+تعیینشمارهسر تعیینمحتوایمتن تعیینمشخصاتلیست تغییربهقلمبدنه تنظیمراست تنظیمطرحبندی \
+تنظیموسط تورفتگی توری توضیح تک ثبتزوج \
+ثبتکامل جداسازینشانهگذاری حاش حرف حرفها حفظبلوکها \
+خالی خطهایسیاه خطهاینازک خطهاخالی خطحاشیه خطزدن \
+خطزدنها خطسیاه خطمتن خطمو خطنازک خا \
+خع در درجآرمها درجثبت درجثبت درجدرخط \
+درجدرخطها درجدرمتن درجدرمیدان درجدربالاییکدیگر درجدرتوری درجراهنما \
+درجزیرفرمول درجشناور درجفرمول درجلیست درجلیستمختلط درجلیستمختلط \
+درجلیستمرجع درجپانوشتها درجپانوشتهایموضعی درجچوبخط درجکناربهکنار درحاشیه \
+درحاشیهدیگر درخارجی درخط درداخلی درراست درصفحه \
+درقالبی درمورد درون درچپ دریافتبافر دریافتنشانه \
+دوران دکمه دکمهپانل رج رجوع رنگ \
+رنگخاکستری روزهفته ریاضی زبان زباناصلی ستون \
+سر شمارهسر شمارهسرجاری شمارهمبدل شمارهها شکافتنشناور \
+شکلخارجی صفحه صفحهزوج صفحهپردازش عبوربلوکها فشرده \
+فضا فضاهایثابت فضایسفید فضایسفیدصحیح قالبی لوحمقایسه \
+ماه متنبرچسب متنحاشیه متنسر متنپانوشت مرجع \
+مرجعصفحه مرجعمتن مقایسهگروهرنگ مقیاس منفی مکان \
+میدان میدانهایگزارش میدانشبیهسازی میدانپشته میدانکپی میلهتطابق \
+میلهرو میلهزیر میلههارو میلهپانل میلههایزیر نسخه \
+نسخهنشانه نشانهگذاری نشانهگذاریزوج نشر نصبزبان نقطهها \
+نقل نقلقول نم نماد نمادلیست نمایشآرایش \
+نمایشبارگذاریها نمایشبستها نمایشتوری نمایشرنگ نمایششکلهایخارجی نمایشطرحبندی \
+نمایشقالب نمایشقلمبدنه نمایشلوح نمایشمجموعهعلامت نمایشمحیطقلمبدنه نمایشمیدانها \
+نمایشچاپ نمایشگروهرنگ نوشتارزوج نوعصفحه پابا پانوشت \
+پایین پرده پرکردنمیدان پسزمینه پیروینسخه پیروینسخهپروفایل \
+پیرویپروفایل چوبخط چپچین کاغذزوج کسر کشیده \
+کلمهراست گیره یادداشت یکجا یکخط
\ No newline at end of file
diff --git a/context/data/context-bbedit-pe.xml b/context/data/context-bbedit-pe.xml
new file mode 100644
index 000000000..168e79256
--- /dev/null
+++ b/context/data/context-bbedit-pe.xml
@@ -0,0 +1 @@
+BBLMKeywordList\CAP\Cap\Caps\Character\Characters\MONTH\Romannumerals\WEEKDAY\WORD\WORDS\Word\Words\appendix\cap\chapter\chem\completecombinedlist\completelistoffloats\completelistofsorts\completelistofsynonyms\coupledregister\crlf\definebodyfontDEF\definebodyfontREF\definedfont\definefontfeature\definefonthandling\definetypeface\description\enumeration\framedtext\indentation\its\labeling\loadsorts\loadsynonyms\mapfontsize\mediaeval\name\nextsection\nocap\paragraph\part\placelistoffloats\placelistofsorts\placelistofsynonyms\ran\register\reservefloat\resettextcontent\section\seeregister\setupcapitals\setupfonthandling\setupfontsynonym\setupinterlinespace2\setuplistalternative\setupurl\sort\startalignment\startbuffer\startbuffer\startcolumns\startcombination\startdescription\startdocument\startenumeration\startfigure\startfloattext\startformula\startframedtext\starthiding\startitemgroup\startlegend\startline\startlinecorrection\startlinenumbering\startlines\startlocal\startlocalenvironment\startlocalfootnotes\startmakeup\startmarginblock\startnamemakeup\startnarrower\startopposite\startoverlay\startoverview\startparagraph\startpositioning\startpostponing\startprofile\startregister\startsymbolset\startsynchronization\starttable\starttables\starttabulate\starttyping\startunpacked\startتوضیح\startتولید\startحقیقت\startخطحاشیه\startخطمتن\startرنگ\startفشرده\startمحیط\startمنویپانل\startمولفه\startنسخه\startنقلقول\startپروژه\startپسزمینه\stopalignment\stopbuffer\stopbuffer\stopcolumns\stopcombination\stopdescription\stopdocument\stopenumeration\stopfigure\stopfloattext\stopformula\stopframedtext\stophiding\stopitemgroup\stoplegend\stopline\stoplinecorrection\stoplinenumbering\stoplines\stoplocal\stoplocalenvironment\stoplocalfootnotes\stopmakeup\stopmarginblock\stopnamemakeup\stopnarrower\stopopposite\stopoverlay\stopoverview\stopparagraph\stoppositioning\stoppostponing\stopprofile\stopsymbolset\stopsynchronization\stoptable\stoptables\stoptabulate\stoptyping\stopunpacked\stopتوضیح\stopتولید\stopحقیقت\stopخطحاشیه\stopخطمتن\stopرنگ\stopفشرده\stopمحیط\stopمنویپانل\stopمولفه\stopنسخه\stopنقلقول\stopپروژه\stopپسزمینه\sub\subject\subsection\subsubject\subsubsection\subsubsubject\synonym\title\tooltip\typ\useURL\usedirectory\آیتم\آیتمها\آینه\اجباربلوکها\از\ازکارانداختنمنویپانل\استفادهبلوکها\استفادهدستخطتایپ\استفادهرمزینه\استفادهشکلخارجی\استفادهفرمانها\استفادهقطعهموزیکخارجی\استفادهمدول\استفادهمرجعها\استفادهنمادها\استفادهنوشتارخارجی\استفادهویژگیها\استفادهپروندهخارجی\استفادهپروندهدستخطتایپ\استفادهپروندههایخارجی\اعدادلاتین\اما\انتخاببرگ\انتخاببلوکها\انتخابنسخه\انتقالبهتوری\بارگذاریآرایش\بارگذاریآیتمها\بارگذاریارجاع\بارگذاریاندازهبرگ\بارگذاریباریکتر\بارگذاریبافر\بارگذاریبالا\بارگذاریبخش\بارگذاریبردباری\بارگذاریبرنامهها\بارگذاریبرگ\بارگذاریبست\بارگذاریبلوک\بارگذاریبلوکهایحاشیه\بارگذاریبلوکبخش\بارگذاریتایپ\بارگذاریتایپکردن\بارگذاریتب\بارگذاریترتیب\بارگذاریترتیب\بارگذاریترکیبها\بارگذاریتطابق\بارگذاریتعریفپانوشت\بارگذاریتنظیم\بارگذاریتهبرگ\بارگذاریتورفتگی\بارگذاریتورفتگیها\بارگذاریتوضیح\بارگذاریثبت\بارگذاریجدولها\بارگذاریجدولبندی\بارگذاریخالی\بارگذاریخروجی\بارگذاریخطها\بارگذاریخطهایحاشیه\بارگذاریخطهایسیاه\بارگذاریخطهایمتن\بارگذاریخطهاینازک\بارگذاریدرجدرخطها\بارگذاریدرجمخالف\بارگذاریدرونحاشیه\بارگذاریدوران\بارگذاریدکمهها\بارگذاریراهنما\بارگذاریرنگ\بارگذاریرنگها\بارگذاریزبان\بارگذاریستونها\بارگذاریسر\بارگذاریسربرگ\بارگذاریسرها\بارگذاریسیستم\بارگذاریشرح\بارگذاریشرح\بارگذاریشرحها\بارگذاریشمارهزیرصفحه\بارگذاریشمارهسر\بارگذاریشمارهصفحه\بارگذاریشمارهگذاری\بارگذاریشمارهگذاریها\بارگذاریشمارهگذاریصفحه\بارگذاریشمارهگذاریپاراگراف\بارگذاریشمارهگذاریخط\بارگذاریشناور\بارگذاریشناورها\بارگذاریشکافتنشناورها\بارگذاریشکلهایخارجی\بارگذاریطرح\بارگذاریطرحبندی\بارگذاریعرضخط\بارگذاریفاصلهبینخط\بارگذاریفرمولها\بارگذاریفضایسفید\بارگذاریفضاگذاری\بارگذاریقالبی\بارگذاریقلممتن\بارگذاریلوح\بارگذاریلیست\بارگذاریلیستترکیبی\بارگذاریلیستمرجع\بارگذاریمترادفها\بارگذاریمتن\بارگذاریمتنهایبالا\بارگذاریمتنسر\بارگذاریمتنسربرگ\بارگذاریمتنقالبی\بارگذاریمتنمتنها\بارگذاریمتنپانوشت\بارگذاریمتنپایین\بارگذاریمجموعهنماد\بارگذاریمحیطقلممتن\بارگذاریمنویپانل\بارگذاریمکانگذاری\بارگذاریمیدان\بارگذاریمیدانها\بارگذاریمیلهتطابق\بارگذاریمیلهزیر\بارگذاریمیلهپانل\بارگذارینسخهها\بارگذارینشانهشکستن\بارگذارینشانهگذاری\بارگذارینشرها\بارگذارینقل\بارگذاریپاراگرافها\بارگذاریپانل\بارگذاریپانوشتها\بارگذاریپایین\بارگذاریپردهها\بارگذاریپردهپانل\بارگذاریپروفایلها\بارگذاریپرکردنخطها\بارگذاریپسزمینه\بارگذاریپسزمینهها\بارگذاریچیدن\بارگذاریگذارصفحه\بارگذاریگروهآیتم\بازنشانی\بازنشانینشانهگذاری\باگذاریمتنبرچسب\بدونبلوکهایبیشتر\بدونتورفتگی\بدونخطبالاوپایین\بدونخطسروتهبرگ\بدونفایلهایبیشتر\بدونفضا\بدونفضایسفید\بدونلیست\بدوننشانهگذاری\برنامه\بروبه\بروبهجعبه\بروپایین\برچسبها\بلند\بلوکهایپردازش\بلوکهاپنهان\بنویسبینلیست\بنویسدرثبت\بنویسدرلیستمرجع\بنویسدرلیست\تاریخ\تاریخجاری\تاریخرجوع\تایپ\تایپبافر\تایپپرونده\تب\ترجمه\تطابق\تعریف\تعریفآرایش\تعریفآرم\تعریفالگویجدول\تعریفاندازهبرگ\تعریفبافر\تعریفبخش\تعریفبرنامه\تعریفبرچسب\تعریفبلوک\تعریفبلوکبخش\تعریفتایپ\تعریفتایپکردن\تعریفتبدیل\تعریفترتیب\تعریفتودهمیدان\تعریفتورفتگی\تعریفثبت\تعریفجدولبندی\تعریفخالی\تعریفخروجی\تعریفرنگ\تعریفزیرمیدان\تعریفسر\تعریفشرح\تعریفشروعپایان\تعریفشمارهبندی\تعریفشمایلمرجع\تعریفشناور\تعریفقالبی\تعریفقلم\تعریفقلممتن\تعریفلوح\تعریفلیست\تعریفلیستترکیبی\تعریفلیستمرجع\تعریفمترادفها\تعریفمترادفقلم\تعریفمتن\تعریفمتنقالبی\تعریفمحیطقلمبدنه\تعریفمرجع\تعریفمنویپانل\تعریفمنویپانل\تعریفمیدان\تعریفنسخه\تعریفنشانهگذاری\تعریفنماد\تعریفنمادشکل\تعریفپاراگرافها\تعریفپروفایل\تعریفپوشش\تعریفگروهرنگ\تعیینشمارهسر\تعیینمحتوایمتن\تعیینمشخصاتلیست\تغییربهقلمبدنه\تنظیمراست\تنظیمطرحبندی\تنظیموسط\تورفتگی\توری\توضیح\تک\ثبتزوج\ثبتکامل\جداسازینشانهگذاری\حاش\حرف\حرفها\حفظبلوکها\خالی\خطهایسیاه\خطهاینازک\خطهاخالی\خطحاشیه\خطزدن\خطزدنها\خطسیاه\خطمتن\خطمو\خطنازک\خا\خع\در\درجآرمها\درجثبت\درجثبت\درجدرخط\درجدرخطها\درجدرمتن\درجدرمیدان\درجدربالاییکدیگر\درجدرتوری\درجراهنما\درجزیرفرمول\درجشناور\درجفرمول\درجلیست\درجلیستمختلط\درجلیستمختلط\درجلیستمرجع\درجپانوشتها\درجپانوشتهایموضعی\درجچوبخط\درجکناربهکنار\درحاشیه\درحاشیهدیگر\درخارجی\درخط\درداخلی\درراست\درصفحه\درقالبی\درمورد\درون\درچپ\دریافتبافر\دریافتنشانه\دوران\دکمه\دکمهپانل\رج\رجوع\رنگ\رنگخاکستری\روزهفته\ریاضی\زبان\زباناصلی\ستون\سر\شمارهسر\شمارهسرجاری\شمارهمبدل\شمارهها\شکافتنشناور\شکلخارجی\صفحه\صفحهزوج\صفحهپردازش\عبوربلوکها\فشرده\فضا\فضاهایثابت\فضایسفید\فضایسفیدصحیح\قالبی\لوحمقایسه\ماه\متنبرچسب\متنحاشیه\متنسر\متنپانوشت\مرجع\مرجعصفحه\مرجعمتن\مقایسهگروهرنگ\مقیاس\منفی\مکان\میدان\میدانهایگزارش\میدانشبیهسازی\میدانپشته\میدانکپی\میلهتطابق\میلهرو\میلهزیر\میلههارو\میلهپانل\میلههایزیر\نسخه\نسخهنشانه\نشانهگذاری\نشانهگذاریزوج\نشر\نصبزبان\نقطهها\نقل\نقلقول\نم\نماد\نمادلیست\نمایشآرایش\نمایشبارگذاریها\نمایشبستها\نمایشتوری\نمایشرنگ\نمایششکلهایخارجی\نمایشطرحبندی\نمایشقالب\نمایشقلمبدنه\نمایشلوح\نمایشمجموعهعلامت\نمایشمحیطقلمبدنه\نمایشمیدانها\نمایشچاپ\نمایشگروهرنگ\نوشتارزوج\نوعصفحه\پابا\پانوشت\پایین\پرده\پرکردنمیدان\پسزمینه\پیروینسخه\پیروینسخهپروفایل\پیرویپروفایل\چوبخط\چپچین\کاغذزوج\کسر\کشیده\کلمهراست\گیره\یادداشت\یکجا\یکخط
\ No newline at end of file
diff --git a/context/data/context-jedit-pe.xml b/context/data/context-jedit-pe.xml
new file mode 100644
index 000000000..4667614f3
--- /dev/null
+++ b/context/data/context-jedit-pe.xml
@@ -0,0 +1,2 @@
+
+CAPCapCapsCharacterCharactersMONTHRomannumeralsWEEKDAYWORDWORDSWordWordsappendixcapchapterchemcompletecombinedlistcompletelistoffloatscompletelistofsortscompletelistofsynonymscoupledregistercrlfdefinebodyfontDEFdefinebodyfontREFdefinedfontdefinefontfeaturedefinefonthandlingdefinetypefacedescriptionenumerationframedtextindentationitslabelingloadsortsloadsynonymsmapfontsizemediaevalnamenextsectionnocapparagraphpartplacelistoffloatsplacelistofsortsplacelistofsynonymsranregisterreservefloatresettextcontentsectionseeregistersetupcapitalssetupfonthandlingsetupfontsynonymsetupinterlinespace2setuplistalternativesetupurlsortstartalignmentstartbufferstartbufferstartcolumnsstartcombinationstartdescriptionstartdocumentstartenumerationstartfigurestartfloattextstartformulastartframedtextstarthidingstartitemgroupstartlegendstartlinestartlinecorrectionstartlinenumberingstartlinesstartlocalstartlocalenvironmentstartlocalfootnotesstartmakeupstartmarginblockstartnamemakeupstartnarrowerstartoppositestartoverlaystartoverviewstartparagraphstartpositioningstartpostponingstartprofilestartregisterstartsymbolsetstartsynchronizationstarttablestarttablesstarttabulatestarttypingstartunpackedstartتوضیحstartتولیدstartحقیقتstartخطحاشیهstartخطمتنstartرنگstartفشردهstartمحیطstartمنویپانلstartمولفهstartنسخهstartنقلقولstartپروژهstartپسزمینهstopalignmentstopbufferstopbufferstopcolumnsstopcombinationstopdescriptionstopdocumentstopenumerationstopfigurestopfloattextstopformulastopframedtextstophidingstopitemgroupstoplegendstoplinestoplinecorrectionstoplinenumberingstoplinesstoplocalstoplocalenvironmentstoplocalfootnotesstopmakeupstopmarginblockstopnamemakeupstopnarrowerstopoppositestopoverlaystopoverviewstopparagraphstoppositioningstoppostponingstopprofilestopsymbolsetstopsynchronizationstoptablestoptablesstoptabulatestoptypingstopunpackedstopتوضیحstopتولیدstopحقیقتstopخطحاشیهstopخطمتنstopرنگstopفشردهstopمحیطstopمنویپانلstopمولفهstopنسخهstopنقلقولstopپروژهstopپسزمینهsubsubjectsubsectionsubsubjectsubsubsectionsubsubsubjectsynonymtitletooltiptypuseURLusedirectoryآیتمآیتمهاآینهاجباربلوکهاازازکارانداختنمنویپانلاستفادهبلوکهااستفادهدستخطتایپاستفادهرمزینهاستفادهشکلخارجیاستفادهفرمانهااستفادهقطعهموزیکخارجیاستفادهمدولاستفادهمرجعهااستفادهنمادهااستفادهنوشتارخارجیاستفادهویژگیهااستفادهپروندهخارجیاستفادهپروندهدستخطتایپاستفادهپروندههایخارجیاعدادلاتیناماانتخاببرگانتخاببلوکهاانتخابنسخهانتقالبهتوریبارگذاریآرایشبارگذاریآیتمهابارگذاریارجاعبارگذاریاندازهبرگبارگذاریباریکتربارگذاریبافربارگذاریبالابارگذاریبخشبارگذاریبردباریبارگذاریبرنامههابارگذاریبرگبارگذاریبستبارگذاریبلوکبارگذاریبلوکهایحاشیهبارگذاریبلوکبخشبارگذاریتایپبارگذاریتایپکردنبارگذاریتببارگذاریترتیببارگذاریترتیببارگذاریترکیبهابارگذاریتطابقبارگذاریتعریفپانوشتبارگذاریتنظیمبارگذاریتهبرگبارگذاریتورفتگیبارگذاریتورفتگیهابارگذاریتوضیحبارگذاریثبتبارگذاریجدولهابارگذاریجدولبندیبارگذاریخالیبارگذاریخروجیبارگذاریخطهابارگذاریخطهایحاشیهبارگذاریخطهایسیاهبارگذاریخطهایمتنبارگذاریخطهاینازکبارگذاریدرجدرخطهابارگذاریدرجمخالفبارگذاریدرونحاشیهبارگذاریدورانبارگذاریدکمههابارگذاریراهنمابارگذاریرنگبارگذاریرنگهابارگذاریزبانبارگذاریستونهابارگذاریسربارگذاریسربرگبارگذاریسرهابارگذاریسیستمبارگذاریشرحبارگذاریشرحبارگذاریشرحهابارگذاریشمارهزیرصفحهبارگذاریشمارهسربارگذاریشمارهصفحهبارگذاریشمارهگذاریبارگذاریشمارهگذاریهابارگذاریشمارهگذاریصفحهبارگذاریشمارهگذاریپاراگرافبارگذاریشمارهگذاریخطبارگذاریشناوربارگذاریشناورهابارگذاریشکافتنشناورهابارگذاریشکلهایخارجیبارگذاریطرحبارگذاریطرحبندیبارگذاریعرضخطبارگذاریفاصلهبینخطبارگذاریفرمولهابارگذاریفضایسفیدبارگذاریفضاگذاریبارگذاریقالبیبارگذاریقلممتنبارگذاریلوحبارگذاریلیستبارگذاریلیستترکیبیبارگذاریلیستمرجعبارگذاریمترادفهابارگذاریمتنبارگذاریمتنهایبالابارگذاریمتنسربارگذاریمتنسربرگبارگذاریمتنقالبیبارگذاریمتنمتنهابارگذاریمتنپانوشتبارگذاریمتنپایینبارگذاریمجموعهنمادبارگذاریمحیطقلممتنبارگذاریمنویپانلبارگذاریمکانگذاریبارگذاریمیدانبارگذاریمیدانهابارگذاریمیلهتطابقبارگذاریمیلهزیربارگذاریمیلهپانلبارگذارینسخههابارگذارینشانهشکستنبارگذارینشانهگذاریبارگذارینشرهابارگذارینقلبارگذاریپاراگرافهابارگذاریپانلبارگذاریپانوشتهابارگذاریپایینبارگذاریپردههابارگذاریپردهپانلبارگذاریپروفایلهابارگذاریپرکردنخطهابارگذاریپسزمینهبارگذاریپسزمینههابارگذاریچیدنبارگذاریگذارصفحهبارگذاریگروهآیتمبازنشانیبازنشانینشانهگذاریباگذاریمتنبرچسببدونبلوکهایبیشتربدونتورفتگیبدونخطبالاوپایینبدونخطسروتهبرگبدونفایلهایبیشتربدونفضابدونفضایسفیدبدونلیستبدوننشانهگذاریبرنامهبروبهبروبهجعبهبروپایینبرچسبهابلندبلوکهایپردازشبلوکهاپنهانبنویسبینلیستبنویسدرثبتبنویسدرلیستمرجعبنویسدرلیستتاریختاریخجاریتاریخرجوعتایپتایپبافرتایپپروندهتبترجمهتطابقتعریفتعریفآرایشتعریفآرمتعریفالگویجدولتعریفاندازهبرگتعریفبافرتعریفبخشتعریفبرنامهتعریفبرچسبتعریفبلوکتعریفبلوکبخشتعریفتایپتعریفتایپکردنتعریفتبدیلتعریفترتیبتعریفتودهمیدانتعریفتورفتگیتعریفثبتتعریفجدولبندیتعریفخالیتعریفخروجیتعریفرنگتعریفزیرمیدانتعریفسرتعریفشرحتعریفشروعپایانتعریفشمارهبندیتعریفشمایلمرجعتعریفشناورتعریفقالبیتعریفقلمتعریفقلممتنتعریفلوحتعریفلیستتعریفلیستترکیبیتعریفلیستمرجعتعریفمترادفهاتعریفمترادفقلمتعریفمتنتعریفمتنقالبیتعریفمحیطقلمبدنهتعریفمرجعتعریفمنویپانلتعریفمنویپانلتعریفمیدانتعریفنسخهتعریفنشانهگذاریتعریفنمادتعریفنمادشکلتعریفپاراگرافهاتعریفپروفایلتعریفپوششتعریفگروهرنگتعیینشمارهسرتعیینمحتوایمتنتعیینمشخصاتلیستتغییربهقلمبدنهتنظیمراستتنظیمطرحبندیتنظیموسطتورفتگیتوریتوضیحتکثبتزوجثبتکاملجداسازینشانهگذاریحاشحرفحرفهاحفظبلوکهاخالیخطهایسیاهخطهاینازکخطهاخالیخطحاشیهخطزدنخطزدنهاخطسیاهخطمتنخطموخطنازکخاخعدردرجآرمهادرجثبتدرجثبتدرجدرخطدرجدرخطهادرجدرمتندرجدرمیداندرجدربالاییکدیگردرجدرتوریدرجراهنمادرجزیرفرمولدرجشناوردرجفرمولدرجلیستدرجلیستمختلطدرجلیستمختلطدرجلیستمرجعدرجپانوشتهادرجپانوشتهایموضعیدرجچوبخطدرجکناربهکناردرحاشیهدرحاشیهدیگردرخارجیدرخطدرداخلیدرراستدرصفحهدرقالبیدرمورددروندرچپدریافتبافردریافتنشانهدوراندکمهدکمهپانلرجرجوعرنگرنگخاکستریروزهفتهریاضیزبانزباناصلیستونسرشمارهسرشمارهسرجاریشمارهمبدلشمارههاشکافتنشناورشکلخارجیصفحهصفحهزوجصفحهپردازشعبوربلوکهافشردهفضافضاهایثابتفضایسفیدفضایسفیدصحیحقالبیلوحمقایسهماهمتنبرچسبمتنحاشیهمتنسرمتنپانوشتمرجعمرجعصفحهمرجعمتنمقایسهگروهرنگمقیاسمنفیمکانمیدانمیدانهایگزارشمیدانشبیهسازیمیدانپشتهمیدانکپیمیلهتطابقمیلهرومیلهزیرمیلههارومیلهپانلمیلههایزیرنسخهنسخهنشانهنشانهگذارینشانهگذاریزوجنشرنصبزباننقطههانقلنقلقولنمنمادنمادلیستنمایشآرایشنمایشبارگذاریهانمایشبستهانمایشتورینمایشرنگنمایششکلهایخارجینمایشطرحبندینمایشقالبنمایشقلمبدنهنمایشلوحنمایشمجموعهعلامتنمایشمحیطقلمبدنهنمایشمیدانهانمایشچاپنمایشگروهرنگنوشتارزوجنوعصفحهپاباپانوشتپایینپردهپرکردنمیدانپسزمینهپیروینسخهپیروینسخهپروفایلپیرویپروفایلچوبخطچپچینکاغذزوجکسرکشیدهکلمهراستگیرهیادداشتیکجایکخط
\ No newline at end of file
diff --git a/context/data/context.properties b/context/data/context.properties
index 48a8d0efe..cd1e8b367 100644
--- a/context/data/context.properties
+++ b/context/data/context.properties
@@ -75,20 +75,24 @@ if PLAT_GTK
name.metafun.console=$(name.context.console)
name.example.console=$(name.context.console)
-name.context.concheck=texmfstart concheck
-name.context.texexec=texmfstart texexec $(name.texexec.flag.pdfopen)
-name.context.texshow=texmfstart texshow
-name.context.purge=texmfstart ctxtools --purge --all
-name.context.update=texmfstart ctxtools --update
-name.context.showcase=texmfstart --file=showcase.pdf --program=context
+if PLAT_WIN
+ name.context.mtxrun=mtxrun.cmd --autogenerate
+
+if PLAT_GTK
+ name.context.mtxrun=mtxrun --autogenerate
-# name.context.examplap=texmfstart --browser --file=http://localhost:8061/exalogin
+name.context.concheck=$(name.context.mtxrun) --script check
+name.context.texexec=$(name.context.mtxrun) --script context $(name.texexec.flag.pdfopen)
+name.context.texshow=$(name.context.mtxrun) texshow
+name.context.purge=$(name.context.mtxrun) ctxtools --purge --all
+name.context.update=$(name.context.mtxrun) texshow --update --force
+name.context.showcase=$(name.context.mtxrun) --launch showcase.pdf
name.context.backend=pdf
name.example.xmlcheck=tidy -quiet -utf8 -xml -errors
-name.metafun.mptopdf=texmfstart mptopdf.pl
+name.metafun.mptopdf=$(name.context.mtxrun) --script mptopdf
# wwwserver --start --port=8061 --url=http://localhost:8061 --forcetemp --direct
# wwwserver.rb --direct
@@ -96,10 +100,10 @@ name.metafun.mptopdf=texmfstart mptopdf.pl
# if needed one can set MTX_SERVER_ROOT to the root of the documentation
if PLAT_WIN
- name.context.wwwserver=cmd /c start /min "Context Documentation" mtxrun --script server --start
+ name.context.wwwserver=cmd /c start /min "Context Documentation" $(name.context.mtxrun) --script server --start
if PLAT_GTK
- name.context.wwwserver=texmfstart mtxrun --script server --start > ~/context-wwwserver.log &
+ name.context.wwwserver=$(name.context.mtxrun) --script server --start > ~/context-wwwserver.log &
# Commands: help info, e:\websites\www.pragma-ade.com\showcase.pdf / todo: manuals
@@ -137,7 +141,6 @@ command.compile.*.fo=$(name.example.xmlcheck) $(FileNameExt)
#command.compile.subsystem.$(file.patterns.example)=1
command.build.$(file.patterns.context)=$(name.context.texexec) --$(name.context.backend) $(FileNameExt)
-# command.build.$(file.patterns.metafun)=$(name.context.texexec) --$(name.context.backend) --mptex $(FileNameExt)
command.build.$(file.patterns.metafun)=$(name.metafun.mptopdf) $(FileNameExt)
command.build.$(file.patterns.example)=$(name.context.texexec) --$(name.context.backend) --xml $(FileNameExt)
command.build.*.fo=$(name.context.texexec) --$(name.context.backend) $(name.texexec.flag.pdfopen) --xml --use=foxet $(FileNameExt)
@@ -381,6 +384,11 @@ if PLAT_GTK
font.monospace=font:!lm mono 10 regular,size:14
font.errorfont=font:!lm mono 10 regular,size:12
+#~ if PLAT_WIN
+ #~ font.monospace=font:Lucida Console,size:12
+ #~ font.monospace=font:Lucida Sans Unicode,size:12
+ #~ font.monospace=font:OpenSymbol,size:17
+
font.base=$(font.monospace)
#~ font.small=$(font.monospace)
font.comment=$(font.monospace)
diff --git a/doc/context/bib/bibmod-doc.pdf b/doc/context/bib/bibmod-doc.pdf
index 7e122fbb1..ea1db3160 100644
Binary files a/doc/context/bib/bibmod-doc.pdf and b/doc/context/bib/bibmod-doc.pdf differ
diff --git a/doc/context/bib/bibmod-doc.tex b/doc/context/bib/bibmod-doc.tex
index a2b246ee4..2ffdfa9f2 100644
--- a/doc/context/bib/bibmod-doc.tex
+++ b/doc/context/bib/bibmod-doc.tex
@@ -6,7 +6,6 @@
\usemodule[bib,set-11,mod-01]
-\setuppublications[alternative=num]
\startXMLmapping[zero]
\processXMLfilegrouped{t-bib.xml}
@@ -60,7 +59,7 @@
The bibliographic module (\type{t-bib.tex}) takes care of references
to publications and the typesetting of publication lists, as well as
providing an interface between \BIBTEX and \CONTEXT. This manual
-documents version 2006.09.15.
+documents version 2009.03.02.
The bibliographic subsystem consists of the main module
\type{t-bib.tex}; four \BIBTEX\ styles (\type{cont-xx.bst}); and a set
@@ -303,6 +302,7 @@ their own options:
\starttabulate[|l|p|]
\NC andtext \NC separation between two authors (for \type{\cite[author]} styles)\NC \NR
\NC otherstext \NC text used for `et.al.' (for \type{\cite[author]} styles)\NC \NR
+\NC namesep \NC the separation between consecutive authors (for \type{\cite[author]} styles)\NC \NR
\NC pubsep \NC separator between publication references in a
\type{\cite} command.\NC \NR
\NC lastpubsep \NC same, but for the
@@ -359,7 +359,7 @@ and select the parts that are needed for the current article.
Starting with version 2006.08.08, the module registers \BIBTEX\ as a
program to be run by texexec, so you no longer need to run \BIBTEX\ by
-hand.
+hand (and in MkIV, the module runs \BIBTEX\ on the fly using Lua).
Still, you may want to create the \type{\jobname.bbl} yourself. The
\type{.bbl} syntax is explained below. There is no default
@@ -747,4 +747,4 @@ point.
\stopmodule
-\stoptext
\ No newline at end of file
+\stoptext
diff --git a/fonts/enc/dvips/context/lm-ec-os.enc b/fonts/enc/dvips/context/lm-ec-os.enc
deleted file mode 100644
index 6bb22f319..000000000
--- a/fonts/enc/dvips/context/lm-ec-os.enc
+++ /dev/null
@@ -1,258 +0,0 @@
-/enclmec[
-/grave
-/acute
-/circumflex
-/tilde
-/dieresis
-/hungarumlaut
-/ring
-/caron
-/breve
-/macron
-/dotaccent
-/cedilla
-/ogonek
-/quotesinglbase
-/guilsinglleft
-/guilsinglright
-/quotedblleft
-/quotedblright
-/quotedblbase
-/guillemotleft
-/guillemotright
-/endash
-/emdash
-/cwm
-/perthousandzero
-/dotlessi
-/dotlessj
-/ff
-/fi
-/fl
-/ffi
-/ffl
-/visiblespace
-/exclam
-/quotedbl
-/numbersign
-/dollar
-/percent
-/ampersand
-/quoteright
-/parenleft
-/parenright
-/asterisk
-/plus
-/comma
-/hyphen
-/period
-/slash
-/zero.oldstyle
-/one.oldstyle
-/two.oldstyle
-/three.oldstyle
-/four.oldstyle
-/five.oldstyle
-/six.oldstyle
-/seven.oldstyle
-/eight.oldstyle
-/nine.oldstyle
-/colon
-/semicolon
-/less
-/equal
-/greater
-/question
-/at
-/A
-/B
-/C
-/D
-/E
-/F
-/G
-/H
-/I
-/J
-/K
-/L
-/M
-/N
-/O
-/P
-/Q
-/R
-/S
-/T
-/U
-/V
-/W
-/X
-/Y
-/Z
-/bracketleft
-/backslash
-/bracketright
-/asciicircum
-/underscore
-/quoteleft
-/a
-/b
-/c
-/d
-/e
-/f
-/g
-/h
-/i
-/j
-/k
-/l
-/m
-/n
-/o
-/p
-/q
-/r
-/s
-/t
-/u
-/v
-/w
-/x
-/y
-/z
-/braceleft
-/bar
-/braceright
-/asciitilde
-/hyphenchar
-/Abreve
-/Aogonek
-/Cacute
-/Ccaron
-/Dcaron
-/Ecaron
-/Eogonek
-/Gbreve
-/Lacute
-/Lcaron
-/Lslash
-/Nacute
-/Ncaron
-/Eng
-/Ohungarumlaut
-/Racute
-/Rcaron
-/Sacute
-/Scaron
-/Scedilla
-/Tcaron
-/Tcedilla
-/Uhungarumlaut
-/Uring
-/Ydieresis
-/Zacute
-/Zcaron
-/Zdotaccent
-/IJ
-/Idotaccent
-/dcroat
-/section
-/abreve
-/aogonek
-/cacute
-/ccaron
-/dcaron
-/ecaron
-/eogonek
-/gbreve
-/lacute
-/lcaron
-/lslash
-/nacute
-/ncaron
-/eng
-/ohungarumlaut
-/racute
-/rcaron
-/sacute
-/scaron
-/scedilla
-/tcaron
-/tcedilla
-/uhungarumlaut
-/uring
-/ydieresis
-/zacute
-/zcaron
-/zdotaccent
-/ij
-/exclamdown
-/questiondown
-/sterling
-/Agrave
-/Aacute
-/Acircumflex
-/Atilde
-/Adieresis
-/Aring
-/AE
-/Ccedilla
-/Egrave
-/Eacute
-/Ecircumflex
-/Edieresis
-/Igrave
-/Iacute
-/Icircumflex
-/Idieresis
-/Eth
-/Ntilde
-/Ograve
-/Oacute
-/Ocircumflex
-/Otilde
-/Odieresis
-/OE
-/Oslash
-/Ugrave
-/Uacute
-/Ucircumflex
-/Udieresis
-/Yacute
-/Thorn
-/Germandbls
-/agrave
-/aacute
-/acircumflex
-/atilde
-/adieresis
-/aring
-/ae
-/ccedilla
-/egrave
-/eacute
-/ecircumflex
-/edieresis
-/igrave
-/iacute
-/icircumflex
-/idieresis
-/eth
-/ntilde
-/ograve
-/oacute
-/ocircumflex
-/otilde
-/odieresis
-/oe
-/oslash
-/ugrave
-/uacute
-/ucircumflex
-/udieresis
-/yacute
-/thorn
-/germandbls
-] def
diff --git a/fonts/enc/dvips/context/lm-qx-os.enc b/fonts/enc/dvips/context/lm-qx-os.enc
deleted file mode 100644
index 6f4fd6bfc..000000000
--- a/fonts/enc/dvips/context/lm-qx-os.enc
+++ /dev/null
@@ -1,258 +0,0 @@
-/enclmqx[
-/.notdef
-/Delta
-/.notdef
-/.notdef
-/.notdef
-/Pi
-/Sigma
-/mu
-/ellipsis
-/f_k
-/Omega
-/ff
-/fi
-/fl
-/ffi
-/ffl
-/dotlessi
-/dotlessj
-/grave
-/acute
-/caron
-/breve
-/macron
-/ring
-/cedilla
-/germandbls
-/ae
-/oe
-/oslash
-/AE
-/OE
-/Oslash
-/space
-/exclam
-/quotedblright
-/numbersign
-/dollar
-/percent
-/ampersand
-/quoteright
-/parenleft
-/parenright
-/asterisk
-/plus
-/comma
-/hyphen
-/period
-/slash
-/zero.oldstyle
-/one.oldstyle
-/two.oldstyle
-/three.oldstyle
-/four.oldstyle
-/five.oldstyle
-/six.oldstyle
-/sevev.oldstyle
-/eight.oldstyle
-/nine.oldstyle
-/colon
-/semicolon
-/exclamdown
-/equal
-/questiondown
-/question
-/at
-/A
-/B
-/C
-/D
-/E
-/F
-/G
-/H
-/I
-/J
-/K
-/L
-/M
-/N
-/O
-/P
-/Q
-/R
-/S
-/T
-/U
-/V
-/W
-/X
-/Y
-/Z
-/bracketleft
-/quotedblleft
-/bracketright
-/circumflex
-/dotaccent
-/quoteleft
-/a
-/b
-/c
-/d
-/e
-/f
-/g
-/h
-/i
-/j
-/k
-/l
-/m
-/n
-/o
-/p
-/q
-/r
-/s
-/t
-/u
-/v
-/w
-/x
-/y
-/z
-/endash
-/emdash
-/hungarumlaut
-/tilde
-/dieresis
-/Euro
-/Aogonek
-/Cacute
-/greater
-/.notdef
-/.notdef
-/Eogonek
-/Iogonek
-/less
-/.notdef
-/Lslash
-/Nacute
-/asciitilde
-/asciicircum
-/.notdef
-/dagger
-/daggerdbl
-/Sacute
-/Scaron
-/Scommaaccent
-/degree
-/Tcommaaccent
-/ogonek
-/Uogonek
-/Ydieresis
-/Zacute
-/Zcaron
-/Zdotaccent
-/IJ
-/braceleft
-/braceright
-/section
-/.notdef
-/aogonek
-/cacute
-/registered
-/copyright
-/divide
-/eogonek
-/iogonek
-/minus
-/multiply
-/lslash
-/nacute
-/plusminus
-/.notdef
-/guillemotleft
-/guillemotright
-/paragraph
-/sacute
-/scaron
-/scommaaccent
-/bullet
-/tcommaaccent
-/threequartersemdash
-/uogonek
-/ydieresis
-/zacute
-/zcaron
-/zdotaccent
-/ij
-/periodcentered
-/quotedbl
-/quotesingle
-/Agrave
-/Aacute
-/Acircumflex
-/Atilde
-/Adieresis
-/Aring
-/backslash
-/Ccedilla
-/Egrave
-/Eacute
-/Ecircumflex
-/Edieresis
-/Igrave
-/Iacute
-/Icircumflex
-/Idieresis
-/Eth
-/Ntilde
-/Ograve
-/Oacute
-/Ocircumflex
-/Otilde
-/Odieresis
-/currency
-/perthousand
-/Ugrave
-/Uacute
-/Ucircumflex
-/Udieresis
-/Yacute
-/Thorn
-/bar
-/agrave
-/aacute
-/acircumflex
-/atilde
-/adieresis
-/aring
-/underscore
-/ccedilla
-/egrave
-/eacute
-/ecircumflex
-/edieresis
-/igrave
-/iacute
-/icircumflex
-/idieresis
-/eth
-/ntilde
-/ograve
-/oacute
-/ocircumflex
-/otilde
-/odieresis
-/anglearc
-/diameter
-/ugrave
-/uacute
-/ucircumflex
-/udieresis
-/yacute
-/thorn
-/quotedblbase
-] def
diff --git a/fonts/enc/dvips/context/lm-qxtt-os.enc b/fonts/enc/dvips/context/lm-qxtt-os.enc
deleted file mode 100644
index 905a34fd9..000000000
--- a/fonts/enc/dvips/context/lm-qxtt-os.enc
+++ /dev/null
@@ -1,258 +0,0 @@
-/enclmqxtt[
-/.notdef
-/Delta
-/.notdef
-/.notdef
-/.notdef
-/Pi
-/Sigma
-/mu
-/ellipsis
-/.notdef
-/Omega
-/.notdef
-/.notdef
-/.notdef
-/.notdef
-/.notdef
-/dotlessi
-/dotlessj
-/grave
-/acute
-/caron
-/breve
-/macron
-/ring
-/cedilla
-/germandbls
-/ae
-/oe
-/oslash
-/AE
-/OE
-/Oslash
-/visiblespace
-/exclam
-/quotedbl
-/numbersign
-/dollar
-/percent
-/ampersand
-/quoteright
-/parenleft
-/parenright
-/asterisk
-/plus
-/comma
-/hyphen
-/period
-/slash
-/zero.oldstyle
-/one.oldstyle
-/two.oldstyle
-/three.oldstyle
-/four.oldstyle
-/five.oldstyle
-/six.oldstyle
-/seven.oldstyle
-/eight.oldstyle
-/nine.oldstyle
-/colon
-/semicolon
-/less
-/equal
-/greater
-/question
-/at
-/A
-/B
-/C
-/D
-/E
-/F
-/G
-/H
-/I
-/J
-/K
-/L
-/M
-/N
-/O
-/P
-/Q
-/R
-/S
-/T
-/U
-/V
-/W
-/X
-/Y
-/Z
-/bracketleft
-/backslash
-/bracketright
-/asciicircum
-/underscore
-/quoteleft
-/a
-/b
-/c
-/d
-/e
-/f
-/g
-/h
-/i
-/j
-/k
-/l
-/m
-/n
-/o
-/p
-/q
-/r
-/s
-/t
-/u
-/v
-/w
-/x
-/y
-/z
-/braceleft
-/bar
-/braceright
-/asciitilde
-/dieresis
-/Euro
-/Aogonek
-/Cacute
-/.notdef
-/.notdef
-/.notdef
-/Eogonek
-/Iogonek
-/.notdef
-/.notdef
-/Lslash
-/Nacute
-/.notdef
-/.notdef
-/.notdef
-/dagger
-/daggerdbl
-/Sacute
-/Scaron
-/Scommaaccent
-/degree
-/Tcommaaccent
-/ogonek
-/Uogonek
-/Ydieresis
-/Zacute
-/Zcaron
-/Zdotaccent
-/.notdef
-/.notdef
-/.notdef
-/section
-/.notdef
-/aogonek
-/cacute
-/registered
-/copyright
-/divide
-/eogonek
-/iogonek
-/minus
-/multiply
-/lslash
-/nacute
-/plusminus
-/.notdef
-/guillemotleft
-/guillemotright
-/paragraph
-/sacute
-/scaron
-/scommaaccent
-/bullet
-/tcommaaccent
-/threequartersemdash
-/uogonek
-/ydieresis
-/zacute
-/zcaron
-/zdotaccent
-/.notdef
-/periodcentered
-/.notdef
-/quotesingle
-/Agrave
-/Aacute
-/Acircumflex
-/Atilde
-/Adieresis
-/Aring
-/.notdef
-/Ccedilla
-/Egrave
-/Eacute
-/Ecircumflex
-/Edieresis
-/Igrave
-/Iacute
-/Icircumflex
-/Idieresis
-/Eth
-/Ntilde
-/Ograve
-/Oacute
-/Ocircumflex
-/Otilde
-/Odieresis
-/currency
-/perthousand
-/Ugrave
-/Uacute
-/Ucircumflex
-/Udieresis
-/Yacute
-/Thorn
-/.notdef
-/agrave
-/aacute
-/acircumflex
-/atilde
-/adieresis
-/aring
-/.notdef
-/ccedilla
-/egrave
-/eacute
-/ecircumflex
-/edieresis
-/igrave
-/iacute
-/icircumflex
-/idieresis
-/eth
-/ntilde
-/ograve
-/oacute
-/ocircumflex
-/otilde
-/odieresis
-/anglearc
-/diameter
-/ugrave
-/uacute
-/ucircumflex
-/udieresis
-/yacute
-/thorn
-/quotedblbase
-] def
diff --git a/fonts/enc/dvips/context/lm-t5-os.enc b/fonts/enc/dvips/context/lm-t5-os.enc
deleted file mode 100644
index 4ff792fb7..000000000
--- a/fonts/enc/dvips/context/lm-t5-os.enc
+++ /dev/null
@@ -1,258 +0,0 @@
-/enclmt5[
-/grave
-/acute
-/circumflex
-/tilde
-/dieresis
-/dotbelow
-/ring
-/caron
-/breve
-/macron
-/dotaccent
-/cedilla
-/hookabove
-/quotesinglbase
-/guilsinglleft
-/guilsinglright
-/quotedblleft
-/quotedblright
-/quotedblbase
-/guillemotleft
-/guillemotright
-/endash
-/emdash
-/cwm
-/perthousandzero
-/dotlessi
-/Yhookabove
-/yhookabove
-/Ydotbelow
-/ydotbelow
-/Dcroat
-/dcroat
-/visiblespace
-/exclam
-/quotedbl
-/numbersign
-/dollar
-/percent
-/ampersand
-/quoteright
-/parenleft
-/parenright
-/asterisk
-/plus
-/comma
-/hyphen
-/period
-/slash
-/zero.oldstyle
-/one.oldstyle
-/two.oldstyle
-/three.oldstyle
-/four.oldstyle
-/five.oldstyle
-/six.oldstyle
-/seven.oldstyle
-/eight.oldstyle
-/nine.oldstyle
-/colon
-/semicolon
-/less
-/equal
-/greater
-/question
-/at
-/A
-/B
-/C
-/D
-/E
-/F
-/G
-/H
-/I
-/J
-/K
-/L
-/M
-/N
-/O
-/P
-/Q
-/R
-/S
-/T
-/U
-/V
-/W
-/X
-/Y
-/Z
-/bracketleft
-/backslash
-/bracketright
-/asciicircum
-/underscore
-/quoteleft
-/a
-/b
-/c
-/d
-/e
-/f
-/g
-/h
-/i
-/j
-/k
-/l
-/m
-/n
-/o
-/p
-/q
-/r
-/s
-/t
-/u
-/v
-/w
-/x
-/y
-/z
-/braceleft
-/bar
-/braceright
-/asciitilde
-/sfthyphen
-/Agrave
-/Aacute
-/Atilde
-/Ahookabove
-/Adotbelow
-/Acircumflex
-/Acircumflexgrave
-/Acircumflexacute
-/Acircumflextilde
-/Acircumflexhookabove
-/Acircumflexdotbelow
-/Abreve
-/Abrevegrave
-/Abreveacute
-/Abrevetilde
-/Abrevehookabove
-/Abrevedotbelow
-/Egrave
-/Eacute
-/Etilde
-/Ehookabove
-/Edotbelow
-/Ecircumflex
-/Ecircumflexgrave
-/Ecircumflexacute
-/Ecircumflextilde
-/Ecircumflexhookabove
-/Ecircumflexdotbelow
-/Igrave
-/Iacute
-/Itilde
-/Ihookabove
-/agrave
-/aacute
-/atilde
-/ahookabove
-/adotbelow
-/acircumflex
-/acircumflexgrave
-/acircumflexacute
-/acircumflextilde
-/acircumflexhookabove
-/acircumflexdotbelow
-/abreve
-/abrevegrave
-/abreveacute
-/abrevetilde
-/abrevehookabove
-/abrevedotbelow
-/egrave
-/eacute
-/etilde
-/ehookabove
-/edotbelow
-/ecircumflex
-/ecircumflexgrave
-/ecircumflexacute
-/ecircumflextilde
-/ecircumflexhookabove
-/ecircumflexdotbelow
-/igrave
-/iacute
-/itilde
-/ihookabove
-/Idotbelow
-/Ograve
-/Oacute
-/Otilde
-/Ohookabove
-/Odotbelow
-/Ocircumflex
-/Ocircumflexgrave
-/Ocircumflexacute
-/Ocircumflextilde
-/Ocircumflexhookabove
-/Ocircumflexdotbelow
-/Ohorn
-/Ohorngrave
-/Ohornacute
-/Ohorntilde
-/Ohornhookabove
-/Ohorndotbelow
-/Ugrave
-/Uacute
-/Utilde
-/Uhookabove
-/Udotbelow
-/Uhorn
-/Uhorngrave
-/Uhornacute
-/Uhorntilde
-/Uhornhookabove
-/Uhorndotbelow
-/Ygrave
-/Yacute
-/Ytilde
-/idotbelow
-/ograve
-/oacute
-/otilde
-/ohookabove
-/odotbelow
-/ocircumflex
-/ocircumflexgrave
-/ocircumflexacute
-/ocircumflextilde
-/ocircumflexhookabove
-/ocircumflexdotbelow
-/ohorn
-/ohorngrave
-/ohornacute
-/ohorntilde
-/ohornhookabove
-/ohorndotbelow
-/ugrave
-/uacute
-/utilde
-/uhookabove
-/udotbelow
-/uhorn
-/uhorngrave
-/uhornacute
-/uhorntilde
-/uhornhookabove
-/uhorndotbelow
-/ygrave
-/yacute
-/ytilde
-] def
diff --git a/fonts/enc/dvips/context/lm-texnansi-os.enc b/fonts/enc/dvips/context/lm-texnansi-os.enc
deleted file mode 100644
index 059dd788b..000000000
--- a/fonts/enc/dvips/context/lm-texnansi-os.enc
+++ /dev/null
@@ -1,258 +0,0 @@
-/enclmtexnansi[
-/.notdef
-/Euro
-/.notdef
-/.notdef
-/fraction
-/dotaccent
-/hungarumlaut
-/ogonek
-/fl
-/.notdef
-/cwm
-/ff
-/fi
-/.notdef
-/ffi
-/ffl
-/dotlessi
-/dotlessj
-/grave
-/acute
-/caron
-/breve
-/macron
-/ring
-/cedilla
-/germandbls
-/ae
-/oe
-/oslash
-/AE
-/OE
-/Oslash
-/space
-/exclam
-/quotedbl
-/numbersign
-/dollar
-/percent
-/ampersand
-/quoteright
-/parenleft
-/parenright
-/asterisk
-/plus
-/comma
-/hyphen
-/period
-/slash
-/zero.oldstyle
-/one.oldstyle
-/two.oldstyle
-/three.oldstyle
-/four.oldstyle
-/five.oldstyle
-/six.oldstyle
-/seven.oldstyle
-/eight.oldstyle
-/nine.oldstyle
-/colon
-/semicolon
-/less
-/equal
-/greater
-/question
-/at
-/A
-/B
-/C
-/D
-/E
-/F
-/G
-/H
-/I
-/J
-/K
-/L
-/M
-/N
-/O
-/P
-/Q
-/R
-/S
-/T
-/U
-/V
-/W
-/X
-/Y
-/Z
-/bracketleft
-/backslash
-/bracketright
-/circumflex
-/underscore
-/quoteleft
-/a
-/b
-/c
-/d
-/e
-/f
-/g
-/h
-/i
-/j
-/k
-/l
-/m
-/n
-/o
-/p
-/q
-/r
-/s
-/t
-/u
-/v
-/w
-/x
-/y
-/z
-/braceleft
-/bar
-/braceright
-/tilde
-/dieresis
-/Lslash
-/quotesingle
-/quotesinglbase
-/florin
-/quotedblbase
-/ellipsis
-/dagger
-/daggerdbl
-/circumflex.dup
-/perthousand
-/Scaron
-/guilsinglleft
-/OE.dup
-/Zcaron
-/asciicircum
-/minus
-/lslash
-/quoteleft.dup
-/quoteright.dup
-/quotedblleft
-/quotedblright
-/bullet
-/endash
-/emdash
-/tilde.dup
-/trademark
-/scaron
-/guilsinglright
-/oe.dup
-/zcaron
-/asciitilde
-/Ydieresis
-/nbspace
-/exclamdown
-/cent
-/sterling
-/currency
-/yen
-/brokenbar
-/section
-/dieresis.dup
-/copyright
-/ordfeminine
-/guillemotleft
-/logicalnot
-/sfthyphen
-/registered
-/macron.dup
-/degree
-/plusminus
-/twosuperior
-/threesuperior
-/acute.dup
-/mu
-/paragraph
-/periodcentered
-/cedilla.dup
-/onesuperior
-/ordmasculine
-/guillemotright
-/onequarter
-/onehalf
-/threequarters
-/questiondown
-/Agrave
-/Aacute
-/Acircumflex
-/Atilde
-/Adieresis
-/Aring
-/AE.dup
-/Ccedilla
-/Egrave
-/Eacute
-/Ecircumflex
-/Edieresis
-/Igrave
-/Iacute
-/Icircumflex
-/Idieresis
-/Eth
-/Ntilde
-/Ograve
-/Oacute
-/Ocircumflex
-/Otilde
-/Odieresis
-/multiply
-/Oslash.dup
-/Ugrave
-/Uacute
-/Ucircumflex
-/Udieresis
-/Yacute
-/Thorn
-/germandbls.dup
-/agrave
-/aacute
-/acircumflex
-/atilde
-/adieresis
-/aring
-/ae.dup
-/ccedilla
-/egrave
-/eacute
-/ecircumflex
-/edieresis
-/igrave
-/iacute
-/icircumflex
-/idieresis
-/eth
-/ntilde
-/ograve
-/oacute
-/ocircumflex
-/otilde
-/odieresis
-/divide
-/oslash.dup
-/ugrave
-/uacute
-/ucircumflex
-/udieresis
-/yacute
-/thorn
-/ydieresis
-] def
diff --git a/fonts/enc/dvips/context/q-8r.enc b/fonts/enc/dvips/context/q-8r.enc
new file mode 100644
index 000000000..be8b32613
--- /dev/null
+++ b/fonts/enc/dvips/context/q-8r.enc
@@ -0,0 +1,264 @@
+% This file could belong to the TeX Gyre collection of fonts,
+% but is only needed and thus distributed with ConTeXt macro package.
+%
+% It provides 8r encoding compatible with TeX Gyre fonts and is used to enable
+% substituting Adobe fonts by TeX Gyre in pxfonts & txfonts.
+%
+/encq8r [
+/.notdef
+/dotaccent
+/fi
+/fl
+/fraction
+/hungarumlaut
+/Lslash
+/lslash
+/ogonek
+/ring
+/.notdef
+/breve
+/minus
+/.notdef
+/Zcaron
+/zcaron
+/caron
+/dotlessi
+/dotlessj
+/ff
+/ffi
+/ffl
+/notequal
+/infinity
+/lessequal
+/greaterequal
+/partialdiff
+/summation
+/product
+/pi
+/grave
+/quotesingle
+/space
+/exclam
+/quotedbl
+/numbersign
+/dollar
+/percent
+/ampersand
+/quoteright
+/parenleft
+/parenright
+/asterisk
+/plus
+/comma
+/hyphen
+/period
+/slash
+/zero
+/one
+/two
+/three
+/four
+/five
+/six
+/seven
+/eight
+/nine
+/colon
+/semicolon
+/less
+/equal
+/greater
+/question
+/at
+/A
+/B
+/C
+/D
+/E
+/F
+/G
+/H
+/I
+/J
+/K
+/L
+/M
+/N
+/O
+/P
+/Q
+/R
+/S
+/T
+/U
+/V
+/W
+/X
+/Y
+/Z
+/bracketleft
+/backslash
+/bracketright
+/asciicircum
+/underscore
+/quoteleft
+/a
+/b
+/c
+/d
+/e
+/f
+/g
+/h
+/i
+/j
+/k
+/l
+/m
+/n
+/o
+/p
+/q
+/r
+/s
+/t
+/u
+/v
+/w
+/x
+/y
+/z
+/braceleft
+/bar
+/braceright
+/asciitilde
+/.notdef
+/Euro
+/integral
+/quotesinglbase
+/florin
+/quotedblbase
+/ellipsis
+/dagger
+/daggerdbl
+/circumflex
+/perthousand
+/Scaron
+/guilsinglleft
+/OE
+/Omega
+/radical
+/approxequal
+/.notdef
+/.notdef
+/.notdef
+/quotedblleft
+/quotedblright
+/bullet
+/endash
+/emdash
+/tilde
+/trademark
+/scaron
+/guilsinglright
+/oe
+/Delta
+/lozenge
+/Ydieresis
+/.notdef
+/exclamdown
+/cent
+/sterling
+/currency
+/yen
+/brokenbar
+/section
+/dieresis
+/copyright
+/ordfeminine
+/guillemotleft
+/logicalnot
+/hyphen
+/registered
+/macron
+/degree
+/plusminus
+/two.superior
+/three.superior
+/acute
+/mu
+/paragraph
+/periodcentered
+/cedilla
+/one.superior
+/ordmasculine
+/guillemotright
+/onequarter
+/onehalf
+/threequarters
+/questiondown
+/Agrave
+/Aacute
+/Acircumflex
+/Atilde
+/Adieresis
+/Aring
+/AE
+/Ccedilla
+/Egrave
+/Eacute
+/Ecircumflex
+/Edieresis
+/Igrave
+/Iacute
+/Icircumflex
+/Idieresis
+/Eth
+/Ntilde
+/Ograve
+/Oacute
+/Ocircumflex
+/Otilde
+/Odieresis
+/multiply
+/Oslash
+/Ugrave
+/Uacute
+/Ucircumflex
+/Udieresis
+/Yacute
+/Thorn
+/germandbls
+/agrave
+/aacute
+/acircumflex
+/atilde
+/adieresis
+/aring
+/ae
+/ccedilla
+/egrave
+/eacute
+/ecircumflex
+/edieresis
+/igrave
+/iacute
+/icircumflex
+/idieresis
+/eth
+/ntilde
+/ograve
+/oacute
+/ocircumflex
+/otilde
+/odieresis
+/divide
+/oslash
+/ugrave
+/uacute
+/ucircumflex
+/udieresis
+/yacute
+/thorn
+/ydieresis
+] def
diff --git a/fonts/map/dvips/context/contnav.map b/fonts/map/dvips/context/contnav.map
new file mode 100644
index 000000000..942798c57
--- /dev/null
+++ b/fonts/map/dvips/context/contnav.map
@@ -0,0 +1 @@
+contnav ContextNavigation chem_setting_scale :
+ chem_setting_scale := scale ;
+ chem_init_all ;
+ fi ;
+ chem_rotation := 1 ;
+ chem_adjacent := 0 ;
+ chem_substituent := 0 ;
+ chem_direction := 0 ;
+ chem_stack_n := 0 ;
+ chem_doing_pb := false ;
+ chem_shift := origin ;
+enddef ;
+
+def chem_stop_structure =
+ currentpicture := currentpicture shifted - chem_shift ;
+ % axis here
+ if chem_setting_fixedwidth :
+ chem_setting_l := - xpart llcorner currentpicture ;
+ chem_setting_r := xpart urcorner currentpicture ;
+ fi ;
+ if chem_setting_fixedheight :
+ chem_setting_t := ypart urcorner currentpicture ;
+ chem_setting_b := - ypart llcorner currentpicture ;
+ fi ;
+ chem_setting_bbox :=
+ (-chem_setting_l,-chem_setting_b) -- ( chem_setting_r,-chem_setting_b) --
+ ( chem_setting_r, chem_setting_t) -- (-chem_setting_l, chem_setting_t) -- cycle ;
+ % maybe put it behind the picture
+ if chem_setting_axis :
+ save stp ; stp := chem_base_width/ 2 * chem_setting_scale ;
+ save siz ; siz := chem_base_width/10 * chem_setting_scale ;
+ draw (-chem_setting_l,0) -- (chem_setting_r,0) withcolor blue ;
+ draw (0,-chem_setting_b) -- (0,chem_setting_t) withcolor blue ;
+ for i = 0 step stp until chem_setting_r : draw (i,-siz) -- (i,siz) withcolor blue ; endfor ;
+ for i = 0 step -stp until -chem_setting_l : draw (i,-siz) -- (i,siz) withcolor blue ; endfor ;
+ for i = 0 step stp until chem_setting_t : draw (-siz,i) -- (siz,i) withcolor blue ; endfor ;
+ for i = 0 step -stp until -chem_setting_b : draw (-siz,i) -- (siz,i) withcolor blue ; endfor ;
+ draw chem_setting_bbox withcolor blue ;
+ fi ;
+ setbounds currentpicture to chem_setting_bbox ;
+enddef ;
+
+def chem_start_component =
+enddef ;
+def chem_stop_component =
+enddef ;
+
+def chem_pb =
+% draw boundingbox currentpicture withpen pencircle scaled 1mm withcolor blue ;
+% draw origin withpen pencircle scaled 2mm withcolor blue ;
+ chem_doing_pb := true ;
+enddef ;
+def chem_pe =
+% draw boundingbox currentpicture withpen pencircle scaled .5mm withcolor red ;
+% draw origin withpen pencircle scaled 1mm withcolor red ;
+ currentpicture := currentpicture shifted - chem_shift ;
+% draw origin withpen pencircle scaled .5mm withcolor green ;
+ chem_shift := origin ;
+ chem_doing_pb := false ;
+enddef ;
+
+vardef chem_do (expr p) =
+ if chem_doing_pb :
+ chem_doing_pb := false ;
+% save pp ; pair pp ; pp := point 1 of ((origin -- p) enlonged chem_picture_offset) ;
+% currentpicture := currentpicture shifted - pp ;
+% chem_shift := chem_shift - center pp ;
+ currentpicture := currentpicture shifted - p ;
+ chem_shift := chem_shift - p ;
+ origin % nullpicture
+ else :
+ p
+ fi
+enddef ;
+
+vardef chem_b (expr n, f, t, r, c) =
+ chem_draw (n, chem_b_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_sb (expr n, f, t, r, c) =
+ chem_draw (n, chem_sb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_s (expr n, f, t, r, c) =
+ chem_draw (n, chem_s_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_ss (expr n, f, t, r, c) =
+ chem_draw (n, chem_ss_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_mid (expr n, r, c) =
+ chem_draw_fixed (n, chem_midt_path[n], r, c) ;
+ chem_draw_fixed (n, chem_midb_path[n], r, c) ;
+enddef ;
+vardef chem_mids (expr n, r, c) =
+ chem_draw_fixed (n, chem_midst_path[n], r, c) ;
+ chem_draw_fixed (n, chem_midsb_path[n], r, c) ;
+enddef ;
+vardef chem_mss (expr n, f, t, r, c) =
+ chem_draw (n, chem_mss_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_pss (expr n, f, t, r, c) =
+ chem_draw (n, chem_pss_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_msb (expr n, f, t, r, c) =
+ chem_draw (n, chem_msb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_psb (expr n, f, t, r, c) =
+ chem_draw (n, chem_psb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_eb (expr n, f, t, r, c) =
+ chem_draw (n, chem_eb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_db (expr n, f, t, r, c) =
+ if n = 1 :
+ chem_draw (n, chem_msb_path [n], f, t, r, c) ;
+ chem_draw (n, chem_psb_path [n], f, t, r, c) ;
+ else :
+ chem_draw (n, chem_dbl_path [n], f, t, r, c) ;
+ chem_draw (n, chem_dbr_path [n], f, t, r, c) ;
+ fi ;
+enddef ;
+vardef chem_er (expr n, f, t, r, c) =
+ chem_draw (n, chem_rl_path[n], f, t, r, c) ;
+ chem_draw (n, chem_rr_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_dr (expr n, f, t, r, c) =
+ chem_draw (n, chem_srl_path[n], f, t, r, c) ;
+ chem_draw (n, chem_srr_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_ad (expr n, f, t, r, c) =
+ chem_draw_arrow(n, chem_ad_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_au (expr n, f, t, r, c) =
+ chem_draw_arrow(n, chem_au_path[n], f, t, r, c)
+enddef ;
+vardef chem_r (expr n, f, t, r, c) =
+ if n < 0 :
+ chem_draw_vertical (n, chem_r_path[n], f, t, r, c) ;
+ else :
+ chem_draw (n, chem_r_path[n], f, t, r, c) ;
+ fi ;
+enddef ;
+vardef chem_rd (expr n, f, t, r, c) =
+ chem_dashed_normal (n, chem_r_path[n], f, t, r, c)
+enddef ;
+vardef chem_mrd (expr n, f, t, r, c) =
+ chem_dashed_normal (n, chem_mr_path[n], f, t, r, c)
+enddef ;
+vardef chem_prd (expr n, f, t, r, c) =
+ chem_dashed_normal (n, chem_pr_path[n], f, t, r, c)
+enddef ;
+vardef chem_br (expr n, f, t, r, c) =
+ chem_fill (n, chem_br_path[n], f, t, r, c )
+enddef ;
+vardef chem_rb (expr n, f, t, r, c) =
+ chem_fill (n, chem_rb_path[n], f, t, r, c)
+enddef ;
+vardef chem_mrb (expr n, f, t, r, c) =
+ chem_fill (n, chem_mrb_path[n], f, t, r, c)
+enddef ;
+vardef chem_prb (expr n, f, t, r, c) =
+ chem_fill (n, chem_prb_path[n], f, t, r, c)
+enddef ;
+vardef chem_mr (expr n, f, t, r, c) =
+ if n < 0 :
+ chem_draw_vertical(n, chem_mr_path[n], f, t, r, c)
+ else :
+ chem_draw (n, chem_mr_path[n], f, t, r, c)
+ fi
+enddef ;
+vardef chem_pr (expr n, f, t, r, c) =
+ if n < 0 :
+ chem_draw_vertical(n, chem_pr_path[n], f, t, r, c)
+ else :
+ chem_draw (n, chem_pr_path[n], f, t, r, c)
+ fi
+enddef ;
+vardef chem_sr (expr n, f, t, r, c) =
+ chem_draw (n, chem_sr_path[n], f, t, r, c)
+enddef ;
+vardef chem_msr (expr n, f, t, r, c) =
+ chem_draw (n, chem_msr_path[n], f, t, r, c)
+enddef ;
+vardef chem_psr (expr n, f, t, r, c) =
+ chem_draw (n, chem_psr_path[n], f, t, r, c)
+enddef ;
+vardef chem_c (expr n, f, t, r, c) =
+ chem_draw (n, chem_c_path[n], f, t, r, c)
+enddef ;
+vardef chem_cc (expr n, f, t, r, c) =
+ chem_draw (n, chem_cc_path[n], f, f, r, c)
+enddef ;
+vardef chem_cd (expr n, f, t, r, c) =
+ chem_dashed_connected (n, chem_c_path[n], f, t, r, c)
+enddef ;
+vardef chem_ccd (expr n, f, t, r, c) =
+ chem_dashed_normal (n, chem_cc_path[n], f, f, r, c)
+enddef ;
+vardef chem_rn (expr n, i, t) =
+ chem_rt (n,i,t) ;
+enddef ;
+vardef chem_rtn (expr n, i, t) =
+ chem_rtt(n,i,t) ;
+enddef ;
+vardef chem_rbn (expr n, i, t) =
+ chem_rbt(n,i,t) ;
+enddef ;
+vardef chem_tb (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_msb_path[n], f, t, r, c) ;
+ chem_draw (n, chem_sb_path [n], f, t, r, c) ;
+ chem_draw (n, chem_psb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_ep (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_e_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_es (expr n, f, t, r, c) = % one
+ chem_draw_dot (n, center chem_e_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_ed (expr n, f, t, r, c) = % one
+ chem_draw_dot (n, point 0 of chem_e_path[n], f, t, r, c) ;
+ chem_draw_dot (n, point 1 of chem_e_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_et (expr n, f, t, r, c) = % one
+ chem_draw_dot (n, point 0 of chem_e_path[n], f, t, r, c) ;
+ chem_draw_dot (n, center chem_e_path[n], f, t, r, c) ;
+ chem_draw_dot (n, point 1 of chem_e_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_sd (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_ddt_path[n], f, t, r, c) ;
+ chem_draw (n, chem_ddb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_rdd (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_ldt_path[n], f, t, r, c) ;
+ chem_draw (n, chem_ldb_path[n], f, t, r, c) ;
+ chem_draw (n, chem_psb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_ldd (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_msb_path[n], f, t, r, c) ;
+ chem_draw (n, chem_rdt_path[n], f, t, r, c) ;
+ chem_draw (n, chem_rdb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_hb (expr n, f, t, r, c) = % one
+ chem_draw_dot (n, point 0 of chem_sb_path[n], f, t, r, c) ;
+ chem_draw_dot (n, center chem_sb_path[n], f, t, r, c) ;
+ chem_draw_dot (n, point 1 of chem_sb_path[n], f, t, r, c) ;
+enddef ;
+vardef chem_bb (expr n, f, t, r, c) = % one
+ if n < 0 :
+ chem_fill (n, chem_bb_path[n], 1, 1, r, c) ;
+ chem_b (n, f, t, r, c) ;
+ else :
+ chem_fill (n, chem_bb_path[n], f, t, r, c) ;
+ fi ;
+enddef ;
+vardef chem_oe (expr n, f, t, r, c) = % one
+ chem_draw (n, chem_oe_path[n], f, t, r, c) ;
+enddef ;
+
+vardef chem_z_zero@#(text t) =
+ chem_text@#(t, chem_do(origin)) ;
+enddef ;
+vardef chem_cz_zero@#(text t) =
+ chem_text@#(t, chem_do(origin)) ;
+enddef ;
+vardef chem_z@#(expr n, p) (text t) =
+ if p = 0 :
+ chem_text@#(t, chem_do(origin)) ;
+ else :
+ chem_text@#(t, chem_do(chem_b_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_cz@#(expr n, p) (text t) =
+ if n = 1 :
+ chem_c_text(t, chem_do(chem_crz_zero[n] rotated chem_ang(n,p))) ;
+ else :
+ chem_text@#(t, chem_do(chem_b_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_midz@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_mid_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_rz@#(expr n, p) (text t) =
+ if n < 0 :
+ % quite special
+ chem_text@#(t, chem_do(chem_r_zero[n] shifted (chem_b_zero[n] rotated chem_ang(n,p)))) ;
+ else :
+ chem_text@#(t, chem_do(chem_r_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_crz@#(expr n, p) (text tx) =
+ chem_text(tx, chem_do(chem_crz_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_mrz@#(expr n, p) (text t) =
+ if n < 0 :
+ % quite special
+ chem_text@#(t, chem_do(chem_mr_zero[n] shifted (chem_b_zero[n] rotated chem_ang(n,p)))) ;
+ else :
+ chem_text@#(t, chem_do(chem_mr_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_prz@#(expr n, p) (text t) =
+ if n < 0 :
+ % quite special
+ chem_text@#(t, chem_do(chem_pr_zero[n] shifted (chem_b_zero[n] rotated chem_ang(n,p)))) ;
+ else :
+ chem_text@#(t, chem_do(chem_pr_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_rt@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_rtt@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rtt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_rbt@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rbt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_zt@#(expr n, p) (text t) =
+ if n = 1 :
+ chem_text@#(t, chem_do(chem_rt_zero[n] rotated chem_ang(n,p))) ;
+ else :
+ chem_text@#(t, chem_do(chem_n_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_zn@#(expr n, p) (text t) =
+ if n = 1 :
+ chem_text@#(t, chem_do(chem_rt_zero[n] rotated chem_ang(n,p))) ;
+ else :
+ chem_text@#(t, chem_do(chem_n_zero[n] rotated chem_ang(n,p))) ;
+ fi ;
+enddef ;
+vardef chem_zbt@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rtt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_zbn@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rtt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_ztt@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rbt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+vardef chem_ztn@#(expr n, p) (text t) =
+ chem_text@#(t, chem_do(chem_rbt_zero[n] rotated chem_ang(n,p))) ;
+enddef ;
+
+vardef chem_symbol(expr t) =
+ draw textext(t) ;
+enddef ;
+
+vardef chem_text@#(expr txt, z) = % adapted copy of thelabel@
+ save p ; picture p ;
+ p := textext(txt) ;
+ p := p
+ if (labtype@# >= 10) : shifted (0,ypart center p) fi
+ shifted (z + chem_text_offset*laboff@# - (labxf@#*lrcorner p + labyf@#*ulcorner p + (1-labxf@#-labyf@#)*llcorner p)) ;
+ if chem_text_trace :
+ draw z withpen pencircle scaled 2pt withcolor red ;
+ draw boundingbox p withpen pencircle scaled 1pt withcolor red ;
+ fi ;
+ draw p
+enddef ;
+
+vardef chem_c_text(expr txt, z) = % adapted copy of thelabel@
+ save p ; picture p ; p := textext(txt) ;
+ save b ; path b ; b := (boundingbox p) shifted z ;
+ save a ; pair a ; a := (origin--z) intersection_point b ;
+ if intersection_found :
+ draw p shifted (z enlonged arclength(a -- center b)) ;
+ else :
+ draw p shifted z ;
+ fi
+% draw b withcolor green ;
+% draw a withcolor red ;
+enddef ;
+
+vardef chem_ang (expr n, d) =
+ ((-1 * (d-1) * chem_angle[n]) + (-chem_rotation+1) * 90 + chem_start[n]) % no ;
+enddef ;
+vardef chem_rot (expr n, d) =
+ chem_rotation := d ;
+enddef ;
+vardef chem_adj (expr n, d) =
+ chem_adjacent := d ;
+enddef ;
+vardef chem_sub (expr n, d) =
+ chem_substituent := d ;
+enddef ;
+vardef chem_dir (expr n, d) =
+ if n = 1 :
+ chem_direction_p := (origin - 2*center(chem_b_path[n] rotated chem_ang(n,d+1))) ;
+ currentpicture := currentpicture shifted chem_direction_p ;
+ chem_shift := chem_shift + chem_direction_p ;
+ fi ;
+enddef ;
+vardef chem_mov (expr n, d) =
+ if d = 0 :
+ currentpicture := currentpicture shifted - chem_shift ;
+ chem_shift := origin ;
+ else :
+ chem_move_p := (origin - 2*center(chem_b_path[n] rotated chem_ang(n,d+chem_initialmov[n]))) ;
+ currentpicture := currentpicture shifted chem_move_p ;
+ chem_shift := chem_shift + chem_move_p ;
+ fi ;
+enddef ;
+vardef chem_off (expr n, d) =
+ if (d = 1) or (d = 2) or (d = 8) : % positive
+ currentpicture := currentpicture shifted (-chem_setting_offset,0) ;
+ chem_shift := chem_shift + (-chem_setting_offset,0)
+ elseif (d = 4) or (d = 5) or (d = 6) : % negative
+ currentpicture := currentpicture shifted ( chem_setting_offset,0) ;
+ chem_shift := chem_shift + ( chem_setting_offset,0)
+ fi ;
+enddef ;
+
+vardef chem_set(expr n, m) =
+ if chem_adjacent > 0 :
+ chem_adjacent_d := xpart chem_b_zero[n] + xpart chem_b_zero[m] ;
+ if chem_adjacent = 1 : chem_adjacent_p := (-chem_adjacent_d, 0) ;
+ elseif chem_adjacent = 2 : chem_adjacent_p := (0, -chem_adjacent_d) ;
+ elseif chem_adjacent = 3 : chem_adjacent_p := ( chem_adjacent_d, 0) ;
+ elseif chem_adjacent = 4 : chem_adjacent_p := (0, chem_adjacent_d) ;
+ else : chem_adjacent_p := origin ;
+ fi ;
+ currentpicture := currentpicture shifted chem_adjacent_p ;
+ chem_shift := chem_shift + chem_adjacent_p ;
+ chem_adjacent := 0 ;
+ fi ;
+ if chem_substituent > 0 :
+ if m = 1 :
+ chem_substituent_d := xpart chem_crz_zero[n] + chem_substituent_offset ;
+ else :
+ chem_substituent_d := xpart chem_crz_zero[n] + xpart chem_b_zero[m] ;
+ fi ;
+ if chem_substituent = 1 : chem_substituent_p := (-chem_substituent_d, 0) ; % - ?
+ elseif chem_substituent = 2 : chem_substituent_p := (0, chem_substituent_d) ;
+ elseif chem_substituent = 3 : chem_substituent_p := ( chem_substituent_d, 0) ;
+ elseif chem_substituent = 4 : chem_substituent_p := (0, -chem_substituent_d) ;
+ else : chem_substituent_p := origin ;
+ fi ;
+ currentpicture := currentpicture shifted chem_substituent_p ;
+ chem_shift := chem_shift + chem_substituent_p ;
+ chem_substituent := 0 ;
+ fi ;
+ chem_rotation := chem_initialrot[m] ;
+enddef ;
+
+vardef chem_draw (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ for i:=from_point upto to_point:
+ draw (path_fragment rotated chem_ang(n,i)) withpen pencircle scaled linewidth withcolor linecolor ;
+ endfor ;
+enddef ;
+vardef chem_fill (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ for i:=from_point upto to_point:
+ fill (path_fragment rotated chem_ang(n,i)) withpen pencircle scaled 0 withcolor linecolor ;
+ endfor ;
+enddef ;
+
+vardef chem_dashed_normal (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ for i:=from_point upto to_point:
+ draw (path_fragment rotated chem_ang(n,i)) withpen pencircle scaled linewidth withcolor linecolor dashed evenly ;
+ endfor ;
+enddef ;
+vardef chem_dashed_connected (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ draw for i:=from_point upto to_point:
+ (path_fragment rotated chem_ang(n,i)) if i < to_point : -- fi
+ endfor withpen pencircle scaled linewidth withcolor linecolor dashed evenly ;
+enddef ;
+vardef chem_draw_dot (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ for i:=from_point upto to_point:
+ draw (path_fragment rotated chem_ang(n,i)) withpen pencircle scaled (chem_dot_factor*linewidth) withcolor linecolor ;
+ endfor ;
+enddef ;
+vardef chem_draw_fixed (expr n, path_fragment, linewidth, linecolor) =
+ draw (path_fragment rotated chem_ang(n,1)) withpen pencircle scaled linewidth withcolor linecolor ;
+enddef ;
+vardef chem_draw_arrow (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ for i:=from_point upto to_point:
+ drawarrow (path_fragment rotated chem_ang(n,i)) withpen pencircle scaled linewidth withcolor linecolor ;
+ endfor ;
+enddef ;
+vardef chem_draw_vertical (expr n, path_fragment, from_point, to_point, linewidth, linecolor) =
+ % quite special
+ for i:=from_point upto to_point:
+ draw (path_fragment shifted (chem_b_zero[n] rotated chem_ang(n,i))) withpen pencircle scaled linewidth withcolor linecolor ;
+ endfor ;
+enddef ;
+
+picture chem_stack_p[] ;
+pair chem_stack_shift[] ;
+
+vardef chem_save =
+ chem_stack_n := chem_stack_n + 1 ;
+ chem_stack_p[chem_stack_n] := currentpicture ;
+ chem_stack_shift[chem_stack_n] := chem_shift ;
+ chem_shift := origin ;
+% chem_adjacent := 0 ;
+% chem_substituent := 0 ;
+% chem_rotation := 1 ;
+ currentpicture := nullpicture ;
+enddef ;
+vardef chem_restore =
+ if chem_stack_n > 0 :
+ currentpicture := currentpicture shifted - chem_shift ;
+ addto chem_stack_p[chem_stack_n] also currentpicture ;
+ currentpicture := chem_stack_p[chem_stack_n] ;
+ chem_stack_p[chem_stack_n] := nullpicture ;
+ chem_shift := chem_stack_shift[chem_stack_n] ;
+ chem_stack_n := chem_stack_n - 1 ;
+ fi ;
+enddef ;
+
+def chem_init_some(expr n, ratio, angle, start, initialrot, initialmov) =
+ chem_width [n] := ratio * chem_base_width * chem_setting_scale ;
+ chem_angle [n] := angle ;
+ chem_start [n] := start ;
+ chem_initialrot[n] := initialrot ;
+ chem_initialmov[n] := initialmov ;
+ chem_b_zero [n] := (chem_width[n],0) rotated (angle/2) ;
+ chem_n_zero [n] := (chem_text_min*chem_width[n],0) rotated (angle/2) ;
+ chem_r_max [n] := chem_radical_max*chem_b_zero[n] ;
+ chem_r_path [n] := chem_b_zero[n] -- chem_r_max[n] ;
+ chem_mr_path [n] := chem_r_path [n] rotatedaround(chem_b_zero[n], (180-angle)/2) ;
+ chem_pr_path [n] := chem_r_path [n] rotatedaround(chem_b_zero[n],-(180-angle)/2) ;
+ chem_r_zero [n] := point 1 of chem_r_path [n] ;
+ chem_mr_zero [n] := point 1 of chem_mr_path[n] ;
+ chem_pr_zero [n] := point 1 of chem_pr_path[n] ;
+ chem_crz_zero [n] := point 1 of (chem_r_path[n] enlonged chem_center_offset) ;
+ chem_au_path [n] := subpath (0.2,0.8) of (chem_r_max[n] -- (chem_r_max[n] rotated angle)) ;
+ chem_ad_path [n] := reverse(chem_au_path[n]) ;
+ chem_rt_zero [n] := (((chem_radical_max+chem_radical_min)/2)*chem_width[n],0) rotated (angle/2) ;
+ chem_rtt_zero [n] := chem_rt_zero[n] rotated + 10 ;
+ chem_rbt_zero [n] := chem_rt_zero[n] rotated - 10 ;
+ chem_b_path [n] := reverse(chem_b_zero[n] -- (chem_b_zero[n] rotated -angle)) ;
+ chem_bx_path [n] := reverse(chem_b_zero[n] -- (chem_b_zero[n] rotated -angle)) ; % ?
+ chem_sb_path [n] := subpath (0.25,0.75) of chem_b_path[n] ;
+ chem_s_path [n] := point 0 of chem_b_path[n] -- point 0 of (chem_b_path[n] rotated (2angle)) ;
+ chem_ss_path [n] := subpath (0.25,0.75) of (chem_s_path[n]) ;
+ chem_pss_path [n] := subpath (0.00,0.75) of (chem_s_path[n]) ;
+ chem_mss_path [n] := subpath (0.25,1.00) of (chem_s_path[n]) ;
+ chem_mid_zero [n] := origin shifted (-.25chem_width[n],0) ;
+ chem_midst_path[n] := chem_mid_zero[n] -- (chem_width[n],0) rotated ( angle + angle/2) ;
+ chem_midsb_path[n] := chem_mid_zero[n] -- (chem_width[n],0) rotated (-angle - angle/2) ;
+ chem_midt_path [n] := subpath (0.25,1.00) of chem_midst_path [n] ;
+ chem_midb_path [n] := subpath (0.25,1.00) of chem_midsb_path [n] ;
+ chem_msb_path [n] := subpath (0.00,0.75) of chem_b_path[n] ;
+ chem_psb_path [n] := subpath (0.25,1.00) of chem_b_path[n] ;
+ chem_dbl_path [n] := chem_sb_path[n] shifted - (0.05[origin,center chem_sb_path[n]]) ; % parallel
+ chem_dbr_path [n] := chem_sb_path[n] shifted + (0.05[origin,center chem_sb_path[n]]) ;
+ chem_eb_path [n] := chem_sb_path[n] shifted - (0.25[origin,center chem_sb_path[n]]) ;
+ chem_sr_path [n] := chem_radical_min*chem_b_zero[n] -- chem_r_max[n] ;
+ chem_rl_path [n] := chem_r_path[n] paralleled (chem_base_width/20) ;
+ chem_rr_path [n] := chem_r_path[n] paralleled -(chem_base_width/20) ;
+ chem_srl_path [n] := chem_sr_path[n] paralleled (chem_base_width/20) ;
+ chem_srr_path [n] := chem_sr_path[n] paralleled -(chem_base_width/20) ;
+ chem_br_path [n] := point 1 of chem_sb_path[n] --
+ point 0 of chem_sb_path[n] rotatedaround(point 1 of chem_sb_path[n], -4) --
+ point 0 of chem_sb_path[n] rotatedaround(point 1 of chem_sb_path[n], 4) -- cycle ;
+ chem_rb_path [n] := chem_b_zero[n] -- chem_r_max[n] rotated -2 -- chem_r_max[n] -- chem_r_max[n] rotated 2 -- cycle ;
+ chem_mrb_path [n] := chem_rb_path[n] rotatedaround(chem_b_zero[n], (180-angle)/2) ;
+ chem_prb_path [n] := chem_rb_path[n] rotatedaround(chem_b_zero[n],-(180-angle)/2) ;
+ chem_msr_path [n] := chem_sr_path[n] rotatedaround(chem_b_zero[n], (180-angle)/2) ;
+ chem_psr_path [n] := chem_sr_path[n] rotatedaround(chem_b_zero[n],-(180-angle)/2) ;
+ % not yet ok:
+ chem_c_path [n] := subpath (30/45, -30/45) of (fullcircle scaled (1.25*chem_circle_radius*chem_width[n]));
+ chem_cc_path [n] := subpath (30/45,8-30/45) of (fullcircle rotated 90 scaled (1.25*chem_circle_radius*chem_width[n]));
+enddef ;
+
+def chem_init_three = chem_init_some(3,30/52 ,120,-60,1,2) ; enddef ; % 60
+def chem_init_four = chem_init_some(4,30/42.5, 90, 0,1,0) ; enddef ; % 45
+def chem_init_five = chem_init_some(5,30/35 , 72, 0,1,0) ; enddef ; % 36
+def chem_init_six = chem_init_some(6, 1 , 60, 0,1,0) ; enddef ; % 30
+def chem_init_eight = chem_init_some(8,30/22.5, 45, 0,1,0) ; enddef ; % 22.5
+
+% bb R -R R Z -RZ +RZ
+
+def chem_init_some_front(expr n, ratio, angle, start, initialrot, initialmov) =
+ chem_init_some(n, ratio, angle, start, initialrot, initialmov) ;
+ chem_bb_path [n] := chem_b_path[n] rotated -angle -- chem_b_path[n] -- chem_b_path[n] rotated angle --
+ (reverse(chem_b_path[n] shortened (chem_base_width/20))) paralleled (chem_base_width/20) --
+ cycle ;
+ chem_r_max [n] := chem_radical_max*chem_b_zero[n] ;
+ chem_mr_path [n] := origin -- origin shifted (0,-.25chem_base_width) ;
+ chem_pr_path [n] := origin -- origin shifted (0, .25*chem_base_width) ;
+ chem_r_path [n] := point 1 of chem_mr_path[n] -- point 1 of chem_pr_path[n] ;
+ chem_mr_zero [n] := point 1 of chem_mr_path[n] ;
+ chem_pr_zero [n] := point 1 of chem_pr_path[n] ;
+enddef ;
+
+def chem_init_five_front = chem_init_some_front(-5,30/35,72,0,2,0) ; enddef ; % 36
+def chem_init_six_front = chem_init_some_front(-6, 1 ,60,0,2,0) ; enddef ; % 30
+
+def chem_init_one =
+ chem_width [1] := .75 * chem_base_width * chem_setting_scale ;
+ chem_angle [1] := 45 ;
+ chem_start [1] := 0 ;
+ chem_initialrot[1] := 1 ;
+ chem_initialmov[1] := 1 ;
+ chem_b_zero [1] := (1.75*chem_width[1],0) ;
+ chem_r_min [1] := chem_radical_min*chem_b_zero[1] ;
+ chem_r_max [1] := chem_radical_max*chem_b_zero[1] ;
+ chem_r_path [1] := (.5*chem_width[1],0) -- (1.25*chem_width[1],0) ;
+ chem_r_zero [1] := point 1 of chem_r_path [1] ;
+ chem_b_path [1] := chem_r_path[1] rotated + (chem_angle[1]) ; % used for move here
+ chem_b_zero [1] := chem_r_zero[1] ;
+ chem_crz_zero [1] := chem_r_zero[1] enlonged chem_center_offset ;
+ chem_e_path [1] := (.5*chem_width[1],-.25*chem_width[1]) -- (.5*chem_width[1],.25*chem_width[1]) ;
+ chem_sb_path [1] := chem_r_path [1] ;
+ chem_msb_path [1] := chem_r_path [1] shifted (0,-.1chem_width[1]) ;
+ chem_psb_path [1] := chem_r_path [1] shifted (0, .1chem_width[1]) ;
+ chem_ddt_path [1] := subpath(0,.4) of chem_r_path [1] ;
+ chem_ddb_path [1] := subpath(.6,1) of chem_r_path [1] ;
+ chem_ldt_path [1] := chem_ddt_path [1] shifted (0,-.1chem_width[1]) ; % parallel
+ chem_ldb_path [1] := chem_ddb_path [1] shifted (0,-.1chem_width[1]) ;
+ chem_rdt_path [1] := chem_ddt_path [1] shifted (0, .1chem_width[1]) ;
+ chem_rdb_path [1] := chem_ddb_path [1] shifted (0, .1chem_width[1]) ;
+ chem_bb_path [1] := point 0 of chem_r_path[1] --
+ point 1 of chem_r_path[1] rotatedaround(point 0 of chem_r_path[1], -4) --
+ point 1 of chem_r_path[1] rotatedaround(point 0 of chem_r_path[1], 4) -- cycle ;
+ chem_oe_path [1] := ((-20,0)--(10,0){up}..(20,10)..(30,0)..(40,-10)..(50.0,0)..(60,10)..(70,0)..(80,-10)..{up}(90,0)--(120,0))
+ xsized (.75*chem_width[1]) shifted point 0 of chem_r_path[1] ;
+ chem_rt_zero [1] := point .5 of chem_r_path[1] ;
+ chem_rtt_zero [1] := chem_rt_zero[1] rotated + (chem_angle[1]/2) ;
+ chem_rbt_zero [1] := chem_rt_zero[1] rotated - (chem_angle[1]/2) ;
+enddef ;
+
+def chem_init_all =
+ chem_init_one ;
+ chem_init_three ;
+ chem_init_four ;
+ chem_init_five ;
+ chem_init_six ;
+ chem_init_eight ;
+ chem_init_five_front ;
+ chem_init_six_front ;
+enddef ;
+
+chem_init_all ;
+
diff --git a/metapost/context/base/mp-core.mp b/metapost/context/base/mp-core.mp
index 0bf19b8a5..6720fe90d 100644
--- a/metapost/context/base/mp-core.mp
+++ b/metapost/context/base/mp-core.mp
@@ -346,6 +346,8 @@ boolean force_multi_par_chain ; force_multi_par_chain := true ;
boolean one_piece_multi_par ; one_piece_multi_par := false ;
boolean check_multi_par_chain ; check_multi_par_chain := true ; % extra page check
+boolean multi_column_first_page_hack; multi_column_first_page_hack := false ;
+
def simplify_multi_pars = % boundingbox ipv shape als optie
for i := 1 upto nofmultipars :
multipars[i] := boundingbox multipars[i] ;
@@ -428,8 +430,6 @@ def prepare_multi_pars (expr fn,fx,fy,fw,fh,fd,
numeric multi_par_pages ; multi_par_pages := nxy[tpos]-nxy[fpos]+1 ;
- ii := 0 ; nn := NOfTextAreas+1 ; nofmultipars := 0 ;
-
vardef snapped_multi_pos (expr p) =
if snap_multi_par_tops :
if abs(ypart p - ypart ulcorner multipar) < par_line_height :
@@ -502,7 +502,7 @@ def prepare_multi_pars (expr fn,fx,fy,fw,fh,fd,
vardef left_top_hang (expr same_area) =
-par_hang_after := ra + estimated_par_lines(py-fy) ;
+ par_hang_after := ra + estimated_par_lines(py-fy) ;
if (par_hang_indent>0) and (par_hang_after<0) and obey_multi_par_hang :
pair _ul_ ; _ul_ := (xpart ulcorner multipar, ypart snapped_multi_pos(ulxy[fpos]));
@@ -525,7 +525,7 @@ par_hang_after := ra + estimated_par_lines(py-fy) ;
vardef right_top_hang (expr same_area) =
-par_hang_after := ra + estimated_par_lines(py-fy) ;
+ par_hang_after := ra + estimated_par_lines(py-fy) ;
if (par_hang_indent<0) and (par_hang_after<0) and obey_multi_par_hang :
pair _ur_ ; _ur_ := (xpart urcorner multipar, ypart snapped_multi_pos(urxy[fpos])) ;
@@ -552,17 +552,15 @@ par_hang_after := ra + estimated_par_lines(py-fy) ;
pair _ul_ ; _ul_ := ulcorner multipar ;
pair _pa_ ; _pa_ := _ul_ shifted (0,par_hang_after*par_line_height) ;
_pa_ := (xpart _pa_,max(ypart _pa_,ypart llcorner multipar)) ;
-
-if t :
- _pa_ := (xpart _pa_,max(ypart _pa_,ypart llxy[tpos]));
-fi ;
-if abs(ypart _pa_-ypart llxy[tpos])=RealPageNumber) and (NOfTextColumns>1)) :
- % handled later
+ save_multipar (i,2,multipar) ;
+ else :
+ % handled later
fi ;
endfor ;
% second loop
-if force_multi_par_chain or (ii > 1) :
+ if force_multi_par_chain or (ii > 1) :
- for i=ii+1 upto nn-1 :
+ for i=ii+1 upto nn-1 :
- % rest of chain / todo : hang
+ % rest of chain / todo : hang
+% hm, the second+ column in column sets now gets lost in a NOfTextColumns
-if (not check_multi_par_chain) or ((nxy[fpos]RealPageNumber)) :
+ if (not check_multi_par_chain) or
+ ((nxy[fpos]RealPageNumber))
+ :
- multipar := set_multipar(i) ;
+ multipar := set_multipar(i) ;
- if obey_multi_par_hang and obey_multi_par_more :
+ if obey_multi_par_hang and obey_multi_par_more :
- multipar :=
- x_left_top_hang(i,false) --
- x_right_top_hang(i,false) --
- x_right_bottom_hang(i,false) --
- x_left_bottom_hang(i,false) --
- cycle ;
+ multipar :=
+ x_left_top_hang(i,false) --
+ x_right_top_hang(i,false) --
+ x_right_bottom_hang(i,false) --
+ x_left_bottom_hang(i,false) --
+ cycle ;
- fi ;
+ fi ;
- save_multipar(i,2,multipar) ;
+ save_multipar(i,2,multipar) ;
-fi ;
+ fi ;
- endfor ;
+ endfor ;
-fi ;
+ fi ;
% end of normal/fallback
@@ -1375,3 +1377,42 @@ enddef ;
endinput ;
end
+
+% for Jelle Huisman
+%
+% \setupcolors[state=start]
+% \dontcomplain
+% \definecolumnset[example][n=3,distance=5mm]
+% \startMPextensions
+% multi_column_first_page_hack := true ;
+% \stopMPextensions
+% \startuseMPgraphic{mpos:par:trick}
+% for i=1 upto nofmultipars-1 : draw (rightboundary multipars[i]) shifted (2.5mm, 0) ; endfor ;
+% \stopuseMPgraphic
+% \definetextbackground[test][mp=mpos:par:trick,method=mpos:par:columnset]
+% \starttext
+% \definecolumnsetspan[chapter][n=3]
+% \startcolumnset[example]
+% \startcolumnsetspan[chapter]
+% \chapter{Chapter One}
+% \stopcolumnsetspan
+% \starttextbackground[test] \dorecurse {3}{\input knuth } \stoptextbackground
+% \stopcolumnset
+% \startcolumnset[example]
+% \startcolumnsetspan[chapter]
+% \chapter{Chapter One}
+% \stopcolumnsetspan
+% \starttextbackground[test] \dorecurse {10}{\input knuth } \stoptextbackground
+% \stopcolumnset
+% \stoptext
+%
+% fast variant:
+%
+% \startuseMPgraphic{whatever}
+% for i=1 upto NOfTextColumns-1 :
+% draw (rightboundary TextColumns[i]) shifted (2.5mm,0) shifted -\MPxy\textanchor ;
+% endfor ;
+% setbounds currentpicture to OverlayBox ;
+% \stopuseMPgraphic
+% \defineoverlay[whatever][\useMPgraphic{whatever}]
+% \setupbackgrounds[text][background=whatever]
diff --git a/metapost/context/base/mp-mlib.mp b/metapost/context/base/mp-mlib.mp
index 134cd12a3..893222473 100644
--- a/metapost/context/base/mp-mlib.mp
+++ b/metapost/context/base/mp-mlib.mp
@@ -30,7 +30,9 @@ extra_endfig := ";addto currentpicture also _tt_p_; " & extra_endfig; % was dr
extra_beginfig := extra_beginfig & "resettextexts;";
vardef rawtextext(expr str) =
- if _trial_run_ :
+ if str = "" :
+ nullpicture
+ elseif _trial_run_ :
image (
_tt_n_ := _tt_n_ + 1 ;
_tt_p_ := image (
@@ -51,6 +53,8 @@ vardef rawtextext(expr str) =
fi
enddef ;
+% not ok yet
+
pair laboff.d, laboff.dlft, laboff.drt ; % new positional suffixes
pair laboff.origin, laboff.raw ; % graph mess
@@ -67,10 +71,66 @@ labtype.origin := 0 ; labtype.raw := 0 ;
laboff.origin = (infinity,infinity) ; labxf.origin := 0 ; labyf.origin := 0 ;
laboff.raw = (infinity,infinity) ; labxf.raw := 0 ; labyf.raw := 0 ;
+pair laboff.l ; laboff.l = laboff.lft ;
+pair laboff.r ; laboff.r = laboff.rt ;
+pair laboff.b ; laboff.b = laboff.bot ;
+pair laboff.t ; laboff.t = laboff.top ;
+pair laboff.l_t ; laboff.l_t = laboff.ulft ;
+pair laboff.r_t ; laboff.r_t = laboff.urt ;
+pair laboff.l_b ; laboff.l_b = laboff.llft ;
+pair laboff.r_b ; laboff.r_b = laboff.lrt ;
+pair laboff.t_l ; laboff.t_l = laboff.ulft ;
+pair laboff.t_r ; laboff.t_r = laboff.urt ;
+pair laboff.b_l ; laboff.b_l = laboff.llft ;
+pair laboff.b_r ; laboff.b_r = laboff.lrt ;
+
+labxf.l ; labxf.l = labxf.lft ;
+labxf.r ; labxf.r = labxf.rt ;
+labxf.b ; labxf.b = labxf.bot ;
+labxf.t ; labxf.t = labxf.top ;
+labxf.l_t ; labxf.l_t = labxf.ulft ;
+labxf.r_t ; labxf.r_t = labxf.urt ;
+labxf.l_b ; labxf.l_b = labxf.llft ;
+labxf.r_b ; labxf.r_b = labxf.lrt ;
+labxf.t_l ; labxf.t_l = labxf.ulft ;
+labxf.t_r ; labxf.t_r = labxf.urt ;
+labxf.b_l ; labxf.b_l = labxf.llft ;
+labxf.b_r ; labxf.b_r = labxf.lrt ;
+
+labyf.l ; labyf.l = labyf.lft ;
+labyf.r ; labyf.r = labyf.rt ;
+labyf.b ; labyf.b = labyf.bot ;
+labyf.t ; labyf.t = labyf.top ;
+labyf.l_t ; labyf.l_t = labyf.ulft ;
+labyf.r_t ; labyf.r_t = labyf.urt ;
+labyf.l_b ; labyf.l_b = labyf.llft ;
+labyf.r_b ; labyf.r_b = labyf.lrt ;
+labyf.t_l ; labyf.t_l = labyf.ulft ;
+labyf.t_r ; labyf.t_r = labyf.urt ;
+labyf.b_l ; labyf.b_l = labyf.llft ;
+labyf.b_r ; labyf.b_r = labyf.lrt ;
+
+labtype.l ; labtype.l = labtype.lft ;
+labtype.r ; labtype.r = labtype.rt ;
+labtype.b ; labtype.b = labtype.bot ;
+labtype.t ; labtype.t = labtype.top ;
+labtype.l_t ; labtype.l_t = labtype.ulft ;
+labtype.r_t ; labtype.r_t = labtype.urt ;
+labtype.l_b ; labtype.l_b = labtype.llft ;
+labtype.r_b ; labtype.r_b = labtype.lrt ;
+labtype.t_l ; labtype.t_l = labtype.ulft ;
+labtype.t_r ; labtype.t_r = labtype.urt ;
+labtype.b_l ; labtype.b_l = labtype.llft ;
+labtype.b_r ; labtype.b_r = labtype.lrt ;
+
vardef thetextext@#(expr p,z) = % adapted copy of thelabel@
- p
- if (labtype@# >= 10) : shifted (0,ypart center p) fi
- shifted (z + labeloffset*laboff@# - (labxf@#*lrcorner p + labyf@#*ulcorner p + (1-labxf@#-labyf@#)*llcorner p))
+ if string p :
+ thetextext@#(rawtextext(p),z)
+ else :
+ p
+ if (labtype@# >= 10) : shifted (0,ypart center p) fi
+ shifted (z + labeloffset*laboff@# - (labxf@#*lrcorner p + labyf@#*ulcorner p + (1-labxf@#-labyf@#)*llcorner p))
+ fi
enddef;
vardef textext@#(expr txt) =
@@ -82,6 +142,28 @@ vardef textext@#(expr txt) =
fi
enddef ;
+% \starttext
+% \startMPpage
+% numeric value ; value = 123 ;
+% label.lft(decimal value,origin) ;
+% draw "oeps" infont defaultfont ;
+% \stopMPpage
+% \stoptext
+
+vardef thelabel@#(expr s, z) =
+ save p ; picture p ;
+ if picture s :
+ p = s ;
+ else :
+ p = textext("\definedfont[" & defaultfont & "]" & s) scaled defaultscale ;
+ fi ;
+ p shifted (z + labeloffset*laboff@# - (labxf@#*lrcorner p + labyf@#*ulcorner p + (1-labxf@#-labyf@#)*llcorner p))
+enddef;
+
+primarydef str infont name = % very naughty !
+ textext("\definedfont[" & name & "]" & str)
+enddef ;
+
def circular_shade (expr p, n, ca, cb) =
begingroup ;
save ab, r ; pair ab ; numeric r ;
diff --git a/metapost/context/base/mp-page.mp b/metapost/context/base/mp-page.mp
index e3750b55b..71ca12aa0 100644
--- a/metapost/context/base/mp-page.mp
+++ b/metapost/context/base/mp-page.mp
@@ -444,4 +444,4 @@ def Enlarged (expr p, d) =
ulEnlarged (p,d) -- cycle)
enddef ;
-endinput ;
\ No newline at end of file
+endinput ;
diff --git a/metapost/context/base/mp-text.mp b/metapost/context/base/mp-text.mp
index c1f9c80e9..292b79b4f 100644
--- a/metapost/context/base/mp-text.mp
+++ b/metapost/context/base/mp-text.mp
@@ -86,8 +86,9 @@ string laboff_l ; laboff_l := ".lft" ;
string laboff_r ; laboff_r := ".rt" ;
string laboff_b ; laboff_b := ".bot" ;
string laboff_t ; laboff_t := ".top" ;
+
string laboff_lt ; laboff_lt := ".ulft" ;
-string laboff_rt ; laboff_rt := ".urt" ;
+string laboff_rt ; laboff_rt := ".urt" ; % bugged, conflict with r
string laboff_lb ; laboff_lb := ".llft" ;
string laboff_rb ; laboff_rb := ".lrt" ;
string laboff_tl ; laboff_tl := ".ulft" ;
diff --git a/metapost/context/base/mp-tool.mp b/metapost/context/base/mp-tool.mp
index ccec2f3c8..817f237b0 100644
--- a/metapost/context/base/mp-tool.mp
+++ b/metapost/context/base/mp-tool.mp
@@ -828,6 +828,15 @@ primarydef p crossed d =
center p shifted ( 0,+d) -- ulcorner p -- cycle)
enddef ;
+%D Also handy (math ladders):
+
+vardef laddered expr p =
+ point 0 of p
+ for i=1 upto length(p) :
+ -- (xpart (point i of p), ypart (point (i-1) of p)) -- (point i of p)
+ endfor
+enddef ;
+
%D Saves typing:
% vardef bottomboundary primary p = (llcorner p -- lrcorner p) enddef ;
@@ -975,6 +984,10 @@ enddef ;
% endgroup
%enddef ;
+primarydef p paralleled d =
+ p shifted if d < 0 : - fi ((point abs(d) on (p rotatedaround(point 0 of p,90))) - point 0 of p)
+enddef ;
+
vardef punked primary p =
(point 0 of p for i=1 upto length(p)-1 : -- point i of p endfor
if cycle p : -- cycle else : -- point length(p) of p fi)
@@ -1746,12 +1759,55 @@ def condition primary b = if b : "true" else : "false" fi enddef ;
primarydef p stretched s =
begingroup
-% save pp ; path pp ; pp := p scaled s ;
save pp ; path pp ; pp := p xyscaled s ;
(pp shifted ((point 0 of p) - (point 0 of pp)))
endgroup
enddef ;
+% primarydef p enlonged len =
+% begingroup
+% save al ; al := arclength(p) ;
+% if al > 0 :
+% if pair p :
+% point 1 of ((origin -- p) stretched ((al+len)/al))
+% else :
+% p stretched ((al+len)/al)
+% fi
+% else :
+% p
+% fi
+% endgroup
+% enddef ;
+
+primarydef p enlonged len =
+ begingroup
+ if pair p :
+ save q ; path q ; q := origin -- p ;
+ save al ; al := arclength(q) ;
+ if al > 0 :
+ point 1 of (q stretched ((al+len)/al))
+ else :
+ p
+ fi
+ else :
+ save al ; al := arclength(p) ;
+ if al > 0 :
+ p stretched ((al+len)/al)
+ else :
+ p
+ fi
+ fi
+ endgroup
+enddef ;
+
+% path p ; p := (0,0) -- (10cm,5cm) ;
+% drawarrow p withcolor red ;
+% drawarrow p shortened 1cm withcolor green ;
+
+primarydef p shortened d =
+ reverse ( ( reverse (p enlonged -d) ) enlonged -d )
+enddef ;
+
% yes or no, untested -)
def xshifted expr dx = shifted(dx,0) enddef ;
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua
index 1e38edeab..aacdbd16d 100644
--- a/scripts/context/lua/luatools.lua
+++ b/scripts/context/lua/luatools.lua
@@ -1,25 +1,26 @@
#!/usr/bin/env texlua
+if not modules then modules = { } end modules ['luatools'] = {
+ version = 1.001,
+ comment = "companion to context.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
-- one can make a stub:
--
-- #!/bin/sh
-- env LUATEXDIR=/....../texmf/scripts/context/lua texlua luatools.lua "$@"
--- filename : luatools.lua
--- comment : companion to context.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-- Although this script is part of the ConTeXt distribution it is
-- relatively indepent of ConTeXt. The same is true for some of
-- the luat files. We may may make them even less dependent in
-- the future. As long as Luatex is under development the
-- interfaces and names of functions may change.
-banner = "version 1.2.2 - 2006+ - PRAGMA ADE / CONTEXT"
-texlua = true
-
-- For the sake of independence we optionally can merge the library
-- code here. It's too much code, but that does not harm. Much of the
-- library code is used elsewhere. We don't want dependencies on
@@ -28,141 +29,42 @@ texlua = true
-- needed when texmfstart is used, or when the proper stub is used or
-- when (windows) suffix binding is active.
+texlua = true
+
-- begin library merge
--- filename : l-string.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-string'] = 1.001
-
---~ function string.split(str, pat) -- taken from the lua wiki
---~ local t = {n = 0} -- so this table has a length field, traverse with ipairs then!
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = string.find(str, fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ table.insert(t,cap)
---~ end
---~ last_end = e+1
---~ s, e, cap = string.find(str, fpat, last_end)
---~ end
---~ if last_end<=string.len(str) then
---~ table.insert(t,(string.sub(str,last_end)))
---~ end
---~ return t
---~ end
---~ function string:split(pat) -- taken from the lua wiki but adapted
---~ local t = { } -- self and colon usage (faster)
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = self:find(fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ t[#t+1] = cap
---~ end
---~ last_end = e+1
---~ s, e, cap = self:find(fpat, last_end)
---~ end
---~ if last_end <= #self then
---~ t[#t+1] = self:sub(last_end)
---~ end
---~ return t
---~ end
---~ a piece of brilliant code by Rici Lake (posted on lua list) -- only names changed
---~
---~ function string:splitter(pat)
---~ local st, g = 1, self:gmatch("()"..pat.."()")
---~ local function splitter(self)
---~ if st then
---~ local s, f = g()
---~ local rv = self:sub(st, (s or 0)-1)
---~ st = f
---~ return rv
---~ end
---~ end
---~ return splitter, self
---~ end
-function string:splitter(pat)
- -- by Rici Lake (posted on lua list) -- only names changed
- -- p 79 ref man: () returns position of match
- local st, g = 1, self:gmatch("()("..pat..")")
- local function strgetter(self, segs, seps, sep, cap1, ...)
- st = sep and seps + #sep
- return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
- end
- local function strsplitter(self)
- if st then return strgetter(self, st, g()) end
- end
- return strsplitter, self
-end
+do -- create closure to overcome 200 locals limit
-function string:split(separator)
- local t = {}
- for k in self:splitter(separator) do t[#t+1] = k end
- return t
-end
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
--- faster than a string:split:
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
-function string:splitchr(chr)
- if #self > 0 then
- local t = { }
- for s in (self..chr):gmatch("(.-)"..chr) do
- t[#t+1] = s
+if not string.split then
+
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
end
- return t
- else
- return { }
end
-end
-function string.piecewise(str, pat, fnc) -- variant of split
- for k in string.splitter(str,pat) do fnc(k) end
end
---~ function string.piecewise(str, pat, fnc) -- variant of split
---~ for k in str:splitter(pat) do fnc(k) end
---~ end
-
---~ do if lpeg then
-
---~ -- this alternative is 30% faster esp when we cache them
---~ -- problem: no expressions
-
---~ splitters = { }
-
---~ function string:split(separator)
---~ if #self > 0 then
---~ local split = splitters[separator]
---~ if not split then
---~ -- based on code by Roberto
---~ local p = lpeg.P(separator)
---~ local c = lpeg.C((1-p)^0)
---~ split = lpeg.Ct(c*(p*c)^0)
---~ splitters[separator] = split
---~ end
---~ return split:match(self)
---~ else
---~ return { }
---~ end
---~ end
-
---~ string.splitchr = string.split
-
---~ function string:piecewise(separator,fnc)
---~ for _,v in pairs(self:split(separator)) do
---~ fnc(v)
---~ end
---~ end
-
---~ end end
-
local chr_to_esc = {
["%"] = "%%",
["."] = "%.",
@@ -176,20 +78,20 @@ local chr_to_esc = {
string.chr_to_esc = chr_to_esc
function string:esc() -- variant 2
- return (self:gsub("(.)",chr_to_esc))
+ return (gsub(self,"(.)",chr_to_esc))
end
function string:unquote()
- return (self:gsub("^([\"\'])(.*)%1$","%2"))
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
end
-function string:quote()
+function string:quote() -- we could use format("%q")
return '"' .. self:unquote() .. '"'
end
function string:count(pattern) -- variant 3
local n = 0
- for _ in self:gmatch(pattern) do
+ for _ in gmatch(self,pattern) do
n = n + 1
end
return n
@@ -198,29 +100,25 @@ end
function string:limit(n,sentinel)
if #self > n then
sentinel = sentinel or " ..."
- return self:sub(1,(n-#sentinel)) .. sentinel
+ return sub(self,1,(n-#sentinel)) .. sentinel
else
return self
end
end
function string:strip()
- return (self:gsub("^%s*(.-)%s*$", "%1"))
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
end
---~ function string.strip(str) -- slightly different
---~ return (string.gsub(string.gsub(str,"^%s*(.-)%s*$","%1"),"%s+"," "))
---~ end
-
function string:is_empty()
- return not self:find("%S")
+ return not find(find,"%S")
end
function string:enhance(pattern,action)
local ok, n = true, 0
while ok do
ok = false
- self = self:gsub(pattern, function(...)
+ self = gsub(self,pattern, function(...)
ok, n = true, n + 1
return action(...)
end)
@@ -228,59 +126,19 @@ function string:enhance(pattern,action)
return self, n
end
---~ function string:enhance(pattern,action)
---~ local ok, n = 0, 0
---~ repeat
---~ self, ok = self:gsub(pattern, function(...)
---~ n = n + 1
---~ return action(...)
---~ end)
---~ until ok == 0
---~ return self, n
---~ end
-
---~ function string:to_hex()
---~ if self then
---~ return (self:gsub("(.)",function(c)
---~ return string.format("%02X",c:byte())
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
---~ function string:from_hex()
---~ if self then
---~ return (self:gsub("(..)",function(c)
---~ return string.char(tonumber(c,16))
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
-string.chr_to_hex = { }
-string.hex_to_chr = { }
+local chr_to_hex, hex_to_chr = { }, { }
for i=0,255 do
- local c, h = string.char(i), string.format("%02X",i)
- string.chr_to_hex[c], string.hex_to_chr[h] = h, c
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
end
---~ function string:to_hex()
---~ if self then return (self:gsub("(.)",string.chr_to_hex)) else return "" end
---~ end
-
---~ function string:from_hex()
---~ if self then return (self:gsub("(..)",string.hex_to_chr)) else return "" end
---~ end
-
function string:to_hex()
- return ((self or ""):gsub("(.)",string.chr_to_hex))
+ return (gsub(self or "","(.)",chr_to_hex))
end
function string:from_hex()
- return ((self or ""):gsub("(..)",string.hex_to_chr))
+ return (gsub(self or "","(..)",hex_to_chr))
end
if not string.characters then
@@ -294,7 +152,7 @@ if not string.characters then
end
local function nextbyte(str, index)
index = index + 1
- return (index <= #str) and index or nil, string.byte(str:sub(index,index))
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
end
function string:bytes()
return nextbyte, self, 0
@@ -302,9 +160,7 @@ if not string.characters then
end
---~ function string:padd(n,chr)
---~ return self .. self.rep(chr or " ",n-#self)
---~ end
+-- we can use format for this (neg n)
function string:rpadd(n,chr)
local m = n-#self
@@ -326,8 +182,8 @@ end
string.padd = string.rpadd
-function is_number(str)
- return str:find("^[%-%+]?[%d]-%.?[%d+]$") == 1
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
end
--~ print(is_number("1"))
@@ -339,9 +195,9 @@ end
--~ print(is_number("+.1"))
function string:split_settings() -- no {} handling, see l-aux for lpeg variant
- if self:find("=") then
+ if find(self,"=") then
local t = { }
- for k,v in self:gmatch("(%a+)=([^%,]*)") do
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
t[k] = v
end
return t
@@ -363,24 +219,67 @@ local patterns_escapes = {
}
function string:pattesc()
- return (self:gsub(".",patterns_escapes))
+ return (gsub(self,".",patterns_escapes))
end
function string:tohash()
local t = { }
- for s in self:gmatch("([^, ]+)") do -- lpeg
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
t[s] = true
end
return t
end
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
--- filename : l-lpeg.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+do -- create closure to overcome 200 locals limit
-if not versions then versions = { } end versions['l-lpeg'] = 1.001
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
--~ l-lpeg.lua :
@@ -404,36 +303,40 @@ if not versions then versions = { } end versions['l-lpeg'] = 1.001
local hash = { }
function lpeg.anywhere(pattern) --slightly adapted from website
- return lpeg.P { lpeg.P(pattern) + 1 * lpeg.V(1) }
+ return P { P(pattern) + 1 * lpeg.V(1) }
end
function lpeg.startswith(pattern) --slightly adapted
- return lpeg.P(pattern)
+ return P(pattern)
end
---~ g = lpeg.splitter(" ",function(s) ... end) -- gmatch:lpeg = 3:2
-
function lpeg.splitter(pattern, action)
- return (((1-lpeg.P(pattern))^1)/action+1)^0
+ return (((1-P(pattern))^1)/action+1)^0
end
-local crlf = lpeg.P("\r\n")
-local cr = lpeg.P("\r")
-local lf = lpeg.P("\n")
-local space = lpeg.S(" \t\f\v")
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
local newline = crlf + cr + lf
local spacing = space^0 * newline
-local empty = spacing * lpeg.Cc("")
-local nonempty = lpeg.Cs((1-spacing)^1) * spacing^-1
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
local content = (empty + nonempty)^1
-local capture = lpeg.Ct(content^0)
+local capture = Ct(content^0)
function string:splitlines()
return capture:match(self)
end
+lpeg.linebyline = content -- better make a sublibrary
+
--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
@@ -441,16 +344,16 @@ end
local splitters_s, splitters_m = { }, { }
-function lpeg.splitat(separator,single)
+local function splitat(separator,single)
local splitter = (single and splitters_s[separator]) or splitters_m[separator]
if not splitter then
- separator = lpeg.P(separator)
+ separator = P(separator)
if single then
- local other, any = lpeg.C((1 - separator)^0), lpeg.P(1)
- splitter = other * (separator * lpeg.C(any^0) + "")
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
splitters_s[separator] = splitter
else
- local other = lpeg.C((1 - separator)^0)
+ local other = C((1 - separator)^0)
splitter = other * (separator * other)^0
splitters_m[separator] = splitter
end
@@ -458,26 +361,43 @@ function lpeg.splitat(separator,single)
return splitter
end
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
+
+
+end -- of closure
--- filename : l-table.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+do -- create closure to overcome 200 locals limit
-if not versions then versions = { } end versions['l-table'] = 1.001
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
table.join = table.concat
local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
-local format = string.format
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
local getmetatable, setmetatable = getmetatable, setmetatable
-local pairs, ipairs, type, next, tostring = pairs, ipairs, type, next, tostring
+local type, next, tostring, ipairs = type, next, tostring, ipairs
function table.strip(tab)
local lst = { }
for i=1,#tab do
- local s = tab[i]:gsub("^%s*(.-)%s*$","%1")
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
if s == "" then
-- skip this one
else
@@ -489,7 +409,7 @@ end
local function sortedkeys(tab)
local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
if kind == 3 then
-- no further check
@@ -516,7 +436,7 @@ end
local function sortedhashkeys(tab) -- fast one
local srt = { }
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
end
sort(srt)
@@ -526,14 +446,25 @@ end
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
function table.append(t, list)
- for _,v in pairs(list) do
+ for _,v in next, list do
insert(t,v)
end
end
function table.prepend(t, list)
- for k,v in pairs(list) do
+ for k,v in next, list do
insert(t,k,v)
end
end
@@ -542,7 +473,7 @@ function table.merge(t, ...) -- first one is target
t = t or {}
local lst = {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
t[k] = v
end
end
@@ -552,7 +483,7 @@ end
function table.merged(...)
local tmp, lst = { }, {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
tmp[k] = v
end
end
@@ -584,13 +515,14 @@ end
local function fastcopy(old) -- fast one
if old then
local new = { }
- for k,v in pairs(old) do
+ for k,v in next, old do
if type(v) == "table" then
new[k] = fastcopy(v) -- was just table.copy
else
new[k] = v
end
end
+ -- optional second arg
local mt = getmetatable(old)
if mt then
setmetatable(new,mt)
@@ -607,7 +539,7 @@ local function copy(t, tables) -- taken from lua wiki, slightly adapted
if not tables[t] then
tables[t] = tcopy
end
- for i,v in pairs(t) do -- brrr, what happens with sparse indexed
+ for i,v in next, t do -- brrr, what happens with sparse indexed
if type(i) == "table" then
if tables[i] then
i = tables[i]
@@ -640,7 +572,7 @@ function table.sub(t,i,j)
end
function table.replace(a,b)
- for k,v in pairs(b) do
+ for k,v in next, b do
a[k] = v
end
end
@@ -662,16 +594,18 @@ end
function table.tohash(t,value)
local h = { }
- if value == nil then value = true end
- for _, v in pairs(t) do -- no ipairs here
- h[v] = value
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
end
return h
end
function table.fromhash(t)
local h = { }
- for k, v in pairs(t) do -- no ipairs here
+ for k, v in next, t do -- no ipairs here
if v then h[#h+1] = k end
end
return h
@@ -695,24 +629,10 @@ local reserved = table.tohash { -- intercept a language flaw, no reserved words
'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
}
-local function key(k)
- if type(k) == "number" then -- or k:find("^%d+$") then
- if hexify then
- return ("[0x%04X]"):format(k)
- else
- return "["..k.."]"
- end
- elseif noquotes and not reserved[k] and k:find("^%a[%a%d%_]*$") then
- return k
- else
- return '["'..k..'"]'
- end
-end
-
local function simple_table(t)
if #t > 0 then
local n = 0
- for _,v in pairs(t) do
+ for _,v in next, t do
n = n + 1
end
if n == #t then
@@ -722,14 +642,14 @@ local function simple_table(t)
local tv = type(v)
if tv == "number" then
if hexify then
- tt[#tt+1] = ("0x%04X"):format(v)
+ tt[#tt+1] = format("0x%04X",v)
else
- tt[#tt+1] = tostring(v)
+ tt[#tt+1] = tostring(v) -- tostring not needed
end
elseif tv == "boolean" then
tt[#tt+1] = tostring(v)
elseif tv == "string" then
- tt[#tt+1] = ("%q"):format(v)
+ tt[#tt+1] = format("%q",v)
else
tt = nil
break
@@ -741,51 +661,72 @@ local function simple_table(t)
return nil
end
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
local function do_serialize(root,name,depth,level,indexed)
if level > 0 then
depth = depth .. " "
if indexed then
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
elseif name then
- handle(("%s%s={"):format(depth,key(name)))
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
else
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
end
end
if root and next(root) then
local first, last = nil, 0 -- #root cannot be trusted here
if compact then
- for k,v in ipairs(root) do -- NOT: for k=1,#root do (we need to quit at nil)
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
if not first then first = k end
last = last + 1
end
end
- --~ for _,k in pairs(sortedkeys(root)) do -- 1% faster:
local sk = sortedkeys(root)
for i=1,#sk do
local k = sk[i]
local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
local t = type(v)
if compact and first and type(k) == "number" and k >= first and k <= last then
if t == "number" then
if hexify then
- handle(("%s 0x%04X,"):format(depth,v))
+ handle(format("%s 0x%04X,",depth,v))
else
- handle(("%s %s,"):format(depth,v))
+ handle(format("%s %s,",depth,v))
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s,"):format(depth,v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
else
- handle(("%s %q,"):format(depth,v))
+ handle(format("%s %q,",depth,v))
end
elseif t == "table" then
if not next(v) then
- handle(("%s {},"):format(depth))
- elseif inline then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
local st = simple_table(v)
if st then
- handle(("%s { %s },"):format(depth,concat(st,", ")))
+ handle(format("%s { %s },",depth,concat(st,", ")))
else
do_serialize(v,k,depth,level+1,true)
end
@@ -793,39 +734,102 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1,true)
end
elseif t == "boolean" then
- handle(("%s %s,"):format(depth,tostring(v)))
+ handle(format("%s %s,",depth,tostring(v)))
elseif t == "function" then
if functions then
- handle(('%s loadstring(%q),'):format(depth,v:dump()))
+ handle(format('%s loadstring(%q),',depth,dump(v)))
else
- handle(('%s "function",'):format(depth))
+ handle(format('%s "function",',depth))
end
else
- handle(("%s %q,"):format(depth,tostring(v)))
+ handle(format("%s %q,",depth,tostring(v)))
end
elseif k == "__p__" then -- parent
if false then
- handle(("%s __p__=nil,"):format(depth))
+ handle(format("%s __p__=nil,",depth))
end
elseif t == "number" then
- if hexify then
- handle(("%s %s=0x%04X,"):format(depth,key(k),v))
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%q,"):format(depth,key(k),v))
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
end
elseif t == "table" then
if not next(v) then
- handle(("%s %s={},"):format(depth,key(k)))
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
elseif inline then
local st = simple_table(v)
if st then
- handle(("%s %s={ %s },"):format(depth,key(k),concat(st,", ")))
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
else
do_serialize(v,k,depth,level+1)
end
@@ -833,24 +837,58 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1)
end
elseif t == "boolean" then
- handle(("%s %s=%s,"):format(depth,key(k),tostring(v)))
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
elseif t == "function" then
if functions then
- handle(('%s %s=loadstring(%q),'):format(depth,key(k),v:dump()))
- else
- handle(('%s %s="function",'):format(depth,key(k)))
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
end
else
- handle(("%s %s=%q,"):format(depth,key(k),tostring(v)))
- -- handle(('%s %s=loadstring(%q),'):format(depth,key(k),string.dump(function() return v end)))
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
end
+ --~ end
end
end
if level > 0 then
- handle(("%s},"):format(depth))
+ handle(format("%s},",depth))
end
end
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
noquotes = _noquotes
hexify = _hexify
@@ -868,7 +906,7 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
end
elseif tname == "number" then
if hexify then
- handle(("[0x%04X]={"):format(name))
+ handle(format("[0x%04X]={",name))
else
handle("[" .. name .. "]={")
end
@@ -1019,14 +1057,18 @@ function table.insert_after_value(t,value,str)
end
end
-function table.are_equal(a,b,n,m)
+local function are_equal(a,b,n,m) -- indexed
if #a == #b then
n = n or 1
m = m or #a
for i=n,m do
local ai, bi = a[i], b[i]
- if (ai==bi) or (type(ai)=="table" and type(bi)=="table" and table.are_equal(ai,bi)) then
- -- continue
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
else
return false
end
@@ -1037,9 +1079,30 @@ function table.are_equal(a,b,n,m)
end
end
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
function table.compact(t)
if t then
- for k,v in pairs(t) do
+ for k,v in next, t do
if not next(v) then
t[k] = nil
end
@@ -1068,7 +1131,7 @@ end
function table.swapped(t)
local s = { }
- for k, v in pairs(t) do
+ for k, v in next, t do
s[v] = k
end
return s
@@ -1090,14 +1153,14 @@ end
function table.hexed(t,seperator)
local tt = { }
- for i=1,#t do tt[i] = ("0x%04X"):format(t[i]) end
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
return concat(tt,seperator or " ")
end
function table.reverse_hash(h)
local r = { }
- for k,v in pairs(h) do
- r[v] = (k:gsub(" ","")):lower()
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
end
return r
end
@@ -1112,14 +1175,36 @@ function table.reverse(t)
return tt
end
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
--- filename : l-io.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-io'] = 1.001
+local byte = string.byte
if string.find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator = "\\", ";"
@@ -1127,8 +1212,8 @@ else
io.fileseparator, io.pathseparator = "/" , ":"
end
-function io.loaddata(filename)
- local f = io.open(filename,'rb')
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
if f then
local data = f:read('*all')
-- garbagecollector.check(data)
@@ -1186,146 +1271,83 @@ function io.noflines(f)
return n
end
-do
-
- local sb = string.byte
-
- local nextchar = {
- [ 4] = function(f)
- return f:read(1,1,1,1)
- end,
- [ 2] = function(f)
- return f:read(1,1)
- end,
- [ 1] = function(f)
- return f:read(1)
- end,
- [-2] = function(f)
- local a, b = f:read(1,1)
- return b, a
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- return d, c, b, a
- end
- }
-
- function io.characters(f,n)
- if f then
- return nextchar[n or 1], f
- else
- return nil, nil
- end
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
end
+}
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
end
-do
-
- local sb = string.byte
-
---~ local nextbyte = {
---~ [4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(a), sb(b), sb(c), sb(d)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end,
---~ [2] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(a), sb(b)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [1] = function (f)
---~ local a = f:read(1)
---~ if a then
---~ return sb(a)
---~ else
---~ return nil
---~ end
---~ end,
---~ [-2] = function (f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(b), sb(a)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [-4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(d), sb(c), sb(b), sb(a)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end
---~ }
-
- local nextbyte = {
- [4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(a), sb(b), sb(c), sb(d)
- else
- return nil, nil, nil, nil
- end
- end,
- [2] = function(f)
- local a, b = f:read(1,1)
- if b then
- return sb(a), sb(b)
- else
- return nil, nil
- end
- end,
- [1] = function (f)
- local a = f:read(1)
- if a then
- return sb(a)
- else
- return nil
- end
- end,
- [-2] = function (f)
- local a, b = f:read(1,1)
- if b then
- return sb(b), sb(a)
- else
- return nil, nil
- end
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(d), sb(c), sb(b), sb(a)
- else
- return nil, nil, nil, nil
- end
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
end
- }
-
- function io.bytes(f,n)
- if f then
- return nextbyte[n or 1], f
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
+ else
+ return nil, nil
+ end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
else
return nil, nil
end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
end
+}
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
end
function io.ask(question,default,options)
@@ -1361,24 +1383,28 @@ function io.ask(question,default,options)
end
--- filename : l-number.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
-if not versions then versions = { } end versions['l-number'] = 1.001
+do -- create closure to overcome 200 locals limit
-if not number then number = { } end
-
--- a,b,c,d,e,f = number.toset(100101)
-
-function number.toset(n)
- return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
-end
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
local format = string.format
+number = number or { }
+
+-- a,b,c,d,e,f = number.toset(100101)
+
+function number.toset(n)
+ return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
+end
+
function number.toevenhex(n)
local s = format("%X",n)
if #s % 2 == 0 then
@@ -1399,72 +1425,72 @@ end
--
-- of course dedicated "(.)(.)(.)(.)" matches are even faster
-do
- local one = lpeg.C(1-lpeg.S(''))^1
+local one = lpeg.C(1-lpeg.S(''))^1
- function number.toset(n)
- return one:match(tostring(n))
- end
+function number.toset(n)
+ return one:match(tostring(n))
end
--- filename : l-set.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-if not versions then versions = { } end versions['l-set'] = 1.001
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
-if not set then set = { } end
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-do
+set = set or { }
- local nums = { }
- local tabs = { }
- local concat = table.concat
+local nums = { }
+local tabs = { }
+local concat = table.concat
- set.create = table.tohash
+set.create = table.tohash
- function set.tonumber(t)
- if next(t) then
- local s = ""
- -- we could save mem by sorting, but it slows down
- for k, v in pairs(t) do
- if v then
- -- why bother about the leading space
- s = s .. " " .. k
- end
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
end
- if not nums[s] then
- tabs[#tabs+1] = t
- nums[s] = #tabs
- end
- return nums[s]
- else
- return 0
end
- end
-
- function set.totable(n)
- if n == 0 then
- return { }
- else
- return tabs[n] or { }
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
end
+ return nums[s]
+ else
+ return 0
end
+end
- function set.contains(n,s)
- if type(n) == "table" then
- return n[s]
- elseif n == 0 then
- return false
- else
- local t = tabs[n]
- return t and t[s]
- end
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
end
+end
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
end
--~ local c = set.create{'aap','noot','mies'}
@@ -1481,16 +1507,19 @@ end
--- filename : l-os.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
+do -- create closure to overcome 200 locals limit
---~ print(table.serialize(os.uname()))
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-os'] = 1.001
+local find = string.find
function os.resultof(command)
return io.popen(command,"r"):read("*all")
@@ -1503,7 +1532,7 @@ if not os.spawn then os.spawn = os.execute end
--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
if not io.fileseparator then
- if string.find(os.getenv("PATH"),";") then
+ if find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
else
io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
@@ -1541,11 +1570,10 @@ end
os.gettimeofday = os.gettimeofday or os.clock
-do
- local startuptime = os.gettimeofday()
- function os.runtime()
- return os.gettimeofday() - startuptime
- end
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
end
--~ print(os.gettimeofday()-os.time())
@@ -1554,47 +1582,92 @@ end
--~ print(os.date("%H:%M:%S",os.gettimeofday()))
--~ print(os.date("%H:%M:%S",os.time()))
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
--- filename : l-md5.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-md5'] = 1.001
-
-if md5 then do
+local platform
- local function convert(str,fmt)
- return (string.gsub(md5.sum(str),".",function(chr) return string.format(fmt,string.byte(chr)) end))
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
end
+ return platform
+end
- if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
- if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
- if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
-end end
+end -- of closure
+do -- create closure to overcome 200 locals limit
--- filename : l-file.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-file'] = 1.001
+-- needs a cleanup
-if not file then file = { } end
+file = file or { }
local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
function file.removesuffix(filename)
- return (filename:gsub("%.[%a%d]+$",""))
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-file.stripsuffix = file.removesuffix
-
function file.addsuffix(filename, suffix)
- if not filename:find("%.[%a%d]+$") then
+ if not find(filename,"%.[%a%d]+$") then
return filename .. "." .. suffix
else
return filename
@@ -1602,23 +1675,23 @@ function file.addsuffix(filename, suffix)
end
function file.replacesuffix(filename, suffix)
- return (filename:gsub("%.[%a%d]+$","")) .. "." .. suffix
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
end
function file.dirname(name)
- return name:match("^(.+)[/\\].-$") or ""
+ return match(name,"^(.+)[/\\].-$") or ""
end
function file.basename(name)
- return name:match("^.+[/\\](.-)$") or name
+ return match(name,"^.+[/\\](.-)$") or name
end
function file.nameonly(name)
- return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$",""))
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
function file.extname(name)
- return name:match("^.+%.([^/\\]-)$") or ""
+ return match(name,"^.+%.([^/\\]-)$") or ""
end
file.suffix = file.extname
@@ -1631,66 +1704,47 @@ file.suffix = file.extname
function file.join(...)
local pth = concat({...},"/")
- pth = pth:gsub("\\","/")
- local a, b = pth:match("^(.*://)(.*)$")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
+ return a .. gsub(b,"//+","/")
end
- a, b = pth:match("^(//)(.*)$")
+ a, b = match(pth,"^(//)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
- end
- return (pth:gsub("//+","/"))
-end
-
-function file.is_writable(name)
- local f = io.open(name, 'w')
- if f then
- f:close()
- return true
- else
- return false
+ return a .. gsub(b,"//+","/")
end
+ return (gsub(pth,"//+","/"))
end
-function file.is_readable(name)
- local f = io.open(name,'r')
- if f then
- f:close()
+function file.iswritable(name)
+ local a = lfs.attributes(name)
+ if a and a.permissions:sub(2,2) == "w" then
return true
else
- return false
+ name = file.dirname(name) or "."
+ if name == "" then name = "." end
+ a = lfs.attributes(name)
+ return a and a.permissions:sub(2,2) == "w"
end
end
-function file.iswritable(name)
- local a = lfs.attributes(name)
- return a and a.permissions:sub(2,2) == "w"
-end
-
function file.isreadable(name)
local a = lfs.attributes(name)
return a and a.permissions:sub(1,1) == "r"
end
---~ function file.split_path(str)
---~ if str:find(';') then
---~ return str:splitchr(";")
---~ else
---~ return str:splitchr(io.pathseparator)
---~ end
---~ end
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
-- todo: lpeg
function file.split_path(str)
local t = { }
- str = str:gsub("\\", "/")
- str = str:gsub("(%a):([;/])", "%1\001%2")
- for name in str:gmatch("([^;:]+)") do
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
if name ~= "" then
- name = name:gsub("\001",":")
- t[#t+1] = name
+ t[#t+1] = gsub(name,"\001",":")
end
end
return t
@@ -1701,15 +1755,15 @@ function file.join_path(tab)
end
function file.collapse_path(str)
- str = str:gsub("/%./","/")
+ str = gsub(str,"/%./","/")
local n, m = 1, 1
while n > 0 or m > 0 do
- str, n = str:gsub("[^/%.]+/%.%.$","")
- str, m = str:gsub("[^/%.]+/%.%./","")
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
end
- str = str:gsub("([^/])/$","%1")
- str = str:gsub("^%./","")
- str = str:gsub("/%.$","")
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
if str == "" then str = "." end
return str
end
@@ -1722,7 +1776,7 @@ end
--~ print(file.collapse_path("a/b/c/../.."))
function file.robustname(str)
- return (str:gsub("[^%a%d%/%-%.\\]+","-"))
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
end
file.readdata = io.loaddata
@@ -1752,8 +1806,6 @@ end
--~ return pattern:match(name)
--~ end
---~ file.stripsuffix = file.removesuffix
-
--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
--~ function file.basename(name)
@@ -1807,7 +1859,6 @@ end
--~ end
--~ local test = file.extname
---~ local test = file.stripsuffix
--~ local test = file.basename
--~ local test = file.dirname
--~ local test = file.addsuffix
@@ -1824,14 +1875,117 @@ end
--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEXsum(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
--- filename : l-url.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-url'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-url'] = 1.001
-if not url then url = { } end
+local char, gmatch = string.char, string.gmatch
+local tonumber, type = tonumber, type
-- from the spec (on the web):
--
@@ -1843,29 +1997,28 @@ if not url then url = { } end
-- / \ / \
-- urn:example:animal:ferret:nose
-do
-
- local function tochar(s)
- return string.char(tonumber(s,16))
- end
+url = url or { }
- local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
+local function tochar(s)
+ return char(tonumber(s,16))
+end
- local hexdigit = lpeg.R("09","AF","af")
- local escaped = percent * lpeg.C(hexdigit * hexdigit) / tochar
+local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
- local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
- local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
- local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
- local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
- local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
+local hexdigit = lpeg.R("09","AF","af")
+local plus = lpeg.P("+")
+local escaped = (plus / " ") + (percent * lpeg.C(hexdigit * hexdigit) / tochar)
- local parser = lpeg.Ct(scheme * authority * path * query * fragment)
+local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
+local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
+local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
+local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
+local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
- function url.split(str)
- return (type(str) == "string" and parser:match(str)) or str
- end
+local parser = lpeg.Ct(scheme * authority * path * query * fragment)
+function url.split(str)
+ return (type(str) == "string" and parser:match(str)) or str
end
function url.hashed(str)
@@ -1888,7 +2041,7 @@ end
function url.query(str)
if type(str) == "string" then
local t = { }
- for k, v in str:gmatch("([^&=]*)=([^&=]*)") do
+ for k, v in gmatch(str,"([^&=]*)=([^&=]*)") do
t[k] = v
end
return t
@@ -1903,12 +2056,12 @@ end
--~ print(url.filename("file:///etc/test.txt"))
--~ print(url.filename("/oeps.txt"))
--- from the spec on the web (sort of):
+--~ from the spec on the web (sort of):
--~
--~ function test(str)
--~ print(table.serialize(url.hashed(str)))
--~ end
----~
+--~
--~ test("%56pass%20words")
--~ test("file:///c:/oeps.txt")
--~ test("file:///c|/oeps.txt")
@@ -1930,205 +2083,210 @@ end
--~ test("zip:///oeps/oeps.zip?bla/bla.tex")
--- filename : l-dir.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
-if not versions then versions = { } end versions['l-dir'] = 1.001
+do -- create closure to overcome 200 locals limit
-dir = { }
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
--- optimizing for no string.find (*) does not save time
+local type = type
+local find, gmatch = string.find, string.gmatch
-if lfs then do
+dir = dir or { }
- local attributes = lfs.attributes
- local walkdir = lfs.dir
+-- optimizing for no string.find (*) does not save time
- local function glob_pattern(path,patt,recurse,action)
- local ok, scanner
- if path == "/" then
- ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
- else
- ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
- end
- if ok and type(scanner) == "function" then
- if not path:find("/$") then path = path .. '/' end
- for name in scanner do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if full:find(patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- glob_pattern(full,patt,recurse,action)
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
end
end
end
+end
- dir.glob_pattern = glob_pattern
+dir.glob_pattern = glob_pattern
- local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
- local pattern = Ct {
- [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
- [2] = C(((1-S("*?/"))^0 * P("/"))^0),
- [3] = C(P(1)^0)
- }
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
- local filter = Cs ( (
- P("**") / ".*" +
- P("*") / "[^/]*" +
- P("?") / "[^/]" +
- P(".") / "%%." +
- P("+") / "%%+" +
- P("-") / "%%-" +
- P(1)
- )^0 )
-
- local function glob(str,t)
- if type(str) == "table" then
- local t = t or { }
- for _, s in ipairs(str) do
- glob(s,t)
- end
- return t
- elseif lfs.isfile(str) then
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
local t = t or { }
- t[#t+1] = str
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
return t
else
- local split = pattern:match(str)
- if split then
- local t = t or { }
- local action = action or function(name) t[#t+1] = name end
- local root, path, base = split[1], split[2], split[3]
- local recurse = base:find("%*%*")
- local start = root .. path
- local result = filter:match(start .. base)
- glob_pattern(start,result,recurse,action)
- return t
- else
- return { }
- end
+ return { }
end
end
+end
- dir.glob = glob
+dir.glob = glob
- --~ list = dir.glob("**/*.tif")
- --~ list = dir.glob("/**/*.tif")
- --~ list = dir.glob("./**/*.tif")
- --~ list = dir.glob("oeps/**/*.tif")
- --~ list = dir.glob("/oeps/**/*.tif")
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
- local function globfiles(path,recurse,func,files) -- func == pattern or function
- if type(func) == "string" then
- local s = func -- alas, we need this indirect way
- func = function(name) return name:find(s) end
- end
- files = files or { }
- for name in walkdir(path) do
- if name:find("^%.") then
- --- skip
- else
- local mode = attributes(name,'mode')
- if mode == "directory" then
- if recurse then
- globfiles(path .. "/" .. name,recurse,func,files)
- end
- elseif mode == "file" then
- if func then
- if func(name) then
- files[#files+1] = path .. "/" .. name
- end
- else
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
files[#files+1] = path .. "/" .. name
end
+ else
+ files[#files+1] = path .. "/" .. name
end
end
end
- return files
end
+ return files
+end
- dir.globfiles = globfiles
+dir.globfiles = globfiles
- -- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
- -- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
- -- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
- -- t = dir.glob("f:/minimal/tex/**/*")
- -- print(dir.ls("f:/minimal/tex/**/*"))
- -- print(dir.ls("*.tex"))
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
- function dir.ls(pattern)
- return table.concat(glob(pattern),"\n")
- end
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
- --~ mkdirs("temp")
- --~ mkdirs("a/b/c")
- --~ mkdirs(".","/a/b/c")
- --~ mkdirs("a","b","c")
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
- local make_indeed = true -- false
+local make_indeed = true -- false
- if string.find(os.getenv("PATH"),";") then
+if string.find(os.getenv("PATH"),";") then
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- local first, middle, last
- local drive = false
- first, middle, last = str:match("^(//)(//*)(.*)$")
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
if first then
- -- empty network path == local path
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
else
- first, last = str:match("^(//)/*(.-)$")
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
if first then
- middle, last = str:match("([^/]+)/+(.-)$")
- if middle then
- pth = "//" .. middle
- else
- pth = "//" .. last
- last = ""
- end
+ pth, drive = first .. middle, true
else
- first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
- if first then
- pth, drive = first .. middle, true
- else
- middle, last = str:match("^(/*)(.-)$")
- if not middle then
- last = str
- end
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
end
end
end
- for s in last:gmatch("[^/]+") do
- if pth == "" then
- pth = s
- elseif drive then
- pth, drive = pth .. s, false
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -2142,79 +2300,79 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- local first, nothing, last = str:match("^(//)(//*)(.*)$")
- if first then
- first = lfs.currentdir() .. "/"
- first = first:gsub("\\","/")
- end
- if not first then
- first, last = str:match("^(//)/*(.*)$")
- end
- if not first then
- first, last = str:match("^([a-zA-Z]:)(.*)$")
- if first and not last:find("^/") then
- local d = lfs.currentdir()
- if lfs.chdir(first) then
- first = lfs.currentdir()
- first = first:gsub("\\","/")
- end
- lfs.chdir(d)
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
end
+ lfs.chdir(d)
end
- if not first then
- first, last = lfs.currentdir(), str
- first = first:gsub("\\","/")
- end
- last = last:gsub("//","/")
- last = last:gsub("/%./","/")
- last = last:gsub("^/*","")
- first = first:gsub("/*$","")
- if last == "" then
- return first
- else
- return first .. "/" .. last
- end
end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
- else
+else
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- str = str:gsub("/+","/")
- if str:find("^/") then
- pth = "/"
- for s in str:gmatch("[^/]+") do
- local first = (pth == "/")
- if first then
- pth = pth .. s
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not first and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
- end
- else
- pth = "."
- for s in str:gmatch("[^/]+") do
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
pth = pth .. "/" .. s
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -2224,30 +2382,35 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- if not str:find("^/") then
- str = lfs.currentdir() .. "/" .. str
- end
- str = str:gsub("//","/")
- str = str:gsub("/%./","/")
- return str
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
end
-
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
end
- dir.makedirs = dir.mkdirs
+end
+
+dir.makedirs = dir.mkdirs
+
-end end
+end -- of closure
+do -- create closure to overcome 200 locals limit
--- filename : l-boolean.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-boolean'] = 1.001
-if not boolean then boolean = { } end
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
function boolean.tonumber(b)
if b then return 1 else return 0 end
@@ -2294,24 +2457,24 @@ function boolean.falsetrue()
end
--- filename : l-unicode.lua
--- comment : split off from luat-inp
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
-if not versions then versions = { } end versions['l-unicode'] = 1.001
-if not unicode then unicode = { } end
+if not modules then modules = { } end modules ['l-unicode'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-local concat, utfchar, utfgsub = table.concat, unicode.utf8.char, unicode.utf8.gsub
-local char, byte = string.char, string.byte
+utf = utf or unicode.utf8
-if not garbagecollector then
- garbagecollector = {
- push = function() collectgarbage("stop") end,
- pop = function() collectgarbage("restart") end,
- }
-end
+local concat, utfchar, utfgsub = table.concat, utf.char, utf.gsub
+local char, byte, find, bytepairs = string.char, string.byte, string.find, string.bytepairs
+
+unicode = unicode or { }
-- 0 EF BB BF UTF-8
-- 1 FF FE UTF-16-little-endian
@@ -2332,17 +2495,17 @@ function unicode.utftype(f) -- \000 fails !
if not str then
f:seek('set')
return 0
- elseif str:find("^%z%z\254\255") then
+ elseif find(str,"^%z%z\254\255") then
return 4
- elseif str:find("^\255\254%z%z") then
+ elseif find(str,"^\255\254%z%z") then
return 3
- elseif str:find("^\254\255") then
+ elseif find(str,"^\254\255") then
f:seek('set',2)
return 2
- elseif str:find("^\255\254") then
+ elseif find(str,"^\255\254") then
f:seek('set',2)
return 1
- elseif str:find("^\239\187\191") then
+ elseif find(str,"^\239\187\191") then
f:seek('set',3)
return 0
else
@@ -2352,18 +2515,17 @@ function unicode.utftype(f) -- \000 fails !
end
function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
---~ garbagecollector.push()
local result, tmp, n, m, p = { }, { }, 0, 0, 0
-- lf | cr | crlf / (cr:13, lf:10)
local function doit()
if n == 10 then
if p ~= 13 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
tmp = { }
p = 0
end
elseif n == 13 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
tmp = { }
p = n
else
@@ -2371,7 +2533,7 @@ function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
p = 0
end
end
- for l,r in str:bytepairs() do
+ for l,r in bytepairs(str) do
if r then
if endian then
n = l*256 + r
@@ -2390,26 +2552,24 @@ function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
end
end
if #tmp > 0 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
end
---~ garbagecollector.pop()
return result
end
function unicode.utf32_to_utf8(str, endian)
---~ garbagecollector.push()
local result = { }
local tmp, n, m, p = { }, 0, -1, 0
-- lf | cr | crlf / (cr:13, lf:10)
local function doit()
if n == 10 then
if p ~= 13 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
tmp = { }
p = 0
end
elseif n == 13 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
tmp = { }
p = n
else
@@ -2417,7 +2577,7 @@ function unicode.utf32_to_utf8(str, endian)
p = 0
end
end
- for a,b in str:bytepairs() do
+ for a,b in bytepairs(str) do
if a and b then
if m < 0 then
if endian then
@@ -2439,48 +2599,55 @@ function unicode.utf32_to_utf8(str, endian)
end
end
if #tmp > 0 then
- result[#result+1] = concat(tmp,"")
+ result[#result+1] = concat(tmp)
end
---~ garbagecollector.pop()
return result
end
+local function little(c)
+ local b = byte(c) -- b = c:byte()
+ if b < 0x10000 then
+ return char(b%256,b/256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1%256,b1/256,b2%256,b2/256)
+ end
+end
+
+local function big(c)
+ local b = byte(c)
+ if b < 0x10000 then
+ return char(b/256,b%256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1/256,b1%256,b2/256,b2%256)
+ end
+end
+
function unicode.utf8_to_utf16(str,littleendian)
if littleendian then
- return char(255,254) .. utfgsub(str,".",function(c)
- local b = byte(c)
- if b < 0x10000 then
- return char(b%256,b/256)
- else
- b = b - 0x10000
- local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
- return char(b1%256,b1/256,b2%256,b2/256)
- end
- end)
+ return char(255,254) .. utfgsub(str,".",little)
else
- return char(254,255) .. utfgsub(str,".",function(c)
- local b = byte(c)
- if b < 0x10000 then
- return char(b/256,b%256)
- else
- b = b - 0x10000
- local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
- return char(b1/256,b1%256,b2/256,b2%256)
- end
- end)
+ return char(254,255) .. utfgsub(str,".",big)
end
end
--- filename : l-math.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
-if not versions then versions = { } end versions['l-math'] = 1.001
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-local floor = math.floor
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
if not math.round then
function math.round(x)
@@ -2500,14 +2667,34 @@ if not math.mod then
end
end
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
--- filename : l-utils.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-utils'] = 1.001
+-- hm, quite unreadable
if not utils then utils = { } end
if not utils.merger then utils.merger = { } end
@@ -2572,24 +2759,52 @@ function utils.merger._self_swap_(data,code)
end
end
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
function utils.merger._self_libs_(libs,list)
- local result, f = { }, nil
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
if type(libs) == 'string' then libs = { libs } end
if type(list) == 'string' then list = { list } end
+ local foundpath = nil
for _, lib in ipairs(libs) do
for _, pth in ipairs(list) do
- local name = string.gsub(pth .. "/" .. lib,"\\","/")
- f = io.open(name)
- if f then
- utils.report("merging library %s",name)
- result[#result+1] = f:read("*all")
- f:close()
- list = { pth } -- speed up the search
- break
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
else
- utils.report("no library %s",name)
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
end
end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
end
return table.concat(result, "\n\n")
end
@@ -2643,15 +2858,257 @@ end
-if not modules then modules = { } end modules ['luat-lib'] = {
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
version = 1.001,
+ comment = "companion to luat-lib.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
}
--- most code already moved to the l-*.lua and other luat-*.lua files
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
@@ -2659,15 +3116,27 @@ function os.setlocale()
-- no way you can mess with it
end
+-- dirty tricks
+
if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
end
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
environment = environment or { }
environment.arguments = { }
environment.files = { }
environment.sortedflags = nil
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
function environment.initialize_arguments(arg)
local arguments, files = { }, { }
environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
@@ -2689,24 +3158,20 @@ function environment.initialize_arguments(arg)
environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
end
-function environment.showarguments()
- for k,v in pairs(environment.arguments) do
- print(k .. " : " .. tostring(v))
- end
- if #environment.files > 0 then
- print("files : " .. table.concat(environment.files, " "))
- end
-end
-
function environment.setargument(name,value)
environment.arguments[name] = value
end
-function environment.argument(name) -- todo: default (plus typecheck on default)
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
local arguments, sortedflags = environment.arguments, environment.sortedflags
if arguments[name] then
return arguments[name]
- else
+ elseif partial then
if not sortedflags then
sortedflags = { }
for _,v in pairs(table.sortedkeys(arguments)) do
@@ -2714,6 +3179,7 @@ function environment.argument(name) -- todo: default (plus typecheck on default)
end
environment.sortedflags = sortedflags
end
+ -- example of potential clash: ^mode ^modefile
for _,v in ipairs(sortedflags) do
if name:find(v) then
return arguments[v:sub(2,#v)]
@@ -2737,43 +3203,17 @@ function environment.split_arguments(separator) -- rather special, cut-off befor
return before, after
end
---~ function environment.reconstruct_commandline(arg)
---~ if not arg then arg = environment.original_arguments end
---~ local result = { }
---~ for _,a in ipairs(arg) do -- ipairs 1 .. #n
---~ local kk, vv = a:match("^(%-+.-)=(.+)$")
---~ if kk and vv then
---~ if vv:find(" ") then
---~ vv = vv:unquote()
---~ vv = vv:gsub('"','\\"')
---~ result[#result+1] = kk .. "=" .. vv:quote()
---~ else
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a
---~ end
---~ elseif a:find(" ") then
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a:quote()
---~ else
---~ result[#result+1] = a
---~ end
---~ end
---~ return table.join(result," ")
---~ end
-
function environment.reconstruct_commandline(arg,noquote)
- if not arg then arg = environment.original_arguments end
+ arg = arg or environment.original_arguments
if noquote and #arg == 1 then
local a = arg[1]
- a = input.resolve(a)
+ a = resolvers.resolve(a)
a = a:unquote()
return a
- elseif #arg == 1 then
+ elseif next(arg) then
local result = { }
for _,a in ipairs(arg) do -- ipairs 1 .. #n
- a = input.resolve(a)
+ a = resolvers.resolve(a)
a = a:unquote()
a = a:gsub('"','\\"') -- tricky
if a:find(" ") then
@@ -2783,6 +3223,8 @@ function environment.reconstruct_commandline(arg,noquote)
end
end
return table.join(result," ")
+ else
+ return ""
end
end
@@ -2818,279 +3260,163 @@ if arg then
end
+-- weird place ... depends on a not yet loaded module
-if not modules then modules = { } end modules ['luat-inp'] = {
- version = 1.001,
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
- comment = "companion to luat-lib.tex",
-}
-
--- TODO: os.getenv -> os.env[]
--- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
--- TODO: check escaping in find etc, too much, too slow
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
--- This lib is multi-purpose and can be loaded again later on so that
--- additional functionality becomes available. We will split this
--- module in components once we're done with prototyping. This is the
--- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
--- something in this module one can best check with Taco or Hans first; there
--- is some nasty trickery going on that relates to traditional kpse support.
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
--- To be considered: hash key lowercase, first entry in table filename
--- (any case), rest paths (so no need for optimization). Or maybe a
--- separate table that matches lowercase names to mixed case when
--- present. In that case the lower() cases can go away. I will do that
--- only when we run into problems with names ... well ... Iwona-Regular.
+environment.loadedluacode = loadfile -- can be overloaded
--- Beware, loading and saving is overloaded in luat-tmp!
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
-if not input then input = { } end
-if not input.suffixes then input.suffixes = { } end
-if not input.formats then input.formats = { } end
-if not input.aux then input.aux = { } end
-
-if not input.suffixmap then input.suffixmap = { } end
-
-if not input.locators then input.locators = { } end -- locate databases
-if not input.hashers then input.hashers = { } end -- load databases
-if not input.generators then input.generators = { } end -- generate databases
-if not input.filters then input.filters = { } end -- conversion filters
-
-local format, concat, sortedkeys = string.format, table.concat, table.sortedkeys
-
-input.locators.notfound = { nil }
-input.hashers.notfound = { nil }
-input.generators.notfound = { nil }
-
-input.cacheversion = '1.0.1'
-input.banner = nil
-input.verbose = false
-input.debug = false
-input.cnfname = 'texmf.cnf'
-input.luaname = 'texmfcnf.lua'
-input.lsrname = 'ls-R'
-input.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
-
---~ input.luasuffix = 'tma'
---~ input.lucsuffix = 'tmc'
-
--- for the moment we have .local but this will disappear
-input.cnfdefault = '{$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- chances are low that the cnf file is in the bin path
-input.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- we use a cleaned up list / format=any is a wildcard, as is *name
-
-input.formats['afm'] = 'AFMFONTS' input.suffixes['afm'] = { 'afm' }
-input.formats['enc'] = 'ENCFONTS' input.suffixes['enc'] = { 'enc' }
-input.formats['fmt'] = 'TEXFORMATS' input.suffixes['fmt'] = { 'fmt' }
-input.formats['map'] = 'TEXFONTMAPS' input.suffixes['map'] = { 'map' }
-input.formats['mp'] = 'MPINPUTS' input.suffixes['mp'] = { 'mp' }
-input.formats['ocp'] = 'OCPINPUTS' input.suffixes['ocp'] = { 'ocp' }
-input.formats['ofm'] = 'OFMFONTS' input.suffixes['ofm'] = { 'ofm', 'tfm' }
-input.formats['otf'] = 'OPENTYPEFONTS' input.suffixes['otf'] = { 'otf' } -- 'ttf'
-input.formats['opl'] = 'OPLFONTS' input.suffixes['opl'] = { 'opl' }
-input.formats['otp'] = 'OTPINPUTS' input.suffixes['otp'] = { 'otp' }
-input.formats['ovf'] = 'OVFFONTS' input.suffixes['ovf'] = { 'ovf', 'vf' }
-input.formats['ovp'] = 'OVPFONTS' input.suffixes['ovp'] = { 'ovp' }
-input.formats['tex'] = 'TEXINPUTS' input.suffixes['tex'] = { 'tex' }
-input.formats['tfm'] = 'TFMFONTS' input.suffixes['tfm'] = { 'tfm' }
-input.formats['ttf'] = 'TTFONTS' input.suffixes['ttf'] = { 'ttf', 'ttc' }
-input.formats['pfb'] = 'T1FONTS' input.suffixes['pfb'] = { 'pfb', 'pfa' }
-input.formats['vf'] = 'VFFONTS' input.suffixes['vf'] = { 'vf' }
-
-input.formats['fea'] = 'FONTFEATURES' input.suffixes['fea'] = { 'fea' }
-input.formats['cid'] = 'FONTCIDMAPS' input.suffixes['cid'] = { 'cid', 'cidmap' }
-
-input.formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
-input.suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
-
-input.formats ['lua'] = 'LUAINPUTS' -- new
-input.suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
--- here we catch a few new thingies (todo: add these paths to context.tmf)
---
--- FONTFEATURES = .;$TEXMF/fonts/fea//
--- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+-- the next ones can use the previous ones / combine
-function input.checkconfigdata() -- not yet ok, no time for debugging now
- local instance = input.instance
- local function fix(varname,default)
- local proname = varname .. "." .. instance.progname or "crap"
- local p = instance.environment[proname]
- local v = instance.environment[varname]
- if not ((p and p ~= "") or (v and v ~= "")) then
- instance.variables[varname] = default -- or environment?
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
end
end
- local name = os.name
- if name == "windows" then
- fix("OSFONTDIR", "c:/windows/fonts//")
- elseif name == "macosx" then
- fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
- else
- -- bad luck
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
end
- fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
- fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
- fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ return false
end
--- backward compatible ones
-input.alternatives = { }
+end -- of closure
-input.alternatives['map files'] = 'map'
-input.alternatives['enc files'] = 'enc'
-input.alternatives['cid files'] = 'cid'
-input.alternatives['fea files'] = 'fea'
-input.alternatives['opentype fonts'] = 'otf'
-input.alternatives['truetype fonts'] = 'ttf'
-input.alternatives['truetype collections'] = 'ttc'
-input.alternatives['type1 fonts'] = 'pfb'
+do -- create closure to overcome 200 locals limit
--- obscure ones
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-input.formats ['misc fonts'] = ''
-input.suffixes['misc fonts'] = { }
+local format = string.format
-input.formats ['sfd'] = 'SFDFONTS'
-input.suffixes ['sfd'] = { 'sfd' }
-input.alternatives['subfont definition files'] = 'sfd'
+local statusinfo, n, registered = { }, 0, { }
--- In practice we will work within one tds tree, but i want to keep
--- the option open to build tools that look at multiple trees, which is
--- why we keep the tree specific data in a table. We used to pass the
--- instance but for practical pusposes we now avoid this and use a
--- instance variable.
-
-function input.newinstance()
-
- local instance = { }
-
- instance.rootpath = ''
- instance.treepath = ''
- instance.progname = 'context'
- instance.engine = 'luatex'
- instance.format = ''
- instance.environment = { }
- instance.variables = { }
- instance.expansions = { }
- instance.files = { }
- instance.remap = { }
- instance.configuration = { }
- instance.setup = { }
- instance.order = { }
- instance.found = { }
- instance.foundintrees = { }
- instance.kpsevars = { }
- instance.hashes = { }
- instance.cnffiles = { }
- instance.luafiles = { }
- instance.lists = { }
- instance.remember = true
- instance.diskcache = true
- instance.renewcache = false
- instance.scandisk = true
- instance.cachepath = nil
- instance.loaderror = false
- instance.smallcache = false
- instance.sortdata = false
- instance.savelists = true
- instance.cleanuppaths = true
- instance.allresults = false
- instance.pattern = nil -- lists
- instance.kpseonly = false -- lists
- instance.loadtime = 0
- instance.starttime = 0
- instance.stoptime = 0
- instance.validfile = function(path,name) return true end
- instance.data = { } -- only for loading
- instance.force_suffixes = true
- instance.dummy_path_expr = "^!*unset/*$"
- instance.fakepaths = { }
- instance.lsrmode = false
-
- -- store once, freeze and faster (once reset we can best use instance.environment)
-
- for k,v in pairs(os.env) do
- instance.environment[k] = input.bare_variable(v)
- end
-
- -- cross referencing, delayed because we can add suffixes
-
- for k, v in pairs(input.suffixes) do
- for _, vv in pairs(v) do
- if vv then
- input.suffixmap[vv] = k
- end
- end
- end
-
- return instance
-
-end
-
-input.instance = input.instance or nil
-
-function input.reset()
- input.instance = input.newinstance()
- return input.instance
-end
-
-function input.reset_hashes()
- input.instance.lists = { }
- input.instance.found = { }
-end
-
-function input.bare_variable(str) -- assumes str is a string
- -- return string.gsub(string.gsub(string.gsub(str,"%s+$",""),'^"(.+)"$',"%1"),"^'(.+)'$","%1")
- return (str:gsub("\s*([\"\']?)(.+)%1\s*", "%2"))
-end
+statistics = statistics or { }
-function input.settrace(n)
- input.trace = tonumber(n or 0)
- if input.trace > 0 then
- input.verbose = true
- end
-end
+statistics.enable = true
+statistics.threshold = 0.05
-input.log = (texio and texio.write_nl) or print
+-- timing functions
-function input.report(...)
- if input.verbose then
- input.log("<<"..format(...)..">>")
- end
-end
+local clock = os.gettimeofday or os.clock
-function input.report(...)
- if input.trace > 0 then -- extra test
- input.log("<<"..format(...)..">>")
- end
+function statistics.hastimer(instance)
+ return instance and instance.starttime
end
-input.settrace(tonumber(os.getenv("MTX.INPUT.TRACE") or os.getenv("MTX_INPUT_TRACE") or input.trace or 0))
-
--- These functions can be used to test the performance, especially
--- loading the database files.
-
-do
- local clock = os.gettimeofday or os.clock
-
- function input.starttiming(instance)
- if instance then
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
+ end
+ if it == 0 then
instance.starttime = clock()
if not instance.loadtime then
instance.loadtime = 0
end
end
+ instance.timing = it + 1
end
+end
- function input.stoptiming(instance, report)
- if instance then
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
local starttime = instance.starttime
if starttime then
local stoptime = clock()
@@ -3098,1032 +3424,727 @@ do
instance.stoptime = stoptime
instance.loadtime = instance.loadtime + loadtime
if report then
- input.report("load time %0.3f",loadtime)
+ statistics.report("load time %0.3f",loadtime)
end
+ instance.timing = 0
return loadtime
end
end
- return 0
end
-
+ return 0
end
-function input.elapsedtime(instance)
+function statistics.elapsedtime(instance)
return format("%0.3f",(instance and instance.loadtime) or 0)
end
-function input.report_loadtime(instance)
- if instance then
- input.report('total load time %s', input.elapsedtime(instance))
- end
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
end
-input.loadtime = input.elapsedtime
+-- general function
-function input.env(key)
- return input.instance.environment[key] or input.osenv(key)
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
end
-function input.osenv(key)
- local ie = input.instance.environment
- local value = ie[key]
- if value == nil then
- -- local e = os.getenv(key)
- local e = os.env[key]
- if e == nil then
- -- value = "" -- false
- else
- value = input.bare_variable(e)
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
end
- ie[key] = value
+ statistics.enable = false
end
- return value or ""
end
--- we follow a rather traditional approach:
---
--- (1) texmf.cnf given in TEXMFCNF
--- (2) texmf.cnf searched in default variable
---
--- also we now follow the stupid route: if not set then just assume *one*
--- cnf file under texmf (i.e. distribution)
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
-input.ownpath = input.ownpath or nil
-input.ownbin = input.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
-input.autoselfdir = true -- false may be handy for debugging
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
-function input.getownpath()
- if not input.ownpath then
- if input.autoselfdir and os.selfdir then
- input.ownpath = os.selfdir
- else
- local binary = input.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
- end
- for p in string.gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
- local b = file.join(p,binary)
- if lfs.isfile(b) then
- -- we assume that after changing to the path the currentdir function
- -- resolves to the real location and use this side effect here; this
- -- trick is needed because on the mac installations use symlinks in the
- -- path instead of real locations
- local olddir = lfs.currentdir()
- if lfs.chdir(p) then
- local pp = lfs.currentdir()
- if input.verbose and p ~= pp then
- input.report("following symlink %s to %s",p,pp)
- end
- input.ownpath = pp
- lfs.chdir(olddir)
- else
- if input.verbose then
- input.report("unable to check path %s",p)
- end
- input.ownpath = p
- end
- break
- end
- end
- end
- if not input.ownpath then input.ownpath = '.' end
- end
- return input.ownpath
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
end
-function input.identify_own()
- local instance = input.instance
- local ownpath = input.getownpath() or lfs.currentdir()
- local ie = instance.environment
- if ownpath then
- if input.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
- if input.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
- if input.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
- else
- input.verbose = true
- input.report("error: unable to locate ownpath")
- os.exit()
- end
- if input.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = input.cnfdefault end
- if input.env('TEXOS') == "" then os.env['TEXOS'] = input.env('SELFAUTODIR') end
- if input.env('TEXROOT') == "" then os.env['TEXROOT'] = input.env('SELFAUTOPARENT') end
- if input.verbose then
- for _,v in ipairs({"SELFAUTOLOC","SELFAUTODIR","SELFAUTOPARENT","TEXMFCNF"}) do
- input.report("variable %s set to %s",v,input.env(v) or "unknown")
- end
- end
- function input.identify_own() end
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
end
-function input.identify_cnf()
- local instance = input.instance
- if #instance.cnffiles == 0 then
- -- fallback
- input.identify_own()
- -- the real search
- input.expand_variables()
- local t = input.split_path(input.env('TEXMFCNF'))
- t = input.aux.expanded_path(t)
- input.aux.expand_vars(t) -- redundant
- local function locate(filename,list)
- for _,v in ipairs(t) do
- local texmfcnf = input.normalize_name(file.join(v,filename))
- if lfs.isfile(texmfcnf) then
- table.insert(list,texmfcnf)
- end
- end
- end
- locate(input.luaname,instance.luafiles)
- locate(input.cnfname,instance.cnffiles)
- end
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
end
-function input.load_cnf()
- local instance = input.instance
- local function loadoldconfigdata()
- for _, fname in ipairs(instance.cnffiles) do
- input.aux.load_cnf(fname)
- end
- end
- -- instance.cnffiles contain complete names now !
- if #instance.cnffiles == 0 then
- input.report("no cnf files found (TEXMFCNF may not be set/known)")
- else
- instance.rootpath = instance.cnffiles[1]
- for k,fname in ipairs(instance.cnffiles) do
- instance.cnffiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- if instance.lsrmode then
- loadoldconfigdata()
- elseif instance.diskcache and not instance.renewcache then
- input.loadoldconfig(instance.cnffiles)
- if instance.loaderror then
- loadoldconfigdata()
- input.saveoldconfig()
- end
- else
- loadoldconfigdata()
- if instance.renewcache then
- input.saveoldconfig()
- end
- end
- input.aux.collapse_cnf_data()
- end
- input.checkconfigdata()
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
end
-function input.load_lua()
- local instance = input.instance
- if #instance.luafiles == 0 then
- -- yet harmless
- else
- instance.rootpath = instance.luafiles[1]
- for k,fname in ipairs(instance.luafiles) do
- instance.luafiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- input.loadnewconfig()
- input.aux.collapse_cnf_data()
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
end
- input.checkconfigdata()
end
-function input.aux.collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
- local instance = input.instance
- for _,c in ipairs(instance.order) do
- for k,v in pairs(c) do
- if not instance.variables[k] then
- if instance.environment[k] then
- instance.variables[k] = instance.environment[k]
- else
- instance.kpsevars[k] = true
- instance.variables[k] = input.bare_variable(v)
- end
- end
- end
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
+ else
+ write_nl(category .. " |")
end
end
-function input.aux.load_cnf(fname)
- local instance = input.instance
- fname = input.clean_path(fname)
- local lname = file.replacesuffix(fname,'lua')
- local f = io.open(lname)
- if f then -- this will go
- f:close()
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- input.aux.load_configuration(dname,lname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
else
- f = io.open(fname)
- if f then
- input.report("loading %s", fname)
- local line, data, n, k, v
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- instance.configuration[dname] = { }
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
- local data = instance.configuration[dname]
- while true do
- local line, n = f:read(), 0
- if line then
- while true do -- join lines
- line, n = line:gsub("\\%s*$", "")
- if n > 0 then
- line = line .. f:read()
- else
- break
- end
- end
- if not line:find("^[%%#]") then
- local k, v = (line:gsub("%s*%%.*$","")):match("%s*(.-)%s*=%s*(.-)%s*$")
- if k and v and not data[k] then
- data[k] = (v:gsub("[%%#].*",'')):gsub("~", "$HOME")
- instance.kpsevars[k] = true
- end
- end
- else
- break
- end
- end
- f:close()
- else
- input.report("skipping %s", fname)
- end
+ write_nl("")
end
end
--- database loading
+local texcount = tex and tex.count
-function input.load_hash()
- local instance = input.instance
- input.locatelists()
- if instance.lsrmode then
- input.loadlists()
- elseif instance.diskcache and not instance.renewcache then
- input.loadfiles()
- if instance.loaderror then
- input.loadlists()
- input.savefiles()
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
+ end
+ else
+ write(format("[%s",real))
end
else
- input.loadlists()
- if instance.renewcache then
- input.savefiles()
- end
+ write("[-")
end
end
-function input.aux.append_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash append: %s",tag)
- end
- table.insert(input.instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+function logs.tex.stop_page_number()
+ write("]")
end
-function input.aux.prepend_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash prepend: %s",tag)
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
+ else
+ write_nl(format("",category))
end
- table.insert(input.instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
end
-
-function input.aux.extend_texmf_var(specification) -- crap, we could better prepend the hash
- local instance = input.instance
--- local t = input.expanded_path_list('TEXMF') -- full expansion
- local t = input.split_path(input.env('TEXMF'))
- table.insert(t,1,specification)
- local newspec = table.join(t,";")
- if instance.environment["TEXMF"] then
- instance.environment["TEXMF"] = newspec
- elseif instance.variables["TEXMF"] then
- instance.variables["TEXMF"] = newspec
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
else
- -- weird
+ write_nl("")
end
- input.expand_variables()
- input.reset_hashes()
end
--- locators
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
-function input.locatelists()
- local instance = input.instance
- for _, path in pairs(input.clean_path_list('TEXMF')) do
- input.report("locating list of %s",path)
- input.locatedatabase(input.normalize_name(path))
- end
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
end
-function input.locatedatabase(specification)
- return input.methodhandler('locators', specification)
+function logs.xml.stop_run()
+ write_nl("")
end
-function input.locators.tex(specification)
- if specification and specification ~= '' and lfs.isdir(specification) then
- if input.trace > 0 then
- input.logger('! tex locator found: %s',specification)
- end
- input.aux.append_hash('file',specification,filename)
- elseif input.trace > 0 then
- input.logger('? tex locator not found: %s',specification)
- end
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
-function input.hashdatabase(tag,name)
- return input.methodhandler('hashers',tag,name)
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
end
-function input.loadfiles()
- local instance = input.instance
- instance.loaderror = false
- instance.files = { }
- if not instance.renewcache then
- for _, hash in ipairs(instance.hashes) do
- input.hashdatabase(hash.tag,hash.name)
- if instance.loaderror then break end
- end
- end
+function logs.xml.report_output_log()
end
-function input.hashers.tex(tag,name)
- input.aux.load_files(tag)
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
end
--- generators:
+local level = 0
-function input.loadlists()
- for _, hash in ipairs(input.instance.hashes) do
- input.generatedatabase(hash.tag)
- end
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
end
-function input.generatedatabase(specification)
- return input.methodhandler('generators', specification)
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
end
-local weird = lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
-
-function input.generators.tex(specification)
- local instance = input.instance
- local tag = specification
- if not instance.lsrmode and lfs.dir then
- input.report("scanning path %s",specification)
- instance.files[tag] = { }
- local files = instance.files[tag]
- local n, m, r = 0, 0, 0
- local spec = specification .. '/'
- local attributes = lfs.attributes
- local directory = lfs.dir
- local small = instance.smallcache
- local function action(path)
- local mode, full
- if path then
- full = spec .. path .. '/'
- else
- full = spec
- end
- for name in directory(full) do
- if name:find("^%.") then
- -- skip
- -- elseif name:find("[%~%`%!%#%$%%%^%&%*%(%)%=%{%}%[%]%:%;\"\'%|%<%>%,%?\n\r\t]") then -- too much escaped
- elseif weird:match(name) then
- -- texio.write_nl("skipping " .. name)
- -- skip
- else
- mode = attributes(full..name,'mode')
- if mode == 'directory' then
- m = m + 1
- if path then
- action(path..'/'..name)
- else
- action(name)
- end
- elseif path and mode == 'file' then
- n = n + 1
- local f = files[name]
- if f then
- if not small then
- if type(f) == 'string' then
- files[name] = { f, path }
- else
- f[#f+1] = path
- end
- end
- else
- files[name] = path
- local lower = name:lower()
- if name ~= lower then
- files["remap:"..lower] = name
- r = r + 1
- end
- end
- end
- end
- end
- end
- action()
- input.report("%s files found on %s directories with %s uppercase remappings",n,m,r)
- else
- local fullname = file.join(specification,input.lsrname)
- local path = '.'
- local f = io.open(fullname)
- if f then
- instance.files[tag] = { }
- local files = instance.files[tag]
- local small = instance.smallcache
- input.report("loading lsr file %s",fullname)
- -- for line in f:lines() do -- much slower then the next one
- for line in (f:read("*a")):gmatch("(.-)\n") do
- if line:find("^[%a%d]") then
- local fl = files[line]
- if fl then
- if not small then
- if type(fl) == 'string' then
- files[line] = { fl, path } -- table
- else
- fl[#fl+1] = path
- end
- end
- else
- files[line] = path -- string
- local lower = line:lower()
- if line ~= lower then
- files["remap:"..lower] = line
- end
- end
- else
- path = line:match("%.%/(.-)%:$") or path -- match could be nil due to empty line
- end
- end
- f:close()
- end
- end
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
end
--- savers, todo
-
-function input.savefiles()
- input.aux.save_data('files', function(k,v)
- return input.instance.validfile(k,v) -- path, name
- end)
-end
+--
--- A config (optionally) has the paths split in tables. Internally
--- we join them and split them after the expansion has taken place. This
--- is more convenient.
+local name, banner = 'report', 'context'
-function input.splitconfig()
- for i,c in ipairs(input.instance) do
- for k,v in pairs(c) do
- if type(v) == 'string' then
- local t = file.split_path(v)
- if #t > 1 then
- c[k] = t
- end
- end
- end
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
end
end
-function input.joinconfig()
- for i,c in ipairs(input.instance.order) do
- for k,v in pairs(c) do
- if type(v) == 'table' then
- c[k] = file.join_path(v)
- end
- end
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
end
end
-function input.split_path(str)
- if type(str) == 'table' then
- return str
- else
- return file.split_path(str)
+
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
end
-function input.join_path(str)
- if type(str) == 'table' then
- return file.join_path(str)
+
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
else
- return str
+ trackers.disable("resolvers.verbose")
end
+ logs.verbose = what or false
end
-function input.splitexpansions()
- local ie = input.instance.expansions
- for k,v in pairs(ie) do
- local t, h = { }, { }
- for _,vv in pairs(file.split_path(v)) do
- if vv ~= "" and not h[vv] then
- t[#t+1] = vv
- h[vv] = true
- end
- end
- if #t > 1 then
- ie[k] = t
- else
- ie[k] = t[1]
- end
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
end
end
--- end of split/join code
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
-function input.saveoldconfig()
- input.splitconfig()
- input.aux.save_data('configuration', nil)
- input.joinconfig()
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
+ end
end
-input.configbanner = [[
--- This is a Luatex configuration file created by 'luatools.lua' or
--- 'luatex.exe' directly. For comment, suggestions and questions you can
--- contact the ConTeXt Development Team. This configuration file is
--- not copyrighted. [HH & TH]
-]]
-
-function input.serialize(files)
- -- This version is somewhat optimized for the kind of
- -- tables that we deal with, so it's much faster than
- -- the generic serializer. This makes sense because
- -- luatools and mtxtools are called frequently. Okay,
- -- we pay a small price for properly tabbed tables.
- local t = { }
- local function dump(k,v,m)
- if type(v) == 'string' then
- return m .. "['" .. k .. "']='" .. v .. "',"
- elseif #v == 1 then
- return m .. "['" .. k .. "']='" .. v[1] .. "',"
- else
- return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
- end
- end
- t[#t+1] = "return {"
- if input.instance.sortdata then
- for _, k in pairs(sortedkeys(files)) do
- local fk = files[k]
- if type(fk) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for _, kk in pairs(sortedkeys(fk)) do
- t[#t+1] = dump(kk,fk[kk],"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,fk,"\t")
- end
- end
- else
- for k, v in pairs(files) do
- if type(v) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for kk,vv in pairs(v) do
- t[#t+1] = dump(kk,vv,"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,v,"\t")
- end
- end
- end
- t[#t+1] = "}"
- return concat(t,"\n")
+function logs.reportline() -- for scripts too
+ logs.report()
end
-if not texmf then texmf = {} end -- no longer needed, at least not here
+logs.simpleline = logs.reportline
-function input.aux.save_data(dataname, check, makename) -- untested without cache overload
- for cachename, files in pairs(input.instance[dataname]) do
- local name = (makename or file.join)(cachename,dataname)
- local luaname, lucname = name .. ".lua", name .. ".luc"
- input.report("preparing %s for %s",dataname,cachename)
- for k, v in pairs(files) do
- if not check or check(v,k) then -- path, name
- if type(v) == "table" and #v == 1 then
- files[k] = v[1]
- end
- else
- files[k] = nil -- false
- end
- end
- local data = {
- type = dataname,
- root = cachename,
- version = input.cacheversion,
- date = os.date("%Y-%m-%d"),
- time = os.date("%H:%M:%S"),
- content = files,
- }
- local ok = io.savedata(luaname,input.serialize(data))
- if ok then
- input.report("%s saved in %s",dataname,luaname)
- if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
- input.report("%s compiled to %s",dataname,lucname)
- else
- input.report("compiling failed for %s, deleting file %s",dataname,lucname)
- os.remove(lucname)
- end
- else
- input.report("unable to save %s in %s (access error)",dataname,luaname)
- end
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
end
end
-function input.aux.load_data(pathname,dataname,filename,makename) -- untested without cache overload
- local instance = input.instance
- filename = ((not filename or (filename == "")) and dataname) or filename
- filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
- local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
- if blob then
- local data = blob()
- if data and data.content and data.type == dataname and data.version == input.cacheversion then
- input.report("loading %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = data.content
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
+ if f then
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
+ f:close()
+ break
else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
+ sleep(0.1)
end
- else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
end
end
--- some day i'll use the nested approach, but not yet (actually we even drop
--- engine/progname support since we have only luatex now)
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
--
--- first texmfcnf.lua files are located, next the cached texmf.cnf files
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
--
--- return {
--- TEXMFBOGUS = 'effe checken of dit werkt',
--- }
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
-function input.aux.load_texmfcnf(dataname,pathname)
- local instance = input.instance
- local filename = file.join(pathname,input.luaname)
- local blob = loadfile(filename)
- if blob then
- local data = blob()
- if data then
- input.report("loading configuration file %s",filename)
- if true then
- -- flatten to variable.progname
- local t = { }
- for k, v in pairs(data) do -- v = progname
- if type(v) == "string" then
- t[k] = v
- else
- for kk, vv in pairs(v) do -- vv = variable
- if type(vv) == "string" then
- t[vv.."."..v] = kk
- end
- end
- end
- end
- instance[dataname][pathname] = t
- else
- instance[dataname][pathname] = data
- end
- else
- input.report("skipping configuration file %s",filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
- end
- else
- input.report("skipping configuration file %s",filename)
- end
-end
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
-function input.aux.load_configuration(dname,lname)
- input.aux.load_data(dname,'configuration',lname and file.basename(lname))
-end
-function input.aux.load_files(tag)
- input.aux.load_data(tag,'files')
-end
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
-function input.resetconfig()
- input.identify_own()
- local instance = input.instance
- instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
end
-function input.loadnewconfig()
- local instance = input.instance
- for _, cnf in ipairs(instance.luafiles) do
- local dname = file.dirname(cnf)
- input.aux.load_texmfcnf('setup',dname)
- instance.order[#instance.order+1] = instance.setup[dname]
- if instance.loaderror then break end
- end
-end
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
-function input.loadoldconfig()
- local instance = input.instance
- if not instance.renewcache then
- for _, cnf in ipairs(instance.cnffiles) do
- local dname = file.dirname(cnf)
- input.aux.load_configuration(dname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- if instance.loaderror then break end
- end
- end
- input.joinconfig()
-end
+-- backward compatible ones
-function input.expand_variables()
- local instance = input.instance
- local expansions, environment, variables = { }, instance.environment, instance.variables
- local env = input.env
- instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
- for k,v in pairs(environment) do
- local a, b = k:match("^(%a+)%_(.*)%s*$")
- if a and b then
- expansions[a..'.'..b] = v
- else
- expansions[k] = v
- end
- end
- for k,v in pairs(environment) do -- move environment to expansions
- if not expansions[k] then expansions[k] = v end
- end
- for k,v in pairs(variables) do -- move variables to expansions
- if not expansions[k] then expansions[k] = v end
- end
- while true do
- local busy = false
- for k,v in pairs(expansions) do
- local s, n = v:gsub("%$([%a%d%_%-]+)", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- local s, m = s:gsub("%$%{([%a%d%_%-]+)%}", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- if n > 0 or m > 0 then
- expansions[k]= s
- end
- end
- if not busy then break end
- end
- for k,v in pairs(expansions) do
- expansions[k] = v:gsub("\\", '/')
- end
-end
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
-function input.aux.expand_vars(lst) -- simple vars
- local instance = input.instance
- local variables, env = instance.variables, input.env
- for k,v in pairs(lst) do
- lst[k] = v:gsub("%$([%a%d%_%-]+)", function(a)
- return variables[a] or env(a)
- end)
- end
-end
+-- obscure ones
-function input.aux.expanded_var(var) -- simple vars
- local instance = input.instance
- return var:gsub("%$([%a%d%_%-]+)", function(a)
- return instance.variables[a] or input.env(a)
- end)
-end
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
-function input.aux.entry(entries,name)
- if name and (name ~= "") then
- local instance = input.instance
- name = name:gsub('%$','')
- local result = entries[name..'.'..instance.progname] or entries[name]
- if result then
- return result
- else
- result = input.env(name)
- if result then
- instance.variables[name] = result
- input.expand_variables()
- return instance.expansions[name] or ""
- end
- end
- end
- return ""
-end
-function input.variable(name)
- return input.aux.entry(input.instance.variables,name)
-end
-function input.expansion(name)
- return input.aux.entry(input.instance.expansions,name)
-end
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
-function input.aux.is_entry(entries,name)
- if name and name ~= "" then
- name = name:gsub('%$','')
- return (entries[name..'.'..input.instance.progname] or entries[name]) ~= nil
- else
- return false
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
end
-end
-function input.is_variable(name)
- return input.aux.is_entry(input.instance.variables,name)
-end
+ return newinstance
-function input.is_expansion(name)
- return input.aux.is_entry(input.instance.expansions,name)
end
-function input.unexpanded_path_list(str)
- local pth = input.variable(str)
- local lst = input.split_path(pth)
- return input.aux.expanded_path(lst)
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
end
-function input.unexpanded_path(str)
- return file.join_path(input.unexpanded_path_list(str))
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
end
-do
- local done = { }
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
- function input.reset_extra_path()
- local instance = input.instance
- local ep = instance.extra_paths
- if not ep then
- ep, done = { }, { }
- instance.extra_paths = ep
- elseif #ep > 0 then
- instance.lists, done = { }, { }
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
end
end
-
- function input.register_extra_path(paths,subpaths)
- local instance = input.instance
- local ep = instance.extra_paths or { }
- local n = #ep
- if paths and paths ~= "" then
- if subpaths and subpaths ~= "" then
- for p in paths:gmatch("[^,]+") do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = p .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
- else
- for p in paths:gmatch("[^,]+") do
- if not done[p] then
- ep[#ep+1] = input.clean_path(p)
- done[p] = true
- end
- end
- end
- elseif subpaths and subpaths ~= "" then
- for i=1,n do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = ep[i] .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
- end
- if #ep > 0 then
- instance.extra_paths = ep -- register paths
- end
- if #ep > n then
- instance.lists = { } -- erase the cache
- end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
end
-function input.expanded_path_list(str)
- local instance = input.instance
- local function made_list(list)
- local ep = instance.extra_paths
- if not ep or #ep == 0 then
- return list
- else
- local done, new = { }, { }
- -- honour . .. ../.. but only when at the start
- for k, v in ipairs(list) do
- if not done[v] then
- if v:find("^[%.%/]$") then
- done[v] = true
- new[#new+1] = v
- else
- break
- end
- end
- end
- -- first the extra paths
- for k, v in ipairs(ep) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- -- next the formal paths
- for k, v in ipairs(list) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- return new
- end
- end
- if not str then
- return ep or { }
- elseif instance.savelists then
- -- engine+progname hash
- str = str:gsub("%$","")
- if not instance.lists[str] then -- cached
- local lst = made_list(input.split_path(input.expansion(str)))
- instance.lists[str] = input.aux.expanded_path(lst)
- end
- return instance.lists[str]
- else
- local lst = input.split_path(input.expansion(str))
- return made_list(input.aux.expanded_path(lst))
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
end
end
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
-function input.clean_path_list(str)
- local t = input.expanded_path_list(str)
- if t then
- for i=1,#t do
- t[i] = file.collapse_path(input.clean_path(t[i]))
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
end
+ ie[key] = value
end
- return t
+ return value or ""
end
-function input.expand_path(str)
- return file.join_path(input.expanded_path_list(str))
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
end
-function input.expanded_path_list_from_var(str) -- brrr
- local tmp = input.var_of_format_or_suffix(str:gsub("%$",""))
- if tmp ~= "" then
- return input.expanded_path_list(str)
- else
- return input.expanded_path_list(tmp)
- end
-end
-function input.expand_path_from_var(str)
- return file.join_path(input.expanded_path_list_from_var(str))
-end
+--
-function input.format_of_var(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
-end
-function input.format_of_suffix(str)
- return input.suffixmap[file.extname(str)] or 'tex'
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
end
-function input.variable_of_format(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
end
-function input.var_of_format_or_suffix(str)
- local v = input.formats[str]
- if v then
- return v
- end
- v = input.formats[input.alternatives[str]]
- if v then
- return v
- end
- v = input.suffixmap[file.extname(str)]
- if v then
- return input.formats[isf]
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
end
- return ''
+ return ""
end
-function input.expand_braces(str) -- output variable and brace expansion of STRING
- local ori = input.variable(str)
- local pth = input.aux.expanded_path(input.split_path(ori))
- return file.join_path(pth)
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
end
-- {a,b,c,d}
@@ -4146,2363 +4167,2168 @@ end
-- work that well; the parsing is ok, but dealing with the resulting
-- table is a pain because we need to work inside-out recursively
-function input.aux.splitpathexpr(str, t, validate)
- -- no need for optimization, only called a few times, we can use lpeg for the sub
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
t = t or { }
- str = str:gsub(",}",",@}")
- str = str:gsub("{,","{@,")
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
-- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
while true do
- local done = false
+ done = false
while true do
- local ok = false
- str = str:gsub("([^{},]+){([^{}]+)}", function(a,b)
- local t = { }
- for s in b:gmatch("[^,]+") do t[#t+1] = a .. s end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
end
while true do
- local ok = false
- str = str:gsub("{([^{}]+)}([^{},]+)", function(a,b)
- local t = { }
- for s in a:gmatch("[^,]+") do t[#t+1] = s .. b end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
end
while true do
- local ok = false
- str = str:gsub("{([^{}]+)}{([^{}]+)}", function(a,b)
- local t = { }
- for sa in a:gmatch("[^,]+") do
- for sb in b:gmatch("[^,]+") do
- t[#t+1] = sa .. sb
- end
- end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
end
- str = str:gsub("({[^{}]*){([^{}]+)}([^{}]*})", function(a,b,c)
- done = true
- return a .. b.. c
- end)
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
if not done then break end
end
- str = str:gsub("[{}]", "")
- str = str:gsub("@","")
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
if validate then
- for s in str:gmatch("[^,]+") do
+ for s in gmatch(str,"[^,]+") do
s = validate(s)
if s then t[#t+1] = s end
end
else
- for s in str:gmatch("[^,]+") do
+ for s in gmatch(str,"[^,]+") do
t[#t+1] = s
end
end
return t
end
-function input.aux.expanded_path(pathlist) -- maybe not a list, just a path
- local instance = input.instance
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
-- a previous version fed back into pathlist
local newlist, ok = { }, false
- for _,v in ipairs(pathlist) do
- if v:find("[{}]") then
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
ok = true
break
end
end
if ok then
- for _, v in ipairs(pathlist) do
- input.aux.splitpathexpr(v, newlist, function(s)
- s = file.collapse_path(s)
- return s ~= "" and not s:find(instance.dummy_path_expr) and s
- end)
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
end
else
- for _,v in ipairs(pathlist) do
- for vv in string.gmatch(v..',',"(.-),") do
- vv = file.collapse_path(v)
- if vv ~= "" then newlist[#newlist+1] = vv end
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
end
end
end
return newlist
end
-input.is_readable = { }
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
-function input.aux.is_readable(readable, name)
- if input.trace > 2 then
- if readable then
- input.logger("+ readable: %s",name)
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
else
- input.logger("- readable: %s", name)
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
end
- return readable
-end
-
-function input.is_readable.file(name)
- return input.aux.is_readable(lfs.isfile(name), name)
+ return resolvers.ownpath
end
-input.is_readable.tex = input.is_readable.file
-
--- name
--- name/name
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
-function input.aux.collect_files(names)
- local instance = input.instance
- local filelist = { }
- for _, fname in pairs(names) do
- if fname then
- if input.trace > 2 then
- input.logger("? blobpath asked: %s",fname)
- end
- local bname = file.basename(fname)
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
local dname = file.dirname(fname)
- if dname == "" or dname:find("^%.") then
- dname = false
- else
- dname = "/" .. dname .. "$"
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
end
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local files = blobpath and instance.files[blobpath]
- if files then
- if input.trace > 2 then
- input.logger('? blobpath do: %s (%s)',blobpath,bname)
- end
- local blobfile = files[bname]
- if not blobfile then
- local rname = "remap:"..bname
- blobfile = files[rname]
- if blobfile then
- bname = files[rname]
- blobfile = files[bname]
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
end
end
- if blobfile then
- if type(blobfile) == 'string' then
- if not dname or blobfile:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,blobfile,bname), -- search
- input.concatinators[hash.type](blobpath,blobfile,bname) -- result
- }
- end
- else
- for _, vv in pairs(blobfile) do
- if not dname or vv:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,vv,bname), -- search
- input.concatinators[hash.type](blobpath,vv,bname) -- result
- }
- end
- end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
end
end
- elseif input.trace > 1 then
- input.logger('! blobpath no: %s (%s)',blobpath,bname)
+ else
+ break
end
end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
end
end
- if #filelist > 0 then
- return filelist
- else
- return nil
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
end
end
-function input.suffix_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str][1]
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
else
- return ""
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
end
+ check_configuration()
end
-function input.suffixes_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str]
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
else
- return {}
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
end
+ check_configuration()
end
-do
+-- database loading
- -- called about 700 times for an empty doc (font initializations etc)
- -- i need to weed the font files for redundant calls
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
- local letter = lpeg.R("az","AZ")
- local separator = lpeg.P("://")
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
- local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator
- local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
- -- ./name ../name /name c: ://
- function input.aux.qualified_path(filename)
- return qualified:match(filename)
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
end
- function input.aux.rootbased_path(filename)
- return rootbased:match(filename)
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
- function input.normalize_name(original)
- return original
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
end
+end
- input.normalize_name = file.collapse_path
+-- hashers
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
end
-function input.aux.register_in_trees(name)
- if not name:find("^%.") then
- local instance = input.instance
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
end
end
--- split the next one up, better for jit
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
-function input.aux.find_file(filename) -- todo : plugin (scanners, checkers etc)
- local instance = input.instance
- local result = { }
- local stamp = nil
- filename = input.normalize_name(filename) -- elsewhere
- filename = file.collapse_path(filename:gsub("\\","/")) -- elsewhere
- -- speed up / beware: format problem
- if instance.remember then
- stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
- if instance.found[stamp] then
- if input.trace > 0 then
- input.logger('! remembered: %s',filename)
- end
- return instance.found[stamp]
- end
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
end
- if filename:find('%*') then
- if input.trace > 0 then
- input.logger('! wildcard: %s', filename)
- end
- result = input.find_wildcard_files(filename)
- elseif input.aux.qualified_path(filename) then
- if input.is_readable.file(filename) then
- if input.trace > 0 then
- input.logger('! qualified: %s', filename)
- end
- result = { filename }
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
else
- local forcedname, ok = "", false
- if file.extname(filename) == "" then
- if instance.format == "" then
- forcedname = filename .. ".tex"
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing standard filetype: tex')
- end
- result, ok = { forcedname }, true
- end
- else
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- forcedname = filename .. "." .. s
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing format filetype: %s', s)
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
end
- result, ok = { forcedname }, true
- break
end
end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
end
end
- if not ok and input.trace > 0 then
- input.logger('? qualified: %s', filename)
- end
end
- else
- -- search spec
- local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
- if ext == "" then
- if not instance.force_suffixes then
- wantedfiles[#wantedfiles+1] = filename
- end
- else
- wantedfiles[#wantedfiles+1] = filename
- end
- if instance.format == "" then
- if ext == "" then
- local forcedname = filename .. '.tex'
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = input.format_of_suffix(forcedname)
- if input.trace > 0 then
- input.logger('! forcing filetype: %s',filetype)
- end
- else
- filetype = input.format_of_suffix(filename)
- if input.trace > 0 then
- input.logger('! using suffix based filetype: %s',filetype)
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
end
end
- else
- if ext == "" then
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
- end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
end
- filetype = instance.format
- if input.trace > 0 then
- input.logger('! using given filetype: %s',filetype)
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
end
end
- local typespec = input.variable_of_format(filetype)
- local pathlist = input.expanded_path_list(typespec)
- if not pathlist or #pathlist == 0 then
- -- no pathlist, access check only / todo == wildcard
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- input.logger('? filetype: %s',filetype or '?')
- input.logger('? wanted files: %s',concat(wantedfiles," | "))
- end
- for _, fname in pairs(wantedfiles) do
- if fname and input.is_readable.file(fname) then
- filename, done = fname, true
- result[#result+1] = file.join('.',fname)
- break
- end
- end
- -- this is actually 'other text files' or 'any' or 'whatever'
- local filelist = input.aux.collect_files(wantedfiles)
- local fl = filelist and filelist[1]
- if fl then
- filename = fl[3]
- result[#result+1] = filename
- done = true
- end
+ if #t > 1 then
+ ie[k] = t
else
- -- list search
- local filelist = input.aux.collect_files(wantedfiles)
- local doscan, recurse
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- -- if pathlist then input.logger('? path list: %s',concat(pathlist," | ")) end
- -- if filelist then input.logger('? file list: %s',concat(filelist," | ")) end
- end
- -- a bit messy ... esp the doscan setting here
- for _, path in pairs(pathlist) do
- if path:find("^!!") then doscan = false else doscan = true end
- if path:find("//$") then recurse = true else recurse = false end
- local pathname = path:gsub("^!+", '')
- done = false
- -- using file list
- if filelist and not (done and not instance.allresults) and recurse then
- -- compare list entries with permitted pattern
- pathname = pathname:gsub("([%-%.])","%%%1") -- this also influences
- pathname = pathname:gsub("/+$", '/.*') -- later usage of pathname
- pathname = pathname:gsub("//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname
- -- input.debug('?',expr)
- for _, fl in ipairs(filelist) do
- local f = fl[2]
- if f:find(expr) then
- -- input.debug('T',' '..f)
- if input.trace > 2 then
- input.logger('= found in hash: %s',f)
- end
- --- todo, test for readable
- result[#result+1] = fl[3]
- input.aux.register_in_trees(f) -- for tracing used files
- done = true
- if not instance.allresults then break end
- else
- -- input.debug('F',' '..f)
- end
- end
- end
- if not done and doscan then
- -- check if on disk / unchecked / does not work at all / also zips
- if input.method_is_file(pathname) then -- ?
- local pname = pathname:gsub("%.%*$",'')
- if not pname:find("%*") then
- local ppname = pname:gsub("/+$","")
- if input.aux.can_be_dir(ppname) then
- for _, w in pairs(wantedfiles) do
- local fname = file.join(ppname,w)
- if input.is_readable.file(fname) then
- if input.trace > 2 then
- input.logger('= found by scanning: %s',fname)
- end
- result[#result+1] = fname
- done = true
- if not instance.allresults then break end
- end
- end
- else
- -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
- end
- end
- end
- end
- if not done and doscan then
- -- todo: slow path scanning
- end
- if done and not instance.allresults then break end
- end
+ ie[k] = t[1]
end
end
- for k,v in pairs(result) do
- result[k] = file.collapse_path(v)
- end
- if instance.remember then
- instance.found[stamp] = result
- end
- return result
end
-input.aux._find_file_ = input.aux.find_file -- frozen variant
+-- end of split/join code
-function input.aux.find_file(filename) -- maybe make a lowres cache too
- local result = input.aux._find_file_(filename)
- if #result == 0 then
- local lowered = filename:lower()
- if filename ~= lowered then
- return input.aux._find_file_(lowered)
- end
- end
- return result
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
end
-function input.aux.can_be_dir(name)
- local instance = input.instance
- if not instance.fakepaths[name] then
- if lfs.isdir(name) then
- instance.fakepaths[name] = 1 -- directory
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
else
- instance.fakepaths[name] = 2 -- no directory
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
end
end
- return (instance.fakepaths[name] == 1)
-end
-
-if not input.concatinators then input.concatinators = { } end
-
-input.concatinators.tex = file.join
-input.concatinators.file = input.concatinators.tex
-
-function input.find_files(filename,filetype,mustexist)
- local instance = input.instance
- if type(mustexist) == boolean then
- -- all set
- elseif type(filetype) == 'boolean' then
- filetype, mustexist = nil, false
- elseif type(filetype) ~= 'string' then
- filetype, mustexist = nil, false
- end
- instance.format = filetype or ''
- local t = input.aux.find_file(filename,true)
- instance.format = ''
- return t
-end
-
-function input.find_file(filename,filetype,mustexist)
- return (input.find_files(filename,filetype,mustexist)[1] or "")
-end
-
-function input.find_given_files(filename)
- local instance = input.instance
- local bname, result = file.basename(filename), { }
- for k, hash in ipairs(instance.hashes) do
- local files = instance.files[hash.tag]
- local blist = files[bname]
- if not blist then
- local rname = "remap:"..bname
- blist = files[rname]
- if blist then
- bname = files[rname]
- blist = files[bname]
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
end
end
- if blist then
- if type(blist) == 'string' then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- if not instance.allresults then break end
- else
- for kk,vv in pairs(blist) do
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- if not instance.allresults then break end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
end
end
end
- return result
-end
-
-function input.find_given_file(filename)
- return (input.find_given_files(filename)[1] or "")
+ t[#t+1] = "}"
+ return concat(t,"\n")
end
-function input.find_wildcard_files(filename) -- todo: remap:
- local instance = input.instance
- local result = { }
- local bname, dname = file.basename(filename), file.dirname(filename)
- local path = dname:gsub("^*/","")
- path = path:gsub("*",".*")
- path = path:gsub("-","%%-")
- if dname == "" then
- path = ".*"
- end
- local name = bname
- name = name:gsub("*",".*")
- name = name:gsub("-","%%-")
- path = path:lower()
- name = name:lower()
- local function doit(blist,bname,hash,allresults)
- local done = false
- if blist then
- if type(blist) == 'string' then
- -- make function and share code
- if (blist:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- done = true
- end
- else
- for kk,vv in pairs(blist) do
- if (vv:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- done = true
- if not allresults then break end
- end
- end
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
end
end
- return done
- end
- local files, allresults, done = instance.files, instance.allresults, false
- if name:find("%*") then
- for k, hash in ipairs(instance.hashes) do
- for kk, hh in pairs(files[hash.tag]) do
- if not kk:find("^remap:") then
- if (kk:lower()):find(name) then
- if doit(hh,kk,hash,allresults) then done = true end
- if done and not allresults then break end
- end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
end
- end
- else
- for k, hash in ipairs(instance.hashes) do
- if doit(files[hash.tag][bname],bname,hash,allresults) then done = true end
- if done and not allresults then break end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
end
end
- -- we can consider also searching the paths not in the database, but then
- -- we end up with a messy search (all // in all path specs)
- return result
-end
-
-function input.find_wildcard_file(filename)
- return (input.find_wildcard_files(filename)[1] or "")
end
--- main user functions
-
-function input.save_used_files_in_trees(filename,jobname)
- local instance = input.instance
- if not filename then filename = 'luatex.jlg' end
- local f = io.open(filename,'w')
- if f then
- f:write("\n")
- f:write("\n")
- if jobname then
- f:write("\t" .. jobname .. "\n")
- end
- f:write("\t\n")
- for _,v in pairs(sorted(instance.foundintrees)) do -- ipairs
- f:write("\t\t" .. v .. "\n")
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
end
- f:write("\t\n")
- f:write("\n")
- f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
end
end
-function input.automount()
- -- implemented later
-end
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
-function input.load()
- input.starttiming(input.instance)
- input.resetconfig()
- input.identify_cnf()
- input.load_lua()
- input.expand_variables()
- input.load_cnf()
- input.expand_variables()
- input.load_hash()
- input.automount()
- input.stoptiming(input.instance)
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
end
-function input.for_files(command, files, filetype, mustexist)
- if files and #files > 0 then
- local function report(str)
- if input.verbose then
- input.report(str) -- has already verbose
- else
- print(str)
- end
- end
- if input.verbose then
- report('')
- end
- for _, file in pairs(files) do
- local result = command(file,filetype,mustexist)
- if type(result) == 'string' then
- report(result)
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
else
- for _,v in pairs(result) do
- report(v)
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
end
end
--- strtab
-
-input.var_value = input.variable -- output the value of variable $STRING.
-input.expand_var = input.expansion -- output variable expansion of STRING.
-
-function input.show_path(str) -- output search path for file type NAME
- return file.join_path(input.expanded_path_list(input.format_of_var(str)))
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
end
--- input.find_file(filename)
--- input.find_file(filename, filetype, mustexist)
--- input.find_file(filename, mustexist)
--- input.find_file(filename, filetype)
-
-function input.aux.register_file(files, name, path)
- if files[name] then
- if type(files[name]) == 'string' then
- files[name] = { files[name], path }
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
else
- files[name] = path
+ expansions[k] = v
end
- else
- files[name] = path
end
-end
-
-if not input.finders then input.finders = { } end
-if not input.openers then input.openers = { } end
-if not input.loaders then input.loaders = { } end
-
-input.finders.notfound = { nil }
-input.openers.notfound = { nil }
-input.loaders.notfound = { false, nil, 0 }
-
-function input.splitmethod(filename)
- if not filename then
- return { } -- safeguard
- elseif type(filename) == "table" then
- return filename -- already split
- elseif not filename:find("://") then
- return { scheme="file", path = filename, original=filename } -- quick hack
- else
- return url.hashed(filename)
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
end
-end
-
-function input.method_is_file(filename)
- return input.splitmethod(filename).scheme == 'file'
-end
-
-function table.sequenced(t,sep) -- temp here
- local s = { }
- for k, v in pairs(t) do
- s[#s+1] = k .. "=" .. v
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
end
- return concat(s, sep or " | ")
-end
-
-function input.methodhandler(what, filename, filetype) -- ...
- local specification = (type(filename) == "string" and input.splitmethod(filename)) or filename -- no or { }, let it bomb
- local scheme = specification.scheme
- if input[what][scheme] then
- if input.trace > 0 then
- input.logger('= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
end
- return input[what][scheme](filename,filetype) -- todo: specification
- else
- return input[what].tex(filename,filetype) -- todo: specification
+ if not busy then break end
end
-end
-
--- also inside next test?
-
-function input.findtexfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
-end
-function input.opentexfile(filename)
- return input.methodhandler('openers',input.normalize_name(filename))
-end
-
-function input.findbinfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
-end
-function input.openbinfile(filename)
- return input.methodhandler('loaders',input.normalize_name(filename))
-end
-
-function input.loadbinfile(filename, filetype)
- local fname = input.findbinfile(input.normalize_name(filename), filetype)
- if fname and fname ~= "" then
- return input.openbinfile(fname)
- else
- return unpack(input.loaders.notfound)
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
end
end
-function input.texdatablob(filename, filetype)
- local ok, data, size = input.loadbinfile(filename, filetype)
- return data or ""
+function resolvers.variable(name)
+ return entry(instance.variables,name)
end
-input.loadtexfile = input.texdatablob
-
-function input.openfile(filename)
- local fullname = input.findtexfile(filename)
- if fullname and (fullname ~= "") then
- return input.opentexfile(fullname)
- else
- return nil
- end
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
end
-function input.logmode()
- return (os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"):lower()
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
end
--- this is a prelude to engine/progname specific configuration files
--- in which case we can omit files meant for other programs and
--- packages
-
---- ctx
-
--- maybe texinputs + font paths
--- maybe positive selection tex/context fonts/tfm|afm|vf|opentype|type1|map|enc
-
-input.validators = { }
-input.validators.visibility = { }
-
-function input.validators.visibility.default(path, name)
- return true
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
end
-function input.validators.visibility.context(path, name)
- path = path[1] or path -- some day a loop
- return not (
- path:find("latex") or
--- path:find("doc") or
- path:find("tex4ht") or
- path:find("source") or
--- path:find("config") or
--- path:find("metafont") or
- path:find("lists$") or
- name:find("%.tpm$") or
- name:find("%.bak$")
- )
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
end
--- todo: describe which functions are public (maybe input.private. ... )
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
--- beware: i need to check where we still need a / on windows:
+do -- no longer needed
-function input.clean_path(str)
- if str then
- str = str:gsub("\\","/")
- str = str:gsub("^!+","")
- str = str:gsub("^~",input.homedir)
- return str
- else
- return nil
- end
-end
+ local done = { }
-function input.do_with_path(name,func)
- for _, v in pairs(input.expanded_path_list(name)) do
- func("^"..input.clean_path(v))
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
end
-end
-
-function input.do_with_var(name,func)
- func(input.aux.expanded_var(name))
-end
-function input.with_files(pattern,handle)
- local instance = input.instance
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local blobtype = hash.type
- if blobpath then
- local files = instance.files[blobpath]
- if files then
- for k,v in pairs(files) do
- if k:find("^remap:") then
- k = files[k]
- v = files[k] -- chained
- end
- if k:find(pattern) then
- if type(v) == "string" then
- handle(blobtype,blobpath,v,k)
- else
- for _,vv in pairs(v) do
- handle(blobtype,blobpath,vv,k)
- end
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
end
end
end
- end
- end
- end
-end
-
-function input.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
- local scriptpath = "scripts/context/lua"
- newname = file.addsuffix(newname,"lua")
- local oldscript = input.clean_path(oldname)
- input.report("to be replaced old script %s", oldscript)
- local newscripts = input.find_files(newname) or { }
- if #newscripts == 0 then
- input.report("unable to locate new script")
- else
- for _, newscript in ipairs(newscripts) do
- newscript = input.clean_path(newscript)
- input.report("checking new script %s", newscript)
- if oldscript == newscript then
- input.report("old and new script are the same")
- elseif not newscript:find(scriptpath) then
- input.report("new script should come from %s",scriptpath)
- elseif not (oldscript:find(file.removesuffix(newname).."$") or oldscript:find(newname.."$")) then
- input.report("invalid new script name")
else
- local newdata = io.loaddata(newscript)
- if newdata then
- input.report("old script content replaced by new content")
- io.savedata(oldscript,newdata)
- break
- else
- input.report("unable to load new script")
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
end
end
end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
end
-end
-
---~ print(table.serialize(input.aux.splitpathexpr("/usr/share/texmf-{texlive,tetex}", {})))
-
--- command line resolver:
-
---~ print(input.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
-
-do
-
- local resolvers = { }
+end
- resolvers.environment = function(str)
- return input.clean_path(os.getenv(str) or os.getenv(str:upper()) or os.getenv(str:lower()) or "")
- end
- resolvers.relative = function(str,n)
- if io.exists(str) then
- -- nothing
- elseif io.exists("./" .. str) then
- str = "./" .. str
- else
- local p = "../"
- for i=1,n or 2 do
- if io.exists(p .. str) then
- str = p .. str
- break
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
else
- p = p .. "../"
+ break
end
end
end
- return input.clean_path(str)
- end
- resolvers.locate = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path((fullname ~= "" and fullname) or str)
- end
- resolvers.filename = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.basename((fullname ~= "" and fullname) or str))
- end
- resolvers.pathname = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.dirname((fullname ~= "" and fullname) or str))
- end
-
- resolvers.env = resolvers.environment
- resolvers.rel = resolvers.relative
- resolvers.loc = resolvers.locate
- resolvers.kpse = resolvers.locate
- resolvers.full = resolvers.locate
- resolvers.file = resolvers.filename
- resolvers.path = resolvers.pathname
-
- local function resolve(str)
- if type(str) == "table" then
- for k, v in pairs(str) do
- str[k] = resolve(v) or v
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
end
- elseif str and str ~= "" then
- str = str:gsub("([a-z]+):([^ \"\']*)", function(method,target)
- if resolvers[method] then
- return resolvers[method](target)
- else
- return method .. ":" .. target
- end
- end)
end
- return str
- end
-
- if os.uname then
- for k, v in pairs(os.uname()) do
- if not resolvers[k] then
- resolvers[k] = function() return v end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
end
end
- end
-
- input.resolve = resolve
-
-end
-
-function input.boolean_variable(str,default)
- local b = input.expansion(str)
- if b == "" then
- return default
- else
- b = toboolean(b)
- return (b == nil and default) or b
- end
-end
-
-
-if not modules then modules = { } end modules ['luat-log'] = {
- version = 1.001,
- comment = "companion to luat-lib.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This is a prelude to a more extensive logging module. For the sake
-of parsing log files, in addition to the standard logging we will
-provide an structured file. Actually, any logging that
-is hooked into callbacks will be \XML\ by default.
---ldx]]--
-
--- input.logger -> special tracing, driven by log level (only input)
--- input.report -> goes to terminal, depends on verbose, has banner
--- logs.report -> module specific tracing and reporting, no banner but class
-
-
-input = input or { }
-logs = logs or { }
-
---[[ldx--
-
This looks pretty ugly but we need to speed things up a bit.
---ldx]]--
-
-logs.levels = {
- ['error'] = 1,
- ['warning'] = 2,
- ['info'] = 3,
- ['debug'] = 4
-}
-
-logs.functions = {
- 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct'
-}
-
-logs.callbacks = {
- 'start_page_number',
- 'stop_page_number',
- 'report_output_pages',
- 'report_output_log'
-}
-
-logs.tracers = {
-}
-
-logs.xml = logs.xml or { }
-logs.tex = logs.tex or { }
-
-logs.level = 0
-
-local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
-
-if texlua then
- write_nl = print
- write = io.write
-end
-
-function logs.xml.report(category,fmt,...) -- new
- write_nl(format("%s",category,format(fmt,...)))
-end
-function logs.xml.line(fmt,...) -- new
- write_nl(format("%s",format(fmt,...)))
-end
-
-function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
-function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
-function logs.xml.push () if logs.level > 0 then tw("" ) end end
-
-function logs.tex.report(category,fmt,...) -- new
- -- write_nl(format("%s | %s",category,format(fmt,...))) -- arg to format can be tex comment so .. .
- write_nl(category .. " | " .. format(fmt,...))
+ return new
+ end
end
-function logs.tex.line(fmt,...) -- new
- write_nl(format(fmt,...))
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
end
-function logs.set_level(level)
- logs.level = logs.levels[level] or level
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
end
-function logs.set_method(method)
- for _, v in pairs(logs.functions) do
- logs[v] = logs[method][v] or function() end
- end
- if callback and input[method] then
- for _, cb in pairs(logs.callbacks) do
- callback.register(cb, input[method][cb])
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
end
end
-function logs.xml.start_page_number()
- write_nl(format("")
- write_nl("")
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
end
-function logs.xml.report_output_pages(p,b)
- write_nl(format("", p))
- write_nl(format("", b))
- write_nl("")
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
end
-
-function logs.xml.report_output_log()
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
end
-function input.logger(...) -- assumes test for input.trace > n
- if input.trace > 0 then
- logs.report(...)
- end
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
end
-function input.report(fmt,...)
- if input.verbose then
- logs.report(input.banner or "report",format(fmt,...))
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
end
-end
-
-function input.reportlines(str) -- todo:
- for line in str:gmatch("(.-)[\n\r]") do
- logs.report(input.banner or "report",line)
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
end
+ return ''
end
-input.moreinfo = [[
-more information about ConTeXt and the tools that come with it can be found at:
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
-maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
-webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
-wiki : http://contextgarden.net
-]]
+resolvers.isreadable = { }
-function input.help(banner,message)
- if not input.verbose then
- input.verbose = true
- -- input.report(banner,"\n")
- end
- input.report(banner,"\n")
- input.report("")
- input.reportlines(message)
- if input.moreinfo and input.moreinfo ~= "" then
- input.report("")
- input.reportlines(input.moreinfo)
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
end
+ return readable
end
-logs.set_level('error')
-logs.set_method('tex')
-
-
-if not modules then modules = { } end modules ['luat-tmp'] = {
- version = 1.001,
- comment = "companion to luat-lib.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This module deals with caching data. It sets up the paths and
-implements loaders and savers for tables. Best is to set the
-following variable. When not set, the usual paths will be
-checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
-problem because most caching involves fonts and the chance of them
-being written at the same time is small. We also need to extend
-luatools with a recache feature.
---ldx]]--
-
-local format = string.format
-
-caches = caches or { }
-dir = dir or { }
-texmf = texmf or { }
+resolvers.isreadable.tex = resolvers.isreadable.file
-caches.path = caches.path or nil
-caches.base = caches.base or "luatex-cache"
-caches.more = caches.more or "context"
-caches.direct = false -- true is faster but may need huge amounts of memory
-caches.trace = false
-caches.tree = false
-caches.paths = caches.paths or nil
-caches.force = false
-caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
+-- name
+-- name/name
-function caches.temp()
- local cachepath = nil
- local function check(list,isenv)
- if not cachepath then
- for _, v in ipairs(list) do
- cachepath = (isenv and (os.env[v] or "")) or v or ""
- if cachepath == "" then
- -- next
- else
- cachepath = input.clean_path(cachepath)
- if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
- break
- elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
- dir.mkdirs(cachepath)
- if lfs.isdir(cachepath) and file.iswritable(cachepath) then
- break
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
end
end
end
- cachepath = nil
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
end
end
end
- check(input.clean_path_list("TEXMFCACHE") or { })
- check(caches.defaults,true)
- if not cachepath then
- print("\nfatal error: there is no valid (writable) cache path defined\n")
- os.exit()
- elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
- print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
- os.exit()
- end
- cachepath = input.normalize_name(cachepath)
- function caches.temp()
- return cachepath
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
end
- return cachepath
end
-function caches.configpath()
- return table.concat(input.instance.cnffiles,";")
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
end
-function caches.hashed(tree)
- return md5.hex((tree:lower()):gsub("[\\\/]+","/"))
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
end
---~ tracing:
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
---~ function caches.hashed(tree)
---~ tree = (tree:lower()):gsub("[\\\/]+","/")
---~ local hash = md5.hex(tree)
---~ if input.verbose then -- temp message
---~ input.report("hashing %s => %s",tree,hash)
---~ end
---~ return hash
---~ end
+-- split the next one up for readability (bu this module needs a cleanup anyway)
-function caches.treehash()
- local tree = caches.configpath()
- if not tree or tree == "" then
- return false
- else
- return caches.hashed(tree)
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
end
+ return (fakepaths[name] == 1)
end
-function caches.setpath(...)
- if not caches.path then
- if not caches.path then
- caches.path = caches.temp()
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
end
- caches.path = input.clean_path(caches.path) -- to be sure
- if lfs then
- caches.tree = caches.tree or caches.treehash()
- if caches.tree then
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
else
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
end
end
end
- if not caches.path then
- caches.path = '.'
- end
- caches.path = input.clean_path(caches.path)
- if lfs and not table.is_empty({...}) then
- local pth = dir.mkdirs(caches.path,...)
- return pth
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
end
- caches.path = dir.expand_name(caches.path)
- return caches.path
-end
-
-function caches.definepath(category,subcategory)
- return function()
- return caches.setpath(category,subcategory)
+ if instance.remember then
+ instance.found[stamp] = result
end
+ return result
end
-function caches.setluanames(path,name)
- return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
-end
-
-function caches.loaddata(path,name)
- local tmaname, tmcname = caches.setluanames(path,name)
- local loader = loadfile(tmcname) or loadfile(tmaname)
- if loader then
- return loader()
- else
- return false
- end
-end
+if not resolvers.concatinators then resolvers.concatinators = { } end
-function caches.is_writable(filepath,filename)
- local tmaname, tmcname = caches.setluanames(filepath,filename)
- return file.is_writable(tmaname)
-end
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
-function caches.savedata(filepath,filename,data,raw)
- local tmaname, tmcname = caches.setluanames(filepath,filename)
- local reduce, simplify = true, true
- if raw then
- reduce, simplify = false, false
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
end
- if caches.direct then
- file.savedata(tmaname, table.serialize(data,'return',true,true,false)) -- no hex
- else
- table.tofile(tmaname, data,'return',true,true,false) -- maybe not the last true
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
end
- local cleanup = input.boolean_variable("PURGECACHE", false)
- local strip = input.boolean_variable("LUACSTRIP", true)
- utils.lua.compile(tmaname, tmcname, cleanup, strip)
+ instance.format = ''
+ return result
end
--- here we use the cache for format loading (texconfig.[formatname|jobname])
-
---~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
-if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and input.instance then
- if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
- texconfig.formatname = caches.setpath("formats") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt")
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
end
---[[ldx--
-
Once we found ourselves defining similar cache constructs
-several times, containers were introduced. Containers are used
-to collect tables in memory and reuse them when possible based
-on (unique) hashes (to be provided by the calling function).
-
-
Caching to disk is disabled by default. Version numbers are
-stored in the saved table which makes it possible to change the
-table structures without bothering about the disk cache.
-
-
Examples of usage can be found in the font related code.
---ldx]]--
-
-containers = { }
-containers.trace = false
-
-do -- local report
-
- local function report(container,tag,name)
- if caches.trace or containers.trace or container.trace then
- logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
- end
- end
-
- local allocated = { }
-
- -- tracing
-
- function containers.define(category, subcategory, version, enabled)
- return function()
- if category and subcategory then
- local c = allocated[category]
- if not c then
- c = { }
- allocated[category] = c
- end
- local s = c[subcategory]
- if not s then
- s = {
- category = category,
- subcategory = subcategory,
- storage = { },
- enabled = enabled,
- version = version or 1.000,
- trace = false,
- path = caches.setpath(category,subcategory),
- }
- c[subcategory] = s
- end
- return s
- else
- return nil
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
end
end
- end
-
- function containers.is_usable(container, name)
- return container.enabled and caches.is_writable(container.path, name)
- end
-
- function containers.is_valid(container, name)
- if name and name ~= "" then
- local storage = container.storage[name]
- return storage and not table.is_empty(storage) and storage.cache_version == container.version
- else
- return false
- end
- end
-
- function containers.read(container,name)
- if container.enabled and not container.storage[name] then
- container.storage[name] = caches.loaddata(container.path,name)
- if containers.is_valid(container,name) then
- report(container,"loaded",name)
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
else
- container.storage[name] = nil
- end
- end
- if container.storage[name] then
- report(container,"reusing",name)
- end
- return container.storage[name]
- end
-
- function containers.write(container, name, data)
- if data then
- data.cache_version = container.version
- if container.enabled then
- local unique, shared = data.unique, data.shared
- data.unique, data.shared = nil, nil
- caches.savedata(container.path, name, data)
- report(container,"saved",name)
- data.unique, data.shared = unique, shared
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
end
- report(container,"stored",name)
- container.storage[name] = data
end
- return data
- end
-
- function containers.content(container,name)
- return container.storage[name]
end
-
+ return result
end
--- since we want to use the cache instead of the tree, we will now
--- reimplement the saver.
-
-local save_data = input.aux.save_data
-local load_data = input.aux.load_data
-
-input.cachepath = nil -- public, for tracing
-input.usecache = true -- public, for tracing
-
-function input.aux.save_data(dataname, check)
- save_data(dataname, check, function(cachename,dataname)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(cachename))
- else
- return file.join(cachename,dataname)
- end
- end)
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
end
-function input.aux.load_data(pathname,dataname,filename)
- load_data(pathname,dataname,filename,function(dataname,filename)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(pathname))
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
else
- if not filename or (filename == "") then
- filename = dataname
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
end
- return file.join(pathname,filename)
end
- end)
+ end
+ return done
end
--- we will make a better format, maybe something xml or just text or lua
-
-input.automounted = input.automounted or { }
-
-function input.automount(usecache)
- local mountpaths = input.clean_path_list(input.expansion('TEXMFMOUNT'))
- if table.is_empty(mountpaths) and usecache then
- mountpaths = { caches.setpath("mount") }
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
end
- if not table.is_empty(mountpaths) then
- input.starttiming(input.instance)
- for k, root in pairs(mountpaths) do
- local f = io.open(root.."/url.tmi")
- if f then
- for line in f:lines() do
- if line then
- if line:find("^[%%#%-]") then -- or %W
- -- skip
- elseif line:find("^zip://") then
- input.report("mounting %s",line)
- table.insert(input.automounted,line)
- input.usezipfile(line)
- end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
end
end
- f:close()
end
end
- input.stoptiming(input.instance)
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
end
--- store info in format
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
-input.storage = { }
-input.storage.data = { }
-input.storage.min = 0 -- 500
-input.storage.max = input.storage.min - 1
-input.storage.trace = false -- true
-input.storage.done = input.storage.done or 0
-input.storage.evaluators = { }
--- (evaluate,message,names)
+-- main user functions
-function input.storage.register(...)
- input.storage.data[#input.storage.data+1] = { ... }
+function resolvers.automount()
+ -- implemented later
end
-function input.storage.evaluate(name)
- input.storage.evaluators[#input.storage.evaluators+1] = name
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
end
-function input.storage.finalize() -- we can prepend the string with "evaluate:"
- for _, t in ipairs(input.storage.evaluators) do
- for i, v in pairs(t) do
- if type(v) == "string" then
- t[i] = loadstring(v)()
- elseif type(v) == "table" then
- for _, vv in pairs(v) do
- if type(vv) == "string" then
- t[i] = loadstring(vv)()
- end
- end
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
end
end
- end
-end
-
-function input.storage.dump()
- for name, data in ipairs(input.storage.data) do
- local evaluate, message, original, target = data[1], data[2], data[3] ,data[4]
- local name, initialize, finalize, code = nil, "", "", ""
- for str in target:gmatch("([^%.]+)") do
- if name then
- name = name .. "." .. str
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
else
- name = str
+ for _,v in ipairs(result) do
+ report(v)
+ end
end
- initialize = format("%s %s = %s or {} ", initialize, name, name)
- end
- if evaluate then
- finalize = "input.storage.evaluate(" .. name .. ")"
- end
- input.storage.max = input.storage.max + 1
- if input.storage.trace then
- logs.report('storage','saving %s in slot %s',message,input.storage.max)
- code =
- initialize ..
- format("logs.report('storage','restoring %s from slot %s') ",message,input.storage.max) ..
- table.serialize(original,name) ..
- finalize
- else
- code = initialize .. table.serialize(original,name) .. finalize
end
- lua.bytecode[input.storage.max] = loadstring(code)
- end
-end
-
--- we also need to count at generation time (nicer for message)
-
-if lua.bytecode then -- from 0 upwards
- local i = input.storage.min
- while lua.bytecode[i] do
- lua.bytecode[i]()
- lua.bytecode[i] = nil
- i = i + 1
end
- input.storage.done = i
end
+-- strtab
--- filename : luat-zip.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-zip'] = 1.001
-
-local format = string.format
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
-if zip and input then
- zip.supported = true
-else
- zip = { }
- zip.supported = false
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
end
-if not zip.supported then
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
- if not input then input = { } end -- will go away
-
- function zip.openarchive (...) return nil end -- needed ?
- function zip.closenarchive (...) end -- needed ?
- function input.usezipfile (...) end -- needed ?
-
-else
-
- -- zip:///oeps.zip?name=bla/bla.tex
- -- zip:///oeps.zip?tree=tex/texmf-local
-
- local function validzip(str)
- if not str:find("^zip://") then
- return "zip:///" .. str
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
else
- return str
+ files[name] = path
end
+ else
+ files[name] = path
end
+end
- zip.archives = { }
- zip.registeredfiles = { }
-
- function zip.openarchive(name)
- if not name or name == "" then
- return nil
- else
- local arch = zip.archives[name]
- if arch then
- return arch
- else
- local full = input.find_file(name) or ""
- local arch = (full ~= "" and zip.open(full)) or false
- zip.archives[name] = arch
- return arch
- end
- end
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
end
+end
- function zip.closearchive(name)
- if not name or name == "" and zip.archives[name] then
- zip.close(zip.archives[name])
- zip.archives[name] = nil
- end
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
end
+ return concat(s, sep or " | ")
+end
- -- zip:///texmf.zip?tree=/tex/texmf
- -- zip:///texmf.zip?tree=/tex/texmf-local
- -- zip:///texmf-mine.zip?tree=/tex/texmf-projects
-
- function input.locators.zip(specification) -- where is this used? startup zips (untested)
- specification = input.splitmethod(specification)
- local zipfile = specification.path
- local zfile = zip.openarchive(name) -- tricky, could be in to be initialized tree
- if input.trace > 0 then
- if zfile then
- input.logger('! zip locator, found: %s',specification.original)
- else
- input.logger('? zip locator, not found: %s',specification.original)
- end
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
end
+end
- function input.hashers.zip(tag,name)
- input.report("loading zip file %s as %s",name,tag)
- input.usezipfile(tag .."?tree=" .. name)
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
end
+end
- function input.concatinators.zip(tag,path,name)
- if not path or path == "" then
- return tag .. '?name=' .. name
- else
- return tag .. '?name=' .. path .. "/" .. name
- end
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
end
+end
- function input.is_readable.zip(name)
- return true
- end
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
- function input.finders.zip(specification,filetype)
- specification = input.splitmethod(specification)
- if specification.path then
- local q = url.query(specification.query)
- if q.name then
- local zfile = zip.openarchive(specification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('! zip finder, path: %s',specification.path)
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
end
- local dfile = zfile:open(q.name)
- if dfile then
- dfile = zfile:close()
- if input.trace > 0 then
- input.logger('+ zip finder, name: %s',q.name)
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
end
- return specification.original
end
- elseif input.trace > 0 then
- input.logger('? zip finder, path %s',specification.path)
end
end
end
- if input.trace > 0 then
- input.logger('- zip finder, name: %s',filename)
- end
- return unpack(input.finders.notfound)
end
+end
- function input.openers.zip(specification)
- local zipspecification = input.splitmethod(specification)
- if zipspecification.path then
- local q = url.query(zipspecification.query)
- if q.name then
- local zfile = zip.openarchive(zipspecification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('+ zip starter, path: %s',zipspecification.path)
- end
- local dfile = zfile:open(q.name)
- if dfile then
- input.show_open(specification)
- return input.openers.text_opener(specification,dfile,'zip')
- end
- elseif input.trace > 0 then
- input.logger('- zip starter, path %s',zipspecification.path)
- end
- end
- end
- if input.trace > 0 then
- input.logger('- zip opener, name: %s',filename)
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
end
- return unpack(input.openers.notfound)
end
+ return nil, nil
+end
- function input.loaders.zip(specification)
- specification = input.splitmethod(specification)
- if specification.path then
- local q = url.query(specification.query)
- if q.name then
- local zfile = zip.openarchive(specification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('+ zip starter, path: %s',specification.path)
- end
- local dfile = zfile:open(q.name)
- if dfile then
- input.show_load(filename)
- if input.trace > 0 then
- input.logger('+ zip loader, name: %s',filename)
- end
- local s = dfile:read("*all")
- dfile:close()
- return true, s, #s
- end
- elseif input.trace > 0 then
- input.logger('- zip starter, path: %s',specification.path)
- end
- end
- end
- if input.trace > 0 then
- input.logger('- zip loader, name: %s',filename)
- end
- return unpack(input.openers.notfound)
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
end
+end
- -- zip:///somefile.zip
- -- zip:///somefile.zip?tree=texmf-local -> mount
+texconfig.kpse_init = false
- function input.usezipfile(zipname)
- zipname = validzip(zipname)
- if input.trace > 0 then
- input.logger('! zip use, file: %s',zipname)
- end
- local specification = input.splitmethod(zipname)
- local zipfile = specification.path
- if zipfile and not zip.registeredfiles[zipname] then
- local tree = url.query(specification.query).tree or ""
- if input.trace > 0 then
- input.logger('! zip register, file: %s',zipname)
- end
- local z = zip.openarchive(zipfile)
- if z then
- local instance = input.instance
- if input.trace > 0 then
- input.logger("= zipfile, registering: %s",zipname)
- end
- input.starttiming(instance)
- input.aux.prepend_hash('zip',zipname,zipfile)
- input.aux.extend_texmf_var(zipname) -- resets hashes too
- zip.registeredfiles[zipname] = z
- instance.files[zipname] = input.aux.register_zip_file(z,tree or "")
- input.stoptiming(instance)
- elseif input.trace > 0 then
- input.logger("? zipfile, unknown: %s",zipname)
- end
- elseif input.trace > 0 then
- input.logger('! zip register, no file: %s',zipname)
- end
- end
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
- function input.aux.register_zip_file(z,tree)
- local files, filter = { }, ""
- if tree == "" then
- filter = "^(.+)/(.-)$"
- else
- filter = "^"..tree.."/(.+)/(.-)$"
- end
- if input.trace > 0 then
- input.logger('= zip filter: %s',filter)
- end
- local register, n = input.aux.register_file, 0
- for i in z:files() do
- local path, name = i.filename:match(filter)
- if path then
- if name and name ~= '' then
- register(files, name, path)
- n = n + 1
- else
- -- directory
- end
- else
- register(files, i.filename, '')
- n = n + 1
- end
- end
- input.logger('= zip entries: %s',n)
- return files
- end
+-- for a while
-end
+input = resolvers
--- filename : luat-zip.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['luat-tex'] = 1.001
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
--- special functions that deal with io
+
+TEXMFCACHE=$TMP;$TEMP;$TMPDIR;$TEMPDIR;$HOME;$TEXMFVAR;$VARTEXMF;.
+
-local format = string.format
+
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
+--ldx]]--
-if texconfig and not texlua then
+local format, lower, gsub = string.format, string.lower, string.gsub
- input.level = input.level or 0
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
- if input.logmode() == 'xml' then
- function input.show_open(name)
- input.level = input.level + 1
- texio.write_nl("")
- end
- function input.show_close(name)
- texio.write(" ")
- input.level = input.level - 1
- end
- function input.show_load(name)
- texio.write_nl("") -- level?
- end
- else
- function input.show_open () end
- function input.show_close() end
- function input.show_load () end
- end
+caches = caches or { }
- function input.finders.generic(tag,filename,filetype)
- local foundname = input.find_file(filename,filetype)
- if foundname and foundname ~= "" then
- if input.trace > 0 then
- input.logger('+ finder: %s, file: %s', tag,filename)
- end
- return foundname
- else
- if input.trace > 0 then
- input.logger('- finder: %s, file: %s', tag,filename)
- end
- return unpack(input.finders.notfound)
- end
- end
+caches.path = caches.path or nil
+caches.base = caches.base or "luatex-cache"
+caches.more = caches.more or "context"
+caches.direct = false -- true is faster but may need huge amounts of memory
+caches.tree = false
+caches.paths = caches.paths or nil
+caches.force = false
+caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
- input.filters.dynamic_translator = nil
- input.filters.frozen_translator = nil
- input.filters.utf_translator = nil
+function caches.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
- function input.openers.text_opener(filename,file_handle,tag)
- local u = unicode.utftype(file_handle)
- local t = { }
- if u > 0 then
- if input.trace > 0 then
- input.logger('+ opener: %s (%s), file: %s',tag,unicode.utfname[u],filename)
- end
- local l
- if u > 2 then
- l = unicode.utf32_to_utf8(file_handle:read("*a"),u==4)
- else
- l = unicode.utf16_to_utf8(file_handle:read("*a"),u==2)
- end
- file_handle:close()
- t = {
- utftype = u, -- may go away
- lines = l,
- current = 0, -- line number, not really needed
- handle = nil,
- noflines = #l,
- close = function()
- if input.trace > 0 then
- input.logger('= closer: %s (%s), file: %s',tag,unicode.utfname[u],filename)
- end
- input.show_close(filename)
- t = nil
- end,
---~ getline = function(n)
---~ local line = t.lines[n]
---~ if not line or line == "" then
---~ return ""
---~ else
---~ local translator = input.filters.utf_translator
---~ return (translator and translator(line)) or line
---~ end
---~ end,
- reader = function(self)
- self = self or t
- local current, lines = self.current, self.lines
- if current >= #lines then
- return nil
- else
- current = current + 1
- self.current = current
- local line = lines[current]
- if line == "" then
- return ""
- else
- local translator = input.filters.utf_translator
- -- return (translator and translator(line)) or line
- if translator then
- return translator(line)
- else
- return line
- end
+function caches.temp()
+ local cachepath = nil
+ local function check(list,isenv)
+ if not cachepath then
+ for k=1,#list do
+ local v = list[k]
+ cachepath = (isenv and (os.env[v] or "")) or v or ""
+ if cachepath == "" then
+ -- next
+ else
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ break
+ elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
+ dir.mkdirs(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then
+ break
end
end
end
- }
- else
- if input.trace > 0 then
- input.logger('+ opener: %s, file: %s',tag,filename)
+ cachepath = nil
end
- -- todo: file;name -> freeze / eerste regel scannen -> freeze
- local filters = input.filters
- t = {
- reader = function(self)
- local line = file_handle:read()
- if line == "" then
- return ""
- end
- local translator = filters.utf_translator
- if translator then
- return translator(line)
- end
- translator = filters.dynamic_translator
- if translator then
- return translator(line)
- end
- return line
- end,
- close = function()
- if input.trace > 0 then
- input.logger('= closer: %s, file: %s',tag,filename)
- end
- input.show_close(filename)
- file_handle:close()
- t = nil
- end,
- handle = function()
- return file_handle
- end,
- noflines = function()
- t.noflines = io.noflines(file_handle)
- return t.noflines
- end
- }
end
- return t
end
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
+ check(caches.defaults,true)
+ if not cachepath then
+ print("\nfatal error: there is no valid (writable) cache path defined\n")
+ os.exit()
+ elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
+ print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
+ os.exit()
+ end
+ cachepath = file.collapse_path(cachepath)
+ function caches.temp()
+ return cachepath
+ end
+ return cachepath
+end
- function input.openers.generic(tag,filename)
- if filename and filename ~= "" then
- local f = io.open(filename,"r")
- if f then
- input.show_open(filename)
- return input.openers.text_opener(filename,f,tag)
- end
- end
- if input.trace > 0 then
- input.logger('- opener: %s, file: %s',tag,filename)
- end
- return unpack(input.openers.notfound)
+function caches.configpath()
+ return table.concat(resolvers.instance.cnffiles,";")
+end
+
+function caches.hashed(tree)
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
+end
+
+function caches.treehash()
+ local tree = caches.configpath()
+ if not tree or tree == "" then
+ return false
+ else
+ return caches.hashed(tree)
end
+end
- function input.loaders.generic(tag,filename)
- if filename and filename ~= "" then
- local f = io.open(filename,"rb")
- if f then
- input.show_load(filename)
- if input.trace > 0 then
- input.logger('+ loader: %s, file: %s',tag,filename)
- end
- local s = f:read("*a")
- garbagecollector.check(s)
- f:close()
- if s then
- return true, s, #s
- end
- end
+function caches.setpath(...)
+ if not caches.path then
+ if not caches.path then
+ caches.path = caches.temp()
end
- if input.trace > 0 then
- input.logger('- loader: %s, file: %s',tag,filename)
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
end
- return unpack(input.loaders.notfound)
end
-
- function input.finders.tex(filename,filetype)
- return input.finders.generic('tex',filename,filetype)
- end
- function input.openers.tex(filename)
- return input.openers.generic('tex',filename)
+ if not caches.path then
+ caches.path = '.'
end
- function input.loaders.tex(filename)
- return input.loaders.generic('tex',filename)
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
+ local pth = dir.mkdirs(caches.path,...)
+ return pth
end
-
+ caches.path = dir.expand_name(caches.path)
+ return caches.path
end
--- callback into the file io and related things; disabling kpse
-
-
-if texconfig and not texlua then do
-
- -- this is not the right place, because we refer to quite some not yet defined tables, but who cares ...
+function caches.definepath(category,subcategory)
+ return function()
+ return caches.setpath(category,subcategory)
+ end
+end
- ctx = ctx or { }
+function caches.setluanames(path,name)
+ return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+end
- function ctx.writestatus(a,b,c,...)
- if c then
- texio.write_nl(("%-15s: %s\n"):format(a,b:format(c,...)))
- else
- texio.write_nl(("%-15s: %s\n"):format(a,b)) -- b can have %'s
- end
+function caches.loaddata(path,name)
+ local tmaname, tmcname = caches.setluanames(path,name)
+ local loader = loadfile(tmcname) or loadfile(tmaname)
+ if loader then
+ return loader()
+ else
+ return false
end
+end
- -- this will become: ctx.install_statistics(fnc() return ..,.. end) etc
-
- local statusinfo, n = { }, 0
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
- function ctx.register_statistics(tag,pattern,fnc)
- statusinfo[#statusinfo+1] = { tag, pattern, fnc }
- if #tag > n then n = #tag end
- end
+function caches.iswritable(filepath,filename)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ return file.iswritable(tmaname)
+end
- function ctx.memused()
- -- collectgarbage("collect")
- return string.format("%s MB (ctx: %s MB)",math.round(collectgarbage("count")), math.round(status.luastate_bytes/1000))
+function caches.savedata(filepath,filename,data,raw)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ local reduce, simplify = true, true
+ if raw then
+ reduce, simplify = false, false
end
-
- function ctx.show_statistics() -- todo: move calls
- local loadtime, register_statistics = input.loadtime, ctx.register_statistics
- if caches then
- register_statistics("used config path", "%s", function() return caches.configpath() end)
- register_statistics("used cache path", "%s", function() return caches.temp() or "?" end)
- end
- if status.luabytecodes > 0 and input.storage and input.storage.done then
- register_statistics("modules/dumps/instances", "%s/%s/%s", function() return status.luabytecodes-500, input.storage.done, status.luastates end)
- end
- if input.instance then
- register_statistics("input load time", "%s seconds", function() return loadtime(input.instance) end)
- end
- if fonts then
- register_statistics("fonts load time","%s seconds", function() return loadtime(fonts) end)
- end
- if xml then
- register_statistics("xml load time", "%s seconds, lpath calls: %s, cached calls: %s", function()
- local stats = xml.statistics()
- return loadtime(xml), stats.lpathcalls, stats.lpathcached
- end)
- register_statistics("lxml load time", "%s seconds preparation, backreferences: %i", function()
- return loadtime(lxml), #lxml.self
- end)
- end
- if mptopdf then
- register_statistics("mps conversion time", "%s seconds", function() return loadtime(mptopdf) end)
- end
- if nodes then
- register_statistics("node processing time", "%s seconds including kernel", function() return loadtime(nodes) end)
- end
- if kernel then
- register_statistics("kernel processing time", "%s seconds", function() return loadtime(kernel) end)
- end
- if attributes then
- register_statistics("attribute processing time", "%s seconds", function() return loadtime(attributes) end)
- end
- if languages then
- register_statistics("language load time", "%s seconds, n=%s", function() return loadtime(languages), languages.hyphenation.n() end)
- end
- if figures then
- register_statistics("graphics processing time", "%s seconds including tex, n=%s", function() return loadtime(figures), figures.n or "?" end)
- end
- if metapost then
- register_statistics("metapost processing time", "%s seconds, loading: %s seconds, execution: %s seconds, n: %s", function() return loadtime(metapost), loadtime(mplib), loadtime(metapost.exectime), metapost.n end)
- end
- if status.luastate_bytes and ctx.memused then
- register_statistics("current memory usage", "%s", ctx.memused)
- end
- if nodes then
- register_statistics("cleaned up reserved nodes", "%s nodes, %s lists of %s", function() return nodes.cleanup_reserved(tex.count[24]) end) -- \topofboxstack
- end
- if status.node_mem_usage then
- register_statistics("node memory usage", "%s", function() return status.node_mem_usage end)
- end
- if languages then
- register_statistics("loaded patterns", "%s", function() return languages.logger.report() end)
- end
- if fonts then
- register_statistics("loaded fonts", "%s", function() return fonts.logger.report() end)
- end
- if xml then -- so we are in mkiv, we need a different check
- register_statistics("runtime", "%s seconds, %i processed pages, %i shipped pages, %.3f pages/second", function()
- input.stoptiming(input.instance)
- local runtime = loadtime(input.instance)
- local shipped = tex.count['nofshipouts']
- local pages = tex.count['realpageno'] - 1
- local persecond = shipped / runtime
- return runtime, pages, shipped, persecond
- end)
- end
- for _, t in ipairs(statusinfo) do
- local tag, pattern, fnc = t[1], t[2], t[3]
- ctx.writestatus("mkiv lua stats", "%s - %s", tag:rpadd(n," "), pattern:format(fnc()))
- end-- input.expanded_path_list("osfontdir")
+ if caches.direct then
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
+ else
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
end
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ utils.lua.compile(tmaname, tmcname, cleanup, strip)
+end
-end end
-
-if texconfig and not texlua then
-
- texconfig.kpse_init = false
- texconfig.trace_file_names = input.logmode() == 'tex'
- texconfig.max_print_line = 100000
+-- here we use the cache for format loading (texconfig.[formatname|jobname])
- -- if still present, we overload kpse (put it off-line so to say)
+--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
+ if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
- input.starttiming(input.instance)
- if not input.instance then
+end -- of closure
- if not input.instance then -- prevent a second loading
+do -- create closure to overcome 200 locals limit
- input.instance = input.reset()
- input.instance.progname = 'context'
- input.instance.engine = 'luatex'
- input.instance.validfile = input.validctxfile
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
- input.load()
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
- end
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
- if callback then
- callback.register('find_read_file' , function(id,name) return input.findtexfile(name) end)
- callback.register('open_read_file' , function( name) return input.opentexfile(name) end)
- end
- if callback then
- callback.register('find_data_file' , function(name) return input.findbinfile(name,"tex") end)
- callback.register('find_enc_file' , function(name) return input.findbinfile(name,"enc") end)
- callback.register('find_font_file' , function(name) return input.findbinfile(name,"tfm") end)
- callback.register('find_format_file' , function(name) return input.findbinfile(name,"fmt") end)
- callback.register('find_image_file' , function(name) return input.findbinfile(name,"tex") end)
- callback.register('find_map_file' , function(name) return input.findbinfile(name,"map") end)
- callback.register('find_ocp_file' , function(name) return input.findbinfile(name,"ocp") end)
- callback.register('find_opentype_file' , function(name) return input.findbinfile(name,"otf") end)
- callback.register('find_output_file' , function(name) return name end)
- callback.register('find_pk_file' , function(name) return input.findbinfile(name,"pk") end)
- callback.register('find_sfd_file' , function(name) return input.findbinfile(name,"sfd") end)
- callback.register('find_truetype_file' , function(name) return input.findbinfile(name,"ttf") end)
- callback.register('find_type1_file' , function(name) return input.findbinfile(name,"pfb") end)
- callback.register('find_vf_file' , function(name) return input.findbinfile(name,"vf") end)
+end -- of closure
- callback.register('read_data_file' , function(file) return input.loadbinfile(file,"tex") end)
- callback.register('read_enc_file' , function(file) return input.loadbinfile(file,"enc") end)
- callback.register('read_font_file' , function(file) return input.loadbinfile(file,"tfm") end)
- -- format
- -- image
- callback.register('read_map_file' , function(file) return input.loadbinfile(file,"map") end)
- callback.register('read_ocp_file' , function(file) return input.loadbinfile(file,"ocp") end)
- callback.register('read_opentype_file' , function(file) return input.loadbinfile(file,"otf") end)
- -- output
- callback.register('read_pk_file' , function(file) return input.loadbinfile(file,"pk") end)
- callback.register('read_sfd_file' , function(file) return input.loadbinfile(file,"sfd") end)
- callback.register('read_truetype_file' , function(file) return input.loadbinfile(file,"ttf") end)
- callback.register('read_type1_file' , function(file) return input.loadbinfile(file,"pfb") end)
- callback.register('read_vf_file' , function(file) return input.loadbinfile(file,"vf" ) end)
- end
+do -- create closure to overcome 200 locals limit
- if input.aleph_mode == nil then environment.aleph_mode = true end -- some day we will drop omega font support
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
- if callback and input.aleph_mode then
- callback.register('find_font_file' , function(name) return input.findbinfile(name,"ofm") end)
- callback.register('read_font_file' , function(file) return input.loadbinfile(file,"ofm") end)
- callback.register('find_vf_file' , function(name) return input.findbinfile(name,"ovf") end)
- callback.register('read_vf_file' , function(file) return input.loadbinfile(file,"ovf") end)
- end
+outputs = outputs or { }
- if callback then
- callback.register('find_write_file' , function(id,name) return name end)
- end
- if callback and (not config or (#config == 0)) then
- callback.register('find_format_file' , function(name) return name end)
- end
- if callback and false then
- for k, v in pairs(callback.list()) do
- if not v then texio.write_nl("callback "..k.." is not set") end
- end
- end
+end -- of closure
- if callback then
+do -- create closure to overcome 200 locals limit
- input.start_actions = { }
- input.stop_actions = { }
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
- function input.register_start_actions(f) table.insert(input.start_actions, f) end
- function input.register_stop_actions (f) table.insert(input.stop_actions, f) end
+local format, lower, gsub = string.format, string.lower, string.gsub
- --~ callback.register('start_run', function() for _, a in pairs(input.start_actions) do a() end end)
- --~ callback.register('stop_run' , function() for _, a in pairs(input.stop_actions ) do a() end end)
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
- end
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
- if callback then
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
- if input.logmode() == 'xml' then
+
Examples of usage can be found in the font related code.
+--ldx]]--
- function input.start_page_number()
- texio.write_nl("")
- texio.write_nl("")
- end
+containers = containers or { }
- callback.register('start_page_number' , input.start_page_number)
- callback.register('stop_page_number' , input.stop_page_number )
+containers.usecache = true
- function input.report_output_pages(p,b)
- texio.write_nl(""..p.."")
- texio.write_nl(""..b.."")
- texio.write_nl("")
- end
- function input.report_output_log()
- end
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
- callback.register('report_output_pages', input.report_output_pages)
- callback.register('report_output_log' , input.report_output_log )
+local allocated = { }
- function input.start_run()
- texio.write_nl("")
- texio.write_nl("")
- texio.write_nl("")
- end
- function input.stop_run()
- texio.write_nl("")
- end
- function input.show_statistics()
- for k,v in pairs(status.list()) do
- texio.write_nl("log",""..tostring(v).."")
- end
- end
+-- tracing
- table.insert(input.start_actions, input.start_run)
- table.insert(input.stop_actions , input.show_statistics)
- table.insert(input.stop_actions , input.stop_run)
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
- else
- table.insert(input.stop_actions , input.show_statistics)
- end
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
- callback.register('start_run', function() for _, a in pairs(input.start_actions) do a() end end)
- callback.register('stop_run' , function() for _, a in pairs(input.stop_actions ) do a() end ctx.show_statistics() end)
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
end
-
end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
- if kpse then
-
- function kpse.find_file(filename,filetype,mustexist)
- return input.find_file(filename,filetype,mustexist)
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
end
- function kpse.expand_path(variable)
- return input.expand_path(variable)
- end
- function kpse.expand_var(variable)
- return input.expand_var(variable)
- end
- function kpse.expand_braces(variable)
- return input.expand_braces(variable)
- end
-
+ report(container,"stored",name)
+ container.storage[name] = data
end
+ return data
+end
+function containers.content(container,name)
+ return container.storage[name]
end
--- program specific configuration (memory settings and alike)
-if texconfig and not texlua then
+end -- of closure
- luatex = luatex or { }
+do -- create closure to overcome 200 locals limit
- luatex.variablenames = {
- 'main_memory', 'extra_mem_bot', 'extra_mem_top',
- 'buf_size','expand_depth',
- 'font_max', 'font_mem_size',
- 'hash_extra', 'max_strings', 'pool_free', 'pool_size', 'string_vacancies',
- 'obj_tab_size', 'pdf_mem_size', 'dest_names_size',
- 'nest_size', 'param_size', 'save_size', 'stack_size',
- 'trie_size', 'hyph_size', 'max_in_open',
- 'ocp_stack_size', 'ocp_list_size', 'ocp_buf_size'
- }
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
- function luatex.variables()
- local t, x = { }, nil
- for _,v in pairs(luatex.variablenames) do
- x = input.var_value(v)
- if x and x:find("^%d+$") then
- t[v] = tonumber(x)
- end
- end
- return t
- end
+local format, lower, gsub = string.format, string.lower, string.gsub
- function luatex.setvariables(tab)
- for k,v in pairs(luatex.variables()) do
- tab[k] = v
- end
- end
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
- if not luatex.variables_set then
- luatex.setvariables(texconfig)
- luatex.variables_set = true
- end
+-- since we want to use the cache instead of the tree, we will now
+-- reimplement the saver.
- texconfig.max_print_line = 100000
- texconfig.max_in_open = 127
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
-end
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
--- some tex basics, maybe this will move to ctx
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
+ else
+ return file.join(cachename,dataname)
+ end
+ end)
+end
-if tex then
+function resolvers.load_data(pathname,dataname,filename)
+ load_data(pathname,dataname,filename,function(dataname,filename)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
+ else
+ if not filename or (filename == "") then
+ filename = dataname
+ end
+ return file.join(pathname,filename)
+ end
+ end)
+end
- local texsprint, texwrite = tex.sprint, tex.write
+-- we will make a better format, maybe something xml or just text or lua
- if not cs then cs = { } end
+resolvers.automounted = resolvers.automounted or { }
- function cs.def(k,v)
- texsprint(tex.texcatcodes, "\\def\\" .. k .. "{" .. v .. "}")
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
+ if table.is_empty(mountpaths) and usecache then
+ mountpaths = { caches.setpath("mount") }
end
-
- function cs.chardef(k,v)
- texsprint(tex.texcatcodes, "\\chardef\\" .. k .. "=" .. v .. "\\relax")
+ if not table.is_empty(mountpaths) then
+ statistics.starttiming(resolvers.instance)
+ for k, root in pairs(mountpaths) do
+ local f = io.open(root.."/url.tmi")
+ if f then
+ for line in f:lines() do
+ if line then
+ if line:find("^[%%#%-]") then -- or %W
+ -- skip
+ elseif line:find("^zip://") then
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
+ end
+ end
+ end
+ f:close()
+ end
+ end
+ statistics.stoptiming(resolvers.instance)
end
+end
+
+-- status info
+
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
+
+-- experiment (code will move)
- function cs.boolcase(b)
- if b then texwrite(1) else texwrite(0) end
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
end
+end
- function cs.testcase(b)
- if b then
- texsprint(tex.texcatcodes, "\\firstoftwoarguments")
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
+ else
+ return "invalid status file"
+ end
else
- texsprint(tex.texcatcodes, "\\secondoftwoarguments")
+ return "missing status file"
end
end
-
+ return true
end
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
if not modules then modules = { } end modules ['luat-kps'] = {
version = 1.001,
comment = "companion to luatools.lua",
@@ -6522,90 +6348,218 @@ $SELFAUTODIR : /usr/tex/bin
$SELFAUTOPARENT : /usr/tex
-
If you wondered abou tsome of the previous mappings, how about
the next bunch:
--ldx]]--
-input.formats['bib'] = ''
-input.formats['bst'] = ''
-input.formats['mft'] = ''
-input.formats['ist'] = ''
-input.formats['web'] = ''
-input.formats['cweb'] = ''
-input.formats['MetaPost support'] = ''
-input.formats['TeX system documentation'] = ''
-input.formats['TeX system sources'] = ''
-input.formats['Troff fonts'] = ''
-input.formats['dvips config'] = ''
-input.formats['graphic/figure'] = ''
-input.formats['ls-R'] = ''
-input.formats['other text files'] = ''
-input.formats['other binary files'] = ''
-
-input.formats['gf'] = ''
-input.formats['pk'] = ''
-input.formats['base'] = 'MFBASES'
-input.formats['cnf'] = ''
-input.formats['mem'] = 'MPMEMS'
-input.formats['mf'] = 'MFINPUTS'
-input.formats['mfpool'] = 'MFPOOL'
-input.formats['mppool'] = 'MPPOOL'
-input.formats['texpool'] = 'TEXPOOL'
-input.formats['PostScript header'] = 'TEXPSHEADERS'
-input.formats['cmap files'] = 'CMAPFONTS'
-input.formats['type42 fonts'] = 'T42FONTS'
-input.formats['web2c files'] = 'WEB2C'
-input.formats['pdftex config'] = 'PDFTEXCONFIG'
-input.formats['texmfscripts'] = 'TEXMFSCRIPTS'
-input.formats['bitmap font'] = ''
-input.formats['lig files'] = 'LIGFONTS'
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-lst'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- used in mtxrun
+
+local find, concat, upper, format = string.find, table.concat, string.upper, string.format
+
+resolvers.listers = resolvers.listers or { }
+
+local function tabstr(str)
+ if type(str) == 'table' then
+ return concat(str," | ")
+ else
+ return str
+ end
+end
+
+local function list(list,report)
+ local instance = resolvers.instance
+ local pat = upper(pattern or "","")
+ local report = report or texio.write_nl
+ for _,key in pairs(table.sortedkeys(list)) do
+ if instance.pattern == "" or find(upper(key),pat) then
+ if instance.kpseonly then
+ if instance.kpsevars[key] then
+ report(format("%s=%s",key,tabstr(list[key])))
+ end
+ else
+ report(format('%s %s=%s',(instance.kpsevars[key] and 'K') or 'E',key,tabstr(list[key])))
+ end
+ end
+ end
+end
+
+function resolvers.listers.variables () list(resolvers.instance.variables ) end
+function resolvers.listers.expansions() list(resolvers.instance.expansions) end
+
+function resolvers.listers.configurations(report)
+ local report = report or texio.write_nl
+ local instance = resolvers.instance
+ for _,key in ipairs(table.sortedkeys(instance.kpsevars)) do
+ if not instance.pattern or (instance.pattern=="") or find(key,instance.pattern) then
+ report(format("%s\n",key))
+ for i,c in ipairs(instance.order) do
+ local str = c[key]
+ if str then
+ report(format("\t%s\t%s",i,str))
+ end
+ end
+ report("")
+ end
+ end
+end
+
+end -- of closure
-- end library merge
-- We initialize some characteristics of this program. We need to
@@ -6623,21 +6577,33 @@ own.libs = { -- todo: check which ones are really needed
'l-number.lua',
'l-set.lua',
'l-os.lua',
- 'l-md5.lua',
'l-file.lua',
+ 'l-md5.lua',
'l-url.lua',
'l-dir.lua',
'l-boolean.lua',
'l-unicode.lua',
'l-math.lua',
'l-utils.lua',
- 'luat-lib.lua',
- 'luat-inp.lua',
- 'luat-log.lua',
- 'luat-tmp.lua',
- 'luat-zip.lua',
- 'luat-tex.lua',
- 'luat-kps.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+-- 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-lst.lua', -- lister
}
-- We need this hack till luatex is fixed.
@@ -6674,11 +6640,11 @@ function locate_libs()
end
end
-if not input then
+if not resolvers then
locate_libs()
end
-if not input then
+if not resolvers then
print("")
print("Luatools is unable to start up due to lack of libraries. You may")
print("try to run 'lua luatools.lua --selfmerge' in the path where this")
@@ -6687,63 +6653,65 @@ if not input then
os.exit()
end
-input.instance = input.reset()
-input.verbose = environment.arguments["verbose"] or false
-input.banner = 'LuaTools'
-utils.report = input.report
-
-input.defaultlibs = { -- not all are needed
- 'l-string.lua', 'l-lpeg.lua', 'l-table.lua', 'l-boolean.lua', 'l-number.lua', 'l-set.lua', 'l-unicode.lua',
- 'l-md5.lua', 'l-os.lua', 'l-io.lua', 'l-file.lua', 'l-url.lua', 'l-dir.lua', 'l-utils.lua', 'l-dimen.lua',
- 'luat-lib.lua', 'luat-inp.lua', 'luat-env.lua', 'luat-tmp.lua', 'luat-zip.lua', 'luat-tex.lua'
-}
+logs.setprogram('LuaTools',"TDS Management Tool 1.31",environment.arguments["verbose"] or false)
--- todo: use environment.argument() instead of environment.arguments[]
+local instance = resolvers.reset()
-local instance = input.instance
+resolvers.defaultlibs = { -- not all are needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-boolean.lua',
+ 'l-number.lua',
+ 'l-unicode.lua',
+ 'l-os.lua',
+ 'l-io.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-url.lua',
+ 'l-dir.lua',
+ 'l-utils.lua',
+ 'l-dimen.lua',
+ 'trac-inf.lua',
+ 'trac-tra.lua',
+ 'trac-log.lua',
+ 'luat-env.lua', -- here ?
+ 'data-res.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-tmp.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-pre.lua',
+ 'data-tex.lua',
+ 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-clr.lua',
+ 'data-lua.lua',
+ 'data-ctx.lua',
+ 'luat-fio.lua',
+ 'luat-cnf.lua',
+}
instance.engine = environment.arguments["engine"] or 'luatex'
instance.progname = environment.arguments["progname"] or 'context'
instance.luaname = environment.arguments["luafile"] or "" -- environment.ownname or ""
-instance.lualibs = environment.arguments["lualibs"] or table.concat(input.defaultlibs,",")
+instance.lualibs = environment.arguments["lualibs"] or table.concat(resolvers.defaultlibs,",")
instance.allresults = environment.arguments["all"] or false
instance.pattern = environment.arguments["pattern"] or nil
instance.sortdata = environment.arguments["sort"] or false
instance.kpseonly = not environment.arguments["all"] or false
instance.my_format = environment.arguments["format"] or instance.format
-instance.lsrmode = environment.arguments["lsr"] or false
if type(instance.pattern) == 'boolean' then
- input.report("invalid pattern specification") -- toto, force verbose for one message
+ logs.simple("invalid pattern specification")
instance.pattern = nil
end
-if environment.arguments["trace"] then input.settrace(environment.arguments["trace"]) end
-
-if environment.arguments["minimize"] then
- if input.validators.visibility[instance.progname] then
- instance.validfile = input.validators.visibility[instance.progname]
- end
-end
-
-function input.my_prepare_a()
- input.resetconfig()
- input.identify_cnf()
- input.load_lua()
- input.expand_variables()
- input.load_cnf()
- input.expand_variables()
-end
-
-function input.my_prepare_b()
- input.my_prepare_a()
- input.load_hash()
- input.automount()
-end
-
--- barename
+if environment.arguments["trace"] then resolvers.settrace(environment.arguments["trace"]) end
-if not messages then messages = { } end
+runners = runners or { }
+messages = messages or { }
messages.no_ini_file = [[
There is no lua initialization file found. This file can be forced by the
@@ -6769,21 +6737,18 @@ messages.help = [[
--luafile=str lua inifile (default is .lua)
--lualibs=list libraries to assemble (optional when --compile)
--compile assemble and compile lua inifile
---mkii force context mkii mode (only for testing, not usable!)
--verbose give a bit more info
---minimize optimize lists for format
--all show all found files
--sort sort cached data
--engine=str target engine
--progname=str format or backend
--pattern=str filter variables
---lsr use lsr and cnf directly
]]
-function input.my_make_format(texname)
- local instance = input.instance
+function runners.make_format(texname)
+ local instance = resolvers.instance
if texname and texname ~= "" then
- if input.usecache then
+ if resolvers.usecache then
local path = file.join(caches.setpath("formats")) -- maybe platform
if path and lfs then
lfs.chdir(path)
@@ -6793,22 +6758,22 @@ function input.my_make_format(texname)
if barename == texname then
texname = texname .. ".tex"
end
- local fullname = input.find_files(texname)[1] or ""
+ local fullname = resolvers.find_files(texname)[1] or ""
if fullname == "" then
- input.report("no tex file with name: %s",texname)
+ logs.simple("no tex file with name: %s",texname)
else
local luaname, lucname, luapath, lualibs = "", "", "", { }
-- the following is optional, since context.lua can also
-- handle this collect and compile business
if environment.arguments["compile"] then
if luaname == "" then luaname = barename end
- input.report("creating initialization file: %s",luaname)
+ logs.simple("creating initialization file: %s",luaname)
luapath = file.dirname(luaname)
if luapath == "" then
luapath = file.dirname(texname)
end
if luapath == "" then
- luapath = file.dirname(input.find_files(texname)[1] or "")
+ luapath = file.dirname(resolvers.find_files(texname)[1] or "")
end
lualibs = string.split(instance.lualibs,",")
luaname = file.basename(barename .. ".lua")
@@ -6818,83 +6783,86 @@ function input.my_make_format(texname)
if lualibs[1] then
local firstlib = file.join(luapath,lualibs[1])
if not lfs.isfile(firstlib) then
- local foundname = input.find_files(lualibs[1])[1]
+ local foundname = resolvers.find_files(lualibs[1])[1]
if foundname then
- input.report("located library path: %s",luapath)
+ logs.simple("located library path: %s",luapath)
luapath = file.dirname(foundname)
end
end
end
- input.report("using library path: %s",luapath)
- input.report("using lua libraries: %s",table.join(lualibs," "))
+ logs.simple("using library path: %s",luapath)
+ logs.simple("using lua libraries: %s",table.join(lualibs," "))
utils.merger.selfcreate(lualibs,luapath,luaname)
- local strip = input.boolean_variable("LUACSTRIP", true)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
if utils.lua.compile(luaname,lucname,false,strip) and io.exists(lucname) then
luaname = lucname
- input.report("using compiled initialization file: %s",lucname)
+ logs.simple("using compiled initialization file: %s",lucname)
else
- input.report("using uncompiled initialization file: %s",luaname)
+ logs.simple("using uncompiled initialization file: %s",luaname)
end
else
for _, v in pairs({instance.luaname, instance.progname, barename}) do
v = string.gsub(v..".lua","%.lua%.lua$",".lua")
if v and (v ~= "") then
- luaname = input.find_files(v)[1] or ""
+ luaname = resolvers.find_files(v)[1] or ""
if luaname ~= "" then
break
end
end
end
end
+ if environment.arguments["noluc"] then
+ luaname = luaname:gsub("%.luc$",".lua") -- make this an option
+ end
if luaname == "" then
- input.reportlines(messages.no_ini_file)
- input.report("texname : %s",texname)
- input.report("luaname : %s",instance.luaname)
- input.report("progname: %s",instance.progname)
- input.report("barename: %s",barename)
+ if logs.verbose then
+ logs.simplelines(messages.no_ini_file)
+ logs.simple("texname : %s",texname)
+ logs.simple("luaname : %s",instance.luaname)
+ logs.simple("progname: %s",instance.progname)
+ logs.simple("barename: %s",barename)
+ end
else
- input.report("using lua initialization file: %s",luaname)
- local mp = dir.glob(file.stripsuffix(file.basename(luaname)).."-*.mem")
+ logs.simple("using lua initialization file: %s",luaname)
+ local mp = dir.glob(file.removesuffix(file.basename(luaname)).."-*.mem")
if mp and #mp > 0 then
for _, name in ipairs(mp) do
- input.report("removing related mplib format %s", file.basename(name))
+ logs.simple("removing related mplib format %s", file.basename(name))
os.remove(name)
end
end
- local flags = { "--ini" }
- if environment.arguments["mkii"] then
- flags[#flags+1] = "--progname=" .. instance.progname
- else
- flags[#flags+1] = "--lua=" .. string.quote(luaname)
- end
+ local flags = {
+ "--ini",
+ "--lua=" .. string.quote(luaname)
+ }
local bs = (os.platform == "unix" and "\\\\") or "\\" -- todo: make a function
local command = "luatex ".. table.concat(flags," ") .. " " .. string.quote(fullname) .. " " .. bs .. "dump"
- input.report("running command: %s\n",command)
+ logs.simple("running command: %s\n",command)
os.spawn(command)
-- todo: do a dummy run that generates the related metafun and mfplain formats
end
end
else
- input.report("no tex file given")
+ logs.simple("no tex file given")
end
end
-function input.my_run_format(name,data,more)
+function runners.run_format(name,data,more)
-- hm, rather old code here; we can now use the file.whatever functions
if name and (name ~= "") then
local barename = name:gsub("%.%a+$","")
local fmtname = ""
- if input.usecache then
+ if resolvers.usecache then
local path = file.join(caches.setpath("formats")) -- maybe platform
fmtname = file.join(path,barename..".fmt") or ""
end
if fmtname == "" then
- fmtname = input.find_files(barename..".fmt")[1] or ""
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
end
- fmtname = input.clean_path(fmtname)
+ fmtname = resolvers.clean_path(fmtname)
barename = fmtname:gsub("%.%a+$","")
if fmtname == "" then
- input.report("no format with name: %s",name)
+ logs.simple("no format with name: %s",name)
else
local luaname = barename .. ".luc"
local f = io.open(luaname)
@@ -6904,151 +6872,104 @@ function input.my_run_format(name,data,more)
end
if f then
f:close()
- local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. string.quote(more)
- input.report("running command: %s",command)
+ local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. (more ~= "" and string.quote(more) or "")
+ logs.simple("running command: %s",command)
os.spawn(command)
else
- input.report("using format name: %s",fmtname)
- input.report("no luc/lua with name: %s",barename)
- end
- end
- end
-end
-
--- helpers for verbose lists
-
-input.listers = input.listers or { }
-
-local function tabstr(str)
- if type(str) == 'table' then
- return table.concat(str," | ")
- else
- return str
- end
-end
-
-local function list(list)
- local instance = input.instance
- local pat = string.upper(pattern or "","")
- for _,key in pairs(table.sortedkeys(list)) do
- if instance.pattern == "" or string.find(key:upper(),pat) then
- if instance.kpseonly then
- if instance.kpsevars[key] then
- print(format("%s=%s",key,tabstr(list[key])))
- end
- else
- print(format('%s %s=%s',(instance.kpsevars[key] and 'K') or 'E',key,tabstr(list[key])))
- end
- end
- end
-end
-
-function input.listers.variables () list(input.instance.variables ) end
-function input.listers.expansions() list(input.instance.expansions) end
-
-function input.listers.configurations()
- local instance = input.instance
- for _,key in pairs(table.sortedkeys(instance.kpsevars)) do
- if not instance.pattern or (instance.pattern=="") or key:find(instance.pattern) then
- print(key.."\n")
- for i,c in ipairs(instance.order) do
- local str = c[key]
- if str then
- print(format("\t%s\t%s",i,str))
- end
+ logs.simple("using format name: %s",fmtname)
+ logs.simple("no luc/lua with name: %s",barename)
end
- print()
end
end
end
-input.report("%s\n",banner)
-
local ok = true
+-- private option --noluc for testing errors in the stub
+
if environment.arguments["find-file"] then
- input.my_prepare_b()
+ resolvers.load()
instance.format = environment.arguments["format"] or instance.format
if instance.pattern then
instance.allresults = true
- input.for_files(input.find_files, { instance.pattern }, instance.my_format)
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
else
- input.for_files(input.find_files, environment.files, instance.my_format)
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
end
elseif environment.arguments["find-path"] then
- input.my_prepare_b()
- local path = input.find_file(environment.files[1], instance.my_format)
- if input.verbose then
- input.report(file.dirname(path))
+ resolvers.load()
+ local path = resolvers.find_file(environment.files[1], instance.my_format)
+ if logs.verbose then
+ logs.simple(file.dirname(path))
else
print(file.dirname(path))
end
elseif environment.arguments["run"] then
- input.my_prepare_a() -- ! no need for loading databases
- input.verbose = true
- input.my_run_format(environment.files[1] or "",environment.files[2] or "",environment.files[3] or "")
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.files[1] or "",environment.files[2] or "",environment.files[3] or "")
elseif environment.arguments["fmt"] then
- input.my_prepare_a() -- ! no need for loading databases
- input.verbose = true
- input.my_run_format(environment.arguments["fmt"], environment.files[1] or "",environment.files[2] or "")
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.arguments["fmt"], environment.files[1] or "",environment.files[2] or "")
elseif environment.arguments["expand-braces"] then
- input.my_prepare_a()
- input.for_files(input.expand_braces, environment.files)
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_braces, environment.files)
elseif environment.arguments["expand-path"] then
- input.my_prepare_a()
- input.for_files(input.expand_path, environment.files)
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_path, environment.files)
elseif environment.arguments["expand-var"] or environment.arguments["expand-variable"] then
- input.my_prepare_a()
- input.for_files(input.expand_var, environment.files)
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_var, environment.files)
elseif environment.arguments["show-path"] or environment.arguments["path-value"] then
- input.my_prepare_a()
- input.for_files(input.show_path, environment.files)
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.show_path, environment.files)
elseif environment.arguments["var-value"] or environment.arguments["show-value"] then
- input.my_prepare_a()
- input.for_files(input.var_value, environment.files)
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.var_value, environment.files)
elseif environment.arguments["format-path"] then
- input.my_prepare_b()
- input.report(caches.setpath("format"))
+ resolvers.load()
+ logs.simple(caches.setpath("format"))
elseif instance.pattern then -- brrr
- input.my_prepare_b()
+ resolvers.load()
instance.format = environment.arguments["format"] or instance.format
instance.allresults = true
- input.for_files(input.find_files, { instance.pattern }, instance.my_format)
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
elseif environment.arguments["generate"] then
instance.renewcache = true
- input.verbose = true
- input.my_prepare_b(instance)
+ logs.setverbose(true)
+ resolvers.load()
elseif environment.arguments["make"] or environment.arguments["ini"] or environment.arguments["compile"] then
- input.my_prepare_b(instance)
- input.verbose = true
- input.my_make_format(environment.files[1] or "")
+ resolvers.load()
+ logs.setverbose(true)
+ runners.make_format(environment.files[1] or "")
elseif environment.arguments["selfmerge"] then
utils.merger.selfmerge(own.name,own.libs,own.list)
elseif environment.arguments["selfclean"] then
utils.merger.selfclean(own.name)
elseif environment.arguments["selfupdate"] then
- input.my_prepare_b()
- input.verbose = true
- input.update_script(own.name,"luatools")
+ resolvers.load()
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"luatools")
elseif environment.arguments["variables"] or environment.arguments["show-variables"] then
- input.my_prepare_a()
- input.listers.variables()
+ resolvers.load("nofiles")
+ resolvers.listers.variables()
elseif environment.arguments["expansions"] or environment.arguments["show-expansions"] then
- input.my_prepare_a()
- input.listers.expansions()
+ resolvers.load("nofiles")
+ resolvers.listers.expansions()
elseif environment.arguments["configurations"] or environment.arguments["show-configurations"] then
- input.my_prepare_a()
- input.listers.configurations()
+ resolvers.load("nofiles")
+ resolvers.listers.configurations()
elseif environment.arguments["help"] or (environment.files[1]=='help') or (#environment.files==0) then
- input.help(banner,messages.help)
+ logs.help(messages.help)
else
- input.my_prepare_b()
- input.for_files(input.find_files, environment.files, instance.my_format)
+ resolvers.load()
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
end
-if input.verbose then
- input.report("")
- input.report("runtime: %0.3f seconds",os.runtime())
+if logs.verbose then
+ logs.simpleline()
+ logs.simple("runtime: %0.3f seconds",os.runtime())
end
if os.platform == "unix" then
diff --git a/scripts/context/lua/mtx-babel.lua b/scripts/context/lua/mtx-babel.lua
index 92b1cd597..8d7765643 100644
--- a/scripts/context/lua/mtx-babel.lua
+++ b/scripts/context/lua/mtx-babel.lua
@@ -385,22 +385,22 @@ do
local structure = environment.argument("structure") or "document"
converter = converter[structure]
if converter then
- input.report("converting '%s' using language '%s' with structure '%s'", filename, language, structure)
+ logs.simple("converting '%s' using language '%s' with structure '%s'", filename, language, structure)
data = converter:match(data)
local newfilename = filename .. ".utf"
io.savedata(newfilename, data)
- input.report("converted data saved in '%s'", newfilename)
+ logs.simple("converted data saved in '%s'", newfilename)
else
- input.report("unknown structure '%s' language '%s'", structure, language)
+ logs.simple("unknown structure '%s' language '%s'", structure, language)
end
else
- input.report("no converter for language '%s'", language)
+ logs.simple("no converter for language '%s'", language)
end
else
- input.report("provide language")
+ logs.simple("provide language")
end
else
- input.report("no data in '%s'",filename)
+ logs.simple("no data in '%s'",filename)
end
end
end
@@ -413,7 +413,7 @@ do
end
-banner = banner .. " | babel conversion tools | version 1.2"
+logs.extendbanner("Babel Conversion Tools 1.2",true)
messages.help = [[
--language=string conversion language (e.g. greek)
@@ -421,10 +421,8 @@ messages.help = [[
--convert convert babel codes into utf
]]
-input.verbose = true
-
if environment.argument("convert") then
scripts.babel.convert(environment.files[1] or "")
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-cache.lua b/scripts/context/lua/mtx-cache.lua
index 0432168ee..a1fbed825 100644
--- a/scripts/context/lua/mtx-cache.lua
+++ b/scripts/context/lua/mtx-cache.lua
@@ -76,7 +76,7 @@ function scripts.cache.list(all)
end)
end
-banner = banner .. " | cache tools "
+logs.extendbanner("Cache Tools 0.10")
messages.help = [[
--purge remove not used files
@@ -93,5 +93,5 @@ elseif environment.argument("erase") then
elseif environment.argument("list") then
scripts.cache.list(environment.argument("all"))
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-chars.lua b/scripts/context/lua/mtx-chars.lua
index f4f751377..d4330ca30 100644
--- a/scripts/context/lua/mtx-chars.lua
+++ b/scripts/context/lua/mtx-chars.lua
@@ -6,38 +6,12 @@ if not modules then modules = { } end modules ['mtx-chars'] = {
license = "see context related readme files"
}
-local format, concat = string.format, table.concat
+local format, concat, utfchar, upper = string.format, table.concat, unicode.utf8.char, string.upper
scripts = scripts or { }
scripts.chars = scripts.chars or { }
-function scripts.chars.stixtomkiv(inname,outname)
- if inname == "" then
- logs.report("aquiring math data","invalid datafilename")
- end
- local f = io.open(inname)
- if not f then
- logs.report("aquiring math data","invalid datafile")
- else
- logs.report("aquiring math data","processing " .. inname)
- if not outname or outname == "" then
- outname = "char-mth.lua"
- end
- local classes = {
- N = "normal",
- A = "alphabetic",
- D = "diacritic",
- P = "punctuation",
- B = "binary",
- R = "relation",
- L = "large",
- O = "opening",
- C = "closing",
- F = "fence"
- }
- local valid, done = false, { }
- local g = io.open(outname,'w')
- g:write([[
+local banner = [[
-- filename : char-mth.lua
-- comment : companion to char-mth.tex (in ConTeXt)
-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
@@ -46,38 +20,70 @@ function scripts.chars.stixtomkiv(inname,outname)
if not versions then versions = { } end versions['char-mth'] = 1.001
if not characters then characters = { } end
- ]])
- g:write(format("\ncharacters.math = {\n"))
- for l in f:lines() do
- if not valid then
- valid = l:find("AMS/TeX name")
- end
- if valid then
- local unicode = l:sub(2,6)
- if unicode:sub(1,1) ~= " " and unicode ~= "" and not done[unicode] then
- local mathclass, adobename, texname = l:sub(57,57) or "", l:sub(13,36) or "", l:sub(84,109) or ""
- texname, adobename = texname:gsub("[\\ ]",""), adobename:gsub("[\\ ]","")
- local t = { }
- if mathclass ~= "" then t[#t+1] = format("mathclass='%s'", classes[mathclass] or "unknown") end
- if adobename ~= "" then t[#t+1] = format("adobename='%s'", adobename ) end
- if texname ~= "" then t[#t+1] = format("texname='%s'" , texname ) end
- if #t > 0 then
- g:write(format("\t[0x%s] = { %s },\n",unicode, concat(t,", ")))
- end
- done[unicode] = true
- end
- end
- end
- if not valid then
- g:write("\t-- The data file is corrupt, invalid or maybe the format has changed.\n")
- logs.report("aquiring math data","problems with data table")
- else
- logs.report("aquiring math data","table saved in " .. outname)
- end
- g:write("}\n")
- g:close()
- f:close()
- end
+]]
+
+--~ function scripts.chars.stixtomkiv(inname,outname)
+--~ if inname == "" then
+--~ logs.report("aquiring math data","invalid datafilename")
+--~ end
+--~ local f = io.open(inname)
+--~ if not f then
+--~ logs.report("aquiring math data","invalid datafile")
+--~ else
+--~ logs.report("aquiring math data","processing " .. inname)
+--~ if not outname or outname == "" then
+--~ outname = "char-mth.lua"
+--~ end
+--~ local classes = {
+--~ N = "normal",
+--~ A = "alphabetic",
+--~ D = "diacritic",
+--~ P = "punctuation",
+--~ B = "binary",
+--~ R = "relation",
+--~ L = "large",
+--~ O = "opening",
+--~ C = "closing",
+--~ F = "fence"
+--~ }
+--~ local valid, done = false, { }
+--~ local g = io.open(outname,'w')
+--~ g:write(banner)
+--~ g:write(format("\ncharacters.math = {\n"))
+--~ for l in f:lines() do
+--~ if not valid then
+--~ valid = l:find("AMS/TeX name")
+--~ end
+--~ if valid then
+--~ local unicode = l:sub(2,6)
+--~ if unicode:sub(1,1) ~= " " and unicode ~= "" and not done[unicode] then
+--~ local mathclass, adobename, texname = l:sub(57,57) or "", l:sub(13,36) or "", l:sub(84,109) or ""
+--~ texname, adobename = texname:gsub("[\\ ]",""), adobename:gsub("[\\ ]","")
+--~ local t = { }
+--~ if mathclass ~= "" then t[#t+1] = format("mathclass='%s'", classes[mathclass] or "unknown") end
+--~ if adobename ~= "" then t[#t+1] = format("adobename='%s'", adobename ) end
+--~ if texname ~= "" then t[#t+1] = format("texname='%s'" , texname ) end
+--~ if #t > 0 then
+--~ g:write(format("\t[0x%s] = { %s },\n",unicode, concat(t,", ")))
+--~ end
+--~ done[unicode] = true
+--~ end
+--~ end
+--~ end
+--~ if not valid then
+--~ g:write("\t-- The data file is corrupt, invalid or maybe the format has changed.\n")
+--~ logs.report("aquiring math data","problems with data table")
+--~ else
+--~ logs.report("aquiring math data","table saved in " .. outname)
+--~ end
+--~ g:write("}\n")
+--~ g:close()
+--~ f:close()
+--~ end
+--~ end
+
+function scripts.chars.stixtomkiv(inname,outname)
+ logs.report("we no longer use this options but use our own tables instead")
end
local banner_pdf_1 = [[
@@ -95,7 +101,7 @@ local banner_pdf_2 = [[
]]
function scripts.chars.makepdfr()
- local chartable = input.find_file("char-def.lua") or ""
+ local chartable = resolvers.find_file("char-def.lua") or ""
if chartable ~= "" then
dofile(chartable)
if characters and characters.data then
@@ -117,93 +123,189 @@ function scripts.chars.makepdfr()
end
end
-local banner_utf_1 = [[
-% filename : enco-utf.tex
-% comment : generated by mtxrun --script chars --utf
-% author : Hans Hagen, PRAGMA-ADE, Hasselt NL
-% copyright: PRAGMA ADE / ConTeXt Development Team
-% license : see context related readme files
+local banner_utf_module = [[
+%% filename : %s
+%% comment : generated by mtxrun --script chars --xtx
+%% author : Hans Hagen, PRAGMA-ADE, Hasselt NL
+%% copyright: PRAGMA ADE / ConTeXt Development Team
+%% license : see context related readme files
+]]
-\ifx\setcclcucx\undefined
+local banner_utf_mappings = [[
- \def\setcclcucx #1 #2 #3 %
- {\global\catcode"#1=11
- \global\lccode "#1="#2
- \global\uccode "#1="#3 }
+% lc/uc/catcode mappings
-\fi
]]
-local banner_utf_2 = [[
+local banner_utf_patch = [[
-% lc/uc/catcode mappings
+% patch needed for turkish
+\setXTXcharcodes "201C "201C "201C
+\setXTXcharcodes "201D "201D "201D
]]
-local banner_utf_3 = [[
+local banner_utf_names = [[
% named characters mapped onto utf (\\char is needed for accents)
]]
-local banner_utf_4 = [[
+local banner_utf_classes = [[
+
+% some character classes for xetex; seems to be rather hard coded, these numbers
+% and also a mix of several classes; here we do linebreaks
+
+]]
+
+local banner_utf_finish = [[
\endinput
]]
+local xtxclasses = {
+ id = 1,
+ ex = 3,
+ is = 3,
+ cm = 256,
+ op = 2,
+ ns = 3,
+ cl = 3,
+}
+
function scripts.chars.makeencoutf()
- local chartable = input.find_file("char-def.lua") or ""
+ local chartable = resolvers.find_file("char-def.lua") or ""
if chartable ~= "" then
dofile(chartable)
- if characters and characters.data then
- local f = io.open("enco-utf.tex", 'w')
+ local function open(name,banner)
+ local f = io.open(name,'w')
+ if f then
+ logs.simple("writing '%s'",name)
+ f:write(format(banner_utf_module,name))
+ f:write(banner)
+ f:write()
+ return f
+ end
+ end
+ local function close(f)
+ f:write(banner_utf_finish)
+ f:close()
+ end
+ local data = characters and characters.data
+ if data then
+ local list = table.sortedkeys(characters.data)
+ local f = open("xetx-utf.tex",banner_utf_mappings)
if f then
- f:write(banner_utf_1)
- f:write(banner_utf_2)
- local list = table.sortedkeys(characters.data)
- local length = 0
for i=1,#list do
local code = list[i]
if code <= 0xFFFF then
- local chr = characters.data[code]
+ local chr = data[code]
local cc = chr.category
if cc == 'll' or cc == 'lu' or cc == 'lt' then
if not chr.lccode then chr.lccode = code end
if not chr.uccode then chr.uccode = code end
- f:write(format("\\setcclcucx %04X %04X %04X %% %s\n",code,chr.lccode,chr.uccode,chr.description))
+ f:write(format('\\setXTXcharcodes "%05X "%05X "%05X %% %s\n',code,chr.lccode,chr.uccode,chr.description))
+ end
+ end
+ end
+ f:write("\n")
+ for i=1,#list do
+ local code = list[i]
+ local chr = data[code]
+ if chr and chr.range then
+ local cc = chr.category
+ if cc == 'lo' then
+ f:write(format('\\dofastrecurse{"%05X}{"%05X}{1}{\\dosetXTXcharcodes\\recurselevel\\recurselevel\\recurselevel}\n',code,chr.range))
end
- if #(chr.contextname or "") > length then
+ end
+ end
+ f:write(banner_utf_patch)
+ close(f)
+ end
+ local f = open("xetx-chr.tex",banner_utf_names)
+ if f then
+ local length = 0
+ for i=1,#list do
+ local code = list[i]
+ if code > 0x5B and code <= 0xFFFF then
+ local chr = data[code]
+ if chr and #(chr.contextname or "") > length then
length = #chr.contextname
end
end
end
- f:write(banner_utf_3)
for i=1,#list do
local code = list[i]
if code > 0x5B and code <= 0xFFFF then
- local chr = characters.data[code]
- if chr.contextname then
- local ch = char(code)
---~ if ch:find("[~#$%%^&{}\\]") then
- f:write(format("\\def\\%s{\\char\"%04X } %% %s: %s\n", chr.contextname:rpadd(length," "), code, chr.description, ch))
---~ else
---~ f:write(format("\\def\\%s{%s} %% %s\n", chr.contextname:rpadd(length," "), ch,chr.description))
---~ end
+ local chr = data[code]
+ if chr and chr.contextname then
+ local ch = utfchar(code)
+ f:write(format("\\def\\%s{\\char\"%05X } %% %s: %s\n", chr.contextname:rpadd(length," "), code, chr.description, ch))
end
end
end
- f:write(banner_utf_4)
- f:close()
+ close(f)
+ end
+ local f = open("xetx-cls.tex",banner_utf_classes)
+ if f then
+ for k, v in pairs(xtxclasses) do
+ f:write(format("\\defineXTXcharinjectionclass[lb:%s]\n",k))
+ end
+ f:write("\n")
+ local i_first, i_last, i_clb = nil, nil, nil
+ local function flush()
+ if i_first then
+ if i_first == i_last then
+ f:write(format('\\dosetXTXcharacterclass{"%05X}{lb:%s}\n',i_first,i_clb))
+ else
+ f:write(format('\\dofastrecurse{"%05X}{"%05X}{1}{\\dosetXTXcharacterclass\\fastrecursecounter{lb:%s}}\n',i_first,i_last,i_clb))
+ end
+ end
+ i_first, i_last, i_clb = nil, nil, nil
+ end
+ for i=1,#list do
+ local code = list[i]
+ local code_next = list[i+1]
+ local chr = data[code]
+ local chr_next = data[code_next]
+ local clb = chr and chr.linebreak
+ local lbc = xtxclasses[clb]
+ if not lbc then
+ flush()
+ elseif clb == i_clb then
+ if i_first then
+ i_last = code
+ else
+ i_first, i_last, i_clb = code, code, clb
+ end
+ else
+ flush()
+ i_first, i_last, i_clb = code, code, clb
+ end
+ end
+ flush()
+ f:write("\n")
+ for i=1,#list do
+ local code = list[i]
+ local chr = data[code]
+ if chr and chr.range then
+ local lbc = chr.linebreak
+ if xtxclasses[lbc] then
+ f:write(format('\\dofastrecurse{"%05X}{"%05X}{1}{\\dosetXTXcharacterclass\\fastrecursecounter{lb:%s}}\n',code,chr.range,lbc))
+ end
+ end
+ end
+ close(f)
end
end
end
end
-banner = banner .. " | character tools "
+logs.extendbanner("Character Tools 0.10")
messages.help = [[
--stix convert stix table to math table
---utf generate enco-utf.tex (used by xetex)
+--xtx generate xetx-*.tex (used by xetex)
--pdf generate pdfr-def.tex (used by pdftex)
]]
@@ -211,10 +313,10 @@ if environment.argument("stix") then
local inname = environment.files[1] or ""
local outname = environment.files[2] or ""
scripts.chars.stixtomkiv(inname,outname)
-elseif environment.argument("utf") then
+elseif environment.argument("xtx") then
scripts.chars.makeencoutf()
elseif environment.argument("pdf") then
scripts.chars.makepdfr()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-check.lua b/scripts/context/lua/mtx-check.lua
index 7c44fa855..6be7f2765 100644
--- a/scripts/context/lua/mtx-check.lua
+++ b/scripts/context/lua/mtx-check.lua
@@ -34,7 +34,7 @@ do
end
end
- local P, S, V, C, CP, CC = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Cp, lpeg.Cc
+ local P, R, S, V, C, CP, CC = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cp, lpeg.Cc
local i_m, d_m = P("$"), P("$$")
local l_s, r_s = P("["), P("]")
@@ -49,22 +49,27 @@ do
local line = newline / function() validator.n = validator.n + 1 end
- local grammar = P { "tokens",
- ["tokens"] = (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0,
- ["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0),
- ["grouped"] = CP() * C(l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g) * CC("group") / progress,
- ["setup"] = CP() * C(l_s * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s) * CC("setup") / progress,
- ["display"] = CP() * C(d_m * (V("whatever") + V("grouped") + (1 - d_m))^0 * d_m) * CC("display") / progress,
- ["inline"] = CP() * C(i_m * (V("whatever") + V("grouped") + (1 - i_m))^0 * i_m) * CC("inline") / progress,
- ["errors"] = (V("gerror") + V("serror") + V("derror") + V("ierror")) * true,
- ["gerror"] = CP() * (l_g + r_g) * CC("grouping") / message,
- ["serror"] = CP() * (l_s + r_g) * CC("setup error") / message,
- ["derror"] = CP() * d_m * CC("display math error") / message,
- ["ierror"] = CP() * i_m * CC("inline math error") / message,
- }
+ -- local grammar = P { "tokens",
+ -- ["tokens"] = (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0,
+ -- ["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0),
+ -- ["grouped"] = CP() * C(l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g) * CC("group") / progress,
+ -- ["setup"] = CP() * C(l_s * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s) * CC("setup") / progress,
+ -- ["display"] = CP() * C(d_m * (V("whatever") + V("grouped") + (1 - d_m))^0 * d_m) * CC("display") / progress,
+ -- ["inline"] = CP() * C(i_m * (V("whatever") + V("grouped") + (1 - i_m))^0 * i_m) * CC("inline") / progress,
+ -- ["errors"] = (V("gerror") + V("serror") + V("derror") + V("ierror")) * true,
+ -- ["gerror"] = CP() * (l_g + r_g) * CC("grouping") / message,
+ -- ["serror"] = CP() * (l_s + r_g) * CC("setup error") / message,
+ -- ["derror"] = CP() * d_m * CC("display math error") / message,
+ -- ["ierror"] = CP() * i_m * CC("inline math error") / message,
+ -- }
+
+ local startluacode = P("\\startluacode")
+ local stopluacode = P("\\stopluacode")
+
+ local somecode = startluacode * (1-stopluacode)^1 * stopluacode
local grammar = P { "tokens",
- ["tokens"] = (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0,
+ ["tokens"] = (V("ignore") + V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0,
["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0),
["grouped"] = l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g,
["setup"] = l_s * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s,
@@ -75,6 +80,7 @@ do
["serror"] = CP() * (l_s + r_g) * CC("setup error") / message,
["derror"] = CP() * d_m * CC("display math error") / message,
["ierror"] = CP() * i_m * CC("inline math error") / message,
+ ["ignore"] = somecode,
}
function validator.check(str)
@@ -117,19 +123,16 @@ function scripts.checker.check(filename)
end
end
-
-banner = banner .. " | tex check tools "
+logs.extendbanner("Syntax Checking 0.10",true)
messages.help = [[
--convert check tex file for errors
]]
-input.verbose = true
-
if environment.argument("check") then
scripts.checker.check(environment.files[1])
elseif environment.argument("help") then
- input.help(banner,messages.help)
+ logs.help(messages.help)
elseif environment.files[1] then
scripts.checker.check(environment.files[1])
end
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua
index 7d5eb7e80..2bae51501 100644
--- a/scripts/context/lua/mtx-context.lua
+++ b/scripts/context/lua/mtx-context.lua
@@ -23,30 +23,6 @@ function io.copydata(fromfile,tofile)
io.savedata(tofile,io.loaddata(fromfile) or "")
end
--- luat-inp
-
-function input.locate_format(name) -- move this to core / luat-xxx
- local barename, fmtname = name:gsub("%.%a+$",""), ""
- if input.usecache then
- local path = file.join(caches.setpath("formats")) -- maybe platform
- fmtname = file.join(path,barename..".fmt") or ""
- end
- if fmtname == "" then
- fmtname = input.find_files(barename..".fmt")[1] or ""
- end
- fmtname = input.clean_path(fmtname)
- if fmtname ~= "" then
- barename = fmtname:gsub("%.%a+$","")
- local luaname, lucname = barename .. ".lua", barename .. ".luc"
- if lfs.isfile(lucname) then
- return barename, luaname
- elseif lfs.isfile(luaname) then
- return barename, luaname
- end
- end
- return nil, nil
-end
-
-- ctx
ctxrunner = { }
@@ -135,15 +111,15 @@ do
elseif ctxdata.ctxname then
ctlname = file.replacesuffix(ctxdata.ctxname,'ctl')
else
- input.report("invalid ctl name: %s",ctlname or "?")
+ logs.simple("invalid ctl name: %s",ctlname or "?")
return
end
end
if table.is_empty(ctxdata.prepfiles) then
- input.report("nothing prepared, no ctl file saved")
+ logs.simple("nothing prepared, no ctl file saved")
os.remove(ctlname)
else
- input.report("saving logdata in: %s",ctlname)
+ logs.simple("saving logdata in: %s",ctlname)
f = io.open(ctlname,'w')
if f then
f:write("\n\n")
@@ -188,8 +164,8 @@ do
ctxdata.jobname = file.addsuffix(ctxdata.jobname,'tex')
ctxdata.ctxname = file.addsuffix(ctxdata.ctxname,'ctx')
- input.report("jobname: %s",ctxdata.jobname)
- input.report("ctxname: %s",ctxdata.ctxname)
+ logs.simple("jobname: %s",ctxdata.jobname)
+ logs.simple("ctxname: %s",ctxdata.ctxname)
-- mtxrun should resolve kpse: and file:
@@ -206,7 +182,7 @@ do
end
end
- if not found and defaultname and defaultname ~= "" and file.exists(defaultname) then
+ if not found and defaultname and defaultname ~= "" and lfs.isfile(defaultname) then
usedname, found = defaultname, true
end
@@ -236,7 +212,7 @@ do
ctxdata.flags = ctxrunner.reflag(ctxdata.flags)
for _, message in ipairs(ctxdata.messages) do
- input.report("ctx comment: %s", xml.tostring(message))
+ logs.simple("ctx comment: %s", xml.tostring(message))
end
xml.each(ctxdata.xmldata,"ctx:value[@name='job']", function(ek,e,k)
@@ -326,10 +302,10 @@ do
-- potential optimization: when mtxrun run internal
command = xml.text(command)
command = ctxrunner.justtext(command) -- command is still xml element here
- input.report("command: %s",command)
+ logs.simple("command: %s",command)
local result = os.spawn(command) or 0
if result > 0 then
- input.report("error, return code: %s",result)
+ logs.simple("error, return code: %s",result)
end
if ctxdata.runlocal then
oldfile = file.basename(oldfile)
@@ -340,11 +316,11 @@ do
file.syncmtimes(oldfile,newfile)
ctxdata.prepfiles[oldfile] = true
else
- input.report("error, check target location of new file: %s", newfile)
+ logs.simple("error, check target location of new file: %s", newfile)
ctxdata.prepfiles[oldfile] = false
end
else
- input.report("old file needs no preprocessing")
+ logs.simple("old file needs no preprocessing")
ctxdata.prepfiles[oldfile] = lfs.isfile(newfile)
end
end
@@ -362,7 +338,8 @@ end
-- rest
scripts.context.multipass = {
- suffixes = { ".tuo", ".tuc" },
+-- suffixes = { ".tuo", ".tuc" },
+ suffixes = { ".tuc" },
nofruns = 8,
}
@@ -394,6 +371,7 @@ scripts.context.backends = {
function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,currentrun,finalrun)
-- take jobname from ctx
+ jobname = file.removesuffix(jobname)
local f = io.open(jobname..".top","w")
if f then
local function someflag(flag)
@@ -433,74 +411,124 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
local function setalways(format,...)
f:write(format:format(...),"\n")
end
+ --
+ setalways("%% runtime options files (command line driven)")
+ --
setalways("\\unprotect")
- setvalue('output' , "\\setupoutput[%s]", scripts.context.backends, 'pdftex')
- setalways( "\\setupsystem[\\c!n=%s,\\c!m=%s]", kindofrun or 0, currentrun or 0)
- setalways( "\\setupsystem[\\c!type=%s]",os.platform)
+ --
+ setalways("%% special commands, mostly for the ctx development team")
+ --
+ if environment.argument("dumpdelta") then
+ setalways("\\tracersdumpdelta")
+ elseif environment.argument("dumphash") then
+ setalways("\\tracersdumphash")
+ end
+ setalways("%% feedback and basic job control")
+ if type(environment.argument("track")) == "string" then
+ setvalue ("track" , "\\enabletrackers[%s]")
+ end
+ setfixed ("timing" , "\\usemodule[timing]")
setfixed ("batchmode" , "\\batchmode")
setfixed ("nonstopmode" , "\\nonstopmode")
setfixed ("tracefiles" , "\\tracefilestrue")
+ setfixed ("nostats" , "\\nomkivstatistics")
setfixed ("paranoid" , "\\def\\maxreadlevel{1}")
- setvalues("modefile" , "\\readlocfile{%s}{}{}")
+ --
+ setalways("%% handy for special styles")
+ --
+ setalways("\\startluacode")
+ setalways("document = document or { }")
+ setalways(table.serialize(environment.arguments, "document.arguments"))
+ setalways(table.serialize(environment.files, "document.files"))
+ setalways("\\stopluacode")
+ --
+ setalways("%% process info")
+ --
+ setalways( "\\setupsystem[\\c!n=%s,\\c!m=%s]", kindofrun or 0, currentrun or 0)
+ setalways( "\\setupsystem[\\c!type=%s]",os.platform)
setvalue ("inputfile" , "\\setupsystem[inputfile=%s]")
setvalue ("result" , "\\setupsystem[file=%s]")
setvalues("path" , "\\usepath[%s]")
+ setvalue ("setuppath" , "\\setupsystem[\\c!directory={%s}]")
+ setvalue ("randomseed" , "\\setupsystem[\\c!random=%s]")
+ setvalue ("arguments" , "\\setupenv[%s]")
+ setalways("%% modes")
+ setvalues("modefile" , "\\readlocfile{%s}{}{}")
+ setvalues("mode" , "\\enablemode[%s]", true)
+ if ctxdata then
+ setvalues(ctxdata.modes, "\\enablemode[%s]")
+ end
+ --
+ setalways("%% options (not that important)")
+ --
+ setalways("\\startsetups *runtime:options")
+ setvalue ('output' , "\\setupoutput[%s]", scripts.context.backends, 'pdftex')
setfixed ("color" , "\\setupcolors[\\c!state=\\v!start]")
- -- setfixed ("nompmode" , "\\runMPgraphicsfalse") -- obsolete, we assume runtime mp graphics
- -- setfixed ("nomprun" , "\\runMPgraphicsfalse") -- obsolete, we assume runtime mp graphics
- -- setfixed ("automprun" , "\\runMPgraphicsfalse") -- obsolete, we assume runtime mp graphics
- setfixed ("fast" , "\\fastmode\n")
- setfixed ("silentmode" , "\\silentmode\n")
- setfixed ("nostats" , "\\nomkivstatistics\n")
setvalue ("separation" , "\\setupcolors[\\c!split=%s]")
- setvalue ("setuppath" , "\\setupsystem[\\c!directory={%s}]")
setfixed ("noarrange" , "\\setuparranging[\\v!disable]")
if environment.argument('arrange') and not finalrun then
setalways( "\\setuparranging[\\v!disable]")
end
- setvalue ("randomseed" , "\\setupsystem[\\c!random=%s]")
- setvalue ("arguments" , "\\setupenv[%s]")
- -- singular and plural
- setvalues("mode" , "\\enablemode[%s]", true)
+ setalways("\\stopsetups")
+ --
+ setalways("%% styles and modules")
+ --
+ setalways("\\startsetups *runtime:modules")
setvalues("filter" , "\\useXMLfilter[%s]", true)
setvalues("usemodule" , "\\usemodule[%s]", true)
setvalues("environment" , "\\environment %s ", true)
- -- ctx stuff
if ctxdata then
- setvalues(ctxdata.modes, "\\enablemode[%s]")
setvalues(ctxdata.modules, "\\usemodule[%s]")
setvalues(ctxdata.environments, "\\environment %s ")
end
- -- done
- setalways("\\protect")
- setalways("\\endinput")
+ setalways("\\stopsetups")
+ --
+ setalways("%% done")
+ --
+ setalways("\\protect \\endinput")
f:close()
end
end
function scripts.context.multipass.copyluafile(jobname)
- io.savedata(jobname..".tuc",io.loaddata(jobname..".tua") or "")
-end
-
-function scripts.context.multipass.copytuifile(jobname)
- local f, g = io.open(jobname..".tui"), io.open(jobname..".tuo",'w')
- if f and g then
- g:write("% traditional utility file, only commands written by mtxrun/context\n%\n")
- for line in f:lines() do
- if line:find("^c ") then
- g:write((line:gsub("^c ","")),"%\n")
- end
- end
- g:write("\\endinput\n")
- f:close()
- g:close()
+-- io.savedata(jobname..".tuc",io.loaddata(jobname..".tua") or "")
+ local tuaname, tucname = jobname..".tua", jobname..".tuc"
+ if lfs.isfile(tuaname) then
+ os.remove(tucname)
+ os.rename(tuaname,tucname)
end
end
+-- obsolete:
+--
+-- function scripts.context.multipass.copytuifile(jobname)
+-- local tuiname, tuoname = jobname .. ".tui", jobname .. ".tuo"
+-- if lfs.isfile(tuiname) then
+-- local f, g = io.open(tuiname), io.open(tuoname,'w')
+-- if f and g then
+-- g:write("% traditional utility file, only commands written by mtxrun/context\n%\n")
+-- for line in f:lines() do
+-- if line:find("^c ") then
+-- g:write((line:gsub("^c ","")),"%\n")
+-- end
+-- end
+-- g:write("\\endinput\n")
+-- f:close()
+-- g:close()
+-- end
+-- else
+-- -- os.remove(tuoname)
+-- end
+-- end
+
scripts.context.xmlsuffixes = table.tohash {
"xml",
}
+scripts.context.luasuffixes = table.tohash {
+ "lua",
+}
+
scripts.context.beforesuffixes = {
"tuo", "tuc"
}
@@ -518,12 +546,17 @@ scripts.context.interfaces = {
it = "cont-it",
ro = "cont-ro",
pe = "cont-pe",
+ -- for taco and me
+ -- xp = "cont-xp",
}
scripts.context.defaultformats = {
"cont-en",
"cont-nl",
+-- "cont-xp",
"mptopdf",
+-- "metatex",
+ "metafun",
"plain"
}
@@ -532,7 +565,7 @@ local function analyze(filename)
if f then
local t = { }
local line = f:read("*line") or ""
- local preamble = line:match("^%% *(.*)$")
+ local preamble = line:match("[\254\255]*%%%s+(.+)$") -- there can be an utf bomb in front
if preamble then
for key, value in preamble:gmatch("(%S+)=(%S+)") do
t[key] = value
@@ -541,42 +574,53 @@ local function analyze(filename)
elseif line:find("^ 0 then
- input.identify_cnf()
- input.load_cnf()
- input.expand_variables()
+ --
local interface = environment.argument("interface")
-- todo: environment.argument("interface","en")
interface = (type(interface) == "string" and interface) or "en"
--
local formatname = scripts.context.interfaces[interface] or "cont-en"
- local formatfile, scriptfile = input.locate_format(formatname)
+ local formatfile, scriptfile = resolvers.locate_format(formatname)
+ -- this catches the command line
+ if not formatfile or not scriptfile then
+ logs.simple("warning: no format found, forcing remake (commandline driven)")
+ scripts.context.generate()
+ scripts.context.make(formatname)
+ formatfile, scriptfile = resolvers.locate_format(formatname)
+ end
+ --
if formatfile and scriptfile then
for _, filename in ipairs(files) do
local basename, pathname = file.basename(filename), file.dirname(filename)
@@ -584,137 +628,275 @@ function scripts.context.run(ctxdata)
if pathname == "" then
filename = "./" .. filename
end
+ -- look at the first line
local a = analyze(filename)
- if a then
- if a.interface and a.interface ~= interface then
+ if a and (a.engine == 'pdftex' or a.engine == 'xetex' or environment.argument("pdftex") or environment.argument("xetex")) then
+ local texexec = resolvers.find_file("texexec.rb") or ""
+ if texexec ~= "" then
+ local command = string.format("ruby %s %s",texexec,environment.reconstruct_commandline(environment.arguments_after))
+ os.exec(command)
+ end
+ else
+ if a and a.interface and a.interface ~= interface then
formatname = scripts.context.interfaces[a.interface] or formatname
- formatfile, scriptfile = input.locate_format(formatname)
+ formatfile, scriptfile = resolvers.locate_format(formatname)
end
- end
- -- we default to mkiv xml !
- if scripts.context.xmlsuffixes[file.extname(filename) or "?"] or environment.argument("forcexml") then
- if environment.argument("mkii") then
- filename = makestub("\\processXMLfilegrouped{%s}",filename)
- else
- filename = makestub("\\xmlprocess{\\xmldocument}{%s}{}",filename)
+ -- this catches the command line
+ if not formatfile or not scriptfile then
+ logs.simple("warning: no format found, forcing remake (source driven)")
+ scripts.context.generate()
+ scripts.context.make(formatname)
+ formatfile, scriptfile = resolvers.locate_format(formatname)
end
- end
- --
- -- todo: also other stubs
- --
- local resultname, oldbase, newbase = environment.argument("result"), "", ""
- if type(resultname) == "string" then
- oldbase = file.removesuffix(jobname)
- newbase = file.removesuffix(resultname)
- if oldbase ~= newbase then
- for _, suffix in pairs(scripts.context.beforesuffixes) do
- local oldname = file.addsuffix(oldbase,suffix)
- local newname = file.addsuffix(newbase,suffix)
- local tmpname = "keep-"..oldname
- os.remove(tmpname)
- os.rename(oldname,tmpname)
- os.remove(oldname)
- os.rename(newname,oldname)
+ if formatfile and scriptfile then
+ -- we default to mkiv xml !
+ local suffix = file.extname(filename) or "?"
+ if scripts.context.xmlsuffixes[suffix] or environment.argument("forcexml") then
+ if environment.argument("mkii") then
+ filename = makestub("\\processXMLfilegrouped{%s}",filename)
+ else
+ filename = makestub("\\xmlprocess{\\xmldocument}{%s}{}",filename)
+ end
+ elseif scripts.context.luasuffixes[suffix] then
+ filename = makestub("\\ctxlua{dofile('%s')}",filename)
end
- else
- resultname = nil
- end
- else
- resultname = nil
- end
- --
- if environment.argument("autopdf") then
- os.spawn(string.format('pdfclose --file "%s" 2>&1', file.replacesuffix(filename,"pdf")))
- if resultname then
- os.spawn(string.format('pdfclose --file "%s" 2>&1', file.replacesuffix(resultname,"pdf")))
- end
- end
- --
- local flags = { }
- if environment.argument("batchmode") then
- flags[#flags+1] = "--interaction=batchmode"
- end
- flags[#flags+1] = "--fmt=" .. string.quote(formatfile)
- flags[#flags+1] = "--lua=" .. string.quote(scriptfile)
- local command = string.format("luatex %s %s", table.concat(flags," "), string.quote(filename))
- local oldhash, newhash = scripts.context.multipass.hashfiles(jobname), { }
- local once = environment.argument("once")
- local maxnofruns = (once and 1) or scripts.context.multipass.nofruns
- for i=1,maxnofruns do
- -- 1:first run, 2:successive run, 3:once, 4:last of maxruns
- local kindofrun = (once and 3) or (i==1 and 1) or (i==maxnofruns and 4) or 2
- scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,false) -- kindofrun, currentrun, final
- input.report("run %s: %s",i,command)
- local returncode, errorstring = os.spawn(command)
- if not returncode then
- input.report("fatal error, message: %s",errorstring or "?")
- os.exit(1)
- break
- elseif returncode > 0 then
- input.report("fatal error, code: %s",returncode or "?")
- os.exit(returncode)
- break
- else
- scripts.context.multipass.copyluafile(jobname)
- scripts.context.multipass.copytuifile(jobname)
- newhash = scripts.context.multipass.hashfiles(jobname)
- if scripts.context.multipass.changed(oldhash,newhash) then
- oldhash = newhash
+ --
+ -- todo: also other stubs
+ --
+ local resultname, oldbase, newbase = environment.argument("result"), "", ""
+ if type(resultname) == "string" then
+ oldbase = file.removesuffix(jobname)
+ newbase = file.removesuffix(resultname)
+ if oldbase ~= newbase then
+ for _, suffix in pairs(scripts.context.beforesuffixes) do
+ local oldname = file.addsuffix(oldbase,suffix)
+ local newname = file.addsuffix(newbase,suffix)
+ local tmpname = "keep-"..oldname
+ os.remove(tmpname)
+ os.rename(oldname,tmpname)
+ os.remove(oldname)
+ os.rename(newname,oldname)
+ end
+ else
+ resultname = nil
+ end
else
- break
+ resultname = nil
+ end
+ --
+ if environment.argument("autopdf") then
+ os.spawn(string.format('pdfclose --file "%s" 2>&1', file.replacesuffix(filename,"pdf")))
+ if resultname then
+ os.spawn(string.format('pdfclose --file "%s" 2>&1', file.replacesuffix(resultname,"pdf")))
+ end
+ end
+ --
+ local okay = statistics.check_fmt_status(formatfile)
+ if okay ~= true then
+ logs.simple("warning: %s, forcing remake",tostring(okay))
+ scripts.context.generate()
+ scripts.context.make(formatname)
+ end
+ --
+ local flags = { }
+ if environment.argument("batchmode") then
+ flags[#flags+1] = "--interaction=batchmode"
+ end
+ flags[#flags+1] = "--fmt=" .. string.quote(formatfile)
+ flags[#flags+1] = "--lua=" .. string.quote(scriptfile)
+ flags[#flags+1] = "--backend=pdf"
+ local command = string.format("luatex %s %s", table.concat(flags," "), string.quote(filename))
+ local oldhash, newhash = scripts.context.multipass.hashfiles(jobname), { }
+ local once = environment.argument("once")
+ local maxnofruns = (once and 1) or scripts.context.multipass.nofruns
+ local arrange = environment.argument("arrange")
+ for i=1,maxnofruns do
+ -- 1:first run, 2:successive run, 3:once, 4:last of maxruns
+ local kindofrun = (once and 3) or (i==1 and 1) or (i==maxnofruns and 4) or 2
+ scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,false) -- kindofrun, currentrun, final
+ logs.simple("run %s: %s",i,command)
+ local returncode, errorstring = os.spawn(command)
+ --~ if returncode == 3 then
+ --~ scripts.context.generate()
+ --~ scripts.context.make(formatname)
+ --~ returncode, errorstring = os.spawn(command)
+ --~ if returncode == 3 then
+ --~ logs.simple("fatal error, return code 3, message: %s",errorstring or "?")
+ --~ os.exit(1)
+ --~ end
+ --~ end
+ if not returncode then
+ logs.simple("fatal error, no return code, message: %s",errorstring or "?")
+ os.exit(1)
+ break
+ elseif returncode > 0 then
+ logs.simple("fatal error, return code: %s",returncode or "?")
+ os.exit(returncode)
+ break
+ else
+ scripts.context.multipass.copyluafile(jobname)
+ -- scripts.context.multipass.copytuifile(jobname)
+ newhash = scripts.context.multipass.hashfiles(jobname)
+ if scripts.context.multipass.changed(oldhash,newhash) then
+ oldhash = newhash
+ else
+ break
+ end
+ end
+ end
+ --
+ if arrange then
+ local kindofrun = 3
+ scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,true) -- kindofrun, currentrun, final
+ logs.simple("arrange run: %s",command)
+ local returncode, errorstring = os.spawn(command)
+ if not returncode then
+ logs.simple("fatal error, no return code, message: %s",errorstring or "?")
+ os.exit(1)
+ elseif returncode > 0 then
+ logs.simple("fatal error, return code: %s",returncode or "?")
+ os.exit(returncode)
+ end
+ end
+ --
+ if environment.argument("purge") then
+ scripts.context.purge_job(filename)
+ elseif environment.argument("purgeall") then
+ scripts.context.purge_job(filename,true)
+ end
+ --
+ os.remove(jobname..".top")
+ --
+ if resultname then
+ for _, suffix in pairs(scripts.context.aftersuffixes) do
+ local oldname = file.addsuffix(oldbase,suffix)
+ local newname = file.addsuffix(newbase,suffix)
+ local tmpname = "keep-"..oldname
+ os.remove(newname)
+ os.rename(oldname,newname)
+ os.rename(tmpname,oldname)
+ end
+ logs.simple("result renamed to: %s",newbase)
+ end
+ --
+ if environment.argument("purge") then
+ scripts.context.purge_job(resultname)
+ elseif environment.argument("purgeall") then
+ scripts.context.purge_job(resultname,true)
+ end
+ --
+ if environment.argument("autopdf") then
+ if resultname then
+ os.spawn(string.format('pdfopen --file "%s" 2>&1', file.replacesuffix(resultname,"pdf")))
+ else
+ os.spawn(string.format('pdfopen --file "%s" 2>&1', file.replacesuffix(filename,"pdf")))
+ end
+ end
+ --
+ if environment.argument("timing") then
+ logs.line()
+ logs.simple("you can process (timing) statistics with:",jobname)
+ logs.line()
+ logs.simple("context --extra=timing '%s'",jobname)
+ logs.simple("mtxrun --script timing --xhtml [--launch --remove] '%s'",jobname)
+ logs.line()
end
- end
- end
- --
- -- todo: extra arrange run
- --
- if environment.argument("purge") then
- scripts.context.purge_job(filename)
- elseif environment.argument("purgeall") then
- scripts.context.purge_job(filename,true)
- end
- --
- if resultname then
- for _, suffix in pairs(scripts.context.aftersuffixes) do
- local oldname = file.addsuffix(oldbase,suffix)
- local newname = file.addsuffix(newbase,suffix)
- local tmpname = "keep-"..oldname
- os.remove(newname)
- os.rename(oldname,newname)
- os.rename(tmpname,oldname)
- end
- input.report("result renamed to: %s",newbase)
- end
- if environment.argument("autopdf") then
- if resultname then
- os.spawn(string.format('pdfopen --file "%s" 2>&1', file.replacesuffix(resultname,"pdf")))
else
- os.spawn(string.format('pdfopen --file "%s" 2>&1', file.replacesuffix(filename,"pdf")))
+ if formatname then
+ logs.simple("error, no format found with name: %s, skipping",formatname)
+ else
+ logs.simple("error, no format found (provide formatname or interface)")
+ end
+ break
end
end
- --
end
else
- input.verbose = true
- input.report("error, no format found with name: %s",formatname)
+ if formatname then
+ logs.simple("error, no format found with name: %s, aborting",formatname)
+ else
+ logs.simple("error, no format found (provide formatname or interface)")
+ end
end
end
end
-function scripts.context.make()
- local list = (environment.files[1] and environment.files) or scripts.context.defaultformats
+function scripts.context.pipe()
+ -- context --pipe
+ -- context --pipe --purge --dummyfile=whatever.tmp
+ local interface = environment.argument("interface")
+ interface = (type(interface) == "string" and interface) or "en"
+ local formatname = scripts.context.interfaces[interface] or "cont-en"
+ local formatfile, scriptfile = resolvers.locate_format(formatname)
+ if not formatfile or not scriptfile then
+ logs.simple("warning: no format found, forcing remake (commandline driven)")
+ scripts.context.generate()
+ scripts.context.make(formatname)
+ formatfile, scriptfile = resolvers.locate_format(formatname)
+ end
+ if formatfile and scriptfile then
+ local okay = statistics.check_fmt_status(formatfile)
+ if okay ~= true then
+ logs.simple("warning: %s, forcing remake",tostring(okay))
+ scripts.context.generate()
+ scripts.context.make(formatname)
+ end
+ local flags = {
+ "--interaction=scrollmode",
+ "--fmt=" .. string.quote(formatfile),
+ "--lua=" .. string.quote(scriptfile),
+ "--backend=pdf",
+ }
+ local filename = environment.argument("dummyfile") or ""
+ if filename == "" then
+ filename = "\\relax"
+ logs.simple("entering scrollmode, end job with \\end")
+ else
+ filename = file.addsuffix(filename,"tmp")
+ io.savedata(filename,"\\relax")
+ scripts.context.multipass.makeoptionfile(filename,{ flags = flags },3,1,false) -- kindofrun, currentrun, final
+ logs.simple("entering scrollmode using '%s' with optionfile, end job with \\end",filename)
+ end
+ local command = string.format("luatex %s %s", table.concat(flags," "), string.quote(filename))
+ os.spawn(command)
+ if environment.argument("purge") then
+ scripts.context.purge_job(filename)
+ elseif environment.argument("purgeall") then
+ scripts.context.purge_job(filename,true)
+ os.remove(filename)
+ end
+ else
+ if formatname then
+ logs.simple("error, no format found with name: %s, aborting",formatname)
+ else
+ logs.simple("error, no format found (provide formatname or interface)")
+ end
+ end
+end
+
+function scripts.context.make(name)
+ local runners = {
+ "luatools --make --compile ",
+ (environment.argument("pdftex") and "mtxrun texexec.rb --make --pdftex ") or false,
+ (environment.argument("xetex") and "mtxrun texexec.rb --make --xetex " ) or false,
+ }
+ local list = (name and { name }) or (environment.files[1] and environment.files) or scripts.context.defaultformats
for _, name in ipairs(list) do
name = scripts.context.interfaces[name] or name
- local command = "luatools --make --compile " .. name
- input.report("running command: %s",command)
- os.spawn(command)
+ for _, runner in ipairs(runners) do
+ if runner then
+ local command = runner .. name
+ logs.simple("running command: %s",command)
+ os.spawn(command)
+ end
+ end
end
end
function scripts.context.generate()
-- hack, should also be a shared function
local command = "luatools --generate "
- input.report("running command: %s",command)
+ logs.simple("running command: %s",command)
os.spawn(command)
end
@@ -725,23 +907,81 @@ function scripts.context.ctx()
scripts.context.run(ctxdata)
end
+function scripts.context.autoctx()
+ local ctxdata = nil
+ local files = (filename and { filename }) or environment.files
+ local firstfile = #files > 0 and files[1]
+ if firstfile and file.extname(firstfile) == "xml" then
+ local f = io.open(firstfile)
+ if f then
+ local chunk = f:read(512) or ""
+ f:close()
+ local ctxname = string.match(chunk,"<%?context%-directive%s+job%s+ctxfile%s+([^ ]-)%s*?>")
+ if ctxname then
+ ctxdata = ctxrunner.new()
+ ctxdata.jobname = firstfile
+ ctxrunner.manipulate(ctxdata,ctxname)
+ end
+ end
+ end
+ scripts.context.run(ctxdata)
+end
+
+-- todo: quite after first image
+
+local template = [[
+ \starttext
+ \startMPpage %% %s
+ input "%s" ;
+ \stopMPpage
+ \stoptext
+]]
+
+local loaded = false
+
+function scripts.context.metapost()
+ local filename = environment.files[1] or ""
+--~ local tempname = "mtx-context-metapost.tex"
+--~ local tempdata = string.format(template,"metafun",filename)
+--~ io.savedata(tempname,tempdata)
+--~ environment.files[1] = tempname
+--~ environment.setargument("result",file.removesuffix(filename))
+--~ environment.setargument("once",true)
+--~ scripts.context.run()
+ if not loaded then
+ dofile(resolvers.find_file("mlib-run.lua"))
+ loaded = true
+ commands = commands or { }
+ commands.writestatus = logs.report
+ end
+ local formatname = environment.arguments("format") or "metafun"
+ if formatname == "" or type(format) == "boolean" then
+ formatname = "metafun"
+ end
+ if environment.arguments("svg") then
+ metapost.directrun(formatname,filename,"svg")
+ else
+ metapost.directrun(formatname,filename,"mps")
+ end
+end
+
function scripts.context.version()
- local name = input.find_file("context.tex")
+ local name = resolvers.find_file("context.tex")
if name ~= "" then
- input.report("main context file: %s",name)
+ logs.simple("main context file: %s",name)
local data = io.loaddata(name)
if data then
local version = data:match("\\edef\\contextversion{(.-)}")
if version then
- input.report("current version: %s",version)
+ logs.simple("current version: %s",version)
else
- input.report("context version: unknown, no timestamp found")
+ logs.simple("context version: unknown, no timestamp found")
end
else
- input.report("context version: unknown, load error")
+ logs.simple("context version: unknown, load error")
end
else
- input.report("main context file: unknown, 'context.tex' not found")
+ logs.simple("main context file: unknown, 'context.tex' not found")
end
end
@@ -780,6 +1020,7 @@ local function purge_file(dfile,cfile)
end
function scripts.context.purge_job(jobname,all)
+ jobname = file.basename(jobname)
local filebase = file.removesuffix(jobname)
local deleted = { }
for _, suffix in ipairs(obsolete_results) do
@@ -794,7 +1035,7 @@ function scripts.context.purge_job(jobname,all)
end
end
if #deleted > 0 then
- input.report("purged files: %s", table.join(deleted,", "))
+ logs.simple("purged files: %s", table.join(deleted,", "))
end
end
@@ -815,56 +1056,260 @@ function scripts.context.purge(all)
end
end
if #deleted > 0 then
- input.report("purged files: %s", table.join(deleted,", "))
+ logs.simple("purged files: %s", table.join(deleted,", "))
end
end
--~ purge_for_files("test",true)
--~ purge_all_files()
+local function touch(name,pattern)
+ local name = resolvers.find_file(name)
+ local olddata = io.loaddata(name)
+ if olddata then
+ local oldversion, newversion = "", os.date("%Y.%m.%d %H:%M")
+ local newdata, ok = olddata:gsub(pattern,function(pre,mid,post)
+ oldversion = mid
+ return pre .. newversion .. post
+ end)
+ if ok > 0 then
+ local backup = file.replacesuffix(name,"tmp")
+ os.remove(backup)
+ os.rename(name,backup)
+ io.savedata(name,newdata)
+ return true, oldversion, newversion, name
+ else
+ return false
+ end
+ end
+end
+
function scripts.context.touch()
if environment.argument("expert") then
- local function touch(name,pattern)
- local name = input.find_file(name)
- local olddata = io.loaddata(name)
- if olddata then
- local oldversion, newversion = "", os.date("%Y.%M.%d %H:%m")
- local newdata, ok = olddata:gsub(pattern,function(pre,mid,post)
- oldversion = mid
- return pre .. newversion .. post
- end)
- if ok > 0 then
- local backup = file.replacesuffix(name,"tmp")
- os.remove(backup)
- os.rename(name,backup)
- io.savedata(name,newdata)
- return true, oldversion, newversion, name
- else
- return false
- end
- end
- end
local done, oldversion, newversion, foundname = touch("context.tex", "(\\edef\\contextversion{)(.-)(})")
if done then
- input.report("old version : %s", oldversion)
- input.report("new version : %s", newversion)
- input.report("touched file: %s", foundname)
+ logs.simple("old version : %s", oldversion)
+ logs.simple("new version : %s", newversion)
+ logs.simple("touched file: %s", foundname)
local ok, _, _, foundname = touch("cont-new.tex", "(\\newcontextversion{)(.-)(})")
if ok then
- input.report("touched file: %s", foundname)
+ logs.simple("touched file: %s", foundname)
+ end
+ local ok, _, _, foundname = touch("cont-xp.tex", "(\\edef\\contextversion{)(.-)(})")
+ if ok then
+ logs.simple("touched file: %s", foundname)
+ end
+ end
+ end
+end
+
+-- extras
+
+function scripts.context.extras(pattern)
+ local found = resolvers.find_file("context.tex")
+ if found == "" then
+ logs.simple("unknown extra: %s", extra)
+ else
+ pattern = file.join(dir.expand_name(file.dirname(found)),string.format("mtx-context-%s.tex",pattern or "*"))
+ local list = dir.glob(pattern)
+ if not extra or extra == "" then
+ logs.extendbanner("extras")
+ else
+ logs.extendbanner(extra)
+ end
+ for k,v in ipairs(list) do
+ local data = io.loaddata(v) or ""
+ data = string.match(data,"begin help(.-)end help")
+ if data then
+ local h = { string.format("extra: %s (%s)",string.gsub(v,"^.*mtx%-context%-(.-)%.tex$","%1"),v) }
+ for s in string.gmatch(data,"%% *(.-)[\n\r]") do
+ h[#h+1] = s
+ end
+ logs.help(table.concat(h,"\n"),"nomoreinfo")
+ end
+ end
+ end
+end
+
+function scripts.context.extra()
+ local extra = environment.argument("extra")
+ if type(extra) == "string" then
+ if environment.argument("help") then
+ scripts.context.extras(extra)
+ else
+ local fullextra = extra
+ if not string.find(fullextra,"mtx%-context%-") then
+ fullextra = "mtx-context-" .. extra
+ end
+ local foundextra = resolvers.find_file(fullextra)
+ if foundextra == "" then
+ scripts.context.extras()
+ return
+ else
+ logs.simple("processing extra: %s", foundextra)
end
+ environment.setargument("purgeall",true)
+ local result = environment.setargument("result") or ""
+ if result == "" then
+ environment.setargument("result","context-extra")
+ end
+ scripts.context.run(nil,foundextra)
end
+ else
+ scripts.context.extras()
end
end
+-- todo: we need to do a dummy run
+
+function scripts.context.track()
+ environment.files = { "m-track" }
+ scripts.context.multipass.nofruns = 1
+ scripts.context.run()
+ -- maybe filter from log
+end
+
function scripts.context.timed(action)
- input.starttiming(scripts.context)
- action()
- input.stoptiming(scripts.context)
- input.report("total runtime: %s",input.elapsedtime(scripts.context))
+ statistics.timed(action)
end
-banner = banner .. " | context tools "
+local zipname = "cont-tmf.zip"
+local mainzip = "http://www.pragma-ade.com/context/latest/" .. zipname
+local validtrees = { "texmf-local", "texmf-context" }
+
+function zip.loaddata(zipfile,filename) -- should be in zip lib
+ local f = zipfile:open(filename)
+ if f then
+ local data = f:read("*a")
+ f:close()
+ return data
+ end
+ return nil
+end
+
+function scripts.context.update()
+ local force = environment.argument("force")
+ local socket = require("socket")
+ local http = require("socket.http")
+ local basepath = resolvers.find_file("context.tex") or ""
+ if basepath == "" then
+ logs.simple("quiting, no 'context.tex' found")
+ return
+ end
+ local basetree = basepath.match(basepath,"^(.-)tex/context/base/context.tex$") or ""
+ if basetree == "" then
+ logs.simple("quiting, no proper tds structure (%s)",basepath)
+ return
+ end
+ local function is_okay(basetree)
+ for _, tree in next, validtrees do
+ local pattern = string.gsub(tree,"%-","%%-")
+ if basetree:find(pattern) then
+ return tree
+ end
+ end
+ return false
+ end
+ local okay = is_okay(basetree)
+ if not okay then
+ logs.simple("quiting, tree '%s' is protected",okay)
+ return
+ else
+ logs.simple("updating tree '%s'",okay)
+ end
+ if not lfs.chdir(basetree) then
+ logs.simple("quiting, unable to change to '%s'",okay)
+ return
+ end
+ logs.simple("fetching '%s'",mainzip)
+ local latest = http.request(mainzip)
+ if not latest then
+ logs.simple("context tree '%s' can be updated, use --force",okay)
+ return
+ end
+ io.savedata("cont-tmf.zip",latest)
+ if false then
+ -- variant 1
+ os.execute("mtxrun --script unzip cont-tmf.zip")
+ else
+ -- variant 2
+ local zipfile = zip.open(zipname)
+ if not zipfile then
+ logs.simple("quiting, unable to open '%s'",zipname)
+ return
+ end
+ local newfile = zip.loaddata(zipfile,"tex/context/base/context.tex")
+ if not newfile then
+ logs.simple("quiting, unable to open '%s'","context.tex")
+ return
+ end
+ local oldfile = io.loaddata(resolvers.find_file("context.tex")) or ""
+ local function versiontonumber(what,str)
+ local version = str:match("\\edef\\contextversion{(.-)}") or ""
+ local year, month, day, hour, minute = str:match("\\edef\\contextversion{(%d+)%.(%d+)%.(%d+) *(%d+)%:(%d+)}")
+ if year and minute then
+ local time = os.time { year=year,month=month,day=day,hour=hour,minute=minute}
+ logs.simple("%s version: %s (%s)",what,version,time)
+ return time
+ else
+ logs.simple("%s version: %s (unknown)",what,version)
+ return nil
+ end
+ end
+ local oldversion = versiontonumber("old",oldfile)
+ local newversion = versiontonumber("new",newfile)
+ if not oldversion or not newversion then
+ logs.simple("quiting, version cannot be determined")
+ return
+ elseif oldversion == newversion then
+ logs.simple("quiting, your current version is up-to-date")
+ return
+ elseif oldversion > newversion then
+ logs.simple("quiting, your current version is newer")
+ return
+ end
+ for k in zipfile:files() do
+ local filename = k.filename
+ if filename:find("/$") then
+ lfs.mkdir(filename)
+ else
+ local data = zip.loaddata(zipfile,filename)
+ if data then
+ if force then
+ io.savedata(filename,data)
+ end
+ logs.simple(filename)
+ end
+ end
+ end
+ for _, scriptname in next, { "luatools.lua", "mtxrun.lua" } do
+ local oldscript = resolvers.find_file(scriptname) or ""
+ if oldscript ~= "" and is_okay(oldscript) then
+ local newscript = "./scripts/context/lua/" .. scriptname
+ local data = io.loaddata(newscript) or ""
+ if data ~= "" then
+ logs.simple("replacing script '%s' by '%s'",oldscript,newscript)
+ if force then
+ io.savedata(oldscript,data)
+ end
+ end
+ else
+ logs.simple("keeping script '%s'",oldscript)
+ end
+ end
+ if force then
+ os.execute("context --generate")
+ os.execute("context --make")
+ end
+ end
+ if force then
+ logs.simple("context tree '%s' has been updated",okay)
+ else
+ logs.simple("context tree '%s' can been updated (use --force)",okay)
+ end
+end
+
+logs.extendbanner("ConTeXt Tools 0.51",true)
messages.help = [[
--run process (one or more) files (default action)
@@ -877,41 +1322,82 @@ messages.help = [[
--once only one run
--purge(all) purge files (--pattern=...)
--result=name rename result to given name
+--arrange run extra arrange pass
--expert expert options
--interface use specified user interface
]]
messages.expert = [[
-expert options: also provide --expert
+expert options:
+
+--touch update context version number (remake needed afterwards, also provide --expert)
+--update update context from website (not to be confused with contextgarden)
+--profile profile job (use: mtxrun --script profile --analyse)
+--track show/set tracker variables
+--timing generate timing and statistics overview
+--extra=name process extra (mtx-context- in distribution)
+]]
+
+messages.private = [[
+private options:
---touch update context version (remake needed afterwards)
+--dumphash dump hash table afterwards
+--dumpdelta dump hash table afterwards (only new entries)
]]
-input.verbose = true
+messages.special = [[
+special options:
+
+--pdftex process file with texexec using pdftex
+--xetex process file with texexec using xetex
+
+--pipe don't check for file and enter scroll mode (--dummyfile=whatever.tmp)
+]]
if environment.argument("once") then
scripts.context.multipass.nofruns = 1
end
+if environment.argument("profile") then
+ os.setenv("MTX_PROFILE_RUN","YES")
+end
+
if environment.argument("run") then
- scripts.context.timed(scripts.context.run)
-elseif environment.argument("make") then
- scripts.context.timed(scripts.context.make)
-elseif environment.argument("generate") then
- scripts.context.timed(scripts.context.generate)
+-- scripts.context.timed(scripts.context.run)
+ scripts.context.timed(scripts.context.autoctx)
+elseif environment.argument("make") or environment.argument("generate") then
+ scripts.context.timed(function()
+ if environment.argument("generate") then
+ scripts.context.generate()
+ end
+ if environment.argument("make") then
+ scripts.context.make()
+ end
+ end)
elseif environment.argument("ctx") then
scripts.context.timed(scripts.context.ctx)
+elseif environment.argument("mp") or environment.argument("metapost") then
+ scripts.context.timed(scripts.context.metapost)
elseif environment.argument("version") then
scripts.context.version()
elseif environment.argument("touch") then
scripts.context.touch()
+elseif environment.argument("update") then
+ scripts.context.update()
elseif environment.argument("expert") then
- input.help(banner,messages.expert)
+ logs.help(table.join({ messages.expert, messages.private, messages.special },"\n"))
+elseif environment.argument("extra") then
+ scripts.context.extra()
elseif environment.argument("help") then
- input.help(banner,messages.help)
+ logs.help(messages.help)
+elseif environment.argument("track") and type(environment.argument("track")) == "boolean" then
+ scripts.context.track()
elseif environment.files[1] then
- scripts.context.timed(scripts.context.run)
+-- scripts.context.timed(scripts.context.run)
+ scripts.context.timed(scripts.context.autoctx)
+elseif environment.argument("pipe") then
+ scripts.context.timed(scripts.context.pipe)
elseif environment.argument("purge") then
-- only when no filename given, supports --pattern
scripts.context.purge()
@@ -919,6 +1405,9 @@ elseif environment.argument("purgeall") then
-- only when no filename given, supports --pattern
scripts.context.purge(true)
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
+if environment.argument("profile") then
+ os.setenv("MTX_PROFILE_RUN","NO")
+end
diff --git a/scripts/context/lua/mtx-convert.lua b/scripts/context/lua/mtx-convert.lua
index eca050f29..cf1d640c5 100644
--- a/scripts/context/lua/mtx-convert.lua
+++ b/scripts/context/lua/mtx-convert.lua
@@ -51,7 +51,7 @@ do
dir.mkdirs(outputpath)
local tmpname = file.replacesuffix(newname,"tmp")
local command = graphics.converters[suffix](oldname,tmpname)
- input.report("command: %s",command)
+ logs.simple("command: %s",command)
io.flush()
os.spawn(command)
os.remove(newname)
@@ -88,7 +88,7 @@ function scripts.convert.convertall()
end
end
-banner = banner .. " | graphic conversion tools "
+logs.extendbanner("Graphic Conversion Tools 0.10",true)
messages.help = [[
--convertall convert all graphics on path
@@ -98,10 +98,8 @@ messages.help = [[
--delay time between sweeps
]]
-input.verbose = true
-
if environment.argument("convertall") then
scripts.convert.convertall()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua
index ef9e37258..befba924e 100644
--- a/scripts/context/lua/mtx-fonts.lua
+++ b/scripts/context/lua/mtx-fonts.lua
@@ -6,7 +6,11 @@ if not modules then modules = { } end modules ['mtx-fonts'] = {
license = "see context related readme files"
}
-dofile(input.find_file("font-syn.lua"))
+if not fontloader then fontloader = fontforge end
+
+dofile(resolvers.find_file("font-otp.lua","tex"))
+dofile(resolvers.find_file("font-syn.lua","tex"))
+dofile(resolvers.find_file("font-mis.lua","tex"))
scripts = scripts or { }
scripts.fonts = scripts.fonts or { }
@@ -15,57 +19,55 @@ function scripts.fonts.reload(verbose)
fonts.names.load(true,verbose)
end
+function scripts.fonts.names(name)
+ name = name or "luatex-fonts-names.lua"
+ fonts.names.identify(true)
+ local data = fonts.names.data
+ if data then
+ data.fallback_mapping = nil
+ logs.report("fontnames","saving names in '%s'",name)
+ io.savedata(name,table.serialize(data,true))
+ elseif lfs.isfile(name) then
+ os.remove(name)
+ end
+end
+
local function showfeatures(v,n,f,s,t)
- local iv = input.verbose
- input.verbose = true
- input.report("fontname: %s",v)
- input.report("fullname: %s",n)
- input.report("filename: %s",f)
- if t == "otf" or t == "ttf" then
- local filename = input.find_file(f,t) or ""
- if filename ~= "" then
- local ff = fontforge.open(filename)
- if ff then
- local data = fontforge.to_table(ff)
- fontforge.close(ff)
- local features = { }
- local function collect(what)
- if data[what] then
- for _, d in ipairs(data[what]) do
- if d.features then
- for _, df in ipairs(d.features) do
- features[df.tag] = features[df.tag] or { }
- for _, ds in ipairs(df.scripts) do
- features[df.tag][ds.script] = features[df.tag][ds.script] or { }
- for _, lang in ipairs(ds.langs) do
- features[df.tag][ds.script][lang] = true
- end
- end
- end
- end
+ logs.simple("fontname: %s",v)
+ logs.simple("fullname: %s",n)
+ logs.simple("filename: %s",f)
+ local features = fonts.get_features(f,t)
+ if features then
+ for what, v in table.sortedpairs(features) do
+ local data = features[what]
+ if data and next(data) then
+ logs.simple()
+ logs.simple("%s features:",what)
+ logs.simple()
+ logs.simple("feature script languages")
+ logs.simple()
+ for f,ff in table.sortedpairs(data) do
+ local done = false
+ for s, ss in table.sortedpairs(ff) do
+ if s == "*" then s = "all" end
+ if ss ["*"] then ss["*"] = nil ss.all = true end
+ if done then
+ f = ""
+ else
+ done = true
end
- end
- end
- collect('gsub')
- collect('gpos')
- input.report("")
- for _, f in ipairs(table.sortedkeys(features)) do
- local ff = features[f]
- for _, s in ipairs(table.sortedkeys(ff)) do
- local ss = ff[s]
- input.report("feature: %s, script: %s, language: %s",f:lower(),s:lower(),(table.concat(table.sortedkeys(ss), " ")):lower())
+ logs.simple("% -8s % -8s % -8s",f,s,table.concat(table.sortedkeys(ss), " "))
end
end
end
end
end
- input.report("")
- input.verbose = iv
+ logs.reportline()
end
function scripts.fonts.list(pattern,reload,all,info)
if reload then
- input.report("fontnames, reloading font database")
+ logs.simple("fontnames, reloading font database")
end
-- make a function for this
pattern = pattern:lower()
@@ -81,7 +83,7 @@ function scripts.fonts.list(pattern,reload,all,info)
--
local t = fonts.names.list(pattern,reload)
if reload then
- input.report("fontnames, done\n\n")
+ logs.simple("fontnames, done\n\n")
end
if t then
local s, w = table.sortedkeys(t), { 0, 0, 0 }
@@ -112,51 +114,52 @@ function scripts.fonts.save(name,sub)
local function save(savename,fontblob)
if fontblob then
savename = savename:lower() .. ".lua"
- input.report("fontsave, saving data in %s",savename)
- table.tofile(savename,fontforge.to_table(fontblob),"return")
- fontforge.close(fontblob)
+ logs.simple("fontsave, saving data in %s",savename)
+ table.tofile(savename,fontloader.to_table(fontblob),"return")
+ fontloader.close(fontblob)
end
end
if name and name ~= "" then
- local filename = input.find_file(name) -- maybe also search for opentype
+ local filename = resolvers.find_file(name) -- maybe also search for opentype
if filename and filename ~= "" then
local suffix = file.extname(filename)
if suffix == 'ttf' or suffix == 'otf' or suffix == 'ttc' then
- local fontinfo = fontforge.info(filename)
+ local fontinfo = fontloader.info(filename)
if fontinfo then
+ logs.simple("font: %s located as %s",name,filename)
if fontinfo[1] then
for _, v in ipairs(fontinfo) do
- save(v.fontname,fontforge.open(filename,v.fullname))
+ save(v.fontname,fontloader.open(filename,v.fullname))
end
else
- save(fontinfo.fullname,fontforge.open(filename))
+ save(fontinfo.fullname,fontloader.open(filename))
end
end
else
- input.verbose = true
- input.report("font: %s not saved",filename)
+ logs.simple("font: %s not saved",filename)
end
else
- input.verbose = true
- input.report("font: %s not found",name)
+ logs.simple("font: %s not found",name)
end
end
end
-banner = banner .. " | font tools "
+logs.extendbanner("Font Tools 0.20",true)
messages.help = [[
--reload generate new font database
--list [--info] list installed fonts (show info)
--save save open type font in raw table
+--names generate 'luatex-fonts-names.lua' (not for context!)
--pattern=str filter files
--all provide alternatives
]]
if environment.argument("reload") then
- local verbose = environment.argument("verbose")
- scripts.fonts.reload(verbose)
+ scripts.fonts.reload(true)
+elseif environment.argument("names") then
+ scripts.fonts.names()
elseif environment.argument("list") then
local pattern = environment.argument("pattern") or environment.files[1] or ""
local all = environment.argument("all")
@@ -168,5 +171,5 @@ elseif environment.argument("save") then
local sub = environment.files[2] or ""
scripts.fonts.save(name,sub)
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-grep.lua b/scripts/context/lua/mtx-grep.lua
index 18e36d2ea..82a80314a 100644
--- a/scripts/context/lua/mtx-grep.lua
+++ b/scripts/context/lua/mtx-grep.lua
@@ -9,54 +9,85 @@ if not modules then modules = { } end modules ['mtx-babel'] = {
scripts = scripts or { }
scripts.grep = scripts.grep or { }
-banner = banner .. " | simple grepper "
+logs.extendbanner("Simple Grepper 0.10",true)
+
+local find, format = string.find, string.format
+
+local cr = lpeg.P("\r")
+local lf = lpeg.P("\n")
+local crlf = cr * lf
+local newline = crlf + cr + lf
+local content = lpeg.C((1-newline)^0) * newline
+
+local write_nl = texio.write_nl
function scripts.grep.find(pattern, files, offset)
if pattern and pattern ~= "" then
- local format = string.format
- input.starttiming(scripts.grep)
- local count, nofmatches, noffiles, nofmatchedfiles = environment.argument("count"), 0, 0, 0
- local function grep(name)
- local data = io.loaddata(name)
- if data then
- noffiles = noffiles + 1
- local n, m = 0, 0
- for line in data:gmatch("[^\n]+") do -- faster than loop over lines
+ statistics.starttiming(scripts.grep)
+ local nofmatches, noffiles, nofmatchedfiles = 0, 0, 0
+ local n, m, name, check = 0, 0, "", nil
+ local count, nocomment = environment.argument("count"), environment.argument("nocomment")
+ if nocomment then
+ if count then
+ check = function(line)
n = n + 1
- if line:find(pattern) then
+ if find(line,"^[%%#]") then
+ -- skip
+ elseif find(line,pattern) then
m = m + 1
- if not count then
- input.log(format("%s %s: %s",name,n,line))
- io.flush()
- end
end
end
- if count and m > 0 then
- nofmatches = nofmatches + m
- nofmatchedfiles = nofmatchedfiles + 1
- input.log(format("%s: %s",name,m))
- io.flush()
+ else
+ check = function(line)
+ n = n + 1
+ if find(line,"^[%%#]") then
+ -- skip
+ elseif find(line,pattern) then
+ m = m + 1
+ write_nl(format("%s %s: %s",name,n,line))
+ io.flush()
+ end
+ end
+ end
+ else
+ if count then
+ check = function(line)
+ n = n + 1
+ if find(line,pattern) then
+ m = m + 1
+ end
+ end
+ else
+ check = function(line)
+ n = n + 1
+ if find(line,pattern) then
+ m = m + 1
+ write_nl(format("%s %s: %s",name,n,line))
+ io.flush()
+ end
end
end
end
---~ for i=offset or 1, #files do
---~ local filename = files[i]
---~ if filename:find("%*") then
---~ for _, name in ipairs(dir.glob(filename)) do
---~ grep(name)
---~ end
---~ else
---~ grep(filename)
---~ end
---~ end
+ local capture = (content/check)^0
for i=offset or 1, #files do
- for _, name in ipairs(dir.glob(files[i])) do
- grep(name)
+ for _, nam in ipairs(dir.glob(files[i])) do
+ name = nam
+ local data = io.loaddata(name)
+ if data then
+ n, m, noffiles = 0, 0, noffiles + 1
+ capture:match(data)
+ if count and m > 0 then
+ nofmatches = nofmatches + m
+ nofmatchedfiles = nofmatchedfiles + 1
+ write_nl(format("%s: %s",name,m))
+ io.flush()
+ end
+ end
end
end
- input.stoptiming(scripts.grep)
+ statistics.stoptiming(scripts.grep)
if count and nofmatches > 0 then
- input.log(format("\nfiles: %s, matches: %s, matched files: %s, runtime: %0.3f seconds",noffiles,nofmatches,nofmatchedfiles,input.loadtime(scripts.grep)))
+ write_nl(format("\nfiles: %s, matches: %s, matched files: %s, runtime: %0.3f seconds",noffiles,nofmatches,nofmatchedfiles,statistics.elapsedtime(scripts.grep)))
end
end
end
@@ -64,9 +95,10 @@ end
messages.help = [[
--pattern search for pattern (optional)
--count count matches only
-]]
+--nocomment skip lines that start with %% or #
-input.verbose = true
+patterns are lua patterns and need to be escaped accordingly
+]]
local pattern = environment.argument("pattern")
local files = environment.files and #environment.files > 0 and environment.files
@@ -76,5 +108,5 @@ if pattern and files then
elseif files then
scripts.grep.find(files[1], files, 2)
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-interface.lua b/scripts/context/lua/mtx-interface.lua
index b57617846..264a2dbe4 100644
--- a/scripts/context/lua/mtx-interface.lua
+++ b/scripts/context/lua/mtx-interface.lua
@@ -11,7 +11,9 @@ local format = string.format
scripts = scripts or { }
scripts.interface = scripts.interface or { }
-local flushers = { }
+local flushers = { }
+local userinterfaces = { 'en','cs','de','it','nl','ro','fr','pe' }
+local messageinterfaces = { 'en','cs','de','it','nl','ro','fr','pe','no' }
function flushers.scite(interface,collection)
local result, i = {}, 0
@@ -59,25 +61,23 @@ end
function flushers.raw(interface,collection)
for _, command in ipairs(collection) do
- input.report(command)
+ logs.simple(command)
end
end
function scripts.interface.editor(editor)
local interfaces= environment.files
if #interfaces == 0 then
- interfaces= { 'en','cs','de','it','nl','ro','fr' }
+ interfaces= userinterfaces
end
- local xmlfile = input.find_file("cont-en.xml") or ""
+ local xmlfile = resolvers.find_file("cont-en.xml") or ""
if xmlfile == "" then
- input.verbose = true
- input.report("unable to locate cont-en.xml")
+ logs.simple("unable to locate cont-en.xml")
end
for _, interface in ipairs(interfaces) do
- local keyfile = input.find_file(format("keys-%s.xml",interface)) or ""
+ local keyfile = resolvers.find_file(format("keys-%s.xml",interface)) or ""
if keyfile == "" then
- input.verbose = true
- input.report("unable to locate keys-*.xml")
+ logs.simple("unable to locate keys-*.xml")
else
local collection = { }
local mappings = { }
@@ -112,7 +112,7 @@ function scripts.interface.editor(editor)
end
function scripts.interface.check()
- local xmlfile = input.find_file("cont-en.xml") or ""
+ local xmlfile = resolvers.find_file("cont-en.xml") or ""
if xmlfile ~= "" then
local f = io.open("cont-en-check.tex","w")
if f then
@@ -138,14 +138,12 @@ function scripts.interface.check()
end
function scripts.interface.context()
- local verbose = input.verbose
- input.verbose = true
- local filename = input.find_file("mult-def.lua") or ""
+ local filename = resolvers.find_file("mult-def.lua") or ""
if filename ~= "" then
local interface = dofile(filename)
if interface and next(interface) then
local variables, constants, commands, elements = interface.variables, interface.constants, interface.commands, interface.elements
- local filename = input.find_file("cont-en.xml") or ""
+ local filename = resolvers.find_file("cont-en.xml") or ""
local xmldata = filename ~= "" and (io.loaddata(filename) or "")
local function flush(texresult,xmlresult,language,what,tag)
local t = interface[what]
@@ -156,7 +154,7 @@ function scripts.interface.context()
local v = t[key]
local value = v[language] or v["en"]
if not value then
- input.report(format("warning, no value for key '%s' for language '%s'",key,language))
+ logs.simple(format("warning, no value for key '%s' for language '%s'",key,language))
else
local value = t[key][language] or t[key].en
texresult[#texresult+1] = format("\\setinterface%s{%s}{%s}",tag,key,value)
@@ -194,9 +192,9 @@ function scripts.interface.context()
local texfilename = format("mult-%s.tex",language)
local xmlfilename = format("keys-%s.xml",language)
io.savedata(texfilename,table.concat(texresult,"\n"))
- input.report(format("saving interface definitions '%s'",texfilename))
+ logs.simple(format("saving interface definitions '%s'",texfilename))
io.savedata(xmlfilename,table.concat(xmlresult,"\n"))
- input.report(format("saving interface translations '%s'",xmlfilename))
+ logs.simple(format("saving interface translations '%s'",xmlfilename))
if language ~= "en" and xmldata ~= "" then
local newdata = xmldata:gsub("( 0 then
- input.report("number of converted files: %i", #report)
- input.report("")
+ logs.simple("number of converted files: %i", #report)
+ logs.simple("")
for _, r in ipairs(report) do
- input.report("%s => %s", r[1], r[2])
+ logs.simple("%s => %s", r[1], r[2])
end
else
- input.report("no input files match %s", table.concat(files,' '))
+ logs.simple("no input files match %s", table.concat(files,' '))
end
else
- input.report("no files match %s", table.concat(environment.files,' '))
+ logs.simple("no files match %s", table.concat(environment.files,' '))
end
end
-banner = banner .. " | mptopdf converter "
+logs.extendbanner("MetaPost to PDF Converter 0.51",true)
messages.help = [[
--rawmp raw metapost run
@@ -125,14 +125,12 @@ messages.help = [[
--latex force --tex=latex
]]
-input.verbose = true
-
if environment.files[1] then
scripts.mptopdf.convertall()
else
if not environment.arguments.help then
- input.report("provide MP output file (or pattern)")
- input.report("")
+ logs.simple("provide MP output file (or pattern)")
+ logs.simple("")
end
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtx-package.lua b/scripts/context/lua/mtx-package.lua
new file mode 100644
index 000000000..06c89907a
--- /dev/null
+++ b/scripts/context/lua/mtx-package.lua
@@ -0,0 +1,68 @@
+if not modules then modules = { } end modules ['mtx-package'] = {
+ version = 1.002,
+ comment = "companion to mtxrun.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, gsub, gmatch = string.format, string.gsub, string.gmatch
+
+scripts = scripts or { }
+messages = messages or { }
+scripts.package = scripts.package or { }
+
+function scripts.package.merge_luatex_files(name,strip)
+ local oldname = resolvers.find_file(name) or ""
+ oldname = file.replacesuffix(oldname,"lua")
+ if oldname == "" then
+ logs.simple("missing '%s'",name)
+ else
+ local newname = file.removesuffix(oldname) .. "-merged.lua"
+ local data = io.loaddata(oldname) or ""
+ if data == "" then
+ logs.simple("missing '%s'",newname)
+ else
+ logs.simple("loading '%s'",oldname)
+ local collected = { }
+ collected[#collected+1] = format("-- merged file : %s\n",newname)
+ collected[#collected+1] = format("-- parent file : %s\n",oldname)
+ collected[#collected+1] = format("-- merge date : %s\n",os.date())
+ -- loadmodule can have extra arguments
+ for lib in gmatch(data,"loadmodule *%([\'\"](.-)[\'\"]") do
+ if file.basename(lib) ~= file.basename(newname) then
+ local fullname = resolvers.find_file(lib) or ""
+ if fullname == "" then
+ logs.simple("missing '%s'",lib)
+ else
+ logs.simple("fetching '%s'",fullname)
+ local data = io.loaddata(fullname)
+ if strip then
+ data = gsub(data,"%-%-%[%[ldx%-%-.-%-%-%ldx%]%]%-%-[\n\r]*","")
+ data = gsub(data,"%-%-%~[^\n\r]*[\n\r]*","\n")
+ data = gsub(data,"%s+%-%-[^\n\r]*[\n\r]*","\n")
+ data = gsub(data,"[\n\r]+","\n")
+ end
+ collected[#collected+1] = "\ndo -- begin closure to overcome local limits and interference\n\n"
+ collected[#collected+1] = data
+ collected[#collected+1] = "\nend -- closure\n"
+ end
+ end
+ end
+ logs.simple("saving '%s'",newname)
+ io.savedata(newname,table.concat(collected))
+ end
+ end
+end
+
+logs.extendbanner("Package Tools 0.1",true)
+
+messages.help = [[
+--merge merge 'loadmodule' into merge file
+]]
+
+if environment.argument("merge") then
+ scripts.package.merge_luatex_files(environment.files[1] or "")
+else
+ logs.help(messages.help)
+end
diff --git a/scripts/context/lua/mtx-patterns.lua b/scripts/context/lua/mtx-patterns.lua
index 7fda6900c..7f130465b 100644
--- a/scripts/context/lua/mtx-patterns.lua
+++ b/scripts/context/lua/mtx-patterns.lua
@@ -19,8 +19,8 @@ scripts.patterns.list = {
{ "cs", "hyph-cs.tex", "czech" },
{ "??", "hyph-cy.tex", "welsh" },
{ "da", "hyph-da.tex", "danish" },
- { "de", "hyph-de-1901.tex", "german, old spelling" },
- { "deo", "hyph-de-1996.tex", "german, new spelling" },
+ { "deo", "hyph-de-1901.tex", "german, old spelling" },
+ { "de", "hyph-de-1996.tex", "german, new spelling" },
--~ { "??", "hyph-el-monoton.tex", "" },
--~ { "??", "hyph-el-polyton.tex", "" },
--~ { "agr", "hyph-grc", "ancient greek" },
@@ -60,7 +60,7 @@ scripts.patterns.list = {
{ "??", "hyph-sr-cyrl.tex", "serbian" },
{ "sv", "hyph-sv.tex", "swedish" },
{ "tr", "hyph-tr.tex", "turkish" },
- { "??", "hyph-uk.tex", "ukrainian" },
+ { "uk", "hyph-uk.tex", "ukrainian" },
{ "??", "hyph-zh-latn.tex", "zh-latn, chinese Pinyin" },
}
@@ -91,6 +91,7 @@ local permitted_characters = table.tohash {
0x0009, -- tab
0x0027, -- apostrofe
0x002D, -- hyphen
+ 0x200C, --
}
function scripts.patterns.load(path,name,mnemonic,fullcheck)
@@ -104,9 +105,9 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
local subdata = io.loaddata(subfull) or ""
if subdata == "" then
if mnemonic then
- input.report("no subfile %s for language %s",subname,mnemonic)
+ logs.simple("no subfile %s for language %s",subname,mnemonic)
else
- input.report("no subfile %s",name)
+ logs.simple("no subfile %s",name)
end
end
return previous .. subdata
@@ -122,15 +123,15 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
line = line:gsub("%%","%%%%")
if fullcheck then
if mnemonic then
- input.report("invalid utf in language %s, file %s, line %s: %s",mnemonic,name,n,line)
+ logs.simple("invalid utf in language %s, file %s, line %s: %s",mnemonic,name,n,line)
else
- input.report("invalid utf in file %s, line %s: %s",name,n,line)
+ logs.simple("invalid utf in file %s, line %s: %s",name,n,line)
end
else
if mnemonic then
- input.report("file %s for %s contains invalid utf",name,mnemonic)
+ logs.simple("file %s for %s contains invalid utf",name,mnemonic)
else
- input.report("file %s contains invalid utf",name)
+ logs.simple("file %s contains invalid utf",name)
end
break
end
@@ -154,17 +155,17 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
for k, v in pairs(h) do
if not permitted_commands[k] then okay = false end
if mnemonic then
- input.report("command \\%s found in language %s, file %s, n=%s",k,mnemonic,name,v)
+ logs.simple("command \\%s found in language %s, file %s, n=%s",k,mnemonic,name,v)
else
- input.report("command \\%s found in file %s, n=%s",k,name,v)
+ logs.simple("command \\%s found in file %s, n=%s",k,name,v)
end
end
if not environment.argument("fast") then
for k, v in pairs(c) do
if mnemonic then
- input.report("command \\%s found in comment of language %s, file %s, n=%s",k,mnemonic,name,v)
+ logs.simple("command \\%s found in comment of language %s, file %s, n=%s",k,mnemonic,name,v)
else
- input.report("command \\%s found in comment of file %s, n=%s",k,name,v)
+ logs.simple("command \\%s found in comment of file %s, n=%s",k,name,v)
end
end
end
@@ -222,9 +223,9 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
local stripped = { }
for k, v in pairs(p) do
if mnemonic then
- input.report("invalid character %s (0x%04X) in patterns of language %s, file %s, n=%s",char(k),k,mnemonic,name,v)
+ logs.simple("invalid character %s (0x%04X) in patterns of language %s, file %s, n=%s",char(k),k,mnemonic,name,v)
else
- input.report("invalid character %s (0x%04X) in patterns of file %s, n=%s",char(k),k,name,v)
+ logs.simple("invalid character %s (0x%04X) in patterns of file %s, n=%s",char(k),k,name,v)
end
if not permitted_characters[k] then
okay = false
@@ -234,9 +235,9 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
end
for k, v in pairs(h) do
if mnemonic then
- input.report("invalid character %s (0x%04X) in exceptions of language %s, file %s, n=%s",char(k),k,mnemonic,name,v)
+ logs.simple("invalid character %s (0x%04X) in exceptions of language %s, file %s, n=%s",char(k),k,mnemonic,name,v)
else
- input.report("invalid character %s (0x%04X) in exceptions of file %s, n=%s",char(k),k,name,v)
+ logs.simple("invalid character %s (0x%04X) in exceptions of file %s, n=%s",char(k),k,name,v)
end
if not permitted_characters[k] then
okay = false
@@ -246,15 +247,15 @@ function scripts.patterns.load(path,name,mnemonic,fullcheck)
end
local stripset = ""
for k, v in pairs(stripped) do
- input.report("entries that contain character %s will be omitted",char(k))
+ logs.simple("entries that contain character %s will be omitted",char(k))
stripset = stripset .. "%" .. char(k)
end
return okay, pats, hyps, comment, stripset, pused, hused
else
if mnemonic then
- input.report("no file %s for language %s",fullname,mnemonic)
+ logs.simple("no file %s for language %s",fullname,mnemonic)
else
- input.report("no file %s",fullname)
+ logs.simple("no file %s",fullname)
end
return false, { }, { }, "", "", { }, { }
end
@@ -265,14 +266,14 @@ function scripts.patterns.save(destination,mnemonic,patterns,hyphenations,commen
local nofhyphenations = #hyphenations
local pu = table.concat(table.sortedkeys(pused), " ")
local hu = table.concat(table.sortedkeys(hused), " ")
- input.report("language %s has %s patterns and %s exceptions",mnemonic,nofpatterns,nofhyphenations)
+ logs.simple("language %s has %s patterns and %s exceptions",mnemonic,nofpatterns,nofhyphenations)
if mnemonic ~= "??" then
local rmefile = file.join(destination,"lang-"..mnemonic..".rme")
local patfile = file.join(destination,"lang-"..mnemonic..".pat")
local hypfile = file.join(destination,"lang-"..mnemonic..".hyp")
local topline = "% generated by mtxrun --script pattern --convert"
local banner = "% for comment and copyright, see " .. rmefile
- input.report("saving language data for %s",mnemonic)
+ logs.simple("saving language data for %s",mnemonic)
if not comment or comment == "" then comment = "% no comment" end
if not type(destination) == "string" then destination = "." end
os.remove(rmefile)
@@ -285,60 +286,58 @@ function scripts.patterns.save(destination,mnemonic,patterns,hyphenations,commen
end
function scripts.patterns.prepare()
- dofile(input.find_file("char-def.lua"))
+ dofile(resolvers.find_file("char-def.lua"))
end
function scripts.patterns.check()
local path = environment.argument("path") or "."
local found = false
- local verbose = input.verbose
- input.verbose = true
if #environment.files > 0 then
for _, name in ipairs(environment.files) do
- input.report("checking language file %s", name)
+ logs.simple("checking language file %s", name)
local okay = scripts.patterns.load(path,name,nil,not environment.argument("fast"))
if #environment.files > 1 then
- input.report("")
+ logs.simple("")
end
end
else
for k, v in pairs(scripts.patterns.list) do
local mnemonic, name = v[1], v[2]
- input.report("checking language %s, file %s", mnemonic, name)
+ logs.simple("checking language %s, file %s", mnemonic, name)
local okay = scripts.patterns.load(path,name,mnemonic,not environment.argument("fast"))
if not okay then
- input.report("there are errors that need to be fixed")
+ logs.simple("there are errors that need to be fixed")
end
- input.report("")
+ logs.simple("")
end
end
- input.verbose = verbose
end
function scripts.patterns.convert()
local path = environment.argument("path") or "."
- local destination = environment.argument("destination") or "."
- if path == destination then
- input.report("source path and destination path should differ (use --path and/or --destination)")
+ if path == "" then
+ logs.simple("provide sourcepath using --path ")
else
- local verbose = input.verbose
- input.verbose = true
- for k, v in pairs(scripts.patterns.list) do
- local mnemonic, name = v[1], v[2]
- input.report("converting language %s, file %s", mnemonic, name)
- local okay, patterns, hyphenations, comment, stripped, pused, hused = scripts.patterns.load(path,name,false)
- if okay then
- scripts.patterns.save(destination,mnemonic,patterns,hyphenations,comment,stripped,pused,hused)
- else
- input.report("convertion aborted due to error(s)")
+ local destination = environment.argument("destination") or "."
+ if path == destination then
+ logs.simple("source path and destination path should differ (use --path and/or --destination)")
+ else
+ for k, v in pairs(scripts.patterns.list) do
+ local mnemonic, name = v[1], v[2]
+ logs.simple("converting language %s, file %s", mnemonic, name)
+ local okay, patterns, hyphenations, comment, stripped, pused, hused = scripts.patterns.load(path,name,false)
+ if okay then
+ scripts.patterns.save(destination,mnemonic,patterns,hyphenations,comment,stripped,pused,hused)
+ else
+ logs.simple("convertion aborted due to error(s)")
+ end
+ logs.simple("")
end
- input.report("")
end
end
- input.verbose = verbose
end
-banner = banner .. " | pattern tools "
+logs.extendbanner("Pattern Tools 0.20",true)
messages.help = [[
--convert generate context language files (mnemonic driven, if not given then all)
@@ -354,10 +353,10 @@ elseif environment.argument("convert") then
scripts.patterns.prepare()
scripts.patterns.convert()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
-- mtxrun --script pattern --check hyph-*.tex
--- mtxrun --script pattern --check --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns
--- mtxrun --script pattern --check --fast --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns
--- mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns --destination e:/tmp/patterns
+-- mtxrun --script pattern --check --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns
+-- mtxrun --script pattern --check --fast --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns
+-- mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns --destination=e:/tmp/patterns
diff --git a/scripts/context/lua/mtx-profile.lua b/scripts/context/lua/mtx-profile.lua
new file mode 100644
index 000000000..d99f7e926
--- /dev/null
+++ b/scripts/context/lua/mtx-profile.lua
@@ -0,0 +1,164 @@
+if not modules then modules = { } end modules ['mtx-profile'] = {
+ version = 1.000,
+ comment = "companion to mtxrun.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- todo: also line number
+-- todo: sort runtime as option
+
+local match, format, find = string.match, string.format, string.find
+
+scripts = scripts or { }
+scripts.profiler = scripts.profiler or { }
+
+local timethreshold = 0
+local callthreshold = 2500
+local countthreshold = 2500
+
+local functiontemplate = "%12s %03.4f %9i %s"
+local calltemplate = "%9i %s"
+local totaltemplate = "%i internal calls, %i function calls taking %3.4f seconds"
+local thresholdtemplate = "thresholds: %i internal calls, %i function calls, %i seconds"
+
+function scripts.profiler.analyse(filename)
+ local f = io.open(filename)
+ if f then
+ local times, counts, calls = { }, { }, { }
+ local totalruntime, totalcount, totalcalls = 0, 0, 0
+ while true do
+ local line = f:read()
+ if line then
+ local stacklevel, filename, functionname, linenumber, currentline, localtime, totaltime = line:match("^(%d+)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)")
+ if not filename then
+ -- next
+ elseif filename == "=[C]" then
+ if not functionname:find("^%(") then
+ calls[functionname] = (calls[functionname] or 0) + 1
+ end
+ else
+ local filename = filename:match("^@(.*)$")
+ if filename then
+ local fi = times[filename]
+ if not fi then fi = { } times[filename] = fi end
+ fi[functionname] = (fi[functionname] or 0) + tonumber(localtime)
+ counts[functionname] = (counts[functionname] or 0) + 1
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ print("")
+ local loaded = { }
+ for _, filename in ipairs(table.sortedkeys(times)) do
+ local functions = times[filename]
+ for _, functionname in ipairs(table.sortedkeys(functions)) do
+ local totaltime = functions[functionname]
+ local count = counts[functionname]
+ totalcount = totalcount + count
+ if totaltime > timethreshold or count > countthreshold then
+ totalruntime = totalruntime + totaltime
+ local functionfile, somenumber = functionname:match("^@(.+):(.-)$")
+ if functionfile then
+ local number = tonumber(somenumber)
+ if number then
+ if not loaded[functionfile] then
+ loaded[functionfile] = string.splitlines(io.loaddata(functionfile) or "")
+ end
+ functionname = loaded[functionfile][number] or functionname
+ functionname = functionname:gsub("^%s*","")
+ functionname = functionname:gsub("%s*%-%-.*$","")
+ functionname = number .. ": " .. functionname
+ end
+ end
+ filename = file.basename(filename)
+ print(functiontemplate:format(filename,totaltime,count,functionname))
+ end
+ end
+ end
+ print("")
+ for _, call in ipairs(table.sortedkeys(calls)) do
+ local n = calls[call]
+ totalcalls = totalcalls + n
+ if n > callthreshold then
+ print(calltemplate:format(n,call))
+ end
+ end
+ print("")
+ print(totaltemplate:format(totalcalls,totalcount,totalruntime))
+ print("")
+ print(thresholdtemplate:format(callthreshold,countthreshold,timethreshold))
+ end
+end
+
+function scripts.profiler.analyse(filename)
+ local f = io.open(filename)
+ local calls = { }
+ local lines = 0
+ if f then
+ while true do
+ local line = f:read()
+ if line then
+ lines = lines + 1
+ local c = match(line,"\\([a-zA-Z%!%?@]+) *%->")
+ if c then
+ local cc = calls[c]
+ if not cc then
+ calls[c] = 1
+ else
+ calls[c] = cc + 1
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ local noc = 0
+local criterium = 100
+ for name, n in next, calls do
+ if n > criterium then
+ if find(name,"^@@[a-z][a-z]") then
+ -- parameter
+ elseif find(name,"^[cvserft]%!") then
+ -- variables and constants
+ elseif find(name,"^%?%?[a-z][a-z]$") then
+ -- prefix
+ elseif find(name,"^%!%!") then
+ -- reserved
+ elseif find(name,"^@.+@$") then
+ -- weird
+ else
+ noc = noc + n
+ print(format("%6i: %s",n,name))
+ end
+ end
+ end
+ print("")
+ print(format("number of lines: %s",lines))
+ print(format("number of calls: %s",noc))
+ print(format("criterium calls: %s",criterium))
+ end
+end
+
+--~ scripts.profiler.analyse("t:/manuals/mk/mk-fonts-profile.lua")
+--~ scripts.profiler.analyse("t:/manuals/mk/mk-introduction-profile.lua")
+
+logs.extendbanner("LuaTeX Profiler 1.00",true)
+
+messages.help = [[
+--analyse analyse lua calls
+--trace analyse tex calls
+]]
+
+if environment.argument("analyse") then
+ scripts.profiler.analyse(environment.files[1] or "luatex-profile.log")
+elseif environment.argument("trace") then
+ scripts.profiler.analyse(environment.files[1] or "temp.log")
+else
+ logs.help(messages.help)
+end
diff --git a/scripts/context/lua/mtx-server-ctx-fonttest.lua b/scripts/context/lua/mtx-server-ctx-fonttest.lua
new file mode 100644
index 000000000..efaae66e3
--- /dev/null
+++ b/scripts/context/lua/mtx-server-ctx-fonttest.lua
@@ -0,0 +1,681 @@
+if not modules then modules = { } end modules ['mtx-server-ctx-fonttest'] = {
+ version = 1.001,
+ comment = "Font Feature Tester",
+ author = "Hans Hagen",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+dofile(resolvers.find_file("l-aux.lua","tex"))
+dofile(resolvers.find_file("trac-lmx.lua","tex"))
+dofile(resolvers.find_file("font-ott.lua","tex"))
+dofile(resolvers.find_file("font-syn.lua","tex"))
+dofile(resolvers.find_file("font-mis.lua","tex"))
+dofile(resolvers.find_file("font-otp.lua","tex"))
+
+local format, gsub, concat, match, find = string.format, string.gsub, table.concat, string.match, string.find
+
+local sample_line = "This is a sample line!"
+local tempname = "mtx-server-ctx-fonttest-temp"
+local temppath = caches.setpath("temp","mtx-server-ctx-fonttest")
+local basename = "mtx-server-ctx-fonttest-data.lua"
+local basepath = temppath
+
+for _, suffix in ipairs { "tex", "pdf", "log" } do
+ os.remove(file.join(temppath,file.addsuffix(tempname,suffix)))
+end
+
+local process_templates = { }
+
+process_templates.default = [[
+\starttext
+ \setcharactermirroring[1]
+ \definefontfeature[sample][%s]
+ \definedfont[name:%s*sample]
+ \startTEXpage[offset=3pt]
+ \detokenize{%s}
+ \stopTEXpage
+\stoptext
+]]
+
+process_templates.cache = [[
+\starttext
+ \definedfont[name:%s]
+ \startTEXpage[offset=3pt]
+ cached: \detokenize{%s}
+ \stopTEXpage
+\stoptext
+]]
+
+process_templates.trace = [[
+\usemodule[fnt-20]
+
+\definefontfeature[sample][%s]
+
+\setupcolors[state=start]
+
+\setcharactermirroring[1]
+
+\setvariables
+ [otftracker]
+ [title=Test Run,
+ font=name:%s,
+ direction=0,
+ features=sample,
+ sample={\detokenize{%s}}]
+]]
+
+local javascripts = [[
+function selected_radio(name) {
+ var form = document.forms["main-form"] ;
+ var script = form.elements[name] ;
+ if (script) {
+ var n = script.length ;
+ if (n) {
+ for (var i=0; i"
+ listoffonts[#listoffonts+1] = "
safe name
font name
filename
sub font
type
"
+ for k, id in ipairs(table.sortedkeys(t)) do
+ local ti = t[id]
+ local type, name, file, sub = ti[1], ti[2], ti[3], ti[4]
+ if type == "otf" or type == "ttf" or type == "ttc" then
+ if sub then sub = "(sub)" else sub = "" end
+ listoffonts[#listoffonts+1] = format("
+]]
+
+scripts.webserver.registerpath(temppath)
+
+local function edit_font(currentfont,detail,tempname)
+ local fontname, fontfile, issub = fonts.names.specification(currentfont or "")
+ local htmldata = showfeatures(fontfile)
+ if htmldata then
+ local features, languages, scripts, options = { }, { }, { }, { }
+ for k,v in ipairs(table.sortedkeys(htmldata.scripts)) do
+ local s = fonts.otf.tables.scripts[v] or v
+ if detail and v == detail.script then
+ scripts[#scripts+1] = format(" %s",s,v,v,v,v)
+ else
+ scripts[#scripts+1] = format(" %s",s,v,v,v,v)
+ end
+ end
+ for k,v in ipairs(table.sortedkeys(htmldata.languages)) do
+ local l = fonts.otf.tables.languages[v] or v
+ if detail and v == detail.language then
+ languages[#languages+1] = format(" %s",l,v,v,v,v)
+ else
+ languages[#languages+1] = format(" %s",l,v,v,v,v)
+ end
+ end
+ for k,v in ipairs(table.sortedkeys(htmldata.features)) do
+ local f = fonts.otf.tables.features[v] or v
+ if detail and detail["f-"..v] then
+ features[#features+1] = format(" %s",f,v,v,v,v)
+ else
+ features[#features+1] = format(" %s",f,v,v,v,v)
+ end
+ end
+ for k, v in ipairs { "trace", "basemode" } do
+ if detail and detail["o-"..v] then
+ options[#options+1] = format(" %s",v,v,v)
+ else
+ options[#options+1] = format(" %s",v,v,v)
+ end
+ end
+ local e = format(edit_template,
+ (detail and detail.sampletext) or sample_line,(detail and detail.name) or "no name",(detail and detail.title) or "",
+ concat(scripts," "),concat(languages," "),concat(features," "),concat(options," "))
+ if tempname then
+ local pdffile, texfile = file.addsuffix(tempname,"pdf"), file.addsuffix(tempname,"tex")
+ local r = format(result_template,pdffile,texfile,pdffile)
+ return e .. r, htmldata.javascript or ""
+ else
+ return e, htmldata.javascript or ""
+ end
+ else
+ return "error, nothing set up yet"
+ end
+end
+
+local function process_font(currentfont,detail) -- maybe just fontname
+ local fontname, fontfile, issub = fonts.names.specification(currentfont or "")
+ local features = {
+ "mode=node",
+ format("language=%s",detail.language or "dflt"),
+ format("script=%s",detail.script or "dflt"),
+ }
+ for k,v in pairs(detail) do
+ local f = match(k,"^f%-(.*)$")
+ if f then
+ features[#features+1] = format("%s=yes",f)
+ end
+ end
+ local variant = process_templates.default
+ if detail["o-trace"] then
+ variant = process_templates.trace
+ end
+ local sample = string.strip(detail.sampletext or "")
+ if sample == "" then sample = sample_line end
+ logs.simple("sample text: %s",sample)
+ io.savedata(file.join(temppath,file.addsuffix(tempname,"tex")),format(variant,concat(features,","),currentfont,sample))
+ os.execute(format("mtxrun --path=%s --script context --once --batchmode --mode=*nofonts %s",temppath,tempname))
+ return edit_font(currentfont,detail,tempname)
+end
+
+local tex_template = [[
+
+%s
+
+]]
+
+local function show_source(currentfont,detail)
+ if tempname and tempname ~= "" then
+ return format(tex_template,io.loaddata(file.join(temppath,file.addsuffix(tempname,"tex"))) or "no source yet")
+ else
+ return "no source file"
+ end
+end
+
+local function show_log(currentfont,detail)
+ if tempname and tempname ~= "" then
+ local data = io.loaddata(file.join(temppath,file.addsuffix(tempname,'log'))) or "no log file yet"
+ data = gsub(data,"[%s%%]*begin of optionfile.-end of optionfile[%s%%]*","\n")
+ return format(tex_template,data)
+ else
+ return "no log file"
+ end
+end
+
+local function show_font(currentfont,detail)
+ local fontname, fontfile, issub = fonts.names.specification(currentfont or "")
+ local features = fonts.get_features(fontfile)
+ local result = { }
+ result[#result+1] = format("
names
",what)
+ result[#result+1] = "
"
+ result[#result+1] = format("
fontname:
%s
",currentfont)
+ result[#result+1] = format("
fullname:
%s
",fontname)
+ result[#result+1] = format("
filename:
%s
",fontfile)
+ result[#result+1] = "
"
+ if features then
+ for what, v in table.sortedpairs(features) do
+ local data = features[what]
+ if data and next(data) then
+ result[#result+1] = format("
%s features
",what)
+ result[#result+1] = "
"
+ result[#result+1] = "
feature
tag
script
languages
"
+ for f,ff in table.sortedpairs(data) do
+ local done = false
+ for s, ss in table.sortedpairs(ff) do
+ if s == "*" then s = "all" end
+ if ss ["*"] then ss["*"] = nil ss.all = true end
+ if done then
+ f = ""
+ else
+ done = true
+ end
+ local title = fonts.otf.tables.features[f] or ""
+ result[#result+1] = format("
%s
%s
%s
%s
",title,f,s,concat(table.sortedkeys(ss)," "))
+ end
+ end
+ result[#result+1] = "
"
+ end
+ end
+ else
+ result[#result+1] = "
This font has no features."
+ end
+ return concat(result,"\n")
+end
+
+
+local info_template = [[
+
+]]
+
+local function info_about()
+ local m = modules ['mtx-server-ctx-fonttest']
+ return format(info_template,m.version,m.comment,m.author,m.copyright)
+end
+
+local save_template = [[
+ the current setup has been saved:
+
+
+
name
%s
+
title
%s
+
font
%s
+
script
%s
+
language
%s
+
features
%s
+
options
%s
+
sampletext
%s
+
+]]
+
+local function loadbase()
+ local datafile = file.join(basepath,basename)
+ local storage = io.loaddata(datafile) or ""
+ if storage == "" then
+ storage = { }
+ else
+ logs.simple("loading '%s'",datafile)
+ storage = loadstring(storage)
+ storage = (storage and storage()) or { }
+ end
+ return storage
+end
+
+local function loadstored(detail,currentfont,name)
+ local storage = loadbase()
+ storage = storage and storage[name]
+ if storage then
+ currentfont = storage.font
+ detail.script = storage.script or detail.script
+ detail.language = storage.language or detail.language
+ detail.title = storage.title or detail.title
+ detail.sampletext = storage.text or detail.sampletext
+ detail.name = name or "no name"
+ for k,v in pairs(storage.features) do
+ detail["f-"..k] = v
+ end
+ for k,v in pairs(storage.options) do
+ detail["o-"..k] = v
+ end
+ end
+ detail.loadname = nil
+ return detail, currentfont
+end
+
+local function savebase(storage,name)
+ local datafile = file.join(basepath,basename)
+ logs.simple("saving '%s' in '%s'",name or "data",datafile)
+ io.savedata(datafile,table.serialize(storage,true))
+end
+
+local function deletestored(detail,currentfont,name)
+ local storage = loadbase()
+ if storage and name and storage[name] then
+ logs.simple("deleting '%s' from base",name)
+ storage[name] = nil
+ savebase(storage)
+ end
+ detail.deletename = nil
+ return detail, ""
+end
+
+local function save_font(currentfont,detail)
+ local fontname, fontfile, issub = fonts.names.specification(currentfont or "")
+ local name, title, script, language, features, options, text = currentfont, "", "dflt", "dflt", { }, { }, ""
+ if detail then
+ local htmldata = showfeatures(fontfile)
+ script = detail.script or script
+ language = detail.language or language
+ text = string.strip(detail.sampletext or text)
+ name = string.strip(detail.name or name)
+ title = string.strip(detail.title or title)
+ for k,v in pairs(htmldata.features) do
+ if detail["f-"..k] then features[k] = true end
+ end
+ for k,v in ipairs { "trace", "basemode" } do
+ if detail["o-"..v] then options[k] = true end
+ end
+ end
+ if name == "" then
+ name = "no name"
+ end
+ local storage = loadbase()
+ storage[name] = {
+ font = currentfont, title = title, script = script, language = language, features = features, options = options, text = text,
+ }
+ savebase(storage,name)
+ return format(save_template,name,title,currentfont,script,language,concat(table.sortedkeys(features)," "),concat(table.sortedkeys(options)," "),text)
+end
+
+local function load_font(currentfont)
+ local datafile = file.join(basepath,basename)
+ local storage = loadbase(datafile)
+ local result = {}
+ result[#result+1] = format("
del
name
font
fontname
script
language
features
title
sampletext
")
+ for k,v in table.sortedpairs(storage) do
+ local fontname, fontfile, issub = fonts.names.specification(v.font or "")
+ result[#result+1] = format("
",
+ k,k,k,v.font,fontname,v.script,v.language,concat(table.sortedkeys(v.features)," "),v.title or "no title",v.text or "")
+ end
+ if #result == 1 then
+ return "nothing saved yet"
+ else
+ return format("
%s
",concat(result,"\n"))
+ end
+end
+
+local function reset_font(currentfont)
+ return edit_font(currentfont)
+end
+
+local extras_template = [[
+ remake font database (take some time)
+]]
+
+local function do_extras(detail,currentfont,extra)
+ return extras_template
+end
+
+local extras = { }
+
+local function do_extra(detail,currentfont,extra)
+ local e = extras[extra]
+ if e then e(detail,currentfont,extra) end
+ return do_extras(detail,currentfont,extra)
+end
+
+function extras.reload()
+ local command = "mtxrun --script font --reload"
+ logs.simple("run command: %s",command)
+ os.execute(command)
+ return do_extras()
+end
+
+
+local status_template = [[
+
+]]
+
+function doit(configuration,filename,hashed)
+
+ local start = os.clock()
+
+ local detail = url.query(hashed.query or "")
+
+ local currentfont = detail.currentfont
+ local action = detail.action
+ local selection = detail.selection
+
+ local loadname = detail.loadname
+ local deletename = detail.deletename
+ local extra = detail.extra
+
+ if loadname and loadname ~= "" then
+ detail, currentfont = loadstored(detail,currentfont,loadname)
+ action = "process"
+ elseif deletename and deletename ~= "" then
+ detail, currentfont = deletestored(detail,currentfont,deletename)
+ action = "load"
+ elseif selection and selection ~= "" then
+ currentfont = selection
+ elseif extra and extra ~= "" then
+ do_extra(detail,currentfont,extra)
+ action = "extras"
+ end
+
+ lmx.restore()
+
+ local fontname, fontfile, issub = fonts.names.specification(currentfont or "")
+
+ if fontfile then
+ lmx.variables['title-default'] = format('ConTeXt Font Tester: %s (%s)',fontname,fontfile)
+ else
+ lmx.variables['title-default'] = 'ConTeXt Font Tester'
+ end
+
+ lmx.variables['color-background-green'] = '#4F6F6F'
+ lmx.variables['color-background-blue'] = '#6F6F8F'
+ lmx.variables['color-background-yellow'] = '#8F8F6F'
+ lmx.variables['color-background-purple'] = '#8F6F8F'
+
+ lmx.variables['color-background-body'] = '#808080'
+ lmx.variables['color-background-main'] = '#3F3F3F'
+ lmx.variables['color-background-one'] = lmx.variables['color-background-green']
+ lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
+
+ lmx.variables['title'] = lmx.variables['title-default']
+
+ lmx.set('title', lmx.get('title'))
+ lmx.set('color-background-one', lmx.get('color-background-green'))
+ lmx.set('color-background-two', lmx.get('color-background-blue'))
+
+ -- lua table and adapt
+
+ lmx.set('formaction', "mtx-server-ctx-fonttest.lua")
+
+ local menu = { }
+ for k, v in ipairs { 'process', 'select', 'save', 'load', 'edit', 'reset', 'features', 'source', 'log', 'info', 'extras'} do
+ menu[#menu+1] = format("",v,v)
+ end
+ lmx.set('menu', concat(menu," "))
+
+ logs.simple("action: %s",action or "no action")
+
+ lmx.set("status",format(status_template,currentfont or ""))
+
+ local result
+
+ if action == "select" then
+ lmx.set('maintext',select_font())
+ elseif action == "info" then
+ lmx.set('maintext',info_about())
+ elseif action == "extras" then
+ lmx.set('maintext',do_extras())
+ elseif currentfont and currentfont ~= "" then
+ if action == "save" then
+ lmx.set('maintext',save_font(currentfont,detail))
+ elseif action == "load" then
+ lmx.set('maintext',load_font(currentfont,detail))
+ elseif action == "source" then
+ lmx.set('maintext',show_source(currentfont,detail))
+ elseif action == "log" then
+ lmx.set('maintext',show_log(currentfont,detail))
+ elseif action == "features" then
+ lmx.set('maintext',show_font(currentfont,detail))
+ else
+ local e, s
+ if action == "process" then
+ e, s = process_font(currentfont,detail)
+ elseif action == "reset" then
+ e, s = reset_font(currentfont)
+ elseif action == "edit" then
+ e, s = edit_font(currentfont,detail)
+ else
+ e, s = process_font(currentfont,detail)
+ end
+ lmx.set('maintext',e)
+ lmx.set('javascriptdata',s)
+ lmx.set('javascripts',javascripts)
+ lmx.set('javascriptinit', "check_form()")
+ end
+ else
+ lmx.set('maintext',select_font())
+ end
+
+ result = { content = lmx.convert('context-fonttest.lmx') }
+
+ logs.simple("time spent on page: %0.03f seconds",os.clock()-start)
+
+ return result
+
+end
+
+return doit, true
+
+--~ make_lmx_page("test")
diff --git a/scripts/context/lua/mtx-server-ctx-help.lua b/scripts/context/lua/mtx-server-ctx-help.lua
new file mode 100644
index 000000000..c53d9f6e0
--- /dev/null
+++ b/scripts/context/lua/mtx-server-ctx-help.lua
@@ -0,0 +1,648 @@
+if not modules then modules = { } end modules ['mtx-server-ctx-help'] = {
+ version = 1.001,
+ comment = "Basic Definition Browser",
+ author = "Hans Hagen",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--~ dofile(resolvers.find_file("l-xml.lua","tex"))
+dofile(resolvers.find_file("l-aux.lua","tex"))
+dofile(resolvers.find_file("trac-lmx.lua","tex"))
+
+-- problem ... serialize parent stack
+
+local format = string.format
+local concat = table.concat
+
+-- -- -- make this a module: cont-xx.lua
+
+document = document or { }
+document.setups = document.setups or { }
+
+document.setups.div = {
+ pe = "
%s]],
+ special = "%s",
+ default = "%s",
+}
+
+local function translate(tag,int,noformat)
+ local t = document.setups.translations
+ local te = t["en"]
+ local ti = t[int] or te
+ if noformat then
+ return ti[tag] or te[tag] or tag
+ else
+ return document.setups.formats.special:format(ti[tag] or te[tag] or tag)
+ end
+end
+
+local function translated(e,int)
+ local attributes = e.at
+ local s = attributes.type or "?"
+ local tag = s:match("^cd:(.*)$")
+ if attributes.default == "yes" then
+ return document.setups.formats.default:format(tag)
+ elseif tag then
+ return translate(tag,int)
+ else
+ return s
+ end
+end
+
+document.setups.loaded = document.setups.loaded or { }
+
+document.setups.current = { }
+document.setups.showsources = false
+
+function document.setups.load(filename)
+ filename = resolvers.find_file(filename) or ""
+ if filename ~= "" then
+ local current = document.setups.loaded[filename]
+ if not current then
+ local loaded = xml.load(filename)
+ if loaded then
+ -- xml.inject(document.setups.root,"/",loaded)
+ current = {
+ file = filename,
+ root = loaded,
+ names = { },
+ used = { },
+ }
+ document.setups.loaded[filename] = current
+ end
+ end
+ document.setups.current = current or { }
+ end
+end
+
+function document.setups.name(ek)
+ local at = ek.at
+ local name = at.name
+ if at.type == 'environment' then
+ name = "start" .. name
+ end
+ if at.variant then
+ name = name .. ":" .. at.variant
+ end
+ if at.generated == "yes" then
+ name = name .. "*"
+ end
+ return name:lower()
+end
+
+function document.setups.csname(ek,int)
+ local cs = ""
+ local at = ek.at
+ if at.type == 'environment' then
+ cs = translate("start",int,true) .. cs
+ end
+ for r, d, k in xml.elements(ek,'cd:sequence/(cd:string|variable)') do
+ local dk = d[k]
+ if dk.tg == "string" then
+ cs = cs .. dk.at.value
+ else
+ cs = cs .. dk.at.value -- to be translated
+ end
+ end
+ return cs
+end
+
+function document.setups.names()
+ local current = document.setups.current
+ local names = current.names
+ if not names or #names == 0 then
+ names = { }
+ local name = document.setups.name
+ local csname = document.setups.csname
+ for r, d, k in xml.elements(current.root,'cd:command') do
+ local dk = d[k]
+ names[#names+1] = { dk.at.name, csname(dk,int) }
+ end
+ table.sort(names, function(a,b) return a[2]:lower() < b[2]:lower() end)
+ current.names = names
+ end
+ return names
+end
+
+function document.setups.show(name)
+ local current = document.setups.current
+ if current.root then
+ local name = name:gsub("[<>]","")
+ local setup = xml.first(current.root,"cd:command[@name='" .. name .. "']")
+ current.used[#current.used+1] = setup
+ xml.sprint(setup)
+ end
+end
+
+function document.setups.showused()
+ local current = document.setups.current
+ if current.root and next(current.used) then
+ for k,v in ipairs(table.sortedkeys(current.used)) do
+ xml.sprint(current.used[v])
+ end
+ end
+end
+function document.setups.showall()
+ local current = document.setups.current
+ if current.root then
+ local list = { }
+ xml.each_element(current.root,"cd:command", function(r,d,t)
+ local ek = d[t]
+ list[document.setups.name(ek)] = ek
+ end )
+ for k,v in ipairs(table.sortedkeys(list)) do
+ xml.sprint(list[v])
+ end
+ end
+end
+function document.setups.resolve(name)
+ local current = document.setups.current
+ if current.root then
+ local e = xml.filter(current.root,format("cd:define[@name='%s']/text()",name))
+ if e then
+ xml.sprint(e)
+ end
+ end
+end
+
+function document.setups.collect(name,int)
+ local current = document.setups.current
+ local formats = document.setups.formats
+ local command = xml.filter(current.root,format("cd:command[@name='%s']",name))
+ if command then
+ local attributes = command.at
+ local data = {
+ command = command,
+ category = attributes.category or "",
+ }
+ if document.setups.showsources then
+ data.source = (attributes.file and formats.source:format(attributes.file,attributes.file)) or ""
+ else
+ data.source = attributes.file or ""
+ end
+ local sequence, n = { "\\" .. document.setups.csname(command,int) }, 0
+ local arguments = { }
+ for r, d, k in xml.elements(command,"(cd:keywords|cd:assignments)") do
+ n = n + 1
+ local attributes = d[k].at
+ if attributes.optional == 'yes' then
+ if attributes.list == 'yes' then
+ sequence[#sequence+1] = formats.optional_list:format(n)
+ else
+ sequence[#sequence+1] = formats.optional_single:format(n)
+ end
+ else
+ if attributes.list == 'yes' then
+ sequence[#sequence+1] = formats.mandate_list:format(n)
+ else
+ sequence[#sequence+1] = formats.mandate_single:format(n)
+ end
+ end
+ end
+ data.sequence = concat(sequence, " ")
+ local parameters, n = { }, 0
+ for r, d, k in xml.elements(command,"(cd:keywords|cd:assignments)") do
+ n = n + 1
+ if d[k].tg == "keywords" then
+ local left = sequence[n+1]
+ local right = { }
+ for r, d, k in xml.elements(d[k],"(cd:constant|cd:resolve)") do
+ local tag = d[k].tg
+ if tag == "resolve" then
+ local name = d[k].at.name or ""
+ if name ~= "" then
+ local resolved = xml.filter(current.root,format("cd:define[@name='%s']",name))
+ for r, d, k in xml.elements(resolved,"cd:constant") do
+ right[#right+1] = translated(d[k],int)
+ end
+ end
+ else
+ right[#right+1] = translated(d[k],int)
+ end
+ end
+ parameters[#parameters+1] = formats.parameter:format(left,"",concat(right, ", "))
+ else
+ local what = sequence[n+1]
+ for r, d, k in xml.elements(d[k],"(cd:parameter|cd:inherit)") do
+ local tag = d[k].tg
+ local left, right = d[k].at.name or "?", { }
+ if tag == "inherit" then
+ local name = d[k].at.name or "?"
+ local goto = document.setups.formats.href:format(name,"\\"..name)
+ if #parameters > 0 and not parameters[#parameters]:find(" ") then
+ parameters[#parameters+1] = formats.parameter:format(" ","","")
+ end
+ parameters[#parameters+1] = formats.parameter:format(what,formats.special:format(translate("inherits",int)),goto)
+ else
+ for r, d, k in xml.elements(d[k],"(cd:constant|cd:resolve)") do
+ local tag = d[k].tg
+ if tag == "resolve" then
+ local name = d[k].at.name or ""
+ if name ~= "" then
+ local resolved = xml.filter(current.root,format("cd:define[@name='%s']",name))
+ for r, d, k in xml.elements(resolved,"cd:constant") do
+ right[#right+1] = translated(d[k],int)
+ end
+ end
+ else
+ right[#right+1] = translated(d[k],int)
+ end
+ end
+ parameters[#parameters+1] = formats.parameter:format(what,left,concat(right, ", "))
+ end
+ what = ""
+ end
+ end
+ parameters[#parameters+1] = formats.parameter:format(" ","","")
+ end
+ data.parameters = parameters
+ return data
+ else
+ return nil
+ end
+end
+
+-- -- --
+
+tex = tex or { }
+
+lmx.variables['color-background-green'] = '#4F6F6F'
+lmx.variables['color-background-blue'] = '#6F6F8F'
+lmx.variables['color-background-yellow'] = '#8F8F6F'
+lmx.variables['color-background-purple'] = '#8F6F8F'
+
+lmx.variables['color-background-body'] = '#808080'
+lmx.variables['color-background-main'] = '#3F3F3F'
+lmx.variables['color-background-main-left'] = '#3F3F3F'
+lmx.variables['color-background-main-right'] = '#5F5F5F'
+lmx.variables['color-background-one'] = lmx.variables['color-background-green']
+lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
+
+lmx.variables['title-default'] = 'ConTeXt Help Information'
+lmx.variables['title'] = lmx.variables['title-default']
+
+function lmx.loadedfile(filename)
+ return io.loaddata(resolvers.find_file(filename)) -- return resolvers.texdatablob(filename)
+end
+
+-- -- --
+
+local interfaces = {
+ czech = 'cz',
+ dutch = 'nl',
+ english = 'en',
+ french = 'fr',
+ german = 'de',
+ italian = 'it',
+ persian = 'pe',
+ romanian = 'ro',
+}
+
+local lastinterface, lastcommand, lastsource = "en", "", ""
+
+local function doit(configuration,filename,hashed)
+
+ local formats = document.setups.formats
+
+ local start = os.clock()
+
+ local detail = aux.settings_to_hash(hashed.query or "")
+
+ lastinterface, lastcommand, lastsource = detail.interface or lastinterface, detail.command or lastcommand, detail.source or lastsource
+
+ if lastinterface then
+ logs.simple("checking interface: %s",lastinterface)
+ document.setups.load(format("cont-%s.xml",lastinterface))
+ end
+
+ local div = document.setups.div[lastinterface]
+ local span = document.setups.span[lastinterface]
+
+ local result = { content = "error" }
+
+ local names, refs, ints = document.setups.names(lastinterface), { }, { }
+ for k,v in ipairs(names) do
+ refs[k] = document.setups.formats.href:format(v[1],v[2])
+ end
+ for k,v in ipairs(table.sortedkeys(interfaces)) do
+ ints[k] = document.setups.formats.interface:format(interfaces[v],v)
+ end
+
+ lmx.restore()
+ lmx.set('title', 'ConTeXt Help Information')
+ lmx.set('color-background-one', lmx.get('color-background-green'))
+ lmx.set('color-background-two', lmx.get('color-background-blue'))
+
+ local n = concat(refs," ")
+ local i = concat(ints,"
")
+
+ if div then
+ lmx.set('names',div:format(n))
+ lmx.set('interfaces',div:format(i))
+ else
+ lmx.set('names', n)
+ lmx.set('interfaces', i)
+ end
+
+ -- first we need to add information about mkii/mkiv
+
+ if document.setups.showsources and lastsource and lastsource ~= "" then
+ -- todo: mkii, mkiv, tex (can be different)
+ local data = io.loaddata(resolvers.find_file(lastsource))
+ lmx.set('maintitle', lastsource)
+ lmx.set('maintext', formats.listing:format(data))
+ lastsource = ""
+ elseif lastcommand and lastcommand ~= "" then
+ local data = document.setups.collect(lastcommand,lastinterface)
+ if data then
+ lmx.set('maintitle', data.sequence)
+ local extra = { }
+ for k, v in ipairs { "environment", "category", "source" } do
+ if data[v] and data[v] ~= "" then
+ lmx.set(v, data[v])
+ extra[#extra+1] = v .. ": " .. data[v]
+ end
+ end
+ lmx.set('extra', concat(extra,", "))
+ lmx.set('maintext', formats.parameters:format(concat(data.parameters)))
+ else
+ lmx.set('maintext', "select command")
+ end
+ else
+ lmx.set('maintext', "no definition")
+ end
+
+ local content = lmx.convert('context-help.lmx')
+
+ logs.simple("time spent on page: %0.03f seconds",os.clock()-start)
+
+ return { content = content }
+end
+
+return doit, true
diff --git a/scripts/context/lua/mtx-server-ctx-startup.lua b/scripts/context/lua/mtx-server-ctx-startup.lua
new file mode 100644
index 000000000..fcb757b3e
--- /dev/null
+++ b/scripts/context/lua/mtx-server-ctx-startup.lua
@@ -0,0 +1,53 @@
+if not modules then modules = { } end modules ['mtx-server-ctx-startup'] = {
+ version = 1.001,
+ comment = "Overview Of Goodies",
+ author = "Hans Hagen",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+dofile(resolvers.find_file("trac-lmx.lua","tex"))
+
+function doit(configuration,filename,hashed)
+
+ lmx.restore()
+
+ lmx.variables['color-background-green'] = '#4F6F6F'
+ lmx.variables['color-background-blue'] = '#6F6F8F'
+ lmx.variables['color-background-yellow'] = '#8F8F6F'
+ lmx.variables['color-background-purple'] = '#8F6F8F'
+
+ lmx.variables['color-background-body'] = '#808080'
+ lmx.variables['color-background-main'] = '#3F3F3F'
+ lmx.variables['color-background-one'] = lmx.variables['color-background-green']
+ lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
+
+ lmx.variables['title'] = "Overview Of Goodies"
+
+ lmx.set('title', lmx.get('title'))
+ lmx.set('color-background-one', lmx.get('color-background-green'))
+ lmx.set('color-background-two', lmx.get('color-background-blue'))
+
+
+ local list = { }
+ local root = file.dirname(resolvers.find_file("mtx-server.lua") or ".")
+ if root == "" then root = "." end
+ local pattern = root .. "/mtx-server-ctx-*.lua"
+ local files = dir.glob(pattern)
+ for i=1,#files do
+ local filename = file.basename(files[i])
+ local name = string.match(filename,"mtx%-server%-ctx%-(.-)%.lua$")
+ if name and name ~= "startup" then
+ list[#list+1] = string.format("%s
",filename,name,name)
+ end
+ end
+
+ lmx.set('maintext',table.concat(list,"\n"))
+
+ result = { content = lmx.convert('context-base.lmx') }
+
+ return result
+
+end
+
+return doit, true
diff --git a/scripts/context/lua/mtx-server.lua b/scripts/context/lua/mtx-server.lua
index d9eb355f6..74f0ed924 100644
--- a/scripts/context/lua/mtx-server.lua
+++ b/scripts/context/lua/mtx-server.lua
@@ -9,9 +9,10 @@ if not modules then modules = { } end modules ['mtx-server'] = {
scripts = scripts or { }
scripts.webserver = scripts.webserver or { }
-dofile(input.find_file("l-url.lua"))
+dofile(resolvers.find_file("l-url.lua","tex"))
+dofile(resolvers.find_file("luat-soc.lua","tex"))
-local socket = require("socket")
+local socket = socket or require("socket") -- redundant in future version
local format = string.format
-- The following two lists are taken from webrick (ruby) and
@@ -126,13 +127,39 @@ local handlers = { }
local function errormessage(client,configuration,n)
local data = format("%s %s
%s %s
",n,messages[n],n,messages[n])
- input.report("handling error %s: %s",n,messages[n])
+ logs.simple("handling error %s: %s",n,messages[n])
handlers.generic(client,configuration,data,nil,true)
end
+local validpaths, registered = { }, { }
+
+function scripts.webserver.registerpath(name)
+ if not registered[name] then
+ local cleanname = string.gsub(name,"%.%.","deleted-parent")
+ logs.simple("registering path '%s'",cleanname)
+ validpaths[#validpaths+1] = cleanname
+ registered[name] = true
+ end
+end
+
function handlers.generic(client,configuration,data,suffix,iscontent)
if not iscontent then
- data = io.loaddata(file.join(configuration.root,data))
+ local name = data
+ logs.simple("requested file '%s'",name)
+ local fullname = file.join(configuration.root,name)
+ data = io.loaddata(fullname) or ""
+ if data == "" then
+ for n=1,#validpaths do
+ local fullname = file.join(validpaths[n],name)
+ data = io.loaddata(fullname) or ""
+ if data ~= "" then
+ logs.simple("sending generic file '%s'",fullname)
+ break
+ end
+ end
+ else
+ logs.simple("sending generic file '%s'",fullname)
+ end
end
if data and data ~= "" then
client:send("HTTP/1.1 200 OK\r\n")
@@ -155,21 +182,37 @@ end
--~ return { content = filename }
--~ end
+local loaded = { }
+
function handlers.lua(client,configuration,filename,suffix,iscontent,hashed) -- filename will disappear, and become hashed.filename
local filename = file.join(configuration.scripts,filename)
- if not input.aux.qualified_path(filename) then
+ if not file.is_qualified_path(filename) then
filename = file.join(configuration.root,filename)
end
-- todo: split url in components, see l-url; rather trivial
- input.report("locating script: %s",filename)
- if lfs.isfile(filename) then
- local result = loadfile(filename)
- input.report("return type: %s",type(result))
- if result and type(result) == "function" then
- -- result() should return a table { [type=,] [length=,] content= }, function or string
- result = result()
+ local result, keep = loaded[filename], false
+ if result then
+ logs.simple("reusing script: %s",filename)
+ else
+ logs.simple("locating script: %s",filename)
+ if lfs.isfile(filename) then
+ logs.simple("loading script: %s",filename)
+ result = loadfile(filename)
+ logs.simple("return type: %s",type(result))
+ if result and type(result) == "function" then
+ -- result() should return a table { [type=,] [length=,] content= }, function or string
+ result, keep = result()
+ if keep then
+ logs.simple("saving script: %s",type(result))
+ loaded[filename] = result
+ end
+ end
+ else
+ errormessage(client,configuration,404)
end
- if result and type(result) == "function" then
+ end
+ if result then
+ if type(result) == "function" then
result = result(configuration,filename,hashed) -- second argument will become query
end
if result and type(result) == "string" then
@@ -181,9 +224,9 @@ function handlers.lua(client,configuration,filename,suffix,iscontent,hashed) --
local action = handlers[suffix] or handlers.generic
action(client,configuration,result.content,suffix,true) -- content
elseif result.filename then
- local suffix = file.extname(filename) or "text/html"
+ local suffix = file.extname(result.filename) or "text/html"
local action = handlers[suffix] or handlers.generic
- action(client,configuration,filename,suffix,false) -- filename
+ action(client,configuration,result.filename,suffix,false) -- filename
else
errormessage(client,configuration,404)
end
@@ -198,18 +241,19 @@ end
handlers.luc = handlers.lua
handlers.html = handlers.htm
-local indices = { "index.htm", "index.html" }
+local indices = { "index.htm", "index.html" }
+local portnumber = 31415 -- pi suits tex
function scripts.webserver.run(configuration)
-- check configuration
- configuration.port = tonumber(configuration.port or os.getenv("MTX_SERVER_PORT") or 8080) or 8080
+ configuration.port = tonumber(configuration.port or os.getenv("MTX_SERVER_PORT") or portnumber) or portnumber
if not configuration.root or not lfs.isdir(configuration.root) then
configuration.root = os.getenv("MTX_SERVER_ROOT") or "."
end
-- locate root and index file in tex tree
if not lfs.isdir(configuration.root) then
for _, name in ipairs(indices) do
- local root = input.resolve("path:" .. name) or ""
+ local root = resolvers.resolve("path:" .. name) or ""
if root ~= "" then
configuration.root = root
configuration.index = configuration.index or name
@@ -217,6 +261,7 @@ function scripts.webserver.run(configuration)
end
end
end
+ configuration.root = dir.expand_name(configuration.root)
if not configuration.index then
for _, name in ipairs(indices) do
if lfs.isfile(file.join(configuration.root,name)) then
@@ -226,14 +271,17 @@ function scripts.webserver.run(configuration)
end
configuration.index = configuration.index or "unknown"
end
- configuration.scripts = configuration.scripts or "cgi"
+ if not configuration.scripts or configuration.scripts == "" then
+ configuration.scripts = dir.expand_name(file.join(configuration.root or ".",configuration.scripts or "."))
+ end
-- so far for checks
- input.report("running at port: %s",configuration.port)
- input.report("document root: %s",configuration.root)
- input.report("main index file: %s",configuration.index)
- input.report("scripts subpath: %s",configuration.scripts)
+ logs.simple("running at port: %s",configuration.port)
+ logs.simple("document root: %s",configuration.root or resolvers.ownpath)
+ logs.simple("main index file: %s",configuration.index)
+ logs.simple("scripts subpath: %s",configuration.scripts)
local server = assert(socket.bind("*", configuration.port))
while true do -- no multiple clients
+ local start = os.clock()
local client = server:accept()
client:settimeout(configuration.timeout or 60)
local request, e = client:receive()
@@ -241,26 +289,26 @@ function scripts.webserver.run(configuration)
errormessage(client,configuration,404)
else
local from = client:getpeername()
- input.report("request from: %s",tostring(from))
+ logs.simple("request from: %s",tostring(from))
local fullurl = request:match("GET (.+) HTTP/.*$") -- todo: more clever
-fullurl = socket.url.unescape(fullurl)
-local hashed = url.hashed(fullurl)
-local query = url.query(hashed.query)
-filename = hashed.path
+ fullurl = socket.url.unescape(fullurl)
+ local hashed = url.hashed(fullurl)
+ local query = url.query(hashed.query)
+ local filename = hashed.path
if filename then
filename = socket.url.unescape(filename)
- input.report("requested action: %s",filename)
+ logs.simple("requested action: %s",filename)
if filename:find("%.%.") then
filename = nil -- invalid path
end
if filename == nil or filename == "" or filename == "/" then
filename = configuration.index
- input.report("invalid filename, forcing: %s",filename)
+ logs.simple("invalid filename, forcing: %s",filename)
end
local suffix = file.extname(filename)
local action = handlers[suffix] or handlers.generic
if action then
- input.report("performing action: %s",filename)
+ logs.simple("performing action: %s",filename)
action(client,configuration,filename,suffix,false,hashed) -- filename and no content
else
errormessage(client,configuration,404)
@@ -270,10 +318,11 @@ filename = hashed.path
end
end
client:close()
+ logs.simple("time spent with client: %0.03f seconds",os.clock()-start)
end
end
-banner = banner .. " | webserver "
+logs.extendbanner("Simple Webserver 0.10")
messages.help = [[
--start start server
@@ -281,15 +330,26 @@ messages.help = [[
--root server root
--scripts scripts sub path
--index index file
+--auto start on own path
]]
-if environment.argument("start") then
+if environment.argument("auto") then
+ local path = resolvers.find_file("mtx-server.lua") or "."
scripts.webserver.run {
port = environment.argument("port"),
- root = environment.argument("root"), -- "e:/websites/www.pragma-ade.com",
+ root = environment.argument("root") or file.dirname(path) or ".",
+ scripts = environment.argument("scripts") or file.dirname(path) or ".",
+ }
+elseif environment.argument("start") then
+ scripts.webserver.run {
+ port = environment.argument("port"),
+ root = environment.argument("root") or ".", -- "e:/websites/www.pragma-ade.com",
index = environment.argument("index"),
- scripts = environment.argument("scripts") or "cgi",
+ scripts = environment.argument("scripts"),
}
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
+
+
+-- mtxrun --script server --start => http://localhost:8080/mtx-server-ctx-help.lua
diff --git a/scripts/context/lua/mtx-timing.lua b/scripts/context/lua/mtx-timing.lua
new file mode 100644
index 000000000..1dcb9aa0e
--- /dev/null
+++ b/scripts/context/lua/mtx-timing.lua
@@ -0,0 +1,201 @@
+if not modules then modules = { } end modules ['mtx-timing'] = {
+ version = 1.002,
+ comment = "companion to mtxrun.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, gsub, concat = string.format, string.gsub, table.concat
+
+dofile(resolvers.find_file("trac-tim.lua","tex"))
+dofile(resolvers.find_file("trac-lmx.lua","tex"))
+
+local meta = [[
+ beginfig(%s) ;
+ begingroup ;
+ save p, q, b, h, w ;
+ path p, q, b ; numeric h, w ;
+ linecap := butt ;
+ h := 100 ;
+ w := 800pt ;
+ p := %s ;
+ q := %s ;
+ p := p shifted -llcorner p ;
+ q := q shifted -llcorner q ;
+ q := q xstretched w ;
+ p := p xstretched w ;
+ b := boundingbox (llcorner p -- llcorner p shifted (w,h)) ;
+ draw b withcolor white withpen pencircle scaled 4pt ;
+ draw p withcolor red withpen pencircle scaled 4pt ;
+ draw q withcolor blue withpen pencircle scaled 2pt ;
+ endgroup ;
+ endfig ;
+]]
+
+local html_graphic = [[
+
+
+]]
+
+local html_menu = [[
+ %s
+]]
+
+local directrun = true
+
+function goodies.progress.make_svg(filename,other)
+ local metadata, menudata, c = { }, { }, 0
+ metadata[#metadata+1] = 'outputformat := "svg" ;'
+ for _, kind in pairs { "parameters", "nodes" } do
+ local mdk = { }
+ menudata[kind] = mdk
+ for n, name in pairs(goodies.progress[kind](filename)) do
+ local first = goodies.progress.path(filename,name)
+ local second = goodies.progress.path(filename,other)
+ c = c + 1
+ metadata[#metadata+1] = format(meta,c,first,second)
+ mdk[#mdk+1] = { name, c }
+ end
+ end
+ metadata[#metadata+1] = "end ."
+ metadata = concat(metadata,"\n\n")
+ if directrun then
+ dofile(resolvers.find_file("mlib-run.lua","tex"))
+ commands = commands or { }
+ commands.writestatus = logs.report
+ local result = metapost.directrun("metafun","timing data","svg",true,metadata)
+ return menudata, result
+ else
+ local mpname = file.replacesuffix(filename,"mp")
+ io.savedata(mpname,metadata)
+ os.execute(format("mpost --progname=context --mem=metafun.mem %s",mpname))
+ os.remove(mpname)
+ os.remove(file.removesuffix(filename).."-mpgraph.mpo") -- brr
+ os.remove(file.removesuffix(filename)..".log") -- brr
+ return menudata
+ end
+end
+
+function goodies.progress.makehtml(filename,other,menudata,metadata)
+ local graphics = { }
+ local result = { graphics = graphics }
+ for _, kind in pairs { "parameters", "nodes" } do
+ local md = menudata[kind]
+ local menu = { }
+ result[kind] = menu
+ for k, v in ipairs(md) do
+ local name, number = v[1], v[2]
+ local min = goodies.progress.bot(filename,name)
+ local max = goodies.progress.top(filename,name)
+ local pages = goodies.progress.pages(filename)
+ local average = math.round(max/pages)
+ if directrun then
+ local data = metadata[number]
+ menu[#menu+1] = format(html_menu,name,name)
+ graphics[#graphics+1] = format(html_graphic,name,name,other,data,min,max,pages,average)
+ else
+ local mpname = file.replacesuffix(filename,number)
+ local data = io.loaddata(mpname) or ""
+ -- data = gsub(data,"[\n\r]*","")
+ data = gsub(data,"<%?xml.->","")
+ menu[#menu+1] = format(html_menu,name,name)
+ graphics[#graphics+1] = format(html_graphic,name,name,other,data,min,max,pages,average)
+ os.remove(mpname)
+ end
+ end
+ end
+ return result
+end
+
+function goodies.progress.valid_file(name)
+ return name and name ~= "" and lfs.isfile(name .. "-luatex-progress.lut")
+end
+
+function goodies.progress.make_lmx_page(name,launch,remove)
+ local filename = name .. "-luatex-progress"
+ local other = "elapsed_time"
+ local template = 'context-timing.lmx'
+
+ lmx.variables['color-background-green'] = '#4F6F6F'
+ lmx.variables['color-background-blue'] = '#6F6F8F'
+ lmx.variables['color-background-yellow'] = '#8F8F6F'
+ lmx.variables['color-background-purple'] = '#8F6F8F'
+
+ lmx.variables['color-background-body'] = '#808080'
+ lmx.variables['color-background-main'] = '#3F3F3F'
+ lmx.variables['color-background-one'] = lmx.variables['color-background-green']
+ lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
+
+ lmx.variables['title-default'] = 'ConTeXt Timing Information'
+ lmx.variables['title'] = lmx.variables['title-default']
+
+ lmx.htmfile = function(name) return name .. "-timing.xhtml" end
+ lmx.lmxfile = function(name) return resolvers.find_file(name,'tex') end
+
+ lmx.set('title', format('ConTeXt Timing Information: %s',file.basename(name)))
+ lmx.set('color-background-one', lmx.get('color-background-green'))
+ lmx.set('color-background-two', lmx.get('color-background-blue'))
+
+ goodies.progress.convert(filename)
+
+ local menudata, metadata = goodies.progress.make_svg(filename,other)
+ local htmldata = goodies.progress.makehtml(filename,other,menudata,metadata)
+
+ lmx.set('parametersmenu', concat(htmldata.parameters, " "))
+ lmx.set('nodesmenu', concat(htmldata.nodes, " "))
+ lmx.set('graphics', concat(htmldata.graphics, "\n\n"))
+
+ if launch then
+ local htmfile = lmx.show(template)
+ if remove then
+ os.sleep(1) -- give time to launch
+ os.remove(htmfile)
+ end
+ else
+ lmx.make(template)
+ end
+
+ lmx.restore()
+end
+
+scripts = scripts or { }
+scripts.timings = scripts.timings or { }
+
+function scripts.timings.xhtml(filename)
+ if filename == "" then
+ logs.simple("provide filename")
+ elseif not goodies.progress.valid_file(filename) then
+ logs.simple("first run context again with the --timing option")
+ else
+ local basename = file.removesuffix(filename)
+ local launch = environment.argument("launch")
+ local remove = environment.argument("remove")
+ goodies.progress.make_lmx_page(basename,launch,remove)
+ end
+end
+
+logs.extendbanner("ConTeXt Timing Tools 0.1",true)
+
+messages.help = [[
+--xhtml make xhtml file
+--launch launch after conversion
+--remove remove after launching
+]]
+
+if environment.argument("xhtml") then
+ scripts.timings.xhtml(environment.files[1] or "")
+else
+ logs.help(messages.help)
+end
diff --git a/scripts/context/lua/mtx-unzip.lua b/scripts/context/lua/mtx-unzip.lua
new file mode 100644
index 000000000..f990f4210
--- /dev/null
+++ b/scripts/context/lua/mtx-unzip.lua
@@ -0,0 +1,101 @@
+-- maybe --pattern
+
+logs.extendbanner("Simple Unzipper 0.10")
+
+messages.help = [[
+--list list files in archive
+--junk flatten unzipped directory structure
+--extract extract files
+]]
+
+scripts = scripts or { }
+scripts.unzipper = scripts.unzipper or { }
+
+function scripts.unzipper.help()
+ logs.help(messages.help)
+end
+
+function scripts.unzipper.opened()
+ local filename = environment.files[1]
+ if filename and filename ~= "" then
+ filename = file.addsuffix(filename,'zip')
+ local zipfile = zip.open(filename)
+ if zipfile then
+ return zipfile
+ end
+ end
+ logs.report("unzip", "no zip file: " .. filename)
+ return false
+end
+
+function scripts.unzipper.list()
+ local zipfile = scripts.unzipper.opened()
+ if zipfile then
+ local n = 0
+ for k in zipfile:files() do
+ if #k.filename > n then n = #k.filename end
+ end
+ local files, paths, compressed, uncompressed = 0, 0, 0, 0
+ for k in zipfile:files() do
+ if k.filename:find("/$") then
+ paths = paths + 1
+ print(string.format("%s", k.filename:rpadd(n," ")))
+ else
+ files = files + 1
+ local cs, us = k.compressed_size, k.uncompressed_size
+ if cs > compressed then
+ compressed = cs
+ end
+ if us > uncompressed then
+ uncompressed = us
+ end
+ print(string.format("%s % 9i % 9i", k.filename:rpadd(n," "),cs,us))
+ end
+ end
+ print(string.format("\n%s % 9i % 9i", (files .. " files, " .. paths .. " directories"):rpadd(n," "),compressed,uncompressed))
+ end
+end
+
+function zip.loaddata(zipfile,filename)
+ local f = zipfile:open(filename)
+ if f then
+ local data = f:read("*a")
+ f:close()
+ return data
+ end
+ return nil
+end
+
+function scripts.unzipper.extract()
+ local zipfile = scripts.unzipper.opened()
+ if zipfile then
+ local junk = environment.arguments["j"] or environment.arguments["junk"]
+ for k in zipfile:files() do
+ local filename = k.filename
+ if filename:find("/$") then
+ if not junk then
+ lfs.mkdir(filename)
+ end
+ else
+ local data = zip.loaddata(zipfile,filename)
+ if data then
+ if junk then
+ filename = file.basename(filename)
+ end
+ io.savedata(filename,data)
+ print(filename)
+ end
+ end
+ end
+ end
+end
+
+if environment.arguments["h"] or environment.arguments["help"] then
+ scripts.unzipper.help()
+elseif environment.arguments["l"] or environment.arguments["list"] then
+ scripts.unzipper.list(zipfile)
+elseif environment.files[1] then -- implicit --extract
+ scripts.unzipper.extract(zipfile)
+else
+ scripts.unzipper.help()
+end
diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua
index b56780c68..66f6898d3 100644
--- a/scripts/context/lua/mtx-update.lua
+++ b/scripts/context/lua/mtx-update.lua
@@ -1,5 +1,5 @@
if not modules then modules = { } end modules ['mtx-update'] = {
- version = 1.001,
+ version = 1.002,
comment = "companion to mtxrun.lua",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
@@ -11,15 +11,20 @@ if not modules then modules = { } end modules ['mtx-update'] = {
-- Together with Arthur Reutenauer she made sure that it worked well on all
-- platforms that matter.
+local format, concat, gmatch = string.format, table.concat, string.gmatch
+
scripts = scripts or { }
scripts.update = scripts.update or { }
minimals = minimals or { }
minimals.config = minimals.config or { }
+-- this is needed under windows
+-- else rsync fails to set the right chmod flags to files
+
os.setenv("CYGWIN","nontsec")
-scripts.update.allformats = {
+scripts.update.texformats = {
"cont-en",
"cont-nl",
"cont-cz",
@@ -28,125 +33,105 @@ scripts.update.allformats = {
"cont-it",
"cont-ro",
"cont-uk",
- "metafun",
+ "cont-pe",
+ "cont-xp",
"mptopdf",
"plain"
}
-scripts.update.fewformats = {
- "cont-en",
- "cont-nl",
+scripts.update.mpformats = {
"metafun",
- "mptopdf",
- "plain"
+ "mpost",
}
+-- experimental is not functional at the moment
+
scripts.update.repositories = {
"current",
"experimental"
}
+-- more options than just these two are available (no idea why this is here)
+
scripts.update.versions = {
"current",
"latest"
}
+-- list of basic folders that are needed to make a functional distribution
+
+scripts.update.base = {
+ { "base/tex/", "texmf" },
+ { "base/metapost/", "texmf" },
+ { "fonts/common/", "texmf" },
+ { "fonts/other/", "texmf" }, -- not *really* needed, but helpful
+ { "context//", "texmf-context" },
+ { "context/img/", "texmf-context" },
+ { "misc/setuptex/", "." },
+ { "misc/web2c", "texmf" },
+ { "bin/common//", "texmf-" },
+ { "bin/context//", "texmf-" },
+ { "bin/metapost//", "texmf-" },
+ { "bin/man/", "texmf-" },
+}
+
+-- binaries and font-related files
+-- for pdftex we don't need OpenType fonts, for LuaTeX/XeTeX we don't need TFM files
+
scripts.update.engines = {
["luatex"] = {
- { "base/tex/", "texmf" },
- { "base/metapost/", "texmf" },
{ "fonts/new/", "texmf" },
- { "fonts/common/", "texmf" },
- { "fonts/other/", "texmf" },
- { "context//", "texmf-context" },
- { "context/img/", "texmf-context" },
- { "context/config/", "texmf-context" },
- { "misc/setuptex/", "." },
- { "misc/web2c", "texmf" },
- { "bin/common//", "texmf-" },
- { "bin/context//", "texmf-" },
- { "bin/metapost//", "texmf-" },
{ "bin/luatex//", "texmf-" },
- { "bin/man/", "texmf-" }
},
["xetex"] = {
- { "base/tex/", "texmf" },
- { "base/metapost/", "texmf" },
{ "base/xetex/", "texmf" },
{ "fonts/new/", "texmf" },
- { "fonts/common/", "texmf" },
- { "fonts/other/", "texmf" },
- { "context//", "texmf-context" },
- { "context/img/", "texmf-context" },
- { "context/config/", "texmf-context" },
- { "misc/setuptex/", "." },
- { "misc/web2c", "texmf" },
- { "bin/common//", "texmf-" },
- { "bin/context//", "texmf-" },
- { "bin/metapost//", "texmf-" },
{ "bin/xetex//", "texmf-" },
- { "bin/man/", "texmf-" }
},
["pdftex"] = {
- { "base/tex/", "texmf" },
- { "base/metapost/", "texmf" },
{ "fonts/old/", "texmf" },
- { "fonts/common/", "texmf" },
- { "fonts/other/", "texmf" },
- { "context//", "texmf-context" },
- { "context/img/", "texmf-context" },
- { "context/config/", "texmf-context" },
- { "misc/setuptex/", "." },
- { "misc/web2c", "texmf" },
- { "bin/common//", "texmf-" },
- { "bin/context//", "texmf-" },
- { "bin/metapost//", "texmf-" },
{ "bin/pdftex//", "texmf-" },
- { "bin/man/", "texmf-" }
},
["all"] = {
- { "base/tex/", "texmf" },
- { "base/metapost/", "texmf" },
- { "base/xetex/", "texmf" },
- { "fonts/old/", "texmf" },
{ "fonts/new/", "texmf" },
- { "fonts/common/", "texmf" },
- { "fonts/other/", "texmf" },
- { "context//", "texmf-context" },
- { "context/img/", "texmf-context" },
- { "context/config/", "texmf-context" },
- { "misc/setuptex/", "." },
- { "misc/web2c", "texmf" },
- { "bin/common//", "texmf-" },
- { "bin/context//", "texmf-" },
- { "bin/metapost//", "texmf-" },
+ { "fonts/old/", "texmf" },
+ { "base/xetex/", "texmf" },
{ "bin/luatex//", "texmf-" },
{ "bin/xetex//", "texmf-" },
{ "bin/pdftex//", "texmf-" },
- { "bin/man/", "texmf-" }
},
}
scripts.update.platforms = {
- ["mswin"] = "mswin",
- ["windows"] = "mswin",
- ["win32"] = "mswin",
- ["win"] = "mswin",
- ["linux"] = "linux",
- ["freebsd"] = "freebsd",
- ["linux-32"] = "linux",
- ["linux-64"] = "linux-64",
- ["linux32"] = "linux",
- ["linux64"] = "linux-64",
- ["linux-ppc"] = "linux-ppc",
- ["ppc"] = "linux-ppc",
- ["osx"] = "osx-intel",
- ["osx-intel"] = "osx-intel",
- ["osx-ppc"] = "osx-ppc",
- ["osx-powerpc"] = "osx-ppc",
- ["osxintel"] = "osx-intel",
- ["osxppc"] = "osx-ppc",
- ["osxpowerpc"] = "osx-ppc",
+ ["mswin"] = "mswin",
+ ["windows"] = "mswin",
+ ["win32"] = "mswin",
+ ["win"] = "mswin",
+ ["linux"] = "linux",
+ ["freebsd"] = "freebsd",
+ ["freebsd-amd64"] = "freebsd-amd64",
+ ["linux-32"] = "linux",
+ ["linux-64"] = "linux-64",
+ ["linux32"] = "linux",
+ ["linux64"] = "linux-64",
+ ["linux-ppc"] = "linux-ppc",
+ ["ppc"] = "linux-ppc",
+ ["osx"] = "osx-intel",
+ ["macosx"] = "osx-intel",
+ ["osx-intel"] = "osx-intel",
+ ["osx-ppc"] = "osx-ppc",
+ ["osx-powerpc"] = "osx-ppc",
+ ["osxintel"] = "osx-intel",
+ ["osxppc"] = "osx-ppc",
+ ["osxpowerpc"] = "osx-ppc",
+ ["solaris-intel"] = "solaris-intel",
+ ["solaris-sparc"] = "solaris-sparc",
+ ["solaris"] = "solaris-sparc",
+}
+
+-- the list is filled up later (when we know what modules to download)
+
+scripts.update.modules = {
}
function scripts.update.run(str)
@@ -160,7 +145,7 @@ function scripts.update.run(str)
end
function scripts.update.fullpath(path)
- if input.aux.rootbased_path(path) then
+ if file.is_rootbased_path(path) then
return path
else
return lfs.currentdir() .. "/" .. path
@@ -168,47 +153,138 @@ function scripts.update.fullpath(path)
end
function scripts.update.synchronize()
+
logs.report("update","start")
+
local texroot = scripts.update.fullpath(states.get("paths.root"))
- local engines = states.get('engines')
- local platforms = states.get('platforms')
- local repositories = states.get('repositories')
- local bin = states.get("rsync.program")
- local url = states.get("rsync.server")
- local version = states.get("context.version")
+ local engines = states.get('engines') or { }
+ local platforms = states.get('platforms') or { }
+ local repositories = states.get('repositories') -- minimals
+ local bin = states.get("rsync.program") -- rsync
+ local url = states.get("rsync.server") -- contextgarden.net
+ local version = states.get("context.version") -- current (or beta)
+ local extras = states.get("extras") -- extra goodies (like modules)
local force = environment.argument("force")
+
+ bin = string.gsub(bin,"\\","/")
+
if not url:find("::$") then url = url .. "::" end
local ok = lfs.attributes(texroot,"mode") == "directory"
if not ok and force then
dir.mkdirs(texroot)
ok = lfs.attributes(texroot,"mode") == "directory"
end
+
+ if force then
+ dir.mkdirs(format("%s/%s", texroot, "texmf-cache"))
+ dir.mkdirs(format("%s/%s", texroot, "texmf-local"))
+ end
+
if ok or not force then
- if force then
- dir.mkdirs(string.format("%s/%s", texroot, "texmf-cache"))
+
+ local fetched, individual, osplatform = { }, { }, os.currentplatform()
+
+ -- takes a collection as argument and returns a list of folders
+
+ local function collection_to_list_of_folders(collection, platform)
+ local archives = {}
+ for _, c in ipairs(collection) do
+ local archive = c[1]
+ archive = archive:gsub("", platform)
+ archive = archive:gsub("", version)
+ archives[#archives+1] = archive
+ end
+ return archives
end
- local fetched, individual = { }, { }
- for engine, _ in pairs(engines) do
- local collections = scripts.update.engines[engine]
- if collections then
- for _, collection in ipairs(collections) do
- for platform, _ in pairs(platforms) do
- platform = scripts.update.platforms[platform]
- if platform then
- local archive = collection[1]:gsub("", platform)
- local destination = string.format("%s/%s", texroot, collection[2]:gsub("", platform))
- destination = destination:gsub("\\","/")
- archive = archive:gsub("",version)
---~ if platform == "windows" or platform == "mswin" then
- if os.currentplatform() == "windows" or os.currentplatform() == "mswin" then
- destination = destination:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
- end
- individual[#individual+1] = { archive, destination }
+
+ -- takes a list of folders as argument and returns a string for rsync
+ -- sample input:
+ -- {'bin/common', 'bin/context'}
+ -- output:
+ -- 'minimals/current/bin/common minimals/current/bin/context'
+
+ local function list_of_folders_to_rsync_string(list_of_folders)
+ local repository = 'current'
+ local prefix = format("%s/%s/", states.get('rsync.module'), repository) -- minimals/current/
+
+ return prefix .. concat(list_of_folders, format(" %s", prefix))
+ end
+
+ -- example of usage: print(list_of_folders_to_rsync_string(collection_to_list_of_folders(scripts.update.base, os.currentplatform)))
+
+ -- rename function and add some more functionality:
+ -- * recursive/non-recursive (default: non-recursive)
+ -- * filter folders or regular files only (default: no filter)
+ -- * grep for size of included files (with --stats switch)
+
+ local function get_list_of_files_from_rsync(list_of_folders)
+ -- temporary file to store the output of rsync (could be a more random name; watch for overwrites)
+ local temp_file = "rsync.tmp.txt"
+ -- a set of folders
+ local folders = {}
+ local command = format("%s %s'%s' > %s", bin, url, list_of_folders_to_rsync_string(list_of_folders), temp_file)
+ os.execute(command)
+ -- read output of rsync
+ local data = io.loaddata(temp_file) or ""
+ -- for every line extract the filename
+ for chmod, s in data:gmatch("([d%-][rwx%-]+).-(%S+)[\n\r]") do
+ -- skip "current" folder
+ if s ~= '.' and chmod:len() == 10 then
+ folders[#folders+1] = s
+ end
+ end
+ -- delete the file to which we have put output of rsync
+ os.remove(temp_file)
+ return folders
+ end
+
+ -- rsync://contextgarden.net/minimals/current/modules/
+
+ if extras and type(extras) == "table" then
+ -- fetch the list of available modules from rsync server
+ local available_modules = get_list_of_files_from_rsync({"modules/"})
+ -- hash of requested modules
+ -- local h = table.tohash(extras:split(","))
+ for _, s in ipairs(available_modules) do
+ -- if extras == "all" or h[s] then
+ if extras.all or extras[s] then
+ scripts.update.modules[#scripts.update.modules+1] = { format("modules/%s/",s), "texmf-context" }
+ end
+ end
+ -- TODO: check if every module from the list has been added and issue warning otherwise
+ -- one idea to do it: remove every value from h once added and then check if anything is left in h
+ end
+
+ local function add_collection(collection,platform)
+ if collection and platform then
+ platform = scripts.update.platforms[platform]
+ if platform then
+ for _, c in ipairs(collection) do
+ local archive = c[1]:gsub("", platform)
+ local destination = format("%s/%s", texroot, c[2]:gsub("", platform))
+ destination = destination:gsub("\\","/")
+ archive = archive:gsub("",version)
+ if osplatform == "windows" or osplatform == "mswin" then
+ destination = destination:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
end
+ individual[#individual+1] = { archive, destination }
end
end
end
end
+
+ for platform, _ in pairs(platforms) do
+ add_collection(scripts.update.base,platform)
+ end
+ for platform, _ in pairs(platforms) do
+ add_collection(scripts.update.modules,platform)
+ end
+ for engine, _ in pairs(engines) do
+ for platform, _ in pairs(platforms) do
+ add_collection(scripts.update.engines[engine],platform)
+ end
+ end
+
local combined = { }
for _, repository in ipairs(scripts.update.repositories) do
if repositories[repository] then
@@ -219,11 +295,11 @@ function scripts.update.synchronize()
cd = { }
combined[destination] = cd
end
- cd[#cd+1] = string.format("%s/%s/%s",states.get('rsync.module'),repository,archive)
+ cd[#cd+1] = format("%s/%s/%s",states.get('rsync.module'),repository,archive)
end
end
end
- if input.verbose then
+ if logs.verbose then
for k, v in pairs(combined) do
logs.report("update", k)
for k,v in ipairs(v) do
@@ -232,24 +308,53 @@ function scripts.update.synchronize()
end
end
for destination, archive in pairs(combined) do
- local archives, command = table.concat(archive," "), ""
- local normalflags, deleteflags = states.get("rsync.flags.normal"), states.get("rsync.flags.delete")
- if true then -- environment.argument("keep") or destination:find("%.$") then
- command = string.format("%s %s %s'%s' '%s'", bin, normalflags, url, archives, destination)
- else
- command = string.format("%s %s %s %s'%s' '%s'", bin, normalflags, deleteflags, url, archives, destination)
+ local archives, command = concat(archive," "), ""
+ -- local normalflags, deleteflags = states.get("rsync.flags.normal"), states.get("rsync.flags.delete")
+ -- if environment.argument("keep") or destination:find("%.$") then
+ -- command = format("%s %s %s'%s' '%s'", bin, normalflags, url, archives, destination)
+ -- else
+ -- command = format("%s %s %s %s'%s' '%s'", bin, normalflags, deleteflags, url, archives, destination)
+ -- end
+ local normalflags, deleteflags = states.get("rsync.flags.normal"), ""
+ if (destination:find("texmf$") or destination:find("texmf%-context$")) and (not environment.argument("keep")) then
+ deleteflags = states.get("rsync.flags.delete")
end
- logs.report("mtx update", string.format("running command: %s",command))
+ command = format("%s %s %s %s'%s' '%s'", bin, normalflags, deleteflags, url, archives, destination)
+ logs.report("mtx update", format("running command: %s",command))
if not fetched[command] then
scripts.update.run(command)
fetched[command] = command
end
end
+
+ local function update_script(script, platform)
+ local bin = bin:gsub("\\","/")
+ local texroot = texroot:gsub("\\","/")
+ platform = scripts.update.platforms[platform]
+ if platform then
+ local command
+ if platform == 'mswin' then
+ bin = bin:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
+ texroot = texroot:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
+ command = string.format("%s -t %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-mswin/bin/", bin, texroot, script, texroot)
+ else
+ command = string.format("%s -tgo --chmod=a+x %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-%s/bin/%s", bin, texroot, script, texroot, platform, script)
+ end
+ logs.report("mtx update", format("updating %s for %s: %s", script, platform, command))
+ scripts.update.run(command)
+ end
+ end
+
+ for platform, _ in pairs(platforms) do
+ update_script('luatools',platform)
+ update_script('mtxrun',platform)
+ end
+
else
- logs.report("mtx update", string.format("no valid texroot: %s",texroot))
+ logs.report("mtx update", format("no valid texroot: %s",texroot))
end
if not force then
- logs.report("update", "use --force to really update")
+ logs.report("update", "use --force to really update files")
end
logs.report("update","done")
end
@@ -262,32 +367,59 @@ function table.fromhash(t)
return h
end
-
+-- make the ConTeXt formats
function scripts.update.make()
+
logs.report("make","start")
+
local force = environment.argument("force")
local texroot = scripts.update.fullpath(states.get("paths.root"))
- local engines = states.get('engines')
+ local engines= states.get('engines')
local platforms = states.get('platforms')
local formats = states.get('formats')
- input.load_tree(texroot)
+
+ resolvers.load_tree(texroot)
+ -- update filename database for pdftex/xetex
scripts.update.run("mktexlsr")
+ -- update filename database for luatex
scripts.update.run("luatools --generate")
- local formatlist = table.concat(table.fromhash(formats), " ")
+ local askedformats = formats
+ local texformats = table.tohash(scripts.update.texformats)
+ local mpformats = table.tohash(scripts.update.mpformats)
+ for k,v in pairs(texformats) do
+ if not askedformats[k] then
+ texformats[k] = nil
+ end
+ end
+ for k,v in pairs(mpformats) do
+ if not askedformats[k] then
+ mpformats[k] = nil
+ end
+ end
+ local formatlist = concat(table.fromhash(texformats), " ")
if formatlist ~= "" then
for engine in pairs(engines) do
- -- todo: just handle make here or in mtxrun --script context --make
---~ os.execute("set")
- scripts.update.run(string.format("texexec --make --all --fast --%s %s",engine,formatlist))
+ if engine == "luatex" then
+ scripts.update.run(format("context --make")) -- maybe also formatlist
+ else
+ -- todo: just handle make here or in mtxrun --script context --make
+ scripts.update.run(format("texexec --make --all --fast --%s %s",engine,formatlist))
+ end
end
end
+ local formatlist = concat(table.fromhash(mpformats), " ")
+ if formatlist ~= "" then
+ scripts.update.run(format("texexec --make --all --fast %s",formatlist))
+ end
if not force then
- logs.report("make", "use --force to really make")
+ logs.report("make", "use --force to really make formats")
end
+ scripts.update.run("mktexlsr")
+ scripts.update.run("luatools --generate")
logs.report("make","done")
end
-banner = banner .. " | download tools "
+logs.extendbanner("Download Tools 0.20",true)
messages.help = [[
--platform=string platform (windows, linux, linux-64, osx-intel, osx-ppc, linux-ppc)
@@ -296,8 +428,9 @@ messages.help = [[
--repository=string specify version (current, experimental)
--context=string specify version (current, latest, yyyy.mm.dd)
--rsync=string rsync binary (rsync)
---texroot installation directory (not guessed for the moment)
---engine tex engine (luatex, pdftex, xetex)
+--texroot=string installation directory (not guessed for the moment)
+--engine=string tex engine (luatex, pdftex, xetex)
+--extras=string extra modules (can be list or 'all')
--force instead of a dryrun, do the real thing
--update update minimal tree
--make also make formats and generate file databases
@@ -305,8 +438,6 @@ messages.help = [[
--state update tree using saved state
]]
-input.verbose = true
-
scripts.savestate = true
if scripts.savestate then
@@ -315,7 +446,7 @@ if scripts.savestate then
-- tag, value, default, persistent
- input.starttiming(states)
+ statistics.starttiming(states)
states.set("info.version",0.1) -- ok
states.set("info.count",(states.get("info.count") or 0) + 1,1,false) -- ok
@@ -333,11 +464,11 @@ if scripts.savestate then
states.set("context.version", environment.argument("context"), "current", true) -- ok
local valid = table.tohash(scripts.update.repositories)
- for r in string.gmatch(environment.argument("repository") or "current","([^, ]+)") do
+ for r in gmatch(environment.argument("repository") or "current","([^, ]+)") do
if valid[r] then states.set("repositories." .. r, true) end
end
local valid = scripts.update.engines
- for r in string.gmatch(environment.argument("engine") or "all","([^, ]+)") do
+ for r in gmatch(environment.argument("engine") or "all","([^, ]+)") do
if r == "all" then
for k, v in pairs(valid) do
if k ~= "all" then
@@ -349,12 +480,16 @@ if scripts.savestate then
end
end
local valid = scripts.update.platforms
- for r in string.gmatch(environment.argument("platform") or os.currentplatform(),"([^, ]+)") do
+ for r in gmatch(environment.argument("platform") or os.currentplatform(),"([^, ]+)") do
if valid[r] then states.set("platforms." .. r, true) end
end
- local valid = table.tohash(scripts.update.allformats)
- for r in string.gmatch(environment.argument("formats") or "","([^, ]+)") do
+ local valid = table.tohash(scripts.update.texformats)
+ for r in gmatch(environment.argument("formats") or "","([^, ]+)") do
+ if valid[r] then states.set("formats." .. r, true) end
+ end
+ local valid = table.tohash(scripts.update.mpformats)
+ for r in gmatch(environment.argument("formats") or "","([^, ]+)") do
if valid[r] then states.set("formats." .. r, true) end
end
@@ -362,7 +497,9 @@ if scripts.savestate then
states.set("formats.cont-nl", true)
states.set("formats.metafun", true)
- -- modules
+ for r in gmatch(environment.argument("extras") or "","([^, ]+)") do
+ states.set("extras." .. r, true)
+ end
logs.report("state","loaded")
@@ -382,12 +519,12 @@ if environment.argument("update") then
elseif environment.argument("make") then
scripts.update.make()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
if scripts.savestate then
- input.stoptiming(states)
- states.set("info.runtime",tonumber(input.elapsedtime(states)))
+ statistics.stoptiming(states)
+ states.set("info.runtime",tonumber(statistics.elapsedtime(states)))
if environment.argument("force") then
states.save()
logs.report("state","saved")
diff --git a/scripts/context/lua/mtx-watch.lua b/scripts/context/lua/mtx-watch.lua
index b7b6fb77b..2e4dcf6ef 100644
--- a/scripts/context/lua/mtx-watch.lua
+++ b/scripts/context/lua/mtx-watch.lua
@@ -58,6 +58,20 @@ do
end
end
end
+ local function toset(t)
+ if type(t) == "table" then
+ return table.concat(t,",")
+ else
+ return t
+ end
+ end
+ local function noset(t)
+ if type(t) == "table" then
+ return t[1]
+ else
+ return t
+ end
+ end
local function process()
local done = false
for _, path in ipairs(environment.files) do
@@ -77,8 +91,8 @@ do
local command = joblog.command
if command then
local replacements = {
- inputpath = (joblog.paths and joblog.paths.input ) or ".",
- outputpath = (joblog.paths and joblog.paths.output) or ".",
+ inputpath = toset((joblog.paths and joblog.paths.input ) or "."),
+ outputpath = noset((joblog.paths and joblog.paths.output) or "."),
filename = joblog.filename or "",
}
command = command:gsub("%%(.-)%%", replacements)
@@ -225,7 +239,7 @@ function scripts.watch.show_logs(path) -- removes duplicates
end
end
-banner = banner .. " | watchdog"
+logs.extendbanner("Watchdog 1.00",true)
messages.help = [[
--logpath optional path for log files
@@ -236,8 +250,6 @@ messages.help = [[
--showlog show log data
]]
-input.verbose = true
-
if environment.argument("watch") then
scripts.watch.watch()
elseif environment.argument("collect") then
@@ -245,5 +257,5 @@ elseif environment.argument("collect") then
elseif environment.argument("showlog") then
scripts.watch.show_logs()
else
- input.help(banner,messages.help)
+ logs.help(messages.help)
end
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 6c68ec51a..0af429bf1 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -8,6 +8,7 @@ if not modules then modules = { } end modules ['mtxrun'] = {
license = "see context related readme files"
}
+
-- one can make a stub:
--
-- #!/bin/sh
@@ -26,7 +27,7 @@ if not modules then modules = { } end modules ['mtxrun'] = {
-- one. Interesting is that using a scripting language instead of c does
-- not have a speed penalty. Actually the lua variant is more efficient,
-- especially when multiple calls to kpsewhich are involved. The lua
--- library also gives way more ocntrol.
+-- library also gives way more control.
-- to be done / considered
--
@@ -37,144 +38,42 @@ if not modules then modules = { } end modules ['mtxrun'] = {
-- remember for subruns: _CTX_K_S_#{original}_
-- remember for subruns: TEXMFSTART.#{original} [tex.rb texmfstart.rb]
-banner = "version 1.1.2 - 2007+ - PRAGMA ADE / CONTEXT" -- not local
texlua = true
-- begin library merge
--- filename : l-string.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-if not versions then versions = { } end versions['l-string'] = 1.001
---~ function string.split(str, pat) -- taken from the lua wiki
---~ local t = {n = 0} -- so this table has a length field, traverse with ipairs then!
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = string.find(str, fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ table.insert(t,cap)
---~ end
---~ last_end = e+1
---~ s, e, cap = string.find(str, fpat, last_end)
---~ end
---~ if last_end<=string.len(str) then
---~ table.insert(t,(string.sub(str,last_end)))
---~ end
---~ return t
---~ end
---~ function string:split(pat) -- taken from the lua wiki but adapted
---~ local t = { } -- self and colon usage (faster)
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = self:find(fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ t[#t+1] = cap
---~ end
---~ last_end = e+1
---~ s, e, cap = self:find(fpat, last_end)
---~ end
---~ if last_end <= #self then
---~ t[#t+1] = self:sub(last_end)
---~ end
---~ return t
---~ end
+do -- create closure to overcome 200 locals limit
---~ a piece of brilliant code by Rici Lake (posted on lua list) -- only names changed
---~
---~ function string:splitter(pat)
---~ local st, g = 1, self:gmatch("()"..pat.."()")
---~ local function splitter(self)
---~ if st then
---~ local s, f = g()
---~ local rv = self:sub(st, (s or 0)-1)
---~ st = f
---~ return rv
---~ end
---~ end
---~ return splitter, self
---~ end
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-function string:splitter(pat)
- -- by Rici Lake (posted on lua list) -- only names changed
- -- p 79 ref man: () returns position of match
- local st, g = 1, self:gmatch("()("..pat..")")
- local function strgetter(self, segs, seps, sep, cap1, ...)
- st = sep and seps + #sep
- return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
- end
- local function strsplitter(self)
- if st then return strgetter(self, st, g()) end
- end
- return strsplitter, self
-end
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
-function string:split(separator)
- local t = {}
- for k in self:splitter(separator) do t[#t+1] = k end
- return t
-end
+if not string.split then
--- faster than a string:split:
+ -- this will be overloaded by a faster lpeg variant
-function string:splitchr(chr)
- if #self > 0 then
- local t = { }
- for s in (self..chr):gmatch("(.-)"..chr) do
- t[#t+1] = s
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
end
- return t
- else
- return { }
end
-end
-function string.piecewise(str, pat, fnc) -- variant of split
- for k in string.splitter(str,pat) do fnc(k) end
end
---~ function string.piecewise(str, pat, fnc) -- variant of split
---~ for k in str:splitter(pat) do fnc(k) end
---~ end
-
---~ do if lpeg then
-
---~ -- this alternative is 30% faster esp when we cache them
---~ -- problem: no expressions
-
---~ splitters = { }
-
---~ function string:split(separator)
---~ if #self > 0 then
---~ local split = splitters[separator]
---~ if not split then
---~ -- based on code by Roberto
---~ local p = lpeg.P(separator)
---~ local c = lpeg.C((1-p)^0)
---~ split = lpeg.Ct(c*(p*c)^0)
---~ splitters[separator] = split
---~ end
---~ return split:match(self)
---~ else
---~ return { }
---~ end
---~ end
-
---~ string.splitchr = string.split
-
---~ function string:piecewise(separator,fnc)
---~ for _,v in pairs(self:split(separator)) do
---~ fnc(v)
---~ end
---~ end
-
---~ end end
-
local chr_to_esc = {
["%"] = "%%",
["."] = "%.",
@@ -188,20 +87,20 @@ local chr_to_esc = {
string.chr_to_esc = chr_to_esc
function string:esc() -- variant 2
- return (self:gsub("(.)",chr_to_esc))
+ return (gsub(self,"(.)",chr_to_esc))
end
function string:unquote()
- return (self:gsub("^([\"\'])(.*)%1$","%2"))
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
end
-function string:quote()
+function string:quote() -- we could use format("%q")
return '"' .. self:unquote() .. '"'
end
function string:count(pattern) -- variant 3
local n = 0
- for _ in self:gmatch(pattern) do
+ for _ in gmatch(self,pattern) do
n = n + 1
end
return n
@@ -210,29 +109,25 @@ end
function string:limit(n,sentinel)
if #self > n then
sentinel = sentinel or " ..."
- return self:sub(1,(n-#sentinel)) .. sentinel
+ return sub(self,1,(n-#sentinel)) .. sentinel
else
return self
end
end
function string:strip()
- return (self:gsub("^%s*(.-)%s*$", "%1"))
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
end
---~ function string.strip(str) -- slightly different
---~ return (string.gsub(string.gsub(str,"^%s*(.-)%s*$","%1"),"%s+"," "))
---~ end
-
function string:is_empty()
- return not self:find("%S")
+ return not find(find,"%S")
end
function string:enhance(pattern,action)
local ok, n = true, 0
while ok do
ok = false
- self = self:gsub(pattern, function(...)
+ self = gsub(self,pattern, function(...)
ok, n = true, n + 1
return action(...)
end)
@@ -240,59 +135,19 @@ function string:enhance(pattern,action)
return self, n
end
---~ function string:enhance(pattern,action)
---~ local ok, n = 0, 0
---~ repeat
---~ self, ok = self:gsub(pattern, function(...)
---~ n = n + 1
---~ return action(...)
---~ end)
---~ until ok == 0
---~ return self, n
---~ end
-
---~ function string:to_hex()
---~ if self then
---~ return (self:gsub("(.)",function(c)
---~ return string.format("%02X",c:byte())
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
---~ function string:from_hex()
---~ if self then
---~ return (self:gsub("(..)",function(c)
---~ return string.char(tonumber(c,16))
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
-string.chr_to_hex = { }
-string.hex_to_chr = { }
+local chr_to_hex, hex_to_chr = { }, { }
for i=0,255 do
- local c, h = string.char(i), string.format("%02X",i)
- string.chr_to_hex[c], string.hex_to_chr[h] = h, c
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
end
---~ function string:to_hex()
---~ if self then return (self:gsub("(.)",string.chr_to_hex)) else return "" end
---~ end
-
---~ function string:from_hex()
---~ if self then return (self:gsub("(..)",string.hex_to_chr)) else return "" end
---~ end
-
function string:to_hex()
- return ((self or ""):gsub("(.)",string.chr_to_hex))
+ return (gsub(self or "","(.)",chr_to_hex))
end
function string:from_hex()
- return ((self or ""):gsub("(..)",string.hex_to_chr))
+ return (gsub(self or "","(..)",hex_to_chr))
end
if not string.characters then
@@ -306,7 +161,7 @@ if not string.characters then
end
local function nextbyte(str, index)
index = index + 1
- return (index <= #str) and index or nil, string.byte(str:sub(index,index))
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
end
function string:bytes()
return nextbyte, self, 0
@@ -314,9 +169,7 @@ if not string.characters then
end
---~ function string:padd(n,chr)
---~ return self .. self.rep(chr or " ",n-#self)
---~ end
+-- we can use format for this (neg n)
function string:rpadd(n,chr)
local m = n-#self
@@ -338,8 +191,8 @@ end
string.padd = string.rpadd
-function is_number(str)
- return str:find("^[%-%+]?[%d]-%.?[%d+]$") == 1
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
end
--~ print(is_number("1"))
@@ -351,9 +204,9 @@ end
--~ print(is_number("+.1"))
function string:split_settings() -- no {} handling, see l-aux for lpeg variant
- if self:find("=") then
+ if find(self,"=") then
local t = { }
- for k,v in self:gmatch("(%a+)=([^%,]*)") do
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
t[k] = v
end
return t
@@ -375,24 +228,67 @@ local patterns_escapes = {
}
function string:pattesc()
- return (self:gsub(".",patterns_escapes))
+ return (gsub(self,".",patterns_escapes))
end
function string:tohash()
local t = { }
- for s in self:gmatch("([^, ]+)") do -- lpeg
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
t[s] = true
end
return t
end
+local pattern = lpeg.Ct(lpeg.C(1)^0)
--- filename : l-lpeg.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-lpeg'] = 1.001
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
--~ l-lpeg.lua :
@@ -416,36 +312,40 @@ if not versions then versions = { } end versions['l-lpeg'] = 1.001
local hash = { }
function lpeg.anywhere(pattern) --slightly adapted from website
- return lpeg.P { lpeg.P(pattern) + 1 * lpeg.V(1) }
+ return P { P(pattern) + 1 * lpeg.V(1) }
end
function lpeg.startswith(pattern) --slightly adapted
- return lpeg.P(pattern)
+ return P(pattern)
end
---~ g = lpeg.splitter(" ",function(s) ... end) -- gmatch:lpeg = 3:2
-
function lpeg.splitter(pattern, action)
- return (((1-lpeg.P(pattern))^1)/action+1)^0
+ return (((1-P(pattern))^1)/action+1)^0
end
-local crlf = lpeg.P("\r\n")
-local cr = lpeg.P("\r")
-local lf = lpeg.P("\n")
-local space = lpeg.S(" \t\f\v")
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
local newline = crlf + cr + lf
local spacing = space^0 * newline
-local empty = spacing * lpeg.Cc("")
-local nonempty = lpeg.Cs((1-spacing)^1) * spacing^-1
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
local content = (empty + nonempty)^1
-local capture = lpeg.Ct(content^0)
+local capture = Ct(content^0)
function string:splitlines()
return capture:match(self)
end
+lpeg.linebyline = content -- better make a sublibrary
+
--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
@@ -453,16 +353,16 @@ end
local splitters_s, splitters_m = { }, { }
-function lpeg.splitat(separator,single)
+local function splitat(separator,single)
local splitter = (single and splitters_s[separator]) or splitters_m[separator]
if not splitter then
- separator = lpeg.P(separator)
+ separator = P(separator)
if single then
- local other, any = lpeg.C((1 - separator)^0), lpeg.P(1)
- splitter = other * (separator * lpeg.C(any^0) + "")
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
splitters_s[separator] = splitter
else
- local other = lpeg.C((1 - separator)^0)
+ local other = C((1 - separator)^0)
splitter = other * (separator * other)^0
splitters_m[separator] = splitter
end
@@ -470,26 +370,43 @@ function lpeg.splitat(separator,single)
return splitter
end
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
--- filename : l-table.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-if not versions then versions = { } end versions['l-table'] = 1.001
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
table.join = table.concat
local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
-local format = string.format
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
local getmetatable, setmetatable = getmetatable, setmetatable
-local pairs, ipairs, type, next, tostring = pairs, ipairs, type, next, tostring
+local type, next, tostring, ipairs = type, next, tostring, ipairs
function table.strip(tab)
local lst = { }
for i=1,#tab do
- local s = tab[i]:gsub("^%s*(.-)%s*$","%1")
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
if s == "" then
-- skip this one
else
@@ -501,7 +418,7 @@ end
local function sortedkeys(tab)
local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
if kind == 3 then
-- no further check
@@ -528,7 +445,7 @@ end
local function sortedhashkeys(tab) -- fast one
local srt = { }
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
end
sort(srt)
@@ -538,14 +455,25 @@ end
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
function table.append(t, list)
- for _,v in pairs(list) do
+ for _,v in next, list do
insert(t,v)
end
end
function table.prepend(t, list)
- for k,v in pairs(list) do
+ for k,v in next, list do
insert(t,k,v)
end
end
@@ -554,7 +482,7 @@ function table.merge(t, ...) -- first one is target
t = t or {}
local lst = {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
t[k] = v
end
end
@@ -564,7 +492,7 @@ end
function table.merged(...)
local tmp, lst = { }, {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
tmp[k] = v
end
end
@@ -596,13 +524,14 @@ end
local function fastcopy(old) -- fast one
if old then
local new = { }
- for k,v in pairs(old) do
+ for k,v in next, old do
if type(v) == "table" then
new[k] = fastcopy(v) -- was just table.copy
else
new[k] = v
end
end
+ -- optional second arg
local mt = getmetatable(old)
if mt then
setmetatable(new,mt)
@@ -619,7 +548,7 @@ local function copy(t, tables) -- taken from lua wiki, slightly adapted
if not tables[t] then
tables[t] = tcopy
end
- for i,v in pairs(t) do -- brrr, what happens with sparse indexed
+ for i,v in next, t do -- brrr, what happens with sparse indexed
if type(i) == "table" then
if tables[i] then
i = tables[i]
@@ -652,7 +581,7 @@ function table.sub(t,i,j)
end
function table.replace(a,b)
- for k,v in pairs(b) do
+ for k,v in next, b do
a[k] = v
end
end
@@ -674,16 +603,18 @@ end
function table.tohash(t,value)
local h = { }
- if value == nil then value = true end
- for _, v in pairs(t) do -- no ipairs here
- h[v] = value
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
end
return h
end
function table.fromhash(t)
local h = { }
- for k, v in pairs(t) do -- no ipairs here
+ for k, v in next, t do -- no ipairs here
if v then h[#h+1] = k end
end
return h
@@ -707,24 +638,10 @@ local reserved = table.tohash { -- intercept a language flaw, no reserved words
'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
}
-local function key(k)
- if type(k) == "number" then -- or k:find("^%d+$") then
- if hexify then
- return ("[0x%04X]"):format(k)
- else
- return "["..k.."]"
- end
- elseif noquotes and not reserved[k] and k:find("^%a[%a%d%_]*$") then
- return k
- else
- return '["'..k..'"]'
- end
-end
-
local function simple_table(t)
if #t > 0 then
local n = 0
- for _,v in pairs(t) do
+ for _,v in next, t do
n = n + 1
end
if n == #t then
@@ -734,14 +651,14 @@ local function simple_table(t)
local tv = type(v)
if tv == "number" then
if hexify then
- tt[#tt+1] = ("0x%04X"):format(v)
+ tt[#tt+1] = format("0x%04X",v)
else
- tt[#tt+1] = tostring(v)
+ tt[#tt+1] = tostring(v) -- tostring not needed
end
elseif tv == "boolean" then
tt[#tt+1] = tostring(v)
elseif tv == "string" then
- tt[#tt+1] = ("%q"):format(v)
+ tt[#tt+1] = format("%q",v)
else
tt = nil
break
@@ -753,51 +670,72 @@ local function simple_table(t)
return nil
end
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
local function do_serialize(root,name,depth,level,indexed)
if level > 0 then
depth = depth .. " "
if indexed then
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
elseif name then
- handle(("%s%s={"):format(depth,key(name)))
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
else
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
end
end
if root and next(root) then
local first, last = nil, 0 -- #root cannot be trusted here
if compact then
- for k,v in ipairs(root) do -- NOT: for k=1,#root do (we need to quit at nil)
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
if not first then first = k end
last = last + 1
end
end
- --~ for _,k in pairs(sortedkeys(root)) do -- 1% faster:
local sk = sortedkeys(root)
for i=1,#sk do
local k = sk[i]
local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
local t = type(v)
if compact and first and type(k) == "number" and k >= first and k <= last then
if t == "number" then
if hexify then
- handle(("%s 0x%04X,"):format(depth,v))
+ handle(format("%s 0x%04X,",depth,v))
else
- handle(("%s %s,"):format(depth,v))
+ handle(format("%s %s,",depth,v))
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s,"):format(depth,v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
else
- handle(("%s %q,"):format(depth,v))
+ handle(format("%s %q,",depth,v))
end
elseif t == "table" then
if not next(v) then
- handle(("%s {},"):format(depth))
- elseif inline then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
local st = simple_table(v)
if st then
- handle(("%s { %s },"):format(depth,concat(st,", ")))
+ handle(format("%s { %s },",depth,concat(st,", ")))
else
do_serialize(v,k,depth,level+1,true)
end
@@ -805,39 +743,102 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1,true)
end
elseif t == "boolean" then
- handle(("%s %s,"):format(depth,tostring(v)))
+ handle(format("%s %s,",depth,tostring(v)))
elseif t == "function" then
if functions then
- handle(('%s loadstring(%q),'):format(depth,v:dump()))
+ handle(format('%s loadstring(%q),',depth,dump(v)))
else
- handle(('%s "function",'):format(depth))
+ handle(format('%s "function",',depth))
end
else
- handle(("%s %q,"):format(depth,tostring(v)))
+ handle(format("%s %q,",depth,tostring(v)))
end
elseif k == "__p__" then -- parent
if false then
- handle(("%s __p__=nil,"):format(depth))
+ handle(format("%s __p__=nil,",depth))
end
elseif t == "number" then
- if hexify then
- handle(("%s %s=0x%04X,"):format(depth,key(k),v))
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%q,"):format(depth,key(k),v))
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
end
elseif t == "table" then
if not next(v) then
- handle(("%s %s={},"):format(depth,key(k)))
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
elseif inline then
local st = simple_table(v)
if st then
- handle(("%s %s={ %s },"):format(depth,key(k),concat(st,", ")))
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
else
do_serialize(v,k,depth,level+1)
end
@@ -845,24 +846,58 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1)
end
elseif t == "boolean" then
- handle(("%s %s=%s,"):format(depth,key(k),tostring(v)))
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
elseif t == "function" then
if functions then
- handle(('%s %s=loadstring(%q),'):format(depth,key(k),v:dump()))
- else
- handle(('%s %s="function",'):format(depth,key(k)))
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
end
else
- handle(("%s %s=%q,"):format(depth,key(k),tostring(v)))
- -- handle(('%s %s=loadstring(%q),'):format(depth,key(k),string.dump(function() return v end)))
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
end
+ --~ end
end
end
if level > 0 then
- handle(("%s},"):format(depth))
+ handle(format("%s},",depth))
end
end
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
noquotes = _noquotes
hexify = _hexify
@@ -880,7 +915,7 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
end
elseif tname == "number" then
if hexify then
- handle(("[0x%04X]={"):format(name))
+ handle(format("[0x%04X]={",name))
else
handle("[" .. name .. "]={")
end
@@ -1031,14 +1066,18 @@ function table.insert_after_value(t,value,str)
end
end
-function table.are_equal(a,b,n,m)
+local function are_equal(a,b,n,m) -- indexed
if #a == #b then
n = n or 1
m = m or #a
for i=n,m do
local ai, bi = a[i], b[i]
- if (ai==bi) or (type(ai)=="table" and type(bi)=="table" and table.are_equal(ai,bi)) then
- -- continue
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
else
return false
end
@@ -1049,9 +1088,30 @@ function table.are_equal(a,b,n,m)
end
end
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
function table.compact(t)
if t then
- for k,v in pairs(t) do
+ for k,v in next, t do
if not next(v) then
t[k] = nil
end
@@ -1080,7 +1140,7 @@ end
function table.swapped(t)
local s = { }
- for k, v in pairs(t) do
+ for k, v in next, t do
s[v] = k
end
return s
@@ -1102,14 +1162,14 @@ end
function table.hexed(t,seperator)
local tt = { }
- for i=1,#t do tt[i] = ("0x%04X"):format(t[i]) end
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
return concat(tt,seperator or " ")
end
function table.reverse_hash(h)
local r = { }
- for k,v in pairs(h) do
- r[v] = (k:gsub(" ","")):lower()
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
end
return r
end
@@ -1124,14 +1184,36 @@ function table.reverse(t)
return tt
end
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
--- filename : l-io.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-io'] = 1.001
+local byte = string.byte
if string.find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator = "\\", ";"
@@ -1139,8 +1221,8 @@ else
io.fileseparator, io.pathseparator = "/" , ":"
end
-function io.loaddata(filename)
- local f = io.open(filename,'rb')
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
if f then
local data = f:read('*all')
-- garbagecollector.check(data)
@@ -1198,146 +1280,83 @@ function io.noflines(f)
return n
end
-do
-
- local sb = string.byte
-
- local nextchar = {
- [ 4] = function(f)
- return f:read(1,1,1,1)
- end,
- [ 2] = function(f)
- return f:read(1,1)
- end,
- [ 1] = function(f)
- return f:read(1)
- end,
- [-2] = function(f)
- local a, b = f:read(1,1)
- return b, a
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- return d, c, b, a
- end
- }
-
- function io.characters(f,n)
- if f then
- return nextchar[n or 1], f
- else
- return nil, nil
- end
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
end
+}
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
end
-do
-
- local sb = string.byte
-
---~ local nextbyte = {
---~ [4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(a), sb(b), sb(c), sb(d)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end,
---~ [2] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(a), sb(b)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [1] = function (f)
---~ local a = f:read(1)
---~ if a then
---~ return sb(a)
---~ else
---~ return nil
---~ end
---~ end,
---~ [-2] = function (f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(b), sb(a)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [-4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(d), sb(c), sb(b), sb(a)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end
---~ }
-
- local nextbyte = {
- [4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(a), sb(b), sb(c), sb(d)
- else
- return nil, nil, nil, nil
- end
- end,
- [2] = function(f)
- local a, b = f:read(1,1)
- if b then
- return sb(a), sb(b)
- else
- return nil, nil
- end
- end,
- [1] = function (f)
- local a = f:read(1)
- if a then
- return sb(a)
- else
- return nil
- end
- end,
- [-2] = function (f)
- local a, b = f:read(1,1)
- if b then
- return sb(b), sb(a)
- else
- return nil, nil
- end
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(d), sb(c), sb(b), sb(a)
- else
- return nil, nil, nil, nil
- end
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
end
- }
-
- function io.bytes(f,n)
- if f then
- return nextbyte[n or 1], f
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
else
return nil, nil
end
- end
-
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
+ else
+ return nil, nil
+ end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
+ end
+}
+
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
end
function io.ask(question,default,options)
@@ -1373,35 +1392,21 @@ function io.ask(question,default,options)
end
--- filename : l-md5.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-md5'] = 1.001
-
-if md5 then do
-
- local function convert(str,fmt)
- return (string.gsub(md5.sum(str),".",function(chr) return string.format(fmt,string.byte(chr)) end))
- end
-
- if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
- if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
- if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+end -- of closure
-end end
+do -- create closure to overcome 200 locals limit
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
--- filename : l-number.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-number'] = 1.001
+local format = string.format
-if not number then number = { } end
+number = number or { }
-- a,b,c,d,e,f = number.toset(100101)
@@ -1409,8 +1414,6 @@ function number.toset(n)
return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
end
-local format = string.format
-
function number.toevenhex(n)
local s = format("%X",n)
if #s % 2 == 0 then
@@ -1431,72 +1434,72 @@ end
--
-- of course dedicated "(.)(.)(.)(.)" matches are even faster
-do
- local one = lpeg.C(1-lpeg.S(''))^1
+local one = lpeg.C(1-lpeg.S(''))^1
- function number.toset(n)
- return one:match(tostring(n))
- end
+function number.toset(n)
+ return one:match(tostring(n))
end
--- filename : l-set.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-if not versions then versions = { } end versions['l-set'] = 1.001
+end -- of closure
-if not set then set = { } end
+do -- create closure to overcome 200 locals limit
-do
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
- local nums = { }
- local tabs = { }
- local concat = table.concat
+set = set or { }
- set.create = table.tohash
+local nums = { }
+local tabs = { }
+local concat = table.concat
- function set.tonumber(t)
- if next(t) then
- local s = ""
- -- we could save mem by sorting, but it slows down
- for k, v in pairs(t) do
- if v then
- -- why bother about the leading space
- s = s .. " " .. k
- end
- end
- if not nums[s] then
- tabs[#tabs+1] = t
- nums[s] = #tabs
+set.create = table.tohash
+
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
end
- return nums[s]
- else
- return 0
end
- end
-
- function set.totable(n)
- if n == 0 then
- return { }
- else
- return tabs[n] or { }
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
end
+ return nums[s]
+ else
+ return 0
end
+end
- function set.contains(n,s)
- if type(n) == "table" then
- return n[s]
- elseif n == 0 then
- return false
- else
- local t = tabs[n]
- return t and t[s]
- end
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
end
+end
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
end
--~ local c = set.create{'aap','noot','mies'}
@@ -1513,16 +1516,19 @@ end
--- filename : l-os.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
+do -- create closure to overcome 200 locals limit
---~ print(table.serialize(os.uname()))
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-os'] = 1.001
+local find = string.find
function os.resultof(command)
return io.popen(command,"r"):read("*all")
@@ -1535,7 +1541,7 @@ if not os.spawn then os.spawn = os.execute end
--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
if not io.fileseparator then
- if string.find(os.getenv("PATH"),";") then
+ if find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
else
io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
@@ -1573,11 +1579,10 @@ end
os.gettimeofday = os.gettimeofday or os.clock
-do
- local startuptime = os.gettimeofday()
- function os.runtime()
- return os.gettimeofday() - startuptime
- end
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
end
--~ print(os.gettimeofday()-os.time())
@@ -1586,27 +1591,92 @@ end
--~ print(os.date("%H:%M:%S",os.gettimeofday()))
--~ print(os.date("%H:%M:%S",os.time()))
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
--- filename : l-file.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-file'] = 1.001
+-- needs a cleanup
-if not file then file = { } end
+file = file or { }
local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
function file.removesuffix(filename)
- return (filename:gsub("%.[%a%d]+$",""))
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-file.stripsuffix = file.removesuffix
-
function file.addsuffix(filename, suffix)
- if not filename:find("%.[%a%d]+$") then
+ if not find(filename,"%.[%a%d]+$") then
return filename .. "." .. suffix
else
return filename
@@ -1614,23 +1684,23 @@ function file.addsuffix(filename, suffix)
end
function file.replacesuffix(filename, suffix)
- return (filename:gsub("%.[%a%d]+$","")) .. "." .. suffix
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
end
-function file.dirname(name)
- return name:match("^(.+)[/\\].-$") or ""
+function file.dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
function file.basename(name)
- return name:match("^.+[/\\](.-)$") or name
+ return match(name,"^.+[/\\](.-)$") or name
end
function file.nameonly(name)
- return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$",""))
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
function file.extname(name)
- return name:match("^.+%.([^/\\]-)$") or ""
+ return match(name,"^.+%.([^/\\]-)$") or ""
end
file.suffix = file.extname
@@ -1643,40 +1713,20 @@ file.suffix = file.extname
function file.join(...)
local pth = concat({...},"/")
- pth = pth:gsub("\\","/")
- local a, b = pth:match("^(.*://)(.*)$")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
+ return a .. gsub(b,"//+","/")
end
- a, b = pth:match("^(//)(.*)$")
+ a, b = match(pth,"^(//)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
- end
- return (pth:gsub("//+","/"))
-end
-
-function file.is_writable(name)
- local f = io.open(name, 'w')
- if f then
- f:close()
- return true
- else
- return false
- end
-end
-
-function file.is_readable(name)
- local f = io.open(name,'r')
- if f then
- f:close()
- return true
- else
- return false
+ return a .. gsub(b,"//+","/")
end
+ return (gsub(pth,"//+","/"))
end
function file.iswritable(name)
- local a = lfs.attributes(name)
+ local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
return a and a.permissions:sub(2,2) == "w"
end
@@ -1685,24 +1735,18 @@ function file.isreadable(name)
return a and a.permissions:sub(1,1) == "r"
end
---~ function file.split_path(str)
---~ if str:find(';') then
---~ return str:splitchr(";")
---~ else
---~ return str:splitchr(io.pathseparator)
---~ end
---~ end
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
-- todo: lpeg
function file.split_path(str)
local t = { }
- str = str:gsub("\\", "/")
- str = str:gsub("(%a):([;/])", "%1\001%2")
- for name in str:gmatch("([^;:]+)") do
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
if name ~= "" then
- name = name:gsub("\001",":")
- t[#t+1] = name
+ t[#t+1] = gsub(name,"\001",":")
end
end
return t
@@ -1713,15 +1757,15 @@ function file.join_path(tab)
end
function file.collapse_path(str)
- str = str:gsub("/%./","/")
+ str = gsub(str,"/%./","/")
local n, m = 1, 1
while n > 0 or m > 0 do
- str, n = str:gsub("[^/%.]+/%.%.$","")
- str, m = str:gsub("[^/%.]+/%.%./","")
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
end
- str = str:gsub("([^/])/$","%1")
- str = str:gsub("^%./","")
- str = str:gsub("/%.$","")
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
if str == "" then str = "." end
return str
end
@@ -1734,7 +1778,7 @@ end
--~ print(file.collapse_path("a/b/c/../.."))
function file.robustname(str)
- return (str:gsub("[^%a%d%/%-%.\\]+","-"))
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
end
file.readdata = io.loaddata
@@ -1764,8 +1808,6 @@ end
--~ return pattern:match(name)
--~ end
---~ file.stripsuffix = file.removesuffix
-
--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
--~ function file.basename(name)
@@ -1819,7 +1861,6 @@ end
--~ end
--~ local test = file.extname
---~ local test = file.stripsuffix
--~ local test = file.basename
--~ local test = file.dirname
--~ local test = file.addsuffix
@@ -1836,206 +1877,307 @@ end
--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+-- also rewrite previous
--- filename : l-dir.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
-if not versions then versions = { } end versions['l-dir'] = 1.001
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
-dir = { }
+-- ./name ../name /name c: :// name/name
--- optimizing for no string.find (*) does not save time
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
-if lfs then do
- local attributes = lfs.attributes
- local walkdir = lfs.dir
+end -- of closure
- local function glob_pattern(path,patt,recurse,action)
- local ok, scanner
- if path == "/" then
- ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
- else
- ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEX(data)
end
- if ok and type(scanner) == "function" then
- if not path:find("/$") then path = path .. '/' end
- for name in scanner do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if full:find(patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- glob_pattern(full,patt,recurse,action)
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type = type
+local find, gmatch = string.find, string.gmatch
+
+dir = dir or { }
+
+-- optimizing for no string.find (*) does not save time
+
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
end
end
end
+end
- dir.glob_pattern = glob_pattern
+dir.glob_pattern = glob_pattern
- local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
- local pattern = Ct {
- [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
- [2] = C(((1-S("*?/"))^0 * P("/"))^0),
- [3] = C(P(1)^0)
- }
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
- local filter = Cs ( (
- P("**") / ".*" +
- P("*") / "[^/]*" +
- P("?") / "[^/]" +
- P(".") / "%%." +
- P("+") / "%%+" +
- P("-") / "%%-" +
- P(1)
- )^0 )
-
- local function glob(str,t)
- if type(str) == "table" then
- local t = t or { }
- for _, s in ipairs(str) do
- glob(s,t)
- end
- return t
- elseif lfs.isfile(str) then
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
local t = t or { }
- t[#t+1] = str
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
return t
else
- local split = pattern:match(str)
- if split then
- local t = t or { }
- local action = action or function(name) t[#t+1] = name end
- local root, path, base = split[1], split[2], split[3]
- local recurse = base:find("%*%*")
- local start = root .. path
- local result = filter:match(start .. base)
- glob_pattern(start,result,recurse,action)
- return t
- else
- return { }
- end
+ return { }
end
end
+end
- dir.glob = glob
+dir.glob = glob
- --~ list = dir.glob("**/*.tif")
- --~ list = dir.glob("/**/*.tif")
- --~ list = dir.glob("./**/*.tif")
- --~ list = dir.glob("oeps/**/*.tif")
- --~ list = dir.glob("/oeps/**/*.tif")
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
- local function globfiles(path,recurse,func,files) -- func == pattern or function
- if type(func) == "string" then
- local s = func -- alas, we need this indirect way
- func = function(name) return name:find(s) end
- end
- files = files or { }
- for name in walkdir(path) do
- if name:find("^%.") then
- --- skip
- else
- local mode = attributes(name,'mode')
- if mode == "directory" then
- if recurse then
- globfiles(path .. "/" .. name,recurse,func,files)
- end
- elseif mode == "file" then
- if func then
- if func(name) then
- files[#files+1] = path .. "/" .. name
- end
- else
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
files[#files+1] = path .. "/" .. name
end
+ else
+ files[#files+1] = path .. "/" .. name
end
end
end
- return files
end
+ return files
+end
- dir.globfiles = globfiles
+dir.globfiles = globfiles
- -- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
- -- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
- -- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
- -- t = dir.glob("f:/minimal/tex/**/*")
- -- print(dir.ls("f:/minimal/tex/**/*"))
- -- print(dir.ls("*.tex"))
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
- function dir.ls(pattern)
- return table.concat(glob(pattern),"\n")
- end
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
- --~ mkdirs("temp")
- --~ mkdirs("a/b/c")
- --~ mkdirs(".","/a/b/c")
- --~ mkdirs("a","b","c")
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
- local make_indeed = true -- false
+local make_indeed = true -- false
- if string.find(os.getenv("PATH"),";") then
+if string.find(os.getenv("PATH"),";") then
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- local first, middle, last
- local drive = false
- first, middle, last = str:match("^(//)(//*)(.*)$")
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
if first then
- -- empty network path == local path
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
else
- first, last = str:match("^(//)/*(.-)$")
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
if first then
- middle, last = str:match("([^/]+)/+(.-)$")
- if middle then
- pth = "//" .. middle
- else
- pth = "//" .. last
- last = ""
- end
+ pth, drive = first .. middle, true
else
- first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
- if first then
- pth, drive = first .. middle, true
- else
- middle, last = str:match("^(/*)(.-)$")
- if not middle then
- last = str
- end
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
end
end
end
- for s in last:gmatch("[^/]+") do
- if pth == "" then
- pth = s
- elseif drive then
- pth, drive = pth .. s, false
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -2049,79 +2191,79 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- local first, nothing, last = str:match("^(//)(//*)(.*)$")
- if first then
- first = lfs.currentdir() .. "/"
- first = first:gsub("\\","/")
- end
- if not first then
- first, last = str:match("^(//)/*(.*)$")
- end
- if not first then
- first, last = str:match("^([a-zA-Z]:)(.*)$")
- if first and not last:find("^/") then
- local d = lfs.currentdir()
- if lfs.chdir(first) then
- first = lfs.currentdir()
- first = first:gsub("\\","/")
- end
- lfs.chdir(d)
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
end
+ lfs.chdir(d)
end
- if not first then
- first, last = lfs.currentdir(), str
- first = first:gsub("\\","/")
- end
- last = last:gsub("//","/")
- last = last:gsub("/%./","/")
- last = last:gsub("^/*","")
- first = first:gsub("/*$","")
- if last == "" then
- return first
- else
- return first .. "/" .. last
- end
end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
- else
+else
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- str = str:gsub("/+","/")
- if str:find("^/") then
- pth = "/"
- for s in str:gmatch("[^/]+") do
- local first = (pth == "/")
- if first then
- pth = pth .. s
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not first and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
- end
- else
- pth = "."
- for s in str:gmatch("[^/]+") do
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
pth = pth .. "/" .. s
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -2131,30 +2273,35 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- if not str:find("^/") then
- str = lfs.currentdir() .. "/" .. str
- end
- str = str:gsub("//","/")
- str = str:gsub("/%./","/")
- return str
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
end
-
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
end
- dir.makedirs = dir.mkdirs
+end
-end end
+dir.makedirs = dir.mkdirs
--- filename : l-boolean.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
-if not versions then versions = { } end versions['l-boolean'] = 1.001
-if not boolean then boolean = { } end
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
function boolean.tonumber(b)
if b then return 1 else return 0 end
@@ -2201,15 +2348,19 @@ function boolean.falsetrue()
end
--- filename : l-math.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
-if not versions then versions = { } end versions['l-math'] = 1.001
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-local floor = math.floor
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
if not math.round then
function math.round(x)
@@ -2229,23 +2380,213 @@ if not math.mod then
end
end
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
-if not modules then modules = { } end modules ['l-xml'] = {
+if not modules then modules = { } end modules ['l-utils'] = {
version = 1.001,
- comment = "this module is the basis for the lxml-* ones",
+ comment = "companion to luat-lib.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
--- RJ: key=value ... lpeg.Ca(lpeg.Cc({}) * (pattern-producing-key-and-value / rawset)^0)
+-- hm, quite unreadable
+
+if not utils then utils = { } end
+if not utils.merger then utils.merger = { } end
+if not utils.lua then utils.lua = { } end
+
+utils.merger.m_begin = "begin library merge"
+utils.merger.m_end = "end library merge"
+utils.merger.pattern =
+ "%c+" ..
+ "%-%-%s+" .. utils.merger.m_begin ..
+ "%c+(.-)%c+" ..
+ "%-%-%s+" .. utils.merger.m_end ..
+ "%c+"
+
+function utils.merger._self_fake_()
+ return
+ "-- " .. "created merged file" .. "\n\n" ..
+ "-- " .. utils.merger.m_begin .. "\n\n" ..
+ "-- " .. utils.merger.m_end .. "\n\n"
+end
+
+function utils.report(...)
+ print(...)
+end
+
+utils.merger.strip_comment = true
+
+function utils.merger._self_load_(name)
+ local f, data = io.open(name), ""
+ if f then
+ utils.report("reading merge from %s",name)
+ data = f:read("*all")
+ f:close()
+ else
+ utils.report("unknown file to merge %s",name)
+ end
+ if data and utils.merger.strip_comment then
+ -- saves some 20K
+ data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
+ end
+ return data or ""
+end
+
+function utils.merger._self_save_(name, data)
+ if data ~= "" then
+ local f = io.open(name,'w')
+ if f then
+ utils.report("saving merge from %s",name)
+ f:write(data)
+ f:close()
+ end
+ end
+end
+
+function utils.merger._self_swap_(data,code)
+ if data ~= "" then
+ return (data:gsub(utils.merger.pattern, function(s)
+ return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
+ end, 1))
+ else
+ return ""
+ end
+end
+
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
+function utils.merger._self_libs_(libs,list)
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
+ if type(libs) == 'string' then libs = { libs } end
+ if type(list) == 'string' then list = { list } end
+ local foundpath = nil
+ for _, lib in ipairs(libs) do
+ for _, pth in ipairs(list) do
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
+ else
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
+ end
+ end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
+ end
+ return table.concat(result, "\n\n")
+end
+
+function utils.merger.selfcreate(libs,list,target)
+ if target then
+ utils.merger._self_save_(
+ target,
+ utils.merger._self_swap_(
+ utils.merger._self_fake_(),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+ end
+end
+
+function utils.merger.selfmerge(name,libs,list,target)
+ utils.merger._self_save_(
+ target or name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+end
+
+function utils.merger.selfclean(name)
+ utils.merger._self_save_(
+ name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ ""
+ )
+ )
+end
+
+function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
+ -- utils.report("compiling",luafile,"into",lucfile)
+ os.remove(lucfile)
+ local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
+ if strip ~= false then
+ command = "-s " .. command
+ end
+ local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
+ if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
+ -- utils.report("removing",luafile)
+ os.remove(luafile)
+ end
+ return done
+end
+
+
+
+end -- of closure
--- some code may move to l-xmlext
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-tab'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
--[[ldx--
The parser used here is inspired by the variant discussed in the lua book, but
handles comment and processing instructions, has a different structure, provides
-parent access; a first version used different tricky but was less optimized to we
+parent access; a first version used different trickery but was less optimized to we
went this route. First we had a find based parser, now we have an based one.
The find based parser can be found in l-xml-edu.lua along with other older code.
@@ -2267,17 +2608,30 @@ optimize the code.
--ldx]]--
xml = xml or { }
-tex = tex or { }
-xml.trace_lpath = false
-xml.trace_print = false
-xml.trace_remap = false
+--~ local xml = xml
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, setmetatable = type, next, setmetatable
+local format, lower, find = string.format, string.lower, string.find
-local format, concat, remove, insert, type, next = string.format, table.concat, table.remove, table.insert, type, next
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers.
+--ldx]]--
---~ local pairs, next, type = pairs, next, type
+local trace_remap = false
+
+if trackers then
+ trackers.register("xml.remap", function(v) trace_remap = v end)
+end
--- todo: some things per xml file, like namespace remapping
+function xml.settrace(str,value)
+ if str == "remap" then
+ trace_remap = value or false
+ end
+end
--[[ldx--
First a hack to enable namespace resolving. A namespace is characterized by
@@ -2289,64 +2643,60 @@ much cleaner.
xml.xmlns = xml.xmlns or { }
-do
+local check = lpeg.P(false)
+local parse = check
- local check = lpeg.P(false)
- local parse = check
-
- --[[ldx--
-
The next function associates a namespace prefix with an . This
- normally happens independent of parsing.
+--[[ldx--
+
The next function associates a namespace prefix with an . This
+normally happens independent of parsing.
-
- xml.registerns("mml","mathml")
-
- --ldx]]--
+
+xml.registerns("mml","mathml")
+
+--ldx]]--
- function xml.registerns(namespace, pattern) -- pattern can be an lpeg
- check = check + lpeg.C(lpeg.P(pattern:lower())) / namespace
- parse = lpeg.P { lpeg.P(check) + 1 * lpeg.V(1) }
- end
+function xml.registerns(namespace, pattern) -- pattern can be an lpeg
+ check = check + lpeg.C(lpeg.P(lower(pattern))) / namespace
+ parse = lpeg.P { lpeg.P(check) + 1 * lpeg.V(1) }
+end
- --[[ldx--
-
The next function also registers a namespace, but this time we map a
- given namespace prefix onto a registered one, using the given
- . This used for attributes like xmlns:m.
+--[[ldx--
+
The next function also registers a namespace, but this time we map a
+given namespace prefix onto a registered one, using the given
+. This used for attributes like xmlns:m.
-
- xml.checkns("m","http://www.w3.org/mathml")
-
- --ldx]]--
+
+xml.checkns("m","http://www.w3.org/mathml")
+
+--ldx]]--
- function xml.checkns(namespace,url)
- local ns = parse:match(url:lower())
- if ns and namespace ~= ns then
- xml.xmlns[namespace] = ns
- end
+function xml.checkns(namespace,url)
+ local ns = parse:match(lower(url))
+ if ns and namespace ~= ns then
+ xml.xmlns[namespace] = ns
end
+end
- --[[ldx--
-
Next we provide a way to turn an into a registered
- namespace. This used for the xmlns attribute.
Next we provide a way to turn an into a registered
+namespace. This used for the xmlns attribute.
- function xml.resolvens(url)
- return parse:match(url:lower()) or ""
- end
+
+resolvedns = xml.resolvens("http://www.w3.org/mathml")
+
- --[[ldx--
-
A namespace in an element can be remapped onto the registered
- one efficiently by using the xml.xmlns table.
- --ldx]]--
+This returns mml.
+--ldx]]--
+function xml.resolvens(url)
+ return parse:match(lower(url)) or ""
end
+--[[ldx--
+
A namespace in an element can be remapped onto the registered
+one efficiently by using the xml.xmlns table.
+--ldx]]--
+
--[[ldx--
This version uses . We follow the same approach as before, stack and top and
such. This version is about twice as fast which is mostly due to the fact that
@@ -2382,247 +2732,253 @@ element.
xml.strip_cm_and_dt = false -- an extra global flag, in case we have many includes
-do
+-- not just one big nested table capture (lpeg overflow)
- -- not just one big nested table capture (lpeg overflow)
+local nsremap, resolvens = xml.xmlns, xml.resolvens
- local nsremap, resolvens = xml.xmlns, xml.resolvens
+local stack, top, dt, at, xmlns, errorstr, entities = {}, {}, {}, {}, {}, nil, {}
- local stack, top, dt, at, xmlns, errorstr, entities = {}, {}, {}, {}, {}, nil, {}
+local mt = { __tostring = xml.text }
- local mt = { __tostring = xml.text }
+function xml.check_error(top,toclose)
+ return ""
+end
- function xml.check_error(top,toclose)
- return ""
- end
+local strip = false
+local cleanup = false
- local strip = false
- local cleanup = false
+function xml.set_text_cleanup(fnc)
+ cleanup = fnc
+end
- function xml.set_text_cleanup(fnc)
- cleanup = fnc
+local function add_attribute(namespace,tag,value)
+ if cleanup and #value > 0 then
+ value = cleanup(value) -- new
+ end
+ if tag == "xmlns" then
+ xmlns[#xmlns+1] = resolvens(value)
+ at[tag] = value
+ elseif namespace == "xmlns" then
+ xml.checkns(tag,value)
+ at["xmlns:" .. tag] = value
+ else
+ at[tag] = value
end
+end
- local function add_attribute(namespace,tag,value)
- if tag == "xmlns" then
- xmlns[#xmlns+1] = resolvens(value)
- at[tag] = value
- elseif namespace == "xmlns" then
- xml.checkns(tag,value)
- at["xmlns:" .. tag] = value
- else
- at[tag] = value
- end
- end
- local function add_begin(spacing, namespace, tag)
- if #spacing > 0 then
- dt[#dt+1] = spacing
- end
- local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
- top = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = stack[#stack] }
- setmetatable(top, mt)
- dt = top.dt
- stack[#stack+1] = top
- at = { }
- end
- local function add_end(spacing, namespace, tag)
- if #spacing > 0 then
- dt[#dt+1] = spacing
- end
- local toclose = remove(stack)
- top = stack[#stack]
- if #stack < 1 then
- errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "")
- elseif toclose.tg ~= tag then -- no namespace check
- errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "")
- end
- dt = top.dt
- dt[#dt+1] = toclose
- if toclose.at.xmlns then
- remove(xmlns)
- end
- end
- local function add_empty(spacing, namespace, tag)
- if #spacing > 0 then
- dt[#dt+1] = spacing
- end
- local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
- top = stack[#stack]
- dt = top.dt
- local t = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = top }
- dt[#dt+1] = t
- setmetatable(t, mt)
- if at.xmlns then
- remove(xmlns)
- end
- at = { }
- end
- local function add_text(text)
- if cleanup and #text > 0 then
- dt[#dt+1] = cleanup(text)
- else
- dt[#dt+1] = text
- end
+local function add_begin(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
end
- local function add_special(what, spacing, text)
- if #spacing > 0 then
- dt[#dt+1] = spacing
- end
- if strip and (what == "@cm@" or what == "@dt@") then
- -- forget it
- else
- dt[#dt+1] = { special=true, ns="", tg=what, dt={text} }
- end
- end
- local function set_message(txt)
- errorstr = "garbage at the end of the file: " .. txt:gsub("([ \n\r\t]*)","")
- end
-
- local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
-
- local space = S(' \r\n\t')
- local open = P('<')
- local close = P('>')
- local squote = S("'")
- local dquote = S('"')
- local equal = P('=')
- local slash = P('/')
- local colon = P(':')
- local valid = R('az', 'AZ', '09') + S('_-.')
- local name_yes = C(valid^1) * colon * C(valid^1)
- local name_nop = C(P(true)) * C(valid^1)
- local name = name_yes + name_nop
-
- local utfbom = P('\000\000\254\255') + P('\255\254\000\000') +
- P('\255\254') + P('\254\255') + P('\239\187\191') -- no capture
-
- local spacing = C(space^0)
- local justtext = C((1-open)^1)
- local somespace = space^1
- local optionalspace = space^0
-
- local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
- local attribute = (somespace * name * optionalspace * equal * optionalspace * value) / add_attribute
- local attributes = attribute^0
-
- local text = justtext / add_text
- local balanced = P { "[" * ((1 - S"[]") + V(1))^0 * "]" } -- taken from lpeg manual, () example
-
- local emptyelement = (spacing * open * name * attributes * optionalspace * slash * close) / add_empty
- local beginelement = (spacing * open * name * attributes * optionalspace * close) / add_begin
- local endelement = (spacing * open * slash * name * optionalspace * close) / add_end
-
- local begincomment = open * P("!--")
- local endcomment = P("--") * close
- local begininstruction = open * P("?")
- local endinstruction = P("?") * close
- local begincdata = open * P("![CDATA[")
- local endcdata = P("]]") * close
-
- local someinstruction = C((1 - endinstruction)^0)
- local somecomment = C((1 - endcomment )^0)
- local somecdata = C((1 - endcdata )^0)
-
- function entity(k,v) entities[k] = v end
-
- local begindoctype = open * P("!DOCTYPE")
- local enddoctype = close
- local beginset = P("[")
- local endset = P("]")
- local doctypename = C((1-somespace)^0)
- local elementdoctype = optionalspace * P(" 0 then
+ dt[#dt+1] = spacing
end
+ local toclose = remove(stack)
+ top = stack[#stack]
+ if #stack < 1 then
+ errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "")
+ elseif toclose.tg ~= tag then -- no namespace check
+ errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "")
+ end
+ dt = top.dt
+ dt[#dt+1] = toclose
+ dt[0] = top
+ if toclose.at.xmlns then
+ remove(xmlns)
+ end
+end
- --[[ldx--
-
Packaging data in an xml like table is done with the following
- function. Maybe it will go away (when not used).
- --ldx]]--
+local function add_empty(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = stack[#stack]
+ dt = top.dt
+ local t = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = top }
+ dt[#dt+1] = t
+ setmetatable(t, mt)
+ if at.xmlns then
+ remove(xmlns)
+ end
+ at = { }
+end
- function xml.is_valid(root)
- return root and root.dt and root.dt[1] and type(root.dt[1]) == "table" and not root.dt[1].er
+local function add_text(text)
+ if cleanup and #text > 0 then
+ dt[#dt+1] = cleanup(text)
+ else
+ dt[#dt+1] = text
end
+end
- function xml.package(tag,attributes,data)
- local ns, tg = tag:match("^(.-):?([^:]+)$")
- local t = { ns = ns, tg = tg, dt = data or "", at = attributes or {} }
- setmetatable(t, mt)
- return t
+local function add_special(what, spacing, text)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
end
+ if strip and (what == "@cm@" or what == "@dt@") then
+ -- forget it
+ else
+ dt[#dt+1] = { special=true, ns="", tg=what, dt={text} }
+ end
+end
+
+local function set_message(txt)
+ errorstr = "garbage at the end of the file: " .. gsub(txt,"([ \n\r\t]*)","")
+end
+
+local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
+
+local space = S(' \r\n\t')
+local open = P('<')
+local close = P('>')
+local squote = S("'")
+local dquote = S('"')
+local equal = P('=')
+local slash = P('/')
+local colon = P(':')
+local valid = R('az', 'AZ', '09') + S('_-.')
+local name_yes = C(valid^1) * colon * C(valid^1)
+local name_nop = C(P(true)) * C(valid^1)
+local name = name_yes + name_nop
+
+local utfbom = P('\000\000\254\255') + P('\255\254\000\000') +
+ P('\255\254') + P('\254\255') + P('\239\187\191') -- no capture
+
+local spacing = C(space^0)
+local justtext = C((1-open)^1)
+local somespace = space^1
+local optionalspace = space^0
+
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local attribute = (somespace * name * optionalspace * equal * optionalspace * value) / add_attribute
+local attributes = attribute^0
+
+local text = justtext / add_text
+local balanced = P { "[" * ((1 - S"[]") + V(1))^0 * "]" } -- taken from lpeg manual, () example
+
+local emptyelement = (spacing * open * name * attributes * optionalspace * slash * close) / add_empty
+local beginelement = (spacing * open * name * attributes * optionalspace * close) / add_begin
+local endelement = (spacing * open * slash * name * optionalspace * close) / add_end
+
+local begincomment = open * P("!--")
+local endcomment = P("--") * close
+local begininstruction = open * P("?")
+local endinstruction = P("?") * close
+local begincdata = open * P("![CDATA[")
+local endcdata = P("]]") * close
+
+local someinstruction = C((1 - endinstruction)^0)
+local somecomment = C((1 - endcomment )^0)
+local somecdata = C((1 - endcdata )^0)
+
+local function entity(k,v) entities[k] = v end
+
+local begindoctype = open * P("!DOCTYPE")
+local enddoctype = close
+local beginset = P("[")
+local endset = P("]")
+local doctypename = C((1-somespace)^0)
+local elementdoctype = optionalspace * P("Packaging data in an xml like table is done with the following
+function. Maybe it will go away (when not used).
+--ldx]]--
+
+function xml.is_valid(root)
+ return root and root.dt and root.dt[1] and type(root.dt[1]) == "table" and not root.dt[1].er
+end
- xml.error_handler = (logs and logs.report) or (input and input.report) or print
+function xml.package(tag,attributes,data)
+ local ns, tg = tag:match("^(.-):?([^:]+)$")
+ local t = { ns = ns, tg = tg, dt = data or "", at = attributes or {} }
+ setmetatable(t, mt)
+ return t
+end
+function xml.is_valid(root)
+ return root and not root.error
end
+xml.error_handler = (logs and logs.report) or (input and logs.report) or print
+
--[[ldx--
We cannot load an from a filehandle so we need to load
the whole file first. The function accepts a string representing
@@ -2666,32 +3022,28 @@ generic table copier. Since we know what we're dealing with we
can speed up things a bit. The second argument is not to be used!
--ldx]]--
-do
-
- function copy(old,tables)
- if old then
- tables = tables or { }
- local new = { }
- if not tables[old] then
- tables[old] = new
- end
- for k,v in pairs(old) do
- new[k] = (type(v) == "table" and (tables[v] or copy(v, tables))) or v
- end
- local mt = getmetatable(old)
- if mt then
- setmetatable(new,mt)
- end
- return new
- else
- return { }
+function copy(old,tables)
+ if old then
+ tables = tables or { }
+ local new = { }
+ if not tables[old] then
+ tables[old] = new
+ end
+ for k,v in pairs(old) do
+ new[k] = (type(v) == "table" and (tables[v] or copy(v, tables))) or v
+ end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
end
+ return new
+ else
+ return { }
end
-
- xml.copy = copy
-
end
+xml.copy = copy
+
--[[ldx--
In serializing the tree or parts of the tree is a major
actitivity which is why the following function is pretty optimized resulting
@@ -2700,207 +3052,204 @@ function for all components is about 15% slower than the concatinating
alternative.
--ldx]]--
-do
-
- -- todo: add when not present
-
- local fallbackhandle = (tex and tex.sprint) or io.write
-
- local function serialize(e, handle, textconverter, attributeconverter, specialconverter, nocommands)
- if not e then
- return
- elseif not nocommands then
- local ec = e.command
- if ec ~= nil then -- we can have all kind of types
- if e.special then
- local etg, edt = e.tg, e.dt
- local spc = specialconverter and specialconverter[etg]
- if spc then
- local result = spc(edt[1])
- if result then
- handle(result)
- return
- else
- -- no need to handle any further
- end
- end
- end
- local xc = xml.command
- if xc then
- xc(e,ec)
- return
- end
- end
- end
- handle = handle or fallbackhandle
- local etg = e.tg
- if etg then
+-- todo: add when not present
+
+local fallbackhandle = (tex and tex.sprint) or io.write
+
+local function serialize(e, handle, textconverter, attributeconverter, specialconverter, nocommands)
+ if not e then
+ return
+ elseif not nocommands then
+ local ec = e.command
+ if ec ~= nil then -- we can have all kind of types
if e.special then
- local edt = e.dt
+ local etg, edt = e.tg, e.dt
local spc = specialconverter and specialconverter[etg]
if spc then
local result = spc(edt[1])
if result then
handle(result)
+ return
else
-- no need to handle any further
end
- elseif etg == "@pi@" then
- -- handle(format("%s?>",edt[1]))
- handle("" .. edt[1] .. "?>")
- elseif etg == "@cm@" then
- -- handle(format("",edt[1]))
- handle("")
- elseif etg == "@cd@" then
- -- handle(format("",edt[1]))
- handle("")
- elseif etg == "@dt@" then
- -- handle(format("",edt[1]))
- handle("")
- elseif etg == "@rt@" then
- serialize(edt,handle,textconverter,attributeconverter,specialconverter,nocommands)
end
- else
- local ens, eat, edt, ern = e.ns, e.at, e.dt, e.rn
- local ats = eat and next(eat) and { } -- type test maybe faster
- if ats then
- if attributeconverter then
- for k,v in pairs(eat) do
- ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
- end
- else
- for k,v in pairs(eat) do
- ats[#ats+1] = format('%s=%q',k,v)
- end
- end
+ end
+ local xc = xml.command
+ if xc then
+ xc(e,ec)
+ return
+ end
+ end
+ end
+ handle = handle or fallbackhandle
+ local etg = e.tg
+ if etg then
+ if e.special then
+ local edt = e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ else
+ -- no need to handle any further
end
- if ern and xml.trace_remap and ern ~= ens then
- ens = ern
+ elseif etg == "@pi@" then
+ -- handle(format("%s?>",edt[1]))
+ handle("" .. edt[1] .. "?>")
+ elseif etg == "@cm@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@cd@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@dt@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@rt@" then
+ serialize(edt,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ else
+ local ens, eat, edt, ern = e.ns, e.at, e.dt, e.rn
+ local ats = eat and next(eat) and { } -- type test maybe faster
+ if ats then
+ if attributeconverter then
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
+ end
+ else
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,v)
+ end
end
- if ens ~= "" then
- if edt and #edt > 0 then
- if ats then
- -- handle(format("<%s:%s %s>",ens,etg,concat(ats," ")))
- handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. ">")
- else
- -- handle(format("<%s:%s>",ens,etg))
- handle("<" .. ens .. ":" .. etg .. ">")
- end
- for i=1,#edt do
- local e = edt[i]
- if type(e) == "string" then
- if textconverter then
- handle(textconverter(e))
- else
- handle(e)
- end
+ end
+ if ern and trace_remap and ern ~= ens then
+ ens = ern
+ end
+ if ens ~= "" then
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s:%s %s>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s:%s>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
else
- serialize(e,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ handle(e)
end
- end
- -- handle(format("%s:%s>",ens,etg))
- handle("" .. ens .. ":" .. etg .. ">")
- else
- if ats then
- -- handle(format("<%s:%s %s/>",ens,etg,concat(ats," ")))
- handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. "/>")
else
- -- handle(format("<%s:%s/>",ens,etg))
- handle("<" .. ens .. ":" .. etg .. "/>")
+ serialize(e,handle,textconverter,attributeconverter,specialconverter,nocommands)
end
end
+ -- handle(format("%s:%s>",ens,etg))
+ handle("" .. ens .. ":" .. etg .. ">")
else
- if edt and #edt > 0 then
- if ats then
- -- handle(format("<%s %s>",etg,concat(ats," ")))
- handle("<" .. etg .. " " .. concat(ats," ") .. ">")
- else
- -- handle(format("<%s>",etg))
- handle("<" .. etg .. ">")
- end
- for i=1,#edt do
- local ei = edt[i]
- if type(ei) == "string" then
- if textconverter then
- handle(textconverter(ei))
- else
- handle(ei)
- end
+ if ats then
+ -- handle(format("<%s:%s %s/>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s:%s/>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. "/>")
+ end
+ end
+ else
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s %s>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s>",etg))
+ handle("<" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local ei = edt[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
else
- serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ handle(ei)
end
- end
- -- handle(format("%s>",etg))
- handle("" .. etg .. ">")
- else
- if ats then
- -- handle(format("<%s %s/>",etg,concat(ats," ")))
- handle("<" .. etg .. " " .. concat(ats," ") .. "/>")
else
- -- handle(format("<%s/>",etg))
- handle("<" .. etg .. "/>")
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
end
end
+ -- handle(format("%s>",etg))
+ handle("" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s %s/>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s/>",etg))
+ handle("<" .. etg .. "/>")
+ end
end
end
- elseif type(e) == "string" then
- if textconverter then
- handle(textconverter(e))
- else
- handle(e)
- end
+ end
+ elseif type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
else
- for i=1,#e do
- local ei = e[i]
- if type(ei) == "string" then
- if textconverter then
- handle(textconverter(ei))
- else
- handle(ei)
- end
+ handle(e)
+ end
+ else
+ for i=1,#e do
+ local ei = e[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
else
- serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ handle(ei)
end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
end
end
end
+end
- xml.serialize = serialize
+xml.serialize = serialize
- function xml.checkbom(root) -- can be made faster
- if root.ri then
- local dt, found = root.dt, false
- for k,v in ipairs(dt) do
- if type(v) == "table" and v.special and v.tg == "@pi" and v.dt:find("xml.*version=") then
- found = true
- break
- end
- end
- if not found then
- insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } )
- insert(dt, 2, "\n" )
+function xml.checkbom(root) -- can be made faster
+ if root.ri then
+ local dt, found = root.dt, false
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "table" and v.special and v.tg == "@pi" and find(v.dt,"xml.*version=") then
+ found = true
+ break
end
end
+ if not found then
+ insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } )
+ insert(dt, 2, "\n" )
+ end
end
+end
- --[[ldx--
-
At the cost of some 25% runtime overhead you can first convert the tree to a string
- and then handle the lot.
- --ldx]]--
+--[[ldx--
+
At the cost of some 25% runtime overhead you can first convert the tree to a string
+and then handle the lot.
+--ldx]]--
- function xml.tostring(root) -- 25% overhead due to collecting
- if root then
- if type(root) == 'string' then
- return root
- elseif next(root) then -- next is faster than type (and >0 test)
- local result = { }
- serialize(root,function(s) result[#result+1] = s end)
- return concat(result,"")
- end
+function xml.tostring(root) -- 25% overhead due to collecting
+ if root then
+ if type(root) == 'string' then
+ return root
+ elseif next(root) then -- next is faster than type (and >0 test)
+ local result = { }
+ serialize(root,function(s) result[#result+1] = s end)
+ return concat(result,"")
end
- return ""
end
-
+ return ""
end
--[[ldx--
@@ -3010,355 +3359,394 @@ function xml.assign(dt,k,root)
end
end
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-pth'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, lower, gmatch, gsub, find = string.format, string.lower, string.gmatch, string.gsub, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers. Here we overload a previously defined
+function.
+--ldx]]--
+
+local trace_lpath = false
+
+if trackers then
+ trackers.register("xml.lpath", function(v) trace_lpath = v end)
+end
+
+local settrace = xml.settrace -- lxml-tab
+
+function xml.settrace(str,value)
+ if str == "lpath" then
+ trace_lpath = value or false
+ else
+ settrace(str,value) -- lxml-tab
+ end
+end
+
--[[ldx--
We've now arrived at an intersting part: accessing the tree using a subset
of and since we're not compatible we call it . We
will explain more about its usage in other documents.
--ldx]]--
-local lpathcalls = 0 -- statisctics
-local lpathcached = 0 -- statisctics
-
-do
-
- xml.functions = xml.functions or { }
- xml.expressions = xml.expressions or { }
-
- local functions = xml.functions
- local expressions = xml.expressions
-
- local actions = {
- [10] = "stay",
- [11] = "parent",
- [12] = "subtree root",
- [13] = "document root",
- [14] = "any",
- [15] = "many",
- [16] = "initial",
- [20] = "match",
- [21] = "match one of",
- [22] = "match and attribute eq",
- [23] = "match and attribute ne",
- [24] = "match one of and attribute eq",
- [25] = "match one of and attribute ne",
- [27] = "has attribute",
- [28] = "has value",
- [29] = "fast match",
- [30] = "select",
- [31] = "expression",
- [40] = "processing instruction",
- }
+local lpathcalls = 0 -- statistics
+local lpathcached = 0 -- statistics
+
+xml.functions = xml.functions or { }
+xml.expressions = xml.expressions or { }
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+local actions = {
+ [10] = "stay",
+ [11] = "parent",
+ [12] = "subtree root",
+ [13] = "document root",
+ [14] = "any",
+ [15] = "many",
+ [16] = "initial",
+ [20] = "match",
+ [21] = "match one of",
+ [22] = "match and attribute eq",
+ [23] = "match and attribute ne",
+ [24] = "match one of and attribute eq",
+ [25] = "match one of and attribute ne",
+ [27] = "has attribute",
+ [28] = "has value",
+ [29] = "fast match",
+ [30] = "select",
+ [31] = "expression",
+ [40] = "processing instruction",
+}
- -- a rather dumb lpeg
+-- a rather dumb lpeg
- local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
- -- instead of using functions we just parse a few names which saves a call
- -- later on
+-- instead of using functions we just parse a few names which saves a call
+-- later on
- local lp_position = P("position()") / "ps"
- local lp_index = P("index()") / "id"
- local lp_text = P("text()") / "tx"
- local lp_name = P("name()") / "(ns~='' and ns..':'..tg)" -- "((rt.ns~='' and rt.ns..':'..rt.tg) or '')"
- local lp_tag = P("tag()") / "tg" -- (rt.tg or '')
- local lp_ns = P("ns()") / "ns" -- (rt.ns or '')
- local lp_noequal = P("!=") / "~=" + P("<=") + P(">=") + P("==")
- local lp_doequal = P("=") / "=="
- local lp_attribute = P("@") / "" * Cc("(at['") * R("az","AZ","--","__")^1 * Cc("'] or '')")
+local lp_position = P("position()") / "ps"
+local lp_index = P("index()") / "id"
+local lp_text = P("text()") / "tx"
+local lp_name = P("name()") / "(ns~='' and ns..':'..tg)" -- "((rt.ns~='' and rt.ns..':'..rt.tg) or '')"
+local lp_tag = P("tag()") / "tg" -- (rt.tg or '')
+local lp_ns = P("ns()") / "ns" -- (rt.ns or '')
+local lp_noequal = P("!=") / "~=" + P("<=") + P(">=") + P("==")
+local lp_doequal = P("=") / "=="
+local lp_attribute = P("@") / "" * Cc("(at['") * R("az","AZ","--","__")^1 * Cc("'] or '')")
- local lp_lua_function = C(R("az","AZ","--","__")^1 * (P(".") * R("az","AZ","--","__")^1)^1) * P("(") / function(t) -- todo: better . handling
- return t .. "("
+local lp_lua_function = C(R("az","AZ","--","__")^1 * (P(".") * R("az","AZ","--","__")^1)^1) * P("(") / function(t) -- todo: better . handling
+ return t .. "("
+end
+
+local lp_function = C(R("az","AZ","--","__")^1) * P("(") / function(t) -- todo: better . handling
+ if expressions[t] then
+ return "expressions." .. t .. "("
+ else
+ return "expressions.error("
end
+end
- local lp_function = C(R("az","AZ","--","__")^1) * P("(") / function(t) -- todo: better . handling
- if expressions[t] then
- return "expressions." .. t .. "("
+local lparent = lpeg.P("(")
+local rparent = lpeg.P(")")
+local noparent = 1 - (lparent+rparent)
+local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
+local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
+
+-- if we use a dedicated namespace then we don't need to pass rt and k
+
+local lp_special = (C(P("name")+P("text")+P("tag"))) * value / function(t,s)
+ if expressions[t] then
+ if s then
+ return "expressions." .. t .. "(r,k," .. s ..")"
else
- return "expressions.error("
+ return "expressions." .. t .. "(r,k)"
end
+ else
+ return "expressions.error(" .. t .. ")"
end
+end
- local lparent = lpeg.P("(")
- local rparent = lpeg.P(")")
- local noparent = 1 - (lparent+rparent)
- local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
- local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
+local converter = lpeg.Cs ( (
+ lp_position +
+ lp_index +
+ lp_text + lp_name + -- fast one
+ lp_special +
+ lp_noequal + lp_doequal +
+ lp_attribute +
+ lp_lua_function +
+ lp_function +
+1 )^1 )
- -- if we use a dedicated namespace then we don't need to pass rt and k
+-- expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1
- local lp_special = (C(P("name")+P("text")+P("tag"))) * value / function(t,s)
- if expressions[t] then
- if s then
- return "expressions." .. t .. "(r,k," .. s ..")"
- else
- return "expressions." .. t .. "(r,k)"
- end
- else
- return "expressions.error(" .. t .. ")"
- end
- end
-
- local converter = lpeg.Cs ( (
- lp_position +
- lp_index +
- lp_text + lp_name + -- fast one
- lp_special +
- lp_noequal + lp_doequal +
- lp_attribute +
- lp_lua_function +
- lp_function +
- 1 )^1 )
-
- -- expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1
-
- local template = [[
- return function(expressions,r,d,k,e,dt,ns,tg,id,ps)
- local at, tx = e.at or { }, dt[1] or ""
- return %s
- end
- ]]
-
- local function make_expression(str)
- str = converter:match(str)
- return str, loadstring(format(template,str))()
- end
-
- local map = { }
-
- local space = S(' \r\n\t')
- local squote = S("'")
- local dquote = S('"')
- local lparent = P('(')
- local rparent = P(')')
- local atsign = P('@')
- local lbracket = P('[')
- local rbracket = P(']')
- local exclam = P('!')
- local period = P('.')
- local eq = P('==') + P('=')
- local ne = P('<>') + P('!=')
- local star = P('*')
- local slash = P('/')
- local colon = P(':')
- local bar = P('|')
- local hat = P('^')
- local valid = R('az', 'AZ', '09') + S('_-')
---~ local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
---~ local name_nop = C(P(true)) * C(valid^1)
- local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
- local name_nop = Cc("*") * C(valid^1)
- local name = name_yes + name_nop
- local number = C((S('+-')^0 * R('09')^1)) / tonumber
- local names = (bar^0 * name)^1
- local morenames = name * (bar^0 * name)^1
- local instructiontag = P('pi::')
- local spacing = C(space^0)
- local somespace = space^1
- local optionalspace = space^0
- local text = C(valid^0)
- local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
- local empty = 1-slash
-
- local is_eq = lbracket * atsign * name * eq * value * rbracket
- local is_ne = lbracket * atsign * name * ne * value * rbracket
- local is_attribute = lbracket * atsign * name * rbracket
- local is_value = lbracket * value * rbracket
- local is_number = lbracket * number * rbracket
-
- local nobracket = 1-(lbracket+rbracket) -- must be improved
- local is_expression = lbracket * C(((C(nobracket^1))/make_expression)) * rbracket
-
- local is_expression = lbracket * (C(nobracket^1))/make_expression * rbracket
-
- local is_one = name
- local is_none = exclam * name
- local is_one_of = ((lparent * names * rparent) + morenames)
- local is_none_of = exclam * ((lparent * names * rparent) + morenames)
-
- local stay = (period )
- local parent = (period * period ) / function( ) map[#map+1] = { 11 } end
- local subtreeroot = (slash + hat ) / function( ) map[#map+1] = { 12 } end
- local documentroot = (hat * hat ) / function( ) map[#map+1] = { 13 } end
- local any = (star ) / function( ) map[#map+1] = { 14 } end
- local many = (star * star ) / function( ) map[#map+1] = { 15 } end
- local initial = (hat * hat * hat ) / function( ) map[#map+1] = { 16 } end
-
- local match = (is_one ) / function(...) map[#map+1] = { 20, true , ... } end
- local match_one_of = (is_one_of ) / function(...) map[#map+1] = { 21, true , ... } end
- local dont_match = (is_none ) / function(...) map[#map+1] = { 20, false, ... } end
- local dont_match_one_of = (is_none_of ) / function(...) map[#map+1] = { 21, false, ... } end
-
- local match_and_eq = (is_one * is_eq ) / function(...) map[#map+1] = { 22, true , ... } end
- local match_and_ne = (is_one * is_ne ) / function(...) map[#map+1] = { 23, true , ... } end
- local dont_match_and_eq = (is_none * is_eq ) / function(...) map[#map+1] = { 22, false, ... } end
- local dont_match_and_ne = (is_none * is_ne ) / function(...) map[#map+1] = { 23, false, ... } end
-
- local match_one_of_and_eq = (is_one_of * is_eq ) / function(...) map[#map+1] = { 24, true , ... } end
- local match_one_of_and_ne = (is_one_of * is_ne ) / function(...) map[#map+1] = { 25, true , ... } end
- local dont_match_one_of_and_eq = (is_none_of * is_eq ) / function(...) map[#map+1] = { 24, false, ... } end
- local dont_match_one_of_and_ne = (is_none_of * is_ne ) / function(...) map[#map+1] = { 25, false, ... } end
-
- local has_attribute = (is_one * is_attribute) / function(...) map[#map+1] = { 27, true , ... } end
- local has_value = (is_one * is_value ) / function(...) map[#map+1] = { 28, true , ... } end
- local dont_has_attribute = (is_none * is_attribute) / function(...) map[#map+1] = { 27, false, ... } end
- local dont_has_value = (is_none * is_value ) / function(...) map[#map+1] = { 28, false, ... } end
- local position = (is_one * is_number ) / function(...) map[#map+1] = { 30, true, ... } end
- local dont_position = (is_none * is_number ) / function(...) map[#map+1] = { 30, false, ... } end
-
- local expression = (is_one * is_expression)/ function(...) map[#map+1] = { 31, true, ... } end
- local dont_expression = (is_none * is_expression)/ function(...) map[#map+1] = { 31, false, ... } end
-
- local self_expression = ( is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
- map[#map+1] = { 31, true, "*", "*", ... } end
- local dont_self_expression = (exclam * is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
- map[#map+1] = { 31, false, "*", "*", ... } end
-
- local instruction = (instructiontag * text ) / function(...) map[#map+1] = { 40, ... } end
- local nothing = (empty ) / function( ) map[#map+1] = { 15 } end -- 15 ?
- local crap = (1-slash)^1
-
- -- a few ugly goodies:
-
- local docroottag = P('^^') / function( ) map[#map+1] = { 12 } end
- local subroottag = P('^') / function( ) map[#map+1] = { 13 } end
- local roottag = P('root::') / function( ) map[#map+1] = { 12 } end
- local parenttag = P('parent::') / function( ) map[#map+1] = { 11 } end
- local childtag = P('child::')
- local selftag = P('self::')
-
- -- there will be more and order will be optimized
-
- local selector = (
- instruction +
---~ many + any + -- brrr, not here !
- parent + stay +
- dont_position + position +
- dont_match_one_of_and_eq + dont_match_one_of_and_ne +
- match_one_of_and_eq + match_one_of_and_ne +
- dont_match_and_eq + dont_match_and_ne +
- match_and_eq + match_and_ne +
- dont_expression + expression +
- dont_self_expression + self_expression +
- has_attribute + has_value +
- dont_match_one_of + match_one_of +
- dont_match + match +
- many + any +
- crap + empty
- )
+local template = [[
+ return function(expressions,r,d,k,e,dt,ns,tg,id,ps)
+ local at, tx = e.at or { }, dt[1] or ""
+ return %s
+ end
+]]
- local grammar = P { "startup",
- startup = (initial + documentroot + subtreeroot + roottag + docroottag + subroottag)^0 * V("followup"),
- followup = ((slash + parenttag + childtag + selftag)^0 * selector)^1,
- }
+local function make_expression(str)
+ str = converter:match(str)
+ return str, loadstring(format(template,str))()
+end
+
+local map = { }
+
+local space = S(' \r\n\t')
+local squote = S("'")
+local dquote = S('"')
+local lparent = P('(')
+local rparent = P(')')
+local atsign = P('@')
+local lbracket = P('[')
+local rbracket = P(']')
+local exclam = P('!')
+local period = P('.')
+local eq = P('==') + P('=')
+local ne = P('<>') + P('!=')
+local star = P('*')
+local slash = P('/')
+local colon = P(':')
+local bar = P('|')
+local hat = P('^')
+local valid = R('az', 'AZ', '09') + S('_-')
+local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
+local name_nop = Cc("*") * C(valid^1)
+local name = name_yes + name_nop
+local number = C((S('+-')^0 * R('09')^1)) / tonumber
+local names = (bar^0 * name)^1
+local morenames = name * (bar^0 * name)^1
+local instructiontag = P('pi::')
+local spacing = C(space^0)
+local somespace = space^1
+local optionalspace = space^0
+local text = C(valid^0)
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local empty = 1-slash
+
+local is_eq = lbracket * atsign * name * eq * value * rbracket
+local is_ne = lbracket * atsign * name * ne * value * rbracket
+local is_attribute = lbracket * atsign * name * rbracket
+local is_value = lbracket * value * rbracket
+local is_number = lbracket * number * rbracket
+
+local nobracket = 1-(lbracket+rbracket) -- must be improved
+local is_expression = lbracket * C(((C(nobracket^1))/make_expression)) * rbracket
+
+local is_expression = lbracket * (C(nobracket^1))/make_expression * rbracket
+
+local is_one = name
+local is_none = exclam * name
+local is_one_of = ((lparent * names * rparent) + morenames)
+local is_none_of = exclam * ((lparent * names * rparent) + morenames)
+
+local stay = (period )
+local parent = (period * period ) / function( ) map[#map+1] = { 11 } end
+local subtreeroot = (slash + hat ) / function( ) map[#map+1] = { 12 } end
+local documentroot = (hat * hat ) / function( ) map[#map+1] = { 13 } end
+local any = (star ) / function( ) map[#map+1] = { 14 } end
+local many = (star * star ) / function( ) map[#map+1] = { 15 } end
+local initial = (hat * hat * hat ) / function( ) map[#map+1] = { 16 } end
+
+local match = (is_one ) / function(...) map[#map+1] = { 20, true , ... } end
+local match_one_of = (is_one_of ) / function(...) map[#map+1] = { 21, true , ... } end
+local dont_match = (is_none ) / function(...) map[#map+1] = { 20, false, ... } end
+local dont_match_one_of = (is_none_of ) / function(...) map[#map+1] = { 21, false, ... } end
+
+local match_and_eq = (is_one * is_eq ) / function(...) map[#map+1] = { 22, true , ... } end
+local match_and_ne = (is_one * is_ne ) / function(...) map[#map+1] = { 23, true , ... } end
+local dont_match_and_eq = (is_none * is_eq ) / function(...) map[#map+1] = { 22, false, ... } end
+local dont_match_and_ne = (is_none * is_ne ) / function(...) map[#map+1] = { 23, false, ... } end
+
+local match_one_of_and_eq = (is_one_of * is_eq ) / function(...) map[#map+1] = { 24, true , ... } end
+local match_one_of_and_ne = (is_one_of * is_ne ) / function(...) map[#map+1] = { 25, true , ... } end
+local dont_match_one_of_and_eq = (is_none_of * is_eq ) / function(...) map[#map+1] = { 24, false, ... } end
+local dont_match_one_of_and_ne = (is_none_of * is_ne ) / function(...) map[#map+1] = { 25, false, ... } end
+
+local has_attribute = (is_one * is_attribute) / function(...) map[#map+1] = { 27, true , ... } end
+local has_value = (is_one * is_value ) / function(...) map[#map+1] = { 28, true , ... } end
+local dont_has_attribute = (is_none * is_attribute) / function(...) map[#map+1] = { 27, false, ... } end
+local dont_has_value = (is_none * is_value ) / function(...) map[#map+1] = { 28, false, ... } end
+local position = (is_one * is_number ) / function(...) map[#map+1] = { 30, true, ... } end
+local dont_position = (is_none * is_number ) / function(...) map[#map+1] = { 30, false, ... } end
+
+local expression = (is_one * is_expression)/ function(...) map[#map+1] = { 31, true, ... } end
+local dont_expression = (is_none * is_expression)/ function(...) map[#map+1] = { 31, false, ... } end
+
+local self_expression = ( is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, true, "*", "*", ... } end
+local dont_self_expression = (exclam * is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, false, "*", "*", ... } end
+
+local instruction = (instructiontag * text ) / function(...) map[#map+1] = { 40, ... } end
+local nothing = (empty ) / function( ) map[#map+1] = { 15 } end -- 15 ?
+local crap = (1-slash)^1
+
+-- a few ugly goodies:
+
+local docroottag = P('^^') / function( ) map[#map+1] = { 12 } end
+local subroottag = P('^') / function( ) map[#map+1] = { 13 } end
+local roottag = P('root::') / function( ) map[#map+1] = { 12 } end
+local parenttag = P('parent::') / function( ) map[#map+1] = { 11 } end
+local childtag = P('child::')
+local selftag = P('self::')
+
+-- there will be more and order will be optimized
+
+local selector = (
+ instruction +
+-- many + any + -- brrr, not here !
+ parent + stay +
+ dont_position + position +
+ dont_match_one_of_and_eq + dont_match_one_of_and_ne +
+ match_one_of_and_eq + match_one_of_and_ne +
+ dont_match_and_eq + dont_match_and_ne +
+ match_and_eq + match_and_ne +
+ dont_expression + expression +
+ dont_self_expression + self_expression +
+ has_attribute + has_value +
+ dont_match_one_of + match_one_of +
+ dont_match + match +
+ many + any +
+ crap + empty
+)
+
+local grammar = P { "startup",
+ startup = (initial + documentroot + subtreeroot + roottag + docroottag + subroottag)^0 * V("followup"),
+ followup = ((slash + parenttag + childtag + selftag)^0 * selector)^1,
+}
- local function compose(str)
- if not str or str == "" then
- -- wildcard
+local function compose(str)
+ if not str or str == "" then
+ -- wildcard
+ return true
+ elseif str == '/' then
+ -- root
+ return false
+ else
+ map = { }
+ grammar:match(str)
+ if #map == 0 then
return true
- elseif str == '/' then
- -- root
- return false
else
- map = { }
- grammar:match(str)
- if #map == 0 then
- return true
- else
- local m = map[1][1]
- if #map == 1 then
- if m == 14 or m == 15 then
- -- wildcard
- return true
- elseif m == 12 then
- -- root
- return false
- end
- elseif #map == 2 and m == 12 and map[2][1] == 20 then
- -- return { { 29, map[2][2], map[2][3], map[2][4], map[2][5] } }
- map[2][1] = 29
- return { map[2] }
- end
- if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
- insert(map, 1, { 16 })
+ local m = map[1][1]
+ if #map == 1 then
+ if m == 14 or m == 15 then
+ -- wildcard
+ return true
+ elseif m == 12 then
+ -- root
+ return false
end
- -- print((table.serialize(map)):gsub("[ \n]+"," "))
- return map
+ elseif #map == 2 and m == 12 and map[2][1] == 20 then
+ -- return { { 29, map[2][2], map[2][3], map[2][4], map[2][5] } }
+ map[2][1] = 29
+ return { map[2] }
+ end
+ if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
+ insert(map, 1, { 16 })
end
+ -- print(gsub(table.serialize(map),"[ \n]+"," "))
+ return map
end
end
+end
- local cache = { }
+local cache = { }
- function xml.lpath(pattern,trace)
- lpathcalls = lpathcalls + 1
- if type(pattern) == "string" then
- local result = cache[pattern]
- if result == nil then -- can be false which is valid -)
- result = compose(pattern)
- cache[pattern] = result
- lpathcached = lpathcached + 1
- end
- if trace or xml.trace_lpath then
- xml.lshow(result)
- end
- return result
- else
- return pattern
+function xml.lpath(pattern,trace)
+ lpathcalls = lpathcalls + 1
+ if type(pattern) == "string" then
+ local result = cache[pattern]
+ if result == nil then -- can be false which is valid -)
+ result = compose(pattern)
+ cache[pattern] = result
+ lpathcached = lpathcached + 1
end
+ if trace or trace_lpath then
+ xml.lshow(result)
+ end
+ return result
+ else
+ return pattern
end
+end
- function lpath_cached_patterns()
- return cache
- end
-
- local fallbackreport = (texio and texio.write) or io.write
+function xml.cached_patterns()
+ return cache
+end
- function xml.lshow(pattern,report)
- report = report or fallbackreport
- local lp = xml.lpath(pattern)
- if lp == false then
- report(" -: root\n")
- elseif lp == true then
- report(" -: wildcard\n")
- else
- if type(pattern) == "string" then
- report(format("pattern: %s\n",pattern))
- end
- for k,v in ipairs(lp) do
- if #v > 1 then
- local t = { }
- for i=2,#v do
- local vv = v[i]
- if type(vv) == "string" then
- t[#t+1] = (vv ~= "" and vv) or "#"
- elseif type(vv) == "boolean" then
- t[#t+1] = (vv and "==") or "<>"
- end
+-- we run out of locals (limited to 200)
+--
+-- local fallbackreport = (texio and texio.write) or io.write
+
+function xml.lshow(pattern,report)
+-- report = report or fallbackreport
+ report = report or (texio and texio.write) or io.write
+ local lp = xml.lpath(pattern)
+ if lp == false then
+ report(" -: root\n")
+ elseif lp == true then
+ report(" -: wildcard\n")
+ else
+ if type(pattern) == "string" then
+ report(format("pattern: %s\n",pattern))
+ end
+ for k=1,#lp do
+ local v = lp[k]
+ if #v > 1 then
+ local t = { }
+ for i=2,#v do
+ local vv = v[i]
+ if type(vv) == "string" then
+ t[#t+1] = (vv ~= "" and vv) or "#"
+ elseif type(vv) == "boolean" then
+ t[#t+1] = (vv and "==") or "<>"
end
- report(format("%2i: %s %s -> %s\n", k,v[1],actions[v[1]],concat(t," ")))
- else
- report(format("%2i: %s %s\n", k,v[1],actions[v[1]]))
end
+ report(format("%2i: %s %s -> %s\n", k,v[1],actions[v[1]],concat(t," ")))
+ else
+ report(format("%2i: %s %s\n", k,v[1],actions[v[1]]))
end
end
end
+end
- function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
- local t = { ... }
- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
- if e == nil then
- report("\n")
- elseif type(e) ~= "table" then
- report(tostring(e))
- elseif e.tg then
- report(tostring(e) .. "\n")
- else
- for i=1,#e do
- report(tostring(e[i]) .. "\n")
- end
+function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
+ local t = { ... }
+-- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+ local report = (type(t[#t]) == "function" and t[#t]) or (texio and texio.write) or io.write
+ if e == nil then
+ report("\n")
+ elseif type(e) ~= "table" then
+ report(tostring(e))
+ elseif e.tg then
+ report(tostring(e) .. "\n")
+ else
+ for i=1,#e do
+ report(tostring(e[i]) .. "\n")
end
end
-
end
--[[ldx--
@@ -3376,161 +3764,174 @@ advance what we want to do with the found element the handle gets three argument
functions.
--ldx]]--
-do
-
- local functions = xml.functions
- local expressions = xml.expressions
-
- expressions.contains = string.find
- expressions.find = string.find
- expressions.upper = string.upper
- expressions.lower = string.lower
- expressions.number = tonumber
- expressions.boolean = toboolean
+local functions = xml.functions
+local expressions = xml.expressions
- expressions.oneof = function(s,...) -- slow
- local t = {...} for i=1,#t do if s == t[i] then return true end end return false
- end
+expressions.contains = string.find
+expressions.find = string.find
+expressions.upper = string.upper
+expressions.lower = string.lower
+expressions.number = tonumber
+expressions.boolean = toboolean
- expressions.error = function(str)
- xml.error_handler("unknown function in lpath expression",str or "?")
- return false
- end
+expressions.oneof = function(s,...) -- slow
+ local t = {...} for i=1,#t do if s == t[i] then return true end end return false
+end
- functions.text = function(root,k,n) -- unchecked, maybe one deeper
- local t = type(t)
- if t == "string" then
- return t
- else -- todo n
- local rdt = root.dt
- return (rdt and rdt[k]) or root[k] or ""
- end
- end
+expressions.error = function(str)
+ xml.error_handler("unknown function in lpath expression",str or "?")
+ return false
+end
- functions.name = function(d,k,n) -- ns + tg
- local found = false
- n = n or 0
- if not k then
- -- not found
- elseif n == 0 then
- local dk = d[k]
- found = dk and (type(dk) == "table") and dk
- elseif n < 0 then
- for i=k-1,1,-1 do
- local di = d[i]
- if type(di) == "table" then
- if n == -1 then
- found = di
- break
- else
- n = n + 1
- end
+functions.text = function(root,k,n) -- unchecked, maybe one deeper
+ local t = type(t)
+ if t == "string" then
+ return t
+ else -- todo n
+ local rdt = root.dt
+ return (rdt and rdt[k]) or root[k] or ""
+ end
+end
+
+functions.name = function(d,k,n) -- ns + tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
end
end
- else
- for i=k+1,#d,1 do
- local di = d[i]
- if type(di) == "table" then
- if n == 1 then
- found = di
- break
- else
- n = n - 1
- end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
end
end
end
- if found then
- local ns, tg = found.rn or found.ns or "", found.tg
- if ns ~= "" then
- return ns .. ":" .. tg
- else
- return tg
- end
+ end
+ if found then
+ local ns, tg = found.rn or found.ns or "", found.tg
+ if ns ~= "" then
+ return ns .. ":" .. tg
else
- return ""
+ return tg
end
+ else
+ return ""
end
+end
- functions.tag = function(d,k,n) -- only tg
- local found = false
- n = n or 0
- if not k then
- -- not found
- elseif n == 0 then
- local dk = d[k]
- found = dk and (type(dk) == "table") and dk
- elseif n < 0 then
- for i=k-1,1,-1 do
- local di = d[i]
- if type(di) == "table" then
- if n == -1 then
- found = di
- break
- else
- n = n + 1
- end
+functions.tag = function(d,k,n) -- only tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
end
end
- else
- for i=k+1,#d,1 do
- local di = d[i]
- if type(di) == "table" then
- if n == 1 then
- found = di
- break
- else
- n = n - 1
- end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
end
end
end
- return (found and found.tg) or ""
end
+ return (found and found.tg) or ""
+end
- expressions.text = functions.text
- expressions.name = functions.name
- expressions.tag = functions.tag
+expressions.text = functions.text
+expressions.name = functions.name
+expressions.tag = functions.tag
- local function traverse(root,pattern,handle,reverse,index,parent,wildcard) -- multiple only for tags, not for namespaces
- if not root then -- error
- return false
- elseif pattern == false then -- root
- handle(root,root.dt,root.ri)
- return false
- elseif pattern == true then -- wildcard
- local rootdt = root.dt
- if rootdt then
- local start, stop, step = 1, #rootdt, 1
- if reverse then
- start, stop, step = stop, start, -1
- end
- for k=start,stop,step do
- if handle(root,rootdt,root.ri or k) then return false end
- if not traverse(rootdt[k],true,handle,reverse) then return false end
- end
+local function traverse(root,pattern,handle,reverse,index,parent,wildcard) -- multiple only for tags, not for namespaces
+ if not root then -- error
+ return false
+ elseif pattern == false then -- root
+ handle(root,root.dt,root.ri)
+ return false
+ elseif pattern == true then -- wildcard
+ local rootdt = root.dt
+ if rootdt then
+ local start, stop, step = 1, #rootdt, 1
+ if reverse then
+ start, stop, step = stop, start, -1
end
- return false
- elseif root.dt then
- index = index or 1
- local action = pattern[index]
- local command = action[1]
- if command == 29 then -- fast case /oeps
- local rootdt = root.dt
- for k=1,#rootdt do
- local e = rootdt[k]
- local tg = e.tg
- if e.tg then
- local ns = e.rn or e.ns
- local ns_a, tg_a = action[3], action[4]
- local matched = (ns_a == "*" or ns == ns_a) and (tg_a == "*" or tg == tg_a)
- if not action[2] then matched = not matched end
- if matched then
- if handle(root,rootdt,k) then return false end
- end
+ for k=start,stop,step do
+ if handle(root,rootdt,root.ri or k) then return false end
+ if not traverse(rootdt[k],true,handle,reverse) then return false end
+ end
+ end
+ return false
+ elseif root.dt then
+ index = index or 1
+ local action = pattern[index]
+ local command = action[1]
+ if command == 29 then -- fast case /oeps
+ local rootdt = root.dt
+ for k=1,#rootdt do
+ local e = rootdt[k]
+ local tg = e.tg
+ if e.tg then
+ local ns = e.rn or e.ns
+ local ns_a, tg_a = action[3], action[4]
+ local matched = (ns_a == "*" or ns == ns_a) and (tg_a == "*" or tg == tg_a)
+ if not action[2] then matched = not matched end
+ if matched then
+ if handle(root,rootdt,k) then return false end
end
end
- elseif command == 11 then -- parent
+ end
+ elseif command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ if (command == 16 or command == 12) and index == 1 then -- initial
+ -- wildcard = true
+ wildcard = command == 16 -- ok?
+ index = index + 1
+ action = pattern[index]
+ command = action and action[1] or 0 -- something is wrong
+ end
+ if command == 11 then -- parent
local ep = root.__p__ or parent
if index < #pattern then
if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
@@ -3538,41 +3939,51 @@ do
return false
end
else
- if (command == 16 or command == 12) and index == 1 then -- initial
- -- wildcard = true
- wildcard = command == 16 -- ok?
- index = index + 1
- action = pattern[index]
- command = action and action[1] or 0 -- something is wrong
- end
- if command == 11 then -- parent
- local ep = root.__p__ or parent
- if index < #pattern then
- if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
- elseif handle(root,rootdt,k) then
- return false
- end
- else
- local rootdt = root.dt
- local start, stop, step, n, dn = 1, #rootdt, 1, 0, 1
- if command == 30 then
- if action[5] < 0 then
- start, stop, step = stop, start, -1
- dn = -1
- end
- elseif reverse and index == #pattern then
+ local rootdt = root.dt
+ local start, stop, step, n, dn = 1, #rootdt, 1, 0, 1
+ if command == 30 then
+ if action[5] < 0 then
start, stop, step = stop, start, -1
+ dn = -1
end
- local idx = 0
- local hsh = { } -- this will slooow down the lot
- for k=start,stop,step do -- we used to have functions for all but a case is faster
- local e = rootdt[k]
- local ns, tg = e.rn or e.ns, e.tg
- if tg then
- -- we can optimize this for simple searches, but it probably does not pay off
- hsh[tg] = (hsh[tg] or 0) + 1
- idx = idx + 1
- if command == 30 then
+ elseif reverse and index == #pattern then
+ start, stop, step = stop, start, -1
+ end
+ local idx = 0
+ local hsh = { } -- this will slooow down the lot
+ for k=start,stop,step do -- we used to have functions for all but a case is faster
+ local e = rootdt[k]
+ local ns, tg = e.rn or e.ns, e.tg
+ if tg then
+ -- we can optimize this for simple searches, but it probably does not pay off
+ hsh[tg] = (hsh[tg] or 0) + 1
+ idx = idx + 1
+ if command == 30 then
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ n = n + dn
+ if n == action[5] then
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ break
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ else
+ local matched, multiple = false, false
+ if command == 20 then -- match
local ns_a, tg_a = action[3], action[4]
if tg == tg_a then
matched = ns_a == "*" or ns == ns_a
@@ -3582,193 +3993,166 @@ do
matched = false
end
if not action[2] then matched = not matched end
- if matched then
- n = n + dn
- if n == action[5] then
- if index == #pattern then
- if handle(root,rootdt,root.ri or k) then return false end
- else
- if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
- end
+ elseif command == 21 then -- match one of
+ multiple = true
+ for i=3,#action,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
break
end
- elseif wildcard then
- if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
end
- else
- local matched, multiple = false, false
- if command == 20 then -- match
- local ns_a, tg_a = action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- if not action[2] then matched = not matched end
- elseif command == 21 then -- match one of
- multiple = true
- for i=3,#action,2 do
- local ns_a, tg_a = action[i], action[i+1]
- if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
- matched = true
- break
- end
- end
- if not action[2] then matched = not matched end
- elseif command == 22 then -- eq
- local ns_a, tg_a = action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- matched = matched and e.at[action[6]] == action[7]
- elseif command == 23 then -- ne
- local ns_a, tg_a = action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- if not action[2] then matched = not matched end
- matched = mached and e.at[action[6]] ~= action[7]
- elseif command == 24 then -- one of eq
- multiple = true
- for i=3,#action-2,2 do
- local ns_a, tg_a = action[i], action[i+1]
- if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
- matched = true
- break
- end
- end
- if not action[2] then matched = not matched end
- matched = matched and e.at[action[#action-1]] == action[#action]
- elseif command == 25 then -- one of ne
- multiple = true
- for i=3,#action-2,2 do
- local ns_a, tg_a = action[i], action[i+1]
- if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
- matched = true
- break
- end
- end
- if not action[2] then matched = not matched end
- matched = matched and e.at[action[#action-1]] ~= action[#action]
- elseif command == 27 then -- has attribute
- local ns_a, tg_a = action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- if not action[2] then matched = not matched end
- matched = matched and e.at[action[5]]
- elseif command == 28 then -- has value
- local edt, ns_a, tg_a = e.dt, action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- if not action[2] then matched = not matched end
- matched = matched and edt and edt[1] == action[5]
- elseif command == 31 then
- local edt, ns_a, tg_a = e.dt, action[3], action[4]
- if tg == tg_a then
- matched = ns_a == "*" or ns == ns_a
- elseif tg_a == '*' then
- matched, multiple = ns_a == "*" or ns == ns_a, true
- else
- matched = false
- end
- if not action[2] then matched = not matched end
- if matched then
- matched = action[6](expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1)
- end
+ if not action[2] then matched = not matched end
+ elseif command == 22 then -- eq
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
end
- if matched then -- combine tg test and at test
- if index == #pattern then
- if handle(root,rootdt,root.ri or k) then return false end
- if wildcard then
- if multiple then
- if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
- else
- -- maybe or multiple; anyhow, check on (section|title) vs just section and title in example in lxml
- if not traverse(e,pattern,handle,reverse,index,root) then return false end
- end
- end
- else
- if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
- end
- elseif command == 14 then -- any
- if index == #pattern then
- if handle(root,rootdt,root.ri or k) then return false end
- else
- if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
- end
- elseif command == 15 then -- many
- if index == #pattern then
- if handle(root,rootdt,root.ri or k) then return false end
- else
- if not traverse(e,pattern,handle,reverse,index+1,root,true) then return false end
+ matched = matched and e.at[action[6]] == action[7]
+ elseif command == 23 then -- ne
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = mached and e.at[action[6]] ~= action[7]
+ elseif command == 24 then -- one of eq
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
end
- -- not here : 11
- elseif command == 11 then -- parent
- local ep = e.__p__ or parent
- if index < #pattern then
- if not traverse(ep,pattern,handle,reverse,root,index+1) then return false end
- elseif handle(root,rootdt,k) then
- return false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] == action[#action]
+ elseif command == 25 then -- one of ne
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
end
- elseif command == 40 and e.special and tg == "@pi@" then -- pi
- local pi = action[2]
- if pi ~= "" then
- local pt = e.dt[1]
- if pt and pt:find(pi) then
- if handle(root,rootdt,k) then
- return false
- end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] ~= action[#action]
+ elseif command == 27 then -- has attribute
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[5]]
+ elseif command == 28 then -- has value
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and edt and edt[1] == action[5]
+ elseif command == 31 then
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ matched = action[6](expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1)
+ end
+ end
+ if matched then -- combine tg test and at test
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ if wildcard then
+ if multiple then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ else
+ -- maybe or multiple; anyhow, check on (section|title) vs just section and title in example in lxml
+ if not traverse(e,pattern,handle,reverse,index,root) then return false end
end
- elseif handle(root,rootdt,k) then
- return false
end
- elseif wildcard then
- if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 14 then -- any
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 15 then -- many
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root,true) then return false end
end
- end
- else
-- not here : 11
- if command == 11 then -- parent
+ elseif command == 11 then -- parent
local ep = e.__p__ or parent
if index < #pattern then
- if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ if not traverse(ep,pattern,handle,reverse,root,index+1) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif command == 40 and e.special and tg == "@pi@" then -- pi
+ local pi = action[2]
+ if pi ~= "" then
+ local pt = e.dt[1]
+ if pt and pt:find(pi) then
+ if handle(root,rootdt,k) then
+ return false
+ end
+ end
elseif handle(root,rootdt,k) then
return false
end
- break -- else loop
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ end
+ else
+ -- not here : 11
+ if command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
end
+ break -- else loop
end
end
end
end
end
- return true
end
-
- xml.traverse = traverse
-
+ return true
end
+xml.traverse = traverse
+
--[[ldx--
Next come all kind of locators and manipulators. The most generic function here
is xml.filter(root,pattern). All registers functions in the filters namespace
@@ -3779,399 +4163,414 @@ local r, d, k = xml.filter(root,"/a/b/c/position(4)"
--ldx]]--
-do
+local traverse, lpath, convert = xml.traverse, xml.lpath, xml.convert
- local traverse, lpath, convert = xml.traverse, xml.lpath, xml.convert
+xml.filters = { }
- xml.filters = { }
+function xml.filters.default(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
- function xml.filters.default(root,pattern)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
- return dt and dt[dk], rt, dt, dk
- end
- function xml.filters.attributes(root,pattern,arguments)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
- local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
- if ekat then
- if arguments then
- return ekat[arguments] or "", rt, dt, dk
- else
- return ekat, rt, dt, dk
- end
- else
- return { }, rt, dt, dk
- end
- end
- function xml.filters.reverse(root,pattern)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
- return dt and dt[dk], rt, dt, dk
- end
- function xml.filters.count(root,pattern,everything)
- local n = 0
- traverse(root, lpath(pattern), function(r,d,t)
- if everything or type(d[t]) == "table" then
- n = n + 1
- end
- end)
- return n
- end
- function xml.filters.elements(root, pattern) -- == all
- local t = { }
- traverse(root, lpath(pattern), function(r,d,k)
- local e = d[k]
- if e then
- t[#t+1] = e
- end
- end)
- return t
- end
- function xml.filters.texts(root, pattern)
- local t = { }
- traverse(root, lpath(pattern), function(r,d,k)
- local e = d[k]
- if e and e.dt then
- t[#t+1] = e.dt
- end
- end)
- return t
- end
- function xml.filters.first(root,pattern)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
- return dt and dt[dk], rt, dt, dk
- end
- function xml.filters.last(root,pattern)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
- return dt and dt[dk], rt, dt, dk
- end
- function xml.filters.index(root,pattern,arguments)
- local rt, dt, dk, reverse, i = nil, nil, nil, false, tonumber(arguments or '1') or 1
- if i and i ~= 0 then
- if i < 0 then
- reverse, i = true, -i
- end
- traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk, i = r, d, k, i-1 return i == 0 end, reverse)
- if i == 0 then
- return dt and dt[dk], rt, dt, dk
- end
- end
- return nil, nil, nil, nil
- end
- function xml.filters.attribute(root,pattern,arguments)
- local rt, dt, dk
- traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
- local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
- return (ekat and (ekat[arguments] or ekat[arguments:gsub("^([\"\'])(.*)%1$","%2")])) or ""
- end
- function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
- local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
- if dtk then -- n
- local dtkdt = dtk.dt
- if not dtkdt then
- return "", rt, dt, dk
- elseif #dtkdt == 1 and type(dtkdt[1]) == "string" then
- return dtkdt[1], rt, dt, dk
- else
- return xml.tostring(dtkdt), rt, dt, dk
- end
+function xml.filters.attributes(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ if ekat then
+ if arguments then
+ return ekat[arguments] or "", rt, dt, dk
else
- return "", rt, dt, dk
+ return ekat, rt, dt, dk
end
+ else
+ return { }, rt, dt, dk
end
- function xml.filters.tag(root,pattern,n)
- local tag = ""
- traverse(root, lpath(pattern), function(r,d,k)
- tag = xml.functions.tag(d,k,n and tonumber(n))
- return true
- end)
- return tag
- end
- function xml.filters.name(root,pattern,n)
- local tag = ""
- traverse(root, lpath(pattern), function(r,d,k)
- tag = xml.functions.name(d,k,n and tonumber(n))
- return true
- end)
- return tag
- end
-
- --[[ldx--
-
For splitting the filter function from the path specification, we can
- use string matching or lpeg matching. Here the difference in speed is
- neglectable but the lpeg variant is more robust.
- --ldx]]--
-
- -- not faster but hipper ... although ... i can't get rid of the trailing / in the path
-
- local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
-
- local slash = P('/')
- local name = (R("az","AZ","--","__"))^1
- local path = C(((1-slash)^0 * slash)^1)
- local argument = P { "(" * C(((1 - S("()")) + V(1))^0) * ")" }
- local action = Cc(1) * path * C(name) * argument
- local attribute = Cc(2) * path * P('@') * C(name)
- local direct = Cc(3) * Cc("../*") * slash^0 * C(name) * argument
-
- local parser = direct + action + attribute
-
- local filters = xml.filters
- local attribute_filter = xml.filters.attributes
- local default_filter = xml.filters.default
+end
- -- todo: also hash, could be gc'd
+function xml.filters.reverse(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
- function xml.filter(root,pattern)
- local kind, a, b, c = parser:match(pattern)
---~ if xml.trace_lpath then
---~ print(pattern,kind,a,b,c)
---~ end
- if kind == 1 or kind == 3 then
- return (filters[b] or default_filter)(root,a,c)
- elseif kind == 2 then
- return attribute_filter(root,a,b)
- else
- return default_filter(root,pattern)
- end
- end
-
- --~ slightly faster, but first we need a proper test file
- --~
- --~ local hash = { }
- --~
- --~ function xml.filter(root,pattern)
- --~ local h = hash[pattern]
- --~ if not h then
- --~ local kind, a, b, c = parser:match(pattern)
- --~ if kind == 1 then
- --~ h = { kind, filters[b] or default_filter, a, b, c }
- --~ elseif kind == 2 then
- --~ h = { kind, attribute_filter, a, b, c }
- --~ else
- --~ h = { kind, default_filter, a, b, c }
- --~ end
- --~ hash[pattern] = h
- --~ end
- --~ local kind = h[1]
- --~ if kind == 1 then
- --~ return h[2](root,h[2],h[4])
- --~ elseif kind == 2 then
- --~ return h[2](root,h[2],h[3])
- --~ else
- --~ return h[2](root,pattern)
- --~ end
- --~ end
-
- --[[ldx--
-
The following functions collect elements and texts.
- --ldx]]--
-
- -- still somewhat bugged
-
- function xml.collect_elements(root, pattern, ignorespaces)
- local rr, dd = { }, { }
- traverse(root, lpath(pattern), function(r,d,k)
- local dk = d and d[k]
- if dk then
- if ignorespaces and type(dk) == "string" and dk:find("[^%S]") then
- -- ignore
- else
- local n = #rr+1
- rr[n], dd[n] = r, dk
- end
- end
- end)
- return dd, rr
- end
-
- function xml.collect_texts(root, pattern, flatten)
- local t = { } -- no r collector
- traverse(root, lpath(pattern), function(r,d,k)
- if d then
- local ek = d[k]
- local tx = ek and ek.dt
- if flatten then
- if tx then
- t[#t+1] = xml.tostring(tx) or ""
- else
- t[#t+1] = ""
- end
- else
- t[#t+1] = tx or ""
- end
- else
- t[#t+1] = ""
- end
- end)
- return t
- end
+function xml.filters.count(root,pattern,everything)
+ local n = 0
+ traverse(root, lpath(pattern), function(r,d,t)
+ if everything or type(d[t]) == "table" then
+ n = n + 1
+ end
+ end)
+ return n
+end
- function xml.collect_tags(root, pattern, nonamespace)
- local t = { }
- xml.traverse(root, xml.lpath(pattern), function(r,d,k)
- local dk = d and d[k]
- if dk and type(dk) == "table" then
- local ns, tg = e.ns, e.tg
- if nonamespace then
- t[#t+1] = tg -- if needed we can return an extra table
- elseif ns == "" then
- t[#t+1] = tg
- else
- t[#t+1] = ns .. ":" .. tg
- end
- end
- end)
- return #t > 0 and {}
- end
+function xml.filters.elements(root, pattern) -- == all
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e then
+ t[#t+1] = e
+ end
+ end)
+ return t
+end
- --[[ldx--
-
Often using an iterators looks nicer in the code than passing handler
- functions. The book describes how to use coroutines for that
- purpose (). This permits
- code like:
+function xml.filters.texts(root, pattern)
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e and e.dt then
+ t[#t+1] = e.dt
+ end
+ end)
+ return t
+end
-
- for r, d, k in xml.elements(xml.load('text.xml'),"title") do
- print(d[k])
- end
-
+function xml.filters.first(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
-
Which will print all the titles in the document. The iterator variant takes
- 1.5 times the runtime of the function variant which is due to the overhead in
- creating the wrapper. So, instead of:
+function xml.filters.last(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
-
- function xml.filters.first(root,pattern)
- for rt,dt,dk in xml.elements(root,pattern)
+function xml.filters.index(root,pattern,arguments)
+ local rt, dt, dk, reverse, i = nil, nil, nil, false, tonumber(arguments or '1') or 1
+ if i and i ~= 0 then
+ if i < 0 then
+ reverse, i = true, -i
+ end
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk, i = r, d, k, i-1 return i == 0 end, reverse)
+ if i == 0 then
return dt and dt[dk], rt, dt, dk
end
- return nil, nil, nil, nil
end
-
-
-
We use the function variants in the filters.
- --ldx]]--
+ return nil, nil, nil, nil
+end
- local wrap, yield = coroutine.wrap, coroutine.yield
+function xml.filters.attribute(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ return (ekat and (ekat[arguments] or ekat[gsub(arguments,"^([\"\'])(.*)%1$","%2")])) or ""
+end
- function xml.elements(root,pattern,reverse)
- return wrap(function() traverse(root, lpath(pattern), yield, reverse) end)
+function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
+ local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
+ if dtk then -- n
+ local dtkdt = dtk.dt
+ if not dtkdt then
+ return "", rt, dt, dk
+ elseif #dtkdt == 1 and type(dtkdt[1]) == "string" then
+ return dtkdt[1], rt, dt, dk
+ else
+ return xml.tostring(dtkdt), rt, dt, dk
+ end
+ else
+ return "", rt, dt, dk
end
+end
- function xml.elements_only(root,pattern,reverse)
- return wrap(function() traverse(root, lpath(pattern), function(r,d,k) yield(d[k]) end, reverse) end)
- end
+function xml.filters.tag(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.tag(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+function xml.filters.name(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.name(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+--[[ldx--
+
For splitting the filter function from the path specification, we can
+use string matching or lpeg matching. Here the difference in speed is
+neglectable but the lpeg variant is more robust.
+--ldx]]--
+
+-- not faster but hipper ... although ... i can't get rid of the trailing / in the path
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+local slash = P('/')
+local name = (R("az","AZ","--","__"))^1
+local path = C(((1-slash)^0 * slash)^1)
+local argument = P { "(" * C(((1 - S("()")) + V(1))^0) * ")" }
+local action = Cc(1) * path * C(name) * argument
+local attribute = Cc(2) * path * P('@') * C(name)
+local direct = Cc(3) * Cc("../*") * slash^0 * C(name) * argument
+
+local parser = direct + action + attribute
+
+local filters = xml.filters
+local attribute_filter = xml.filters.attributes
+local default_filter = xml.filters.default
- function xml.each_element(root, pattern, handle, reverse)
- local ok
- traverse(root, lpath(pattern), function(r,d,k) ok = true handle(r,d,k) end, reverse)
- return ok
+-- todo: also hash, could be gc'd
+
+function xml.filter(root,pattern)
+ local kind, a, b, c = parser:match(pattern)
+ if kind == 1 or kind == 3 then
+ return (filters[b] or default_filter)(root,a,c)
+ elseif kind == 2 then
+ return attribute_filter(root,a,b)
+ else
+ return default_filter(root,pattern)
end
+end
- function xml.process_elements(root, pattern, handle)
- traverse(root, lpath(pattern), function(r,d,k)
- local dkdt = d[k].dt
- if dkdt then
- for i=1,#dkdt do
- local v = dkdt[i]
- if v.tg then handle(v) end
- end
+--~ slightly faster, but first we need a proper test file
+--~
+--~ local hash = { }
+--~
+--~ function xml.filter(root,pattern)
+--~ local h = hash[pattern]
+--~ if not h then
+--~ local kind, a, b, c = parser:match(pattern)
+--~ if kind == 1 then
+--~ h = { kind, filters[b] or default_filter, a, b, c }
+--~ elseif kind == 2 then
+--~ h = { kind, attribute_filter, a, b, c }
+--~ else
+--~ h = { kind, default_filter, a, b, c }
+--~ end
+--~ hash[pattern] = h
+--~ end
+--~ local kind = h[1]
+--~ if kind == 1 then
+--~ return h[2](root,h[2],h[4])
+--~ elseif kind == 2 then
+--~ return h[2](root,h[2],h[3])
+--~ else
+--~ return h[2](root,pattern)
+--~ end
+--~ end
+
+--[[ldx--
+
The following functions collect elements and texts.
+--ldx]]--
+
+-- still somewhat bugged
+
+function xml.collect_elements(root, pattern, ignorespaces)
+ local rr, dd = { }, { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk then
+ if ignorespaces and type(dk) == "string" and dk:find("[^%S]") then
+ -- ignore
+ else
+ local n = #rr+1
+ rr[n], dd[n] = r, dk
end
- end)
- end
+ end
+ end)
+ return dd, rr
+end
- function xml.process_attributes(root, pattern, handle)
- traverse(root, lpath(pattern), function(r,d,k)
+function xml.collect_texts(root, pattern, flatten)
+ local t = { } -- no r collector
+ traverse(root, lpath(pattern), function(r,d,k)
+ if d then
local ek = d[k]
- local a = ek.at or { }
- handle(a)
- if next(a) then -- next is faster than type (and >0 test)
- ek.at = a
+ local tx = ek and ek.dt
+ if flatten then
+ if tx then
+ t[#t+1] = xml.tostring(tx) or ""
+ else
+ t[#t+1] = ""
+ end
else
- ek.at = nil
+ t[#t+1] = tx or ""
end
- end)
+ else
+ t[#t+1] = ""
+ end
+ end)
+ return t
+end
+
+function xml.collect_tags(root, pattern, nonamespace)
+ local t = { }
+ xml.traverse(root, xml.lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk and type(dk) == "table" then
+ local ns, tg = e.ns, e.tg
+ if nonamespace then
+ t[#t+1] = tg -- if needed we can return an extra table
+ elseif ns == "" then
+ t[#t+1] = tg
+ else
+ t[#t+1] = ns .. ":" .. tg
+ end
+ end
+ end)
+ return #t > 0 and {}
+end
+
+--[[ldx--
+
Often using an iterators looks nicer in the code than passing handler
+functions. The book describes how to use coroutines for that
+purpose (). This permits
+code like:
+
+
+for r, d, k in xml.elements(xml.load('text.xml'),"title") do
+ print(d[k])
+end
+
+
+
Which will print all the titles in the document. The iterator variant takes
+1.5 times the runtime of the function variant which is due to the overhead in
+creating the wrapper. So, instead of:
+
+
+function xml.filters.first(root,pattern)
+ for rt,dt,dk in xml.elements(root,pattern)
+ return dt and dt[dk], rt, dt, dk
end
+ return nil, nil, nil, nil
+end
+
+
+
We use the function variants in the filters.
+--ldx]]--
- --[[ldx--
-
We've now arrives at the functions that manipulate the tree.
- --ldx]]--
+local wrap, yield = coroutine.wrap, coroutine.yield
- function xml.inject_element(root, pattern, element, prepend)
- if root and element then
- local matches, collect = { }, nil
- if type(element) == "string" then
- element = convert(element,true)
+function xml.elements(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), yield, reverse) end)
+end
+
+function xml.elements_only(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), function(r,d,k) yield(d[k]) end, reverse) end)
+end
+
+function xml.each_element(root, pattern, handle, reverse)
+ local ok
+ traverse(root, lpath(pattern), function(r,d,k) ok = true handle(r,d,k) end, reverse)
+ return ok
+end
+
+function xml.process_elements(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then
+ for i=1,#dkdt do
+ local v = dkdt[i]
+ if v.tg then handle(v) end
end
- if element then
- collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
- traverse(root, lpath(pattern), collect)
- for i=1,#matches do
- local m = matches[i]
- local r, d, k, element, edt = m[1], m[2], m[3], m[4], nil
- if element.ri then
- element = element.dt[element.ri].dt
+ end
+ end)
+end
+
+function xml.process_attributes(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local ek = d[k]
+ local a = ek.at or { }
+ handle(a)
+ if next(a) then -- next is faster than type (and >0 test)
+ ek.at = a
+ else
+ ek.at = nil
+ end
+ end)
+end
+
+--[[ldx--
+
We've now arrives at the functions that manipulate the tree.
+--ldx]]--
+
+function xml.inject_element(root, pattern, element, prepend)
+ if root and element then
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=1,#matches do
+ local m = matches[i]
+ local r, d, k, element, edt = m[1], m[2], m[3], m[4], nil
+ if element.ri then
+ element = element.dt[element.ri].dt
+ else
+ element = element.dt
+ end
+ if r.ri then
+ edt = r.dt[r.ri].dt
+ else
+ edt = d and d[k] and d[k].dt
+ end
+ if edt then
+ local be, af
+ if prepend then
+ be, af = xml.copy(element), edt
else
- element = element.dt
+ be, af = edt, xml.copy(element)
end
- if r.ri then
- edt = r.dt[r.ri].dt
- else
- edt = d and d[k] and d[k].dt
+ for i=1,#af do
+ be[#be+1] = af[i]
end
- if edt then
- local be, af
- if prepend then
- be, af = xml.copy(element), edt
- else
- be, af = edt, xml.copy(element)
- end
- for i=1,#af do
- be[#be+1] = af[i]
- end
- if r.ri then
- r.dt[r.ri].dt = be
- else
- d[k].dt = be
- end
+ if r.ri then
+ r.dt[r.ri].dt = be
else
- -- r.dt = element.dt -- todo
+ d[k].dt = be
end
+ else
+ -- r.dt = element.dt -- todo
end
end
end
end
+end
- -- todo: copy !
+-- todo: copy !
- function xml.insert_element(root, pattern, element, before) -- todo: element als functie
- if root and element then
- if pattern == "/" then
- xml.inject_element(root, pattern, element, before)
- else
- local matches, collect = { }, nil
- if type(element) == "string" then
- element = convert(element,true)
- end
- if element and element.ri then
- element = element.dt[element.ri]
- end
- if element then
- collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
- traverse(root, lpath(pattern), collect)
- for i=#matches,1,-1 do
- local m = matches[i]
- local r, d, k, element = m[1], m[2], m[3], m[4]
- if not before then k = k + 1 end
- if element.tg then
- insert(d,k,element) -- untested
- elseif element.dt then
- for _,v in ipairs(element.dt) do -- i added
- insert(d,k,v)
+function xml.insert_element(root, pattern, element, before) -- todo: element als functie
+ if root and element then
+ if pattern == "/" then
+ xml.inject_element(root, pattern, element, before)
+ else
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ local r, d, k, element = m[1], m[2], m[3], m[4]
+ if not before then k = k + 1 end
+ if element.tg then
+ insert(d,k,element) -- untested
+--~ elseif element.dt then
+--~ for _,v in ipairs(element.dt) do -- i added
+--~ insert(d,k,v)
+--~ k = k + 1
+--~ end
+--~ end
+ else
+ local edt = element.dt
+ if edt then
+ for i=1,#edt do
+ insert(d,k,edt[i])
k = k + 1
end
end
@@ -4180,176 +4579,176 @@ do
end
end
end
+end
- xml.insert_element_after = xml.insert_element
- xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end
- xml.inject_element_after = xml.inject_element
- xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end
+xml.insert_element_after = xml.insert_element
+xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end
+xml.inject_element_after = xml.inject_element
+xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end
- function xml.delete_element(root, pattern)
- local matches, deleted = { }, { }
- local collect = function(r,d,k) matches[#matches+1] = { r, d, k } end
- traverse(root, lpath(pattern), collect)
- for i=#matches,1,-1 do
- local m = matches[i]
- deleted[#deleted+1] = table.remove(m[2],m[3])
- end
- return deleted
+function xml.delete_element(root, pattern)
+ local matches, deleted = { }, { }
+ local collect = function(r,d,k) matches[#matches+1] = { r, d, k } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ deleted[#deleted+1] = remove(m[2],m[3])
end
+ return deleted
+end
- function xml.replace_element(root, pattern, element)
- if type(element) == "string" then
- element = convert(element,true)
- end
- if element and element.ri then
- element = element.dt[element.ri]
- end
- if element then
- traverse(root, lpath(pattern), function(rm, d, k)
- d[k] = element.dt -- maybe not clever enough
- end)
- end
+function xml.replace_element(root, pattern, element)
+ if type(element) == "string" then
+ element = convert(element,true)
end
-
- local function load_data(name) -- == io.loaddata
- local f, data = io.open(name), ""
- if f then
- data = f:read("*all",'b') -- 'b' ?
- f:close()
- end
- return data
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ traverse(root, lpath(pattern), function(rm, d, k)
+ d[k] = element.dt -- maybe not clever enough
+ end)
end
+end
- function xml.include(xmldata,pattern,attribute,recursive,loaddata)
- -- parse="text" (default: xml), encoding="" (todo)
- -- attribute = attribute or 'href'
- pattern = pattern or 'include'
- loaddata = loaddata or load_data
- local function include(r,d,k)
- local ek, name = d[k], nil
- if not attribute or attribute == "" then
- local ekdt = ek.dt
- name = (type(ekdt) == "table" and ekdt[1]) or ekdt
- end
- if not name then
- if ek.at then
- for a in (attribute or "href"):gmatch("([^|]+)") do
- name = ek.at[a]
- if name then break end
- end
+local function load_data(name) -- == io.loaddata
+ local f, data = io.open(name), ""
+ if f then
+ data = f:read("*all",'b') -- 'b' ?
+ f:close()
+ end
+ return data
+end
+
+function xml.include(xmldata,pattern,attribute,recursive,loaddata)
+ -- parse="text" (default: xml), encoding="" (todo)
+ -- attribute = attribute or 'href'
+ pattern = pattern or 'include'
+ loaddata = loaddata or load_data
+ local function include(r,d,k)
+ local ek, name = d[k], nil
+ if not attribute or attribute == "" then
+ local ekdt = ek.dt
+ name = (type(ekdt) == "table" and ekdt[1]) or ekdt
+ end
+ if not name then
+ if ek.at then
+ for a in gmatch(attribute or "href","([^|]+)") do
+ name = ek.at[a]
+ if name then break end
end
end
- local data = (name and name ~= "" and loaddata(name)) or ""
- if data == "" then
+ end
+ local data = (name and name ~= "" and loaddata(name)) or ""
+ if data == "" then
+ xml.empty(d,k)
+ elseif ek.at["parse"] == "text" then -- for the moment hard coded
+ d[k] = xml.escaped(data)
+ else
+ local xi = xml.convert(data)
+ if not xi then
xml.empty(d,k)
- elseif ek.at["parse"] == "text" then -- for the moment hard coded
- d[k] = xml.escaped(data)
else
- local xi = xml.convert(data)
- if not xi then
- xml.empty(d,k)
- else
- if recursive then
- xml.include(xi,pattern,attribute,recursive,loaddata)
- end
- xml.assign(d,k,xi)
+ if recursive then
+ xml.include(xi,pattern,attribute,recursive,loaddata)
end
+ xml.assign(d,k,xi)
end
end
- xml.each_element(xmldata, pattern, include)
end
+ xml.each_element(xmldata, pattern, include)
+end
- function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space !
- traverse(root, lpath(pattern), function(r,d,k)
- local dkdt = d[k].dt
- if dkdt then -- can be optimized
- local t = { }
- for i=1,#dkdt do
- local str = dkdt[i]
- if type(str) == "string" then
+function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space !
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then -- can be optimized
+ local t = { }
+ for i=1,#dkdt do
+ local str = dkdt[i]
+ if type(str) == "string" then
+ if str == "" then
+ -- stripped
+ else
+ if nolines then
+ str = gsub(str,"[ \n\r\t]+"," ")
+ end
if str == "" then
-- stripped
else
- if nolines then
- str = str:gsub("[ \n\r\t]+"," ")
- end
- if str == "" then
- -- stripped
- else
- t[#t+1] = str
- end
+ t[#t+1] = str
end
- else
- t[#t+1] = str
end
+ else
+ t[#t+1] = str
end
- d[k].dt = t
end
- end)
- end
+ d[k].dt = t
+ end
+ end)
+end
- function xml.rename_space(root, oldspace, newspace) -- fast variant
- local ndt = #root.dt
- local rename = xml.rename_space
- for i=1,ndt or 0 do
- local e = root[i]
- if type(e) == "table" then
- if e.ns == oldspace then
- e.ns = newspace
- if e.rn then
- e.rn = newspace
- end
- end
- local edt = e.dt
- if edt then
- rename(edt, oldspace, newspace)
+local function rename_space(root, oldspace, newspace) -- fast variant
+ local ndt = #root.dt
+ for i=1,ndt or 0 do
+ local e = root[i]
+ if type(e) == "table" then
+ if e.ns == oldspace then
+ e.ns = newspace
+ if e.rn then
+ e.rn = newspace
end
end
+ local edt = e.dt
+ if edt then
+ rename_space(edt, oldspace, newspace)
+ end
end
end
+end
- function xml.remap_tag(root, pattern, newtg)
- traverse(root, lpath(pattern), function(r,d,k)
- d[k].tg = newtg
- end)
- end
- function xml.remap_namespace(root, pattern, newns)
- traverse(root, lpath(pattern), function(r,d,k)
- d[k].ns = newns
- end)
- end
- function xml.check_namespace(root, pattern, newns)
- traverse(root, lpath(pattern), function(r,d,k)
- local dk = d[k]
- if (not dk.rn or dk.rn == "") and dk.ns == "" then
- dk.rn = newns
- end
- end)
- end
- function xml.remap_name(root, pattern, newtg, newns, newrn)
- traverse(root, lpath(pattern), function(r,d,k)
- local dk = d[k]
- dk.tg = newtg
- dk.ns = newns
- dk.rn = newrn
- end)
- end
+xml.rename_space = rename_space
- function xml.filters.found(root,pattern,check_content)
- local found = false
- traverse(root, lpath(pattern), function(r,d,k)
- if check_content then
- local dk = d and d[k]
- found = dk and dk.dt and next(dk.dt) and true
- else
- found = true
- end
- return true
- end)
- return found
- end
+function xml.remap_tag(root, pattern, newtg)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].tg = newtg
+ end)
+end
+function xml.remap_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].ns = newns
+ end)
+end
+function xml.check_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ if (not dk.rn or dk.rn == "") and dk.ns == "" then
+ dk.rn = newns
+ end
+ end)
+end
+function xml.remap_name(root, pattern, newtg, newns, newrn)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ dk.tg = newtg
+ dk.ns = newns
+ dk.rn = newrn
+ end)
+end
+function xml.filters.found(root,pattern,check_content)
+ local found = false
+ traverse(root, lpath(pattern), function(r,d,k)
+ if check_content then
+ local dk = d and d[k]
+ found = dk and dk.dt and next(dk.dt) and true
+ else
+ found = true
+ end
+ return true
+ end)
+ return found
end
--[[ldx--
@@ -4387,10 +4786,12 @@ put them here instead of loading mode modules there then needed.
--ldx]]--
function xml.gsub(t,old,new)
- if t.dt then
- for k,v in ipairs(t.dt) do
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
if type(v) == "string" then
- t.dt[k] = v:gsub(old,new)
+ dt[k] = gsub(v,old,new)
else
xml.gsub(v,old,new)
end
@@ -4415,45 +4816,41 @@ end
--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
---~ function xml.escaped (str) return str:gsub("(.)" , xml.escapes ) end
---~ function xml.unescaped(str) return str:gsub("(&.-;)", xml.unescapes) end
---~ function xml.cleansed (str) return str:gsub("<.->" , '' ) end -- "%b<>"
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
-do
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
- local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
-
- -- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
- --
- -- 1021:0335:0287:0247
-
- -- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
- --
- -- 1559:0257:0288:0190 (last one suggested by roberto)
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
- -- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
- -- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
- local normal = (1 - S("<&>"))^0
- local special = P("<")/"<" + P(">")/">" + P("&")/"&"
- local escaped = Cs(normal * (special * normal)^0)
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
- -- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
- -- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
- -- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
- local normal = (1 - S"&")^0
- local special = P("<")/"<" + P(">")/">" + P("&")/"&"
- local unescaped = Cs(normal * (special * normal)^0)
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
- -- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
- local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
- function xml.escaped (str) return escaped :match(str) end
- function xml.unescaped(str) return unescaped:match(str) end
- function xml.cleansed (str) return cleansed :match(str) end
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
-end
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
function xml.join(t,separator,lastseparator)
if #t > 0 then
@@ -4471,155 +4868,46 @@ function xml.join(t,separator,lastseparator)
end
end
+function xml.statistics()
+ return {
+ lpathcalls = lpathcalls,
+ lpathcached = lpathcached,
+ }
+end
---[[ldx--
-
We provide (at least here) two entity handlers. The more extensive
-resolver consults a hash first, tries to convert to next,
-and finaly calls a handler when defines. When this all fails, the
-original entity is returned.
---ldx]]--
+-- xml.set_text_cleanup(xml.show_text_entities)
+-- xml.set_text_cleanup(xml.resolve_text_entities)
-do if unicode and unicode.utf8 then
+--~ xml.lshow("/../../../a/(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!b[@d!='e']/f")
- xml.entities = xml.entities or { } -- xml.entity_handler == function
+--~ x = xml.convert([[
+--~
+--~ 01
+--~ 02
+--~ 03
+--~ OK
+--~ 05
+--~ 06
+--~ ALSO OK
+--~
+--~ ]])
- function xml.entity_handler(e)
- return format("[%s]",e)
- end
+--~ xml.settrace("lpath",true)
- local char = unicode.utf8.char
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
+--~ xml.xshow(xml.first(x,"b[@n=='03' or @n=='08']"))
+--~ xml.xshow(xml.all (x,"b[number(@n)>2 and number(@n)<6]"))
+--~ xml.xshow(xml.first(x,"b[find(text(),'ALSO')]"))
- local function toutf(s)
- return char(tonumber(s,16))
- end
-
- function utfize(root)
- local d = root.dt
- for k=1,#d do
- local dk = d[k]
- if type(dk) == "string" then
- -- test prevents copying if no match
- if dk:find(".-;") then
- d[k] = dk:gsub("(.-);",toutf)
- end
- else
- utfize(dk)
- end
- end
- end
-
- xml.utfize = utfize
-
- local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
- if e:find("#x") then
- return char(tonumber(e:sub(3),16))
- else
- local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
- if ee then
- return ee
- else
- local h = xml.entity_handler
- return (h and h(e)) or "&" .. e .. ";"
- end
- end
- end
-
- local function resolve_entities(root)
- if not root.special or root.tg == "@rt@" then
- local d = root.dt
- for k=1,#d do
- local dk = d[k]
- if type(dk) == "string" then
- if dk:find("&.-;") then
- d[k] = dk:gsub("&(.-);",resolve)
- end
- else
- resolve_entities(dk)
- end
- end
- end
- end
-
- xml.resolve_entities = resolve_entities
-
- function xml.utfize_text(str)
- if str:find("") then
- return (str:gsub("(.-);",toutf))
- else
- return str
- end
- end
-
- function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
- if str:find("&") then
- return (str:gsub("&(.-);",resolve))
- else
- return str
- end
- end
-
- function xml.show_text_entities(str)
- if str:find("&") then
- return (str:gsub("&(.-);","[%1]"))
- else
- return str
- end
- end
-
- -- experimental, this will be done differently
-
- function xml.merge_entities(root)
- local documententities = root.entities
- local allentities = xml.entities
- if documententities then
- for k, v in pairs(documententities) do
- allentities[k] = v
- end
- end
- end
-
-end end
-
-function xml.statistics()
- return {
- lpathcalls = lpathcalls,
- lpathcached = lpathcached,
- }
-end
-
--- xml.set_text_cleanup(xml.show_text_entities)
--- xml.set_text_cleanup(xml.resolve_text_entities)
-
---~ xml.lshow("/../../../a/(b|c)[@d='e']/f")
---~ xml.lshow("/../../../a/!(b|c)[@d='e']/f")
---~ xml.lshow("/../../../a/!b[@d!='e']/f")
-
---~ x = xml.convert([[
---~
---~ 01
---~ 02
---~ 03
---~ OK
---~ 05
---~ 06
---~ ALSO OK
---~
---~ ]])
-
---~ xml.trace_lpath = true
-
---~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
---~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
---~ xml.xshow(xml.first(x,"b[@n=='03' or @n=='08']"))
---~ xml.xshow(xml.all (x,"b[number(@n)>2 and number(@n)<6]"))
---~ xml.xshow(xml.first(x,"b[find(text(),'ALSO')]"))
-
---~ str = [[
---~
---~
---~ my secret
---~
---~ ]]
+--~ str = [[
+--~
+--~
+--~ my secret
+--~
+--~ ]]
--~ x = xml.convert([[
--~ 0102xx03OK
@@ -4633,177 +4921,522 @@ end
--~ print(xml.filter(x,"b/tag(1)"))
--- filename : l-utils.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+end -- of closure
-if not versions then versions = { } end versions['l-utils'] = 1.001
+do -- create closure to overcome 200 locals limit
-if not utils then utils = { } end
-if not utils.merger then utils.merger = { } end
-if not utils.lua then utils.lua = { } end
+if not modules then modules = { } end modules ['lxml-ent'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-utils.merger.m_begin = "begin library merge"
-utils.merger.m_end = "end library merge"
-utils.merger.pattern =
- "%c+" ..
- "%-%-%s+" .. utils.merger.m_begin ..
- "%c+(.-)%c+" ..
- "%-%-%s+" .. utils.merger.m_end ..
- "%c+"
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub, find = string.format, string.gsub, string.find
+local utfchar = unicode.utf8.char
-function utils.merger._self_fake_()
- return
- "-- " .. "created merged file" .. "\n\n" ..
- "-- " .. utils.merger.m_begin .. "\n\n" ..
- "-- " .. utils.merger.m_end .. "\n\n"
-end
+--[[ldx--
+
We provide (at least here) two entity handlers. The more extensive
+resolver consults a hash first, tries to convert to next,
+and finaly calls a handler when defines. When this all fails, the
+original entity is returned.
+--ldx]]--
-function utils.report(...)
- print(...)
-end
+xml.entities = xml.entities or { } -- xml.entity_handler == function
-utils.merger.strip_comment = true
+function xml.entity_handler(e)
+ return format("[%s]",e)
+end
-function utils.merger._self_load_(name)
- local f, data = io.open(name), ""
- if f then
- utils.report("reading merge from %s",name)
- data = f:read("*all")
- f:close()
- else
- utils.report("unknown file to merge %s",name)
- end
- if data and utils.merger.strip_comment then
- -- saves some 20K
- data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
- end
- return data or ""
+local function toutf(s)
+ return utfchar(tonumber(s,16))
end
-function utils.merger._self_save_(name, data)
- if data ~= "" then
- local f = io.open(name,'w')
- if f then
- utils.report("saving merge from %s",name)
- f:write(data)
- f:close()
+local function utfize(root)
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ -- test prevents copying if no match
+ if find(dk,".-;") then
+ d[k] = gsub(dk,"(.-);",toutf)
+ end
+ else
+ utfize(dk)
end
end
end
-function utils.merger._self_swap_(data,code)
- if data ~= "" then
- return (data:gsub(utils.merger.pattern, function(s)
- return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
- end, 1))
+xml.utfize = utfize
+
+local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
+ if find(e,"^#x") then
+ return utfchar(tonumber(e:sub(3),16))
+ elseif find(e,"^#") then
+ return utfchar(tonumber(e:sub(2)))
else
- return ""
+ local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
+ if ee then
+ return ee
+ else
+ local h = xml.entity_handler
+ return (h and h(e)) or "&" .. e .. ";"
+ end
end
end
-function utils.merger._self_libs_(libs,list)
- local result, f = { }, nil
- if type(libs) == 'string' then libs = { libs } end
- if type(list) == 'string' then list = { list } end
- for _, lib in ipairs(libs) do
- for _, pth in ipairs(list) do
- local name = string.gsub(pth .. "/" .. lib,"\\","/")
- f = io.open(name)
- if f then
- utils.report("merging library %s",name)
- result[#result+1] = f:read("*all")
- f:close()
- list = { pth } -- speed up the search
- break
+local function resolve_entities(root)
+ if not root.special or root.tg == "@rt@" then
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ if find(dk,"&.-;") then
+ d[k] = gsub(dk,"&(.-);",resolve)
+ end
else
- utils.report("no library %s",name)
+ resolve_entities(dk)
end
end
end
- return table.concat(result, "\n\n")
end
-function utils.merger.selfcreate(libs,list,target)
- if target then
- utils.merger._self_save_(
- target,
- utils.merger._self_swap_(
- utils.merger._self_fake_(),
- utils.merger._self_libs_(libs,list)
- )
- )
+xml.resolve_entities = resolve_entities
+
+function xml.utfize_text(str)
+ if find(str,"") then
+ return (gsub(str,"(.-);",toutf))
+ else
+ return str
end
end
-function utils.merger.selfmerge(name,libs,list,target)
- utils.merger._self_save_(
- target or name,
- utils.merger._self_swap_(
- utils.merger._self_load_(name),
- utils.merger._self_libs_(libs,list)
- )
- )
+function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
+ if find(str,"&") then
+ return (gsub(str,"&(.-);",resolve))
+ else
+ return str
+ end
end
-function utils.merger.selfclean(name)
- utils.merger._self_save_(
- name,
- utils.merger._self_swap_(
- utils.merger._self_load_(name),
- ""
- )
- )
+function xml.show_text_entities(str)
+ if find(str,"&") then
+ return (gsub(str,"&(.-);","[%1]"))
+ else
+ return str
+ end
end
-function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
- -- utils.report("compiling",luafile,"into",lucfile)
- os.remove(lucfile)
- local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
- if strip ~= false then
- command = "-s " .. command
- end
- local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
- if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
- -- utils.report("removing",luafile)
- os.remove(luafile)
+-- experimental, this will be done differently
+
+function xml.merge_entities(root)
+ local documententities = root.entities
+ local allentities = xml.entities
+ if documententities then
+ for k, v in next, documententities do
+ allentities[k] = v
+ end
end
- return done
end
+end -- of closure
-if not modules then modules = { } end modules ['luat-lib'] = {
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-mis'] = {
version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
- comment = "companion to luat-lib.tex",
+ license = "see context related readme files"
}
--- most code already moved to the l-*.lua and other luat-*.lua files
+local concat = table.concat
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub = string.format, string.gsub
-os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
-function os.setlocale()
- -- no way you can mess with it
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
end
-if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
- arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
end
-environment = environment or { }
-environment.arguments = { }
-environment.files = { }
-environment.sortedflags = nil
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
-function environment.initialize_arguments(arg)
- local arguments, files = { }, { }
- environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
- for index, argument in pairs(arg) do
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+xml.escaped_pattern = escaped
+xml.unescaped_pattern = unescaped
+xml.cleansed_pattern = cleansed
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
+
+-- dirty tricks
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
+
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
if index > 0 then
local flag, value = argument:match("^%-+(.+)=(.-)$")
if flag then
@@ -4821,24 +5454,20 @@ function environment.initialize_arguments(arg)
environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
end
-function environment.showarguments()
- for k,v in pairs(environment.arguments) do
- print(k .. " : " .. tostring(v))
- end
- if #environment.files > 0 then
- print("files : " .. table.concat(environment.files, " "))
- end
-end
-
function environment.setargument(name,value)
environment.arguments[name] = value
end
-function environment.argument(name) -- todo: default (plus typecheck on default)
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
local arguments, sortedflags = environment.arguments, environment.sortedflags
if arguments[name] then
return arguments[name]
- else
+ elseif partial then
if not sortedflags then
sortedflags = { }
for _,v in pairs(table.sortedkeys(arguments)) do
@@ -4846,6 +5475,7 @@ function environment.argument(name) -- todo: default (plus typecheck on default)
end
environment.sortedflags = sortedflags
end
+ -- example of potential clash: ^mode ^modefile
for _,v in ipairs(sortedflags) do
if name:find(v) then
return arguments[v:sub(2,#v)]
@@ -4869,43 +5499,17 @@ function environment.split_arguments(separator) -- rather special, cut-off befor
return before, after
end
---~ function environment.reconstruct_commandline(arg)
---~ if not arg then arg = environment.original_arguments end
---~ local result = { }
---~ for _,a in ipairs(arg) do -- ipairs 1 .. #n
---~ local kk, vv = a:match("^(%-+.-)=(.+)$")
---~ if kk and vv then
---~ if vv:find(" ") then
---~ vv = vv:unquote()
---~ vv = vv:gsub('"','\\"')
---~ result[#result+1] = kk .. "=" .. vv:quote()
---~ else
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a
---~ end
---~ elseif a:find(" ") then
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a:quote()
---~ else
---~ result[#result+1] = a
---~ end
---~ end
---~ return table.join(result," ")
---~ end
-
function environment.reconstruct_commandline(arg,noquote)
- if not arg then arg = environment.original_arguments end
+ arg = arg or environment.original_arguments
if noquote and #arg == 1 then
local a = arg[1]
- a = input.resolve(a)
+ a = resolvers.resolve(a)
a = a:unquote()
return a
- elseif #arg == 1 then
+ elseif next(arg) then
local result = { }
for _,a in ipairs(arg) do -- ipairs 1 .. #n
- a = input.resolve(a)
+ a = resolvers.resolve(a)
a = a:unquote()
a = a:gsub('"','\\"') -- tricky
if a:find(" ") then
@@ -4915,6 +5519,8 @@ function environment.reconstruct_commandline(arg,noquote)
end
end
return table.join(result," ")
+ else
+ return ""
end
end
@@ -4950,279 +5556,163 @@ if arg then
end
+-- weird place ... depends on a not yet loaded module
-if not modules then modules = { } end modules ['luat-inp'] = {
- version = 1.001,
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
- comment = "companion to luat-lib.tex",
-}
-
--- TODO: os.getenv -> os.env[]
--- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
--- TODO: check escaping in find etc, too much, too slow
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
--- This lib is multi-purpose and can be loaded again later on so that
--- additional functionality becomes available. We will split this
--- module in components once we're done with prototyping. This is the
--- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
--- something in this module one can best check with Taco or Hans first; there
--- is some nasty trickery going on that relates to traditional kpse support.
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
--- To be considered: hash key lowercase, first entry in table filename
--- (any case), rest paths (so no need for optimization). Or maybe a
--- separate table that matches lowercase names to mixed case when
--- present. In that case the lower() cases can go away. I will do that
--- only when we run into problems with names ... well ... Iwona-Regular.
+environment.loadedluacode = loadfile -- can be overloaded
--- Beware, loading and saving is overloaded in luat-tmp!
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
-if not input then input = { } end
-if not input.suffixes then input.suffixes = { } end
-if not input.formats then input.formats = { } end
-if not input.aux then input.aux = { } end
-
-if not input.suffixmap then input.suffixmap = { } end
-
-if not input.locators then input.locators = { } end -- locate databases
-if not input.hashers then input.hashers = { } end -- load databases
-if not input.generators then input.generators = { } end -- generate databases
-if not input.filters then input.filters = { } end -- conversion filters
-
-local format, concat, sortedkeys = string.format, table.concat, table.sortedkeys
-
-input.locators.notfound = { nil }
-input.hashers.notfound = { nil }
-input.generators.notfound = { nil }
-
-input.cacheversion = '1.0.1'
-input.banner = nil
-input.verbose = false
-input.debug = false
-input.cnfname = 'texmf.cnf'
-input.luaname = 'texmfcnf.lua'
-input.lsrname = 'ls-R'
-input.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
-
---~ input.luasuffix = 'tma'
---~ input.lucsuffix = 'tmc'
-
--- for the moment we have .local but this will disappear
-input.cnfdefault = '{$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- chances are low that the cnf file is in the bin path
-input.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- we use a cleaned up list / format=any is a wildcard, as is *name
-
-input.formats['afm'] = 'AFMFONTS' input.suffixes['afm'] = { 'afm' }
-input.formats['enc'] = 'ENCFONTS' input.suffixes['enc'] = { 'enc' }
-input.formats['fmt'] = 'TEXFORMATS' input.suffixes['fmt'] = { 'fmt' }
-input.formats['map'] = 'TEXFONTMAPS' input.suffixes['map'] = { 'map' }
-input.formats['mp'] = 'MPINPUTS' input.suffixes['mp'] = { 'mp' }
-input.formats['ocp'] = 'OCPINPUTS' input.suffixes['ocp'] = { 'ocp' }
-input.formats['ofm'] = 'OFMFONTS' input.suffixes['ofm'] = { 'ofm', 'tfm' }
-input.formats['otf'] = 'OPENTYPEFONTS' input.suffixes['otf'] = { 'otf' } -- 'ttf'
-input.formats['opl'] = 'OPLFONTS' input.suffixes['opl'] = { 'opl' }
-input.formats['otp'] = 'OTPINPUTS' input.suffixes['otp'] = { 'otp' }
-input.formats['ovf'] = 'OVFFONTS' input.suffixes['ovf'] = { 'ovf', 'vf' }
-input.formats['ovp'] = 'OVPFONTS' input.suffixes['ovp'] = { 'ovp' }
-input.formats['tex'] = 'TEXINPUTS' input.suffixes['tex'] = { 'tex' }
-input.formats['tfm'] = 'TFMFONTS' input.suffixes['tfm'] = { 'tfm' }
-input.formats['ttf'] = 'TTFONTS' input.suffixes['ttf'] = { 'ttf', 'ttc' }
-input.formats['pfb'] = 'T1FONTS' input.suffixes['pfb'] = { 'pfb', 'pfa' }
-input.formats['vf'] = 'VFFONTS' input.suffixes['vf'] = { 'vf' }
-
-input.formats['fea'] = 'FONTFEATURES' input.suffixes['fea'] = { 'fea' }
-input.formats['cid'] = 'FONTCIDMAPS' input.suffixes['cid'] = { 'cid', 'cidmap' }
-
-input.formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
-input.suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
-
-input.formats ['lua'] = 'LUAINPUTS' -- new
-input.suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
--- here we catch a few new thingies (todo: add these paths to context.tmf)
---
--- FONTFEATURES = .;$TEXMF/fonts/fea//
--- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+-- the next ones can use the previous ones / combine
-function input.checkconfigdata() -- not yet ok, no time for debugging now
- local instance = input.instance
- local function fix(varname,default)
- local proname = varname .. "." .. instance.progname or "crap"
- local p = instance.environment[proname]
- local v = instance.environment[varname]
- if not ((p and p ~= "") or (v and v ~= "")) then
- instance.variables[varname] = default -- or environment?
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
end
end
- local name = os.name
- if name == "windows" then
- fix("OSFONTDIR", "c:/windows/fonts//")
- elseif name == "macosx" then
- fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
- else
- -- bad luck
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
end
- fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
- fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
- fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ return false
end
--- backward compatible ones
-input.alternatives = { }
+end -- of closure
-input.alternatives['map files'] = 'map'
-input.alternatives['enc files'] = 'enc'
-input.alternatives['cid files'] = 'cid'
-input.alternatives['fea files'] = 'fea'
-input.alternatives['opentype fonts'] = 'otf'
-input.alternatives['truetype fonts'] = 'ttf'
-input.alternatives['truetype collections'] = 'ttc'
-input.alternatives['type1 fonts'] = 'pfb'
+do -- create closure to overcome 200 locals limit
--- obscure ones
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-input.formats ['misc fonts'] = ''
-input.suffixes['misc fonts'] = { }
+local format = string.format
-input.formats ['sfd'] = 'SFDFONTS'
-input.suffixes ['sfd'] = { 'sfd' }
-input.alternatives['subfont definition files'] = 'sfd'
+local statusinfo, n, registered = { }, 0, { }
--- In practice we will work within one tds tree, but i want to keep
--- the option open to build tools that look at multiple trees, which is
--- why we keep the tree specific data in a table. We used to pass the
--- instance but for practical pusposes we now avoid this and use a
--- instance variable.
+statistics = statistics or { }
-function input.newinstance()
+statistics.enable = true
+statistics.threshold = 0.05
- local instance = { }
+-- timing functions
- instance.rootpath = ''
- instance.treepath = ''
- instance.progname = 'context'
- instance.engine = 'luatex'
- instance.format = ''
- instance.environment = { }
- instance.variables = { }
- instance.expansions = { }
- instance.files = { }
- instance.remap = { }
- instance.configuration = { }
- instance.setup = { }
- instance.order = { }
- instance.found = { }
- instance.foundintrees = { }
- instance.kpsevars = { }
- instance.hashes = { }
- instance.cnffiles = { }
- instance.luafiles = { }
- instance.lists = { }
- instance.remember = true
- instance.diskcache = true
- instance.renewcache = false
- instance.scandisk = true
- instance.cachepath = nil
- instance.loaderror = false
- instance.smallcache = false
- instance.sortdata = false
- instance.savelists = true
- instance.cleanuppaths = true
- instance.allresults = false
- instance.pattern = nil -- lists
- instance.kpseonly = false -- lists
- instance.loadtime = 0
- instance.starttime = 0
- instance.stoptime = 0
- instance.validfile = function(path,name) return true end
- instance.data = { } -- only for loading
- instance.force_suffixes = true
- instance.dummy_path_expr = "^!*unset/*$"
- instance.fakepaths = { }
- instance.lsrmode = false
+local clock = os.gettimeofday or os.clock
- -- store once, freeze and faster (once reset we can best use instance.environment)
+function statistics.hastimer(instance)
+ return instance and instance.starttime
+end
- for k,v in pairs(os.env) do
- instance.environment[k] = input.bare_variable(v)
- end
-
- -- cross referencing, delayed because we can add suffixes
-
- for k, v in pairs(input.suffixes) do
- for _, vv in pairs(v) do
- if vv then
- input.suffixmap[vv] = k
- end
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
end
- end
-
- return instance
-
-end
-
-input.instance = input.instance or nil
-
-function input.reset()
- input.instance = input.newinstance()
- return input.instance
-end
-
-function input.reset_hashes()
- input.instance.lists = { }
- input.instance.found = { }
-end
-
-function input.bare_variable(str) -- assumes str is a string
- -- return string.gsub(string.gsub(string.gsub(str,"%s+$",""),'^"(.+)"$',"%1"),"^'(.+)'$","%1")
- return (str:gsub("\s*([\"\']?)(.+)%1\s*", "%2"))
-end
-
-function input.settrace(n)
- input.trace = tonumber(n or 0)
- if input.trace > 0 then
- input.verbose = true
- end
-end
-
-input.log = (texio and texio.write_nl) or print
-
-function input.report(...)
- if input.verbose then
- input.log("<<"..format(...)..">>")
- end
-end
-
-function input.report(...)
- if input.trace > 0 then -- extra test
- input.log("<<"..format(...)..">>")
- end
-end
-
-input.settrace(tonumber(os.getenv("MTX.INPUT.TRACE") or os.getenv("MTX_INPUT_TRACE") or input.trace or 0))
-
--- These functions can be used to test the performance, especially
--- loading the database files.
-
-do
- local clock = os.gettimeofday or os.clock
-
- function input.starttiming(instance)
- if instance then
+ if it == 0 then
instance.starttime = clock()
if not instance.loadtime then
instance.loadtime = 0
end
end
+ instance.timing = it + 1
end
+end
- function input.stoptiming(instance, report)
- if instance then
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
local starttime = instance.starttime
if starttime then
local stoptime = clock()
@@ -5230,2170 +5720,2434 @@ do
instance.stoptime = stoptime
instance.loadtime = instance.loadtime + loadtime
if report then
- input.report("load time %0.3f",loadtime)
+ statistics.report("load time %0.3f",loadtime)
end
+ instance.timing = 0
return loadtime
end
end
- return 0
end
-
+ return 0
end
-function input.elapsedtime(instance)
+function statistics.elapsedtime(instance)
return format("%0.3f",(instance and instance.loadtime) or 0)
end
-function input.report_loadtime(instance)
- if instance then
- input.report('total load time %s', input.elapsedtime(instance))
- end
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
end
-input.loadtime = input.elapsedtime
+-- general function
-function input.env(key)
- return input.instance.environment[key] or input.osenv(key)
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
end
-function input.osenv(key)
- local ie = input.instance.environment
- local value = ie[key]
- if value == nil then
- -- local e = os.getenv(key)
- local e = os.env[key]
- if e == nil then
- -- value = "" -- false
- else
- value = input.bare_variable(e)
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
end
- ie[key] = value
+ statistics.enable = false
end
- return value or ""
end
--- we follow a rather traditional approach:
---
--- (1) texmf.cnf given in TEXMFCNF
--- (2) texmf.cnf searched in default variable
---
--- also we now follow the stupid route: if not set then just assume *one*
--- cnf file under texmf (i.e. distribution)
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
-input.ownpath = input.ownpath or nil
-input.ownbin = input.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
-input.autoselfdir = true -- false may be handy for debugging
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
-function input.getownpath()
- if not input.ownpath then
- if input.autoselfdir and os.selfdir then
- input.ownpath = os.selfdir
- else
- local binary = input.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
- end
- for p in string.gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
- local b = file.join(p,binary)
- if lfs.isfile(b) then
- -- we assume that after changing to the path the currentdir function
- -- resolves to the real location and use this side effect here; this
- -- trick is needed because on the mac installations use symlinks in the
- -- path instead of real locations
- local olddir = lfs.currentdir()
- if lfs.chdir(p) then
- local pp = lfs.currentdir()
- if input.verbose and p ~= pp then
- input.report("following symlink %s to %s",p,pp)
- end
- input.ownpath = pp
- lfs.chdir(olddir)
- else
- if input.verbose then
- input.report("unable to check path %s",p)
- end
- input.ownpath = p
- end
- break
- end
- end
- end
- if not input.ownpath then input.ownpath = '.' end
- end
- return input.ownpath
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
end
-function input.identify_own()
- local instance = input.instance
- local ownpath = input.getownpath() or lfs.currentdir()
- local ie = instance.environment
- if ownpath then
- if input.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
- if input.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
- if input.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
- else
- input.verbose = true
- input.report("error: unable to locate ownpath")
- os.exit()
- end
- if input.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = input.cnfdefault end
- if input.env('TEXOS') == "" then os.env['TEXOS'] = input.env('SELFAUTODIR') end
- if input.env('TEXROOT') == "" then os.env['TEXROOT'] = input.env('SELFAUTOPARENT') end
- if input.verbose then
- for _,v in ipairs({"SELFAUTOLOC","SELFAUTODIR","SELFAUTOPARENT","TEXMFCNF"}) do
- input.report("variable %s set to %s",v,input.env(v) or "unknown")
- end
- end
- function input.identify_own() end
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
end
-function input.identify_cnf()
- local instance = input.instance
- if #instance.cnffiles == 0 then
- -- fallback
- input.identify_own()
- -- the real search
- input.expand_variables()
- local t = input.split_path(input.env('TEXMFCNF'))
- t = input.aux.expanded_path(t)
- input.aux.expand_vars(t) -- redundant
- local function locate(filename,list)
- for _,v in ipairs(t) do
- local texmfcnf = input.normalize_name(file.join(v,filename))
- if lfs.isfile(texmfcnf) then
- table.insert(list,texmfcnf)
- end
- end
- end
- locate(input.luaname,instance.luafiles)
- locate(input.cnfname,instance.cnffiles)
- end
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
end
-function input.load_cnf()
- local instance = input.instance
- local function loadoldconfigdata()
- for _, fname in ipairs(instance.cnffiles) do
- input.aux.load_cnf(fname)
- end
- end
- -- instance.cnffiles contain complete names now !
- if #instance.cnffiles == 0 then
- input.report("no cnf files found (TEXMFCNF may not be set/known)")
- else
- instance.rootpath = instance.cnffiles[1]
- for k,fname in ipairs(instance.cnffiles) do
- instance.cnffiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- if instance.lsrmode then
- loadoldconfigdata()
- elseif instance.diskcache and not instance.renewcache then
- input.loadoldconfig(instance.cnffiles)
- if instance.loaderror then
- loadoldconfigdata()
- input.saveoldconfig()
- end
- else
- loadoldconfigdata()
- if instance.renewcache then
- input.saveoldconfig()
- end
- end
- input.aux.collapse_cnf_data()
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
end
- input.checkconfigdata()
end
-function input.load_lua()
- local instance = input.instance
- if #instance.luafiles == 0 then
- -- yet harmless
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
else
- instance.rootpath = instance.luafiles[1]
- for k,fname in ipairs(instance.luafiles) do
- instance.luafiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- input.loadnewconfig()
- input.aux.collapse_cnf_data()
+ write_nl(category .. " |")
end
- input.checkconfigdata()
end
-function input.aux.collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
- local instance = input.instance
- for _,c in ipairs(instance.order) do
- for k,v in pairs(c) do
- if not instance.variables[k] then
- if instance.environment[k] then
- instance.variables[k] = instance.environment[k]
- else
- instance.kpsevars[k] = true
- instance.variables[k] = input.bare_variable(v)
- end
- end
- end
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
+ else
+ write_nl("")
end
end
-function input.aux.load_cnf(fname)
- local instance = input.instance
- fname = input.clean_path(fname)
- local lname = file.replacesuffix(fname,'lua')
- local f = io.open(lname)
- if f then -- this will go
- f:close()
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- input.aux.load_configuration(dname,lname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
- else
- f = io.open(fname)
- if f then
- input.report("loading %s", fname)
- local line, data, n, k, v
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- instance.configuration[dname] = { }
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
- local data = instance.configuration[dname]
- while true do
- local line, n = f:read(), 0
- if line then
- while true do -- join lines
- line, n = line:gsub("\\%s*$", "")
- if n > 0 then
- line = line .. f:read()
- else
- break
- end
- end
- if not line:find("^[%%#]") then
- local k, v = (line:gsub("%s*%%.*$","")):match("%s*(.-)%s*=%s*(.-)%s*$")
- if k and v and not data[k] then
- data[k] = (v:gsub("[%%#].*",'')):gsub("~", "$HOME")
- instance.kpsevars[k] = true
- end
- end
- else
- break
- end
+local texcount = tex and tex.count
+
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
end
- f:close()
else
- input.report("skipping %s", fname)
+ write(format("[%s",real))
end
+ else
+ write("[-")
end
end
--- database loading
+function logs.tex.stop_page_number()
+ write("]")
+end
-function input.load_hash()
- local instance = input.instance
- input.locatelists()
- if instance.lsrmode then
- input.loadlists()
- elseif instance.diskcache and not instance.renewcache then
- input.loadfiles()
- if instance.loaderror then
- input.loadlists()
- input.savefiles()
- end
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
else
- input.loadlists()
- if instance.renewcache then
- input.savefiles()
- end
+ write_nl(format("",category))
end
end
-
-function input.aux.append_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash append: %s",tag)
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
+ else
+ write_nl("")
end
- table.insert(input.instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
end
-function input.aux.prepend_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash prepend: %s",tag)
- end
- table.insert(input.instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
+
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
end
-function input.aux.extend_texmf_var(specification) -- crap, we could better prepend the hash
- local instance = input.instance
--- local t = input.expanded_path_list('TEXMF') -- full expansion
- local t = input.split_path(input.env('TEXMF'))
- table.insert(t,1,specification)
- local newspec = table.join(t,";")
- if instance.environment["TEXMF"] then
- instance.environment["TEXMF"] = newspec
- elseif instance.variables["TEXMF"] then
- instance.variables["TEXMF"] = newspec
- else
- -- weird
- end
- input.expand_variables()
- input.reset_hashes()
+function logs.xml.stop_run()
+ write_nl("")
end
--- locators
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
+
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
+end
+
+function logs.xml.report_output_log()
end
-function input.locatedatabase(specification)
- return input.methodhandler('locators', specification)
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
end
-function input.locators.tex(specification)
- if specification and specification ~= '' and lfs.isdir(specification) then
- if input.trace > 0 then
- input.logger('! tex locator found: %s',specification)
- end
- input.aux.append_hash('file',specification,filename)
- elseif input.trace > 0 then
- input.logger('? tex locator not found: %s',specification)
+local level = 0
+
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
+end
+
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
+end
+
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
+end
+
+--
+
+local name, banner = 'report', 'context'
+
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
end
end
--- hashers
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
+ end
+end
-function input.hashdatabase(tag,name)
- return input.methodhandler('hashers',tag,name)
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
+ end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
end
-function input.loadfiles()
- local instance = input.instance
- instance.loaderror = false
- instance.files = { }
- if not instance.renewcache then
- for _, hash in ipairs(instance.hashes) do
- input.hashdatabase(hash.tag,hash.name)
- if instance.loaderror then break end
- end
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
+ else
+ trackers.disable("resolvers.verbose")
end
+ logs.verbose = what or false
end
-function input.hashers.tex(tag,name)
- input.aux.load_files(tag)
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
+ end
end
--- generators:
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
-function input.loadlists()
- for _, hash in ipairs(input.instance.hashes) do
- input.generatedatabase(hash.tag)
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
end
end
-function input.generatedatabase(specification)
- return input.methodhandler('generators', specification)
+function logs.reportline() -- for scripts too
+ logs.report()
end
-local weird = lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+logs.simpleline = logs.reportline
-function input.generators.tex(specification)
- local instance = input.instance
- local tag = specification
- if not instance.lsrmode and lfs.dir then
- input.report("scanning path %s",specification)
- instance.files[tag] = { }
- local files = instance.files[tag]
- local n, m, r = 0, 0, 0
- local spec = specification .. '/'
- local attributes = lfs.attributes
- local directory = lfs.dir
- local small = instance.smallcache
- local function action(path)
- local mode, full
- if path then
- full = spec .. path .. '/'
- else
- full = spec
- end
- for name in directory(full) do
- if name:find("^%.") then
- -- skip
- -- elseif name:find("[%~%`%!%#%$%%%^%&%*%(%)%=%{%}%[%]%:%;\"\'%|%<%>%,%?\n\r\t]") then -- too much escaped
- elseif weird:match(name) then
- -- texio.write_nl("skipping " .. name)
- -- skip
- else
- mode = attributes(full..name,'mode')
- if mode == 'directory' then
- m = m + 1
- if path then
- action(path..'/'..name)
- else
- action(name)
- end
- elseif path and mode == 'file' then
- n = n + 1
- local f = files[name]
- if f then
- if not small then
- if type(f) == 'string' then
- files[name] = { f, path }
- else
- f[#f+1] = path
- end
- end
- else
- files[name] = path
- local lower = name:lower()
- if name ~= lower then
- files["remap:"..lower] = name
- r = r + 1
- end
- end
- end
- end
- end
- end
- action()
- input.report("%s files found on %s directories with %s uppercase remappings",n,m,r)
- else
- local fullname = file.join(specification,input.lsrname)
- local path = '.'
- local f = io.open(fullname)
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
+ end
+end
+
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
if f then
- instance.files[tag] = { }
- local files = instance.files[tag]
- local small = instance.smallcache
- input.report("loading lsr file %s",fullname)
- -- for line in f:lines() do -- much slower then the next one
- for line in (f:read("*a")):gmatch("(.-)\n") do
- if line:find("^[%a%d]") then
- local fl = files[line]
- if fl then
- if not small then
- if type(fl) == 'string' then
- files[line] = { fl, path } -- table
- else
- fl[#fl+1] = path
- end
- end
- else
- files[line] = path -- string
- local lower = line:lower()
- if line ~= lower then
- files["remap:"..lower] = line
- end
- end
- else
- path = line:match("%.%/(.-)%:$") or path -- match could be nil due to empty line
- end
- end
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
f:close()
+ break
+ else
+ sleep(0.1)
end
end
end
--- savers, todo
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
-function input.savefiles()
- input.aux.save_data('files', function(k,v)
- return input.instance.validfile(k,v) -- path, name
- end)
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
end
--- A config (optionally) has the paths split in tables. Internally
--- we join them and split them after the expansion has taken place. This
--- is more convenient.
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
-function input.splitconfig()
- for i,c in ipairs(input.instance) do
- for k,v in pairs(c) do
- if type(v) == 'string' then
- local t = file.split_path(v)
- if #t > 1 then
- c[k] = t
- end
- end
- end
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
end
+
+ return newinstance
+
end
-function input.joinconfig()
- for i,c in ipairs(input.instance.order) do
- for k,v in pairs(c) do
- if type(v) == 'table' then
- c[k] = file.join_path(v)
- end
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
end
end
-end
-function input.split_path(str)
- if type(str) == 'table' then
- return str
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
else
- return file.split_path(str)
+ -- bad luck
end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
end
-function input.join_path(str)
- if type(str) == 'table' then
- return file.join_path(str)
- else
- return str
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
end
end
-function input.splitexpansions()
- local ie = input.instance.expansions
- for k,v in pairs(ie) do
- local t, h = { }, { }
- for _,vv in pairs(file.split_path(v)) do
- if vv ~= "" and not h[vv] then
- t[#t+1] = vv
- h[vv] = true
- end
- end
- if #t > 1 then
- ie[k] = t
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
else
- ie[k] = t[1]
+ value = resolvers.bare_variable(e)
end
+ ie[key] = value
end
+ return value or ""
end
--- end of split/join code
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
-function input.saveoldconfig()
- input.splitconfig()
- input.aux.save_data('configuration', nil)
- input.joinconfig()
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
end
-input.configbanner = [[
--- This is a Luatex configuration file created by 'luatools.lua' or
--- 'luatex.exe' directly. For comment, suggestions and questions you can
--- contact the ConTeXt Development Team. This configuration file is
--- not copyrighted. [HH & TH]
-]]
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
-function input.serialize(files)
- -- This version is somewhat optimized for the kind of
- -- tables that we deal with, so it's much faster than
- -- the generic serializer. This makes sense because
- -- luatools and mtxtools are called frequently. Okay,
- -- we pay a small price for properly tabbed tables.
- local t = { }
- local function dump(k,v,m)
- if type(v) == 'string' then
- return m .. "['" .. k .. "']='" .. v .. "',"
- elseif #v == 1 then
- return m .. "['" .. k .. "']='" .. v[1] .. "',"
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
else
- return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
end
end
- t[#t+1] = "return {"
- if input.instance.sortdata then
- for _, k in pairs(sortedkeys(files)) do
- local fk = files[k]
- if type(fk) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for _, kk in pairs(sortedkeys(fk)) do
- t[#t+1] = dump(kk,fk[kk],"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,fk,"\t")
- end
- end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
else
- for k, v in pairs(files) do
- if type(v) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for kk,vv in pairs(v) do
- t[#t+1] = dump(kk,vv,"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,v,"\t")
- end
- end
+ return false
end
- t[#t+1] = "}"
- return concat(t,"\n")
end
-if not texmf then texmf = {} end -- no longer needed, at least not here
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
-function input.aux.save_data(dataname, check, makename) -- untested without cache overload
- for cachename, files in pairs(input.instance[dataname]) do
- local name = (makename or file.join)(cachename,dataname)
- local luaname, lucname = name .. ".lua", name .. ".luc"
- input.report("preparing %s for %s",dataname,cachename)
- for k, v in pairs(files) do
- if not check or check(v,k) then -- path, name
- if type(v) == "table" and #v == 1 then
- files[k] = v[1]
- end
- else
- files[k] = nil -- false
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
end
end
- local data = {
- type = dataname,
- root = cachename,
- version = input.cacheversion,
- date = os.date("%Y-%m-%d"),
- time = os.date("%H:%M:%S"),
- content = files,
- }
- local ok = io.savedata(luaname,input.serialize(data))
- if ok then
- input.report("%s saved in %s",dataname,luaname)
- if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
- input.report("%s compiled to %s",dataname,lucname)
- else
- input.report("compiling failed for %s, deleting file %s",dataname,lucname)
- os.remove(lucname)
- end
- else
- input.report("unable to save %s in %s (access error)",dataname,luaname)
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
end
end
+ return t
end
-function input.aux.load_data(pathname,dataname,filename,makename) -- untested without cache overload
- local instance = input.instance
- filename = ((not filename or (filename == "")) and dataname) or filename
- filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
- local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
- if blob then
- local data = blob()
- if data and data.content and data.type == dataname and data.version == input.cacheversion then
- input.report("loading %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = data.content
- else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
end
else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
end
+ return newlist
end
--- some day i'll use the nested approach, but not yet (actually we even drop
--- engine/progname support since we have only luatex now)
+-- we follow a rather traditional approach:
--
--- first texmfcnf.lua files are located, next the cached texmf.cnf files
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
--
--- return {
--- TEXMFBOGUS = 'effe checken of dit werkt',
--- }
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
-function input.aux.load_texmfcnf(dataname,pathname)
- local instance = input.instance
- local filename = file.join(pathname,input.luaname)
- local blob = loadfile(filename)
- if blob then
- local data = blob()
- if data then
- input.report("loading configuration file %s",filename)
- if true then
- -- flatten to variable.progname
- local t = { }
- for k, v in pairs(data) do -- v = progname
- if type(v) == "string" then
- t[k] = v
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
else
- for kk, vv in pairs(v) do -- vv = variable
- if type(vv) == "string" then
- t[vv.."."..v] = kk
- end
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
end
+ resolvers.ownpath = p
end
+ break
end
- instance[dataname][pathname] = t
- else
- instance[dataname][pathname] = data
end
- else
- input.report("skipping configuration file %s",filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
end
- else
- input.report("skipping configuration file %s",filename)
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
end
+ return resolvers.ownpath
end
-function input.aux.load_configuration(dname,lname)
- input.aux.load_data(dname,'configuration',lname and file.basename(lname))
-end
-function input.aux.load_files(tag)
- input.aux.load_data(tag,'files')
-end
-
-function input.resetconfig()
- input.identify_own()
- local instance = input.instance
- instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
-end
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
-function input.loadnewconfig()
- local instance = input.instance
- for _, cnf in ipairs(instance.luafiles) do
- local dname = file.dirname(cnf)
- input.aux.load_texmfcnf('setup',dname)
- instance.order[#instance.order+1] = instance.setup[dname]
- if instance.loaderror then break end
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
end
-end
-
-function input.loadoldconfig()
- local instance = input.instance
- if not instance.renewcache then
- for _, cnf in ipairs(instance.cnffiles) do
- local dname = file.dirname(cnf)
- input.aux.load_configuration(dname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- if instance.loaderror then break end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
end
end
- input.joinconfig()
+ identify_own = function() end
end
-function input.expand_variables()
- local instance = input.instance
- local expansions, environment, variables = { }, instance.environment, instance.variables
- local env = input.env
- instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
- for k,v in pairs(environment) do
- local a, b = k:match("^(%a+)%_(.*)%s*$")
- if a and b then
- expansions[a..'.'..b] = v
- else
- expansions[k] = v
- end
- end
- for k,v in pairs(environment) do -- move environment to expansions
- if not expansions[k] then expansions[k] = v end
- end
- for k,v in pairs(variables) do -- move variables to expansions
- if not expansions[k] then expansions[k] = v end
- end
- while true do
- local busy = false
- for k,v in pairs(expansions) do
- local s, n = v:gsub("%$([%a%d%_%-]+)", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- local s, m = s:gsub("%$%{([%a%d%_%-]+)%}", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- if n > 0 or m > 0 then
- expansions[k]= s
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
end
end
- if not busy then break end
- end
- for k,v in pairs(expansions) do
- expansions[k] = v:gsub("\\", '/')
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
end
end
-function input.aux.expand_vars(lst) -- simple vars
- local instance = input.instance
- local variables, env = instance.variables, input.env
- for k,v in pairs(lst) do
- lst[k] = v:gsub("%$([%a%d%_%-]+)", function(a)
- return variables[a] or env(a)
- end)
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
end
end
-function input.aux.expanded_var(var) -- simple vars
- local instance = input.instance
- return var:gsub("%$([%a%d%_%-]+)", function(a)
- return instance.variables[a] or input.env(a)
- end)
-end
-
-function input.aux.entry(entries,name)
- if name and (name ~= "") then
- local instance = input.instance
- name = name:gsub('%$','')
- local result = entries[name..'.'..instance.progname] or entries[name]
- if result then
- return result
- else
- result = input.env(name)
- if result then
- instance.variables[name] = result
- input.expand_variables()
- return instance.expansions[name] or ""
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
end
end
end
- return ""
-end
-function input.variable(name)
- return input.aux.entry(input.instance.variables,name)
-end
-function input.expansion(name)
- return input.aux.entry(input.instance.expansions,name)
end
-function input.aux.is_entry(entries,name)
- if name and name ~= "" then
- name = name:gsub('%$','')
- return (entries[name..'.'..input.instance.progname] or entries[name]) ~= nil
- else
- return false
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
end
-end
-
-function input.is_variable(name)
- return input.aux.is_entry(input.instance.variables,name)
-end
-
-function input.is_expansion(name)
- return input.aux.is_entry(input.instance.expansions,name)
-end
-
-function input.unexpanded_path_list(str)
- local pth = input.variable(str)
- local lst = input.split_path(pth)
- return input.aux.expanded_path(lst)
-end
-
-function input.unexpanded_path(str)
- return file.join_path(input.unexpanded_path_list(str))
-end
-
-do
- local done = { }
-
- function input.reset_extra_path()
- local instance = input.instance
- local ep = instance.extra_paths
- if not ep then
- ep, done = { }, { }
- instance.extra_paths = ep
- elseif #ep > 0 then
- instance.lists, done = { }, { }
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
end
- end
-
- function input.register_extra_path(paths,subpaths)
- local instance = input.instance
- local ep = instance.extra_paths or { }
- local n = #ep
- if paths and paths ~= "" then
- if subpaths and subpaths ~= "" then
- for p in paths:gmatch("[^,]+") do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = p .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
- else
- for p in paths:gmatch("[^,]+") do
- if not done[p] then
- ep[#ep+1] = input.clean_path(p)
- done[p] = true
- end
- end
- end
- elseif subpaths and subpaths ~= "" then
- for i=1,n do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = ep[i] .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
end
- if #ep > 0 then
- instance.extra_paths = ep -- register paths
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
end
- if #ep > n then
- instance.lists = { } -- erase the cache
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
end
+ collapse_cnf_data()
end
-
+ check_configuration()
end
-function input.expanded_path_list(str)
- local instance = input.instance
- local function made_list(list)
- local ep = instance.extra_paths
- if not ep or #ep == 0 then
- return list
- else
- local done, new = { }, { }
- -- honour . .. ../.. but only when at the start
- for k, v in ipairs(list) do
- if not done[v] then
- if v:find("^[%.%/]$") then
- done[v] = true
- new[#new+1] = v
- else
- break
- end
- end
- end
- -- first the extra paths
- for k, v in ipairs(ep) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- -- next the formal paths
- for k, v in ipairs(list) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- return new
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
end
- end
- if not str then
- return ep or { }
- elseif instance.savelists then
- -- engine+progname hash
- str = str:gsub("%$","")
- if not instance.lists[str] then -- cached
- local lst = made_list(input.split_path(input.expansion(str)))
- instance.lists[str] = input.aux.expanded_path(lst)
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
end
- return instance.lists[str]
- else
- local lst = input.split_path(input.expansion(str))
- return made_list(input.aux.expanded_path(lst))
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
end
+ check_configuration()
end
+-- database loading
-function input.clean_path_list(str)
- local t = input.expanded_path_list(str)
- if t then
- for i=1,#t do
- t[i] = file.collapse_path(input.clean_path(t[i]))
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
end
end
- return t
end
-function input.expand_path(str)
- return file.join_path(input.expanded_path_list(str))
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
end
-function input.expanded_path_list_from_var(str) -- brrr
- local tmp = input.var_of_format_or_suffix(str:gsub("%$",""))
- if tmp ~= "" then
- return input.expanded_path_list(str)
- else
- return input.expanded_path_list(tmp)
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
end
-end
-function input.expand_path_from_var(str)
- return file.join_path(input.expanded_path_list_from_var(str))
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
end
-function input.format_of_var(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
-end
-function input.format_of_suffix(str)
- return input.suffixmap[file.extname(str)] or 'tex'
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
end
-function input.variable_of_format(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
-end
+-- locators
-function input.var_of_format_or_suffix(str)
- local v = input.formats[str]
- if v then
- return v
- end
- v = input.formats[input.alternatives[str]]
- if v then
- return v
- end
- v = input.suffixmap[file.extname(str)]
- if v then
- return input.formats[isf]
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
end
- return ''
end
-function input.expand_braces(str) -- output variable and brace expansion of STRING
- local ori = input.variable(str)
- local pth = input.aux.expanded_path(input.split_path(ori))
- return file.join_path(pth)
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
end
--- {a,b,c,d}
--- a,b,c/{p,q,r},d
--- a,b,c/{p,q,r}/d/{x,y,z}//
--- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
--- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
--- a{b,c}{d,e}f
--- {a,b,c,d}
--- {a,b,c/{p,q,r},d}
--- {a,b,c/{p,q,r}/d/{x,y,z}//}
--- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
--- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
--- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
-
--- this one is better and faster, but it took me a while to realize
--- that this kind of replacement is cleaner than messy parsing and
--- fuzzy concatenating we can probably gain a bit with selectively
--- applying lpeg, but experiments with lpeg parsing this proved not to
--- work that well; the parsing is ok, but dealing with the resulting
--- table is a pain because we need to work inside-out recursively
-
-function input.aux.splitpathexpr(str, t, validate)
- -- no need for optimization, only called a few times, we can use lpeg for the sub
- t = t or { }
- str = str:gsub(",}",",@}")
- str = str:gsub("{,","{@,")
- -- str = "@" .. str .. "@"
- while true do
- local done = false
- while true do
- local ok = false
- str = str:gsub("([^{},]+){([^{}]+)}", function(a,b)
- local t = { }
- for s in b:gmatch("[^,]+") do t[#t+1] = a .. s end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- while true do
- local ok = false
- str = str:gsub("{([^{}]+)}([^{},]+)", function(a,b)
- local t = { }
- for s in a:gmatch("[^,]+") do t[#t+1] = s .. b end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- while true do
- local ok = false
- str = str:gsub("{([^{}]+)}{([^{}]+)}", function(a,b)
- local t = { }
- for sa in a:gmatch("[^,]+") do
- for sb in b:gmatch("[^,]+") do
- t[#t+1] = sa .. sb
- end
- end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- str = str:gsub("({[^{}]*){([^{}]+)}([^{}]*})", function(a,b,c)
- done = true
- return a .. b.. c
- end)
- if not done then break end
- end
- str = str:gsub("[{}]", "")
- str = str:gsub("@","")
- if validate then
- for s in str:gmatch("[^,]+") do
- s = validate(s)
- if s then t[#t+1] = s end
- end
- else
- for s in str:gmatch("[^,]+") do
- t[#t+1] = s
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
end
- return t
end
-function input.aux.expanded_path(pathlist) -- maybe not a list, just a path
- local instance = input.instance
- -- a previous version fed back into pathlist
- local newlist, ok = { }, false
- for _,v in ipairs(pathlist) do
- if v:find("[{}]") then
- ok = true
- break
- end
- end
- if ok then
- for _, v in ipairs(pathlist) do
- input.aux.splitpathexpr(v, newlist, function(s)
- s = file.collapse_path(s)
- return s ~= "" and not s:find(instance.dummy_path_expr) and s
- end)
- end
- else
- for _,v in ipairs(pathlist) do
- for vv in string.gmatch(v..',',"(.-),") do
- vv = file.collapse_path(v)
- if vv ~= "" then newlist[#newlist+1] = vv end
- end
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
end
end
- return newlist
end
-input.is_readable = { }
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
-function input.aux.is_readable(readable, name)
- if input.trace > 2 then
- if readable then
- input.logger("+ readable: %s",name)
- else
- input.logger("- readable: %s", name)
- end
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
end
- return readable
end
-function input.is_readable.file(name)
- return input.aux.is_readable(lfs.isfile(name), name)
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
end
-input.is_readable.tex = input.is_readable.file
+-- starting with . or .. etc or funny char
--- name
--- name/name
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
-function input.aux.collect_files(names)
- local instance = input.instance
- local filelist = { }
- for _, fname in pairs(names) do
- if fname then
- if input.trace > 2 then
- input.logger("? blobpath asked: %s",fname)
- end
- local bname = file.basename(fname)
- local dname = file.dirname(fname)
- if dname == "" or dname:find("^%.") then
- dname = false
- else
- dname = "/" .. dname .. "$"
- end
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local files = blobpath and instance.files[blobpath]
- if files then
- if input.trace > 2 then
- input.logger('? blobpath do: %s (%s)',blobpath,bname)
- end
- local blobfile = files[bname]
- if not blobfile then
- local rname = "remap:"..bname
- blobfile = files[rname]
- if blobfile then
- bname = files[rname]
- blobfile = files[bname]
- end
- end
- if blobfile then
- if type(blobfile) == 'string' then
- if not dname or blobfile:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,blobfile,bname), -- search
- input.concatinators[hash.type](blobpath,blobfile,bname) -- result
- }
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
end
- else
- for _, vv in pairs(blobfile) do
- if not dname or vv:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,vv,bname), -- search
- input.concatinators[hash.type](blobpath,vv,bname) -- result
- }
- end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
end
end
end
- elseif input.trace > 1 then
- input.logger('! blobpath no: %s (%s)',blobpath,bname)
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
end
end
end
end
- if #filelist > 0 then
- return filelist
- else
- return nil
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
end
end
-function input.suffix_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str][1]
- else
- return ""
- end
-end
+-- savers, todo
-function input.suffixes_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str]
- else
- return {}
- end
+function resolvers.savefiles()
+ resolvers.save_data('files')
end
-do
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
- -- called about 700 times for an empty doc (font initializations etc)
- -- i need to weed the font files for redundant calls
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
- local letter = lpeg.R("az","AZ")
- local separator = lpeg.P("://")
-
- local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator
- local rootbased = lpeg.P("/") + letter*lpeg.P(":")
-
- -- ./name ../name /name c: ://
- function input.aux.qualified_path(filename)
- return qualified:match(filename)
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
end
- function input.aux.rootbased_path(filename)
- return rootbased:match(filename)
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
end
-
- function input.normalize_name(original)
- return original
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
end
-
- input.normalize_name = file.collapse_path
-
end
-function input.aux.register_in_trees(name)
- if not name:find("^%.") then
- local instance = input.instance
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
end
end
--- split the next one up, better for jit
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
-function input.aux.find_file(filename) -- todo : plugin (scanners, checkers etc)
- local instance = input.instance
- local result = { }
- local stamp = nil
- filename = input.normalize_name(filename) -- elsewhere
- filename = file.collapse_path(filename:gsub("\\","/")) -- elsewhere
- -- speed up / beware: format problem
- if instance.remember then
- stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
- if instance.found[stamp] then
- if input.trace > 0 then
- input.logger('! remembered: %s',filename)
- end
- return instance.found[stamp]
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
end
end
- if filename:find('%*') then
- if input.trace > 0 then
- input.logger('! wildcard: %s', filename)
- end
- result = input.find_wildcard_files(filename)
- elseif input.aux.qualified_path(filename) then
- if input.is_readable.file(filename) then
- if input.trace > 0 then
- input.logger('! qualified: %s', filename)
- end
- result = { filename }
- else
- local forcedname, ok = "", false
- if file.extname(filename) == "" then
- if instance.format == "" then
- forcedname = filename .. ".tex"
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing standard filetype: tex')
- end
- result, ok = { forcedname }, true
- end
- else
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- forcedname = filename .. "." .. s
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing format filetype: %s', s)
- end
- result, ok = { forcedname }, true
- break
- end
- end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
end
- end
- if not ok and input.trace > 0 then
- input.logger('? qualified: %s', filename)
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
end
end
else
- -- search spec
- local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
- if ext == "" then
- if not instance.force_suffixes then
- wantedfiles[#wantedfiles+1] = filename
- end
- else
- wantedfiles[#wantedfiles+1] = filename
- end
- if instance.format == "" then
- if ext == "" then
- local forcedname = filename .. '.tex'
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = input.format_of_suffix(forcedname)
- if input.trace > 0 then
- input.logger('! forcing filetype: %s',filetype)
- end
- else
- filetype = input.format_of_suffix(filename)
- if input.trace > 0 then
- input.logger('! using suffix based filetype: %s',filetype)
- end
- end
- else
- if ext == "" then
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
end
- filetype = instance.format
- if input.trace > 0 then
- input.logger('! using given filetype: %s',filetype)
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
end
end
- local typespec = input.variable_of_format(filetype)
- local pathlist = input.expanded_path_list(typespec)
- if not pathlist or #pathlist == 0 then
- -- no pathlist, access check only / todo == wildcard
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- input.logger('? filetype: %s',filetype or '?')
- input.logger('? wanted files: %s',concat(wantedfiles," | "))
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
end
- for _, fname in pairs(wantedfiles) do
- if fname and input.is_readable.file(fname) then
- filename, done = fname, true
- result[#result+1] = file.join('.',fname)
- break
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
end
+ os.remove(lucname)
end
- -- this is actually 'other text files' or 'any' or 'whatever'
- local filelist = input.aux.collect_files(wantedfiles)
- local fl = filelist and filelist[1]
- if fl then
- filename = fl[3]
- result[#result+1] = filename
- done = true
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
end
+ instance[dataname][pathname] = data.content
else
- -- list search
- local filelist = input.aux.collect_files(wantedfiles)
- local doscan, recurse
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- -- if pathlist then input.logger('? path list: %s',concat(pathlist," | ")) end
- -- if filelist then input.logger('? file list: %s',concat(filelist," | ")) end
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
end
- -- a bit messy ... esp the doscan setting here
- for _, path in pairs(pathlist) do
- if path:find("^!!") then doscan = false else doscan = true end
- if path:find("//$") then recurse = true else recurse = false end
- local pathname = path:gsub("^!+", '')
- done = false
- -- using file list
- if filelist and not (done and not instance.allresults) and recurse then
- -- compare list entries with permitted pattern
- pathname = pathname:gsub("([%-%.])","%%%1") -- this also influences
- pathname = pathname:gsub("/+$", '/.*') -- later usage of pathname
- pathname = pathname:gsub("//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname
- -- input.debug('?',expr)
- for _, fl in ipairs(filelist) do
- local f = fl[2]
- if f:find(expr) then
- -- input.debug('T',' '..f)
- if input.trace > 2 then
- input.logger('= found in hash: %s',f)
- end
- --- todo, test for readable
- result[#result+1] = fl[3]
- input.aux.register_in_trees(f) -- for tracing used files
- done = true
- if not instance.allresults then break end
- else
- -- input.debug('F',' '..f)
- end
- end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
end
- if not done and doscan then
- -- check if on disk / unchecked / does not work at all / also zips
- if input.method_is_file(pathname) then -- ?
- local pname = pathname:gsub("%.%*$",'')
- if not pname:find("%*") then
- local ppname = pname:gsub("/+$","")
- if input.aux.can_be_dir(ppname) then
- for _, w in pairs(wantedfiles) do
- local fname = file.join(ppname,w)
- if input.is_readable.file(fname) then
- if input.trace > 2 then
- input.logger('= found by scanning: %s',fname)
- end
- result[#result+1] = fname
- done = true
- if not instance.allresults then break end
- end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
end
- else
- -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
end
end
end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
end
- if not done and doscan then
- -- todo: slow path scanning
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
end
- if done and not instance.allresults then break end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
end
- for k,v in pairs(result) do
- result[k] = file.collapse_path(v)
- end
- if instance.remember then
- instance.found[stamp] = result
- end
- return result
end
-input.aux._find_file_ = input.aux.find_file -- frozen variant
-
-function input.aux.find_file(filename) -- maybe make a lowres cache too
- local result = input.aux._find_file_(filename)
- if #result == 0 then
- local lowered = filename:lower()
- if filename ~= lowered then
- return input.aux._find_file_(lowered)
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
end
end
- return result
+ resolvers.joinconfig()
end
-function input.aux.can_be_dir(name)
- local instance = input.instance
- if not instance.fakepaths[name] then
- if lfs.isdir(name) then
- instance.fakepaths[name] = 1 -- directory
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
else
- instance.fakepaths[name] = 2 -- no directory
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
end
- return (instance.fakepaths[name] == 1)
end
-if not input.concatinators then input.concatinators = { } end
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
-input.concatinators.tex = file.join
-input.concatinators.file = input.concatinators.tex
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
-function input.find_files(filename,filetype,mustexist)
- local instance = input.instance
- if type(mustexist) == boolean then
- -- all set
- elseif type(filetype) == 'boolean' then
- filetype, mustexist = nil, false
- elseif type(filetype) ~= 'string' then
- filetype, mustexist = nil, false
- end
- instance.format = filetype or ''
- local t = input.aux.find_file(filename,true)
- instance.format = ''
- return t
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
end
-function input.find_file(filename,filetype,mustexist)
- return (input.find_files(filename,filetype,mustexist)[1] or "")
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
end
-function input.find_given_files(filename)
- local instance = input.instance
- local bname, result = file.basename(filename), { }
- for k, hash in ipairs(instance.hashes) do
- local files = instance.files[hash.tag]
- local blist = files[bname]
- if not blist then
- local rname = "remap:"..bname
- blist = files[rname]
- if blist then
- bname = files[rname]
- blist = files[bname]
- end
- end
- if blist then
- if type(blist) == 'string' then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- if not instance.allresults then break end
- else
- for kk,vv in pairs(blist) do
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- if not instance.allresults then break end
- end
- end
- end
- end
- return result
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
end
-function input.find_given_file(filename)
- return (input.find_given_files(filename)[1] or "")
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
end
-function input.find_wildcard_files(filename) -- todo: remap:
- local instance = input.instance
- local result = { }
- local bname, dname = file.basename(filename), file.dirname(filename)
- local path = dname:gsub("^*/","")
- path = path:gsub("*",".*")
- path = path:gsub("-","%%-")
- if dname == "" then
- path = ".*"
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
end
- local name = bname
- name = name:gsub("*",".*")
- name = name:gsub("-","%%-")
- path = path:lower()
- name = name:lower()
- local function doit(blist,bname,hash,allresults)
- local done = false
- if blist then
- if type(blist) == 'string' then
- -- make function and share code
- if (blist:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- done = true
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
end
else
- for kk,vv in pairs(blist) do
- if (vv:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- done = true
- if not allresults then break end
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
end
end
end
- end
- return done
- end
- local files, allresults, done = instance.files, instance.allresults, false
- if name:find("%*") then
- for k, hash in ipairs(instance.hashes) do
- for kk, hh in pairs(files[hash.tag]) do
- if not kk:find("^remap:") then
- if (kk:lower()):find(name) then
- if doit(hh,kk,hash,allresults) then done = true end
- if done and not allresults then break end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
end
end
end
end
- else
- for k, hash in ipairs(instance.hashes) do
- if doit(files[hash.tag][bname],bname,hash,allresults) then done = true end
- if done and not allresults then break end
- end
- end
- -- we can consider also searching the paths not in the database, but then
- -- we end up with a messy search (all // in all path specs)
- return result
-end
-
-function input.find_wildcard_file(filename)
- return (input.find_wildcard_files(filename)[1] or "")
-end
-
--- main user functions
-
-function input.save_used_files_in_trees(filename,jobname)
- local instance = input.instance
- if not filename then filename = 'luatex.jlg' end
- local f = io.open(filename,'w')
- if f then
- f:write("\n")
- f:write("\n")
- if jobname then
- f:write("\t" .. jobname .. "\n")
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
end
- f:write("\t\n")
- for _,v in pairs(sorted(instance.foundintrees)) do -- ipairs
- f:write("\t\t" .. v .. "\n")
+ if #ep > n then
+ instance.lists = { } -- erase the cache
end
- f:write("\t\n")
- f:write("\n")
- f:close()
end
-end
-
-function input.automount()
- -- implemented later
-end
-function input.load()
- input.starttiming(input.instance)
- input.resetconfig()
- input.identify_cnf()
- input.load_lua()
- input.expand_variables()
- input.load_cnf()
- input.expand_variables()
- input.load_hash()
- input.automount()
- input.stoptiming(input.instance)
end
-function input.for_files(command, files, filetype, mustexist)
- if files and #files > 0 then
- local function report(str)
- if input.verbose then
- input.report(str) -- has already verbose
- else
- print(str)
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
end
end
- if input.verbose then
- report('')
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
end
- for _, file in pairs(files) do
- local result = command(file,filetype,mustexist)
- if type(result) == 'string' then
- report(result)
- else
- for _,v in pairs(result) do
- report(v)
- end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
end
end
+ return new
end
end
--- strtab
-
-input.var_value = input.variable -- output the value of variable $STRING.
-input.expand_var = input.expansion -- output variable expansion of STRING.
-
-function input.show_path(str) -- output search path for file type NAME
- return file.join_path(input.expanded_path_list(input.format_of_var(str)))
-end
-
--- input.find_file(filename)
--- input.find_file(filename, filetype, mustexist)
--- input.find_file(filename, mustexist)
--- input.find_file(filename, filetype)
-
-function input.aux.register_file(files, name, path)
- if files[name] then
- if type(files[name]) == 'string' then
- files[name] = { files[name], path }
- else
- files[name] = path
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
end
- else
- files[name] = path
- end
-end
-
-if not input.finders then input.finders = { } end
-if not input.openers then input.openers = { } end
-if not input.loaders then input.loaders = { } end
-
-input.finders.notfound = { nil }
-input.openers.notfound = { nil }
-input.loaders.notfound = { false, nil, 0 }
-
-function input.splitmethod(filename)
- if not filename then
- return { } -- safeguard
- elseif type(filename) == "table" then
- return filename -- already split
- elseif not filename:find("://") then
- return { scheme="file", path = filename, original=filename } -- quick hack
- else
- return url.hashed(filename)
end
+ return t
end
-function input.method_is_file(filename)
- return input.splitmethod(filename).scheme == 'file'
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
end
-function table.sequenced(t,sep) -- temp here
- local s = { }
- for k, v in pairs(t) do
- s[#s+1] = k .. "=" .. v
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
end
- return concat(s, sep or " | ")
end
-function input.methodhandler(what, filename, filetype) -- ...
- local specification = (type(filename) == "string" and input.splitmethod(filename)) or filename -- no or { }, let it bomb
- local scheme = specification.scheme
- if input[what][scheme] then
- if input.trace > 0 then
- input.logger('= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
- end
- return input[what][scheme](filename,filetype) -- todo: specification
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
else
- return input[what].tex(filename,filetype) -- todo: specification
+ return resolvers.expanded_path_list(tmp)
end
end
--- also inside next test?
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
-function input.findtexfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
end
-function input.opentexfile(filename)
- return input.methodhandler('openers',input.normalize_name(filename))
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
end
-function input.findbinfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
-end
-function input.openbinfile(filename)
- return input.methodhandler('loaders',input.normalize_name(filename))
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
end
-function input.loadbinfile(filename, filetype)
- local fname = input.findbinfile(input.normalize_name(filename), filetype)
- if fname and fname ~= "" then
- return input.openbinfile(fname)
- else
- return unpack(input.loaders.notfound)
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
end
+ return ''
end
-function input.texdatablob(filename, filetype)
- local ok, data, size = input.loadbinfile(filename, filetype)
- return data or ""
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
end
-input.loadtexfile = input.texdatablob
+resolvers.isreadable = { }
-function input.openfile(filename)
- local fullname = input.findtexfile(filename)
- if fullname and (fullname ~= "") then
- return input.opentexfile(fullname)
- else
- return nil
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
end
+ return readable
end
-function input.logmode()
- return (os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"):lower()
-end
-
--- this is a prelude to engine/progname specific configuration files
--- in which case we can omit files meant for other programs and
--- packages
+resolvers.isreadable.tex = resolvers.isreadable.file
---- ctx
-
--- maybe texinputs + font paths
--- maybe positive selection tex/context fonts/tfm|afm|vf|opentype|type1|map|enc
-
-input.validators = { }
-input.validators.visibility = { }
+-- name
+-- name/name
-function input.validators.visibility.default(path, name)
- return true
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
end
-function input.validators.visibility.context(path, name)
- path = path[1] or path -- some day a loop
- return not (
- path:find("latex") or
--- path:find("doc") or
- path:find("tex4ht") or
- path:find("source") or
--- path:find("config") or
--- path:find("metafont") or
- path:find("lists$") or
- name:find("%.tpm$") or
- name:find("%.bak$")
- )
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
end
--- todo: describe which functions are public (maybe input.private. ... )
-
--- beware: i need to check where we still need a / on windows:
-
-function input.clean_path(str)
- if str then
- str = str:gsub("\\","/")
- str = str:gsub("^!+","")
- str = str:gsub("^~",input.homedir)
- return str
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
else
- return nil
+ return {}
end
end
-function input.do_with_path(name,func)
- for _, v in pairs(input.expanded_path_list(name)) do
- func("^"..input.clean_path(v))
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
end
end
-function input.do_with_var(name,func)
- func(input.aux.expanded_var(name))
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
end
-function input.with_files(pattern,handle)
- local instance = input.instance
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local blobtype = hash.type
- if blobpath then
- local files = instance.files[blobpath]
- if files then
- for k,v in pairs(files) do
- if k:find("^remap:") then
- k = files[k]
- v = files[k] -- chained
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
end
- if k:find(pattern) then
- if type(v) == "string" then
- handle(blobtype,blobpath,v,k)
- else
- for _,vv in pairs(v) do
- handle(blobtype,blobpath,vv,k)
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
end
+ result, ok = { forcedname }, true
+ break
end
end
end
end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
end
- end
-end
-
-function input.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
- local scriptpath = "scripts/context/lua"
- newname = file.addsuffix(newname,"lua")
- local oldscript = input.clean_path(oldname)
- input.report("to be replaced old script %s", oldscript)
- local newscripts = input.find_files(newname) or { }
- if #newscripts == 0 then
- input.report("unable to locate new script")
else
- for _, newscript in ipairs(newscripts) do
- newscript = input.clean_path(newscript)
- input.report("checking new script %s", newscript)
- if oldscript == newscript then
- input.report("old and new script are the same")
- elseif not newscript:find(scriptpath) then
- input.report("new script should come from %s",scriptpath)
- elseif not (oldscript:find(file.removesuffix(newname).."$") or oldscript:find(newname.."$")) then
- input.report("invalid new script name")
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
else
- local newdata = io.loaddata(newscript)
- if newdata then
- input.report("old script content replaced by new content")
- io.savedata(oldscript,newdata)
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
break
- else
- input.report("unable to load new script")
end
end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
end
end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
end
+if not resolvers.concatinators then resolvers.concatinators = { } end
---~ print(table.serialize(input.aux.splitpathexpr("/usr/share/texmf-{texlive,tetex}", {})))
-
--- command line resolver:
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
---~ print(input.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
-
-do
-
- local resolvers = { }
-
- resolvers.environment = function(str)
- return input.clean_path(os.getenv(str) or os.getenv(str:upper()) or os.getenv(str:lower()) or "")
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
end
- resolvers.relative = function(str,n)
- if io.exists(str) then
- -- nothing
- elseif io.exists("./" .. str) then
- str = "./" .. str
- else
- local p = "../"
- for i=1,n or 2 do
- if io.exists(p .. str) then
- str = p .. str
- break
- else
- p = p .. "../"
- end
- end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
end
- return input.clean_path(str)
- end
- resolvers.locate = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path((fullname ~= "" and fullname) or str)
- end
- resolvers.filename = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.basename((fullname ~= "" and fullname) or str))
- end
- resolvers.pathname = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.dirname((fullname ~= "" and fullname) or str))
end
+ instance.format = ''
+ return result
+end
- resolvers.env = resolvers.environment
- resolvers.rel = resolvers.relative
- resolvers.loc = resolvers.locate
- resolvers.kpse = resolvers.locate
- resolvers.full = resolvers.locate
- resolvers.file = resolvers.filename
- resolvers.path = resolvers.pathname
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
- local function resolve(str)
- if type(str) == "table" then
- for k, v in pairs(str) do
- str[k] = resolve(v) or v
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
end
- elseif str and str ~= "" then
- str = str:gsub("([a-z]+):([^ \"\']*)", function(method,target)
- if resolvers[method] then
- return resolvers[method](target)
- else
- return method .. ":" .. target
- end
- end)
end
- return str
- end
-
- if os.uname then
- for k, v in pairs(os.uname()) do
- if not resolvers[k] then
- resolvers[k] = function() return v end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
end
end
end
-
- input.resolve = resolve
-
+ return result
end
-function input.boolean_variable(str,default)
- local b = input.expansion(str)
- if b == "" then
- return default
- else
- b = toboolean(b)
- return (b == nil and default) or b
- end
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
end
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
-if not modules then modules = { } end modules ['luat-log'] = {
- version = 1.001,
- comment = "companion to luat-lib.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This is a prelude to a more extensive logging module. For the sake
-of parsing log files, in addition to the standard logging we will
-provide an structured file. Actually, any logging that
-is hooked into callbacks will be \XML\ by default.
---ldx]]--
-
--- input.logger -> special tracing, driven by log level (only input)
--- input.report -> goes to terminal, depends on verbose, has banner
--- logs.report -> module specific tracing and reporting, no banner but class
-
-
-input = input or { }
-logs = logs or { }
-
---[[ldx--
-
This looks pretty ugly but we need to speed things up a bit.
---ldx]]--
-
-logs.levels = {
- ['error'] = 1,
- ['warning'] = 2,
- ['info'] = 3,
- ['debug'] = 4
-}
-
-logs.functions = {
- 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct'
-}
-
-logs.callbacks = {
- 'start_page_number',
- 'stop_page_number',
- 'report_output_pages',
- 'report_output_log'
-}
-
-logs.tracers = {
-}
-
-logs.xml = logs.xml or { }
-logs.tex = logs.tex or { }
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
-logs.level = 0
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
-local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+-- main user functions
-if texlua then
- write_nl = print
- write = io.write
+function resolvers.automount()
+ -- implemented later
end
-function logs.xml.report(category,fmt,...) -- new
- write_nl(format("%s",category,format(fmt,...)))
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
end
-function logs.xml.line(fmt,...) -- new
- write_nl(format("%s",format(fmt,...)))
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
end
-function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
-function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
-function logs.xml.push () if logs.level > 0 then tw("" ) end end
+-- strtab
-function logs.tex.report(category,fmt,...) -- new
- -- write_nl(format("%s | %s",category,format(fmt,...))) -- arg to format can be tex comment so .. .
- write_nl(category .. " | " .. format(fmt,...))
-end
-function logs.tex.line(fmt,...) -- new
- write_nl(format(fmt,...))
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
end
-function logs.set_level(level)
- logs.level = logs.levels[level] or level
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
end
-function logs.set_method(method)
- for _, v in pairs(logs.functions) do
- logs[v] = logs[method][v] or function() end
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
end
- if callback and input[method] then
- for _, cb in pairs(logs.callbacks) do
- callback.register(cb, input[method][cb])
- end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
end
+ return concat(s, sep or " | ")
end
-function logs.xml.start_page_number()
- write_nl(format("
%s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
end
-function logs.xml.stop_page_number()
- write("/>")
- write_nl("")
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
end
-function logs.xml.report_output_pages(p,b)
- write_nl(format("", p))
- write_nl(format("", b))
- write_nl("")
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
end
-function logs.xml.report_output_log()
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
end
-function input.logger(...) -- assumes test for input.trace > n
- if input.trace > 0 then
- logs.report(...)
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
end
end
-function input.report(fmt,...)
- if input.verbose then
- logs.report(input.banner or "report",format(fmt,...))
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
end
-function input.reportlines(str) -- todo:
- for line in str:gmatch("(.-)[\n\r]") do
- logs.report(input.banner or "report",line)
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
end
end
-input.moreinfo = [[
-more information about ConTeXt and the tools that come with it can be found at:
+texconfig.kpse_init = false
-maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
-webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
-wiki : http://contextgarden.net
-]]
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
-function input.help(banner,message)
- if not input.verbose then
- input.verbose = true
- -- input.report(banner,"\n")
- end
- input.report(banner,"\n")
- input.report("")
- input.reportlines(message)
- if input.moreinfo and input.moreinfo ~= "" then
- input.report("")
- input.reportlines(input.moreinfo)
- end
-end
+-- for a while
-logs.set_level('error')
-logs.set_method('tex')
+input = resolvers
+
+
+end -- of closure
+do -- create closure to overcome 200 locals limit
-if not modules then modules = { } end modules ['luat-tmp'] = {
+if not modules then modules = { } end modules ['data-tmp'] = {
version = 1.001,
comment = "companion to luat-lib.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -7417,17 +8171,16 @@ being written at the same time is small. We also need to extend
luatools with a recache feature.
--ldx]]--
-local format = string.format
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
caches = caches or { }
-dir = dir or { }
-texmf = texmf or { }
caches.path = caches.path or nil
caches.base = caches.base or "luatex-cache"
caches.more = caches.more or "context"
caches.direct = false -- true is faster but may need huge amounts of memory
-caches.trace = false
caches.tree = false
caches.paths = caches.paths or nil
caches.force = false
@@ -7437,13 +8190,14 @@ function caches.temp()
local cachepath = nil
local function check(list,isenv)
if not cachepath then
- for _, v in ipairs(list) do
+ for k=1,#list do
+ local v = list[k]
cachepath = (isenv and (os.env[v] or "")) or v or ""
if cachepath == "" then
-- next
else
- cachepath = input.clean_path(cachepath)
- if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
break
elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
dir.mkdirs(cachepath)
@@ -7456,7 +8210,7 @@ function caches.temp()
end
end
end
- check(input.clean_path_list("TEXMFCACHE") or { })
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
check(caches.defaults,true)
if not cachepath then
print("\nfatal error: there is no valid (writable) cache path defined\n")
@@ -7465,7 +8219,7 @@ function caches.temp()
print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
os.exit()
end
- cachepath = input.normalize_name(cachepath)
+ cachepath = file.collapse_path(cachepath)
function caches.temp()
return cachepath
end
@@ -7473,24 +8227,13 @@ function caches.temp()
end
function caches.configpath()
- return table.concat(input.instance.cnffiles,";")
+ return table.concat(resolvers.instance.cnffiles,";")
end
function caches.hashed(tree)
- return md5.hex((tree:lower()):gsub("[\\\/]+","/"))
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
end
---~ tracing:
-
---~ function caches.hashed(tree)
---~ tree = (tree:lower()):gsub("[\\\/]+","/")
---~ local hash = md5.hex(tree)
---~ if input.verbose then -- temp message
---~ input.report("hashing %s => %s",tree,hash)
---~ end
---~ return hash
---~ end
-
function caches.treehash()
local tree = caches.configpath()
if not tree or tree == "" then
@@ -7505,21 +8248,19 @@ function caches.setpath(...)
if not caches.path then
caches.path = caches.temp()
end
- caches.path = input.clean_path(caches.path) -- to be sure
- if lfs then
- caches.tree = caches.tree or caches.treehash()
- if caches.tree then
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
- else
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
- end
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
end
end
if not caches.path then
caches.path = '.'
end
- caches.path = input.clean_path(caches.path)
- if lfs and not table.is_empty({...}) then
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
local pth = dir.mkdirs(caches.path,...)
return pth
end
@@ -7547,9 +8288,14 @@ function caches.loaddata(path,name)
end
end
-function caches.is_writable(filepath,filename)
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
+
+function caches.iswritable(filepath,filename)
local tmaname, tmcname = caches.setluanames(filepath,filename)
- return file.is_writable(tmaname)
+ return file.iswritable(tmaname)
end
function caches.savedata(filepath,filename,data,raw)
@@ -7559,23 +8305,177 @@ function caches.savedata(filepath,filename,data,raw)
reduce, simplify = false, false
end
if caches.direct then
- file.savedata(tmaname, table.serialize(data,'return',true,true,false)) -- no hex
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
else
- table.tofile(tmaname, data,'return',true,true,false) -- maybe not the last true
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
end
- local cleanup = input.boolean_variable("PURGECACHE", false)
- local strip = input.boolean_variable("LUACSTRIP", true)
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
utils.lua.compile(tmaname, tmcname, cleanup, strip)
end
-- here we use the cache for format loading (texconfig.[formatname|jobname])
--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
-if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and input.instance then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
- texconfig.formatname = caches.setpath("formats") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt")
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-res'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--~ print(resolvers.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
+
+local upper, lower, gsub = string.upper, string.lower, string.gsub
+
+local prefixes = { }
+
+prefixes.environment = function(str)
+ return resolvers.clean_path(os.getenv(str) or os.getenv(upper(str)) or os.getenv(lower(str)) or "")
+end
+
+prefixes.relative = function(str,n)
+ if io.exists(str) then
+ -- nothing
+ elseif io.exists("./" .. str) then
+ str = "./" .. str
+ else
+ local p = "../"
+ for i=1,n or 2 do
+ if io.exists(p .. str) then
+ str = p .. str
+ break
+ else
+ p = p .. "../"
+ end
+ end
+ end
+ return resolvers.clean_path(str)
+end
+
+prefixes.locate = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path((fullname ~= "" and fullname) or str)
+end
+
+prefixes.filename = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.basename((fullname ~= "" and fullname) or str))
+end
+
+prefixes.pathname = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.dirname((fullname ~= "" and fullname) or str))
+end
+
+prefixes.env = prefixes.environment
+prefixes.rel = prefixes.relative
+prefixes.loc = prefixes.locate
+prefixes.kpse = prefixes.locate
+prefixes.full = prefixes.locate
+prefixes.file = prefixes.filename
+prefixes.path = prefixes.pathname
+
+local function _resolve_(method,target)
+ if prefixes[method] then
+ return prefixes[method](target)
+ else
+ return method .. ":" .. target
+ end
+end
+
+local function resolve(str)
+ if type(str) == "table" then
+ for k, v in pairs(str) do -- ipairs
+ str[k] = resolve(v) or v
+ end
+ elseif str and str ~= "" then
+ str = gsub(str,"([a-z]+):([^ \"\']*)",_resolve_)
+ end
+ return str
+end
+
+resolvers.resolve = resolve
+
+if os.uname then
+
+ for k, v in pairs(os.uname()) do
+ if not prefixes[k] then
+ prefixes[k] = function() return v end
+ end
+ end
+
end
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
--[[ldx--
Once we found ourselves defining similar cache constructs
several times, containers were introduced. Containers are used
@@ -7589,126 +8489,145 @@ table structures without bothering about the disk cache.
Examples of usage can be found in the font related code.
--ldx]]--
-containers = { }
-containers.trace = false
+containers = containers or { }
-do -- local report
+containers.usecache = true
- local function report(container,tag,name)
- if caches.trace or containers.trace or container.trace then
- logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
- end
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
end
+end
- local allocated = { }
+local allocated = { }
- -- tracing
+-- tracing
- function containers.define(category, subcategory, version, enabled)
- return function()
- if category and subcategory then
- local c = allocated[category]
- if not c then
- c = { }
- allocated[category] = c
- end
- local s = c[subcategory]
- if not s then
- s = {
- category = category,
- subcategory = subcategory,
- storage = { },
- enabled = enabled,
- version = version or 1.000,
- trace = false,
- path = caches.setpath(category,subcategory),
- }
- c[subcategory] = s
- end
- return s
- else
- return nil
- end
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
end
end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
- function containers.is_usable(container, name)
- return container.enabled and caches.is_writable(container.path, name)
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
end
+end
- function containers.is_valid(container, name)
- if name and name ~= "" then
- local storage = container.storage[name]
- return storage and not table.is_empty(storage) and storage.cache_version == container.version
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
else
- return false
+ container.storage[name] = nil
end
end
-
- function containers.read(container,name)
- if container.enabled and not container.storage[name] then
- container.storage[name] = caches.loaddata(container.path,name)
- if containers.is_valid(container,name) then
- report(container,"loaded",name)
- else
- container.storage[name] = nil
- end
- end
- if container.storage[name] then
- report(container,"reusing",name)
- end
- return container.storage[name]
+ if container.storage[name] then
+ report(container,"reusing",name)
end
+ return container.storage[name]
+end
- function containers.write(container, name, data)
- if data then
- data.cache_version = container.version
- if container.enabled then
- local unique, shared = data.unique, data.shared
- data.unique, data.shared = nil, nil
- caches.savedata(container.path, name, data)
- report(container,"saved",name)
- data.unique, data.shared = unique, shared
- end
- report(container,"stored",name)
- container.storage[name] = data
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
end
- return data
+ report(container,"stored",name)
+ container.storage[name] = data
end
+ return data
+end
- function containers.content(container,name)
- return container.storage[name]
- end
+function containers.content(container,name)
+ return container.storage[name]
+end
+function containers.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
end
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
-- since we want to use the cache instead of the tree, we will now
-- reimplement the saver.
-local save_data = input.aux.save_data
-local load_data = input.aux.load_data
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
-input.cachepath = nil -- public, for tracing
-input.usecache = true -- public, for tracing
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
-function input.aux.save_data(dataname, check)
- save_data(dataname, check, function(cachename,dataname)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(cachename))
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
else
return file.join(cachename,dataname)
end
end)
end
-function input.aux.load_data(pathname,dataname,filename)
+function resolvers.load_data(pathname,dataname,filename)
load_data(pathname,dataname,filename,function(dataname,filename)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(pathname))
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
else
if not filename or (filename == "") then
filename = dataname
@@ -7720,15 +8639,15 @@ end
-- we will make a better format, maybe something xml or just text or lua
-input.automounted = input.automounted or { }
+resolvers.automounted = resolvers.automounted or { }
-function input.automount(usecache)
- local mountpaths = input.clean_path_list(input.expansion('TEXMFMOUNT'))
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
if table.is_empty(mountpaths) and usecache then
mountpaths = { caches.setpath("mount") }
end
if not table.is_empty(mountpaths) then
- input.starttiming(input.instance)
+ statistics.starttiming(resolvers.instance)
for k, root in pairs(mountpaths) do
local f = io.open(root.."/url.tmi")
if f then
@@ -7737,98 +8656,72 @@ function input.automount(usecache)
if line:find("^[%%#%-]") then -- or %W
-- skip
elseif line:find("^zip://") then
- input.report("mounting %s",line)
- table.insert(input.automounted,line)
- input.usezipfile(line)
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
end
end
end
f:close()
end
end
- input.stoptiming(input.instance)
+ statistics.stoptiming(resolvers.instance)
end
end
--- store info in format
-
-input.storage = { }
-input.storage.data = { }
-input.storage.min = 0 -- 500
-input.storage.max = input.storage.min - 1
-input.storage.trace = false -- true
-input.storage.done = input.storage.done or 0
-input.storage.evaluators = { }
--- (evaluate,message,names)
+-- status info
-function input.storage.register(...)
- input.storage.data[#input.storage.data+1] = { ... }
-end
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
-function input.storage.evaluate(name)
- input.storage.evaluators[#input.storage.evaluators+1] = name
-end
+-- experiment (code will move)
-function input.storage.finalize() -- we can prepend the string with "evaluate:"
- for _, t in ipairs(input.storage.evaluators) do
- for i, v in pairs(t) do
- if type(v) == "string" then
- t[i] = loadstring(v)()
- elseif type(v) == "table" then
- for _, vv in pairs(v) do
- if type(vv) == "string" then
- t[i] = loadstring(vv)()
- end
- end
- end
- end
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
end
end
-function input.storage.dump()
- for name, data in ipairs(input.storage.data) do
- local evaluate, message, original, target = data[1], data[2], data[3] ,data[4]
- local name, initialize, finalize, code = nil, "", "", ""
- for str in target:gmatch("([^%.]+)") do
- if name then
- name = name .. "." .. str
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
else
- name = str
+ return "invalid status file"
end
- initialize = format("%s %s = %s or {} ", initialize, name, name)
- end
- if evaluate then
- finalize = "input.storage.evaluate(" .. name .. ")"
- end
- input.storage.max = input.storage.max + 1
- if input.storage.trace then
- logs.report('storage','saving %s in slot %s',message,input.storage.max)
- code =
- initialize ..
- format("logs.report('storage','restoring %s from slot %s') ",message,input.storage.max) ..
- table.serialize(original,name) ..
- finalize
else
- code = initialize .. table.serialize(original,name) .. finalize
+ return "missing status file"
end
- lua.bytecode[input.storage.max] = loadstring(code)
end
+ return true
end
--- we also need to count at generation time (nicer for message)
-if lua.bytecode then -- from 0 upwards
- local i = input.storage.min
- while lua.bytecode[i] do
- lua.bytecode[i]()
- lua.bytecode[i] = nil
- i = i + 1
- end
- input.storage.done = i
-end
+end -- of closure
+do -- create closure to overcome 200 locals limit
-if not modules then modules = { } end modules ['luat-log'] = {
+if not modules then modules = { } end modules ['data-zip'] = {
version = 1.001,
comment = "companion to luat-lib.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -7836,154 +8729,556 @@ if not modules then modules = { } end modules ['luat-log'] = {
license = "see context related readme files"
}
---[[ldx--
-
This is a prelude to a more extensive logging module. For the sake
-of parsing log files, in addition to the standard logging we will
-provide an structured file. Actually, any logging that
-is hooked into callbacks will be \XML\ by default.
---ldx]]--
+local format, find = string.format, string.find
--- input.logger -> special tracing, driven by log level (only input)
--- input.report -> goes to terminal, depends on verbose, has banner
--- logs.report -> module specific tracing and reporting, no banner but class
+local trace_locating, trace_verbose = false, false
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trace_verbose = v end)
-input = input or { }
-logs = logs or { }
+zip = zip or { }
+zip.archives = zip.archives or { }
+zip.registeredfiles = zip.registeredfiles or { }
---[[ldx--
-
This looks pretty ugly but we need to speed things up a bit.
---ldx]]--
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+local locators, hashers, concatinators = resolvers.locators, resolvers.hashers, resolvers.concatinators
-logs.levels = {
- ['error'] = 1,
- ['warning'] = 2,
- ['info'] = 3,
- ['debug'] = 4
-}
+local archives = zip.archives
-logs.functions = {
- 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct'
-}
+-- zip:///oeps.zip?name=bla/bla.tex
+-- zip:///oeps.zip?tree=tex/texmf-local
-logs.callbacks = {
- 'start_page_number',
- 'stop_page_number',
- 'report_output_pages',
- 'report_output_log'
-}
+local function validzip(str) -- todo: use url splitter
+ if not find(str,"^zip://") then
+ return "zip:///" .. str
+ else
+ return str
+ end
+end
-logs.tracers = {
-}
+function zip.openarchive(name)
+ if not name or name == "" then
+ return nil
+ else
+ local arch = archives[name]
+ if not arch then
+ local full = resolvers.find_file(name) or ""
+ arch = (full ~= "" and zip.open(full)) or false
+ archives[name] = arch
+ end
+ return arch
+ end
+end
-logs.xml = logs.xml or { }
-logs.tex = logs.tex or { }
+function zip.closearchive(name)
+ if not name or (name == "" and archives[name]) then
+ zip.close(archives[name])
+ archives[name] = nil
+ end
+end
-logs.level = 0
+-- zip:///texmf.zip?tree=/tex/texmf
+-- zip:///texmf.zip?tree=/tex/texmf-local
+-- zip:///texmf-mine.zip?tree=/tex/texmf-projects
-local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+function locators.zip(specification) -- where is this used? startup zips (untested)
+ specification = resolvers.splitmethod(specification)
+ local zipfile = specification.path
+ local zfile = zip.openarchive(name) -- tricky, could be in to be initialized tree
+ if trace_locating then
+ if zfile then
+ logs.report("fileio",'! zip locator, found: %s',specification.original)
+ else
+ logs.report("fileio",'? zip locator, not found: %s',specification.original)
+ end
+ end
+end
-if texlua then
- write_nl = print
- write = io.write
+function hashers.zip(tag,name)
+ if trace_verbose then
+ logs.report("fileio","loading zip file %s as %s",name,tag)
+ end
+ resolvers.usezipfile(format("%s?tree=%s",tag,name))
end
-function logs.xml.report(category,fmt,...) -- new
- write_nl(format("%s",category,format(fmt,...)))
+function concatinators.zip(tag,path,name)
+ if not path or path == "" then
+ return format('%s?name=%s',tag,name)
+ else
+ return format('%s?name=%s/%s',tag,path,name)
+ end
end
-function logs.xml.line(fmt,...) -- new
- write_nl(format("%s",format(fmt,...)))
+
+function resolvers.isreadable.zip(name)
+ return true
end
-function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
-function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
-function logs.xml.push () if logs.level > 0 then tw("" ) end end
+function finders.zip(specification,filetype)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'! zip finder, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ dfile = zfile:close()
+ if trace_locating then
+ logs.report("fileio",'+ zip finder, name: %s',q.name)
+ end
+ return specification.original
+ end
+ elseif trace_locating then
+ logs.report("fileio",'? zip finder, path %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip finder, name: %s',filename)
+ end
+ return unpack(finders.notfound)
+end
-function logs.tex.report(category,fmt,...) -- new
- -- write_nl(format("%s | %s",category,format(fmt,...))) -- arg to format can be tex comment so .. .
- write_nl(category .. " | " .. format(fmt,...))
+function openers.zip(specification)
+ local zipspecification = resolvers.splitmethod(specification)
+ if zipspecification.path then
+ local q = url.query(zipspecification.query)
+ if q.name then
+ local zfile = zip.openarchive(zipspecification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',zipspecification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_open(specification)
+ return openers.text_opener(specification,dfile,'zip')
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path %s',zipspecification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip opener, name: %s',filename)
+ end
+ return unpack(openers.notfound)
end
-function logs.tex.line(fmt,...) -- new
- write_nl(format(fmt,...))
+
+function loaders.zip(specification)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_load(filename)
+ if trace_locating then
+ logs.report("fileio",'+ zip loader, name: %s',filename)
+ end
+ local s = dfile:read("*all")
+ dfile:close()
+ return true, s, #s
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path: %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip loader, name: %s',filename)
+ end
+ return unpack(openers.notfound)
end
-function logs.set_level(level)
- logs.level = logs.levels[level] or level
+-- zip:///somefile.zip
+-- zip:///somefile.zip?tree=texmf-local -> mount
+
+function resolvers.usezipfile(zipname)
+ zipname = validzip(zipname)
+ if trace_locating then
+ logs.report("fileio",'! zip use, file: %s',zipname)
+ end
+ local specification = resolvers.splitmethod(zipname)
+ local zipfile = specification.path
+ if zipfile and not zip.registeredfiles[zipname] then
+ local tree = url.query(specification.query).tree or ""
+ if trace_locating then
+ logs.report("fileio",'! zip register, file: %s',zipname)
+ end
+ local z = zip.openarchive(zipfile)
+ if z then
+ local instance = resolvers.instance
+ if trace_locating then
+ logs.report("fileio","= zipfile, registering: %s",zipname)
+ end
+ statistics.starttiming(instance)
+ resolvers.prepend_hash('zip',zipname,zipfile)
+ resolvers.extend_texmf_var(zipname) -- resets hashes too
+ zip.registeredfiles[zipname] = z
+ instance.files[zipname] = resolvers.register_zip_file(z,tree or "")
+ statistics.stoptiming(instance)
+ elseif trace_locating then
+ logs.report("fileio","? zipfile, unknown: %s",zipname)
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! zip register, no file: %s',zipname)
+ end
end
-function logs.set_method(method)
- for _, v in pairs(logs.functions) do
- logs[v] = logs[method][v] or function() end
+function resolvers.register_zip_file(z,tree)
+ local files, filter = { }, ""
+ if tree == "" then
+ filter = "^(.+)/(.-)$"
+ else
+ filter = format("^%s/(.+)/(.-)$",tree)
end
- if callback and input[method] then
- for _, cb in pairs(logs.callbacks) do
- callback.register(cb, input[method][cb])
+ if trace_locating then
+ logs.report("fileio",'= zip filter: %s',filter)
+ end
+ local register, n = resolvers.register_file, 0
+ for i in z:files() do
+ local path, name = i.filename:match(filter)
+ if path then
+ if name and name ~= '' then
+ register(files, name, path)
+ n = n + 1
+ else
+ -- directory
+ end
+ else
+ register(files, i.filename, '')
+ n = n + 1
end
end
+ logs.report("fileio",'= zip entries: %s',n)
+ return files
end
-function logs.xml.start_page_number()
- write_nl(format("")
- write_nl("")
+function finders.curl(protocol,filename)
+ local foundname = curl.fetch(protocol, filename)
+ return finders.generic(protocol,foundname,filetype)
end
-function logs.xml.report_output_pages(p,b)
- write_nl(format("", p))
- write_nl(format("", b))
- write_nl("")
+function openers.curl(protocol,filename)
+ return openers.generic(protocol,filename)
end
-function logs.xml.report_output_log()
+function loaders.curl(protocol,filename)
+ return loaders.generic(protocol,filename)
end
-function input.logger(...) -- assumes test for input.trace > n
- if input.trace > 0 then
- logs.report(...)
+-- todo: metamethod
+
+function curl.install(protocol)
+ finders[protocol] = function (filename,filetype) return finders.curl(protocol,filename) end
+ openers[protocol] = function (filename) return openers.curl(protocol,filename) end
+ loaders[protocol] = function (filename) return loaders.curl(protocol,filename) end
+end
+
+curl.install('http')
+curl.install('https')
+curl.install('ftp')
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
end
end
-function input.report(fmt,...)
- if input.verbose then
- logs.report(input.banner or "report",format(fmt,...))
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- loads *.tmf files in minimal tree roots (to be optimized and documented)
+
+function resolvers.check_environment(tree)
+ logs.simpleline()
+ os.setenv('TMP', os.getenv('TMP') or os.getenv('TEMP') or os.getenv('TMPDIR') or os.getenv('HOME'))
+ os.setenv('TEXOS', os.getenv('TEXOS') or ("texmf-" .. os.currentplatform()))
+ os.setenv('TEXPATH', (tree or "tex"):gsub("\/+$",''))
+ os.setenv('TEXMFOS', os.getenv('TEXPATH') .. "/" .. os.getenv('TEXOS'))
+ logs.simpleline()
+ logs.simple("preset : TEXPATH => %s", os.getenv('TEXPATH'))
+ logs.simple("preset : TEXOS => %s", os.getenv('TEXOS'))
+ logs.simple("preset : TEXMFOS => %s", os.getenv('TEXMFOS'))
+ logs.simple("preset : TMP => %s", os.getenv('TMP'))
+ logs.simple('')
+end
+
+function resolvers.load_environment(name) -- todo: key=value as well as lua
+ local f = io.open(name)
+ if f then
+ for line in f:lines() do
+ if line:find("^[%%%#]") then
+ -- skip comment
+ else
+ local key, how, value = line:match("^(.-)%s*([<=>%?]+)%s*(.*)%s*$")
+ if how then
+ value = value:gsub("%%(.-)%%", function(v) return os.getenv(v) or "" end)
+ if how == "=" or how == "<<" then
+ os.setenv(key,value)
+ elseif how == "?" or how == "??" then
+ os.setenv(key,os.getenv(key) or value)
+ elseif how == "<" or how == "+=" then
+ if os.getenv(key) then
+ os.setenv(key,os.getenv(key) .. io.fileseparator .. value)
+ else
+ os.setenv(key,value)
+ end
+ elseif how == ">" or how == "=+" then
+ if os.getenv(key) then
+ os.setenv(key,value .. io.pathseparator .. os.getenv(key))
+ else
+ os.setenv(key,value)
+ end
+ end
+ end
+ end
+ end
+ f:close()
end
end
-function input.reportlines(str) -- todo:
- for line in str:gmatch("(.-)[\n\r]") do
- logs.report(input.banner or "report",line)
+function resolvers.load_tree(tree)
+ if tree and tree ~= "" then
+ local setuptex = 'setuptex.tmf'
+ if lfs.attributes(tree, "mode") == "directory" then -- check if not nil
+ setuptex = tree .. "/" .. setuptex
+ else
+ setuptex = tree
+ end
+ if io.exists(setuptex) then
+ resolvers.check_environment(tree)
+ resolvers.load_environment(setuptex)
+ end
end
end
-input.moreinfo = [[
-more information about ConTeXt and the tools that come with it can be found at:
-
-maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
-webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
-wiki : http://contextgarden.net
-]]
-
-function input.help(banner,message)
- if not input.verbose then
- input.verbose = true
- -- input.report(banner,"\n")
- end
- input.report(banner,"\n")
- input.report("")
- input.reportlines(message)
- if input.moreinfo and input.moreinfo ~= "" then
- input.report("")
- input.reportlines(input.moreinfo)
- end
-end
-logs.set_level('error')
-logs.set_method('tex')
+end -- of closure
+do -- create closure to overcome 200 locals limit
if not modules then modules = { } end modules ['luat-sta'] = {
version = 1.001,
@@ -7992,6 +9287,8 @@ if not modules then modules = { } end modules ['luat-sta'] = {
license = "see context related readme files"
}
+-- this code is used in the updater
+
states = states or { }
states.data = states.data or { }
states.hash = states.hash or { }
@@ -8018,27 +9315,32 @@ end
function states.set_by_tag(tag,key,value,default,persistent)
local d, h = states.data[tag], states.hash[tag]
if d then
- local dkey, hkey = key, key
- local pre, post = key:match("(.+)%.([^%.]+)$")
- if pre and post then
- for k in pre:gmatch("[^%.]+") do
- local dk = d[k]
- if not dk then
- dk = { }
- d[k] = dk
+ if type(d) == "table" then
+ local dkey, hkey = key, key
+ local pre, post = key:match("(.+)%.([^%.]+)$")
+ if pre and post then
+ for k in pre:gmatch("[^%.]+") do
+ local dk = d[k]
+ if not dk then
+ dk = { }
+ d[k] = dk
+ end
+ d = dk
end
- d = dk
+ dkey, hkey = post, key
end
- dkey, hkey = post, key
- end
- if type(value) == nil then
- value = value or default
- elseif persistent then
- value = value or d[dkey] or default
- else
- value = value or default
+ if type(value) == nil then
+ value = value or default
+ elseif persistent then
+ value = value or d[dkey] or default
+ else
+ value = value or default
+ end
+ d[dkey], h[hkey] = value, value
+ elseif type(d) == "string" then
+ -- weird
+ states.data[tag], states.hash[tag] = value, value
end
- d[dkey], h[hkey] = value, value
end
end
@@ -8158,7 +9460,6 @@ end
--~ },
--~ }
-
--~ states.save("teststate", "update")
--~ states.load("teststate", "update")
@@ -8169,6 +9470,8 @@ end
--~ states.load("teststate", "update")
--~ print(states.get_by_tag("update","rsync.server","unknown"))
+
+end -- of closure
-- end library merge
own = { } -- not local
@@ -8178,27 +9481,43 @@ own.libs = { -- todo: check which ones are really needed
'l-lpeg.lua',
'l-table.lua',
'l-io.lua',
- 'l-md5.lua',
'l-number.lua',
'l-set.lua',
'l-os.lua',
'l-file.lua',
+ 'l-md5.lua',
'l-dir.lua',
'l-boolean.lua',
'l-math.lua',
- 'l-xml.lua',
-- 'l-unicode.lua',
- 'l-utils.lua',
-- 'l-tex.lua',
- 'luat-lib.lua',
- 'luat-inp.lua',
- 'luat-log.lua',
--- 'luat-zip.lua',
--- 'luat-tex.lua',
--- 'luat-kps.lua',
- 'luat-tmp.lua',
- 'luat-log.lua',
- 'luat-sta.lua',
+ 'l-utils.lua',
+-- 'l-xml.lua',
+ 'lxml-tab.lua',
+ 'lxml-pth.lua',
+ 'lxml-ent.lua',
+ 'lxml-mis.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+ 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+ 'data-zip.lua',
+ 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-tmf.lua', -- tree files
+ -- needed ?
+ 'luat-sta.lua', -- states
}
-- We need this hack till luatex is fixed.
@@ -8236,11 +9555,11 @@ local function locate_libs()
end
end
-if not input then
+if not resolvers then
locate_libs()
end
-if not input then
+if not resolvers then
print("")
print("Mtxrun is unable to start up due to lack of libraries. You may")
print("try to run 'lua mtxrun.lua --selfmerge' in the path where this")
@@ -8249,216 +9568,12 @@ if not input then
os.exit()
end
-input.instance = input.reset()
-input.banner = 'MtxRun'
-utils.report = input.report
-
-local instance = input.instance
-
-
--- use os.env or environment when available
-
-function input.check_environment(tree)
- input.report('')
- os.setenv('TMP', os.getenv('TMP') or os.getenv('TEMP') or os.getenv('TMPDIR') or os.getenv('HOME'))
- os.setenv('TEXOS', os.getenv('TEXOS') or ("texmf-" .. os.currentplatform()))
- os.setenv('TEXPATH', (tree or "tex"):gsub("\/+$",''))
- os.setenv('TEXMFOS', os.getenv('TEXPATH') .. "/" .. os.getenv('TEXOS'))
- input.report('')
- input.report("preset : TEXPATH => %s", os.getenv('TEXPATH'))
- input.report("preset : TEXOS => %s", os.getenv('TEXOS'))
- input.report("preset : TEXMFOS => %s", os.getenv('TEXMFOS'))
- input.report("preset : TMP => %s", os.getenv('TMP'))
- input.report('')
-end
-
-function input.load_environment(name) -- todo: key=value as well as lua
- local f = io.open(name)
- if f then
- for line in f:lines() do
- if line:find("^[%%%#]") then
- -- skip comment
- else
- local key, how, value = line:match("^(.-)%s*([<=>%?]+)%s*(.*)%s*$")
- if how then
- value = value:gsub("%%(.-)%%", function(v) return os.getenv(v) or "" end)
- if how == "=" or how == "<<" then
- os.setenv(key,value)
- elseif how == "?" or how == "??" then
- os.setenv(key,os.getenv(key) or value)
- elseif how == "<" or how == "+=" then
- if os.getenv(key) then
- os.setenv(key,os.getenv(key) .. io.fileseparator .. value)
- else
- os.setenv(key,value)
- end
- elseif how == ">" or how == "=+" then
- if os.getenv(key) then
- os.setenv(key,value .. io.pathseparator .. os.getenv(key))
- else
- os.setenv(key,value)
- end
- end
- end
- end
- end
- f:close()
- end
-end
-
-function input.load_tree(tree)
- if tree and tree ~= "" then
- local setuptex = 'setuptex.tmf'
- if lfs.attributes(tree, "mode") == "directory" then -- check if not nil
- setuptex = tree .. "/" .. setuptex
- else
- setuptex = tree
- end
- if io.exists(setuptex) then
- input.check_environment(tree)
- input.load_environment(setuptex)
- end
- end
-end
-
--- md5 extensions
-
--- maybe md.md5 md.md5hex md.md5HEX
-
-if not md5 then md5 = { } end
-
-if not md5.sum then
- function md5.sum(k)
- return string.rep("x",16)
- end
-end
-
-function md5.hexsum(k)
- return (string.gsub(md5.sum(k), ".", function(c) return string.format("%02x", string.byte(c)) end))
-end
-
-function md5.HEXsum(k)
- return (string.gsub(md5.sum(k), ".", function(c) return string.format("%02X", string.byte(c)) end))
-end
-
--- file extensions
-
-file.needs_updating_threshold = 1
-
-function file.needs_updating(oldname,newname) -- size modification access change
- local oldtime = lfs.attributes(oldname, modification)
- local newtime = lfs.attributes(newname, modification)
- if newtime >= oldtime then
- return false
- elseif oldtime - newtime < file.needs_updating_threshold then
- return false
- else
- return true
- end
-end
-
-function file.checksum(name)
- if md5 then
- local data = io.loaddata(name)
- if data then
- return md5.HEXsum(data)
- end
- end
- return nil
-end
-
-function file.loadchecksum(name)
- if md5 then
- local data = io.loaddata(name .. ".md5")
- return data and data:gsub("%s","")
- end
- return nil
-end
-
-function file.savechecksum(name, checksum)
- if not checksum then checksum = file.checksum(name) end
- if checksum then
- io.savedata(name .. ".md5",checksum)
- return checksum
- end
- return nil
-end
-
-os.arch = os.arch or function()
- return os.resultof("uname -m") or "linux"
-end
-
-function os.currentplatform(name, default)
- local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
- if name then
- if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
- return "mswin"
- elseif name == "linux" then
- local architecture = os.arch()
- if architecture:find("x86_64") then
- return "linux-64"
- elseif architecture:find("ppc") then
- return "linux-ppc"
- else
- return "linux"
- end
- elseif name == "macosx" then
- local architecture = os.arch()
- if architecture:find("i386") then
- return "osx-intel"
- else
- return "osx-ppc"
- end
- elseif name == "freebsd" then
- return "freebsd"
- end
- end
- return default or name
-end
-
--- it starts here
-
-input.runners = { }
-input.runners.applications = { }
-
-input.runners.applications.lua = "luatex --luaonly"
-input.runners.applications.pl = "perl"
-input.runners.applications.py = "python"
-input.runners.applications.rb = "ruby"
-
-input.runners.suffixes = {
- 'rb', 'lua', 'py', 'pl'
-}
-
-input.runners.registered = {
- texexec = { 'texexec.rb', true },
- texutil = { 'texutil.rb', true },
- texfont = { 'texfont.pl', true },
- texshow = { 'texshow.pl', false },
-
- makempy = { 'makempy.pl', true },
- mptopdf = { 'mptopdf.pl', true },
- pstopdf = { 'pstopdf.rb', true },
-
--- examplex = { 'examplex.rb', false },
- concheck = { 'concheck.rb', false },
-
- runtools = { 'runtools.rb', true },
- textools = { 'textools.rb', true },
- tmftools = { 'tmftools.rb', true },
- ctxtools = { 'ctxtools.rb', true },
- rlxtools = { 'rlxtools.rb', true },
- pdftools = { 'pdftools.rb', true },
- mpstools = { 'mpstools.rb', true },
- exatools = { 'exatools.rb', true },
- xmltools = { 'xmltools.rb', true },
- luatools = { 'luatools.lua', true },
- mtxtools = { 'mtxtools.rb', true },
+logs.setprogram('MTXrun',"TDS Runner Tool 1.22",environment.arguments["verbose"] or false)
- pdftrimwhite = { 'pdftrimwhite.pl', false }
-}
+local instance = resolvers.reset()
-if not messages then messages = { } end
+runners = runners or { } -- global
+messages = messages or { }
messages.help = [[
--script run an mtx script (--noquotes)
@@ -8488,43 +9603,78 @@ messages.help = [[
--launch (--all) launch files like manuals, assumes os support
--intern run script using built in libraries
+
+--usekpse use kpse as fallback (when no mkiv and cache installed, often slower)
+--forcekpse force using kpse (handy when no mkiv and cache installed but less functionality)
]]
-function input.runners.my_prepare_a()
- input.resetconfig()
- input.identify_cnf()
- input.load_lua()
- input.expand_variables()
- input.load_cnf()
- input.expand_variables()
-end
+runners.applications = {
+ ["lua"] = "luatex --luaonly",
+ ["luc"] = "luatex --luaonly",
+ ["pl"] = "perl",
+ ["py"] = "python",
+ ["rb"] = "ruby",
+}
-function input.runners.my_prepare_b()
- input.runners.my_prepare_a()
- input.load_hash()
- input.automount()
-end
+runners.suffixes = {
+ 'rb', 'lua', 'py', 'pl'
+}
+
+runners.registered = {
+ texexec = { 'texexec.rb', true }, -- context mkii runner (only tool not to be luafied)
+ texutil = { 'texutil.rb', true }, -- old perl based index sorter for mkii (old versions need it)
+ texfont = { 'texfont.pl', true }, -- perl script that makes mkii font metric files
+ texfind = { 'texfind.pl', false }, -- perltk based tex searching tool, mostly used at pragma
+ texshow = { 'texshow.pl', false }, -- perltk based context help system, will be luafied
+ -- texwork = { \texwork.pl', false }, -- perltk based editing environment, only used at pragma
+
+ makempy = { 'makempy.pl', true },
+ mptopdf = { 'mptopdf.pl', true },
+ pstopdf = { 'pstopdf.rb', true }, -- converts ps (and some more) images, does some cleaning (replaced)
+
+-- examplex = { 'examplex.rb', false },
+ concheck = { 'concheck.rb', false },
+
+ runtools = { 'runtools.rb', true },
+ textools = { 'textools.rb', true },
+ tmftools = { 'tmftools.rb', true },
+ ctxtools = { 'ctxtools.rb', true },
+ rlxtools = { 'rlxtools.rb', true },
+ pdftools = { 'pdftools.rb', true },
+ mpstools = { 'mpstools.rb', true },
+-- exatools = { 'exatools.rb', true },
+ xmltools = { 'xmltools.rb', true },
+-- luatools = { 'luatools.lua', true },
+ mtxtools = { 'mtxtools.rb', true },
+
+ pdftrimwhite = { 'pdftrimwhite.pl', false }
+}
+
+runners.launchers = {
+ windows = { },
+ unix = { }
+}
-function input.runners.prepare()
+function runners.prepare()
local checkname = environment.argument("ifchanged")
if checkname and checkname ~= "" then
local oldchecksum = file.loadchecksum(checkname)
local newchecksum = file.checksum(checkname)
if oldchecksum == newchecksum then
- input.report("file '%s' is unchanged",checkname)
+ logs.simple("file '%s' is unchanged",checkname)
return "skip"
else
- input.report("file '%s' is changed, processing started",checkname)
+ logs.simple("file '%s' is changed, processing started",checkname)
end
file.savechecksum(checkname)
end
local oldname, newname = string.split(environment.argument("iftouched") or "", ",")
if oldname and newname and oldname ~= "" and newname ~= "" then
if not file.needs_updating(oldname,newname) then
- input.report("file '%s' and '%s' have same age",oldname,newname)
+ logs.simple("file '%s' and '%s' have same age",oldname,newname)
return "skip"
else
- input.report("file '%s' is older than '%s'",oldname,newname)
+ logs.simple("file '%s' is older than '%s'",oldname,newname)
end
end
local tree = environment.argument('tree') or ""
@@ -8532,28 +9682,27 @@ function input.runners.prepare()
tree = os.getenv('TEXMFSTART_TREE') or os.getenv('TEXMFSTARTTREE') or tree
end
if tree and tree ~= "" then
- input.load_tree(tree)
+ resolvers.load_tree(tree)
end
local env = environment.argument('environment') or ""
if env and env ~= "" then
for _,e in pairs(string.split(env)) do
-- maybe force suffix when not given
- input.load_tree(e)
+ resolvers.load_tree(e)
end
end
local runpath = environment.argument("path")
- if runpath and not dir.chdir(runpath) then
- input.report("unable to change to path '%s'",runpath)
+ if runpath and not lfs.chdir(runpath) then
+ logs.simple("unable to change to path '%s'",runpath)
return "error"
end
return "run"
end
-function input.runners.execute_script(fullname,internal)
- local instance = input.instance
+function runners.execute_script(fullname,internal)
local noquote = environment.argument("noquotes")
if fullname and fullname ~= "" then
- local state = input.runners.prepare()
+ local state = runners.prepare()
if state == 'error' then
return false
elseif state == 'skip' then
@@ -8570,41 +9719,44 @@ function input.runners.execute_script(fullname,internal)
return ""
end )
name = name:gsub("^script:","")
- if suffix == "" and input.runners.registered[name] and input.runners.registered[name][1] then
- name = input.runners.registered[name][1]
+ if suffix == "" and runners.registered[name] and runners.registered[name][1] then
+ name = runners.registered[name][1]
suffix = file.extname(name)
end
if suffix == "" then
-- loop over known suffixes
- for _,s in pairs(input.runners.suffixes) do
- result = input.find_file(name .. "." .. s, 'texmfscripts')
+ for _,s in pairs(runners.suffixes) do
+ result = resolvers.find_file(name .. "." .. s, 'texmfscripts')
if result ~= "" then
break
end
end
- elseif input.runners.applications[suffix] then
- result = input.find_file(name, 'texmfscripts')
+ elseif runners.applications[suffix] then
+ result = resolvers.find_file(name, 'texmfscripts')
else
-- maybe look on path
- result = input.find_file(name, 'other text files')
+ result = resolvers.find_file(name, 'other text files')
end
end
if result and result ~= "" then
+ local before, after = environment.split_arguments(fullname) -- already done
+ environment.arguments_before, environment.arguments_after = before, after
if internal then
- local before, after = environment.split_arguments(fullname)
arg = { } for _,v in pairs(after) do arg[#arg+1] = v end
dofile(result)
else
- local binary = input.runners.applications[file.extname(result)]
+ local binary = runners.applications[file.extname(result)]
if binary and binary ~= "" then
result = binary .. " " .. result
end
- local before, after = environment.split_arguments(fullname)
local command = result .. " " .. environment.reconstruct_commandline(after,noquote)
- input.report("")
- input.report("executing: %s",command)
- input.report("\n \n")
- io.flush()
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
+ io.flush()
+ end
local code = os.exec(command) -- maybe spawn
return code == 0
end
@@ -8614,10 +9766,10 @@ function input.runners.execute_script(fullname,internal)
return false
end
-function input.runners.execute_program(fullname)
+function runners.execute_program(fullname)
local noquote = environment.argument("noquotes")
if fullname and fullname ~= "" then
- local state = input.runners.prepare()
+ local state = runners.prepare()
if state == 'error' then
return false
elseif state == 'skip' then
@@ -8627,9 +9779,10 @@ function input.runners.execute_program(fullname)
environment.initialize_arguments(after)
fullname = fullname:gsub("^bin:","")
local command = fullname .. " " .. (environment.reconstruct_commandline(after or "",noquote) or "")
- input.report("")
- input.report("executing: %s",command)
- input.report("\n \n")
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
io.flush()
local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn
return code == 0
@@ -8638,8 +9791,13 @@ function input.runners.execute_program(fullname)
return false
end
-function input.runners.handle_stubs(create)
- local stubpath = environment.argument('stubpath') or '.' -- 'auto' no longer supported
+-- the --usekpse flag will fallback on kpse
+
+local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
+local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
+
+function runners.handle_stubs(create)
+ local stubpath = environment.argument('stubpath') or '.' -- 'auto' no longer subpathssupported
local windows = environment.argument('windows') or environment.argument('mswin') or false
local unix = environment.argument('unix') or environment.argument('linux') or false
if not windows and not unix then
@@ -8649,77 +9807,77 @@ function input.runners.handle_stubs(create)
windows = true
end
end
- for _,v in pairs(input.runners.registered) do
+ for _,v in pairs(runners.registered) do
local name, doit = v[1], v[2]
if doit then
local base = string.gsub(file.basename(name), "%.(.-)$", "")
if create then
- -- direct local command = input.runners.applications[file.extname(name)] .. " " .. name
- local command = "luatex --luaonly mtxrun.lua " .. name
if windows then
- io.savedata(base..".bat", {"@echo off", command.." %*"}, "\013\010")
- input.report("windows stub for '%s' created",base)
+ io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name))
+ logs.simple("windows stub for '%s' created",base)
end
if unix then
- io.savedata(base, {"#!/bin/sh", command..' "$@"'}, "\010")
- input.report("unix stub for '%s' created",base)
+ io.savedata(file.join(stubpath,base),string.format(unix_stub,name))
+ logs.simple("unix stub for '%s' created",base)
end
else
- if windows and (os.remove(base..'.bat') or os.remove(base..'.cmd')) then
- input.report("windows stub for '%s' removed", base)
+ if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then
+ logs.simple("windows stub for '%s' removed", base)
end
- if unix and (os.remove(base) or os.remove(base..'.sh')) then
- input.report("unix stub for '%s' removed",base)
+ if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then
+ logs.simple("unix stub for '%s' removed",base)
end
end
end
end
end
-function input.runners.resolve_string(filename)
+function runners.resolve_string(filename)
if filename and filename ~= "" then
- input.runners.report_location(input.resolve(filename))
+ runners.report_location(resolvers.resolve(filename))
end
end
-function input.runners.locate_file(filename)
+function runners.locate_file(filename)
+ -- differs from texmfstart where locate appends .com .exe .bat ... todo
if filename and filename ~= "" then
- input.runners.report_location(input.find_given_file(filename))
+ runners.report_location(resolvers.find_given_file(filename))
end
end
-function input.runners.locate_platform()
- input.runners.report_location(os.currentplatform())
+function runners.locate_platform()
+ runners.report_location(os.currentplatform())
end
-function input.runners.report_location(result)
- if input.verbose then
- input.report("")
+function runners.report_location(result)
+ if logs.verbose then
+ logs.simpleline()
if result and result ~= "" then
- input.report(result)
+ logs.simple(result)
else
- input.report("not found")
+ logs.simple("not found")
end
else
io.write(result)
end
end
-function input.runners.edit_script(filename) -- we assume that vim is present on most systems
+function runners.edit_script(filename) -- we assume that vim is present on most systems
local editor = os.getenv("MTXRUN_EDITOR") or os.getenv("TEXMFSTART_EDITOR") or os.getenv("EDITOR") or 'vim'
- local rest = input.resolve(filename)
+ local rest = resolvers.resolve(filename)
if rest ~= "" then
local command = editor .. " " .. rest
- if input.verbose then
- input.report("")
- input.report("starting editor: %s",command)
- input.report("\n \n")
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("starting editor: %s",command)
+ logs.simple_line()
+ logs.simple_line()
end
os.launch(command)
end
end
-function input.runners.save_script_session(filename, list)
+function runners.save_script_session(filename, list)
local t = { }
for _, key in ipairs(list) do
t[key] = environment.arguments[key]
@@ -8727,7 +9885,7 @@ function input.runners.save_script_session(filename, list)
io.savedata(filename,table.serialize(t,true))
end
-function input.runners.load_script_session(filename)
+function runners.load_script_session(filename)
if lfs.isfile(filename) then
local t = io.loaddata(filename)
if t then
@@ -8740,15 +9898,10 @@ function input.runners.load_script_session(filename)
end
end
-input.runners.launchers = {
- windows = { },
- unix = { }
-}
-
-function input.launch(str)
+function resolvers.launch(str)
-- maybe we also need to test on mtxrun.launcher.suffix environment
-- variable or on windows consult the assoc and ftype vars and such
- local launchers = input.runners.launchers[os.platform] if launchers then
+ local launchers = runners.launchers[os.platform] if launchers then
local suffix = file.extname(str) if suffix then
local runner = launchers[suffix] if runner then
str = runner .. " " .. str
@@ -8758,41 +9911,40 @@ function input.launch(str)
os.launch(str)
end
-function input.runners.launch_file(filename)
- local instance = input.instance
+function runners.launch_file(filename)
instance.allresults = true
- input.verbose = true
+ logs.setverbose(true)
local pattern = environment.arguments["pattern"]
if not pattern or pattern == "" then
pattern = filename
end
if not pattern or pattern == "" then
- input.report("provide name or --pattern=")
+ logs.simple("provide name or --pattern=")
else
- local t = input.find_files(pattern)
+ local t = resolvers.find_files(pattern)
if not t or #t == 0 then
- t = input.aux.find_file("*/" .. pattern,true)
+ t = resolvers.find_files("*/" .. pattern)
end
if not t or #t == 0 then
- t = input.aux.find_file("*/" .. pattern .. "*",true)
+ t = resolvers.find_files("*/" .. pattern .. "*")
end
if t and #t > 0 then
if environment.arguments["all"] then
for _, v in pairs(t) do
- input.report("launching %s", v)
- input.launch(v)
+ logs.simple("launching %s", v)
+ resolvers.launch(v)
end
else
- input.report("launching %s", t[1])
- input.launch(t[1])
+ logs.simple("launching %s", t[1])
+ resolvers.launch(t[1])
end
else
- input.report("no match for %s", pattern)
+ logs.simple("no match for %s", pattern)
end
end
end
-function input.runners.find_mtx_script(filename)
+function runners.find_mtx_script(filename)
local function found(name)
local path = file.dirname(name)
if path and path ~= "" then
@@ -8803,10 +9955,10 @@ function input.runners.find_mtx_script(filename)
end
end
filename = file.addsuffix(filename,"lua")
- local basename = file.stripsuffix(file.basename(filename))
+ local basename = file.removesuffix(file.basename(filename))
local suffix = file.extname(filename)
-- qualified path, raw name
- local fullname = input.aux.qualified_path(filename) and io.exists(filename) and filename
+ local fullname = file.is_qualified_path(filename) and io.exists(filename) and filename
if fullname and fullname ~= "" then
return fullname
end
@@ -8818,74 +9970,84 @@ function input.runners.find_mtx_script(filename)
end
-- context namespace, mtx-
fullname = "mtx-" .. filename
- fullname = found(fullname) or input.find_file(fullname)
+ fullname = found(fullname) or resolvers.find_file(fullname)
if fullname and fullname ~= "" then
return fullname
end
-- context namespace, mtx-s
fullname = "mtx-" .. basename .. "s" .. "." .. suffix
- fullname = found(fullname) or input.find_file(fullname)
+ fullname = found(fullname) or resolvers.find_file(fullname)
if fullname and fullname ~= "" then
return fullname
end
-- context namespace, mtx-
fullname = "mtx-" .. basename:gsub("s$","") .. "." .. suffix
- fullname = found(fullname) or input.find_file(fullname)
+ fullname = found(fullname) or resolvers.find_file(fullname)
if fullname and fullname ~= "" then
return fullname
end
-- context namespace, just
- fullname = input.find_file(fullname)
+ fullname = resolvers.find_file(filename)
return fullname
end
-function input.runners.execute_ctx_script(filename,arguments)
- local fullname = input.runners.find_mtx_script(filename)
+function runners.execute_ctx_script(filename,arguments)
+ local fullname = runners.find_mtx_script(filename) or ""
+ -- retyr after generate but only if --autogenerate
+ if fullname == "" and environment.argument("autogenerate") then -- might become the default
+ instance.renewcache = true
+ logs.setverbose(true)
+ resolvers.load()
+ --
+ fullname = runners.find_mtx_script(filename) or ""
+ end
-- that should do it
- if fullname and fullname ~= "" then
- local state = input.runners.prepare()
+ if fullname ~= "" then
+ local state = runners.prepare()
if state == 'error' then
return false
elseif state == 'skip' then
return true
elseif state == "run" then
-- load and save ... kind of undocumented
- arg = { } for _,v in pairs(arguments) do arg[#arg+1] = v end
+ arg = { } for _,v in pairs(arguments) do arg[#arg+1] = resolvers.resolve(v) end
environment.initialize_arguments(arg)
local loadname = environment.arguments['load']
if loadname then
if type(loadname) ~= "string" then loadname = file.basename(fullname) end
loadname = file.replacesuffix(loadname,"cfg")
- input.runners.load_script_session(loadname)
+ runners.load_script_session(loadname)
end
filename = environment.files[1]
- if input.verbose then
- input.report("using script: %s\n",fullname)
+ if logs.verbose then
+ logs.simple("using script: %s\n",fullname)
end
dofile(fullname)
local savename = environment.arguments['save']
- if savename and input.runners.save_list and not table.is_empty(input.runners.save_list or { }) then
+ if savename and runners.save_list and not table.is_empty(runners.save_list or { }) then
if type(savename) ~= "string" then savename = file.basename(fullname) end
savename = file.replacesuffix(savename,"cfg")
- input.runners.save_script_session(savename, input.runners.save_list)
+ runners.save_script_session(savename, runners.save_list)
end
return true
end
else
- input.verbose = true
+ logs.setverbose(true)
filename = file.addsuffix(filename,"lua")
if filename == "" then
- input.report("unknown script, no name given")
- elseif input.aux.qualified_path(filename) then
- input.report("unknown script '%s'",filename)
+ logs.simple("unknown script, no name given")
+ elseif file.is_qualified_path(filename) then
+ logs.simple("unknown script '%s'",filename)
else
- input.report("unknown script '%s' or 'mtx-%s'",filename,filename)
+ logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename)
end
return false
end
end
-input.report("%s\n",banner)
+function runners.timed(action)
+ statistics.timed(action)
+end
-- this is a bit dirty ... first we store the first filename and next we
-- split the arguments so that we only see the ones meant for this script
@@ -8895,14 +10057,79 @@ local filename = environment.files[1] or ""
local ok = true
local before, after = environment.split_arguments(filename)
+environment.arguments_before, environment.arguments_after = before, after
environment.initialize_arguments(before)
instance.engine = environment.argument("engine") or 'luatex'
instance.progname = environment.argument("progname") or 'context'
instance.lsrmode = environment.argument("lsr") or false
-input.verbose = environment.argument("verbose") or false
-input.runners.my_prepare_b()
+-- maybe the unset has to go to this level
+
+if environment.argument("usekpse") or environment.argument("forcekpse") then
+
+ os.setenv("engine","")
+ os.setenv("progname","")
+
+ local remapper = {
+ otf = "opentype fonts",
+ ttf = "truetype fonts",
+ ttc = "truetype fonts",
+ pfb = "type1 fonts",
+ other = "other text files",
+ }
+
+ local function kpse_initialized()
+ texconfig.kpse_init = true
+ local t = os.clock()
+ local k = kpse.original.new("luatex",instance.progname)
+ local dummy = k:find_file("mtxrun.lua") -- so that we're initialized
+ logs.simple("kpse fallback with progname '%s' initialized in %s seconds",instance.progname,os.clock()-t)
+ kpse_initialized = function() return k end
+ return k
+ end
+
+ local find_file = resolvers.find_file
+ local show_path = resolvers.show_path
+
+ if environment.argument("forcekpse") then
+
+ function resolvers.find_file(name,kind)
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ function resolvers.show_path(name)
+ return (kpse_initialized():show_path(name)) or ""
+ end
+
+ elseif environment.argument("usekpse") then
+
+ resolvers.load()
+
+ function resolvers.find_file(name,kind)
+ local found = find_file(name,kind) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ end
+ function resolvers.show_path(name)
+ local found = show_path(name) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():show_path(name)) or ""
+ end
+ end
+
+ end
+
+else
+
+ resolvers.load()
+
+end
+
if environment.argument("selfmerge") then
-- embed used libraries
@@ -8911,47 +10138,47 @@ elseif environment.argument("selfclean") then
-- remove embedded libraries
utils.merger.selfclean(own.name)
elseif environment.argument("selfupdate") then
- input.verbose = true
- input.update_script(own.name,"mtxrun")
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"mtxrun")
elseif environment.argument("ctxlua") or environment.argument("internal") then
-- run a script by loading it (using libs)
- ok = input.runners.execute_script(filename,true)
-elseif environment.argument("script") then
+ ok = runners.execute_script(filename,true)
+elseif environment.argument("script") or environment.argument("s") then
-- run a script by loading it (using libs), pass args
- ok = input.runners.execute_ctx_script(filename,after)
+ ok = runners.execute_ctx_script(filename,after)
elseif environment.argument("execute") then
-- execute script
- ok = input.runners.execute_script(filename)
+ ok = runners.execute_script(filename)
elseif environment.argument("direct") then
-- equals bin:
- ok = input.runners.execute_program(filename)
+ ok = runners.execute_program(filename)
elseif environment.argument("edit") then
-- edit file
- input.runners.edit_script(filename)
+ runners.edit_script(filename)
elseif environment.argument("launch") then
- input.runners.launch_file(filename)
+ runners.launch_file(filename)
elseif environment.argument("make") then
-- make stubs
- input.runners.handle_stubs(true)
+ runners.handle_stubs(true)
elseif environment.argument("remove") then
-- remove stub
- input.runners.handle_stubs(false)
+ runners.handle_stubs(false)
elseif environment.argument("resolve") then
-- resolve string
- input.runners.resolve_string(filename)
+ runners.resolve_string(filename)
elseif environment.argument("locate") then
-- locate file
- input.runners.locate_file(filename)
+ runners.locate_file(filename)
elseif environment.argument("platform")then
-- locate platform
- input.runners.locate_platform()
+ runners.locate_platform()
elseif environment.argument("help") or filename=='help' or filename == "" then
- input.help(banner,messages.help)
+ logs.help(messages.help)
-- execute script
elseif filename:find("^bin:") then
- ok = input.runners.execute_program(filename)
+ ok = runners.execute_program(filename)
else
- ok = input.runners.execute_script(filename)
+ ok = runners.execute_script(filename)
end
if os.platform == "unix" then
diff --git a/scripts/context/lua/x-ldx.lua b/scripts/context/lua/x-ldx.lua
index 67d5f925c..af5c9c0c8 100644
--- a/scripts/context/lua/x-ldx.lua
+++ b/scripts/context/lua/x-ldx.lua
@@ -335,10 +335,10 @@ The next function wraps it all in one call:
--ldx]]--
function ldx.convert(luaname,ldxname)
- if not file.is_readable(luaname) then
+ if not file.isreadable(luaname) then
luaname = luaname .. ".lua"
end
- if file.is_readable(luaname) then
+ if file.isreadable(luaname) then
if not ldxname then
ldxname = file.replacesuffix(luaname,"ldx")
end
diff --git a/scripts/context/ruby/base/exa.rb b/scripts/context/ruby/base/exa.rb
index 5a094351e..7ba990cf9 100644
--- a/scripts/context/ruby/base/exa.rb
+++ b/scripts/context/ruby/base/exa.rb
@@ -3,8 +3,9 @@
# tex.setup.setuplayout.width.[integer|real|dimension|string|key]
# tex.[mp]var.whatever.width.[integer|real|dimension|string|key]
-require 'ftools'
-require 'md5'
+require 'fileutils'
+# require 'ftools'
+require 'digest/md5'
# this can become a lua thing
@@ -40,7 +41,7 @@ module ExaEncrypt
pre, password, post = $1, $2, $3
unless password =~ /MD5:/i then
done = true
- password = "MD5:" + MD5.new(password).hexdigest.upcase
+ password = "MD5:" + Digest::MD5.hexdigest(password).upcase
end
"#{pre}#{password}#{post}"
end
@@ -49,7 +50,7 @@ module ExaEncrypt
attributes, password = $1, $2
unless password =~ /^([0-9A-F][0-9A-F])+$/ then
done = true
- password = MD5.new(password).hexdigest.upcase
+ password = Digest::MD5.hexdigest(password).upcase
attributes = " encryption='md5'#{attributes}"
end
"#{password}"
diff --git a/scripts/context/ruby/base/file.rb b/scripts/context/ruby/base/file.rb
index 39bb7d467..1aeac5fd6 100644
--- a/scripts/context/ruby/base/file.rb
+++ b/scripts/context/ruby/base/file.rb
@@ -8,7 +8,8 @@
# info : j.hagen@xs4all.nl
# www : www.pragma-ade.com
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
class File
@@ -110,7 +111,7 @@ class File
def File.silentcopy(oldname,newname)
return if File.expand_path(oldname) == File.expand_path(newname)
- File.makedirs(File.dirname(newname)) rescue false
+ FileUtils.makedirs(File.dirname(newname)) rescue false
File.copy(oldname,newname) rescue false
end
@@ -123,7 +124,7 @@ class File
begin
File.rename(oldname,newname)
rescue
- File.makedirs(File.dirname(newname)) rescue false
+ FileUtils.makedirs(File.dirname(newname)) rescue false
File.copy(oldname,newname) rescue false
end
end
diff --git a/scripts/context/ruby/base/kpse.rb b/scripts/context/ruby/base/kpse.rb
index 0e185b5b8..0f9868784 100644
--- a/scripts/context/ruby/base/kpse.rb
+++ b/scripts/context/ruby/base/kpse.rb
@@ -13,6 +13,7 @@
# todo: web2c vs miktex module and include in kpse
require 'rbconfig'
+require 'fileutils'
# beware $engine is lowercase in kpse
#
@@ -185,6 +186,7 @@ module Kpse
return results
end
+
def Kpse.formatpaths
# maybe we should check for writeability
unless @@paths.key?('formatpaths') then
@@ -272,7 +274,7 @@ module Kpse
unless done then
formatpaths.each do |fp|
fpp = fp.sub(/#{engine}\/*$/o,'')
- File.makedirs(fpp) rescue false # maybe we don't have an path yet
+ FileUtils.makedirs(fpp) rescue false # maybe we don't have an path yet
if FileTest.directory?(fpp) && FileTest.writable?(fpp) then
# use this path
formatpath, done = fp.dup, true
@@ -285,12 +287,12 @@ module Kpse
end
end
# needed !
- File.makedirs(formatpath) rescue false
+ FileUtils.makedirs(formatpath) rescue false
# fall back to current path
formatpath = '.' if formatpath.empty? || ! FileTest.writable?(formatpath)
# append engine but prevent duplicates
formatpath = File.join(formatpath.sub(/\/*#{engine}\/*$/,''), engine) if enginepath
- File.makedirs(formatpath) rescue false
+ FileUtils.makedirs(formatpath) rescue false
setpath(engine,formatpath)
# ENV['engine'] = savedengine
end
diff --git a/scripts/context/ruby/base/state.rb b/scripts/context/ruby/base/state.rb
index 4b2088128..76ef50b25 100644
--- a/scripts/context/ruby/base/state.rb
+++ b/scripts/context/ruby/base/state.rb
@@ -1,4 +1,4 @@
-require "md5"
+require 'digest/md5'
# todo: register omissions per file
@@ -57,7 +57,7 @@ class FileState
begin
if FileTest.file?(filename) && (data = IO.read(filename)) then
data.gsub!(/\n.*?(#{[omit].flatten.join('|')}).*?\n/) do "\n" end if omit
- sum = MD5.new(data).hexdigest.upcase
+ sum = Digest::MD5.hexdigest(data).upcase
end
rescue
sum = ''
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index 4f3e51299..c14cb840f 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -16,6 +16,8 @@
# report ?
+require 'fileutils'
+
require 'base/variables'
require 'base/kpse'
require 'base/system'
@@ -128,11 +130,12 @@ class TEX
['cont-ro','ro','romanian'] .each do |f| @@texformats[f] = 'cont-ro' end
['cont-gb','gb','cont-uk','uk','british'] .each do |f| @@texformats[f] = 'cont-gb' end
['cont-pe','pe','persian'] .each do |f| @@texformats[f] = 'cont-pe' end
+ ['cont-xp','xp','experimental'] .each do |f| @@texformats[f] = 'cont-xp' end
['mptopdf'] .each do |f| @@texformats[f] = 'mptopdf' end
['latex'] .each do |f| @@texformats[f] = 'latex.ltx' end
- ['plain','mpost'] .each do |f| @@mpsformats[f] = 'plain' end
+ ['plain','mpost'] .each do |f| @@mpsformats[f] = 'mpost' end
['metafun','context','standard'] .each do |f| @@mpsformats[f] = 'metafun' end
['pdftex','pdfetex','aleph','omega','petex',
@@ -143,7 +146,7 @@ class TEX
['plain','default','standard','mptopdf'] .each do |f| @@texmethods[f] = 'plain' end
['cont-en','cont-nl','cont-de','cont-it',
'cont-fr','cont-cs','cont-ro','cont-gb',
- 'cont-pe'] .each do |f| @@texmethods[f] = 'context' end
+ 'cont-pe','cont-xp'] .each do |f| @@texmethods[f] = 'context' end
['latex','pdflatex'] .each do |f| @@texmethods[f] = 'latex' end
['plain','default','standard'] .each do |f| @@mpsmethods[f] = 'plain' end
@@ -154,7 +157,7 @@ class TEX
['cont-en','cont-nl','cont-de','cont-it',
'cont-fr','cont-cs','cont-ro','cont-gb',
- 'cont-pe'] .each do |f| @@texprocstr[f] = @@platformslash + "emergencyend" end
+ 'cont-pe','cont-xp'] .each do |f| @@texprocstr[f] = @@platformslash + "emergencyend" end
@@runoptions['aleph'] = ['--8bit']
@@runoptions['luatex'] = ['--file-line-error']
@@ -166,7 +169,7 @@ class TEX
@@tcxflag['aleph'] = true
@@tcxflag['luatex'] = false
- @@tcxflag['mpost'] = true
+ @@tcxflag['mpost'] = false
@@tcxflag['pdfetex'] = true
@@tcxflag['pdftex'] = true
@@tcxflag['petex'] = false
@@ -174,8 +177,8 @@ class TEX
@@draftoptions['pdftex'] = ['--draftmode']
- @@booleanvars = [
- 'batchmode', 'nonstopmode', 'fast', 'fastdisabled', 'silentmode', 'final',
+ @@mainbooleanvars = [
+ 'batchmode', 'nonstopmode', 'fast', 'final',
'paranoid', 'notparanoid', 'nobanner', 'once', 'allpatterns', 'draft',
'nompmode', 'nomprun', 'automprun', 'combine',
'nomapfiles', 'local',
@@ -187,19 +190,19 @@ class TEX
'globalfile', 'autopath',
'purge', 'purgeall', 'keep', 'autopdf', 'xpdf', 'simplerun', 'verbose',
'nooptionfile', 'nobackend', 'noctx', 'utfbom',
- 'mkii',
+ 'mkii','mkiv',
]
- @@stringvars = [
+ @@mainstringvars = [
'modefile', 'result', 'suffix', 'response', 'path',
'filters', 'usemodules', 'environments', 'separation', 'setuppath',
'arguments', 'input', 'output', 'randomseed', 'modes', 'mode', 'filename',
'ctxfile', 'printformat', 'paperformat', 'paperoffset',
'timeout', 'passon'
]
- @@standardvars = [
+ @@mainstandardvars = [
'mainlanguage', 'bodyfont', 'language'
]
- @@knownvars = [
+ @@mainknownvars = [
'engine', 'distribution', 'texformats', 'mpsformats', 'progname', 'interface',
'runs', 'backend'
]
@@ -208,29 +211,31 @@ class TEX
@@extrastringvars = []
def booleanvars
- [@@booleanvars,@@extrabooleanvars].flatten.uniq
+ [@@mainbooleanvars,@@extrabooleanvars].flatten.uniq
end
def stringvars
- [@@stringvars,@@extrastringvars].flatten.uniq
+ [@@mainstringvars,@@extrastringvars].flatten.uniq
end
def standardvars
- [@@standardvars].flatten.uniq
+ [@@mainstandardvars].flatten.uniq
end
def knownvars
- [@@knownvars].flatten.uniq
+ [@@mainknownvars].flatten.uniq
end
def allbooleanvars
- [@@booleanvars,@@extrabooleanvars].flatten.uniq
+ [@@mainbooleanvars,@@extrabooleanvars].flatten.uniq
end
def allstringvars
- [@@stringvars,@@extrastringvars,@@standardvars,@@knownvars].flatten.uniq
+ [@@mainstringvars,@@extrastringvars,@@mainstandardvars,@@mainknownvars].flatten.uniq
end
def setextrastringvars(vars)
- @@extrastringvars << vars
+ # @@extrastringvars << vars -- problems in 1.9
+ @@extrastringvars = [@@extrastringvars,vars].flatten
end
def setextrabooleanvars(vars)
- @@extrabooleanvars << vars
+ # @@extrabooleanvars << vars -- problems in 1.9
+ @@extrabooleanvars = [@@extrabooleanvars,vars].flatten
end
# def jobvariables(names=nil)
@@ -580,7 +585,7 @@ class TEX
if data = (IO.readlines(@@luafiles) rescue nil) then
report("compiling lua files (using #{File.expand_path(@@luafiles)})")
begin
- File.makedirs(@@luatarget) rescue false
+ FileUtils.makedirs(@@luatarget) rescue false
data.each do |line|
luafile = line.chomp
lucfile = File.basename(luafile).gsub(/\..*?$/,'') + ".luc"
@@ -686,7 +691,8 @@ class TEX
mpsformats.each do |mpsformat|
report("generating mps format #{mpsformat}")
progname = validprogname([getvariable('progname'),mpsformat,mpsengine])
- if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
+ # if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
+ if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then
setvariable('error','no format made')
end
end
@@ -1009,7 +1015,11 @@ end
tmp << "\\starttext\n"
if forcexml then
# tmp << checkxmlfile(rawname)
- tmp << "\\processXMLfilegrouped{#{rawname}}\n"
+ if getvariable('mkiv') then
+ tmp << "\\xmlprocess{\\xmldocument}{#{rawname}}{}\n"
+ else
+ tmp << "\\processXMLfilegrouped{#{rawname}}\n"
+ end
else
tmp << "\\processfile{#{rawname}}\n"
end
@@ -1329,12 +1339,9 @@ class TEX
# local handies
opt << "\% #{topname}\n"
opt << "\\unprotect\n"
- if getvariable('utfbom') then
- opt << "\\enableregime[utf]"
- end
- opt << "\\setupsystem[\\c!n=#{kindofrun},\\c!m=#{currentrun}]\n"
- progname = validprogname(['metafun']) # [getvariable('progname'),mpsformat,mpsengine]
- opt << "\\def\\MPOSTformatswitch\{#{prognameflag(progname)} #{formatflag('mpost')}=\}\n"
+ #
+ # feedback and basic control
+ #
if getvariable('batchmode') then
opt << "\\batchmode\n"
end
@@ -1344,6 +1351,21 @@ class TEX
if getvariable('paranoid') then
opt << "\\def\\maxreadlevel{1}\n"
end
+ if getvariable('nomapfiles') then
+ opt << "\\disablemapfiles\n"
+ end
+ if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then
+ opt << "\\runMPgraphicsfalse\n"
+ end
+ if getvariable('utfbom') then
+ opt << "\\enableregime[utf]"
+ end
+ progname = validprogname(['metafun']) # [getvariable('progname'),mpsformat,mpsengine]
+ opt << "\\def\\MPOSTformatswitch\{#{prognameflag(progname)} #{formatflag('mpost')}=\}\n"
+ #
+ # process info
+ #
+ opt << "\\setupsystem[\\c!n=#{kindofrun},\\c!m=#{currentrun}]\n"
if (str = File.unixfied(getvariable('modefile'))) && ! str.empty? then
opt << "\\readlocfile{#{str}}{}{}\n"
end
@@ -1360,6 +1382,35 @@ class TEX
if (str = getvariable('mainlanguage').downcase) && ! str.empty? && ! str.standard? then
opt << "\\setuplanguage[#{str}]\n"
end
+ if (str = getvariable('arguments')) && ! str.empty? then
+ opt << "\\setupenv[#{str}]\n"
+ end
+ if (str = getvariable('setuppath')) && ! str.empty? then
+ opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n"
+ end
+ if (str = getvariable('randomseed')) && ! str.empty? then
+ report("using randomseed #{str}")
+ opt << "\\setupsystem[\\c!random=#{str}]\n"
+ end
+ if (str = getvariable('input')) && ! str.empty? then
+ opt << "\\setupsystem[inputfile=#{str}]\n"
+ else
+ opt << "\\setupsystem[inputfile=#{rawname}]\n"
+ end
+ #
+ # modes
+ #
+ # we handle both "--mode" and "--modes", else "--mode" is mapped onto "--modefile"
+ if (str = getvariable('modes')) && ! str.empty? then
+ opt << "\\enablemode[#{str}]\n"
+ end
+ if (str = getvariable('mode')) && ! str.empty? then
+ opt << "\\enablemode[#{str}]\n"
+ end
+ #
+ # options
+ #
+ opt << "\\startsetups *runtime:options\n"
if str = validbackend(getvariable('backend')) then
opt << "\\setupoutput[#{str}]\n"
elsif str = validbackend(getvariable('output')) then
@@ -1368,21 +1419,9 @@ class TEX
if getvariable('color') then
opt << "\\setupcolors[\\c!state=\\v!start]\n"
end
- if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then
- opt << "\\runMPgraphicsfalse\n"
- end
- if getvariable('fast') && ! getvariable('fastdisabled') then
- opt << "\\fastmode\n"
- end
- if getvariable('silentmode') then
- opt << "\\silentmode\n"
- end
if (str = getvariable('separation')) && ! str.empty? then
opt << "\\setupcolors[\\c!split=#{str}]\n"
end
- if (str = getvariable('setuppath')) && ! str.empty? then
- opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n"
- end
if (str = getvariable('paperformat')) && ! str.empty? && ! str.standard? then
if str =~ /^([a-z]+\d+)([a-z]+\d+)$/io then # A5A4 A4A3 A2A1 ...
opt << "\\setuppapersize[#{$1.upcase}][#{$2.upcase}]\n"
@@ -1399,9 +1438,6 @@ class TEX
if getvariable('centerpage') then
opt << "\\setuplayout[\\c!location=\\v!middle,\\c!marking=\\v!on]\n"
end
- if getvariable('nomapfiles') then
- opt << "\\disablemapfiles\n"
- end
if getvariable('noarrange') then
opt << "\\setuparranging[\\v!disable]\n"
elsif getvariable('arrange') then
@@ -1419,26 +1455,6 @@ class TEX
end
opt << "\\setuparranging[#{arrangement.flatten.join(',')}]\n" if arrangement.size > 0
end
- # we handle both "--mode" and "--modes", else "--mode" is
- # mapped onto "--modefile"
- if (str = getvariable('modes')) && ! str.empty? then
- opt << "\\enablemode[#{str}]\n"
- end
- if (str = getvariable('mode')) && ! str.empty? then
- opt << "\\enablemode[#{str}]\n"
- end
- if (str = getvariable('arguments')) && ! str.empty? then
- opt << "\\setupenv[#{str}]\n"
- end
- if (str = getvariable('randomseed')) && ! str.empty? then
- report("using randomseed #{str}")
- opt << "\\setupsystem[\\c!random=#{str}]\n"
- end
- if (str = getvariable('input')) && ! str.empty? then
- opt << "\\setupsystem[inputfile=#{str}]\n"
- else
- opt << "\\setupsystem[inputfile=#{rawname}]\n"
- end
if (str = getvariable('pages')) && ! str.empty? then
if str.downcase == 'odd' then
opt << "\\chardef\\whichpagetoshipout=1\n"
@@ -1459,14 +1475,18 @@ class TEX
opt << "\\def\\pagestoshipout\{#{pagelist.join(',')}\}\n";
end
end
- opt << "\\protect\n";
- # begin getvariable('modes' ).split(',').uniq.each do |e| opt << "\\enablemode [#{e}]\n" end ; rescue ; end
+ opt << "\\stopsetups\n"
+ #
+ # styles and modules
+ #
+ opt << "\\startsetups *runtime:modules\n"
begin getvariable('filters' ).split(',').uniq.each do |f| opt << "\\useXMLfilter[#{f}]\n" end ; rescue ; end
begin getvariable('usemodules' ).split(',').uniq.each do |m| opt << "\\usemodule [#{m}]\n" end ; rescue ; end
begin getvariable('environments').split(',').uniq.each do |e| opt << "\\environment #{e} \n" end ; rescue ; end
- # this will become:
- # begin getvariable('environments').split(',').uniq.each do |e| opt << "\\useenvironment[#{e}]\n" end ; rescue ; end
- opt << "\\endinput\n"
+ opt << "\\stopsetups\n"
+ #
+ opt << "\\protect \\endinput\n"
+ #
opt.close
else
report("unable to write option file #{topname}")
@@ -1579,7 +1599,9 @@ end
if mpsengine && mpsformat then
ENV["MPXCOMMAND"] = "0" unless mpx
progname = validprogname([getvariable('progname'),mpsformat,mpsengine])
- runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
+ mpname.gsub!(/\.mp$/,"") # temp bug in mp
+ # runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
+ runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)])
true
else
false
@@ -1589,7 +1611,7 @@ end
def runtexmp(filename,filetype='',purge=true)
checktestversion
mpname = File.suffixed(filename,filetype,'mp')
- if File.atleast?(mpname,25) then
+ if File.atleast?(mpname,10) then
# first run needed
File.silentdelete(File.suffixed(mpname,'mpt'))
doruntexmp(mpname,nil,true,purge)
@@ -1627,7 +1649,7 @@ end
end
def runtexutil(filename=[], options=['--ref','--ij','--high'], old=false)
- filename.each do |fname|
+ [filename].flatten.each do |fname|
if old then
Kpse.runscript('texutil',fname,options)
else
@@ -2065,7 +2087,7 @@ end
setvariable('mp.line','')
setvariable('mp.error','')
if mpdata = File.silentread(mpname) then
- mpdata.gsub!(/^\%.*\n/o,'')
+ # mpdata.gsub!(/^\%.*\n/o,'')
File.silentrename(mpname,mpcopy)
texfound = mergebe || (mpdata =~ /btex .*? etex/mo)
if mp = openedfile(mpname) then
@@ -2082,10 +2104,11 @@ end
mp << mergebe['0'] if mergebe.key?('0')
end
end
- mp << MPTools::splitmplines(mpdata)
- mp << "\n"
- mp << "end"
+ # mp << MPTools::splitmplines(mpdata)
+ mp << mpdata
mp << "\n"
+ # mp << "end"
+ # mp << "\n"
mp.close
end
processmpx(mpname,true,true,purge) if texfound
@@ -2097,7 +2120,10 @@ end
options = ''
end
# todo plain|mpost|metafun
- ok = runmp(mpname)
+ begin
+ ok = runmp(mpname)
+ rescue
+ end
if f = File.silentopen(File.suffixed(mpname,'log')) then
while str = f.gets do
if str =~ /^l\.(\d+)\s(.*?)\n/o then
diff --git a/scripts/context/ruby/base/texutil.rb b/scripts/context/ruby/base/texutil.rb
index 9e66aecff..3775469ed 100644
--- a/scripts/context/ruby/base/texutil.rb
+++ b/scripts/context/ruby/base/texutil.rb
@@ -475,24 +475,37 @@ class TeXUtil
@@debug = false
def initialize(t, c, k, d)
- @type, @command, @key, @sortkey, @data = t, c, k, k, d
+ @type, @command, @key, @sortkey, @data = t, c, k, c, d
end
attr_reader :type, :command, :key, :data
attr_reader :sortkey
attr_writer :sortkey
+ # def build(sorter)
+ # if @key then
+ # @sortkey = sorter.normalize(sorter.tokenize(@sortkey))
+ # @sortkey = sorter.remap(sorter.simplify(@key.downcase)) # ??
+ # if @sortkey.empty? then
+ # @sortkey = sorter.remap(@command.downcase)
+ # end
+ # else
+ # @key = ""
+ # @sortkey = ""
+ # end
+ # end
+
def build(sorter)
- if @key then
+ if @sortkey and not @sortkey.empty? then
@sortkey = sorter.normalize(sorter.tokenize(@sortkey))
- @sortkey = sorter.remap(sorter.simplify(@key.downcase)) # ??
- if @sortkey.empty? then
- @sortkey = sorter.remap(@command.downcase)
- end
- else
- @key = ""
- @sortkey = ""
- # weird
+ @sortkey = sorter.remap(sorter.simplify(@sortkey.downcase)) # ??
+ end
+ if not @sortkey or @sortkey.empty? then
+ @sortkey = sorter.normalize(sorter.tokenize(@key))
+ @sortkey = sorter.remap(sorter.simplify(@sortkey.downcase)) # ??
+ end
+ if not @sortkey or @sortkey.empty? then
+ @sortkey = @key.dup
end
end
diff --git a/scripts/context/ruby/base/tool.rb b/scripts/context/ruby/base/tool.rb
index 5ccedfec1..abf0d5ed0 100644
--- a/scripts/context/ruby/base/tool.rb
+++ b/scripts/context/ruby/base/tool.rb
@@ -24,10 +24,15 @@ module Tool
t = Time.now
u = t.usec.to_s % [1..2] [0..3]
pth = t.strftime("#{mainpath}%Y%m%d-%H%M%S-#{u}-#{Process.pid}")
- if pth == $constructedtempdir
- # sleep(0.01)
- retry
- end
+ #
+ # problems with 1.9
+ #
+ # if pth == $constructedtempdir
+ # # sleep(0.01)
+ # retry
+ # end
+ pth == $constructedtempdir
+ #
Dir.mkdir(pth) if create
$constructedtempdir = pth
return pth
@@ -216,7 +221,7 @@ module Tool
def Tool.checksuffix(old)
- return old unless test(?f,old)
+ return old unless FileTest.file?(old)
new = old
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index b5e231e27..ecdc4c128 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -56,7 +56,8 @@ require 'base/file'
require 'rexml/document'
require 'net/http'
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
require 'kconv'
exit if defined?(REQUIRE2LIB)
@@ -2279,6 +2280,7 @@ class TexDeps
report("loading files")
report('')
n = 0
+# try tex and mkiv
@files.each do |filename|
if File.file?(filename) and f = File.open(filename) then
defs, uses, l = 0, 0, 0
diff --git a/scripts/context/ruby/fcd_start.rb b/scripts/context/ruby/fcd_start.rb
index 348ac75ba..28f407c76 100644
--- a/scripts/context/ruby/fcd_start.rb
+++ b/scripts/context/ruby/fcd_start.rb
@@ -260,6 +260,7 @@ class FastCD
puts(Dir.pwd.gsub(/\\/o, '/'))
end
rescue
+ puts("some error")
end
end
@@ -272,6 +273,7 @@ class FastCD
else
f.puts("cd #{dir.gsub("\\",'/')}")
end
+ f.close
end
@result = dir
report("changing to #{dir}",true)
@@ -283,6 +285,7 @@ class FastCD
end
def choose(args=[])
+ offset = 97
unless @pattern.empty? then
begin
case @result.size
@@ -301,7 +304,7 @@ class FastCD
return
end
else
- index = answer[0] - ?a
+ index = answer[0] - offset
if dir = list[index] then
chdir(dir)
return
@@ -309,21 +312,27 @@ class FastCD
end
end
rescue
+ puts("some error")
end
loop do
print("\n")
list.each_index do |i|
+begin
if i < @@maxlength then
- puts("#{(i+?a).chr} #{list[i]}")
+ # puts("#{(i+?a).chr} #{list[i]}")
+ puts("#{(i+offset).chr} #{list[i]}")
else
puts("\n there are #{list.length-@@maxlength} entries more")
break
end
+rescue
+ puts("some error")
+end
end
print("\n>> ")
if answer = wait then
- if answer >= ?a and answer <= ?z then
- index = answer - ?a
+ if answer >= offset and answer <= offset+25 then
+ index = answer - offset
if dir = list[index] then
print("#{answer.chr} ")
chdir(dir)
@@ -350,7 +359,7 @@ class FastCD
end
end
rescue
- # report($!)
+ report($!)
end
end
end
diff --git a/scripts/context/ruby/graphics/gs.rb b/scripts/context/ruby/graphics/gs.rb
index cb3d016f4..6143c8812 100644
--- a/scripts/context/ruby/graphics/gs.rb
+++ b/scripts/context/ruby/graphics/gs.rb
@@ -13,7 +13,8 @@
require 'base/variables'
require 'base/system'
-require 'ftools'
+require 'fileutils'
+# Require 'ftools'
class GhostScript
@@ -218,15 +219,15 @@ class GhostScript
rescue
report("job aborted due to some error: #{$!}")
begin
- File.delete(resultfile) if test(?e,resultfile)
+ File.delete(resultfile) if FileTest.file?(resultfile)
rescue
report("unable to delete faulty #{resultfile}")
end
ok = false
ensure
deleteprofile(getvariable('profile'))
- File.delete(@@pstempfile) if test(?e,@@pstempfile)
- File.delete(@@pdftempfile) if test(?e,@@pdftempfile)
+ File.delete(@@pstempfile) if FileTest.file?(@@pstempfile)
+ File.delete(@@pdftempfile) if FileTest.file?(@@pdftempfile)
end
return ok
end
@@ -243,13 +244,14 @@ class GhostScript
def pdfmethod? (str)
case method(str).to_i
- when 3, 4, 5 then return true
+ when 1, 3, 4, 5 then return true
end
return false
end
def pdfprefix (str)
case method(str).to_i
+ when 1 then return 'raw-'
when 4 then return 'lowres-'
when 5 then return 'normal-'
end
@@ -383,7 +385,7 @@ class GhostScript
debug('piping data')
unless pipebounded(tmp,eps) then
debug('something went wrong in the pipe')
- File.delete(outfile) if test(?e,outfile)
+ File.delete(outfile) if FileTest.file?(outfile)
end
debug('closing pipe')
eps.close_write
@@ -412,7 +414,7 @@ class GhostScript
unless ok then
begin
report('no output file due to error')
- File.delete(outfile) if test(?e,outfile)
+ File.delete(outfile) if FileTest.file?(outfile)
rescue
# debug("fatal error: #{$!}")
debug('file',outfile,'may be invalid')
@@ -421,7 +423,7 @@ class GhostScript
debug('deleting temp file')
begin
- File.delete(@@pstempfile) if test(?e,@@pstempfile)
+ File.delete(@@pstempfile) if FileTest.file?(@@pstempfile)
rescue
end
@@ -467,7 +469,7 @@ class GhostScript
# def convertcropped (inpfile, outfile)
# report("converting #{inpfile} cropped")
# do_convertbounded(inpfile, @@pdftempfile)
- # return unless test(?e,@@pdftempfile)
+ # return unless FileTest.file?(@@pdftempfile)
# arguments = " --offset=#{@offset} #{@@pdftempfile} #{outfile}"
# report("calling #{@@pdftrimwhite}")
# unless ok = System.run(@@pdftrimwhite,arguments) then
diff --git a/scripts/context/ruby/pdftools.rb b/scripts/context/ruby/pdftools.rb
index 23edfeca2..8ad74ec4f 100644
--- a/scripts/context/ruby/pdftools.rb
+++ b/scripts/context/ruby/pdftools.rb
@@ -20,7 +20,8 @@ $: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.u
require 'base/switch'
require 'base/logger'
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
class File
diff --git a/scripts/context/ruby/rlxtools.rb b/scripts/context/ruby/rlxtools.rb
index 1617fcad4..36bc9f790 100644
--- a/scripts/context/ruby/rlxtools.rb
+++ b/scripts/context/ruby/rlxtools.rb
@@ -19,7 +19,8 @@ require 'base/logger'
require 'base/system'
require 'base/kpse'
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
require 'rexml/document'
class Commands
diff --git a/scripts/context/ruby/rsfiltool.rb b/scripts/context/ruby/rsfiltool.rb
index f3abfdfc7..6d7c7aba0 100644
--- a/scripts/context/ruby/rsfiltool.rb
+++ b/scripts/context/ruby/rsfiltool.rb
@@ -18,7 +18,8 @@ end
# todo : split session stuff from xmpl/base into an xmpl/session module and "include xmpl/session" into base and here and ...
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
require 'xmpl/base'
require 'xmpl/switch'
require 'xmpl/request'
diff --git a/scripts/context/ruby/runtools.rb b/scripts/context/ruby/runtools.rb
index 9c504845a..5565748e2 100644
--- a/scripts/context/ruby/runtools.rb
+++ b/scripts/context/ruby/runtools.rb
@@ -1,5 +1,6 @@
require 'timeout'
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
require 'rbconfig'
class File
diff --git a/scripts/context/ruby/texexec.rb b/scripts/context/ruby/texexec.rb
index a09572c6c..a549659ef 100644
--- a/scripts/context/ruby/texexec.rb
+++ b/scripts/context/ruby/texexec.rb
@@ -1,8 +1,9 @@
-banner = ['TeXExec', 'version 6.2.0', '1997-2006', 'PRAGMA ADE/POD']
+banner = ['TeXExec', 'version 6.2.1', '1997-2009', 'PRAGMA ADE/POD']
$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
-require 'ftools' # needed ?
+require 'fileutils'
+# require 'ftools' # needed ?
require 'base/switch'
require 'base/logger'
@@ -277,6 +278,7 @@ class Commands
info = `pdfinfo #{filename}`
if info =~ /Pages:\s*(\d+)/ then
nofpages = $1.to_i
+ result = @commandline.checkedoption('result','texexec')
nofpages.times do |i|
if f = File.open(tempfile,"w") then
n = i + 1
@@ -285,8 +287,10 @@ class Commands
f << "\\externalfigure[#{filename}][object=no,page=#{n}]\n"
f << "\\stopTEXpage\\stoptext\n"
f.close
+ job.setvariable('result',"#{result}-#{n}")
job.setvariable('interface','english') # redundant
job.setvariable('simplerun',true)
+ job.setvariable('purge',true)
job.setvariable('files',[tempfile])
job.processtex
end
diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb
index 388bef85b..4976f7fd0 100644
--- a/scripts/context/ruby/texmfstart.rb
+++ b/scripts/context/ruby/texmfstart.rb
@@ -1,5 +1,9 @@
#!/usr/bin/env ruby
+# We have removed the fast, server and client variants and no longer
+# provide the distributed 'serve trees' option. After all, we're now
+# using luatex.
+
# program : texmfstart
# copyright : PRAGMA Advanced Document Engineering
# version : 1.9.0 - 2003/2006
@@ -18,8 +22,6 @@
# Of couse I can make this into a nice class, which i'll undoubtely will
# do when I feel the need. In that case it will be part of a bigger game.
-# turning this into a service would be nice, so some day ...
-
# --locate => provides location
# --exec => exec instead of system
# --iftouched=a,b => only if timestamp a<>b
@@ -34,30 +36,17 @@
$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
require "rbconfig"
-require "md5"
+require "fileutils"
-# funny, selfmergs was suddenly broken to case problems
-
-# kpse_merge_done: require 'base/kpseremote'
-# kpse_merge_done: require 'base/kpsedirect'
-# kpse_merge_done: require 'base/kpsefast'
-# kpse_merge_done: require 'base/merge'
+require "digest/md5"
# kpse_merge_start
-# kpse_merge_file: 't:/ruby/base/kpsefast.rb'
-
-# module : base/kpsefast
-# copyright : PRAGMA Advanced Document Engineering
-# version : 2005
-# author : Hans Hagen
-#
-# project : ConTeXt / eXaMpLe
-# concept : Hans Hagen
-# info : j.hagen@xs4all.nl
-
-# todo: multiple cnf files
-#
+class File
+ def File::makedirs(*x)
+ FileUtils.makedirs(x)
+ end
+end
class String
@@ -106,1147 +95,6 @@ class File
end
-module KpseUtil
-
- # to be adapted, see loading cnf file
-
- @@texmftrees = ['texmf-local','texmf.local','../..','texmf'] # '../..' is for gwtex
- @@texmfcnf = 'texmf.cnf'
-
- def KpseUtil::identify
- # we mainly need to identify the local tex stuff and wse assume that
- # the texmfcnf variable is set; otherwise we need to expand the
- # TEXMF variable and that takes time since it may involve more
- ownpath = File.expand_path($0)
- if ownpath.gsub!(/texmf.*?$/o, '') then
- ENV['SELFAUTOPARENT'] = ownpath
- else
- ENV['SELFAUTOPARENT'] = '.' # fall back
- # may be too tricky:
- #
- # (ENV['PATH'] ||'').split_path.each do |p|
- # if p.gsub!(/texmf.*?$/o, '') then
- # ENV['SELFAUTOPARENT'] = p
- # break
- # end
- # end
- end
- filenames = Array.new
- if ENV['TEXMFCNF'] && ! ENV['TEXMFCNF'].empty? then
- ENV['TEXMFCNF'].to_s.split_path.each do |path|
- filenames << File.join(path,@@texmfcnf)
- end
- elsif ENV['SELFAUTOPARENT'] == '.' then
- filenames << File.join('.',@@texmfcnf)
- else
- @@texmftrees.each do |tree|
- filenames << File.join(ENV['SELFAUTOPARENT'],tree,'web2c',@@texmfcnf)
- end
- end
- loop do
- busy = false
- filenames.collect! do |f|
- f.gsub(/\$([a-zA-Z0-9\_\-]+)/o) do
- if (! ENV[$1]) || (ENV[$1] == $1) then
- "$#{$1}"
- else
- busy = true
- ENV[$1]
- end
- end
- end
- break unless busy
- end
- filenames.delete_if do |f|
- ! FileTest.file?(f)
- end
- return filenames
- end
-
- def KpseUtil::environment
- Hash.new.merge(ENV)
- end
-
-end
-
-class KpseFast
-
- # formats are an incredible inconsistent mess
-
- @@suffixes = Hash.new
- @@formats = Hash.new
- @@suffixmap = Hash.new
-
- @@texmfcnf = 'texmf.cnf'
-
- @@suffixes['gf'] = ['.gf'] # todo
- @@suffixes['pk'] = ['.pk'] # todo
- @@suffixes['tfm'] = ['.tfm']
- @@suffixes['afm'] = ['.afm']
- @@suffixes['base'] = ['.base']
- @@suffixes['bib'] = ['.bib']
- @@suffixes['bst'] = ['.bst']
- @@suffixes['cnf'] = ['.cnf']
- @@suffixes['ls-R'] = ['ls-R', 'ls-r']
- @@suffixes['fmt'] = ['.fmt', '.efmt', '.efm', '.ofmt', '.ofm', '.oft', '.eofmt', '.eoft', '.eof', '.pfmt', '.pfm', '.epfmt', '.epf', '.xpfmt', '.xpf', '.afmt', '.afm']
- @@suffixes['map'] = ['.map']
- @@suffixes['mem'] = ['.mem']
- @@suffixes['mf'] = ['.mf']
- @@suffixes['mfpool'] = ['.pool']
- @@suffixes['mft'] = ['.mft']
- @@suffixes['mp'] = ['.mp']
- @@suffixes['mppool'] = ['.pool']
- @@suffixes['ocp'] = ['.ocp']
- @@suffixes['ofm'] = ['.ofm', '.tfm']
- @@suffixes['opl'] = ['.opl']
- @@suffixes['otp'] = ['.otp']
- @@suffixes['ovf'] = ['.ovf']
- @@suffixes['ovp'] = ['.ovp']
- @@suffixes['graphic/figure'] = ['.eps', '.epsi']
- @@suffixes['tex'] = ['.tex']
- @@suffixes['texpool'] = ['.pool']
- @@suffixes['PostScript header'] = ['.pro']
- @@suffixes['type1 fonts'] = ['.pfa', '.pfb']
- @@suffixes['vf'] = ['.vf']
- @@suffixes['ist'] = ['.ist']
- @@suffixes['truetype fonts'] = ['.ttf', '.ttc']
- @@suffixes['web'] = ['.web', '.ch']
- @@suffixes['cweb'] = ['.w', '.web', '.ch']
- @@suffixes['enc files'] = ['.enc']
- @@suffixes['cmap files'] = ['.cmap']
- @@suffixes['subfont definition files'] = ['.sfd']
- @@suffixes['lig files'] = ['.lig']
- @@suffixes['bitmap font'] = []
- @@suffixes['MetaPost support'] = []
- @@suffixes['TeX system documentation'] = []
- @@suffixes['TeX system sources'] = []
- @@suffixes['Troff fonts'] = []
- @@suffixes['dvips config'] = []
- @@suffixes['type42 fonts'] = []
- @@suffixes['web2c files'] = []
- @@suffixes['other text files'] = []
- @@suffixes['other binary files'] = []
- @@suffixes['misc fonts'] = []
- @@suffixes['opentype fonts'] = []
- @@suffixes['pdftex config'] = []
- @@suffixes['texmfscripts'] = []
-
- # replacements
-
- @@suffixes['fmt'] = ['.fmt']
- @@suffixes['type1 fonts'] = ['.pfa', '.pfb', '.pfm']
- @@suffixes['tex'] = ['.tex', '.xml']
- @@suffixes['texmfscripts'] = ['rb','lua','py','pl']
-
- @@suffixes.keys.each do |k| @@suffixes[k].each do |s| @@suffixmap[s] = k end end
-
- # TTF2TFMINPUTS
- # MISCFONTS
- # TEXCONFIG
- # DVIPDFMINPUTS
- # OTFFONTS
-
- @@formats['gf'] = ''
- @@formats['pk'] = ''
- @@formats['tfm'] = 'TFMFONTS'
- @@formats['afm'] = 'AFMFONTS'
- @@formats['base'] = 'MFBASES'
- @@formats['bib'] = ''
- @@formats['bst'] = ''
- @@formats['cnf'] = ''
- @@formats['ls-R'] = ''
- @@formats['fmt'] = 'TEXFORMATS'
- @@formats['map'] = 'TEXFONTMAPS'
- @@formats['mem'] = 'MPMEMS'
- @@formats['mf'] = 'MFINPUTS'
- @@formats['mfpool'] = 'MFPOOL'
- @@formats['mft'] = ''
- @@formats['mp'] = 'MPINPUTS'
- @@formats['mppool'] = 'MPPOOL'
- @@formats['ocp'] = 'OCPINPUTS'
- @@formats['ofm'] = 'OFMFONTS'
- @@formats['opl'] = 'OPLFONTS'
- @@formats['otp'] = 'OTPINPUTS'
- @@formats['ovf'] = 'OVFFONTS'
- @@formats['ovp'] = 'OVPFONTS'
- @@formats['graphic/figure'] = ''
- @@formats['tex'] = 'TEXINPUTS'
- @@formats['texpool'] = 'TEXPOOL'
- @@formats['PostScript header'] = 'TEXPSHEADERS'
- @@formats['type1 fonts'] = 'T1FONTS'
- @@formats['vf'] = 'VFFONTS'
- @@formats['ist'] = ''
- @@formats['truetype fonts'] = 'TTFONTS'
- @@formats['web'] = ''
- @@formats['cweb'] = ''
- @@formats['enc files'] = 'ENCFONTS'
- @@formats['cmap files'] = 'CMAPFONTS'
- @@formats['subfont definition files'] = 'SFDFONTS'
- @@formats['lig files'] = 'LIGFONTS'
- @@formats['bitmap font'] = ''
- @@formats['MetaPost support'] = ''
- @@formats['TeX system documentation'] = ''
- @@formats['TeX system sources'] = ''
- @@formats['Troff fonts'] = ''
- @@formats['dvips config'] = ''
- @@formats['type42 fonts'] = 'T42FONTS'
- @@formats['web2c files'] = 'WEB2C'
- @@formats['other text files'] = ''
- @@formats['other binary files'] = ''
- @@formats['misc fonts'] = ''
- @@formats['opentype fonts'] = 'OPENTYPEFONTS'
- @@formats['pdftex config'] = 'PDFTEXCONFIG'
- @@formats['texmfscripts'] = 'TEXMFSCRIPTS'
-
- attr_accessor :progname, :engine, :format, :rootpath, :treepath,
- :verbose, :remember, :scandisk, :diskcache, :renewcache
-
- @@cacheversion = '1'
-
- def initialize
- @rootpath = ''
- @treepath = ''
- @progname = 'kpsewhich'
- @engine = 'pdftex'
- @variables = Hash.new
- @expansions = Hash.new
- @files = Hash.new
- @found = Hash.new
- @kpsevars = Hash.new
- @lsrfiles = Array.new
- @cnffiles = Array.new
- @verbose = true
- @remember = true
- @scandisk = true
- @diskcache = true
- @renewcache = false
- @isolate = false
-
- @diskcache = false
- @cachepath = nil
- @cachefile = 'tmftools.log'
-
- @environment = ENV
- end
-
- def set(key,value)
- case key
- when 'progname' then @progname = value
- when 'engine' then @engine = value
- when 'format' then @format = value
- end
- end
-
- def push_environment(env)
- @environment = env
- end
-
- # {$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,}/web2c}
- #
- # $SELFAUTOLOC : /usr/tex/bin/platform
- # $SELFAUTODIR : /usr/tex/bin
- # $SELFAUTOPARENT : /usr/tex
- #
- # since we live in scriptpath we need a slightly different method
-
- def load_cnf(filenames=nil)
- unless filenames then
- ownpath = File.expand_path($0)
- if ownpath.gsub!(/texmf.*?$/o, '') then
- @environment['SELFAUTOPARENT'] = ownpath
- else
- @environment['SELFAUTOPARENT'] = '.'
- end
- unless @treepath.empty? then
- unless @rootpath.empty? then
- @treepath = @treepath.split(',').collect do |p| File.join(@rootpath,p) end.join(',')
- end
- @environment['TEXMF'] = @treepath
- # only the first one
- @environment['TEXMFCNF'] = File.join(@treepath.split(',').first,'texmf/web2c')
- end
- unless @rootpath.empty? then
- @environment['TEXMFCNF'] = File.join(@rootpath,'texmf/web2c')
- @environment['SELFAUTOPARENT'] = @rootpath
- @isolate = true
- end
- filenames = Array.new
- if @environment['TEXMFCNF'] and not @environment['TEXMFCNF'].empty? then
- @environment['TEXMFCNF'].to_s.split_path.each do |path|
- filenames << File.join(path,@@texmfcnf)
- end
- elsif @environment['SELFAUTOPARENT'] == '.' then
- filenames << File.join('.',@@texmfcnf)
- else
- ['texmf-local','texmf'].each do |tree|
- filenames << File.join(@environment['SELFAUTOPARENT'],tree,'web2c',@@texmfcnf)
- end
- end
- end
- # /texmf/web2c/texmf.cnf
- filenames = _expanded_path_(filenames)
- @rootpath = filenames.first
- 3.times do
- @rootpath = File.dirname(@rootpath)
- end
- filenames.collect! do |f|
- f.gsub("\\", '/')
- end
- filenames.each do |fname|
- if FileTest.file?(fname) and f = File.open(fname) then
- @cnffiles << fname
- while line = f.gets do
- loop do
- # concatenate lines ending with \
- break unless line.sub!(/\\\s*$/o) do
- f.gets || ''
- end
- end
- case line
- when /^[\%\#]/o then
- # comment
- when /^\s*(.*?)\s*\=\s*(.*?)\s*$/o then
- key, value = $1, $2
- unless @variables.key?(key) then
- value.sub!(/\%.*$/,'')
- value.sub!(/\~/, "$HOME")
- @variables[key] = value
- end
- @kpsevars[key] = true
- end
- end
- f.close
- end
- end
- end
-
- def load_lsr
- @lsrfiles = []
- simplified_list(expansion('TEXMF')).each do |p|
- ['ls-R','ls-r'].each do |f|
- filename = File.join(p,f)
- if FileTest.file?(filename) then
- @lsrfiles << [filename,File.size(filename)]
- break
- end
- end
- end
- @files = Hash.new
- if @diskcache then
- ['HOME','TEMP','TMP','TMPDIR'].each do |key|
- if @environment[key] then
- if FileTest.directory?(@environment[key]) then
- @cachepath = @environment[key]
- @cachefile = [@rootpath.gsub(/[^A-Z0-9]/io, '-').gsub(/\-+/,'-'),File.basename(@cachefile)].join('-')
- break
- end
- end
- end
- if @cachepath and not @renewcache and FileTest.file?(File.join(@cachepath,@cachefile)) then
- begin
- if f = File.open(File.join(@cachepath,@cachefile)) then
- cacheversion = Marshal.load(f)
- if cacheversion == @@cacheversion then
- lsrfiles = Marshal.load(f)
- if lsrfiles == @lsrfiles then
- @files = Marshal.load(f)
- end
- end
- f.close
- end
- rescue
- @files = Hash.new
- end
- end
- end
- return if @files.size > 0
- @lsrfiles.each do |filedata|
- filename, filesize = filedata
- filepath = File.dirname(filename)
- begin
- path = '.'
- data = IO.readlines(filename)
- if data[0].chomp =~ /% ls\-R \-\- filename database for kpathsea\; do not change this line\./io then
- data.each do |line|
- case line
- when /^[a-zA-Z0-9]/o then
- line.chomp!
- if @files[line] then
- @files[line] << path
- else
- @files[line] = [path]
- end
- when /^\.\/(.*?)\:$/o then
- path = File.join(filepath,$1)
- end
- end
- end
- rescue
- # sorry
- end
- end
- if @diskcache and @cachepath and f = File.open(File.join(@cachepath,@cachefile),'wb') then
- f << Marshal.dump(@@cacheversion)
- f << Marshal.dump(@lsrfiles)
- f << Marshal.dump(@files)
- f.close
- end
- end
-
- def expand_variables
- @expansions = Hash.new
- if @isolate then
- @variables['TEXMFCNF'] = @environment['TEXMFCNF'].dup
- @variables['SELFAUTOPARENT'] = @environment['SELFAUTOPARENT'].dup
- else
- @environment.keys.each do |e|
- if e =~ /^([a-zA-Z]+)\_(.*)\s*$/o then
- @expansions["#{$1}.#{$2}"] = (@environment[e] ||'').dup
- else
- @expansions[e] = (@environment[e] ||'').dup
- end
- end
- end
- @variables.keys.each do |k|
- @expansions[k] = @variables[k].dup unless @expansions[k]
- end
- loop do
- busy = false
- @expansions.keys.each do |k|
- @expansions[k].gsub!(/\$([a-zA-Z0-9\_\-]*)/o) do
- busy = true
- @expansions[$1] || ''
- end
- @expansions[k].gsub!(/\$\{([a-zA-Z0-9\_\-]*)\}/o) do
- busy = true
- @expansions[$1] || ''
- end
- end
- break unless busy
- end
- @expansions.keys.each do |k|
- @expansions[k] = @expansions[k].gsub("\\", '/')
- end
- end
-
- def variable(name='')
- (name and not name.empty? and @variables[name.sub('$','')]) or ''
- end
-
- def expansion(name='')
- (name and not name.empty? and @expansions[name.sub('$','')]) or ''
- end
-
- def variable?(name='')
- name and not name.empty? and @variables.key?(name.sub('$',''))
- end
-
- def expansion?(name='')
- name and not name.empty? and @expansions.key?(name.sub('$',''))
- end
-
- def simplified_list(str)
- lst = str.gsub(/^\{/o,'').gsub(/\}$/o,'').split(",")
- lst.collect do |l|
- l.sub(/^[\!]*/,'').sub(/[\/\\]*$/o,'')
- end
- end
-
- def original_variable(variable)
- if variable?("#{@progname}.#{variable}") then
- variable("#{@progname}.#{variable}")
- elsif variable?(variable) then
- variable(variable)
- else
- ''
- end
- end
-
- def expanded_variable(variable)
- if expansion?("#{variable}.#{@progname}") then
- expansion("#{variable}.#{@progname}")
- elsif expansion?(variable) then
- expansion(variable)
- else
- ''
- end
- end
-
- def original_path(filename='')
- _expanded_path_(original_variable(var_of_format_or_suffix(filename)).split(";"))
- end
-
- def expanded_path(filename='')
- _expanded_path_(expanded_variable(var_of_format_or_suffix(filename)).split(";"))
- end
-
- def _expanded_path_(pathlist)
- i, n = 0, 0
- pathlist.collect! do |mainpath|
- mainpath.gsub(/([\{\}])/o) do
- if $1 == "{" then
- i += 1 ; n = i if i > n ; "<#{i}>"
- else
- i -= 1 ; "#{i+1}>"
- end
- end
- end
- n.times do |i|
- loop do
- more = false
- newlist = []
- pathlist.each do |path|
- unless path.sub!(/^(.*?)<(#{n-i})>(.*?)<\/\2>(.*?)$/) do
- pre, mid, post = $1, $3, $4
- mid.gsub!(/\,$/,',.')
- mid.split(',').each do |m|
- more = true
- if m == '.' then
- newlist << "#{pre}#{post}"
- else
- newlist << "#{pre}#{m}#{post}"
- end
- end
- end then
- newlist << path
- end
- end
- if more then
- pathlist = [newlist].flatten # copy -)
- else
- break
- end
- end
- end
- pathlist = pathlist.uniq.collect do |path|
- p = path
- # p.gsub(/^\/+/o) do '' end
- # p.gsub!(/(.)\/\/(.)/o) do "#{$1}/#{$2}" end
- # p.gsub!(/\/\/+$/o) do '//' end
- p.gsub!(/\/\/+/o) do '//' end
- p
- end
- pathlist
- end
-
- # todo: ignore case
-
- def var_of_format(str)
- @@formats[str] || ''
- end
-
- def var_of_suffix(str) # includes .
- if @@suffixmap.key?(str) then @@formats[@@suffixmap[str]] else '' end
- end
-
- def var_of_format_or_suffix(str)
- if @@formats.key?(str) then
- @@formats[str]
- elsif @@suffixmap.key?(File.extname(str)) then # extname includes .
- @@formats[@@suffixmap[File.extname(str)]] # extname includes .
- else
- ''
- end
- end
-
-end
-
-class KpseFast
-
- # test things
-
- def list_variables(kpseonly=true)
- @variables.keys.sort.each do |k|
- if kpseonly then
- puts("#{k} = #{@variables[k]}") if @kpsevars[k]
- else
- puts("#{if @kpsevars[k] then 'K' else 'E' end} #{k} = #{@variables[k]}")
- end
- end
- end
-
- def list_expansions(kpseonly=true)
- @expansions.keys.sort.each do |k|
- if kpseonly then
- puts("#{k} = #{@expansions[k]}") if @kpsevars[k]
- else
- puts("#{if @kpsevars[k] then 'K' else 'E' end} #{k} = #{@expansions[k]}")
- end
- end
- end
-
- def list_lsr
- puts("files = #{@files.size}")
- end
-
- def set_test_patterns
- @variables["KPSE_TEST_PATTERN_A"] = "foo/{1,2}/bar//"
- @variables["KPSE_TEST_PATTERN_B"] = "!!x{A,B{1,2}}y"
- @variables["KPSE_TEST_PATTERN_C"] = "x{A,B//{1,2}}y"
- @variables["KPSE_TEST_PATTERN_D"] = "x{A,B//{1,2,}}//y"
- end
-
- def show_test_patterns
- ['A','B','D'].each do |i|
- puts ""
- puts @variables ["KPSE_TEST_PATTERN_#{i}"]
- puts ""
- puts expand_path("KPSE_TEST_PATTERN_#{i}").split_path
- puts ""
- end
- end
-
-end
-
-class KpseFast
-
- # kpse stuff
-
- def expand_braces(str) # output variable and brace expansion of STRING.
- _expanded_path_(original_variable(str).split_path).join_path
- end
-
- def expand_path(str) # output complete path expansion of STRING.
- _expanded_path_(expanded_variable(str).split_path).join_path
- end
-
- def expand_var(str) # output variable expansion of STRING.
- expanded_variable(str)
- end
-
- def show_path(str) # output search path for file type NAME
- expanded_path(str).join_path
- end
-
- def var_value(str) # output the value of variable $STRING.
- original_variable(str)
- end
-
-end
-
-class KpseFast
-
- def _is_cnf_?(filename)
- filename == File.basename((@cnffiles.first rescue @@texmfcnf) || @@texmfcnf)
- end
-
- def find_file(filename)
- if _is_cnf_?(filename) then
- @cnffiles.first rescue ''
- else
- [find_files(filename,true)].flatten.first || ''
- end
- end
-
- def find_files(filename,first=false)
- if _is_cnf_?(filename) then
- result = @cnffiles.dup
- else
- if @remember then
- # stamp = "#{filename}--#{@format}--#{@engine}--#{@progname}"
- stamp = "#{filename}--#{@engine}--#{@progname}"
- return @found[stamp] if @found.key?(stamp)
- end
- pathlist = expanded_path(filename)
- result = []
- filelist = if @files.key?(filename) then @files[filename].uniq else nil end
- done = false
- if pathlist.size == 0 then
- if FileTest.file?(filename) then
- done = true
- result << '.'
- end
- else
- pathlist.each do |path|
- doscan = if path =~ /^\!\!/o then false else true end
- recurse = if path =~ /\/\/$/o then true else false end
- pathname = path.dup
- pathname.gsub!(/^\!+/o, '')
- done = false
- if not done and filelist then
- # checking for exact match
- if filelist.include?(pathname) then
- result << pathname
- done = true
- end
- if not done and recurse then
- # checking for fuzzy //
- pathname.gsub!(/\/+$/o, '/.*')
- # pathname.gsub!(/\/\//o,'/[\/]*/')
- pathname.gsub!(/\/\//o,'/.*?/')
- re = /^#{pathname}/
- filelist.each do |f|
- if re =~ f then
- result << f # duplicates will be filtered later
- done = true
- end
- break if done
- end
- end
- end
- if not done and doscan then
- # checking for path itself
- pname = pathname.sub(/\.\*$/,'')
- if not pname =~ /\*/o and FileTest.file?(File.join(pname,filename)) then
- result << pname
- done = true
- end
- end
- break if done and first
- end
- end
- if not done and @scandisk then
- pathlist.each do |path|
- pathname = path.dup
- unless pathname.gsub!(/^\!+/o, '') then # !! prevents scan
- recurse = pathname.gsub!(/\/+$/o, '')
- complex = pathname.gsub!(/\/\//o,'/*/')
- if recurse then
- if complex then
- if ok = File.glob_file("#{pathname}/**/#{filename}") then
- result << File.dirname(ok)
- done = true
- end
- elsif ok = File.locate_file(pathname,filename) then
- result << File.dirname(ok)
- done = true
- end
- elsif complex then
- if ok = File.glob_file("#{pathname}/#{filename}") then
- result << File.dirname(ok)
- done = true
- end
- elsif FileTest.file?(File.join(pathname,filename)) then
- result << pathname
- done = true
- end
- break if done and first
- end
- end
- end
- result = result.uniq.collect do |pathname|
- File.join(pathname,filename)
- end
- @found[stamp] = result if @remember
- end
- return result # redundant
- end
-
-end
-
-class KpseFast
-
- class FileData
- attr_accessor :tag, :name, :size, :date
- def initialize(tag=0,name=nil,size=nil,date=nil)
- @tag, @name, @size, @date = tag, name, size, date
- end
- def FileData.sizes(a)
- a.collect do |aa|
- aa.size
- end
- end
- def report
- case @tag
- when 1 then "deleted | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}"
- when 2 then "present | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}"
- when 3 then "obsolete | #{' '*8} | #{' '*16} | #{@name}"
- end
- end
- end
-
- def analyze_files(filter='',strict=false,sort='',delete=false)
- puts("command line = #{ARGV.join(' ')}")
- puts("number of files = #{@files.size}")
- puts("filter pattern = #{filter}")
- puts("loaded cnf files = #{@cnffiles.join(' ')}")
- puts('')
- if filter.gsub!(/^not:/,'') then
- def the_same(filter,filename)
- not filter or filter.empty? or /#{filter}/ !~ filename
- end
- else
- def the_same(filter,filename)
- not filter or filter.empty? or /#{filter}/ =~ filename
- end
- end
- @files.keys.each do |name|
- if @files[name].size > 1 then
- data = Array.new
- @files[name].each do |path|
- filename = File.join(path,name)
- # if not filter or filter.empty? or /#{filter}/ =~ filename then
- if the_same(filter,filename) then
- if FileTest.file?(filename) then
- if delete then
- data << FileData.new(1,filename,File.size(filename),File.mtime(filename))
- begin
- File.delete(filename) if delete
- rescue
- end
- else
- data << FileData.new(2,filename,File.size(filename),File.mtime(filename))
- end
- else
- # data << FileData.new(3,filename)
- end
- end
- end
- if data.length > 1 then
- if strict then
- # if data.collect do |d| d.size end.uniq! then
- # data.sort! do |a,b| b.size <=> a.size end
- # data.each do |d| puts d.report end
- # puts ''
- # end
- data.sort! do |a,b|
- if a.size and b.size then
- b.size <=> a.size
- else
- 0
- end
- end
- bunch = Array.new
- done = false
- data.each do |d|
- if bunch.size == 0 then
- bunch << d
- elsif bunch[0].size == d.size then
- bunch << d
- else
- if bunch.size > 1 then
- bunch.each do |b|
- puts b.report
- end
- done = true
- end
- bunch = [d]
- end
- end
- puts '' if done
- else
- case sort
- when 'size' then data.sort! do |a,b| a.size <=> b.size end
- when 'revsize' then data.sort! do |a,b| b.size <=> a.size end
- when 'date' then data.sort! do |a,b| a.date <=> b.date end
- when 'revdate' then data.sort! do |a,b| b.date <=> a.date end
- end
- data.each do |d| puts d.report end
- puts ''
- end
- end
- end
- end
- end
-
-end
-
-
- # k = KpseFast.new # (root)
- # k.set_test_patterns
- # k.load_cnf
- # k.expand_variables
- # k.load_lsr
-
- # k.show_test_patterns
-
- # puts k.list_variables
- # puts k.list_expansions
- # k.list_lsr
- # puts k.expansion("$TEXMF")
- # puts k.expanded_path("TEXINPUTS","context")
-
- # k.progname, k.engine, k.format = 'context', 'pdftex', 'tfm'
- # k.scandisk = false # == must_exist
- # k.expand_variables
-
- # 10.times do |i| puts k.find_file('texnansi-lmr10.tfm') end
-
- # puts "expand braces $TEXMF"
- # puts k.expand_braces("$TEXMF")
- # puts "expand path $TEXMF"
- # puts k.expand_path("$TEXMF")
- # puts "expand var $TEXMF"
- # puts k.expand_var("$TEXMF")
- # puts "expand path $TEXMF"
- # puts k.show_path('tfm')
- # puts "expand value $TEXINPUTS"
- # puts k.var_value("$TEXINPUTS")
- # puts "expand value $TEXINPUTS.context"
- # puts k.var_value("$TEXINPUTS.context")
-
- # exit
-
-
-
-# kpse_merge_file: 't:/ruby/base/kpse/trees.rb'
-
-require 'monitor'
-# kpse_merge_done: require 'base/kpsefast'
-
-class KpseTrees < Monitor
-
- def initialize
- @trees = Hash.new
- end
-
- def pattern(filenames)
- filenames.join('|').gsub(/\\+/o,'/').downcase
- end
-
- def choose(filenames,environment)
- current = pattern(filenames)
- load(filenames,environment) unless @trees[current]
- puts "enabling tree #{current}"
- current
- end
-
- def fetch(filenames,environment) # will send whole object !
- current = pattern(filenames)
- load(filenames,environment) unless @trees[current]
- puts "fetching tree #{current}"
- @trees[current]
- end
-
- def load(filenames,environment)
- current = pattern(filenames)
- puts "loading tree #{current}"
- @trees[current] = KpseFast.new
- @trees[current].push_environment(environment)
- @trees[current].load_cnf(filenames)
- @trees[current].expand_variables
- @trees[current].load_lsr
- end
-
- def set(tree,key,value)
- case key
- when 'progname' then @trees[tree].progname = value
- when 'engine' then @trees[tree].engine = value
- when 'format' then @trees[tree].format = value
- end
- end
- def get(tree,key)
- case key
- when 'progname' then @trees[tree].progname
- when 'engine' then @trees[tree].engine
- when 'format' then @trees[tree].format
- end
- end
-
- def load_cnf(tree)
- @trees[tree].load_cnf
- end
- def load_lsr(tree)
- @trees[tree].load_lsr
- end
- def expand_variables(tree)
- @trees[tree].expand_variables
- end
- def expand_braces(tree,str)
- @trees[tree].expand_braces(str)
- end
- def expand_path(tree,str)
- @trees[tree].expand_path(str)
- end
- def expand_var(tree,str)
- @trees[tree].expand_var(str)
- end
- def show_path(tree,str)
- @trees[tree].show_path(str)
- end
- def var_value(tree,str)
- @trees[tree].var_value(str)
- end
- def find_file(tree,filename)
- @trees[tree].find_file(filename)
- end
- def find_files(tree,filename,first)
- @trees[tree].find_files(filename,first)
- end
-
-end
-
-
-# kpse_merge_file: 't:/ruby/base/kpse/drb.rb'
-
-require 'drb'
-# kpse_merge_done: require 'base/kpse/trees'
-
-class KpseServer
-
- attr_accessor :port
-
- def initialize(port=7000)
- @port = port
- end
-
- def start
- puts "starting drb service at port #{@port}"
- DRb.start_service("druby://localhost:#{@port}", KpseTrees.new)
- trap(:INT) do
- DRb.stop_service
- end
- DRb.thread.join
- end
-
- def stop
- # todo
- end
-
-end
-
-class KpseClient
-
- attr_accessor :port
-
- def initialize(port=7000)
- @port = port
- @kpse = nil
- end
-
- def start
- # only needed when callbacks are used / slow, due to Socket::getaddrinfo
- # DRb.start_service
- end
-
- def object
- @kpse = DRbObject.new(nil,"druby://localhost:#{@port}")
- end
-
-end
-
-
-# SERVER_URI="druby://localhost:8787"
-#
-# # Start a local DRbServer to handle callbacks.
-# #
-# # Not necessary for this small example, but will be required
-# # as soon as we pass a non-marshallable object as an argument
-# # to a dRuby call.
-# DRb.start_service
-#
-
-
-# kpse_merge_file: 't:/ruby/base/kpseremote.rb'
-
-# kpse_merge_done: require 'base/kpsefast'
-
-case ENV['KPSEMETHOD']
- when /soap/o then # kpse_merge_done: require 'base/kpse/soap'
- when /drb/o then # kpse_merge_done: require 'base/kpse/drb'
- else # kpse_merge_done: require 'base/kpse/drb'
-end
-
-class KpseRemote
-
- @@port = ENV['KPSEPORT'] || 7000
- @@method = ENV['KPSEMETHOD'] || 'drb'
-
- def KpseRemote::available?
- @@method && @@port
- end
-
- def KpseRemote::start_server(port=nil)
- kpse = KpseServer.new(port || @@port)
- kpse.start
- end
-
- def KpseRemote::start_client(port=nil) # keeps object in server
- kpseclient = KpseClient.new(port || @@port)
- kpseclient.start
- kpse = kpseclient.object
- tree = kpse.choose(KpseUtil::identify, KpseUtil::environment)
- [kpse, tree]
- end
-
- def KpseRemote::fetch(port=nil) # no need for defining methods but slower, send whole object
- kpseclient = KpseClient.new(port || @@port)
- kpseclient.start
- kpseclient.object.fetch(KpseUtil::identify, KpseUtil::environment) rescue nil
- end
-
- def initialize(port=nil)
- if KpseRemote::available? then
- begin
- @kpse, @tree = KpseRemote::start_client(port)
- rescue
- @kpse, @tree = nil, nil
- end
- else
- @kpse, @tree = nil, nil
- end
- end
-
- def progname=(value)
- @kpse.set(@tree,'progname',value)
- end
- def format=(value)
- @kpse.set(@tree,'format',value)
- end
- def engine=(value)
- @kpse.set(@tree,'engine',value)
- end
-
- def progname
- @kpse.get(@tree,'progname')
- end
- def format
- @kpse.get(@tree,'format')
- end
- def engine
- @kpse.get(@tree,'engine')
- end
-
- def load
- @kpse.load(KpseUtil::identify, KpseUtil::environment)
- end
- def okay?
- @kpse && @tree
- end
- def set(key,value)
- @kpse.set(@tree,key,value)
- end
- def load_cnf
- @kpse.load_cnf(@tree)
- end
- def load_lsr
- @kpse.load_lsr(@tree)
- end
- def expand_variables
- @kpse.expand_variables(@tree)
- end
- def expand_braces(str)
- clean_name(@kpse.expand_braces(@tree,str))
- end
- def expand_path(str)
- clean_name(@kpse.expand_path(@tree,str))
- end
- def expand_var(str)
- clean_name(@kpse.expand_var(@tree,str))
- end
- def show_path(str)
- clean_name(@kpse.show_path(@tree,str))
- end
- def var_value(str)
- clean_name(@kpse.var_value(@tree,str))
- end
- def find_file(filename)
- clean_name(@kpse.find_file(@tree,filename))
- end
- def find_files(filename,first=false)
- # dodo: each filename
- @kpse.find_files(@tree,filename,first)
- end
-
- private
-
- def clean_name(str)
- str.gsub(/\\/,'/')
- end
-
-end
-
-
# kpse_merge_file: 't:/ruby/base/kpsedirect.rb'
class KpseDirect
@@ -1284,14 +132,11 @@ class KpseDirect
end
-
# kpse_merge_stop
-
-
$mswindows = Config::CONFIG['host_os'] =~ /mswin/
$separator = File::PATH_SEPARATOR
-$version = "2.0.3"
+$version = "2.1.0"
$ownpath = File.dirname($0)
if $mswindows then
@@ -1335,7 +180,7 @@ $predefined['ctxtools'] = 'ctxtools.rb'
$predefined['rlxtools'] = 'rlxtools.rb'
$predefined['pdftools'] = 'pdftools.rb'
$predefined['mpstools'] = 'mpstools.rb'
-$predefined['exatools'] = 'exatools.rb'
+# $predefined['exatools'] = 'exatools.rb'
$predefined['xmltools'] = 'xmltools.rb'
# $predefined['luatools'] = 'luatools.lua'
# $predefined['mtxtools'] = 'mtxtools.rb'
@@ -1412,22 +257,7 @@ def check_kpse
if $kpse then
# already done
else
- begin
- if KpseRemote::available? then
- $kpse = KpseRemote.new
- if $kpse.okay? then
- puts("kpse : remote") if $verbose
- else
- $kpse = KpseDirect.new
- puts("kpse : direct (forced)") if $verbose
- end
- else
- $kpse = KpseDirect.new
- puts("kpse : direct") if $verbose
- end
- rescue
- puts("kpse : direct (fallback)") if $verbose
- end
+ $kpse = KpseDirect.new
end
end
@@ -1488,18 +318,6 @@ end
class File
- # def File.needsupdate(oldname,newname)
- # begin
- # if $mswindows then
- # return File.stat(oldname).mtime > File.stat(newname).mtime
- # else
- # return File.stat(oldname).mtime != File.stat(newname).mtime
- # end
- # rescue
- # return true
- # end
- # end
-
@@update_eps = 1
def File.needsupdate(oldname,newname)
@@ -1543,33 +361,6 @@ class File
end
-# def hashed (arr=[])
- # arg = if arr.class == String then arr.split(' ') else arr.dup end
- # hsh = Hash.new
- # if arg.length > 0
- # hsh['arguments'] = ''
- # done = false
- # arg.each do |s|
- # if done then
- # if s =~ / / then
- # hsh['arguments'] += " \"#{s}\"" # maybe split on =
- # else
- # hsh['arguments'] += " #{s}"
- # end
- # else
- # kvl = s.split('=')
- # if kvl[0].sub!(/^\-+/,'') then
- # hsh[kvl[0]] = if kvl.length > 1 then kvl[1] else true end
- # else
- # hsh['file'] = s
- # done = true
- # end
- # end
- # end
- # end
- # return hsh
-# end
-
def hashed (arr=[])
arg = if arr.class == String then arr.split(' ') else arr.dup end
hsh = Hash.new
@@ -2115,12 +906,6 @@ end
def make(filename,windows=false,linux=false,remove=false)
basename = File.basename(filename).gsub(/\.[^.]+?$/, '')
-# if @kpse.find_file(@tree,filename+".lua") or @kpse.find_file(@tree,filename+".rb") or @kpse.find_file(@tree,filename+".pl") then
- # make stub indeed
-# else
- # report("no stub needed for '#{basename}'")
- # return
-# end
if $stubpath == 'auto' then
basename = File.dirname($0) + '/' + basename
else
@@ -2203,7 +988,7 @@ def process(&block)
checkname = filename + ".md5"
oldchecksum, newchecksum = "old", "new"
begin
- newchecksum = MD5.new(IO.read(filename)).hexdigest.upcase
+ newchecksum = Digest::MD5.hexdigest(IO.read(filename)).upcase
rescue
newchecksum = "new"
else
@@ -2423,22 +1208,6 @@ def execute(arguments) # br global
elsif $selfcleanup then
output("ruby libraries are cleaned up") if SelfMerge::cleanup
return true
- elsif $serve then
- if ENV['KPSEMETHOD'] && ENV['KPSEPORT'] then
- # # kpse_merge_done: require 'base/kpseremote'
- begin
- KpseRemote::start_server
- rescue
- return false
- else
- return true
- end
- else
- usage
- puts("")
- puts("message : set 'KPSEMETHOD' and 'KPSEPORT' variables")
- return false
- end
elsif $help || ! $filename || $filename.empty? then
usage
loadtree($tree)
diff --git a/scripts/context/ruby/textools.rb b/scripts/context/ruby/textools.rb
index 442dc1924..a5858c5ca 100644
--- a/scripts/context/ruby/textools.rb
+++ b/scripts/context/ruby/textools.rb
@@ -20,7 +20,8 @@ $: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.u
require 'base/switch'
require 'base/logger'
-require 'ftools'
+require 'fileutils'
+# require 'ftools'
# Remark
#
diff --git a/scripts/context/ruby/www/admin.rb b/scripts/context/ruby/www/admin.rb
deleted file mode 100644
index 8983ca2b7..000000000
--- a/scripts/context/ruby/www/admin.rb
+++ /dev/null
@@ -1,215 +0,0 @@
-require 'fileutils'
-
-require 'www/lib'
-require 'www/dir'
-require 'www/common'
-
-class WWW
-
- include Common
-
- # klopt nog niet, twee keer task met een verschillend doel
-
- def handle_exatask
- # case @session.check('task', request_variable('task'))
- task, options, option = @session.get('task'), @session.get('option').split(@@re_bar), request_variable('option')
- option = (options.first || '') if option.empty?
- case task
- when 'exaadmin'
- @session.set('status', 'admin') # admin: status|dir
- touch_session(@session.get('id'))
- if options.include?(option) then
- case option
- when 'status' then handle_exaadmin_status
- when 'dir' then handle_exaadmin_dir
- else handle_exaadmin_status
- end
- elsif option.empty? then
- message('Status', "unknown option")
- else
- message('Status', "option '#{option}' not permitted #{options.inspect}")
- end
- else
- message('Status', "unknown task '#{task}'")
- end
- end
-
- def handle_exaadmin
- if id = valid_session() then
- handle_exatask
- else
- message('Status', 'no login')
- end
- end
-
- def handle_exaadmin_dir
- check_template_file('exalogin','exalogin-template.htm')
- @interface.set('path:docroot', work_root)
- @interface.set('dir:uri', 'exaadmin') # forces the dir handler into cgi mode
- @interface.set('dir:task', 'exaadmin') # forces the dir handler into cgi mode
- @interface.set('dir:option', 'dir') # forces the dir handler into cgi mode
- filename = "#{@@session_prefix}#{request_variable('path')}"
- fullname = File.join(work_root,filename)
- if request_variable('path').empty? then
- handle_exaadmin_status
- elsif FileTest.directory?(fullname) then
- handle_dir(filename, [], false)
- elsif File.zero?(fullname) then
- message('Error', "The file '#{filename}' is empty")
- elsif File.size?(fullname) > (4 * 1024 * 1024) then
- if FileTest.file?(File.expand_path(File.join(cache_root,filename))) then
- str = "
Cached alternative: #{File.basename(filename)}"
- else
- str = ''
- end
- message('Error', "The file '#{filename}' is too big to serve over cgi." + str)
- else
- send_file(fullname)
- end
- end
-
- def handle_exaadmin_status
- check_template_file('exalogin','exalogin-template.htm')
- begin
- n, str, lines, list, start, most, least, cached = 0, '', '', Hash.new, Time.now, 0, 0, false
- filename = File.join(tmp_path(dirname),'sessions.rbd')
- begin
- File.open(filename) do |f|
- list = Marshal.load(f)
- end
- rescue
- cached, list = false, Hash.new
- else
- cached = true
- end
- files = Dir.glob("{#{work_roots.join(',')}}/#{@@session_prefix}*.ses")
- list.keys.each do |l|
- list.delete(l) unless files.include?(l) # slow
- end
- files.each do |f|
- ctime = File.ctime(f)
- stime = list[f][0] == ctime rescue 0
- unless ctime == stime then
- begin
- hash = load_session_file(f)
- rescue
- else
- list[f] = [ctime,hash]
- end
- end
- end
- begin
- File.open(filename,'w') do |f|
- f << Marshal.dump(list)
- end
- rescue
- # no save
- end
- begin
- keys = list.keys.sort do |a,b|
- case list[b][0] <=> list[a][0]
- when -1 then -1
- when +1 then +1
- else
- a <=> b
- end
- end
- rescue
- keys = list.keys.sort
- end
- totaltime, totaldone = 0.0, 0
- if keys.length > 0 then
- keys.each do |entry|
- s, t, session = entry, list[entry][0], list[entry][1]
- status = session['status'] || ''
- runtime = (session['runtime'] || '').to_f rescue 0
- starttime = (start.to_i-session['starttime'].to_i).to_s rescue ''
- requesttime = session['endtime'].to_i-session['starttime'].to_i rescue 0
- requesttime = if requesttime > 0 then requesttime.to_s else '' end
- if runtime > 0.0 then
- totaltime += runtime
- totaldone += 1
- if least > 0 then
- if runtime < least then least = runtime end
- else
- least = runtime
- end
- if most > 0 then
- if runtime > most then most = runtime end
- else
- most = runtime
- end
- end
- if status.empty? then
- # skip, garbage
- elsif status =~ /^(|exa)admin/o then
- # skip, useless
- else
- begin
- lines << "
\n"
- end
- end
- rescue
- message('Status', "#{$!} There is currently no status available.", false, @@admin_refresh, 'exaadmin')
- else
- if n > 0 then
- # r = if n > 100 then 60 else @@admin_refresh.to_i end # scanning takes long
- r = @@admin_refresh
- average = "average = #{if totaldone > 0 then sprintf('%.02f',totaltime/totaldone) else '0' end} (#{sprintf('%.02f',least)} .. #{sprintf('%.02f',most)})"
- sessions = "sessions = #{n}"
- refresh = "refresh = #{r.to_s} sec"
- loadtime = "loadtime = #{sprintf('%.04f',Time.now-start)} sec"
- cached = if cached then "cached" else "not cached" end
- message("Status | #{sessions} | #{refresh} | #{loadtime} - #{cached} | #{average} |", str, false, r, 'exaadmin')
- else
- message('Status', "There are no sessions registered.", false, @@admin_refresh, 'exaadmin')
- end
- end
- end
-
- private
-
- def th(str)
- "
#{str}
\n"
- end
-
- def td(str)
- "
#{str || ''}  
\n"
- end
-
-end
diff --git a/scripts/context/ruby/www/common.rb b/scripts/context/ruby/www/common.rb
deleted file mode 100644
index 9c3832294..000000000
--- a/scripts/context/ruby/www/common.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-# We cannot chdir in threads because it is something
-# process wide, so we will run into problems with the
-# other threads. The same is true for the global ENV
-# pseudo hash, so we cannot communicate the runpath
-# via an anvironment either. This leaves texmfstart
-# in combination with a path directive and an tmf file.
-
-module Common # can be a mixin
-
- # we assume that the hash.subset method is defined
-
- @@re_texmfstart = /^(texmfstart|ruby\s*texmfstart.rb)\s*(.*)$/
- @@re_texmfpath = /^\-\-path\=/
-
- def command_string(path,command,log='')
- runner = "texmfstart --path=#{File.expand_path(path)}"
- if command =~ @@re_texmfstart then
- cmd, arg = $1, $2
- if arg =~ @@re_texmfpath then
- # there is already an --path (first switch)
- else
- command = "#{runner} #{arg}"
- end
- else
- command = "#{runner} bin:#{command}"
- end
- if log && ! log.empty? then
- return "#{command} 2>&1 > #{File.expand_path(File.join(path,log))}"
- else
- return command
- end
- end
-
- def set_os_vars
- begin
- ENV['TEXOS'] = ENV['TEXOS'] || platform
- rescue
- ENV['TEXOS'] = 'texmf-linux'
- else
- ENV['TEXOS'] = 'texmf-' + ENV['TEXOS'] unless ENV['TEXOS'] =~ /^texmf\-/
- ensure
- ENV['EXA:TEXOS'] = ENV['TEXOS']
- end
- end
-
- def set_environment(hash)
- set_os_vars
- paths = ENV['PATH'].split(File::PATH_SEPARATOR)
- hash.subset('binpath:').keys.each do |key|
- begin
- paths << File.expand_path(hash[key])
- rescue
- end
- end
- ENV['PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
- hash.subset('path:').keys.each do |path|
- key, value = "EXA:#{path.upcase}", File.expand_path(hash[path])
- ENV[key] = value
- end
- end
-
- def save_environment(hash,path,filename='request.tmf')
- begin
- File.open(File.join(path,filename),'w') do |f|
- set_os_vars
- ['EXA:TEXOS','TEXOS'].each do |key|
- f.puts("#{key} = #{ENV[key]}")
- end
- hash.subset('binpath:').keys.each do |key|
- f.puts("PATH < #{File.expand_path(@interface.get(key))}")
- end
- hash.subset('path:').keys.each do |path|
- f.puts("EXA:#{path.upcase} = #{File.expand_path(@interface.get(path))}")
- end
- end
- rescue
- end
- end
-
-end
diff --git a/scripts/context/ruby/www/dir.rb b/scripts/context/ruby/www/dir.rb
deleted file mode 100644
index 115fd8911..000000000
--- a/scripts/context/ruby/www/dir.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-require 'www/lib'
-
-# dir handling
-
-class WWW
-
- # borrowed code from webrick demo, patched
-
- @@dir_name_width = 25
-
- def handle_dir(dirpath=@variables.get('path'),hidden=[],showdirs=true)
- check_template_file('dir','text-template.htm')
- docroot = @interface.get('path:docroot')
- dirpath = dirpath || ''
- hidden = [] unless hidden
- local_path = dirpath.dup
- title, str = "Index of #{escaped(dirpath)}", ''
- begin
- local_path.gsub!(/[\/\\]+/,'/')
- local_path.gsub!(/\/$/, '')
- if local_path !~ /^(\.|\.\.|\/|[a-zA-Z]\:)$/io then # maybe also /...
- full_path = File.join(docroot,local_path)
- @interface.set('log:dir', full_path)
- begin
- list = Dir::entries(full_path)
- rescue
- str << "unable to parse #{local_path}"
- else
- if list then
- list.collect! do |name|
- if name =~ /^\.+/o then
- nil # no . and ..
- else
- st = (File::stat(File.join(docroot,local_path,name)) rescue nil)
- if st.nil? then
- [name, nil, -1, false]
- elsif st.directory? then
- if showdirs then [name + "/", st.mtime, -1, true] else nil end
- elsif hidden.length > 0 then
- if hidden.include?(name) then nil else [name, st.mtime, st.size, false] end
- else
- [name, st.mtime, st.size, false]
- end
- end
- end
- list.compact!
- n, m, s = @variables.get('n'), @variables.get('m'), @variables.get('s')
- if ! n.empty? then
- idx, d0 = 0, n
- elsif ! m.empty? then
- idx, d0 = 1, m
- elsif ! s.empty? then
- idx, d0 = 2, s
- else
- idx, d0 = 0, 'a'
- end
- d1 = if d0 == 'a' then 'd' else 'a' end
- if d0 == 'a' then
- list.sort! do |a,b| a[idx] <=> b[idx] end
- else
- list.sort! do |a,b| b[idx] <=> a[idx] end
- end
- u = dir_uri(@variables.get('path') || '.')
- str << "
\n
\n"
- str << "name".ljust(49+u.length)
- str << "last modified".ljust(41+u.length)
- str << "size".rjust(31+u.length) << "\n" << "\n"
- # parent path
- if showdirs && ! hidden.include?('..') then
- dname = "parent directory"
- fname = "#{File.dirname(dirpath)}"
- time = File::mtime(File.join(docroot,local_path,"/.."))
- str << dir_entry(fname,dname,time,-1,true)
- str << "\n"
- end
- # directories
- done = false
- list.each do |name, time, size, dir|
- if dir then
- if name.size > @@dir_name_width then
- dname = name.sub(/^(.#{@@dir_name_width-2})(.*)/) do $1 + ".." end
- else
- dname = name
- end
- fname = "#{escaped(dirpath)}/#{escaped(name)}"
- str << dir_entry(fname,dname,time,size,dir)
- done = true
- end
- end
- str << "\n" if done
- # files
- list.each do |name, time, size, dir|
- unless dir then
- if name.size > @@dir_name_width then
- dname = name.sub(/^(.#{@@dir_name_width-2})(.*)/) do $1 + ".." end
- else
- dname = name
- end
- fname = "#{escaped(dirpath)}/#{escaped(name)}"
- str << dir_entry(fname,dname,time,size,dir)
- end
- end
- str << "\n"
- str << '
'
- else
- str << 'no info'
- end
- end
- else
- str << 'no access'
- end
- rescue
- str << "error #{$!}
"
- str << $@.join("\n")
- str << "
"
- end
- message(title,str)
- end
- def dir_uri(f='.')
- u, t, o = @interface.get('dir:uri'), @interface.get('dir:task'), @interface.get('dir:option') # takes precedence, in case we run under cgi control
- if u.empty? then
- u, t, o = @interface.get('process:uri'), '', ''
- elsif ! t.empty? then
- t = "task=#{t}&"
- o = "option=#{o}&"
- end
- if u && ! u.empty? then
- u = u.sub(/\?.*$/,'') # frozen string
- if f =~ /^\.+$/ then
- "#{u}?#{t}#{o}path="
- else
- "#{u}?#{t}#{o}path=#{f}"
- end
- else
- ''
- end
- end
-
- def dir_entry(fname,dname,time,size,dir=false)
- if dir then
- f = fname.sub(/\/+$/,'').sub(/^\/+/,'')
- s = "#{dname}"
- elsif ! @interface.get('dir:uri').empty? then # takes precedence, in case we run under cgi control
- s = "#{dname}"
- else
- s = "#{dname}"
- end
- # s << " " * (30 - dname.size)
- s << " " * (@@dir_name_width + 5 - dname.size)
- s << (time ? time.strftime("%Y/%m/%d %H:%M ") : " " * 22)
- s << (size >= 0 ? size.to_s : "-").rjust(12) << "\n"
- return s
- end
-
-end
diff --git a/scripts/context/ruby/www/exa.rb b/scripts/context/ruby/www/exa.rb
deleted file mode 100644
index 20a40fc7b..000000000
--- a/scripts/context/ruby/www/exa.rb
+++ /dev/null
@@ -1,387 +0,0 @@
-require 'fileutils'
-require 'www/lib'
-require 'www/dir'
-require 'www/common'
-require 'www/admin'
-
-class WWW
-
- include Common
-
- def handle_exadefault
- check_template_file('exalogin','exalogin-template.htm')
- if id = logged_in_session(true) then
- finish_login
- else
- message('Error', 'No default login permitted.')
- end
- end
-
- def handle_exalogin
- check_template_file('exalogin','exalogin-template.htm')
- if id = logged_in_session(false) then
- finish_login
- else
- message('Error', 'No default login permitted.')
- end
- end
-
- def finish_login
- get_gui()
- filename, path, task = @session.get('gui'), @session.checked('path','.'), @session.get('task')
- if ! task.empty? then
- save_session
- handle_exatask
- elsif filename and not filename.empty? then
- save_session
- fullname = filename.gsub(/\.\./,'')
- fullname = File.join(path,filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'), filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'), path, filename) unless FileTest.file?(fullname)
- if FileTest.file?(fullname) then
- send_file(fullname,true)
- else
- message('Interface', 'Invalid interface request, no valid interface file.' )
- end
- else
- message('Interface', 'Invalid interface request, no default interface file.')
- end
- end
-
- def handle_exainterface()
- check_template_file('text','exalogin-template.htm')
- if id = valid_session() then
- filename = @interface.get('process:uri').to_s # kind of dup
- if ! filename.empty? && filename.sub!(/^.*\//,'') then
- path = @session.checked('path', '.')
- fullname = filename.gsub(/\.\./,'')
- fullname = File.join(path,filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'),filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'),path,filename) unless FileTest.file?(fullname)
- if FileTest.file?(fullname) then
- save_session
- send_file(fullname,true)
- else
- get_file(filename)
- filename, path = @session.get('gui'), @session.checked('path','.')
- if filename and not filename.empty? then
- save_session
- fullname = filename.gsub(/\.\./,'')
- fullname = File.join(path,filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'),filename) unless FileTest.file?(fullname)
- fullname = File.join(@interface.get('path:interfaces'),path,filename) unless FileTest.file?(fullname)
- send_file(fullname,true) if FileTest.file?(fullname)
- else
- message('Interface', 'Invalid interface request, no interface file.')
- end
- end
- else
- message('Interface', 'Invalid interface request, no resource file.')
- end
- else
- message('Interface', 'Invalid interface request, no login.')
- end
- end
-
- def handle_exarequest() # todo: check if request is 'command'
- check_template_file('exalogin','exalogin-template.htm')
- if id = client_session() then
- client = true
- @interface.set('log:kind', "remote client request: #{id}")
- elsif id = valid_session() then
- client = false
- @interface.set('log:kind', "remote browser request: #{id}")
- else
- client, id = false, nil
- @interface.set('log:kind', 'unknown kind of request')
- end
- if id then
- dir, tmp = dirname, tmp_path(dirname)
- requestname, replyname = 'request.exa', 'reply.exa'
- requestfile, replyfile = File.join(tmp,requestname), File.join(tmp,replyname)
- lockfile = File.join(dirname,lckname)
- action, filename, command, url, req = '', '', '', '', ''
- extract_sent_files(tmp)
- @variables.each do |key, value|
- case key
- when 'exa:request' then
- req = value.dup
- when 'exa:action' then
- action = value.dup
- # when 'exa:command' then
- # command = value.dup
- # when 'exa:url' then
- # url = value.dup
- when 'exa:filename' then
- filename = value.dup
- when 'exa:threshold' then
- @interface.set('process:threshold', value.dup)
- when /^fakename/o then
- @variables.set(key, File.basename(value))
- when /^filename\-/o then
- @variables.set(key, filename = File.basename(value))
- when /^dataname\-/o then
- @variables.set(key)
- else # remove varname- prefix from value
- @variables.set(key, @variables.get(key).sub(/#{key}\-/,''))
- end
- end
- @variables.check('exa:filename', filename)
- @variables.check('exa:action', action)
- if @variables.empty?('exa:filename') then
- @variables.set('exa:filename', @interface.get('log:attachments').split('|').first || '')
- end
- req.gsub!(//i, '')
- dat = "\n"
- @variables.each do |key, value|
- if ['password','exa:request'].include?(key) then
- # skip
- elsif ! value || value.empty? then
- dat << "\n"
- else # todo: escape 'm
- dat << "#{value}\n"
- end
- end
- dat << "\n"
- if req.empty? then
- req << "\n"
- req << "\n"
- req << "\n"
- req << "'#{action}\n" unless action.empty?
- # req << "'#{command}\n" unless command.empty?
- # req << "'#{url}\n" unless url.empty?
- req << "\n"
- req << "constructed request\n"
- req << dat
- req << "\n"
- else
- # better use rexml but slower
- if req =~ /]*>.*?\s*\s*(.*?)\s*<\/exa:threshold>\s*.*?<\/exa:request>/moi then
- threshold = $1
- unless threshold.empty? then
- @interface.set('process:threshold', threshold)
- @session.set('threshold', threshold)
- end
- end
- req.sub!(/(]*>.*?)\s*\s*\-\-action\=(.*?)\s*<\/exa:option>\s*(.*?<\/exa:request>)/moi) do
- pre, act, pos = $1, $2, $3
- action = act.sub(/\.exa$/,'') if action.empty?
- str = "#{pre}#{action}#{pos}"
- str.sub(/\s*.*?<\/exa:command>\s*/moi ,'')
- end
- req.sub!(/(]*>.*?)\s*(.*?)\s*<\/exa:action>(.*?<\/exa:request>)/moi) do
- pre, act, pos = $1, $2, $3
- action = act.sub(/\.exa$/,'') if action.empty?
- str = "#{pre}#{action}#{pos}"
- str.sub(/\s*.*?<\/exa:command>\s*/moi ,'')
- end
- unless req =~ /(.*?)<\/exa:data>/moi then
- req.sub!(/(<\/exa:request>)/) do dat + $1 end
- end
- end
- req.sub!(/.*?<\/exa:filename>/moi, '')
- unless @variables.empty?('exa:filename') then
- req.sub!(/(<\/exa:application>)/moi) do
- "#{@variables.get('exa:filename')}<\/exa:filename>" + $1
- end
- end
- @variables.set('exa:action', action)
- @interface.set("log:#{requestname}", req)
- begin
- File.open(requestfile,'w') do |f|
- f << req
- end
- rescue
- message('Error', 'There is a problem in handling this request (working path access).')
- return
- end
- File.delete(replyfile) rescue false
- @interface.set('log:action',action)
- get_command(action)
- logdata = ''
- begin
- command = @session.get('command')
- @interface.set('log:command',if command.empty? then '[no command]' else command end)
- if ! command.empty? then
- @session.set('starttime', Time.now.to_i.to_s) # can be variables and in save list
- if @interface.true?('process:background') then
- # background
- @session.set('status', 'running: background')
- @session.set('maxtime', @interface.get('process:timeout'))
- @session.set('threshold', @interface.get('process:threshold'))
- save_session
- timeout(@@watch_delay) do
- save_environment(@interface,tmp)
- begin
- starttime = File.mtime(@session_file)
- # crap
- loop do
- sleep(1)
- if starttime != File.mtime(@session_file) then
- break unless FileTest.file?(lockfile)
- end
- end
- rescue TimeoutError
- if client then
- send_reply()
- else
- message('Status', 'Processing your request takes a while',true,5,'exastatus')
- end
- return
- rescue
- end
- end
- if client then send_reply() else send_result() end
- else
- # foreground
- status = 'running: foreground'
- @session.set('status', status)
- @session.set('maxtime', @interface.get('process:timeout'))
- @session.set('threshold', @interface.get('process:threshold'))
- save_session
- timeout(@interface.get('process:timeout').to_i) do
- begin
- status = 'running: foreground'
- set_environment(@interface)
- save_environment(@interface,tmp)
- command = command_string(tmp,command)
- logdata = `#{command}`
- rescue TimeoutError
- status = 'running: timeout'
- logdata = "timeout: #{@interface.get('process:timeout')} seconds"
- rescue
- status = 'running: aborted'
- logdata = 'fatal runtime error'
- else
- @session.set('endtime', Time.now.to_i.to_s)
- status = 'running: finished'
- end
- end
- @session.set('status', status)
- save_session
- case @session.get('status')
- when 'running: finished' then
- if client then send_reply(logdata) else send_result(logdata) end
- when 'running: timeout' then
- message('Error', 'There is a problem in handling this request (timeout).')
- when 'running: aborted' then
- message('Error', 'There is a problem in handling this request (aborted).')
- else
- message('Error', 'There is a problem in handling this request (unknown).')
- end
- end
- else
- message('Error', 'There is a problem in handling this request (no runner).')
- end
- rescue
- message('Error', 'There is a problem in handling this request (no run).' + $!)
- end
- else
- message('Error', 'Invalid session.')
- end
- end
-
- def handle_exacommand() # shares code with exarequest
- check_template_file('exalogin','exalogin-template.htm')
- if id = client_session() then
- client = true
- @interface.set('log:kind', "remote client request: #{id}")
- elsif id = valid_session() then
- client = false
- @interface.set('log:kind', "remote browser request: #{id}")
- else
- client, id = false, nil
- @interface.set('log:kind', 'unknown kind of request')
- end
- if id then
- dir, tmp = dirname, tmp_path(dirname)
- requestname, replyname = 'request.exa', 'reply.exa'
- requestfile, replyfile = File.join(tmp,requestname), File.join(tmp,replyname)
- req, command, url = '', '', ''
- @variables.each do |key, value|
- case key
- when 'exa:request' then
- req = value.dup
- when 'exa:command' then
- command = value.dup
- when 'exa:threshold' then
- @interface.set('process:threshold', value.dup)
- when 'exa:url' then
- url = value.dup
- end
- end
- unless req.empty? then
- # better use rexml but slower / reuse these : command = filter_from_request('exa:command')
- if req =~ /]*>.*?\s*\s*(.*?)\s*<\/exa:command>\s*.*?<\/exa:request>/moi then
- command = $1
- end
- if req =~ /]*>.*?\s*\s*(.*?)\s*<\/exa:url>\s*.*?<\/exa:request>/moi then
- url = $1
- end
- if req =~ /]*>.*?\s*\s*(.*?)\s*<\/exa:threshold>\s*.*?<\/exa:request>/moi then
- threshold = $1
- unless threshold.empty? then
- @interface.set('process:threshold', threshold)
- @session.set('threshold', threshold)
- end
- end
- end
- @variables.check('exa:command', command)
- @variables.check('exa:url', url)
- File.delete(replyfile) rescue false
- case @variables.get('exa:command')
- when 'fetch' then
- if @variables.empty?('exa:url') then
- message('Error', "Problems with fetching, no file given")
- else
- # the action starts here
- filename = @variables.get('exa:url').to_s # kind of dup
- unless filename.empty? then
- get_path(filename) # also registers filename as url
- path = @session.checked('path', '')
- fullname = filename.gsub(/\.\./,'')
- fullname = File.join(path,fullname) unless path.empty?
- if FileTest.file?(fullname) then
- if client then
- send_url(fullname)
- else
- send_file(fullname,true)
- end
- @session.set('threshold', @interface.get('process:threshold'))
- @session.set('url',filename)
- save_session
- else
- message('Error', "Problems with fetching, unknown file #{fullname}.")
- # message('Error', "Problems with fetching, unknown file #{filename}.")
- end
- else
- message('Error', "Problems with fetching, invalid file #{filename}.")
- end
- # and ends here
- end
- else
- message('Error', "Invalid command #{command}.")
- end
- else
- message('Error', 'Invalid session.')
- end
- end
-
- def handle_exastatus
- get_cfg() # weird, needed for apache, but not for wwwserver
- if request_variable('id').empty? then
- if id = valid_session() then
- send_result()
- else
- message('Error', 'Invalid session.')
- end
- else
- if id = valid_session() then
- send_reply()
- else
- send_reply('invalid session')
- end
- end
- end
-
-end
diff --git a/scripts/context/ruby/www/lib.rb b/scripts/context/ruby/www/lib.rb
deleted file mode 100644
index b9a44c9f6..000000000
--- a/scripts/context/ruby/www/lib.rb
+++ /dev/null
@@ -1,1405 +0,0 @@
-#!/usr/bin/env ruby
-
-# This is just a simple environment for remote processing of context
-# files. It's not a framework, nor an example of how that should be done.
-# Nowadays there are environments like Rails or Nitro. Maybe some day I'll
-# give one of them a try.
-
-#
-#
-#
-
-# we make limited use of cgi methods because we also need to handle webrick
-
-# %var% as well as $(var) are supported
-
-# paths need to be expanded before they enter apache, since .. is not
-# handled by default
-
-require 'base/variables'
-
-require 'ftools'
-require 'fileutils'
-require 'tempfile'
-require 'timeout'
-require 'md5'
-require 'digest/md5'
-require 'cgi' # we also need escaping for webrick (could move it here)
-
-# beware, namespaces have to match !
-
-module XML
-
- def XML::element(tag,attributes=nil)
- if attributes.class == Hash then
- if block_given? then
- XML::element(tag,XML::attributes(attributes)) do yield end
- else
- XML::element(tag,XML::attributes(attributes))
- end
- else
- if block_given? then
- "<#{tag}#{if attributes && ! attributes.empty? then ' ' + attributes end}>#{yield}#{tag}>"
- else
- "<#{tag}#{if attributes && ! attributes.empty? then ' ' + attributes end}/>"
- end
- end
- end
-
- def XML::attributes(hash)
- str = ''
- hash.each do |k,v|
- str << ' ' unless str.empty?
- if v =~ /\'/ then
- str << "#{k}=\"#{v}\""
- else
- str << "#{k}=\'#{v}\'"
- end
- end
- return str
- end
-
- def XML::create(version='1.0')
- "#{yield || ''}"
- end
-
- def XML::line
- "\n"
- end
-
-end
-
-# str =
- # XML::create do
- # XML::element('test') do
- # XML::element('test') do
- # 'text a'
- # end +
- # XML::element('test',XML::attributes({'a'=>'b'})) do
- # XML::element('nested',XML::attributes({'a'=>'b'})) do
- # 'text b-1'
- # end +
- # XML::element('nested',XML::attributes({'a'=>'b'})) do
- # 'text b-2'
- # end
- # end +
- # XML::element('nested',{'a'=>'b'}) do
- # 'text c'
- # end
- # end
- # end
-
-class ExtendedHash
-
- DEFAULT = 'default'
-
- @@re_default = /^(default|)$/i
-
- def default?(key)
- self[key] =~ @@re_default rescue true # unset, empty or 'default'
- end
-
- def default(key)
- self[key] = DEFAULT
- end
-
- def match?(key,value)
- value == '*' || value == self[key]
- end
-
-
-end
-
-class WWW
-
- @@session_prefix = ''
- @@data_file = 'example.cfg'
- @@session_max_age = 60*60
- @@watch_delay = 30
- @@send_threshold = 2*1024*1024
- @@admin_refresh = 10
- @@namespace = "http://www.pragma-ade.com/schemas/example.rng"
-
- @@re_bar = /\s*\|\s*/
- @@re_lst = /\s*\,\s*/
- @@re_var_a = /\%(.*?)\%/
- @@re_var_b = /\$\((.*?)\)/
-
- attr_reader :variables
- attr_writer :variables
-
- @@paths = [
- 'configurations',
- 'data',
- 'distributions',
- 'documents',
- 'interfaces',
- 'logs',
- 'resources',
- 'runners',
- 'scripts',
- 'templates',
- 'work']
-
- @@re_true = /^\s*(YES|ON|TRUE|1)\s*$/io
- @@re_false = /^\s*(NO|OFF|FALSE|0)\s*$/io
-
- def initialize(webrick_daemon=nil,webrick_request=nil,webrick_response=nil)
- @session_id, @session_file = '', ''
- @cgi, @cgi_cookie = nil, nil
- @webrick_daemon, @webrick_request, @webrick_response = webrick_daemon, webrick_request, webrick_response
-
- @interface = ExtendedHash.new
- @variables = ExtendedHash.new
- @session = ExtendedHash.new
-
- @checked = false
-
- analyze_request()
- update_interface()
-
- @interface.set('template:message' , 'exalogin-template.htm')
- @interface.set('template:status' , 'exalogin-template.htm')
- @interface.set('template:login' , 'exalogin.htm')
- @interface.set('process:timeout' , @@session_max_age)
- @interface.set('process:threshold' , @@send_threshold)
- @interface.set('process:background', 'yes') # this demands a watchdog being active
- @interface.set('process:indirect' , 'no') # indirect download, no direct feed
- @interface.set('process:autologin' , 'yes') # provide default interface when applicable
- @interface.set('process:exaurl' , '') # this one will be used as replacement in templates
- @interface.set('trace:run' , 'no')
- @interface.set('trace:errors' , 'no')
- @interface.set('process:os' , platform)
- @interface.set('process:texos' , 'texmf-' + platform)
-
- @interface.set('trace:run' , 'yes') if (ENV['EXA_TRACE_RUN'] || '') =~ @@re_true
- @interface.set('trace:errors' , 'yes') if (ENV['EXA_TRACE_ERRORS'] || '') =~ @@re_true
-
- yield self if block_given?
- end
-
- def set(key,value)
- @interface.set(key,value)
- end
- def get(key)
- @interface.get(key,value)
- end
-
- def platform
- case RUBY_PLATFORM
- when /(mswin|bccwin|mingw|cygwin)/i then 'mswin'
- when /(linux)/i then 'linux'
- when /(netbsd|unix)/i then 'unix'
- when /(darwin|rhapsody|nextstep)/i then 'macosx'
- else 'unix'
- end
- end
-
- def check_cgi
- # when mod_ruby is used, we need to close
- # the cgi session explicitly
- unless @webrick_request then
- unless @cgi then
- @cgi = CGI.new('html4')
- at_exit do
- begin
- @cgi.close
- rescue
- end
- end
- end
- end
- end
-
- def request_variable(key)
- begin
- if @webrick_request then
- [@webrick_request.query[key]].flatten.first.to_s
- else
- check_cgi
- [@cgi.params[key]].flatten.first.to_s
- end
- rescue
- ''
- end
- end
-
- def request_cookie(key)
- begin
- if @cgi then
- if str = @cgi.cookies[key] then
- return str.first || ''
- end
- elsif @webrick_request then
- @webrick_request.cookies.flatten.each do |cookie|
- if cookie.name == key then
- return cookie.value unless cookie.value.empty?
- end
- end
- end
- rescue
- end
- return ''
- end
-
- def analyze_request
- if @webrick_request then
- @interface.set('path:docroot', @webrick_daemon.config[:DocumentRoot] || './documents')
- @interface.set('process:uri', @webrick_request.request_uri.to_s)
- # @interface.set('process.url', [@webrick_request.host,@webrick_request.request_port].join(':'))
- @cgi = nil
- @webrick_request.query.each do |key, value|
- # todo: filename
- @variables.set(key, [value].flatten.first)
- end
- else
- @interface.set('path:docroot', ENV['DOCUMENT_ROOT'] || './documents')
- @interface.set('process:uri', ENV['REQUEST_URI'] || '')
- # @interface.set('process.url', [ENV['SERVER_NAME'],ENV['SERVER:PORT']].join(':'))
- ARGV[0] = '' # get rid of terminal mode
- check_cgi
- # quite fragile, due to changes between 1.6 and 1.8
- @cgi.params.keys.each do |p|
- if @cgi[p].respond_to?(:original_filename) then
- @interface.set('log:method','post')
- if @cgi[p].original_filename && ! @cgi[p].original_filename.empty? then
- @variables.set(p, File.basename(@cgi[p].original_filename))
- else
- case @cgi.params[p].class
- when StringIO.class then @variables.set(p, @cgi[p].read)
- when Array.class then @variables.set(p, @cgi[p].first.to_s)
- when String.class then @variables.set(p, @cgi[p])
- when Tempfile.class then @variables.set(p, '[data blob]')
- end
- end
- else
- @interface.set('log:method','get') unless @interface.get('log:method') == 'post'
- @variables.set(p, [@cgi.params[p]].flatten.first.to_s)
- end
- end
- end
- @interface.set('path:root', File.dirname(@interface.get('path:docroot')))
- end
-
- # name in calling script takes precedence
- # one can set template:whatever as well
- # todo: in config
-
- def check_template_file(tag='',filename='exalogin-template.htm')
- @interface.set('file:template', filename) if @interface.get('file:template').empty?
- @interface.set('tag:template', tag)
- @interface.set('file:template', @interface.get('tag:template')) unless @interface.get('tag:template').empty?
- end
-
- def update_interface()
- root = @interface.get('path:docroot')
- @interface.set('path:docroot', File.expand_path("#{root}"))
- @@paths.each do |path|
- @interface.set("path:#{path}", File.expand_path("#{root}/../#{path}"))
- end
- @interface.set('file:template', @interface.get('tag:template')) unless @interface.get('tag:template').empty?
- end
-
- def indirect?(result)
- size = FileTest.size?(result) || 0
- @interface.true?('trace:errors') || @interface.true?('trace:run') || @interface.true?('process:indirect') ||
- ((! @interface.empty?('process:threshold')) && (size > @interface.get('process:threshold').to_i)) ||
- ((! @session.empty?('threshold')) && (size > @session.get('threshold').to_i))
- end
-
-end
-
-# files
-
-class WWW
-
- def sesname
- File.basename(@session_file)
- end
- def dirname
- File.basename(@session_file.sub(/ses$/,'dir'))
- end
- def lckname
- File.basename(@session_file.sub(/ses$/,'lck'))
- end
-
- def work_root(expand=true)
- p = if expand then File.expand_path(@interface.get('path:work')) else @interface.get('path:work') end
- if @interface.true?('process:background') then
- File.join(@interface.get('path:work'),'watch')
- else
- File.join(@interface.get('path:work'),'direct')
- end
- end
-
- def work_roots(expand=true)
- p = if expand then File.expand_path(@interface.get('path:work')) else @interface.get('path:work') end
- [File.join(@interface.get('path:work'),'watch'),File.join(@interface.get('path:work'),'direct')]
- end
-
- def cache_root(expand=true)
- p = if expand then File.expand_path(@interface.get('path:work')) else @interface.get('path:work') end
- File.join(@interface.get('path:work'),'cache')
- end
-
- def cleanup_path(dir)
- FileUtils::rm_r(pth) rescue false
- end
-
- def tmp_path(dir)
- @interface.set('path:templates', File.expand_path(@interface.get('path:templates'))) # to be sure; here ? ? ?
- pth = File.join(work_root,dir)
- File.makedirs(pth) rescue false
- pth
- end
-
- def locked?(lck)
- FileTest.file?(lck)
- end
-
-end
-
-# sessions
-
-class WWW
-
- @@session_tags = ['id','domain','project','username','password','gui','path','process','command','filename','action','status', 'starttime','endtime','runtime','task','option','threshold','url'].sort
- @@session_keep = ['id','domain','project','username','password','process'].sort
- @@session_reset = @@session_tags - @@session_keep
-
- def new_session()
- if @variables.empty?('exa:session') then
- @session_id = new_session_id
- else
- @session_id = @variables.get('exa:session')
- end
- if @session_id == 'default' then # ???
- @session_id = new_session_id
- end
- @session_file = File.join(work_root,"#{@@session_prefix}#{@session_id}.ses")
- register_session
- return @session_id
- end
-
- def reset_session(all=false)
- (if all then @@session_tags else @@session_reset end).each do |k|
- @session.set(k)
- end
- end
-
- def valid_session
- @session_id = request_variable('id')
- if @session_id.empty? then
- begin
- if @cgi then
- if @session_id = @cgi.cookies['session_id'] then
- @session_id = @session_id.first || ''
- else
- @session_id = ''
- end
- elsif @webrick_request then
- @webrick_request.cookies.flatten.each do |cookie|
- if cookie.name == 'session_id' then
- unless cookie.value.empty? then
- @session_id = cookie.value
- # break
- end
- end
- end
- else
- @session_id = ''
- end
- rescue
- @interface.set('log:session',"[error in request #{$!}]")
- return false
- end
- end
- if @session_id.empty? then
- @interface.set('log:session','[no id, check work dir permissions]')
- return false
- else
- @interface.set('log:session',@session_id)
- load_session
- if ! @session.empty?('domain') && ! @session.empty?('project') && ! @session.empty?('username') then
- register_session
- return @session_id
- else
- return false
- end
- end
- end
-
- def touch_session(id=nil)
- begin
- t = Time.now
- File.utime(t,t,File.join(work_root,"#{@@session_prefix}#{id || @session_id}.ses")) rescue false
- rescue
- false
- end
- end
-
- def forced_session
- @session_id = new_session
- if @session_id.empty? then
- @interface.set('log:session','[no id, check work dir permissions]')
- return false
- else
- return check_session
- end
- end
-
- def client_session
- request, done = @variables.get('exa:request'), false
- request.sub!(/(^.*]*>.*?)\s*\s*(.*)\s*<\/exa:client>\s*(.*?<\/exa:request>.*$)/mio) do
- pre, client, post = $1, $2, $3
- client.scan(/(.*?)<\/exa:\1>/mio) do
- @variables.set($1, $2)
- end
- done = true
- pre + post
- end
- if done then
- return forced_session
- else
- return nil
- end
- end
-
- def register_session
- if @cgi then
- @cgi_cookie = CGI::Cookie::new(
- 'name' => 'session_id',
- 'value' => @session_id,
- 'expires' => Time.now + @interface.get('process:timeout').to_i
- )
- # @cgi_cookie = CGI::Cookie::new('session_id',@session_id)
- elsif @webrick_response then
- if cookie = WEBrick::Cookie.new('session_id', @session_id) then
- cookie.expires = Time.now + @interface.get('process:timeout').to_i
- cookie.max_age = @interface.get('process:timeout').to_i
- cookie.comment = 'exa identifier'
- @webrick_response.cookies.clear
- @webrick_response.cookies << cookie
- end
- end
- end
-
- def new_session_id # taken from cgi
- md5 = Digest::MD5::new
- now = Time::now
- md5.update(now.to_s)
- md5.update(String(now.usec))
- md5.update(String(rand(0)))
- md5.update(String($$))
- md5.update('foobar')
- @new_session = true
- md5.hexdigest[0,32] # was 16
- end
-
- @@hide_passwords = true
- HIDDEN = 'hidden'
-
- def same_passwords(password) # password in cfg file
- if @@hide_passwords && (@session.get('password') == HIDDEN) && (@session_id == @session.get('id')) then
- # this condition is only true when a same session id is found and
- # the password is checked once and set to HIDDEN
- same = true
- elsif password =~ /^MD5:/ then
- # so, one cannot send a known encrypted password since it will be
- # encrypted twice then
- same = (password == "MD5:" + MD5.new(@session.get('password')).hexdigest.upcase)
- else
- if (@session.default?('domain') && @session.default?('project') && @session.default?('username')) then
- @session.default('password') # is this safe enough?
- end
- same = (password == @session.get('password'))
- end
- if @@hide_passwords && same then
- @session.set('password', HIDDEN)
- save_session # next time this session is ok anyway
- end
- return same
- end
-
- @@session_line = /^\s*(?![\#\%])(.*?)\s*\=\s*(.*?)\s*$/o
- @@session_begin = 'begin exa session'
- @@session_end = 'end exa session'
-
- def loaded_session_data(filename)
- begin
- if data = IO.readlines(filename) then
- return data if (data.first =~ /^[\#\%]\s*#{@@session_begin}/o) && (data.last =~ /^[\#\%]\s*#{@@session_end}/o)
- end
- rescue
- end
- return nil
- end
-
- def load_session()
- begin
- @session_file = File.join(work_root,"#{@@session_prefix}#{@session_id}.ses")
- if data = loaded_session_data(@session_file) then
- data.each do |line|
- if line =~ @@session_line then
- @session.set($1, $2 || '')
- end
- end
- else
- return false
- end
- rescue
- return false
- else
- return true
- end
- end
-
- def load_session_file(filename)
- begin
- if data = loaded_session_data(filename) then
- session = Hash.new
- data.each do |line|
- if line =~ @@session_line then
- session[$1] = $2 || ''
- end
- end
- else
- Hash.new
- end
- rescue
- Hash.new
- else
- session
- end
- end
-
- def save_session
- begin
- unless @session_id.empty? then
- @session_file = File.join(work_root,"#{@@session_prefix}#{@session_id}.ses")
- @session_file = File.join(work_root,"#{@@session_prefix}#{@session_id}.ses")
- File.open(@session_file,'w') do |f|
- f << "\# #{@@session_begin}\n"
- @@session_tags.each do |tag|
- if @session && @session.key?(tag) then
- if ! @session.get(tag).empty? then # no one liner, fails
- f << "#{tag}=#{@session.get(tag)}\n"
- end
- elsif @variables.key?(tag) && ! @variables.empty?(key) then
- f << "#{tag}=#{@variables.get(tag)}\n"
- end
- end
- @session.subset("ENV").keys.each do |tag|
- f << "#{tag}=#{@session.get(tag)}\n"
- end
- f << "\# #{@@session_end}\n"
- end
- end
- rescue
- return false
- else
- return true
- end
- end
-
- def logged_in_session(force_default=false)
- if force_default || (@variables.default?('domain') && @variables.default?('project') && @variables.default?('username')) then
- id = default_session
- else
- id = check_session
- end
- end
-
- def default_session
- if @interface.true?('process:autologin') then
- @variables.default('domain')
- @variables.default('project')
- @variables.default('username')
- @variables.default('password')
- check_session
- else
- @session_id = nil
- end
- end
-
- def check_session
- @session.set('domain', @variables.get('domain').downcase)
- @session.set('project', @variables.get('project').downcase)
- @session.set('username', @variables.get('username').downcase)
- @session.set('password', @variables.get('password').downcase)
- new_session
- @session.set('id', @session_id)
- save_session
- return @session_id
- end
-
- def delete_session(id=nil)
- File.delete(work_root,"#{@@session_prefix}#{id || @session_id}.ses") rescue false
- end
-
- def cleanup_sessions(max_age=nil)
- begin
- now, age = Time.now, (max_age||@interface.get('process:timeout')).to_i
- Dir.glob("{#{work_root},#{cache_root}/#{@@session_prefix}*").each do |s|
- begin
- if (now - File.mtime(s)) > age then
- if FileTest.directory?(s) then
- FileUtils::rm_r(s)
- else
- File.delete(s)
- end
- end
- rescue
- # maybe purged in the meantime
- end
- end
- rescue
- # maybe another process is busy
- end
- end
-
-end
-
-# templates
-
-class WWW
-
- def filled_template(title,text,showtime=false,refresh=0,refreshurl=nil)
- template = @interface.get("template:#{@interface.get('tag:template')}")
- template = @interface.get("template:status") if template.empty?
- fullname = File.join(@interface.get('path:templates'),template)
- @interface.set('log:templatename',template)
- @interface.set('log:templatefile',fullname)
- append_status(text)
- htmreply = ''
- if FileTest.file?(fullname) then
- begin
- htmreply = IO.read(fullname)
- rescue
- htmreply = ''
- end
- end
- if refresh>0 then
- if refreshurl then
- metadata = ""
- else
- metadata = ""
- end
- else
- metadata = ''
- end
- if ! htmreply || htmreply.empty? then
- # in head:
- htmreply = <<-EOD
-
- #{metadata}
-
- #{title}
-
-
-
#{title}
-
#{Time.now}
- #{text}
-
-
- EOD
- else
- if showtime then
- exa_template = "
#{title}
\n
#{Time.now}
\n#{text}\n"
- else
- exa_template = "
#{title}
#{text}\n"
- end
- htmreply = replace_template_placeholder(htmreply,exa_template,metadata)
- end
- htmreply
- end
-
- def message(title,str='',showtime=false,refresh=0,refreshurl=nil)
- if @cgi then
- @cgi.out("cookie"=>[@cgi_cookie]) do
- filled_template(title,str,showtime,refresh,refreshurl)
- end
- elsif @webrick_response then
- @webrick_response['content-type'] = 'text/html'
- @webrick_response.body = filled_template(title,str,showtime,refresh,refreshurl)
- else
- filled_template(title,str,showtime,refresh,refreshurl)
- end
- end
-
- def plaintext(str)
- if @cgi then
- @cgi.out('cookie'=>[@cgi_cookie],'content-type'=>'text/plain') do
- str
- end
- elsif @webrick_response then
- @webrick_response['content-type'] = 'text/plain'
- @webrick_response.body = str
- else
- str
- end
- end
-
- def exareply(status='',url='',size='',comment='')
- exaurl = @interface.get('process:exaurl')
- str = "\n\n"
- str << "\n"
- str << " #{@session_id}\n" unless @session_id.empty?
- str << " #{status}\n" unless (status || '').empty?
- str << " #{exaurl}/#{url}\n" unless (url || '').empty?
- str << " #{size}\n" unless (size || '').empty?
- str << " #{comment}\n" unless (comment|| '').empty?
- str << "\n"
- return str
- end
-
- def append_status(str='')
- if @interface.true?('trace:errors') then
- if $! && $@ then
- str << "
'
- @interface.subset('path:').each do |k,v|
- if FileTest.directory?(v) then
- if FileTest.writable?(v) then
- str << "#{v} exists and is writable\n"
- else
- str << "#{v} is not writable\n"
- end
- else
- str << "#{v} does not exist\n"
- end
- end
- str << '
'
- end
- str
- end
-
- def simpleurl(url)
- if url then url.sub(/(:80|:443)$/,'') else '' end
- end
-
- def replace_exa_placeholders(data)
- data.gsub(/([\"\'])\@exa\_([a-zA-Z0-9\-\_]+)\1/) do
- quot, key, value = $1, $2, ''
- begin
- value = @variables.get(key)
- rescue
- value = ''
- end
- quot + value + quot
- end
- end
-
- def replace_url_placeholder(data)
- data.gsub!(/(http:\/\/|\/+)*\@exa\_main\_url/, @interface.get('process:exaurl'))
- replace_exa_placeholders(data)
- end
-
- def replace_template_placeholder(data,template='',metadata='')
- data.gsub!(/(http:\/\/|\/+)*\@exa\_main\_url/, @interface.get('process:exaurl'))
- data.gsub!(/\@exa\_template/, template)
- data.gsub!(/\@exa\_metadata/, metadata)
- replace_exa_placeholders(data)
- end
-
- def escaped(str)
- str
- end
-
-end
-
-# send files
-
-class WWW
-
- def send_file(filename,parse=false) # this can take a lot of memory, look for alternative (fastcgi ?)
- begin
- if filename =~ /\.pdf$/ then
- mimetype, parse = 'application/pdf', false
- elsif filename =~ /\.(html|htm)$/ then
- mimetype, parse = 'text/html', true
- else
- mimetype, parse = 'text/plain', false
- end
- if FileTest.file?(filename) then
- if @webrick_response then
- begin
- @webrick_response['content-type'] = mimetype
- @webrick_response['content-length'] = FileTest.size?(filename)
- if parse then
- File.open(filename, 'rb') do |f|
- @webrick_response.body = replace_url_placeholder(f.read)
- end
- else
- @webrick_response.body = File.open(filename, 'rb')
- end
- rescue
- else
- return
- end
- elsif @cgi then
- begin
- # the following works ok, but stores the whole file in memory (see @cgi.out)
- #
- # File.open(filename, 'rb') do |f|
- # @cgi.out('cookie'=>[@cgi_cookie],'connection'=>'close', 'length'=>File.size(filename), 'type'=>mimetype) do
- # if parse then replace_url_placeholder(f.read) else f.read end
- # end
- # end
- if parse then
- File.open(filename, 'rb') do |f|
- @cgi.out('cookie'=>[@cgi_cookie],'connection'=>'close', 'length'=>File.size(filename), 'type'=>mimetype) do
- replace_url_placeholder(f.read)
- end
- end
- else
- @cgi.print(@cgi.header('cookie'=>[@cgi_cookie],'connection'=>'close', 'length'=>File.size(filename), 'type'=>mimetype))
- File.open(filename, 'rb') do |f|
- while str = f.gets do
- @cgi.print(str)
- end
- end
- end
- rescue
- else
- return
- end
- end
- end
- rescue
- end
- message('Error', "There is a problem with sending file #{File.basename(filename)}.")
- end
-
- def send_htmlfile(filename,parse=false)
- send_file(filename,parse)
- end
- def send_pdffile(filename) # this can take a lot of memory, look for alternative (fastcgi ?)
- send_file(filename,false)
- end
-
-end
-
-# tracing
-
-class WWW
-
- def show_vars(a=@variables,title='')
- if a && a.length > 0 then
- if title.empty? then
- str = ''
- else
- str = "#{title}"
- end
- str << "
\n"
- a.keys.sort.each do |k|
- if k && a[k] && ! a[k].empty? then
- if k == 'password' then
- val = if a[k] == 'default' then 'default' else '******' end
- else
- # str << "#{k} => #{a[k].sub(/^\s+/moi,'').sub(/\s+$/moi,'')}\n"
- val = a[k].to_s.strip
- val.gsub!("&","&")
- val.gsub!("<","<")
- val.gsub!(">",">")
- val.gsub!("\n","\n ")
- end
- str << "#{k} => #{val}\n"
- end
- end
- str << "
\n"
- return str
- else
- return ''
- end
- end
-
- def status_data
- show_vars(@session , 'Session' ) +
- show_vars(@variables, 'Variables' ) +
- show_vars(@interface, 'Interface' ) +
- show_vars(ENV , 'Environment')
- end
-
- def report_status
- check_template_file('status')
- message('Status',status_data)
- end
-
-end
-
-# attachments
-
-class WWW
-
- def extract_sent_files(dir)
- files = Array.new
- if @cgi then
- @cgi.params.keys.each do |tag|
- begin
- if filename = @cgi[tag].original_filename then
- files << extract_file_content(dir,filename,@cgi[tag]) unless filename.empty?
- end
- rescue
- end
- end
- elsif @webrick_request then
- @webrick_request.query.keys.each do |tag|
- begin
- if filename = @webrick_request.query[tag].filename then
- files << extract_file_content(dir,filename,@webrick_request.query[tag]) unless filename.empty?
- end
- rescue
- end
- end
- end
- @interface.set('log:attachments', files.compact.uniq.join('|'))
- end
-
- def extract_file_content(dir,filename,data)
- filename = File.join(dir,File.basename(filename))
- begin
- @interface.set('log:attachclass', data.class.inspect)
- if data.class == Tempfile then
- begin
- File.copy(data.path,filename)
- rescue
- begin
- File.open(filename,'wb') do |f|
- File.open(data.path,'rb') do |g|
- while str = g.gets do
- f.write(str)
- end
- end
- end
- rescue
- @interface.set('log:attachstate', "saving tempfile #{filename} failed (#{$!})")
- else
- @interface.set('log:attachstate', "tempfile #{filename} has been saved")
- end
- else
- @interface.set('log:attachstate', "#{data.path} copied to #{filename}")
- end
- elsif data.class == String then
- begin
- File.open(filename,'wb') do |f|
- f.write(data)
- end
- rescue
- @interface.set('log:attachstate', "saving string #{filename} failed (#{$!})")
- else
- @interface.set('log:attachstate', "string #{filename} has been saved")
- end
- elsif data.class == StringIO then
- begin
- File.open(filename,'wb') do |f|
- f.write(data.read)
- end
- rescue
- @interface.set('log:attachstate', "saving stringio #{filename} failed (#{$!})")
- else
- @interface.set('log:attachstate', "stringio #{filename} has been saved")
- end
- else
- @interface.set('log:attachstate', "unknown attachment class #{data.class.to_s}")
- end
- rescue
- begin File.delete(filename) ; rescue ; end
- else
- begin File.delete(filename) if FileTest.size(filename) == 0 ; rescue ; end
- end
- return File.basename(filename)
- end
-
-end
-
-# configuration
-
-class WWW
-
- def interface_base_name(str)
- str.sub(/\.(pdf|htm|html)$/, '')
- end
-
- def located_interface_file(filename)
- ['configurations', 'runners', 'scripts'].each do |tag|
- datafile = File.join(@interface.get("path:#{tag}"),filename)
- if FileTest.file?(datafile+'.encrypted') then
- return datafile + '.encrypted'
- elsif FileTest.file?(datafile) then
- return datafile
- end
- end
- return nil
- end
-
- def load_interface_file(filename=@@data_file)
- reset_session() # no save yet
- if datafile = located_interface_file(filename) then
- nestedfiles = Array.new
- begin
- data = IO.read(datafile) || ''
- unless data.empty? then
- loop do # we need to load them recursively
- done = false
- data.gsub!(/^include\s*:\s*(.*?)\s*$/) do
- includedname, done = $1, true
- if nestedname = located_interface_file(includedname) then
- begin
- str = ("\n" + IO.read(nestedname) + "\n") || ''
- rescue
- nestedfiles << File.basename('-'+includedname)
- ''
- else
- nestedfiles << File.basename('+'+includedname)
- str
- end
- else
- nestedfiles << File.basename('-'+includedname)
- ''
- end
- end
- break unless done
- end
- end
- @interface.set('log:configurationfile', datafile + ' [' + nestedfiles.join(' ') + ']')
- return data
- rescue
- end
- end
- @interface.set('log:configurationfile', filename + ' [not loaded]')
- return nil
- end
-
- def fetch_session_interface_variables(data)
- data.scan(/^variable\s*:\s*(.*?)\s*\=\s*(.*?)\s*$/) do
- @interface.set($1, $2)
- end
- return true
- end
-
- def fetch_session_project_list(data)
- projectlist, permitted = Array.new, false
- data.scan(/^user\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*\,\s*(.*?)\s*$/) do
- domain, username, password, projects = $1, $2, $3, $4
- if @session.match?('domain',domain) && @session.match?('username',username) then
- if same_passwords(password) then
- projectlist, permitted = @interface.resolved(projects).split(@@re_bar), true
- break
- end
- end
- end
- if permitted then
- @interface.set('log:projectlist', '['+projectlist.join(' ')+']')
- if projectlist.length == 0 then
- return nil
- else
- return projectlist
- end
- else
- @interface.set('log:projectlist', '[no projects]')
- return nil
- end
- end
-
- def fetch_session_command(data)
- data.scan(/^process\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*$/) do
- domain, process, command = $1, $2, $3
- if @session.match?('domain',domain) && @session.match?('process',process) then
- @session.set('command', @interface.resolved(command))
- end
- end
- return @session.get('command')
- end
-
- def fetch_session_settings(data)
- data.scan(/^setting\s*:\s*(.*?)\s*\,\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*$/) do
- domain, process, variable, value = $1, $2, $3, $4
- if @session.match?('domain',domain) && @session.match?('process',process) then
- @interface.set(variable,value)
- end
- end
- end
-
- def get_command(action)
- # @session.set('action', action)
- # if @session.get('process') == 'none' then
- # @interface.set('log:child','yes')
- # @session.set('process', action)
- # end
- if data = load_interface_file() then
- fetch_session_interface_variables(data)
- if projectlist = fetch_session_project_list(data) then
- data.scan(/^project\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*$/) do
- domain, project, gui, path, process = $1, $2, $3, $4, $5
- if @session.match?('domain',domain) then
- if @session.match?('project',project) then
- if projectlist.include?(project) then
- @session.set('process', @interface.resolved(process))
- # break # no, else we end up in the parent (e.g. examplap instead of impose)
- end
- elsif ! action.empty? && project == action then
- if projectlist.include?(action) then
- @session.set('process', @interface.resolved(process))
- # break # no, else we end up in the parent (e.g. examplap instead of impose)
- end
- end
- end
- end
- fetch_session_command(data)
- fetch_session_settings(data)
- end
- end
- return ! @session.nothing?('command')
- end
-
- def get_file(filename)
- @session.set('filename', filename)
- if data = load_interface_file() then
- fetch_session_interface_variables(data)
- if projectlist = fetch_session_project_list(data) then
- data.scan(/^project\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*$/) do
- domain, project, gui, path, process = $1, $2, $3, $4, $5
- if @session.match?('domain',domain) then
- guilist = @interface.resolved(gui).split(@@re_bar)
- guilist.each do |g|
- if /#{filename}$/ =~ g then
- @session.set('gui', File.expand_path(@interface.resolved(g)))
- @session.set('path', File.expand_path(@interface.resolved(path)))
- @session.set('process', process)
- break # take first matching interface
- end
- end
- end
- end
- end
- end
- return ! (@session.nothing?('gui') && @session.nothing?('path') && @session.nothing?('process'))
- end
-
- def get_path(url='')
- if data = load_interface_file() then
- fetch_session_interface_variables(data)
- if projectlist = fetch_session_project_list(data) then
- data.scan(/^project\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*$/) do
- domain, project, gui, path, process = $1, $2, $3, $4, $5
- if @session.match?('domain',domain) && @session.match?('project',project) then
- @session.set('url', url)
- @session.set('gui', '')
- @session.set('path', File.expand_path(@interface.resolved(path)))
- @session.set('process', '')
- end
- end
- end
- end
- return ! @session.nothing?('path')
- end
-
- def get_gui()
- if data = load_interface_file() then
- fetch_session_interface_variables(data)
- if projectlist = fetch_session_project_list(data) then
- data.scan(/^project\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*$/) do
- domain, project, gui, path, process = $1, $2, $3, $4, $5
- if @session.match?('domain',domain) && @session.match?('project',project) && projectlist.include?(project) then
- @session.set('gui', File.expand_path(@interface.resolved(gui)))
- @session.set('path', File.expand_path(@interface.resolved(path)))
- @session.set('process', process) unless process == 'none'
- break # take first matching interface
- end
- end
- data.scan(/^admin\s*:\s*(.*?)\s*\,\s*(.*?)\s*\=\s*(.*?)\s*\,\s*(.*?)\s*$/) do
- domain, project, task, option = $1, $2, $3, $4
- if @session.match?('domain',domain) && @session.match?('project',project) && projectlist.include?(project) then
- @session.set('task', task)
- @session.set('option', option)
- break # take first matching task
- end
- end
- end
- end
- return ! (@session.nothing?('gui') && @session.nothing?('path') && @session.nothing?('process'))
- end
-
- def get_cfg()
- if data = load_interface_file() then
- fetch_session_interface_variables(data)
- end
- end
-
-end
-
-class WWW
-
- def send_reply(logdata='')
- if @interface.true?('trace:run') then
- send_result(logdata)
- else
- dir, tmp = dirname, tmp_path(dirname)
- case @session.get('status')
- when 'running: finished' then
- resultname, replyname = 'result.pdf', 'reply.exa'
- replyfile = File.join(tmp,replyname)
- if FileTest.file?(replyfile) then
- begin
- data = IO.read(replyfile)
- resultname = if data =~ /(.*?)<\/exa:output>/ then $1 else resultname end
- rescue
- plaintext(exareply('error in reply'))
- return
- end
- end
- resultfile = File.join(tmp,resultname)
- if FileTest.file?(resultfile) then
- if indirect?(resultfile) then
- begin
- File.makedirs(File.join(cache_root,dir))
- FileUtils::mv(resultfile,File.join(cache_root,dir,resultname))
- rescue
- plaintext(exareply('unable to access cache'))
- else
- plaintext(exareply('big file', "cache/#{dir}/#{resultname}", "#{File.size?(resultfile)}"))
- end
- else
- send_file(resultfile)
- end
- else
- plaintext(exareply('no result'))
- end
- else # background, running, aborted
- plaintext(exareply(@session.get('status')))
- end
- end
- end
-
- def send_url(fullname)
- dir, tmp = dirname, tmp_path(dirname)
- resultname, replyname = 'result.pdf', 'reply.exa'
- replyfile = File.join(tmp,replyname)
- resultfile = File.join(tmp,resultname)
- targetname = File.join(cache_root,dir,resultname)
- # make sure that there is no target left in case of an
- # error; needed in case of given session name
- if FileTest.directory?(File.join(cache_root,dir)) then
- File.delete(targetname) rescue false
- end
- # now try to locate the file
- if FileTest.file?(fullname) then
- if indirect?(fullname) then
- begin
- # check if directory exists and (if so) delete left overs
- File.makedirs(File.join(cache_root,dir))
- File.delete(targetname) rescue false
- File.symlink(fullname,targetname) rescue message('Status',$!)
- unless FileTest.file?(targetname) then
- FileUtils::cp(fullname,targetname) rescue false
- end
- rescue
- plaintext(exareply('unable to access cache'))
- else
- plaintext(exareply('big file', "cache/#{dir}/#{resultname}", "#{File.size?(fullname)}"))
- end
- else
- send_file(fullname)
- end
- else
- message('Status', 'The file is not found')
- end
- end
-
- def send_result(logdata='')
- check_template_file('exalogin','exalogin-template.htm')
- dir, tmp = dirname, tmp_path(dirname)
- resultname, replyname, logname = 'result.pdf', 'reply.exa', 'log.htm'
- case @session.get('status')
- when 'running: background' then
- if st = @session.get('starttime') then # fuzzy
- st = Time.now.to_i if st.empty?
- if (Time.now.to_i - st.to_i) > @interface.get('process:timeout').to_i then
- message('Status', 'Your request has been aborted (timeout)',true)
- else
- message('Status', 'Your request is queued',true,5,'exastatus')
- end
- end
- when 'running: busy' then
- if st = @session.get('starttime') then # fuzzy
- st = Time.now.to_i if st.empty?
- if (Time.now.to_i - st.to_i) > @interface.get('process:timeout').to_i then
- message('Status', 'Your request has been aborted (timeout)',true)
- else
- message('Status', 'Your request is being processed',true,5,'exastatus')
- end
- end
- when 'running: aborted' then
- message('Status', 'Your request has been aborted (timeout)',true)
- when 'running: finished' then
- if @interface.true?('trace:run') then
- logfile = File.join(tmp,logname)
- begin
- if f = File.open(logname,'w') then
- if logdata.empty? then
- begin
- logdata = IO.read('www-watch.out')
- rescue
- logdata = 'no log data'
- end
- end
- f << filled_template('Log',"
#{CGI::escapeHTML(logdata)}
")
- f.close
- end
- rescue
- message('Error', '')
- end
- if FileTest.file?(logfile) then
- begin
- File.makedirs(File.join(cache_root,dir))
- FileUtils::mv(logfile,File.join(cache_root,dir,logname))
- rescue
- logdata = "
unable to access cache"
- else
- logdata = "
#{logname}"
- end
- else
- logdata = ''
- end
- else
- logdata = ''
- end
- # todo: generate reply.exa if no reply
- replyfile = File.join(tmp,replyname)
- if FileTest.file?(replyfile) then
- begin
- data = IO.read(replyfile)
- resultname = if data =~ /(.*?)<\/exa:output>/ then $1 else resultname end
- rescue
- message('Error','There is a problem in handling this request (invalid reply).')
- return
- end
- end
- resultfile = File.join(tmp,resultname)
- if FileTest.file?(resultfile) then
- if indirect?(resultfile) then
- begin
- File.makedirs(File.join(cache_root,dir))
- FileUtils::mv(resultfile,File.join(cache_root,dir,resultname))
- rescue
- str = "
unable to access cache"
- else
- str = "
#{resultname} (#{File.size?(resultname)} bytes)"
- end
- message('Result', 'You can pick up the result here:' + str + logdata)
- else
- send_file(resultfile)
- end
- else
- message('Error', 'There is a problem in handling this request (no result file).' + logdata)
- end
- end
- end
-
-end
diff --git a/scripts/context/ruby/www/login.rb b/scripts/context/ruby/www/login.rb
deleted file mode 100644
index 1c88a97e6..000000000
--- a/scripts/context/ruby/www/login.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'www/lib'
-
-# basic login
-
-class WWW
-
- def handle_login()
- check_template_file('login','exalogin.htm')
- set('password', '')
- message('Login','')
- end
-
-end
diff --git a/scripts/context/ruby/wwwclient.rb b/scripts/context/ruby/wwwclient.rb
deleted file mode 100644
index d41541a09..000000000
--- a/scripts/context/ruby/wwwclient.rb
+++ /dev/null
@@ -1,677 +0,0 @@
-#!/usr/bin/env ruby
-
-# a direct request is just passed on
-#
-# exaclient --direct --request=somerequest.exa --result=somefile.pdf
-#
-# in an extended request the filename in the template file is replaced by the filename
-# given on the command line; templates are located on the current path and at parent
-# directories (two levels); the filename is expanded to a full path
-#
-# exaclient --extend --template=tmicare-l-h.exa --file=somefile.xml --result=somefile.pdf
-#
-# a constructed request is build out of the provided filename and action; the filename is
-# expanded to a full path
-#
-# exaclient --construct --action=tmicare-s-h.exa --file=somefile.xml --result=somefile.pdf
-#
-# in all cases, the result is either determined by a switch or taken from a reply file
-
-banner = ['WWWClient', 'version 1.0.0', '2003-2006', 'PRAGMA ADE/POD']
-
-$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
-
-require 'base/switch'
-require 'base/logger'
-
-require 'timeout'
-require 'thread'
-require 'rexml/document'
-require 'net/http'
-
-class File
-
- def File.backtracked(filename,level=3)
- if level > 0 && filename && ! filename.empty? then
- if FileTest.file?(filename) then
- filename
- else
- File.backtracked('../'+filename,level-1)
- end
- else
- filename
- end
- end
-
- def File.expanded(filename)
- File.expand_path(filename)
- end
-
-end
-
-class Commands
-
- include CommandBase
-
-end
-
-class Commands
-
- @@namespace = "xmlns:exa='http://www.pragma-ade.com/schemas/example.rng'"
- @@randchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "abcdefghijklmnopqrstuvwxyz"
-
- def traceback
- "(error: #{$!})" + "\n -- " + $@.join("\n >>")
- end
-
- def pdf(action,filename,enabled)
- if enabled && FileTest.file?(filename) then
- begin
- report("pdf action #{action} on #{filename}")
- case action
- when 'close' then system("pdfclose --all")
- when 'open' then system("pdfopen --file #{filename}")
- end
- rescue
- # forget about it
- end
- end
- end
-
- def status(replyfile,str) # when block, then ok
- begin
- # def status(*whatever)
- # end
- File.open(replyfile,'w') do |f|
- report("saving reply info in '#{replyfile}'")
- f.puts("\n\n")
- f.puts("\n")
- if block_given? then
- f.puts(" ok\n")
- f.puts(" #{yield}\n")
- else
- f.puts(" error\n")
- end
- f.puts(" " + str + "\n")
- f.puts("\n")
- f.close
- report("saving status: #{str}")
- end
- rescue
- report("saving reply info in '#{replyfile}' fails")
- ensure
- exit
- end
- exit # to be real sure
- end
-
-
- def boundary_string (length) # copied from webrick/utils
- rand_max = @@randchars.size
- ret = ""
- length.times do
- ret << @@randchars[rand(rand_max)]
- end
- ret.upcase
- end
-
-end
-
-class Commands
-
- @@connecttimeout = 10*60 # ten minutes
- @@processtimeout = 60*60 # an hour
- @@polldelay = 5 # 5 seconds
-
- def main
-
- datatemplate = @commandline.option('template')
- datafile = @commandline.option('file')
- dataaction = @commandline.option('action')
-
- if ! datatemplate.empty? then
- report("template '#{datatemplate}' specified without --construct")
- report("aborting")
- elsif ! dataaction.empty? then
- report("action data '#{dataaction}' specified without --construct or --extend")
- report("aborting")
- elsif ! datafile.empty? then
- report("action file '#{datafile}' specified without --construct or --extend")
- report("aborting")
- else
- report("assuming --direct")
- direct()
- end
-
- end
-
- def construct
-
- requestfile = @commandline.option('request')
- replyfile = @commandline.option('reply')
-
- datatemplate = @commandline.option('template')
- datafile = @commandline.option('file')
- dataaction = @commandline.option('action')
-
- domain = @commandline.option('domain')
- project = @commandline.option('project')
- username = @commandline.option('username')
- password = @commandline.option('password')
-
- threshold = @commandline.option('threshold')
-
- datablob = ''
-
- begin
- datablob = IO.read(datatemplate)
- rescue
- datablob = ''
- else
- begin
- request = REXML::Document.new(datablob)
- if e = REXML::XPath.match(request.root,"/exa:request/exa:data") then
- datablob = e.to_s.chomp
- end
- rescue
- datablob = ''
- end
- end
-
- begin
- File.open(requestfile,'w') do |f|
- f.puts "\n"
- f.puts "\n"
- f.puts " \n"
- f.puts " #{dataaction}\n" unless dataaction.empty?
- f.puts " #{datafile}\n" unless datafile.empty?
- f.puts " #{threshold}\n" unless threshold.empty?
- f.puts " \n"
- f.puts " \n"
- f.puts " #{domain}\n"
- f.puts " #{project}\n"
- f.puts " #{username}\n"
- f.puts " #{password}\n"
- f.puts " \n"
- if datablob.empty? then
- f.puts " \n"
- else
- f.puts " #{datablob.chomp}\n"
- end
- f.puts ""
- end
- rescue
- status(replyfile,"unable to create '#{requestfile}'")
- end
-
- direct()
-
- end
-
- def extend
-
- requestfile = @commandline.option('request')
- replyfile = @commandline.option('reply')
-
- datatemplate = @commandline.option('template')
- datafile = @commandline.option('file')
- dataaction = @commandline.option('action')
-
- threshold = @commandline.option('threshold')
-
- if datatemplate.empty? then
- status(replyfile,"invalid data template '#{datatemplate}'")
- else
- begin
- if FileTest.file?(datatemplate) && oldrequest = IO.read(datatemplate) then
- request, done = REXML::Document.new(oldrequest), false
- if ! threshold.empty? && e = REXML::XPath.match(request.root,"/exa:request/exa:application/exa:threshold") then
- e.text, done = threshold, true
- end
- if ! dataaction.empty? && e = REXML::XPath.match(request.root,"/exa:request/exa:application/exa:action") then
- e.text, done = dataaction, true
- end
- if ! datafile.empty? && e = REXML::XPath.match(request.root,"/exa:request/exa:application/exa:filename") then
- e.text, done = datafile, true
- end
- #
- if ! threshold.empty? && e = REXML::XPath.match(request.root,"/exa:request/exa:application") then
- e = e.add_element('exa:threshold')
- e.add_text(threshold.to_s)
- done = true
- end
- #
- report("nothing replaced in template file") unless done
- begin
- File.open(requestfile,'w') do |f|
- f.puts(newrequest.to_s)
- end
- rescue
- status(replyfile,"unable to create '#{requestfile}'")
- end
- else
- status(replyfile,"unable to read data template '#{datatemplate}'")
- end
- rescue
- status(replyfile,"unable to handle data template '#{datatemplate}'")
- end
- end
-
- direct()
-
- end
-
- def direct
-
- requestpath = @commandline.option('path')
- requestfile = @commandline.option('request')
- replyfile = @commandline.option('reply')
- resultfile = @commandline.option('result')
- datatemplate = @commandline.option('template')
- datafile = @commandline.option('file')
- threshold = @commandline.option('threshold')
- address = @commandline.option('address')
- port = @commandline.option('port')
- session_id = @commandline.option('session')
- exaurl = @commandline.option('exaurl')
-
- exaurl = "/#{exaurl}" unless exaurl =~ /^\//
-
- address.sub!(/^http\:\/\//io) do
- ''
- end
- address.sub!(/\:(\d+)$/io) do
- port = $1
- ''
- end
-
- autopdf = @commandline.option('autopdf')
-
- dialogue = nil
-
- resultfile.sub!(/\.[a-z]+?$/, '') # don't overwrite the source
-
- unless requestpath.empty? then
- begin
- if FileTest.directory?(requestpath) then
- if Dir.chdir(requestpath) then
- report("gone to path '#{requestpath}'")
- else
- status(replyfile,"unable to go to path '#{requestpath}")
- end
- else
- status(replyfile,"unable to locate '#{requestpath}'")
- end
- rescue
- status(replyfile,"unable to handle '#{requestpath}'")
- end
- end
-
- datafile = File.expand_path(datafile) unless datafile.empty?
- datatemplate = File.backtracked(datatemplate,3) unless datatemplate.empty?
-
- # request must be valid
-
- status(replyfile,'no request file') if requestfile.empty?
- status(replyfile,"invalid request file '#{requestfile}'") unless FileTest.file?(requestfile)
-
- begin
- request = IO.readlines(requestfile).join('')
- request = REXML::Document.new(request)
- status(replyfile,'invalid request (no request)') unless request.root.fully_expanded_name=='exa:request'
- status(replyfile,'invalid request (no application block)') unless request.elements['exa:request'].elements['exa.application'] == nil # explicit nil test needed
- rescue REXML::ParseException
- status(replyfile,'invalid request (invalid xml file)')
- rescue
- status(replyfile,'invalid request (invalid file)')
- else
- report("using request file '#{requestfile}'")
- end
-
- # request can force session_id
-
- if session_id && session_id.empty? then
- begin
- id = request.elements['exa:request'].elements['exa:application'].elements['exa:session'].text
- rescue Exception
- id = ''
- ensure
- if id && ! id.empty? then
- session_id = id
- end
- end
- end
-
- # request can overload reply name
-
- begin
- rreplyfile = request.elements['exa:request'].elements['exa:application'].elements['exa:output'].text
- rescue Exception
- rreplyfile = nil
- ensure
- if rreplyfile && ! rreplyfile.empty? then
- replyfile = rreplyfile
- report("reply file '#{replyfile} set by request'")
- else
- report("using reply file '#{replyfile}'")
- end
- end
-
- # request can overload result name
-
- begin
- rresultfile = request.elements['exa:request'].elements['exa:application'].elements['exa:result']
- rescue Exception
- rresultfile = nil
- ensure
- if rresultfile && ! rresultfile.empty? then
- resultfile = rresultfile
- report("result file '#{resultfile}' set by request")
- else
- report("using result file '#{resultfile}'")
- end
- end
-
- # try to connect to server
-
- start_time = Time.now
-
- processtimeout = begin @commandline.option('timeout').to_i rescue @@processtimeout end
- processtimeout = @@processtimeout if processtimeout == 0 # 'xx'.to_i => 0
-
- dialogue = start_dialogue(address, port, processtimeout)
-
- if dialogue then
- # continue
- else
- status(replyfile,'no connection')
- end
-
- # post request
-
- timeout (@@processtimeout-10) do # -10 so that we run into this one first
- begin
- report("posting request of type '#{exaurl}'")
- report("using session id '#{session_id}'") if session_id && ! session_id.empty?
- firstline, chunks, total = nil, 0, 0
- body, boundary, crlf = '', boundary_string(32), "\x0d\x0a"
- body << '--' + boundary + crlf
- body << "Content-Disposition: form-data; name=\"exa:request\""
- body << crlf
- body << "Content-Type: text/plain"
- body << crlf + crlf
- body << request.to_s
- body << crlf + '--' + boundary + crlf
-if session_id && ! session_id.empty? then
- body << "Content-Disposition: form-data; name=\"exa:session\""
- body << "Content-Type: text/plain"
- body << crlf + crlf
- body << session_id
- body << crlf + '--' + boundary + crlf
-end
- begin
- File.open(datafile,'rb') do |df|
- body << "Content-Disposition: form-data; name=\"filename\""
- body << "Content-Type: text/plain"
- body << crlf + crlf
- body << datafile
- body << crlf + '--' + boundary + crlf
- body << "Content-Disposition: form-data; name=\"fakename\" ; filename=\"#{datafile}\""
- body << "Content-Type: application/octetstream"
- body << "Content-Transfer-Encoding: binary"
- body << crlf + crlf
- body << df.read
- body << crlf + '--' + boundary + '--' + crlf
- end
- rescue
- # skip
- end
- headers = Hash.new
- headers['content-type'] = "multipart/form-data; boundary=#{boundary}"
- headers['content-length'] = body.length.to_s
- begin
- File.open(resultfile,'wb') do |rf|
- begin
- # firstline is max 1024 but ok for reply
- dialogue.post(exaurl,body,headers) do |str|
- if ! firstline || firstline.empty? then
- report('receiving result') if total == 0
- firstline = str
- end
- total += 1
- rf.write(str)
- end
- rescue
- report("forced close #{traceback}")
- end
- end
- rescue
- status(replyfile,'cannot open file')
- end
- begin
- File.delete(resultfile) if File.zero?(resultfile)
- rescue
- end
- unless FileTest.file?(resultfile) then
- report("deleting empty resultfile")
- begin
- File.delete(resultfile)
- rescue
- # nice try, an error anyway
- end
- status(replyfile,'empty file')
- else
- n, id, status = 0, '', ''
- loop do
- again = false
- if ! dialogue then
- again = true
- elsif firstline =~ /(\ 1
- unless dialogue then
- report('reestablishing connection')
- dialogue = start_dialogue(address, port, processtimeout)
- end
- if dialogue then
- begin
- File.open(resultfile,'wb') do |rf|
- begin
- body = "id=#{id}"
- headers = Hash.new
- headers['content-type'] = "application/x-www-form-urlencoded"
- headers['content-length'] = body.length.to_s
- total, firstline = 0, ''
- dialogue.post("/exastatus",body,headers) do |str|
- if ! firstline || firstline.empty? then
- firstline = str
- end
- total += 1
- rf.write(str)
- end
- rescue
- report("forced close #{traceback}")
- dialogue = nil
- again = true
- end
- end
- begin
- File.delete(resultfile) if File.zero?(resultfile)
- rescue
- end
- rescue
- report("error in opening file #{traceback}")
- status(replyfile,'cannot open file')
- end
- else
- report("unable to make a connection")
- status(replyfile,'unable to make a connection') # exit
- end
- else
- break
- end
- end
- case firstline
- when /<\?xml\s*version=.*?\?>\s*#{resultfile}
"
- end
- when /html/io then
- report("done, file #{resultfile}, type html, #{total} chunks, #{File.size? rescue 0} bytes")
- if resultfile =~ /\.(htm|html)$/i then
- report("file identified as 'html'")
- elsif resultfile =~ /\..*$/o
- report("result file suffix should be 'htm'")
- else
- newresultfile = resultfile + '.htm'
- begin
- File.delete(newresultfile) if FileTest.file?(newresultfile)
- resultfile = newresultfile if File.rename(resultfile,newresultfile)
- rescue
- report("adding 'htm' suffix to result name failed")
- else
- report("'htm' suffix added to result name")
- end
- end
- report("result saved in '#{resultfile}'")
- status(replyfile,'ok') do
- "#{resultfile}"
- end
- else
- report("no result file, first line #{firstline}")
- status(replyfile,'no result file')
- end
- end
- rescue TimeoutError
- report("aborted due to time out")
- status(replyfile,'time out')
- rescue
- report("aborted due to some problem #{traceback}")
- status(replyfile,"no answer #{traceback}")
- end
- end
-
- begin
- report("run time: #{Time.now-start_time} seconds")
- rescue
- end
-
- end
-
- def start_dialogue(address, port, processtimeout)
- timeout(@@connecttimeout) do
- report("trying to connect to #{address}:#{port}")
- begin
- begin
- if dialogue = Net::HTTP.new(address, port) then
- # dialogue.set_debug_output $stderr
- dialogue.read_timeout = processtimeout # set this before start
- if dialogue.start then
- report("connected to #{address}:#{port}, timeout: #{processtimeout}")
- else
- retry
- end
- else
- retry
- end
- rescue
- sleep(2)
- retry
- else
- return dialogue
- end
- rescue TimeoutError
- return nil
- rescue
- return nil
- end
- end
- end
-
-end
-
-logger = Logger.new(banner.shift)
-commandline = CommandLine.new
-
-commandline.registerflag('autopdf')
-
-commandline.registervalue('path' , '')
-
-commandline.registervalue('request' , 'request.exa')
-commandline.registervalue('reply' , 'reply.exa')
-commandline.registervalue('result' , 'result')
-
-commandline.registervalue('template' , '')
-commandline.registervalue('file' , '')
-commandline.registervalue('action' , '')
-commandline.registervalue('timeout' , '')
-
-commandline.registervalue('domain' , 'default')
-commandline.registervalue('project' , 'default')
-commandline.registervalue('username' , 'guest')
-commandline.registervalue('password' , 'anonymous')
-commandline.registervalue('exaurl' , 'exarequest')
-commandline.registervalue('threshold' , '0')
-commandline.registervalue('session' , '')
-
-commandline.registervalue('address' , 'localhost')
-commandline.registervalue('port' , '80')
-
-commandline.registeraction('direct' , '[--path --request --reply --result --autopdf]')
-commandline.registeraction('construct', '[--path --request --reply --result --autopdf] --file --action')
-commandline.registeraction('extend' , '[--path --request --reply --result --autopdf] --file --action --template')
-
-commandline.registeraction('direct')
-commandline.registeraction('construct')
-commandline.registeraction('extend')
-
-commandline.registerflag('verbose')
-commandline.registeraction('help')
-commandline.registeraction('version')
-
-commandline.expand
-
-Commands.new(commandline,logger,banner).send(commandline.action || 'main')
diff --git a/scripts/context/ruby/wwwserver.rb b/scripts/context/ruby/wwwserver.rb
deleted file mode 100644
index 13d5d1312..000000000
--- a/scripts/context/ruby/wwwserver.rb
+++ /dev/null
@@ -1,293 +0,0 @@
-#!/usr/bin/env ruby
-
-banner = ['WWWServer', 'version 1.0.0', '2003-2006', 'PRAGMA ADE/POD']
-
-$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
-
-require 'base/switch'
-require 'base/logger'
-
-require 'monitor'
-
-# class WWW < Monitor
-# end
-# class Server < Monitor
-# end
-
-require 'www/lib'
-require 'www/dir'
-require 'www/login'
-require 'www/exa'
-
-require 'tempfile'
-require 'ftools'
-require 'webrick'
-
-class Server
-
- attr_accessor :document_root, :work_path, :logs_path, :port_number, :exa_url, :verbose, :trace, :direct
-
- def initialize(logger)
- @httpd = nil
- @document_root = ''
- @work_path = ''
- @logs_path = ''
- @port_number = 8061
- @exa_url = 'http://localhost:8061'
- @logger = logger
- @n_of_clients = 500
- @request_timeout = 5*60
- @verbose = false
- @trace = false
- @direct = false
- end
-
- def report(str)
- @logger.report(str) if @logger
- end
-
- def setup
- if @document_root.empty? then
- rootpath = File.expand_path($0)
- @document_root = File.expand_path(File.join(File.dirname(rootpath),'..','documents'))
- unless FileTest.directory?(@document_root) then # todo: optional
- loop do
- prevpath = rootpath.dup
- rootpath = File.dirname(rootpath)
- if prevpath == rootpath then
- break
- else
- checkpath = File.join(rootpath,'documents')
- # report("locating: #{checkpath}")
- if FileTest.directory?(checkpath) then
- @document_root = checkpath
- break
- else
- checkpath = File.join(rootpath,'docroot/documents')
- # report("locating: #{checkpath}")
- if FileTest.directory?(checkpath) then
- @document_root = checkpath
- break
- end
- end
- end
- end
- end
- end
- @document_root = File.join(Dir.pwd, 'documents') unless FileTest.directory?(@document_root)
- unless FileTest.directory?(@document_root) then
- report("invalid document root: #{@document_root}")
- exit
- else
- report("using document root: #{@document_root}")
- end
- #
- @work_path = File.expand_path(File.join(@document_root,'..','work')) if @work_path.empty?
- # begin File.makedirs(@work_path) ; rescue ; end # no, let's auto-temp
- if ! FileTest.directory?(@work_path) || ! FileTest.writable?(@work_path) then
- @work_path = File.expand_path(File.join(Dir.tmpdir,'exaserver','work'))
- begin File.makedirs(@logs_path) ; rescue ; end
- end
- report("using work path: #{@work_path}")
- #
- @logs_path = File.expand_path(File.join(@document_root,'..','logs')) if @logs_path.empty?
- # begin File.makedirs(@logs_path) ; rescue ; end # no, let's auto-temp
- if ! FileTest.directory?(@logs_path) || ! FileTest.writable?(@logs_path) then
- @logs_path = File.expand_path(File.join(Dir.tmpdir,'exaserver','logs'))
- begin File.makedirs(@logs_path) ; rescue ; end
- end
- report("using log path: #{@logs_path}")
- #
- if @logs_path.empty? then
- @logfile = $stderr
- @accfile = $stderr
- else
- @logfile = File.join(@logs_path,'exa-info.log')
- @accfile = File.join(@logs_path,'exa-access.log')
- begin File.delete(@logfile) ; rescue ; end
- begin File.delete(@accfile) ; rescue ; end
- end
- #
- begin
- @httpd = WEBrick::HTTPServer.new(
- :DocumentRoot => @document_root,
- :DocumentRootOptions => { :FancyIndexing => false },
- :DirectoryIndex => ['index.html','index.htm','showcase.pdf'],
- :Port => @port_number.to_i,
- :Logger => WEBrick::Log.new(@logfile, WEBrick::Log::INFO), # DEBUG
- :RequestTimeout => @request_timeout,
- :MaxClients => @n_of_clients,
- :AccessLog => [
- [ @accfile, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
- [ @accfile, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
- [ @accfile, WEBrick::AccessLog::AGENT_LOG_FORMAT ],
- # :CGIPathEnv => ENV["PATH"] # PATH environment variable for CGI.
- ]
- )
- rescue
- report("starting server at port: #{@port_number} failed")
- exit
- else
- report("running server at port: #{@port_number}")
- end
-
- begin
- #
- @httpd.mount_proc("/dir") do |request,reply|
- report("accepting /dir") if @verbose
- web_session(request,reply).handle_dir
- end
- @httpd.mount_proc("/login") do |request,reply|
- report("accepting /login") if @verbose
- web_session(request,reply).handle_login
- end
- @httpd.mount("/cache", WEBrick::HTTPServlet::FileHandler, File.join(@work_path,'cache'))
- # @httpd.mount_proc("/cache") do |request,reply|
- # WEBrick::HTTPServlet::FileHandler(@httpd,@work_path) # not ok
- # end
- @httpd.mount_proc("/exalogin") do |request,reply|
- report("accepting /exalogin") if @verbose
- web_session(request,reply).handle_exalogin
- end
- @httpd.mount_proc("/exadefault") do |request,reply|
- report("accepting /exadefault") if @verbose
- web_session(request,reply).handle_exadefault
- end
- @httpd.mount_proc("/exainterface") do |request,reply|
- report("accepting /exainterface") if @verbose
- web_session(request,reply).handle_exainterface
- end
- @httpd.mount_proc("/exarequest") do |request,reply|
- report("accepting /exarequest") if @verbose
- web_session(request,reply).handle_exarequest
- end
- @httpd.mount_proc("/exacommand") do |request,reply|
- report("accepting /exacommand") if @verbose
- web_session(request,reply).handle_exacommand
- end
- @httpd.mount_proc("/exastatus") do |request,reply|
- report("accepting /exastatus") if @verbose
- web_session(request,reply).handle_exastatus
- end
- @httpd.mount_proc("/exaadmin") do |request,reply|
- report("accepting /exaadmin") if @verbose
- web_session(request,reply).handle_exaadmin
- end
- #
- rescue
- report("problem in starting server: #{$!}")
- end
- [:INT, :TERM, :EXIT].each do |signal|
- trap(signal) do
- @httpd.shutdown
- end
- end
- end
-
- def start
- unless @httpd then
- setup
- @httpd.start
- end
- end
-
- def stop
- @httpd.shutdown if @httpd
- end
-
- def restart
- stop
- start
- end
-
- private
-
- def web_session(request,reply)
- www = WWW.new(@httpd,request,reply)
- www.set('path:work', @work_path)
- www.set('path:logs', @logs_path)
- www.set('path:root', File.dirname(@document_root))
- www.set('process:exaurl', @exa_url)
- www.set('trace:errors','yes') if @trace
- www.set('process:background', 'no') if @direct
- return www
- end
-
-end
-
-class Commands
-
- include CommandBase
-
- def start
- if server = setup then server.start end
- end
-
- def stop
- if server = setup then server.stop end
- end
-
- def restart
- if server = setup then server.restart end
- end
-
- private
-
- def setup
- server = Server.new(logger)
- server.document_root = @commandline.option('root')
- server.verbose = @commandline.option('verbose')
- if @commandline.option('forcetemp') then
- server.work_path = Dir.tmpdir + '/exa/work'
- server.logs_path = Dir.tmpdir + '/exa/logs'
- [server.work_path,server.logs_path].each do |d|
- begin
- File.makedirs(d) unless FileTest.directory?(d)
- rescue
- report("unable to create #{d}")
- exit
- end
- unless FileTest.writable?(d) then
- report("unable to access #{d}")
- exit
- end
- end
- else
- server.work_path = @commandline.option('work')
- server.logs_path = @commandline.option('logs')
- end
- server.port_number = @commandline.option('port')
- server.exa_url = @commandline.option('url')
- server.trace = @commandline.option('trace')
- server.direct = @commandline.option('direct')
- return server
- end
-
-end
-
-logger = Logger.new(banner.shift)
-commandline = CommandLine.new
-
-commandline.registervalue('root' , '')
-commandline.registervalue('work' , '')
-commandline.registervalue('logs' , '')
-commandline.registervalue('address', 'localhost')
-commandline.registervalue('port' , '8061')
-commandline.registervalue('url' , 'http://localhost:8061')
-
-commandline.registeraction('start' , 'start the server [--root --forcetemp --work --logs --address --port --url]')
-commandline.registeraction('stop' , 'stop the server')
-commandline.registeraction('restart', 'restart the server')
-
-commandline.registerflag('forcetemp')
-commandline.registerflag('direct')
-commandline.registerflag('verbose')
-commandline.registerflag('trace')
-
-commandline.registeraction('help')
-commandline.registeraction('version')
-
-commandline.expand
-
-Commands.new(commandline,logger,banner).send(commandline.action || 'start')
-
diff --git a/scripts/context/ruby/wwwwatch.rb b/scripts/context/ruby/wwwwatch.rb
deleted file mode 100644
index 0faa45aec..000000000
--- a/scripts/context/ruby/wwwwatch.rb
+++ /dev/null
@@ -1,497 +0,0 @@
-#!/usr/bin/env ruby
-
-banner = ['WWWWatch', 'version 1.0.0', '2003-2006', 'PRAGMA ADE/POD']
-
-$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
-
-require 'base/switch'
-require 'base/logger'
-
-require 'www/common'
-
-require 'monitor'
-require 'fileutils'
-require 'ftools'
-require 'tempfile'
-require 'timeout'
-require 'thread'
-
-class Watch < Monitor
-
- include Common
-
- @@session_prefix = ''
- @@check_factor = 4
- @@process_timeout = 1*60*60
- @@fast_wait_loop = false
-
- @@session_line = /^\s*(?![\#\%])(.*?)\s*\=\s*(.*?)\s*$/o
- @@session_begin = 'begin exa session'
- @@session_end = 'end exa session'
-
- attr_accessor :root_path, :work_path, :create, :cache_path, :delay, :max_threads, :max_age, :verbose
-
- def initialize(logger) # we need to register all @vars here becase of the monitor
- @threads = Hash.new
- @files = Array.new
- @stats = Hash.new
- @skips = Hash.new
- @root_path = ''
- @work_path = Dir.tmpdir
- @cache_path = @work_path
- @last_action = Time.now
- @delay = 1
- @max_threads = 5
- @max_age = @@process_timeout
- @logger = logger
- @verbose = false
- @create = false
- @onlyonerun = false
- # [:INT, :TERM, :EXIT].each do |signal|
- # trap(signal) do
- # kill
- # exit # rescue false
- # end
- # end
- # at_exit do
- # kill
- # end
- end
-
- def trace
- if @verbose && @logger then
- @logger.report("exception: #{$!})")
- $@.each do |t|
- @logger.report(">> #{t}")
- end
- end
- end
-
- def report(str)
- @logger.report(str) if @logger
- end
-
- def setup
- @threads = Hash.new
- @files = Array.new
- @stats = Hash.new
- @skips = Hash.new
- @root_path = File.expand_path(File.join(File.dirname(Dir.pwd),'.')) if @root_path.empty?
- @work_path = File.expand_path(File.join(@root_path,'work','watch')) if @work_path.empty?
- # @cache_path = File.expand_path(File.join(@root_path,'work','cache')) if @cache_path.empty?
- @cache_path = File.expand_path(File.join(File.dirname(@work_path),'cache')) if @cache_path.empty?
- if @create then
- begin File.makedirs(@work_path) ; rescue ; end
- begin File.makedirs(@cache_path) ; rescue ; end
- end
- unless File.writable?(@work_path) then
- @work_path = File.expand_path(File.join(Dir.tmpdir,'work','watch'))
- if @create then
- begin File.makedirs(@work_path) ; rescue ; end
- end
- end
- unless File.writable?(@cache_path) then
- @cache_path = File.expand_path(File.join(Dir.tmpdir,'work','cache'))
- if @create then
- begin File.makedirs(@cache_path) ; rescue ; end
- end
- end
- unless File.writable?(@work_path) then
- puts "no valid work path: #{@work_path}"
- exit! rescue false # no checking, no at_exit done
- end
- unless File.writable?(@cache_path) then
- puts "no valid cache path: #{@cache_path}" ; # no reason to exit
- end
- @last_action = Time.now
- report("watching path #{@work_path}") if @verbose
- end
-
- def lock(lck)
- begin
- report("watchdog: locking #{lck}") if @verbose
- File.open(lck,'w') do |f|
- f << Time.now
- end
- rescue
- trace
- end
- end
-
- def unlock(lck)
- begin
- report("watchdog: unlocking #{lck}") if @verbose
- File.delete(lck)
- rescue
- trace
- end
- end
-
- def kill
- @threads.each do |t|
- t.kill rescue false
- end
- end
-
- def restart
- @files = Array.new
- @skips = Hash.new
- @stats = Hash.new
- kill # threads
- end
-
- def collect
- begin
- @files = Array.new
- Dir.glob("#{@work_path}/#{@@session_prefix}*.ses").each do |sessionfile|
- sessionfile = File.expand_path(sessionfile)
- begin
- if @threads.key?(sessionfile) then
- # leave alone
- elsif (Time.now - File.mtime(sessionfile)) > @max_age.to_i then
- # delete
- FileUtils::rm_r(sessionfile) rescue false
- FileUtils::rm_r(sessionfile.sub(/ses$/,'dir')) rescue false
- FileUtils::rm_r(sessionfile.sub(/ses$/,'lck')) rescue false
- begin
- FileUtils::rm_r(File.join(@cache_path, File.basename(sessionfile.sub(/ses$/,'dir'))))
- rescue
- report("watchdog: problems in cache cleanup #{$!}") # if @verbose
- end
- @stats.delete(sessionfile) rescue false
- @skips.delete(sessionfile) rescue false
- report("watchdog: removing session #{sessionfile}") if @verbose
- elsif ! @skips.key?(sessionfile) then
- @files << sessionfile
- report("watchdog: checking session #{sessionfile}") if @verbose
- end
- rescue
- # maybe purged in the meantime
- end
- end
- rescue
- if File.directory?(@work_path) then
- @files = Array.new
- else
- # maybe dir is deleted (manual cleanup)
- restart
- end
- end
- begin
- Dir.glob("#{@cache_path}/*.dir").each do |dirname|
- begin
- if (Time.now - File.mtime(dirname)) > @max_age.to_i then
- begin
- FileUtils::rm_r(dirname)
- rescue
- report("watchdog: problems in cache cleanup #{$!}") # if @verbose
- end
- end
- rescue
- # maybe purged in the meantime
- end
- end
- rescue
- end
- end
-
- def purge
- begin
- Dir.glob("#{@work_path}/#{@@session_prefix}*").each do |sessionfile|
- sessionfile = File.expand_path(sessionfile)
- begin
- if (Time.now - File.mtime(sessionfile)) > @max_age.to_i then
- begin
- if FileTest.directory?(sessionfile) then
- FileUtils::rm_r(sessionfile)
- else
- File.delete(sessionfile)
- end
- rescue
- end
- begin
- @stats.delete(sessionfile)
- @skips.delete(sessionfile)
- rescue
- end
- report("watchdog: purging session #{sessionfile}") if @verbose
- end
- rescue
- # maybe purged in the meantime
- end
- end
- rescue
- end
- end
-
- def loaded_session_data(filename)
- begin
- if data = IO.readlines(filename) then
- return data if (data.first =~ /^[\#\%]\s*#{@@session_begin}/o) && (data.last =~ /^[\#\%]\s*#{@@session_end}/o)
- end
- rescue
- trace
- end
- return nil
- end
-
- def load(sessionfile)
- # we assume that we get an exception when the file is locked
- begin
- if data = loaded_session_data(sessionfile) then
- report("watchdog: loading session #{sessionfile}") if @verbose
- vars = Hash.new
- data.each do |line|
- begin
- if line.chomp =~ /^(.*?)\s*\=\s*(.*?)\s*$/o then
- key, value = $1, $2
- vars[key] = value
- end
- rescue
- end
- end
- return vars
- else
- return nil
- end
- rescue
- trace
- return nil
- end
- end
-
- def save(sessionfile, vars)
- begin
- report("watchdog: saving session #{sessionfile}") if @verbose
- if @stats.key?(sessionfile) then
- @stats[sessionfile] = File.mtime(sessionfile)
- elsif @stats[sessionfile] == File.mtime(sessionfile) then
- else
- # construct data first
- str = "\# #{@@session_begin}\n"
- for k,v in vars do
- str << "#{k}=#{v}\n"
- end
- str << "\# #{@@session_end}\n"
- # save as fast as possible
- File.open(sessionfile,'w') do |f|
- f.puts(str)
- end
- end
- rescue
- report("watchdog: unable to save session #{sessionfile}") if @verbose
- trace
- return false
- else
- return true
- end
- end
-
- def launch
- begin
- @files.each do |sessionfile|
- if @threads.length < @max_threads then
- begin
- if ! @skips.key?(sessionfile) && (vars = load(sessionfile)) then
- if (id = vars['id']) && vars['status'] then
- if vars['status'] == 'running: background' then
- @last_action = Time.now
- @threads[sessionfile] = Thread.new(vars, sessionfile) do |vars, sessionfile|
- begin
- report("watchdog: starting thread #{sessionfile}") if @verbose
- dir = File.expand_path(sessionfile.sub(/ses$/,'dir'))
- lck = File.expand_path(sessionfile.sub(/ses$/,'lck'))
- start_of_run = Time.now
- start_of_job = start_of_run.dup
- max_time = @max_age
- begin
- start_of_job = vars['starttime'].to_i || start_of_run
- start_of_job = start_of_run if start_of_job == 0
- rescue
- start_of_job = Time.now
- end
- begin
- max_runtime = vars['maxtime'].to_i || @max_age
- max_runtime = @max_age if max_runtime == 0
- max_runtime = max_runtime - (Time.now.to_i - start_of_job.to_i)
- rescue
- max_runtime = @max_age
- end
- lock(lck)
- if max_runtime > 0 then
- command = vars['command'] || ''
- if ! command.empty? then
- vars['status'] = 'running: busy'
- vars['timeout'] = max_runtime.to_s
- save(sessionfile,vars)
- timeout(max_runtime) do
- begin
- command = command_string(dir,command,'process.log')
- report("watchdog: #{command}") if @verbose
- system(command)
- rescue TimeoutError
- vars['status'] = 'running: timeout'
- rescue
- trace
- vars['status'] = 'running: aborted'
- else
- vars['status'] = 'running: finished'
- vars['runtime'] = sprintf("%.02f",(Time.now - start_of_run))
- vars['endtime'] = Time.now.to_i.to_s
- end
- end
- else
- vars['status'] = 'running: aborted' # no command
- end
- else
- vars['status'] = 'running: aborted' # not enough time
- end
- save(sessionfile,vars)
- unlock(lck)
- report("watchdog: ending thread #{sessionfile}") if @verbose
- @threads.delete(sessionfile)
- rescue
- trace
- end
- end
- else
- report("watchdog: skipping - id (#{vars['id']}) / status (#{vars['status']})") if @verbose
- end
- if @onlyonerun then
- @skips[sessionfile] = true
- else
- @skips.delete(sessionfile)
- end
- else
- # not yet ok
- end
- else
- # maybe a lock
- end
- rescue
- trace
- end
- else
- break
- end
- end
- rescue
- trace
- end
- end
-
- def wait
- begin
- # report(Time.now.to_s) if @verbose
- loop do
- @threads.delete_if do |k,v|
- begin
- v == nil || v.stop?
- rescue
- true
- else
- false
- end
- end
- if @threads.length == @max_threads then
- if @delay > @max_threads then
- sleep(@delay)
- else
- sleep(@max_threads)
- end
- break if @@fast_wait_loop
- else
- sleep(@delay)
- break
- end
- end
- rescue
- trace
- end
- end
-
- def check
- begin
- time = Time.now
- if (time - @last_action) > @@check_factor*@max_age then
- report("watchdog: cleanup") if @verbose
- @stats = Hash.new
- @last_action = time
- kill
- end
- rescue
- trace
- end
- end
-
- def cycle
- loop do
- begin
- collect
- launch
- wait
- check
- rescue
- trace
- report("watchdog: some problem, restarting loop")
- end
- end
- end
-
-end
-
-class Commands
-
- include CommandBase
-
- def watch
- if watch = setup then
- watch.cycle
- else
- report("provide valid work path")
- end
- end
- def main
- watch
- end
-
- private
-
- def setup
- if watch = Watch.new(logger) then
- watch.root_path = @commandline.option('root')
- watch.work_path = @commandline.option('work')
- watch.cache_path = @commandline.option('cache')
- watch.create = @commandline.option('create')
- watch.verbose = @commandline.option('verbose')
- begin
- watch.max_threads = @commandline.option('threads').to_i
- rescue
- watch.max_threads = 5
- end
- watch.setup
- end
- return watch
- end
-
-end
-
-logger = Logger.new(banner.shift)
-commandline = CommandLine.new
-
-commandline.registervalue('root', '')
-commandline.registervalue('work', '')
-commandline.registervalue('cache', '')
-commandline.registervalue('threads', '5')
-
-commandline.registerflag('create')
-
-commandline.registeraction('watch', '[--work=path] [--root=path] [--create]')
-
-commandline.registerflag('verbose')
-commandline.registeraction('help')
-commandline.registeraction('version')
-
-commandline.expand
-
-Commands.new(commandline,logger,banner).send(commandline.action || 'main')
diff --git a/scripts/context/stubs/mswin/ctxtools.bat b/scripts/context/stubs/mswin/ctxtools.bat
index f1f5e019e..8047c9b68 100755
--- a/scripts/context/stubs/mswin/ctxtools.bat
+++ b/scripts/context/stubs/mswin/ctxtools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart ctxtools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute ctxtools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/exatools.bat b/scripts/context/stubs/mswin/exatools.bat
deleted file mode 100755
index 57f798e82..000000000
--- a/scripts/context/stubs/mswin/exatools.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-texmfstart exatools.rb %*
diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua
new file mode 100644
index 000000000..aacdbd16d
--- /dev/null
+++ b/scripts/context/stubs/mswin/luatools.lua
@@ -0,0 +1,6977 @@
+#!/usr/bin/env texlua
+
+if not modules then modules = { } end modules ['luatools'] = {
+ version = 1.001,
+ comment = "companion to context.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+-- one can make a stub:
+--
+-- #!/bin/sh
+-- env LUATEXDIR=/....../texmf/scripts/context/lua texlua luatools.lua "$@"
+
+-- Although this script is part of the ConTeXt distribution it is
+-- relatively indepent of ConTeXt. The same is true for some of
+-- the luat files. We may may make them even less dependent in
+-- the future. As long as Luatex is under development the
+-- interfaces and names of functions may change.
+
+-- For the sake of independence we optionally can merge the library
+-- code here. It's too much code, but that does not harm. Much of the
+-- library code is used elsewhere. We don't want dependencies on
+-- Lua library paths simply because these scripts are located in the
+-- texmf tree and not in some Lua path. Normally this merge is not
+-- needed when texmfstart is used, or when the proper stub is used or
+-- when (windows) suffix binding is active.
+
+texlua = true
+
+-- begin library merge
+
+
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
+
+if not string.split then
+
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
+ end
+ end
+
+end
+
+local chr_to_esc = {
+ ["%"] = "%%",
+ ["."] = "%.",
+ ["+"] = "%+", ["-"] = "%-", ["*"] = "%*",
+ ["^"] = "%^", ["$"] = "%$",
+ ["["] = "%[", ["]"] = "%]",
+ ["("] = "%(", [")"] = "%)",
+ ["{"] = "%{", ["}"] = "%}"
+}
+
+string.chr_to_esc = chr_to_esc
+
+function string:esc() -- variant 2
+ return (gsub(self,"(.)",chr_to_esc))
+end
+
+function string:unquote()
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
+end
+
+function string:quote() -- we could use format("%q")
+ return '"' .. self:unquote() .. '"'
+end
+
+function string:count(pattern) -- variant 3
+ local n = 0
+ for _ in gmatch(self,pattern) do
+ n = n + 1
+ end
+ return n
+end
+
+function string:limit(n,sentinel)
+ if #self > n then
+ sentinel = sentinel or " ..."
+ return sub(self,1,(n-#sentinel)) .. sentinel
+ else
+ return self
+ end
+end
+
+function string:strip()
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
+end
+
+function string:is_empty()
+ return not find(find,"%S")
+end
+
+function string:enhance(pattern,action)
+ local ok, n = true, 0
+ while ok do
+ ok = false
+ self = gsub(self,pattern, function(...)
+ ok, n = true, n + 1
+ return action(...)
+ end)
+ end
+ return self, n
+end
+
+local chr_to_hex, hex_to_chr = { }, { }
+
+for i=0,255 do
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
+end
+
+function string:to_hex()
+ return (gsub(self or "","(.)",chr_to_hex))
+end
+
+function string:from_hex()
+ return (gsub(self or "","(..)",hex_to_chr))
+end
+
+if not string.characters then
+
+ local function nextchar(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, str:sub(index,index)
+ end
+ function string:characters()
+ return nextchar, self, 0
+ end
+ local function nextbyte(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
+ end
+ function string:bytes()
+ return nextbyte, self, 0
+ end
+
+end
+
+-- we can use format for this (neg n)
+
+function string:rpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self .. self.rep(chr or " ",m)
+ else
+ return self
+ end
+end
+
+function string:lpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self.rep(chr or " ",m) .. self
+ else
+ return self
+ end
+end
+
+string.padd = string.rpadd
+
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
+end
+
+--~ print(is_number("1"))
+--~ print(is_number("1.1"))
+--~ print(is_number(".1"))
+--~ print(is_number("-0.1"))
+--~ print(is_number("+0.1"))
+--~ print(is_number("-.1"))
+--~ print(is_number("+.1"))
+
+function string:split_settings() -- no {} handling, see l-aux for lpeg variant
+ if find(self,"=") then
+ local t = { }
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return nil
+ end
+end
+
+local patterns_escapes = {
+ ["-"] = "%-",
+ ["."] = "%.",
+ ["+"] = "%+",
+ ["*"] = "%*",
+ ["%"] = "%%",
+ ["("] = "%)",
+ [")"] = "%)",
+ ["["] = "%[",
+ ["]"] = "%]",
+}
+
+function string:pattesc()
+ return (gsub(self,".",patterns_escapes))
+end
+
+function string:tohash()
+ local t = { }
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
+ t[s] = true
+ end
+ return t
+end
+
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
+
+--~ l-lpeg.lua :
+
+--~ lpeg.digit = lpeg.R('09')^1
+--~ lpeg.sign = lpeg.S('+-')^1
+--~ lpeg.cardinal = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.integer = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.float = lpeg.P(lpeg.sign^0 * lpeg.digit^0 * lpeg.P('.') * lpeg.digit^1)
+--~ lpeg.number = lpeg.float + lpeg.integer
+--~ lpeg.oct = lpeg.P("0") * lpeg.R('07')^1
+--~ lpeg.hex = lpeg.P("0x") * (lpeg.R('09') + lpeg.R('AF'))^1
+--~ lpeg.uppercase = lpeg.P("AZ")
+--~ lpeg.lowercase = lpeg.P("az")
+
+--~ lpeg.eol = lpeg.S('\r\n\f')^1 -- includes formfeed
+--~ lpeg.space = lpeg.S(' ')^1
+--~ lpeg.nonspace = lpeg.P(1-lpeg.space)^1
+--~ lpeg.whitespace = lpeg.S(' \r\n\f\t')^1
+--~ lpeg.nonwhitespace = lpeg.P(1-lpeg.whitespace)^1
+
+local hash = { }
+
+function lpeg.anywhere(pattern) --slightly adapted from website
+ return P { P(pattern) + 1 * lpeg.V(1) }
+end
+
+function lpeg.startswith(pattern) --slightly adapted
+ return P(pattern)
+end
+
+function lpeg.splitter(pattern, action)
+ return (((1-P(pattern))^1)/action+1)^0
+end
+
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
+local newline = crlf + cr + lf
+local spacing = space^0 * newline
+
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
+local content = (empty + nonempty)^1
+
+local capture = Ct(content^0)
+
+function string:splitlines()
+ return capture:match(self)
+end
+
+lpeg.linebyline = content -- better make a sublibrary
+
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps")) -- oeps
+
+local splitters_s, splitters_m = { }, { }
+
+local function splitat(separator,single)
+ local splitter = (single and splitters_s[separator]) or splitters_m[separator]
+ if not splitter then
+ separator = P(separator)
+ if single then
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
+ splitters_s[separator] = splitter
+ else
+ local other = C((1 - separator)^0)
+ splitter = other * (separator * other)^0
+ splitters_m[separator] = splitter
+ end
+ end
+ return splitter
+end
+
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+table.join = table.concat
+
+local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
+local getmetatable, setmetatable = getmetatable, setmetatable
+local type, next, tostring, ipairs = type, next, tostring, ipairs
+
+function table.strip(tab)
+ local lst = { }
+ for i=1,#tab do
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
+ if s == "" then
+ -- skip this one
+ else
+ lst[#lst+1] = s
+ end
+ end
+ return lst
+end
+
+local function sortedkeys(tab)
+ local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ if kind == 3 then
+ -- no further check
+ else
+ local tkey = type(key)
+ if tkey == "string" then
+ -- if kind == 2 then kind = 3 else kind = 1 end
+ kind = (kind == 2 and 3) or 1
+ elseif tkey == "number" then
+ -- if kind == 1 then kind = 3 else kind = 2 end
+ kind = (kind == 1 and 3) or 2
+ else
+ kind = 3
+ end
+ end
+ end
+ if kind == 0 or kind == 3 then
+ sort(srt,function(a,b) return (tostring(a) < tostring(b)) end)
+ else
+ sort(srt)
+ end
+ return srt
+end
+
+local function sortedhashkeys(tab) -- fast one
+ local srt = { }
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ end
+ sort(srt)
+ return srt
+end
+
+table.sortedkeys = sortedkeys
+table.sortedhashkeys = sortedhashkeys
+
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
+function table.append(t, list)
+ for _,v in next, list do
+ insert(t,v)
+ end
+end
+
+function table.prepend(t, list)
+ for k,v in next, list do
+ insert(t,k,v)
+ end
+end
+
+function table.merge(t, ...) -- first one is target
+ t = t or {}
+ local lst = {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ t[k] = v
+ end
+ end
+ return t
+end
+
+function table.merged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ tmp[k] = v
+ end
+ end
+ return tmp
+end
+
+function table.imerge(t, ...)
+ local lst = {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ t[#t+1] = nst[j]
+ end
+ end
+ return t
+end
+
+function table.imerged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ tmp[#tmp+1] = nst[j]
+ end
+ end
+ return tmp
+end
+
+local function fastcopy(old) -- fast one
+ if old then
+ local new = { }
+ for k,v in next, old do
+ if type(v) == "table" then
+ new[k] = fastcopy(v) -- was just table.copy
+ else
+ new[k] = v
+ end
+ end
+ -- optional second arg
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+local function copy(t, tables) -- taken from lua wiki, slightly adapted
+ tables = tables or { }
+ local tcopy = {}
+ if not tables[t] then
+ tables[t] = tcopy
+ end
+ for i,v in next, t do -- brrr, what happens with sparse indexed
+ if type(i) == "table" then
+ if tables[i] then
+ i = tables[i]
+ else
+ i = copy(i, tables)
+ end
+ end
+ if type(v) ~= "table" then
+ tcopy[i] = v
+ elseif tables[v] then
+ tcopy[i] = tables[v]
+ else
+ tcopy[i] = copy(v, tables)
+ end
+ end
+ local mt = getmetatable(t)
+ if mt then
+ setmetatable(tcopy,mt)
+ end
+ return tcopy
+end
+
+table.fastcopy = fastcopy
+table.copy = copy
+
+-- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+
+function table.sub(t,i,j)
+ return { unpack(t,i,j) }
+end
+
+function table.replace(a,b)
+ for k,v in next, b do
+ a[k] = v
+ end
+end
+
+-- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice)
+
+function table.is_empty(t)
+ return not t or not next(t)
+end
+
+function table.one_entry(t)
+ local n = next(t)
+ return n and not next(t,n)
+end
+
+function table.starts_at(t)
+ return ipairs(t,1)(t,0)
+end
+
+function table.tohash(t,value)
+ local h = { }
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
+ end
+ return h
+end
+
+function table.fromhash(t)
+ local h = { }
+ for k, v in next, t do -- no ipairs here
+ if v then h[#h+1] = k end
+ end
+ return h
+end
+
+--~ print(table.serialize(t), "\n")
+--~ print(table.serialize(t,"name"), "\n")
+--~ print(table.serialize(t,false), "\n")
+--~ print(table.serialize(t,true), "\n")
+--~ print(table.serialize(t,"name",true), "\n")
+--~ print(table.serialize(t,"name",true,true), "\n")
+
+table.serialize_functions = true
+table.serialize_compact = true
+table.serialize_inline = true
+
+local noquotes, hexify, handle, reduce, compact, inline, functions
+
+local reserved = table.tohash { -- intercept a language flaw, no reserved words as key
+ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if',
+ 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
+}
+
+local function simple_table(t)
+ if #t > 0 then
+ local n = 0
+ for _,v in next, t do
+ n = n + 1
+ end
+ if n == #t then
+ local tt = { }
+ for i=1,#t do
+ local v = t[i]
+ local tv = type(v)
+ if tv == "number" then
+ if hexify then
+ tt[#tt+1] = format("0x%04X",v)
+ else
+ tt[#tt+1] = tostring(v) -- tostring not needed
+ end
+ elseif tv == "boolean" then
+ tt[#tt+1] = tostring(v)
+ elseif tv == "string" then
+ tt[#tt+1] = format("%q",v)
+ else
+ tt = nil
+ break
+ end
+ end
+ return tt
+ end
+ end
+ return nil
+end
+
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
+local function do_serialize(root,name,depth,level,indexed)
+ if level > 0 then
+ depth = depth .. " "
+ if indexed then
+ handle(format("%s{",depth))
+ elseif name then
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
+ else
+ handle(format("%s{",depth))
+ end
+ end
+ if root and next(root) then
+ local first, last = nil, 0 -- #root cannot be trusted here
+ if compact then
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
+ if not first then first = k end
+ last = last + 1
+ end
+ end
+ local sk = sortedkeys(root)
+ for i=1,#sk do
+ local k = sk[i]
+ local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
+ local t = type(v)
+ if compact and first and type(k) == "number" and k >= first and k <= last then
+ if t == "number" then
+ if hexify then
+ handle(format("%s 0x%04X,",depth,v))
+ else
+ handle(format("%s %s,",depth,v))
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
+ else
+ handle(format("%s %q,",depth,v))
+ end
+ elseif t == "table" then
+ if not next(v) then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
+ local st = simple_table(v)
+ if st then
+ handle(format("%s { %s },",depth,concat(st,", ")))
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ elseif t == "boolean" then
+ handle(format("%s %s,",depth,tostring(v)))
+ elseif t == "function" then
+ if functions then
+ handle(format('%s loadstring(%q),',depth,dump(v)))
+ else
+ handle(format('%s "function",',depth))
+ end
+ else
+ handle(format("%s %q,",depth,tostring(v)))
+ end
+ elseif k == "__p__" then -- parent
+ if false then
+ handle(format("%s __p__=nil,",depth))
+ end
+ elseif t == "number" then
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
+ else
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
+ end
+ elseif t == "table" then
+ if not next(v) then
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
+ elseif inline then
+ local st = simple_table(v)
+ if st then
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ elseif t == "boolean" then
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
+ elseif t == "function" then
+ if functions then
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
+ end
+ --~ end
+ end
+ end
+ if level > 0 then
+ handle(format("%s},",depth))
+ end
+end
+
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
+local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
+ noquotes = _noquotes
+ hexify = _hexify
+ handle = _handle or print
+ reduce = _reduce or false
+ compact = table.serialize_compact
+ inline = compact and table.serialize_inline
+ functions = table.serialize_functions
+ local tname = type(name)
+ if tname == "string" then
+ if name == "return" then
+ handle("return {")
+ else
+ handle(name .. "={")
+ end
+ elseif tname == "number" then
+ if hexify then
+ handle(format("[0x%04X]={",name))
+ else
+ handle("[" .. name .. "]={")
+ end
+ elseif tname == "boolean" then
+ if name then
+ handle("return {")
+ else
+ handle("{")
+ end
+ else
+ handle("t={")
+ end
+ if root and next(root) then
+ do_serialize(root,name,"",0,indexed)
+ end
+ handle("}")
+end
+
+--~ name:
+--~
+--~ true : return { }
+--~ false : { }
+--~ nil : t = { }
+--~ string : string = { }
+--~ 'return' : return { }
+--~ number : [number] = { }
+
+function table.serialize(root,name,reduce,noquotes,hexify)
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ return concat(t,"\n")
+end
+
+function table.tohandle(handle,root,name,reduce,noquotes,hexify)
+ serialize(root,name,handle,reduce,noquotes,hexify)
+end
+
+-- sometimes tables are real use (zapfino extra pro is some 85M) in which
+-- case a stepwise serialization is nice; actually, we could consider:
+--
+-- for line in table.serializer(root,name,reduce,noquotes) do
+-- ...(line)
+-- end
+--
+-- so this is on the todo list
+
+table.tofile_maxtab = 2*1024
+
+function table.tofile(filename,root,name,reduce,noquotes,hexify)
+ local f = io.open(filename,'w')
+ if f then
+ local maxtab = table.tofile_maxtab
+ if maxtab > 1 then
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ if #t > maxtab then
+ f:write(concat(t,"\n"),"\n") -- hm, write(sometable) should be nice
+ t = { }
+ end
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ f:write(concat(t,"\n"),"\n")
+ else
+ local function flush(s)
+ f:write(s,"\n")
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ end
+ f:close()
+ end
+end
+
+local function flatten(t,f,complete)
+ for i=1,#t do
+ local v = t[i]
+ if type(v) == "table" then
+ if complete or type(v[1]) == "table" then
+ flatten(v,f,complete)
+ else
+ f[#f+1] = v
+ end
+ else
+ f[#f+1] = v
+ end
+ end
+end
+
+function table.flatten(t)
+ local f = { }
+ flatten(t,f,true)
+ return f
+end
+
+function table.unnest(t) -- bad name
+ local f = { }
+ flatten(t,f,false)
+ return f
+end
+
+table.flatten_one_level = table.unnest
+
+-- the next three may disappear
+
+function table.remove_value(t,value) -- todo: n
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ remove(t,i)
+ -- remove all, so no: return
+ end
+ end
+ end
+end
+
+function table.insert_before_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i,str)
+ return
+ end
+ end
+ end
+ insert(t,1,str)
+ elseif value then
+ insert(t,1,value)
+ end
+end
+
+function table.insert_after_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i+1,str)
+ return
+ end
+ end
+ end
+ t[#t+1] = str
+ elseif value then
+ t[#t+1] = value
+ end
+end
+
+local function are_equal(a,b,n,m) -- indexed
+ if #a == #b then
+ n = n or 1
+ m = m or #a
+ for i=n,m do
+ local ai, bi = a[i], b[i]
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+ else
+ return false
+ end
+end
+
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
+function table.compact(t)
+ if t then
+ for k,v in next, t do
+ if not next(v) then
+ t[k] = nil
+ end
+ end
+ end
+end
+
+function table.contains(t, v)
+ if t then
+ for i=1, #t do
+ if t[i] == v then
+ return i
+ end
+ end
+ end
+ return false
+end
+
+function table.count(t)
+ local n, e = 0, next(t)
+ while e do
+ n, e = n + 1, next(t,e)
+ end
+ return n
+end
+
+function table.swapped(t)
+ local s = { }
+ for k, v in next, t do
+ s[v] = k
+ end
+ return s
+end
+
+--~ function table.are_equal(a,b)
+--~ return table.serialize(a) == table.serialize(b)
+--~ end
+
+function table.clone(t,p) -- t is optional or nil or table
+ if not p then
+ t, p = { }, t or { }
+ elseif not t then
+ t = { }
+ end
+ setmetatable(t, { __index = function(_,key) return p[key] end })
+ return t
+end
+
+function table.hexed(t,seperator)
+ local tt = { }
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
+ return concat(tt,seperator or " ")
+end
+
+function table.reverse_hash(h)
+ local r = { }
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
+ end
+ return r
+end
+
+function table.reverse(t)
+ local tt = { }
+ if #t > 0 then
+ for i=#t,1,-1 do
+ tt[#tt+1] = t[i]
+ end
+ end
+ return tt
+end
+
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local byte = string.byte
+
+if string.find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator = "\\", ";"
+else
+ io.fileseparator, io.pathseparator = "/" , ":"
+end
+
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
+ if f then
+ local data = f:read('*all')
+ -- garbagecollector.check(data)
+ f:close()
+ return data
+ else
+ return nil
+ end
+end
+
+function io.savedata(filename,data,joiner)
+ local f = io.open(filename,"wb")
+ if f then
+ if type(data) == "table" then
+ f:write(table.join(data,joiner or ""))
+ elseif type(data) == "function" then
+ data(f)
+ else
+ f:write(data)
+ end
+ f:close()
+ return true
+ else
+ return false
+ end
+end
+
+function io.exists(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return false
+ else
+ assert(f:close())
+ return true
+ end
+end
+
+function io.size(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return 0
+ else
+ local s = f:seek("end")
+ assert(f:close())
+ return s
+ end
+end
+
+function io.noflines(f)
+ local n = 0
+ for _ in f:lines() do
+ n = n + 1
+ end
+ f:seek('set',0)
+ return n
+end
+
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
+ end
+}
+
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
+ end
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
+ else
+ return nil, nil
+ end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
+ else
+ return nil, nil
+ end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
+ end
+}
+
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+function io.ask(question,default,options)
+ while true do
+ io.write(question)
+ if options then
+ io.write(string.format(" [%s]",table.concat(options,"|")))
+ end
+ if default then
+ io.write(string.format(" [%s]",default))
+ end
+ io.write(string.format(" "))
+ local answer = io.read()
+ answer = answer:gsub("^%s*(.*)%s*$","%1")
+ if answer == "" and default then
+ return default
+ elseif not options then
+ return answer
+ else
+ for _,v in pairs(options) do
+ if v == answer then
+ return answer
+ end
+ end
+ local pattern = "^" .. answer
+ for _,v in pairs(options) do
+ if v:find(pattern) then
+ return v
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+number = number or { }
+
+-- a,b,c,d,e,f = number.toset(100101)
+
+function number.toset(n)
+ return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
+end
+
+function number.toevenhex(n)
+ local s = format("%X",n)
+ if #s % 2 == 0 then
+ return s
+ else
+ return "0" .. s
+ end
+end
+
+-- the lpeg way is slower on 8 digits, but faster on 4 digits, some 7.5%
+-- on
+--
+-- for i=1,1000000 do
+-- local a,b,c,d,e,f,g,h = number.toset(12345678)
+-- local a,b,c,d = number.toset(1234)
+-- local a,b,c = number.toset(123)
+-- end
+--
+-- of course dedicated "(.)(.)(.)(.)" matches are even faster
+
+local one = lpeg.C(1-lpeg.S(''))^1
+
+function number.toset(n)
+ return one:match(tostring(n))
+end
+
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+set = set or { }
+
+local nums = { }
+local tabs = { }
+local concat = table.concat
+
+set.create = table.tohash
+
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
+ end
+ end
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
+ end
+ return nums[s]
+ else
+ return 0
+ end
+end
+
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
+ end
+end
+
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
+end
+
+--~ local c = set.create{'aap','noot','mies'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ local c = set.create{'zus','wim','jet'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ print(t['jet'])
+--~ print(set.contains(t,'jet'))
+--~ print(set.contains(t,'aap'))
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+function os.resultof(command)
+ return io.popen(command,"r"):read("*all")
+end
+
+if not os.exec then os.exec = os.execute end
+if not os.spawn then os.spawn = os.execute end
+
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+
+if not io.fileseparator then
+ if find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ else
+ io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ end
+end
+
+os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+
+function os.launch(str)
+ if os.platform == "windows" then
+ os.execute("start " .. str) -- os.spawn ?
+ else
+ os.execute(str .. " &") -- os.spawn ?
+ end
+end
+
+if not os.setenv then
+ function os.setenv() return false end
+end
+
+if not os.times then
+ -- utime = user time
+ -- stime = system time
+ -- cutime = children user time
+ -- cstime = children system time
+ function os.times()
+ return {
+ utime = os.gettimeofday(), -- user
+ stime = 0, -- system
+ cutime = 0, -- children user
+ cstime = 0, -- children system
+ }
+ end
+end
+
+os.gettimeofday = os.gettimeofday or os.clock
+
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
+end
+
+--~ print(os.gettimeofday()-os.time())
+--~ os.sleep(1.234)
+--~ print (">>",os.runtime())
+--~ print(os.date("%H:%M:%S",os.gettimeofday()))
+--~ print(os.date("%H:%M:%S",os.time()))
+
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
+
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- needs a cleanup
+
+file = file or { }
+
+local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
+end
+
+function file.addsuffix(filename, suffix)
+ if not find(filename,"%.[%a%d]+$") then
+ return filename .. "." .. suffix
+ else
+ return filename
+ end
+end
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
+
+function file.dirname(name)
+ return match(name,"^(.+)[/\\].-$") or ""
+end
+
+function file.basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
+end
+
+function file.nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+end
+
+function file.extname(name)
+ return match(name,"^.+%.([^/\\]-)$") or ""
+end
+
+file.suffix = file.extname
+
+--~ print(file.join("x/","/y"))
+--~ print(file.join("http://","/y"))
+--~ print(file.join("http://a","/y"))
+--~ print(file.join("http:///a","/y"))
+--~ print(file.join("//nas-1","/y"))
+
+function file.join(...)
+ local pth = concat({...},"/")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ a, b = match(pth,"^(//)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ return (gsub(pth,"//+","/"))
+end
+
+function file.iswritable(name)
+ local a = lfs.attributes(name)
+ if a and a.permissions:sub(2,2) == "w" then
+ return true
+ else
+ name = file.dirname(name) or "."
+ if name == "" then name = "." end
+ a = lfs.attributes(name)
+ return a and a.permissions:sub(2,2) == "w"
+ end
+end
+
+function file.isreadable(name)
+ local a = lfs.attributes(name)
+ return a and a.permissions:sub(1,1) == "r"
+end
+
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
+
+-- todo: lpeg
+
+function file.split_path(str)
+ local t = { }
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
+ if name ~= "" then
+ t[#t+1] = gsub(name,"\001",":")
+ end
+ end
+ return t
+end
+
+function file.join_path(tab)
+ return concat(tab,io.pathseparator) -- can have trailing //
+end
+
+function file.collapse_path(str)
+ str = gsub(str,"/%./","/")
+ local n, m = 1, 1
+ while n > 0 or m > 0 do
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
+ end
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
+ if str == "" then str = "." end
+ return str
+end
+
+--~ print(file.collapse_path("a/./b/.."))
+--~ print(file.collapse_path("a/aa/../b/bb"))
+--~ print(file.collapse_path("a/../.."))
+--~ print(file.collapse_path("a/.././././b/.."))
+--~ print(file.collapse_path("a/./././b/.."))
+--~ print(file.collapse_path("a/b/c/../.."))
+
+function file.robustname(str)
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
+end
+
+file.readdata = io.loaddata
+file.savedata = io.savedata
+
+function file.copy(oldname,newname)
+ file.savedata(newname,io.loaddata(oldname))
+end
+
+-- lpeg variants, slightly faster, not always
+
+--~ local period = lpeg.P(".")
+--~ local slashes = lpeg.S("\\/")
+--~ local noperiod = 1-period
+--~ local noslashes = 1-slashes
+--~ local name = noperiod^1
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.C(noperiod^1) * -1
+
+--~ function file.extname(name)
+--~ return pattern:match(name) or ""
+--~ end
+
+--~ local pattern = lpeg.Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+
+--~ function file.removesuffix(name)
+--~ return pattern:match(name)
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
+
+--~ function file.basename(name)
+--~ return pattern:match(name) or name
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.Cp() * noslashes^1 * -1
+
+--~ function file.dirname(name)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2)
+--~ else
+--~ return ""
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.addsuffix(name, suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.replacesuffix(name,suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2) .. "." .. suffix
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * lpeg.Cp() * ((noperiod^1 * period)^1 * lpeg.Cp() + lpeg.P(true)) * noperiod^1 * -1
+
+--~ function file.nameonly(name)
+--~ local a, b = pattern:match(name)
+--~ if b then
+--~ return name:sub(a,b-2)
+--~ elseif a then
+--~ return name:sub(a)
+--~ else
+--~ return name
+--~ end
+--~ end
+
+--~ local test = file.extname
+--~ local test = file.basename
+--~ local test = file.dirname
+--~ local test = file.addsuffix
+--~ local test = file.replacesuffix
+--~ local test = file.nameonly
+
+--~ print(1,test("./a/b/c/abd.def.xxx","!!!"))
+--~ print(2,test("./../b/c/abd.def.xxx","!!!"))
+--~ print(3,test("a/b/c/abd.def.xxx","!!!"))
+--~ print(4,test("a/b/c/def.xxx","!!!"))
+--~ print(5,test("a/b/c/def","!!!"))
+--~ print(6,test("def","!!!"))
+--~ print(7,test("def.xxx","!!!"))
+
+--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEXsum(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-url'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local char, gmatch = string.char, string.gmatch
+local tonumber, type = tonumber, type
+
+-- from the spec (on the web):
+--
+-- foo://example.com:8042/over/there?name=ferret#nose
+-- \_/ \______________/\_________/ \_________/ \__/
+-- | | | | |
+-- scheme authority path query fragment
+-- | _____________________|__
+-- / \ / \
+-- urn:example:animal:ferret:nose
+
+url = url or { }
+
+local function tochar(s)
+ return char(tonumber(s,16))
+end
+
+local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
+
+local hexdigit = lpeg.R("09","AF","af")
+local plus = lpeg.P("+")
+local escaped = (plus / " ") + (percent * lpeg.C(hexdigit * hexdigit) / tochar)
+
+local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
+local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
+local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
+local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
+local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
+
+local parser = lpeg.Ct(scheme * authority * path * query * fragment)
+
+function url.split(str)
+ return (type(str) == "string" and parser:match(str)) or str
+end
+
+function url.hashed(str)
+ local s = url.split(str)
+ return {
+ scheme = (s[1] ~= "" and s[1]) or "file",
+ authority = s[2],
+ path = s[3],
+ query = s[4],
+ fragment = s[5],
+ original = str
+ }
+end
+
+function url.filename(filename)
+ local t = url.hashed(filename)
+ return (t.scheme == "file" and t.path:gsub("^/([a-zA-Z])([:|])/)","%1:")) or filename
+end
+
+function url.query(str)
+ if type(str) == "string" then
+ local t = { }
+ for k, v in gmatch(str,"([^&=]*)=([^&=]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return str
+ end
+end
+
+--~ print(url.filename("file:///c:/oeps.txt"))
+--~ print(url.filename("c:/oeps.txt"))
+--~ print(url.filename("file:///oeps.txt"))
+--~ print(url.filename("file:///etc/test.txt"))
+--~ print(url.filename("/oeps.txt"))
+
+--~ from the spec on the web (sort of):
+--~
+--~ function test(str)
+--~ print(table.serialize(url.hashed(str)))
+--~ end
+--~
+--~ test("%56pass%20words")
+--~ test("file:///c:/oeps.txt")
+--~ test("file:///c|/oeps.txt")
+--~ test("file:///etc/oeps.txt")
+--~ test("file://./etc/oeps.txt")
+--~ test("file:////etc/oeps.txt")
+--~ test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
+--~ test("http://www.ietf.org/rfc/rfc2396.txt")
+--~ test("ldap://[2001:db8::7]/c=GB?objectClass?one#what")
+--~ test("mailto:John.Doe@example.com")
+--~ test("news:comp.infosystems.www.servers.unix")
+--~ test("tel:+1-816-555-1212")
+--~ test("telnet://192.0.2.16:80/")
+--~ test("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
+--~ test("/etc/passwords")
+--~ test("http://www.pragma-ade.com/spaced%20name")
+
+--~ test("zip:///oeps/oeps.zip#bla/bla.tex")
+--~ test("zip:///oeps/oeps.zip?bla/bla.tex")
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type = type
+local find, gmatch = string.find, string.gmatch
+
+dir = dir or { }
+
+-- optimizing for no string.find (*) does not save time
+
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
+ end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
+ end
+ end
+ end
+end
+
+dir.glob_pattern = glob_pattern
+
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
+
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
+ local t = t or { }
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
+ return t
+ else
+ return { }
+ end
+ end
+end
+
+dir.glob = glob
+
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
+
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
+ files[#files+1] = path .. "/" .. name
+ end
+ else
+ files[#files+1] = path .. "/" .. name
+ end
+ end
+ end
+ end
+ return files
+end
+
+dir.globfiles = globfiles
+
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
+
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
+
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
+
+local make_indeed = true -- false
+
+if string.find(os.getenv("PATH"),";") then
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
+ if first then
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
+ else
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
+ if first then
+ pth, drive = first .. middle, true
+ else
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
+ end
+ end
+ end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("a:"))
+--~ print(dir.mkdirs("a:/b/c"))
+--~ print(dir.mkdirs("a:b/c"))
+--~ print(dir.mkdirs("a:/bbb/c"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
+ end
+ lfs.chdir(d)
+ end
+ end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
+
+else
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
+ end
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
+ end
+
+end
+
+dir.makedirs = dir.mkdirs
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
+
+function boolean.tonumber(b)
+ if b then return 1 else return 0 end
+end
+
+function toboolean(str,tolerant)
+ if tolerant then
+ local tstr = type(str)
+ if tstr == "string" then
+ return str == "true" or str == "yes" or str == "on" or str == "1" or str == "t"
+ elseif tstr == "number" then
+ return tonumber(str) ~= 0
+ elseif tstr == "nil" then
+ return false
+ else
+ return str
+ end
+ elseif str == "true" then
+ return true
+ elseif str == "false" then
+ return false
+ else
+ return str
+ end
+end
+
+function string.is_boolean(str)
+ if type(str) == "string" then
+ if str == "true" or str == "yes" or str == "on" or str == "t" then
+ return true
+ elseif str == "false" or str == "no" or str == "off" or str == "f" then
+ return false
+ end
+ end
+ return nil
+end
+
+function boolean.alwaystrue()
+ return true
+end
+
+function boolean.falsetrue()
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-unicode'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+utf = utf or unicode.utf8
+
+local concat, utfchar, utfgsub = table.concat, utf.char, utf.gsub
+local char, byte, find, bytepairs = string.char, string.byte, string.find, string.bytepairs
+
+unicode = unicode or { }
+
+-- 0 EF BB BF UTF-8
+-- 1 FF FE UTF-16-little-endian
+-- 2 FE FF UTF-16-big-endian
+-- 3 FF FE 00 00 UTF-32-little-endian
+-- 4 00 00 FE FF UTF-32-big-endian
+
+unicode.utfname = {
+ [0] = 'utf-8',
+ [1] = 'utf-16-le',
+ [2] = 'utf-16-be',
+ [3] = 'utf-32-le',
+ [4] = 'utf-32-be'
+}
+
+function unicode.utftype(f) -- \000 fails !
+ local str = f:read(4)
+ if not str then
+ f:seek('set')
+ return 0
+ elseif find(str,"^%z%z\254\255") then
+ return 4
+ elseif find(str,"^\255\254%z%z") then
+ return 3
+ elseif find(str,"^\254\255") then
+ f:seek('set',2)
+ return 2
+ elseif find(str,"^\255\254") then
+ f:seek('set',2)
+ return 1
+ elseif find(str,"^\239\187\191") then
+ f:seek('set',3)
+ return 0
+ else
+ f:seek('set')
+ return 0
+ end
+end
+
+function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
+ local result, tmp, n, m, p = { }, { }, 0, 0, 0
+ -- lf | cr | crlf / (cr:13, lf:10)
+ local function doit()
+ if n == 10 then
+ if p ~= 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = 0
+ end
+ elseif n == 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = n
+ else
+ tmp[#tmp+1] = utfchar(n)
+ p = 0
+ end
+ end
+ for l,r in bytepairs(str) do
+ if r then
+ if endian then
+ n = l*256 + r
+ else
+ n = r*256 + l
+ end
+ if m > 0 then
+ n = (m-0xD800)*0x400 + (n-0xDC00) + 0x10000
+ m = 0
+ doit()
+ elseif n >= 0xD800 and n <= 0xDBFF then
+ m = n
+ else
+ doit()
+ end
+ end
+ end
+ if #tmp > 0 then
+ result[#result+1] = concat(tmp)
+ end
+ return result
+end
+
+function unicode.utf32_to_utf8(str, endian)
+ local result = { }
+ local tmp, n, m, p = { }, 0, -1, 0
+ -- lf | cr | crlf / (cr:13, lf:10)
+ local function doit()
+ if n == 10 then
+ if p ~= 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = 0
+ end
+ elseif n == 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = n
+ else
+ tmp[#tmp+1] = utfchar(n)
+ p = 0
+ end
+ end
+ for a,b in bytepairs(str) do
+ if a and b then
+ if m < 0 then
+ if endian then
+ m = a*256*256*256 + b*256*256
+ else
+ m = b*256 + a
+ end
+ else
+ if endian then
+ n = m + a*256 + b
+ else
+ n = m + b*256*256*256 + a*256*256
+ end
+ m = -1
+ doit()
+ end
+ else
+ break
+ end
+ end
+ if #tmp > 0 then
+ result[#result+1] = concat(tmp)
+ end
+ return result
+end
+
+local function little(c)
+ local b = byte(c) -- b = c:byte()
+ if b < 0x10000 then
+ return char(b%256,b/256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1%256,b1/256,b2%256,b2/256)
+ end
+end
+
+local function big(c)
+ local b = byte(c)
+ if b < 0x10000 then
+ return char(b/256,b%256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1/256,b1%256,b2/256,b2%256)
+ end
+end
+
+function unicode.utf8_to_utf16(str,littleendian)
+ if littleendian then
+ return char(255,254) .. utfgsub(str,".",little)
+ else
+ return char(254,255) .. utfgsub(str,".",big)
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
+
+if not math.round then
+ function math.round(x)
+ return floor(x + 0.5)
+ end
+end
+
+if not math.div then
+ function math.div(n,m)
+ return floor(n/m)
+ end
+end
+
+if not math.mod then
+ function math.mod(n,m)
+ return n % m
+ end
+end
+
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- hm, quite unreadable
+
+if not utils then utils = { } end
+if not utils.merger then utils.merger = { } end
+if not utils.lua then utils.lua = { } end
+
+utils.merger.m_begin = "begin library merge"
+utils.merger.m_end = "end library merge"
+utils.merger.pattern =
+ "%c+" ..
+ "%-%-%s+" .. utils.merger.m_begin ..
+ "%c+(.-)%c+" ..
+ "%-%-%s+" .. utils.merger.m_end ..
+ "%c+"
+
+function utils.merger._self_fake_()
+ return
+ "-- " .. "created merged file" .. "\n\n" ..
+ "-- " .. utils.merger.m_begin .. "\n\n" ..
+ "-- " .. utils.merger.m_end .. "\n\n"
+end
+
+function utils.report(...)
+ print(...)
+end
+
+utils.merger.strip_comment = true
+
+function utils.merger._self_load_(name)
+ local f, data = io.open(name), ""
+ if f then
+ utils.report("reading merge from %s",name)
+ data = f:read("*all")
+ f:close()
+ else
+ utils.report("unknown file to merge %s",name)
+ end
+ if data and utils.merger.strip_comment then
+ -- saves some 20K
+ data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
+ end
+ return data or ""
+end
+
+function utils.merger._self_save_(name, data)
+ if data ~= "" then
+ local f = io.open(name,'w')
+ if f then
+ utils.report("saving merge from %s",name)
+ f:write(data)
+ f:close()
+ end
+ end
+end
+
+function utils.merger._self_swap_(data,code)
+ if data ~= "" then
+ return (data:gsub(utils.merger.pattern, function(s)
+ return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
+ end, 1))
+ else
+ return ""
+ end
+end
+
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
+function utils.merger._self_libs_(libs,list)
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
+ if type(libs) == 'string' then libs = { libs } end
+ if type(list) == 'string' then list = { list } end
+ local foundpath = nil
+ for _, lib in ipairs(libs) do
+ for _, pth in ipairs(list) do
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
+ else
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
+ end
+ end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
+ end
+ return table.concat(result, "\n\n")
+end
+
+function utils.merger.selfcreate(libs,list,target)
+ if target then
+ utils.merger._self_save_(
+ target,
+ utils.merger._self_swap_(
+ utils.merger._self_fake_(),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+ end
+end
+
+function utils.merger.selfmerge(name,libs,list,target)
+ utils.merger._self_save_(
+ target or name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+end
+
+function utils.merger.selfclean(name)
+ utils.merger._self_save_(
+ name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ ""
+ )
+ )
+end
+
+function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
+ -- utils.report("compiling",luafile,"into",lucfile)
+ os.remove(lucfile)
+ local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
+ if strip ~= false then
+ command = "-s " .. command
+ end
+ local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
+ if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
+ -- utils.report("removing",luafile)
+ os.remove(luafile)
+ end
+ return done
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
+
+-- dirty tricks
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
+
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
+ if index > 0 then
+ local flag, value = argument:match("^%-+(.+)=(.-)$")
+ if flag then
+ arguments[flag] = string.unquote(value or "")
+ else
+ flag = argument:match("^%-+(.+)")
+ if flag then
+ arguments[flag] = true
+ else
+ files[#files+1] = argument
+ end
+ end
+ end
+ end
+ environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
+end
+
+function environment.setargument(name,value)
+ environment.arguments[name] = value
+end
+
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
+ local arguments, sortedflags = environment.arguments, environment.sortedflags
+ if arguments[name] then
+ return arguments[name]
+ elseif partial then
+ if not sortedflags then
+ sortedflags = { }
+ for _,v in pairs(table.sortedkeys(arguments)) do
+ sortedflags[#sortedflags+1] = "^" .. v
+ end
+ environment.sortedflags = sortedflags
+ end
+ -- example of potential clash: ^mode ^modefile
+ for _,v in ipairs(sortedflags) do
+ if name:find(v) then
+ return arguments[v:sub(2,#v)]
+ end
+ end
+ end
+ return nil
+end
+
+function environment.split_arguments(separator) -- rather special, cut-off before separator
+ local done, before, after = false, { }, { }
+ for _,v in ipairs(environment.original_arguments) do
+ if not done and v == separator then
+ done = true
+ elseif done then
+ after[#after+1] = v
+ else
+ before[#before+1] = v
+ end
+ end
+ return before, after
+end
+
+function environment.reconstruct_commandline(arg,noquote)
+ arg = arg or environment.original_arguments
+ if noquote and #arg == 1 then
+ local a = arg[1]
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ return a
+ elseif next(arg) then
+ local result = { }
+ for _,a in ipairs(arg) do -- ipairs 1 .. #n
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ a = a:gsub('"','\\"') -- tricky
+ if a:find(" ") then
+ result[#result+1] = a:quote()
+ else
+ result[#result+1] = a
+ end
+ end
+ return table.join(result," ")
+ else
+ return ""
+ end
+end
+
+if arg then
+
+ -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
+ local newarg, instring = { }, false
+
+ for index, argument in ipairs(arg) do
+ if argument:find("^\"") then
+ newarg[#newarg+1] = argument:gsub("^\"","")
+ if not argument:find("\"$") then
+ instring = true
+ end
+ elseif argument:find("\"$") then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
+ instring = false
+ elseif instring then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument
+ else
+ newarg[#newarg+1] = argument
+ end
+ end
+ for i=1,-5,-1 do
+ newarg[i] = arg[i]
+ end
+
+ environment.initialize_arguments(newarg)
+ environment.original_arguments = newarg
+ environment.raw_arguments = arg
+
+ arg = { } -- prevent duplicate handling
+
+end
+
+-- weird place ... depends on a not yet loaded module
+
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
+
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
+
+environment.loadedluacode = loadfile -- can be overloaded
+
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
+
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
+
+-- the next ones can use the previous ones / combine
+
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
+ end
+ end
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
+ end
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+local statusinfo, n, registered = { }, 0, { }
+
+statistics = statistics or { }
+
+statistics.enable = true
+statistics.threshold = 0.05
+
+-- timing functions
+
+local clock = os.gettimeofday or os.clock
+
+function statistics.hastimer(instance)
+ return instance and instance.starttime
+end
+
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
+ end
+ if it == 0 then
+ instance.starttime = clock()
+ if not instance.loadtime then
+ instance.loadtime = 0
+ end
+ end
+ instance.timing = it + 1
+ end
+end
+
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
+ local starttime = instance.starttime
+ if starttime then
+ local stoptime = clock()
+ local loadtime = stoptime - starttime
+ instance.stoptime = stoptime
+ instance.loadtime = instance.loadtime + loadtime
+ if report then
+ statistics.report("load time %0.3f",loadtime)
+ end
+ instance.timing = 0
+ return loadtime
+ end
+ end
+ end
+ return 0
+end
+
+function statistics.elapsedtime(instance)
+ return format("%0.3f",(instance and instance.loadtime) or 0)
+end
+
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
+end
+
+-- general function
+
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
+end
+
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
+ end
+ statistics.enable = false
+ end
+end
+
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
+
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
+
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
+end
+
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
+end
+
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
+end
+
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
+ end
+end
+
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
+ else
+ write_nl(category .. " |")
+ end
+end
+
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
+ else
+ write_nl("")
+ end
+end
+
+local texcount = tex and tex.count
+
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
+ end
+ else
+ write(format("[%s",real))
+ end
+ else
+ write("[-")
+ end
+end
+
+function logs.tex.stop_page_number()
+ write("]")
+end
+
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
+ else
+ write_nl(format("",category))
+ end
+end
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
+ else
+ write_nl("")
+ end
+end
+
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
+
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
+end
+
+function logs.xml.stop_run()
+ write_nl("")
+end
+
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
+
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
+end
+
+function logs.xml.report_output_log()
+end
+
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
+end
+
+local level = 0
+
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
+end
+
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
+end
+
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
+end
+
+--
+
+local name, banner = 'report', 'context'
+
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
+ end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
+end
+
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
+ else
+ trackers.disable("resolvers.verbose")
+ end
+ logs.verbose = what or false
+end
+
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
+ end
+end
+
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
+
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
+ end
+end
+
+function logs.reportline() -- for scripts too
+ logs.report()
+end
+
+logs.simpleline = logs.reportline
+
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
+ end
+end
+
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
+ if f then
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
+ f:close()
+ break
+ else
+ sleep(0.1)
+ end
+ end
+end
+
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
+end
+
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
+ end
+
+ return newinstance
+
+end
+
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
+ end
+ end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
+ end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
+ end
+end
+
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
+ end
+ ie[key] = value
+ end
+ return value or ""
+end
+
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
+
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
+end
+
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
+
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
+ end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
+end
+
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
+
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
+ end
+ end
+ return t
+end
+
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
+ end
+ else
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
+ end
+ return newlist
+end
+
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
+ end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
+ end
+ return resolvers.ownpath
+end
+
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
+
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
+ end
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
+ end
+end
+
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+-- database loading
+
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
+
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
+ end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
+
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
+ end
+end
+
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
+ end
+end
+
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
+
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
+ end
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
+ end
+ end
+ end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
+ end
+ end
+ end
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
+ end
+end
+
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ end
+ end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
+ end
+ end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
+ end
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
+ end
+ end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
+ end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
+ end
+end
+
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
+end
+
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
+ else
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
+ end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
+ end
+end
+
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
+
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
+
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
+end
+
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
+end
+
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
+end
+
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
+
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
+ end
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ else
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
+ end
+
+end
+
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
+ end
+ end
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ return new
+ end
+end
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
+end
+
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
+end
+
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
+ end
+end
+
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
+ else
+ return resolvers.expanded_path_list(tmp)
+ end
+end
+
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
+
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
+end
+
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
+ end
+ return ''
+end
+
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
+
+resolvers.isreadable = { }
+
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
+ end
+ return readable
+end
+
+resolvers.isreadable.tex = resolvers.isreadable.file
+
+-- name
+-- name/name
+
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
+end
+
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
+end
+
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
+end
+
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
+
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
+end
+
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
+ else
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
+ end
+ end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
+end
+
+if not resolvers.concatinators then resolvers.concatinators = { } end
+
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
+
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
+ end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
+ end
+ instance.format = ''
+ return result
+end
+
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
+
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
+ end
+ end
+ end
+ return result
+end
+
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
+end
+
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
+
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
+
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
+
+-- main user functions
+
+function resolvers.automount()
+ -- implemented later
+end
+
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
+end
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
+end
+
+-- strtab
+
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
+end
+
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
+end
+
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
+ end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
+ end
+ return concat(s, sep or " | ")
+end
+
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
+end
+
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
+end
+
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
+end
+
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
+
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
+end
+
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
+ end
+end
+
+texconfig.kpse_init = false
+
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
+
+-- for a while
+
+input = resolvers
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
+--ldx]]--
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+
+caches = caches or { }
+
+caches.path = caches.path or nil
+caches.base = caches.base or "luatex-cache"
+caches.more = caches.more or "context"
+caches.direct = false -- true is faster but may need huge amounts of memory
+caches.tree = false
+caches.paths = caches.paths or nil
+caches.force = false
+caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
+
+function caches.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
+
+function caches.temp()
+ local cachepath = nil
+ local function check(list,isenv)
+ if not cachepath then
+ for k=1,#list do
+ local v = list[k]
+ cachepath = (isenv and (os.env[v] or "")) or v or ""
+ if cachepath == "" then
+ -- next
+ else
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ break
+ elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
+ dir.mkdirs(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then
+ break
+ end
+ end
+ end
+ cachepath = nil
+ end
+ end
+ end
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
+ check(caches.defaults,true)
+ if not cachepath then
+ print("\nfatal error: there is no valid (writable) cache path defined\n")
+ os.exit()
+ elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
+ print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
+ os.exit()
+ end
+ cachepath = file.collapse_path(cachepath)
+ function caches.temp()
+ return cachepath
+ end
+ return cachepath
+end
+
+function caches.configpath()
+ return table.concat(resolvers.instance.cnffiles,";")
+end
+
+function caches.hashed(tree)
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
+end
+
+function caches.treehash()
+ local tree = caches.configpath()
+ if not tree or tree == "" then
+ return false
+ else
+ return caches.hashed(tree)
+ end
+end
+
+function caches.setpath(...)
+ if not caches.path then
+ if not caches.path then
+ caches.path = caches.temp()
+ end
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
+ end
+ end
+ if not caches.path then
+ caches.path = '.'
+ end
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
+ local pth = dir.mkdirs(caches.path,...)
+ return pth
+ end
+ caches.path = dir.expand_name(caches.path)
+ return caches.path
+end
+
+function caches.definepath(category,subcategory)
+ return function()
+ return caches.setpath(category,subcategory)
+ end
+end
+
+function caches.setluanames(path,name)
+ return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+end
+
+function caches.loaddata(path,name)
+ local tmaname, tmcname = caches.setluanames(path,name)
+ local loader = loadfile(tmcname) or loadfile(tmaname)
+ if loader then
+ return loader()
+ else
+ return false
+ end
+end
+
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
+
+function caches.iswritable(filepath,filename)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ return file.iswritable(tmaname)
+end
+
+function caches.savedata(filepath,filename,data,raw)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ local reduce, simplify = true, true
+ if raw then
+ reduce, simplify = false, false
+ end
+ if caches.direct then
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
+ else
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
+ end
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ utils.lua.compile(tmaname, tmcname, cleanup, strip)
+end
+
+-- here we use the cache for format loading (texconfig.[formatname|jobname])
+
+--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
+ if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
+
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
+
+
Examples of usage can be found in the font related code.
+--ldx]]--
+
+containers = containers or { }
+
+containers.usecache = true
+
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
+
+local allocated = { }
+
+-- tracing
+
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
+
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
+ end
+ end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
+
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
+ end
+ report(container,"stored",name)
+ container.storage[name] = data
+ end
+ return data
+end
+
+function containers.content(container,name)
+ return container.storage[name]
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+-- since we want to use the cache instead of the tree, we will now
+-- reimplement the saver.
+
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
+
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
+
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
+ else
+ return file.join(cachename,dataname)
+ end
+ end)
+end
+
+function resolvers.load_data(pathname,dataname,filename)
+ load_data(pathname,dataname,filename,function(dataname,filename)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
+ else
+ if not filename or (filename == "") then
+ filename = dataname
+ end
+ return file.join(pathname,filename)
+ end
+ end)
+end
+
+-- we will make a better format, maybe something xml or just text or lua
+
+resolvers.automounted = resolvers.automounted or { }
+
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
+ if table.is_empty(mountpaths) and usecache then
+ mountpaths = { caches.setpath("mount") }
+ end
+ if not table.is_empty(mountpaths) then
+ statistics.starttiming(resolvers.instance)
+ for k, root in pairs(mountpaths) do
+ local f = io.open(root.."/url.tmi")
+ if f then
+ for line in f:lines() do
+ if line then
+ if line:find("^[%%#%-]") then -- or %W
+ -- skip
+ elseif line:find("^zip://") then
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
+ end
+ end
+ end
+ f:close()
+ end
+ end
+ statistics.stoptiming(resolvers.instance)
+ end
+end
+
+-- status info
+
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
+
+-- experiment (code will move)
+
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
+ end
+end
+
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
+ else
+ return "invalid status file"
+ end
+ else
+ return "missing status file"
+ end
+ end
+ return true
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-lst'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- used in mtxrun
+
+local find, concat, upper, format = string.find, table.concat, string.upper, string.format
+
+resolvers.listers = resolvers.listers or { }
+
+local function tabstr(str)
+ if type(str) == 'table' then
+ return concat(str," | ")
+ else
+ return str
+ end
+end
+
+local function list(list,report)
+ local instance = resolvers.instance
+ local pat = upper(pattern or "","")
+ local report = report or texio.write_nl
+ for _,key in pairs(table.sortedkeys(list)) do
+ if instance.pattern == "" or find(upper(key),pat) then
+ if instance.kpseonly then
+ if instance.kpsevars[key] then
+ report(format("%s=%s",key,tabstr(list[key])))
+ end
+ else
+ report(format('%s %s=%s',(instance.kpsevars[key] and 'K') or 'E',key,tabstr(list[key])))
+ end
+ end
+ end
+end
+
+function resolvers.listers.variables () list(resolvers.instance.variables ) end
+function resolvers.listers.expansions() list(resolvers.instance.expansions) end
+
+function resolvers.listers.configurations(report)
+ local report = report or texio.write_nl
+ local instance = resolvers.instance
+ for _,key in ipairs(table.sortedkeys(instance.kpsevars)) do
+ if not instance.pattern or (instance.pattern=="") or find(key,instance.pattern) then
+ report(format("%s\n",key))
+ for i,c in ipairs(instance.order) do
+ local str = c[key]
+ if str then
+ report(format("\t%s\t%s",i,str))
+ end
+ end
+ report("")
+ end
+ end
+end
+
+
+end -- of closure
+-- end library merge
+
+-- We initialize some characteristics of this program. We need to
+-- do this before we load the libraries, else own.name will not be
+-- properly set (handy for selfcleaning the file). It's an ugly
+-- looking piece of code.
+
+own = { }
+
+own.libs = { -- todo: check which ones are really needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-io.lua',
+ 'l-number.lua',
+ 'l-set.lua',
+ 'l-os.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-url.lua',
+ 'l-dir.lua',
+ 'l-boolean.lua',
+ 'l-unicode.lua',
+ 'l-math.lua',
+ 'l-utils.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+-- 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-lst.lua', -- lister
+}
+
+-- We need this hack till luatex is fixed.
+
+if arg and arg[0] == 'luatex' and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+-- End of hack.
+
+own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+own.path = string.match(own.name,"^(.+)[\\/].-$") or "."
+own.list = { '.' }
+
+if own.path ~= '.' then
+ table.insert(own.list,own.path)
+end
+
+table.insert(own.list,own.path.."/../../../tex/context/base")
+table.insert(own.list,own.path.."/mtx")
+table.insert(own.list,own.path.."/../sources")
+
+function locate_libs()
+ for _, lib in pairs(own.libs) do
+ for _, pth in pairs(own.list) do
+ local filename = string.gsub(pth .. "/" .. lib,"\\","/")
+ local codeblob = loadfile(filename)
+ if codeblob then
+ codeblob()
+ own.list = { pth } -- speed up te search
+ break
+ end
+ end
+ end
+end
+
+if not resolvers then
+ locate_libs()
+end
+
+if not resolvers then
+ print("")
+ print("Luatools is unable to start up due to lack of libraries. You may")
+ print("try to run 'lua luatools.lua --selfmerge' in the path where this")
+ print("script is located (normally under ..../scripts/context/lua) which")
+ print("will make luatools library independent.")
+ os.exit()
+end
+
+logs.setprogram('LuaTools',"TDS Management Tool 1.31",environment.arguments["verbose"] or false)
+
+local instance = resolvers.reset()
+
+resolvers.defaultlibs = { -- not all are needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-boolean.lua',
+ 'l-number.lua',
+ 'l-unicode.lua',
+ 'l-os.lua',
+ 'l-io.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-url.lua',
+ 'l-dir.lua',
+ 'l-utils.lua',
+ 'l-dimen.lua',
+ 'trac-inf.lua',
+ 'trac-tra.lua',
+ 'trac-log.lua',
+ 'luat-env.lua', -- here ?
+ 'data-res.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-tmp.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-pre.lua',
+ 'data-tex.lua',
+ 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-clr.lua',
+ 'data-lua.lua',
+ 'data-ctx.lua',
+ 'luat-fio.lua',
+ 'luat-cnf.lua',
+}
+
+instance.engine = environment.arguments["engine"] or 'luatex'
+instance.progname = environment.arguments["progname"] or 'context'
+instance.luaname = environment.arguments["luafile"] or "" -- environment.ownname or ""
+instance.lualibs = environment.arguments["lualibs"] or table.concat(resolvers.defaultlibs,",")
+instance.allresults = environment.arguments["all"] or false
+instance.pattern = environment.arguments["pattern"] or nil
+instance.sortdata = environment.arguments["sort"] or false
+instance.kpseonly = not environment.arguments["all"] or false
+instance.my_format = environment.arguments["format"] or instance.format
+
+if type(instance.pattern) == 'boolean' then
+ logs.simple("invalid pattern specification")
+ instance.pattern = nil
+end
+
+if environment.arguments["trace"] then resolvers.settrace(environment.arguments["trace"]) end
+
+runners = runners or { }
+messages = messages or { }
+
+messages.no_ini_file = [[
+There is no lua initialization file found. This file can be forced by the
+"--progname" directive, or specified with "--luaname", or it is derived
+automatically from the formatname (aka jobname). It may be that you have
+to regenerate the file database using "luatools --generate".
+]]
+
+messages.help = [[
+--generate generate file database
+--variables show configuration variables
+--expansions show expanded variables
+--configurations show configuration order
+--expand-braces expand complex variable
+--expand-path expand variable (resolve paths)
+--expand-var expand variable (resolve references)
+--show-path show path expansion of ...
+--var-value report value of variable
+--find-file report file location
+--find-path report path of file
+--make or --ini make luatex format
+--run or --fmt= run luatex format
+--luafile=str lua inifile (default is .lua)
+--lualibs=list libraries to assemble (optional when --compile)
+--compile assemble and compile lua inifile
+--verbose give a bit more info
+--all show all found files
+--sort sort cached data
+--engine=str target engine
+--progname=str format or backend
+--pattern=str filter variables
+]]
+
+function runners.make_format(texname)
+ local instance = resolvers.instance
+ if texname and texname ~= "" then
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ if path and lfs then
+ lfs.chdir(path)
+ end
+ end
+ local barename = texname:gsub("%.%a+$","")
+ if barename == texname then
+ texname = texname .. ".tex"
+ end
+ local fullname = resolvers.find_files(texname)[1] or ""
+ if fullname == "" then
+ logs.simple("no tex file with name: %s",texname)
+ else
+ local luaname, lucname, luapath, lualibs = "", "", "", { }
+ -- the following is optional, since context.lua can also
+ -- handle this collect and compile business
+ if environment.arguments["compile"] then
+ if luaname == "" then luaname = barename end
+ logs.simple("creating initialization file: %s",luaname)
+ luapath = file.dirname(luaname)
+ if luapath == "" then
+ luapath = file.dirname(texname)
+ end
+ if luapath == "" then
+ luapath = file.dirname(resolvers.find_files(texname)[1] or "")
+ end
+ lualibs = string.split(instance.lualibs,",")
+ luaname = file.basename(barename .. ".lua")
+ lucname = file.basename(barename .. ".luc")
+ -- todo: when this fails, we can just copy the merged libraries from
+ -- luatools since they are normally the same, at least for context
+ if lualibs[1] then
+ local firstlib = file.join(luapath,lualibs[1])
+ if not lfs.isfile(firstlib) then
+ local foundname = resolvers.find_files(lualibs[1])[1]
+ if foundname then
+ logs.simple("located library path: %s",luapath)
+ luapath = file.dirname(foundname)
+ end
+ end
+ end
+ logs.simple("using library path: %s",luapath)
+ logs.simple("using lua libraries: %s",table.join(lualibs," "))
+ utils.merger.selfcreate(lualibs,luapath,luaname)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ if utils.lua.compile(luaname,lucname,false,strip) and io.exists(lucname) then
+ luaname = lucname
+ logs.simple("using compiled initialization file: %s",lucname)
+ else
+ logs.simple("using uncompiled initialization file: %s",luaname)
+ end
+ else
+ for _, v in pairs({instance.luaname, instance.progname, barename}) do
+ v = string.gsub(v..".lua","%.lua%.lua$",".lua")
+ if v and (v ~= "") then
+ luaname = resolvers.find_files(v)[1] or ""
+ if luaname ~= "" then
+ break
+ end
+ end
+ end
+ end
+ if environment.arguments["noluc"] then
+ luaname = luaname:gsub("%.luc$",".lua") -- make this an option
+ end
+ if luaname == "" then
+ if logs.verbose then
+ logs.simplelines(messages.no_ini_file)
+ logs.simple("texname : %s",texname)
+ logs.simple("luaname : %s",instance.luaname)
+ logs.simple("progname: %s",instance.progname)
+ logs.simple("barename: %s",barename)
+ end
+ else
+ logs.simple("using lua initialization file: %s",luaname)
+ local mp = dir.glob(file.removesuffix(file.basename(luaname)).."-*.mem")
+ if mp and #mp > 0 then
+ for _, name in ipairs(mp) do
+ logs.simple("removing related mplib format %s", file.basename(name))
+ os.remove(name)
+ end
+ end
+ local flags = {
+ "--ini",
+ "--lua=" .. string.quote(luaname)
+ }
+ local bs = (os.platform == "unix" and "\\\\") or "\\" -- todo: make a function
+ local command = "luatex ".. table.concat(flags," ") .. " " .. string.quote(fullname) .. " " .. bs .. "dump"
+ logs.simple("running command: %s\n",command)
+ os.spawn(command)
+ -- todo: do a dummy run that generates the related metafun and mfplain formats
+ end
+ end
+ else
+ logs.simple("no tex file given")
+ end
+end
+
+function runners.run_format(name,data,more)
+ -- hm, rather old code here; we can now use the file.whatever functions
+ if name and (name ~= "") then
+ local barename = name:gsub("%.%a+$","")
+ local fmtname = ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ barename = fmtname:gsub("%.%a+$","")
+ if fmtname == "" then
+ logs.simple("no format with name: %s",name)
+ else
+ local luaname = barename .. ".luc"
+ local f = io.open(luaname)
+ if not f then
+ luaname = barename .. ".lua"
+ f = io.open(luaname)
+ end
+ if f then
+ f:close()
+ local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. (more ~= "" and string.quote(more) or "")
+ logs.simple("running command: %s",command)
+ os.spawn(command)
+ else
+ logs.simple("using format name: %s",fmtname)
+ logs.simple("no luc/lua with name: %s",barename)
+ end
+ end
+ end
+end
+
+local ok = true
+
+-- private option --noluc for testing errors in the stub
+
+if environment.arguments["find-file"] then
+ resolvers.load()
+ instance.format = environment.arguments["format"] or instance.format
+ if instance.pattern then
+ instance.allresults = true
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
+ else
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
+ end
+elseif environment.arguments["find-path"] then
+ resolvers.load()
+ local path = resolvers.find_file(environment.files[1], instance.my_format)
+ if logs.verbose then
+ logs.simple(file.dirname(path))
+ else
+ print(file.dirname(path))
+ end
+elseif environment.arguments["run"] then
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.files[1] or "",environment.files[2] or "",environment.files[3] or "")
+elseif environment.arguments["fmt"] then
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.arguments["fmt"], environment.files[1] or "",environment.files[2] or "")
+elseif environment.arguments["expand-braces"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_braces, environment.files)
+elseif environment.arguments["expand-path"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_path, environment.files)
+elseif environment.arguments["expand-var"] or environment.arguments["expand-variable"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_var, environment.files)
+elseif environment.arguments["show-path"] or environment.arguments["path-value"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.show_path, environment.files)
+elseif environment.arguments["var-value"] or environment.arguments["show-value"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.var_value, environment.files)
+elseif environment.arguments["format-path"] then
+ resolvers.load()
+ logs.simple(caches.setpath("format"))
+elseif instance.pattern then -- brrr
+ resolvers.load()
+ instance.format = environment.arguments["format"] or instance.format
+ instance.allresults = true
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
+elseif environment.arguments["generate"] then
+ instance.renewcache = true
+ logs.setverbose(true)
+ resolvers.load()
+elseif environment.arguments["make"] or environment.arguments["ini"] or environment.arguments["compile"] then
+ resolvers.load()
+ logs.setverbose(true)
+ runners.make_format(environment.files[1] or "")
+elseif environment.arguments["selfmerge"] then
+ utils.merger.selfmerge(own.name,own.libs,own.list)
+elseif environment.arguments["selfclean"] then
+ utils.merger.selfclean(own.name)
+elseif environment.arguments["selfupdate"] then
+ resolvers.load()
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"luatools")
+elseif environment.arguments["variables"] or environment.arguments["show-variables"] then
+ resolvers.load("nofiles")
+ resolvers.listers.variables()
+elseif environment.arguments["expansions"] or environment.arguments["show-expansions"] then
+ resolvers.load("nofiles")
+ resolvers.listers.expansions()
+elseif environment.arguments["configurations"] or environment.arguments["show-configurations"] then
+ resolvers.load("nofiles")
+ resolvers.listers.configurations()
+elseif environment.arguments["help"] or (environment.files[1]=='help') or (#environment.files==0) then
+ logs.help(messages.help)
+else
+ resolvers.load()
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
+end
+
+if logs.verbose then
+ logs.simpleline()
+ logs.simple("runtime: %0.3f seconds",os.runtime())
+end
+
+if os.platform == "unix" then
+ io.write("\n")
+end
diff --git a/scripts/context/stubs/mswin/makempy.bat b/scripts/context/stubs/mswin/makempy.bat
index e339058c6..03eaa8a28 100755
--- a/scripts/context/stubs/mswin/makempy.bat
+++ b/scripts/context/stubs/mswin/makempy.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart makempy.pl %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute makempy.pl %*
+endlocal
diff --git a/scripts/context/stubs/mswin/metatex.cmd b/scripts/context/stubs/mswin/metatex.cmd
new file mode 100644
index 000000000..858f28f8f
--- /dev/null
+++ b/scripts/context/stubs/mswin/metatex.cmd
@@ -0,0 +1,5 @@
+@echo off
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --script metatex %*
+endlocal
diff --git a/scripts/context/stubs/mswin/mpstools.bat b/scripts/context/stubs/mswin/mpstools.bat
index df1732e17..8bd25674c 100755
--- a/scripts/context/stubs/mswin/mpstools.bat
+++ b/scripts/context/stubs/mswin/mpstools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart mpstools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute mpstools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/mptopdf.bat b/scripts/context/stubs/mswin/mptopdf.bat
index 242854337..f29881763 100755
--- a/scripts/context/stubs/mswin/mptopdf.bat
+++ b/scripts/context/stubs/mswin/mptopdf.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart mptopdf.pl %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute mptopdf.pl %*
+endlocal
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
new file mode 100644
index 000000000..0af429bf1
--- /dev/null
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -0,0 +1,10190 @@
+#!/usr/bin/env texlua
+
+if not modules then modules = { } end modules ['mtxrun'] = {
+ version = 1.001,
+ comment = "runner, lua replacement for texmfstart.rb",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+
+-- one can make a stub:
+--
+-- #!/bin/sh
+-- env LUATEXDIR=/....../texmf/scripts/context/lua luatex --luaonly mtxrun.lua "$@"
+
+-- filename : mtxrun.lua
+-- comment : companion to context.tex
+-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
+-- copyright: PRAGMA ADE / ConTeXt Development Team
+-- license : see context related readme files
+
+-- This script is based on texmfstart.rb but does not use kpsewhich to
+-- locate files. Although kpse is a library it never came to opening up
+-- its interface to other programs (esp scripting languages) and so we
+-- do it ourselves. The lua variant evolved out of an experimental ruby
+-- one. Interesting is that using a scripting language instead of c does
+-- not have a speed penalty. Actually the lua variant is more efficient,
+-- especially when multiple calls to kpsewhich are involved. The lua
+-- library also gives way more control.
+
+-- to be done / considered
+--
+-- support for --exec or make it default
+-- support for jar files (or maybe not, never used, too messy)
+-- support for $RUBYINPUTS cum suis (if still needed)
+-- remember for subruns: _CTX_K_V_#{original}_
+-- remember for subruns: _CTX_K_S_#{original}_
+-- remember for subruns: TEXMFSTART.#{original} [tex.rb texmfstart.rb]
+
+texlua = true
+
+-- begin library merge
+
+
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
+
+if not string.split then
+
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
+ end
+ end
+
+end
+
+local chr_to_esc = {
+ ["%"] = "%%",
+ ["."] = "%.",
+ ["+"] = "%+", ["-"] = "%-", ["*"] = "%*",
+ ["^"] = "%^", ["$"] = "%$",
+ ["["] = "%[", ["]"] = "%]",
+ ["("] = "%(", [")"] = "%)",
+ ["{"] = "%{", ["}"] = "%}"
+}
+
+string.chr_to_esc = chr_to_esc
+
+function string:esc() -- variant 2
+ return (gsub(self,"(.)",chr_to_esc))
+end
+
+function string:unquote()
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
+end
+
+function string:quote() -- we could use format("%q")
+ return '"' .. self:unquote() .. '"'
+end
+
+function string:count(pattern) -- variant 3
+ local n = 0
+ for _ in gmatch(self,pattern) do
+ n = n + 1
+ end
+ return n
+end
+
+function string:limit(n,sentinel)
+ if #self > n then
+ sentinel = sentinel or " ..."
+ return sub(self,1,(n-#sentinel)) .. sentinel
+ else
+ return self
+ end
+end
+
+function string:strip()
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
+end
+
+function string:is_empty()
+ return not find(find,"%S")
+end
+
+function string:enhance(pattern,action)
+ local ok, n = true, 0
+ while ok do
+ ok = false
+ self = gsub(self,pattern, function(...)
+ ok, n = true, n + 1
+ return action(...)
+ end)
+ end
+ return self, n
+end
+
+local chr_to_hex, hex_to_chr = { }, { }
+
+for i=0,255 do
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
+end
+
+function string:to_hex()
+ return (gsub(self or "","(.)",chr_to_hex))
+end
+
+function string:from_hex()
+ return (gsub(self or "","(..)",hex_to_chr))
+end
+
+if not string.characters then
+
+ local function nextchar(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, str:sub(index,index)
+ end
+ function string:characters()
+ return nextchar, self, 0
+ end
+ local function nextbyte(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
+ end
+ function string:bytes()
+ return nextbyte, self, 0
+ end
+
+end
+
+-- we can use format for this (neg n)
+
+function string:rpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self .. self.rep(chr or " ",m)
+ else
+ return self
+ end
+end
+
+function string:lpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self.rep(chr or " ",m) .. self
+ else
+ return self
+ end
+end
+
+string.padd = string.rpadd
+
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
+end
+
+--~ print(is_number("1"))
+--~ print(is_number("1.1"))
+--~ print(is_number(".1"))
+--~ print(is_number("-0.1"))
+--~ print(is_number("+0.1"))
+--~ print(is_number("-.1"))
+--~ print(is_number("+.1"))
+
+function string:split_settings() -- no {} handling, see l-aux for lpeg variant
+ if find(self,"=") then
+ local t = { }
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return nil
+ end
+end
+
+local patterns_escapes = {
+ ["-"] = "%-",
+ ["."] = "%.",
+ ["+"] = "%+",
+ ["*"] = "%*",
+ ["%"] = "%%",
+ ["("] = "%)",
+ [")"] = "%)",
+ ["["] = "%[",
+ ["]"] = "%]",
+}
+
+function string:pattesc()
+ return (gsub(self,".",patterns_escapes))
+end
+
+function string:tohash()
+ local t = { }
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
+ t[s] = true
+ end
+ return t
+end
+
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
+
+--~ l-lpeg.lua :
+
+--~ lpeg.digit = lpeg.R('09')^1
+--~ lpeg.sign = lpeg.S('+-')^1
+--~ lpeg.cardinal = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.integer = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.float = lpeg.P(lpeg.sign^0 * lpeg.digit^0 * lpeg.P('.') * lpeg.digit^1)
+--~ lpeg.number = lpeg.float + lpeg.integer
+--~ lpeg.oct = lpeg.P("0") * lpeg.R('07')^1
+--~ lpeg.hex = lpeg.P("0x") * (lpeg.R('09') + lpeg.R('AF'))^1
+--~ lpeg.uppercase = lpeg.P("AZ")
+--~ lpeg.lowercase = lpeg.P("az")
+
+--~ lpeg.eol = lpeg.S('\r\n\f')^1 -- includes formfeed
+--~ lpeg.space = lpeg.S(' ')^1
+--~ lpeg.nonspace = lpeg.P(1-lpeg.space)^1
+--~ lpeg.whitespace = lpeg.S(' \r\n\f\t')^1
+--~ lpeg.nonwhitespace = lpeg.P(1-lpeg.whitespace)^1
+
+local hash = { }
+
+function lpeg.anywhere(pattern) --slightly adapted from website
+ return P { P(pattern) + 1 * lpeg.V(1) }
+end
+
+function lpeg.startswith(pattern) --slightly adapted
+ return P(pattern)
+end
+
+function lpeg.splitter(pattern, action)
+ return (((1-P(pattern))^1)/action+1)^0
+end
+
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
+local newline = crlf + cr + lf
+local spacing = space^0 * newline
+
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
+local content = (empty + nonempty)^1
+
+local capture = Ct(content^0)
+
+function string:splitlines()
+ return capture:match(self)
+end
+
+lpeg.linebyline = content -- better make a sublibrary
+
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps")) -- oeps
+
+local splitters_s, splitters_m = { }, { }
+
+local function splitat(separator,single)
+ local splitter = (single and splitters_s[separator]) or splitters_m[separator]
+ if not splitter then
+ separator = P(separator)
+ if single then
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
+ splitters_s[separator] = splitter
+ else
+ local other = C((1 - separator)^0)
+ splitter = other * (separator * other)^0
+ splitters_m[separator] = splitter
+ end
+ end
+ return splitter
+end
+
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+table.join = table.concat
+
+local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
+local getmetatable, setmetatable = getmetatable, setmetatable
+local type, next, tostring, ipairs = type, next, tostring, ipairs
+
+function table.strip(tab)
+ local lst = { }
+ for i=1,#tab do
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
+ if s == "" then
+ -- skip this one
+ else
+ lst[#lst+1] = s
+ end
+ end
+ return lst
+end
+
+local function sortedkeys(tab)
+ local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ if kind == 3 then
+ -- no further check
+ else
+ local tkey = type(key)
+ if tkey == "string" then
+ -- if kind == 2 then kind = 3 else kind = 1 end
+ kind = (kind == 2 and 3) or 1
+ elseif tkey == "number" then
+ -- if kind == 1 then kind = 3 else kind = 2 end
+ kind = (kind == 1 and 3) or 2
+ else
+ kind = 3
+ end
+ end
+ end
+ if kind == 0 or kind == 3 then
+ sort(srt,function(a,b) return (tostring(a) < tostring(b)) end)
+ else
+ sort(srt)
+ end
+ return srt
+end
+
+local function sortedhashkeys(tab) -- fast one
+ local srt = { }
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ end
+ sort(srt)
+ return srt
+end
+
+table.sortedkeys = sortedkeys
+table.sortedhashkeys = sortedhashkeys
+
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
+function table.append(t, list)
+ for _,v in next, list do
+ insert(t,v)
+ end
+end
+
+function table.prepend(t, list)
+ for k,v in next, list do
+ insert(t,k,v)
+ end
+end
+
+function table.merge(t, ...) -- first one is target
+ t = t or {}
+ local lst = {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ t[k] = v
+ end
+ end
+ return t
+end
+
+function table.merged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ tmp[k] = v
+ end
+ end
+ return tmp
+end
+
+function table.imerge(t, ...)
+ local lst = {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ t[#t+1] = nst[j]
+ end
+ end
+ return t
+end
+
+function table.imerged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ tmp[#tmp+1] = nst[j]
+ end
+ end
+ return tmp
+end
+
+local function fastcopy(old) -- fast one
+ if old then
+ local new = { }
+ for k,v in next, old do
+ if type(v) == "table" then
+ new[k] = fastcopy(v) -- was just table.copy
+ else
+ new[k] = v
+ end
+ end
+ -- optional second arg
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+local function copy(t, tables) -- taken from lua wiki, slightly adapted
+ tables = tables or { }
+ local tcopy = {}
+ if not tables[t] then
+ tables[t] = tcopy
+ end
+ for i,v in next, t do -- brrr, what happens with sparse indexed
+ if type(i) == "table" then
+ if tables[i] then
+ i = tables[i]
+ else
+ i = copy(i, tables)
+ end
+ end
+ if type(v) ~= "table" then
+ tcopy[i] = v
+ elseif tables[v] then
+ tcopy[i] = tables[v]
+ else
+ tcopy[i] = copy(v, tables)
+ end
+ end
+ local mt = getmetatable(t)
+ if mt then
+ setmetatable(tcopy,mt)
+ end
+ return tcopy
+end
+
+table.fastcopy = fastcopy
+table.copy = copy
+
+-- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+
+function table.sub(t,i,j)
+ return { unpack(t,i,j) }
+end
+
+function table.replace(a,b)
+ for k,v in next, b do
+ a[k] = v
+ end
+end
+
+-- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice)
+
+function table.is_empty(t)
+ return not t or not next(t)
+end
+
+function table.one_entry(t)
+ local n = next(t)
+ return n and not next(t,n)
+end
+
+function table.starts_at(t)
+ return ipairs(t,1)(t,0)
+end
+
+function table.tohash(t,value)
+ local h = { }
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
+ end
+ return h
+end
+
+function table.fromhash(t)
+ local h = { }
+ for k, v in next, t do -- no ipairs here
+ if v then h[#h+1] = k end
+ end
+ return h
+end
+
+--~ print(table.serialize(t), "\n")
+--~ print(table.serialize(t,"name"), "\n")
+--~ print(table.serialize(t,false), "\n")
+--~ print(table.serialize(t,true), "\n")
+--~ print(table.serialize(t,"name",true), "\n")
+--~ print(table.serialize(t,"name",true,true), "\n")
+
+table.serialize_functions = true
+table.serialize_compact = true
+table.serialize_inline = true
+
+local noquotes, hexify, handle, reduce, compact, inline, functions
+
+local reserved = table.tohash { -- intercept a language flaw, no reserved words as key
+ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if',
+ 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
+}
+
+local function simple_table(t)
+ if #t > 0 then
+ local n = 0
+ for _,v in next, t do
+ n = n + 1
+ end
+ if n == #t then
+ local tt = { }
+ for i=1,#t do
+ local v = t[i]
+ local tv = type(v)
+ if tv == "number" then
+ if hexify then
+ tt[#tt+1] = format("0x%04X",v)
+ else
+ tt[#tt+1] = tostring(v) -- tostring not needed
+ end
+ elseif tv == "boolean" then
+ tt[#tt+1] = tostring(v)
+ elseif tv == "string" then
+ tt[#tt+1] = format("%q",v)
+ else
+ tt = nil
+ break
+ end
+ end
+ return tt
+ end
+ end
+ return nil
+end
+
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
+local function do_serialize(root,name,depth,level,indexed)
+ if level > 0 then
+ depth = depth .. " "
+ if indexed then
+ handle(format("%s{",depth))
+ elseif name then
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
+ else
+ handle(format("%s{",depth))
+ end
+ end
+ if root and next(root) then
+ local first, last = nil, 0 -- #root cannot be trusted here
+ if compact then
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
+ if not first then first = k end
+ last = last + 1
+ end
+ end
+ local sk = sortedkeys(root)
+ for i=1,#sk do
+ local k = sk[i]
+ local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
+ local t = type(v)
+ if compact and first and type(k) == "number" and k >= first and k <= last then
+ if t == "number" then
+ if hexify then
+ handle(format("%s 0x%04X,",depth,v))
+ else
+ handle(format("%s %s,",depth,v))
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
+ else
+ handle(format("%s %q,",depth,v))
+ end
+ elseif t == "table" then
+ if not next(v) then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
+ local st = simple_table(v)
+ if st then
+ handle(format("%s { %s },",depth,concat(st,", ")))
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ elseif t == "boolean" then
+ handle(format("%s %s,",depth,tostring(v)))
+ elseif t == "function" then
+ if functions then
+ handle(format('%s loadstring(%q),',depth,dump(v)))
+ else
+ handle(format('%s "function",',depth))
+ end
+ else
+ handle(format("%s %q,",depth,tostring(v)))
+ end
+ elseif k == "__p__" then -- parent
+ if false then
+ handle(format("%s __p__=nil,",depth))
+ end
+ elseif t == "number" then
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
+ else
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
+ end
+ elseif t == "table" then
+ if not next(v) then
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
+ elseif inline then
+ local st = simple_table(v)
+ if st then
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ elseif t == "boolean" then
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
+ elseif t == "function" then
+ if functions then
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
+ end
+ --~ end
+ end
+ end
+ if level > 0 then
+ handle(format("%s},",depth))
+ end
+end
+
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
+local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
+ noquotes = _noquotes
+ hexify = _hexify
+ handle = _handle or print
+ reduce = _reduce or false
+ compact = table.serialize_compact
+ inline = compact and table.serialize_inline
+ functions = table.serialize_functions
+ local tname = type(name)
+ if tname == "string" then
+ if name == "return" then
+ handle("return {")
+ else
+ handle(name .. "={")
+ end
+ elseif tname == "number" then
+ if hexify then
+ handle(format("[0x%04X]={",name))
+ else
+ handle("[" .. name .. "]={")
+ end
+ elseif tname == "boolean" then
+ if name then
+ handle("return {")
+ else
+ handle("{")
+ end
+ else
+ handle("t={")
+ end
+ if root and next(root) then
+ do_serialize(root,name,"",0,indexed)
+ end
+ handle("}")
+end
+
+--~ name:
+--~
+--~ true : return { }
+--~ false : { }
+--~ nil : t = { }
+--~ string : string = { }
+--~ 'return' : return { }
+--~ number : [number] = { }
+
+function table.serialize(root,name,reduce,noquotes,hexify)
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ return concat(t,"\n")
+end
+
+function table.tohandle(handle,root,name,reduce,noquotes,hexify)
+ serialize(root,name,handle,reduce,noquotes,hexify)
+end
+
+-- sometimes tables are real use (zapfino extra pro is some 85M) in which
+-- case a stepwise serialization is nice; actually, we could consider:
+--
+-- for line in table.serializer(root,name,reduce,noquotes) do
+-- ...(line)
+-- end
+--
+-- so this is on the todo list
+
+table.tofile_maxtab = 2*1024
+
+function table.tofile(filename,root,name,reduce,noquotes,hexify)
+ local f = io.open(filename,'w')
+ if f then
+ local maxtab = table.tofile_maxtab
+ if maxtab > 1 then
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ if #t > maxtab then
+ f:write(concat(t,"\n"),"\n") -- hm, write(sometable) should be nice
+ t = { }
+ end
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ f:write(concat(t,"\n"),"\n")
+ else
+ local function flush(s)
+ f:write(s,"\n")
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ end
+ f:close()
+ end
+end
+
+local function flatten(t,f,complete)
+ for i=1,#t do
+ local v = t[i]
+ if type(v) == "table" then
+ if complete or type(v[1]) == "table" then
+ flatten(v,f,complete)
+ else
+ f[#f+1] = v
+ end
+ else
+ f[#f+1] = v
+ end
+ end
+end
+
+function table.flatten(t)
+ local f = { }
+ flatten(t,f,true)
+ return f
+end
+
+function table.unnest(t) -- bad name
+ local f = { }
+ flatten(t,f,false)
+ return f
+end
+
+table.flatten_one_level = table.unnest
+
+-- the next three may disappear
+
+function table.remove_value(t,value) -- todo: n
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ remove(t,i)
+ -- remove all, so no: return
+ end
+ end
+ end
+end
+
+function table.insert_before_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i,str)
+ return
+ end
+ end
+ end
+ insert(t,1,str)
+ elseif value then
+ insert(t,1,value)
+ end
+end
+
+function table.insert_after_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i+1,str)
+ return
+ end
+ end
+ end
+ t[#t+1] = str
+ elseif value then
+ t[#t+1] = value
+ end
+end
+
+local function are_equal(a,b,n,m) -- indexed
+ if #a == #b then
+ n = n or 1
+ m = m or #a
+ for i=n,m do
+ local ai, bi = a[i], b[i]
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+ else
+ return false
+ end
+end
+
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
+function table.compact(t)
+ if t then
+ for k,v in next, t do
+ if not next(v) then
+ t[k] = nil
+ end
+ end
+ end
+end
+
+function table.contains(t, v)
+ if t then
+ for i=1, #t do
+ if t[i] == v then
+ return i
+ end
+ end
+ end
+ return false
+end
+
+function table.count(t)
+ local n, e = 0, next(t)
+ while e do
+ n, e = n + 1, next(t,e)
+ end
+ return n
+end
+
+function table.swapped(t)
+ local s = { }
+ for k, v in next, t do
+ s[v] = k
+ end
+ return s
+end
+
+--~ function table.are_equal(a,b)
+--~ return table.serialize(a) == table.serialize(b)
+--~ end
+
+function table.clone(t,p) -- t is optional or nil or table
+ if not p then
+ t, p = { }, t or { }
+ elseif not t then
+ t = { }
+ end
+ setmetatable(t, { __index = function(_,key) return p[key] end })
+ return t
+end
+
+function table.hexed(t,seperator)
+ local tt = { }
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
+ return concat(tt,seperator or " ")
+end
+
+function table.reverse_hash(h)
+ local r = { }
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
+ end
+ return r
+end
+
+function table.reverse(t)
+ local tt = { }
+ if #t > 0 then
+ for i=#t,1,-1 do
+ tt[#tt+1] = t[i]
+ end
+ end
+ return tt
+end
+
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local byte = string.byte
+
+if string.find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator = "\\", ";"
+else
+ io.fileseparator, io.pathseparator = "/" , ":"
+end
+
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
+ if f then
+ local data = f:read('*all')
+ -- garbagecollector.check(data)
+ f:close()
+ return data
+ else
+ return nil
+ end
+end
+
+function io.savedata(filename,data,joiner)
+ local f = io.open(filename,"wb")
+ if f then
+ if type(data) == "table" then
+ f:write(table.join(data,joiner or ""))
+ elseif type(data) == "function" then
+ data(f)
+ else
+ f:write(data)
+ end
+ f:close()
+ return true
+ else
+ return false
+ end
+end
+
+function io.exists(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return false
+ else
+ assert(f:close())
+ return true
+ end
+end
+
+function io.size(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return 0
+ else
+ local s = f:seek("end")
+ assert(f:close())
+ return s
+ end
+end
+
+function io.noflines(f)
+ local n = 0
+ for _ in f:lines() do
+ n = n + 1
+ end
+ f:seek('set',0)
+ return n
+end
+
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
+ end
+}
+
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
+ end
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
+ else
+ return nil, nil
+ end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
+ else
+ return nil, nil
+ end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
+ end
+}
+
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+function io.ask(question,default,options)
+ while true do
+ io.write(question)
+ if options then
+ io.write(string.format(" [%s]",table.concat(options,"|")))
+ end
+ if default then
+ io.write(string.format(" [%s]",default))
+ end
+ io.write(string.format(" "))
+ local answer = io.read()
+ answer = answer:gsub("^%s*(.*)%s*$","%1")
+ if answer == "" and default then
+ return default
+ elseif not options then
+ return answer
+ else
+ for _,v in pairs(options) do
+ if v == answer then
+ return answer
+ end
+ end
+ local pattern = "^" .. answer
+ for _,v in pairs(options) do
+ if v:find(pattern) then
+ return v
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+number = number or { }
+
+-- a,b,c,d,e,f = number.toset(100101)
+
+function number.toset(n)
+ return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
+end
+
+function number.toevenhex(n)
+ local s = format("%X",n)
+ if #s % 2 == 0 then
+ return s
+ else
+ return "0" .. s
+ end
+end
+
+-- the lpeg way is slower on 8 digits, but faster on 4 digits, some 7.5%
+-- on
+--
+-- for i=1,1000000 do
+-- local a,b,c,d,e,f,g,h = number.toset(12345678)
+-- local a,b,c,d = number.toset(1234)
+-- local a,b,c = number.toset(123)
+-- end
+--
+-- of course dedicated "(.)(.)(.)(.)" matches are even faster
+
+local one = lpeg.C(1-lpeg.S(''))^1
+
+function number.toset(n)
+ return one:match(tostring(n))
+end
+
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+set = set or { }
+
+local nums = { }
+local tabs = { }
+local concat = table.concat
+
+set.create = table.tohash
+
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
+ end
+ end
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
+ end
+ return nums[s]
+ else
+ return 0
+ end
+end
+
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
+ end
+end
+
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
+end
+
+--~ local c = set.create{'aap','noot','mies'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ local c = set.create{'zus','wim','jet'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ print(t['jet'])
+--~ print(set.contains(t,'jet'))
+--~ print(set.contains(t,'aap'))
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+function os.resultof(command)
+ return io.popen(command,"r"):read("*all")
+end
+
+if not os.exec then os.exec = os.execute end
+if not os.spawn then os.spawn = os.execute end
+
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+
+if not io.fileseparator then
+ if find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ else
+ io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ end
+end
+
+os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+
+function os.launch(str)
+ if os.platform == "windows" then
+ os.execute("start " .. str) -- os.spawn ?
+ else
+ os.execute(str .. " &") -- os.spawn ?
+ end
+end
+
+if not os.setenv then
+ function os.setenv() return false end
+end
+
+if not os.times then
+ -- utime = user time
+ -- stime = system time
+ -- cutime = children user time
+ -- cstime = children system time
+ function os.times()
+ return {
+ utime = os.gettimeofday(), -- user
+ stime = 0, -- system
+ cutime = 0, -- children user
+ cstime = 0, -- children system
+ }
+ end
+end
+
+os.gettimeofday = os.gettimeofday or os.clock
+
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
+end
+
+--~ print(os.gettimeofday()-os.time())
+--~ os.sleep(1.234)
+--~ print (">>",os.runtime())
+--~ print(os.date("%H:%M:%S",os.gettimeofday()))
+--~ print(os.date("%H:%M:%S",os.time()))
+
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
+
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- needs a cleanup
+
+file = file or { }
+
+local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
+end
+
+function file.addsuffix(filename, suffix)
+ if not find(filename,"%.[%a%d]+$") then
+ return filename .. "." .. suffix
+ else
+ return filename
+ end
+end
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
+
+function file.dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
+end
+
+function file.basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
+end
+
+function file.nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+end
+
+function file.extname(name)
+ return match(name,"^.+%.([^/\\]-)$") or ""
+end
+
+file.suffix = file.extname
+
+--~ print(file.join("x/","/y"))
+--~ print(file.join("http://","/y"))
+--~ print(file.join("http://a","/y"))
+--~ print(file.join("http:///a","/y"))
+--~ print(file.join("//nas-1","/y"))
+
+function file.join(...)
+ local pth = concat({...},"/")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ a, b = match(pth,"^(//)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ return (gsub(pth,"//+","/"))
+end
+
+function file.iswritable(name)
+ local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ return a and a.permissions:sub(2,2) == "w"
+end
+
+function file.isreadable(name)
+ local a = lfs.attributes(name)
+ return a and a.permissions:sub(1,1) == "r"
+end
+
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
+
+-- todo: lpeg
+
+function file.split_path(str)
+ local t = { }
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
+ if name ~= "" then
+ t[#t+1] = gsub(name,"\001",":")
+ end
+ end
+ return t
+end
+
+function file.join_path(tab)
+ return concat(tab,io.pathseparator) -- can have trailing //
+end
+
+function file.collapse_path(str)
+ str = gsub(str,"/%./","/")
+ local n, m = 1, 1
+ while n > 0 or m > 0 do
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
+ end
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
+ if str == "" then str = "." end
+ return str
+end
+
+--~ print(file.collapse_path("a/./b/.."))
+--~ print(file.collapse_path("a/aa/../b/bb"))
+--~ print(file.collapse_path("a/../.."))
+--~ print(file.collapse_path("a/.././././b/.."))
+--~ print(file.collapse_path("a/./././b/.."))
+--~ print(file.collapse_path("a/b/c/../.."))
+
+function file.robustname(str)
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
+end
+
+file.readdata = io.loaddata
+file.savedata = io.savedata
+
+function file.copy(oldname,newname)
+ file.savedata(newname,io.loaddata(oldname))
+end
+
+-- lpeg variants, slightly faster, not always
+
+--~ local period = lpeg.P(".")
+--~ local slashes = lpeg.S("\\/")
+--~ local noperiod = 1-period
+--~ local noslashes = 1-slashes
+--~ local name = noperiod^1
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.C(noperiod^1) * -1
+
+--~ function file.extname(name)
+--~ return pattern:match(name) or ""
+--~ end
+
+--~ local pattern = lpeg.Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+
+--~ function file.removesuffix(name)
+--~ return pattern:match(name)
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
+
+--~ function file.basename(name)
+--~ return pattern:match(name) or name
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.Cp() * noslashes^1 * -1
+
+--~ function file.dirname(name)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2)
+--~ else
+--~ return ""
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.addsuffix(name, suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.replacesuffix(name,suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2) .. "." .. suffix
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * lpeg.Cp() * ((noperiod^1 * period)^1 * lpeg.Cp() + lpeg.P(true)) * noperiod^1 * -1
+
+--~ function file.nameonly(name)
+--~ local a, b = pattern:match(name)
+--~ if b then
+--~ return name:sub(a,b-2)
+--~ elseif a then
+--~ return name:sub(a)
+--~ else
+--~ return name
+--~ end
+--~ end
+
+--~ local test = file.extname
+--~ local test = file.basename
+--~ local test = file.dirname
+--~ local test = file.addsuffix
+--~ local test = file.replacesuffix
+--~ local test = file.nameonly
+
+--~ print(1,test("./a/b/c/abd.def.xxx","!!!"))
+--~ print(2,test("./../b/c/abd.def.xxx","!!!"))
+--~ print(3,test("a/b/c/abd.def.xxx","!!!"))
+--~ print(4,test("a/b/c/def.xxx","!!!"))
+--~ print(5,test("a/b/c/def","!!!"))
+--~ print(6,test("def","!!!"))
+--~ print(7,test("def.xxx","!!!"))
+
+--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEX(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type = type
+local find, gmatch = string.find, string.gmatch
+
+dir = dir or { }
+
+-- optimizing for no string.find (*) does not save time
+
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
+ end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
+ end
+ end
+ end
+end
+
+dir.glob_pattern = glob_pattern
+
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
+
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
+ local t = t or { }
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
+ return t
+ else
+ return { }
+ end
+ end
+end
+
+dir.glob = glob
+
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
+
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
+ files[#files+1] = path .. "/" .. name
+ end
+ else
+ files[#files+1] = path .. "/" .. name
+ end
+ end
+ end
+ end
+ return files
+end
+
+dir.globfiles = globfiles
+
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
+
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
+
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
+
+local make_indeed = true -- false
+
+if string.find(os.getenv("PATH"),";") then
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
+ if first then
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
+ else
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
+ if first then
+ pth, drive = first .. middle, true
+ else
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
+ end
+ end
+ end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("a:"))
+--~ print(dir.mkdirs("a:/b/c"))
+--~ print(dir.mkdirs("a:b/c"))
+--~ print(dir.mkdirs("a:/bbb/c"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
+ end
+ lfs.chdir(d)
+ end
+ end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
+
+else
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
+ end
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
+ end
+
+end
+
+dir.makedirs = dir.mkdirs
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
+
+function boolean.tonumber(b)
+ if b then return 1 else return 0 end
+end
+
+function toboolean(str,tolerant)
+ if tolerant then
+ local tstr = type(str)
+ if tstr == "string" then
+ return str == "true" or str == "yes" or str == "on" or str == "1" or str == "t"
+ elseif tstr == "number" then
+ return tonumber(str) ~= 0
+ elseif tstr == "nil" then
+ return false
+ else
+ return str
+ end
+ elseif str == "true" then
+ return true
+ elseif str == "false" then
+ return false
+ else
+ return str
+ end
+end
+
+function string.is_boolean(str)
+ if type(str) == "string" then
+ if str == "true" or str == "yes" or str == "on" or str == "t" then
+ return true
+ elseif str == "false" or str == "no" or str == "off" or str == "f" then
+ return false
+ end
+ end
+ return nil
+end
+
+function boolean.alwaystrue()
+ return true
+end
+
+function boolean.falsetrue()
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
+
+if not math.round then
+ function math.round(x)
+ return floor(x + 0.5)
+ end
+end
+
+if not math.div then
+ function math.div(n,m)
+ return floor(n/m)
+ end
+end
+
+if not math.mod then
+ function math.mod(n,m)
+ return n % m
+ end
+end
+
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- hm, quite unreadable
+
+if not utils then utils = { } end
+if not utils.merger then utils.merger = { } end
+if not utils.lua then utils.lua = { } end
+
+utils.merger.m_begin = "begin library merge"
+utils.merger.m_end = "end library merge"
+utils.merger.pattern =
+ "%c+" ..
+ "%-%-%s+" .. utils.merger.m_begin ..
+ "%c+(.-)%c+" ..
+ "%-%-%s+" .. utils.merger.m_end ..
+ "%c+"
+
+function utils.merger._self_fake_()
+ return
+ "-- " .. "created merged file" .. "\n\n" ..
+ "-- " .. utils.merger.m_begin .. "\n\n" ..
+ "-- " .. utils.merger.m_end .. "\n\n"
+end
+
+function utils.report(...)
+ print(...)
+end
+
+utils.merger.strip_comment = true
+
+function utils.merger._self_load_(name)
+ local f, data = io.open(name), ""
+ if f then
+ utils.report("reading merge from %s",name)
+ data = f:read("*all")
+ f:close()
+ else
+ utils.report("unknown file to merge %s",name)
+ end
+ if data and utils.merger.strip_comment then
+ -- saves some 20K
+ data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
+ end
+ return data or ""
+end
+
+function utils.merger._self_save_(name, data)
+ if data ~= "" then
+ local f = io.open(name,'w')
+ if f then
+ utils.report("saving merge from %s",name)
+ f:write(data)
+ f:close()
+ end
+ end
+end
+
+function utils.merger._self_swap_(data,code)
+ if data ~= "" then
+ return (data:gsub(utils.merger.pattern, function(s)
+ return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
+ end, 1))
+ else
+ return ""
+ end
+end
+
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
+function utils.merger._self_libs_(libs,list)
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
+ if type(libs) == 'string' then libs = { libs } end
+ if type(list) == 'string' then list = { list } end
+ local foundpath = nil
+ for _, lib in ipairs(libs) do
+ for _, pth in ipairs(list) do
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
+ else
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
+ end
+ end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
+ end
+ return table.concat(result, "\n\n")
+end
+
+function utils.merger.selfcreate(libs,list,target)
+ if target then
+ utils.merger._self_save_(
+ target,
+ utils.merger._self_swap_(
+ utils.merger._self_fake_(),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+ end
+end
+
+function utils.merger.selfmerge(name,libs,list,target)
+ utils.merger._self_save_(
+ target or name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+end
+
+function utils.merger.selfclean(name)
+ utils.merger._self_save_(
+ name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ ""
+ )
+ )
+end
+
+function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
+ -- utils.report("compiling",luafile,"into",lucfile)
+ os.remove(lucfile)
+ local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
+ if strip ~= false then
+ command = "-s " .. command
+ end
+ local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
+ if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
+ -- utils.report("removing",luafile)
+ os.remove(luafile)
+ end
+ return done
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-tab'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
The parser used here is inspired by the variant discussed in the lua book, but
+handles comment and processing instructions, has a different structure, provides
+parent access; a first version used different trickery but was less optimized to we
+went this route. First we had a find based parser, now we have an based one.
+The find based parser can be found in l-xml-edu.lua along with other older code.
+
+
Expecially the lpath code is experimental, we will support some of xpath, but
+only things that make sense for us; as compensation it is possible to hook in your
+own functions. Apart from preprocessing content for we also need
+this module for process management, like handling and
+files.
Beware, the interface may change. For instance at, ns, tg, dt may get more
+verbose names. Once the code is stable we will also remove some tracing and
+optimize the code.
+--ldx]]--
+
+xml = xml or { }
+
+--~ local xml = xml
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, setmetatable = type, next, setmetatable
+local format, lower, find = string.format, string.lower, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers.
+--ldx]]--
+
+local trace_remap = false
+
+if trackers then
+ trackers.register("xml.remap", function(v) trace_remap = v end)
+end
+
+function xml.settrace(str,value)
+ if str == "remap" then
+ trace_remap = value or false
+ end
+end
+
+--[[ldx--
+
First a hack to enable namespace resolving. A namespace is characterized by
+a . The following function associates a namespace prefix with a
+pattern. We use , which in this case is more than twice as fast as a
+find based solution where we loop over an array of patterns. Less code and
+much cleaner.
The next function also registers a namespace, but this time we map a
+given namespace prefix onto a registered one, using the given
+. This used for attributes like xmlns:m.
+
+
+xml.checkns("m","http://www.w3.org/mathml")
+
+--ldx]]--
+
+function xml.checkns(namespace,url)
+ local ns = parse:match(lower(url))
+ if ns and namespace ~= ns then
+ xml.xmlns[namespace] = ns
+ end
+end
+
+--[[ldx--
+
Next we provide a way to turn an into a registered
+namespace. This used for the xmlns attribute.
A namespace in an element can be remapped onto the registered
+one efficiently by using the xml.xmlns table.
+--ldx]]--
+
+--[[ldx--
+
This version uses . We follow the same approach as before, stack and top and
+such. This version is about twice as fast which is mostly due to the fact that
+we don't have to prepare the stream for cdata, doctype etc etc. This variant is
+is dedicated to Luigi Scarso, who challenged me with 40 megabyte files that
+took 12.5 seconds to load (1.5 for file io and the rest for tree building). With
+the implementation we got that down to less 7.3 seconds. Loading the 14
+ interface definition files (2.6 meg) went down from 1.05 seconds to 0.55.
+
+
Next comes the parser. The rather messy doctype definition comes in many
+disguises so it is no surprice that later on have to dedicate quite some
+ code to it.
+
+
+
+
+
+
+
+
+
+
+
The code may look a bit complex but this is mostly due to the fact that we
+resolve namespaces and attach metatables. There is only one public function:
+
+
+local x = xml.convert(somestring)
+
+
+
An optional second boolean argument tells this function not to create a root
+element.
+--ldx]]--
+
+xml.strip_cm_and_dt = false -- an extra global flag, in case we have many includes
+
+-- not just one big nested table capture (lpeg overflow)
+
+local nsremap, resolvens = xml.xmlns, xml.resolvens
+
+local stack, top, dt, at, xmlns, errorstr, entities = {}, {}, {}, {}, {}, nil, {}
+
+local mt = { __tostring = xml.text }
+
+function xml.check_error(top,toclose)
+ return ""
+end
+
+local strip = false
+local cleanup = false
+
+function xml.set_text_cleanup(fnc)
+ cleanup = fnc
+end
+
+local function add_attribute(namespace,tag,value)
+ if cleanup and #value > 0 then
+ value = cleanup(value) -- new
+ end
+ if tag == "xmlns" then
+ xmlns[#xmlns+1] = resolvens(value)
+ at[tag] = value
+ elseif namespace == "xmlns" then
+ xml.checkns(tag,value)
+ at["xmlns:" .. tag] = value
+ else
+ at[tag] = value
+ end
+end
+
+local function add_begin(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = stack[#stack] }
+ setmetatable(top, mt)
+ dt = top.dt
+ stack[#stack+1] = top
+ at = { }
+end
+
+local function add_end(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local toclose = remove(stack)
+ top = stack[#stack]
+ if #stack < 1 then
+ errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "")
+ elseif toclose.tg ~= tag then -- no namespace check
+ errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "")
+ end
+ dt = top.dt
+ dt[#dt+1] = toclose
+ dt[0] = top
+ if toclose.at.xmlns then
+ remove(xmlns)
+ end
+end
+
+local function add_empty(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = stack[#stack]
+ dt = top.dt
+ local t = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = top }
+ dt[#dt+1] = t
+ setmetatable(t, mt)
+ if at.xmlns then
+ remove(xmlns)
+ end
+ at = { }
+end
+
+local function add_text(text)
+ if cleanup and #text > 0 then
+ dt[#dt+1] = cleanup(text)
+ else
+ dt[#dt+1] = text
+ end
+end
+
+local function add_special(what, spacing, text)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ if strip and (what == "@cm@" or what == "@dt@") then
+ -- forget it
+ else
+ dt[#dt+1] = { special=true, ns="", tg=what, dt={text} }
+ end
+end
+
+local function set_message(txt)
+ errorstr = "garbage at the end of the file: " .. gsub(txt,"([ \n\r\t]*)","")
+end
+
+local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
+
+local space = S(' \r\n\t')
+local open = P('<')
+local close = P('>')
+local squote = S("'")
+local dquote = S('"')
+local equal = P('=')
+local slash = P('/')
+local colon = P(':')
+local valid = R('az', 'AZ', '09') + S('_-.')
+local name_yes = C(valid^1) * colon * C(valid^1)
+local name_nop = C(P(true)) * C(valid^1)
+local name = name_yes + name_nop
+
+local utfbom = P('\000\000\254\255') + P('\255\254\000\000') +
+ P('\255\254') + P('\254\255') + P('\239\187\191') -- no capture
+
+local spacing = C(space^0)
+local justtext = C((1-open)^1)
+local somespace = space^1
+local optionalspace = space^0
+
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local attribute = (somespace * name * optionalspace * equal * optionalspace * value) / add_attribute
+local attributes = attribute^0
+
+local text = justtext / add_text
+local balanced = P { "[" * ((1 - S"[]") + V(1))^0 * "]" } -- taken from lpeg manual, () example
+
+local emptyelement = (spacing * open * name * attributes * optionalspace * slash * close) / add_empty
+local beginelement = (spacing * open * name * attributes * optionalspace * close) / add_begin
+local endelement = (spacing * open * slash * name * optionalspace * close) / add_end
+
+local begincomment = open * P("!--")
+local endcomment = P("--") * close
+local begininstruction = open * P("?")
+local endinstruction = P("?") * close
+local begincdata = open * P("![CDATA[")
+local endcdata = P("]]") * close
+
+local someinstruction = C((1 - endinstruction)^0)
+local somecomment = C((1 - endcomment )^0)
+local somecdata = C((1 - endcdata )^0)
+
+local function entity(k,v) entities[k] = v end
+
+local begindoctype = open * P("!DOCTYPE")
+local enddoctype = close
+local beginset = P("[")
+local endset = P("]")
+local doctypename = C((1-somespace)^0)
+local elementdoctype = optionalspace * P("Packaging data in an xml like table is done with the following
+function. Maybe it will go away (when not used).
+--ldx]]--
+
+function xml.is_valid(root)
+ return root and root.dt and root.dt[1] and type(root.dt[1]) == "table" and not root.dt[1].er
+end
+
+function xml.package(tag,attributes,data)
+ local ns, tg = tag:match("^(.-):?([^:]+)$")
+ local t = { ns = ns, tg = tg, dt = data or "", at = attributes or {} }
+ setmetatable(t, mt)
+ return t
+end
+
+function xml.is_valid(root)
+ return root and not root.error
+end
+
+xml.error_handler = (logs and logs.report) or (input and logs.report) or print
+
+--[[ldx--
+
We cannot load an from a filehandle so we need to load
+the whole file first. The function accepts a string representing
+a filename or a file handle.
+--ldx]]--
+
+function xml.load(filename)
+ if type(filename) == "string" then
+ local f = io.open(filename,'r')
+ if f then
+ local root = xml.convert(f:read("*all"))
+ f:close()
+ return root
+ else
+ return xml.convert("")
+ end
+ elseif filename then -- filehandle
+ return xml.convert(filename:read("*all"))
+ else
+ return xml.convert("")
+ end
+end
+
+--[[ldx--
+
When we inject new elements, we need to convert strings to
+valid trees, which is what the next function does.
+--ldx]]--
+
+function xml.toxml(data)
+ if type(data) == "string" then
+ local root = { xml.convert(data,true) }
+ return (#root > 1 and root) or root[1]
+ else
+ return data
+ end
+end
+
+--[[ldx--
+
For copying a tree we use a dedicated function instead of the
+generic table copier. Since we know what we're dealing with we
+can speed up things a bit. The second argument is not to be used!
+--ldx]]--
+
+function copy(old,tables)
+ if old then
+ tables = tables or { }
+ local new = { }
+ if not tables[old] then
+ tables[old] = new
+ end
+ for k,v in pairs(old) do
+ new[k] = (type(v) == "table" and (tables[v] or copy(v, tables))) or v
+ end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+xml.copy = copy
+
+--[[ldx--
+
In serializing the tree or parts of the tree is a major
+actitivity which is why the following function is pretty optimized resulting
+in a few more lines of code than needed. The variant that uses the formatting
+function for all components is about 15% slower than the concatinating
+alternative.
+--ldx]]--
+
+-- todo: add when not present
+
+local fallbackhandle = (tex and tex.sprint) or io.write
+
+local function serialize(e, handle, textconverter, attributeconverter, specialconverter, nocommands)
+ if not e then
+ return
+ elseif not nocommands then
+ local ec = e.command
+ if ec ~= nil then -- we can have all kind of types
+ if e.special then
+ local etg, edt = e.tg, e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ return
+ else
+ -- no need to handle any further
+ end
+ end
+ end
+ local xc = xml.command
+ if xc then
+ xc(e,ec)
+ return
+ end
+ end
+ end
+ handle = handle or fallbackhandle
+ local etg = e.tg
+ if etg then
+ if e.special then
+ local edt = e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ else
+ -- no need to handle any further
+ end
+ elseif etg == "@pi@" then
+ -- handle(format("%s?>",edt[1]))
+ handle("" .. edt[1] .. "?>")
+ elseif etg == "@cm@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@cd@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@dt@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@rt@" then
+ serialize(edt,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ else
+ local ens, eat, edt, ern = e.ns, e.at, e.dt, e.rn
+ local ats = eat and next(eat) and { } -- type test maybe faster
+ if ats then
+ if attributeconverter then
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
+ end
+ else
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,v)
+ end
+ end
+ end
+ if ern and trace_remap and ern ~= ens then
+ ens = ern
+ end
+ if ens ~= "" then
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s:%s %s>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s:%s>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ serialize(e,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s:%s>",ens,etg))
+ handle("" .. ens .. ":" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s:%s %s/>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s:%s/>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. "/>")
+ end
+ end
+ else
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s %s>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s>",etg))
+ handle("<" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local ei = edt[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s>",etg))
+ handle("" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s %s/>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s/>",etg))
+ handle("<" .. etg .. "/>")
+ end
+ end
+ end
+ end
+ elseif type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ for i=1,#e do
+ local ei = e[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ end
+end
+
+xml.serialize = serialize
+
+function xml.checkbom(root) -- can be made faster
+ if root.ri then
+ local dt, found = root.dt, false
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "table" and v.special and v.tg == "@pi" and find(v.dt,"xml.*version=") then
+ found = true
+ break
+ end
+ end
+ if not found then
+ insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } )
+ insert(dt, 2, "\n" )
+ end
+ end
+end
+
+--[[ldx--
+
At the cost of some 25% runtime overhead you can first convert the tree to a string
+and then handle the lot.
+--ldx]]--
+
+function xml.tostring(root) -- 25% overhead due to collecting
+ if root then
+ if type(root) == 'string' then
+ return root
+ elseif next(root) then -- next is faster than type (and >0 test)
+ local result = { }
+ serialize(root,function(s) result[#result+1] = s end)
+ return concat(result,"")
+ end
+ end
+ return ""
+end
+
+--[[ldx--
+
The next function operated on the content only and needs a handle function
+that accepts a string.
+--ldx]]--
+
+function xml.string(e,handle)
+ if not handle or (e.special and e.tg ~= "@rt@") then
+ -- nothing
+ elseif e.tg then
+ local edt = e.dt
+ if edt then
+ for i=1,#edt do
+ xml.string(edt[i],handle)
+ end
+ end
+ else
+ handle(e)
+ end
+end
+
+--[[ldx--
+
How you deal with saving data depends on your preferences. For a 40 MB database
+file the timing on a 2.3 Core Duo are as follows (time in seconds):
+
+
+1.3 : load data from file to string
+6.1 : convert string into tree
+5.3 : saving in file using xmlsave
+6.8 : converting to string using xml.tostring
+3.6 : saving converted string in file
+
+
+
The save function is given below.
+--ldx]]--
+
+function xml.save(root,name)
+ local f = io.open(name,"w")
+ if f then
+ xml.serialize(root,function(s) f:write(s) end)
+ f:close()
+ end
+end
+
+--[[ldx--
+
A few helpers:
+--ldx]]--
+
+function xml.body(root)
+ return (root.ri and root.dt[root.ri]) or root
+end
+
+function xml.text(root)
+ return (root and xml.tostring(root)) or ""
+end
+
+function xml.content(root) -- bugged
+ return (root and root.dt and xml.tostring(root.dt)) or ""
+end
+
+function xml.isempty(root, pattern)
+ if pattern == "" or pattern == "*" then
+ pattern = nil
+ end
+ if pattern then
+ -- todo
+ return false
+ else
+ return not root or not root.dt or #root.dt == 0 or root.dt == ""
+ end
+end
+
+--[[ldx--
+
The next helper erases an element but keeps the table as it is,
+and since empty strings are not serialized (effectively) it does
+not harm. Copying the table would take more time. Usage:
+
+
+dt[k] = xml.empty() or xml.empty(dt,k)
+
+--ldx]]--
+
+function xml.empty(dt,k)
+ if dt and k then
+ dt[k] = ""
+ return dt[k]
+ else
+ return ""
+ end
+end
+
+--[[ldx--
+
The next helper assigns a tree (or string). Usage:
+
+
+dt[k] = xml.assign(root) or xml.assign(dt,k,root)
+
+--ldx]]--
+
+function xml.assign(dt,k,root)
+ if dt and k then
+ dt[k] = (type(root) == "table" and xml.body(root)) or root
+ return dt[k]
+ else
+ return xml.body(root)
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-pth'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, lower, gmatch, gsub, find = string.format, string.lower, string.gmatch, string.gsub, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers. Here we overload a previously defined
+function.
+--ldx]]--
+
+local trace_lpath = false
+
+if trackers then
+ trackers.register("xml.lpath", function(v) trace_lpath = v end)
+end
+
+local settrace = xml.settrace -- lxml-tab
+
+function xml.settrace(str,value)
+ if str == "lpath" then
+ trace_lpath = value or false
+ else
+ settrace(str,value) -- lxml-tab
+ end
+end
+
+--[[ldx--
+
We've now arrived at an intersting part: accessing the tree using a subset
+of and since we're not compatible we call it . We
+will explain more about its usage in other documents.
+--ldx]]--
+
+local lpathcalls = 0 -- statistics
+local lpathcached = 0 -- statistics
+
+xml.functions = xml.functions or { }
+xml.expressions = xml.expressions or { }
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+local actions = {
+ [10] = "stay",
+ [11] = "parent",
+ [12] = "subtree root",
+ [13] = "document root",
+ [14] = "any",
+ [15] = "many",
+ [16] = "initial",
+ [20] = "match",
+ [21] = "match one of",
+ [22] = "match and attribute eq",
+ [23] = "match and attribute ne",
+ [24] = "match one of and attribute eq",
+ [25] = "match one of and attribute ne",
+ [27] = "has attribute",
+ [28] = "has value",
+ [29] = "fast match",
+ [30] = "select",
+ [31] = "expression",
+ [40] = "processing instruction",
+}
+
+-- a rather dumb lpeg
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+-- instead of using functions we just parse a few names which saves a call
+-- later on
+
+local lp_position = P("position()") / "ps"
+local lp_index = P("index()") / "id"
+local lp_text = P("text()") / "tx"
+local lp_name = P("name()") / "(ns~='' and ns..':'..tg)" -- "((rt.ns~='' and rt.ns..':'..rt.tg) or '')"
+local lp_tag = P("tag()") / "tg" -- (rt.tg or '')
+local lp_ns = P("ns()") / "ns" -- (rt.ns or '')
+local lp_noequal = P("!=") / "~=" + P("<=") + P(">=") + P("==")
+local lp_doequal = P("=") / "=="
+local lp_attribute = P("@") / "" * Cc("(at['") * R("az","AZ","--","__")^1 * Cc("'] or '')")
+
+local lp_lua_function = C(R("az","AZ","--","__")^1 * (P(".") * R("az","AZ","--","__")^1)^1) * P("(") / function(t) -- todo: better . handling
+ return t .. "("
+end
+
+local lp_function = C(R("az","AZ","--","__")^1) * P("(") / function(t) -- todo: better . handling
+ if expressions[t] then
+ return "expressions." .. t .. "("
+ else
+ return "expressions.error("
+ end
+end
+
+local lparent = lpeg.P("(")
+local rparent = lpeg.P(")")
+local noparent = 1 - (lparent+rparent)
+local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
+local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
+
+-- if we use a dedicated namespace then we don't need to pass rt and k
+
+local lp_special = (C(P("name")+P("text")+P("tag"))) * value / function(t,s)
+ if expressions[t] then
+ if s then
+ return "expressions." .. t .. "(r,k," .. s ..")"
+ else
+ return "expressions." .. t .. "(r,k)"
+ end
+ else
+ return "expressions.error(" .. t .. ")"
+ end
+end
+
+local converter = lpeg.Cs ( (
+ lp_position +
+ lp_index +
+ lp_text + lp_name + -- fast one
+ lp_special +
+ lp_noequal + lp_doequal +
+ lp_attribute +
+ lp_lua_function +
+ lp_function +
+1 )^1 )
+
+-- expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1
+
+local template = [[
+ return function(expressions,r,d,k,e,dt,ns,tg,id,ps)
+ local at, tx = e.at or { }, dt[1] or ""
+ return %s
+ end
+]]
+
+local function make_expression(str)
+ str = converter:match(str)
+ return str, loadstring(format(template,str))()
+end
+
+local map = { }
+
+local space = S(' \r\n\t')
+local squote = S("'")
+local dquote = S('"')
+local lparent = P('(')
+local rparent = P(')')
+local atsign = P('@')
+local lbracket = P('[')
+local rbracket = P(']')
+local exclam = P('!')
+local period = P('.')
+local eq = P('==') + P('=')
+local ne = P('<>') + P('!=')
+local star = P('*')
+local slash = P('/')
+local colon = P(':')
+local bar = P('|')
+local hat = P('^')
+local valid = R('az', 'AZ', '09') + S('_-')
+local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
+local name_nop = Cc("*") * C(valid^1)
+local name = name_yes + name_nop
+local number = C((S('+-')^0 * R('09')^1)) / tonumber
+local names = (bar^0 * name)^1
+local morenames = name * (bar^0 * name)^1
+local instructiontag = P('pi::')
+local spacing = C(space^0)
+local somespace = space^1
+local optionalspace = space^0
+local text = C(valid^0)
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local empty = 1-slash
+
+local is_eq = lbracket * atsign * name * eq * value * rbracket
+local is_ne = lbracket * atsign * name * ne * value * rbracket
+local is_attribute = lbracket * atsign * name * rbracket
+local is_value = lbracket * value * rbracket
+local is_number = lbracket * number * rbracket
+
+local nobracket = 1-(lbracket+rbracket) -- must be improved
+local is_expression = lbracket * C(((C(nobracket^1))/make_expression)) * rbracket
+
+local is_expression = lbracket * (C(nobracket^1))/make_expression * rbracket
+
+local is_one = name
+local is_none = exclam * name
+local is_one_of = ((lparent * names * rparent) + morenames)
+local is_none_of = exclam * ((lparent * names * rparent) + morenames)
+
+local stay = (period )
+local parent = (period * period ) / function( ) map[#map+1] = { 11 } end
+local subtreeroot = (slash + hat ) / function( ) map[#map+1] = { 12 } end
+local documentroot = (hat * hat ) / function( ) map[#map+1] = { 13 } end
+local any = (star ) / function( ) map[#map+1] = { 14 } end
+local many = (star * star ) / function( ) map[#map+1] = { 15 } end
+local initial = (hat * hat * hat ) / function( ) map[#map+1] = { 16 } end
+
+local match = (is_one ) / function(...) map[#map+1] = { 20, true , ... } end
+local match_one_of = (is_one_of ) / function(...) map[#map+1] = { 21, true , ... } end
+local dont_match = (is_none ) / function(...) map[#map+1] = { 20, false, ... } end
+local dont_match_one_of = (is_none_of ) / function(...) map[#map+1] = { 21, false, ... } end
+
+local match_and_eq = (is_one * is_eq ) / function(...) map[#map+1] = { 22, true , ... } end
+local match_and_ne = (is_one * is_ne ) / function(...) map[#map+1] = { 23, true , ... } end
+local dont_match_and_eq = (is_none * is_eq ) / function(...) map[#map+1] = { 22, false, ... } end
+local dont_match_and_ne = (is_none * is_ne ) / function(...) map[#map+1] = { 23, false, ... } end
+
+local match_one_of_and_eq = (is_one_of * is_eq ) / function(...) map[#map+1] = { 24, true , ... } end
+local match_one_of_and_ne = (is_one_of * is_ne ) / function(...) map[#map+1] = { 25, true , ... } end
+local dont_match_one_of_and_eq = (is_none_of * is_eq ) / function(...) map[#map+1] = { 24, false, ... } end
+local dont_match_one_of_and_ne = (is_none_of * is_ne ) / function(...) map[#map+1] = { 25, false, ... } end
+
+local has_attribute = (is_one * is_attribute) / function(...) map[#map+1] = { 27, true , ... } end
+local has_value = (is_one * is_value ) / function(...) map[#map+1] = { 28, true , ... } end
+local dont_has_attribute = (is_none * is_attribute) / function(...) map[#map+1] = { 27, false, ... } end
+local dont_has_value = (is_none * is_value ) / function(...) map[#map+1] = { 28, false, ... } end
+local position = (is_one * is_number ) / function(...) map[#map+1] = { 30, true, ... } end
+local dont_position = (is_none * is_number ) / function(...) map[#map+1] = { 30, false, ... } end
+
+local expression = (is_one * is_expression)/ function(...) map[#map+1] = { 31, true, ... } end
+local dont_expression = (is_none * is_expression)/ function(...) map[#map+1] = { 31, false, ... } end
+
+local self_expression = ( is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, true, "*", "*", ... } end
+local dont_self_expression = (exclam * is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, false, "*", "*", ... } end
+
+local instruction = (instructiontag * text ) / function(...) map[#map+1] = { 40, ... } end
+local nothing = (empty ) / function( ) map[#map+1] = { 15 } end -- 15 ?
+local crap = (1-slash)^1
+
+-- a few ugly goodies:
+
+local docroottag = P('^^') / function( ) map[#map+1] = { 12 } end
+local subroottag = P('^') / function( ) map[#map+1] = { 13 } end
+local roottag = P('root::') / function( ) map[#map+1] = { 12 } end
+local parenttag = P('parent::') / function( ) map[#map+1] = { 11 } end
+local childtag = P('child::')
+local selftag = P('self::')
+
+-- there will be more and order will be optimized
+
+local selector = (
+ instruction +
+-- many + any + -- brrr, not here !
+ parent + stay +
+ dont_position + position +
+ dont_match_one_of_and_eq + dont_match_one_of_and_ne +
+ match_one_of_and_eq + match_one_of_and_ne +
+ dont_match_and_eq + dont_match_and_ne +
+ match_and_eq + match_and_ne +
+ dont_expression + expression +
+ dont_self_expression + self_expression +
+ has_attribute + has_value +
+ dont_match_one_of + match_one_of +
+ dont_match + match +
+ many + any +
+ crap + empty
+)
+
+local grammar = P { "startup",
+ startup = (initial + documentroot + subtreeroot + roottag + docroottag + subroottag)^0 * V("followup"),
+ followup = ((slash + parenttag + childtag + selftag)^0 * selector)^1,
+}
+
+local function compose(str)
+ if not str or str == "" then
+ -- wildcard
+ return true
+ elseif str == '/' then
+ -- root
+ return false
+ else
+ map = { }
+ grammar:match(str)
+ if #map == 0 then
+ return true
+ else
+ local m = map[1][1]
+ if #map == 1 then
+ if m == 14 or m == 15 then
+ -- wildcard
+ return true
+ elseif m == 12 then
+ -- root
+ return false
+ end
+ elseif #map == 2 and m == 12 and map[2][1] == 20 then
+ -- return { { 29, map[2][2], map[2][3], map[2][4], map[2][5] } }
+ map[2][1] = 29
+ return { map[2] }
+ end
+ if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
+ insert(map, 1, { 16 })
+ end
+ -- print(gsub(table.serialize(map),"[ \n]+"," "))
+ return map
+ end
+ end
+end
+
+local cache = { }
+
+function xml.lpath(pattern,trace)
+ lpathcalls = lpathcalls + 1
+ if type(pattern) == "string" then
+ local result = cache[pattern]
+ if result == nil then -- can be false which is valid -)
+ result = compose(pattern)
+ cache[pattern] = result
+ lpathcached = lpathcached + 1
+ end
+ if trace or trace_lpath then
+ xml.lshow(result)
+ end
+ return result
+ else
+ return pattern
+ end
+end
+
+function xml.cached_patterns()
+ return cache
+end
+
+-- we run out of locals (limited to 200)
+--
+-- local fallbackreport = (texio and texio.write) or io.write
+
+function xml.lshow(pattern,report)
+-- report = report or fallbackreport
+ report = report or (texio and texio.write) or io.write
+ local lp = xml.lpath(pattern)
+ if lp == false then
+ report(" -: root\n")
+ elseif lp == true then
+ report(" -: wildcard\n")
+ else
+ if type(pattern) == "string" then
+ report(format("pattern: %s\n",pattern))
+ end
+ for k=1,#lp do
+ local v = lp[k]
+ if #v > 1 then
+ local t = { }
+ for i=2,#v do
+ local vv = v[i]
+ if type(vv) == "string" then
+ t[#t+1] = (vv ~= "" and vv) or "#"
+ elseif type(vv) == "boolean" then
+ t[#t+1] = (vv and "==") or "<>"
+ end
+ end
+ report(format("%2i: %s %s -> %s\n", k,v[1],actions[v[1]],concat(t," ")))
+ else
+ report(format("%2i: %s %s\n", k,v[1],actions[v[1]]))
+ end
+ end
+ end
+end
+
+function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
+ local t = { ... }
+-- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+ local report = (type(t[#t]) == "function" and t[#t]) or (texio and texio.write) or io.write
+ if e == nil then
+ report("\n")
+ elseif type(e) ~= "table" then
+ report(tostring(e))
+ elseif e.tg then
+ report(tostring(e) .. "\n")
+ else
+ for i=1,#e do
+ report(tostring(e[i]) .. "\n")
+ end
+ end
+end
+
+--[[ldx--
+
An is converted to a table with instructions for traversing the
+tree. Hoever, simple cases are signaled by booleans. Because we don't know in
+advance what we want to do with the found element the handle gets three arguments:
+
+
+r : the root element of the data table
+d : the data table of the result
+t : the index in the data table of the result
+
+
+
Access to the root and data table makes it possible to construct insert and delete
+functions.
+--ldx]]--
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+expressions.contains = string.find
+expressions.find = string.find
+expressions.upper = string.upper
+expressions.lower = string.lower
+expressions.number = tonumber
+expressions.boolean = toboolean
+
+expressions.oneof = function(s,...) -- slow
+ local t = {...} for i=1,#t do if s == t[i] then return true end end return false
+end
+
+expressions.error = function(str)
+ xml.error_handler("unknown function in lpath expression",str or "?")
+ return false
+end
+
+functions.text = function(root,k,n) -- unchecked, maybe one deeper
+ local t = type(t)
+ if t == "string" then
+ return t
+ else -- todo n
+ local rdt = root.dt
+ return (rdt and rdt[k]) or root[k] or ""
+ end
+end
+
+functions.name = function(d,k,n) -- ns + tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ if found then
+ local ns, tg = found.rn or found.ns or "", found.tg
+ if ns ~= "" then
+ return ns .. ":" .. tg
+ else
+ return tg
+ end
+ else
+ return ""
+ end
+end
+
+functions.tag = function(d,k,n) -- only tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ return (found and found.tg) or ""
+end
+
+expressions.text = functions.text
+expressions.name = functions.name
+expressions.tag = functions.tag
+
+local function traverse(root,pattern,handle,reverse,index,parent,wildcard) -- multiple only for tags, not for namespaces
+ if not root then -- error
+ return false
+ elseif pattern == false then -- root
+ handle(root,root.dt,root.ri)
+ return false
+ elseif pattern == true then -- wildcard
+ local rootdt = root.dt
+ if rootdt then
+ local start, stop, step = 1, #rootdt, 1
+ if reverse then
+ start, stop, step = stop, start, -1
+ end
+ for k=start,stop,step do
+ if handle(root,rootdt,root.ri or k) then return false end
+ if not traverse(rootdt[k],true,handle,reverse) then return false end
+ end
+ end
+ return false
+ elseif root.dt then
+ index = index or 1
+ local action = pattern[index]
+ local command = action[1]
+ if command == 29 then -- fast case /oeps
+ local rootdt = root.dt
+ for k=1,#rootdt do
+ local e = rootdt[k]
+ local tg = e.tg
+ if e.tg then
+ local ns = e.rn or e.ns
+ local ns_a, tg_a = action[3], action[4]
+ local matched = (ns_a == "*" or ns == ns_a) and (tg_a == "*" or tg == tg_a)
+ if not action[2] then matched = not matched end
+ if matched then
+ if handle(root,rootdt,k) then return false end
+ end
+ end
+ end
+ elseif command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ if (command == 16 or command == 12) and index == 1 then -- initial
+ -- wildcard = true
+ wildcard = command == 16 -- ok?
+ index = index + 1
+ action = pattern[index]
+ command = action and action[1] or 0 -- something is wrong
+ end
+ if command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ local rootdt = root.dt
+ local start, stop, step, n, dn = 1, #rootdt, 1, 0, 1
+ if command == 30 then
+ if action[5] < 0 then
+ start, stop, step = stop, start, -1
+ dn = -1
+ end
+ elseif reverse and index == #pattern then
+ start, stop, step = stop, start, -1
+ end
+ local idx = 0
+ local hsh = { } -- this will slooow down the lot
+ for k=start,stop,step do -- we used to have functions for all but a case is faster
+ local e = rootdt[k]
+ local ns, tg = e.rn or e.ns, e.tg
+ if tg then
+ -- we can optimize this for simple searches, but it probably does not pay off
+ hsh[tg] = (hsh[tg] or 0) + 1
+ idx = idx + 1
+ if command == 30 then
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ n = n + dn
+ if n == action[5] then
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ break
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ else
+ local matched, multiple = false, false
+ if command == 20 then -- match
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 21 then -- match one of
+ multiple = true
+ for i=3,#action,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 22 then -- eq
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ matched = matched and e.at[action[6]] == action[7]
+ elseif command == 23 then -- ne
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = mached and e.at[action[6]] ~= action[7]
+ elseif command == 24 then -- one of eq
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] == action[#action]
+ elseif command == 25 then -- one of ne
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] ~= action[#action]
+ elseif command == 27 then -- has attribute
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[5]]
+ elseif command == 28 then -- has value
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and edt and edt[1] == action[5]
+ elseif command == 31 then
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ matched = action[6](expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1)
+ end
+ end
+ if matched then -- combine tg test and at test
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ if wildcard then
+ if multiple then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ else
+ -- maybe or multiple; anyhow, check on (section|title) vs just section and title in example in lxml
+ if not traverse(e,pattern,handle,reverse,index,root) then return false end
+ end
+ end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 14 then -- any
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 15 then -- many
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root,true) then return false end
+ end
+ -- not here : 11
+ elseif command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,root,index+1) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif command == 40 and e.special and tg == "@pi@" then -- pi
+ local pi = action[2]
+ if pi ~= "" then
+ local pt = e.dt[1]
+ if pt and pt:find(pi) then
+ if handle(root,rootdt,k) then
+ return false
+ end
+ end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ end
+ else
+ -- not here : 11
+ if command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ break -- else loop
+ end
+ end
+ end
+ end
+ end
+ end
+ return true
+end
+
+xml.traverse = traverse
+
+--[[ldx--
+
Next come all kind of locators and manipulators. The most generic function here
+is xml.filter(root,pattern). All registers functions in the filters namespace
+can be path of a search path, as in:
+
+
+local r, d, k = xml.filter(root,"/a/b/c/position(4)"
+
+--ldx]]--
+
+local traverse, lpath, convert = xml.traverse, xml.lpath, xml.convert
+
+xml.filters = { }
+
+function xml.filters.default(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.attributes(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ if ekat then
+ if arguments then
+ return ekat[arguments] or "", rt, dt, dk
+ else
+ return ekat, rt, dt, dk
+ end
+ else
+ return { }, rt, dt, dk
+ end
+end
+
+function xml.filters.reverse(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.count(root,pattern,everything)
+ local n = 0
+ traverse(root, lpath(pattern), function(r,d,t)
+ if everything or type(d[t]) == "table" then
+ n = n + 1
+ end
+ end)
+ return n
+end
+
+function xml.filters.elements(root, pattern) -- == all
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e then
+ t[#t+1] = e
+ end
+ end)
+ return t
+end
+
+function xml.filters.texts(root, pattern)
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e and e.dt then
+ t[#t+1] = e.dt
+ end
+ end)
+ return t
+end
+
+function xml.filters.first(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.last(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.index(root,pattern,arguments)
+ local rt, dt, dk, reverse, i = nil, nil, nil, false, tonumber(arguments or '1') or 1
+ if i and i ~= 0 then
+ if i < 0 then
+ reverse, i = true, -i
+ end
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk, i = r, d, k, i-1 return i == 0 end, reverse)
+ if i == 0 then
+ return dt and dt[dk], rt, dt, dk
+ end
+ end
+ return nil, nil, nil, nil
+end
+
+function xml.filters.attribute(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ return (ekat and (ekat[arguments] or ekat[gsub(arguments,"^([\"\'])(.*)%1$","%2")])) or ""
+end
+
+function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
+ local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
+ if dtk then -- n
+ local dtkdt = dtk.dt
+ if not dtkdt then
+ return "", rt, dt, dk
+ elseif #dtkdt == 1 and type(dtkdt[1]) == "string" then
+ return dtkdt[1], rt, dt, dk
+ else
+ return xml.tostring(dtkdt), rt, dt, dk
+ end
+ else
+ return "", rt, dt, dk
+ end
+end
+
+function xml.filters.tag(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.tag(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+function xml.filters.name(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.name(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+--[[ldx--
+
For splitting the filter function from the path specification, we can
+use string matching or lpeg matching. Here the difference in speed is
+neglectable but the lpeg variant is more robust.
+--ldx]]--
+
+-- not faster but hipper ... although ... i can't get rid of the trailing / in the path
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+local slash = P('/')
+local name = (R("az","AZ","--","__"))^1
+local path = C(((1-slash)^0 * slash)^1)
+local argument = P { "(" * C(((1 - S("()")) + V(1))^0) * ")" }
+local action = Cc(1) * path * C(name) * argument
+local attribute = Cc(2) * path * P('@') * C(name)
+local direct = Cc(3) * Cc("../*") * slash^0 * C(name) * argument
+
+local parser = direct + action + attribute
+
+local filters = xml.filters
+local attribute_filter = xml.filters.attributes
+local default_filter = xml.filters.default
+
+-- todo: also hash, could be gc'd
+
+function xml.filter(root,pattern)
+ local kind, a, b, c = parser:match(pattern)
+ if kind == 1 or kind == 3 then
+ return (filters[b] or default_filter)(root,a,c)
+ elseif kind == 2 then
+ return attribute_filter(root,a,b)
+ else
+ return default_filter(root,pattern)
+ end
+end
+
+--~ slightly faster, but first we need a proper test file
+--~
+--~ local hash = { }
+--~
+--~ function xml.filter(root,pattern)
+--~ local h = hash[pattern]
+--~ if not h then
+--~ local kind, a, b, c = parser:match(pattern)
+--~ if kind == 1 then
+--~ h = { kind, filters[b] or default_filter, a, b, c }
+--~ elseif kind == 2 then
+--~ h = { kind, attribute_filter, a, b, c }
+--~ else
+--~ h = { kind, default_filter, a, b, c }
+--~ end
+--~ hash[pattern] = h
+--~ end
+--~ local kind = h[1]
+--~ if kind == 1 then
+--~ return h[2](root,h[2],h[4])
+--~ elseif kind == 2 then
+--~ return h[2](root,h[2],h[3])
+--~ else
+--~ return h[2](root,pattern)
+--~ end
+--~ end
+
+--[[ldx--
+
The following functions collect elements and texts.
+--ldx]]--
+
+-- still somewhat bugged
+
+function xml.collect_elements(root, pattern, ignorespaces)
+ local rr, dd = { }, { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk then
+ if ignorespaces and type(dk) == "string" and dk:find("[^%S]") then
+ -- ignore
+ else
+ local n = #rr+1
+ rr[n], dd[n] = r, dk
+ end
+ end
+ end)
+ return dd, rr
+end
+
+function xml.collect_texts(root, pattern, flatten)
+ local t = { } -- no r collector
+ traverse(root, lpath(pattern), function(r,d,k)
+ if d then
+ local ek = d[k]
+ local tx = ek and ek.dt
+ if flatten then
+ if tx then
+ t[#t+1] = xml.tostring(tx) or ""
+ else
+ t[#t+1] = ""
+ end
+ else
+ t[#t+1] = tx or ""
+ end
+ else
+ t[#t+1] = ""
+ end
+ end)
+ return t
+end
+
+function xml.collect_tags(root, pattern, nonamespace)
+ local t = { }
+ xml.traverse(root, xml.lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk and type(dk) == "table" then
+ local ns, tg = e.ns, e.tg
+ if nonamespace then
+ t[#t+1] = tg -- if needed we can return an extra table
+ elseif ns == "" then
+ t[#t+1] = tg
+ else
+ t[#t+1] = ns .. ":" .. tg
+ end
+ end
+ end)
+ return #t > 0 and {}
+end
+
+--[[ldx--
+
Often using an iterators looks nicer in the code than passing handler
+functions. The book describes how to use coroutines for that
+purpose (). This permits
+code like:
+
+
+for r, d, k in xml.elements(xml.load('text.xml'),"title") do
+ print(d[k])
+end
+
+
+
Which will print all the titles in the document. The iterator variant takes
+1.5 times the runtime of the function variant which is due to the overhead in
+creating the wrapper. So, instead of:
+
+
+function xml.filters.first(root,pattern)
+ for rt,dt,dk in xml.elements(root,pattern)
+ return dt and dt[dk], rt, dt, dk
+ end
+ return nil, nil, nil, nil
+end
+
+
+
We use the function variants in the filters.
+--ldx]]--
+
+local wrap, yield = coroutine.wrap, coroutine.yield
+
+function xml.elements(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), yield, reverse) end)
+end
+
+function xml.elements_only(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), function(r,d,k) yield(d[k]) end, reverse) end)
+end
+
+function xml.each_element(root, pattern, handle, reverse)
+ local ok
+ traverse(root, lpath(pattern), function(r,d,k) ok = true handle(r,d,k) end, reverse)
+ return ok
+end
+
+function xml.process_elements(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then
+ for i=1,#dkdt do
+ local v = dkdt[i]
+ if v.tg then handle(v) end
+ end
+ end
+ end)
+end
+
+function xml.process_attributes(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local ek = d[k]
+ local a = ek.at or { }
+ handle(a)
+ if next(a) then -- next is faster than type (and >0 test)
+ ek.at = a
+ else
+ ek.at = nil
+ end
+ end)
+end
+
+--[[ldx--
+
We've now arrives at the functions that manipulate the tree.
+--ldx]]--
+
+function xml.inject_element(root, pattern, element, prepend)
+ if root and element then
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=1,#matches do
+ local m = matches[i]
+ local r, d, k, element, edt = m[1], m[2], m[3], m[4], nil
+ if element.ri then
+ element = element.dt[element.ri].dt
+ else
+ element = element.dt
+ end
+ if r.ri then
+ edt = r.dt[r.ri].dt
+ else
+ edt = d and d[k] and d[k].dt
+ end
+ if edt then
+ local be, af
+ if prepend then
+ be, af = xml.copy(element), edt
+ else
+ be, af = edt, xml.copy(element)
+ end
+ for i=1,#af do
+ be[#be+1] = af[i]
+ end
+ if r.ri then
+ r.dt[r.ri].dt = be
+ else
+ d[k].dt = be
+ end
+ else
+ -- r.dt = element.dt -- todo
+ end
+ end
+ end
+ end
+end
+
+-- todo: copy !
+
+function xml.insert_element(root, pattern, element, before) -- todo: element als functie
+ if root and element then
+ if pattern == "/" then
+ xml.inject_element(root, pattern, element, before)
+ else
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ local r, d, k, element = m[1], m[2], m[3], m[4]
+ if not before then k = k + 1 end
+ if element.tg then
+ insert(d,k,element) -- untested
+--~ elseif element.dt then
+--~ for _,v in ipairs(element.dt) do -- i added
+--~ insert(d,k,v)
+--~ k = k + 1
+--~ end
+--~ end
+ else
+ local edt = element.dt
+ if edt then
+ for i=1,#edt do
+ insert(d,k,edt[i])
+ k = k + 1
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+xml.insert_element_after = xml.insert_element
+xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end
+xml.inject_element_after = xml.inject_element
+xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end
+
+function xml.delete_element(root, pattern)
+ local matches, deleted = { }, { }
+ local collect = function(r,d,k) matches[#matches+1] = { r, d, k } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ deleted[#deleted+1] = remove(m[2],m[3])
+ end
+ return deleted
+end
+
+function xml.replace_element(root, pattern, element)
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ traverse(root, lpath(pattern), function(rm, d, k)
+ d[k] = element.dt -- maybe not clever enough
+ end)
+ end
+end
+
+local function load_data(name) -- == io.loaddata
+ local f, data = io.open(name), ""
+ if f then
+ data = f:read("*all",'b') -- 'b' ?
+ f:close()
+ end
+ return data
+end
+
+function xml.include(xmldata,pattern,attribute,recursive,loaddata)
+ -- parse="text" (default: xml), encoding="" (todo)
+ -- attribute = attribute or 'href'
+ pattern = pattern or 'include'
+ loaddata = loaddata or load_data
+ local function include(r,d,k)
+ local ek, name = d[k], nil
+ if not attribute or attribute == "" then
+ local ekdt = ek.dt
+ name = (type(ekdt) == "table" and ekdt[1]) or ekdt
+ end
+ if not name then
+ if ek.at then
+ for a in gmatch(attribute or "href","([^|]+)") do
+ name = ek.at[a]
+ if name then break end
+ end
+ end
+ end
+ local data = (name and name ~= "" and loaddata(name)) or ""
+ if data == "" then
+ xml.empty(d,k)
+ elseif ek.at["parse"] == "text" then -- for the moment hard coded
+ d[k] = xml.escaped(data)
+ else
+ local xi = xml.convert(data)
+ if not xi then
+ xml.empty(d,k)
+ else
+ if recursive then
+ xml.include(xi,pattern,attribute,recursive,loaddata)
+ end
+ xml.assign(d,k,xi)
+ end
+ end
+ end
+ xml.each_element(xmldata, pattern, include)
+end
+
+function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space !
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then -- can be optimized
+ local t = { }
+ for i=1,#dkdt do
+ local str = dkdt[i]
+ if type(str) == "string" then
+
+ if str == "" then
+ -- stripped
+ else
+ if nolines then
+ str = gsub(str,"[ \n\r\t]+"," ")
+ end
+ if str == "" then
+ -- stripped
+ else
+ t[#t+1] = str
+ end
+ end
+ else
+ t[#t+1] = str
+ end
+ end
+ d[k].dt = t
+ end
+ end)
+end
+
+local function rename_space(root, oldspace, newspace) -- fast variant
+ local ndt = #root.dt
+ for i=1,ndt or 0 do
+ local e = root[i]
+ if type(e) == "table" then
+ if e.ns == oldspace then
+ e.ns = newspace
+ if e.rn then
+ e.rn = newspace
+ end
+ end
+ local edt = e.dt
+ if edt then
+ rename_space(edt, oldspace, newspace)
+ end
+ end
+ end
+end
+
+xml.rename_space = rename_space
+
+function xml.remap_tag(root, pattern, newtg)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].tg = newtg
+ end)
+end
+function xml.remap_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].ns = newns
+ end)
+end
+function xml.check_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ if (not dk.rn or dk.rn == "") and dk.ns == "" then
+ dk.rn = newns
+ end
+ end)
+end
+function xml.remap_name(root, pattern, newtg, newns, newrn)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ dk.tg = newtg
+ dk.ns = newns
+ dk.rn = newrn
+ end)
+end
+
+function xml.filters.found(root,pattern,check_content)
+ local found = false
+ traverse(root, lpath(pattern), function(r,d,k)
+ if check_content then
+ local dk = d and d[k]
+ found = dk and dk.dt and next(dk.dt) and true
+ else
+ found = true
+ end
+ return true
+ end)
+ return found
+end
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+function xml.statistics()
+ return {
+ lpathcalls = lpathcalls,
+ lpathcached = lpathcached,
+ }
+end
+
+-- xml.set_text_cleanup(xml.show_text_entities)
+-- xml.set_text_cleanup(xml.resolve_text_entities)
+
+--~ xml.lshow("/../../../a/(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!b[@d!='e']/f")
+
+--~ x = xml.convert([[
+--~
+--~ 01
+--~ 02
+--~ 03
+--~ OK
+--~ 05
+--~ 06
+--~ ALSO OK
+--~
+--~ ]])
+
+--~ xml.settrace("lpath",true)
+
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
+--~ xml.xshow(xml.first(x,"b[@n=='03' or @n=='08']"))
+--~ xml.xshow(xml.all (x,"b[number(@n)>2 and number(@n)<6]"))
+--~ xml.xshow(xml.first(x,"b[find(text(),'ALSO')]"))
+
+--~ str = [[
+--~
+--~
+--~ my secret
+--~
+--~ ]]
+
+--~ x = xml.convert([[
+--~ 0102xx03OK
+--~ ]])
+--~ xml.xshow(xml.first(x,"b[tag(2) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-2) == 'x']"))
+
+--~ print(xml.filter(x,"b/tag(2)"))
+--~ print(xml.filter(x,"b/tag(1)"))
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-ent'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub, find = string.format, string.gsub, string.find
+local utfchar = unicode.utf8.char
+
+--[[ldx--
+
We provide (at least here) two entity handlers. The more extensive
+resolver consults a hash first, tries to convert to next,
+and finaly calls a handler when defines. When this all fails, the
+original entity is returned.
+--ldx]]--
+
+xml.entities = xml.entities or { } -- xml.entity_handler == function
+
+function xml.entity_handler(e)
+ return format("[%s]",e)
+end
+
+local function toutf(s)
+ return utfchar(tonumber(s,16))
+end
+
+local function utfize(root)
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ -- test prevents copying if no match
+ if find(dk,".-;") then
+ d[k] = gsub(dk,"(.-);",toutf)
+ end
+ else
+ utfize(dk)
+ end
+ end
+end
+
+xml.utfize = utfize
+
+local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
+ if find(e,"^#x") then
+ return utfchar(tonumber(e:sub(3),16))
+ elseif find(e,"^#") then
+ return utfchar(tonumber(e:sub(2)))
+ else
+ local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
+ if ee then
+ return ee
+ else
+ local h = xml.entity_handler
+ return (h and h(e)) or "&" .. e .. ";"
+ end
+ end
+end
+
+local function resolve_entities(root)
+ if not root.special or root.tg == "@rt@" then
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ if find(dk,"&.-;") then
+ d[k] = gsub(dk,"&(.-);",resolve)
+ end
+ else
+ resolve_entities(dk)
+ end
+ end
+ end
+end
+
+xml.resolve_entities = resolve_entities
+
+function xml.utfize_text(str)
+ if find(str,"") then
+ return (gsub(str,"(.-);",toutf))
+ else
+ return str
+ end
+end
+
+function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
+ if find(str,"&") then
+ return (gsub(str,"&(.-);",resolve))
+ else
+ return str
+ end
+end
+
+function xml.show_text_entities(str)
+ if find(str,"&") then
+ return (gsub(str,"&(.-);","[%1]"))
+ else
+ return str
+ end
+end
+
+-- experimental, this will be done differently
+
+function xml.merge_entities(root)
+ local documententities = root.entities
+ local allentities = xml.entities
+ if documententities then
+ for k, v in next, documententities do
+ allentities[k] = v
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-mis'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat = table.concat
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub = string.format, string.gsub
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+xml.escaped_pattern = escaped
+xml.unescaped_pattern = unescaped
+xml.cleansed_pattern = cleansed
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
+
+-- dirty tricks
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
+
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
+ if index > 0 then
+ local flag, value = argument:match("^%-+(.+)=(.-)$")
+ if flag then
+ arguments[flag] = string.unquote(value or "")
+ else
+ flag = argument:match("^%-+(.+)")
+ if flag then
+ arguments[flag] = true
+ else
+ files[#files+1] = argument
+ end
+ end
+ end
+ end
+ environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
+end
+
+function environment.setargument(name,value)
+ environment.arguments[name] = value
+end
+
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
+ local arguments, sortedflags = environment.arguments, environment.sortedflags
+ if arguments[name] then
+ return arguments[name]
+ elseif partial then
+ if not sortedflags then
+ sortedflags = { }
+ for _,v in pairs(table.sortedkeys(arguments)) do
+ sortedflags[#sortedflags+1] = "^" .. v
+ end
+ environment.sortedflags = sortedflags
+ end
+ -- example of potential clash: ^mode ^modefile
+ for _,v in ipairs(sortedflags) do
+ if name:find(v) then
+ return arguments[v:sub(2,#v)]
+ end
+ end
+ end
+ return nil
+end
+
+function environment.split_arguments(separator) -- rather special, cut-off before separator
+ local done, before, after = false, { }, { }
+ for _,v in ipairs(environment.original_arguments) do
+ if not done and v == separator then
+ done = true
+ elseif done then
+ after[#after+1] = v
+ else
+ before[#before+1] = v
+ end
+ end
+ return before, after
+end
+
+function environment.reconstruct_commandline(arg,noquote)
+ arg = arg or environment.original_arguments
+ if noquote and #arg == 1 then
+ local a = arg[1]
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ return a
+ elseif next(arg) then
+ local result = { }
+ for _,a in ipairs(arg) do -- ipairs 1 .. #n
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ a = a:gsub('"','\\"') -- tricky
+ if a:find(" ") then
+ result[#result+1] = a:quote()
+ else
+ result[#result+1] = a
+ end
+ end
+ return table.join(result," ")
+ else
+ return ""
+ end
+end
+
+if arg then
+
+ -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
+ local newarg, instring = { }, false
+
+ for index, argument in ipairs(arg) do
+ if argument:find("^\"") then
+ newarg[#newarg+1] = argument:gsub("^\"","")
+ if not argument:find("\"$") then
+ instring = true
+ end
+ elseif argument:find("\"$") then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
+ instring = false
+ elseif instring then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument
+ else
+ newarg[#newarg+1] = argument
+ end
+ end
+ for i=1,-5,-1 do
+ newarg[i] = arg[i]
+ end
+
+ environment.initialize_arguments(newarg)
+ environment.original_arguments = newarg
+ environment.raw_arguments = arg
+
+ arg = { } -- prevent duplicate handling
+
+end
+
+-- weird place ... depends on a not yet loaded module
+
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
+
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
+
+environment.loadedluacode = loadfile -- can be overloaded
+
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
+
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
+
+-- the next ones can use the previous ones / combine
+
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
+ end
+ end
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
+ end
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+local statusinfo, n, registered = { }, 0, { }
+
+statistics = statistics or { }
+
+statistics.enable = true
+statistics.threshold = 0.05
+
+-- timing functions
+
+local clock = os.gettimeofday or os.clock
+
+function statistics.hastimer(instance)
+ return instance and instance.starttime
+end
+
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
+ end
+ if it == 0 then
+ instance.starttime = clock()
+ if not instance.loadtime then
+ instance.loadtime = 0
+ end
+ end
+ instance.timing = it + 1
+ end
+end
+
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
+ local starttime = instance.starttime
+ if starttime then
+ local stoptime = clock()
+ local loadtime = stoptime - starttime
+ instance.stoptime = stoptime
+ instance.loadtime = instance.loadtime + loadtime
+ if report then
+ statistics.report("load time %0.3f",loadtime)
+ end
+ instance.timing = 0
+ return loadtime
+ end
+ end
+ end
+ return 0
+end
+
+function statistics.elapsedtime(instance)
+ return format("%0.3f",(instance and instance.loadtime) or 0)
+end
+
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
+end
+
+-- general function
+
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
+end
+
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
+ end
+ statistics.enable = false
+ end
+end
+
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
+
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
+
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
+end
+
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
+end
+
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
+end
+
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
+ end
+end
+
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
+ else
+ write_nl(category .. " |")
+ end
+end
+
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
+ else
+ write_nl("")
+ end
+end
+
+local texcount = tex and tex.count
+
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
+ end
+ else
+ write(format("[%s",real))
+ end
+ else
+ write("[-")
+ end
+end
+
+function logs.tex.stop_page_number()
+ write("]")
+end
+
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
+ else
+ write_nl(format("",category))
+ end
+end
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
+ else
+ write_nl("")
+ end
+end
+
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
+
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
+end
+
+function logs.xml.stop_run()
+ write_nl("")
+end
+
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
+
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
+end
+
+function logs.xml.report_output_log()
+end
+
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
+end
+
+local level = 0
+
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
+end
+
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
+end
+
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
+end
+
+--
+
+local name, banner = 'report', 'context'
+
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
+ end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
+end
+
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
+ else
+ trackers.disable("resolvers.verbose")
+ end
+ logs.verbose = what or false
+end
+
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
+ end
+end
+
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
+
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
+ end
+end
+
+function logs.reportline() -- for scripts too
+ logs.report()
+end
+
+logs.simpleline = logs.reportline
+
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
+ end
+end
+
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
+ if f then
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
+ f:close()
+ break
+ else
+ sleep(0.1)
+ end
+ end
+end
+
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
+end
+
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
+ end
+
+ return newinstance
+
+end
+
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
+ end
+ end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
+ end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
+ end
+end
+
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
+ end
+ ie[key] = value
+ end
+ return value or ""
+end
+
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
+
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
+end
+
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
+
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
+ end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
+end
+
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
+
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
+ end
+ end
+ return t
+end
+
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
+ end
+ else
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
+ end
+ return newlist
+end
+
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
+ end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
+ end
+ return resolvers.ownpath
+end
+
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
+
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
+ end
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
+ end
+end
+
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+-- database loading
+
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
+
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
+ end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
+
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
+ end
+end
+
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
+ end
+end
+
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
+
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
+ end
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
+ end
+ end
+ end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
+ end
+ end
+ end
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
+ end
+end
+
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ end
+ end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
+ end
+ end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
+ end
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
+ end
+ end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
+ end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
+ end
+end
+
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
+end
+
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
+ else
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
+ end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
+ end
+end
+
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
+
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
+
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
+end
+
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
+end
+
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
+end
+
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
+
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
+ end
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ else
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
+ end
+
+end
+
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
+ end
+ end
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ return new
+ end
+end
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
+end
+
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
+end
+
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
+ end
+end
+
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
+ else
+ return resolvers.expanded_path_list(tmp)
+ end
+end
+
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
+
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
+end
+
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
+ end
+ return ''
+end
+
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
+
+resolvers.isreadable = { }
+
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
+ end
+ return readable
+end
+
+resolvers.isreadable.tex = resolvers.isreadable.file
+
+-- name
+-- name/name
+
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
+end
+
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
+end
+
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
+end
+
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
+
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
+end
+
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
+ else
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
+ end
+ end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
+end
+
+if not resolvers.concatinators then resolvers.concatinators = { } end
+
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
+
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
+ end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
+ end
+ instance.format = ''
+ return result
+end
+
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
+
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
+ end
+ end
+ end
+ return result
+end
+
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
+end
+
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
+
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
+
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
+
+-- main user functions
+
+function resolvers.automount()
+ -- implemented later
+end
+
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
+end
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
+end
+
+-- strtab
+
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
+end
+
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
+end
+
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
+ end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
+ end
+ return concat(s, sep or " | ")
+end
+
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
+end
+
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
+end
+
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
+end
+
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
+
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
+end
+
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
+ end
+end
+
+texconfig.kpse_init = false
+
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
+
+-- for a while
+
+input = resolvers
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
+--ldx]]--
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+
+caches = caches or { }
+
+caches.path = caches.path or nil
+caches.base = caches.base or "luatex-cache"
+caches.more = caches.more or "context"
+caches.direct = false -- true is faster but may need huge amounts of memory
+caches.tree = false
+caches.paths = caches.paths or nil
+caches.force = false
+caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
+
+function caches.temp()
+ local cachepath = nil
+ local function check(list,isenv)
+ if not cachepath then
+ for k=1,#list do
+ local v = list[k]
+ cachepath = (isenv and (os.env[v] or "")) or v or ""
+ if cachepath == "" then
+ -- next
+ else
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ break
+ elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
+ dir.mkdirs(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then
+ break
+ end
+ end
+ end
+ cachepath = nil
+ end
+ end
+ end
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
+ check(caches.defaults,true)
+ if not cachepath then
+ print("\nfatal error: there is no valid (writable) cache path defined\n")
+ os.exit()
+ elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
+ print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
+ os.exit()
+ end
+ cachepath = file.collapse_path(cachepath)
+ function caches.temp()
+ return cachepath
+ end
+ return cachepath
+end
+
+function caches.configpath()
+ return table.concat(resolvers.instance.cnffiles,";")
+end
+
+function caches.hashed(tree)
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
+end
+
+function caches.treehash()
+ local tree = caches.configpath()
+ if not tree or tree == "" then
+ return false
+ else
+ return caches.hashed(tree)
+ end
+end
+
+function caches.setpath(...)
+ if not caches.path then
+ if not caches.path then
+ caches.path = caches.temp()
+ end
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
+ end
+ end
+ if not caches.path then
+ caches.path = '.'
+ end
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
+ local pth = dir.mkdirs(caches.path,...)
+ return pth
+ end
+ caches.path = dir.expand_name(caches.path)
+ return caches.path
+end
+
+function caches.definepath(category,subcategory)
+ return function()
+ return caches.setpath(category,subcategory)
+ end
+end
+
+function caches.setluanames(path,name)
+ return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+end
+
+function caches.loaddata(path,name)
+ local tmaname, tmcname = caches.setluanames(path,name)
+ local loader = loadfile(tmcname) or loadfile(tmaname)
+ if loader then
+ return loader()
+ else
+ return false
+ end
+end
+
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
+
+function caches.iswritable(filepath,filename)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ return file.iswritable(tmaname)
+end
+
+function caches.savedata(filepath,filename,data,raw)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ local reduce, simplify = true, true
+ if raw then
+ reduce, simplify = false, false
+ end
+ if caches.direct then
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
+ else
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
+ end
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ utils.lua.compile(tmaname, tmcname, cleanup, strip)
+end
+
+-- here we use the cache for format loading (texconfig.[formatname|jobname])
+
+--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
+ if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-res'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--~ print(resolvers.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
+
+local upper, lower, gsub = string.upper, string.lower, string.gsub
+
+local prefixes = { }
+
+prefixes.environment = function(str)
+ return resolvers.clean_path(os.getenv(str) or os.getenv(upper(str)) or os.getenv(lower(str)) or "")
+end
+
+prefixes.relative = function(str,n)
+ if io.exists(str) then
+ -- nothing
+ elseif io.exists("./" .. str) then
+ str = "./" .. str
+ else
+ local p = "../"
+ for i=1,n or 2 do
+ if io.exists(p .. str) then
+ str = p .. str
+ break
+ else
+ p = p .. "../"
+ end
+ end
+ end
+ return resolvers.clean_path(str)
+end
+
+prefixes.locate = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path((fullname ~= "" and fullname) or str)
+end
+
+prefixes.filename = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.basename((fullname ~= "" and fullname) or str))
+end
+
+prefixes.pathname = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.dirname((fullname ~= "" and fullname) or str))
+end
+
+prefixes.env = prefixes.environment
+prefixes.rel = prefixes.relative
+prefixes.loc = prefixes.locate
+prefixes.kpse = prefixes.locate
+prefixes.full = prefixes.locate
+prefixes.file = prefixes.filename
+prefixes.path = prefixes.pathname
+
+local function _resolve_(method,target)
+ if prefixes[method] then
+ return prefixes[method](target)
+ else
+ return method .. ":" .. target
+ end
+end
+
+local function resolve(str)
+ if type(str) == "table" then
+ for k, v in pairs(str) do -- ipairs
+ str[k] = resolve(v) or v
+ end
+ elseif str and str ~= "" then
+ str = gsub(str,"([a-z]+):([^ \"\']*)",_resolve_)
+ end
+ return str
+end
+
+resolvers.resolve = resolve
+
+if os.uname then
+
+ for k, v in pairs(os.uname()) do
+ if not prefixes[k] then
+ prefixes[k] = function() return v end
+ end
+ end
+
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
+
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
+
+
Examples of usage can be found in the font related code.
+--ldx]]--
+
+containers = containers or { }
+
+containers.usecache = true
+
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
+
+local allocated = { }
+
+-- tracing
+
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
+
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
+ end
+ end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
+
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
+ end
+ report(container,"stored",name)
+ container.storage[name] = data
+ end
+ return data
+end
+
+function containers.content(container,name)
+ return container.storage[name]
+end
+
+function containers.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+-- since we want to use the cache instead of the tree, we will now
+-- reimplement the saver.
+
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
+
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
+
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
+ else
+ return file.join(cachename,dataname)
+ end
+ end)
+end
+
+function resolvers.load_data(pathname,dataname,filename)
+ load_data(pathname,dataname,filename,function(dataname,filename)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
+ else
+ if not filename or (filename == "") then
+ filename = dataname
+ end
+ return file.join(pathname,filename)
+ end
+ end)
+end
+
+-- we will make a better format, maybe something xml or just text or lua
+
+resolvers.automounted = resolvers.automounted or { }
+
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
+ if table.is_empty(mountpaths) and usecache then
+ mountpaths = { caches.setpath("mount") }
+ end
+ if not table.is_empty(mountpaths) then
+ statistics.starttiming(resolvers.instance)
+ for k, root in pairs(mountpaths) do
+ local f = io.open(root.."/url.tmi")
+ if f then
+ for line in f:lines() do
+ if line then
+ if line:find("^[%%#%-]") then -- or %W
+ -- skip
+ elseif line:find("^zip://") then
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
+ end
+ end
+ end
+ f:close()
+ end
+ end
+ statistics.stoptiming(resolvers.instance)
+ end
+end
+
+-- status info
+
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
+
+-- experiment (code will move)
+
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
+ end
+end
+
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
+ else
+ return "invalid status file"
+ end
+ else
+ return "missing status file"
+ end
+ end
+ return true
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-zip'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, find = string.format, string.find
+
+local trace_locating, trace_verbose = false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trace_verbose = v end)
+
+zip = zip or { }
+zip.archives = zip.archives or { }
+zip.registeredfiles = zip.registeredfiles or { }
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+local locators, hashers, concatinators = resolvers.locators, resolvers.hashers, resolvers.concatinators
+
+local archives = zip.archives
+
+-- zip:///oeps.zip?name=bla/bla.tex
+-- zip:///oeps.zip?tree=tex/texmf-local
+
+local function validzip(str) -- todo: use url splitter
+ if not find(str,"^zip://") then
+ return "zip:///" .. str
+ else
+ return str
+ end
+end
+
+function zip.openarchive(name)
+ if not name or name == "" then
+ return nil
+ else
+ local arch = archives[name]
+ if not arch then
+ local full = resolvers.find_file(name) or ""
+ arch = (full ~= "" and zip.open(full)) or false
+ archives[name] = arch
+ end
+ return arch
+ end
+end
+
+function zip.closearchive(name)
+ if not name or (name == "" and archives[name]) then
+ zip.close(archives[name])
+ archives[name] = nil
+ end
+end
+
+-- zip:///texmf.zip?tree=/tex/texmf
+-- zip:///texmf.zip?tree=/tex/texmf-local
+-- zip:///texmf-mine.zip?tree=/tex/texmf-projects
+
+function locators.zip(specification) -- where is this used? startup zips (untested)
+ specification = resolvers.splitmethod(specification)
+ local zipfile = specification.path
+ local zfile = zip.openarchive(name) -- tricky, could be in to be initialized tree
+ if trace_locating then
+ if zfile then
+ logs.report("fileio",'! zip locator, found: %s',specification.original)
+ else
+ logs.report("fileio",'? zip locator, not found: %s',specification.original)
+ end
+ end
+end
+
+function hashers.zip(tag,name)
+ if trace_verbose then
+ logs.report("fileio","loading zip file %s as %s",name,tag)
+ end
+ resolvers.usezipfile(format("%s?tree=%s",tag,name))
+end
+
+function concatinators.zip(tag,path,name)
+ if not path or path == "" then
+ return format('%s?name=%s',tag,name)
+ else
+ return format('%s?name=%s/%s',tag,path,name)
+ end
+end
+
+function resolvers.isreadable.zip(name)
+ return true
+end
+
+function finders.zip(specification,filetype)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'! zip finder, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ dfile = zfile:close()
+ if trace_locating then
+ logs.report("fileio",'+ zip finder, name: %s',q.name)
+ end
+ return specification.original
+ end
+ elseif trace_locating then
+ logs.report("fileio",'? zip finder, path %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip finder, name: %s',filename)
+ end
+ return unpack(finders.notfound)
+end
+
+function openers.zip(specification)
+ local zipspecification = resolvers.splitmethod(specification)
+ if zipspecification.path then
+ local q = url.query(zipspecification.query)
+ if q.name then
+ local zfile = zip.openarchive(zipspecification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',zipspecification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_open(specification)
+ return openers.text_opener(specification,dfile,'zip')
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path %s',zipspecification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip opener, name: %s',filename)
+ end
+ return unpack(openers.notfound)
+end
+
+function loaders.zip(specification)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_load(filename)
+ if trace_locating then
+ logs.report("fileio",'+ zip loader, name: %s',filename)
+ end
+ local s = dfile:read("*all")
+ dfile:close()
+ return true, s, #s
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path: %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip loader, name: %s',filename)
+ end
+ return unpack(openers.notfound)
+end
+
+-- zip:///somefile.zip
+-- zip:///somefile.zip?tree=texmf-local -> mount
+
+function resolvers.usezipfile(zipname)
+ zipname = validzip(zipname)
+ if trace_locating then
+ logs.report("fileio",'! zip use, file: %s',zipname)
+ end
+ local specification = resolvers.splitmethod(zipname)
+ local zipfile = specification.path
+ if zipfile and not zip.registeredfiles[zipname] then
+ local tree = url.query(specification.query).tree or ""
+ if trace_locating then
+ logs.report("fileio",'! zip register, file: %s',zipname)
+ end
+ local z = zip.openarchive(zipfile)
+ if z then
+ local instance = resolvers.instance
+ if trace_locating then
+ logs.report("fileio","= zipfile, registering: %s",zipname)
+ end
+ statistics.starttiming(instance)
+ resolvers.prepend_hash('zip',zipname,zipfile)
+ resolvers.extend_texmf_var(zipname) -- resets hashes too
+ zip.registeredfiles[zipname] = z
+ instance.files[zipname] = resolvers.register_zip_file(z,tree or "")
+ statistics.stoptiming(instance)
+ elseif trace_locating then
+ logs.report("fileio","? zipfile, unknown: %s",zipname)
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! zip register, no file: %s',zipname)
+ end
+end
+
+function resolvers.register_zip_file(z,tree)
+ local files, filter = { }, ""
+ if tree == "" then
+ filter = "^(.+)/(.-)$"
+ else
+ filter = format("^%s/(.+)/(.-)$",tree)
+ end
+ if trace_locating then
+ logs.report("fileio",'= zip filter: %s',filter)
+ end
+ local register, n = resolvers.register_file, 0
+ for i in z:files() do
+ local path, name = i.filename:match(filter)
+ if path then
+ if name and name ~= '' then
+ register(files, name, path)
+ n = n + 1
+ else
+ -- directory
+ end
+ else
+ register(files, i.filename, '')
+ n = n + 1
+ end
+ end
+ logs.report("fileio",'= zip entries: %s',n)
+ return files
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-crl'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+curl = curl or { }
+
+curl.cached = { }
+curl.cachepath = caches.definepath("curl")
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+
+function curl.fetch(protocol, name)
+ local cachename = curl.cachepath() .. "/" .. name:gsub("[^%a%d%.]+","-")
+-- cachename = cachename:gsub("[\\/]", io.fileseparator)
+ cachename = cachename:gsub("[\\]", "/") -- cleanup
+ if not curl.cached[name] then
+ if not io.exists(cachename) then
+ curl.cached[name] = cachename
+ local command = "curl --silent --create-dirs --output " .. cachename .. " " .. name -- no protocol .. "://"
+ os.spawn(command)
+ end
+ if io.exists(cachename) then
+ curl.cached[name] = cachename
+ else
+ curl.cached[name] = ""
+ end
+ end
+ return curl.cached[name]
+end
+
+function finders.curl(protocol,filename)
+ local foundname = curl.fetch(protocol, filename)
+ return finders.generic(protocol,foundname,filetype)
+end
+
+function openers.curl(protocol,filename)
+ return openers.generic(protocol,filename)
+end
+
+function loaders.curl(protocol,filename)
+ return loaders.generic(protocol,filename)
+end
+
+-- todo: metamethod
+
+function curl.install(protocol)
+ finders[protocol] = function (filename,filetype) return finders.curl(protocol,filename) end
+ openers[protocol] = function (filename) return openers.curl(protocol,filename) end
+ loaders[protocol] = function (filename) return loaders.curl(protocol,filename) end
+end
+
+curl.install('http')
+curl.install('https')
+curl.install('ftp')
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- loads *.tmf files in minimal tree roots (to be optimized and documented)
+
+function resolvers.check_environment(tree)
+ logs.simpleline()
+ os.setenv('TMP', os.getenv('TMP') or os.getenv('TEMP') or os.getenv('TMPDIR') or os.getenv('HOME'))
+ os.setenv('TEXOS', os.getenv('TEXOS') or ("texmf-" .. os.currentplatform()))
+ os.setenv('TEXPATH', (tree or "tex"):gsub("\/+$",''))
+ os.setenv('TEXMFOS', os.getenv('TEXPATH') .. "/" .. os.getenv('TEXOS'))
+ logs.simpleline()
+ logs.simple("preset : TEXPATH => %s", os.getenv('TEXPATH'))
+ logs.simple("preset : TEXOS => %s", os.getenv('TEXOS'))
+ logs.simple("preset : TEXMFOS => %s", os.getenv('TEXMFOS'))
+ logs.simple("preset : TMP => %s", os.getenv('TMP'))
+ logs.simple('')
+end
+
+function resolvers.load_environment(name) -- todo: key=value as well as lua
+ local f = io.open(name)
+ if f then
+ for line in f:lines() do
+ if line:find("^[%%%#]") then
+ -- skip comment
+ else
+ local key, how, value = line:match("^(.-)%s*([<=>%?]+)%s*(.*)%s*$")
+ if how then
+ value = value:gsub("%%(.-)%%", function(v) return os.getenv(v) or "" end)
+ if how == "=" or how == "<<" then
+ os.setenv(key,value)
+ elseif how == "?" or how == "??" then
+ os.setenv(key,os.getenv(key) or value)
+ elseif how == "<" or how == "+=" then
+ if os.getenv(key) then
+ os.setenv(key,os.getenv(key) .. io.fileseparator .. value)
+ else
+ os.setenv(key,value)
+ end
+ elseif how == ">" or how == "=+" then
+ if os.getenv(key) then
+ os.setenv(key,value .. io.pathseparator .. os.getenv(key))
+ else
+ os.setenv(key,value)
+ end
+ end
+ end
+ end
+ end
+ f:close()
+ end
+end
+
+function resolvers.load_tree(tree)
+ if tree and tree ~= "" then
+ local setuptex = 'setuptex.tmf'
+ if lfs.attributes(tree, "mode") == "directory" then -- check if not nil
+ setuptex = tree .. "/" .. setuptex
+ else
+ setuptex = tree
+ end
+ if io.exists(setuptex) then
+ resolvers.check_environment(tree)
+ resolvers.load_environment(setuptex)
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-sta'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this code is used in the updater
+
+states = states or { }
+states.data = states.data or { }
+states.hash = states.hash or { }
+states.tag = states.tag or ""
+states.filename = states.filename or ""
+
+function states.save(filename,tag)
+ tag = tag or states.tag
+ filename = file.addsuffix(filename or states.filename,'lus')
+ io.savedata(filename,
+ "-- generator : luat-sta.lua\n" ..
+ "-- state tag : " .. tag .. "\n\n" ..
+ table.serialize(states.data[tag or states.tag] or {},true)
+ )
+end
+
+function states.load(filename,tag)
+ states.filename = filename
+ states.tag = tag or "whatever"
+ states.filename = file.addsuffix(states.filename,'lus')
+ states.data[states.tag], states.hash[states.tag] = (io.exists(filename) and dofile(filename)) or { }, { }
+end
+
+function states.set_by_tag(tag,key,value,default,persistent)
+ local d, h = states.data[tag], states.hash[tag]
+ if d then
+ if type(d) == "table" then
+ local dkey, hkey = key, key
+ local pre, post = key:match("(.+)%.([^%.]+)$")
+ if pre and post then
+ for k in pre:gmatch("[^%.]+") do
+ local dk = d[k]
+ if not dk then
+ dk = { }
+ d[k] = dk
+ end
+ d = dk
+ end
+ dkey, hkey = post, key
+ end
+ if type(value) == nil then
+ value = value or default
+ elseif persistent then
+ value = value or d[dkey] or default
+ else
+ value = value or default
+ end
+ d[dkey], h[hkey] = value, value
+ elseif type(d) == "string" then
+ -- weird
+ states.data[tag], states.hash[tag] = value, value
+ end
+ end
+end
+
+function states.get_by_tag(tag,key,default)
+ local h = states.hash[tag]
+ if h and h[key] then
+ return h[key]
+ else
+ local d = states.data[tag]
+ if d then
+ for k in key:gmatch("[^%.]+") do
+ local dk = d[k]
+ if dk then
+ d = dk
+ else
+ return default
+ end
+ end
+ return d or default
+ end
+ end
+end
+
+function states.set(key,value,default,persistent)
+ states.set_by_tag(states.tag,key,value,default,persistent)
+end
+
+function states.get(key,default)
+ return states.get_by_tag(states.tag,key,default)
+end
+
+--~ states.data.update = {
+--~ ["version"] = {
+--~ ["major"] = 0,
+--~ ["minor"] = 1,
+--~ },
+--~ ["rsync"] = {
+--~ ["server"] = "contextgarden.net",
+--~ ["module"] = "minimals",
+--~ ["repository"] = "current",
+--~ ["flags"] = "-rpztlv --stats",
+--~ },
+--~ ["tasks"] = {
+--~ ["update"] = true,
+--~ ["make"] = true,
+--~ ["delete"] = false,
+--~ },
+--~ ["platform"] = {
+--~ ["host"] = true,
+--~ ["other"] = {
+--~ ["mswin"] = false,
+--~ ["linux"] = false,
+--~ ["linux-64"] = false,
+--~ ["osx-intel"] = false,
+--~ ["osx-ppc"] = false,
+--~ ["sun"] = false,
+--~ },
+--~ },
+--~ ["context"] = {
+--~ ["available"] = {"current", "beta", "alpha", "experimental"},
+--~ ["selected"] = "current",
+--~ },
+--~ ["formats"] = {
+--~ ["cont-en"] = true,
+--~ ["cont-nl"] = true,
+--~ ["cont-de"] = false,
+--~ ["cont-cz"] = false,
+--~ ["cont-fr"] = false,
+--~ ["cont-ro"] = false,
+--~ },
+--~ ["engine"] = {
+--~ ["pdftex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["pdftex"] = true,
+--~ },
+--~ },
+--~ ["luatex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ },
+--~ },
+--~ ["xetex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["xetex"] = false,
+--~ },
+--~ },
+--~ ["metapost"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["mpost"] = true,
+--~ ["metafun"] = true,
+--~ },
+--~ },
+--~ },
+--~ ["fonts"] = {
+--~ },
+--~ ["doc"] = {
+--~ },
+--~ ["modules"] = {
+--~ ["f-urwgaramond"] = false,
+--~ ["f-urwgothic"] = false,
+--~ ["t-bnf"] = false,
+--~ ["t-chromato"] = false,
+--~ ["t-cmscbf"] = false,
+--~ ["t-cmttbf"] = false,
+--~ ["t-construction-plan"] = false,
+--~ ["t-degrade"] = false,
+--~ ["t-french"] = false,
+--~ ["t-lettrine"] = false,
+--~ ["t-lilypond"] = false,
+--~ ["t-mathsets"] = false,
+--~ ["t-tikz"] = false,
+--~ ["t-typearea"] = false,
+--~ ["t-vim"] = false,
+--~ },
+--~ }
+
+--~ states.save("teststate", "update")
+--~ states.load("teststate", "update")
+
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+--~ states.set_by_tag("update","rsync.server","oeps")
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+--~ states.save("teststate", "update")
+--~ states.load("teststate", "update")
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+
+
+end -- of closure
+-- end library merge
+
+own = { } -- not local
+
+own.libs = { -- todo: check which ones are really needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-io.lua',
+ 'l-number.lua',
+ 'l-set.lua',
+ 'l-os.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-dir.lua',
+ 'l-boolean.lua',
+ 'l-math.lua',
+-- 'l-unicode.lua',
+-- 'l-tex.lua',
+ 'l-utils.lua',
+-- 'l-xml.lua',
+ 'lxml-tab.lua',
+ 'lxml-pth.lua',
+ 'lxml-ent.lua',
+ 'lxml-mis.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+ 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+ 'data-zip.lua',
+ 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-tmf.lua', -- tree files
+ -- needed ?
+ 'luat-sta.lua', -- states
+}
+
+-- We need this hack till luatex is fixed.
+--
+-- for k,v in pairs(arg) do print(k,v) end
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+-- End of hack.
+
+own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+
+own.path = string.match(own.name,"^(.+)[\\/].-$") or "."
+own.list = { '.' }
+if own.path ~= '.' then
+ table.insert(own.list,own.path)
+end
+table.insert(own.list,own.path.."/../../../tex/context/base")
+table.insert(own.list,own.path.."/mtx")
+table.insert(own.list,own.path.."/../sources")
+
+local function locate_libs()
+ for _, lib in pairs(own.libs) do
+ for _, pth in pairs(own.list) do
+ local filename = string.gsub(pth .. "/" .. lib,"\\","/")
+ local codeblob = loadfile(filename)
+ if codeblob then
+ codeblob()
+ own.list = { pth } -- speed up te search
+ break
+ end
+ end
+ end
+end
+
+if not resolvers then
+ locate_libs()
+end
+
+if not resolvers then
+ print("")
+ print("Mtxrun is unable to start up due to lack of libraries. You may")
+ print("try to run 'lua mtxrun.lua --selfmerge' in the path where this")
+ print("script is located (normally under ..../scripts/context/lua) which")
+ print("will make this script library independent.")
+ os.exit()
+end
+
+logs.setprogram('MTXrun',"TDS Runner Tool 1.22",environment.arguments["verbose"] or false)
+
+local instance = resolvers.reset()
+
+runners = runners or { } -- global
+messages = messages or { }
+
+messages.help = [[
+--script run an mtx script (--noquotes)
+--execute run a script or program (--noquotes)
+--resolve resolve prefixed arguments
+--ctxlua run internally (using preloaded libs)
+--locate locate given filename
+
+--autotree use texmf tree cf. env 'texmfstart_tree' or 'texmfstarttree'
+--tree=pathtotree use given texmf tree (default file: 'setuptex.tmf')
+--environment=name use given (tmf) environment file
+--path=runpath go to given path before execution
+--ifchanged=filename only execute when given file has changed (md checksum)
+--iftouched=old,new only execute when given file has changed (time stamp)
+
+--make create stubs for (context related) scripts
+--remove remove stubs (context related) scripts
+--stubpath=binpath paths where stubs wil be written
+--windows create windows (mswin) stubs
+--unix create unix (linux) stubs
+
+--verbose give a bit more info
+--engine=str target engine
+--progname=str format or backend
+
+--edit launch editor with found file
+--launch (--all) launch files like manuals, assumes os support
+
+--intern run script using built in libraries
+
+--usekpse use kpse as fallback (when no mkiv and cache installed, often slower)
+--forcekpse force using kpse (handy when no mkiv and cache installed but less functionality)
+]]
+
+runners.applications = {
+ ["lua"] = "luatex --luaonly",
+ ["luc"] = "luatex --luaonly",
+ ["pl"] = "perl",
+ ["py"] = "python",
+ ["rb"] = "ruby",
+}
+
+runners.suffixes = {
+ 'rb', 'lua', 'py', 'pl'
+}
+
+runners.registered = {
+ texexec = { 'texexec.rb', true }, -- context mkii runner (only tool not to be luafied)
+ texutil = { 'texutil.rb', true }, -- old perl based index sorter for mkii (old versions need it)
+ texfont = { 'texfont.pl', true }, -- perl script that makes mkii font metric files
+ texfind = { 'texfind.pl', false }, -- perltk based tex searching tool, mostly used at pragma
+ texshow = { 'texshow.pl', false }, -- perltk based context help system, will be luafied
+ -- texwork = { \texwork.pl', false }, -- perltk based editing environment, only used at pragma
+
+ makempy = { 'makempy.pl', true },
+ mptopdf = { 'mptopdf.pl', true },
+ pstopdf = { 'pstopdf.rb', true }, -- converts ps (and some more) images, does some cleaning (replaced)
+
+-- examplex = { 'examplex.rb', false },
+ concheck = { 'concheck.rb', false },
+
+ runtools = { 'runtools.rb', true },
+ textools = { 'textools.rb', true },
+ tmftools = { 'tmftools.rb', true },
+ ctxtools = { 'ctxtools.rb', true },
+ rlxtools = { 'rlxtools.rb', true },
+ pdftools = { 'pdftools.rb', true },
+ mpstools = { 'mpstools.rb', true },
+-- exatools = { 'exatools.rb', true },
+ xmltools = { 'xmltools.rb', true },
+-- luatools = { 'luatools.lua', true },
+ mtxtools = { 'mtxtools.rb', true },
+
+ pdftrimwhite = { 'pdftrimwhite.pl', false }
+}
+
+runners.launchers = {
+ windows = { },
+ unix = { }
+}
+
+function runners.prepare()
+ local checkname = environment.argument("ifchanged")
+ if checkname and checkname ~= "" then
+ local oldchecksum = file.loadchecksum(checkname)
+ local newchecksum = file.checksum(checkname)
+ if oldchecksum == newchecksum then
+ logs.simple("file '%s' is unchanged",checkname)
+ return "skip"
+ else
+ logs.simple("file '%s' is changed, processing started",checkname)
+ end
+ file.savechecksum(checkname)
+ end
+ local oldname, newname = string.split(environment.argument("iftouched") or "", ",")
+ if oldname and newname and oldname ~= "" and newname ~= "" then
+ if not file.needs_updating(oldname,newname) then
+ logs.simple("file '%s' and '%s' have same age",oldname,newname)
+ return "skip"
+ else
+ logs.simple("file '%s' is older than '%s'",oldname,newname)
+ end
+ end
+ local tree = environment.argument('tree') or ""
+ if environment.argument('autotree') then
+ tree = os.getenv('TEXMFSTART_TREE') or os.getenv('TEXMFSTARTTREE') or tree
+ end
+ if tree and tree ~= "" then
+ resolvers.load_tree(tree)
+ end
+ local env = environment.argument('environment') or ""
+ if env and env ~= "" then
+ for _,e in pairs(string.split(env)) do
+ -- maybe force suffix when not given
+ resolvers.load_tree(e)
+ end
+ end
+ local runpath = environment.argument("path")
+ if runpath and not lfs.chdir(runpath) then
+ logs.simple("unable to change to path '%s'",runpath)
+ return "error"
+ end
+ return "run"
+end
+
+function runners.execute_script(fullname,internal)
+ local noquote = environment.argument("noquotes")
+ if fullname and fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ instance.progname = environment.argument("progname") or instance.progname
+ instance.format = environment.argument("format") or instance.format
+ local path, name, suffix, result = file.dirname(fullname), file.basename(fullname), file.extname(fullname), ""
+ if path ~= "" then
+ result = fullname
+ elseif name then
+ name = name:gsub("^int[%a]*:",function()
+ internal = true
+ return ""
+ end )
+ name = name:gsub("^script:","")
+ if suffix == "" and runners.registered[name] and runners.registered[name][1] then
+ name = runners.registered[name][1]
+ suffix = file.extname(name)
+ end
+ if suffix == "" then
+ -- loop over known suffixes
+ for _,s in pairs(runners.suffixes) do
+ result = resolvers.find_file(name .. "." .. s, 'texmfscripts')
+ if result ~= "" then
+ break
+ end
+ end
+ elseif runners.applications[suffix] then
+ result = resolvers.find_file(name, 'texmfscripts')
+ else
+ -- maybe look on path
+ result = resolvers.find_file(name, 'other text files')
+ end
+ end
+ if result and result ~= "" then
+ local before, after = environment.split_arguments(fullname) -- already done
+ environment.arguments_before, environment.arguments_after = before, after
+ if internal then
+ arg = { } for _,v in pairs(after) do arg[#arg+1] = v end
+ dofile(result)
+ else
+ local binary = runners.applications[file.extname(result)]
+ if binary and binary ~= "" then
+ result = binary .. " " .. result
+ end
+ local command = result .. " " .. environment.reconstruct_commandline(after,noquote)
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
+ io.flush()
+ end
+ local code = os.exec(command) -- maybe spawn
+ return code == 0
+ end
+ end
+ end
+ end
+ return false
+end
+
+function runners.execute_program(fullname)
+ local noquote = environment.argument("noquotes")
+ if fullname and fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ local before, after = environment.split_arguments(fullname)
+ environment.initialize_arguments(after)
+ fullname = fullname:gsub("^bin:","")
+ local command = fullname .. " " .. (environment.reconstruct_commandline(after or "",noquote) or "")
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
+ io.flush()
+ local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn
+ return code == 0
+ end
+ end
+ return false
+end
+
+-- the --usekpse flag will fallback on kpse
+
+local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
+local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
+
+function runners.handle_stubs(create)
+ local stubpath = environment.argument('stubpath') or '.' -- 'auto' no longer subpathssupported
+ local windows = environment.argument('windows') or environment.argument('mswin') or false
+ local unix = environment.argument('unix') or environment.argument('linux') or false
+ if not windows and not unix then
+ if os.platform == "unix" then
+ unix = true
+ else
+ windows = true
+ end
+ end
+ for _,v in pairs(runners.registered) do
+ local name, doit = v[1], v[2]
+ if doit then
+ local base = string.gsub(file.basename(name), "%.(.-)$", "")
+ if create then
+ if windows then
+ io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name))
+ logs.simple("windows stub for '%s' created",base)
+ end
+ if unix then
+ io.savedata(file.join(stubpath,base),string.format(unix_stub,name))
+ logs.simple("unix stub for '%s' created",base)
+ end
+ else
+ if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then
+ logs.simple("windows stub for '%s' removed", base)
+ end
+ if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then
+ logs.simple("unix stub for '%s' removed",base)
+ end
+ end
+ end
+ end
+end
+
+function runners.resolve_string(filename)
+ if filename and filename ~= "" then
+ runners.report_location(resolvers.resolve(filename))
+ end
+end
+
+function runners.locate_file(filename)
+ -- differs from texmfstart where locate appends .com .exe .bat ... todo
+ if filename and filename ~= "" then
+ runners.report_location(resolvers.find_given_file(filename))
+ end
+end
+
+function runners.locate_platform()
+ runners.report_location(os.currentplatform())
+end
+
+function runners.report_location(result)
+ if logs.verbose then
+ logs.simpleline()
+ if result and result ~= "" then
+ logs.simple(result)
+ else
+ logs.simple("not found")
+ end
+ else
+ io.write(result)
+ end
+end
+
+function runners.edit_script(filename) -- we assume that vim is present on most systems
+ local editor = os.getenv("MTXRUN_EDITOR") or os.getenv("TEXMFSTART_EDITOR") or os.getenv("EDITOR") or 'vim'
+ local rest = resolvers.resolve(filename)
+ if rest ~= "" then
+ local command = editor .. " " .. rest
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("starting editor: %s",command)
+ logs.simple_line()
+ logs.simple_line()
+ end
+ os.launch(command)
+ end
+end
+
+function runners.save_script_session(filename, list)
+ local t = { }
+ for _, key in ipairs(list) do
+ t[key] = environment.arguments[key]
+ end
+ io.savedata(filename,table.serialize(t,true))
+end
+
+function runners.load_script_session(filename)
+ if lfs.isfile(filename) then
+ local t = io.loaddata(filename)
+ if t then
+ t = loadstring(t)
+ if t then t = t() end
+ for key, value in pairs(t) do
+ environment.arguments[key] = value
+ end
+ end
+ end
+end
+
+function resolvers.launch(str)
+ -- maybe we also need to test on mtxrun.launcher.suffix environment
+ -- variable or on windows consult the assoc and ftype vars and such
+ local launchers = runners.launchers[os.platform] if launchers then
+ local suffix = file.extname(str) if suffix then
+ local runner = launchers[suffix] if runner then
+ str = runner .. " " .. str
+ end
+ end
+ end
+ os.launch(str)
+end
+
+function runners.launch_file(filename)
+ instance.allresults = true
+ logs.setverbose(true)
+ local pattern = environment.arguments["pattern"]
+ if not pattern or pattern == "" then
+ pattern = filename
+ end
+ if not pattern or pattern == "" then
+ logs.simple("provide name or --pattern=")
+ else
+ local t = resolvers.find_files(pattern)
+ if not t or #t == 0 then
+ t = resolvers.find_files("*/" .. pattern)
+ end
+ if not t or #t == 0 then
+ t = resolvers.find_files("*/" .. pattern .. "*")
+ end
+ if t and #t > 0 then
+ if environment.arguments["all"] then
+ for _, v in pairs(t) do
+ logs.simple("launching %s", v)
+ resolvers.launch(v)
+ end
+ else
+ logs.simple("launching %s", t[1])
+ resolvers.launch(t[1])
+ end
+ else
+ logs.simple("no match for %s", pattern)
+ end
+ end
+end
+
+function runners.find_mtx_script(filename)
+ local function found(name)
+ local path = file.dirname(name)
+ if path and path ~= "" then
+ return false
+ else
+ local fullname = own and own.path and file.join(own.path,name)
+ return io.exists(fullname) and fullname
+ end
+ end
+ filename = file.addsuffix(filename,"lua")
+ local basename = file.removesuffix(file.basename(filename))
+ local suffix = file.extname(filename)
+ -- qualified path, raw name
+ local fullname = file.is_qualified_path(filename) and io.exists(filename) and filename
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- current path, raw name
+ fullname = "./" .. filename
+ fullname = io.exists(fullname) and fullname
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-
+ fullname = "mtx-" .. filename
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-s
+ fullname = "mtx-" .. basename .. "s" .. "." .. suffix
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-
+ fullname = "mtx-" .. basename:gsub("s$","") .. "." .. suffix
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, just
+ fullname = resolvers.find_file(filename)
+ return fullname
+end
+
+function runners.execute_ctx_script(filename,arguments)
+ local fullname = runners.find_mtx_script(filename) or ""
+ -- retyr after generate but only if --autogenerate
+ if fullname == "" and environment.argument("autogenerate") then -- might become the default
+ instance.renewcache = true
+ logs.setverbose(true)
+ resolvers.load()
+ --
+ fullname = runners.find_mtx_script(filename) or ""
+ end
+ -- that should do it
+ if fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ -- load and save ... kind of undocumented
+ arg = { } for _,v in pairs(arguments) do arg[#arg+1] = resolvers.resolve(v) end
+ environment.initialize_arguments(arg)
+ local loadname = environment.arguments['load']
+ if loadname then
+ if type(loadname) ~= "string" then loadname = file.basename(fullname) end
+ loadname = file.replacesuffix(loadname,"cfg")
+ runners.load_script_session(loadname)
+ end
+ filename = environment.files[1]
+ if logs.verbose then
+ logs.simple("using script: %s\n",fullname)
+ end
+ dofile(fullname)
+ local savename = environment.arguments['save']
+ if savename and runners.save_list and not table.is_empty(runners.save_list or { }) then
+ if type(savename) ~= "string" then savename = file.basename(fullname) end
+ savename = file.replacesuffix(savename,"cfg")
+ runners.save_script_session(savename, runners.save_list)
+ end
+ return true
+ end
+ else
+ logs.setverbose(true)
+ filename = file.addsuffix(filename,"lua")
+ if filename == "" then
+ logs.simple("unknown script, no name given")
+ elseif file.is_qualified_path(filename) then
+ logs.simple("unknown script '%s'",filename)
+ else
+ logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename)
+ end
+ return false
+ end
+end
+
+function runners.timed(action)
+ statistics.timed(action)
+end
+
+-- this is a bit dirty ... first we store the first filename and next we
+-- split the arguments so that we only see the ones meant for this script
+-- ... later we will use the second half
+
+local filename = environment.files[1] or ""
+local ok = true
+
+local before, after = environment.split_arguments(filename)
+environment.arguments_before, environment.arguments_after = before, after
+environment.initialize_arguments(before)
+
+instance.engine = environment.argument("engine") or 'luatex'
+instance.progname = environment.argument("progname") or 'context'
+instance.lsrmode = environment.argument("lsr") or false
+
+-- maybe the unset has to go to this level
+
+if environment.argument("usekpse") or environment.argument("forcekpse") then
+
+ os.setenv("engine","")
+ os.setenv("progname","")
+
+ local remapper = {
+ otf = "opentype fonts",
+ ttf = "truetype fonts",
+ ttc = "truetype fonts",
+ pfb = "type1 fonts",
+ other = "other text files",
+ }
+
+ local function kpse_initialized()
+ texconfig.kpse_init = true
+ local t = os.clock()
+ local k = kpse.original.new("luatex",instance.progname)
+ local dummy = k:find_file("mtxrun.lua") -- so that we're initialized
+ logs.simple("kpse fallback with progname '%s' initialized in %s seconds",instance.progname,os.clock()-t)
+ kpse_initialized = function() return k end
+ return k
+ end
+
+ local find_file = resolvers.find_file
+ local show_path = resolvers.show_path
+
+ if environment.argument("forcekpse") then
+
+ function resolvers.find_file(name,kind)
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ function resolvers.show_path(name)
+ return (kpse_initialized():show_path(name)) or ""
+ end
+
+ elseif environment.argument("usekpse") then
+
+ resolvers.load()
+
+ function resolvers.find_file(name,kind)
+ local found = find_file(name,kind) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ end
+ function resolvers.show_path(name)
+ local found = show_path(name) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():show_path(name)) or ""
+ end
+ end
+
+ end
+
+else
+
+ resolvers.load()
+
+end
+
+
+if environment.argument("selfmerge") then
+ -- embed used libraries
+ utils.merger.selfmerge(own.name,own.libs,own.list)
+elseif environment.argument("selfclean") then
+ -- remove embedded libraries
+ utils.merger.selfclean(own.name)
+elseif environment.argument("selfupdate") then
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"mtxrun")
+elseif environment.argument("ctxlua") or environment.argument("internal") then
+ -- run a script by loading it (using libs)
+ ok = runners.execute_script(filename,true)
+elseif environment.argument("script") or environment.argument("s") then
+ -- run a script by loading it (using libs), pass args
+ ok = runners.execute_ctx_script(filename,after)
+elseif environment.argument("execute") then
+ -- execute script
+ ok = runners.execute_script(filename)
+elseif environment.argument("direct") then
+ -- equals bin:
+ ok = runners.execute_program(filename)
+elseif environment.argument("edit") then
+ -- edit file
+ runners.edit_script(filename)
+elseif environment.argument("launch") then
+ runners.launch_file(filename)
+elseif environment.argument("make") then
+ -- make stubs
+ runners.handle_stubs(true)
+elseif environment.argument("remove") then
+ -- remove stub
+ runners.handle_stubs(false)
+elseif environment.argument("resolve") then
+ -- resolve string
+ runners.resolve_string(filename)
+elseif environment.argument("locate") then
+ -- locate file
+ runners.locate_file(filename)
+elseif environment.argument("platform")then
+ -- locate platform
+ runners.locate_platform()
+elseif environment.argument("help") or filename=='help' or filename == "" then
+ logs.help(messages.help)
+ -- execute script
+elseif filename:find("^bin:") then
+ ok = runners.execute_program(filename)
+else
+ ok = runners.execute_script(filename)
+end
+
+if os.platform == "unix" then
+ io.write("\n")
+end
+
+if ok == false then ok = 1 elseif ok == true then ok = 0 end
+
+os.exit(ok)
diff --git a/scripts/context/stubs/mswin/mtxtools.bat b/scripts/context/stubs/mswin/mtxtools.bat
new file mode 100755
index 000000000..9554220c4
--- /dev/null
+++ b/scripts/context/stubs/mswin/mtxtools.bat
@@ -0,0 +1,5 @@
+@echo off
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute mtxtools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/pdftools.bat b/scripts/context/stubs/mswin/pdftools.bat
index adc48eacf..5e893fb2a 100755
--- a/scripts/context/stubs/mswin/pdftools.bat
+++ b/scripts/context/stubs/mswin/pdftools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart pdftools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute pdftools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/pdftrimwhite.bat b/scripts/context/stubs/mswin/pdftrimwhite.bat
deleted file mode 100755
index a7034b400..000000000
--- a/scripts/context/stubs/mswin/pdftrimwhite.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-texmfstart pdftrimwhite.pl %*
diff --git a/scripts/context/stubs/mswin/pstopdf.bat b/scripts/context/stubs/mswin/pstopdf.bat
index 248e34caf..f8d4325f4 100755
--- a/scripts/context/stubs/mswin/pstopdf.bat
+++ b/scripts/context/stubs/mswin/pstopdf.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart pstopdf.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute pstopdf.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/rlxtools.bat b/scripts/context/stubs/mswin/rlxtools.bat
index b78dec13b..82f09665a 100755
--- a/scripts/context/stubs/mswin/rlxtools.bat
+++ b/scripts/context/stubs/mswin/rlxtools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart rlxtools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute rlxtools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/runtools.bat b/scripts/context/stubs/mswin/runtools.bat
index 68a7b4f97..f471e747d 100755
--- a/scripts/context/stubs/mswin/runtools.bat
+++ b/scripts/context/stubs/mswin/runtools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart runtools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute runtools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texexec.bat b/scripts/context/stubs/mswin/texexec.bat
index 02b297b9c..acbe41fd8 100755
--- a/scripts/context/stubs/mswin/texexec.bat
+++ b/scripts/context/stubs/mswin/texexec.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart texexec.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute texexec.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texexec.cmd b/scripts/context/stubs/mswin/texexec.cmd
new file mode 100644
index 000000000..acbe41fd8
--- /dev/null
+++ b/scripts/context/stubs/mswin/texexec.cmd
@@ -0,0 +1,5 @@
+@echo off
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute texexec.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texfind.bat b/scripts/context/stubs/mswin/texfind.bat
deleted file mode 100755
index b7c11cbca..000000000
--- a/scripts/context/stubs/mswin/texfind.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-texmfstart texfind %*
diff --git a/scripts/context/stubs/mswin/texfont.bat b/scripts/context/stubs/mswin/texfont.bat
index 3134bf14c..98e9f7c76 100755
--- a/scripts/context/stubs/mswin/texfont.bat
+++ b/scripts/context/stubs/mswin/texfont.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart texfont.pl %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute texfont.pl %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texmfstart.cmd b/scripts/context/stubs/mswin/texmfstart.cmd
new file mode 100644
index 000000000..47a10cc54
--- /dev/null
+++ b/scripts/context/stubs/mswin/texmfstart.cmd
@@ -0,0 +1,5 @@
+@echo off
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texshow.bat b/scripts/context/stubs/mswin/texshow.bat
deleted file mode 100755
index 2060846ad..000000000
--- a/scripts/context/stubs/mswin/texshow.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-texmfstart texshow.pl %*
diff --git a/scripts/context/stubs/mswin/textools.bat b/scripts/context/stubs/mswin/textools.bat
index 727b4a36d..3b047ba7d 100755
--- a/scripts/context/stubs/mswin/textools.bat
+++ b/scripts/context/stubs/mswin/textools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart textools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute textools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/texutil.bat b/scripts/context/stubs/mswin/texutil.bat
index 1e63639bb..f01ced1a3 100755
--- a/scripts/context/stubs/mswin/texutil.bat
+++ b/scripts/context/stubs/mswin/texutil.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart texutil.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute texutil.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/tmftools.bat b/scripts/context/stubs/mswin/tmftools.bat
index c9c0c08bd..689a93c65 100755
--- a/scripts/context/stubs/mswin/tmftools.bat
+++ b/scripts/context/stubs/mswin/tmftools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart tmftools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute tmftools.rb %*
+endlocal
diff --git a/scripts/context/stubs/mswin/xmltools.bat b/scripts/context/stubs/mswin/xmltools.bat
index 2de0e4457..572cc9b8b 100755
--- a/scripts/context/stubs/mswin/xmltools.bat
+++ b/scripts/context/stubs/mswin/xmltools.bat
@@ -1,2 +1,5 @@
@echo off
-texmfstart xmltools.rb %*
+setlocal
+set ownpath=%~dp0%
+texlua "%ownpath%mtxrun.lua" --usekpse --execute xmltools.rb %*
+endlocal
diff --git a/scripts/context/stubs/unix/ctxtools b/scripts/context/stubs/unix/ctxtools
index 84e47bbee..4658a345a 100755
--- a/scripts/context/stubs/unix/ctxtools
+++ b/scripts/context/stubs/unix/ctxtools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart ctxtools.rb "$@"
+mtxrun --usekpse --execute ctxtools.rb "$@"
diff --git a/scripts/context/stubs/unix/exatools b/scripts/context/stubs/unix/exatools
deleted file mode 100755
index 50ff0f07e..000000000
--- a/scripts/context/stubs/unix/exatools
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-texmfstart exatools.rb "$@"
diff --git a/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools
new file mode 100755
index 000000000..aacdbd16d
--- /dev/null
+++ b/scripts/context/stubs/unix/luatools
@@ -0,0 +1,6977 @@
+#!/usr/bin/env texlua
+
+if not modules then modules = { } end modules ['luatools'] = {
+ version = 1.001,
+ comment = "companion to context.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+-- one can make a stub:
+--
+-- #!/bin/sh
+-- env LUATEXDIR=/....../texmf/scripts/context/lua texlua luatools.lua "$@"
+
+-- Although this script is part of the ConTeXt distribution it is
+-- relatively indepent of ConTeXt. The same is true for some of
+-- the luat files. We may may make them even less dependent in
+-- the future. As long as Luatex is under development the
+-- interfaces and names of functions may change.
+
+-- For the sake of independence we optionally can merge the library
+-- code here. It's too much code, but that does not harm. Much of the
+-- library code is used elsewhere. We don't want dependencies on
+-- Lua library paths simply because these scripts are located in the
+-- texmf tree and not in some Lua path. Normally this merge is not
+-- needed when texmfstart is used, or when the proper stub is used or
+-- when (windows) suffix binding is active.
+
+texlua = true
+
+-- begin library merge
+
+
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
+
+if not string.split then
+
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
+ end
+ end
+
+end
+
+local chr_to_esc = {
+ ["%"] = "%%",
+ ["."] = "%.",
+ ["+"] = "%+", ["-"] = "%-", ["*"] = "%*",
+ ["^"] = "%^", ["$"] = "%$",
+ ["["] = "%[", ["]"] = "%]",
+ ["("] = "%(", [")"] = "%)",
+ ["{"] = "%{", ["}"] = "%}"
+}
+
+string.chr_to_esc = chr_to_esc
+
+function string:esc() -- variant 2
+ return (gsub(self,"(.)",chr_to_esc))
+end
+
+function string:unquote()
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
+end
+
+function string:quote() -- we could use format("%q")
+ return '"' .. self:unquote() .. '"'
+end
+
+function string:count(pattern) -- variant 3
+ local n = 0
+ for _ in gmatch(self,pattern) do
+ n = n + 1
+ end
+ return n
+end
+
+function string:limit(n,sentinel)
+ if #self > n then
+ sentinel = sentinel or " ..."
+ return sub(self,1,(n-#sentinel)) .. sentinel
+ else
+ return self
+ end
+end
+
+function string:strip()
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
+end
+
+function string:is_empty()
+ return not find(find,"%S")
+end
+
+function string:enhance(pattern,action)
+ local ok, n = true, 0
+ while ok do
+ ok = false
+ self = gsub(self,pattern, function(...)
+ ok, n = true, n + 1
+ return action(...)
+ end)
+ end
+ return self, n
+end
+
+local chr_to_hex, hex_to_chr = { }, { }
+
+for i=0,255 do
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
+end
+
+function string:to_hex()
+ return (gsub(self or "","(.)",chr_to_hex))
+end
+
+function string:from_hex()
+ return (gsub(self or "","(..)",hex_to_chr))
+end
+
+if not string.characters then
+
+ local function nextchar(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, str:sub(index,index)
+ end
+ function string:characters()
+ return nextchar, self, 0
+ end
+ local function nextbyte(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
+ end
+ function string:bytes()
+ return nextbyte, self, 0
+ end
+
+end
+
+-- we can use format for this (neg n)
+
+function string:rpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self .. self.rep(chr or " ",m)
+ else
+ return self
+ end
+end
+
+function string:lpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self.rep(chr or " ",m) .. self
+ else
+ return self
+ end
+end
+
+string.padd = string.rpadd
+
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
+end
+
+--~ print(is_number("1"))
+--~ print(is_number("1.1"))
+--~ print(is_number(".1"))
+--~ print(is_number("-0.1"))
+--~ print(is_number("+0.1"))
+--~ print(is_number("-.1"))
+--~ print(is_number("+.1"))
+
+function string:split_settings() -- no {} handling, see l-aux for lpeg variant
+ if find(self,"=") then
+ local t = { }
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return nil
+ end
+end
+
+local patterns_escapes = {
+ ["-"] = "%-",
+ ["."] = "%.",
+ ["+"] = "%+",
+ ["*"] = "%*",
+ ["%"] = "%%",
+ ["("] = "%)",
+ [")"] = "%)",
+ ["["] = "%[",
+ ["]"] = "%]",
+}
+
+function string:pattesc()
+ return (gsub(self,".",patterns_escapes))
+end
+
+function string:tohash()
+ local t = { }
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
+ t[s] = true
+ end
+ return t
+end
+
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
+
+--~ l-lpeg.lua :
+
+--~ lpeg.digit = lpeg.R('09')^1
+--~ lpeg.sign = lpeg.S('+-')^1
+--~ lpeg.cardinal = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.integer = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.float = lpeg.P(lpeg.sign^0 * lpeg.digit^0 * lpeg.P('.') * lpeg.digit^1)
+--~ lpeg.number = lpeg.float + lpeg.integer
+--~ lpeg.oct = lpeg.P("0") * lpeg.R('07')^1
+--~ lpeg.hex = lpeg.P("0x") * (lpeg.R('09') + lpeg.R('AF'))^1
+--~ lpeg.uppercase = lpeg.P("AZ")
+--~ lpeg.lowercase = lpeg.P("az")
+
+--~ lpeg.eol = lpeg.S('\r\n\f')^1 -- includes formfeed
+--~ lpeg.space = lpeg.S(' ')^1
+--~ lpeg.nonspace = lpeg.P(1-lpeg.space)^1
+--~ lpeg.whitespace = lpeg.S(' \r\n\f\t')^1
+--~ lpeg.nonwhitespace = lpeg.P(1-lpeg.whitespace)^1
+
+local hash = { }
+
+function lpeg.anywhere(pattern) --slightly adapted from website
+ return P { P(pattern) + 1 * lpeg.V(1) }
+end
+
+function lpeg.startswith(pattern) --slightly adapted
+ return P(pattern)
+end
+
+function lpeg.splitter(pattern, action)
+ return (((1-P(pattern))^1)/action+1)^0
+end
+
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
+local newline = crlf + cr + lf
+local spacing = space^0 * newline
+
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
+local content = (empty + nonempty)^1
+
+local capture = Ct(content^0)
+
+function string:splitlines()
+ return capture:match(self)
+end
+
+lpeg.linebyline = content -- better make a sublibrary
+
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps")) -- oeps
+
+local splitters_s, splitters_m = { }, { }
+
+local function splitat(separator,single)
+ local splitter = (single and splitters_s[separator]) or splitters_m[separator]
+ if not splitter then
+ separator = P(separator)
+ if single then
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
+ splitters_s[separator] = splitter
+ else
+ local other = C((1 - separator)^0)
+ splitter = other * (separator * other)^0
+ splitters_m[separator] = splitter
+ end
+ end
+ return splitter
+end
+
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+table.join = table.concat
+
+local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
+local getmetatable, setmetatable = getmetatable, setmetatable
+local type, next, tostring, ipairs = type, next, tostring, ipairs
+
+function table.strip(tab)
+ local lst = { }
+ for i=1,#tab do
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
+ if s == "" then
+ -- skip this one
+ else
+ lst[#lst+1] = s
+ end
+ end
+ return lst
+end
+
+local function sortedkeys(tab)
+ local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ if kind == 3 then
+ -- no further check
+ else
+ local tkey = type(key)
+ if tkey == "string" then
+ -- if kind == 2 then kind = 3 else kind = 1 end
+ kind = (kind == 2 and 3) or 1
+ elseif tkey == "number" then
+ -- if kind == 1 then kind = 3 else kind = 2 end
+ kind = (kind == 1 and 3) or 2
+ else
+ kind = 3
+ end
+ end
+ end
+ if kind == 0 or kind == 3 then
+ sort(srt,function(a,b) return (tostring(a) < tostring(b)) end)
+ else
+ sort(srt)
+ end
+ return srt
+end
+
+local function sortedhashkeys(tab) -- fast one
+ local srt = { }
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ end
+ sort(srt)
+ return srt
+end
+
+table.sortedkeys = sortedkeys
+table.sortedhashkeys = sortedhashkeys
+
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
+function table.append(t, list)
+ for _,v in next, list do
+ insert(t,v)
+ end
+end
+
+function table.prepend(t, list)
+ for k,v in next, list do
+ insert(t,k,v)
+ end
+end
+
+function table.merge(t, ...) -- first one is target
+ t = t or {}
+ local lst = {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ t[k] = v
+ end
+ end
+ return t
+end
+
+function table.merged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ tmp[k] = v
+ end
+ end
+ return tmp
+end
+
+function table.imerge(t, ...)
+ local lst = {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ t[#t+1] = nst[j]
+ end
+ end
+ return t
+end
+
+function table.imerged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ tmp[#tmp+1] = nst[j]
+ end
+ end
+ return tmp
+end
+
+local function fastcopy(old) -- fast one
+ if old then
+ local new = { }
+ for k,v in next, old do
+ if type(v) == "table" then
+ new[k] = fastcopy(v) -- was just table.copy
+ else
+ new[k] = v
+ end
+ end
+ -- optional second arg
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+local function copy(t, tables) -- taken from lua wiki, slightly adapted
+ tables = tables or { }
+ local tcopy = {}
+ if not tables[t] then
+ tables[t] = tcopy
+ end
+ for i,v in next, t do -- brrr, what happens with sparse indexed
+ if type(i) == "table" then
+ if tables[i] then
+ i = tables[i]
+ else
+ i = copy(i, tables)
+ end
+ end
+ if type(v) ~= "table" then
+ tcopy[i] = v
+ elseif tables[v] then
+ tcopy[i] = tables[v]
+ else
+ tcopy[i] = copy(v, tables)
+ end
+ end
+ local mt = getmetatable(t)
+ if mt then
+ setmetatable(tcopy,mt)
+ end
+ return tcopy
+end
+
+table.fastcopy = fastcopy
+table.copy = copy
+
+-- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+
+function table.sub(t,i,j)
+ return { unpack(t,i,j) }
+end
+
+function table.replace(a,b)
+ for k,v in next, b do
+ a[k] = v
+ end
+end
+
+-- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice)
+
+function table.is_empty(t)
+ return not t or not next(t)
+end
+
+function table.one_entry(t)
+ local n = next(t)
+ return n and not next(t,n)
+end
+
+function table.starts_at(t)
+ return ipairs(t,1)(t,0)
+end
+
+function table.tohash(t,value)
+ local h = { }
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
+ end
+ return h
+end
+
+function table.fromhash(t)
+ local h = { }
+ for k, v in next, t do -- no ipairs here
+ if v then h[#h+1] = k end
+ end
+ return h
+end
+
+--~ print(table.serialize(t), "\n")
+--~ print(table.serialize(t,"name"), "\n")
+--~ print(table.serialize(t,false), "\n")
+--~ print(table.serialize(t,true), "\n")
+--~ print(table.serialize(t,"name",true), "\n")
+--~ print(table.serialize(t,"name",true,true), "\n")
+
+table.serialize_functions = true
+table.serialize_compact = true
+table.serialize_inline = true
+
+local noquotes, hexify, handle, reduce, compact, inline, functions
+
+local reserved = table.tohash { -- intercept a language flaw, no reserved words as key
+ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if',
+ 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
+}
+
+local function simple_table(t)
+ if #t > 0 then
+ local n = 0
+ for _,v in next, t do
+ n = n + 1
+ end
+ if n == #t then
+ local tt = { }
+ for i=1,#t do
+ local v = t[i]
+ local tv = type(v)
+ if tv == "number" then
+ if hexify then
+ tt[#tt+1] = format("0x%04X",v)
+ else
+ tt[#tt+1] = tostring(v) -- tostring not needed
+ end
+ elseif tv == "boolean" then
+ tt[#tt+1] = tostring(v)
+ elseif tv == "string" then
+ tt[#tt+1] = format("%q",v)
+ else
+ tt = nil
+ break
+ end
+ end
+ return tt
+ end
+ end
+ return nil
+end
+
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
+local function do_serialize(root,name,depth,level,indexed)
+ if level > 0 then
+ depth = depth .. " "
+ if indexed then
+ handle(format("%s{",depth))
+ elseif name then
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
+ else
+ handle(format("%s{",depth))
+ end
+ end
+ if root and next(root) then
+ local first, last = nil, 0 -- #root cannot be trusted here
+ if compact then
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
+ if not first then first = k end
+ last = last + 1
+ end
+ end
+ local sk = sortedkeys(root)
+ for i=1,#sk do
+ local k = sk[i]
+ local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
+ local t = type(v)
+ if compact and first and type(k) == "number" and k >= first and k <= last then
+ if t == "number" then
+ if hexify then
+ handle(format("%s 0x%04X,",depth,v))
+ else
+ handle(format("%s %s,",depth,v))
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
+ else
+ handle(format("%s %q,",depth,v))
+ end
+ elseif t == "table" then
+ if not next(v) then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
+ local st = simple_table(v)
+ if st then
+ handle(format("%s { %s },",depth,concat(st,", ")))
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ elseif t == "boolean" then
+ handle(format("%s %s,",depth,tostring(v)))
+ elseif t == "function" then
+ if functions then
+ handle(format('%s loadstring(%q),',depth,dump(v)))
+ else
+ handle(format('%s "function",',depth))
+ end
+ else
+ handle(format("%s %q,",depth,tostring(v)))
+ end
+ elseif k == "__p__" then -- parent
+ if false then
+ handle(format("%s __p__=nil,",depth))
+ end
+ elseif t == "number" then
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
+ else
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
+ end
+ elseif t == "table" then
+ if not next(v) then
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
+ elseif inline then
+ local st = simple_table(v)
+ if st then
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ elseif t == "boolean" then
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
+ elseif t == "function" then
+ if functions then
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
+ end
+ --~ end
+ end
+ end
+ if level > 0 then
+ handle(format("%s},",depth))
+ end
+end
+
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
+local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
+ noquotes = _noquotes
+ hexify = _hexify
+ handle = _handle or print
+ reduce = _reduce or false
+ compact = table.serialize_compact
+ inline = compact and table.serialize_inline
+ functions = table.serialize_functions
+ local tname = type(name)
+ if tname == "string" then
+ if name == "return" then
+ handle("return {")
+ else
+ handle(name .. "={")
+ end
+ elseif tname == "number" then
+ if hexify then
+ handle(format("[0x%04X]={",name))
+ else
+ handle("[" .. name .. "]={")
+ end
+ elseif tname == "boolean" then
+ if name then
+ handle("return {")
+ else
+ handle("{")
+ end
+ else
+ handle("t={")
+ end
+ if root and next(root) then
+ do_serialize(root,name,"",0,indexed)
+ end
+ handle("}")
+end
+
+--~ name:
+--~
+--~ true : return { }
+--~ false : { }
+--~ nil : t = { }
+--~ string : string = { }
+--~ 'return' : return { }
+--~ number : [number] = { }
+
+function table.serialize(root,name,reduce,noquotes,hexify)
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ return concat(t,"\n")
+end
+
+function table.tohandle(handle,root,name,reduce,noquotes,hexify)
+ serialize(root,name,handle,reduce,noquotes,hexify)
+end
+
+-- sometimes tables are real use (zapfino extra pro is some 85M) in which
+-- case a stepwise serialization is nice; actually, we could consider:
+--
+-- for line in table.serializer(root,name,reduce,noquotes) do
+-- ...(line)
+-- end
+--
+-- so this is on the todo list
+
+table.tofile_maxtab = 2*1024
+
+function table.tofile(filename,root,name,reduce,noquotes,hexify)
+ local f = io.open(filename,'w')
+ if f then
+ local maxtab = table.tofile_maxtab
+ if maxtab > 1 then
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ if #t > maxtab then
+ f:write(concat(t,"\n"),"\n") -- hm, write(sometable) should be nice
+ t = { }
+ end
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ f:write(concat(t,"\n"),"\n")
+ else
+ local function flush(s)
+ f:write(s,"\n")
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ end
+ f:close()
+ end
+end
+
+local function flatten(t,f,complete)
+ for i=1,#t do
+ local v = t[i]
+ if type(v) == "table" then
+ if complete or type(v[1]) == "table" then
+ flatten(v,f,complete)
+ else
+ f[#f+1] = v
+ end
+ else
+ f[#f+1] = v
+ end
+ end
+end
+
+function table.flatten(t)
+ local f = { }
+ flatten(t,f,true)
+ return f
+end
+
+function table.unnest(t) -- bad name
+ local f = { }
+ flatten(t,f,false)
+ return f
+end
+
+table.flatten_one_level = table.unnest
+
+-- the next three may disappear
+
+function table.remove_value(t,value) -- todo: n
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ remove(t,i)
+ -- remove all, so no: return
+ end
+ end
+ end
+end
+
+function table.insert_before_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i,str)
+ return
+ end
+ end
+ end
+ insert(t,1,str)
+ elseif value then
+ insert(t,1,value)
+ end
+end
+
+function table.insert_after_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i+1,str)
+ return
+ end
+ end
+ end
+ t[#t+1] = str
+ elseif value then
+ t[#t+1] = value
+ end
+end
+
+local function are_equal(a,b,n,m) -- indexed
+ if #a == #b then
+ n = n or 1
+ m = m or #a
+ for i=n,m do
+ local ai, bi = a[i], b[i]
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+ else
+ return false
+ end
+end
+
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
+function table.compact(t)
+ if t then
+ for k,v in next, t do
+ if not next(v) then
+ t[k] = nil
+ end
+ end
+ end
+end
+
+function table.contains(t, v)
+ if t then
+ for i=1, #t do
+ if t[i] == v then
+ return i
+ end
+ end
+ end
+ return false
+end
+
+function table.count(t)
+ local n, e = 0, next(t)
+ while e do
+ n, e = n + 1, next(t,e)
+ end
+ return n
+end
+
+function table.swapped(t)
+ local s = { }
+ for k, v in next, t do
+ s[v] = k
+ end
+ return s
+end
+
+--~ function table.are_equal(a,b)
+--~ return table.serialize(a) == table.serialize(b)
+--~ end
+
+function table.clone(t,p) -- t is optional or nil or table
+ if not p then
+ t, p = { }, t or { }
+ elseif not t then
+ t = { }
+ end
+ setmetatable(t, { __index = function(_,key) return p[key] end })
+ return t
+end
+
+function table.hexed(t,seperator)
+ local tt = { }
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
+ return concat(tt,seperator or " ")
+end
+
+function table.reverse_hash(h)
+ local r = { }
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
+ end
+ return r
+end
+
+function table.reverse(t)
+ local tt = { }
+ if #t > 0 then
+ for i=#t,1,-1 do
+ tt[#tt+1] = t[i]
+ end
+ end
+ return tt
+end
+
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local byte = string.byte
+
+if string.find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator = "\\", ";"
+else
+ io.fileseparator, io.pathseparator = "/" , ":"
+end
+
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
+ if f then
+ local data = f:read('*all')
+ -- garbagecollector.check(data)
+ f:close()
+ return data
+ else
+ return nil
+ end
+end
+
+function io.savedata(filename,data,joiner)
+ local f = io.open(filename,"wb")
+ if f then
+ if type(data) == "table" then
+ f:write(table.join(data,joiner or ""))
+ elseif type(data) == "function" then
+ data(f)
+ else
+ f:write(data)
+ end
+ f:close()
+ return true
+ else
+ return false
+ end
+end
+
+function io.exists(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return false
+ else
+ assert(f:close())
+ return true
+ end
+end
+
+function io.size(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return 0
+ else
+ local s = f:seek("end")
+ assert(f:close())
+ return s
+ end
+end
+
+function io.noflines(f)
+ local n = 0
+ for _ in f:lines() do
+ n = n + 1
+ end
+ f:seek('set',0)
+ return n
+end
+
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
+ end
+}
+
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
+ end
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
+ else
+ return nil, nil
+ end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
+ else
+ return nil, nil
+ end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
+ end
+}
+
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+function io.ask(question,default,options)
+ while true do
+ io.write(question)
+ if options then
+ io.write(string.format(" [%s]",table.concat(options,"|")))
+ end
+ if default then
+ io.write(string.format(" [%s]",default))
+ end
+ io.write(string.format(" "))
+ local answer = io.read()
+ answer = answer:gsub("^%s*(.*)%s*$","%1")
+ if answer == "" and default then
+ return default
+ elseif not options then
+ return answer
+ else
+ for _,v in pairs(options) do
+ if v == answer then
+ return answer
+ end
+ end
+ local pattern = "^" .. answer
+ for _,v in pairs(options) do
+ if v:find(pattern) then
+ return v
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+number = number or { }
+
+-- a,b,c,d,e,f = number.toset(100101)
+
+function number.toset(n)
+ return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
+end
+
+function number.toevenhex(n)
+ local s = format("%X",n)
+ if #s % 2 == 0 then
+ return s
+ else
+ return "0" .. s
+ end
+end
+
+-- the lpeg way is slower on 8 digits, but faster on 4 digits, some 7.5%
+-- on
+--
+-- for i=1,1000000 do
+-- local a,b,c,d,e,f,g,h = number.toset(12345678)
+-- local a,b,c,d = number.toset(1234)
+-- local a,b,c = number.toset(123)
+-- end
+--
+-- of course dedicated "(.)(.)(.)(.)" matches are even faster
+
+local one = lpeg.C(1-lpeg.S(''))^1
+
+function number.toset(n)
+ return one:match(tostring(n))
+end
+
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+set = set or { }
+
+local nums = { }
+local tabs = { }
+local concat = table.concat
+
+set.create = table.tohash
+
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
+ end
+ end
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
+ end
+ return nums[s]
+ else
+ return 0
+ end
+end
+
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
+ end
+end
+
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
+end
+
+--~ local c = set.create{'aap','noot','mies'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ local c = set.create{'zus','wim','jet'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ print(t['jet'])
+--~ print(set.contains(t,'jet'))
+--~ print(set.contains(t,'aap'))
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+function os.resultof(command)
+ return io.popen(command,"r"):read("*all")
+end
+
+if not os.exec then os.exec = os.execute end
+if not os.spawn then os.spawn = os.execute end
+
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+
+if not io.fileseparator then
+ if find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ else
+ io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ end
+end
+
+os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+
+function os.launch(str)
+ if os.platform == "windows" then
+ os.execute("start " .. str) -- os.spawn ?
+ else
+ os.execute(str .. " &") -- os.spawn ?
+ end
+end
+
+if not os.setenv then
+ function os.setenv() return false end
+end
+
+if not os.times then
+ -- utime = user time
+ -- stime = system time
+ -- cutime = children user time
+ -- cstime = children system time
+ function os.times()
+ return {
+ utime = os.gettimeofday(), -- user
+ stime = 0, -- system
+ cutime = 0, -- children user
+ cstime = 0, -- children system
+ }
+ end
+end
+
+os.gettimeofday = os.gettimeofday or os.clock
+
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
+end
+
+--~ print(os.gettimeofday()-os.time())
+--~ os.sleep(1.234)
+--~ print (">>",os.runtime())
+--~ print(os.date("%H:%M:%S",os.gettimeofday()))
+--~ print(os.date("%H:%M:%S",os.time()))
+
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
+
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- needs a cleanup
+
+file = file or { }
+
+local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
+end
+
+function file.addsuffix(filename, suffix)
+ if not find(filename,"%.[%a%d]+$") then
+ return filename .. "." .. suffix
+ else
+ return filename
+ end
+end
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
+
+function file.dirname(name)
+ return match(name,"^(.+)[/\\].-$") or ""
+end
+
+function file.basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
+end
+
+function file.nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+end
+
+function file.extname(name)
+ return match(name,"^.+%.([^/\\]-)$") or ""
+end
+
+file.suffix = file.extname
+
+--~ print(file.join("x/","/y"))
+--~ print(file.join("http://","/y"))
+--~ print(file.join("http://a","/y"))
+--~ print(file.join("http:///a","/y"))
+--~ print(file.join("//nas-1","/y"))
+
+function file.join(...)
+ local pth = concat({...},"/")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ a, b = match(pth,"^(//)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ return (gsub(pth,"//+","/"))
+end
+
+function file.iswritable(name)
+ local a = lfs.attributes(name)
+ if a and a.permissions:sub(2,2) == "w" then
+ return true
+ else
+ name = file.dirname(name) or "."
+ if name == "" then name = "." end
+ a = lfs.attributes(name)
+ return a and a.permissions:sub(2,2) == "w"
+ end
+end
+
+function file.isreadable(name)
+ local a = lfs.attributes(name)
+ return a and a.permissions:sub(1,1) == "r"
+end
+
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
+
+-- todo: lpeg
+
+function file.split_path(str)
+ local t = { }
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
+ if name ~= "" then
+ t[#t+1] = gsub(name,"\001",":")
+ end
+ end
+ return t
+end
+
+function file.join_path(tab)
+ return concat(tab,io.pathseparator) -- can have trailing //
+end
+
+function file.collapse_path(str)
+ str = gsub(str,"/%./","/")
+ local n, m = 1, 1
+ while n > 0 or m > 0 do
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
+ end
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
+ if str == "" then str = "." end
+ return str
+end
+
+--~ print(file.collapse_path("a/./b/.."))
+--~ print(file.collapse_path("a/aa/../b/bb"))
+--~ print(file.collapse_path("a/../.."))
+--~ print(file.collapse_path("a/.././././b/.."))
+--~ print(file.collapse_path("a/./././b/.."))
+--~ print(file.collapse_path("a/b/c/../.."))
+
+function file.robustname(str)
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
+end
+
+file.readdata = io.loaddata
+file.savedata = io.savedata
+
+function file.copy(oldname,newname)
+ file.savedata(newname,io.loaddata(oldname))
+end
+
+-- lpeg variants, slightly faster, not always
+
+--~ local period = lpeg.P(".")
+--~ local slashes = lpeg.S("\\/")
+--~ local noperiod = 1-period
+--~ local noslashes = 1-slashes
+--~ local name = noperiod^1
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.C(noperiod^1) * -1
+
+--~ function file.extname(name)
+--~ return pattern:match(name) or ""
+--~ end
+
+--~ local pattern = lpeg.Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+
+--~ function file.removesuffix(name)
+--~ return pattern:match(name)
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
+
+--~ function file.basename(name)
+--~ return pattern:match(name) or name
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.Cp() * noslashes^1 * -1
+
+--~ function file.dirname(name)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2)
+--~ else
+--~ return ""
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.addsuffix(name, suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.replacesuffix(name,suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2) .. "." .. suffix
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * lpeg.Cp() * ((noperiod^1 * period)^1 * lpeg.Cp() + lpeg.P(true)) * noperiod^1 * -1
+
+--~ function file.nameonly(name)
+--~ local a, b = pattern:match(name)
+--~ if b then
+--~ return name:sub(a,b-2)
+--~ elseif a then
+--~ return name:sub(a)
+--~ else
+--~ return name
+--~ end
+--~ end
+
+--~ local test = file.extname
+--~ local test = file.basename
+--~ local test = file.dirname
+--~ local test = file.addsuffix
+--~ local test = file.replacesuffix
+--~ local test = file.nameonly
+
+--~ print(1,test("./a/b/c/abd.def.xxx","!!!"))
+--~ print(2,test("./../b/c/abd.def.xxx","!!!"))
+--~ print(3,test("a/b/c/abd.def.xxx","!!!"))
+--~ print(4,test("a/b/c/def.xxx","!!!"))
+--~ print(5,test("a/b/c/def","!!!"))
+--~ print(6,test("def","!!!"))
+--~ print(7,test("def.xxx","!!!"))
+
+--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEXsum(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-url'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local char, gmatch = string.char, string.gmatch
+local tonumber, type = tonumber, type
+
+-- from the spec (on the web):
+--
+-- foo://example.com:8042/over/there?name=ferret#nose
+-- \_/ \______________/\_________/ \_________/ \__/
+-- | | | | |
+-- scheme authority path query fragment
+-- | _____________________|__
+-- / \ / \
+-- urn:example:animal:ferret:nose
+
+url = url or { }
+
+local function tochar(s)
+ return char(tonumber(s,16))
+end
+
+local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
+
+local hexdigit = lpeg.R("09","AF","af")
+local plus = lpeg.P("+")
+local escaped = (plus / " ") + (percent * lpeg.C(hexdigit * hexdigit) / tochar)
+
+local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
+local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
+local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
+local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
+local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
+
+local parser = lpeg.Ct(scheme * authority * path * query * fragment)
+
+function url.split(str)
+ return (type(str) == "string" and parser:match(str)) or str
+end
+
+function url.hashed(str)
+ local s = url.split(str)
+ return {
+ scheme = (s[1] ~= "" and s[1]) or "file",
+ authority = s[2],
+ path = s[3],
+ query = s[4],
+ fragment = s[5],
+ original = str
+ }
+end
+
+function url.filename(filename)
+ local t = url.hashed(filename)
+ return (t.scheme == "file" and t.path:gsub("^/([a-zA-Z])([:|])/)","%1:")) or filename
+end
+
+function url.query(str)
+ if type(str) == "string" then
+ local t = { }
+ for k, v in gmatch(str,"([^&=]*)=([^&=]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return str
+ end
+end
+
+--~ print(url.filename("file:///c:/oeps.txt"))
+--~ print(url.filename("c:/oeps.txt"))
+--~ print(url.filename("file:///oeps.txt"))
+--~ print(url.filename("file:///etc/test.txt"))
+--~ print(url.filename("/oeps.txt"))
+
+--~ from the spec on the web (sort of):
+--~
+--~ function test(str)
+--~ print(table.serialize(url.hashed(str)))
+--~ end
+--~
+--~ test("%56pass%20words")
+--~ test("file:///c:/oeps.txt")
+--~ test("file:///c|/oeps.txt")
+--~ test("file:///etc/oeps.txt")
+--~ test("file://./etc/oeps.txt")
+--~ test("file:////etc/oeps.txt")
+--~ test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
+--~ test("http://www.ietf.org/rfc/rfc2396.txt")
+--~ test("ldap://[2001:db8::7]/c=GB?objectClass?one#what")
+--~ test("mailto:John.Doe@example.com")
+--~ test("news:comp.infosystems.www.servers.unix")
+--~ test("tel:+1-816-555-1212")
+--~ test("telnet://192.0.2.16:80/")
+--~ test("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
+--~ test("/etc/passwords")
+--~ test("http://www.pragma-ade.com/spaced%20name")
+
+--~ test("zip:///oeps/oeps.zip#bla/bla.tex")
+--~ test("zip:///oeps/oeps.zip?bla/bla.tex")
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type = type
+local find, gmatch = string.find, string.gmatch
+
+dir = dir or { }
+
+-- optimizing for no string.find (*) does not save time
+
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
+ end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
+ end
+ end
+ end
+end
+
+dir.glob_pattern = glob_pattern
+
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
+
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
+ local t = t or { }
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
+ return t
+ else
+ return { }
+ end
+ end
+end
+
+dir.glob = glob
+
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
+
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
+ files[#files+1] = path .. "/" .. name
+ end
+ else
+ files[#files+1] = path .. "/" .. name
+ end
+ end
+ end
+ end
+ return files
+end
+
+dir.globfiles = globfiles
+
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
+
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
+
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
+
+local make_indeed = true -- false
+
+if string.find(os.getenv("PATH"),";") then
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
+ if first then
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
+ else
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
+ if first then
+ pth, drive = first .. middle, true
+ else
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
+ end
+ end
+ end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("a:"))
+--~ print(dir.mkdirs("a:/b/c"))
+--~ print(dir.mkdirs("a:b/c"))
+--~ print(dir.mkdirs("a:/bbb/c"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
+ end
+ lfs.chdir(d)
+ end
+ end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
+
+else
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
+ end
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
+ end
+
+end
+
+dir.makedirs = dir.mkdirs
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
+
+function boolean.tonumber(b)
+ if b then return 1 else return 0 end
+end
+
+function toboolean(str,tolerant)
+ if tolerant then
+ local tstr = type(str)
+ if tstr == "string" then
+ return str == "true" or str == "yes" or str == "on" or str == "1" or str == "t"
+ elseif tstr == "number" then
+ return tonumber(str) ~= 0
+ elseif tstr == "nil" then
+ return false
+ else
+ return str
+ end
+ elseif str == "true" then
+ return true
+ elseif str == "false" then
+ return false
+ else
+ return str
+ end
+end
+
+function string.is_boolean(str)
+ if type(str) == "string" then
+ if str == "true" or str == "yes" or str == "on" or str == "t" then
+ return true
+ elseif str == "false" or str == "no" or str == "off" or str == "f" then
+ return false
+ end
+ end
+ return nil
+end
+
+function boolean.alwaystrue()
+ return true
+end
+
+function boolean.falsetrue()
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-unicode'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+utf = utf or unicode.utf8
+
+local concat, utfchar, utfgsub = table.concat, utf.char, utf.gsub
+local char, byte, find, bytepairs = string.char, string.byte, string.find, string.bytepairs
+
+unicode = unicode or { }
+
+-- 0 EF BB BF UTF-8
+-- 1 FF FE UTF-16-little-endian
+-- 2 FE FF UTF-16-big-endian
+-- 3 FF FE 00 00 UTF-32-little-endian
+-- 4 00 00 FE FF UTF-32-big-endian
+
+unicode.utfname = {
+ [0] = 'utf-8',
+ [1] = 'utf-16-le',
+ [2] = 'utf-16-be',
+ [3] = 'utf-32-le',
+ [4] = 'utf-32-be'
+}
+
+function unicode.utftype(f) -- \000 fails !
+ local str = f:read(4)
+ if not str then
+ f:seek('set')
+ return 0
+ elseif find(str,"^%z%z\254\255") then
+ return 4
+ elseif find(str,"^\255\254%z%z") then
+ return 3
+ elseif find(str,"^\254\255") then
+ f:seek('set',2)
+ return 2
+ elseif find(str,"^\255\254") then
+ f:seek('set',2)
+ return 1
+ elseif find(str,"^\239\187\191") then
+ f:seek('set',3)
+ return 0
+ else
+ f:seek('set')
+ return 0
+ end
+end
+
+function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
+ local result, tmp, n, m, p = { }, { }, 0, 0, 0
+ -- lf | cr | crlf / (cr:13, lf:10)
+ local function doit()
+ if n == 10 then
+ if p ~= 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = 0
+ end
+ elseif n == 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = n
+ else
+ tmp[#tmp+1] = utfchar(n)
+ p = 0
+ end
+ end
+ for l,r in bytepairs(str) do
+ if r then
+ if endian then
+ n = l*256 + r
+ else
+ n = r*256 + l
+ end
+ if m > 0 then
+ n = (m-0xD800)*0x400 + (n-0xDC00) + 0x10000
+ m = 0
+ doit()
+ elseif n >= 0xD800 and n <= 0xDBFF then
+ m = n
+ else
+ doit()
+ end
+ end
+ end
+ if #tmp > 0 then
+ result[#result+1] = concat(tmp)
+ end
+ return result
+end
+
+function unicode.utf32_to_utf8(str, endian)
+ local result = { }
+ local tmp, n, m, p = { }, 0, -1, 0
+ -- lf | cr | crlf / (cr:13, lf:10)
+ local function doit()
+ if n == 10 then
+ if p ~= 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = 0
+ end
+ elseif n == 13 then
+ result[#result+1] = concat(tmp)
+ tmp = { }
+ p = n
+ else
+ tmp[#tmp+1] = utfchar(n)
+ p = 0
+ end
+ end
+ for a,b in bytepairs(str) do
+ if a and b then
+ if m < 0 then
+ if endian then
+ m = a*256*256*256 + b*256*256
+ else
+ m = b*256 + a
+ end
+ else
+ if endian then
+ n = m + a*256 + b
+ else
+ n = m + b*256*256*256 + a*256*256
+ end
+ m = -1
+ doit()
+ end
+ else
+ break
+ end
+ end
+ if #tmp > 0 then
+ result[#result+1] = concat(tmp)
+ end
+ return result
+end
+
+local function little(c)
+ local b = byte(c) -- b = c:byte()
+ if b < 0x10000 then
+ return char(b%256,b/256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1%256,b1/256,b2%256,b2/256)
+ end
+end
+
+local function big(c)
+ local b = byte(c)
+ if b < 0x10000 then
+ return char(b/256,b%256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1/256,b1%256,b2/256,b2%256)
+ end
+end
+
+function unicode.utf8_to_utf16(str,littleendian)
+ if littleendian then
+ return char(255,254) .. utfgsub(str,".",little)
+ else
+ return char(254,255) .. utfgsub(str,".",big)
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
+
+if not math.round then
+ function math.round(x)
+ return floor(x + 0.5)
+ end
+end
+
+if not math.div then
+ function math.div(n,m)
+ return floor(n/m)
+ end
+end
+
+if not math.mod then
+ function math.mod(n,m)
+ return n % m
+ end
+end
+
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- hm, quite unreadable
+
+if not utils then utils = { } end
+if not utils.merger then utils.merger = { } end
+if not utils.lua then utils.lua = { } end
+
+utils.merger.m_begin = "begin library merge"
+utils.merger.m_end = "end library merge"
+utils.merger.pattern =
+ "%c+" ..
+ "%-%-%s+" .. utils.merger.m_begin ..
+ "%c+(.-)%c+" ..
+ "%-%-%s+" .. utils.merger.m_end ..
+ "%c+"
+
+function utils.merger._self_fake_()
+ return
+ "-- " .. "created merged file" .. "\n\n" ..
+ "-- " .. utils.merger.m_begin .. "\n\n" ..
+ "-- " .. utils.merger.m_end .. "\n\n"
+end
+
+function utils.report(...)
+ print(...)
+end
+
+utils.merger.strip_comment = true
+
+function utils.merger._self_load_(name)
+ local f, data = io.open(name), ""
+ if f then
+ utils.report("reading merge from %s",name)
+ data = f:read("*all")
+ f:close()
+ else
+ utils.report("unknown file to merge %s",name)
+ end
+ if data and utils.merger.strip_comment then
+ -- saves some 20K
+ data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
+ end
+ return data or ""
+end
+
+function utils.merger._self_save_(name, data)
+ if data ~= "" then
+ local f = io.open(name,'w')
+ if f then
+ utils.report("saving merge from %s",name)
+ f:write(data)
+ f:close()
+ end
+ end
+end
+
+function utils.merger._self_swap_(data,code)
+ if data ~= "" then
+ return (data:gsub(utils.merger.pattern, function(s)
+ return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
+ end, 1))
+ else
+ return ""
+ end
+end
+
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
+function utils.merger._self_libs_(libs,list)
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
+ if type(libs) == 'string' then libs = { libs } end
+ if type(list) == 'string' then list = { list } end
+ local foundpath = nil
+ for _, lib in ipairs(libs) do
+ for _, pth in ipairs(list) do
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
+ else
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
+ end
+ end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
+ end
+ return table.concat(result, "\n\n")
+end
+
+function utils.merger.selfcreate(libs,list,target)
+ if target then
+ utils.merger._self_save_(
+ target,
+ utils.merger._self_swap_(
+ utils.merger._self_fake_(),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+ end
+end
+
+function utils.merger.selfmerge(name,libs,list,target)
+ utils.merger._self_save_(
+ target or name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+end
+
+function utils.merger.selfclean(name)
+ utils.merger._self_save_(
+ name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ ""
+ )
+ )
+end
+
+function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
+ -- utils.report("compiling",luafile,"into",lucfile)
+ os.remove(lucfile)
+ local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
+ if strip ~= false then
+ command = "-s " .. command
+ end
+ local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
+ if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
+ -- utils.report("removing",luafile)
+ os.remove(luafile)
+ end
+ return done
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
+
+-- dirty tricks
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
+
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
+ if index > 0 then
+ local flag, value = argument:match("^%-+(.+)=(.-)$")
+ if flag then
+ arguments[flag] = string.unquote(value or "")
+ else
+ flag = argument:match("^%-+(.+)")
+ if flag then
+ arguments[flag] = true
+ else
+ files[#files+1] = argument
+ end
+ end
+ end
+ end
+ environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
+end
+
+function environment.setargument(name,value)
+ environment.arguments[name] = value
+end
+
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
+ local arguments, sortedflags = environment.arguments, environment.sortedflags
+ if arguments[name] then
+ return arguments[name]
+ elseif partial then
+ if not sortedflags then
+ sortedflags = { }
+ for _,v in pairs(table.sortedkeys(arguments)) do
+ sortedflags[#sortedflags+1] = "^" .. v
+ end
+ environment.sortedflags = sortedflags
+ end
+ -- example of potential clash: ^mode ^modefile
+ for _,v in ipairs(sortedflags) do
+ if name:find(v) then
+ return arguments[v:sub(2,#v)]
+ end
+ end
+ end
+ return nil
+end
+
+function environment.split_arguments(separator) -- rather special, cut-off before separator
+ local done, before, after = false, { }, { }
+ for _,v in ipairs(environment.original_arguments) do
+ if not done and v == separator then
+ done = true
+ elseif done then
+ after[#after+1] = v
+ else
+ before[#before+1] = v
+ end
+ end
+ return before, after
+end
+
+function environment.reconstruct_commandline(arg,noquote)
+ arg = arg or environment.original_arguments
+ if noquote and #arg == 1 then
+ local a = arg[1]
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ return a
+ elseif next(arg) then
+ local result = { }
+ for _,a in ipairs(arg) do -- ipairs 1 .. #n
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ a = a:gsub('"','\\"') -- tricky
+ if a:find(" ") then
+ result[#result+1] = a:quote()
+ else
+ result[#result+1] = a
+ end
+ end
+ return table.join(result," ")
+ else
+ return ""
+ end
+end
+
+if arg then
+
+ -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
+ local newarg, instring = { }, false
+
+ for index, argument in ipairs(arg) do
+ if argument:find("^\"") then
+ newarg[#newarg+1] = argument:gsub("^\"","")
+ if not argument:find("\"$") then
+ instring = true
+ end
+ elseif argument:find("\"$") then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
+ instring = false
+ elseif instring then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument
+ else
+ newarg[#newarg+1] = argument
+ end
+ end
+ for i=1,-5,-1 do
+ newarg[i] = arg[i]
+ end
+
+ environment.initialize_arguments(newarg)
+ environment.original_arguments = newarg
+ environment.raw_arguments = arg
+
+ arg = { } -- prevent duplicate handling
+
+end
+
+-- weird place ... depends on a not yet loaded module
+
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
+
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
+
+environment.loadedluacode = loadfile -- can be overloaded
+
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
+
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
+
+-- the next ones can use the previous ones / combine
+
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
+ end
+ end
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
+ end
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+local statusinfo, n, registered = { }, 0, { }
+
+statistics = statistics or { }
+
+statistics.enable = true
+statistics.threshold = 0.05
+
+-- timing functions
+
+local clock = os.gettimeofday or os.clock
+
+function statistics.hastimer(instance)
+ return instance and instance.starttime
+end
+
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
+ end
+ if it == 0 then
+ instance.starttime = clock()
+ if not instance.loadtime then
+ instance.loadtime = 0
+ end
+ end
+ instance.timing = it + 1
+ end
+end
+
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
+ local starttime = instance.starttime
+ if starttime then
+ local stoptime = clock()
+ local loadtime = stoptime - starttime
+ instance.stoptime = stoptime
+ instance.loadtime = instance.loadtime + loadtime
+ if report then
+ statistics.report("load time %0.3f",loadtime)
+ end
+ instance.timing = 0
+ return loadtime
+ end
+ end
+ end
+ return 0
+end
+
+function statistics.elapsedtime(instance)
+ return format("%0.3f",(instance and instance.loadtime) or 0)
+end
+
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
+end
+
+-- general function
+
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
+end
+
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
+ end
+ statistics.enable = false
+ end
+end
+
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
+
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
+
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
+end
+
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
+end
+
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
+end
+
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
+ end
+end
+
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
+ else
+ write_nl(category .. " |")
+ end
+end
+
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
+ else
+ write_nl("")
+ end
+end
+
+local texcount = tex and tex.count
+
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
+ end
+ else
+ write(format("[%s",real))
+ end
+ else
+ write("[-")
+ end
+end
+
+function logs.tex.stop_page_number()
+ write("]")
+end
+
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
+ else
+ write_nl(format("",category))
+ end
+end
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
+ else
+ write_nl("")
+ end
+end
+
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
+
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
+end
+
+function logs.xml.stop_run()
+ write_nl("")
+end
+
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
+
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
+end
+
+function logs.xml.report_output_log()
+end
+
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
+end
+
+local level = 0
+
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
+end
+
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
+end
+
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
+end
+
+--
+
+local name, banner = 'report', 'context'
+
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
+ end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
+end
+
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
+ else
+ trackers.disable("resolvers.verbose")
+ end
+ logs.verbose = what or false
+end
+
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
+ end
+end
+
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
+
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
+ end
+end
+
+function logs.reportline() -- for scripts too
+ logs.report()
+end
+
+logs.simpleline = logs.reportline
+
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
+ end
+end
+
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
+ if f then
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
+ f:close()
+ break
+ else
+ sleep(0.1)
+ end
+ end
+end
+
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
+end
+
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
+ end
+
+ return newinstance
+
+end
+
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
+ end
+ end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
+ end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
+ end
+end
+
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
+ end
+ ie[key] = value
+ end
+ return value or ""
+end
+
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
+
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
+end
+
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
+
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
+ end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
+end
+
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
+
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
+ end
+ end
+ return t
+end
+
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
+ end
+ else
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
+ end
+ return newlist
+end
+
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
+ end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
+ end
+ return resolvers.ownpath
+end
+
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
+
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
+ end
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
+ end
+end
+
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+-- database loading
+
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
+
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
+ end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
+
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
+ end
+end
+
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
+ end
+end
+
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
+
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
+ end
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
+ end
+ end
+ end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
+ end
+ end
+ end
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
+ end
+end
+
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ end
+ end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
+ end
+ end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
+ end
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
+ end
+ end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
+ end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
+ end
+end
+
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
+end
+
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
+ else
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
+ end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
+ end
+end
+
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
+
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
+
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
+end
+
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
+end
+
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
+end
+
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
+
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
+ end
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ else
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
+ end
+
+end
+
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
+ end
+ end
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ return new
+ end
+end
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
+end
+
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
+end
+
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
+ end
+end
+
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
+ else
+ return resolvers.expanded_path_list(tmp)
+ end
+end
+
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
+
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
+end
+
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
+ end
+ return ''
+end
+
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
+
+resolvers.isreadable = { }
+
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
+ end
+ return readable
+end
+
+resolvers.isreadable.tex = resolvers.isreadable.file
+
+-- name
+-- name/name
+
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
+end
+
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
+end
+
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
+end
+
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
+
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
+end
+
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
+ else
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
+ end
+ end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
+end
+
+if not resolvers.concatinators then resolvers.concatinators = { } end
+
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
+
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
+ end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
+ end
+ instance.format = ''
+ return result
+end
+
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
+
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
+ end
+ end
+ end
+ return result
+end
+
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
+end
+
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
+
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
+
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
+
+-- main user functions
+
+function resolvers.automount()
+ -- implemented later
+end
+
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
+end
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
+end
+
+-- strtab
+
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
+end
+
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
+end
+
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
+ end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
+ end
+ return concat(s, sep or " | ")
+end
+
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
+end
+
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
+end
+
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
+end
+
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
+
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
+end
+
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
+ end
+end
+
+texconfig.kpse_init = false
+
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
+
+-- for a while
+
+input = resolvers
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
+--ldx]]--
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+
+caches = caches or { }
+
+caches.path = caches.path or nil
+caches.base = caches.base or "luatex-cache"
+caches.more = caches.more or "context"
+caches.direct = false -- true is faster but may need huge amounts of memory
+caches.tree = false
+caches.paths = caches.paths or nil
+caches.force = false
+caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
+
+function caches.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
+
+function caches.temp()
+ local cachepath = nil
+ local function check(list,isenv)
+ if not cachepath then
+ for k=1,#list do
+ local v = list[k]
+ cachepath = (isenv and (os.env[v] or "")) or v or ""
+ if cachepath == "" then
+ -- next
+ else
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ break
+ elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
+ dir.mkdirs(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then
+ break
+ end
+ end
+ end
+ cachepath = nil
+ end
+ end
+ end
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
+ check(caches.defaults,true)
+ if not cachepath then
+ print("\nfatal error: there is no valid (writable) cache path defined\n")
+ os.exit()
+ elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
+ print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
+ os.exit()
+ end
+ cachepath = file.collapse_path(cachepath)
+ function caches.temp()
+ return cachepath
+ end
+ return cachepath
+end
+
+function caches.configpath()
+ return table.concat(resolvers.instance.cnffiles,";")
+end
+
+function caches.hashed(tree)
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
+end
+
+function caches.treehash()
+ local tree = caches.configpath()
+ if not tree or tree == "" then
+ return false
+ else
+ return caches.hashed(tree)
+ end
+end
+
+function caches.setpath(...)
+ if not caches.path then
+ if not caches.path then
+ caches.path = caches.temp()
+ end
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
+ end
+ end
+ if not caches.path then
+ caches.path = '.'
+ end
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
+ local pth = dir.mkdirs(caches.path,...)
+ return pth
+ end
+ caches.path = dir.expand_name(caches.path)
+ return caches.path
+end
+
+function caches.definepath(category,subcategory)
+ return function()
+ return caches.setpath(category,subcategory)
+ end
+end
+
+function caches.setluanames(path,name)
+ return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+end
+
+function caches.loaddata(path,name)
+ local tmaname, tmcname = caches.setluanames(path,name)
+ local loader = loadfile(tmcname) or loadfile(tmaname)
+ if loader then
+ return loader()
+ else
+ return false
+ end
+end
+
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
+
+function caches.iswritable(filepath,filename)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ return file.iswritable(tmaname)
+end
+
+function caches.savedata(filepath,filename,data,raw)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ local reduce, simplify = true, true
+ if raw then
+ reduce, simplify = false, false
+ end
+ if caches.direct then
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
+ else
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
+ end
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ utils.lua.compile(tmaname, tmcname, cleanup, strip)
+end
+
+-- here we use the cache for format loading (texconfig.[formatname|jobname])
+
+--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
+ if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
+
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
+
+
Examples of usage can be found in the font related code.
+--ldx]]--
+
+containers = containers or { }
+
+containers.usecache = true
+
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
+
+local allocated = { }
+
+-- tracing
+
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
+
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
+ end
+ end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
+
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
+ end
+ report(container,"stored",name)
+ container.storage[name] = data
+ end
+ return data
+end
+
+function containers.content(container,name)
+ return container.storage[name]
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+-- since we want to use the cache instead of the tree, we will now
+-- reimplement the saver.
+
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
+
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
+
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
+ else
+ return file.join(cachename,dataname)
+ end
+ end)
+end
+
+function resolvers.load_data(pathname,dataname,filename)
+ load_data(pathname,dataname,filename,function(dataname,filename)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
+ else
+ if not filename or (filename == "") then
+ filename = dataname
+ end
+ return file.join(pathname,filename)
+ end
+ end)
+end
+
+-- we will make a better format, maybe something xml or just text or lua
+
+resolvers.automounted = resolvers.automounted or { }
+
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
+ if table.is_empty(mountpaths) and usecache then
+ mountpaths = { caches.setpath("mount") }
+ end
+ if not table.is_empty(mountpaths) then
+ statistics.starttiming(resolvers.instance)
+ for k, root in pairs(mountpaths) do
+ local f = io.open(root.."/url.tmi")
+ if f then
+ for line in f:lines() do
+ if line then
+ if line:find("^[%%#%-]") then -- or %W
+ -- skip
+ elseif line:find("^zip://") then
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
+ end
+ end
+ end
+ f:close()
+ end
+ end
+ statistics.stoptiming(resolvers.instance)
+ end
+end
+
+-- status info
+
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
+
+-- experiment (code will move)
+
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
+ end
+end
+
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
+ else
+ return "invalid status file"
+ end
+ else
+ return "missing status file"
+ end
+ end
+ return true
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-lst'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- used in mtxrun
+
+local find, concat, upper, format = string.find, table.concat, string.upper, string.format
+
+resolvers.listers = resolvers.listers or { }
+
+local function tabstr(str)
+ if type(str) == 'table' then
+ return concat(str," | ")
+ else
+ return str
+ end
+end
+
+local function list(list,report)
+ local instance = resolvers.instance
+ local pat = upper(pattern or "","")
+ local report = report or texio.write_nl
+ for _,key in pairs(table.sortedkeys(list)) do
+ if instance.pattern == "" or find(upper(key),pat) then
+ if instance.kpseonly then
+ if instance.kpsevars[key] then
+ report(format("%s=%s",key,tabstr(list[key])))
+ end
+ else
+ report(format('%s %s=%s',(instance.kpsevars[key] and 'K') or 'E',key,tabstr(list[key])))
+ end
+ end
+ end
+end
+
+function resolvers.listers.variables () list(resolvers.instance.variables ) end
+function resolvers.listers.expansions() list(resolvers.instance.expansions) end
+
+function resolvers.listers.configurations(report)
+ local report = report or texio.write_nl
+ local instance = resolvers.instance
+ for _,key in ipairs(table.sortedkeys(instance.kpsevars)) do
+ if not instance.pattern or (instance.pattern=="") or find(key,instance.pattern) then
+ report(format("%s\n",key))
+ for i,c in ipairs(instance.order) do
+ local str = c[key]
+ if str then
+ report(format("\t%s\t%s",i,str))
+ end
+ end
+ report("")
+ end
+ end
+end
+
+
+end -- of closure
+-- end library merge
+
+-- We initialize some characteristics of this program. We need to
+-- do this before we load the libraries, else own.name will not be
+-- properly set (handy for selfcleaning the file). It's an ugly
+-- looking piece of code.
+
+own = { }
+
+own.libs = { -- todo: check which ones are really needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-io.lua',
+ 'l-number.lua',
+ 'l-set.lua',
+ 'l-os.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-url.lua',
+ 'l-dir.lua',
+ 'l-boolean.lua',
+ 'l-unicode.lua',
+ 'l-math.lua',
+ 'l-utils.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+-- 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-lst.lua', -- lister
+}
+
+-- We need this hack till luatex is fixed.
+
+if arg and arg[0] == 'luatex' and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+-- End of hack.
+
+own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+own.path = string.match(own.name,"^(.+)[\\/].-$") or "."
+own.list = { '.' }
+
+if own.path ~= '.' then
+ table.insert(own.list,own.path)
+end
+
+table.insert(own.list,own.path.."/../../../tex/context/base")
+table.insert(own.list,own.path.."/mtx")
+table.insert(own.list,own.path.."/../sources")
+
+function locate_libs()
+ for _, lib in pairs(own.libs) do
+ for _, pth in pairs(own.list) do
+ local filename = string.gsub(pth .. "/" .. lib,"\\","/")
+ local codeblob = loadfile(filename)
+ if codeblob then
+ codeblob()
+ own.list = { pth } -- speed up te search
+ break
+ end
+ end
+ end
+end
+
+if not resolvers then
+ locate_libs()
+end
+
+if not resolvers then
+ print("")
+ print("Luatools is unable to start up due to lack of libraries. You may")
+ print("try to run 'lua luatools.lua --selfmerge' in the path where this")
+ print("script is located (normally under ..../scripts/context/lua) which")
+ print("will make luatools library independent.")
+ os.exit()
+end
+
+logs.setprogram('LuaTools',"TDS Management Tool 1.31",environment.arguments["verbose"] or false)
+
+local instance = resolvers.reset()
+
+resolvers.defaultlibs = { -- not all are needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-boolean.lua',
+ 'l-number.lua',
+ 'l-unicode.lua',
+ 'l-os.lua',
+ 'l-io.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-url.lua',
+ 'l-dir.lua',
+ 'l-utils.lua',
+ 'l-dimen.lua',
+ 'trac-inf.lua',
+ 'trac-tra.lua',
+ 'trac-log.lua',
+ 'luat-env.lua', -- here ?
+ 'data-res.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-tmp.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-pre.lua',
+ 'data-tex.lua',
+ 'data-bin.lua',
+-- 'data-zip.lua',
+-- 'data-clr.lua',
+ 'data-lua.lua',
+ 'data-ctx.lua',
+ 'luat-fio.lua',
+ 'luat-cnf.lua',
+}
+
+instance.engine = environment.arguments["engine"] or 'luatex'
+instance.progname = environment.arguments["progname"] or 'context'
+instance.luaname = environment.arguments["luafile"] or "" -- environment.ownname or ""
+instance.lualibs = environment.arguments["lualibs"] or table.concat(resolvers.defaultlibs,",")
+instance.allresults = environment.arguments["all"] or false
+instance.pattern = environment.arguments["pattern"] or nil
+instance.sortdata = environment.arguments["sort"] or false
+instance.kpseonly = not environment.arguments["all"] or false
+instance.my_format = environment.arguments["format"] or instance.format
+
+if type(instance.pattern) == 'boolean' then
+ logs.simple("invalid pattern specification")
+ instance.pattern = nil
+end
+
+if environment.arguments["trace"] then resolvers.settrace(environment.arguments["trace"]) end
+
+runners = runners or { }
+messages = messages or { }
+
+messages.no_ini_file = [[
+There is no lua initialization file found. This file can be forced by the
+"--progname" directive, or specified with "--luaname", or it is derived
+automatically from the formatname (aka jobname). It may be that you have
+to regenerate the file database using "luatools --generate".
+]]
+
+messages.help = [[
+--generate generate file database
+--variables show configuration variables
+--expansions show expanded variables
+--configurations show configuration order
+--expand-braces expand complex variable
+--expand-path expand variable (resolve paths)
+--expand-var expand variable (resolve references)
+--show-path show path expansion of ...
+--var-value report value of variable
+--find-file report file location
+--find-path report path of file
+--make or --ini make luatex format
+--run or --fmt= run luatex format
+--luafile=str lua inifile (default is .lua)
+--lualibs=list libraries to assemble (optional when --compile)
+--compile assemble and compile lua inifile
+--verbose give a bit more info
+--all show all found files
+--sort sort cached data
+--engine=str target engine
+--progname=str format or backend
+--pattern=str filter variables
+]]
+
+function runners.make_format(texname)
+ local instance = resolvers.instance
+ if texname and texname ~= "" then
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ if path and lfs then
+ lfs.chdir(path)
+ end
+ end
+ local barename = texname:gsub("%.%a+$","")
+ if barename == texname then
+ texname = texname .. ".tex"
+ end
+ local fullname = resolvers.find_files(texname)[1] or ""
+ if fullname == "" then
+ logs.simple("no tex file with name: %s",texname)
+ else
+ local luaname, lucname, luapath, lualibs = "", "", "", { }
+ -- the following is optional, since context.lua can also
+ -- handle this collect and compile business
+ if environment.arguments["compile"] then
+ if luaname == "" then luaname = barename end
+ logs.simple("creating initialization file: %s",luaname)
+ luapath = file.dirname(luaname)
+ if luapath == "" then
+ luapath = file.dirname(texname)
+ end
+ if luapath == "" then
+ luapath = file.dirname(resolvers.find_files(texname)[1] or "")
+ end
+ lualibs = string.split(instance.lualibs,",")
+ luaname = file.basename(barename .. ".lua")
+ lucname = file.basename(barename .. ".luc")
+ -- todo: when this fails, we can just copy the merged libraries from
+ -- luatools since they are normally the same, at least for context
+ if lualibs[1] then
+ local firstlib = file.join(luapath,lualibs[1])
+ if not lfs.isfile(firstlib) then
+ local foundname = resolvers.find_files(lualibs[1])[1]
+ if foundname then
+ logs.simple("located library path: %s",luapath)
+ luapath = file.dirname(foundname)
+ end
+ end
+ end
+ logs.simple("using library path: %s",luapath)
+ logs.simple("using lua libraries: %s",table.join(lualibs," "))
+ utils.merger.selfcreate(lualibs,luapath,luaname)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ if utils.lua.compile(luaname,lucname,false,strip) and io.exists(lucname) then
+ luaname = lucname
+ logs.simple("using compiled initialization file: %s",lucname)
+ else
+ logs.simple("using uncompiled initialization file: %s",luaname)
+ end
+ else
+ for _, v in pairs({instance.luaname, instance.progname, barename}) do
+ v = string.gsub(v..".lua","%.lua%.lua$",".lua")
+ if v and (v ~= "") then
+ luaname = resolvers.find_files(v)[1] or ""
+ if luaname ~= "" then
+ break
+ end
+ end
+ end
+ end
+ if environment.arguments["noluc"] then
+ luaname = luaname:gsub("%.luc$",".lua") -- make this an option
+ end
+ if luaname == "" then
+ if logs.verbose then
+ logs.simplelines(messages.no_ini_file)
+ logs.simple("texname : %s",texname)
+ logs.simple("luaname : %s",instance.luaname)
+ logs.simple("progname: %s",instance.progname)
+ logs.simple("barename: %s",barename)
+ end
+ else
+ logs.simple("using lua initialization file: %s",luaname)
+ local mp = dir.glob(file.removesuffix(file.basename(luaname)).."-*.mem")
+ if mp and #mp > 0 then
+ for _, name in ipairs(mp) do
+ logs.simple("removing related mplib format %s", file.basename(name))
+ os.remove(name)
+ end
+ end
+ local flags = {
+ "--ini",
+ "--lua=" .. string.quote(luaname)
+ }
+ local bs = (os.platform == "unix" and "\\\\") or "\\" -- todo: make a function
+ local command = "luatex ".. table.concat(flags," ") .. " " .. string.quote(fullname) .. " " .. bs .. "dump"
+ logs.simple("running command: %s\n",command)
+ os.spawn(command)
+ -- todo: do a dummy run that generates the related metafun and mfplain formats
+ end
+ end
+ else
+ logs.simple("no tex file given")
+ end
+end
+
+function runners.run_format(name,data,more)
+ -- hm, rather old code here; we can now use the file.whatever functions
+ if name and (name ~= "") then
+ local barename = name:gsub("%.%a+$","")
+ local fmtname = ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ barename = fmtname:gsub("%.%a+$","")
+ if fmtname == "" then
+ logs.simple("no format with name: %s",name)
+ else
+ local luaname = barename .. ".luc"
+ local f = io.open(luaname)
+ if not f then
+ luaname = barename .. ".lua"
+ f = io.open(luaname)
+ end
+ if f then
+ f:close()
+ local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. (more ~= "" and string.quote(more) or "")
+ logs.simple("running command: %s",command)
+ os.spawn(command)
+ else
+ logs.simple("using format name: %s",fmtname)
+ logs.simple("no luc/lua with name: %s",barename)
+ end
+ end
+ end
+end
+
+local ok = true
+
+-- private option --noluc for testing errors in the stub
+
+if environment.arguments["find-file"] then
+ resolvers.load()
+ instance.format = environment.arguments["format"] or instance.format
+ if instance.pattern then
+ instance.allresults = true
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
+ else
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
+ end
+elseif environment.arguments["find-path"] then
+ resolvers.load()
+ local path = resolvers.find_file(environment.files[1], instance.my_format)
+ if logs.verbose then
+ logs.simple(file.dirname(path))
+ else
+ print(file.dirname(path))
+ end
+elseif environment.arguments["run"] then
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.files[1] or "",environment.files[2] or "",environment.files[3] or "")
+elseif environment.arguments["fmt"] then
+ resolvers.load("nofiles") -- ! no need for loading databases
+ logs.setverbose(true)
+ runners.run_format(environment.arguments["fmt"], environment.files[1] or "",environment.files[2] or "")
+elseif environment.arguments["expand-braces"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_braces, environment.files)
+elseif environment.arguments["expand-path"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_path, environment.files)
+elseif environment.arguments["expand-var"] or environment.arguments["expand-variable"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.expand_var, environment.files)
+elseif environment.arguments["show-path"] or environment.arguments["path-value"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.show_path, environment.files)
+elseif environment.arguments["var-value"] or environment.arguments["show-value"] then
+ resolvers.load("nofiles")
+ resolvers.for_files(resolvers.var_value, environment.files)
+elseif environment.arguments["format-path"] then
+ resolvers.load()
+ logs.simple(caches.setpath("format"))
+elseif instance.pattern then -- brrr
+ resolvers.load()
+ instance.format = environment.arguments["format"] or instance.format
+ instance.allresults = true
+ resolvers.for_files(resolvers.find_files, { instance.pattern }, instance.my_format)
+elseif environment.arguments["generate"] then
+ instance.renewcache = true
+ logs.setverbose(true)
+ resolvers.load()
+elseif environment.arguments["make"] or environment.arguments["ini"] or environment.arguments["compile"] then
+ resolvers.load()
+ logs.setverbose(true)
+ runners.make_format(environment.files[1] or "")
+elseif environment.arguments["selfmerge"] then
+ utils.merger.selfmerge(own.name,own.libs,own.list)
+elseif environment.arguments["selfclean"] then
+ utils.merger.selfclean(own.name)
+elseif environment.arguments["selfupdate"] then
+ resolvers.load()
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"luatools")
+elseif environment.arguments["variables"] or environment.arguments["show-variables"] then
+ resolvers.load("nofiles")
+ resolvers.listers.variables()
+elseif environment.arguments["expansions"] or environment.arguments["show-expansions"] then
+ resolvers.load("nofiles")
+ resolvers.listers.expansions()
+elseif environment.arguments["configurations"] or environment.arguments["show-configurations"] then
+ resolvers.load("nofiles")
+ resolvers.listers.configurations()
+elseif environment.arguments["help"] or (environment.files[1]=='help') or (#environment.files==0) then
+ logs.help(messages.help)
+else
+ resolvers.load()
+ resolvers.for_files(resolvers.find_files, environment.files, instance.my_format)
+end
+
+if logs.verbose then
+ logs.simpleline()
+ logs.simple("runtime: %0.3f seconds",os.runtime())
+end
+
+if os.platform == "unix" then
+ io.write("\n")
+end
diff --git a/scripts/context/stubs/unix/makempy b/scripts/context/stubs/unix/makempy
index 4bf7a1af2..34892b284 100755
--- a/scripts/context/stubs/unix/makempy
+++ b/scripts/context/stubs/unix/makempy
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart makempy.pl "$@"
+mtxrun --usekpse --execute makempy.pl "$@"
diff --git a/scripts/context/stubs/unix/metatex b/scripts/context/stubs/unix/metatex
new file mode 100755
index 000000000..f0c6b65d4
--- /dev/null
+++ b/scripts/context/stubs/unix/metatex
@@ -0,0 +1,2 @@
+#!/bin/sh
+mtxrun --script metatex "$@"
diff --git a/scripts/context/stubs/unix/mpstools b/scripts/context/stubs/unix/mpstools
index b4c8f6345..1a64d90b0 100755
--- a/scripts/context/stubs/unix/mpstools
+++ b/scripts/context/stubs/unix/mpstools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart mpstools.rb "$@"
+mtxrun --usekpse --execute mpstools.rb "$@"
diff --git a/scripts/context/stubs/unix/mptopdf b/scripts/context/stubs/unix/mptopdf
index 980a3123d..f57a8b7a7 100755
--- a/scripts/context/stubs/unix/mptopdf
+++ b/scripts/context/stubs/unix/mptopdf
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart mptopdf.pl "$@"
+mtxrun --usekpse --execute mptopdf.pl "$@"
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
new file mode 100755
index 000000000..0af429bf1
--- /dev/null
+++ b/scripts/context/stubs/unix/mtxrun
@@ -0,0 +1,10190 @@
+#!/usr/bin/env texlua
+
+if not modules then modules = { } end modules ['mtxrun'] = {
+ version = 1.001,
+ comment = "runner, lua replacement for texmfstart.rb",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+
+-- one can make a stub:
+--
+-- #!/bin/sh
+-- env LUATEXDIR=/....../texmf/scripts/context/lua luatex --luaonly mtxrun.lua "$@"
+
+-- filename : mtxrun.lua
+-- comment : companion to context.tex
+-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
+-- copyright: PRAGMA ADE / ConTeXt Development Team
+-- license : see context related readme files
+
+-- This script is based on texmfstart.rb but does not use kpsewhich to
+-- locate files. Although kpse is a library it never came to opening up
+-- its interface to other programs (esp scripting languages) and so we
+-- do it ourselves. The lua variant evolved out of an experimental ruby
+-- one. Interesting is that using a scripting language instead of c does
+-- not have a speed penalty. Actually the lua variant is more efficient,
+-- especially when multiple calls to kpsewhich are involved. The lua
+-- library also gives way more control.
+
+-- to be done / considered
+--
+-- support for --exec or make it default
+-- support for jar files (or maybe not, never used, too messy)
+-- support for $RUBYINPUTS cum suis (if still needed)
+-- remember for subruns: _CTX_K_V_#{original}_
+-- remember for subruns: _CTX_K_S_#{original}_
+-- remember for subruns: TEXMFSTART.#{original} [tex.rb texmfstart.rb]
+
+texlua = true
+
+-- begin library merge
+
+
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
+
+if not string.split then
+
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
+ end
+ end
+
+end
+
+local chr_to_esc = {
+ ["%"] = "%%",
+ ["."] = "%.",
+ ["+"] = "%+", ["-"] = "%-", ["*"] = "%*",
+ ["^"] = "%^", ["$"] = "%$",
+ ["["] = "%[", ["]"] = "%]",
+ ["("] = "%(", [")"] = "%)",
+ ["{"] = "%{", ["}"] = "%}"
+}
+
+string.chr_to_esc = chr_to_esc
+
+function string:esc() -- variant 2
+ return (gsub(self,"(.)",chr_to_esc))
+end
+
+function string:unquote()
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
+end
+
+function string:quote() -- we could use format("%q")
+ return '"' .. self:unquote() .. '"'
+end
+
+function string:count(pattern) -- variant 3
+ local n = 0
+ for _ in gmatch(self,pattern) do
+ n = n + 1
+ end
+ return n
+end
+
+function string:limit(n,sentinel)
+ if #self > n then
+ sentinel = sentinel or " ..."
+ return sub(self,1,(n-#sentinel)) .. sentinel
+ else
+ return self
+ end
+end
+
+function string:strip()
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
+end
+
+function string:is_empty()
+ return not find(find,"%S")
+end
+
+function string:enhance(pattern,action)
+ local ok, n = true, 0
+ while ok do
+ ok = false
+ self = gsub(self,pattern, function(...)
+ ok, n = true, n + 1
+ return action(...)
+ end)
+ end
+ return self, n
+end
+
+local chr_to_hex, hex_to_chr = { }, { }
+
+for i=0,255 do
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
+end
+
+function string:to_hex()
+ return (gsub(self or "","(.)",chr_to_hex))
+end
+
+function string:from_hex()
+ return (gsub(self or "","(..)",hex_to_chr))
+end
+
+if not string.characters then
+
+ local function nextchar(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, str:sub(index,index)
+ end
+ function string:characters()
+ return nextchar, self, 0
+ end
+ local function nextbyte(str, index)
+ index = index + 1
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
+ end
+ function string:bytes()
+ return nextbyte, self, 0
+ end
+
+end
+
+-- we can use format for this (neg n)
+
+function string:rpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self .. self.rep(chr or " ",m)
+ else
+ return self
+ end
+end
+
+function string:lpadd(n,chr)
+ local m = n-#self
+ if m > 0 then
+ return self.rep(chr or " ",m) .. self
+ else
+ return self
+ end
+end
+
+string.padd = string.rpadd
+
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
+end
+
+--~ print(is_number("1"))
+--~ print(is_number("1.1"))
+--~ print(is_number(".1"))
+--~ print(is_number("-0.1"))
+--~ print(is_number("+0.1"))
+--~ print(is_number("-.1"))
+--~ print(is_number("+.1"))
+
+function string:split_settings() -- no {} handling, see l-aux for lpeg variant
+ if find(self,"=") then
+ local t = { }
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
+ t[k] = v
+ end
+ return t
+ else
+ return nil
+ end
+end
+
+local patterns_escapes = {
+ ["-"] = "%-",
+ ["."] = "%.",
+ ["+"] = "%+",
+ ["*"] = "%*",
+ ["%"] = "%%",
+ ["("] = "%)",
+ [")"] = "%)",
+ ["["] = "%[",
+ ["]"] = "%]",
+}
+
+function string:pattesc()
+ return (gsub(self,".",patterns_escapes))
+end
+
+function string:tohash()
+ local t = { }
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
+ t[s] = true
+ end
+ return t
+end
+
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
+
+--~ l-lpeg.lua :
+
+--~ lpeg.digit = lpeg.R('09')^1
+--~ lpeg.sign = lpeg.S('+-')^1
+--~ lpeg.cardinal = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.integer = lpeg.P(lpeg.sign^0 * lpeg.digit^1)
+--~ lpeg.float = lpeg.P(lpeg.sign^0 * lpeg.digit^0 * lpeg.P('.') * lpeg.digit^1)
+--~ lpeg.number = lpeg.float + lpeg.integer
+--~ lpeg.oct = lpeg.P("0") * lpeg.R('07')^1
+--~ lpeg.hex = lpeg.P("0x") * (lpeg.R('09') + lpeg.R('AF'))^1
+--~ lpeg.uppercase = lpeg.P("AZ")
+--~ lpeg.lowercase = lpeg.P("az")
+
+--~ lpeg.eol = lpeg.S('\r\n\f')^1 -- includes formfeed
+--~ lpeg.space = lpeg.S(' ')^1
+--~ lpeg.nonspace = lpeg.P(1-lpeg.space)^1
+--~ lpeg.whitespace = lpeg.S(' \r\n\f\t')^1
+--~ lpeg.nonwhitespace = lpeg.P(1-lpeg.whitespace)^1
+
+local hash = { }
+
+function lpeg.anywhere(pattern) --slightly adapted from website
+ return P { P(pattern) + 1 * lpeg.V(1) }
+end
+
+function lpeg.startswith(pattern) --slightly adapted
+ return P(pattern)
+end
+
+function lpeg.splitter(pattern, action)
+ return (((1-P(pattern))^1)/action+1)^0
+end
+
+-- variant:
+
+--~ local parser = lpeg.Ct(lpeg.splitat(newline))
+
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
+local newline = crlf + cr + lf
+local spacing = space^0 * newline
+
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
+local content = (empty + nonempty)^1
+
+local capture = Ct(content^0)
+
+function string:splitlines()
+ return capture:match(self)
+end
+
+lpeg.linebyline = content -- better make a sublibrary
+
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps->what->more")) -- oeps what more
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps->what->more")) -- oeps what->more
+--~ local p = lpeg.splitat("->",false) print(p:match("oeps")) -- oeps
+--~ local p = lpeg.splitat("->",true) print(p:match("oeps")) -- oeps
+
+local splitters_s, splitters_m = { }, { }
+
+local function splitat(separator,single)
+ local splitter = (single and splitters_s[separator]) or splitters_m[separator]
+ if not splitter then
+ separator = P(separator)
+ if single then
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
+ splitters_s[separator] = splitter
+ else
+ local other = C((1 - separator)^0)
+ splitter = other * (separator * other)^0
+ splitters_m[separator] = splitter
+ end
+ end
+ return splitter
+end
+
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+table.join = table.concat
+
+local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
+local getmetatable, setmetatable = getmetatable, setmetatable
+local type, next, tostring, ipairs = type, next, tostring, ipairs
+
+function table.strip(tab)
+ local lst = { }
+ for i=1,#tab do
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
+ if s == "" then
+ -- skip this one
+ else
+ lst[#lst+1] = s
+ end
+ end
+ return lst
+end
+
+local function sortedkeys(tab)
+ local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ if kind == 3 then
+ -- no further check
+ else
+ local tkey = type(key)
+ if tkey == "string" then
+ -- if kind == 2 then kind = 3 else kind = 1 end
+ kind = (kind == 2 and 3) or 1
+ elseif tkey == "number" then
+ -- if kind == 1 then kind = 3 else kind = 2 end
+ kind = (kind == 1 and 3) or 2
+ else
+ kind = 3
+ end
+ end
+ end
+ if kind == 0 or kind == 3 then
+ sort(srt,function(a,b) return (tostring(a) < tostring(b)) end)
+ else
+ sort(srt)
+ end
+ return srt
+end
+
+local function sortedhashkeys(tab) -- fast one
+ local srt = { }
+ for key,_ in next, tab do
+ srt[#srt+1] = key
+ end
+ sort(srt)
+ return srt
+end
+
+table.sortedkeys = sortedkeys
+table.sortedhashkeys = sortedhashkeys
+
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
+function table.append(t, list)
+ for _,v in next, list do
+ insert(t,v)
+ end
+end
+
+function table.prepend(t, list)
+ for k,v in next, list do
+ insert(t,k,v)
+ end
+end
+
+function table.merge(t, ...) -- first one is target
+ t = t or {}
+ local lst = {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ t[k] = v
+ end
+ end
+ return t
+end
+
+function table.merged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ for k, v in next, lst[i] do
+ tmp[k] = v
+ end
+ end
+ return tmp
+end
+
+function table.imerge(t, ...)
+ local lst = {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ t[#t+1] = nst[j]
+ end
+ end
+ return t
+end
+
+function table.imerged(...)
+ local tmp, lst = { }, {...}
+ for i=1,#lst do
+ local nst = lst[i]
+ for j=1,#nst do
+ tmp[#tmp+1] = nst[j]
+ end
+ end
+ return tmp
+end
+
+local function fastcopy(old) -- fast one
+ if old then
+ local new = { }
+ for k,v in next, old do
+ if type(v) == "table" then
+ new[k] = fastcopy(v) -- was just table.copy
+ else
+ new[k] = v
+ end
+ end
+ -- optional second arg
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+local function copy(t, tables) -- taken from lua wiki, slightly adapted
+ tables = tables or { }
+ local tcopy = {}
+ if not tables[t] then
+ tables[t] = tcopy
+ end
+ for i,v in next, t do -- brrr, what happens with sparse indexed
+ if type(i) == "table" then
+ if tables[i] then
+ i = tables[i]
+ else
+ i = copy(i, tables)
+ end
+ end
+ if type(v) ~= "table" then
+ tcopy[i] = v
+ elseif tables[v] then
+ tcopy[i] = tables[v]
+ else
+ tcopy[i] = copy(v, tables)
+ end
+ end
+ local mt = getmetatable(t)
+ if mt then
+ setmetatable(tcopy,mt)
+ end
+ return tcopy
+end
+
+table.fastcopy = fastcopy
+table.copy = copy
+
+-- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack)
+
+function table.sub(t,i,j)
+ return { unpack(t,i,j) }
+end
+
+function table.replace(a,b)
+ for k,v in next, b do
+ a[k] = v
+ end
+end
+
+-- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice)
+
+function table.is_empty(t)
+ return not t or not next(t)
+end
+
+function table.one_entry(t)
+ local n = next(t)
+ return n and not next(t,n)
+end
+
+function table.starts_at(t)
+ return ipairs(t,1)(t,0)
+end
+
+function table.tohash(t,value)
+ local h = { }
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
+ end
+ return h
+end
+
+function table.fromhash(t)
+ local h = { }
+ for k, v in next, t do -- no ipairs here
+ if v then h[#h+1] = k end
+ end
+ return h
+end
+
+--~ print(table.serialize(t), "\n")
+--~ print(table.serialize(t,"name"), "\n")
+--~ print(table.serialize(t,false), "\n")
+--~ print(table.serialize(t,true), "\n")
+--~ print(table.serialize(t,"name",true), "\n")
+--~ print(table.serialize(t,"name",true,true), "\n")
+
+table.serialize_functions = true
+table.serialize_compact = true
+table.serialize_inline = true
+
+local noquotes, hexify, handle, reduce, compact, inline, functions
+
+local reserved = table.tohash { -- intercept a language flaw, no reserved words as key
+ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if',
+ 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
+}
+
+local function simple_table(t)
+ if #t > 0 then
+ local n = 0
+ for _,v in next, t do
+ n = n + 1
+ end
+ if n == #t then
+ local tt = { }
+ for i=1,#t do
+ local v = t[i]
+ local tv = type(v)
+ if tv == "number" then
+ if hexify then
+ tt[#tt+1] = format("0x%04X",v)
+ else
+ tt[#tt+1] = tostring(v) -- tostring not needed
+ end
+ elseif tv == "boolean" then
+ tt[#tt+1] = tostring(v)
+ elseif tv == "string" then
+ tt[#tt+1] = format("%q",v)
+ else
+ tt = nil
+ break
+ end
+ end
+ return tt
+ end
+ end
+ return nil
+end
+
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
+local function do_serialize(root,name,depth,level,indexed)
+ if level > 0 then
+ depth = depth .. " "
+ if indexed then
+ handle(format("%s{",depth))
+ elseif name then
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
+ else
+ handle(format("%s{",depth))
+ end
+ end
+ if root and next(root) then
+ local first, last = nil, 0 -- #root cannot be trusted here
+ if compact then
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
+ if not first then first = k end
+ last = last + 1
+ end
+ end
+ local sk = sortedkeys(root)
+ for i=1,#sk do
+ local k = sk[i]
+ local v = root[k]
+ --~ if v == root then
+ -- circular
+ --~ else
+ local t = type(v)
+ if compact and first and type(k) == "number" and k >= first and k <= last then
+ if t == "number" then
+ if hexify then
+ handle(format("%s 0x%04X,",depth,v))
+ else
+ handle(format("%s %s,",depth,v))
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
+ else
+ handle(format("%s %q,",depth,v))
+ end
+ elseif t == "table" then
+ if not next(v) then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
+ local st = simple_table(v)
+ if st then
+ handle(format("%s { %s },",depth,concat(st,", ")))
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ else
+ do_serialize(v,k,depth,level+1,true)
+ end
+ elseif t == "boolean" then
+ handle(format("%s %s,",depth,tostring(v)))
+ elseif t == "function" then
+ if functions then
+ handle(format('%s loadstring(%q),',depth,dump(v)))
+ else
+ handle(format('%s "function",',depth))
+ end
+ else
+ handle(format("%s %q,",depth,tostring(v)))
+ end
+ elseif k == "__p__" then -- parent
+ if false then
+ handle(format("%s __p__=nil,",depth))
+ end
+ elseif t == "number" then
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
+ else
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ end
+ elseif t == "string" then
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
+ end
+ elseif t == "table" then
+ if not next(v) then
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
+ elseif inline then
+ local st = simple_table(v)
+ if st then
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ else
+ do_serialize(v,k,depth,level+1)
+ end
+ elseif t == "boolean" then
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
+ elseif t == "function" then
+ if functions then
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
+ end
+ else
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
+ end
+ --~ end
+ end
+ end
+ if level > 0 then
+ handle(format("%s},",depth))
+ end
+end
+
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
+local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
+ noquotes = _noquotes
+ hexify = _hexify
+ handle = _handle or print
+ reduce = _reduce or false
+ compact = table.serialize_compact
+ inline = compact and table.serialize_inline
+ functions = table.serialize_functions
+ local tname = type(name)
+ if tname == "string" then
+ if name == "return" then
+ handle("return {")
+ else
+ handle(name .. "={")
+ end
+ elseif tname == "number" then
+ if hexify then
+ handle(format("[0x%04X]={",name))
+ else
+ handle("[" .. name .. "]={")
+ end
+ elseif tname == "boolean" then
+ if name then
+ handle("return {")
+ else
+ handle("{")
+ end
+ else
+ handle("t={")
+ end
+ if root and next(root) then
+ do_serialize(root,name,"",0,indexed)
+ end
+ handle("}")
+end
+
+--~ name:
+--~
+--~ true : return { }
+--~ false : { }
+--~ nil : t = { }
+--~ string : string = { }
+--~ 'return' : return { }
+--~ number : [number] = { }
+
+function table.serialize(root,name,reduce,noquotes,hexify)
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ return concat(t,"\n")
+end
+
+function table.tohandle(handle,root,name,reduce,noquotes,hexify)
+ serialize(root,name,handle,reduce,noquotes,hexify)
+end
+
+-- sometimes tables are real use (zapfino extra pro is some 85M) in which
+-- case a stepwise serialization is nice; actually, we could consider:
+--
+-- for line in table.serializer(root,name,reduce,noquotes) do
+-- ...(line)
+-- end
+--
+-- so this is on the todo list
+
+table.tofile_maxtab = 2*1024
+
+function table.tofile(filename,root,name,reduce,noquotes,hexify)
+ local f = io.open(filename,'w')
+ if f then
+ local maxtab = table.tofile_maxtab
+ if maxtab > 1 then
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ if #t > maxtab then
+ f:write(concat(t,"\n"),"\n") -- hm, write(sometable) should be nice
+ t = { }
+ end
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ f:write(concat(t,"\n"),"\n")
+ else
+ local function flush(s)
+ f:write(s,"\n")
+ end
+ serialize(root,name,flush,reduce,noquotes,hexify)
+ end
+ f:close()
+ end
+end
+
+local function flatten(t,f,complete)
+ for i=1,#t do
+ local v = t[i]
+ if type(v) == "table" then
+ if complete or type(v[1]) == "table" then
+ flatten(v,f,complete)
+ else
+ f[#f+1] = v
+ end
+ else
+ f[#f+1] = v
+ end
+ end
+end
+
+function table.flatten(t)
+ local f = { }
+ flatten(t,f,true)
+ return f
+end
+
+function table.unnest(t) -- bad name
+ local f = { }
+ flatten(t,f,false)
+ return f
+end
+
+table.flatten_one_level = table.unnest
+
+-- the next three may disappear
+
+function table.remove_value(t,value) -- todo: n
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ remove(t,i)
+ -- remove all, so no: return
+ end
+ end
+ end
+end
+
+function table.insert_before_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i,str)
+ return
+ end
+ end
+ end
+ insert(t,1,str)
+ elseif value then
+ insert(t,1,value)
+ end
+end
+
+function table.insert_after_value(t,value,str)
+ if str then
+ if value then
+ for i=1,#t do
+ if t[i] == value then
+ insert(t,i+1,str)
+ return
+ end
+ end
+ end
+ t[#t+1] = str
+ elseif value then
+ t[#t+1] = value
+ end
+end
+
+local function are_equal(a,b,n,m) -- indexed
+ if #a == #b then
+ n = n or 1
+ m = m or #a
+ for i=n,m do
+ local ai, bi = a[i], b[i]
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+ else
+ return false
+ end
+end
+
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
+function table.compact(t)
+ if t then
+ for k,v in next, t do
+ if not next(v) then
+ t[k] = nil
+ end
+ end
+ end
+end
+
+function table.contains(t, v)
+ if t then
+ for i=1, #t do
+ if t[i] == v then
+ return i
+ end
+ end
+ end
+ return false
+end
+
+function table.count(t)
+ local n, e = 0, next(t)
+ while e do
+ n, e = n + 1, next(t,e)
+ end
+ return n
+end
+
+function table.swapped(t)
+ local s = { }
+ for k, v in next, t do
+ s[v] = k
+ end
+ return s
+end
+
+--~ function table.are_equal(a,b)
+--~ return table.serialize(a) == table.serialize(b)
+--~ end
+
+function table.clone(t,p) -- t is optional or nil or table
+ if not p then
+ t, p = { }, t or { }
+ elseif not t then
+ t = { }
+ end
+ setmetatable(t, { __index = function(_,key) return p[key] end })
+ return t
+end
+
+function table.hexed(t,seperator)
+ local tt = { }
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
+ return concat(tt,seperator or " ")
+end
+
+function table.reverse_hash(h)
+ local r = { }
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
+ end
+ return r
+end
+
+function table.reverse(t)
+ local tt = { }
+ if #t > 0 then
+ for i=#t,1,-1 do
+ tt[#tt+1] = t[i]
+ end
+ end
+ return tt
+end
+
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local byte = string.byte
+
+if string.find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator = "\\", ";"
+else
+ io.fileseparator, io.pathseparator = "/" , ":"
+end
+
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
+ if f then
+ local data = f:read('*all')
+ -- garbagecollector.check(data)
+ f:close()
+ return data
+ else
+ return nil
+ end
+end
+
+function io.savedata(filename,data,joiner)
+ local f = io.open(filename,"wb")
+ if f then
+ if type(data) == "table" then
+ f:write(table.join(data,joiner or ""))
+ elseif type(data) == "function" then
+ data(f)
+ else
+ f:write(data)
+ end
+ f:close()
+ return true
+ else
+ return false
+ end
+end
+
+function io.exists(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return false
+ else
+ assert(f:close())
+ return true
+ end
+end
+
+function io.size(filename)
+ local f = io.open(filename)
+ if f == nil then
+ return 0
+ else
+ local s = f:seek("end")
+ assert(f:close())
+ return s
+ end
+end
+
+function io.noflines(f)
+ local n = 0
+ for _ in f:lines() do
+ n = n + 1
+ end
+ f:seek('set',0)
+ return n
+end
+
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
+ end
+}
+
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
+ end
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
+ else
+ return nil, nil
+ end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
+ end
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
+ else
+ return nil, nil
+ end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
+ end
+}
+
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
+end
+
+function io.ask(question,default,options)
+ while true do
+ io.write(question)
+ if options then
+ io.write(string.format(" [%s]",table.concat(options,"|")))
+ end
+ if default then
+ io.write(string.format(" [%s]",default))
+ end
+ io.write(string.format(" "))
+ local answer = io.read()
+ answer = answer:gsub("^%s*(.*)%s*$","%1")
+ if answer == "" and default then
+ return default
+ elseif not options then
+ return answer
+ else
+ for _,v in pairs(options) do
+ if v == answer then
+ return answer
+ end
+ end
+ local pattern = "^" .. answer
+ for _,v in pairs(options) do
+ if v:find(pattern) then
+ return v
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+number = number or { }
+
+-- a,b,c,d,e,f = number.toset(100101)
+
+function number.toset(n)
+ return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
+end
+
+function number.toevenhex(n)
+ local s = format("%X",n)
+ if #s % 2 == 0 then
+ return s
+ else
+ return "0" .. s
+ end
+end
+
+-- the lpeg way is slower on 8 digits, but faster on 4 digits, some 7.5%
+-- on
+--
+-- for i=1,1000000 do
+-- local a,b,c,d,e,f,g,h = number.toset(12345678)
+-- local a,b,c,d = number.toset(1234)
+-- local a,b,c = number.toset(123)
+-- end
+--
+-- of course dedicated "(.)(.)(.)(.)" matches are even faster
+
+local one = lpeg.C(1-lpeg.S(''))^1
+
+function number.toset(n)
+ return one:match(tostring(n))
+end
+
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+set = set or { }
+
+local nums = { }
+local tabs = { }
+local concat = table.concat
+
+set.create = table.tohash
+
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
+ end
+ end
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
+ end
+ return nums[s]
+ else
+ return 0
+ end
+end
+
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
+ end
+end
+
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
+end
+
+--~ local c = set.create{'aap','noot','mies'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ local c = set.create{'zus','wim','jet'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ print(t['jet'])
+--~ print(set.contains(t,'jet'))
+--~ print(set.contains(t,'aap'))
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+function os.resultof(command)
+ return io.popen(command,"r"):read("*all")
+end
+
+if not os.exec then os.exec = os.execute end
+if not os.spawn then os.spawn = os.execute end
+
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+
+if not io.fileseparator then
+ if find(os.getenv("PATH"),";") then
+ io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ else
+ io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ end
+end
+
+os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+
+function os.launch(str)
+ if os.platform == "windows" then
+ os.execute("start " .. str) -- os.spawn ?
+ else
+ os.execute(str .. " &") -- os.spawn ?
+ end
+end
+
+if not os.setenv then
+ function os.setenv() return false end
+end
+
+if not os.times then
+ -- utime = user time
+ -- stime = system time
+ -- cutime = children user time
+ -- cstime = children system time
+ function os.times()
+ return {
+ utime = os.gettimeofday(), -- user
+ stime = 0, -- system
+ cutime = 0, -- children user
+ cstime = 0, -- children system
+ }
+ end
+end
+
+os.gettimeofday = os.gettimeofday or os.clock
+
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
+end
+
+--~ print(os.gettimeofday()-os.time())
+--~ os.sleep(1.234)
+--~ print (">>",os.runtime())
+--~ print(os.date("%H:%M:%S",os.gettimeofday()))
+--~ print(os.date("%H:%M:%S",os.time()))
+
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
+
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- needs a cleanup
+
+file = file or { }
+
+local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
+
+function file.removesuffix(filename)
+ return (gsub(filename,"%.[%a%d]+$",""))
+end
+
+function file.addsuffix(filename, suffix)
+ if not find(filename,"%.[%a%d]+$") then
+ return filename .. "." .. suffix
+ else
+ return filename
+ end
+end
+
+function file.replacesuffix(filename, suffix)
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
+end
+
+function file.dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
+end
+
+function file.basename(name)
+ return match(name,"^.+[/\\](.-)$") or name
+end
+
+function file.nameonly(name)
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
+end
+
+function file.extname(name)
+ return match(name,"^.+%.([^/\\]-)$") or ""
+end
+
+file.suffix = file.extname
+
+--~ print(file.join("x/","/y"))
+--~ print(file.join("http://","/y"))
+--~ print(file.join("http://a","/y"))
+--~ print(file.join("http:///a","/y"))
+--~ print(file.join("//nas-1","/y"))
+
+function file.join(...)
+ local pth = concat({...},"/")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ a, b = match(pth,"^(//)(.*)$")
+ if a and b then
+ return a .. gsub(b,"//+","/")
+ end
+ return (gsub(pth,"//+","/"))
+end
+
+function file.iswritable(name)
+ local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
+ return a and a.permissions:sub(2,2) == "w"
+end
+
+function file.isreadable(name)
+ local a = lfs.attributes(name)
+ return a and a.permissions:sub(1,1) == "r"
+end
+
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
+
+-- todo: lpeg
+
+function file.split_path(str)
+ local t = { }
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
+ if name ~= "" then
+ t[#t+1] = gsub(name,"\001",":")
+ end
+ end
+ return t
+end
+
+function file.join_path(tab)
+ return concat(tab,io.pathseparator) -- can have trailing //
+end
+
+function file.collapse_path(str)
+ str = gsub(str,"/%./","/")
+ local n, m = 1, 1
+ while n > 0 or m > 0 do
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
+ end
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
+ if str == "" then str = "." end
+ return str
+end
+
+--~ print(file.collapse_path("a/./b/.."))
+--~ print(file.collapse_path("a/aa/../b/bb"))
+--~ print(file.collapse_path("a/../.."))
+--~ print(file.collapse_path("a/.././././b/.."))
+--~ print(file.collapse_path("a/./././b/.."))
+--~ print(file.collapse_path("a/b/c/../.."))
+
+function file.robustname(str)
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
+end
+
+file.readdata = io.loaddata
+file.savedata = io.savedata
+
+function file.copy(oldname,newname)
+ file.savedata(newname,io.loaddata(oldname))
+end
+
+-- lpeg variants, slightly faster, not always
+
+--~ local period = lpeg.P(".")
+--~ local slashes = lpeg.S("\\/")
+--~ local noperiod = 1-period
+--~ local noslashes = 1-slashes
+--~ local name = noperiod^1
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.C(noperiod^1) * -1
+
+--~ function file.extname(name)
+--~ return pattern:match(name) or ""
+--~ end
+
+--~ local pattern = lpeg.Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+
+--~ function file.removesuffix(name)
+--~ return pattern:match(name)
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
+
+--~ function file.basename(name)
+--~ return pattern:match(name) or name
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.Cp() * noslashes^1 * -1
+
+--~ function file.dirname(name)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2)
+--~ else
+--~ return ""
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.addsuffix(name, suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * lpeg.Cp() * noperiod^1 * -1
+
+--~ function file.replacesuffix(name,suffix)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ return name:sub(1,p-2) .. "." .. suffix
+--~ else
+--~ return name .. "." .. suffix
+--~ end
+--~ end
+
+--~ local pattern = (noslashes^0 * slashes)^0 * lpeg.Cp() * ((noperiod^1 * period)^1 * lpeg.Cp() + lpeg.P(true)) * noperiod^1 * -1
+
+--~ function file.nameonly(name)
+--~ local a, b = pattern:match(name)
+--~ if b then
+--~ return name:sub(a,b-2)
+--~ elseif a then
+--~ return name:sub(a)
+--~ else
+--~ return name
+--~ end
+--~ end
+
+--~ local test = file.extname
+--~ local test = file.basename
+--~ local test = file.dirname
+--~ local test = file.addsuffix
+--~ local test = file.replacesuffix
+--~ local test = file.nameonly
+
+--~ print(1,test("./a/b/c/abd.def.xxx","!!!"))
+--~ print(2,test("./../b/c/abd.def.xxx","!!!"))
+--~ print(3,test("a/b/c/abd.def.xxx","!!!"))
+--~ print(4,test("a/b/c/def.xxx","!!!"))
+--~ print(5,test("a/b/c/def","!!!"))
+--~ print(6,test("def","!!!"))
+--~ print(7,test("def.xxx","!!!"))
+
+--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This also provides file checksums and checkers.
+
+local gsub, format, byte = string.gsub, string.format, string.byte
+
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
+ end
+end
+
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEX(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
+
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type = type
+local find, gmatch = string.find, string.gmatch
+
+dir = dir or { }
+
+-- optimizing for no string.find (*) does not save time
+
+local attributes = lfs.attributes
+local walkdir = lfs.dir
+
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
+ end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
+ end
+ end
+ end
+end
+
+dir.glob_pattern = glob_pattern
+
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
+
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
+
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
+ local t = t or { }
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
+ return t
+ else
+ return { }
+ end
+ end
+end
+
+dir.glob = glob
+
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
+
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
+ files[#files+1] = path .. "/" .. name
+ end
+ else
+ files[#files+1] = path .. "/" .. name
+ end
+ end
+ end
+ end
+ return files
+end
+
+dir.globfiles = globfiles
+
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
+
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
+
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
+
+local make_indeed = true -- false
+
+if string.find(os.getenv("PATH"),";") then
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
+ if first then
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
+ else
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
+ if first then
+ pth, drive = first .. middle, true
+ else
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
+ end
+ end
+ end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("a:"))
+--~ print(dir.mkdirs("a:/b/c"))
+--~ print(dir.mkdirs("a:b/c"))
+--~ print(dir.mkdirs("a:/bbb/c"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
+ end
+ lfs.chdir(d)
+ end
+ end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
+
+else
+
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
+ end
+ end
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ end
+ return pth, (lfs.isdir(pth) == true)
+ end
+
+--~ print(dir.mkdirs("","","a","c"))
+--~ print(dir.mkdirs("a"))
+--~ print(dir.mkdirs("/a/b/c"))
+--~ print(dir.mkdirs("/aaa/b/c"))
+--~ print(dir.mkdirs("//a/b/c"))
+--~ print(dir.mkdirs("///a/b/c"))
+--~ print(dir.mkdirs("a/bbb//ccc/"))
+
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
+ end
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
+ end
+
+end
+
+dir.makedirs = dir.mkdirs
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
+
+function boolean.tonumber(b)
+ if b then return 1 else return 0 end
+end
+
+function toboolean(str,tolerant)
+ if tolerant then
+ local tstr = type(str)
+ if tstr == "string" then
+ return str == "true" or str == "yes" or str == "on" or str == "1" or str == "t"
+ elseif tstr == "number" then
+ return tonumber(str) ~= 0
+ elseif tstr == "nil" then
+ return false
+ else
+ return str
+ end
+ elseif str == "true" then
+ return true
+ elseif str == "false" then
+ return false
+ else
+ return str
+ end
+end
+
+function string.is_boolean(str)
+ if type(str) == "string" then
+ if str == "true" or str == "yes" or str == "on" or str == "t" then
+ return true
+ elseif str == "false" or str == "no" or str == "off" or str == "f" then
+ return false
+ end
+ end
+ return nil
+end
+
+function boolean.alwaystrue()
+ return true
+end
+
+function boolean.falsetrue()
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
+
+if not math.round then
+ function math.round(x)
+ return floor(x + 0.5)
+ end
+end
+
+if not math.div then
+ function math.div(n,m)
+ return floor(n/m)
+ end
+end
+
+if not math.mod then
+ function math.mod(n,m)
+ return n % m
+ end
+end
+
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- hm, quite unreadable
+
+if not utils then utils = { } end
+if not utils.merger then utils.merger = { } end
+if not utils.lua then utils.lua = { } end
+
+utils.merger.m_begin = "begin library merge"
+utils.merger.m_end = "end library merge"
+utils.merger.pattern =
+ "%c+" ..
+ "%-%-%s+" .. utils.merger.m_begin ..
+ "%c+(.-)%c+" ..
+ "%-%-%s+" .. utils.merger.m_end ..
+ "%c+"
+
+function utils.merger._self_fake_()
+ return
+ "-- " .. "created merged file" .. "\n\n" ..
+ "-- " .. utils.merger.m_begin .. "\n\n" ..
+ "-- " .. utils.merger.m_end .. "\n\n"
+end
+
+function utils.report(...)
+ print(...)
+end
+
+utils.merger.strip_comment = true
+
+function utils.merger._self_load_(name)
+ local f, data = io.open(name), ""
+ if f then
+ utils.report("reading merge from %s",name)
+ data = f:read("*all")
+ f:close()
+ else
+ utils.report("unknown file to merge %s",name)
+ end
+ if data and utils.merger.strip_comment then
+ -- saves some 20K
+ data = data:gsub("%-%-~[^\n\r]*[\r\n]", "")
+ end
+ return data or ""
+end
+
+function utils.merger._self_save_(name, data)
+ if data ~= "" then
+ local f = io.open(name,'w')
+ if f then
+ utils.report("saving merge from %s",name)
+ f:write(data)
+ f:close()
+ end
+ end
+end
+
+function utils.merger._self_swap_(data,code)
+ if data ~= "" then
+ return (data:gsub(utils.merger.pattern, function(s)
+ return "\n\n" .. "-- "..utils.merger.m_begin .. "\n" .. code .. "\n" .. "-- "..utils.merger.m_end .. "\n\n"
+ end, 1))
+ else
+ return ""
+ end
+end
+
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
+function utils.merger._self_libs_(libs,list)
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
+ if type(libs) == 'string' then libs = { libs } end
+ if type(list) == 'string' then list = { list } end
+ local foundpath = nil
+ for _, lib in ipairs(libs) do
+ for _, pth in ipairs(list) do
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
+ else
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
+ end
+ end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
+ end
+ return table.concat(result, "\n\n")
+end
+
+function utils.merger.selfcreate(libs,list,target)
+ if target then
+ utils.merger._self_save_(
+ target,
+ utils.merger._self_swap_(
+ utils.merger._self_fake_(),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+ end
+end
+
+function utils.merger.selfmerge(name,libs,list,target)
+ utils.merger._self_save_(
+ target or name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ utils.merger._self_libs_(libs,list)
+ )
+ )
+end
+
+function utils.merger.selfclean(name)
+ utils.merger._self_save_(
+ name,
+ utils.merger._self_swap_(
+ utils.merger._self_load_(name),
+ ""
+ )
+ )
+end
+
+function utils.lua.compile(luafile, lucfile, cleanup, strip) -- defaults: cleanup=false strip=true
+ -- utils.report("compiling",luafile,"into",lucfile)
+ os.remove(lucfile)
+ local command = "-o " .. string.quote(lucfile) .. " " .. string.quote(luafile)
+ if strip ~= false then
+ command = "-s " .. command
+ end
+ local done = (os.spawn("texluac " .. command) == 0) or (os.spawn("luac " .. command) == 0)
+ if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
+ -- utils.report("removing",luafile)
+ os.remove(luafile)
+ end
+ return done
+end
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-tab'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
The parser used here is inspired by the variant discussed in the lua book, but
+handles comment and processing instructions, has a different structure, provides
+parent access; a first version used different trickery but was less optimized to we
+went this route. First we had a find based parser, now we have an based one.
+The find based parser can be found in l-xml-edu.lua along with other older code.
+
+
Expecially the lpath code is experimental, we will support some of xpath, but
+only things that make sense for us; as compensation it is possible to hook in your
+own functions. Apart from preprocessing content for we also need
+this module for process management, like handling and
+files.
Beware, the interface may change. For instance at, ns, tg, dt may get more
+verbose names. Once the code is stable we will also remove some tracing and
+optimize the code.
+--ldx]]--
+
+xml = xml or { }
+
+--~ local xml = xml
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, setmetatable = type, next, setmetatable
+local format, lower, find = string.format, string.lower, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers.
+--ldx]]--
+
+local trace_remap = false
+
+if trackers then
+ trackers.register("xml.remap", function(v) trace_remap = v end)
+end
+
+function xml.settrace(str,value)
+ if str == "remap" then
+ trace_remap = value or false
+ end
+end
+
+--[[ldx--
+
First a hack to enable namespace resolving. A namespace is characterized by
+a . The following function associates a namespace prefix with a
+pattern. We use , which in this case is more than twice as fast as a
+find based solution where we loop over an array of patterns. Less code and
+much cleaner.
The next function also registers a namespace, but this time we map a
+given namespace prefix onto a registered one, using the given
+. This used for attributes like xmlns:m.
+
+
+xml.checkns("m","http://www.w3.org/mathml")
+
+--ldx]]--
+
+function xml.checkns(namespace,url)
+ local ns = parse:match(lower(url))
+ if ns and namespace ~= ns then
+ xml.xmlns[namespace] = ns
+ end
+end
+
+--[[ldx--
+
Next we provide a way to turn an into a registered
+namespace. This used for the xmlns attribute.
A namespace in an element can be remapped onto the registered
+one efficiently by using the xml.xmlns table.
+--ldx]]--
+
+--[[ldx--
+
This version uses . We follow the same approach as before, stack and top and
+such. This version is about twice as fast which is mostly due to the fact that
+we don't have to prepare the stream for cdata, doctype etc etc. This variant is
+is dedicated to Luigi Scarso, who challenged me with 40 megabyte files that
+took 12.5 seconds to load (1.5 for file io and the rest for tree building). With
+the implementation we got that down to less 7.3 seconds. Loading the 14
+ interface definition files (2.6 meg) went down from 1.05 seconds to 0.55.
+
+
Next comes the parser. The rather messy doctype definition comes in many
+disguises so it is no surprice that later on have to dedicate quite some
+ code to it.
+
+
+
+
+
+
+
+
+
+
+
The code may look a bit complex but this is mostly due to the fact that we
+resolve namespaces and attach metatables. There is only one public function:
+
+
+local x = xml.convert(somestring)
+
+
+
An optional second boolean argument tells this function not to create a root
+element.
+--ldx]]--
+
+xml.strip_cm_and_dt = false -- an extra global flag, in case we have many includes
+
+-- not just one big nested table capture (lpeg overflow)
+
+local nsremap, resolvens = xml.xmlns, xml.resolvens
+
+local stack, top, dt, at, xmlns, errorstr, entities = {}, {}, {}, {}, {}, nil, {}
+
+local mt = { __tostring = xml.text }
+
+function xml.check_error(top,toclose)
+ return ""
+end
+
+local strip = false
+local cleanup = false
+
+function xml.set_text_cleanup(fnc)
+ cleanup = fnc
+end
+
+local function add_attribute(namespace,tag,value)
+ if cleanup and #value > 0 then
+ value = cleanup(value) -- new
+ end
+ if tag == "xmlns" then
+ xmlns[#xmlns+1] = resolvens(value)
+ at[tag] = value
+ elseif namespace == "xmlns" then
+ xml.checkns(tag,value)
+ at["xmlns:" .. tag] = value
+ else
+ at[tag] = value
+ end
+end
+
+local function add_begin(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = stack[#stack] }
+ setmetatable(top, mt)
+ dt = top.dt
+ stack[#stack+1] = top
+ at = { }
+end
+
+local function add_end(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local toclose = remove(stack)
+ top = stack[#stack]
+ if #stack < 1 then
+ errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "")
+ elseif toclose.tg ~= tag then -- no namespace check
+ errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "")
+ end
+ dt = top.dt
+ dt[#dt+1] = toclose
+ dt[0] = top
+ if toclose.at.xmlns then
+ remove(xmlns)
+ end
+end
+
+local function add_empty(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = stack[#stack]
+ dt = top.dt
+ local t = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = top }
+ dt[#dt+1] = t
+ setmetatable(t, mt)
+ if at.xmlns then
+ remove(xmlns)
+ end
+ at = { }
+end
+
+local function add_text(text)
+ if cleanup and #text > 0 then
+ dt[#dt+1] = cleanup(text)
+ else
+ dt[#dt+1] = text
+ end
+end
+
+local function add_special(what, spacing, text)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ if strip and (what == "@cm@" or what == "@dt@") then
+ -- forget it
+ else
+ dt[#dt+1] = { special=true, ns="", tg=what, dt={text} }
+ end
+end
+
+local function set_message(txt)
+ errorstr = "garbage at the end of the file: " .. gsub(txt,"([ \n\r\t]*)","")
+end
+
+local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
+
+local space = S(' \r\n\t')
+local open = P('<')
+local close = P('>')
+local squote = S("'")
+local dquote = S('"')
+local equal = P('=')
+local slash = P('/')
+local colon = P(':')
+local valid = R('az', 'AZ', '09') + S('_-.')
+local name_yes = C(valid^1) * colon * C(valid^1)
+local name_nop = C(P(true)) * C(valid^1)
+local name = name_yes + name_nop
+
+local utfbom = P('\000\000\254\255') + P('\255\254\000\000') +
+ P('\255\254') + P('\254\255') + P('\239\187\191') -- no capture
+
+local spacing = C(space^0)
+local justtext = C((1-open)^1)
+local somespace = space^1
+local optionalspace = space^0
+
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local attribute = (somespace * name * optionalspace * equal * optionalspace * value) / add_attribute
+local attributes = attribute^0
+
+local text = justtext / add_text
+local balanced = P { "[" * ((1 - S"[]") + V(1))^0 * "]" } -- taken from lpeg manual, () example
+
+local emptyelement = (spacing * open * name * attributes * optionalspace * slash * close) / add_empty
+local beginelement = (spacing * open * name * attributes * optionalspace * close) / add_begin
+local endelement = (spacing * open * slash * name * optionalspace * close) / add_end
+
+local begincomment = open * P("!--")
+local endcomment = P("--") * close
+local begininstruction = open * P("?")
+local endinstruction = P("?") * close
+local begincdata = open * P("![CDATA[")
+local endcdata = P("]]") * close
+
+local someinstruction = C((1 - endinstruction)^0)
+local somecomment = C((1 - endcomment )^0)
+local somecdata = C((1 - endcdata )^0)
+
+local function entity(k,v) entities[k] = v end
+
+local begindoctype = open * P("!DOCTYPE")
+local enddoctype = close
+local beginset = P("[")
+local endset = P("]")
+local doctypename = C((1-somespace)^0)
+local elementdoctype = optionalspace * P("Packaging data in an xml like table is done with the following
+function. Maybe it will go away (when not used).
+--ldx]]--
+
+function xml.is_valid(root)
+ return root and root.dt and root.dt[1] and type(root.dt[1]) == "table" and not root.dt[1].er
+end
+
+function xml.package(tag,attributes,data)
+ local ns, tg = tag:match("^(.-):?([^:]+)$")
+ local t = { ns = ns, tg = tg, dt = data or "", at = attributes or {} }
+ setmetatable(t, mt)
+ return t
+end
+
+function xml.is_valid(root)
+ return root and not root.error
+end
+
+xml.error_handler = (logs and logs.report) or (input and logs.report) or print
+
+--[[ldx--
+
We cannot load an from a filehandle so we need to load
+the whole file first. The function accepts a string representing
+a filename or a file handle.
+--ldx]]--
+
+function xml.load(filename)
+ if type(filename) == "string" then
+ local f = io.open(filename,'r')
+ if f then
+ local root = xml.convert(f:read("*all"))
+ f:close()
+ return root
+ else
+ return xml.convert("")
+ end
+ elseif filename then -- filehandle
+ return xml.convert(filename:read("*all"))
+ else
+ return xml.convert("")
+ end
+end
+
+--[[ldx--
+
When we inject new elements, we need to convert strings to
+valid trees, which is what the next function does.
+--ldx]]--
+
+function xml.toxml(data)
+ if type(data) == "string" then
+ local root = { xml.convert(data,true) }
+ return (#root > 1 and root) or root[1]
+ else
+ return data
+ end
+end
+
+--[[ldx--
+
For copying a tree we use a dedicated function instead of the
+generic table copier. Since we know what we're dealing with we
+can speed up things a bit. The second argument is not to be used!
+--ldx]]--
+
+function copy(old,tables)
+ if old then
+ tables = tables or { }
+ local new = { }
+ if not tables[old] then
+ tables[old] = new
+ end
+ for k,v in pairs(old) do
+ new[k] = (type(v) == "table" and (tables[v] or copy(v, tables))) or v
+ end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+xml.copy = copy
+
+--[[ldx--
+
In serializing the tree or parts of the tree is a major
+actitivity which is why the following function is pretty optimized resulting
+in a few more lines of code than needed. The variant that uses the formatting
+function for all components is about 15% slower than the concatinating
+alternative.
+--ldx]]--
+
+-- todo: add when not present
+
+local fallbackhandle = (tex and tex.sprint) or io.write
+
+local function serialize(e, handle, textconverter, attributeconverter, specialconverter, nocommands)
+ if not e then
+ return
+ elseif not nocommands then
+ local ec = e.command
+ if ec ~= nil then -- we can have all kind of types
+ if e.special then
+ local etg, edt = e.tg, e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ return
+ else
+ -- no need to handle any further
+ end
+ end
+ end
+ local xc = xml.command
+ if xc then
+ xc(e,ec)
+ return
+ end
+ end
+ end
+ handle = handle or fallbackhandle
+ local etg = e.tg
+ if etg then
+ if e.special then
+ local edt = e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ else
+ -- no need to handle any further
+ end
+ elseif etg == "@pi@" then
+ -- handle(format("%s?>",edt[1]))
+ handle("" .. edt[1] .. "?>")
+ elseif etg == "@cm@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@cd@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@dt@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@rt@" then
+ serialize(edt,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ else
+ local ens, eat, edt, ern = e.ns, e.at, e.dt, e.rn
+ local ats = eat and next(eat) and { } -- type test maybe faster
+ if ats then
+ if attributeconverter then
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
+ end
+ else
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,v)
+ end
+ end
+ end
+ if ern and trace_remap and ern ~= ens then
+ ens = ern
+ end
+ if ens ~= "" then
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s:%s %s>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s:%s>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ serialize(e,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s:%s>",ens,etg))
+ handle("" .. ens .. ":" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s:%s %s/>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s:%s/>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. "/>")
+ end
+ end
+ else
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s %s>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s>",etg))
+ handle("<" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local ei = edt[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s>",etg))
+ handle("" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s %s/>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s/>",etg))
+ handle("<" .. etg .. "/>")
+ end
+ end
+ end
+ end
+ elseif type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ for i=1,#e do
+ local ei = e[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ end
+end
+
+xml.serialize = serialize
+
+function xml.checkbom(root) -- can be made faster
+ if root.ri then
+ local dt, found = root.dt, false
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "table" and v.special and v.tg == "@pi" and find(v.dt,"xml.*version=") then
+ found = true
+ break
+ end
+ end
+ if not found then
+ insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } )
+ insert(dt, 2, "\n" )
+ end
+ end
+end
+
+--[[ldx--
+
At the cost of some 25% runtime overhead you can first convert the tree to a string
+and then handle the lot.
+--ldx]]--
+
+function xml.tostring(root) -- 25% overhead due to collecting
+ if root then
+ if type(root) == 'string' then
+ return root
+ elseif next(root) then -- next is faster than type (and >0 test)
+ local result = { }
+ serialize(root,function(s) result[#result+1] = s end)
+ return concat(result,"")
+ end
+ end
+ return ""
+end
+
+--[[ldx--
+
The next function operated on the content only and needs a handle function
+that accepts a string.
+--ldx]]--
+
+function xml.string(e,handle)
+ if not handle or (e.special and e.tg ~= "@rt@") then
+ -- nothing
+ elseif e.tg then
+ local edt = e.dt
+ if edt then
+ for i=1,#edt do
+ xml.string(edt[i],handle)
+ end
+ end
+ else
+ handle(e)
+ end
+end
+
+--[[ldx--
+
How you deal with saving data depends on your preferences. For a 40 MB database
+file the timing on a 2.3 Core Duo are as follows (time in seconds):
+
+
+1.3 : load data from file to string
+6.1 : convert string into tree
+5.3 : saving in file using xmlsave
+6.8 : converting to string using xml.tostring
+3.6 : saving converted string in file
+
+
+
The save function is given below.
+--ldx]]--
+
+function xml.save(root,name)
+ local f = io.open(name,"w")
+ if f then
+ xml.serialize(root,function(s) f:write(s) end)
+ f:close()
+ end
+end
+
+--[[ldx--
+
A few helpers:
+--ldx]]--
+
+function xml.body(root)
+ return (root.ri and root.dt[root.ri]) or root
+end
+
+function xml.text(root)
+ return (root and xml.tostring(root)) or ""
+end
+
+function xml.content(root) -- bugged
+ return (root and root.dt and xml.tostring(root.dt)) or ""
+end
+
+function xml.isempty(root, pattern)
+ if pattern == "" or pattern == "*" then
+ pattern = nil
+ end
+ if pattern then
+ -- todo
+ return false
+ else
+ return not root or not root.dt or #root.dt == 0 or root.dt == ""
+ end
+end
+
+--[[ldx--
+
The next helper erases an element but keeps the table as it is,
+and since empty strings are not serialized (effectively) it does
+not harm. Copying the table would take more time. Usage:
+
+
+dt[k] = xml.empty() or xml.empty(dt,k)
+
+--ldx]]--
+
+function xml.empty(dt,k)
+ if dt and k then
+ dt[k] = ""
+ return dt[k]
+ else
+ return ""
+ end
+end
+
+--[[ldx--
+
The next helper assigns a tree (or string). Usage:
+
+
+dt[k] = xml.assign(root) or xml.assign(dt,k,root)
+
+--ldx]]--
+
+function xml.assign(dt,k,root)
+ if dt and k then
+ dt[k] = (type(root) == "table" and xml.body(root)) or root
+ return dt[k]
+ else
+ return xml.body(root)
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-pth'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, lower, gmatch, gsub, find = string.format, string.lower, string.gmatch, string.gsub, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers. Here we overload a previously defined
+function.
+--ldx]]--
+
+local trace_lpath = false
+
+if trackers then
+ trackers.register("xml.lpath", function(v) trace_lpath = v end)
+end
+
+local settrace = xml.settrace -- lxml-tab
+
+function xml.settrace(str,value)
+ if str == "lpath" then
+ trace_lpath = value or false
+ else
+ settrace(str,value) -- lxml-tab
+ end
+end
+
+--[[ldx--
+
We've now arrived at an intersting part: accessing the tree using a subset
+of and since we're not compatible we call it . We
+will explain more about its usage in other documents.
+--ldx]]--
+
+local lpathcalls = 0 -- statistics
+local lpathcached = 0 -- statistics
+
+xml.functions = xml.functions or { }
+xml.expressions = xml.expressions or { }
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+local actions = {
+ [10] = "stay",
+ [11] = "parent",
+ [12] = "subtree root",
+ [13] = "document root",
+ [14] = "any",
+ [15] = "many",
+ [16] = "initial",
+ [20] = "match",
+ [21] = "match one of",
+ [22] = "match and attribute eq",
+ [23] = "match and attribute ne",
+ [24] = "match one of and attribute eq",
+ [25] = "match one of and attribute ne",
+ [27] = "has attribute",
+ [28] = "has value",
+ [29] = "fast match",
+ [30] = "select",
+ [31] = "expression",
+ [40] = "processing instruction",
+}
+
+-- a rather dumb lpeg
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+-- instead of using functions we just parse a few names which saves a call
+-- later on
+
+local lp_position = P("position()") / "ps"
+local lp_index = P("index()") / "id"
+local lp_text = P("text()") / "tx"
+local lp_name = P("name()") / "(ns~='' and ns..':'..tg)" -- "((rt.ns~='' and rt.ns..':'..rt.tg) or '')"
+local lp_tag = P("tag()") / "tg" -- (rt.tg or '')
+local lp_ns = P("ns()") / "ns" -- (rt.ns or '')
+local lp_noequal = P("!=") / "~=" + P("<=") + P(">=") + P("==")
+local lp_doequal = P("=") / "=="
+local lp_attribute = P("@") / "" * Cc("(at['") * R("az","AZ","--","__")^1 * Cc("'] or '')")
+
+local lp_lua_function = C(R("az","AZ","--","__")^1 * (P(".") * R("az","AZ","--","__")^1)^1) * P("(") / function(t) -- todo: better . handling
+ return t .. "("
+end
+
+local lp_function = C(R("az","AZ","--","__")^1) * P("(") / function(t) -- todo: better . handling
+ if expressions[t] then
+ return "expressions." .. t .. "("
+ else
+ return "expressions.error("
+ end
+end
+
+local lparent = lpeg.P("(")
+local rparent = lpeg.P(")")
+local noparent = 1 - (lparent+rparent)
+local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
+local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
+
+-- if we use a dedicated namespace then we don't need to pass rt and k
+
+local lp_special = (C(P("name")+P("text")+P("tag"))) * value / function(t,s)
+ if expressions[t] then
+ if s then
+ return "expressions." .. t .. "(r,k," .. s ..")"
+ else
+ return "expressions." .. t .. "(r,k)"
+ end
+ else
+ return "expressions.error(" .. t .. ")"
+ end
+end
+
+local converter = lpeg.Cs ( (
+ lp_position +
+ lp_index +
+ lp_text + lp_name + -- fast one
+ lp_special +
+ lp_noequal + lp_doequal +
+ lp_attribute +
+ lp_lua_function +
+ lp_function +
+1 )^1 )
+
+-- expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1
+
+local template = [[
+ return function(expressions,r,d,k,e,dt,ns,tg,id,ps)
+ local at, tx = e.at or { }, dt[1] or ""
+ return %s
+ end
+]]
+
+local function make_expression(str)
+ str = converter:match(str)
+ return str, loadstring(format(template,str))()
+end
+
+local map = { }
+
+local space = S(' \r\n\t')
+local squote = S("'")
+local dquote = S('"')
+local lparent = P('(')
+local rparent = P(')')
+local atsign = P('@')
+local lbracket = P('[')
+local rbracket = P(']')
+local exclam = P('!')
+local period = P('.')
+local eq = P('==') + P('=')
+local ne = P('<>') + P('!=')
+local star = P('*')
+local slash = P('/')
+local colon = P(':')
+local bar = P('|')
+local hat = P('^')
+local valid = R('az', 'AZ', '09') + S('_-')
+local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
+local name_nop = Cc("*") * C(valid^1)
+local name = name_yes + name_nop
+local number = C((S('+-')^0 * R('09')^1)) / tonumber
+local names = (bar^0 * name)^1
+local morenames = name * (bar^0 * name)^1
+local instructiontag = P('pi::')
+local spacing = C(space^0)
+local somespace = space^1
+local optionalspace = space^0
+local text = C(valid^0)
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local empty = 1-slash
+
+local is_eq = lbracket * atsign * name * eq * value * rbracket
+local is_ne = lbracket * atsign * name * ne * value * rbracket
+local is_attribute = lbracket * atsign * name * rbracket
+local is_value = lbracket * value * rbracket
+local is_number = lbracket * number * rbracket
+
+local nobracket = 1-(lbracket+rbracket) -- must be improved
+local is_expression = lbracket * C(((C(nobracket^1))/make_expression)) * rbracket
+
+local is_expression = lbracket * (C(nobracket^1))/make_expression * rbracket
+
+local is_one = name
+local is_none = exclam * name
+local is_one_of = ((lparent * names * rparent) + morenames)
+local is_none_of = exclam * ((lparent * names * rparent) + morenames)
+
+local stay = (period )
+local parent = (period * period ) / function( ) map[#map+1] = { 11 } end
+local subtreeroot = (slash + hat ) / function( ) map[#map+1] = { 12 } end
+local documentroot = (hat * hat ) / function( ) map[#map+1] = { 13 } end
+local any = (star ) / function( ) map[#map+1] = { 14 } end
+local many = (star * star ) / function( ) map[#map+1] = { 15 } end
+local initial = (hat * hat * hat ) / function( ) map[#map+1] = { 16 } end
+
+local match = (is_one ) / function(...) map[#map+1] = { 20, true , ... } end
+local match_one_of = (is_one_of ) / function(...) map[#map+1] = { 21, true , ... } end
+local dont_match = (is_none ) / function(...) map[#map+1] = { 20, false, ... } end
+local dont_match_one_of = (is_none_of ) / function(...) map[#map+1] = { 21, false, ... } end
+
+local match_and_eq = (is_one * is_eq ) / function(...) map[#map+1] = { 22, true , ... } end
+local match_and_ne = (is_one * is_ne ) / function(...) map[#map+1] = { 23, true , ... } end
+local dont_match_and_eq = (is_none * is_eq ) / function(...) map[#map+1] = { 22, false, ... } end
+local dont_match_and_ne = (is_none * is_ne ) / function(...) map[#map+1] = { 23, false, ... } end
+
+local match_one_of_and_eq = (is_one_of * is_eq ) / function(...) map[#map+1] = { 24, true , ... } end
+local match_one_of_and_ne = (is_one_of * is_ne ) / function(...) map[#map+1] = { 25, true , ... } end
+local dont_match_one_of_and_eq = (is_none_of * is_eq ) / function(...) map[#map+1] = { 24, false, ... } end
+local dont_match_one_of_and_ne = (is_none_of * is_ne ) / function(...) map[#map+1] = { 25, false, ... } end
+
+local has_attribute = (is_one * is_attribute) / function(...) map[#map+1] = { 27, true , ... } end
+local has_value = (is_one * is_value ) / function(...) map[#map+1] = { 28, true , ... } end
+local dont_has_attribute = (is_none * is_attribute) / function(...) map[#map+1] = { 27, false, ... } end
+local dont_has_value = (is_none * is_value ) / function(...) map[#map+1] = { 28, false, ... } end
+local position = (is_one * is_number ) / function(...) map[#map+1] = { 30, true, ... } end
+local dont_position = (is_none * is_number ) / function(...) map[#map+1] = { 30, false, ... } end
+
+local expression = (is_one * is_expression)/ function(...) map[#map+1] = { 31, true, ... } end
+local dont_expression = (is_none * is_expression)/ function(...) map[#map+1] = { 31, false, ... } end
+
+local self_expression = ( is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, true, "*", "*", ... } end
+local dont_self_expression = (exclam * is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, false, "*", "*", ... } end
+
+local instruction = (instructiontag * text ) / function(...) map[#map+1] = { 40, ... } end
+local nothing = (empty ) / function( ) map[#map+1] = { 15 } end -- 15 ?
+local crap = (1-slash)^1
+
+-- a few ugly goodies:
+
+local docroottag = P('^^') / function( ) map[#map+1] = { 12 } end
+local subroottag = P('^') / function( ) map[#map+1] = { 13 } end
+local roottag = P('root::') / function( ) map[#map+1] = { 12 } end
+local parenttag = P('parent::') / function( ) map[#map+1] = { 11 } end
+local childtag = P('child::')
+local selftag = P('self::')
+
+-- there will be more and order will be optimized
+
+local selector = (
+ instruction +
+-- many + any + -- brrr, not here !
+ parent + stay +
+ dont_position + position +
+ dont_match_one_of_and_eq + dont_match_one_of_and_ne +
+ match_one_of_and_eq + match_one_of_and_ne +
+ dont_match_and_eq + dont_match_and_ne +
+ match_and_eq + match_and_ne +
+ dont_expression + expression +
+ dont_self_expression + self_expression +
+ has_attribute + has_value +
+ dont_match_one_of + match_one_of +
+ dont_match + match +
+ many + any +
+ crap + empty
+)
+
+local grammar = P { "startup",
+ startup = (initial + documentroot + subtreeroot + roottag + docroottag + subroottag)^0 * V("followup"),
+ followup = ((slash + parenttag + childtag + selftag)^0 * selector)^1,
+}
+
+local function compose(str)
+ if not str or str == "" then
+ -- wildcard
+ return true
+ elseif str == '/' then
+ -- root
+ return false
+ else
+ map = { }
+ grammar:match(str)
+ if #map == 0 then
+ return true
+ else
+ local m = map[1][1]
+ if #map == 1 then
+ if m == 14 or m == 15 then
+ -- wildcard
+ return true
+ elseif m == 12 then
+ -- root
+ return false
+ end
+ elseif #map == 2 and m == 12 and map[2][1] == 20 then
+ -- return { { 29, map[2][2], map[2][3], map[2][4], map[2][5] } }
+ map[2][1] = 29
+ return { map[2] }
+ end
+ if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
+ insert(map, 1, { 16 })
+ end
+ -- print(gsub(table.serialize(map),"[ \n]+"," "))
+ return map
+ end
+ end
+end
+
+local cache = { }
+
+function xml.lpath(pattern,trace)
+ lpathcalls = lpathcalls + 1
+ if type(pattern) == "string" then
+ local result = cache[pattern]
+ if result == nil then -- can be false which is valid -)
+ result = compose(pattern)
+ cache[pattern] = result
+ lpathcached = lpathcached + 1
+ end
+ if trace or trace_lpath then
+ xml.lshow(result)
+ end
+ return result
+ else
+ return pattern
+ end
+end
+
+function xml.cached_patterns()
+ return cache
+end
+
+-- we run out of locals (limited to 200)
+--
+-- local fallbackreport = (texio and texio.write) or io.write
+
+function xml.lshow(pattern,report)
+-- report = report or fallbackreport
+ report = report or (texio and texio.write) or io.write
+ local lp = xml.lpath(pattern)
+ if lp == false then
+ report(" -: root\n")
+ elseif lp == true then
+ report(" -: wildcard\n")
+ else
+ if type(pattern) == "string" then
+ report(format("pattern: %s\n",pattern))
+ end
+ for k=1,#lp do
+ local v = lp[k]
+ if #v > 1 then
+ local t = { }
+ for i=2,#v do
+ local vv = v[i]
+ if type(vv) == "string" then
+ t[#t+1] = (vv ~= "" and vv) or "#"
+ elseif type(vv) == "boolean" then
+ t[#t+1] = (vv and "==") or "<>"
+ end
+ end
+ report(format("%2i: %s %s -> %s\n", k,v[1],actions[v[1]],concat(t," ")))
+ else
+ report(format("%2i: %s %s\n", k,v[1],actions[v[1]]))
+ end
+ end
+ end
+end
+
+function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
+ local t = { ... }
+-- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+ local report = (type(t[#t]) == "function" and t[#t]) or (texio and texio.write) or io.write
+ if e == nil then
+ report("\n")
+ elseif type(e) ~= "table" then
+ report(tostring(e))
+ elseif e.tg then
+ report(tostring(e) .. "\n")
+ else
+ for i=1,#e do
+ report(tostring(e[i]) .. "\n")
+ end
+ end
+end
+
+--[[ldx--
+
An is converted to a table with instructions for traversing the
+tree. Hoever, simple cases are signaled by booleans. Because we don't know in
+advance what we want to do with the found element the handle gets three arguments:
+
+
+r : the root element of the data table
+d : the data table of the result
+t : the index in the data table of the result
+
+
+
Access to the root and data table makes it possible to construct insert and delete
+functions.
+--ldx]]--
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+expressions.contains = string.find
+expressions.find = string.find
+expressions.upper = string.upper
+expressions.lower = string.lower
+expressions.number = tonumber
+expressions.boolean = toboolean
+
+expressions.oneof = function(s,...) -- slow
+ local t = {...} for i=1,#t do if s == t[i] then return true end end return false
+end
+
+expressions.error = function(str)
+ xml.error_handler("unknown function in lpath expression",str or "?")
+ return false
+end
+
+functions.text = function(root,k,n) -- unchecked, maybe one deeper
+ local t = type(t)
+ if t == "string" then
+ return t
+ else -- todo n
+ local rdt = root.dt
+ return (rdt and rdt[k]) or root[k] or ""
+ end
+end
+
+functions.name = function(d,k,n) -- ns + tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ if found then
+ local ns, tg = found.rn or found.ns or "", found.tg
+ if ns ~= "" then
+ return ns .. ":" .. tg
+ else
+ return tg
+ end
+ else
+ return ""
+ end
+end
+
+functions.tag = function(d,k,n) -- only tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ return (found and found.tg) or ""
+end
+
+expressions.text = functions.text
+expressions.name = functions.name
+expressions.tag = functions.tag
+
+local function traverse(root,pattern,handle,reverse,index,parent,wildcard) -- multiple only for tags, not for namespaces
+ if not root then -- error
+ return false
+ elseif pattern == false then -- root
+ handle(root,root.dt,root.ri)
+ return false
+ elseif pattern == true then -- wildcard
+ local rootdt = root.dt
+ if rootdt then
+ local start, stop, step = 1, #rootdt, 1
+ if reverse then
+ start, stop, step = stop, start, -1
+ end
+ for k=start,stop,step do
+ if handle(root,rootdt,root.ri or k) then return false end
+ if not traverse(rootdt[k],true,handle,reverse) then return false end
+ end
+ end
+ return false
+ elseif root.dt then
+ index = index or 1
+ local action = pattern[index]
+ local command = action[1]
+ if command == 29 then -- fast case /oeps
+ local rootdt = root.dt
+ for k=1,#rootdt do
+ local e = rootdt[k]
+ local tg = e.tg
+ if e.tg then
+ local ns = e.rn or e.ns
+ local ns_a, tg_a = action[3], action[4]
+ local matched = (ns_a == "*" or ns == ns_a) and (tg_a == "*" or tg == tg_a)
+ if not action[2] then matched = not matched end
+ if matched then
+ if handle(root,rootdt,k) then return false end
+ end
+ end
+ end
+ elseif command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ if (command == 16 or command == 12) and index == 1 then -- initial
+ -- wildcard = true
+ wildcard = command == 16 -- ok?
+ index = index + 1
+ action = pattern[index]
+ command = action and action[1] or 0 -- something is wrong
+ end
+ if command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ local rootdt = root.dt
+ local start, stop, step, n, dn = 1, #rootdt, 1, 0, 1
+ if command == 30 then
+ if action[5] < 0 then
+ start, stop, step = stop, start, -1
+ dn = -1
+ end
+ elseif reverse and index == #pattern then
+ start, stop, step = stop, start, -1
+ end
+ local idx = 0
+ local hsh = { } -- this will slooow down the lot
+ for k=start,stop,step do -- we used to have functions for all but a case is faster
+ local e = rootdt[k]
+ local ns, tg = e.rn or e.ns, e.tg
+ if tg then
+ -- we can optimize this for simple searches, but it probably does not pay off
+ hsh[tg] = (hsh[tg] or 0) + 1
+ idx = idx + 1
+ if command == 30 then
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ n = n + dn
+ if n == action[5] then
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ break
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ else
+ local matched, multiple = false, false
+ if command == 20 then -- match
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 21 then -- match one of
+ multiple = true
+ for i=3,#action,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 22 then -- eq
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ matched = matched and e.at[action[6]] == action[7]
+ elseif command == 23 then -- ne
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = mached and e.at[action[6]] ~= action[7]
+ elseif command == 24 then -- one of eq
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] == action[#action]
+ elseif command == 25 then -- one of ne
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] ~= action[#action]
+ elseif command == 27 then -- has attribute
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[5]]
+ elseif command == 28 then -- has value
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and edt and edt[1] == action[5]
+ elseif command == 31 then
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ matched = action[6](expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1)
+ end
+ end
+ if matched then -- combine tg test and at test
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ if wildcard then
+ if multiple then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ else
+ -- maybe or multiple; anyhow, check on (section|title) vs just section and title in example in lxml
+ if not traverse(e,pattern,handle,reverse,index,root) then return false end
+ end
+ end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 14 then -- any
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 15 then -- many
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root,true) then return false end
+ end
+ -- not here : 11
+ elseif command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,root,index+1) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif command == 40 and e.special and tg == "@pi@" then -- pi
+ local pi = action[2]
+ if pi ~= "" then
+ local pt = e.dt[1]
+ if pt and pt:find(pi) then
+ if handle(root,rootdt,k) then
+ return false
+ end
+ end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ end
+ else
+ -- not here : 11
+ if command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ break -- else loop
+ end
+ end
+ end
+ end
+ end
+ end
+ return true
+end
+
+xml.traverse = traverse
+
+--[[ldx--
+
Next come all kind of locators and manipulators. The most generic function here
+is xml.filter(root,pattern). All registers functions in the filters namespace
+can be path of a search path, as in:
+
+
+local r, d, k = xml.filter(root,"/a/b/c/position(4)"
+
+--ldx]]--
+
+local traverse, lpath, convert = xml.traverse, xml.lpath, xml.convert
+
+xml.filters = { }
+
+function xml.filters.default(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.attributes(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ if ekat then
+ if arguments then
+ return ekat[arguments] or "", rt, dt, dk
+ else
+ return ekat, rt, dt, dk
+ end
+ else
+ return { }, rt, dt, dk
+ end
+end
+
+function xml.filters.reverse(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.count(root,pattern,everything)
+ local n = 0
+ traverse(root, lpath(pattern), function(r,d,t)
+ if everything or type(d[t]) == "table" then
+ n = n + 1
+ end
+ end)
+ return n
+end
+
+function xml.filters.elements(root, pattern) -- == all
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e then
+ t[#t+1] = e
+ end
+ end)
+ return t
+end
+
+function xml.filters.texts(root, pattern)
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e and e.dt then
+ t[#t+1] = e.dt
+ end
+ end)
+ return t
+end
+
+function xml.filters.first(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.last(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.index(root,pattern,arguments)
+ local rt, dt, dk, reverse, i = nil, nil, nil, false, tonumber(arguments or '1') or 1
+ if i and i ~= 0 then
+ if i < 0 then
+ reverse, i = true, -i
+ end
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk, i = r, d, k, i-1 return i == 0 end, reverse)
+ if i == 0 then
+ return dt and dt[dk], rt, dt, dk
+ end
+ end
+ return nil, nil, nil, nil
+end
+
+function xml.filters.attribute(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ return (ekat and (ekat[arguments] or ekat[gsub(arguments,"^([\"\'])(.*)%1$","%2")])) or ""
+end
+
+function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
+ local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
+ if dtk then -- n
+ local dtkdt = dtk.dt
+ if not dtkdt then
+ return "", rt, dt, dk
+ elseif #dtkdt == 1 and type(dtkdt[1]) == "string" then
+ return dtkdt[1], rt, dt, dk
+ else
+ return xml.tostring(dtkdt), rt, dt, dk
+ end
+ else
+ return "", rt, dt, dk
+ end
+end
+
+function xml.filters.tag(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.tag(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+function xml.filters.name(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.name(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+--[[ldx--
+
For splitting the filter function from the path specification, we can
+use string matching or lpeg matching. Here the difference in speed is
+neglectable but the lpeg variant is more robust.
+--ldx]]--
+
+-- not faster but hipper ... although ... i can't get rid of the trailing / in the path
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+local slash = P('/')
+local name = (R("az","AZ","--","__"))^1
+local path = C(((1-slash)^0 * slash)^1)
+local argument = P { "(" * C(((1 - S("()")) + V(1))^0) * ")" }
+local action = Cc(1) * path * C(name) * argument
+local attribute = Cc(2) * path * P('@') * C(name)
+local direct = Cc(3) * Cc("../*") * slash^0 * C(name) * argument
+
+local parser = direct + action + attribute
+
+local filters = xml.filters
+local attribute_filter = xml.filters.attributes
+local default_filter = xml.filters.default
+
+-- todo: also hash, could be gc'd
+
+function xml.filter(root,pattern)
+ local kind, a, b, c = parser:match(pattern)
+ if kind == 1 or kind == 3 then
+ return (filters[b] or default_filter)(root,a,c)
+ elseif kind == 2 then
+ return attribute_filter(root,a,b)
+ else
+ return default_filter(root,pattern)
+ end
+end
+
+--~ slightly faster, but first we need a proper test file
+--~
+--~ local hash = { }
+--~
+--~ function xml.filter(root,pattern)
+--~ local h = hash[pattern]
+--~ if not h then
+--~ local kind, a, b, c = parser:match(pattern)
+--~ if kind == 1 then
+--~ h = { kind, filters[b] or default_filter, a, b, c }
+--~ elseif kind == 2 then
+--~ h = { kind, attribute_filter, a, b, c }
+--~ else
+--~ h = { kind, default_filter, a, b, c }
+--~ end
+--~ hash[pattern] = h
+--~ end
+--~ local kind = h[1]
+--~ if kind == 1 then
+--~ return h[2](root,h[2],h[4])
+--~ elseif kind == 2 then
+--~ return h[2](root,h[2],h[3])
+--~ else
+--~ return h[2](root,pattern)
+--~ end
+--~ end
+
+--[[ldx--
+
The following functions collect elements and texts.
+--ldx]]--
+
+-- still somewhat bugged
+
+function xml.collect_elements(root, pattern, ignorespaces)
+ local rr, dd = { }, { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk then
+ if ignorespaces and type(dk) == "string" and dk:find("[^%S]") then
+ -- ignore
+ else
+ local n = #rr+1
+ rr[n], dd[n] = r, dk
+ end
+ end
+ end)
+ return dd, rr
+end
+
+function xml.collect_texts(root, pattern, flatten)
+ local t = { } -- no r collector
+ traverse(root, lpath(pattern), function(r,d,k)
+ if d then
+ local ek = d[k]
+ local tx = ek and ek.dt
+ if flatten then
+ if tx then
+ t[#t+1] = xml.tostring(tx) or ""
+ else
+ t[#t+1] = ""
+ end
+ else
+ t[#t+1] = tx or ""
+ end
+ else
+ t[#t+1] = ""
+ end
+ end)
+ return t
+end
+
+function xml.collect_tags(root, pattern, nonamespace)
+ local t = { }
+ xml.traverse(root, xml.lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk and type(dk) == "table" then
+ local ns, tg = e.ns, e.tg
+ if nonamespace then
+ t[#t+1] = tg -- if needed we can return an extra table
+ elseif ns == "" then
+ t[#t+1] = tg
+ else
+ t[#t+1] = ns .. ":" .. tg
+ end
+ end
+ end)
+ return #t > 0 and {}
+end
+
+--[[ldx--
+
Often using an iterators looks nicer in the code than passing handler
+functions. The book describes how to use coroutines for that
+purpose (). This permits
+code like:
+
+
+for r, d, k in xml.elements(xml.load('text.xml'),"title") do
+ print(d[k])
+end
+
+
+
Which will print all the titles in the document. The iterator variant takes
+1.5 times the runtime of the function variant which is due to the overhead in
+creating the wrapper. So, instead of:
+
+
+function xml.filters.first(root,pattern)
+ for rt,dt,dk in xml.elements(root,pattern)
+ return dt and dt[dk], rt, dt, dk
+ end
+ return nil, nil, nil, nil
+end
+
+
+
We use the function variants in the filters.
+--ldx]]--
+
+local wrap, yield = coroutine.wrap, coroutine.yield
+
+function xml.elements(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), yield, reverse) end)
+end
+
+function xml.elements_only(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), function(r,d,k) yield(d[k]) end, reverse) end)
+end
+
+function xml.each_element(root, pattern, handle, reverse)
+ local ok
+ traverse(root, lpath(pattern), function(r,d,k) ok = true handle(r,d,k) end, reverse)
+ return ok
+end
+
+function xml.process_elements(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then
+ for i=1,#dkdt do
+ local v = dkdt[i]
+ if v.tg then handle(v) end
+ end
+ end
+ end)
+end
+
+function xml.process_attributes(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local ek = d[k]
+ local a = ek.at or { }
+ handle(a)
+ if next(a) then -- next is faster than type (and >0 test)
+ ek.at = a
+ else
+ ek.at = nil
+ end
+ end)
+end
+
+--[[ldx--
+
We've now arrives at the functions that manipulate the tree.
+--ldx]]--
+
+function xml.inject_element(root, pattern, element, prepend)
+ if root and element then
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=1,#matches do
+ local m = matches[i]
+ local r, d, k, element, edt = m[1], m[2], m[3], m[4], nil
+ if element.ri then
+ element = element.dt[element.ri].dt
+ else
+ element = element.dt
+ end
+ if r.ri then
+ edt = r.dt[r.ri].dt
+ else
+ edt = d and d[k] and d[k].dt
+ end
+ if edt then
+ local be, af
+ if prepend then
+ be, af = xml.copy(element), edt
+ else
+ be, af = edt, xml.copy(element)
+ end
+ for i=1,#af do
+ be[#be+1] = af[i]
+ end
+ if r.ri then
+ r.dt[r.ri].dt = be
+ else
+ d[k].dt = be
+ end
+ else
+ -- r.dt = element.dt -- todo
+ end
+ end
+ end
+ end
+end
+
+-- todo: copy !
+
+function xml.insert_element(root, pattern, element, before) -- todo: element als functie
+ if root and element then
+ if pattern == "/" then
+ xml.inject_element(root, pattern, element, before)
+ else
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ local r, d, k, element = m[1], m[2], m[3], m[4]
+ if not before then k = k + 1 end
+ if element.tg then
+ insert(d,k,element) -- untested
+--~ elseif element.dt then
+--~ for _,v in ipairs(element.dt) do -- i added
+--~ insert(d,k,v)
+--~ k = k + 1
+--~ end
+--~ end
+ else
+ local edt = element.dt
+ if edt then
+ for i=1,#edt do
+ insert(d,k,edt[i])
+ k = k + 1
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+xml.insert_element_after = xml.insert_element
+xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end
+xml.inject_element_after = xml.inject_element
+xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end
+
+function xml.delete_element(root, pattern)
+ local matches, deleted = { }, { }
+ local collect = function(r,d,k) matches[#matches+1] = { r, d, k } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ deleted[#deleted+1] = remove(m[2],m[3])
+ end
+ return deleted
+end
+
+function xml.replace_element(root, pattern, element)
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ traverse(root, lpath(pattern), function(rm, d, k)
+ d[k] = element.dt -- maybe not clever enough
+ end)
+ end
+end
+
+local function load_data(name) -- == io.loaddata
+ local f, data = io.open(name), ""
+ if f then
+ data = f:read("*all",'b') -- 'b' ?
+ f:close()
+ end
+ return data
+end
+
+function xml.include(xmldata,pattern,attribute,recursive,loaddata)
+ -- parse="text" (default: xml), encoding="" (todo)
+ -- attribute = attribute or 'href'
+ pattern = pattern or 'include'
+ loaddata = loaddata or load_data
+ local function include(r,d,k)
+ local ek, name = d[k], nil
+ if not attribute or attribute == "" then
+ local ekdt = ek.dt
+ name = (type(ekdt) == "table" and ekdt[1]) or ekdt
+ end
+ if not name then
+ if ek.at then
+ for a in gmatch(attribute or "href","([^|]+)") do
+ name = ek.at[a]
+ if name then break end
+ end
+ end
+ end
+ local data = (name and name ~= "" and loaddata(name)) or ""
+ if data == "" then
+ xml.empty(d,k)
+ elseif ek.at["parse"] == "text" then -- for the moment hard coded
+ d[k] = xml.escaped(data)
+ else
+ local xi = xml.convert(data)
+ if not xi then
+ xml.empty(d,k)
+ else
+ if recursive then
+ xml.include(xi,pattern,attribute,recursive,loaddata)
+ end
+ xml.assign(d,k,xi)
+ end
+ end
+ end
+ xml.each_element(xmldata, pattern, include)
+end
+
+function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space !
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then -- can be optimized
+ local t = { }
+ for i=1,#dkdt do
+ local str = dkdt[i]
+ if type(str) == "string" then
+
+ if str == "" then
+ -- stripped
+ else
+ if nolines then
+ str = gsub(str,"[ \n\r\t]+"," ")
+ end
+ if str == "" then
+ -- stripped
+ else
+ t[#t+1] = str
+ end
+ end
+ else
+ t[#t+1] = str
+ end
+ end
+ d[k].dt = t
+ end
+ end)
+end
+
+local function rename_space(root, oldspace, newspace) -- fast variant
+ local ndt = #root.dt
+ for i=1,ndt or 0 do
+ local e = root[i]
+ if type(e) == "table" then
+ if e.ns == oldspace then
+ e.ns = newspace
+ if e.rn then
+ e.rn = newspace
+ end
+ end
+ local edt = e.dt
+ if edt then
+ rename_space(edt, oldspace, newspace)
+ end
+ end
+ end
+end
+
+xml.rename_space = rename_space
+
+function xml.remap_tag(root, pattern, newtg)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].tg = newtg
+ end)
+end
+function xml.remap_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].ns = newns
+ end)
+end
+function xml.check_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ if (not dk.rn or dk.rn == "") and dk.ns == "" then
+ dk.rn = newns
+ end
+ end)
+end
+function xml.remap_name(root, pattern, newtg, newns, newrn)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ dk.tg = newtg
+ dk.ns = newns
+ dk.rn = newrn
+ end)
+end
+
+function xml.filters.found(root,pattern,check_content)
+ local found = false
+ traverse(root, lpath(pattern), function(r,d,k)
+ if check_content then
+ local dk = d and d[k]
+ found = dk and dk.dt and next(dk.dt) and true
+ else
+ found = true
+ end
+ return true
+ end)
+ return found
+end
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+function xml.statistics()
+ return {
+ lpathcalls = lpathcalls,
+ lpathcached = lpathcached,
+ }
+end
+
+-- xml.set_text_cleanup(xml.show_text_entities)
+-- xml.set_text_cleanup(xml.resolve_text_entities)
+
+--~ xml.lshow("/../../../a/(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!b[@d!='e']/f")
+
+--~ x = xml.convert([[
+--~
+--~ 01
+--~ 02
+--~ 03
+--~ OK
+--~ 05
+--~ 06
+--~ ALSO OK
+--~
+--~ ]])
+
+--~ xml.settrace("lpath",true)
+
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
+--~ xml.xshow(xml.first(x,"b[@n=='03' or @n=='08']"))
+--~ xml.xshow(xml.all (x,"b[number(@n)>2 and number(@n)<6]"))
+--~ xml.xshow(xml.first(x,"b[find(text(),'ALSO')]"))
+
+--~ str = [[
+--~
+--~
+--~ my secret
+--~
+--~ ]]
+
+--~ x = xml.convert([[
+--~ 0102xx03OK
+--~ ]])
+--~ xml.xshow(xml.first(x,"b[tag(2) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-2) == 'x']"))
+
+--~ print(xml.filter(x,"b/tag(2)"))
+--~ print(xml.filter(x,"b/tag(1)"))
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-ent'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub, find = string.format, string.gsub, string.find
+local utfchar = unicode.utf8.char
+
+--[[ldx--
+
We provide (at least here) two entity handlers. The more extensive
+resolver consults a hash first, tries to convert to next,
+and finaly calls a handler when defines. When this all fails, the
+original entity is returned.
+--ldx]]--
+
+xml.entities = xml.entities or { } -- xml.entity_handler == function
+
+function xml.entity_handler(e)
+ return format("[%s]",e)
+end
+
+local function toutf(s)
+ return utfchar(tonumber(s,16))
+end
+
+local function utfize(root)
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ -- test prevents copying if no match
+ if find(dk,".-;") then
+ d[k] = gsub(dk,"(.-);",toutf)
+ end
+ else
+ utfize(dk)
+ end
+ end
+end
+
+xml.utfize = utfize
+
+local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
+ if find(e,"^#x") then
+ return utfchar(tonumber(e:sub(3),16))
+ elseif find(e,"^#") then
+ return utfchar(tonumber(e:sub(2)))
+ else
+ local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
+ if ee then
+ return ee
+ else
+ local h = xml.entity_handler
+ return (h and h(e)) or "&" .. e .. ";"
+ end
+ end
+end
+
+local function resolve_entities(root)
+ if not root.special or root.tg == "@rt@" then
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ if find(dk,"&.-;") then
+ d[k] = gsub(dk,"&(.-);",resolve)
+ end
+ else
+ resolve_entities(dk)
+ end
+ end
+ end
+end
+
+xml.resolve_entities = resolve_entities
+
+function xml.utfize_text(str)
+ if find(str,"") then
+ return (gsub(str,"(.-);",toutf))
+ else
+ return str
+ end
+end
+
+function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
+ if find(str,"&") then
+ return (gsub(str,"&(.-);",resolve))
+ else
+ return str
+ end
+end
+
+function xml.show_text_entities(str)
+ if find(str,"&") then
+ return (gsub(str,"&(.-);","[%1]"))
+ else
+ return str
+ end
+end
+
+-- experimental, this will be done differently
+
+function xml.merge_entities(root)
+ local documententities = root.entities
+ local allentities = xml.entities
+ if documententities then
+ for k, v in next, documententities do
+ allentities[k] = v
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['lxml-mis'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat = table.concat
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub = string.format, string.gsub
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+xml.escaped_pattern = escaped
+xml.unescaped_pattern = unescaped
+xml.cleansed_pattern = cleansed
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-tra'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- the tag is kind of generic and used for functions that are not
+-- bound to a variable, like node.new, node.copy etc (contrary to for instance
+-- node.has_attribute which is bound to a has_attribute local variable in mkiv)
+
+debugger = debugger or { }
+
+local counters = { }
+local names = { }
+local getinfo = debug.getinfo
+local format, find, lower, gmatch = string.format, string.find, string.lower, string.gmatch
+
+-- one
+
+local function hook()
+ local f = getinfo(2,"f").func
+ local n = getinfo(2,"Sn")
+-- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
+ if f then
+ local cf = counters[f]
+ if cf == nil then
+ counters[f] = 1
+ names[f] = n
+ else
+ counters[f] = cf + 1
+ end
+ end
+end
+local function getname(func)
+ local n = names[func]
+ if n then
+ if n.what == "C" then
+ return n.name or ''
+ else
+ -- source short_src linedefined what name namewhat nups func
+ local name = n.name or n.namewhat or n.what
+ if not name or name == "" then name = "?" end
+ return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
+ end
+ else
+ return "unknown"
+ end
+end
+function debugger.showstats(printer,threshold)
+ printer = printer or texio.write or print
+ threshold = threshold or 0
+ local total, grandtotal, functions = 0, 0, 0
+ printer("\n") -- ugly but ok
+ -- table.sort(counters)
+ for func, count in pairs(counters) do
+ if count > threshold then
+ local name = getname(func)
+ if not name:find("for generator") then
+ printer(format("%8i %s", count, name))
+ total = total + count
+ end
+ end
+ grandtotal = grandtotal + count
+ functions = functions + 1
+ end
+ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+end
+
+-- two
+
+--~ local function hook()
+--~ local n = getinfo(2)
+--~ if n.what=="C" and not n.name then
+--~ local f = tostring(debug.traceback())
+--~ local cf = counters[f]
+--~ if cf == nil then
+--~ counters[f] = 1
+--~ names[f] = n
+--~ else
+--~ counters[f] = cf + 1
+--~ end
+--~ end
+--~ end
+--~ function debugger.showstats(printer,threshold)
+--~ printer = printer or texio.write or print
+--~ threshold = threshold or 0
+--~ local total, grandtotal, functions = 0, 0, 0
+--~ printer("\n") -- ugly but ok
+--~ -- table.sort(counters)
+--~ for func, count in pairs(counters) do
+--~ if count > threshold then
+--~ printer(format("%8i %s", count, func))
+--~ total = total + count
+--~ end
+--~ grandtotal = grandtotal + count
+--~ functions = functions + 1
+--~ end
+--~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
+--~ end
+
+-- rest
+
+function debugger.savestats(filename,threshold)
+ local f = io.open(filename,'w')
+ if f then
+ debugger.showstats(function(str) f:write(str) end,threshold)
+ f:close()
+ end
+end
+
+function debugger.enable()
+ debug.sethook(hook,"c")
+end
+
+function debugger.disable()
+ debug.sethook()
+--~ counters[debug.getinfo(2,"f").func] = nil
+end
+
+function debugger.tracing()
+ local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
+ if n > 0 then
+ function debugger.tracing() return true end ; return true
+ else
+ function debugger.tracing() return false end ; return false
+ end
+end
+
+--~ debugger.enable()
+
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+--~ print(math.sin(1*.5))
+
+--~ debugger.disable()
+
+--~ print("")
+--~ debugger.showstats()
+--~ print("")
+--~ debugger.showstats(print,3)
+
+trackers = trackers or { }
+
+local data, done = { }, { }
+
+local function set(what,value)
+ for w in gmatch(lower(what),"[^, ]+") do
+ for d, f in next, data do
+ if done[d] then
+ -- prevent recursion due to wildcards
+ elseif find(d,w) then
+ done[d] = true
+ for i=1,#f do
+ f[i](value)
+ end
+ end
+ end
+ end
+end
+
+local function reset()
+ for d, f in next, data do
+ for i=1,#f do
+ f[i](false)
+ end
+ end
+end
+
+function trackers.register(what,...)
+ what = lower(what)
+ local w = data[what]
+ if not w then
+ w = { }
+ data[what] = w
+ end
+ for _, fnc in next, { ... } do
+ local typ = type(fnc)
+ if typ == "function" then
+ w[#w+1] = fnc
+ elseif typ == "string" then
+ w[#w+1] = function(value) set(fnc,value,nesting) end
+ end
+ end
+end
+
+function trackers.enable(what)
+ done = { }
+ set(what,true)
+end
+
+function trackers.disable(what)
+ done = { }
+ if not what or what == "" then
+ trackers.reset(what)
+ else
+ set(what,false)
+ end
+end
+
+function trackers.reset(what)
+ done = { }
+ reset()
+end
+
+function trackers.list() -- pattern
+ local list = table.sortedkeys(data)
+ local user, system = { }, { }
+ for l=1,#list do
+ local what = list[l]
+ if find(what,"^%*") then
+ system[#system+1] = what
+ else
+ user[#user+1] = what
+ end
+ end
+ return user, system
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A former version provided functionality for non embeded core
+-- scripts i.e. runtime library loading. Given the amount of
+-- Lua code we use now, this no longer makes sense. Much of this
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
+
+-- dirty tricks
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
+
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
+
+if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
+if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
+ if index > 0 then
+ local flag, value = argument:match("^%-+(.+)=(.-)$")
+ if flag then
+ arguments[flag] = string.unquote(value or "")
+ else
+ flag = argument:match("^%-+(.+)")
+ if flag then
+ arguments[flag] = true
+ else
+ files[#files+1] = argument
+ end
+ end
+ end
+ end
+ environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
+end
+
+function environment.setargument(name,value)
+ environment.arguments[name] = value
+end
+
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
+ local arguments, sortedflags = environment.arguments, environment.sortedflags
+ if arguments[name] then
+ return arguments[name]
+ elseif partial then
+ if not sortedflags then
+ sortedflags = { }
+ for _,v in pairs(table.sortedkeys(arguments)) do
+ sortedflags[#sortedflags+1] = "^" .. v
+ end
+ environment.sortedflags = sortedflags
+ end
+ -- example of potential clash: ^mode ^modefile
+ for _,v in ipairs(sortedflags) do
+ if name:find(v) then
+ return arguments[v:sub(2,#v)]
+ end
+ end
+ end
+ return nil
+end
+
+function environment.split_arguments(separator) -- rather special, cut-off before separator
+ local done, before, after = false, { }, { }
+ for _,v in ipairs(environment.original_arguments) do
+ if not done and v == separator then
+ done = true
+ elseif done then
+ after[#after+1] = v
+ else
+ before[#before+1] = v
+ end
+ end
+ return before, after
+end
+
+function environment.reconstruct_commandline(arg,noquote)
+ arg = arg or environment.original_arguments
+ if noquote and #arg == 1 then
+ local a = arg[1]
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ return a
+ elseif next(arg) then
+ local result = { }
+ for _,a in ipairs(arg) do -- ipairs 1 .. #n
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ a = a:gsub('"','\\"') -- tricky
+ if a:find(" ") then
+ result[#result+1] = a:quote()
+ else
+ result[#result+1] = a
+ end
+ end
+ return table.join(result," ")
+ else
+ return ""
+ end
+end
+
+if arg then
+
+ -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
+ local newarg, instring = { }, false
+
+ for index, argument in ipairs(arg) do
+ if argument:find("^\"") then
+ newarg[#newarg+1] = argument:gsub("^\"","")
+ if not argument:find("\"$") then
+ instring = true
+ end
+ elseif argument:find("\"$") then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
+ instring = false
+ elseif instring then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument
+ else
+ newarg[#newarg+1] = argument
+ end
+ end
+ for i=1,-5,-1 do
+ newarg[i] = arg[i]
+ end
+
+ environment.initialize_arguments(newarg)
+ environment.original_arguments = newarg
+ environment.raw_arguments = arg
+
+ arg = { } -- prevent duplicate handling
+
+end
+
+-- weird place ... depends on a not yet loaded module
+
+function environment.texfile(filename)
+ return resolvers.find_file(filename,'tex')
+end
+
+function environment.luafile(filename)
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
+end
+
+environment.loadedluacode = loadfile -- can be overloaded
+
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
+
+function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
+ filename = file.replacesuffix(filename, "lua")
+ local fullname = environment.luafile(filename)
+ if fullname and fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
+ return environment.loadedluacode(fullname)
+ else
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ return nil
+ end
+end
+
+-- the next ones can use the previous ones / combine
+
+function environment.loadluafile(filename, version)
+ local lucname, luaname, chunk
+ local basename = file.removesuffix(filename)
+ if basename == filename then
+ lucname, luaname = basename .. ".luc", basename .. ".lua"
+ else
+ lucname, luaname = nil, basename -- forced suffix
+ end
+ -- when not overloaded by explicit suffix we look for a luc file first
+ local fullname = (lucname and environment.luafile(lucname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ end
+ if chunk then
+ assert(chunk)()
+ if version then
+ -- we check of the version number of this chunk matches
+ local v = version -- can be nil
+ if modules and modules[filename] then
+ v = modules[filename].version -- new method
+ elseif versions and versions[filename] then
+ v = versions[filename] -- old method
+ end
+ if v == version then
+ return true
+ else
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
+ environment.loadluafile(filename)
+ end
+ else
+ return true
+ end
+ end
+ fullname = (luaname and environment.luafile(luaname)) or ""
+ if fullname ~= "" then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
+ chunk = loadfile(fullname) -- this way we don't need a file exists check
+ if not chunk then
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
+ else
+ assert(chunk)()
+ return true
+ end
+ end
+ return false
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['trac-inf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+local statusinfo, n, registered = { }, 0, { }
+
+statistics = statistics or { }
+
+statistics.enable = true
+statistics.threshold = 0.05
+
+-- timing functions
+
+local clock = os.gettimeofday or os.clock
+
+function statistics.hastimer(instance)
+ return instance and instance.starttime
+end
+
+function statistics.starttiming(instance)
+ if instance then
+ local it = instance.timing
+ if not it then
+ it = 0
+ end
+ if it == 0 then
+ instance.starttime = clock()
+ if not instance.loadtime then
+ instance.loadtime = 0
+ end
+ end
+ instance.timing = it + 1
+ end
+end
+
+function statistics.stoptiming(instance, report)
+ if instance then
+ local it = instance.timing
+ if it > 1 then
+ instance.timing = it - 1
+ else
+ local starttime = instance.starttime
+ if starttime then
+ local stoptime = clock()
+ local loadtime = stoptime - starttime
+ instance.stoptime = stoptime
+ instance.loadtime = instance.loadtime + loadtime
+ if report then
+ statistics.report("load time %0.3f",loadtime)
+ end
+ instance.timing = 0
+ return loadtime
+ end
+ end
+ end
+ return 0
+end
+
+function statistics.elapsedtime(instance)
+ return format("%0.3f",(instance and instance.loadtime) or 0)
+end
+
+function statistics.elapsedindeed(instance)
+ local t = (instance and instance.loadtime) or 0
+ return t > statistics.threshold
+end
+
+-- general function
+
+function statistics.register(tag,fnc)
+ if statistics.enable and type(fnc) == "function" then
+ local rt = registered[tag] or (#statusinfo + 1)
+ statusinfo[rt] = { tag, fnc }
+ registered[tag] = rt
+ if #tag > n then n = #tag end
+ end
+end
+
+function statistics.show(reporter)
+ if statistics.enable then
+ if not reporter then reporter = function(tag,data,n) texio.write_nl(tag .. " " .. data) end end
+ -- this code will move
+ local register = statistics.register
+ register("luatex banner", function()
+ return string.lower(status.banner)
+ end)
+ register("control sequences", function()
+ return format("%s of %s", status.cs_count, status.hash_size+status.hash_extra)
+ end)
+ register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end)
+ register("current memory usage", statistics.memused)
+ register("runtime",statistics.runtime)
+-- --
+ for i=1,#statusinfo do
+ local s = statusinfo[i]
+ local r = s[2]()
+ if r then
+ reporter(s[1],r,n)
+ end
+ end
+ statistics.enable = false
+ end
+end
+
+function statistics.show_job_stat(tag,data,n)
+ texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data))
+end
+
+function statistics.memused() -- no math.round yet -)
+ local round = math.round or math.floor
+ return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
+end
+
+if statistics.runtime then
+ -- already loaded and set
+elseif luatex and luatex.starttime then
+ statistics.starttime = luatex.starttime
+ statistics.loadtime = 0
+ statistics.timing = 0
+else
+ statistics.starttiming(statistics)
+end
+
+function statistics.runtime()
+ statistics.stoptiming(statistics)
+ return statistics.formatruntime(statistics.elapsedtime(statistics))
+end
+
+function statistics.formatruntime(runtime)
+ return format("%s seconds", statistics.elapsedtime(statistics))
+end
+
+function statistics.timed(action,report)
+ local timer = { }
+ report = report or logs.simple
+ statistics.starttiming(timer)
+ action()
+ statistics.stoptiming(timer)
+ report("total runtime: %s",statistics.elapsedtime(timer))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-log'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is old code that needs an overhaul
+
+local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
+
+if texlua then
+ write_nl = print
+ write = io.write
+end
+
+--[[ldx--
+
This is a prelude to a more extensive logging module. For the sake
+of parsing log files, in addition to the standard logging we will
+provide an structured file. Actually, any logging that
+is hooked into callbacks will be \XML\ by default.
+--ldx]]--
+
+logs = logs or { }
+logs.xml = logs.xml or { }
+logs.tex = logs.tex or { }
+
+--[[ldx--
+
This looks pretty ugly but we need to speed things up a bit.
+--ldx]]--
+
+logs.moreinfo = [[
+more information about ConTeXt and the tools that come with it can be found at:
+
+maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
+webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
+wiki : http://contextgarden.net
+]]
+
+logs.levels = {
+ ['error'] = 1,
+ ['warning'] = 2,
+ ['info'] = 3,
+ ['debug'] = 4,
+}
+
+logs.functions = {
+ 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct',
+ 'start_run', 'stop_run',
+ 'start_page_number', 'stop_page_number',
+ 'report_output_pages', 'report_output_log',
+ 'report_tex_stat', 'report_job_stat',
+ 'show_open', 'show_close', 'show_load',
+}
+
+logs.tracers = {
+}
+
+logs.level = 0
+logs.mode = string.lower((os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"))
+
+function logs.set_level(level)
+ logs.level = logs.levels[level] or level
+end
+
+function logs.set_method(method)
+ for _, v in next, logs.functions do
+ logs[v] = logs[method][v] or function() end
+ end
+end
+
+-- tex logging
+
+function logs.tex.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(category .. " | " .. format(fmt,...))
+ else
+ write_nl(category .. " |")
+ end
+end
+
+function logs.tex.line(fmt,...) -- new
+ if fmt then
+ write_nl(format(fmt,...))
+ else
+ write_nl("")
+ end
+end
+
+local texcount = tex and tex.count
+
+function logs.tex.start_page_number()
+ local real, user, sub = texcount[0], texcount[1], texcount[2]
+ if real > 0 then
+ if user > 0 then
+ if sub > 0 then
+ write(format("[%s.%s.%s",real,user,sub))
+ else
+ write(format("[%s.%s",real,user))
+ end
+ else
+ write(format("[%s",real))
+ end
+ else
+ write("[-")
+ end
+end
+
+function logs.tex.stop_page_number()
+ write("]")
+end
+
+logs.tex.report_job_stat = statistics.show_job_stat
+
+-- xml logging
+
+function logs.xml.report(category,fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",category,format(fmt,...)))
+ else
+ write_nl(format("",category))
+ end
+end
+function logs.xml.line(fmt,...) -- new
+ if fmt then
+ write_nl(format("%s",format(fmt,...)))
+ else
+ write_nl("")
+ end
+end
+
+function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
+function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
+function logs.xml.push () if logs.level > 0 then tw("" ) end end
+
+function logs.xml.start_run()
+ write_nl("")
+ write_nl("") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng'
+ write_nl("")
+end
+
+function logs.xml.stop_run()
+ write_nl("")
+end
+
+function logs.xml.start_page_number()
+ write_nl(format("")
+ write_nl("")
+end
+
+function logs.xml.report_output_pages(p,b)
+ write_nl(format("", p))
+ write_nl(format("", b))
+ write_nl("")
+end
+
+function logs.xml.report_output_log()
+end
+
+function logs.xml.report_tex_stat(k,v)
+ texiowrite_nl("log",""..tostring(v).."")
+end
+
+local level = 0
+
+function logs.xml.show_open(name)
+ level = level + 1
+ texiowrite_nl(format("",level,name))
+end
+
+function logs.xml.show_close(name)
+ texiowrite(" ")
+ level = level - 1
+end
+
+function logs.xml.show_load(name)
+ texiowrite_nl(format("",level+1,name))
+end
+
+--
+
+local name, banner = 'report', 'context'
+
+local function report(category,fmt,...)
+ if fmt then
+ write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
+ elseif category then
+ write_nl(format("%s | %s",name,category))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+local function simple(fmt,...)
+ if fmt then
+ write_nl(format("%s | %s",name,format(fmt,...)))
+ else
+ write_nl(format("%s |",name))
+ end
+end
+
+function logs.setprogram(_name_,_banner_,_verbose_)
+ name, banner = _name_, _banner_
+ if _verbose_ then
+ trackers.enable("resolvers.verbose")
+ end
+ logs.set_method("tex")
+ logs.report = report -- also used in libraries
+ logs.simple = simple -- only used in scripts !
+ if utils then
+ utils.report = simple
+ end
+ logs.verbose = _verbose_
+end
+
+function logs.setverbose(what)
+ if what then
+ trackers.enable("resolvers.verbose")
+ else
+ trackers.disable("resolvers.verbose")
+ end
+ logs.verbose = what or false
+end
+
+function logs.extendbanner(_banner_,_verbose_)
+ banner = banner .. " | ".. _banner_
+ if _verbose_ ~= nil then
+ logs.setverbose(what)
+ end
+end
+
+logs.verbose = false
+logs.report = logs.tex.report
+logs.simple = logs.tex.report
+
+function logs.reportlines(str) -- todo:
+ for line in str:gmatch("(.-)[\n\r]") do
+ logs.report(line)
+ end
+end
+
+function logs.reportline() -- for scripts too
+ logs.report()
+end
+
+logs.simpleline = logs.reportline
+
+function logs.help(message,option)
+ logs.report(banner)
+ logs.reportline()
+ logs.reportlines(message)
+ local moreinfo = logs.moreinfo or ""
+ if moreinfo ~= "" and option ~= "nomoreinfo" then
+ logs.reportline()
+ logs.reportlines(moreinfo)
+ end
+end
+
+logs.set_level('error')
+logs.set_method('tex')
+
+function logs.system(whereto,process,jobname,category,...)
+ for i=1,10 do
+ local f = io.open(whereto,"a")
+ if f then
+ f:write(format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)))
+ f:close()
+ break
+ else
+ sleep(0.1)
+ end
+ end
+end
+
+--~ local syslogname = "oeps.xxx"
+--~
+--~ for i=1,10 do
+--~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123")
+--~ end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
+end
+
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
+ end
+
+ return newinstance
+
+end
+
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
+ end
+ end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
+ end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
+ end
+end
+
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
+ end
+ ie[key] = value
+ end
+ return value or ""
+end
+
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
+
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
+end
+
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
+
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
+ end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
+end
+
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
+
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
+ end
+ end
+ return t
+end
+
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
+ end
+ else
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
+ end
+ return newlist
+end
+
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
+ end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
+ end
+ return resolvers.ownpath
+end
+
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
+
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
+ end
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
+ end
+end
+
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+-- database loading
+
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
+
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
+ end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
+
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
+ end
+end
+
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
+ end
+end
+
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
+
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
+ end
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
+ end
+ end
+ end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
+ end
+ end
+ end
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
+ end
+end
+
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ end
+ end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
+ end
+ end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
+ end
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
+ end
+ end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
+ end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
+ end
+end
+
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
+end
+
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
+ else
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
+ end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
+ end
+end
+
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
+
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
+
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
+end
+
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
+end
+
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
+end
+
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
+
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
+ end
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ else
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
+ end
+
+end
+
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
+ end
+ end
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ return new
+ end
+end
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
+end
+
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
+end
+
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
+ end
+end
+
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
+ else
+ return resolvers.expanded_path_list(tmp)
+ end
+end
+
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
+
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
+end
+
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
+ end
+ return ''
+end
+
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
+
+resolvers.isreadable = { }
+
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
+ end
+ return readable
+end
+
+resolvers.isreadable.tex = resolvers.isreadable.file
+
+-- name
+-- name/name
+
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
+end
+
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
+end
+
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
+end
+
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
+
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
+end
+
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
+ else
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
+ end
+ end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
+end
+
+if not resolvers.concatinators then resolvers.concatinators = { } end
+
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
+
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
+ end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
+ end
+ instance.format = ''
+ return result
+end
+
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
+
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
+ end
+ end
+ end
+ return result
+end
+
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
+end
+
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
+
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
+
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
+
+-- main user functions
+
+function resolvers.automount()
+ -- implemented later
+end
+
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
+end
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
+end
+
+-- strtab
+
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
+end
+
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
+end
+
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
+ end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
+ end
+ return concat(s, sep or " | ")
+end
+
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
+end
+
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
+end
+
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
+end
+
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
+
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
+end
+
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
+ end
+end
+
+texconfig.kpse_init = false
+
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
+
+-- for a while
+
+input = resolvers
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
+--ldx]]--
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+
+caches = caches or { }
+
+caches.path = caches.path or nil
+caches.base = caches.base or "luatex-cache"
+caches.more = caches.more or "context"
+caches.direct = false -- true is faster but may need huge amounts of memory
+caches.tree = false
+caches.paths = caches.paths or nil
+caches.force = false
+caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
+
+function caches.temp()
+ local cachepath = nil
+ local function check(list,isenv)
+ if not cachepath then
+ for k=1,#list do
+ local v = list[k]
+ cachepath = (isenv and (os.env[v] or "")) or v or ""
+ if cachepath == "" then
+ -- next
+ else
+ cachepath = resolvers.clean_path(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
+ break
+ elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
+ dir.mkdirs(cachepath)
+ if lfs.isdir(cachepath) and file.iswritable(cachepath) then
+ break
+ end
+ end
+ end
+ cachepath = nil
+ end
+ end
+ end
+ check(resolvers.clean_path_list("TEXMFCACHE") or { })
+ check(caches.defaults,true)
+ if not cachepath then
+ print("\nfatal error: there is no valid (writable) cache path defined\n")
+ os.exit()
+ elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
+ print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
+ os.exit()
+ end
+ cachepath = file.collapse_path(cachepath)
+ function caches.temp()
+ return cachepath
+ end
+ return cachepath
+end
+
+function caches.configpath()
+ return table.concat(resolvers.instance.cnffiles,";")
+end
+
+function caches.hashed(tree)
+ return md5.hex(gsub(lower(tree),"[\\\/]+","/"))
+end
+
+function caches.treehash()
+ local tree = caches.configpath()
+ if not tree or tree == "" then
+ return false
+ else
+ return caches.hashed(tree)
+ end
+end
+
+function caches.setpath(...)
+ if not caches.path then
+ if not caches.path then
+ caches.path = caches.temp()
+ end
+ caches.path = resolvers.clean_path(caches.path) -- to be sure
+ caches.tree = caches.tree or caches.treehash()
+ if caches.tree then
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
+ else
+ caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
+ end
+ end
+ if not caches.path then
+ caches.path = '.'
+ end
+ caches.path = resolvers.clean_path(caches.path)
+ if not table.is_empty({...}) then
+ local pth = dir.mkdirs(caches.path,...)
+ return pth
+ end
+ caches.path = dir.expand_name(caches.path)
+ return caches.path
+end
+
+function caches.definepath(category,subcategory)
+ return function()
+ return caches.setpath(category,subcategory)
+ end
+end
+
+function caches.setluanames(path,name)
+ return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+end
+
+function caches.loaddata(path,name)
+ local tmaname, tmcname = caches.setluanames(path,name)
+ local loader = loadfile(tmcname) or loadfile(tmaname)
+ if loader then
+ return loader()
+ else
+ return false
+ end
+end
+
+--~ function caches.loaddata(path,name)
+--~ local tmaname, tmcname = caches.setluanames(path,name)
+--~ return dofile(tmcname) or dofile(tmaname)
+--~ end
+
+function caches.iswritable(filepath,filename)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ return file.iswritable(tmaname)
+end
+
+function caches.savedata(filepath,filename,data,raw)
+ local tmaname, tmcname = caches.setluanames(filepath,filename)
+ local reduce, simplify = true, true
+ if raw then
+ reduce, simplify = false, false
+ end
+ if caches.direct then
+ file.savedata(tmaname, table.serialize(data,'return',false,true,false)) -- no hex
+ else
+ table.tofile(tmaname, data,'return',false,true,false) -- maybe not the last true
+ end
+ local cleanup = resolvers.boolean_variable("PURGECACHE", false)
+ local strip = resolvers.boolean_variable("LUACSTRIP", true)
+ utils.lua.compile(tmaname, tmcname, cleanup, strip)
+end
+
+-- here we use the cache for format loading (texconfig.[formatname|jobname])
+
+--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
+if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and resolvers.instance then
+ if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
+ texconfig.formatname = caches.setpath("formats") .. "/" .. gsub(texconfig.luaname,"%.lu.$",".fmt")
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-res'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--~ print(resolvers.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
+
+local upper, lower, gsub = string.upper, string.lower, string.gsub
+
+local prefixes = { }
+
+prefixes.environment = function(str)
+ return resolvers.clean_path(os.getenv(str) or os.getenv(upper(str)) or os.getenv(lower(str)) or "")
+end
+
+prefixes.relative = function(str,n)
+ if io.exists(str) then
+ -- nothing
+ elseif io.exists("./" .. str) then
+ str = "./" .. str
+ else
+ local p = "../"
+ for i=1,n or 2 do
+ if io.exists(p .. str) then
+ str = p .. str
+ break
+ else
+ p = p .. "../"
+ end
+ end
+ end
+ return resolvers.clean_path(str)
+end
+
+prefixes.locate = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path((fullname ~= "" and fullname) or str)
+end
+
+prefixes.filename = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.basename((fullname ~= "" and fullname) or str))
+end
+
+prefixes.pathname = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.dirname((fullname ~= "" and fullname) or str))
+end
+
+prefixes.env = prefixes.environment
+prefixes.rel = prefixes.relative
+prefixes.loc = prefixes.locate
+prefixes.kpse = prefixes.locate
+prefixes.full = prefixes.locate
+prefixes.file = prefixes.filename
+prefixes.path = prefixes.pathname
+
+local function _resolve_(method,target)
+ if prefixes[method] then
+ return prefixes[method](target)
+ else
+ return method .. ":" .. target
+ end
+end
+
+local function resolve(str)
+ if type(str) == "table" then
+ for k, v in pairs(str) do -- ipairs
+ str[k] = resolve(v) or v
+ end
+ elseif str and str ~= "" then
+ str = gsub(str,"([a-z]+):([^ \"\']*)",_resolve_)
+ end
+ return str
+end
+
+resolvers.resolve = resolve
+
+if os.uname then
+
+ for k, v in pairs(os.uname()) do
+ if not prefixes[k] then
+ prefixes[k] = function() return v end
+ end
+ end
+
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
+
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
+
+
Examples of usage can be found in the font related code.
+--ldx]]--
+
+containers = containers or { }
+
+containers.usecache = true
+
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
+
+local allocated = { }
+
+-- tracing
+
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
+
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
+ end
+ end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
+
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
+ end
+ report(container,"stored",name)
+ container.storage[name] = data
+ end
+ return data
+end
+
+function containers.content(container,name)
+ return container.storage[name]
+end
+
+function containers.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-use'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+-- since we want to use the cache instead of the tree, we will now
+-- reimplement the saver.
+
+local save_data = resolvers.save_data
+local load_data = resolvers.load_data
+
+resolvers.cachepath = nil -- public, for tracing
+resolvers.usecache = true -- public, for tracing
+
+function resolvers.save_data(dataname)
+ save_data(dataname, function(cachename,dataname)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(cachename))
+ else
+ return file.join(cachename,dataname)
+ end
+ end)
+end
+
+function resolvers.load_data(pathname,dataname,filename)
+ load_data(pathname,dataname,filename,function(dataname,filename)
+ resolvers.usecache = not toboolean(resolvers.expansion("CACHEINTDS") or "false",true)
+ if resolvers.usecache then
+ resolvers.cachepath = resolvers.cachepath or caches.definepath("trees")
+ return file.join(resolvers.cachepath(),caches.hashed(pathname))
+ else
+ if not filename or (filename == "") then
+ filename = dataname
+ end
+ return file.join(pathname,filename)
+ end
+ end)
+end
+
+-- we will make a better format, maybe something xml or just text or lua
+
+resolvers.automounted = resolvers.automounted or { }
+
+function resolvers.automount(usecache)
+ local mountpaths = resolvers.clean_path_list(resolvers.expansion('TEXMFMOUNT'))
+ if table.is_empty(mountpaths) and usecache then
+ mountpaths = { caches.setpath("mount") }
+ end
+ if not table.is_empty(mountpaths) then
+ statistics.starttiming(resolvers.instance)
+ for k, root in pairs(mountpaths) do
+ local f = io.open(root.."/url.tmi")
+ if f then
+ for line in f:lines() do
+ if line then
+ if line:find("^[%%#%-]") then -- or %W
+ -- skip
+ elseif line:find("^zip://") then
+ if trace_locating then
+ logs.report("fileio","mounting %s",line)
+ end
+ table.insert(resolvers.automounted,line)
+ resolvers.usezipfile(line)
+ end
+ end
+ end
+ f:close()
+ end
+ end
+ statistics.stoptiming(resolvers.instance)
+ end
+end
+
+-- status info
+
+statistics.register("used config path", function() return caches.configpath() end)
+statistics.register("used cache path", function() return caches.temp() or "?" end)
+
+-- experiment (code will move)
+
+function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname
+ local enginebanner = status.list().banner
+ if formatbanner and enginebanner and sourcefile then
+ local luvname = file.replacesuffix(texname,"luv")
+ local luvdata = {
+ enginebanner = enginebanner,
+ formatbanner = formatbanner,
+ sourcehash = md5.hex(io.loaddata(resolvers.find_file(sourcefile)) or "unknown"),
+ sourcefile = sourcefile,
+ }
+ io.savedata(luvname,table.serialize(luvdata,true))
+ end
+end
+
+function statistics.check_fmt_status(texname)
+ local enginebanner = status.list().banner
+ if enginebanner and texname then
+ local luvname = file.replacesuffix(texname,"luv")
+ if lfs.isfile(luvname) then
+ local luv = dofile(luvname)
+ if luv and luv.sourcefile then
+ local sourcehash = md5.hex(io.loaddata(resolvers.find_file(luv.sourcefile)) or "unknown")
+ if luv.enginebanner and luv.enginebanner ~= enginebanner then
+ return "engine mismatch"
+ end
+ if luv.sourcehash and luv.sourcehash ~= sourcehash then
+ return "source mismatch"
+ end
+ else
+ return "invalid status file"
+ end
+ else
+ return "missing status file"
+ end
+ end
+ return true
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-zip'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, find = string.format, string.find
+
+local trace_locating, trace_verbose = false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trace_verbose = v end)
+
+zip = zip or { }
+zip.archives = zip.archives or { }
+zip.registeredfiles = zip.registeredfiles or { }
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+local locators, hashers, concatinators = resolvers.locators, resolvers.hashers, resolvers.concatinators
+
+local archives = zip.archives
+
+-- zip:///oeps.zip?name=bla/bla.tex
+-- zip:///oeps.zip?tree=tex/texmf-local
+
+local function validzip(str) -- todo: use url splitter
+ if not find(str,"^zip://") then
+ return "zip:///" .. str
+ else
+ return str
+ end
+end
+
+function zip.openarchive(name)
+ if not name or name == "" then
+ return nil
+ else
+ local arch = archives[name]
+ if not arch then
+ local full = resolvers.find_file(name) or ""
+ arch = (full ~= "" and zip.open(full)) or false
+ archives[name] = arch
+ end
+ return arch
+ end
+end
+
+function zip.closearchive(name)
+ if not name or (name == "" and archives[name]) then
+ zip.close(archives[name])
+ archives[name] = nil
+ end
+end
+
+-- zip:///texmf.zip?tree=/tex/texmf
+-- zip:///texmf.zip?tree=/tex/texmf-local
+-- zip:///texmf-mine.zip?tree=/tex/texmf-projects
+
+function locators.zip(specification) -- where is this used? startup zips (untested)
+ specification = resolvers.splitmethod(specification)
+ local zipfile = specification.path
+ local zfile = zip.openarchive(name) -- tricky, could be in to be initialized tree
+ if trace_locating then
+ if zfile then
+ logs.report("fileio",'! zip locator, found: %s',specification.original)
+ else
+ logs.report("fileio",'? zip locator, not found: %s',specification.original)
+ end
+ end
+end
+
+function hashers.zip(tag,name)
+ if trace_verbose then
+ logs.report("fileio","loading zip file %s as %s",name,tag)
+ end
+ resolvers.usezipfile(format("%s?tree=%s",tag,name))
+end
+
+function concatinators.zip(tag,path,name)
+ if not path or path == "" then
+ return format('%s?name=%s',tag,name)
+ else
+ return format('%s?name=%s/%s',tag,path,name)
+ end
+end
+
+function resolvers.isreadable.zip(name)
+ return true
+end
+
+function finders.zip(specification,filetype)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'! zip finder, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ dfile = zfile:close()
+ if trace_locating then
+ logs.report("fileio",'+ zip finder, name: %s',q.name)
+ end
+ return specification.original
+ end
+ elseif trace_locating then
+ logs.report("fileio",'? zip finder, path %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip finder, name: %s',filename)
+ end
+ return unpack(finders.notfound)
+end
+
+function openers.zip(specification)
+ local zipspecification = resolvers.splitmethod(specification)
+ if zipspecification.path then
+ local q = url.query(zipspecification.query)
+ if q.name then
+ local zfile = zip.openarchive(zipspecification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',zipspecification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_open(specification)
+ return openers.text_opener(specification,dfile,'zip')
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path %s',zipspecification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip opener, name: %s',filename)
+ end
+ return unpack(openers.notfound)
+end
+
+function loaders.zip(specification)
+ specification = resolvers.splitmethod(specification)
+ if specification.path then
+ local q = url.query(specification.query)
+ if q.name then
+ local zfile = zip.openarchive(specification.path)
+ if zfile then
+ if trace_locating then
+ logs.report("fileio",'+ zip starter, path: %s',specification.path)
+ end
+ local dfile = zfile:open(q.name)
+ if dfile then
+ logs.show_load(filename)
+ if trace_locating then
+ logs.report("fileio",'+ zip loader, name: %s',filename)
+ end
+ local s = dfile:read("*all")
+ dfile:close()
+ return true, s, #s
+ end
+ elseif trace_locating then
+ logs.report("fileio",'- zip starter, path: %s',specification.path)
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- zip loader, name: %s',filename)
+ end
+ return unpack(openers.notfound)
+end
+
+-- zip:///somefile.zip
+-- zip:///somefile.zip?tree=texmf-local -> mount
+
+function resolvers.usezipfile(zipname)
+ zipname = validzip(zipname)
+ if trace_locating then
+ logs.report("fileio",'! zip use, file: %s',zipname)
+ end
+ local specification = resolvers.splitmethod(zipname)
+ local zipfile = specification.path
+ if zipfile and not zip.registeredfiles[zipname] then
+ local tree = url.query(specification.query).tree or ""
+ if trace_locating then
+ logs.report("fileio",'! zip register, file: %s',zipname)
+ end
+ local z = zip.openarchive(zipfile)
+ if z then
+ local instance = resolvers.instance
+ if trace_locating then
+ logs.report("fileio","= zipfile, registering: %s",zipname)
+ end
+ statistics.starttiming(instance)
+ resolvers.prepend_hash('zip',zipname,zipfile)
+ resolvers.extend_texmf_var(zipname) -- resets hashes too
+ zip.registeredfiles[zipname] = z
+ instance.files[zipname] = resolvers.register_zip_file(z,tree or "")
+ statistics.stoptiming(instance)
+ elseif trace_locating then
+ logs.report("fileio","? zipfile, unknown: %s",zipname)
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! zip register, no file: %s',zipname)
+ end
+end
+
+function resolvers.register_zip_file(z,tree)
+ local files, filter = { }, ""
+ if tree == "" then
+ filter = "^(.+)/(.-)$"
+ else
+ filter = format("^%s/(.+)/(.-)$",tree)
+ end
+ if trace_locating then
+ logs.report("fileio",'= zip filter: %s',filter)
+ end
+ local register, n = resolvers.register_file, 0
+ for i in z:files() do
+ local path, name = i.filename:match(filter)
+ if path then
+ if name and name ~= '' then
+ register(files, name, path)
+ n = n + 1
+ else
+ -- directory
+ end
+ else
+ register(files, i.filename, '')
+ n = n + 1
+ end
+ end
+ logs.report("fileio",'= zip entries: %s',n)
+ return files
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-crl'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+curl = curl or { }
+
+curl.cached = { }
+curl.cachepath = caches.definepath("curl")
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+
+function curl.fetch(protocol, name)
+ local cachename = curl.cachepath() .. "/" .. name:gsub("[^%a%d%.]+","-")
+-- cachename = cachename:gsub("[\\/]", io.fileseparator)
+ cachename = cachename:gsub("[\\]", "/") -- cleanup
+ if not curl.cached[name] then
+ if not io.exists(cachename) then
+ curl.cached[name] = cachename
+ local command = "curl --silent --create-dirs --output " .. cachename .. " " .. name -- no protocol .. "://"
+ os.spawn(command)
+ end
+ if io.exists(cachename) then
+ curl.cached[name] = cachename
+ else
+ curl.cached[name] = ""
+ end
+ end
+ return curl.cached[name]
+end
+
+function finders.curl(protocol,filename)
+ local foundname = curl.fetch(protocol, filename)
+ return finders.generic(protocol,foundname,filetype)
+end
+
+function openers.curl(protocol,filename)
+ return openers.generic(protocol,filename)
+end
+
+function loaders.curl(protocol,filename)
+ return loaders.generic(protocol,filename)
+end
+
+-- todo: metamethod
+
+function curl.install(protocol)
+ finders[protocol] = function (filename,filetype) return finders.curl(protocol,filename) end
+ openers[protocol] = function (filename) return openers.curl(protocol,filename) end
+ loaders[protocol] = function (filename) return loaders.curl(protocol,filename) end
+end
+
+curl.install('http')
+curl.install('https')
+curl.install('ftp')
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['data-tmf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- loads *.tmf files in minimal tree roots (to be optimized and documented)
+
+function resolvers.check_environment(tree)
+ logs.simpleline()
+ os.setenv('TMP', os.getenv('TMP') or os.getenv('TEMP') or os.getenv('TMPDIR') or os.getenv('HOME'))
+ os.setenv('TEXOS', os.getenv('TEXOS') or ("texmf-" .. os.currentplatform()))
+ os.setenv('TEXPATH', (tree or "tex"):gsub("\/+$",''))
+ os.setenv('TEXMFOS', os.getenv('TEXPATH') .. "/" .. os.getenv('TEXOS'))
+ logs.simpleline()
+ logs.simple("preset : TEXPATH => %s", os.getenv('TEXPATH'))
+ logs.simple("preset : TEXOS => %s", os.getenv('TEXOS'))
+ logs.simple("preset : TEXMFOS => %s", os.getenv('TEXMFOS'))
+ logs.simple("preset : TMP => %s", os.getenv('TMP'))
+ logs.simple('')
+end
+
+function resolvers.load_environment(name) -- todo: key=value as well as lua
+ local f = io.open(name)
+ if f then
+ for line in f:lines() do
+ if line:find("^[%%%#]") then
+ -- skip comment
+ else
+ local key, how, value = line:match("^(.-)%s*([<=>%?]+)%s*(.*)%s*$")
+ if how then
+ value = value:gsub("%%(.-)%%", function(v) return os.getenv(v) or "" end)
+ if how == "=" or how == "<<" then
+ os.setenv(key,value)
+ elseif how == "?" or how == "??" then
+ os.setenv(key,os.getenv(key) or value)
+ elseif how == "<" or how == "+=" then
+ if os.getenv(key) then
+ os.setenv(key,os.getenv(key) .. io.fileseparator .. value)
+ else
+ os.setenv(key,value)
+ end
+ elseif how == ">" or how == "=+" then
+ if os.getenv(key) then
+ os.setenv(key,value .. io.pathseparator .. os.getenv(key))
+ else
+ os.setenv(key,value)
+ end
+ end
+ end
+ end
+ end
+ f:close()
+ end
+end
+
+function resolvers.load_tree(tree)
+ if tree and tree ~= "" then
+ local setuptex = 'setuptex.tmf'
+ if lfs.attributes(tree, "mode") == "directory" then -- check if not nil
+ setuptex = tree .. "/" .. setuptex
+ else
+ setuptex = tree
+ end
+ if io.exists(setuptex) then
+ resolvers.check_environment(tree)
+ resolvers.load_environment(setuptex)
+ end
+ end
+end
+
+
+end -- of closure
+
+do -- create closure to overcome 200 locals limit
+
+if not modules then modules = { } end modules ['luat-sta'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this code is used in the updater
+
+states = states or { }
+states.data = states.data or { }
+states.hash = states.hash or { }
+states.tag = states.tag or ""
+states.filename = states.filename or ""
+
+function states.save(filename,tag)
+ tag = tag or states.tag
+ filename = file.addsuffix(filename or states.filename,'lus')
+ io.savedata(filename,
+ "-- generator : luat-sta.lua\n" ..
+ "-- state tag : " .. tag .. "\n\n" ..
+ table.serialize(states.data[tag or states.tag] or {},true)
+ )
+end
+
+function states.load(filename,tag)
+ states.filename = filename
+ states.tag = tag or "whatever"
+ states.filename = file.addsuffix(states.filename,'lus')
+ states.data[states.tag], states.hash[states.tag] = (io.exists(filename) and dofile(filename)) or { }, { }
+end
+
+function states.set_by_tag(tag,key,value,default,persistent)
+ local d, h = states.data[tag], states.hash[tag]
+ if d then
+ if type(d) == "table" then
+ local dkey, hkey = key, key
+ local pre, post = key:match("(.+)%.([^%.]+)$")
+ if pre and post then
+ for k in pre:gmatch("[^%.]+") do
+ local dk = d[k]
+ if not dk then
+ dk = { }
+ d[k] = dk
+ end
+ d = dk
+ end
+ dkey, hkey = post, key
+ end
+ if type(value) == nil then
+ value = value or default
+ elseif persistent then
+ value = value or d[dkey] or default
+ else
+ value = value or default
+ end
+ d[dkey], h[hkey] = value, value
+ elseif type(d) == "string" then
+ -- weird
+ states.data[tag], states.hash[tag] = value, value
+ end
+ end
+end
+
+function states.get_by_tag(tag,key,default)
+ local h = states.hash[tag]
+ if h and h[key] then
+ return h[key]
+ else
+ local d = states.data[tag]
+ if d then
+ for k in key:gmatch("[^%.]+") do
+ local dk = d[k]
+ if dk then
+ d = dk
+ else
+ return default
+ end
+ end
+ return d or default
+ end
+ end
+end
+
+function states.set(key,value,default,persistent)
+ states.set_by_tag(states.tag,key,value,default,persistent)
+end
+
+function states.get(key,default)
+ return states.get_by_tag(states.tag,key,default)
+end
+
+--~ states.data.update = {
+--~ ["version"] = {
+--~ ["major"] = 0,
+--~ ["minor"] = 1,
+--~ },
+--~ ["rsync"] = {
+--~ ["server"] = "contextgarden.net",
+--~ ["module"] = "minimals",
+--~ ["repository"] = "current",
+--~ ["flags"] = "-rpztlv --stats",
+--~ },
+--~ ["tasks"] = {
+--~ ["update"] = true,
+--~ ["make"] = true,
+--~ ["delete"] = false,
+--~ },
+--~ ["platform"] = {
+--~ ["host"] = true,
+--~ ["other"] = {
+--~ ["mswin"] = false,
+--~ ["linux"] = false,
+--~ ["linux-64"] = false,
+--~ ["osx-intel"] = false,
+--~ ["osx-ppc"] = false,
+--~ ["sun"] = false,
+--~ },
+--~ },
+--~ ["context"] = {
+--~ ["available"] = {"current", "beta", "alpha", "experimental"},
+--~ ["selected"] = "current",
+--~ },
+--~ ["formats"] = {
+--~ ["cont-en"] = true,
+--~ ["cont-nl"] = true,
+--~ ["cont-de"] = false,
+--~ ["cont-cz"] = false,
+--~ ["cont-fr"] = false,
+--~ ["cont-ro"] = false,
+--~ },
+--~ ["engine"] = {
+--~ ["pdftex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["pdftex"] = true,
+--~ },
+--~ },
+--~ ["luatex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ },
+--~ },
+--~ ["xetex"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["xetex"] = false,
+--~ },
+--~ },
+--~ ["metapost"] = {
+--~ ["install"] = true,
+--~ ["formats"] = {
+--~ ["mpost"] = true,
+--~ ["metafun"] = true,
+--~ },
+--~ },
+--~ },
+--~ ["fonts"] = {
+--~ },
+--~ ["doc"] = {
+--~ },
+--~ ["modules"] = {
+--~ ["f-urwgaramond"] = false,
+--~ ["f-urwgothic"] = false,
+--~ ["t-bnf"] = false,
+--~ ["t-chromato"] = false,
+--~ ["t-cmscbf"] = false,
+--~ ["t-cmttbf"] = false,
+--~ ["t-construction-plan"] = false,
+--~ ["t-degrade"] = false,
+--~ ["t-french"] = false,
+--~ ["t-lettrine"] = false,
+--~ ["t-lilypond"] = false,
+--~ ["t-mathsets"] = false,
+--~ ["t-tikz"] = false,
+--~ ["t-typearea"] = false,
+--~ ["t-vim"] = false,
+--~ },
+--~ }
+
+--~ states.save("teststate", "update")
+--~ states.load("teststate", "update")
+
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+--~ states.set_by_tag("update","rsync.server","oeps")
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+--~ states.save("teststate", "update")
+--~ states.load("teststate", "update")
+--~ print(states.get_by_tag("update","rsync.server","unknown"))
+
+
+end -- of closure
+-- end library merge
+
+own = { } -- not local
+
+own.libs = { -- todo: check which ones are really needed
+ 'l-string.lua',
+ 'l-lpeg.lua',
+ 'l-table.lua',
+ 'l-io.lua',
+ 'l-number.lua',
+ 'l-set.lua',
+ 'l-os.lua',
+ 'l-file.lua',
+ 'l-md5.lua',
+ 'l-dir.lua',
+ 'l-boolean.lua',
+ 'l-math.lua',
+-- 'l-unicode.lua',
+-- 'l-tex.lua',
+ 'l-utils.lua',
+-- 'l-xml.lua',
+ 'lxml-tab.lua',
+ 'lxml-pth.lua',
+ 'lxml-ent.lua',
+ 'lxml-mis.lua',
+ 'trac-tra.lua',
+ 'luat-env.lua',
+ 'trac-inf.lua',
+ 'trac-log.lua',
+ 'data-res.lua',
+ 'data-tmp.lua',
+ 'data-pre.lua',
+ 'data-inp.lua',
+ 'data-out.lua',
+ 'data-con.lua',
+ 'data-use.lua',
+-- 'data-tex.lua',
+-- 'data-bin.lua',
+ 'data-zip.lua',
+ 'data-crl.lua',
+-- 'data-lua.lua',
+ 'data-kps.lua', -- so that we can replace kpsewhich
+ 'data-aux.lua', -- updater
+ 'data-tmf.lua', -- tree files
+ -- needed ?
+ 'luat-sta.lua', -- states
+}
+
+-- We need this hack till luatex is fixed.
+--
+-- for k,v in pairs(arg) do print(k,v) end
+
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+-- End of hack.
+
+own.name = (environment and environment.ownname) or arg[0] or 'luatools.lua'
+
+own.path = string.match(own.name,"^(.+)[\\/].-$") or "."
+own.list = { '.' }
+if own.path ~= '.' then
+ table.insert(own.list,own.path)
+end
+table.insert(own.list,own.path.."/../../../tex/context/base")
+table.insert(own.list,own.path.."/mtx")
+table.insert(own.list,own.path.."/../sources")
+
+local function locate_libs()
+ for _, lib in pairs(own.libs) do
+ for _, pth in pairs(own.list) do
+ local filename = string.gsub(pth .. "/" .. lib,"\\","/")
+ local codeblob = loadfile(filename)
+ if codeblob then
+ codeblob()
+ own.list = { pth } -- speed up te search
+ break
+ end
+ end
+ end
+end
+
+if not resolvers then
+ locate_libs()
+end
+
+if not resolvers then
+ print("")
+ print("Mtxrun is unable to start up due to lack of libraries. You may")
+ print("try to run 'lua mtxrun.lua --selfmerge' in the path where this")
+ print("script is located (normally under ..../scripts/context/lua) which")
+ print("will make this script library independent.")
+ os.exit()
+end
+
+logs.setprogram('MTXrun',"TDS Runner Tool 1.22",environment.arguments["verbose"] or false)
+
+local instance = resolvers.reset()
+
+runners = runners or { } -- global
+messages = messages or { }
+
+messages.help = [[
+--script run an mtx script (--noquotes)
+--execute run a script or program (--noquotes)
+--resolve resolve prefixed arguments
+--ctxlua run internally (using preloaded libs)
+--locate locate given filename
+
+--autotree use texmf tree cf. env 'texmfstart_tree' or 'texmfstarttree'
+--tree=pathtotree use given texmf tree (default file: 'setuptex.tmf')
+--environment=name use given (tmf) environment file
+--path=runpath go to given path before execution
+--ifchanged=filename only execute when given file has changed (md checksum)
+--iftouched=old,new only execute when given file has changed (time stamp)
+
+--make create stubs for (context related) scripts
+--remove remove stubs (context related) scripts
+--stubpath=binpath paths where stubs wil be written
+--windows create windows (mswin) stubs
+--unix create unix (linux) stubs
+
+--verbose give a bit more info
+--engine=str target engine
+--progname=str format or backend
+
+--edit launch editor with found file
+--launch (--all) launch files like manuals, assumes os support
+
+--intern run script using built in libraries
+
+--usekpse use kpse as fallback (when no mkiv and cache installed, often slower)
+--forcekpse force using kpse (handy when no mkiv and cache installed but less functionality)
+]]
+
+runners.applications = {
+ ["lua"] = "luatex --luaonly",
+ ["luc"] = "luatex --luaonly",
+ ["pl"] = "perl",
+ ["py"] = "python",
+ ["rb"] = "ruby",
+}
+
+runners.suffixes = {
+ 'rb', 'lua', 'py', 'pl'
+}
+
+runners.registered = {
+ texexec = { 'texexec.rb', true }, -- context mkii runner (only tool not to be luafied)
+ texutil = { 'texutil.rb', true }, -- old perl based index sorter for mkii (old versions need it)
+ texfont = { 'texfont.pl', true }, -- perl script that makes mkii font metric files
+ texfind = { 'texfind.pl', false }, -- perltk based tex searching tool, mostly used at pragma
+ texshow = { 'texshow.pl', false }, -- perltk based context help system, will be luafied
+ -- texwork = { \texwork.pl', false }, -- perltk based editing environment, only used at pragma
+
+ makempy = { 'makempy.pl', true },
+ mptopdf = { 'mptopdf.pl', true },
+ pstopdf = { 'pstopdf.rb', true }, -- converts ps (and some more) images, does some cleaning (replaced)
+
+-- examplex = { 'examplex.rb', false },
+ concheck = { 'concheck.rb', false },
+
+ runtools = { 'runtools.rb', true },
+ textools = { 'textools.rb', true },
+ tmftools = { 'tmftools.rb', true },
+ ctxtools = { 'ctxtools.rb', true },
+ rlxtools = { 'rlxtools.rb', true },
+ pdftools = { 'pdftools.rb', true },
+ mpstools = { 'mpstools.rb', true },
+-- exatools = { 'exatools.rb', true },
+ xmltools = { 'xmltools.rb', true },
+-- luatools = { 'luatools.lua', true },
+ mtxtools = { 'mtxtools.rb', true },
+
+ pdftrimwhite = { 'pdftrimwhite.pl', false }
+}
+
+runners.launchers = {
+ windows = { },
+ unix = { }
+}
+
+function runners.prepare()
+ local checkname = environment.argument("ifchanged")
+ if checkname and checkname ~= "" then
+ local oldchecksum = file.loadchecksum(checkname)
+ local newchecksum = file.checksum(checkname)
+ if oldchecksum == newchecksum then
+ logs.simple("file '%s' is unchanged",checkname)
+ return "skip"
+ else
+ logs.simple("file '%s' is changed, processing started",checkname)
+ end
+ file.savechecksum(checkname)
+ end
+ local oldname, newname = string.split(environment.argument("iftouched") or "", ",")
+ if oldname and newname and oldname ~= "" and newname ~= "" then
+ if not file.needs_updating(oldname,newname) then
+ logs.simple("file '%s' and '%s' have same age",oldname,newname)
+ return "skip"
+ else
+ logs.simple("file '%s' is older than '%s'",oldname,newname)
+ end
+ end
+ local tree = environment.argument('tree') or ""
+ if environment.argument('autotree') then
+ tree = os.getenv('TEXMFSTART_TREE') or os.getenv('TEXMFSTARTTREE') or tree
+ end
+ if tree and tree ~= "" then
+ resolvers.load_tree(tree)
+ end
+ local env = environment.argument('environment') or ""
+ if env and env ~= "" then
+ for _,e in pairs(string.split(env)) do
+ -- maybe force suffix when not given
+ resolvers.load_tree(e)
+ end
+ end
+ local runpath = environment.argument("path")
+ if runpath and not lfs.chdir(runpath) then
+ logs.simple("unable to change to path '%s'",runpath)
+ return "error"
+ end
+ return "run"
+end
+
+function runners.execute_script(fullname,internal)
+ local noquote = environment.argument("noquotes")
+ if fullname and fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ instance.progname = environment.argument("progname") or instance.progname
+ instance.format = environment.argument("format") or instance.format
+ local path, name, suffix, result = file.dirname(fullname), file.basename(fullname), file.extname(fullname), ""
+ if path ~= "" then
+ result = fullname
+ elseif name then
+ name = name:gsub("^int[%a]*:",function()
+ internal = true
+ return ""
+ end )
+ name = name:gsub("^script:","")
+ if suffix == "" and runners.registered[name] and runners.registered[name][1] then
+ name = runners.registered[name][1]
+ suffix = file.extname(name)
+ end
+ if suffix == "" then
+ -- loop over known suffixes
+ for _,s in pairs(runners.suffixes) do
+ result = resolvers.find_file(name .. "." .. s, 'texmfscripts')
+ if result ~= "" then
+ break
+ end
+ end
+ elseif runners.applications[suffix] then
+ result = resolvers.find_file(name, 'texmfscripts')
+ else
+ -- maybe look on path
+ result = resolvers.find_file(name, 'other text files')
+ end
+ end
+ if result and result ~= "" then
+ local before, after = environment.split_arguments(fullname) -- already done
+ environment.arguments_before, environment.arguments_after = before, after
+ if internal then
+ arg = { } for _,v in pairs(after) do arg[#arg+1] = v end
+ dofile(result)
+ else
+ local binary = runners.applications[file.extname(result)]
+ if binary and binary ~= "" then
+ result = binary .. " " .. result
+ end
+ local command = result .. " " .. environment.reconstruct_commandline(after,noquote)
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
+ io.flush()
+ end
+ local code = os.exec(command) -- maybe spawn
+ return code == 0
+ end
+ end
+ end
+ end
+ return false
+end
+
+function runners.execute_program(fullname)
+ local noquote = environment.argument("noquotes")
+ if fullname and fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ local before, after = environment.split_arguments(fullname)
+ environment.initialize_arguments(after)
+ fullname = fullname:gsub("^bin:","")
+ local command = fullname .. " " .. (environment.reconstruct_commandline(after or "",noquote) or "")
+ logs.simpleline()
+ logs.simple("executing: %s",command)
+ logs.simpleline()
+ logs.simpleline()
+ io.flush()
+ local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn
+ return code == 0
+ end
+ end
+ return false
+end
+
+-- the --usekpse flag will fallback on kpse
+
+local windows_stub = '@echo off\013\010setlocal\013\010set ownpath=%%~dp0%%\013\010texlua "%%ownpath%%mtxrun.lua" --usekpse --execute %s %%*\013\010endlocal\013\010'
+local unix_stub = '#!/bin/sh\010mtxrun --usekpse --execute %s \"$@\"\010'
+
+function runners.handle_stubs(create)
+ local stubpath = environment.argument('stubpath') or '.' -- 'auto' no longer subpathssupported
+ local windows = environment.argument('windows') or environment.argument('mswin') or false
+ local unix = environment.argument('unix') or environment.argument('linux') or false
+ if not windows and not unix then
+ if os.platform == "unix" then
+ unix = true
+ else
+ windows = true
+ end
+ end
+ for _,v in pairs(runners.registered) do
+ local name, doit = v[1], v[2]
+ if doit then
+ local base = string.gsub(file.basename(name), "%.(.-)$", "")
+ if create then
+ if windows then
+ io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name))
+ logs.simple("windows stub for '%s' created",base)
+ end
+ if unix then
+ io.savedata(file.join(stubpath,base),string.format(unix_stub,name))
+ logs.simple("unix stub for '%s' created",base)
+ end
+ else
+ if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then
+ logs.simple("windows stub for '%s' removed", base)
+ end
+ if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then
+ logs.simple("unix stub for '%s' removed",base)
+ end
+ end
+ end
+ end
+end
+
+function runners.resolve_string(filename)
+ if filename and filename ~= "" then
+ runners.report_location(resolvers.resolve(filename))
+ end
+end
+
+function runners.locate_file(filename)
+ -- differs from texmfstart where locate appends .com .exe .bat ... todo
+ if filename and filename ~= "" then
+ runners.report_location(resolvers.find_given_file(filename))
+ end
+end
+
+function runners.locate_platform()
+ runners.report_location(os.currentplatform())
+end
+
+function runners.report_location(result)
+ if logs.verbose then
+ logs.simpleline()
+ if result and result ~= "" then
+ logs.simple(result)
+ else
+ logs.simple("not found")
+ end
+ else
+ io.write(result)
+ end
+end
+
+function runners.edit_script(filename) -- we assume that vim is present on most systems
+ local editor = os.getenv("MTXRUN_EDITOR") or os.getenv("TEXMFSTART_EDITOR") or os.getenv("EDITOR") or 'vim'
+ local rest = resolvers.resolve(filename)
+ if rest ~= "" then
+ local command = editor .. " " .. rest
+ if logs.verbose then
+ logs.simpleline()
+ logs.simple("starting editor: %s",command)
+ logs.simple_line()
+ logs.simple_line()
+ end
+ os.launch(command)
+ end
+end
+
+function runners.save_script_session(filename, list)
+ local t = { }
+ for _, key in ipairs(list) do
+ t[key] = environment.arguments[key]
+ end
+ io.savedata(filename,table.serialize(t,true))
+end
+
+function runners.load_script_session(filename)
+ if lfs.isfile(filename) then
+ local t = io.loaddata(filename)
+ if t then
+ t = loadstring(t)
+ if t then t = t() end
+ for key, value in pairs(t) do
+ environment.arguments[key] = value
+ end
+ end
+ end
+end
+
+function resolvers.launch(str)
+ -- maybe we also need to test on mtxrun.launcher.suffix environment
+ -- variable or on windows consult the assoc and ftype vars and such
+ local launchers = runners.launchers[os.platform] if launchers then
+ local suffix = file.extname(str) if suffix then
+ local runner = launchers[suffix] if runner then
+ str = runner .. " " .. str
+ end
+ end
+ end
+ os.launch(str)
+end
+
+function runners.launch_file(filename)
+ instance.allresults = true
+ logs.setverbose(true)
+ local pattern = environment.arguments["pattern"]
+ if not pattern or pattern == "" then
+ pattern = filename
+ end
+ if not pattern or pattern == "" then
+ logs.simple("provide name or --pattern=")
+ else
+ local t = resolvers.find_files(pattern)
+ if not t or #t == 0 then
+ t = resolvers.find_files("*/" .. pattern)
+ end
+ if not t or #t == 0 then
+ t = resolvers.find_files("*/" .. pattern .. "*")
+ end
+ if t and #t > 0 then
+ if environment.arguments["all"] then
+ for _, v in pairs(t) do
+ logs.simple("launching %s", v)
+ resolvers.launch(v)
+ end
+ else
+ logs.simple("launching %s", t[1])
+ resolvers.launch(t[1])
+ end
+ else
+ logs.simple("no match for %s", pattern)
+ end
+ end
+end
+
+function runners.find_mtx_script(filename)
+ local function found(name)
+ local path = file.dirname(name)
+ if path and path ~= "" then
+ return false
+ else
+ local fullname = own and own.path and file.join(own.path,name)
+ return io.exists(fullname) and fullname
+ end
+ end
+ filename = file.addsuffix(filename,"lua")
+ local basename = file.removesuffix(file.basename(filename))
+ local suffix = file.extname(filename)
+ -- qualified path, raw name
+ local fullname = file.is_qualified_path(filename) and io.exists(filename) and filename
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- current path, raw name
+ fullname = "./" .. filename
+ fullname = io.exists(fullname) and fullname
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-
+ fullname = "mtx-" .. filename
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-s
+ fullname = "mtx-" .. basename .. "s" .. "." .. suffix
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, mtx-
+ fullname = "mtx-" .. basename:gsub("s$","") .. "." .. suffix
+ fullname = found(fullname) or resolvers.find_file(fullname)
+ if fullname and fullname ~= "" then
+ return fullname
+ end
+ -- context namespace, just
+ fullname = resolvers.find_file(filename)
+ return fullname
+end
+
+function runners.execute_ctx_script(filename,arguments)
+ local fullname = runners.find_mtx_script(filename) or ""
+ -- retyr after generate but only if --autogenerate
+ if fullname == "" and environment.argument("autogenerate") then -- might become the default
+ instance.renewcache = true
+ logs.setverbose(true)
+ resolvers.load()
+ --
+ fullname = runners.find_mtx_script(filename) or ""
+ end
+ -- that should do it
+ if fullname ~= "" then
+ local state = runners.prepare()
+ if state == 'error' then
+ return false
+ elseif state == 'skip' then
+ return true
+ elseif state == "run" then
+ -- load and save ... kind of undocumented
+ arg = { } for _,v in pairs(arguments) do arg[#arg+1] = resolvers.resolve(v) end
+ environment.initialize_arguments(arg)
+ local loadname = environment.arguments['load']
+ if loadname then
+ if type(loadname) ~= "string" then loadname = file.basename(fullname) end
+ loadname = file.replacesuffix(loadname,"cfg")
+ runners.load_script_session(loadname)
+ end
+ filename = environment.files[1]
+ if logs.verbose then
+ logs.simple("using script: %s\n",fullname)
+ end
+ dofile(fullname)
+ local savename = environment.arguments['save']
+ if savename and runners.save_list and not table.is_empty(runners.save_list or { }) then
+ if type(savename) ~= "string" then savename = file.basename(fullname) end
+ savename = file.replacesuffix(savename,"cfg")
+ runners.save_script_session(savename, runners.save_list)
+ end
+ return true
+ end
+ else
+ logs.setverbose(true)
+ filename = file.addsuffix(filename,"lua")
+ if filename == "" then
+ logs.simple("unknown script, no name given")
+ elseif file.is_qualified_path(filename) then
+ logs.simple("unknown script '%s'",filename)
+ else
+ logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename)
+ end
+ return false
+ end
+end
+
+function runners.timed(action)
+ statistics.timed(action)
+end
+
+-- this is a bit dirty ... first we store the first filename and next we
+-- split the arguments so that we only see the ones meant for this script
+-- ... later we will use the second half
+
+local filename = environment.files[1] or ""
+local ok = true
+
+local before, after = environment.split_arguments(filename)
+environment.arguments_before, environment.arguments_after = before, after
+environment.initialize_arguments(before)
+
+instance.engine = environment.argument("engine") or 'luatex'
+instance.progname = environment.argument("progname") or 'context'
+instance.lsrmode = environment.argument("lsr") or false
+
+-- maybe the unset has to go to this level
+
+if environment.argument("usekpse") or environment.argument("forcekpse") then
+
+ os.setenv("engine","")
+ os.setenv("progname","")
+
+ local remapper = {
+ otf = "opentype fonts",
+ ttf = "truetype fonts",
+ ttc = "truetype fonts",
+ pfb = "type1 fonts",
+ other = "other text files",
+ }
+
+ local function kpse_initialized()
+ texconfig.kpse_init = true
+ local t = os.clock()
+ local k = kpse.original.new("luatex",instance.progname)
+ local dummy = k:find_file("mtxrun.lua") -- so that we're initialized
+ logs.simple("kpse fallback with progname '%s' initialized in %s seconds",instance.progname,os.clock()-t)
+ kpse_initialized = function() return k end
+ return k
+ end
+
+ local find_file = resolvers.find_file
+ local show_path = resolvers.show_path
+
+ if environment.argument("forcekpse") then
+
+ function resolvers.find_file(name,kind)
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ function resolvers.show_path(name)
+ return (kpse_initialized():show_path(name)) or ""
+ end
+
+ elseif environment.argument("usekpse") then
+
+ resolvers.load()
+
+ function resolvers.find_file(name,kind)
+ local found = find_file(name,kind) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():find_file(resolvers.clean_path(name),(kind ~= "" and (remapper[kind] or kind)) or "tex") or "") or ""
+ end
+ end
+ function resolvers.show_path(name)
+ local found = show_path(name) or ""
+ if found ~= "" then
+ return found
+ else
+ return (kpse_initialized():show_path(name)) or ""
+ end
+ end
+
+ end
+
+else
+
+ resolvers.load()
+
+end
+
+
+if environment.argument("selfmerge") then
+ -- embed used libraries
+ utils.merger.selfmerge(own.name,own.libs,own.list)
+elseif environment.argument("selfclean") then
+ -- remove embedded libraries
+ utils.merger.selfclean(own.name)
+elseif environment.argument("selfupdate") then
+ logs.setverbose(true)
+ resolvers.update_script(own.name,"mtxrun")
+elseif environment.argument("ctxlua") or environment.argument("internal") then
+ -- run a script by loading it (using libs)
+ ok = runners.execute_script(filename,true)
+elseif environment.argument("script") or environment.argument("s") then
+ -- run a script by loading it (using libs), pass args
+ ok = runners.execute_ctx_script(filename,after)
+elseif environment.argument("execute") then
+ -- execute script
+ ok = runners.execute_script(filename)
+elseif environment.argument("direct") then
+ -- equals bin:
+ ok = runners.execute_program(filename)
+elseif environment.argument("edit") then
+ -- edit file
+ runners.edit_script(filename)
+elseif environment.argument("launch") then
+ runners.launch_file(filename)
+elseif environment.argument("make") then
+ -- make stubs
+ runners.handle_stubs(true)
+elseif environment.argument("remove") then
+ -- remove stub
+ runners.handle_stubs(false)
+elseif environment.argument("resolve") then
+ -- resolve string
+ runners.resolve_string(filename)
+elseif environment.argument("locate") then
+ -- locate file
+ runners.locate_file(filename)
+elseif environment.argument("platform")then
+ -- locate platform
+ runners.locate_platform()
+elseif environment.argument("help") or filename=='help' or filename == "" then
+ logs.help(messages.help)
+ -- execute script
+elseif filename:find("^bin:") then
+ ok = runners.execute_program(filename)
+else
+ ok = runners.execute_script(filename)
+end
+
+if os.platform == "unix" then
+ io.write("\n")
+end
+
+if ok == false then ok = 1 elseif ok == true then ok = 0 end
+
+os.exit(ok)
diff --git a/scripts/context/stubs/unix/mtxtools b/scripts/context/stubs/unix/mtxtools
new file mode 100755
index 000000000..3803c1c6f
--- /dev/null
+++ b/scripts/context/stubs/unix/mtxtools
@@ -0,0 +1,2 @@
+#!/bin/sh
+mtxrun --usekpse --execute mtxtools.rb "$@"
diff --git a/scripts/context/stubs/unix/pdftools b/scripts/context/stubs/unix/pdftools
index 92ee803a8..da7bd64cf 100755
--- a/scripts/context/stubs/unix/pdftools
+++ b/scripts/context/stubs/unix/pdftools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart pdftools.rb "$@"
+mtxrun --usekpse --execute pdftools.rb "$@"
diff --git a/scripts/context/stubs/unix/pdftrimwhite b/scripts/context/stubs/unix/pdftrimwhite
deleted file mode 100755
index 00b5f525a..000000000
--- a/scripts/context/stubs/unix/pdftrimwhite
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-texmfstart pdftrimwhite.pl "$@"
diff --git a/scripts/context/stubs/unix/pstopdf b/scripts/context/stubs/unix/pstopdf
index 5b38ed426..059812cce 100755
--- a/scripts/context/stubs/unix/pstopdf
+++ b/scripts/context/stubs/unix/pstopdf
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart pstopdf.rb "$@"
+mtxrun --usekpse --execute pstopdf.rb "$@"
diff --git a/scripts/context/stubs/unix/rlxtools b/scripts/context/stubs/unix/rlxtools
index 41cea40fc..d01987b3c 100755
--- a/scripts/context/stubs/unix/rlxtools
+++ b/scripts/context/stubs/unix/rlxtools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart rlxtools.rb "$@"
+mtxrun --usekpse --execute rlxtools.rb "$@"
diff --git a/scripts/context/stubs/unix/runtools b/scripts/context/stubs/unix/runtools
index ff9a33379..e21c1a244 100755
--- a/scripts/context/stubs/unix/runtools
+++ b/scripts/context/stubs/unix/runtools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart runtools.rb "$@"
+mtxrun --usekpse --execute runtools.rb "$@"
diff --git a/scripts/context/stubs/unix/texexec b/scripts/context/stubs/unix/texexec
index 215817290..083e500c6 100755
--- a/scripts/context/stubs/unix/texexec
+++ b/scripts/context/stubs/unix/texexec
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart texexec.rb "$@"
+mtxrun --usekpse --execute texexec.rb "$@"
diff --git a/scripts/context/stubs/unix/texfind b/scripts/context/stubs/unix/texfind
deleted file mode 100755
index c054bdf52..000000000
--- a/scripts/context/stubs/unix/texfind
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-texmfstart texfind "$@"
diff --git a/scripts/context/stubs/unix/texfont b/scripts/context/stubs/unix/texfont
index a91f786e3..bc811a640 100755
--- a/scripts/context/stubs/unix/texfont
+++ b/scripts/context/stubs/unix/texfont
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart texfont.pl "$@"
+mtxrun --usekpse --execute texfont.pl "$@"
diff --git a/scripts/context/stubs/unix/texmfstart b/scripts/context/stubs/unix/texmfstart
new file mode 100755
index 000000000..1799b3579
--- /dev/null
+++ b/scripts/context/stubs/unix/texmfstart
@@ -0,0 +1,2 @@
+#!/bin/sh
+mtxrun --usekpse "$@"
diff --git a/scripts/context/stubs/unix/texshow b/scripts/context/stubs/unix/texshow
deleted file mode 100755
index afd62c339..000000000
--- a/scripts/context/stubs/unix/texshow
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-texmfstart texshow.pl "$@"
diff --git a/scripts/context/stubs/unix/textools b/scripts/context/stubs/unix/textools
index 7445eac37..76087ca57 100755
--- a/scripts/context/stubs/unix/textools
+++ b/scripts/context/stubs/unix/textools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart textools.rb "$@"
+mtxrun --usekpse --execute textools.rb "$@"
diff --git a/scripts/context/stubs/unix/texutil b/scripts/context/stubs/unix/texutil
index 607154af0..f5d9b6f1d 100755
--- a/scripts/context/stubs/unix/texutil
+++ b/scripts/context/stubs/unix/texutil
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart texutil.rb "$@"
+mtxrun --usekpse --execute texutil.rb "$@"
diff --git a/scripts/context/stubs/unix/tmftools b/scripts/context/stubs/unix/tmftools
index 7531a9663..48d32f0fd 100755
--- a/scripts/context/stubs/unix/tmftools
+++ b/scripts/context/stubs/unix/tmftools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart tmftools.rb "$@"
+mtxrun --usekpse --execute tmftools.rb "$@"
diff --git a/scripts/context/stubs/unix/xmltools b/scripts/context/stubs/unix/xmltools
index 03086d043..a673d1e7a 100755
--- a/scripts/context/stubs/unix/xmltools
+++ b/scripts/context/stubs/unix/xmltools
@@ -1,2 +1,2 @@
#!/bin/sh
-texmfstart xmltools.rb "$@"
+mtxrun --usekpse --execute xmltools.rb "$@"
diff --git a/tex/context/base/attr-ini.lua b/tex/context/base/attr-ini.lua
index 204cabce1..3b2ed7791 100644
--- a/tex/context/base/attr-ini.lua
+++ b/tex/context/base/attr-ini.lua
@@ -6,146 +6,23 @@ if not modules then modules = { } end modules ['attr-ini'] = {
license = "see context related readme files"
}
--- todo: document this
-
--- nb: attributes: color etc is much slower than normal (marks + literals) but ...
--- nb. too many "0 g"s
-
---
--- nodes
---
-
-nodes = nodes or { }
-
-local format, concat, texsprint = string.format, table.concat, tex.sprint
-
--- This is not the most ideal place, but it will do. Maybe we need to move
--- attributes to node-att.lua.
-
-do
-
- -- just for testing
-
- local reserved = { }
-
- function nodes.register(n)
- reserved[#reserved+1] = n
- end
-
- function nodes.cleanup_reserved(nofboxes) -- todo
- local nr, free = #reserved, node.free
- for i=1,nr do
- free(reserved[i])
- end
- local nl, tb, flush = 0, tex.box, node.flush_list
- if nofboxes then
- for i=1,nofboxes do
- local l = tb[i]
- if l then
- free(tb[i])
- nl = nl + 1
- end
- end
- end
- reserved = { }
- return nr, nl, nofboxes
- end
-
-end
+-- this module is being reconstructed
-do
-
- local pdfliteral = node.new("whatsit",8) pdfliteral.next, pdfliteral.prev = nil, nil pdfliteral.mode = 1
- local disc = node.new("disc") disc.next, disc.prev = nil, nil
- local kern = node.new("kern",1) kern.next, kern.prev = nil, nil
- local penalty = node.new("penalty") penalty.next, penalty.prev = nil, nil
- local glue = node.new("glue") glue.next, glue.prev = nil, nil
- local glue_spec = node.new("glue_spec")
- local glyph = node.new("glyph",0) glyph.next, glyph.prev = nil, nil
- local textdir = node.new("whatsit",7) textdir.next, textdir.prev = nil, nil
-
- nodes.register(pdfliteral)
- nodes.register(disc)
- nodes.register(kern)
- nodes.register(penalty)
- nodes.register(glue)
- nodes.register(glue_spec)
- nodes.register(glyph)
- nodes.register(textdir)
-
- local copy = node.copy
-
- function nodes.glyph(fnt,chr)
- local n = copy(glyph)
- if fnt then n.font = fnt end
- if chr then n.char = chr end
- return n
- end
- function nodes.penalty(p)
- local n = copy(penalty)
- n.penalty = p
- return n
- end
- function nodes.kern(k)
- local n = copy(kern)
- n.kern = k
- return n
- end
- function nodes.glue(width,stretch,shrink)
- local n = copy(glue)
- local s = copy(glue_spec)
- s.width, s.stretch, s.shrink = width, stretch, shrink
- n.spec = s
- return n
- end
- function nodes.glue_spec(width,stretch,shrink)
- local s = copy(glue_spec)
- s.width, s.stretch, s.shrink = width, stretch, shrink
- return s
- end
- function nodes.disc()
- return copy(disc)
- end
- function nodes.pdfliteral(str)
- local t = copy(pdfliteral)
- t.data = str
- return t
- end
- function nodes.textdir(dir)
- local t = copy(textdir)
- t.dir = dir
- return t
- end
-
-end
-
-function tex.node_mem_status()
- -- todo: lpeg
- local s = status.node_mem_usage
- local t = { }
- for n, tag in s:gmatch("(%d+) ([a-z_]+)") do
- t[tag] = n
- end
- return t
-end
-
---
--- attributes
---
+local type = type
+local format, gmatch = string.format, string.gmatch
+local concat = table.concat
+local texsprint = tex.sprint
-attributes = attributes or { }
+local ctxcatcodes = tex.ctxcatcodes
-attributes.names = attributes.names or { }
-attributes.numbers = attributes.numbers or { }
-attributes.list = attributes.list or { }
+-- todo: document this
-input.storage.register(false, "attributes/names", attributes.names, "attributes.names")
-input.storage.register(false, "attributes/numbers", attributes.numbers, "attributes.numbers")
-input.storage.register(false, "attributes/list", attributes.list, "attributes.list")
+-- nb: attributes: color etc is much slower than normal (marks + literals) but ...
+-- nb. too many "0 g"s
-function attributes.define(name,number)
- attributes.numbers[name], attributes.names[number], attributes.list[number] = number, name, { }
-end
+nodes = nodes or { }
+states = states or { }
+shipouts = shipouts or { }
-- We can distinguish between rules and glyphs but it's not worth the trouble. A
-- first implementation did that and while it saves a bit for glyphs and rules, it
@@ -156,342 +33,6 @@ end
-- i will do the resource stuff later, when we have an interface to pdf (ok, i can
-- fake it with tokens but it will take some coding
-function totokens(str)
- local t = { }
---~ for c in string.bytes(str) do
- for c in str:bytes() do
- t[#t+1] = { 12, c }
- end
- return t
-end
-
--- temp hack, will be proper driver stuff
-
-backends = backends or { }
-backends.pdf = backends.pdf or { }
-backend = backend or backends.pdf
-
-do
-
- local pdfliteral, register = nodes.pdfliteral, nodes.register
-
- function backends.pdf.literal(str)
- local t = pdfliteral(str)
- register(t)
- return t
- end
-
-end
-
--- shipouts
-
-shipouts = shipouts or { }
-
-do
-
- local pairs = pairs -- in theory faster
-
- local hlist, vlist = node.id('hlist'), node.id('vlist')
-
- local has_attribute = node.has_attribute
-
- nodes.trigger = nodes.trigger or false
- nodes.triggering = nodes.triggering or false
-
- -- we used to do the main processor loop here and call processor for each node
- -- but eventually this was too much a slow down (1 sec on 23 for 120 pages mk)
- -- so that we moved looping to the processor itself; this may lead to a bit of
- -- duplicate code once that we have more state handlers
-
- local starttiming, stoptiming = input.starttiming, input.stoptiming
- local trigger, numbers = nodes.trigger, attributes.numbers
-
- local function process_attribute(head,plugin) -- head,attribute,enabled,initializer,resolver,processor,finalizer
- starttiming(attributes)
- local done, used, ok = false, nil, false
- local name = plugin.name
- local attribute = numbers[name]
- local namespace = plugin.namespace
- if namespace.enabled then
- local processor = plugin.processor
- if processor then
- local initializer = plugin.initializer
- local resolver = plugin.resolver
- local inheritance = (resolver and resolver()) or -1
- if initializer then
- initializer(namespace,attribute,head)
- end
- head, ok = processor(namespace,attribute,head,inheritance)
- if ok then
- local finalizer = plugin.finalizer
- if finalizer then
- head, ok, used = finalizer(namespace,attribute,head)
- if used then
- local flusher = plugin.flusher
- if flusher then
- local h, d = flusher(namespace,attribute,head,used)
- head = h
- end
- end
- end
- done = true
- end
- end
- end
- stoptiming(attributes)
- return head, done
- end
-
- nodes.process_attribute = process_attribute
-
- function nodes.install_attribute_handler(plugin)
- return function(head)
- return process_attribute(head,plugin)
- end
- end
-
-end
-
---
--- generic handlers
---
-
-states = { }
-
-do
-
- local glyph, glue, rule, whatsit, hlist, vlist = node.id('glyph'), node.id('glue'), node.id('rule'), node.id('whatsit'), node.id('hlist'), node.id('vlist')
-
- local has_attribute, copy = node.has_attribute, node.copy
-
- local current, current_selector, used, done = 0, 0, { }, false
-
- function states.initialize(what, attribute, stack)
- current, current_selector, used, done = 0, 0, { }, false
- end
-
- local function insert(n,stack,previous,head) -- there is a helper, we need previous because we are not slided
- if n then
- if type(n) == "function" then
- n = n()
- end
- n = copy(n)
- n.next = stack
- if previous then
- previous.next = n
- else
- head = n
- end
- previous = n
- end
- return stack, head
- end
-
- function states.finalize(namespace,attribute,head) -- is this one ok?
- if current > 0 then
- local nn = namespace.none
- if nn then
- local id = head.id
- if id == hlist or id == vlist then
- local list = head.list
- if list then
- local _, h = insert(nn,list,nil,list)
- head.list = h
- end
- else
- stack, head = insert(nn,head,nil,head)
- end
- return head, true, true
- end
- end
- return head, false, false
- end
-
- local function process(namespace,attribute,head,inheritance,default) -- one attribute
- local trigger = namespace.triggering and nodes.triggering and nodes.trigger
- local stack, previous, done = head, nil, false
- local nsdata, nsreviver, nsnone = namespace.data, namespace.reviver, namespace.none
- while stack do
- local id = stack.id
- -- if id == glyph or (id == whatsit and stack.subtype == 8) or id == rule or (id == glue and stack.leader) then -- or disc
- if id == glyph or id == rule or (id == glue and stack.leader) then -- or disc
- local c = has_attribute(stack,attribute)
- if c then
- if default and c == inheritance then
- if current ~= default then
- local data = nsdata[default] or nsreviver(default)
- stack, head = insert(data,stack,previous,head)
- current, done, used[default] = default, true, true
- end
- elseif current ~= c then
- local data = nsdata[c] or nsreviver(c)
- stack, head = insert(data,stack,previous,head)
- current, done, used[c] = c, true, true
- end
- if id == glue then --leader
- -- same as *list
- local content = stack.leader
- if content then
- local ok = false
- if trigger and has_attribute(stack,trigger) then
- local outer = has_attribute(stack,attribute)
- if outer ~= inheritance then
- stack.leader, ok = process(namespace,attribute,content,inheritance,outer)
- else
- stack.leader, ok = process(namespace,attribute,content,inheritance,default)
- end
- else
- stack.leader, ok = process(namespace,attribute,content,inheritance,default)
- end
- done = done or ok
- end
- end
- elseif default and inheritance then
- if current ~= default then
- local data = nsdata[default] or nsreviver(default)
- stack, head = insert(data,stack,previous,head)
- current, done, used[default] = default, true, true
- end
- elseif current > 0 then
- stack, head = insert(nsnone,stack,previous,head)
- current, done, used[0] = 0, true, true
- end
- elseif id == hlist or id == vlist then
- local content = stack.list
- if content then
- local ok = false
- if trigger and has_attribute(stack,trigger) then
- local outer = has_attribute(stack,attribute)
- if outer ~= inheritance then
- stack.list, ok = process(namespace,attribute,content,inheritance,outer)
- else
- stack.list, ok = process(namespace,attribute,content,inheritance,default)
- end
- else
- stack.list, ok = process(namespace,attribute,content,inheritance,default)
- end
- done = done or ok
- end
- end
- previous = stack
- stack = stack.next
- end
- return head, done
- end
-
- states.process = process
-
- -- we can force a selector, e.g. document wide color spaces, saves a little
- -- watch out, we need to check both the selector state (like colorspace) and
- -- the main state (like color), otherwise we get into troubles when a selector
- -- state changes while the main state stays the same (like two glyphs following
- -- each other with the same color but different color spaces e.g. \showcolor)
-
- local function selective(namespace,attribute,head,inheritance,default) -- two attributes
- local trigger = namespace.triggering and nodes.triggering and nodes.trigger
- local stack, previous, done = head, nil, false
- -- local nsselector, nsforced, nsselector = namespace.default, namespace.forced, namespace.selector
- local nsforced, nsselector = namespace.forced, namespace.selector
- local nsdata, nsreviver, nsnone = namespace.data, namespace.reviver, namespace.none
- while stack do
- local id = stack.id
- -- if id == glyph or (id == whatsit and stack.subtype == 8) or id == rule or (id == glue and stack.leader) then -- or disc
- if id == glyph or id == rule or (id == glue and stack.leader) then -- or disc
- local c = has_attribute(stack,attribute)
- if c then
- if default and c == inheritance then
- if current ~= default then
- local data = nsdata[default] or nsreviver(default)
- stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
- current, done, used[default] = default, true, true
- end
- else
- local s = has_attribute(stack,nsselector)
- if current ~= c or current_selector ~= s then
- local data = nsdata[c] or nsreviver(c)
- stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
- current, current_selector, done, used[c] = c, s, true, true
- end
- end
- elseif default and inheritance then
- if current ~= default then
- local data = nsdata[default] or nsreviver(default)
- stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
- current, done, used[default] = default, true, true
- end
- elseif current > 0 then
- stack, head = insert(nsnone,stack,previous,head)
- current, current_selector, done, used[0] = 0, 0, true, true
- end
- if id == glue then -- leader
- -- same as *list
- local content = stack.leader
- if content then
- local ok = false
- if trigger and has_attribute(stack,trigger) then
- local outer = has_attribute(stack,attribute)
- if outer ~= inheritance then
- stack.leader, ok = selective(namespace,attribute,content,inheritance,outer)
- else
- stack.leader, ok = selective(namespace,attribute,content,inheritance,default)
- end
- else
- stack.leader, ok = selective(namespace,attribute,content,inheritance,default)
- end
- done = done or ok
- end
- end
- elseif id == hlist or id == vlist then
- local content = stack.list
- if content then
- local ok = false
- if trigger and has_attribute(stack,trigger) then
- local outer = has_attribute(stack,attribute)
- if outer ~= inheritance then
- stack.list, ok = selective(namespace,attribute,content,inheritance,outer)
- else
- stack.list, ok = selective(namespace,attribute,content,inheritance,default)
- end
- else
- stack.list, ok = selective(namespace,attribute,content,inheritance,default)
- end
- done = done or ok
- end
- end
- previous = stack
- stack = stack.next
- end
- return head, done
- end
-
- states.selective = selective
-
-end
-
-states = states or { }
-states.collected = states.collected or { }
-
-input.storage.register(false,"states/collected", states.collected, "states.collected")
-
-function states.collect(str)
- local collected = states.collected
- collected[#collected+1] = str
-end
-
-function states.flush()
- local collected = states.collected
- if #collected > 0 then
- for i=1,#collected do
- texsprint(tex.ctxcatcodes,collected[i]) -- we're in context mode anyway
- end
- states.collected = { }
- end
-end
-
-function states.check()
- texio.write_nl(concat(states.collected,"\n"))
-end
-
--
-- colors
--
@@ -500,21 +41,9 @@ end
-- at the tex end add 0, 1, 2, but this is not faster and less
-- flexible (since sometimes we freeze color attribute values at
-- the lua end of the game
-
+--
-- we also need to store the colorvalues because we need then in mp
-
-colors = colors or { }
-colors.data = colors.data or { }
-colors.values = colors.values or { }
-colors.registered = colors.registered or { }
-colors.enabled = true
-colors.weightgray = true
-colors.attribute = 0
-colors.selector = 0
-colors.default = 1
-colors.main = nil
-colors.triggering = true
-
+--
-- This is a compromis between speed and simplicity. We used to store the
-- values and data in one array, which made in neccessary to store the
-- converters that need node constructor into strings and evaluate them
@@ -526,21 +55,33 @@ colors.triggering = true
-- colors.strings[color] = "return colors." .. colorspace .. "(" .. concat({...},",") .. ")"
-- end
--
--- input.storage.register(true,"colors/data", colors.strings, "colors.data") -- evaluated
+-- storage.register("colors/data", colors.strings, "colors.data") -- evaluated
--
-- We assume that only processcolors are defined in the format.
-input.storage.register(false,"colors/values", colors.values, "colors.values")
-input.storage.register(false,"colors/registered", colors.registered, "colors.registered")
+colors = colors or { }
+colors.data = colors.data or { }
+colors.values = colors.values or { }
+colors.registered = colors.registered or { }
+colors.enabled = true
+colors.weightgray = true
+colors.attribute = 0
+colors.selector = 0
+colors.default = 1
+colors.main = nil
+colors.triggering = true
+
+storage.register("colors/values", colors.values, "colors.values")
+storage.register("colors/registered", colors.registered, "colors.registered")
-colors.stamps = {
+local templates = {
rgb = "r:%s:%s:%s",
cmyk = "c:%s:%s:%s:%s",
gray = "s:%s",
spot = "p:%s:%s:%s:%s"
}
-colors.models = {
+local models = {
all = 1,
gray = 2,
rgb = 3,
@@ -549,158 +90,146 @@ colors.models = {
colors.model = "all"
-do
+local data = colors.data
+local values = colors.values
+local registered = colors.registered
- local min = math.min
- local max = math.max
+local numbers = attributes.numbers
+local list = attributes.list
- local function rgbdata(r,g,b) -- dodo: backends.pdf.rgbdata
- return backends.pdf.literal(format("%s %s %s rg %s %s %s RG",r,g,b,r,g,b))
- end
+local min = math.min
+local max = math.max
- local function cmykdata(c,m,y,k)
- return backends.pdf.literal(format("%s %s %s %s k %s %s %s %s K",c,m,y,k,c,m,y,k))
- end
+local nodeinjections = backends.nodeinjections
+local codeinjections = backends.codeinjections
+local registrations = backends.registrations
- local function graydata(s)
- return backends.pdf.literal(format("%s g %s G",s,s))
- end
-
- local function spotdata(n,f,d,p)
- if type(p) == "string" then
- p = p:gsub(","," ") -- brr misuse of spot
- end
- return backends.pdf.literal(format("/%s cs /%s CS %s SCN %s scn",n,n,p,p))
- end
+local function rgbtocmyk(r,g,b) -- we could reduce
+ return 1-r, 1-g, 1-b, 0
+end
- local function rgbtocmyk(r,g,b) -- we could reduce
- return 1-r, 1-g, 1-b, 0
- end
+local function cmyktorgb(c,m,y,k)
+ return 1.0 - min(1.0,c+k), 1.0 - min(1.0,m+k), 1.0 - min(1.0,y+k)
+end
- local function cmyktorgb(c,m,y,k)
- return 1.0 - min(1.0,c+k), 1.0 - min(1.0,m+k), 1.0 - min(1.0,y+k)
+local function rgbtogray(r,g,b)
+ if colors.weightgray then
+ return .30*r+.59*g+.11*b
+ else
+ return r/3+g/3+b/3
end
+end
- local function rgbtogray(r,g,b)
- if colors.weightgray then
- return .30*r+.59*g+.11*b
- else
- return r/3+g/3+b/3
- end
- end
+local function cmyktogray(c,m,y,k)
+ return rgbtogray(cmyktorgb(c,m,y,k))
+end
- local function cmyktogray(c,m,y,k)
- return rgbtogray(cmyktorgb(c,m,y,k))
- end
+colors.rgbtocmyk = rgbtocmyk
+colors.rgbtogray = rgbtogray
+colors.cmyktorgb = cmyktorgb
+colors.cmyktogray = cmyktogray
- colors.rgbtocmyk = rgbtocmyk
- colors.rgbtogray = rgbtogray
- colors.cmyktorgb = cmyktorgb
- colors.cmyktogray = cmyktogray
+-- we can share some *data by using s, rgb and cmyk hashes, but
+-- normally the amount of colors is not that large; storing the
+-- components costs a bit of extra runtime, but we expect to gain
+-- some back because we have them at hand; the number indicates the
+-- default color space
- -- we can share some *data by using s, rgb and cmyk hashes, but
- -- normally the amount of colors is not that large; storing the
- -- components costs a bit of extra runtime, but we expect to gain
- -- some back because we have them at hand; the number indicates the
- -- default color space
+function colors.gray(s)
+ return { 2, s, s, s, s, 0, 0, 0, 1-s }
+end
- function colors.gray(s)
- return { 2, s, s, s, s, 0, 0, 0, 1-s }
- end
+function colors.rgb(r,g,b)
+ local s = rgbtogray(r,g,b)
+ local c, m, y, k = rgbtocmyk(r,g,b)
+ return { 3, s, r, g, b, c, m, y, k }
+end
- function colors.rgb(r,g,b)
- local s = rgbtogray(r,g,b)
- local c, m, y, k = rgbtocmyk(r,g,b)
- return { 3, s, r, g, b, c, m, y, k }
- end
+function colors.cmyk(c,m,y,k)
+ local s = cmyktogray(c,m,y,k)
+ local r, g, b = cmyktorgb(c,m,y,k)
+ return { 4, s, r, g, b, c, m, y, k }
+end
- function colors.cmyk(c,m,y,k)
- local s = cmyktogray(c,m,y,k)
- local r, g, b = cmyktorgb(c,m,y,k)
- return { 4, s, r, g, b, c, m, y, k }
- end
+--~ function colors.spot(parent,f,d,p)
+--~ return { 5, .5, .5, .5, .5, 0, 0, 0, .5, parent, f, d, p }
+--~ end
- --~ function colors.spot(parent,f,d,p)
- --~ return { 5, .5, .5, .5, .5, 0, 0, 0, .5, parent, f, d, p }
- --~ end
-
- function colors.spot(parent,f,d,p)
- if type(p) == "number" then
- local n = attributes.list[attributes.numbers.color][parent] -- hard coded ref to color number
- if n then
- local v = colors.values[n]
- if v then
- -- the via cmyk hack is dirty, but it scales better
- local c, m, y, k = p*v[6], p*v[7], p*v[8], p*v[8]
- local r, g, b = cmyktorgb(c,m,y,k)
- local s = cmyktogray(c,m,y,k)
- return { 5, s, r, g, b, c, m, y, k, parent, f, d, p }
- end
+function colors.spot(parent,f,d,p)
+ if type(p) == "number" then
+ local n = list[numbers.color][parent] -- hard coded ref to color number
+ if n then
+ local v = values[n]
+ if v then
+ -- the via cmyk hack is dirty, but it scales better
+ local c, m, y, k = p*v[6], p*v[7], p*v[8], p*v[8]
+ local r, g, b = cmyktorgb(c,m,y,k)
+ local s = cmyktogray(c,m,y,k)
+ return { 5, s, r, g, b, c, m, y, k, parent, f, d, p }
end
- else
- -- todo, multitone (maybe p should be a table)
end
- return { 5, .5, .5, .5, .5, 0, 0, 0, .5, parent, f, d, p }
+ else
+ -- todo, multitone (maybe p should be a table)
end
+ return { 5, .5, .5, .5, .5, 0, 0, 0, .5, parent, f, d, p }
+end
- function colors.reviver(n)
- local d = colors.data[n]
- if not d then
- local v = colors.values[n]
- if not v then
- local gray = graydata(0)
+function colors.reviver(n)
+ local d = data[n]
+ if not d then
+ local v = values[n]
+ if not v then
+ local gray = nodeinjections.graycolor(0)
+ d = { gray, gray, gray, gray }
+ logs.report("attributes","unable to revive color %s",n or "?")
+ else
+ local kind, gray, rgb, cmyk = v[1], nodeinjections.graycolor(v[2]), nodeinjections.rgbcolor(v[3],v[4],v[5]), nodeinjections.cmykcolor(v[6],v[7],v[8],v[9])
+ if kind == 2 then
d = { gray, gray, gray, gray }
- logs.report("attributes","unable to revive color %s",n or "?")
- else
- local kind, gray, rgb, cmyk = v[1], graydata(v[2]), rgbdata(v[3],v[4],v[5]), cmykdata(v[6],v[7],v[8],v[9])
- if kind == 2 then
- d = { gray, gray, gray, gray }
- elseif kind == 3 then
- d = { rgb, gray, rgb, cmyk }
- elseif kind == 4 then
- d = { cmyk, gray, rgb, cmyk }
- elseif kind == 5 then
- local spot = spotdata(v[10],v[11],v[12],v[13])
- d = { spot, gray, rgb, cmyk }
- end
+ elseif kind == 3 then
+ d = { rgb, gray, rgb, cmyk }
+ elseif kind == 4 then
+ d = { cmyk, gray, rgb, cmyk }
+ elseif kind == 5 then
+ local spot = nodeinjections.spotcolor(v[10],v[11],v[12],v[13])
+ d = { spot, gray, rgb, cmyk }
end
- colors.data[n] = d
end
- return d
+ data[n] = d
end
+ return d
+end
- function colors.filter(n)
- return concat(colors.data[n],":",5)
- end
-
- colors.none = graydata(0)
-
+function colors.filter(n)
+ return concat(data[n],":",5)
end
+colors.none = nodeinjections.graycolor(0)
+
function colors.setmodel(attribute,name)
colors.model = name
- colors.selector = attributes.numbers[attribute]
- colors.default = colors.models[name] or 1
+ colors.selector = numbers[attribute]
+ colors.default = models[name] or 1
return colors.default
end
function colors.register(attribute, name, colorspace, ...) -- passing 9 vars is faster
- local stamp = format(colors.stamps[colorspace], ...)
- local color = colors.registered[stamp]
+ local stamp = format(templates[colorspace],...)
+ local color = registered[stamp]
if not color then
- color = #colors.values+1
- colors.values[color] = colors[colorspace](...)
- colors.registered[stamp] = color
+ color = #values+1
+ values[color] = colors[colorspace](...)
+ registered[stamp] = color
colors.reviver(color)
end
if name then
- attributes.list[attributes.numbers[attribute]][name] = color -- not grouped, so only global colors
+ list[numbers[attribute]][name] = color -- not grouped, so only global colors
end
- return colors.registered[stamp]
+ return registered[stamp]
end
function colors.value(id)
- return colors.values[id]
+ return values[id]
end
shipouts.handle_color = nodes.install_attribute_handler {
@@ -709,7 +238,7 @@ shipouts.handle_color = nodes.install_attribute_handler {
initializer = states.initialize,
finalizer = states.finalize,
processor = states.selective,
- resolver = function(...) return colors.main end,
+ resolver = function() return colors.main end,
}
-- transparencies
@@ -722,51 +251,56 @@ transparencies.registered = transparencies.registered or { }
transparencies.data = transparencies.data or { }
transparencies.values = transparencies.values or { }
transparencies.enabled = false
-transparencies.template = "%s:%s"
transparencies.triggering = true
-input.storage.register(false, "transparencies/registered", transparencies.registered, "transparencies.registered")
-input.storage.register(false, "transparencies/values", transparencies.values, "transparencies.values")
+storage.register("transparencies/registered", transparencies.registered, "transparencies.registered")
+storage.register("transparencies/values", transparencies.values, "transparencies.values")
-function transparencies.reference(n)
- return backends.pdf.literal(format("/Tr%s gs",n))
+local registered = transparencies.registered
+local data = transparencies.data
+local values = transparencies.values
+local template = "%s:%s"
+
+local function reference(n)
+ reference = nodeinjections.transparency
+ return reference(n)
end
function transparencies.register(name,a,t)
- local stamp = format(transparencies.template,a,t)
- local n = transparencies.registered[stamp]
+ local stamp = format(template,a,t)
+ local n = registered[stamp]
if not n then
- n = #transparencies.data+1
- transparencies.data[n] = transparencies.reference(n)
- transparencies.values[n] = { a, t }
- transparencies.registered[stamp] = n
- states.collect(format("\\presetPDFtransparencybynumber{%s}{%s}{%s}",n,a,t)) -- too many, but experimental anyway
+ n = #data+1
+ data[n] = reference(n)
+ values[n] = { a, t }
+ registered[stamp] = n
+ registrations.transparency(n,a,t)
end
- return transparencies.registered[stamp]
+ return registered[stamp]
end
function transparencies.reviver(n)
- local d = transparencies.data[n]
+ local d = data[n]
if not d then
- local v = transparencies.values[n]
+ local v = values[n]
if not v then
- d = transparencies.reference(0)
+ d = reference(0)
logs.report("attributes","unable to revive transparency %s",n or "?")
else
- d = transparencies.reference(n)
- states.collect(format("\\presetPDFtransparencybynumber{%s}{%s}{%s}",n,v[1],v[2]))
+ d = reference(n)
+ registrations.transparency(n,v[1],v[2])
end
- transparencies.data[n] = d
+ data[n] = d
end
return d
end
-- check if there is an identity
-transparencies.none = transparencies.reference(0) -- for the moment the pdf backend does this
+transparencies.none = reference(0) -- for the moment the pdf backend does this
function transparencies.value(id)
- return transparencies.values[id]
+ return values[id]
end
shipouts.handle_transparency = nodes.install_attribute_handler {
@@ -783,8 +317,8 @@ overprints = overprints or { }
overprints.data = overprints.data or { }
overprints.enabled = false
-overprints.data[1] = backends.pdf.literal(format("/GSoverprint gs"))
-overprints.data[2] = backends.pdf.literal(format("/GSknockout gs"))
+overprints.data[1] = nodeinjections.overprint()
+overprints.data[2] = nodeinjections.knockout()
overprints.none = overprints.data[2]
@@ -793,12 +327,14 @@ overprints.registered = {
knockout = 2,
}
---~ input.storage.register(false, "overprints/registered", overprints.registered, "overprints.registered")
---~ input.storage.register(false, "overprints/data", overprints.data, "overprints.data")
+--~ storage.register("overprints/registered", overprints.registered, "overprints.registered")
+--~ storage.register("overprints/data", overprints.data, "overprints.data")
+
+local data = overprints.data
+local registered = overprints.registered
function overprints.register(stamp)
--- states.collect(texsprint(tex.ctxcatcodes,"\\initializePDFoverprint")) -- to be testd
- return overprints.registered[stamp] or overprints.registered.overprint
+ return registered[stamp] or registered.overprint
end
shipouts.handle_overprint = nodes.install_attribute_handler {
@@ -815,8 +351,8 @@ negatives = negatives or { }
negatives.data = negatives.data or { }
negatives.enabled = false
-negatives.data[1] = backends.pdf.literal(format("/GSpositive gs"))
-negatives.data[2] = backends.pdf.literal(format("/GSnegative gs"))
+negatives.data[1] = nodeinjections.positive()
+negatives.data[2] = nodeinjections.negative()
negatives.none = negatives.data[1]
@@ -826,7 +362,6 @@ negatives.registered = {
}
function negatives.register(stamp)
--- states.collect(texsprint(tex.ctxcatcodes,"\\initializePDFnegative")) -- to be testd
return negatives.registered[stamp] or negatives.registered.positive
end
@@ -838,7 +373,7 @@ shipouts.handle_negative = nodes.install_attribute_handler {
processor = states.process,
}
--- effects
+-- effects -- can be optimized
effects = effects or { }
effects.data = effects.data or { }
@@ -846,8 +381,8 @@ effects.registered = effects.registered or { }
effects.enabled = false
effects.stamp = "%s:%s:%s"
-input.storage.register(false, "effects/registered", effects.registered, "effects.registered")
-input.storage.register(false, "effects/data", effects.data, "effects.data")
+storage.register("effects/registered", effects.registered, "effects.registered")
+storage.register("effects/data", effects.data, "effects.data")
function effects.register(effect,stretch,rulethickness)
local stamp = format(effects.stamp,effect,stretch,rulethickness)
@@ -856,27 +391,18 @@ function effects.register(effect,stretch,rulethickness)
n = #effects.data+1
effects.data[n] = effects.reference(effect,stretch,rulethickness)
effects.registered[stamp] = n
- -- states.collect("") -- nothing
end
return effects.registered[stamp]
end
-backends.pdf.effects = {
- normal = 0,
- inner = 0,
- outer = 1,
- both = 2,
- hidden = 3,
-}
+-- valid effects: normal inner outer both hidden
function effects.reference(effect,stretch,rulethickness)
- -- always, no zero test (removed)
- rulethickness = number.dimenfactors["bp"]*rulethickness
- effect = backends.pdf.effects[effect] or backends.pdf.effects['normal']
- return backends.pdf.literal(format("%s Tc %s w %s Tr",stretch,rulethickness,effect)) -- watch order
+ effects.reference = nodeinjections.effect
+ return nodeinjections.effect(stretch,rulethickness,effect)
end
-effects.none = effects.reference(0,0,0) -- faster: backends.pdf.literal("0 Tc 0 w 0 Tr")
+effects.none = effects.reference(0,0,0)
shipouts.handle_effect = nodes.install_attribute_handler {
name = "effect",
@@ -891,15 +417,18 @@ shipouts.handle_effect = nodes.install_attribute_handler {
viewerlayers = viewerlayers or { }
viewerlayers.data = viewerlayers.data or { }
viewerlayers.registered = viewerlayers.registered or { }
-viewerlayers.stamp = "%s"
viewerlayers.enabled = false
-input.storage.register(false, "viewerlayers/registered", viewerlayers.registered, "viewerlayers.registered")
---~ input.storage.register(false, "viewerlayers/data", viewerlayers.data, "viewerlayers.data")
+storage.register("viewerlayers/registered", viewerlayers.registered, "viewerlayers.registered")
+--~ storage.register("viewerlayers/data", viewerlayers.data, "viewerlayers.data")
+
+local data = viewerlayers.data
+local registered = viewerlayers.registered
+local template = "%s"
local somedone = false
local somedata = { }
-local nonedata = backends.pdf.literal("EMC")
+local nonedata = nodeinjections.stoplayer()
function viewerlayers.none() -- no local
if somedone then
@@ -914,8 +443,8 @@ local function some(name)
local sd = somedata[name]
if not sd then
sd = {
- backends.pdf.literal(format("EMC /OC /%s BDC",name)),
- backends.pdf.literal(format( "/OC /%s BDC",name)),
+ nodeinjections.switchlayer(name),
+ nodeinjections.startlayer(name),
}
somedata[name] = sd
end
@@ -933,14 +462,14 @@ local function initializer(...)
end
viewerlayers.register = function(name)
- local stamp = format(viewerlayers.stamp,name)
- local n = viewerlayers.registered[stamp]
+ local stamp = format(template,name)
+ local n = registered[stamp]
if not n then
- n = #viewerlayers.data + 1
- viewerlayers.data[n] = function() return some(name) end
- viewerlayers.registered[stamp] = n
+ n = #data + 1
+ data[n] = function() return some(name) end -- slow but for the moment we don't store things in the format
+ registered[stamp] = n
end
- return viewerlayers.registered[stamp]
+ return registered[stamp] -- == n
end
shipouts.handle_viewerlayer = nodes.install_attribute_handler {
@@ -950,5 +479,3 @@ shipouts.handle_viewerlayer = nodes.install_attribute_handler {
finalizer = states.finalize,
processor = states.process,
}
-
---~ nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_viewerlayer", nil, "notail")
diff --git a/tex/context/base/attr-ini.tex b/tex/context/base/attr-ini.tex
index c9e4110e5..3997d546b 100644
--- a/tex/context/base/attr-ini.tex
+++ b/tex/context/base/attr-ini.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Attribute Macros / initialization}
+\writestatus{loading}{ConTeXt Attribute Macros / Initialization}
%D Although it's still somewhat experimental, here we introduce code
%D related to attributes.
@@ -20,63 +20,21 @@
\registerctxluafile{attr-ini}{1.001}
-\newcount\attdefcounter
-
-% \def\newattribute#1%
-% {\global\advance\attdefcounter\plusone
-% \global\attributedef#1\attdefcounter
-% \ctxlua{attributes.define("\strippedcsname#1",\number\attdefcounter)}}
-
-% \newattribute\statusattribute
-% \newattribute\colorattribute
-% \newattribute\skipattribute
-% \newattribute\penaltyattribute
-
-\newtoks \attributesresetlist
-
-\def\defineattribute[#1]% alternatively we can let lua do the housekeeping
- {\global\advance\attdefcounter\plusone
- \expandafter \xdef\csname :attr:#1\endcsname{\number\attdefcounter}%
- \global\expandafter\attributedef\csname @attr@#1\endcsname \attdefcounter
- \writestatus\m!systems{defining attribute #1 with number \the\attdefcounter}%
- \appendetoks\csname @attr@#1\endcsname\minusone\to\attributesresetlist
- \ctxlua{attributes.define("#1",\number\attdefcounter)}}
-
-% expandable so we can \edef them for speed
-
-\def\dosetattribute#1#2{\csname @attr@#1\endcsname#2\relax}
-\def\doresetattribute#1{\csname @attr@#1\endcsname\minusone}
-\def\dogetattribute #1{\number\csname @attr@#1\endcsname}
-\def\dogetattributeid#1{\csname :attr:#1\endcsname}
-
-\let\dompattribute\gobbletwoarguments
-
-\defineattribute[mark]
-% \defineattribute[status] % used ? maybe combine with
-\defineattribute[state]
-\defineattribute[trigger] % feature inheritance
-\defineattribute[skip]
-\defineattribute[penalty]
-
-\startruntimectxluacode
- nodes.trigger = \dogetattributeid{trigger}
-\stopruntimectxluacode
-
-% \defineattribute[ignore]
+\definesystemattribute[state]
+\definesystemattribute[skip]
+\definesystemattribute[penalty]
+\definesystemattribute[colormodel][global] % no reset
+\definesystemattribute[color]
+\definesystemattribute[transparency]
+\definesystemattribute[overprint]
+\definesystemattribute[negative]
+\definesystemattribute[effect]
+\definesystemattribute[viewerlayer]
+
+% \definesystemattribute[ignore]
%
% \edef\startignorecontent{\dosetattribute{ignore}\plusone}
% \edef\stopignorecontent {\doresetattribute{ignore}}
-%
-% \startruntimectxluacode
-% nodes.ignore = \dogetattributeid{ignore}
-% \stopruntimectxluacode
-
-% \dosetattribute{status}{1}
-
-% temp here / will be indirect ! just for testing
-
-\defineattribute[colormodel]
-\defineattribute[color]
% todo: no need for 'color' argument, we can set that once at startup; currently
% a bit inconsistent
@@ -106,8 +64,6 @@
% transparency
-\defineattribute[transparency]
-
\def\registertransparency#1#2#3%
{\setevalue{(ts:#1)}{\dosetattribute{transparency}{\ctxlua{tex.print(transparencies.register(#2,#3))}}}}
@@ -123,8 +79,6 @@
% overprint
-\defineattribute[overprint]
-
\def\registeroverprint#1#2%
{\setevalue{(os:#1)}{\dosetattribute{overprint}{\ctxlua{tex.print(overprints.register('#2'))}}}}
@@ -139,8 +93,6 @@
% negative
-\defineattribute[negative]
-
\def\registernegative#1#2%
{\setevalue{(ns:#1)}{\dosetattribute{negative}{\ctxlua{tex.print(negatives.register('#2'))}}}}
@@ -155,8 +107,6 @@
% effect
-\defineattribute[effect]
-
\def\registereffect#1#2#3% #2=stretch #3=rulethickness
{\setxvalue{(es:#1:#2:\number\dimexpr#3\relax)}%
{\dosetattribute{effect}{\ctxlua{tex.print(effects.register('#1',#2,\number\dimexpr#3\relax))}}}}
@@ -176,90 +126,25 @@
% viewerlayers
-\defineattribute[viewerlayer]
+% \def\registerviewerlayer#1#2% global !
+% {\setxvalue{(vl:#1)}{\dosetattribute{viewerlayer}{\ctxlua{tex.print(viewerlayers.register('#2'))}}}}
+%
+% \setevalue{(vl:)}{\doresetattribute{viewerlayer}}
+%
+% needs to work over stopitemize grouping etc
+
+\def\registerviewerlayer#1#2% global !
+ {\setxvalue{(vl:#1)}{\global\dosetattribute{viewerlayer}{\ctxlua{tex.print(viewerlayers.register('#2'))}}}}
-\def\registerviewerlayer#1#2%
- {\setevalue{(vl:#1)}{\dosetattribute{viewerlayer}{\ctxlua{tex.print(viewerlayers.register('#2'))}}}}
+\setevalue{(vl:)}{\global\doresetattribute{viewerlayer}}
-\setevalue{(vl:)}{\doresetattribute{viewerlayer}}
+%
\def\dotriggerviewerlayer
{\ctxlua{viewerlayers.enabled=true}%
\gdef\dotriggerviewerlayer##1{\csname(vl:##1)\endcsname}%
\dotriggerviewerlayer}
-% ugly solution for backend handling
-
-% \def\shipout
-% {%\writestatus{SHIPOUT}{CALLED AT PAGE \realfolio}%
-% \dowithnextbox
-% {\ctxlua{callbacks.push('hpack_filter',nodes.process_page)}%
-% %\writestatus{SHIPOUT}{START PACKAGING}%
-% \setbox\nextbox\hbox{\box\nextbox}%
-% %\writestatus{SHIPOUT}{STOP PACKAGING}%
-% \ctxlua{callbacks.pop('hpack_filter')}%
-% \primitive\shipout\box\nextbox}}
-
-% \def\shipout
-% {\dowithnextbox
-% {\ctxlua{nodes.process_page(tex.box[\number\nextbox])}%
-% \primitive\shipout\box\nextbox}}
-
-% Objects are processed indepently \unknown\ actually we may need a proper callback.
-
-\newbox\finalizedshipoutbox
-
-\def\finalizeobjectbox#1{\ctxlua{nodes.process_page(tex.box[\number#1])}}
-
-\def\finalizeshipoutbox#1% % hack till we have access to pdf backend
- {\global\setbox\finalizedshipoutbox\hbox{#1}%
- \finalizeobjectbox\finalizedshipoutbox
- \hbox{\ctxlua{states.flush()}\box\finalizedshipoutbox}}
-
-\let\normalshipout\shipout
-
-% tricky stuff:
-
-\newcount\attributeboxcount
-
-\edef\startinheritattributes{\dosetattribute {trigger}{1}}
-\edef\stopinheritattributes {\doresetattribute{trigger}}
-
-\def\doattributedcopy {\afterassignment\dodoattributedcopy\attributeboxcount}
-\def\doattributedbox {\afterassignment\dodoattributedbox \attributeboxcount}
-
-\def\dodoattributedcopy
- {\startinheritattributes
- \ifvbox\attributeboxcount
- \vbox{\unvcopy\attributeboxcount}%
- \else
- \hbox{\unhcopy\attributeboxcount}%
- \fi
- \stopinheritattributes}
-
-\def\dodoattributedbox
- {\startinheritattributes
- \ifvbox\attributeboxcount
- \vbox{\unvbox\attributeboxcount}%
- \else
- \hbox{\unhbox\attributeboxcount}%
- \fi
- \stopinheritattributes}
-
-\def\enableattributeinheritance
- {\ctxlua{nodes.triggering=true}%
- \let\attributedcopy\doattributedcopy
- \let\attributedbox \doattributedbox}
-
-\def\disableattributeinheritance
- {\ctxlua{nodes.triggering=false}%
- \let\attributedcopy\copy
- \let\attributedbox \box}
-
-\disableattributeinheritance
-
-% \enableattributeinheritance % will become default
-
\protect \endinput
% test case
diff --git a/tex/context/base/back-ini.lua b/tex/context/base/back-ini.lua
new file mode 100644
index 000000000..0a11c2ef7
--- /dev/null
+++ b/tex/context/base/back-ini.lua
@@ -0,0 +1,75 @@
+if not modules then modules = { } end modules ['back-ini'] = {
+ version = 1.001,
+ comment = "companion to back-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+backends = backends or { }
+
+local function nothing() return nil end
+
+backends.nodeinjections = {
+ rgbcolor = nothing,
+ cmykcolor = nothing,
+ graycolor = nothing,
+ spotcolor = nothing,
+ transparency = nothing,
+ overprint = nothing,
+ knockout = nothing,
+ positive = nothing,
+ negative = nothing,
+ effect = nothing,
+ startlayer = nothing,
+ stoplayer = nothing,
+ switchlayer = nothing,
+}
+
+backends.codeinjections = {
+ insertmovie = nothing,
+}
+
+backends.registrations = {
+ grayspotcolor = nothing,
+ rgbspotcolor = nothing,
+ cmykspotcolor = nothing,
+ grayindexcolor = nothing,
+ rgbindexcolor = nothing,
+ cmykindexcolor = nothing,
+ spotcolorname = nothing,
+ transparency = nothing,
+}
+
+local nodeinjections = backends.nodeinjections
+local codeinjections = backends.codeinjections
+local registrations = backends.registrations
+
+backends.current = "unknown"
+
+function backends.install(what)
+ if type(what) == "string" then
+ backends.current = what
+ what = backends[what]
+ if what then
+ local wi = what.nodeinjections
+ if wi then
+ for k, v in next, wi do
+ nodeinjections[k] = v
+ end
+ end
+ local wi = what.codeinjections
+ if wi then
+ for k, v in next, wi do
+ codeinjections[k] = v
+ end
+ end
+ local wi = what.registrations
+ if wi then
+ for k, v in next, wi do
+ registrations[k] = v
+ end
+ end
+ end
+ end
+end
diff --git a/tex/context/base/back-ini.tex b/tex/context/base/back-ini.tex
new file mode 100644
index 000000000..a60b6a329
--- /dev/null
+++ b/tex/context/base/back-ini.tex
@@ -0,0 +1,896 @@
+%D \module
+%D [ file=back-ini,
+%D version=2009.04.15,
+%D title=\CONTEXT\ Backend Macros,
+%D subtitle=Initialization,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Backend Macros / Initialization}
+
+\registerctxluafile{back-ini}{1.001}
+
+%D We currently have a curious mix between tex and lua backend
+%D handling but eventually most will move to lua.
+
+\unprotect
+
+%D Right from the start \CONTEXT\ had a backend system based on
+%D runtime pluggable code. As most backend issues involved specials
+%D and since postprocessors had not that much in common, we ended up
+%D with a system where we could switch backend as well as output code
+%D for multiple backends at the same time.
+%D
+%D Because \LUATEX\ has the backend built in, and since some backend
+%D issues have been moved to the frontend I decided to provide new
+%D backend code for \MKIV, starting with what was actually used.
+%D
+%D At this moment \DVI\ is no longer used for advanced document
+%D output and we therefore dropped support for this format. Future
+%D versions might support more backends again, but this has a low
+%D priority.
+%D
+%D The big question is: what is to be considered a backend issue and
+%D what not. For the moment we treat image inclusion, object reuse,
+%D position tracking and color as frontend issues, if only because we
+%D deal with them via \LUA\ code and as such we don't depend too much
+%D on macro calls that need to inject code for the backend.
+%D
+%D Not everything here makes sense and the content of this file will
+%D definitely change.
+
+%D We use a couple of (global) variables because it saves us the
+%D trouble of dealing with arguments.
+
+\letempty \@@DriverFieldName
+\letempty \@@DriverFieldWidth
+\letempty \@@DriverFieldHeight
+\letempty \@@DriverFieldDefault
+\letempty \@@DriverFieldNumber
+\letempty \@@DriverFieldNumber
+\letempty \@@DriverFieldStyle
+\letempty \@@DriverFieldColor
+\letempty \@@DriverFieldBackgroundColor
+\letempty \@@DriverFieldFrameColor
+\letempty \@@DriverFieldLayer
+\letempty \@@DriverFieldOption
+\letempty \@@DriverFieldAlign
+\letempty \@@DriverFieldClickIn
+\letempty \@@DriverFieldClickOut
+\letempty \@@DriverFieldRegionIn
+\letempty \@@DriverFieldRegionOut
+\letempty \@@DriverFieldAfterKey
+\letempty \@@DriverFieldFormat
+\letempty \@@DriverFieldValidate
+\letempty \@@DriverFieldCalculate
+\letempty \@@DriverFieldFocusIn
+\letempty \@@DriverFieldFocusOut
+
+\letempty \@@DriverCommentLayer
+\letempty \@@DriverAttachmentLayer
+
+\letempty \@@DriverImageBox
+\letempty \@@DriverImageOptions
+\letempty \@@DriverImageWidth
+\letempty \@@DriverImageHeight
+\letempty \@@DriverImageFile
+\letempty \@@DriverImageLabel
+\letempty \@@DriverImageType
+\letempty \@@DriverImageMethod
+\letempty \@@DriverImagePage
+
+\newif\ifcollectreferenceactions
+
+%D \macros
+%D {dostartgraymode,dostopgraymode,
+%D dostartrgbcolormode,dostartcmykcolormode,dostartgraycolormode,dostopcolormode}
+%D
+%D Switching to and from color can be done in two ways:
+%D
+%D \startitemize[packed,n]
+%D \item insert driver specific commands
+%D \item pass instructions to the output device
+%D \stopitemize
+%D
+%D The first approach is more general and lays the
+%D responsibility at the driver side. Probably due to the fact
+%D that \TEX\ does not directly support color, we have been
+%D confronted for the last few years with changing special
+%D definitions. The need for support depends on how a macro
+%D package handles colored text that crosses the page boundary.
+%D Again, there are two approaches.
+%D
+%D \startitemize[packed,n]
+%D \item let \TEX\ do the job
+%D \item let the driver handle things
+%D \stopitemize
+%D
+%D The first approach is as driver independant as possible and
+%D can easily be accomplished by using \TEX's mark mechanism.
+%D In \CONTEXT\ we follow this approach. More and more, drivers
+%D are starting to support color, including stacking them.
+%D
+%D Colors as well as grayscales can be represented in scales
+%D from~0 to~1. When drivers use values in the range 0..255,
+%D this value has to be adapted in the translation process.
+%D Technically it's possible to get a grayscale from combining
+%D colors. In the \cap{RGB} color system, a color with Red,
+%D Green and Blue components of 0.80 show the same gray as a
+%D Gray Scale specified 0.80. The \cap{CMYK} color system
+%D supports a Black component apart from Cyan, Magenta and
+%D Yellow.
+%D
+%D Depending on the target format, color support differs from
+%D gray support. PostScript for example offers different
+%D operators for setting gray and color. This is because
+%D printing something using three colors is someting else than
+%D printing with just black.
+%D
+%D In \CONTEXT\ we have implemented a color subsystem that
+%D supports the use of well defined colors that, when printed
+%D in black and white, still can be distinguished. This
+%D approach enables us to serve both printed and electronic
+%D versions, using colored text and illustrations. More on the
+%D fundamentals of this topic can be found in the \cap{MAPS} of
+%D the Dutch User Group, 14 (95.1).
+%D
+%D To satisfy all those needs, we define four specials which
+%D supply enough information for drivers to act upon. We
+%D could have used more general commands with the keywords
+%D 'rgb' and 'gray', but because these specials are used often,
+%D we prefer the more direct and shorter alternative.
+%D
+%D We start with the installation of color and grayscale
+%D specials. The values are in the range 0..1 (e.g. 0.25).
+%D
+%D \starttyping
+%D \dostartgraymode {gray} ... \dostopgraymode
+%D \dostartrgbcolormode {red} {green} {blue} ... \dostopcolormode
+%D \dostartcmykcolormode {cyan} {magenta} {yellow} {black} ... \dostopcolormode
+%D \dostartgraycolormode {gray} ... \dostopcolormode
+%D \stoptyping
+%D
+%D Because we can expect conflicts between drivers, we
+%D implement them as category \type{or}. In previous versions
+%D of \DVIPSONE\ the use of their color||specials did not
+%D interfere with the PostScript ones, but recent versions do.
+
+\let \dostartgraymode \gobbleoneargument
+\let \dostopgraymode \donothing
+\let \dostartrgbcolormode \gobblethreearguments
+\let \dostartcmykcolormode \gobblefourarguments
+\let \dostartgraycolormode \gobbleoneargument
+\let \dostopcolormode \donothing
+\let \dostartspotcolormode \gobbletwoarguments
+\let \doregisterrgbspotcolor \gobblesevenarguments
+\let \doregistercmykspotcolor \gobbleeightarguments
+\let \doregistergrayspotcolor \gobblefourarguments
+\let \doregisterrgbindexcolor \gobblesevenarguments
+\let \doregistercmykindexcolor \gobbleeightarguments
+\let \doregistergrayindexcolor \gobblefourarguments
+\let \doregisterspotcolorname \gobbletwoarguments
+\let \dostartnonecolormode \donothing
+\let \doregisternonecolor \donothing
+
+%D \macros
+%D {doinsertsoundtrack}
+%D
+%D Sounds are (for the moment) just files with
+%D associated options.
+%D
+%D \starttyping
+%D \doinsertsoundtrack {file} {label} {options}
+%D \stoptyping
+
+\let \doinsertsoundtrack \gobblethreearguments
+
+%D \macros
+%D {dostartrotation,dostoprotation,
+%D dostartscaling,dostopscaling,
+%D dostartmirroring,dostopmirroring,
+%D dostartnegative,dostopnegative}
+%D dostartoverprint,dostopoverprint}
+%D
+%D We support a couple of transformations and renderings:
+%D
+%D \starttyping
+%D \dostartrotation {angle} ... \dostoprotation
+%D \dostartscaling {x} {y} ... \dostopscaling
+%D \dostartmirroring {x} {y} ... \dostopmirroring
+%D \stoptyping
+
+\let \dostartrotation \gobbleoneargument
+\let \dostoprotation \donothing
+\let \dostartscaling \gobbletwoarguments
+\let \dostopscaling \donothing
+\let \dostartmirroring \donothing
+\let \dostopmirroring \donothing
+
+\let \dostartnegative \donothing
+\let \dostopnegative \donothing
+\let \dostartoverprint \donothing
+\let \dostopoverprint \donothing
+
+%D The following two specials are used in for instance \type
+%D {\vadjust}'d margin material inside colored paragraphs.
+
+\let \dostartgraphicgroup \donothing
+\let \dostopgraphicgroup \donothing
+
+%D \macros
+%D {doselectfirstpaperbin,
+%D doselectsecondpaperbin}
+%D
+%D Here are some very printer||specific ones. No further
+%D comment.
+
+\let \doselectfirstpaperbin \donothing
+\let \doselectsecondpaperbin \donothing
+
+%D \macros
+%D {doovalbox}
+%D
+%D When we look at the implementation, this is a complicated
+%D one. There are seven arguments.
+%D
+%D \starttyping
+%D \doovalbox {w} {h} {d} {linewidth} {radius} {stroke} {fill} {variant}
+%D \stoptyping
+%D
+%D This command has to return a \type{\vbox} which can be used
+%D to lay over another one (with text). The radius is in
+%D degrees, the stroke and fill are~\type{1} (true) of~\type{0}
+%D (false).
+
+\let \doovalbox \gobbleeightarguments
+
+%D \macros
+%D {dostartclipping,dostopclipping}
+%D
+%D Clipping is implemented in such a way that an arbitrary code
+%D can be fed.
+%D
+%D \starttyping
+%D \dostartclipping {pathname} {width} {height}
+%D \dostopclipping
+%D \stoptyping
+
+\let \dostartclipping \gobblethreearguments
+\let \dostopclipping \donothing
+
+%D \macros
+%D {dosetupidentity}
+%D
+%D We can declare some characteristics of the document with
+%D
+%D \starttyping
+%D \dosetupidentity {title} {subject} {author} {creator} {date} {keys}
+%D \stoptyping
+%D
+%D All data is in string format.
+
+\let \dosetupidentity \gobblesixarguments
+
+%D \macros
+%D {dosetuppaper}
+%D
+%D This special can be used to tell the driver what page size
+%D to use. The special takes three arguments.
+%D
+%D \starttyping
+%D \dosetuppaper {type} {width} {height}
+%D \stoptyping
+%D
+%D The type is one of the common identifiers, like A4, A5 or
+%D B2.
+
+\let \dosetuppaper \gobblethreearguments
+
+%D \macros
+%D {dosetupprinter}
+%D
+%D Some drivers enable the user to specify the paper type
+%D used and/or page dimensions to be taken into account.
+%D
+%D \starttyping
+%D \dosetupprinter {type} {hoffset} {voffset} {width} {height}
+%D \stoptyping
+%D
+%D The first argument is one of \type{letter}, \type{legal},
+%D \type{A4}, \type{A5} etc. The dimensions are in
+%D basepoints.
+
+\let \dosetupprinter \gobblefourarguments
+
+%D \macros
+%D {dosetupopenaction, dosetupclosaction,
+%D dosetupopenpageaction, dosetupclospageaction,
+%D dosetupinteraction,
+%D dosetupscreen,
+%D dosetupviewmode}
+%D
+%D Here come some obscure interactive commands. Probably the
+%D specs will change with the development of the macros that
+%D use them.
+%D
+%D The first ones can be used to set up the interaction.
+%D
+%D \starttyping
+%D \dosetupinteraction
+%D \stoptyping
+%D
+%D Normally this command does nothing but giving a message
+%D that some scheme is supported.
+%D
+%D \starttyping
+%D \dosetupstartaction
+%D \dosetupstopaction
+%D \stoptyping
+%D
+%D These two setup the actions to be executed when the document
+%D is opened and closed.
+%D
+%D The next commands sets up the page and screen. They are
+%D kind of related.
+%D
+%D \starttyping
+%D \dosetuppage {hoffset} {voffset} {width} {height} {options}
+%D \dosetupscreen {hoffset} {voffset} {width} {height} {options}
+%D \stoptyping
+%D
+%D The first four arguments are in points. Option~1 results in a
+%D full screen launch.
+%D
+%D \starttyping
+%D \dosetuppageview {keyword}
+%D \stoptyping
+%D
+%D For the moment we only support \type{fit}.
+
+\let \dosetupinteraction \donothing
+\let \dosetupopenaction \donothing
+\let \dosetupscreen \gobblefourarguments
+\let \dosetuppageview \gobbleoneargument
+\let \dosetupcloseaction \donothing
+\let \dosetupopenpageaction \donothing
+\let \dosetupclosepageaction \donothing
+\let \dosetuprenderingopenpageaction \donothing
+\let \dosetuprenderingclosepageaction \donothing
+\let \dosetupcropbox \gobblefourarguments
+\let \dosetuptrimbox \gobblefourarguments
+\let \dosetupartbox \gobblefourarguments
+\let \dosetupbleedbox \gobblefourarguments
+
+%D \macros
+%D {dostarthide,
+%D dostophide}
+%D
+%D Not every part of the screen is suitable for paper. Menus
+%D for instance have no meaning on an non||interactive medium.
+%D These elements are hidden by means of:
+%D
+%D \starttyping
+%D \dostarthide .. \dostophide
+%D \stoptyping
+
+\let \dostarthide \donothing
+\let \dostophide \donothing
+
+%D \macros
+%D {dostartgotolocation, dostopgotolocation,
+%D dostartgotorealpage, dostopgotorealpage}
+%D
+%D When we want to support hypertext buttons, again we have
+%D to deal with two concepts.
+%D
+%D \startitemize[packed,n]
+%D \item let \TEX\ highlight the text
+%D \item let the driver show us where to click
+%D \stopitemize
+%D
+%D The first approach is the most secure one. It gives us
+%D complete control over the visual appearance of hyper
+%D buttons. The second alternative lets the driver guess what
+%D part of the text needs highlighting. As long as we deal with
+%D not too complicated textual buttons, this is no problem.
+%D It's even a bit more efficient when we take long mid
+%D paragraph active regions into account. When we let \TEX\
+%D handle active sentences {\em for instance marked like this
+%D one}, we have to take care of line- and pagebreaks ourselve.
+%D However, it's no trivial matter to let a driver find out
+%D where things begin and end. Because most hyperlinks can be
+%D found in tables of contents and registers, the saving in
+%D terms of bytes can be neglected and the first approach is a
+%D clear winner.
+%D
+%D The most convenient way of cross||referencing is using named
+%D destinations. A more simple scheme is using page numbers as
+%D destinations. Because the latter alternative can often be
+%D implemented more efficient, and because we cannot be sure
+%D what scheme a driver supports, we always have to supply a
+%D pagenumber, even when we use named destinations.
+%D
+%D To enable a driver to find out what to make active, we have
+%D to provide begin and endpoints, so like with color, we use
+%D pairs of specials. The first scheme can be satisfied with
+%D proper dimensions of the areas to be made active.
+%D
+%D The interactive real work is done by the following four
+%D specials. The reason for providing the first one with both
+%D a label and a number, is a result of the quite poor
+%D implementation of \type{pdfmarks} in version 1.0 of
+%D Acrobat. Because only pagenumbers were supported as
+%D destination, we had to provide both labels (\DVIWINDO) and
+%D pagenumbers (\PDF). Some drivers use start stop pairs.
+%D
+%D \starttyping
+%D \dostartgotolocation {w} {h} {url} {file} {label} {page}
+%D \dostartgotorealpage {w} {h} {url} {file} {page}
+%D \stoptyping
+%D
+%D Their counterparts are:
+%D
+%D \starttyping
+%D \dostopgotolocation
+%D \dostopgotorealpage
+%D \stoptyping
+%D
+%D The internal alternative is used for system||generated
+%D links, the external one for user||generated links. The
+%D Uniform Resource Locator can be used to let the reader
+%D surf the net.
+
+\let \dostartgotolocation \gobblesixarguments
+\let \dostopgotolocation \donothing
+\let \dostartgotorealpage \gobblefourarguments
+\let \dostopgotorealpage \donothing
+
+%D One may wonder why jumps to page and location are not
+%D combined. By splitting them, we enable macro||packages to
+%D force the prefered alternative, while on the other hand
+%D drivers can pick up the alternative desired most.
+
+%D \macros
+%D {dostartgotoJS, doflushJSpreamble}
+%D
+%D Rather special is the option to include and execute
+%D JavaScript code. This is a typical \PDF\ option.
+%D
+%D \starttyping
+%D \dostartgotoJS {w} {h} {script}
+%D \stoptyping
+%D
+%D This not so standard \TEX\ feature should be used with
+%D care. Preamble scripts are flushed by
+%D
+%D \doflushJSpreamble {script}
+
+\let \dostartgotoJS \gobblethreearguments
+\let \dostopgotoJS \donothing
+\let \doflushJSpreamble \gobbleoneargument
+
+%D \macros
+%D {dostartthisislocation, dostopthisislocation,
+%D dostartthisisrealpage, dostopthisisrealpage}
+%D
+%D Before we can goto some location or page, we have to tell
+%D the system where it can be found. Because some drivers
+%D follow the \SGML\ approach of begin||end tags, we have to
+%D support pairs. A possible extension to this scheme is
+%D supplying coordinates for viewing the text.
+%D
+%D The opposite commands of \type{\dogotosomething} have only
+%D one argument:
+%D
+%D \starttyping
+%D \dostartthisislocation {label}
+%D \dostartthisisrealpage {page}
+%D \stoptyping
+%D
+%D These commands are accompanied by:
+%D
+%D \starttyping
+%D \dostopthisislocation
+%D \dostopthisisrealpage
+%D \stoptyping
+%D
+%D As with all interactive commands's they are installed as
+%D \type{and} category specials.
+
+\let \dostartthisislocation \gobbleoneargument
+\let \dostopthisislocation \donothing
+\let \dostartthisisrealpage \gobbleoneargument
+\let \dostopthisisrealpage \donothing
+
+%D In \CONTEXT\ we don't use the \type{\stopsomething}
+%D macros because we let \TEX\ take care of typographic
+%D issues.
+
+%D \macros
+%D {doresetgotowhereever}
+%D
+%D These and others need:
+
+\let \doresetgotowhereever \donothing
+
+%D \macros
+%D {dostartexecutecommand, dostopexecutecommand}
+%D
+%D The actual behavior of the next pair of commands depends
+%D much on the viewing engine. Therefore one cannot depend
+%D too much on their support.
+%D
+%D \starttyping
+%D \dostartexecutecommand {w} {h} {command} {options}
+%D \stoptyping
+%D
+%D At least the next commands are supported (more examples
+%D can be found in \type {spec-fdf.tex}:
+%D
+%D \startlinecorrection\setupalign[middle]\leavevmode
+%D \starttable[|l|l|]
+%D \HL
+%D \NC \bf command \NC \bf action \NC\SR
+%D \HL
+%D \NC first \NC go to the first page \NC\FR
+%D \NC previous \NC go to the previous page \NC\MR
+%D \NC next \NC go to the next page \NC\MR
+%D \NC last \NC go to the last page \NC\MR
+%D \NC backward \NC go back to the link list \NC\MR
+%D \NC forward \NC go forward in the link list \NC\MR
+%D \NC print \NC enter print mode \NC\MR
+%D \NC exit \NC exit viewer \NC\MR
+%D \NC close \NC close document \NC\MR
+%D \NC enter \NC enter viewer \NC\MR
+%D \NC help \NC show help on the viewer \NC\LR
+%D \HL
+%D \stoptable
+%D \stoplinecorrection
+%D
+%D Options are to be passed as a comma separated list of
+%D assignments.
+
+\let \dostartexecutecommand \gobblefourarguments
+\let \dostopexecutecommand \donothing
+
+%D \macros
+%D {dostartobject,
+%D dostopobject,
+%D doresetobjects,
+%D doinsertobject}
+%D
+%D Reuse of object can reduce the output filesize
+%D considerably. Reusable objects are implemented with:
+%D
+%D \starttyping
+%D \dostartobject{class}{name}{width}{height}{depth}
+%D some typeset material
+%D \dostopobject
+%D \stoptyping
+%D
+%D \starttyping
+%D \doinsertobject{class}{name}
+%D \stoptyping
+%D
+%D The savings can be huge in interactive texts. The next macro needs
+%D to be called after a graphic is inserted (in order to clean up
+%D global references).
+%D
+%D \starttyping
+%D \doresetobjects
+%D \stoptyping
+
+\let \dostartobject \gobblefourarguments
+\let \dostopobject \donothing
+\let \doinsertobject \gobbletwoarguments
+\let \doresetobjects \donothing
+
+%D \macros
+%D {doregisterfigure, doregisterfigurecolor}
+%D
+%D Images can be objects as well and it's up to the driver to
+%D handle this. Alternative images are also up to the driver,
+%D and the next macro tells the driver that the previous image
+%D is somehow followed by another and that both have to be
+%D handled together. This is a rather fuzzy model, but for the
+%D moment it suits its purpose: low res screen versions combined
+%D with high res printable ones.
+
+\let \doregisterfigure \gobbletwoarguments
+\let \doregisterfigurecolor \gobbleoneargument
+
+% %D \macros
+% %D {dogetobjectreference}
+% %D
+% %D For very special purposes, one can ask for the internal
+% %D reference to the object. Beware!
+%
+% \let \dogetobjectreference \gobblethreearguments
+%
+% %D The first argument is the name, the second a macro that
+% %D gets the associated value.
+
+%D \macros
+%D {dostartrunprogram, dostoprunprogram,
+%D dostartgotoprofile, dostopgotoprofile,
+%D dobeginofprofile,
+%D doendofprofile}
+%D
+%D These specials are still experimental. They are not yet
+%D supported by the programs the way they should be.
+%D
+%D {\em --- still undocumented ---}
+
+\let \dostartrunprogram \gobblefourarguments
+\let \dostoprunprogram \donothing
+\let \dostartgotoprofile \gobblethreearguments
+\let \dostopgotoprofile \donothing
+\let \dobeginofprofile \gobblefourarguments
+\let \doendofprofile \donothing
+
+%D \macros
+%D {doinsertbookmark}
+%D
+%D Bookmarks, that is viewer generated tables of contents, are
+%D a strange phenomena, mainly because \TEX\ can provide
+%D whatever kind of table in much better quality.
+
+\let \doinsertbookmark \gobblefourarguments
+
+%D This special is called as:
+%D
+%D \starttyping
+%D \doinstallbookmark {level} {nofsubentries} {text} {page} {open}
+%D \stoptyping
+%D
+%D This definition is very \PDF\ oriented, so for more
+%D information we kindly refer to the \PDF\ manuals.
+
+%D \macros
+%D {dosetpagetransition}
+%D
+%D In presentations, fancy page transitions can, at least for a
+%D short moment, let the audience focus at the screen. Like the
+%D previous one, this special is very \PDF.
+%D
+%D \starttyping
+%D \dosetpagetransition{dissolve}{0}
+%D \stoptyping
+%D
+%D Transitions have symbolic names, like dissolve, box, split,
+%D blinds, wipe and glitter. The second argument determines
+%D the wait time (unless zero).
+
+\let \dosetpagetransition \gobbletwoarguments
+
+%D \macros
+%D {dopresettextfield,dopresetlinefield,
+%D dopresetchoicefield,dopresetpopupfield,dopresetcombofield,
+%D dopresetbuttonfield,dopresetcheckfield,
+%D dopresetradiofield,dopresetradiorecord}
+%D
+%D The special drivers are programmed independant from their
+%D calling macros are thereby use the standard \TEX\ way of
+%D passing parameters. Unfortunately fields often have more
+%D than nine characteristics, so we pack some arguments in one.
+%D
+%D \starttyping
+%D \dopresettextfield / \dopresetlinefield
+%D {name} {width} {height} {default} {length}
+%D {style,color} {options} {alignment} {actions}
+%D
+%D \dopresetchoicefield / \dopresetpopupfield / \dopresetcombofield
+%D {name} {width} {height} {default}
+%D {style,color} {options} {values} {actions}
+%D
+%D \dopresetpushfield
+%D {name} {width} {height} {default}
+%D {options} {values} {actions}
+%D
+%D \dopresetcheckfield
+%D {name} {width} {height} {default}
+%D {options} {values} {actions}
+%D
+%D \dopresetradiofield
+%D {name} {width} {height} {default}
+%D {options} {parent} {values} {actions}
+%D
+%D \dopresetradiorecord
+%D {name} {top} {options} {kids} {actions}
+%D \stoptyping
+
+\let \dopresetlinefield \gobbleninearguments
+\let \dopresettextfield \gobbleninearguments
+\let \dopresetchoicefield \gobbleeightarguments
+\let \dopresetpopupfield \gobbleeightarguments
+\let \dopresetcombofield \gobbleeightarguments
+\let \dopresetpushfield \gobblesevenarguments
+\let \dopresetcheckfield \gobblesevenarguments
+\let \dopresetradiofield \gobbleeightarguments
+\let \dopresetradiorecord \gobblefourarguments
+
+%D \macros
+%D {dodefinefieldset,dogetfieldset,doiffieldset}
+%D
+%D Field sets, used in resetting and submitting, are handled
+%D by:
+
+\let \dodefinefieldset \gobbletwoarguments
+\let \dogetfieldset \gobbleoneargument
+\let \doiffieldset \gobbletwoarguments
+
+%D \macros
+%D {dosetfieldstatus}
+%D
+%D For practical reasons we set some field characteristics
+%D using:
+%D
+%D \starttyping
+%D \dosetfieldstatus {mode} {parent} {kids} {root}
+%D \stoptyping
+
+\let \dosetfieldstatus \gobblefourarguments
+
+%D with:
+
+\def\fieldlonermode {0} % no \chardef here
+\def\fieldparentmode{1} % no \chardef here
+\def\fieldchildmode {2} % no \chardef here
+\def\fieldcopymode {3} % no \chardef here
+
+%D \macros
+%D {doregistercalculationset}
+%D
+%D We can define a calculation order list with:
+%D
+%D \starttyping
+%D \doregistercalculationset {set identifier}
+%D \stoptyping
+
+\let \doregistercalculationset \gobbleoneargument
+
+%D \macros
+%D {doinsertcomment, doflushcomments}
+%D
+%D Not so much out of need, but to be complete, we also
+%D implement text annotations, so called comment:
+%D
+%D \starttyping
+%D \doinsertcomment
+%D {title} {width} {height} {color} {open} {symbol} {collect} {data}
+%D \stoptyping
+%D
+%D When enables, comments can be collected and flushed:
+%D
+%D \starttyping
+%D \doflushcomments
+%D \stoptyping
+
+\let \doinsertcomment \gobbleeightarguments
+\let \doflushcomments \donothing
+
+%D \macros
+%D {dostarttransparency,dostoptransparency}
+%D
+%D \starttyping
+%D \dostarttransparency{fraction}{type}
+%D \dostoptransparency
+%D \stoptyping
+%D
+%D Although in \CONTEXT\ transparency is closely integrated
+%D in the color drivers, in the end it is an independent
+%D feature.
+
+\let \dostarttransparency \gobbletwoarguments
+\let \dostoptransparency \donothing
+
+%D \macros
+%D {doattachfile}
+%D
+%D \starttyping
+%D \doattachfile{title}{width}{height}{depth}{color}{symbol}{filename}{source}
+%D \stoptyping
+
+\let \doattachfile \gobbleeightarguments
+
+%D Experimental (properties):
+
+\let \dostartviewerlayer \gobbleoneargument
+\let \dostopviewerlayer \donothing
+\let \dodefineviewerlayer \gobblefivearguments
+\let \domakeviewerlayerlist \gobbleoneargument
+
+\let \doinsertrenderingwindow \gobblefourarguments
+\let \doinsertrendering \gobblefourarguments
+\let \doinsertrenderingobject \gobblefourarguments
+\let \doinsertrenderingobject \gobblefourarguments
+
+\let \dostartfonteffect \gobblethreearguments
+\let \dostopfonteffect \donothing
+
+%D From now on, mapfile loading is also a special; we assume the
+%D more or less standard dvips syntax.
+
+\let \doresetmapfilelist \donothing
+\let \doloadmapfile \gobbletwoarguments % + - = | filename
+\let \doloadmapline \gobbletwoarguments % + - = | fileline
+
+%D \macros
+%D {ifusepagedestinations}
+%D
+%D In \PDF\ version 1.0 only page references were supported,
+%D while in \DVIWINDO\ 1.N only named references were accepted.
+%D Therefore \CONTEXT\ supports both methods of referencing. In
+%D \PDF\ version 1.1 named destinations arrived. Lack of
+%D continuous support of version 1.1 viewers for \MSDOS\
+%D therefore sometimes forces us to prefer page references. As
+%D a bonus, they are faster too and have no limitations. How
+%D fortunate we were having both mechanisms available when the
+%D version 3.0 (\PDF\ version 1.2) viewers proved to be too
+%D bugged to support named destinations.
+
+\newif\ifusepagedestinations
+
+%D \macros
+%D {ifhighlighthyperlinks}
+%D
+%D The next switch can be used to make user hyperlinks are
+%D not highlighted when clicked on.
+
+\newif\ifhighlighthyperlinks
+
+%D \macros
+%D {ifgotonewwindow}
+%D
+%D To make the {\em goto previous jump} feature more
+%D convenient when using more than one file, it makes sense
+%D to force the viewer to open a new window for each file
+%D opened.
+
+\newif\ifgotonewwindow
+
+%D \macros
+%D {jobsuffix}
+%D
+%D By default, \TEX\ produces \DVI\ files which can be
+%D converted to other filetypes. Sometimes it is handy to
+%D know what the target file will be. In other driver
+%D modules we wil set \type {\jobsuffix} to \type {pdf}.
+
+% this will become a mode
+
+\def\jobsuffix{pdf}
+
+\ifdefined\resetsystemmode \else
+ \let\setsystemmode \gobbleoneargument
+ \let\resetsystemmode\gobbleoneargument
+\fi
+
+\def\setjobsuffix#1%
+ {\resetsystemmode\jobsuffix
+ \edef\jobsuffix{#1}%
+ \setsystemmode\jobsuffix}
+
+%D \macros
+%D {everyresetspecials}
+%D
+%D Now what will this one do? We'll see in a few lines.
+
+\newtoks\everyresetspecials
+
+\appendtoksonce
+ \ifdefined\setjobsuffix\setjobsuffix{pdf}\fi
+\to \everyresetspecials
+
+\def\defineoutput{\dodoubleargument\dodefineoutput}
+
+\def\usespecials [#1]{}
+\def\dodefineoutput[#1][#2]{}
+\def\setupoutput [#1]{}
+
+\protect \endinput
diff --git a/tex/context/base/back-pdf.lua b/tex/context/base/back-pdf.lua
new file mode 100644
index 000000000..2488db7f7
--- /dev/null
+++ b/tex/context/base/back-pdf.lua
@@ -0,0 +1,189 @@
+if not modules then modules = { } end modules ['back-pdf'] = {
+ version = 1.001,
+ comment = "companion to back-pdf.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module implements a couple of cleanup methods. We need these
+in order to meet the specification. Watch the double
+parenthesis; they are needed because otherwise we would pass more
+than one argument to .
+--ldx]]--
+
+local type, next = type, next
+local char, byte, format, gsub = string.char, string.byte, string.format, string.gsub
+local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
+local texsprint, texwrite = tex.sprint, tex.write
+
+ctxcatcodes = tex.ctxcatcodes
+
+pdf = pdf or { } -- global
+
+backends.pdf = pdf -- registered
+
+function pdf.cleandestination(str)
+ texsprint((gsub(str,"[%/%#%<%>%[%]%(%)%-%s]+","-")))
+end
+
+function pdf.cleandestination(str)
+ texsprint((gsub(str,"[%/%#%<%>%[%]%(%)%-%s]+","-")))
+end
+
+function pdf.sanitizedstring(str)
+ texsprint((gsub(str,"([\\/#<>%[%]%(%)])","\\%1")))
+end
+
+function pdf.hexify(str)
+ texwrite("feff")
+ for b in utfvalues(str) do
+ if b < 0x10000 then
+ texwrite(format("%04x",b))
+ else
+ texwrite(format("%04x%04x",b/1024+0xD800,b%1024+0xDC00))
+ end
+ end
+end
+
+function pdf.utf8to16(s,offset) -- derived from j. sauter's post on the list
+ offset = (offset and 0x110000) or 0 -- so, only an offset when true
+ texwrite(char(offset+254,offset+255))
+ for c in utfvalues(s) do
+ if c < 0x10000 then
+ texwrite(char(offset+c/256,offset+c%256))
+ else
+ c = c - 0x10000
+ local c1, c2 = c / 1024 + 0xD800, c % 1024 + 0xDC00
+ texwrite(char(offset+c1/256,offset+c1%256,offset+c2/256,offset+c2%256))
+ end
+ end
+end
+
+pdf.nodeinjections = pdf.nodeinjections or { } -- we hash elsewhere
+pdf.codeinjections = pdf.codeinjections or { } -- we hash elsewhere
+pdf.registrations = pdf.registrations or { } -- we hash elsewhere
+
+local pdfliteral, register = nodes.pdfliteral, nodes.register
+
+local nodeinjections = pdf.nodeinjections
+local codeinjections = pdf.codeinjections
+local registrations = pdf.registrations
+
+function nodeinjections.rgbcolor(r,g,b)
+ return register(pdfliteral(format("%s %s %s rg %s %s %s RG",r,g,b,r,g,b)))
+end
+
+function nodeinjections.cmykcolor(c,m,y,k)
+ return register(pdfliteral(format("%s %s %s %s k %s %s %s %s K",c,m,y,k,c,m,y,k)))
+end
+
+function nodeinjections.graycolor(s)
+ return register(pdfliteral(format("%s g %s G",s,s)))
+end
+
+function nodeinjections.spotcolor(n,f,d,p)
+ if type(p) == "string" then
+ p = p:gsub(","," ") -- brr misuse of spot
+ end
+ return register(pdfliteral(format("/%s cs /%s CS %s SCN %s scn",n,n,p,p)))
+end
+
+function nodeinjections.transparency(n)
+ return register(pdfliteral(format("/Tr%s gs",n)))
+end
+
+function nodeinjections.overprint()
+ return register(pdfliteral("/GSoverprint gs"))
+end
+
+function nodeinjections.knockout()
+ return register(pdfliteral("/GSknockout gs"))
+end
+
+function nodeinjections.positive()
+ return register(pdfliteral("/GSpositive gs"))
+end
+
+function nodeinjections.negative()
+ return register(pdfliteral("/GSnegative gs"))
+end
+
+local effects = {
+ normal = 0,
+ inner = 0,
+ outer = 1,
+ both = 2,
+ hidden = 3,
+}
+
+function nodeinjections.effect(stretch,rulethickness,effect)
+ -- always, no zero test (removed)
+ rulethickness = number.dimenfactors["bp"]*rulethickness
+ effect = effects[effect] or effects['normal']
+ return register(pdfliteral(format("%s Tc %s w %s Tr",stretch,rulethickness,effect))) -- watch order
+end
+
+function nodeinjections.startlayer(name)
+ return register(pdfliteral(format("/OC /%s BDC",name)))
+end
+
+function nodeinjections.stoplayer()
+ return register(pdfliteral("EMC"))
+end
+
+function nodeinjections.switchlayer(name)
+ return register(pdfliteral(format("EMC /OC /%s BDC",name)))
+end
+
+-- code
+
+function codeinjections.insertmovie(spec) -- width, height, factor, repeat, controls, preview, label, foundname
+ local width, height = spec.width, spec.height
+ local options, actions = "", ""
+ if spec["repeat"] then
+ actions = actions .. "/Mode /Repeat "
+ end
+ if spec.controls then
+ actions = actions .. "/ShowControls true "
+ else
+ actions = actions .. "/ShowControls false "
+ end
+ if spec.preview then
+ options = options .. "/Poster true "
+ end
+ if actions ~= "" then
+ actions= "/A <<" .. actions .. ">>"
+ end
+ return format( -- todo: doPDFannotation
+ "\\doPDFannotation{%ssp}{%ssp}{/Subtype /Movie /Border [0 0 0] /T (movie %s) /Movie << /F (%s) /Aspect [%s %s] %s>> %s}",
+ width, height, spec.label, spec.foundname, factor * width, factor * height, options, actions
+ )
+end
+
+local s_template_g = "\\dodoPDFregistergrayspotcolor{%s}{%s}{%s}{%s}{%s}" -- n f d p s (p can go away)
+local s_template_r = "\\dodoPDFregisterrgbspotcolor {%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p r g b
+local s_template_c = "\\dodoPDFregistercmykspotcolor{%s}{%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p c m y k
+local m_template_g = "\\doPDFregistergrayindexcolor{%s}{%s}{%s}{%s}{%s}" -- n f d p s (p can go away)
+local m_template_r = "\\doPDFregisterrgbindexcolor {%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p r g b
+local m_template_c = "\\doPDFregistercmykindexcolor{%s}{%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p c m y k
+local s_template_e = "\\doPDFregisterspotcolorname{%s}{%s}" -- name, e -- todo in new backend: gsub(e," ","#20")
+local t_template = "\\presetPDFtransparencybynumber{%s}{%s}{%s}" -- n, a, t
+
+function registrations.grayspotcolor (n,f,d,p,s) states.collect(format(s_template_g,n,f,d,p,s)) end
+function registrations.rgbspotcolor (n,f,d,p,r,g,b) states.collect(format(s_template_r,n,f,d,p,r,g,b)) end
+function registrations.cmykspotcolor (n,f,d,p,c,m,y,k) states.collect(format(s_template_c,n,f,d,p,c,m,y,k)) end
+function registrations.grayindexcolor(n,f,d,p,s) states.collect(format(m_template_g,n,f,d,p,s)) end
+function registrations.rgbindexcolor (n,f,d,p,r,g,b) states.collect(format(m_template_r,n,f,d,p,r,g,b)) end
+function registrations.cmykindexcolor(n,f,d,p,c,m,y,k) states.collect(format(m_template_c,n,f,d,p,c,m,y,k)) end
+function registrations.spotcolorname (name,e) states.collect(format(s_template_e,name,e)) end -- texsprint(ctxcatcodes,format(s_template_e,name,e))
+function registrations.transparency (n,a,t) states.collect(format(t_template ,n,a,t)) end -- too many, but experimental anyway
+
+-- eventually we need to load this runtime
+--
+-- backends.install((environment and environment.arguments and environment.arguments.backend) or "pdf")
+--
+-- but now we need to force this as we also load the pdf tex part which hooks into all kind of places
+
+backends.install("pdf")
diff --git a/tex/context/base/back-pdf.tex b/tex/context/base/back-pdf.tex
new file mode 100644
index 000000000..b7de1051f
--- /dev/null
+++ b/tex/context/base/back-pdf.tex
@@ -0,0 +1,3226 @@
+%D \module
+%D [ file=back-pdf,
+%D version=2009.04.15,
+%D title=\CONTEXT\ Backend Macros,
+%D subtitle=\PDF,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Backend Macros / PDF}
+
+\registerctxluafile{back-pdf}{1.001}
+
+\unprotect
+
+%D When dealing with resources, we share the resource dictionaries
+%D between all xforms. This is inefficent in the sense that when no
+%D resources are used, redundant entries take space, but on the other
+%D hand we save redundant dictionaries so it's a nice compromise. Maybe
+%D that in \LUATEX\ I will reimplement most of the code here anyway.
+
+%D Initialization of fields is tricky. If a field has no
+%D value, it is kind of not there. If ResetForm is used, the
+%D default is assigned, but pushbuttons are spoiled. Adding a
+%D \type {/MK} dictionary helps, but gives ugly down
+%D appearances (displaced with background). What a mess.
+%D Also, in order to get at least something, the \type {/AS}
+%D key should be provided.
+
+%D A couple of variables:
+
+\newtoks \everybackendshipout
+\newtoks \everylastbackendshipout
+
+\let\lastPDFaction\empty
+
+\ifdefined\everyPDFximage \else \newtoks\everyPDFximage \fi
+\ifdefined\everyPDFxform \else \newtoks\everyPDFxform \fi
+\ifdefined\everygoto \else \newtoks\everygoto \fi
+\ifdefined\everysetfield \else \newtoks\everysetfield \fi
+
+%D A few helpers:
+
+\let\PDFcode \pdfliteral
+\def\PDFcontentcode{\pdfliteral}
+\def\PDFdirectcode {\pdfliteral direct}
+
+%D \macros
+%D {PDFobjref}
+%D
+%D Just a shortcut.
+
+% Watch out, \def\PDFobjref#1{\purenumber#1 0 R} also works, but not when
+% #1 == \the\whatever
+
+\def\PDFobjref#1{\purenumber{#1} 0 R}
+
+%D \macros
+%D {PDFswapdir}
+
+\let\PDFswapdir\empty \def\PDFswapdir{\ifcase\inlinedirection\or\or-\fi}
+
+% the pdf spec changed cq. viewers started behaving differently / 5+
+
+\chardef\overcomePDFpage\plusone % page numbers/ beware: optimizers remove this one
+\chardef\overcomePDFpage\plustwo % page:number
+\chardef\overcomePDFpage\plusthree % pdftex page ref feature
+
+%D \macros
+%D {setPDFdestination}
+%D
+%D \PDF\ destinations should obey the specifications laid down
+%D in the \PDF\ reference manual. The next macro strips illegal
+%D characters from the destination name.
+
+\def\setPDFdestination #1{\xdef\PDFdestination{\ctxlua{pdf.cleandestination("\luaescapestring{#1}")}}}
+\def\hexifiedPDFstring #1{\ctxlua{pdf.hexify("\luaescapestring{#1}")}}
+\def\sanitizePDFencoding#1\to#2{\xdef#2{\ctxlua{pdf.hexify("\luaescapestring{#1}")}}}
+
+%D
+
+\def\appendtopdfpageresources #1{\normalexpanded{\global\pdfpageresources{#1\the\pdfpageresources}}}
+\def\appendtopdfpageattributes #1{\normalexpanded{\global\pdfpageattr {#1\the\pdfpageattr }}}
+\def\appendtopdfpagesattributes#1{\normalexpanded{\global\pdfpagesattr {#1\the\pdfpagesattr }}}
+\def\appendtopdfcatalog {\pdfcatalog}
+\def\appendtopdfinfo {\pdfinfo}
+
+\def\resetpdfpageattributes{\global\pdfpageattr\emptytoks}
+\def\resetpdfpageresources {\global\pdfpageresources\emptytoks}
+
+%D Due to the fact that \PDFTEX\ has a different concept of
+%D page attributes, we need:
+
+\appendtoksonce
+ \resetpdfpageattributes
+ \resetpdfpageresources
+\to \everyaftershipout
+
+%D \macros
+%D {insertpdfaction,
+%D insertpdfannotation,
+%D insertpdfannotationobject,
+%D createpdfdictionaryobject,
+%D createpdfarrayobject,
+%D defaultobjectreference,
+%D doPDFgetobjectreference}
+%D
+%D This module deals with \PDF\ support, including fill||in
+%D forms. Before we present the largely unreadable bunch of
+%D macros, we introduce the here||not||defined low level
+%D interface macros. These must be provided by the special
+%D drivers \type{pdf} (\ACROBAT) and \type{tpd} (\PDFTEX).
+%D
+%D \starttyping
+%D \insertpdfaction #1#2#3 width height action
+%D \insertpdfannotation #1#2#3 width height data
+%D \createpdfannotationobject #1#2#3#4#5 class name width height data
+%D \createpdfdictionaryobject #1#2#3 class name data
+%D \createpdfarrayobject #1#2#3 class name data
+%D
+%D \defaultobjectreference #1#2 class name
+%D \doPDFgetobjectreference #1#2#3 class name \PDFobjectreference
+%D \doPDFgetobjectpagereference #1#2#3 class name \PDFobjectreference
+%D \stoptyping
+%D
+%D The keywords reflect their use. For the moment we stick to
+%D keywords, because that way at we get an indication of what
+%D we're doing.
+
+\def\createpdfdictionaryobject#1#2#3%
+ {\flushatshipout
+ {\immediate\pdfobj{<< #3 >>}%
+ \dosetobjectreference{#1}{#2}{\the\pdflastobj}}}
+
+\def\createpdfarrayobject#1#2#3%
+ {\flushatshipout
+ {\immediate\pdfobj{[ #3 ]}%
+ \dosetobjectreference{#1}{#2}{\the\pdflastobj}}}
+
+\def\createpdfannotationobject#1#2#3#4#5%
+ {\insertpdfannotation{#3}{#4}{#5}%
+ \dosetobjectreference{#1}{#2}{\the\pdflastannot}}
+
+\def\createpdfactionobject#1#2#3#4#5%
+ {\insertpdfaction{#3}{#4}{#5}%
+ \dosetobjectreference{#1}{#2}{\the\pdflastannot}}
+
+%D \macros
+%D {insertpdfaction,insertpdfannotation,ifsharePDFactions}
+%D
+%D Next we handle annotations. All link annotations are
+%D implemented using the action dictionary. This enables us to
+%D use multiple actions. The second macro is for instance
+%D used for movie inclusion.
+
+\newif\ifsharePDFactions \sharePDFactionstrue
+
+\def\insertpdfaction#1#2#3%
+ {\xdef\lastPDFcontent{#3}%
+ \ifcollectreferenceactions
+ \global\let\lastPDFaction\lastPDFcontent
+ \else
+ \ifsharePDFactions
+ \ifcase\similarreference\relax
+ \xdef\lastPDFaction{<<\lastPDFcontent>>}%
+ \or
+ \immediate\pdfobj{<<\lastPDFcontent>>}%
+ \xdef\lastPDFaction{\PDFobjref\pdflastobj}%
+ \else
+ % leave \lastPDFaction untouched
+ \fi
+ \else
+ \xdef\lastPDFaction{<<\lastPDFcontent>>}%
+ \fi
+ \pdfannot
+ width #1 height #2 depth \zeropoint
+ {/Subtype /Link
+ /Border [0 0 0]
+ \ifhighlighthyperlinks \else /H /N \fi
+ /A \lastPDFaction}%
+ \fi}
+
+\def\insertpdfannotation#1#2#3%
+ {\pdfannot width #1 height #2 depth \zeropoint{#3}}
+
+%D \macros
+%D {doPDFbookmark}
+%D
+%D Well, isn't the next one ugly? Thanks to the \PDF\
+%D standard.
+
+\def\doPDFbookmark#1#2#3#4#5% to be renamed
+ {\doPDFgetpagereference{#4}\PDFobjectreference
+ \pdfoutline
+ user {<>}%
+ \ifcase#2 \else count \ifcase#5-\fi#2 \fi
+ {#3}}
+
+%D For special (\METAPOST) effects, we need to build
+%D resource dictionaries. Here is the framework.
+
+\let\docuPDFextgstates \empty
+\let\docuPDFcolorspaces\empty
+\let\docuPDFshades \empty
+
+\def\checkPDFextgstates
+ {\ifx\docuPDFextgstates\empty \else
+ \ifnum\realpageno=\lastpage\relax
+ \createpdfdictionaryobject{FDF}{docuextgstates}{\docuPDFextgstates}%
+ \fi
+ \doPDFgetobjectreference{FDF}{docuextgstates}\PDFobjectreference
+ \appendtopdfpageresources{/ExtGState \PDFobjectreference}%
+ \fi}
+
+\def\checkPDFcolorspaces
+ {\ifx\docuPDFcolorspaces\empty \else
+ \ifnum\realpageno=\lastpage\relax
+ \createpdfdictionaryobject{FDF}{colorspaces}{\docuPDFcolorspaces}%
+ \fi
+ \doPDFgetobjectreference{FDF}{colorspaces}\PDFobjectreference
+ \appendtopdfpageresources{/ColorSpace \PDFobjectreference}%
+ \fi}
+
+\def\checkPDFshades
+ {\ifx\docuPDFshades\empty \else
+ \ifnum\realpageno=\lastpage\relax
+ \createpdfdictionaryobject{FDF}{docushades}{\docuPDFshades}%
+ \fi
+ \doPDFgetobjectreference{FDF}{docushades}\PDFobjectreference
+ \appendtopdfpageresources{/Shading \PDFobjectreference}%
+ \fi}
+
+\def\appendtoPDFdocumentextgstates #1{\xdef\docuPDFextgstates {\docuPDFextgstates \space#1}}
+\def\appendtoPDFdocumentcolorspaces#1{\xdef\docuPDFcolorspaces{\docuPDFcolorspaces\space#1}}
+\def\appendtoPDFdocumentshades #1{\xdef\docuPDFshades {\docuPDFshades \space#1}}
+
+%D Page actions:
+
+\let\lastpdfopenaction \empty
+\let\lastpdfcloseaction\empty
+
+\def\dosetupopenaction {\appendtopdfcatalog{/OpenAction <<\lastPDFaction>>}}
+\def\dosetupcloseaction{\appendtopdfcatalog{/CloseAction <<\lastPDFaction>>}}
+
+\def\dosetupopenpageaction {\glet\lastpdfopenaction \lastPDFaction}
+\def\dosetupclosepageaction{\glet\lastpdfcloseaction\lastPDFaction}
+
+\def\checkPDFpageactions
+ {\iflocation % important since direct
+ \donefalse
+ \ifx\lastpdfopenaction \empty\!!doneafalse\else\donetrue\!!doneatrue\fi
+ \ifx\lastpdfcloseaction\empty\!!donebfalse\else\donetrue\!!donebtrue\fi
+ \ifdone
+ \appendtopdfpageattributes
+ {/AA <<\if!!donea/O <<\lastpdfopenaction >> \fi
+ \if!!doneb/C <<\lastpdfcloseaction>> \fi>>}%
+ \fi
+ \glet\lastpdfopenaction \empty
+ \glet\lastpdfcloseaction\empty
+ \fi}
+
+%D \macros
+%D {ifPDFstrokecolor}
+%D
+%D We can reduce the filesize a bit by setting the next switch
+%D to false. The amount of reduction depends on the use of
+%D color, but don't expect more than a few percent. Zip
+%D compression is already rather efficient in itself.
+
+\newif\ifPDFstrokecolor \PDFstrokecolortrue
+
+%D When submitting forms, we need to communicate the format.
+
+\chardef\submitoutputformat=0 % 0=unknown 1=HTML 2=FDF 3=XML
+
+\def\setsubmitoutputformat#1%
+ {\doifinsetelse{#1}{FDF,fdf}
+ {\chardef\submitoutputformat2}
+ {\doifinsetelse{#1}{XML,xml}
+ {\chardef\submitoutputformat3}
+ {\chardef\submitoutputformat1}}%
+ \relax}
+
+%D Handy to have this available asap:
+
+\ifdefined\everyPDFxform \newtoks\everyPDFxform \fi
+\ifdefined\everyPDFximage \newtoks\everyPDFximage \fi
+
+% once we can be sure that the latest versions of pdftex are
+% available we can use:
+%
+% \pdfobj reserveobjnum \edef\one{\the\pdflastobj}
+% \pdfobj reserveobjnum \edef\two{\the\pdflastobj}
+%
+% \pdfobj useobjnum \one {x}
+% \pdfobj useobjnum \two {x}
+%
+% we then can rewrite part of spec-fdf because the other drivers
+% already support symbolic references
+
+%D \macros
+%D {jobsuffix}
+%D
+%D Being one of the first typographical systems able to support
+%D advances \PDF\ support, \TEX\ is also one of the first
+%D systems to produce high quality \PDF\ code directly. Thanks
+%D to Han The Thanh c.s. the \TEX\ community can leap forward
+%D once again.
+%D
+%D One important characteristic of \PDFTEX\ is that is can
+%D produce standard \DVI\ code as well as \PDF\ code. This
+%D enables us to use one format file to support both output
+%D formats.
+
+%D All modules in this group use specials to tell drivers what
+%D non||\TEX\ actions to take. Because from the \TEX\ point of
+%D view, there is no difference between \DVI\ and \PDF, we
+%D therefore only have to bend the \DVI\ driver support into
+%D \PDF\ support. Technically spoken, specials no longer serve
+%D a purpose, except from ending up as comment in the \PDF\
+%D file.
+%D
+%D Before we continue we need to make sure if indeed those
+%D \PDFTEX\ primitives are permitted. If no primitives are
+%D available, we just stop reading any further.
+
+\pdfoutput = 1
+\pdfhorigin = 1 true in
+\pdfvorigin = 1 true in
+\pdfimageresolution = 300
+\pdfpkresolution = 600
+\pdfdecimaldigits = 10
+\pdfinclusionerrorlevel = 0
+\pdfminorversion = 5
+%pdfuniqueresname = 1
+
+\def\PDFversion{1.\number\pdfminorversion}
+
+%D For some internal testing we need to know the output
+%D suffix.
+
+\setjobsuffix{pdf}
+
+%D \macros
+%D {dosetuppaper}
+%D
+%D If we don't set the paper size, \PDFTEX\ will certainly do
+%D it in a way we don't want, therefore we need:
+
+\def\dosetuppaper#1#2#3%
+ {\global\pdfpagewidth #2\relax
+ \global\pdfpageheight#3\relax}
+
+%D \macros
+%D {doloadmapfile,doloadmapline,doresetmapfilelist}
+
+\def\doresetmapfilelist
+ {\global\let\doresetmapfilelist\relax
+ \pdfmapfile{original-empty.map}}
+
+\def\doloadmapfile #1#2{\pdfmapfile{#1#2}}
+\def\doloadmapline #1#2{\pdfmapline{#1#2}}
+
+%D nasty but needed
+
+\appendtoksonce \loadallfontmapfiles \to \everyPDFximage
+\appendtoksonce \loadallfontmapfiles \to \everyPDFxform
+
+%D left overs:
+
+ \let\currentmovie\s!unknown
+
+ \def\doPDFinsertmov
+ {\bgroup
+ \xdef\currentmovie{\@@DriverImageLabel}%
+ \PointsToBigPoints\@@DriverImageWidth \width
+ \PointsToBigPoints\@@DriverImageHeight\height
+ \let\pdf@@options\empty
+ \let\pdf@@actions\empty
+ \donefalse
+ \expanded{\processallactionsinset[\@@DriverImageOptions]}
+ [\v!controls=>\donetrue,
+ \v!repeat=>\edef\pdf@@actions{\pdf@@actions /Mode /Repeat },
+ \v!preview=>\edef\pdf@@options{\pdf@@options /Poster true }]%
+ \edef\pdf@@actions{\pdf@@actions /ShowControls \ifdone true\else false\fi}%
+ \insertpdfannotation\@@DriverImageWidth\@@DriverImageHeight
+ {/Subtype /Movie
+ /Border [0 0 0]
+ /T (movie \currentmovie)
+ /Movie << /F (\@@DriverImageFile) /Aspect [\width\space\height] \pdf@@options >>
+ /A << \pdf@@actions >>}%
+ \egroup}
+
+%D \macros
+%D {doinsertsoundtrack}
+%D
+%D We use numbers instead of labels to keep track of sounds.
+
+\let\currentsound\s!unknown
+
+\def\doinsertsoundtrack#1#2#3%
+ {\bgroup
+ \xdef\currentsound{#2}%
+ \let\pdf@@actions\empty
+ \@EA\processallactionsinset\@EA
+ [#3]
+ [\v!repeat=>\edef\pdf@@actions{\pdf@@actions /Mode /Repeat }]%
+ \collectdriverresource
+ %\flushatshipout % since it can be buried in a chained box
+ {\insertpdfannotation{0pt}{0pt}
+ {/Subtype /Movie
+ /Border [0 0 0]
+ /T (sound \currentsound)
+ /Movie <>%
+ \ifx\pdf@@actions\empty\else/A << \pdf@@actions >>\fi}}%
+ \egroup}
+
+%D \macros
+%D {doPDFattachfile}
+
+\def\doPDFfilestreamobject#1#2#3#4%
+ {}
+
+\def\doPDFfilestreamidentifier#1%
+ {0}
+
+\def\doPDFgetfilestreamreference#1#2%
+ {0 0 R}
+
+\def\doattachfile#1#2#3#4#5#6#7#8%
+ {\bgroup % title width height color symbol file
+ \edefconvertedargument\PDFfile{#8}%
+ % beware: the symbol may (indirectly) use the file
+ % reference when typesetting the object number;
+ \presetPDFsymbolappearance{#5}{#6}{#2}{#3}{#4}% sets width/height
+ \startPDFsymbolappearance
+ \doPDFembedfile\PDFfile{#7}{#8}%
+ \doPDFgetembeddedfilereference\PDFfile\PDFobjectreference
+ \setFDFlayer\@@DriverAttachmentLayer
+ \insertpdfannotation{\width}{\totalheight}
+ {/Subtype /FileAttachment
+ /FS \PDFobjectreference\space
+ /Contents (#1)
+ \PDFsymbol
+ \FDFlayer
+ \PDFattributes}%
+ \stopPDFsymbolappearance
+ \egroup}
+
+% semi-public
+
+\def\doPDFembedfile#1#2#3% symbolic name | filename | user name
+ {\edefconvertedargument\PDFfile{#1}%
+ \doifnotflagged{a:\PDFfile}%
+ {\doPDFfilestreamobject{PDFEF}{\PDFfile}{#2}{#3}%
+ \doglobal\setflag{a:\PDFfile}}}
+
+\def\doPDFgetembeddedfilereference#1#2%
+ {\edefconvertedargument\PDFfile{#1}%
+ \doPDFgetobjectreference{PDFEF}\PDFfile#2}
+
+\def\doPDFgetembeddedfilestreamreference#1#2%
+ {\edefconvertedargument\PDFfile{#1}%
+ \doPDFgetfilestreamreference\PDFfile#2} % == \doPDFgetobjectreference{PDFFS}\PDFfile#2
+
+% requested by Jens-Uwe Morawski: permits usage of pdftosrc
+% in viewers that don't support attachments:
+%
+% \definesymbol
+% [ObjectNumber]
+% % [object number {\PDFattachmentnumber[xx]}] % named
+% [object number \PDFattachmentnumber] % current
+%
+% \useattachment[test][xx][test.tex]
+% \setupattachments[symbol=ObjectNumber]
+% \attachment[test]
+
+\def\PDFattachmentnumber
+ {\dosingleargument\doPDFattachmentnumber}
+
+\def\doPDFattachmentnumber[#1]%
+ {\iffirstargument
+ \doPDFfilestreamidentifier{#1}%
+ \else
+ \doPDFfilestreamidentifier\PDFfile
+ \fi}
+
+%D \macros
+%D {...}
+%D
+%D Rather preliminary. We have to wait till the complete specs
+%D show up. As usual, we cannot really check it (Acrobat 6.0
+%D has a bug that inhibits us to make a test file). Half a day
+%D of testing made clear that trying to control the plugin fails
+%D in most cases (we need plugin specs -). We also miss a feature
+%D to let acrobat wait with proceeding (action processing) till
+%D the media clip is ready.
+
+% aiff audio/aiff
+% au audio/basic
+% avi video/avi
+% mid audio/midi
+% mov video/quicktime
+% mp3 audio/x-mp3 (mpeg)
+% mp4 audio/mp4
+% mp4 video/mp4
+% mpeg video/mpeg
+% smil application/smil
+% swf application/x-shockwave-flash
+
+% beware, this is preliminary code, should be improved
+
+\def\PDFrenderingspecs#1{\executeifdefined{PDFMR:#1}\empty}
+
+\def\PDFexecutestartrendering {/Rendition /OP 0 \PDFrenderingspecs\argumentA}
+\def\PDFexecutestoprendering {/Rendition /OP 1 \PDFrenderingspecs\argumentA}
+\def\PDFexecutepauserendering {/Rendition /OP 2 \PDFrenderingspecs\argumentA}
+\def\PDFexecuteresumerendering {/Rendition /OP 3 \PDFrenderingspecs\argumentA}
+
+% todo : sub files
+%
+% \doPDFembedfile{pier-39.png}{pier-39.png}{pier-39.png}%
+% \doPDFgetembeddedfilestreamreference{pier-39.png}\xPDFobjectreference
+% \edef\xxxx{/RF [(pier-39.png) \xPDFobjectreference]}%
+
+% todo: alternative renderings
+%
+% object_1 -> <> >>
+% object_2 -> <> >>
+% rendering -> <>
+
+\def\doinsertrendering#1#2#3#4% tag mime file options
+ {\ifundefined{PDFMR:#1}%
+ \doifinstringelse{://}{#3}\donetrue\donefalse % evt url as keyword
+ \createpdfdictionaryobject{PDFMF}{#1}
+ {/Type /Rendition
+ /S /MR
+ % does not work: /SP << /Type /MediaScreenParam /BE << /B [1 0 0] /O 0.5 >> >>
+ /C << /Type /MediaClip
+ /S /MCD
+ /N (#1)
+ /Alt [() (file not found)] % language id + message
+ /D << /Type /Filespec
+ /F (#3)
+ \ifdone/FS /URL\fi >>
+ /CT (#2) >>}%
+ % common code
+ \doifobjectreferencefoundelse{PDFMS}{#1}
+ {\doPDFgetobjectreference{PDFMS}{#1}\PDFobjectreferenceB}
+ {\doPDFgetobjectreference{PDFMU}{#1}\PDFobjectreferenceB}%
+ \doPDFgetobjectreference{PDFMF}{#1}\PDFobjectreferenceA
+ \setxvalue{PDFMR:#1}% needed /AA actions in /Screen
+ {/R \PDFobjectreferenceA
+ /AN \PDFobjectreferenceB}%
+ \doifobjectreferencefoundelse{PDFMS}{#1}\donothing
+ {\dodoinsertrenderingwindow{PDFMU}{#1}\zeropoint\zeropoint{#4}}%
+ \fi}
+
+\def\doinsertrenderingobject#1#2#3#4% tag class objectname options
+ {\ifundefined{PDFMR:#1}%
+ \doPDFgetobjectreference{#2}{#3}\PDFobjectreference
+ \createpdfdictionaryobject{PDFMF}{#1}
+ {/Type /Rendition
+ /S /MR
+ /C << /Type /MediaClip
+ /S /MCD
+ /N (#1)
+ /D \PDFobjectreference>>}%
+ % common code
+ \doifobjectreferencefoundelse{PDFMS}{#1}
+ {\doPDFgetobjectreference{PDFMS}{#1}\PDFobjectreferenceB}
+ {\doPDFgetobjectreference{PDFMU}{#1}\PDFobjectreferenceB}%
+ \doPDFgetobjectreference{PDFMF}{#1}\PDFobjectreferenceA
+ \setxvalue{PDFMR:#1}% needed /AA actions in /Screen
+ {/R \PDFobjectreferenceA
+ /AN \PDFobjectreferenceB}%
+ \doifobjectreferencefoundelse{PDFMS}{#1}\donothing
+ {\dodoinsertrenderingwindow{PDFMU}{#1}\zeropoint\zeropoint{#4}}%
+ \fi}
+
+\def\doinsertrenderingwindow
+ {\dodoinsertrenderingwindow{PDFMS}}
+
+\def\dodoinsertrenderingwindow#1#2#3#4#5%
+ {\vbox to #4 \bgroup
+ \checkPDFscreenactions{#2}{#5}%
+ \doPDFgetobjectpagereference{PDFMF}{#2}\PDFobjectreferenceA
+ \doPDFgetobjectreference {PDFMF}{#2}\PDFobjectreferenceB
+ \vss
+ \hbox to #3 \bgroup
+ \createpdfannotationobject{#1}{#2}{#3}{#4}
+ {/Subtype /Screen
+ /P \PDFobjectreferenceA
+ /A \PDFobjectreferenceB
+ \PDFattributes
+ /Border [0 0 0]}%
+ \hss
+ \egroup
+ \egroup}
+
+\global\let\PDFrenderingopenpageaction \empty
+\global\let\PDFrenderingclosepageaction\empty
+
+\def\checkPDFscreenactions#1#2%
+ {\let\PDFattributes\empty
+ \iflocation % important since direct -)
+ % the action can either (already) be set by the window handler
+ % or (normally when no window [i.e a zero dimensions one] is present) by keyword
+ \doifinset\v!auto{#2}
+ {% brrr, here instead of in navigation module, must move and become special
+ % now two sided dependency
+ \let\checkrendering\gobbleoneargument
+ \ifx\PDFrenderingopenpageaction \empty
+ \handlereferenceactions{\v!StartRendering{#1}}\dosetuprenderingopenpageaction
+ \fi
+ \ifx\PDFrenderingclosepageaction\empty
+ \handlereferenceactions{\v!StopRendering {#1}}\dosetuprenderingclosepageaction
+ \fi
+ }%
+ \donefalse
+ \ifx\PDFrenderingopenpageaction \empty\!!doneafalse\else\donetrue\!!doneatrue\fi
+ \ifx\PDFrenderingclosepageaction\empty\!!donebfalse\else\donetrue\!!donebtrue\fi
+ \ifdone
+ \edef\PDFattributes
+ {/AA <<\if!!donea/PO <<\PDFrenderingopenpageaction >> \fi
+ \if!!doneb/PC <<\PDFrenderingclosepageaction>> \fi>>}%
+ \fi
+ \global\let\PDFrenderingopenpageaction \empty
+ \global\let\PDFrenderingclosepageaction\empty
+ \fi}
+
+\def\dosetuprenderingopenpageaction {\global\let\PDFrenderingopenpageaction \lastPDFaction}
+\def\dosetuprenderingclosepageaction{\global\let\PDFrenderingclosepageaction\lastPDFaction}
+
+%D For the moment we don't test for alternatives that
+%D themselves have alternatives, especially cylcic
+%D dependencies.
+
+% \def\pdfimmediateximage{\immediate\pdfximage}
+%
+% \def\checkpdfimageattributes
+% {\ifx\PDFfigurereference\empty
+% \global\let\pdfimageattributes\empty
+% \else
+% \immediate\pdfobj
+% {[ << /Image \PDFobjref\PDFfigurereference
+% /DefaultForPrinting true >> ]}%
+% \xdef\pdfimageattributes
+% {attr {/Alternates \PDFobjref\pdflastobj}}%
+% \fi}
+%
+% \global\let\PDFimagecolorreference\empty
+%
+% \def\checkpdfimagecolorspecs
+% {\ifx\pdflastximagecolordepth \undefined
+% \global\let\pdfimagecolorspecs\empty
+% \else\ifx\PDFimagecolorreference\empty
+% \global\let\pdfimagecolorspecs\empty
+% \else
+% \xdef\pdfimagecolorspecs{colorspace \PDFimagecolorreference\space}%
+% \fi\fi
+% \global\let\PDFimagecolorreference\empty}
+
+%D \macros
+%D {doregisterfigure}
+%D
+%D Here is the fuzzy, very special dependant figure
+%D registration special. We need to refer to the innermost
+%D object (ximage).
+
+ \def\doregisterfigure#1#2%
+ {\doifundefined{IM::#1::#2}
+ {\setxvalue{IM::#1::#2}{\the\pdflastximage}}%
+ \xdef\PDFfigurereference{\getvalue{IM::#1::#2}}}
+
+%D \macros
+%D {doovalbox}
+%D
+%D Drawing frames with round corners is inherited from the
+%D main module.
+%D
+%D For drawing ovals we use quite raw \PDF\ code. The next
+%D implementation does not differ that much from the one
+%D implemented in the \POSTSCRIPT\ driver.
+
+\def\doPDFovalcalc#1#2#3%
+ {\PointsToBigPoints{\dimexpr#1+#2\relax}#3}
+
+\def\doovalbox#1#2#3#4#5#6#7#8% todo: \scratchdimen/\scatchbox
+ {\forcecolorhack
+ \bgroup
+ \dimen0=#4\divide\dimen0 \plustwo
+ \doPDFovalcalc{0pt}{+\dimen0}\xmin
+ \doPDFovalcalc{#1}{-\dimen0}\xmax
+ \doPDFovalcalc{#2}{-\dimen0}\ymax
+ \doPDFovalcalc{-#3}{+\dimen0}\ymin
+ \advance\dimen0 by #5%
+ \doPDFovalcalc{0pt}{+\dimen0}\xxmin
+ \doPDFovalcalc{#1}{-\dimen0}\xxmax
+ \doPDFovalcalc{#2}{-\dimen0}\yymax
+ \doPDFovalcalc{-#3}{+\dimen0}\yymin
+ \doPDFovalcalc{#4}{\zeropoint}\stroke
+ \doPDFovalcalc{#5}{\zeropoint}\radius
+ \edef\dostroke{#6}%
+ \edef\dofill{#7}%
+ \edef\mode{\number#8 \space}%
+ % no \ifcase, else \relax in pdfcode
+ \setbox\scratchbox\hbox
+ {\ifnum\dostroke\dofill>\zerocount
+ \ifPDFstrokecolor\else\ifnum\dostroke=\plusone
+ \writestatus\m!colors{pdf stroke color will fail}\wait
+ \fi\fi
+ \PDFcode
+ {q
+ \stroke\space w
+ \ifcase\mode
+ \xxmin\space \ymin \space m
+ \xxmax\space \ymin \space l
+ \xmax \space \ymin \space \xmax \space \yymin\space y
+ \xmax \space \yymax\space l
+ \xmax \space \ymax \space \xxmax\space \ymax \space y
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ h
+ \or % 1
+ \xxmin\space \ymin \space m
+ \xxmax\space \ymin \space l
+ \xmax \space \ymin \space \xmax \space \yymin\space y
+ \xmax \space \ymax \space l
+ \xmin \space \ymax \space l
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ h
+ \or % 2
+ \xxmin\space \ymin \space m
+ \xmax \space \ymin \space l
+ \xmax \space \ymax \space l
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ h
+ \or % 3
+ \xmin \space \ymin \space m
+ \xmax \space \ymin \space l
+ \xmax \space \yymax\space l
+ \xmax \space \ymax \space \xxmax\space \ymax \space y
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \ymin \space l
+ h
+ \or % 4
+ \xmin \space \ymin \space m
+ \xxmax\space \ymin \space l
+ \xmax \space \ymin \space \xmax \space \yymin\space y
+ \xmax \space \yymax\space l
+ \xmax \space \ymax \space \xxmax\space \ymax \space y
+ \xmin \space \ymax \space l
+ \xmin \space \ymin\space l
+ h
+ \or % 5
+ \xmin \space \ymin \space m
+ \xmax \space \ymin \space l
+ \xmax \space \yymax\space l
+ \xmax \space \ymax \space \xxmax\space \ymax \space y
+ \xmin \space \ymax \space l
+ \xmin \space \ymin \space l
+ h
+ \or % 6
+ \xmin \space \ymin \space m
+ \xxmax\space \ymin \space l
+ \xmax \space \ymin \space \xmax \space \yymin\space y
+ \xmax \space \ymax \space l
+ \xmin \space \ymax \space l
+ \xmin \space \ymin \space l
+ h
+ \or
+ \xxmin\space \ymin \space m
+ \xmax \space \ymin \space l
+ \xmax \space \ymax \space l
+ \xmin \space \ymax \space l
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ h
+ \or
+ \xmin \space \ymin \space m
+ \xmax \space \ymin \space l
+ \xmax \space \ymax \space l
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \ymin \space l
+ h
+ \or % 9 top open
+ \xmin \space \ymax \space m
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ \xxmax\space \ymin \space l
+ \xmax \space \ymin \space \xmax \space \yymin\space y
+ \xmax \space \ymax \space l
+ \or % 10 right open
+ \xmax \space \ymax \space m
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \yymin\space l
+ \xmin \space \ymin \space \xxmin\space \ymin \space y
+ \xmax\space \ymin \space l
+ \or % 11 bottom open
+ \xmax \space \ymin \space m
+ \xmax \space \yymax\space l
+ \xmax \space \ymax \space \xxmax \space \ymax\space y
+ \xxmin\space \ymax \space l
+ \xmin \space \ymax \space \xmin \space \yymax\space y
+ \xmin \space \ymin \space l
+ \or % 12 left open
+ \xmin \space \ymax \space m
+ \xxmax\space \ymax \space l
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xmax \space \yymin\space l
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \xmin \space \ymin \space l
+ \or % 13
+ \xmin \space \ymax \space m
+ \xxmax\space \ymax \space l
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xmax\space \ymin \space l
+ \or % 14
+ \xmax \space \ymax \space m
+ \xmax \space \yymin\space l
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \xmin \space \ymin \space l
+ \or % 15
+ \xmax \space \ymin \space m
+ \xxmin\space \ymin \space l
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \xmin \space \ymax \space l
+ \or % 16
+ \xmin \space \ymin \space m
+ \xmin \space \yymax\space l
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \xmax \space \ymax \space l
+ \or % 17
+ \xxmax\space \ymax \space m
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \or % 18
+ \xmax \space \yymin\space m
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \or % 19
+ \xxmin\space \ymin \space m
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \or % 20
+ \xmin \space \yymax\space m
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \or % 21
+ \xxmax\space \ymax \space m
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xmin \space \yymax\space m
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \or % 22
+ \xxmax\space \ymax \space m
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xmax \space \yymin\space m
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \or % 23
+ \xmax \space \yymin\space m
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \xxmin\space \ymin \space m
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \or % 24
+ \xxmin\space \ymin \space m
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \xmin \space \yymax\space m
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \or % 25
+ \xxmax\space \ymax \space m
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xmax \space \yymin\space m
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \xxmin\space \ymin \space m
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \xmin \space \yymax\space m
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \or % 26
+ \xmax \space \yymin\space m
+ \xmax \space \ymin \space \xxmax\space \ymin \space y
+ \xmin \space \yymax\space m
+ \xmin \space \ymax \space \xxmin\space \ymax \space y
+ \or % 27
+ \xxmax\space \ymax \space m
+ \xmax \space \ymax \space \xmax \space \yymax\space y
+ \xxmin\space \ymin \space m
+ \xmin \space \ymin \space \xmin \space \yymin\space y
+ \or % 28
+ \fi
+ \ifnum\mode>8
+ S
+ \else
+ \ifnum\dostroke=\plusone S \fi
+ \ifnum\dofill =\plusone f \fi
+ \fi
+ Q}%
+ \fi}%
+ \wd\scratchbox#1\ht\scratchbox#2\dp\scratchbox#3\box\scratchbox
+ \egroup}
+
+%D \macros
+%D {dostartgraymode,dostopgraymode,
+%D dostartrgbcolormode,dostartcmykcolormode,dostartgraycolormode,
+%D dostopcolormode,
+%D dostartrotation,dostoprotation,
+%D dostartscaling,dostopscaling,
+%D dostartmirroring,dostopmirroring,
+%D dostartnegative,dostopnegative,
+%D dostartoverprint,dostopoverprint}
+
+\def\dostartrotation#1% grouped
+ {\setcalculatedcos\cos{#1}%
+ \setcalculatedsin\sin{#1}%
+ \forcecolorhack
+ \PDFcode{q \cos\space\sin\space\negated\sin\space\cos\space0 0 cm}}
+
+\def\dostoprotation
+ {\PDFcode{Q}}
+
+\def\@@PDFzeroscale{.0001}
+
+\def\dostartscaling#1#2% the test is needed because acrobat is bugged!
+ {\forcecolorhack
+ \PDFcode{q \ifdim#1\points=\zeropoint\@@PDFzeroscale\else#1\fi\space 0 0
+ \ifdim#2\points=\zeropoint\@@PDFzeroscale\else#2\fi\space 0 0 cm}}
+
+\def\dostopscaling
+ {\PDFcode{Q}}
+
+\def\dostartmirroring{\PDFcode{-1 0 0 1 0 0 cm}}
+\def\dostopmirroring {\PDFcode{-1 0 0 1 0 0 cm}}
+
+\def\dostartnegative {\ifdefined\initializePDFnegative \initializePDFnegative \PDFcode{/GSnegative gs}\fi}
+\def\dostopnegative {\ifdefined\initializePDFnegative \initializePDFnegative \PDFcode{/GSpositive gs}\fi}
+\def\dostartoverprint{\ifdefined\initializePDFoverprint\initializePDFoverprint\PDFcode{/GSoverprint gs}\fi}
+\def\dostopoverprint {\ifdefined\initializePDFoverprint\initializePDFoverprint\PDFcode{/GSknockout gs}\fi} % wrong
+
+%D \macros
+%D {doPDFstartgraymode,doPDFstopgraymode,
+%D doPDFstartrgbcolormode,doPDFstartcmykcolormode,doPDFstartgraycolormode,
+%D doPDFstopcolormode}
+%D
+%D In \PDF\ there are two color states, one for strokes and one
+%D for fills. This means that we have to set the color in a
+%D rather redundant looking way. Unfortunately this makes the
+%D \PDF\ file much larger than needed. We can save few bytes
+%D by not setting the stroke color. Due to zip compression we
+%D only save a few percent.
+
+\def\dostartgraymode #1{\PDFcode{#1 g\ifPDFstrokecolor\space#1 G\fi}}
+\def\dostopgraymode {\PDFcode{0 g\ifPDFstrokecolor\space 0 G\fi}}
+\def\dostartrgbcolormode #1#2#3{\PDFcode{#1 #2 #3 rg\ifPDFstrokecolor\space#1 #2 #3 RG\fi}}
+\def\dostartcmykcolormode#1#2#3#4{\PDFcode{#1 #2 #3 #4 k\ifPDFstrokecolor\space#1 #2 #3 #4 K\fi}}
+\def\dostartgraycolormode #1{\PDFcode{#1 g\ifPDFstrokecolor\space#1 G\fi}}
+\def\dostopcolormode {\PDFcode{0 g\ifPDFstrokecolor\space0 G\fi}}
+
+\def\dostartspotcolormode#1#2% redefining spotcolors is not possible anyway
+ {\ifundefined{pdf:scs:#2}%
+ \bgroup
+ \getcommacommandsize[#2]%
+ \ifcase\commalistsize\or
+ \setxvalue{pdf:scs:#2}{#2 SCN #2 scn}% \setxvalue{pdf:scs:#2}{#2 SC #2 sc}%
+ \else
+ \let\PDFspotcolorspecs\empty
+ \def\dospotcolorcommand##1{\edef\PDFspotcolorspecs{\PDFspotcolorspecs##1\space}}%
+ \processcommacommand[#2]\dospotcolorcommand
+ \setxvalue{pdf:scs:#2}{\PDFspotcolorspecs SCN \PDFspotcolorspecs scn}%
+ \fi
+ \egroup
+ \fi
+ \PDFcode{/#1 cs /#1 CS \PDFgetspotcolorspec{#2}}}
+
+\def\PDFgetspotcolorspec#1%
+ {\executeifdefined{pdf:scs:#1}\empty} % better no default than one with too less args
+
+\def\dostartnonecolormode
+ {\PDFcode{/None CS 1 SC /None cs 1 sc}}
+
+%D We need to register the spot colors and their fallbacks.
+
+% we cannot use /DeviceN since GS <=7.21 breaks on it
+% and Jaws does not handle it at all {[/DeviceN [/All|/None]
+% /Device#2 \PDFobjref\pdflastobj]} so we use separation
+% colors that work and print ok
+
+\def\doPDFregistersomespotcolor#1#2#3#4% implemented in the driver
+ {\writestatus\m!systems{missing spot color definition}\wait}
+
+\def\doregisternonecolor % internal command
+ {\doregistergrayspotcolor{None}{1}%
+ \globallet\doregisternonecolor\relax}
+
+\def\dodoPDFregisterrgbspotcolor#1#2#3#4#5#6#7% name noffractions names p's r g b
+ {\doPDFregistersomespotcolor{#1}{#2}{#3}{#4}{RGB}{0.0 1.0 0.0 1.0 0.0 1.0}%
+ {\ifcase#2\or dup #5 mul exch dup #6 mul exch #7 mul\else#5 #6 #7\fi}}
+
+\def\dodoPDFregistercmykspotcolor#1#2#3#4#5#6#7#8% name noffractions names p's c m y k
+ {\doPDFregistersomespotcolor{#1}{#2}{#3}{#4}{CMYK}{0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0}%
+ {\ifcase#2\or dup #5 mul exch dup #6 mul exch dup #7 mul exch #8 mul\else #5 #6 #7 #8\fi}}
+
+\def\dodoPDFregistergrayspotcolor#1#2#3#4#5% name noffractions names p's s
+ {\doPDFregistersomespotcolor{#1}{#2}{#3}{#4}{Gray}{0.0 1.0}%
+ {\ifcase#2\or #5 mul\else #5\fi}}
+
+\def\doregisterrgbspotcolor#1#2#3#4#5#6#7% name noffractions names p's r g b
+ {\ifRGBsupported
+ \dodoPDFregisterrgbspotcolor{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
+ \else
+ \edef\@@cl@@r{#5}\edef\@@cl@@g{#6}\edef\@@cl@@b{#7}%
+ \ifCMYKsupported
+ \convertRGBtoCMYK\@@cl@@r\@@cl@@g\@@cl@@b
+ \dodoPDFregistercmykspotcolor{#1}{#2}{#3}{#4}\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
+ \else
+ \convertRGBtoGRAY\@@cl@@r\@@cl@@g\@@cl@@b
+ \dodoPDFregistergrayspotcolor{#1}{#2}{#3}{#4}\@@cl@@s
+ \fi
+ \fi}
+
+\def\doregistercmykspotcolor#1#2#3#4#5#6#7#8% name noffractions names p's c m y k
+ {\ifCMYKsupported
+ \dodoPDFregistercmykspotcolor{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}%
+ \else
+ \edef\@@cl@@c{#5}\edef\@@cl@@m{#6}\edef\@@cl@@y{#7}\edef\@@cl@@k{#8}%
+ \ifRGBsupported
+ \convertCMYKtoRGB\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
+ \dodoPDFregisterrgbspotcolor{#1}{#2}{#3}{#4}\@@cl@@r\@@cl@@g\@@cl@@b
+ \else
+ \convertCMYKtoGRAY\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
+ \dodoPDFregistergrayspotcolor{#1}{#2}{#3}{#4}\@@cl@@s
+ \fi
+ \fi}
+
+\def\doregistergrayspotcolor{\dodoPDFregistergrayspotcolor}
+
+%D New and very experimental.
+
+\def\doregistercmykindexcolor#1#2#3#4#5#6#7#8% name noffractions names p's c m y k
+ {\doPDFregistersomeindexcolor{#1}{#2}{#3}{#4}{CMYK}{0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0}%
+ {dup #5 mul exch dup #6 mul exch dup #7 mul exch #8 mul}}
+
+\def\doregisterrgbindexcolor#1#2#3#4#5#6#7% name noffractions names p's r g b
+ {\doPDFregistersomeindexcolor{#1}{#2}{#3}{#4}{RGB}{0.0 1.0 0.0 1.0 0.0 1.0}%
+ {dup #5 mul exch dup #6 mul exch #7 mul}}
+
+\def\doregistergrayindexcolor#1#2#3#4#5% name noffractions names p's s
+ {\doPDFregistersomeindexcolor{#1}{#2}{#3}{#4}{Gray}{0.0 1.0}%
+ {pop}}
+
+\let\checkpredefinedcolor\predefineindexcolor % we need an index in order to negate bitmaps
+
+\def\doregisterfigurecolor#1% always an index color
+ {\dogetobjectreference{PDFIX}{\internalspotcolorname{#1}}\PDFimagecolorreference}
+
+\def\doregisterspotcolorname#1#2% no need for escape in luatex
+ {\bgroup
+ \let\ascii\empty
+ \def\docommand##1%
+ {\edef\ascii{\ascii
+ \ifx\nexthandledtoken\space
+ \letterhash20%
+ \else\ifx\nexthandledtoken\blankspace
+ \letterhash20%
+ \else
+ ##1%
+ \fi\fi}}%
+ \expanded{\handletokens#2}\with\docommand
+ \letgvalue{@@pdf@@scn@@#1}\ascii
+ \egroup}
+
+\def\doPDFregistersomespotcolor#1#2#3#4#5#6#7% name fractions names p's space domain function
+ {\bgroup
+ \let\spotpops\empty
+ \ifcase#2\or
+ %def\PDFspotcolornames{/Separation /#1}%
+ \edef\PDFspotcolornames{/Separation /\executeifdefined{@@pdf@@scn@@#1}{#1}}%
+ \def\PDFspotcolordomain{0.0 1.0}%
+ \else
+ \dorecurse{#2}{\edef\spotpops{\spotpops pop }}%
+ \let\PDFspotcolornames \empty
+ \let\PDFspotcolordomain\empty
+ \def\dospotcolorcommand##1%
+ {\edef\PDFspotcolornames {\PDFspotcolornames/\executeifdefined{@@pdf@@scn@@##1}{##1}\space}%
+ \edef\PDFspotcolordomain{\PDFspotcolordomain 0.0 1.0\space}}%
+ \processcommacommand[#3]\dospotcolorcommand
+ \edef\PDFspotcolornames{/DeviceN [\PDFspotcolornames]}%
+ \fi
+ \immediate \pdfobj stream attr
+ {/FunctionType 4 /Domain [\PDFspotcolordomain] /Range [#6]}{{\spotpops#7}}%
+ \immediate \pdfobj
+ {[\PDFspotcolornames\space /Device#5 \PDFobjref\pdflastobj]}%
+ \dosetobjectreference{PDFCS}{#1}{\the\pdflastobj}%
+ \appendtoPDFdocumentcolorspaces{/#1 \PDFobjref\pdflastobj}%
+ \egroup}
+
+%D New and very experimental.
+
+\def\doPDFregistersomeindexcolor#1#2#3#4#5#6#7% name fractions names p's space domain function
+ {\bgroup
+ \let\spotpops\empty
+ \dorecurse{#2}{\edef\spotpops{\spotpops exch pop\space}}%
+ \let\PDFspotcolornames \empty
+ \let\PDFspotcolordomain\empty
+ \def\docommand##1%
+ {%\edef\PDFspotcolornames {\PDFspotcolornames/##1\space}%
+ \edef\PDFspotcolornames{\PDFspotcolornames/\executeifdefined{@@pdf@@scn@@##1}{##1}\space}%
+ \edef\PDFspotcolordomain{\PDFspotcolordomain 0.0 1.0\space}}%
+ \processcommacommand[#3,None]\docommand
+ \let\PDFcolorindexvector\empty
+ \def\docommand##1%
+ {\scratchdimen##1\points
+ \scratchdimen\recurselevel\scratchdimen
+ \scratchcounter\scratchdimen
+ \divide\scratchcounter \maxcard
+ \edef\PDFcolorindexvector{\PDFcolorindexvector\uchexnumbers\scratchcounter}}%
+ %\dostepwiserecurse\zerocount{255}\plusone
+ \dostepwiserecurse{255}\zerocount\minusone % we need to negate
+ {\rawprocesscommacommand[#4,1]\docommand
+ \xdef\PDFcolorindexvector{\PDFcolorindexvector\space}}%
+ \immediate \pdfobj stream attr
+ {/FunctionType 4 /Domain [\PDFspotcolordomain] /Range [#6]}{{\spotpops#7}}%
+ \immediate \pdfobj
+ {[/Indexed
+ [/DeviceN [\PDFspotcolornames] /Device#5 \the\pdflastobj\space0 R] %
+ 255 <\PDFcolorindexvector>]}%
+ \dosetobjectreference{PDFIX}{#1}{\the\pdflastobj}%
+ \appendtoPDFdocumentcolorspaces{/#1_INDEXED \the\pdflastobj\space0 R}%
+ \egroup}
+
+%D \macros
+%D {dostarttransparency,dostoptransparency}
+%D
+%D For transparency, we need to implement a couple of
+%D auxiliary macros. If needed, we will generalize them later.
+
+\def\@@PDT{@PDT@}
+
+\ifx\PDFcurrenttransparency\undefined
+ \newcount\PDFcurrenttransparency \PDFcurrenttransparency=0 % -1
+\fi
+
+\def\assignPDFtransparency#1#2%
+ {\edef\PDFtransparencyidentifier{/Tr#1}%
+ \edef\PDFtransparencyreference{\PDFobjref{#2}}}
+
+\def\presetPDFtransparency#1#2%
+ {\initializePDFtransparency
+ \executeifdefined{\@@PDT#1:#2}{\dopresetPDFtransparency{#1}{#2}}}
+
+\def\dopresetPDFtransparency#1#2%
+ {\global\advance\PDFcurrenttransparency \plusone
+ \immediate\pdfobj{\PDFtransparancydictionary{#1}{#2}{}}%
+ \edef\PDFtransparencyidentifier{/Tr\the\PDFcurrenttransparency}%
+ \edef\PDFtransparencyreference {\PDFobjref\pdflastobj}%
+ \setxvalue{\@@PDT#1:#2}%
+ {\noexpand\assignPDFtransparency{\the\PDFcurrenttransparency}{\the\pdflastobj}}%
+ \appendtoPDFdocumentextgstates
+ {\PDFtransparencyidentifier\space
+ \PDFtransparencyreference\space}}
+
+\def\initializePDFtransparency
+ {\immediate\pdfobj{\PDFtransparancydictionary{1}{1}{/AIS false}}%
+ \xdef\PDFtransparencyresetidentifier{/Tr0}%
+ \xdef\PDFtransparencyresetreference{\PDFobjref\pdflastobj}%
+ \setxvalue{\@@PDT0:0}%
+ {\noexpand\assignPDFtransparency{0}{\the\pdflastobj}}%
+ \appendtoPDFdocumentextgstates
+ {\PDFtransparencyresetidentifier\space
+ \PDFtransparencyresetreference\space}%
+ \global\let\initializePDFtransparency\relax}
+
+%D Transparency support:
+
+\def\PDFtransparancydictionary#1#2#3% type fraction extras
+ {<>}
+
+\def\dodoPDFstarttransparency#1#2%
+ {\presetPDFtransparency{#1}{#2}%
+ \PDFcode{\PDFtransparencyidentifier\space gs }}
+
+\def\dodoPDFstoptransparency
+ {\PDFcode{/Tr0 gs }}
+
+\def\dostarttransparency
+ {\global\let\dostarttransparency\dodoPDFstarttransparency
+ \global\let\dostoptransparency \dodoPDFstoptransparency
+ \initializetransparency
+ \dostarttransparency}
+
+% This is tricky: because a text stream is handled before
+% the page body is built, we can run into stops that will
+% match an outer start; however, the stop is needed in case
+% of a text color: [text color text] [other color text] on a
+% first page combined with color splitting will go wrong if
+% we stick to the relaxing method.
+
+% \def\dostoptransparency
+% {\initializetransparency
+% \dodoPDFstoptransparency}
+
+%D These use:
+
+\let\initializetransparency\relax
+
+\let\PDFtransparencyresetreference \empty
+\let\PDFtransparencyresetidentifier\empty
+
+\let\PDFtransparencyreference \empty
+\let\PDFtransparencyidentifier\empty
+
+%D New trickery:
+
+\def\dostartgraphicgroup{\PDFcode{q}}
+\def\dostopgraphicgroup {\PDFcode{Q}}
+
+%D \macros
+%D {dostartclipping,dostopclipping}
+%D
+%D Clipping in \PDFTEX\ is rather trivial. We can even hook
+%D in \METAPOST\ without problems.
+
+\def\dostartclipping#1#2#3%
+ {\PointsToBigPoints{#2}\width
+ \PointsToBigPoints{#3}\height
+ \grabMPclippath{#1}{1}\width\height
+ {0 0 m \width\space 0 l \width \height l 0 \height l}%
+ \pdfliteral % PDFcode ?
+ {q 0 w \MPclippath\space W n}}
+
+\def\dostopclipping
+ {\pdfliteral{Q n}} % PDFcode
+
+%D \macros
+%D {dosetupinteraction}
+%D
+%D Nothing special is needed to enable \PDF\ commands and
+%D interaction. We stick with a message.
+
+\def\dosetupinteraction
+ {\showmessage\m!interactions{21}{pdftex}}
+
+%D \macros
+%D {doresetgotowhereever,
+%D dostartthisisrealpage,dostartthisislocation,
+%D dostartgotorealpage,dostartgotolocation,dostartgotoJS}
+%D
+%D The interactions macros are the core of this module. We
+%D support both page destinations and named ones. We don't
+%D need the \type{\stop}||alternatives. We also don't need
+%D to set the special that sets the real page number.
+
+%D In the goto specials we took care of secondary references.
+%D Here we define the macros used.
+
+\def\doresetgotowhereever
+ {\global\let\secondaryPDFreferences\empty}
+
+\doresetgotowhereever % just to be sure
+
+% we can (in etex) share more by testing on this
+
+\def\savesecondaryPDFreference#1%
+ {\@EA\xdef\csname PDF-SR:\the\nofsecondaryreferences\endcsname{#1}}
+
+\def\savesecondaryPDFreference % #1 == \action
+ {\global\@EA\let\csname PDF-SR:\the\nofsecondaryreferences\endcsname}
+
+% test should happen in core-ref
+
+\def\getsecondaryPDFreferences
+ {\ifcase\nofsecondaryreferences\else
+ \ifcsname PDF-SR:\the\nofsecondaryreferences\endcsname
+ \xdef\secondaryPDFreferences{/Next <<\csname PDF-SR:\the\nofsecondaryreferences\endcsname\space\secondaryPDFreferences>>}%
+ \fi
+ \global\advance\nofsecondaryreferences \minusone
+ \expandafter\getsecondaryPDFreferences
+ \fi}
+
+%D \macros
+%D {dostartthisislocation}
+%D
+%D Next we define the macros that deal with hyperreferencing,
+%D graphic inclusion and general document features. These are
+%D the olderst ones. I won't comment much because one needs
+%D knowledge of \PDF\ itself, and explaning \PDF\ is beyond
+%D this documentation.
+
+\def\dostartthisislocation#1%
+ {\bgroup
+ \setPDFdestination{#1}%
+ \ifx\PDFdestination\empty \else
+ \pdfdest name {\PDFdestination}\PDFpageviewkey
+ \fi
+ \egroup}
+
+\def\locationfilesuffix{pdf}
+
+\def\dostartgotolocation#1#2#3#4#5#6%
+ {\bgroup
+ \doifelsenothing{#3}
+ {\setPDFdestination{#5}%
+ \doifelsenothing\PDFdestination
+ {\let\action\empty}
+ {\doifelsenothing{#4}
+ {\let\PDFfile\empty}
+ {\expanded{\beforesplitstring#4}\at.\to\PDFfile
+ \doifparentfileelse\PDFfile % {#4}
+ {\let\PDFfile\empty}
+ %{\setreferencefilename#4.\locationfilesuffix\to\PDFfile
+ {\@EA\setreferencefilename\PDFfile.\locationfilesuffix\to\PDFfile
+ \edef\PDFfile
+ {R /F (\PDFfile)\ifgotonewwindow\space/NewWindow true \fi}}}%
+ \edef\action%
+ {/S /GoTo\PDFfile\space /D (\PDFdestination)}}}
+ {\doifelsenothing{#4}
+ {\let\PDFfile\empty
+ \let\PDFdestination\empty}
+ {\setreferencefilename/#4\to\PDFfile
+ \setPDFdestination{#5}%
+ \doifsomething\PDFdestination
+ {\edef\PDFdestination{\letterhash\PDFdestination}}}%
+ \edef\action{/S /URI /URI (#3\PDFfile\PDFdestination)}}%
+ \ifx\action\empty\else
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi
+ \fi
+ \egroup}
+
+\def\PDFgotonewwindow{\ifgotonewwindow\space/NewWindow true \fi}
+
+% optimization in tpd driver
+%
+% \edef\PDFdestination{(page:\the\scratchcounter)}%
+%
+% ==>
+%
+% \advance\scratchcounter 1
+% \edef\PDFdestination{[\pdfpageref \PDFobjref\scratchcounter\PDFpageviewwrd]}%
+%
+% \doPDFgetpagedestination#1#2% pagenumber macro % % fuzzy hack
+
+\def\dostartgotorealpage#1#2#3#4#5% watch the R append trick
+ {\bgroup
+ \doifelsenothing{#3}% #1 = url
+ {\scratchcounter0#5\relax
+ \ifnum\scratchcounter>0
+ \doifelsenothing{#4}
+ {\let\PDFfile\empty}
+ {\expanded{\beforesplitstring#4}\at.\to\PDFfile
+ \doifparentfileelse\PDFfile % {#4}
+ {\let\PDFfile\empty}
+ %{\setreferencefilename#4.\locationfilesuffix\to\PDFfile
+ {\@EA\setreferencefilename\PDFfile.\locationfilesuffix\to\PDFfile
+ \edef\PDFfile{R /F (\PDFfile)\PDFgotonewwindow}}}%
+ \ifx\PDFfile\empty
+ \ifcase\overcomePDFpage
+ \or % pdf starts numbering at zero
+ \advance\scratchcounter \minusone
+ \edef\PDFdestination{[\the\scratchcounter\space\PDFpageviewwrd]}%
+ \or % pdf starts numbering at zero
+ \advance\scratchcounter \minusone
+ \edef\PDFdestination{(page:\the\scratchcounter)}%
+ \or % pdftex starts numbering at one
+ \edef\PDFdestination{[\pdfpageref\scratchcounter\space0 R \PDFpageviewwrd]}%
+ \fi
+ \else % across files it's a page number / pdf starts numbering at zero
+ \advance\scratchcounter \minusone
+ \edef\PDFdestination{[\the\scratchcounter\space\PDFpageviewwrd]}%
+ \fi
+ \edef\action{/S /GoTo\PDFfile\space /D \PDFdestination}%
+ \else
+ \let\action\empty
+ \fi}
+ {\doifelsenothing{#4}
+ {\let\PDFfile\empty}
+ {\setreferencefilename/#4\to\PDFfile}%
+ \edef\action{/S /URI /URI (#3\PDFfile)}}%
+ \ifx\action\empty\else
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi
+ \fi
+ \egroup}
+
+\let\lastfakedPDFpage\!!zerocount
+
+\def\fakePDFpagedestination % as in pdf, we start numbering at zero
+ {\iflocation \ifarrangingpages \ifnum\overcomePDFpage=\plustwo \else
+ \ifnum\lastfakedPDFpage<\realpageno
+ \bgroup
+ \xdef\lastfakedPDFpage{\realfolio}%
+ \advance\realpageno \minusone % is \expanded needed ?
+ \normalexpanded{\noexpand\pdfdest name {page:\realfolio}\PDFpageviewkey}%
+ \egroup
+ \fi
+ \fi \fi \fi}
+
+\def\dostartgotoJS#1#2#3%
+ {\bgroup
+ \doPSsanitizeJScode#3\to\sanitizedJScode
+ \edef\action{/S /JavaScript /JS (\sanitizedJScode)}%
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi
+ \egroup}
+
+%D When going to a location, we obey the time and space saving
+%D boolean \type{\ifusepagedestination}. Named destinations are
+%D stripped and made robust. This all happens in the macros
+%D called for.
+
+%D \macros
+%D {doflushJSpreamble}
+%D
+%D It does not make sense to duplicate common \JAVASCRIPT\
+%D functions, and therefore they can be predefined and must be
+%D output separately. Currently this special is not shared
+%D with the \ACROBAT\ one, simply because \DISTILLER\ does not
+%D yet support something \type{\pdfnames}.
+
+% \oneJSpreamblefalse % buggy in acrobat
+
+\def\doflushJSpreamble#1%
+ {\bgroup
+ \let\compositeJScode\empty
+ \def\docommand##1%
+ {\edef\sanitizedJScode{\getJSpreamble{##1}}%
+ \@EA\doPSsanitizeJScode\sanitizedJScode\to\sanitizedJScode
+ \immediate\pdfobj {<< /S /JavaScript /JS (\sanitizedJScode) >>}%
+ \edef\compositeJScode
+ {\compositeJScode\space (##1) \PDFobjref\pdflastobj}}%
+ \processcommalist[#1]\docommand
+ \immediate\pdfobj{<< /Names [ \compositeJScode ] >>}%
+ \pdfnames{/JavaScript \PDFobjref\pdflastobj}%
+ \egroup}
+
+%D \macros
+%D {dostarthide,dostophide}
+%D
+%D Hiding parts of the document for printing is not yet
+%D supported by \PDF\ and therefore \PDFTEX.
+
+\let\dostarthide\donothing
+\let\dostophide \donothing
+
+%D \macros
+%D {doPDFsetupscreen,doPDFsetupidentity}
+%D
+%D Opposite to \DVI\ drivers, \PDF\ ones must know which what
+%D page dimensions they are dealing. We also use the
+%D opportunity to launch full screen (1) or show bookmarks (2).
+%D
+%D Setting of the screen boundingbox involves some
+%D calculations. Here we also take care of (non) full screen
+%D startup. The dimensions are rounded. Because \PDFTEX\ and
+%D \ACROBAT\ handle setting the page dimensions in a
+%D different way, we do not share this special.
+
+\def\dosetupscreen{\doPDFsetupscreen\pdfpageheight}
+
+\let\currentPDFpagemode \empty % document catalog
+\let\currentPDFviewerprefs\empty % document catalog
+
+\let\currentPDFcropbox \empty % page attributes
+\let\currentPDFbleedbox \empty % page attributes
+\let\currentPDFartbox \empty % page attributes
+\let\currentPDFtrimbox \empty % page attributes
+
+\def\doPDFsetupscreen#1#2#3#4#5#6% watch the extra argument
+ {\bgroup
+ \xdef\currentPDFpagemode
+ {\ifnum#6=4
+ /PageLayout /TwoColumnRight
+ \else
+ /PageMode \ifcase#6
+ /UseNone\or/FullScreen\or/UseOutlines\else/UseNone\fi
+ \fi}%
+ \xdef\currentPDFviewerprefs % space after #6 needed, else \relax
+ {\ifcase#6 \or\or\else /ViewerPreferences << /FitWindow true >>\fi}%
+ \egroup}
+
+\def\addPDFdocumentinfo
+ {\appendtopdfcatalog{\currentPDFpagemode\currentPDFviewerprefs}%
+ \appendtopdfcatalog{/Version \ifdim\PDFversion00\points>100\points 1.\fi\PDFversion}%
+ \appendtopdfinfo{/Trapped /False}%
+ \appendtopdfinfo{/ConTeXt.Version (\contextversion)}%
+ \appendtopdfinfo{/ConTeXt.Time (\number\normalyear.\twodigits\normalmonth.\twodigits\normalday\space \twodigits\currenthour:\twodigits\currentminute)}%
+ \appendtopdfinfo{/ConTeXt.Jobname (\jobname)}%
+ \appendtopdfinfo{/ConTeXt.Url (www.pragma-ade.com)}%
+ \glet\addPDFdocumentinfo\relax}
+
+\def\PDFversion{1.5}
+
+\appendtoksonce
+ \def\PDFversion{1.5}%
+\to \everyresetspecials
+
+\def\doPDFsetupwhateverbox#1#2#3#4#5#6% watch the extra arguments
+ {\bgroup
+ \!!widtha \dimexpr#5+#3\relax
+ \!!heightb\dimexpr#2-#4\relax
+ \!!heighta\dimexpr\!!heightb-#6\relax
+ % sometimes whole values give better results
+ % \PointsToWholeBigPoints{#3}\left
+ % \PointsToWholeBigPoints\!!heighta\bottom
+ % \PointsToWholeBigPoints\!!widtha \width
+ % \PointsToWholeBigPoints\!!heightb\height
+ % but since pdf/x does not round when checking if
+ % the boxes fit inside the media box ...
+ \PointsToBigPoints{#3}\left
+ \PointsToBigPoints\!!heighta\bottom
+ \PointsToBigPoints\!!widtha \width
+ \PointsToBigPoints\!!heightb\height
+ \xdef#1{[\left\space\bottom\space\width\space\height]}%
+ \egroup}
+
+\gdef\currentPDFtrimbox{\currentPDFcropbox} % default, needed for pdf/x
+
+\def\dosetupartbox {\doPDFsetupwhateverbox\currentPDFartbox \pdfpageheight}
+\def\dosetupcropbox {\doPDFsetupwhateverbox\currentPDFcropbox \pdfpageheight}
+\def\dosetupbleedbox{\doPDFsetupwhateverbox\currentPDFbleedbox\pdfpageheight}
+\def\dosetuptrimbox {\doPDFsetupwhateverbox\currentPDFtrimbox \pdfpageheight}
+
+\def\flushPDFpageboxes
+ {\edef\currentPDFtrimbox{\currentPDFtrimbox}%
+ \ifx\currentPDFartbox \empty\else\appendtopdfpageattributes{/ArtBox \currentPDFartbox }\fi
+ \ifx\currentPDFcropbox \empty\else\appendtopdfpageattributes{/CropBox \currentPDFcropbox }\fi
+ \ifx\currentPDFbleedbox\empty\else\appendtopdfpageattributes{/BleedBox \currentPDFbleedbox}\fi
+ \ifx\currentPDFtrimbox \empty\else\appendtopdfpageattributes{/TrimBox \currentPDFtrimbox }\fi}
+
+%D \macros
+%D {dostartexecutecommand}
+%D
+%D \PDF\ viewers enable us to navigate using menus and shortcut
+%D keys. These navigational tools can also be accessed by using
+%D annotations. The next special takes care of inserting them.
+%D
+%D At the cost of much auxiliary placeholders, we can pretty
+%D fast convert the command asked for. This is how the \PDF\
+%D code looks like.
+
+\def\PDFmoviecode#1#2#3%
+ {/Movie
+ /T (\ifcase#1movie \else sound \fi\ifx\argumentA\empty#2\else\argumentA\fi)
+ /Operation /\ifcase#3Play\or Stop\or Pause\or Resume\fi\space}
+
+\def\PDFexecutestartmovie {\PDFmoviecode0\currentmovie0}
+\def\PDFexecutestopmovie {\PDFmoviecode0\currentmovie1}
+\def\PDFexecutepausemovie {\PDFmoviecode0\currentmovie2}
+\def\PDFexecuteresumemovie {\PDFmoviecode0\currentmovie3}
+
+\def\PDFexecutestartsound {\PDFmoviecode1\currentsound0}
+\def\PDFexecutestopsound {\PDFmoviecode1\currentsound1}
+\def\PDFexecutepausesound {\PDFmoviecode1\currentsound2}
+\def\PDFexecuteresumesound {\PDFmoviecode1\currentsound3}
+
+\def\PDFformcode#1%
+ {\doiffieldset{#1}{/Field [\dogetfieldset{#1}]}}
+
+% bit 3 = html
+% bit 6 = xml
+% bit 4 = get
+
+\ifx\PDFsubmitfiller\undefined \let\PDFsubmitfiller\empty \fi
+
+\chardef\PDFformmethod=1 % 0=GET 1=POST
+
+\def\PDFformflag#1#2{\ifcase\PDFformmethod#1\else#2\fi}
+
+\def\PDFexecuteimportform {/Named /N /AcroForm:ImportFDF}
+\def\PDFexecuteexportform {/Named /N /AcroForm:ExportFDF}
+\def\PDFexecuteresetform {/ResetForm \PDFformcode\argumentA}
+\def\PDFexecutesubmitform {/SubmitForm \PDFformcode\argumentB
+ /Flags \ifcase\submitoutputformat\space
+ \PDFformflag{12} {4} % 0=unknown
+ \or \PDFformflag{12} {4} % 1=HTML
+ \or \PDFformflag {8} {0} % 2=FDF
+ \or \PDFformflag{40}{32} % 3=XML
+ \else \PDFformflag{12} {4} % ?=unknown
+ \fi
+ /F (\argumentA)\PDFsubmitfiller}
+
+% urifill permits url substitution
+
+\def\PDFexecutehide {/Hide /T (\argumentA) /H true}
+\def\PDFexecuteshow {/Hide /T (\argumentA) /H false}
+
+\def\PDFexecutefirst {/Named /N /FirstPage}
+\def\PDFexecuteprevious {/Named /N /PrevPage}
+\def\PDFexecutenext {/Named /N /NextPage}
+\def\PDFexecutelast {/Named /N /LastPage}
+\def\PDFexecutebackward {/Named /N /GoBack}
+\def\PDFexecuteforward {/Named /N /GoForward}
+\def\PDFexecuteprint {/Named /N /Print}
+\def\PDFexecuteexit {/Named /N /Quit}
+\def\PDFexecuteclose {/Named /N /Close}
+\def\PDFexecutesave {/Named /N /Save}
+\def\PDFexecutesavenamed {/Named /N /SaveAs}
+\def\PDFexecuteopennamed {/Named /N /Open}
+\def\PDFexecutehelp {/Named /N /HelpUserGuide}
+\def\PDFexecutetoggle {/Named /N /FullScreen}
+\def\PDFexecutesearch {/Named /N /Find}
+\def\PDFexecutesearchagain {/Named /N /FindAgain}
+\def\PDFexecutegotopage {/Named /N /GoToPage}
+\def\PDFexecutequery {/Named /N /AcroSrch:Query}
+\def\PDFexecutequeryagain {/Named /N /AcroSrch:NextHit}
+\def\PDFexecutefitwidth {/Named /N /FitWidth}
+\def\PDFexecutefitheight {/Named /N /FitHeight}
+
+\let\PDFobjectclass\empty
+\let\PDFobjectname \empty
+
+\def\dostartexecutecommand#1#2#3#4%
+ {\doifdefined{PDFexecute#3}
+ {\bgroup
+ \edef\argument{#4}%
+ \ifx\argument\empty
+ \let\argumentA\empty
+ \let\argumentB\empty
+ \else
+ \@EA\dogetcommalistelement\@EA1\@EA\from#4\to\argumentA
+ \@EA\dogetcommalistelement\@EA2\@EA\from#4\to\argumentB
+ \fi
+ \edef\action%
+ {/S \getvalue{PDFexecute#3}}%
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+% \ifx\PDFobjectclass\empty
+% \let\next\insertpdfaction
+% \else
+% \edef\next{\createpdfactionobject{\PDFobjectclass}{\PDFobjectname}}%
+% \globalletempty\PDFobjectclass
+% \globalletempty\PDFobjectname
+% \fi
+% \next
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi
+ \egroup}}
+
+%D \macros
+%D {dosetupidentity}
+%D
+%D Documents can be tagged with an application accessible title
+%D and subtitle, the authorname, a date, the creator, keywords
+%D etc. For the moment \PDFTEX\ only supports the first three
+%D of these.
+
+\def\dosetupidentity#1#2#3#4#5#6%
+ {\normalexpanded{\noexpand\appendtopdfinfo
+ {/Title <\hexifiedPDFstring{#1}>
+ /Subject <\hexifiedPDFstring{#2}>
+ /Author <\hexifiedPDFstring{#3}>
+ /Creator <\hexifiedPDFstring{#4}>
+ /ModDate (#4)
+ /ID (\jobname.#5) % needed for pdf/x
+ /Keywords <\hexifiedPDFstring{#6}>}}}
+
+%D \macros
+%D {dostartrunprogam}
+%D
+%D We can run a program form within a document, although this
+%D feature is rather weak, due to path problems and buggy
+%D argument passing.
+
+\def\dostartrunprogram#1#2#3#4% new: #3 => #3#4
+ {\bgroup
+ %\edef\string{#3}%
+ %\@EA\beforesplitstring\string\at{ }\to\program
+ %\@EA\aftersplitstring \string\at{ }\to\parameters
+ %\edef\action%
+ % {/S /Launch /F (\program) /P (\parameters) /D (.)}%
+ \edef\action
+ {/S /Launch /F (#3) /P (#4) /D (.)}%
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi
+ \egroup}
+
+%D \macros
+%D {dostartgotoprofile, dostopgotoprofile,
+%D dobeginofprofile, doendofprofile}
+%D
+%D \CONTEXT\ user profiles and version control fall back on
+%D \PDF\ article threads. Unfortunately one cannot influence
+%D the view yet in an (for me) acceptable way.
+
+\def\dostartgotoprofile#1#2#3% to be done: file
+ {\bgroup
+ \setPDFdestination{#3}%
+ \doifsomething\PDFdestination
+ {\edef\action
+ {/S /Thread /D (\PDFdestination)}%
+ \ifsecondaryreference
+ \savesecondaryPDFreference\action
+ \else
+ \getsecondaryPDFreferences
+ \insertpdfaction{\PDFswapdir#1}{#2}{\action \secondaryPDFreferences}%
+ \fi}%
+ \egroup}
+
+%D Some day, I'll reimplement threading in a useful way.
+%D Currently the viewers handle threads rather diffuse.
+
+\def\dobeginofprofile#1#2#3#4%
+ {\setPDFdestination{#1}%
+ \doifsomething\PDFdestination
+ {\pdfthread
+ width #2 height #3
+ attr {/Title (\PDFdestination)} % can be omitted
+ name {\PDFdestination}}}
+
+\def\doendofprofile
+ {}
+
+%D \macros
+%D {doinsertbookmark}
+%D
+%D In \PDF\ bookmarks are the building blocks of a viewer
+%D provided sort of table of contents. \TEX\ has to provide
+%D the entry as well as the number of child entries. Strings
+%D need to be sanatized as good as possible to suit the default
+%D encoding. In \CONTEXT\ users can overrule this string by
+%D supplying an alternative one. Look at the macro called for
+%D to see how funny these bookmarks are defined.
+
+\def\doinsertbookmark#1#2#3#4#5% level sublevels text page open=1
+ {\bgroup
+ \doPDFgetpagereference{#4}\PDFobjectreference
+ \pdfoutline
+ user {<>}%
+ \ifcase#2 \else count \ifcase#5-\fi#2 \fi
+% {<\hexifiedPDFstring{#3}>}% goes wrong
+ {<#3>}%
+ \egroup}
+
+%D \macros
+%D {dostartobject,dostopobject,doinsertobject}
+%D
+%D Due to \PDF's object oriented character, we can include and
+%D reuse objects. These can be compared with \TEX's boxes. The
+%D \TEX\ counterpart is defined in the module \type{spec-dvi}.
+%D We don't use the dimensions here.
+%D
+%D The next solution is not that beautiful. Because objects are
+%D containers for whatever kind of content, graphics can be
+%D part of this content, and a graphic object can be part of
+%D the more general type. In practice this means that an ximage
+%D would be embedded in an xform, which in itself is not that
+%D big a problem, apart from a few bytes overhead. However, for
+%D reasons unknown to me alternative images must be pure
+%D ximages |<|indeed, somehow one cannot use a vector graphic
+%D as alternative|>| that are not embedded into forms, so this
+%D is why the object handler treats them different. This
+%D implies knowledge of the calling routines, especially the
+%D \type{FIG} trigger, that signals that we just embedded an
+%D image. Alternatively I could have introduced a dual object
+%D system, but the overhead in duplicate specials is currently
+%D not what we want. I'd rather implement a more mature
+%D object support system from scratch.
+
+\let\currentPDFresources\empty
+\let\PDFimageattributes \empty
+\let\PDFfigurereference \empty
+\let\PDFimagereference \empty
+
+\def\dostartobject#1#2#3#4#5%
+ {\bgroup
+ \setbox\nextbox\vbox\bgroup
+ \def\dodostopobject
+ {\egroup
+ \ifx\PDFimagereference\empty
+ % We also flush page resources, since shared
+ % resources end up there; otherwise transparencies
+ % won't work in xforms; some day I will optimize
+ % this.
+ \the\everyPDFxform
+ \finalizeobjectbox\nextbox
+ \immediate\pdfxform
+ resources {\currentPDFresources\the\pdfpageresources}%
+ \nextbox
+ \global\let\currentPDFresources\empty
+ \dosetobjectreference{#1}{#2}{\the\pdflastxform}%
+ \else
+ \dosetobjectreference{#1}{#2}{-\PDFimagereference}%
+ \global\let\PDFimagereference\empty
+ \fi}}
+
+\def\dostopobject
+ {\dodostopobject
+ \egroup}
+
+\def\doresetobjects
+ {\global\let\PDFimagereference\empty}
+
+\def\doinsertobject#1#2%
+ {\bgroup
+ \doifobjectreferencefoundelse{#1}{#2}
+ {\dogetobjectreference{#1}{#2}\PDFobjectreference
+ \ifnum\PDFobjectreference<0
+ \@EA\@EA\@EA\pdfrefximage\@EA\gobbleoneargument\PDFobjectreference
+ \else
+ \pdfrefxform\PDFobjectreference
+ \fi}%
+ {}%
+ \egroup}
+
+\appendtoksonce
+ \collectPDFresources
+ \global\let\currentPDFresources\collectedPDFresources
+\to \everyPDFxform
+
+%D \macros
+%D {dosetpagetransition}
+%D
+%D Page transitions only make sence in presentations. They are
+%D passed as raw \PDF\ code to the page object. Take a look
+%D at the implementation to get an impression of the rubish
+%D passed on.
+%D
+%D This array holds a reasonable selection of transitions
+%D (watch out: \type{replace} is not in this list). Most of
+%D the transitions look awful anyway. By the way, \CONTEXT\ is
+%D able to select transitions randomly.
+
+\def\pagetransitions
+ {{split,in,vertical},{split,in,horizontal},
+ {split,out,vertical},{split,out,horizontal},
+ {blinds,horizontal},{blinds,vertical},
+ {box,in},{box,out},
+ {wipe,east},{wipe,west},{wipe,north},{wipe,south},
+ dissolve,
+ {glitter,east},{glitter,south},
+ {fly,in,east},{fly,in,west},{fly,in,north},{fly,in,south},
+ {fly,out,east},{fly,out,west},{fly,out,north},{fly,out,south},
+ {push,east},{push,west},{push,north},{push,south},
+ {cover,east},{cover,west},{cover,north},{cover,south},
+ {uncover,east},{uncover,west},{uncover,north},{uncover,south},
+ fade}
+
+%D Again, we use macros as placeholders for \PDF\ key||value
+%D pairs.
+
+\def\PDFpagesplit {/S /Split }
+\def\PDFpageblinds {/S /Blinds }
+\def\PDFpagebox {/S /Box }
+\def\PDFpagewipe {/S /Wipe }
+\def\PDFpagedissolve {/S /Dissolve }
+\def\PDFpageglitter {/S /Glitter }
+\def\PDFpagereplace {/S /R }
+
+\def\PDFpagefly {/S /Fly } % 1.5
+\def\PDFpagepush {/S /Push } % 1.5
+\def\PDFpagecover {/S /Cover } % 1.5
+\def\PDFpageuncover {/S /Uncover } % 1.5
+\def\PDFpagefade {/S /Fade } % 1.5
+
+\def\PDFpagehorizontal {/Dm /H }
+\def\PDFpagevertical {/Dm /V }
+\def\PDFpagein {/M /I }
+\def\PDFpageout {/M /O }
+\def\PDFpageeast {/Di 0 }
+\def\PDFpagenorth {/Di 90 }
+\def\PDFpagewest {/Di 180 }
+\def\PDFpagesouth {/Di 270 }
+
+\def\dodoPDFsetpagetransition#1%
+ {\doifdefined{PDFpage#1}
+ {\edef\PDFpagetransitions{\PDFpagetransitions\getvalue{PDFpage#1}}}}
+
+\def\dosetpagetransition#1#2%
+ {\let\PDFpagetransitions\empty
+ \processcommalist[#1]\dodoPDFsetpagetransition
+ \appendtopdfpageattributes
+ %{\ifnum#2>0 /Dur #2 \fi
+ {\ifnum0<0#2 /Dur #2 \fi
+ \ifx\PDFpagetransitions\empty\else/Trans <<\PDFpagetransitions>>\fi}}
+
+%D The expansion is needed because else the \type{\pdfpageattr}
+%D token list flushes an unexpanded \type{\csname}. The
+%D \type{\global} is needed because the assignment can take
+%D place deeply buried (for instance in the \type{\shipout}
+%D box.
+
+%D \macros
+%D {doinsertcomment, doflushcomments}
+%D
+%D Text annotation, or comments, are provided too:
+
+%D \macros
+%D {dopresetlinefield,dopresettextfield,
+%D dopresetchoicefield,dopresetpopupfield,dopresetcombofield,
+%D dopresetpushfield,dopresetcheckfield,
+%D dopresetradiofield,dopresetradiorecord}
+%D
+%D \PDF\ offers extensive field support. The next bunch of
+%D definitions map the specials.
+
+%D \macros
+%D {dodefinefieldset,dogetfieldset,doiffieldset}
+%D
+%D Field sets, needed for reset and submit handling, are
+%D taken care of by:
+
+%D The next section of this module is dedicated to form
+%D support. These macros are complicated by the fact that
+%D cloning is possible.
+
+%D \macros
+%D {FDFflag...,FDFplus...}
+%D
+%D The \type{/FT} key determines the type of field: text,
+%D button or choice. The latter two come in several disguises,
+%D which are set by flipping bits in the \type{/Ff}. Other bits
+%D are used to set states. Personally I hate this bitty way of
+%D doing things. The next six bit determine the field sub type:
+
+\def\FDFflagMultiLine {4096} % 13
+\def\FDFflagNoToggleToOff {16384} % 15
+\def\FDFflagRadio {32768} % 16
+\def\FDFflagPushButton {65536} % 17
+\def\FDFflagPopUp {131072} % 18
+\def\FDFflagEdit {262144} % 19
+
+% bugged anyway, so we need to drop it:
+
+\def\FDFflagRadiosInUnison {33554432} % 26
+
+%D A few more (pdf 1.4) flags, what the spell check one: for
+%D obscure reasons for Adobe downward compatibility means
+%D enabling features that harm old applications like testing.
+
+\def\FDFflagDoNotSpellCheck {4194304} % 23
+\def\FDFflagDoNotScroll {8388608} % 24
+
+%D The next bits (watch how strange the bits are organized)
+%D take care of the states:
+
+\def\FDFflagReadOnly {1} % 1
+\def\FDFflagRequired {2} % 2
+\def\FDFflagNoExport {4} % 3
+\def\FDFflagPassword {8192} % 14
+\def\FDFflagSort {524288} % 20
+\def\FDFflagFileSelect {1048576} % 21
+
+%D There is a second, again bitset oriented, \type{/F} flag:
+
+\def\FDFplusInvisible {1} % 1
+\def\FDFplusHidden {2} % 2
+\def\FDFplusPrintable {4} % 3
+
+%def\FDFplusNoView {32} % 6
+%def\FDFplusToggleNoView {256} % 9
+
+\def\FDFplusAutoView {256} % {288} % 6+9
+
+%D \macros
+%D {setFDFswitches}
+%D
+%D The non||type bits are mapped onto user||interface
+%D swithes, to be used later on:
+
+\def\@@FDFflag{FDFflag}
+\def\@@FDFplus{FDFplus}
+
+\letvalue {\@@FDFflag\v!readonly}=\FDFflagReadOnly
+\letvalue {\@@FDFflag\v!required}=\FDFflagRequired
+\letvalue {\@@FDFflag\v!protected}=\FDFflagPassword
+\letvalue {\@@FDFflag\v!sorted}=\FDFflagSort
+\letvalue {\@@FDFflag\v!unavailable}=\FDFflagNoExport
+\letvalue {\@@FDFflag\v!nocheck}=\FDFflagDoNotSpellCheck
+\letvalue {\@@FDFflag\v!fixed}=\FDFflagDoNotScroll
+\letvalue {\@@FDFflag\v!file}=\FDFflagFileSelect
+
+\letvalue {\@@FDFplus\v!hidden}=\FDFplusHidden
+\letvalue {\@@FDFplus\v!printable}=\FDFplusPrintable
+
+\letvalue {\@@FDFplus\v!auto}=\FDFplusAutoView
+
+%D A set of switches is collected into the flags we mentioned
+%D before by the next macro (we don't handle negations yet,
+%D but do take care of redundancy):
+
+\def\FDFflag{0}
+\def\FDFplus{0}
+
+\def\setFDFswitches[#1]%
+ {\bgroup
+ \!!counta\zerocount
+ \!!countb\zerocount
+ \def\docommand##1%
+ {\doifsomething{##1}
+ {\advance\!!counta 0\getvalue{\@@FDFflag##1}%
+ \setvalue{\@@FDFflag##1}{0}%
+ \advance\!!countb 0\getvalue{\@@FDFplus##1}%
+ \setvalue{\@@FDFplus##1}{0}}}%
+ \processcommacommand[#1]\docommand
+ \xdef\FDFflag{\the\!!counta}%
+ \xdef\FDFplus{\the\!!countb}%
+ \egroup}
+
+%D \macros
+%D {setFDFvalues}
+%D
+%D Menu items are passed as an array of \type{(string)}'s and
+%D the content of this array is build with:
+
+\let\FDFvalues \empty
+\let\FDFfirstvalues \empty
+\let\FDFsecondvalues\empty
+\let\FDFkidlist \empty
+\let\FDFdefaultindex\!!zerocount
+\let\FDFdefaultvalue\empty
+
+% Why do we need to tweak this mechanism each time acrobat updates ...
+% it would make sense to have version specific sections in pdf files
+% since my guess is that it never will be done right since each year
+% new programmers have new ideas about what is supposed to happen with
+% kids. So .. best is not to trust this feature esp not for radio
+% widgets. (new flags, different interpretation of AS etc etc)
+
+\def\setFDFvalues[#1][#2]% #1 = list (item=>value) #2 = default
+ {\let\FDFvalues \empty
+ %when radio opt works ok
+ %\let\FDFfirstvalues \empty
+ %\let\FDFsecondvalues\empty
+ \let\FDFkidlist \empty
+ %\let\FDFdefaultindex\!!zerocount
+ %\let\FDFdefaultvalue\empty
+ %\scratchcounter\zerocount
+ \def\dodocommand##1=>##2=>##3\end
+ {\addtocommalist{##1}\FDFkidlist
+ %\edef\FDFfirstvalues{\FDFfirstvalues(##1)}%
+ %\doif{##1}{#2}{\edef\FDFdefaultindex{\the\scratchcounter}}%
+ %\advance\scratchcounter\plusone
+ \doifelsenothing{##2}
+ {\doif{##1}{#2}{\edef\FDFdefaultvalue{##1}}%
+ %\edef\FDFsecondvalues{\FDFsecondvalues(##1)}%
+ \edef\FDFvalues{\FDFvalues [(##1)(##1)] }}
+ {\doif{##1}{#2}{\edef\FDFdefaultvalue{##2}}%
+ %\edef\FDFsecondvalues{\FDFsecondvalues(##2)}%
+ \edef\FDFvalues{\FDFvalues [(##2)(##1)] }}}% ! ##1 is shown
+ \def\docommand##1%
+ {\dodocommand##1=>=>\end}%
+ \expanded{\processcommalist[#1]}\docommand}
+
+%D This macro accepts comma separated \type{visual=>result}
+%D pairs.
+
+%D \macros
+%D {setFDFalignment}
+%D
+%D Text and line fields can be entered and showed in three
+%D alternative alingments, indicated by a digit:
+
+\def\FDFalign{0}
+
+\def\setFDFalignment[#1]%
+ {\processaction
+ [#1]
+ [ \v!left=>\edef\FDFalign{2}, % raggedleft
+ \v!middle=>\edef\FDFalign{1}, % raggedcenter
+ \v!right=>\edef\FDFalign{0}]} % raggedright
+
+%D \macros
+%D {setFDFattributes}
+%D
+%D The weak part of (at least version 2.1 \PDF) is that only
+%D default fonts are handled well. Another restriction is that
+%D the encoding vector must be the standard \PDF\ document one.
+%D Although the \PDF\ reference explictly states that one could
+%D use the normal text operators, leading is not yet handled.
+%D
+%D For the moment the current \CONTEXT\ font is mapped onto
+%D one best suitable default font. The color attribute is
+%D less problematic and is directly derived from the \CONTEXT\
+%D color.
+
+\def\FDFattributes{/Helv 12 Tf 0 g 14.4 TL}
+
+\def\FDFrm {TiRo} \def\FDFss {Helv} \def\FDFtt {Cour}
+\def\FDFrmtf{TiRo} \def\FDFsstf{Helv} \def\FDFtttf{Cour}
+\def\FDFrmbf{TiBo} \def\FDFssbf{HeBo} \def\FDFttbf{CoBo}
+\def\FDFrmit{TiIt} \def\FDFssit{HeOb} \def\FDFttit{CoOb}
+\def\FDFrmsl{TiIt} \def\FDFsssl{HeOb} \def\FDFttsl{CoOb}
+\def\FDFrmbi{TiBI} \def\FDFssbi{HeBO} \def\FDFttbi{CoBO}
+\def\FDFrmbs{TiBI} \def\FDFssbs{HeBO} \def\FDFttbs{CoBO}
+
+\let\FDFusedfonts=\FDFsstf
+
+\def\setFDFattributes[#1,#2,#3,#4]% style, color, backgroundcolor, framecolor
+ {\bgroup % nog interlinie: n TL
+ \setbox\scratchbox\hbox
+ \bgroup
+ \doconvertfont{#1}{}%
+ \PointsToBigPoints\bodyfontsize\size % x/xx, so better the actual size
+ \doifdefinedelse{FDF\fontstyle\fontalternative}
+ {\xdef\FDFattributes{\getvalue{FDF\fontstyle\fontalternative}}}
+ {\doifdefinedelse{FDF\fontstyle}
+ {\xdef\FDFattributes{\getvalue{FDF\fontstyle}}}
+ {\xdef\FDFattributes{\FDFrm}}}%
+ \doglobal\addtocommalist\FDFattributes\FDFusedfonts
+ \xdef\FDFattributes% move up with "x.y Ts"
+ {/\FDFattributes\space\size\space Tf\space\PDFcolor{#2}}%
+ \doifelsenothing{#3}
+ {\global\let\FDFsurroundings\empty}
+ {\xdef\FDFsurroundings{/BG \FDFcolor{#3}}}%
+ \doifsomething{#4}
+ {\xdef\FDFsurroundings{\FDFsurroundings\space /BC \FDFcolor{#4}}}%
+ \ifx\FDFsurroundings\empty \else
+ \xdef\FDFsurroundings{/MK << \FDFsurroundings\space>>}%
+ \fi
+ \egroup
+ \egroup}
+
+%D \macros
+%D {setFDFactions}
+%D
+%D Depending on the type of the field, one can assign
+%D \JAVASCRIPT\ code to a mouse event or keystroke. The next
+%D preparation macro shows what events are handled.
+
+\let\FDFactions\empty
+
+\def\setFDFactions[#1,#2,#3,#4,#5,#6,#7,#8,%
+ {\global\let\FDFactions\empty
+ \setFDFaction D#1% mousedown
+ \setFDFaction U#2% mouseup
+ \setFDFaction E#3% enterregion
+ \setFDFaction X#4% exitregion
+ \setFDFaction K#5% afterkeystroke
+ \setFDFaction F#6% formatresult
+ \setFDFaction V#7% validateresult
+ \setFDFaction C#8% calculatewhatever
+ \setFDFactionsmore}
+
+\def\setFDFactionsmore#1,#2]%
+ {\setFDFaction{Fo}#1% focusin
+ \setFDFaction{Bl}#2% focusout % was I (now pdf ref manual explicitly talks about lowercase l)
+ \ifx\FDFactions\empty\else
+ \xdef\FDFactions{/AA << \FDFactions >>}% since 1.3 no longer inherited
+ \fi}
+
+% todo, when new var scheme is implemented
+%
+% \setFDFaction{PO}\@@DriverFieldPageOpen
+% \setFDFaction{PC}\@@DriverFieldPageClose
+% \setFDFaction{PV}\@@DriverFieldPageVisible
+% \setFDFaction{PI}\@@DriverFieldPageInVisible
+
+%D The event handler becomes something:
+%D
+%D \starttyping
+%D /AA << /D << /S ... >> ... /C << /S ... >>
+%D /A << /S /JavaScript /JS (...) >>
+%D \stoptyping
+
+\def\setFDFaction#1#2%
+ {\bgroup
+ \def\docommand{\xdef\FDFactions{\FDFactions /#1 << \lastPDFaction >> }}%
+ \@EA\handlereferenceactions\@EA{#2}\docommand % one level expansion
+ \egroup}
+
+%D \macros
+%D {testFDFactions}
+%D
+%D This rather confusion prone series of script can be tested
+%D with:
+%D
+%D \starttyping
+%D \testFDFactions
+%D \stoptyping
+%D
+%D which simply redefined the previous macro to one that prints
+%D a message to the console.
+
+\def\testFDFactions
+ {\def\setFDFaction##1##2%
+ {\doPSsanitizeJScode console.show();console.println("executing:##1"); \to\sanitizedJScode
+ \edef\FDFactions{\FDFactions /##1 << /S /JavaScript /JS (\sanitizedJScode) >> }}}
+
+%D \macros
+%D {doregistercalculationset}
+%D
+%D There is at most one calculation order list, which defines
+%D the order in which fields are calculated. The calculation
+%D order is defined using:
+
+\let\PDFcalculationset\empty
+
+\def\doregistercalculationset#1%
+ {\def\PDFcalculationset{#1}}
+
+%D \macros
+%D {registerFDFobject,everylastshipout}
+%D
+%D Officially one needs to embed some general datastructures
+%D that tell the viewer what fields are present in the file, as
+%D well as what resources they use. The next mechanism does that
+%D job automatically when one registers the field.
+
+\def\flushFDFnames
+ {\ifx\FDFcollection\empty\else
+ \defineFDFfonts
+ \createpdfarrayobject{FDF}{local:fields}{\FDFcollection}%
+ \doPDFgetobjectreference{FDF}{local:fields}\PDFobjectreference
+ % The /NeedAppearances is pretty important because
+ % otherwise Acrobat 5 blows up on cloned radio widgets
+ \createpdfdictionaryobject{FDF}{local:acroform}
+ {/Fields \PDFobjectreference\space
+ /NeedAppearances true
+ \doiffieldset\PDFcalculationset{/CO [\dogetfieldset\PDFcalculationset]}
+ /DR << /Font << \FDFfonts >> >>
+ /DA (/Helv 10 Tf 0 g)}%
+ \doPDFgetobjectreference{FDF}{local:acroform}\PDFobjectreference
+ \appendtopdfcatalog
+ {/AcroForm \PDFobjectreference}%
+ \global\let\FDFcollection\empty
+ \global\let\flushFDFnames\relax
+ \fi}
+
+\let\FDFcollection\empty
+
+\def\registerFDFobject#1%
+ {\ifx\flushFDFnames\relax
+ \writestatus{FDF}{second run needed for field list (#1)}%
+ \fi
+ \doPDFgetobjectreference{FDF}{#1}\PDFobjectreference
+ \xdef\FDFcollection{\FDFcollection\space\PDFobjectreference}}
+
+\appendtoksonce \flushFDFnames \to \everylastshipout % test \everybye / was \prependtoksonce
+
+%D \macros
+%D {defineFDFfonts}
+%D
+%D Another datastruture concerns the fonts used. We only
+%D define the fonts we use.
+
+\def\defineFDFfonts
+ {\let\FDFfonts\empty
+ \processcommacommand[\FDFusedfonts]\defineFDFfont}
+
+\def\defineFDFfont#1%
+ {\createpdfdictionaryobject{FDF}{local:#1}
+ {/Type /Font
+ /Subtype /Type1
+ /Name /#1
+ /BaseFont /\getvalue{FDFname#1}}%
+ \doPDFgetobjectreference{FDF}{local:#1}\PDFobjectreference
+ \edef\FDFfonts{\FDFfonts \space/#1 \PDFobjectreference}}
+
+%D Another list of constants:
+
+\def\FDFnameTiRo {Times-Roman}
+\def\FDFnameTiBo {Times-Bold}
+\def\FDFnameTiIt {Times-Italic}
+\def\FDFnameTiBI {Times-BoldItalic}
+\def\FDFnameHelv {Helvetica}
+\def\FDFnameHeBo {Helvetica-Bold}
+\def\FDFnameHeOb {Helvetica-Oblique}
+\def\FDFnameHeBO {Helvetica-BoldOblique}
+\def\FDFnameCour {Courier}
+\def\FDFnameCoBo {Courier-Bold}
+\def\FDFnameCoOb {Courier-Oblique}
+\def\FDFnameCoBO {Courier-BoldOblique}
+
+%D \macros
+%D {currentFDFmode,currentFDFparent,currentFDFkids,currenrFDFroot}
+%D
+%D There are three more quasi global interfacing variables
+%D that need to be set.
+
+\let\currentFDFmode \fieldlonermode
+\let\currentFDFkids \empty
+\let\currentFDFparent\empty
+\let\currentFDFroot \empty
+
+%D \macros
+%D {dosetfieldstatus}
+%D
+%D And here comes the special that deals with them.
+
+\def\dosetfieldstatus#1#2#3#4%
+ {\chardef\currentFDFmode #1%
+ \edef\currentFDFparent {#2}%
+ \edef\currentFDFkids {#3}%
+ \edef\currentFDFroot {#4}}
+
+%D We already dealt with the encoding vector. Conversion from
+%D \TEX\ \ASCII\ encoding to the other one, is accomplished by
+%D the next few macros. Wach out: we don't group here.
+
+\appendtoksonce
+ \simplifycommands
+\to \everysetfield
+
+%D \macros
+%D {doPDFinsertcomment}
+%D
+%D An example its use is the next special, one that deals with
+%D text annotations.
+
+\newcounter\nofFDFcomments
+
+\newif\ifPDFpopupcomments \PDFpopupcommentstrue
+
+\def\doflushcomments
+ {\box\PDFsymbolbox}
+
+\long\def\doinsertcomment#1#2#3#4#5#6#7#8% % \@@DriverCommentLayer set otherwise
+ {\bgroup % title width height color open symbol collect data
+ \presetPDFsymbolappearance{#4}{#6}{#2}{#3}\!!zeropoint% sets width/height
+ \doifelsenothing{#1}
+ {\let\PDFidentifier\empty}
+ {\sanitizePDFencoding#1\to\PDFcommenttitle
+ \def\PDFidentifier{/T <\PDFcommenttitle>}}%
+ \sanitizePDFencoding#8\to\PDFdata
+ \setFDFlayer\@@DriverCommentLayer
+ \startPDFsymbolappearance
+ \ifPDFpopupcomments
+ \doglobal\increment\nofFDFcomments
+ \doifobjectreferencefoundelse{FDF}{c:\nofFDFcomments}
+ {\doPDFgetobjectreference{FDF}{c:\nofFDFcomments}\PDFobjectreference
+ \donetrue}
+ \donefalse
+ \ifdone
+ \setbox\scratchbox\hbox
+ {\createpdfannotationobject{FDF}{c::\nofFDFcomments}{#2}{#3}% text window, size does not work
+ {/Subtype /Popup
+ /Parent \PDFobjectreference}}%
+ \ifcase#7\relax
+ \vbox to \height{\forgetall\vskip#3\box\scratchbox\vss}%
+ \else % incredible trial and error hack
+ % it's quite a mess, the annot width cannot be set, well, it can
+ % but the appearance and text sizes get mixed up
+% \setbox\scratchbox\vbox to \height{\forgetall\vskip#3\box\scratchbox\vss}%
+% \global\setbox\PDFsymbolbox\vbox
+% {\hsize#2%
+% \forgetall
+% \vsmash{\box\PDFsymbolbox}
+% \box\scratchbox}%
+ % this may change when acrobat gets less bugged
+ \setbox\scratchbox\vbox to #3{\forgetall\vss\box\scratchbox}%
+ \wd\scratchbox#2%
+ \global\setbox\PDFsymbolbox\vbox
+ {\startoverlay{\box\PDFsymbolbox}{\box\scratchbox}\stopoverlay}%
+ \fi
+ \fi
+ % generic
+ \doifobjectreferencefoundelse{FDF}{c::\nofFDFcomments}
+ {\doPDFgetobjectreference{FDF}{c::\nofFDFcomments}\PDFobjectreference
+ \donetrue}
+ \donefalse
+ \createpdfannotationobject{FDF}{c:\nofFDFcomments}{\width}{\height}
+ {/Subtype /Text
+ \ifcase#5 \else/Open true\fi
+ % pdftex (efficient)
+ % \ifdone /Popup \PDFobjref\pdflastannot\fi
+ % generic (less efficient)
+ \ifdone /Popup \PDFobjectreference\fi
+ /Contents <\PDFdata>
+ \PDFidentifier
+ \FDFlayer
+ \PDFsymbol
+ \PDFattributes}%
+ \else
+ \insertpdfannotation{#2}{#3}
+ {/Subtype /Text
+ \ifcase#5 \else/Open true\fi
+ /Contents <\PDFdata>
+ \FDFlayer
+ \PDFsymbol
+ \PDFidentifier
+ \PDFattributes}%
+ \fi
+ \stopPDFsymbolappearance
+ \egroup}
+
+% symbols with a reasonable default of 18/24 pt
+
+\newbox\PDFsymbolbox
+
+\def\PDFsymbolNew {/Insert}
+\def\PDFsymbolBalloon {/Comment}
+\def\PDFsymbolAddition {/NewParagraph}
+\def\PDFsymbolHelp {/Help}
+\def\PDFsymbolParagraph {/Paragraph}
+\def\PDFsymbolKey {/Key }
+
+\def\PDFsymbolGraph {/Graph}
+\def\PDFsymbolPaperclip {/Paperclip}
+\def\PDFsymbolAttachment{/Attachment}
+\def\PDFsymbolTag {/Tag}
+
+\def\startPDFsymbolappearance
+ {\setbox\scratchbox\vbox to \totalheight \bgroup \vfill}
+
+\def\stopPDFsymbolappearance
+ {\egroup
+ \setbox\scratchbox\hbox{\lower\depth\box\scratchbox}%
+ \wd\scratchbox\width
+ \ht\scratchbox\height
+ \dp\scratchbox\depth
+ \box\scratchbox}
+
+\def\presetPDFsymbolappearance#1#2#3#4#5% symbol color width height depth
+ {\doifelsenothing{#1}
+ {\let\PDFattributes\empty}
+ {\def\PDFattributes{/C \FDFcolor{#1}}}%
+ \scratchdimen#3\edef\width {\the\scratchdimen}%
+ \scratchdimen#4\edef\height{\the\scratchdimen}%
+ \scratchdimen#5\edef\depth {\the\scratchdimen}%
+ \advance\scratchdimen\height\edef\totalheight{\the\scratchdimen}%
+ \doifelsenothing{#2}
+ {\let\PDFsymbol\empty}
+ {\ifundefined{PDFsymbol#2}%
+ \getfromcommacommand[#2][1]\let\PDFsymbolnormalsymbol\commalistelement
+ \getfromcommacommand[#2][2]\let\PDFsymboldownsymbol \commalistelement
+ \doifsymboldefinedelse\PDFsymbolnormalsymbol
+ {\doifsymboldefinedelse\PDFsymboldownsymbol
+ {\dopresetPDFsymbolappearance
+ \PDFsymbolnormalsymbol\PDFsymboldownsymbol}
+ {\dopresetPDFsymbolappearance
+ \PDFsymbolnormalsymbol\PDFsymbolnormalsymbol}}
+ {\doifsymboldefinedelse\PDFsymboldownsymbol
+ {\dopresetPDFsymbolappearance
+ \PDFsymboldownsymbol\PDFsymboldownsymbol}
+ {\let\PDFsymbol\empty}}%
+ \else
+ \def\PDFsymbol{/Name \getvalue{PDFsymbol#2} }%
+ \fi}}
+
+\def\dopresetPDFsymbolappearance#1#2%
+ {\dopresetfieldsymbol{#1}%
+ \dopresetfieldsymbol{#2}%
+ \setbox\scratchbox\hbox{\symbol[#1]}%
+ \edef\width {\the\wd\scratchbox}%
+ \edef\height{\the\ht\scratchbox}%
+ \edef\depth {\the\dp\scratchbox}%
+ \scratchdimen\height \advance\scratchdimen\depth
+ \edef\totalheight{\the\scratchdimen}%
+ \doPDFgetobjectreference{SYM}{#1}\FDFsymbolNappearance
+ \doPDFgetobjectreference{SYM}{#2}\FDFsymbolDappearance
+ \edef\PDFsymbol
+ {/AP <>}}
+
+%D Hooked into \CONTEXT, this special supports
+%D
+%D \starttyping
+%D \startcomment
+%D hello beautiful\\world
+%D \stopcomment
+%D
+%D \startcomment[hello]
+%D de \'e\'erste keer
+%D the f\'irst time
+%D \stopcommen
+%D
+%D \startcommentaar[hallo][color=green,width=4cm,height=3cm]
+%D first
+%D
+%D second
+%D \stopcommentaar
+%D \stoptyping
+%D
+%D So, special characters, forced linebreaks using \type{\\}
+%D and \type{\par} are handled in the appropriate way.
+
+%D \macros
+%D {dosetuppageview}
+%D
+%D Because this command will seldom be called, we can permit
+%D slow action processing. We need three settings, one for
+%D direct \PDF\ inclusion, the other as \PDFTEX\ keyword, an
+%D a last one for form. All determine in what way the
+%D screen is adapted when going to a destination. Watch the
+%D space.
+
+\def\PDFpageviewkey{fit}
+\def\PDFpageviewwrd{/Fit}
+\def\PDFpageview {/View [\PDFpageviewwrd] }
+\def\PDFpagexyzspec{0 0 0} % hack, pdftex does handle this
+\let\PDFpagexyzspec\empty % hack, pdftex does not accept spec
+
+\def\dosetuppageview#1% watch the v-h swapping here
+ {\processaction
+ [#1]
+ [ \v!fit=>\def\PDFpageviewkey {fit}\def\PDFpageviewwrd{/Fit},
+ \v!width=>\def\PDFpageviewkey {fith}\def\PDFpageviewwrd{/FitH},
+ \v!height=>\def\PDFpageviewkey {fitv}\def\PDFpageviewwrd{/FitV},
+ \v!minwidth=>\def\PDFpageviewkey{fitbh}\def\PDFpageviewwrd{/FitBH},
+ \v!minheight=>\def\PDFpageviewkey{fitbv}\def\PDFpageviewwrd{/FitBV},
+ \v!standard=>\def\PDFpageviewkey{xyz \PDFpagexyzspec}\def\PDFpageviewwrd{/XYZ \PDFpagexyzspec},
+ \s!unknown=>\def\PDFpageviewkey {fit}\def\PDFpageviewwrd{/Fit}]%
+ \edef\PDFpageview{/View [\PDFpageviewwrd]}}
+
+%D \macros
+%D {setFDFkids}
+%D
+%D Clones as well as radiofields (which themselves can have
+%D cloned components) need a list of kids. The next macro
+%D builds one.
+
+\def\setFDFkids[#1][#2]% tag commalist
+ {\let\FDFkids\empty
+ \def\docommand##1%
+ {\doPDFgetobjectreference{FDF}{#1##1}\PDFobjectreference
+ \edef\FDFkids{\FDFkids\PDFobjectreference\space}}%
+ \@EA\processcommalist\@EA[#2]\docommand
+ \ifx\FDFkids\empty\else\edef\FDFkids{/Kids [\FDFkids]}\fi}
+
+%D \macros
+%D {dopresetlinefield,dopresettextfield,
+%D dopresetchoicefield,dopresetpopupfield,dopresetcombofield,
+%D dopresetpushfield,dopresetcheckfield,
+%D dopresetfield,dopresetradiorecord}
+%D
+%D I would say: read the \PDF\ reference manual first and see
+%D what happens here next. Lucky us that they have so much in
+%D common.
+
+\def\dopresetlinefield#1#2#3#4#5#6#7#8#9%
+ {\bgroup
+ \setFDFlayer\@@DriverFieldLayer
+ \setFDFswitches[#7]%
+ \setFDFattributes[#6]%
+ \setFDFalignment[#8]%
+ \setFDFactions[#9]%
+ \edef\FDFtext{\hexifiedPDFstring{#4}}%
+ \ifcase\currentFDFmode
+ \createpdfannotationobject{FDF}{#1}{#2}{#3}
+ {/Subtype /Widget /T (#1) /FT /Tx
+ /MaxLen \ifcase0#5 1000 \else#5 \fi
+ %/DV (#4) /V (#4) % value added
+ /DV <\FDFtext> /V <\FDFtext>
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ /Q \FDFalign\space
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \setFDFkids[kids:][\currentFDFkids]%
+ \createpdfdictionaryobject{FDF}{#1}
+ {/T (#1) /FT /Tx
+ /MaxLen \ifcase0#5 1000 \else#5 \fi
+ \FDFkids\space
+ %/DV (#4) /V (#4) % value added
+ /DV <\FDFtext> /V <\FDFtext>
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ /Q \FDFalign\space
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ /Q \FDFalign\space
+ \FDFactions}%
+ \or
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference
+ /F \FDFplus
+ \FDFactions}%
+ \fi
+ \egroup}
+
+\def\dopresettextfield#1#2#3#4#5#6#7#8#9%
+ {\dopresetlinefield{#1}{#2}{#3}{#4}{#5}{#6}{MultiLine,#7}{#8}{#9}}
+
+\def\dopresetchoicefield#1#2#3#4#5#6#7#8%
+ {\bgroup
+ \setFDFlayer\@@DriverFieldLayer
+ \setFDFswitches[#6]%
+ \setFDFattributes[#5]%
+ \setFDFvalues[#7][#4]%
+ \setFDFactions[#8]%
+ \ifcase\currentFDFmode
+ \createpdfannotationobject{FDF}{#1}{#2}{#3}
+ {/Subtype /Widget
+ /T (#1) /FT /Ch
+ /DV (#4) /V (#4)
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ /Opt [\FDFvalues]
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \setFDFkids[kids:][\currentFDFkids]%
+ \createpdfdictionaryobject{FDF}{#1}
+ {/T (#1) /FT /Ch
+ \FDFkids\space
+ /DV (#4) /V (#4)
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ /Opt [\FDFvalues]
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ /DA (\FDFattributes)
+ \FDFlayer\space
+ \FDFsurroundings\space
+ \FDFactions}%
+ \or
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference
+ /F \FDFplus
+ \FDFactions}%
+ \fi
+ \egroup}
+
+\def\dopresetpopupfield#1#2#3#4#5#6#7#8%
+ {\dopresetchoicefield{#1}{#2}{#3}{#4}{#5}{PopUp,#6}{#7}{#8}}
+
+\def\dopresetcombofield#1#2#3#4#5#6#7#8%
+ {\dopresetchoicefield{#1}{#2}{#3}{#4}{#5}{PopUp,Edit,#6}{#7}{#8}}
+
+\newif\ifFDFvalues
+
+\def\doFDFpresetpushcheckfield#1#2#3#4#5#6#7#8% in acro<5 (\FDFdefault)
+ {\bgroup % in acro>5 /\FDFdefault
+ \setFDFlayer\@@DriverFieldLayer
+ \ifcase#8\relax\FDFvaluesfalse\else\FDFvaluestrue\fi
+ \setFDFswitches[#5]%
+ \setFDFactions[#7]%
+ \doifelse{#4}{1}
+ {\def\FDFdefault{On}}
+ {\def\FDFdefault{Off}}%
+ \ifcase\currentFDFmode
+ \doFDFappearance{On}{#6}{#8}%
+ \createpdfannotationobject{FDF}{#1}{#2}{#3}
+ {/Subtype /Widget /T (#1) /FT /Btn
+ \ifFDFvalues
+ /DV /\FDFdefault\space
+ /V /\FDFdefault\space
+ /AS /\FDFdefault\space
+ \fi
+ \FDFlayer
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ \FDFlayer\space
+ \FDFappearance\space
+% /IF << /SW /N >> % strange, only works for stupid buttons
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or % no appearance and layer ?
+ \setFDFkids[kids:][\currentFDFkids]%
+ \createpdfdictionaryobject{FDF}{#1}
+ {/T (#1) /FT /Btn
+ \FDFkids\space
+ \ifFDFvalues
+ /DV /\FDFdefault\space
+ /V /\FDFdefault\space
+ /AS /\FDFdefault\space
+ \fi
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \doFDFappearance{On}{#6}{#8}%
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference\space
+ \ifFDFvalues
+ /DV /\FDFdefault\space
+ /V /\FDFdefault\space
+ /AS /\FDFdefault\space
+ \fi
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ \FDFlayer\space
+ \FDFappearance\space
+ \FDFactions}%
+ \or
+ \doFDFappearance{On}{#6}{#8}%
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference\space
+ /F \FDFplus\space
+ \ifFDFvalues
+ /DV /\FDFdefault\space
+ /V /\FDFdefault\space
+ /AS /\FDFdefault\space
+ \fi
+ \FDFlayer\space
+ \FDFappearance
+ \FDFactions}%
+ \fi
+ \egroup}
+
+\def\dopresetpushfield#1#2#3#4#5#6#7%
+ {\doFDFpresetpushcheckfield{#1}{#2}{#3}{#4}{PushButton,#5}{#6}{#7}{0}}
+
+\def\dopresetcheckfield#1#2#3#4#5#6#7%
+ {\doFDFpresetpushcheckfield{#1}{#2}{#3}{#4}{#5}{#6}{#7}{1}}
+
+\def\dopresetradiofield#1#2#3#4#5#6#7#8%
+ {\bgroup
+ \setFDFlayer\@@DriverFieldLayer
+ \FDFvaluestrue
+ \setFDFswitches[#5]%
+ \setFDFactions[#8]%
+ \doifelsenothing{#4}
+ {\def\FDFdefault{Off}}
+ {\def\FDFdefault{#4}}%
+ \@EA\aftersplitstring\FDFdefault\at=>\to\FDFdefaultvalue
+ \ifx\FDFdefaultvalue\empty\else\let\FDFdefault\FDFdefaultvalue\fi
+ \ifcase\currentFDFmode
+ \doFDFappearance{#1}{#7}{1}%
+ \doPDFgetobjectreference{FDF}{#6}\PDFobjectreference
+ \createpdfannotationobject{FDF}{#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference\space
+ /F \FDFplus\space
+ /AS /\FDFdefault\space
+ \FDFlayer\space
+ \FDFappearance\space
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ \setFDFkids[kids:][\currentFDFkids]%
+ \doPDFgetobjectreference{FDF}{#6}\PDFobjectreference
+ \createpdfdictionaryobject{FDF}{#1}
+ {/Parent \PDFobjectreference\space
+ \FDFkids\space
+ /F \FDFplus\space
+ \FDFactions}%
+ \registerFDFobject{#1}%
+ \or
+ %\doFDFappearance{#1}{#7}{1}%
+ \doFDFappearance{\currentFDFparent}{#7}{1}%
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue % nb
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference\space
+ /AS /\FDFdefault\space
+ /F \FDFplus\space
+ \FDFlayer\space
+ \FDFappearance\space
+ \FDFactions}%
+ \or
+ %\doFDFappearance{#1}{#7}{1}%
+ \doFDFappearance{\currentFDFparent}{#7}{1}%
+ \doPDFgetobjectreference{FDF}\currentFDFparent\PDFobjectreference
+ %\global\objectreferencingtrue
+ \createpdfannotationobject{FDF}{kids:#1}{#2}{#3}
+ {/Subtype /Widget
+ /Parent \PDFobjectreference\space
+ /AS /\FDFdefault\space
+ /F \FDFplus\space
+ \FDFlayer\space
+ \FDFappearance\space
+ \FDFactions}%
+ \fi
+ \egroup}
+
+% Beware, RadiosInUnison is really needed in the pre 1.5/6 time this
+% was the default but out of a sudden it's no longer the case. Also
+% the NoToggleToOff interferes with kids of kids and both it will
+% break older documents, i.e. so much for pdf as standard. With
+% features like widgets we can probably best wait till adobe tools
+% themselves support it because that's probably the moment that
+% functionality gets frozen/becomes definitive. Actually, acrobat
+% flattens the kids tree, so that's yet another situation. The
+% interesting thing is that it worked ok in acrobat 2/3 but got bugged
+% in later versions. [The rationale is in html compatibility, which
+% seems to be more important than compatibility of documents, which in
+% turn renders acrobat useless for forms.] Anyway, synchronization is
+% broken or not depending on the combination pdfversion/acrobatversion.
+
+\def\dopresetradiorecord#1#2#3#4#5%
+ {\bgroup
+ % < pdf 1.5 (1.5 was broken)
+ % \setFDFswitches[Radio,NoToggleToOff,RadiosInUnison,#3]%
+ % > pdf 1.5
+ \setFDFswitches[Radio,RadiosInUnison,#3]%
+ % older, else fatal error
+ % \setFDFkids[#4][]%
+ % newer
+ \setFDFvalues[#4][#2]% inits kidlist
+ \expanded{\setFDFkids[][\FDFkidlist]}%
+ %
+ \setFDFactions[#5]%
+ \createpdfdictionaryobject{FDF}{#1}
+ {%/Subtype /Widget
+ /FT /Btn /T (#1) /Rect [0 0 0 0]
+ % used to be this
+ % /V (#2)
+ % then this
+ % /DV (#2)
+ % since this bomded in 5
+ % /V (#2)
+ % and now finally this works
+ /H /N
+ % /opt is buggy in 5.05, only works once, sigh
+ %\ifx\FDFfirstvalues\FDFsecondvalues
+ /V /#2
+ %\else
+ % /V /\FDFdefaultindex\space
+ % /Opt [\FDFsecondvalues]
+ %\fi
+ /Ff \FDFflag\space
+ /F \FDFplus\space
+ \FDFkids\space
+ \FDFactions}%
+ \egroup}
+
+%D At the cost of some more references, we can save bytes,
+%D by sharing appearance dictionaries. This code needs more
+%D documentation. Surprise:
+
+\def\dodoFDFappearance#1#2%
+ {\ifx#2\empty\else
+ \dogetcommacommandelement1\from#2\to\commalistelement
+ \ifx\commalistelement\empty\else
+ \doPDFgetobjectreference{SYM}\commalistelement\PDFobjectreference
+ \edef\N{\ifFDFvalues\N /#1 \fi\PDFobjectreference\space}%
+ \fi
+ \dogetcommacommandelement2\from#2\to\commalistelement
+ \ifx\commalistelement\empty\else
+ \doPDFgetobjectreference{SYM}\commalistelement\PDFobjectreference
+ \edef\R{\ifFDFvalues\R /#1 \fi\PDFobjectreference\space}%
+ \fi
+ \dogetcommacommandelement3\from#2\to\commalistelement
+ \ifx\commalistelement\empty\else
+ \doPDFgetobjectreference{SYM}\commalistelement\PDFobjectreference
+ \edef\D{\ifFDFvalues\D /#1 \fi\PDFobjectreference\space}%
+ \def\FDFappearance{/H /P }%
+ \fi
+ \fi}
+
+\def\redoFDFappearance#1%
+ {\ifx#1\empty\else
+ \dogetcommacommandelement3\from#1\to\commalistelement
+ \ifx\commalistelement\empty\else
+ \def\FDFappearance{/H /P }%
+ \fi
+ \fi}
+
+\def\doFDFappearance#1#2#3%
+ {\ifcase#3\relax % push only field
+ \edef\yes{#2}%
+ \let\no\empty
+ \else % on / off field
+ \dogetcommacommandelement1\from#2,\to\yes
+ \dogetcommacommandelement2\from#2,\to\no
+ \fi
+ \def\FDFappearance{/H /N}%
+ \doifobjectfoundelse{FDF}{ap:#1:\yes:\no}
+ {\redoFDFappearance\yes
+ \redoFDFappearance\no}
+ {\presetobject{FDF}{ap:#1:\yes:\no}% funny hack
+ \let\N\empty\let\R\empty\let\D\empty
+ \dodoFDFappearance{#1}\yes
+ \dodoFDFappearance{Off}\no
+ \createpdfdictionaryobject{FDF}{ap:#1:\yes:\no}
+ {\ifx\N\empty\else/N \ifFDFvalues<<\N>>\else\N\fi\fi
+ \ifx\R\empty\else/R \ifFDFvalues<<\R>>\else\R\fi\fi
+ \ifx\D\empty\else/D \ifFDFvalues<<\D>>\else\D\fi\fi}}%
+ \doPDFgetobjectreference{FDF}{ap:#1:\yes:\no}\PDFobjectreference
+ \edef\FDFappearance{\FDFappearance /AP \PDFobjectreference}}
+
+\def\doFDFdefault#1#2%
+ {\doifelse{#2}{1}{\def\FDFdefault{On}}{\def\FDFdefault{Off}}}
+
+%D Layer support:
+
+\def\setFDFlayer#1% todo : \ifx\PDFobjectreference\noPDFobjectreference ipv found
+ {\letempty\FDFlayer
+ \doifsomething{#1}%
+ {\checkproperty[#1]% == \dodocheckproperty\@@DriverFieldLayer
+ \doifobjectreferencefoundelse{PDLN}{#1}
+ {\doPDFgetobjectreference{PDLN}{#1}\!!stringa % we need to avoid a clash with other macros
+ \edef\FDFlayer{/OC \!!stringa}}%
+ \donothing}}
+
+%D The three appearances {\em normal}, \type{roll over} and
+%D \type{push down} are passed as comma separated triplets,
+%D that is, the second argument can look like:
+%D
+%D \starttyping
+%D {yes,ok,fine},{no,rubish,awful}
+%D \stoptyping
+
+%D \macros
+%D {dodefinefieldset,dogetfieldset,doiffieldset}
+%D
+%D Field sets, the ones we use in submitting and resetting
+%D fields, are implemented using the next low level specials:
+%D
+%D \starttyping
+%D \doFDFdefinefieldset{TAG}{name,name,...}
+%D \doFDFgetfieldset{TAG}
+%D \doiffieldset{TAG}{sequence}
+%D \stoptyping
+
+\def\dodefinefieldset#1#2% tag commalist
+ {\let\FDFfieldset\empty
+ \def\docommand##1%
+ {\doPDFgetobjectreference{FDF}{##1}\PDFobjectreference
+ \edef\FDFfieldset{\FDFfieldset\PDFobjectreference\space}}%
+ \processcommacommand[#2]\docommand % nb: command
+ \setevalue{FDF:set:#1}{\FDFfieldset}}
+
+\def\dogetfieldset#1%
+ {\getvalue{FDF:set:#1}}
+
+\def\doiffieldset#1#2%
+ {\ifundefined{FDF:set:#1}\else#2\fi}
+
+%D \macros
+%D {defaultobjectreference,doPDFgetobjectreference}
+%D
+%D Because in \PDFTEX\ we have to construct the object
+%D references \type{N 0 R}, we can default to the non existing
+%D zero object number.
+
+\def\defaultobjectreference#1#2%
+ {0}
+
+\def\doPDFgetobjectreference#1#2#3%
+ {\dogetobjectreference{#1}{#2}#3%
+ \edef#3{\ifx#3\empty null\else\PDFobjref{#3}\fi}}
+
+\def\doPDFgetobjectnumber#1#2#3%
+ {\dogetobjectreference{#1}{#2}#3%
+ \edef#3{\ifx#3\empty 0\else#3\fi}}
+
+\def\doPDFgetobjectpage#1#2#3%
+ {\dogetobjectreferencepage{#1}{#2}#3%
+ \ifx#3\empty\def#3{1}\fi}
+
+\def\doPDFgetobjectpagereference#1#2#3%
+ {\dogetobjectreferencepage{#1}{#2}#3%
+ \ifx#3\empty
+ \doPDFgetpagereference\realfolio#3%
+ \else
+ \doPDFgetpagereference#3#3% we assume that #3 gets expanded
+ \fi}
+
+\def\doPDFgetpagereference#1#2% number macro
+ {\edef#2{\ifnum#1>\zerocount\PDFobjref{\pdfpageref#1}\else null\fi}}
+
+\def\thePDFpagereference#1#2% number macro
+ {\ifnum#1>\zerocount\PDFobjref{\pdfpageref#1}\else null\fi}
+
+%D \macros
+%D {initializePDFnegative,initializePDFoverprint}
+%D
+%D Here follow some rather obscure macros. They will only
+%D come into action when one wants negated output.
+
+\def\initializePDFnegative
+ {\immediate\pdfobj stream attr {/FunctionType 4 /Range [0 1] /Domain [0 1]} {{1 exch sub}}%
+ \immediate\pdfobj{<>}%
+ \appendtoPDFdocumentextgstates{/GSnegative \PDFobjref\pdflastobj}%
+ \immediate\pdfobj{<>}%
+ \appendtoPDFdocumentextgstates{/GSpositive \PDFobjref\pdflastobj}%
+ \global\let\initializePDFnegative\relax}
+
+\def\initializePDFoverprint
+ {\immediate\pdfobj{<>}% /op defaults to /OP
+ \appendtoPDFdocumentextgstates{/GSknockout \PDFobjref\pdflastobj}%
+ \immediate\pdfobj{<>}% /op defaults to /OP
+ \edef\PDFobjectreferenceB{\the\pdflastobj}%
+ \appendtoPDFdocumentextgstates{/GSoverprint \PDFobjref\pdflastobj}%
+ \global\let\initializePDFoverprint\relax}
+
+%D File embedding. Storing the stream identifier is needed
+%D to get access to the number. When typeset, the user can
+%D feed this number to \type {pdftosrc} and filter the
+%D file from the \PDF\ file.
+
+\let\PDFlaststreamobject \s!unknown
+%def\PDFlaststreamreference{0 0 R}
+
+\def\doPDFfilestreamobject#1#2#3#4%
+ {\immediate\pdfobj stream file{#4}%
+ \edef\PDFlaststreamobject{\the\pdflastobj}%
+ \dosetobjectreference{PDFFS}{#2}{\PDFlaststreamobject}%
+ \createpdfdictionaryobject{#1}{#2}{/Type /Filespec /F (#3) /EF <>}}
+
+\def\doPDFgetfilestreamreference#1#2%
+ {\doPDFgetobjectreference{PDFFS}{#1}#2}
+
+\def\doPDFfilestreamidentifier#1%
+ {\doifsomething{#1}
+ {\doPDFgetfilestreamreference{#1}\PDFobjectreference
+ \@EA\beforesplitstring\PDFobjectreference\at{ }\to\PDFlaststreamobject
+ \PDFlaststreamobject}}
+
+% MP ?
+
+ \def\setMPPDFobject#1#2% resources boxnumber
+ {\the\everyPDFxform
+ \finalizeobjectbox{#2}%
+ \immediate\pdfxform resources{#1}#2%
+ \edef\getMPPDFobject{\noexpand\pdfrefxform\the\pdflastxform}}
+
+ \let\getMPPDFobject\relax
+
+ \def\doinsertMPfile#1%
+ {\doiffileelse{./#1}{\includeMPasPDF{./#1}}{\message{[MP #1]}}}
+
+%D Even newer trickery:
+
+% resource -> prop -> mc's -> OCG|OCMD (nested)
+% ocg:
+% /Intent/Design
+% ocmd
+% /P /AllOn
+% kan zelf ocmd bevatten
+
+\let\PDFtextlayers\empty
+\let\PDFpagelayers\empty
+\let\PDFhidelayers\empty
+\let\PDFvidelayers\empty
+
+\def\dostartlayer#1{\PDFcode{/OC /#1 BDC}}
+\def\dostoplayer {\PDFcode {EMC}}
+
+\def\dodefineviewerlayer#1#2#3#4#5% tag title visible type printable
+ {\createpdfdictionaryobject{PDLN}{#1}
+ {/Type /OCG
+ \ifcase#4 \or
+ /Intent /Design % disable layer hiding by user
+ \fi
+ \ifnum#5=\zerocount
+ /Usage << /Print << /PrintState /OFF >> >> % printable or not
+ \fi
+ /Name (#2)}%
+ \doPDFgetobjectreference{PDLN}{#1}\PDFobjectreference
+ \xdef\PDFtextlayers{\PDFtextlayers\space\PDFobjectreference}%
+ \doifelse{#3}\v!start
+ {\xdef\PDFvidelayers{\PDFvidelayers\space\PDFobjectreference}}%
+ {\xdef\PDFhidelayers{\PDFhidelayers\space\PDFobjectreference}}%
+ \createpdfdictionaryobject{PDLD}{#1}
+ {/Type /OCMD
+ /OCGs [\PDFobjectreference]}%
+ \doPDFgetobjectreference{PDLD}{#1}\PDFobjectreference
+ \xdef\PDFpagelayers{\PDFpagelayers\space /#1 \PDFobjectreference}}
+
+\def\flushPDFtextlayers
+ {\ifx\PDFtextlayers\empty \else
+ \driverreferenced \createpdfarrayobject{PDF}{textlayers}{\PDFtextlayers}%
+ \doPDFgetobjectreference{PDF}{textlayers}\!!stringa
+ \ifx\PDFvidelayers\empty
+ \def\!!stringb{[null]}%
+ \else
+ \driverreferenced \createpdfarrayobject{PDF}{videlayers}{\PDFvidelayers}%
+ \doPDFgetobjectreference{PDF}{videlayers}\!!stringb
+ \fi
+ \ifx\PDFhidelayers\empty
+ \def\!!stringc{[null]}%
+ \else
+ \driverreferenced \createpdfarrayobject{PDF}{hidelayers}{\PDFhidelayers}%
+ \doPDFgetobjectreference{PDF}{hidelayers}\!!stringc
+ \fi
+ \appendtopdfcatalog
+ {/OCProperties
+ << % display in menu
+ /D << /Order \!!stringa
+ /ON \!!stringb
+ /OFF \!!stringc >>
+ % used properties
+ /OCGs \!!stringa >>}%
+ \globallet\flushPDFtextlayers\relax
+ \fi}
+
+\def\flushPDFpagelayers
+ {\ifx\PDFpagelayers\empty \else
+ \appendtopdfpageresources{/Properties <<\PDFpagelayers>>}%
+ \fi}
+
+\def\PDFlayeractionlist{null}
+
+\def\PDFexecutehidelayer {/SetOCGState /State [/OFF \PDFlayeractionlist]}
+\def\PDFexecutevidelayer {/SetOCGState /State [/ON \PDFlayeractionlist]}
+\def\PDFexecutetogglelayer {/SetOCGState /State [/Toggle \PDFlayeractionlist]}
+
+\def\domakeviewerlayerlist#1%
+ {\bgroup
+ \globallet\PDFlayeractionlist\empty
+ \def\docommand##1%
+ {\doPDFgetobjectreference{PDLN}{##1}\PDFobjectreference
+ \xdef\PDFlayeractionlist{\PDFlayeractionlist\space\PDFobjectreference}}%
+ \processcommalist[#1]\docommand
+ \egroup}
+
+%D Something rather pdf dependent:
+
+% #1 => 1=fill 2=stroke 3=strokedfill 4=invisible
+% #2 => linewidth
+% #3 => spacing (beware, one needs to set the hsize as well)
+
+\def\dostartfonteffect#1#2#3%
+ {\ifdim#2>\zeropoint
+ \PointsToBigPoints{#2}\ascii
+ \PDFcode{\ascii\space w}%
+ \fi
+ \ifdim#3\points=\onepoint\else
+ \scratchdimen#3\points
+ \PDFcode{\withoutpt{\the\scratchdimen}\space Tc}%
+ \fi
+ \PDFcode{\purenumber#1 Tr}}
+
+\def\dostopfonteffect
+ {\PDFcode{1 w 0 Tc 0 Tr}}
+
+%D Handy for the \METAPOST\ to \PDF\ converter:
+
+\appendtoksonce
+ \collectPDFresources
+ \global\let\currentPDFresources\collectedPDFresources
+\to \everyPDFxform
+
+\let\collectedPDFresources\empty
+
+\def\collectPDFresources % suboptimal
+ {\doifobjectreferencefoundelse{FDF}{docushades} % redundant, we have an reserved object now
+ {\doPDFgetobjectreference{FDF}{docushades}\PDFobjectreference
+ \xdef\collectedPDFresources{\collectedPDFresources/Shading \PDFobjectreference}}\donothing
+ \doifobjectreferencefoundelse{FDF}{docuextgstates}
+ {\doPDFgetobjectreference{FDF}{docuextgstates}\PDFobjectreference
+ \xdef\collectedPDFresources{\collectedPDFresources/ExtGState \PDFobjectreference}}\donothing
+ \doifobjectreferencefoundelse{FDF}{colorspaces}
+ {\doPDFgetobjectreference{FDF}{colorspaces}\PDFobjectreference
+ \xdef\collectedPDFresources{\collectedPDFresources/ColorSpace \PDFobjectreference}}\donothing
+ \global\let\collectPDFresources\relax}
+
+\appendtoks
+ \flushPDFpagelayers
+ \flushJSpreamble
+ \flushJSpreamble
+ \checkPDFextgstates
+ \checkPDFcolorspaces
+ \checkPDFshades
+ \checkPDFpageactions
+ \fakePDFpagedestination
+ \flushPDFpageboxes
+ \addPDFdocumentinfo
+\to \everybackendshipout
+
+\appendtoks
+ \flushPDFtextlayers
+ \finalflushJSpreamble
+\to \everylastbackendshipout
+
+%D Temporary hack:
+
+\def\TransparencyHack % png: /CS /DeviceRGB /I true
+ {\appendtoksonce
+ \appendtopdfpageattributes{/Group << /S /Transparency /I true /K true>>}%
+ \to \everyPDFxform
+ \appendtoksonce
+ \appendtopdfpageattributes{/Group << /S /Transparency /I true /K true>>}%
+ \to \everyshipout}
+
+\protect \endinput
diff --git a/tex/context/base/bibl-bib.lua b/tex/context/base/bibl-bib.lua
new file mode 100644
index 000000000..028202ec2
--- /dev/null
+++ b/tex/context/base/bibl-bib.lua
@@ -0,0 +1,233 @@
+if not modules then modules = { } end modules ['bibl-bib'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This is a prelude to integrated bibliography support. This file just loads
+bibtex files and converts them to xml so that the we access the content
+in a convenient way. Actually handling the data takes place elsewhere.
This module implements some methods and creates additional datastructured
from the big character table that we use for all kind of purposes:
char-def.lua.
+
+
We assume that at this point characters.data is already
+loaded!
At this point we assume that the big data table is loaded. From this
table we derive a few more.
--ldx]]--
--- used ?
-
-characters.unicodes = characters.unicodes or { }
-characters.utfcodes = characters.utfcodes or { }
-characters.enccodes = characters.enccodes or { }
-characters.fallbacks = characters.fallbacks or { }
-characters.directions = characters.directions or { }
-
-function characters.context.rehash()
- local unicodes, utfcodes, enccodes, fallbacks, directions = characters.unicodes, characters.utfcodes, characters.enccodes, characters.fallbacks, characters.directions
- for k,v in pairs(characters.data) do
- local contextname, adobename, specials = v.contextname, v.adobename, v.specials
- if contextname then
- local slot = v.unicodeslot
- unicodes[contextname] = slot
- utfcodes[contextname] = utfchar(slot)
- end
- local encname = adobename or contextname
- if encname then
- enccodes[encname] = k
- end
+if not characters.fallbacks then
+
+ characters.fallbacks = { }
+ characters.directions = { }
+
+ local fallbacks = characters.fallbacks
+ local directions = characters.directions
+
+ for k,v in next, data do
+ local specials = v.specials
if specials and specials[1] == "compat" and specials[2] == 0x0020 and specials[3] then
local s = specials[3]
fallbacks[k] = s
@@ -331,101 +365,92 @@ function characters.context.rehash()
end
directions[k] = v.direction
end
- for name,code in pairs(characters.synonyms) do
- if not enccodes[name] then enccodes[name] = code end
- end
-end
--- maybe some day, no significate speed up now
+end
---~ input.storage.register(false, "characters.unicodes", characters.unicodes, "characters.unicodes")
---~ input.storage.register(false, "characters.utfcodes", characters.utfcodes, "characters.utfcodes")
---~ input.storage.register(false, "characters.enccodes", characters.enccodes, "characters.enccodes")
---~ input.storage.register(false, "characters.fallbacks", characters.fallbacks, "characters.fallbacks")
---~ input.storage.register(false, "characters.directions", characters.directions, "characters.directions")
+storage.register("characters.fallbacks", characters.fallbacks, "characters.fallbacks")
+storage.register("characters.directions", characters.directions, "characters.directions")
--[[ldx--
The context namespace is used to store methods and data
which is rather specific to .
--ldx]]--
-function characters.context.show(n)
- local n = characters.number(n)
- local d = characters.data[n]
- if d then
- local function entry(label,name)
- texsprint(tex.ctxcatcodes,format("\\NC %s\\NC %s\\NC\\NR",label,characters.valid(d[name])))
- end
- texsprint(tex.ctxcatcodes,"\\starttabulate[|Tl|Tl|]")
- entry("unicode index" , "unicodeslot")
- entry("context name" , "contextname")
- entry("adobe name" , "adobename")
- entry("category" , "category")
- entry("description" , "description")
- entry("uppercase code", "uccode")
- entry("lowercase code", "lccode")
- entry("specials" , "specials")
- texsprint(tex.ctxcatcodes,"\\stoptabulate ")
- end
-end
-
--[[ldx--
Instead of using a file to define the named glyphs, we
use the table. After all, we have this information available anyway.
--ldx]]--
function characters.makeactive(n,name) -- let ?
- texsprint(tex.ctxcatcodes,format("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name))
+ texsprint(ctxcatcodes,format("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name))
end
function tex.uprint(n)
- texsprint(tex.ctxcatcodes,utfchar(n))
+ texsprint(ctxcatcodes,utfchar(n))
end
-function characters.context.define(tobelettered, tobeactivated)
- local unicodes, utfcodes = characters.unicodes, characters.utfcodes
- local tc = tex.ctxcatcodes
- local is_character, is_command = characters.is_character, characters.is_command
+local template_a = "\\startextendcatcodetable{%s}\\chardef\\l=11\\chardef\\a=13\\let\\c\\catcode%s\\let\\a\\undefined\\let\\l\\undefined\\let\\c\\undefined\\stopextendcatcodetable"
+local template_b = "\\chardef\\l=11\\chardef\\a=13\\let\\c\\catcode%s\\let\\a\\undefined\\let\\l\\undefined\\let\\c\\undefined"
+
+-- we need a function for setting the codes ....
+
+function characters.define(tobelettered, tobeactivated) -- catcodetables
+ local is_character, is_command, is_letter = characters.is_character, characters.is_command, characters.is_letter
local lettered, activated = { }, { }
- for u, chr in pairs(characters.data) do
+ for u, chr in next, data do
+ -- we can use a macro instead of direct settings
local fallback = chr.fallback
if fallback then
- texsprint("{\\catcode"..u.."=13\\unexpanded\\gdef "..utfchar(u).."{\\checkedchar{"..u.."}{"..fallback.."}}}")
- activated[#activated+1] = "\\c"..u.."=".."13"
+ texprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\checkedchar{",u,"}{",fallback,"}}}")
+ activated[#activated+1] = "\\c"..u.."\\a"
else
local contextname = chr.contextname
local category = chr.category
if contextname then
if is_character[category] then
-- by this time, we're still in normal catcode mode
+ -- subtle: not "\\",contextname but "\\"..contextname
if chr.unicodeslot < 128 then
- texsprint(tc, "\\chardef\\" .. contextname .. "=" .. u) -- unicodes[contextname])
+ texprint(ctxcatcodes, "\\chardef\\"..contextname,"=",u)
else
- texsprint(tc, "\\let\\" .. contextname .. "=" .. utfchar(u)) -- utfcodes[contextname])
- lettered[#lettered+1] = "\\c"..u.."=".."11"
+ texprint(ctxcatcodes, "\\let\\"..contextname,"=",utfchar(u))
+ if is_letter[category] then
+ lettered[#lettered+1] = "\\c"..u.."\\l"
+ end
end
elseif is_command[category] then
- texsprint("{\\catcode"..u.."=13\\unexpanded\\gdef "..utfchar(u).."{\\"..contextname.."}}")
- activated[#activated+1] = "\\c"..u.."=".."13"
+ texprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\"..contextname,"}}")
+ activated[#activated+1] = "\\c"..u.."\\a"
end
- else
- if is_character[category] then
- if u >= 128 and u <= 65536 then
- lettered[#lettered+1] = "\\c"..u.."=".."11"
- end
+ elseif is_letter[category] then
+ if u >= 128 and u <= 65536 then -- catch private mess
+ lettered[#lettered+1] = "\\c"..u.."\\l"
end
end
end
+ if chr.range then
+ lettered[#lettered+1] = format('\\dofastrecurse{"%05X}{"%05X}{1}{\\c\\fastrecursecounter\\l}',u,chr.range)
+ end
end
- lettered[#lettered+1] = "\\c"..0x200C.."=".."11" -- non-joiner
- lettered[#lettered+1] = "\\c"..0x200D.."=".."11" -- joiner
- lettered = concat(lettered)
- for _, i in ipairs(tobelettered or { }) do
- texsprint(tc,format("\\startextendcatcodetable{%s}\\let\\c\\catcode%s\\stopextendcatcodetable",i,lettered))
+ -- if false then
+ lettered[#lettered+1] = "\\c"..0x200C.."\\l" -- non-joiner
+ lettered[#lettered+1] = "\\c"..0x200D.."\\l" -- joiner
+ -- fi
+ if tobelettered then
+ lettered = concat(lettered)
+ if true then
+ texsprint(ctxcatcodes,format(template_b,lettered))
+ else
+ for l=1,#tobelettered do
+ texsprint(ctxcatcodes,format(template_a,tobelettered[l],lettered))
+ end
+ end
end
- activated = concat(activated)
- for _, i in ipairs(tobeactivated or { } ) do
- texsprint(tc,format("\\startextendcatcodetable{%s}\\let\\c\\catcode%s\\stopextendcatcodetable",i,activated))
+ if tobeactivated then
+ activated = concat(activated)
+ for a=1,#tobeactivated do
+ texsprint(ctxcatcodes,format(template_a,tobeactivated[a],activated))
+ end
end
end
@@ -439,15 +464,22 @@ end
Setting the lccodes is also done in a loop over the data table.
--ldx]]--
+-- we need a function ...
+
function characters.setcodes()
- local tc = tex.ctxcatcodes
- for code, chr in pairs(characters.data) do
+ for code, chr in next, data do
local cc = chr.category
if cc == 'll' or cc == 'lu' or cc == 'lt' then
local lc, uc = chr.lccode, chr.uccode
if not lc then chr.lccode, lc = code, code end
if not uc then chr.uccode, uc = code, code end
- texsprint(tc, format("\\setcclcuc %i %i %i ",code,lc,uc))
+ texsprint(ctxcatcodes,format("\\setcclcuc{%i}{%i}{%i}",code,lc,uc))
+ end
+ if cc == "lu" then
+ texprint(ctxcatcodes,"\\sfcode ",code,"999 ")
+ end
+ if cc == "lo" and chr.range then
+ texsprint(ctxcatcodes,format('\\dofastrecurse{"%05X}{"%05X}{1}{\\setcclcucself\\fastrecursecounter}',code,chr.range))
end
end
end
@@ -479,22 +511,13 @@ end
characters.valid = characters.is_valid
---[[ldx--
-
The next method is used when constructing the main table, although nowadays
-we do this in one step. The index can be a string or a number.
---ldx]]--
-
-function characters.define(c)
- characters.data[characters.number(c.unicodeslot)] = c
-end
-
--[[ldx--
--ldx]]--
-- set a table entry; index is number (can be different from unicodeslot)
function characters.set(n, c)
- characters.data[characters.number(n)] = c
+ data[characters.number(n)] = c
end
--[[ldx--
@@ -503,7 +526,7 @@ can be different (not likely).
--ldx]]--
function characters.get(n)
- return characters.data[characters.number(n)]
+ return data[characters.number(n)]
end
--[[ldx--
@@ -512,43 +535,43 @@ to the checking.
--ldx]]--
function characters.hexindex(n)
- return format("%04X", characters.valid(characters.data[characters.number(n)].unicodeslot))
+ return format("%04X", characters.valid(data[characters.number(n)].unicodeslot))
end
function characters.contextname(n)
- return characters.valid(characters.data[characters.number(n)].contextname)
+ return characters.valid(data[characters.number(n)].contextname)
end
function characters.adobename(n)
- return characters.valid(characters.data[characters.number(n)].adobename)
+ return characters.valid(data[characters.number(n)].adobename)
end
function characters.description(n)
- return characters.valid(characters.data[characters.number(n)].description)
+ return characters.valid(data[characters.number(n)].description)
end
function characters.category(n)
- return characters.valid(characters.data[characters.number(n)].category)
+ return characters.valid(data[characters.number(n)].category)
end
--[[ldx--
Requesting lower and uppercase codes:
--ldx]]--
-function characters.uccode(n) return characters.data[n].uccode or n end
-function characters.lccode(n) return characters.data[n].lccode or n end
+function characters.uccode(n) return data[n].uccode or n end
+function characters.lccode(n) return data[n].lccode or n end
function characters.flush(n)
- local c = characters.data[n]
+ local c = data[n]
if c and c.contextname then
- texsprint(tex.texcatcodes, "\\"..c.contextname)
+ texsprint(texcatcodes, "\\"..c.contextname)
else
- texsprint(unicode.utf8.char(n))
+ texsprint(utfchar(n))
end
end
function characters.shape(n)
- local shcode = characters.data[n].shcode
+ local shcode = data[n].shcode
if not shcode then
return n, nil
elseif type(shcode) == "table" then
@@ -564,43 +587,29 @@ end
function characters.is_of_category(token,category)
if type(token) == "string" then
- return characters.data[utfbyte(token)].category == category
+ return data[utfbyte(token)].category == category
else
- return characters.data[token].category == category
+ return data[token].category == category
end
end
function characters.i_is_of_category(i,category) -- by index (number)
- local cd = characters.data[i]
+ local cd = data[i]
return cd and cd.category == category
end
function characters.n_is_of_category(n,category) -- by name (string)
- local cd = characters.data[utfbyte(n)]
+ local cd = data[utfbyte(n)]
return cd and cd.category == category
end
---[[ldx--
-
The following code is kind of messy. It is used to generate the right
-unicode reference tables.
---ldx]]--
-
-function characters.setpdfunicodes()
---~ local tc = tex.ctxcatcodes
---~ for _,v in pairs(characters.data) do
---~ if v.adobename then
---~ texsprint(tc,format("\\pdfglyphtounicode{%s}{%04X}", v.adobename, v.unicodeslot))
---~ end
---~ end
-end
-
-- xml support
characters.active_offset = 0x10000
xml.entities = xml.entities or { }
-input.storage.register(false,"xml/entities",xml.entities,"xml.entities") -- this will move to lxml
+storage.register("xml/entities",xml.entities,"xml.entities") -- this will move to lxml
function characters.remapentity(chr,slot)
texsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr))
diff --git a/tex/context/base/char-ini.tex b/tex/context/base/char-ini.tex
index ba1ecf15b..b79e44857 100644
--- a/tex/context/base/char-ini.tex
+++ b/tex/context/base/char-ini.tex
@@ -1,8 +1,8 @@
%D \module
%D [ file=char-ini,
%D version=2006.08.20,
-%D title=\CONTEXT\ Character Macros,
-%D subtitle=Character Support (Initialization),
+%D title=\CONTEXT\ Character Support,
+%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
@@ -11,14 +11,12 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Character Support (initialization)}
+\writestatus{loading}{ConTeXt Character Support / Initialization}
\registerctxluafile{char-def}{1.001} % let's load this one first
\registerctxluafile{char-ini}{1.001}
\registerctxluafile{char-cmp}{1.001} % maybe we will load this someplace else
-\registerctxluafile{char-tok}{1.001} % maybe we will load this someplace else
-\registerctxluafile{char-map}{1.001}
-\registerctxluafile{char-syn}{1.001}
+\registerctxluafile{char-map}{1.001} % maybe we will load this someplace else
\unprotect
@@ -31,18 +29,15 @@
\def\checkedchar {\relax\ifmmode\expandafter\checkedmathchar\else\expandafter\checkedtextchar\fi} % #1#2
\def\checkedmathchar#1#2{#2}
\def\checkedtextchar #1{\iffontchar\font#1 \expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi{\char#1}}
-\def\setcclcuc #1 #2 #3 {\global\catcode#1=11 \global\lccode #1=#2 \global\uccode #1=#3 }
%D The codes are stored in the format, so we don't need to reinitialize
-%D them (unless of course we have adapted the table).
+%D them (unless of course we have adapted the table). It is on the agenda
+%D to do this with \type {tex.lccode} cum suis once they're available.
-\ctxlua{characters.setcodes()}
+\def\setcclcuc#1#2#3{\global\catcode#1=11 \global\lccode #1=#2 \global\uccode #1=#3 }
+\def\setcclcucself#1{\global\catcode#1=11 \global\lccode #1=#1 \global\uccode #1=#1 }
-% obsolete
-%
-% \startruntimeluacode
-% \ctxlua{characters.setpdfunicodes()}% pdftounicode mappings can only be done runtime
-% \stopruntimeluacode
+\ctxlua{characters.setcodes()}
%D There may be a problem with the turkisch patterns. By now it's taken care of in
%D ctxtools (thanks to Mojca). There seems to be a bug in the patterns (^^11 refers
@@ -51,16 +46,8 @@
% \setcclcuc "201C "201C "201C
% \setcclcuc "201D "201D "201D
-% definitions
-
-\startruntimectxluacode
- characters.context.rehash()
-\stopruntimectxluacode
-
-% \ctxlua{characters.context.rehash()}
-
\ctxlua {
- characters.context.define(
+ characters.define(
{ % letter catcodes
\number\texcatcodes,
\number\ctxcatcodes,
@@ -85,10 +72,3 @@
}
\protect \endinput
-
-% \ctxlua{characters.context.show(123)}
-% \ctxlua{characters.context.show(0x7B)}
-% \ctxlua{characters.context.show("7B")}
-
-% \dostepwiserecurse{`A}{`Z}{1}
-% {\ctxlua{characters.context.show(\recurselevel)}}
diff --git a/tex/context/base/char-map.lua b/tex/context/base/char-map.lua
index e463158c5..0d8422bc2 100644
--- a/tex/context/base/char-map.lua
+++ b/tex/context/base/char-map.lua
@@ -1,15 +1,12 @@
--- filename : char-map.lua
--- comment : companion to char-def.tex (in ConTeXt)
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
--- remark : derived from 'specialcasing.txt', se Arthurs comments in char-map.txt
-
-
-if not versions then versions = { } end versions['char-map'] = 1.001
-if not characters then characters = { } end
+if not modules then modules = { } end modules ['char-map'] = {
+ version = 1.001,
+ comment = "companion to char-ini.tex",
+ author = "Hans Hagen & Arthur Reutenauer",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+characters = characters or { }
characters.casemap={
[0x0049]={
diff --git a/tex/context/base/char-syn.lua b/tex/context/base/char-syn.lua
deleted file mode 100644
index a779e1a58..000000000
--- a/tex/context/base/char-syn.lua
+++ /dev/null
@@ -1,140 +0,0 @@
-if not modules then modules = { } end modules ['char-syn'] = {
- version = 1.001,
- comment = "companion to char-ini.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
--- thanks to tex4ht for these mappings
-
-characters.synonyms = {
- angle = 0x2220,
- anticlockwise = 0x21BA,
- arrowaxisleft = 0x2190,
- arrowaxisright = 0x2192,
- arrowparrleftright = 0x21C6,
- arrowparrrightleft = 0x21C4,
- arrowtailleft = 0x21A2,
- arrowtailright = 0x21A3,
- arrowtripleleft = 0x21DA,
- arrowtripleright = 0x21DB,
- axisshort = 0x2212,
- because = 0x2235,
- between = 0x226C,
- check = 0x2713,
- circleasteris = 0x229B,
- circleequal = 0x2257,
- circleminus = 0x229D,
- circleR = 0x24C7,
- circlering = 0x229A,
- circleS = 0x24C8,
- clockwise = 0x21BB,
- complement = 0x2201,
- curlyleft = 0x21AB,
- curlyright = 0x21AC,
- dblarrowdwn = 0x21CA,
- dblarrowheadleft = 0x219E,
- dblarrowheadright = 0x21A0,
- dblarrowleft = 0x21C7,
- dblarrowright = 0x21C9,
- dblarrowup = 0x21C8,
- defines = 0x225C,
- diamond = 0x2662,
- diamondsolid = 0x2666,
- difference = 0x224F,
- dotplus = 0x2214,
- downfall = 0x22CE,
- equaldotleftright = 0x2252,
- equaldotrightleft = 0x2253,
- equalorfollows = 0x22DF,
- equalorgreater = 0x22DD,
- equalorless = 0x22DC,
- equalorprecedes = 0x22DE,
- equalsdots = 0x2251,
- followsorcurly = 0x227D,
- followsorequal = 0x227F,
- forces = 0x22A9,
- forcesbar = 0x22AA,
- fork = 0x22D4,
- frown = 0x2322,
- geomequivalent = 0x224E,
- greaterdbleqlless = 0x22Da,
- greaterdblequal = 0x2267,
- greaterlessequal = 0x22DA,
- greaterorapproxeql = 0x227F,
- greaterorequalslant= 0x2265,
- greaterorless = 0x2277,
- greaterorsimilar = 0x2273,
- harpoondownleft = 0x21C3,
- harpoondownright = 0x21C2,
- harpoonleftright = 0x21CC,
- harpoonrightleft = 0x21CB,
- harpoonupleft = 0x21BF,
- harpoonupright = 0x21BE,
- intercal = 0x22BA,
- intersectiondbl = 0x22D2,
- lessdbleqlgreater = 0x22DB,
- lessdblequal = 0x2266,
- lessequalgreater = 0x22DB,
- lessorapproxeql = 0x227E,
- lessorequalslant = 0x2264,
- lessorgreater = 0x2276,
- lessorsimilar = 0x2272,
- maltesecross = 0xFFFD,
- measuredangle = 0x2221,
- muchgreater = 0x22D9,
- muchless = 0x22D8,
- multimap = 0x22B8,
- multiopenleft = 0x22CB,
- multiopenright = 0x22CC,
- nand = 0x22BC,
- orunderscore = 0x22BB,
- perpcorrespond = 0x2259,
- precedesorcurly = 0x227C,
- precedesorequal = 0x227E,
- primereverse = 0x2035,
- proportional = 0x221D,
- revasymptequal = 0x2243,
- revsimilar = 0x223D,
- rightanglene = 0x231D,
- rightanglenw = 0x231C,
- rightanglese = 0x231F,
- rightanglesw = 0x231E,
- ringinequal = 0x2256,
- satisfies = 0x22A8,
- shiftleft = 0x21B0,
- shiftright = 0x21B1,
- smile = 0x2323,
- sphericalangle = 0x2222,
- square = 0x25A1,
- squaredot = 0x22A1,
- squareimage = 0x228F,
- squareminus = 0x229F,
- squaremultiply = 0x22A0,
- squareoriginal = 0x2290,
- squareplus = 0x229E,
- squaresmallsolid = 0x25AA,
- squaresolid = 0x25A0,
- squiggleleftright = 0x21AD,
- squiggleright = 0x21DD,
- star = 0x22C6,
- subsetdbl = 0x22D0,
- subsetdblequal = 0x2286,
- supersetdbl = 0x22D1,
- supersetdblequa = 0x2287,
- therefore = 0x2234,
- triangle = 0x25B5,
- triangledownsld = 0x25BE,
- triangleinv = 0x25BF,
- triangleleft = 0x25C3,
- triangleleftequal = 0x22B4,
- triangleleftsld = 0x25C2,
- triangleright = 0x25B9,
- trianglerightequal = 0x22B5,
- trianglerightsld = 0x25B8,
- trianglesolid = 0x25B4,
- uniondbl = 0x22D3,
- uprise = 0x22CF,
- Yen = 0x00A5,
-}
diff --git a/tex/context/base/char-utf.lua b/tex/context/base/char-utf.lua
index 273923c36..7dd5d914f 100644
--- a/tex/context/base/char-utf.lua
+++ b/tex/context/base/char-utf.lua
@@ -1,6 +1,6 @@
if not modules then modules = { } end modules ['char-utf'] = {
version = 1.001,
- comment = "companion to char-ini.tex",
+ comment = "companion to char-utf.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -19,9 +19,11 @@ in special kinds of output (for instance ).
over a string.
--ldx]]--
-local concat = table.concat
+local utf = unicode.utf8
+local concat, gmatch = table.concat, string.gmatch
+local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
-utf = utf or unicode.utf8
+local ctxcatcodes = tex.ctxcatcodes
characters = characters or { }
characters.graphemes = characters.graphemes or { }
@@ -38,17 +40,12 @@ local utfchar, utfbyte, utfgsub = utf.char, utf.byte, utf.gsub
--[[ldx--
It only makes sense to collapse at runtime, since we don't expect
-source code to depend on collapsing:
-
-
-characters.filters.utf.collapsing = true
-input.filters.utf_translator = characters.filters.utf.collapse
-
+source code to depend on collapsing.
--ldx]]--
function utffilters.initialize()
if utffilters.collapsing and not utffilters.initialized then
- for k,v in pairs(characters.data) do
+ for k,v in next, characters.data do
-- using vs and first testing for length is faster (.02->.01 s)
local vs = v.specials
if vs and #vs == 3 and vs[1] == 'char' then
@@ -86,7 +83,7 @@ function utffilters.collapse(str) -- old one
utffilters.initialize()
end
local tokens, first, done = { }, false, false
- for second in str:utfcharacters() do
+ for second in utfcharacters(str) do
local cgf = graphemes[first]
if cgf and cgf[second] then
first, done = cgf[second], true
@@ -132,7 +129,7 @@ utffilters.private = {
local low = utffilters.private.low
local high = utffilters.private.high
local escapes = utffilters.private.escapes
-local special = "~#$%^&_{}\\"
+local special = "~#$%^&_{}\\|"
function utffilters.private.set(ch)
local cb
@@ -154,7 +151,7 @@ function utffilters.private.escape(str) return utfgsub(str,"(.)", escapes) end
local set = utffilters.private.set
-for ch in special:gmatch(".") do set(ch) end
+for ch in gmatch(special,".") do set(ch) end
--[[ldx--
We get a more efficient variant of this when we integrate
@@ -186,7 +183,7 @@ function utffilters.collapse(str) -- not really tested (we could preallocate a t
cf.initialize()
end
local tokens, first, done, n = { }, false, false, 0
- for second in str:utfcharacters() do
+ for second in utfcharacters(str) do
if done then
local crs = cr[second]
if crs then
@@ -208,7 +205,7 @@ function utffilters.collapse(str) -- not really tested (we could preallocate a t
else
local crs = cr[second]
if crs then
- for s in str:utfcharacters() do
+ for s in utfcharacters(str) do
if n == 1 then
break
else
@@ -222,7 +219,7 @@ function utffilters.collapse(str) -- not really tested (we could preallocate a t
else
local cgf = graphemes[first]
if cgf and cgf[second] then
- for s in str:utfcharacters() do
+ for s in utfcharacters(str) do
if n == 1 then
break
else
@@ -248,120 +245,29 @@ function utffilters.collapse(str) -- not really tested (we could preallocate a t
end
--[[ldx--
-
In the beginning of we experimented with a sequence
-of filters so that we could manipulate the input stream. However, since
-this is a partial solution (not taking macro expansion into account)
-and since it may interfere with non-text, we will not use this feature
-by default.
The following helper functions may disappear (or become optional)
-in the future. Well, they are now.
+
Next we implement some commands that are used in the user interface.
--ldx]]--
---[[obsolete--
-
-characters.filters.sequences = characters.filters.sequences or { }
-characters.filters.activated = false
-
-function characters.filters.append(name)
- table.insert(characters.filters.sequences,name)
-end
-
-function characters.filters.prepend(name)
- table.insert(characters.filters.sequences,1,name)
-end
-
-function characters.filters.remove(name)
- for k,v in ipairs(characters.filters.sequences) do
- if v == name then
- table.remove(characters.filters.sequences,k)
- end
- end
-end
-
-function characters.filters.replace(name_1,name_2)
- for k,v in ipairs(characters.filters.sequences) do
- if v == name_1 then
- characters.filters.sequences[k] = name_2
- break
- end
- end
-end
-
-function characters.filters.insert_before(name_1,name_2)
- for k,v in ipairs(characters.filters.sequences) do
- if v == name_1 then
- table.insert(characters.filters.sequences,k,name_2)
- break
- end
- end
-end
+commands = commands or { }
-function characters.filters.insert_after(name_1,name_2)
- for k,v in ipairs(characters.filters.sequences) do
- if v == name_1 then
- table.insert(characters.filters.sequences,k+1,name_2)
- break
- end
- end
+function commands.uchar(first,second)
+ tex.sprint(ctxcatcodes,utfchar(first*256+second))
end
-function characters.filters.list(separator)
- concat(characters.filters.sequences,seperator or ' ')
-end
-
-function characters.filters.process(str)
- if characters.filters.activated then
- for _,v in ipairs(characters.filters.sequences) do
- str = v(str)
- end
- return str
- else
- return nil -- luatex callback optimalisation
- end
-end
-
---obsolete]]--
-
--[[ldx--
-
The following code is no longer needed and replaced by token
-collectors somehwere else.
+
A few helpers (used to be luat-uni).
--ldx]]--
---[[obsolete--
-
-characters.filters.collector = { }
-characters.filters.collector.data = { }
-characters.filters.collector.collecting = false
-
-function characters.filters.collector.reset()
- characters.filters.collector.data = { }
-end
-
-function characters.filters.collector.flush(separator)
- tex.sprint(concat(characters.filters.collector.data,separator))
-end
-
-function characters.filters.collector.prune(n)
- for i=1,n do
- table.remove(characters.filters.collector.data,-1)
+function utf.split(str)
+ local t = { }
+ for snippet in utfcharacters(str) do
+ t[#t+1] = snippet
end
+ return t
end
-function characters.filters.collector.numerate(str)
- if characters.filters.collector.collecting then
- table.insert(characters.filters.collector.data,(unicode.utf8.gsub(str,"(.)", function(c)
- return ("0x%04X "):format(unicode.utf8.byte(c))
- end)))
+function utf.each(str,fnc)
+ for snippet in utfcharacters(str) do
+ fnc(snippet)
end
- return str
end
-
---obsolete]]--
diff --git a/tex/context/base/char-utf.tex b/tex/context/base/char-utf.tex
index 2e7156962..d21cd842c 100644
--- a/tex/context/base/char-utf.tex
+++ b/tex/context/base/char-utf.tex
@@ -1,8 +1,8 @@
%D \module
%D [ file=char-utf,
%D version=2006.12.05,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=Unicode Support (UTF),
+%D title=\CONTEXT\ Character Support,
+%D subtitle=Unicode UTF,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Unicode Support (utf)}
+\writestatus{loading}{ConTeXt Character Support / Unicode UTF}
%D After a bit of experimenting we reached a clean state where \UTF\
%D 8, 16 and 32 were supported as well as collapsing (combining
@@ -31,28 +31,10 @@
\appendtoks
\ctxlua {
characters.filters.utf.collapsing = true
- input.filters.utf_translator = characters.filters.utf.collapse
+ resolvers.install_text_filter('utf',characters.filters.utf.collapse)
}%
\to \everyjob
-% %D This is a hack, and only meant for special situations. We don't
-% %D support this in for instance verbatim. The active characters map
-% %D onto the \CONTEXT\ names and font handling etc. is up to the user.
-%
-% %D This feature is obsolete.
-%
-% \registerctxluafile{char-act}{1.001}
-%
-% \def\enableactiveutf {\ctxlua{characters.active.enable()}}
-% \def\disableactiveutf{\ctxlua{characters.active.disable()}}
-% \def\testactiveutf #1{\ctxlua{characters.active.test("#1")}}
-
-%D Usage:
-%D
-%D \starttyping
-%D \enableactiveutf \testactiveutf{eacute}
-%D \stoptyping
-
%D The next one influences input parsing.
%D
%D \starttyping
diff --git a/tex/context/base/chem-ini.lua b/tex/context/base/chem-ini.lua
new file mode 100644
index 000000000..27b734840
--- /dev/null
+++ b/tex/context/base/chem-ini.lua
@@ -0,0 +1,74 @@
+if not modules then modules = { } end modules ['chem-ini'] = {
+ version = 1.001,
+ comment = "companion to chem-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, texsprint = string.format, tex.sprint
+
+local trace_molecules = false trackers.register("chemistry.molecules", function(v) trace_molecules = v end)
+
+local ctxcatcodes = tex.ctxcatcodes
+
+chemicals = chemicals or { }
+
+--[[
+
The next code is an adaptation of code from Wolfgang Schuster
+as posted on the mailing list. This version supports nested
+braces and unbraced integers as scripts. We could consider
+spaces as terminals for them but first let collect a bunch
+of input then.
+]]--
+
+-- some lpeg, maybe i'll make an syst-lpg module
+
+local lowercase = lpeg.R("az")
+local uppercase = lpeg.R("AZ")
+local backslash = lpeg.P("\\")
+local csname = backslash * lpeg.P(1) * (1-backslash)^0
+local plus = lpeg.P("+") / "\\textplus "
+local minus = lpeg.P("-") / "\\textminus "
+local digit = lpeg.R("09")
+local sign = plus + minus
+local cardinal = digit^1
+local integer = sign^0 * cardinal
+
+local leftbrace = lpeg.P("{")
+local rightbrace = lpeg.P("}")
+local nobrace = 1 - (leftbrace + rightbrace)
+local nested = lpeg.P { leftbrace * (csname + sign + nobrace + lpeg.V(1))^0 * rightbrace }
+local any = lpeg.P(1)
+
+local subscript = lpeg.P("_")
+local superscript = lpeg.P("^")
+local somescript = subscript + superscript
+
+--~ local content = lpeg.Cs(nested + integer + sign + any)
+local content = lpeg.Cs(csname + nested + sign + any)
+
+-- could be made more efficient
+
+local lowhigh = lpeg.Cc("\\lohi{%s}{%s}") * subscript * content * superscript * content / format
+local highlow = lpeg.Cc("\\hilo{%s}{%s}") * superscript * content * subscript * content / format
+local low = lpeg.Cc("\\low{%s}") * subscript * content / format
+local high = lpeg.Cc("\\high{%s}") * superscript * content / format
+local justtext = (1 - somescript)^1
+local parser = lpeg.Cs((csname + lowhigh + highlow + low + high + sign + any)^0)
+
+chemicals.moleculeparser = parser -- can be used to avoid functioncall
+
+function chemicals.molecule(str)
+ return parser:match(str)
+end
+
+function commands.molecule(str)
+ if trace_molecules then
+ local rep = parser:match(str)
+ logs.report("chemistry", "molecule %s => %s",str,rep)
+ texsprint(ctxcatcodes,rep)
+ else
+ texsprint(ctxcatcodes,parser:match(str))
+ end
+end
diff --git a/tex/context/base/chem-ini.mkiv b/tex/context/base/chem-ini.mkiv
new file mode 100644
index 000000000..b28e73e42
--- /dev/null
+++ b/tex/context/base/chem-ini.mkiv
@@ -0,0 +1,42 @@
+%D \module
+%D [ file=chem-ini,
+%D version=2008.03.06,
+%D subtitle=Chemistry,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Chemistry Macros / Initialization} % might become Inline
+
+\registerctxluafile{chem-ini}{1.001}
+
+\unprotect
+
+%D \macros
+%D {\molecule}
+%D
+%D Quick and dirty:
+%D
+%D \starttyping
+%D \def\molecule#1{$\enablesupersub\tf#1$}
+%D \stoptyping
+%D
+%D Using \LUA:
+%D
+%D \startbuffer
+%D \molecule{H_2SO_4^-2}
+%D \molecule{H_2SO_4^{-2}}
+%D \molecule{H_2SO_4^{-2{x}}}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+\def\molecule#1{\ctxlua{commands.molecule(\!!bs#1\!!es)}}
+
+\protect \endinput
+
+
diff --git a/tex/context/base/chem-str-test.tex b/tex/context/base/chem-str-test.tex
new file mode 100644
index 000000000..fd6a8227a
--- /dev/null
+++ b/tex/context/base/chem-str-test.tex
@@ -0,0 +1,560 @@
+% Beware, integrated ppchtex support is incomplete and under
+% construction so when you depend on the full functionality
+% you need to use the module!
+%
+% For testing new functionality:
+%
+% \startMPextensions
+% input "mp-chem.mp" ;
+% \stopMPextensions
+% \startluacode
+% dofile(resolvers.find_file("chem-str.lua","tex"))
+% \stopluacode
+% \setbox\scratchbox\hbox{\startMPcode\stopMPcode}
+
+\enabletrackers[chemistry.structure]
+
+\starttext
+
+\defineprocessor[ch:r][color=red]
+\defineprocessor[ch:g][color=green]
+\defineprocessor[ch:b][color=blue]
+
+\setupchemical[frame=on,offset=3pt]
+
+\startbuffer[test-set]
+
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV1,B] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV2,B] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV3,B] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV4,B] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV5,B] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,MOV6,B] \stopchemical \quad
+
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,AU] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,AD] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,EB] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,DB] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,ER] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,DR] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,BR] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,SB] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,-SB] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,+SB] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,C] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,CC] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,CD] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,CCD] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,SB,SR] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,SB,-SR] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,SB,+SR] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,RD] \stopchemical \quad
+
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,SB,Z] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RZ] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,+R,+RZ] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,-R,-RZ] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,RB,RZ] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,+RB,+RZ][a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,-RB,-RZ][a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RT] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RTT] [a,b,c,d,e,f] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RBT] [a,b,c,d,e,f] \stopchemical \quad
+
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RN] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RTN] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RBN] \stopchemical \quad
+
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,B,R,RN] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,ROT1,B,R,RN] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,ROT2,B,R,RN] \stopchemical \quad
+ \dontleavehmode \startchemical \chemical[\ChemicalKind,ROT3,B,R,RN] \stopchemical \quad
+
+\stopbuffer
+
+\dontcomplain
+
+% \startTEXpage
+
+\setupchemicalframed[frame=on]
+
+% \startTEXpage
+% \noindent \startchemical \chemical[THREE, B,R,RZ][RZ_1,RZ_2,RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT1,B,R,RZ][RZ_1,RZ_2,RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B,R,RZ][RZ_1,RZ_2,RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B,R,RZ][RZ_1,RZ_2,RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B,R,RZ][RZ_1,RZ_2,RZ_3]\stopchemical
+
+% \noindent \startchemical \chemical[THREE, B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3]\stopchemical
+
+% \noindent \startchemical \chemical[THREE, B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3]\stopchemical
+% \stopTEXpage
+
+% \startTEXpage
+% \noindent \startchemical \chemical[SIX,ROT1,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT2,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT3,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT4,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[SIX,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[SIX,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[SIX,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \stopTEXpage
+
+% \startTEXpage
+% \noindent \startchemical \chemical[FIVE,ROT1,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT2,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT3,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT4,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[FIVE,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[FIVE,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FIVE,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \stopTEXpage
+
+% \startTEXpage
+% \noindent \startchemical \chemical[FOUR,ROT1,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT2,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT3,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT4,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[FOUR,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[FOUR,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[FOUR,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \stopTEXpage
+
+% \startTEXpage
+% \noindent \startchemical \chemical[THREE,ROT1,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[THREE,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6]\stopchemical
+
+% \noindent \startchemical \chemical[THREE,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \noindent \startchemical \chemical[THREE,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6]\stopchemical
+% \stopTEXpage
+
+% \startTEXpage
+% \noindent \startchemical \chemical[EIGHT,ROT1,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6,RZ_7,RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT2,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6,RZ_7,RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT3,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6,RZ_7,RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT4,B, R, RZ, AU][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6,RZ_7,RZ_8]\stopchemical
+
+% \noindent \startchemical \chemical[EIGHT,ROT1,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6,-RZ_7,-RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT2,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6,-RZ_7,-RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT3,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6,-RZ_7,-RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT4,B,-R,-RZ][-RZ_1,-RZ_2,-RZ_3,-RZ_4,-RZ_5,-RZ_6,-RZ_7,-RZ_8]\stopchemical
+
+% \noindent \startchemical \chemical[EIGHT,ROT1,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6,+RZ_7,+RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT2,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6,+RZ_7,+RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT3,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6,+RZ_7,+RZ_8]\stopchemical
+% \noindent \startchemical \chemical[EIGHT,ROT4,B,+R,+RZ][+RZ_1,+RZ_2,+RZ_3,+RZ_4,+RZ_5,+RZ_6,+RZ_7,+RZ_8]\stopchemical
+% \stopTEXpage
+
+% \enabletrackers[chemistry.molecules]
+
+% \startchemicalformula
+% \chemical{S}
+% \chemical{+}
+% \chemical{O_2}
+% \chemical{GIVES}
+% \chemical{\+{4}{S}}
+% \chemical{\+{4}{S}\-{2}{O_2}}
+% \chemical{\-{2}{O_2}}
+% \stopchemicalformula
+
+% \startformula
+% \chemical{S}
+% \chemical{+}
+% \chemical{O_2}
+% \chemical{GIVES}
+% \chemical{\+{4}{S}}
+% \chemical{\+{4}{S}\-{2}{O_2}}
+% \chemical{\-{2}{O_2}}
+% \stopformula
+
+
+\startTEXpage[offset=2cm]
+
+\startchemical[width=fit,size=small,scale=small,frame=on]
+ \chemical[SIX,B]
+\stopchemical
+
+% \startchemical[width=fit,size=small,scale=small,frame=on]
+% \chemical[ONE,SB258]
+% \stopchemical
+
+% \startchemical[width=fit,size=small,scale=small,frame=on]
+% \chemical[ONE,ROT3,SB258]
+% \stopchemical
+
+% \startchemical[width=fit,size=small,scale=small,frame=on]
+% \chemical[FIVE,ROT3,SB34,+SB2,-SB5,Z345,DR35,SR4,CRZ35,SUB1,ONE,SB258,Z0,Z28][C,N,C,O,O,CH,COOC_2H_5,COOC_2H_5]
+% \stopchemical
+
+% \startchemical[scale=small,width=8000,height=8000,frame=on]
+% \chemical[SIX,SB2356,DB14,Z2346,SR36,RZ36] [C,N,C,C,H,H_2]
+% \chemical[PB:Z1,ONE,Z0,DIR8,Z0,SB24,DB7,Z27,PE][C,C,CH_3,O]
+% \chemical[PB:Z5,ONE,Z0,DIR6,Z0,SB24,DB7,Z47,PE][C,C,H_3C,O]
+% \chemical[SR24,RZ24] [CH_3,H_3C]
+% \stopchemical
+
+% \startchemical[scale=small,width=6000,height=6000,frame=on]
+% \chemical[SIX,SB2356,DB14,Z,SR36,RZ36,SR1245,RZ24][C,C,N,C,C,C,H,H_2,CH_3,H_3C]
+% \chemical[PB:RZ1,ONE,Z0,SB2,DB7,Z27,PE][C,CH_3,O]
+% \chemical[PB:RZ5,ONE,Z0,SB4,DB7,Z47,PE][C,H_3C,O]
+% \stopchemical
+
+% \startchemical[width=fit,size=small,scale=small,frame=on]
+% \chemical
+% [SIX,B,C,ADJ1,FIVE,ROT3,SB34,+SB2,-SB5,Z345,DR35,SR4,CRZ35,SUB1,ONE,OFF1,SB258,Z0,Z28]
+% [C,N,C,O,O,CH,COOC_2H_5,COOC_2H_5]
+% \stopchemical
+
+% \startchemical[width=fit,height=fit,frame=on,scale=small]
+% \chemical
+% [ONE,SB15,DB7,Z057,3OFF1,MOV1,Z0,3OFF1,MOV1,
+% Z017,SB1357,MOV3,Z0,MOV3,SB1357,Z013,3OFF5,
+% MOV5,Z0,3OFF5,SB5,Z5]
+% [C,H_2N,NH,(CH_2)_3,C,COOH,H,\SL{NH},C,COOH,H,
+% (CH_2)_2,HOOC]
+% \stopchemical
+
+% \startchemical[width=fit,height=fit,frame=on,scale=small]
+% \chemical
+% [ONE,SB15,DB7,Z057,3OFF1,MOV1,Z0,3OFF1,MOV1,Z017,SB1357,MOV3,Z0,MOV3,SB1357,Z013,3OFF5,MOV5,Z0,3OFF5,SB5,Z5]
+% [C,H_2N,NH,(CH_2)_3,C,COOH,H,\SL{NH},C,COOH,H,(CH_2)_2,HOOC]
+% \stopchemical
+
+% \startchemical
+% \chemical[ONE,Z0,DB,Z][C_0,C_1,C_1,C_3,C_4,C_5,C_6,C_7,C_8]
+% \stopchemical
+
+% \startchemical
+% \chemical[ONE,Z0,SB,Z][C_0,C_1,C_1,C_3,C_4,C_5,C_6,C_7,C_8]
+% \stopchemical
+
+% \startchemical
+% \chemical[ONE,Z0,DB,CZ][C_0,C_1,C_1,C_3,C_4,C_5,C_6,C_7,C_8]
+% \stopchemical
+
+% \startchemical
+% [width=fit,top=2000,bottom=2000,
+% scale=small,size=small]%
+% \chemical
+% [ONE,
+% SAVE,
+% Z0,SB731,MOV1,Z0,SB1,MOV1,Z0,DB8,CZ8,SB1,Z1,
+% RESTORE,
+% SAVE,
+% SUB4,ONE,Z0,SB3,SB1,MOV1,Z0,SB1,MOV1,Z0,DB8,CZ8,SB1,Z1,
+% RESTORE,
+% SUB2,ONE,Z0,SB7,SB1,MOV1,Z0,SB1,MOV1,Z0,DB8,CZ8,SB1,Z1]
+% [\SR{HC},O,C,O,C_{19}H_{39},
+% \SR{H_{2}C},O,C,O,C_{17}H_{29},
+% \SR{H_{2}C},O,C,O,C_{21}H_{41}]
+% \stopchemical
+
+% \chemical[width=fit,height=fit,frame=on,scale=small]
+% [ONE,Z0,MOV7,SB1357,Z017,3OFF5,MOV5,Z0,3OFF5,MOV5,SB15,DB7,Z057,MOV0,MOV3,SB1357,Z013,MOV5,3OFF5,Z0,6OFF5,SB5,Z5]
+% [\SL{NH},C,COOH,H,(CH_2)_3,C,H_2H,NH,C,COOH,H,(CH_2)_2,HOOC]
+% \stopchemical
+
+% \chemical[width=fit,height=fit,frame=on,scale=small]
+% [ONE,Z0,MOV7,SB1357,Z017,3OFF5,MOV5,Z0,3OFF5,MOV5,SB15,DB7,Z057,MOV0,MOV3,SB1357,Z013,MOV5,3OFF5,Z0,6OFF5,SB5,Z5]
+% [\SL{NH},C,COOH,H,(CH_2)_3,C,H_2H,NH,C,COOH,H,(CH_2)_2,HOOC]
+% \stopchemical
+
+% \startchemical[width=fit,top=1500,bottom=3500]
+% \chemical[ONE,Z0,DB1,SB3,SB7,Z7,MOV1,Z0,SB3,SB7,Z3,Z7,MOV0,SUB2,SIX,B,R6,C][C,H,C,H,H]
+% \chemical[ONE,Z0,DB1,SB3,SB7,Z7,MOV1,Z0,SB3,SB7,Z3,Z7,MOV0,SUB2,SIX,B,R6,C][C,H,C,H,H]
+% \bottext{styreen}
+% \stopchemical
+
+% \startchemical
+% \chemical[SPACE,PLUS,SPACE]
+% \stopchemical
+% \startchemical[right=600]
+% \chemical[ONE,CZ0][3CH_{3}OH]
+% \stopchemical
+% \startchemical
+% \chemical[SPACE,GIVES,SPACE,SPACE][H^+/H_2O]
+% \stopchemical
+% \startchemical
+% \chemical
+% [ONE,
+% SAVE,
+% Z0,SB7,SB3,SB1,Z1,
+% RESTORE,
+% SAVE,
+% SUB4,ONE,Z0,SB3,SB1,Z1,
+% RESTORE,
+% SUB2,ONE,Z0,SB7,SB1,Z1]
+% [\SR{HC},OH,
+% \SR{H_{2}C},OH,
+% \SR{H_{2}C},OH]
+% \stopchemical
+% \startchemical
+% \chemical[SPACE,PLUS,SPACE]
+% \stopchemical
+
+% \startchemical
+% \chemical
+% [ONE,
+% SAVE,
+% Z0,DB8,CZ8,SB1,SB5,Z5,MOV1,Z0,SB1,Z1,
+% RESTORE,
+% SAVE,
+% SUB4,ONE,Z0,DB8,CZ8,SB1,SB5,Z5,MOV1,Z0,SB1,Z1,
+% RESTORE,
+% SUB2,ONE,Z0,DB8,CZ8,SB1,SB5,Z5,MOV1,Z0,SB1,Z1]
+% [C,O,C_{19}H_{39},O,CH_{3},
+% C,O,C_{17}H_{29},O,CH_{3},
+% C,O,C_{21}H_{41},O,CH_{3}]
+% \stopchemical
+
+% \startchemical[height=4500,bottom=2500]
+% \bottext{$\beta$-D-Fructopyranose}
+% \chemical[SIX,FRONT,BB,B1236,+SB4,-SB5,Z5,+R12346,+RZ12346,-R12346,-RZ12346][Z_0,+R_1,+R_2,+R_3,+R_4,+R_6,-R_1,-R_2,-R_3,-R_4,-R_6]
+% \stopchemical
+
+% \startchemical[height=4500,bottom=2500]
+% \chemical[SIX,FRONT,BB,B]
+% \stopchemical
+
+% \startchemical
+% [width=fit,height=fit,frame=on]
+% \chemical
+% [SIX,DB135,SB246,Z,SR6,RZ6][C,C,N,\SR{HC},N,C,NH_2]
+% \chemical
+% [SIX,MOV1,DB1,SB23,SS6,Z1..3,SR3,RZ3][N,\SL{CH},N,H]
+% \stopchemical
+
+% \startchemical \chemical[SIX,B,R,RZ1=a] \stopchemical
+% \startchemical \chemical[SIX,B,R,RZ1..3=a] \stopchemical
+% \startchemical \chemical[SIX,B,R,RZ135=a] \stopchemical
+% \startchemical \chemical[SIX,B,R,RZ] [a] \stopchemical
+% \startchemical \chemical[SIX,B,R,RZ] [a,b] \stopchemical
+% \startchemical \chemical[SIX,B,R,RZ=a] \stopchemical
+
+% \definechemical[molecule]
+% {\chemical
+% [ONE,Z0,SB1357,
+% SAVE,SUB2,SIX,B,R6,C,RESTORE,
+% MOV1,Z0,SB137,MOV1,Z0,SB37,MOV1]
+% [C,C,C]}
+
+% \startchemical[width=fit,height=fit]
+% \chemical[molecule,molecule,molecule]
+% \stopchemical
+
+% \definechemical[molecule]
+% {\chemical
+% [ONE,Z0,SB1357,
+% SAVE,SUB2,SIX,B,R6,C,RESTORE,
+% MOV1,Z0,SB137,MOV1,Z0,SB37,MOV1]}
+
+% \startchemical[width=fit,height=fit]
+% \chemical[molecule,molecule,molecule][A,B,C,D,E,F,G,H,I]
+% \stopchemical
+
+\stopTEXpage
+
+% \noindent \startchemical
+% \chemical[SIX,B1..3]
+% \stopchemical
+
+% \noindent \startchemical[width=fit,height=fit] % auto5 ipb off5
+% \chemical[SIX,B,C,R,RZ][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]
+% \stopchemical
+% \noindent \startchemical[width=fit,height=fit] % auto5 ipb off5
+% \chemical[SIX,ROT1,B,C,R,RZ][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]
+% \stopchemical
+% \startchemical[width=fit,height=fit] % auto5 ipb off5
+% \chemical[SIX,ROT2,B,C,R,RZ][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]
+% \stopchemical
+% \startchemical[width=fit,height=fit] % auto5 ipb off5
+% \chemical[SIX,ROT3,B,C,R,RZ][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]
+% \stopchemical
+% \startchemical[width=fit,height=fit] % auto5 ipb off5
+% \chemical[SIX,ROT4,B,C,R,RZ][RZ_1,RZ_2,RZ_3,RZ_4,RZ_5,RZ_6]
+% \stopchemical
+
+% \startchemical[width=fit,height=fit,axis=on] % auto5 ipb off5
+% \chemical[SIX,B,C,R6,PB:RZ6,ONE,CZ0,OE1,SB5,MOV5,CZ0,OFF5,OE5,PE][CH,CH_2]
+% \stopchemical
+
+% \dontleavehmode \startchemical \chemical[SIX,B,R,RZ][1,2,3,4,5,6,] \stopchemical
+
+% \start
+% \setupchemicalframed[frame=off]
+% \dontleavehmode \startchemical[scale=medium,style=slanted,color=red,rulecolor=green,left=2000,right=4000,top=2000,bottom=2000,axis=on] \chemical[SIX,B,R,RZ][1,2,3,4,5,6,] \stopchemical
+
+% \dontleavehmode
+% \startchemical[width=fit,height=fit]
+% \chemical[SIX,B][1,2,3,4,5,6]
+% \start
+% \setupchemical[rulecolor=red]
+% \chemical[SIX,R][1,2,3,4,5,6]
+% \stop
+% \chemical[SIX,RZ][1,2,3,4,5,6]
+% \stopchemical
+% \stop
+
+% \stopTEXpage
+
+% \stoptext
+
+% \startTEXpage
+
+% \dontleavehmode \startchemical \chemical[ONE,SB,Z0,Z][0,1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,DB,Z0,Z][0,1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,TB,Z0,Z][0,1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,EP,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,ES,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,ED,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,ET,Z0][0] \stopchemical \quad
+
+
+% \dontleavehmode \startchemical \chemical[ONE,SD,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,LDD,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,RDD,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,HB,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,BB,Z0][0] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,OE,Z0][0] \stopchemical \quad
+
+
+% \dontleavehmode \startchemical \chemical[ONE,SB,Z] [1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,CZ][1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZT][a,b,c,d,e,f,g,h] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZN][1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZBT][1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZBN][1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZTT][1,2,3,4,5,6,7,8] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,ZTN][1,2,3,4,5,6,7,8] \stopchemical \quad
+
+% \dontleavehmode \startchemical \chemical[ONE,SB,MOV1,SB] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[ONE,SB,MOV1,SB,MOV3,SB] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,MOV1,B] \stopchemical \quad
+
+
+% \dontleavehmode \startchemical \chemical[ONE,SB,Z0,Z][0,1,2,3,4,5,6] \stopchemical \quad
+% \stopTEXpage
+
+
+% \dorecurse{1000}{\dontleavehmode \startchemical \chemical[SIX,B,R,RZ][a,b,c,d,e,f] \stopchemical \quad}
+
+% \dontleavehmode \startchemical \chemical[SIX,B,R,RT] [a,b,c,d,e,f] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,R,RTT] [a,b,c,d,e,f] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,R,RBT] [a,b,c,d,e,f] \stopchemical \quad
+
+% \dontleavehmode \startchemical \chemical[SIX,B,R,+R,-R] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B1..4] \stopchemical \quad
+
+% \dontleavehmode \startchemical \chemical[SIX,B,ZN] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,ZT][A,B,C,D,E,F] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,R,AU] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,R,AD] \stopchemical \quad
+
+% \dontleavehmode \startchemical \chemical[SIX,B,ADJ1,SIX,B] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,ADJ1,FIVE,ROT1,B] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,ADJ1,FOUR,B] \stopchemical \quad
+% \dontleavehmode \startchemical \chemical[SIX,B,ADJ1,THREE,B] \stopchemical \quad
+
+% \definechemical[sixring]
+% {\chemical[SIX,B,R]}
+
+% \startchemical[frame=on,width=6000]
+% \chemical[sixring,RZ][A,B,C,D,E,F]
+% \stopchemical
+
+% \definechemical[test]
+% {\chemical[SIX,SB,Z][A,B,C,D,E,F]}
+
+% \startchemical
+% \chemical[SIX,SB,Z,ADJ1,test,ADJ1,SIX,SB,Z][a,b,c,d,e,f,g,h,j,k,l,m,P,Q,R,S,T,U,W]
+% \chemical[ADJ1,SIX,SB,Z][1,2,3,4,5,6]
+% \stopchemical
+
+% \definechemical[test]{\chemical[SIX,SB,Z]}
+
+% \startchemical
+% \chemical[SIX,SB,Z,ADJ1,test,ADJ1,SIX,SB,Z][a,b,c,d,e,f,g,h,j,k,l,m,P,Q,R,S,T,U,W]
+% \chemical[ADJ1,SIX,SB,Z][1,2,3,4,5,6]
+% \stopchemical
+
+% \startchemical
+% \chemical[ADJ1,SIX,SB,Z][a_1,a_2,a_3,a_4,a_5,\ominus]
+% \stopchemical
+
+% \startchemical
+% \chemical[SIX,SB,Z,SAVE,ADJ1,SIX,SB,Z,ADJ1,SIX,SB,Z,RESTORE,ADJ3,SIX,SB,Z][1,2,3,4,5,6,a,b,c,d,e,f,A,B,C,D,E,F,!,!,!,!,!,!]
+% \stopchemical
+
+% $$
+% \startchemical
+% \chemical[OPENCOMPLEX]
+% \stopchemical
+% \startchemical
+% \chemical[SIX,SB,Z][1,2,3,4,5,6]
+% \stopchemical
+% \startchemical
+% \chemical[SPACE,GIVES,SPACE][a,b]
+% \stopchemical
+% \startchemical
+% \chemical[SIX,SB,Z][1,2,3,4,5,6]
+% \stopchemical
+% \startchemical
+% \chemical[CLOSECOMPLEX]
+% \stopchemical
+% $$
+
+% \stoptext
+
+% \page
+
+% \def\ChemicalKind{SIX} \getbuffer[test-set]
+% \def\ChemicalKind{FIVE} \getbuffer[test-set]
+% \def\ChemicalKind{FOUR} \getbuffer[test-set]
+% \def\ChemicalKind{THREE} \getbuffer[test-set]
+
+% \startchemical
+% \chemical[SIX,SB,C135,SR,Z0,Z,RZ][X,ch:r->A,ch:g->B,ch:b->C,D,E,F,a,b,c,d,e,f]
+% \chemical[MOV1,SIX,SB,C135,SR,Z0,Z,RZ][X,ch:r->A,ch:g->B,ch:b->C,D,E,F,a,b,c,d,e,f]
+% \chemical[MOV3,SIX,SB,C135,SR,Z0,Z,RZ][X,ch:r->A,ch:g->B,ch:b->C,D,E,F,a,b,c,d,e,f]
+% \stopchemical
+
+\stoptext
diff --git a/tex/context/base/chem-str.lua b/tex/context/base/chem-str.lua
new file mode 100644
index 000000000..8ab48fca2
--- /dev/null
+++ b/tex/context/base/chem-str.lua
@@ -0,0 +1,488 @@
+if not modules then modules = { } end modules ['chem-str'] = {
+ version = 1.001,
+ comment = "companion to chem-str.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This module in incomplete and experimental.
+
+-- We can push snippets into an mp instance.
+
+local trace_structure = false trackers.register("chemistry.structure", function(v) trace_structure = v end)
+local trace_textstack = false trackers.register("chemistry.textstack", function(v) trace_textstack = v end)
+
+local format, gmatch, match, lower, gsub = string.format, string.gmatch, string.match, string.lower, string.gsub
+local concat, insert, remove = table.concat, table.insert, table.remove
+local apply = structure.processors.apply
+local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
+
+local variables = interfaces.variables
+
+chemicals = chemicals or { }
+
+chemicals.instance = "metafun" -- "ppchtex"
+chemicals.format = "metafun"
+chemicals.structures = 0
+
+local remapper = {
+ ["+"] = "p",
+ ["-"] = "m",
+}
+
+local common_keys = {
+ b = "line", eb = "line", db = "line", er = "line", dr = "line", br = "line",
+ sb = "line", msb = "line", psb = "line",
+ r = "line", pr = "line", mr = "line",
+ au = "line", ad = "line",
+ rb = "line", mrb = "line", prb = "line",
+ rd = "line", mrd = "line", prd = "line",
+ sr = "line", msr = "line", psr = "line",
+ c = "line", cc = "line", cd = "line", ccd = "line",
+ rn = "number", rtn = "number", rbn = "number",
+ s = "line", ss = "line", pss = "line", mss = "line",
+ mid = "fixed", mids = "fixed", midz = "text",
+ z = "text", rz = "text", mrz = "text", prz = "text", crz = "text",
+ rt = "text", rtt = "text", rbt = "text", zt = "text", zn = "number",
+ mov = "transform", rot = "transform", adj = "transform", dir = "transform", sub = "transform",
+}
+
+local front_keys = {
+ b = "line", bb= "line",
+ sb = "line", msb = "line", psb = "line",
+ r = "line", pr = "line", mr = "line",
+ z = "text", mrz = "text", prz = "text",
+}
+
+local one_keys = {
+ sb = "line", db = "line", tb = "line",
+ ep = "line", es = "line", ed = "line", et = "line",
+ sd = "line", ldd = "line", rdd = "line",
+ hb = "line", bb = "line", oe = "line",
+ z = "text", cz = "text", zt = "text", zn = "number",
+ zbt = "text", zbn = "number", ztt = "text", ztn = "number",
+ mov = "transform", sub = "transform", dir = "transform", off = "transform",
+}
+
+local front_align = {
+ mrz = { { "b","b","b","b","b","b" } },
+ prz = { { "t","t","t","t","t","t" } },
+}
+
+local syntax = {
+ one = {
+ n = 1, max = 8, keys = one_keys,
+ align = {
+ z = { { "r", "r_b", "b", "l_b", "l", "l_t", "t", "r_t" } },
+--~ z = { { "r", "r", "b", "l", "l", "l", "t", "r" } },
+ }
+ },
+ three = {
+ n = 3, max = 3, keys = common_keys,
+ align = {
+ mrz = { { "r","b","l" }, { "b","l","t" }, { "l","t","r" }, { "t","r","b" } },
+ rz = { { "r","l_b","l_t" }, { "b","l_t","r_t" }, { "l","r_t","r_b" }, { "t","r_b","l_b" } },
+ prz = { { "r","l","t" }, { "b","t","r" }, { "l","r","b" }, { "t","b","l" } },
+ }
+ },
+ four = {
+ n = 4, max = 4, keys = common_keys,
+ align = {
+ mrz = { { "t","r","b","l" }, { "r","b","l","t" }, { "b","l","t","r" }, { "l","t","r","b" } },
+ rz = { { "r_t","r_b","l_b","l_t" }, { "r_b","l_b","l_t","r_t" }, { "l_b","l_t","r_t","r_b" }, { "l_t","r_t","r_b","l_b" } },
+ prz = { { "r","b","l","t" }, { "b","l","t","r" }, { "l","t","r","b" }, { "t","r","b","l" } },
+ }
+ },
+ five = {
+ n = 5, max = 5, keys = common_keys,
+ align = {
+ mrz = { { "t","r","b","b","l" }, { "r","b","l","l","t" }, { "b","l","t","r","r" }, { "l","t","r","r","b" } },
+ rz = { { "r","r","b","l","t" }, { "b","b","l","t","r" }, { "l","l","t","r","b" }, { "t","t","r","b","l" } },
+ prz = { { "r","b","l","t","t" }, { "b","l","t","r","r" }, { "l","t","r","b","b" }, { "t","r","b","l","l" } },
+ }
+ },
+ six = {
+ n = 6, max = 6, keys = common_keys,
+ align = {
+ mrz = { { "t","t","r","b","b","l" }, { "r","b","b","l","t","t" }, { "b","b","l","t","t","r" }, { "l","t","t","r","b","b" } },
+ rz = { { "r","r","b","l","l","t" }, { "b","b","l","t","t","r" }, { "l","l","t","r","r","b" }, { "t","t","r","b","b","l" } },
+ prz = { { "r","b","l","l","t","r" }, { "b","l","t","t","r","b" }, { "l","t","r","r","b","l" }, { "t","r","b","b","l","t" } },
+ }
+ },
+ eight = {
+ n = 8, max = 8, keys = common_keys,
+ align = { -- todo
+ mrz = { { "t","r","r","b","b","l","l","t" }, { "r","b","b","l","l","t","t","r" }, { "b","l","l","t","t","r","r","b" }, { "l","t","t","r","r","b","b","l" } },
+ rz = { { "r","r","b","b","l","l","t","t" }, { "b","b","l","l","t","t","r","r" }, { "l","l","t","t","r","r","b","b" }, { "t","t","r","r","b","b","l","l" } },
+ prz = { { "r","b","b","l","l","t","t","r" }, { "b","l","l","t","t","r","r","b" }, { "l","t","t","r","r","b","b","l" }, { "t","r","r","b","b","l","l","t" } },
+ }
+ },
+ five_front = {
+ n = -5, max = 5, keys = front_keys, align = front_align,
+ },
+ six_front = {
+ n = -6, max = 6, keys = front_keys, align = front_align,
+ },
+ pb = { direct = 'chem_pb ;' },
+ pe = { direct = 'chem_pe ;' },
+ save = { direct = 'chem_save ;' },
+ restore = { direct = 'chem_restore ;' },
+ space = { direct = 'chem_symbol("\\chemicalsymbol[space]") ;' },
+ plus = { direct = 'chem_symbol("\\chemicalsymbol[plus]") ;' },
+ minus = { direct = 'chem_symbol("\\chemicalsymbol[minus]") ;' },
+ gives = { direct = 'chem_symbol("\\chemicalsymbol[gives]{%s}{%s}") ;', arguments = 2 },
+ equilibrium = { direct = 'chem_symbol("\\chemicalsymbol[equilibrium]{%s}{%s}") ;', arguments = 2 },
+ mesomeric = { direct = 'chem_symbol("\\chemicalsymbol[mesomeric]{%s}{%s}") ;', arguments = 2 },
+ opencomplex = { direct = 'chem_symbol("\\chemicalsymbol[opencomplex]") ;' },
+ closecomplex = { direct = 'chem_symbol("\\chemicalsymbol[closecomplex]") ;' },
+}
+
+local definitions = { }
+
+function chemicals.undefine(name)
+ definitions[name] = nil
+end
+
+function chemicals.define(name,spec,text)
+ local dn = definitions[name]
+ if not dn then dn = { } definitions[name] = dn end
+ dn[#dn+1] = {
+ spec = aux.settings_to_array(lower(spec)),
+ text = aux.settings_to_array(text),
+ }
+end
+
+local metacode, kind, keys, bonds, max, txt, textsize, rot, pstack
+local molecule = chemicals.molecule -- or use chemicals.moleculeparser:match(...)
+
+local function fetch(txt)
+ local st = stack[txt]
+ local t = st.text[st.n]
+--~ st.n = st.n + 1
+ while not t and txt > 1 do
+ txt = txt - 1
+ st = stack[txt]
+ t = st.text[st.n]
+--~ st.n = st.n + 1
+ end
+ if t then
+ if trace_textstack then
+ logs.report("chemical", "fetching from stack %s slot %s: %s",txt,st.n,t)
+ end
+st.n = st.n + 1
+ end
+ return txt, t
+end
+
+local digit = lpeg.R("09")/tonumber
+local colon = lpeg.P(":")
+local equal = lpeg.P("=")
+local other = 1 - digit - colon - equal
+local remapped = lpeg.S("+-") / remapper
+local operation = lpeg.Cs((remapped^0 * other)^1)
+local amount = digit
+local single = digit
+local special = (colon * lpeg.C(other^1)) + lpeg.Cc("")
+local range = digit * lpeg.P("..") * digit
+local set = lpeg.Ct(digit^2)
+local text = (equal * lpeg.C(lpeg.P(1)^0)) + lpeg.Cc(false)
+local pattern =
+ (amount + lpeg.Cc(1)) *
+ operation *
+ special * (
+ range * lpeg.Cc(false) * text +
+ lpeg.Cc(false) * lpeg.Cc(false) * set * text +
+ single * lpeg.Cc(false) * lpeg.Cc(false) * text +
+ lpeg.Cc(false) * lpeg.Cc(false) * lpeg.Cc(false) * text
+ )
+
+--~ local n, operation, index, upto, set, text = pattern:match("RZ1357")
+
+--~ print(pattern:match("RZ=x")) 1 RZ false false false x
+--~ print(pattern:match("RZ1=x")) 1 RZ 1 false false x
+--~ print(pattern:match("RZ1..3=x")) 1 RZ 1 3 false x
+--~ print(pattern:match("RZ13=x")) 1 RZ false false table x
+
+local function process(spec,text,n,rulethickness,rulecolor,offset)
+ insert(stack,{ spec=spec, text=text, n=n })
+ local txt = #stack
+ for i=1,#spec do
+ local s = spec[i]
+ local d = definitions[s]
+ if d then
+ for i=1,#d do
+ local di = d[i]
+ process(di.spec,di.text,1,rulethickness,rulecolor)
+ end
+ else
+ local rep, operation, special, index, upto, set, text = pattern:match(s)
+ if operation == "pb" then
+ insert(pstack,kind)
+ metacode[#metacode+1] = syntax.pb.direct
+ if keys[special] == "text" and index then
+ if keys["c"..special] == "text" then -- can be option: auto ...
+ metacode[#metacode+1] = format('chem_c%s(%s,%s,"");',special,bonds,index)
+ else
+ metacode[#metacode+1] = format('chem_%s(%s,%s,"");',special,bonds,index)
+ end
+ end
+ elseif operation == "save" then
+ insert(pstack,kind)
+ metacode[#metacode+1] = syntax.save.direct
+ elseif operation == "pe" or operation == "restore" then
+ kind = remove(pstack)
+ local ss = syntax[kind]
+ local prev = bonds or 6
+ keys, bonds, max, rot = ss.keys, ss.n, ss.max, 1
+ metacode[#metacode+1] = syntax[operation].direct
+ metacode[#metacode+1] = format("chem_set(%s,%s) ;",prev,bonds)
+ elseif operation == "front" then
+ if syntax[kind .. "_front"] then
+ kind = kind .. "_front"
+ local ss = syntax[kind]
+ local prev = bonds or 6
+ keys, bonds, max, rot = ss.keys, ss.n, ss.max, 1
+ metacode[#metacode+1] = format("chem_set(%s,%s) ;",prev,bonds)
+ end
+ elseif operation then
+ local ss = syntax[operation]
+ if ss then
+ local ds = ss.direct
+ if ds then
+ local sa = ss.arguments
+ if sa == 1 then
+ local one ; txt, one = fetch(txt)
+ metacode[#metacode+1] = format(ds,one or "")
+ elseif sa ==2 then
+ local one ; txt, one = fetch(txt)
+ local two ; txt, two = fetch(txt)
+ metacode[#metacode+1] = format(ds,one or "",two or "")
+ else
+ metacode[#metacode+1] = ds
+ end
+ elseif ss.keys then
+ local prev = bonds or 6
+ kind, keys, bonds, max, rot = s, ss.keys, ss.n, ss.max, 1
+ metacode[#metacode+1] = format("chem_set(%s,%s) ;",prev,bonds)
+ end
+ else
+ local what = keys[operation]
+ if what == "line" then
+ if set then
+ for i=1,#set do
+ local si = set[i]
+ metacode[#metacode+1] = format("chem_%s(%s,%s,%s,%s,%s);",operation,bonds,si,si,rulethickness,rulecolor)
+ end
+ elseif upto then
+ metacode[#metacode+1] = format("chem_%s(%s,%s,%s,%s,%s);",operation,bonds,index,upto,rulethickness,rulecolor)
+ elseif index then
+ metacode[#metacode+1] = format("chem_%s(%s,%s,%s,%s,%s);",operation,bonds,index,index,rulethickness,rulecolor)
+ else
+ metacode[#metacode+1] = format("chem_%s(%s,%s,%s,%s,%s);",operation,bonds,1,max,rulethickness,rulecolor)
+ end
+ elseif what == "number" then
+ if set then
+ for i=1,#set do
+ local si = set[i]
+ metacode[#metacode+1] = format('chem_%s(%s,%s,"\\dochemicaltext{%s}");',operation,bonds,si,si)
+ end
+ elseif upto then
+ for i=index,upto do
+ local si = set[i]
+ metacode[#metacode+1] = format('chem_%s(%s,%s,"\\dochemicaltext{%s}");',operation,bonds,si,si)
+ end
+ elseif index then
+ metacode[#metacode+1] = format('chem_%s(%s,%s,"\\dochemicaltext{%s}");',operation,bonds,index,index)
+ else
+ for i=1,max do
+ metacode[#metacode+1] = format('chem_%s(%s,%s,"\\dochemicaltext{%s}");',operation,bonds,i,i)
+ end
+ end
+ elseif what == "text" then
+ local align = syntax[kind].align
+ align = align and align[operation]
+ align = align and align[rot]
+ if set then
+ for i=1,#set do
+ local si = set[i]
+ local t = text
+ if not t then txt, t = fetch(txt) end
+ if t then
+ local a = align and align[si]
+ if a then a = "." .. a else a = "" end
+ metacode[#metacode+1] = format('chem_%s%s(%s,%s,"\\dochemicaltext{%s}");',operation,a,bonds,si,molecule(apply(t)))
+ end
+ end
+ elseif upto then
+ for i=index,upto do
+ local t = text
+ if not t then txt, t = fetch(txt) end
+ if t then
+ local s = align and align[i]
+ if s then s = "." .. s else s = "" end
+ metacode[#metacode+1] = format('chem_%s%s(%s,%s,"\\dochemicaltext{%s}");',operation,s,bonds,i,molecule(apply(t)))
+ end
+ end
+ elseif index == 0 then
+ local t = text
+ if not t then txt, t = fetch(txt) end
+ if t then
+ metacode[#metacode+1] = format('chem_%s_zero("\\dochemicaltext{%s}");',operation,molecule(apply(t)))
+ end
+ elseif index then
+ local t = text
+ if not t then txt, t = fetch(txt) end
+ if t then
+ local s = align and align[index]
+ if s then s = "." .. s else s = "" end
+ metacode[#metacode+1] = format('chem_%s%s(%s,%s,"\\dochemicaltext{%s}");',operation,s,bonds,index,molecule(apply(t)))
+ end
+ else
+ for i=1,max do
+ local t = text
+ if not t then txt, t = fetch(txt) end
+ if t then
+ local s = align and align[i]
+ if s then s = "." .. s else s = "" end
+ metacode[#metacode+1] = format('chem_%s%s(%s,%s,"\\dochemicaltext{%s}");',operation,s,bonds,i,molecule(apply(t)))
+ end
+ end
+ end
+ elseif what == "transform" then
+ if index then
+ for r=1,rep do
+ metacode[#metacode+1] = format('chem_%s(%s,%s);',operation,bonds,index)
+ end
+ if operation == "rot" then
+ rot = index
+ end
+ end
+ elseif what == "fixed" then
+ metacode[#metacode+1] = format("chem_%s(%s,%s,%s);",operation,bonds,rulethickness,rulecolor)
+ end
+ end
+ end
+ end
+ end
+ remove(stack)
+end
+
+-- the size related values are somewhat special but we want to be
+-- compatible
+--
+-- maybe we should default to fit
+--
+-- rulethickness in points
+
+function chemicals.start(settings)
+ chemicals.structures = chemicals.structures + 1
+ local textsize, rulethickness, rulecolor = settings.size, settings.rulethickness, settings.rulecolor
+ local width, height, scale, offset = settings.width or 0, settings.height or 0, settings.scale or "medium", settings.offset or 0
+ local l, r, t, b = settings.left or 0, settings.right or 0, settings.top or 0, settings.bottom or 0
+ if scale == variables.small then
+ scale = 500
+ elseif scale == variables.medium or scale == 0 then
+ scale = 625
+ elseif scale == variables.big then
+ scale = 750
+ else
+ scale = tonumber(scale)
+ if not scale or scale == 0 then
+ scale = 750
+ elseif scale < 500 then
+ scale = 500
+ end
+ end
+ if width == variables.fit then
+ width = true
+ else
+ width = tonumber(width) or 0
+ if l == 0 then
+ if r == 0 then
+ l = (width == 0 and 2000) or width/2
+ r = l
+ elseif width ~= 0 then
+ l = width - r
+ end
+ elseif r == 0 and width ~= 0 then
+ r = width - l
+ end
+ width = false
+ end
+ if height == variables.fit then
+ height = true
+ else
+ height = tonumber(height) or 0
+ if t == 0 then
+ if b == 0 then
+ t = (height == 0 and 2000) or height/2
+ b = t
+ elseif height ~= 0 then
+ t = height - b
+ end
+ elseif b == 0 and height ~= 0 then
+ b = height - t
+ end
+ height = false
+ end
+ scale = 0.75 * scale/625
+ metacode = { format("chem_start_structure(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ;",
+ chemicals.structures,
+ l/25, r/25, t/25, b/25, scale,
+ tostring(settings.axis == variables.on), tostring(width), tostring(height), tostring(offset)
+ ) }
+ kind, keys, bonds, stack, rot, pstack = "six", { }, 6, { }, 1, { }
+end
+
+function chemicals.stop()
+ metacode[#metacode+1] = "chem_stop_structure ;"
+ local mpcode = concat(metacode,"\n")
+ if trace_structure then
+ logs.report("chemical", "metapost code:\n%s", mpcode)
+ end
+ metapost.graphic(chemicals.instance,chemicals.format,mpcode,"")
+ metacode = nil
+end
+
+function chemicals.component(spec,text,settings)
+ rulethickness, rulecolor, offset = settings.rulethickness, settings.rulecolor
+ local spec = aux.settings_to_array(lower(spec))
+ local text = aux.settings_to_array(text)
+ metacode[#metacode+1] = "chem_start_component ;"
+ process(spec,text,1,rulethickness,rulecolor)
+ metacode[#metacode+1] = "chem_stop_component ;"
+end
+
+local inline = {
+ ["single"] = "\\chemicalsinglebond", ["-"] = "\\chemicalsinglebond",
+ ["double"] = "\\chemicaldoublebond", ["--"] = "\\chemicaldoublebond",
+ ["triple"] = "\\chemicaltriplebond", ["---"] = "\\chemicaltriplebond",
+ ["gives"] = "\\chemicalgives", ["->"] = "\\chemicalgives",
+ ["equilibrium"] = "\\chemicalequilibrium", ["<->"] = "\\chemicalequilibrium",
+ ["mesomeric"] = "\\chemicalmesomeric", ["<>"] = "\\chemicalmesomeric",
+ ["plus"] = "\\chemicalsplus", ["+"] = "\\chemicalsplus",
+ ["minus"] = "\\chemicalsminus",
+ ["space"] = "\\chemicalsspace",
+}
+
+-- todo: top / bottom
+
+function chemicals.inline(spec)
+ local spec = aux.settings_to_array(spec)
+ for i=1,#spec do
+ local s = spec[i]
+ local inl = inline[lower(s)]
+ if inl then
+ texsprint(ctxcatcodes,inl)
+ else
+ texsprint(ctxcatcodes,format("\\chemicalinline{%s}",molecule(s)))
+ end
+ end
+end
+
+statistics.register("chemical formulas", function()
+ if chemicals.structures > 0 then
+ return format("%s chemical structure formulas",chemicals.structures) -- no timing needed, part of metapost
+ end
+end)
diff --git a/tex/context/base/chem-str.mkiv b/tex/context/base/chem-str.mkiv
new file mode 100644
index 000000000..29c6fe939
--- /dev/null
+++ b/tex/context/base/chem-str.mkiv
@@ -0,0 +1,526 @@
+%D \module
+%D [ file=chem-ini,
+%D version=2009.05.13,
+%D subtitle=Chemistry,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This module in incomplete and experimental. Eventually this code
+%D will replace \PPCHTEX.
+
+\writestatus{loading}{ConTeXt Chemistry Macros / Structure}
+
+\registerctxluafile{chem-str}{1.001}
+
+% We have a slightly different interface. This is unchanged:
+%
+% \startchemical[axis=on]
+% \chemical[SIX,ROT2,B,R6,SUB1,FIVE,ROT1,B][1]
+% \stopchemical
+%
+% Here we use chemicalformula instead, so no longer a mix:
+%
+% \startchemicalformula
+% \chemical{H_2}{top}{bottom}
+% \chemical{PLUS}{top}{bottom}
+% \chemical{O}{top}{bottom}
+% \chemical{GIVES}{top}{bottom}
+% \chemical{H_2O}{top}{bottom}
+% \stopchemicalformula
+%
+% \startchemicalformula
+% \chemical{H_2}
+% \chemical{PLUS}
+% \chemical{O}
+% \chemical{GIVES}
+% \chemical{H_2O}
+% \stopchemicalformula
+%
+% The inline variant has only one argument:
+%
+% \chemical{H_2,PLUS,O,GIVES,H_2O}
+
+% todo: seven | eight | frontsix | fontfive | carbon | newmans | chair
+
+\unprotect
+
+\def\setupchemical
+ {\dosingleempty\dosetupchemical}
+
+\def\dosetupchemical
+ {\getparameters[\??cm]}
+
+\let\setupchemicals\setupchemical
+
+\def\setupchemicalframed
+ {\dosingleempty\dosetupchemicalframed}
+
+\def\dosetupchemicalframed
+ {\getparameters[\??cm:\c!frame]}
+
+\def\chemicalparameter#1{\csname\??cm#1\endcsname}
+
+\def\definechemical
+ {\dosingleargument\dodefinechemical} % global
+
+\def\dodefinechemical[#1]#2%
+ {\startnointerference
+ \ctxlua{chemicals.undefine("#1")}%
+ \def\chemical{\dodoubleempty\dostructurechemical}%
+ \def\dostructurechemical[##1][##2]{\ctxlua{chemicals.define("#1",\!!bs##1\!!es,\!!bs\detokenize{##2}\!!es)}}%
+ #2% flush
+ \stopnointerference}
+
+\def\definechemicalsymbol
+ {\dodoubleempty\dodefinechemicalsymbol}
+
+\def\dodefinechemicalsymbol[#1][#2]%
+ {\setvalue{\??cm::#1}{#2}}
+
+\def\chemicalsymbol[#1]%
+ {\getvalue{\??cm::#1}}
+
+% size (small medium big)
+
+\def\dosetchemicaltext
+ {\dosetfontattribute \??cm\c!style
+ \dosetcolorattribute\??cm\c!color}
+
+\def\dochemicaltext#1%
+ {\dosetchemicaltext\strut#1} % maybe also \setstrut
+
+\edef\chemicaltoplocation{t}
+\edef\chemicalbotlocation{b}
+
+\def\dochemicaltext#1% in ppchtex we had a more clever alignment
+ {\dosetchemicaltext\strut#1} % maybe also \setstrut
+
+\newconditional\indisplaychemical
+
+\unexpanded\def\startchemical
+ {\dosingleempty\dostartchemical}
+
+\setvalue{\??cm:\c!size:\v!small }{\txx}
+\setvalue{\??cm:\c!size:\v!medium}{\tx}
+\setvalue{\??cm:\c!size:\v!big }{}
+
+\newtoks \everychemical
+\newtoks \everystructurechemical
+\newtoks \withchemicalbox
+\newbox \chemicalbox
+\newconditional\somechemicaltext
+\newdimen \chemicalwidth
+\newdimen \chemicalheight
+\newdimen \chemicaldepth
+
+\def\dostartchemical[#1]%
+ {\ifmmode\vcenter\else\vbox\fi
+ \bgroup
+ \dontcomplain
+ \settrue\indisplaychemical
+ \forgetall
+ \getparameters[\??cm][#1]%
+ \the\everystructurechemical
+ \setbox\chemicalbox\hbox\bgroup
+ \ctxlua{chemicals.start {
+ width = "\chemicalparameter\c!width",
+ height = "\chemicalparameter\c!height",
+ left = \chemicalparameter\c!left,
+ right = \chemicalparameter\c!right,
+ top = \chemicalparameter\c!top,
+ bottom = \chemicalparameter\c!bottom,
+ scale = "\chemicalparameter\c!scale",
+ axis = "\chemicalparameter\c!axis",
+ offset = "\the\dimexpr.25em\relax",
+ } }%
+ \startnointerference}
+
+\unexpanded\def\stopchemical
+ {\stopnointerference
+ \ctxlua{chemicals.stop()}%
+ \egroup
+ \chemicalwidth \wd\chemicalbox
+ \chemicalheight\ht\chemicalbox
+ \chemicaldepth \dp\chemicalbox
+ \the\withchemicalbox
+ \doifelsenothing{\chemicalparameter\c!frame}\handlechemicalframednop\handlechemicalframedyes
+ \egroup}
+
+\def\handlechemicalframedyes
+ {\localframed%
+ [\??cm:\c!frame]%
+ [\c!frame=\chemicalparameter\c!frame,\c!align=\v!normal,\c!strut=\v!no]{\vbox{\box\chemicalbox\vss}}} % remove depth
+
+\def\handlechemicalframednop
+ {\localframed%
+ [\??cm:\c!frame]%
+ [\c!align=\v!normal,\c!strut=\v!no]{\vbox{\box\chemicalbox\vss}}} % remove depth
+
+\let\startstructurechemical\startchemical
+\let\stopstructurechemical \stopchemical
+
+\unexpanded\def\structurechemical
+ {\dotripleempty\dostructurechemical}
+
+\appendtoks
+ \let\chemical\structurechemical
+\to\everystructurechemical
+
+\def\dostructurechemical
+ {\ifthirdargument
+ \expandafter\dostructurechemicalthree
+ \else
+ \expandafter\dostructurechemicaltwo
+ \fi}
+
+\def\dostructurechemicalthree[#1][#2][#3]%
+ {\writestatus\m!chemicals{hyperlinked chemicals not yet supported}% todo reference, for the moment ignored
+ \ctxlua{chemicals.component(\!!bs#2\!!es, \!!bs\detokenize{#3}\!!es, { % maybe also pass first two args this way
+ rulethickness = "\the\dimexpr\chemicalparameter\c!rulethickness\relax", % todo: scaled points
+ rulecolor = "\MPcolor{\chemicalparameter\c!rulecolor}" % we can precalculate this for speedup
+ } ) }%
+ \ignorespaces}
+
+\def\dostructurechemicaltwo[#1][#2]%
+ {\ctxlua{chemicals.component(\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es, { % maybe also pass first two args this way
+ rulethickness = "\the\dimexpr\chemicalparameter\c!rulethickness\relax", % todo: scaled points
+ rulecolor = "\MPcolor{\chemicalparameter\c!rulecolor}" % we can precalculate this for speedup
+ } ) }%
+ \ignorespaces}
+
+\appendtoks
+ \setbox\chemicalbox\hbox{\raise\MPlly\onebasepoint\box\chemicalbox}%
+ \chemicalwidth \wd\chemicalbox
+ \chemicalheight\ht\chemicalbox
+ \chemicaldepth \dp\chemicalbox
+\to \withchemicalbox
+
+% kind of compatible, but text sizes instead of math sizes (i.e. tx is larger than scriptsize)
+
+\appendtoks
+ \edef\chemicalbodyfont{\chemicalparameter\c!bodyfont}%
+ \doifnot\chemicalbodyfont\fontbody{\switchtobodyfont[\chemicalbodyfont]}% \fontbody is not expanded (yet)
+ \getvalue{\??cm:\c!size:\chemicalparameter\c!size}%
+% \to \everystructurechemical
+\to \everychemical
+
+\def\chemicaltoptext#1{\global\settrue\somechemicaltext\gdef\thetoptext{#1}\ignorespaces}
+\def\chemicalbottext#1{\global\settrue\somechemicaltext\gdef\thebottext{#1}\ignorespaces}
+\def\chemicalmidtext#1{\global\settrue\somechemicaltext\gdef\themidtext{#1}\ignorespaces}
+
+\appendtoks
+ \let\toptext\chemicaltoptext \glet\thetoptext\empty
+ \let\bottext\chemicalbottext \glet\thebottext\empty
+ \let\midtext\chemicalmidtext \glet\themidtext\empty
+ \global\setfalse\somechemicaltext
+\to \everystructurechemical
+
+\def\doaddchemicaltexts
+ {\setbox2\hbox to \chemicalwidth{\strut\hss\hbox{\strut\themidtext}\hss}%
+ \setbox4\hbox to \chemicalwidth{\strut\hss\hbox{\strut\thetoptext}\hss}%
+ \setbox6\hbox to \chemicalwidth{\strut\hss\hbox{\strut\thebottext}\hss}%
+ \setbox\chemicalbox\hbox \bgroup
+ \box\chemicalbox
+ \hskip-\chemicalwidth
+ \raise\chemicalheight\hbox{\lower\ht4\box4}%
+ \hskip-\chemicalwidth
+ \lower.5\dimexpr\ht2-\dp2\relax\box2%
+ \hskip-\chemicalwidth
+ \lower\chemicaldepth \hbox{\raise\dp6\box6}%
+ \hss
+ \egroup} % text on top of chemicals
+
+\appendtoks
+ \ifconditional\somechemicaltext
+ \doaddchemicaltexts
+ \chemicalwidth \wd\chemicalbox
+ \chemicalheight\ht\chemicalbox
+ \chemicaldepth \dp\chemicalbox
+ \fi
+\to \withchemicalbox
+
+% todo: enspace or emspace
+
+\definechemicalsymbol[space] [\enspace\quad\enspace]
+\definechemicalsymbol[plus] [\enspace+\enspace]
+\definechemicalsymbol[minus] [\enspace-\enspace]
+\definechemicalsymbol[gives] [\dochemicalarrow\xrightarrow]
+\definechemicalsymbol[equilibrium] [\dochemicalarrow\xrightoverleftarrow]
+\definechemicalsymbol[mesomeric] [\dochemicalarrow\xleftrightarrow]
+\definechemicalsymbol[opencomplex] [\mathematics{\Bigg[}] % not yet ok
+\definechemicalsymbol[closecomplex][\mathematics{\Bigg]}] % not yet ok
+
+\definechemicalsymbol[SPACE] [{\chemicalsymbol[space]}]
+\definechemicalsymbol[PLUS] [{\chemicalsymbol[plus]}]
+\definechemicalsymbol[MINUS] [{\chemicalsymbol[minus]}]
+\definechemicalsymbol[GIVES] [{\chemicalsymbol[gives]}]
+\definechemicalsymbol[EQUILIBRIUM] [{\chemicalsymbol[equilibrium]}]
+\definechemicalsymbol[MESOMERIC] [{\chemicalsymbol[mesomeric]}]
+\definechemicalsymbol[OPENCOMPLEX] [{\chemicalsymbol[opencomplex]}]
+\definechemicalsymbol[CLOSECOMPLEX][{\chemicalsymbol[closecomplex]}]
+
+\def\dochemicalarrow#1#2#3%
+ {\enspace
+ \mathematics{#1%
+ {\strut\hbox \!!spread 2em{\hss\ctxlua{chemicals.inline(\!!bs#2\!!es)}\hss}}%
+ {\strut\hbox \!!spread 2em{\hss\ctxlua{chemicals.inline(\!!bs#3\!!es)}\hss}}}%
+ \enspace}
+
+% special macros (probably needs some more work)
+
+\def\dochemicaltop#1#2#3#4%
+ {\begingroup
+ \setbox0\hbox{\tx\setstrut\strut#3}%
+ \setbox2\hbox{\setstrut\strut\molecule{#4}}%
+ \setbox0\hbox{\raise\dimexpr\dp0+\ht2\relax\hbox to \wd2{#1\box0#2}}%
+ \smashbox0
+ \hbox{\box0\box2}%
+ \endgroup}%
+
+\def\dochemicalbottom#1#2#3#4%
+ {\begingroup
+ \setbox0\hbox{\tx\setstrut\strut#3}%
+ \setbox2\hbox{\setstrut\strut#4}%
+ \setbox0\hbox{\lower\dimexpr\dp2+\ht0\relax\hbox to \wd2{#1\box0#2}}%
+ \smashbox0
+ \hbox{\box0\box2}%
+ \endgroup}%
+
+\unexpanded\def\chemicalleft#1#2%
+ {\begingroup
+ \hbox{\llap{\tx\setstrut\strut#1}\setstrut\strut#2}%
+ \endgroup}%
+
+\unexpanded\def\chemicalright#1#2%
+ {\begingroup
+ \hbox{\setstrut\strut#2\rlap{\tx\setstrut\strut#1}}%
+ \endgroup}%
+
+\unexpanded\def\chemicaltop {\dochemicaltop \hss \hss }
+\unexpanded\def\chemicallefttop {\dochemicaltop \relax \hss }
+\unexpanded\def\chemicalrighttop {\dochemicaltop \hss \relax}
+\unexpanded\def\chemicalbottom {\dochemicalbottom \hss \hss }
+\unexpanded\def\chemicalleftbottom {\dochemicalbottom \relax \hss }
+\unexpanded\def\chemicalrightbottom {\dochemicalbottom \hss \relax}
+
+\unexpanded\def\chemicaltopleft #1{\chemicalleft {\chemicalrighttop {#1}{}}}
+\unexpanded\def\chemicalbottomleft #1{\chemicalleft {\chemicalrightbottom{#1}{}}}
+\unexpanded\def\chemicaltopright #1{\chemicalright{\chemicallefttop {#1}{}}}
+\unexpanded\def\chemicalbottomright #1{\chemicalright{\chemicalleftbottom {#1}{}}}
+
+\unexpanded\def\chemicalcentered #1{\setbox\scratchbox\hbox{C}\hbox to \wd\scratchbox{\setstrut\strut\hss#1\hss}}
+\unexpanded\def\chemicalleftcentered #1{\setbox\scratchbox\hbox{C}\hbox to \wd\scratchbox{\setstrut\strut #1\hss}}
+\unexpanded\def\chemicalrightcentered#1{\setbox\scratchbox\hbox{C}\hbox to \wd\scratchbox{\setstrut\strut\hss#1}}
+
+\let\chemicalsmashedmiddle\chemicalcentered
+\let\chemicalsmashedleft \chemicalleftcentered
+\let\chemicalsmashedright \chemicalrightcentered
+
+\unexpanded\def\chemicaloxidation#1#2#3%
+ {\chemicaltop{\txx\ifcase#2\relax0\else#1\uppercase\expandafter{\romannumeral#2}\fi}{#3}}
+
+\unexpanded\def\chemicaloxidationplus {\dotriplegroupempty\chemicaloxidation{\textplus }} % {} needed!
+\unexpanded\def\chemicaloxidationminus{\dotriplegroupempty\chemicaloxidation{\textminus}} % {} needed!
+\unexpanded\def\chemicalforeveropen {\dotriplegroupempty\chemicalleft {$\big[$}} % {} needed!
+\unexpanded\def\chemicalforeverclose {\dotriplegroupempty\chemicalright {$\big]$}} % {} needed!
+\unexpanded\def\chemicaloxidationone {\chemicaloxidation\relax1}
+\unexpanded\def\chemicaloxidationtwo {\chemicaloxidation\relax2}
+\unexpanded\def\chemicaloxidationthree{\chemicaloxidation\relax3}
+\unexpanded\def\chemicaloxidationfour {\chemicaloxidation\relax4}
+\unexpanded\def\chemicaloxidationfive {\chemicaloxidation\relax5}
+\unexpanded\def\chemicaloxidationsix {\chemicaloxidation\relax6}
+\unexpanded\def\chemicaloxidationseven{\chemicaloxidation\relax7}
+
+\appendtoks
+ \let \+\chemicaloxidationplus
+ \let \-\chemicaloxidationminus
+ \let \[\chemicalforeveropen
+ \let \]\chemicalforeverclose
+ \let \1\chemicaloxidationone
+ \let \2\chemicaloxidationtwo
+ \let \3\chemicaloxidationthree
+ \let \4\chemicaloxidationfour
+ \let \5\chemicaloxidationfive
+ \let \6\chemicaloxidationsix
+ \let \7\chemicaloxidationseven
+ \let \X\chemicaltighttext
+ \let \T\chemicaltop
+ \let \B\chemicalbottom
+ \let \L\chemicalleft
+ \let\LC\chemicalleftcentered
+ \let \R\chemicalright
+ \let\RC\chemicalrightcentered
+ \let\TL\chemicaltopleft
+ \let\BL\chemicalbottomleft
+ \let\TR\chemicaltopright
+ \let\BR\chemicalbottomright
+ \let\LT\chemicallefttop
+ \let\LB\chemicalleftbottom
+ \let\RT\chemicalrighttop
+ \let\RB\chemicalrightbottom
+ \let\SL\chemicalsmashedleft
+ \let\SM\chemicalsmashedmiddle
+ \let\SR\chemicalsmashedright
+\to \everychemical
+
+\appendtoks
+ \the\everychemical
+\to \everystructurechemical
+
+% inline
+
+\unexpanded\def\chemical
+ {\ifinformula
+ \expandafter\displaychemical
+ \else
+ \expandafter\inlinechemical
+ \fi}
+
+\def\displaychemical
+ {\dotriplegroupempty\dodisplaychemical}
+
+\def\dodisplaychemical#1#2#3% todo:
+ {\the\everychemical \everychemical\emptytoks
+ \quad
+ \vcenter\bgroup
+ \ifthirdargument
+ \ifsecondargument
+ \halign{&\hss##\hss\cr#2\cr\molecule{#1}\cr#3\cr}%
+ \else
+ \halign{&\hss##\hss\cr\molecule{#1}\cr#2\cr}%
+ \fi
+ \else
+ \hbox{\molecule{#1}}%
+ \fi
+ \egroup
+ \quad}
+
+\def\inlinechemical#1%
+ {\dontleavehmode\hbox{\ctxlua{chemicals.inline(\!!bs#1\!!es)}}}
+
+\def\chemicalbondrule{\hbox{\vrule\!!height.75ex\!!depth-\dimexpr.75ex-\linewidth\relax\!!width1em\relax}}
+
+\definechemicalsymbol[i:space] [\enspace\quad\enspace]
+\definechemicalsymbol[i:plus] [\enspace\mathematics{+}\enspace]
+\definechemicalsymbol[i:minus] [\enspace\mathematics{-}\enspace]
+\definechemicalsymbol[i:gives] [\enspace\mathematics{\xrightarrow{}{}}\enspace]
+\definechemicalsymbol[i:equilibrium] [\enspace\mathematics{\xrightpverleftarrow{}{}}\enspace]
+\definechemicalsymbol[i:mesomeric] [\enspace\mathematics{\xleftrightarrow{}{}}\enspace]
+\definechemicalsymbol[i:single] [\chemicalbondrule]
+\definechemicalsymbol[i:tripple] [\hbox{\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}]
+\definechemicalsymbol[i:double] [\hbox{\chemicalbondrule\hskip-1em\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}]
+
+\def\chemicalsinglebond {\chemicalsymbol[i:single]}
+\def\chemicaldoublebond {\chemicalsymbol[i:tripple]}
+\def\chemicaltriplebond {\chemicalsymbol[i:double]}
+\def\chemicalgives {\chemicalsymbol[i:gives]}
+\def\chemicalmesomeric {\chemicalsymbol[i:mesomeric]}
+\def\chemicalequilibrium{\chemicalsymbol[i:equilibrium]}
+\def\chemicalsplus {\chemicalsymbol[i:plus]}
+\def\chemicalsminus {\chemicalsymbol[i:minus]}
+\def\chemicalsspace {\chemicalsymbol[i:space]}
+\def\chemicalinline #1{#1}
+
+% display
+
+\newconditional\formulachemicalhastop
+\newconditional\formulachemicalhasbot
+
+\newtoks\formulachemicaltop
+\newtoks\formulachemicalmid
+\newtoks\formulachemicalbot
+
+\newif\ifinchemicalformula
+
+\def\startchemicalformula
+ {\mathortext\vcenter\vbox\bgroup
+ \forgetall
+ \inchemicalformulatrue
+ \the\everychemical
+ \everychemical\emptytoks
+ \formulachemicaltop\emptytoks % not needed
+ \formulachemicalmid\emptytoks % not needed
+ \formulachemicalbot\emptytoks % not needed
+ \let\chemical\formulachemical
+ \setfalse\formulachemicalhastop
+ \setfalse\formulachemicalhasbot }
+
+\def\stopchemicalformula
+ {\tabskip1em\relax
+ \nointerlineskip
+ \ifconditional\formulachemicalhastop
+ \ifconditional\formulachemicalhasbot
+ \halign{&\hss##\hss\cr\the\formulachemicaltop\cr\the\formulachemicalmid\cr\the\formulachemicalbot\cr}%
+ \else
+ \halign{&\hss##\hss\cr\the\formulachemicaltop\cr\the\formulachemicalmid\cr}%
+ \fi
+ \else
+ \ifconditional\formulachemicalhasbot
+ \halign{&\hss##\hss\cr\the\formulachemicalmid\cr\the\formulachemicalbot\cr}%
+ \else
+ \halign{&\hss##\hss\cr\the\formulachemicalmid\cr}%
+ \fi
+ \fi
+ \egroup}
+
+\unexpanded\def\formulachemical
+ {\relax\dotriplegroupempty\doformulachemical}
+
+\def\doformulachemical#1#2#3%
+ {\ifthirdargument
+ \doifelsenothing{#2}\noformulachemicaltop{\doformulachemicaltop{#2}}%
+ \doifelsenothing{#3}\noformulachemicalbot{\doformulachemicalbot{#3}}%
+ \else\ifsecondargument
+ \noformulachemicaltop
+ \doifelsenothing{#2}\noformulachemicalbot{\doformulachemicalbot{#2}}%
+ \else
+ \noformulachemicaltop
+ \noformulachemicalbot
+ \fi\fi
+ \formulachemicalmid\expandafter{\the\formulachemicalmid\dodochemicalformulamid{#1}&}}
+
+\def\noformulachemicaltop {\formulachemicaltop\expandafter{\the\formulachemicaltop&}}
+\def\noformulachemicalbot {\formulachemicalbot\expandafter{\the\formulachemicalbot&}}
+\def\doformulachemicaltop#1{\formulachemicaltop\expandafter{\the\formulachemicaltop\dodochemicalformulatop{#1}&}\settrue\formulachemicalhastop}
+\def\doformulachemicalbot#1{\formulachemicalbot\expandafter{\the\formulachemicalbot\dodochemicalformulabot{#1}&}\settrue\formulachemicalhasbot}
+
+\def\dodochemicalformulamid#1%
+ {\ifcsname\??cm::\detokenize{#1}\endcsname\csname\??cm::\detokenize{#1}\expandafter\endcsname\else\molecule{#1}\fi{}{}}
+
+\def\dodochemicalformulatop#1{\strut#1}
+\def\dodochemicalformulabot#1{\strut#1}
+
+% gone: state option resolution offset (now frame offset) alternative
+
+\setupchemicalframed
+ [\c!align=\v!normal,
+ \c!strut=\v!no,
+ \c!offset=\v!overlay,
+ \c!frame=off]
+
+\setupchemical
+ [\c!frame=,
+ \c!width=0,
+ \c!height=0,
+ \c!left=0,
+ \c!right=0,
+ \c!top=0,
+ \c!bottom=0,
+ \c!bodyfont=\the\bodyfontsize,
+ \c!scale=\v!medium,
+ \c!size=\v!medium,
+ \c!textsize=\v!big,
+ \c!axis=\v!off,
+ \c!style=\rm,
+ \c!location=,
+ \c!color=,
+ \c!rulethickness=\linewidth,
+ \c!rulecolor=,
+ \c!factor=1]
+
+\protect \endinput
diff --git a/tex/context/base/colo-ext.mkii b/tex/context/base/colo-ext.mkii
new file mode 100644
index 000000000..06facd34e
--- /dev/null
+++ b/tex/context/base/colo-ext.mkii
@@ -0,0 +1,57 @@
+%D \module
+%D [ file=colo-ext, % mostof thsi code used to be in colo-ini.tex
+%D version=1997.04.01,
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Extras,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Color Macros / Extras}
+
+\unprotect
+
+%D \macros
+%D {negatecolorcomponent, negativecolorbox}
+%D
+%D Sometimes, especially when we deal with typesetting
+%D devices, we want to reverse the color scheme. Instead of
+%D recalculating all those colors, we use a quick and dirty
+%D approach:
+%D
+%D \starttyping
+%D \negativecolorbox0
+%D \stoptyping
+%D
+%D will negate the colors in box zero.
+
+\def\negatecolorbox#1%
+ {\setbox#1\hbox
+ {\dostartnegative
+ \localstartcolor[white]\vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1\localstopcolor
+ \hskip-\wd#1%
+ \box#1%
+ \dostopnegative}}
+
+%D There are in principle two ways to handle overprint: bound to colors
+%D or independent. For the moment we only support independent overprint
+%D handling. Here we deal with a per-document setting.
+
+\setupcolors
+ [\c!overprint=\v!no]
+
+\def\starttextoverprint
+ {\doifelse\@@cloverprint\v!yes
+ {\let\stoptextoverprint\dostopoverprint\dostartoverprint}
+ {\let\stoptextoverprint\donothing}}
+
+\let\stoptextoverprint\donothing
+
+\appendtoks \starttextoverprint \to \everystarttextproperties
+\appendtoks \stoptextoverprint \to \everystoptextproperties
+
+\protect \endinput
diff --git a/tex/context/base/colo-ext.mkiv b/tex/context/base/colo-ext.mkiv
new file mode 100644
index 000000000..06facd34e
--- /dev/null
+++ b/tex/context/base/colo-ext.mkiv
@@ -0,0 +1,57 @@
+%D \module
+%D [ file=colo-ext, % mostof thsi code used to be in colo-ini.tex
+%D version=1997.04.01,
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Extras,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Color Macros / Extras}
+
+\unprotect
+
+%D \macros
+%D {negatecolorcomponent, negativecolorbox}
+%D
+%D Sometimes, especially when we deal with typesetting
+%D devices, we want to reverse the color scheme. Instead of
+%D recalculating all those colors, we use a quick and dirty
+%D approach:
+%D
+%D \starttyping
+%D \negativecolorbox0
+%D \stoptyping
+%D
+%D will negate the colors in box zero.
+
+\def\negatecolorbox#1%
+ {\setbox#1\hbox
+ {\dostartnegative
+ \localstartcolor[white]\vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1\localstopcolor
+ \hskip-\wd#1%
+ \box#1%
+ \dostopnegative}}
+
+%D There are in principle two ways to handle overprint: bound to colors
+%D or independent. For the moment we only support independent overprint
+%D handling. Here we deal with a per-document setting.
+
+\setupcolors
+ [\c!overprint=\v!no]
+
+\def\starttextoverprint
+ {\doifelse\@@cloverprint\v!yes
+ {\let\stoptextoverprint\dostopoverprint\dostartoverprint}
+ {\let\stoptextoverprint\donothing}}
+
+\let\stoptextoverprint\donothing
+
+\appendtoks \starttextoverprint \to \everystarttextproperties
+\appendtoks \stoptextoverprint \to \everystoptextproperties
+
+\protect \endinput
diff --git a/tex/context/base/colo-ext.tex b/tex/context/base/colo-ext.tex
deleted file mode 100644
index 33e87459d..000000000
--- a/tex/context/base/colo-ext.tex
+++ /dev/null
@@ -1,57 +0,0 @@
-%D \module
-%D [ file=colo-ext, % mostof thsi code used to be in colo-ini.tex
-%D version=1997.04.01,
-%D title=\CONTEXT\ Color Macros,
-%D subtitle=Extras,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Color Macros / extras}
-
-\unprotect
-
-%D \macros
-%D {negatecolorcomponent, negativecolorbox}
-%D
-%D Sometimes, especially when we deal with typesetting
-%D devices, we want to reverse the color scheme. Instead of
-%D recalculating all those colors, we use a quick and dirty
-%D approach:
-%D
-%D \starttyping
-%D \negativecolorbox0
-%D \stoptyping
-%D
-%D will negate the colors in box zero.
-
-\def\negatecolorbox#1%
- {\setbox#1\hbox
- {\dostartnegative
- \localstartcolor[white]\vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1\localstopcolor
- \hskip-\wd#1%
- \box#1%
- \dostopnegative}}
-
-%D There are in principle two ways to handle overprint: bound to colors
-%D or independent. For the moment we only support independent overprint
-%D handling. Here we deal with a per-document setting.
-
-\setupcolors
- [\c!overprint=\v!no]
-
-\def\starttextoverprint
- {\doifelse\@@cloverprint\v!yes
- {\let\stoptextoverprint\dostopoverprint\dostartoverprint}
- {\let\stoptextoverprint\donothing}}
-
-\let\stoptextoverprint\donothing
-
-\appendtoks \starttextoverprint \to \everystarttextproperties
-\appendtoks \stoptextoverprint \to \everystoptextproperties
-
-\protect \endinput
diff --git a/tex/context/base/colo-hex.mkii b/tex/context/base/colo-hex.mkii
new file mode 100644
index 000000000..dac2e46d0
--- /dev/null
+++ b/tex/context/base/colo-hex.mkii
@@ -0,0 +1,115 @@
+%D \module
+%D [ file=colo-hex,
+%D version=2004.06.23,
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Hex Colors,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\ifx\dodododefinecolor\undefined \else
+ \endinput
+\fi
+
+\writestatus{loading}{ConTeXt Color Macros / Hexadecimal}
+
+% \edef\testcolor{\string#FFC0C0}
+% \edef\testcolor{\string#55}
+%
+% \setupcolors[state=start]
+%
+% \expanded{\definecolor[thehexcolor][\hexcolorspec\testcolor]}
+%
+% \checkhexcolor[\testcolor]
+%
+% \definecolor[thehexcolor][\testcolor]
+%
+% \starttext
+%
+% test \color[thehexcolor]{rood}
+% test \color[red]{rood}
+% test \color[\testcolor]{rood}
+%
+% \stoptext
+
+\unprotect
+
+\newdimen\hexcolorfraction \hexcolorfraction=\dimexpr(1pt/256)
+
+\chardef\hexcolorprefix=`#
+
+\def\hexcolorspec #1{\expandafter\dohexcolorspec #1\empty\empty\empty\empty\relax}
+\def\hexcolorpattern#1{\expandafter\dohexcolorpattern#1\empty\empty\empty\empty\relax}
+
+\ifx\dohexstringtonumber\undefined \def\dohexstringtonumber{"} \fi
+
+\def\hexcolorcomponent#1#2%
+ {\ifnum\dohexstringtonumber#1#2=\zerocount0\else\ifnum\dohexstringtonumber#1#2=\plusone1\else
+ \expandafter\withoutpt\the\dimexpr(\dohexstringtonumber#1#2\hexcolorfraction)%
+ \fi\fi}
+
+\def\dohexcolorspec#1#2#3#4#5#6#7#8\relax
+ {\ifx#4\empty
+ s=\hexcolorcomponent#2#3%
+ \else
+ r=\hexcolorcomponent#2#3,g=\hexcolorcomponent#4#5,b=\hexcolorcomponent#6#7%
+ \fi}
+
+\def\dohexcolorpattern#1#2#3#4#5#6#7#8\relax
+ {0\ifx#4\empty
+ S:\hexcolorcomponent#2#3%
+ \else
+ R:\hexcolorcomponent#2#3:\hexcolorcomponent#4#5:\hexcolorcomponent#6#7%
+ \fi:0:0}
+
+\def\doifhexcolorelse#1%
+ {\expandafter\dodoifhexcolorelse#10\od} % 0 is a dirty trick to catch an empty #1
+
+\def\dodoifhexcolorelse#1#2\od
+ {\ifnum`#1=\hexcolorprefix
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\docheckhexcolor#1%
+ {\doifhexcolorelse{#1}{\doifundefined{#1}{\setxvalue{\??cr#1}{\hexcolorpattern{#1}}}}\donothing}
+
+\def\checkhexcolor[#1]%
+ {\expanded{\docheckhexcolor{#1}}}
+
+\def\colorHpattern{\@EA\hexcolorpattern\@EA{\@EA*\@@cl@@h}} % * == dummy placeholder
+
+\let\dodododefinecolor\dododefinecolor % we will overload this one
+
+\def\dododefinecolor#1#2#3#4[#5][#6]%
+ {\doifhexcolorelse{#6}
+ {\setxvalue{\??cr#5}{\hexcolorpattern{#6}}}
+ {\dodododefinecolor#1#2#3#4[#5][#6]}}
+
+%D For Adam Lindsay and his XeTeX special driver:
+
+% because we intercept the zero condition, the .23pt in 1.23pt will disappear in the
+% ifcase zero part branch
+
+\def\colorhexcomponent#1%
+ {\ifdim#1\points<.005\points
+ 00\else\lchexnumbers{\the\dimexpr(255\dimexpr(#1\points)\relax+.5\points)\relax}%
+ \fi}
+
+% the faster one
+
+\newdimen\hex@color@a \hex@color@a=.005pt
+\newdimen\hex@color@b \hex@color@b=.5pt
+\chardef \hex@color@c =255
+
+\def\colorhexcomponent#1%
+ {\ifdim#1\points<\hex@color@a
+ 00\else\lchexnumbers{\the\dimexpr(#1\points*\hex@color@c+\hex@color@b)\relax}%
+ \fi}
+
+\protect \endinput
diff --git a/tex/context/base/colo-hex.mkiv b/tex/context/base/colo-hex.mkiv
new file mode 100644
index 000000000..b31321b7e
--- /dev/null
+++ b/tex/context/base/colo-hex.mkiv
@@ -0,0 +1,115 @@
+%D \module
+%D [ file=colo-hex,
+%D version=2004.06.23,
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Hex Colors,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D Not yet supported in \MKIV.
+
+\endinput
+
+\writestatus{loading}{ConTeXt Color Macros / Hexadecimal}
+
+% \edef\testcolor{\string#FFC0C0}
+% \edef\testcolor{\string#55}
+%
+% \setupcolors[state=start]
+%
+% \expanded{\definecolor[thehexcolor][\hexcolorspec\testcolor]}
+%
+% \checkhexcolor[\testcolor]
+%
+% \definecolor[thehexcolor][\testcolor]
+%
+% \starttext
+%
+% test \color[thehexcolor]{rood}
+% test \color[red]{rood}
+% test \color[\testcolor]{rood}
+%
+% \stoptext
+
+\unprotect
+
+\newdimen\hexcolorfraction \hexcolorfraction=\dimexpr1pt/256\relax
+
+\chardef\hexcolorprefix=`#
+
+\def\hexcolorspec #1{\expandafter\dohexcolorspec #1\empty\empty\empty\empty\relax}
+\def\hexcolorpattern#1{\expandafter\dohexcolorpattern#1\empty\empty\empty\empty\relax}
+
+\ifx\dohexstringtonumber\undefined \def\dohexstringtonumber{"} \fi
+
+\def\hexcolorcomponent#1#2%
+ {\ifnum\dohexstringtonumber#1#2=\zerocount0\else\ifnum\dohexstringtonumber#1#2=\plusone1\else
+ \expandafter\withoutpt\the\dimexpr(\dohexstringtonumber#1#2\hexcolorfraction)%
+ \fi\fi}
+
+\def\dohexcolorspec#1#2#3#4#5#6#7#8\relax
+ {\ifx#4\empty
+ s=\hexcolorcomponent#2#3%
+ \else
+ r=\hexcolorcomponent#2#3,g=\hexcolorcomponent#4#5,b=\hexcolorcomponent#6#7%
+ \fi}
+
+\def\dohexcolorpattern#1#2#3#4#5#6#7#8\relax
+ {0\ifx#4\empty
+ S:\hexcolorcomponent#2#3%
+ \else
+ R:\hexcolorcomponent#2#3:\hexcolorcomponent#4#5:\hexcolorcomponent#6#7%
+ \fi:0:0}
+
+\def\doifhexcolorelse#1%
+ {\expandafter\dodoifhexcolorelse#10\od} % 0 is a dirty trick to catch an empty #1
+
+\def\dodoifhexcolorelse#1#2\od
+ {\ifnum`#1=\hexcolorprefix
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\docheckhexcolor#1%
+ {\doifhexcolorelse{#1}{\doifundefined{#1}{\setxvalue{\??cr#1}{\hexcolorpattern{#1}}}}\donothing}
+
+\def\checkhexcolor[#1]%
+ {\expanded{\docheckhexcolor{#1}}}
+
+\def\colorHpattern{\@EA\hexcolorpattern\@EA{\@EA*\@@cl@@h}} % * == dummy placeholder
+
+\let\dodododefinecolor\dododefinecolor % we will overload this one
+
+\def\dododefinecolor#1#2#3#4[#5][#6]%
+ {\doifhexcolorelse{#6}
+ {\setxvalue{\??cr#5}{\hexcolorpattern{#6}}}
+ {\dodododefinecolor#1#2#3#4[#5][#6]}}
+
+%D For Adam Lindsay and his XeTeX special driver:
+
+% because we intercept the zero condition, the .23pt in 1.23pt will disappear in the
+% ifcase zero part branch
+
+\def\colorhexcomponent#1%
+ {\ifdim#1\points<.005\points
+ 00\else\lchexnumbers{\the\dimexpr(255\dimexpr(#1\points)\relax+.5\points)\relax}%
+ \fi}
+
+% the faster one
+
+\newdimen\hex@color@a \hex@color@a=.005pt
+\newdimen\hex@color@b \hex@color@b=.5pt
+\chardef \hex@color@c =255
+
+\def\colorhexcomponent#1%
+ {\ifdim#1\points<\hex@color@a
+ 00\else\lchexnumbers{\the\dimexpr(#1\points*\hex@color@c+\hex@color@b)\relax}%
+ \fi}
+
+\protect \endinput
diff --git a/tex/context/base/colo-hex.tex b/tex/context/base/colo-hex.tex
index 8d5c3f86f..7d223c131 100644
--- a/tex/context/base/colo-hex.tex
+++ b/tex/context/base/colo-hex.tex
@@ -1,119 +1,3 @@
-%D \module
-%D [ file=colo-hex,
-%D version=2004.06.23,
-%D title=\CONTEXT\ Color Macros,
-%D subtitle=Hex Colors,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
+% this is just a stub
-\beginLUATEX
- \endinput
-\endLUATEX
-
-\ifx\dodododefinecolor\undefined \else
- \endinput
-\fi
-
-\writestatus{loading}{Context Color Macros / hexadecimal}
-
-% \edef\testcolor{\string#FFC0C0}
-% \edef\testcolor{\string#55}
-%
-% \setupcolors[state=start]
-%
-% \expanded{\definecolor[thehexcolor][\hexcolorspec\testcolor]}
-%
-% \checkhexcolor[\testcolor]
-%
-% \definecolor[thehexcolor][\testcolor]
-%
-% \starttext
-%
-% test \color[thehexcolor]{rood}
-% test \color[red]{rood}
-% test \color[\testcolor]{rood}
-%
-% \stoptext
-
-\unprotect
-
-\newdimen\hexcolorfraction \hexcolorfraction=\dimexpr(1pt/256)
-
-\chardef\hexcolorprefix=`#
-
-\def\hexcolorspec #1{\expandafter\dohexcolorspec #1\empty\empty\empty\empty\relax}
-\def\hexcolorpattern#1{\expandafter\dohexcolorpattern#1\empty\empty\empty\empty\relax}
-
-\ifx\dohexstringtonumber\undefined \def\dohexstringtonumber{"} \fi
-
-\def\hexcolorcomponent#1#2%
- {\ifnum\dohexstringtonumber#1#2=\zerocount0\else\ifnum\dohexstringtonumber#1#2=\plusone1\else
- \expandafter\withoutpt\the\dimexpr(\dohexstringtonumber#1#2\hexcolorfraction)%
- \fi\fi}
-
-\def\dohexcolorspec#1#2#3#4#5#6#7#8\relax
- {\ifx#4\empty
- s=\hexcolorcomponent#2#3%
- \else
- r=\hexcolorcomponent#2#3,g=\hexcolorcomponent#4#5,b=\hexcolorcomponent#6#7%
- \fi}
-
-\def\dohexcolorpattern#1#2#3#4#5#6#7#8\relax
- {0\ifx#4\empty
- S:\hexcolorcomponent#2#3%
- \else
- R:\hexcolorcomponent#2#3:\hexcolorcomponent#4#5:\hexcolorcomponent#6#7%
- \fi:0:0}
-
-\def\doifhexcolorelse#1%
- {\expandafter\dodoifhexcolorelse#10\od} % 0 is a dirty trick to catch an empty #1
-
-\def\dodoifhexcolorelse#1#2\od
- {\ifnum`#1=\hexcolorprefix
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\docheckhexcolor#1%
- {\doifhexcolorelse{#1}{\doifundefined{#1}{\setxvalue{\??cr#1}{\hexcolorpattern{#1}}}}\donothing}
-
-\def\checkhexcolor[#1]%
- {\expanded{\docheckhexcolor{#1}}}
-
-\def\colorHpattern{\@EA\hexcolorpattern\@EA{\@EA*\@@cl@@h}} % * == dummy placeholder
-
-\let\dodododefinecolor\dododefinecolor % we will overload this one
-
-\def\dododefinecolor#1#2#3#4[#5][#6]%
- {\doifhexcolorelse{#6}
- {\setxvalue{\??cr#5}{\hexcolorpattern{#6}}}
- {\dodododefinecolor#1#2#3#4[#5][#6]}}
-
-%D For Adam Lindsay and his XeTeX special driver:
-
-% because we intercept the zero condition, the .23pt in 1.23pt will disappear in the
-% ifcase zero part branch
-
-\def\colorhexcomponent#1%
- {\ifdim#1\points<.005\points
- 00\else\lchexnumbers{\the\dimexpr(255\dimexpr(#1\points)\relax+.5\points)\relax}%
- \fi}
-
-% the faster one
-
-\newdimen\hex@color@a \hex@color@a=.005pt
-\newdimen\hex@color@b \hex@color@b=.5pt
-\chardef \hex@color@c =255
-
-\def\colorhexcomponent#1%
- {\ifdim#1\points<\hex@color@a
- 00\else\lchexnumbers{\the\dimexpr(#1\points*\hex@color@c+\hex@color@b)\relax}%
- \fi}
-
-\protect \endinput
+\loadmarkfile{colo-hex}
diff --git a/tex/context/base/colo-ini.lua b/tex/context/base/colo-ini.lua
index 777c88572..c615aad7f 100644
--- a/tex/context/base/colo-ini.lua
+++ b/tex/context/base/colo-ini.lua
@@ -18,38 +18,20 @@ if not modules then modules = { } end modules ['colo-ini'] = {
-- todo: %s -> %f
-backends = backends or { }
-backends.pdf = backends.pdf or { }
-backend = backends.pdf
+local texsprint = tex.sprint
+local concat =table.concat
+local format, gmatch, gsub, lower = string.format, string.gmatch, string.gsub, string.lower
-local texsprint, format, concat = tex.sprint, string.format, table.concat
-
-local s_template_g = "\\dodoPDFregistergrayspotcolor{%s}{%s}{%s}{%s}{%s}" -- n f d p s (p can go away)
-local s_template_r = "\\dodoPDFregisterrgbspotcolor {%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p r g b
-local s_template_c = "\\dodoPDFregistercmykspotcolor{%s}{%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p c m y k
-
-function backends.pdf.registergrayspotcolor(n,f,d,p,s) states.collect(s_template_g:format(n,f,d,p,s)) end
-function backends.pdf.registerrgbspotcolor (n,f,d,p,r,g,b) states.collect(s_template_r:format(n,f,d,p,r,g,b)) end
-function backends.pdf.registercmykspotcolor(n,f,d,p,c,m,y,k) states.collect(s_template_c:format(n,f,d,p,c,m,y,k)) end
-
-local m_template_g = "\\doPDFregistergrayindexcolor{%s}{%s}{%s}{%s}{%s}" -- n f d p s (p can go away)
-local m_template_r = "\\doPDFregisterrgbindexcolor {%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p r g b
-local m_template_c = "\\doPDFregistercmykindexcolor{%s}{%s}{%s}{%s}{%s}{%s}{%s}{%s}" -- n f d p c m y k
-
-function backends.pdf.registergrayindexcolor(n,f,d,p,s) states.collect(m_template_g:format(n,f,d,p,s)) end
-function backends.pdf.registerrgbindexcolor (n,f,d,p,r,g,b) states.collect(m_template_r:format(n,f,d,p,r,g,b)) end
-function backends.pdf.registercmykindexcolor(n,f,d,p,c,m,y,k) states.collect(m_template_c:format(n,f,d,p,c,m,y,k)) end
+ctx = ctx or { }
+ctx.aux = ctx.aux or { }
-local s_template_e = "\\doPDFregisterspotcolorname{%s}{%s}" -- name, e
+local ctxcatcodes = tex.ctxcatcodes
-function backends.pdf.registerspotcolorname(name,e)
- if e and e ~= "" then
- texsprint(tex.ctxcatcodes,format(s_template_e,name,e)) -- todo in new backend: e:gsub(" ","#20")
- end
-end
+local registrations = backends.registrations
-ctx = ctx or { }
-ctx.aux = ctx.aux or { }
+local a_color = attributes.private('color')
+local a_transparency = attributes.private('transparency')
+local a_colorspace = attributes.private('colorspace')
local a_l_c_template = "\\setevalue{(ca:%s)}{%s}" ..
"\\setevalue{(cs:%s)}{\\dosetattribute{color}{%s}}"
@@ -59,10 +41,10 @@ local f_l_c_template = "\\setvalue {(ca:%s)}{\\doinheritca{%s}}" ..
"\\setvalue {(cs:%s)}{\\doinheritcs{%s}}"
local f_g_c_template = "\\setgvalue{(ca:%s)}{\\doinheritca{%s}}" ..
"\\setgvalue{(cs:%s)}{\\doinheritcs{%s}}"
-local r_l_c_template = "\\letbeundefined{(ca:%s)}" ..
- "\\letbeundefined{(cs:%s)}"
-local r_g_c_template = "\\global\\letbeundefined{(ca:%s)}" ..
- "\\global\\letbeundefined{(cs:%s)}"
+local r_l_c_template = "\\localundefine{(ca:%s)}" ..
+ "\\localundefine{(cs:%s)}"
+local r_g_c_template = "\\globalundefine{(ca:%s)}" ..
+ "\\globalundefine{(cs:%s)}"
local a_l_t_template = "\\setevalue{(ta:%s)}{%s}" ..
"\\setevalue{(ts:%s)}{\\dosetattribute{transparency}{%s}}"
@@ -72,68 +54,68 @@ local f_l_t_template = "\\setvalue {(ta:%s)}{\\doinheritta{%s}}" ..
"\\setvalue {(ts:%s)}{\\doinheritts{%s}}"
local f_g_t_template = "\\setgvalue{(ta:%s)}{\\doinheritta{%s}}" ..
"\\setgvalue{(ts:%s)}{\\doinheritts{%s}}"
-local r_l_t_template = "\\letbeundefined{(ta:%s)}" ..
- "\\letbeundefined{(ts:%s)}"
-local r_g_t_template = "\\global\\letbeundefined{(ta:%s)}" ..
- "\\global\\letbeundefined{(ts:%s)}"
+local r_l_t_template = "\\localundefine{(ta:%s)}" ..
+ "\\localundefine{(ts:%s)}"
+local r_g_t_template = "\\globalundefine{(ta:%s)}" ..
+ "\\globalundefine{(ts:%s)}"
function ctx.aux.definecolor(name, ca, global)
if ca and ca > 0 then
if global then
- texsprint(tex.ctxcatcodes,a_g_c_template:format(name, ca, name, ca))
+ texsprint(ctxcatcodes,format(a_g_c_template, name, ca, name, ca))
else
- texsprint(tex.ctxcatcodes,a_l_c_template:format(name, ca, name, ca))
+ texsprint(ctxcatcodes,format(a_l_c_template, name, ca, name, ca))
end
else
if global then
- texsprint(tex.ctxcatcodes,r_g_c_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_g_c_template, name, name))
else
- texsprint(tex.ctxcatcodes,r_l_c_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_l_c_template, name, name))
end
end
end
function ctx.aux.inheritcolor(name, ca, global)
if ca and ca ~= "" then
if global then
- texsprint(tex.ctxcatcodes,f_g_c_template:format(name, ca, name, ca))
+ texsprint(ctxcatcodes,format(f_g_c_template, name, ca, name, ca))
else
- texsprint(tex.ctxcatcodes,f_l_c_template:format(name, ca, name, ca))
+ texsprint(ctxcatcodes,format(f_l_c_template, name, ca, name, ca))
end
else
if global then
- texsprint(tex.ctxcatcodes,r_g_c_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_g_c_template, name, name))
else
- texsprint(tex.ctxcatcodes,r_l_c_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_l_c_template, name, name))
end
end
end
function ctx.aux.definetransparent(name, ta, global)
if ta and ta > 0 then
if global then
- texsprint(tex.ctxcatcodes,a_g_t_template:format(name, ta, name, ta))
+ texsprint(ctxcatcodes,format(a_g_t_template, name, ta, name, ta))
else
- texsprint(tex.ctxcatcodes,a_l_t_template:format(name, ta, name, ta))
+ texsprint(ctxcatcodes,format(a_l_t_template, name, ta, name, ta))
end
else
if global then
- texsprint(tex.ctxcatcodes,r_g_t_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_g_t_template, name, name))
else
- texsprint(tex.ctxcatcodes,r_l_t_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_l_t_template, name, name))
end
end
end
function ctx.aux.inherittransparent(name, ta, global)
if ta and ta ~= "" then
if global then
- texsprint(tex.ctxcatcodes,f_g_t_template:format(name, ta, name, ta))
+ texsprint(ctxcatcodes,format(f_g_t_template, name, ta, name, ta))
else
- texsprint(tex.ctxcatcodes,f_l_t_template:format(name, ta, name, ta))
+ texsprint(ctxcatcodes,format(f_l_t_template, name, ta, name, ta))
end
else
if global then
- texsprint(tex.ctxcatcodes,r_g_t_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_g_t_template, name, name))
else
- texsprint(tex.ctxcatcodes,r_l_t_template:format(name, name))
+ texsprint(ctxcatcodes,format(r_l_t_template, name, name))
end
end
end
@@ -173,13 +155,15 @@ local function registerspotcolor(parent,name,parentnumber,e,f,d,p)
local kind = colors.default -- else problems with shading etc
if kind == 1 then kind = v[1] end
if kind == 2 then -- name noffractions names p's r g b
- backend.registergrayspotcolor(parent,f,d,p,v[2])
+ registrations.grayspotcolor(parent,f,d,p,v[2])
elseif kind == 3 then
- backend.registerrgbspotcolor (parent,f,d,p,v[3],v[4],v[5])
+ registrations.rgbspotcolor (parent,f,d,p,v[3],v[4],v[5])
elseif kind == 4 then
- backend.registercmykspotcolor(parent,f,d,p,v[6],v[7],v[8],v[9])
+ registrations.cmykspotcolor(parent,f,d,p,v[6],v[7],v[8],v[9])
+ end
+ if e and e ~= "" then
+ registrations.spotcolorname(parent,e)
end
- backends.pdf.registerspotcolorname(parent,e)
end
registered[parentnumber] = true
end
@@ -192,11 +176,11 @@ local function registermultitonecolor(parent,name,parentnumber,e,f,d,p) -- same
local kind = colors.default -- else problems with shading etc
if kind == 1 then kind = v[1] end
if kind == 2 then
- backend.registergrayindexcolor(parent,f,d,p,v[2])
+ registrations.grayindexcolor(parent,f,d,p,v[2])
elseif kind == 3 then
- backend.registerrgbindexcolor (parent,f,d,p,v[3],v[4],v[5])
+ registrations.rgbindexcolor (parent,f,d,p,v[3],v[4],v[5])
elseif kind == 4 then
- backend.registercmykindexcolor(parent,f,d,p,v[6],v[7],v[8],v[9])
+ registrations.cmykindexcolor(parent,f,d,p,v[6],v[7],v[8],v[9])
end
end
registered[parentnumber] = true
@@ -227,8 +211,8 @@ function ctx.defineprocesscolor(name,str,global,freeze) -- still inconsistent co
ctx.aux.definetransparent(name, 0, global) -- can be sped up
end
elseif freeze then
- local ca = attributes.list[attributes.numbers['color']] [str]
- local ta = attributes.list[attributes.numbers['transparency']][str]
+ local ca = attributes.list[a_color] [str]
+ local ta = attributes.list[a_transparency][str]
if ca then
ctx.aux.definecolor(name, ca, global)
end
@@ -239,8 +223,8 @@ function ctx.defineprocesscolor(name,str,global,freeze) -- still inconsistent co
ctx.aux.inheritcolor(name, str, global)
ctx.aux.inherittransparent(name, str, global)
-- if global and str ~= "" then -- For Peter Rolf who wants access to the numbers in Lua. (Currently only global is supported.)
- -- attributes.list[attributes.numbers['color']] [name] = attributes.list[attributes.numbers['color']] [str] or -1 -- reset
- -- attributes.list[attributes.numbers['transparency']][name] = attributes.list[attributes.numbers['transparency']][str] or -1 -- reset
+ -- attributes.list[a_color] [name] = attributes.list[a_color] [str] or attributes.unsetvalue -- reset
+ -- attributes.list[a_transparency][name] = attributes.list[a_transparency][str] or attributes.unsetvalue
-- end
end
end
@@ -250,20 +234,11 @@ function ctx.isblack(ca) -- maybe commands
return (cv and cv[2] == 0) or false
end
--- function ctx.aux.colorattribute(name)
--- local al = attributes.list[attributes.numbers['color']]
--- return al[name] or 0
--- end
--- function ctx.aux.transparencyattribute(name)
--- local al = attributes.list[attributes.numbers['transparency']]
--- return al[name] or 0
--- end
-
function ctx.definespotcolor(name,parent,str,global)
if parent == "" or parent:find("=") then
ctx.registerspotcolor(name, parent)
elseif name ~= parent then
- local cp = attributes.list[attributes.numbers['color']][parent]
+ local cp = attributes.list[a_color][parent]
if cp then
local t = str:split_settings()
if t then
@@ -284,7 +259,7 @@ function ctx.definespotcolor(name,parent,str,global)
end
function ctx.registerspotcolor(parent, str)
- local cp = attributes.list[attributes.numbers['color']][parent]
+ local cp = attributes.list[a_color][parent]
if cp then
local e = ""
if str then
@@ -297,7 +272,7 @@ end
function ctx.definemultitonecolor(name,multispec,colorspec,selfspec)
local dd, pp, nn = { }, { }, { }
- for k,v in multispec:gmatch("(%a+)=([^%,]*)") do
+ for k,v in gmatch(multispec,"(%a+)=([^%,]*)") do
dd[#dd+1] = k
pp[#pp+1] = v
nn[#nn+1] = k
@@ -307,9 +282,9 @@ function ctx.definemultitonecolor(name,multispec,colorspec,selfspec)
local nof = #dd
if nof > 0 then
dd, pp, nn = concat(dd,','), concat(pp,','), concat(nn,'_')
- local parent = (nn:lower()):gsub("[^%d%a%.]+","_")
+ local parent = gsub(lower(nn),"[^%d%a%.]+","_")
ctx.defineprocesscolor(parent,colorspec..","..selfspec,true,true)
- local cp = attributes.list[attributes.numbers['color']][parent]
+ local cp = attributes.list[a_color][parent]
if cp then
registerspotcolor (parent, name, cp, "", nof, dd, pp)
registermultitonecolor(parent, name, cp, "", nof, dd, pp)
@@ -362,28 +337,26 @@ end
function ctx.formatcolor(ca,separator)
local cv = colors.value(ca)
if cv then
- local model = cv[1]
+ local c, f, t, model = { }, 13, 13, cv[1]
if model == 2 then
- return tostring(cv[2])
+ f, t = 2, 2
elseif model == 3 then
- return concat(cv,separator,3,5)
+ f, t = 3, 5
elseif model == 4 then
- return concat(cv,separator,6,9)
- else
- return tostring(cv[13])
+ f, t = 6, 9
end
+ for i=f,t do
+ c[#c+1] = format("%0.3f",cv[i])
+ end
+ return concat(c,separator)
else
- return tostring(0)
+ return format("%0.3f",0)
end
end
function ctx.formatgray(ca,separator)
local cv = colors.value(ca)
- if cv then
- return tostring(cv[2])
- else
- return tostring(0)
- end
+ return format("%0.3f",(cv and cv[2]) or 0)
end
function ctx.colorcomponents(ca)
@@ -433,7 +406,7 @@ function ctx.pdfcolor(model,ca,default) -- todo: use gray when no color
else
local n,f,d,p = cv[10],cv[11],cv[12],cv[13]
if type(p) == "string" then
- p = p:gsub(","," ") -- brr misuse of spot
+ p = gsub(p,","," ") -- brr misuse of spot
end
return format("/%s cs /%s CS %s SCN %s scn",n,n,p,p)
end
@@ -519,23 +492,23 @@ end
function ctx.resolvempgraycolor(csa,csb,model,s)
local ca = colors.register('color',nil,'gray',s)
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
end
function ctx.resolvemprgbcolor(csa,csb,model,r,g,b)
local ca = colors.register('color',nil,'rgb',r,g,b)
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
end
function ctx.resolvempcmykcolor(csa,csb,model,c,m,y,k)
local ca = colors.register('color',nil,'cmyk',c,m,y,k)
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
end
function ctx.resolvempspotcolor(csa,csb,model,n,f,d,p)
local ca = colors.register('color',nil,'spot',n,f,d,p)
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
- texsprint(tex.ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csa,ctx.pdfcolorvalue(model,ca)))
+ texsprint(ctxcatcodes,format("\\setxvalue{%s}{%s}",csb,ctx.pdfcolorspace(model,ca)))
end
-- literals needed to inject code in the mp stream, we cannot use attributes there
@@ -544,24 +517,24 @@ end
local intransparency = false
function ctx.pdfrgbliteral(model,r,g,b)
- texsprint(tex.ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'rgb',r,g,b))))
+ texsprint(ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'rgb',r,g,b))))
end
function ctx.pdfcmykliteral(model,c,m,y,k)
- texsprint(tex.ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'cmyk',c,m,y,k))))
+ texsprint(ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'cmyk',c,m,y,k))))
end
function ctx.pdfgrayliteral(model,s)
- texsprint(tex.ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'gray',s))))
+ texsprint(ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'gray',s))))
end
function ctx.pdfspotliteral(model,n,f,d,p)
- texsprint(tex.ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'spot',n,f,d,p)))) -- incorrect
+ texsprint(ctxcatcodes,format("\\pdfliteral{%s}",ctx.pdfcolor(model,colors.register('color',nil,'spot',n,f,d,p)))) -- incorrect
end
function ctx.pdftransparencyliteral(a,t)
intransparency = true
- texsprint(tex.ctxcatcodes,format("\\pdfliteral{/Tr%s gs}",transparencies.register(nil,a,t)))
+ texsprint(ctxcatcodes,format("\\pdfliteral{/Tr%s gs}",transparencies.register(nil,a,t)))
end
function ctx.pdffinishtransparency()
if intransparency then
intransparency = false
- texsprint(tex.ctxcatcodes,"\\pdfliteral{/Tr0 gs}") -- we happen to know this -)
+ texsprint(ctxcatcodes,"\\pdfliteral{/Tr0 gs}") -- we happen to know this -)
end
end
diff --git a/tex/context/base/colo-ini.mkii b/tex/context/base/colo-ini.mkii
index 745bb1679..2d2a7bdaa 100644
--- a/tex/context/base/colo-ini.mkii
+++ b/tex/context/base/colo-ini.mkii
@@ -1,6 +1,6 @@
%D \module
%D [ file=colo-ini,
-%D version=1997.04.01,
+%D version=2007.08.08,
%D title=\CONTEXT\ Color Macros,
%D subtitle=Initialization,
%D author=Hans Hagen,
@@ -11,8 +11,872 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D We need to clean this up further but first we hav eto make sure that mkiv
+%D code works ok.
+
+\writestatus{loading}{ConTeXt Color Macros / Initialization}
+
+%D This module implements color. Since \MKII\ and \MKIV\ use a completely
+%D different approach, this module only implements a few generic mechanisms.
+
\unprotect
+\chardef\colorversion=1 % temp, needed for tracing purposes, mkiv transition
+
+%D We use a couple of local registers. That way we don't have
+%D to group when converting colors. By the way, this is not
+%D really faster. We can sqeeze half a second runtime for 50K
+%D switches on a 1G machine, but the macros will become rather
+%D ugly then. To mention one such improvement: no colon
+%D after the key character (.25 sec).
+
+\newdimen\colordimen
+\newcount\colorcount
+
+%D When typesetting for paper, we prefer using the \cap{CMYK}
+%D color space, but for on||screen viewing we prefer \cap{RGB}
+%D (the previous implementation supported only this scheme).
+%D Independant of such specifications, we support some automatic
+%D conversions:
+%D
+%D \startitemize[packed]
+%D \item convert all colors to \cap{RGB}
+%D \item convert all colors to \cap{CMYK}
+%D \item convert all colors to gray scales
+%D \stopitemize
+%D
+%D We also support optimization of colors to gray scales.
+%D
+%D \startitemize[continue]
+%D \item reduce gray colors to gray scales
+%D \item reduce \cap{CMY} components to \cap{K}
+%D \stopitemize
+%D
+%D These options are communicated by means of:
+
+\newif\ifRGBsupported
+\newif\ifCMYKsupported
+\newif\ifSPOTsupported
+\newif\ifpreferGRAY
+\newif\ifGRAYprefered
+\newif\ifreduceCMYK
+\newif\ifconverttoGRAY
+\newif\ifweightGRAY \weightGRAYtrue
+
+\newif\ifconvertMPcolors
+\newif\ifreduceMPcolors
+\newif\ifforcegrayMPcolors
+
+%D The last boolean controls reduction of \cap{CMYK} to
+%D \cap{CMY} colors. When set to true, the black component
+%D is added to the other ones.
+%D
+%D Prefering gray is not the same as converting to gray.
+%D Conversion treats each color components in a different way,
+%D while prefering is just a reduction and thus a
+%D space||saving option.
+
+\newif\iffreezecolors \freezecolorsfalse
+\newif\ifincolor % true if colors enabled
+\newif\iflocalcolor
+
+\let\colorlist \empty
+\let\currentspotcolor \empty
+\let\allspotcolors \empty
+\let\usedspotcolors \empty
+\let\usedcolorchannels\empty
+\let\currentpalet \empty
+
+%D \macros
+%D {definecolor,defineglobalcolor,definenamedcolor,definespotcolor,definemultitonecolor}
+%D
+%D \startbuffer
+%D \definecolor [blue] [c=1,m=.38,y=0,k=.64] % pantone pms 2965 uncoated m
+%D \definecolor [yellow] [c=0,m=.28,y=1,k=.06] % pantone pms 124 uncoated m
+%D
+%D \definespotcolor [blue-100] [blue] [p=1]
+%D \definespotcolor [yellow-100] [yellow] [p=1]
+%D
+%D \definemultitonecolor [pdftoolscolor] [blue=.12,yellow=.28] [c=.1,m=.1,y=.3,k=.1]
+%D
+%D \useexternalfigure[demofig][mill.png][object=no]
+%D
+%D \startcombination[4*1]
+%D {\externalfigure[demofig]} {no color}
+%D {\externalfigure[demofig][color=pdftoolscolor]} {indexed duotone}
+%D {\externalfigure[demofig][color=blue-100]} {spot color}
+%D {\externalfigure[demofig][color=yellow-100]} {spot color}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \getbuffer \typebuffer
+
+\def\definecolor {\dodoubleargument\dodefinecolor}
+\def\defineglobalcolor {\dodoubleargument\dodefineglobalcolor}
+\def\definenamedcolor {\dodoubleargument\dodefinenamedcolor}
+\def\definespotcolor {\dotripleargument\dodefinespotcolor}
+\def\definemultitonecolor{\doquadrupleempty\dodefinemultitonecolor}
+
+% check: registerusedspotcolors
+% check: registerusedcolorchannels
+
+%D \macros
+%D {doifcolorelse, doifcolor}
+%D
+%D Switching to a color is done by means of the following
+%D command. Later on we will explain the use of palets. We
+%D define ourselves a color conditional first.
+
+\ifx\doifcolorelse\undefined
+ \let\doifcolorelse\secondoftwoarguments
+ \let\doifcolor \gobbleoneargument
+\fi
+
+%D \macros
+%D {localstartcolor,localstopcolor}
+%D
+%D Simple color support, that is without nesting, is provided
+%D by:
+
+\ifx\localstartcolor\undefined
+ \let\localstartcolor\undefined
+ \let\localstopcolor \undefined
+\fi
+
+%D \macros
+%D {faststartcolor,faststopcolor}
+%D
+%D No checking for arguments and such:
+
+\ifx\faststartcolor\undefined
+ \def\faststartcolor[#1]{}
+ \def\faststopcolor {}
+\fi
+
+%D These local ones may go away in future versions.
+
+%D \macros
+%D {startcolor,stopcolor}
+%D
+%D The more save method, the one that saves the current color
+%D state and returns to this state afterward, is activated by:
+%D
+%D \showsetup{startcolor}
+
+\ifx\startcolor\undefined
+ \let\startcolor\undefined
+ \let\stopcolor \undefined
+\fi
+
+%D \macros
+%D {startcurrentcolor,stopcurrentcolor}
+
+\def\startcurrentcolor{\startcolor[\outercolorname]}
+\def\stopcurrentcolor {\stopcolor}
+
+%D \macros
+%D {color,graycolor}
+%D
+%D This leaves the simple color command:
+%D
+%D \showsetup{color}
+%D \showsetup{graycolor}
+
+\ifx\color\undefined
+ \def\color [#1]{}
+ \def\graycolor[#1]{}
+ \def\gray {\graycolor}
+\fi
+
+%D \macros
+%D {localstartraster,localstopraster,
+%D startraster,stopraster,raster}
+%D
+%D The previous conversions are not linear and treat each color
+%D component according to human perception curves. Pure gray
+%D (we call them rasters) has equal color components. In
+%D \CONTEXT\ rasters are only used as backgrounds and these
+%D don't cross page boundaries in the way color does. Therefore
+%D we don't need stacks and marks. Just to be compatible with
+%D color support we offer both 'global' and 'local' commands.
+
+\ifx\startraster\undefined
+ \def\startraster [#1]{}
+ \def\stopraster {}
+ \def\raster [#1]{}
+ \def\localstartraster[#1]{}
+ \def\localstopraster {}
+\fi
+
+%D \macros
+%D {colorvalue, grayvalue}
+%D
+%D We can typeset the color components using \type{\colorvalue} and
+%D \type{\grayvalue}. The commands:
+%D
+%D \startbuffer
+%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
+%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D show us:
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+
+\def\colorformatseparator{ }
+
+\ifx\colorvalue\undefined
+ \let\colorvalue\gobbleoneargument
+ \let\grayvalue \gobbleoneargument
+\fi
+
+% check: \currentcolorname
+% check: \outercolorname
+
+%D \macros
+%D {setupcolor}
+%D
+%D Color definitions can be grouped in files with the name:
+%D
+%D \starttyping
+%D \f!colorprefix-identifier.tex
+%D \stoptyping
+%D
+%D where \type{\f!colorprefix} is \unprotect {\tttf \f!colorprefix}.
+%D Loading such a file is done by \protect
+%D
+%D \showsetup{setupcolor}
+%D
+%D Some default colors are specified in \type{colo-rgb.tex},
+%D which is loaded into the format by:
+%D
+%D \starttyping
+%D \setupcolor[rgb]
+%D \stoptyping
+
+\let\colorstyle\empty
+
+\def\setupcolor
+ {\dosingleargument\dosetupcolor}
+
+\def\dosetupcolor[#1]%
+ {\doifnot{#1}\colorstyle
+ {\def\colorstyle{#1}%
+ \processcommalist[#1]\dodosetupcolor}}
+
+\def\dodosetupcolor#1%
+ {\makeshortfilename[\truefilename{\f!colorprefix#1}]%
+ \startreadingfile
+ \readsysfile\shortfilename
+ {\showmessage\m!colors4\colorstyle}
+ {\showmessage\m!colors5\colorstyle}%
+ \stopreadingfile}
+
+\let\usecolors\setupcolor
+
+% check: \chardef\currentcolorchannel=0
+% check: \startcolormode
+% check: \newif\iffilterspotcolor \filterspotcolorfalse
+% check: \newif\ifdoingspotcolor \doingspotcolorfalse
+% check: \registercolorchannel
+
+%D \macros
+%D {definetransparency}
+%D
+%D This command numbers to names:
+
+\def\definetransparency
+ {\dodoubleargument\dodefinetransparency}
+
+\def\setupcolors
+ {\dosingleargument\dosetupcolors}
+
+\def\resetcolorsplitting
+ {\chardef\currentcolorchannel\zerocount
+ \let\currentspotcolor\empty
+ \filterspotcolorfalse}
+
+\def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplit\fi}
+\def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplit-\fi}
+
+\def\setcolorsplitting
+ {\resetsystemmode{\v!color\colorsplitsuffix}%
+ \resetcolorsplitting
+ \processaction
+ [\@@clsplit]
+ [ c=>\chardef\currentcolorchannel1,%
+ m=>\chardef\currentcolorchannel2,%
+ y=>\chardef\currentcolorchannel3,%
+ k=>\chardef\currentcolorchannel4,%
+ r=>\chardef\currentcolorchannel5,%
+ g=>\chardef\currentcolorchannel6,%
+ b=>\chardef\currentcolorchannel7,%
+ s=>\chardef\currentcolorchannel8,%
+ \v!no=>,% \currentcolorchannel0,% all colors
+ \s!default=>,% \currentcolorchannel0,% all colors
+ \s!unknown=>\filterspotcolortrue
+ \edef\currentspotcolor{\commalistelement}]%
+ \setsystemmode{\v!color\colorsplitsuffix}%
+ \iffilterspotcolor \let\@@clrgb\v!no \fi}
+
+\ifx\dosetupcolormodel\undefined
+ \let\dosetupcolormodel\relax
+\fi
+
+\def\dosetupcolors[#1]% some no longer make sense in MkIV
+ {\getparameters[\??cl][#1]%
+ \doifelse\@@clspot\v!yes
+ \SPOTsupportedtrue
+ \SPOTsupportedfalse
+ \doifelsenothing\@@clsplit
+ \resetcolorsplitting
+ \setcolorsplitting
+ \doifelse\@@clreduction\v!yes
+ \reduceCMYKtrue
+ \reduceCMYKfalse
+ \doifelse\@@clexpansion\v!yes
+ \freezecolorstrue
+ \freezecolorsfalse
+ \doifelse\@@clcriterium\v!all
+ \hidesplitcolortrue
+ \hidesplitcolorfalse
+ \doifelse\@@clrgb\v!no
+ {\ifRGBsupported \ifproductionrun\showmessage\m!colors {9}\v!rgb \fi\RGBsupportedfalse \fi}
+ {\ifRGBsupported \else\ifproductionrun\showmessage\m!colors{10}\v!rgb \fi\RGBsupportedtrue \fi}%
+ \doifelse\@@clcmyk\v!no
+ {\ifCMYKsupported \ifproductionrun\showmessage\m!colors {9}\v!cmyk \fi\CMYKsupportedfalse\fi}
+ {\ifCMYKsupported\else\ifproductionrun\showmessage\m!colors{10}\v!cmyk \fi\CMYKsupportedtrue \fi}%
+ \doifelse\@@clmpcmyk\v!no
+ {\ifMPcmykcolors \ifproductionrun\showmessage\m!colors {9}{\v!mp\v!cmyk}\fi\MPcmykcolorsfalse \fi}
+ {\ifMPcmykcolors \else\ifproductionrun\showmessage\m!colors{10}{\v!mp\v!cmyk}\fi\MPcmykcolorstrue \fi}%
+ \doifelse\@@clmpspot\v!no
+ {\ifMPspotcolors \ifproductionrun\showmessage\m!colors {9}{\v!mp\v!spot}\fi\MPspotcolorsfalse \fi}
+ {\ifMPspotcolors \else\ifproductionrun\showmessage\m!colors{10}{\v!mp\v!spot}\fi\MPspotcolorstrue \fi}%
+ \preferGRAYfalse
+ \processaction
+ [\@@clconversion]
+ [ \v!yes=>\preferGRAYtrue,
+ \v!always=>\preferGRAYtrue\RGBsupportedfalse\CMYKsupportedfalse]%
+ \ifRGBsupported
+ \converttoGRAYfalse
+ \forcegrayMPcolorsfalse
+ \else\ifCMYKsupported
+ \converttoGRAYfalse
+ \forcegrayMPcolorsfalse
+ \convertMPcolorstrue
+ \ifreduceCMYK
+ \reduceMPcolorstrue
+ \fi
+ \else
+ \ifconverttoGRAY\else\showmessage\m!colors{11}\empty\fi
+ \converttoGRAYtrue
+ \forcegrayMPcolorstrue
+ \convertMPcolorsfalse
+ \reduceMPcolorsfalse
+ \fi\fi
+ \processaction
+ [\@@clstate]
+ [ \v!global=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
+ \incolortrue\localcolorfalse,
+ \v!local=>\ifincolor\else\showmessage\m!colors2\colorstyle\fi
+ \incolortrue\localcolortrue,
+ \v!start=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
+ \incolortrue\localcolorfalse
+ \let\@@clstate\v!global,
+ \v!stop=>\incolorfalse\localcolorfalse
+ \forcegrayMPcolorstrue]%
+ \dosetupcolormodel
+ \initializemaintextcolor}
+
+%D \macros
+%D {startregistercolor,stopregistercolor,permitcolormode}
+%D
+%D If you only want to register a color, the switch \type
+%D {\ifpermitcolormode} can be used. That way the nested
+%D colors know where to go back to.
+
+\ifx\startregistercolor\undefined
+ \def\startregistercolor[#1]{}
+ \def\stopregistercolor {}
+\fi
+
+%D We use these macros for implementing text colors
+%D (actually, the first application was in foreground
+%D colors).
+%D
+%D \starttyping
+%D \starttextcolor[red]
+%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
+%D \stoptextcolor
+%D \stoptyping
+%D
+%D This is more efficient than the alternative:
+%D
+%D \starttyping
+%D \setupbackgrounds[text][foregroundcolor=red]
+%D \startregistercolor[red]
+%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
+%D \stopregistercolor
+%D \stoptyping
+
+\def\maintextcolor {}
+\def\defaulttextcolor {black}
+\def\@@themaintextcolor{themaintextcolor}
+
+\ifx\initializemaintextcolor\undefined
+ \def\starttextcolor [#1]{}
+ \def\stoptextcolor {}
+ \def\initializemaintextcolor {}
+\fi
+
+\ifx\restoretextcolor\undefined % to be redone
+ \let\restoretextcolor \firstofoneargument
+ \let\localstarttextcolor\relax
+ \let\localstoptextcolor \relax
+\fi
+
+%D In this documentation we will not go into too much details
+%D on palets. Curious users can find more information on this
+%D topic in \from[use of color].
+%D
+%D At the moment we implemented color in \CONTEXT\ color
+%D printing was not yet on the desktop. In spite of this lack our
+%D graphics designer made colorfull illustrations. When printed
+%D on a black and white printer, distinctive colors can come
+%D out equally gray. We therefore decided to use only colors
+%D that were distinctive in colors as well as in black and
+%D white print.
+%D
+%D Although none of the graphic packages we used supported
+%D logical colors and global color redefition, we build this
+%D support into \CONTEXT. This enabled us to experiment and
+%D also prepared us for the future.
+
+%D \macros
+%D {definepalet}
+%D
+%D Colors are grouped in palets. The colors in such a palet can
+%D have colorful names, but best is to use names that specify
+%D their use, like {\em important} or {\em danger}. As a sort
+%D of example \CONTEXT\ has some palets predefined,
+%D like:\footnote{At the time I wrote the palet support, I was
+%D reading 'A hort history of time' of S.~Hawkins, so that's
+%D why we stuck to quarks.}
+%D
+%D \starttyping
+%D \definepalet
+%D [alfa]
+%D [ top=rood:7,
+%D bottom=groen:6,
+%D up=blauw:5,
+%D down=cyaan:4,
+%D strange=magenta:3,
+%D charm=geel:2]
+%D \stoptyping
+%D
+%D It's formal definition is:
+%D
+%D \showsetup{definepalet}
+%D
+%D Visualized, such a palet looks like:
+%D
+%D \startbuffer[palet]
+%D \showpalet [alfa] [horizontal,name,number,value]
+%D \stopbuffer
+%D
+%D \startlinecorrection
+%D \getbuffer[palet]
+%D \stoplinecorrection
+%D
+%D This bar shows both the color and gray alternatives of the
+%D palet components (not visible in black and white print).
+%D
+%D When needed, one can copy a palet by saying:
+%D
+%D \starttyping
+%D \definepalet [TEXcolorpretty] [colorpretty]
+%D \stoptyping
+%D
+%D This saves us some typing in for instance the modules that
+%D deal with pretty verbatim typesetting.
+
+\def\definepalet
+ {\dodoubleargument\dodefinepalet}
+
+\def\dodefinepalet[#1][#2]%
+ {\doifassignmentelse{#2}
+ {%\showmessage\m!colors6{#1}%
+ \letvalue{\??pa#1}\empty
+ \setevalue{\??pa\??pa#1}{#2}%
+ \def\dodododefinepalet[##1=##2]%
+ {\doifvaluesomething{\??pa#1}
+ {\setevalue{\??pa#1}{\csname\??pa#1\endcsname,}}%
+ \setevalue{\??pa#1}{\csname\??pa#1\endcsname##1}%
+ \dodefinepaletcolor{#1}{##1}{##2}}%
+ \def\dododefinepalet##1%
+ {\dodododefinepalet[##1]}%
+ \processcommalist[#2]\dododefinepalet}
+ {\doifdefined{\??pa#2}
+ {\expanded{\dodefinepalet[#1][\csname\??pa\??pa#2\endcsname]}}}}
+
+\ifx\dodefinepaletcolor\undefined
+ \let\dodefinepaletcolor\gobblethreearguments
+\fi
+
+\let\paletsize\!!zerocount
+
+\def\getpaletsize[#1]%
+ {\getcommacommandsize[\csname\??pa\??pa#1\endcsname]%
+ \edef\paletsize{\number\commalistsize}}
+
+%D Instead of refering to colors, one can also directly specify
+%D a color:
+%D
+%D \starttyping
+%D \definepalet[test][xx=green]
+%D \definepalet[test][xx={y=.4}]
+%D \stoptyping
+
+%D \macros
+%D {setuppalet}
+%D
+%D Colors are taken from the current palet, if defined.
+%D Setting the current palet is done by:
+%D
+%D \showsetup{setuppalet}
+
+\let\currentpalet\empty
+
+\def\setuppalet
+ {\dosingleempty\dosetuppalet}
+
+\def\dosetuppalet[#1]%
+ {\edef\currentpalet{#1}%
+ \ifx\currentpalet\empty
+ % seems to be a reset
+ \else\ifcsname\??pa\currentpalet\endcsname
+ \edef\currentpalet{#1:}%
+ \else
+ \showmessage\m!colors7\currentpalet
+ \let\currentpalet\empty
+ \fi\fi}
+
+%D \macros
+%D {showpalet}
+%D
+%D The previous visualization was typeset with:
+%D
+%D \typebuffer[palet]
+%D
+%D This commands is defined as:
+%D
+%D \showsetup{showpalet}
+
+\fetchruntimecommand \showpalet {\f!colorprefix\s!run}
+
+%D \macros
+%D {showcolorcomponents}
+%D
+%D \starttyping
+%D \showcolorcomponents[color-1,color-2]
+%D \stoptyping
+
+\fetchruntimecommand \showcolorcomponents {\f!colorprefix\s!run}
+
+%D \macros
+%D {definecolorgroup}
+%D
+%D The naming of the colors in this palet suggests some
+%D ordening, which in turn is suported by color grouping.
+%D
+%D \starttyping
+%D \definecolorgroup
+%D [red]
+%D [1.00:0.90:0.90,
+%D 1.00:0.80:0.80,
+%D 1.00:0.70:0.70,
+%D 1.00:0.55:0.55,
+%D 1.00:0.40:0.40,
+%D 1.00:0.25:0.25,
+%D 1.00:0.15:0.15,
+%D 0.90:0.00:0.00]
+%D \stoptyping
+%D
+%D In such a color group colors are numbered from~$1$ to~$n$.
+%D
+%D \showsetup{definecolorgroup}
+%D
+%D This kind of specification is not only more compact than
+%D defining each color separate, it also loads faster and takes
+%D less bytes.
+
+\def\definecolorgroup
+ {\dotripleempty\dodefinecolorgroup}
+
+\def\dododefinecolorgroupgray [#1][#2:#3]{\definecolor [#1:\the\colorcount][s=#2]}
+\def\dododefinecolorgrouprgb [#1][#2:#3:#4:#5]{\definecolor [#1:\the\colorcount][r=#2,g=#3,b=#4]}
+\def\dododefinecolorgroupcmyk[#1][#2:#3:#4:#5:#6]{\definecolor [#1:\the\colorcount][c=#2,m=#3=,y=#4,k=#5]}
+\def\dododefinecolorgroupspot [#1][#2:#3:#4]{\definespotcolor[#1:\the\colorcount][#2][p=#3]}
+
+\def\dododefinecolorgroup#1#2%
+ {\advance\colorcount\plusone
+ \getvalue{dododefinecolorgroup\currentcolorspace}[#1][#2:0:0:0:0]}
+
+\def\dodefinecolorgroup[#1][#2][#3]% obsolete, just use palets
+ {\ifthirdargument
+ \doifelsenothing{#2}{\let\currentcolorspace\v!rgb}{\def\currentcolorspace{#2}}%
+ \colorcount\zerocount
+ \processcommalist[#3]{\dododefinecolorgroup{#1}}%
+ \else
+ \doifinstringelse{:}{#2}
+ {\definecolorgroup[#1][\v!rgb][#2]}
+ {\doloop
+ {\doifdefinedelse{\??cr#2:\recurselevel}
+ {\setevalue{\??cr#1:\recurselevel}{\csname\??cr#2:\recurselevel\endcsname}}
+ {\exitloop}}}%
+ \fi}
+
+%D \macros
+%D {showcolorgroup}
+%D
+%D We can show the group by:
+%D
+%D \startbuffer
+%D \showcolorgroup [blue] [horizontal,name,number,value]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or in color:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D which uses:
+%D
+%D \showsetup{showcolorgroup}
+
+\fetchruntimecommand \showcolorgroup {\f!colorprefix\s!run}
+
+%D There are ten predefined color groups, like
+%D \color[green]{\em groen}, \color[red]{\em rood},
+%D \color[blue]{\em blauw}, \color[cyan]{\em cyaan},
+%D \color[magenta]{\em magenta} and \color[yellow]{\em geel}.
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\hss
+%D \showcolorgroup [red] [vertical,name,number]\hss
+%D \showcolorgroup [green] [vertical,name]\hss
+%D \showcolorgroup [blue] [vertical,name]\hss
+%D \showcolorgroup [cyan] [vertical,name]\hss
+%D \showcolorgroup [magenta][vertical,name]\hss
+%D \showcolorgroup [yellow] [vertical,name]\hss}
+%D \stoplinecorrection
+%D
+%D These groups are used to define palets {\em alfa} upto {\em
+%D zeta}. As long as we don't use colors from the same row, we
+%D get ourselves distinctive palets. By activating such a palet
+%D one gains access to its members {\em top} to {\em charm} (of
+%D course one should use more suitable names than these).
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\showpalet [alfa] [vertical,name,number]\hss
+%D \showpalet [beta] [vertical,name]\hss
+%D \showpalet [gamma] [vertical,name]\hss
+%D \showpalet [delta] [vertical,name]\hss
+%D \showpalet [epsilon] [vertical,name]\hss
+%D \showpalet [zeta] [vertical,name]}
+%D \stoplinecorrection
+%D
+%D By using the keyword \type {value} the individual color
+%D components are shown too. When printed in color, these
+%D showcases show both the colors and the gray value.
+
+%D \macros
+%D {comparepalet}
+%D
+%D There are some more testing macros available:
+%D
+%D \startbuffer
+%D \comparepalet [alfa]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D shows the palet colors against a background:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D The formal definition is:
+%D
+%D \showsetup{comparepalet}
+
+\fetchruntimecommand \comparepalet {\f!colorprefix\s!run}
+
+%D \macros
+%D {comparecolorgroup}
+%D
+%D The similar command:
+%D
+%D \startbuffer
+%D \comparecolorgroup [blue]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D shows color groups:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D this commands are defined as:
+%D
+%D \showsetup{comparecolorgroup}
+
+\fetchruntimecommand \comparecolorgroup {\f!colorprefix\s!run}
+
+%D \macros
+%D {showcolor}
+%D
+%D But let's not forget that we also have the more traditional
+%D non||related colors. These show up after:
+%D
+%D \starttyping
+%D \showcolor [name]
+%D \stoptyping
+%D
+%D Where \type{name} for instance can be \type{rgb}.
+%D
+%D \showsetup{showcolor}
+
+\fetchruntimecommand \showcolor {\f!colorprefix\s!run}
+
+%D It would make sense to put the following code in \type
+%D {colo-mps}, but it it rather low level.
+
+%D \macros
+%D {negatecolorcomponent,negatedcolorcomponent}
+%D
+%D These speak for themselves. See \type {colo-ext} for usage.
+
+\def\negatecolorcomponent#1% #1 = \macro
+ {\scratchdimen\onepoint\advance\scratchdimen-#1\onepoint
+ \ifdim\scratchdimen<\zeropoint\scratchdimen\zeropoint\fi
+ \edef#1{\withoutpt\the\scratchdimen}}
+
+\let\negatedcolorcomponent\firstofoneargument
+
+\def\negatedcolorcomponent#1%
+ {\ifdim\dimexpr\onepoint-#1\onepoint\relax<\zeropoint
+ \!!zerocount
+ \else
+ \expandafter\withoutpt\the\dimexpr\onepoint-#1\onepoint\relax
+ \fi}
+
+\def\negatecolorcomponent#1% #1 = \macro
+ {\edef#1{\negatedcolorcomponent{#1}}}
+
+%D \macros
+%D {ifMPgraphics, ifMPcmykcolors, MPcolor}
+%D
+%D A very special macro is \type{\MPcolor}. This one can be
+%D used to pass a \CONTEXT\ color to \METAPOST.
+%D
+%D \starttyping
+%D \MPcolor{my own red}
+%D \stoptyping
+%D
+%D This macro returns a \METAPOST\ triplet \type{(R,G,B)}.
+%D Unless \CMYK\ color support is turned on with \type
+%D {MPcmyk}, only \cap{RGB} colors and gray scales are
+%D supported.
+
+\newif\ifMPcmykcolors % \MPcmykcolorsfalse
+\newif\ifMPspotcolors % \MPspotcolorsfalse
+
+\ifx\MPcolor\undefined
+ \def\MPcolor#1{(0,0,0)}
+\fi
+
+%D \macros
+%D {PDFcolor,FDFcolor}
+%D
+%D Similar alternatives are avaliable for \PDF:
+
+%D For the moment we keep the next downward compatibility
+%D switch, i.e.\ expanded colors. However, predefined colors
+%D and palets are no longer expanded (which is what I wanted
+%D in the first place).
+%D
+%D Well, in case we want to do color separation and use CMYK
+%D colors only, this is dangerous since unwanted remapping may
+%D take place. Especially when we redefine already defined
+%D colors in another color space (e.g. darkgreen is
+%D predefined in RGB color space, so a redefinition in CMYK
+%D coordinates before RGB mode is disabled, would give
+%D unexpected results due to the already frozen color spec.)
+%D
+%D So, from now on, colors are not frozen any more!
+
+\chardef\currentcolorchannel=0
+
+\newif\iffilterspotcolor \filterspotcolorfalse
+\newif\ifdoingspotcolor \doingspotcolorfalse
+
+\def\registercolorchannel#1%
+ {\ifdoingspotcolor \else
+ \global\expandafter\chardef\csname\??cs#1\endcsname\zerocount
+ \fi}
+
+\newif\ifhidesplitcolor \hidesplitcolortrue
+
+%D The next macro is for instance used in figure splitting:
+
+\def\doifseparatingcolorselse
+ {\iffilterspotcolor
+ \@EA\firstoftwoarguments
+ \else\ifcase\currentcolorchannel
+ \@EAEAEA\secondoftwoarguments
+ \else
+ \@EAEAEA\firstoftwoarguments
+ \fi\fi}
+
+\def\doifcolorchannelelse#1%
+ {\doifseparatingcolorselse
+ {\doifelsenothing{#1}
+ \secondoftwoarguments
+ {\doifelse{#1}\@@clsplit
+ \firstoftwoarguments
+ \secondoftwoarguments}}
+ \secondoftwoarguments}
+
+\def\resetcolorseparation
+ {\filterspotcolorfalse
+ \chardef\currentcolorchannel\zerocount}
+
+%D These can be used in selecting specific files (like
+%D figuredatabases).
+
+% we already have:
+%
+% \def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplitsen\fi}
+% \def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplitsen-\fi}
+
+\def\colorchannelprefix{\doifseparatingcolorselse\@@clsplit\empty-}
+\def\colorchannelsuffix{-\doifseparatingcolorselse\@@clsplit\empty}
+
+%D We now define the low level macros:
+
\chardef\colorversion=1
%D Color support is not present in \TEX. Colorful output can
@@ -165,8 +1029,12 @@
\def\dodefineglobalcolor{\dododefinecolor\doglobal\setgvalue\setxvalue1}
\def\dodefinenamedcolor {\dododefinecolor\doglobal\setvalue \setevalue0}
+\let\colorlist\empty % not really used, only for colo-run
+\setfalse\collectcolorsinlist
+\def\collectcolorinlist#1{\doglobal\addtocommalist{#1}\colorlist}
+
\def\dododefinecolor#1#2#3#4[#5][#6]% #2==set(g)value #3==set[e|x]value
- {#1\addtocommalist{#5}\colorlist % optional
+ {\ifconditional\collectcolorsinlist\collectcolorinlist{#5}\fi
\doifassignmentelse{#6}
{\@@resetcolorparameters
\getparameters[\??cl @@][#6]%
@@ -218,7 +1086,7 @@
\def\dodefinespotcolor[#1][#2][#3]% todo: always global
{\doifnot{#1}{#2}
{\@@resetcolorparameters
- \doglobal\addtocommalist{#1}\colorlist % optional
+ \ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\edef\@@cl@@n{#2}%
\getparameters[\??cl @@][#3]%
\doifnothing\@@cl@@p{\let\@@cl@@p\!!plusone}%
@@ -312,7 +1180,7 @@
\def\dodefinespotcolor[#1][#2][#3]% todo: always global (REDEFINED)
{\doifnot{#1}{#2}
{\@@resetcolorparameters
- \doglobal\addtocommalist{#1}\colorlist % optional
+ \ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\edef\@@cl@@n{#2}%
\getparameters[\??cl @@][#3]%
\doifnothing \@@cl@@p{\let\@@cl@@p\!!plusone}%
@@ -1859,4 +2727,50 @@
\appendtoks \localcolortrue \to \everyshapebox
+%D \macros
+%D {forcecolorhack}
+%D
+%D Awful \unknown
+
+\let\forcecolorhack\relax
+
+%D We default to the colors defined in \module{colo-rgb} and
+%D support both \cap{RGB} and \cap{CMYK} output. As you can
+%D see, color support is turned off by default. Reduction of
+%D gray colors to gray scales is turned on.
+
+\definecolor[black][s=0]
+\definecolor[white][s=1]
+
+\definetransparency [none] [0]
+\definetransparency [normal] [1]
+\definetransparency [multiply] [2]
+\definetransparency [screen] [3]
+\definetransparency [overlay] [4]
+\definetransparency [softlight] [5]
+\definetransparency [hardlight] [6]
+\definetransparency [colordodge] [7]
+\definetransparency [colorburn] [8]
+\definetransparency [darken] [9]
+\definetransparency [lighten] [10]
+\definetransparency [difference] [11]
+\definetransparency [exclusion] [12]
+
+\setupcolors
+ [\c!state=\v!stop,
+ \c!conversion=\v!yes,
+ \c!reduction=\v!no,
+ \c!rgb=\v!yes,
+ \c!cmyk=\v!yes,
+ \c!spot=\v!yes,
+ \c!mp\c!cmyk=\@@clcmyk,
+ \c!mp\c!spot=\@@clspot,
+ \c!expansion=\v!no,
+ \c!textcolor=,
+ \c!split=\v!no,
+ \c!criterium=\v!all]
+
+\setupcolor
+ [\v!rgb]
+
\protect \endinput
diff --git a/tex/context/base/colo-ini.mkiv b/tex/context/base/colo-ini.mkiv
index 7f79cdfad..cf7f2446a 100644
--- a/tex/context/base/colo-ini.mkiv
+++ b/tex/context/base/colo-ini.mkiv
@@ -11,8 +11,874 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D We need to clean this up further but first we hav eto make sure that mkiv
+%D code works ok.
+
+\writestatus{loading}{ConTeXt Color Macros / Initialization}
+
+%D This module implements color. Since \MKII\ and \MKIV\ use a completely
+%D different approach, this module only implements a few generic mechanisms.
+
+\registerctxluafile{colo-ini}{1.000}
+
\unprotect
+\chardef\colorversion=1 % temp, needed for tracing purposes, mkiv transition
+
+%D We use a couple of local registers. That way we don't have
+%D to group when converting colors. By the way, this is not
+%D really faster. We can sqeeze half a second runtime for 50K
+%D switches on a 1G machine, but the macros will become rather
+%D ugly then. To mention one such improvement: no colon
+%D after the key character (.25 sec).
+
+\newdimen\colordimen
+\newcount\colorcount
+
+%D When typesetting for paper, we prefer using the \cap{CMYK}
+%D color space, but for on||screen viewing we prefer \cap{RGB}
+%D (the previous implementation supported only this scheme).
+%D Independant of such specifications, we support some automatic
+%D conversions:
+%D
+%D \startitemize[packed]
+%D \item convert all colors to \cap{RGB}
+%D \item convert all colors to \cap{CMYK}
+%D \item convert all colors to gray scales
+%D \stopitemize
+%D
+%D We also support optimization of colors to gray scales.
+%D
+%D \startitemize[continue]
+%D \item reduce gray colors to gray scales
+%D \item reduce \cap{CMY} components to \cap{K}
+%D \stopitemize
+%D
+%D These options are communicated by means of:
+
+\newif\ifRGBsupported
+\newif\ifCMYKsupported
+\newif\ifSPOTsupported
+\newif\ifpreferGRAY
+\newif\ifGRAYprefered
+\newif\ifreduceCMYK
+\newif\ifconverttoGRAY
+\newif\ifweightGRAY \weightGRAYtrue
+
+\newif\ifconvertMPcolors
+\newif\ifreduceMPcolors
+\newif\ifforcegrayMPcolors
+
+%D The last boolean controls reduction of \cap{CMYK} to
+%D \cap{CMY} colors. When set to true, the black component
+%D is added to the other ones.
+%D
+%D Prefering gray is not the same as converting to gray.
+%D Conversion treats each color components in a different way,
+%D while prefering is just a reduction and thus a
+%D space||saving option.
+
+\newif\iffreezecolors \freezecolorsfalse
+\newif\ifincolor % true if colors enabled
+\newif\iflocalcolor
+
+\let\colorlist \empty
+\let\currentspotcolor \empty
+\let\allspotcolors \empty
+\let\usedspotcolors \empty
+\let\usedcolorchannels\empty
+\let\currentpalet \empty
+
+%D \macros
+%D {definecolor,defineglobalcolor,definenamedcolor,definespotcolor,definemultitonecolor}
+%D
+%D \startbuffer
+%D \definecolor [blue] [c=1,m=.38,y=0,k=.64] % pantone pms 2965 uncoated m
+%D \definecolor [yellow] [c=0,m=.28,y=1,k=.06] % pantone pms 124 uncoated m
+%D
+%D \definespotcolor [blue-100] [blue] [p=1]
+%D \definespotcolor [yellow-100] [yellow] [p=1]
+%D
+%D \definemultitonecolor [pdftoolscolor] [blue=.12,yellow=.28] [c=.1,m=.1,y=.3,k=.1]
+%D
+%D \useexternalfigure[demofig][mill.png][object=no]
+%D
+%D \startcombination[4*1]
+%D {\externalfigure[demofig]} {no color}
+%D {\externalfigure[demofig][color=pdftoolscolor]} {indexed duotone}
+%D {\externalfigure[demofig][color=blue-100]} {spot color}
+%D {\externalfigure[demofig][color=yellow-100]} {spot color}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \getbuffer \typebuffer
+
+\def\definecolor {\dodoubleargument\dodefinecolor}
+\def\defineglobalcolor {\dodoubleargument\dodefineglobalcolor}
+\def\definenamedcolor {\dodoubleargument\dodefinenamedcolor}
+\def\definespotcolor {\dotripleargument\dodefinespotcolor}
+\def\definemultitonecolor{\doquadrupleempty\dodefinemultitonecolor}
+
+% check: registerusedspotcolors
+% check: registerusedcolorchannels
+
+%D \macros
+%D {doifcolorelse, doifcolor}
+%D
+%D Switching to a color is done by means of the following
+%D command. Later on we will explain the use of palets. We
+%D define ourselves a color conditional first.
+
+\ifx\doifcolorelse\undefined
+ \let\doifcolorelse\secondoftwoarguments
+ \let\doifcolor \gobbleoneargument
+\fi
+
+%D \macros
+%D {localstartcolor,localstopcolor}
+%D
+%D Simple color support, that is without nesting, is provided
+%D by:
+
+\ifx\localstartcolor\undefined
+ \let\localstartcolor\undefined
+ \let\localstopcolor \undefined
+\fi
+
+%D \macros
+%D {faststartcolor,faststopcolor}
+%D
+%D No checking for arguments and such:
+
+\ifx\faststartcolor\undefined
+ \def\faststartcolor[#1]{}
+ \def\faststopcolor {}
+\fi
+
+%D These local ones may go away in future versions.
+
+%D \macros
+%D {startcolor,stopcolor}
+%D
+%D The more save method, the one that saves the current color
+%D state and returns to this state afterward, is activated by:
+%D
+%D \showsetup{startcolor}
+
+\ifx\startcolor\undefined
+ \let\startcolor\undefined
+ \let\stopcolor \undefined
+\fi
+
+%D \macros
+%D {startcurrentcolor,stopcurrentcolor}
+
+\def\startcurrentcolor{\startcolor[\outercolorname]}
+\def\stopcurrentcolor {\stopcolor}
+
+%D \macros
+%D {color,graycolor}
+%D
+%D This leaves the simple color command:
+%D
+%D \showsetup{color}
+%D \showsetup{graycolor}
+
+\ifx\color\undefined
+ \def\color [#1]{}
+ \def\graycolor[#1]{}
+ \def\gray {\graycolor}
+\fi
+
+%D \macros
+%D {localstartraster,localstopraster,
+%D startraster,stopraster,raster}
+%D
+%D The previous conversions are not linear and treat each color
+%D component according to human perception curves. Pure gray
+%D (we call them rasters) has equal color components. In
+%D \CONTEXT\ rasters are only used as backgrounds and these
+%D don't cross page boundaries in the way color does. Therefore
+%D we don't need stacks and marks. Just to be compatible with
+%D color support we offer both 'global' and 'local' commands.
+
+\ifx\startraster\undefined
+ \def\startraster [#1]{}
+ \def\stopraster {}
+ \def\raster [#1]{}
+ \def\localstartraster[#1]{}
+ \def\localstopraster {}
+\fi
+
+%D \macros
+%D {colorvalue, grayvalue}
+%D
+%D We can typeset the color components using \type{\colorvalue} and
+%D \type{\grayvalue}. The commands:
+%D
+%D \startbuffer
+%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
+%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D show us:
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+
+\def\colorformatseparator{ }
+
+\ifx\colorvalue\undefined
+ \let\colorvalue\gobbleoneargument
+ \let\grayvalue \gobbleoneargument
+\fi
+
+% check: \currentcolorname
+% check: \outercolorname
+
+%D \macros
+%D {setupcolor}
+%D
+%D Color definitions can be grouped in files with the name:
+%D
+%D \starttyping
+%D \f!colorprefix-identifier.tex
+%D \stoptyping
+%D
+%D where \type{\f!colorprefix} is \unprotect {\tttf \f!colorprefix}.
+%D Loading such a file is done by \protect
+%D
+%D \showsetup{setupcolor}
+%D
+%D Some default colors are specified in \type{colo-rgb.tex},
+%D which is loaded into the format by:
+%D
+%D \starttyping
+%D \setupcolor[rgb]
+%D \stoptyping
+
+\let\colorstyle\empty
+
+\def\setupcolor
+ {\dosingleargument\dosetupcolor}
+
+\def\dosetupcolor[#1]%
+ {\doifnot{#1}\colorstyle
+ {\def\colorstyle{#1}%
+ \processcommalist[#1]\dodosetupcolor}}
+
+\def\dodosetupcolor#1%
+ {\makeshortfilename[\truefilename{\f!colorprefix#1}]%
+ \startreadingfile
+ \readsysfile\shortfilename
+ {\showmessage\m!colors4\colorstyle}
+ {\showmessage\m!colors5\colorstyle}%
+ \stopreadingfile}
+
+\let\usecolors\setupcolor
+
+% check: \chardef\currentcolorchannel=0
+% check: \startcolormode
+% check: \newif\iffilterspotcolor \filterspotcolorfalse
+% check: \newif\ifdoingspotcolor \doingspotcolorfalse
+% check: \registercolorchannel
+
+%D \macros
+%D {definetransparency}
+%D
+%D This command numbers to names:
+
+\def\definetransparency
+ {\dodoubleargument\dodefinetransparency}
+
+\def\setupcolors
+ {\dosingleargument\dosetupcolors}
+
+\def\resetcolorsplitting
+ {\chardef\currentcolorchannel\zerocount
+ \let\currentspotcolor\empty
+ \filterspotcolorfalse}
+
+\def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplit\fi}
+\def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplit-\fi}
+
+\def\setcolorsplitting
+ {\resetsystemmode{\v!color\colorsplitsuffix}%
+ \resetcolorsplitting
+ \processaction
+ [\@@clsplit]
+ [ c=>\chardef\currentcolorchannel1,%
+ m=>\chardef\currentcolorchannel2,%
+ y=>\chardef\currentcolorchannel3,%
+ k=>\chardef\currentcolorchannel4,%
+ r=>\chardef\currentcolorchannel5,%
+ g=>\chardef\currentcolorchannel6,%
+ b=>\chardef\currentcolorchannel7,%
+ s=>\chardef\currentcolorchannel8,%
+ \v!no=>,% \currentcolorchannel0,% all colors
+ \s!default=>,% \currentcolorchannel0,% all colors
+ \s!unknown=>\filterspotcolortrue
+ \edef\currentspotcolor{\commalistelement}]%
+ \setsystemmode{\v!color\colorsplitsuffix}%
+ \iffilterspotcolor \let\@@clrgb\v!no \fi}
+
+\ifx\dosetupcolormodel\undefined
+ \let\dosetupcolormodel\relax
+\fi
+
+\def\dosetupcolors[#1]% some no longer make sense in MkIV
+ {\getparameters[\??cl][#1]%
+ \doifelse\@@clspot\v!yes
+ \SPOTsupportedtrue
+ \SPOTsupportedfalse
+ \doifelsenothing\@@clsplit
+ \resetcolorsplitting
+ \setcolorsplitting
+ \doifelse\@@clreduction\v!yes
+ \reduceCMYKtrue
+ \reduceCMYKfalse
+ \doifelse\@@clexpansion\v!yes
+ \freezecolorstrue
+ \freezecolorsfalse
+ \doifelse\@@clcriterium\v!all
+ \hidesplitcolortrue
+ \hidesplitcolorfalse
+ \doifelse\@@clrgb\v!no
+ {\ifRGBsupported \ifproductionrun\showmessage\m!colors {9}\v!rgb \fi\RGBsupportedfalse \fi}
+ {\ifRGBsupported \else\ifproductionrun\showmessage\m!colors{10}\v!rgb \fi\RGBsupportedtrue \fi}%
+ \doifelse\@@clcmyk\v!no
+ {\ifCMYKsupported \ifproductionrun\showmessage\m!colors {9}\v!cmyk \fi\CMYKsupportedfalse\fi}
+ {\ifCMYKsupported\else\ifproductionrun\showmessage\m!colors{10}\v!cmyk \fi\CMYKsupportedtrue \fi}%
+ \doifelse\@@clmpcmyk\v!no
+ {\ifMPcmykcolors \ifproductionrun\showmessage\m!colors {9}{\v!mp\v!cmyk}\fi\MPcmykcolorsfalse \fi}
+ {\ifMPcmykcolors \else\ifproductionrun\showmessage\m!colors{10}{\v!mp\v!cmyk}\fi\MPcmykcolorstrue \fi}%
+ \doifelse\@@clmpspot\v!no
+ {\ifMPspotcolors \ifproductionrun\showmessage\m!colors {9}{\v!mp\v!spot}\fi\MPspotcolorsfalse \fi}
+ {\ifMPspotcolors \else\ifproductionrun\showmessage\m!colors{10}{\v!mp\v!spot}\fi\MPspotcolorstrue \fi}%
+ \preferGRAYfalse
+ \processaction
+ [\@@clconversion]
+ [ \v!yes=>\preferGRAYtrue,
+ \v!always=>\preferGRAYtrue\RGBsupportedfalse\CMYKsupportedfalse]%
+ \ifRGBsupported
+ \converttoGRAYfalse
+ \forcegrayMPcolorsfalse
+ \else\ifCMYKsupported
+ \converttoGRAYfalse
+ \forcegrayMPcolorsfalse
+ \convertMPcolorstrue
+ \ifreduceCMYK
+ \reduceMPcolorstrue
+ \fi
+ \else
+ \ifconverttoGRAY\else\showmessage\m!colors{11}\empty\fi
+ \converttoGRAYtrue
+ \forcegrayMPcolorstrue
+ \convertMPcolorsfalse
+ \reduceMPcolorsfalse
+ \fi\fi
+ \processaction
+ [\@@clstate]
+ [ \v!global=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
+ \incolortrue\localcolorfalse,
+ \v!local=>\ifincolor\else\showmessage\m!colors2\colorstyle\fi
+ \incolortrue\localcolortrue,
+ \v!start=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
+ \incolortrue\localcolorfalse
+ \let\@@clstate\v!global,
+ \v!stop=>\incolorfalse\localcolorfalse
+ \forcegrayMPcolorstrue]%
+ \dosetupcolormodel
+ \initializemaintextcolor}
+
+%D \macros
+%D {startregistercolor,stopregistercolor,permitcolormode}
+%D
+%D If you only want to register a color, the switch \type
+%D {\ifpermitcolormode} can be used. That way the nested
+%D colors know where to go back to.
+
+\ifx\startregistercolor\undefined
+ \def\startregistercolor[#1]{}
+ \def\stopregistercolor {}
+\fi
+
+%D We use these macros for implementing text colors
+%D (actually, the first application was in foreground
+%D colors).
+%D
+%D \starttyping
+%D \starttextcolor[red]
+%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
+%D \stoptextcolor
+%D \stoptyping
+%D
+%D This is more efficient than the alternative:
+%D
+%D \starttyping
+%D \setupbackgrounds[text][foregroundcolor=red]
+%D \startregistercolor[red]
+%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
+%D \stopregistercolor
+%D \stoptyping
+
+\def\maintextcolor {}
+\def\defaulttextcolor {black}
+\def\@@themaintextcolor{themaintextcolor}
+
+\ifx\initializemaintextcolor\undefined
+ \def\starttextcolor [#1]{}
+ \def\stoptextcolor {}
+ \def\initializemaintextcolor {}
+\fi
+
+\ifx\restoretextcolor\undefined % to be redone
+ \let\restoretextcolor \firstofoneargument
+ \let\localstarttextcolor\relax
+ \let\localstoptextcolor \relax
+\fi
+
+%D In this documentation we will not go into too much details
+%D on palets. Curious users can find more information on this
+%D topic in \from[use of color].
+%D
+%D At the moment we implemented color in \CONTEXT\ color
+%D printing was not yet on the desktop. In spite of this lack our
+%D graphics designer made colorfull illustrations. When printed
+%D on a black and white printer, distinctive colors can come
+%D out equally gray. We therefore decided to use only colors
+%D that were distinctive in colors as well as in black and
+%D white print.
+%D
+%D Although none of the graphic packages we used supported
+%D logical colors and global color redefition, we build this
+%D support into \CONTEXT. This enabled us to experiment and
+%D also prepared us for the future.
+
+%D \macros
+%D {definepalet}
+%D
+%D Colors are grouped in palets. The colors in such a palet can
+%D have colorful names, but best is to use names that specify
+%D their use, like {\em important} or {\em danger}. As a sort
+%D of example \CONTEXT\ has some palets predefined,
+%D like:\footnote{At the time I wrote the palet support, I was
+%D reading 'A hort history of time' of S.~Hawkins, so that's
+%D why we stuck to quarks.}
+%D
+%D \starttyping
+%D \definepalet
+%D [alfa]
+%D [ top=rood:7,
+%D bottom=groen:6,
+%D up=blauw:5,
+%D down=cyaan:4,
+%D strange=magenta:3,
+%D charm=geel:2]
+%D \stoptyping
+%D
+%D It's formal definition is:
+%D
+%D \showsetup{definepalet}
+%D
+%D Visualized, such a palet looks like:
+%D
+%D \startbuffer[palet]
+%D \showpalet [alfa] [horizontal,name,number,value]
+%D \stopbuffer
+%D
+%D \startlinecorrection
+%D \getbuffer[palet]
+%D \stoplinecorrection
+%D
+%D This bar shows both the color and gray alternatives of the
+%D palet components (not visible in black and white print).
+%D
+%D When needed, one can copy a palet by saying:
+%D
+%D \starttyping
+%D \definepalet [TEXcolorpretty] [colorpretty]
+%D \stoptyping
+%D
+%D This saves us some typing in for instance the modules that
+%D deal with pretty verbatim typesetting.
+
+\def\definepalet
+ {\dodoubleargument\dodefinepalet}
+
+\def\dodefinepalet[#1][#2]%
+ {\doifassignmentelse{#2}
+ {%\showmessage\m!colors6{#1}%
+ \letvalue{\??pa#1}\empty
+ \setevalue{\??pa\??pa#1}{#2}%
+ \def\dodododefinepalet[##1=##2]%
+ {\doifvaluesomething{\??pa#1}
+ {\setevalue{\??pa#1}{\csname\??pa#1\endcsname,}}%
+ \setevalue{\??pa#1}{\csname\??pa#1\endcsname##1}%
+ \dodefinepaletcolor{#1}{##1}{##2}}%
+ \def\dododefinepalet##1%
+ {\dodododefinepalet[##1]}%
+ \processcommalist[#2]\dododefinepalet}
+ {\doifdefined{\??pa#2}
+ {\expanded{\dodefinepalet[#1][\csname\??pa\??pa#2\endcsname]}}}}
+
+\ifx\dodefinepaletcolor\undefined
+ \let\dodefinepaletcolor\gobblethreearguments
+\fi
+
+\let\paletsize\!!zerocount
+
+\def\getpaletsize[#1]%
+ {\getcommacommandsize[\csname\??pa\??pa#1\endcsname]%
+ \edef\paletsize{\number\commalistsize}}
+
+%D Instead of refering to colors, one can also directly specify
+%D a color:
+%D
+%D \starttyping
+%D \definepalet[test][xx=green]
+%D \definepalet[test][xx={y=.4}]
+%D \stoptyping
+
+%D \macros
+%D {setuppalet}
+%D
+%D Colors are taken from the current palet, if defined.
+%D Setting the current palet is done by:
+%D
+%D \showsetup{setuppalet}
+
+\let\currentpalet\empty
+
+\def\setuppalet
+ {\dosingleempty\dosetuppalet}
+
+\def\dosetuppalet[#1]%
+ {\edef\currentpalet{#1}%
+ \ifx\currentpalet\empty
+ % seems to be a reset
+ \else\ifcsname\??pa\currentpalet\endcsname
+ \edef\currentpalet{#1:}%
+ \else
+ \showmessage\m!colors7\currentpalet
+ \let\currentpalet\empty
+ \fi\fi}
+
+%D \macros
+%D {showpalet}
+%D
+%D The previous visualization was typeset with:
+%D
+%D \typebuffer[palet]
+%D
+%D This commands is defined as:
+%D
+%D \showsetup{showpalet}
+
+\fetchruntimecommand \showpalet {\f!colorprefix\s!run}
+
+%D \macros
+%D {showcolorcomponents}
+%D
+%D \starttyping
+%D \showcolorcomponents[color-1,color-2]
+%D \stoptyping
+
+\fetchruntimecommand \showcolorcomponents {\f!colorprefix\s!run}
+
+%D \macros
+%D {definecolorgroup}
+%D
+%D The naming of the colors in this palet suggests some
+%D ordening, which in turn is suported by color grouping.
+%D
+%D \starttyping
+%D \definecolorgroup
+%D [red]
+%D [1.00:0.90:0.90,
+%D 1.00:0.80:0.80,
+%D 1.00:0.70:0.70,
+%D 1.00:0.55:0.55,
+%D 1.00:0.40:0.40,
+%D 1.00:0.25:0.25,
+%D 1.00:0.15:0.15,
+%D 0.90:0.00:0.00]
+%D \stoptyping
+%D
+%D In such a color group colors are numbered from~$1$ to~$n$.
+%D
+%D \showsetup{definecolorgroup}
+%D
+%D This kind of specification is not only more compact than
+%D defining each color separate, it also loads faster and takes
+%D less bytes.
+
+\def\definecolorgroup
+ {\dotripleempty\dodefinecolorgroup}
+
+\def\dododefinecolorgroupgray [#1][#2:#3]{\definecolor [#1:\the\colorcount][s=#2]}
+\def\dododefinecolorgrouprgb [#1][#2:#3:#4:#5]{\definecolor [#1:\the\colorcount][r=#2,g=#3,b=#4]}
+\def\dododefinecolorgroupcmyk[#1][#2:#3:#4:#5:#6]{\definecolor [#1:\the\colorcount][c=#2,m=#3=,y=#4,k=#5]}
+\def\dododefinecolorgroupspot [#1][#2:#3:#4]{\definespotcolor[#1:\the\colorcount][#2][p=#3]}
+
+\def\dododefinecolorgroup#1#2%
+ {\advance\colorcount\plusone
+ \getvalue{dododefinecolorgroup\currentcolorspace}[#1][#2:0:0:0:0]}
+
+\def\dodefinecolorgroup[#1][#2][#3]% obsolete, just use palets
+ {\ifthirdargument
+ \doifelsenothing{#2}{\let\currentcolorspace\v!rgb}{\def\currentcolorspace{#2}}%
+ \colorcount\zerocount
+ \processcommalist[#3]{\dododefinecolorgroup{#1}}%
+ \else
+ \doifinstringelse{:}{#2}
+ {\definecolorgroup[#1][\v!rgb][#2]}
+ {\doloop
+ {\doifdefinedelse{\??cr#2:\recurselevel}
+ {\setevalue{\??cr#1:\recurselevel}{\csname\??cr#2:\recurselevel\endcsname}}
+ {\exitloop}}}%
+ \fi}
+
+%D \macros
+%D {showcolorgroup}
+%D
+%D We can show the group by:
+%D
+%D \startbuffer
+%D \showcolorgroup [blue] [horizontal,name,number,value]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or in color:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D which uses:
+%D
+%D \showsetup{showcolorgroup}
+
+\fetchruntimecommand \showcolorgroup {\f!colorprefix\s!run}
+
+%D There are ten predefined color groups, like
+%D \color[green]{\em groen}, \color[red]{\em rood},
+%D \color[blue]{\em blauw}, \color[cyan]{\em cyaan},
+%D \color[magenta]{\em magenta} and \color[yellow]{\em geel}.
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\hss
+%D \showcolorgroup [red] [vertical,name,number]\hss
+%D \showcolorgroup [green] [vertical,name]\hss
+%D \showcolorgroup [blue] [vertical,name]\hss
+%D \showcolorgroup [cyan] [vertical,name]\hss
+%D \showcolorgroup [magenta][vertical,name]\hss
+%D \showcolorgroup [yellow] [vertical,name]\hss}
+%D \stoplinecorrection
+%D
+%D These groups are used to define palets {\em alfa} upto {\em
+%D zeta}. As long as we don't use colors from the same row, we
+%D get ourselves distinctive palets. By activating such a palet
+%D one gains access to its members {\em top} to {\em charm} (of
+%D course one should use more suitable names than these).
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\showpalet [alfa] [vertical,name,number]\hss
+%D \showpalet [beta] [vertical,name]\hss
+%D \showpalet [gamma] [vertical,name]\hss
+%D \showpalet [delta] [vertical,name]\hss
+%D \showpalet [epsilon] [vertical,name]\hss
+%D \showpalet [zeta] [vertical,name]}
+%D \stoplinecorrection
+%D
+%D By using the keyword \type {value} the individual color
+%D components are shown too. When printed in color, these
+%D showcases show both the colors and the gray value.
+
+%D \macros
+%D {comparepalet}
+%D
+%D There are some more testing macros available:
+%D
+%D \startbuffer
+%D \comparepalet [alfa]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D shows the palet colors against a background:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D The formal definition is:
+%D
+%D \showsetup{comparepalet}
+
+\fetchruntimecommand \comparepalet {\f!colorprefix\s!run}
+
+%D \macros
+%D {comparecolorgroup}
+%D
+%D The similar command:
+%D
+%D \startbuffer
+%D \comparecolorgroup [blue]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D shows color groups:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D this commands are defined as:
+%D
+%D \showsetup{comparecolorgroup}
+
+\fetchruntimecommand \comparecolorgroup {\f!colorprefix\s!run}
+
+%D \macros
+%D {showcolor}
+%D
+%D But let's not forget that we also have the more traditional
+%D non||related colors. These show up after:
+%D
+%D \starttyping
+%D \showcolor [name]
+%D \stoptyping
+%D
+%D Where \type{name} for instance can be \type{rgb}.
+%D
+%D \showsetup{showcolor}
+
+\fetchruntimecommand \showcolor {\f!colorprefix\s!run}
+
+%D It would make sense to put the following code in \type
+%D {colo-mps}, but it it rather low level.
+
+%D \macros
+%D {negatecolorcomponent,negatedcolorcomponent}
+%D
+%D These speak for themselves. See \type {colo-ext} for usage.
+
+\def\negatecolorcomponent#1% #1 = \macro
+ {\scratchdimen\onepoint\advance\scratchdimen-#1\onepoint
+ \ifdim\scratchdimen<\zeropoint\scratchdimen\zeropoint\fi
+ \edef#1{\withoutpt\the\scratchdimen}}
+
+\let\negatedcolorcomponent\firstofoneargument
+
+\def\negatedcolorcomponent#1%
+ {\ifdim\dimexpr\onepoint-#1\onepoint\relax<\zeropoint
+ \!!zerocount
+ \else
+ \expandafter\withoutpt\the\dimexpr\onepoint-#1\onepoint\relax
+ \fi}
+
+\def\negatecolorcomponent#1% #1 = \macro
+ {\edef#1{\negatedcolorcomponent{#1}}}
+
+%D \macros
+%D {ifMPgraphics, ifMPcmykcolors, MPcolor}
+%D
+%D A very special macro is \type{\MPcolor}. This one can be
+%D used to pass a \CONTEXT\ color to \METAPOST.
+%D
+%D \starttyping
+%D \MPcolor{my own red}
+%D \stoptyping
+%D
+%D This macro returns a \METAPOST\ triplet \type{(R,G,B)}.
+%D Unless \CMYK\ color support is turned on with \type
+%D {MPcmyk}, only \cap{RGB} colors and gray scales are
+%D supported.
+
+\newif\ifMPcmykcolors % \MPcmykcolorsfalse
+\newif\ifMPspotcolors % \MPspotcolorsfalse
+
+\ifx\MPcolor\undefined
+ \def\MPcolor#1{(0,0,0)}
+\fi
+
+%D \macros
+%D {PDFcolor,FDFcolor}
+%D
+%D Similar alternatives are avaliable for \PDF:
+
+%D For the moment we keep the next downward compatibility
+%D switch, i.e.\ expanded colors. However, predefined colors
+%D and palets are no longer expanded (which is what I wanted
+%D in the first place).
+%D
+%D Well, in case we want to do color separation and use CMYK
+%D colors only, this is dangerous since unwanted remapping may
+%D take place. Especially when we redefine already defined
+%D colors in another color space (e.g. darkgreen is
+%D predefined in RGB color space, so a redefinition in CMYK
+%D coordinates before RGB mode is disabled, would give
+%D unexpected results due to the already frozen color spec.)
+%D
+%D So, from now on, colors are not frozen any more!
+
+\chardef\currentcolorchannel=0
+
+\newif\iffilterspotcolor \filterspotcolorfalse
+\newif\ifdoingspotcolor \doingspotcolorfalse
+
+\def\registercolorchannel#1%
+ {\ifdoingspotcolor \else
+ \global\expandafter\chardef\csname\??cs#1\endcsname\zerocount
+ \fi}
+
+\newif\ifhidesplitcolor \hidesplitcolortrue
+
+%D The next macro is for instance used in figure splitting:
+
+\def\doifseparatingcolorselse
+ {\iffilterspotcolor
+ \@EA\firstoftwoarguments
+ \else\ifcase\currentcolorchannel
+ \@EAEAEA\secondoftwoarguments
+ \else
+ \@EAEAEA\firstoftwoarguments
+ \fi\fi}
+
+\def\doifcolorchannelelse#1%
+ {\doifseparatingcolorselse
+ {\doifelsenothing{#1}
+ \secondoftwoarguments
+ {\doifelse{#1}\@@clsplit
+ \firstoftwoarguments
+ \secondoftwoarguments}}
+ \secondoftwoarguments}
+
+\def\resetcolorseparation
+ {\filterspotcolorfalse
+ \chardef\currentcolorchannel\zerocount}
+
+%D These can be used in selecting specific files (like
+%D figuredatabases).
+
+% we already have:
+%
+% \def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplitsen\fi}
+% \def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplitsen-\fi}
+
+\def\colorchannelprefix{\doifseparatingcolorselse\@@clsplit\empty-}
+\def\colorchannelsuffix{-\doifseparatingcolorselse\@@clsplit\empty}
+
+%D We now define the low level macros:
+
\chardef\colorversion=2
% todo: palets in definecolor
@@ -37,8 +903,6 @@
% draw btex test etex withprescript \mptexcolor{blue} ;
% \stopMPpage
-\registerctxluafile{colo-ini}{1.000}
-
\ifx\currentcolormodel\undefined \newcount\currentcolormodel \fi
\def\setcolormodel#1%
@@ -79,28 +943,9 @@
% Since we couple definitions, we could stick to one test. Todo. Same for mpcolor.
-% \def\doactivatecolor#1% : in currentpalet, maybe not, ugly
-% {\ifcsname(cs:\currentpalet#1)\endcsname
-% \csname(cs:\currentpalet#1)\endcsname
-% \csname(ts:\currentpalet#1)\endcsname
-% \else
-% \csname(cs:#1)\endcsname
-% \csname(ts:#1)\endcsname
-% \fi}
-
-% \def\doactivatecolor#1% : in currentpalet, maybe not, ugly
-% {\csname(cs:\ifcsname(cs:\currentpalet#1)\endcsname\currentpalet\fi#1)\endcsname}
-% \csname(ts:\ifcsname(ts:\currentpalet#1)\endcsname\currentpalet\fi#1)\endcsname}
-%
-% more robust test, else we get \relaxed non-colors which may confuse e.g. mpcolor
-
\letvalue{(cs:-}\empty
\letvalue{(ts:-}\empty
-% \def\doactivatecolor#1% : in currentpalet, maybe not, ugly
-% {\csname(cs:\ifcsname(cs:\currentpalet#1)\endcsname\currentpalet#1\else\ifcsname(cs:#1)\endcsname#1\else-\fi\fi)\endcsname
-% \csname(ts:\ifcsname(ts:\currentpalet#1)\endcsname\currentpalet#1\else\ifcsname(ts:#1)\endcsname#1\else-\fi\fi)\endcsname}
-
\def\doactivatecolor#1% : in currentpalet, maybe not, ugly
{\ifcsname(cs:\currentpalet#1)\endcsname
\csname(cs:\currentpalet#1)\endcsname
@@ -131,29 +976,27 @@
\def\dodefinecolorcommand#1#2%
{\unexpanded#1{#2}{\doactivatecolor{#2}}}
-% todo: \allspotcolors
-
-\def\colorlist % not really used, only for colo-run
- {\ctxlua{tex.sprint(table.concat(table.sortedkeys(attributes.list[attributes.numbers.color]),","))}}
+\let\colorlist\empty % not really used, only for colo-run
+\setfalse\collectcolorsinlist
+\def\collectcolorinlist#1{\doglobal\addtocommalist{#1}\colorlist}
\def\dodefinecolor[#1][#2]%
- {%\addtocommalist{#1}\colorlist
+ {\ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\ctxlua{ctx.defineprocesscolor("#1","#2",false,\iffreezecolors true\else false\fi)}%
\dodefinecolorcommand\setvalue{#1}}
\def\dodefineglobalcolor[#1][#2]%
- {%\doglobal\addtocommalist{#1}\colorlist
+ {\ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\ctxlua{ctx.defineprocesscolor("#1","#2",true,\iffreezecolors true\else false\fi)}%
\dodefinecolorcommand\setgvalue{#1}}
\def\dodefinenamedcolor[#1][#2]%
- {%\doglobal\addtocommalist{#1}\colorlist
+ {\ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\ctxlua{ctx.defineprocesscolor("#1","#2",false,\iffreezecolors true\else false\fi)}%
\dodefinecolorcommand\setvalue{#1}}
\def\dodefinespotcolor[#1][#2][#3]%
- {%\doglobal\addtocommalist{#1}\colorlist % optional
- \doglobal\addtocommalist{#2}\allspotcolors
+ {\ifconditional\collectcolorsinlist\collectcolorinlist{#1}\fi
\ctxlua{ctx.definespotcolor("#1","#2","#3",true)}%
\dodefinecolorcommand\setxvalue{#1}}
@@ -293,7 +1136,7 @@
\appendtoks \initializemaintextcolor \to \everyjob
-\def\localstarttextcolor{\expanded{\startcolor[\ifx\maintextcolor\empty\defaulttextcolor\else\maintextcolor\fi]}}
+\def\localstarttextcolor{\normalexpanded{\noexpand\startcolor[\ifx\maintextcolor\empty\defaulttextcolor\else\maintextcolor\fi]}}
\let\localstoptextcolor \stopcolor
\let\restoretextcolor \firstofoneargument
@@ -302,11 +1145,14 @@
{\definecolor[\??pa#1:#2][#3]%
\iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(cs:#1:#2)}{\csname(cs:\??pa#1:#2)\endcsname}%
\iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(ca:#1:#2)}{\csname(ca:\??pa#1:#2)\endcsname}}
- {\doifdefinedelse{(cs:#3)}% \definepalet[test][xx=green]
- {\iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(cs:#1:#2)}{\csname(cs:#3)\endcsname}%
- \iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(ca:#1:#2)}{\csname(ca:#3)\endcsname}}
- {\letvalue{(cs:#1:#2)}\undefined
- \letvalue{(ca:#1:#2)}\undefined}}}
+ {\ifcsname(cs:#3)\endcsname % \definepalet[test][xx=green]
+ \iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(cs:#1:#2)}{\csname(cs:#3)\endcsname}%
+ \iffreezecolors\@EA\setevalue\else\@EA\setvalue\fi{(ca:#1:#2)}{\csname(ca:#3)\endcsname}%
+ \else
+ % not entered when making format
+ \localundefine{(cs:#1:#2)}% \letvalue{(cs:#1:#2)}\undefined
+ \localundefine{(ca:#1:#2)}% \letvalue{(ca:#1:#2)}\undefined
+ \fi}}
\setvalue{(cs:)}{} \setvalue{(ca:)}{0}
\setvalue{(ts:)}{} \setvalue{(ta:)}{0}
@@ -352,7 +1198,25 @@
\presetPDFtransparency{#2}{#3}%
\fi}
-\protect \endinput
+%D \macros
+%D {forcecolorhack}
+%D
+%D We can out this in front of (for instance) a special and so force color
+%D to be applied (only glyphs, rules and leaders are handled).
+%D
+%D \startbuffer
+%D \framed
+%D [background=color,backgroundcolor=yellow,framecolor=red,corner=round]
+%D {test}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+% ignores in attribute handler
+%
+% \def\forcecolorhack{\vrule\!!width\zeropoint\!!height\zeropoint\!!depth\zeropoint}
+
+\def\forcecolorhack{\leaders\hrule\hskip\zeropoint}
% \setupcolors[state=start]
%
@@ -368,3 +1232,48 @@
% \ctxlua{tex.print(ctx.aux.colorattribute("green"))}
% \ctxlua{tex.print(ctx.aux.colorattribute("black"))}
% \stoptext
+
+%D We default to the colors defined in \module{colo-rgb} and
+%D support both \cap{RGB} and \cap{CMYK} output. As you can
+%D see, color support is turned off by default. Reduction of
+%D gray colors to gray scales is turned on.
+
+\definecolor[black][s=0]
+\definecolor[white][s=1]
+
+\definetransparency [none] [0]
+\definetransparency [normal] [1]
+\definetransparency [multiply] [2]
+\definetransparency [screen] [3]
+\definetransparency [overlay] [4]
+\definetransparency [softlight] [5]
+\definetransparency [hardlight] [6]
+\definetransparency [colordodge] [7]
+\definetransparency [colorburn] [8]
+\definetransparency [darken] [9]
+\definetransparency [lighten] [10]
+\definetransparency [difference] [11]
+\definetransparency [exclusion] [12]
+
+\appendtoks
+ \setupcolors[\c!state=\v!start]% later direct
+\to \everyjob
+
+\setupcolors
+ [\c!state=\v!stop, % in mkii: \v!stop
+ \c!conversion=\v!yes,
+ \c!reduction=\v!no,
+ \c!rgb=\v!yes,
+ \c!cmyk=\v!yes,
+ \c!spot=\v!yes,
+ \c!mp\c!cmyk=\@@clcmyk,
+ \c!mp\c!spot=\@@clspot,
+ \c!expansion=\v!no,
+ \c!textcolor=,
+ \c!split=\v!no,
+ \c!criterium=\v!all]
+
+\setupcolor
+ [\v!rgb]
+
+\protect \endinput
diff --git a/tex/context/base/colo-ini.tex b/tex/context/base/colo-ini.tex
deleted file mode 100644
index 0136596a5..000000000
--- a/tex/context/base/colo-ini.tex
+++ /dev/null
@@ -1,1051 +0,0 @@
-%D \module
-%D [ file=colo-ini,
-%D version=2007.08.08,
-%D title=\CONTEXT\ Color Macros,
-%D subtitle=Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D We need to clean this up further but first we hav eto make sure that mkiv
-%D code works ok.
-
-\writestatus{loading}{Context Color Macros / initialization}
-
-%D This module implements color. Since \MKII\ and \MKIV\ use a completely
-%D different approach, this module only implements a few generic mechanisms.
-
-\startmessages dutch library: colors
- title: kleur
- 1: systeem -- is globaal actief
- 2: systeem -- is lokaal actief
- 3: -- is niet gedefinieerd --
- 4: systeem -- wordt geladen
- 5: onbekend systeem --
- 6: palet -- is beschikbaar
- 7: palet -- is niet beschikbaar
- 8: specificatie -- bij -- wordt zwart
- 9: -- kleurruimte wordt niet ondersteund
- 10: -- kleurruimte wordt ondersteund
- 11: kleur wordt vertaald in grijs
- 12: -- is geregistreerd
-\stopmessages
-
-\startmessages english library: colors
- title: color
- 1: system -- is global activated
- 2: system -- is local activated
- 3: -- is not defined --
- 4: system -- is loaded
- 5: unknown system --
- 6: palette -- is available
- 7: palette -- is not available
- 8: specification -- at color -- becomes black
- 9: -- color space is not supported
- 10: -- color space is supported
- 11: color is converted to gray
- 12: -- is registered
-\stopmessages
-
-\startmessages german library: colors
- title: farbe
- 1: system -- ist global aktiviert
- 2: system -- ist lokal aktiviert
- 3: -- ist undefiniert --
- 4: system -- ist geladen
- 5: unbekanntes System --
- 6: palette -- ist verfuegbar
- 7: palette -- ist nicht verfuegbar
- 8: Spezifikation -- bei Farbe -- wird schwarz
- 9: -- Farbraum wird nicht unterstuetzt
- 10: -- Farbraum wird unterstuetzt
- 11: Farbe wird in Grau umgewandelt
- 12: -- is registered
-\stopmessages
-
-\startmessages czech library: colors
- title: barva
- 1: system -- je globalne aktivovana
- 2: system -- je lokalne activovana
- 3: -- neni definovana --
- 4: system -- je nacten
- 5: neznamy system --
- 6: palette -- je k dispozici
- 7: palette -- neni k dispozici
- 8: specifikace -- v barve -- bude cerna
- 9: -- prostor barev neni podporovan
- 10: -- prostor barev je podporovan
- 11: barva je prevedena na sed
- 12: -- is registered
-\stopmessages
-
-\startmessages italian library: colors
- title: colore
- 1: sistema -- attivato globalmente
- 2: sistema -- attivato localmente
- 3: -- non definito --
- 4: sistema -- caricato
- 5: sistema -- sconosciuto
- 6: tavolozza -- resa disponibile
- 7: tavolozza -- non disponibile
- 8: specifica -- del colore -- convertita in nero
- 9: spazio dei colori -- non supportato
- 10: spazio dei colori -- supportato
- 11: il colore ø convertito in grigio
- 12: -- is registered
-\stopmessages
-
-\startmessages norwegian library: colors
- title: farge
- 1: system -- er aktivert globalt
- 2: system -- er aktivert lokalt
- 3: -- er udefinert --
- 4: system -- er lest inn
- 5: ukjent system --
- 6: palett -- er tilgjengelig
- 7: palett -- er ikke tilgjengelig
- 8: spesifikasjon -- for farge -- gir kun svart
- 9: -- fargerom er ikke støttet
- 10: -- fargerom er støttet
- 11: fargen vil bli vist som grø
- 12: -- is registered
-\stopmessages
-
-\startmessages romanian library: colors
- title: culori
- 1: sistem -- este activata global
- 2: sistem -- este activata local
- 3: -- nu este definita --
- 4: sistem -- este incarcata
- 5: sistem -- necunoscuta
- 6: paleta -- este disponibila
- 7: palette -- nu este disponibila
- 8: specificatia -- la culoarea -- devine neagra
- 9: spatiul de culoare -- nu este suportat
- 10: spatiul de culoare -- este suportat
- 11: culoarea este convertita la gri
- 12: -- is registered
-\stopmessages
-
-\startmessages french library: colors
- title: couleurs
- 1: le système -- est globalement activé
- 2: le système -- est localement activé
- 3: -- n'est pas défini --
- 4: le système -- est chargé
- 5: système -- inconnu
- 6: la palette -- est disponible
- 7: le palette -- n'est pas disponible
- 8: la spécification -- de la couleur -- devient noire
- 9: l'espace de couleur -- n'est pas supporté
- 10: -- l'espace de couleur est supporté
- 11: la couleur est convertie en niveau de gris
- 12: -- est enregistré
-\stopmessages
-
-\unprotect
-
-\chardef\colorversion=1 % temp, needed for tracing purposes, mkiv transition
-
-%D We use a couple of local registers. That way we don't have
-%D to group when converting colors. By the way, this is not
-%D really faster. We can sqeeze half a second runtime for 50K
-%D switches on a 1G machine, but the macros will become rather
-%D ugly then. To mention one such improvement: no colon
-%D after the key character (.25 sec).
-
-\newdimen\colordimen
-\newcount\colorcount
-
-%D When typesetting for paper, we prefer using the \cap{CMYK}
-%D color space, but for on||screen viewing we prefer \cap{RGB}
-%D (the previous implementation supported only this scheme).
-%D Independant of such specifications, we support some automatic
-%D conversions:
-%D
-%D \startitemize[packed]
-%D \item convert all colors to \cap{RGB}
-%D \item convert all colors to \cap{CMYK}
-%D \item convert all colors to gray scales
-%D \stopitemize
-%D
-%D We also support optimization of colors to gray scales.
-%D
-%D \startitemize[continue]
-%D \item reduce gray colors to gray scales
-%D \item reduce \cap{CMY} components to \cap{K}
-%D \stopitemize
-%D
-%D These options are communicated by means of:
-
-\newif\ifRGBsupported
-\newif\ifCMYKsupported
-\newif\ifSPOTsupported
-\newif\ifpreferGRAY
-\newif\ifGRAYprefered
-\newif\ifreduceCMYK
-\newif\ifconverttoGRAY
-\newif\ifweightGRAY \weightGRAYtrue
-
-\newif\ifconvertMPcolors
-\newif\ifreduceMPcolors
-\newif\ifforcegrayMPcolors
-
-%D The last boolean controls reduction of \cap{CMYK} to
-%D \cap{CMY} colors. When set to true, the black component
-%D is added to the other ones.
-%D
-%D Prefering gray is not the same as converting to gray.
-%D Conversion treats each color components in a different way,
-%D while prefering is just a reduction and thus a
-%D space||saving option.
-
-\newif\iffreezecolors \freezecolorsfalse
-\newif\ifincolor % true if colors enabled
-\newif\iflocalcolor
-
-\let\colorlist \empty
-\let\currentspotcolor \empty
-\let\allspotcolors \empty
-\let\usedspotcolors \empty
-\let\usedcolorchannels\empty
-\let\currentpalet \empty
-
-%D \macros
-%D {definecolor,defineglobalcolor,definenamedcolor,definespotcolor,definemultitonecolor}
-%D
-%D \startbuffer
-%D \definecolor [blue] [c=1,m=.38,y=0,k=.64] % pantone pms 2965 uncoated m
-%D \definecolor [yellow] [c=0,m=.28,y=1,k=.06] % pantone pms 124 uncoated m
-%D
-%D \definespotcolor [blue-100] [blue] [p=1]
-%D \definespotcolor [yellow-100] [yellow] [p=1]
-%D
-%D \definemultitonecolor [pdftoolscolor] [blue=.12,yellow=.28] [c=.1,m=.1,y=.3,k=.1]
-%D
-%D \useexternalfigure[demofig][mill.png][object=no]
-%D
-%D \startcombination[4*1]
-%D {\externalfigure[demofig]} {no color}
-%D {\externalfigure[demofig][color=pdftoolscolor]} {indexed duotone}
-%D {\externalfigure[demofig][color=blue-100]} {spot color}
-%D {\externalfigure[demofig][color=yellow-100]} {spot color}
-%D \stopcombination
-%D \stopbuffer
-%D
-%D \getbuffer \typebuffer
-
-\def\definecolor {\dodoubleargument\dodefinecolor}
-\def\defineglobalcolor {\dodoubleargument\dodefineglobalcolor}
-\def\definenamedcolor {\dodoubleargument\dodefinenamedcolor}
-\def\definespotcolor {\dotripleargument\dodefinespotcolor}
-\def\definemultitonecolor{\doquadrupleempty\dodefinemultitonecolor}
-
-% check: registerusedspotcolors
-% check: registerusedcolorchannels
-
-%D \macros
-%D {doifcolorelse, doifcolor}
-%D
-%D Switching to a color is done by means of the following
-%D command. Later on we will explain the use of palets. We
-%D define ourselves a color conditional first.
-
-\ifx\doifcolorelse\undefined
- \let\doifcolorelse\secondoftwoarguments
- \let\doifcolor \gobbleoneargument
-\fi
-
-%D \macros
-%D {localstartcolor,localstopcolor}
-%D
-%D Simple color support, that is without nesting, is provided
-%D by:
-
-\ifx\localstartcolor\undefined
- \let\localstartcolor\undefined
- \let\localstopcolor \undefined
-\fi
-
-%D \macros
-%D {faststartcolor,faststopcolor}
-%D
-%D No checking for arguments and such:
-
-\ifx\faststartcolor\undefined
- \def\faststartcolor[#1]{}
- \def\faststopcolor {}
-\fi
-
-%D These local ones may go away in future versions.
-
-%D \macros
-%D {startcolor,stopcolor}
-%D
-%D The more save method, the one that saves the current color
-%D state and returns to this state afterward, is activated by:
-%D
-%D \showsetup{startcolor}
-
-\ifx\startcolor\undefined
- \let\startcolor\undefined
- \let\stopcolor \undefined
-\fi
-
-%D \macros
-%D {startcurrentcolor,stopcurrentcolor}
-
-\def\startcurrentcolor{\startcolor[\outercolorname]}
-\def\stopcurrentcolor {\stopcolor}
-
-%D \macros
-%D {color,graycolor}
-%D
-%D This leaves the simple color command:
-%D
-%D \showsetup{color}
-%D \showsetup{graycolor}
-
-\ifx\color\undefined
- \def\color [#1]{}
- \def\graycolor[#1]{}
- \def\gray {\graycolor}
-\fi
-
-%D \macros
-%D {localstartraster,localstopraster,
-%D startraster,stopraster,raster}
-%D
-%D The previous conversions are not linear and treat each color
-%D component according to human perception curves. Pure gray
-%D (we call them rasters) has equal color components. In
-%D \CONTEXT\ rasters are only used as backgrounds and these
-%D don't cross page boundaries in the way color does. Therefore
-%D we don't need stacks and marks. Just to be compatible with
-%D color support we offer both 'global' and 'local' commands.
-
-\ifx\startraster\undefined
- \def\startraster [#1]{}
- \def\stopraster {}
- \def\raster [#1]{}
- \def\localstartraster[#1]{}
- \def\localstopraster {}
-\fi
-
-%D \macros
-%D {colorvalue, grayvalue}
-%D
-%D We can typeset the color components using \type{\colorvalue} and
-%D \type{\grayvalue}. The commands:
-%D
-%D \startbuffer
-%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
-%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D show us:
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-
-\def\colorformatseparator{ }
-
-\ifx\colorvalue\undefined
- \let\colorvalue\gobbleoneargument
- \let\grayvalue \gobbleoneargument
-\fi
-
-% check: \currentcolorname
-% check: \outercolorname
-
-%D \macros
-%D {setupcolor}
-%D
-%D Color definitions can be grouped in files with the name:
-%D
-%D \starttyping
-%D \f!colorprefix-identifier.tex
-%D \stoptyping
-%D
-%D where \type{\f!colorprefix} is \unprotect {\tttf \f!colorprefix}.
-%D Loading such a file is done by \protect
-%D
-%D \showsetup{setupcolor}
-%D
-%D Some default colors are specified in \type{colo-rgb.tex},
-%D which is loaded into the format by:
-%D
-%D \starttyping
-%D \setupcolor[rgb]
-%D \stoptyping
-
-\let\colorstyle\empty
-
-\def\setupcolor
- {\dosingleargument\dosetupcolor}
-
-\def\dosetupcolor[#1]%
- {\doifnot{#1}\colorstyle
- {\def\colorstyle{#1}%
- \processcommalist[#1]\dodosetupcolor}}
-
-\def\dodosetupcolor#1%
- {\makeshortfilename[\truefilename{\f!colorprefix#1}]%
- \startreadingfile
- \readsysfile\shortfilename
- {\showmessage\m!colors4\colorstyle}
- {\showmessage\m!colors5\colorstyle}%
- \stopreadingfile}
-
-\let\usecolors\setupcolor
-
-% check: \chardef\currentcolorchannel=0
-% check: \startcolormode
-% check: \newif\iffilterspotcolor \filterspotcolorfalse
-% check: \newif\ifdoingspotcolor \doingspotcolorfalse
-% check: \registercolorchannel
-
-%D \macros
-%D {definetransparency}
-%D
-%D This command numbers to names:
-
-\def\definetransparency
- {\dodoubleargument\dodefinetransparency}
-
-\def\setupcolors
- {\dosingleargument\dosetupcolors}
-
-\def\resetcolorsplitting
- {\chardef\currentcolorchannel\zerocount
- \let\currentspotcolor\empty
- \filterspotcolorfalse}
-
-\def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplit\fi}
-\def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplit-\fi}
-
-\def\setcolorsplitting
- {\resetsystemmode{\v!color\colorsplitsuffix}%
- \resetcolorsplitting
- \processaction
- [\@@clsplit]
- [ c=>\chardef\currentcolorchannel1,%
- m=>\chardef\currentcolorchannel2,%
- y=>\chardef\currentcolorchannel3,%
- k=>\chardef\currentcolorchannel4,%
- r=>\chardef\currentcolorchannel5,%
- g=>\chardef\currentcolorchannel6,%
- b=>\chardef\currentcolorchannel7,%
- s=>\chardef\currentcolorchannel8,%
- \v!no=>,% \currentcolorchannel0,% all colors
- \s!default=>,% \currentcolorchannel0,% all colors
- \s!unknown=>\filterspotcolortrue
- \edef\currentspotcolor{\commalistelement}]%
- \setsystemmode{\v!color\colorsplitsuffix}%
- \iffilterspotcolor \let\@@clrgb\v!no \fi}
-
-\ifx\dosetupcolormodel\undefined
- \let\dosetupcolormodel\relax
-\fi
-
-\def\dosetupcolors[#1]% some no longer make sense in MkIV
- {\getparameters[\??cl][#1]%
- \doifelse\@@clspot\v!yes
- \SPOTsupportedtrue
- \SPOTsupportedfalse
- \doifelsenothing\@@clsplit
- \resetcolorsplitting
- \setcolorsplitting
- \doifelse\@@clreduction\v!yes
- \reduceCMYKtrue
- \reduceCMYKfalse
- \doifelse\@@clexpansion\v!yes
- \freezecolorstrue
- \freezecolorsfalse
- \doifelse\@@clcriterium\v!all
- \hidesplitcolortrue
- \hidesplitcolorfalse
- \doifelse\@@clrgb\v!no
- {\ifRGBsupported \showmessage\m!colors {9}\v!rgb\RGBsupportedfalse\fi}
- {\ifRGBsupported\else\showmessage\m!colors{10}\v!rgb\RGBsupportedtrue \fi}%
- \doifelse\@@clcmyk\v!no
- {\ifCMYKsupported \showmessage\m!colors {9}\v!cmyk\CMYKsupportedfalse\fi}
- {\ifCMYKsupported\else\showmessage\m!colors{10}\v!cmyk\CMYKsupportedtrue \fi}%
- \doifelse\@@clmpcmyk\v!no
- {\ifMPcmykcolors \showmessage\m!colors {9}{\v!mp\v!cmyk}\MPcmykcolorsfalse\fi}
- {\ifMPcmykcolors\else\showmessage\m!colors{10}{\v!mp\v!cmyk}\MPcmykcolorstrue \fi}%
- \doifelse\@@clmpspot\v!no
- {\ifMPspotcolors \showmessage\m!colors {9}{\v!mp\v!spot}\MPspotcolorsfalse\fi}
- {\ifMPspotcolors\else\showmessage\m!colors{10}{\v!mp\v!spot}\MPspotcolorstrue \fi}%
- \preferGRAYfalse
- \processaction
- [\@@clconversion]
- [ \v!yes=>\preferGRAYtrue,
- \v!always=>\preferGRAYtrue\RGBsupportedfalse\CMYKsupportedfalse]%
- \ifRGBsupported
- \converttoGRAYfalse
- \forcegrayMPcolorsfalse
- \else\ifCMYKsupported
- \converttoGRAYfalse
- \forcegrayMPcolorsfalse
- \convertMPcolorstrue
- \ifreduceCMYK
- \reduceMPcolorstrue
- \fi
- \else
- \ifconverttoGRAY\else\showmessage\m!colors{11}\empty\fi
- \converttoGRAYtrue
- \forcegrayMPcolorstrue
- \convertMPcolorsfalse
- \reduceMPcolorsfalse
- \fi\fi
- \processaction
- [\@@clstate]
- [ \v!global=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
- \incolortrue\localcolorfalse,
- \v!local=>\ifincolor\else\showmessage\m!colors2\colorstyle\fi
- \incolortrue\localcolortrue,
- \v!start=>\ifincolor\else\showmessage\m!colors1\colorstyle\fi
- \incolortrue\localcolorfalse
- \let\@@clstate\v!global,
- \v!stop=>\incolorfalse\localcolorfalse
- \forcegrayMPcolorstrue]%
- \dosetupcolormodel
- \initializemaintextcolor}
-
-%D \macros
-%D {startregistercolor,stopregistercolor,permitcolormode}
-%D
-%D If you only want to register a color, the switch \type
-%D {\ifpermitcolormode} can be used. That way the nested
-%D colors know where to go back to.
-
-\ifx\startregistercolor\undefined
- \def\startregistercolor[#1]{}
- \def\stopregistercolor {}
-\fi
-
-%D We use these macros for implementing text colors
-%D (actually, the first application was in foreground
-%D colors).
-%D
-%D \starttyping
-%D \starttextcolor[red]
-%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
-%D \stoptextcolor
-%D \stoptyping
-%D
-%D This is more efficient than the alternative:
-%D
-%D \starttyping
-%D \setupbackgrounds[text][foregroundcolor=red]
-%D \startregistercolor[red]
-%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
-%D \stopregistercolor
-%D \stoptyping
-
-\def\maintextcolor {}
-\def\defaulttextcolor {black}
-\def\@@themaintextcolor{themaintextcolor}
-
-\ifx\initializemaintextcolor\undefined
- \def\starttextcolor [#1]{}
- \def\stoptextcolor {}
- \def\initializemaintextcolor {}
-\fi
-
-\ifx\restoretextcolor\undefined % to be redone
- \let\restoretextcolor \firstofoneargument
- \let\localstarttextcolor\relax
- \let\localstoptextcolor \relax
-\fi
-
-%D In this documentation we will not go into too much details
-%D on palets. Curious users can find more information on this
-%D topic in \from[use of color].
-%D
-%D At the moment we implemented color in \CONTEXT\ color
-%D printing was not yet on the desktop. In spite of this lack our
-%D graphics designer made colorfull illustrations. When printed
-%D on a black and white printer, distinctive colors can come
-%D out equally gray. We therefore decided to use only colors
-%D that were distinctive in colors as well as in black and
-%D white print.
-%D
-%D Although none of the graphic packages we used supported
-%D logical colors and global color redefition, we build this
-%D support into \CONTEXT. This enabled us to experiment and
-%D also prepared us for the future.
-
-%D \macros
-%D {definepalet}
-%D
-%D Colors are grouped in palets. The colors in such a palet can
-%D have colorful names, but best is to use names that specify
-%D their use, like {\em important} or {\em danger}. As a sort
-%D of example \CONTEXT\ has some palets predefined,
-%D like:\footnote{At the time I wrote the palet support, I was
-%D reading 'A hort history of time' of S.~Hawkins, so that's
-%D why we stuck to quarks.}
-%D
-%D \starttyping
-%D \definepalet
-%D [alfa]
-%D [ top=rood:7,
-%D bottom=groen:6,
-%D up=blauw:5,
-%D down=cyaan:4,
-%D strange=magenta:3,
-%D charm=geel:2]
-%D \stoptyping
-%D
-%D It's formal definition is:
-%D
-%D \showsetup{definepalet}
-%D
-%D Visualized, such a palet looks like:
-%D
-%D \startbuffer[palet]
-%D \showpalet [alfa] [horizontal,name,number,value]
-%D \stopbuffer
-%D
-%D \startlinecorrection
-%D \getbuffer[palet]
-%D \stoplinecorrection
-%D
-%D This bar shows both the color and gray alternatives of the
-%D palet components (not visible in black and white print).
-%D
-%D When needed, one can copy a palet by saying:
-%D
-%D \starttyping
-%D \definepalet [TEXcolorpretty] [colorpretty]
-%D \stoptyping
-%D
-%D This saves us some typing in for instance the modules that
-%D deal with pretty verbatim typesetting.
-
-\def\definepalet
- {\dodoubleargument\dodefinepalet}
-
-\def\dodefinepalet[#1][#2]%
- {\doifassignmentelse{#2}
- {%\showmessage\m!colors6{#1}%
- \letvalue{\??pa#1}\empty
- \setevalue{\??pa\??pa#1}{#2}%
- \def\dodododefinepalet[##1=##2]%
- {\doifvaluesomething{\??pa#1}
- {\setevalue{\??pa#1}{\csname\??pa#1\endcsname,}}%
- \setevalue{\??pa#1}{\csname\??pa#1\endcsname##1}%
- \dodefinepaletcolor{#1}{##1}{##2}}%
- \def\dododefinepalet##1%
- {\dodododefinepalet[##1]}%
- \processcommalist[#2]\dododefinepalet}
- {\doifdefined{\??pa#2}
- {\expanded{\dodefinepalet[#1][\csname\??pa\??pa#2\endcsname]}}}}
-
-\ifx\dodefinepaletcolor\undefined
- \let\dodefinepaletcolor\gobblethreearguments
-\fi
-
-\let\paletsize\!!zerocount
-
-\def\getpaletsize[#1]%
- {\getcommacommandsize[\csname\??pa\??pa#1\endcsname]%
- \edef\paletsize{\number\commalistsize}}
-
-%D Instead of refering to colors, one can also directly specify
-%D a color:
-%D
-%D \starttyping
-%D \definepalet[test][xx=green]
-%D \definepalet[test][xx={y=.4}]
-%D \stoptyping
-
-%D \macros
-%D {setuppalet}
-%D
-%D Colors are taken from the current palet, if defined.
-%D Setting the current palet is done by:
-%D
-%D \showsetup{setuppalet}
-
-\let\currentpalet\empty
-
-\def\setuppalet
- {\dosingleempty\dosetuppalet}
-
-\def\dosetuppalet[#1]%
- {\edef\currentpalet{#1}%
- \ifx\currentpalet\empty
- % seems to be a reset
- \else\ifcsname\??pa\currentpalet\endcsname
- \edef\currentpalet{#1:}%
- \else
- \showmessage\m!colors7\currentpalet
- \let\currentpalet\empty
- \fi\fi}
-
-%D \macros
-%D {showpalet}
-%D
-%D The previous visualization was typeset with:
-%D
-%D \typebuffer[palet]
-%D
-%D This commands is defined as:
-%D
-%D \showsetup{showpalet}
-
-\fetchruntimecommand \showpalet {\f!colorprefix\s!run}
-
-%D \macros
-%D {showcolorcomponents}
-%D
-%D \starttyping
-%D \showcolorcomponents[color-1,color-2]
-%D \stoptyping
-
-\fetchruntimecommand \showcolorcomponents {\f!colorprefix\s!run}
-
-%D \macros
-%D {definecolorgroup}
-%D
-%D The naming of the colors in this palet suggests some
-%D ordening, which in turn is suported by color grouping.
-%D
-%D \starttyping
-%D \definecolorgroup
-%D [red]
-%D [1.00:0.90:0.90,
-%D 1.00:0.80:0.80,
-%D 1.00:0.70:0.70,
-%D 1.00:0.55:0.55,
-%D 1.00:0.40:0.40,
-%D 1.00:0.25:0.25,
-%D 1.00:0.15:0.15,
-%D 0.90:0.00:0.00]
-%D \stoptyping
-%D
-%D In such a color group colors are numbered from~$1$ to~$n$.
-%D
-%D \showsetup{definecolorgroup}
-%D
-%D This kind of specification is not only more compact than
-%D defining each color separate, it also loads faster and takes
-%D less bytes.
-
-\def\definecolorgroup
- {\dotripleempty\dodefinecolorgroup}
-
-\def\dododefinecolorgroupgray [#1][#2:#3]{\definecolor [#1:\the\colorcount][s=#2]}
-\def\dododefinecolorgrouprgb [#1][#2:#3:#4:#5]{\definecolor [#1:\the\colorcount][r=#2,g=#3,b=#4]}
-\def\dododefinecolorgroupcmyk[#1][#2:#3:#4:#5:#6]{\definecolor [#1:\the\colorcount][c=#2,m=#3=,y=#4,k=#5]}
-\def\dododefinecolorgroupspot [#1][#2:#3:#4]{\definespotolor[#1:\the\colorcount][#2][p=#3]}
-
-\def\dododefinecolorgroup#1#2%
- {\advance\colorcount\plusone
- \getvalue{dododefinecolorgroup\currentcolorspace}[#1][#2:0:0:0:0]}
-
-\def\dodefinecolorgroup[#1][#2][#3]% obsolete, just use palets
- {\ifthirdargument
- \doifelsenothing{#2}{\let\currentcolorspace\v!rgb}{\def\currentcolorspace{#2}}%
- \colorcount\zerocount
- \processcommalist[#3]{\dododefinecolorgroup{#1}}%
- \else
- \doifinstringelse{:}{#2}
- {\definecolorgroup[#1][\v!rgb][#2]}
- {\doloop
- {\doifdefinedelse{\??cr#2:\recurselevel}
- {\setevalue{\??cr#1:\recurselevel}{\csname\??cr#2:\recurselevel\endcsname}}
- {\exitloop}}}%
- \fi}
-
-%D \macros
-%D {showcolorgroup}
-%D
-%D We can show the group by:
-%D
-%D \startbuffer
-%D \showcolorgroup [blue] [horizontal,name,number,value]
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D or in color:
-%D
-%D \startlinecorrection
-%D \getbuffer
-%D \stoplinecorrection
-%D
-%D which uses:
-%D
-%D \showsetup{showcolorgroup}
-
-\fetchruntimecommand \showcolorgroup {\f!colorprefix\s!run}
-
-%D There are ten predefined color groups, like
-%D \color[green]{\em groen}, \color[red]{\em rood},
-%D \color[blue]{\em blauw}, \color[cyan]{\em cyaan},
-%D \color[magenta]{\em magenta} and \color[yellow]{\em geel}.
-%D
-%D \startlinecorrection
-%D \hbox to \hsize
-%D {\hss
-%D \showcolorgroup [red] [vertical,name,number]\hss
-%D \showcolorgroup [green] [vertical,name]\hss
-%D \showcolorgroup [blue] [vertical,name]\hss
-%D \showcolorgroup [cyan] [vertical,name]\hss
-%D \showcolorgroup [magenta][vertical,name]\hss
-%D \showcolorgroup [yellow] [vertical,name]\hss}
-%D \stoplinecorrection
-%D
-%D These groups are used to define palets {\em alfa} upto {\em
-%D zeta}. As long as we don't use colors from the same row, we
-%D get ourselves distinctive palets. By activating such a palet
-%D one gains access to its members {\em top} to {\em charm} (of
-%D course one should use more suitable names than these).
-%D
-%D \startlinecorrection
-%D \hbox to \hsize
-%D {\showpalet [alfa] [vertical,name,number]\hss
-%D \showpalet [beta] [vertical,name]\hss
-%D \showpalet [gamma] [vertical,name]\hss
-%D \showpalet [delta] [vertical,name]\hss
-%D \showpalet [epsilon] [vertical,name]\hss
-%D \showpalet [zeta] [vertical,name]}
-%D \stoplinecorrection
-%D
-%D By using the keyword \type {value} the individual color
-%D components are shown too. When printed in color, these
-%D showcases show both the colors and the gray value.
-
-%D \macros
-%D {comparepalet}
-%D
-%D There are some more testing macros available:
-%D
-%D \startbuffer
-%D \comparepalet [alfa]
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D shows the palet colors against a background:
-%D
-%D \startlinecorrection
-%D \getbuffer
-%D \stoplinecorrection
-%D
-%D The formal definition is:
-%D
-%D \showsetup{comparepalet}
-
-\fetchruntimecommand \comparepalet {\f!colorprefix\s!run}
-
-%D \macros
-%D {comparecolorgroup}
-%D
-%D The similar command:
-%D
-%D \startbuffer
-%D \comparecolorgroup [blue]
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D shows color groups:
-%D
-%D \startlinecorrection
-%D \getbuffer
-%D \stoplinecorrection
-%D
-%D this commands are defined as:
-%D
-%D \showsetup{comparecolorgroup}
-
-\fetchruntimecommand \comparecolorgroup {\f!colorprefix\s!run}
-
-%D \macros
-%D {showcolor}
-%D
-%D But let's not forget that we also have the more traditional
-%D non||related colors. These show up after:
-%D
-%D \starttyping
-%D \showcolor [name]
-%D \stoptyping
-%D
-%D Where \type{name} for instance can be \type{rgb}.
-%D
-%D \showsetup{showcolor}
-
-\fetchruntimecommand \showcolor {\f!colorprefix\s!run}
-
-%D It would make sense to put the following code in \type
-%D {colo-mps}, but it it rather low level.
-
-%D \macros
-%D {negatecolorcomponent,negatedcolorcomponent}
-%D
-%D These speak for themselves. See \type {colo-ext} for usage.
-
-\def\negatecolorcomponent#1% #1 = \macro
- {\scratchdimen\onepoint\advance\scratchdimen-#1\onepoint
- \ifdim\scratchdimen<\zeropoint\scratchdimen\zeropoint\fi
- \edef#1{\withoutpt\the\scratchdimen}}
-
-\let\negatedcolorcomponent\firstofoneargument
-
-\def\negatedcolorcomponent#1%
- {\ifdim\dimexpr\onepoint-#1\onepoint\relax<\zeropoint
- \!!zerocount
- \else
- \expandafter\withoutpt\the\dimexpr\onepoint-#1\onepoint\relax
- \fi}
-
-\def\negatecolorcomponent#1% #1 = \macro
- {\edef#1{\negatedcolorcomponent{#1}}}
-
-%D \macros
-%D {ifMPgraphics, ifMPcmykcolors, MPcolor}
-%D
-%D A very special macro is \type{\MPcolor}. This one can be
-%D used to pass a \CONTEXT\ color to \METAPOST.
-%D
-%D \starttyping
-%D \MPcolor{my own red}
-%D \stoptyping
-%D
-%D This macro returns a \METAPOST\ triplet \type{(R,G,B)}.
-%D Unless \CMYK\ color support is turned on with \type
-%D {MPcmyk}, only \cap{RGB} colors and gray scales are
-%D supported.
-
-\newif\ifMPcmykcolors % \MPcmykcolorsfalse
-\newif\ifMPspotcolors % \MPspotcolorsfalse
-
-\ifx\MPcolor\undefined
- \def\MPcolor#1{(0,0,0)}
-\fi
-
-%D \macros
-%D {PDFcolor,FDFcolor}
-%D
-%D Similar alternatives are avaliable for \PDF:
-
-%D For the moment we keep the next downward compatibility
-%D switch, i.e.\ expanded colors. However, predefined colors
-%D and palets are no longer expanded (which is what I wanted
-%D in the first place).
-%D
-%D Well, in case we want to do color separation and use CMYK
-%D colors only, this is dangerous since unwanted remapping may
-%D take place. Especially when we redefine already defined
-%D colors in another color space (e.g. darkgreen is
-%D predefined in RGB color space, so a redefinition in CMYK
-%D coordinates before RGB mode is disabled, would give
-%D unexpected results due to the already frozen color spec.)
-%D
-%D So, from now on, colors are not frozen any more!
-
-% \appendtoks\setupcolors[\c!expansie=\v!ja]\to\everyjob
-
-\chardef\currentcolorchannel=0
-
-\newif\iffilterspotcolor \filterspotcolorfalse
-\newif\ifdoingspotcolor \doingspotcolorfalse
-
-\def\registercolorchannel#1%
- {\ifdoingspotcolor \else
- \global\expandafter\chardef\csname\??cs#1\endcsname\zerocount
- \fi}
-
-\newif\ifhidesplitcolor \hidesplitcolortrue
-
-%D The next macro is for instance used in figure splitting:
-
-\def\doifseparatingcolorselse
- {\iffilterspotcolor
- \@EA\firstoftwoarguments
- \else\ifcase\currentcolorchannel
- \@EAEAEA\secondoftwoarguments
- \else
- \@EAEAEA\firstoftwoarguments
- \fi\fi}
-
-\def\doifcolorchannelelse#1%
- {\doifseparatingcolorselse
- {\doifelsenothing{#1}
- \secondoftwoarguments
- {\doifelse{#1}\@@clsplit
- \firstoftwoarguments
- \secondoftwoarguments}}
- \secondoftwoarguments}
-
-\def\resetcolorseparation
- {\filterspotcolorfalse
- \chardef\currentcolorchannel\zerocount}
-
-%D These can be used in selecting specific files (like
-%D figuredatabases).
-
-% we already have:
-%
-% \def\colorsplitsuffix{\ifcase\currentcolorchannel\else-\@@clsplitsen\fi}
-% \def\colorsplitprefix{\ifcase\currentcolorchannel\else\@@clsplitsen-\fi}
-
-\def\colorchannelprefix{\doifseparatingcolorselse\@@clsplit\empty-}
-\def\colorchannelsuffix{-\doifseparatingcolorselse\@@clsplit\empty}
-
-%D We now load the low level macros:
-
-\loadmarkfile{colo-ini}
-
-%D We default to the colors defined in \module{colo-rgb} and
-%D support both \cap{RGB} and \cap{CMYK} output. As you can
-%D see, color support is turned off by default. Reduction of
-%D gray colors to gray scales is turned on.
-
-\definecolor[black][s=0]
-\definecolor[white][s=1]
-
-\definetransparency [none] [0]
-\definetransparency [normal] [1]
-\definetransparency [multiply] [2]
-\definetransparency [screen] [3]
-\definetransparency [overlay] [4]
-\definetransparency [softlight] [5]
-\definetransparency [hardlight] [6]
-\definetransparency [colordodge] [7]
-\definetransparency [colorburn] [8]
-\definetransparency [darken] [9]
-\definetransparency [lighten] [10]
-\definetransparency [difference] [11]
-\definetransparency [exclusion] [12]
-
-\setupcolors
- [\c!state=\v!stop,
- \c!conversion=\v!yes,
- \c!reduction=\v!no,
- \c!rgb=\v!yes,
- \c!cmyk=\v!yes,
- \c!spot=\v!yes,
- \c!mp\c!cmyk=\@@clcmyk,
- \c!mp\c!spot=\@@clspot,
- \c!expansion=\v!no,
- \c!textcolor=,
- \c!split=\v!no,
- \c!criterium=\v!all]
-
-\setupcolor
- [\v!rgb]
-
-\protect \endinput
diff --git a/tex/context/base/colo-run.tex b/tex/context/base/colo-run.tex
index 6313255c3..d94ea9801 100644
--- a/tex/context/base/colo-run.tex
+++ b/tex/context/base/colo-run.tex
@@ -155,8 +155,9 @@
\gdef\doshowcolor[#1]%
{\bgroup
\iffirstargument
- \let\colorlist\empty
+ \let\colorlist\empty % not really used, only for colo-run
\let\colorstyle\empty
+ \settrue\collectcolorsinlist
\setupcolor[#1]%
\fi
\def\rule
diff --git a/tex/context/base/cont-cs.tex b/tex/context/base/cont-cs.tex
index 94235a8b3..f878920aa 100644
--- a/tex/context/base/cont-cs.tex
+++ b/tex/context/base/cont-cs.tex
@@ -26,6 +26,14 @@
\installlanguage [\s!sk] [\c!state=\v!start]
\installlanguage [\s!cs] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-de.tex b/tex/context/base/cont-de.tex
index 95976e815..460ca7eca 100644
--- a/tex/context/base/cont-de.tex
+++ b/tex/context/base/cont-de.tex
@@ -31,6 +31,14 @@
\installlanguage [deo] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-en.tex b/tex/context/base/cont-en.tex
index e3275845c..e2b09ecbe 100644
--- a/tex/context/base/cont-en.tex
+++ b/tex/context/base/cont-en.tex
@@ -35,6 +35,12 @@
\installlanguage [\s!sk] [\c!state=\v!start]
\installlanguage [\s!pl] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+% \prependtoks
+% \the \everysetupdocument
+% \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-fil.tex b/tex/context/base/cont-fil.tex
index a0712a42f..28b6b6f55 100644
--- a/tex/context/base/cont-fil.tex
+++ b/tex/context/base/cont-fil.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context File Synonyms}
+\writestatus{loading}{ConTeXt File Synonyms}
\definefilesynonym [chemie] [chemic]
\definefilesynonym [chemics] [chemic]
diff --git a/tex/context/base/cont-fr.tex b/tex/context/base/cont-fr.tex
index c6cf11ff1..d812b28f9 100644
--- a/tex/context/base/cont-fr.tex
+++ b/tex/context/base/cont-fr.tex
@@ -29,6 +29,14 @@
\installlanguage [\s!nl] [\c!state=\v!start]
\installlanguage [\s!it] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-gb.tex b/tex/context/base/cont-gb.tex
index 6e60cd1bc..99d297425 100644
--- a/tex/context/base/cont-gb.tex
+++ b/tex/context/base/cont-gb.tex
@@ -29,6 +29,14 @@
\installlanguage [\s!nl] [\c!state=\v!start]
\installlanguage [\s!it] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-it.tex b/tex/context/base/cont-it.tex
index d3141a4ae..2141e3bc9 100644
--- a/tex/context/base/cont-it.tex
+++ b/tex/context/base/cont-it.tex
@@ -28,6 +28,14 @@
\installlanguage [\s!es] [\c!state=\v!start]
\installlanguage [\s!it] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-log.tex b/tex/context/base/cont-log.tex
index fb821331d..8419394c4 100644
--- a/tex/context/base/cont-log.tex
+++ b/tex/context/base/cont-log.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context TeX Logos}
+\writestatus{loading}{ConTeXt TeX Logos}
%D The system that is used to typeset this text is called \TEX,
%D typeset with an lowered~E. From te beginning of \TEX,
@@ -228,6 +228,7 @@
\def\pdfTeX {pdf\TeX}
\def\pdfeTeX {pdfe-\TeX}
\def\luaTeX {lua\TeX}
+\def\metaTeX {meta\TeX}
\unexpanded\def\XeTeX {X\lower.5ex\hbox{\kern-.15em\mirror{E}}\kern-.1667em\TeX}
% Better, since lm has a mirrored E (don't ask me why)
@@ -251,41 +252,39 @@
{\setbox\scratchbox\hbox{E}%
\raise\dimexpr\ht\scratchbox+\dp\scratchbox\relax\hbox{\rotate[\c!rotation=180]{\box\scratchbox}}}
-\beginNEWTEX
-
-\unexpanded\def\XeTeX
- {X\lower.5ex
- \hbox
- {\kern-.15em
- \iffontchar\font"018E\relax
- \char"018E%
- \else
- \ifx\fontalternative\c!bf\mirror{E}\else
- \ifx\fontalternative\c!it \@XeTeX@\else
- \ifx\fontalternative\c!sl \@XeTeX@\else
- \ifx\fontalternative\c!bi \@XeTeX@\else
- \ifx\fontalternative\c!bs \@XeTeX@\else
- \mirror{E}\fi\fi\fi\fi\fi
- \fi}%
- \kern-.1667em \TeX}
-
-\endNEWTEX
-
-\beginOLDTEX
-
-\unexpanded\def\XeTeX
- {X\lower.5ex
- \hbox
- {\kern-.15em
- \ifx\fontalternative\c!bf\mirror{E}\else
- \ifx\fontalternative\c!it \@XeTeX@\else
- \ifx\fontalternative\c!sl \@XeTeX@\else
- \ifx\fontalternative\c!bi \@XeTeX@\else
- \ifx\fontalternative\c!bs \@XeTeX@\else
- \mirror{E}\fi\fi\fi\fi\fi}%
- \kern-.1667em \TeX}
-
-\endOLDTEX
+\ifnum\texengine=\pdftexengine
+
+ \unexpanded\def\XeTeX
+ {X\lower.5ex
+ \hbox
+ {\kern-.15em
+ \ifx\fontalternative\c!bf\mirror{E}\else
+ \ifx\fontalternative\c!it \@XeTeX@\else
+ \ifx\fontalternative\c!sl \@XeTeX@\else
+ \ifx\fontalternative\c!bi \@XeTeX@\else
+ \ifx\fontalternative\c!bs \@XeTeX@\else
+ \mirror{E}\fi\fi\fi\fi\fi}%
+ \kern-.1667em \TeX}
+
+\else
+
+ \unexpanded\def\XeTeX
+ {X\lower.5ex
+ \hbox
+ {\kern-.15em
+ \iffontchar\font"018E\relax
+ \char"018E%
+ \else
+ \ifx\fontalternative\c!bf\mirror{E}\else
+ \ifx\fontalternative\c!it \@XeTeX@\else
+ \ifx\fontalternative\c!sl \@XeTeX@\else
+ \ifx\fontalternative\c!bi \@XeTeX@\else
+ \ifx\fontalternative\c!bs \@XeTeX@\else
+ \mirror{E}\fi\fi\fi\fi\fi
+ \fi}%
+ \kern-.1667em \TeX}
+
+\fi
\let\ETEX \eTeX
\let\PDFTEX \pdfTeX
diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv
index 20813c37b..9e2ca49c0 100644
--- a/tex/context/base/cont-new.mkiv
+++ b/tex/context/base/cont-new.mkiv
@@ -24,8 +24,32 @@
\unprotect
+% we need to figure this out (to be discussed)
+
+\unexpanded\def\textminus
+ {\char \iffontchar\font"2012 "2012 % figuredash
+ \else\iffontchar\font"2013 "2013 % endash
+ \else\iffontchar\font"2212 "2212 % math minus
+ "002D % hyphen
+ \fi\fi\fi}
+
+\unexpanded\def\textplus
+ {\char"002B } % plus
+
+% \def\registerviewerlayer#1#2% global !
+% {\setxvalue{(vl:#1)}{\global\dosetattribute{viewerlayer}{\ctxlua{tex.print(viewerlayers.register('#2'))}}}}
+
+% \setevalue{(vl:)}{\global\doresetattribute{viewerlayer}}
+
+\let\\=\crlf % till we fixed all styles
+
+% \def\pagedir{\expandafter\gobblethreearguments}
+% \def\bodydir{\expandafter\gobblethreearguments}
+
% we have to make an mkii/mkiv core-not
+\ifx\definestructurecounter\undefined
+
\def\dochecknote % only to be called locally, some bools will become class-ones
{% for the moment no mixed text/endnotes modes, so we use
% \footnoteparameter and not \noteparameter (**)
@@ -79,22 +103,24 @@
\skip \currentnoteins\zeropoint
\fi}
-%
-
-\def\writestatus#1#2{\ctxlua{ctx.writestatus(\!!bs#1\!!es,\!!bs#2\!!es)}}
+\fi
\ifx\clearmarks\undefined
\def\clearmarks {\begingroup\afterassignment\doclearmarks\scratchcounter}
\def\doclearmarks{\normalmarks\scratchcounter{}\endgroup}
\fi
-\def\resetmark#1% we cannot use \normalmarks#1{}
- {\global\@EA\chardef\csname\@@mrk\string#1\endcsname\zerocount
- \@EA\clearmarks\csname\@@prk\string#1\endcsname
- \global\@EA\let\csname\@@trk\string#1\endcsname\empty
- \global\@EA\let\csname\@@frk\string#1\endcsname\empty
- \global\@EA\let\csname\@@brk\string#1\endcsname\empty
- \global\@EA\let\csname\@@crk\string#1\endcsname\empty}
+\ifx\@@trk\undefined \else
+
+ \def\resetmark#1% we cannot use \normalmarks#1{}
+ {\global\@EA\chardef\csname\@@mrk\string#1\endcsname\zerocount
+ \@EA\clearmarks\csname\@@prk\string#1\endcsname
+ \global\@EA\let\csname\@@trk\string#1\endcsname\empty
+ \global\@EA\let\csname\@@frk\string#1\endcsname\empty
+ \global\@EA\let\csname\@@brk\string#1\endcsname\empty
+ \global\@EA\let\csname\@@crk\string#1\endcsname\empty}
+
+\fi
%D Since this can be a showstopper, we report the path at the beginning
%D as well as at the end of a run.
@@ -102,15 +128,26 @@
% \writestatus\m!lua{used config path - \ctxlua{tex.print(caches.configpath())}}
% \writestatus\m!lua{used cache path - \ctxlua{tex.print(caches.path)}}
+\startluacode
+ statistics.register("result saved in file", function()
+ return string.format( "%s.%s", "\outputfilename", (tex.pdfoutput>0 and "pdf") or "dvi")
+ end)
+\stopluacode
+
%D For the moment we report some statistics. Later this will become an option,
%D but for now we need this information.
-\def\nomkivstatistics{\ctxlua{function ctx.show_statistics() end}} % for taco
+\def\nomkivstatistics{\ctxlua{statistics.enable = false}} % for taco
\def\resettimer {\ctxlua{environment.starttime = os.clock()}}
\def\elapsedtime {\ctxlua{tex.sprint(os.clock()-environment.starttime)}}
\let\elapsedseconds \elapsedtime
+% we will have a bunch of extra tracers (--dumphash --dumpdelta)
+
+\def\tracersdumphash {\ctxlua{tracers.register_dump_hash(false)}}
+\def\tracersdumpdelta{\ctxlua{tracers.register_dump_hash(true)}}
+
\resettimer
%D For me.
@@ -145,44 +182,33 @@
% texio.write_nl("CREATING "..pth)
% os.execute("mkdir " .. pth)
% end
-% input.output_files = { }
+% resolvers.output_files = { }
% callback.register('find_write_file', function(id,name)
-% input.output_files[name] = file.join(".","tmp","\jobname",name)
-% texio.write_nl("REDIRECTING OUTPUT "..name.. " TO " .. input.output_files[name])
-% return input.output_files[name]
+% resolvers.output_files[name] = file.join(".","tmp","\jobname",name)
+% texio.write_nl("REDIRECTING OUTPUT "..name.. " TO " .. resolvers.output_files[name])
+% return resolvers.output_files[name]
% end)
% callback.register('find_read_file', function(id,name)
% local sname = string.gsub(name,"^\letterpercent./","")
-% if input.output_files[sname] then
-% return input.output_files[name]
+% if resolvers.output_files[sname] then
+% return resolvers.output_files[name]
% elseif string.find(sname,"^\jobname[\letterpercent.\letterpercent-]") then
% local n = file.join(".","tmp","\jobname",sname)
% local f = io.open(n)
% if f then
-% input.output_files[name] = n
+% resolvers.output_files[name] = n
% texio.write_nl("REDIRECTING INPUT "..sname.. " TO " .. n)
% f:close()
% return n
% else
-% return input.findtexfile(name)
+% return resolvers.findtexfile(name)
% end
% else
-% return input.findtexfile(name)
+% return resolvers.findtexfile(name)
% end
% end)
% }
-% The following commands need to be taken care of, e.g. because there is not yet
-% a mkiv module for them. (Currently they're overloaded so we need to redefine them.)
-
-\def\WORD {\groupedcommand{\setcharactercasing[\plusone ]}{}}
-\def\word {\groupedcommand{\setcharactercasing[\plustwo ]}{}}
-\def\Word {\groupedcommand{\setcharactercasing[\plusthree]}{}}
-\def\Words{\groupedcommand{\setcharactercasing[\plusfour]}{}}
-
-\let\WORDS\WORD
-\let\words\word
-
\definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]
\protect \endinput
diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex
index ee047599b..b8e2a6f95 100644
--- a/tex/context/base/cont-new.tex
+++ b/tex/context/base/cont-new.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\newcontextversion{2008.10.31 13:58}
+\newcontextversion{2009.05.28 11:23}
%D This file is loaded at runtime, thereby providing an
%D excellent place for hacks, patches, extensions and new
@@ -21,7 +21,7 @@
% it's about time to clean up this file ...
-\writestatus{\m!systems}{beware: some patches loaded from cont-new.tex}
+\writestatus\m!systems{beware: some patches loaded from cont-new.tex}
% \ifx\pdfmapfile \undefined \else \pdfmapfile{ } \fi
@@ -31,13 +31,16 @@
\let\then\relax % \ifnum1>2\then -)
-\def\TransparencyHack % png: /CS /DeviceRGB /I true
- {\appendtoks
- \doPDFpageattribute{/Group << /S /Transparency /I true /K true>>}%
- \to \everyPDFxform
- \appendtoks
- \doPDFpageattribute{/Group << /S /Transparency /I true /K true>>}%
- \to \everyshipout}
+\def\fastscale#1%
+ {\begingroup
+ \ifnum#1=1000\relax
+ \setfalse\scaleboxdone
+ \else
+ \settrue\scaleboxdone
+ \edef\finalscaleboxxscale{\withoutpt\the\dimexpr#1pt/1000\relax}%
+ \let\finalscaleboxyscale\finalscaleboxxscale
+ \fi
+ \dowithnextbox{\doscaleboxindeed\flushnextbox\endgroup}\hbox}
% \setupcaption [figure] [align=flushleft]
% \setupcaption [figure-1] [align=flushleft,leftmargin=10mm]
@@ -96,9 +99,9 @@
% normally one does not want this to happen nested, maybe there
% is more; non public vars btw, will become conditionals
-\appendtoks \writetoregisterfalse \to \everybeforeutilityread
-\appendtoks \writetolistfalse \to \everybeforeutilityread
-\appendtoks \notesenabledfalse \to \everybeforeutilityread
+\ifx\writetoregisterfalse\undefined \else \appendtoks \writetoregisterfalse \to \everybeforeutilityread \fi
+\ifx\writetolistfalse \undefined \else \appendtoks \writetolistfalse \to \everybeforeutilityread \fi
+\ifx\notesenabledfalse \undefined \else \appendtoks \notesenabledfalse \to \everybeforeutilityread \fi
% \setuplabeltext[\s!itemcount1={{I(},{)}}]
% \def\labeledcountervalue#1{\labeltexts{#1}{\countervalue{#1}}}
@@ -515,69 +518,6 @@
\egroup
-% todo : test low level translation (nl->en) and optimize script
-
-% \definestylecollection[mine]
-
-% \definestyleinstance[mine][default][sorry]
-% \definestyleinstance[mine][tt][bs][ttbs:\rm\sl]
-% \definestyleinstance[mine][tt][bf][ttbf:\rm\sl]
-% \definestyleinstance[mine][bf][\sl]
-% \definestyleinstance[mine][sl][\tt]
-
-% {\bf test \mine test \sl test \mine test \bs oeps \mine oeps {\tt test \mine \bf test}}
-
-\definesystemvariable{sx}
-
-\def\definestylecollection
- {\dosingleargument\dodefinestylecollection}
-
-\def\dodefinestylecollection[#1]%
- {\iffirstargument
- \unexpanded\setvalue{#1}{\styleinstance[#1]}%
- \def\docommand##1%
- {\def\dodocommand####1{\letbeundefined{\??sx##1:####1:\commalistelement}}%
- \processcommacommand[\alternativelist,\s!default]\dodocommand}%
- \processcommacommand[\stylelist,\s!default]\docommand
- \fi}
-
-\def\definestyleinstance
- {\doquadrupleargument\dodefinestyleinstance}
-
-\def\dodefinestyleinstance[#1][#2][#3][#4]% [name] [rm|ss|tt|..] [sl|bf|...] [whatever]
- {\iffirstargument
- \doifundefined{#1}{\definestylecollection[#1]}%
- \fi
- \iffourthargument
- \setvalue{\??sx#1:#2:#3}{#4}%
- \else\ifthirdargument
- \setvalue{\??sx#1::#2}{#3}%
- \else\ifsecondargument
- \letvalue{\??sx#1::#2}\empty
- \fi\fi\fi}
-
-\unexpanded\def\styleinstance[#1]% will be faster
- {%\begingroup\expanded{\infofont[#1:\fontstyle:\fontalternative]}\endgroup
- \executeifdefined{\??sx#1:\fontstyle:\fontalternative}%
- {\executeifdefined{\??sx#1:\fontstyle:\s!default}%
- {\executeifdefined{\??sx#1::\fontalternative}
- {\getvalue {\??sx#1::\s!default}}}}}
-
-% \unexpanded\def\styleinstance[#1]%
-% {\csname\??sx#1%
-% \ifcsname:\fontstyle:\fontalternative\endcsname
-% :\fontstyle:\fontalternative
-% \else\ifcsname:\fontstyle:\s!default\endcsname
-% :\fontstyle:\s!default
-% \else\ifcsname::\fontalternative\endcsname
-% ::\fontalternative
-% \else\ifcsname::\s!default\endcsname
-% ::\s!default
-% \else
-% % nothing, \relax
-% \fi\fi\fi\fi
-% \endcsname}
-
% no, wrong! never!
%
% \def\tightlayer[#1]%
@@ -849,16 +789,6 @@
% externfiguur -> grid =ja|hoogte|diepte|halveregel|passend -> helemaal in details
% stelplaatsblokin -> zijuitlijnen=hoogte|diepte|regel|halveregel|grid -> halveregel in 'details'
-% TODO: TEST FIRST, NO CORRECTION NEEDED IN GRID MODE, EVT OPTION
-
-\def\OTRONEsomeherefloat[#1]% spacing between two successive must be better
- {\baselinecorrection % not really needed in grid mode:
- %\ifgridsnapping \else \baselinecorrection \fi % ! ! ! test test test ! ! ! !
- \doplacefloatbox
- \doinsertfloatinfo
- \dochecknextindentation\??bk
- \dorechecknextindentation}
-
% todo: switch koppelen aan par scheelt pos
% to be documented: \startspread .. \stopspread
diff --git a/tex/context/base/cont-nl.tex b/tex/context/base/cont-nl.tex
index 4635d750d..32b82b01a 100644
--- a/tex/context/base/cont-nl.tex
+++ b/tex/context/base/cont-nl.tex
@@ -29,6 +29,14 @@
\installlanguage [\s!nl] [\c!state=\v!start]
\installlanguage [\s!it] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-old.tex b/tex/context/base/cont-old.tex
index f8b4b6062..360b5f2e6 100644
--- a/tex/context/base/cont-old.tex
+++ b/tex/context/base/cont-old.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Old Macros}
+\writestatus{loading}{ConTeXt Old Macros}
\unprotect
diff --git a/tex/context/base/cont-pe.tex b/tex/context/base/cont-pe.tex
index ab2b30bcd..fdf47d680 100644
--- a/tex/context/base/cont-pe.tex
+++ b/tex/context/base/cont-pe.tex
@@ -32,6 +32,14 @@
\installlanguage [\s!nl] [\c!state=\v!start]
\installlanguage [\s!pe] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-ro.tex b/tex/context/base/cont-ro.tex
index e6b2eadf3..9be9b1162 100644
--- a/tex/context/base/cont-ro.tex
+++ b/tex/context/base/cont-ro.tex
@@ -25,6 +25,14 @@
\installlanguage [\s!de] [\c!state=\v!start]
\installlanguage [\s!ro] [\c!state=\v!start]
-\setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\ifnum\texengine=\luatexengine
+ % will be runtime option: typeface
+ \appendtoks
+ \usetypescript[modern]
+ \setuptypeface[modern]
+ \to \everyjob
+\else
+ \setupencoding[default=ec] \usetypescript[fallback][\defaultencoding] \setupbodyfont[rm,12pt]
+\fi
\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/cont-sys.ori b/tex/context/base/cont-sys.ori
index 335a7d984..11c0141e7 100644
--- a/tex/context/base/cont-sys.ori
+++ b/tex/context/base/cont-sys.ori
@@ -14,8 +14,8 @@
\unprotect
% Speed up typescript loading, but at the cost of much memory:
-%
-% \preloadtypescripts
+
+\preloadtypescripts
% If you want another default font:
%
@@ -121,7 +121,6 @@
% When you have your own fonts installed, you may want to predefine:
%
% \usetypescriptfile[type-buy]
-% \usetypescriptfile [type-gyr]
% Some styles default to Lucida Bright. You can overload
% Lucida by Times cum suis. Watch out, the pos collection
@@ -158,8 +157,8 @@
% Enabling run time \METAPOST\ (also enable \write18 in
% texmf.cnf):
-% \runMPgraphicstrue
-% \runMPTEXgraphicstrue
+\runMPgraphicstrue
+\runMPTEXgraphicstrue
% This saves some runtime, but needs a format, which you can
% make with 'texexec --make --alone metafun'. Make sure that
diff --git a/tex/context/base/cont-usr.ori b/tex/context/base/cont-usr.ori
index dab420e3e..5a3070362 100644
--- a/tex/context/base/cont-usr.ori
+++ b/tex/context/base/cont-usr.ori
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{User Settings}
+\writestatus{loading}{ConTeXt User Settings}
\unprotect
diff --git a/tex/context/base/context-base.lmx b/tex/context/base/context-base.lmx
new file mode 100644
index 000000000..5c96b4979
--- /dev/null
+++ b/tex/context/base/context-base.lmx
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tex/context/base/context.css b/tex/context/base/context.css
index ef4a44cea..f332ae242 100644
--- a/tex/context/base/context.css
+++ b/tex/context/base/context.css
@@ -12,6 +12,12 @@ a.dir-view:link, a.dir-view:active, a.dir-view:visited {
color: #FFFFFF ;
text-decoration: underline ;
}
+.valid {
+ color: #00FF00 ;
+}
+.invalid {
+ color: #FF0000 ;
+}
h1, .title {
font-style: normal ;
font-weight: normal ;
@@ -31,6 +37,15 @@ table {
font-size: 12px ;
margin: 0 ;
}
+th {
+ font-weight: bold ;
+ text-align: left ;
+ padding-bottom: 6px ;
+}
+.tc {
+ font-weight: bold ;
+ text-align: left ;
+}
p, li {
max-width: 60em ;
}
diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii
index d58ba7ad7..1a2fa4abb 100644
--- a/tex/context/base/context.mkii
+++ b/tex/context/base/context.mkii
@@ -15,37 +15,46 @@
%D manipulation macros. The first one loads \PLAIN\ \TEX, as
%D minimal as possible.
+\loadcorefile{syst-ini.tex}
+\loadcorefile{norm-tex.tex}
+\loadcorefile{norm-etx.tex}
+\loadcorefile{norm-ptx.tex}
+\loadcorefile{norm-xtx.tex}
+\loadcorefile{norm-ctx.tex}
\loadcorefile{syst-pln.tex}
-\loadcorefile{syst-prm.tex}
-\loadcorefile{syst-cat.tex}
-
-\loadcorefile{syst-etx.tex}
-\loadcorefile{syst-pdt.tex}
-\loadcorefile{syst-omg.tex}
-\loadcorefile{syst-xtx.tex}
-\loadcorefile{syst-mtx.tex}
+\loadmarkfile{catc-ini}
+\loadcorefile{catc-act.tex}
+\loadcorefile{catc-def.tex}
+\loadcorefile{catc-ctx.tex}
+\loadcorefile{catc-sym.tex}
\loadcorefile{syst-gen.tex}
\loadcorefile{syst-ext.tex}
-\loadcorefile{syst-chr.tex}
-\loadcorefile{syst-fnt.tex}
\loadcorefile{syst-new.tex}
-\loadcorefile{syst-con.tex}
-\loadcorefile{syst-var.tex}
-\loadcorefile{syst-str.tex}
-\loadcorefile{syst-rtp.tex}
+\loadmarkfile{syst-con}
+\loadcorefile{thrd-trg.tex} % based on: David Carlisle
+
+\loadmarkfile{syst-fnt}
+\loadmarkfile{syst-str}
+\loadmarkfile{syst-rtp}
+
+\ifnum\texengine=\xetexengine
+ \loadcorefile{xetx-ini.tex}
+ \loadcorefile{xetx-utf.tex}
+ \loadcorefile{xetx-chr.tex}
+ \loadcorefile{xetx-cls.tex}
+\fi
%D To enable selective loading, we say:
-\CONTEXTtrue
+\newif\ifCONTEXT \CONTEXTtrue % will disappear
%D In order to conveniently load files, we need a few
%D support modules.
-\loadcorefile{supp-ini.tex}
-\loadcorefile{supp-fil.tex}
-\loadcorefile{supp-dir.tex}
+\loadmarkfile{supp-fil}
+\loadmarkfile{supp-dir}
%D After this we're ready for the multi||lingual interface
%D modules.
@@ -54,17 +63,13 @@
\loadcorefile{mult-fst.tex}
\loadcorefile{mult-sys.tex}
\loadcorefile{mult-def.tex}
-
-%D We also use some third party macros. These are loaded by
-%D saying:
-
-\loadcorefile{thrd-ran.tex} % based on: Donald Arseneau
-\loadcorefile{thrd-trg.tex} % based on: David Carlisle
+\loadmarkfile{mult-chk}
%D Now we're ready for some general support modules. These
%D modules implement some basic typesetting functionality.
\loadcorefile{core-var.tex}
+\loadmarkfile{core-env}
\loadcorefile{supp-box.tex}
\loadcorefile{supp-mrk.tex}
@@ -72,7 +77,7 @@
\loadcorefile{supp-fun.tex}
%loadcorefile{supp-eps.tex}
\loadcorefile{supp-spe.tex}
-\loadcorefile{supp-ran.tex}
+\loadmarkfile{supp-ran}
%loadcorefile{supp-mps.tex}
\loadmkiifile{supp-mps.tex}
\loadmkiifile{supp-tpi.tex}
@@ -101,7 +106,7 @@
\loadcorefile{core-ins.tex}
\loadcorefile{core-fil.tex}
-\loadcorefile{core-con.tex}
+\loadmarkfile{core-con}
%D We already need some synonyms (patterns). At runtime this
%D file will be reloaded.
@@ -122,43 +127,40 @@
%D The next few modules do what their names state. They
%D load additional definition modules when needed.
-\loadcorefile{regi-ini.tex}
-\loadcorefile{enco-ini.tex}
-\loadcorefile{filt-ini.tex}
-\loadcorefile{hand-ini.tex}
+\loadmarkfile{regi-ini}
\loadcorefile{regi-syn.tex}
-\loadcorefile{lang-ini.tex}
-\loadcorefile{lang-ctx.tex}
-\loadcorefile{lang-dis.tex}
+\loadmarkfile{enco-ini}
+%loadcorefile{filt-ini.tex}
+\loadmarkfile{hand-ini}
+
+\loadmarkfile{lang-ini}
+\loadmarkfile{lang-spe}
+\loadmarkfile{lang-lab}
\loadmarkfile{unic-ini}
\loadcorefile{core-gen.tex}
-\loadcorefile{core-new.tex}
-\loadcorefile{core-uti.tex}
-\loadcorefile{core-two.tex}
+\loadmarkfile{core-uti}
+\loadmarkfile{core-two}
\loadcorefile{core-stg.tex}
-\loadcorefile{spec-mis.tex}
\loadcorefile{spec-ini.tex}
+\loadcorefile{spec-mis.tex}
\loadcorefile{spec-def.tex}
\loadcorefile{spec-var.tex}
-\loadcorefile{colo-ini.tex}
-\loadcorefile{colo-ext.tex}
+\loadmarkfile{colo-ini}
+\loadmarkfile{colo-ext}
%D For the moment we load a lot of languages. In the future
%D we'll have to be more space conservative.
\loadcorefile{lang-mis.tex}
-\loadcorefile{lang-url.tex}
-\loadcorefile{lang-spe.tex}
-\loadcorefile{lang-lab.tex}
+\loadmarkfile{lang-url}
\loadcorefile{lang-ger.tex}
\loadcorefile{lang-ita.tex}
\loadcorefile{lang-sla.tex}
-
\loadcorefile{lang-alt.tex}
\loadcorefile{lang-ana.tex}
\loadcorefile{lang-art.tex}
@@ -167,10 +169,9 @@
\loadcorefile{lang-grk.tex}
\loadcorefile{lang-ind.tex}
\loadcorefile{lang-ura.tex}
-
\loadcorefile{lang-vn.tex}
-
\loadcorefile{lang-ara.tex}
+\loadcorefile{lang-cyr.tex}
%D All kind of symbols are handled in:
@@ -178,43 +179,45 @@
%D Sorting:
-\loadcorefile{sort-ini.tex}
+\loadmarkfile{sort-ini}
%D Next we load some core macro's. These implement the
%D macros' that are seen by the users. The order of loading
%D is important, due to dependancies.
-\loadcorefile{core-spa.tex}
+\loadmarkfile{core-spa}
\loadcorefile{core-grd.tex}
\loadcorefile{core-mar.tex}
-\loadcorefile{core-pos.tex}
+\loadmarkfile{core-pos}
\loadcorefile{core-mak.tex}
\loadcorefile{core-dat.tex}
-\loadcorefile{core-ver.tex}
-\loadcorefile{core-rul.tex}
+\loadmarkfile{core-ver}
+\loadmarkfile{core-rul}
\loadcorefile{core-vis.tex}
\loadcorefile{core-num.tex}
-\loadcorefile{core-tsp.tex}
-\loadcorefile{core-tab.tex}
-\loadcorefile{core-nav.tex}
+\loadcorefile{tabl-pln.tex}
+\loadcorefile{tabl-tab.tex}
+\loadcorefile{tabl-tsp.tex}
+\loadmarkfile{core-nav}
\loadcorefile{core-ref.tex}
-\loadcorefile{core-obj.tex}
+\loadmarkfile{core-obj}
\loadcorefile{core-lst.tex}
\loadcorefile{core-itm.tex}
\loadcorefile{core-des.tex}
-\loadcorefile{core-mat.tex}
+\loadcorefile{core-mat.tex} % should come after math-pln etc
\loadcorefile{core-syn.tex}
-\loadcorefile{core-sys.tex}
+\loadmarkfile{core-sys}
-\loadcorefile{page-ini.tex}
-\loadcorefile{page-bck.tex}
+\loadmarkfile{page-ini}
+\loadmarkfile{page-bck}
\loadcorefile{page-not.tex}
-\loadcorefile{page-one.tex}
+\loadmarkfile{page-one}
\loadcorefile{page-lay.tex}
\loadmkiifile{page-log.tex}
-\loadcorefile{page-txt.tex}
+\loadmarkfile{page-txt}
\loadcorefile{page-sid.tex}
\loadcorefile{page-flt.tex}
+\loadcorefile{page-mis.tex}
\loadcorefile{page-mul.tex}
\loadcorefile{page-set.tex}
\loadcorefile{page-lyr.tex}
@@ -224,19 +227,20 @@
\loadcorefile{page-par.tex}
\loadcorefile{page-mar.tex}
-\loadcorefile{core-job.tex} % why so late?
+\loadmarkfile{core-job} % why so late?
% so far
-\loadmarkfile{core-sec}
+\loadcorefile{core-sec.tex}
\loadcorefile{core-swd.tex}
-\loadcorefile{core-buf.tex}
+\loadmarkfile{core-buf}
\loadcorefile{core-blk.tex}
\loadcorefile{page-imp.tex}
-\loadcorefile{core-tbl.tex}
-\loadcorefile{core-int.tex}
-\loadcorefile{core-ntb.tex}
-\loadcorefile{core-ltb.tex}
+\loadcorefile{tabl-tbl.tex}
+\loadmarkfile{core-int}
+\loadmarkfile{tabl-ntb}
+\loadcorefile{tabl-nte.tex}
+\loadcorefile{tabl-ltb.tex}
%D A few more languages, that have specifics using core
%D functionality:
@@ -246,8 +250,8 @@
%D How about fill||in fields and related stuff?
-\loadcorefile{java-ini.tex}
-\loadcorefile{core-fld.tex}
+\loadmarkfile{java-ini}
+\loadmarkfile{core-fld}
\loadcorefile{core-hlp.tex}
%D Registers can depend on fields, so we load that now.
@@ -260,27 +264,33 @@
%D instead of italian.
\loadmarkfile{font-ini}
-\loadcorefile{font-uni.tex}
+
+\ifnum\texengine=\xetexengine
+ \loadcorefile{font-xtx.tex}
+\fi
+
+\loadmarkfile{font-unk}
+\loadmarkfile{font-uni}
\loadcorefile{font-bfm.tex}
\loadcorefile{enco-pfr.tex}
-\loadcorefile{type-ini.tex}
+\loadmarkfile{type-ini}
\loadcorefile{type-def.tex}
%D Properties. Don't ask.
-\loadcorefile{prop-ini.tex}
-\loadcorefile{prop-lay.tex}
-\loadcorefile{prop-mis.tex}
+\loadmarkfile{prop-ini}
+\loadmarkfile{prop-lay}
+\loadmarkfile{prop-mis}
%D Like languages, fonts, encodings and symbols, \METAPOST\
%D support is also organized in its own class of modules.
\loadmarkfile{meta-ini}
\loadmarkfile{meta-tex}
+\loadmarkfile{meta-pdf}
-\loadcorefile{meta-pdf.tex}
\loadcorefile{meta-pag.tex}
%D Special page handling (maybe even later)
@@ -299,20 +309,21 @@
%D Math.
-\loadcorefile{math-pln.tex}
-\loadcorefile{math-ini.tex}
-\loadcorefile{math-ext.tex}
+\loadmarkfile{math-pln}
+\loadmarkfile{math-ini}
+\loadmarkfile{math-arr}
+\loadmarkfile{math-frc}
%D Now we're ready for more core modules.
-\loadcorefile{core-fnt.tex}
+\loadmarkfile{core-fnt}
\loadcorefile{core-not.tex}
\loadcorefile{core-lnt.tex}
-\loadcorefile{core-mis.tex}
+\loadmarkfile{core-mis}
\loadcorefile{core-trf.tex}
-\loadcorefile{core-inc.tex}
+\loadmarkfile{core-inc}
\loadcorefile{core-fig.tex}
\loadcorefile{core-par.tex}
@@ -330,14 +341,10 @@
\loadcorefile{xtag-ini.tex}
\loadcorefile{xtag-ext.tex}
-\loadcorefile{xtag-prs.tex}
-\loadcorefile{xtag-map.tex}
-\loadcorefile{xtag-stk.tex}
\loadcorefile{xtag-exp.tex}
\loadcorefile{xtag-pre.tex}
\loadcorefile{xtag-xsd.tex}
\loadcorefile{xtag-rng.tex}
-%loadcorefile{xtag-ent.tex}
%D How about this:
@@ -350,14 +357,14 @@
%D This one overloads af few things:
-\loadcorefile{core-ctx.tex}
+\loadmarkfile{core-ctx}
%D Defaults go here (more will be moved to this module
%D later):
\loadcorefile{core-lme.tex}
\loadcorefile{core-ini.tex}
-\loadcorefile{core-def.tex}
+\loadmarkfile{core-def}
%D Preloaded modules (some need xml support):
@@ -374,23 +381,6 @@
%D \item \type{cont-fil}: filename and module synonyms
%D \stopitemize
-\unprotect
-
-\beginLUATEX
- \prependtoks
- \ctxlua{input.starttiming(ctx)}%
- \to \everyjob
- \appendtoks
- \ctxlua{input.stoptiming(ctx)}%
- \to \everyjob
- \appendtoks
- \writestatus\m!lua{used config path - \ctxlua{tex.print(caches.configpath())}}%
- \writestatus\m!lua{used cache path - \ctxlua{tex.print(caches.path)}}%
- \to \everydump
-\endLUATEX
-
-\protect
-
% %D Except from english, no hyphenation patterns are loaded
% %D yet. Users can specify their needs in the next module:
%
diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv
index fb130e5ea..b3542fb21 100644
--- a/tex/context/base/context.mkiv
+++ b/tex/context/base/context.mkiv
@@ -11,171 +11,119 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+% syst-cat -> catc-ini + vectors
+% spec-* -> special backends for luatex
+
%D First we load the system modules. These implement a lot of
%D manipulation macros. The first one loads \PLAIN\ \TEX, as
%D minimal as possible.
+\loadcorefile{syst-ini.tex}
+\loadcorefile{norm-ctx.tex}
\loadcorefile{syst-pln.tex}
-\loadcorefile{syst-prm.tex}
-\loadmkivfile{luat-env.tex}
+\loadmkivfile{luat-cod.tex}
+\loadmkivfile{luat-bas.tex}
\loadmkivfile{luat-lib.tex}
-\loadcorefile{syst-cat.tex}
-
-\loadcorefile{syst-etx.tex}
-\loadcorefile{syst-pdt.tex}
-\loadcorefile{syst-omg.tex}
-\loadcorefile{syst-xtx.tex}
-\loadcorefile{syst-mtx.tex}
-\loadcorefile{syst-gen.tex}
-\loadcorefile{syst-ext.tex}
-\loadcorefile{syst-chr.tex}
-\loadcorefile{syst-fnt.tex}
-\loadcorefile{syst-new.tex}
-\loadcorefile{syst-con.tex}
-\loadcorefile{syst-var.tex}
-\loadcorefile{syst-str.tex}
-\loadcorefile{syst-rtp.tex}
+\loadmarkfile{catc-ini}
+\loadcorefile{catc-act.tex}
+\loadcorefile{catc-def.tex}
+\loadcorefile{catc-ctx.tex}
+\loadcorefile{catc-sym.tex}
-%D To enable selective loading, we say:
+\newif\ifCONTEXT \CONTEXTtrue % will disappear
-\CONTEXTtrue
+\loadcorefile{syst-aux.tex}
+\loadcorefile{syst-lua.tex}
+\loadmarkfile{syst-con}
-%D In order to conveniently load files, we need a few
-%D support modules.
+\loadmarkfile{syst-fnt}
+\loadmarkfile{syst-str}
+\loadmarkfile{syst-rtp}
-\loadcorefile{supp-ini.tex}
-\loadcorefile{supp-fil.tex}
-\loadcorefile{supp-dir.tex}
-
-%D We need to initialize characters.
+\loadmarkfile{supp-fil}
+\loadmarkfile{supp-dir}
\loadmkivfile{char-ini.tex}
\loadmkivfile{char-utf.tex}
-%D After this we're ready for the multi||lingual interface
-%D modules.
-
\loadmarkfile{mult-ini}
\loadcorefile{mult-fst.tex}
\loadcorefile{mult-sys.tex}
\loadcorefile{mult-def.tex}
+\loadmarkfile{mult-chk}
\loadmkivfile{luat-ini.tex}
-\loadmkivfile{luat-lmx.tex}
-
-\loadmkivfile{luat-uni.tex}
\loadmkivfile{toks-ini.tex}
-\loadmkivfile{attr-ini.tex}
\loadmkivfile{node-ini.tex}
+\loadmkivfile{node-fin.tex}
\loadmkivfile{node-par.tex}
-%D We also use some third party macros. These are loaded by
-%D saying:
+\loadcorefile{core-var.tex}
-\loadcorefile{thrd-ran.tex} % based on: Donald Arseneau
-\loadcorefile{thrd-trg.tex} % based on: David Carlisle
+\loadcorefile{back-ini.tex}
+\loadcorefile{back-pdf.tex}
-%D Now we're ready for some general support modules. These
-%D modules implement some basic typesetting functionality.
+\loadmkivfile{attr-ini.tex}
-\loadcorefile{core-var.tex}
-\loadmkivfile{luat-deb.tex}
+\loadmarkfile{core-env}
+
+\loadmkivfile{trac-lmx.tex}
+\loadmkivfile{trac-deb.tex}
\loadcorefile{supp-box.tex}
-\loadcorefile{supp-mrk.tex}
+
\loadcorefile{supp-vis.tex}
\loadcorefile{supp-fun.tex}
-\loadcorefile{supp-spe.tex}
-\loadcorefile{supp-ran.tex}
+
+\loadmarkfile{supp-ran}
\loadcorefile{supp-mat.tex}
\loadcorefile{supp-ali.tex}
\loadcorefile{supp-num.tex}
-%D The next module deals with language specific typographic
-%D extensions.
-
\loadcorefile{typo-ini.tex}
-%D Verbatim typesetting is implemented in a separate class of
-%D modules. The pretty typesetting modules are loaded at run
-%D time.
-
\loadcorefile{verb-ini.tex}
-%D The following modules are not sequentially dependent,
-%D i.e. they have ugly dependencies, which will be cleaned
-%D up by adding more overloading.
-
-%D When loading the font, color and special modules, we need a
-%D bit more advanced file handling as well as some general
-%D variables, and features, so next we load:
-
\loadcorefile{core-ins.tex}
\loadcorefile{core-fil.tex}
-\loadcorefile{core-con.tex}
-
-%D We already need some synonyms (patterns). At runtime this
-%D file will be reloaded.
+\loadmarkfile{core-con}
\loadcorefile{cont-fil.tex}
-%D \CONTEXT\ does not implement its own table handling. We
-%D just go for the best there is and load \TABLE. Just to be
-%D sure we do it here, before we redefine \type{|}.
-
-\loadcorefile{thrd-tab.tex} % based on: Michael Wichura / will be reimplemented
-
-%D Here comes the last support modules. They take care of
-%D some language specific things.
-
-\loadcorefile{supp-pat.tex}
-
-%D The next few modules do what their names state. They
-%D load additional definition modules when needed.
-
-\loadcorefile{regi-ini.tex}
-\loadcorefile{enco-ini.tex}
-\loadcorefile{filt-ini.tex}
-\loadcorefile{hand-ini.tex}
+\loadmarkfile{regi-ini}
\loadcorefile{regi-syn.tex}
-\loadcorefile{lang-ini.tex}
-\loadcorefile{lang-ctx.tex}
-\loadcorefile{lang-dis.tex}
+\loadmarkfile{enco-ini}
+\loadmarkfile{hand-ini}
-\loadmarkfile{unic-ini}
+\loadmarkfile{lang-ini}
+\loadmarkfile{lang-spe}
+\loadmarkfile{lang-lab}
-% \readfile{lang-url.pat}{}{} % test
+\loadmarkfile{unic-ini}
\loadcorefile{core-gen.tex}
-\loadcorefile{core-new.tex}
-\loadcorefile{core-uti.tex}
-\loadcorefile{core-two.tex}
+\loadmarkfile{core-uti}
+\loadmarkfile{core-two}
\loadcorefile{core-stg.tex}
-\loadcorefile{spec-mis.tex}
-\loadcorefile{spec-ini.tex}
-\loadcorefile{spec-def.tex}
-\loadcorefile{spec-var.tex}
+% \loadcorefile{spec-ini.tex}
+% \loadcorefile{spec-mis.tex}
+% \loadcorefile{spec-def.tex}
+% \loadcorefile{spec-var.tex}
-\loadcorefile{colo-ini.tex}
-\loadcorefile{colo-ext.tex}
-
-%D For the moment we load a lot of languages. In the future
-%D we'll have to be more space conservative.
+\loadmarkfile{colo-ini}
+\loadmarkfile{colo-ext}
\loadcorefile{lang-mis.tex}
-\loadcorefile{lang-url.tex}
-\loadcorefile{lang-spe.tex}
-\loadcorefile{lang-lab.tex}
+\loadmarkfile{lang-url}
\loadcorefile{lang-ger.tex}
\loadcorefile{lang-ita.tex}
\loadcorefile{lang-sla.tex}
-
\loadcorefile{lang-alt.tex}
\loadcorefile{lang-ana.tex}
\loadcorefile{lang-art.tex}
@@ -184,113 +132,118 @@
\loadcorefile{lang-grk.tex}
\loadcorefile{lang-ind.tex}
\loadcorefile{lang-ura.tex}
-
+\loadcorefile{lang-cjk.tex}
\loadcorefile{lang-vn.tex}
-
\loadcorefile{lang-ara.tex}
-
-%D All kind of symbols are handled in:
+\loadcorefile{lang-cyr.tex}
\loadcorefile{symb-ini.tex}
-%D Sorting:
+\loadmarkfile{sort-ini}
-\loadcorefile{sort-ini.tex}
+\loadmarkfile{core-rul}
-%D Next we load some core macro's. These implement the
-%D macros' that are seen by the users. The order of loading
-%D is important, due to dependancies.
+\loadcorefile{lxml-ini}
-\loadcorefile{core-spa.tex}
+\loadcorefile{strc-ini}
+\loadcorefile{strc-doc}
+\loadcorefile{strc-mar}
+\loadcorefile{strc-prc}
+\loadcorefile{strc-sbe}
+\loadcorefile{strc-lst}
+\loadcorefile{strc-sec}
+\loadcorefile{strc-num}
+\loadcorefile{strc-ren}
+\loadcorefile{strc-xml}
+\loadcorefile{strc-pag} % hm, depends on core-num
+\loadcorefile{strc-def} % might happen later
+\loadcorefile{strc-ref}
+\loadcorefile{strc-reg}
+
+\loadcorefile{bibl-bib}
+
+\loadmarkfile{core-spa}
\loadcorefile{core-grd.tex}
-\loadcorefile{core-mar.tex}
-\loadcorefile{core-pos.tex}
+
+\loadmarkfile{core-pos}
\loadcorefile{core-mak.tex}
-\loadcorefile{core-dat.tex}
-\loadcorefile{core-ver.tex}
-\loadcorefile{core-rul.tex}
+\loadmarkfile{core-ver}
+
\loadcorefile{core-vis.tex}
-\loadcorefile{core-num.tex}
-\loadcorefile{core-tsp.tex}
-\loadcorefile{core-tab.tex}
-\loadcorefile{core-nav.tex}
-\loadcorefile{core-ref.tex}
-\loadcorefile{core-obj.tex}
-\loadcorefile{core-lst.tex}
-\loadcorefile{core-itm.tex}
-\loadcorefile{core-des.tex}
-\loadcorefile{core-mat.tex}
-\loadcorefile{core-syn.tex}
-\loadcorefile{core-sys.tex}
-
-\loadcorefile{page-ini.tex}
-\loadcorefile{page-bck.tex}
+\loadmarkfile{core-nav}
+\loadmarkfile{core-obj}
+
+\loadcorefile{strc-itm.tex}
+\loadcorefile{strc-des.tex}
+\loadcorefile{strc-syn.tex}
+
+\loadmarkfile{core-sys}
+
+\loadmarkfile{page-ini}
+\loadmarkfile{page-bck}
\loadcorefile{page-not.tex}
-\loadcorefile{page-one.tex}
+\loadmarkfile{page-one}
\loadcorefile{page-lay.tex}
-\loadcorefile{page-txt.tex}
+\loadmarkfile{page-txt}
\loadcorefile{page-sid.tex}
-\loadcorefile{page-flt.tex}
+
+\loadcorefile{strc-flt.tex}
+
+\loadcorefile{page-mis.tex}
\loadcorefile{page-mul.tex}
\loadcorefile{page-set.tex}
\loadcorefile{page-lyr.tex}
\loadcorefile{page-mak.tex}
-\loadcorefile{page-num.tex}
+
\loadmarkfile{page-lin}
\loadcorefile{page-par.tex}
\loadcorefile{page-mar.tex}
-\loadcorefile{core-job.tex} % why so late?
+\loadmarkfile{core-job} % why so late?
-% so far
+\loadmarkfile{core-buf}
-\loadmarkfile{core-sec}
-\loadcorefile{core-swd.tex}
-\loadcorefile{core-buf.tex}
-\loadcorefile{core-blk.tex}
-\loadcorefile{page-imp.tex}
-\loadcorefile{core-tbl.tex}
-\loadcorefile{core-int.tex}
-\loadcorefile{core-ntb.tex}
-\loadcorefile{core-ltb.tex}
+\loadcorefile{strc-blk.tex}
-%D A few more languages, that have specifics using core
-%D functionality:
+\loadcorefile{page-imp.tex}
-\loadcorefile{lang-chi.tex}
-\loadcorefile{lang-jap.tex}
+\loadmarkfile{core-int}
+\loadcorefile{strc-bkm.tex} % bookmarks
-%D How about fill||in fields and related stuff?
+\loadcorefile{tabl-pln.tex}
+\loadcorefile{thrd-tab.tex}
+\loadcorefile{tabl-tab.tex}
+\loadcorefile{tabl-tbl.tex}
+\loadmarkfile{tabl-ntb}
+\loadcorefile{tabl-nte.tex}
+\loadcorefile{tabl-ltb.tex}
+\loadcorefile{tabl-tsp.tex}
-\loadcorefile{java-ini.tex}
-\loadcorefile{core-fld.tex}
+\loadmarkfile{java-ini}
+\loadmarkfile{core-fld}
\loadcorefile{core-hlp.tex}
-%D Registers can depend on fields, so we load that now.
-
-\loadcorefile{core-reg.tex}
-
-%D Of course we do need fonts. There are no \TFM\ files
-%D loaded yet, so the format file is independant of their
-%D content. Here we also redefine \type{\it} as {\it italic}
-%D instead of italian.
-
+\loadcorefile{char-enc.tex}
\loadmarkfile{font-ini}
-\loadcorefile{font-uni.tex}
-\loadcorefile{font-bfm.tex}
-\loadmkivfile{font-col.tex}
-
-\loadcorefile{type-ini.tex}
+\loadmarkfile{font-unk}
+\loadmarkfile{font-tra}
+\loadmarkfile{font-uni}
+\loadmarkfile{font-col}
+
+\loadcorefile{typo-spa.tex}
+\loadcorefile{typo-krn.tex}
+\loadcorefile{typo-mir.tex}
+\loadcorefile{typo-brk.tex}
+\loadcorefile{typo-cap.tex}
+
+\loadmarkfile{type-ini}
\loadcorefile{type-def.tex}
-%D Properties. Don't ask.
+\loadcorefile{scrp-ini.tex}
-\loadcorefile{prop-ini.tex}
-\loadcorefile{prop-lay.tex}
-\loadcorefile{prop-mis.tex}
-
-%D Like languages, fonts, encodings and symbols, \METAPOST\
-%D support is also organized in its own class of modules.
+\loadmarkfile{prop-ini}
+\loadmarkfile{prop-lay}
+\loadmarkfile{prop-mis}
\loadmkivfile{mlib-ctx.tex}
\loadmkivfile{mlib-pdf.tex}
@@ -298,121 +251,100 @@
\loadmarkfile{meta-ini}
\loadmarkfile{meta-tex}
+\loadmarkfile{meta-pdf}
-\loadcorefile{meta-pdf.tex}
\loadcorefile{meta-pag.tex}
-%D Special page handling (maybe even later)
-
\loadcorefile{page-flw.tex}
\loadcorefile{page-spr.tex}
\loadcorefile{page-plg.tex}
\loadcorefile{page-str.tex}
-%D Hm.
-
\loadcorefile{core-pgr.tex}
\loadcorefile{core-bar.tex}
\loadcorefile{core-snc.tex}
+\loadmarkfile{math-pln}
+\loadmarkfile{math-ini}
+\loadmarkfile{math-for}
+\loadmarkfile{math-def}
+\loadmarkfile{math-ali}
+\loadmarkfile{math-arr}
+\loadmarkfile{math-frc}
+\loadmarkfile{math-scr}
+\loadmarkfile{math-int}
+\loadmarkfile{math-del}
+\loadmarkfile{math-inl}
+\loadmarkfile{math-dis}
+
+\loadcorefile{strc-mat.tex}
-%D Math.
+\loadmarkfile{chem-ini}
+\loadmarkfile{chem-str}
-\loadcorefile{math-pln.tex}
-\loadcorefile{math-ini.tex}
-\loadcorefile{math-ext.tex}
+\loadmarkfile{core-fnt}
-%D Now we're ready for more core modules.
+\loadcorefile{strc-not.tex}
-\loadcorefile{core-fnt.tex}
-\loadcorefile{core-not.tex}
\loadcorefile{core-lnt.tex}
-\loadcorefile{core-mis.tex}
+\loadmarkfile{core-mis}
\loadcorefile{core-trf.tex}
-\loadcorefile{core-inc.tex}
+\loadmarkfile{core-inc}
\loadcorefile{core-fig.tex}
-\loadcorefile{core-par.tex}
\loadcorefile{core-box.tex}
\loadcorefile{page-app.tex}
\loadmarkfile{meta-fig}
-%D Language specific spacing.
-
\loadcorefile{lang-spa.tex}
-%D Only the basic XML parser and remapper are part of the core.
-%D These macros are loaded last since they overload and|/|or
-%D extend previously defined ones.
-
-\loadmkivfile{lxml-ini.tex}
-
\loadcorefile{xtag-ini.tex}
\loadcorefile{xtag-ext.tex}
-\loadcorefile{xtag-prs.tex}
-\loadcorefile{xtag-map.tex}
-\loadcorefile{xtag-stk.tex}
\loadcorefile{xtag-exp.tex}
\loadcorefile{xtag-pre.tex}
\loadcorefile{xtag-xsd.tex}
\loadcorefile{xtag-rng.tex}
-%loadcorefile{xtag-ent.tex}
-
-%D How about this:
\loadcorefile{meta-xml.tex}
-%D \TEX\ related logo's are always typeset in a special way.
-%D Here they come:
-
\loadcorefile{cont-log.tex}
-%D This one overloads af few things:
+\loadcorefile{task-ini.tex}
-\loadcorefile{core-ctx.tex}
-
-%D Defaults go here (more will be moved to this module
-%D later):
+\loadmarkfile{core-ctx}
\loadcorefile{core-lme.tex}
\loadcorefile{core-ini.tex}
-\loadcorefile{core-def.tex}
-
-%D Preloaded modules (some need xml support):
+\loadmarkfile{core-def}
%usemodule[x][res-04] % xml resource libraries
%usemodule[x][res-08] % rlx runtime conversion
-\usemodule[x][res-12] % rli external indentification
-
-%D At run time, a few more files are loaded, like:
-%D
-%D \startitemize[packed]
-%D \item \type{cont-sys}: local (system dependant) defaults
-%D \item \type{cont-old}: substitutes for old (obsolete) macros
-%D \item \type{cont-new}: new macro implementations (for testing)
-%D \item \type{cont-fil}: filename and module synonyms
-%D \stopitemize
+% \usemodule[x][res-12] % rli external indentification
\unprotect
-\beginLUATEX
- \prependtoks
- \ctxlua{input.starttiming(ctx)}%
- \to \everyjob
- \appendtoks
- \ctxlua{input.stoptiming(ctx)}%
- \to \everyjob
- \appendtoks
- \writestatus\m!lua{used config path - \ctxlua{tex.print(caches.configpath())}}%
- \writestatus\m!lua{used cache path - \ctxlua{tex.print(caches.path)}}%
- \to \everydump
-\endLUATEX
-
-\protect
-
-% %D Except from english, no hyphenation patterns are loaded
-% %D yet. Users can specify their needs in the next module:
-%
-% \input cont-usr.tex
+\prependtoks
+ \ctxlua{statistics.starttiming(ctx)}%
+\to \everyjob
+\appendtoks
+ \ctxlua{statistics.stoptiming(ctx)}%
+\to \everyjob
+\appendtoks
+ \writestatus\m!lua{used config path - \ctxlua{tex.print(caches.configpath())}}%
+ \writestatus\m!lua{used cache path - \ctxlua{tex.print(caches.path)}}%
+\to \everydump
+
+\setupcurrentlanguage[\s!en]
+
+\appendtoks
+ \ctxlua {
+ statistics.report_storage("log")
+ statistics.save_fmt_status("\jobname","\contextversion","context.tex")
+ }%
+\to \everydump
+
+\setsystemmode{experimental} % test with *experimental
+
+\protect \errorstopmode \dump \endinput
diff --git a/tex/context/base/context.rme b/tex/context/base/context.rme
new file mode 100644
index 000000000..1b1e48902
--- /dev/null
+++ b/tex/context/base/context.rme
@@ -0,0 +1,85 @@
+Some Basic information
+----------------------
+
+There are currently three interfaces available:
+
+ cont-en the english version
+ cont-de the german version
+ cont-nl the dutch version
+ cont-cz the czech version
+ cont-ro the romanian version
+ cont-it the italian version
+
+One should compile one of these (or all) into a fmt file.
+When one uses the main file,
+
+ context the undefined version
+
+TeX ask for an interface language as well as a message
+language. Here one has to specify the full name (english,
+german, dutch, etc.) or use the default (enter). The \
+savest way to update the TeX and MetaPost format files
+is to use TeXExec:
+
+texexec --make --alone en nl metafun
+
+In the TeXExec manual you can read how to generate a format
+with specific fonts and patterns.
+
+By default only the english hyphenation patterns are loaded,
+unless more are enabled in:
+
+ cont-usr the typesetting language specifications
+
+Furthermore, users can preset commands etc in the file
+
+ cont-sys a system file loaded at runtime
+
+For questions and remarks on ConTeXt, one can subscribe to
+the list:
+
+ ntg-context@ntg.nl
+
+by sending the message
+
+ subscribe ntg-context
+
+to the list server:
+
+ majordomo@ntg.nl
+
+One can find more info at:
+
+ www.pragma-ade.com
+
+or at the mirror sites mentioned there.
+
+Don't hesitate to ask questions. ConTeXt can do a lot, and
+the manuals are always a bit behind and incomplete. Also take
+a look at the files
+
+ mreadme.pdf
+ minstall.pdf
+ mtexexec.pdf
+ mtexutil.pdf
+
+The teTeX, fpTeX, and 4TeX distributions demonstrate how
+ConTeXt can be integrated in a TeX directory structure.
+
+-------------------------
+
+functionality removed from mkiv:
+
+page-log : layers can do teh same and are more flexible
+core-dat : just use lua for database purposes
+core-swd : this was a temporary solution
+
+functionality changed in mkii and mkiv:
+
+xtag-map : no longer preloaded
+xtag-stk : no longer preloaded
+xtag-prs : no longer preloaded
+
+-------------------------
+
+Hans Hagen, pragma@wxs.nl
diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex
index 875779ef4..08ffc3a60 100644
--- a/tex/context/base/context.tex
+++ b/tex/context/base/context.tex
@@ -13,15 +13,6 @@
\catcode`\{=1 \catcode`\}=2 \catcode`\#=6
-%D For many years \CONTEXT\ supported both good old \TEX\ and \ETEX, but
-%D the time has come (August 2006) to advance, especially now that all
-%D engines provide \ETEX\ functionality and more is on the horizon.
-
-\ifx\eTeXversion\undefined
- \immediate\write16{SORRY CONTEXT NOW NEEDS ETEX}
- \expandafter \end
-\fi
-
%D From the next string (which is set by the script that assembles the
%D distribution) later on we will calculate a number that can be used
%D by use modules to identify the feature level. Starting with version
@@ -29,12 +20,12 @@
%D your styles an modules.
\edef\contextformat {\jobname}
-\edef\contextversion{2008.10.31 13:58}
+\edef\contextversion{2009.05.28 11:23}
%D For those who want to use this:
-\def\fmtname {context}
-\def\fmtversion{3.1415926}
+\let\fmtname \contextformat
+\let\fmtversion\contextversion
\let\showcontextbanner\relax
diff --git a/tex/context/base/core-bar.tex b/tex/context/base/core-bar.tex
index 9b7acf17f..5b28afb9d 100644
--- a/tex/context/base/core-bar.tex
+++ b/tex/context/base/core-bar.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Plus Macros / Margin Bars etc}
+\writestatus{loading}{ConTeXt Core Macros / Margin Bars}
\unprotect
diff --git a/tex/context/base/core-blk.lua b/tex/context/base/core-blk.lua
deleted file mode 100644
index 1007273d5..000000000
--- a/tex/context/base/core-blk.lua
+++ /dev/null
@@ -1,145 +0,0 @@
-if not modules then modules = { } end modules ['core-blk'] = {
- version = 1.001,
- comment = "companion to core-blk.mkiv",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
--- this one runs on top of buffers and structure
-
-local texprint, format = tex.print, string.format
-
-structure = structure or { }
-structure.blocks = structure.blocks or { }
-
-local blocks = structure.blocks
-
-blocks.collected = blocks.collected or { }
-blocks.tobesaved = blocks.tobesaved or { }
-blocks.states = blocks.states or { }
-
-local tobesaved, collected, states = blocks.tobesaved, blocks.collected, blocks.states
-
-local function initializer()
- tobesaved, collected, states = blocks.tobesaved, blocks.collected, blocks.states
-end
-
--- not used, todo: option to do single or double pass
-
--- job.register('structure.blocks.collected', structure.blocks.tobesaved, initializer, nil)
-
-local printer = (lpeg.linebyline/texprint)^0
-
-function blocks.print(name,data,hide)
- if hide then
- texprint(tex.ctxcatcodes,format("\\dostarthiddenblock{%s}",name))
- else
- texprint(tex.ctxcatcodes,format("\\dostartnormalblock{%s}",name))
- end
- if type(data) == "table" then
- for i=1,#data do
- texprint(data[i])
- end
- else
- printer:match(data)
- end
- if hide then
- texprint(tex.ctxcatcodes,"\\dostophiddenblock")
- else
- texprint(tex.ctxcatcodes,"\\dostopnormalblock")
- end
-end
-
-function blocks.define(name)
- states[name] = { all = "hide" }
-end
-
-function blocks.setstate(state,name,tag)
- local all = tag == ""
- local tags = not all and aux.settings_to_array(tag)
- for n in name:gmatch("%s*([^,]+)") do
- local sn = states[n]
- if not sn then
- -- error
- elseif all then
- sn.all = state
- else
- for _, tag in pairs(tags) do
- sn[tag] = state
- end
- end
- end
-end
-
-function blocks.select(state,name,tag,criterium)
- criterium = criterium or "text"
- if tag:find("=") then tag = "" end
- local names = aux.settings_to_set(name)
- local all = tag == ""
- local tags = not all and aux.settings_to_set(tag)
- local hide = state == "process"
- local n = structure.sections.number_at_depth(criterium)
- local result = structure.lists.filter_collected("all", criterium, n, tobesaved)
- for i=1,#result do
- local b = result[i].entry
- if names[b.name] then
- local btags = b.tags
- if all then
- blocks.print(name,b.data,hide)
- else
- for tag, sta in pairs(tags) do
- if btags[tag] then
- blocks.print(name,b.data,hide)
- break
- end
- end
- end
- end
- end
-end
-
-function blocks.save(name,tag,buffer)
- local data = buffers.data[buffer]
- local tags = aux.settings_to_set(tag)
- local plus, minus = false, false
- if tags['+'] then plus = true tags['+'] = nil end
- if tags['-'] then minus = true tags['-'] = nil end
- local slt = structure.lists.tobesaved
- tobesaved[#tobesaved+1] = {
- entry = {
- name = name,
- tags = tags,
- data = data or "error",
- plus = plus,
- minus = minus,
- },
- sectionnumber = slt[#slt] and slt[#slt].sectionnumber
- }
- local allstate = states[name].all
- if not next(tags) then
- if allstate ~= "hide" then
- blocks.print(name,data)
- elseif plus then
- blocks.print(name,data,true)
- end
- else
- local sn = states[name]
- for tag, _ in pairs(tags) do
- if sn[tag] == nil then
- if allstate ~= "hide" then
- blocks.print(name,data)
- break
- end
- elseif sn[tag] ~= "hide" then
- blocks.print(name,data)
- break
- end
- end
- end
- buffers.data[buffer] = nil
-end
-
--- function sections.getnumber()
--- structure.sections.number(entry, { }, "sectionnumber", "sectionnumber")
--- end
diff --git a/tex/context/base/core-blk.mkiv b/tex/context/base/core-blk.mkiv
deleted file mode 100644
index 9d1f4deb4..000000000
--- a/tex/context/base/core-blk.mkiv
+++ /dev/null
@@ -1,109 +0,0 @@
-%D \module
-%D [ file=core-blk,
-%D version=2008.10.20,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Blockmoves,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-% \registerctxluafile{core-blk}{1.001}
-\ctxloadluafile{core-blk}{}
-
-% we run on top of buffers and sections
-%
-% todo: prefix numbers (needs further integration elsewhere)
-% check functionality
-% alternative files (needs further integration elsewhere)
-
-\def\blockparameter#1#2{\ifcsname\??tb#1#2\endcsname\csname\??tb#1#2\endcsname\fi}
-
-\def\setupblockparameters{\dodoubleargument \dosetupblock} % fast one (for compatibility)
-\def\setupblock {\dodoubleargumentwithset\dosetupblock} % handles set
-
-\def\dosetupblock[#1]{\getparameters[\??tb#1]} % [#1][#2]}
-
-\def\defineblock
- {\dosingleargument\dodefineblock}
-
-\def\dodefineblock[#1]%
- {\getparameters
- [\??tb#1]
- [\c!before=\blank,
- \c!after=\blank,
- \c!inner=,
- \c!style=,
- \c!file=]% todo
- \ctxlua{structure.blocks.define("#1")}%
- \setvalue{\e!begin#1}{\dodoubleempty\dobeginofblock[#1]}%
- \letvalue{\e!end#1}\relax}
-
-\long\def\dobeginofblock[#1][#2]%
- {\expanded{\dodowithbuffer{@block@}{\e!begin#1}{\e!end#1}}
- {}{\ctxlua{structure.blocks.save("#1","#2","@block@")}}}% before after
-
-\def\dostarthiddenblock
- {\startnointerference
- \dostartnormalblock}
-
-\def\dostophiddenblock
- {\dostopnormalblock
- \stopnointerference}
-
-% order matters: \c!before (think of: \c!before=\startitemize)
-
-\let\doblocksetups\gobbleoneargument
-
-\def\dostartnormalblock#1% name
- {\bgroup
-\visibletrue
- \edef\currentblock{#1}%
- \doblocksetups\currentblock
- \let\doblocksetups\gobbleoneargument
- \blockparameter\currentblock\c!before
- \dosetfontattribute{\??tb\currentblock}\c!style
- \dosetcolorattribute{\??tb\currentblock}\c!color
- \blockparameter\currentblock\c!inner
- \ignorespaces}
-
-\def\dostopnormalblock
- {\removeunwantedspaces
- \blockparameter\currentblock\c!after
- \par % todo: alternative = text, paragraph
- \egroup}
-
-\def\dosetblockstate[#1][#2][#3]% state name tag
- {\ctxlua{structure.blocks.setstate("#1","#2","#3")}}
-
-\def\doselectblocks[#1][#2][#3][#4]% state name tag setups
- {\begingroup
- \doifassignmentelse{#3}
- {\getparameters[\??tb\??tb][\c!criterium=\v!text,#3]%
- \def\doblocksetups##1{\getparameters[\??tb##1][#3]}%
- \ctxlua{structure.blocks.select("#1","#2","","\@@tb@@tbcriterium")}}
- {\getparameters[\??tb\??tb][\c!criterium=\v!text,#4]%
- \def\doblocksetups##1{\getparameters[\??tb##1][#4]}%
- \ctxlua{structure.blocks.select("#1","#2","#3","\@@tb@@tbcriterium")}}%
- \endgroup}
-
-% hide: save, if [+] also hidden execute
-% keep: save and normal execute
-
-\def\hideblocks{\dotripleempty\dosetblockstate[hide]}
-\def\keepblocks{\dotripleempty\dosetblockstate[keep]}
-
-% use : normal execute unless [-]
-% process: hidden execute unless [-]
-% select : idem use
-
-\def\useblocks {\doquadrupleempty\doselectblocks[use]}
-\def\processblocks{\doquadrupleempty\doselectblocks[process]}
-\def\selectblocks {\doquadrupleempty\doselectblocks[use]}
-
-\protect
diff --git a/tex/context/base/core-blk.tex b/tex/context/base/core-blk.tex
index 8de1099e6..b224bf18e 100644
--- a/tex/context/base/core-blk.tex
+++ b/tex/context/base/core-blk.tex
@@ -13,135 +13,7 @@
% investigate etex's \readline and \scantokens
-\writestatus{loading}{Context Core Macros / Blockmoves}
-
-\startmessages dutch library: textblocks
- title: tekstblokken
- 1: nieuwe versie, tweede run nodig
- 2: wegschrijven blokken naar --
- 3: inlezen blokken uit --
- 4: er is een tweede run nodig
- 5: -- niet verborgen
- 6: -- verborgen en verwerkt
- 7: -- verborgen
- 8: -- gehandhaafd
- 9: -- niet gehandhaafd
- 10: -- geladen en verwerkt
- 11: -- geladen en geplaatst
- 12: -- overgeslagen
-\stopmessages
-
-\startmessages english library: textblocks
- title: textblocks
- 1: new version, second pass needed
- 2: writing blocks to --
- 3: reading blocks from --
- 4: second pass needed
- 5: -- not hidden
- 6: -- hidden and processed
- 7: -- hidden
- 8: -- typeset
- 9: -- not typeset
- 10: -- loaded and processed
- 11: -- loaded and typeset
- 12: -- skipped
-\stopmessages
-
-\startmessages german library: textblocks
- title: textblock
- 1: neue Version, zweiter Durchlauf benoetigt
- 2: schreibe Bloecke zu --
- 3: lese Bloecke von --
- 4: zweiter Durchlauf benoetigt
- 5: -- nicht verborgen
- 6: -- verborgen und verarbeitet
- 7: -- verborgen
- 8: -- gesetzt
- 9: -- nicht gesetzt
- 10: -- geladen und verarbeitet
- 11: -- geladen und gesetzt
- 12: -- ausgelassen
-\stopmessages
-
-\startmessages czech library: textblocks
- title: textovyblok
- 1: nova verze, je treba druhy beh
- 2: zapisuji bloky do --
- 3: ctu bloky z --
- 4: je treba druhy beh
- 5: -- neni skryto
- 6: -- skryto a zpracovano
- 7: -- skryto
- 8: -- vysazeno
- 9: -- nevysazeno
- 10: -- nacteno a zpracovano
- 11: -- nacteno a vysazeno
- 12: -- preskoceno
-\stopmessages
-
-\startmessages italian library: textblocks
- title: blocchi di testo
- 1: nuova versione, seconda passata necessaria
- 2: scrittura dei blocchi su --
- 3: lettura dei blocchi da --
- 4: seconda passata necessaria
- 5: -- non nascosto
- 6: -- nascosto ed elaborato
- 7: -- nascosto
- 8: -- composto
- 9: -- non composto
- 10: -- caricato ed elaborato
- 11: -- caricato e composto
- 12: -- saltato
-\stopmessages
-
-\startmessages norwegian library: textblocks
- title: tekstblokker
- 1: ny versjon, andre gjennomkjøring nødvendig
- 2: skriver blokker til --
- 3: leser blokker fra --
- 4: andre gjennomkjøring nødvendig
- 5: -- ikke skjult
- 6: -- skjult og behandlet
- 7: -- skjult
- 8: -- tegnsatt
- 9: -- ikke tegnsatt
- 10: -- lest inn og behandlet
- 11: -- lest inn og tegnsatt
- 12: -- utelatt
-\stopmessages
-
-\startmessages romanian library: textblocks
- title: blocuri de text
- 1: o noua versiune, este nevoie de inca o trecere
- 2: se scriu blocurile in --
- 3: se citesc blocurile din --
- 4: este nevoie de inca o trecere
- 5: -- nu este ascuns
- 6: -- ascuns si procesat
- 7: -- ascuns
- 8: -- cules
- 9: -- nu este cules
- 10: -- incarcat si procesat
- 11: -- incarcat si cules
- 12: -- sarit peste
-\stopmessages
-
-\startmessages french library: textblocks
- title: blocs de texte
- 1: nouvelle version, une seconde passe est nécessaire
- 2: ecriture des blocs vers --
- 3: lecture des blocs en provenance de --
- 4: seconde passe nécessaire
- 5: -- non caché
- 6: -- caché et traité
- 7: -- caché
- 8: -- composé
- 9: -- non composé
- 10: -- chargé et traité
- 11: -- chargé et composé
- 12: -- sauté
-\stopmessages
+\writestatus{loading}{ConTeXt Core Macros / Blockmoves}
\unprotect
diff --git a/tex/context/base/core-box.tex b/tex/context/base/core-box.tex
index bbcfe451d..97811e78f 100644
--- a/tex/context/base/core-box.tex
+++ b/tex/context/base/core-box.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Boxes}
+\writestatus{loading}{ConTeXt Core Macros / Boxes}
%D This module contains all kind of macros for moving content
%D around. Many macros here come from other modules, but
@@ -274,7 +274,6 @@
\global\ht\collectorbox\scratchdimen
\egroup}
-
%\definecollector[test]
%\setcollector[test]
% [location=rb]
diff --git a/tex/context/base/core-buf.lua b/tex/context/base/core-buf.lua
index a43c33054..389ebde35 100644
--- a/tex/context/base/core-buf.lua
+++ b/tex/context/base/core-buf.lua
@@ -1,17 +1,17 @@
--- filename : core-buf.lua
--- comment : companion to core-buf.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['core-buf'] = {
+ version = 1.001,
+ comment = "companion to core-buf.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-- ctx lua reference model / hooks and such
-- to be optimized
-- redefine buffers.get
-if not versions then versions = { } end versions['core-buf'] = 1.001
-
-if unicode and not utf then utf = unicode.utf8 end
+utf = unicode.utf8
buffers = { }
buffers.data = { }
@@ -22,9 +22,15 @@ buffers.visualizers = { }
-- if needed we can make 'm local
+local utf = unicode.utf8
+
local concat, texsprint, texprint, texwrite = table.concat, tex.sprint, tex.print, tex.write
local utfbyte, utffind, utfgsub = utf.byte, utf.find, utf.gsub
-local byte, sub, find, char, gsub, rep = string.byte, string.sub, string.find, string.char, string.gsub, string.rep
+local byte, sub, find, char, gsub, rep, lower = string.byte, string.sub, string.find, string.char, string.gsub, string.rep, string.lower
+local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
+
+local vrbcatcodes = tex.vrbcatcodes
+local ctxcatcodes = tex.ctxcatcodes
local data, commands, flags, hooks, visualizers = buffers.data, buffers.commands, buffers.flags, buffers.hooks, buffers.visualizers
@@ -132,31 +138,19 @@ function buffers.type(name)
end
end
---~ function buffers.typefile(name) -- keep this one, uses tex reader
---~ local t = input.openfile(name)
---~ local action = buffers.typeline
---~ if t then
---~ local lines = { }
---~ while true do
---~ local str = t.reader()
---~ if str then
---~ lines[#lines+1] = str
---~ else
---~ break
---~ end
---~ end
---~ t.close()
---~ local line, n = 0, 0
---~ local first, last, m = buffers.strip(lines)
---~ for i=first,last do
---~ n, line = action(lines[i], n, m, line)
---~ end
---~ end
---~ end
-
-function buffers.typefile(name)
- local str = io.loaddata(name)
- if str then
+function buffers.loaddata(filename) -- this one might go away
+ -- this will be cleaned up when we have split supp-fil completely
+ -- instead of half-half
+ local ok, str, n = resolvers.loaders.tex(filename)
+ if not str then
+ ok, str, n = resolvers.loaders.tex(file.addsuffix(filename,'tex'))
+ end
+ return str or ""
+end
+
+function buffers.typefile(name) -- still somewhat messy, since name can be be suffixless
+ local str = buffers.loaddata(name)
+ if str and str~= "" then
local lines = str:splitlines()
local line, n, action = 0, 0, buffers.typeline
local first, last, m = buffers.strip(lines)
@@ -192,21 +186,6 @@ function buffers.save(name)
io.savedata(f,b)
end
--- todo, use more locals
-
---~ function buffers.get(name)
---~ local b = data[name]
---~ if b then
---~ if type(b) == "table" then
---~ for i=1,#b do
---~ texprint(b[i])
---~ end
---~ else
---~ string.piecewise(b, " *[\010\013]", texprint) -- hm, can be faster
---~ end
---~ end
---~ end
-
local printer = (lpeg.linebyline/texprint)^0
function buffers.get(name)
@@ -217,17 +196,16 @@ function buffers.get(name)
texprint(b[i])
end
else
- -- b:piecewise(" *[\010\013]", texprint) -- hm, can be faster
printer:match(b)
end
end
end
-function buffers.content(name) -- no print
+local function content(name,separator) -- no print
local b = data[name]
if b then
if type(b) == "table" then
- return concat(b," ")
+ return concat(b,separator or "\n")
else
return b
end
@@ -236,24 +214,30 @@ function buffers.content(name) -- no print
end
end
+buffers.content = content
+
function buffers.collect(names,separator) -- no print
local t = { }
if type(names) == "table" then
for i=1,#names do
- local c = buffers.content(names[i])
+ local c = content(names[i],separator)
if c ~= "" then
t[#t+1] = c
end
end
else
for name in names:gmatch("[^,]+") do
- local c = buffers.content(name)
+ local c = content(name,separator)
if c ~= "" then
t[#t+1] = c
end
end
end
- return concat(t,separator or " ") -- maybe this will change to "\n"
+ return concat(t,separator or "\n") -- "\n" is safer due to comments and such
+end
+
+local function tobyte(c)
+ return " [" .. byte(c) .. "] "
end
function buffers.inspect(name)
@@ -262,17 +246,13 @@ function buffers.inspect(name)
if type(b) == "table" then
for _,v in ipairs(b) do
if v == "" then
- texsprint(tex.ctxcatcodes,"[crlf]\\par ")
+ texsprint(ctxcatcodes,"[crlf]\\par ") -- space ?
else
- texsprint(tex.ctxcatcodes,(b:gsub("(.)",function(c)
- return " [" .. byte(c) .. "] "
- end)) .. "\\par")
+ texsprint(ctxcatcodes,(gsub(b,"(.)",tobyte)),"\\par")
end
end
else
- texsprint(tex.ctxcatcodes,(b:gsub("(.)",function(c)
- return " [" .. byte(c) .. "] "
- end)))
+ texsprint(ctxcatcodes,(gsub(b,"(.)",tobyte)))
end
end
end
@@ -286,7 +266,7 @@ visualizers.mp = { }
visualizers.escapetoken = nil
visualizers.tablength = 7
-visualizers.enabletab = false
+visualizers.enabletab = true -- false
visualizers.enableescape = false
visualizers.obeyspace = true
@@ -299,19 +279,18 @@ end
buffers.currentvisualizer = 'default'
function buffers.setvisualizer(str)
- buffers.currentvisualizer = str:lower()
+ buffers.currentvisualizer = lower(str)
if not visualizers[buffers.currentvisualizer] then
buffers.currentvisualizer = 'default'
end
end
function buffers.doifelsevisualizer(str)
- cs.testcase((str ~= "") and (visualizers[str:lower()] ~= nil))
+ cs.testcase((str ~= "") and (visualizers[lower(str)] ~= nil))
end
-- calling routines, don't change
-
function hooks.flush_line(str,nesting)
str = str:gsub(" *[\n\r]+ *"," ")
local flush_line = visualizers[buffers.currentvisualizer].flush_line
@@ -350,7 +329,12 @@ function hooks.empty_line()
end
function hooks.line(str)
- local empty_line = visualizers[buffers.currentvisualizer].line
+ local line = visualizers[buffers.currentvisualizer].line
+ if visualizers.enabletab then
+ str = string.tabtospace(str,visualizers.tablength)
+ else
+ str = gsub(str,"\t"," ")
+ end
if line then
return line(str)
else
@@ -361,19 +345,19 @@ end
-- defaults
function visualizers.default.flush_line(str)
- texsprint(tex.ctxcatcodes,buffers.escaped(str))
+ texsprint(ctxcatcodes,buffers.escaped(str))
end
function visualizers.default.begin_of_line(n)
- texsprint(tex.ctxcatcodes, commands.begin_of_line_command .. "{" .. n .. "}")
+ texsprint(ctxcatcodes, commands.begin_of_line_command,"{",n,"}")
end
function visualizers.default.end_of_line()
- texsprint(tex.ctxcatcodes,commands.end_of_line_command)
+ texsprint(ctxcatcodes,commands.end_of_line_command)
end
function visualizers.default.empty_line()
- texsprint(tex.ctxcatcodes,commands.empty_line_command)
+ texsprint(ctxcatcodes,commands.empty_line_command)
end
function visualizers.default.line(str)
@@ -418,7 +402,7 @@ function visualizers.flush_nested(str, enable) -- no utf, kind of obsolete mess
end
end
result = result .. "\\char" .. byte(sub(str,i,i)) .. " " .. string.rep("}",nested)
- texsprint(tex.ctxcatcodes,result)
+ texsprint(ctxcatcodes,result)
end
-- handy helpers
@@ -461,14 +445,16 @@ buffers.open_nested = rep("\\char"..byte('<').." ",2)
buffers.close_nested = rep("\\char"..byte('>').." ",2)
function buffers.replace_nested(result)
- return (gsub(result:gsub(buffers.open_nested,"{"),buffers.close_nested,"}"))
+ result = gsub(result,buffers.open_nested, "{")
+ result = gsub(result,buffers.close_nested,"}")
+ return result
end
function buffers.flush_result(result,nested)
if nested then
- texsprint(tex.ctxcatcodes,buffers.replace_nested(concat(result,"")))
+ texsprint(ctxcatcodes,buffers.replace_nested(concat(result,"")))
else
- texsprint(tex.ctxcatcodes,concat(result,""))
+ texsprint(ctxcatcodes,concat(result,""))
end
end
@@ -489,15 +475,6 @@ function buffers.escaped(str)
return (utfgsub(str,"(.)", escaped_token))
end
---~ function buffers.escaped_chr(ch)
---~ local b = utfbyte(ch)
---~ if b == 32 then
---~ return "\\obs "
---~ else
---~ return "\\char" .. b .. " "
---~ end
---~ end
-
function buffers.escaped_chr(ch)
if ch == " " then
return "\\obs "
@@ -506,58 +483,17 @@ function buffers.escaped_chr(ch)
end
end
--- redone
-
---~ function visualizers.default.flush_line(str)
---~ local tc = tex.ctxcatcodes
---~ for u in str:utfcharacters() do
---~ texsprint(tc,escaped_token(u))
---~ end
---~ end
-
---~ local a, z, A, Z, zero, nine = byte("a"), byte("z"), byte("A"), byte("Z"), byte("0"), byte("9")
-
---~ function visualizers.default.flush_line(str)
---~ local tc = tex.ctxcatcodes
---~ for b in str:utfvalues() do
---~ if (b>=a and b<=z) or (b>=A and b<=Z) or (b>=zero and b<=nine) then
---~ texsprint(tc,char(b))
---~ elseif b == 32 then
---~ texsprint(tc,"\\obs ")
---~ else
---~ texsprint(tc,"\\char",b," ")
---~ end
---~ end
---~ end
-
---~ function visualizers.default.flush_line(str)
---~ local tc = tex.ctxcatcodes
---~ local vc = tex.vrbcatcodes
---~ local vs = visualizers.obeyspace
---~ for ch in str:utfcharacters() do
---~ if ch == "{" or ch == "}" then
---~ texsprint(tc,"\\char",ch:byte()," ")
---~ elseif vs and ch == " " then
---~ texsprint(tc,"\\obs ")
---~ else
---~ texsprint(vc,ch)
---~ end
---~ end
---~ end
-
function visualizers.default.flush_line(str)
str = str:gsub(" *[\n\r]+ *"," ")
- local vc = tex.vrbcatcodes
if visualizers.obeyspace then
- local tc = tex.ctxcatcodes
- for c in str:utfcharacters() do
+ for c in utfcharacters(str) do
if c == " " then
- texsprint(tc,"\\obs ")
+ texsprint(ctxcatcodes,"\\obs ")
else
- texsprint(vc,c)
+ texsprint(vrbcatcodes,c)
end
end
else
- texsprint(vc,str)
+ texsprint(vrbcatcodes,str)
end
end
diff --git a/tex/context/base/core-buf.mkii b/tex/context/base/core-buf.mkii
index 206992e9b..9937fae01 100644
--- a/tex/context/base/core-buf.mkii
+++ b/tex/context/base/core-buf.mkii
@@ -11,69 +11,14 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
-
-\def\mkresetbuffer
- {\unlinkfile{\TEXbufferfile\currentbuffer}}
-
-\long\def\mksetbuffer#1%
- {\edef\bufferfilename{\TEXbufferfile{\currentbuffer}}%
- \immediate\openout\tmpblocks\bufferfilename
- \defconvertedargument\ascii{#1}%
- \immediate\write\tmpblocks{\ascii}%
- \immediate\closeout\tmpblocks}
-
-\def\mkstartbuffer#1#2#3#4#5% ook grabben a la mkiv / no, we need to add par anchors
- {\doifelsenothing{#4}
- {\letbeundefined{\e!stop\v!buffer}% % \let\stopbuffer=\relax % \undefined
- \edefconvertedargument\beginofblock{\e!start\v!buffer}%
- \edefconvertedargument\endofblock {\e!stop \v!buffer}%
- \ifcase\buffernestmode
- \let\processnextbufferline\processnextbufferlineB
- \else
- \let\processnextbufferline\processnextbufferlineA
- \fi}
- {\letbeundefined{#4}% \letvalue{#4}=\relax % \undefined
- \@EA\defconvertedargument\@EA\beginofblock\@EA{\csname#3\endcsname}% we could use defconvertedcommand here (no \@EA)
- \@EA\defconvertedargument\@EA\endofblock \@EA{\csname#4\endcsname}% we could use defconvertedcommand here (no \@EA)
- \ifcase\buffernestmode
- \let\processnextbufferline\processnextbufferlineB
- \or
- \let\processnextbufferline\processnextbufferlineB
- \else
- \let\processnextbufferline\processnextbufferlineA
- \fi}%
- \def\closebufferfile
- {\ifsegmentatebuffer
- \immediate\write\tmpblocks{\string\stopbufferparagraph}%
- \fi
- \immediate\closeout\tmpblocks
- #5% \egroup
- \getvalue{#4}}%
- \doifelsenothing{#2}
- {\edef\bufferfilename{\TEXbufferfile\jobname}}%
- {\edef\bufferfilename{\TEXbufferfile{#2}}}%
- \immediate\openout\tmpblocks\bufferfilename
- \ifsegmentatebuffer
- \immediate\write\tmpblocks{\string\startbufferparagraph}%
- \fi
- \newcounter\nestedbufferlevel
- \recatcodeuppercharacterstrue
- \setcatcodetable\vrbcatcodes
- \obeylines
- \copybufferline}
+\writestatus{loading}{ConTeXt Core Macros / Buffers}
-\def\mkdobuffer#1% command
- {\beginrestorecatcodes
- #1%
- \endrestorecatcodes}
+\unprotect
-\def\mkgetbuffer {\readjobfile{\TEXbufferfile{\currentbuffer}}\donothing\donothing}
-\def\mktypebuffer{\typefile{\TEXbufferfile{\currentbuffer}}}
+% Helpers:
-% support macros
+\chardef\buffernestmode\plusone % 0: not nested, 1: startbuffer nested, 2: all buffers nested
-% \expandafter \convertargument \gobbleoneargument @ \to \emptybufferline
\edefconvertedargument\emptybufferline{ }
\ifx\tmpblocks\undefined \newwrite\tmpblocks \fi
@@ -133,12 +78,271 @@
{\processnextbufferline{#1}\closebufferfile{\flushbufferline{#1}\copybufferline}}
\egroup
-% kind of obsolete with mkiv
+\newif\ifsegmentatebuffer
+\newif\ifemptybufferline
+
+\def\currentbuffer{\jobname}
-\def\mkstartmemorybuffer
+\def\setcurrentbuffer#1%
+ {\doifelsenothing{#1}{\edef\currentbuffer{\jobname}}{\edef\currentbuffer{#1}}}
+
+\def\resetbuffer
+ {\dosingleempty\doresetbuffer}
+
+\def\doresetbuffer[#1]%
+ {\begingroup
+ \setcurrentbuffer{#1}%
+ \unlinkfile{\TEXbufferfile\currentbuffer}%
+ \endgroup}
+
+\def\dostartbuffer
+ {\bgroup
+ \obeylines % nodig, anders gaat 't fout als direct \starttable (bv)
+ \doquadrupleempty\dodostartbuffer}
+
+\def\dodostartbuffer[#1][#2][#3][#4]% upward compatible
+ {\iffourthargument
+ \def\next{\dododostartbuffer{#1}{#2}{#3}{#4}}%
+ \else
+ \def\next{\dododostartbuffer {}{#1}{#2}{#3}}%
+ \fi
+ \next}
+
+\def\dododostartbuffer#1#2#3#4%
+ {%\showmessage\m!systems{15}{#2}%
+ \doifelsevalue{\??bu#1\c!paragraph}\v!yes
+ {\segmentatebuffertrue} % todo in mkiv
+ {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}\segmentatebuffertrue\segmentatebufferfalse}%
+ \doifvalue{\??bu#1\c!local}\v!yes
+ {\chardef\buffernestmode\plustwo}% permit nesting
+ \setcurrentbuffer{#2}%
+ \doifelsenothing{#4}
+ {\letbeundefined{\e!stop\v!buffer}% % \let\stopbuffer=\relax % \undefined
+ \edefconvertedargument\beginofblock{\e!start\v!buffer}%
+ \edefconvertedargument\endofblock {\e!stop \v!buffer}%
+ \ifcase\buffernestmode
+ \let\processnextbufferline\processnextbufferlineB
+ \else
+ \let\processnextbufferline\processnextbufferlineA
+ \fi}
+ {\letbeundefined{#4}% \letvalue{#4}=\relax % \undefined
+ \@EA\defconvertedargument\@EA\beginofblock\@EA{\csname#3\endcsname}% we could use defconvertedcommand here (no \@EA)
+ \@EA\defconvertedargument\@EA\endofblock \@EA{\csname#4\endcsname}% we could use defconvertedcommand here (no \@EA)
+ \ifcase\buffernestmode
+ \let\processnextbufferline\processnextbufferlineB
+ \or
+ \let\processnextbufferline\processnextbufferlineB
+ \else
+ \let\processnextbufferline\processnextbufferlineA
+ \fi}%
+ \def\closebufferfile
+ {\ifsegmentatebuffer
+ \immediate\write\tmpblocks{\string\stopbufferparagraph}%
+ \fi
+ \immediate\closeout\tmpblocks
+ \egroup
+ \getvalue{#4}}%
+ \doifelsenothing{#2}
+ {\edef\bufferfilename{\TEXbufferfile\jobname}}%
+ {\edef\bufferfilename{\TEXbufferfile{#2}}}%
+ \immediate\openout\tmpblocks\bufferfilename
+ \ifsegmentatebuffer
+ \immediate\write\tmpblocks{\string\startbufferparagraph}%
+ \fi
+ \newcounter\nestedbufferlevel
+ \recatcodeuppercharacterstrue
+ \setcatcodetable\vrbcatcodes
+ \obeylines
+ \copybufferline}
+
+\letvalue{\e!start\v!buffer}\dostartbuffer
+
+\let\endbuffer\undefined % to please the dep parser
+
+\def\setbuffer
+ {\dosingleempty\dosetbuffer}
+
+\long\def\dosetbuffer[#1]#2\endbuffer % seldom used so we just pass #2
+ {\begingroup
+ \setcurrentbuffer{#1}%
+ \edef\bufferfilename{\TEXbufferfile{\currentbuffer}}%
+ \immediate\openout\tmpblocks\bufferfilename
+ \defconvertedargument\ascii{#2}%
+ \immediate\write\tmpblocks{\ascii}%
+ \immediate\closeout\tmpblocks
+ \endgroup}
+
+\def\setupbuffer
+ {\dodoubleempty\dosetupbuffer}
+
+\def\dosetupbuffer[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??bu#1][#2]%
+ \else
+ \getparameters[\??bu][#1]%
+ \fi}
+
+\def\dodefinebuffer[#1][#2]%
+ {\iffirstargument % else problems
+ \doglobal\increment\nofdefinedbuffers
+ \letvalue{\??bu#1\c!number }\nofdefinedbuffers
+ \letvalue{\??bu#1\c!paragraph}\v!no
+ \setevalue{\e!start#1}{\noexpand\dostartbuffer[#1][def-\nofdefinedbuffers][\e!start#1][\e!stop#1]}%
+ \setevalue{\e!get #1}{\noexpand\dogetbuffer [#1][def-\nofdefinedbuffers]}%
+ \setevalue{\e!type #1}{\noexpand\dotypebuffer [#1][def-\nofdefinedbuffers]}%
+ \getparameters[\??bu#1][#2]%
+ \fi}
+
+\def\definebuffer
+ {\dodoubleempty\dodefinebuffer}
+
+\def\getbuffer
+ {\dodoubleempty\dogetbuffer}
+
+\def\dogetbuffer[#1][#2]%
+ {\ifsecondargument
+ \dodogetbuffer[#1][#2]%
+ \else
+ \dodogetbuffer[][#1]%
+ \fi}
+
+\def\dogetbufferasis{\readjobfile{\TEXbufferfile{\currentbuffer}}\donothing\donothing}%
+
+\def\dodogetbuffer[#1][#2]%
+ {\getvalue{\??bu#1\c!before}%
+ \dobuffer{16}{#2}\dogetbufferasis
+ \getvalue{\??bu#1\c!after}}
+
+\def\typebuffer
+ {\dodoubleempty\dotypebuffer}
+
+\def\dogetfilebuffer{\typefile{\TEXbufferfile{\currentbuffer}}}
+
+\def\dotypebuffer[#1][#2]%
+ {\iffirstargument
+ \dobuffer{17}{#1}\dogetfilebuffer
+ \else
+ \dobuffer{17}{#2}\dogetfilebuffer
+ \fi}
+
+\def\dobuffer#1#2#3%
+ {\doifelsenothing{#2}
+ {\dodobuffer#3\jobname}
+ {\processcommalist[#2]{\dodobuffer#3}}}
+
+\def\dodobuffer#1#2% command name
+ {\pushmacro\currentbuffer
+ \edef\currentbuffer{\ifcsname\??bu#2\c!number\endcsname def-\csname\??bu#2\c!number\endcsname\else#2\fi}%
+ \beginrestorecatcodes
+ #1%
+ \endrestorecatcodes
+ \popmacro\currentbuffer}
+
+\def\processTEXbuffer{\getbuffer} % handy
+
+% seldom used, only in a few projects that demanded more speed
+
+\def\dostartmemorybuffer
{\dosingleempty\dostartmemorybuffer}
\long\def\dostartmemorybuffer[#1]#2\stopbuffer
{\setbuffer[#1]#2\endbuffer}
+\let\dostartfilebuffer\startbuffer
+
+\def\usememorybuffers{\let\startbuffer\dostartmemorybuffer}
+\def\usefilebuffers {\let\startbuffer\dostartfilebuffer}
+
+% this features is soldom used (complex examns where we need to fetch
+% special parts of a text
+%
+% this is not yet supported in mkiv (relatively easy to do but there
+% we don't have the par tags but need to grab 'm
+
+\def\skippedbufferparagraphs{0}
+
+\let\startbufferparagraph\relax
+\let\stopbufferparagraph \par % \relax
+
+\newcount\currentbufferparagraph
+
+\def\getbufferparagraphs
+ {\dodoubleempty\dogetbufferparagraphs}
+
+\def\dosetbufferoffset#1%
+ {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}
+ {\currentbufferparagraph-\getvalue{\??bu#1\c!paragraph}}
+ {\currentbufferparagraph \zerocount}%
+ \relax}
+
+\def\dogetbufferparagraphs[#1][#2]%
+ {\iffirstargument
+ \ifsecondargument
+ \dosetbufferoffset{#1}%
+ \doifelse{#2}\v!all
+ {\def\startbufferparagraph{\normalbufferparagraph{#1}}}
+ {\def\startbufferparagraph{\filterbufferparagraph{#1}{#2}}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{#1}}%
+ \def\next{\getparagraphedbuffer[#1]}%
+ \else
+ \dosetbufferoffset\empty
+ \def\startbufferparagraph{\filterbufferparagraph{}{#1}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{}}%
+ \def\next{\getparagraphedbuffer[]}%
+ \fi
+ \else
+ \dosetbufferoffset\empty
+ \def\startbufferparagraph{\normalbufferparagraph{}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{}}%
+ \def\next{\getparagraphedbuffer[]}%
+ \fi
+ \next}
+
+\def\dogetparagraphbuffer{\readjobfile{\TEXbufferfile{\currentbuffer}}\donothing\donothing}
+
+\def\getparagraphedbuffer[#1]%
+ {\dobuffer{16}{#1}\dogetparagraphbuffer}
+
+\def\dostopbufferparagraph#1%
+ {\getvalue{\??bu#1\c!after}\par}
+
+\def\dostartbufferparagraph#1%
+ {\par\getvalue{\??bu#1\c!before}}
+
+\def\normalbufferparagraph
+ {\advance\currentbufferparagraph \plusone
+ \ifnum\currentbufferparagraph>\zerocount
+ \expandafter\dostartbufferparagraph
+ \else
+ \expandafter\gobbleoneargument
+ \fi}
+
+\def\filterbufferparagraph#1#2%
+ {\advance\currentbufferparagraph \plusone
+ \ifcase\currentbufferparagraph
+ \@EA\gobblebufferparagraph
+ \else
+ \doifinsetelse{\the\currentbufferparagraph}{#2}
+ {\@EA\dostartbufferparagraph}
+ {\@EA\fakebufferparagraph}%
+ \fi
+ {#1}}
+
+\long\def\gobblebufferparagraph#1#2\stopbufferparagraph
+ {}
+
+\def\fakebufferparagraph#1%
+ {\bgroup
+ \def\stopbufferparagraph{\dostopbufferparagraph{#1}\egroup\egroup}%
+ \setbox\scratchbox\vbox\bgroup\dostartbufferparagraph{#1}}
+
+% definitions
+
+\definebuffer[\v!hiding] \setupbuffer[\v!hiding][\c!local=\v!yes]
+
+\setupbuffer
+ [\c!paragraph=\v!no,
+ \c!before=,
+ \c!after=]
+
\protect \endinput
diff --git a/tex/context/base/core-buf.mkiv b/tex/context/base/core-buf.mkiv
index c4f13839d..8b69616b9 100644
--- a/tex/context/base/core-buf.mkiv
+++ b/tex/context/base/core-buf.mkiv
@@ -11,75 +11,80 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-% this will become a proper new verbatim module
+\writestatus{loading}{ConTeXt Core Macros / Buffers}
+
+\registerctxluafile{core-buf}{1.001}
+
+\ifdefined\doinitializeverbatim \else% temp hack
+ \ifdefined\mkinitializeverbatim
+ \let\doinitializeverbatim\mkinitializeverbatim
+ \else
+ \def\doinitializeverbatim{\tttf}
+ \fi
+\fi
\unprotect
-\registerctxluafile{core-buf}{1.001}
+\chardef\buffernestmode\plusone % 0: not nested, 1: startbuffer nested, 2: all buffers nested
+
+\newif\ifsegmentatebuffer
+\newif\ifemptybufferline
-\def\mkresetbuffer
- {\ctxlua{buffers.erase("\currentbuffer")}}
+\def\currentbuffer{\jobname}
-\long\def\mksetbuffer#1%
- {\ctxlua{buffers.set("\currentbuffer", \!!bs\detokenize{#1}\!!es)}}
+\def\setcurrentbuffer#1%
+ {\doifelsenothing{#1}{\edef\currentbuffer{\jobname}}{\edef\currentbuffer{#1}}}
-\long\def\mkstartbuffer#1#2#3#4#5%
- {\doifelsenothing{#4}
- {\expanded{\setbuffercapsules{\e!start\v!buffer}{\e!stop\v!buffer}}%
+\def\resetbuffer
+ {\dosingleempty\doresetbuffer}
+
+\def\doresetbuffer[#1]%
+ {\begingroup
+ \setcurrentbuffer{#1}%
+ \ctxlua{buffers.erase("\currentbuffer")}%
+ \endgroup}
+
+\def\dostartbuffer
+ {\bgroup
+ \obeylines % nodig, anders gaat 't fout als direct \starttable (bv)
+ \doquadrupleempty\dodostartbuffer}
+
+\def\dodostartbuffer[#1][#2][#3][#4]% upward compatible
+ {\iffourthargument
+ \def\next{\dododostartbuffer{#1}{#2}{#3}{#4}}%
+ \else
+ \def\next{\dododostartbuffer {}{#1}{#2}{#3}}%
+ \fi
+ \next}
+
+\def\dododostartbuffer#1#2#3#4%
+ {%\showmessage\m!systems{15}{#2}%
+ \doifelsevalue{\??bu#1\c!paragraph}\v!yes
+ {\segmentatebuffertrue} % todo in mkiv
+ {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}\segmentatebuffertrue\segmentatebufferfalse}%
+ \doifvalue{\??bu#1\c!local}\v!yes
+ {\chardef\buffernestmode\plustwo}% permit nesting
+ \setcurrentbuffer{#2}%
+ \doifelsenothing{#4}
+ {\normalexpanded{\noexpand\setbuffercapsules{\e!start\v!buffer}{\e!stop\v!buffer}}%
\letvalue\bufferstop\relax}
%{\@EA\setbuffercapsules\@EA{\csname#3\@EA\endcsname\@EA}\@EA{\csname#4\endcsname}}% if we strip later
{\setbuffercapsules{#3}{#4}}%
- \expanded{\dodowithbuffer
+ \normalexpanded{\noexpand\dodowithbuffer
{\currentbuffer}
{\bufferstart}
{\bufferstop}
{\donothing}
- {#5% \egroup
+ {\egroup
\noexpand\getvalue{\bufferstop}}}}
-\def\mkdobuffer#1%
- {#1}
-
-\def\mkdoifelsebuffer#1%
- {\ctxlua{buffers.doifelsebuffer("#1")}}
-
-\def\mkgetbuffer
- {\ctxlua{buffers.get("\currentbuffer")}}
-
-% will move
-
-\ifx\mkinitializeverbatim\undefined \def\mkinitializeverbatim{\tttf} \fi
-
-\def\mktypebuffer
- {\mkdotypebuffer{\v!file}{}{\currentbuffer}}
-
-\def\mkprocessbufferverbatim
- {\mkinitializeverbatim
- \ctxlua{buffers.type("\currentbuffer")}}
-
-\def\mkprocessbufferlinesverbatim#1#2#3%
- {#2%
- % todo, set up numbers
- \mkinitializeverbatim
- \ctxlua{buffers.type("\currentbuffer")}
- #3}
-
-\def\mkdotypebuffer#1#2#3% see dodotypefile
- {\mkdoifelsebuffer{#3}
- {\dosometyping{#1}{#2}{#3}\mkprocessbufferverbatim\mkprocessbufferlinesverbatim}
- {\reporttypingerror{#3}}}
-
-% \def\setbuffercapsules#1#2%
-% {\edef\bufferstart{\strippedcsname#1}\edef\bufferstart{\scantextokens\expandafter{\bufferstart}}%
-% \edef\bufferstop {\strippedcsname#2}\edef\bufferstop {\scantextokens\expandafter{\bufferstop }}}
+\letvalue{\e!start\v!buffer}\dostartbuffer
-\def\setbuffercapsules#1#2% \scantextokens not needed (had a reason at some point)
- {\edef\bufferstart{#1}\edef\bufferstart{\scantextokens\expandafter{\bufferstart}}%
- \edef\bufferstop {#2}\edef\bufferstop {\scantextokens\expandafter{\bufferstop }}}
+\let\endbuffer\undefined % to please the dep parser
\def\dowithbuffer#1#2#3% name, startsequence, stopsequence, before, after
{\setbuffercapsules{#2}{#3}%
- \expanded{\dodowithbuffer{#1}{\bufferstart}{\bufferstop}}}
+ \normalexpanded{\noexpand\dodowithbuffer{#1}{\bufferstart}{\bufferstop}}}
\long\def\dodowithbuffer#1#2#3#4#5% name, startsequence, stopsequence, before, after
{#4%
@@ -97,12 +102,105 @@
\nododowithbuffer}%
\dododowithbuffer}
-% kind of redundant in mkiv
+\def\setbuffercapsules#1#2% \scantextokens not needed (had a reason at some point)
+ {\edef\bufferstart{#1}\edef\bufferstart{\scantextokens\expandafter{\bufferstart}}%
+ \edef\bufferstop {#2}\edef\bufferstop {\scantextokens\expandafter{\bufferstop }}}
+
+\def\setbuffer
+ {\dosingleempty\dosetbuffer}
+
+\long\def\dosetbuffer[#1]#2\endbuffer % seldom used so we just pass #2
+ {\begingroup
+ \setcurrentbuffer{#1}%
+ \ctxlua{buffers.set("\currentbuffer", \!!bs\detokenize{#2}\!!es)}%
+ \endgroup}
+
+\def\setupbuffer
+ {\dodoubleempty\dosetupbuffer}
+
+\def\dosetupbuffer[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??bu#1][#2]%
+ \else
+ \getparameters[\??bu][#1]%
+ \fi}
+
+\def\dodefinebuffer[#1][#2]%
+ {\iffirstargument % else problems
+ \doglobal\increment\nofdefinedbuffers
+ \letvalue{\??bu#1\c!number }\nofdefinedbuffers
+ \letvalue{\??bu#1\c!paragraph}\v!no
+ \setevalue{\e!start#1}{\noexpand\dostartbuffer[#1][def-\nofdefinedbuffers][\e!start#1][\e!stop#1]}%
+ \setevalue{\e!get #1}{\noexpand\dogetbuffer [#1][def-\nofdefinedbuffers]}%
+ \setevalue{\e!type #1}{\noexpand\dotypebuffer [#1][def-\nofdefinedbuffers]}%
+ \getparameters[\??bu#1][#2]%
+ \fi}
+
+\def\definebuffer
+ {\dodoubleempty\dodefinebuffer}
+
+\def\getbuffer
+ {\dodoubleempty\dogetbuffer}
+
+\def\dogetbuffer[#1][#2]%
+ {\ifsecondargument
+ \dodogetbuffer[#1][#2]%
+ \else
+ \dodogetbuffer[][#1]%
+ \fi}
-\let\mkstartmemorybuffer\startbuffer
-\let\mkstartfilebuffer \startbuffer
+\def\dogetbufferasis{\ctxlua{buffers.get("\currentbuffer")}}
-% bonus
+\def\dodogetbuffer[#1][#2]%
+ {\getvalue{\??bu#1\c!before}%
+ \dobuffer{16}{#2}\dogetbufferasis
+ \getvalue{\??bu#1\c!after}}
+
+\def\typebuffer
+ {\dodoubleempty\dotypebuffer}
+
+\def\doprocessbufferverbatim
+ {\doinitializeverbatim
+ \ctxlua{buffers.type("\currentbuffer")}}
+
+\def\doprocessbufferlinesverbatim#1#2#3%
+ {#2%
+ % todo, set up numbers
+ \doinitializeverbatim
+ \ctxlua{buffers.type("\currentbuffer")}
+ #3}
+
+\def\doifelsebuffer#1%
+ {\ctxlua{buffers.doifelsebuffer("#1")}}
+
+\def\dodotypebuffer#1#2#3% see dodotypefile
+ {\doifelsebuffer{#3}
+ {\dosometyping{#1}{#2}{#3}\doprocessbufferverbatim\doprocessbufferlinesverbatim}
+ {\reporttypingerror{#3}}}
+
+\def\dotypefilebuffer{\dodotypebuffer{\v!file}{}{\currentbuffer}}%
+
+\def\dotypebuffer[#1][#2]%
+ {\iffirstargument
+ \dobuffer{17}{#1}\dotypefilebuffer
+ \else
+ \dobuffer{17}{#2}\dotypefilebuffer
+ \fi}
+
+\def\dobuffer#1#2#3%
+ {\doifelsenothing{#2}
+ {\dodobuffer#3\jobname}
+ {\processcommalist[#2]{\dodobuffer#3}}}
+
+\def\dodobuffer#1#2% command name
+ {\pushmacro\currentbuffer
+ \edef\currentbuffer{\ifcsname\??bu#2\c!number\endcsname def-\csname\??bu#2\c!number\endcsname\else#2\fi}%
+ #1%
+ \popmacro\currentbuffer}
+
+\def\processTEXbuffer{\getbuffer} % handy
+
+% extras:
\def\inspectbuffer
{\dosingleempty\doinspectbuffer}
@@ -110,5 +208,107 @@
\def\doinspectbuffer[#1]%
{\setcurrentbuffer{#1}%
\ctxlua{buffers.inspect("\currentbuffer")}}
+
+% seldom used, only in a few projects that demanded more speed
+
+\let\usememorybuffers\relax
+\let\usefilebuffers \relax
+
+% this features is soldom used (complex examns where we need to fetch
+% special parts of a text
+%
+% this is not yet supported in mkiv (relatively easy to do but there
+% we don't have the par tags but need to grab 'm
+
+\def\skippedbufferparagraphs{0}
+
+\let\startbufferparagraph\relax
+\let\stopbufferparagraph \par % \relax
+
+\newcount\currentbufferparagraph
+
+\def\getbufferparagraphs
+ {\dodoubleempty\dogetbufferparagraphs}
+
+\def\dosetbufferoffset#1%
+ {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}
+ {\currentbufferparagraph-\getvalue{\??bu#1\c!paragraph}}
+ {\currentbufferparagraph \zerocount}%
+ \relax}
+
+\def\dogetbufferparagraphs[#1][#2]%
+ {\iffirstargument
+ \ifsecondargument
+ \dosetbufferoffset{#1}%
+ \doifelse{#2}\v!all
+ {\def\startbufferparagraph{\normalbufferparagraph{#1}}}
+ {\def\startbufferparagraph{\filterbufferparagraph{#1}{#2}}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{#1}}%
+ \def\next{\getparagraphedbuffer[#1]}%
+ \else
+ \dosetbufferoffset\empty
+ \def\startbufferparagraph{\filterbufferparagraph{}{#1}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{}}%
+ \def\next{\getparagraphedbuffer[]}%
+ \fi
+ \else
+ \dosetbufferoffset\empty
+ \def\startbufferparagraph{\normalbufferparagraph{}}%
+ \def\stopbufferparagraph{\dostopbufferparagraph{}}%
+ \def\next{\getparagraphedbuffer[]}%
+ \fi
+ \next}
+
+\def\dotypeparagraphbuffer{\ctxlua{buffers.get("\currentbuffer")}}
+
+\def\getparagraphedbuffer[#1]%
+ {\dobuffer{16}{#1}\dotypeparagraphbuffer}
+
+\def\dostopbufferparagraph#1%
+ {\getvalue{\??bu#1\c!after}\par}
+
+\def\dostartbufferparagraph#1%
+ {\par\getvalue{\??bu#1\c!before}}
+
+\def\normalbufferparagraph
+ {\advance\currentbufferparagraph \plusone
+ \ifnum\currentbufferparagraph>\zerocount
+ \expandafter\dostartbufferparagraph
+ \else
+ \expandafter\gobbleoneargument
+ \fi}
+
+\def\filterbufferparagraph#1#2%
+ {\advance\currentbufferparagraph \plusone
+ \ifcase\currentbufferparagraph
+ \@EA\gobblebufferparagraph
+ \else
+ \doifinsetelse{\the\currentbufferparagraph}{#2}
+ {\@EA\dostartbufferparagraph}
+ {\@EA\fakebufferparagraph}%
+ \fi
+ {#1}}
+
+\long\def\gobblebufferparagraph#1#2\stopbufferparagraph
+ {}
+
+\def\fakebufferparagraph#1%
+ {\bgroup
+ \def\stopbufferparagraph{\dostopbufferparagraph{#1}\egroup\egroup}%
+ \setbox\scratchbox\vbox\bgroup\dostartbufferparagraph{#1}}
+
+% definitions
+
+\definebuffer[\v!hiding] \setupbuffer[\v!hiding][\c!local=\v!yes]
+
+\setupbuffer
+ [\c!paragraph=\v!no,
+ \c!before=,
+ \c!after=]
+
+% only mkiv:
+
+\def\savebuffer{\dosingleempty\dosavebuffer}
+\def\dosavebuffer[#1]{\ctxlua{buffers.save("#1")}}
\protect \endinput
diff --git a/tex/context/base/core-buf.tex b/tex/context/base/core-buf.tex
deleted file mode 100644
index efc0b7973..000000000
--- a/tex/context/base/core-buf.tex
+++ /dev/null
@@ -1,250 +0,0 @@
-%D \module
-%D [ file=core-buf, % blocks are moved to core-blk
-%D version=2000.01.05,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Buffers,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Buffers}
-
-\unprotect
-
-\let\mkresetbuffer \donothing
-\let\mksetbuffer \gobbleoneargument
-\let\mkstartbuffer \gobblefivearguments
-\let\mkdobuffer \gobbleoneargument
-\let\mkstartmemorybuffer\startbuffer
-\let\mkstartfilebuffer \startbuffer
-\let\mkgetbuffer \donothing
-\let\mktypebuffer \donothing
-
-\chardef\buffernestmode\plusone % 0: not nested, 1: startbuffer nested, 2: all buffers nested
-
-\newif\ifsegmentatebuffer
-\newif\ifemptybufferline
-
-\def\currentbuffer{\jobname}
-
-\def\setcurrentbuffer#1%
- {\doifelsenothing{#1}{\edef\currentbuffer{\jobname}}{\edef\currentbuffer{#1}}}
-
-\def\resetbuffer
- {\dosingleempty\doresetbuffer}
-
-\def\doresetbuffer[#1]%
- {\begingroup
- \setcurrentbuffer{#1}%
- \mkresetbuffer
- \endgroup}
-
-\def\dostartbuffer
- {\bgroup
- \obeylines % nodig, anders gaat 't fout als direct \starttable (bv)
- \doquadrupleempty\dodostartbuffer}
-
-\def\dodostartbuffer[#1][#2][#3][#4]% upward compatible
- {\iffourthargument
- \def\next{\dododostartbuffer{#1}{#2}{#3}{#4}}%
- \else
- \def\next{\dododostartbuffer {}{#1}{#2}{#3}}%
- \fi
- \next}
-
-\def\dododostartbuffer#1#2#3#4%
- {%\showmessage\m!systems{15}{#2}%
- \doifelsevalue{\??bu#1\c!paragraph}\v!yes
- {\segmentatebuffertrue} % todo in mkiv
- {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}\segmentatebuffertrue\segmentatebufferfalse}%
- \doifvalue{\??bu#1\c!local}\v!yes
- {\chardef\buffernestmode\plustwo}% permit nesting
- \setcurrentbuffer{#2}%
- \mkstartbuffer{#1}{#2}{#3}{#4}{\egroup}}
-
-\letvalue{\e!start\v!buffer}\dostartbuffer
-
-\let\endbuffer\undefined % to please the dep parser
-
-\def\setbuffer
- {\dosingleempty\dosetbuffer}
-
-\def\dosetbuffer[#1]#2\endbuffer % seldom used so we just pass #2
- {\begingroup
- \setcurrentbuffer{#1}%
- \mksetbuffer{#2}%
- \endgroup}
-
-\def\setupbuffer
- {\dodoubleempty\dosetupbuffer}
-
-\def\dosetupbuffer[#1][#2]%
- {\ifsecondargument
- \getparameters[\??bu#1][#2]%
- \else
- \getparameters[\??bu][#1]%
- \fi}
-
-\def\dodefinebuffer[#1][#2]%
- {\iffirstargument % else problems
- \doglobal\increment\nofdefinedbuffers
- \letvalue{\??bu#1\c!number }\nofdefinedbuffers
- \letvalue{\??bu#1\c!paragraph}\v!no
- \setevalue{\e!start#1}{\noexpand\dostartbuffer[#1][def-\nofdefinedbuffers][\e!start#1][\e!stop#1]}%
- \setevalue{\e!get #1}{\noexpand\dogetbuffer [#1][def-\nofdefinedbuffers]}%
- \setevalue{\e!type #1}{\noexpand\dotypebuffer [#1][def-\nofdefinedbuffers]}%
- \getparameters[\??bu#1][#2]%
- \fi}
-
-\def\definebuffer
- {\dodoubleempty\dodefinebuffer}
-
-\def\getbuffer
- {\dodoubleempty\dogetbuffer}
-
-\def\dogetbuffer[#1][#2]%
- {\ifsecondargument
- \dodogetbuffer[#1][#2]%
- \else
- \dodogetbuffer[][#1]%
- \fi}
-
-\def\dodogetbuffer[#1][#2]%
- {\getvalue{\??bu#1\c!before}%
- \dobuffer{16}{#2}\mkgetbuffer
- \getvalue{\??bu#1\c!after}}
-
-\def\typebuffer
- {\dodoubleempty\dotypebuffer}
-
-\def\dotypebuffer[#1][#2]%
- {\iffirstargument
- \dobuffer{17}{#1}\mktypebuffer
- \else
- \dobuffer{17}{#2}\mktypebuffer
- \fi}
-
-\def\dobuffer#1#2#3%
- {\doifelsenothing{#2}
- {\dodobuffer#3\jobname}
- {\processcommalist[#2]{\dodobuffer#3}}}
-
-\def\dodobuffer#1#2% command name
- {\pushmacro\currentbuffer
- \edef\currentbuffer{\ifcsname\??bu#2\c!number\endcsname def-\csname\??bu#2\c!number\endcsname\else#2\fi}%
- \mkdobuffer#1%
- \popmacro\currentbuffer}
-
-\def\processTEXbuffer{\getbuffer} % handy
-
-% seldom used, only in a few projects that demanded more speed
-
-\def\usememorybuffers{\let\startbuffer\mkstartmemorybuffer}
-\def\usefilebuffers {\let\startbuffer\mkstartfilebuffer}
-
-% this features is soldom used (complex examns where we need to fetch
-% special parts of a text
-%
-% this is not yet supported in mkiv (relatively easy to do but there
-% we don't have the par tags but need to grab 'm
-
-\def\skippedbufferparagraphs{0}
-
-\let\startbufferparagraph\relax
-\let\stopbufferparagraph \par % \relax
-
-\newcount\currentbufferparagraph
-
-\def\getbufferparagraphs
- {\dodoubleempty\dogetbufferparagraphs}
-
-\def\dosetbufferoffset#1%
- {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}
- {\currentbufferparagraph-\getvalue{\??bu#1\c!paragraph}}
- {\currentbufferparagraph \zerocount}%
- \relax}
-
-\def\dogetbufferparagraphs[#1][#2]%
- {\iffirstargument
- \ifsecondargument
- \dosetbufferoffset{#1}%
- \doifelse{#2}\v!all
- {\def\startbufferparagraph{\normalbufferparagraph{#1}}}
- {\def\startbufferparagraph{\filterbufferparagraph{#1}{#2}}}%
- \def\stopbufferparagraph{\dostopbufferparagraph{#1}}%
- \def\next{\getparagraphedbuffer[#1]}%
- \else
- \dosetbufferoffset\empty
- \def\startbufferparagraph{\filterbufferparagraph{}{#1}}%
- \def\stopbufferparagraph{\dostopbufferparagraph{}}%
- \def\next{\getparagraphedbuffer[]}%
- \fi
- \else
- \dosetbufferoffset\empty
- \def\startbufferparagraph{\normalbufferparagraph{}}%
- \def\stopbufferparagraph{\dostopbufferparagraph{}}%
- \def\next{\getparagraphedbuffer[]}%
- \fi
- \next}
-
-\def\getparagraphedbuffer[#1]%
- {\dobuffer{16}{#1}\mkgetbuffer}
-
-\def\dostopbufferparagraph#1%
- {\getvalue{\??bu#1\c!after}\par}
-
-\def\dostartbufferparagraph#1%
- {\par\getvalue{\??bu#1\c!before}}
-
-\def\normalbufferparagraph
- {\advance\currentbufferparagraph \plusone
- \ifnum\currentbufferparagraph>\zerocount
- \expandafter\dostartbufferparagraph
- \else
- \expandafter\gobbleoneargument
- \fi}
-
-\def\filterbufferparagraph#1#2%
- {\advance\currentbufferparagraph \plusone
- \ifcase\currentbufferparagraph
- \@EA\gobblebufferparagraph
- \else
- \doifinsetelse{\the\currentbufferparagraph}{#2}
- {\@EA\dostartbufferparagraph}
- {\@EA\fakebufferparagraph}%
- \fi
- {#1}}
-
-\long\def\gobblebufferparagraph#1#2\stopbufferparagraph
- {}
-
-\def\fakebufferparagraph#1%
- {\bgroup
- \def\stopbufferparagraph{\dostopbufferparagraph{#1}\egroup\egroup}%
- \setbox\scratchbox\vbox\bgroup\dostartbufferparagraph{#1}}
-
-% only mkiv
-
-\beginLUATEX
- \def\savebuffer{\dosingleempty\dosavebuffer}
- \def\dosavebuffer[#1]{\ctxlua{buffers.save("#1")}}
-\endLUATEX
-
-% plugins
-
-\loadmarkfile{core-buf}
-
-% definitions
-
-\definebuffer[\v!hiding] \setupbuffer[\v!hiding][\c!local=\v!yes]
-
-\setupbuffer
- [\c!paragraph=\v!no,
- \c!before=,
- \c!after=]
-
-\protect \endinput
diff --git a/tex/context/base/core-con.lua b/tex/context/base/core-con.lua
index 20bfef32a..1b1657957 100644
--- a/tex/context/base/core-con.lua
+++ b/tex/context/base/core-con.lua
@@ -14,11 +14,25 @@ slower but look nicer this way.
Some code may move to a module in the language namespace.
--ldx]]--
-local texsprint, floor, mod, format, date, time = tex.sprint, math.floor, math.mod, string.format, os.date, os.time
+local utf = unicode.utf8
+
+local floor, mod, date, time, concat, format = math.floor, math.mod, os.date, os.time, table.concat, string.format
+local texsprint, utfchar = tex.sprint, utf.char
+
+local ctxcatcodes = tex.ctxcatcodes
converters = converters or { }
languages = languages or { }
+--~ ['arabic-digits'] = {
+--~ 0x0660, 0x0661, 0x0662, 0x0663, 0x0664,
+--~ 0x0665, 0x0666, 0x0667, 0x0668, 0x0669
+--~ },
+--~ ['persian-digits'] = {
+--~ 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4,
+--~ 0x06F5, 0x06F6, 0x06F7, 0x06F8, 0x06F9
+--~ },
+
languages.counters = {
['**'] = {
0x0061, 0x0062, 0x0063, 0x0064, 0x0065,
@@ -43,12 +57,20 @@ languages.counters = {
0x03A6, 0x03A7, 0x03A8, 0x03A9
},
['arabic'] = {
- 0x0660, 0x0661, 0x0662, 0x0663, 0x0664,
- 0x0665, 0x0666, 0x0667, 0x0668, 0x0669
+ 0x0627, 0x0628, 0x062C, 0x062F, 0x0647,
+ 0x0648, 0x0632, 0x062D, 0x0637, 0x0649,
+ 0x0643, 0x0644, 0x0645, 0x0646, 0x0633,
+ 0x0639, 0x0641, 0x0635, 0x0642, 0x0631,
+ 0x0634, 0x062A, 0x062B, 0x062E, 0x0630,
+ 0x0636, 0x0638, 0x063A,
},
['persian'] = {
- 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4,
- 0x06F5, 0x06F6, 0x06F7, 0x06F8, 0x06F9
+ 0x0627, 0x0628, 0x062C, 0x062F, 0x0647,
+ 0x0648, 0x0632, 0x062D, 0x0637, 0x0649,
+ 0x06A9, 0x0644, 0x0645, 0x0646, 0x0633,
+ 0x0639, 0x0641, 0x0635, 0x0642, 0x0631,
+ 0x0634, 0x062A, 0x062B, 0x062E, 0x0630,
+ 0x0636, 0x0638, 0x063A,
},
['thai'] = {
0xE050, 0xE051, 0xE052, 0xE053, 0xE054,
@@ -69,16 +91,34 @@ languages.counters = {
['tibetan'] = {
0x0F20, 0x0F21, 0x0F22, 0x0F23, 0x0F24,
0x0F25, 0x0F26, 0x0F27, 0x0F28, 0x0F29
- }
+ },
+ ['korean'] = {
+ 0x3131, 0x3134, 0x3137, 0x3139, 0x3141,
+ 0x3142, 0x3145, 0x3147, 0x3148, 0x314A,
+ 0x314B, 0x314C, 0x314D, 0x314E
+ },
+ ['korean-parent'] = { -- parenthesed
+ 0x3200, 0x3201, 0x3202, 0x3203, 0x3204,
+ 0x3205, 0x3206, 0x3207, 0x3208, 0x3209,
+ 0x320A, 0x320B, 0x320C, 0x320D
+ },
+ ['korean-circle'] = { -- circled
+ 0x3260, 0x3261, 0x3262, 0x3263, 0x3264,
+ 0x3265, 0x3266, 0x3267, 0x3268, 0x3269,
+ 0x326A, 0x326B, 0x326C, 0x326D
+ },
}
local counters = languages.counters
-counters['gr'] = counters['greek']
-counters['g'] = counters['greek']
-counters['sl'] = counters['slovenian']
+counters['ar'] = counters['arabic']
+counters['gr'] = counters['greek']
+counters['g'] = counters['greek']
+counters['sl'] = counters['slovenian']
+counters['kr'] = counters['korean']
+counters['kr-p'] = counters['korean-parent']
+counters['kr-c'] = counters['korean-circle']
-local utfchar = utf.char
local fallback = utf.byte('0')
function converters.chr(n,m)
@@ -92,7 +132,7 @@ function converters.maxchrs(n,m,cmd)
converters.maxchrs(floor((n-1)/m),m,cmd)
n = (n-1)%m + 1
end
- texsprint(tex.ctxcatcodes, format("%s{%s}",cmd,n))
+ texsprint(ctxcatcodes, format("%s{%s}",cmd,n))
end
function converters.chrs(n,m)
if n > 26 then
@@ -219,3 +259,222 @@ end
function converters.abjadnumerals (n) return texsprint(converters.toabjad(n,false)) end
function converters.abjadnodotnumerals(n) return texsprint(converters.toabjad(n,true)) end
+
+local vector = {
+ normal = {
+ [0] = "○",
+ [1] = "一",
+ [2] = "二",
+ [3] = "三",
+ [4] = "四",
+ [5] = "五",
+ [6] = "六",
+ [7] = "七",
+ [8] = "八",
+ [9] = "九",
+ [10] = "十",
+ [100] = "百",
+ [1000] = "千",
+ [10000] = "万",
+ [100000000] = "亿",
+ },
+ cap = {
+ [0] = "零",
+ [1] = "壹",
+ [2] = "贰",
+ [3] = "叁",
+ [4] = "肆",
+ [5] = "伍",
+ [6] = "陆",
+ [7] = "柒",
+ [8] = "捌",
+ [9] = "玖",
+ [10] = "拾",
+ [100] = "佰",
+ [1000] = "仟",
+ [10000] = "萬",
+ [100000000] = "亿",
+ },
+ all = {
+ [0] = "○",
+ [1] = "一",
+ [2] = "二",
+ [3] = "三",
+ [4] = "四",
+ [5] = "五",
+ [6] = "六",
+ [7] = "七",
+ [8] = "八",
+ [9] = "九",
+ [10] = "十",
+ [20] = "廿",
+ [30] = "卅",
+ [100] = "百",
+ [1000] = "千",
+ [10000] = "万",
+ [100000000] = "亿",
+ }
+}
+
+function tochinese(n,name) -- normal, caps, all
+ local result = { }
+ local vector = vector[name] or vector.normal
+ while true do
+ if n == 0 then
+ break
+ elseif n >= 100000000 then
+ local m = floor(n/100000000)
+ if m > 1 then result[#result+1] = tochinese(m) end
+ result[#result+1] = vector[100000000]
+ n = n % 100000000
+ elseif n >= 10000000 then
+ result[#result+1] = tochinese(floor(n/10000))
+ result[#result+1] = vector[10000]
+ n = n % 10000
+ elseif n >= 1000000 then
+ result[#result+1] = tochinese(floor(n/10000))
+ result[#result+1] = vector[10000]
+ n = n % 10000
+ elseif n >= 100000 then
+ result[#result+1] = tochinese(floor(n/10000))
+ result[#result+1] = vector[10000]
+ n = n % 10000
+ elseif n >= 10000 then
+ local m = floor(n/10000)
+ if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[10000]
+ n = n % 10000
+ elseif n >= 1000 then
+ local m = floor(n/1000)
+ if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[1000]
+ n = n % 1000
+ elseif n >= 100 then
+ local m = floor(n/100)
+ if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[100]
+ n = n % 100
+ elseif n >= 10 then
+ local m = floor(n/10)
+ if vector[m*10] then
+ result[#result+1] = vector[m*10]
+ else
+ result[#result+1] = vector[m]
+ result[#result+1] = vector[10]
+ end
+ n = n % 10
+ else
+ result[#result+1] = vector[n]
+ break
+ end
+ end
+ return concat(result)
+end
+
+--~ for k, v in ipairs { 1,10,15,25,35,45,11,100,111,1111,10000,11111,100000,111111,1111111,11111111,111111111,100000000,1111111111,11111111111,111111111111,1111111111111 } do
+--~ print(v,tochinese(v),tochinese(v,"all"),tochinese(v,"cap"))
+--~ end
+
+function converters.chinesenumerals (n) return texsprint(tochinese(n,"normal")) end
+function converters.chinesecapnumerals(n) return texsprint(tochinese(n,"cap" )) end
+function converters.chineseallnumerals(n) return texsprint(tochinese(n,"all" )) end
+
+--~ Well, since the one asking for this didn't test it the following code is not
+--~ enabled.
+--~
+--~ -- This Lua version is based on a Javascript by Behdad Esfahbod which in turn
+--~ -- is based on GPL'd code by Roozbeh Pournader of the The FarsiWeb Project
+--~ -- Group: http://www.farsiweb.info/jalali/jalali.js.
+--~ --
+--~ -- We start tables at one, I kept it zero based in order to stay close to
+--~ -- the original.
+--~ --
+--~ -- Conversion by Hans Hagen
+--~
+--~ local g_days_in_month = { [0]=31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+--~ local j_days_in_month = { [0]=31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 }
+--~
+--~ local function div(a,b)
+--~ return math.floor(a/b)
+--~ end
+--~
+--~ local function remainder(a,b)
+--~ return a - div(a,b)*b
+--~ end
+--~
+--~ function gregorian_to_jalali(gy,gm,gd)
+--~ local jy, jm, jd, g_day_no, j_day_no, j_np, i
+--~ gy, gm, gd = gy - 1600, gm - 1, gd - 1
+--~ g_day_no = 365*gy + div((gy+3),4) - div((gy+99),100) + div((gy+399),400)
+--~ i = 0
+--~ while i < gm do
+--~ g_day_no = g_day_no + g_days_in_month[i]
+--~ i = i + 1
+--~ end
+--~ if (gm>1 and ((gy%4==0 and gy%100~=0) or (gy%400==0))) then
+--~ g_day_no = g_day_no + 1
+--~ end
+--~ g_day_no = g_day_no + gd
+--~ j_day_no = g_day_no - 79
+--~ j_np = div(j_day_no,12053)
+--~ j_day_no = remainder(j_day_no,12053)
+--~ jy = 979 + 33*j_np + 4*div(j_day_no,1461)
+--~ j_day_no = remainder(j_day_no,1461)
+--~ if j_day_no >= 366 then
+--~ jy = jy + div((j_day_no-1),365)
+--~ j_day_no = remainder((j_day_no-1),365)
+--~ end
+--~ i = 0
+--~ while i < 11 and j_day_no >= j_days_in_month[i] do
+--~ j_day_no = j_day_no - j_days_in_month[i]
+--~ i = i + 1
+--~ end
+--~ jm = i + 1
+--~ jd = j_day_no + 1
+--~ return jy, jm, jd
+--~ end
+--~
+--~ function jalali_to_gregorian(jy,jm,jd)
+--~ local gy, gm, gd, g_day_no, j_day_no, leap, i
+--~ jy, jm, jd = jy - 979, jm - 1, jd - 1
+--~ j_day_no = 365*jy + div(jy,33)*8 + div((remainder(jy,33)+3),4)
+--~ i = 0
+--~ while i < jm do
+--~ j_day_no = j_day_no + j_days_in_month[i]
+--~ i = i + 1
+--~ end
+--~ j_day_no = j_day_no + jd
+--~ g_day_no = j_day_no + 79
+--~ gy = 1600 + 400*div(g_day_no,146097)
+--~ g_day_no = remainder (g_day_no, 146097)
+--~ leap = 1
+--~ if g_day_no >= 36525 then
+--~ g_day_no = g_day_no - 1
+--~ gy = gy + 100*div(g_day_no,36524)
+--~ g_day_no = remainder (g_day_no, 36524)
+--~ if g_day_no >= 365 then
+--~ g_day_no = g_day_no + 1
+--~ else
+--~ leap = 0
+--~ end
+--~ end
+--~ gy = gy + 4*div(g_day_no,1461)
+--~ g_day_no = remainder (g_day_no, 1461)
+--~ if g_day_no >= 366 then
+--~ leap = 0
+--~ g_day_no = g_day_no - 1
+--~ gy = gy + div(g_day_no, 365)
+--~ g_day_no = remainder(g_day_no, 365)
+--~ end
+--~ i = 0
+--~ while g_day_no >= g_days_in_month[i] + ((i == 1 and leap) or 0) do
+--~ g_day_no = g_day_no - g_days_in_month[i] + ((i == 1 and leap) or 0)
+--~ i = i + 1
+--~ end
+--~ gm = i + 1
+--~ gd = g_day_no + 1
+--~ return gy, gm, gd
+--~ end
+--~
+--~ print(gregorian_to_jalali(2009,02,24))
+--~ print(jalali_to_gregorian(1387,12,06))
diff --git a/tex/context/base/core-con.mkii b/tex/context/base/core-con.mkii
index d9347b475..c39bdd9d4 100644
--- a/tex/context/base/core-con.mkii
+++ b/tex/context/base/core-con.mkii
@@ -2,7 +2,7 @@
%D [ file=core-con,
%D version=1997.26.08,
%D title=\CONTEXT\ Core Macros,
-%D subtitle=Conversion Macros,
+%D subtitle=Conversion,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,8 +11,67 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Conversion}
+
\unprotect
+\ifx\currentlanguage\undefined \let\currentlanguage\empty \fi
+\ifx\labeltext \undefined \let\labeltext\firstofoneargument \fi
+
+%D This module deals with all kind of conversions from numbers
+%D and dates. I considered splitting this module in a support
+%D one and a core one, but to keep things simple as well as
+%D preserve the overview, I decided against splitting.
+
+\let\spr\firstofoneargument % separator
+\let\stp\firstofoneargument % stopper
+
+% cleaner, some day:
+%
+% \def\isolateseparators % etex only, even works with list separator overloading
+% {\unexpanded\def\spr##1{{##1}}%
+% \unexpanded\def\stp##1{{##1}}}
+
+% needed for arab :
+
+\def\isolateseparators % even works with list separator overloading
+ {\def\spr##1{{##1}}%
+ \def\stp##1{{##1}}}
+
+%D \macros
+%D {numbers}
+%D
+%D First we deal with the dummy conversion of numbers using the
+%D \TEX\ primitive \type{\number}. The uppercase alternative is
+%D only there for compatibility with the other conversion
+%D macros. We could do without \type{#1} but this way we get
+%D rid of unwanted braces. For the savety we also define a
+%D non||sence uppercase alternative.
+%D
+%D \showsetup{numbers}
+%D
+%D \starttyping
+%D \def\numbers#1{\number#1}
+%D \def\Numbers#1{\number#1}
+%D \stoptyping
+%D
+%D Due to read ahead, as in \type{[\pagenumber\space]} the space will
+%D disappear, unless we use:
+
+\def\numbers#1{\purenumber{#1}}
+\def\Numbers#1{\purenumber{#1}}
+
+%D \macros
+%D {romannumerals,Romannumerals}
+%D
+%D \TEX\ the program uses a rather tricky conversion from
+%D numbers to their roman counterparts. This conversion could
+%D of course be programmed in \TEX\ itself, but I guess Knuth
+%D found the programming trick worth presenting.
+%D
+%D \showsetup{romannumerals}
+%D \showsetup{Romannumerals}
+
%D When upcasing the result, we just follow the text book rules
%D of expansion. Later on we'll see some more uppercase tricks.
@@ -50,6 +109,24 @@
\uppercase\expandafter{\romannumeral#1#2}%
\fi\fi\fi\fi}
+%D \macros
+%D {character,Character}
+%D
+%D Converting a number into a character can of course only
+%D be done with numbers less or equal to~26. At the cost of
+%D much more macros a faster conversion is possible, using:
+%D
+%D \starttyping
+%D \setvalue{char1}{a} \def\character#1{\getvalue{char#1}}
+%D \stoptyping
+%D
+%D But we prefer a simpel \type{\case}.
+%D
+%D \showsetup{character}
+%D \showsetup{Character}
+
+\def\unknowncharacter{-} % else in lists \relax
+
%D Big case statements but pretty fast:
\def\character#1%
@@ -68,6 +145,38 @@
\unknowncharacter
\fi}
+%D \macros
+%D {characters,Characters}
+%D
+%D Converting large numbers is supported by the next two
+%D macros. This time we just count on: $\cdots$~x, y, z, aa,
+%D ab, ac~$\cdots$.
+%D
+%D \showsetup{characters}
+%D \showsetup{Characters}
+
+%D The fully expandable alternative:
+
+\def\dodoconvertcharacters#1#2#3%
+ {\ifcase#3\else
+ \ifnum#3>#1
+ \expandafter\doconvertcharacters\expandafter#2\expandafter{\the\numexpr(#3+12)/#1-1\relax}%
+ \expandafter#2\expandafter{\the\numexpr#3-((#3+12)/#1-1)*#1\relax}%
+ \else
+ \expandafter#2\expandafter{\number#3}%
+ \fi
+ \fi}
+
+\def\doconvertcharacters{\dodoconvertcharacters{26}}
+
+\def\characters{\doconvertcharacters\character}
+\def\Characters{\doconvertcharacters\Character}
+
+%D \macros
+%D {greeknumerals,Greeknumerals}
+%D
+%D Why should we only honour the romans, and not the greek?
+
\def\greeknumerals#1%
{% no longer needed: \mathematics
{\ifcase#1\unknowncharacter\or
@@ -94,22 +203,115 @@
\unknowncharacter
\fi}}
-%D The fully expandable alternative:
+%D \macros
+%D {oldstylenumerals,oldstyleromannumerals}
+%D
+%D These conversions are dedicated to Frans Goddijn.
-\def\dodoconvertcharacters#1#2#3%
- {\ifcase#3\else
- \ifnum#3>#1
- \expandafter\doconvertcharacters\expandafter#2\expandafter{\the\numexpr(#3+12)/#1-1\relax}%
- \expandafter#2\expandafter{\the\numexpr#3-((#3+12)/#1-1)*#1\relax}%
- \else
- \expandafter#2\expandafter{\number#3}%
- \fi
+\unexpanded\def\oldstylenumerals#1%
+ {{\os\number#1}}
+
+\unexpanded\def\oldstyleromannumerals#1%
+ {{\leftrulefalse\rightrulefalse\ss\txx\boxrulewidth.15ex
+ \ruledhbox spread .15em{\hss\uppercased{\romannumerals{#1}}\hss}}}
+
+%D \macros
+%D {protectconversion}
+%D
+%D The previous two commands are not robust enough to be
+%D passed to \type{\write} en \type{\message}. That's why we
+%D introduce:
+
+\def\protectconversion
+ {\def\doconvertcharacters##1{##1}} % was \relax
+ %{\def\doconvertcharacters##1{\ifcase0##1 0\else##1\fi}} more save
+
+%D \macros
+%D {normaltime,normalyear,normalmonth,normalday}
+%D
+%D The last part of this module is dedicated to converting
+%D dates. Because we want to use as meaningful commands as
+%D possible, and because \TEX\ already uses up some of those,
+%D we save the original meanings.
+
+\savenormalmeaning\time
+\savenormalmeaning\year
+\savenormalmeaning\month
+\savenormalmeaning\day
+
+%D \macros
+%D {month,MONTH}
+%D
+%D Converting the month number into a month name is done
+%D using a case statement, abstact values and the label
+%D mechanism. This way users can easily redefine a label from
+%D for instance german into austrian.
+%D
+%D \starttyping
+%D \setuplabeltext [de] [january=J\"anner]
+%D \stoptyping
+%D
+%D Anyhow, the conversion looks like:
+
+\def\domonthtag#1%
+ {\ifcase#1%
+ \or \v!january \or \v!february \or \v!march \or \v!april
+ \or \v!may \or \v!june \or \v!july \or \v!august
+ \or \v!september \or \v!october \or \v!november \or \v!december
+ \else
+ \v!unknown
\fi}
-\def\doconvertcharacters{\dodoconvertcharacters{26}}
+\def\doconvertmonthlong #1{\labeltext{\domonthtag{#1}}}
+\def\doconvertmonthshort#1{\labeltext{\domonthtag{#1}:\s!mnem}}
-\def\characters{\doconvertcharacters\character}
-\def\Characters{\doconvertcharacters\Character}
+\let\doconvertmonth\doconvertmonthlong
+
+%D We redefine the \TEX\ primitive \type{\month} as:
+%D
+%D \showsetup{month}
+%D \showsetup{MONTH}
+
+\def\monthlong {\doconvertmonthlong}
+\def\monthshort{\doconvertmonthshort}
+\def\month {\doconvertmonth}
+
+\def\MONTH #1{{\let\labeltext\LABELTEXT\month {#1}}}
+\def\MONTHLONG #1{{\let\labeltext\LABELTEXT\monthlong {#1}}}
+\def\MONTHSHORT#1{{\let\labeltext\LABELTEXT\monthshort{#1}}}
+
+%D We never explicitly needed this, but Tobias Burnus pointed
+%D out that it would be handy to convert to the day of the
+%D week. In doing so, we have to calculate the total number of
+%D days, taking leapyears into account. For those who are
+%D curious:
+%D
+%D \startitemize[packed]
+%D \item years that can be divided by 4 are leapyears
+%D \item exept years that can be divided by 100
+%D \item unless years can be divided by 400
+%D \stopitemize
+%D
+%D This makes the year 1900 into a normal year and 1996 and
+%D 2000 into leap years, right? Well, converting to string
+%D looks familiar:
+
+\def\doconvertday#1%
+ {\labeltext
+ {\ifcase#1
+ \or \v!sunday \or \v!monday \or \v!tuesday \or \v!wednesday
+ \or \v!thursday \or \v!friday \or \v!saturday \fi}}
+
+%D \macros
+%D {getdayoftheweek, dayoftheweek}
+%D
+%D The conversion algoritm is an old one and a translation from
+%D a procedure written in MODULA~2 back in the 80's. I finaly
+%D found the 4--100-400 rules in some enclopedia. Look at this
+%D messy low level routine that takes the day, month and year
+%D as arguments:
+
+\newcount\normalweekday
\def\getdayoftheweek#1#2#3%
{\bgroup
@@ -140,6 +342,77 @@
\def\dayoftheweek#1#2#3%
{\getdayoftheweek{#1}{#2}{#3}\doconvertday{\normalweekday}}
+%D Using this macro in
+%D
+%D \startbuffer
+%D monday: \dayoftheweek {4} {5} {1992}
+%D friday: \dayoftheweek {16} {6} {1995}
+%D monday: \dayoftheweek {25} {8} {1997}
+%D saturday: \dayoftheweek {30} {8} {1997}
+%D tuesday: \dayoftheweek {2} {1} {1996}
+%D tuesday: \dayoftheweek {7} {1} {1997}
+%D tuesday: \dayoftheweek {13} {1} {1998}
+%D friday: \dayoftheweek {1} {1} {2000}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D gives
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D The macro \type {\getdayoftheweek} can be used to calculate
+%D the number \type {\normalweekday}.
+
+%D \macros
+%D {weekday,WEEKDAY}
+%D
+%D The first one is sort of redundant. It takes the day
+%D number argument.
+%D
+%D \showsetup{weekday}
+%D \showsetup{WEEKDAY}
+
+\def\weekday
+ {\doconvertday}
+
+\def\WEEKDAY#1%
+ {{\let\labeltext\LABELTEXT\doconvertday{#1}}}
+
+%D \macros
+%D {weekoftheday}
+%D
+%D {\em not yet implemented:}
+%D
+%D \starttyping
+%D \def\weekoftheday#1#2#3%
+%D {}
+%D \stoptyping
+
+%D \macros
+%D {doifleapyearelse,
+%D getdayspermonth}
+%D
+%D Sometimes we need to know if we're dealing with a
+%D leapyear, so here is a testmacro:
+%D
+%D \starttyping
+%D \doifleapyearelse{year}{yes}{no}
+%D \stoptyping
+%D
+%D An example of its use can be seen in the macro
+%D
+%D \starttyping
+%D \getdayspermonth{year}{month}
+%D \stoptyping
+%D
+%D The number of days is available in the macro \type
+%D {\numberofdays}.
+
\def\doifleapyearelse#1% #2#3%
{\bgroup
\!!doneafalse
@@ -185,12 +458,450 @@
{\ifcase#2 \or31\or\numberofdays\or31\or30\or
31\or30\or31\or31\or30\or31\or30\or31\fi}}
+%D \macros
+%D {currentdate, date}
+%D
+%D We use these conversion macros in the date formatting
+%D macro:
+%D
+%D \showsetup{currentdate}
+%D
+%D This macro takes care of proper spacing and delivers for
+%D instance:
+%D
+%D \startbuffer
+%D \currentdate[weekday,day,month,year] % still dutch example
+%D \currentdate[WEEKDAY,day,MONTH,year] % still dutch example
+%D \stopbuffer
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D depending of course on the keywords. Here we gave:
+%D
+%D \typebuffer
+%D
+%D If needed one can also add non||keywords, like in
+%D
+%D \startbuffer
+%D \currentdate[dd,--,mm,--,yy]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or typeset: \getbuffer.
+%D
+%D When no argument is passed, the current date is given as
+%D specified per language (using \type{\installlanguage}).
+%D
+%D \showsetup{currentdate}
+%D
+%D \startbuffer
+%D \date
+%D \date[d=12,m=12,y=1998][weekday]
+%D \date[d=12,m=12,y=1998]
+%D \stopbuffer
+%D
+%D We can also typeset arbitrary dates, using the previous
+%D command.
+%D
+%D \typebuffer
+%D
+%D The date is specified by one character keys. When no date
+%D is given, we get the current date.
+%D
+%D \startlines
+%D \getbuffer
+%D \stoplines
+
+\def\kenmerkdatumpatroon{j,mm,dd} % jj,mm,dd changed at januari 1-1-2000
+
+\newsignal\datesignal
+
+\def\dobetweendates
+ {\ifdim\lastskip=\datesignal\relax\else
+ \unskip\space
+ \hskip\datesignal\relax
+ \fi}
+
+\newtoks \everycurrentdate
+
+\def\complexcurrentdate[#1]%
+ {\bgroup
+ \the\everycurrentdate
+ \def\betweendates{\let\betweendates\dobetweendates}%
+ % was \processcommacommandp[#1]\docomplexcurrentdate
+ \safeedef\ascii{\empty#1}% keep encoded chars
+ \@EA\processcommalist\@EA[\ascii]\docomplexcurrentdate
+ \ifdim\lastskip=\datesignal\relax
+ \unskip
+ \fi
+ \egroup}
+
+\def\docomplexcurrentdate#1%
+ {\lowercase{\edef\!!stringa{#1}}% permits usage in \smallcapped
+ \expanded{\processaction[\!!stringa]}% [#1]
+ [ \v!day=>\betweendates\the\normalday,
+ %\v!day+=>\betweendates\ordinaldaynumber\normalday,
+ \v!day+=>\betweendates\convertnumber{\v!day+}\normalday,
+ \v!month=>\betweendates\month\normalmonth,
+ \v!year=>\betweendates\the\normalyear,
+ \v!space=>\unskip\ \hskip\datesignal,% optimization -)
+ \ =>\unskip\ \hskip\datesignal,% optimization -)
+ d=>\convertnumber\v!day\normalday,
+ %d+=>\ordinaldaynumber\normalday,
+ d+=>\convertnumber{\v!day+}\normalday,
+ m=>\convertnumber\v!month\normalmonth,
+ j=>\convertnumber\v!year\normalyear,
+ y=>\convertnumber\v!year\normalyear,
+ w=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
+ dd=>\ifnum\normalday >9 \else0\fi\the\normalday,
+ %dd+=>\ordinaldaynumber{\ifnum\normalday >9 \else0\fi\the\normalday},
+ dd+=>\convertnumber{\v!day+}{\ifnum\normalday >9 \else0\fi\the\normalday},
+ mm=>\ifnum\normalmonth>9 \else0\fi\the\normalmonth,
+ jj=>\expandafter\gobbletwoarguments\the\normalyear,
+ yy=>\expandafter\gobbletwoarguments\the\normalyear,
+ \v!weekday=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
+ \v!referral=>\expanded{\complexcurrentdate[\kenmerkdatumpatroon]},
+ \s!unknown=>\unskip
+ % #1 and not the lowercased \commalistelement, vietnamese has text
+ % {} because #1 can have comma, like: {\ ,}
+ {#1}%
+ \hskip\datesignal
+ \def\betweendates{\let\betweendates\dobetweendates}]}
+
+\def\simplecurrentdate
+ {\expanded{\complexcurrentdate[\currentdatespecification]}}
+
+\definecomplexorsimple\currentdate
+
+\def\dodate[#1][#2]%
+ {\bgroup
+ \iffirstargument
+ \getparameters[\??da][d=\normalday,m=\normalmonth,y=\normalyear,#1]%
+ \normalday \@@dad\relax
+ \normalmonth\@@dam\relax
+ \normalyear \@@day\relax
+ \ifsecondargument
+ \currentdate[#2]%
+ \else
+ \currentdate
+ \fi
+ \else
+ \currentdate
+ \fi
+ \egroup}
+
+\def\date
+ {\dodoubleempty\dodate}
+
+%D \macros
+%D {currenttime}
+%D
+%D The currenttime is actually the jobtime. You can specify
+%D a pattern similar to the previous date macro using the
+%D keys \type {h}, \type {m} and a separator.
+
\def\calculatecurrenttime
{\dosetdivision\time{60}\scratchcounter
\edef\currenthour {\ifnum\scratchcounter<10 0\fi \the\scratchcounter}%
\dosetmodulo \time{60}\scratchcounter
\edef\currentminute{\ifnum\scratchcounter<10 0\fi \the\scratchcounter}}
+\let\currenthour \!!plusone
+\let\currentminute\!!plusone
+
+\def\currenttimespecification{h,:,m}
+
+\def\complexcurrenttime[#1]%
+ {\calculatecurrenttime
+ \processallactionsinset[#1]
+ [h=>\currenthour,m=>\currentminute,\s!unknown=>\commalistelement]}
+
+\def\simplecurrenttime
+ {\expanded{\complexcurrenttime[\currenttimespecification]}}
+
+\definecomplexorsimple\currenttime
+
+%D Because we're dealing with dates, we also introduce a few
+%D day loops:
+%D
+%D \starttyping
+%D \processmonth{year}{month}{command}
+%D \processyear{year}{command}{before}{after}
+%D \stoptyping
+%D
+%D The counters \type {\normalyear}, \type {\normalmonth} and
+%D \type{\normalday} can be used for for date manipulations.
+
+\long\def\processmonth#1#2#3% year month command
+ {\bgroup
+ \getdayspermonth{#1}{#2}%
+ \dostepwiserecurse1\numberofdays1%
+ {\normalyear #1\relax
+ \normalmonth#2\relax
+ \normalday \recurselevel\relax
+ #3}%
+ \egroup}
+
+\def\lastmonth{12} % can be set to e.g. 1 when testing
+
+\long\def\processyear#1#2#3#4% year command before after
+ {\bgroup
+ \dorecurse\lastmonth
+ {\normalyear #1\relax
+ \normalmonth\recurselevel\relax
+ #3\processmonth\normalyear\normalmonth{#2}#4}%
+ \egroup}
+
+%D \macros
+%D {defineconversion, convertnumber}
+%D
+%D Conversion involves the macros that we implemented earlier
+%D in this module.
+%D
+%D \showsetup{defineconversion}
+%D \showsetup{convertnumber}
+%D
+%D We can feed this command with conversion macros as well as
+%D a set of conversion symbols. Both need a bit different
+%D treatment.
+%D
+%D \starttyping
+%D \defineconversion [roman] [\romannumerals]
+%D \defineconversion [set 1] [$\star$,$\bullet$,$\ast$]
+%D \stoptyping
+%D
+%D You can define a language dependent conversion with:
+%D
+%D \starttyping
+%D \defineconversion [en] [whatever] [\something]
+%D \stoptyping
+
+% \def\dodefineconversion[#1][#2]%
+% {\ConvertConstantAfter\doifinstringelse{,}{#2}
+% {\scratchcounter=0
+% \def\docommand##1%
+% {\advance\scratchcounter 1
+% \setvalue{\??cv#1\the\scratchcounter}{##1}}%
+% \processcommalist[#2]\docommand
+% \setvalue{\??cv#1}##1{\csname\??cv#1##1\endcsname}}
+% {\setvalue{\??cv#1}{#2}}}
+%
+% \def\defineconversion%
+% {\dodoubleargument\dodefineconversion}
+
+\def\defineconversion
+ {\dotripleempty\dodefineconversion}
+
+\def\dodefineconversion[#1][#2][#3]%
+ {\ifthirdargument
+ \dododefineconversion[#1][#2][#3]%
+ \else
+ \dododefineconversion[][#1][#2]%
+ \fi}
+
+%D \starttyping
+%D \def\dododefineconversion[#1][#2][#3]%
+%D {\ConvertConstantAfter\doifinstringelse{,}{#3}
+%D {\scratchcounter\zerocount
+%D \def\docommand##1%
+%D {\advance\scratchcounter \plusone
+%D \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
+%D \processcommalist[#3]\docommand
+%D \setvalue{\??cv#1#2}##1{\executeifdefined{\??cv#1#2##1}\unknown}} % catch out-of-range numbers
+%D {\setvalue{\??cv#1#2}{#3}}}
+%D \stoptyping
+
+%D This approach has the disadvantage that when you run out of
+%D symbols you get unknown results. The following implementation
+%D permits overloading of the converter:
+
+\def\dododefineconversion[#1][#2][#3]%
+ {\ConvertConstantAfter\doifinstringelse{,}{#3}
+ {\scratchcounter\zerocount
+ \def\docommand##1%
+ {\advance\scratchcounter \plusone
+ \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
+ \processcommalist[#3]\docommand
+ \setevalue{\??cv#1#2}##1%
+ {\noexpand\docheckedconversion{#1#2}{\the\scratchcounter}{##1}}}
+ {\setvalue{\??cv#1#2}{#3}}}
+
+\def\docheckedconversion#1#2#3% class maxnumber number
+ {\executeifdefined{\??cv#1#3}\unknown}
+
+%D When Gerben reported problems with footnote numbering per page,
+%D Taco came with the following wrap around solution. So, let's
+%D overload the checked conversion macro:
+
+\def\docheckedconversion#1#2#3% class maxnumber number
+ {\executeifdefined{\??cv#1\modulatednumber{#2}{#3}}\unknown}
+
+%D Taco's modulo code is implemented in the system module
+%D \type {syst-con}.
+
+%D If a conversion is just a font switch then we need to make sure
+%D that the number is indeed end up as number in the input, so we
+%D need to handle the second argument.
+
+\def\convertnumber#1#2%
+ {\csname\??cv
+ \ifcsname\??cv\currentlanguage#1\endcsname
+ \currentlanguage#1%
+ \else\ifcsname\??cv#1\endcsname
+ #1%
+ \else
+ \s!default
+ \fi\fi
+ \endcsname{\number#2}}
+
+\def\doifconversiondefinedelse#1%
+ {\ifcsname\??cv\currentlanguage#1\endcsname
+ \@EA\firstoftwoarguments
+ \else\ifcsname\??cv#1\endcsname
+ \@EAEAEA\firstoftwoarguments
+ \else
+ \@EAEAEA\secondoftwoarguments
+ \fi\fi}
+
+\def\doifelseconversionnumber#1#2% slow but seldom used
+ {\doifdefinedelse{\??cv#1#2}}
+
+%D Handy.
+
+\setvalue{\??cv:\c!n:\v!one }{1}
+\setvalue{\??cv:\c!n:\v!two }{2}
+\setvalue{\??cv:\c!n:\v!three}{3}
+\setvalue{\??cv:\c!n:\v!four }{4}
+\setvalue{\??cv:\c!n:\v!five }{5}
+
+\def\wordtonumber#1#2{\ifcsname\??cv:\c!n:#1\endcsname\csname\??cv:\c!n:#1\endcsname\else#2\fi}
+
+% \defineconversion[ctx][c,o,n,t,e,x,t]
+%
+% \doloop{\doifelseconversionnumber{ctx}{\recurselevel}{[\recurselevel]}{\exitloop}}
+
+\defineconversion [\s!default] [\numbers]
+
+%D As longs as symbols are linked to levels or numbers, we can
+%D also use the conversion mechanism, but in for instance the
+%D itemization macros, we prefer symbols because they can more
+%D easier be (partially) redefined. Symbols are implemented
+%D in another module.
+
+\defineconversion [] [\numbers] % the default conversion
+
+\defineconversion [a] [\characters]
+\defineconversion [A] [\Characters]
+\defineconversion [AK] [\smallcapped\characters]
+\defineconversion [KA] [\smallcapped\characters]
+
+\defineconversion [n] [\numbers]
+\defineconversion [N] [\Numbers]
+\defineconversion [m] [\mediaeval]
+
+\defineconversion [i] [\romannumerals]
+\defineconversion [I] [\Romannumerals]
+\defineconversion [r] [\romannumerals]
+\defineconversion [R] [\Romannumerals]
+\defineconversion [KR] [\smallcapped\romannumerals]
+\defineconversion [RK] [\smallcapped\romannumerals]
+
+\defineconversion [g] [\greeknumerals]
+\defineconversion [G] [\Greeknumerals]
+
+\defineconversion [o] [\oldstylenumerals]
+\defineconversion [O] [\oldstylenumerals]
+\defineconversion [or] [\oldstyleromannumerals]
+
+\defineconversion [\v!character] [\character]
+\defineconversion [\v!Character] [\Character]
+
+\defineconversion [\v!characters] [\characters]
+\defineconversion [\v!Characters] [\Characters]
+
+\defineconversion [\v!numbers] [\numbers]
+\defineconversion [\v!Numbers] [\Numbers]
+\defineconversion [\v!mediaeval] [\mediaeval]
+
+\defineconversion [\v!romannumerals] [\romannumerals]
+\defineconversion [\v!Romannumerals] [\Romannumerals]
+
+\defineconversion [\v!greek] [\greeknumerals]
+\defineconversion [\v!Greek] [\Greeknumerals]
+
+\defineconversion [arabicnumerals] [\arabicnumerals]
+\defineconversion [persiannumerals] [\arabicnumerals]
+
+\defineconversion [month] [\doconvertmonthlong]
+\defineconversion [month:mnem] [\doconvertmonthshort]
+
+% Some bonus ones:
+
+\defineconversion [\v!empty] [\gobbleoneargument]
+\defineconversion [\v!none] [\numbers]
+
+\ifx\symbol\undefined \def\symbol[#1]{#1} \fi % todo
+
+\defineconversion
+ [set 0]
+ [{\symbol[bullet]},
+ {\symbol[dash]},
+ {\symbol[star]},
+ {\symbol[triangle]},
+ {\symbol[circle]},
+ {\symbol[medcircle]},
+ {\symbol[bigcircle]},
+ {\symbol[square]}]
+
+\defineconversion
+ [set 1]
+ [\mathematics{\star},
+ \mathematics{\star\star},
+ \mathematics{\star\star\star},
+ \mathematics{\ddagger},
+ \mathematics{\ddagger\ddagger},
+ \mathematics{\ddagger\ddagger\ddagger},
+ \mathematics{\ast},
+ \mathematics{\ast\ast},
+ \mathematics{\ast\ast\ast}]
+
+\defineconversion
+ [set 2]
+ [\mathematics{*},
+ \mathematics{\dag},
+ \mathematics{\ddag},
+ \mathematics{**},
+ \mathematics{\dag\dag},
+ \mathematics{\ddag\ddag},
+ \mathematics{***},
+ \mathematics{\dag\dag\dag},
+ \mathematics{\ddag\ddag\ddag},
+ \mathematics{****},
+ \mathematics{\dag\dag\dag\dag},
+ \mathematics{\ddag\ddag\ddag\ddag}]
+
+\defineconversion
+ [set 3]
+ [\mathematics{\star},
+ \mathematics{\star\star},
+ \mathematics{\star\star\star},
+ \mathematics{\ddagger},
+ \mathematics{\ddagger\ddagger},
+ \mathematics{\ddagger\ddagger\ddagger},
+ \mathematics{\P},
+ \mathematics{\P\P},
+ \mathematics{\P\P\P},
+ \mathematics{\S},
+ \mathematics{\S\S},
+ \mathematics{\S\S\S},
+ \mathematics{\ast},
+ \mathematics{\ast\ast},
+ \mathematics{\ast\ast\ast}]
%D \macros
%D {defineconversionvector,conversionnumber} % bad names so no danger for clash
@@ -235,24 +946,24 @@
% actually mkiii code
-\beginXETEX
-
-\defineconversionvector{arabicnumerals} {"0660}
-\defineconversionvector{persiannumerals} {"06F0}
-\defineconversionvector{thainumerals} {"0E50}
-\defineconversionvector{devanagarinumerals}{"0966}
-\defineconversionvector{gurmurkhinumerals} {"0A66}
-\defineconversionvector{gujaratinumerals} {"0AE6}
-\defineconversionvector{tibetannumerals} {"0F20} % also "half numerals?"
-
-\defineconversion[arabicnumerals] [\conversionnumber{arabicnumerals}]
-\defineconversion[persiannumerals] [\conversionnumber{persiannumerals}]
-\defineconversion[thainumerals] [\conversionnumber{thainumerals}]
-\defineconversion[devanagarinumerals][\conversionnumber{devanagarinumerals}]
-\defineconversion[gurmurkhinumerals] [\conversionnumber{gurmurkhinumerals}]
-\defineconversion[gujaratinumerals] [\conversionnumber{gujaratinumerals}]
-\defineconversion[tibetannumerals] [\conversionnumber{tibetannumerals}]
-
-\endXETEX
+\ifnum\texengine=\xetexengine
+
+ \defineconversionvector{arabicnumerals} {"0660}
+ \defineconversionvector{persiannumerals} {"06F0}
+ \defineconversionvector{thainumerals} {"0E50}
+ \defineconversionvector{devanagarinumerals}{"0966}
+ \defineconversionvector{gurmurkhinumerals} {"0A66}
+ \defineconversionvector{gujaratinumerals} {"0AE6}
+ \defineconversionvector{tibetannumerals} {"0F20} % also "half numerals?"
+
+ \defineconversion[arabicnumerals] [\conversionnumber{arabicnumerals}]
+ \defineconversion[persiannumerals] [\conversionnumber{persiannumerals}]
+ \defineconversion[thainumerals] [\conversionnumber{thainumerals}]
+ \defineconversion[devanagarinumerals][\conversionnumber{devanagarinumerals}]
+ \defineconversion[gurmurkhinumerals] [\conversionnumber{gurmurkhinumerals}]
+ \defineconversion[gujaratinumerals] [\conversionnumber{gujaratinumerals}]
+ \defineconversion[tibetannumerals] [\conversionnumber{tibetannumerals}]
+
+\fi
\protect \endinput
diff --git a/tex/context/base/core-con.mkiv b/tex/context/base/core-con.mkiv
index 70ddc6991..5568fc78c 100644
--- a/tex/context/base/core-con.mkiv
+++ b/tex/context/base/core-con.mkiv
@@ -1,8 +1,8 @@
%D \module
%D [ file=core-con,
-%D version=2006.09.16,
+%D version=1997.26.08,
%D title=\CONTEXT\ Core Macros,
-%D subtitle=Conversion Macros,
+%D subtitle=Conversion,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,33 +11,331 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
+\writestatus{loading}{ConTeXt Core Macros / Conversion}
\registerctxluafile{core-con}{1.001}
-\def\romannumerals #1{\ctxlua{converters.romannumerals(\number#1)}}
-\def\Romannumerals #1{\ctxlua{converters.Romannumerals(\number#1)}}
-\def\abjadnumerals #1{\ctxlua{converters.arabicnumerals(\number#1)}}
-\def\abjadnodotnumerals#1{\ctxlua{converters.arabicnodotnumerals(\number#1)}}
-\def\abjadnaivenumerals#1{\ctxlua{converters.arabicnaivenumerals(\number#1)}}
+\unprotect
-\defineconversion [romannumerals] [\romannumerals]
-\defineconversion [Romannumerals] [\Romannumerals]
-\defineconversion [abjadnumerals] [\abjadnumerals]
-\defineconversion [abjadnodotnumerals] [\adjadnodotnumerals]
-\defineconversion [abjadnaivenumerals] [\adjadnaivenumerals]
+\ifx\currentlanguage\undefined \let\currentlanguage\empty \fi
+\ifx\labeltext \undefined \let\labeltext\firstofoneargument \fi
-\def\character #1{\ctxlua{converters.character (\number#1)}}
-\def\Character #1{\ctxlua{converters.Character (\number#1)}}
-\def\characters#1{\ctxlua{converters.characters(\number#1)}}
-\def\Characters#1{\ctxlua{converters.Characters(\number#1)}}
+%D This module deals with all kind of conversions from numbers
+%D and dates. I considered splitting this module in a support
+%D one and a core one, but to keep things simple as well as
+%D preserve the overview, I decided against splitting.
+
+\let\spr\firstofoneargument % separator
+\let\stp\firstofoneargument % stopper
+
+% cleaner, some day:
+%
+% \def\isolateseparators % etex only, even works with list separator overloading
+% {\unexpanded\def\spr##1{{##1}}%
+% \unexpanded\def\stp##1{{##1}}}
+
+% needed for arab :
+
+\def\isolateseparators % even works with list separator overloading
+ {\def\spr##1{{##1}}%
+ \def\stp##1{{##1}}}
+
+%D \macros
+%D {numbers}
+%D
+%D First we deal with the dummy conversion of numbers using the
+%D \TEX\ primitive \type{\number}. The uppercase alternative is
+%D only there for compatibility with the other conversion
+%D macros. We could do without \type{#1} but this way we get
+%D rid of unwanted braces. For the savety we also define a
+%D non||sence uppercase alternative.
+%D
+%D \showsetup{numbers}
+%D
+%D \starttyping
+%D \def\numbers#1{\number#1}
+%D \def\Numbers#1{\number#1}
+%D \stoptyping
+%D
+%D Due to read ahead, as in \type{[\pagenumber\space]} the space will
+%D disappear, unless we use:
+
+\def\numbers#1{\purenumber{#1}}
+\def\Numbers#1{\purenumber{#1}}
+
+%D \macros
+%D {romannumerals,Romannumerals}
+%D
+%D \TEX\ the program uses a rather tricky conversion from
+%D numbers to their roman counterparts. This conversion could
+%D of course be programmed in \TEX\ itself, but I guess Knuth
+%D found the programming trick worth presenting.
+%D
+%D \showsetup{romannumerals}
+%D \showsetup{Romannumerals}
+
+\def\romannumerals#1{\ctxlua{converters.romannumerals(\number#1)}}
+\def\Romannumerals#1{\ctxlua{converters.Romannumerals(\number#1)}}
+
+%D Arabic etc:
+
+\def\abjadnumerals #1{\ctxlua{converters.abjadnumerals (\number#1)}}
+\def\abjadnodotnumerals#1{\ctxlua{converters.abjadnodotnumerals(\number#1)}}
+\def\abjadnaivenumerals#1{\ctxlua{converters.arabicnumerals (\number#1)}}
\def\languagecharacters#1{\ctxlua{converters.alphabetic(\number#1,"\currentlanguage")}} % new
\def\languageCharacters#1{\ctxlua{converters.Alphabetic(\number#1,"\currentlanguage")}} % new
+% we could use an auxiliary macro to save some bytes in the format
+%
+% \def\dolanguagecharacters#1#2{\ctxlua{converters.alphabetic(\number#2,"#1")}}
+
+\def\thainumerals #1{\ctxlua{converters.alphabetic(\number#1,"thai")}}
+\def\devanagarinumerals#1{\ctxlua{converters.alphabetic(\number#1,"devanagari")}}
+\def\gurmurkhinumerals #1{\ctxlua{converters.alphabetic(\number#1,"gurmurkhi")}}
+\def\gujaratinumerals #1{\ctxlua{converters.alphabetic(\number#1,"gujarati")}}
+\def\tibetannumerals #1{\ctxlua{converters.alphabetic(\number#1,"tibetan")}}
+\def\greeknumerals #1{\ctxlua{converters.alphabetic(\number#1,"greek")}}
+\def\Greeknumerals #1{\ctxlua{converters.Alphabetic(\number#1,"greek")}}
+\def\arabicnumerals #1{\ctxlua{converters.alphabetic(\number#1,"arabic")}}
+\def\persiannumerals #1{\ctxlua{converters.alphabetic(\number#1,"persian")}}
+
+\let\arabicexnumerals \persiannumerals
+
+\def\koreannumerals #1{\ctxlua{converters.alphabetic(\number#1,"korean")}}
+\def\koreannumeralsp#1{\ctxlua{converters.alphabetic(\number#1,"korean-parent")}}
+\def\koreannumeralsc#1{\ctxlua{converters.alphabetic(\number#1,"korean-circle")}}
+
+\def\chinesenumerals #1{\ctxlua{converters.chinesenumerals (\number#1)}}
+\def\chinesecapnumerals#1{\ctxlua{converters.chinesecapnumerals(\number#1,"cap")}}
+\def\chineseallnumerals#1{\ctxlua{converters.chineseallnumerals(\number#1,"all")}}
+
+%D \macros
+%D {character,Character}
+%D
+%D Converting a number into a character can of course only
+%D be done with numbers less or equal to~26. At the cost of
+%D much more macros a faster conversion is possible, using:
+%D
+%D \starttyping
+%D \setvalue{char1}{a} \def\character#1{\getvalue{char#1}}
+%D \stoptyping
+%D
+%D But we prefer a simpel \type{\case}.
+%D
+%D \showsetup{character}
+%D \showsetup{Character}
+
+\def\unknowncharacter{-} % else in lists \relax
+
+\def\character#1{\ctxlua{converters.character (\number#1)}}
+\def\Character#1{\ctxlua{converters.Character (\number#1)}}
+
+%D \macros
+%D {characters,Characters}
+%D
+%D Converting large numbers is supported by the next two
+%D macros. This time we just count on: $\cdots$~x, y, z, aa,
+%D ab, ac~$\cdots$.
+%D
+%D \showsetup{characters}
+%D \showsetup{Characters}
+
+\def\characters#1{\ctxlua{converters.characters(\number#1)}}
+\def\Characters#1{\ctxlua{converters.Characters(\number#1)}}
+
+%D \macros
+%D {greeknumerals,Greeknumerals}
+%D
+%D Why should we only honour the romans, and not the greek?
+
+\let\greeknumerals\gobbleoneargument
+\let\Greeknumerals\gobbleoneargument
+
+%D \macros
+%D {oldstylenumerals,oldstyleromannumerals}
+%D
+%D These conversions are dedicated to Frans Goddijn.
+
+\unexpanded\def\oldstylenumerals#1%
+ {{\os\number#1}}
+
+\unexpanded\def\oldstyleromannumerals#1%
+ {{\leftrulefalse\rightrulefalse\ss\txx\boxrulewidth.15ex
+ \ruledhbox spread .15em{\hss\uppercased{\romannumerals{#1}}\hss}}}
+
+%D \macros
+%D {protectconversion}
+%D
+%D The previous two commands are not robust enough to be
+%D passed to \type{\write} en \type{\message}. That's why we
+%D introduce:
+
+\def\protectconversion
+ {\def\doconvertcharacters##1{##1}} % was \relax
+ %{\def\doconvertcharacters##1{\ifcase0##1 0\else##1\fi}} more save
+
+%D \macros
+%D {normaltime,normalyear,normalmonth,normalday}
+%D
+%D The last part of this module is dedicated to converting
+%D dates. Because we want to use as meaningful commands as
+%D possible, and because \TEX\ already uses up some of those,
+%D we save the original meanings.
+
+\savenormalmeaning\time
+\savenormalmeaning\year
+\savenormalmeaning\month
+\savenormalmeaning\day
+
+%D \macros
+%D {month,MONTH}
+%D
+%D Converting the month number into a month name is done
+%D using a case statement, abstact values and the label
+%D mechanism. This way users can easily redefine a label from
+%D for instance german into austrian.
+%D
+%D \starttyping
+%D \setuplabeltext [de] [january=J\"anner]
+%D \stoptyping
+%D
+%D Anyhow, the conversion looks like:
+
+\def\domonthtag#1%
+ {\ifcase#1%
+ \or \v!january \or \v!february \or \v!march \or \v!april
+ \or \v!may \or \v!june \or \v!july \or \v!august
+ \or \v!september \or \v!october \or \v!november \or \v!december
+ \else
+ \v!unknown
+ \fi}
+
+\def\doconvertmonthlong #1{\labeltext{\domonthtag{#1}}}
+\def\doconvertmonthshort#1{\labeltext{\domonthtag{#1}:\s!mnem}}
+
+\let\doconvertmonth\doconvertmonthlong
+
+%D We redefine the \TEX\ primitive \type{\month} as:
+%D
+%D \showsetup{month}
+%D \showsetup{MONTH}
+
+\def\monthlong {\doconvertmonthlong}
+\def\monthshort{\doconvertmonthshort}
+\def\month {\doconvertmonth}
+
+\def\MONTH #1{{\let\labeltext\LABELTEXT\month {#1}}}
+\def\MONTHLONG #1{{\let\labeltext\LABELTEXT\monthlong {#1}}}
+\def\MONTHSHORT#1{{\let\labeltext\LABELTEXT\monthshort{#1}}}
+
+%D We never explicitly needed this, but Tobias Burnus pointed
+%D out that it would be handy to convert to the day of the
+%D week. In doing so, we have to calculate the total number of
+%D days, taking leapyears into account. For those who are
+%D curious:
+%D
+%D \startitemize[packed]
+%D \item years that can be divided by 4 are leapyears
+%D \item exept years that can be divided by 100
+%D \item unless years can be divided by 400
+%D \stopitemize
+%D
+%D This makes the year 1900 into a normal year and 1996 and
+%D 2000 into leap years, right? Well, converting to string
+%D looks familiar:
+
+\def\doconvertday#1%
+ {\labeltext
+ {\ifcase#1
+ \or \v!sunday \or \v!monday \or \v!tuesday \or \v!wednesday
+ \or \v!thursday \or \v!friday \or \v!saturday \fi}}
+
+%D \macros
+%D {getdayoftheweek, dayoftheweek}
+%D
+%D The conversion algoritm is an old one and a translation from
+%D a procedure written in MODULA~2 back in the 80's. I finaly
+%D found the 4--100-400 rules in some enclopedia. Look at this
+%D messy low level routine that takes the day, month and year
+%D as arguments:
+
+\newcount\normalweekday
+
\def\getdayoftheweek#1#2#3{\normalweekday\ctxlua{converters.weekday(\number#1,\number#2,\number#3)}}
\def\dayoftheweek #1#2#3{\doconvertday{\ctxlua{converters.weekday(\number#1,\number#2,\number#3)}}}
+%D Using this macro in
+%D
+%D \startbuffer
+%D monday: \dayoftheweek {4} {5} {1992}
+%D friday: \dayoftheweek {16} {6} {1995}
+%D monday: \dayoftheweek {25} {8} {1997}
+%D saturday: \dayoftheweek {30} {8} {1997}
+%D tuesday: \dayoftheweek {2} {1} {1996}
+%D tuesday: \dayoftheweek {7} {1} {1997}
+%D tuesday: \dayoftheweek {13} {1} {1998}
+%D friday: \dayoftheweek {1} {1} {2000}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D gives
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D The macro \type {\getdayoftheweek} can be used to calculate
+%D the number \type {\normalweekday}.
+
+%D \macros
+%D {weekday,WEEKDAY}
+%D
+%D The first one is sort of redundant. It takes the day
+%D number argument.
+%D
+%D \showsetup{weekday}
+%D \showsetup{WEEKDAY}
+
+\def\weekday
+ {\doconvertday}
+
+\def\WEEKDAY#1%
+ {{\let\labeltext\LABELTEXT\doconvertday{#1}}}
+
+%D \macros
+%D {weekoftheday}
+%D
+%D {\em not yet implemented:}
+%D
+%D \starttyping
+%D \def\weekoftheday#1#2#3%
+%D {}
+%D \stoptyping
+
+%D \macros
+%D {doifleapyearelse,
+%D getdayspermonth}
+%D
+%D Sometimes we need to know if we're dealing with a
+%D leapyear, so here is a testmacro:
+%D
+%D \starttyping
+%D \doifleapyearelse{year}{yes}{no}
+%D \stoptyping
+%D
+%D An example of its use can be seen in the macro
+%D
+%D \starttyping
+%D \getdayspermonth{year}{month}
+%D \stoptyping
+%D
+%D The number of days is available in the macro \type
+%D {\numberofdays}.
+
\def\doifleapyearelse#1%
{\ifcase\ctxlua{converters.leapyear(\number#1)}
\@EA\secondoftwoarguments
@@ -51,11 +349,6 @@
\def\dayspermonth#1#2%
{\ctxlua{converters.nofdays(\number#1,\number#2)}}
-\def\calculatecurrenttime
- {\edef\currenthour {\ctxlua{converters.hour ()}}%
- \edef\currentminute{\ctxlua{converters.minute()}}%
- \edef\currentsecond{\ctxlua{converters.second()}}}
-
% problem is that we calculate with those numbers
%
% \def\time {\numexpr\ctxlua{converters.textime()}\relax}
@@ -71,33 +364,481 @@
% \dayspermonth{2000}{2}
% [\the\normaltime=\the\time]
-% we could use an auxiliary macro to save some bytes in the format
+%D \macros
+%D {currentdate, date}
+%D
+%D We use these conversion macros in the date formatting
+%D macro:
+%D
+%D \showsetup{currentdate}
+%D
+%D This macro takes care of proper spacing and delivers for
+%D instance:
+%D
+%D \startbuffer
+%D \currentdate[weekday,day,month,year] % still dutch example
+%D \currentdate[WEEKDAY,day,MONTH,year] % still dutch example
+%D \stopbuffer
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D depending of course on the keywords. Here we gave:
+%D
+%D \typebuffer
+%D
+%D If needed one can also add non||keywords, like in
+%D
+%D \startbuffer
+%D \currentdate[dd,--,mm,--,yy]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or typeset: \getbuffer.
+%D
+%D When no argument is passed, the current date is given as
+%D specified per language (using \type{\installlanguage}).
+%D
+%D \showsetup{currentdate}
+%D
+%D \startbuffer
+%D \date
+%D \date[d=12,m=12,y=1998][weekday]
+%D \date[d=12,m=12,y=1998]
+%D \stopbuffer
+%D
+%D We can also typeset arbitrary dates, using the previous
+%D command.
+%D
+%D \typebuffer
+%D
+%D The date is specified by one character keys. When no date
+%D is given, we get the current date.
+%D
+%D \startlines
+%D \getbuffer
+%D \stoplines
+
+\def\kenmerkdatumpatroon{j,mm,dd} % jj,mm,dd changed at januari 1-1-2000
+
+\newsignal\datesignal
+
+\def\dobetweendates
+ {\ifdim\lastskip=\datesignal\relax\else
+ \unskip\space
+ \hskip\datesignal\relax
+ \fi}
+
+\newtoks \everycurrentdate
+
+\def\complexcurrentdate[#1]%
+ {\bgroup
+ \the\everycurrentdate
+ \def\betweendates{\let\betweendates\dobetweendates}%
+ % was \processcommacommandp[#1]\docomplexcurrentdate
+ \safeedef\ascii{\empty#1}% keep encoded chars
+ \@EA\processcommalist\@EA[\ascii]\docomplexcurrentdate
+ \ifdim\lastskip=\datesignal\relax
+ \unskip
+ \fi
+ \egroup}
+
+\def\docomplexcurrentdate#1%
+ {\lowercase{\edef\!!stringa{#1}}% permits usage in \smallcapped
+ \expanded{\processaction[\!!stringa]}% [#1]
+ [ \v!day=>\betweendates\the\normalday,
+ %\v!day+=>\betweendates\ordinaldaynumber\normalday,
+ \v!day+=>\betweendates\convertnumber{\v!day+}\normalday,
+ \v!month=>\betweendates\month\normalmonth,
+ \v!year=>\betweendates\the\normalyear,
+ \v!space=>\unskip\ \hskip\datesignal,% optimization -)
+ \ =>\unskip\ \hskip\datesignal,% optimization -)
+ d=>\convertnumber\v!day\normalday,
+ %d+=>\ordinaldaynumber\normalday,
+ d+=>\convertnumber{\v!day+}\normalday,
+ m=>\convertnumber\v!month\normalmonth,
+ j=>\convertnumber\v!year\normalyear,
+ y=>\convertnumber\v!year\normalyear,
+ w=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
+ dd=>\ifnum\normalday >9 \else0\fi\the\normalday,
+ %dd+=>\ordinaldaynumber{\ifnum\normalday >9 \else0\fi\the\normalday},
+ dd+=>\convertnumber{\v!day+}{\ifnum\normalday >9 \else0\fi\the\normalday},
+ mm=>\ifnum\normalmonth>9 \else0\fi\the\normalmonth,
+ jj=>\expandafter\gobbletwoarguments\the\normalyear,
+ yy=>\expandafter\gobbletwoarguments\the\normalyear,
+ \v!weekday=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
+ \v!referral=>\expanded{\complexcurrentdate[\kenmerkdatumpatroon]},
+ \s!unknown=>\unskip
+ % #1 and not the lowercased \commalistelement, vietnamese has text
+ % {} because #1 can have comma, like: {\ ,}
+ {#1}%
+ \hskip\datesignal
+ \def\betweendates{\let\betweendates\dobetweendates}]}
+
+\def\simplecurrentdate
+ {\expanded{\complexcurrentdate[\currentdatespecification]}}
+
+\definecomplexorsimple\currentdate
+
+\def\dodate[#1][#2]%
+ {\bgroup
+ \iffirstargument
+ \getparameters[\??da][d=\normalday,m=\normalmonth,y=\normalyear,#1]%
+ \normalday \@@dad\relax
+ \normalmonth\@@dam\relax
+ \normalyear \@@day\relax
+ \ifsecondargument
+ \currentdate[#2]%
+ \else
+ \currentdate
+ \fi
+ \else
+ \currentdate
+ \fi
+ \egroup}
+
+\def\date
+ {\dodoubleempty\dodate}
+
+%D \macros
+%D {currenttime}
+%D
+%D The currenttime is actually the jobtime. You can specify
+%D a pattern similar to the previous date macro using the
+%D keys \type {h}, \type {m} and a separator.
+
+\def\calculatecurrenttime
+ {\edef\currenthour {\ctxlua{converters.hour ()}}%
+ \edef\currentminute{\ctxlua{converters.minute()}}%
+ \edef\currentsecond{\ctxlua{converters.second()}}}
+
+\let\currenthour \!!plusone
+\let\currentminute\!!plusone
+
+\def\currenttimespecification{h,:,m}
+
+\def\complexcurrenttime[#1]%
+ {\calculatecurrenttime
+ \processallactionsinset[#1]
+ [h=>\currenthour,m=>\currentminute,\s!unknown=>\commalistelement]}
+
+\def\simplecurrenttime
+ {\expanded{\complexcurrenttime[\currenttimespecification]}}
+
+\definecomplexorsimple\currenttime
+
+%D Because we're dealing with dates, we also introduce a few
+%D day loops:
+%D
+%D \starttyping
+%D \processmonth{year}{month}{command}
+%D \processyear{year}{command}{before}{after}
+%D \stoptyping
+%D
+%D The counters \type {\normalyear}, \type {\normalmonth} and
+%D \type{\normalday} can be used for for date manipulations.
+
+\long\def\processmonth#1#2#3% year month command
+ {\bgroup
+ \getdayspermonth{#1}{#2}%
+ \dostepwiserecurse1\numberofdays1%
+ {\normalyear #1\relax
+ \normalmonth#2\relax
+ \normalday \recurselevel\relax
+ #3}%
+ \egroup}
+
+\def\lastmonth{12} % can be set to e.g. 1 when testing
+
+\long\def\processyear#1#2#3#4% year command before after
+ {\bgroup
+ \dorecurse\lastmonth
+ {\normalyear #1\relax
+ \normalmonth\recurselevel\relax
+ #3\processmonth\normalyear\normalmonth{#2}#4}%
+ \egroup}
+
+%D \macros
+%D {defineconversion, convertnumber}
+%D
+%D Conversion involves the macros that we implemented earlier
+%D in this module.
+%D
+%D \showsetup{defineconversion}
+%D \showsetup{convertnumber}
+%D
+%D We can feed this command with conversion macros as well as
+%D a set of conversion symbols. Both need a bit different
+%D treatment.
+%D
+%D \starttyping
+%D \defineconversion [roman] [\romannumerals]
+%D \defineconversion [set 1] [$\star$,$\bullet$,$\ast$]
+%D \stoptyping
+%D
+%D You can define a language dependent conversion with:
+%D
+%D \starttyping
+%D \defineconversion [en] [whatever] [\something]
+%D \stoptyping
+
+% \def\dodefineconversion[#1][#2]%
+% {\ConvertConstantAfter\doifinstringelse{,}{#2}
+% {\scratchcounter=0
+% \def\docommand##1%
+% {\advance\scratchcounter 1
+% \setvalue{\??cv#1\the\scratchcounter}{##1}}%
+% \processcommalist[#2]\docommand
+% \setvalue{\??cv#1}##1{\csname\??cv#1##1\endcsname}}
+% {\setvalue{\??cv#1}{#2}}}
%
-% \def\dolanguagecharacters#1#2{\ctxlua{converters.alphabetic(\number#2,"#1")}}
+% \def\defineconversion%
+% {\dodoubleargument\dodefineconversion}
-% this does not belong here, but in a lang-module
+\def\defineconversion
+ {\dotripleempty\dodefineconversion}
-\def\thainumerals #1{\ctxlua{converters.alphabetic(\number#1,"thai")}}
-\def\devanagarinumerals#1{\ctxlua{converters.alphabetic(\number#1,"devanagari")}}
-\def\gurmurkhinumerals #1{\ctxlua{converters.alphabetic(\number#1,"gurmurkhi")}}
-\def\gujaratinumerals #1{\ctxlua{converters.alphabetic(\number#1,"gujarati")}}
-\def\tibetannumerals #1{\ctxlua{converters.alphabetic(\number#1,"tibetan")}}
-\def\greeknumerals #1{\ctxlua{converters.alphabetic(\number#1,"greek")}}
-\def\Greeknumerals #1{\ctxlua{converters.Alphabetic(\number#1,"greek")}}
-\def\arabicnumerals #1{\ctxlua{converters.alphabetic(\number#1,"arabic")}}
-\def\persiannumerals #1{\ctxlua{converters.alphabetic(\number#1,"persian")}}
+\def\dodefineconversion[#1][#2][#3]%
+ {\ifthirdargument
+ \dododefineconversion[#1][#2][#3]%
+ \else
+ \dododefineconversion[][#1][#2]%
+ \fi}
-\let\arabicexnumerals \persiannumerals
+%D \starttyping
+%D \def\dododefineconversion[#1][#2][#3]%
+%D {\ConvertConstantAfter\doifinstringelse{,}{#3}
+%D {\scratchcounter\zerocount
+%D \def\docommand##1%
+%D {\advance\scratchcounter \plusone
+%D \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
+%D \processcommalist[#3]\docommand
+%D \setvalue{\??cv#1#2}##1{\executeifdefined{\??cv#1#2##1}\unknown}} % catch out-of-range numbers
+%D {\setvalue{\??cv#1#2}{#3}}}
+%D \stoptyping
+
+%D This approach has the disadvantage that when you run out of
+%D symbols you get unknown results. The following implementation
+%D permits overloading of the converter:
+
+\def\dododefineconversion[#1][#2][#3]%
+ {\ConvertConstantAfter\doifinstringelse{,}{#3}
+ {\scratchcounter\zerocount
+ \def\docommand##1%
+ {\advance\scratchcounter \plusone
+ \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
+ \processcommalist[#3]\docommand
+ \setevalue{\??cv#1#2}##1%
+ {\noexpand\docheckedconversion{#1#2}{\the\scratchcounter}{##1}}}
+ {\setvalue{\??cv#1#2}{#3}}}
+
+\def\docheckedconversion#1#2#3% class maxnumber number
+ {\executeifdefined{\??cv#1#3}\unknown}
+
+%D When Gerben reported problems with footnote numbering per page,
+%D Taco came with the following wrap around solution. So, let's
+%D overload the checked conversion macro:
+
+\def\docheckedconversion#1#2#3% class maxnumber number
+ {\executeifdefined{\??cv#1\modulatednumber{#2}{#3}}\unknown}
+
+%D Taco's modulo code is implemented in the system module
+%D \type {syst-con}.
+
+%D If a conversion is just a font switch then we need to make sure
+%D that the number is indeed end up as number in the input, so we
+%D need to handle the second argument.
+
+\def\convertnumber#1#2%
+ {\csname\??cv
+ \ifcsname\??cv\currentlanguage#1\endcsname
+ \currentlanguage#1%
+ \else\ifcsname\??cv#1\endcsname
+ #1%
+ \else
+ \s!default
+ \fi\fi
+ \endcsname{\number#2}}
+
+\def\doifconversiondefinedelse#1%
+ {\ifcsname\??cv\currentlanguage#1\endcsname
+ \@EA\firstoftwoarguments
+ \else\ifcsname\??cv#1\endcsname
+ \@EAEAEA\firstoftwoarguments
+ \else
+ \@EAEAEA\secondoftwoarguments
+ \fi\fi}
+
+\def\doifelseconversionnumber#1#2% slow but seldom used
+ {\doifdefinedelse{\??cv#1#2}}
+
+%D Handy.
+
+\setvalue{\??cv:\c!n:\v!one }{1}
+\setvalue{\??cv:\c!n:\v!two }{2}
+\setvalue{\??cv:\c!n:\v!three}{3}
+\setvalue{\??cv:\c!n:\v!four }{4}
+\setvalue{\??cv:\c!n:\v!five }{5}
+
+\def\wordtonumber#1#2{\ifcsname\??cv:\c!n:#1\endcsname\csname\??cv:\c!n:#1\endcsname\else#2\fi}
+
+% \defineconversion[ctx][c,o,n,t,e,x,t]
+%
+% \doloop{\doifelseconversionnumber{ctx}{\recurselevel}{[\recurselevel]}{\exitloop}}
+
+%D As longs as symbols are linked to levels or numbers, we can
+%D also use the conversion mechanism, but in for instance the
+%D itemization macros, we prefer symbols because they can more
+%D easier be (partially) redefined. Symbols are implemented
+%D in another module.
+
+\def\smallcappedromannumerals#1{\smallcapped{\romannumerals{#1}}}
+\def\smallcappedcharacters #1{\smallcapped{\characters {#1}}}
+
+\defineconversion [] [\numbers] % the default conversion
+\defineconversion [\v!empty] [\gobbleoneargument]
+\defineconversion [\v!none] [\numbers]
+\defineconversion [\s!default] [\numbers]
+
+\defineconversion [month] [\doconvertmonthlong]
+\defineconversion [month:mnem] [\doconvertmonthshort]
+
+\defineconversion [\v!character] [\character]
+\defineconversion [\v!Character] [\Character]
+
+\defineconversion [\v!characters] [\characters]
+\defineconversion [\v!Characters] [\Characters]
+
+\defineconversion [a] [\characters]
+\defineconversion [A] [\Characters]
+\defineconversion [AK] [\smallcappedcharacters]
+\defineconversion [KA] [\smallcappedcharacters]
+
+\defineconversion [\v!numbers] [\numbers]
+\defineconversion [\v!Numbers] [\Numbers]
+\defineconversion [\v!mediaeval] [\mediaeval]
+
+\defineconversion [n] [\numbers]
+\defineconversion [N] [\Numbers]
+\defineconversion [m] [\mediaeval]
+\defineconversion [o] [\oldstylenumerals]
+\defineconversion [O] [\oldstylenumerals]
+\defineconversion [or] [\oldstyleromannumerals]
+
+\defineconversion [\v!romannumerals] [\romannumerals]
+\defineconversion [\v!Romannumerals] [\Romannumerals]
+
+\defineconversion [i] [\romannumerals]
+\defineconversion [I] [\Romannumerals]
+\defineconversion [r] [\romannumerals]
+\defineconversion [R] [\Romannumerals]
+
+\defineconversion [KR] [\smallcappedromannumerals]
+\defineconversion [RK] [\smallcappedromannumerals]
+
+\defineconversion [\v!greek] [\greeknumerals]
+\defineconversion [\v!Greek] [\Greeknumerals]
+
+\defineconversion [g] [\greeknumerals]
+\defineconversion [G] [\Greeknumerals]
+
+\defineconversion [arabicnumerals] [\arabicnumerals]
+\defineconversion [persiannumerals] [\persiannumerals]
+
+\defineconversion [abjadnumerals] [\abjadnumerals]
+\defineconversion [abjadnodotnumerals] [\adjadnodotnumerals]
+\defineconversion [abjadnaivenumerals] [\adjadnaivenumerals]
+
+\defineconversion [thainumerals] [\thainumerals]
+\defineconversion [devanagarinumerals] [\devanagarinumerals]
+\defineconversion [gurmurkhinumerals] [\gurmurkhinumerals]
+\defineconversion [gujaratinumerals] [\gujaratinumerals]
+\defineconversion [tibetannumerals] [\tibetannumerals]
+\defineconversion [greeknumerals] [\greeknumerals]
+\defineconversion [Greeknumerals] [\Greeknumerals]
+\defineconversion [arabicnumerals] [\arabicnumerals]
+\defineconversion [persiannumerals] [\persiannumerals]
+\defineconversion [arabicexnumerals] [\arabicexnumerals]
+
+
+\defineconversion [koreannumerals] [\koreannumerals]
+\defineconversion [koreanparentnumerals] [\koreanparentnumerals]
+\defineconversion [koreancirclenumerals] [\koreancirclenumerals]
+
+\defineconversion [kr] [\koreannumerals]
+\defineconversion [kr-p] [\koreanparentnumerals]
+\defineconversion [kr-c] [\koreancirclenumerals]
+
+\defineconversion [chinesenumerals] [\chinesenumerals]
+\defineconversion [chinesecapnumeralscn] [\chinesecapnumerals]
+\defineconversion [chineseallnumeralscn] [\chineseallnumerals]
+
+\defineconversion [cn] [\chinesenumerals]
+\defineconversion [cn-c] [\chinesecapnumerals]
+\defineconversion [cn-a] [\chineseallnumerals]
+
+%D Symbol sets:
+
+\ifx\symbol\undefined \def\symbol[#1]{#1} \fi % todo
+
+\defineconversion
+ [set 0]
+ [{\symbol[bullet]},
+ {\symbol[dash]},
+ {\symbol[star]},
+ {\symbol[triangle]},
+ {\symbol[circle]},
+ {\symbol[medcircle]},
+ {\symbol[bigcircle]},
+ {\symbol[square]}]
+
+\defineconversion
+ [set 1]
+ [\mathematics{\star},
+ \mathematics{\star\star},
+ \mathematics{\star\star\star},
+ \mathematics{\ddagger},
+ \mathematics{\ddagger\ddagger},
+ \mathematics{\ddagger\ddagger\ddagger},
+ \mathematics{\ast},
+ \mathematics{\ast\ast},
+ \mathematics{\ast\ast\ast}]
+
+\defineconversion
+ [set 2]
+ [\mathematics{*},
+ \mathematics{\dag},
+ \mathematics{\ddag},
+ \mathematics{**},
+ \mathematics{\dag\dag},
+ \mathematics{\ddag\ddag},
+ \mathematics{***},
+ \mathematics{\dag\dag\dag},
+ \mathematics{\ddag\ddag\ddag},
+ \mathematics{****},
+ \mathematics{\dag\dag\dag\dag},
+ \mathematics{\ddag\ddag\ddag\ddag}]
-\defineconversion [thainumerals] [\thainumerals]
-\defineconversion [devanagarinumerals] [\devanagarinumerals]
-\defineconversion [gurmurkhinumerals] [\gurmurkhinumerals]
-\defineconversion [gujaratinumerals] [\gujaratinumerals]
-\defineconversion [tibetannumerals] [\tibetannumerals]
-\defineconversion [greeknumerals] [\greeknumerals]
-\defineconversion [Greeknumerals] [\Greeknumerals]
-\defineconversion [arabicnumerals] [\arabicnumerals]
-\defineconversion [persiannumerals] [\persiannumerals]
-\defineconversion [arabicexnumerals] [\arabicexnumerals]
+\defineconversion
+ [set 3]
+ [\mathematics{\star},
+ \mathematics{\star\star},
+ \mathematics{\star\star\star},
+ \mathematics{\ddagger},
+ \mathematics{\ddagger\ddagger},
+ \mathematics{\ddagger\ddagger\ddagger},
+ \mathematics{\P},
+ \mathematics{\P\P},
+ \mathematics{\P\P\P},
+ \mathematics{\S},
+ \mathematics{\S\S},
+ \mathematics{\S\S\S},
+ \mathematics{\ast},
+ \mathematics{\ast\ast},
+ \mathematics{\ast\ast\ast}]
\protect \endinput
diff --git a/tex/context/base/core-con.tex b/tex/context/base/core-con.tex
deleted file mode 100644
index 13d59ecc6..000000000
--- a/tex/context/base/core-con.tex
+++ /dev/null
@@ -1,744 +0,0 @@
-%D \module
-%D [ file=core-con,
-%D version=1997.26.08,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Conversion Macros,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Conversion Macros}
-
-\unprotect
-
-\ifx\currentlanguage\undefined \let\currentlanguage\empty \fi
-\ifx\labeltext \undefined \let\labeltext\firstofoneargument \fi
-
-%D This module deals with all kind of conversions from numbers
-%D and dates. I considered splitting this module in a support
-%D one and a core one, but to keep things simple as well as
-%D preserve the overview, I decided against splitting.
-
-\let\spr\firstofoneargument % separator
-\let\stp\firstofoneargument % stopper
-
-% cleaner, some day:
-%
-% \def\isolateseparators % etex only, even works with list separator overloading
-% {\unexpanded\def\spr##1{{##1}}%
-% \unexpanded\def\stp##1{{##1}}}
-
-% needed for arab :
-
-\def\isolateseparators % even works with list separator overloading
- {\def\spr##1{{##1}}%
- \def\stp##1{{##1}}}
-
-%D \macros
-%D {numbers}
-%D
-%D First we deal with the dummy conversion of numbers using the
-%D \TEX\ primitive \type{\number}. The uppercase alternative is
-%D only there for compatibility with the other conversion
-%D macros. We could do without \type{#1} but this way we get
-%D rid of unwanted braces. For the savety we also define a
-%D non||sence uppercase alternative.
-%D
-%D \showsetup{numbers}
-%D
-%D \starttyping
-%D \def\numbers#1{\number#1}
-%D \def\Numbers#1{\number#1}
-%D \stoptyping
-%D
-%D Due to read ahead, as in \type{[\pagenumber\space]} the space will
-%D disappear, unless we use:
-
-\def\numbers#1{\purenumber{#1}}
-\def\Numbers#1{\purenumber{#1}}
-
-%D \macros
-%D {romannumerals,Romannumerals}
-%D
-%D \TEX\ the program uses a rather tricky conversion from
-%D numbers to their roman counterparts. This conversion could
-%D of course be programmed in \TEX\ itself, but I guess Knuth
-%D found the programming trick worth presenting.
-%D
-%D \showsetup{romannumerals}
-%D \showsetup{Romannumerals}
-
-\let\romannumerals\gobbleoneargument
-\let\Romannumerals\gobbleoneargument
-
-%D \macros
-%D {character,Character}
-%D
-%D Converting a number into a character can of course only
-%D be done with numbers less or equal to~26. At the cost of
-%D much more macros a faster conversion is possible, using:
-%D
-%D \starttyping
-%D \setvalue{char1}{a} \def\character#1{\getvalue{char#1}}
-%D \stoptyping
-%D
-%D But we prefer a simpel \type{\case}.
-%D
-%D \showsetup{character}
-%D \showsetup{Character}
-
-\def\unknowncharacter{-} % else in lists \relax
-
-\let\character\gobbleoneargument
-\let\Character\gobbleoneargument
-
-%D \macros
-%D {characters,Characters}
-%D
-%D Converting large numbers is supported by the next two
-%D macros. This time we just count on: $\cdots$~x, y, z, aa,
-%D ab, ac~$\cdots$.
-%D
-%D \showsetup{characters}
-%D \showsetup{Characters}
-
-\let\characters\gobbleoneargument
-\let\Characters\gobbleoneargument
-
-%D \macros
-%D {greeknumerals,Greeknumerals}
-%D
-%D Why should we only honour the romans, and not the greek?
-
-\let\greeknumerals\gobbleoneargument
-\let\Greeknumerals\gobbleoneargument
-
-%D \macros
-%D {oldstylenumerals,oldstyleromannumerals}
-%D
-%D These conversions are dedicated to Frans Goddijn.
-
-\unexpanded\def\oldstylenumerals#1%
- {{\os\number#1}}
-
-\unexpanded\def\oldstyleromannumerals#1%
- {{\leftrulefalse\rightrulefalse\ss\txx\boxrulewidth.15ex
- \ruledhbox spread .15em{\hss\uppercased{\romannumerals{#1}}\hss}}}
-
-%D \macros
-%D {protectconversion}
-%D
-%D The previous two commands are not robust enough to be
-%D passed to \type{\write} en \type{\message}. That's why we
-%D introduce:
-
-\def\protectconversion
- {\def\doconvertcharacters##1{##1}} % was \relax
- %{\def\doconvertcharacters##1{\ifcase0##1 0\else##1\fi}} more save
-
-%D \macros
-%D {normaltime,normalyear,normalmonth,normalday}
-%D
-%D The last part of this module is dedicated to converting
-%D dates. Because we want to use as meaningful commands as
-%D possible, and because \TEX\ already uses up some of those,
-%D we save the original meanings.
-
-\savenormalmeaning\time
-\savenormalmeaning\year
-\savenormalmeaning\month
-\savenormalmeaning\day
-
-%D \macros
-%D {month,MONTH}
-%D
-%D Converting the month number into a month name is done
-%D using a case statement, abstact values and the label
-%D mechanism. This way users can easily redefine a label from
-%D for instance german into austrian.
-%D
-%D \starttyping
-%D \setuplabeltext [de] [january=J\"anner]
-%D \stoptyping
-%D
-%D Anyhow, the conversion looks like:
-
-\def\domonthtag#1%
- {\ifcase#1%
- \or \v!january \or \v!february \or \v!march \or \v!april
- \or \v!may \or \v!june \or \v!july \or \v!august
- \or \v!september \or \v!october \or \v!november \or \v!december
- \else
- \v!unknown
- \fi}
-
-\def\doconvertmonthlong #1{\labeltext{\domonthtag{#1}}}
-\def\doconvertmonthshort#1{\labeltext{\domonthtag{#1}:\s!mnem}}
-
-\let\doconvertmonth\doconvertmonthlong
-
-%D We redefine the \TEX\ primitive \type{\month} as:
-%D
-%D \showsetup{month}
-%D \showsetup{MONTH}
-
-\def\monthlong {\doconvertmonthlong}
-\def\monthshort{\doconvertmonthshort}
-\def\month {\doconvertmonth}
-
-\def\MONTH #1{{\let\labeltext\LABELTEXT\month {#1}}}
-\def\MONTHLONG #1{{\let\labeltext\LABELTEXT\monthlong {#1}}}
-\def\MONTHSHORT#1{{\let\labeltext\LABELTEXT\monthshort{#1}}}
-
-%D We never explicitly needed this, but Tobias Burnus pointed
-%D out that it would be handy to convert to the day of the
-%D week. In doing so, we have to calculate the total number of
-%D days, taking leapyears into account. For those who are
-%D curious:
-%D
-%D \startitemize[packed]
-%D \item years that can be divided by 4 are leapyears
-%D \item exept years that can be divided by 100
-%D \item unless years can be divided by 400
-%D \stopitemize
-%D
-%D This makes the year 1900 into a normal year and 1996 and
-%D 2000 into leap years, right? Well, converting to string
-%D looks familiar:
-
-\def\doconvertday#1%
- {\labeltext
- {\ifcase#1
- \or \v!sunday \or \v!monday \or \v!tuesday \or \v!wednesday
- \or \v!thursday \or \v!friday \or \v!saturday \fi}}
-
-%D \macros
-%D {getdayoftheweek, dayoftheweek}
-%D
-%D The conversion algoritm is an old one and a translation from
-%D a procedure written in MODULA~2 back in the 80's. I finaly
-%D found the 4--100-400 rules in some enclopedia. Look at this
-%D messy low level routine that takes the day, month and year
-%D as arguments:
-
-\newcount\normalweekday
-
-\let\getdayoftheweek\gobblethreearguments
-\let\dayoftheweek \gobblethreearguments
-
-%D Using this macro in
-%D
-%D \startbuffer
-%D monday: \dayoftheweek {4} {5} {1992}
-%D friday: \dayoftheweek {16} {6} {1995}
-%D monday: \dayoftheweek {25} {8} {1997}
-%D saturday: \dayoftheweek {30} {8} {1997}
-%D tuesday: \dayoftheweek {2} {1} {1996}
-%D tuesday: \dayoftheweek {7} {1} {1997}
-%D tuesday: \dayoftheweek {13} {1} {1998}
-%D friday: \dayoftheweek {1} {1} {2000}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D gives
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D The macro \type {\getdayoftheweek} can be used to calculate
-%D the number \type {\normalweekday}.
-
-%D \macros
-%D {weekday,WEEKDAY}
-%D
-%D The first one is sort of redundant. It takes the day
-%D number argument.
-%D
-%D \showsetup{weekday}
-%D \showsetup{WEEKDAY}
-
-\def\weekday
- {\doconvertday}
-
-\def\WEEKDAY#1%
- {{\let\labeltext\LABELTEXT\doconvertday{#1}}}
-
-%D \macros
-%D {weekoftheday}
-%D
-%D {\em not yet implemented:}
-%D
-%D \starttyping
-%D \def\weekoftheday#1#2#3%
-%D {}
-%D \stoptyping
-
-%D \macros
-%D {doifleapyearelse,
-%D getdayspermonth}
-%D
-%D Sometimes we need to know if we're dealing with a
-%D leapyear, so here is a testmacro:
-%D
-%D \starttyping
-%D \doifleapyearelse{year}{yes}{no}
-%D \stoptyping
-%D
-%D An example of its use can be seen in the macro
-%D
-%D \starttyping
-%D \getdayspermonth{year}{month}
-%D \stoptyping
-%D
-%D The number of days is available in the macro \type
-%D {\numberofdays}.
-
-\def\doifleapyearelse #1{\firstoftwoarguments}
-\def\getdayspermonth#1#2{\let\numberofdays\!!zerocount}
-
-%D \macros
-%D {currentdate, date}
-%D
-%D We use these conversion macros in the date formatting
-%D macro:
-%D
-%D \showsetup{currentdate}
-%D
-%D This macro takes care of proper spacing and delivers for
-%D instance:
-%D
-%D \startbuffer
-%D \currentdate[weekday,day,month,year] % still dutch example
-%D \currentdate[WEEKDAY,day,MONTH,year] % still dutch example
-%D \stopbuffer
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D depending of course on the keywords. Here we gave:
-%D
-%D \typebuffer
-%D
-%D If needed one can also add non||keywords, like in
-%D
-%D \startbuffer
-%D \currentdate[dd,--,mm,--,yy]
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D or typeset: \getbuffer.
-%D
-%D When no argument is passed, the current date is given as
-%D specified per language (using \type{\installlanguage}).
-%D
-%D \showsetup{currentdate}
-%D
-%D \startbuffer
-%D \date
-%D \date[d=12,m=12,y=1998][weekday]
-%D \date[d=12,m=12,y=1998]
-%D \stopbuffer
-%D
-%D We can also typeset arbitrary dates, using the previous
-%D command.
-%D
-%D \typebuffer
-%D
-%D The date is specified by one character keys. When no date
-%D is given, we get the current date.
-%D
-%D \startlines
-%D \getbuffer
-%D \stoplines
-
-\def\kenmerkdatumpatroon{j,mm,dd} % jj,mm,dd changed at januari 1-1-2000
-
-\newsignal\datesignal
-
-\def\dobetweendates
- {\ifdim\lastskip=\datesignal\relax\else
- \unskip\space
- \hskip\datesignal\relax
- \fi}
-
-\newtoks \everycurrentdate
-
-\def\complexcurrentdate[#1]%
- {\bgroup
- \the\everycurrentdate
- \def\betweendates{\let\betweendates\dobetweendates}%
- % was \processcommacommandp[#1]\docomplexcurrentdate
- \safeedef\ascii{\empty#1}% keep encoded chars
- \@EA\processcommalist\@EA[\ascii]\docomplexcurrentdate
- \ifdim\lastskip=\datesignal\relax
- \unskip
- \fi
- \egroup}
-
-\def\docomplexcurrentdate#1%
- {\lowercase{\edef\!!stringa{#1}}% permits usage in \smallcapped
- \expanded{\processaction[\!!stringa]}% [#1]
- [ \v!day=>\betweendates\the\normalday,
- %\v!day+=>\betweendates\ordinaldaynumber\normalday,
- \v!day+=>\betweendates\convertnumber{\v!day+}\normalday,
- \v!month=>\betweendates\month\normalmonth,
- \v!year=>\betweendates\the\normalyear,
- \v!space=>\unskip\ \hskip\datesignal,% optimization -)
- \ =>\unskip\ \hskip\datesignal,% optimization -)
- d=>\convertnumber\v!day\normalday,
- %d+=>\ordinaldaynumber\normalday,
- d+=>\convertnumber{\v!day+}\normalday,
- m=>\convertnumber\v!month\normalmonth,
- j=>\convertnumber\v!year\normalyear,
- y=>\convertnumber\v!year\normalyear,
- w=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
- dd=>\ifnum\normalday >9 \else0\fi\the\normalday,
- %dd+=>\ordinaldaynumber{\ifnum\normalday >9 \else0\fi\the\normalday},
- dd+=>\convertnumber{\v!day+}{\ifnum\normalday >9 \else0\fi\the\normalday},
- mm=>\ifnum\normalmonth>9 \else0\fi\the\normalmonth,
- jj=>\expandafter\gobbletwoarguments\the\normalyear,
- yy=>\expandafter\gobbletwoarguments\the\normalyear,
- \v!weekday=>\betweendates\dayoftheweek\normalday\normalmonth\normalyear,
- \v!referral=>\expanded{\complexcurrentdate[\kenmerkdatumpatroon]},
- \s!unknown=>\unskip
- % #1 and not the lowercased \commalistelement, vietnamese has text
- % {} because #1 can have comma, like: {\ ,}
- {#1}%
- \hskip\datesignal
- \def\betweendates{\let\betweendates\dobetweendates}]}
-
-\def\simplecurrentdate
- {\expanded{\complexcurrentdate[\currentdatespecification]}}
-
-\definecomplexorsimple\currentdate
-
-\def\dodate[#1][#2]%
- {\bgroup
- \iffirstargument
- \getparameters[\??da][d=\normalday,m=\normalmonth,y=\normalyear,#1]%
- \normalday \@@dad\relax
- \normalmonth\@@dam\relax
- \normalyear \@@day\relax
- \ifsecondargument
- \currentdate[#2]%
- \else
- \currentdate
- \fi
- \else
- \currentdate
- \fi
- \egroup}
-
-\def\date
- {\dodoubleempty\dodate}
-
-%D \macros
-%D {currenttime}
-%D
-%D The currenttime is actually the jobtime. You can specify
-%D a pattern similar to the previous date macro using the
-%D keys \type {h}, \type {m} and a separator.
-
-\let\calculatecurrenttime\relax
-
-\let\currenthour \!!plusone
-\let\currentminute\!!plusone
-
-\appendtoks \calculatecurrenttime \to \everyjob
-
-\def\currenttimespecification{h,:,m}
-
-\def\complexcurrenttime[#1]%
- {\calculatecurrenttime
- \processallactionsinset[#1]
- [h=>\currenthour,m=>\currentminute,\s!unknown=>\commalistelement]}
-
-\def\simplecurrenttime
- {\expanded{\complexcurrenttime[\currenttimespecification]}}
-
-\definecomplexorsimple\currenttime
-
-%D Because we're dealing with dates, we also introduce a few
-%D day loops:
-%D
-%D \starttyping
-%D \processmonth{year}{month}{command}
-%D \processyear{year}{command}{before}{after}
-%D \stoptyping
-%D
-%D The counters \type {\normalyear}, \type {\normalmonth} and
-%D \type{\normalday} can be used for for date manipulations.
-
-\long\def\processmonth#1#2#3% year month command
- {\bgroup
- \getdayspermonth{#1}{#2}%
- \dostepwiserecurse1\numberofdays1%
- {\normalyear #1\relax
- \normalmonth#2\relax
- \normalday \recurselevel\relax
- #3}%
- \egroup}
-
-\def\lastmonth{12} % can be set to e.g. 1 when testing
-
-\long\def\processyear#1#2#3#4% year command before after
- {\bgroup
- \dorecurse\lastmonth
- {\normalyear #1\relax
- \normalmonth\recurselevel\relax
- #3\processmonth\normalyear\normalmonth{#2}#4}%
- \egroup}
-
-%D \macros
-%D {defineconversion, convertnumber}
-%D
-%D Conversion involves the macros that we implemented earlier
-%D in this module.
-%D
-%D \showsetup{defineconversion}
-%D \showsetup{convertnumber}
-%D
-%D We can feed this command with conversion macros as well as
-%D a set of conversion symbols. Both need a bit different
-%D treatment.
-%D
-%D \starttyping
-%D \defineconversion [roman] [\romannumerals]
-%D \defineconversion [set 1] [$\star$,$\bullet$,$\ast$]
-%D \stoptyping
-%D
-%D You can define a language dependent conversion with:
-%D
-%D \starttyping
-%D \defineconversion [en] [whatever] [\something]
-%D \stoptyping
-
-% \def\dodefineconversion[#1][#2]%
-% {\ConvertConstantAfter\doifinstringelse{,}{#2}
-% {\scratchcounter=0
-% \def\docommand##1%
-% {\advance\scratchcounter 1
-% \setvalue{\??cv#1\the\scratchcounter}{##1}}%
-% \processcommalist[#2]\docommand
-% \setvalue{\??cv#1}##1{\csname\??cv#1##1\endcsname}}
-% {\setvalue{\??cv#1}{#2}}}
-%
-% \def\defineconversion%
-% {\dodoubleargument\dodefineconversion}
-
-\def\defineconversion
- {\dotripleempty\dodefineconversion}
-
-\def\dodefineconversion[#1][#2][#3]%
- {\ifthirdargument
- \dododefineconversion[#1][#2][#3]%
- \else
- \dododefineconversion[][#1][#2]%
- \fi}
-
-%D \starttyping
-%D \def\dododefineconversion[#1][#2][#3]%
-%D {\ConvertConstantAfter\doifinstringelse{,}{#3}
-%D {\scratchcounter\zerocount
-%D \def\docommand##1%
-%D {\advance\scratchcounter \plusone
-%D \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
-%D \processcommalist[#3]\docommand
-%D \setvalue{\??cv#1#2}##1{\executeifdefined{\??cv#1#2##1}\unknown}} % catch out-of-range numbers
-%D {\setvalue{\??cv#1#2}{#3}}}
-%D \stoptyping
-
-%D This approach has the disadvantage that when you run out of
-%D symbols you get unknown results. The following implementation
-%D permits overloading of the converter:
-
-\def\dododefineconversion[#1][#2][#3]%
- {\ConvertConstantAfter\doifinstringelse{,}{#3}
- {\scratchcounter\zerocount
- \def\docommand##1%
- {\advance\scratchcounter \plusone
- \setvalue{\??cv#1#2\the\scratchcounter}{##1}}%
- \processcommalist[#3]\docommand
- \setevalue{\??cv#1#2}##1%
- {\noexpand\docheckedconversion{#1#2}{\the\scratchcounter}{##1}}}
- {\setvalue{\??cv#1#2}{#3}}}
-
-\def\docheckedconversion#1#2#3% class maxnumber number
- {\executeifdefined{\??cv#1#3}\unknown}
-
-%D When Gerben reported problems with footnote numbering per page,
-%D Taco came with the following wrap around solution. So, let's
-%D overload the checked conversion macro:
-
-\def\docheckedconversion#1#2#3% class maxnumber number
- {\executeifdefined{\??cv#1\modulatednumber{#2}{#3}}\unknown}
-
-%D Taco's modulo code is implemented in the system module
-%D \type {syst-con}.
-
-%D If a conversion is just a font switch then we need to make sure
-%D that the number is indeed end up as number in the input, so we
-%D need to handle the second argument.
-
-\def\convertnumber#1#2%
- {\csname\??cv
- \ifcsname\??cv\currentlanguage#1\endcsname
- \currentlanguage#1%
- \else\ifcsname\??cv#1\endcsname
- #1%
- \else
- \s!default
- \fi\fi
- \endcsname{\number#2}}
-
-\def\doifconversiondefinedelse#1%
- {\ifcsname\??cv\currentlanguage#1\endcsname
- \@EA\firstoftwoarguments
- \else\ifcsname\??cv#1\endcsname
- \@EAEAEA\firstoftwoarguments
- \else
- \@EAEAEA\secondoftwoarguments
- \fi\fi}
-
-\def\doifelseconversionnumber#1#2% slow but seldom used
- {\doifdefinedelse{\??cv#1#2}}
-
-% \defineconversion[ctx][c,o,n,t,e,x,t]
-%
-% \doloop{\doifelseconversionnumber{ctx}{\recurselevel}{[\recurselevel]}{\exitloop}}
-
-\defineconversion [\s!default] [\numbers]
-
-%D As longs as symbols are linked to levels or numbers, we can
-%D also use the conversion mechanism, but in for instance the
-%D itemization macros, we prefer symbols because they can more
-%D easier be (partially) redefined. Symbols are implemented
-%D in another module.
-
-\defineconversion [] [\numbers] % the default conversion
-
-\defineconversion [a] [\characters]
-\defineconversion [A] [\Characters]
-\defineconversion [AK] [\smallcapped\characters]
-\defineconversion [KA] [\smallcapped\characters]
-
-\defineconversion [n] [\numbers]
-\defineconversion [N] [\Numbers]
-\defineconversion [m] [\mediaeval]
-
-\defineconversion [i] [\romannumerals]
-\defineconversion [I] [\Romannumerals]
-\defineconversion [r] [\romannumerals]
-\defineconversion [R] [\Romannumerals]
-\defineconversion [KR] [\smallcapped\romannumerals]
-\defineconversion [RK] [\smallcapped\romannumerals]
-
-\defineconversion [g] [\greeknumerals]
-\defineconversion [G] [\Greeknumerals]
-
-\defineconversion [o] [\oldstylenumerals]
-\defineconversion [O] [\oldstylenumerals]
-\defineconversion [or] [\oldstyleromannumerals]
-
-\defineconversion [\v!character] [\character]
-\defineconversion [\v!Character] [\Character]
-
-\defineconversion [\v!characters] [\characters]
-\defineconversion [\v!Characters] [\Characters]
-
-\defineconversion [\v!numbers] [\numbers]
-\defineconversion [\v!Numbers] [\Numbers]
-\defineconversion [\v!mediaeval] [\mediaeval]
-
-\defineconversion [\v!romannumerals] [\romannumerals]
-\defineconversion [\v!Romannumerals] [\Romannumerals]
-
-\defineconversion [\v!greek] [\greeknumerals]
-\defineconversion [\v!Greek] [\Greeknumerals]
-
-\defineconversion [arabicnumerals] [\arabicnumerals]
-\defineconversion [persiannumerals] [\arabicnumerals]
-
-\defineconversion [month] [\doconvertmonthlong]
-\defineconversion [month:mnem] [\doconvertmonthshort]
-
-% Some bonus ones:
-
-\defineconversion [\v!empty] [\gobbleoneargument]
-\defineconversion [\v!none] [\numbers]
-
-\ifx\symbol\undefined \def\symbol[#1]{#1} \fi % todo
-
-\defineconversion
- [set 0]
- [{\symbol[bullet]},
- {\symbol[dash]},
- {\symbol[star]},
- {\symbol[triangle]},
- {\symbol[circle]},
- {\symbol[medcircle]},
- {\symbol[bigcircle]},
- {\symbol[square]}]
-
-\defineconversion
- [set 1]
- [\mathematics{\star},
- \mathematics{\star\star},
- \mathematics{\star\star\star},
- \mathematics{\ddagger},
- \mathematics{\ddagger\ddagger},
- \mathematics{\ddagger\ddagger\ddagger},
- \mathematics{\ast},
- \mathematics{\ast\ast},
- \mathematics{\ast\ast\ast}]
-
-\defineconversion
- [set 2]
- [\mathematics{*},
- \mathematics{\dag},
- \mathematics{\ddag},
- \mathematics{**},
- \mathematics{\dag\dag},
- \mathematics{\ddag\ddag},
- \mathematics{***},
- \mathematics{\dag\dag\dag},
- \mathematics{\ddag\ddag\ddag},
- \mathematics{****},
- \mathematics{\dag\dag\dag\dag},
- \mathematics{\ddag\ddag\ddag\ddag}]
-
-\defineconversion
- [set 3]
- [\mathematics{\star},
- \mathematics{\star\star},
- \mathematics{\star\star\star},
- \mathematics{\ddagger},
- \mathematics{\ddagger\ddagger},
- \mathematics{\ddagger\ddagger\ddagger},
- \mathematics{\P},
- \mathematics{\P\P},
- \mathematics{\P\P\P},
- \mathematics{\S},
- \mathematics{\S\S},
- \mathematics{\S\S\S},
- \mathematics{\ast},
- \mathematics{\ast\ast},
- \mathematics{\ast\ast\ast}]
-
-%D Plugins:
-
-\loadmarkfile{core-con}
-
-\protect \endinput
diff --git a/tex/context/base/core-ctx.lua b/tex/context/base/core-ctx.lua
index 90cd4cb3b..eb9003bf1 100644
--- a/tex/context/base/core-ctx.lua
+++ b/tex/context/base/core-ctx.lua
@@ -6,8 +6,9 @@ if not modules then modules = { } end modules ['supp-fil'] = {
license = "see context related readme files"
}
-commands = commands or { }
-commands.trace_prepfiles = false
+local trace_prepfiles = false trackers.register("resolvers.prepfiles", function(v) trace_prepfiles = v end)
+
+commands = commands or { }
local list, suffix, islocal, found = { }, "prep", false, false
@@ -17,11 +18,11 @@ function commands.loadctxpreplist()
local x = xml.load(ctlname)
if x then
islocal = xml.found(x,"ctx:preplist[@local=='yes']")
- if commands.trace_prepfiles then
+ if trace_prepfiles then
if islocal then
- ctx.writestatus("systems","loading ctx log file (local)") -- todo: m!systems
+ commands.writestatus("systems","loading ctx log file (local)") -- todo: m!systems
else
- ctx.writestatus("systems","loading ctx log file (specified)") -- todo: m!systems
+ commands.writestatus("systems","loading ctx log file (specified)") -- todo: m!systems
end
end
for r, d, k in xml.elements(x,"ctx:prepfile") do
@@ -31,8 +32,8 @@ function commands.loadctxpreplist()
name = file.basename(name)
end
local done = dk.at['done'] or 'no'
- if commands.trace_prepfiles then
- ctx.writestatus("systems","registering %s -> %s",done)
+ if trace_prepfiles then
+ commands.writestatus("systems","registering %s -> %s",done)
end
found = true
list[name] = done -- 'yes' or 'no'
@@ -41,26 +42,26 @@ function commands.loadctxpreplist()
end
end
-local function resolve(name)
- local function found(name)
- local prepname = name .. "." .. suffix
- local done = list[name]
- if done then
- if lfs.isfile(prepname) then
- if commands.trace_prepfiles then
- ctx.writestatus("systems", "preprocessing: using %s",prepname)
- end
- return prepname
- end
+-- -- --
+
+local function found(name) -- used in resolve
+ local prepname = name .. "." .. suffix
+ if list[name] and lfs.isfile(prepname) then
+ if trace_prepfiles then
+ commands.writestatus("systems", "preprocessing: using %s",prepname)
end
- return false
+ return prepname
end
+ return false
+end
+
+local function resolve(name) -- used a few times later on
local filename = file.collapse_path(name)
local prepname = islocal and found(file.basename(name))
if prepname then
return prepname
end
- local prepname = found(filename)
+ prepname = found(filename)
if prepname then
return prepname
end
diff --git a/tex/context/base/core-ctx.mkii b/tex/context/base/core-ctx.mkii
index 673d69c09..93cf8b4be 100644
--- a/tex/context/base/core-ctx.mkii
+++ b/tex/context/base/core-ctx.mkii
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Ctx Job Files}
+\writestatus{loading}{ConTeXt Core Macros / Job Control}
\unprotect
diff --git a/tex/context/base/core-ctx.mkiv b/tex/context/base/core-ctx.mkiv
index f2447ffd0..c401b09f0 100644
--- a/tex/context/base/core-ctx.mkiv
+++ b/tex/context/base/core-ctx.mkiv
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Ctx Job Files}
+\writestatus{loading}{ConTeXt Core Macros / Job Control}
\unprotect
@@ -23,5 +23,4 @@
\appendtoks\loadctxpreplist\to\everystarttext % will become: \prependtoks\loadctxpreplist\to\everyjob
-
\protect \endinput
diff --git a/tex/context/base/core-ctx.tex b/tex/context/base/core-ctx.tex
deleted file mode 100644
index 6eb70f029..000000000
--- a/tex/context/base/core-ctx.tex
+++ /dev/null
@@ -1,22 +0,0 @@
-%D \module
-%D [ file=core-ctx,
-%D version=2006.08.16, % old stuff
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Job Control,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Ctx Job Files}
-
-%D After some experimenting this code moved into the core. It
-%D overloades a few file reading macros and permits runtime
-%D conversion and job control.
-
-\loadmarkfile{core-ctx}
-
-\endinput
diff --git a/tex/context/base/core-dat.tex b/tex/context/base/core-dat.tex
index dc39f979f..44a82e1f3 100644
--- a/tex/context/base/core-dat.tex
+++ b/tex/context/base/core-dat.tex
@@ -13,73 +13,25 @@
% THIS WILL DISAPPEAR, I.E. BE MOVED TO A MODULE
-\writestatus{loading}{Context Database Support}
+\writestatus{loading}{ConTeXt Core Macros / Database Support}
-\startmessages dutch library: databases
- title: database
- 1: --
- 2: lokaal bestand --
- 3: globaal bestand --
- 4: onbekend bestand --
-\stopmessages
+% messages moved
-\startmessages english library: databases
- title: databases
- 1: --
- 2: local file --
- 3: global file --
- 4: unknown file --
-\stopmessages
+% messages moved
-\startmessages german library: databases
- title: Datenbank
- 1: --
- 2: lokale Datei --
- 3: globale Datei --
- 4: unbekannte Datei --
-\stopmessages
+% messages moved
% TOM :
-\startmessages czech library: databases
- title: databases
- 1: --
- 2: local file --
- 3: global file --
- 4: unknown file --
-\stopmessages
+% messages moved
-\startmessages italian library: databases
- title: database
- 1: --
- 2: file locale --
- 3: file globale --
- 4: file sconosciuto --
-\stopmessages
+% messages moved
-\startmessages norwegian library: databases
- title: databaser
- 1: --
- 2: lokal fil --
- 3: global fil --
- 4: ukjent fil --
-\stopmessages
+% messages moved
-\startmessages romanian library: databases
- title: baze de date
- 1: --
- 2: fisier local --
- 3: fisier global --
- 4: fisier necunoscut --
-\stopmessages
+% messages moved
-\startmessages french library: databases
- title: bases de données
- 1: --
- 2: fichier local --
- 3: fichier global --
- 4: fichier inconnu --
-\stopmessages
+% messages moved
\unprotect
diff --git a/tex/context/base/core-def.mkii b/tex/context/base/core-def.mkii
new file mode 100644
index 000000000..ea2d0ff15
--- /dev/null
+++ b/tex/context/base/core-def.mkii
@@ -0,0 +1,77 @@
+%D \module
+%D [ file=core-def,
+%D version=2002.05.07,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Defaults,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Defaults}
+
+%D Here we collect settings that cannot be done earlier due to
+%D depedencies. More code will moved to this module later.
+
+\unprotect
+
+\usesymbols[mis,mvs] % 'glm' no longer needed due to lm
+
+\usesymbols[nav] \setupsymbolset[navigation 1]
+
+\setupinteraction[\c!symbolset=navigation 1]
+
+% initialization order:
+
+%appendtoks \initializeluainstances \to \everyjob
+\appendtoks \showcontextbanner \to \everyjob
+\appendtoks \initializenewlinechar \to \everyjob
+\appendtoks \checksystemcommandmode \to \everyjob
+\appendtoks \calculatecurrenttime \to \everyjob
+\appendtoks \loadsystemfiles \to \everyjob
+
+\appendtoks \loadoptionfile \to \everyjob % can load files !
+
+\appendtoks \preloadfonts \to \everyjob
+\appendtoks \settopskip \to \everyjob
+\appendtoks \preloadlanguages \to \everyjob
+\appendtoks \preloadspecials \to \everyjob
+\appendtoks \openspecialfile \to \everyjob
+\appendtoks \openutilities \to \everyjob
+\appendtoks \splitjobfilename \to \everyjob
+\appendtoks \checknotes \to \everyjob % depends on bodyfont
+\appendtoks \initializeMPgraphics \to \everyjob % after loading system files
+\appendtoks \reportsystemcommandmode \to \everyjob
+\appendtoks \initializemainlanguage \to \everyjob
+\appendtoks \settrue\trackfilenames \to \everyjob
+\appendtoks \newbackgroundfalse \to \everyjob % global
+
+\ifdefined\initializepagecounters
+ \appendtoks \initializepagecounters \to \everyjob
+\fi
+
+\appendtoks \directsetup{*runtime:options} \to \everyjob % we could erase them afterwards % order can change
+\appendtoks \directsetup{*runtime:modules} \to \everyjob % we could erase them afterwards % order can change
+
+\appendtoks \checkpreprocessor \to \everyjob
+
+%appendtoks \page[\v!last] \page \to \everybye % moved to core-job, we need to do this cleaner
+\appendtoks \ifarrangingpages\poparrangedpages\fi \to \everybye
+\appendtoks \registerfileinfo[end]\jobname \to \everybye
+\appendtoks \savenofpages \to \everybye
+\appendtoks \savenofsubpages \to \everybye
+
+\appendtoks \closeutilities \to \everygoodbye
+\appendtoks \stopcopyingblocks \to \everygoodbye
+\appendtoks \closespecialfile \to \everygoodbye
+
+\prependtoks \resetutilities \to \everystarttext % moved 28-02-2002
+\prependtoks \loadtwopassdata \to \everystarttext % moved 28-02-2002
+\appendtoks \checkreferences \to \everystarttext % new 04-12-1999
+
+% \appendtoks\everyjob\expandafter{\the\everyjob\checkpreprocessor}\to\everydump
+
+\protect \endinput
diff --git a/tex/context/base/core-def.mkiv b/tex/context/base/core-def.mkiv
new file mode 100644
index 000000000..380b733bc
--- /dev/null
+++ b/tex/context/base/core-def.mkiv
@@ -0,0 +1,74 @@
+%D \module
+%D [ file=core-def,
+%D version=2002.05.07,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Defaults,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Defaults}
+
+%D Here we collect settings that cannot be done earlier due to
+%D depedencies. More code will moved to this module later.
+
+\unprotect
+
+\usesymbols[mis,mvs,nav]
+
+\setupsymbolset[navigation 1]
+
+\setupinteraction[\c!symbolset=navigation 1]
+
+% initialization order:
+
+\appendtoks \showcontextbanner \to \everyjob
+\appendtoks \initializenewlinechar \to \everyjob
+\appendtoks \checksystemcommandmode \to \everyjob
+\appendtoks \calculatecurrenttime \to \everyjob
+\appendtoks \loadsystemfiles \to \everyjob
+\appendtoks \loadoptionfile \to \everyjob % can load files !
+\appendtoks \preloadfonts \to \everyjob
+\appendtoks \settopskip \to \everyjob
+\appendtoks \preloadlanguages \to \everyjob
+\appendtoks \preloadspecials \to \everyjob
+\appendtoks \splitjobfilename \to \everyjob
+\appendtoks \checknotes \to \everyjob % depends on bodyfont
+\appendtoks \initializeMPgraphics \to \everyjob % after loading system files
+\appendtoks \reportsystemcommandmode \to \everyjob
+\appendtoks \initializemainlanguage \to \everyjob
+\appendtoks \MPLIBregister \to \everyjob
+\appendtoks \xmlinitialize \to \everyjob
+\appendtoks \settrue\trackfilenames \to \everyjob
+\appendtoks \newbackgroundfalse \to \everyjob % global
+\appendtoks \initializepagecounters \to \everyjob
+\appendtoks \directsetup{*runtime:options} \to \everyjob % we could erase them afterwards % order can change
+\appendtoks \directsetup{*runtime:modules} \to \everyjob % we could erase them afterwards % order can change
+\appendtoks \checkpreprocessor \to \everyjob
+
+%appendtoks \page[\v!last] \page \to \everybye % moved to core-job, we need to do this cleaner
+\appendtoks \ifarrangingpages\poparrangedpages\fi \to \everybye
+\appendtoks \registerfileinfo[end]\jobname \to \everybye
+
+\prependtoks \resetutilities \to \everystarttext % moved 28-02-2002
+
+\appendtoks \MPLIBallocate{1000} \to \everydump
+
+\prependtoks \resetallattributes \to \everybeforeoutput
+
+\appendtoks \the\everybackendshipout \to \everyshipout
+\prependtoks \the\everylastbackendshipout \to \everylastshipout
+
+% temporary here:
+
+\ifx\in \undefined\else \let\normalmathin \in \unexpanded\def\in {\mathortext\normalmathin \dospecialin } \fi
+\ifx\at \undefined\else \let\normalmathat \at \unexpanded\def\at {\mathortext\normalmathat \dospecialat } \fi
+\ifx\about\undefined\else \let\normalmathabout\about \unexpanded\def\about{\mathortext\normalmathabout\dospecialabout} \fi
+\ifx\from \undefined\else \let\normalmathfrom \from \unexpanded\def\from {\mathortext\normalmathfrom \dospecialfrom } \fi
+\ifx\over \undefined\else \let\normalmathover \over \unexpanded\def\over {\mathortext\normalmathover \dospecialabout} \fi
+
+\protect \endinput
diff --git a/tex/context/base/core-def.tex b/tex/context/base/core-def.tex
deleted file mode 100644
index c7c49858e..000000000
--- a/tex/context/base/core-def.tex
+++ /dev/null
@@ -1,27 +0,0 @@
-%D \module
-%D [ file=core-def,
-%D version=2002.05.07,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Defaults,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Defaults}
-
-%D Here we collect settings that cannot be done earlier due to
-%D depedencies. More code will moved to this module later.
-
-\unprotect
-
-\usesymbols[mis,mvs] % 'glm' no longer needed due to lm
-
-\usesymbols[nav] \setupsymbolset[navigation 1]
-
-\setupinteraction[\c!symbolset=navigation 1]
-
-\protect \endinput
diff --git a/tex/context/base/core-des.tex b/tex/context/base/core-des.tex
index 1794800a4..dc7136c40 100644
--- a/tex/context/base/core-des.tex
+++ b/tex/context/base/core-des.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Descriptions}
+\writestatus{loading}{ConTeXt Core Macros / Descriptions}
%D In order to be more flexible with theorems Aditya Mahajan added
%D support for titles and endsymbols. At the same time we some more
@@ -394,7 +394,7 @@
% which calls:
\def\@@makedescription#1%
- {\postponefootnotes % new, assumes grouping
+ {\postponenotes % new, assumes grouping
\def\currentdescription{#1}%
\executeifdefined
{@@description\descriptionparameter\c!location}
@@ -829,8 +829,7 @@
\def\do@@label[#1][#2]%
{\numberparameter{#1}\c!before
- \numberparameter{#1}\c!command
- {\doattributes{\@@thenumber{#1}}\c!headstyle\c!headcolor{\getvalue{\e!next#1}[#2]}}%
+ \numberparameter{#1}\c!command{\doattributes{\@@thenumber{#1}}\c!headstyle\c!headcolor{\getvalue{\e!next#1}[#2]}}%
\numberparameter{#1}\c!after}%
\def\do@@nextlabel[#1][#2]%
diff --git a/tex/context/base/core-env.mkii b/tex/context/base/core-env.mkii
new file mode 100644
index 000000000..a22594b27
--- /dev/null
+++ b/tex/context/base/core-env.mkii
@@ -0,0 +1,543 @@
+%D \module
+%D [ file=core-env, % was core-new
+%D version=1995.01.01, % wrong
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=New ones,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Environments}
+
+\unprotect
+
+% Clean labels:
+
+\bgroup % some day this will go away / we could use detokenize as well
+
+% actually we should handle all discretionaries here
+
+\catcode`:=\@@active
+
+\gdef\cleanuplabel#1%
+ {\begingroup
+ \let:\lettercolon
+ \xdef\cleanlabel{#1}%
+ \endgroup}
+
+\gdef\cleanupprefixedlabel#1#2%
+ {\begingroup
+ \let:\lettercolon
+ \xdef\cleanprefix{#1}%
+ \xdef\cleanlabel {#2}%
+ \endgroup}
+
+\gdef\protectlabels
+ {\let:\lettercolon}
+
+\global\def\blabelgroup {\begingroup \let:\lettercolon}
+\global\let\elabelgroup \endgroup
+
+\gdef\labelcsname
+ {\begingroup\let:\lettercolon
+ \expandafter\endgroup\csname}
+
+\gdef\labelvalue#1%
+ {\labelcsname#1\endcsname}
+
+\egroup
+
+%D Modes:
+%D
+%D \starttyping
+%D \enablemode[screen,paper,bound]
+%D
+%D \doifmodeelse {paper} {this} {that}
+%D \doifmode {paper,screen} {this}
+%D \doifnotmode {paper,bound} {that}
+%D
+%D \startmode [list]
+%D \stopmode
+%D
+%D \startnotmode [list]
+%D \stopnotmode
+%D \stoptyping
+%D
+%D system modes have a * as prefix
+%D
+%D Sometimes, we want to prevent a mode for being set. Think
+%D of situations where a style enables a mode, but an outer
+%D level style does not want that. Preventing can be
+%D considered a permanent disabling on forehand.
+
+\def\@mode@{@md@}
+
+\def\systemmodeprefix{*}
+
+\def\disabledmode {0}
+\def\enabledmode {1}
+\def\preventedmode {2}
+
+% fast internal ones
+
+\def\setmode #1{\@EA\let\csname\@mode@#1\endcsname\enabledmode }
+\def\resetmode#1{\@EA\let\csname\@mode@#1\endcsname\disabledmode}
+
+\def\setsystemmode #1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\enabledmode }
+\def\resetsystemmode#1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\disabledmode}
+
+% user ones
+
+\def\preventmode{\unprotect\dopreventmode}
+\def\enablemode {\unprotect\doenablemode }
+\def\disablemode{\unprotect\dodisablemode}
+
+\def\dopreventmode[#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dodopreventmode}
+\def\doenablemode [#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dodoenablemode }
+\def\dodisablemode[#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dododisablemode}
+
+\def\dodopreventmode#1%
+ {\@EA\let\csname\@mode@#1\endcsname\preventedmode}
+
+\def\dodoenablemode#1% mode can be relax
+ {\ifcase0\csname\@mode@#1\endcsname\relax
+ \@EA\let\csname\@mode@#1\endcsname\enabledmode
+ \fi}
+
+\def\dododisablemode#1%
+ {\ifcase0\csname\@mode@#1\endcsname\or
+ \@EA\let\csname\@mode@#1\endcsname\disabledmode
+ \fi}
+
+% handy for mp
+
+\def\booleanmodevalue#1% can be \relax
+ {\expandafter\ifx\csname\@mode@#1\endcsname\relax
+ fals%
+ \else\ifnum0\csname\@mode@#1\endcsname=0
+ fals%
+ \else
+ tru%
+ \fi\fi e}
+
+% check macros
+
+\newif\ifcheckedmode
+
+\def\dodocheckformode#1%
+ {\ifcase0\csname\@mode@#1\endcsname\or\checkedmodetrue\fi}
+
+\def\docheckformode#1#2#3% will be sped up with a quit
+ {\cleanuplabel{#3}%
+ \protect\checkedmodefalse\rawprocesscommacommand[\cleanlabel]\dodocheckformode
+ \ifcheckedmode\@EA#1\else\@EA#2\fi}
+
+\def\dodocheckforallmodes#1%
+ {\ifcase0\csname\@mode@#1\endcsname\relax\checkedmodefalse\or\or\checkedmodefalse\fi}
+
+\def\docheckforallmodes#1#2#3% will be sped up with a quit
+ {\cleanuplabel{#3}%
+ \protect\checkedmodetrue\rawprocesscommacommand[\cleanlabel]\dodocheckforallmodes
+ \ifcheckedmode\@EA#1\else\@EA#2\fi}
+
+% simple ones
+
+\def\doifmodeelse{\unprotect\dodoifmodeelse}
+\def\doifmode {\unprotect\dodoifmode}
+\def\doifnotmode {\unprotect\dodoifnotmode}
+\def\startmode {\unprotect\dostartmode}
+\def\startnotmode{\unprotect\dostartnotmode}
+
+\def\dodoifmodeelse
+ {\docheckformode\firstoftwoarguments\secondoftwoarguments}
+
+\def\dodoifmode
+ {\docheckformode\firstofoneargument\gobbleoneargument}
+
+\def\dodoifnotmode
+ {\docheckformode\gobbleoneargument\firstofoneargument}
+
+\long\def\dostartmode[#1]%
+ {\docheckformode\donothing\dostopmode{#1}}
+
+\long\def\dostartnotmode[#1]%
+ {\docheckformode\dostopnotmode\donothing{#1}}
+
+\let\stopmode \donothing
+\let\stopnotmode\donothing
+
+\long\def\dostopmode #1\stopmode {}
+\long\def\dostopnotmode#1\stopnotmode{}
+
+\def\doifallmodeselse{\unprotect\dodoifallmodeselse}
+\def\doifallmodes {\unprotect\dodoifallmodes}
+\def\doifnotallmodes {\unprotect\dodoifnotallmodes}
+\def\startallmodes {\unprotect\dostartallmodes}
+\def\startnotallmodes{\unprotect\dostartnotallmodes}
+
+\def\dodoifallmodeselse
+ {\docheckforallmodes\firstoftwoarguments\secondoftwoarguments}
+
+\def\dodoifallmodes
+ {\docheckforallmodes\firstofoneargument\gobbleoneargument}
+
+\def\dodoifnotallmodes
+ {\docheckforallmodes\gobbleoneargument\firstofoneargument}
+
+\long\def\dostartallmodes[#1]%
+ {\docheckforallmodes\donothing\dostopallmodes{#1}}
+
+\long\def\dostartnotallmodes[#1]%
+ {\docheckforallmodes\dostopnotallmodes\donothing{#1}}
+
+\let\stopallmodes \donothing
+\let\stopnotallmodes\donothing
+
+\long\def\dostopallmodes #1\stopallmodes {}
+\long\def\dostopnotallmodes#1\stopnotallmodes{}
+
+% Setups
+
+\let\startsetups\relax % to please dep checker
+\let\stopsetups \relax % to please dep checker
+
+\expanded
+ {\long\def\@EA\noexpand\csname\e!start\v!setups\endcsname
+ {\begingroup\noexpand\doifnextoptionalelse
+ {\noexpand\startsetupsA\@EA\noexpand\csname\e!stop\v!setups\endcsname}
+ {\noexpand\startsetupsB\@EA\noexpand\csname\e!stop\v!setups\endcsname}}}
+
+\letvalue{\e!stop\v!setups}\relax
+
+\unexpanded \def\setups{\doifnextbgroupelse\dosetupsA\dosetupsB} % {..} or [..]
+\unexpanded \def\setup {\doifnextbgroupelse\dosetups \dosetupsC} % {..} or [..]
+
+\def\dosetupsA #1{\cleanuplabel{#1}\processcommacommand[\cleanlabel]\dosetups} % {..}
+\def\dosetupsB[#1]{\cleanuplabel{#1}\processcommacommand[\cleanlabel]\dosetups} % [..]
+\def\dosetupsC[#1]{\cleanuplabel{#1}\dosetups\cleanlabel} % [..]
+
+% \def\dosetups#1% the grid option will be extended to other main modes
+% {\executeifdefined{\??su\ifgridsnapping\v!grid\fi:#1}
+% {\executeifdefined{\??su :#1}\gobbleoneargument}\empty} % takes one argument
+%
+% \def\setupwithargument#1% the grid option will be extended to other main modes
+% {\executeifdefined{\??su:#1}\gobbleoneargument}
+
+% better:
+
+% \def\dosetups#1% the grid option will be extended to other main modes
+% {\executeifdefined{\??su\ifgridsnapping\v!grid\fi:#1}
+% {\executeifdefined{\??su :#1}\gobbleoneargument}\empty} % takes one argument
+%
+% \def\setupwithargument#1% the grid option will be extended to other main modes
+% {\executeifdefined{\??su:#1}\gobbleoneargument}
+
+% faster:
+
+\letvalue{\??su:\letterpercent}\gobbleoneargument
+
+\def\dosetups#1% the grid option will be extended to other main modes
+ {\csname\??su
+ \ifgridsnapping
+ \ifcsname\??su\v!grid:#1\endcsname\v!grid:#1\else\ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi\fi
+ \else
+ \ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi
+ \fi
+ \endcsname\empty} % takes one argument
+
+\def\setupwithargument#1% the grid option will be extended to other main modes
+ {\csname\??su:\ifcsname\??su:#1\endcsname#1\else\letterpercent\fi\endcsname}
+
+\let\directsetup\dosetups
+
+% somehow fails ...
+%
+% \letvalue{\??su:..}\gobbleoneargument
+%
+% \def\dosetups#1% the grid option will be extended to other main modes
+% {\csname \??su
+% \ifcsname\??su\ifgridsnapping\v!grid\fi:#1\endcsname\v!grid:#1\else
+% \ifcsname\??su :#1\endcsname :#1\else
+% :..\fi\fi
+% \endcsname\empty} % takes one argument
+%
+% \def\setupwithargument#1% the grid option will be extended to other main modes
+% {\csname\??su:\ifcsname\??su:#1\endcsname#1\else..\fi\endcsname}
+
+\let\directsetup\dosetups
+
+\def\doifsetupselse#1% to be done: grid
+ {\doifdefinedelse{\??su:#1}}
+
+\chardef\setupseolmode\plusone
+
+\def\startsetups {\xxstartsetups\plusone \stopsetups } \let\stopsetups \relax
+\def\startlocalsetups{\xxstartsetups\plusone \stoplocalsetups} \let\stoplocalsetups\relax
+\def\startrawsetups {\xxstartsetups\zerocount\stoprawsetups } \let\stoprawsetups \relax
+\def\startxmlsetups {\xxstartsetups\plustwo \stopxmlsetups } \let\stopxmlsetups \relax
+
+\def\xxstartsetups#1#2%
+ {\begingroup\chardef\setupseolmode#1\doifnextoptionalelse{\startsetupsA#2}{\startsetupsB#2}}
+
+\def\startsetupsA#1% [ ] delimited
+ {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
+ \dotripleempty\dostartsetups[#1]}
+
+\def\startsetupsB#1#2 % space delimited
+ {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
+ \dodostartsetups#1\empty{#2}}
+
+\def\startsetupsC[#1][#2][#3]{\dodostartsetups#1{#2}{#3}} % [..] [..]
+\def\startsetupsD[#1][#2][#3]{\dodostartsetups#1\empty{#2}} % [..]
+
+\def\dostartsetups
+ {\ifthirdargument\@EA\startsetupsC\else\@EA\startsetupsD\fi}
+
+% \long\def\dodostartsetups#1#2#3% watch out: not \grabuntil
+% {\dograbuntil#1{\endgroup\dodoglobal\long\setvalue{\??su#2:#3}}} % \doglobal
+%
+% better:
+
+% \long\def\dodostartsetups#1#2#3% watch out: not \grabuntil
+% {\cleanuplabel{\??su#2:#3}\dograbuntil#1{\endgroup\dodoglobal\long\setvalue\cleanlabel}} % \doglobal
+
+% \long\def\dodostartsetups#1#2#3%
+% {\cleanuplabel{\??su#2:#3}%
+% \long\def\dododostartsetups##1#1{\endgroup\dodoglobal\long\setvalue\cleanlabel####1{##1}}\dododostartsetups}
+
+\long\def\dodostartsetups#1#2#3%
+ {\cleanuplabel{\??su#2:#3}%
+ \long\def\dododostartsetups##1#1%
+ {\endgroup
+ \dodoglobal % bah
+ \long\expandafter\setvalue\expandafter\cleanlabel\expandafter####\expandafter1\expandafter{##1}}%
+ \dododostartsetups\empty} % the empty trick prevents the { } in {arg} from being eaten up
+
+\def\systemsetupsprefix{*}
+
+\def\systemsetups#1{\dosetups{\systemsetupsprefix#1}}
+
+\def\resetsetups[#1]% see x-fo for usage
+ {\ifundefined{\??su\ifgridsnapping\v!grid\fi:#1}%
+ \dodoglobal\letbeundefined{\??su:#1}%
+ \else
+ \dodoglobal\letbeundefined{\??su\ifgridsnapping\v!grid\fi:#1}%
+ \fi}
+
+% or
+%
+% \def\resetsetups[#1]%
+% {\letbeundefined
+% {\??su:%
+% \ifundefined{\??su\ifgridsnapping\v!grid\fi:#1}#1\else\ifgridsnapping\v!grid\fi%
+% #1}}
+
+%D new and beta and will become a module instead
+
+\def\defineshortcut
+ {\dotripleargument\dodefineshortcut}
+
+\def\dodefineshortcut[#1][#2][#3]%
+ {\ifthirdargument
+ \doifelsenothing{#1}
+ {\dododefineshortcut[<>][#2][#3]}
+ {\dododefineshortcut[#1][#2][#3]}%
+ \else\ifsecondargument
+ \dododefineshortcut[<>][#1][#2]%
+ \else
+ \dododefineshortcut[<>][][#1]%
+ \fi\fi}
+
+\def\dododefineshortcut[#1#2][#3][#4]% #1 is the trigger, #2 the delimiter/tag
+ {\doifundefined{\??te\??te\string#2}{\letvalue{\??te\??te\string#2}=#1}%
+ \defineactivecharacter #1 {\@EA\doshortcut\string#2} %
+ \getparameters
+ [\??te\string#2#3]
+ [\c!commands=,\c!command=,\c!style=,\c!color=,#4]}
+
+\def\doshortcut#1%
+ {\ifmmode
+ \getvalue{\??te\??te#1}%
+ \else
+ \bgroup
+ \catcode`#1=\@@other
+ \def\dodoshortcut##1#1%
+ {\def\shorttag{\??te#1}%
+ \def\shortcut{##1}%
+ \dododoshortcut##1:\end}%
+ \@EA\dodoshortcut
+ \fi}
+
+\def\dododoshortcut#1:#2\end
+ {\doifelsenothing{#2}
+ {\doifundefinedelse{\shorttag\c!commands}
+ {\shortcut}
+ {\@EA\dodododoshortcut\@EA\shorttag\@EA:\shortcut:\end}}
+ {\doifundefinedelse{\shorttag#1\c!commands}
+ {\shortcut}
+ {\dodododoshortcut\shorttag#1:#2\end}}%
+ \egroup}
+
+\def\dodododoshortcut#1:#2:\end
+ {\getvalue{#1\c!commands}%
+ \doattributes{#1}\c!style\c!color{\getvalue{#1\c!command}{#2}}}
+
+%D \defineshortcut [style=type]
+%D \defineshortcut [b] [style=bold]
+%D \defineshortcut [e] [style=\em]
+%D \defineshortcut [t] [style=type]
+%D \defineshortcut [c] [style=cap]
+%D \defineshortcut [k] [style=cap]
+%D \defineshortcut [u] [style=type,command=\hyphenatedurl]
+%D
+%D \startlines
+%D test test
+%D test test
+%D test test
+%D test test
+%D zus<>zo zus<:>zo zus<::>zo
+%D test test dat (ziezo)
+%D test test dat (:ziezo)
+%D test test dat (ziezo:)
+%D test test dat (zi:ezo:)
+%D well, looks fuzzy
+%D $10<20$
+%D \stoplines
+%D
+%D \defineshortcut [<>] [i] [style=\it]
+%D \defineshortcut [()] [b] [style=\bf]
+%D \defineshortcut [++] [s] [style=\sl]
+%D \defineshortcut [//] [u] [style=\underbars]
+%D \defineshortcut [--] [a] [style=\overstrike]
+%D
+%D \startlines
+%D it seems well
+%D it seems (b:to work) well
+%D it seems +s:to work+ well
+%D it seems /u:to work/ well
+%D it seems -a:to work- well
+%D \stoplines
+
+%D \macros
+%D {setvariables,getvariable,getvariabledefault}
+%D
+%D \starttyping
+%D \setvariables[xx][title=]
+%D \setvariables[xx][title=test test]
+%D \setvariables[xx][title=test $x=1$ test] % fatal error reported
+%D \setvariables[xx][title=test {$x=1$} test]
+%D \setvariables[xx][title] % fatal error reported
+%D \setvariables[xx][titletitel=e]
+%D \stoptyping
+
+\def\??vars{@@vars}
+
+\def\setvariables {\dotripleargument\dosetvariables[\getrawparameters ]}
+\def\setevariables{\dotripleargument\dosetvariables[\getraweparameters]}
+\def\setgvariables{\dotripleargument\dosetvariables[\getrawgparameters]}
+\def\setxvariables{\dotripleargument\dosetvariables[\getrawxparameters]}
+
+\def\globalsetvariables % obsolete
+ {\dotripleargument\dosetvariables[\globalgetrawparameters]}
+
+\long\def\dosetvariables[#1][#2][#3]% tricky, test on s-pre-60
+ {\errorisfataltrue
+ \doifelse{#2}\currentvariableclass
+ {#1[\??vars:#2:][#3]}%
+ {\pushmacro\currentvariableclass
+ \def\currentvariableclass{#2}%
+ \getvariable{#2}\s!reset
+ #1[\??vars:#2:][#3]%
+ \getvariable{#2}\s!set
+ \popmacro\currentvariableclass}%
+ \errorisfatalfalse}
+
+\long\def\setvariable #1#2#3{\long\setvalue {\??vars:#1:#2}{#3}}
+\long\def\setevariable#1#2#3{\long\setevalue{\??vars:#1:#2}{#3}}
+\long\def\setgvariable#1#2#3{\long\setgvalue{\??vars:#1:#2}{#3}}
+\long\def\setxvariable#1#2#3{\long\setxvalue{\??vars:#1:#2}{#3}}
+
+\def\getvariable#1#2% to be sped up
+ {\csname
+ \ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi
+ \endcsname}
+
+\def\showvariable#1#2%
+ {\showvalue{\ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi}}
+
+\let\currentvariableclass\empty
+
+%D \macros
+%D {doifelsevariable,doifvariable,doifnotvariable}
+%D
+%D A few trivial macros:
+
+\def\doifelsevariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\doifvariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\firstofoneargument
+ \else
+ \expandafter\gobbleoneargument
+ \fi}
+
+\def\doifnotvariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\firstofoneargument
+ \fi}
+
+\def\getvariabledefault#1#2% #3% can be command, so no ifcsname here
+ {\executeifdefined{\??vars:#1:#2}}% {#3}
+
+%D \macros
+%D {checkvariables}
+%D
+%D I'll probably forget that this on exists.
+
+\def\checkvariables
+ {\dodoubleargument\docheckvariables}
+
+\def\docheckvariables
+ {\dogetparameters\docheckrawvalue}
+
+\def\docheckrawvalue#1#2#3%
+ {\doifundefined {\??vars:#1:#2}{\setvalue{\??vars:#1:#2}{#3}}
+ {\doifvaluenothing{\??vars:#1:#2}{\setvalue{\??vars:#1:#2}{#3}}}}
+
+% \def\setupenv{\dodoubleargument\rawgetparameters[\??en]}
+%
+% \def\doifenvelse#1{\doifdefinedelse{\??en#1}} % speed up
+% \def\doifenv #1{\doifdefined {\??en#1}} % speed up
+% \def\doifnotenv #1{\doifundefined {\??en#1}} % speed up
+%
+% \def\env#1{\csname\??en#1\endcsname}
+%
+% \def\envvar#1#2%
+% {\ifcsname\??en#1\endcsname
+% \csname\??en#1\endcsname\else#2%
+% \fi}
+
+% low level change, now also accessible as \getvariable{environment}{...}; the
+% next macros will become obsolete some day in favor of normal variables
+
+\def\s!environment{environment}
+
+\def\setupenv {\dotripleargument\dosetvariables[\getrawparameters][\s!environment]}
+\def\doifenvelse{\doifelsevariable \s!environment}
+\def\doifenv {\doifvariable \s!environment}
+\def\doifnotenv {\doifnotvariable \s!environment}
+\def\env {\getvariable \s!environment}
+\def\envvar {\getvariabledefault\s!environment}
+
+\protect \endinput
diff --git a/tex/context/base/core-env.mkiv b/tex/context/base/core-env.mkiv
new file mode 100644
index 000000000..47bd7549d
--- /dev/null
+++ b/tex/context/base/core-env.mkiv
@@ -0,0 +1,472 @@
+%D \module
+%D [ file=core-env, % was core-new
+%D version=1995.01.01, % wrong
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=New ones,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Environments}
+
+\unprotect
+
+%D Clean labels (no longer needed in \MKIV\ but we keep the grouping
+%D till we hav ea full separation of code.):
+
+\def\cleanuplabel#1%
+ {\xdef\cleanlabel{#1}}
+
+\def\cleanupprefixedlabel#1#2%
+ {\xdef\cleanprefix{#1}%
+ \xdef\cleanlabel {#2}}
+
+\let\protectlabels\donothing
+\let\blabelgroup \begingroup % obsolete
+\let\elabelgroup \endgroup % obsolete
+\let\labelcsname \csname
+\let\labelvalue \getvalue
+
+%D Modes:
+%D
+%D \starttyping
+%D \enablemode[screen,paper,bound]
+%D
+%D \doifmodeelse {paper} {this} {that}
+%D \doifmode {paper,screen} {this}
+%D \doifnotmode {paper,bound} {that}
+%D
+%D \startmode [list]
+%D \stopmode
+%D
+%D \startnotmode [list]
+%D \stopnotmode
+%D \stoptyping
+%D
+%D system modes have a * as prefix
+%D
+%D Sometimes, we want to prevent a mode for being set. Think
+%D of situations where a style enables a mode, but an outer
+%D level style does not want that. Preventing can be
+%D considered a permanent disabling on forehand.
+
+\def\@mode@{@md@}
+
+\def\systemmodeprefix{*}
+
+\def\disabledmode {0} % no chardefs
+\def\enabledmode {1}
+\def\preventedmode{2}
+
+% fast internal ones
+
+\def\setmode #1{\@EA\let\csname\@mode@#1\endcsname\enabledmode }
+\def\resetmode#1{\@EA\let\csname\@mode@#1\endcsname\disabledmode}
+
+\def\setsystemmode #1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\enabledmode }
+\def\resetsystemmode#1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\disabledmode}
+
+% user ones
+
+\def\preventmode{\unprotect\dopreventmode}
+\def\enablemode {\unprotect\doenablemode }
+\def\disablemode{\unprotect\dodisablemode}
+
+\def\dopreventmode[#1]{\protect\rawprocesscommacommand[#1]\dodopreventmode}
+\def\doenablemode [#1]{\protect\rawprocesscommacommand[#1]\dodoenablemode }
+\def\dodisablemode[#1]{\protect\rawprocesscommacommand[#1]\dododisablemode}
+
+\def\dodopreventmode#1%
+ {\@EA\let\csname\@mode@#1\endcsname\preventedmode}
+
+\def\dodoenablemode#1% mode can be relax
+ {\ifcase0\csname\@mode@#1\endcsname\relax
+ \@EA\let\csname\@mode@#1\endcsname\enabledmode
+ \fi}
+
+\def\dododisablemode#1%
+ {\ifcase0\csname\@mode@#1\endcsname\or
+ \@EA\let\csname\@mode@#1\endcsname\disabledmode
+ \fi}
+
+% handy for mp
+
+\def\booleanmodevalue#1% can be \relax
+ {\expandafter\ifx\csname\@mode@#1\endcsname\relax
+ fals%
+ \else\ifnum0\csname\@mode@#1\endcsname=0
+ fals%
+ \else
+ tru%
+ \fi\fi e}
+
+% check macros
+
+\newif\ifcheckedmode
+
+\def\dodocheckformode#1%
+ {\ifcase0\csname\@mode@#1\endcsname\or\checkedmodetrue\fi}
+
+\def\docheckformode#1#2#3% will be sped up with a quit
+ {\protect\checkedmodefalse\rawprocesscommacommand[#3]\dodocheckformode
+ \ifcheckedmode\@EA#1\else\@EA#2\fi}
+
+\def\dodocheckforallmodes#1%
+ {\ifcase0\csname\@mode@#1\endcsname\relax\checkedmodefalse\or\or\checkedmodefalse\fi}
+
+\def\docheckforallmodes#1#2#3% will be sped up with a quit
+ {\protect\checkedmodetrue\rawprocesscommacommand[#3]\dodocheckforallmodes
+ \ifcheckedmode\@EA#1\else\@EA#2\fi}
+
+% simple ones
+
+\def\doifmodeelse{\unprotect\dodoifmodeelse}
+\def\doifmode {\unprotect\dodoifmode}
+\def\doifnotmode {\unprotect\dodoifnotmode}
+\def\startmode {\unprotect\dostartmode}
+\def\startnotmode{\unprotect\dostartnotmode}
+
+\def\dodoifmodeelse
+ {\docheckformode\firstoftwoarguments\secondoftwoarguments}
+
+\def\dodoifmode
+ {\docheckformode\firstofoneargument\gobbleoneargument}
+
+\def\dodoifnotmode
+ {\docheckformode\gobbleoneargument\firstofoneargument}
+
+\long\def\dostartmode[#1]%
+ {\docheckformode\donothing\dostopmode{#1}}
+
+\long\def\dostartnotmode[#1]%
+ {\docheckformode\dostopnotmode\donothing{#1}}
+
+\let\stopmode \donothing
+\let\stopnotmode\donothing
+
+\long\def\dostopmode #1\stopmode {}
+\long\def\dostopnotmode#1\stopnotmode{}
+
+\def\doifallmodeselse{\unprotect\dodoifallmodeselse}
+\def\doifallmodes {\unprotect\dodoifallmodes}
+\def\doifnotallmodes {\unprotect\dodoifnotallmodes}
+\def\startallmodes {\unprotect\dostartallmodes}
+\def\startnotallmodes{\unprotect\dostartnotallmodes}
+
+\def\dodoifallmodeselse
+ {\docheckforallmodes\firstoftwoarguments\secondoftwoarguments}
+
+\def\dodoifallmodes
+ {\docheckforallmodes\firstofoneargument\gobbleoneargument}
+
+\def\dodoifnotallmodes
+ {\docheckforallmodes\gobbleoneargument\firstofoneargument}
+
+\long\def\dostartallmodes[#1]%
+ {\docheckforallmodes\donothing\dostopallmodes{#1}}
+
+\long\def\dostartnotallmodes[#1]%
+ {\docheckforallmodes\dostopnotallmodes\donothing{#1}}
+
+\let\stopallmodes \donothing
+\let\stopnotallmodes\donothing
+
+\long\def\dostopallmodes #1\stopallmodes {}
+\long\def\dostopnotallmodes#1\stopnotallmodes{}
+
+%D Setups:
+
+\let\startsetups\relax % to please dep checker
+\let\stopsetups \relax % to please dep checker
+
+\expanded
+ {\long\def\@EA\noexpand\csname\e!start\v!setups\endcsname
+ {\begingroup\noexpand\doifnextoptionalelse
+ {\noexpand\startsetupsA\@EA\noexpand\csname\e!stop\v!setups\endcsname}
+ {\noexpand\startsetupsB\@EA\noexpand\csname\e!stop\v!setups\endcsname}}}
+
+\letvalue{\e!stop\v!setups}\relax
+
+\unexpanded \def\setups{\doifnextbgroupelse\dosetupsA\dosetupsB} % {..} or [..]
+\unexpanded \def\setup {\doifnextbgroupelse\dosetups \dosetupsC} % {..} or [..]
+
+\def\dosetupsA #1{\processcommacommand[#1]\dosetups} % {..}
+\def\dosetupsB[#1]{\processcommacommand[#1]\dosetups} % [..]
+\def\dosetupsC[#1]{\dosetups{#1}} % [..]
+
+\letvalue{\??su:\letterpercent}\gobbleoneargument
+
+\def\dosetups#1% the grid option will be extended to other main modes
+ {\csname\??su
+ \ifgridsnapping
+ \ifcsname\??su\v!grid:#1\endcsname\v!grid:#1\else\ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi\fi
+ \else
+ \ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi
+ \fi
+ \endcsname\empty} % takes one argument
+
+\def\setupwithargument#1% the grid option will be extended to other main modes
+ {\csname\??su:\ifcsname\??su:#1\endcsname#1\else\letterpercent\fi\endcsname}
+
+\let\directsetup\dosetups
+
+\def\doifsetupselse#1% to be done: grid
+ {\doifdefinedelse{\??su:#1}}
+
+\chardef\setupseolmode\plusone
+
+\def\startsetups {\xxstartsetups\plusone \stopsetups } \let\stopsetups \relax
+\def\startlocalsetups{\xxstartsetups\plusone \stoplocalsetups} \let\stoplocalsetups\relax
+\def\startrawsetups {\xxstartsetups\zerocount\stoprawsetups } \let\stoprawsetups \relax
+\def\startxmlsetups {\xxstartsetups\plustwo \stopxmlsetups } \let\stopxmlsetups \relax
+
+\def\xxstartsetups#1#2%
+ {\begingroup\let\setupseolmode#1\doifnextoptionalelse{\startsetupsA#2}{\startsetupsB#2}}
+
+\def\startsetupsA#1% [ ] delimited
+ {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
+ \dotripleempty\dostartsetups[#1]}
+
+\def\startsetupsB#1#2 % space delimited
+ {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
+ \dodostartsetups#1\empty{#2}}
+
+\def\startsetupsC[#1][#2][#3]{\dodostartsetups#1{#2}{#3}} % [..] [..]
+\def\startsetupsD[#1][#2][#3]{\dodostartsetups#1\empty{#2}} % [..]
+
+\def\dostartsetups
+ {\ifthirdargument\@EA\startsetupsC\else\@EA\startsetupsD\fi}
+
+\long\def\dodostartsetups#1#2#3%
+ {\long\def\dododostartsetups##1#1%
+ {\endgroup
+ \dodoglobal % bah
+ \long\expandafter\def\csname\??su#2:#3\expandafter\endcsname\expandafter####\expandafter1\expandafter{##1}}%
+ \dododostartsetups\empty} % the empty trick prevents the { } in {arg} from being eaten up
+
+\def\systemsetupsprefix{*}
+
+\def\systemsetups#1{\dosetups{\systemsetupsprefix#1}}
+
+\def\resetsetups[#1]% see x-fo for usage
+ {\ifcsname\??su\ifgridsnapping\v!grid\fi:#1\endcsname
+ \dodoglobal\letbeundefined{\??su\ifgridsnapping\v!grid\fi:#1}%
+ \else
+ \dodoglobal\letbeundefined{\??su:#1}%
+ \fi}
+
+%D \defineshortcut [style=type]
+%D \defineshortcut [b] [style=bold]
+%D \defineshortcut [e] [style=\em]
+%D \defineshortcut [t] [style=type]
+%D \defineshortcut [c] [style=cap]
+%D \defineshortcut [k] [style=cap]
+%D \defineshortcut [u] [style=type,command=\hyphenatedurl]
+%D
+%D \startlines
+%D test test
+%D test test
+%D test test
+%D test test
+%D zus<>zo zus<:>zo zus<::>zo
+%D test test dat (ziezo)
+%D test test dat (:ziezo)
+%D test test dat (ziezo:)
+%D test test dat (zi:ezo:)
+%D well, looks fuzzy
+%D $10<20$
+%D \stoplines
+%D
+%D \defineshortcut [<>] [i] [style=\it]
+%D \defineshortcut [()] [b] [style=\bf]
+%D \defineshortcut [++] [s] [style=\sl]
+%D \defineshortcut [//] [u] [style=\underbars]
+%D \defineshortcut [--] [a] [style=\overstrike]
+%D
+%D \startlines
+%D it seems well
+%D it seems (b:to work) well
+%D it seems +s:to work+ well
+%D it seems /u:to work/ well
+%D it seems -a:to work- well
+%D \stoplines
+
+\def\defineshortcut
+ {\dotripleargument\dodefineshortcut}
+
+\def\dodefineshortcut[#1][#2][#3]%
+ {\ifthirdargument
+ \doifelsenothing{#1}
+ {\dododefineshortcut[<>][#2][#3]}
+ {\dododefineshortcut[#1][#2][#3]}%
+ \else\ifsecondargument
+ \dododefineshortcut[<>][#1][#2]%
+ \else
+ \dododefineshortcut[<>][][#1]%
+ \fi\fi}
+
+\def\dododefineshortcut[#1#2][#3][#4]% #1 is the trigger, #2 the delimiter/tag
+ {\doifundefined{\??te\??te\string#2}{\letvalue{\??te\??te\string#2}=#1}%
+ \defineactivecharacter #1 {\@EA\doshortcut\string#2} % we need to deactivate in math
+ \getparameters
+ [\??te\string#2#3]
+ [\c!commands=,\c!command=,\c!style=,\c!color=,#4]}
+
+\def\doshortcut#1%
+ {\ifmmode
+ \getvalue{\??te\??te#1}%
+ \else
+ \bgroup
+ \catcode`#1=\@@other
+ \def\dodoshortcut##1#1%
+ {\def\shorttag{\??te#1}%
+ \def\shortcut{##1}%
+ \dododoshortcut##1:\end}%
+ \@EA\dodoshortcut
+ \fi}
+
+\def\dododoshortcut#1:#2\end
+ {\doifelsenothing{#2}
+ {\doifundefinedelse{\shorttag\c!commands}
+ {\shortcut}
+ {\@EA\dodododoshortcut\@EA\shorttag\@EA:\shortcut:\end}}
+ {\doifundefinedelse{\shorttag#1\c!commands}
+ {\shortcut}
+ {\dodododoshortcut\shorttag#1:#2\end}}%
+ \egroup}
+
+\def\dodododoshortcut#1:#2:\end
+ {\getvalue{#1\c!commands}%
+ \doattributes{#1}\c!style\c!color{\getvalue{#1\c!command}{#2}}}
+
+%D \macros
+%D {setvariables,getvariable,getvariabledefault}
+%D
+%D \starttyping
+%D \setvariables[xx][title=]
+%D \setvariables[xx][title=test test]
+%D \setvariables[xx][title=test $x=1$ test] % fatal error reported
+%D \setvariables[xx][title=test {$x=1$} test]
+%D \setvariables[xx][title] % fatal error reported
+%D \setvariables[xx][titletitel=e]
+%D \stoptyping
+
+\def\??vars{@@vars}
+
+\def\setvariables {\dotripleargument\dosetvariables[\getrawparameters ]}
+\def\setevariables{\dotripleargument\dosetvariables[\getraweparameters]}
+\def\setgvariables{\dotripleargument\dosetvariables[\getrawgparameters]}
+\def\setxvariables{\dotripleargument\dosetvariables[\getrawxparameters]}
+
+\def\globalsetvariables % obsolete
+ {\dotripleargument\dosetvariables[\globalgetrawparameters]}
+
+\long\def\dosetvariables[#1][#2][#3]% tricky, test on s-pre-60
+ {\errorisfataltrue
+ \doifelse{#2}\currentvariableclass
+ {#1[\??vars:#2:][#3]}%
+ {\pushmacro\currentvariableclass
+ \def\currentvariableclass{#2}%
+ \getvariable{#2}\s!reset
+ #1[\??vars:#2:][#3]%
+ \getvariable{#2}\s!set
+ \popmacro\currentvariableclass}%
+ \errorisfatalfalse}
+
+\long\def\setvariable #1#2#3{\long\expandafter\def \csname\??vars:#1:#2\endcsname{#3}}
+\long\def\setevariable#1#2#3{\long\expandafter\edef\csname\??vars:#1:#2\endcsname{#3}}
+\long\def\setgvariable#1#2#3{\long\expandafter\gdef\csname\??vars:#1:#2\endcsname{#3}}
+\long\def\setxvariable#1#2#3{\long\expandafter\xdef\csname\??vars:#1:#2\endcsname{#3}}
+
+\def\getvariable#1#2%
+ {\csname
+ \ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi
+ \endcsname}
+
+\def\showvariable#1#2%
+ {\showvalue{\ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi}}
+
+\let\currentvariableclass\empty
+
+%D \macros
+%D {checkvariables}
+%D
+%D I'll probably forget that this on exists.
+
+\def\checkvariables
+ {\dodoubleargument\docheckvariables}
+
+\def\docheckvariables
+ {\dogetparameters\docheckrawvalue}
+
+\long\def\docheckrawvalue#1#2#3%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \edef\checkedrawvalue{\csname\??vars:#1:#2\endcsname}%
+ \ifx\checkedrawvalue\empty
+ \long\expandafter\def\csname\??vars:#1:#2\endcsname{#3}%
+ \fi
+ \else
+ \long\expandafter\def\csname\??vars:#1:#2\endcsname{#3}%
+ \fi}
+
+%D \macros
+%D {doifelsevariable,doifvariable,doifnotvariable}
+%D
+%D A few trivial macros:
+
+\def\doifelsevariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\doifvariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\firstofoneargument
+ \else
+ \expandafter\gobbleoneargument
+ \fi}
+
+\def\doifnotvariable#1#2%
+ {\ifcsname\??vars:#1:#2\endcsname
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\firstofoneargument
+ \fi}
+
+\def\getvariabledefault#1#2% #3% can be command, so no ifcsname here
+ {\executeifdefined{\??vars:#1:#2}}% {#3}
+
+% \def\setupenv{\dodoubleargument\rawgetparameters[\??en]}
+%
+% \def\doifenvelse#1{\doifdefinedelse{\??en#1}} % speed up
+% \def\doifenv #1{\doifdefined {\??en#1}} % speed up
+% \def\doifnotenv #1{\doifundefined {\??en#1}} % speed up
+%
+% \def\env#1{\csname\??en#1\endcsname}
+%
+% \def\envvar#1#2%
+% {\ifcsname\??en#1\endcsname
+% \csname\??en#1\endcsname\else#2%
+% \fi}
+%
+% low level change, now also accessible as \getvariable
+% {environment}{...}; the next macros will become obsolete
+% some day in favor of normal variables in the environment
+% namespace
+
+\def\s!environment{environment}
+
+\def\setupenv {\dotripleargument\dosetvariables[\getrawparameters][\s!environment]}
+\def\doifenvelse{\doifelsevariable \s!environment}
+\def\doifenv {\doifvariable \s!environment}
+\def\doifnotenv {\doifnotvariable \s!environment}
+\def\env {\getvariable \s!environment}
+\def\envvar {\getvariabledefault\s!environment}
+
+\protect \endinput
diff --git a/tex/context/base/core-fig.tex b/tex/context/base/core-fig.tex
index 714a85e49..63aa1d193 100644
--- a/tex/context/base/core-fig.tex
+++ b/tex/context/base/core-fig.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Figure Handling}
+\writestatus{loading}{ConTeXt Core Macros / Figure Handling}
\unprotect
@@ -491,8 +491,6 @@
\doglobal\beforesplitstring#3\at.\to\typesetfilename
\externalfigure[\typesetfilename.pdf][#2,#4]}
-\appendtoks \setupexternalfigures[\c!option=\v!empty] \to \everyfastmode
-
\setupexternalfigures
[\c!option=,
\c!object=\v!yes, % we only check for no
diff --git a/tex/context/base/core-fil.tex b/tex/context/base/core-fil.tex
index eda055a96..fca253a7b 100644
--- a/tex/context/base/core-fil.tex
+++ b/tex/context/base/core-fil.tex
@@ -11,54 +11,10 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / File Support}
+\writestatus{loading}{ConTeXt Core Macros / File Support}
\unprotect
-% NOT YET DOCUMENTED !!
-%
-% overal \normalinput
-
-\startmessages dutch library: files
- title: files
- 1: file synoniem -- is al in gebruik voor --
-\stopmessages
-
-\startmessages english library: files
- title: files
- 1: file synonym -- is already used for --
-\stopmessages
-
-\startmessages german library: files
- title: files
- 1: Dateisynonym -- wird bereits fuer -- benutzt
-\stopmessages
-
-\startmessages czech library: files
- title: soubory
- 1: synonymum souboru -- je jiz pouzito pro --
-\stopmessages
-
-\startmessages italian library: files
- title: file
- 1: sinonimo file -- già in uso per --
-\stopmessages
-
-\startmessages norwegian library: files
- title: filer
- 1: filesynonym -- er allerede brukt for --
-\stopmessages
-
-\startmessages romanian library: files
- title: fisiere
- 1: sinonimul fisierelor -- este folosit deja pentru --
-\stopmessages
-
-\startmessages french library: files
- title: fichiers
- 1: le synonyme de fichier -- est déjà utilisé pour --
-\stopmessages
-
%D Files registered as temporary files will be deleted after a
%D run by texexec:
@@ -100,6 +56,8 @@
%D \usemodules[pictex,chemie,unit]
%D \stoptyping
+% will be redone in mkiv
+
\def\definefilesynonym
{\dodoubleempty\dodefinefilesynonym}
@@ -207,6 +165,7 @@
{\dododousemodules{#1-}{#2}}%
\ifconditional\moduleisloaded\else
\showmessage\m!systems6{#2}%
+ \appendtoks\showmessage\m!systems6{#2}\to\everynotabene
\fi}
% \def\usemodules
@@ -254,7 +213,7 @@
\let\currentmodule \s!unknown
\def\startmodule
- {\doifnextcharelse[\dostartmodule\nostartmodule}
+ {\doifnextoptionalelse\dostartmodule\nostartmodule}
\def\nostartmodule #1 %
{\dostartmodule[#1]}
@@ -339,7 +298,7 @@
% The following filenames are defined here:
\def\TEXbufferfile #1{\bufferprefix#1.\f!temporaryextension}
-\def\MPgraphicfile {\bufferprefix mp\ifMPrun run\else graph\fi}
+\def\MPgraphicfile {\bufferprefix mp\ifMPrun run\else graph\fi} % not needed in luatex
\def\convertMPcolorfile{\bufferprefix metacmyk.tmp}
%D To save memory, we implement some seldomly used commands
@@ -373,9 +332,6 @@
\let\checkpreprocessor\relax
-% \appendtoks\relax{\appendtoks \checkpreprocessor \to \everyjob}\to\everydump
-\appendtoks\everyjob\expandafter{\the\everyjob\checkpreprocessor}\to\everydump
-
%D To be documented and probably moved
\def\documentresources{\@@erurl}
diff --git a/tex/context/base/core-fld.mkii b/tex/context/base/core-fld.mkii
new file mode 100644
index 000000000..2b177c916
--- /dev/null
+++ b/tex/context/base/core-fld.mkii
@@ -0,0 +1,1080 @@
+%D \module
+%D [ file=core-fld,
+%D version=1997.05.18,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Fields,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% \appendtocommalist versus \addtocommalist
+%
+% * as default trigger in radiofields ?
+%
+% beware: weblink plugin truncates on length, while save as doesn't;
+% more precise: (1) first time right string is sent, (2)
+% internal string truncated, (3) second time truncated
+% string is sent.
+
+\writestatus{loading}{ConTeXt Core Macros / Fields}
+
+% messages
+
+\definemessageconstant{fields}
+
+\unprotect
+
+%D First we hook fields into the (viewer based) layering mechanism
+%D (implemented as properties).
+
+\ifx\currentlayerproperty\undefined\else \let\currentlayerproperty\empty\fi
+
+\appendtoks
+ \doif\@@iafieldlayer\v!auto
+ {\def\@@iafieldlayer{\currentlayerproperty}}%
+\to \everysetupinteraction
+
+\setupinteraction
+ [\c!fieldlayer=\v!auto] % auto by default
+
+%D Internal command, linked to \type{\definesymbol}.
+
+\def\dogetfieldsymbol#1%
+ {\getobject{SYM}{#1}}
+
+\def\dopresetfieldsymbol#1%
+ {\checkobjectreferences
+ \doifobjectfoundelse{SYM}{#1}
+ {}
+ {\settightobject{SYM}{#1}\hbox{\symbol[#1]}%
+ \flushatshipout
+ {\setbox0\hbox{\hskip-\maxdimen\getobject{SYM}{#1}}%
+ \smashbox0\box0}}}
+
+\def\presetfieldsymbols[#1]% slow
+ {\def\dopresetfieldsymbols##1%
+ {\processcommalist[##1]\dopresetfieldsymbol}%
+ \@EA\processcommalist\@EA[#1]\dopresetfieldsymbols}
+
+\def\definedefaultsymbols
+ {\definesymbol[defaultyes][$\times$]%
+ \definesymbol[defaultno][$\cdot$]}
+
+\def\resetfieldsymbol[#1]% for experimental usage only
+ {\resetobject{SYM}{#1}}
+
+%D The interface to the specials. DEFAULT NOG ANDERS
+
+\def\preparefieldvariables % evt \def's at the outer level (test) or \edef's here for fast testing
+ {\let\@@DriverFieldNumber \@@fdn
+ \let\@@DriverFieldStyle \@@fdstyle
+ \let\@@DriverFieldColor \@@fdcolor
+ \let\@@DriverFieldBackgroundColor\@@fdfieldbackgroundcolor
+ \let\@@DriverFieldFrameColor \@@fdfieldframecolor
+ \let\@@DriverFieldLayer \@@fdfieldlayer
+ \let\@@DriverFieldOption \@@fdoption
+ \let\@@DriverFieldAlign \@@fdalign
+ \let\@@DriverFieldClickIn \@@fdclickin
+ \let\@@DriverFieldClickOut \@@fdclickout
+ \let\@@DriverFieldRegionIn \@@fdregionin
+ \let\@@DriverFieldRegionOut \@@fdregionout
+ \let\@@DriverFieldAfterKey \@@fdafterkey
+ \let\@@DriverFieldFormat \@@fdformat
+ \let\@@DriverFieldValidate \@@fdvalidate
+ \let\@@DriverFieldCalculate \@@fdcalculate
+ \let\@@DriverFieldFocusIn \@@fdfocusin
+ \let\@@DriverFieldFocusOut \@@fdfocusout}
+
+% todo : remove arguments, consider DriverField a namespace
+
+\def\presetlinefield
+ {\preparefieldvariables
+ \dopresetlinefield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldNumber}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldAlign}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presettextfield
+ {\preparefieldvariables
+ \dopresettextfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldNumber}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldAlign}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetchoicefield
+ {\preparefieldvariables
+ \dopresetchoicefield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetpopupfield
+ {\preparefieldvariables
+ \dopresetpopupfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetcombofield
+ {\preparefieldvariables
+ \dopresetcombofield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetcheckfield
+ {\preparefieldvariables
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetcheckfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetpushfield
+ {\preparefieldvariables
+ %\edef\@@DriverFieldValues{{\@@DriverFieldValues}}% makes sure {a,b,c} is passed
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetpushfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetradiofield
+ {\preparefieldvariables
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetradiofield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldRoot}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetradiorecord
+ {\preparefieldvariables
+ \dopresetradiorecord
+ {\@@DriverFieldName}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldKids}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\setfieldmodes#1#2#3%
+ {\xdef\@@DriverFieldMode{#1}% % 0 1 2 3
+ \xdef\@@DriverFieldFree{#2}% % 0 1
+ \xdef\@@DriverFieldAuto{#3}} % 0 1
+
+\newevery\everysetfield\relax
+
+\def\doiffieldelse#1{\doifdefinedelse{fielddata#1}}
+
+\def\setfield#1#2#3#4#5#6#7#8#9%
+ {\bgroup
+ \doglobal\increment\numberoffields
+ \iftracefields
+ \doglobal\addtocommalist{#1}\collectedfields
+ \fi
+ \the\everysetfield
+ \setxvalue{fielddata#1}% kortere tag #7 needs expansion etc
+ {\noexpand\dosetfield{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
+ \egroup}
+
+\def\dosetfield#1#2#3#4#5#6#7#8#9%
+ {\xdef\@@DriverFieldName {#1}%
+ \xdef\@@DriverFieldType {#2}%
+ \xdef\@@DriverFieldRoot {#3}%
+ \xdef\@@DriverFieldParent {#4}%
+ \xdef\@@DriverFieldKids {#5}%
+ \xdef\@@DriverFieldGroup {#6}%
+ \setfieldmodes #7%
+ \bgroup
+ \def\par{\string\n\string\n}%
+ \xdef\@@DriverFieldValues {#8}%
+ \xdef\@@DriverFieldDefault{#9}%
+ \egroup}
+
+\def\changefield#1%
+ {\setfield{#1}\@@DriverFieldType\@@DriverFieldRoot\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldGroup
+ {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}\@@DriverFieldValues\@@DriverFieldDefault}
+
+\def\getfield#1% name
+ {\doifundefinedelse{fielddata#1}
+ {\dosetfield{#1}\empty\empty\empty\empty\empty{\empty00}\empty\empty}
+ {\getvalue{fielddata#1}}}
+
+\newif\iftracefields \tracefieldsfalse
+
+\let\tracefields\tracefieldstrue
+
+\def\doshowfields[#1]% todo: tabulate van maken en runtime
+ {\bgroup
+ \switchtobodyfont[8pt,tt]%
+ \doifsomething{#1}{\def\collectedfields{#1}}%
+ \ifx\collectedfields\empty
+ \par specify [fieldlist] or say \type{\tracefieldstrue} first\par
+ \else
+ \def\normalizedfieldmode##1##2##3%
+ {\ifcase0##2 \else\sl\fi
+ \ifcase0##1 loner\or parent\or clone\or copy\fi}%
+ \def\dosetfield##1##2##3##4##5##6##7##8##9%
+ {##1#2#3#4#5#6&\normalizedfieldmode##7#8#9\cr}%
+ \halign
+ {#\strut\hss\quad\cr
+ \noalign{\hrule}%
+ NAME &TYPE &ROOT &
+ PARENT&KIDS &GROUP &
+ MODE &VALUES&DEFAULT\cr
+ \noalign{\hrule}%
+ \@EA\globalprocesscommalist\@EA[\collectedfields]\getfield
+ \noalign{\hrule}}%
+ \fi
+ \egroup}
+
+\def\showfields
+ {\dosingleempty\doshowfields}
+
+\def\dologfields[#1]%
+ {\bgroup
+ \immediate\openout\scratchwrite=fields.log
+ \doifsomething{#1}{\def\collectedfields{#1}}%
+ \ifx\colledtedfields\empty
+ \immediate\write\scratchwrite{use \tracefieldstrue}%
+ \else
+ \def\normalizedfieldmode##1##2##3%
+ {\edef\@@DriverFieldMode
+ {\ifcase##1 loner \or parent \or clone \or copy \fi
+ \ifcase##2 \else(done)\fi}}%
+ \def\dosetfield##1##2##3##4##5##6##7##8##9%
+ {\normalizedfieldmode##7%
+ \immediate\write\scratchwrite
+ {N=##1 / T=##2 / R=##3 / P=##4 / K=##5 / G=##6 /
+ M=\@@DriverFieldMode\space/ V=##8 / D=##9}}%
+ \processcommacommand[\collectedfields]\getfield
+ \fi
+ \immediate\closeout\scratchwrite
+ \egroup}
+
+\def\logfields
+ {\dosingleempty\doLogFields}
+
+%D \starttyping
+%D \definefield [name] [type] [group] [values] [default]
+%D
+%D \definefield [WWWW] [text] [textsetup] [default text]
+%D \definefield [XXXX] [push] [pushsetup] [yes,no] [yes]
+%D \definefield [XXXX] [check] [checksetup] [yes,no] [yes]
+%D \definefield [YYYY] [combo] [combosetup] [a,b,c,d] [b]
+%D \definefield [ZZZZ] [radio] [radiosetup] [W,X,Y,Z] [Y]
+%D
+%D \definesubfield [W] [subsetup] [p,q]
+%D \definesubfield [X,Y] [subsetup] [p,r]
+%D \definesubfield [Z] [subsetup] [y,z]
+%D
+%D evt \definemainfield ... wanneer geplaatst voor subs gegeven
+%D
+%D \clonefield [XXXX] [XX,YY] [mysetup] [on,off]
+%D \clonefield [Z] [AA,BB] [somesetup] [true,false]
+%D \clonefield [Z] [CC,DD] [anothersetup]
+%D
+%D \copyfield [XXXX] [PP,QQ,RR]
+%D
+%D \field[XXXX]
+%D \fitfield[XXXX]
+%D \stoptyping
+
+\newif\ifdefinemainfield \definemainfieldfalse
+
+%D We need to keep track of cloned (related) fields and so by
+%D maintaining lists of field clones.
+%D
+%D The first alternative used a two pass data list and was
+%D implemented as follows:
+%D
+%D \starttyping
+%D \def\getmainfieldkids#1%
+%D {\let\@@DriverFieldKids\empty
+%D \ifdefinemainfield
+%D \definetwopasslist{fld:#1}% defined by system
+%D \doloop
+%D {\gettwopassdata{fld:#1}%
+%D \iftwopassdatafound
+%D %\addtocommalist\twopassdata\@@DriverFieldKids
+%D \appendtocommalist\twopassdata\@@DriverFieldKids
+%D \else
+%D \exitloop
+%D \fi}%
+%D \fi}
+%D \stoptyping
+%D
+%D However, the next alternative is much faster when we have
+%D a field with thousands of clones, something not that
+%D imaginary.
+%D
+%D \starttyping
+%D \def\getmainfieldkids#1%
+%D {\let\@@DriverFieldKids\empty
+%D \ifdefinemainfield
+%D \definetwopasslist{fld:#1}% runtime defined by system
+%D \getnamedtwopassdatalist{fld:#1}\@@DriverFieldKids
+%D \fi}
+%D \stoptyping
+%D
+%D The data is written by file using:
+%D
+%D \starttyping
+%D \newcounter\nofmainfieldkids
+%D
+%D \def\setmainfieldkid#1#2%
+%D {\doglobal\increment\nofmainfieldkids
+%D \savetwopassdata{fld:#1}{\nofmainfieldkids}{#2}}
+%D \stoptyping
+%D
+%D The trade of of this mechanism is that for each cloned or
+%D copied field, the uitlity file is to be read in order to
+%D fetch the data.
+%D
+%D The next, much faster alternative uses a dedicated %
+%D reference mechanism.
+
+\def\setmainfieldkid#1#2%
+ {\immediatewriteutilitycommand{\fieldreference{#1}{#2}}}
+
+\def\checkfieldreferences
+ {\startnointerference
+ \protectlabels
+ \doutilities{fieldreferences}\jobname\empty\relax\relax
+ \global\let\checkfieldreferences\relax
+ \stopnointerference}
+
+\def\setfieldreferences
+ {\def\fieldreference##1##2%
+ {\ifundefined{\r!widget##1}%
+ \setxvalue{\r!widget##1}{##2}%
+ \else
+ \edef\!!stringa{\getvalue{\r!widget##1}}%
+ \setxvalue{\r!widget##1}{\!!stringa,##2}%
+ \fi}}
+
+\def\resetfieldreferences
+ {\let\fieldreference\gobbletwoarguments}
+
+\def\getmainfieldkids#1%
+ {\checkfieldreferences
+ \ifdefinemainfield
+ \doifundefinedelse{\r!widget#1}%
+ {\let\@@DriverFieldKids\empty}
+ {\@EA\let\@EA\@@DriverFieldKids\csname\r!widget#1\endcsname}%
+ \else
+ \let\@@DriverFieldKids\empty
+ \fi}
+
+\resetfieldreferences
+
+%D Of course it costs a few more tokens to implement, but it's
+%D worth the memory: running for instance the 2000 page
+%D english examns publishing on demand document went down from
+%D 1350 seconds to less than 950 on a 650 Mhz pentium.
+
+\def\definefield
+ {\definemainfieldfalse\doquintupleempty\dodefinefield}
+
+\def\definemainfield
+ {\definemainfieldtrue \doquintupleempty\dodefinefield}
+
+\let\collectedfields\empty
+\newcounter\numberoffields
+\newcounter\totalnumberoffields
+
+\def\savenumberoffields
+ {\ifcase\numberoffields\relax\else
+ \savecurrentvalue\totalnumberoffields\numberoffields
+ \fi}
+
+\appendtoks \savenumberoffields \to \everybye % \everylastshipout
+
+% \def\presetfieldreferences
+% {\ifnum\totalnumberoffields>0
+% \definereference[AtOpenInitializeForm][\v!ResetForm]%
+% \fi}
+%
+% \definereference[AtOpenInitializeForm][\v!geen]
+%
+% \appendtoks \presetfieldreferences \to \everycheckreferences
+
+\def\dodefinefield[#1][#2][#3][#4][#5]%
+ {\ifsecondargument
+ \edef\currentfieldname{#1}% just in case we're inside a loop
+ \doifundefinedelse{define#2field}
+ {\writestatus\m!fields{unknown field type #2}}
+ {\doifundefined{fielddata\currentfieldname}
+ {\getmainfieldkids\currentfieldname
+ \ifdefinemainfield
+ \ifx\@@DriverFieldKids\empty
+ \let\@@DriverFieldMode\fieldlonermode
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ \fi
+ \def\@@DriverFieldAuto{1}%
+ \else
+ \let\@@DriverFieldMode\fieldlonermode
+ \def\@@DriverFieldAuto{0}%
+ \fi
+ \def\@@DriverFieldFree{0}%
+ \getvalue{define#2field}{\currentfieldname}{#2}{#3}{#4}{#5}}}%
+ \else
+ \writestatus\m!fields{pass fieldname and fieldtype}%
+ \fi}
+
+\def\definelinefield#1#2#3#4#5%
+ {\setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{#4}}
+
+\let\definetextfield=\definelinefield
+
+\def\definechoicefield#1#2#3#4#5%
+ {\doifelsenothing{#4}
+ {\def\@@DriverFieldValues{yes,no}}
+ {\def\@@DriverFieldValues{#4}}%
+ \doifelsenothing{#5}
+ {\dogetcommacommandelement2\from\@@DriverFieldValues \to\@@DriverFieldDefault
+ \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
+ {\def\@@DriverFieldDefault{#5}}%
+ \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+\let\definepopupfield=\definechoicefield
+\let\definecombofield=\definechoicefield
+
+%\def\definecheckfield#1#2#3#4#5%
+% {\doifelsenothing{#4}
+% {\definedefaultsymbols
+% \def\@@DriverFieldValues{defaultyes}}
+% {\def\@@DriverFieldValues{#4}}%
+% \doifelsenothing{#5}
+% {\dogetcommacommandelement2\from\@@DriverFieldValues\to\@@DriverFieldDefault
+% \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
+% {\def\@@DriverFieldDefault{#5}}%
+% \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+%D Since these fields have an on/off state only, we pass 1/0
+%D to the driver as default values.
+
+\def\definecheckfield#1#2#3#4#5%
+ {\doifelsenothing{#4}
+ {\definedefaultsymbols
+ \def\@@DriverFieldValues{defaultyes}}
+ {\def\@@DriverFieldValues{#4}}%
+ \doifelsenothing{#5}
+ {\def\@@DriverFieldDefault{2}}
+ {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldDefault
+ \doifinstringelse{#5}{\@@DriverFieldDefault}
+ {\def\@@DriverFieldDefault{1}}
+ {\def\@@DriverFieldDefault{0}}}%
+ \setfield
+ {#1}{#2}{}{}{\@@DriverFieldKids}{#3}%
+ {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}%
+ {\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+\let\definepushfield=\definecheckfield
+
+\def\defineradiofield#1#2#3#4#5%
+ {\iffourthargument
+ \doifelsenothing{#5}
+ {\dogetcommacommandelement1\from#4\to\SavedFieldDefault
+ \dogetcommacommandelement1\from\SavedFieldDefault\to\SavedFieldDefault}
+ {\def\SavedFieldDefault{#5}}%
+% when opt works
+% \@EA\beforesplitstring\SavedFieldDefault\at=>\to\SavedFieldDefault
+ \ifx\@@DriverFieldKids\empty
+ \setfield{#1}{#2}{}{}{#4}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
+ \else
+ \setfield{#1}{#2}{}{}{#4,\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
+ \fi
+%
+ \def\docommand##1%
+ {\doifelse{##1}\SavedFieldDefault
+ {\def\@@DriverFieldDefault{##1}}%
+ {\let\@@DriverFieldDefault\empty}%
+ \setfield{##1}{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
+% when opt works
+% \def\docommand##1%
+% {\@EA\beforesplitstring##1\at=>\to\FieldValue
+% \doifelse\FieldValue\SavedFieldDefault
+% {\let\@@DriverFieldDefault\FieldValue}%
+% {\let\@@DriverFieldDefault\empty}%
+% \setfield\FieldValue{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
+ \processcommalist[#4]\docommand
+ \else
+ \writestatus\m!fields{pass values too}%
+ \fi}
+
+\def\definesubfield
+ {\dotripleempty\dodefinesubfield}
+
+\def\dodefinesubfield[#1][#2][#3]% for the moment only radio ones
+ {\ifsecondargument
+ \def\docommand##1%
+ {\getfield{##1}%
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field ##1}% to do
+ \else
+ \doifsomething{#2}
+ {\edef\@@DriverFieldGroup{#2}}%
+ \doifelsenothing{#3}
+ {\definedefaultsymbols
+ \def\@@DriverFieldValues{defaultyes}}
+ {\def\@@DriverFieldValues{#3}}%
+ \changefield{##1}%
+ \fi}%
+ \processcommalist[#1]\docommand
+ \else
+ \writestatus\m!fields{pass fieldname, setupgroup, values and default}%
+ \fi}
+
+\def\doclonefield[#1][#2][#3][#4]% parent children setupgroup values
+ {\ifsecondargument
+ \getfield{#1}%
+\iftrialtypesetting\else
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #1}%
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
+ \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
+ \processcommalist[#2]\docommand
+ \changefield{#1}%
+ \let\@@DriverFieldAutoParent\@@DriverFieldAuto
+ \def\@@DriverFieldParent{#1}%
+ \let\@@DriverFieldKids\empty
+ \let\@@DriverFieldRoot\empty
+ \let\@@DriverFieldMode\fieldchildmode
+ \def\@@DriverFieldFree{0}%
+ \def\@@DriverFieldAuto{0}%
+ \doifsomething{#3}{\edef\@@DriverFieldGroup{#3}}%
+ \doifsomething{#4}{\edef\@@DriverFieldValues{#4}}%
+ \def\docommand##1%
+ {\ifcase\@@DriverFieldAutoParent\else
+ \setmainfieldkid{\@@DriverFieldParent}{##1}%
+ \fi
+ \changefield{##1}}%
+ \processcommalist[#2]\docommand
+ \fi
+\fi
+ \else
+ \writestatus\m!fields{pass parent field and clones}%
+ \fi}
+
+\def\clonefield
+ {\doquadrupleempty\doclonefield}
+
+\def\docopyfield[#1][#2]% parent children
+ {\ifsecondargument
+ \getfield{#1}%
+\iftrialtypesetting\else
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #1}%
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
+ \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
+ \processcommalist[#2]\docommand
+ \changefield{#1}%
+ \let\@@DriverFieldAutoParent\@@DriverFieldAuto
+ \def\@@DriverFieldParent{#1}%
+ \let\@@DriverFieldKids\empty
+ \let\@@DriverFieldRoot\empty
+ \let\@@DriverFieldMode\fieldcopymode
+ \def\@@DriverFieldFree{0}%
+ \def\@@DriverFieldAuto{0}%
+ \def\docommand##1%
+ {\ifcase\@@DriverFieldAutoParent\else
+ \setmainfieldkid{\@@DriverFieldParent}{##1}%
+ \fi
+ \changefield{##1}}%
+ \processcommalist[#2]\docommand
+ \fi
+\fi
+ \else
+ \writestatus\m!fields{pass parent field and copies}%
+ \fi}
+
+\def\copyfield{\dodoubleempty\docopyfield}
+
+\unexpanded\def\field {\dotripleempty\dofield[\dohandlefield]}
+\unexpanded\def\fitfield{\dotripleempty\dofield[\dohandlefitfield]}
+
+\def\dofield[#1][#2][#3]%
+ {\iffirstargument
+ \bgroup
+ \getfield{#2}%
+ \ifsecondargument
+ \def\@@DriverFieldLabel{#3}%
+ \else
+ \let\@@DriverFieldLabel\@@DriverFieldName
+ \fi
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #2}%
+ \else\ifcase\@@DriverFieldFree\relax
+ \doifdefinedelse{\strippedcsname\setupfield\@@DriverFieldGroup}
+ {\let\dosetupfield=#1\getvalue{\strippedcsname\setupfield\@@DriverFieldGroup}}
+ {#1[\@@DriverFieldName][\v!label,\v!frame,\v!horizontal][][][]}%
+\iftrialtypesetting\else
+ \def\@@DriverFieldFree{1}%
+ \changefield{#2}%
+\fi
+ \else\ifcase\@@DriverFieldAuto\relax
+ % \writestatus\m!fields{field #2 already typeset}%
+ \else
+ % \writestatus\m!fields{field #2 automatically copied}%
+ \nextsystemfield
+ \copyfield[\@@DriverFieldName][\currentsystemfield]%
+ \dotripleempty\dofield[#1][\currentsystemfield][#3]% get the if's right
+ \fi\fi\fi
+ \egroup
+ \fi}
+
+\def\typesetfield
+ {\useJSscripts[fld]%
+ \ifx\@@DriverFieldRoot\empty \else
+ \let\@@SavedFieldName\@@DriverFieldName
+ \getfield\@@DriverFieldRoot
+ \ifcase\@@DriverFieldFree\relax
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetrecord
+\iftrialtypesetting\else
+ \def\@@DriverFieldFree{1}%
+ \changefield\@@DriverFieldName
+\fi
+ \fi
+ \getfield\@@SavedFieldName
+ \fi
+ \ifx\@@DriverFieldKids\empty
+ \donefalse
+ \else
+ \donetrue
+ \fi
+ \ifdone
+ \let\@@DriverFieldParent\@@DriverFieldName
+ %\addtocommalist\@@DriverFieldParent\@@DriverFieldKids
+ \appendtocommalist\@@DriverFieldParent\@@DriverFieldKids
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetfield
+ \let\@@DriverFieldMode\fieldchildmode
+ \fi
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetfield}
+
+\def\dopresetfield
+ {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType field}\fi\fi}
+
+\def\dopresetrecord
+ {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType record}\fi\fi}
+
+\def\dodefinethefieldset[#1][#2]%
+ {\dodefinefieldset{#1}{#2}}
+
+\def\definefieldset%
+ {\dodoubleargument\dodefinethefieldset}
+
+\def\normaldodosetupfield[#1][#2][#3][#4][#5]%
+ {\doifdefinedelse{\strippedcsname\setupfield#1}
+ {\pushmacro\dosetupfield
+ \def\dosetupfield[##1][##2][##3][##4][##5]%
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][##2,#2][##3,#3][##4,#4][##5,#5]}}%
+ \getvalue{\strippedcsname\setupfield#1}%
+ \popmacro\dosetupfield}
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}}
+
+\let\dodosetupfield\normaldodosetupfield
+
+\def\donosetupfield[#1][#2][#3][#4][#5]%
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}
+
+\def\dosetupfield[#1][#2][#3][#4][#5]%
+ {\iffifthargument
+ \def\docommand##1{\dodosetupfield[##1][#2][#3][#4][#5]}%
+ \processcommalist[#1]\docommand
+ \else\ifthirdargument
+ \def\docommand##1{\dodosetupfield[##1][#2][][][#3]}%
+ \processcommalist[#1]\docommand
+ \else\ifsecondargument
+ \doifelse{#2}\v!reset
+ {\def\docommand##1{\donosetupfield[#1][][][][]}}
+ {\def\docommand##1{\dodosetupfield[##1][][][][#2]}}%
+ \processcommalist[#1]\docommand
+ \else\iffirstargument
+ \def\docommand##1{\dodosetupfield[##1][][][][]}%
+ \processcommalist[#1]\docommand
+ \else
+ \writestatus\m!fields{provide either 1, 2, 3 or 5 arguments}%
+ \fi\fi\fi\fi}
+
+\def\setupfield
+ {\doquintupleempty\dosetupfield}
+
+\def\dosetupfields[#1][#2][#3][#4]%
+ {\ifsecondargument
+ \def\dodosetupfield[##1][##2][##3][##4][##5]%
+ {\doifdefinedelse{\strippedcsname\setupfield##1}
+ {\def\dosetupfield[####1][####2][####3][####4][####5]%
+ {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,####2,##2][#2,####3,##3][#3,####4,##4][#4,####5,##5]}}%
+ \getvalue{\strippedcsname\setupfield##1}}
+ {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,##2][#2,##3][#3,##4][#4,##5]}}}%
+ \else\iffirstargument
+ \doifelse{#1}\v!reset
+ {\resetfields}
+ {\setupfields[][][][#1]}% checken
+ \else
+ \writestatus\m!fields{provide either 1 or 4 arguments}%
+ \fi\fi}
+
+\def\setupfields
+ {\doquadrupleempty\dosetupfields}
+
+\def\resetfields
+ {\let\dodosetupfield\normaldodosetupfield}
+
+% \setupfields[\v!reset]
+
+% opties: veld, label, kader, vertikaal/horizontaal
+
+\newif\ifShowFieldLabel
+\newif\ifShowFieldFrame
+\newif\ifVerticalField
+\newif\ifHorizontalField
+
+% way to slow/complicated, we need some simple alternative
+% as well
+
+\def\dohandlefield[#1][#2][#3][#4][#5]%
+ {\presetlocalframed[\??fd]%
+ \processallactionsinset
+ [#2]
+ [ \v!reset=>\ShowFieldLabelfalse\ShowFieldFramefalse
+ \HorizontalFieldfalse\VerticalFieldfalse,
+ \v!label=>\ShowFieldLabeltrue,
+ \v!frame=>\ShowFieldFrametrue,
+ \v!horizontal=>\HorizontalFieldtrue,
+ \v!vertical=>\VerticalFieldtrue]%
+ \ifVerticalField
+ \getparameters[\??fd]
+ [\c!distance=\!!zeropoint,\c!inbetween=\vskip\@@localoffset,
+ \c!align=\v!right,\c!width=20em]%
+ \else\ifHorizontalField
+ \getparameters[\??fd]
+ [\c!distance=\@@localoffset,\c!inbetween=,\c!align=\c!left,
+ \c!height=10ex]%
+ \else
+ \getparameters[\??fd]
+ [\c!distance=\!!zeropoint,\c!inbetween=,\c!align=\c!left]%
+ \fi\fi
+ \getparameters[\??fd]
+ [\c!n=,\c!before=,\c!after=\vss,\c!style=,\c!color=,#3]%
+ \reshapeframeboxfalse % else ugly spacing
+ \ifShowFieldFrame
+ \localframed[\??fd][\c!strut=\v!no,\c!align=]\bgroup
+ \else
+ \vbox\bgroup
+ \fi
+ \dontcomplain
+ \ifShowFieldLabel
+ \setbox0\hbox
+ {\reshapeframeboxtrue % else wrong dimensions
+ \framed
+ [\c!style=,\c!color=,\c!align=\c!right,#4]
+ {\@@DriverFieldLabel}}%
+ \fi
+ \setbox2\hbox
+ {\reshapeframeboxtrue % else wrong dimensions
+ \ifVerticalField
+ \setupframed[\c!height=6ex,\c!width=\hsize]%
+ \else\ifHorizontalField
+ \setupframed[\c!height=\vsize,\c!width=20em]%
+ \else
+ \setupframed[\c!height=2cm,\c!width=2cm]%
+ \fi\fi
+ \framed
+ [\c!align=\v!right,\c!strut=\v!no,#5]
+ {\getparameters
+ [\??fd]
+ [\c!color=,\c!style=,\c!align=\v!right,\c!option=,
+ \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
+ \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
+ \c!focusin=,\c!focusout=,
+ \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
+ \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5]%
+ \scratchdimen\framedwidth \edef\@@DriverFieldWidth {\the\scratchdimen}%
+ \scratchdimen\framedheight\edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \vfill
+ \hbox{\lower\@@fdfieldoffset\hbox{\typesetfield}}
+ \vss}}%
+ \ifShowFieldLabel
+ \ifVerticalField
+ \vbox
+ {\copy0
+ \@@fdinbetween
+ \copy2}%
+ \else
+ \hbox
+ {\vbox \ifdim\ht2>\ht0 to \ht2 \fi
+ {\@@fdbefore
+ \copy0
+ \@@fdafter}%
+ \hskip\@@fddistance
+ \vbox \ifdim\ht0>\ht2 to \ht0 \fi
+ {\@@fdbefore
+ \box2
+ \@@fdafter}}%
+ \fi
+ \else
+ \box2
+ \fi
+ \egroup}
+
+\chardef\fitfieldmode\plusone % 3 = best
+
+\def\dohandlefitfield[#1][#2][#3][#4][#5]% alleen check
+ {\presetlocalframed[\??fd]%
+ \localframed
+ [\??fd]
+ [\c!n=1024, % beware: weblink plug in truncates
+ \c!strut=\v!no,\c!color=,\c!style=,\c!option=,
+ \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
+ \c!focusin=,\c!focusout=,
+ \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
+ \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
+ \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5,\c!align=]
+ {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldValue
+ \ifx\@@DriverFieldValue\empty
+ \let\@@DriverFieldValue\@@DriverFieldDefault
+ \fi
+ \dopresetfieldsymbol\@@DriverFieldValue
+ \setbox\scratchbox\hbox{\dogetfieldsymbol\@@DriverFieldValue}%
+ \scratchdimen\wd\scratchbox \edef\@@DriverFieldWidth {\the\scratchdimen}%
+ \scratchdimen\ht\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \ifcase\fitfieldmode
+ \typesetfield
+ \or % 1 = ignore depth (original, assumed no depth, actually a bug)
+ \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
+ \or % 2 = add depth to height, but no depth in result
+ \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
+ \or % 3 = add depth to height, and apply depth to result
+ \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \hbox to \wd\scratchbox{\lower\dp\scratchbox\hbox{\typesetfield}\hfill}%
+ \fi}}
+
+%D Common stuff
+
+\newcounter\nofsystemfields
+
+\def\nextsystemfield
+ {\doglobal\increment\nofsystemfields
+ \def\currentsystemfield{sys::\nofsystemfields}}
+
+%D An example:
+
+\def\fillinfield
+ {\dosingleempty\dofillinfield}
+
+\def\dofillinfield[#1]#2%
+ {\dontleavehmode
+ \hbox
+ {\forgetall
+ \setupfields[\v!reset]%
+ \nextsystemfield
+ \useJSscripts[ans]%
+ \doifelsenothing{#1}
+ {\def\therightanswer{#2}}
+ {\def\therightanswer{#1}}%
+ \setbox0\hbox{#2}%
+ \setbox2\hbox{\therightanswer}%
+ \dimen0=\ifdim\wd0>\wd2 \wd0 \else \wd2 \fi
+ \advance\dimen0 .2em
+ \definefield
+ [\currentsystemfield][line][systemfield]%
+ \setupfield
+ [systemfield]
+ [\c!n=1024, % beware: weblink plugin truncates
+ \c!location=\v!low,\c!strut=\v!yes,\c!fieldoffset=0pt,
+ \c!height=1.2\openlineheight,\c!width=\dimen0,\c!offset=\v!overlay,
+ \c!style=,\c!align=\v!middle,\c!frame=\v!off,
+ \c!color=red,\c!fieldbackgroundcolor=\s!white,\c!fieldframecolor=blue,
+ \c!validate=JS(Check_Answer{\currentsystemfield,\therightanswer})]%
+ \switchtobodyfont
+ [\c!small]%
+ \hbox to \wd0
+ {\copy0\hskip-\wd0\hss\field[\currentsystemfield]\hss}}}
+
+%D and another one:
+
+\def\tooltip
+ {\dosingleempty\dotooltip}
+
+\def\dotooltip[#1]#2#3%
+ {\bgroup
+ \setupfields[\v!reset]%
+ \useJSscripts[fld]%
+ \setbox0\hbox
+ {\dontcomplain
+ \nextsystemfield
+ \setbox0\hbox{#2}%
+ \definesymbol
+ [\currentsystemfield:txt]
+ [{\inframed[\c!frame=\v!off,\c!background=\v!screen]{#3}}]%
+ \setbox2\hbox{\symbol[\currentsystemfield:txt]}%
+ \definefield
+ [\currentsystemfield:txt][check]
+ [dummy][\currentsystemfield:txt][\currentsystemfield:txt]%
+ \setupfield
+ [dummy]
+ [\c!frame=\v!off,
+ \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
+ \c!option=\v!hidden]%
+ \hbox to \zeropoint
+ {\dimen0\wd2\advance\dimen0 -\wd0
+ \doifelse{#1}\v!left
+ {\hskip-\dimen0}
+ {\doif{#1}\v!middle
+ {\hskip-.5\dimen0}}%
+ \lower\openlineheight\hbox to \zeropoint
+ {\fitfield[\currentsystemfield:txt]}}%
+ \dimen0=\ifdim\wd0=\zeropoint 3em\else\wd0\fi
+ \definesymbol
+ [\currentsystemfield:but]
+ [{\framed[\c!height=2ex,\c!width=\dimen0,\c!frame=\v!off]{}}]%
+ \definefield
+ [\currentsystemfield:but][push]
+ [dummy][\currentsystemfield:but][\currentsystemfield:but]%
+ \setupfield
+ [dummy]
+ [\c!frame=\v!off,
+ \c!option=,
+ \c!regionin=JS(Vide_Field{\currentsystemfield:txt}),
+ \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
+ \c!fieldlayer=\@@iafieldlayer]%
+ \lower2ex\hbox to \zeropoint
+ {\fitfield[\currentsystemfield:but]}%
+ #2}%
+ \ht0\strutht\dp0\strutdp\box0
+ \egroup}
+
+%D And one more:
+
+\def\definefieldstack
+ {\dotripleargument\dodefinefieldstack}
+
+\def\dodefinefieldstack[#1][#2][#3]% name, symbols, settings
+ {\doifundefined{fieldstack:#1}
+ {\setgvalue{fieldstack:#1}{\dodofieldstack[#1][#2][#3]}}}
+
+\def\dodofieldstack[#1][#2][#3]% start=n, 0 == leeg
+ {\bgroup
+ \getparameters[\??fd][\c!start=1,#3]%
+ \setupfields[\v!reset]%
+ \definesymbol[\v!empty][]%
+ \useJSscripts[fld][FieldStack]%
+ \newcounter\stackedfieldnumber
+ \def\dododofieldstack##1%
+ {\increment\stackedfieldnumber
+ \ifnum\stackedfieldnumber=\@@fdstart\relax
+ \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][##1]%
+ \else
+ \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][\v!empty]%
+ \fi}%
+ \processcommalist[#2]\dododofieldstack
+ \setupfield[#1][\v!reset]% added
+ \setupfield[#1][\c!option=\v!readonly,#3]% #3 swapped
+ \newcounter\stackedfieldnumber
+ \def\dododofieldstack##1%
+ {\doglobal\increment\stackedfieldnumber
+ \fitfield[#1:\stackedfieldnumber]\egroup\bgroup}%
+ \startoverlay
+ \bgroup
+ \globalprocesscommalist[#2]\dododofieldstack
+ \egroup
+ \stopoverlay
+ \egroup}
+
+\def\dofieldstack[#1][#2][#3]%
+ {\ifsecondargument
+ \dodefinefieldstack[#1][#2][#3]\fieldstack[#1]%
+ \else
+ \getvalue{fieldstack:#1}\setgvalue{fieldstack:#1}{[#1]}%
+ \fi}
+
+\def\fieldstack
+ {\dotripleempty\dofieldstack}
+
+%D When submitting a form, we need to tell the driver module
+%D that we want \FDF\ or \HTML.
+
+\def\setupforms
+ {\dodoubleargument\getparameters[\??fr]}
+
+\def\checksubmitform#1%
+ {\setsubmitoutputformat\@@frmethod}
+
+\setexecutecommandcheck {submitform} \checksubmitform
+
+\setupforms
+ [\c!method=HTML]
+
+\protect \endinput
diff --git a/tex/context/base/core-fld.mkiv b/tex/context/base/core-fld.mkiv
new file mode 100644
index 000000000..96ecf6b54
--- /dev/null
+++ b/tex/context/base/core-fld.mkiv
@@ -0,0 +1,1079 @@
+%D \module
+%D [ file=core-fld,
+%D version=1997.05.18,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Fields,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% \appendtocommalist versus \addtocommalist
+%
+% * as default trigger in radiofields ?
+%
+% beware: weblink plugin truncates on length, while save as doesn't;
+% more precise: (1) first time right string is sent, (2)
+% internal string truncated, (3) second time truncated
+% string is sent.
+
+\writestatus{loading}{ConTeXt Core Macros / Fields}
+
+% messages
+
+\definemessageconstant{fields}
+
+\unprotect
+
+%D First we hook fields into the (viewer based) layering mechanism
+%D (implemented as properties).
+
+\ifx\currentlayerproperty\undefined\else \let\currentlayerproperty\empty\fi
+
+\appendtoks
+ \doif\@@iafieldlayer\v!auto
+ {\def\@@iafieldlayer{\currentlayerproperty}}%
+\to \everysetupinteraction
+
+\setupinteraction
+ [\c!fieldlayer=\v!auto] % auto by default
+
+%D Internal command, linked to \type{\definesymbol}.
+
+\def\dogetfieldsymbol#1%
+ {\getobject{SYM}{#1}}
+
+\def\dopresetfieldsymbol#1%
+ {\doifobjectfoundelse{SYM}{#1}
+ {}
+ {\settightobject{SYM}{#1}\hbox{\symbol[#1]}%
+ \flushatshipout
+ {\setbox0\hbox{\hskip-\maxdimen\getobject{SYM}{#1}}%
+ \smashbox0\box0}}}
+
+\def\presetfieldsymbols[#1]% slow
+ {\def\dopresetfieldsymbols##1%
+ {\processcommalist[##1]\dopresetfieldsymbol}%
+ \@EA\processcommalist\@EA[#1]\dopresetfieldsymbols}
+
+\def\definedefaultsymbols
+ {\definesymbol[defaultyes][$\times$]%
+ \definesymbol[defaultno][$\cdot$]}
+
+\def\resetfieldsymbol[#1]% for experimental usage only
+ {\resetobject{SYM}{#1}}
+
+%D The interface to the specials. DEFAULT NOG ANDERS
+
+\def\preparefieldvariables % evt \def's at the outer level (test) or \edef's here for fast testing
+ {\let\@@DriverFieldNumber \@@fdn
+ \let\@@DriverFieldStyle \@@fdstyle
+ \let\@@DriverFieldColor \@@fdcolor
+ \let\@@DriverFieldBackgroundColor\@@fdfieldbackgroundcolor
+ \let\@@DriverFieldFrameColor \@@fdfieldframecolor
+ \let\@@DriverFieldLayer \@@fdfieldlayer
+ \let\@@DriverFieldOption \@@fdoption
+ \let\@@DriverFieldAlign \@@fdalign
+ \let\@@DriverFieldClickIn \@@fdclickin
+ \let\@@DriverFieldClickOut \@@fdclickout
+ \let\@@DriverFieldRegionIn \@@fdregionin
+ \let\@@DriverFieldRegionOut \@@fdregionout
+ \let\@@DriverFieldAfterKey \@@fdafterkey
+ \let\@@DriverFieldFormat \@@fdformat
+ \let\@@DriverFieldValidate \@@fdvalidate
+ \let\@@DriverFieldCalculate \@@fdcalculate
+ \let\@@DriverFieldFocusIn \@@fdfocusin
+ \let\@@DriverFieldFocusOut \@@fdfocusout}
+
+% todo : remove arguments, consider DriverField a namespace
+
+\def\presetlinefield
+ {\preparefieldvariables
+ \dopresetlinefield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldNumber}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldAlign}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presettextfield
+ {\preparefieldvariables
+ \dopresettextfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldNumber}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldAlign}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetchoicefield
+ {\preparefieldvariables
+ \dopresetchoicefield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetpopupfield
+ {\preparefieldvariables
+ \dopresetpopupfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetcombofield
+ {\preparefieldvariables
+ \dopresetcombofield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetcheckfield
+ {\preparefieldvariables
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetcheckfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetpushfield
+ {\preparefieldvariables
+ %\edef\@@DriverFieldValues{{\@@DriverFieldValues}}% makes sure {a,b,c} is passed
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetpushfield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetradiofield
+ {\preparefieldvariables
+ \presetfieldsymbols[\@@DriverFieldValues]%
+ \dopresetradiofield
+ {\@@DriverFieldName}
+ {\@@DriverFieldWidth}
+ {\@@DriverFieldHeight}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldRoot}
+ {\@@DriverFieldValues}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\presetradiorecord
+ {\preparefieldvariables
+ \dopresetradiorecord
+ {\@@DriverFieldName}
+ {\@@DriverFieldDefault}
+ {\@@DriverFieldOption}
+ {\@@DriverFieldKids}
+ {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
+ \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
+ \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
+
+\def\setfieldmodes#1#2#3%
+ {\xdef\@@DriverFieldMode{#1}% % 0 1 2 3
+ \xdef\@@DriverFieldFree{#2}% % 0 1
+ \xdef\@@DriverFieldAuto{#3}} % 0 1
+
+\newevery\everysetfield\relax
+
+\def\doiffieldelse#1{\doifdefinedelse{fielddata#1}}
+
+\def\setfield#1#2#3#4#5#6#7#8#9%
+ {\bgroup
+ \doglobal\increment\numberoffields
+ \iftracefields
+ \doglobal\addtocommalist{#1}\collectedfields
+ \fi
+ \the\everysetfield
+ \setxvalue{fielddata#1}% kortere tag #7 needs expansion etc
+ {\noexpand\dosetfield{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
+ \egroup}
+
+\def\dosetfield#1#2#3#4#5#6#7#8#9%
+ {\xdef\@@DriverFieldName {#1}%
+ \xdef\@@DriverFieldType {#2}%
+ \xdef\@@DriverFieldRoot {#3}%
+ \xdef\@@DriverFieldParent {#4}%
+ \xdef\@@DriverFieldKids {#5}%
+ \xdef\@@DriverFieldGroup {#6}%
+ \setfieldmodes #7%
+ \bgroup
+ \def\par{\string\n\string\n}%
+ \xdef\@@DriverFieldValues {#8}%
+ \xdef\@@DriverFieldDefault{#9}%
+ \egroup}
+
+\def\changefield#1%
+ {\setfield{#1}\@@DriverFieldType\@@DriverFieldRoot\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldGroup
+ {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}\@@DriverFieldValues\@@DriverFieldDefault}
+
+\def\getfield#1% name
+ {\doifundefinedelse{fielddata#1}
+ {\dosetfield{#1}\empty\empty\empty\empty\empty{\empty00}\empty\empty}
+ {\getvalue{fielddata#1}}}
+
+\newif\iftracefields \tracefieldsfalse
+
+\let\tracefields\tracefieldstrue
+
+\def\doshowfields[#1]% todo: tabulate van maken en runtime
+ {\bgroup
+ \switchtobodyfont[8pt,tt]%
+ \doifsomething{#1}{\def\collectedfields{#1}}%
+ \ifx\collectedfields\empty
+ \par specify [fieldlist] or say \type{\tracefieldstrue} first\par
+ \else
+ \def\normalizedfieldmode##1##2##3%
+ {\ifcase0##2 \else\sl\fi
+ \ifcase0##1 loner\or parent\or clone\or copy\fi}%
+ \def\dosetfield##1##2##3##4##5##6##7##8##9%
+ {##1#2#3#4#5#6&\normalizedfieldmode##7#8#9\cr}%
+ \halign
+ {#\strut\hss\quad\cr
+ \noalign{\hrule}%
+ NAME &TYPE &ROOT &
+ PARENT&KIDS &GROUP &
+ MODE &VALUES&DEFAULT\cr
+ \noalign{\hrule}%
+ \@EA\globalprocesscommalist\@EA[\collectedfields]\getfield
+ \noalign{\hrule}}%
+ \fi
+ \egroup}
+
+\def\showfields
+ {\dosingleempty\doshowfields}
+
+\def\dologfields[#1]%
+ {\bgroup
+ \immediate\openout\scratchwrite=fields.log
+ \doifsomething{#1}{\def\collectedfields{#1}}%
+ \ifx\colledtedfields\empty
+ \immediate\write\scratchwrite{use \tracefieldstrue}%
+ \else
+ \def\normalizedfieldmode##1##2##3%
+ {\edef\@@DriverFieldMode
+ {\ifcase##1 loner \or parent \or clone \or copy \fi
+ \ifcase##2 \else(done)\fi}}%
+ \def\dosetfield##1##2##3##4##5##6##7##8##9%
+ {\normalizedfieldmode##7%
+ \immediate\write\scratchwrite
+ {N=##1 / T=##2 / R=##3 / P=##4 / K=##5 / G=##6 /
+ M=\@@DriverFieldMode\space/ V=##8 / D=##9}}%
+ \processcommacommand[\collectedfields]\getfield
+ \fi
+ \immediate\closeout\scratchwrite
+ \egroup}
+
+\def\logfields
+ {\dosingleempty\doLogFields}
+
+%D \starttyping
+%D \definefield [name] [type] [group] [values] [default]
+%D
+%D \definefield [WWWW] [text] [textsetup] [default text]
+%D \definefield [XXXX] [push] [pushsetup] [yes,no] [yes]
+%D \definefield [XXXX] [check] [checksetup] [yes,no] [yes]
+%D \definefield [YYYY] [combo] [combosetup] [a,b,c,d] [b]
+%D \definefield [ZZZZ] [radio] [radiosetup] [W,X,Y,Z] [Y]
+%D
+%D \definesubfield [W] [subsetup] [p,q]
+%D \definesubfield [X,Y] [subsetup] [p,r]
+%D \definesubfield [Z] [subsetup] [y,z]
+%D
+%D evt \definemainfield ... wanneer geplaatst voor subs gegeven
+%D
+%D \clonefield [XXXX] [XX,YY] [mysetup] [on,off]
+%D \clonefield [Z] [AA,BB] [somesetup] [true,false]
+%D \clonefield [Z] [CC,DD] [anothersetup]
+%D
+%D \copyfield [XXXX] [PP,QQ,RR]
+%D
+%D \field[XXXX]
+%D \fitfield[XXXX]
+%D \stoptyping
+
+\newif\ifdefinemainfield \definemainfieldfalse
+
+%D We need to keep track of cloned (related) fields and so by
+%D maintaining lists of field clones.
+%D
+%D The first alternative used a two pass data list and was
+%D implemented as follows:
+%D
+%D \starttyping
+%D \def\getmainfieldkids#1%
+%D {\let\@@DriverFieldKids\empty
+%D \ifdefinemainfield
+%D \definetwopasslist{fld:#1}% defined by system
+%D \doloop
+%D {\gettwopassdata{fld:#1}%
+%D \iftwopassdatafound
+%D %\addtocommalist\twopassdata\@@DriverFieldKids
+%D \appendtocommalist\twopassdata\@@DriverFieldKids
+%D \else
+%D \exitloop
+%D \fi}%
+%D \fi}
+%D \stoptyping
+%D
+%D However, the next alternative is much faster when we have
+%D a field with thousands of clones, something not that
+%D imaginary.
+%D
+%D \starttyping
+%D \def\getmainfieldkids#1%
+%D {\let\@@DriverFieldKids\empty
+%D \ifdefinemainfield
+%D \definetwopasslist{fld:#1}% runtime defined by system
+%D \getnamedtwopassdatalist{fld:#1}\@@DriverFieldKids
+%D \fi}
+%D \stoptyping
+%D
+%D The data is written by file using:
+%D
+%D \starttyping
+%D \newcounter\nofmainfieldkids
+%D
+%D \def\setmainfieldkid#1#2%
+%D {\doglobal\increment\nofmainfieldkids
+%D \savetwopassdata{fld:#1}{\nofmainfieldkids}{#2}}
+%D \stoptyping
+%D
+%D The trade of of this mechanism is that for each cloned or
+%D copied field, the uitlity file is to be read in order to
+%D fetch the data.
+%D
+%D The next, much faster alternative uses a dedicated %
+%D reference mechanism.
+
+\def\setmainfieldkid#1#2%
+ {\immediatewriteutilitycommand{\fieldreference{#1}{#2}}}
+
+\def\checkfieldreferences
+ {\startnointerference
+ \protectlabels
+ \doutilities{fieldreferences}\jobname\empty\relax\relax
+ \global\let\checkfieldreferences\relax
+ \stopnointerference}
+
+\def\setfieldreferences
+ {\def\fieldreference##1##2%
+ {\ifundefined{\r!widget##1}%
+ \setxvalue{\r!widget##1}{##2}%
+ \else
+ \edef\!!stringa{\getvalue{\r!widget##1}}%
+ \setxvalue{\r!widget##1}{\!!stringa,##2}%
+ \fi}}
+
+\def\resetfieldreferences
+ {\let\fieldreference\gobbletwoarguments}
+
+\def\getmainfieldkids#1%
+ {\checkfieldreferences
+ \ifdefinemainfield
+ \doifundefinedelse{\r!widget#1}%
+ {\let\@@DriverFieldKids\empty}
+ {\@EA\let\@EA\@@DriverFieldKids\csname\r!widget#1\endcsname}%
+ \else
+ \let\@@DriverFieldKids\empty
+ \fi}
+
+\resetfieldreferences
+
+%D Of course it costs a few more tokens to implement, but it's
+%D worth the memory: running for instance the 2000 page
+%D english examns publishing on demand document went down from
+%D 1350 seconds to less than 950 on a 650 Mhz pentium.
+
+\def\definefield
+ {\definemainfieldfalse\doquintupleempty\dodefinefield}
+
+\def\definemainfield
+ {\definemainfieldtrue \doquintupleempty\dodefinefield}
+
+\let\collectedfields\empty
+\newcounter\numberoffields
+\newcounter\totalnumberoffields
+
+\def\savenumberoffields
+ {\ifcase\numberoffields\relax\else
+ \savecurrentvalue\totalnumberoffields\numberoffields
+ \fi}
+
+\appendtoks \savenumberoffields \to \everybye % \everylastshipout
+
+% \def\presetfieldreferences
+% {\ifnum\totalnumberoffields>0
+% \definereference[AtOpenInitializeForm][\v!ResetForm]%
+% \fi}
+%
+% \definereference[AtOpenInitializeForm][\v!geen]
+%
+% \appendtoks \presetfieldreferences \to \everycheckreferences
+
+\def\dodefinefield[#1][#2][#3][#4][#5]%
+ {\ifsecondargument
+ \edef\currentfieldname{#1}% just in case we're inside a loop
+ \doifundefinedelse{define#2field}
+ {\writestatus\m!fields{unknown field type #2}}
+ {\doifundefined{fielddata\currentfieldname}
+ {\getmainfieldkids\currentfieldname
+ \ifdefinemainfield
+ \ifx\@@DriverFieldKids\empty
+ \let\@@DriverFieldMode\fieldlonermode
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ \fi
+ \def\@@DriverFieldAuto{1}%
+ \else
+ \let\@@DriverFieldMode\fieldlonermode
+ \def\@@DriverFieldAuto{0}%
+ \fi
+ \def\@@DriverFieldFree{0}%
+ \getvalue{define#2field}{\currentfieldname}{#2}{#3}{#4}{#5}}}%
+ \else
+ \writestatus\m!fields{pass fieldname and fieldtype}%
+ \fi}
+
+\def\definelinefield#1#2#3#4#5%
+ {\setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{#4}}
+
+\let\definetextfield=\definelinefield
+
+\def\definechoicefield#1#2#3#4#5%
+ {\doifelsenothing{#4}
+ {\def\@@DriverFieldValues{yes,no}}
+ {\def\@@DriverFieldValues{#4}}%
+ \doifelsenothing{#5}
+ {\dogetcommacommandelement2\from\@@DriverFieldValues \to\@@DriverFieldDefault
+ \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
+ {\def\@@DriverFieldDefault{#5}}%
+ \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+\let\definepopupfield=\definechoicefield
+\let\definecombofield=\definechoicefield
+
+%\def\definecheckfield#1#2#3#4#5%
+% {\doifelsenothing{#4}
+% {\definedefaultsymbols
+% \def\@@DriverFieldValues{defaultyes}}
+% {\def\@@DriverFieldValues{#4}}%
+% \doifelsenothing{#5}
+% {\dogetcommacommandelement2\from\@@DriverFieldValues\to\@@DriverFieldDefault
+% \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
+% {\def\@@DriverFieldDefault{#5}}%
+% \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+%D Since these fields have an on/off state only, we pass 1/0
+%D to the driver as default values.
+
+\def\definecheckfield#1#2#3#4#5%
+ {\doifelsenothing{#4}
+ {\definedefaultsymbols
+ \def\@@DriverFieldValues{defaultyes}}
+ {\def\@@DriverFieldValues{#4}}%
+ \doifelsenothing{#5}
+ {\def\@@DriverFieldDefault{2}}
+ {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldDefault
+ \doifinstringelse{#5}{\@@DriverFieldDefault}
+ {\def\@@DriverFieldDefault{1}}
+ {\def\@@DriverFieldDefault{0}}}%
+ \setfield
+ {#1}{#2}{}{}{\@@DriverFieldKids}{#3}%
+ {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}%
+ {\@@DriverFieldValues}{\@@DriverFieldDefault}}
+
+\let\definepushfield=\definecheckfield
+
+\def\defineradiofield#1#2#3#4#5%
+ {\iffourthargument
+ \doifelsenothing{#5}
+ {\dogetcommacommandelement1\from#4\to\SavedFieldDefault
+ \dogetcommacommandelement1\from\SavedFieldDefault\to\SavedFieldDefault}
+ {\def\SavedFieldDefault{#5}}%
+% when opt works
+% \@EA\beforesplitstring\SavedFieldDefault\at=>\to\SavedFieldDefault
+ \ifx\@@DriverFieldKids\empty
+ \setfield{#1}{#2}{}{}{#4}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
+ \else
+ \setfield{#1}{#2}{}{}{#4,\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
+ \fi
+%
+ \def\docommand##1%
+ {\doifelse{##1}\SavedFieldDefault
+ {\def\@@DriverFieldDefault{##1}}%
+ {\let\@@DriverFieldDefault\empty}%
+ \setfield{##1}{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
+% when opt works
+% \def\docommand##1%
+% {\@EA\beforesplitstring##1\at=>\to\FieldValue
+% \doifelse\FieldValue\SavedFieldDefault
+% {\let\@@DriverFieldDefault\FieldValue}%
+% {\let\@@DriverFieldDefault\empty}%
+% \setfield\FieldValue{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
+ \processcommalist[#4]\docommand
+ \else
+ \writestatus\m!fields{pass values too}%
+ \fi}
+
+\def\definesubfield
+ {\dotripleempty\dodefinesubfield}
+
+\def\dodefinesubfield[#1][#2][#3]% for the moment only radio ones
+ {\ifsecondargument
+ \def\docommand##1%
+ {\getfield{##1}%
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field ##1}% to do
+ \else
+ \doifsomething{#2}
+ {\edef\@@DriverFieldGroup{#2}}%
+ \doifelsenothing{#3}
+ {\definedefaultsymbols
+ \def\@@DriverFieldValues{defaultyes}}
+ {\def\@@DriverFieldValues{#3}}%
+ \changefield{##1}%
+ \fi}%
+ \processcommalist[#1]\docommand
+ \else
+ \writestatus\m!fields{pass fieldname, setupgroup, values and default}%
+ \fi}
+
+\def\doclonefield[#1][#2][#3][#4]% parent children setupgroup values
+ {\ifsecondargument
+ \getfield{#1}%
+\iftrialtypesetting\else
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #1}%
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
+ \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
+ \processcommalist[#2]\docommand
+ \changefield{#1}%
+ \let\@@DriverFieldAutoParent\@@DriverFieldAuto
+ \def\@@DriverFieldParent{#1}%
+ \let\@@DriverFieldKids\empty
+ \let\@@DriverFieldRoot\empty
+ \let\@@DriverFieldMode\fieldchildmode
+ \def\@@DriverFieldFree{0}%
+ \def\@@DriverFieldAuto{0}%
+ \doifsomething{#3}{\edef\@@DriverFieldGroup{#3}}%
+ \doifsomething{#4}{\edef\@@DriverFieldValues{#4}}%
+ \def\docommand##1%
+ {\ifcase\@@DriverFieldAutoParent\else
+ \setmainfieldkid{\@@DriverFieldParent}{##1}%
+ \fi
+ \changefield{##1}}%
+ \processcommalist[#2]\docommand
+ \fi
+\fi
+ \else
+ \writestatus\m!fields{pass parent field and clones}%
+ \fi}
+
+\def\clonefield
+ {\doquadrupleempty\doclonefield}
+
+\def\docopyfield[#1][#2]% parent children
+ {\ifsecondargument
+ \getfield{#1}%
+\iftrialtypesetting\else
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #1}%
+ \else
+ \let\@@DriverFieldMode\fieldparentmode
+ %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
+ \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
+ \processcommalist[#2]\docommand
+ \changefield{#1}%
+ \let\@@DriverFieldAutoParent\@@DriverFieldAuto
+ \def\@@DriverFieldParent{#1}%
+ \let\@@DriverFieldKids\empty
+ \let\@@DriverFieldRoot\empty
+ \let\@@DriverFieldMode\fieldcopymode
+ \def\@@DriverFieldFree{0}%
+ \def\@@DriverFieldAuto{0}%
+ \def\docommand##1%
+ {\ifcase\@@DriverFieldAutoParent\else
+ \setmainfieldkid{\@@DriverFieldParent}{##1}%
+ \fi
+ \changefield{##1}}%
+ \processcommalist[#2]\docommand
+ \fi
+\fi
+ \else
+ \writestatus\m!fields{pass parent field and copies}%
+ \fi}
+
+\def\copyfield{\dodoubleempty\docopyfield}
+
+\unexpanded\def\field {\dotripleempty\dofield[\dohandlefield]}
+\unexpanded\def\fitfield{\dotripleempty\dofield[\dohandlefitfield]}
+
+\def\dofield[#1][#2][#3]%
+ {\iffirstargument
+ \bgroup
+ \getfield{#2}%
+ \ifsecondargument
+ \def\@@DriverFieldLabel{#3}%
+ \else
+ \let\@@DriverFieldLabel\@@DriverFieldName
+ \fi
+ \ifx\@@DriverFieldType\empty
+ \writestatus\m!fields{unknown field #2}%
+ \else\ifcase\@@DriverFieldFree\relax
+ \doifdefinedelse{\strippedcsname\setupfield\@@DriverFieldGroup}
+ {\let\dosetupfield=#1\getvalue{\strippedcsname\setupfield\@@DriverFieldGroup}}
+ {#1[\@@DriverFieldName][\v!label,\v!frame,\v!horizontal][][][]}%
+\iftrialtypesetting\else
+ \def\@@DriverFieldFree{1}%
+ \changefield{#2}%
+\fi
+ \else\ifcase\@@DriverFieldAuto\relax
+ % \writestatus\m!fields{field #2 already typeset}%
+ \else
+ % \writestatus\m!fields{field #2 automatically copied}%
+ \nextsystemfield
+ \copyfield[\@@DriverFieldName][\currentsystemfield]%
+ \dotripleempty\dofield[#1][\currentsystemfield][#3]% get the if's right
+ \fi\fi\fi
+ \egroup
+ \fi}
+
+\def\typesetfield
+ {\useJSscripts[fld]%
+ \ifx\@@DriverFieldRoot\empty \else
+ \let\@@SavedFieldName\@@DriverFieldName
+ \getfield\@@DriverFieldRoot
+ \ifcase\@@DriverFieldFree\relax
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetrecord
+\iftrialtypesetting\else
+ \def\@@DriverFieldFree{1}%
+ \changefield\@@DriverFieldName
+\fi
+ \fi
+ \getfield\@@SavedFieldName
+ \fi
+ \ifx\@@DriverFieldKids\empty
+ \donefalse
+ \else
+ \donetrue
+ \fi
+ \ifdone
+ \let\@@DriverFieldParent\@@DriverFieldName
+ %\addtocommalist\@@DriverFieldParent\@@DriverFieldKids
+ \appendtocommalist\@@DriverFieldParent\@@DriverFieldKids
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetfield
+ \let\@@DriverFieldMode\fieldchildmode
+ \fi
+ \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
+ \dopresetfield}
+
+\def\dopresetfield
+ {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType field}\fi\fi}
+
+\def\dopresetrecord
+ {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType record}\fi\fi}
+
+\def\dodefinethefieldset[#1][#2]%
+ {\dodefinefieldset{#1}{#2}}
+
+\def\definefieldset%
+ {\dodoubleargument\dodefinethefieldset}
+
+\def\normaldodosetupfield[#1][#2][#3][#4][#5]%
+ {\doifdefinedelse{\strippedcsname\setupfield#1}
+ {\pushmacro\dosetupfield
+ \def\dosetupfield[##1][##2][##3][##4][##5]%
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][##2,#2][##3,#3][##4,#4][##5,#5]}}%
+ \getvalue{\strippedcsname\setupfield#1}%
+ \popmacro\dosetupfield}
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}}
+
+\let\dodosetupfield\normaldodosetupfield
+
+\def\donosetupfield[#1][#2][#3][#4][#5]%
+ {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}
+
+\def\dosetupfield[#1][#2][#3][#4][#5]%
+ {\iffifthargument
+ \def\docommand##1{\dodosetupfield[##1][#2][#3][#4][#5]}%
+ \processcommalist[#1]\docommand
+ \else\ifthirdargument
+ \def\docommand##1{\dodosetupfield[##1][#2][][][#3]}%
+ \processcommalist[#1]\docommand
+ \else\ifsecondargument
+ \doifelse{#2}\v!reset
+ {\def\docommand##1{\donosetupfield[#1][][][][]}}
+ {\def\docommand##1{\dodosetupfield[##1][][][][#2]}}%
+ \processcommalist[#1]\docommand
+ \else\iffirstargument
+ \def\docommand##1{\dodosetupfield[##1][][][][]}%
+ \processcommalist[#1]\docommand
+ \else
+ \writestatus\m!fields{provide either 1, 2, 3 or 5 arguments}%
+ \fi\fi\fi\fi}
+
+\def\setupfield
+ {\doquintupleempty\dosetupfield}
+
+\def\dosetupfields[#1][#2][#3][#4]%
+ {\ifsecondargument
+ \def\dodosetupfield[##1][##2][##3][##4][##5]%
+ {\doifdefinedelse{\strippedcsname\setupfield##1}
+ {\def\dosetupfield[####1][####2][####3][####4][####5]%
+ {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,####2,##2][#2,####3,##3][#3,####4,##4][#4,####5,##5]}}%
+ \getvalue{\strippedcsname\setupfield##1}}
+ {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,##2][#2,##3][#3,##4][#4,##5]}}}%
+ \else\iffirstargument
+ \doifelse{#1}\v!reset
+ {\resetfields}
+ {\setupfields[][][][#1]}% checken
+ \else
+ \writestatus\m!fields{provide either 1 or 4 arguments}%
+ \fi\fi}
+
+\def\setupfields
+ {\doquadrupleempty\dosetupfields}
+
+\def\resetfields
+ {\let\dodosetupfield\normaldodosetupfield}
+
+% \setupfields[\v!reset]
+
+% opties: veld, label, kader, vertikaal/horizontaal
+
+\newif\ifShowFieldLabel
+\newif\ifShowFieldFrame
+\newif\ifVerticalField
+\newif\ifHorizontalField
+
+% way to slow/complicated, we need some simple alternative
+% as well
+
+\def\dohandlefield[#1][#2][#3][#4][#5]%
+ {\presetlocalframed[\??fd]%
+ \processallactionsinset
+ [#2]
+ [ \v!reset=>\ShowFieldLabelfalse\ShowFieldFramefalse
+ \HorizontalFieldfalse\VerticalFieldfalse,
+ \v!label=>\ShowFieldLabeltrue,
+ \v!frame=>\ShowFieldFrametrue,
+ \v!horizontal=>\HorizontalFieldtrue,
+ \v!vertical=>\VerticalFieldtrue]%
+ \ifVerticalField
+ \getparameters[\??fd]
+ [\c!distance=\!!zeropoint,\c!inbetween=\vskip\@@localoffset,
+ \c!align=\v!right,\c!width=20em]%
+ \else\ifHorizontalField
+ \getparameters[\??fd]
+ [\c!distance=\@@localoffset,\c!inbetween=,\c!align=\c!left,
+ \c!height=10ex]%
+ \else
+ \getparameters[\??fd]
+ [\c!distance=\!!zeropoint,\c!inbetween=,\c!align=\c!left]%
+ \fi\fi
+ \getparameters[\??fd]
+ [\c!n=,\c!before=,\c!after=\vss,\c!style=,\c!color=,#3]%
+ \reshapeframeboxfalse % else ugly spacing
+ \ifShowFieldFrame
+ \localframed[\??fd][\c!strut=\v!no,\c!align=]\bgroup
+ \else
+ \vbox\bgroup
+ \fi
+ \dontcomplain
+ \ifShowFieldLabel
+ \setbox0\hbox
+ {\reshapeframeboxtrue % else wrong dimensions
+ \framed
+ [\c!style=,\c!color=,\c!align=\c!right,#4]
+ {\@@DriverFieldLabel}}%
+ \fi
+ \setbox2\hbox
+ {\reshapeframeboxtrue % else wrong dimensions
+ \ifVerticalField
+ \setupframed[\c!height=6ex,\c!width=\hsize]%
+ \else\ifHorizontalField
+ \setupframed[\c!height=\vsize,\c!width=20em]%
+ \else
+ \setupframed[\c!height=2cm,\c!width=2cm]%
+ \fi\fi
+ \framed
+ [\c!align=\v!right,\c!strut=\v!no,#5]
+ {\getparameters
+ [\??fd]
+ [\c!color=,\c!style=,\c!align=\v!right,\c!option=,
+ \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
+ \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
+ \c!focusin=,\c!focusout=,
+ \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
+ \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5]%
+ \scratchdimen\framedwidth \edef\@@DriverFieldWidth {\the\scratchdimen}%
+ \scratchdimen\framedheight\edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \vfill
+ \hbox{\lower\@@fdfieldoffset\hbox{\typesetfield}}
+ \vss}}%
+ \ifShowFieldLabel
+ \ifVerticalField
+ \vbox
+ {\copy0
+ \@@fdinbetween
+ \copy2}%
+ \else
+ \hbox
+ {\vbox \ifdim\ht2>\ht0 to \ht2 \fi
+ {\@@fdbefore
+ \copy0
+ \@@fdafter}%
+ \hskip\@@fddistance
+ \vbox \ifdim\ht0>\ht2 to \ht0 \fi
+ {\@@fdbefore
+ \box2
+ \@@fdafter}}%
+ \fi
+ \else
+ \box2
+ \fi
+ \egroup}
+
+\chardef\fitfieldmode\plusone % 3 = best
+
+\def\dohandlefitfield[#1][#2][#3][#4][#5]% alleen check
+ {\presetlocalframed[\??fd]%
+ \localframed
+ [\??fd]
+ [\c!n=1024, % beware: weblink plug in truncates
+ \c!strut=\v!no,\c!color=,\c!style=,\c!option=,
+ \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
+ \c!focusin=,\c!focusout=,
+ \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
+ \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
+ \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5,\c!align=]
+ {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldValue
+ \ifx\@@DriverFieldValue\empty
+ \let\@@DriverFieldValue\@@DriverFieldDefault
+ \fi
+ \dopresetfieldsymbol\@@DriverFieldValue
+ \setbox\scratchbox\hbox{\dogetfieldsymbol\@@DriverFieldValue}%
+ \scratchdimen\wd\scratchbox \edef\@@DriverFieldWidth {\the\scratchdimen}%
+ \scratchdimen\ht\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \ifcase\fitfieldmode
+ \typesetfield
+ \or % 1 = ignore depth (original, assumed no depth, actually a bug)
+ \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
+ \or % 2 = add depth to height, but no depth in result
+ \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
+ \or % 3 = add depth to height, and apply depth to result
+ \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
+ \hbox to \wd\scratchbox{\lower\dp\scratchbox\hbox{\typesetfield}\hfill}%
+ \fi}}
+
+%D Common stuff
+
+\newcounter\nofsystemfields
+
+\def\nextsystemfield
+ {\doglobal\increment\nofsystemfields
+ \def\currentsystemfield{sys::\nofsystemfields}}
+
+%D An example:
+
+\def\fillinfield
+ {\dosingleempty\dofillinfield}
+
+\def\dofillinfield[#1]#2%
+ {\dontleavehmode
+ \hbox
+ {\forgetall
+ \setupfields[\v!reset]%
+ \nextsystemfield
+ \useJSscripts[ans]%
+ \doifelsenothing{#1}
+ {\def\therightanswer{#2}}
+ {\def\therightanswer{#1}}%
+ \setbox0\hbox{#2}%
+ \setbox2\hbox{\therightanswer}%
+ \dimen0=\ifdim\wd0>\wd2 \wd0 \else \wd2 \fi
+ \advance\dimen0 .2em
+ \definefield
+ [\currentsystemfield][line][systemfield]%
+ \setupfield
+ [systemfield]
+ [\c!n=1024, % beware: weblink plugin truncates
+ \c!location=\v!low,\c!strut=\v!yes,\c!fieldoffset=0pt,
+ \c!height=1.2\openlineheight,\c!width=\dimen0,\c!offset=\v!overlay,
+ \c!style=,\c!align=\v!middle,\c!frame=\v!off,
+ \c!color=red,\c!fieldbackgroundcolor=\s!white,\c!fieldframecolor=blue,
+ \c!validate=JS(Check_Answer{\currentsystemfield,\therightanswer})]%
+ \switchtobodyfont
+ [\c!small]%
+ \hbox to \wd0
+ {\copy0\hskip-\wd0\hss\field[\currentsystemfield]\hss}}}
+
+%D and another one:
+
+\def\tooltip
+ {\dosingleempty\dotooltip}
+
+\def\dotooltip[#1]#2#3%
+ {\bgroup
+ \setupfields[\v!reset]%
+ \useJSscripts[fld]%
+ \setbox0\hbox
+ {\dontcomplain
+ \nextsystemfield
+ \setbox0\hbox{#2}%
+ \definesymbol
+ [\currentsystemfield:txt]
+ [{\inframed[\c!frame=\v!off,\c!background=\v!screen]{#3}}]%
+ \setbox2\hbox{\symbol[\currentsystemfield:txt]}%
+ \definefield
+ [\currentsystemfield:txt][check]
+ [dummy][\currentsystemfield:txt][\currentsystemfield:txt]%
+ \setupfield
+ [dummy]
+ [\c!frame=\v!off,
+ \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
+ \c!option=\v!hidden]%
+ \hbox to \zeropoint
+ {\dimen0\wd2\advance\dimen0 -\wd0
+ \doifelse{#1}\v!left
+ {\hskip-\dimen0}
+ {\doif{#1}\v!middle
+ {\hskip-.5\dimen0}}%
+ \lower\openlineheight\hbox to \zeropoint
+ {\fitfield[\currentsystemfield:txt]}}%
+ \dimen0=\ifdim\wd0=\zeropoint 3em\else\wd0\fi
+ \definesymbol
+ [\currentsystemfield:but]
+ [{\framed[\c!height=2ex,\c!width=\dimen0,\c!frame=\v!off]{}}]%
+ \definefield
+ [\currentsystemfield:but][push]
+ [dummy][\currentsystemfield:but][\currentsystemfield:but]%
+ \setupfield
+ [dummy]
+ [\c!frame=\v!off,
+ \c!option=,
+ \c!regionin=JS(Vide_Field{\currentsystemfield:txt}),
+ \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
+ \c!fieldlayer=\@@iafieldlayer]%
+ \lower2ex\hbox to \zeropoint
+ {\fitfield[\currentsystemfield:but]}%
+ #2}%
+ \ht0\strutht\dp0\strutdp\box0
+ \egroup}
+
+%D And one more:
+
+\def\definefieldstack
+ {\dotripleargument\dodefinefieldstack}
+
+\def\dodefinefieldstack[#1][#2][#3]% name, symbols, settings
+ {\doifundefined{fieldstack:#1}
+ {\setgvalue{fieldstack:#1}{\dodofieldstack[#1][#2][#3]}}}
+
+\def\dodofieldstack[#1][#2][#3]% start=n, 0 == leeg
+ {\bgroup
+ \getparameters[\??fd][\c!start=1,#3]%
+ \setupfields[\v!reset]%
+ \definesymbol[\v!empty][]%
+ \useJSscripts[fld][FieldStack]%
+ \newcounter\stackedfieldnumber
+ \def\dododofieldstack##1%
+ {\increment\stackedfieldnumber
+ \ifnum\stackedfieldnumber=\@@fdstart\relax
+ \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][##1]%
+ \else
+ \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][\v!empty]%
+ \fi}%
+ \processcommalist[#2]\dododofieldstack
+ \setupfield[#1][\v!reset]% added
+ \setupfield[#1][\c!option=\v!readonly,#3]% #3 swapped
+ \newcounter\stackedfieldnumber
+ \def\dododofieldstack##1%
+ {\doglobal\increment\stackedfieldnumber
+ \fitfield[#1:\stackedfieldnumber]\egroup\bgroup}%
+ \startoverlay
+ \bgroup
+ \globalprocesscommalist[#2]\dododofieldstack
+ \egroup
+ \stopoverlay
+ \egroup}
+
+\def\dofieldstack[#1][#2][#3]%
+ {\ifsecondargument
+ \dodefinefieldstack[#1][#2][#3]\fieldstack[#1]%
+ \else
+ \getvalue{fieldstack:#1}\setgvalue{fieldstack:#1}{[#1]}%
+ \fi}
+
+\def\fieldstack
+ {\dotripleempty\dofieldstack}
+
+%D When submitting a form, we need to tell the driver module
+%D that we want \FDF\ or \HTML.
+
+\def\setupforms
+ {\dodoubleargument\getparameters[\??fr]}
+
+\def\checksubmitform#1%
+ {\setsubmitoutputformat\@@frmethod}
+
+\setexecutecommandcheck {submitform} \checksubmitform
+
+\setupforms
+ [\c!method=HTML]
+
+\protect \endinput
diff --git a/tex/context/base/core-fld.tex b/tex/context/base/core-fld.tex
deleted file mode 100644
index 3b1ce9b3f..000000000
--- a/tex/context/base/core-fld.tex
+++ /dev/null
@@ -1,1080 +0,0 @@
-%D \module
-%D [ file=core-fld,
-%D version=1997.05.18,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Fill in fields,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% \appendtocommalist versus \addtocommalist
-%
-% * as default trigger in radiofields ?
-%
-% beware: weblink plugin truncates on length, while save as doesn't;
-% more precise: (1) first time right string is sent, (2)
-% internal string truncated, (3) second time truncated
-% string is sent.
-
-\writestatus{loading}{Context Field Macros}
-
-% messages
-
-\definemessageconstant{fields}
-
-\unprotect
-
-%D First we hook fields into the (viewer based) layering mechanism
-%D (implemented as properties).
-
-\ifx\currentlayerproperty\undefined\else \let\currentlayerproperty\empty\fi
-
-\appendtoks
- \doif\@@iafieldlayer\v!auto
- {\def\@@iafieldlayer{\currentlayerproperty}}%
-\to \everysetupinteraction
-
-\setupinteraction
- [\c!fieldlayer=\v!auto] % auto by default
-
-%D Internal command, linked to \type{\definesymbol}.
-
-\def\dogetfieldsymbol#1%
- {\getobject{SYM}{#1}}
-
-\def\dopresetfieldsymbol#1%
- {\checkobjectreferences
- \doifobjectfoundelse{SYM}{#1}
- {}
- {\settightobject{SYM}{#1}\hbox{\symbol[#1]}%
- \flushatshipout
- {\setbox0\hbox{\hskip-\maxdimen\getobject{SYM}{#1}}%
- \smashbox0\box0}}}
-
-\def\presetfieldsymbols[#1]% slow
- {\def\dopresetfieldsymbols##1%
- {\processcommalist[##1]\dopresetfieldsymbol}%
- \@EA\processcommalist\@EA[#1]\dopresetfieldsymbols}
-
-\def\definedefaultsymbols
- {\definesymbol[defaultyes][$\times$]%
- \definesymbol[defaultno][$\cdot$]}
-
-\def\resetfieldsymbol[#1]% for experimental usage only
- {\resetobject{SYM}{#1}}
-
-%D The interface to the specials. DEFAULT NOG ANDERS
-
-\def\preparefieldvariables % evt \def's at the outer level (test) or \edef's here for fast testing
- {\let\@@DriverFieldNumber \@@fdn
- \let\@@DriverFieldStyle \@@fdstyle
- \let\@@DriverFieldColor \@@fdcolor
- \let\@@DriverFieldBackgroundColor\@@fdfieldbackgroundcolor
- \let\@@DriverFieldFrameColor \@@fdfieldframecolor
- \let\@@DriverFieldLayer \@@fdfieldlayer
- \let\@@DriverFieldOption \@@fdoption
- \let\@@DriverFieldAlign \@@fdalign
- \let\@@DriverFieldClickIn \@@fdclickin
- \let\@@DriverFieldClickOut \@@fdclickout
- \let\@@DriverFieldRegionIn \@@fdregionin
- \let\@@DriverFieldRegionOut \@@fdregionout
- \let\@@DriverFieldAfterKey \@@fdafterkey
- \let\@@DriverFieldFormat \@@fdformat
- \let\@@DriverFieldValidate \@@fdvalidate
- \let\@@DriverFieldCalculate \@@fdcalculate
- \let\@@DriverFieldFocusIn \@@fdfocusin
- \let\@@DriverFieldFocusOut \@@fdfocusout}
-
-% todo : remove arguments, consider DriverField a namespace
-
-\def\presetlinefield
- {\preparefieldvariables
- \dopresetlinefield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldNumber}
- {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
- {\@@DriverFieldOption}
- {\@@DriverFieldAlign}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presettextfield
- {\preparefieldvariables
- \dopresettextfield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldNumber}
- {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
- {\@@DriverFieldOption}
- {\@@DriverFieldAlign}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetchoicefield
- {\preparefieldvariables
- \dopresetchoicefield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
- {\@@DriverFieldOption}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetpopupfield
- {\preparefieldvariables
- \dopresetpopupfield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
- {\@@DriverFieldOption}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetcombofield
- {\preparefieldvariables
- \dopresetcombofield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldStyle,\@@DriverFieldColor,\@@DriverFieldBackgroundColor,\@@DriverFieldFrameColor}
- {\@@DriverFieldOption}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetcheckfield
- {\preparefieldvariables
- \presetfieldsymbols[\@@DriverFieldValues]%
- \dopresetcheckfield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldOption}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetpushfield
- {\preparefieldvariables
- %\edef\@@DriverFieldValues{{\@@DriverFieldValues}}% makes sure {a,b,c} is passed
- \presetfieldsymbols[\@@DriverFieldValues]%
- \dopresetpushfield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldOption}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetradiofield
- {\preparefieldvariables
- \presetfieldsymbols[\@@DriverFieldValues]%
- \dopresetradiofield
- {\@@DriverFieldName}
- {\@@DriverFieldWidth}
- {\@@DriverFieldHeight}
- {\@@DriverFieldDefault}
- {\@@DriverFieldOption}
- {\@@DriverFieldRoot}
- {\@@DriverFieldValues}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\presetradiorecord
- {\preparefieldvariables
- \dopresetradiorecord
- {\@@DriverFieldName}
- {\@@DriverFieldDefault}
- {\@@DriverFieldOption}
- {\@@DriverFieldKids}
- {\@@DriverFieldClickIn,\@@DriverFieldClickOut,\@@DriverFieldRegionIn,\@@DriverFieldRegionOut,%
- \@@DriverFieldAfterKey,\@@DriverFieldFormat,\@@DriverFieldValidate,\@@DriverFieldCalculate,%
- \@@DriverFieldFocusIn,\@@DriverFieldFocusOut}}
-
-\def\setfieldmodes#1#2#3%
- {\xdef\@@DriverFieldMode{#1}% % 0 1 2 3
- \xdef\@@DriverFieldFree{#2}% % 0 1
- \xdef\@@DriverFieldAuto{#3}} % 0 1
-
-\newevery\everysetfield\relax
-
-\def\doiffieldelse#1{\doifdefinedelse{fielddata#1}}
-
-\def\setfield#1#2#3#4#5#6#7#8#9%
- {\bgroup
- \doglobal\increment\numberoffields
- \iftracefields
- \doglobal\addtocommalist{#1}\collectedfields
- \fi
- \the\everysetfield
- \setxvalue{fielddata#1}% kortere tag #7 needs expansion etc
- {\noexpand\dosetfield{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
- \egroup}
-
-\def\dosetfield#1#2#3#4#5#6#7#8#9%
- {\xdef\@@DriverFieldName {#1}%
- \xdef\@@DriverFieldType {#2}%
- \xdef\@@DriverFieldRoot {#3}%
- \xdef\@@DriverFieldParent {#4}%
- \xdef\@@DriverFieldKids {#5}%
- \xdef\@@DriverFieldGroup {#6}%
- \setfieldmodes #7%
- \bgroup
- \def\par{\string\n\string\n}%
- \xdef\@@DriverFieldValues {#8}%
- \xdef\@@DriverFieldDefault{#9}%
- \egroup}
-
-\def\changefield#1%
- {\setfield{#1}\@@DriverFieldType\@@DriverFieldRoot\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldGroup
- {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}\@@DriverFieldValues\@@DriverFieldDefault}
-
-\def\getfield#1% name
- {\doifundefinedelse{fielddata#1}
- {\dosetfield{#1}\empty\empty\empty\empty\empty{\empty00}\empty\empty}
- {\getvalue{fielddata#1}}}
-
-\newif\iftracefields \tracefieldsfalse
-
-\let\tracefields\tracefieldstrue
-
-\def\doshowfields[#1]% todo: tabulate van maken en runtime
- {\bgroup
- \switchtobodyfont[8pt,tt]%
- \doifsomething{#1}{\def\collectedfields{#1}}%
- \ifx\collectedfields\empty
- \par specify [fieldlist] or say \type{\tracefieldstrue} first\par
- \else
- \def\normalizedfieldmode##1##2##3%
- {\ifcase0##2 \else\sl\fi
- \ifcase0##1 loner\or parent\or clone\or copy\fi}%
- \def\dosetfield##1##2##3##4##5##6##7##8##9%
- {##1#2#3#4#5#6&\normalizedfieldmode##7#8#9\cr}%
- \halign
- {#\strut\hss\quad\cr
- \noalign{\hrule}%
- NAME &TYPE &ROOT &
- PARENT&KIDS &GROUP &
- MODE &VALUES&DEFAULT\cr
- \noalign{\hrule}%
- \@EA\globalprocesscommalist\@EA[\collectedfields]\getfield
- \noalign{\hrule}}%
- \fi
- \egroup}
-
-\def\showfields
- {\dosingleempty\doshowfields}
-
-\def\dologfields[#1]%
- {\bgroup
- \immediate\openout\scratchwrite=fields.log
- \doifsomething{#1}{\def\collectedfields{#1}}%
- \ifx\colledtedfields\empty
- \immediate\write\scratchwrite{use \tracefieldstrue}%
- \else
- \def\normalizedfieldmode##1##2##3%
- {\edef\@@DriverFieldMode
- {\ifcase##1 loner \or parent \or clone \or copy \fi
- \ifcase##2 \else(done)\fi}}%
- \def\dosetfield##1##2##3##4##5##6##7##8##9%
- {\normalizedfieldmode##7%
- \immediate\write\scratchwrite
- {N=##1 / T=##2 / R=##3 / P=##4 / K=##5 / G=##6 /
- M=\@@DriverFieldMode\space/ V=##8 / D=##9}}%
- \processcommacommand[\collectedfields]\getfield
- \fi
- \immediate\closeout\scratchwrite
- \egroup}
-
-\def\logfields
- {\dosingleempty\doLogFields}
-
-%D \starttyping
-%D \definefield [name] [type] [group] [values] [default]
-%D
-%D \definefield [WWWW] [text] [textsetup] [default text]
-%D \definefield [XXXX] [push] [pushsetup] [yes,no] [yes]
-%D \definefield [XXXX] [check] [checksetup] [yes,no] [yes]
-%D \definefield [YYYY] [combo] [combosetup] [a,b,c,d] [b]
-%D \definefield [ZZZZ] [radio] [radiosetup] [W,X,Y,Z] [Y]
-%D
-%D \definesubfield [W] [subsetup] [p,q]
-%D \definesubfield [X,Y] [subsetup] [p,r]
-%D \definesubfield [Z] [subsetup] [y,z]
-%D
-%D evt \definemainfield ... wanneer geplaatst voor subs gegeven
-%D
-%D \clonefield [XXXX] [XX,YY] [mysetup] [on,off]
-%D \clonefield [Z] [AA,BB] [somesetup] [true,false]
-%D \clonefield [Z] [CC,DD] [anothersetup]
-%D
-%D \copyfield [XXXX] [PP,QQ,RR]
-%D
-%D \field[XXXX]
-%D \fitfield[XXXX]
-%D \stoptyping
-
-\newif\ifdefinemainfield \definemainfieldfalse
-
-%D We need to keep track of cloned (related) fields and so by
-%D maintaining lists of field clones.
-%D
-%D The first alternative used a two pass data list and was
-%D implemented as follows:
-%D
-%D \starttyping
-%D \def\getmainfieldkids#1%
-%D {\let\@@DriverFieldKids\empty
-%D \ifdefinemainfield
-%D \definetwopasslist{fld:#1}% defined by system
-%D \doloop
-%D {\gettwopassdata{fld:#1}%
-%D \iftwopassdatafound
-%D %\addtocommalist\twopassdata\@@DriverFieldKids
-%D \appendtocommalist\twopassdata\@@DriverFieldKids
-%D \else
-%D \exitloop
-%D \fi}%
-%D \fi}
-%D \stoptyping
-%D
-%D However, the next alternative is much faster when we have
-%D a field with thousands of clones, something not that
-%D imaginary.
-%D
-%D \starttyping
-%D \def\getmainfieldkids#1%
-%D {\let\@@DriverFieldKids\empty
-%D \ifdefinemainfield
-%D \definetwopasslist{fld:#1}% runtime defined by system
-%D \getnamedtwopassdatalist{fld:#1}\@@DriverFieldKids
-%D \fi}
-%D \stoptyping
-%D
-%D The data is written by file using:
-%D
-%D \starttyping
-%D \newcounter\nofmainfieldkids
-%D
-%D \def\setmainfieldkid#1#2%
-%D {\doglobal\increment\nofmainfieldkids
-%D \savetwopassdata{fld:#1}{\nofmainfieldkids}{#2}}
-%D \stoptyping
-%D
-%D The trade of of this mechanism is that for each cloned or
-%D copied field, the uitlity file is to be read in order to
-%D fetch the data.
-%D
-%D The next, much faster alternative uses a dedicated %
-%D reference mechanism.
-
-\def\setmainfieldkid#1#2%
- {\immediatewriteutilitycommand{\fieldreference{#1}{#2}}}
-
-\def\checkfieldreferences
- {\startnointerference
- \protectlabels
- \doutilities{fieldreferences}\jobname\empty\relax\relax
- \global\let\checkfieldreferences\relax
- \stopnointerference}
-
-\def\setfieldreferences
- {\def\fieldreference##1##2%
- {\ifundefined{\r!widget##1}%
- \setxvalue{\r!widget##1}{##2}%
- \else
- \edef\!!stringa{\getvalue{\r!widget##1}}%
- \setxvalue{\r!widget##1}{\!!stringa,##2}%
- \fi}}
-
-\def\resetfieldreferences
- {\let\fieldreference\gobbletwoarguments}
-
-\def\getmainfieldkids#1%
- {\checkfieldreferences
- \ifdefinemainfield
- \doifundefinedelse{\r!widget#1}%
- {\let\@@DriverFieldKids\empty}
- {\@EA\let\@EA\@@DriverFieldKids\csname\r!widget#1\endcsname}%
- \else
- \let\@@DriverFieldKids\empty
- \fi}
-
-\resetfieldreferences
-
-%D Of course it costs a few more tokens to implement, but it's
-%D worth the memory: running for instance the 2000 page
-%D english examns publishing on demand document went down from
-%D 1350 seconds to less than 950 on a 650 Mhz pentium.
-
-\def\definefield
- {\definemainfieldfalse\doquintupleempty\dodefinefield}
-
-\def\definemainfield
- {\definemainfieldtrue \doquintupleempty\dodefinefield}
-
-\let\collectedfields\empty
-\newcounter\numberoffields
-\newcounter\totalnumberoffields
-
-\def\savenumberoffields
- {\ifcase\numberoffields\relax\else
- \savecurrentvalue\totalnumberoffields\numberoffields
- \fi}
-
-\appendtoks \savenumberoffields \to \everybye % \everylastshipout
-
-% \def\presetfieldreferences
-% {\ifnum\totalnumberoffields>0
-% \definereference[AtOpenInitializeForm][\v!ResetForm]%
-% \fi}
-%
-% \definereference[AtOpenInitializeForm][\v!geen]
-%
-% \appendtoks \presetfieldreferences \to \everycheckreferences
-
-\def\dodefinefield[#1][#2][#3][#4][#5]%
- {\ifsecondargument
- \edef\currentfieldname{#1}% just in case we're inside a loop
- \doifundefinedelse{define#2field}
- {\writestatus\m!fields{unknown field type #2}}
- {\doifundefined{fielddata\currentfieldname}
- {\getmainfieldkids\currentfieldname
- \ifdefinemainfield
- \ifx\@@DriverFieldKids\empty
- \let\@@DriverFieldMode\fieldlonermode
- \else
- \let\@@DriverFieldMode\fieldparentmode
- \fi
- \def\@@DriverFieldAuto{1}%
- \else
- \let\@@DriverFieldMode\fieldlonermode
- \def\@@DriverFieldAuto{0}%
- \fi
- \def\@@DriverFieldFree{0}%
- \getvalue{define#2field}{\currentfieldname}{#2}{#3}{#4}{#5}}}%
- \else
- \writestatus\m!fields{pass fieldname and fieldtype}%
- \fi}
-
-\def\definelinefield#1#2#3#4#5%
- {\setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{#4}}
-
-\let\definetextfield=\definelinefield
-
-\def\definechoicefield#1#2#3#4#5%
- {\doifelsenothing{#4}
- {\def\@@DriverFieldValues{yes,no}}
- {\def\@@DriverFieldValues{#4}}%
- \doifelsenothing{#5}
- {\dogetcommacommandelement2\from\@@DriverFieldValues \to\@@DriverFieldDefault
- \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
- {\def\@@DriverFieldDefault{#5}}%
- \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
-
-\let\definepopupfield=\definechoicefield
-\let\definecombofield=\definechoicefield
-
-%\def\definecheckfield#1#2#3#4#5%
-% {\doifelsenothing{#4}
-% {\definedefaultsymbols
-% \def\@@DriverFieldValues{defaultyes}}
-% {\def\@@DriverFieldValues{#4}}%
-% \doifelsenothing{#5}
-% {\dogetcommacommandelement2\from\@@DriverFieldValues\to\@@DriverFieldDefault
-% \dogetcommacommandelement1\from\@@DriverFieldDefault\to\@@DriverFieldDefault}
-% {\def\@@DriverFieldDefault{#5}}%
-% \setfield{#1}{#2}{}{}{\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{\@@DriverFieldValues}{\@@DriverFieldDefault}}
-
-%D Since these fields have an on/off state only, we pass 1/0
-%D to the driver as default values.
-
-\def\definecheckfield#1#2#3#4#5%
- {\doifelsenothing{#4}
- {\definedefaultsymbols
- \def\@@DriverFieldValues{defaultyes}}
- {\def\@@DriverFieldValues{#4}}%
- \doifelsenothing{#5}
- {\def\@@DriverFieldDefault{2}}
- {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldDefault
- \doifinstringelse{#5}{\@@DriverFieldDefault}
- {\def\@@DriverFieldDefault{1}}
- {\def\@@DriverFieldDefault{0}}}%
- \setfield
- {#1}{#2}{}{}{\@@DriverFieldKids}{#3}%
- {\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}%
- {\@@DriverFieldValues}{\@@DriverFieldDefault}}
-
-\let\definepushfield=\definecheckfield
-
-\def\defineradiofield#1#2#3#4#5%
- {\iffourthargument
- \doifelsenothing{#5}
- {\dogetcommacommandelement1\from#4\to\SavedFieldDefault
- \dogetcommacommandelement1\from\SavedFieldDefault\to\SavedFieldDefault}
- {\def\SavedFieldDefault{#5}}%
-% when opt works
-% \@EA\beforesplitstring\SavedFieldDefault\at=>\to\SavedFieldDefault
- \ifx\@@DriverFieldKids\empty
- \setfield{#1}{#2}{}{}{#4}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
- \else
- \setfield{#1}{#2}{}{}{#4,\@@DriverFieldKids}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\SavedFieldDefault}%
- \fi
-%
- \def\docommand##1%
- {\doifelse{##1}\SavedFieldDefault
- {\def\@@DriverFieldDefault{##1}}%
- {\let\@@DriverFieldDefault\empty}%
- \setfield{##1}{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
-% when opt works
-% \def\docommand##1%
-% {\@EA\beforesplitstring##1\at=>\to\FieldValue
-% \doifelse\FieldValue\SavedFieldDefault
-% {\let\@@DriverFieldDefault\FieldValue}%
-% {\let\@@DriverFieldDefault\empty}%
-% \setfield\FieldValue{#2}{#1}{}{}{#3}{\@@DriverFieldMode\@@DriverFieldFree\@@DriverFieldAuto}{}{\@@DriverFieldDefault}}%
- \processcommalist[#4]\docommand
- \else
- \writestatus\m!fields{pass values too}%
- \fi}
-
-\def\definesubfield
- {\dotripleempty\dodefinesubfield}
-
-\def\dodefinesubfield[#1][#2][#3]% for the moment only radio ones
- {\ifsecondargument
- \def\docommand##1%
- {\getfield{##1}%
- \ifx\@@DriverFieldType\empty
- \writestatus\m!fields{unknown field ##1}% to do
- \else
- \doifsomething{#2}
- {\edef\@@DriverFieldGroup{#2}}%
- \doifelsenothing{#3}
- {\definedefaultsymbols
- \def\@@DriverFieldValues{defaultyes}}
- {\def\@@DriverFieldValues{#3}}%
- \changefield{##1}%
- \fi}%
- \processcommalist[#1]\docommand
- \else
- \writestatus\m!fields{pass fieldname, setupgroup, values and default}%
- \fi}
-
-\def\doclonefield[#1][#2][#3][#4]% parent children setupgroup values
- {\ifsecondargument
- \getfield{#1}%
-\iftrialtypesetting\else
- \ifx\@@DriverFieldType\empty
- \writestatus\m!fields{unknown field #1}%
- \else
- \let\@@DriverFieldMode\fieldparentmode
- %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
- \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
- \processcommalist[#2]\docommand
- \changefield{#1}%
- \let\@@DriverFieldAutoParent\@@DriverFieldAuto
- \def\@@DriverFieldParent{#1}%
- \let\@@DriverFieldKids\empty
- \let\@@DriverFieldRoot\empty
- \let\@@DriverFieldMode\fieldchildmode
- \def\@@DriverFieldFree{0}%
- \def\@@DriverFieldAuto{0}%
- \doifsomething{#3}{\edef\@@DriverFieldGroup{#3}}%
- \doifsomething{#4}{\edef\@@DriverFieldValues{#4}}%
- \def\docommand##1%
- {\ifcase\@@DriverFieldAutoParent\else
- \setmainfieldkid{\@@DriverFieldParent}{##1}%
- \fi
- \changefield{##1}}%
- \processcommalist[#2]\docommand
- \fi
-\fi
- \else
- \writestatus\m!fields{pass parent field and clones}%
- \fi}
-
-\def\clonefield
- {\doquadrupleempty\doclonefield}
-
-\def\docopyfield[#1][#2]% parent children
- {\ifsecondargument
- \getfield{#1}%
-\iftrialtypesetting\else
- \ifx\@@DriverFieldType\empty
- \writestatus\m!fields{unknown field #1}%
- \else
- \let\@@DriverFieldMode\fieldparentmode
- %\def\docommand##1{\addtocommalist{##1}\@@DriverFieldKids}%
- \def\docommand##1{\appendtocommalist{##1}\@@DriverFieldKids}%
- \processcommalist[#2]\docommand
- \changefield{#1}%
- \let\@@DriverFieldAutoParent\@@DriverFieldAuto
- \def\@@DriverFieldParent{#1}%
- \let\@@DriverFieldKids\empty
- \let\@@DriverFieldRoot\empty
- \let\@@DriverFieldMode\fieldcopymode
- \def\@@DriverFieldFree{0}%
- \def\@@DriverFieldAuto{0}%
- \def\docommand##1%
- {\ifcase\@@DriverFieldAutoParent\else
- \setmainfieldkid{\@@DriverFieldParent}{##1}%
- \fi
- \changefield{##1}}%
- \processcommalist[#2]\docommand
- \fi
-\fi
- \else
- \writestatus\m!fields{pass parent field and copies}%
- \fi}
-
-\def\copyfield{\dodoubleempty\docopyfield}
-
-\unexpanded\def\field {\dotripleempty\dofield[\dohandlefield]}
-\unexpanded\def\fitfield{\dotripleempty\dofield[\dohandlefitfield]}
-
-\def\dofield[#1][#2][#3]%
- {\iffirstargument
- \bgroup
- \getfield{#2}%
- \ifsecondargument
- \def\@@DriverFieldLabel{#3}%
- \else
- \let\@@DriverFieldLabel\@@DriverFieldName
- \fi
- \ifx\@@DriverFieldType\empty
- \writestatus\m!fields{unknown field #2}%
- \else\ifcase\@@DriverFieldFree\relax
- \doifdefinedelse{\strippedcsname\setupfield\@@DriverFieldGroup}
- {\let\dosetupfield=#1\getvalue{\strippedcsname\setupfield\@@DriverFieldGroup}}
- {#1[\@@DriverFieldName][\v!label,\v!frame,\v!horizontal][][][]}%
-\iftrialtypesetting\else
- \def\@@DriverFieldFree{1}%
- \changefield{#2}%
-\fi
- \else\ifcase\@@DriverFieldAuto\relax
- % \writestatus\m!fields{field #2 already typeset}%
- \else
- % \writestatus\m!fields{field #2 automatically copied}%
- \nextsystemfield
- \copyfield[\@@DriverFieldName][\currentsystemfield]%
- \dotripleempty\dofield[#1][\currentsystemfield][#3]% get the if's right
- \fi\fi\fi
- \egroup
- \fi}
-
-\def\typesetfield
- {\useJSscripts[fld]%
- \ifx\@@DriverFieldRoot\empty \else
- \let\@@SavedFieldName\@@DriverFieldName
- \getfield\@@DriverFieldRoot
- \ifcase\@@DriverFieldFree\relax
- \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
- \dopresetrecord
-\iftrialtypesetting\else
- \def\@@DriverFieldFree{1}%
- \changefield\@@DriverFieldName
-\fi
- \fi
- \getfield\@@SavedFieldName
- \fi
- \ifx\@@DriverFieldKids\empty
- \donefalse
- \else
- \donetrue
- \fi
- \ifdone
- \let\@@DriverFieldParent\@@DriverFieldName
- %\addtocommalist\@@DriverFieldParent\@@DriverFieldKids
- \appendtocommalist\@@DriverFieldParent\@@DriverFieldKids
- \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
- \dopresetfield
- \let\@@DriverFieldMode\fieldchildmode
- \fi
- \dosetfieldstatus\@@DriverFieldMode\@@DriverFieldParent\@@DriverFieldKids\@@DriverFieldRoot
- \dopresetfield}
-
-\def\dopresetfield
- {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType field}\fi\fi}
-
-\def\dopresetrecord
- {\iftrialtypesetting\else\iflocation\getvalue{preset\@@DriverFieldType record}\fi\fi}
-
-\def\dodefinethefieldset[#1][#2]%
- {\dodefinefieldset{#1}{#2}}
-
-\def\definefieldset%
- {\dodoubleargument\dodefinethefieldset}
-
-\def\normaldodosetupfield[#1][#2][#3][#4][#5]%
- {\doifdefinedelse{\strippedcsname\setupfield#1}
- {\pushmacro\dosetupfield
- \def\dosetupfield[##1][##2][##3][##4][##5]%
- {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][##2,#2][##3,#3][##4,#4][##5,#5]}}%
- \getvalue{\strippedcsname\setupfield#1}%
- \popmacro\dosetupfield}
- {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}}
-
-\let\dodosetupfield\normaldodosetupfield
-
-\def\donosetupfield[#1][#2][#3][#4][#5]%
- {\setvalue{\strippedcsname\setupfield#1}{\dosetupfield[#1][#2][#3][#4][#5]}}
-
-\def\dosetupfield[#1][#2][#3][#4][#5]%
- {\iffifthargument
- \def\docommand##1{\dodosetupfield[##1][#2][#3][#4][#5]}%
- \processcommalist[#1]\docommand
- \else\ifthirdargument
- \def\docommand##1{\dodosetupfield[##1][#2][][][#3]}%
- \processcommalist[#1]\docommand
- \else\ifsecondargument
- \doifelse{#2}\v!reset
- {\def\docommand##1{\donosetupfield[#1][][][][]}}
- {\def\docommand##1{\dodosetupfield[##1][][][][#2]}}%
- \processcommalist[#1]\docommand
- \else\iffirstargument
- \def\docommand##1{\dodosetupfield[##1][][][][]}%
- \processcommalist[#1]\docommand
- \else
- \writestatus\m!fields{provide either 1, 2, 3 or 5 arguments}%
- \fi\fi\fi\fi}
-
-\def\setupfield
- {\doquintupleempty\dosetupfield}
-
-\def\dosetupfields[#1][#2][#3][#4]%
- {\ifsecondargument
- \def\dodosetupfield[##1][##2][##3][##4][##5]%
- {\doifdefinedelse{\strippedcsname\setupfield##1}
- {\def\dosetupfield[####1][####2][####3][####4][####5]%
- {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,####2,##2][#2,####3,##3][#3,####4,##4][#4,####5,##5]}}%
- \getvalue{\strippedcsname\setupfield##1}}
- {\setvalue{\strippedcsname\setupfield##1}{\dosetupfield[##1][#1,##2][#2,##3][#3,##4][#4,##5]}}}%
- \else\iffirstargument
- \doifelse{#1}\v!reset
- {\resetfields}
- {\setupfields[][][][#1]}% checken
- \else
- \writestatus\m!fields{provide either 1 or 4 arguments}%
- \fi\fi}
-
-\def\setupfields
- {\doquadrupleempty\dosetupfields}
-
-\def\resetfields
- {\let\dodosetupfield\normaldodosetupfield}
-
-% \setupfields[\v!reset]
-
-% opties: veld, label, kader, vertikaal/horizontaal
-
-\newif\ifShowFieldLabel
-\newif\ifShowFieldFrame
-\newif\ifVerticalField
-\newif\ifHorizontalField
-
-% way to slow/complicated, we need some simple alternative
-% as well
-
-\def\dohandlefield[#1][#2][#3][#4][#5]%
- {\presetlocalframed[\??fd]%
- \processallactionsinset
- [#2]
- [ \v!reset=>\ShowFieldLabelfalse\ShowFieldFramefalse
- \HorizontalFieldfalse\VerticalFieldfalse,
- \v!label=>\ShowFieldLabeltrue,
- \v!frame=>\ShowFieldFrametrue,
- \v!horizontal=>\HorizontalFieldtrue,
- \v!vertical=>\VerticalFieldtrue]%
- \ifVerticalField
- \getparameters[\??fd]
- [\c!distance=\!!zeropoint,\c!inbetween=\vskip\@@localoffset,
- \c!align=\v!right,\c!width=20em]%
- \else\ifHorizontalField
- \getparameters[\??fd]
- [\c!distance=\@@localoffset,\c!inbetween=,\c!align=\c!left,
- \c!height=10ex]%
- \else
- \getparameters[\??fd]
- [\c!distance=\!!zeropoint,\c!inbetween=,\c!align=\c!left]%
- \fi\fi
- \getparameters[\??fd]
- [\c!n=,\c!before=,\c!after=\vss,\c!style=,\c!color=,#3]%
- \reshapeframeboxfalse % else ugly spacing
- \ifShowFieldFrame
- \localframed[\??fd][\c!strut=\v!no,\c!align=]\bgroup
- \else
- \vbox\bgroup
- \fi
- \dontcomplain
- \ifShowFieldLabel
- \setbox0\hbox
- {\reshapeframeboxtrue % else wrong dimensions
- \framed
- [\c!style=,\c!color=,\c!align=\c!right,#4]
- {\@@DriverFieldLabel}}%
- \fi
- \setbox2\hbox
- {\reshapeframeboxtrue % else wrong dimensions
- \ifVerticalField
- \setupframed[\c!height=6ex,\c!width=\hsize]%
- \else\ifHorizontalField
- \setupframed[\c!height=\vsize,\c!width=20em]%
- \else
- \setupframed[\c!height=2cm,\c!width=2cm]%
- \fi\fi
- \framed
- [\c!align=\v!right,\c!strut=\v!no,#5]
- {\getparameters
- [\??fd]
- [\c!color=,\c!style=,\c!align=\v!right,\c!option=,
- \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
- \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
- \c!focusin=,\c!focusout=,
- \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
- \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5]%
- \scratchdimen\framedwidth \edef\@@DriverFieldWidth {\the\scratchdimen}%
- \scratchdimen\framedheight\edef\@@DriverFieldHeight{\the\scratchdimen}%
- \vfill
- \hbox{\lower\@@fdfieldoffset\hbox{\typesetfield}}
- \vss}}%
- \ifShowFieldLabel
- \ifVerticalField
- \vbox
- {\copy0
- \@@fdinbetween
- \copy2}%
- \else
- \hbox
- {\vbox \ifdim\ht2>\ht0 to \ht2 \fi
- {\@@fdbefore
- \copy0
- \@@fdafter}%
- \hskip\@@fddistance
- \vbox \ifdim\ht0>\ht2 to \ht0 \fi
- {\@@fdbefore
- \box2
- \@@fdafter}}%
- \fi
- \else
- \box2
- \fi
- \egroup}
-
-\chardef\fitfieldmode\plusone % 3 = best
-
-\def\dohandlefitfield[#1][#2][#3][#4][#5]% alleen check
- {\presetlocalframed[\??fd]%
- \localframed
- [\??fd]
- [\c!n=1024, % beware: weblink plug in truncates
- \c!strut=\v!no,\c!color=,\c!style=,\c!option=,
- \c!clickin=,\c!clickout=,\c!regionin=,\c!regionout=,
- \c!focusin=,\c!focusout=,
- \c!afterkey=,\c!format=,\c!validate=,\c!calculate=,
- \c!fieldoffset=\!!zeropoint,\c!fieldbackgroundcolor=,
- \c!fieldframecolor=,\c!fieldlayer=\@@iafieldlayer,#5,\c!align=]
- {\dogetcommacommandelement1\from\@@DriverFieldValues\to\@@DriverFieldValue
- \ifx\@@DriverFieldValue\empty
- \let\@@DriverFieldValue\@@DriverFieldDefault
- \fi
- \dopresetfieldsymbol\@@DriverFieldValue
- \setbox\scratchbox\hbox{\dogetfieldsymbol\@@DriverFieldValue}%
- \scratchdimen\wd\scratchbox \edef\@@DriverFieldWidth {\the\scratchdimen}%
- \scratchdimen\ht\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
- \ifcase\fitfieldmode
- \typesetfield
- \or % 1 = ignore depth (original, assumed no depth, actually a bug)
- \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
- \or % 2 = add depth to height, but no depth in result
- \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
- \vbox to \ht\scratchbox{\vfill\hbox to \wd\scratchbox{\typesetfield\hfill}\vss}%
- \or % 3 = add depth to height, and apply depth to result
- \advance\scratchdimen\dp\scratchbox \edef\@@DriverFieldHeight{\the\scratchdimen}%
- \hbox to \wd\scratchbox{\lower\dp\scratchbox\hbox{\typesetfield}\hfill}%
- \fi}}
-
-%D Common stuff
-
-\newcounter\nofsystemfields
-
-\def\nextsystemfield
- {\doglobal\increment\nofsystemfields
- \def\currentsystemfield{sys::\nofsystemfields}}
-
-%D An example:
-
-\def\fillinfield
- {\dosingleempty\dofillinfield}
-
-\def\dofillinfield[#1]#2%
- {\dontleavehmode
- \hbox
- {\forgetall
- \setupfields[\v!reset]%
- \nextsystemfield
- \useJSscripts[ans]%
- \doifelsenothing{#1}
- {\def\therightanswer{#2}}
- {\def\therightanswer{#1}}%
- \setbox0\hbox{#2}%
- \setbox2\hbox{\therightanswer}%
- \dimen0=\ifdim\wd0>\wd2 \wd0 \else \wd2 \fi
- \advance\dimen0 .2em
- \definefield
- [\currentsystemfield][line][systemfield]%
- \setupfield
- [systemfield]
- [\c!n=1024, % beware: weblink plugin truncates
- \c!location=\v!low,\c!strut=\v!yes,\c!fieldoffset=0pt,
- \c!height=1.2\openlineheight,\c!width=\dimen0,\c!offset=\v!overlay,
- \c!style=,\c!align=\v!middle,\c!frame=\v!off,
- \c!color=red,\c!fieldbackgroundcolor=\s!white,\c!fieldframecolor=blue,
- \c!validate=JS(Check_Answer{\currentsystemfield,\therightanswer})]%
- \switchtobodyfont
- [\c!small]%
- \hbox to \wd0
- {\copy0\hskip-\wd0\hss\field[\currentsystemfield]\hss}}}
-
-%D and another one:
-
-\def\tooltip
- {\dosingleempty\dotooltip}
-
-\def\dotooltip[#1]#2#3%
- {\bgroup
- \setupfields[\v!reset]%
- \useJSscripts[fld]%
- \setbox0\hbox
- {\dontcomplain
- \nextsystemfield
- \setbox0\hbox{#2}%
- \definesymbol
- [\currentsystemfield:txt]
- [{\inframed[\c!frame=\v!off,\c!background=\v!screen]{#3}}]%
- \setbox2\hbox{\symbol[\currentsystemfield:txt]}%
- \definefield
- [\currentsystemfield:txt][check]
- [dummy][\currentsystemfield:txt][\currentsystemfield:txt]%
- \setupfield
- [dummy]
- [\c!frame=\v!off,
- \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
- \c!option=\v!hidden]%
- \hbox to \zeropoint
- {\dimen0\wd2\advance\dimen0 -\wd0
- \doifelse{#1}\v!left
- {\hskip-\dimen0}
- {\doif{#1}\v!middle
- {\hskip-.5\dimen0}}%
- \lower\openlineheight\hbox to \zeropoint
- {\fitfield[\currentsystemfield:txt]}}%
- \dimen0=\ifdim\wd0=\zeropoint 3em\else\wd0\fi
- \definesymbol
- [\currentsystemfield:but]
- [{\framed[\c!height=2ex,\c!width=\dimen0,\c!frame=\v!off]{}}]%
- \definefield
- [\currentsystemfield:but][push]
- [dummy][\currentsystemfield:but][\currentsystemfield:but]%
- \setupfield
- [dummy]
- [\c!frame=\v!off,
- \c!option=,
- \c!regionin=JS(Vide_Field{\currentsystemfield:txt}),
- \c!regionout=JS(Hide_Field{\currentsystemfield:txt}),
- \c!fieldlayer=\@@iafieldlayer]%
- \lower2ex\hbox to \zeropoint
- {\fitfield[\currentsystemfield:but]}%
- #2}%
- \ht0\strutht\dp0\strutdp\box0
- \egroup}
-
-%D And one more:
-
-\def\definefieldstack
- {\dotripleargument\dodefinefieldstack}
-
-\def\dodefinefieldstack[#1][#2][#3]% name, symbols, settings
- {\doifundefined{fieldstack:#1}
- {\setgvalue{fieldstack:#1}{\dodofieldstack[#1][#2][#3]}}}
-
-\def\dodofieldstack[#1][#2][#3]% start=n, 0 == leeg
- {\bgroup
- \getparameters[\??fd][\c!start=1,#3]%
- \setupfields[\v!reset]%
- \definesymbol[\v!empty][]%
- \useJSscripts[fld][FieldStack]%
- \newcounter\stackedfieldnumber
- \def\dododofieldstack##1%
- {\increment\stackedfieldnumber
- \ifnum\stackedfieldnumber=\@@fdstart\relax
- \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][##1]%
- \else
- \definefield[#1:\stackedfieldnumber][check][#1][##1,\v!empty][\v!empty]%
- \fi}%
- \processcommalist[#2]\dododofieldstack
- \setupfield[#1][\v!reset]% added
- \setupfield[#1][\c!option=\v!readonly,#3]% #3 swapped
- \newcounter\stackedfieldnumber
- \def\dododofieldstack##1%
- {\doglobal\increment\stackedfieldnumber
- \fitfield[#1:\stackedfieldnumber]\egroup\bgroup}%
- \startoverlay
- \bgroup
- \globalprocesscommalist[#2]\dododofieldstack
- \egroup
- \stopoverlay
- \egroup}
-
-\def\dofieldstack[#1][#2][#3]%
- {\ifsecondargument
- \dodefinefieldstack[#1][#2][#3]\fieldstack[#1]%
- \else
- \getvalue{fieldstack:#1}\setgvalue{fieldstack:#1}{[#1]}%
- \fi}
-
-\def\fieldstack
- {\dotripleempty\dofieldstack}
-
-%D When submitting a form, we need to tell the driver module
-%D that we want \FDF\ or \HTML.
-
-\def\setupforms
- {\dodoubleargument\getparameters[\??fr]}
-
-\def\checksubmitform#1%
- {\setsubmitoutputformat\@@frmethod}
-
-\setexecutecommandcheck {submitform} \checksubmitform
-
-\setupforms
- [\c!method=HTML]
-
-\protect \endinput
diff --git a/tex/context/base/core-fnt.mkii b/tex/context/base/core-fnt.mkii
new file mode 100644
index 000000000..9bc2a66f5
--- /dev/null
+++ b/tex/context/base/core-fnt.mkii
@@ -0,0 +1,726 @@
+%D \module
+%D [ file=core-fnt,
+%D version=1995.10.10,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Fonts,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Fonts}
+
+\unprotect
+
+%D \macros
+%D {compound}
+%D
+%D We will overload the already active \type {|} so we have
+%D to save its meaning in order to be able to use this handy
+%D macro.
+%D
+%D \starttyping
+%D so test\compound{}test can be used instead of test||test
+%D \stoptyping
+
+\bgroup \catcode`\|=\@@active \gdef\compound#1{|#1|} \egroup
+
+%D Here we hook some code into the clean up mechanism needed
+%D for verbatim data.
+
+\appendtoks
+ \disablecompoundcharacters
+ \disablediscretionaries
+\to \everycleanupfeatures
+
+%D \macros
+%D {kap,KAP,Kap,Kaps,nokap,userealcaps,usepseudocaps}
+%D
+%D We already introduced \type{\cap} as way to capitalize
+%D words. This command comes in several versions:
+%D
+%D \startbuffer
+%D \cap {let's put on a \cap{cap}}
+%D \cap {let's put on a \nocap{cap}}
+%D \CAP {let's put on a \\{cap}}
+%D \Cap {let's put on a \\{cap}}
+%D \Caps{let's put on a cap}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D Note the use of \type{\nocap}, \type{\\} and the nested
+%D \type{\cap}.
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D These macros show te main reason why we introduced the
+%D smaller \type{\tx} and \type{\txx}.
+%D
+%D \starttyping
+%D \cap\romannumerals{1995}
+%D \stoptyping
+%D
+%D This at first sight unusual capitilization is completely
+%D legal.
+%D
+%D \showsetup{smallcapped}
+%D \showsetup{notsmallcapped}
+%D \showsetup{CAPPED}
+%D \showsetup{SmallCapped}
+%D \showsetup{SmallCaps}
+%D
+%D The difference between pseudo and real caps is demonstrated
+%D below:
+%D
+%D \startbuffer
+%D \usepseudocaps \cap{Hans Hagen}
+%D \userealcaps \cap{Hans Hagen}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D The \type {\bgroup} trickery below is needed because of
+%D \type {\groupedcommand}.
+
+\def\usepseudocaps
+ {\def\cap@@uppercase{\the\everyuppercase\uppercased}%
+ \def\cap@@lowercase{\the\everylowercase\lowercased}%
+ \def\cap@@visualize{\tx}}
+
+\def\userealcaps
+ {\let\cap@@uppercase\relax
+ %\let\cap@@lowercase\relax % Definitely not!
+ \def\cap@@visualize{\sc}}
+
+\usepseudocaps
+
+\unexpanded\def\smallcapped % else conflict with math
+ {\futurelet\next\dosmallcapped}
+
+\def\disablepseudocaps
+ {\let\smallcapped\donothing}
+
+\def\dosmallcapped
+ {\ifx\next\bgroup
+ \expandafter\dodosmallcapped\expandafter\relax
+ \else
+ \expandafter\dodosmallcapped
+ \fi}
+
+\def\dodosmallcapped#1#2%
+ {\ifmmode\hbox\fi
+ \bgroup
+ \cap@@visualize
+ \cap@@uppercase{#1{#2}}%
+ \egroup}
+
+\unexpanded\def\notsmallcapped#1%
+ {\cap@@lowercase{#1}}
+
+\unexpanded\def\CAPPED#1%
+ {{\def\\##1{\smallcapped{##1}}#1}}
+
+\unexpanded\def\SmallCapped#1%
+ {\CAPPED{\\#1}}
+
+\unexpanded\def\SmallCaps
+ {\let\processword\SmallCapped
+ \processwords}
+
+%D Sure:
+
+\def\kap{\smallcapped} % for old times sake
+
+%D Some precautions for a \PLAIN\ \TEX\ definition.
+
+\unexpanded\def\normalcap{\dohandlemathtoken{cap}}
+\unexpanded\def\normalCap{\dohandlemathtoken{Cap}}
+
+\def\cap{\mathortext\normalcap\smallcapped}
+\def\Cap{\mathortext\normalCap\SmallCapped}
+
+\appendtoks
+ \let\cap\firstofoneargument
+ \let\Cap\firstofoneargument
+\to \simplifiedcommands
+
+%D \macros
+%D {setupcapitals}
+%D
+%D By default we use pseudo small caps in titles. This can be
+%D set up with:
+%D
+%D \showsetup{setupcapitals}
+
+\let\normalsmallcapped\smallcapped
+
+\def\setupcapitals
+ {\dosingleempty\dosetupcapitals}
+
+\def\dosetupcapitals[#1]%
+ {\getparameters[\??kk][#1]%
+ \doifelse\@@kktitle\v!yes
+ {\definealternativestyle[\v!capital][\normalsmallcapped][\normalsmallcapped]%
+ \definealternativestyle[\v!smallcaps][\sc][\sc]%
+ \unexpanded\def\smallcapped{\normalsmallcapped}}
+ {\definealternativestyle[\v!capital][\normalsmallcapped][\uppercased]%
+ \definealternativestyle[\v!smallcaps][\sc][\uppercased]%
+ \unexpanded\def\smallcapped{\doconvertfont\v!capital}}%
+ \doifelse\@@kksc\v!yes
+ \userealcaps
+ \usepseudocaps}
+
+\ifx\uppercased\undefined \let\uppercased\uppercase \fi
+\ifx\lowercased\undefined \let\lowercased\lowercase \fi
+
+% pretty tricky stuff:
+%
+% \usemodule[abr-01] \TEX \METAPOST \PPCHTEX \LATEX
+% \usemodule[abr-02] \TEX \METAPOST \PPCHTEX \LATEX
+
+%def\uppercased#1{{\forceunexpanded\xdef\@@globalcrap{\uppercase{#1}}}\@@globalcrap}
+%def\lowercased#1{{\forceunexpanded\xdef\@@globalcrap{\lowercase{#1}}}\@@globalcrap}
+
+\def\uppercased#1{{\forceunexpanded\xdef\@@expanded{\uppercase{#1}}}\@@expanded}
+\def\lowercased#1{{\forceunexpanded\xdef\@@expanded{\lowercase{#1}}}\@@expanded}
+
+\setupcapitals
+ [\c!title=\v!yes,
+ \c!sc=\v!no]
+
+%D \macros
+%D {Word, Words, WORD, WORDS, doprocesswords}
+%D
+%D This is probably not the right place to present the next set
+%D of macros.
+%D
+%D \starttyping
+%D \Word {far too many words}
+%D \Words{far too many words}
+%D \WORD {far too many words}
+%D \WORDS{far too many words}
+%D \stoptyping
+%D
+%D \typebuffer
+%D
+%D This calls result in:
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D \showsetup{Word}
+%D \showsetup{Words}
+%D \showsetup{WORD}
+%D \showsetup{WORDS}
+
+\def\doWord#1%
+ {\bgroup
+ \the\everyuppercase
+ \uppercase{#1}%
+ \egroup}
+
+\unexpanded\def\Word#1%
+ {\doWord#1}
+
+\def\doprocesswords#1 #2\od
+ {\ConvertToConstant\doifnot{#1}{}
+ {\processword{#1} %
+ \doprocesswords#2 \od}}
+
+\def\processwords#1%
+ {\doprocesswords#1 \od\unskip}
+
+\let\processword\relax
+
+\unexpanded\def\Words
+ {\let\processword\Word
+ \processwords}
+
+\unexpanded\def\WORD#1%
+ {\bgroup
+ \let\smallcapped\firstofoneargument
+ \let\WORD\firstofoneargument
+ \douppercase{#1}%
+ \egroup}
+
+\unexpanded\def\WORDS#1%
+ {\WORD{#1}}
+
+%D \macros
+%D {stretched}
+%D
+%D Stretching characters in a word is a sort of typographical
+%D murder. Nevertheless we support this manipulation for use in
+%D for instance titles.
+%D
+%D \starttyping
+%D \hbox to 5cm{\stretched{murder}}
+%D \stoptyping
+%D
+%D \typebuffer
+%D
+%D or
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D \showsetup{stretched}
+
+\def\stretched#1%
+ {\ifvmode\hbox to \hsize\else\ifinner\else\hbox\fi\fi
+ \bgroup\processtokens\relax\hss\relax{\hss\hss}{#1}\egroup}
+
+%D \startbuffer
+%D \stretched{Unknown Box}
+%D \hbox to .5\hsize{\stretched{A Horizontal Box}}
+%D \vbox to 2cm{\stretched{A Vertical Box}}
+%D \hbox to 3cm{\stretched{sp{\'e}c{\`\i}{\"a}l}}
+%D \stopbuffer
+%D
+%D \getbuffer
+%D
+%D The first line of this macros takes care of boxing. Normally
+%D one will use an \type{\hbox} specification. The last line
+%D shows how special characters should be passed.
+%D
+%D \typebuffer
+
+%D \macros
+%D {stretchednormalcase, stretcheduppercase, stretchedlowercase}
+%D
+%D A convenient alternative is:
+%D
+%D \starttyping
+%D \stretcheduppercase{Is this what you like?}
+%D \stoptyping
+%D
+%D \typebuffer
+%D
+%D this one uses fixed skips and kerns.
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D The default skip can be set with:
+
+% \def\stretchedspacefactor{4}
+% \def\stretchedspaceamount{.25em}
+%
+% \unexpanded\def\stretcheduppercase#1%
+% {\bgroup
+% \the\everyuppercase
+% \uppercase{\def\textstring{#1}}%
+% \ifdim\stretchedspaceamount>\zeropoint
+% \def\textkern%
+% {\kern\stretchedspaceamount}%
+% \def\textskip%
+% {\scratchdimen=\stretchedspaceamount
+% \hskip\stretchedspacefactor\scratchdimen}%
+% \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
+% \textskip\@EA{\textstring}%
+% \else
+% \textstring
+% \fi
+% \egroup}
+
+%D Given the following settings, the space is 1em by default:
+
+\def\stretchedspacefactor{4}
+\def\stretchedspaceamount{.25em}
+\def\stretchedbreaktokens{.@/}
+
+\unexpanded\def\stretchednormalcase
+ {\stretchedsomecase\firstofoneargument}
+
+\unexpanded\def\stretcheduppercase
+ {\stretchedsomecase{\the\everyuppercase\uppercase}}
+
+\unexpanded\def\stretchedlowercase
+ {\stretchedsomecase{\the\everylowercase\lowercase}}
+
+\def\stretchedsomecase#1#2%
+ {\bgroup
+ #1{\def\textstring{#2}}%
+ \ifdim\stretchedspaceamount=\zeropoint
+ \textstring
+ \else
+ \def\textkern##1%
+ {% beware: ##1 may not be \box\somebox -)
+ \determinemidwordbreak{##1}{\stretchedbreaktokens}%
+ \kern\stretchedspaceamount##1\domidwordbreak}%
+ \def\textskip
+ {\scratchdimen\stretchedspaceamount
+ \hskip\stretchedspacefactor\scratchdimen}%
+ \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
+ \textskip\@EA{\textstring}%
+ \fi
+ \egroup}
+
+%D An auxiliary macro, see for usage \type {\stretcheduppercase}.
+
+\let\domidwordbreak\relax
+
+\def\setmidwordbreaktoken#1%
+ {\sfcode`#1=5000\relax}
+
+\def\determinemidwordbreak#1#2%
+ {\edef\midwordbreaktokens{#2}%
+ \ifx\midwordbreaktokens\empty
+ \global\let\domidwordbreak\relax
+ \else
+ \setbox\scratchbox\hbox
+ {\expandafter\handletokens\midwordbreaktokens\with\setmidwordbreaktoken
+ a\space \!!dimena\lastskip
+ #1\space\!!dimenb\lastskip \relax % needed
+ \ifdim\!!dimena=\!!dimenb
+ \globallet\domidwordbreak\relax
+ \else
+ \globallet\domidwordbreak\allowbreak
+ \fi}%
+ \fi}
+
+%D \macros
+%D {underbar,underbars,
+%D overbar,overbars,
+%D overstrike,overstrikes,
+%D setupunderbar}
+%D
+%D In the rare case that we need undelined words, for instance
+%D because all font alternatives are already in use, one can
+%D use \type{\underbar} and \type{\overstrike} and their plural
+%D forms.
+%D
+%D \startbuffer
+%D \underbars{drawing \underbar{bars} under words is a typewriter leftover}
+%D \overstrikes{striking words makes them \overstrike{unreadable} but
+%D sometimes even \overbar{top lines} come into view.}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D The next macros are derived from the \PLAIN\ \TEX\ one, but
+%D also supports nesting. The \type{$} keeps us in horizontal
+%D mode and at the same time applies grouping.
+%D
+%D \showsetup{underbar}
+%D \showsetup{underbars}
+%D \showsetup{overbar}
+%D \showsetup{overbars}
+%D \showsetup{overstrike}
+%D \showsetup{overstrikes}
+%D
+%D Although underlining is ill advised, we permit some
+%D alternatives, that can be set up by:
+%D
+%D \showsetup{setupunderbar}
+%D
+%D The alternatives show up as
+%D {\setupunderbar [alternative=a]\underbar{alternative a}},
+%D {\setupunderbar [alternative=b]\underbar{alternative b}},
+%D {\setupunderbar [alternative=c]\underbar{alternative c}}
+%D and
+%D {\setupunderbar [rulethickness=1pt]\underbar{1pt width}},
+%D {\setupunderbar [rulethickness=2pt]\underbar{2pt width}},
+%D or whatever. Because \type{\overstrike} uses the same
+%D method, the settings also apply to that macro.
+
+\newcount\underbarlevel
+
+\def\underbarmethoda#1#2#3% RULE
+ {\hbox to #1{\vrule\!!width#1\!!height#2\!!depth#3}}
+
+\def\underbarmethodb#1#2#3% DASH
+ {\hbox to #1
+ {\hskip-.25em
+ \xleaders
+ \hbox{\hskip.25em\vrule\!!width.25em\!!height#2\!!depth#3}
+ \hfil}}
+
+\def\underbarmethodc#1#2#3% PERIOD
+ {\hbox to #1
+ {\dimen4=#3
+ \advance\dimen4 .2ex
+ \hskip-.25em
+ \xleaders
+ \hbox{\hskip.25em\lower\dimen4\hbox{.}}
+ \hfil}}
+
+\def\dododounderbar#1#2#3%
+ {\startmathmode
+ \setbox0\hbox{#3}%
+ \setbox2\hbox{\color[\@@onrulecolor]{\getvalue{underbarmethod\@@onalternative}{\wd0}{#1}{#2}}}%
+ \wd0\zeropoint
+ \ht2\ht0
+ \dp2\dp0
+ \box0\box2
+ \stopmathmode}
+
+\unexpanded\def\dodounderbar#1%
+ {\bgroup
+ \dimen0=\@@onbottomoffset
+ \dimen0=\underbarlevel\dimen0
+ \ifdone \else
+ \advance\dimen0 -\strutht
+ \fi
+ \dimen2\dimen0
+ \advance\dimen2 \@@onrulethickness
+ \dododounderbar{-\dimen0}{\dimen2}{#1}%
+ \egroup}
+
+\def\betweenunderbarwords
+ {\bgroup
+ \setbox0\hbox{\dodounderbar{\hskip\interwordspace}}%
+ \nobreak
+ \hskip\zeropoint\!!minus\interwordshrink
+ \discretionary{}{}{\box0}%
+ \egroup}
+
+\def\betweenunderbarspaces
+ {\hskip\currentspaceskip}
+
+% \unexpanded\def\dounderbar#1#2%
+% {\let\betweenisolatedwords#1%
+% \processisolatedwords{#2}\dodounderbar
+% \egroup}
+
+\unexpanded\def\underbar
+ {\bgroup
+ \advance\underbarlevel\plusone
+ \donetrue
+ \dounderbar\betweenunderbarwords}
+
+\unexpanded\def\dounderbar#1%
+ {\let\betweenisolatedwords#1%
+ \dosingleempty\redounderbar}
+
+\unexpanded\def\redounderbar[#1]#2%
+ {\iffirstargument\setupunderbar[#1]\fi
+ \processisolatedwords{#2}\dodounderbar
+ \egroup}
+
+\unexpanded\def\underbars
+ {\bgroup
+ \advance\underbarlevel\plusone
+ \donetrue
+ \dounderbar\betweenunderbarspaces}
+
+\unexpanded\def\overbar
+ {\bgroup
+ \advance\underbarlevel\minusone
+ \donefalse
+ \dounderbar\betweenunderbarwords}
+
+\unexpanded\def\overbars
+ {\bgroup
+ \advance\underbarlevel\minusone
+ \donefalse
+ \dounderbar\betweenunderbarspaces}
+
+\def\dooverstrike#1%
+ {\bgroup
+ \dimen0=\@@ontopoffset
+ \dimen2=\dimen0
+ \advance\dimen2 \@@onrulethickness
+ \dododounderbar{\dimen2}{-\dimen0}{#1}%
+ \egroup}
+
+\def\betweenoverstrikewords
+ {\bgroup
+ \setbox0\hbox{\dooverstrike{\hskip\interwordspace}}%
+ \nobreak
+ \hskip\zeropoint\!!minus\interwordshrink
+ \discretionary{}{}{\box0}%
+ \egroup}
+
+\unexpanded\def\overstrike#1%
+ {\bgroup
+ \let\betweenisolatedwords\betweenoverstrikewords
+ \processisolatedwords{#1}\dooverstrike
+ \egroup}
+
+\unexpanded\def\overstrikes#1%
+ {\bgroup
+ \processisolatedwords{#1}\dooverstrike
+ \egroup}
+
+\def\underbarparameter#1{\csname\??on#1\csname}
+
+\def\setupunderbar
+ {\dodoubleargument\getparameters[\??on]}
+
+%D \macros
+%D {shiftedword, shiftedwords}
+%D
+%D Used as \type {\shiftedwords {10pt} {some text}} this macro will
+%D move
+
+% \def\shiftedword#1% #2%
+% {\raise#1\hbox} % {#2}} % officially: {\ifdim#1>\zeropoint\raise\else\lower\fi#1\hbox{#2}}
+
+% \def\shiftedwords#1#2%
+% {\processisolatedwords{#2}{\shiftedword{#1}}}
+
+%D \macros
+%D {low, high, lohi}
+%D
+%D Although \TEX\ is pretty well aware of super- and
+%D subscripts, its mechanism is mainly tuned for math mode.
+%D The next few commands take care of script texts both modes.
+%D
+%D \startbuffer
+%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}?
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D Note the different placement of \type {\lohi}, where we
+%D need a bit more space. The implementation looks a bit
+%D fuzzy, since some \type {\fontdimen}'s are involved to
+%D determine the optimal placement.
+
+\def\dodohighlow
+ {\ifx\fontsize\empty
+ \ifmmode
+ \ifnum\fam<0 \tx \else \holamathfont \fi
+ \else
+ \tx
+ \fi
+ \else
+ \tx
+ \fi}
+
+\def\dohighlow#1#2#3#4#5% todo, named fontdimens
+ {\dontleavehmode
+ \bgroup
+ \scratchdimen\ifdim\fontexheight\textfont2=1ex #2\textfont2\else #3ex\fi
+ \advance\scratchdimen #4ex
+ \kern.1ex
+ \setbox\scratchbox\hbox{#1\scratchdimen\hbox{\dodohighlow#5}}%
+ \ht\scratchbox\strutheight
+ \dp\scratchbox\strutdepth
+ \box\scratchbox
+ \egroup}
+
+\unexpanded\def\high{\dohighlow\raise\mathsupnormal{.86}{0}}
+\unexpanded\def\low {\dohighlow\lower\mathsubnormal{.48}{0}}
+
+% \unexpanded\def\lohi#1#2%
+% {\dontleavehmode
+% \hbox
+% {\setbox4=\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#1}}%
+% \setbox6=\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#2}}%
+% \ifdim\wd4<\wd6
+% \wd4=\zeropoint\box4\box6
+% \else
+% \wd6=\zeropoint\box6\box4
+% \fi}}
+
+\unexpanded\def\lohi
+ {\dosingleempty\dolohi}
+
+\def\dolohi[#1]#2#3%
+ {\dontleavehmode
+ \hbox
+ {\setbox4\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#2}}%
+ \setbox6\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#3}}%
+ \doif{#1}{\v!left}
+ {\ifdim\wd4<\wd6
+ \setbox4\hbox to \wd6{\hss\box4}%
+ \else
+ \setbox6\hbox to \wd4{\hss\box6}%
+ \fi}%
+ \ifdim\wd4<\wd6
+ \wd4=\zeropoint\box4\box6
+ \else
+ \wd6=\zeropoint\box6\box4
+ \fi}}
+
+%D You can provide an optional keyword \type {left}, in which
+%D case the super and subscripts will be aligned in a way that
+%D permits placement at the left of a word (which means that
+%D it will be right aligned).
+%D
+%D \startbuffer
+%D \lohi{aha}{ah} test \lohi{aha}{ah} test
+%D \lohi[left]{aha}{ah} test \lohi[left]{aha}{ah} test
+%D \lohi{aha}{ah} test\lohi{aha}{ah} test
+%D \lohi[left]{aha}{ah}test \lohi[left]{aha}{ah}test
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+
+%D \macros
+%D {setupinitial,placeinitial,checkinitial}
+%D
+%D {\em To be documented.}
+%D
+%D \starttyping
+%D \setupinitial[state=start] \placeinitial \input tufte
+%D \stoptyping
+%D
+%D and
+%D
+%D \starttyping
+%D \def\bpar{\ifvmode\checkinitial\fi}
+%D \def\epar{\ifhmode\par\fi\checkinitial}
+%D \stoptyping
+
+% to do: more fine tuning
+
+\def\setupinitial
+ {\dodoubleempty\getparameters[\??dc]}
+
+\definefontsynonym[Initial][Regular] % prefered initial identifier
+\definefontsynonym[initial][Initial] % internal but accepted too
+
+\setupinitial
+ [\c!state=\v!stop,
+ \c!location=\v!text,
+ \c!n=3,
+ \c!distance=.125em,
+ \c!command=,
+ \s!font=initial]
+
+\def\AutoDroppedCapsCommand{\NiceDroppedCaps\@@dccommand\@@dcfont\@@dcdistance\@@dcn}%
+
+\def\placeinitial
+ {\doifelse\@@dclocation\v!margin{\chardef\DropMode\plusone}{\chardef\DropMode\zerocount}%
+ \doif \@@dcstate\v!start{\ifcase\@@dcn\else\AutoDroppedCaps\fi}}
+
+\let\checkinitial\CheckDroppedCaps
+
+%D This module has only a few setups:
+
+\setupunderbar
+ [\c!alternative=a,
+ \c!rulethickness=\linewidth,
+ \c!bottomoffset=1.5pt,
+ \c!topoffset=2.5pt,
+ \c!rulecolor=]
+
+\protect \endinput
diff --git a/tex/context/base/core-fnt.mkiv b/tex/context/base/core-fnt.mkiv
new file mode 100644
index 000000000..323183712
--- /dev/null
+++ b/tex/context/base/core-fnt.mkiv
@@ -0,0 +1,498 @@
+%D \module
+%D [ file=core-fnt,
+%D version=1995.10.10,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Fonts,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Fonts}
+
+\unprotect
+
+%D \macros
+%D {compound}
+%D
+%D We will overload the already active \type {|} so we have
+%D to save its meaning in order to be able to use this handy
+%D macro.
+%D
+%D \starttyping
+%D so test\compound{}test can be used instead of test||test
+%D \stoptyping
+
+\bgroup \catcode`\|=\@@active \gdef\compound#1{|#1|} \egroup
+
+%D Here we hook some code into the clean up mechanism needed
+%D for verbatim data.
+
+\appendtoks
+ \disablecompoundcharacters
+ \disablediscretionaries
+\to \everycleanupfeatures
+
+%D \macros
+%D {stretched}
+%D
+%D Stretching characters in a word is a sort of typographical
+%D murder. Nevertheless we support this manipulation for use in
+%D for instance titles.
+%D
+%D \starttyping
+%D \hbox to 5cm{\stretched{murder}}
+%D \stoptyping
+%D
+%D \typebuffer
+%D
+%D or
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D \showsetup{stretched}
+
+\def\stretched#1%
+ {\ifvmode\hbox to \hsize\else\ifinner\else\hbox\fi\fi
+ \bgroup\processtokens\relax\hss\relax{\hss\hss}{#1}\egroup}
+
+%D \startbuffer
+%D \stretched{Unknown Box}
+%D \hbox to .5\hsize{\stretched{A Horizontal Box}}
+%D \vbox to 2cm{\stretched{A Vertical Box}}
+%D \hbox to 3cm{\stretched{sp{\'e}c{\`\i}{\"a}l}}
+%D \stopbuffer
+%D
+%D \getbuffer
+%D
+%D The first line of this macros takes care of boxing. Normally
+%D one will use an \type{\hbox} specification. The last line
+%D shows how special characters should be passed.
+%D
+%D \typebuffer
+
+%D \macros
+%D {stretchednormalcase, stretcheduppercase, stretchedlowercase}
+%D
+%D A convenient alternative is:
+%D
+%D \starttyping
+%D \stretcheduppercase{Is this what you like?}
+%D \stoptyping
+%D
+%D \typebuffer
+%D
+%D this one uses fixed skips and kerns.
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D The default skip can be set with:
+
+% \def\stretchedspacefactor{4}
+% \def\stretchedspaceamount{.25em}
+%
+% \unexpanded\def\stretcheduppercase#1%
+% {\bgroup
+% \the\everyuppercase
+% \uppercase{\def\textstring{#1}}%
+% \ifdim\stretchedspaceamount>\zeropoint
+% \def\textkern%
+% {\kern\stretchedspaceamount}%
+% \def\textskip%
+% {\scratchdimen=\stretchedspaceamount
+% \hskip\stretchedspacefactor\scratchdimen}%
+% \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
+% \textskip\@EA{\textstring}%
+% \else
+% \textstring
+% \fi
+% \egroup}
+
+%D Given the following settings, the space is 1em by default:
+
+\def\stretchedspacefactor{4}
+\def\stretchedspaceamount{.25em}
+\def\stretchedbreaktokens{.@/}
+
+\unexpanded\def\stretchednormalcase
+ {\stretchedsomecase\firstofoneargument}
+
+\unexpanded\def\stretcheduppercase
+ {\stretchedsomecase{\the\everyuppercase\uppercase}}
+
+\unexpanded\def\stretchedlowercase
+ {\stretchedsomecase{\the\everylowercase\lowercase}}
+
+\def\stretchedsomecase#1#2%
+ {\bgroup
+ #1{\def\textstring{#2}}%
+ \ifdim\stretchedspaceamount=\zeropoint
+ \textstring
+ \else
+ \def\textkern##1%
+ {% beware: ##1 may not be \box\somebox -)
+ \determinemidwordbreak{##1}{\stretchedbreaktokens}%
+ \kern\stretchedspaceamount##1\domidwordbreak}%
+ \def\textskip
+ {\scratchdimen\stretchedspaceamount
+ \hskip\stretchedspacefactor\scratchdimen}%
+ \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
+ \textskip\@EA{\textstring}%
+ \fi
+ \egroup}
+
+%D An auxiliary macro, see for usage \type {\stretcheduppercase}.
+
+\let\domidwordbreak\relax
+
+\def\setmidwordbreaktoken#1%
+ {\sfcode`#1=5000\relax}
+
+\def\determinemidwordbreak#1#2%
+ {\edef\midwordbreaktokens{#2}%
+ \ifx\midwordbreaktokens\empty
+ \global\let\domidwordbreak\relax
+ \else
+ \setbox\scratchbox\hbox
+ {\expandafter\handletokens\midwordbreaktokens\with\setmidwordbreaktoken
+ a\space \!!dimena\lastskip
+ #1\space\!!dimenb\lastskip \relax % needed
+ \ifdim\!!dimena=\!!dimenb
+ \globallet\domidwordbreak\relax
+ \else
+ \globallet\domidwordbreak\allowbreak
+ \fi}%
+ \fi}
+
+%D \macros
+%D {underbar,underbars,
+%D overbar,overbars,
+%D overstrike,overstrikes,
+%D setupunderbar}
+%D
+%D In the rare case that we need undelined words, for instance
+%D because all font alternatives are already in use, one can
+%D use \type{\underbar} and \type{\overstrike} and their plural
+%D forms.
+%D
+%D \startbuffer
+%D \underbars{drawing \underbar{bars} under words is a typewriter leftover}
+%D \overstrikes{striking words makes them \overstrike{unreadable} but
+%D sometimes even \overbar{top lines} come into view.}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D The next macros are derived from the \PLAIN\ \TEX\ one, but
+%D also supports nesting. The \type{$} keeps us in horizontal
+%D mode and at the same time applies grouping.
+%D
+%D \showsetup{underbar}
+%D \showsetup{underbars}
+%D \showsetup{overbar}
+%D \showsetup{overbars}
+%D \showsetup{overstrike}
+%D \showsetup{overstrikes}
+%D
+%D Although underlining is ill advised, we permit some
+%D alternatives, that can be set up by:
+%D
+%D \showsetup{setupunderbar}
+%D
+%D The alternatives show up as
+%D {\setupunderbar [alternative=a]\underbar{alternative a}},
+%D {\setupunderbar [alternative=b]\underbar{alternative b}},
+%D {\setupunderbar [alternative=c]\underbar{alternative c}}
+%D and
+%D {\setupunderbar [rulethickness=1pt]\underbar{1pt width}},
+%D {\setupunderbar [rulethickness=2pt]\underbar{2pt width}},
+%D or whatever. Because \type{\overstrike} uses the same
+%D method, the settings also apply to that macro.
+
+\newcount\underbarlevel
+
+\def\underbarmethoda#1#2#3% RULE
+ {\hbox to #1{\vrule\!!width#1\!!height#2\!!depth#3}}
+
+\def\underbarmethodb#1#2#3% DASH
+ {\hbox to #1
+ {\hskip-.25em
+ \xleaders
+ \hbox{\hskip.25em\vrule\!!width.25em\!!height#2\!!depth#3}
+ \hfil}}
+
+\def\underbarmethodc#1#2#3% PERIOD
+ {\hbox to #1
+ {\dimen4=#3
+ \advance\dimen4 .2ex
+ \hskip-.25em
+ \xleaders
+ \hbox{\hskip.25em\lower\dimen4\hbox{.}}
+ \hfil}}
+
+\def\dododounderbar#1#2#3%
+ {\startmathmode
+ \setbox0\hbox{#3}%
+ \setbox2\hbox{\color[\@@onrulecolor]{\getvalue{underbarmethod\@@onalternative}{\wd0}{#1}{#2}}}%
+ \wd0\zeropoint
+ \ht2\ht0
+ \dp2\dp0
+ \box0\box2
+ \stopmathmode}
+
+\unexpanded\def\dodounderbar#1%
+ {\bgroup
+ \dimen0=\@@onbottomoffset
+ \dimen0=\underbarlevel\dimen0
+ \ifdone \else
+ \advance\dimen0 -\strutht
+ \fi
+ \dimen2\dimen0
+ \advance\dimen2 \@@onrulethickness
+ \dododounderbar{-\dimen0}{\dimen2}{#1}%
+ \egroup}
+
+\def\betweenunderbarwords
+ {\bgroup
+ \setbox0\hbox{\dodounderbar{\hskip\interwordspace}}%
+ \nobreak
+ \hskip\zeropoint\!!minus\interwordshrink
+ \discretionary{}{}{\box0}%
+ \egroup}
+
+\def\betweenunderbarspaces
+ {\hskip\currentspaceskip}
+
+% \unexpanded\def\dounderbar#1#2%
+% {\let\betweenisolatedwords#1%
+% \processisolatedwords{#2}\dodounderbar
+% \egroup}
+
+\unexpanded\def\underbar
+ {\bgroup
+ \advance\underbarlevel\plusone
+ \donetrue
+ \dounderbar\betweenunderbarwords}
+
+\unexpanded\def\dounderbar#1%
+ {\let\betweenisolatedwords#1%
+ \dosingleempty\redounderbar}
+
+\unexpanded\def\redounderbar[#1]#2%
+ {\iffirstargument\setupunderbar[#1]\fi
+ \processisolatedwords{#2}\dodounderbar
+ \egroup}
+
+\unexpanded\def\underbars
+ {\bgroup
+ \advance\underbarlevel\plusone
+ \donetrue
+ \dounderbar\betweenunderbarspaces}
+
+\unexpanded\def\overbar
+ {\bgroup
+ \advance\underbarlevel\minusone
+ \donefalse
+ \dounderbar\betweenunderbarwords}
+
+\unexpanded\def\overbars
+ {\bgroup
+ \advance\underbarlevel\minusone
+ \donefalse
+ \dounderbar\betweenunderbarspaces}
+
+\def\dooverstrike#1%
+ {\bgroup
+ \dimen0=\@@ontopoffset
+ \dimen2=\dimen0
+ \advance\dimen2 \@@onrulethickness
+ \dododounderbar{\dimen2}{-\dimen0}{#1}%
+ \egroup}
+
+\def\betweenoverstrikewords
+ {\bgroup
+ \setbox0\hbox{\dooverstrike{\hskip\interwordspace}}%
+ \nobreak
+ \hskip\zeropoint\!!minus\interwordshrink
+ \discretionary{}{}{\box0}%
+ \egroup}
+
+\unexpanded\def\overstrike#1%
+ {\bgroup
+ \let\betweenisolatedwords\betweenoverstrikewords
+ \processisolatedwords{#1}\dooverstrike
+ \egroup}
+
+\unexpanded\def\overstrikes#1%
+ {\bgroup
+ \processisolatedwords{#1}\dooverstrike
+ \egroup}
+
+\def\underbarparameter#1{\csname\??on#1\csname}
+
+\def\setupunderbar
+ {\dodoubleargument\getparameters[\??on]}
+
+%D \macros
+%D {shiftedword, shiftedwords}
+%D
+%D Used as \type {\shiftedwords {10pt} {some text}} this macro will
+%D move
+
+% \def\shiftedword#1% #2%
+% {\raise#1\hbox} % {#2}} % officially: {\ifdim#1>\zeropoint\raise\else\lower\fi#1\hbox{#2}}
+
+% \def\shiftedwords#1#2%
+% {\processisolatedwords{#2}{\shiftedword{#1}}}
+
+%D \macros
+%D {low, high, lohi, hilo}
+%D
+%D Although \TEX\ is pretty well aware of super- and
+%D subscripts, its mechanism is mainly tuned for math mode.
+%D The next few commands take care of script texts both modes.
+%D
+%D \startbuffer
+%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}?
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D Note the different placement of \type {\lohi}, where we
+%D need a bit more space. The implementation looks a bit
+%D fuzzy, since some \type {\fontdimen}'s are involved to
+%D determine the optimal placement.
+
+\def\dodohighlow
+ {\ifx\fontsize\empty
+ \ifmmode
+ \ifnum\fam<0 \tx \else \holamathfont \fi
+ \else
+ \tx
+ \fi
+ \else
+ \tx
+ \fi}
+
+\def\dohighlow#1#2#3#4#5% todo, named fontdimens
+ {\dontleavehmode
+ \bgroup
+ \scratchdimen\ifdim\fontexheight\textfont2=1ex #2\textfont2\else #3ex\fi
+ \advance\scratchdimen #4ex
+ \kern.1ex
+ \setbox\scratchbox\hbox{#1\scratchdimen\hbox{\dodohighlow#5}}%
+ \ht\scratchbox\strutheight
+ \dp\scratchbox\strutdepth
+ \box\scratchbox
+ \egroup}
+
+\unexpanded\def\high{\dohighlow\raise\mathsupnormal{.86}{0}}
+\unexpanded\def\low {\dohighlow\lower\mathsubnormal{.48}{0}}
+
+\unexpanded\def\lohi
+ {\dosingleempty\dolohi}
+
+\unexpanded\def\hilo
+ {\dosingleempty\dohilo}
+
+\def\dolohi[#1]#2#3%
+ {\dontleavehmode
+ \hbox
+ {\setbox4\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#2}}%
+ \setbox6\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#3}}%
+ \doif{#1}{\v!left}
+ {\ifdim\wd4<\wd6
+ \setbox4\hbox to \wd6{\hss\box4}%
+ \else
+ \setbox6\hbox to \wd4{\hss\box6}%
+ \fi}%
+ \ifdim\wd4<\wd6
+ \wd4=\zeropoint\box4\box6
+ \else
+ \wd6=\zeropoint\box6\box4
+ \fi}}
+
+\def\dohilo[#1]#2#3%
+ {\dolohi[#1]{#3}{#2}}
+
+%D You can provide an optional keyword \type {left}, in which
+%D case the super and subscripts will be aligned in a way that
+%D permits placement at the left of a word (which means that
+%D it will be right aligned).
+%D
+%D \startbuffer
+%D \lohi{aha}{ah} test \lohi{aha}{ah} test
+%D \lohi[left]{aha}{ah} test \lohi[left]{aha}{ah} test
+%D \lohi{aha}{ah} test\lohi{aha}{ah} test
+%D \lohi[left]{aha}{ah}test \lohi[left]{aha}{ah}test
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+
+%D \macros
+%D {setupinitial,placeinitial,checkinitial}
+%D
+%D {\em To be documented.}
+%D
+%D \starttyping
+%D \setupinitial[state=start] \placeinitial \input tufte
+%D \stoptyping
+%D
+%D and
+%D
+%D \starttyping
+%D \def\bpar{\ifvmode\checkinitial\fi}
+%D \def\epar{\ifhmode\par\fi\checkinitial}
+%D \stoptyping
+
+% to do: more fine tuning
+
+\def\setupinitial
+ {\dodoubleempty\getparameters[\??dc]}
+
+\definefontsynonym[Initial][Regular] % prefered initial identifier
+\definefontsynonym[initial][Initial] % internal but accepted too
+
+\setupinitial
+ [\c!state=\v!stop,
+ \c!location=\v!text,
+ \c!n=3,
+ \c!distance=.125em,
+ \c!command=,
+ \s!font=initial]
+
+\def\AutoDroppedCapsCommand{\NiceDroppedCaps\@@dccommand\@@dcfont\@@dcdistance\@@dcn}%
+
+\def\placeinitial
+ {\doifelse\@@dclocation\v!margin{\chardef\DropMode\plusone}{\chardef\DropMode\zerocount}%
+ \doif \@@dcstate\v!start{\ifcase\@@dcn\else\AutoDroppedCaps\fi}}
+
+\let\checkinitial\CheckDroppedCaps
+
+%D This module has only a few setups:
+
+\setupunderbar
+ [\c!alternative=a,
+ \c!rulethickness=\linewidth,
+ \c!bottomoffset=1.5pt,
+ \c!topoffset=2.5pt,
+ \c!rulecolor=]
+
+\protect \endinput
diff --git a/tex/context/base/core-fnt.tex b/tex/context/base/core-fnt.tex
deleted file mode 100644
index e6f7fada4..000000000
--- a/tex/context/base/core-fnt.tex
+++ /dev/null
@@ -1,726 +0,0 @@
-%D \module
-%D [ file=core-fnt,
-%D version=1995.10.10,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Font Support,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Font Support}
-
-\unprotect
-
-%D \macros
-%D {compound}
-%D
-%D We will overload the already active \type {|} so we have
-%D to save its meaning in order to be able to use this handy
-%D macro.
-%D
-%D \starttyping
-%D so test\compound{}test can be used instead of test||test
-%D \stoptyping
-
-\bgroup \catcode`\|=\@@active \gdef\compound#1{|#1|} \egroup
-
-%D Here we hook some code into the clean up mechanism needed
-%D for verbatim data.
-
-\appendtoks
- \disablecompoundcharacters
- \disablediscretionaries
-\to \everycleanupfeatures
-
-%D \macros
-%D {kap,KAP,Kap,Kaps,nokap,userealcaps,usepseudocaps}
-%D
-%D We already introduced \type{\cap} as way to capitalize
-%D words. This command comes in several versions:
-%D
-%D \startbuffer
-%D \cap {let's put on a \cap{cap}}
-%D \cap {let's put on a \nocap{cap}}
-%D \CAP {let's put on a \\{cap}}
-%D \Cap {let's put on a \\{cap}}
-%D \Caps{let's put on a cap}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Note the use of \type{\nocap}, \type{\\} and the nested
-%D \type{\cap}.
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D These macros show te main reason why we introduced the
-%D smaller \type{\tx} and \type{\txx}.
-%D
-%D \starttyping
-%D \cap\romannumerals{1995}
-%D \stoptyping
-%D
-%D This at first sight unusual capitilization is completely
-%D legal.
-%D
-%D \showsetup{smallcapped}
-%D \showsetup{notsmallcapped}
-%D \showsetup{CAPPED}
-%D \showsetup{SmallCapped}
-%D \showsetup{SmallCaps}
-%D
-%D The difference between pseudo and real caps is demonstrated
-%D below:
-%D
-%D \startbuffer
-%D \usepseudocaps \cap{Hans Hagen}
-%D \userealcaps \cap{Hans Hagen}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D The \type {\bgroup} trickery below is needed because of
-%D \type {\groupedcommand}.
-
-\def\usepseudocaps
- {\def\cap@@uppercase{\the\everyuppercase\uppercased}%
- \def\cap@@lowercase{\the\everylowercase\lowercased}%
- \def\cap@@visualize{\tx}}
-
-\def\userealcaps
- {\let\cap@@uppercase\relax
- %\let\cap@@lowercase\relax % Definitely not!
- \def\cap@@visualize{\sc}}
-
-\usepseudocaps
-
-\unexpanded\def\smallcapped % else conflict with math
- {\futurelet\next\dosmallcapped}
-
-\def\disablepseudocaps
- {\let\smallcapped\donothing}
-
-\def\dosmallcapped
- {\ifx\next\bgroup
- \expandafter\dodosmallcapped\expandafter\relax
- \else
- \expandafter\dodosmallcapped
- \fi}
-
-\def\dodosmallcapped#1#2%
- {\ifmmode\hbox\fi
- \bgroup
- \cap@@visualize
- \cap@@uppercase{#1{#2}}%
- \egroup}
-
-\unexpanded\def\notsmallcapped#1%
- {\cap@@lowercase{#1}}
-
-\unexpanded\def\CAPPED#1%
- {{\def\\##1{\smallcapped{##1}}#1}}
-
-\unexpanded\def\SmallCapped#1%
- {\CAPPED{\\#1}}
-
-\unexpanded\def\SmallCaps
- {\let\processword\SmallCapped
- \processwords}
-
-%D Sure:
-
-\def\kap{\smallcapped} % for old times sake
-
-%D Some precautions for a \PLAIN\ \TEX\ definition.
-
-\unexpanded\def\normalcap{\dohandlemathtoken{cap}}
-\unexpanded\def\normalCap{\dohandlemathtoken{Cap}}
-
-\def\cap{\mathortext\normalcap\smallcapped}
-\def\Cap{\mathortext\normalCap\SmallCapped}
-
-\appendtoks
- \let\cap\firstofoneargument
- \let\Cap\firstofoneargument
-\to \simplifiedcommands
-
-%D \macros
-%D {setupcapitals}
-%D
-%D By default we use pseudo small caps in titles. This can be
-%D set up with:
-%D
-%D \showsetup{setupcapitals}
-
-\let\normalsmallcapped\smallcapped
-
-\def\setupcapitals
- {\dosingleempty\dosetupcapitals}
-
-\def\dosetupcapitals[#1]%
- {\getparameters[\??kk][#1]%
- \doifelse\@@kktitle\v!yes
- {\definealternativestyle[\v!capital][\normalsmallcapped][\normalsmallcapped]%
- \definealternativestyle[\v!smallcaps][\sc][\sc]%
- \unexpanded\def\smallcapped{\normalsmallcapped}}
- {\definealternativestyle[\v!capital][\normalsmallcapped][\uppercased]%
- \definealternativestyle[\v!smallcaps][\sc][\uppercased]%
- \unexpanded\def\smallcapped{\doconvertfont\v!capital}}%
- \doifelse\@@kksc\v!yes
- \userealcaps
- \usepseudocaps}
-
-\ifx\uppercased\undefined \let\uppercased\uppercase \fi
-\ifx\lowercased\undefined \let\lowercased\lowercase \fi
-
-% pretty tricky stuff:
-%
-% \usemodule[abr-01] \TEX \METAPOST \PPCHTEX \LATEX
-% \usemodule[abr-02] \TEX \METAPOST \PPCHTEX \LATEX
-
-%def\uppercased#1{{\forceunexpanded\xdef\@@globalcrap{\uppercase{#1}}}\@@globalcrap}
-%def\lowercased#1{{\forceunexpanded\xdef\@@globalcrap{\lowercase{#1}}}\@@globalcrap}
-
-\def\uppercased#1{{\forceunexpanded\xdef\@@expanded{\uppercase{#1}}}\@@expanded}
-\def\lowercased#1{{\forceunexpanded\xdef\@@expanded{\lowercase{#1}}}\@@expanded}
-
-\setupcapitals
- [\c!title=\v!yes,
- \c!sc=\v!no]
-
-%D \macros
-%D {Word, Words, WORD, WORDS, doprocesswords}
-%D
-%D This is probably not the right place to present the next set
-%D of macros.
-%D
-%D \starttyping
-%D \Word {far too many words}
-%D \Words{far too many words}
-%D \WORD {far too many words}
-%D \WORDS{far too many words}
-%D \stoptyping
-%D
-%D \typebuffer
-%D
-%D This calls result in:
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D \showsetup{Word}
-%D \showsetup{Words}
-%D \showsetup{WORD}
-%D \showsetup{WORDS}
-
-\def\doWord#1%
- {\bgroup
- \the\everyuppercase
- \uppercase{#1}%
- \egroup}
-
-\unexpanded\def\Word#1%
- {\doWord#1}
-
-\def\doprocesswords#1 #2\od
- {\ConvertToConstant\doifnot{#1}{}
- {\processword{#1} %
- \doprocesswords#2 \od}}
-
-\def\processwords#1%
- {\doprocesswords#1 \od\unskip}
-
-\let\processword\relax
-
-\unexpanded\def\Words
- {\let\processword\Word
- \processwords}
-
-\unexpanded\def\WORD#1%
- {\bgroup
- \let\smallcapped\firstofoneargument
- \let\WORD\firstofoneargument
- \douppercase{#1}%
- \egroup}
-
-\unexpanded\def\WORDS#1%
- {\WORD{#1}}
-
-%D \macros
-%D {stretched}
-%D
-%D Stretching characters in a word is a sort of typographical
-%D murder. Nevertheless we support this manipulation for use in
-%D for instance titles.
-%D
-%D \starttyping
-%D \hbox to 5cm{\stretched{murder}}
-%D \stoptyping
-%D
-%D \typebuffer
-%D
-%D or
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-%D
-%D \showsetup{stretched}
-
-\def\stretched#1%
- {\ifvmode\hbox to \hsize\else\ifinner\else\hbox\fi\fi
- \bgroup\processtokens\relax\hss\relax{\hss\hss}{#1}\egroup}
-
-%D \startbuffer
-%D \stretched{Unknown Box}
-%D \hbox to .5\hsize{\stretched{A Horizontal Box}}
-%D \vbox to 2cm{\stretched{A Vertical Box}}
-%D \hbox to 3cm{\stretched{sp{\'e}c{\`\i}{\"a}l}}
-%D \stopbuffer
-%D
-%D \getbuffer
-%D
-%D The first line of this macros takes care of boxing. Normally
-%D one will use an \type{\hbox} specification. The last line
-%D shows how special characters should be passed.
-%D
-%D \typebuffer
-
-%D \macros
-%D {stretchednormalcase, stretcheduppercase, stretchedlowercase}
-%D
-%D A convenient alternative is:
-%D
-%D \starttyping
-%D \stretcheduppercase{Is this what you like?}
-%D \stoptyping
-%D
-%D \typebuffer
-%D
-%D this one uses fixed skips and kerns.
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-%D
-%D The default skip can be set with:
-
-% \def\stretchedspacefactor{4}
-% \def\stretchedspaceamount{.25em}
-%
-% \unexpanded\def\stretcheduppercase#1%
-% {\bgroup
-% \the\everyuppercase
-% \uppercase{\def\textstring{#1}}%
-% \ifdim\stretchedspaceamount>\zeropoint
-% \def\textkern%
-% {\kern\stretchedspaceamount}%
-% \def\textskip%
-% {\scratchdimen=\stretchedspaceamount
-% \hskip\stretchedspacefactor\scratchdimen}%
-% \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
-% \textskip\@EA{\textstring}%
-% \else
-% \textstring
-% \fi
-% \egroup}
-
-%D Given the following settings, the space is 1em by default:
-
-\def\stretchedspacefactor{4}
-\def\stretchedspaceamount{.25em}
-\def\stretchedbreaktokens{.@/}
-
-\unexpanded\def\stretchednormalcase
- {\stretchedsomecase\firstofoneargument}
-
-\unexpanded\def\stretcheduppercase
- {\stretchedsomecase{\the\everyuppercase\uppercase}}
-
-\unexpanded\def\stretchedlowercase
- {\stretchedsomecase{\the\everylowercase\lowercase}}
-
-\def\stretchedsomecase#1#2%
- {\bgroup
- #1{\def\textstring{#2}}%
- \ifdim\stretchedspaceamount=\zeropoint
- \textstring
- \else
- \def\textkern##1%
- {% beware: ##1 may not be \box\somebox -)
- \determinemidwordbreak{##1}{\stretchedbreaktokens}%
- \kern\stretchedspaceamount##1\domidwordbreak}%
- \def\textskip
- {\scratchdimen\stretchedspaceamount
- \hskip\stretchedspacefactor\scratchdimen}%
- \@EA\processtokens\@EA\relax\@EA\textkern\@EA\relax\@EA
- \textskip\@EA{\textstring}%
- \fi
- \egroup}
-
-%D An auxiliary macro, see for usage \type {\stretcheduppercase}.
-
-\let\domidwordbreak\relax
-
-\def\setmidwordbreaktoken#1%
- {\sfcode`#1=5000\relax}
-
-\def\determinemidwordbreak#1#2%
- {\edef\midwordbreaktokens{#2}%
- \ifx\midwordbreaktokens\empty
- \global\let\domidwordbreak\relax
- \else
- \setbox\scratchbox\hbox
- {\expandafter\handletokens\midwordbreaktokens\with\setmidwordbreaktoken
- a\space \!!dimena\lastskip
- #1\space\!!dimenb\lastskip \relax % needed
- \ifdim\!!dimena=\!!dimenb
- \globallet\domidwordbreak\relax
- \else
- \globallet\domidwordbreak\allowbreak
- \fi}%
- \fi}
-
-%D \macros
-%D {underbar,underbars,
-%D overbar,overbars,
-%D overstrike,overstrikes,
-%D setupunderbar}
-%D
-%D In the rare case that we need undelined words, for instance
-%D because all font alternatives are already in use, one can
-%D use \type{\underbar} and \type{\overstrike} and their plural
-%D forms.
-%D
-%D \startbuffer
-%D \underbars{drawing \underbar{bars} under words is a typewriter leftover}
-%D \overstrikes{striking words makes them \overstrike{unreadable} but
-%D sometimes even \overbar{top lines} come into view.}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D The next macros are derived from the \PLAIN\ \TEX\ one, but
-%D also supports nesting. The \type{$} keeps us in horizontal
-%D mode and at the same time applies grouping.
-%D
-%D \showsetup{underbar}
-%D \showsetup{underbars}
-%D \showsetup{overbar}
-%D \showsetup{overbars}
-%D \showsetup{overstrike}
-%D \showsetup{overstrikes}
-%D
-%D Although underlining is ill advised, we permit some
-%D alternatives, that can be set up by:
-%D
-%D \showsetup{setupunderbar}
-%D
-%D The alternatives show up as
-%D {\setupunderbar [alternative=a]\underbar{alternative a}},
-%D {\setupunderbar [alternative=b]\underbar{alternative b}},
-%D {\setupunderbar [alternative=c]\underbar{alternative c}}
-%D and
-%D {\setupunderbar [rulethickness=1pt]\underbar{1pt width}},
-%D {\setupunderbar [rulethickness=2pt]\underbar{2pt width}},
-%D or whatever. Because \type{\overstrike} uses the same
-%D method, the settings also apply to that macro.
-
-\newcount\underbarlevel
-
-\def\underbarmethoda#1#2#3% RULE
- {\hbox to #1{\vrule\!!width#1\!!height#2\!!depth#3}}
-
-\def\underbarmethodb#1#2#3% DASH
- {\hbox to #1
- {\hskip-.25em
- \xleaders
- \hbox{\hskip.25em\vrule\!!width.25em\!!height#2\!!depth#3}
- \hfil}}
-
-\def\underbarmethodc#1#2#3% PERIOD
- {\hbox to #1
- {\dimen4=#3
- \advance\dimen4 .2ex
- \hskip-.25em
- \xleaders
- \hbox{\hskip.25em\lower\dimen4\hbox{.}}
- \hfil}}
-
-\def\dododounderbar#1#2#3%
- {\startmathmode
- \setbox0\hbox{#3}%
- \setbox2\hbox{\color[\@@onrulecolor]{\getvalue{underbarmethod\@@onalternative}{\wd0}{#1}{#2}}}%
- \wd0\zeropoint
- \ht2\ht0
- \dp2\dp0
- \box0\box2
- \stopmathmode}
-
-\unexpanded\def\dodounderbar#1%
- {\bgroup
- \dimen0=\@@onbottomoffset
- \dimen0=\underbarlevel\dimen0
- \ifdone \else
- \advance\dimen0 -\strutht
- \fi
- \dimen2\dimen0
- \advance\dimen2 \@@onrulethickness
- \dododounderbar{-\dimen0}{\dimen2}{#1}%
- \egroup}
-
-\def\betweenunderbarwords
- {\bgroup
- \setbox0\hbox{\dodounderbar{\hskip\interwordspace}}%
- \nobreak
- \hskip\zeropoint\!!minus\interwordshrink
- \discretionary{}{}{\box0}%
- \egroup}
-
-\def\betweenunderbarspaces
- {\hskip\currentspaceskip}
-
-% \unexpanded\def\dounderbar#1#2%
-% {\let\betweenisolatedwords#1%
-% \processisolatedwords{#2}\dodounderbar
-% \egroup}
-
-\unexpanded\def\underbar
- {\bgroup
- \advance\underbarlevel\plusone
- \donetrue
- \dounderbar\betweenunderbarwords}
-
-\unexpanded\def\dounderbar#1%
- {\let\betweenisolatedwords#1%
- \dosingleempty\redounderbar}
-
-\unexpanded\def\redounderbar[#1]#2%
- {\iffirstargument\setupunderbar[#1]\fi
- \processisolatedwords{#2}\dodounderbar
- \egroup}
-
-\unexpanded\def\underbars
- {\bgroup
- \advance\underbarlevel\plusone
- \donetrue
- \dounderbar\betweenunderbarspaces}
-
-\unexpanded\def\overbar
- {\bgroup
- \advance\underbarlevel\minusone
- \donefalse
- \dounderbar\betweenunderbarwords}
-
-\unexpanded\def\overbars
- {\bgroup
- \advance\underbarlevel\minusone
- \donefalse
- \dounderbar\betweenunderbarspaces}
-
-\def\dooverstrike#1%
- {\bgroup
- \dimen0=\@@ontopoffset
- \dimen2=\dimen0
- \advance\dimen2 \@@onrulethickness
- \dododounderbar{\dimen2}{-\dimen0}{#1}%
- \egroup}
-
-\def\betweenoverstrikewords
- {\bgroup
- \setbox0\hbox{\dooverstrike{\hskip\interwordspace}}%
- \nobreak
- \hskip\zeropoint\!!minus\interwordshrink
- \discretionary{}{}{\box0}%
- \egroup}
-
-\unexpanded\def\overstrike#1%
- {\bgroup
- \let\betweenisolatedwords\betweenoverstrikewords
- \processisolatedwords{#1}\dooverstrike
- \egroup}
-
-\unexpanded\def\overstrikes#1%
- {\bgroup
- \processisolatedwords{#1}\dooverstrike
- \egroup}
-
-\def\underbarparameter#1{\csname\??on#1\csname}
-
-\def\setupunderbar
- {\dodoubleargument\getparameters[\??on]}
-
-%D \macros
-%D {shiftedword, shiftedwords}
-%D
-%D Used as \type {\shiftedwords {10pt} {some text}} this macro will
-%D move
-
-% \def\shiftedword#1% #2%
-% {\raise#1\hbox} % {#2}} % officially: {\ifdim#1>\zeropoint\raise\else\lower\fi#1\hbox{#2}}
-
-% \def\shiftedwords#1#2%
-% {\processisolatedwords{#2}{\shiftedword{#1}}}
-
-%D \macros
-%D {low, high, lohi}
-%D
-%D Although \TEX\ is pretty well aware of super- and
-%D subscripts, its mechanism is mainly tuned for math mode.
-%D The next few commands take care of script texts both modes.
-%D
-%D \startbuffer
-%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}?
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D Note the different placement of \type {\lohi}, where we
-%D need a bit more space. The implementation looks a bit
-%D fuzzy, since some \type {\fontdimen}'s are involved to
-%D determine the optimal placement.
-
-\def\dodohighlow
- {\ifx\fontsize\empty
- \ifmmode
- \ifnum\fam<0 \tx \else \holamathfont \fi
- \else
- \tx
- \fi
- \else
- \tx
- \fi}
-
-\def\dohighlow#1#2#3#4#5% todo, named fontdimens
- {\dontleavehmode
- \bgroup
- \scratchdimen\ifdim\fontexheight\textfont2=1ex #2\textfont2\else #3ex\fi
- \advance\scratchdimen #4ex
- \kern.1ex
- \setbox\scratchbox\hbox{#1\scratchdimen\hbox{\dodohighlow#5}}%
- \ht\scratchbox\strutheight
- \dp\scratchbox\strutdepth
- \box\scratchbox
- \egroup}
-
-\unexpanded\def\high{\dohighlow\raise\mathsupnormal{.86}{0}}
-\unexpanded\def\low {\dohighlow\lower\mathsubnormal{.48}{0}}
-
-% \unexpanded\def\lohi#1#2%
-% {\dontleavehmode
-% \hbox
-% {\setbox4=\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#1}}%
-% \setbox6=\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#2}}%
-% \ifdim\wd4<\wd6
-% \wd4=\zeropoint\box4\box6
-% \else
-% \wd6=\zeropoint\box6\box4
-% \fi}}
-
-\unexpanded\def\lohi
- {\dosingleempty\dolohi}
-
-\def\dolohi[#1]#2#3%
- {\dontleavehmode
- \hbox
- {\setbox4\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#2}}%
- \setbox6\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#3}}%
- \doif{#1}{\v!left}
- {\ifdim\wd4<\wd6
- \setbox4\hbox to \wd6{\hss\box4}%
- \else
- \setbox6\hbox to \wd4{\hss\box6}%
- \fi}%
- \ifdim\wd4<\wd6
- \wd4=\zeropoint\box4\box6
- \else
- \wd6=\zeropoint\box6\box4
- \fi}}
-
-%D You can provide an optional keyword \type {left}, in which
-%D case the super and subscripts will be aligned in a way that
-%D permits placement at the left of a word (which means that
-%D it will be right aligned).
-%D
-%D \startbuffer
-%D \lohi{aha}{ah} test \lohi{aha}{ah} test
-%D \lohi[left]{aha}{ah} test \lohi[left]{aha}{ah} test
-%D \lohi{aha}{ah} test\lohi{aha}{ah} test
-%D \lohi[left]{aha}{ah}test \lohi[left]{aha}{ah}test
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-
-%D \macros
-%D {setupinitial,placeinitial,checkinitial}
-%D
-%D {\em To be documented.}
-%D
-%D \starttyping
-%D \setupinitial[state=start] \placeinitial \input tufte
-%D \stoptyping
-%D
-%D and
-%D
-%D \starttyping
-%D \def\bpar{\ifvmode\checkinitial\fi}
-%D \def\epar{\ifhmode\par\fi\checkinitial}
-%D \stoptyping
-
-% to do: more fine tuning
-
-\def\setupinitial
- {\dodoubleempty\getparameters[\??dc]}
-
-\definefontsynonym[Initial][Regular] % prefered initial identifier
-\definefontsynonym[initial][Initial] % internal but accepted too
-
-\setupinitial
- [\c!state=\v!stop,
- \c!location=\v!text,
- \c!n=3,
- \c!distance=.125em,
- \c!command=,
- \s!font=initial]
-
-\def\AutoDroppedCapsCommand{\NiceDroppedCaps\@@dccommand\@@dcfont\@@dcdistance\@@dcn}%
-
-\def\placeinitial
- {\doifelse\@@dclocation\v!margin{\chardef\DropMode\plusone}{\chardef\DropMode\zerocount}%
- \doif \@@dcstate\v!start{\ifcase\@@dcn\else\AutoDroppedCaps\fi}}
-
-\let\checkinitial\CheckDroppedCaps
-
-%D This module has only a few setups:
-
-\setupunderbar
- [\c!alternative=a,
- \c!rulethickness=\linewidth,
- \c!bottomoffset=1.5pt,
- \c!topoffset=2.5pt,
- \c!rulecolor=]
-
-\protect \endinput
diff --git a/tex/context/base/core-gen.tex b/tex/context/base/core-gen.tex
index aaaba84d1..b6ab2a208 100644
--- a/tex/context/base/core-gen.tex
+++ b/tex/context/base/core-gen.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / General}
+\writestatus{loading}{ConTeXt Core Macros / General}
\unprotect
@@ -60,79 +60,38 @@
%D {waarde groot}
%D \stoptyping
-\def\assigndimension#1#2#3#4#5% can be a skip
- {\processaction
- [#1]
- [ \v!small=>#2=#3\relax,
- \v!medium=>#2=#4\relax,
- \v!big=>#2=#5\relax,
- \v!none=>#2=\zeropoint,
- -\v!small=>#2=-#3\relax,
- -\v!medium=>#2=-#4\relax,
- -\v!big=>#2=-#5\relax,
- \s!unknown=>#2=#1\relax]}
-
-\def\assignalfadimension#1#2#3#4#5%
- {\processaction
- [#1]
- [ \v!small=>\edef#2{#3},
- \v!medium=>\edef#2{#4},
- \v!big=>\edef#2{#5},
- \v!none=>\edef#2{0},
- \s!unknown=>\edef#2{#1}]}
-
-%D De onderstaande implementatie is veel sneller, maar
-%D tegelijkertijd ook veel lelijker. Omdat we deze macro
-%D relatief weinig aanroepen laten we deze optimalisatie maar
-%D achterwege. Bovendien kunnen oplossingen als deze de
-%D hash||table aardig uitputten (\type {\doifdefined}).
-%D
-%D \starttyping
-%D \edef\@@dimension{@@dim}
-%D \edef\@@negdimension{\@@dimension-}
-%D
-%D \def\assigndimension#1#2#3#4#5%
-%D {\setvalue{\@@dimension \v!small }{#3}%
-%D \setvalue{\@@dimension \v!medium}{#4}%
-%D \setvalue{\@@dimension \v!big }{#5}%
-%D \setvalue{\@@dimension \v!none }{\!!zeropoint}%
-%D \setvalue{\@@negdimension\v!small }{-#3}%
-%D \setvalue{\@@negdimension\v!medium}{-#4}%
-%D \setvalue{\@@negdimension\v!big }{-#5}%
-%D \setvalue{\@@negdimension\v!none }{\!!zeropoint}%
-%D \doifdefinedelse{\@@dimension#1}
-%D {#2=\getvalue{\@@dimension#1}}
-%D {#2=#1}}
-%D \stoptyping
-%D
-%D Let's give this a try:
-
-\let\nopv!none \v!none
-\let\posv!big \v!big
-\let\posv!middle \v!medium
-\let\posv!small \v!small
-\edef\negv!big {-\v!big}
-\edef\negv!middle{-\v!medium}
-\edef\negv!small {-\v!small}
-
-\def\assigndimension#1#2#3#4#5%
- {\edef\!!stringa{#1}%
- #2=\ifx\!!stringa\nopv!none \zeropoint\else
- \ifx\!!stringa\posv!big #5\else
- \ifx\!!stringa\posv!middle #4\else
- \ifx\!!stringa\posv!small #3\else
- \ifx\!!stringa\negv!big -#5\else
- \ifx\!!stringa\negv!middle-#4\else
- \ifx\!!stringa\negv!small -#3\else
- #1\fi\fi\fi\fi\fi\fi\fi}
-
-\def\assignalfadimension#1#2#3#4#5%
- {\edef\!!stringa{#1}%
- \edef#2{\ifx\!!stringa\posv!big #5\else
- \ifx\!!stringa\posv!middle#4\else
- \ifx\!!stringa\posv!small #3\else
- \ifx\!!stringa\nopv!none 0\else
- #1\fi\fi\fi\fi}}
+% The third (optimized) version:
+
+\def\@ad@{@ad@}
+
+\setvalue{\@ad@ \v!none }{\zeropoint\gobblethreearguments}
+\setvalue{\@ad@ \v!big }{\thirdofthreearguments}
+\setvalue{\@ad@ \v!medium}{\secondofthreearguments}
+\setvalue{\@ad@ \v!small }{\firstofthreearguments}
+\setvalue{\@ad@-\v!big }{-\thirdofthreearguments}
+\setvalue{\@ad@-\v!medium}{-\secondofthreearguments}
+\setvalue{\@ad@-\v!small }{-\firstofthreearguments}
+
+\def\assigndimension#1#2% #3 #4 #5
+ {#2=\ifcsname\@ad@#1\endcsname
+ \csname\@ad@#1\expandafter\endcsname
+ \else
+ #1\expandafter\gobblethreearguments
+ \fi}
+
+\def\@aa@{@aa@}
+
+\setvalue{\@aa@\v!none }{0\gobblethreearguments}
+\setvalue{\@aa@\v!big }{\thirdofthreearguments}
+\setvalue{\@aa@\v!medium}{\secondofthreearguments}
+\setvalue{\@aa@\v!small }{\firstofthreearguments}
+
+\def\assignalfadimension#1#2#3#4#5% #3#4#5 are single digits
+ {\edef#2{\ifcsname\@aa@#1\endcsname
+ \csname\@aa@#1\expandafter\endcsname
+ \else
+ #1\expandafter\gobblethreearguments
+ \fi#3#4#5}}
%D \macros
%D {assignvalue}
@@ -162,22 +121,18 @@
%D
%D Hier doet \type{geen} dus niet mee.
-\def\assignvalue#1#2#3#4#5%
- {\processaction
- [#1]
- [ \v!small=>\edef#2{#3},
- \v!medium=>\edef#2{#4},
- \v!big=>\edef#2{#5},
- \s!unknown=>\edef#2{#1}]}
+\def\@av@{@av@}
-%D Or faster:
+\letvalue{\@av@\v!big }\thirdofthreearguments
+\letvalue{\@av@\v!medium}\secondofthreearguments
+\letvalue{\@av@\v!small }\firstofthreearguments
\def\assignvalue#1#2#3#4#5%
- {\edef\!!stringa{#1}%
- \edef#2{\ifx\!!stringa\posv!big #5\else
- \ifx\!!stringa\posv!middle#4\else
- \ifx\!!stringa\posv!small #3\else
- #1\fi\fi\fi}}
+ {\edef#2{\ifcsname\@av@#1\endcsname
+ \csname\@av@#1\expandafter\endcsname
+ \else
+ #1\expandafter\gobblethreearguments
+ \fi{#3}{#4}{#5}}}
%D \macros
%D {assignwidth}
@@ -200,11 +155,11 @@
\def\assignwidth#1#2#3#4%
{\doifelsenothing{#2}
- {\setbox0\hbox{#3}%
- #1\wd0}
+ {\setbox\scratchbox\hbox{#3}%
+ #1\wd\scratchbox}
{\doifinsetelse{#2}{\v!fit,\v!broad}
- {\setbox0=\hbox{#3}%
- #1\wd0
+ {\setbox\scratchbox\hbox{#3}%
+ #1\wd\scratchbox
\doif{#2}\v!broad{\advance#1 #4}}%
{#1=#2}}}%
diff --git a/tex/context/base/core-grd.tex b/tex/context/base/core-grd.tex
index 5db966455..249e2e430 100644
--- a/tex/context/base/core-grd.tex
+++ b/tex/context/base/core-grd.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Grid Snapping}
+\writestatus{loading}{ConTeXt Core Macros / Grid Snapping}
\unprotect
diff --git a/tex/context/base/core-inc.lua b/tex/context/base/core-inc.lua
index 1707c1b25..35370058d 100644
--- a/tex/context/base/core-inc.lua
+++ b/tex/context/base/core-inc.lua
@@ -33,63 +33,23 @@ The TeX-Lua mix is suboptimal. This has to do with the fact that we cannot
run TeX code from within Lua. Some more functionality will move to Lua.
]]--
-local texsprint, format = tex.sprint, string.format
+local texsprint, format, lower = tex.sprint, string.format, string.lower
-backends = backends or { }
-backends.pdf = backends.pdf or { }
+local ctxcatcodes = tex.ctxcatcodes
---~ function backends.pdf.startscaling(sx,sy)
---~ return nodes.pdfliteral(format("q %s 0 0 %s 0 0 cm",(sx ~= 0 and sx) or .0001,(sy ~= 0 and sy) or .0001))
---~ end
---~ function backends.pdf.stopscaling()
---~ return nodes.pdfliteral("%Q")
---~ end
-
-function backends.pdf.insertmovie(data)
- data = data or figures.current()
- local dr, du, ds = data.request, data.used, data.status
- local width, height, factor = du.width or dr.width, du.height or dr.height, number.dimenfactors.bp
- local options, actions = "", ""
- if dr["repeat"] then
- actions = actions .. "/Mode /Repeat "
- end
- if dr.controls then
- actions = actions .. "/ShowControls true "
- else
- actions = actions .. "/ShowControls false "
- end
- if dr.preview then
- options = options .. "/Poster true "
- end
- if actions ~= "" then
- actions= "/A <<" .. actions .. ">>"
- end
- texsprint(tex.ctxcatcodes, format(
- "\\doPDFannotation{%ssp}{%ssp}{/Subtype /Movie /Border [0 0 0] /T (movie %s) /Movie << /F (%s) /Aspect [%s %s] %s>> %s}",
- width, height, dr.label, du.foundname, factor * width, factor * height, options, actions
- ))
- return data
-end
-
---~ if node then do
---~ local n = node.new(0,0)
---~ local m = getmetatable(n)
---~ m.__concat = function(a,b)
---~ local t = node.slide(a)
---~ t.next, b.prev = b, t
---~ return a
---~ end
---~ node.free(n)
---~ end end
+local trace_figures = false trackers.register("figures.locating",function(v) trace_figures = v end)
--- some extra img functions ---
-function img.totable(i)
- local t = { }
- for _, v in ipairs(img.keys()) do
- t[v] = i[v]
+local imgkeys = img.keys()
+
+function img.totable(imgtable)
+ local result = { }
+ for k=1,#imgkeys do
+ local key = imgkeys[k]
+ result[key] = imgtable[key]
end
- return t
+ return result
end
function img.serialize(i)
@@ -124,7 +84,6 @@ figures.found = figures.found or { }
figures.suffixes = figures.suffixes or { }
figures.patterns = figures.patterns or { }
figures.boxnumber = figures.boxid or 0
-figures.trace = false
figures.defaultsearch = true
figures.defaultwidth = 0
figures.defaultheight = 0
@@ -226,7 +185,7 @@ function figures.setpaths(locationset,pathlist)
end
end
figures.paths, last_pathlist = t, pathlist
- if figures.trace then
+ if trace_figures then
logs.report("figures","locations: %s",last_locationset)
logs.report("figures","path list: %s",table.concat(figures.paths))
end
@@ -299,11 +258,13 @@ do
end
function figures.push(request)
- input.starttiming(figures)
+ statistics.starttiming(figures)
local figuredata = figures.new()
if request then
- local iv = interfaces.variables
- local w, h = tonumber(request.width), tonumber(request.height)
+ local iv = interfaces.variables
+ -- request.width/height are strings and are only used when no natural dimensions
+ -- can be determined; at some point the handlers might set them to numbers instead
+--~ local w, h = tonumber(request.width), tonumber(request.height)
request.page = math.max(tonumber(request.page) or 1,1)
request.size = img.check_size(request.size)
request.object = iv[request.object] == "yes"
@@ -312,8 +273,8 @@ do
request.cache = request.cache ~= "" and request.cache
request.prefix = request.prefix ~= "" and request.prefix
request.format = request.format ~= "" and request.format
- request.width = (w and w > 0) or false
- request.height = (h and h > 0) or false
+--~ request.width = (w and w > 0) or false
+--~ request.height = (h and h > 0) or false
table.merge(figuredata.request,request)
end
callstack[#callstack+1] = figuredata
@@ -322,7 +283,7 @@ do
function figures.pop()
figuredata = callstack[#callstack]
callstack[#callstack] = nil
- input.stoptiming(figures)
+ statistics.stoptiming(figures)
end
-- maybe move texsprint to tex
function figures.get(category,tag,default)
@@ -334,7 +295,7 @@ do
end
end
function figures.tprint(category,tag,default)
- texsprint(tex.ctxcatcodes,figures.get(category,tag,default))
+ texsprint(ctxcatcodes,figures.get(category,tag,default))
end
function figures.current()
return callstack[#callstack]
@@ -342,187 +303,180 @@ do
end
-do
-
- local function register(askedname,specification)
- if specification then
- local format = specification.format
- if format then
- local converter = figures.converters[format]
- if converter then
- local oldname = specification.fullname
- local newformat = "pdf" -- todo, other target than pdf
- local newpath = file.dirname(oldname)
- local newbase = file.replacesuffix(file.basename(oldname),newformat)
- local fc = specification.cache or figures.cachepaths.path
- if fc and fc ~= "" and fc ~= "." then
- newpath = fc
- end
- local subpath = specification.subpath or figures.cachepaths.subpath
- if subpath and subpath ~= "" and subpath ~= "." then
- newpath = newpath .. "/" .. subpath
- end
- local prefix = specification.prefix or figures.cachepaths.prefix
- if prefix and prefix ~= "" then
- newbase = prefix .. newbase
- end
- local newname = file.join(newpath,newbase)
- dir.makedirs(newpath)
- local oldtime = lfs.attributes(oldname,'modification') or 0
- local newtime = lfs.attributes(newname,'modification') or 0
- if oldtime > newtime then
- converter(oldname,newname)
- end
- if io.exists(newname) then
- specification.foundname = oldname
- specification.fullname = newname
- specification.prefix = prefix
- specification.subpath = subpath
- specification.converted = true
- format = newformat
- elseif io.exists(oldname) then
- specification.fullname = newname
- specification.converted = false
- end
+local function register(askedname,specification)
+ if specification then
+ local format = specification.format
+ if format then
+ local converter = figures.converters[format]
+ if converter then
+ local oldname = specification.fullname
+ local newformat = "pdf" -- todo, other target than pdf
+ local newpath = file.dirname(oldname)
+ local newbase = file.replacesuffix(file.basename(oldname),newformat)
+ local fc = specification.cache or figures.cachepaths.path
+ if fc and fc ~= "" and fc ~= "." then
+ newpath = fc
+ end
+ local subpath = specification.subpath or figures.cachepaths.subpath
+ if subpath and subpath ~= "" and subpath ~= "." then
+ newpath = newpath .. "/" .. subpath
+ end
+ local prefix = specification.prefix or figures.cachepaths.prefix
+ if prefix and prefix ~= "" then
+ newbase = prefix .. newbase
+ end
+ local newname = file.join(newpath,newbase)
+ dir.makedirs(newpath)
+ local oldtime = lfs.attributes(oldname,'modification') or 0
+ local newtime = lfs.attributes(newname,'modification') or 0
+ if oldtime > newtime then
+ converter(oldname,newname)
+ end
+ if io.exists(newname) then
+ specification.foundname = oldname
+ specification.fullname = newname
+ specification.prefix = prefix
+ specification.subpath = subpath
+ specification.converted = true
+ format = newformat
+ elseif io.exists(oldname) then
+ specification.fullname = newname
+ specification.converted = false
end
end
- specification.found = validtypes[format]
- if figures.trace then
+ end
+ local found = figures.suffixes[format] -- validtypes[format]
+ if not found then
+ specification.found = false
+ if trace_figures then
logs.report("figures","format not supported: %s",format)
end
else
- specification = { }
+ specification.found = true
+ if trace_figures then
+ if validtypes[format] then
+ logs.report("figures","format natively supported by backend: %s",format)
+ else
+ logs.report("figures","format supported by output file format: %s",format)
+ end
+ end
end
- specification.foundname = specification.foundname or specification.fullname
- figures.found[askedname] = specification
- return specification
+ else
+ specification = { }
end
+ specification.foundname = specification.foundname or specification.fullname
+ figures.found[askedname] = specification
+ return specification
+end
- local function locate(request) -- name, format, cache
- local askedname = input.clean_path(request.name)
- if figures.found[askedname] then
- return figures.found[askedname]
- end
- local askedpath= file.dirname(askedname)
- local askedbase = file.basename(askedname)
- local askedformat = (request.format ~= "" and request.format ~= "unknown" and request.format) or file.extname(askedname) or ""
- local askedcache = request.cache
- if askedformat ~= "" then
- askedformat = askedformat:lower()
- local format = figures.suffixes[askedformat]
- if not format then
- for _, pattern in ipairs(figures.patterns) do
- if askedformat:find(pattern[1]) then
- format = pattern[2]
- break
- end
+local function locate(request) -- name, format, cache
+ local askedname = resolvers.clean_path(request.name)
+ if figures.found[askedname] then
+ return figures.found[askedname]
+ end
+ local askedpath= file.dirname(askedname)
+ local askedbase = file.basename(askedname)
+ local askedformat = (request.format ~= "" and request.format ~= "unknown" and request.format) or file.extname(askedname) or ""
+ local askedcache = request.cache
+ if askedformat ~= "" then
+ askedformat = lower(askedformat)
+ local format = figures.suffixes[askedformat]
+ if not format then
+ for _, pattern in ipairs(figures.patterns) do
+ if askedformat:find(pattern[1]) then
+ format = pattern[2]
+ break
end
end
- if format then
- local foundname = figures.exists(askedname,askedformat)
- if foundname then
- return register(askedname, {
+ end
+ if format then
+ local foundname = figures.exists(askedname,askedformat)
+ if foundname then
+ return register(askedname, {
+ askedname = askedname,
+ fullname = askedname,
+ format = format,
+ cache = askedcache,
+ foundname = foundname,
+ })
+ end
+ end
+ if askedpath ~= "" then
+ -- path and type given, todo: strip pieces of path
+ if figures.exists(askedname,askedformat) then
+ return register(askedname, {
+ askedname = askedname,
+ fullname = askedname,
+ format = askedformat,
+ cache = askedcache,
+ })
+ end
+ else
+ -- type given
+ for _, path in ipairs(figures.paths) do
+ local check = path .. "/" .. askedname
+ if figures.exists(check,askedformat) then
+ return register(check, {
askedname = askedname,
- fullname = askedname,
- format = format,
+ fullname = check,
+ format = askedformat,
cache = askedcache,
- foundname = foundname,
})
end
end
- if askedpath ~= "" then
- -- path and type given, todo: strip pieces of path
- if figures.exists(askedname,askedformat) then
+ if figures.defaultsearch then
+ local check = resolvers.find_file(askedname)
+ if check and check ~= "" then
return register(askedname, {
askedname = askedname,
- fullname = askedname,
+ fullname = check,
format = askedformat,
cache = askedcache,
})
end
- else
- -- type given
- for _, path in ipairs(figures.paths) do
- local check = path .. "/" .. askedname
- if figures.exists(check,askedformat) then
- return register(check, {
- askedname = askedname,
- fullname = check,
- format = askedformat,
- cache = askedcache,
- })
- end
- end
- if figures.defaultsearch then
- local check = input.find_file(askedname)
- if check and check ~= "" then
- return register(askedname, {
- askedname = askedname,
- fullname = check,
- format = askedformat,
- cache = askedcache,
- })
- end
+ end
+ end
+ elseif askedpath ~= "" then
+ for _, format in ipairs(figures.order) do
+ local list = figures.formats[format].list or { format }
+ for _, suffix in ipairs(list) do
+ local check = file.addsuffix(askedname,suffix)
+ if figures.exists(check,format) then
+ return register(askedname, {
+ askedname = askedname,
+ fullname = check,
+ format = format,
+ cache = askedcache,
+ })
end
end
- elseif askedpath ~= "" then
+ end
+ else
+ if figures.prefer_quality then
for _, format in ipairs(figures.order) do
local list = figures.formats[format].list or { format }
for _, suffix in ipairs(list) do
- local check = file.addsuffix(askedname,suffix)
- if figures.exists(check,format) then
- return register(askedname, {
- askedname = askedname,
- fullname = check,
- format = format,
- cache = askedcache,
- })
- end
- end
- end
- else
- if figures.prefer_quality then
- for _, format in ipairs(figures.order) do
- local list = figures.formats[format].list or { format }
- for _, suffix in ipairs(list) do
- local name = file.replacesuffix(askedbase,suffix)
- for _, path in ipairs(figures.paths) do
- local check = path .. "/" .. name
- if figures.exists(check,format) then
- return register(askedname, {
- askedname = askedname,
- fullname = check,
- format = format,
- cache = askedcache,
- })
- end
- end
- end
- end
- else -- 'location'
- for _, path in ipairs(figures.paths) do
- for _, format in ipairs(figures.order) do
- local list = figures.formats[format].list or { format }
- for _, suffix in ipairs(list) do
- local check = path .. "/" .. file.replacesuffix(askedbase,suffix)
- if figures.exists(check,format) then
- return register(askedname, {
- askedname = askedname,
- fullname = check,
- format = format,
- cache = askedcache,
- })
- end
+ local name = file.replacesuffix(askedbase,suffix)
+ for _, path in ipairs(figures.paths) do
+ local check = path .. "/" .. name
+ if figures.exists(check,format) then
+ return register(askedname, {
+ askedname = askedname,
+ fullname = check,
+ format = format,
+ cache = askedcache,
+ })
end
end
end
end
- if figures.defaultsearch then
+ else -- 'location'
+ for _, path in ipairs(figures.paths) do
for _, format in ipairs(figures.order) do
local list = figures.formats[format].list or { format }
for _, suffix in ipairs(list) do
- local check = input.find_file(file.replacesuffix(askedname,suffix))
- if check and check ~= "" then
+ local check = path .. "/" .. file.replacesuffix(askedbase,suffix)
+ if figures.exists(check,format) then
return register(askedname, {
askedname = askedname,
fullname = check,
@@ -534,75 +488,92 @@ do
end
end
end
- return register(askedname)
+ if figures.defaultsearch then
+ for _, format in ipairs(figures.order) do
+ local list = figures.formats[format].list or { format }
+ for _, suffix in ipairs(list) do
+ local check = resolvers.find_file(file.replacesuffix(askedname,suffix))
+ if check and check ~= "" then
+ return register(askedname, {
+ askedname = askedname,
+ fullname = check,
+ format = format,
+ cache = askedcache,
+ })
+ end
+ end
+ end
+ end
end
+ return register(askedname)
+end
- -- -- -- plugins -- -- --
+-- -- -- plugins -- -- --
- figures.existers = figures.existers or { }
- figures.checkers = figures.checkers or { }
- figures.includers = figures.includers or { }
- figures.converters = figures.converters or { }
- figures.identifiers = figures.identifiers or { }
+figures.existers = figures.existers or { }
+figures.checkers = figures.checkers or { }
+figures.includers = figures.includers or { }
+figures.converters = figures.converters or { }
+figures.identifiers = figures.identifiers or { }
- figures.identifiers.list = {
- figures.identifiers.default
- }
+figures.identifiers.list = {
+ figures.identifiers.default
+}
- function figures.identifiers.default(data)
- local dr, du, ds = data.request, data.used, data.status
- local l = locate(dr)
- local foundname = l.foundname
- local fullname = l.fullname or foundname
- if fullname then
- du.format = l.format or false
- du.fullname = fullname -- can be cached
- ds.fullname = foundname -- original
- ds.format = l.format
- ds.status = (l.found and 10) or 0
- end
- return data
+function figures.identifiers.default(data)
+ local dr, du, ds = data.request, data.used, data.status
+ local l = locate(dr)
+ local foundname = l.foundname
+ local fullname = l.fullname or foundname
+ if fullname then
+ du.format = l.format or false
+ du.fullname = fullname -- can be cached
+ ds.fullname = foundname -- original
+ ds.format = l.format
+ ds.status = (l.found and 10) or 0
end
+ return data
+end
- function figures.identify(data)
- data = data or figures.current()
- for _, identifier in ipairs(figures.identifiers.list) do
- data = identifier(data)
- if data.status.status > 0 then
- break
- end
+function figures.identify(data)
+ data = data or figures.current()
+ for _, identifier in ipairs(figures.identifiers.list) do
+ data = identifier(data)
+ if data.status.status > 0 then
+ break
end
- return data
- end
- function figures.exists(askedname,format)
- return (figures.existers[format] or figures.existers.generic)(askedname)
- end
- function figures.check(data)
- data = data or figures.current()
- local dr, du, ds = data.request, data.used, data.status
- return (figures.checkers[ds.format] or figures.checkers.generic)(data)
- end
- function figures.include(data)
- data = data or figures.current()
- local dr, du, ds = data.request, data.used, data.status
- return (figures.includers[ds.format] or figures.includers.generic)(data)
- end
- function figures.scale(data) -- will become lua code
- texsprint(tex.ctxcatcodes,"\\doscalefigure")
- return data
- end
- function figures.done(data)
- figures.n = figures.n + 1
- data = data or figures.current()
- local dr, du, ds = data.request, data.used, data.status
- ds.width = tex.wd[figures.boxnumber]
- ds.height = tex.ht[figures.boxnumber]
- ds.xscale = ds.width/(du.width or 1)
- ds.yscale = ds.height/(du.height or 1)
- return data
end
+ return data
+end
+function figures.exists(askedname,format)
+ return (figures.existers[format] or figures.existers.generic)(askedname)
+end
+function figures.check(data)
+ data = data or figures.current()
+ local dr, du, ds = data.request, data.used, data.status
+ return (figures.checkers[ds.format] or figures.checkers.generic)(data)
+end
+function figures.include(data)
+ data = data or figures.current()
+ local dr, du, ds = data.request, data.used, data.status
+ return (figures.includers[ds.format] or figures.includers.generic)(data)
+end
+function figures.scale(data) -- will become lua code
+ texsprint(ctxcatcodes,"\\doscalefigure")
+ return data
+end
+function figures.done(data)
+ figures.n = figures.n + 1
+ data = data or figures.current()
+ local dr, du, ds = data.request, data.used, data.status
+ ds.width = tex.wd[figures.boxnumber]
+ ds.height = tex.ht[figures.boxnumber]
+ ds.xscale = ds.width/(du.width or 1)
+ ds.yscale = ds.height/(du.height or 1)
+ return data
+end
- function figures.dummy(data) -- fails
+function figures.dummy(data) -- fails
--~ data = data or figures.current()
--~ local dr, du, ds = data.request, data.used, data.status
--~ local r = node.new("rule")
@@ -610,9 +581,7 @@ do
--~ r.height = du.height or figures.defaultheight
--~ r.depth = du.depth or figures.defaultdepth
--~ tex.box[figures.boxnumber] = node.write(r)
- texsprint(tex.ctxcatcodes,"\\emptyfoundexternalfigure")
- end
-
+ texsprint(ctxcatcodes,"\\emptyfoundexternalfigure")
end
-- -- -- generic -- -- --
@@ -620,10 +589,10 @@ end
function figures.existers.generic(askedname)
--~ local result = io.exists(askedname)
--~ result = (result==true and askedname) or result
---~ local result = input.find_file(askedname) or ""
- local result = input.findbinfile(askedname) or ""
+--~ local result = resolvers.find_file(askedname) or ""
+ local result = resolvers.findbinfile(askedname) or ""
if result == "" then result = false end
- if figures.trace then
+ if trace_figures then
if result then
logs.report("figures","found: %s -> %s",askedname,result)
else
@@ -652,8 +621,9 @@ function figures.checkers.generic(data)
end
function figures.includers.generic(data)
local dr, du, ds = data.request, data.used, data.status
- dr.width = dr.width or du.width
- dr.height = dr.height or du.height
+ -- here we set the 'natural dimensions'
+ dr.width = du.width
+ dr.height = du.height
local hash = figures.hash(data)
local figure = figures.used[hash]
if figure == nil then
@@ -670,7 +640,7 @@ function figures.includers.generic(data)
tex.box[n] = img.node(figure) -- img.write(figure)
tex.wd[n], tex.ht[n], tex.dp[n] = figure.width, figure.height, 0 -- new, hm, tricky, we need to do that in tex (yet)
ds.objectnumber = figure.objnum
- texsprint(tex.ctxcatcodes,"\\relocateexternalfigure")
+ texsprint(ctxcatcodes,"\\relocateexternalfigure")
end
return data
end
@@ -682,13 +652,14 @@ function figures.checkers.nongeneric(data,command)
local name = du.fullname or "unknown nongeneric"
local hash = name
if dr.object then
- if not job.objects["FIG::"..hash] then
- texsprint(tex.ctxcatcodes,command)
- texsprint(tex.ctxcatcodes,format("\\setobject{FIG}{%s}\\vbox{\\box\\foundexternalfigure}",hash))
+ -- hm, bugged
+ if not jobobjects.get("FIG::"..hash) then
+ texsprint(ctxcatcodes,command)
+ texsprint(ctxcatcodes,format("\\setobject{FIG}{%s}\\vbox{\\box\\foundexternalfigure}",hash))
end
- texsprint(tex.ctxcatcodes,format("\\global\\setbox\\foundexternalfigure\\vbox{\\getobject{FIG}{%s}}",hash))
+ texsprint(ctxcatcodes,format("\\global\\setbox\\foundexternalfigure\\vbox{\\getobject{FIG}{%s}}",hash))
else
- texsprint(tex.ctxcatcodes,command)
+ texsprint(ctxcatcodes,command)
end
return data
end
@@ -700,14 +671,25 @@ end
function figures.checkers.mov(data)
local dr, du, ds = data.request, data.used, data.status
- du.width = dr.width or figures.defaultwidth
- du.height = dr.height or figures.defaultheight
+ dr.width = (dr.width or figures.defaultwidth):todimen()
+ dr.height = (dr.height or figures.defaultheight):todimen()
+ du.width = dr.width
+ du.height = dr.height
du.foundname = du.fullname
- texsprint(tex.ctxcatcodes,format("\\startfoundexternalfigure{%ssp}{%ssp}",du.width,du.height))
- data = backends.pdf.insertmovie(data)
- texsprint(tex.ctxcatcodes,"\\stopfoundexternalfigure")
+ local code = backends.codeinjections {
+ width = du.width or dr.width,
+ height = du.height or dr.height,
+ factor = number.dimenfactors.bp,
+ ["repeat"] = dr["repeat"],
+ controls = dr.controls,
+ preview = dr.preview,
+ label = dr.label,
+ foundname = du.foundname,
+ }
+ texsprint(ctxcatcodes,format("\\startfoundexternalfigure{%ssp}{%ssp}%s\\stopfoundexternalfigure",du.width,du.height,code))
return data
end
+
figures.includers.mov = figures.includers.nongeneric
-- -- -- mps -- -- --
@@ -731,7 +713,7 @@ figures.includers.buffers = figures.includers.nongeneric
-- -- -- tex -- -- --
function figures.existers.tex(askedname)
- askedname = input.find_file(askedname)
+ askedname = resolvers.find_file(askedname)
return (askedname ~= "" and askedname) or false
end
function figures.checkers.tex(data)
@@ -761,38 +743,39 @@ figures.converters.svg = figures.converters.eps
--~ os.spawn(command)
--~ end
-
figures.bases = { }
figures.bases.list = { } -- index => { basename, fullname, xmlroot }
figures.bases.used = { } -- [basename] => { basename, fullname, xmlroot } -- pointer to list
figures.bases.found = { }
figures.bases.enabled = false
-function figures.bases.use(basename)
+local bases = figures.bases
+
+function bases.use(basename)
if basename == "reset" then
- figures.bases.list = { }
- figures.bases.used = { }
- figures.bases.found = { }
- figures.bases.enabled = false
+ bases.list = { }
+ bases.used = { }
+ bases.found = { }
+ bases.enabled = false
else
basename = file.addsuffix(basename,"xml")
- if not figures.bases.used[basename] then
+ if not bases.used[basename] then
local t = { basename, nil, nil }
- figures.bases.used[basename] = t
- figures.bases.list[#figures.bases.list+1] = t
- if not figures.bases.enabled then
- figures.bases.enabled = true
+ bases.used[basename] = t
+ bases.list[#bases.list+1] = t
+ if not bases.enabled then
+ bases.enabled = true
xml.registerns("rlx","http://www.pragma-ade.com/schemas/rlx") -- we should be able to do this per xml file
end
end
end
end
-function figures.bases.find(basename,askedlabel)
+function bases.find(basename,askedlabel)
basename = file.addsuffix(basename,"xml")
- local t = figures.bases.found[askedlabel]
+ local t = bases.found[askedlabel]
if t == nil then
- local base = figures.bases.used[basename]
+ local base = bases.used[basename]
local page = 0
if base[2] == nil then
-- no yet located
@@ -816,7 +799,7 @@ function figures.bases.find(basename,askedlabel)
name = xml.filters.text(e,"*:file"),
page = page,
}
- figures.bases.found[askedlabel] = t
+ bases.found[askedlabel] = t
return t
end
end
@@ -827,9 +810,9 @@ end
-- we can access sequential or by name
-function figures.bases.locate(askedlabel)
- for _, entry in ipairs(figures.bases.list) do
- local t = figures.bases.find(entry[1],askedlabel)
+function bases.locate(askedlabel)
+ for _, entry in ipairs(bases.list) do
+ local t = bases.find(entry[1],askedlabel)
if t then
return t
end
@@ -838,9 +821,9 @@ function figures.bases.locate(askedlabel)
end
function figures.identifiers.base(data)
- if figures.bases.enabled then
+ if bases.enabled then
local dr, du, ds = data.request, data.used, data.status
- local fbl = figures.bases.locate(dr.name or dr.label)
+ local fbl = bases.locate(dr.name or dr.label)
if fbl then
du.page = fbl.page
du.format = fbl.format
@@ -858,3 +841,14 @@ figures.identifiers.list = {
figures.identifiers.base,
figures.identifiers.default
}
+
+-- tracing
+
+statistics.register("graphics processing time", function()
+ local n = figures.n
+ if n > 0 then
+ return format("%s seconds including tex, n=%s", statistics.elapsedtime(figures),n)
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/core-inc.mkii b/tex/context/base/core-inc.mkii
index fe3894d57..ce97a0d1b 100644
--- a/tex/context/base/core-inc.mkii
+++ b/tex/context/base/core-inc.mkii
@@ -11,6 +11,8 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Figure Inclusion}
+
% todo: directory : system -> \allinputpaths (so that we can \usesubpath)
%D This is a reimplementation of the original module, which
@@ -30,82 +32,19 @@
\unprotect
-\startmessages dutch library: figures
- title: figuren
- 1: figuur -- is niet te vinden
- 2: figuur -- wordt niet preset
- 3: maten van -- worden extern vastgesteld
- 4: maten van -- geladen uit figuurfile zelf
- 5: maten van -- zijn onbekend
- 6: maten van -- berekend door rlxtools
- 8: figuurobject -- wordt opnieuw gebruikt
-\stopmessages
-
-\startmessages english library: figures
- title: figures
- 1: figure -- can not be found
- 2: figure -- is not preset
- 3: dimensions of -- are determined externally
- 4: dimensions of -- loaded from figurefile itself
- 5: dimensions of -- are unknown
- 6: dimensions of -- calculated by rlxtools
- 8: figureobject -- is reused
-\stopmessages
-
-\startmessages german library: figures
- title: Abbildungen
- 1: Abbildung -- kann nicht gefunden werden
- 2: Abbildung -- wird nicht erstellt
- 3: dimensions of -- are determined externally
- 4: Dimensionen von -- geladen aus der Abbildungsdatei selbst
- 5: Dimensions of -- are unknown
- 6: Dimensionen von -- ausgerechnet durch rlxtools
- 8: Abbildungobjekt -- wurde wiederverwandt
-\stopmessages
-
-\startmessages czech library: figures
- title: obrazy
- 1: obraz -- nelze nalezt
- 2: obraz -- nepritomen
- 3: dimensions of -- are determined externally
- 4: dimenze obrazu -- nacteny primo z jeho souboru
- 5: dimensions of -- are unknown
- 6: dimenze obrazu -- spocteny programem rlxtools
- 8: obrazovy objekt -- je znovu pouzit
-\stopmessages
-
-\startmessages italian library: figures
- title: figure
- 1: figura -- non trovata
- 2: la figura -- non è preimpostata
- 3: dimensions of -- are determined externally
- 4: dimensioni di -- caricate dal file di immagini stesso
- 5: dimensions of -- are unknown
- 6: dimensioni di -- calcolate da rlxtools
- 8: oggetto-figura -- riutilizzato
-\stopmessages
-
-\startmessages romanian library: figures
- title: figuri
- 1: figura -- nu poate fi gasita
- 2: figura -- nu este presetata
- 3: dimensions of -- are determined externally
- 4: dimensiunea figurii -- se incarca din fisierul insusi
- 5: dimensions of -- are unknown
- 6: dimensiunea figurii -- este calculata de rlxtools
- 8: obiectul figura -- este refolosit
-\stopmessages
-
-\startmessages french library: figures
- title: figures
- 1: la figure -- ne peut être trouvée
- 2: la figure -- n'est pas pré-sélectionnée
- 3: dimensions of -- are determined externally
- 4: les dimensions de -- chargées implicitement à partir du fichier de figure
- 5: dimensions of -- are unknown
- 6: les dimensions de -- calculées par rlxtools
- 8: figureobject -- est réutilisé
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
%D Due to the mere fact that \DVI|/|\PDF\ drivers differ in their
%D needs for figure dimensions, we have to provide the width,
@@ -827,8 +766,8 @@
\def\insertscaledfiguredriverdata
{\insertfiguredriverdata\finalscaleboxwidth\finalscaleboxheight}
-\ifx\externalfigurereplacement\undefined\let\externalfigurereplacement\gobblethrearguments\fi
-\ifx\externalfigureplaceholder\undefined\let\externalfigureplaceholder\gobblethrearguments\fi
+\ifx\externalfigurereplacement\undefined\let\externalfigurereplacement\gobblethreearguments\fi
+\ifx\externalfigureplaceholder\undefined\let\externalfigureplaceholder\gobblethreearguments\fi
\def\registerexternalfigure % no placement, handy for preprocessing
{\dotripleempty\doregisterexternalfigure}
diff --git a/tex/context/base/core-inc.mkiv b/tex/context/base/core-inc.mkiv
index 24a78e657..06c8dc306 100644
--- a/tex/context/base/core-inc.mkiv
+++ b/tex/context/base/core-inc.mkiv
@@ -11,6 +11,8 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Figure Inclusion}
+
%D todo:
%D
%D - color conversion
@@ -150,6 +152,8 @@
\let\@@efpreview \v!no
\let\@@efrepeat \v!no
%
+ \let\@@efforegroundcolor\empty
+ %
\let\@@efhfactor \empty
\let\@@efwfactor \empty
\let\@@effactor \empty
@@ -165,6 +169,8 @@
\let\@@eflines \empty
\let\@@efgrid \empty}
+\resetfigureusersettings
+
\appendtoks
\resetfigureusersettings
\to \everyexternalfigureresets
@@ -176,6 +182,8 @@
\doif\@@exoption\v!empty
{\skipexternalfigurestrue
\let\@@efframe\v!off}%
+ \doifsomething\@@efwidth {\doifdimensionelse\@@efwidth {\edef\@@efwidth {\the\dimexpr\@@efwidth }}\donothing}%
+ \doifsomething\@@efheight{\doifdimensionelse\@@efheight{\edef\@@efheight{\the\dimexpr\@@efheight}}\donothing}%
% seperation, seldom used
\doifseparatingcolorselse
{\let\@@efforegroundcolor\empty
@@ -346,8 +354,8 @@
\iftrialtypesetting \else \feedbackexternalfigure \fi
\fi}}
-\ifx\externalfigurereplacement\undefined\let\externalfigurereplacement\gobblethrearguments\fi
-\ifx\externalfigureplaceholder\undefined\let\externalfigureplaceholder\gobblethrearguments\fi
+\ifx\externalfigurereplacement\undefined\let\externalfigurereplacement\gobblethreearguments\fi
+\ifx\externalfigureplaceholder\undefined\let\externalfigureplaceholder\gobblethreearguments\fi
\let\feedbackexternalfigure\relax % \gobblefourarguments
\let\dowithfigure \relax
diff --git a/tex/context/base/core-inc.tex b/tex/context/base/core-inc.tex
deleted file mode 100644
index 88d52e746..000000000
--- a/tex/context/base/core-inc.tex
+++ /dev/null
@@ -1,18 +0,0 @@
-%D \module
-%D [ file=core-inc, % moved from core-fig
-%D version=2006.08.26, % overhaul of 1997.03.31
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Figure Inclusion,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Figure Inclusion}
-
-\loadmarkfile{core-inc}
-
-\endinput
diff --git a/tex/context/base/core-ini.tex b/tex/context/base/core-ini.tex
index 4f6e9fe1d..69edf9735 100644
--- a/tex/context/base/core-ini.tex
+++ b/tex/context/base/core-ini.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Initialization}
+\writestatus{loading}{ConTeXt Core Macros / Additional Initialization}
%D We will move more code to here, so that we become less dependent of the
%D orde in which modules are loaded.
diff --git a/tex/context/base/core-ins.tex b/tex/context/base/core-ins.tex
index c1185f7de..069153434 100644
--- a/tex/context/base/core-ins.tex
+++ b/tex/context/base/core-ins.tex
@@ -2,7 +2,7 @@
%D [ file=core-ins,
%D version=2002.04.16,
%D title=\CONTEXT\ Insertion Macros,
-%D subtitle=Insertions,
+%D subtitle=Insertions,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,14 +11,14 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Insertion Macros / General}
+\writestatus{loading}{ConTeXt Core Macros / Insertions}
%D Insertions are special data collections that are associated
%D to \TEX's internal page builder. When multiple footnote
%D classes were introduced, I decided to isolate some of the
-%D functionality in a module.
+%D functionality in a module.
-\unprotect
+\unprotect
\newtoks\@@insertionlist
@@ -29,7 +29,7 @@
%\def\installinsertion#1%
% {\ifx#1\undefined
% \newinsert#1%
-% \count#1\plusthousand
+% \count#1\plusthousand
% \skip #1\zeropoint
% \dimen#1\maxdimen
% \appendtoks\doprocessinsert#1\to\@@insertionlist
@@ -41,7 +41,7 @@
\fi
\ifx#1\relax % permits \csname...\endcsname
\newinsert#1%
- \count#1\plusthousand
+ \count#1\plusthousand
\skip #1\zeropoint
\dimen#1\maxdimen
\appendtoks\doprocessinsert#1\to\@@insertionlist
@@ -52,10 +52,10 @@
{\def\doprocessinsert##1{\ifvoid##1\else\insert##1{\unvbox##1}\fi}%
\processinsertions}
-%D For instance, when we postpone footnotes, we need to save
-%D some data related to the inserts. The next methods are
-%D far from ideal, but better than nothing. We save and
-%D restore box content and associated data independently.
+%D For instance, when we postpone footnotes, we need to save
+%D some data related to the inserts. The next methods are
+%D far from ideal, but better than nothing. We save and
+%D restore box content and associated data independently.
%D The box content is only restores when non||void.
\def\backupinsertion#1%
@@ -63,41 +63,41 @@
\def\installbackupinsertion#1%
{\expandafter\newinsert\csname\string#1\endcsname
- \count\backupinsertion#1\zerocount
+ \count\backupinsertion#1\zerocount
\skip \backupinsertion#1\zeropoint
\dimen\backupinsertion#1\maxdimen}
\def\saveinsertionbox#1%
- {\ifdim\ht#1>\zeropoint % hm, actually unknown
+ {\ifdim\ht#1>\zeropoint % hm, actually unknown
\global\setbox\backupinsertion#1\box#1%
\else
- \global\setbox\backupinsertion#1\box\voidb@x
+ \global\setbox\backupinsertion#1\emptybox
\fi}
\def\restoreinsertionbox#1%
- {\ifvoid\backupinsertion#1\else % if void, we keep the content
+ {\ifvoid\backupinsertion#1\else % if void, we keep the content
\global\setbox#1\box\backupinsertion#1%
\fi}
\def\eraseinsertionbackup#1%
- {\global\setbox\backupinsertion#1\box\voidb@x}
+ {\global\setbox\backupinsertion#1\emptybox}
-\def\saveinsertiondata#1%
+\def\saveinsertiondata#1%
{\global\skip \backupinsertion#1\skip #1%
\global\count\backupinsertion#1\count#1%
\global\dimen\backupinsertion#1\dimen#1}
-\def\restoreinsertiondata#1%
+\def\restoreinsertiondata#1%
{\global\skip #1\skip \backupinsertion#1%
\global\count#1\count\backupinsertion#1%
\global\dimen#1\dimen\backupinsertion#1}
-%D Auxiliary macros:
+%D Auxiliary macros:
\def\addinsertionheight#1\to#2%
{\ifvoid#1\else
- \advance#2 1\skip#1\relax
- \advance#2 \ht #1\relax
+ \advance#2 1\skip#1\relax
+ \advance#2 \ht #1\relax
\fi}
-\protect \endinput
+\protect \endinput
diff --git a/tex/context/base/core-int.mkii b/tex/context/base/core-int.mkii
new file mode 100644
index 000000000..1ca9d23d1
--- /dev/null
+++ b/tex/context/base/core-int.mkii
@@ -0,0 +1,2217 @@
+%D \module
+%D [ file=core-int,
+%D version=1995.01.01,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Interaction,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% evt interactionbaren runtime laden (scheelt 8K)
+
+%D Still to be done properly.
+
+\writestatus{loading}{ConTeXt Core Macros / Interaction}
+
+\unprotect
+
+% \expand vs \expanded
+
+% linked registers implementeren als een koppeling == mooier
+
+\presetlocalframed[\??lk]
+
+\newcounter\numberoflinks
+
+\def\stelkoppelingenin%
+ {\dodoubleargument\getparameters[\??lk]}
+
+\def\definieerkoppeling[#1]% % local loading !
+ {\doifundefined{\s!link:#1:\s!list}
+ {\expanded{\definetwopasslist{\s!link:#1}}%
+ \expanded{\doloadtwopassdata{\s!link:#1}}%
+ \getfirsttwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:f}\twopassdata
+ \getlasttwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:l}\twopassdata
+ \letgvalue{\s!link:#1:s}\noftwopassitems
+ \gettwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:c}\twopassdata
+ \letgvalue{\s!link:#1:n}\twopassdata}}
+
+\def\koppeling[#1]#2%
+ {\bgroup
+ \definieerkoppeling[#1]%
+ \doglobal\increment\numberoflinks
+ \gettwopassdata{\s!link:#1}%
+ \edef\numberoflinks{0\getvalue{\s!link:#1:s}}%
+ \edef\firstlink {0\getvalue{\s!link:#1:f}}%
+ \edef\lastlink {0\getvalue{\s!link:#1:l}}%
+ \edef\currentlink {0\getvalue{\s!link:#1:n}}%
+ \edef\prevlink {0\getvalue{\s!link:#1:c}}%
+ \iftwopassdatafound
+ \edef\nextlink{0\twopassdata}%
+ \letgvalue{\s!link:#1:n}\nextlink
+ \letgvalue{\s!link:#1:c}\currentlink
+ \else
+ \edef\nextlink{0\getvalue{\s!link:#1:l}}%
+ \fi
+ \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
+ \ifnum\noflinks<\plustwo
+ \locationfalse
+ \fi
+ \iflocation
+ \hbox
+ {\setinteractionparameter\c!width\!!zeropoint
+ \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
+ \ifnum\noflinks>\plustwo
+ \hskip\@@lkdistance
+ \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
+ \fi
+ \hskip\@@lkdistance
+ #2\relax
+ \hskip\@@lkdistance
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
+ \hskip\@@lkdistance
+ \fi
+ \dogotosomepage\??lk\gotoendcharacter\lastlink}%
+ \else
+ \hbox{#2}%
+ \fi
+ \egroup}
+
+\def\definieerkoppeling[#1]% % local loading !
+ {\doifundefined{\s!link:#1:\s!list}
+ {\expanded{\definetwopasslist{\s!link:#1}}% \expanded{\doloadtwopassdata{\s!link:#1}}%
+ \getfirsttwopassdata{\s!link:#1}%
+ \let\firstlink\twopassdata
+ \getlasttwopassdata{\s!link:#1}%
+ \let\lastlink\twopassdata
+ \let\noflinks\noftwopassitems
+ \gettwopassdata{\s!link:#1}%
+ \let\currentlink\twopassdata
+ \let\nextlink\twopassdata
+ \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}}}
+
+\def\koppeling[#1]#2%
+ {\bgroup
+ \definieerkoppeling[#1]%
+ \doglobal\increment\numberoflinks
+ \gettwopassdata{\s!link:#1}%
+ \def\next[##1:##2:##3:##4:##5]%
+ {\edef\firstlink {0##1}%
+ \edef\lastlink {0##2}%
+ \edef\noflinks {0##3}%
+ \edef\prevlink {0##4}%
+ \edef\currentlink{0##5}}%
+ \expanded{\next[\getvalue{\s!link:#1:}]}%
+ \edef\nextlink{0\iftwopassdatafound\twopassdata\else\lastlink\fi}%
+ \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}%
+ \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
+ \ifnum\noflinks<\plustwo
+ \locationfalse
+ \fi
+ \iflocation
+ \hbox
+ {\setinteractionparameter\c!width\!!zeropoint
+ #2\relax
+ \hskip\@@lkdistance
+ \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
+ \fi
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
+ \hskip\@@lkdistance
+ \fi
+ \dogotosomepage\??lk\gotoendcharacter\lastlink}%
+ \else
+ \hbox{#2}%
+ \fi
+ \egroup}
+
+\let\setupinteractionscreens\empty
+
+\def\docalculateinteractionscreen
+ {\doifelse\@@scwidth\v!fit
+ {\!!widtha\leftcombitotal
+ \ifdim\backspace>\!!widtha\ifdim\backspace>\zeropoint\relax
+ \advance\backspace -\!!widtha
+ \fi\fi
+ \advance\!!widtha\rightcombitotal
+ \advance\!!widtha 2\dimexpr\@@scbackspace+\@@schoroffset\relax}
+ {\doifelse\@@scwidth\v!max
+ {\!!widtha\printpaperwidth}
+ {\!!widtha\@@scwidth}}%
+ \doifelse\@@scheight\v!fit
+ {\!!heighta\dimexpr\topheight+\topdistance\relax
+ \ifdim\topspace>\!!heighta\ifdim\topspace>\zeropoint\relax
+ \advance\topspace -\!!heighta
+ \fi\fi
+ \advance\!!heighta \dimexpr\makeupheight+\bottomdistance+\bottomheight\relax
+ \advance\!!heighta 2\dimexpr\@@sctopspace+\@@scveroffset\relax}
+ {\doifelse\@@scheight\v!max
+ {\!!heighta\printpaperheight}
+ {\!!heighta\@@scheight}}%
+ \doif\@@scdelay\v!none{\let\@@scdelay\zerocountervalue}}
+
+% The macro is not to be changed; only the \@@ia-variables
+% may be set! ConTeXt is the producer but we no longer
+% mention the pragma site, since we don't want to be bothered
+% with remarks about third party documents and/or associated
+% with documents produced outside our control.
+
+\def\doprepareidentity % beware, we need to construct
+ {\let\!!stringa\@@iakeyword % an unexpanded space separated
+ \let\@@iakeyword\empty % list of keywords from a comma
+ \def\doprepareidentity##1% % separated one
+ {\ifx\@@iakeyword\empty
+ \appended\def\@@iakeyword{##1}%
+ \else
+ \appended\def\@@iakeyword{ ##1}%
+ \fi}%
+ \@EA\processcommalist\@EA[\!!stringa]\doprepareidentity
+ \global\let\doprepareidentity\relax}
+
+%D The Creator field is changed per 12/04/2006 due to user presure. This
+%D means that I need to put my own status info someplace else.
+
+\def\initializeidentity
+ {\doprepareidentity
+ \dosetupidentity % no \expanded{..} will be done in special (else no pdfdoc)
+ {\@@iatitle}{\@@iasubtitle}{\@@iaauthor}%
+ {ConTeXt - \contextversion}%
+ {\@@iadate}{\@@iakeyword}%
+ \global\let\initializeidentity\relax}
+
+\appendtoks \initializeidentity \to \everyshipout
+
+\def\initializepaper
+ {\bgroup
+ \ifx\@@ppleft \empty
+ \ifx\@@ppright\empty
+ \ifx\@@pptop \empty
+ \ifx\@@ppbottom \empty
+ \ifx\@@pcstate\v!start
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi
+ \iflocation % without screen settings
+ \egroup
+ \dosetuppaper\papersize\paperwidth\paperheight
+ \else
+ \egroup
+ \dosetuppaper\printpapersize\printpaperwidth\printpaperheight
+ \fi}
+
+\appendtoks \initializepaper \to \everyshipout
+
+\def\doinitializepaper
+ {\bgroup
+ \docalculateinteractionscreen
+ \ifdim\!!widtha>\paperwidth\ifdim\!!widtha>\zeropoint
+ \paperwidth\!!widtha
+ \fi\fi
+ \ifdim\!!heighta>\paperheight\ifdim\!!heighta>\zeropoint
+ \paperheight\!!heighta
+ \fi\fi
+ \dosetuppaper
+ {\printpapersize}
+ {\the\paperwidth}
+ {\the\paperheight}%
+ \egroup}
+
+\let\@@pcscreendata\empty
+
+\def\dosetupinteractionscreens % met a, b en \number
+ {\doifnot\@@pcstate\v!start\dodosetupinteractionscreens}
+
+\setvalue{\??sc\c!option\v!max }{1} % tzt share with driver
+\setvalue{\??sc\c!option\v!bookmark }{2} % tzt share with driver
+\setvalue{\??sc\c!option\v!fit }{3} % tzt share with driver
+\setvalue{\??sc\c!option\v!doublesided}{4} % tzt share with driver
+
+\def\dodosetupinteractionscreens % met a, b en \number
+ {\bgroup
+ \docalculateinteractionscreen
+ \!!counte=0\getvalue{\??sc\c!option\@@scoption}\relax
+ % niet waterdicht
+ \doifnot{\the\!!widtha\the\!!heighta}\@@pcscreendata
+ {\xdef\@@pcscreendata{\the\!!widtha\the\!!heighta}%
+ \showmessage\m!interactions1{\withoutpt\the\!!widtha,\withoutpt\the\!!heighta}}%
+ % needs to be split: dimensions for each page
+ % and mode per document and only once !
+ \dosetupscreen \backoffset\topoffset\!!widtha\!!heighta{\the\!!counte}%
+ \dosetupcropbox\backoffset\topoffset\!!widtha\!!heighta
+ \egroup}
+
+\def\dosetupinteractionscreen[#1]%
+ {\getparameters[\??sc][#1]%
+ \ifproductionrun
+ \let\initializepaper\doinitializepaper
+ \let\setupinteractionscreens\dosetupinteractionscreens
+ \fi}
+
+\appendtoks \setupinteractionscreens \to \everyfirstshipout % needed to get option=max etc working
+\appendtoks \setupinteractionscreens \to \everyshipout % needed for page/screen dimensions
+
+\def\setupinteractionscreen
+ {\dosingleempty\dosetupinteractionscreen}
+
+%D Due to requests I finally decided to support bookmarks, a
+%D driver dependant way of showing tables of content. The most
+%D simple way of support is hooking bookmark generation into
+%D the existing list mechanisms. That way users can generate
+%D bookmarks automatically, although its entirely valid to add
+%D bookmarks by defining alternative ones. These will be added
+%D at the appropriate place in the list.
+
+% \hoofdstuk{het eerste hoofdstuk}
+%
+% \bookmark {de eerste bookmark} % optional overruled hoofdstuk
+%
+% .... text ....
+%
+% \placebookmarks [hoofdstuk,paragraaf,subparagraaf,subsubparagraaf,mylist]
+% [open list]
+%
+% \bookmark[mylist]{whatever}
+
+\def\@@bookmark {bm::}
+\def\@@booklevel{bl::}
+\def\@@bookcount{bc::}
+
+\definelist[\@@bookmark]
+
+\newtoks\postponedbookmarks
+
+\def\flushpostponedbookmark
+ {\the\postponedbookmarks
+ \global\postponedbookmarks\emptytoks}
+
+\def\simplebookmark#1%
+ {\doglobal\prependtoks
+ \writetolist[\@@bookmark]{}{#1}%
+ \to\postponedbookmarks}
+
+\def\complexbookmark[#1]#2%
+ {\doglobal\appendtoks\writetolist[#1]{}{#2}\to\postponedbookmarks}
+
+\definecomplexorsimple\bookmark
+
+\newif\iftracebookmarks \tracebookmarksfalse
+
+\let\tracebookmarks\tracebookmarkstrue
+
+\def\placebookmarks
+ {\dodoubleempty\doplacebookmarks}
+
+\def\doplacebookmarks[#1][#2]%
+ {\iflocation
+ \iffirstargument
+ \bgroup
+ \ifsecondargument
+ \doifelse{#2}\v!all
+ {\edef\openbookmarklist{#1}}
+ {\edef\openbookmarklist{#2}}%
+ \else
+ \let\openbookmarklist\empty
+ \fi
+ \global\let\bookmarklevellist\empty
+ \def\bookmarklevelcount{0}%
+ \doprocessbookmarks[#1]\dogetbookmarkelement
+ \dolistelement{}{}{}{}{}{}% needed to finish the first pass
+ \doprocessbookmarks[#1]\doputbookmarkelement
+ \flushbookmark
+ \egroup
+ \else
+ \expanded{\placebookmarks\@EA[\getvalue{\??ih\v!content\c!list}]}%
+ \fi
+ \fi}
+
+\def\doprocessbookmarks[#1]#2%
+ {\let\dolistelement#2\relax
+ \scratchcounter\zerocount
+ \def\docommand##1%
+ {\advance\scratchcounter \plusone
+ \getlistlevel[##1]\listlevel{\the\scratchcounter}%
+ \setxvalue{\@@bookcount\the\scratchcounter}{1}%
+ \setxvalue{\@@booklevel##1}{\listlevel}}%
+ \processcommalist[#1]\docommand
+ \setxvalue{\@@bookcount0}{1}%
+ \global\chardef\currentbookmarklevel\zerocount
+ \global\chardef\previousbookmarklevel\zerocount
+ \doutilities{listentries,#1,\@@bookmark}\jobname{#1}\relax\relax}
+
+\def\dodogetbookmarkelement#1#2#3#4#5#6%
+ {\doifelsenothing{#1}
+ {\global\chardef\currentbookmarklevel\zerocount}
+ {\global\chardef\currentbookmarklevel\getvalue{\@@booklevel#1}\relax}%
+ \ifnum\currentbookmarklevel>\previousbookmarklevel
+ \setxvalue{\@@bookcount\the\currentbookmarklevel}{1}%
+ \else\ifnum\currentbookmarklevel<\previousbookmarklevel
+ \bgroup
+ \!!counta\previousbookmarklevel
+ \doloop
+ {\let\bookmarktag\empty
+ \!!countb\!!counta
+ \advance\!!countb \minusone
+ \dorecurse\!!countb
+ {\edef\bookmarktag
+ {\bookmarktag\getvalue{\@@bookcount\recurselevel}:}}%
+ \edef\bookmarklevelcount
+ {\getvalue{\@@bookcount\the\!!counta}}%
+ \xdef\bookmarklevellist
+ {\bookmarklevellist/\bookmarktag:\bookmarklevelcount/}%
+ \advance\!!counta \minusone
+ \ifnum\!!counta=\currentbookmarklevel
+ \exitloop
+ \fi}%
+ \egroup
+ \@EA\doglobal\@EA\increment\csname \@@bookcount\the\currentbookmarklevel\endcsname\relax
+ \else
+ \@EA\doglobal\@EA\increment\csname \@@bookcount\the\previousbookmarklevel\endcsname\relax
+ \fi\fi
+ \global\utilitydonetrue
+ \global\chardef\previousbookmarklevel\currentbookmarklevel}
+
+\def\getbookmarklevelcount
+ {\@EA\def\@EA\docommand\@EA[\@EA##\@EA1\@EA/\bookmarktag:##2/##3]%
+ {\def\bookmarklevelcount{##2}}%
+ \@EA\@EA\@EA\docommand\@EA\@EA\@EA[\@EA\bookmarklevellist\@EA/\bookmarktag:0/]}
+
+\def\dodoputbookmarkelement#1#2#3#4#5#6%
+ {\doifelsenothing{#1}
+ {\global\chardef\currentbookmarklevel\zerocount}
+ {\global\chardef\currentbookmarklevel\getvalue{\@@booklevel#1}\relax}%
+ \ifnum\currentbookmarklevel>\previousbookmarklevel
+ \setxvalue{\@@bookcount\the\currentbookmarklevel}{1}%
+ \else\ifnum\currentbookmarklevel<\previousbookmarklevel
+ \@EA\doglobal\@EA\increment\csname \@@bookcount\the\currentbookmarklevel\endcsname\relax
+ \else
+ \@EA\doglobal\@EA\increment\csname \@@bookcount\the\previousbookmarklevel\endcsname\relax
+ \fi\fi
+ \let\bookmarktag\empty
+ \!!countb\currentbookmarklevel
+ \dorecurse\!!countb
+ {\edef\bookmarktag
+ {\bookmarktag\getvalue{\@@bookcount\recurselevel}:}}%
+ \getbookmarklevelcount
+ \iftracebookmarks
+ \bgroup
+ \par
+ \bookmarktag\quad
+ \dorecurse\currentbookmarklevel{\quad}\unskip#1\quad
+ (\bookmarklevelcount)\quad
+ \egroup
+ \fi
+ \global\chardef\previousbookmarklevel\currentbookmarklevel
+ \global\utilitydonetrue
+ \insertsomebookmark{#1}{\the\currentbookmarklevel}{\bookmarklevelcount}{#4}{#6}}
+
+\def\dogetbookmarkelement#1#2#3#4#5#6%
+ {\doifnot{#1}\@@bookmark
+ {\dodogetbookmarkelement{#1}{#2}{#3}{#4}{#5}{#6}}}
+
+\def\doputbookmarkelement#1#2#3#4#5#6%
+ {\doifelse{#1}\@@bookmark
+ {\localbookmark{#4}}
+ {\flushbookmark
+ \dodoputbookmarkelement{#1}{#2}{#3}{#4}{#5}{#6}}}
+
+\let\flushbookmark\relax
+\let\localbookmark\gobbleoneargument
+
+\def\insertsomebookmark#1#2#3#4#5%
+ {\gdef\flushbookmark
+ {\doinsertsomebookmark{#1}{#2}{#3}{#4}{#5}{g}}%
+ \gdef\localbookmark##1%
+ {\doinsertsomebookmark{#1}{#2}{#3}{##1}{#5}{l}}}
+
+\def\doinsertsomebookmark#1#2#3#4#5#6%
+ {\global\utilitydonetrue
+ \global\let\localbookmark\gobbleoneargument
+ \global\let\flushbookmark\relax
+ \doifinstringelse{#1}\openbookmarklist
+ {\chardef\openbookmark\plusone}
+ {\chardef\openbookmark\zerocount}%
+ \iftracebookmarks(#6: #4)\quad(\the\openbookmark)\par\fi
+ \doinsertbookmark{#2}{#3}{#4}{#5}{\openbookmark}}
+
+% \startinteractionmenu[rechts]
+% \but [eerste] eerste \\
+% \txt hello world \\
+% \but [tweede] tweede \\
+% \nop \\
+% \but [tweede] tweede \\
+% \rul whow \\
+% \but [tweede] tweede \\
+% \raw hello world \\
+% \but [tweede] tweede \\
+% \com \vfill \\
+% \but [derde] derde \\
+% \stopinteractionmenu
+
+\newif\iflocationmenupermitted
+
+\def\testinteractionmenu#1%
+ {\iflocation
+ \doifelse\@@iamenu\v!on
+ {\doifelsevalue{\??am#1\c!state}\v!start
+ {\global\locationmenupermittedtrue}
+ {\global\locationmenupermittedfalse}}
+ {\global\locationmenupermittedfalse}%
+ \else
+ \global\locationmenupermittedfalse
+ \fi}
+
+\def\dodisableinteractionmenu[#1][#2][#3]%
+ {\def\dododisableinteractionmenu##1%
+ {\doifelse{#3}{}
+ {\letvalue{\??am##1\c!obstruction}\empty}
+ {\edef\interactieblokkade{\getvalue{\??am##1\c!obstruction}}
+ \def\docommand####1{#1{####1}{\interactieblokkade}}% #1 = \remove or \add
+ \processcommalist[#3]\docommand
+ \setevalue{\??am##1\c!obstruction}{\interactieblokkade}}}%
+ \processcommalist[#2]\dododisableinteractionmenu}
+
+\def\disableinteractionmenu
+ {\dotripleempty\dodisableinteractionmenu[\addtocommalist]}
+
+\def\enableinteractionmenu
+ {\dotripleempty\dodisableinteractionmenu[\removefromcommalist]}
+
+% ja : kader/achtergrond met tekst
+% leeg : kader/achtergrond maar geen tekst
+% nee : alleen ruimte reserveren
+% geen : helemaal weglaten
+
+\newif\iflocationdummy
+\newif\ifskippedmenuitem
+
+\newif\iflocationempty
+\newif\iflocationclick
+
+% ja : kader/achtergrond met tekst
+% leeg : kader/achtergrond maar geen tekst
+% nee : alleen ruimte reserveren
+% geen : helemaal weglaten
+%
+% \setupinteractionmenu[right][samepage=yes, unknownreference=yes]
+% \setupinteractionmenu[right][samepage=empty,unknownreference=empty]
+% \setupinteractionmenu[right][samepage=no, unknownreference=no]
+% \setupinteractionmenu[right][samepage=none, unknownreference=none]
+%
+% \startinteractionmenu[right]
+% \but [firstpage] first \\
+% \but [lastpage] last \\
+% \but [somepage] crap \\
+% \stopinteractionmenu
+
+\def\dosetlocationboxcontent#1[#2]#3[#4]%
+ {\global\skippedmenuitemfalse
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}%
+ \iflocationclick
+ \hbox{\gotolocation{#4}{\box\locationbox}}%
+ \else
+ \hbox{\box\locationbox}%
+ \fi}
+
+\let\dosetlocationboxyes\dosetlocationboxcontent
+
+\def\dosetlocationboxempty#1[%
+ {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,}
+
+\def\dosetlocationboxno#1[%
+ {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,\c!frame=,\c!background=,}
+
+\def\dosetlocationboxnone#1[#2]#3[#4]%
+ {\global\skippedmenuitemtrue}
+
+\def\setlocationboxyes#1[#2]#3[#4]%
+ {\locationclicktrue
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \global\skippedmenuitemfalse
+ \gotolocation
+ {#4}% % needed
+ {\ifrealreferencepage
+ \ifcase\csname\??am\??am\csname#1\c!samepage\endcsname\endcsname\relax
+ \copycsname#1\c!color\endcsname\csname#1\c!contrastcolor\endcsname
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \global\skippedmenuitemtrue
+ \fi
+ \else
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \fi}}%
+ \ifskippedmenuitem\else\box\locationbox\fi}
+
+\def\setlocationboxnop#1[#2]#3[#4]%
+ {\locationclickfalse
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \global\skippedmenuitemfalse
+ \ifcase\csname\??am\??am\csname#1\c!unknownreference\endcsname\endcsname\relax
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \global\skippedmenuitemtrue
+ \fi}%
+ \ifskippedmenuitem\else\box\locationbox\fi}
+
+\def\setlocationboxraw#1[#2]#3[#4]%
+ {\localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}
+
+\def\setlocationbox#1[#2]#3[#4]%
+ {\bgroup % really needed !
+ \edef\permittedreferences{\csname#1\c!obstruction\endcsname}%
+ \doifreferencepermittedelse{#4}%
+ {\setlocationboxyes{#1}[#2]{#3}[#4]}%
+ {\setlocationboxnop{#1}[#2]{#3}[#4]}%
+ \egroup}
+
+\def\setlocationnop#1[#2]#3%
+ {\localframed[#1][#2]{#3}}
+
+\def\executeamboxcommands#1#2#3#4#5%
+ {%\processaction
+ % [\getvalue{\??am#1\c!dummy}]
+ % [ \v!yes=>\chardef\handleunknownmenuitem=0\relax,
+ % \v!empty=>\chardef\handleunknownmenuitem=1\relax,
+ % \v!no=>\chardef\handleunknownmenuitem=2\relax]%
+ \getvalue{\??am#1#3}\relax
+ \setamboxcommands{#1}{#4}%
+ \ignorespaces#2\unskip
+ \getvalue{\??am#1#5}}
+
+\newcounter\currentamposition
+
+\newtoks\everysetmenucommands
+
+\def\setamboxcommands#1#2%
+ {\def\currentmenu{#1}% % kan nog eerder
+ \def\currentsubmenu{#2}% % ? ?
+ \doglobal\newcounter\currentamposition
+ \the\everysetmenucommands}
+
+\def\menu@@amboxcommand#1\\%
+ {\dontleavehmode
+ \bgroup
+ \ignorespaces#1\unskip\relax
+ \ifskippedmenuitem \else
+ \getvalue{\??am\currentmenu\currentsubmenu}%
+ \fi
+ \egroup
+ \ignorespaces}
+
+\appendtoks
+ \let\@@amboxcommand\menu@@amboxcommand
+\to \everysetmenucommands
+
+\def\menu@raw[#1]#2\\%
+ {\@@amboxcommand\gotobox{\ignorespaces#2\unskip}[#1]\\}%
+
+\def\menu@but[#1]#2\\%
+ {\@@amboxcommand\do@@amposition\currentmenu{#1}{\setlocationbox{\??am\currentmenu}[]{\ignorespaces#2\unskip}[#1]}\\}%
+
+\def\menu@got[#1]#2\\% pas op! offset
+ {\@@amboxcommand\setlocationbox{\??am\currentmenu}[\c!frame=\v!off,\c!background=]{\ignorespaces#2\unskip}[#1]\\}%
+
+\def\menu@nop#1\\%
+ {\@@amboxcommand\setlocationboxraw{\??am\currentmenu}[\c!frame=\v!off,\c!background=,\c!empty=\v!yes]{\ignorespaces#1\unskip}[]\\}%
+
+\def\menu@txt#1\\%
+ {\@@amboxcommand\localframed[\??am\currentmenu][\c!frame=\v!off,\c!background=]{\ignorespaces#1\unskip}\\}%
+
+\def\menu@rul#1\\% ook \do@@amposition !
+ {\@@amboxcommand\localframed[\??am\currentmenu][]{\ignorespaces#1\unskip}\\}%
+
+\def\menu@com#1\\%
+ {\ignorespaces#1\unskip\ignorespaces}%
+
+\appendtoks
+ \let\raw\menu@raw
+ \let\but\menu@but
+ \let\got\menu@got
+ \let\nop\menu@nop
+ \let\txt\menu@txt
+ \let\rul\menu@rul
+ \let\com\menu@com
+\to \everysetmenucommands
+
+\ifx\do@@amposition\undefined
+ \let\do@@amposition\gobbletwoarguments % hook for positional thingies
+\fi
+
+\let\currentmenu\empty
+
+% beware : never change the concept of pbgoffset
+
+\def\menuparameter#1{\csname\??am\currentmenu#1\endcsname}
+
+\def\@@amhbox#1#2#3#4%
+ {\def\currentmenu{#3}%
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \bgroup
+ \showcomposition
+ \scratchdimen\dimexpr
+ \makeupwidth
+ +\pagebackgroundhoffset
+ +\pagebackgroundhoffset
+ -\menuparameter\c!leftoffset
+ -\menuparameter\c!rightoffset
+ \relax
+ \setbox\scratchbox\hbox to \scratchdimen
+ {\forgetall\executeamboxcommands{#3}{#4}\c!left\c!middle\c!right}%
+ \setbox\scratchbox\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}%
+ \wd\scratchbox\makeupwidth % geen \ht=#2 setting (yet)
+ \hskip\dimexpr-\pagebackgroundhoffset+\menuparameter\c!leftoffset\relax
+ \box\scratchbox
+ \egroup
+ \else
+ #1\relax
+ \fi}
+
+\def\@@amvbox#1#2#3#4% don't change skipping, this one works!
+ {\def\currentmenu{#3}%
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \bgroup
+ \showcomposition
+ \scratchdimen\dimexpr
+ \textheight
+ +\pagebackgroundvoffset
+ +\pagebackgroundvoffset
+ +\pagebackgrounddepth
+ -\menuparameter\c!topoffset
+ -\menuparameter\c!bottomoffset
+ \relax
+ \setbox\scratchbox\vbox to \scratchdimen
+ {\forgetall % Voor't geval de afstand
+ %\setupblank[\v!standard]% % (tijdelijk) is aangepast.
+ \restorestandardblank
+ \hsize#2\relax
+ \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after}%
+ \setbox\scratchbox\vbox{\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}}%
+ \setbox\scratchbox\vbox
+ {\ht\scratchbox\zeropoint
+ \vskip\dimexpr-\pagebackgroundvoffset+\menuparameter\c!topoffset\relax
+ \box\scratchbox
+ \vskip\pagebackgroundvoffset}% overbodig
+ \ht\scratchbox\textheight
+ \wd\scratchbox#2\relax
+ \box\scratchbox
+ \egroup
+ \else
+ #1\relax
+ \fi}
+
+\ifx\do@@ammenuposition\undefined
+ \let\do@@ammenuposition\gobbleoneargument % hook for positional thingies
+\fi
+
+\setvalue{\??am\s!do\v!right }{\@@amvbox{\dodummypageskip\v!right }\rightedgewidth}
+\setvalue{\??am\s!do\v!left }{\@@amvbox{\dodummypageskip\v!left }\leftedgewidth }
+\setvalue{\??am\s!do\v!top }{\@@amhbox{\dodummypageskip\v!top }\topheight }
+\setvalue{\??am\s!do\v!bottom}{\@@amhbox{\dodummypageskip\v!bottom}\bottomheight }
+
+\def\dointeractionmenu#1#2%
+ {\getvalue{\??am\s!do\getvalue{\??am#1\c!location}}{#1}{#2}}
+
+\unexpanded\def\interactionmenu[#1]%
+ {\getvalue{\??am\c!menu#1}}
+
+\def\horizontalinteractionmenu#1#2#3#4%
+ {\ifdim#2>\zeropoint % new
+ \scratchdimen\zeropoint
+ \setbox\scratchbox\hbox
+ {\def\docommand##1%
+ {\doifnotvalue{\??am##1\c!state}\v!none
+ {\hskip\scratchdimen
+ \setbox2\hbox to #2
+ {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
+ \doifelsevalue{\??am##1\c!distance}\v!overlay
+ {\scratchdimen\zeropoint
+ \wd2\zeropoint}%
+ {\scratchdimen\getvalue{\??am##1\c!distance}}%
+ \box2}}%
+ \startinteraction
+ \processcommacommand[\getvalue{\??am#1}]\docommand
+ \stopinteraction}%
+ \wd\scratchbox#2\relax
+ \box\scratchbox
+ \fi}
+
+\def\verticalinteractionmenu#1#2#3#4%
+ {\ifdim#2>\zeropoint % new
+ \scratchdimen\zeropoint
+ \setbox\scratchbox\vbox
+ {\def\docommand##1%
+ {\doifnotvalue{\??am##1\c!state}\v!none
+ {\vskip\scratchdimen
+ \setbox2\vbox to #2
+ {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
+ \doifelsevalue{\??am##1\c!distance}\v!overlay
+ {\scratchdimen\zeropoint
+ \offinterlineskip
+ \dp2\zeropoint
+ \ht2\zeropoint}%
+ {\scratchdimen\getvalue{\??am##1\c!distance}}%
+ \box2}}%
+ \startinteraction
+ \processcommacommand[\getvalue{\??am#1}]\docommand
+ \stopinteraction}%
+ \ht\scratchbox#2\relax
+ \dp\scratchbox\zeropoint
+ \box\scratchbox
+ \fi}
+
+\letvalue{\??am\v!left }\empty
+\letvalue{\??am\v!right}\empty
+\letvalue{\??am\v!top }\empty
+\letvalue{\??am\v!bottom }\empty
+
+% todo : \defineinteractionmenuclass
+
+\def\interactionmenus[#1]%
+ {\iflocation
+ \getvalue{\??am\??am\c!menu#1}%
+ \else
+ \dodummypageskip{#1}%
+ \fi}
+
+\setvalue{\??am\??am\c!menu\v!left }{\horizontalinteractionmenu\v!left \leftedgewidth \c!left \c!right}
+\setvalue{\??am\??am\c!menu\v!right }{\horizontalinteractionmenu\v!right \rightedgewidth\c!left \c!right}
+\setvalue{\??am\??am\c!menu\v!top }{\verticalinteractionmenu \v!top \topheight \c!before\c!after}
+\setvalue{\??am\??am\c!menu\v!bottom}{\verticalinteractionmenu \v!bottom\bottomheight \c!before\c!after}
+
+% this can be implemented with the following command (which
+% is new, undocumented, experimental, untested, etc etc)
+
+\def\defineinteractionmenuclass
+ {\dodoubleargument\dodefineinteractionmenuclass}
+
+\def\dodefineinteractionmenuclass[#1][#2]% tag hori|veri
+ {\doifelse{#2}\v!vertical
+ {\setvalue{\??am\??am\c!menu#1}{\verticalinteractionmenu {#1}{\getvalue{\??am#1\c!width }}\c!before\c!after}}
+ {\setvalue{\??am\??am\c!menu#1}{\horizontalinteractionmenu{#1}{\getvalue{\??am#1\c!height}}\c!left\c!right }}}
+
+% \setupinteraction[menu=on,state=start]
+%
+% \defineinteractionmenuclass[test] [vertical]
+% \defineinteractionmenuclass[another][horizontal]
+%
+% \defineinteractionmenu[test] [left][state=start,width=4cm]
+% \defineinteractionmenu[another][top] [state=start,height=1cm]
+%
+% \startinteractionmenu[test]
+% \but [firstpage] test-a \\
+% \but [nextpage] test-b \\
+% \stopinteractionmenu
+%
+% \startinteractionmenu[another]
+% \but [firstpage] test-a \\
+% \but [nextpage] test-b \\
+% \stopinteractionmenu
+%
+% \setupheadertexts[{\interactionmenu[another]}]
+%
+% \starttext
+%
+% test \interactionmenu[test] \page
+% test \interactionmenu[test] \page
+%
+% \stoptext
+
+%D This can save complicated menu macros when one want to
+%D keep control over parts of a menu (i.e.\ turn them on and
+%D off). We could have achieved something similar with modes.
+
+\def\local@@ambox#1#2#3#4% don't change skipping, this one works!
+ {\bgroup
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after
+ \else
+ #1\relax
+ \fi
+ \egroup}
+
+\def\includemenu[#1]%
+ {\doifvalue{\??am#1\c!state}\v!local
+ {\bgroup
+ \letvalue{\??am#1\c!state}\v!start
+ \let\@@amvbox\local@@ambox
+ \let\@@amhbox\local@@ambox
+ \getvalue{\??am\c!menu#1}%
+ \egroup}}
+
+%D We also need an explicit position control some day. I'll
+%D do that when I need it. [The stacking order.]
+
+\newif\ifextendedmenu
+
+% [name] [location]
+% [name] [location] [pars]
+
+\def\defineinteractionmenu
+ {\dotripleempty\dodefineinteractionmenu}
+
+\def\dodefineinteractionmenu[#1][#2][#3]%
+ {% main settings
+ \letvalue{\??am\c!menu#1}\empty
+ \setvalue{\@@dodolistelement#1}{\def\dosomelistelement{\dodomenulistelement{#1}}}%
+ \presetlocalframed[\??am#1]%
+ % register location
+ \expanded{\addtocommalist{#1}\@EA\noexpand\csname\??am#2\endcsname}%
+ % inherit settings
+ \doifnot{#1}{#2}
+ {\copyparameters[\??am#1][\??am#2]
+ [\c!left,\c!middle,\c!right,\c!before,\c!after,\c!inbetween,%
+ \c!width,\c!height,\c!distance,\c!offset,%
+ \c!frame,\c!framecolor,\c!rulethickness,%
+ \c!background,\c!backgroundcolor,\c!backgroundscreen,%
+ \c!style,\c!color,\c!contrastcolor,\c!samepage,\c!unknownreference,%
+ \c!leftoffset,\c!rightoffset,\c!topoffset,\c!bottomoffset]}%
+ % additional settings
+ \getparameters[\??am#1][\c!location=#2,\c!obstruction=,#3]}
+
+\def\setupinteractionmenu
+ {\dodoubleargument\dosetupinteractionmenu}
+
+\def\dosetupinteractionmenu[#1][#2]%
+ {\def\docommand##1{\getparameters[\??am##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\expandafter\chardef\csname\??am\??am\v!yes \endcsname\zerocount
+\expandafter\chardef\csname\??am\??am\v!empty\endcsname\plusone
+\expandafter\chardef\csname\??am\??am\v!no \endcsname\plustwo
+\expandafter\chardef\csname\??am\??am\v!none \endcsname\plusthree
+\expandafter\chardef\csname\??am\??am \endcsname\plusone % default
+
+\processbetween{\v!interactionmenu}\dostartinteractionmenu
+
+\def\dostartinteractionmenu#1%
+ {\dodostartinteractionmenu#1\dodostopinteractionmenu}
+
+\def\dodostartinteractionmenu[#1]#2\dodostopinteractionmenu
+ {\setvalue{\??am\c!menu#1}{\extendedmenutrue\dointeractionmenu{#1}{#2}}}
+
+\def\resetinteractionmenu[#1]%
+ {\letvalue{\??am\c!menu#1}\empty}
+
+\def\dodomenulistelement#1#2#3#4#5#6#7%
+ {\setbox0=\hbox
+ {\let\gotolocation\gobbleoneargument % hack to catch last []
+ %\locationclickfalse % ipv ^
+ \docheckrealreferencepage{#7}%
+ \setlocationboxyes
+ {\??am#1}% % needed !
+ []% no settings
+ {\limitatetext{#5}{\getvalue{\??li#2\c!maxwidth}}{\unknown}}% % needed !
+ []}% normally the destination, catch by gobble
+ \@@amboxcommand\do@@amposition{#1}{#7}% beware, we pass the pagenumber
+ {\ignorespaces\linklisttoelement{#3}{#6}{#7}{\box0}\unskip}\\}
+
+% \scherm moet worden als \page
+
+\def\screen
+ {\dosingleempty\doscreen}
+
+\def\doscreen[#1]%
+ {\iflocation\page[#1]\fi}
+
+\unexpanded\def\menubutton
+ {\dodoubleempty\domenubutton}
+
+\def\domenubutton[#1]%
+ {\iffirstargument
+ \ifsecondargument
+ \@EAEAEA\domenubuttonB
+ \else
+ \doifassignmentelse{#1}
+ {\@EAEAEA\domenubuttonC}
+ {\@EAEAEA\domenubuttonD}%
+ \fi
+ \else
+ \@EA\domenubuttonA
+ \fi[#1]}
+
+\def\domenubuttonA[#1][#2]#3[#4]% normal button, no parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox\??bt[]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonB[#1][#2]#3[#4]% menu button, with parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox{\??am#1}[#2]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonC[#1][#2]#3[#4]% normal button, with parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox\??bt[#1]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonD[#1][#2]#3[#4]% menu button, no parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox{\??am#1}[]{#3}[#4]%
+ \egroup}
+
+\def\menubox
+ {\dodoubleempty\domenubox}
+
+\def\domenubox[#1][#2]#3%
+ {\bgroup
+ \let\setlocationbox\setlocationboxraw
+ \domenubutton[#1][#2]#3[]%
+ \egroup}
+
+% Hier volgen de synchronisatiemacro's:
+
+\def\syncprefix{sync}
+
+%def\syncmarker{syncmark}
+%\definemarking[\syncmarker]
+%\setupmarking[\syncmarker][\c!expansie=\v!ja]
+
+\newmark\syncmarker
+
+\newcounter\synccounter
+
+\newif\ifsynchronisation
+
+\def\startsynchronization%
+ {\iflocation\ifsynchronisation
+ \doglobal\increment\synccounter
+ \fi\fi}
+
+\def\stopsynchronization%
+ {\iflocation\ifsynchronisation
+ %\thisisdestination{\syncprefix:\synccounter}%
+ \pagereference[\syncprefix:\synccounter]%
+ \ifvmode
+ \@EA\setmark\@EA\syncmarker\@EA{\synccounter} % \marking[\syncmarker]{\synccounter}%
+ \else
+ \showmessage\m!interactions4\synccounter
+ \fi
+ \fi\fi}
+
+\def\synchronize%
+ {\startsynchronization
+ \stopsynchronization}
+
+\def\dosetupsynchronization[#1]%
+ {\getparameters[\??sy][#1]%
+ \doifelse\@@systate\v!start
+ \synchronisationtrue
+ \synchronisationfalse}
+
+\def\setupsynchronization
+ {\dosingleargument\dosetupsynchronization}
+
+\def\definesynchronization
+ {\dosingleargument\dodefinesynchronization}
+
+\def\setupsynchronizationbar
+ {\dodoubleargument\getparameters[\??ba]}
+
+\presetlocalframed[\??ba]
+
+\setvalue{synchronisatie\v!page}[#1]%
+ {\bgroup
+ %\setupinteraction[\c!width=\!!zeropoint]%
+ \setinteractionparameter\c!width\!!zeropoint
+ \setbox0\hbox
+ {\localframed[\??ba][]{\dolocationattributes\??ba\c!style\c!color{\strut\@@batext}}}%
+ \dontcomplain
+ \def\atthebottom
+ {\leaders\hrule\!!depth1ex\!!height-.5ex\hfil}%
+ \def\atthetop##1##2##3%
+ {\dimen0=\wd0
+ \divide\dimen0 3
+ \multiply\dimen0 ##2\relax
+ \dimen2=.25em % brrr
+ \advance\dimen0 -##3\dimen2
+ %\gotodestination
+ % {}{#1}{\syncprefix:##1}{}
+ % {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}}%
+ \gotobox
+ {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}%
+ [#1::\syncprefix:##1]}%
+ \hbox
+ {\def\check##1##2%
+ {\edef##2{0##1\syncmarker}%
+ \ifnum0##2=0 \def##2{1}\fi}%
+ \check\gettopmark\top
+ \check\getfirstmark\first
+ \check\getbotmark\bot
+ \setbox2\hbox to \wd0
+ {\ifnum\top=\first\relax
+ \ifnum\first=\bot\relax
+ \atthetop\first30\relax
+ \else
+ \atthetop\first21\hss\atthetop\bot11\relax
+ \fi
+ \else
+ \ifnum\first=\bot\relax
+ \atthetop\top11\hss\atthetop\first21\relax
+ \else
+ \atthetop\top11\hss\atthetop\first11\hss\atthetop\bot11\relax
+ \fi
+ \fi}%
+ \wd2=\zeropoint\box2
+ \box0\relax}%
+ \egroup}
+
+\setvalue{synchronisatie\v!local}[#1]%
+ {\bgroup
+ %\setupinteraction[\c!width=\!!zeropoint]%
+ \setinteractionparameter\c!width\!!zeropoint
+ \def\blackrule{\hbox{\vrule\!!height.5em\!!width.5em}}%
+ %\gotodestination
+ % {}{##1}{\syncprefix:#1}{0}
+ % {\color[\locationcolor\@@bacolor]{\blackrule}}%
+ \gotobox %
+ {\color[\locationcolor\@@bacolor]{\blackrule}}%
+ [#1::\syncprefix:\synccounter]%
+ \egroup}
+
+\def\synchronizationbar[#1][#2]%
+ {\iflocation\ifsynchronisation
+ \bgroup
+ \setupsynchronizationbar
+ [\c!text=\getvalue{doc:des:#1},#2]%
+ \getvalue{synchronisatie\@@baalternative}[#1]%
+ \egroup
+ \fi\fi}
+
+% A nice application of glue. All this code will be rewritten and
+% generalized.
+
+\newbox\interactionbarbox
+
+\newif\ifbarsymbol
+
+\def\dogotosomepage#1#2#3% nog checken !
+ {\checkreferences % nodig ??
+ \hbox
+ {\iflocation
+ \ifnum#3=\realpageno
+ #2%
+ \else
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
+ \fi
+ \else
+ #2%
+ \fi}}
+
+\def\dogotosomecontrastpage#1#2#3% nog checken, may replace previous
+ {\checkreferences % nodig ??
+ \hbox
+ {\iflocation
+ \ifnum#3=\realpageno
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!contrastcolor}{#2}}%
+ \else
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
+ \fi
+ \else
+ #2%
+ \fi}}
+
+\presetlocalframed[\??ib]
+
+\def\interactionbara % we need better control over contrastcolor
+ {\iflocation % maybe just use gotopage and set colors
+ \bgroup
+ \setinteractionparameter\c!width\zeropoint
+ \setupblackrules[\c!height=\v!max,\c!depth=\v!max]%
+ \!!widthb\dimexpr\@@ibwidth-2.75\emwidth\relax
+ \!!widtha\dimexpr\!!widthb/\lastpage\relax
+ \bgroup
+ \advance\realpageno\minusone
+ \ifvoid\interactionbarbox
+ \bgroup
+ \processaction
+ [\@@ibstep]
+ [ \v!small=>\scratchdimen.25\emwidth,
+ \v!medium=>\scratchdimen.5\emwidth,
+ \v!big=>\scratchdimen\emwidth,
+ \s!unknown=>\scratchdimen\!!widtha]%
+ \ifdim\!!widtha<\scratchdimen\relax
+ \!!counta\numexpr\scratchdimen/\!!widtha\relax
+ \else
+ \!!counta\@@ibstep\relax
+ \fi
+ \!!widtha\!!counta\!!widtha
+ \setbox\scratchbox\hbox{\blackrule[\c!width=\!!widtha,\c!color=middlegray]}% color here, else no mkiv
+ \global\setbox\interactionbarbox\hbox to \!!widthb
+ {\hss
+ \dostepwiserecurse\plusone\lastpage\!!counta
+ {\gotorealpage\empty\empty\recurselevel{\copy\scratchbox}}%
+ \hss}%
+ \global\wd\interactionbarbox\zeropoint
+ \egroup
+ \fi
+ \egroup
+ \noindent
+ \strut
+ \hbox to \@@ibwidth
+ {\dontcomplain
+ \setupblackrules[\c!width=\emwidth]%
+ \dogotosomecontrastpage\??ib\blackrule\firstpage
+ \hss
+ \copy\interactionbarbox
+ \hbox to \!!widthb
+ {\ifdim\!!widtha<\emwidth
+ \!!widtha\emwidth
+ \fi
+ \setupblackrules[\c!width=\!!widtha]%
+ \ifnum\realpageno>\plusone
+ \!!counta\numexpr\realpageno-\plustwo\relax
+ \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
+ \dogotosomepage\??ib\blackrule\prevpage
+ \fi
+ \dogotosomecontrastpage\??ib{\blackrule[\c!width=.5em]}\realpageno
+ \ifnum\realpageno<\lastpage\relax
+ \dogotosomepage\??ib\blackrule\nextpage
+ \!!counta\numexpr\lastpage-\realpageno-\plusone\relax
+ \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
+ \fi}%
+ \hss
+ \dogotosomecontrastpage\??ib\blackrule\lastpage}%
+ \egroup
+ \fi}
+
+\def\interactionbarb
+ {\ifnum\lastpage>\firstpage\relax
+ \interactionbuttons[\v!firstpage,\v!previouspage,\v!nextpage,\v!lastpage]%
+ \fi}
+
+\def\interactionbarc
+ {\iflocation
+ \ifnum\lastpage>\plusone
+ \hbox to \@@ibwidth
+ {\setupblackrules[\c!height=\@@ibheight,\c!depth=\@@ibdepth]%
+ \scratchdimen\dimexpr(\@@ibwidth-4\emwidth)/\numexpr\lastpage+\minusone\relax\relax
+ \!!widtha\numexpr\realpageno+\minusone\relax\scratchdimen
+ \!!widthb\numexpr\lastpage-\realpageno\relax\scratchdimen
+ \startcolor[\locationcolor\@@ibcolor]%
+ \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\firstpage
+ \hss
+ \dogotosomepage\empty{\blackrule[\c!width=\!!widtha]}\prevpage
+ \color[\@@ibcontrastcolor]{\blackrule[\c!width=\emwidth]}%
+ \dogotosomepage\empty{\blackrule[\c!width=\!!widthb]}\nextpage
+ \hss
+ \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\lastpage
+ \stopcolor}%
+ \fi
+ \fi}
+
+\def\interactionbard
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \hbox \bgroup
+ \setinteractionparameter\c!width\!!zeropoint
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi]}}%
+ \else
+ \def\dogotox##1%
+ {\hbox{\vrule\!!height\@@ibheight\!!depth \@@ibdepth\!!width \@@ibwidth}}%
+ \fi
+ \dostepwiserecurse\plusone\nofsubpages\plusone
+ {\bgroup
+ \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
+ \ifnum\scratchcounter<\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
+ \else\ifnum\scratchcounter=\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
+ \fi\fi
+ \egroup
+ \hskip\@@ibdistance}%
+ \unskip % not needed
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbare% KAN WORDEN GECOMBINEERD MET D
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \bgroup
+ \!!widthb\dimexpr\nofsubpages\dimexpr\@@ibdistance\relax-\@@ibdistance\relax % (n-1)
+ \!!widtha\dimexpr(\@@ibwidth-\!!widthb)/\nofsubpages\relax
+ \ifdim\!!widtha<\@@ibdistance\relax
+ \interactionbarf
+ \else
+ \setinteractionparameter\c!width\!!zeropoint
+ \noindent
+ \hbox to \@@ibwidth
+ \bgroup
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi}}%
+ \else
+ \def\dogotox##1%
+ {\hbox{\vrule\!!height\@@ibheight\!!depth\@@ibdepth\!!width\!!widtha}}%
+ \fi
+ \dostepwiserecurse\plusone\nofsubpages\plusone
+ {\bgroup
+ \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
+ \ifnum\scratchcounter<\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
+ \else\ifnum\scratchcounter=\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
+ \fi\fi
+ \egroup
+ \hss}%
+ \unskip
+ \egroup
+ \fi
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbarf % !! KAN WORDEN GECOMBINEERD MET D !!
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \setinteractionparameter\c!width\!!zeropoint
+ \noindent
+ \hbox to \@@ibwidth
+ \bgroup
+ \!!countb\zerocount
+ \loop % todo: \doloop
+ \advance\!!countb \plusone
+ %\!!countc\nofsubpages \divide\!!countc \!!countb \advance\!!countc \plusone
+ \!!countc\numexpr(\nofsubpages/\!!countb)+\plusone\relax % rounding
+ \!!widthb\@@ibdistance
+ \multiply\!!widthb \!!countc
+ \advance\!!widthb -\@@ibdistance
+ \!!widtha\@@ibwidth
+ \advance\!!widtha -\!!widthb
+ \divide\!!widtha \!!countc
+ \ifdim\!!widtha<\@@ibdistance\relax
+ \repeat
+ \ifnum\!!countc>\plusone
+ % this is not that well tested
+ \advance\!!countc \minustwo
+ \!!widtha-\@@ibdistance
+ \!!widtha\!!countc\!!widtha
+ \advance\!!widtha \@@ibwidth
+ \advance\!!countc \plusone
+ \divide\!!widtha \!!countc
+ \fi
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!somewhere\or\v!somewhere\or\v!next\fi}}%
+ \else
+ \def\dogotox##1%
+ {\hbox
+ {\!!heighta\@@ibheight
+ \!!deptha\@@ibdepth
+ \ifcase##1\relax
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \fi}}%
+ \fi
+ \!!countc\numexpr\realpageno-\plustwo\relax
+ \!!countd\numexpr\realpageno+\plustwo\relax
+ \ifnum\!!countc<\plusone \!!countc\plusone \fi
+ \!!countf\zerocount
+ \dostepwiserecurse\firstsubpage\lastsubpage\plusone
+ {\!!doneafalse
+ \advance\!!countf \plusone
+ \ifnum\recurselevel=\firstsubpage\relax \!!doneatrue \fi
+ \ifnum\recurselevel=\lastsubpage\relax \!!doneatrue \fi
+ \if!!donea
+ \ifnum\recurselevel<\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox0}\recurselevel
+ \else\ifnum\recurselevel>\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox4}\recurselevel
+ \fi\fi
+ \hss
+ \!!countf\zerocount
+ \else\ifnum\!!countf=\!!countb
+ \ifnum\recurselevel<\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox1}\recurselevel
+ \else\ifnum\recurselevel>\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox3}\recurselevel
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
+ \fi\fi
+ \hss
+ \!!countf\zerocount
+ \fi\fi}%
+ \unskip
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbarg
+ {\ifnum\lastsubpage>\firstsubpage\relax
+ \interactionbuttons[\v!firstsubpage,\v!previoussubpage,\v!nextsubpage,\v!lastsubpage]%
+ \fi}
+
+\def\checkinteractionbar#1#2#3%
+ {\ifdim\@@ibwidth=\zeropoint\def\@@ibwidth{#1}\fi
+ \doifnothing\@@ibheight{\def\@@ibheight{#2}}%
+ \doifnothing\@@ibdepth{\def\@@ibdepth{#3}}}
+
+\def\complexinteractionbar[#1]%
+ {\doifelse{#1}\v!reset
+ {\global\setbox\interactionbarbox\emptybox}%
+ {\bgroup
+ \iflocation
+ \checksubpages % goes wrong / loads \numberofpages too
+ \getparameters[\??ib][#1]%
+ \doif\@@ibstate\v!start
+ {\startinteraction
+ \processaction % breedte defaults !
+ [\@@ibalternative]
+ [ c=>\checkinteractionbar{10em}\v!max \v!max,
+ d=>\checkinteractionbar{.5em}{.5em} \!!zeropoint,
+ e=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
+ f=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
+ \s!default=>\checkinteractionbar{10em}\v!broad\!!zeropoint,
+ \s!unknown=>\checkinteractionbar{10em}\v!broad\!!zeropoint]%
+ \doifelse\@@ibsymbol\v!yes
+ \barsymboltrue\barsymbolfalse
+ \getvalue{interactionbar\@@ibalternative}%
+ \stopinteraction}%
+ \fi
+ \egroup}}
+
+\definecomplexorsimpleempty\interactionbar
+
+\def\setupinteractionbar
+ {\dodoubleargument\getparameters[\??ib]}
+
+% Er wordt vooralsnog uitgegaan van een symmetrische
+% start-stop situatie.
+
+\def\c!profiel!! {profiel:} % brrr
+\def\c!versie!! {versie:}
+
+\def\dodefineprofile[#1][#2]%
+ {\iflocation
+ \def\dododefineprofile##1%
+ {\def\dodododefineprofile####1%
+ {\doifdefinedelse{\c!profiel!!####1}%
+ {\edef\!!stringa{\getvalue{\c!profiel!!####1}}%
+ \setevalue{\c!profiel!!####1}{\!!stringa,##1}}%
+ {\setevalue{\c!profiel!!####1}{##1}}}%
+ \processcommalist[#2]\dodododefineprofile}%
+ \processcommalist[#1]\dododefineprofile
+ \fi}
+
+\def\defineprofile%
+ {\dodoubleargument\dodefineprofile}
+
+% Als met \getpar wordt gewerkt, dan moet \next worden toegepast.
+
+% TZT initialisatie!
+
+\def\profilepage{}
+
+\let\dosetprofilepage\relax
+\let\dogetprofilepage\relax
+
+\def\processprofile#1[#2]%
+ {\iflocation
+ \par % needed for pdftex
+ \bgroup
+ \dosetprofilepage
+ \dogetprofilepage
+ \def\processoneprofile##1##2%
+ {\ExpandBothAfter\doifinsetelse{##2}{\processedprofiles}%
+ {\doifsomething{##1}{(##1)}}%
+ {\addtocommalist{##2}\processedprofiles
+ ##1\relax
+ \ifcase#1\relax
+ \dobeginofprofile{##2}\paperwidth\paperheight\profilepage
+ \else
+ \doendofprofile
+ \fi}}%
+ \let\processedprofiles\empty
+ \def\doprocessprofile##1%
+ {\doifelse{\@@pfoption}{\v!test}%
+ {\goodbreak\blank\nobreak\tt[\space
+ \ifcase#1\v!start\else\v!stop\fi profiel\space ##1:\space
+ \doifdefinedelse{\c!profiel!!##1}%
+ {\def\dodoprocessprofile####1%
+ {\processoneprofile
+ {\goto{####1}[\c!profiel!!####1]}%
+ {####1}%
+ \space}%
+ \processcommacommand
+ [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}%
+ {- }%
+ ]\nobreak\blank}%
+ {\doifdefined{\c!profiel!!##1}%
+ {\def\dodoprocessprofile####1%
+ {\processoneprofile{}{####1}}%
+ \processcommacommand
+ [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}}}%
+ \processcommalist[#2]\doprocessprofile
+ \egroup
+ \par % needed for pdftex
+ \fi}
+
+\def\startprofile[#1]%
+ {\iflocation
+ \bgroup
+ \addtocommalist{#1}\actualprofile
+ \def\stopprofile%
+ {\processprofile1[#1]%
+ \egroup}%
+ \def\next{\processprofile0[#1]}% % \DoAfterFi \processprofile0[#1]%
+ \else % ^^^^^^^^^^ will be obsolete
+ \let\next\relax % since ugly and never used
+ \fi
+ \next}
+
+\let\stopprofile\relax
+
+\def\dofollowprofile#1[#2]%
+ {\iflocation
+ \hbox
+ {\dohandlegoto
+ {\dolocationattributes\??ia\c!style\c!color{#1\presetgoto}}%
+ {\dostartgotoprofile\buttonwidth\buttonheight{#2}}%
+ {\dostopgotoprofile}}%
+ \else
+ {#1}%
+ \fi}
+
+\def\followprofile#1[#2]%
+ {\iflocation
+ \doif\@@pfoption\v!test{\pagereference[\c!profiel!!#2]}%
+ \dofollowprofile{#1}[#2]%
+ \fi}
+
+\def\setupprofiles%
+ {\dodoubleargument\getparameters[\??pf]}
+
+% Als er nog geen tekst op de pagina staat, dan heeft het
+% profiel betrekking op het bovenstaande, dus soms een vorige
+% pagina! Vreemd, omdat PDF paginagewijs werkt. Gelukkig
+% biedt /page een oplossing. Echter: expansie van een
+% \special kan niet worden uitgesteld, zodat alleen een
+% two-pass een oplossing vormt. Het onderstaande kan komen
+% te vervallen als Acrobat dit ondervangt. Het scheelt een
+% pass en een lijst.
+%
+% Er kunnen eventueel twee lijsten worden gebruikt. Een voor
+% het begin (start) en een voor het eind (stop). Nu staat
+% alles in een lijst.
+
+\definetwopasslist\s!profile
+
+\newcounter\currentprofile
+
+\def\dosetprofilepage%
+ {\doglobal\increment\currentprofile
+ \lazysavetwopassdata{\s!profile}{\currentprofile}{\noexpand\realfolio}}
+
+\def\dogetprofilepage%
+ {\gettwopassdata{\s!profile}%
+ \let\profilepage=\twopassdata}
+
+% is this stuff used at all
+
+\newcounter\versionlevel
+\newcounter\versionorder
+
+\newif\ifrecentversion
+
+\let\oldatcharacter=@
+
+\def\minimumversion{0}
+\def\actualversion{0}
+
+\def\dosetupversions[#1]%
+ {\getparameters[\??ve][#1]
+ \stripcharacter.\from\@@venumber\to\minimumversion}
+
+\def\setupversions
+ {\dosingleargument\dosetupversions}
+
+\definetwopasslist\s!versionbegin
+\definetwopasslist\s!versionend
+
+\let\actualprofile\empty
+
+\def\doresetpageversion
+ {\lazysavetwopassdata{\s!versionend}{\versionorder}{\noexpand\realfolio}}
+
+\def\dosetpageversion#1%
+ {\recentversiontrue
+ \doglobal\increment\versionorder\relax
+ \lazysavetwopassdata{\s!versionbegin}{\versionorder}{\noexpand\realfolio}%
+ \let\resetpageversion\doresetpageversion}
+
+\def\recentcontributions{}
+
+\def\checkrecentcontributions%
+ {\gettwopassdata{\s!versionbegin}%
+ \iftwopassdatafound
+ \!!counta\twopassdata\relax
+ \gettwopassdata{\s!versionend}%
+ \iftwopassdatafound
+ \!!countb\twopassdata\relax
+ \doglobal\increment\versionorder\relax
+ \savetwopassdata{\s!versionbegin}{\versionorder}{\the\!!counta}%
+ \savetwopassdata{\s!versionend }{\versionorder}{\the\!!countb}%
+ \dostepwiserecurse\!!counta\!!countb\plusone
+ {\@EA\doglobal\@EA\addtocommalist\@EA{\recurselevel}{\recentcontributions}}%
+ \let\next\checkrecentcontributions
+ \else
+ \let\next\relax
+ \fi
+ \else
+ \let\next\relax
+ \fi
+ \next}
+
+\def\docheckpageversion
+ {\ExpandBothAfter\doifinsetelse{\realfolio}{\recentcontributions}
+ {\pageselectedtrue}%
+ {\pageselectedfalse}}
+
+\let\setpageversion \gobbleoneargument
+\let\resetpageversion \relax
+\let\checkpageversion \relax
+
+\def\complexstartversion[#1]%
+ {\bgroup
+ \doifelsenothing\actualprofile
+ {\startprofile[#1]}%
+ {\startprofile[#1,\actualprofile]}%
+ \def\docomplexstartversie##1%
+ {\stripcharacter.\from##1\to\actualversion
+ \ifnum\versionlevel>\zerocount\relax
+ \ifnum\actualversion=\zerocount
+ \setpageversion\actualversion % unknown version
+ \else
+ \ifnum\actualversion<\minimumversion\relax
+ \relax % old version
+ \else
+ \setpageversion\actualversion % new version
+ \fi
+ \fi
+ \fi}%
+ \doglobal\increment\versionlevel\relax
+ \doifelsenothing{#1}
+ {\docomplexstartversie{0}}%
+ {\processcommalist[#1]\docomplexstartversie}}
+
+\definecomplexorsimpleempty\startversion
+
+\def\stopversion
+ {\stopprofile
+ \doglobal\decrement\versionlevel
+ \ifnum\versionlevel<\zerocount
+ \showmessage\m!versions1\empty
+ \else
+ \resetpageversion
+ \egroup
+ \fi}
+
+\def\markversion
+ {\showmessage\m!versions2\empty
+ \let\setpageversion\dosetpageversion
+ \let\resetpageversion\relax
+ \let\checkpageversion\relax}
+
+\def\selectversion
+ {\checkrecentcontributions
+ \showmessage\m!versions3\recentcontributions
+ \let\setpageversio\gobbleoneargument
+ \let\resetpageversion\relax
+ \let\checkpageversion\docheckpageversion}
+
+\def\dodefineversion[#1][#2]%
+ {\setvalue{\c!versie!!#1}{#2}%
+ \defineprofile[#1][#2]}
+
+\def\defineversion
+ {\dodoubleargument\dodefineversion}
+
+\def\followversion
+ {\followprofile}
+
+\def\followprofileversion#1[#2][#3]%
+ {\def\docommand##1%
+ {\defineprofile[#2#3][##1]}%
+ \processcommacommand[\getvalue{\c!versie!!#3}]\docommand
+ \followprofile#1[#2#3]}
+
+\newcounter\currentpagetransition
+
+\newif\ifrandomtransitions
+
+\def\setuppagetransitions%
+ {\dosingleempty\dosetuppagetransitions}
+
+\def\dosetuppagetransitions[#1]%
+ {\doifelsenothing{#1}
+ {\doifnot\@@scdelay\v!none
+ {\let\setpagetransition\setsomepagedelay}}
+ {\doifelse{#1}\v!start
+ {\doifnot\@@scdelay\v!none
+ {\let\setpagetransition\setsomepagedelay}}
+ {\doglobal\newcounter\currentpagetransition
+ \doifinsetelse{#1}{\v!reset,\v!stop}
+ {\let\setpagetransition\relax}
+ {\let\setpagetransition\setsomepagetransition
+ \doifinsetelse\v!random{#1}
+ {\randomtransitionstrue}{\randomtransitionsfalse}%
+ \edef\userpagetransitions{#1}%
+ \@EA\removefromcommalist\@EA{\v!random}\userpagetransitions
+ \ifx\userpagetransitions\empty
+ \let\userpagetransitions\pagetransitions
+ \fi}}}}
+
+\def\setsomepagedelay
+ {\expanded{\dosetpagetransition{0}{\@@scdelay}}}
+
+\def\setsomepagetransition
+ {\iflocation
+ \ifrandomtransitions
+ \expanded{\getcommalistsize[\userpagetransitions]}%
+ \getrandomnumber\currentpagetransition1\commalistsize
+ \else
+ \doglobal\increment\currentpagetransition
+ \fi
+ \expanded{\getfromcommalist[\userpagetransitions][\currentpagetransition]}%
+ \doifnumberelse\commalistelement
+ {\expanded{\getfromcommalist[\pagetransitions][\commalistelement]}}
+ {}%
+ \ifx\commalistelement\empty
+ \doglobal\newcounter\currentpagetransition
+ \setsomepagetransition
+ \else
+ \doifelse\@@scdelay\v!none
+ {\expanded{\dosetpagetransition{\commalistelement}{0}}}
+ {\expanded{\dosetpagetransition{\commalistelement}{\@@scdelay}}}%
+ \fi
+ \fi}
+
+\prependtoks \setpagetransition \to \everyshipout
+
+% temporary here
+
+%D \startbuffer
+%D \dorecurse{10}
+%D {\horizontalpositionbar
+%D \pos\recurselevel \min1 \max10
+%D \token\framed{\recurselevel}%
+%D \\}
+%D
+%D \hbox to 15em
+%D {\hss
+%D \dorecurse{10}
+%D {\verticalpositionbar\pos\recurselevel\min1\max10\token\blackrule\\
+%D \hss}}
+%D \stopbuffer
+
+\def\horizontalpositionbar\pos#1\min#2\max#3\token#4\\%
+ {\hbox to \hsize
+ {\hskip\zeropoint\!!plus #1\!!fill
+ \hskip\zeropoint\!!plus-#2\!!fill
+ #4\relax
+ \hskip\zeropoint\!!plus #3\!!fill
+ \hskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\verticalpositionbar\pos#1\min#2\max#3\token#4\\%
+ {\vbox to \vsize
+ {\vskip\zeropoint\!!plus #1\!!fill
+ \vskip\zeropoint\!!plus-#2\!!fill
+ \hbox{#4}\relax
+ \vskip\zeropoint\!!plus #3\!!fill
+ \vskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\horizontalgrowingbar\pos#1\min#2\max#3\height#4\depth#5\\%
+ {\hbox to \hsize
+ {\scratchcounter#1%
+ \advance\scratchcounter -#2%
+ \advance\scratchcounter \plusone
+ \leaders\vrule\hskip\zeropoint\!!plus \scratchcounter\!!fill
+ \vrule\!!width\zeropoint\!!height#4\!!depth#5%
+ \hskip\zeropoint\!!plus #3\!!fill
+ \hskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\verticalgrowingbar\pos#1\min#2\max#3\width#4\\%
+ {\vbox to \vsize
+ {\scratchcounter#1%
+ \advance\scratchcounter -#2%
+ \advance\scratchcounter \plusone
+ \leaders\hrule\vskip\zeropoint\!!plus\scratchcounter\!!fill
+ \hrule\!!width#4\!!height\zeropoint\!!depth\zeropoint
+ \vskip\zeropoint\!!plus #3\!!fill
+ \vskip\zeropoint\!!plus-#1\!!fill}}
+
+\newbox\commentbox
+
+\def\doflushcommentanchors
+ {\let\next\relax % new
+ \processaction
+ [\@@cclocation]
+ [% \v!text=>\let\next\relax, % new
+ \v!inmargin=>\let\next\inmargin, % brr not the same as inleft|rightmargin
+ \v!leftedge=>\let\next\inleftedge,
+ \v!rightedge=>\let\next\inrightedge,
+ \v!leftmargin=>\let\next\inleftmargin,
+ \v!rightmargin=>\let\next\inrightmargin]%
+ \next{\hbox{\raise\strutht\box\commentbox}}}
+
+\def\flushcommentanchors % in everypar so indirect
+ {\ifvoid\commentbox\else \doflushcommentanchors \fi}
+
+\def\setupcomment
+ {\dodoubleargument\getparameters[\??cc]}
+
+\setvalue{\e!start\v!comment}% the dummy triple gobbles trailing spaces
+ {\dotripleempty\dostartcommentaar}
+
+\def\comment
+ {\dodoubleempty\docomment}
+
+\def\dodocomment#1%
+ {\!!widtha\@@ccwidth
+ \!!heighta\@@ccheight
+ \doifelse\@@ccoption\v!max
+ {\let\@@ccopen \!!plusone}{\let\@@ccopen \!!zerocount}%
+ \doifelse\@@ccoption\v!buffer
+ {\let\@@cccollect\!!plusone}{\let\@@cccollect\!!zerocount}%
+ \preparecommentvariables
+ \doinsertcomment
+ \@@cctitle\!!widtha\!!heighta
+ \@@cccolor\@@ccopen\@@ccsymbol
+ \@@cccollect{#1}}
+
+\def\preparecommentvariables % more will move here as with fields
+ {\let\@@DriverCommentLayer\@@cctextlayer}
+
+\def\dopreparecommentaar#1#2%
+ {\doifassignmentelse{#1}
+ {\getparameters[\??cc][#1]}
+ {\getparameters[\??cc][\c!title=#1,#2]}%
+ \obeylines
+ \doif\@@ccspace\v!yes\obeyspaces}
+
+\def\dostartcommentaar[#1][#2][#3]%
+ {\bgroup
+ \doifelse\@@ccstate\v!start
+ {\dopreparecommentaar{#1}{#2}%
+ \long\def\docommand##1%
+ {\global\setbox\commentbox\frozenhbox
+ {\hbox to \zeropoint
+ {\struttedbox{\tbox{\dodocomment{##1}}}\hss}%
+ \hskip\ifvoid\commentbox\@@ccmargin\else\@@ccdistance\fi
+ \box\commentbox}%
+ \egroup}}%
+ {\long\def\docommand##1%
+ {\egroup}}%
+ \grabuntil{\e!stop\v!comment}\docommand}
+
+\letvalue{\e!stop\v!comment}\relax % handy for \expanded{...}
+
+\def\docomment[#1][#2]#3%
+ {\doif\@@ccstate\v!start
+ {\hbox to \zeropoint
+ {\dopreparecommentaar{#1}{#2}%
+ \hskip-\@@ccmargin
+ \struttedbox{\tbox{\dodocomment{#3}}\hss}}}%
+ \ignorespaces}
+
+% \startcomment
+% hello beautiful\\world
+% \stopcomment
+%
+% \startcomment[hello]
+% hello << \'e\'erste >>
+% beautiful
+% world
+% \stopcomment
+%
+% \startcomment[hello][color=green,width=4cm,height=3cm]
+% hello \leftguillemot\ \'e\'erste \rightguillemot\
+% beautiful
+% world
+% \stopcommentaar
+%
+% \startcomment[hello][color=green,width=4cm,height=3cm]
+% hello \leftguillemot\ \'e\'erste \rightguillemot\ test
+%
+% beautiful
+%
+% world
+% \stopcomment
+%
+% \startcomment[symbol=Balloon]
+% Do we want this kind of rubish? And, why isn't this and
+% some more features related to text annotations so poorly
+% (actually not) documented? Anyhow, by providing this
+% functionality we demonstrate that \pdfTeX\ can do it. By
+% the way, it's funny that when in Acrobat we scale up the
+% text, the symbols scale down.
+% \stopcomment
+
+% \definesymbol [comment-normal][{\externalfigure[cow.pdf]}]
+% \definesymbol [comment-down] [{\externalfigure[cow.pdf]}]
+%
+% \def\CowSymbol#1#2%
+% {\scale
+% [\c!height=#1]
+% {\startMPcode
+% loadfigure "koe.mp" number 1 ;
+% refill currentpicture withcolor #2 ;
+% \stopMPcode}}
+%
+% \definesymbol [comment-normal]
+% [\CowSymbol{4ex}{red}]
+%
+% \definesymbol [comment-down]
+% [\CowSymbol{4ex}{green}]
+%
+% \setupcomment
+% [\c!symbol={comment-normal,comment-down},
+% \c!option=\v!buffer]
+%
+% \setupfootertexts[\placecomments]
+
+\def\placecomments
+ {\doflushcomments}
+
+% \setupinteraction[state=start]
+%
+% \useattachment[test.tex]
+% \useattachment[whatever][test.tex]
+% \useattachment[whatever][newname][test.tex]
+% \useattachment[whatever][title][newname][test.tex]
+%
+% % \setupattachments[\c!symbol={symbol-normal,symbol-down}]
+%
+% \starttext \attachment[whatever] \stoptext
+
+\definesystemvariable{at}
+
+\def\useattachment
+ {\doquadrupleempty\douseattachment}
+
+\def\douseattachment[#1][#2][#3][#4]% tag title newname filename
+ {\iffourthargument
+ \setgvalue{\??at:#1}{{#2}{#3}{#4}}% tooltip kind of case
+ \else\ifthirdargument
+ \setgvalue{\??at:#1}{{#2}{#2}{#3}}% full path case
+ \else\ifsecondargument
+ \setgvalue{\??at:#1}{{#2}{#2}{#2}}% obvious case
+ \else
+ \setgvalue{\??at:#1}{{#1}{#1}{#1}}% worst case
+ \fi\fi\fi}
+
+\let\attachmenttitle\empty
+\let\attachmentname \empty
+\let\attachmentfile \empty
+
+\def\getattachmentdata[#1]%
+ {\edef\attachmenttitle{\filterfromvalue{\??at:#1}31}% description
+ \edef\attachmentname {\filterfromvalue{\??at:#1}32}% new name
+ \edef\attachmentfile {\filterfromvalue{\??at:#1}33}% original
+ \expandafter\splitstring\attachmentname\at.\to\!!stringa\and\!!stringb
+ \ifx\!!stringb\empty % no suffix, so we need to inherit it
+ \expandafter\splitstring\attachmentfile\at.\to\!!stringc\and\!!stringd
+ \edef\attachmentname{\attachmentname.\!!stringd}%
+ \fi}
+
+\def\attachment
+ {\dodoubleempty\doattachment}
+
+\def\doattachment[#1][#2]% currently title equals newname
+ {\iflocation
+ \ifsecondargument
+ \doifundefined{\??at:#2}
+ {\showmessage\m!interactions6{#2}%
+ \useattachment[#2]}%
+ \doif\@@atstate\v!start
+ {\bgroup
+ \getattachmentdata[#2]%
+ \doiffileelse\attachmentfile
+ {\setupattachments[#1]%
+ \presetattachmentvariables
+\struttedbox{\tbox{%
+ \doattachfile
+ \attachmenttitle
+ {1em}\strutheight\strutdepth\@@atcolor\@@atsymbol
+ \attachmentname
+ \attachmentfile}%
+}}%
+ {\showmessage\m!interactions5\attachmentfile}%
+ \egroup}%
+ \else\iffirstargument
+ \attachment[][#1]%
+ \fi\fi
+ \fi}
+
+\def\presetattachmentvariables
+ {\let\@@DriverAttachmentLayer\@@attextlayer}
+
+\def\setupattachments
+ {\dodoubleempty\getparameters[\??at]}
+
+\setupattachments
+ [\c!state=\v!start,
+ \c!color=\@@iacolor,
+ \c!textlayer=,
+ \c!symbol=]
+
+% jammer, tussen/midden had erin gemoeten; \c!commando toevoegen
+
+\def\registermenucommand#1%
+ {{\textonly\noindent#1\space}} % no math switching
+
+\def\doregistermenubuttons[#1][#2]% [menu id] [register]
+ {\bgroup
+ \ifsecondargument
+ \setupinteractionmenu
+ [#1][\c!unknownreference=\v!yes,\c!samepage=\v!yes]%
+ \def\docommand##1%
+ {\registermenucommand{\menubutton[#1]{##1}[#2:##1]}}%
+ \else
+ \def\docommand##1%
+ {\registermenucommand
+ {\button
+ [\c!unknownreference=\v!yes,\c!samepage=\v!yes]
+ {##1}[#1:##1]}}%
+ \fi
+ \handletokens abcdefghijklmnopqrstuvwxyz\with\docommand % moet anders
+ \egroup}
+
+\def\registermenubuttons
+ {\dodoubleempty\doregistermenubuttons}
+
+\stelkoppelingenin
+ [\c!distance=.25em,
+ \c!width=\v!fit,
+ \c!location=\v!low,
+ \c!color=\@@iacolor,
+ \c!frame=\v!off,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=]
+
+\defineinteractionmenu
+ [\v!right]
+ [\v!right]
+ [\c!before=,
+ \c!after=\vfil,
+ \c!inbetween=\blank,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!left=\hss,
+ \c!right=\hss,
+ \c!width=\rightedgewidth,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!left]
+ [\v!left]
+ [\c!before=,
+ \c!after=\vfil,
+ \c!inbetween=\blank,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!left=\hss,
+ \c!right=\hss,
+ \c!width=\leftedgewidth,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!bottom]
+ [\v!bottom]
+ [\c!before=\vss,
+ \c!after=\vss,
+ \c!middle=\hfil,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!width=\v!fit,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!top]
+ [\v!top]
+ [\c!before=\vss,
+ \c!after=\vss,
+ \c!middle=\hfil,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!width=\v!fit,
+ \c!height=\v!broad]
+
+\setupinteractionmenu
+ [\v!left,\v!right,\v!top,\v!bottom]
+ [\c!offset=.25em,
+ \c!position=\v!no,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundcolor=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!state=\v!start,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!empty,
+ \c!topoffset=\!!zeropoint,
+ \c!bottomoffset=\!!zeropoint,
+ \c!leftoffset=\!!zeropoint,
+ \c!rightoffset=\!!zeropoint]
+
+\def\placeleftedgetextblock % Is \hss/\hsize really needed here?
+ {\hbox to \leftedgewidth % (check outer level and settings)
+ {\hsize\leftedgewidth\hss\interactionmenus[\v!left]}}
+
+\def\placerightedgetextblock % Is \hss/\hsize really needed here?
+ {\hbox to \rightedgewidth % (check outer level and settings)
+ {\hsize\rightedgewidth\interactionmenus[\v!right]\hss}}
+
+\def\placetoptextblock
+ {\vbox to \topheight
+ {\vsize\topheight
+ \csname\??tk\v!top\c!before\endcsname
+ \interactionmenus[\v!top]%
+ \csname\??tk\v!top\c!after\endcsname
+ \kern\zeropoint}}
+
+\def\placebottomtextblock
+ {\vbox to \bottomheight
+ {\vsize\bottomheight
+ \csname\??tk\v!bottom\c!before\endcsname
+ \interactionmenus[\v!bottom]%
+ \csname\??tk\v!bottom\c!after\endcsname
+ \kern\zeropoint}}
+
+\ifx\leftedgetextcontent\undefined \else
+
+ \appendtoks \placeleftedgetextblock \hskip-\leftedgewidth \to \leftedgetextcontent
+ \appendtoks \placerightedgetextblock \hskip-\rightedgewidth \to \rightedgetextcontent
+ \appendtoks \placetoptextblock \vskip-\topheight \to \toptextcontent
+ \appendtoks \placebottomtextblock \vskip-\bottomheight \to \bottomtextcontent
+
+\fi
+
+\setupinteractionscreen
+ [\c!width=\printpaperwidth,
+ \c!height=\printpaperheight,
+ \c!horoffset=\!!zeropoint,
+ \c!veroffset=\!!zeropoint,
+ \c!backspace=\backspace,
+ \c!topspace=\topspace,
+ \c!option=\v!min,
+ \c!delay=\v!none]
+
+\setupbuttons
+ [\c!state=\v!start,
+ \c!width=\v!fit,
+ \c!height=\v!broad,
+ \c!offset=0.25em,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!yes]
+
+\setupinteractionbar
+ [\c!state=\v!start,
+ \c!alternative=a,
+ \c!symbol=\v!no,
+ \c!width=\rightedgewidth,
+ \c!height=, % these are taken care
+ \c!depth=, % of at calling time
+ \c!distance=.5em, % beter relateren aan breedte
+ \c!step=1,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!yes]
+
+\setupsynchronizationbar
+ [\c!alternative=\v!page,
+ \c!width=\rightedgewidth,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=]
+
+\setupsynchronization
+ [\c!state=\v!stop]
+
+\setupprofiles
+ [\c!option=]
+
+\setuppagetransitions
+ [\v!reset]
+
+\setupcomment
+ [\c!state=\v!start,
+ \c!margin=2.5em,
+ \c!distance=1em,
+ \c!width=.3\textwidth,
+ \c!height=.2\textheight,
+ \c!color=\@@iacolor,
+ \c!title=,
+ \c!space=\v!no,
+ \c!symbol=\v!normal,
+ \c!location=\v!inmargin,
+ \c!option=,
+ \c!textlayer=]
+
+\setupversions % beware, @ is made active here,
+ [\c!number=1, % therefore we set this one at the end
+ \c!style=\ss,
+ \c!color=]
+
+\protect \endinput
diff --git a/tex/context/base/core-int.mkiv b/tex/context/base/core-int.mkiv
new file mode 100644
index 000000000..d02881801
--- /dev/null
+++ b/tex/context/base/core-int.mkiv
@@ -0,0 +1,2036 @@
+%D \module
+%D [ file=core-int,
+%D version=1995.01.01,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Interaction,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% evt interactionbaren runtime laden (scheelt 8K)
+
+%D Still to be done properly.
+
+\writestatus{loading}{ConTeXt Core Macros / Interaction}
+
+\unprotect
+
+% \expand vs \expanded
+
+% linked registers implementeren als een koppeling == mooier
+
+\presetlocalframed[\??lk]
+
+\newcounter\numberoflinks
+
+\def\stelkoppelingenin%
+ {\dodoubleargument\getparameters[\??lk]}
+
+\def\definieerkoppeling[#1]% % local loading !
+ {\doifundefined{\s!link:#1:\s!list}
+ {\expanded{\definetwopasslist{\s!link:#1}}%
+ \expanded{\doloadtwopassdata{\s!link:#1}}%
+ \getfirsttwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:f}\twopassdata
+ \getlasttwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:l}\twopassdata
+ \letgvalue{\s!link:#1:s}\noftwopassitems
+ \gettwopassdata{\s!link:#1}%
+ \letgvalue{\s!link:#1:c}\twopassdata
+ \letgvalue{\s!link:#1:n}\twopassdata}}
+
+\def\koppeling[#1]#2%
+ {\bgroup
+ \definieerkoppeling[#1]%
+ \doglobal\increment\numberoflinks
+ \gettwopassdata{\s!link:#1}%
+ \edef\numberoflinks{0\getvalue{\s!link:#1:s}}%
+ \edef\firstlink {0\getvalue{\s!link:#1:f}}%
+ \edef\lastlink {0\getvalue{\s!link:#1:l}}%
+ \edef\currentlink {0\getvalue{\s!link:#1:n}}%
+ \edef\prevlink {0\getvalue{\s!link:#1:c}}%
+ \iftwopassdatafound
+ \edef\nextlink{0\twopassdata}%
+ \letgvalue{\s!link:#1:n}\nextlink
+ \letgvalue{\s!link:#1:c}\currentlink
+ \else
+ \edef\nextlink{0\getvalue{\s!link:#1:l}}%
+ \fi
+ \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
+ \ifnum\noflinks<\plustwo
+ \locationfalse
+ \fi
+ \iflocation
+ \hbox
+ {\setinteractionparameter\c!width\!!zeropoint
+ \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
+ \ifnum\noflinks>\plustwo
+ \hskip\@@lkdistance
+ \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
+ \fi
+ \hskip\@@lkdistance
+ #2\relax
+ \hskip\@@lkdistance
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
+ \hskip\@@lkdistance
+ \fi
+ \dogotosomepage\??lk\gotoendcharacter\lastlink}%
+ \else
+ \hbox{#2}%
+ \fi
+ \egroup}
+
+\def\definieerkoppeling[#1]% % local loading !
+ {\doifundefined{\s!link:#1:\s!list}
+ {\expanded{\definetwopasslist{\s!link:#1}}% \expanded{\doloadtwopassdata{\s!link:#1}}%
+ \getfirsttwopassdata{\s!link:#1}%
+ \let\firstlink\twopassdata
+ \getlasttwopassdata{\s!link:#1}%
+ \let\lastlink\twopassdata
+ \let\noflinks\noftwopassitems
+ \gettwopassdata{\s!link:#1}%
+ \let\currentlink\twopassdata
+ \let\nextlink\twopassdata
+ \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}}}
+
+\def\koppeling[#1]#2%
+ {\bgroup
+ \definieerkoppeling[#1]%
+ \doglobal\increment\numberoflinks
+ \gettwopassdata{\s!link:#1}%
+ \def\next[##1:##2:##3:##4:##5]%
+ {\edef\firstlink {0##1}%
+ \edef\lastlink {0##2}%
+ \edef\noflinks {0##3}%
+ \edef\prevlink {0##4}%
+ \edef\currentlink{0##5}}%
+ \expanded{\next[\getvalue{\s!link:#1:}]}%
+ \edef\nextlink{0\iftwopassdatafound\twopassdata\else\lastlink\fi}%
+ \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}%
+ \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
+ \ifnum\noflinks<\plustwo
+ \locationfalse
+ \fi
+ \iflocation
+ \hbox
+ {\setinteractionparameter\c!width\!!zeropoint
+ #2\relax
+ \hskip\@@lkdistance
+ \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
+ \fi
+ \ifnum\noflinks>\plustwo
+ \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
+ \hskip\@@lkdistance
+ \fi
+ \dogotosomepage\??lk\gotoendcharacter\lastlink}%
+ \else
+ \hbox{#2}%
+ \fi
+ \egroup}
+
+\let\setupinteractionscreens\empty
+
+\def\docalculateinteractionscreen
+ {\doifelse\@@scwidth\v!fit
+ {\!!widtha\leftcombitotal
+ \ifdim\backspace>\!!widtha\ifdim\backspace>\zeropoint\relax
+ \advance\backspace -\!!widtha
+ \fi\fi
+ \advance\!!widtha\rightcombitotal
+ \advance\!!widtha 2\dimexpr\@@scbackspace+\@@schoroffset\relax}
+ {\doifelse\@@scwidth\v!max
+ {\!!widtha\printpaperwidth}
+ {\!!widtha\@@scwidth}}%
+ \doifelse\@@scheight\v!fit
+ {\!!heighta\dimexpr\topheight+\topdistance\relax
+ \ifdim\topspace>\!!heighta\ifdim\topspace>\zeropoint\relax
+ \advance\topspace -\!!heighta
+ \fi\fi
+ \advance\!!heighta \dimexpr\makeupheight+\bottomdistance+\bottomheight\relax
+ \advance\!!heighta 2\dimexpr\@@sctopspace+\@@scveroffset\relax}
+ {\doifelse\@@scheight\v!max
+ {\!!heighta\printpaperheight}
+ {\!!heighta\@@scheight}}%
+ \doif\@@scdelay\v!none{\let\@@scdelay\zerocountervalue}}
+
+% The macro is not to be changed; only the \@@ia-variables
+% may be set! ConTeXt is the producer but we no longer
+% mention the pragma site, since we don't want to be bothered
+% with remarks about third party documents and/or associated
+% with documents produced outside our control.
+
+\def\doprepareidentity % beware, we need to construct
+ {\let\!!stringa\@@iakeyword % an unexpanded space separated
+ \let\@@iakeyword\empty % list of keywords from a comma
+ \def\doprepareidentity##1% % separated one
+ {\ifx\@@iakeyword\empty
+ \appended\def\@@iakeyword{##1}%
+ \else
+ \appended\def\@@iakeyword{ ##1}%
+ \fi}%
+ \@EA\processcommalist\@EA[\!!stringa]\doprepareidentity
+ \global\let\doprepareidentity\relax}
+
+%D The Creator field is changed per 12/04/2006 due to user presure. This
+%D means that I need to put my own status info someplace else.
+
+\def\initializeidentity
+ {\doprepareidentity
+ \dosetupidentity % no \expanded{..} will be done in special (else no pdfdoc)
+ {\@@iatitle}{\@@iasubtitle}{\@@iaauthor}%
+ {ConTeXt - \contextversion}%
+ {\@@iadate}{\@@iakeyword}%
+ \global\let\initializeidentity\relax}
+
+\appendtoks \initializeidentity \to \everyshipout
+
+\def\initializepaper
+ {\bgroup
+ \ifx\@@ppleft \empty
+ \ifx\@@ppright\empty
+ \ifx\@@pptop \empty
+ \ifx\@@ppbottom \empty
+ \ifx\@@pcstate\v!start
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi\else
+ \locationfalse\fi
+ \iflocation % without screen settings
+ \egroup
+ \dosetuppaper\papersize\paperwidth\paperheight
+ \else
+ \egroup
+ \dosetuppaper\printpapersize\printpaperwidth\printpaperheight
+ \fi}
+
+\appendtoks \initializepaper \to \everyshipout
+
+\def\doinitializepaper
+ {\bgroup
+ \docalculateinteractionscreen
+ \ifdim\!!widtha>\paperwidth\ifdim\!!widtha>\zeropoint
+ \paperwidth\!!widtha
+ \fi\fi
+ \ifdim\!!heighta>\paperheight\ifdim\!!heighta>\zeropoint
+ \paperheight\!!heighta
+ \fi\fi
+ \dosetuppaper
+ {\printpapersize}
+ {\the\paperwidth}
+ {\the\paperheight}%
+ \egroup}
+
+\let\@@pcscreendata\empty
+
+\def\dosetupinteractionscreens % met a, b en \number
+ {\doifnot\@@pcstate\v!start\dodosetupinteractionscreens}
+
+\setvalue{\??sc\c!option\v!max }{1} % tzt share with driver
+\setvalue{\??sc\c!option\v!bookmark }{2} % tzt share with driver
+\setvalue{\??sc\c!option\v!fit }{3} % tzt share with driver
+\setvalue{\??sc\c!option\v!doublesided}{4} % tzt share with driver
+
+\def\dodosetupinteractionscreens % met a, b en \number
+ {\bgroup
+ \docalculateinteractionscreen
+ \!!counte=0\getvalue{\??sc\c!option\@@scoption}\relax
+ % niet waterdicht
+ \doifnot{\the\!!widtha\the\!!heighta}\@@pcscreendata
+ {\xdef\@@pcscreendata{\the\!!widtha\the\!!heighta}%
+ \showmessage\m!interactions1{\withoutpt\the\!!widtha,\withoutpt\the\!!heighta}}%
+ % needs to be split: dimensions for each page
+ % and mode per document and only once !
+ \dosetupscreen \backoffset\topoffset\!!widtha\!!heighta{\the\!!counte}%
+ \dosetupcropbox\backoffset\topoffset\!!widtha\!!heighta
+ \egroup}
+
+\def\dosetupinteractionscreen[#1]%
+ {\getparameters[\??sc][#1]%
+ \ifproductionrun
+ \let\initializepaper\doinitializepaper
+ \let\setupinteractionscreens\dosetupinteractionscreens
+ \fi}
+
+\appendtoks \setupinteractionscreens \to \everyfirstshipout % needed to get option=max etc working
+\appendtoks \setupinteractionscreens \to \everyshipout % needed for page/screen dimensions
+
+\def\setupinteractionscreen
+ {\dosingleempty\dosetupinteractionscreen}
+
+% \startinteractionmenu[rechts]
+% \but [eerste] eerste \\
+% \txt hello world \\
+% \but [tweede] tweede \\
+% \nop \\
+% \but [tweede] tweede \\
+% \rul whow \\
+% \but [tweede] tweede \\
+% \raw hello world \\
+% \but [tweede] tweede \\
+% \com \vfill \\
+% \but [derde] derde \\
+% \stopinteractionmenu
+
+\newif\iflocationmenupermitted
+
+\def\testinteractionmenu#1%
+ {\iflocation
+ \doifelse\@@iamenu\v!on
+ {\doifelsevalue{\??am#1\c!state}\v!start
+ {\global\locationmenupermittedtrue}
+ {\global\locationmenupermittedfalse}}
+ {\global\locationmenupermittedfalse}%
+ \else
+ \global\locationmenupermittedfalse
+ \fi}
+
+\def\dodisableinteractionmenu[#1][#2][#3]%
+ {\def\dododisableinteractionmenu##1%
+ {\doifelse{#3}{}
+ {\letvalue{\??am##1\c!obstruction}\empty}
+ {\edef\interactieblokkade{\getvalue{\??am##1\c!obstruction}}
+ \def\docommand####1{#1{####1}{\interactieblokkade}}% #1 = \remove or \add
+ \processcommalist[#3]\docommand
+ \setevalue{\??am##1\c!obstruction}{\interactieblokkade}}}%
+ \processcommalist[#2]\dododisableinteractionmenu}
+
+\def\disableinteractionmenu
+ {\dotripleempty\dodisableinteractionmenu[\addtocommalist]}
+
+\def\enableinteractionmenu
+ {\dotripleempty\dodisableinteractionmenu[\removefromcommalist]}
+
+% ja : kader/achtergrond met tekst
+% leeg : kader/achtergrond maar geen tekst
+% nee : alleen ruimte reserveren
+% geen : helemaal weglaten
+
+\newif\iflocationdummy
+\newif\ifskippedmenuitem
+
+\newif\iflocationempty
+\newif\iflocationclick
+
+% ja : kader/achtergrond met tekst
+% leeg : kader/achtergrond maar geen tekst
+% nee : alleen ruimte reserveren
+% geen : helemaal weglaten
+%
+% \setupinteractionmenu[right][samepage=yes, unknownreference=yes]
+% \setupinteractionmenu[right][samepage=empty,unknownreference=empty]
+% \setupinteractionmenu[right][samepage=no, unknownreference=no]
+% \setupinteractionmenu[right][samepage=none, unknownreference=none]
+%
+% \startinteractionmenu[right]
+% \but [firstpage] first \\
+% \but [lastpage] last \\
+% \but [somepage] crap \\
+% \stopinteractionmenu
+
+\def\dosetlocationboxcontent#1[#2]#3[#4]%
+ {\global\skippedmenuitemfalse
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}%
+ \iflocationclick
+ \hbox{\gotolocation{#4}{\box\locationbox}}%
+ \else
+ \hbox{\box\locationbox}%
+ \fi}
+
+\let\dosetlocationboxyes\dosetlocationboxcontent
+
+\def\dosetlocationboxempty#1[%
+ {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,}
+
+\def\dosetlocationboxno#1[%
+ {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,\c!frame=,\c!background=,}
+
+\def\dosetlocationboxnone#1[#2]#3[#4]%
+ {\global\skippedmenuitemtrue}
+
+\def\setlocationboxyes#1[#2]#3[#4]%
+ {\locationclicktrue
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \global\skippedmenuitemfalse
+ \gotolocation
+ {#4}% % needed
+ {\ifrealreferencepage
+ \ifcase\csname\??am\??am\csname#1\c!samepage\endcsname\endcsname\relax
+ \copycsname#1\c!color\endcsname\csname#1\c!contrastcolor\endcsname
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \global\skippedmenuitemtrue
+ \fi
+ \else
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \fi}}%
+ \ifskippedmenuitem\else\box\locationbox\fi}
+
+\def\setlocationboxnop#1[#2]#3[#4]%
+ {\locationclickfalse
+ \setbox\locationbox\hbox
+ {\resetgoto % anders cyclische aanroep !
+ \global\skippedmenuitemfalse
+ \ifcase\csname\??am\??am\csname#1\c!unknownreference\endcsname\endcsname\relax
+ \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
+ \or
+ \global\skippedmenuitemtrue
+ \fi}%
+ \ifskippedmenuitem\else\box\locationbox\fi}
+
+\def\setlocationboxraw#1[#2]#3[#4]%
+ {\localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}
+
+\def\setlocationbox#1[#2]#3[#4]%
+ {\bgroup % really needed !
+ \edef\permittedreferences{\csname#1\c!obstruction\endcsname}%
+ \doifreferencepermittedelse{#4}%
+ {\setlocationboxyes{#1}[#2]{#3}[#4]}%
+ {\setlocationboxnop{#1}[#2]{#3}[#4]}%
+ \egroup}
+
+\def\setlocationnop#1[#2]#3%
+ {\localframed[#1][#2]{#3}}
+
+\def\executeamboxcommands#1#2#3#4#5%
+ {%\processaction
+ % [\getvalue{\??am#1\c!dummy}]
+ % [ \v!yes=>\chardef\handleunknownmenuitem=0\relax,
+ % \v!empty=>\chardef\handleunknownmenuitem=1\relax,
+ % \v!no=>\chardef\handleunknownmenuitem=2\relax]%
+ \getvalue{\??am#1#3}\relax
+ \setamboxcommands{#1}{#4}%
+ \ignorespaces#2\unskip
+ \getvalue{\??am#1#5}}
+
+\newcounter\currentamposition
+
+\newtoks\everysetmenucommands
+
+\def\setamboxcommands#1#2%
+ {\def\currentmenu{#1}% % kan nog eerder
+ \def\currentsubmenu{#2}% % ? ?
+ \doglobal\newcounter\currentamposition
+ \the\everysetmenucommands}
+
+\def\menu@@amboxcommand#1\\%
+ {\dontleavehmode
+ \bgroup
+ \ignorespaces#1\unskip\relax
+ \ifskippedmenuitem \else
+ \getvalue{\??am\currentmenu\currentsubmenu}%
+ \fi
+ \egroup
+ \ignorespaces}
+
+\appendtoks
+ \let\@@amboxcommand\menu@@amboxcommand
+\to \everysetmenucommands
+
+\def\menu@raw[#1]#2\\%
+ {\@@amboxcommand\gotobox{\ignorespaces#2\unskip}[#1]\\}%
+
+\def\menu@but[#1]#2\\%
+ {\@@amboxcommand\do@@amposition\currentmenu{#1}{\setlocationbox{\??am\currentmenu}[]{\ignorespaces#2\unskip}[#1]}\\}%
+
+\def\menu@got[#1]#2\\% pas op! offset
+ {\@@amboxcommand\setlocationbox{\??am\currentmenu}[\c!frame=\v!off,\c!background=]{\ignorespaces#2\unskip}[#1]\\}%
+
+\def\menu@nop#1\\%
+ {\@@amboxcommand\setlocationboxraw{\??am\currentmenu}[\c!frame=\v!off,\c!background=,\c!empty=\v!yes]{\ignorespaces#1\unskip}[]\\}%
+
+\def\menu@txt#1\\%
+ {\@@amboxcommand\localframed[\??am\currentmenu][\c!frame=\v!off,\c!background=]{\ignorespaces#1\unskip}\\}%
+
+\def\menu@rul#1\\% ook \do@@amposition !
+ {\@@amboxcommand\localframed[\??am\currentmenu][]{\ignorespaces#1\unskip}\\}%
+
+\def\menu@com#1\\%
+ {\ignorespaces#1\unskip\ignorespaces}%
+
+\appendtoks
+ \let\raw\menu@raw
+ \let\but\menu@but
+ \let\got\menu@got
+ \let\nop\menu@nop
+ \let\txt\menu@txt
+ \let\rul\menu@rul
+ \let\com\menu@com
+\to \everysetmenucommands
+
+\ifx\do@@amposition\undefined
+ \let\do@@amposition\gobbletwoarguments % hook for positional thingies
+\fi
+
+\let\currentmenu\empty
+
+% beware : never change the concept of pbgoffset
+
+\def\menuparameter#1{\csname\??am\currentmenu#1\endcsname}
+
+\def\@@amhbox#1#2#3#4%
+ {\def\currentmenu{#3}%
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \bgroup
+ \showcomposition
+ \scratchdimen\dimexpr
+ \makeupwidth
+ +\pagebackgroundhoffset
+ +\pagebackgroundhoffset
+ -\menuparameter\c!leftoffset
+ -\menuparameter\c!rightoffset
+ \relax
+ \setbox\scratchbox\hbox to \scratchdimen
+ {\forgetall\executeamboxcommands{#3}{#4}\c!left\c!middle\c!right}%
+ \setbox\scratchbox\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}%
+ \wd\scratchbox\makeupwidth % geen \ht=#2 setting (yet)
+ \hskip\dimexpr-\pagebackgroundhoffset+\menuparameter\c!leftoffset\relax
+ \box\scratchbox
+ \egroup
+ \else
+ #1\relax
+ \fi}
+
+\def\@@amvbox#1#2#3#4% don't change skipping, this one works!
+ {\def\currentmenu{#3}%
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \bgroup
+ \showcomposition
+ \scratchdimen\dimexpr
+ \textheight
+ +\pagebackgroundvoffset
+ +\pagebackgroundvoffset
+ +\pagebackgrounddepth
+ -\menuparameter\c!topoffset
+ -\menuparameter\c!bottomoffset
+ \relax
+ \setbox\scratchbox\vbox to \scratchdimen
+ {\forgetall % Voor't geval de afstand
+ %\setupblank[\v!standard]% % (tijdelijk) is aangepast.
+ \restorestandardblank
+ \hsize#2\relax
+ \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after}%
+ \setbox\scratchbox\vbox{\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}}%
+ \setbox\scratchbox\vbox
+ {\ht\scratchbox\zeropoint
+ \vskip\dimexpr-\pagebackgroundvoffset+\menuparameter\c!topoffset\relax
+ \box\scratchbox
+ \vskip\pagebackgroundvoffset}% overbodig
+ \ht\scratchbox\textheight
+ \wd\scratchbox#2\relax
+ \box\scratchbox
+ \egroup
+ \else
+ #1\relax
+ \fi}
+
+\ifx\do@@ammenuposition\undefined
+ \let\do@@ammenuposition\gobbleoneargument % hook for positional thingies
+\fi
+
+\setvalue{\??am\s!do\v!right }{\@@amvbox{\dodummypageskip\v!right }\rightedgewidth}
+\setvalue{\??am\s!do\v!left }{\@@amvbox{\dodummypageskip\v!left }\leftedgewidth }
+\setvalue{\??am\s!do\v!top }{\@@amhbox{\dodummypageskip\v!top }\topheight }
+\setvalue{\??am\s!do\v!bottom}{\@@amhbox{\dodummypageskip\v!bottom}\bottomheight }
+
+\def\dointeractionmenu#1#2%
+ {\getvalue{\??am\s!do\getvalue{\??am#1\c!location}}{#1}{#2}}
+
+\unexpanded\def\interactionmenu[#1]%
+ {\getvalue{\??am\c!menu#1}}
+
+\def\horizontalinteractionmenu#1#2#3#4%
+ {\ifdim#2>\zeropoint % new
+ \scratchdimen\zeropoint
+ \setbox\scratchbox\hbox
+ {\def\docommand##1%
+ {\doifnotvalue{\??am##1\c!state}\v!none
+ {\hskip\scratchdimen
+ \setbox2\hbox to #2
+ {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
+ \doifelsevalue{\??am##1\c!distance}\v!overlay
+ {\scratchdimen\zeropoint
+ \wd2\zeropoint}%
+ {\scratchdimen\getvalue{\??am##1\c!distance}}%
+ \box2}}%
+ \startinteraction
+ \processcommacommand[\getvalue{\??am#1}]\docommand
+ \stopinteraction}%
+ \wd\scratchbox#2\relax
+ \box\scratchbox
+ \fi}
+
+\def\verticalinteractionmenu#1#2#3#4%
+ {\ifdim#2>\zeropoint % new
+ \scratchdimen\zeropoint
+ \setbox\scratchbox\vbox
+ {\def\docommand##1%
+ {\doifnotvalue{\??am##1\c!state}\v!none
+ {\vskip\scratchdimen
+ \setbox2\vbox to #2
+ {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
+ \doifelsevalue{\??am##1\c!distance}\v!overlay
+ {\scratchdimen\zeropoint
+ \offinterlineskip
+ \dp2\zeropoint
+ \ht2\zeropoint}%
+ {\scratchdimen\getvalue{\??am##1\c!distance}}%
+ \box2}}%
+ \startinteraction
+ \processcommacommand[\getvalue{\??am#1}]\docommand
+ \stopinteraction}%
+ \ht\scratchbox#2\relax
+ \dp\scratchbox\zeropoint
+ \box\scratchbox
+ \fi}
+
+\letvalue{\??am\v!left }\empty
+\letvalue{\??am\v!right}\empty
+\letvalue{\??am\v!top }\empty
+\letvalue{\??am\v!bottom }\empty
+
+% todo : \defineinteractionmenuclass
+
+\def\interactionmenus[#1]%
+ {\iflocation
+ \getvalue{\??am\??am\c!menu#1}%
+ \else
+ \dodummypageskip{#1}%
+ \fi}
+
+\setvalue{\??am\??am\c!menu\v!left }{\horizontalinteractionmenu\v!left \leftedgewidth \c!left \c!right}
+\setvalue{\??am\??am\c!menu\v!right }{\horizontalinteractionmenu\v!right \rightedgewidth\c!left \c!right}
+\setvalue{\??am\??am\c!menu\v!top }{\verticalinteractionmenu \v!top \topheight \c!before\c!after}
+\setvalue{\??am\??am\c!menu\v!bottom}{\verticalinteractionmenu \v!bottom\bottomheight \c!before\c!after}
+
+% this can be implemented with the following command (which
+% is new, undocumented, experimental, untested, etc etc)
+
+\def\defineinteractionmenuclass
+ {\dodoubleargument\dodefineinteractionmenuclass}
+
+\def\dodefineinteractionmenuclass[#1][#2]% tag hori|veri
+ {\doifelse{#2}\v!vertical
+ {\setvalue{\??am\??am\c!menu#1}{\verticalinteractionmenu {#1}{\getvalue{\??am#1\c!width }}\c!before\c!after}}
+ {\setvalue{\??am\??am\c!menu#1}{\horizontalinteractionmenu{#1}{\getvalue{\??am#1\c!height}}\c!left\c!right }}}
+
+% \setupinteraction[menu=on,state=start]
+%
+% \defineinteractionmenuclass[test] [vertical]
+% \defineinteractionmenuclass[another][horizontal]
+%
+% \defineinteractionmenu[test] [left][state=start,width=4cm]
+% \defineinteractionmenu[another][top] [state=start,height=1cm]
+%
+% \startinteractionmenu[test]
+% \but [firstpage] test-a \\
+% \but [nextpage] test-b \\
+% \stopinteractionmenu
+%
+% \startinteractionmenu[another]
+% \but [firstpage] test-a \\
+% \but [nextpage] test-b \\
+% \stopinteractionmenu
+%
+% \setupheadertexts[{\interactionmenu[another]}]
+%
+% \starttext
+%
+% test \interactionmenu[test] \page
+% test \interactionmenu[test] \page
+%
+% \stoptext
+
+%D This can save complicated menu macros when one want to
+%D keep control over parts of a menu (i.e.\ turn them on and
+%D off). We could have achieved something similar with modes.
+
+\def\local@@ambox#1#2#3#4% don't change skipping, this one works!
+ {\bgroup
+ \testinteractionmenu{#3}%
+ \iflocationmenupermitted
+ \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after
+ \else
+ #1\relax
+ \fi
+ \egroup}
+
+\def\includemenu[#1]%
+ {\doifvalue{\??am#1\c!state}\v!local
+ {\bgroup
+ \letvalue{\??am#1\c!state}\v!start
+ \let\@@amvbox\local@@ambox
+ \let\@@amhbox\local@@ambox
+ \getvalue{\??am\c!menu#1}%
+ \egroup}}
+
+%D We also need an explicit position control some day. I'll
+%D do that when I need it. [The stacking order.]
+
+\newif\ifextendedmenu
+
+% [name] [location]
+% [name] [location] [pars]
+
+\def\defineinteractionmenu
+ {\dotripleempty\dodefineinteractionmenu}
+
+\def\dodefineinteractionmenu[#1][#2][#3]%
+ {% main settings
+ \letvalue{\??am\c!menu#1}\empty
+ \setvalue{\@@dodolistelement#1}{\def\dosomelistelement{\dodomenulistelement{#1}}}%
+ \presetlocalframed[\??am#1]%
+ % register location
+ \expanded{\addtocommalist{#1}\@EA\noexpand\csname\??am#2\endcsname}%
+ % inherit settings
+ \doifnot{#1}{#2}
+ {\copyparameters[\??am#1][\??am#2]
+ [\c!left,\c!middle,\c!right,\c!before,\c!after,\c!inbetween,%
+ \c!width,\c!height,\c!distance,\c!offset,%
+ \c!frame,\c!framecolor,\c!rulethickness,%
+ \c!background,\c!backgroundcolor,\c!backgroundscreen,%
+ \c!style,\c!color,\c!contrastcolor,\c!samepage,\c!unknownreference,%
+ \c!leftoffset,\c!rightoffset,\c!topoffset,\c!bottomoffset]}%
+ % additional settings
+ \getparameters[\??am#1][\c!location=#2,\c!obstruction=,#3]}
+
+\def\setupinteractionmenu
+ {\dodoubleargument\dosetupinteractionmenu}
+
+\def\dosetupinteractionmenu[#1][#2]%
+ {\def\docommand##1{\getparameters[\??am##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\expandafter\chardef\csname\??am\??am\v!yes \endcsname\zerocount
+\expandafter\chardef\csname\??am\??am\v!empty\endcsname\plusone
+\expandafter\chardef\csname\??am\??am\v!no \endcsname\plustwo
+\expandafter\chardef\csname\??am\??am\v!none \endcsname\plusthree
+\expandafter\chardef\csname\??am\??am \endcsname\plusone % default
+
+\processbetween{\v!interactionmenu}\dostartinteractionmenu
+
+\def\dostartinteractionmenu#1%
+ {\dodostartinteractionmenu#1\dodostopinteractionmenu}
+
+\def\dodostartinteractionmenu[#1]#2\dodostopinteractionmenu
+ {\setvalue{\??am\c!menu#1}{\extendedmenutrue\dointeractionmenu{#1}{#2}}}
+
+\def\resetinteractionmenu[#1]%
+ {\letvalue{\??am\c!menu#1}\empty}
+
+\def\dodomenulistelement#1#2#3#4#5#6#7%
+ {\setbox0=\hbox
+ {\let\gotolocation\gobbleoneargument % hack to catch last []
+ %\locationclickfalse % ipv ^
+ \docheckrealreferencepage{#7}%
+ \setlocationboxyes
+ {\??am#1}% % needed !
+ []% no settings
+ {\limitatetext{#5}{\getvalue{\??li#2\c!maxwidth}}{\unknown}}% % needed !
+ []}% normally the destination, catch by gobble
+ \@@amboxcommand\do@@amposition{#1}{#7}% beware, we pass the pagenumber
+ {\ignorespaces\linklisttoelement{#3}{#6}{#7}{\box0}\unskip}\\}
+
+% \scherm moet worden als \page
+
+\def\screen
+ {\dosingleempty\doscreen}
+
+\def\doscreen[#1]%
+ {\iflocation\page[#1]\fi}
+
+\unexpanded\def\menubutton
+ {\dodoubleempty\domenubutton}
+
+\def\domenubutton[#1]%
+ {\iffirstargument
+ \ifsecondargument
+ \@EAEAEA\domenubuttonB
+ \else
+ \doifassignmentelse{#1}
+ {\@EAEAEA\domenubuttonC}
+ {\@EAEAEA\domenubuttonD}%
+ \fi
+ \else
+ \@EA\domenubuttonA
+ \fi[#1]}
+
+\def\domenubuttonA[#1][#2]#3[#4]% normal button, no parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox\??bt[]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonB[#1][#2]#3[#4]% menu button, with parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox{\??am#1}[#2]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonC[#1][#2]#3[#4]% normal button, with parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox\??bt[#1]{#3}[#4]%
+ \egroup}
+
+\def\domenubuttonD[#1][#2]#3[#4]% menu button, no parameters
+ {\bgroup
+ %\locationdummytrue
+ \setlocationbox{\??am#1}[]{#3}[#4]%
+ \egroup}
+
+\def\menubox
+ {\dodoubleempty\domenubox}
+
+\def\domenubox[#1][#2]#3%
+ {\bgroup
+ \let\setlocationbox\setlocationboxraw
+ \domenubutton[#1][#2]#3[]%
+ \egroup}
+
+% Hier volgen de synchronisatiemacro's:
+
+\def\syncprefix{sync}
+
+%def\syncmarker{syncmark}
+%\definemarking[\syncmarker]
+%\setupmarking[\syncmarker][\c!expansie=\v!ja]
+
+\newmark\syncmarker
+
+\newcounter\synccounter
+
+\newif\ifsynchronisation
+
+\def\startsynchronization%
+ {\iflocation\ifsynchronisation
+ \doglobal\increment\synccounter
+ \fi\fi}
+
+\def\stopsynchronization%
+ {\iflocation\ifsynchronisation
+ %\thisisdestination{\syncprefix:\synccounter}%
+ \pagereference[\syncprefix:\synccounter]%
+ \ifvmode
+ \@EA\setmark\@EA\syncmarker\@EA{\synccounter} % \marking[\syncmarker]{\synccounter}%
+ \else
+ \showmessage\m!interactions4\synccounter
+ \fi
+ \fi\fi}
+
+\def\synchronize%
+ {\startsynchronization
+ \stopsynchronization}
+
+\def\dosetupsynchronization[#1]%
+ {\getparameters[\??sy][#1]%
+ \doifelse\@@systate\v!start
+ \synchronisationtrue
+ \synchronisationfalse}
+
+\def\setupsynchronization
+ {\dosingleargument\dosetupsynchronization}
+
+\def\definesynchronization
+ {\dosingleargument\dodefinesynchronization}
+
+\def\setupsynchronizationbar
+ {\dodoubleargument\getparameters[\??ba]}
+
+\presetlocalframed[\??ba]
+
+\setvalue{synchronisatie\v!page}[#1]%
+ {\bgroup
+ %\setupinteraction[\c!width=\!!zeropoint]%
+ \setinteractionparameter\c!width\!!zeropoint
+ \setbox0\hbox
+ {\localframed[\??ba][]{\dolocationattributes\??ba\c!style\c!color{\strut\@@batext}}}%
+ \dontcomplain
+ \def\atthebottom
+ {\leaders\hrule\!!depth1ex\!!height-.5ex\hfil}%
+ \def\atthetop##1##2##3%
+ {\dimen0=\wd0
+ \divide\dimen0 3
+ \multiply\dimen0 ##2\relax
+ \dimen2=.25em % brrr
+ \advance\dimen0 -##3\dimen2
+ %\gotodestination
+ % {}{#1}{\syncprefix:##1}{}
+ % {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}}%
+ \gotobox
+ {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}%
+ [#1::\syncprefix:##1]}%
+ \hbox
+ {\def\check##1##2%
+ {\edef##2{0##1\syncmarker}%
+ \ifnum0##2=0 \def##2{1}\fi}%
+ \check\gettopmark\top
+ \check\getfirstmark\first
+ \check\getbotmark\bot
+ \setbox2\hbox to \wd0
+ {\ifnum\top=\first\relax
+ \ifnum\first=\bot\relax
+ \atthetop\first30\relax
+ \else
+ \atthetop\first21\hss\atthetop\bot11\relax
+ \fi
+ \else
+ \ifnum\first=\bot\relax
+ \atthetop\top11\hss\atthetop\first21\relax
+ \else
+ \atthetop\top11\hss\atthetop\first11\hss\atthetop\bot11\relax
+ \fi
+ \fi}%
+ \wd2=\zeropoint\box2
+ \box0\relax}%
+ \egroup}
+
+\setvalue{synchronisatie\v!local}[#1]%
+ {\bgroup
+ %\setupinteraction[\c!width=\!!zeropoint]%
+ \setinteractionparameter\c!width\!!zeropoint
+ \def\blackrule{\hbox{\vrule\!!height.5em\!!width.5em}}%
+ %\gotodestination
+ % {}{##1}{\syncprefix:#1}{0}
+ % {\color[\locationcolor\@@bacolor]{\blackrule}}%
+ \gotobox %
+ {\color[\locationcolor\@@bacolor]{\blackrule}}%
+ [#1::\syncprefix:\synccounter]%
+ \egroup}
+
+\def\synchronizationbar[#1][#2]%
+ {\iflocation\ifsynchronisation
+ \bgroup
+ \setupsynchronizationbar
+ [\c!text=\getvalue{doc:des:#1},#2]%
+ \getvalue{synchronisatie\@@baalternative}[#1]%
+ \egroup
+ \fi\fi}
+
+% A nice application of glue. All this code will be rewritten and
+% generalized.
+
+\newbox\interactionbarbox
+
+\newif\ifbarsymbol
+
+\def\dogotosomepage#1#2#3% nog checken !
+ {\hbox
+ {\iflocation
+ \ifnum#3=\realpageno
+ #2%
+ \else
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
+ \fi
+ \else
+ #2%
+ \fi}}
+
+\def\dogotosomecontrastpage#1#2#3% nog checken, may replace previous
+ {\checkreferences % nodig ??
+ \hbox
+ {\iflocation
+ \ifnum#3=\realpageno
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!contrastcolor}{#2}}%
+ \else
+ \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
+ \fi
+ \else
+ #2%
+ \fi}}
+
+\presetlocalframed[\??ib]
+
+\def\interactionbara % we need better control over contrastcolor
+ {\iflocation % maybe just use gotopage and set colors
+ \bgroup
+ \setinteractionparameter\c!width\zeropoint
+ \setupblackrules[\c!height=\v!max,\c!depth=\v!max]%
+ \!!widthb\dimexpr\@@ibwidth-2.75\emwidth\relax
+ \!!widtha\dimexpr\!!widthb/\lastpage\relax
+ \bgroup
+ \advance\realpageno\minusone
+ \ifvoid\interactionbarbox
+ \bgroup
+ \processaction
+ [\@@ibstep]
+ [ \v!small=>\scratchdimen.25\emwidth,
+ \v!medium=>\scratchdimen.5\emwidth,
+ \v!big=>\scratchdimen\emwidth,
+ \s!unknown=>\scratchdimen\!!widtha]%
+ \ifdim\!!widtha<\scratchdimen\relax
+ \!!counta\numexpr\scratchdimen/\!!widtha\relax
+ \else
+ \!!counta\@@ibstep\relax
+ \fi
+ \!!widtha\!!counta\!!widtha
+ \setbox\scratchbox\hbox{\blackrule[\c!width=\!!widtha,\c!color=middlegray]}% color here, else no mkiv
+ \global\setbox\interactionbarbox\hbox to \!!widthb
+ {\hss
+ \dostepwiserecurse\plusone\lastpage\!!counta
+ {\gotorealpage\empty\empty\recurselevel{\copy\scratchbox}}%
+ \hss}%
+ \global\wd\interactionbarbox\zeropoint
+ \egroup
+ \fi
+ \egroup
+ \noindent
+ \strut
+ \hbox to \@@ibwidth
+ {\dontcomplain
+ \setupblackrules[\c!width=\emwidth]%
+ \dogotosomecontrastpage\??ib\blackrule\firstpage
+ \hss
+ \copy\interactionbarbox
+ \hbox to \!!widthb
+ {\ifdim\!!widtha<\emwidth
+ \!!widtha\emwidth
+ \fi
+ \setupblackrules[\c!width=\!!widtha]%
+ \ifnum\realpageno>\plusone
+ \!!counta\numexpr\realpageno-\plustwo\relax
+ \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
+ \dogotosomepage\??ib\blackrule\prevpage
+ \fi
+ \dogotosomecontrastpage\??ib{\blackrule[\c!width=.5em]}\realpageno
+ \ifnum\realpageno<\lastpage\relax
+ \dogotosomepage\??ib\blackrule\nextpage
+ \!!counta\numexpr\lastpage-\realpageno-\plusone\relax
+ \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
+ \fi}%
+ \hss
+ \dogotosomecontrastpage\??ib\blackrule\lastpage}%
+ \egroup
+ \fi}
+
+\def\interactionbarb
+ {\ifnum\lastpage>\firstpage\relax
+ \interactionbuttons[\v!firstpage,\v!previouspage,\v!nextpage,\v!lastpage]%
+ \fi}
+
+\def\interactionbarc
+ {\iflocation
+ \ifnum\lastpage>\plusone
+ \hbox to \@@ibwidth
+ {\setupblackrules[\c!height=\@@ibheight,\c!depth=\@@ibdepth]%
+ \scratchdimen\dimexpr(\@@ibwidth-4\emwidth)/\numexpr\lastpage+\minusone\relax\relax
+ \!!widtha\numexpr\realpageno+\minusone\relax\scratchdimen
+ \!!widthb\numexpr\lastpage-\realpageno\relax\scratchdimen
+ \startcolor[\locationcolor\@@ibcolor]%
+ \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\firstpage
+ \hss
+ \dogotosomepage\empty{\blackrule[\c!width=\!!widtha]}\prevpage
+ \color[\@@ibcontrastcolor]{\blackrule[\c!width=\emwidth]}%
+ \dogotosomepage\empty{\blackrule[\c!width=\!!widthb]}\nextpage
+ \hss
+ \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\lastpage
+ \stopcolor}%
+ \fi
+ \fi}
+
+\def\interactionbard
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \hbox \bgroup
+ \setinteractionparameter\c!width\!!zeropoint
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi]}}%
+ \else
+ \def\dogotox##1%
+ {\hbox{\vrule\!!height\@@ibheight\!!depth \@@ibdepth\!!width \@@ibwidth}}%
+ \fi
+ \dostepwiserecurse\plusone\nofsubpages\plusone
+ {\bgroup
+ \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
+ \ifnum\scratchcounter<\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
+ \else\ifnum\scratchcounter=\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
+ \fi\fi
+ \egroup
+ \hskip\@@ibdistance}%
+ \unskip % not needed
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbare% KAN WORDEN GECOMBINEERD MET D
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \bgroup
+ \!!widthb\dimexpr\nofsubpages\dimexpr\@@ibdistance\relax-\@@ibdistance\relax % (n-1)
+ \!!widtha\dimexpr(\@@ibwidth-\!!widthb)/\nofsubpages\relax
+ \ifdim\!!widtha<\@@ibdistance\relax
+ \interactionbarf
+ \else
+ \setinteractionparameter\c!width\!!zeropoint
+ \noindent
+ \hbox to \@@ibwidth
+ \bgroup
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi}}%
+ \else
+ \def\dogotox##1%
+ {\hbox{\vrule\!!height\@@ibheight\!!depth\@@ibdepth\!!width\!!widtha}}%
+ \fi
+ \dostepwiserecurse\plusone\nofsubpages\plusone
+ {\bgroup
+ \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
+ \ifnum\scratchcounter<\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
+ \else\ifnum\scratchcounter=\realpageno\relax
+ \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
+ \fi\fi
+ \egroup
+ \hss}%
+ \unskip
+ \egroup
+ \fi
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbarf % !! KAN WORDEN GECOMBINEERD MET D !!
+ {\iflocation\ifshowingsubpage
+ \ifnum\nofsubpages>\plusone
+ \setinteractionparameter\c!width\!!zeropoint
+ \noindent
+ \hbox to \@@ibwidth
+ \bgroup
+ \!!countb\zerocount
+ \loop % todo: \doloop
+ \advance\!!countb \plusone
+ %\!!countc\nofsubpages \divide\!!countc \!!countb \advance\!!countc \plusone
+ \!!countc\numexpr(\nofsubpages/\!!countb)+\plusone\relax % rounding
+ \!!widthb\@@ibdistance
+ \multiply\!!widthb \!!countc
+ \advance\!!widthb -\@@ibdistance
+ \!!widtha\@@ibwidth
+ \advance\!!widtha -\!!widthb
+ \divide\!!widtha \!!countc
+ \ifdim\!!widtha<\@@ibdistance\relax
+ \repeat
+ \ifnum\!!countc>\plusone
+ % this is not that well tested
+ \advance\!!countc \minustwo
+ \!!widtha-\@@ibdistance
+ \!!widtha\!!countc\!!widtha
+ \advance\!!widtha \@@ibwidth
+ \advance\!!countc \plusone
+ \divide\!!widtha \!!countc
+ \fi
+ \ifbarsymbol
+ \setupsymbolset[\@@iasymbolset]%
+ \def\dogotox##1%
+ {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!somewhere\or\v!somewhere\or\v!next\fi}}%
+ \else
+ \def\dogotox##1%
+ {\hbox
+ {\!!heighta\@@ibheight
+ \!!deptha\@@ibdepth
+ \ifcase##1\relax
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
+ \or
+ \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
+ \fi}}%
+ \fi
+ \!!countc\numexpr\realpageno-\plustwo\relax
+ \!!countd\numexpr\realpageno+\plustwo\relax
+ \ifnum\!!countc<\plusone \!!countc\plusone \fi
+ \!!countf\zerocount
+ \dostepwiserecurse\firstsubpage\lastsubpage\plusone
+ {\!!doneafalse
+ \advance\!!countf \plusone
+ \ifnum\recurselevel=\firstsubpage\relax \!!doneatrue \fi
+ \ifnum\recurselevel=\lastsubpage\relax \!!doneatrue \fi
+ \if!!donea
+ \ifnum\recurselevel<\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox0}\recurselevel
+ \else\ifnum\recurselevel>\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox4}\recurselevel
+ \fi\fi
+ \hss
+ \!!countf\zerocount
+ \else\ifnum\!!countf=\!!countb
+ \ifnum\recurselevel<\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox1}\recurselevel
+ \else\ifnum\recurselevel>\realpageno
+ \dogotosomecontrastpage\??ib{\dogotox3}\recurselevel
+ \else
+ \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
+ \fi\fi
+ \hss
+ \!!countf\zerocount
+ \fi\fi}%
+ \unskip
+ \egroup
+ \fi
+ \fi\fi}
+
+\def\interactionbarg
+ {\ifnum\lastsubpage>\firstsubpage\relax
+ \interactionbuttons[\v!firstsubpage,\v!previoussubpage,\v!nextsubpage,\v!lastsubpage]%
+ \fi}
+
+\def\checkinteractionbar#1#2#3%
+ {\ifdim\@@ibwidth=\zeropoint\def\@@ibwidth{#1}\fi
+ \doifnothing\@@ibheight{\def\@@ibheight{#2}}%
+ \doifnothing\@@ibdepth{\def\@@ibdepth{#3}}}
+
+\def\complexinteractionbar[#1]%
+ {\doifelse{#1}\v!reset
+ {\global\setbox\interactionbarbox\emptybox}%
+ {\bgroup
+ \iflocation
+ \checksubpages % goes wrong / loads \numberofpages too
+ \getparameters[\??ib][#1]%
+ \doif\@@ibstate\v!start
+ {\startinteraction
+ \processaction % breedte defaults !
+ [\@@ibalternative]
+ [ c=>\checkinteractionbar{10em}\v!max \v!max,
+ d=>\checkinteractionbar{.5em}{.5em} \!!zeropoint,
+ e=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
+ f=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
+ \s!default=>\checkinteractionbar{10em}\v!broad\!!zeropoint,
+ \s!unknown=>\checkinteractionbar{10em}\v!broad\!!zeropoint]%
+ \doifelse\@@ibsymbol\v!yes
+ \barsymboltrue\barsymbolfalse
+ \getvalue{interactionbar\@@ibalternative}%
+ \stopinteraction}%
+ \fi
+ \egroup}}
+
+\definecomplexorsimpleempty\interactionbar
+
+\def\setupinteractionbar
+ {\dodoubleargument\getparameters[\??ib]}
+
+% Er wordt vooralsnog uitgegaan van een symmetrische
+% start-stop situatie.
+
+\def\c!profiel!! {profiel:} % brrr
+\def\c!versie!! {versie:}
+
+\def\dodefineprofile[#1][#2]%
+ {\iflocation
+ \def\dododefineprofile##1%
+ {\def\dodododefineprofile####1%
+ {\doifdefinedelse{\c!profiel!!####1}%
+ {\edef\!!stringa{\getvalue{\c!profiel!!####1}}%
+ \setevalue{\c!profiel!!####1}{\!!stringa,##1}}%
+ {\setevalue{\c!profiel!!####1}{##1}}}%
+ \processcommalist[#2]\dodododefineprofile}%
+ \processcommalist[#1]\dododefineprofile
+ \fi}
+
+\def\defineprofile%
+ {\dodoubleargument\dodefineprofile}
+
+% Als met \getpar wordt gewerkt, dan moet \next worden toegepast.
+
+% TZT initialisatie!
+
+\def\profilepage{}
+
+\let\dosetprofilepage\relax
+\let\dogetprofilepage\relax
+
+\def\processprofile#1[#2]%
+ {\iflocation
+ \par % needed for pdftex
+ \bgroup
+ \dosetprofilepage
+ \dogetprofilepage
+ \def\processoneprofile##1##2%
+ {\ExpandBothAfter\doifinsetelse{##2}{\processedprofiles}%
+ {\doifsomething{##1}{(##1)}}%
+ {\addtocommalist{##2}\processedprofiles
+ ##1\relax
+ \ifcase#1\relax
+ \dobeginofprofile{##2}\paperwidth\paperheight\profilepage
+ \else
+ \doendofprofile
+ \fi}}%
+ \let\processedprofiles\empty
+ \def\doprocessprofile##1%
+ {\doifelse{\@@pfoption}{\v!test}%
+ {\goodbreak\blank\nobreak\tt[\space
+ \ifcase#1\v!start\else\v!stop\fi profiel\space ##1:\space
+ \doifdefinedelse{\c!profiel!!##1}%
+ {\def\dodoprocessprofile####1%
+ {\processoneprofile
+ {\goto{####1}[\c!profiel!!####1]}%
+ {####1}%
+ \space}%
+ \processcommacommand
+ [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}%
+ {- }%
+ ]\nobreak\blank}%
+ {\doifdefined{\c!profiel!!##1}%
+ {\def\dodoprocessprofile####1%
+ {\processoneprofile{}{####1}}%
+ \processcommacommand
+ [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}}}%
+ \processcommalist[#2]\doprocessprofile
+ \egroup
+ \par % needed for pdftex
+ \fi}
+
+\def\startprofile[#1]%
+ {\iflocation
+ \bgroup
+ \addtocommalist{#1}\actualprofile
+ \def\stopprofile%
+ {\processprofile1[#1]%
+ \egroup}%
+ \def\next{\processprofile0[#1]}% % \DoAfterFi \processprofile0[#1]%
+ \else % ^^^^^^^^^^ will be obsolete
+ \let\next\relax % since ugly and never used
+ \fi
+ \next}
+
+\let\stopprofile\relax
+
+\def\dofollowprofile#1[#2]%
+ {\iflocation
+ \hbox
+ {\dohandlegoto
+ {\dolocationattributes\??ia\c!style\c!color{#1\presetgoto}}%
+ {\dostartgotoprofile\buttonwidth\buttonheight{#2}}%
+ {\dostopgotoprofile}}%
+ \else
+ {#1}%
+ \fi}
+
+\def\followprofile#1[#2]%
+ {\iflocation
+ \doif\@@pfoption\v!test{\pagereference[\c!profiel!!#2]}%
+ \dofollowprofile{#1}[#2]%
+ \fi}
+
+\def\setupprofiles%
+ {\dodoubleargument\getparameters[\??pf]}
+
+% Als er nog geen tekst op de pagina staat, dan heeft het
+% profiel betrekking op het bovenstaande, dus soms een vorige
+% pagina! Vreemd, omdat PDF paginagewijs werkt. Gelukkig
+% biedt /page een oplossing. Echter: expansie van een
+% \special kan niet worden uitgesteld, zodat alleen een
+% two-pass een oplossing vormt. Het onderstaande kan komen
+% te vervallen als Acrobat dit ondervangt. Het scheelt een
+% pass en een lijst.
+%
+% Er kunnen eventueel twee lijsten worden gebruikt. Een voor
+% het begin (start) en een voor het eind (stop). Nu staat
+% alles in een lijst.
+
+\definetwopasslist\s!profile
+
+\newcounter\currentprofile
+
+\def\dosetprofilepage%
+ {\doglobal\increment\currentprofile
+ \lazysavetwopassdata{\s!profile}{\currentprofile}{\noexpand\realfolio}}
+
+\def\dogetprofilepage%
+ {\gettwopassdata{\s!profile}%
+ \let\profilepage=\twopassdata}
+
+% is this stuff used at all
+
+\newcounter\versionlevel
+\newcounter\versionorder
+
+\newif\ifrecentversion
+
+\let\oldatcharacter=@
+
+\def\minimumversion{0}
+\def\actualversion{0}
+
+\def\dosetupversions[#1]%
+ {\getparameters[\??ve][#1]
+ \stripcharacter.\from\@@venumber\to\minimumversion}
+
+\def\setupversions
+ {\dosingleargument\dosetupversions}
+
+\definetwopasslist\s!versionbegin
+\definetwopasslist\s!versionend
+
+\let\actualprofile\empty
+
+\def\doresetpageversion
+ {\lazysavetwopassdata{\s!versionend}{\versionorder}{\noexpand\realfolio}}
+
+\def\dosetpageversion#1%
+ {\recentversiontrue
+ \doglobal\increment\versionorder\relax
+ \lazysavetwopassdata{\s!versionbegin}{\versionorder}{\noexpand\realfolio}%
+ \let\resetpageversion\doresetpageversion}
+
+\def\recentcontributions{}
+
+\def\checkrecentcontributions%
+ {\gettwopassdata{\s!versionbegin}%
+ \iftwopassdatafound
+ \!!counta\twopassdata\relax
+ \gettwopassdata{\s!versionend}%
+ \iftwopassdatafound
+ \!!countb\twopassdata\relax
+ \doglobal\increment\versionorder\relax
+ \savetwopassdata{\s!versionbegin}{\versionorder}{\the\!!counta}%
+ \savetwopassdata{\s!versionend }{\versionorder}{\the\!!countb}%
+ \dostepwiserecurse\!!counta\!!countb\plusone
+ {\@EA\doglobal\@EA\addtocommalist\@EA{\recurselevel}{\recentcontributions}}%
+ \let\next\checkrecentcontributions
+ \else
+ \let\next\relax
+ \fi
+ \else
+ \let\next\relax
+ \fi
+ \next}
+
+\def\docheckpageversion
+ {\ExpandBothAfter\doifinsetelse{\realfolio}{\recentcontributions}
+ {\pageselectedtrue}%
+ {\pageselectedfalse}}
+
+\let\setpageversion \gobbleoneargument
+\let\resetpageversion \relax
+\let\checkpageversion \relax
+
+\def\complexstartversion[#1]%
+ {\bgroup
+ \doifelsenothing\actualprofile
+ {\startprofile[#1]}%
+ {\startprofile[#1,\actualprofile]}%
+ \def\docomplexstartversie##1%
+ {\stripcharacter.\from##1\to\actualversion
+ \ifnum\versionlevel>\zerocount\relax
+ \ifnum\actualversion=\zerocount
+ \setpageversion\actualversion % unknown version
+ \else
+ \ifnum\actualversion<\minimumversion\relax
+ \relax % old version
+ \else
+ \setpageversion\actualversion % new version
+ \fi
+ \fi
+ \fi}%
+ \doglobal\increment\versionlevel\relax
+ \doifelsenothing{#1}
+ {\docomplexstartversie{0}}%
+ {\processcommalist[#1]\docomplexstartversie}}
+
+\definecomplexorsimpleempty\startversion
+
+\def\stopversion
+ {\stopprofile
+ \doglobal\decrement\versionlevel
+ \ifnum\versionlevel<\zerocount
+ \showmessage\m!versions1\empty
+ \else
+ \resetpageversion
+ \egroup
+ \fi}
+
+\def\markversion
+ {\showmessage\m!versions2\empty
+ \let\setpageversion\dosetpageversion
+ \let\resetpageversion\relax
+ \let\checkpageversion\relax}
+
+\def\selectversion
+ {\checkrecentcontributions
+ \showmessage\m!versions3\recentcontributions
+ \let\setpageversio\gobbleoneargument
+ \let\resetpageversion\relax
+ \let\checkpageversion\docheckpageversion}
+
+\def\dodefineversion[#1][#2]%
+ {\setvalue{\c!versie!!#1}{#2}%
+ \defineprofile[#1][#2]}
+
+\def\defineversion
+ {\dodoubleargument\dodefineversion}
+
+\def\followversion
+ {\followprofile}
+
+\def\followprofileversion#1[#2][#3]%
+ {\def\docommand##1%
+ {\defineprofile[#2#3][##1]}%
+ \processcommacommand[\getvalue{\c!versie!!#3}]\docommand
+ \followprofile#1[#2#3]}
+
+\newcounter\currentpagetransition
+
+\newif\ifrandomtransitions
+
+\def\setuppagetransitions%
+ {\dosingleempty\dosetuppagetransitions}
+
+\def\dosetuppagetransitions[#1]%
+ {\doifelsenothing{#1}
+ {\doifnot\@@scdelay\v!none
+ {\let\setpagetransition\setsomepagedelay}}
+ {\doifelse{#1}\v!start
+ {\doifnot\@@scdelay\v!none
+ {\let\setpagetransition\setsomepagedelay}}
+ {\doglobal\newcounter\currentpagetransition
+ \doifinsetelse{#1}{\v!reset,\v!stop}
+ {\let\setpagetransition\relax}
+ {\let\setpagetransition\setsomepagetransition
+ \doifinsetelse\v!random{#1}
+ {\randomtransitionstrue}{\randomtransitionsfalse}%
+ \edef\userpagetransitions{#1}%
+ \@EA\removefromcommalist\@EA{\v!random}\userpagetransitions
+ \ifx\userpagetransitions\empty
+ \let\userpagetransitions\pagetransitions
+ \fi}}}}
+
+\def\setsomepagedelay
+ {\expanded{\dosetpagetransition{0}{\@@scdelay}}}
+
+\def\setsomepagetransition
+ {\iflocation
+ \ifrandomtransitions
+ \expanded{\getcommalistsize[\userpagetransitions]}%
+ \getrandomnumber\currentpagetransition1\commalistsize
+ \else
+ \doglobal\increment\currentpagetransition
+ \fi
+ \expanded{\getfromcommalist[\userpagetransitions][\currentpagetransition]}%
+ \doifnumberelse\commalistelement
+ {\expanded{\getfromcommalist[\pagetransitions][\commalistelement]}}
+ {}%
+ \ifx\commalistelement\empty
+ \doglobal\newcounter\currentpagetransition
+ \setsomepagetransition
+ \else
+ \doifelse\@@scdelay\v!none
+ {\expanded{\dosetpagetransition{\commalistelement}{0}}}
+ {\expanded{\dosetpagetransition{\commalistelement}{\@@scdelay}}}%
+ \fi
+ \fi}
+
+\prependtoks \setpagetransition \to \everyshipout
+
+% temporary here
+
+%D \startbuffer
+%D \dorecurse{10}
+%D {\horizontalpositionbar
+%D \pos\recurselevel \min1 \max10
+%D \token\framed{\recurselevel}%
+%D \\}
+%D
+%D \hbox to 15em
+%D {\hss
+%D \dorecurse{10}
+%D {\verticalpositionbar\pos\recurselevel\min1\max10\token\blackrule\\
+%D \hss}}
+%D \stopbuffer
+
+\def\horizontalpositionbar\pos#1\min#2\max#3\token#4\\%
+ {\hbox to \hsize
+ {\hskip\zeropoint\!!plus #1\!!fill
+ \hskip\zeropoint\!!plus-#2\!!fill
+ #4\relax
+ \hskip\zeropoint\!!plus #3\!!fill
+ \hskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\verticalpositionbar\pos#1\min#2\max#3\token#4\\%
+ {\vbox to \vsize
+ {\vskip\zeropoint\!!plus #1\!!fill
+ \vskip\zeropoint\!!plus-#2\!!fill
+ \hbox{#4}\relax
+ \vskip\zeropoint\!!plus #3\!!fill
+ \vskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\horizontalgrowingbar\pos#1\min#2\max#3\height#4\depth#5\\%
+ {\hbox to \hsize
+ {\scratchcounter#1%
+ \advance\scratchcounter -#2%
+ \advance\scratchcounter \plusone
+ \leaders\vrule\hskip\zeropoint\!!plus \scratchcounter\!!fill
+ \vrule\!!width\zeropoint\!!height#4\!!depth#5%
+ \hskip\zeropoint\!!plus #3\!!fill
+ \hskip\zeropoint\!!plus-#1\!!fill}}
+
+\def\verticalgrowingbar\pos#1\min#2\max#3\width#4\\%
+ {\vbox to \vsize
+ {\scratchcounter#1%
+ \advance\scratchcounter -#2%
+ \advance\scratchcounter \plusone
+ \leaders\hrule\vskip\zeropoint\!!plus\scratchcounter\!!fill
+ \hrule\!!width#4\!!height\zeropoint\!!depth\zeropoint
+ \vskip\zeropoint\!!plus #3\!!fill
+ \vskip\zeropoint\!!plus-#1\!!fill}}
+
+\newbox\commentbox
+
+\def\doflushcommentanchors
+ {\let\next\relax % new
+ \processaction
+ [\@@cclocation]
+ [% \v!text=>\let\next\relax, % new
+ \v!inmargin=>\let\next\inmargin, % brr not the same as inleft|rightmargin
+ \v!leftedge=>\let\next\inleftedge,
+ \v!rightedge=>\let\next\inrightedge,
+ \v!leftmargin=>\let\next\inleftmargin,
+ \v!rightmargin=>\let\next\inrightmargin]%
+ \next{\hbox{\raise\strutht\box\commentbox}}}
+
+\def\flushcommentanchors % in everypar so indirect
+ {\ifvoid\commentbox\else \doflushcommentanchors \fi}
+
+\def\setupcomment
+ {\dodoubleargument\getparameters[\??cc]}
+
+\setvalue{\e!start\v!comment}% the dummy triple gobbles trailing spaces
+ {\dotripleempty\dostartcommentaar}
+
+\def\comment
+ {\dodoubleempty\docomment}
+
+\def\dodocomment#1%
+ {\!!widtha\@@ccwidth
+ \!!heighta\@@ccheight
+ \doifelse\@@ccoption\v!max
+ {\let\@@ccopen \!!plusone}{\let\@@ccopen \!!zerocount}%
+ \doifelse\@@ccoption\v!buffer
+ {\let\@@cccollect\!!plusone}{\let\@@cccollect\!!zerocount}%
+ \preparecommentvariables
+ \doinsertcomment
+ \@@cctitle\!!widtha\!!heighta
+ \@@cccolor\@@ccopen\@@ccsymbol
+ \@@cccollect{#1}}
+
+\def\preparecommentvariables % more will move here as with fields
+ {\let\@@DriverCommentLayer\@@cctextlayer}
+
+\def\dopreparecommentaar#1#2%
+ {\doifassignmentelse{#1}
+ {\getparameters[\??cc][#1]}
+ {\getparameters[\??cc][\c!title=#1,#2]}%
+ \obeylines
+ \doif\@@ccspace\v!yes\obeyspaces}
+
+\def\dostartcommentaar[#1][#2][#3]%
+ {\bgroup
+ \doifelse\@@ccstate\v!start
+ {\dopreparecommentaar{#1}{#2}%
+ \long\def\docommand##1%
+ {\global\setbox\commentbox\frozenhbox
+ {\hbox to \zeropoint
+ {\struttedbox{\tbox{\dodocomment{##1}}}\hss}%
+ \hskip\ifvoid\commentbox\@@ccmargin\else\@@ccdistance\fi
+ \box\commentbox}%
+ \egroup}}%
+ {\long\def\docommand##1%
+ {\egroup}}%
+ \grabuntil{\e!stop\v!comment}\docommand}
+
+\letvalue{\e!stop\v!comment}\relax % handy for \expanded{...}
+
+\def\docomment[#1][#2]#3%
+ {\doif\@@ccstate\v!start
+ {\hbox to \zeropoint
+ {\dopreparecommentaar{#1}{#2}%
+ \hskip-\@@ccmargin
+ \struttedbox{\tbox{\dodocomment{#3}}\hss}}}%
+ \ignorespaces}
+
+% \startcomment
+% hello beautiful\\world
+% \stopcomment
+%
+% \startcomment[hello]
+% hello << \'e\'erste >>
+% beautiful
+% world
+% \stopcomment
+%
+% \startcomment[hello][color=green,width=4cm,height=3cm]
+% hello \leftguillemot\ \'e\'erste \rightguillemot\
+% beautiful
+% world
+% \stopcommentaar
+%
+% \startcomment[hello][color=green,width=4cm,height=3cm]
+% hello \leftguillemot\ \'e\'erste \rightguillemot\ test
+%
+% beautiful
+%
+% world
+% \stopcomment
+%
+% \startcomment[symbol=Balloon]
+% Do we want this kind of rubish? And, why isn't this and
+% some more features related to text annotations so poorly
+% (actually not) documented? Anyhow, by providing this
+% functionality we demonstrate that \pdfTeX\ can do it. By
+% the way, it's funny that when in Acrobat we scale up the
+% text, the symbols scale down.
+% \stopcomment
+
+% \definesymbol [comment-normal][{\externalfigure[cow.pdf]}]
+% \definesymbol [comment-down] [{\externalfigure[cow.pdf]}]
+%
+% \def\CowSymbol#1#2%
+% {\scale
+% [\c!height=#1]
+% {\startMPcode
+% loadfigure "koe.mp" number 1 ;
+% refill currentpicture withcolor #2 ;
+% \stopMPcode}}
+%
+% \definesymbol [comment-normal]
+% [\CowSymbol{4ex}{red}]
+%
+% \definesymbol [comment-down]
+% [\CowSymbol{4ex}{green}]
+%
+% \setupcomment
+% [\c!symbol={comment-normal,comment-down},
+% \c!option=\v!buffer]
+%
+% \setupfootertexts[\placecomments]
+
+\def\placecomments
+ {\doflushcomments}
+
+% \setupinteraction[state=start]
+%
+% \useattachment[test.tex]
+% \useattachment[whatever][test.tex]
+% \useattachment[whatever][newname][test.tex]
+% \useattachment[whatever][title][newname][test.tex]
+%
+% % \setupattachments[\c!symbol={symbol-normal,symbol-down}]
+%
+% \starttext \attachment[whatever] \stoptext
+
+\definesystemvariable{at}
+
+\def\useattachment
+ {\doquadrupleempty\douseattachment}
+
+\def\douseattachment[#1][#2][#3][#4]% tag title newname filename
+ {\iffourthargument
+ \setgvalue{\??at:#1}{{#2}{#3}{#4}}% tooltip kind of case
+ \else\ifthirdargument
+ \setgvalue{\??at:#1}{{#2}{#2}{#3}}% full path case
+ \else\ifsecondargument
+ \setgvalue{\??at:#1}{{#2}{#2}{#2}}% obvious case
+ \else
+ \setgvalue{\??at:#1}{{#1}{#1}{#1}}% worst case
+ \fi\fi\fi}
+
+\let\attachmenttitle\empty
+\let\attachmentname \empty
+\let\attachmentfile \empty
+
+\def\getattachmentdata[#1]%
+ {\edef\attachmenttitle{\filterfromvalue{\??at:#1}31}% description
+ \edef\attachmentname {\filterfromvalue{\??at:#1}32}% new name
+ \edef\attachmentfile {\filterfromvalue{\??at:#1}33}% original
+ \expandafter\splitstring\attachmentname\at.\to\!!stringa\and\!!stringb
+ \ifx\!!stringb\empty % no suffix, so we need to inherit it
+ \expandafter\splitstring\attachmentfile\at.\to\!!stringc\and\!!stringd
+ \edef\attachmentname{\attachmentname.\!!stringd}%
+ \fi}
+
+\def\attachment
+ {\dodoubleempty\doattachment}
+
+\def\doattachment[#1][#2]% currently title equals newname
+ {\iflocation
+ \ifsecondargument
+ \doifundefined{\??at:#2}
+ {\showmessage\m!interactions6{#2}%
+ \useattachment[#2]}%
+ \doif\@@atstate\v!start
+ {\bgroup
+ \getattachmentdata[#2]%
+ \doiffileelse\attachmentfile
+ {\setupattachments[#1]%
+ \presetattachmentvariables
+\struttedbox{\tbox{%
+ \doattachfile
+ \attachmenttitle
+ {1em}\strutheight\strutdepth\@@atcolor\@@atsymbol
+ \attachmentname
+ \attachmentfile}%
+}}%
+ {\showmessage\m!interactions5\attachmentfile}%
+ \egroup}%
+ \else\iffirstargument
+ \attachment[][#1]%
+ \fi\fi
+ \fi}
+
+\def\presetattachmentvariables
+ {\let\@@DriverAttachmentLayer\@@attextlayer}
+
+\def\setupattachments
+ {\dodoubleempty\getparameters[\??at]}
+
+\setupattachments
+ [\c!state=\v!start,
+ \c!color=\@@iacolor,
+ \c!textlayer=,
+ \c!symbol=]
+
+% jammer, tussen/midden had erin gemoeten; \c!commando toevoegen
+
+\def\registermenucommand#1%
+ {{\textonly\noindent#1\space}} % no math switching
+
+\def\doregistermenubuttons[#1][#2]% [menu id] [register]
+ {\bgroup
+ \ifsecondargument
+ \setupinteractionmenu
+ [#1][\c!unknownreference=\v!yes,\c!samepage=\v!yes]%
+ \def\docommand##1%
+ {\registermenucommand{\menubutton[#1]{##1}[#2:##1]}}%
+ \else
+ \def\docommand##1%
+ {\registermenucommand
+ {\button
+ [\c!unknownreference=\v!yes,\c!samepage=\v!yes]
+ {##1}[#1:##1]}}%
+ \fi
+ \handletokens abcdefghijklmnopqrstuvwxyz\with\docommand % moet anders
+ \egroup}
+
+\def\registermenubuttons
+ {\dodoubleempty\doregistermenubuttons}
+
+\stelkoppelingenin
+ [\c!distance=.25em,
+ \c!width=\v!fit,
+ \c!location=\v!low,
+ \c!color=\@@iacolor,
+ \c!frame=\v!off,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=]
+
+\defineinteractionmenu
+ [\v!right]
+ [\v!right]
+ [\c!before=,
+ \c!after=\vfil,
+ \c!inbetween=\blank,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!left=\hss,
+ \c!right=\hss,
+ \c!width=\rightedgewidth,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!left]
+ [\v!left]
+ [\c!before=,
+ \c!after=\vfil,
+ \c!inbetween=\blank,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!left=\hss,
+ \c!right=\hss,
+ \c!width=\leftedgewidth,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!bottom]
+ [\v!bottom]
+ [\c!before=\vss,
+ \c!after=\vss,
+ \c!middle=\hfil,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!width=\v!fit,
+ \c!height=\v!broad]
+
+\defineinteractionmenu
+ [\v!top]
+ [\v!top]
+ [\c!before=\vss,
+ \c!after=\vss,
+ \c!middle=\hfil,
+ \c!distance=\bodyfontsize, % 12pt
+ \c!width=\v!fit,
+ \c!height=\v!broad]
+
+\setupinteractionmenu
+ [\v!left,\v!right,\v!top,\v!bottom]
+ [\c!offset=.25em,
+ \c!position=\v!no,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundcolor=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!state=\v!start,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!empty,
+ \c!topoffset=\!!zeropoint,
+ \c!bottomoffset=\!!zeropoint,
+ \c!leftoffset=\!!zeropoint,
+ \c!rightoffset=\!!zeropoint]
+
+\def\placeleftedgetextblock % Is \hss/\hsize really needed here?
+ {\hbox to \leftedgewidth % (check outer level and settings)
+ {\hsize\leftedgewidth\hss\interactionmenus[\v!left]}}
+
+\def\placerightedgetextblock % Is \hss/\hsize really needed here?
+ {\hbox to \rightedgewidth % (check outer level and settings)
+ {\hsize\rightedgewidth\interactionmenus[\v!right]\hss}}
+
+\def\placetoptextblock
+ {\vbox to \topheight
+ {\vsize\topheight
+ \csname\??tk\v!top\c!before\endcsname
+ \interactionmenus[\v!top]%
+ \csname\??tk\v!top\c!after\endcsname
+ \kern\zeropoint}}
+
+\def\placebottomtextblock
+ {\vbox to \bottomheight
+ {\vsize\bottomheight
+ \csname\??tk\v!bottom\c!before\endcsname
+ \interactionmenus[\v!bottom]%
+ \csname\??tk\v!bottom\c!after\endcsname
+ \kern\zeropoint}}
+
+\ifx\leftedgetextcontent\undefined \else
+
+ \appendtoks \placeleftedgetextblock \hskip-\leftedgewidth \to \leftedgetextcontent
+ \appendtoks \placerightedgetextblock \hskip-\rightedgewidth \to \rightedgetextcontent
+ \appendtoks \placetoptextblock \vskip-\topheight \to \toptextcontent
+ \appendtoks \placebottomtextblock \vskip-\bottomheight \to \bottomtextcontent
+
+\fi
+
+\setupinteractionscreen
+ [\c!width=\printpaperwidth,
+ \c!height=\printpaperheight,
+ \c!horoffset=\!!zeropoint,
+ \c!veroffset=\!!zeropoint,
+ \c!backspace=\backspace,
+ \c!topspace=\topspace,
+ \c!option=\v!min,
+ \c!delay=\v!none]
+
+\setupbuttons
+ [\c!state=\v!start,
+ \c!width=\v!fit,
+ \c!height=\v!broad,
+ \c!offset=0.25em,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!yes]
+
+\setupinteractionbar
+ [\c!state=\v!start,
+ \c!alternative=a,
+ \c!symbol=\v!no,
+ \c!width=\rightedgewidth,
+ \c!height=, % these are taken care
+ \c!depth=, % of at calling time
+ \c!distance=.5em, % beter relateren aan breedte
+ \c!step=1,
+ \c!color=\@@iacolor,
+ \c!contrastcolor=\@@iacontrastcolor,
+ \c!frame=\v!on,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!samepage=\v!yes,
+ \c!unknownreference=\v!yes]
+
+\setupsynchronizationbar
+ [\c!alternative=\v!page,
+ \c!width=\rightedgewidth,
+ \c!style=\@@iastyle,
+ \c!color=\@@iacolor,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=]
+
+\setupsynchronization
+ [\c!state=\v!stop]
+
+\setupprofiles
+ [\c!option=]
+
+\setuppagetransitions
+ [\v!reset]
+
+\setupcomment
+ [\c!state=\v!start,
+ \c!margin=2.5em,
+ \c!distance=1em,
+ \c!width=.3\textwidth,
+ \c!height=.2\textheight,
+ \c!color=\@@iacolor,
+ \c!title=,
+ \c!space=\v!no,
+ \c!symbol=\v!normal,
+ \c!location=\v!inmargin,
+ \c!option=,
+ \c!textlayer=]
+
+\setupversions % beware, @ is made active here,
+ [\c!number=1, % therefore we set this one at the end
+ \c!style=\ss,
+ \c!color=]
+
+\protect \endinput
diff --git a/tex/context/base/core-int.tex b/tex/context/base/core-int.tex
deleted file mode 100644
index 79061958d..000000000
--- a/tex/context/base/core-int.tex
+++ /dev/null
@@ -1,2355 +0,0 @@
-%D \module
-%D [ file=core-int,
-%D version=1995.01.01,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Interaction,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% evt interactionbaren runtime laden (scheelt 8K)
-
-%D Still to be done properly.
-
-\writestatus{loading}{Context Core Macros / Interaction}
-
-% interactions 5 and 6 to be translated
-
-\startmessages dutch library: interactions
- title: interactie
- 1: aspect ratio -- x -- (b x h)
- 2: actief
- 3: niet actief
- 4: geen paginasynchronisatie (--) in hmode
- 5: onbekend attachment --
- 6: attachment file -- bestaat niet
-\stopmessages
-
-\startmessages english library: interactions
- title: interaction
- 1: aspect ratio -- x -- (b x h)
- 2: active
- 3: inactive
- 4: no pagesynchronisation (--) in hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages german library: interactions
- title: Interaktion
- 1: Seitenverhaeltnis -- x -- (B x H)
- 2: aktiv
- 3: inaktiv
- 4: keine Seitensynchronisation (--) im hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages czech library: interactions
- title: interakce
- 1: pomer -- x -- (s x v)
- 2: aktivni
- 3: neaktivni
- 4: zadna strankova synchronizace (--) v hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages italian library: interactions
- title: interazione
- 1: rapporto -- x -- (b x a)
- 2: attiva
- 3: inattiva
- 4: sincronizzazione di pagina (--) non disponibile in hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages norwegian library: interactions
- title: interaksjon
- 1: forholdstall -- x -- (b x h)
- 2: aktiv
- 3: inaktiv
- 4: ingen sidesynkronisering (--) i hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages romanian library: interactions
- title: interactiuni
- 1: aspectul -- x -- (b x h)
- 2: activ
- 3: inactiv
- 4: nu exista sincronizare pt. pagini (--) in hmode
- 5: unknown attachment --
- 6: attachment file -- does not exist
-\stopmessages
-
-\startmessages french library: interactions
- title: interaction
- 1: ratio d'aspect -- x -- (b x h)
- 2: actif
- 3: inactif
- 4: pas de synchronisation de page (--) dans le hmode
- 5: le fichier joint -- est inconnu
- 6: le fichier joint -- n'existe pas
-\stopmessages
-
-\startmessages dutch library: versions
- title: versie
- 1: er mankeert een @+
- 2: markeren pagina's
- 3: geselecteerde pagina's: --
-\stopmessages
-
-\startmessages english library: versions
- title: version
- 1: missing @+
- 2: marking pages
- 3: selected pages: --
-\stopmessages
-
-\startmessages german library: versions
- title: Version
- 1: fehlendes @+
- 2: Erstelle Seiten
- 3: Ausgewaehlte Seiten: --
-\stopmessages
-
-\startmessages czech library: versions
- title: verze
- 1: postradam @+
- 2: oznacuji se strany
- 3: oznacene strany: --
-\stopmessages
-
-\startmessages italian library: versions
- title: version
- 1: @+ mancante
- 2: marcatura pagine
- 3: pagine selezionate: --
-\stopmessages
-
-\startmessages norwegian library: versions
- title: versjon
- 1: manglende @+
- 2: markerer sider
- 3: valgte sider: --
-\stopmessages
-
-\startmessages romanian library: versions
- title: versiuni
- 1: lipseste @+
- 2: pagini marcate
- 3: pagini selectate: --
-\stopmessages
-
-\startmessages french library: versions
- title: version
- 1: @+ manquant
- 2: marquage des pages
- 3: pages sélectionnées : --
-\stopmessages
-
-\unprotect
-
-% \expand vs \expanded
-
-% linked registers implementeren als een koppeling == mooier
-
-\presetlocalframed[\??lk]
-
-\newcounter\numberoflinks
-
-\def\stelkoppelingenin%
- {\dodoubleargument\getparameters[\??lk]}
-
-\def\definieerkoppeling[#1]% % local loading !
- {\doifundefined{\s!link:#1:\s!list}
- {\expanded{\definetwopasslist{\s!link:#1}}%
- \expanded{\doloadtwopassdata{\s!link:#1}}%
- \getfirsttwopassdata{\s!link:#1}%
- \letgvalue{\s!link:#1:f}\twopassdata
- \getlasttwopassdata{\s!link:#1}%
- \letgvalue{\s!link:#1:l}\twopassdata
- \letgvalue{\s!link:#1:s}\noftwopassitems
- \gettwopassdata{\s!link:#1}%
- \letgvalue{\s!link:#1:c}\twopassdata
- \letgvalue{\s!link:#1:n}\twopassdata}}
-
-\def\koppeling[#1]#2%
- {\bgroup
- \definieerkoppeling[#1]%
- \doglobal\increment\numberoflinks
- \gettwopassdata{\s!link:#1}%
- \edef\numberoflinks{0\getvalue{\s!link:#1:s}}%
- \edef\firstlink {0\getvalue{\s!link:#1:f}}%
- \edef\lastlink {0\getvalue{\s!link:#1:l}}%
- \edef\currentlink {0\getvalue{\s!link:#1:n}}%
- \edef\prevlink {0\getvalue{\s!link:#1:c}}%
- \iftwopassdatafound
- \edef\nextlink{0\twopassdata}%
- \letgvalue{\s!link:#1:n}\nextlink
- \letgvalue{\s!link:#1:c}\currentlink
- \else
- \edef\nextlink{0\getvalue{\s!link:#1:l}}%
- \fi
- \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
- \ifnum\noflinks<\plustwo
- \locationfalse
- \fi
- \iflocation
- \hbox
- {\setinteractionparameter\c!width\!!zeropoint
- \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
- \ifnum\noflinks>\plustwo
- \hskip\@@lkdistance
- \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
- \fi
- \hskip\@@lkdistance
- #2\relax
- \hskip\@@lkdistance
- \ifnum\noflinks>\plustwo
- \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
- \hskip\@@lkdistance
- \fi
- \dogotosomepage\??lk\gotoendcharacter\lastlink}%
- \else
- \hbox{#2}%
- \fi
- \egroup}
-
-\def\definieerkoppeling[#1]% % local loading !
- {\doifundefined{\s!link:#1:\s!list}
- {\expanded{\definetwopasslist{\s!link:#1}}% \expanded{\doloadtwopassdata{\s!link:#1}}%
- \getfirsttwopassdata{\s!link:#1}%
- \let\firstlink\twopassdata
- \getlasttwopassdata{\s!link:#1}%
- \let\lastlink\twopassdata
- \let\noflinks\noftwopassitems
- \gettwopassdata{\s!link:#1}%
- \let\currentlink\twopassdata
- \let\nextlink\twopassdata
- \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}}}
-
-\def\koppeling[#1]#2%
- {\bgroup
- \definieerkoppeling[#1]%
- \doglobal\increment\numberoflinks
- \gettwopassdata{\s!link:#1}%
- \def\next[##1:##2:##3:##4:##5]%
- {\edef\firstlink {0##1}%
- \edef\lastlink {0##2}%
- \edef\noflinks {0##3}%
- \edef\prevlink {0##4}%
- \edef\currentlink{0##5}}%
- \expanded{\next[\getvalue{\s!link:#1:}]}%
- \edef\nextlink{0\iftwopassdatafound\twopassdata\else\lastlink\fi}%
- \setxvalue{\s!link:#1:}{\firstlink:\lastlink:\noflinks:\currentlink:\nextlink}%
- \lazysavetwopassdata{\s!link:#1}{\numberoflinks}{\noexpand\realfolio}%
- \ifnum\noflinks<\plustwo
- \locationfalse
- \fi
- \iflocation
- \hbox
- {\setinteractionparameter\c!width\!!zeropoint
- #2\relax
- \hskip\@@lkdistance
- \dogotosomepage\??lk\gotobegincharacter\firstlink\hss
- \ifnum\noflinks>\plustwo
- \dogotosomepage\??lk\gobackwardcharacter\prevlink\hss
- \fi
- \ifnum\noflinks>\plustwo
- \dogotosomepage\??lk\goforwardcharacter\nextlink\hss
- \hskip\@@lkdistance
- \fi
- \dogotosomepage\??lk\gotoendcharacter\lastlink}%
- \else
- \hbox{#2}%
- \fi
- \egroup}
-
-\let\setupinteractionscreens\empty
-
-\def\docalculateinteractionscreen
- {\doifelse\@@scwidth\v!fit
- {\!!widtha\leftcombitotal
- \ifdim\backspace>\!!widtha\ifdim\backspace>\zeropoint\relax
- \advance\backspace -\!!widtha
- \fi\fi
- \advance\!!widtha\rightcombitotal
- \advance\!!widtha 2\dimexpr\@@scbackspace+\@@schoroffset\relax}
- {\doifelse\@@scwidth\v!max
- {\!!widtha\printpaperwidth}
- {\!!widtha\@@scwidth}}%
- \doifelse\@@scheight\v!fit
- {\!!heighta\dimexpr\topheight+\topdistance\relax
- \ifdim\topspace>\!!heighta\ifdim\topspace>\zeropoint\relax
- \advance\topspace -\!!heighta
- \fi\fi
- \advance\!!heighta \dimexpr\makeupheight+\bottomdistance+\bottomheight\relax
- \advance\!!heighta 2\dimexpr\@@sctopspace+\@@scveroffset\relax}
- {\doifelse\@@scheight\v!max
- {\!!heighta\printpaperheight}
- {\!!heighta\@@scheight}}%
- \doif\@@scdelay\v!none{\let\@@scdelay\zerocountervalue}}
-
-% The macro is not to be changed; only the \@@ia-variables
-% may be set! ConTeXt is the producer but we no longer
-% mention the pragma site, since we don't want to be bothered
-% with remarks about third party documents and/or associated
-% with documents produced outside our control.
-
-\def\doprepareidentity % beware, we need to construct
- {\let\!!stringa\@@iakeyword % an unexpanded space separated
- \let\@@iakeyword\empty % list of keywords from a comma
- \def\doprepareidentity##1% % separated one
- {\ifx\@@iakeyword\empty
- \appended\def\@@iakeyword{##1}%
- \else
- \appended\def\@@iakeyword{ ##1}%
- \fi}%
- \@EA\processcommalist\@EA[\!!stringa]\doprepareidentity
- \global\let\doprepareidentity\relax}
-
-%D The Creator field is changed per 12/04/2006 due to user presure. This
-%D means that I need to put my own status info someplace else.
-
-\def\initializeidentity
- {\doprepareidentity
- \dosetupidentity % no \expanded{..} will be done in special (else no pdfdoc)
- {\@@iatitle}{\@@iasubtitle}{\@@iaauthor}%
- {ConTeXt - \contextversion}%
- {\@@iadate}{\@@iakeyword}%
- \global\let\initializeidentity\relax}
-
-\appendtoks \initializeidentity \to \everyshipout
-
-\def\initializepaper
- {\bgroup
- \ifx\@@ppleft \empty
- \ifx\@@ppright\empty
- \ifx\@@pptop \empty
- \ifx\@@ppbottom \empty
- \ifx\@@pcstate\v!start
- \locationfalse\fi\else
- \locationfalse\fi\else
- \locationfalse\fi\else
- \locationfalse\fi\else
- \locationfalse\fi
- \iflocation % without screen settings
- \egroup
- \dosetuppaper\papersize\paperwidth\paperheight
- \else
- \egroup
- \dosetuppaper\printpapersize\printpaperwidth\printpaperheight
- \fi}
-
-\appendtoks \initializepaper \to \everyshipout
-
-\def\doinitializepaper
- {\bgroup
- \docalculateinteractionscreen
- \ifdim\!!widtha>\paperwidth\ifdim\!!widtha>\zeropoint
- \paperwidth\!!widtha
- \fi\fi
- \ifdim\!!heighta>\paperheight\ifdim\!!heighta>\zeropoint
- \paperheight\!!heighta
- \fi\fi
- \dosetuppaper
- {\printpapersize}
- {\the\paperwidth}
- {\the\paperheight}%
- \egroup}
-
-\let\@@pcscreendata\empty
-
-\def\dosetupinteractionscreens % met a, b en \number
- {\doifnot\@@pcstate\v!start\dodosetupinteractionscreens}
-
-\setvalue{\??sc\c!option\v!max }{1} % tzt share with driver
-\setvalue{\??sc\c!option\v!bookmark }{2} % tzt share with driver
-\setvalue{\??sc\c!option\v!fit }{3} % tzt share with driver
-\setvalue{\??sc\c!option\v!doublesided}{4} % tzt share with driver
-
-\def\dodosetupinteractionscreens % met a, b en \number
- {\bgroup
- \docalculateinteractionscreen
- \!!counte=0\getvalue{\??sc\c!option\@@scoption}\relax
- % niet waterdicht
- \doifnot{\the\!!widtha\the\!!heighta}\@@pcscreendata
- {\xdef\@@pcscreendata{\the\!!widtha\the\!!heighta}%
- \showmessage\m!interactions1{\withoutpt\the\!!widtha,\withoutpt\the\!!heighta}}%
- % needs to be split: dimensions for each page
- % and mode per document and only once !
- \dosetupscreen \backoffset\topoffset\!!widtha\!!heighta{\the\!!counte}%
- \dosetupcropbox\backoffset\topoffset\!!widtha\!!heighta
- \egroup}
-
-\def\dosetupinteractionscreen[#1]%
- {\getparameters[\??sc][#1]%
- \ifproductionrun
- \let\initializepaper\doinitializepaper
- \let\setupinteractionscreens\dosetupinteractionscreens
- \fi}
-
-\appendtoks \setupinteractionscreens \to \everyfirstshipout % needed to get option=max etc working
-\appendtoks \setupinteractionscreens \to \everyshipout % needed for page/screen dimensions
-
-\def\setupinteractionscreen
- {\dosingleempty\dosetupinteractionscreen}
-
-%D Due to requests I finally decided to support bookmarks, a
-%D driver dependant way of showing tables of content. The most
-%D simple way of support is hooking bookmark generation into
-%D the existing list mechanisms. That way users can generate
-%D bookmarks automatically, although its entirely valid to add
-%D bookmarks by defining alternative ones. These will be added
-%D at the appropriate place in the list.
-
-% \hoofdstuk{het eerste hoofdstuk}
-%
-% \bookmark {de eerste bookmark} % optional overruled hoofdstuk
-%
-% .... text ....
-%
-% \placebookmarks [hoofdstuk,paragraaf,subparagraaf,subsubparagraaf,mylist]
-% [open list]
-%
-% \bookmark[mylist]{whatever}
-
-\def\@@bookmark {bm::}
-\def\@@booklevel{bl::}
-\def\@@bookcount{bc::}
-
-\definelist[\@@bookmark]
-
-\newtoks\postponedbookmarks
-
-\def\flushpostponedbookmark
- {\the\postponedbookmarks
- \global\postponedbookmarks\emptytoks}
-
-\def\simplebookmark#1%
- {\doglobal\prependtoks
- \writetolist[\@@bookmark]{}{#1}%
- \to\postponedbookmarks}
-
-\def\complexbookmark[#1]#2%
- {\doglobal\appendtoks\writetolist[#1]{}{#2}\to\postponedbookmarks}
-
-\definecomplexorsimple\bookmark
-
-\newif\iftracebookmarks \tracebookmarksfalse
-
-\let\tracebookmarks\tracebookmarkstrue
-
-\def\placebookmarks
- {\dodoubleempty\doplacebookmarks}
-
-\def\doplacebookmarks[#1][#2]%
- {\iflocation
- \iffirstargument
- \bgroup
- \ifsecondargument
- \doifelse{#2}\v!all
- {\edef\openbookmarklist{#1}}
- {\edef\openbookmarklist{#2}}%
- \else
- \let\openbookmarklist\empty
- \fi
- \global\let\bookmarklevellist\empty
- \def\bookmarklevelcount{0}%
- \doprocessbookmarks[#1]\dogetbookmarkelement
- \dolistelement{}{}{}{}{}{}% needed to finish the first pass
- \doprocessbookmarks[#1]\doputbookmarkelement
- \flushbookmark
- \egroup
- \else
- \expanded{\placebookmarks\@EA[\getvalue{\??ih\v!content\c!list}]}%
- \fi
- \fi}
-
-\def\doprocessbookmarks[#1]#2%
- {\let\dolistelement#2\relax
- \scratchcounter\zerocount
- \def\docommand##1%
- {\advance\scratchcounter \plusone
- \getlistlevel[##1]\listlevel{\the\scratchcounter}%
- \setxvalue{\@@bookcount\the\scratchcounter}{1}%
- \setxvalue{\@@booklevel##1}{\listlevel}}%
- \processcommalist[#1]\docommand
- \setxvalue{\@@bookcount0}{1}%
- \global\chardef\currentbookmarklevel\zerocount
- \global\chardef\previousbookmarklevel\zerocount
- \doutilities{listentries,#1,\@@bookmark}\jobname{#1}\relax\relax}
-
-\def\dodogetbookmarkelement#1#2#3#4#5#6%
- {\doifelsenothing{#1}
- {\global\chardef\currentbookmarklevel\zerocount}
- {\global\chardef\currentbookmarklevel\getvalue{\@@booklevel#1}\relax}%
- \ifnum\currentbookmarklevel>\previousbookmarklevel
- \setxvalue{\@@bookcount\the\currentbookmarklevel}{1}%
- \else\ifnum\currentbookmarklevel<\previousbookmarklevel
- \bgroup
- \!!counta\previousbookmarklevel
- \doloop
- {\let\bookmarktag\empty
- \!!countb\!!counta
- \advance\!!countb \minusone
- \dorecurse\!!countb
- {\edef\bookmarktag
- {\bookmarktag\getvalue{\@@bookcount\recurselevel}:}}%
- \edef\bookmarklevelcount
- {\getvalue{\@@bookcount\the\!!counta}}%
- \xdef\bookmarklevellist
- {\bookmarklevellist/\bookmarktag:\bookmarklevelcount/}%
- \advance\!!counta \minusone
- \ifnum\!!counta=\currentbookmarklevel
- \exitloop
- \fi}%
- \egroup
- \@EA\doglobal\@EA\increment\csname \@@bookcount\the\currentbookmarklevel\endcsname\relax
- \else
- \@EA\doglobal\@EA\increment\csname \@@bookcount\the\previousbookmarklevel\endcsname\relax
- \fi\fi
- \global\utilitydonetrue
- \global\chardef\previousbookmarklevel\currentbookmarklevel}
-
-\def\getbookmarklevelcount
- {\@EA\def\@EA\docommand\@EA[\@EA##\@EA1\@EA/\bookmarktag:##2/##3]%
- {\def\bookmarklevelcount{##2}}%
- \@EA\@EA\@EA\docommand\@EA\@EA\@EA[\@EA\bookmarklevellist\@EA/\bookmarktag:0/]}
-
-\def\dodoputbookmarkelement#1#2#3#4#5#6%
- {\doifelsenothing{#1}
- {\global\chardef\currentbookmarklevel\zerocount}
- {\global\chardef\currentbookmarklevel\getvalue{\@@booklevel#1}\relax}%
- \ifnum\currentbookmarklevel>\previousbookmarklevel
- \setxvalue{\@@bookcount\the\currentbookmarklevel}{1}%
- \else\ifnum\currentbookmarklevel<\previousbookmarklevel
- \@EA\doglobal\@EA\increment\csname \@@bookcount\the\currentbookmarklevel\endcsname\relax
- \else
- \@EA\doglobal\@EA\increment\csname \@@bookcount\the\previousbookmarklevel\endcsname\relax
- \fi\fi
- \let\bookmarktag\empty
- \!!countb\currentbookmarklevel
- \dorecurse\!!countb
- {\edef\bookmarktag
- {\bookmarktag\getvalue{\@@bookcount\recurselevel}:}}%
- \getbookmarklevelcount
- \iftracebookmarks
- \bgroup
- \par
- \bookmarktag\quad
- \dorecurse\currentbookmarklevel{\quad}\unskip#1\quad
- (\bookmarklevelcount)\quad
- \egroup
- \fi
- \global\chardef\previousbookmarklevel\currentbookmarklevel
- \global\utilitydonetrue
- \insertsomebookmark{#1}{\the\currentbookmarklevel}{\bookmarklevelcount}{#4}{#6}}
-
-\def\dogetbookmarkelement#1#2#3#4#5#6%
- {\doifnot{#1}\@@bookmark
- {\dodogetbookmarkelement{#1}{#2}{#3}{#4}{#5}{#6}}}
-
-\def\doputbookmarkelement#1#2#3#4#5#6%
- {\doifelse{#1}\@@bookmark
- {\localbookmark{#4}}
- {\flushbookmark
- \dodoputbookmarkelement{#1}{#2}{#3}{#4}{#5}{#6}}}
-
-\let\flushbookmark\relax
-\let\localbookmark\gobbleoneargument
-
-\def\insertsomebookmark#1#2#3#4#5%
- {\gdef\flushbookmark
- {\doinsertsomebookmark{#1}{#2}{#3}{#4}{#5}{g}}%
- \gdef\localbookmark##1%
- {\doinsertsomebookmark{#1}{#2}{#3}{##1}{#5}{l}}}
-
-\def\doinsertsomebookmark#1#2#3#4#5#6%
- {\global\utilitydonetrue
- \global\let\localbookmark\gobbleoneargument
- \global\let\flushbookmark\relax
- \doifinstringelse{#1}\openbookmarklist
- {\chardef\openbookmark\plusone}
- {\chardef\openbookmark\zerocount}%
- \iftracebookmarks(#6: #4)\quad(\the\openbookmark)\par\fi
- \doinsertbookmark{#2}{#3}{#4}{#5}{\openbookmark}}
-
-% \startinteractionmenu[rechts]
-% \but [eerste] eerste \\
-% \txt hello world \\
-% \but [tweede] tweede \\
-% \nop \\
-% \but [tweede] tweede \\
-% \rul whow \\
-% \but [tweede] tweede \\
-% \raw hello world \\
-% \but [tweede] tweede \\
-% \com \vfill \\
-% \but [derde] derde \\
-% \stopinteractionmenu
-
-\newif\iflocationmenupermitted
-
-\def\testinteractionmenu#1%
- {\iflocation
- \doifelse\@@iamenu\v!on
- {\doifelsevalue{\??am#1\c!state}\v!start
- {\global\locationmenupermittedtrue}
- {\global\locationmenupermittedfalse}}
- {\global\locationmenupermittedfalse}%
- \else
- \global\locationmenupermittedfalse
- \fi}
-
-\def\dodisableinteractionmenu[#1][#2][#3]%
- {\def\dododisableinteractionmenu##1%
- {\doifelse{#3}{}
- {\letvalue{\??am##1\c!obstruction}\empty}
- {\edef\interactieblokkade{\getvalue{\??am##1\c!obstruction}}
- \def\docommand####1{#1{####1}{\interactieblokkade}}% #1 = \remove or \add
- \processcommalist[#3]\docommand
- \setevalue{\??am##1\c!obstruction}{\interactieblokkade}}}%
- \processcommalist[#2]\dododisableinteractionmenu}
-
-\def\disableinteractionmenu
- {\dotripleempty\dodisableinteractionmenu[\addtocommalist]}
-
-\def\enableinteractionmenu
- {\dotripleempty\dodisableinteractionmenu[\removefromcommalist]}
-
-% ja : kader/achtergrond met tekst
-% leeg : kader/achtergrond maar geen tekst
-% nee : alleen ruimte reserveren
-% geen : helemaal weglaten
-
-\newif\iflocationdummy
-\newif\ifskippedmenuitem
-
-\newif\iflocationempty
-\newif\iflocationclick
-
-% ja : kader/achtergrond met tekst
-% leeg : kader/achtergrond maar geen tekst
-% nee : alleen ruimte reserveren
-% geen : helemaal weglaten
-%
-% \setupinteractionmenu[right][samepage=yes, unknownreference=yes]
-% \setupinteractionmenu[right][samepage=empty,unknownreference=empty]
-% \setupinteractionmenu[right][samepage=no, unknownreference=no]
-% \setupinteractionmenu[right][samepage=none, unknownreference=none]
-%
-% \startinteractionmenu[right]
-% \but [firstpage] first \\
-% \but [lastpage] last \\
-% \but [somepage] crap \\
-% \stopinteractionmenu
-
-\def\dosetlocationboxcontent#1[#2]#3[#4]%
- {\global\skippedmenuitemfalse
- \setbox\locationbox\hbox
- {\resetgoto % anders cyclische aanroep !
- \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}%
- \iflocationclick
- \hbox{\gotolocation{#4}{\box\locationbox}}%
- \else
- \hbox{\box\locationbox}%
- \fi}
-
-\let\dosetlocationboxyes\dosetlocationboxcontent
-
-\def\dosetlocationboxempty#1[%
- {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,}
-
-\def\dosetlocationboxno#1[%
- {\dosetlocationboxcontent{#1}[\c!empty=\v!yes,\c!frame=,\c!background=,}
-
-\def\dosetlocationboxnone#1[#2]#3[#4]%
- {\global\skippedmenuitemtrue}
-
-\def\setlocationboxyes#1[#2]#3[#4]%
- {\locationclicktrue
- \setbox\locationbox\hbox
- {\resetgoto % anders cyclische aanroep !
- \global\skippedmenuitemfalse
- \gotolocation
- {#4}% % needed
- {\ifrealreferencepage
- \ifcase\csname\??am\??am\csname#1\c!samepage\endcsname\endcsname\relax
- \copycsname#1\c!color\endcsname\csname#1\c!contrastcolor\endcsname
- \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \global\skippedmenuitemtrue
- \fi
- \else
- \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \fi}}%
- \ifskippedmenuitem\else\box\locationbox\fi}
-
-\def\setlocationboxnop#1[#2]#3[#4]%
- {\locationclickfalse
- \setbox\locationbox\hbox
- {\resetgoto % anders cyclische aanroep !
- \global\skippedmenuitemfalse
- \ifcase\csname\??am\??am\csname#1\c!unknownreference\endcsname\endcsname\relax
- \localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \localframed[#1][\c!empty=\v!yes,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \localframed[#1][\c!empty=\v!yes,\c!frame=,\c!background=,#2]{\dolocationattributes{#1}\c!style\c!color{#3}}%
- \or
- \global\skippedmenuitemtrue
- \fi}%
- \ifskippedmenuitem\else\box\locationbox\fi}
-
-\def\setlocationboxraw#1[#2]#3[#4]%
- {\localframed[#1][#2]{\dolocationattributes{#1}\c!style\c!color{#3}}}
-
-\def\setlocationbox#1[#2]#3[#4]%
- {\bgroup % really needed !
- \edef\permittedreferences{\csname#1\c!obstruction\endcsname}%
- \doifreferencepermittedelse{#4}%
- {\setlocationboxyes{#1}[#2]{#3}[#4]}%
- {\setlocationboxnop{#1}[#2]{#3}[#4]}%
- \egroup}
-
-\def\setlocationnop#1[#2]#3%
- {\localframed[#1][#2]{#3}}
-
-\def\executeamboxcommands#1#2#3#4#5%
- {%\processaction
- % [\getvalue{\??am#1\c!dummy}]
- % [ \v!yes=>\chardef\handleunknownmenuitem=0\relax,
- % \v!empty=>\chardef\handleunknownmenuitem=1\relax,
- % \v!no=>\chardef\handleunknownmenuitem=2\relax]%
- \getvalue{\??am#1#3}\relax
- \setamboxcommands{#1}{#4}%
- \ignorespaces#2\unskip
- \getvalue{\??am#1#5}}
-
-\newcounter\currentamposition
-
-\newtoks\everysetmenucommands
-
-\def\setamboxcommands#1#2%
- {\def\currentmenu{#1}% % kan nog eerder
- \def\currentsubmenu{#2}% % ? ?
- \doglobal\newcounter\currentamposition
- \the\everysetmenucommands}
-
-\def\menu@@amboxcommand#1\\%
- {\dontleavehmode
- \bgroup
- \ignorespaces#1\unskip\relax
- \ifskippedmenuitem \else
- \getvalue{\??am\currentmenu\currentsubmenu}%
- \fi
- \egroup
- \ignorespaces}
-
-\appendtoks
- \let\@@amboxcommand\menu@@amboxcommand
-\to \everysetmenucommands
-
-\def\menu@raw[#1]#2\\%
- {\@@amboxcommand\gotobox{\ignorespaces#2\unskip}[#1]\\}%
-
-\def\menu@but[#1]#2\\%
- {\@@amboxcommand\do@@amposition\currentmenu{#1}{\setlocationbox{\??am\currentmenu}[]{\ignorespaces#2\unskip}[#1]}\\}%
-
-\def\menu@got[#1]#2\\% pas op! offset
- {\@@amboxcommand\setlocationbox{\??am\currentmenu}[\c!frame=\v!off,\c!background=]{\ignorespaces#2\unskip}[#1]\\}%
-
-\def\menu@nop#1\\%
- {\@@amboxcommand\setlocationboxraw{\??am\currentmenu}[\c!frame=\v!off,\c!background=,\c!empty=\v!yes]{\ignorespaces#1\unskip}[]\\}%
-
-\def\menu@txt#1\\%
- {\@@amboxcommand\localframed[\??am\currentmenu][\c!frame=\v!off,\c!background=]{\ignorespaces#1\unskip}\\}%
-
-\def\menu@rul#1\\% ook \do@@amposition !
- {\@@amboxcommand\localframed[\??am\currentmenu][]{\ignorespaces#1\unskip}\\}%
-
-\def\menu@com#1\\%
- {\ignorespaces#1\unskip\ignorespaces}%
-
-\appendtoks
- \let\raw\menu@raw
- \let\but\menu@but
- \let\got\menu@got
- \let\nop\menu@nop
- \let\txt\menu@txt
- \let\rul\menu@rul
- \let\com\menu@com
-\to \everysetmenucommands
-
-\ifx\do@@amposition\undefined
- \let\do@@amposition\gobbletwoarguments % hook for positional thingies
-\fi
-
-\let\currentmenu\empty
-
-% beware : never change the concept of pbgoffset
-
-\def\menuparameter#1{\csname\??am\currentmenu#1\endcsname}
-
-\def\@@amhbox#1#2#3#4%
- {\def\currentmenu{#3}%
- \testinteractionmenu{#3}%
- \iflocationmenupermitted
- \bgroup
- \showcomposition
- \scratchdimen\dimexpr
- \makeupwidth
- +\pagebackgroundhoffset
- +\pagebackgroundhoffset
- -\menuparameter\c!leftoffset
- -\menuparameter\c!rightoffset
- \relax
- \setbox\scratchbox\hbox to \scratchdimen
- {\forgetall\executeamboxcommands{#3}{#4}\c!left\c!middle\c!right}%
- \setbox\scratchbox\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}%
- \wd\scratchbox\makeupwidth % geen \ht=#2 setting (yet)
- \hskip\dimexpr-\pagebackgroundhoffset+\menuparameter\c!leftoffset\relax
- \box\scratchbox
- \egroup
- \else
- #1\relax
- \fi}
-
-\def\@@amvbox#1#2#3#4% don't change skipping, this one works!
- {\def\currentmenu{#3}%
- \testinteractionmenu{#3}%
- \iflocationmenupermitted
- \bgroup
- \showcomposition
- \scratchdimen\dimexpr
- \textheight
- +\pagebackgroundvoffset
- +\pagebackgroundvoffset
- +\pagebackgrounddepth
- -\menuparameter\c!topoffset
- -\menuparameter\c!bottomoffset
- \relax
- \setbox\scratchbox\vbox to \scratchdimen
- {\forgetall % Voor't geval de afstand
- %\setupblank[\v!standard]% % (tijdelijk) is aangepast.
- \restorestandardblank
- \hsize#2\relax
- \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after}%
- \setbox\scratchbox\vbox{\hbox{\do@@ammenuposition{#3}{\box\scratchbox}}}%
- \setbox\scratchbox\vbox
- {\ht\scratchbox\zeropoint
- \vskip\dimexpr-\pagebackgroundvoffset+\menuparameter\c!topoffset\relax
- \box\scratchbox
- \vskip\pagebackgroundvoffset}% overbodig
- \ht\scratchbox\textheight
- \wd\scratchbox#2\relax
- \box\scratchbox
- \egroup
- \else
- #1\relax
- \fi}
-
-\ifx\do@@ammenuposition\undefined
- \let\do@@ammenuposition\gobbleoneargument % hook for positional thingies
-\fi
-
-\setvalue{\??am\s!do\v!right }{\@@amvbox{\dodummypageskip\v!right }\rightedgewidth}
-\setvalue{\??am\s!do\v!left }{\@@amvbox{\dodummypageskip\v!left }\leftedgewidth }
-\setvalue{\??am\s!do\v!top }{\@@amhbox{\dodummypageskip\v!top }\topheight }
-\setvalue{\??am\s!do\v!bottom}{\@@amhbox{\dodummypageskip\v!bottom}\bottomheight }
-
-\def\dointeractionmenu#1#2%
- {\getvalue{\??am\s!do\getvalue{\??am#1\c!location}}{#1}{#2}}
-
-\unexpanded\def\interactionmenu[#1]%
- {\getvalue{\??am\c!menu#1}}
-
-\def\horizontalinteractionmenu#1#2#3#4%
- {\ifdim#2>\zeropoint % new
- \scratchdimen\zeropoint
- \setbox\scratchbox\hbox
- {\def\docommand##1%
- {\doifnotvalue{\??am##1\c!state}\v!none
- {\hskip\scratchdimen
- \setbox2\hbox to #2
- {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
- \doifelsevalue{\??am##1\c!distance}\v!overlay
- {\scratchdimen\zeropoint
- \wd2\zeropoint}%
- {\scratchdimen\getvalue{\??am##1\c!distance}}%
- \box2}}%
- \startinteraction
- \processcommacommand[\getvalue{\??am#1}]\docommand
- \stopinteraction}%
- \wd\scratchbox#2\relax
- \box\scratchbox
- \fi}
-
-\def\verticalinteractionmenu#1#2#3#4%
- {\ifdim#2>\zeropoint % new
- \scratchdimen\zeropoint
- \setbox\scratchbox\vbox
- {\def\docommand##1%
- {\doifnotvalue{\??am##1\c!state}\v!none
- {\vskip\scratchdimen
- \setbox2\vbox to #2
- {\getvalue{\??am##1#3}\interactionmenu[##1]\getvalue{\??am##1#4}}%
- \doifelsevalue{\??am##1\c!distance}\v!overlay
- {\scratchdimen\zeropoint
- \offinterlineskip
- \dp2\zeropoint
- \ht2\zeropoint}%
- {\scratchdimen\getvalue{\??am##1\c!distance}}%
- \box2}}%
- \startinteraction
- \processcommacommand[\getvalue{\??am#1}]\docommand
- \stopinteraction}%
- \ht\scratchbox#2\relax
- \dp\scratchbox\zeropoint
- \box\scratchbox
- \fi}
-
-\letvalue{\??am\v!left }\empty
-\letvalue{\??am\v!right}\empty
-\letvalue{\??am\v!top }\empty
-\letvalue{\??am\v!bottom }\empty
-
-% todo : \defineinteractionmenuclass
-
-\def\interactionmenus[#1]%
- {\iflocation
- \getvalue{\??am\??am\c!menu#1}%
- \else
- \dodummypageskip{#1}%
- \fi}
-
-\setvalue{\??am\??am\c!menu\v!left }{\horizontalinteractionmenu\v!left \leftedgewidth \c!left \c!right}
-\setvalue{\??am\??am\c!menu\v!right }{\horizontalinteractionmenu\v!right \rightedgewidth\c!left \c!right}
-\setvalue{\??am\??am\c!menu\v!top }{\verticalinteractionmenu \v!top \topheight \c!before\c!after}
-\setvalue{\??am\??am\c!menu\v!bottom}{\verticalinteractionmenu \v!bottom\bottomheight \c!before\c!after}
-
-% this can be implemented with the following command (which
-% is new, undocumented, experimental, untested, etc etc)
-
-\def\defineinteractionmenuclass
- {\dodoubleargument\dodefineinteractionmenuclass}
-
-\def\dodefineinteractionmenuclass[#1][#2]% tag hori|veri
- {\doifelse{#2}\v!vertical
- {\setvalue{\??am\??am\c!menu#1}{\verticalinteractionmenu {#1}{\getvalue{\??am#1\c!width }}\c!before\c!after}}
- {\setvalue{\??am\??am\c!menu#1}{\horizontalinteractionmenu{#1}{\getvalue{\??am#1\c!height}}\c!left\c!right }}}
-
-% \setupinteraction[menu=on,state=start]
-%
-% \defineinteractionmenuclass[test] [vertical]
-% \defineinteractionmenuclass[another][horizontal]
-%
-% \defineinteractionmenu[test] [left][state=start,width=4cm]
-% \defineinteractionmenu[another][top] [state=start,height=1cm]
-%
-% \startinteractionmenu[test]
-% \but [firstpage] test-a \\
-% \but [nextpage] test-b \\
-% \stopinteractionmenu
-%
-% \startinteractionmenu[another]
-% \but [firstpage] test-a \\
-% \but [nextpage] test-b \\
-% \stopinteractionmenu
-%
-% \setupheadertexts[{\interactionmenu[another]}]
-%
-% \starttext
-%
-% test \interactionmenu[test] \page
-% test \interactionmenu[test] \page
-%
-% \stoptext
-
-%D This can save complicated menu macros when one want to
-%D keep control over parts of a menu (i.e.\ turn them on and
-%D off). We could have achieved something similar with modes.
-
-\def\local@@ambox#1#2#3#4% don't change skipping, this one works!
- {\bgroup
- \testinteractionmenu{#3}%
- \iflocationmenupermitted
- \executeamboxcommands{#3}{#4}\c!before\c!inbetween\c!after
- \else
- #1\relax
- \fi
- \egroup}
-
-\def\includemenu[#1]%
- {\doifvalue{\??am#1\c!state}\v!local
- {\bgroup
- \letvalue{\??am#1\c!state}\v!start
- \let\@@amvbox\local@@ambox
- \let\@@amhbox\local@@ambox
- \getvalue{\??am\c!menu#1}%
- \egroup}}
-
-%D We also need an explicit position control some day. I'll
-%D do that when I need it. [The stacking order.]
-
-\newif\ifextendedmenu
-
-% [name] [location]
-% [name] [location] [pars]
-
-\def\defineinteractionmenu
- {\dotripleempty\dodefineinteractionmenu}
-
-\def\dodefineinteractionmenu[#1][#2][#3]%
- {% main settings
- \letvalue{\??am\c!menu#1}\empty
- \setvalue{\@@dodolistelement#1}{\def\dosomelistelement{\dodomenulistelement{#1}}}%
- \presetlocalframed[\??am#1]%
- % register location
- \expanded{\addtocommalist{#1}\@EA\noexpand\csname\??am#2\endcsname}%
- % inherit settings
- \doifnot{#1}{#2}
- {\copyparameters[\??am#1][\??am#2]
- [\c!left,\c!middle,\c!right,\c!before,\c!after,\c!inbetween,%
- \c!width,\c!height,\c!distance,\c!offset,%
- \c!frame,\c!framecolor,\c!rulethickness,%
- \c!background,\c!backgroundcolor,\c!backgroundscreen,%
- \c!style,\c!color,\c!contrastcolor,\c!samepage,\c!unknownreference,%
- \c!leftoffset,\c!rightoffset,\c!topoffset,\c!bottomoffset]}%
- % additional settings
- \getparameters[\??am#1][\c!location=#2,\c!obstruction=,#3]}
-
-\def\setupinteractionmenu
- {\dodoubleargument\dosetupinteractionmenu}
-
-\def\dosetupinteractionmenu[#1][#2]%
- {\def\docommand##1{\getparameters[\??am##1][#2]}%
- \processcommalist[#1]\docommand}
-
-\expandafter\chardef\csname\??am\??am\v!yes \endcsname\zerocount
-\expandafter\chardef\csname\??am\??am\v!empty\endcsname\plusone
-\expandafter\chardef\csname\??am\??am\v!no \endcsname\plustwo
-\expandafter\chardef\csname\??am\??am\v!none \endcsname\plusthree
-\expandafter\chardef\csname\??am\??am \endcsname\plusone % default
-
-\processbetween{\v!interactionmenu}\dostartinteractionmenu
-
-\def\dostartinteractionmenu#1%
- {\dodostartinteractionmenu#1\dodostopinteractionmenu}
-
-\def\dodostartinteractionmenu[#1]#2\dodostopinteractionmenu
- {\setvalue{\??am\c!menu#1}{\extendedmenutrue\dointeractionmenu{#1}{#2}}}
-
-\def\resetinteractionmenu[#1]%
- {\letvalue{\??am\c!menu#1}\empty}
-
-\def\dodomenulistelement#1#2#3#4#5#6#7%
- {\setbox0=\hbox
- {\let\gotolocation\gobbleoneargument % hack to catch last []
- %\locationclickfalse % ipv ^
- \docheckrealreferencepage{#7}%
- \setlocationboxyes
- {\??am#1}% % needed !
- []% no settings
- {\limitatetext{#5}{\getvalue{\??li#2\c!maxwidth}}{\unknown}}% % needed !
- []}% normally the destination, catch by gobble
- \@@amboxcommand\do@@amposition{#1}{#7}% beware, we pass the pagenumber
- {\ignorespaces\linklisttoelement{#3}{#6}{#7}{\box0}\unskip}\\}
-
-% \scherm moet worden als \page
-
-\def\screen
- {\dosingleempty\doscreen}
-
-\def\doscreen[#1]%
- {\iflocation\page[#1]\fi}
-
-\unexpanded\def\menubutton
- {\dodoubleempty\domenubutton}
-
-\def\domenubutton[#1]%
- {\iffirstargument
- \ifsecondargument
- \@EAEAEA\domenubuttonB
- \else
- \doifassignmentelse{#1}
- {\@EAEAEA\domenubuttonC}
- {\@EAEAEA\domenubuttonD}%
- \fi
- \else
- \@EA\domenubuttonA
- \fi[#1]}
-
-\def\domenubuttonA[#1][#2]#3[#4]% normal button, no parameters
- {\bgroup
- %\locationdummytrue
- \setlocationbox\??bt[]{#3}[#4]%
- \egroup}
-
-\def\domenubuttonB[#1][#2]#3[#4]% menu button, with parameters
- {\bgroup
- %\locationdummytrue
- \setlocationbox{\??am#1}[#2]{#3}[#4]%
- \egroup}
-
-\def\domenubuttonC[#1][#2]#3[#4]% normal button, with parameters
- {\bgroup
- %\locationdummytrue
- \setlocationbox\??bt[#1]{#3}[#4]%
- \egroup}
-
-\def\domenubuttonD[#1][#2]#3[#4]% menu button, no parameters
- {\bgroup
- %\locationdummytrue
- \setlocationbox{\??am#1}[]{#3}[#4]%
- \egroup}
-
-\def\menubox
- {\dodoubleempty\domenubox}
-
-\def\domenubox[#1][#2]#3%
- {\bgroup
- \let\setlocationbox\setlocationboxraw
- \domenubutton[#1][#2]#3[]%
- \egroup}
-
-% Hier volgen de synchronisatiemacro's:
-
-\def\syncprefix{sync}
-\def\syncmarker{syncmark}
-
-%\definemarking[\syncmarker]
-%\setupmarking[\syncmarker][\c!expansie=\v!ja]
-
-\newmark\syncmarker
-
-\newcounter\synccounter
-
-\newif\ifsynchronisation
-
-\def\startsynchronization%
- {\iflocation\ifsynchronisation
- \doglobal\increment\synccounter
- \fi\fi}
-
-\def\stopsynchronization%
- {\iflocation\ifsynchronisation
- %\thisisdestination{\syncprefix:\synccounter}%
- \pagereference[\syncprefix:\synccounter]%
- \ifvmode
- \@EA\setmark\@EA\syncmarker\@EA{\synccounter} % \marking[\syncmarker]{\synccounter}%
- \else
- \showmessage\m!interactions4\synccounter
- \fi
- \fi\fi}
-
-\def\synchronize%
- {\startsynchronization
- \stopsynchronization}
-
-\def\dosetupsynchronization[#1]%
- {\getparameters[\??sy][#1]%
- \doifelse\@@systate\v!start
- \synchronisationtrue
- \synchronisationfalse}
-
-\def\setupsynchronization
- {\dosingleargument\dosetupsynchronization}
-
-\def\definesynchronization
- {\dosingleargument\dodefinesynchronization}
-
-\def\setupsynchronizationbar
- {\dodoubleargument\getparameters[\??ba]}
-
-\presetlocalframed[\??ba]
-
-\setvalue{synchronisatie\v!page}[#1]%
- {\bgroup
- %\setupinteraction[\c!width=\!!zeropoint]%
- \setinteractionparameter\c!width\!!zeropoint
- \setbox0\hbox
- {\localframed[\??ba][]{\dolocationattributes\??ba\c!style\c!color{\strut\@@batext}}}%
- \dontcomplain
- \def\atthebottom
- {\leaders\hrule\!!depth1ex\!!height-.5ex\hfil}%
- \def\atthetop##1##2##3%
- {\dimen0=\wd0
- \divide\dimen0 3
- \multiply\dimen0 ##2\relax
- \dimen2=.25em % brrr
- \advance\dimen0 -##3\dimen2
- %\gotodestination
- % {}{#1}{\syncprefix:##1}{}
- % {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}}%
- \gotobox
- {\hbox to \dimen0{\color[\locationcolor\@@bacolor]{\atthebottom}}}%
- [#1::\syncprefix:##1]}%
- \hbox
- {\def\check##1##2%
- {\edef##2{0##1\syncmarker}%
- \ifnum0##2=0 \def##2{1}\fi}%
- \check\gettopmark\top
- \check\getfirstmark\first
- \check\getbotmark\bot
- \setbox2\hbox to \wd0
- {\ifnum\top=\first\relax
- \ifnum\first=\bot\relax
- \atthetop\first30\relax
- \else
- \atthetop\first21\hss\atthetop\bot11\relax
- \fi
- \else
- \ifnum\first=\bot\relax
- \atthetop\top11\hss\atthetop\first21\relax
- \else
- \atthetop\top11\hss\atthetop\first11\hss\atthetop\bot11\relax
- \fi
- \fi}%
- \wd2=\zeropoint\box2
- \box0\relax}%
- \egroup}
-
-\setvalue{synchronisatie\v!local}[#1]%
- {\bgroup
- %\setupinteraction[\c!width=\!!zeropoint]%
- \setinteractionparameter\c!width\!!zeropoint
- \def\blackrule{\hbox{\vrule\!!height.5em\!!width.5em}}%
- %\gotodestination
- % {}{##1}{\syncprefix:#1}{0}
- % {\color[\locationcolor\@@bacolor]{\blackrule}}%
- \gotobox %
- {\color[\locationcolor\@@bacolor]{\blackrule}}%
- [#1::\syncprefix:\synccounter]%
- \egroup}
-
-\def\synchronizationbar[#1][#2]%
- {\iflocation\ifsynchronisation
- \bgroup
- \setupsynchronizationbar
- [\c!text=\getvalue{doc:des:#1},#2]%
- \getvalue{synchronisatie\@@baalternative}[#1]%
- \egroup
- \fi\fi}
-
-% A nice application of glue. All this code will be rewritten and
-% generalized.
-
-\newbox\interactionbarbox
-
-\newif\ifbarsymbol
-
-\def\dogotosomepage#1#2#3% nog checken !
- {\checkreferences % nodig ??
- \hbox
- {\iflocation
- \ifnum#3=\realpageno
- #2%
- \else
- \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
- \fi
- \else
- #2%
- \fi}}
-
-\def\dogotosomecontrastpage#1#2#3% nog checken, may replace previous
- {\checkreferences % nodig ??
- \hbox
- {\iflocation
- \ifnum#3=\realpageno
- \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!contrastcolor}{#2}}%
- \else
- \gotorealpage\empty\empty{#3}{\doifsomething{#1}{\dolocationattributes{#1}\c!style\c!color}{#2}}%
- \fi
- \else
- #2%
- \fi}}
-
-\presetlocalframed[\??ib]
-
-\def\interactionbara % we need better control over contrastcolor
- {\iflocation % maybe just use gotopage and set colors
- \bgroup
- \setinteractionparameter\c!width\zeropoint
- \setupblackrules[\c!height=\v!max,\c!depth=\v!max]%
- \!!widthb\dimexpr\@@ibwidth-2.75\emwidth\relax
- \!!widtha\dimexpr\!!widthb/\lastpage\relax
- \bgroup
- \advance\realpageno\minusone
- \ifvoid\interactionbarbox
- \bgroup
- \processaction
- [\@@ibstep]
- [ \v!small=>\scratchdimen.25\emwidth,
- \v!medium=>\scratchdimen.5\emwidth,
- \v!big=>\scratchdimen\emwidth,
- \s!unknown=>\scratchdimen\!!widtha]%
- \ifdim\!!widtha<\scratchdimen\relax
- \!!counta\numexpr\scratchdimen/\!!widtha\relax
- \else
- \!!counta\@@ibstep\relax
- \fi
- \!!widtha\!!counta\!!widtha
- \setbox\scratchbox\hbox{\blackrule[\c!width=\!!widtha,\c!color=middlegray]}% color here, else no mkiv
- \global\setbox\interactionbarbox\hbox to \!!widthb
- {\hss
- \dostepwiserecurse\plusone\lastpage\!!counta
- {\gotorealpage\empty\empty\recurselevel{\copy\scratchbox}}%
- \hss}%
- \global\wd\interactionbarbox\zeropoint
- \egroup
- \fi
- \egroup
- \noindent
- \strut
- \hbox to \@@ibwidth
- {\dontcomplain
- \setupblackrules[\c!width=\emwidth]%
- \dogotosomecontrastpage\??ib\blackrule\firstpage
- \hss
- \copy\interactionbarbox
- \hbox to \!!widthb
- {\ifdim\!!widtha<\emwidth
- \!!widtha\emwidth
- \fi
- \setupblackrules[\c!width=\!!widtha]%
- \ifnum\realpageno>\plusone
- \!!counta\numexpr\realpageno-\plustwo\relax
- \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
- \dogotosomepage\??ib\blackrule\prevpage
- \fi
- \dogotosomecontrastpage\??ib{\blackrule[\c!width=.5em]}\realpageno
- \ifnum\realpageno<\lastpage\relax
- \dogotosomepage\??ib\blackrule\nextpage
- \!!counta\numexpr\lastpage-\realpageno-\plusone\relax
- \hskip\zeropoint\!!plus\!!counta \s!sp\relax % cm gives overflow
- \fi}%
- \hss
- \dogotosomecontrastpage\??ib\blackrule\lastpage}%
- \egroup
- \fi}
-
-\def\interactionbarb
- {\ifnum\lastpage>\firstpage\relax
- \interactionbuttons[\v!firstpage,\v!previouspage,\v!nextpage,\v!lastpage]%
- \fi}
-
-\def\interactionbarc
- {\iflocation
- \ifnum\lastpage>\plusone
- \hbox to \@@ibwidth
- {\setupblackrules[\c!height=\@@ibheight,\c!depth=\@@ibdepth]%
- \scratchdimen\dimexpr(\@@ibwidth-4\emwidth)/\numexpr\lastpage+\minusone\relax\relax
- \!!widtha\numexpr\realpageno+\minusone\relax\scratchdimen
- \!!widthb\numexpr\lastpage-\realpageno\relax\scratchdimen
- \startcolor[\locationcolor\@@ibcolor]%
- \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\firstpage
- \hss
- \dogotosomepage\empty{\blackrule[\c!width=\!!widtha]}\prevpage
- \color[\@@ibcontrastcolor]{\blackrule[\c!width=\emwidth]}%
- \dogotosomepage\empty{\blackrule[\c!width=\!!widthb]}\nextpage
- \hss
- \dogotosomepage\empty{\blackrule[\c!width=\emwidth]}\lastpage
- \stopcolor}%
- \fi
- \fi}
-
-\def\interactionbard
- {\iflocation\ifshowingsubpage
- \ifnum\nofsubpages>\plusone
- \hbox \bgroup
- \setinteractionparameter\c!width\!!zeropoint
- \ifbarsymbol
- \setupsymbolset[\@@iasymbolset]%
- \def\dogotox##1%
- {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi]}}%
- \else
- \def\dogotox##1%
- {\hbox{\vrule\!!height\@@ibheight\!!depth \@@ibdepth\!!width \@@ibwidth}}%
- \fi
- \dostepwiserecurse\plusone\nofsubpages\plusone
- {\bgroup
- \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
- \ifnum\scratchcounter<\realpageno\relax
- \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
- \else\ifnum\scratchcounter=\realpageno\relax
- \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
- \else
- \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
- \fi\fi
- \egroup
- \hskip\@@ibdistance}%
- \unskip % not needed
- \egroup
- \fi
- \fi\fi}
-
-\def\interactionbare% KAN WORDEN GECOMBINEERD MET D
- {\iflocation\ifshowingsubpage
- \ifnum\nofsubpages>\plusone
- \bgroup
- \!!widthb\dimexpr\nofsubpages\dimexpr\@@ibdistance\relax-\@@ibdistance\relax % (n-1)
- \!!widtha\dimexpr(\@@ibwidth-\!!widthb)/\nofsubpages\relax
- \ifdim\!!widtha<\@@ibdistance\relax
- \interactionbarf
- \else
- \setinteractionparameter\c!width\!!zeropoint
- \noindent
- \hbox to \@@ibwidth
- \bgroup
- \ifbarsymbol
- \setupsymbolset[\@@iasymbolset]%
- \def\dogotox##1%
- {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!next\fi}}%
- \else
- \def\dogotox##1%
- {\hbox{\vrule\!!height\@@ibheight\!!depth\@@ibdepth\!!width\!!widtha}}%
- \fi
- \dostepwiserecurse\plusone\nofsubpages\plusone
- {\bgroup
- \scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
- \ifnum\scratchcounter<\realpageno\relax
- \dogotosomecontrastpage\??ib{\dogotox0}\scratchcounter
- \else\ifnum\scratchcounter=\realpageno\relax
- \dogotosomecontrastpage\??ib{\dogotox1}\scratchcounter
- \else
- \dogotosomecontrastpage\??ib{\dogotox2}\scratchcounter
- \fi\fi
- \egroup
- \hss}%
- \unskip
- \egroup
- \fi
- \egroup
- \fi
- \fi\fi}
-
-\def\interactionbarf % !! KAN WORDEN GECOMBINEERD MET D !!
- {\iflocation\ifshowingsubpage
- \ifnum\nofsubpages>\plusone
- \setinteractionparameter\c!width\!!zeropoint
- \noindent
- \hbox to \@@ibwidth
- \bgroup
- \!!countb\zerocount
- \loop % todo: \doloop
- \advance\!!countb \plusone
- %\!!countc\nofsubpages \divide\!!countc \!!countb \advance\!!countc \plusone
- \!!countc\numexpr(\nofsubpages/\!!countb)+\plusone\relax % rounding
- \!!widthb\@@ibdistance
- \multiply\!!widthb \!!countc
- \advance\!!widthb -\@@ibdistance
- \!!widtha\@@ibwidth
- \advance\!!widtha -\!!widthb
- \divide\!!widtha \!!countc
- \ifdim\!!widtha<\@@ibdistance\relax
- \repeat
- \ifnum\!!countc>\plusone
- % this is not that well tested
- \advance\!!countc \minustwo
- \!!widtha-\@@ibdistance
- \!!widtha\!!countc\!!widtha
- \advance\!!widtha \@@ibwidth
- \advance\!!countc \plusone
- \divide\!!widtha \!!countc
- \fi
- \ifbarsymbol
- \setupsymbolset[\@@iasymbolset]%
- \def\dogotox##1%
- {\hbox{\symbol[\ifcase##1 \v!previous\or\v!somewhere\or\v!somewhere\or\v!somewhere\or\v!next\fi}}%
- \else
- \def\dogotox##1%
- {\hbox
- {\!!heighta\@@ibheight
- \!!deptha\@@ibdepth
- \ifcase##1\relax
- \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
- \or
- \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
- \or
- \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
- \or
- \vrule\!!height.5\!!heighta\!!depth.5\!!deptha\!!width\!!widtha
- \or
- \vrule\!!height \!!heighta\!!depth \!!deptha\!!width\!!widtha
- \fi}}%
- \fi
- \!!countc\numexpr\realpageno-\plustwo\relax
- \!!countd\numexpr\realpageno+\plustwo\relax
- \ifnum\!!countc<\plusone \!!countc\plusone \fi
- \!!countf\zerocount
- \dostepwiserecurse\firstsubpage\lastsubpage\plusone
- {\!!doneafalse
- \advance\!!countf \plusone
- \ifnum\recurselevel=\firstsubpage\relax \!!doneatrue \fi
- \ifnum\recurselevel=\lastsubpage\relax \!!doneatrue \fi
- \if!!donea
- \ifnum\recurselevel<\realpageno
- \dogotosomecontrastpage\??ib{\dogotox0}\recurselevel
- \else\ifnum\recurselevel>\realpageno
- \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
- \else
- \dogotosomecontrastpage\??ib{\dogotox4}\recurselevel
- \fi\fi
- \hss
- \!!countf\zerocount
- \else\ifnum\!!countf=\!!countb
- \ifnum\recurselevel<\realpageno
- \dogotosomecontrastpage\??ib{\dogotox1}\recurselevel
- \else\ifnum\recurselevel>\realpageno
- \dogotosomecontrastpage\??ib{\dogotox3}\recurselevel
- \else
- \dogotosomecontrastpage\??ib{\dogotox2}\recurselevel
- \fi\fi
- \hss
- \!!countf\zerocount
- \fi\fi}%
- \unskip
- \egroup
- \fi
- \fi\fi}
-
-\def\interactionbarg
- {\ifnum\lastsubpage>\firstsubpage\relax
- \interactionbuttons[\v!firstsubpage,\v!previoussubpage,\v!nextsubpage,\v!lastsubpage]%
- \fi}
-
-\def\checkinteractionbar#1#2#3%
- {\ifdim\@@ibwidth=\zeropoint\def\@@ibwidth{#1}\fi
- \doifnothing\@@ibheight{\def\@@ibheight{#2}}%
- \doifnothing\@@ibdepth{\def\@@ibdepth{#3}}}
-
-\def\complexinteractionbar[#1]%
- {\doifelse{#1}\v!reset
- {\global\setbox\interactionbarbox\box\voidb@x}%
- {\bgroup
- \iflocation
- \checksubpages % goes wrong / loads \numberofpages too
- \getparameters[\??ib][#1]%
- \doif\@@ibstate\v!start
- {\startinteraction
- \processaction % breedte defaults !
- [\@@ibalternative]
- [ c=>\checkinteractionbar{10em}\v!max \v!max,
- d=>\checkinteractionbar{.5em}{.5em} \!!zeropoint,
- e=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
- f=>\checkinteractionbar{10em}{.5em} \!!zeropoint,
- \s!default=>\checkinteractionbar{10em}\v!broad\!!zeropoint,
- \s!unknown=>\checkinteractionbar{10em}\v!broad\!!zeropoint]%
- \doifelse\@@ibsymbol\v!yes
- \barsymboltrue\barsymbolfalse
- \getvalue{interactionbar\@@ibalternative}%
- \stopinteraction}%
- \fi
- \egroup}}
-
-\definecomplexorsimpleempty\interactionbar
-
-\def\setupinteractionbar
- {\dodoubleargument\getparameters[\??ib]}
-
-% Er wordt vooralsnog uitgegaan van een symmetrische
-% start-stop situatie.
-
-\def\c!profiel!! {profiel:} % brrr
-\def\c!versie!! {versie:}
-
-\def\dodefineprofile[#1][#2]%
- {\iflocation
- \def\dododefineprofile##1%
- {\def\dodododefineprofile####1%
- {\doifdefinedelse{\c!profiel!!####1}%
- {\edef\!!stringa{\getvalue{\c!profiel!!####1}}%
- \setevalue{\c!profiel!!####1}{\!!stringa,##1}}%
- {\setevalue{\c!profiel!!####1}{##1}}}%
- \processcommalist[#2]\dodododefineprofile}%
- \processcommalist[#1]\dododefineprofile
- \fi}
-
-\def\defineprofile%
- {\dodoubleargument\dodefineprofile}
-
-% Als met \getpar wordt gewerkt, dan moet \next worden toegepast.
-
-% TZT initialisatie!
-
-\def\profilepage{}
-
-\let\dosetprofilepage\relax
-\let\dogetprofilepage\relax
-
-\def\processprofile#1[#2]%
- {\iflocation
- \par % needed for pdftex
- \bgroup
- \dosetprofilepage
- \dogetprofilepage
- \def\processoneprofile##1##2%
- {\ExpandBothAfter\doifinsetelse{##2}{\processedprofiles}%
- {\doifsomething{##1}{(##1)}}%
- {\addtocommalist{##2}\processedprofiles
- ##1\relax
- \ifcase#1\relax
- \dobeginofprofile{##2}\paperwidth\paperheight\profilepage
- \else
- \doendofprofile
- \fi}}%
- \let\processedprofiles\empty
- \def\doprocessprofile##1%
- {\doifelse{\@@pfoption}{\v!test}%
- {\goodbreak\blank\nobreak\tt[\space
- \ifcase#1\v!start\else\v!stop\fi profiel\space ##1:\space
- \doifdefinedelse{\c!profiel!!##1}%
- {\def\dodoprocessprofile####1%
- {\processoneprofile
- {\goto{####1}[\c!profiel!!####1]}%
- {####1}%
- \space}%
- \processcommacommand
- [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}%
- {- }%
- ]\nobreak\blank}%
- {\doifdefined{\c!profiel!!##1}%
- {\def\dodoprocessprofile####1%
- {\processoneprofile{}{####1}}%
- \processcommacommand
- [\getvalue{\c!profiel!!##1}]\dodoprocessprofile}}}%
- \processcommalist[#2]\doprocessprofile
- \egroup
- \par % needed for pdftex
- \fi}
-
-\def\startprofile[#1]%
- {\iflocation
- \bgroup
- \addtocommalist{#1}\actualprofile
- \def\stopprofile%
- {\processprofile1[#1]%
- \egroup}%
- \def\next{\processprofile0[#1]}% % \DoAfterFi \processprofile0[#1]%
- \else % ^^^^^^^^^^ will be obsolete
- \let\next\relax % since ugly and never used
- \fi
- \next}
-
-\let\stopprofile\relax
-
-\def\dofollowprofile#1[#2]%
- {\iflocation
- \hbox
- {\dohandlegoto
- {\dolocationattributes\??ia\c!style\c!color{#1\presetgoto}}%
- {\dostartgotoprofile\buttonwidth\buttonheight{#2}}%
- {\dostopgotoprofile}}%
- \else
- {#1}%
- \fi}
-
-\def\followprofile#1[#2]%
- {\iflocation
- \doif\@@pfoption\v!test{\pagereference[\c!profiel!!#2]}%
- \dofollowprofile{#1}[#2]%
- \fi}
-
-\def\setupprofiles%
- {\dodoubleargument\getparameters[\??pf]}
-
-% Als er nog geen tekst op de pagina staat, dan heeft het
-% profiel betrekking op het bovenstaande, dus soms een vorige
-% pagina! Vreemd, omdat PDF paginagewijs werkt. Gelukkig
-% biedt /page een oplossing. Echter: expansie van een
-% \special kan niet worden uitgesteld, zodat alleen een
-% two-pass een oplossing vormt. Het onderstaande kan komen
-% te vervallen als Acrobat dit ondervangt. Het scheelt een
-% pass en een lijst.
-%
-% Er kunnen eventueel twee lijsten worden gebruikt. Een voor
-% het begin (start) en een voor het eind (stop). Nu staat
-% alles in een lijst.
-
-\definetwopasslist\s!profile
-
-\newcounter\currentprofile
-
-\def\dosetprofilepage%
- {\doglobal\increment\currentprofile
- \lazysavetwopassdata{\s!profile}{\currentprofile}{\noexpand\realfolio}}
-
-\def\dogetprofilepage%
- {\gettwopassdata{\s!profile}%
- \let\profilepage=\twopassdata}
-
-% is this stuff used at all
-
-\newcounter\versionlevel
-\newcounter\versionorder
-
-\newif\ifrecentversion
-
-\let\oldatcharacter=@
-
-\def\minimumversion{0}
-\def\actualversion{0}
-
-\def\dosetupversions[#1]%
- {\getparameters[\??ve][#1]
- \stripcharacter.\from\@@venumber\to\minimumversion}
-
-\def\setupversions
- {\dosingleargument\dosetupversions}
-
-\definetwopasslist\s!versionbegin
-\definetwopasslist\s!versionend
-
-\let\actualprofile\empty
-
-\def\doresetpageversion
- {\lazysavetwopassdata{\s!versionend}{\versionorder}{\noexpand\realfolio}}
-
-\def\dosetpageversion#1%
- {\recentversiontrue
- \doglobal\increment\versionorder\relax
- \lazysavetwopassdata{\s!versionbegin}{\versionorder}{\noexpand\realfolio}%
- \let\resetpageversion\doresetpageversion}
-
-\def\recentcontributions{}
-
-\def\checkrecentcontributions%
- {\gettwopassdata{\s!versionbegin}%
- \iftwopassdatafound
- \!!counta\twopassdata\relax
- \gettwopassdata{\s!versionend}%
- \iftwopassdatafound
- \!!countb\twopassdata\relax
- \doglobal\increment\versionorder\relax
- \savetwopassdata{\s!versionbegin}{\versionorder}{\the\!!counta}%
- \savetwopassdata{\s!versionend }{\versionorder}{\the\!!countb}%
- \dostepwiserecurse\!!counta\!!countb\plusone
- {\@EA\doglobal\@EA\addtocommalist\@EA{\recurselevel}{\recentcontributions}}%
- \let\next\checkrecentcontributions
- \else
- \let\next\relax
- \fi
- \else
- \let\next\relax
- \fi
- \next}
-
-\def\docheckpageversion
- {\ExpandBothAfter\doifinsetelse{\realfolio}{\recentcontributions}
- {\pageselectedtrue}%
- {\pageselectedfalse}}
-
-\let\setpageversion \gobbleoneargument
-\let\resetpageversion \relax
-\let\checkpageversion \relax
-
-\def\complexstartversion[#1]%
- {\bgroup
- \doifelsenothing\actualprofile
- {\startprofile[#1]}%
- {\startprofile[#1,\actualprofile]}%
- \def\docomplexstartversie##1%
- {\stripcharacter.\from##1\to\actualversion
- \ifnum\versionlevel>\zerocount\relax
- \ifnum\actualversion=\zerocount
- \setpageversion\actualversion % unknown version
- \else
- \ifnum\actualversion<\minimumversion\relax
- \relax % old version
- \else
- \setpageversion\actualversion % new version
- \fi
- \fi
- \fi}%
- \doglobal\increment\versionlevel\relax
- \doifelsenothing{#1}
- {\docomplexstartversie{0}}%
- {\processcommalist[#1]\docomplexstartversie}}
-
-\definecomplexorsimpleempty\startversion
-
-\def\stopversion
- {\stopprofile
- \doglobal\decrement\versionlevel
- \ifnum\versionlevel<\zerocount
- \showmessage\m!versions1\empty
- \else
- \resetpageversion
- \egroup
- \fi}
-
-\def\markversion
- {\showmessage\m!versions2\empty
- \let\setpageversion\dosetpageversion
- \let\resetpageversion\relax
- \let\checkpageversion\relax}
-
-\def\selectversion
- {\checkrecentcontributions
- \showmessage\m!versions3\recentcontributions
- \let\setpageversio\gobbleoneargument
- \let\resetpageversion\relax
- \let\checkpageversion\docheckpageversion}
-
-\def\dodefineversion[#1][#2]%
- {\setvalue{\c!versie!!#1}{#2}%
- \defineprofile[#1][#2]}
-
-\def\defineversion
- {\dodoubleargument\dodefineversion}
-
-\def\followversion
- {\followprofile}
-
-\def\followprofileversion#1[#2][#3]%
- {\def\docommand##1%
- {\defineprofile[#2#3][##1]}%
- \processcommacommand[\getvalue{\c!versie!!#3}]\docommand
- \followprofile#1[#2#3]}
-
-\newcounter\currentpagetransition
-
-\newif\ifrandomtransitions
-
-\def\setuppagetransitions%
- {\dosingleempty\dosetuppagetransitions}
-
-\def\dosetuppagetransitions[#1]%
- {\doifelsenothing{#1}
- {\doifnot\@@scdelay\v!none
- {\let\setpagetransition\setsomepagedelay}}
- {\doifelse{#1}\v!start
- {\doifnot\@@scdelay\v!none
- {\let\setpagetransition\setsomepagedelay}}
- {\doglobal\newcounter\currentpagetransition
- \doifinsetelse{#1}{\v!reset,\v!stop}
- {\let\setpagetransition\relax}
- {\let\setpagetransition\setsomepagetransition
- \doifinsetelse\v!random{#1}
- {\randomtransitionstrue}{\randomtransitionsfalse}%
- \edef\userpagetransitions{#1}%
- \@EA\removefromcommalist\@EA{\v!random}\userpagetransitions
- \ifx\userpagetransitions\empty
- \let\userpagetransitions\pagetransitions
- \fi}}}}
-
-\def\setsomepagedelay
- {\expanded{\dosetpagetransition{0}{\@@scdelay}}}
-
-\def\setsomepagetransition
- {\iflocation
- \ifrandomtransitions
- \expanded{\getcommalistsize[\userpagetransitions]}%
- \getrandomnumber\currentpagetransition1\commalistsize
- \else
- \doglobal\increment\currentpagetransition
- \fi
- \expanded{\getfromcommalist[\userpagetransitions][\currentpagetransition]}%
- \doifnumberelse\commalistelement
- {\expanded{\getfromcommalist[\pagetransitions][\commalistelement]}}
- {}%
- \ifx\commalistelement\empty
- \doglobal\newcounter\currentpagetransition
- \setsomepagetransition
- \else
- \doifelse\@@scdelay\v!none
- {\expanded{\dosetpagetransition{\commalistelement}{0}}}
- {\expanded{\dosetpagetransition{\commalistelement}{\@@scdelay}}}%
- \fi
- \fi}
-
-\prependtoks \setpagetransition \to \everyshipout
-
-% temporary here
-
-%D \startbuffer
-%D \dorecurse{10}
-%D {\horizontalpositionbar
-%D \pos\recurselevel \min1 \max10
-%D \token\framed{\recurselevel}%
-%D \\}
-%D
-%D \hbox to 15em
-%D {\hss
-%D \dorecurse{10}
-%D {\verticalpositionbar\pos\recurselevel\min1\max10\token\blackrule\\
-%D \hss}}
-%D \stopbuffer
-
-\def\horizontalpositionbar\pos#1\min#2\max#3\token#4\\%
- {\hbox to \hsize
- {\hskip\zeropoint\!!plus #1\!!fill
- \hskip\zeropoint\!!plus-#2\!!fill
- #4\relax
- \hskip\zeropoint\!!plus #3\!!fill
- \hskip\zeropoint\!!plus-#1\!!fill}}
-
-\def\verticalpositionbar\pos#1\min#2\max#3\token#4\\%
- {\vbox to \vsize
- {\vskip\zeropoint\!!plus #1\!!fill
- \vskip\zeropoint\!!plus-#2\!!fill
- \hbox{#4}\relax
- \vskip\zeropoint\!!plus #3\!!fill
- \vskip\zeropoint\!!plus-#1\!!fill}}
-
-\def\horizontalgrowingbar\pos#1\min#2\max#3\height#4\depth#5\\%
- {\hbox to \hsize
- {\scratchcounter#1%
- \advance\scratchcounter -#2%
- \advance\scratchcounter \plusone
- \leaders\vrule\hskip\zeropoint\!!plus \scratchcounter\!!fill
- \vrule\!!width\zeropoint\!!height#4\!!depth#5%
- \hskip\zeropoint\!!plus #3\!!fill
- \hskip\zeropoint\!!plus-#1\!!fill}}
-
-\def\verticalgrowingbar\pos#1\min#2\max#3\width#4\\%
- {\vbox to \vsize
- {\scratchcounter#1%
- \advance\scratchcounter -#2%
- \advance\scratchcounter \plusone
- \leaders\hrule\vskip\zeropoint\!!plus\scratchcounter\!!fill
- \hrule\!!width#4\!!height\zeropoint\!!depth\zeropoint
- \vskip\zeropoint\!!plus #3\!!fill
- \vskip\zeropoint\!!plus-#1\!!fill}}
-
-\newbox\commentbox
-
-\def\doflushcommentanchors
- {\let\next\relax % new
- \processaction
- [\@@cclocation]
- [% \v!text=>\let\next\relax, % new
- \v!inmargin=>\let\next\inmargin, % brr not the same as inleft|rightmargin
- \v!leftedge=>\let\next\inleftedge,
- \v!rightedge=>\let\next\inrightedge,
- \v!leftmargin=>\let\next\inleftmargin,
- \v!rightmargin=>\let\next\inrightmargin]%
- \next{\hbox{\raise\strutht\box\commentbox}}}
-
-\def\flushcommentanchors % in everypar so indirect
- {\ifvoid\commentbox\else \doflushcommentanchors \fi}
-
-\def\setupcomment
- {\dodoubleargument\getparameters[\??cc]}
-
-\setvalue{\e!start\v!comment}% the dummy triple gobbles trailing spaces
- {\dotripleempty\dostartcommentaar}
-
-\def\comment
- {\dodoubleempty\docomment}
-
-\def\dodocomment#1%
- {\!!widtha\@@ccwidth
- \!!heighta\@@ccheight
- \doifelse\@@ccoption\v!max
- {\let\@@ccopen \!!plusone}{\let\@@ccopen \!!zerocount}%
- \doifelse\@@ccoption\v!buffer
- {\let\@@cccollect\!!plusone}{\let\@@cccollect\!!zerocount}%
- \preparecommentvariables
- \doinsertcomment
- \@@cctitle\!!widtha\!!heighta
- \@@cccolor\@@ccopen\@@ccsymbol
- \@@cccollect{#1}}
-
-\def\preparecommentvariables % more will move here as with fields
- {\let\@@DriverCommentLayer\@@cctextlayer}
-
-\def\dopreparecommentaar#1#2%
- {\doifassignmentelse{#1}
- {\getparameters[\??cc][#1]}
- {\getparameters[\??cc][\c!title=#1,#2]}%
- \obeylines
- \doif\@@ccspace\v!yes\obeyspaces}
-
-\def\dostartcommentaar[#1][#2][#3]%
- {\bgroup
- \doifelse\@@ccstate\v!start
- {\dopreparecommentaar{#1}{#2}%
- \long\def\docommand##1%
- {\global\setbox\commentbox\frozenhbox
- {\hbox to \zeropoint
- {\struttedbox{\tbox{\dodocomment{##1}}}\hss}%
- \hskip\ifvoid\commentbox\@@ccmargin\else\@@ccdistance\fi
- \box\commentbox}%
- \egroup}}%
- {\long\def\docommand##1%
- {\egroup}}%
- \grabuntil{\e!stop\v!comment}\docommand}
-
-\letvalue{\e!stop\v!comment}\relax % handy for \expanded{...}
-
-\def\docomment[#1][#2]#3%
- {\doif\@@ccstate\v!start
- {\hbox to \zeropoint
- {\dopreparecommentaar{#1}{#2}%
- \hskip-\@@ccmargin
- \struttedbox{\tbox{\dodocomment{#3}}\hss}}}%
- \ignorespaces}
-
-% \startcomment
-% hello beautiful\\world
-% \stopcomment
-%
-% \startcomment[hello]
-% hello << \'e\'erste >>
-% beautiful
-% world
-% \stopcomment
-%
-% \startcomment[hello][color=green,width=4cm,height=3cm]
-% hello \leftguillemot\ \'e\'erste \rightguillemot\
-% beautiful
-% world
-% \stopcommentaar
-%
-% \startcomment[hello][color=green,width=4cm,height=3cm]
-% hello \leftguillemot\ \'e\'erste \rightguillemot\ test
-%
-% beautiful
-%
-% world
-% \stopcomment
-%
-% \startcomment[symbol=Balloon]
-% Do we want this kind of rubish? And, why isn't this and
-% some more features related to text annotations so poorly
-% (actually not) documented? Anyhow, by providing this
-% functionality we demonstrate that \pdfTeX\ can do it. By
-% the way, it's funny that when in Acrobat we scale up the
-% text, the symbols scale down.
-% \stopcomment
-
-% \definesymbol [comment-normal][{\externalfigure[cow.pdf]}]
-% \definesymbol [comment-down] [{\externalfigure[cow.pdf]}]
-%
-% \def\CowSymbol#1#2%
-% {\scale
-% [\c!height=#1]
-% {\startMPcode
-% loadfigure "koe.mp" number 1 ;
-% refill currentpicture withcolor #2 ;
-% \stopMPcode}}
-%
-% \definesymbol [comment-normal]
-% [\CowSymbol{4ex}{red}]
-%
-% \definesymbol [comment-down]
-% [\CowSymbol{4ex}{green}]
-%
-% \setupcomment
-% [\c!symbol={comment-normal,comment-down},
-% \c!option=\v!buffer]
-%
-% \setupfootertexts[\placecomments]
-
-\def\placecomments
- {\doflushcomments}
-
-% \setupinteraction[state=start]
-%
-% \useattachment[test.tex]
-% \useattachment[whatever][test.tex]
-% \useattachment[whatever][newname][test.tex]
-% \useattachment[whatever][title][newname][test.tex]
-%
-% % \setupattachments[\c!symbol={symbol-normal,symbol-down}]
-%
-% \starttext \attachment[whatever] \stoptext
-
-\definesystemvariable{at}
-
-\def\useattachment
- {\doquadrupleempty\douseattachment}
-
-\def\douseattachment[#1][#2][#3][#4]% tag title newname filename
- {\iffourthargument
- \setgvalue{\??at:#1}{{#2}{#3}{#4}}% tooltip kind of case
- \else\ifthirdargument
- \setgvalue{\??at:#1}{{#2}{#2}{#3}}% full path case
- \else\ifsecondargument
- \setgvalue{\??at:#1}{{#2}{#2}{#2}}% obvious case
- \else
- \setgvalue{\??at:#1}{{#1}{#1}{#1}}% worst case
- \fi\fi\fi}
-
-\let\attachmenttitle\empty
-\let\attachmentname \empty
-\let\attachmentfile \empty
-
-\def\getattachmentdata[#1]%
- {\edef\attachmenttitle{\filterfromvalue{\??at:#1}31}% description
- \edef\attachmentname {\filterfromvalue{\??at:#1}32}% new name
- \edef\attachmentfile {\filterfromvalue{\??at:#1}33}% original
- \expandafter\splitstring\attachmentname\at.\to\!!stringa\and\!!stringb
- \ifx\!!stringb\empty % no suffix, so we need to inherit it
- \expandafter\splitstring\attachmentfile\at.\to\!!stringc\and\!!stringd
- \edef\attachmentname{\attachmentname.\!!stringd}%
- \fi}
-
-\def\attachment
- {\dodoubleempty\doattachment}
-
-\def\doattachment[#1][#2]% currently title equals newname
- {\iflocation
- \ifsecondargument
- \doifundefined{\??at:#2}
- {\showmessage\m!interactions6{#2}%
- \useattachment[#2]}%
- \doif\@@atstate\v!start
- {\bgroup
- \getattachmentdata[#2]%
- \doiffileelse\attachmentfile
- {\setupattachments[#1]%
- \presetattachmentvariables
-\struttedbox{\tbox{%
- \doattachfile
- \attachmenttitle
- {1em}\strutheight\strutdepth\@@atcolor\@@atsymbol
- \attachmentname
- \attachmentfile}%
-}}%
- {\showmessage\m!interactions5\attachmentfile}%
- \egroup}%
- \else\iffirstargument
- \attachment[][#1]%
- \fi\fi
- \fi}
-
-\def\presetattachmentvariables
- {\let\@@DriverAttachmentLayer\@@attextlayer}
-
-\def\setupattachments
- {\dodoubleempty\getparameters[\??at]}
-
-\setupattachments
- [\c!state=\v!start,
- \c!color=\@@iacolor,
- \c!textlayer=,
- \c!symbol=]
-
-% jammer, tussen/midden had erin gemoeten; \c!commando toevoegen
-
-\def\registermenucommand#1%
- {{\textonly\noindent#1\space}} % no math switching
-
-\def\doregistermenubuttons[#1][#2]% [menu id] [register]
- {\bgroup
- \ifsecondargument
- \setupinteractionmenu
- [#1][\c!unknownreference=\v!yes,\c!samepage=\v!yes]%
- \def\docommand##1%
- {\registermenucommand{\menubutton[#1]{##1}[#2:##1]}}%
- \else
- \def\docommand##1%
- {\registermenucommand
- {\button
- [\c!unknownreference=\v!yes,\c!samepage=\v!yes]
- {##1}[#1:##1]}}%
- \fi
- \handletokens abcdefghijklmnopqrstuvwxyz\with\docommand % moet anders
- \egroup}
-
-\def\registermenubuttons
- {\dodoubleempty\doregistermenubuttons}
-
-\stelkoppelingenin
- [\c!distance=.25em,
- \c!width=\v!fit,
- \c!location=\v!low,
- \c!color=\@@iacolor,
- \c!frame=\v!off,
- \c!background=,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=]
-
-\defineinteractionmenu
- [\v!right]
- [\v!right]
- [\c!before=,
- \c!after=\vfil,
- \c!inbetween=\blank,
- \c!distance=\bodyfontsize, % 12pt
- \c!left=\hss,
- \c!right=\hss,
- \c!width=\rightedgewidth,
- \c!height=\v!broad]
-
-\defineinteractionmenu
- [\v!left]
- [\v!left]
- [\c!before=,
- \c!after=\vfil,
- \c!inbetween=\blank,
- \c!distance=\bodyfontsize, % 12pt
- \c!left=\hss,
- \c!right=\hss,
- \c!width=\leftedgewidth,
- \c!height=\v!broad]
-
-\defineinteractionmenu
- [\v!bottom]
- [\v!bottom]
- [\c!before=\vss,
- \c!after=\vss,
- \c!middle=\hfil,
- \c!distance=\bodyfontsize, % 12pt
- \c!width=\v!fit,
- \c!height=\v!broad]
-
-\defineinteractionmenu
- [\v!top]
- [\v!top]
- [\c!before=\vss,
- \c!after=\vss,
- \c!middle=\hfil,
- \c!distance=\bodyfontsize, % 12pt
- \c!width=\v!fit,
- \c!height=\v!broad]
-
-\setupinteractionmenu
- [\v!left,\v!right,\v!top,\v!bottom]
- [\c!offset=.25em,
- \c!position=\v!no,
- \c!frame=\v!on,
- \c!background=,
- \c!backgroundcolor=,
- \c!backgroundscreen=\@@rsscreen,
- \c!style=\@@iastyle,
- \c!color=\@@iacolor,
- \c!contrastcolor=\@@iacontrastcolor,
- \c!state=\v!start,
- \c!samepage=\v!yes,
- \c!unknownreference=\v!empty,
- \c!topoffset=\!!zeropoint,
- \c!bottomoffset=\!!zeropoint,
- \c!leftoffset=\!!zeropoint,
- \c!rightoffset=\!!zeropoint]
-
-\def\placeleftedgetextblock % Is \hss/\hsize really needed here?
- {\hbox to \leftedgewidth % (check outer level and settings)
- {\hsize\leftedgewidth\hss\interactionmenus[\v!left]}}
-
-\def\placerightedgetextblock % Is \hss/\hsize really needed here?
- {\hbox to \rightedgewidth % (check outer level and settings)
- {\hsize\rightedgewidth\interactionmenus[\v!right]\hss}}
-
-\def\placetoptextblock
- {\vbox to \topheight
- {\vsize\topheight
- \csname\??tk\v!top\c!before\endcsname
- \interactionmenus[\v!top]%
- \csname\??tk\v!top\c!after\endcsname
- \kern\zeropoint}}
-
-\def\placebottomtextblock
- {\vbox to \bottomheight
- {\vsize\bottomheight
- \csname\??tk\v!bottom\c!before\endcsname
- \interactionmenus[\v!bottom]%
- \csname\??tk\v!bottom\c!after\endcsname
- \kern\zeropoint}}
-
-\ifx\leftedgetextcontent\undefined \else
-
- \appendtoks \placeleftedgetextblock \hskip-\leftedgewidth \to \leftedgetextcontent
- \appendtoks \placerightedgetextblock \hskip-\rightedgewidth \to \rightedgetextcontent
- \appendtoks \placetoptextblock \vskip-\topheight \to \toptextcontent
- \appendtoks \placebottomtextblock \vskip-\bottomheight \to \bottomtextcontent
-
-\fi
-
-\setupinteractionscreen
- [\c!width=\printpaperwidth,
- \c!height=\printpaperheight,
- \c!horoffset=\!!zeropoint,
- \c!veroffset=\!!zeropoint,
- \c!backspace=\backspace,
- \c!topspace=\topspace,
- \c!option=\v!min,
- \c!delay=\v!none]
-
-\setupbuttons
- [\c!state=\v!start,
- \c!width=\v!fit,
- \c!height=\v!broad,
- \c!offset=0.25em,
- \c!frame=\v!on,
- \c!background=,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=,
- \c!style=\@@iastyle,
- \c!color=\@@iacolor,
- \c!contrastcolor=\@@iacontrastcolor,
- \c!samepage=\v!yes,
- \c!unknownreference=\v!yes]
-
-\setupinteractionbar
- [\c!state=\v!start,
- \c!alternative=a,
- \c!symbol=\v!no,
- \c!width=\rightedgewidth,
- \c!height=, % these are taken care
- \c!depth=, % of at calling time
- \c!distance=.5em, % beter relateren aan breedte
- \c!step=1,
- \c!color=\@@iacolor,
- \c!contrastcolor=\@@iacontrastcolor,
- \c!frame=\v!on,
- \c!background=,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=,
- \c!samepage=\v!yes,
- \c!unknownreference=\v!yes]
-
-\setupsynchronizationbar
- [\c!alternative=\v!page,
- \c!width=\rightedgewidth,
- \c!style=\@@iastyle,
- \c!color=\@@iacolor,
- \c!background=,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=]
-
-\setupsynchronization
- [\c!state=\v!stop]
-
-\setupprofiles
- [\c!option=]
-
-\setuppagetransitions
- [\v!reset]
-
-\setupcomment
- [\c!state=\v!start,
- \c!margin=2.5em,
- \c!distance=1em,
- \c!width=.3\textwidth,
- \c!height=.2\textheight,
- \c!color=\@@iacolor,
- \c!title=,
- \c!space=\v!no,
- \c!symbol=\v!normal,
- \c!location=\v!inmargin,
- \c!option=,
- \c!textlayer=]
-
-\setupversions % beware, @ is made active here,
- [\c!number=1, % therefore we set this one at the end
- \c!style=\ss,
- \c!color=]
-
-\protect \endinput
diff --git a/tex/context/base/core-itm.tex b/tex/context/base/core-itm.tex
index 1c8744d5b..406f9d1e4 100644
--- a/tex/context/base/core-itm.tex
+++ b/tex/context/base/core-itm.tex
@@ -14,39 +14,23 @@
% new: text + lefttext=(,righttext=)
% start=
-\writestatus{loading}{Context Core Macros / Itemgroups}
+\writestatus{loading}{ConTeXt Core Macros / Itemgroups}
-\startmessages dutch library: layouts
- 9: momenteel maximaal -- niveaus in opsommingen
-\stopmessages
+% messages moved
-\startmessages english library: layouts
- 9: currently no more than -- levels in itemizations
-\stopmessages
+% messages moved
-\startmessages german library: layouts
- 9: z.Z. nicht mehr als -- Ebenen in Aufzaehlungen
-\stopmessages
+% messages moved
-\startmessages czech library: layouts
- 9: aktualne ne vice nez -- urovne/urovni vyctu
-\stopmessages
+% messages moved
-\startmessages italian library: layouts
- 9: attualmente non più di -- livelli di elencazione
-\stopmessages
+% messages moved
-\startmessages norwegian library: layouts
- 9: for øyeblikket maksimalt -- nivåer i opplisting
-\stopmessages
+% messages moved
-\startmessages romanian library: layouts
- 9: acum nu se supota mai mult de -- nivele de adancime la iteratii
-\stopmessages
+% messages moved
-\startmessages french library: layouts
- 9: pas plus de -- niveaux pour l'instant dans les élémentarisations
-\stopmessages
+% messages moved
\unprotect
@@ -944,7 +928,7 @@
\ifdim\scratchdimen>\dimen0
\advance\scratchdimen -\dimen0
\else
- \scratchdimen\z@
+ \scratchdimen\zeropoint
\fi
\llap{\hbox to \dimen0{\ifconditional\sublistitem\llap{+}\fi\box8\hss}}% was: \hfill
\hskip\scratchdimen}
diff --git a/tex/context/base/core-job.lua b/tex/context/base/core-job.lua
index 8b45a5783..fb4f76de1 100644
--- a/tex/context/base/core-job.lua
+++ b/tex/context/base/core-job.lua
@@ -6,79 +6,14 @@ if not modules then modules = { } end modules ['core-job'] = {
license = "see context related readme files"
}
--- will move
+local texsprint, texprint, format, find, gmatch = tex.sprint, tex.print, string.format, string.find, string.gmatch
-local texsprint, texprint, format = tex.sprint, tex.print, string.format
-
-commands.writestatus = ctx.writestatus
-
-function commands.doifelse(b)
- if b then -- faster with if than with expression
- texsprint(tex.texcatcodes,"\\firstoftwoarguments")
- else
- texsprint(tex.texcatcodes,"\\secondoftwoarguments")
- end
-end
-function commands.doif(b)
- if b then
- texsprint(tex.texcatcodes,"\\firstofoneargument")
- else
- texsprint(tex.texcatcodes,"\\gobbleoneargument")
- end
-end
-function commands.doifnot(b)
- if b then
- texsprint(tex.texcatcodes,"\\gobbleoneargument")
- else
- texsprint(tex.texcatcodes,"\\firstofoneargument")
- end
-end
-cs.testcase = commands.doifelse
-
-function commands.doifelsespaces(str)
- return commands.doifelse(str:find("^ +$"))
-end
-
-local s = lpeg.splitat(",")
-
-local h = { }
-
-function commands.doifcommonelse(a,b)
- local ha = h[a]
- local hb = h[b]
- if not ha then ha = s:match(a) h[a] = ha end
- if not hb then hb = s:match(b) h[b] = hb end
- for i=1,#ha do
- for j=1,#hb do
- if ha[i] == hb[i] then
- return cs.testcase(true)
- end
- end
- end
- return cs.testcase(false)
-end
-
-function commands.doifinsetelse(a,b)
- local hb = h[b]
- if not hb then hb = s:match(b) h[b] = hb end
- for j=1,#hb do
- if a == hb[i] then
- return cs.testcase(true)
- end
- end
- return cs.testcase(false)
-end
-
-function commands. def(cs,value) texsprint(tex.ctxcatcodes,format( "\\def\\%s{%s}",cs,value)) end
-function commands.edef(cs,value) texsprint(tex.ctxcatcodes,format("\\edef\\%s{%s}",cs,value)) end
-function commands.gdef(cs,value) texsprint(tex.ctxcatcodes,format("\\gdef\\%s{%s}",cs,value)) end
-function commands.xdef(cs,value) texsprint(tex.ctxcatcodes,format("\\xdef\\%s{%s}",cs,value)) end
-
-function commands.cs(cs,args) texsprint(tex.ctxcatcodes,format("\\csname %s\\endcsname %s",cs,args or"")) end
+local ctxcatcodes = tex.ctxcatcodes
+local texcatcodes = tex.texcatcodes
-- main code
-function input.findctxfile(name,maxreadlevel)
+function resolvers.findctxfile(name,maxreadlevel)
local function exists(n)
if io.exists(n) then
return n
@@ -90,7 +25,7 @@ function input.findctxfile(name,maxreadlevel)
end
return nil
end
- if input.aux.qualified_path(name) then
+ if file.is_qualified_path(name) then
return name
else
-- not that efficient, too many ./ lookups
@@ -107,41 +42,40 @@ function input.findctxfile(name,maxreadlevel)
end
end
end
- return input.find_file(name) or ""
+ return resolvers.find_file(name) or ""
end
end
function commands.processfile(name,maxreadlevel)
- name = input.findctxfile(name,maxreadlevel)
+ name = resolvers.findctxfile(name,maxreadlevel)
if name ~= "" then
---~ texsprint(tex.ctxcatcodes,format('\\input {%s}',name)) -- future version
- texsprint(tex.ctxcatcodes,format("\\input %s\\relax",name)) -- we need \input {name}
+ texsprint(ctxcatcodes,format("\\input %s\\relax",name)) -- we need \input {name}
end
end
function commands.doifinputfileelse(name,maxreadlevel)
- commands.doifelse(input.findctxfile(name,maxreadlevel) ~= "")
+ commands.doifelse(resolvers.findctxfile(name,maxreadlevel) ~= "")
end
function commands.locatefilepath(name,maxreadlevel)
- texsprint(tex.texcatcodes,file.dirname(input.findctxfile(name,maxreadlevel)))
+ texsprint(texcatcodes,file.dirname(resolvers.findctxfile(name,maxreadlevel)))
end
function commands.usepath(paths,maxreadlevel)
- input.register_extra_path(paths)
- texsprint(tex.texcatcodes,table.concat(input.instance.extra_paths or {}, ""))
+ resolvers.register_extra_path(paths)
+ texsprint(texcatcodes,table.concat(resolvers.instance.extra_paths or {}, ""))
end
function commands.usesubpath(subpaths,maxreadlevel)
- input.register_extra_path(nil,subpaths)
- texsprint(tex.texcatcodes,table.concat(input.instance.extra_paths or {}, ""))
+ resolvers.register_extra_path(nil,subpaths)
+ texsprint(texcatcodes,table.concat(resolvers.instance.extra_paths or {}, ""))
end
function commands.usezipfile(name,tree)
if tree and tree ~= "" then
- input.usezipfile(format("zip:///%s?tree=%s",name,tree))
+ resolvers.usezipfile(format("zip:///%s?tree=%s",name,tree))
else
- input.usezipfile(format("zip:///%s",name))
+ resolvers.usezipfile(format("zip:///%s",name))
end
end
@@ -162,20 +96,20 @@ local function convertexamodes(str)
local data = xml.content(dk) or ""
local mode = label:match("^mode:(.+)$")
if mode then
- texsprint(tex.ctxcatcodes,format("\\enablemode[%s:%s]",mode,data))
+ texsprint(ctxcatcodes,format("\\enablemode[%s:%s]",mode,data))
end
- texsprint(tex.ctxcatcodes,format("\\setvariable{exa:variables}{%s}{%s}",label,data:gsub("([{}])","\\%1")))
+ texsprint(ctxcatcodes,format("\\setvariable{exa:variables}{%s}{%s}",label,data:gsub("([{}])","\\%1")))
end
end
end
--- we need a system file option: ,. .. etc + paths but no tex lookup so input.find_file is wrong here
+-- we need a system file option: ,. .. etc + paths but no tex lookup so resolvers.find_file is wrong here
function commands.loadexamodes(filename)
if not filename or filename == "" then
- filename = file.stripsuffix(tex.jobname)
+ filename = file.removesuffix(tex.jobname)
end
- filename = input.find_file(file.addsuffix(filename,'ctm')) or ""
+ filename = resolvers.find_file(file.addsuffix(filename,'ctm')) or ""
if filename ~= "" then
commands.writestatus("examodes","loading %s",filename) -- todo: message system
convertexamodes(io.loaddata(filename))
@@ -184,59 +118,72 @@ function commands.loadexamodes(filename)
end
end
+function commands.logoptionfile(name)
+ -- todo: xml if xml logmode
+ local f = io.open(name)
+ if f then
+ texio.write_nl("log","%\n%\tbegin of optionfile\n%\n")
+ for line in f:lines() do
+ texio.write("log",format("%%\t%s\n",line))
+ end
+ texio.write("log","%\n%\tend of optionfile\n%\n")
+ f:close()
+ end
+end
+
--~ set functions not ok and not faster on mk runs either
--~
--~ local function doifcommonelse(a,b)
---~ local ba = a:find(",")
---~ local bb = b:find(",")
+--~ local ba = find(a,",")
+--~ local bb = find(b,",")
--~ if ba and bb then
---~ for sa in a:gmatch("[^ ,]+") do
---~ for sb in b:gmatch("[^ ,]+") do
+--~ for sa in gmatch(a,"[^ ,]+") do
+--~ for sb in gmatch(b,"[^ ,]+") do
--~ if sa == sb then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..sa.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",sa,"}")
--~ return true
--~ end
--~ end
--~ end
--~ elseif ba then
---~ for sa in a:gmatch("[^ ,]+") do
+--~ for sa in gmatch(a,"[^ ,]+") do
--~ if sa == b then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..b.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",b,"}")
--~ return true
--~ end
--~ end
--~ elseif bb then
---~ for sb in b:gmatch("[^ ,]+") do
+--~ for sb in gmatch(b,"[^ ,]+") do
--~ if a == sb then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..a.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}")
--~ return true
--~ end
--~ end
--~ else
--~ if a == b then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..a.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}")
--~ return true
--~ end
--~ end
---~ texsprint(tex.ctxcatcodes,"\\let\\commalistelement\\empty")
+--~ texsprint(ctxcatcodes,"\\let\\commalistelement\\empty")
--~ return false
--~ end
--~ local function doifinsetelse(a,b)
---~ local bb = b:find(",")
+--~ local bb = find(b,",")
--~ if bb then
---~ for sb in b:gmatch("[^ ,]+") do
+--~ for sb in gmatch(b,"[^ ,]+") do
--~ if a == sb then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..a.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}")
--~ return true
--~ end
--~ end
--~ else
--~ if a == b then
---~ texsprint(tex.ctxcatcodes,"\\def\\commalistelement{"..a.."}")
+--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}")
--~ return true
--~ end
--~ end
---~ texsprint(tex.ctxcatcodes,"\\let\\commalistelement\\empty")
+--~ texsprint(ctxcatcodes,"\\let\\commalistelement\\empty")
--~ return false
--~ end
--~ function commands.doifcommon (a,b) commands.doif (doifcommonelse(a,b)) end
@@ -245,4 +192,3 @@ end
--~ function commands.doifinset (a,b) commands.doif (doifinsetelse(a,b)) end
--~ function commands.doifnotinset (a,b) commands.doifnot (doifinsetelse(a,b)) end
--~ function commands.doifinsetelse (a,b) commands.doifelse(doifinsetelse(a,b)) end
-
diff --git a/tex/context/base/core-job.mkii b/tex/context/base/core-job.mkii
index 3a0f4e2f4..59d8552df 100644
--- a/tex/context/base/core-job.mkii
+++ b/tex/context/base/core-job.mkii
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-job, % copied from main-001,
-%D version=2008.01.25,
+%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Job Handling,
%D author=Hans Hagen,
@@ -11,8 +11,44 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D This module is still to be split and documented.
+
+\writestatus{loading}{ConTeXt Core Macros / Job Handling}
+
\unprotect
+\let \currentproject \empty
+\let \currentproduct \empty
+\let \currentenvironment \empty
+\let \currentcomponent \empty
+
+\let \loadedfiles \empty
+\let \processedfiles \empty
+
+\let \nomorefiles \relax
+
+\let \allinputpaths \empty
+\let \locatedfilepath \empty
+
+\newcount\textlevel
+\newcount\fileprocesslevel
+
+\setvalue{\c!file::0}{\jobname}
+
+\def\processedfile % is used in styles, don't change !
+ {\getvalue{\c!file::\number\fileprocesslevel}}
+
+\def\dostarttextfile#1%
+ {\global\advance\fileprocesslevel\plusone
+ \setxvalue{\c!file::\number\fileprocesslevel}{#1}%
+ \@EA\doglobal\@EA\addtocommalist\@EA{#1}\processedfiles}
+
+\def\dostoptextfile
+ {\global\advance\fileprocesslevel\minusone}
+
+\def\processlocalfile#1#2%
+ {#1{#2}\donothing{\readfile{#2}\donothing\donothing}}
+
\def\processfile#1%
{\ifx\allinputpaths\empty
\def\next{\processlocalfile\readlocfile}%
@@ -83,4 +119,282 @@
\processcommacommand[\allinputpaths]\docommand
\fi}
+\def\registerfileinfo[#1#2]#3% geen \showmessage ?
+ {\writestatus\m!systems{#1#2 file #3 at line \the\inputlineno}%
+ \immediatewriteutility{f #1 {#3}}}
+
+\ifx\preloadfonts \undefined \let\preloadfonts \relax \fi
+\ifx\preloadspecials\undefined \let\preloadspecials\relax \fi
+
+\def\loadallsystemfiles#1#2%
+ {\ifx\@@svdirectory\empty
+ \readsysfile{#1}{\showmessage\m!systems2{#1}}{#2}%
+ \else% yet undocumented
+ \def\doloadsystemfile##1%
+ {\readsetfile{##1}{#1}{\showmessage\m!systems2{#1}}{#2}}%
+ \processcommacommand[\@@svdirectory]\doloadsystemfile
+ \fi}
+
+\ifx\disableXML\undefined \let\disableXML\relax \fi
+
+\def\loadsystemfiles
+ {\reportprotectionstate
+ \readsysfile\f!newfilename{\showmessage\m!systems2\f!newfilename}\donothing
+ %\readsysfile\f!oldfilename{\showmessage\m!systems2\f!oldfilename}\donothing
+ \loadallsystemfiles\f!filfilename
+ \donothing
+ \loadallsystemfiles\f!sysfilename
+ {\loadallsystemfiles{\f!sysfilename.rme}\donothing % new, fall back
+ \doglobal\appendtoks % brrr better \setcatcodetable\ctxcatcodes % % test
+ \bgroup\disableXML\loadallsystemfiles\f!errfilename\donothing\egroup
+ \to\everygoodbye}}
+
+%D Loading of \type {cont-usr.tex} (edited by the user)
+%D and \type {cont-fmt.tex} (generated by texexec).
+
+\def\loaduserspecifications
+ {% this used to be the file where users can tune their system, especially patterns
+ \readsysfile\f!usrfilename{\showmessage\m!systems2\f!usrfilename}\donothing
+ % this one took care of user preferences (fonts, messages) but lm made this obsolete
+ \readjobfile\f!fmtfilename{\showmessage\m!systems2\f!fmtfilename}\donothing
+ % from now on we preload all patterns (only in mkii)
+ \preloadallpatterns}
+
+\let\loaduserspecifications\relax
+
+%D We don't want multiple jobfiles to interfere.
+
+\def\loadoptionfile
+ {\readjobfile{\jobname.\f!optionextension}
+ {\showmessage\m!systems2{\jobname.\f!optionextension}}%
+ {\writestatus\m!systems {no \jobname.\f!optionextension}}}
+
+% Most natural ...
+%
+% \def\doateverystarttext
+% {\the\everystarttext
+% \global\let\doateverystarttext\relax}
+%
+% ... most practical, since we can load env's in a
+% something.run file (nested \starttext's; see for
+% instance x-res-08, where we definitely want to
+% open the file!).
+
+\def\doateverystarttext
+ {\the\everystarttext
+ \global\everystarttext\emptytoks}
+
+\def\starttext
+ {\doateverystarttext
+ \ifcase\textlevel
+ \registerfileinfo[begin]\jobname
+ \expandafter\startcopyingblocks
+ \fi
+ \global\advance\textlevel\plusone}
+
+\def\stoptext
+ {\global\advance\textlevel\minusone
+ \ifnum\textlevel>\zerocount \else
+ \page[\v!last]\page % new, moved from everybye to here; flushes headers, colors etc etc etc
+ \the\everystoptext
+ %\the\everybye %
+ %\the\everygoodbye % == \end (new)
+ %\expandafter\normalend %
+ \expandafter\finalend
+ \fi}
+
+\def\finalend
+ {\ifnum\textlevel>\zerocount \else
+ \the\everybye
+ \the\everygoodbye
+ \doifsometokselse\everynotabene{\writeline\the\everynotabene\writeline}\donothing
+ \global\everybye \emptytoks % rather unneeded
+ \global\everygoodbye\emptytoks % but for sure
+ \expandafter\normalend
+ \fi}
+
+\let\end\finalend
+
+\def\emergencyend
+ {\writestatus\m!systems{invalid \@EA\string\csname\e!start\v!text\endcsname...\@EA\string\csname\e!stop\v!text\endcsname\space structure}%
+ \stoptext}
+
+\def\currentfile{\inputfilename}
+
+\def\doexecutefileonce#1%
+ {\beforesplitstring#1\at.\to\currentfile
+ \fullexpandtwoargsafter\doifnotinset\currentfile\loadedfiles
+ {\fullexpandoneargafter\addtocommalist\currentfile\loadedfiles
+ \doexecutefile{#1}}}
+
+\def\doexecutefile#1%
+ {\registerfileinfo[begin]{#1}%
+ \dostarttextfile{#1}%
+ \processfile{#1}%
+ \dostoptextfile
+ \registerfileinfo[end]{#1}}
+
+\def\donotexecutefile#1%
+ {}
+
+\def\verwerkfile#1 %
+ {\doexecutefile{#1}}
+
+\def\useenvironment[#1]% maybe commalist
+ {\environment #1 \relax}
+
+\def\environment #1 % at outermost level only (load only once)
+ {\pushmacro\startenvironment
+ \pushmacro\stopenvironment
+ \def\startenvironment ##1 {}%
+ \let\stopenvironment\relax
+ \startreadingfile
+ \doexecutefileonce{#1}
+ \stopreadingfile
+ \popmacro\stopenvironment
+ \popmacro\startenvironment}
+
+\def\component #1 % at outermost level only
+ {\dostarttextfile{#1}%
+ \processfile{#1}%
+ \dostoptextfile}
+
+\newcount\filelevel
+
+\let\currentcomponent \v!text
+\let\currentcomponentpath\f!currentpath
+
+\def\donextlevel#1#2#3#4#5#6#7\\%
+ {\pushmacro\currentcomponent
+ \pushmacro\currentcomponentpath
+ \let\currentcomponent#1%
+ \setsystemmode\currentcomponent
+ \splitfilename{#1}%
+ \ifx\splitoffpath\empty
+ \let\currentcomponentpath\f!currentpath
+ \else
+ \let\currentcomponentpath\splitoffpath
+ \fi
+ \beforesplitstring#7\at.\to#2\relax % can become path + base
+ \ifcase\filelevel\relax
+ \starttext
+ \def\project ##1 {#3{##1}}%
+ \def\environment ##1 {#4{##1}}%
+ \def\product ##1 {#5{##1}}%
+ \def\component ##1 {#6{##1}}%
+ \fi
+ \advance\filelevel\plusone
+ \fullexpandoneargafter\addtocommalist{#1}\loadedfiles}
+
+\def\doprevlevel
+ {\popmacro\currentcomponentpath
+ \popmacro\currentcomponent
+ \setsystemmode\currentcomponent
+ \ifnum\filelevel=\plusone
+ \expandafter\stoptext
+ \else
+ \advance\filelevel\minusone
+ \expandafter\endinput
+ \fi}
+
+\def\startproject #1 %
+ {\donextlevel\v!project\currentproject
+ \donotexecutefile\doexecutefileonce
+ \doexecutefileonce\doexecutefile#1\\}
+
+\def\startproduct #1 %
+ {\doateverystarttext
+ \donextlevel\v!product\currentproduct
+ \doexecutefileonce\doexecutefileonce
+ \donotexecutefile\doexecutefile#1\\}
+
+\def\startcomponent #1 %
+ {\doateverystarttext
+ \donextlevel\v!component\currentcomponent
+ \doexecutefileonce\doexecutefileonce
+ \donotexecutefile\doexecutefile#1\\}
+
+\def\startenvironment #1 %
+ {\donextlevel\v!environment\currentenvironment
+ \donotexecutefile\doexecutefileonce
+ \donotexecutefile\donotexecutefile#1\\}
+
+% \startproject test
+% 1: \startmode[*project] project \stopmode \endgraf
+% 2: \startmode[*product] product \stopmode \endgraf
+% \stopproject
+
+\def\stopproject {\doprevlevel}
+\def\stopproduct {\doprevlevel}
+\def\stopcomponent {\doprevlevel}
+\def\stopenvironment{\doprevlevel}
+
+% more or less replaced by modes
+
+\setvalue{\e!start\v!localenvironment}[#1]%
+ {\let\loadedlocalenvironments\empty
+ \def\docommand##1%
+ {\beforesplitstring##1\at.\to\someevironment
+ \fullexpandoneargafter\addtocommalist\someevironment\loadedlocalenvironments}%
+ \processcommalist[#1]\docommand
+ \fullexpandtwoargsafter\doifcommonelse % no longer next needed
+ {\currentproject,\currentproduct,%
+ \currentcomponent,\currentenvironment}
+ {\loadedlocalenvironments}
+ {\letvalue{\e!stop\v!localenvironment}\relax}
+ {\grabuntil{\e!stop\v!localenvironment}\gobbleoneargument}} % TH: fixed, was \relax
+
+\setvalue{\v!localenvironment}#1 {\doexecutefileonce{#1}}
+
+% NOT TOEVOEGEN: \the\everytrace
+
+\neverypar=\emptytoks
+
+% \appendtoks \flushnotes \to \everypar
+% \appendtoks \synchronizesidefloats \to \everypar
+% \appendtoks \checkindentation \to \everypar
+% \appendtoks \showparagraphnumber \to \everypar
+% \appendtoks \flushmargincontents \to \everypar
+% \appendtoks \flushcommentanchors \to \everypar
+% \appendtoks \synchronizenotes \to \everypar
+
+% \appendtoks \flushnotes \to \everydisplay
+% \appendtoks \adjustsidefloatdisplaylines \to \everydisplay
+
+% soon, when pdftex 1.22 is out in the field:
+
+\chardef\systemcommandmode\zerocount % 0=unknown 1=disabled 2=enabled
+
+\def\checksystemcommandmode
+ {\ifx\pdfshellescape\undefined \else
+ \chardef\systemcommandmode \ifcase\pdfshellescape \plusone \else \plustwo \fi
+ \fi
+ \global\let\checksystemcommandmode\relax}
+
+\def\reportsystemcommandmode
+ {\ifcase\systemcommandmode
+ \or
+ \writestatus\m!systems{system commands are disabled}%
+ \or
+ \writestatus\m!systems{system commands are enabled}%
+ \fi}
+
+% \ifx\etexversion\undefined \else \ifnum\etexversion<202
+% \prependtoks
+% \writestatus\m!systems{eTeX version \number\etexversion\space -> too old (bugs)}%
+% \writeline
+% \to \everyjob
+% \fi \fi
+
+% \ifx\pdftexversion\undefined \else \ifnum\number\pdftexversion<120
+% \prependtoks
+% \writestatus\m!systems{pdfTeX version \number\pdftexversion\space -> please update}%
+% \writeline
+% \to \everyjob
+% \fi \fi
+
+% Default-instellingen (verborgen)
+
+\resetutilities
+
\protect \endinput
diff --git a/tex/context/base/core-job.mkiv b/tex/context/base/core-job.mkiv
index 2c0f34412..cdb1564f4 100644
--- a/tex/context/base/core-job.mkiv
+++ b/tex/context/base/core-job.mkiv
@@ -1,6 +1,6 @@
%D \module
-%D [ file=core-job,
-%D version=2008.01.25,
+%D [ file=core-job, % copied from main-001,
+%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Job Handling,
%D author=Hans Hagen,
@@ -11,32 +11,333 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\registerctxluafile{core-job}{1.001}
+%D This module is still to be split and documented.
+
+\writestatus{loading}{ConTeXt Core Macros / Job Handling}
\unprotect
-\def\processfile #1{\ctxlua{commands.processfile("#1",\number\maxreadlevel)}}
-\def\doifinputfileelse#1{\ctxlua{commands.doifinputfileelse("#1",\number\maxreadlevel)}}
-\def\locatefilepath #1{\edef\locatedfilepath{\ctxlua{commands.locatefilepath("#1",\number\maxreadlevel)}}}
-\def\usepath [#1]{\edef\allinputpaths{\ctxlua{commands.usepath("#1")}}}
-\def\usesubpath [#1]{\edef\allinputpaths{\ctxlua{commands.usesubpath("#1")}}}
+\registerctxluafile{core-job}{1.001}
+
+\let \currentproject \empty
+\let \currentproduct \empty
+\let \currentenvironment \empty
+\let \currentcomponent \empty
+
+\let \loadedfiles \empty
+\let \processedfiles \empty
+
+\let \nomorefiles \relax
+
+\let \allinputpaths \empty
+\let \locatedfilepath \empty
+\newcount\textlevel
+\newcount\fileprocesslevel
+
+\setvalue{\c!file::0}{\jobname}
+
+\def\processedfile % is used in styles, don't change !
+ {\getvalue{\c!file::\number\fileprocesslevel}}
+
+\def\dostarttextfile#1%
+ {\global\advance\fileprocesslevel\plusone
+ \setxvalue{\c!file::\number\fileprocesslevel}{#1}%
+ \@EA\doglobal\@EA\addtocommalist\@EA{#1}\processedfiles}
+
+\def\dostoptextfile
+ {\global\advance\fileprocesslevel\minusone}
+
+\def\processlocalfile#1#2%
+ {#1{#2}\donothing{\readfile{#2}\donothing\donothing}}
+
+\def\processfile #1{\ctxlua{commands.processfile("#1",\number\maxreadlevel)}}
+\def\doifinputfileelse #1{\ctxlua{commands.doifinputfileelse("#1",\number\maxreadlevel)}}
+\def\locatefilepath #1{\edef\locatedfilepath{\ctxlua{commands.locatefilepath("#1",\number\maxreadlevel)}}}
+\def\usepath [#1]{\edef\allinputpaths{\ctxlua{commands.usepath("#1")}}}
+\def\usesubpath [#1]{\edef\allinputpaths{\ctxlua{commands.usesubpath("#1")}}}
\def\usezipfile {\dodoubleempty\dousezipfile}
\def\dousezipfile[#1][#2]{\ctxlua{commands.usezipfile("#1","#2")}} % [filename] [optional subtree]
\def\loadexamodes {\dosingleempty\doloadexamodes}
\def\doloadexamodes [#1]{\ctxlua{commands.loadexamodes("#1")}}
-% for the moment here:
+\def\registerfileinfo[#1#2]#3% geen \showmessage ?
+ {\writestatus\m!systems{#1#2 file #3 at line \the\inputlineno}%
+ \immediatewriteutility{f #1 {#3}}}
+
+\ifx\preloadfonts \undefined \let\preloadfonts \relax \fi
+\ifx\preloadspecials\undefined \let\preloadspecials\relax \fi
+
+\def\loadallsystemfiles#1#2%
+ {\ifx\@@svdirectory\empty
+ \readsysfile{#1}{\showmessage\m!systems2{#1}}{#2}%
+ \else% yet undocumented
+ \def\doloadsystemfile##1%
+ {\readsetfile{##1}{#1}{\showmessage\m!systems2{#1}}{#2}}%
+ \processcommacommand[\@@svdirectory]\doloadsystemfile
+ \fi}
+
+\ifx\disableXML\undefined \let\disableXML\relax \fi
+
+\def\loadsystemfiles
+ {\reportprotectionstate
+ \readsysfile\f!newfilename{\showmessage\m!systems2\f!newfilename}\donothing
+ %\readsysfile\f!oldfilename{\showmessage\m!systems2\f!oldfilename}\donothing
+ \loadallsystemfiles\f!filfilename
+ \donothing
+ \loadallsystemfiles\f!sysfilename
+ {\loadallsystemfiles{\f!sysfilename.rme}\donothing % new, fall back
+ \doglobal\appendtoks % brrr better \setcatcodetable\ctxcatcodes % % test
+ \bgroup\disableXML\loadallsystemfiles\f!errfilename\donothing\egroup
+ \to\everygoodbye}}
+
+%D Loading of \type {cont-usr.tex} (edited by the user)
+%D and \type {cont-fmt.tex} (generated by texexec).
+
+% \def\loaduserspecifications
+% {% this used to be the file where users can tune their system, especially patterns
+% \readsysfile\f!usrfilename{\showmessage\m!systems2\f!usrfilename}\donothing
+% % this one took care of user preferences (fonts, messages) but lm made this obsolete
+% \readjobfile\f!fmtfilename{\showmessage\m!systems2\f!fmtfilename}\donothing
+% % from now on we preload all patterns (only in mkii)
+% \preloadallpatterns}
+
+\let\loaduserspecifications\relax
+
+%D We don't want multiple jobfiles to interfere.
+
+\def\loadoptionfile
+ {\readjobfile{\jobname.\f!optionextension}
+ {\showmessage\m!systems2{\jobname.\f!optionextension}%
+ \ctxlua{commands.logoptionfile("\jobname.\f!optionextension")}}%
+ {\writestatus\m!systems {no \jobname.\f!optionextension}}}
+
+% Most natural ...
+%
+% \def\doateverystarttext
+% {\the\everystarttext
+% \global\let\doateverystarttext\relax}
+%
+% ... most practical, since we can load env's in a
+% something.run file (nested \starttext's; see for
+% instance x-res-08, where we definitely want to
+% open the file!).
+
+\def\doateverystarttext
+ {\the\everystarttext
+ \global\everystarttext\emptytoks}
+
+\def\starttext
+ {\doateverystarttext
+ \ifcase\textlevel
+ \registerfileinfo[begin]\jobname
+ \fi
+ \global\advance\textlevel\plusone}
+
+\def\stoptext
+ {\global\advance\textlevel\minusone
+ \ifnum\textlevel>\zerocount \else
+ \page[\v!last]\page % new, moved from everybye to here; flushes headers, colors etc etc etc
+ \the\everystoptext
+ %\the\everybye %
+ %\the\everygoodbye % == \end (new)
+ %\expandafter\normalend %
+ \expandafter\finalend
+ \fi}
+
+\def\finalend
+ {\ifnum\textlevel>\zerocount \else
+ \the\everybye
+ \the\everygoodbye
+ \doifsometokselse\everynotabene{\writeline\the\everynotabene\writeline}\donothing
+ \global\everybye \emptytoks % rather unneeded
+ \global\everygoodbye\emptytoks % but for sure
+ \expandafter\normalend
+ \fi}
+
+\let\end\finalend
+
+\def\emergencyend
+ {\writestatus\m!systems{invalid \@EA\string\csname\e!start\v!text\endcsname...\@EA\string\csname\e!stop\v!text\endcsname\space structure}%
+ \stoptext}
+
+\def\currentfile{\inputfilename}
+
+\def\doexecutefileonce#1%
+ {\beforesplitstring#1\at.\to\currentfile
+ \fullexpandtwoargsafter\doifnotinset\currentfile\loadedfiles
+ {\fullexpandoneargafter\addtocommalist\currentfile\loadedfiles
+ \doexecutefile{#1}}}
+
+\def\doexecutefile#1%
+ {\registerfileinfo[begin]{#1}%
+ \dostarttextfile{#1}%
+ \processfile{#1}%
+ \dostoptextfile
+ \registerfileinfo[end]{#1}}
+
+\def\donotexecutefile#1%
+ {}
+
+\def\verwerkfile#1 %
+ {\doexecutefile{#1}}
+
+\def\useenvironment[#1]% maybe commalist
+ {\environment #1 \relax}
+
+\def\environment #1 % at outermost level only (load only once)
+ {\pushmacro\startenvironment
+ \pushmacro\stopenvironment
+ \def\startenvironment ##1 {}%
+ \let\stopenvironment\relax
+ \startreadingfile
+ \doexecutefileonce{#1}
+ \stopreadingfile
+ \popmacro\stopenvironment
+ \popmacro\startenvironment}
+
+\def\component #1 % at outermost level only
+ {\dostarttextfile{#1}%
+ \processfile{#1}%
+ \dostoptextfile}
+
+\newcount\filelevel
+
+\let\currentcomponent \v!text
+\let\currentcomponentpath\f!currentpath
+
+\def\donextlevel#1#2#3#4#5#6#7\\%
+ {\pushmacro\currentcomponent
+ \pushmacro\currentcomponentpath
+ \let\currentcomponent#1%
+ \setsystemmode\currentcomponent
+ \splitfilename{#1}%
+ \ifx\splitoffpath\empty
+ \let\currentcomponentpath\f!currentpath
+ \else
+ \let\currentcomponentpath\splitoffpath
+ \fi
+ \beforesplitstring#7\at.\to#2\relax % can become path + base
+ \ifcase\filelevel\relax
+ \starttext
+ \def\project ##1 {#3{##1}}%
+ \def\environment ##1 {#4{##1}}%
+ \def\product ##1 {#5{##1}}%
+ \def\component ##1 {#6{##1}}%
+ \fi
+ \advance\filelevel\plusone
+ \fullexpandoneargafter\addtocommalist{#1}\loadedfiles}
+
+\def\doprevlevel
+ {\popmacro\currentcomponentpath
+ \popmacro\currentcomponent
+ \setsystemmode\currentcomponent
+ \ifnum\filelevel=\plusone
+ \expandafter\stoptext
+ \else
+ \advance\filelevel\minusone
+ \expandafter\endinput
+ \fi}
+
+\def\startproject #1 %
+ {\donextlevel\v!project\currentproject
+ \donotexecutefile\doexecutefileonce
+ \doexecutefileonce\doexecutefile#1\\}
+
+\def\startproduct #1 %
+ {\doateverystarttext
+ \donextlevel\v!product\currentproduct
+ \doexecutefileonce\doexecutefileonce
+ \donotexecutefile\doexecutefile#1\\}
+
+\def\startcomponent #1 %
+ {\doateverystarttext
+ \donextlevel\v!component\currentcomponent
+ \doexecutefileonce\doexecutefileonce
+ \donotexecutefile\doexecutefile#1\\}
+
+\def\startenvironment #1 %
+ {\donextlevel\v!environment\currentenvironment
+ \donotexecutefile\doexecutefileonce
+ \donotexecutefile\donotexecutefile#1\\}
+
+% \startproject test
+% 1: \startmode[*project] project \stopmode \endgraf
+% 2: \startmode[*product] product \stopmode \endgraf
+% \stopproject
+
+\def\stopproject {\doprevlevel}
+\def\stopproduct {\doprevlevel}
+\def\stopcomponent {\doprevlevel}
+\def\stopenvironment{\doprevlevel}
+
+% more or less replaced by modes
+
+\setvalue{\e!start\v!localenvironment}[#1]%
+ {\let\loadedlocalenvironments\empty
+ \def\docommand##1%
+ {\beforesplitstring##1\at.\to\someevironment
+ \fullexpandoneargafter\addtocommalist\someevironment\loadedlocalenvironments}%
+ \processcommalist[#1]\docommand
+ \fullexpandtwoargsafter\doifcommonelse % no longer next needed
+ {\currentproject,\currentproduct,%
+ \currentcomponent,\currentenvironment}
+ {\loadedlocalenvironments}
+ {\letvalue{\e!stop\v!localenvironment}\relax}
+ {\grabuntil{\e!stop\v!localenvironment}\gobbleoneargument}} % TH: fixed, was \relax
+
+\setvalue{\v!localenvironment}#1 {\doexecutefileonce{#1}}
+
+% NOT TOEVOEGEN: \the\everytrace
+
+\neverypar=\emptytoks
+
+% \appendtoks \flushnotes \to \everypar
+% \appendtoks \synchronizesidefloats \to \everypar
+% \appendtoks \checkindentation \to \everypar
+% \appendtoks \showparagraphnumber \to \everypar
+% \appendtoks \flushmargincontents \to \everypar
+% \appendtoks \flushcommentanchors \to \everypar
+% \appendtoks \synchronizenotes \to \everypar
+
+% \appendtoks \flushnotes \to \everydisplay
+% \appendtoks \adjustsidefloatdisplaylines \to \everydisplay
+
+% soon, when pdftex 1.22 is out in the field:
+
+\chardef\systemcommandmode\zerocount % 0=unknown 1=disabled 2=enabled
+
+\def\checksystemcommandmode
+ {\ifx\pdfshellescape\undefined \else
+ \chardef\systemcommandmode \ifcase\pdfshellescape \plusone \else \plustwo \fi
+ \fi
+ \global\let\checksystemcommandmode\relax}
+
+\def\reportsystemcommandmode
+ {\ifcase\systemcommandmode
+ \or
+ \writestatus\m!systems{system commands are disabled}%
+ \or
+ \writestatus\m!systems{system commands are enabled}%
+ \fi}
-\def\expdoifelse#1#2{\ctxlua{commands.doifelse(\!!bs#1\!!es==\!!bs#2\!!es)}}
-\def\expdoif #1#2{\ctxlua{commands.doif (\!!bs#1\!!es==\!!bs#2\!!es)}}
-\def\expdoifnot #1#2{\ctxlua{commands.doifnot (\!!bs#1\!!es==\!!bs#2\!!es)}}
+% \ifx\etexversion\undefined \else \ifnum\etexversion<202
+% \prependtoks
+% \writestatus\m!systems{eTeX version \number\etexversion\space -> too old (bugs)}%
+% \writeline
+% \to \everyjob
+% \fi \fi
-% \testfeatureonce{100000}{\doifelse{hello world}{here i am}{}} % 0.3
-% \testfeatureonce{100000}{\expandabledoifelse{hello world}{here i am}{}} % 1.5
+% \ifx\pdftexversion\undefined \else \ifnum\number\pdftexversion<120
+% \prependtoks
+% \writestatus\m!systems{pdfTeX version \number\pdftexversion\space -> please update}%
+% \writeline
+% \to \everyjob
+% \fi \fi
+
+% Default-instellingen (verborgen)
-\def\expdoifcommonelse#1#2{\ctxlua{commands.doifcommonelse("#1","#2")}}
-\def\expdoifinsetelse #1#2{\ctxlua{commands.doifinsetelse("#1","#2")}}
+\resetutilities
\protect \endinput
diff --git a/tex/context/base/core-job.tex b/tex/context/base/core-job.tex
deleted file mode 100644
index ca9ef67c3..000000000
--- a/tex/context/base/core-job.tex
+++ /dev/null
@@ -1,368 +0,0 @@
-%D \module
-%D [ file=core-job, % copied from main-001,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Job Handling,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This module is still to be split and documented.
-
-\writestatus{loading}{Context Core Macros / Job Handling}
-
-\loadmarkfile{core-job}
-
-\unprotect
-
-\let \currentproject \empty
-\let \currentproduct \empty
-\let \currentenvironment \empty
-\let \currentcomponent \empty
-
-\let \loadedfiles \empty
-\let \processedfiles \empty
-
-\let \nomorefiles \relax
-
-\let \allinputpaths \empty
-\let \locatedfilepath \empty
-
-\newcount\textlevel
-\newcount\fileprocesslevel
-
-\setvalue{\c!file::0}{\jobname}
-
-\def\processedfile % is used in styles, don't change !
- {\getvalue{\c!file::\number\fileprocesslevel}}
-
-\def\dostarttextfile#1%
- {\global\advance\fileprocesslevel\plusone
- \setxvalue{\c!file::\number\fileprocesslevel}{#1}%
- \@EA\doglobal\@EA\addtocommalist\@EA{#1}\processedfiles}
-
-\def\dostoptextfile
- {\global\advance\fileprocesslevel\minusone}
-
-\def\processlocalfile#1#2%
- {#1{#2}\donothing{\readfile{#2}\donothing\donothing}}
-
-\ifx\processfile \undefined \let\processfile \gobbleoneargument \fi
-\ifx\doifinputfileelse\undefined \let\doifinputfileelse \gobbleoneargument \fi
-\ifx\locatefilepath \undefined \let\locatefilepath \gobbleoneargument \fi
-\ifx\usepath \undefined \def\usepath [#1]{} \fi
-\ifx\usesubpath \undefined \def\usesubpath [#1]{} \fi
-
-\def\registerfileinfo[#1#2]#3% geen \showmessage ?
- {\writestatus\m!systems{#1#2 file #3 at line \the\inputlineno}%
- \immediatewriteutility{f #1 {#3}}}
-
-\ifx\preloadfonts \undefined \let\preloadfonts \relax \fi
-\ifx\preloadspecials\undefined \let\preloadspecials\relax \fi
-
-\def\loadallsystemfiles#1#2%
- {\ifx\@@svdirectory\empty
- \readsysfile{#1}{\showmessage\m!systems2{#1}}{#2}%
- \else% yet undocumented
- \def\doloadsystemfile##1%
- {\readsetfile{##1}{#1}{\showmessage\m!systems2{#1}}{#2}}%
- \processcommacommand[\@@svdirectory]\doloadsystemfile
- \fi}
-
-\ifx\disableXML\undefined \let\disableXML\relax \fi
-
-\def\loadsystemfiles
- {\reportprotectionstate
- \readsysfile\f!newfilename{\showmessage\m!systems2\f!newfilename}\donothing
- %\readsysfile\f!oldfilename{\showmessage\m!systems2\f!oldfilename}\donothing
- \loadallsystemfiles\f!filfilename
- \donothing
- \loadallsystemfiles\f!sysfilename
- {\loadallsystemfiles{\f!sysfilename.rme}\donothing % new, fall back
- \doglobal\appendtoks % brrr better \setcatcodetable\ctxcatcodes % % test
- \bgroup\disableXML\loadallsystemfiles\f!errfilename\donothing\egroup
- \to\everygoodbye}}
-
-%D Loading of \type {cont-usr.tex} (edited by the user)
-%D and \type {cont-fmt.tex} (generated by texexec).
-
-\def\loaduserspecifications
- {% this used to be the file where users can tune their system, especially patterns
- \readsysfile\f!usrfilename{\showmessage\m!systems2\f!usrfilename}\donothing
- % this one took care of user preferences (fonts, messages) but lm made this obsolete
- \readjobfile\f!fmtfilename{\showmessage\m!systems2\f!fmtfilename}\donothing
- % from now on we preload all patterns (only in mkii)
- \preloadallpatterns}
-
-%D We don't want multiple jobfiles to interfere.
-
-\def\loadoptionfile
- {\readjobfile{\jobname.\f!optionextension}
- {\showmessage\m!systems2{\jobname.\f!optionextension}}%
- {\writestatus\m!systems {no \jobname.\f!optionextension}}}
-
-% \newevery \everyjob \EveryJob
-% \appendtoks ... \to \everyjob
-
-\appendtoks \loadsystemfiles \to \everyjob
-\appendtoks \preloadfonts \to \everyjob
-\appendtoks \settopskip \to \everyjob
-\appendtoks \preloadlanguages \to \everyjob
-\appendtoks \preloadspecials \to \everyjob
-\appendtoks \openspecialfile \to \everyjob
-%appendtoks \checkutilityfile \to \everyjob % obsolete
-\appendtoks \openutilities \to \everyjob
-\appendtoks \loadoptionfile \to \everyjob
-%appendtoks \loadtwopassdata \to \everyjob
-\appendtoks \checknotes \to \everyjob % depends on bodyfont
-\appendtoks \initializeMPgraphics \to \everyjob % after loading system files
-
-\appendtoks \page[\v!last] \page \to \everybye
-\appendtoks \ifarrangingpages\poparrangedpages\fi \to \everybye
-\appendtoks \registerfileinfo[end]\jobname \to \everybye
-
-\appendtoks \savenofpages \to \everybye
-\appendtoks \savenofsubpages \to \everybye
-
-\appendtoks \closeutilities \to \everygoodbye
-\appendtoks \stopcopyingblocks \to \everygoodbye
-\appendtoks \closespecialfile \to \everygoodbye
-
-\prependtoks \resetutilities \to \everystarttext % moved 28-02-2002
-\prependtoks \loadtwopassdata \to \everystarttext % moved 28-02-2002
-\appendtoks \checkreferences \to \everystarttext % new 04-12-1999
-
-% Most natural ...
-%
-% \def\doateverystarttext
-% {\the\everystarttext
-% \global\let\doateverystarttext\relax}
-%
-% ... most practical, since we can load env's in a
-% something.run file (nested \starttext's; see for
-% instance x-res-08, where we definitely want to
-% open the file!).
-
-\def\doateverystarttext
- {\the\everystarttext
- \global\everystarttext\emptytoks}
-
-\def\starttext
- {\doateverystarttext
- \ifcase\textlevel
- \registerfileinfo[begin]\jobname
- \expandafter\startcopyingblocks
- \fi
- \global\advance\textlevel\plusone}
-
-\def\stoptext
- {\global\advance\textlevel\minusone
- \ifnum\textlevel>\zerocount \else
- \the\everystoptext
- %\the\everybye %
- %\the\everygoodbye % == \end (new)
- %\expandafter\normalend %
- \expandafter\finalend
- \fi}
-
-\def\finalend
- {\ifnum\textlevel>\zerocount \else
- \the\everybye
- \the\everygoodbye
- \global\everybye \emptytoks % rather unneeded
- \global\everygoodbye\emptytoks % but for sure
- \expandafter\normalend
- \fi}
-
-\let\end\finalend
-
-\def\emergencyend
- {\writestatus\m!systems{invalid \@EA\string\csname\e!start\v!text\endcsname...\@EA\string\csname\e!stop\v!text\endcsname\space structure}%
- \stoptext}
-
-\def\currentfile{\inputfilename}
-
-\def\doexecutefileonce#1%
- {\beforesplitstring#1\at.\to\currentfile
- \fullexpandtwoargsafter\doifnotinset\currentfile\loadedfiles
- {\fullexpandoneargafter\addtocommalist\currentfile\loadedfiles
- \doexecutefile{#1}}}
-
-\def\doexecutefile#1%
- {\registerfileinfo[begin]{#1}%
- \dostarttextfile{#1}%
- \processfile{#1}%
- \dostoptextfile
- \registerfileinfo[end]{#1}}
-
-\def\donotexecutefile#1%
- {}
-
-\def\verwerkfile#1 %
- {\doexecutefile{#1}}
-
-\def\useenvironment[#1]% maybe commalist
- {\environment #1 \relax}
-
-\def\environment #1 % at outermost level only (load only once)
- {\pushmacro\startenvironment
- \pushmacro\stopenvironment
- \def\startenvironment ##1 {}%
- \let\stopenvironment\relax
- \startreadingfile
- \doexecutefileonce{#1}
- \stopreadingfile
- \popmacro\stopenvironment
- \popmacro\startenvironment}
-
-\def\component #1 % at outermost level only
- {\dostarttextfile{#1}%
- \processfile{#1}%
- \dostoptextfile}
-
-\newcount\filelevel
-
-\let\currentcomponent \v!text
-\let\currentcomponentpath\f!currentpath
-
-\def\donextlevel#1#2#3#4#5#6#7\\%
- {\pushmacro\currentcomponent
- \pushmacro\currentcomponentpath
- \let\currentcomponent#1%
- \setsystemmode\currentcomponent
- \splitfilename{#1}%
- \ifx\splitoffpath\empty
- \let\currentcomponentpath\f!currentpath
- \else
- \let\currentcomponentpath\splitoffpath
- \fi
- \beforesplitstring#7\at.\to#2\relax % can become path + base
- \ifcase\filelevel\relax
- \starttext
- \def\project ##1 {#3{##1}}%
- \def\environment ##1 {#4{##1}}%
- \def\product ##1 {#5{##1}}%
- \def\component ##1 {#6{##1}}%
- \fi
- \advance\filelevel\plusone
- \fullexpandoneargafter\addtocommalist{#1}\loadedfiles}
-
-\def\doprevlevel
- {\popmacro\currentcomponentpath
- \popmacro\currentcomponent
- \setsystemmode\currentcomponent
- \ifnum\filelevel=\plusone
- \expandafter\stoptext
- \else
- \advance\filelevel\minusone
- \expandafter\endinput
- \fi}
-
-\def\startproject #1 %
- {\donextlevel\v!project\currentproject
- \donotexecutefile\doexecutefileonce
- \doexecutefileonce\doexecutefile#1\\}
-
-\def\startproduct #1 %
- {\doateverystarttext
- \donextlevel\v!product\currentproduct
- \doexecutefileonce\doexecutefileonce
- \donotexecutefile\doexecutefile#1\\}
-
-\def\startcomponent #1 %
- {\doateverystarttext
- \donextlevel\v!component\currentcomponent
- \doexecutefileonce\doexecutefileonce
- \donotexecutefile\doexecutefile#1\\}
-
-\def\startenvironment #1 %
- {\donextlevel\v!environment\currentenvironment
- \donotexecutefile\doexecutefileonce
- \donotexecutefile\donotexecutefile#1\\}
-
-% \startproject test
-% 1: \startmode[*project] project \stopmode \endgraf
-% 2: \startmode[*product] product \stopmode \endgraf
-% \stopproject
-
-\def\stopproject {\doprevlevel}
-\def\stopproduct {\doprevlevel}
-\def\stopcomponent {\doprevlevel}
-\def\stopenvironment{\doprevlevel}
-
-% more or less replaced by modes
-
-\setvalue{\e!start\v!localenvironment}[#1]%
- {\let\loadedlocalenvironments\empty
- \def\docommand##1%
- {\beforesplitstring##1\at.\to\someevironment
- \fullexpandoneargafter\addtocommalist\someevironment\loadedlocalenvironments}%
- \processcommalist[#1]\docommand
- \fullexpandtwoargsafter\doifcommonelse % no longer next needed
- {\currentproject,\currentproduct,%
- \currentcomponent,\currentenvironment}
- {\loadedlocalenvironments}
- {\letvalue{\e!stop\v!localenvironment}\relax}
- {\grabuntil{\e!stop\v!localenvironment}\gobbleoneargument}} % TH: fixed, was \relax
-
-\setvalue{\v!localenvironment}#1 {\doexecutefileonce{#1}}
-
-% NOT TOEVOEGEN: \the\everytrace
-
-\neverypar=\emptytoks
-
-% \appendtoks \flushnotes \to \everypar
-% \appendtoks \synchronizesidefloats \to \everypar
-% \appendtoks \checkindentation \to \everypar
-% \appendtoks \showparagraphnumber \to \everypar
-% \appendtoks \flushmargincontents \to \everypar
-% \appendtoks \flushcommentanchors \to \everypar
-% \appendtoks \synchronizenotes \to \everypar
-
-% \appendtoks \flushnotes \to \everydisplay
-% \appendtoks \adjustsidefloatdisplaylines \to \everydisplay
-
-% soon, when pdftex 1.22 is out in the field:
-
-\chardef\systemcommandmode\zerocount % 0=unknown 1=disabled 2=enabled
-
-\ifx\pdfshellescape\undefined \else
- \prependtoks
- \chardef\systemcommandmode \ifcase\pdfshellescape \plusone \else \plustwo \fi
- \to \everyjob
-\fi
-
-\appendtoks
- \ifcase\systemcommandmode
- \or
- \writestatus\m!systems{system commands are disabled}%
- \or
- \writestatus\m!systems{system commands are enabled}%
- \fi
-\to \everyjob
-
-\ifx\etexversion\undefined \else \ifnum\etexversion<202
- \prependtoks
- \writestatus\m!systems{eTeX version \number\etexversion\space -> too old (bugs)}%
- \writeline
- \to \everyjob
-\fi \fi
-
-\ifx\pdftexversion\undefined \else \ifnum\number\pdftexversion<120
- \prependtoks
- \writestatus\m!systems{pdfTeX version \number\pdftexversion\space -> please update}%
- \writeline
- \to \everyjob
-\fi \fi
-
-\prependtoks \showcontextbanner \to \everyjob
-
-% Default-instellingen (verborgen)
-
-\resetutilities
-
-\protect \endinput
diff --git a/tex/context/base/core-lme.tex b/tex/context/base/core-lme.tex
index d8c99d8c7..69dc3b7b2 100644
--- a/tex/context/base/core-lme.tex
+++ b/tex/context/base/core-lme.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Last Minute Extensions}
+\writestatus{loading}{ConTeXt Core Macros / Last Minute Extensions}
%D Things that depend on too much other things.
diff --git a/tex/context/base/core-lnt.tex b/tex/context/base/core-lnt.tex
index 0d960decd..ae3200e7a 100644
--- a/tex/context/base/core-lnt.tex
+++ b/tex/context/base/core-lnt.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Line Notes}
+\writestatus{loading}{ConTeXt Core Macros / Line Notes}
%D This module loads on top of the footnote and line numbering macros.
diff --git a/tex/context/base/core-lst.tex b/tex/context/base/core-lst.tex
index d246be3bc..84648f6c9 100644
--- a/tex/context/base/core-lst.tex
+++ b/tex/context/base/core-lst.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Lists}
+\writestatus{loading}{ConTeXt Core Macros / Lists}
\unprotect
@@ -241,6 +241,7 @@
\c!depth=\v!broad,
\c!offset=0.25em,
\c!maxwidth=,
+ \c!align=,
\c!state=\v!start,
\c!coupling=\v!off,
\c!criterium=\v!local,
diff --git a/tex/context/base/core-ltb.tex b/tex/context/base/core-ltb.tex
deleted file mode 100644
index 3ebd16379..000000000
--- a/tex/context/base/core-ltb.tex
+++ /dev/null
@@ -1,856 +0,0 @@
-%D \module
-%D [ file=core-ltb,
-%D version=2002.10.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Line Tables,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% testfile: tfmetrics.tex
-
-% todo: als nx>1, dan in geval van rek tussenruimte berekenen en optellen
-% bij breedte, dus: nx nog niet gebruiken in combinatie met rek ! ! ! ! !
-
-% This module is experimental, undocumented, and currently only set up
-% eTeX. It provides a mechanism for typesetting very large tables,
-% spanning many pages horizontally and vertically, with repeated
-% header lines and (entry) columns, tab tracking, color, etc. In does
-% two passes over a table, which is why the table goes into a
-% buffer or file. As said, tables can be real huge.
-
-% \BH \BC .. \EC \BC .. \EC \EH % append
-% \BR \BC .. \EC \BC .. \EC \ER
-%
-% or
-%
-% \NC .. \NC .. \NC \NR (todo: optional last \NC)
-
-% alternative:
-%
-% (1) direct run, save content in macro, but only if needed
-%
-% todo
-%
-% (2) buffered table content
-%
-% \startbuffer
-% \startlinetablehead
-% \stoplinetablehead
-% \startlinetablebody
-% \stoplinetablebody
-% \stopbuffer
-%
-% \processlinetablebuffer[buffer]
-%
-% in buffer : head and body
-%
-% (3) unbuffered run, multipass
-%
-% - run with starting width zero / prev run
-% - clip on prev run
-% - flush real widths
-
-\writestatus{loading}{Context Core Macros / Line Tables}
-
-\unprotect
-
-\chardef\linetablesplitstate\zerocount
-\chardef\linetableheadstate \zerocount
-
-\edef\??ler{\??le:r:}
-\edef\??lec{\??le:c:}
-\edef\??lew{\??le:w:}
-\edef\??leh{\??le:h:}
-\edef\??led{\??le:d:}
-
-\newif\iflinetablepreroll
-\newif\ifinlinetable
-
-\newcount\linetablecolumn
-\newcount\linetablesubcol
-\newdimen\linetablewidth
-\newdimen\linetableheight
-\newbox \linetablecell
-
-\let\noflinetablecolumns\!!zerocount
-\let\noflinetablerows \!!zerocount
-\let\noflinetablelines \!!zerocount
-\let\noflinetableparts \!!zerocount
-\let\linetablepart \!!plusone
-\let\linetablestep \!!plusone
-\let\linetableline \!!zerocount
-\let\linetablerow \!!zerocount
-\let\linetablerows \!!zerocount
-
-\initializetablebox \zerocount % holds repeater
-
-\chardef\linetablehmode \zerocount
-\chardef\linetablepage \zerocount
-\chardef\linetablerepeat\zerocount
-
-\def\setuplinetable
- {\dotripleempty\dosetuplinetable}
-
-\def\dosetuplinetable[#1][#2][#3]%
- {\ifthirdargument
- \getparameters[\??le:#1:#2][#3]%
- \else\ifsecondargument
- \getparameters[\??lec#1][#2]%
- \else
- \getparameters[\??le][#1]%
- \fi\fi}
-
-\setuplinetable
- [\c!n=\!!maxcard,
- \c!lines=\!!maxcard,
- \c!nx=\plusone,
- \c!nleft=0,
- \c!repeat=\v!yes, % when \c!nleft>0, repeat on both pages
- \c!before=,
- \c!after=,
- \c!inbetween=\page,
- \c!distance=\zeropoint,
- \c!stretch=\v!no,
- \c!align=\c!right,
- \c!leftoffset=.25ex,
- \c!rightoffset=\linetableparameter\c!leftoffset,
- \c!maxwidth=\zeropoint,
- \c!width=5em,
- \c!height=\v!fit, % \v!line = faster
- \c!background=,
- \c!backgroundcolor=]
-
-\def\linetableparameter#1%
- {\csname\??le#1\endcsname}
-
-\def\doifelselinetablecparameter#1%
- {\ifcsname\??lec\number\linetablecolumn#1\endcsname
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\linetablecparameter#1%
- {\csname
- \ifcsname\??lec\number\linetablecolumn#1\endcsname
- \??lec\number\linetablecolumn
- \else
- \??le
- \fi
- #1\endcsname}
-
-\def\linetablerparameter#1% faster, leaner and meaner
- {\csname
- \ifnum\linetablerow=\zerocount % geen ifcase
- \ifcsname\??ler\v!header#1\endcsname
- \??ler\v!header#1%
- \else\ifcsname\??ler0#1\endcsname
- \??ler0#1%
- \else
- \s!empty
- \fi\fi
- \else
- \ifcsname\??ler\number\linetablerow#1\endcsname
- \??ler\number\linetablerow#1%
- \else\ifcsname\??ler\v!oddeven\linetablerow#1\endcsname
- \??ler\v!oddeven\linetablerow#1%
- \else
- \s!empty
- \fi\fi
- \fi
- \endcsname}
-
-\def\setnoftableslines
- {\doifelse{\linetableparameter\c!lines}\v!fit
- {% whitespace already added by vertical strut
- \ifdim\pagegoal<\maxdimen
- \scratchdimen\pagegoal
- \advance\scratchdimen -\pagetotal
- \else
- \scratchdimen\textheight
- \fi
- \getrawnoflines\scratchdimen
- \xdef\noflinetablelines{\the\noflines}
-\iflinetablepreroll \else \ifnum\noflinetablelines<\plustwo
- \page \setnoftableslines
-\fi \fi
-}
- {\xdef\noflinetablelines{\linetableparameter\c!lines}}}
-
-\def\startlinetablecell
- {\dosingleempty\dostartlinetablecell}
-
-\def\dostartlinetablecell[#1]%
- {\global\setbox\linetablecell\hbox\bgroup
- \iffirstargument
- \getparameters[\??lec\number\linetablecolumn][#1]%
- \fi
- \xdef\linetablestep{\linetablecparameter\c!nx}%
- \ifcase\linetablestep\or
- \scratchdimen\linetablecparameter\c!width
- \scratchskip \linetablecparameter\c!distance
- \else
- \scratchdimen \zeropoint
- \scratchskip \zeropoint
- \scratchcounter\linetablecolumn
- \dorecurse\linetablestep
- {\advance\scratchdimen\linetablecparameter\c!width
- %\advance\scratchskip \linetablecparameter\c!distance
- \global\advance \linetablecolumn\plusone
- \advance\scratchskip \linetablecparameter\c!distance
- }%
- \global\linetablecolumn\scratchcounter
- \fi
- \chardef\linetablemode
- \iflinetablepreroll
- \ifdim\scratchdimen>\zeropoint \zerocount \else \plustwo \fi
- \else
- \zerocount
- \fi
- \ifcase\linetablemode
- \ifcase\linetablehmode
- % nothing
- \or
- % fit, keep it simple
- \or
- \chardef\linetablemode\plusone % line
- \else
- % some already calculated height
- \fi
- \fi
- \setbox\scratchbox\hbox
- \bgroup
- \dontcomplain
- \hskip\linetablecparameter\c!leftoffset\relax
- % 0 = width, unknown height
- % 1 = width, fixed height
- % 2 = no width, auto hsize
- \ifnum\linetablemode<\plustwo
- \advance\scratchdimen-\linetablecparameter\c!leftoffset
- \advance\scratchdimen-\linetablecparameter\c!rightoffset
- \fi
- \ifcase\linetablemode
- \dosetraggedcommand{\linetablecparameter\c!align}%
- \vtop \ifdim\linetableheight>\zeropoint to\linetableheight \fi \bgroup
- \hsize\scratchdimen
- \raggedcommand
- \else
- \setalignmentswitch{\linetablecparameter\c!align}%
- \hbox \ifcase\linetablemode \or to\scratchdimen \fi \bgroup
- \ifcase\alignmentswitch\hss\or\hss\fi
- \fi
- \dostartattributes{\??lec\number\linetablecolumn}\c!style\c!color\empty
- \begstrut \ignorespaces}
-
-% \def\stoplinetablecell
-% {\unskip \endstrut
-% \dostopattributes
-% \ifcase\linetablemode
-% \endgraf
-% \else
-% \ifcase\alignmentswitch\else\hss\fi
-% \fi
-% \egroup
-% \hskip\linetablecparameter\c!rightoffset
-% \egroup
-% \iflinetablepreroll
-% \box\scratchbox
-% \else
-% \doif{\linetablecparameter\c!background}\v!color
-% {\backgroundline[\linetablecparameter\c!backgroundcolor]}%
-% {\box\scratchbox}%
-% \fi
-% \egroup}
-
-\newconditional\linetableautoheight \settrue\linetableautoheight
-
-\def\stoplinetablecell
- {\unskip \endstrut
- \dostopattributes
- \ifcase\linetablemode
- \endgraf
- \else
- \ifcase\alignmentswitch\else\hss\fi
- \fi
- \egroup
- \hskip\linetablecparameter\c!rightoffset
- \egroup
- \iflinetablepreroll
- \box\scratchbox
- \else
- \doifelse{\linetablecparameter\c!background}\v!color
- {\ifconditional\linetableautoheight
- \hbox{\blackrule
- [ \c!color=\linetablecparameter\c!backgroundcolor,
- \c!height=\linetablerparameter{x\c!height},
- \c!depth=\linetablerparameter{x\c!depth},
- \c!width=\wd\scratchbox]%
- \hskip-\wd\scratchbox\box\scratchbox}%
- \else
- \backgroundline[\linetablecparameter\c!backgroundcolor]{\box\scratchbox}%
- \fi}%
- {\box\scratchbox}%
- \fi
- \egroup}
-
-% \def\stoplinetablecell
-% {\unskip \endstrut
-% \dostopattributes
-% \ifcase\linetablemode
-% \endgraf
-% \else
-% \ifcase\alignmentswitch\else\hss\fi
-% \fi
-% \egroup
-% \hskip\linetablecparameter\c!rightoffset
-% \egroup
-% \iflinetablepreroll
-% \box\scratchbox
-% \else
-% \doifelse{\linetablecparameter\c!background}\v!color
-% {\ifconditional\linetableautoheight
-% % \hbox{\blackrule
-% % [ \c!color=\linetablecparameter\c!backgroundcolor,
-% % \c!height=\linetablerparameter{x\c!height},
-% % \c!depth=\linetablerparameter{x\c!depth},
-% % \c!width=\wd\scratchbox]%
-% % \hskip-\wd\scratchbox\box\scratchbox}%
-% \dp\scratchbox\linetablerparameter{x\c!depth}%
-% \ht\scratchbox\linetablerparameter{x\c!height}%
-% \framed
-% [\c!offset=\v!overlay,
-% \c!frameoffset=.5\linewidth,
-% \c!leftframe=\v!off,\c!rightframe=\v!off,
-% \c!background=\v!color,
-% \c!backgroundcolor=\linetablecparameter\c!backgroundcolor%
-% ]{\box\scratchbox}%
-% \else
-% \backgroundline[\linetablecparameter\c!backgroundcolor]{\box\scratchbox}%
-% \fi}%
-% {\box\scratchbox}%
-% \fi
-% \egroup}
-
-\def\savelinetablepart
- {\global\setbox\tablebox\linetablepart
- \ifnum\linetablepart=\zerocount
- \box\scratchbox % just storing
- \else
- \vbox
- {\ifvoid\tablebox\linetablepart\else\unvbox\tablebox\linetablepart\fi
- \doif{\linetablerparameter\c!background}\v!color
- {\backgroundline[\linetablerparameter\c!backgroundcolor]}%
- {\box\scratchbox}% is also arg to \backgroundline
- \endgraf
- \linetablerparameter\c!after}%
- \fi}
-
-\def\flushlinetableparts
- {\doglobal\increment\linetableline
- \ifnum\linetableline<\noflinetablelines
- % keep collecting
- \else
- \iflinetablepreroll
- % forget about them
- \else
- \dorecurse\noflinetableparts
- {\let\linetablepart\recurselevel
- \dp\tablebox\linetablepart\strutdepth
- % noindent en endgraf needed else whitespace mess-up!
- \whitespace % here not after verticalstrut
- \ifdim\topskipgap=\zeropoint\else
- \verticalstrut\nobreak\kern-\struttotal\kern-\parskip\nobreak\nointerlineskip % fix topskip
- \fi
- \noindent\strut\hbox to \hsize{\box\tablebox\linetablepart\hss}\endgraf
- \ifnum\linetablepart<\noflinetableparts\relax
- \linetableparameter\c!inbetween
- \fi}%
- \ifnum\linetablerows<\noflinetablerows\relax
- \linetableparameter\c!inbetween
- \else
- % after, later
- \fi
- \chardef\linetableheadstate\plusthree
- \global\setbox\tablebox\zerocount\emptybox % here
- \fi
- % reset \linetablerow will be an option, currently
- % starts at zero after split
- \globallet\linetablerow\!!zerocount
- \globallet\linetableline\!!zerocount
- \global\chardef\linetablepage\zerocount
- \global\linetablewidth\zeropoint
- \setnoftableslines
- \fi}
-
-\def\startlinetablepart
- {\global\linetablesubcol\zerocount
- \setbox\scratchbox\hbox\bgroup
- \doconvertfont{\linetablerparameter\c!style}%
- \startcolor[\linetablerparameter\c!color]%
- \ignorespaces}
-
-\def\stoplinetablepart
- {\ifnum\linetablepart>\zerocount
- \unskip \unskip % remove last intercolumn skip (distance+fill)
- \fi
- \stopcolor
- \egroup
- \iflinetablepreroll \else
- \ifcase\linetablepart
- % we're collecting the repeater
- \else
- \scratchdimen\hsize \advance\scratchdimen-\wd\scratchbox\relax
- \ifdim\scratchdimen>\linetableparameter\c!stretch\else
- \setbox\scratchbox\hbox to \hsize{\unhbox\scratchbox}%
- \fi
- \fi
- \fi}
-
-\def\checklinetablepart
- {\global\advance\linetablewidth\wd\linetablecell
- \global\advance\linetablecolumn\linetablestep
- \global\advance\linetablesubcol\linetablestep
- \relax
- %\message{\the\linetablecolumn,\the\linetablesubcol}\wait
- % from now on the column counter is already incremented
- \ifcase\linetablesplitstate
- \iflinetablepreroll \else
- \box\linetablecell
- % the columncounter is one ahead !
-% \hskip\linetablecparameter\c!afstand
- \hskip\scratchskip
- \fi
- %%%
- \donefalse
- \ifcase\linetablerepeat\else
- % van te voren berekenen
- \scratchcounter\linetablecolumn\advance\scratchcounter-\plustwo
- \ifnum\linetablerepeat=\scratchcounter
- \donetrue % collecting repeater
- \fi
- \fi
- %%%%
- \ifdone
- % collecting repeater
- \else
- \ifnum\linetablecolumn>\getvalue{\??le::\linetablepart}\relax
- \donetrue
- \fi
- \fi
- \ifdone
- \stoplinetablepart
- \iflinetablepreroll \else
- \savelinetablepart
- \fi
- \ifcase\linetablepage \or
- \global\chardef\linetablepage \plustwo
- \else
- \global\chardef\linetablepage \plusone
- \fi
- \doglobal\increment\linetablepart
- \global\linetablewidth\wd\tablebox\zerocount
- \startlinetablepart
- \fi
- \else
- \donefalse
- \!!doneafalse
- \ifcase\linetablerepeat\else
- % van te voren berekenen
- \scratchcounter\linetablecolumn \advance\scratchcounter-\plustwo
- \ifnum\linetablerepeat=\scratchcounter
- \donetrue % collecting repeater
- \fi
- \fi
- \ifdone
- \!!doneatrue
- % collecting repeater
- \else\ifdim\linetablewidth>\hsize
- \donetrue
- \else
-% \global\advance\linetablewidth\linetablecparameter\c!afstand\relax
- \global\advance\linetablewidth\scratchskip
- \ifdim\linetablewidth>\hsize % ?
- \donetrue
- \fi
- \fi\fi
- \ifdone
- \stoplinetablepart
- \savelinetablepart
- \ifcase\linetablepage \or
- \global\chardef\linetablepage \plustwo
- \else
- \global\chardef\linetablepage \plusone
- \fi
- \doglobal\increment\linetablepart
- \ifnum\linetablepart>\noflinetableparts
- \globallet\noflinetableparts\linetablepart
- \initializetablebox\linetablepart
- \fi
- \global\linetablewidth\wd\linetablecell
- \startlinetablepart
- \if!!doneb \else \ifcase\linetablerepeat \else
- % check for left/right page
- \ifcase\linetablepage\donetrue\or\donetrue\or\donefalse\fi\ifdone
- % insert repeater
- \global\advance\linetablewidth\wd\tablebox\zerocount
- \iflinetablepreroll\kern\wd\else\unhcopy\fi\tablebox\zerocount
- \fi
- \fi \fi
- \fi
- \iflinetablepreroll \else
- \box\linetablecell
- % the columncounter is one ahead !
-% \hskip\linetablecparameter\c!afstand
-% \hskip\scratchskip
-\dorecurse\linetablestep{\strut\hfil}%
- \hskip\scratchskip
- \fi
- \fi}
-
-% \linetableparameter\c!var -> \@@levar (when no classes)
-
-\def\startlinetablerun % to do: quit when nested
- {\bgroup
- \inlinetabletrue
- % autowidth
- \doif{\linetableparameter\c!maxwidth}\v!fit
- {\setuplinetable[\c!maxwidth=\zeropoint]}%
- \processaction
- [\linetableparameter\c!stretch]
- [ \v!no=>{\setuplinetable[\c!stretch=\maxdimen]},% no stretch
- \v!yes=>{\setuplinetable[\c!stretch=\zeropoint]}]% max stretch
- \chardef\linetablerepeat\linetableparameter\c!nleft
- \chardef\linetablesplitstate % =
- \ifdim\linetableparameter\c!maxwidth>\zeropoint
- \zerocount \else \plusone
- \fi
- % optional prevdepth correction
- \iflinetablepreroll
- \globallet\noflinetablerows\!!zerocount
- \else
- \linetableparameter\c!before
- \fi
- \globallet\linetablerows\!!zerocount
- \globallet\noflinetablecolumns\!!zerocount
- \globallet\noflinetableparts\!!zerocount
- \!!counta\zerocount
- \def\docommand##1%
- {\doglobal\increment\noflinetableparts
- \advance\!!counta##1%
- \setxvalue{\??le::\noflinetableparts}{\the\!!counta}}%
- \processcommacommand[\linetableparameter\c!n]\docommand
- \initializetableboxes\noflinetableparts
- \ifcase\linetablerepeat
- \globallet\linetablepart\!!plusone
- \else
- \globallet\linetablepart\!!zerocount % repeater
- \fi
- \globallet\linetablestep\!!plusone
- \globallet\linetableline\!!zerocount
- \globallet\linetablerow \!!zerocount
- \global\linetablecolumn \zerocount
- \global\linetablesubcol \zerocount
- \global\linetablewidth \zeropoint
-\iflinetablepreroll \else \ifdim\pagetotal>\zeropoint
- \verticalstrut\kern-\struttotal
-\fi \fi
- \setnoftableslines
- \checklinetablepage
- \let\BR\linetableBR
- \let\ER\linetableER
- \let\BH\linetableBR
- \let\EH\linetableER
- \let\BC\linetableBC
- \let\EC\linetableEC
- \let\NC\linetableNC
- \let\NR\linetableNR
- \flushlinetablehead}
-
-\def\stoplinetablerun
- {\globallet\linetableline\!!maxcard
- \chardef\linetableheadstate\zerocount % blocked
- \flushlinetableparts
- \iflinetablepreroll \else
- \linetableparameter\c!after
- \fi
- \globallet\linetablepart \!!zerocount
- \globallet\noflinetableparts\!!zerocount
- \egroup}
-
-% \def\checklinecolumnwidth
-% {\ifundefined{\??lew\number\linetablecolumn}%
-% \donetrue
-% \else\ifdim\getvalue{\??lew\number\linetablecolumn}<\wd\linetablecell
-% \donetrue
-% \else
-% \donefalse
-% \fi\fi
-% \ifdone
-% \setxvalue{\??lew\number\linetablecolumn}{\the\wd\linetablecell}%
-% \fi}
-%
-% \def\checklinecolumnwidth
-% {\ifcsname\??lew\number\linetablecolumn\endcsname
-% \ifdim\csname\??lew\number\linetablecolumn\endcsname<\wd\linetablecell
-% \donetrue
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \setxvalue{\??lew\number\linetablecolumn}{\the\wd\linetablecell}%
-% \fi}
-
-% \def\checklinecolumnwidth
-% {\expandafter\xdef\csname\??lew\number\linetablecolumn\endcsname
-% {\expandafter\ifx\csname\??lew\number\linetablecolumn\endcsname\relax
-% \the\wd\linetablecell
-% \else\ifdim\csname\??lew\number\linetablecolumn\endcsname<\wd\linetablecell
-% \the\wd\linetablecell
-% \else
-% \csname\??lew\number\linetablecolumn\endcsname
-% \fi\fi}}
-
-\def\checklinecolumndimension#1#2#3%
- {\expandafter\xdef\csname#1\number#3\endcsname
- {\expandafter\ifx\csname#1\number#3\endcsname\relax
- \the#2\linetablecell
- \else\ifdim\csname#1\number#3\endcsname<#2\linetablecell
- \the#2\linetablecell
- \else
- \csname#1\number#3\endcsname
- \fi\fi}}
-
-\def\checklinecolumnwidth {\checklinecolumndimension\??lew\wd\linetablecolumn}
-\def\checklinecolumnheight{\checklinecolumndimension\??leh\ht\linetablerow}
-\def\checklinecolumndepth {\checklinecolumndimension\??led\dp\linetablerow}
-
-\def\linetableBR
- {\dosingleempty\dolinetableBR}
-
-\def\dolinetableBR[#1]% #1 not yet implemented
- {\ifnum\linetableheadstate=1\else
- \doglobal\increment\linetablerow
- \doglobal\increment\linetablerows
- \fi
- \global\linetablecolumn\plusone
- \global\linetablesubcol\plusone
-% \linetableheight\linetablerparameter\c!height
-%
-% \ifx\linetableheight\empty
-% % nothing
-% \else\ifx\linetableheight\v!fit
-% % keep it simple
-% \else\ifx\linetableheight\v!line
-% \chardef\linetablemode\plusone
-% \else
-% \!!heighta\linetableheight
-% \advance\!!heighta-\strutdepth
-% \fi\fi\fi
-%
- \linetableheight\zeropoint
- \edef\!!stringa{\linetablerparameter\c!height}%
- \ifx\!!stringa\empty
- \chardef\linetablehmode\zerocount
- \else\ifx\!!stringa\v!fit
- \chardef\linetablehmode\plusone
- \else\ifx\!!stringa\v!line
- \chardef\linetablehmode\plustwo
- \else
- \linetableheight\!!stringa
- \advance\linetableheight-\strutdepth
- \fi\fi\fi
-%
- \startlinetablepart}
-
-\def\linetableBC
- {\startlinetablecell}
-
-\def\linetableEC
- {\stoplinetablecell
- \iflinetablepreroll
- \checklinecolumnwidth
- \checklinecolumnheight
- \checklinecolumndepth
- \fi
- \checklinetablepart}
-
-\def\linetableER
- {% \stoplinetablecell
- % no \box\linetablecell, i.e. dummy columnn, last \NC \NR
- \stoplinetablepart
- \savelinetablepart
- \advance\linetablecolumn \minusone
- \ifnum\linetablecolumn>\noflinetablecolumns
- \xdef\noflinetablecolumns{\number\linetablecolumn}%
- \fi
- \flushlinetableparts
- \global\linetablecolumn\zerocount
- \global\linetablewidth \zeropoint
- \ifcase\linetablerepeat
- \globallet\linetablepart\!!plusone
- \else
- \globallet\linetablepart\!!zerocount % repeater
- \fi
- \checklinetablepage
- \flushlinetablehead}
-
-\def\checklinetablepage
- {\global\chardef\linetablepage\zerocount
- \ifcase\linetablerepeat \else \ifcase\linetablepage
- \doif{\linetableparameter\c!repeat}\v!no
- {\global\chardef\linetablepage\doifoddpageelse\plusone\plustwo}%
- \fi \fi}
-
-\def\flushlinetablehead
- {\ifcase\linetableheadstate
- % 0 blocked
- \or
- % 1 doing head
- \or
- % 2 head done
- \or
- % 3 trigger flush
- \chardef\linetableheadstate\plusone
- \the\@@linetablehead\relax
- \chardef\linetableheadstate\plustwo
- \fi}
-
-\def\linetableNC % first time special treatment
- {\relax
- \ifcase\linetablecolumn
- \linetableBR
- \else
- \linetableEC
- \fi
- \linetableBC} % beware, this will result in BR BC EC BC NR
-
-\def\linetableNR
- {\stoplinetablecell % dummy
- \linetableER}
-
-\def\startlinetable
- {\startlinetablerun}
-
-\def\stoplinetable
- {\stoplinetablerun}
-
-\def\startlinetableanalysis
- {\bgroup
- \linetableprerolltrue
- \trialtypesettingtrue
- \startlinetablerun}
-
-\def\stoplinetableanalysis
- {\stoplinetablerun
- \egroup
- \globallet\noflinetablerows\linetablerows
- \dorecurse\noflinetablerows % global, from last run {\linetableparameter\c!n}
- {%\writestatus{linetable}{\recurselevel->\getvalue{\??lew\recurselevel}}%
- \setevalue{\??ler\recurselevel x\c!height}{\getvalue{\??leh\recurselevel}}%
- \setevalue{\??ler\recurselevel x\c!depth }{\getvalue{\??led\recurselevel}}%
- \letgvalue{\??leh\recurselevel}\!!zeropoint
- \letgvalue{\??led\recurselevel}\!!zeropoint}
- \dorecurse\noflinetablecolumns % global, from last run {\linetableparameter\c!n}
- {%\writestatus{linetable}{\recurselevel->\getvalue{\??lew\recurselevel}}%
- \setevalue{\??lec\recurselevel\c!width}{\getvalue{\??lew\recurselevel}}%
- \letgvalue{\??lew\recurselevel}\!!zeropoint}} % init next table
-
-% todo: store in box instead of macro
-
-\newtoks \@@linetablehead
-
-\long\def\startlinetablehead#1\stoplinetablehead
- {\ifinlinetable
- \@@linetablehead\emptytoks
- \fi
- \chardef\linetableheadstate3 % full
- \@@linetablehead{#1}%
- \ifinlinetable
- \flushlinetablehead
- \fi}
-
-\def\linetableBH
- {\ifx\EC\relax
- % signal, grabbing lines
- \else
- \@@linetablehead\emptytoks
- \fi
- \pushmacro\BC
- \pushmacro\EC
- \def\BC##1\EC{\appendtoks##1\to\@@linetablehead}%
- \let\EC\relax} % signal
-
-\def\linetableEH
- {\popmacro\EC
- \popmacro\BC
- \@EA\startlinetablehead\the\@@linetablehead\stoplinetablehead}
-
-\let\startlinetablebody\donothing
-\let\stoplinetablebody \donothing
-
-\def\processlinetablebuffer
- {\dosingleempty\doprocesslinetablebuffer}
-
-\def\doprocesslinetablebuffer[#1]%
- {\bgroup
- \let\startlinetable\donothing
- \let\stoplinetable \donothing
- \startlinetableanalysis\getbuffer[#1]\stoplinetableanalysis
- \startlinetablerun \getbuffer[#1]\stoplinetablerun
- \egroup}
-
-\def\processlinetablefile#1%
- {\bgroup
- \let\startlinetable\donothing
- \let\stoplinetable \donothing
- \startlinetableanalysis\readfile{#1}\donothing\donothing\stoplinetableanalysis
- \startlinetablerun \readfile{#1}\donothing\donothing\stoplinetablerun
- \egroup}
-
-\protect \endinput
-
-\doifnotmode{demo}{\endinput}
-
-\setuplinetable[n=6,m={2,2,2},lines=25] % m ?
-
-\setuplinetable[c][1] [width=2cm,background=color,backgroundcolor=red]
-\setuplinetable[c][4] [width=3cm,background=color,backgroundcolor=yellow]
-\setuplinetable[c][6] [width=3cm,background=color,backgroundcolor=magenta]
-\setuplinetable[r][odd] [background=color,backgroundcolor=gray]
-\setuplinetable[r][even][background=color,backgroundcolor=green]
-
-\starttext
-
-\showframe \showstruts
-
-\setupcolors[state=start]
-
-\setuppagenumbering[alternative=doublesided]\page[left]
-
-\startlinetable
-\NC aaa\crlf aaa \NC bb \NC c \NC ddddd \NC eeee \NC ff \NC \NR
-\dorecurse{100}{\NC aaa \NC bb \NC c \NC ddddd \NC eeee \NC ff \NC \NR}
-\stoplinetable
-
-\startlinetable
-\NC[style=slanted,color=green,background=color,backgroundcolor=darkred,nx=2,uitlijnen=middle] xxx
- \NC yy \NC ddddd \NC eeee \NC ff \NC \NR
-\dorecurse{100}{\NC aaa \NC bb \NC c \NC ddddd \NC eeee \NC ff \NC \NR}
-\stoplinetable
-
-% \startbuffer[lt]
-% \NC aaa\crlf aaa \NC bb \NC c \NC ddddd \NC ee \NC ff \NC \NR
-% \NC aaa\crlf aaa \NC b \NC cc \NC ddd \NC eeee \NC f \NC \NR
-% \stopbuffer
-%
-% \processlinetablebuffer[lt]
-
-\stoptext
diff --git a/tex/context/base/core-mak.tex b/tex/context/base/core-mak.tex
index 761f83156..574fb9756 100644
--- a/tex/context/base/core-mak.tex
+++ b/tex/context/base/core-mak.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / General Makeup Commands}
+\writestatus{loading}{ConTeXt Core Macros / General Makeup Commands}
\unprotect
diff --git a/tex/context/base/core-mar.tex b/tex/context/base/core-mar.tex
index 45d12d327..8096793ad 100644
--- a/tex/context/base/core-mar.tex
+++ b/tex/context/base/core-mar.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Markings}
+\writestatus{loading}{ConTeXt Core Macros / Markings}
\unprotect
@@ -108,9 +108,6 @@
\let\nomarking\empty
-\def\doifmarkingelse#1%
- {\doifdefinedelse{\??mk#1}}
-
\def\fetchmark[#1][#2]% % expandable / never use \unexpanded
{\ifcsname\??mk::#1\endcsname % saved mark
\csname\??mk::\??mk::#2\@EA\@EA\@EA\endcsname
diff --git a/tex/context/base/core-mat.tex b/tex/context/base/core-mat.tex
index f7517c445..21f4e60b8 100644
--- a/tex/context/base/core-mat.tex
+++ b/tex/context/base/core-mat.tex
@@ -13,7 +13,7 @@
% engels maken
-\writestatus{loading}{Context Core Macros / Math Fundamentals}
+\writestatus{loading}{ConTeXt Core Macros / Math Fundamentals}
\unprotect
@@ -31,16 +31,10 @@
% \definemessageconstant{math}
-% \startmessages all library: math
-% title: math
-% 1: don't use -- here (line \the\inputlineno)
-% \stopmessages
+% % messages moved
% \def\invalidmathcommand#1{\showmessage\m!math1{#1}}
-% \let\normaleqno \eqno
-% \let\normalleqno\leqno
-
% \appendtoks
% \def\eqno {\invalidmathcommand{\string\eqno }}%
% \def\leqno{\invalidmathcommand{\string\leqno}}%
@@ -55,7 +49,7 @@
% H(K|M,C) = H(K|C) - H(M|C)\eqno{\hbox{(\in{}[eq:keyapp])}}
% \stopformula
-\def\mathortext
+\unexpanded\def\mathortext
{\ifmmode
\expandafter\firstoftwoarguments
\else
@@ -342,11 +336,11 @@
\switchtoformulabodyfont[#2]%
\parskip\formulaparskip
\def\currentformula{#1}%
-% may look better in itemizations
-\doif{\formulaparameter\c!option}\v!middle
- {\def\leftdisplayskip{\zeropoint}%
- \def\rightdisplayskip{\zeropoint}}%
-% this was an experiment
+ % may look better in itemizations
+ \doif{\formulaparameter\c!option}\v!middle
+ {\def\leftdisplayskip{\zeropoint}%
+ \def\rightdisplayskip{\zeropoint}}%
+ % this was an experiment
\doifsomething{\formulaparameter\c!margin}% so we test first
{\dosetleftskipadaption{\formulaparameter\c!margin}%
\edef\leftdisplaymargin{\the\leftskipadaption}}% overloaded
@@ -415,9 +409,11 @@
\beforedisplayspace
\par
\ifvmode
- \verticalstrut
- \vskip-\struttotal
- \vskip-\baselineskip
+ \prevdepth-\maxdimen % texbook pagina 79-80
+ % otherwise problems at the top of a page, don't remove:
+ \verticalstrut
+ \vskip-\struttotal
+ \vskip-\baselineskip
\fi
\fi
$$\setdisplaydimensions
@@ -515,8 +511,6 @@
[\c!indentnext=\v!yes,
\c!alternative=multi]
-% in m-math
-%
% \defineformulaalternative[multi][\begindmath][\enddmath]
%
% \fakewords{20}{40}\epar
@@ -622,8 +616,8 @@
\setupsubformulas
[\c!conversion=\v!character,
-% \c!separator=\@@fmseparator,
- \c!separator=,%AM: for compatibility with \placesubformula
+ %\c!separator=\@@fmseparator,
+ \c!separator=,% AM: for compatibility with \placesubformula
\c!indentnext=\@@fmindentnext]
%D Experimental goodie:
@@ -718,9 +712,6 @@
\def\dispplaceformula[#1]#2$$#3$$%
{\dodoplaceformula[#1]{#2}\dostartformula{}#3\dostopformula}
-\let\normalreqno\eqno
-\let\normalleqno\leqno
-
\let\donestedformulanumber\gobbletwoarguments
\def\dodoplaceformula[#1]#2% messy, needs a clean up
@@ -768,6 +759,8 @@
%D The next code is derived from plain \TEX.
+\newcount\interdisplaylinepenalty \interdisplaylinepenalty=100
+
\newif\ifdt@p
\def\displ@y
@@ -777,7 +770,7 @@
{\noalign
{\ifdt@p
\global\dt@pfalse
- \ifdim\prevdepth>-1000\p@
+ \ifdim\prevdepth>-\thousandpoint
\vskip-\lineskiplimit
\vskip\normallineskiplimit
\fi
@@ -789,7 +782,7 @@
\def\displ@y{\resetdisplaymatheq\normaldispl@y}
-\def\m@th{\mathsurround\z@}
+\def\m@th{\mathsurround\zeropoint} % obsolete
%D Here we implement a basic math alignment mechanism. Numbers
%D are also handled. The macros \type {\startinnermath} and
@@ -1031,7 +1024,7 @@
%D some \PLAIN\ macros.
\def\@@dobig#1#2%
- {{\hbox{$\left#2\vbox\!!to#1\bodyfontsize{}\right.\n@space$}}}
+ {{\hbox{$\left#2\vbox\!!to#1\bodyfontsize{}\right.\nulldelimiterspace\zeropoint\relax\mathsurround\zeropoint$}}}
\def\big {\@@dobig{0.85}}
\def\Big {\@@dobig{1.15}}
@@ -2554,8 +2547,8 @@
\def\startsubstack
{\begingroup
\vcenter\bgroup
- \baselineskip\dimexpr\fontdimen10 \scriptfont\plustwo + \fontdimen12 \scriptfont\plustwo\relax
- \lineskip\plusthree\fontdimen8 \scriptfont\plusthree
+ \baselineskip\mathstacktotal
+ \lineskip\mathstackvgap
\lineskiplimit\lineskip
\let\stopmathmode\relax
\def\NC{\domatrixNC}%
@@ -2863,10 +2856,10 @@
\def\mathboldsymbol#1%
{\preparebinrel{#1}%
\currentbinrel{\mathchoice
- {\hbox{\switchtoformulabodyfont [boldmath]$\m@th#1$}}
- {\hbox{\switchtoformulabodyfont [boldmath]$\m@th#1$}}
- {\hbox{\switchtoformulabodyfont [boldmath,script]$\m@th#1$}}
- {\hbox{\switchtoformulabodyfont[boldmath,scriptscript]$\m@th#1$}}}}
+ {\hbox{\switchtoformulabodyfont [boldmath]$\mathsurround\zeropoint#1$}}
+ {\hbox{\switchtoformulabodyfont [boldmath]$\mathsurround\zeropoint#1$}}
+ {\hbox{\switchtoformulabodyfont [boldmath,script]$\mathsurround\zeropoint#1$}}
+ {\hbox{\switchtoformulabodyfont[boldmath,scriptscript]$\mathsurround\zeropoint#1$}}}}
\def\boldsymbol
{\mathortext\mathboldsymbol\bold}
@@ -2902,6 +2895,7 @@
\def\dealwithmathtextencoding
{\expanded{\everyhbox{\the\everyhbox\noexpand\fastenableencoding{\currentencoding}}}%
+ \expanded{\everyvbox{\the\everyvbox\noexpand\fastenableencoding{\currentencoding}}}%
\def\dealwithmathtextencoding{\let\characterencoding\nocharacterencoding}%
\dealwithmathtextencoding}
diff --git a/tex/context/base/core-mis.mkii b/tex/context/base/core-mis.mkii
new file mode 100644
index 000000000..e860a537a
--- /dev/null
+++ b/tex/context/base/core-mis.mkii
@@ -0,0 +1,2676 @@
+%D \module
+%D [ file=core-mis,
+%D version=1998.01.29,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Miscelaneous,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Misc Commands}
+
+% todo: kleur in legenda + letter
+
+% %D You would not expect the next macro in \CONTEXT,
+% %D wouldn't you? It's there to warn \LATEX\ users that
+% %D something is wrong.
+% %D
+% %D Obsolete now:
+% %
+% % \def\documentstyle{\showmessage\m!systems3\empty\stoptekst}
+% %
+% % \let\documentclass=\documentstyle
+% %D \macros
+% %D {simplifiedcommands, simplifycommands}
+% %D
+% %D I first needed this simplification in bookmarks. Users can
+% %D add their own if needed.
+
+\unprotect
+
+%D Sometimes (for instance in bookmarks) we need to simplify macro
+%D behaviour, so here is the hook.
+
+\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
+
+\def\simplifycommands{\the\simplifiedcommands}
+
+%D A possibly growing list:
+
+%appendtoks \def\executesynonym#1#2#3#4{#3}\to\simplifiedcommands
+%appendtoks \def\executesort#1#2#3{#3}\to\simplifiedcommands
+
+\appendtoks \def\ { }\to\simplifiedcommands
+\appendtoks \def\type#1{\letterbackslash\strippedcsname#1}\to\simplifiedcommands
+\appendtoks \def\tex#1{\letterbackslash#1}\to\simplifiedcommands
+\appendtoks \def\TeX{TeX}\to\simplifiedcommands
+\appendtoks \def\ConTeXt{ConTeXt}\to\simplifiedcommands
+\appendtoks \def\MetaPost{MetaPost}\to\simplifiedcommands
+\appendtoks \def\MetaFont{MetaFont}\to\simplifiedcommands
+\appendtoks \def\MetaFun{MetaFun}\to\simplifiedcommands
+%appendtoks \def||{-}\to\simplifiedcommands
+\appendtoks \def|#1|{\ifx#1\empty\empty-\else#1\fi}\to\simplifiedcommands
+
+\appendtoks\let\buildtextaccent\secondoftwoarguments\to\simplifiedcommands
+
+% THIS WAS MAIN-002.TEX
+
+%\def\checkinterlineskip
+% {\ifvmode
+% \ifdim\lastskip>\zeropoint
+% \nointerlineskip
+% \else\ifdim\lastkern>\zeropoint
+% \nointerlineskip
+% \fi\fi
+% \fi}
+
+\def\horitems#1#2% #1=breedte #2=commandos
+ {\scratchdimen#1%
+ \divide\scratchdimen \nofitems
+ \!!counta\zerocount
+ \def\docommand##1%
+ {\advance\!!counta \plusone
+ \processaction
+ [\@@isalign]
+ [ \v!left=>\hbox to \scratchdimen{\strut##1\hss},
+ \v!right=>\hbox to \scratchdimen{\hss\strut##1},
+ \v!middle=>\hbox to \scratchdimen{\hss\strut##1\hss},
+ \v!margin=>\ifnum\!!counta=\plusone\hss\else\hfill\fi
+ \strut##1%
+ \ifnum\!!counta=\nofitems\hss\else\hfill\fi,
+ \s!default=>\hbox to \scratchdimen{\hss\strut##1\hss}, % midden
+ \s!unknown=>\hbox to \scratchdimen{\strut##1\hss}]}% % links
+ \hbox to #1{\hss#2\hss}}
+
+\def\veritems#1#2% #1=breedte #2=commandos
+ {\scratchdimen#1%
+ \def\docommand##1%
+ {\ifdim\scratchdimen<\zeropoint % the - was a signal
+ \hbox to -\scratchdimen{\hss\strut##1}%
+ \else\ifdim\scratchdimen>\zeropoint
+ \hbox to \scratchdimen{\strut##1\hss}%
+ \else
+ \hbox{\strut##1}%
+ \fi\fi}%
+ \vbox{#2}}
+
+\def\dosetupitems[#1]%
+ {\getparameters[\??is][#1]%
+ \doif\@@iswidth\v!unknown
+ {\def\@@iswidth{\hsize}}%
+ \doifconversiondefinedelse\@@issymbol
+ {\def\doitembullet##1{\convertnumber{\@@issymbol}{##1}}}
+ {\doifsymboldefinedelse\@@issymbol
+ {\def\doitembullet##1{\symbol[\@@issymbol]}}{}}}
+
+\def\makeitemsandbullets#1%
+ {\doifelse\@@isn\v!unknown
+ {\getcommalistsize[#1]%
+ \edef\nofitems{\commalistsize}}
+ {\edef\nofitems{\@@isn}}%
+ \setbox0\hbox
+ {\doitems \@@iswidth
+ {\processcommalist[#1]\docommand}}%
+ \setbox2\hbox
+ {\doitems \@@isbulletbreedte
+ {\dorecurse\nofitems
+ {\docommand{\strut\doitembullet\recurselevel}}}}}
+
+\def\dostartitems#1#2#3%
+ {\let\doitems#2%
+ \def\@@isbulletbreedte{#3}%
+ \makeitemsandbullets{#1}%
+ \@@isbefore}
+
+\def\dostopitems
+ {\@@isafter
+ \egroup}
+
+\setvalue{doitems\v!top}#1%
+ {\dostartitems{#1}\horitems\@@iswidth
+ \noindent\vbox
+ {\forgetall
+ \doifsomething\@@issymbol
+ {\doifnot\@@issymbol\v!none
+ {\box2
+ \@@isinbetween
+ \nointerlineskip}}%
+ \box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!bottom}#1%
+ {\dostartitems{#1}\horitems\@@iswidth
+ \noindent\vbox
+ {\forgetall
+ \box0
+ \doifsomething\@@issymbol
+ {\@@isinbetween
+ \nointerlineskip
+ \box2}}%
+ \dostopitems}
+
+\setvalue{doitems\v!inmargin}#1%
+ {\dostartitems{#1}\veritems{-1.5em}% - is a signal
+ \noindent\hbox{\llap{\box2\hskip\leftmargindistance}\box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!left}#1%
+ {\advance\hsize -1.5em%
+ \dostartitems{#1}\veritems{1.5em}%
+ \noindent\hbox{\box2\box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!right}#1%
+ {\dostartitems{#1}\veritems{0em}%
+ \noindent\hbox{\box0\hskip-\wd2\box2}%
+ \dostopitems}
+
+\def\setupitems
+ {\dosingleargument\dosetupitems}
+
+\def\complexitems[#1]%
+ {\bgroup
+ \setupitems[#1]%
+ \parindent\zeropoint
+ \setlocalhsize
+ \hsize\localhsize
+ \dontcomplain
+ %\doifundefined{doitems\@@islocation}%
+ % {\let\@@islocation\v!left}%
+ %\getvalue{doitems\@@islocation}}
+ \executeifdefined{doitems\@@islocation}{\let\@@islocation\v!left}}
+
+\definecomplexorsimpleempty\items
+
+\setupitems
+ [\c!location=\v!left,
+ \c!symbol=5,
+ \c!width=\hsize,
+ \c!align=\v!middle,
+ \c!n=\v!unknown,
+ \c!before=\blank,
+ \c!inbetween={\blank[\v!medium]},
+ \c!after=\blank]
+
+% Te zijner tijd [plaats=boven,onder,midden] implementeren,
+% in dat geval moet eerst de maximale hoogte worden bepaald.
+%
+% Overigens kan een en ander mooier met \halign.
+
+% there is quite some historic balast in this mechanism, the next variant
+% is a first cleanup
+
+\let\currentparagraph\empty
+
+\newcount\alcounter \newcount\alnsize \newdimen\alhsize
+
+\def\paragraphparameter#1% \checkedparameter\??al\currentparagraph#1
+ {\executeifdefined{\??al\currentparagraph#1}{\executeifdefined{\??al#1}\empty}}
+
+\def\paragraphcellmeter#1#2% \checkedparameter\??al\currentparagraph#1
+ {\executeifdefined{\??al\currentparagraph\number#1#2}{\paragraphparameter{#2}}}
+
+\def\dodefineparagraphs[#1][#2]%
+ {\edef\currentparagraph{#1}%
+ \setvalue{\s!do\s!next\currentparagraph}%
+ {\def\\{\getvalue\currentparagraph}}%
+ \setvalue\currentparagraph
+ {\getvalue{\s!do\s!next#1}%
+ \dostartparagraphs{#1}}%
+ \setvalue{\e!next\currentparagraph}%
+ {\getvalue{#1}}%
+ \setvalue{\e!start\currentparagraph}%
+ {\bgroup
+ \edef\currentparagraph{#1}%
+ \letvalue{\s!do\s!next\currentparagraph}\empty
+ \setvalue{\e!stop\currentparagraph}{\getvalue\currentparagraph\egroup}%
+ \getvalue\currentparagraph}%
+ \getparameters[\??al\currentparagraph]%
+ [%\c!n=3,
+ %\c!before=\blank,
+ %\c!after=\blank,
+ %\c!distance=1em,
+ %\c!height=\v!fit,
+ %\c!rule=\v!off,
+ %\c!command=,
+ %\c!align=,
+ %\c!tolerance=\v!tolerant,
+ %\c!rulethickness=\linewidth,
+ %\c!rulecolor=,
+ %\c!style=,
+ %\c!color=,
+ %\c!top=,
+ %\c!top=\vss,
+ %\c!bottom=\vfill,
+ #2]%
+ \setvalue{\e!setup#1\e!endsetup}%
+ {\setupparagraphs[#1]}%
+ \dorecurse
+ {\paragraphparameter\c!n}
+ {\setupparagraphs
+ [\currentparagraph]
+ [\recurselevel]
+ [\c!width=,
+ %\c!bottom=\paragraphparameter\c!bottom,
+ %\c!top=\paragraphparameter\c!top,
+ %\c!height=\paragraphparameter\c!height,
+ %\c!rule=\paragraphparameter\c!rule,
+ %\c!rulethickness=\paragraphparameter\c!rulethickness,
+ %\c!rulecolor=\paragraphparameter\c!rulecolor,
+ %\c!align=\paragraphparameter\c!align,
+ %\c!tolerance=\paragraphparameter\c!tolerance, % obsolete
+ %\c!distance=\paragraphparameter\c!distance,
+ \c!style=\paragraphparameter\c!style,
+ \c!color=\paragraphparameter\c!color]}%
+ \setupparagraphs[\currentparagraph][1][\c!distance=\zeropoint]}
+
+\def\defineparagraphs
+ {\dodoubleargument\dodefineparagraphs}
+
+\def\dosetupparagraphs[#1][#2][#3]%
+ {\edef\currentparagraph{#1}%
+ \ifsecondargument
+ \doifelse{#2}\v!each
+ {\dorecurse
+ {\paragraphparameter\c!n}
+ {\getparameters[\??al\currentparagraph\recurselevel][#3]}}
+ {\doifelsenothing{#3}
+ {\getparameters[\??al\currentparagraph][#2]}
+ {\def\docommand##1{\getparameters[\??al\currentparagraph##1][#3]}%
+ \processcommalist[#2]\docommand}}%
+ \else
+ \getparameters[\??al][#1]%
+ \fi}
+
+\def\setupparagraphs
+ {\dotripleempty\dosetupparagraphs}
+
+\setupparagraphs
+ [\c!n=3,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!distance=1em,
+ \c!height=\v!fit,
+ \c!rule=\v!off,
+ \c!command=,
+ \c!align=,
+ \c!tolerance=\v!tolerant, % obsolete
+ \c!rulethickness=\linewidth,
+ \c!rulecolor=,
+ \c!style=,
+ \c!color=,
+ \c!top=,
+ \c!top=\vss,
+ \c!bottom=\vfill]
+
+\def\doparagraphrule
+ {\doifelse{\paragraphcellmeter\alcounter\c!rule}\v!on
+ {\linewidth\paragraphcellmeter\alcounter\c!rulethickness
+ \scratchdimen\paragraphcellmeter\alcounter\c!distance
+ \advance\scratchdimen-\linewidth
+ \divide\scratchdimen \plustwo
+ \hskip\scratchdimen
+ \color[\paragraphcellmeter\alcounter\c!rulecolor]{\vrule\!!width\linewidth}%
+ \hskip\scratchdimen}
+ {\hskip\paragraphcellmeter\alcounter\c!distance}}
+
+\def\dostartparagraph
+ {\doifelsenothing{\paragraphcellmeter\alcounter\c!width}
+ {\!!widtha\alhsize
+ \divide\!!widtha \alnsize}
+ {\!!widtha\paragraphcellmeter\alcounter\c!width}%
+ \dostartattributes{\??al\currentparagraph\number\alcounter}\c!style\c!color\empty
+ \doifelse{\paragraphcellmeter\alcounter\c!height}\v!fit
+ {\setbox\scratchbox\vtop}
+ {\setbox\scratchbox\vtop to \paragraphcellmeter\alcounter\c!height}%
+ \bgroup
+ \blank[\v!disable]%
+ \forgetall
+ \paragraphcellmeter\alcounter\c!top
+ \paragraphparameter\c!inner
+ \hsize\!!widtha % setting \wd afterwards removed
+ \paragraphcellmeter\alcounter\c!inner % twice
+ \expanded{\setupalign [\paragraphcellmeter\alcounter\c!align ]}% {normal,verytolerant,stretch}
+ \expanded{\setuptolerance[\paragraphcellmeter\alcounter\c!tolerance]}% obsolete
+ \ignorespaces
+ \endgraf
+ \ignorespaces
+ %
+ % Nadeel van de onderstaande constructie is dat \everypar
+ % binnen een groep kan staan en zo steeds \begstruts
+ % worden geplaatst. Mooi is anders dus moet het anders!
+ %
+ % Hier is \Everypar niet nodig.
+ %
+ \everypar{\begstrut\everypar\emptytoks}%
+ %
+ \nospace % remove + ignore
+ \paragraphcellmeter\alcounter\c!command}
+
+\def\dostopparagraph
+ {\ifvmode
+ \removelastskip
+ \else
+ \unskip\endstrut\endgraf
+ \fi
+ \paragraphcellmeter\alcounter\c!bottom
+ \egroup
+ \ifdim\wd\scratchbox=\zeropoint % no data
+ \wd\scratchbox\!!widtha
+ \fi
+ \box\scratchbox
+ \dostopattributes
+ \ifnum\alcounter<\paragraphparameter\c!n\relax
+ \@EA\doparagraphcell
+ \else
+ \@EA\dostopparagraphs
+ \fi}
+
+\def\doparagraphcell
+ {\global\advance\alcounter \plusone
+ \doifelsenothing{\paragraphcellmeter\alcounter\c!distance}
+ {\ifnum\alcounter=\plusone\else
+ \hskip\paragraphparameter\c!distance
+ \fi}
+ {\ifnum\alcounter=\plusone
+ \hskip\paragraphcellmeter\alcounter\c!distance
+ \else
+ \doparagraphrule
+ \fi}%
+ \letvalue\currentparagraph\dostopparagraph
+ \dostartparagraph}
+
+\def\dostartparagraphs#1%
+ {\bgroup
+ \edef\currentparagraph{#1}%
+ \global\alcounter\zerocount
+ \parindent\zeropoint
+ \setlocalhsize
+ \alhsize\localhsize
+ \alnsize\paragraphparameter\c!n\relax
+ \dorecurse \alnsize
+ {\doifelsenothing{\paragraphcellmeter\recurselevel\c!distance}
+ {\ifnum\recurselevel=\plusone\else
+ \global\advance\alhsize -\paragraphparameter\c!distance
+ \fi}
+ {\global\advance\alhsize -\paragraphcellmeter\recurselevel\c!distance}%
+ \doifsomething{\paragraphcellmeter\recurselevel\c!width}
+ {\global\advance\alnsize \minusone
+ \global\advance\alhsize -\paragraphcellmeter\recurselevel\c!width}}%
+ %whitespace % gaat fout bij \framed
+ \paragraphparameter\c!before
+ \leavevmode % gaat wel goed bij \framed, brrr
+ \setbox\scratchbox\vbox\bgroup\hbox\bgroup\doparagraphcell}
+
+\def\dostopparagraphs
+ {\egroup
+ \egroup
+ \iftrue
+ \hbox{\raise\strutheight\box\scratchbox}% new
+ \else
+ \box\scratchbox % old
+ \fi
+ \par
+ \paragraphparameter\c!after
+ \egroup}
+
+\def\dosetuptab[#1]%
+ {\getparameters[\??ta]
+ [\c!headstyle=\v!normal,
+ \c!headcolor=,
+ \c!style=\v!normal,
+ \c!color=,
+ \c!width=\v!broad,
+ \c!sample={\hskip4em},
+ \c!before=,
+ \c!after=,
+ #1]%
+ \definedescription
+ [tab]
+ [\c!headstyle=\@@taheadstyle,
+ \c!headcolor=\@@tacolor,
+ \c!sample=\@@tasample,
+ \c!width=\@@tawidth,
+ \c!before=\@@tabefore,
+ \c!after=\@@taafter]}
+
+\def\setuptab
+ {\dosingleargument\dosetuptab}
+
+\setuptab
+ [\c!location=\v!left]
+
+% The following macro's are derived from PPCHTEX and
+% therefore take some LaTeX font-switching into account.
+
+\newif\ifloweredsubscripts
+
+% Due to some upward incompatibality of LaTeX to LaTeX2.09
+% and/or LaTeX2e we had to force \@@chemieletter. Otherwise
+% some weird \nullfont error comes up.
+
+\doifundefined{@@chemieletter}{\def\@@chemieletter{\rm}}
+
+\def\beginlatexmathmodehack
+ {\ifmmode
+ \let\endlatexmathmodehack\relax
+ \else
+ \def\endlatexmathmodehack{$}$\@@chemieletter
+ \fi}
+
+\def\setsubscripts
+ {\beginlatexmathmodehack
+ \def\dosetsubscript##1##2##3%
+ {\dimen0=##3\fontexheight##2%
+ \setxvalue{@@\string##1\string##2}{\the##1##2\relax}%
+ ##1##2=\dimen0\relax}%
+ \def\dodosetsubscript##1##2%
+ {\dosetsubscript{##1}{\textfont2}{##2}%
+ \dosetsubscript{##1}{\scriptfont2}{##2}%
+ \dosetsubscript{##1}{\scriptscriptfont2}{##2}}%
+ %dodosetsubscript\mathsupnormal {?}%
+ \dodosetsubscript\mathsubnormal {.7}%
+ \dodosetsubscript\mathsubcombined{.7}%
+ \global\loweredsubscriptstrue
+ \endlatexmathmodehack}
+
+\def\resetsubscripts
+ {\ifloweredsubscripts
+ \beginlatexmathmodehack
+ \def\doresetsubscript##1##2%
+ {\dimen0=\getvalue{@@\string##1\string##2}\relax
+ ##1##2=\dimen0}%
+ \def\dodoresetsubscript##1%
+ {\doresetsubscript{##1}{\textfont2}%
+ \doresetsubscript{##1}{\scriptfont2}%
+ \doresetsubscript{##1}{\scriptscriptfont2}}%
+ %dodoresetsubscript\mathsupnormal
+ \dodoresetsubscript\mathsubnormal
+ \dodoresetsubscript\mathsubcombined
+ \global\loweredsubscriptsfalse
+ \endlatexmathmodehack
+ \fi}
+
+\let\beginlatexmathmodehack = \relax
+\let\endlatexmathmodehack = \relax
+
+\def\chem#1#2#3%
+ {\bgroup
+ \setsubscripts
+ \mathematics{\hbox{#1}_{#2}^{#3}}%
+ \resetsubscripts
+ \egroup}
+
+\unexpanded\def\celsius #1{#1\mathematics{^\circ}C}
+\unexpanded\def\inch {\mathematics{\prime\prime}} % was: \hbox{\rm\char125\relax}
+\unexpanded\def\fraction#1#2{\mathematics{#1\over#2}}
+
+% very dutch
+
+\unexpanded\def\graden {\mathematics{^\circ}}
+
+\def\bedragprefix {\euro\normalfixedspace}
+\def\bedragsuffix {}
+\def\bedragempty {\euro}
+
+\unexpanded\def\bedrag#1%
+ {\strut\hbox\bgroup
+ \let\normalfixedspace\nonbreakablespace
+ \doifelsenothing{#1}
+ {\bedragempty}
+ {\bedragprefix\digits{#1}\bedragsuffix}%
+ \egroup}
+
+% \definieeralineas[test][n=3]
+%
+% \stelalineasin[test][3][breedte=4cm,uitlijnen=links]
+%
+% \startopelkaar
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{~.~~1,--} \\
+% \test hans \\ ton \\ \bedrag{~.~~1,~~} \\
+% \test hans \\ ton \\ \bedrag{~.100,--} \\
+% \test hans \\ ton \\ \subtot{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \totaal{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{nihil,--} \\
+% \test hans \\ ton \\ \totaal{nihil,--} \\
+% \test hans \\ ton \\ \subtot{nihil,--} \\
+% \stopopelkaar
+
+\def\periodswidth {.5em}
+\def\periodsdefault{3} % was 5, but now it's like \unknown
+
+\unexpanded\def\periods
+ {\dosingleempty\doperiods}
+
+\def\doperiods[#1]%
+ {\dontleavehmode
+ \begingroup
+ \scratchdimen\periodswidth
+ \hbox to \iffirstargument#1\else\periodsdefault\fi \scratchdimen
+ {\leaders\hbox to \scratchdimen{\hss.\hss}\hss}%
+ \endgroup}
+
+\unexpanded\def\unknown
+ {\periods\relax} % relax prevents lookahead for []
+
+% compatibility macros
+
+\def\doorsnede
+ {\hbox{\rlap/$\circ$} }
+
+\unexpanded\def\ongeveer
+ {\mathematics\pm}
+
+\chardef\boundarycharactermode\plusone
+
+\def\midboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \languageparameter#1%
+ %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+\def\leftboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ \languageparameter#1%
+ \nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+\def\rightboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ \prewordbreak %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \languageparameter#1%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+% actually this is pretty old, but temporary moved here
+%
+% obsolete:
+
+\def\setuphyphenmark
+ {\dodoubleargument\getparameters[\??kp]}
+
+\def\setuphyphenmark[#1]% sign=normal|wide
+ {\dodoubleargument\getparameters[\??kp][#1]%
+ \doifinsetelse\@@kpsign {\v!normal}
+ {\let\textmodehyphen\normalhyphen \let\textmodehyphendiscretionary\normalhyphendiscretionary}
+ {\let\textmodehyphen\composedhyphen\let\textmodehyphendiscretionary\composedhyphendiscretionary}}
+
+\setuphyphenmark[\c!sign=\v!wide]
+% % \setuphyphenmark[\c!sign=\v!normal]
+
+\definesymbol[\c!lefthyphen] [\languageparameter\c!lefthyphen]
+\definesymbol[\c!righthyphen] [\languageparameter\c!righthyphen]
+\definesymbol[\c!hyphen] [\languageparameter\c!hyphen]
+
+\def\normalhyphen
+ {\hbox{\directsymbol\empty\c!hyphen}}
+
+\def\composedhyphen
+ {\hbox{\directsymbol\empty\c!compoundhyphen}}
+
+\def\normalhyphendiscretionary
+ {\discretionary
+ {\hbox{\directsymbol\empty\c!lefthyphen}}
+ {\hbox{\directsymbol\empty\c!righthyphen}}
+ {\hbox{\directsymbol\empty\c!hyphen}}}
+
+\def\composedhyphendiscretionary
+ {\discretionary
+ {\hbox{\directsymbol\empty\c!leftcompoundhyphen}}
+ {\hbox{\directsymbol\empty\c!rightcompoundhyphen}}
+ {\hbox{\directsymbol\empty\c!compoundhyphen}}}
+
+\let\textmodehyphen \composedhyphen
+\let\textmodehyphendiscretionary\composedhyphendiscretionary
+
+\definesymbol[\c!leftcompoundhyphen] [\languageparameter\c!leftcompoundhyphen]
+\definesymbol[\c!rightcompoundhyphen] [\languageparameter\c!rightcompoundhyphen]
+\definesymbol[\c!compoundhyphen] [\languageparameter\c!compoundhyphen]
+
+\definehspace [sentence] [\zeropoint]
+\definehspace [intersentence] [.250em]
+
+\definesymbol
+ [\c!midsentence]
+ [\midboundarycharacter\c!midsentence{sentence}]
+
+\definesymbol
+ [\c!leftsentence]
+ [\leftboundarycharacter\c!leftsentence{sentence}]
+
+\definesymbol
+ [\c!rightsentence]
+ [\rightboundarycharacter\c!rightsentence{sentence}]
+
+\definesymbol
+ [\c!leftsubsentence]
+ [\leftboundarycharacter\c!leftsubsentence{sentence}]
+
+\definesymbol
+ [\c!rightsubsentence]
+ [\rightboundarycharacter\c!rightsubsentence{sentence}]
+
+\newsignal \subsentencesignal
+\newcounter\subsentencelevel
+
+\let\beforesubsentence\donothing
+\let\aftersubsentence \donothing
+
+% todo: make this language option
+%
+% \def\beforesubsentence{\removeunwantedspaces}
+% \def\aftersubsentence {\ignorespaces}
+
+\def\midsentence
+ {\symbol[\c!midsentence]}
+
+\def\beginofsubsentence
+ {\beforesubsentence
+ \ifdim\lastkern=\subsentencesignal
+ \unskip
+ \kern\hspaceamount\currentlanguage{intersentence}%
+ \fi
+ \doglobal\increment\subsentencelevel
+ \ifnum\subsentencelevel=\plusone
+ \dontleavehmode % was \leaveoutervmode
+ \fi
+ \symbol[\ifodd\subsentencelevel\c!leftsentence\else\c!leftsubsentence\fi]%
+ }% \ignorespaces}
+
+\def\endofsubsentence % relax prevents space gobbling
+ {\symbol[\ifodd\subsentencelevel\c!rightsentence\else\c!rightsubsentence\fi]%
+ \doglobal\decrement\subsentencelevel
+ \unskip
+ \kern\subsentencesignal\relax
+ \aftersubsentence}
+
+\def\beginofsubsentencespacing % relax prevents space gobbling
+ {\kern\subsentencesignal\relax}% \ignorespaces}
+
+\def\endofsubsentencespacing
+ {\ifdim\lastkern=\subsentencesignal
+ \unskip
+ \hskip\hspaceamount\currentlanguage{intersentence}%
+ % no good, actually language dependent:
+% \ignorespaces
+ \else
+ \unskip
+ \fi}
+
+%D \startbuffer
+%D test |<|test |<|test|>| test|>| test \par
+%D test|<|test|<|test|>|test|>|test \par
+%D test |<||<|test|>||>| test \par
+%D test \directdiscretionary{<}test\directdiscretionary{>} test \par
+%D \stopbuffer
+%D
+%D \typebuffer
+%D \getbuffer
+
+\def\startsubsentence{\beginofsubsentence \prewordbreak\beginofsubsentencespacing}
+\def\stopsubsentence {\endofsubsentencespacing\prewordbreak\endofsubsentence}
+
+%D \defineXMLenvironment [subsentence]
+%D {|<|}
+%D {|>|}
+%D \defineXMLenvironment [subsentence]
+%D {\directdiscretionary{<}}
+%D {\directdiscretionary{>}}
+%D \defineXMLenvironment [subsentence]
+%D {\startsubsentence}
+%D {\stopsubsentence}
+%D
+%D \startbuffer
+%D test test test
+%D \stopbuffer
+%D
+%D \typebuffer
+%D \processXMLbuffer
+
+\enableactivediscretionaries
+
+\definehspace [quotation] [\zeropoint]
+\definehspace [interquotation] [.125em]
+
+%definehspace [quote] [\zeropoint]
+%definehspace [speech] [\zeropoint]
+
+\definehspace [quote] [\hspaceamount\currentlanguage{quotation}]
+\definehspace [speech] [\hspaceamount\currentlanguage{quotation}]
+
+\definesymbol
+ [\c!leftquotation]
+ [\leftboundarycharacter\c!leftquotation{quotation}]
+
+\definesymbol
+ [\c!rightquotation]
+ [\rightboundarycharacter\c!rightquotation{quotation}]
+
+\definesymbol
+ [\c!leftquote]
+ [\leftboundarycharacter\c!leftquote{quote}]
+
+\definesymbol
+ [\c!rightquote]
+ [\rightboundarycharacter\c!rightquote{quote}]
+
+\definesymbol
+ [\c!leftspeech]
+ [\leftboundarycharacter\c!leftspeech{speech}]
+
+\definesymbol
+ [\c!rightspeech]
+ [\rightboundarycharacter\c!rightspeech{speech}]
+
+\definesymbol
+ [\c!middlespeech]
+ [\leftboundarycharacter\c!middlespeech{speech}]
+
+\appendtoks\def\quotation#1{"#1"}\to\simplifiedcommands
+\appendtoks\def\quote #1{'#1'}\to\simplifiedcommands
+
+%D The next features was so desperately needed by Giuseppe
+%D Bilotta that he made a module for it. Since this is a
+%D typical example of core functionality, I decided to extend
+%D the low level quotation macros in such a way that a speech
+%D feature could be build on top of it. The speech opening and
+%D closing symbols are defined per language. Italian is an
+%D example of a language that has them set.
+
+% this will replace the quotation and speed definitions
+
+\newsignal\delimitedtextsignal
+
+\let\currentdelimitedtext\s!unknown
+
+\def\delimitedtextparameter#1% will be sped up
+ {\executeifdefined{\??ci\currentdelimitedtext:\csname\??ci\currentdelimitedtext\c!level\endcsname#1}%
+ {\executeifdefined{\??ci\currentdelimitedtext#1}%
+ {\executeifdefined{\??ci#1}\empty}}}
+
+\def\definedelimitedtext
+ {\dodoubleempty\dodefinedelimitedtext}
+
+\def\dodefinedelimitedtext[#1][#2]%
+ {\doifassignmentelse{#2}
+ {\getparameters
+ [\??ci#1]
+ [\c!location=\v!margin, % \v!text \v!paragraph
+ \c!spacebefore=,
+ \c!spaceafter=\delimitedtextparameter\c!spacebefore,
+ \c!style=\v!normal,
+ \c!color=,
+ \c!leftmargin=\zeropoint,
+ \c!rightmargin=\delimitedtextparameter\c!leftmargin,
+ \c!indentnext=\v!yes,
+ \c!before=,
+ \c!after=,
+ \c!left=,
+ \c!right=,
+ \c!level=0,
+ \c!repeat=\v!no,
+ \c!method=,
+ #2]}%
+ {\doifdefined{#2}
+ {\copyparameters[\??ci#1][\??ci#2]
+ [\c!location,\c!spacebefore,\c!spaceafter,\c!style,\c!color,
+ \c!leftmargin,\c!rightmargin,\c!indentnext,
+ \c!before,\c!after,\c!left,\c!right]}}%
+ \doifsomething{#1}
+ {\unexpanded\setvalue{#1}{\delimitedtext[#1]}%
+ \setvalue{\e!start#1}{\startdelimitedtext[#1]}%
+ \setvalue{\e!stop #1}{\stopdelimitedtext}}}
+
+\def\setupdelimitedtext
+ {\dotripleargument\dosetupdelimitedtext}
+
+\def\dosetupdelimitedtext[#1][#2][#3]% #2 = optional level
+ {\ifthirdargument
+ \getparameters[\??ci#1:#2][#3]%
+ \else\ifsecondargument
+ \getparameters[\??ci#1][#2]%
+ \else
+ \getparameters[\??ci][#1]%
+ \fi\fi}
+
+\def\dorepeatdelimitedtext
+ {\relax\ifcase\delimitedtextparameter\c!level\else
+ \dohandledelimitedtext\c!middle % maybe better \dohandleleftdelimitedtext
+ \fi}
+
+\let\dohandlerepeatdelimitedtext\relax
+
+\def\startdelimitedtext[#1]%
+ {\bgroup
+ \pushdelimitedtext{#1}%
+ \doifelse{\delimitedtextparameter\c!method}\s!font
+ {\def\dostopdelimitedtext
+ {\removeunwantedspaces\ignoredelimitedtext\c!right}%
+ \ignoredelimitedtext\c!left\ignorespaces}
+ {\doifelse{\delimitedtextparameter\c!repeat}\v!yes
+ {\let\dohandlerepeatdelimitedtext\dorepeatdelimitedtext}%
+ {\let\dohandlerepeatdelimitedtext\relax}%
+ \doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
+ {\dosingleempty\dostartdelimitedtextpar}\dostartdelimitedtexttxt}}
+
+\def\dostartdelimitedtextpar[#1]%
+ {\let\dostopdelimitedtext\dostopdelimitedtextpar
+ \doifsomething{\delimitedtextparameter\c!spacebefore}
+ {\blank[\delimitedtextparameter\c!spacebefore]}%
+ \delimitedtextparameter\c!before
+ % nicer:
+ % \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
+ % \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
+ % backward compatible:
+ \doifelsenothing{#1}
+ {\endgraf
+ \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
+ \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
+ \let\dodostopdelimitedtextpar\endgraf}
+ {\startnarrower[#1]\let\dodostopdelimitedtextpar\stopnarrower}%
+ % so far
+ % \dochecknextindentation{\??ci\currentdelimitedtext}% AM: not here
+ \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
+ \leftdelimitedtextmark
+ \ignorespaces}
+
+\def\dostopdelimitedtextpar
+ {\removeunwantedspaces
+ \removelastskip
+ \rightdelimitedtextmark
+ \dostopattributes
+ \dodostopdelimitedtextpar
+ \delimitedtextparameter\c!after
+ \doifsomething{\delimitedtextparameter\c!spaceafter}
+ {\blank[\delimitedtextparameter\c!spaceafter]}%
+ \dochecknextindentation{\??ci\currentdelimitedtext}% AM: here
+ \dorechecknextindentation}% AM: This was missing!
+
+\def\dostartdelimitedtexttxt
+ {\let\dostopdelimitedtext\dostopdelimitedtexttxt
+ \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
+ \dohandleleftdelimitedtext\c!left
+ \ignorespaces}
+
+\def\dostopdelimitedtexttxt
+ {\removeunwantedspaces
+ \dohandlerightdelimitedtext\c!right
+ \dostopattributes}
+
+\def\stopdelimitedtext
+ {\dostopdelimitedtext
+ \popdelimitedtext
+ \egroup}
+
+\def\pushdelimitedtext#1%
+ {\globalpushmacro\currentdelimitedtext
+ \def\currentdelimitedtext{#1}%
+ \doglobal\incrementvalue{\??ci\currentdelimitedtext\c!level}}
+
+\def\popdelimitedtext
+ {\doglobal\decrementvalue{\??ci\currentdelimitedtext\c!level}%
+ \globalpopmacro\currentdelimitedtext}
+
+\def\delimitedtext[#1]%
+ {\pushdelimitedtext{#1}%
+ \doifelse{\delimitedtextparameter\c!method}\s!font
+ {\dofontdrivendelimited}
+ {\doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
+ \dodelimitedtextpar\dodelimitedtexttxt}}
+
+% shortcuts
+
+\def\startdelimited{\startdelimitedtext}
+\def\stopdelimited {\stopdelimitedtext} % no let, dynamically assigned
+\def\delimited {\delimitedtext}
+
+\def\leftdelimitedtextmark
+ {\doifsomething{\delimitedtextparameter\c!left}
+ {\setbox\scratchbox\hbox{\delimitedtextparameter\c!left}%
+ \dontleavehmode
+ \doif{\delimitedtextparameter\c!location}\v!margin{\hskip-\wd\scratchbox}%
+ \box\scratchbox}}
+
+\def\rightdelimitedtextmark
+ {\doifsomething{\delimitedtextparameter\c!right}
+ {\hsmash{\delimitedtextparameter\c!right}}}
+
+% \starttext
+% \hyphenatedword{groepsvrijstellingsverordeningen}\par
+% \hyphenatedword{\quote{groepsvrijstellingsverordeningen}}\par
+% \dorecurse{100}{\hskip300pt\hskip\recurselevel pt test \quote{xxx xxxx}.\par}
+% \page \setuppapersize[A5][A4]
+% \quotation {overly beautiful pusillanimous sesquipedalian
+% longwinded} test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test
+% \stoptext
+
+\def\dohandledelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+% \ifdim\lastskip=\delimitedtextsignal
+% \unskip
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi
+ \ifhmode % else funny pagebeaks
+ \penalty\!!tenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+% \penalty\!!tenthousand % else overfull boxes, but that's better than dangling periods
+ \kern\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+\def\dohandleleftdelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else\ifdim\lastskip=\delimitedtextsignal
+ \unskip
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi\fi
+ \strut % new, needed below
+ \ifhmode % else funny pagebeaks
+ \penalty\!!tenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+ \hskip\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+\def\dohandlerightdelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else\ifdim\lastskip=\delimitedtextsignal
+ \unskip
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi\fi
+ \ifhmode % else funny pagebeaks
+ \penalty\!!tenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+ \kern\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+\def\ignoredelimitedtext#1%
+ {\delimitedtextparameter#1}
+
+\def\handledelimitedtext#1%
+ {\dohandledelimitedtext{#1}\relax}
+
+\def\handleleftdelimitedtext#1%
+ {\dohandleleftdelimitedtext{#1}\relax}
+
+\def\handlerightdelimitedtext#1%
+ {\dohandlerightdelimitedtext{#1}\relax}
+
+\unexpanded\def\dodelimitedtextpar
+ {\dohandleleftdelimitedtext\c!left\relax
+ \groupedcommand
+ \donothing
+ {\dohandlerightdelimitedtext\c!right\removelastskip
+ \popdelimitedtext}}
+
+\unexpanded\def\dodelimitedtexttxt
+ {\doifelse{\delimitedtextparameter\c!style}\v!normal
+ \doquoteddelimited\doattributeddelimited}
+
+\def\doquoteddelimited
+ {\dohandleleftdelimitedtext\c!left\relax
+ \groupedcommand
+ \donothing
+ {\dohandlerightdelimitedtext\c!right
+ \removelastskip
+ \popdelimitedtext}}
+
+\def\doattributeddelimited
+ {\groupedcommand
+ {\dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color}
+ {\dostopattributes
+ \popdelimitedtext}}
+
+\def\dofontdrivendelimited
+ {\simplegroupedcommand
+ {\languageparameter{\c!left\currentdelimitedtext}}
+ {\languageparameter{\c!right\currentdelimitedtext}%
+ \popdelimitedtext}}
+
+% testcase for nesting:
+%
+% \quotation{... \quotation{...} ...}
+% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
+% \setupdelimitedtext[quotation][1][left=(,right=)]
+% \setupdelimitedtext[quotation][2][left={[},right={]}]
+% \setupdelimitedtext[quotation][3][left=\{,right=\}]
+% \quotation{... \quotation{...} ...}
+% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
+
+\definedelimitedtext
+ [\v!quotation]
+ [\c!left={\symbol[\c!leftquotation]},
+ \c!right={\symbol[\c!rightquotation]},
+ \c!leftmargin=\v!standard]
+
+\definedelimitedtext
+ [\v!quote][\v!quotation]
+
+\setupdelimitedtext
+ [\v!quote]
+ [\c!location=\v!text,
+ \c!left={\symbol[\c!leftquote]},
+ \c!right={\symbol[\c!rightquote]}]
+
+\definedelimitedtext
+ [\v!blockquote][\v!quotation]
+
+\setupdelimitedtext
+ [\v!blockquote]
+ [\c!left=,
+ \c!right=]
+
+\definedelimitedtext
+ [\v!speech][\v!quotation]
+
+\setupdelimitedtext
+ [\v!speech]
+ [\c!repeat=\v!yes,
+ \c!left={\symbol[\c!leftspeech]},
+ \c!middle={\symbol[\c!middlespeech]},
+ \c!right={\symbol[\c!rightspeech]}]
+
+% how do we call an tight quote
+%
+% \definedelimitedtext
+% [\v!quotation][\v!quotation]
+%
+% \setupdelimitedtext
+% [\v!quotation]
+% [\c!indentnext=\v!no,
+% \c!spacebefore=\v!nowhite]
+
+\def\setupquotation{\setupdelimitedtext[\v!quotation]}
+\def\setupquote {\setupdelimitedtext[\v!quote]}
+
+% seldom used, move from kernel to run time module
+
+\ifx\tfx\undefined \let\tfx\relax \fi
+
+\def\basegrid
+ {\dosingleempty\dobasegrid}
+
+\def\dobasegrid[#1]%
+ {\begingroup
+ \getparameters[\??rt]
+ [\c!x=0,\c!y=0,
+ \c!nx=10,\c!ny=10,
+ \c!dx=.5,\c!dy=.5,
+ \c!xstep=0,\c!ystep=0,
+ \c!unit=\s!cm,
+ \c!scale=1,
+ \c!factor=1,
+ \c!offset=\v!yes,
+ \c!location=\v!left,
+ #1]%
+ \startpositioning
+ \dimen0=\@@rtdx\@@rtunit\relax
+ \dimen0=\@@rtscale\dimen0\relax
+ \dimen0=\@@rtfactor\dimen0\relax
+ \multiply\dimen0 \@@rtnx\relax
+ \dimen2=\@@rtdy\@@rtunit\relax
+ \dimen2=\@@rtscale\dimen2\relax
+ \dimen2=\@@rtfactor\dimen2\relax
+ \multiply\dimen2 \@@rtny\relax
+ \def\horline
+ {\vbox
+ {\hrule
+ \!!width \dimen0
+ \!!height \linewidth
+ \!!depth \!!zeropoint}}%
+ \def\verline%
+ {\vrule
+ \!!width \linewidth
+ \!!height \dimen2
+ \!!depth \!!zeropoint}%
+ \doglobal\newcounter\@@gridc
+ \doglobal\newcounter\@@gridd
+ \doglobal\newcounter\@@gride
+ \def\setlegend##1##2##3%
+ {\gdef\@@gridc{0}%
+ \dimen0=2em\relax
+ \dimen2=##2\@@rtunit\relax
+ \dimen2=\@@rtscale\dimen2\relax
+ \dimen2=\@@rtfactor\dimen2\relax
+ \divide\dimen0 \dimen2\relax
+ \xdef\@@gride{\number\dimen0}%
+ \ifnum\@@gride>50
+ \gdef\@@gride{100}%
+ \else\ifnum\@@gride>10
+ \gdef\@@gride{50}%
+ \else\ifnum\@@gride>5
+ \gdef\@@gride{10}%
+ \else\ifnum\@@gride>1
+ \gdef\@@gride{5}%
+ \else
+ \gdef\@@gride{1}%
+ \fi\fi\fi\fi
+ \gdef\@@gridd{0}%
+ \def\legend
+ {\ifnum\@@gridd=\zerocount
+ \vbox
+ {\increment(\@@gridc,##1)%
+ \hbox to 2em{\hss\@@gridc\hss}}%
+ \global\let\@@gridd=\@@gride
+ \fi
+ \doglobal\decrement\@@gridd
+ \doglobal\increment(\@@gridc,##1)}}%
+ \def\draw##1##2##3##4##5##6##7##8##9%
+ {\setuppositioning
+ [\c!state=##8,
+ \c!xstep=\v!absolute,
+ \c!ystep=\v!absolute,
+ \c!unit=\@@rtunit,
+ \c!scale=\@@rtscale,
+ \c!factor=\@@rtfactor,
+ \c!offset=\@@rtoffset,
+ \c!xoffset=##6,
+ \c!yoffset=##7]%
+ \doifelse{##9}\v!middle
+ {\scratchdimen##3pt\scratchdimen.5\scratchdimen
+ \edef\@@psxx{\withoutpt\the\scratchdimen}%
+ \scratchdimen##4pt\scratchdimen.5\scratchdimen
+ \edef\@@psyy{\withoutpt\the\scratchdimen}%
+ \scratchcounter##2\advance\scratchcounter -1
+ \edef\@@pszz{\the\scratchcounter}}
+ {\edef\@@psxx{0}\edef\@@psyy{0}\edef\@@pszz{##2}}%
+ \position(\@@psxx,\@@psyy){##1}%
+ \setuppositioning
+ [\c!state=##8,
+ \c!xstep=\v!relative,
+ \c!ystep=\v!relative,
+ \c!scale=\@@rtscale,
+ \c!factor=\@@rtfactor,
+ \c!offset=\@@rtoffset,
+ \c!unit=\@@rtunit]%
+ \dorecurse\@@pszz{\position(##3,##4){##5}}}%
+ \draw
+ \verline\@@rtnx\@@rtdx0\verline\!!zeropoint\!!zeropoint\v!start\empty
+ \draw
+ \horline\@@rtny0\@@rtdy\horline\!!zeropoint\!!zeropoint\v!start\empty
+ \tfx
+ \doifnot\@@rtxstep{0}
+ {\setlegend\@@rtxstep\@@rtdx\@@rtx
+ \draw\legend\@@rtnx\@@rtdx0\legend{-1em}{-1.5em}\v!overlay\@@rtlocation}%
+ \doifnot\@@rtystep{0}
+ {\setlegend\@@rtystep\@@rtdy\@@rty
+ \draw\legend\@@rtny0\@@rtdy\legend{-2em}{-.75ex}\v!overlay\@@rtlocation}%
+ \stoppositioning
+ \endgroup}
+
+\let\grid\basegrid
+
+% Dit wordt:
+%
+% \doorverwijzen[naam][instellingen] enz.
+%
+% waarbij bijvoorbeeld publicatie is. Dit levert:
+%
+% \start
+% \stop
+%
+% \beginvan
+% \eindvan
+%
+% \publicatie
+%
+% \volledigelijstmetpublicaties
+%
+% eigenlijk kan ook door... zo worden uitgebreid!
+
+% old, will become obsolete or module, replace by bib module
+
+% \defineenumeration
+% [@publicatie]
+% [\c!location=\v!left,
+% \c!width=\@@pbwidth,\c!hang=,\c!sample=,
+% \c!before=\@@pbbefore,\c!after=\@@pbafter,\c!inbetween=,
+% \c!headstyle=\@@pbheadstyle,\c!style=,
+% \c!headcolor=\@@pbheadcolor,\c!color=,
+% \c!way=\@@pbway,\c!blockway=\@@pbblockway,
+% \c!text=,\c!left=\@@pbleft,\c!right=\@@pbright]
+
+% \def\dosetuppublications[#1]%
+% {\getparameters[\??pb][#1]}
+%
+% \def\setuppublications%
+% {\dosingleargument\dosetuppublications}
+%
+% \def\apa@publicatie
+% {\doifsomething\@@pb@naam {\@@pb@naam,\space}%
+% \doifsomething\@@pb@titel {{\sl\@@pb@titel}.\space}%
+% \doifsomething\@@pb@jaar {(\@@pb@jaar).\space}%
+% \doifsomething\@@pb@plaats {\@@pb@plaats\doifelsenothing\@@pb@uitgever{.}{:\space}}%
+% \doifsomething\@@pb@uitgever{\@@pb@uitgever.}}
+%
+% \def\normaal@publicatie
+% {\@@pb@naam, \@@pb@titel, \@@pb@jaar, \@@pb@pagina, \@@pb@plaats, \@@pb@uitgever.}
+%
+% \def\complexstartpublicatie[#1]#2\stoppublicatie
+% {\bgroup
+% \def\dosetpublicatie
+% {\processcommalist
+% [naam,titel,jaar,plaats,pagina,uitgever]
+% \setpublicatie
+% \ignorespaces}%
+% \def\setpublicatie##1%
+% {\letvalue{\??pb @##1}\empty
+% \setvalue{##1}####1{\setvalue{\??pb @##1}{####1}\ignorespaces}}%
+% \def\getpublicatie%
+% {\doifsomething\@@pbalternative{\getvalue{\@@pbalternative @publicatie}}}%
+% \doifelse\@@pbnumbering\v!yes
+% {\@publicatie[#1]\dosetpublicatie#2\getpublicatie\par}%
+% {\@@pbbefore
+% \dosetpublicatie\ignorespaces#2\getpublicatie
+% \@@pbafter}%
+% \egroup}
+%
+% \definecomplexorsimpleempty\startpublicatie
+%
+% \def\publication#1[#2]%
+% {\@@pbleft\in{#1}[#2]\@@pbright}
+%
+% \setuppublications
+% [\c!numbering=\v!yes,
+% \c!alternative=\c!apa,
+% \c!width=2em,
+% \c!hang=,
+% \c!sample=,
+% \c!before=,
+% \c!after=,
+% \c!inbetween=,
+% \c!headstyle=,
+% \c!headcolor=,
+% \c!style=,
+% \c!color=,
+% \c!blockway=\v!by\v!text,
+% \c!way=\v!by\v!text,
+% \c!text=,
+% \c!left={[},
+% \c!right={]}]
+
+% only used at pragma, move from kernel to run time module
+
+\def\referraldate
+ {\currentdate[\v!referral]}
+
+\def\doreferral[#1]%
+ {\noheaderandfooterlines
+ \bgroup
+ \getparameters
+ [\??km]
+ [\c!bet=\unknown,\c!dat=\unknown,\c!ken=\unknown,
+ \c!from=,\c!to=,\c!ref=,#1]%
+ % moet anders, hoort niet in 01b
+ \assigntranslation[\s!nl=referentie,\s!en=reference,\s!de=Referenz,\s!sp=referencia]\to\@@@kmref
+ \assigntranslation[\s!nl=van,\s!en=from,\s!de=Von,\s!sp=de]\to\@@@kmvan
+ \assigntranslation[\s!nl=aan,\s!en=to,\s!de=An,\s!sp=a]\to\@@@kmaan
+ \assigntranslation[\s!nl=betreft,\s!en=concerns,\s!de=Betreff,\s!sp=]\to\@@@kmbet
+ \assigntranslation[\s!nl=datum,\s!en=date,\s!de=Datum,\s!sp=fecha]\to\@@@kmdat
+ \assigntranslation[\s!nl=kenmerk,\s!en=mark,\s!de=Kennzeichen,\s!sp=]\to\@@@kmken
+ %
+ \definetabulate[\s!dummy][|l|p|]
+ \startdummy
+ \NC\@@@kmbet\EQ\@@kmbet\NC\NR
+ \NC\@@@kmdat\EQ\@@kmdat\NC\NR
+ \NC\@@@kmken\EQ\expanded{\smallcapped{\@@kmken}}\NC\NR
+ \doifsomething{\@@kmfrom\@@kmto}{\NC\NC\NC\NR}%
+ \doifsomething \@@kmfrom {\NC\@@@kmvan\EQ\@@kmfrom\NC\NR}%
+ \doifsomething \@@kmto {\NC\@@@kmaan\EQ\@@kmto\NC\NR}%
+ \doifsomething \@@kmref {\NC\NC\NC\NR\NC\@@@kmref\EQ\@@kmref\NC\NR}%
+ \stopdummy
+ \egroup}
+
+\def\referral
+ {\dosingleargument\doreferral}
+
+% FUZZY OLD STUFF: will be removed when not used in some manual;
+% rows instead of columns, i'd forgotten that this code exist
+%
+% \definesystemvariable{ri}
+%
+% \def\setuprows
+% {\dodoubleargument\getparameters[\??ri]}
+%
+% \definecomplexorsimpleempty\startrows
+%
+% \def\complexstartrows[#1]%
+% {\bgroup
+% \setuprows[#1]%
+% \let\do@@ribottom\relax
+% \def\row
+% {\do@@ribottom
+% \egroup
+% \dimen0\vsize
+% \divide\dimen0 \@@rin
+% \advance\dimen0 -\lineskip
+% \vbox to \dimen0
+% \bgroup
+% \@@ritop
+% \let\do@@ribottom\@@ribottom
+% \ignorespaces}%
+% \bgroup
+% \row}
+%
+% \def\stoprows
+% {\do@@ribottom
+% \egroup
+% \egroup}
+%
+% \setuprows
+% [\c!n=2,
+% \c!top=,
+% \c!bottom=\vfill]
+
+% THIS WAS MAIN-003.TEX
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+\definetabulate
+ [\v!legend]
+ [|emj1|i1|mR|]
+
+\setuptabulate
+ [\v!legend]
+ [\c!unit=.75em,\c!inner=\setquicktabulate\leg,EQ={=}]
+
+\definetabulate
+ [\v!legend][\v!two]
+ [|emj1|emk1|i1|mR|]
+
+\definetabulate
+ [\v!fact]
+ [|R|ecmj1|i1mR|]
+
+\setuptabulate
+ [\v!fact]
+ [\c!unit=.75em,\c!inner=\setquicktabulate\fact,EQ={=}]
+
+\unexpanded\def\xbox
+ {\bgroup\aftergroup\egroup\hbox\bgroup\tx\let\next=}
+
+\unexpanded\def\xxbox
+ {\bgroup\aftergroup\egroup\hbox\bgroup\txx\let\next=}
+
+% \def\mrm#1%
+% {$\rm#1$}
+
+%D \macros
+%D {definepairedbox, setuppairedbox, placepairedbox}
+%D
+%D Paired boxes, formally called legends, but from now on a
+%D legend is just an instance, are primarily meant for
+%D typesetting some text alongside an illustration. Although
+%D there is quite some variation possible, the functionality is
+%D kept simple, if only because in most cases such pairs are
+%D typeset sober.
+%D
+%D The location specification accepts a pair, where the first
+%D keyword specifies the arrangement, and the second one the
+%D alignment. The first key of the location pair is one of
+%D \type {left}, \type {right}, \type {top} or \type {bottom},
+%D while the second key can also be \type {middle}.
+%D
+%D The first box is just collected in an horizontal box, but
+%D the second one is a vertical box that gets passed the
+%D bodyfont and alignment settings.
+
+%D Today we would implement this using layers .... but for the
+%D moment we keep it this way.
+
+% \startbuffer[test]
+% \test left \test left,top \test left,bottom \test left,middle
+% \test right \test right,top \test right,bottom \test right,middle
+% \test top \test top,left \test top,right \test top,middle
+% \test bottom \test bottom,left \test bottom,right \test bottom,middle
+% \stopbuffer
+%
+% \def\showtest#1%
+% {\pagina
+% \typebuffer[demo]
+% \def\test##1
+% {\startlinecorrection[blank]
+% \getbuffer[demo]%
+% \ruledhbox\placelegend
+% [bodyfont=6pt,location={##1}]
+% {\framed[width=.25\textwidth]{\tttf##1}}
+% {#1}
+% \stoplinecorrection}
+% \getbuffer[test]}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=\hsize,maxwidth=\makeupwidth,
+% height=\vsize,maxheight=\makeupheight]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate the default settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=\textwidth,
+% maxwidth=\textwidth]
+% \stopbuffer
+%
+% \showtest{\input tufte }
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=.65\textwidth]
+% \stopbuffer
+%
+% \showtest{\input knuth }
+%
+% \startbuffer[demo]
+% \setuplegend
+% [height=2cm]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate some other settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=.65\textwidth,
+% height=2cm]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate some other settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [n=2,align=right,width=.5\textwidth]
+% \stopbuffer
+%
+% \showtest{\input zapf }
+
+%D \macros
+%D {setuplegend, placelegend}
+%D
+%D It makes sense to typeset a legend to a figure in \TEX\
+%D and not in a drawing package. The macro \type {\placelegend}
+%D combines a figure (or something else) and its legend. This
+%D command is just a paired box.
+%D
+%D The legend is placed according to \type {location}, being
+%D \type {bottom} or \type {right}. The macro macro is used as
+%D follows.
+%D
+%D \starttyping
+%D \placefigure
+%D {whow}
+%D {\placelegend
+%D {\externalfigure[cow]}
+%D {\starttabulation
+%D \NC 1 \NC head \NC \NR
+%D \NC 2 \NC legs \NC \NR
+%D \NC 3 \NC tail \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend
+%D {\externalfigure[cow]}
+%D {\starttabulation[|l|l|l|l|]
+%D \NC 1 \NC head \NC 3 \NC tail \NC \NR
+%D \NC 2 \NC legs \NC \NC \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {\starttabulation
+%D \NC 1 \NC head \NC \NR
+%D \NC 2 \NC legs \NC \NR
+%D \NC 3 \NC tail \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {head \par legs \par tail}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {\startitemize[packed]
+%D \item head \item legs \item tail \item belly \item horns
+%D \stopitemize}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2,width=.8\hsize]
+%D {\externalfigure[cow]}
+%D {\startitemize[packed]
+%D \item head \item legs \item tail \item belly \item horns
+%D \stopitemize}}
+%D \stoptyping
+
+\newbox\firstpairedbox
+\newbox\secondpairedbox
+
+\def\definepairedbox
+ {\dodoubleempty\dodefinepairedbox}
+
+\def\dodefinepairedbox[#1][#2]%
+ {\getparameters
+ [\??ld#1]
+ [\c!n=1,
+ \c!distance=\bodyfontsize,
+ \c!before=,
+ \c!after=,
+ \c!color=,
+ \c!style=,
+ \c!inbetween={\blank[\v!medium]},
+ \c!width=\hsize,
+ \c!height=\vsize,
+ \c!maxwidth=\textwidth, % \makeupwidth,
+ \c!maxheight=\textheight, % \makeupheight,
+ \c!bodyfont=,
+ \c!align=,
+ \c!location=\v!bottom,
+ #2]%
+ \setvalue{\e!setup#1\e!endsetup}{\setuppairedbox[#1]}%
+ \setvalue{\e!place#1}{\placepairedbox[#1]}}
+
+\def\setuppairedbox
+ {\dodoubleempty\dosetuppairedbox}
+
+\def\dosetuppairedbox[#1]%
+ {\getparameters[\??ld#1]}
+
+\def\placepairedbox
+ {\bgroup\dodoubleempty\doplacepairedbox}
+
+\def\doplacepairedbox[#1][#2]% watch the hsize/vsize tricks
+ {\setuppairedbox[#1][#2]% % and don't change them
+ \copyparameters % brrr
+ [\??ld][\??ld#1]
+ [\c!n,\c!distance,\c!inbetween,\c!before,\c!after,
+ \c!width,\c!height,\c!maxwidth,\c!maxheight,
+ \c!color,\c!style,\c!bodyfont,\c!align,\c!location]%
+ \@@ldbefore\bgroup
+ \global\setsystemmode{pairedbox}%
+ \beforefirstpairedbox
+ \dowithnextbox
+ {\betweenbothpairedboxes
+ \dowithnextbox
+ {\afterbothpairedboxes
+ \egroup\@@ldafter
+ \egroup}
+ \vbox\bgroup
+ \insidesecondpairedbox
+ \let\next=}
+ \hbox}
+
+\def\beforefirstpairedbox
+ {\chardef\pairedlocationa1 % left
+ \chardef\pairedlocationb4 % middle
+ \getfromcommacommand[\@@ldlocation][1]%
+ \processaction
+ [\commalistelement]
+ [ \v!left=>\chardef\pairedlocationa0,
+ \v!right=>\chardef\pairedlocationa1,
+ \v!top=>\chardef\pairedlocationa2,
+ \v!bottom=>\chardef\pairedlocationa3]%
+ \getfromcommacommand[\@@ldlocation][2]%
+ \processaction
+ [\commalistelement]
+ [ \v!left=>\chardef\pairedlocationb0,
+ \v!right=>\chardef\pairedlocationb1,
+ \v!high=>\chardef\pairedlocationb2,
+ \v!top=>\chardef\pairedlocationb2,
+ \v!low=>\chardef\pairedlocationb3,
+ \v!bottom=>\chardef\pairedlocationb3,
+ \v!middle=>\chardef\pairedlocationb4]}
+
+\def\betweenbothpairedboxes
+ {\switchtobodyfont[\@@ldbodyfont]% split under same regime
+ \setbox\firstpairedbox\flushnextbox
+ \ifnum\pairedlocationa<2
+ \hsize\wd\firstpairedbox % trick
+ \hsize\@@ldwidth
+ \scratchdimen\wd\firstpairedbox
+ \advance\scratchdimen \@@lddistance
+ \bgroup\advance\scratchdimen \hsize
+ \ifdim\scratchdimen>\@@ldmaxwidth\relax
+ \egroup
+ \hsize\@@ldmaxwidth
+ \advance\hsize -\scratchdimen
+ \else
+ \egroup
+ \fi
+ \else
+ \hsize\wd\firstpairedbox
+ \hsize\@@ldwidth % can be \hsize
+ \ifdim\hsize>\@@ldmaxwidth\relax \hsize\@@ldmaxwidth \fi % can be \hsize
+ \fi
+ \ifnum\@@ldn>\plusone
+ \setrigidcolumnhsize\hsize\@@lddistance\@@ldn
+ \fi}
+
+\def\afterbothpairedboxes
+ {\setbox\secondpairedbox\vbox
+ {% \localstartcolor[\@@ldcolor]% does not work yet
+ \ifnum\@@ldn>1
+ \rigidcolumnbalance\nextbox
+ \else
+ \flushnextbox
+ \fi
+ }% \localstopcolor}%
+ \ifnum\pairedlocationa<2\hbox\else\vbox\fi\bgroup % hide vsize
+ \forgetall
+ \ifnum\pairedlocationa<2
+ \scratchdimen\maxoftwoboxdimens\ht\firstpairedbox\secondpairedbox
+ \vsize\scratchdimen
+ \ifdim\scratchdimen<\@@ldheight\relax % can be \vsize
+ \scratchdimen\@@ldheight
+ \fi
+ \ifdim\scratchdimen>\@@ldmaxheight\relax
+ \scratchdimen\@@ldmaxheight
+ \fi
+ \valignpairedbox\firstpairedbox \scratchdimen
+ \valignpairedbox\secondpairedbox\scratchdimen
+ \else
+ \scratchdimen\maxoftwoboxdimens\wd\firstpairedbox\secondpairedbox
+ \halignpairedbox\firstpairedbox \scratchdimen
+ \halignpairedbox\secondpairedbox\scratchdimen
+ \scratchdimen\ht\secondpairedbox
+ \vsize\scratchdimen
+ \ifdim\ht\secondpairedbox<\@@ldheight\relax % can be \vsize
+ \scratchdimen\@@ldheight\relax % \relax needed
+ \fi
+ \ifdim\scratchdimen>\@@ldmaxheight\relax % todo: totale hoogte
+ \scratchdimen\@@ldmaxheight\relax % \relax needed
+ \fi
+ \ifdim\scratchdimen>\ht\secondpairedbox
+ \setbox\secondpairedbox\vbox to \scratchdimen
+ {\ifnum\pairedlocationa=3 \vss\fi %
+ \box\secondpairedbox
+ \ifnum\pairedlocationa=2 \vss\fi}% \kern\zeropoint
+ \fi
+ \fi
+ \ifcase\pairedlocationa
+ \box\secondpairedbox\hskip\@@lddistance\box\firstpairedbox \or
+ \box\firstpairedbox \hskip\@@lddistance\box\secondpairedbox\or
+ \box\secondpairedbox\endgraf \nointerlineskip \@@ldinbetween \box\firstpairedbox \or
+ \box\firstpairedbox \endgraf \nointerlineskip \@@ldinbetween \box\secondpairedbox\else
+ \fi
+ \egroup}
+
+\def\insidesecondpairedbox
+ {\forgetall
+ \setupalign[\@@ldalign]%
+ \tolerantTABLEbreaktrue % hm.
+ \blank[\v!disable]%
+ \everypar{\begstrut}}
+
+\def\maxoftwoboxdimens#1#2#3%
+ {#1\ifdim#1#2>#1#3 #2\else#3\fi}
+
+\def\valignpairedbox#1#2%
+ {\setbox#1\vbox to #2
+ {\ifcase\pairedlocationb\or\or\or\vss\or\vss\fi
+ \box#1\relax
+ \ifcase\pairedlocationb\or\or\vss\or\or\vss\fi}}
+
+\def\halignpairedbox#1#2%
+ {\setbox#1\hbox to #2
+ {\ifcase\pairedlocationb\or\hss\or\or\or\hss\fi
+ \box#1\relax
+ \ifcase\pairedlocationb\hss\or\or\or\or\hss\fi}}
+
+\definepairedbox[\v!legend]
+
+%D Goody:
+
+\appendtoks
+ \global\resetsystemmode{combination}%
+ \global\resetsystemmode{pairedbox}%
+\to \everyinsidefloat
+
+% todo: \startcombination \startcomb \stopcomb ...
+
+\newcount\horcombination % counter
+\newcount\totcombination
+
+\def\definecombination
+ {\dodoubleempty\dodefinecombination}
+
+\def\dodefinecombination[#1][#2]%
+ {\copyparameters
+ [\??co#1][\??co]
+ [\c!width,\c!height,\c!distance,\c!location,%
+ \c!before,\c!inbetween,\c!after,\c!align,%
+ \c!style,\c!color]%
+ \getparameters
+ [\??co#1][#2]}
+
+\def\setupcombinations
+ {\dodoubleempty\dosetupcombinations}
+
+\def\dosetupcombinations[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??co#1][#2]%
+ \else
+ \getparameters[\??co][#1]%
+ \fi}
+
+\def\combinationparameter#1%
+ {\csname\??co\currentcombination#1\endcsname}%
+
+\def\startcombination
+ {\bgroup % so we can grab a group
+ \dodoubleempty\dostartcombination}
+
+% \startcombination {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[2*1] {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[1*2] {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[2] {alpha} {a} {beta} {b} \stopcombination
+
+\def\dostartcombination[#1][#2]%
+ {\global\setsystemmode{combination}%
+ \doifnothing{#1}\firstargumentfalse % to be sure (when called in macros)
+ \doifnothing{#2}\secondargumentfalse % to be sure (when called in macros)
+ \ifsecondargument
+ \def\currentcombination{#1}%
+ \edef\currentcombinationspec{#2*1*}%
+ \else % better : \doifcombinationelse ... \??co#1\c!location
+ \doifinstringelse{*}{#1}
+ {\let\currentcombination\empty
+ \edef\currentcombinationspec{#1*1*}}
+ {\doifnumberelse{#1}
+ {\let\currentcombination\empty
+ \edef\currentcombinationspec{#1*1*}}
+ {\def\currentcombination{#1}%
+ \edef\currentcombinationspec{2*1*}}}%
+ \fi
+ \forgetall
+ \doifelse{\combinationparameter\c!height}\v!fit
+ \vbox {\vbox to \combinationparameter\c!height}%
+ \bgroup
+ \expanded{\dodostartcombination[\currentcombinationspec]}}
+
+\long\def\dodostartcombination[#1*#2*#3]%
+ {\setuphorizontaldivision
+ [\c!n=\v!fit,\c!distance=\combinationparameter\c!distance]%
+ \global\horcombination#1%
+ \global\totcombination#2%
+ \global\setbox\combinationstack\emptybox
+ \xdef\maxhorcombination{\the\horcombination}%
+ \multiply\totcombination\horcombination
+ \tabskip\zeropoint
+ \doifelse{\combinationparameter\c!width}\v!fit
+ {\halign}{\halign to \combinationparameter\c!width}%
+ \bgroup&%
+ %\hfil##\hfil% now : location={left,top}
+ \expanded{\doifnotinset{\v!left}{\combinationparameter\c!location}}\hfil
+ ##%
+ \expanded{\doifnotinset{\v!right}{\combinationparameter\c!location}}\hfil
+ &\tabskip\zeropoint \!!plus 1fill##\cr
+ \docombination}
+
+\def\docombination % we want to add struts but still ignore an empty box
+ {\dowithnextbox
+ {\setbox0\flushnextbox
+ \dowithnextbox
+ {\setbox2\flushnextbox
+ \dodocombination}%
+ \vtop\bgroup
+ \def\next
+ {\futurelet\nexttoken\nextnext}%
+ \def\nextnext
+ {\ifx\nexttoken\egroup \else % the next box is empty
+ \hsize\wd0
+ \setupalign[\combinationparameter\c!align]%
+ \dostartattributes{\??co\currentcombination}\c!style\c!color\empty
+ \bgroup
+ \aftergroup\endstrut
+ \aftergroup\dostopattributes
+ \aftergroup\egroup
+ \begstrut
+ \fi}%
+ \afterassignment\next\let\nexttoken=}
+ \hbox}
+
+% stupid version, does not align top stuff when captions,
+% keep as example
+%
+% \def\dodocombination
+% {\vbox
+% {\forgetall % \setupwhitespace[\v!none]%
+% \let\next\vbox
+% \ExpandFirstAfter\processallactionsinset
+% [\combinationparameter\c!location]
+% [ \v!top=>\let\next\tbox,
+% \v!middle=>\let\next\halfwaybox]%
+% \next{\copy0}%
+% \ifdim\ht2>\zeropoint % beter dan \wd2, nu \strut mogelijk
+% \combinationparameter\c!inbetween
+% %\vtop % wrong code
+% % {\nointerlineskip % recently added
+% % \hsize\wd0
+% % \setupalign[\combinationparameter\c!align]% % \raggedcenter
+% % \begstrut\unhbox2\endstrut}%
+% \box2
+% \fi}%
+% \ifnum\totcombination>\plusone
+% \global\advance\totcombination\minusone
+% \global\advance\horcombination\minusone
+% \ifnum\horcombination=\zerocount
+% \def\next
+% {\cr\noalign
+% {\forgetall % \setupwhitespace[\v!geen]% no
+% \nointerlineskip
+% \combinationparameter\c!before
+% \combinationparameter\c!after
+% \vss
+% \nointerlineskip}%
+% \global\horcombination\maxhorcombination\relax
+% \docombination}%
+% \else
+% \def\next
+% {&&&\hskip\combinationparameter\c!distance&\docombination}%
+% \fi
+% \else
+% \def\next
+% {\cr\egroup}%
+% \fi
+% \next}
+
+% \def\dodocombination
+% {\vbox
+% {\forgetall % \setupwhitespace[\v!none]%
+% \let\next\vbox
+% \ExpandFirstAfter\processallactionsinset
+% [\combinationparameter\c!plaats]
+% [ \v!top=>\let\next\tbox,
+% \v!middle=>\let\next\halfwaybox]%
+% \next{\copy0}%
+% % we need to save the caption for a next alignment line
+% \saveoncombinationstack2}%
+% \ifnum\totcombination>\plusone
+% \global\advance\totcombination\minusone
+% \global\advance\horcombination\minusone
+% \ifnum\horcombination=\zerocount
+% \def\next
+% {\cr
+% \flushcombinationstack
+% \noalign
+% {\forgetall % \setupwhitespace[\v!none]% no
+% \global\setbox\combinationstack\emptybox
+% \nointerlineskip
+% \combinationparameter\c!after
+% \combinationparameter\c!before
+% \vss
+% \nointerlineskip}%
+% \global\horcombination\maxhorcombination\relax
+% \docombination}%
+% \else
+% \def\next
+% {&&&\hskip\combinationparameter\c!distance&\docombination}%
+% \fi
+% \else
+% \def\next
+% {\cr
+% \flushcombinationstack
+% \egroup}%
+% \fi
+% \next}
+
+\def\depthonlybox
+ {\dowithnextbox{\vtop{\hsize\wd\nextbox\kern\zeropoint\box\nextbox}}\vbox}
+
+% \def\boxwithstrutheight
+% {\dowithnextbox
+% {\scratchdimen\strutheight
+% \advance\scratchdimen-\nextboxht
+% \hbox{\raise\scratchdimen\box\nextbox}}%
+% \vbox}
+
+\def\dodocombination
+ {\vbox
+ {\forgetall % \setupwhitespace[\v!none]%
+ \let\next\vbox
+ \expanded{\processallactionsinset[\combinationparameter\c!location]}
+ [ \v!top=>\let\next\depthonlybox, % \tbox,
+ \v!middle=>\let\next\halfwaybox]%
+ \next{\copy0}%
+ % we need to save the caption for a next alignment line
+ \saveoncombinationstack2}%
+ \ifnum\totcombination>\plusone
+ \global\advance\totcombination\minusone
+ \global\advance\horcombination\minusone
+ \ifnum\horcombination=\zerocount
+ \def\next
+ {\cr
+ \flushcombinationstack
+ \noalign
+ {\forgetall % \setupwhitespace[\v!none]% no
+ \global\setbox\combinationstack\emptybox
+ \nointerlineskip
+ \combinationparameter\c!after
+ \combinationparameter\c!before
+ \vss
+ \nointerlineskip}%
+ \global\horcombination\maxhorcombination\relax
+ \docombination}%
+ \else
+ \def\next
+ {&&&\hskip\combinationparameter\c!distance&\docombination}%
+ \fi
+ \else
+ \def\next
+ {\cr
+ \flushcombinationstack
+ \egroup}%
+ \fi
+ \next}
+
+% formally ok:
+%
+% \def\stopcombination
+% {\egroup
+% \egroup}
+%
+% more robust:
+%
+% \def\stopcombination
+% {{}{}{}{}{}{}{}{}% catches (at most 4) missing entries
+% \egroup
+% \egroup}
+%
+% even better:
+
+\def\stopcombination
+ {{\scratchtoks{{}{}{}}\dorecurse\totcombination{\appendtoks{}{}{}{}\to\scratchtoks}\expandafter}\the\scratchtoks
+ \egroup
+ \egroup}
+
+\newbox\combinationstack
+
+\def\saveoncombinationstack#1%
+ {\global\setbox\combinationstack\hbox
+ {\hbox{\box#1}\unhbox\combinationstack}}
+
+\def\flushcombinationstack
+ {\noalign
+ {\ifdim\ht\combinationstack>\zeropoint
+\nointerlineskip % nieuw
+ \combinationparameter\c!inbetween
+ \global\horcombination\maxhorcombination
+ \globallet\doflushcombinationstack\dodoflushcombinationstack
+ \else
+ \global\setbox\combinationstack\emptybox
+ \globallet\doflushcombinationstack\donothing
+ \fi}%
+ \doflushcombinationstack\crcr}
+
+\gdef\dodoflushcombinationstack
+ {\global\setbox\combinationstack\hbox
+ {\unhbox\combinationstack
+ \global\setbox1\lastbox}%
+ \box1% \ruledhbox{\box1}%
+ \global\advance\horcombination\minusone\relax
+ \ifnum\horcombination>\zerocount
+ \def\next{&&&&\doflushcombinationstack}%
+ \else
+ \global\setbox\combinationstack\emptybox
+ %\let\next\relax
+ \@EA\gobbleoneargument
+ \fi
+ \next}
+
+\setupcombinations
+ [\c!width=\v!fit,
+ \c!height=\v!fit,
+ \c!distance=1em,
+ \c!location=\v!bottom, % can be something {top,left}
+ \c!before=\blank,
+ \c!inbetween={\blank[\v!medium]},
+ \c!style=,
+ \c!color=,
+ \c!after=,
+ \c!align=\v!middle]
+
+%D \macros
+%D {startfloatcombination}
+%D
+%D \setupexternalfigures[directory={../sample}]
+%D \startbuffer
+%D \placefigure
+%D [left,none]
+%D {}
+%D {\startfloatcombination[2*2]
+%D \placefigure{alpha}{\externalfigure[cow.pdf][width=1cm]}
+%D \placefigure{beta} {\externalfigure[cow.pdf][width=2cm]}
+%D \placefigure{gamma}{\externalfigure[cow.pdf][width=3cm]}
+%D \placefigure{delta}{\externalfigure[cow.pdf][width=4cm]}
+%D \stopfloatcombination}
+%D
+%D \input tufte
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+\def\startfloatcombination
+ {\dodoubleempty\dostartfloatcombination}
+
+\def\dostartfloatcombination[#1][#2]%
+ {\vbox\bgroup
+ %\insidecolumnstrue % trick, forces no centering, todo: proper switch/feature
+ \chardef\postcenterfloatmethod\zerocount
+ \forcelocalfloats
+ \def\stopfloatcombination
+ {\scratchtoks\emptytoks
+ \dorecurse\noflocalfloats
+ {\appendetoks{\noexpand\getlocalfloat{\recurselevel}}{}\to\scratchtoks}%
+ \expanded{\startcombination[#1]\the\scratchtoks}\stopcombination
+ \resetlocalfloats
+ \egroup}}
+
+\def\placerelativetoeachother#1#2%
+ {\bgroup
+ \dowithnextbox
+ {\bgroup
+ \setbox0\box\nextbox
+ \dowithnextbox
+ {\setbox2\box\nextbox
+ #1{#2#########2\cr\box0\cr\box2\cr}
+ \egroup
+ \egroup}
+ \hbox}
+ \hbox}
+
+\def\placeontopofeachother{\placerelativetoeachother\halign\hss}
+\def\placesidebyside {\placerelativetoeachother\valign\vss}
+
+% this will be replaced or go away, never used
+
+\def\douseexternalfiles[#1][#2]%
+ {\getparameters
+ [\??fi#1]
+ [\c!file=,
+ \c!bodyfont=,
+ \c!option=,
+ #2]}
+
+\def\useexternalfiles
+ {\dodoubleargument\douseexternalfiles}
+
+\def\dostelexternefilesin[#1][#2]%
+ {\doifundefinedelse{\??fi#1\c!file}
+ {\useexternalfiles[#1][#2]}
+ {\getparameters[\??fi#1][#2]}}
+
+\def\stelexternefilesin
+ {\dodoubleargument\dostelexternefilesin}
+
+\def\verwerkexternefile#1#2#3%
+ {\bgroup
+ \getparameters[\??fi#1][\c!file=,#3]%
+ \doinputonce{\getvalue{\??fi#1\c!file}}%
+ \ExpandFirstAfter\switchtobodyfont[\getvalue{\??fi#1\c!bodyfont}]%
+ \readsysfile{#2} % beter: loc of fix gebied
+ \donothing
+ {\showmessage\m!systems{41}{#2,#1}}%
+ \egroup}
+
+\def\douseexternalfile[#1][#2][#3][#4]%
+ {\stelexternefilesin[#1][]%
+ \doinputonce{\getvalue{\??fi#1\c!file}}%
+ \doifelsenothing{#2}
+ {\setvalue{#3}{\verwerkexternefile{#1}{#3}{#4}}}
+ {\setvalue{#2}{\verwerkexternefile{#1}{#3}{#4}}}}
+
+\def\useexternalfile
+ {\doquadrupleargument\douseexternalfile}
+
+\useexternalfiles
+ [pictex]
+ [\c!bodyfont=\v!small,
+ \c!file=pictex]
+
+\useexternalfiles
+ [table]
+ [\c!file=table]
+
+%D A couple of examples, demonstrating how the depth is
+%D taken care of:
+%D
+%D \startbuffer
+%D test\rotate[frame=on, rotation=0] {gans}%
+%D test\rotate[frame=on, rotation=90] {gans}%
+%D test\rotate[frame=on, rotation=180]{gans}%
+%D test\rotate[frame=on, rotation=270]{gans}%
+%D test
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+% When we rotate over arbitrary angles, we need to relocate the
+% resulting box because rotation brings that box onto the negative
+% axis. The calculations (mostly sin and cosine) need to be tuned for
+% the way a box is packages (i.e. the refence point). A typical example
+% of drawing, scribbling, and going back to the days of school math.
+%
+% We do a bit more calculations than needed, simply because that way
+% it's easier to debug the code.
+
+\def\dododorotatenextbox
+ {\setbox\nextbox\vbox to \@@layerysiz
+ {\vfill
+ \hbox to \@@layerxsiz
+ {\dostartrotation\@@rorotation
+ \nextboxwd\zeropoint
+ \nextboxht\zeropoint
+ \flushnextbox
+ \dostoprotation
+ \hfill}%
+ \kern\@@layerypos}%
+ \setbox\nextbox\hbox
+ {\kern\@@layerxpos
+ \kern\@@layerxoff
+ \lower\@@layeryoff\flushnextbox}}
+
+\def\dodorotatenextbox#1#2% quite some trial and error -)
+ {\dontshowcomposition
+ \dontcomplain
+ \ifnum#2=\plusfour
+ % new, location=middle
+ \!!widthb \nextboxwd
+ \!!heightb\nextboxht
+ \!!depthb \nextboxdp
+ \setbox\nextbox\vbox{\vskip.5\nextboxht\hskip-.5\nextboxwd\flushnextbox}%
+ \smashbox\nextbox
+ \fi
+ \!!widtha \nextboxwd
+ \!!heighta\nextboxht
+ \!!deptha \nextboxdp
+ \!!doneafalse
+ \!!donebfalse
+ \ifcase#2\or
+ % 1: fit
+ \or
+ % 2: depth, not fit
+ \!!doneatrue
+ \!!donebtrue
+ \or
+ % 3: depth, fit
+ \!!donebtrue
+ \fi
+ \setbox\nextbox\vbox{\hbox{\raise\nextboxdp\flushnextbox}}%
+ \!!dimena \nextboxht
+ \setcalculatedcos\cos\@@rorotation
+ \setcalculatedsin\sin\@@rorotation
+ \@@layerxpos\zeropoint
+ \@@layerypos\zeropoint
+ \@@layerxoff\zeropoint
+ \@@layeryoff\zeropoint
+ \ifdim\sin\points>\zeropoint
+ \ifdim\cos\points>\zeropoint
+ \@@layerxsiz \cos\!!widtha
+ \@@layerysiz \sin\!!widtha
+ \advance\@@layerxsiz \sin\!!dimena
+ \advance\@@layerysiz \cos\!!dimena
+ \@@layerypos \cos\!!dimena
+ \if!!donea
+ \@@layerxoff \negated\sin\!!dimena
+ \advance\@@layerxoff \sin\!!deptha
+ \fi
+ \if!!doneb
+ \@@layeryoff \cos\!!deptha
+ \fi
+ \dododorotatenextbox
+ \else
+ \@@layerxsiz \negated\cos\!!widtha
+ \@@layerysiz \sin\!!widtha
+ \advance\@@layerxsiz \sin\!!dimena
+ \advance\@@layerysiz \negated\cos\!!dimena
+ \@@layerxpos \negated\cos\!!widtha
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \sin\!!deptha
+ \fi
+ \if!!doneb
+ \@@layeryoff \negated\cos\!!heighta
+ \fi
+ \dododorotatenextbox
+ \wd\nextbox\if!!donea\sin\!!deptha\else\@@layerxsiz\fi
+ \fi
+ \else
+ \ifdim\cos\points<\zeropoint
+ \@@layerxsiz \negated\cos\!!widtha
+ \@@layerysiz \negated\sin\!!widtha
+ \advance\@@layerxsiz \negated\sin\!!dimena
+ \advance\@@layerysiz \negated\cos\!!dimena
+ \@@layerxpos \@@layerxsiz
+ \@@layerypos \negated\sin\!!widtha
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \negated\sin\!!heighta
+ \fi
+ \if!!doneb
+ \@@layeryoff \@@layerysiz
+ \advance\@@layeryoff \cos\!!deptha
+ \fi
+ \dododorotatenextbox
+ \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
+ \else
+ \@@layerxsiz \cos\!!widtha
+ \@@layerysiz \negated\sin\!!widtha
+ \advance\@@layerxsiz \negated\sin\!!dimena
+ \advance\@@layerysiz \cos\!!dimena
+ \ifdim\sin\points=\zeropoint
+ \@@layerxpos \zeropoint
+ \@@layerxoff \zeropoint
+ \@@layerypos \@@layerysiz
+ \if!!doneb
+ \@@layeryoff \!!deptha
+ \fi
+ \else
+ \@@layerypos \@@layerysiz
+ \@@layerxpos \negated\sin\!!dimena
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \negated\sin\!!heighta
+ \fi
+ \if!!doneb
+ \@@layeryoff \negated\sin\!!deptha
+ \fi
+ \fi
+ \dododorotatenextbox
+ \ifdim\sin\points=\zeropoint
+ \else
+ \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
+ \fi
+ \fi
+ \fi
+ % new, location=middle
+ \ifnum#2=\plusfour
+ \setbox\nextbox\vbox{\vskip-.5\!!heightb\hskip.5\!!heightb\flushnextbox}%
+ \nextboxwd\!!widthb
+ \nextboxht\!!heightb
+ \nextboxdp\!!depthb
+ \fi}
+
+\def\dorotatenextbox#1#2%
+ {\doifsomething{#1}
+ {\edef\@@rorotation{\realnumber{#1}}% get rid of leading zeros and spaces
+ \setbox\nextbox\vbox{\flushnextbox}% not really needed
+ \dodorotatenextbox\@@rorotation#2}%
+ \hbox{\boxcursor\flushnextbox}}
+
+\def\dodorotatebox#1% {angle} \hbox/\vbox/\vtop
+ {\bgroup\hbox\bgroup % compatibility hack
+ \dowithnextbox
+ {\dorotatenextbox{#1}\plusone
+ \egroup\egroup}}
+
+\def\dorotatebox#1% {angle} \hbox/\vbox/\vtop
+ {\ifcase#1\relax
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\dodorotatebox
+ \fi{#1}}
+
+\unexpanded\def\rotate % \bgroup: \rotate kan argument zijn
+ {\bgroup\complexorsimpleempty\rotate}
+
+% \def\complexrotate[#1]% framed met diepte !
+% {\getparameters[\??ro][#1]%
+% \processaction
+% [\@@rolocation]
+% [ \v!depth=>\!!counta\plusthree\donefalse,% depth fit - raw box
+% \v!fit=>\!!counta\plustwo \donefalse,% depth tight - raw box
+% \v!broad=>\!!counta\plusone \donefalse,% nodepth fit - raw box
+% \v!high=>\!!counta\plusone \donetrue ,% nodepth fit - framed
+% \v!middle=>\!!counta\plusfour \donefalse,% centered, keep dimensions
+% \s!default=>\!!counta\plusthree\donetrue ,% depth fit - framed
+% \s!unknown=>\!!counta\plusthree\donetrue ]% depth fit - framed
+% \ifdone
+% \def\docommand{\localframed[\??ro][#1,\c!location=]}%
+% \else
+% \let\docommand\relax
+% \fi
+% \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
+
+\setvalue{\??ro::\c!location::\v!depth }{\!!counta\plusthree\donefalse} % depth fit - raw box
+\setvalue{\??ro::\c!location::\v!fit }{\!!counta\plustwo \donefalse} % depth tight - raw box
+\setvalue{\??ro::\c!location::\v!broad }{\!!counta\plusone \donefalse} % nodepth fit - raw box
+\setvalue{\??ro::\c!location::\v!high }{\!!counta\plusone \donetrue } % nodepth fit - framed
+\setvalue{\??ro::\c!location::\v!middle }{\!!counta\plusfour \donefalse} % centered, keep dimensions
+\setvalue{\??ro::\c!location::\v!default}{\!!counta\plusthree\donetrue } % depth fit - framed
+
+\def\complexrotate[#1]% framed met diepte !
+ {\getparameters[\??ro][#1]%
+ \executeifdefined{\??ro::\c!location::\@@rolocation}{\!!counta\plusthree\donetrue}%
+ \ifdone
+ \def\docommand{\localframed[\??ro][#1,\c!location=]}%
+ \else
+ \let\docommand\relax
+ \fi
+ \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
+
+\presetlocalframed[\??ro]
+
+\def\setuprotate
+ {\dodoubleargument\getparameters[\??ro]}
+
+\setuprotate
+ [\c!rotation=90,
+ \c!location=\v!normal,
+ \c!width=\v!fit,
+ \c!height=\v!fit,
+ \c!offset=\v!overlay,
+ \c!frame=\v!off]
+
+% \dostepwiserecurse{0}{360}{10}
+% {\startlinecorrection[blank]
+% \hbox
+% {\expanded{\setuprotate[rotation=\recurselevel]}%
+% \traceboxplacementtrue
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=depth] {\ruledhbox{\bfb (depth)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=fit] {\ruledhbox{\bfb (fit)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=broad] {\ruledhbox{\bfb (broad)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=normal]{\ruledhbox{\bfb (normal)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=high] {\ruledhbox{\bfb (high)}}}}}
+% \stoplinecorrection}
+
+% to be used in some other places! todo!
+%
+% divides \hsize in fractions, will be made a bit more
+% clever and advanced when needed
+%
+% \horizontaldivision[n/m,elements,distance]
+%
+% \horizontaldivision[2/5,3,1em]
+% \horizontaldivision[2/5,3,1em]
+% \horizontaldivision[1/5,3,1em]
+%
+% \setuphorizontaldivision[afstand=,aantal=] (passend,passend)
+
+\def\??fr{@@fr}
+
+\def\setuphorizontaldivision
+ {\dodoubleargument\getparameters[\??fr]}
+
+\def\horizontaldivision
+ {\dosingleargument\dohorizontaldivision}
+
+\def\dohorizontaldivision[#1]%
+ {\dodohorizontaldivision[#1,,,,,,]}
+
+\def\dodohorizontaldivision[#1/#2,#3,#4,#5]%
+ {\doifelsenothing{#3}
+ {\doifelse\@@frn\v!fit
+ {\!!counta#2\relax}
+ {\!!counta\@@frn\relax}}
+ {\!!counta#3\relax}%
+ \doifelsenothing{#4}
+ {\doifelse\@@frdistance\v!fit
+ {\!!widtha\zeropoint}
+ {\!!widtha\@@frdistance}}
+ {\!!widtha#4}%
+ \advance\!!counta \minusone
+ \multiply\!!widtha \!!counta
+ \advance\hsize -\!!widtha
+ \divide\hsize #2\relax
+ \hsize#1\hsize}
+
+\setuphorizontaldivision
+ [\c!distance=\tfskipsize,
+ \c!n=\v!fit]
+
+%D This one is for Daniel Pittman, who wanted tight
+%D fractions. We show three versions. First the simple
+%D one using \type {\low} and \type {high}:
+%D
+%D \startbuffer
+%D \def\vfrac#1#2%
+%D {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}
+%D
+%D test \vfrac{1}{2} test \vfrac{123}{456} test
+%D \stopbuffer
+%D
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D A better way to handle the kerning is the following, here
+%D we kind of assume that tye slash is symmetrical and has
+%D nearly zero width.
+%D
+%D \startbuffer
+%D \def\vfract#1#2%
+%D {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}
+%D \stopbuffer
+%D
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D The third and best alternative is the following:
+%D
+%D {\showmakeup\getbuffer}\crlf\getbuffer
+%D
+%D This time we measure the height of the \type {/} and
+%D shift over the maximum height and depths of this
+%D character and the fractional digits (we use 57 as
+%D sample). Here we combine all methods in one macros.
+
+\chardef\vulgarfractionmethod=3
+
+\definehspace[vulgarfraction][.25em] % [.15em]
+\definesymbol[vulgarfraction][/] % [\raise.2ex\hbox{/}]
+
+\unexpanded\def\vulgarfraction#1#2%
+ {\dontleavehmode
+ \hbox
+ {\def\vulgarfraction{vulgarfraction}%
+ \ifcase\vulgarfractionmethod
+ #1\symbol[\vulgarfraction]#2%
+ \or
+ \high{\tx#1\kern-\hspaceamount\empty\vulgarfraction}%
+ \symbol[\vulgarfraction]%
+ \low {\kern-\hspaceamount\empty\vulgarfraction\tx#2}%
+ \or
+ \high{\tx#1}%
+ \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
+ \low{\tx#2}%
+ \or
+ \setbox0\hbox{\symbol[\vulgarfraction]}%
+ \setbox2\hbox{\txx57}%
+ \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
+ \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
+ \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
+ \fi}}
+
+\ifx\vfrac\undefined \let\vfrac\vulgarfraction \fi
+
+%D \starttabulate
+%D \HL
+%D \NC \bf method \NC \bf visualization \NC\NR
+%D \HL
+%D \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR
+%D \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR
+%D \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR
+%D \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR
+%D \HL
+%D \stoptabulate
+
+%D Under construction:
+%D
+%D \starttyping
+%D \commalistsentence[aap,noot,mies]
+%D \commalistsentence[aap,noot]
+%D \commalistsentence[aap]
+%D \commalistsentence[a,b,c]
+%D \commalistsentence[a,b,c][{ \& },{ and }]
+%D \commalistsentence[a,b,c][+,-]
+%D \stoptyping
+
+\let\handlecommalistsentence\firstofoneargument
+
+\def\commalistsentenceone{and-1}
+\def\commalistsentencetwo{and-2}
+
+\def\commalistsentence
+ {\dodoubleempty\docommalistsentence}
+
+\def\docommalistsentence[#1][#2]%
+ {\bgroup
+ \getfromcommalist[#2][1]%
+ \ifx\commalistelement\empty
+ \def\@@commalistsentenceone{\labeltext\commalistsentenceone}%
+ \else
+ \let\@@commalistsentenceone\commalistelement
+ \fi
+ \getfromcommalist[#2][2]%
+ \ifx\commalistelement\empty
+ \def\@@commalistsentencetwo{\labeltext\commalistsentencetwo}%
+ \else
+ \let\@@commalistsentencetwo\commalistelement
+ \fi
+ \getcommalistsize[#1]%
+ \ifcase\commalistsize\relax
+ \def\serializedcommalist{#1}%
+ \else
+ \let\serializedcommalist\empty
+ \scratchcounter\zerocount
+ \def\docommand##1%
+ {\advance\scratchcounter \plusone
+ \ifnum\scratchcounter=\plusone
+ \scratchtoks{\handlecommalistsentence{##1}}%
+ \else
+ \ifnum\scratchcounter=\commalistsize
+ \appendtoks\@@commalistsentencetwo\handlecommalistsentence{##1}\to\scratchtoks
+ \else
+ \appendtoks\@@commalistsentenceone\handlecommalistsentence{##1}\to\scratchtoks
+ \fi
+ \fi}%
+ \processcommacommand[#1]\docommand
+ \edef\serializedcommalist{\the\scratchtoks}%
+ \fi
+ \serializedcommalist
+ \egroup}
+
+\def\commacommandsentence[#1]{\@EA\commalistsentence\@EA[#1]}
+
+\ifx\textcomma\undefined \def\textcomma{,} \fi
+
+\setuplabeltext [\s!nl] [and-1=\textcomma\ , and-2= en ]
+\setuplabeltext [\s!en] [and-1=\textcomma\ , and-2=\textcomma\ and ]
+\setuplabeltext [\s!de] [and-1=\textcomma\ , and-2= und ]
+
+%D \macros
+%D {somekindoftab}
+%D
+%D This macro can be used to create tabs:
+%D
+%D \starttyping
+%D \setupheadertexts[{\somekindoftab[alternative=horizontal]{\framed{\realfolio}}}]
+%D \setuptexttexts [{\somekindoftab[alternative=vertical] {\framed{\realfolio}}}]
+%D
+%D \starttext
+%D \showframe \dorecurse{10}{test\page}
+%D \stoptext
+%D \stoptyping
+
+\def\somekindoftab
+ {\dosingleempty\dosomekindoftab}
+
+\def\dosomekindoftab[#1]%
+ {\bgroup
+ \getparameters[xx]
+ [\c!alternative=\v!vertical,
+ \c!width=\textwidth,\c!height=\textheight,
+ \c!n=\lastpage,\c!m=\realpageno,
+ #1]%
+ \doifelse\xxalternative\v!vertical
+ {\dodosomekindoftab\vbox\vskip\xxheight}
+ {\dodosomekindoftab\hbox\hskip\xxwidth }}
+
+\def\dodosomekindoftab#1#2#3#4%
+ {#1 to #3 \bgroup
+ \forgetall
+ \ifnum\xxm>\plusone
+ #2\zeropoint \!!plus \the\numexpr\xxm -1\relax fill\relax
+ \fi
+ #4%
+ \ifnum\xxm<\xxn\relax
+ #2\zeropoint \!!plus \the\numexpr\xxn-\xxm\relax fill\relax
+ \fi
+ \egroup
+ \egroup}
+
+\protect \endinput
diff --git a/tex/context/base/core-mis.mkiv b/tex/context/base/core-mis.mkiv
new file mode 100644
index 000000000..96d3bd2cd
--- /dev/null
+++ b/tex/context/base/core-mis.mkiv
@@ -0,0 +1,2606 @@
+%D \module
+%D [ file=core-mis,
+%D version=1998.01.29,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Miscelaneous,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Misc Commands}
+
+% todo: kleur in legenda + letter
+
+% %D You would not expect the next macro in \CONTEXT,
+% %D wouldn't you? It's there to warn \LATEX\ users that
+% %D something is wrong.
+% %D
+% %D Obsolete now:
+% %
+% % \def\documentstyle{\showmessage\m!systems3\empty\stoptekst}
+% %
+% % \let\documentclass=\documentstyle
+% %D \macros
+% %D {simplifiedcommands, simplifycommands}
+% %D
+% %D I first needed this simplification in bookmarks. Users can
+% %D add their own if needed.
+
+\unprotect
+
+%D Sometimes (for instance in bookmarks) we need to simplify macro
+%D behaviour, so here is the hook.
+
+\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
+
+\def\simplifycommands{\the\simplifiedcommands}
+
+%D A possibly growing list:
+
+%appendtoks \def\executesynonym#1#2#3#4{#3}\to\simplifiedcommands
+%appendtoks \def\executesort#1#2#3{#3}\to\simplifiedcommands
+
+\appendtoks \def\ { }\to\simplifiedcommands
+\appendtoks \def\type#1{\letterbackslash\strippedcsname#1}\to\simplifiedcommands
+\appendtoks \def\tex#1{\letterbackslash#1}\to\simplifiedcommands
+\appendtoks \def\TeX{TeX}\to\simplifiedcommands
+\appendtoks \def\ConTeXt{ConTeXt}\to\simplifiedcommands
+\appendtoks \def\MetaPost{MetaPost}\to\simplifiedcommands
+\appendtoks \def\MetaFont{MetaFont}\to\simplifiedcommands
+\appendtoks \def\MetaFun{MetaFun}\to\simplifiedcommands
+%appendtoks \def||{-}\to\simplifiedcommands
+\appendtoks \def|#1|{\ifx#1\empty\empty-\else#1\fi}\to\simplifiedcommands
+
+\appendtoks\let\buildtextaccent\secondoftwoarguments\to\simplifiedcommands
+
+% THIS WAS MAIN-002.TEX
+
+%\def\checkinterlineskip
+% {\ifvmode
+% \ifdim\lastskip>\zeropoint
+% \nointerlineskip
+% \else\ifdim\lastkern>\zeropoint
+% \nointerlineskip
+% \fi\fi
+% \fi}
+
+\def\horitems#1#2% #1=breedte #2=commandos
+ {\scratchdimen#1%
+ \divide\scratchdimen \nofitems
+ \!!counta\zerocount
+ \def\docommand##1%
+ {\advance\!!counta \plusone
+ \processaction
+ [\@@isalign]
+ [ \v!left=>\hbox to \scratchdimen{\strut##1\hss},
+ \v!right=>\hbox to \scratchdimen{\hss\strut##1},
+ \v!middle=>\hbox to \scratchdimen{\hss\strut##1\hss},
+ \v!margin=>\ifnum\!!counta=\plusone\hss\else\hfill\fi
+ \strut##1%
+ \ifnum\!!counta=\nofitems\hss\else\hfill\fi,
+ \s!default=>\hbox to \scratchdimen{\hss\strut##1\hss}, % midden
+ \s!unknown=>\hbox to \scratchdimen{\strut##1\hss}]}% % links
+ \hbox to #1{\hss#2\hss}}
+
+\def\veritems#1#2% #1=breedte #2=commandos
+ {\scratchdimen#1%
+ \def\docommand##1%
+ {\ifdim\scratchdimen<\zeropoint % the - was a signal
+ \hbox to -\scratchdimen{\hss\strut##1}%
+ \else\ifdim\scratchdimen>\zeropoint
+ \hbox to \scratchdimen{\strut##1\hss}%
+ \else
+ \hbox{\strut##1}%
+ \fi\fi}%
+ \vbox{#2}}
+
+\def\dosetupitems[#1]%
+ {\getparameters[\??is][#1]%
+ \doif\@@iswidth\v!unknown
+ {\def\@@iswidth{\hsize}}%
+ \doifconversiondefinedelse\@@issymbol
+ {\def\doitembullet##1{\convertnumber{\@@issymbol}{##1}}}
+ {\doifsymboldefinedelse\@@issymbol
+ {\def\doitembullet##1{\symbol[\@@issymbol]}}{}}}
+
+\def\makeitemsandbullets#1%
+ {\doifelse\@@isn\v!unknown
+ {\getcommalistsize[#1]%
+ \edef\nofitems{\commalistsize}}
+ {\edef\nofitems{\@@isn}}%
+ \setbox0\hbox
+ {\doitems \@@iswidth
+ {\processcommalist[#1]\docommand}}%
+ \setbox2\hbox
+ {\doitems \@@isbulletbreedte
+ {\dorecurse\nofitems
+ {\docommand{\strut\doitembullet\recurselevel}}}}}
+
+\def\dostartitems#1#2#3%
+ {\let\doitems#2%
+ \def\@@isbulletbreedte{#3}%
+ \makeitemsandbullets{#1}%
+ \@@isbefore}
+
+\def\dostopitems
+ {\@@isafter
+ \egroup}
+
+\setvalue{doitems\v!top}#1%
+ {\dostartitems{#1}\horitems\@@iswidth
+ \noindent\vbox
+ {\forgetall
+ \doifsomething\@@issymbol
+ {\doifnot\@@issymbol\v!none
+ {\box2
+ \@@isinbetween
+ \nointerlineskip}}%
+ \box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!bottom}#1%
+ {\dostartitems{#1}\horitems\@@iswidth
+ \noindent\vbox
+ {\forgetall
+ \box0
+ \doifsomething\@@issymbol
+ {\@@isinbetween
+ \nointerlineskip
+ \box2}}%
+ \dostopitems}
+
+\setvalue{doitems\v!inmargin}#1%
+ {\dostartitems{#1}\veritems{-1.5em}% - is a signal
+ \noindent\hbox{\llap{\box2\hskip\leftmargindistance}\box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!left}#1%
+ {\advance\hsize -1.5em%
+ \dostartitems{#1}\veritems{1.5em}%
+ \noindent\hbox{\box2\box0}%
+ \dostopitems}
+
+\setvalue{doitems\v!right}#1%
+ {\dostartitems{#1}\veritems{0em}%
+ \noindent\hbox{\box0\hskip-\wd2\box2}%
+ \dostopitems}
+
+\def\setupitems
+ {\dosingleargument\dosetupitems}
+
+\def\complexitems[#1]%
+ {\bgroup
+ \setupitems[#1]%
+ \parindent\zeropoint
+ \setlocalhsize
+ \hsize\localhsize
+ \dontcomplain
+ %\doifundefined{doitems\@@islocation}%
+ % {\let\@@islocation\v!left}%
+ %\getvalue{doitems\@@islocation}}
+ \executeifdefined{doitems\@@islocation}{\let\@@islocation\v!left}}
+
+\definecomplexorsimpleempty\items
+
+\setupitems
+ [\c!location=\v!left,
+ \c!symbol=5,
+ \c!width=\hsize,
+ \c!align=\v!middle,
+ \c!n=\v!unknown,
+ \c!before=\blank,
+ \c!inbetween={\blank[\v!medium]},
+ \c!after=\blank]
+
+% Te zijner tijd [plaats=boven,onder,midden] implementeren,
+% in dat geval moet eerst de maximale hoogte worden bepaald.
+%
+% Overigens kan een en ander mooier met \halign.
+
+% there is quite some historic balast in this mechanism, the next variant
+% is a first cleanup
+
+\let\currentparagraph\empty
+
+\newcount\alcounter \newcount\alnsize \newdimen\alhsize
+
+\def\paragraphparameter#1% \checkedparameter\??al\currentparagraph#1
+ {\executeifdefined{\??al\currentparagraph#1}{\executeifdefined{\??al#1}\empty}}
+
+\def\paragraphcellmeter#1#2% \checkedparameter\??al\currentparagraph#1
+ {\executeifdefined{\??al\currentparagraph\number#1#2}{\paragraphparameter{#2}}}
+
+\def\dodefineparagraphs[#1][#2]%
+ {\edef\currentparagraph{#1}%
+ \setvalue{\s!do\s!next\currentparagraph}%
+ {\def\\{\getvalue\currentparagraph}}%
+ \setvalue\currentparagraph
+ {\getvalue{\s!do\s!next#1}%
+ \dostartparagraphs{#1}}%
+ \setvalue{\e!next\currentparagraph}%
+ {\getvalue{#1}}%
+ \setvalue{\e!start\currentparagraph}%
+ {\bgroup
+ \edef\currentparagraph{#1}%
+ \letvalue{\s!do\s!next\currentparagraph}\empty
+ \setvalue{\e!stop\currentparagraph}{\getvalue\currentparagraph\egroup}%
+ \getvalue\currentparagraph}%
+ \getparameters[\??al\currentparagraph]%
+ [%\c!n=3,
+ %\c!before=\blank,
+ %\c!after=\blank,
+ %\c!distance=1em,
+ %\c!height=\v!fit,
+ %\c!rule=\v!off,
+ %\c!command=,
+ %\c!align=,
+ %\c!tolerance=\v!tolerant,
+ %\c!rulethickness=\linewidth,
+ %\c!rulecolor=,
+ %\c!style=,
+ %\c!color=,
+ %\c!top=,
+ %\c!top=\vss,
+ %\c!bottom=\vfill,
+ #2]%
+ \setvalue{\e!setup#1\e!endsetup}%
+ {\setupparagraphs[#1]}%
+ \dorecurse
+ {\paragraphparameter\c!n}
+ {\setupparagraphs
+ [\currentparagraph]
+ [\recurselevel]
+ [\c!width=,
+ %\c!bottom=\paragraphparameter\c!bottom,
+ %\c!top=\paragraphparameter\c!top,
+ %\c!height=\paragraphparameter\c!height,
+ %\c!rule=\paragraphparameter\c!rule,
+ %\c!rulethickness=\paragraphparameter\c!rulethickness,
+ %\c!rulecolor=\paragraphparameter\c!rulecolor,
+ %\c!align=\paragraphparameter\c!align,
+ %\c!tolerance=\paragraphparameter\c!tolerance, % obsolete
+ %\c!distance=\paragraphparameter\c!distance,
+ \c!style=\paragraphparameter\c!style,
+ \c!color=\paragraphparameter\c!color]}%
+ \setupparagraphs[\currentparagraph][1][\c!distance=\zeropoint]}
+
+\def\defineparagraphs
+ {\dodoubleargument\dodefineparagraphs}
+
+\def\dosetupparagraphs[#1][#2][#3]%
+ {\edef\currentparagraph{#1}%
+ \ifsecondargument
+ \doifelse{#2}\v!each
+ {\dorecurse
+ {\paragraphparameter\c!n}
+ {\getparameters[\??al\currentparagraph\recurselevel][#3]}}
+ {\doifelsenothing{#3}
+ {\getparameters[\??al\currentparagraph][#2]}
+ {\def\docommand##1{\getparameters[\??al\currentparagraph##1][#3]}%
+ \processcommalist[#2]\docommand}}%
+ \else
+ \getparameters[\??al][#1]%
+ \fi}
+
+\def\setupparagraphs
+ {\dotripleempty\dosetupparagraphs}
+
+\setupparagraphs
+ [\c!n=3,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!distance=1em,
+ \c!height=\v!fit,
+ \c!rule=\v!off,
+ \c!command=,
+ \c!align=,
+ \c!tolerance=\v!tolerant, % obsolete
+ \c!rulethickness=\linewidth,
+ \c!rulecolor=,
+ \c!style=,
+ \c!color=,
+ \c!top=,
+ \c!top=\vss,
+ \c!bottom=\vfill]
+
+\def\doparagraphrule
+ {\doifelse{\paragraphcellmeter\alcounter\c!rule}\v!on
+ {\linewidth\paragraphcellmeter\alcounter\c!rulethickness
+ \scratchdimen\paragraphcellmeter\alcounter\c!distance
+ \advance\scratchdimen-\linewidth
+ \divide\scratchdimen \plustwo
+ \hskip\scratchdimen
+ \color[\paragraphcellmeter\alcounter\c!rulecolor]{\vrule\!!width\linewidth}%
+ \hskip\scratchdimen}
+ {\hskip\paragraphcellmeter\alcounter\c!distance}}
+
+\def\dostartparagraph
+ {\doifelsenothing{\paragraphcellmeter\alcounter\c!width}
+ {\!!widtha\alhsize
+ \divide\!!widtha \alnsize}
+ {\!!widtha\paragraphcellmeter\alcounter\c!width}%
+ \dostartattributes{\??al\currentparagraph\number\alcounter}\c!style\c!color\empty
+ \doifelse{\paragraphcellmeter\alcounter\c!height}\v!fit
+ {\setbox\scratchbox\vtop}
+ {\setbox\scratchbox\vtop to \paragraphcellmeter\alcounter\c!height}%
+ \bgroup
+ \blank[\v!disable]%
+ \forgetall
+ \paragraphcellmeter\alcounter\c!top
+ \paragraphparameter\c!inner
+ \hsize\!!widtha % setting \wd afterwards removed
+ \paragraphcellmeter\alcounter\c!inner % twice
+ \expanded{\setupalign [\paragraphcellmeter\alcounter\c!align ]}% {normal,verytolerant,stretch}
+ \expanded{\setuptolerance[\paragraphcellmeter\alcounter\c!tolerance]}% obsolete
+ \ignorespaces
+ \endgraf
+ \ignorespaces
+ %
+ % Nadeel van de onderstaande constructie is dat \everypar
+ % binnen een groep kan staan en zo steeds \begstruts
+ % worden geplaatst. Mooi is anders dus moet het anders!
+ %
+ % Hier is \Everypar niet nodig.
+ %
+ \everypar{\begstrut\everypar\emptytoks}%
+ %
+ \nospace % remove + ignore
+ \paragraphcellmeter\alcounter\c!command}
+
+\def\dostopparagraph
+ {\ifvmode
+ \removelastskip
+ \else
+ \unskip\endstrut\endgraf
+ \fi
+ \paragraphcellmeter\alcounter\c!bottom
+ \egroup
+ \ifdim\wd\scratchbox=\zeropoint % no data
+ \wd\scratchbox\!!widtha
+ \fi
+ \box\scratchbox
+ \dostopattributes
+ \ifnum\alcounter<\paragraphparameter\c!n\relax
+ \@EA\doparagraphcell
+ \else
+ \@EA\dostopparagraphs
+ \fi}
+
+\def\doparagraphcell
+ {\global\advance\alcounter \plusone
+ \doifelsenothing{\paragraphcellmeter\alcounter\c!distance}
+ {\ifnum\alcounter=\plusone\else
+ \hskip\paragraphparameter\c!distance
+ \fi}
+ {\ifnum\alcounter=\plusone
+ \hskip\paragraphcellmeter\alcounter\c!distance
+ \else
+ \doparagraphrule
+ \fi}%
+ \letvalue\currentparagraph\dostopparagraph
+ \dostartparagraph}
+
+\def\dostartparagraphs#1%
+ {\bgroup
+ \edef\currentparagraph{#1}%
+ \global\alcounter\zerocount
+ \parindent\zeropoint
+ \setlocalhsize
+ \alhsize\localhsize
+ \alnsize\paragraphparameter\c!n\relax
+ \dorecurse \alnsize
+ {\doifelsenothing{\paragraphcellmeter\recurselevel\c!distance}
+ {\ifnum\recurselevel=\plusone\else
+ \global\advance\alhsize -\paragraphparameter\c!distance
+ \fi}
+ {\global\advance\alhsize -\paragraphcellmeter\recurselevel\c!distance}%
+ \doifsomething{\paragraphcellmeter\recurselevel\c!width}
+ {\global\advance\alnsize \minusone
+ \global\advance\alhsize -\paragraphcellmeter\recurselevel\c!width}}%
+ %whitespace % gaat fout bij \framed
+ \paragraphparameter\c!before
+ \leavevmode % gaat wel goed bij \framed, brrr
+ \setbox\scratchbox\vbox\bgroup\hbox\bgroup\doparagraphcell}
+
+\def\dostopparagraphs
+ {\egroup
+ \egroup
+ \iftrue
+ \hbox{\raise\strutheight\box\scratchbox}% new
+ \else
+ \box\scratchbox % old
+ \fi
+ \par
+ \paragraphparameter\c!after
+ \egroup}
+
+\def\dosetuptab[#1]%
+ {\getparameters[\??ta]
+ [\c!headstyle=\v!normal,
+ \c!headcolor=,
+ \c!style=\v!normal,
+ \c!color=,
+ \c!width=\v!broad,
+ \c!sample={\hskip4em},
+ \c!before=,
+ \c!after=,
+ #1]%
+ \definedescription
+ [tab]
+ [\c!headstyle=\@@taheadstyle,
+ \c!headcolor=\@@tacolor,
+ \c!sample=\@@tasample,
+ \c!width=\@@tawidth,
+ \c!before=\@@tabefore,
+ \c!after=\@@taafter]}
+
+\def\setuptab
+ {\dosingleargument\dosetuptab}
+
+\setuptab
+ [\c!location=\v!left]
+
+% The following macro's are derived from PPCHTEX and
+% therefore take some LaTeX font-switching into account.
+
+\newif\ifloweredsubscripts
+
+% Due to some upward incompatibality of LaTeX to LaTeX2.09
+% and/or LaTeX2e we had to force \@@chemieletter. Otherwise
+% some weird \nullfont error comes up.
+
+\doifundefined{@@chemieletter}{\def\@@chemieletter{\rm}}
+
+\def\beginlatexmathmodehack
+ {\ifmmode
+ \let\endlatexmathmodehack\relax
+ \else
+ \def\endlatexmathmodehack{$}$\@@chemieletter
+ \fi}
+
+\def\setsubscripts
+ {\beginlatexmathmodehack
+ \def\dosetsubscript##1##2##3%
+ {\dimen0=##3\fontexheight##2%
+ \setxvalue{@@\string##1\string##2}{\the##1##2\relax}%
+ ##1##2=\dimen0\relax}%
+ \def\dodosetsubscript##1##2%
+ {\dosetsubscript{##1}{\textfont2}{##2}%
+ \dosetsubscript{##1}{\scriptfont2}{##2}%
+ \dosetsubscript{##1}{\scriptscriptfont2}{##2}}%
+ %dodosetsubscript\mathsupnormal {?}%
+ \dodosetsubscript\mathsubnormal {.7}%
+ \dodosetsubscript\mathsubcombined{.7}%
+ \global\loweredsubscriptstrue
+ \endlatexmathmodehack}
+
+\def\resetsubscripts
+ {\ifloweredsubscripts
+ \beginlatexmathmodehack
+ \def\doresetsubscript##1##2%
+ {\dimen0=\getvalue{@@\string##1\string##2}\relax
+ ##1##2=\dimen0}%
+ \def\dodoresetsubscript##1%
+ {\doresetsubscript{##1}{\textfont2}%
+ \doresetsubscript{##1}{\scriptfont2}%
+ \doresetsubscript{##1}{\scriptscriptfont2}}%
+ %dodoresetsubscript\mathsupnormal
+ \dodoresetsubscript\mathsubnormal
+ \dodoresetsubscript\mathsubcombined
+ \global\loweredsubscriptsfalse
+ \endlatexmathmodehack
+ \fi}
+
+\let\beginlatexmathmodehack = \relax
+\let\endlatexmathmodehack = \relax
+
+\def\chem#1#2#3%
+ {\bgroup
+ \setsubscripts
+ \mathematics{\hbox{#1}_{#2}^{#3}}%
+ \resetsubscripts
+ \egroup}
+
+\unexpanded\def\celsius #1{#1\mathematics{^\circ}C}
+\unexpanded\def\inch {\mathematics{\prime\prime}} % was: \hbox{\rm\char125\relax}
+\unexpanded\def\fraction#1#2{\mathematics{#1\over#2}}
+
+% very dutch
+
+\unexpanded\def\graden {\mathematics{^\circ}}
+
+\def\bedragprefix {\euro\normalfixedspace}
+\def\bedragsuffix {}
+\def\bedragempty {\euro}
+
+\unexpanded\def\bedrag#1%
+ {\strut\hbox\bgroup
+ \let\normalfixedspace\nonbreakablespace
+ \doifelsenothing{#1}
+ {\bedragempty}
+ {\bedragprefix\digits{#1}\bedragsuffix}%
+ \egroup}
+
+% \definieeralineas[test][n=3]
+%
+% \stelalineasin[test][3][breedte=4cm,uitlijnen=links]
+%
+% \startopelkaar
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{~.~~1,--} \\
+% \test hans \\ ton \\ \bedrag{~.~~1,~~} \\
+% \test hans \\ ton \\ \bedrag{~.100,--} \\
+% \test hans \\ ton \\ \subtot{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{1.000,--} \\
+% \test hans \\ ton \\ \totaal{1.000,--} \\
+% \test hans \\ ton \\ \bedrag{nihil,--} \\
+% \test hans \\ ton \\ \totaal{nihil,--} \\
+% \test hans \\ ton \\ \subtot{nihil,--} \\
+% \stopopelkaar
+
+\def\periodswidth {.5em}
+\def\periodsdefault{3} % was 5, but now it's like \unknown
+
+\unexpanded\def\periods
+ {\dosingleempty\doperiods}
+
+\def\doperiods[#1]% todo: also n=,width= or maybe just #1,#2
+ {\dontleavehmode
+ \begingroup
+ \scratchdimen\periodswidth
+ \hbox to \iffirstargument#1\else\periodsdefault\fi \scratchdimen
+ {\leaders\hbox to \scratchdimen{\hss.\hss}\hss}%
+ \endgroup}
+
+\unexpanded\def\unknown
+ {\periods\relax} % relax prevents lookahead for []
+
+% Example by Wolfgang Schuster on the context list:
+%
+% \unexpanded\def\fourdots{{\def\periodswidth{.3em}\periods[4]}}
+%
+% Hello\fourdots\ World\fourdots \par Hello\fourdots\ World.
+
+% compatibility macros
+
+\def\doorsnede
+ {\hbox{\rlap/$\circ$} }
+
+\unexpanded\def\ongeveer
+ {\mathematics\pm}
+
+\chardef\boundarycharactermode\plusone
+
+\def\midboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \languageparameter#1%
+ %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+\def\leftboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ \languageparameter#1%
+ \nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+\def\rightboundarycharacter#1#2%
+ {\ifcase\boundarycharactermode
+ \or
+ \prewordbreak %\nobreak
+ \hskip\hspaceamount\currentlanguage{#2}%
+ \languageparameter#1%
+ \or
+ \languageparameter#1%
+ \fi
+ \chardef\boundarycharactermode\plusone}
+
+% actually this is pretty old, but temporary moved here
+%
+% obsolete:
+
+\def\setuphyphenmark
+ {\dodoubleargument\getparameters[\??kp]}
+
+\def\setuphyphenmark[#1]% sign=normal|wide
+ {\dodoubleargument\getparameters[\??kp][#1]%
+ \doifinsetelse\@@kpsign {\v!normal}
+ {\let\textmodehyphen\normalhyphen \let\textmodehyphendiscretionary\normalhyphendiscretionary}
+ {\let\textmodehyphen\composedhyphen\let\textmodehyphendiscretionary\composedhyphendiscretionary}}
+
+\setuphyphenmark[\c!sign=\v!wide]
+% % \setuphyphenmark[\c!sign=\v!normal]
+
+\definesymbol[\c!lefthyphen] [\languageparameter\c!lefthyphen]
+\definesymbol[\c!righthyphen] [\languageparameter\c!righthyphen]
+\definesymbol[\c!hyphen] [\languageparameter\c!hyphen]
+
+\def\normalhyphen
+ {\hbox{\directsymbol\empty\c!hyphen}}
+
+\def\composedhyphen
+ {\hbox{\directsymbol\empty\c!compoundhyphen}}
+
+\def\normalhyphendiscretionary
+ {\discretionary
+ {\hbox{\directsymbol\empty\c!lefthyphen}}
+ {\hbox{\directsymbol\empty\c!righthyphen}}
+ {\hbox{\directsymbol\empty\c!hyphen}}}
+
+\def\composedhyphendiscretionary
+ {\discretionary
+ {\hbox{\directsymbol\empty\c!leftcompoundhyphen}}
+ {\hbox{\directsymbol\empty\c!rightcompoundhyphen}}
+ {\hbox{\directsymbol\empty\c!compoundhyphen}}}
+
+\let\textmodehyphen \composedhyphen
+\let\textmodehyphendiscretionary\composedhyphendiscretionary
+
+\definesymbol[\c!leftcompoundhyphen] [\languageparameter\c!leftcompoundhyphen]
+\definesymbol[\c!rightcompoundhyphen] [\languageparameter\c!rightcompoundhyphen]
+\definesymbol[\c!compoundhyphen] [\languageparameter\c!compoundhyphen]
+
+\definehspace [sentence] [\zeropoint]
+\definehspace [intersentence] [.250em]
+
+\definesymbol
+ [\c!midsentence]
+ [\midboundarycharacter\c!midsentence{sentence}]
+
+\definesymbol
+ [\c!leftsentence]
+ [\leftboundarycharacter\c!leftsentence{sentence}]
+
+\definesymbol
+ [\c!rightsentence]
+ [\rightboundarycharacter\c!rightsentence{sentence}]
+
+\definesymbol
+ [\c!leftsubsentence]
+ [\leftboundarycharacter\c!leftsubsentence{sentence}]
+
+\definesymbol
+ [\c!rightsubsentence]
+ [\rightboundarycharacter\c!rightsubsentence{sentence}]
+
+\newsignal \subsentencesignal
+\newcount \subsentencelevel
+
+\let\beforesubsentence\donothing
+\let\aftersubsentence \donothing
+
+% todo: make this language option
+%
+% \def\beforesubsentence{\removeunwantedspaces}
+% \def\aftersubsentence {\ignorespaces}
+
+\def\midsentence
+ {\symbol[\c!midsentence]}
+
+\def\beginofsubsentence
+ {\beforesubsentence
+ \ifdim\lastkern=\subsentencesignal
+ \unskip
+ \kern\hspaceamount\currentlanguage{intersentence}%
+ \fi
+ \global\advance\subsentencelevel\plusone
+ \ifnum\subsentencelevel=\plusone
+ \dontleavehmode % was \leaveoutervmode
+ \fi
+ \symbol[\ifodd\subsentencelevel\c!leftsentence\else\c!leftsubsentence\fi]%
+ }% \ignorespaces}
+
+\def\endofsubsentence % relax prevents space gobbling
+ {\symbol[\ifodd\subsentencelevel\c!rightsentence\else\c!rightsubsentence\fi]%
+ \global\advance\subsentencelevel\minusone
+ \unskip
+ \kern\subsentencesignal\relax
+ \aftersubsentence}
+
+\def\beginofsubsentencespacing % relax prevents space gobbling
+ {\kern\subsentencesignal\relax}% \ignorespaces}
+
+\def\endofsubsentencespacing
+ {\ifdim\lastkern=\subsentencesignal
+ \unskip
+ \hskip\hspaceamount\currentlanguage{intersentence}%
+ % no good, actually language dependent:
+% \ignorespaces
+ \else
+ \unskip
+ \fi}
+
+%D \startbuffer
+%D test |<|test |<|test|>| test|>| test \par
+%D test|<|test|<|test|>|test|>|test \par
+%D test |<||<|test|>||>| test \par
+%D test \directdiscretionary{<}test\directdiscretionary{>} test \par
+%D \stopbuffer
+%D
+%D \typebuffer
+%D \getbuffer
+
+\def\startsubsentence{\beginofsubsentence \prewordbreak\beginofsubsentencespacing}
+\def\stopsubsentence {\endofsubsentencespacing\prewordbreak\endofsubsentence}
+
+%D \defineXMLenvironment [subsentence]
+%D {|<|}
+%D {|>|}
+%D \defineXMLenvironment [subsentence]
+%D {\directdiscretionary{<}}
+%D {\directdiscretionary{>}}
+%D \defineXMLenvironment [subsentence]
+%D {\startsubsentence}
+%D {\stopsubsentence}
+%D
+%D \startbuffer
+%D test test test
+%D \stopbuffer
+%D
+%D \typebuffer
+%D \processXMLbuffer
+
+\enableactivediscretionaries
+
+\definehspace [quotation] [\zeropoint]
+\definehspace [interquotation] [.125em]
+
+%definehspace [quote] [\zeropoint]
+%definehspace [speech] [\zeropoint]
+
+\definehspace [quote] [\hspaceamount\currentlanguage{quotation}]
+\definehspace [speech] [\hspaceamount\currentlanguage{quotation}]
+
+\definesymbol
+ [\c!leftquotation]
+ [\leftboundarycharacter\c!leftquotation{quotation}]
+
+\definesymbol
+ [\c!rightquotation]
+ [\rightboundarycharacter\c!rightquotation{quotation}]
+
+\definesymbol
+ [\c!leftquote]
+ [\leftboundarycharacter\c!leftquote{quote}]
+
+\definesymbol
+ [\c!rightquote]
+ [\rightboundarycharacter\c!rightquote{quote}]
+
+\definesymbol
+ [\c!leftspeech]
+ [\leftboundarycharacter\c!leftspeech{speech}]
+
+\definesymbol
+ [\c!rightspeech]
+ [\rightboundarycharacter\c!rightspeech{speech}]
+
+\definesymbol
+ [\c!middlespeech]
+ [\leftboundarycharacter\c!middlespeech{speech}]
+
+\appendtoks\def\quotation#1{"#1"}\to\simplifiedcommands
+\appendtoks\def\quote #1{'#1'}\to\simplifiedcommands
+
+%D The next features was so desperately needed by Giuseppe
+%D Bilotta that he made a module for it. Since this is a
+%D typical example of core functionality, I decided to extend
+%D the low level quotation macros in such a way that a speech
+%D feature could be build on top of it. The speech opening and
+%D closing symbols are defined per language. Italian is an
+%D example of a language that has them set.
+
+% this will replace the quotation and speed definitions
+
+\newsignal\delimitedtextsignal
+
+\let\currentdelimitedtext\s!unknown
+
+\def\delimitedtextlevel{\csname\??ci:\currentdelimitedtext:\c!level\endcsname}
+
+\def\doinitializetextlevel#1%
+ {\ifcsname\??ci:#1:\c!level\endcsname
+ \newcount\csname\??ci:#1:\c!level\endcsname\zerocount
+ \else
+ \expandafter\newcount\csname\??ci:#1:\c!level\endcsname
+ \fi}
+
+\def\delimitedtextparameter#1% will be sped up
+ {\executeifdefined{\??ci\currentdelimitedtext:\number\delimitedtextlevel#1}%
+ {\executeifdefined{\??ci\currentdelimitedtext#1}%
+ {\executeifdefined{\??ci#1}\empty}}}
+
+\def\definedelimitedtext
+ {\dodoubleempty\dodefinedelimitedtext}
+
+\def\dodefinedelimitedtext[#1][#2]%
+ {\doinitializetextlevel{#1}%
+ \doifassignmentelse{#2}
+ {\getparameters
+ [\??ci#1]
+ [\c!location=\v!margin, % \v!text \v!paragraph
+ \c!spacebefore=,
+ \c!spaceafter=\delimitedtextparameter\c!spacebefore,
+ \c!style=\v!normal,
+ \c!color=,
+ \c!leftmargin=\zeropoint,
+ \c!rightmargin=\delimitedtextparameter\c!leftmargin,
+ \c!indentnext=\v!yes,
+ \c!before=,
+ \c!after=,
+ \c!left=,
+ \c!right=,
+ %\c!level=0,
+ \c!repeat=\v!no,
+ \c!method=,
+ #2]}%
+ {\doifdefined{#2}
+ {\copyparameters[\??ci#1][\??ci#2]
+ [\c!location,\c!spacebefore,\c!spaceafter,\c!style,\c!color,
+ \c!leftmargin,\c!rightmargin,\c!indentnext,
+ \c!before,\c!after,\c!left,\c!right]}}%
+ \doifsomething{#1}
+ {\unexpanded\setvalue{#1}{\delimitedtext[#1]}%
+ \setvalue{\e!start#1}{\startdelimitedtext[#1]}%
+ \setvalue{\e!stop #1}{\stopdelimitedtext}}}
+
+\def\setupdelimitedtext
+ {\dotripleargument\dosetupdelimitedtext}
+
+\def\dosetupdelimitedtext[#1][#2][#3]% #2 = optional level
+ {\ifthirdargument
+ \getparameters[\??ci#1:#2][#3]%
+ \else\ifsecondargument
+ \getparameters[\??ci#1][#2]%
+ \else
+ \getparameters[\??ci][#1]%
+ \fi\fi}
+
+\def\dorepeatdelimitedtext
+ {\relax\ifcase\delimitedtextlevel\else
+ \dohandledelimitedtext\c!middle % maybe better \dohandleleftdelimitedtext
+ \fi}
+
+\let\dohandlerepeatdelimitedtext\relax
+
+\def\startdelimitedtext[#1]%
+ {\bgroup
+ \pushdelimitedtext{#1}%
+ \doifelse{\delimitedtextparameter\c!method}\s!font
+ {\def\dostopdelimitedtext
+ {\removeunwantedspaces\ignoredelimitedtext\c!right}%
+ \ignoredelimitedtext\c!left\ignorespaces}
+ {\doifelse{\delimitedtextparameter\c!repeat}\v!yes
+ {\let\dohandlerepeatdelimitedtext\dorepeatdelimitedtext}%
+ {\let\dohandlerepeatdelimitedtext\relax}%
+ \doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
+ {\dosingleempty\dostartdelimitedtextpar}\dostartdelimitedtexttxt}}
+
+\def\dostartdelimitedtextpar[#1]%
+ {\let\dostopdelimitedtext\dostopdelimitedtextpar
+ \doifsomething{\delimitedtextparameter\c!spacebefore}
+ {\blank[\delimitedtextparameter\c!spacebefore]}%
+ \delimitedtextparameter\c!before
+ % nicer:
+ % \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
+ % \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
+ % backward compatible:
+ \doifelsenothing{#1}
+ {\endgraf
+ \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
+ \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
+ \let\dodostopdelimitedtextpar\endgraf}
+ {\startnarrower[#1]\let\dodostopdelimitedtextpar\stopnarrower}%
+ % so far
+ % \dochecknextindentation{\??ci\currentdelimitedtext}% AM: not here
+ \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
+ \leftdelimitedtextmark
+ \ignorespaces}
+
+\def\dostopdelimitedtextpar
+ {\removeunwantedspaces
+ \removelastskip
+ \rightdelimitedtextmark
+ \dostopattributes
+ \dodostopdelimitedtextpar
+ \delimitedtextparameter\c!after
+ \doifsomething{\delimitedtextparameter\c!spaceafter}
+ {\blank[\delimitedtextparameter\c!spaceafter]}%
+ \dochecknextindentation{\??ci\currentdelimitedtext}% AM: here
+ \dorechecknextindentation}% AM: This was missing!
+
+\def\dostartdelimitedtexttxt
+ {\let\dostopdelimitedtext\dostopdelimitedtexttxt
+ \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
+ \dohandleleftdelimitedtext\c!left
+ \ignorespaces}
+
+\def\dostopdelimitedtexttxt
+ {\removeunwantedspaces
+ \dohandlerightdelimitedtext\c!right
+ \dostopattributes}
+
+\def\stopdelimitedtext
+ {\dostopdelimitedtext
+ \popdelimitedtext
+ \egroup}
+
+\def\pushdelimitedtext#1%
+ {\globalpushmacro\currentdelimitedtext
+ \def\currentdelimitedtext{#1}%
+ \global\advance\delimitedtextlevel\plusone}
+
+\def\popdelimitedtext
+ {\global\advance\delimitedtextlevel\minusone
+ \globalpopmacro\currentdelimitedtext}
+
+\def\delimitedtext[#1]%
+ {\pushdelimitedtext{#1}%
+ \doifelse{\delimitedtextparameter\c!method}\s!font
+ {\dofontdrivendelimited}
+ {\doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
+ \dodelimitedtextpar\dodelimitedtexttxt}}
+
+% shortcuts
+
+\def\startdelimited{\startdelimitedtext}
+\def\stopdelimited {\stopdelimitedtext} % no let, dynamically assigned
+\def\delimited {\delimitedtext}
+
+\def\leftdelimitedtextmark
+ {\doifsomething{\delimitedtextparameter\c!left}
+ {\setbox\scratchbox\hbox{\delimitedtextparameter\c!left}%
+ \dontleavehmode
+ \doif{\delimitedtextparameter\c!location}\v!margin{\hskip-\wd\scratchbox}%
+ \box\scratchbox}}
+
+\def\rightdelimitedtextmark
+ {\doifsomething{\delimitedtextparameter\c!right}
+ {\hsmash{\delimitedtextparameter\c!right}}}
+
+% \starttext
+% \hyphenatedword{groepsvrijstellingsverordeningen}\par
+% \hyphenatedword{\quote{groepsvrijstellingsverordeningen}}\par
+% \dorecurse{100}{\hskip300pt\hskip\recurselevel pt test \quote{xxx xxxx}.\par}
+% \page \setuppapersize[A5][A4]
+% \quotation {overly beautiful pusillanimous sesquipedalian
+% longwinded} test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test test test test test test test test test test test
+% test test test
+% \stoptext
+
+\def\dohandledelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+% \ifdim\lastskip=\delimitedtextsignal
+% \unskip
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi
+ \ifhmode % else funny pagebeaks
+ \penalty\plustenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+% \penalty\plustenthousand % else overfull boxes, but that's better than dangling periods
+ \kern\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+\def\dohandleleftdelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else\ifdim\lastskip=\delimitedtextsignal
+ \unskip
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi\fi
+ \strut % new, needed below
+ \ifhmode % else funny pagebeaks
+ \penalty\plustenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+ \hskip\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+\def\dohandlerightdelimitedtext#1#2%
+ {\begingroup
+ \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \ifdim\lastkern=\delimitedtextsignal
+ \unkern
+ \penalty\plustenthousand
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else\ifdim\lastskip=\delimitedtextsignal
+ \unskip
+ \penalty\plustenthousand
+ \hskip\hspaceamount\currentlanguage{interquotation}%
+ \else
+ #2%
+ \fi\fi
+ \ifhmode % else funny pagebeaks
+ \penalty\plustenthousand
+ \hskip\zeropoint % == \prewordbreak
+ \fi
+ \strut % new, needed below
+ \delimitedtextparameter#1% unhbox\scratchbox
+ \kern\delimitedtextsignal % +- \prewordbreak
+ \fi
+ \endgroup}
+
+
+\def\ignoredelimitedtext#1%
+ {\delimitedtextparameter#1}
+
+\def\handledelimitedtext#1%
+ {\dohandledelimitedtext{#1}\relax}
+
+\def\handleleftdelimitedtext#1%
+ {\dohandleleftdelimitedtext{#1}\relax}
+
+\def\handlerightdelimitedtext#1%
+ {\dohandlerightdelimitedtext{#1}\relax}
+
+\unexpanded\def\dodelimitedtextpar
+ {\dohandleleftdelimitedtext\c!left\relax
+ \groupedcommand
+ \donothing
+ {\dohandlerightdelimitedtext\c!right\removelastskip
+ \popdelimitedtext}}
+
+\unexpanded\def\dodelimitedtexttxt
+ {\doifelse{\delimitedtextparameter\c!style}\v!normal
+ \doquoteddelimited\doattributeddelimited}
+
+\def\doquoteddelimited
+ {\dohandleleftdelimitedtext\c!left\relax
+ \groupedcommand
+ \donothing
+ {\dohandlerightdelimitedtext\c!right
+ \removelastskip
+ \popdelimitedtext}}
+
+\def\doattributeddelimited
+ {\groupedcommand
+ {\dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color}
+ {\dostopattributes
+ \popdelimitedtext}}
+
+\def\dofontdrivendelimited
+ {\simplegroupedcommand
+ {\languageparameter{\c!left\currentdelimitedtext}}
+ {\languageparameter{\c!right\currentdelimitedtext}%
+ \popdelimitedtext}}
+
+% testcase for nesting:
+%
+% \quotation{... \quotation{...} ...}
+% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
+% \setupdelimitedtext[quotation][1][left=(,right=)]
+% \setupdelimitedtext[quotation][2][left={[},right={]}]
+% \setupdelimitedtext[quotation][3][left=\{,right=\}]
+% \quotation{... \quotation{...} ...}
+% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
+
+\definedelimitedtext
+ [\v!quotation]
+ [\c!left={\symbol[\c!leftquotation]},
+ \c!right={\symbol[\c!rightquotation]},
+ \c!leftmargin=\v!standard]
+
+\definedelimitedtext
+ [\v!quote][\v!quotation]
+
+\setupdelimitedtext
+ [\v!quote]
+ [\c!location=\v!text,
+ \c!left={\symbol[\c!leftquote]},
+ \c!right={\symbol[\c!rightquote]}]
+
+\definedelimitedtext
+ [\v!blockquote][\v!quotation]
+
+\setupdelimitedtext
+ [\v!blockquote]
+ [\c!left=,
+ \c!right=]
+
+\definedelimitedtext
+ [\v!speech][\v!quotation]
+
+\setupdelimitedtext
+ [\v!speech]
+ [\c!repeat=\v!yes,
+ \c!left={\symbol[\c!leftspeech]},
+ \c!middle={\symbol[\c!middlespeech]},
+ \c!right={\symbol[\c!rightspeech]}]
+
+% how do we call an tight quote
+%
+% \definedelimitedtext
+% [\v!quotation][\v!quotation]
+%
+% \setupdelimitedtext
+% [\v!quotation]
+% [\c!indentnext=\v!no,
+% \c!spacebefore=\v!nowhite]
+
+\def\setupquotation{\setupdelimitedtext[\v!quotation]}
+\def\setupquote {\setupdelimitedtext[\v!quote]}
+
+% seldom used, move from kernel to run time module
+
+\ifx\tfx\undefined \let\tfx\relax \fi
+
+\def\basegrid
+ {\dosingleempty\dobasegrid}
+
+\def\dobasegrid[#1]%
+ {\begingroup
+ \getparameters[\??rt]
+ [\c!x=0,\c!y=0,
+ \c!nx=10,\c!ny=10,
+ \c!dx=.5,\c!dy=.5,
+ \c!xstep=0,\c!ystep=0,
+ \c!unit=\s!cm,
+ \c!scale=1,
+ \c!factor=1,
+ \c!offset=\v!yes,
+ \c!location=\v!left,
+ #1]%
+ \startpositioning
+ \dimen0=\@@rtdx\@@rtunit\relax
+ \dimen0=\@@rtscale\dimen0\relax
+ \dimen0=\@@rtfactor\dimen0\relax
+ \multiply\dimen0 \@@rtnx\relax
+ \dimen2=\@@rtdy\@@rtunit\relax
+ \dimen2=\@@rtscale\dimen2\relax
+ \dimen2=\@@rtfactor\dimen2\relax
+ \multiply\dimen2 \@@rtny\relax
+ \def\horline
+ {\vbox
+ {\hrule
+ \!!width \dimen0
+ \!!height \linewidth
+ \!!depth \!!zeropoint}}%
+ \def\verline%
+ {\vrule
+ \!!width \linewidth
+ \!!height \dimen2
+ \!!depth \!!zeropoint}%
+ \doglobal\newcounter\@@gridc
+ \doglobal\newcounter\@@gridd
+ \doglobal\newcounter\@@gride
+ \def\setlegend##1##2##3%
+ {\gdef\@@gridc{0}%
+ \dimen0=2em\relax
+ \dimen2=##2\@@rtunit\relax
+ \dimen2=\@@rtscale\dimen2\relax
+ \dimen2=\@@rtfactor\dimen2\relax
+ \divide\dimen0 \dimen2\relax
+ \xdef\@@gride{\number\dimen0}%
+ \ifnum\@@gride>50
+ \gdef\@@gride{100}%
+ \else\ifnum\@@gride>10
+ \gdef\@@gride{50}%
+ \else\ifnum\@@gride>5
+ \gdef\@@gride{10}%
+ \else\ifnum\@@gride>1
+ \gdef\@@gride{5}%
+ \else
+ \gdef\@@gride{1}%
+ \fi\fi\fi\fi
+ \gdef\@@gridd{0}%
+ \def\legend
+ {\ifnum\@@gridd=\zerocount
+ \vbox
+ {\increment(\@@gridc,##1)%
+ \hbox to 2em{\hss\@@gridc\hss}}%
+ \global\let\@@gridd=\@@gride
+ \fi
+ \doglobal\decrement\@@gridd
+ \doglobal\increment(\@@gridc,##1)}}%
+ \def\draw##1##2##3##4##5##6##7##8##9%
+ {\setuppositioning
+ [\c!state=##8,
+ \c!xstep=\v!absolute,
+ \c!ystep=\v!absolute,
+ \c!unit=\@@rtunit,
+ \c!scale=\@@rtscale,
+ \c!factor=\@@rtfactor,
+ \c!offset=\@@rtoffset,
+ \c!xoffset=##6,
+ \c!yoffset=##7]%
+ \doifelse{##9}\v!middle
+ {\scratchdimen##3pt\scratchdimen.5\scratchdimen
+ \edef\@@psxx{\withoutpt\the\scratchdimen}%
+ \scratchdimen##4pt\scratchdimen.5\scratchdimen
+ \edef\@@psyy{\withoutpt\the\scratchdimen}%
+ \scratchcounter##2\advance\scratchcounter -1
+ \edef\@@pszz{\the\scratchcounter}}
+ {\edef\@@psxx{0}\edef\@@psyy{0}\edef\@@pszz{##2}}%
+ \position(\@@psxx,\@@psyy){##1}%
+ \setuppositioning
+ [\c!state=##8,
+ \c!xstep=\v!relative,
+ \c!ystep=\v!relative,
+ \c!scale=\@@rtscale,
+ \c!factor=\@@rtfactor,
+ \c!offset=\@@rtoffset,
+ \c!unit=\@@rtunit]%
+ \dorecurse\@@pszz{\position(##3,##4){##5}}}%
+ \draw
+ \verline\@@rtnx\@@rtdx0\verline\!!zeropoint\!!zeropoint\v!start\empty
+ \draw
+ \horline\@@rtny0\@@rtdy\horline\!!zeropoint\!!zeropoint\v!start\empty
+ \tfx
+ \doifnot\@@rtxstep{0}
+ {\setlegend\@@rtxstep\@@rtdx\@@rtx
+ \draw\legend\@@rtnx\@@rtdx0\legend{-1em}{-1.5em}\v!overlay\@@rtlocation}%
+ \doifnot\@@rtystep{0}
+ {\setlegend\@@rtystep\@@rtdy\@@rty
+ \draw\legend\@@rtny0\@@rtdy\legend{-2em}{-.75ex}\v!overlay\@@rtlocation}%
+ \stoppositioning
+ \endgroup}
+
+\let\grid\basegrid
+
+% only used at pragma, move from kernel to run time module
+
+\def\referraldate
+ {\currentdate[\v!referral]}
+
+\def\doreferral[#1]%
+ {\noheaderandfooterlines
+ \bgroup
+ \getparameters
+ [\??km]
+ [\c!bet=\unknown,\c!dat=\unknown,\c!ken=\unknown,
+ \c!from=,\c!to=,\c!ref=,#1]%
+ % moet anders, hoort niet in 01b
+ \assigntranslation[\s!nl=referentie,\s!en=reference,\s!de=Referenz,\s!sp=referencia]\to\@@@kmref
+ \assigntranslation[\s!nl=van,\s!en=from,\s!de=Von,\s!sp=de]\to\@@@kmvan
+ \assigntranslation[\s!nl=aan,\s!en=to,\s!de=An,\s!sp=a]\to\@@@kmaan
+ \assigntranslation[\s!nl=betreft,\s!en=concerns,\s!de=Betreff,\s!sp=]\to\@@@kmbet
+ \assigntranslation[\s!nl=datum,\s!en=date,\s!de=Datum,\s!sp=fecha]\to\@@@kmdat
+ \assigntranslation[\s!nl=kenmerk,\s!en=mark,\s!de=Kennzeichen,\s!sp=]\to\@@@kmken
+ %
+ \definetabulate[\s!dummy][|l|p|]
+ \startdummy
+ \NC\@@@kmbet\EQ\@@kmbet\NC\NR
+ \NC\@@@kmdat\EQ\@@kmdat\NC\NR
+ \NC\@@@kmken\EQ\expanded{\smallcapped{\@@kmken}}\NC\NR
+ \doifsomething{\@@kmfrom\@@kmto}{\NC\NC\NC\NR}%
+ \doifsomething \@@kmfrom {\NC\@@@kmvan\EQ\@@kmfrom\NC\NR}%
+ \doifsomething \@@kmto {\NC\@@@kmaan\EQ\@@kmto\NC\NR}%
+ \doifsomething \@@kmref {\NC\NC\NC\NR\NC\@@@kmref\EQ\@@kmref\NC\NR}%
+ \stopdummy
+ \egroup}
+
+\def\referral
+ {\dosingleargument\doreferral}
+
+% FUZZY OLD STUFF: will be removed when not used in some manual;
+% rows instead of columns, i'd forgotten that this code exist
+%
+% \definesystemvariable{ri}
+%
+% \def\setuprows
+% {\dodoubleargument\getparameters[\??ri]}
+%
+% \definecomplexorsimpleempty\startrows
+%
+% \def\complexstartrows[#1]%
+% {\bgroup
+% \setuprows[#1]%
+% \let\do@@ribottom\relax
+% \def\row
+% {\do@@ribottom
+% \egroup
+% \dimen0\vsize
+% \divide\dimen0 \@@rin
+% \advance\dimen0 -\lineskip
+% \vbox to \dimen0
+% \bgroup
+% \@@ritop
+% \let\do@@ribottom\@@ribottom
+% \ignorespaces}%
+% \bgroup
+% \row}
+%
+% \def\stoprows
+% {\do@@ribottom
+% \egroup
+% \egroup}
+%
+% \setuprows
+% [\c!n=2,
+% \c!top=,
+% \c!bottom=\vfill]
+
+% THIS WAS MAIN-003.TEX
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+\definetabulate
+ [\v!legend]
+ [|emj1|i1|mR|]
+
+\setuptabulate
+ [\v!legend]
+ [\c!unit=.75em,\c!inner=\setquicktabulate\leg,EQ={=}]
+
+\definetabulate
+ [\v!legend][\v!two]
+ [|emj1|emk1|i1|mR|]
+
+\definetabulate
+ [\v!fact]
+ [|R|ecmj1|i1mR|]
+
+\setuptabulate
+ [\v!fact]
+ [\c!unit=.75em,\c!inner=\setquicktabulate\fact,EQ={=}]
+
+\unexpanded\def\xbox
+ {\bgroup\aftergroup\egroup\hbox\bgroup\tx\let\next=}
+
+\unexpanded\def\xxbox
+ {\bgroup\aftergroup\egroup\hbox\bgroup\txx\let\next=}
+
+% \def\mrm#1%
+% {$\rm#1$}
+
+%D \macros
+%D {definepairedbox, setuppairedbox, placepairedbox}
+%D
+%D Paired boxes, formally called legends, but from now on a
+%D legend is just an instance, are primarily meant for
+%D typesetting some text alongside an illustration. Although
+%D there is quite some variation possible, the functionality is
+%D kept simple, if only because in most cases such pairs are
+%D typeset sober.
+%D
+%D The location specification accepts a pair, where the first
+%D keyword specifies the arrangement, and the second one the
+%D alignment. The first key of the location pair is one of
+%D \type {left}, \type {right}, \type {top} or \type {bottom},
+%D while the second key can also be \type {middle}.
+%D
+%D The first box is just collected in an horizontal box, but
+%D the second one is a vertical box that gets passed the
+%D bodyfont and alignment settings.
+
+%D Today we would implement this using layers .... but for the
+%D moment we keep it this way.
+
+% \startbuffer[test]
+% \test left \test left,top \test left,bottom \test left,middle
+% \test right \test right,top \test right,bottom \test right,middle
+% \test top \test top,left \test top,right \test top,middle
+% \test bottom \test bottom,left \test bottom,right \test bottom,middle
+% \stopbuffer
+%
+% \def\showtest#1%
+% {\pagina
+% \typebuffer[demo]
+% \def\test##1
+% {\startlinecorrection[blank]
+% \getbuffer[demo]%
+% \ruledhbox\placelegend
+% [bodyfont=6pt,location={##1}]
+% {\framed[width=.25\textwidth]{\tttf##1}}
+% {#1}
+% \stoplinecorrection}
+% \getbuffer[test]}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=\hsize,maxwidth=\makeupwidth,
+% height=\vsize,maxheight=\makeupheight]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate the default settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=\textwidth,
+% maxwidth=\textwidth]
+% \stopbuffer
+%
+% \showtest{\input tufte }
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=.65\textwidth]
+% \stopbuffer
+%
+% \showtest{\input knuth }
+%
+% \startbuffer[demo]
+% \setuplegend
+% [height=2cm]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate some other settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [width=.65\textwidth,
+% height=2cm]
+% \stopbuffer
+%
+% \showtest{These examples demonstrate some other settings.}
+%
+% \startbuffer[demo]
+% \setuplegend
+% [n=2,align=right,width=.5\textwidth]
+% \stopbuffer
+%
+% \showtest{\input zapf }
+
+%D \macros
+%D {setuplegend, placelegend}
+%D
+%D It makes sense to typeset a legend to a figure in \TEX\
+%D and not in a drawing package. The macro \type {\placelegend}
+%D combines a figure (or something else) and its legend. This
+%D command is just a paired box.
+%D
+%D The legend is placed according to \type {location}, being
+%D \type {bottom} or \type {right}. The macro macro is used as
+%D follows.
+%D
+%D \starttyping
+%D \placefigure
+%D {whow}
+%D {\placelegend
+%D {\externalfigure[cow]}
+%D {\starttabulation
+%D \NC 1 \NC head \NC \NR
+%D \NC 2 \NC legs \NC \NR
+%D \NC 3 \NC tail \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend
+%D {\externalfigure[cow]}
+%D {\starttabulation[|l|l|l|l|]
+%D \NC 1 \NC head \NC 3 \NC tail \NC \NR
+%D \NC 2 \NC legs \NC \NC \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {\starttabulation
+%D \NC 1 \NC head \NC \NR
+%D \NC 2 \NC legs \NC \NR
+%D \NC 3 \NC tail \NC \NR
+%D \stoptabulation}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {head \par legs \par tail}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2]
+%D {\externalfigure[cow]}
+%D {\startitemize[packed]
+%D \item head \item legs \item tail \item belly \item horns
+%D \stopitemize}}
+%D
+%D \placefigure
+%D {whow}
+%D {\placelegend[n=2,width=.8\hsize]
+%D {\externalfigure[cow]}
+%D {\startitemize[packed]
+%D \item head \item legs \item tail \item belly \item horns
+%D \stopitemize}}
+%D \stoptyping
+
+\newbox\firstpairedbox
+\newbox\secondpairedbox
+
+\def\definepairedbox
+ {\dodoubleempty\dodefinepairedbox}
+
+\def\dodefinepairedbox[#1][#2]%
+ {\getparameters
+ [\??ld#1]
+ [\c!n=1,
+ \c!distance=\bodyfontsize,
+ \c!before=,
+ \c!after=,
+ \c!color=,
+ \c!style=,
+ \c!inbetween={\blank[\v!medium]},
+ \c!width=\hsize,
+ \c!height=\vsize,
+ \c!maxwidth=\textwidth, % \makeupwidth,
+ \c!maxheight=\textheight, % \makeupheight,
+ \c!bodyfont=,
+ \c!align=,
+ \c!location=\v!bottom,
+ #2]%
+ \setvalue{\e!setup#1\e!endsetup}{\setuppairedbox[#1]}%
+ \setvalue{\e!place#1}{\placepairedbox[#1]}}
+
+\def\setuppairedbox
+ {\dodoubleempty\dosetuppairedbox}
+
+\def\dosetuppairedbox[#1]%
+ {\getparameters[\??ld#1]}
+
+\def\placepairedbox
+ {\bgroup\dodoubleempty\doplacepairedbox}
+
+\def\doplacepairedbox[#1][#2]% watch the hsize/vsize tricks
+ {\setuppairedbox[#1][#2]% % and don't change them
+ \copyparameters % brrr
+ [\??ld][\??ld#1]
+ [\c!n,\c!distance,\c!inbetween,\c!before,\c!after,
+ \c!width,\c!height,\c!maxwidth,\c!maxheight,
+ \c!color,\c!style,\c!bodyfont,\c!align,\c!location]%
+ \@@ldbefore\bgroup
+ \global\setsystemmode{pairedbox}%
+ \beforefirstpairedbox
+ \dowithnextbox
+ {\betweenbothpairedboxes
+ \dowithnextbox
+ {\afterbothpairedboxes
+ \egroup\@@ldafter
+ \egroup}
+ \vbox\bgroup
+ \insidesecondpairedbox
+ \let\next=}
+ \hbox}
+
+\def\beforefirstpairedbox
+ {\chardef\pairedlocationa1 % left
+ \chardef\pairedlocationb4 % middle
+ \getfromcommacommand[\@@ldlocation][1]%
+ \processaction
+ [\commalistelement]
+ [ \v!left=>\chardef\pairedlocationa0,
+ \v!right=>\chardef\pairedlocationa1,
+ \v!top=>\chardef\pairedlocationa2,
+ \v!bottom=>\chardef\pairedlocationa3]%
+ \getfromcommacommand[\@@ldlocation][2]%
+ \processaction
+ [\commalistelement]
+ [ \v!left=>\chardef\pairedlocationb0,
+ \v!right=>\chardef\pairedlocationb1,
+ \v!high=>\chardef\pairedlocationb2,
+ \v!top=>\chardef\pairedlocationb2,
+ \v!low=>\chardef\pairedlocationb3,
+ \v!bottom=>\chardef\pairedlocationb3,
+ \v!middle=>\chardef\pairedlocationb4]}
+
+\def\betweenbothpairedboxes
+ {\switchtobodyfont[\@@ldbodyfont]% split under same regime
+ \setbox\firstpairedbox\flushnextbox
+ \ifnum\pairedlocationa<2
+ \hsize\wd\firstpairedbox % trick
+ \hsize\@@ldwidth
+ \scratchdimen\wd\firstpairedbox
+ \advance\scratchdimen \@@lddistance
+ \bgroup\advance\scratchdimen \hsize
+ \ifdim\scratchdimen>\@@ldmaxwidth\relax
+ \egroup
+ \hsize\@@ldmaxwidth
+ \advance\hsize -\scratchdimen
+ \else
+ \egroup
+ \fi
+ \else
+ \hsize\wd\firstpairedbox
+ \hsize\@@ldwidth % can be \hsize
+ \ifdim\hsize>\@@ldmaxwidth\relax \hsize\@@ldmaxwidth \fi % can be \hsize
+ \fi
+ \ifnum\@@ldn>\plusone
+ \setrigidcolumnhsize\hsize\@@lddistance\@@ldn
+ \fi}
+
+\def\afterbothpairedboxes
+ {\setbox\secondpairedbox\vbox
+ {% \localstartcolor[\@@ldcolor]% does not work yet
+ \ifnum\@@ldn>1
+ \rigidcolumnbalance\nextbox
+ \else
+ \flushnextbox
+ \fi
+ }% \localstopcolor}%
+ \ifnum\pairedlocationa<2\hbox\else\vbox\fi\bgroup % hide vsize
+ \forgetall
+ \ifnum\pairedlocationa<2
+ \scratchdimen\maxoftwoboxdimens\ht\firstpairedbox\secondpairedbox
+ \vsize\scratchdimen
+ \ifdim\scratchdimen<\@@ldheight\relax % can be \vsize
+ \scratchdimen\@@ldheight
+ \fi
+ \ifdim\scratchdimen>\@@ldmaxheight\relax
+ \scratchdimen\@@ldmaxheight
+ \fi
+ \valignpairedbox\firstpairedbox \scratchdimen
+ \valignpairedbox\secondpairedbox\scratchdimen
+ \else
+ \scratchdimen\maxoftwoboxdimens\wd\firstpairedbox\secondpairedbox
+ \halignpairedbox\firstpairedbox \scratchdimen
+ \halignpairedbox\secondpairedbox\scratchdimen
+ \scratchdimen\ht\secondpairedbox
+ \vsize\scratchdimen
+ \ifdim\ht\secondpairedbox<\@@ldheight\relax % can be \vsize
+ \scratchdimen\@@ldheight\relax % \relax needed
+ \fi
+ \ifdim\scratchdimen>\@@ldmaxheight\relax % todo: totale hoogte
+ \scratchdimen\@@ldmaxheight\relax % \relax needed
+ \fi
+ \ifdim\scratchdimen>\ht\secondpairedbox
+ \setbox\secondpairedbox\vbox to \scratchdimen
+ {\ifnum\pairedlocationa=3 \vss\fi %
+ \box\secondpairedbox
+ \ifnum\pairedlocationa=2 \vss\fi}% \kern\zeropoint
+ \fi
+ \fi
+ \ifcase\pairedlocationa
+ \box\secondpairedbox\hskip\@@lddistance\box\firstpairedbox \or
+ \box\firstpairedbox \hskip\@@lddistance\box\secondpairedbox\or
+ \box\secondpairedbox\endgraf \nointerlineskip \@@ldinbetween \box\firstpairedbox \or
+ \box\firstpairedbox \endgraf \nointerlineskip \@@ldinbetween \box\secondpairedbox\else
+ \fi
+ \egroup}
+
+\def\insidesecondpairedbox
+ {\forgetall
+ \setupalign[\@@ldalign]%
+ \tolerantTABLEbreaktrue % hm.
+ \blank[\v!disable]%
+ \everypar{\begstrut}}
+
+\def\maxoftwoboxdimens#1#2#3%
+ {#1\ifdim#1#2>#1#3 #2\else#3\fi}
+
+\def\valignpairedbox#1#2%
+ {\setbox#1\vbox to #2
+ {\ifcase\pairedlocationb\or\or\or\vss\or\vss\fi
+ \box#1\relax
+ \ifcase\pairedlocationb\or\or\vss\or\or\vss\fi}}
+
+\def\halignpairedbox#1#2%
+ {\setbox#1\hbox to #2
+ {\ifcase\pairedlocationb\or\hss\or\or\or\hss\fi
+ \box#1\relax
+ \ifcase\pairedlocationb\hss\or\or\or\or\hss\fi}}
+
+\definepairedbox[\v!legend]
+
+%D Goody:
+
+\appendtoks
+ \global\resetsystemmode{combination}%
+ \global\resetsystemmode{pairedbox}%
+\to \everyinsidefloat
+
+% todo: \startcombination \startcomb \stopcomb ...
+
+\newcount\horcombination % counter
+\newcount\totcombination
+
+\def\definecombination
+ {\dodoubleempty\dodefinecombination}
+
+\def\dodefinecombination[#1][#2]%
+ {\copyparameters
+ [\??co#1][\??co]
+ [\c!width,\c!height,\c!distance,\c!location,%
+ \c!before,\c!inbetween,\c!after,\c!align,%
+ \c!style,\c!color]%
+ \getparameters
+ [\??co#1][#2]}
+
+\def\setupcombinations
+ {\dodoubleempty\dosetupcombinations}
+
+\def\dosetupcombinations[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??co#1][#2]%
+ \else
+ \getparameters[\??co][#1]%
+ \fi}
+
+\def\combinationparameter#1%
+ {\csname\??co\currentcombination#1\endcsname}%
+
+\def\startcombination
+ {\bgroup % so we can grab a group
+ \dodoubleempty\dostartcombination}
+
+% \startcombination {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[2*1] {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[1*2] {alpha} {a} {beta} {b} \stopcombination
+% \startcombination[2] {alpha} {a} {beta} {b} \stopcombination
+
+\def\dostartcombination[#1][#2]%
+ {\global\setsystemmode{combination}%
+ \doifnothing{#1}\firstargumentfalse % to be sure (when called in macros)
+ \doifnothing{#2}\secondargumentfalse % to be sure (when called in macros)
+ \ifsecondargument
+ \def\currentcombination{#1}%
+ \edef\currentcombinationspec{#2*1*}%
+ \else % better : \doifcombinationelse ... \??co#1\c!location
+ \doifinstringelse{*}{#1}
+ {\let\currentcombination\empty
+ \edef\currentcombinationspec{#1*1*}}
+ {\doifnumberelse{#1}
+ {\let\currentcombination\empty
+ \edef\currentcombinationspec{#1*1*}}
+ {\def\currentcombination{#1}%
+ \edef\currentcombinationspec{2*1*}}}%
+ \fi
+ \forgetall
+ \doifelse{\combinationparameter\c!height}\v!fit
+ \vbox {\vbox to \combinationparameter\c!height}%
+ \bgroup
+ \expanded{\dodostartcombination[\currentcombinationspec]}}
+
+\long\def\dodostartcombination[#1*#2*#3]%
+ {\setuphorizontaldivision
+ [\c!n=\v!fit,\c!distance=\combinationparameter\c!distance]%
+ \global\horcombination#1%
+ \global\totcombination#2%
+ \global\setbox\combinationstack\emptybox
+ \xdef\maxhorcombination{\the\horcombination}%
+ \multiply\totcombination\horcombination
+ \tabskip\zeropoint
+ \doifelse{\combinationparameter\c!width}\v!fit
+ {\halign}{\halign to \combinationparameter\c!width}%
+ \bgroup&%
+ %\hfil##\hfil% now : location={left,top}
+ \expanded{\doifnotinset{\v!left}{\combinationparameter\c!location}}\hfil
+ ##%
+ \expanded{\doifnotinset{\v!right}{\combinationparameter\c!location}}\hfil
+ &\tabskip\zeropoint \!!plus 1fill##\cr
+ \docombination}
+
+\def\docombination % we want to add struts but still ignore an empty box
+ {\dowithnextbox
+ {\setbox0\flushnextbox
+ \dowithnextbox
+ {\setbox2\flushnextbox
+ \dodocombination}%
+ \vtop\bgroup
+ \def\next
+ {\futurelet\nexttoken\nextnext}%
+ \def\nextnext
+ {\ifx\nexttoken\egroup \else % the next box is empty
+ \hsize\wd0
+ \setupalign[\combinationparameter\c!align]%
+ \dostartattributes{\??co\currentcombination}\c!style\c!color\empty
+ \bgroup
+ \aftergroup\endstrut
+ \aftergroup\dostopattributes
+ \aftergroup\egroup
+ \begstrut
+ \fi}%
+ \afterassignment\next\let\nexttoken=}
+ \hbox}
+
+% stupid version, does not align top stuff when captions,
+% keep as example
+%
+% \def\dodocombination
+% {\vbox
+% {\forgetall % \setupwhitespace[\v!none]%
+% \let\next\vbox
+% \ExpandFirstAfter\processallactionsinset
+% [\combinationparameter\c!location]
+% [ \v!top=>\let\next\tbox,
+% \v!middle=>\let\next\halfwaybox]%
+% \next{\copy0}%
+% \ifdim\ht2>\zeropoint % beter dan \wd2, nu \strut mogelijk
+% \combinationparameter\c!inbetween
+% %\vtop % wrong code
+% % {\nointerlineskip % recently added
+% % \hsize\wd0
+% % \setupalign[\combinationparameter\c!align]% % \raggedcenter
+% % \begstrut\unhbox2\endstrut}%
+% \box2
+% \fi}%
+% \ifnum\totcombination>\plusone
+% \global\advance\totcombination\minusone
+% \global\advance\horcombination\minusone
+% \ifnum\horcombination=\zerocount
+% \def\next
+% {\cr\noalign
+% {\forgetall % \setupwhitespace[\v!geen]% no
+% \nointerlineskip
+% \combinationparameter\c!before
+% \combinationparameter\c!after
+% \vss
+% \nointerlineskip}%
+% \global\horcombination\maxhorcombination\relax
+% \docombination}%
+% \else
+% \def\next
+% {&&&\hskip\combinationparameter\c!distance&\docombination}%
+% \fi
+% \else
+% \def\next
+% {\cr\egroup}%
+% \fi
+% \next}
+
+% \def\dodocombination
+% {\vbox
+% {\forgetall % \setupwhitespace[\v!none]%
+% \let\next\vbox
+% \ExpandFirstAfter\processallactionsinset
+% [\combinationparameter\c!plaats]
+% [ \v!top=>\let\next\tbox,
+% \v!middle=>\let\next\halfwaybox]%
+% \next{\copy0}%
+% % we need to save the caption for a next alignment line
+% \saveoncombinationstack2}%
+% \ifnum\totcombination>\plusone
+% \global\advance\totcombination\minusone
+% \global\advance\horcombination\minusone
+% \ifnum\horcombination=\zerocount
+% \def\next
+% {\cr
+% \flushcombinationstack
+% \noalign
+% {\forgetall % \setupwhitespace[\v!none]% no
+% \global\setbox\combinationstack\emptybox
+% \nointerlineskip
+% \combinationparameter\c!after
+% \combinationparameter\c!before
+% \vss
+% \nointerlineskip}%
+% \global\horcombination\maxhorcombination\relax
+% \docombination}%
+% \else
+% \def\next
+% {&&&\hskip\combinationparameter\c!distance&\docombination}%
+% \fi
+% \else
+% \def\next
+% {\cr
+% \flushcombinationstack
+% \egroup}%
+% \fi
+% \next}
+
+\def\depthonlybox
+ {\dowithnextbox{\vtop{\hsize\wd\nextbox\kern\zeropoint\box\nextbox}}\vbox}
+
+% \def\boxwithstrutheight
+% {\dowithnextbox
+% {\scratchdimen\strutheight
+% \advance\scratchdimen-\nextboxht
+% \hbox{\raise\scratchdimen\box\nextbox}}%
+% \vbox}
+
+\def\dodocombination
+ {\vbox
+ {\forgetall % \setupwhitespace[\v!none]%
+ \let\next\vbox
+ \expanded{\processallactionsinset[\combinationparameter\c!location]}
+ [ \v!top=>\let\next\depthonlybox, % \tbox,
+ \v!middle=>\let\next\halfwaybox]%
+ \next{\copy0}%
+ % we need to save the caption for a next alignment line
+ \saveoncombinationstack2}%
+ \ifnum\totcombination>\plusone
+ \global\advance\totcombination\minusone
+ \global\advance\horcombination\minusone
+ \ifnum\horcombination=\zerocount
+ \def\next
+ {\cr
+ \flushcombinationstack
+ \noalign
+ {\forgetall % \setupwhitespace[\v!none]% no
+ \global\setbox\combinationstack\emptybox
+ \nointerlineskip
+ \combinationparameter\c!after
+ \combinationparameter\c!before
+ \vss
+ \nointerlineskip}%
+ \global\horcombination\maxhorcombination\relax
+ \docombination}%
+ \else
+ \def\next
+ {&&&\hskip\combinationparameter\c!distance&\docombination}%
+ \fi
+ \else
+ \def\next
+ {\cr
+ \flushcombinationstack
+ \egroup}%
+ \fi
+ \next}
+
+% formally ok:
+%
+% \def\stopcombination
+% {\egroup
+% \egroup}
+%
+% more robust:
+%
+% \def\stopcombination
+% {{}{}{}{}{}{}{}{}% catches (at most 4) missing entries
+% \egroup
+% \egroup}
+%
+% even better:
+
+\def\stopcombination
+ {{\scratchtoks{{}{}{}}\dorecurse\totcombination{\appendtoks{}{}{}{}\to\scratchtoks}\expandafter}\the\scratchtoks
+ \egroup
+ \egroup}
+
+\newbox\combinationstack
+
+\def\saveoncombinationstack#1%
+ {\global\setbox\combinationstack\hbox
+ {\hbox{\box#1}\unhbox\combinationstack}}
+
+\def\flushcombinationstack
+ {\noalign
+ {\ifdim\ht\combinationstack>\zeropoint
+\nointerlineskip % nieuw
+ \combinationparameter\c!inbetween
+ \global\horcombination\maxhorcombination
+ \globallet\doflushcombinationstack\dodoflushcombinationstack
+ \else
+ \global\setbox\combinationstack\emptybox
+ \globallet\doflushcombinationstack\donothing
+ \fi}%
+ \doflushcombinationstack\crcr}
+
+\gdef\dodoflushcombinationstack
+ {\global\setbox\combinationstack\hbox
+ {\unhbox\combinationstack
+ \global\setbox1\lastbox}%
+ \box1% \ruledhbox{\box1}%
+ \global\advance\horcombination\minusone\relax
+ \ifnum\horcombination>\zerocount
+ \def\next{&&&&\doflushcombinationstack}%
+ \else
+ \global\setbox\combinationstack\emptybox
+ %\let\next\relax
+ \@EA\gobbleoneargument
+ \fi
+ \next}
+
+\setupcombinations
+ [\c!width=\v!fit,
+ \c!height=\v!fit,
+ \c!distance=1em,
+ \c!location=\v!bottom, % can be something {top,left}
+ \c!before=\blank,
+ \c!inbetween={\blank[\v!medium]},
+ \c!style=,
+ \c!color=,
+ \c!after=,
+ \c!align=\v!middle]
+
+%D \macros
+%D {startfloatcombination}
+%D
+%D \setupexternalfigures[directory={../sample}]
+%D \startbuffer
+%D \placefigure
+%D [left,none]
+%D {}
+%D {\startfloatcombination[2*2]
+%D \placefigure{alpha}{\externalfigure[cow.pdf][width=1cm]}
+%D \placefigure{beta} {\externalfigure[cow.pdf][width=2cm]}
+%D \placefigure{gamma}{\externalfigure[cow.pdf][width=3cm]}
+%D \placefigure{delta}{\externalfigure[cow.pdf][width=4cm]}
+%D \stopfloatcombination}
+%D
+%D \input tufte
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+\def\startfloatcombination
+ {\dodoubleempty\dostartfloatcombination}
+
+\def\dostartfloatcombination[#1][#2]%
+ {\vbox\bgroup
+ %\insidecolumnstrue % trick, forces no centering, todo: proper switch/feature
+ \chardef\postcenterfloatmethod\zerocount
+ \forcelocalfloats
+ \def\stopfloatcombination
+ {\scratchtoks\emptytoks
+ \dorecurse\noflocalfloats
+ {\appendetoks{\noexpand\getlocalfloat{\recurselevel}}{}\to\scratchtoks}%
+ \expanded{\startcombination[#1]\the\scratchtoks}\stopcombination
+ \resetlocalfloats
+ \egroup}}
+
+\def\placerelativetoeachother#1#2%
+ {\bgroup
+ \dowithnextbox
+ {\bgroup
+ \setbox0\box\nextbox
+ \dowithnextbox
+ {\setbox2\box\nextbox
+ #1{#2#########2\cr\box0\cr\box2\cr}
+ \egroup
+ \egroup}
+ \hbox}
+ \hbox}
+
+\def\placeontopofeachother{\placerelativetoeachother\halign\hss}
+\def\placesidebyside {\placerelativetoeachother\valign\vss}
+
+% this will be replaced or go away, never used
+
+\def\douseexternalfiles[#1][#2]%
+ {\getparameters
+ [\??fi#1]
+ [\c!file=,
+ \c!bodyfont=,
+ \c!option=,
+ #2]}
+
+\def\useexternalfiles
+ {\dodoubleargument\douseexternalfiles}
+
+\def\dostelexternefilesin[#1][#2]%
+ {\doifundefinedelse{\??fi#1\c!file}
+ {\useexternalfiles[#1][#2]}
+ {\getparameters[\??fi#1][#2]}}
+
+\def\stelexternefilesin
+ {\dodoubleargument\dostelexternefilesin}
+
+\def\verwerkexternefile#1#2#3%
+ {\bgroup
+ \getparameters[\??fi#1][\c!file=,#3]%
+ \doinputonce{\getvalue{\??fi#1\c!file}}%
+ \ExpandFirstAfter\switchtobodyfont[\getvalue{\??fi#1\c!bodyfont}]%
+ \readsysfile{#2} % beter: loc of fix gebied
+ \donothing
+ {\showmessage\m!systems{41}{#2,#1}}%
+ \egroup}
+
+\def\douseexternalfile[#1][#2][#3][#4]%
+ {\stelexternefilesin[#1][]%
+ \doinputonce{\getvalue{\??fi#1\c!file}}%
+ \doifelsenothing{#2}
+ {\setvalue{#3}{\verwerkexternefile{#1}{#3}{#4}}}
+ {\setvalue{#2}{\verwerkexternefile{#1}{#3}{#4}}}}
+
+\def\useexternalfile
+ {\doquadrupleargument\douseexternalfile}
+
+\useexternalfiles
+ [pictex]
+ [\c!bodyfont=\v!small,
+ \c!file=pictex]
+
+\useexternalfiles
+ [table]
+ [\c!file=table]
+
+%D A couple of examples, demonstrating how the depth is
+%D taken care of:
+%D
+%D \startbuffer
+%D test\rotate[frame=on, rotation=0] {gans}%
+%D test\rotate[frame=on, rotation=90] {gans}%
+%D test\rotate[frame=on, rotation=180]{gans}%
+%D test\rotate[frame=on, rotation=270]{gans}%
+%D test
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+% When we rotate over arbitrary angles, we need to relocate the
+% resulting box because rotation brings that box onto the negative
+% axis. The calculations (mostly sin and cosine) need to be tuned for
+% the way a box is packages (i.e. the refence point). A typical example
+% of drawing, scribbling, and going back to the days of school math.
+%
+% We do a bit more calculations than needed, simply because that way
+% it's easier to debug the code.
+
+\def\dododorotatenextbox
+ {\setbox\nextbox\vbox to \@@layerysiz
+ {\vfill
+ \hbox to \@@layerxsiz
+ {\dostartrotation\@@rorotation
+ \nextboxwd\zeropoint
+ \nextboxht\zeropoint
+ \flushnextbox
+ \dostoprotation
+ \hfill}%
+ \kern\@@layerypos}%
+ \setbox\nextbox\hbox
+ {\kern\@@layerxpos
+ \kern\@@layerxoff
+ \lower\@@layeryoff\flushnextbox}}
+
+\def\dodorotatenextbox#1#2% quite some trial and error -)
+ {\dontshowcomposition
+ \dontcomplain
+ \ifnum#2=\plusfour
+ % new, location=middle
+ \!!widthb \nextboxwd
+ \!!heightb\nextboxht
+ \!!depthb \nextboxdp
+ \setbox\nextbox\vbox{\vskip.5\nextboxht\hskip-.5\nextboxwd\flushnextbox}%
+ \smashbox\nextbox
+ \fi
+ \!!widtha \nextboxwd
+ \!!heighta\nextboxht
+ \!!deptha \nextboxdp
+ \!!doneafalse
+ \!!donebfalse
+ \ifcase#2\or
+ % 1: fit
+ \or
+ % 2: depth, not fit
+ \!!doneatrue
+ \!!donebtrue
+ \or
+ % 3: depth, fit
+ \!!donebtrue
+ \fi
+ \setbox\nextbox\vbox{\hbox{\raise\nextboxdp\flushnextbox}}%
+ \!!dimena \nextboxht
+ \setcalculatedcos\cos\@@rorotation
+ \setcalculatedsin\sin\@@rorotation
+ \@@layerxpos\zeropoint
+ \@@layerypos\zeropoint
+ \@@layerxoff\zeropoint
+ \@@layeryoff\zeropoint
+ \ifdim\sin\points>\zeropoint
+ \ifdim\cos\points>\zeropoint
+ \@@layerxsiz \cos\!!widtha
+ \@@layerysiz \sin\!!widtha
+ \advance\@@layerxsiz \sin\!!dimena
+ \advance\@@layerysiz \cos\!!dimena
+ \@@layerypos \cos\!!dimena
+ \if!!donea
+ \@@layerxoff \negated\sin\!!dimena
+ \advance\@@layerxoff \sin\!!deptha
+ \fi
+ \if!!doneb
+ \@@layeryoff \cos\!!deptha
+ \fi
+ \dododorotatenextbox
+ \else
+ \@@layerxsiz \negated\cos\!!widtha
+ \@@layerysiz \sin\!!widtha
+ \advance\@@layerxsiz \sin\!!dimena
+ \advance\@@layerysiz \negated\cos\!!dimena
+ \@@layerxpos \negated\cos\!!widtha
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \sin\!!deptha
+ \fi
+ \if!!doneb
+ \@@layeryoff \negated\cos\!!heighta
+ \fi
+ \dododorotatenextbox
+ \wd\nextbox\if!!donea\sin\!!deptha\else\@@layerxsiz\fi
+ \fi
+ \else
+ \ifdim\cos\points<\zeropoint
+ \@@layerxsiz \negated\cos\!!widtha
+ \@@layerysiz \negated\sin\!!widtha
+ \advance\@@layerxsiz \negated\sin\!!dimena
+ \advance\@@layerysiz \negated\cos\!!dimena
+ \@@layerxpos \@@layerxsiz
+ \@@layerypos \negated\sin\!!widtha
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \negated\sin\!!heighta
+ \fi
+ \if!!doneb
+ \@@layeryoff \@@layerysiz
+ \advance\@@layeryoff \cos\!!deptha
+ \fi
+ \dododorotatenextbox
+ \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
+ \else
+ \@@layerxsiz \cos\!!widtha
+ \@@layerysiz \negated\sin\!!widtha
+ \advance\@@layerxsiz \negated\sin\!!dimena
+ \advance\@@layerysiz \cos\!!dimena
+ \ifdim\sin\points=\zeropoint
+ \@@layerxpos \zeropoint
+ \@@layerxoff \zeropoint
+ \@@layerypos \@@layerysiz
+ \if!!doneb
+ \@@layeryoff \!!deptha
+ \fi
+ \else
+ \@@layerypos \@@layerysiz
+ \@@layerxpos \negated\sin\!!dimena
+ \if!!donea
+ \@@layerxoff -\@@layerxsiz
+ \advance\@@layerxoff \negated\sin\!!heighta
+ \fi
+ \if!!doneb
+ \@@layeryoff \negated\sin\!!deptha
+ \fi
+ \fi
+ \dododorotatenextbox
+ \ifdim\sin\points=\zeropoint
+ \else
+ \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
+ \fi
+ \fi
+ \fi
+ % new, location=middle
+ \ifnum#2=\plusfour
+ \setbox\nextbox\vbox{\vskip-.5\!!heightb\hskip.5\!!heightb\flushnextbox}%
+ \nextboxwd\!!widthb
+ \nextboxht\!!heightb
+ \nextboxdp\!!depthb
+ \fi}
+
+\def\dorotatenextbox#1#2%
+ {\doifsomething{#1}
+ {\edef\@@rorotation{\realnumber{#1}}% get rid of leading zeros and spaces
+ \setbox\nextbox\vbox{\flushnextbox}% not really needed
+ \dodorotatenextbox\@@rorotation#2}%
+ \hbox{\boxcursor\flushnextbox}}
+
+\def\dodorotatebox#1% {angle} \hbox/\vbox/\vtop
+ {\bgroup\hbox\bgroup % compatibility hack
+ \dowithnextbox
+ {\dorotatenextbox{#1}\plusone
+ \egroup\egroup}}
+
+\def\dorotatebox#1% {angle} \hbox/\vbox/\vtop
+ {\ifcase#1\relax
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\dodorotatebox
+ \fi{#1}}
+
+\unexpanded\def\rotate % \bgroup: \rotate kan argument zijn
+ {\bgroup\complexorsimpleempty\rotate}
+
+% \def\complexrotate[#1]% framed met diepte !
+% {\getparameters[\??ro][#1]%
+% \processaction
+% [\@@rolocation]
+% [ \v!depth=>\!!counta\plusthree\donefalse,% depth fit - raw box
+% \v!fit=>\!!counta\plustwo \donefalse,% depth tight - raw box
+% \v!broad=>\!!counta\plusone \donefalse,% nodepth fit - raw box
+% \v!high=>\!!counta\plusone \donetrue ,% nodepth fit - framed
+% \v!middle=>\!!counta\plusfour \donefalse,% centered, keep dimensions
+% \s!default=>\!!counta\plusthree\donetrue ,% depth fit - framed
+% \s!unknown=>\!!counta\plusthree\donetrue ]% depth fit - framed
+% \ifdone
+% \def\docommand{\localframed[\??ro][#1,\c!location=]}%
+% \else
+% \let\docommand\relax
+% \fi
+% \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
+
+\setvalue{\??ro::\c!location::\v!depth }{\!!counta\plusthree\donefalse} % depth fit - raw box
+\setvalue{\??ro::\c!location::\v!fit }{\!!counta\plustwo \donefalse} % depth tight - raw box
+\setvalue{\??ro::\c!location::\v!broad }{\!!counta\plusone \donefalse} % nodepth fit - raw box
+\setvalue{\??ro::\c!location::\v!high }{\!!counta\plusone \donetrue } % nodepth fit - framed
+\setvalue{\??ro::\c!location::\v!middle }{\!!counta\plusfour \donefalse} % centered, keep dimensions
+\setvalue{\??ro::\c!location::\v!default}{\!!counta\plusthree\donetrue } % depth fit - framed
+
+\def\complexrotate[#1]% framed met diepte !
+ {\getparameters[\??ro][#1]%
+ \executeifdefined{\??ro::\c!location::\@@rolocation}{\!!counta\plusthree\donetrue}%
+ \ifdone
+ \def\docommand{\localframed[\??ro][#1,\c!location=]}%
+ \else
+ \let\docommand\relax
+ \fi
+ \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
+
+\presetlocalframed[\??ro]
+
+\def\setuprotate
+ {\dodoubleargument\getparameters[\??ro]}
+
+\setuprotate
+ [\c!rotation=90,
+ \c!location=\v!normal,
+ \c!width=\v!fit,
+ \c!height=\v!fit,
+ \c!offset=\v!overlay,
+ \c!frame=\v!off]
+
+% \dostepwiserecurse{0}{360}{10}
+% {\startlinecorrection[blank]
+% \hbox
+% {\expanded{\setuprotate[rotation=\recurselevel]}%
+% \traceboxplacementtrue
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=depth] {\ruledhbox{\bfb (depth)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=fit] {\ruledhbox{\bfb (fit)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=broad] {\ruledhbox{\bfb (broad)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=normal]{\ruledhbox{\bfb (normal)}}}}%
+% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=high] {\ruledhbox{\bfb (high)}}}}}
+% \stoplinecorrection}
+
+% to be used in some other places! todo!
+%
+% divides \hsize in fractions, will be made a bit more
+% clever and advanced when needed
+%
+% \horizontaldivision[n/m,elements,distance]
+%
+% \horizontaldivision[2/5,3,1em]
+% \horizontaldivision[2/5,3,1em]
+% \horizontaldivision[1/5,3,1em]
+%
+% \setuphorizontaldivision[afstand=,aantal=] (passend,passend)
+
+\def\??fr{@@fr}
+
+\def\setuphorizontaldivision
+ {\dodoubleargument\getparameters[\??fr]}
+
+\def\horizontaldivision
+ {\dosingleargument\dohorizontaldivision}
+
+\def\dohorizontaldivision[#1]%
+ {\dodohorizontaldivision[#1,,,,,,]}
+
+\def\dodohorizontaldivision[#1/#2,#3,#4,#5]%
+ {\doifelsenothing{#3}
+ {\doifelse\@@frn\v!fit
+ {\!!counta#2\relax}
+ {\!!counta\@@frn\relax}}
+ {\!!counta#3\relax}%
+ \doifelsenothing{#4}
+ {\doifelse\@@frdistance\v!fit
+ {\!!widtha\zeropoint}
+ {\!!widtha\@@frdistance}}
+ {\!!widtha#4}%
+ \advance\!!counta \minusone
+ \multiply\!!widtha \!!counta
+ \advance\hsize -\!!widtha
+ \divide\hsize #2\relax
+ \hsize#1\hsize}
+
+\setuphorizontaldivision
+ [\c!distance=\tfskipsize,
+ \c!n=\v!fit]
+
+%D This one is for Daniel Pittman, who wanted tight
+%D fractions. We show three versions. First the simple
+%D one using \type {\low} and \type {high}:
+%D
+%D \startbuffer
+%D \def\vfrac#1#2%
+%D {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}
+%D
+%D test \vfrac{1}{2} test \vfrac{123}{456} test
+%D \stopbuffer
+%D
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D A better way to handle the kerning is the following, here
+%D we kind of assume that tye slash is symmetrical and has
+%D nearly zero width.
+%D
+%D \startbuffer
+%D \def\vfract#1#2%
+%D {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}
+%D \stopbuffer
+%D
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D The third and best alternative is the following:
+%D
+%D {\showmakeup\getbuffer}\crlf\getbuffer
+%D
+%D This time we measure the height of the \type {/} and
+%D shift over the maximum height and depths of this
+%D character and the fractional digits (we use 57 as
+%D sample). Here we combine all methods in one macros.
+
+\chardef\vulgarfractionmethod=3
+
+\definehspace[vulgarfraction][.25em] % [.15em]
+\definesymbol[vulgarfraction][/] % [\raise.2ex\hbox{/}]
+
+\unexpanded\def\vulgarfraction#1#2%
+ {\dontleavehmode
+ \hbox
+ {\def\vulgarfraction{vulgarfraction}%
+ \ifcase\vulgarfractionmethod
+ #1\symbol[\vulgarfraction]#2%
+ \or
+ \high{\tx#1\kern-\hspaceamount\empty\vulgarfraction}%
+ \symbol[\vulgarfraction]%
+ \low {\kern-\hspaceamount\empty\vulgarfraction\tx#2}%
+ \or
+ \high{\tx#1}%
+ \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
+ \low{\tx#2}%
+ \or
+ \setbox0\hbox{\symbol[\vulgarfraction]}%
+ \setbox2\hbox{\txx57}%
+ \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
+ \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
+ \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
+ \fi}}
+
+\ifx\vfrac\undefined \let\vfrac\vulgarfraction \fi
+
+%D \starttabulate
+%D \HL
+%D \NC \bf method \NC \bf visualization \NC\NR
+%D \HL
+%D \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR
+%D \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR
+%D \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR
+%D \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR
+%D \HL
+%D \stoptabulate
+
+%D Under construction:
+%D
+%D \starttyping
+%D \commalistsentence[aap,noot,mies]
+%D \commalistsentence[aap,noot]
+%D \commalistsentence[aap]
+%D \commalistsentence[a,b,c]
+%D \commalistsentence[a,b,c][{ \& },{ and }]
+%D \commalistsentence[a,b,c][+,-]
+%D \stoptyping
+
+\let\handlecommalistsentence\firstofoneargument
+
+\def\commalistsentenceone{and-1}
+\def\commalistsentencetwo{and-2}
+
+\def\commalistsentence
+ {\dodoubleempty\docommalistsentence}
+
+\def\docommalistsentence[#1][#2]%
+ {\bgroup
+ \getfromcommalist[#2][1]%
+ \ifx\commalistelement\empty
+ \def\@@commalistsentenceone{\labeltext\commalistsentenceone}%
+ \else
+ \let\@@commalistsentenceone\commalistelement
+ \fi
+ \getfromcommalist[#2][2]%
+ \ifx\commalistelement\empty
+ \def\@@commalistsentencetwo{\labeltext\commalistsentencetwo}%
+ \else
+ \let\@@commalistsentencetwo\commalistelement
+ \fi
+ \getcommalistsize[#1]%
+ \ifcase\commalistsize\relax
+ \def\serializedcommalist{#1}%
+ \else
+ \let\serializedcommalist\empty
+ \scratchcounter\zerocount
+ \def\docommand##1%
+ {\advance\scratchcounter \plusone
+ \ifnum\scratchcounter=\plusone
+ \scratchtoks{\handlecommalistsentence{##1}}%
+ \else
+ \ifnum\scratchcounter=\commalistsize
+ \appendtoks\@@commalistsentencetwo\handlecommalistsentence{##1}\to\scratchtoks
+ \else
+ \appendtoks\@@commalistsentenceone\handlecommalistsentence{##1}\to\scratchtoks
+ \fi
+ \fi}%
+ \processcommacommand[#1]\docommand
+ \edef\serializedcommalist{\the\scratchtoks}%
+ \fi
+ \serializedcommalist
+ \egroup}
+
+\def\commacommandsentence[#1]{\@EA\commalistsentence\@EA[#1]}
+
+\ifx\textcomma\undefined \def\textcomma{,} \fi
+
+\setuplabeltext [\s!nl] [and-1=\textcomma\ , and-2= en ]
+\setuplabeltext [\s!en] [and-1=\textcomma\ , and-2=\textcomma\ and ]
+\setuplabeltext [\s!de] [and-1=\textcomma\ , and-2= und ]
+
+%D \macros
+%D {somekindoftab}
+%D
+%D This macro can be used to create tabs:
+%D
+%D \starttyping
+%D \setupheadertexts[{\somekindoftab[alternative=horizontal]{\framed{\realfolio}}}]
+%D \setuptexttexts [{\somekindoftab[alternative=vertical] {\framed{\realfolio}}}]
+%D
+%D \starttext
+%D \showframe \dorecurse{10}{test\page}
+%D \stoptext
+%D \stoptyping
+
+\def\somekindoftab
+ {\dosingleempty\dosomekindoftab}
+
+\def\dosomekindoftab[#1]%
+ {\bgroup
+ \getparameters[xx]
+ [\c!alternative=\v!vertical,
+ \c!width=\textwidth,\c!height=\textheight,
+ \c!n=\lastpage,\c!m=\realpageno,
+ #1]%
+ \doifelse\xxalternative\v!vertical
+ {\dodosomekindoftab\vbox\vskip\xxheight}
+ {\dodosomekindoftab\hbox\hskip\xxwidth }}
+
+\def\dodosomekindoftab#1#2#3#4%
+ {#1 to #3 \bgroup
+ \forgetall
+ \ifnum\xxm>\plusone
+ #2\zeropoint \!!plus \the\numexpr\xxm -1\relax fill\relax
+ \fi
+ #4%
+ \ifnum\xxm<\xxn\relax
+ #2\zeropoint \!!plus \the\numexpr\xxn-\xxm\relax fill\relax
+ \fi
+ \egroup
+ \egroup}
+
+\protect \endinput
diff --git a/tex/context/base/core-mis.tex b/tex/context/base/core-mis.tex
deleted file mode 100644
index de1da7597..000000000
--- a/tex/context/base/core-mis.tex
+++ /dev/null
@@ -1,2733 +0,0 @@
-%D \module
-%D [ file=core-mis,
-%D version=1998.01.29,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Miscelaneous,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Misc Commands}
-
-% todo: kleur in legenda + letter
-
-% Obsolete
-%
-% \startmessages dutch library: systems
-% title: systeem
-% 3: probeer LaTeX eens
-% \stopmessages
-%
-% \startmessages english library: systems
-% title: system
-% 3: try LaTeX
-% \stopmessages
-%
-% \startmessages german library: systems
-% title: system
-% 3: Versuche LaTeX
-% \stopmessages
-%
-% \startmessages czech library: systems
-% title: system
-% 3: zkuste LaTeX
-% \stopmessages
-%
-% \startmessages italian library: systems
-% title: sistema
-% 3: provare LaTeX
-% \stopmessages
-%
-% \startmessages norwegian library: systems
-% title: system
-% 3: forsker LaTeX
-% \stopmessages
-%
-% \startmessages romanian library: systems
-% title: sistem
-% 3: incercati LaTeX
-% \stopmessages
-%
-
-% %D You would not expect the next macro in \CONTEXT,
-% %D wouldn't you? It's there to warn \LATEX\ users that
-% %D something is wrong.
-% %D
-% %D Obsolete now:
-% %
-% % \def\documentstyle{\showmessage\m!systems3\empty\stoptekst}
-% %
-% % \let\documentclass=\documentstyle
-% %D \macros
-% %D {simplifiedcommands, simplifycommands}
-% %D
-% %D I first needed this simplification in bookmarks. Users can
-% %D add their own if needed.
-
-\unprotect
-
-%D Sometimes (for instance in bookmarks) we need to simplify macro
-%D behaviour, so here is the hook.
-
-\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
-
-\def\simplifycommands{\the\simplifiedcommands}
-
-%D A possibly growing list:
-
-%appendtoks \def\executesynonym#1#2#3#4{#3}\to\simplifiedcommands
-%appendtoks \def\executesort#1#2#3{#3}\to\simplifiedcommands
-
-\appendtoks \def\ { }\to\simplifiedcommands
-\appendtoks \def\type#1{\string\\\strippedcsname#1}\to\simplifiedcommands
-\appendtoks \def\tex#1{\string\\#1}\to\simplifiedcommands
-\appendtoks \def\TeX{TeX}\to\simplifiedcommands
-\appendtoks \def\ConTeXt{ConTeXt}\to\simplifiedcommands
-\appendtoks \def\MetaPost{MetaPost}\to\simplifiedcommands
-\appendtoks \def\MetaFont{MetaFont}\to\simplifiedcommands
-\appendtoks \def\MetaFun{MetaFun}\to\simplifiedcommands
-%appendtoks \def||{-}\to\simplifiedcommands
-\appendtoks \def|#1|{\ifx#1\empty\empty-\else#1\fi}\to\simplifiedcommands
-
-\appendtoks\let\buildtextaccent\secondoftwoarguments\to\simplifiedcommands
-
-% THIS WAS MAIN-002.TEX
-
-%\def\checkinterlineskip
-% {\ifvmode
-% \ifdim\lastskip>\zeropoint
-% \nointerlineskip
-% \else\ifdim\lastkern>\zeropoint
-% \nointerlineskip
-% \fi\fi
-% \fi}
-
-\def\horitems#1#2% #1=breedte #2=commandos
- {\scratchdimen#1%
- \divide\scratchdimen \nofitems
- \!!counta\zerocount
- \def\docommand##1%
- {\advance\!!counta \plusone
- \processaction
- [\@@isalign]
- [ \v!left=>\hbox to \scratchdimen{\strut##1\hss},
- \v!right=>\hbox to \scratchdimen{\hss\strut##1},
- \v!middle=>\hbox to \scratchdimen{\hss\strut##1\hss},
- \v!margin=>\ifnum\!!counta=\plusone\hss\else\hfill\fi
- \strut##1%
- \ifnum\!!counta=\nofitems\hss\else\hfill\fi,
- \s!default=>\hbox to \scratchdimen{\hss\strut##1\hss}, % midden
- \s!unknown=>\hbox to \scratchdimen{\strut##1\hss}]}% % links
- \hbox to #1{\hss#2\hss}}
-
-\def\veritems#1#2% #1=breedte #2=commandos
- {\scratchdimen#1%
- \def\docommand##1%
- {\ifdim\scratchdimen<\zeropoint % the - was a signal
- \hbox to -\scratchdimen{\hss\strut##1}%
- \else\ifdim\scratchdimen>\zeropoint
- \hbox to \scratchdimen{\strut##1\hss}%
- \else
- \hbox{\strut##1}%
- \fi\fi}%
- \vbox{#2}}
-
-\def\dosetupitems[#1]%
- {\getparameters[\??is][#1]%
- \doif\@@iswidth\v!unknown
- {\def\@@iswidth{\hsize}}%
- \doifconversiondefinedelse\@@issymbol
- {\def\doitembullet##1{\convertnumber{\@@issymbol}{##1}}}
- {\doifsymboldefinedelse\@@issymbol
- {\def\doitembullet##1{\symbol[\@@issymbol]}}{}}}
-
-\def\makeitemsandbullets#1%
- {\doifelse\@@isn\v!unknown
- {\getcommalistsize[#1]%
- \edef\nofitems{\commalistsize}}
- {\edef\nofitems{\@@isn}}%
- \setbox0\hbox
- {\doitems \@@iswidth
- {\processcommalist[#1]\docommand}}%
- \setbox2\hbox
- {\doitems \@@isbulletbreedte
- {\dorecurse\nofitems
- {\docommand{\strut\doitembullet\recurselevel}}}}}
-
-\def\dostartitems#1#2#3%
- {\let\doitems#2%
- \def\@@isbulletbreedte{#3}%
- \makeitemsandbullets{#1}%
- \@@isbefore}
-
-\def\dostopitems
- {\@@isafter
- \egroup}
-
-\setvalue{doitems\v!top}#1%
- {\dostartitems{#1}\horitems\@@iswidth
- \noindent\vbox
- {\forgetall
- \doifsomething\@@issymbol
- {\doifnot\@@issymbol\v!none
- {\box2
- \@@isinbetween
- \nointerlineskip}}%
- \box0}%
- \dostopitems}
-
-\setvalue{doitems\v!bottom}#1%
- {\dostartitems{#1}\horitems\@@iswidth
- \noindent\vbox
- {\forgetall
- \box0
- \doifsomething\@@issymbol
- {\@@isinbetween
- \nointerlineskip
- \box2}}%
- \dostopitems}
-
-\setvalue{doitems\v!inmargin}#1%
- {\dostartitems{#1}\veritems{-1.5em}% - is a signal
- \noindent\hbox{\llap{\box2\hskip\leftmargindistance}\box0}%
- \dostopitems}
-
-\setvalue{doitems\v!left}#1%
- {\advance\hsize -1.5em%
- \dostartitems{#1}\veritems{1.5em}%
- \noindent\hbox{\box2\box0}%
- \dostopitems}
-
-\setvalue{doitems\v!right}#1%
- {\dostartitems{#1}\veritems{0em}%
- \noindent\hbox{\box0\hskip-\wd2\box2}%
- \dostopitems}
-
-\def\setupitems
- {\dosingleargument\dosetupitems}
-
-\def\complexitems[#1]%
- {\bgroup
- \setupitems[#1]%
- \parindent\zeropoint
- \setlocalhsize
- \hsize\localhsize
- \dontcomplain
- %\doifundefined{doitems\@@islocation}%
- % {\let\@@islocation\v!left}%
- %\getvalue{doitems\@@islocation}}
- \executeifdefined{doitems\@@islocation}{\let\@@islocation\v!left}}
-
-\definecomplexorsimpleempty\items
-
-\setupitems
- [\c!location=\v!left,
- \c!symbol=5,
- \c!width=\hsize,
- \c!align=\v!middle,
- \c!n=\v!unknown,
- \c!before=\blank,
- \c!inbetween={\blank[\v!medium]},
- \c!after=\blank]
-
-% Te zijner tijd [plaats=boven,onder,midden] implementeren,
-% in dat geval moet eerst de maximale hoogte worden bepaald.
-%
-% Overigens kan een en ander mooier met \halign.
-
-% there is quite some historic balast in this mechanism, the next variant
-% is a first cleanup
-
-\let\currentparagraph\empty
-
-\newcount\alcounter \newcount\alnsize \newdimen\alhsize
-
-\def\paragraphparameter#1% \checkedparameter\??al\currentparagraph#1
- {\executeifdefined{\??al\currentparagraph#1}{\executeifdefined{\??al#1}\empty}}
-
-\def\paragraphcellmeter#1#2% \checkedparameter\??al\currentparagraph#1
- {\executeifdefined{\??al\currentparagraph\number#1#2}{\paragraphparameter{#2}}}
-
-\def\dodefineparagraphs[#1][#2]%
- {\edef\currentparagraph{#1}%
- \setvalue{\s!do\s!next\currentparagraph}%
- {\def\\{\getvalue\currentparagraph}}%
- \setvalue\currentparagraph
- {\getvalue{\s!do\s!next#1}%
- \dostartparagraphs{#1}}%
- \setvalue{\e!next\currentparagraph}%
- {\getvalue{#1}}%
- \setvalue{\e!start\currentparagraph}%
- {\bgroup
- \edef\currentparagraph{#1}%
- \letvalue{\s!do\s!next\currentparagraph}\empty
- \setvalue{\e!stop\currentparagraph}{\getvalue\currentparagraph\egroup}%
- \getvalue\currentparagraph}%
- \getparameters[\??al\currentparagraph]%
- [%\c!n=3,
- %\c!before=\blank,
- %\c!after=\blank,
- %\c!distance=1em,
- %\c!height=\v!fit,
- %\c!rule=\v!off,
- %\c!command=,
- %\c!align=,
- %\c!tolerance=\v!tolerant,
- %\c!rulethickness=\linewidth,
- %\c!rulecolor=,
- %\c!style=,
- %\c!color=,
- %\c!top=,
- %\c!top=\vss,
- %\c!bottom=\vfill,
- #2]%
- \setvalue{\e!setup#1\e!endsetup}%
- {\setupparagraphs[#1]}%
- \dorecurse
- {\paragraphparameter\c!n}
- {\setupparagraphs
- [\currentparagraph]
- [\recurselevel]
- [\c!width=,
- %\c!bottom=\paragraphparameter\c!bottom,
- %\c!top=\paragraphparameter\c!top,
- %\c!height=\paragraphparameter\c!height,
- %\c!rule=\paragraphparameter\c!rule,
- %\c!rulethickness=\paragraphparameter\c!rulethickness,
- %\c!rulecolor=\paragraphparameter\c!rulecolor,
- %\c!align=\paragraphparameter\c!align,
- %\c!tolerance=\paragraphparameter\c!tolerance, % obsolete
- %\c!distance=\paragraphparameter\c!distance,
- \c!style=\paragraphparameter\c!style,
- \c!color=\paragraphparameter\c!color]}%
- \setupparagraphs[\currentparagraph][1][\c!distance=\zeropoint]}
-
-\def\defineparagraphs
- {\dodoubleargument\dodefineparagraphs}
-
-\def\dosetupparagraphs[#1][#2][#3]%
- {\edef\currentparagraph{#1}%
- \ifsecondargument
- \doifelse{#2}\v!each
- {\dorecurse
- {\paragraphparameter\c!n}
- {\getparameters[\??al\currentparagraph\recurselevel][#3]}}
- {\doifelsenothing{#3}
- {\getparameters[\??al\currentparagraph][#2]}
- {\def\docommand##1{\getparameters[\??al\currentparagraph##1][#3]}%
- \processcommalist[#2]\docommand}}%
- \else
- \getparameters[\??al][#1]%
- \fi}
-
-\def\setupparagraphs
- {\dotripleempty\dosetupparagraphs}
-
-\setupparagraphs
- [\c!n=3,
- \c!before=\blank,
- \c!after=\blank,
- \c!distance=1em,
- \c!height=\v!fit,
- \c!rule=\v!off,
- \c!command=,
- \c!align=,
- \c!tolerance=\v!tolerant, % obsolete
- \c!rulethickness=\linewidth,
- \c!rulecolor=,
- \c!style=,
- \c!color=,
- \c!top=,
- \c!top=\vss,
- \c!bottom=\vfill]
-
-\def\doparagraphrule
- {\doifelse{\paragraphcellmeter\alcounter\c!rule}\v!on
- {\linewidth\paragraphcellmeter\alcounter\c!rulethickness
- \scratchdimen\paragraphcellmeter\alcounter\c!distance
- \advance\scratchdimen-\linewidth
- \divide\scratchdimen \plustwo
- \hskip\scratchdimen
- \color[\paragraphcellmeter\alcounter\c!rulecolor]{\vrule\!!width\linewidth}%
- \hskip\scratchdimen}
- {\hskip\paragraphcellmeter\alcounter\c!distance}}
-
-\def\dostartparagraph
- {\doifelsenothing{\paragraphcellmeter\alcounter\c!width}
- {\!!widtha\alhsize
- \divide\!!widtha \alnsize}
- {\!!widtha\paragraphcellmeter\alcounter\c!width}%
- \dostartattributes{\??al\currentparagraph\number\alcounter}\c!style\c!color\empty
- \doifelse{\paragraphcellmeter\alcounter\c!height}\v!fit
- {\setbox\scratchbox\vtop}
- {\setbox\scratchbox\vtop to \paragraphcellmeter\alcounter\c!height}%
- \bgroup
- \blank[\v!disable]%
- \forgetall
- \paragraphcellmeter\alcounter\c!top
- \paragraphparameter\c!inner
- \hsize\!!widtha % setting \wd afterwards removed
- \paragraphcellmeter\alcounter\c!inner % twice
- \expanded{\setupalign [\paragraphcellmeter\alcounter\c!align ]}% {normal,verytolerant,stretch}
- \expanded{\setuptolerance[\paragraphcellmeter\alcounter\c!tolerance]}% obsolete
- \ignorespaces
- \endgraf
- \ignorespaces
- %
- % Nadeel van de onderstaande constructie is dat \everypar
- % binnen een groep kan staan en zo steeds \begstruts
- % worden geplaatst. Mooi is anders dus moet het anders!
- %
- % Hier is \Everypar niet nodig.
- %
- \everypar{\begstrut\everypar\emptytoks}%
- %
- \nospace % remove + ignore
- \paragraphcellmeter\alcounter\c!command}
-
-\def\dostopparagraph
- {\ifvmode
- \removelastskip
- \else
- \unskip\endstrut\endgraf
- \fi
- \paragraphcellmeter\alcounter\c!bottom
- \egroup
- \ifdim\wd\scratchbox=\zeropoint % no data
- \wd\scratchbox\!!widtha
- \fi
- \box\scratchbox
- \dostopattributes
- \ifnum\alcounter<\paragraphparameter\c!n\relax
- \@EA\doparagraphcell
- \else
- \@EA\dostopparagraphs
- \fi}
-
-\def\doparagraphcell
- {\global\advance\alcounter \plusone
- \doifelsenothing{\paragraphcellmeter\alcounter\c!distance}
- {\ifnum\alcounter=\plusone\else
- \hskip\paragraphparameter\c!distance
- \fi}
- {\ifnum\alcounter=\plusone
- \hskip\paragraphcellmeter\alcounter\c!distance
- \else
- \doparagraphrule
- \fi}%
- \letvalue\currentparagraph\dostopparagraph
- \dostartparagraph}
-
-\def\dostartparagraphs#1%
- {\bgroup
- \edef\currentparagraph{#1}%
- \global\alcounter\zerocount
- \parindent\zeropoint
- \setlocalhsize
- \alhsize\localhsize
- \alnsize\paragraphparameter\c!n\relax
- \dorecurse \alnsize
- {\doifelsenothing{\paragraphcellmeter\recurselevel\c!distance}
- {\ifnum\recurselevel=\plusone\else
- \global\advance\alhsize -\paragraphparameter\c!distance
- \fi}
- {\global\advance\alhsize -\paragraphcellmeter\recurselevel\c!distance}%
- \doifsomething{\paragraphcellmeter\recurselevel\c!width}
- {\global\advance\alnsize \minusone
- \global\advance\alhsize -\paragraphcellmeter\recurselevel\c!width}}%
- %whitespace % gaat fout bij \framed
- \paragraphparameter\c!before
- \leavevmode % gaat wel goed bij \framed, brrr
- \setbox\scratchbox\vbox\bgroup\hbox\bgroup\doparagraphcell}
-
-\def\dostopparagraphs
- {\egroup
- \egroup
- \iftrue
- \hbox{\raise\strutheight\box\scratchbox}% new
- \else
- \box\scratchbox % old
- \fi
- \par
- \paragraphparameter\c!after
- \egroup}
-
-\def\dosetuptab[#1]%
- {\getparameters[\??ta]
- [\c!headstyle=\v!normal,
- \c!headcolor=,
- \c!style=\v!normal,
- \c!color=,
- \c!width=\v!broad,
- \c!sample={\hskip4em},
- \c!before=,
- \c!after=,
- #1]%
- \definedescription
- [tab]
- [\c!headstyle=\@@taheadstyle,
- \c!headcolor=\@@tacolor,
- \c!sample=\@@tasample,
- \c!width=\@@tawidth,
- \c!before=\@@tabefore,
- \c!after=\@@taafter]}
-
-\def\setuptab
- {\dosingleargument\dosetuptab}
-
-\setuptab
- [\c!location=\v!left]
-
-% The following macro's are derived from PPCHTEX and
-% therefore take some LaTeX font-switching into account.
-
-\newif\ifloweredsubscripts
-
-% Due to some upward incompatibality of LaTeX to LaTeX2.09
-% and/or LaTeX2e we had to force \@@chemieletter. Otherwise
-% some weird \nullfont error comes up.
-
-\doifundefined{@@chemieletter}{\def\@@chemieletter{\rm}}
-
-\def\beginlatexmathmodehack
- {\ifmmode
- \let\endlatexmathmodehack\relax
- \else
- \def\endlatexmathmodehack{$}$\@@chemieletter
- \fi}
-
-\def\setsubscripts
- {\beginlatexmathmodehack
- \def\dosetsubscript##1##2##3%
- {\dimen0=##3\fontexheight##2%
- \setxvalue{@@\string##1\string##2}{\the##1##2\relax}%
- ##1##2=\dimen0\relax}%
- \def\dodosetsubscript##1##2%
- {\dosetsubscript{##1}{\textfont2}{##2}%
- \dosetsubscript{##1}{\scriptfont2}{##2}%
- \dosetsubscript{##1}{\scriptscriptfont2}{##2}}%
- %dodosetsubscript\mathsupnormal {?}%
- \dodosetsubscript\mathsubnormal {.7}%
- \dodosetsubscript\mathsubcombined{.7}%
- \global\loweredsubscriptstrue
- \endlatexmathmodehack}
-
-\def\resetsubscripts
- {\ifloweredsubscripts
- \beginlatexmathmodehack
- \def\doresetsubscript##1##2%
- {\dimen0=\getvalue{@@\string##1\string##2}\relax
- ##1##2=\dimen0}%
- \def\dodoresetsubscript##1%
- {\doresetsubscript{##1}{\textfont2}%
- \doresetsubscript{##1}{\scriptfont2}%
- \doresetsubscript{##1}{\scriptscriptfont2}}%
- %dodoresetsubscript\mathsupnormal
- \dodoresetsubscript\mathsubnormal
- \dodoresetsubscript\mathsubcombined
- \global\loweredsubscriptsfalse
- \endlatexmathmodehack
- \fi}
-
-\let\beginlatexmathmodehack = \relax
-\let\endlatexmathmodehack = \relax
-
-\def\chem#1#2#3%
- {\bgroup
- \setsubscripts
- \mathematics{\hbox{#1}_{#2}^{#3}}%
- \resetsubscripts
- \egroup}
-
-\unexpanded\def\celsius #1{#1\mathematics{^\circ}C}
-\unexpanded\def\inch {\mathematics{\prime\prime}} % was: \hbox{\rm\char125\relax}
-\unexpanded\def\fraction#1#2{\mathematics{#1\over#2}}
-
-% very dutch
-
-\unexpanded\def\graden {\mathematics{^\circ}}
-
-\def\bedragprefix {\euro\normalfixedspace}
-\def\bedragsuffix {}
-\def\bedragempty {\euro}
-
-\unexpanded\def\bedrag#1%
- {\strut\hbox\bgroup
- \let\normalfixedspace\nonbreakablespace
- \doifelsenothing{#1}
- {\bedragempty}
- {\bedragprefix\digits{#1}\bedragsuffix}%
- \egroup}
-
-% \definieeralineas[test][n=3]
-%
-% \stelalineasin[test][3][breedte=4cm,uitlijnen=links]
-%
-% \startopelkaar
-% \test hans \\ ton \\ \bedrag{1.000,--} \\
-% \test hans \\ ton \\ \bedrag{~.~~1,--} \\
-% \test hans \\ ton \\ \bedrag{~.~~1,~~} \\
-% \test hans \\ ton \\ \bedrag{~.100,--} \\
-% \test hans \\ ton \\ \subtot{1.000,--} \\
-% \test hans \\ ton \\ \bedrag{1.000,--} \\
-% \test hans \\ ton \\ \bedrag{1.000,--} \\
-% \test hans \\ ton \\ \totaal{1.000,--} \\
-% \test hans \\ ton \\ \bedrag{nihil,--} \\
-% \test hans \\ ton \\ \totaal{nihil,--} \\
-% \test hans \\ ton \\ \subtot{nihil,--} \\
-% \stopopelkaar
-
-\def\periodswidth {.5em}
-\def\periodsdefault{3} % was 5, but now it's like \unknown
-
-\unexpanded\def\periods
- {\dosingleempty\doperiods}
-
-\def\doperiods[#1]%
- {\dontleavehmode
- \begingroup
- \scratchdimen\periodswidth
- \hbox to \iffirstargument#1\else\periodsdefault\fi \scratchdimen
- {\leaders\hbox to \scratchdimen{\hss.\hss}\hss}%
- \endgroup}
-
-\unexpanded\def\unknown
- {\periods\relax} % relax prevents lookahead for []
-
-% compatibility macros
-
-\def\doorsnede
- {\hbox{\rlap/$\circ$} }
-
-\unexpanded\def\ongeveer
- {\mathematics\pm}
-
-\chardef\boundarycharactermode\plusone
-
-\def\midboundarycharacter#1#2%
- {\ifcase\boundarycharactermode
- \or
- %\nobreak
- \hskip\hspaceamount\currentlanguage{#2}%
- \languageparameter#1%
- %\nobreak
- \hskip\hspaceamount\currentlanguage{#2}%
- \or
- \languageparameter#1%
- \fi
- \chardef\boundarycharactermode\plusone}
-
-\def\leftboundarycharacter#1#2%
- {\ifcase\boundarycharactermode
- \or
- \languageparameter#1%
- \nobreak
- \hskip\hspaceamount\currentlanguage{#2}%
- \or
- \languageparameter#1%
- \fi
- \chardef\boundarycharactermode\plusone}
-
-\def\rightboundarycharacter#1#2%
- {\ifcase\boundarycharactermode
- \or
- \prewordbreak %\nobreak
- \hskip\hspaceamount\currentlanguage{#2}%
- \languageparameter#1%
- \or
- \languageparameter#1%
- \fi
- \chardef\boundarycharactermode\plusone}
-
-% actually this is pretty old, but temporary moved here
-%
-% obsolete:
-
-\def\setuphyphenmark
- {\dodoubleargument\getparameters[\??kp]}
-
-
-\def\setuphyphenmark[#1]% sign=normal|wide
- {\dodoubleargument\getparameters[\??kp][#1]%
- \doifinsetelse\@@kpsign {\v!normal}
- {\let\textmodehyphen\normalhyphen \let\textmodehyphendiscretionary\normalhyphendiscretionary}
- {\let\textmodehyphen\composedhyphen\let\textmodehyphendiscretionary\composedhyphendiscretionary}}
-
-\setuphyphenmark[\c!sign=\v!wide]
-% % \setuphyphenmark[\c!sign=\v!normal]
-
-\definesymbol[\c!lefthyphen] [\languageparameter\c!lefthyphen]
-\definesymbol[\c!righthyphen] [\languageparameter\c!righthyphen]
-\definesymbol[\c!hyphen] [\languageparameter\c!hyphen]
-
-\def\normalhyphen
- {\hbox{\directsymbol\empty\c!hyphen}}
-
-\def\composedhyphen
- {\hbox{\directsymbol\empty\c!compoundhyphen}}
-
-\def\normalhyphendiscretionary
- {\discretionary
- {\hbox{\directsymbol\empty\c!lefthyphen}}
- {\hbox{\directsymbol\empty\c!righthyphen}}
- {\hbox{\directsymbol\empty\c!hyphen}}}
-
-\def\composedhyphendiscretionary
- {\discretionary
- {\hbox{\directsymbol\empty\c!leftcompoundhyphen}}
- {\hbox{\directsymbol\empty\c!rightcompoundhyphen}}
- {\hbox{\directsymbol\empty\c!compoundhyphen}}}
-
-\let\textmodehyphen \composedhyphen
-\let\textmodehyphendiscretionary\composedhyphendiscretionary
-
-\definesymbol[\c!leftcompoundhyphen] [\languageparameter\c!leftcompoundhyphen]
-\definesymbol[\c!rightcompoundhyphen] [\languageparameter\c!rightcompoundhyphen]
-\definesymbol[\c!compoundhyphen] [\languageparameter\c!compoundhyphen]
-
-\definehspace [sentence] [\zeropoint]
-\definehspace [intersentence] [.250em]
-
-\definesymbol
- [\c!midsentence]
- [\midboundarycharacter\c!midsentence{sentence}]
-
-\definesymbol
- [\c!leftsentence]
- [\leftboundarycharacter\c!leftsentence{sentence}]
-
-\definesymbol
- [\c!rightsentence]
- [\rightboundarycharacter\c!rightsentence{sentence}]
-
-\definesymbol
- [\c!leftsubsentence]
- [\leftboundarycharacter\c!leftsubsentence{sentence}]
-
-\definesymbol
- [\c!rightsubsentence]
- [\rightboundarycharacter\c!rightsubsentence{sentence}]
-
-\newsignal \subsentencesignal
-\newcounter\subsentencelevel
-
-\let\beforesubsentence\donothing
-\let\aftersubsentence \donothing
-
-% todo: make this language option
-%
-% \def\beforesubsentence{\removeunwantedspaces}
-% \def\aftersubsentence {\ignorespaces}
-
-\def\midsentence
- {\symbol[\c!midsentence]}
-
-\def\beginofsubsentence
- {\beforesubsentence
- \ifdim\lastkern=\subsentencesignal
- \unskip
- \kern\hspaceamount\currentlanguage{intersentence}%
- \fi
- \doglobal\increment\subsentencelevel
- \ifnum\subsentencelevel=\plusone
- \dontleavehmode % was \leaveoutervmode
- \fi
- \symbol[\ifodd\subsentencelevel\c!leftsentence\else\c!leftsubsentence\fi]%
- }% \ignorespaces}
-
-\def\endofsubsentence % relax prevents space gobbling
- {\symbol[\ifodd\subsentencelevel\c!rightsentence\else\c!rightsubsentence\fi]%
- \doglobal\decrement\subsentencelevel
- \unskip
- \kern\subsentencesignal\relax
- \aftersubsentence}
-
-\def\beginofsubsentencespacing % relax prevents space gobbling
- {\kern\subsentencesignal\relax}% \ignorespaces}
-
-\def\endofsubsentencespacing
- {\ifdim\lastkern=\subsentencesignal
- \unskip
- \hskip\hspaceamount\currentlanguage{intersentence}%
- % no good, actually language dependent:
-% \ignorespaces
- \else
- \unskip
- \fi}
-
-%D \startbuffer
-%D test |<|test |<|test|>| test|>| test \par
-%D test|<|test|<|test|>|test|>|test \par
-%D test |<||<|test|>||>| test \par
-%D test \directdiscretionary{<}test\directdiscretionary{>} test \par
-%D \stopbuffer
-%D
-%D \typebuffer
-%D \getbuffer
-
-\def\startsubsentence{\beginofsubsentence \prewordbreak\beginofsubsentencespacing}
-\def\stopsubsentence {\endofsubsentencespacing\prewordbreak\endofsubsentence}
-
-%D \defineXMLenvironment [subsentence]
-%D {|<|}
-%D {|>|}
-%D \defineXMLenvironment [subsentence]
-%D {\directdiscretionary{<}}
-%D {\directdiscretionary{>}}
-%D \defineXMLenvironment [subsentence]
-%D {\startsubsentence}
-%D {\stopsubsentence}
-%D
-%D \startbuffer
-%D test test test
-%D \stopbuffer
-%D
-%D \typebuffer
-%D \processXMLbuffer
-
-\enableactivediscretionaries
-
-\definehspace [quotation] [\zeropoint]
-\definehspace [interquotation] [.125em]
-
-%definehspace [quote] [\zeropoint]
-%definehspace [speech] [\zeropoint]
-
-\definehspace [quote] [\hspaceamount\currentlanguage{quotation}]
-\definehspace [speech] [\hspaceamount\currentlanguage{quotation}]
-
-\definesymbol
- [\c!leftquotation]
- [\leftboundarycharacter\c!leftquotation{quotation}]
-
-\definesymbol
- [\c!rightquotation]
- [\rightboundarycharacter\c!rightquotation{quotation}]
-
-\definesymbol
- [\c!leftquote]
- [\leftboundarycharacter\c!leftquote{quote}]
-
-\definesymbol
- [\c!rightquote]
- [\rightboundarycharacter\c!rightquote{quote}]
-
-\definesymbol
- [\c!leftspeech]
- [\leftboundarycharacter\c!leftspeech{speech}]
-
-\definesymbol
- [\c!rightspeech]
- [\rightboundarycharacter\c!rightspeech{speech}]
-
-\definesymbol
- [\c!middlespeech]
- [\leftboundarycharacter\c!middlespeech{speech}]
-
-\appendtoks\def\quotation#1{"#1"}\to\simplifiedcommands
-\appendtoks\def\quote #1{'#1'}\to\simplifiedcommands
-
-%D The next features was so desperately needed by Giuseppe
-%D Bilotta that he made a module for it. Since this is a
-%D typical example of core functionality, I decided to extend
-%D the low level quotation macros in such a way that a speech
-%D feature could be build on top of it. The speech opening and
-%D closing symbols are defined per language. Italian is an
-%D example of a language that has them set.
-
-% this will replace the quotation and speed definitions
-
-\newsignal\delimitedtextsignal
-
-\let\currentdelimitedtext\s!unknown
-
-\def\delimitedtextparameter#1% will be sped up
- {\executeifdefined{\??ci\currentdelimitedtext:\csname\??ci\currentdelimitedtext\c!level\endcsname#1}%
- {\executeifdefined{\??ci\currentdelimitedtext#1}%
- {\executeifdefined{\??ci#1}\empty}}}
-
-\def\definedelimitedtext
- {\dodoubleempty\dodefinedelimitedtext}
-
-\def\dodefinedelimitedtext[#1][#2]%
- {\doifassignmentelse{#2}
- {\getparameters
- [\??ci#1]
- [\c!location=\v!margin, % \v!text \v!paragraph
- \c!spacebefore=,
- \c!spaceafter=\delimitedtextparameter\c!spacebefore,
- \c!style=\v!normal,
- \c!color=,
- \c!leftmargin=\zeropoint,
- \c!rightmargin=\delimitedtextparameter\c!leftmargin,
- \c!indentnext=\v!yes,
- \c!before=,
- \c!after=,
- \c!left=,
- \c!right=,
- \c!level=0,
- \c!repeat=\v!no,
- \c!method=,
- #2]}%
- {\doifdefined{#2}
- {\copyparameters[\??ci#1][\??ci#2]
- [\c!location,\c!spacebefore,\c!spaceafter,\c!style,\c!color,
- \c!leftmargin,\c!rightmargin,\c!indentnext,
- \c!before,\c!after,\c!left,\c!right]}}%
- \doifsomething{#1}
- {\unexpanded\setvalue{#1}{\delimitedtext[#1]}%
- \setvalue{\e!start#1}{\startdelimitedtext[#1]}%
- \setvalue{\e!stop #1}{\stopdelimitedtext}}}
-
-\def\setupdelimitedtext
- {\dotripleargument\dosetupdelimitedtext}
-
-\def\dosetupdelimitedtext[#1][#2][#3]% #2 = optional level
- {\ifthirdargument
- \getparameters[\??ci#1:#2][#3]%
- \else\ifsecondargument
- \getparameters[\??ci#1][#2]%
- \else
- \getparameters[\??ci][#1]%
- \fi\fi}
-
-\def\dorepeatdelimitedtext
- {\relax\ifcase\delimitedtextparameter\c!level\else
- \dohandledelimitedtext\c!middle % maybe better \dohandleleftdelimitedtext
- \fi}
-
-\let\dohandlerepeatdelimitedtext\relax
-
-\def\startdelimitedtext[#1]%
- {\bgroup
- \pushdelimitedtext{#1}%
- \doifelse{\delimitedtextparameter\c!method}\s!font
- {\def\dostopdelimitedtext
- {\removeunwantedspaces\ignoredelimitedtext\c!right}%
- \ignoredelimitedtext\c!left\ignorespaces}
- {\doifelse{\delimitedtextparameter\c!repeat}\v!yes
- {\let\dohandlerepeatdelimitedtext\dorepeatdelimitedtext}%
- {\let\dohandlerepeatdelimitedtext\relax}%
- \doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
- {\dosingleempty\dostartdelimitedtextpar}\dostartdelimitedtexttxt}}
-
-\def\dostartdelimitedtextpar[#1]%
- {\let\dostopdelimitedtext\dostopdelimitedtextpar
- \doifsomething{\delimitedtextparameter\c!spacebefore}
- {\blank[\delimitedtextparameter\c!spacebefore]}%
- \delimitedtextparameter\c!before
- % nicer:
- % \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
- % \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
- % backward compatible:
- \doifelsenothing{#1}
- {\endgraf
- \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
- \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
- \let\dodostopdelimitedtextpar\endgraf}
- {\startnarrower[#1]\let\dodostopdelimitedtextpar\stopnarrower}%
- % so far
- % \dochecknextindentation{\??ci\currentdelimitedtext}% AM: not here
- \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
- \leftdelimitedtextmark
- \ignorespaces}
-
-\def\dostopdelimitedtextpar
- {\removeunwantedspaces
- \removelastskip
- \rightdelimitedtextmark
- \dostopattributes
- \dodostopdelimitedtextpar
- \delimitedtextparameter\c!after
- \doifsomething{\delimitedtextparameter\c!spaceafter}
- {\blank[\delimitedtextparameter\c!spaceafter]}%
- \dochecknextindentation{\??ci\currentdelimitedtext}% AM: here
- \dorechecknextindentation}% AM: This was missing!
-
-\def\dostartdelimitedtexttxt
- {\let\dostopdelimitedtext\dostopdelimitedtexttxt
- \dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color\empty
- \dohandleleftdelimitedtext\c!left
- \ignorespaces}
-
-\def\dostopdelimitedtexttxt
- {\removeunwantedspaces
- \dohandlerightdelimitedtext\c!right
- \dostopattributes}
-
-\def\stopdelimitedtext
- {\dostopdelimitedtext
- \popdelimitedtext
- \egroup}
-
-\def\pushdelimitedtext#1%
- {\globalpushmacro\currentdelimitedtext
- \def\currentdelimitedtext{#1}%
- \doglobal\incrementvalue{\??ci\currentdelimitedtext\c!level}}
-
-\def\popdelimitedtext
- {\doglobal\decrementvalue{\??ci\currentdelimitedtext\c!level}%
- \globalpopmacro\currentdelimitedtext}
-
-\def\delimitedtext[#1]%
- {\pushdelimitedtext{#1}%
- \doifelse{\delimitedtextparameter\c!method}\s!font
- {\dofontdrivendelimited}
- {\doifinsetelse{\delimitedtextparameter\c!location}{\v!paragraph,\v!margin}%
- \dodelimitedtextpar\dodelimitedtexttxt}}
-
-% shortcuts
-
-\def\startdelimited{\startdelimitedtext}
-\def\stopdelimited {\stopdelimitedtext} % no let, dynamically assigned
-\def\delimited {\delimitedtext}
-
-\def\leftdelimitedtextmark
- {\doifsomething{\delimitedtextparameter\c!left}
- {\setbox\scratchbox\hbox{\delimitedtextparameter\c!left}%
- \dontleavehmode
- \doif{\delimitedtextparameter\c!location}\v!margin{\hskip-\wd\scratchbox}%
- \box\scratchbox}}
-
-\def\rightdelimitedtextmark
- {\doifsomething{\delimitedtextparameter\c!right}
- {\hsmash{\delimitedtextparameter\c!right}}}
-
-% \starttext
-% \hyphenatedword{groepsvrijstellingsverordeningen}\par
-% \hyphenatedword{\quote{groepsvrijstellingsverordeningen}}\par
-% \dorecurse{100}{\hskip300pt\hskip\recurselevel pt test \quote{xxx xxxx}.\par}
-% \page \setuppapersize[A5][A4]
-% \quotation {overly beautiful pusillanimous sesquipedalian
-% longwinded} test test test test test test test test test test test
-% test test test test test test test test test test test test test
-% test test test test test test test test test test test test test
-% test test test test test test test test test test test test test
-% test test test
-% \stoptext
-
-\def\dohandledelimitedtext#1#2%
- {\begingroup
- \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
- \ifdim\wd\scratchbox>\zeropoint
-% \ifdim\lastskip=\delimitedtextsignal
-% \unskip
- \ifdim\lastkern=\delimitedtextsignal
- \unkern
- \hskip\hspaceamount\currentlanguage{interquotation}%
- \else
- #2%
- \fi
- \ifhmode % else funny pagebeaks
- \penalty\!!tenthousand
- \hskip\zeropoint % == \prewordbreak
- \fi
- \strut % new, needed below
- \delimitedtextparameter#1% unhbox\scratchbox
-% \penalty\!!tenthousand % else overfull boxes, but that's better than dangling periods
- \kern\delimitedtextsignal % +- \prewordbreak
- \fi
- \endgroup}
-
-\def\dohandleleftdelimitedtext#1#2%
- {\begingroup
- \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
- \ifdim\wd\scratchbox>\zeropoint
- \ifdim\lastkern=\delimitedtextsignal
- \unkern
- \hskip\hspaceamount\currentlanguage{interquotation}%
- \else\ifdim\lastskip=\delimitedtextsignal
- \unskip
- \hskip\hspaceamount\currentlanguage{interquotation}%
- \else
- #2%
- \fi\fi
- \strut % new, needed below
- \ifhmode % else funny pagebeaks
- \penalty\!!tenthousand
- \hskip\zeropoint % == \prewordbreak
- \fi
- \strut % new, needed below
- \delimitedtextparameter#1% unhbox\scratchbox
- \hskip\delimitedtextsignal % +- \prewordbreak
- \fi
- \endgroup}
-
-\def\dohandlerightdelimitedtext#1#2%
- {\begingroup
- \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
- \ifdim\wd\scratchbox>\zeropoint
- \ifdim\lastkern=\delimitedtextsignal
- \unkern
- \hskip\hspaceamount\currentlanguage{interquotation}%
- \else\ifdim\lastskip=\delimitedtextsignal
- \unskip
- \hskip\hspaceamount\currentlanguage{interquotation}%
- \else
- #2%
- \fi\fi
- \ifhmode % else funny pagebeaks
- \penalty\!!tenthousand
- \hskip\zeropoint % == \prewordbreak
- \fi
- \strut % new, needed below
- \delimitedtextparameter#1% unhbox\scratchbox
- \kern\delimitedtextsignal % +- \prewordbreak
- \fi
- \endgroup}
-
-\def\ignoredelimitedtext#1%
- {\delimitedtextparameter#1}
-
-\def\handledelimitedtext#1%
- {\dohandledelimitedtext{#1}\relax}
-
-\def\handleleftdelimitedtext#1%
- {\dohandleleftdelimitedtext{#1}\relax}
-
-\def\handlerightdelimitedtext#1%
- {\dohandlerightdelimitedtext{#1}\relax}
-
-\unexpanded\def\dodelimitedtextpar
- {\dohandleleftdelimitedtext\c!left\relax
- \groupedcommand
- \donothing
- {\dohandlerightdelimitedtext\c!right\removelastskip
- \popdelimitedtext}}
-
-\unexpanded\def\dodelimitedtexttxt
- {\doifelse{\delimitedtextparameter\c!style}\v!normal
- \doquoteddelimited\doattributeddelimited}
-
-\def\doquoteddelimited
- {\dohandleleftdelimitedtext\c!left\relax
- \groupedcommand
- \donothing
- {\dohandlerightdelimitedtext\c!right
- \removelastskip
- \popdelimitedtext}}
-
-\def\doattributeddelimited
- {\groupedcommand
- {\dostartattributes{\??ci\currentdelimitedtext}\c!style\c!color}
- {\dostopattributes
- \popdelimitedtext}}
-
-\def\dofontdrivendelimited
- {\simplegroupedcommand
- {\languageparameter{\c!left\currentdelimitedtext}}
- {\languageparameter{\c!right\currentdelimitedtext}%
- \popdelimitedtext}}
-
-% testcase for nesting:
-%
-% \quotation{... \quotation{...} ...}
-% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
-% \setupdelimitedtext[quotation][1][left=(,right=)]
-% \setupdelimitedtext[quotation][2][left={[},right={]}]
-% \setupdelimitedtext[quotation][3][left=\{,right=\}]
-% \quotation{... \quotation{...} ...}
-% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
-
-\definedelimitedtext
- [\v!quotation]
- [\c!left={\symbol[\c!leftquotation]},
- \c!right={\symbol[\c!rightquotation]},
- \c!leftmargin=\v!standard]
-
-\definedelimitedtext
- [\v!quote][\v!quotation]
-
-\setupdelimitedtext
- [\v!quote]
- [\c!location=\v!text,
- \c!left={\symbol[\c!leftquote]},
- \c!right={\symbol[\c!rightquote]}]
-
-\definedelimitedtext
- [\v!blockquote][\v!quotation]
-
-\setupdelimitedtext
- [\v!blockquote]
- [\c!left=,
- \c!right=]
-
-\definedelimitedtext
- [\v!speech][\v!quotation]
-
-\setupdelimitedtext
- [\v!speech]
- [\c!repeat=\v!yes,
- \c!left={\symbol[\c!leftspeech]},
- \c!middle={\symbol[\c!middlespeech]},
- \c!right={\symbol[\c!rightspeech]}]
-
-% how do we call an tight quote
-%
-% \definedelimitedtext
-% [\v!quotation][\v!quotation]
-%
-% \setupdelimitedtext
-% [\v!quotation]
-% [\c!indentnext=\v!no,
-% \c!spacebefore=\v!nowhite]
-
-\def\setupquotation{\setupdelimitedtext[\v!quotation]}
-\def\setupquote {\setupdelimitedtext[\v!quote]}
-
-% seldom used, move from kernel to run time module
-
-\ifx\tfx\undefined \let\tfx\relax \fi
-
-\def\basegrid
- {\dosingleempty\dobasegrid}
-
-\def\dobasegrid[#1]%
- {\begingroup
- \getparameters[\??rt]
- [\c!x=0,\c!y=0,
- \c!nx=10,\c!ny=10,
- \c!dx=.5,\c!dy=.5,
- \c!xstep=0,\c!ystep=0,
- \c!unit=\s!cm,
- \c!scale=1,
- \c!factor=1,
- \c!offset=\v!yes,
- \c!location=\v!left,
- #1]%
- \startpositioning
- \dimen0=\@@rtdx\@@rtunit\relax
- \dimen0=\@@rtscale\dimen0\relax
- \dimen0=\@@rtfactor\dimen0\relax
- \multiply\dimen0 \@@rtnx\relax
- \dimen2=\@@rtdy\@@rtunit\relax
- \dimen2=\@@rtscale\dimen2\relax
- \dimen2=\@@rtfactor\dimen2\relax
- \multiply\dimen2 \@@rtny\relax
- \def\horline
- {\vbox
- {\hrule
- \!!width \dimen0
- \!!height \linewidth
- \!!depth \!!zeropoint}}%
- \def\verline%
- {\vrule
- \!!width \linewidth
- \!!height \dimen2
- \!!depth \!!zeropoint}%
- \doglobal\newcounter\@@gridc
- \doglobal\newcounter\@@gridd
- \doglobal\newcounter\@@gride
- \def\setlegend##1##2##3%
- {\gdef\@@gridc{0}%
- \dimen0=2em\relax
- \dimen2=##2\@@rtunit\relax
- \dimen2=\@@rtscale\dimen2\relax
- \dimen2=\@@rtfactor\dimen2\relax
- \divide\dimen0 \dimen2\relax
- \xdef\@@gride{\number\dimen0}%
- \ifnum\@@gride>50
- \gdef\@@gride{100}%
- \else\ifnum\@@gride>10
- \gdef\@@gride{50}%
- \else\ifnum\@@gride>5
- \gdef\@@gride{10}%
- \else\ifnum\@@gride>1
- \gdef\@@gride{5}%
- \else
- \gdef\@@gride{1}%
- \fi\fi\fi\fi
- \gdef\@@gridd{0}%
- \def\legend
- {\ifnum\@@gridd=\zerocount
- \vbox
- {\increment(\@@gridc,##1)%
- \hbox to 2em{\hss\@@gridc\hss}}%
- \global\let\@@gridd=\@@gride
- \fi
- \doglobal\decrement\@@gridd
- \doglobal\increment(\@@gridc,##1)}}%
- \def\draw##1##2##3##4##5##6##7##8##9%
- {\setuppositioning
- [\c!state=##8,
- \c!xstep=\v!absolute,
- \c!ystep=\v!absolute,
- \c!unit=\@@rtunit,
- \c!scale=\@@rtscale,
- \c!factor=\@@rtfactor,
- \c!offset=\@@rtoffset,
- \c!xoffset=##6,
- \c!yoffset=##7]%
- \doifelse{##9}\v!middle
- {\scratchdimen##3pt\scratchdimen.5\scratchdimen
- \edef\@@psxx{\withoutpt\the\scratchdimen}%
- \scratchdimen##4pt\scratchdimen.5\scratchdimen
- \edef\@@psyy{\withoutpt\the\scratchdimen}%
- \scratchcounter##2\advance\scratchcounter -1
- \edef\@@pszz{\the\scratchcounter}}
- {\edef\@@psxx{0}\edef\@@psyy{0}\edef\@@pszz{##2}}%
- \position(\@@psxx,\@@psyy){##1}%
- \setuppositioning
- [\c!state=##8,
- \c!xstep=\v!relative,
- \c!ystep=\v!relative,
- \c!scale=\@@rtscale,
- \c!factor=\@@rtfactor,
- \c!offset=\@@rtoffset,
- \c!unit=\@@rtunit]%
- \dorecurse\@@pszz{\position(##3,##4){##5}}}%
- \draw
- \verline\@@rtnx\@@rtdx0\verline\!!zeropoint\!!zeropoint\v!start\empty
- \draw
- \horline\@@rtny0\@@rtdy\horline\!!zeropoint\!!zeropoint\v!start\empty
- \tfx
- \doifnot\@@rtxstep{0}
- {\setlegend\@@rtxstep\@@rtdx\@@rtx
- \draw\legend\@@rtnx\@@rtdx0\legend{-1em}{-1.5em}\v!overlay\@@rtlocation}%
- \doifnot\@@rtystep{0}
- {\setlegend\@@rtystep\@@rtdy\@@rty
- \draw\legend\@@rtny0\@@rtdy\legend{-2em}{-.75ex}\v!overlay\@@rtlocation}%
- \stoppositioning
- \endgroup}
-
-\let\grid\basegrid
-
-% Dit wordt:
-%
-% \doorverwijzen[naam][instellingen] enz.
-%
-% waarbij bijvoorbeeld publicatie is. Dit levert:
-%
-% \start
-% \stop
-%
-% \beginvan
-% \eindvan
-%
-% \publicatie
-%
-% \volledigelijstmetpublicaties
-%
-% eigenlijk kan ook door... zo worden uitgebreid!
-
-% old, will become obsolete or module, replace by bib module
-
-\defineenumeration
- [@publicatie]
- [\c!location=\v!left,
- \c!width=\@@pbwidth,\c!hang=,\c!sample=,
- \c!before=\@@pbbefore,\c!after=\@@pbafter,\c!inbetween=,
- \c!headstyle=\@@pbheadstyle,\c!style=,
- \c!headcolor=\@@pbheadcolor,\c!color=,
- \c!way=\@@pbway,\c!blockway=\@@pbblockway,
- \c!text=,\c!left=\@@pbleft,\c!right=\@@pbright]
-
-\def\dosetuppublications[#1]%
- {\getparameters[\??pb][#1]}
-
-\def\setuppublications%
- {\dosingleargument\dosetuppublications}
-
-\def\apa@publicatie
- {\doifsomething\@@pb@naam {\@@pb@naam,\space}%
- \doifsomething\@@pb@titel {{\sl\@@pb@titel}.\space}%
- \doifsomething\@@pb@jaar {(\@@pb@jaar).\space}%
- \doifsomething\@@pb@plaats {\@@pb@plaats\doifelsenothing\@@pb@uitgever{.}{:\space}}%
- \doifsomething\@@pb@uitgever{\@@pb@uitgever.}}
-
-\def\normaal@publicatie
- {\@@pb@naam, \@@pb@titel, \@@pb@jaar, \@@pb@pagina, \@@pb@plaats, \@@pb@uitgever.}
-
-\def\complexstartpublicatie[#1]#2\stoppublicatie
- {\bgroup
- \def\dosetpublicatie
- {\processcommalist
- [naam,titel,jaar,plaats,pagina,uitgever]
- \setpublicatie
- \ignorespaces}%
- \def\setpublicatie##1%
- {\letvalue{\??pb @##1}\empty
- \setvalue{##1}####1{\setvalue{\??pb @##1}{####1}\ignorespaces}}%
- \def\getpublicatie%
- {\doifsomething\@@pbalternative{\getvalue{\@@pbalternative @publicatie}}}%
- \doifelse\@@pbnumbering\v!yes
- {\@publicatie[#1]\dosetpublicatie#2\getpublicatie\par}%
- {\@@pbbefore
- \dosetpublicatie\ignorespaces#2\getpublicatie
- \@@pbafter}%
- \egroup}
-
-\definecomplexorsimpleempty\startpublicatie
-
-\def\publication#1[#2]%
- {\@@pbleft\in{#1}[#2]\@@pbright}
-
-\setuppublications
- [\c!numbering=\v!yes,
- \c!alternative=\c!apa,
- \c!width=2em,
- \c!hang=,
- \c!sample=,
- \c!before=,
- \c!after=,
- \c!inbetween=,
- \c!headstyle=,
- \c!headcolor=,
- \c!style=,
- \c!color=,
- \c!blockway=\v!by\v!text,
- \c!way=\v!by\v!text,
- \c!text=,
- \c!left={[},
- \c!right={]}]
-
-% only used at pragma, move from kernel to run time module
-
-\def\referraldate
- {\currentdate[\v!referral]}
-
-\def\doreferral[#1]%
- {\noheaderandfooterlines
- \bgroup
- \getparameters
- [\??km]
- [\c!bet=\unknown,\c!dat=\unknown,\c!ken=\unknown,
- \c!from=,\c!to=,\c!ref=,#1]%
- % moet anders, hoort niet in 01b
- \assigntranslation[\s!nl=referentie,\s!en=reference,\s!de=Referenz,\s!sp=referencia]\to\@@@kmref
- \assigntranslation[\s!nl=van,\s!en=from,\s!de=Von,\s!sp=de]\to\@@@kmvan
- \assigntranslation[\s!nl=aan,\s!en=to,\s!de=An,\s!sp=a]\to\@@@kmaan
- \assigntranslation[\s!nl=betreft,\s!en=concerns,\s!de=Betreff,\s!sp=]\to\@@@kmbet
- \assigntranslation[\s!nl=datum,\s!en=date,\s!de=Datum,\s!sp=fecha]\to\@@@kmdat
- \assigntranslation[\s!nl=kenmerk,\s!en=mark,\s!de=Kennzeichen,\s!sp=]\to\@@@kmken
- %
- \definetabulate[\s!dummy][|l|p|]
- \startdummy
- \NC\@@@kmbet\EQ\@@kmbet\NC\NR
- \NC\@@@kmdat\EQ\@@kmdat\NC\NR
- \NC\@@@kmken\EQ\expanded{\smallcapped{\@@kmken}}\NC\NR
- \doifsomething{\@@kmfrom\@@kmto}{\NC\NC\NC\NR}%
- \doifsomething \@@kmfrom {\NC\@@@kmvan\EQ\@@kmfrom\NC\NR}%
- \doifsomething \@@kmto {\NC\@@@kmaan\EQ\@@kmto\NC\NR}%
- \doifsomething \@@kmref {\NC\NC\NC\NR\NC\@@@kmref\EQ\@@kmref\NC\NR}%
- \stopdummy
- \egroup}
-
-\def\referral
- {\dosingleargument\doreferral}
-
-% FUZZY OLD STUFF: will be removed when not used in some manual;
-% rows instead of columns, i'd forgotten that this code exist
-%
-% \definesystemvariable{ri}
-%
-% \def\setuprows
-% {\dodoubleargument\getparameters[\??ri]}
-%
-% \definecomplexorsimpleempty\startrows
-%
-% \def\complexstartrows[#1]%
-% {\bgroup
-% \setuprows[#1]%
-% \let\do@@ribottom\relax
-% \def\row
-% {\do@@ribottom
-% \egroup
-% \dimen0\vsize
-% \divide\dimen0 \@@rin
-% \advance\dimen0 -\lineskip
-% \vbox to \dimen0
-% \bgroup
-% \@@ritop
-% \let\do@@ribottom\@@ribottom
-% \ignorespaces}%
-% \bgroup
-% \row}
-%
-% \def\stoprows
-% {\do@@ribottom
-% \egroup
-% \egroup}
-%
-% \setuprows
-% [\c!n=2,
-% \c!top=,
-% \c!bottom=\vfill]
-
-% THIS WAS MAIN-003.TEX
-
-\startmessages dutch library: systems
- 41: externe file -- in groep -- bestaat niet
-\stopmessages
-
-\startmessages english library: systems
- 41: external file -- in group -- does not exist
-\stopmessages
-
-\startmessages german library: systems
- 41: Externe Datei -- in Gruppe -- existiert nicht
-\stopmessages
-
-\startmessages czech library: systems
- 41: externi soubor -- ve skupine -- neexistuje
-\stopmessages
-
-\startmessages italian library: systems
- 41: il file esterno -- del gruppo -- non esiste
-\stopmessages
-
-\startmessages norwegian library: systems
- 41: ekstern fil -- i gruppe -- eksisterer ikke
-\stopmessages
-
-\startmessages romanian library: systems
- 41: fisierul extern -- din grupul -- nu exista
-\stopmessages
-
-\startmessages french library: systems
- 41: le fichier externe -- du groupe -- n'existe pas
-\stopmessages
-
-\definetabulate
- [\v!legend]
- [|emj1|i1|mR|]
-
-\setuptabulate
- [\v!legend]
- [\c!unit=.75em,\c!inner=\setquicktabulate\leg,EQ={=}]
-
-\definetabulate
- [\v!legend][\v!two]
- [|emj1|emk1|i1|mR|]
-
-\definetabulate
- [\v!fact]
- [|R|ecmj1|i1mR|]
-
-\setuptabulate
- [\v!fact]
- [\c!unit=.75em,\c!inner=\setquicktabulate\fact,EQ={=}]
-
-\unexpanded\def\xbox
- {\bgroup\aftergroup\egroup\hbox\bgroup\tx\let\next=}
-
-\unexpanded\def\xxbox
- {\bgroup\aftergroup\egroup\hbox\bgroup\txx\let\next=}
-
-% \def\mrm#1%
-% {$\rm#1$}
-
-%D \macros
-%D {definepairedbox, setuppairedbox, placepairedbox}
-%D
-%D Paired boxes, formally called legends, but from now on a
-%D legend is just an instance, are primarily meant for
-%D typesetting some text alongside an illustration. Although
-%D there is quite some variation possible, the functionality is
-%D kept simple, if only because in most cases such pairs are
-%D typeset sober.
-%D
-%D The location specification accepts a pair, where the first
-%D keyword specifies the arrangement, and the second one the
-%D alignment. The first key of the location pair is one of
-%D \type {left}, \type {right}, \type {top} or \type {bottom},
-%D while the second key can also be \type {middle}.
-%D
-%D The first box is just collected in an horizontal box, but
-%D the second one is a vertical box that gets passed the
-%D bodyfont and alignment settings.
-
-%D Today we would implement this using layers .... but for the
-%D moment we keep it this way.
-
-% \startbuffer[test]
-% \test left \test left,top \test left,bottom \test left,middle
-% \test right \test right,top \test right,bottom \test right,middle
-% \test top \test top,left \test top,right \test top,middle
-% \test bottom \test bottom,left \test bottom,right \test bottom,middle
-% \stopbuffer
-%
-% \def\showtest#1%
-% {\pagina
-% \typebuffer[demo]
-% \def\test##1
-% {\startlinecorrection[blank]
-% \getbuffer[demo]%
-% \ruledhbox\placelegend
-% [bodyfont=6pt,location={##1}]
-% {\framed[width=.25\textwidth]{\tttf##1}}
-% {#1}
-% \stoplinecorrection}
-% \getbuffer[test]}
-%
-% \startbuffer[demo]
-% \setuplegend
-% [width=\hsize,maxwidth=\makeupwidth,
-% height=\vsize,maxheight=\makeupheight]
-% \stopbuffer
-%
-% \showtest{These examples demonstrate the default settings.}
-%
-% \startbuffer[demo]
-% \setuplegend
-% [width=\textwidth,
-% maxwidth=\textwidth]
-% \stopbuffer
-%
-% \showtest{\input tufte }
-%
-% \startbuffer[demo]
-% \setuplegend
-% [width=.65\textwidth]
-% \stopbuffer
-%
-% \showtest{\input knuth }
-%
-% \startbuffer[demo]
-% \setuplegend
-% [height=2cm]
-% \stopbuffer
-%
-% \showtest{These examples demonstrate some other settings.}
-%
-% \startbuffer[demo]
-% \setuplegend
-% [width=.65\textwidth,
-% height=2cm]
-% \stopbuffer
-%
-% \showtest{These examples demonstrate some other settings.}
-%
-% \startbuffer[demo]
-% \setuplegend
-% [n=2,align=right,width=.5\textwidth]
-% \stopbuffer
-%
-% \showtest{\input zapf }
-
-%D \macros
-%D {setuplegend, placelegend}
-%D
-%D It makes sense to typeset a legend to a figure in \TEX\
-%D and not in a drawing package. The macro \type {\placelegend}
-%D combines a figure (or something else) and its legend. This
-%D command is just a paired box.
-%D
-%D The legend is placed according to \type {location}, being
-%D \type {bottom} or \type {right}. The macro macro is used as
-%D follows.
-%D
-%D \starttyping
-%D \placefigure
-%D {whow}
-%D {\placelegend
-%D {\externalfigure[cow]}
-%D {\starttabulation
-%D \NC 1 \NC head \NC \NR
-%D \NC 2 \NC legs \NC \NR
-%D \NC 3 \NC tail \NC \NR
-%D \stoptabulation}}
-%D
-%D \placefigure
-%D {whow}
-%D {\placelegend
-%D {\externalfigure[cow]}
-%D {\starttabulation[|l|l|l|l|]
-%D \NC 1 \NC head \NC 3 \NC tail \NC \NR
-%D \NC 2 \NC legs \NC \NC \NC \NR
-%D \stoptabulation}}
-%D
-%D \placefigure
-%D {whow}
-%D {\placelegend[n=2]
-%D {\externalfigure[cow]}
-%D {\starttabulation
-%D \NC 1 \NC head \NC \NR
-%D \NC 2 \NC legs \NC \NR
-%D \NC 3 \NC tail \NC \NR
-%D \stoptabulation}}
-%D
-%D \placefigure
-%D {whow}
-%D {\placelegend[n=2]
-%D {\externalfigure[cow]}
-%D {head \par legs \par tail}}
-%D
-%D \placefigure
-%D {whow}
-%D {\placelegend[n=2]
-%D {\externalfigure[cow]}
-%D {\startitemize[packed]
-%D \item head \item legs \item tail \item belly \item horns
-%D \stopitemize}}
-%D
-%D \placefigure
-%D {whow}
-%D {\placelegend[n=2,width=.8\hsize]
-%D {\externalfigure[cow]}
-%D {\startitemize[packed]
-%D \item head \item legs \item tail \item belly \item horns
-%D \stopitemize}}
-%D \stoptyping
-
-\newbox\firstpairedbox
-\newbox\secondpairedbox
-
-\def\definepairedbox
- {\dodoubleempty\dodefinepairedbox}
-
-\def\dodefinepairedbox[#1][#2]%
- {\getparameters
- [\??ld#1]
- [\c!n=1,
- \c!distance=\bodyfontsize,
- \c!before=,
- \c!after=,
- \c!color=,
- \c!style=,
- \c!inbetween={\blank[\v!medium]},
- \c!width=\hsize,
- \c!height=\vsize,
- \c!maxwidth=\textwidth, % \makeupwidth,
- \c!maxheight=\textheight, % \makeupheight,
- \c!bodyfont=,
- \c!align=,
- \c!location=\v!bottom,
- #2]%
- \setvalue{\e!setup#1\e!endsetup}{\setuppairedbox[#1]}%
- \setvalue{\e!place#1}{\placepairedbox[#1]}}
-
-\def\setuppairedbox
- {\dodoubleempty\dosetuppairedbox}
-
-\def\dosetuppairedbox[#1]%
- {\getparameters[\??ld#1]}
-
-\def\placepairedbox
- {\bgroup\dodoubleempty\doplacepairedbox}
-
-\def\doplacepairedbox[#1][#2]% watch the hsize/vsize tricks
- {\setuppairedbox[#1][#2]% % and don't change them
- \copyparameters % brrr
- [\??ld][\??ld#1]
- [\c!n,\c!distance,\c!inbetween,\c!before,\c!after,
- \c!width,\c!height,\c!maxwidth,\c!maxheight,
- \c!color,\c!style,\c!bodyfont,\c!align,\c!location]%
- \@@ldbefore\bgroup
- \global\setsystemmode{pairedbox}%
- \beforefirstpairedbox
- \dowithnextbox
- {\betweenbothpairedboxes
- \dowithnextbox
- {\afterbothpairedboxes
- \egroup\@@ldafter
- \egroup}
- \vbox\bgroup
- \insidesecondpairedbox
- \let\next=}
- \hbox}
-
-\def\beforefirstpairedbox
- {\chardef\pairedlocationa1 % left
- \chardef\pairedlocationb4 % middle
- \getfromcommacommand[\@@ldlocation][1]%
- \processaction
- [\commalistelement]
- [ \v!left=>\chardef\pairedlocationa0,
- \v!right=>\chardef\pairedlocationa1,
- \v!top=>\chardef\pairedlocationa2,
- \v!bottom=>\chardef\pairedlocationa3]%
- \getfromcommacommand[\@@ldlocation][2]%
- \processaction
- [\commalistelement]
- [ \v!left=>\chardef\pairedlocationb0,
- \v!right=>\chardef\pairedlocationb1,
- \v!high=>\chardef\pairedlocationb2,
- \v!top=>\chardef\pairedlocationb2,
- \v!low=>\chardef\pairedlocationb3,
- \v!bottom=>\chardef\pairedlocationb3,
- \v!middle=>\chardef\pairedlocationb4]}
-
-\def\betweenbothpairedboxes
- {\switchtobodyfont[\@@ldbodyfont]% split under same regime
- \setbox\firstpairedbox\flushnextbox
- \ifnum\pairedlocationa<2
- \hsize\wd\firstpairedbox % trick
- \hsize\@@ldwidth
- \scratchdimen\wd\firstpairedbox
- \advance\scratchdimen \@@lddistance
- \bgroup\advance\scratchdimen \hsize
- \ifdim\scratchdimen>\@@ldmaxwidth\relax
- \egroup
- \hsize\@@ldmaxwidth
- \advance\hsize -\scratchdimen
- \else
- \egroup
- \fi
- \else
- \hsize\wd\firstpairedbox
- \hsize\@@ldwidth % can be \hsize
- \ifdim\hsize>\@@ldmaxwidth\relax \hsize\@@ldmaxwidth \fi % can be \hsize
- \fi
- \ifnum\@@ldn>\plusone
- \setrigidcolumnhsize\hsize\@@lddistance\@@ldn
- \fi}
-
-\def\afterbothpairedboxes
- {\setbox\secondpairedbox\vbox
- {% \localstartcolor[\@@ldcolor]% does not work yet
- \ifnum\@@ldn>1
- \rigidcolumnbalance\nextbox
- \else
- \flushnextbox
- \fi
- }% \localstopcolor}%
- \ifnum\pairedlocationa<2\hbox\else\vbox\fi\bgroup % hide vsize
- \forgetall
- \ifnum\pairedlocationa<2
- \scratchdimen\maxoftwoboxdimens\ht\firstpairedbox\secondpairedbox
- \vsize\scratchdimen
- \ifdim\scratchdimen<\@@ldheight\relax % can be \vsize
- \scratchdimen\@@ldheight
- \fi
- \ifdim\scratchdimen>\@@ldmaxheight\relax
- \scratchdimen\@@ldmaxheight
- \fi
- \valignpairedbox\firstpairedbox \scratchdimen
- \valignpairedbox\secondpairedbox\scratchdimen
- \else
- \scratchdimen\maxoftwoboxdimens\wd\firstpairedbox\secondpairedbox
- \halignpairedbox\firstpairedbox \scratchdimen
- \halignpairedbox\secondpairedbox\scratchdimen
- \scratchdimen\ht\secondpairedbox
- \vsize\scratchdimen
- \ifdim\ht\secondpairedbox<\@@ldheight\relax % can be \vsize
- \scratchdimen\@@ldheight\relax % \relax needed
- \fi
- \ifdim\scratchdimen>\@@ldmaxheight\relax % todo: totale hoogte
- \scratchdimen\@@ldmaxheight\relax % \relax needed
- \fi
- \ifdim\scratchdimen>\ht\secondpairedbox
- \setbox\secondpairedbox\vbox to \scratchdimen
- {\ifnum\pairedlocationa=3 \vss\fi %
- \box\secondpairedbox
- \ifnum\pairedlocationa=2 \vss\fi}% \kern\zeropoint
- \fi
- \fi
- \ifcase\pairedlocationa
- \box\secondpairedbox\hskip\@@lddistance\box\firstpairedbox \or
- \box\firstpairedbox \hskip\@@lddistance\box\secondpairedbox\or
- \box\secondpairedbox\endgraf \nointerlineskip \@@ldinbetween \box\firstpairedbox \or
- \box\firstpairedbox \endgraf \nointerlineskip \@@ldinbetween \box\secondpairedbox\else
- \fi
- \egroup}
-
-\def\insidesecondpairedbox
- {\forgetall
- \setupalign[\@@ldalign]%
- \tolerantTABLEbreaktrue % hm.
- \blank[\v!disable]%
- \everypar{\begstrut}}
-
-\def\maxoftwoboxdimens#1#2#3%
- {#1\ifdim#1#2>#1#3 #2\else#3\fi}
-
-\def\valignpairedbox#1#2%
- {\setbox#1\vbox to #2
- {\ifcase\pairedlocationb\or\or\or\vss\or\vss\fi
- \box#1\relax
- \ifcase\pairedlocationb\or\or\vss\or\or\vss\fi}}
-
-\def\halignpairedbox#1#2%
- {\setbox#1\hbox to #2
- {\ifcase\pairedlocationb\or\hss\or\or\or\hss\fi
- \box#1\relax
- \ifcase\pairedlocationb\hss\or\or\or\or\hss\fi}}
-
-\definepairedbox[\v!legend]
-
-%D Goody:
-
-\newevery \everyinsidefloat \relax
-
-\appendtoks
- \global\resetsystemmode{combination}%
- \global\resetsystemmode{pairedbox}%
-\to \everyinsidefloat
-
-% todo: \startcombination \startcomb \stopcomb ...
-
-\newcount\horcombination % counter
-\newcount\totcombination
-
-\def\definecombination
- {\dodoubleempty\dodefinecombination}
-
-\def\dodefinecombination[#1][#2]%
- {\copyparameters
- [\??co#1][\??co]
- [\c!width,\c!height,\c!distance,\c!location,%
- \c!before,\c!inbetween,\c!after,\c!align,%
- \c!style,\c!color]%
- \getparameters
- [\??co#1][#2]}
-
-\def\setupcombinations
- {\dodoubleempty\dosetupcombinations}
-
-\def\dosetupcombinations[#1][#2]%
- {\ifsecondargument
- \getparameters[\??co#1][#2]%
- \else
- \getparameters[\??co][#1]%
- \fi}
-
-\def\combinationparameter#1%
- {\csname\??co\currentcombination#1\endcsname}%
-
-\def\startcombination
- {\bgroup % so we can grab a group
- \dodoubleempty\dostartcombination}
-
-% \startcombination {alpha} {a} {beta} {b} \stopcombination
-% \startcombination[2*1] {alpha} {a} {beta} {b} \stopcombination
-% \startcombination[1*2] {alpha} {a} {beta} {b} \stopcombination
-% \startcombination[2] {alpha} {a} {beta} {b} \stopcombination
-
-\def\dostartcombination[#1][#2]%
- {\global\setsystemmode{combination}%
- \doifnothing{#1}\firstargumentfalse % to be sure (when called in macros)
- \doifnothing{#2}\secondargumentfalse % to be sure (when called in macros)
- \ifsecondargument
- \def\currentcombination{#1}%
- \edef\currentcombinationspec{#2*1*}%
- \else % better : \doifcombinationelse ... \??co#1\c!location
- \doifinstringelse{*}{#1}
- {\let\currentcombination\empty
- \edef\currentcombinationspec{#1*1*}}
- {\doifnumberelse{#1}
- {\let\currentcombination\empty
- \edef\currentcombinationspec{#1*1*}}
- {\def\currentcombination{#1}%
- \edef\currentcombinationspec{2*1*}}}%
- \fi
- \forgetall
- \doifelse{\combinationparameter\c!height}\v!fit
- \vbox {\vbox to \combinationparameter\c!height}%
- \bgroup
- \expanded{\dodostartcombination[\currentcombinationspec]}}
-
-\long\def\dodostartcombination[#1*#2*#3]%
- {\setuphorizontaldivision
- [\c!n=\v!fit,\c!distance=\combinationparameter\c!distance]%
- \global\horcombination#1%
- \global\totcombination#2%
- \global\setbox\combinationstack\emptybox
- \xdef\maxhorcombination{\the\horcombination}%
- \multiply\totcombination\horcombination
- \tabskip\zeropoint
- \doifelse{\combinationparameter\c!width}\v!fit
- {\halign}{\halign to \combinationparameter\c!width}%
- \bgroup&%
- %\hfil##\hfil% now : location={left,top}
- \expanded{\doifnotinset{\v!left}{\combinationparameter\c!location}}\hfil
- ##%
- \expanded{\doifnotinset{\v!right}{\combinationparameter\c!location}}\hfil
- &\tabskip\zeropoint \!!plus 1fill##\cr
- \docombination}
-
-\def\docombination % we want to add struts but still ignore an empty box
- {\dowithnextbox
- {\setbox0\flushnextbox
- \dowithnextbox
- {\setbox2\flushnextbox
- \dodocombination}%
- \vtop\bgroup
- \def\next
- {\futurelet\nexttoken\nextnext}%
- \def\nextnext
- {\ifx\nexttoken\egroup \else % the next box is empty
- \hsize\wd0
- \setupalign[\combinationparameter\c!align]%
- \dostartattributes{\??co\currentcombination}\c!style\c!color\empty
- \bgroup
- \aftergroup\endstrut
- \aftergroup\dostopattributes
- \aftergroup\egroup
- \begstrut
- \fi}%
- \afterassignment\next\let\nexttoken=}
- \hbox}
-
-% stupid version, does not align top stuff when captions,
-% keep as example
-%
-% \def\dodocombination
-% {\vbox
-% {\forgetall % \setupwhitespace[\v!none]%
-% \let\next\vbox
-% \ExpandFirstAfter\processallactionsinset
-% [\combinationparameter\c!location]
-% [ \v!top=>\let\next\tbox,
-% \v!middle=>\let\next\halfwaybox]%
-% \next{\copy0}%
-% \ifdim\ht2>\zeropoint % beter dan \wd2, nu \strut mogelijk
-% \combinationparameter\c!inbetween
-% %\vtop % wrong code
-% % {\nointerlineskip % recently added
-% % \hsize\wd0
-% % \setupalign[\combinationparameter\c!align]% % \raggedcenter
-% % \begstrut\unhbox2\endstrut}%
-% \box2
-% \fi}%
-% \ifnum\totcombination>\plusone
-% \global\advance\totcombination\minusone
-% \global\advance\horcombination\minusone
-% \ifnum\horcombination=\zerocount
-% \def\next
-% {\cr\noalign
-% {\forgetall % \setupwhitespace[\v!geen]% no
-% \nointerlineskip
-% \combinationparameter\c!before
-% \combinationparameter\c!after
-% \vss
-% \nointerlineskip}%
-% \global\horcombination\maxhorcombination\relax
-% \docombination}%
-% \else
-% \def\next
-% {&&&\hskip\combinationparameter\c!distance&\docombination}%
-% \fi
-% \else
-% \def\next
-% {\cr\egroup}%
-% \fi
-% \next}
-
-% \def\dodocombination
-% {\vbox
-% {\forgetall % \setupwhitespace[\v!none]%
-% \let\next\vbox
-% \ExpandFirstAfter\processallactionsinset
-% [\combinationparameter\c!plaats]
-% [ \v!top=>\let\next\tbox,
-% \v!middle=>\let\next\halfwaybox]%
-% \next{\copy0}%
-% % we need to save the caption for a next alignment line
-% \saveoncombinationstack2}%
-% \ifnum\totcombination>\plusone
-% \global\advance\totcombination\minusone
-% \global\advance\horcombination\minusone
-% \ifnum\horcombination=\zerocount
-% \def\next
-% {\cr
-% \flushcombinationstack
-% \noalign
-% {\forgetall % \setupwhitespace[\v!none]% no
-% \global\setbox\combinationstack\emptybox
-% \nointerlineskip
-% \combinationparameter\c!after
-% \combinationparameter\c!before
-% \vss
-% \nointerlineskip}%
-% \global\horcombination\maxhorcombination\relax
-% \docombination}%
-% \else
-% \def\next
-% {&&&\hskip\combinationparameter\c!distance&\docombination}%
-% \fi
-% \else
-% \def\next
-% {\cr
-% \flushcombinationstack
-% \egroup}%
-% \fi
-% \next}
-
-\def\depthonlybox
- {\dowithnextbox{\vtop{\hsize\wd\nextbox\kern\zeropoint\box\nextbox}}\vbox}
-
-% \def\boxwithstrutheight
-% {\dowithnextbox
-% {\scratchdimen\strutheight
-% \advance\scratchdimen-\nextboxht
-% \hbox{\raise\scratchdimen\box\nextbox}}%
-% \vbox}
-
-\def\dodocombination
- {\vbox
- {\forgetall % \setupwhitespace[\v!none]%
- \let\next\vbox
- \expanded{\processallactionsinset[\combinationparameter\c!location]}
- [ \v!top=>\let\next\depthonlybox, % \tbox,
- \v!middle=>\let\next\halfwaybox]%
- \next{\copy0}%
- % we need to save the caption for a next alignment line
- \saveoncombinationstack2}%
- \ifnum\totcombination>\plusone
- \global\advance\totcombination\minusone
- \global\advance\horcombination\minusone
- \ifnum\horcombination=\zerocount
- \def\next
- {\cr
- \flushcombinationstack
- \noalign
- {\forgetall % \setupwhitespace[\v!none]% no
- \global\setbox\combinationstack\emptybox
- \nointerlineskip
- \combinationparameter\c!after
- \combinationparameter\c!before
- \vss
- \nointerlineskip}%
- \global\horcombination\maxhorcombination\relax
- \docombination}%
- \else
- \def\next
- {&&&\hskip\combinationparameter\c!distance&\docombination}%
- \fi
- \else
- \def\next
- {\cr
- \flushcombinationstack
- \egroup}%
- \fi
- \next}
-
-% formally ok:
-%
-% \def\stopcombination
-% {\egroup
-% \egroup}
-%
-% more robust:
-%
-% \def\stopcombination
-% {{}{}{}{}{}{}{}{}% catches (at most 4) missing entries
-% \egroup
-% \egroup}
-%
-% even better:
-
-\def\stopcombination
- {{\scratchtoks{{}{}{}}\dorecurse\totcombination{\appendtoks{}{}{}{}\to\scratchtoks}\expandafter}\the\scratchtoks
- \egroup
- \egroup}
-
-\newbox\combinationstack
-
-\def\saveoncombinationstack#1%
- {\global\setbox\combinationstack\hbox
- {\hbox{\box#1}\unhbox\combinationstack}}
-
-\def\flushcombinationstack
- {\noalign
- {\ifdim\ht\combinationstack>\zeropoint
-\nointerlineskip % nieuw
- \combinationparameter\c!inbetween
- \global\horcombination\maxhorcombination
- \globallet\doflushcombinationstack\dodoflushcombinationstack
- \else
- \global\setbox\combinationstack\emptybox
- \globallet\doflushcombinationstack\donothing
- \fi}%
- \doflushcombinationstack\crcr}
-
-\gdef\dodoflushcombinationstack
- {\global\setbox\combinationstack\hbox
- {\unhbox\combinationstack
- \global\setbox1\lastbox}%
- \box1% \ruledhbox{\box1}%
- \global\advance\horcombination\minusone\relax
- \ifnum\horcombination>\zerocount
- \def\next{&&&&\doflushcombinationstack}%
- \else
- \global\setbox\combinationstack\emptybox
- %\let\next\relax
- \@EA\gobbleoneargument
- \fi
- \next}
-
-\setupcombinations
- [\c!width=\v!fit,
- \c!height=\v!fit,
- \c!distance=1em,
- \c!location=\v!bottom, % can be something {top,left}
- \c!before=\blank,
- \c!inbetween={\blank[\v!medium]},
- \c!style=,
- \c!color=,
- \c!after=,
- \c!align=\v!middle]
-
-%D \macros
-%D {startfloatcombination}
-%D
-%D \setupexternalfigures[directory={../sample}]
-%D \startbuffer
-%D \placefigure
-%D [left,none]
-%D {}
-%D {\startfloatcombination[2*2]
-%D \placefigure{alpha}{\externalfigure[cow.pdf][width=1cm]}
-%D \placefigure{beta} {\externalfigure[cow.pdf][width=2cm]}
-%D \placefigure{gamma}{\externalfigure[cow.pdf][width=3cm]}
-%D \placefigure{delta}{\externalfigure[cow.pdf][width=4cm]}
-%D \stopfloatcombination}
-%D
-%D \input tufte
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-\def\startfloatcombination
- {\dodoubleempty\dostartfloatcombination}
-
-\def\dostartfloatcombination[#1][#2]%
- {\vbox\bgroup
- %\insidecolumnstrue % trick, forces no centering, todo: proper switch/feature
- \chardef\postcenterfloatmethod\zerocount
- \forcelocalfloats
- \def\stopfloatcombination
- {\scratchtoks\emptytoks
- \dorecurse\noflocalfloats
- {\appendetoks{\noexpand\getlocalfloat{\recurselevel}}{}\to\scratchtoks}%
- \expanded{\startcombination[#1]\the\scratchtoks}\stopcombination
- \resetlocalfloats
- \egroup}}
-
-\def\placerelativetoeachother#1#2%
- {\bgroup
- \dowithnextbox
- {\bgroup
- \setbox0\box\nextbox
- \dowithnextbox
- {\setbox2\box\nextbox
- #1{#2#########2\cr\box0\cr\box2\cr}
- \egroup
- \egroup}
- \hbox}
- \hbox}
-
-\def\placeontopofeachother{\placerelativetoeachother\halign\hss}
-\def\placesidebyside {\placerelativetoeachother\valign\vss}
-
-% this will be replaced or go away, never used
-
-\def\douseexternalfiles[#1][#2]%
- {\getparameters
- [\??fi#1]
- [\c!file=,
- \c!bodyfont=,
- \c!option=,
- #2]}
-
-\def\useexternalfiles
- {\dodoubleargument\douseexternalfiles}
-
-\def\dostelexternefilesin[#1][#2]%
- {\doifundefinedelse{\??fi#1\c!file}
- {\useexternalfiles[#1][#2]}
- {\getparameters[\??fi#1][#2]}}
-
-\def\stelexternefilesin
- {\dodoubleargument\dostelexternefilesin}
-
-\def\verwerkexternefile#1#2#3%
- {\bgroup
- \getparameters[\??fi#1][\c!file=,#3]%
- \doinputonce{\getvalue{\??fi#1\c!file}}%
- \ExpandFirstAfter\switchtobodyfont[\getvalue{\??fi#1\c!bodyfont}]%
- \readsysfile{#2} % beter: loc of fix gebied
- \donothing
- {\showmessage\m!systems{41}{#2,#1}}%
- \egroup}
-
-\def\douseexternalfile[#1][#2][#3][#4]%
- {\stelexternefilesin[#1][]%
- \doinputonce{\getvalue{\??fi#1\c!file}}%
- \doifelsenothing{#2}
- {\setvalue{#3}{\verwerkexternefile{#1}{#3}{#4}}}
- {\setvalue{#2}{\verwerkexternefile{#1}{#3}{#4}}}}
-
-\def\useexternalfile
- {\doquadrupleargument\douseexternalfile}
-
-\useexternalfiles
- [pictex]
- [\c!bodyfont=\v!small,
- \c!file=pictex]
-
-\useexternalfiles
- [table]
- [\c!file=table]
-
-%D A couple of examples, demonstrating how the depth is
-%D taken care of:
-%D
-%D \startbuffer
-%D test\rotate[frame=on, rotation=0] {gans}%
-%D test\rotate[frame=on, rotation=90] {gans}%
-%D test\rotate[frame=on, rotation=180]{gans}%
-%D test\rotate[frame=on, rotation=270]{gans}%
-%D test
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-% When we rotate over arbitrary angles, we need to relocate the
-% resulting box because rotation brings that box onto the negative
-% axis. The calculations (mostly sin and cosine) need to be tuned for
-% the way a box is packages (i.e. the refence point). A typical example
-% of drawing, scribbling, and going back to the days of school math.
-%
-% We do a bit more calculations than needed, simply because that way
-% it's easier to debug the code.
-
-\def\dododorotatenextbox
- {\setbox\nextbox\vbox to \@@layerysiz
- {\vfill
- \hbox to \@@layerxsiz
- {\dostartrotation\@@rorotation
- \nextboxwd\zeropoint
- \nextboxht\zeropoint
- \flushnextbox
- \dostoprotation
- \hfill}%
- \kern\@@layerypos}%
- \setbox\nextbox\hbox
- {\kern\@@layerxpos
- \kern\@@layerxoff
- \lower\@@layeryoff\flushnextbox}}
-
-\def\dodorotatenextbox#1#2% quite some trial and error -)
- {\dontshowcomposition
- \dontcomplain
- \ifnum#2=\plusfour
- % new, location=middle
- \!!widthb \nextboxwd
- \!!heightb\nextboxht
- \!!depthb \nextboxdp
- \setbox\nextbox\vbox{\vskip.5\nextboxht\hskip-.5\nextboxwd\flushnextbox}%
- \smashbox\nextbox
- \fi
- \!!widtha \nextboxwd
- \!!heighta\nextboxht
- \!!deptha \nextboxdp
- \!!doneafalse
- \!!donebfalse
- \ifcase#2\or
- % 1: fit
- \or
- % 2: depth, not fit
- \!!doneatrue
- \!!donebtrue
- \or
- % 3: depth, fit
- \!!donebtrue
- \fi
- \setbox\nextbox\vbox{\hbox{\raise\nextboxdp\flushnextbox}}%
- \!!dimena \nextboxht
- \calculatecos\@@rorotation\edef\cos{\calculatedcos\@@rorotation}%
- \calculatesin\@@rorotation\edef\sin{\calculatedsin\@@rorotation}%
- \@@layerxpos\zeropoint
- \@@layerypos\zeropoint
- \@@layerxoff\zeropoint
- \@@layeryoff\zeropoint
- \ifdim\sin\points>\zeropoint
- \ifdim\cos\points>\zeropoint
- \@@layerxsiz \cos\!!widtha
- \@@layerysiz \sin\!!widtha
- \advance\@@layerxsiz \sin\!!dimena
- \advance\@@layerysiz \cos\!!dimena
- \@@layerypos \cos\!!dimena
- \if!!donea
- \@@layerxoff \negated\sin\!!dimena
- \advance\@@layerxoff \sin\!!deptha
- \fi
- \if!!doneb
- \@@layeryoff \cos\!!deptha
- \fi
- \dododorotatenextbox
- \else
- \@@layerxsiz \negated\cos\!!widtha
- \@@layerysiz \sin\!!widtha
- \advance\@@layerxsiz \sin\!!dimena
- \advance\@@layerysiz \negated\cos\!!dimena
- \@@layerxpos \negated\cos\!!widtha
- \if!!donea
- \@@layerxoff -\@@layerxsiz
- \advance\@@layerxoff \sin\!!deptha
- \fi
- \if!!doneb
- \@@layeryoff \negated\cos\!!heighta
- \fi
- \dododorotatenextbox
- \wd\nextbox\if!!donea\sin\!!deptha\else\@@layerxsiz\fi
- \fi
- \else
- \ifdim\cos\points<\zeropoint
- \@@layerxsiz \negated\cos\!!widtha
- \@@layerysiz \negated\sin\!!widtha
- \advance\@@layerxsiz \negated\sin\!!dimena
- \advance\@@layerysiz \negated\cos\!!dimena
- \@@layerxpos \@@layerxsiz
- \@@layerypos \negated\sin\!!widtha
- \if!!donea
- \@@layerxoff -\@@layerxsiz
- \advance\@@layerxoff \negated\sin\!!heighta
- \fi
- \if!!doneb
- \@@layeryoff \@@layerysiz
- \advance\@@layeryoff \cos\!!deptha
- \fi
- \dododorotatenextbox
- \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
- \else
- \@@layerxsiz \cos\!!widtha
- \@@layerysiz \negated\sin\!!widtha
- \advance\@@layerxsiz \negated\sin\!!dimena
- \advance\@@layerysiz \cos\!!dimena
- \ifdim\sin\points=\zeropoint
- \@@layerxpos \zeropoint
- \@@layerxoff \zeropoint
- \@@layerypos \@@layerysiz
- \if!!doneb
- \@@layeryoff \!!deptha
- \fi
- \else
- \@@layerypos \@@layerysiz
- \@@layerxpos \negated\sin\!!dimena
- \if!!donea
- \@@layerxoff -\@@layerxsiz
- \advance\@@layerxoff \negated\sin\!!heighta
- \fi
- \if!!doneb
- \@@layeryoff \negated\sin\!!deptha
- \fi
- \fi
- \dododorotatenextbox
- \ifdim\sin\points=\zeropoint
- \else
- \wd\nextbox\if!!donea\negated\sin\!!heighta\else\@@layerxsiz\fi
- \fi
- \fi
- \fi
- % new, location=middle
- \ifnum#2=\plusfour
- \setbox\nextbox\vbox{\vskip-.5\!!heightb\hskip.5\!!heightb\flushnextbox}%
- \nextboxwd\!!widthb
- \nextboxht\!!heightb
- \nextboxdp\!!depthb
- \fi}
-
-\def\dorotatenextbox#1#2%
- {\doifsomething{#1}
- {\edef\@@rorotation{\realnumber{#1}}% get rid of leading zeros and spaces
- \setbox\nextbox\vbox{\flushnextbox}% not really needed
- \dodorotatenextbox\@@rorotation#2}%
- \hbox{\boxcursor\flushnextbox}}
-
-\def\dodorotatebox#1% {angle} \hbox/\vbox/\vtop
- {\bgroup\hbox\bgroup % compatibility hack
- \dowithnextbox
- {\dorotatenextbox{#1}\plusone
- \egroup\egroup}}
-
-\def\dorotatebox#1% {angle} \hbox/\vbox/\vtop
- {\ifcase#1\relax
- \expandafter\gobbleoneargument
- \else
- \expandafter\dodorotatebox
- \fi{#1}}
-
-\unexpanded\def\rotate % \bgroup: \rotate kan argument zijn
- {\bgroup\complexorsimpleempty\rotate}
-
-% \def\complexrotate[#1]% framed met diepte !
-% {\getparameters[\??ro][#1]%
-% \processaction
-% [\@@rolocation]
-% [ \v!depth=>\!!counta\plusthree\donefalse,% depth fit - raw box
-% \v!fit=>\!!counta\plustwo \donefalse,% depth tight - raw box
-% \v!broad=>\!!counta\plusone \donefalse,% nodepth fit - raw box
-% \v!high=>\!!counta\plusone \donetrue ,% nodepth fit - framed
-% \v!middle=>\!!counta\plusfour \donefalse,% centered, keep dimensions
-% \s!default=>\!!counta\plusthree\donetrue ,% depth fit - framed
-% \s!unknown=>\!!counta\plusthree\donetrue ]% depth fit - framed
-% \ifdone
-% \def\docommand{\localframed[\??ro][#1,\c!location=]}%
-% \else
-% \let\docommand\relax
-% \fi
-% \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
-
-\setvalue{\??ro::\c!location::\v!depth }{\!!counta\plusthree\donefalse} % depth fit - raw box
-\setvalue{\??ro::\c!location::\v!fit }{\!!counta\plustwo \donefalse} % depth tight - raw box
-\setvalue{\??ro::\c!location::\v!broad }{\!!counta\plusone \donefalse} % nodepth fit - raw box
-\setvalue{\??ro::\c!location::\v!high }{\!!counta\plusone \donetrue } % nodepth fit - framed
-\setvalue{\??ro::\c!location::\v!middle }{\!!counta\plusfour \donefalse} % centered, keep dimensions
-\setvalue{\??ro::\c!location::\v!default}{\!!counta\plusthree\donetrue } % depth fit - framed
-
-\def\complexrotate[#1]% framed met diepte !
- {\getparameters[\??ro][#1]%
- \executeifdefined{\??ro::\c!location::\@@rolocation}{\!!counta\plusthree\donetrue}%
- \ifdone
- \def\docommand{\localframed[\??ro][#1,\c!location=]}%
- \else
- \let\docommand\relax
- \fi
- \dowithnextbox{\dorotatenextbox\@@rorotation\!!counta\egroup}\vbox\docommand}
-
-\presetlocalframed[\??ro]
-
-\def\setuprotate
- {\dodoubleargument\getparameters[\??ro]}
-
-\setuprotate
- [\c!rotation=90,
- \c!location=\v!normal,
- \c!width=\v!fit,
- \c!height=\v!fit,
- \c!offset=\v!overlay,
- \c!frame=\v!off]
-
-% \dostepwiserecurse{0}{360}{10}
-% {\startlinecorrection[blank]
-% \hbox
-% {\expanded{\setuprotate[rotation=\recurselevel]}%
-% \traceboxplacementtrue
-% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=depth] {\ruledhbox{\bfb (depth)}}}}%
-% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=fit] {\ruledhbox{\bfb (fit)}}}}%
-% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=broad] {\ruledhbox{\bfb (broad)}}}}%
-% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=normal]{\ruledhbox{\bfb (normal)}}}}%
-% \hbox to .2\hsize{\hss\ruledhbox{\rotate[location=high] {\ruledhbox{\bfb (high)}}}}}
-% \stoplinecorrection}
-
-% to be used in some other places! todo!
-%
-% divides \hsize in fractions, will be made a bit more
-% clever and advanced when needed
-%
-% \horizontaldivision[n/m,elements,distance]
-%
-% \horizontaldivision[2/5,3,1em]
-% \horizontaldivision[2/5,3,1em]
-% \horizontaldivision[1/5,3,1em]
-%
-% \setuphorizontaldivision[afstand=,aantal=] (passend,passend)
-
-\def\??fr{@@fr}
-
-\def\setuphorizontaldivision
- {\dodoubleargument\getparameters[\??fr]}
-
-\def\horizontaldivision
- {\dosingleargument\dohorizontaldivision}
-
-\def\dohorizontaldivision[#1]%
- {\dodohorizontaldivision[#1,,,,,,]}
-
-\def\dodohorizontaldivision[#1/#2,#3,#4,#5]%
- {\doifelsenothing{#3}
- {\doifelse\@@frn\v!fit
- {\!!counta#2\relax}
- {\!!counta\@@frn\relax}}
- {\!!counta#3\relax}%
- \doifelsenothing{#4}
- {\doifelse\@@frdistance\v!fit
- {\!!widtha\zeropoint}
- {\!!widtha\@@frdistance}}
- {\!!widtha#4}%
- \advance\!!counta \minusone
- \multiply\!!widtha \!!counta
- \advance\hsize -\!!widtha
- \divide\hsize #2\relax
- \hsize#1\hsize}
-
-\setuphorizontaldivision
- [\c!distance=\tfskipsize,
- \c!n=\v!fit]
-
-%D This one is for Daniel Pittman, who wanted tight
-%D fractions. We show three versions. First the simple
-%D one using \type {\low} and \type {high}:
-%D
-%D \startbuffer
-%D \def\vfrac#1#2%
-%D {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}
-%D
-%D test \vfrac{1}{2} test \vfrac{123}{456} test
-%D \stopbuffer
-%D
-%D \typebuffer {\showmakeup\getbuffer}
-%D
-%D A better way to handle the kerning is the following, here
-%D we kind of assume that tye slash is symmetrical and has
-%D nearly zero width.
-%D
-%D \startbuffer
-%D \def\vfract#1#2%
-%D {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}
-%D \stopbuffer
-%D
-%D \typebuffer {\showmakeup\getbuffer}
-%D
-%D The third and best alternative is the following:
-%D
-%D {\showmakeup\getbuffer}\crlf\getbuffer
-%D
-%D This time we measure the height of the \type {/} and
-%D shift over the maximum height and depths of this
-%D character and the fractional digits (we use 57 as
-%D sample). Here we combine all methods in one macros.
-
-\chardef\vulgarfractionmethod=3
-
-\definehspace[vulgarfraction][.25em] % [.15em]
-\definesymbol[vulgarfraction][/] % [\raise.2ex\hbox{/}]
-
-\unexpanded\def\vulgarfraction#1#2%
- {\dontleavehmode
- \hbox
- {\def\vulgarfraction{vulgarfraction}%
- \ifcase\vulgarfractionmethod
- #1\symbol[\vulgarfraction]#2%
- \or
- \high{\tx#1\kern-\hspaceamount\empty\vulgarfraction}%
- \symbol[\vulgarfraction]%
- \low {\kern-\hspaceamount\empty\vulgarfraction\tx#2}%
- \or
- \high{\tx#1}%
- \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
- \low{\tx#2}%
- \or
- \setbox0\hbox{\symbol[\vulgarfraction]}%
- \setbox2\hbox{\txx57}%
- \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
- \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
- \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
- \fi}}
-
-\ifx\vfrac\undefined \let\vfrac\vulgarfraction \fi
-
-%D \starttabulate
-%D \HL
-%D \NC \bf method \NC \bf visualization \NC\NR
-%D \HL
-%D \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR
-%D \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR
-%D \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR
-%D \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR
-%D \HL
-%D \stoptabulate
-
-%D Under construction:
-%D
-%D \starttyping
-%D \commalistsentence[aap,noot,mies]
-%D \commalistsentence[aap,noot]
-%D \commalistsentence[aap]
-%D \commalistsentence[a,b,c]
-%D \commalistsentence[a,b,c][{ \& },{ and }]
-%D \commalistsentence[a,b,c][+,-]
-%D \stoptyping
-
-\let\handlecommalistsentence\firstofoneargument
-
-\def\commalistsentenceone{and-1}
-\def\commalistsentencetwo{and-2}
-
-\def\commalistsentence
- {\dodoubleempty\docommalistsentence}
-
-\def\docommalistsentence[#1][#2]%
- {\bgroup
- \getfromcommalist[#2][1]%
- \ifx\commalistelement\empty
- \def\@@commalistsentenceone{\labeltext\commalistsentenceone}%
- \else
- \let\@@commalistsentenceone\commalistelement
- \fi
- \getfromcommalist[#2][2]%
- \ifx\commalistelement\empty
- \def\@@commalistsentencetwo{\labeltext\commalistsentencetwo}%
- \else
- \let\@@commalistsentencetwo\commalistelement
- \fi
- \getcommalistsize[#1]%
- \ifcase\commalistsize\relax
- \def\serializedcommalist{#1}%
- \else
- \let\serializedcommalist\empty
- \scratchcounter\zerocount
- \def\docommand##1%
- {\advance\scratchcounter \plusone
- \ifnum\scratchcounter=\plusone
- \scratchtoks{\handlecommalistsentence{##1}}%
- \else
- \ifnum\scratchcounter=\commalistsize
- \appendtoks\@@commalistsentencetwo\handlecommalistsentence{##1}\to\scratchtoks
- \else
- \appendtoks\@@commalistsentenceone\handlecommalistsentence{##1}\to\scratchtoks
- \fi
- \fi}%
- \processcommacommand[#1]\docommand
- \edef\serializedcommalist{\the\scratchtoks}%
- \fi
- \serializedcommalist
- \egroup}
-
-\def\commacommandsentence[#1]{\@EA\commalistsentence\@EA[#1]}
-
-\ifx\textcomma\undefined \def\textcomma{,} \fi
-
-\setuplabeltext [\s!nl] [and-1=\textcomma\ , and-2= en ]
-\setuplabeltext [\s!en] [and-1=\textcomma\ , and-2=\textcomma\ and ]
-\setuplabeltext [\s!de] [and-1=\textcomma\ , and-2= und ]
-
-%D \macros
-%D {somekindoftab}
-%D
-%D This macro can be used to create tabs:
-%D
-%D \starttyping
-%D \setupheadertexts[{\somekindoftab[alternative=horizontal]{\framed{\realfolio}}}]
-%D \setuptexttexts [{\somekindoftab[alternative=vertical] {\framed{\realfolio}}}]
-%D
-%D \starttext
-%D \showframe \dorecurse{10}{test\page}
-%D \stoptext
-%D \stoptyping
-
-\def\somekindoftab
- {\dosingleempty\dosomekindoftab}
-
-\def\dosomekindoftab[#1]%
- {\bgroup
- \getparameters[xx]
- [\c!alternative=\v!vertical,
- \c!width=\textwidth,\c!height=\textheight,
- \c!n=\lastpage,\c!m=\realpageno,
- #1]%
- \doifelse\xxalternative\v!vertical
- {\dodosomekindoftab\vbox\vskip\xxheight}
- {\dodosomekindoftab\hbox\hskip\xxwidth }}
-
-\def\dodosomekindoftab#1#2#3#4%
- {#1 to #3 \bgroup
- \forgetall
- \ifnum\xxm>\plusone
- #2\zeropoint \!!plus \the\numexpr\xxm -1\relax fill\relax
- \fi
- #4%
- \ifnum\xxm<\xxn\relax
- #2\zeropoint \!!plus \the\numexpr\xxn-\xxm\relax fill\relax
- \fi
- \egroup
- \egroup}
-
-\protect \endinput
diff --git a/tex/context/base/core-nav.mkii b/tex/context/base/core-nav.mkii
new file mode 100644
index 000000000..f4594ab3b
--- /dev/null
+++ b/tex/context/base/core-nav.mkii
@@ -0,0 +1,379 @@
+%D \module
+%D [ file=core-nav,
+%D version=1998.01.15,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Navigation,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Navigation}
+
+\unprotect
+
+%D Support for interactive document is very present in
+%D \CONTEXT\ and interwoven in many modules. This means that in
+%D this module, where we deal with some common navigational
+%D features, there will be quite some forward references.
+%D
+%D When I started implementing hypertext support, the macros
+%D were mostly dealing with things related to locations, that
+%D is click in this location and goto that one. The
+%D functionality of many macro depends on the output medium:
+%D paper or screen. The next boolean holds the state:
+
+\newif\iflocation \def\ifinteractief{\iflocation} % upw comp
+
+%D We also allocate a scratchbox:
+
+\newbox\locationbox
+
+%D There is no interaction at all unless enabled by saying:
+%D
+%D \starttyping
+%D \setupinteraction[state=start]
+%D \stoptyping
+%D
+%D The other settings are:
+%D
+%D \showsetup{setupinteraction}
+%D
+%D In the special driver modules we introduced a switch that
+%D forces page destinations (instead of named ones). We set
+%D this switch here.
+
+\def\setinteractionparameter#1#2% use with case, no checking done
+ {\setvalue{\??ia#1}{#2}} % pass #2, can be \blabla
+
+\def\resetinteractionparameter#1% use with case, no checking done
+ {\letvalue{\??ia#1}\empty}
+
+% \def\interactionparameter#1%
+% {\csname\??ia#1\endcsname}
+
+\newtoks\everysetupinteraction
+
+\def\setupinteraction
+ {\dosingleargument\dodosetupinteraction}
+
+\def\dodosetupinteraction[#1]% % \dosetupinteraction == special
+ {\getparameters[\??ia][#1]%
+ \the\everysetupinteraction}
+
+% todo, move partial append to where the action happens
+
+\appendtoks
+ \doifelse\@@iastate\v!start
+ {\iflocation\else
+ \showmessage\m!interactions2{\ifusepagedestinations\space(PAGE)\fi}%
+ \global\locationtrue
+ \fi}
+ {\iflocation
+ \showmessage\m!interactions3{\ifusepagedestinations\space(PAGE)\fi}%
+ \global\locationfalse
+ \fi}%
+ \iflocation
+ \setsystemmode \v!interaction
+ \else
+ \resetsystemmode\v!interaction
+ \fi
+ \dosetuppageview\@@iafocus
+ \doifsomething\@@iacalculate
+ {\doregistercalculationset\@@iacalculate}%
+ \doifelse\@@iastrut\v!yes
+ \locationstruttrue
+ \locationstrutfalse
+ \doifelse\@@iaclick\v!yes
+ \highlighthyperlinkstrue
+ \highlighthyperlinksfalse
+ \doifelse\@@iasplit\v!yes
+ \locationsplittrue
+ \locationsplitfalse
+ \doifelse\@@iadisplay\v!new
+ \gotonewwindowtrue
+ \gotonewwindowfalse
+ \doifelse\@@iapage\v!yes
+ {\global\usepagedestinationstrue}
+ {\global\usepagedestinationsfalse}%
+\to \everysetupinteraction
+
+%D We have to make sure of some settings:
+
+\def\dolocationstartup
+ {\iflocation
+ \dosetupinteraction
+ \handlereferenceactions\@@iaopenaction \dosetupopenaction
+ \handlereferenceactions\@@iacloseaction\dosetupcloseaction
+ \setupinteractionscreens
+ \global\let\dolocationstartup\relax
+ \fi}
+
+\appendtoks \dolocationstartup \to \everyshipout
+
+\def\dolocationpagecheck % brr pdf dependent
+ {\iflocation
+ \handlereferenceactions\@@iaopenpageaction \dosetupopenpageaction
+ \handlereferenceactions\@@iaclosepageaction\dosetupclosepageaction
+ \fi}
+
+\appendtoks \dolocationpagecheck \to \everyshipout
+
+%D The next few macros are really horrible. For proper
+%D navigation a in||line hypertext fragment must have
+%D comfortable properties, so we must force some minimal
+%D dimensions. On the other hand button, and here I mean those
+%D pieces of text with fancy outlines and/or backgrounds, often
+%D have fixed, preset dimensions.
+%D
+%D To make things even worse, if we choose to let the optimal
+%D dimensions depend on the height and depth of a strut, a not
+%D too uncommon practice in \TEX, we have to deal with the fact
+%D that such a strut, set inside a box, is unknown too the
+%D outside world.
+%D
+%D The solution lays in passing the strut characteristics in
+%D a proper way, in our case by applying \type{\presetgoto}:
+%D
+%D \starttyping
+%D {some piece of text \presetgoto}
+%D \stoptyping
+%D
+%D This macro stores the current strut values.
+
+\newif\iflocationstrut
+\newif\iflocationsplit
+
+\def\resetgoto
+ {\globallet\@@ia@@hoogte\!!zeropoint
+ \globallet\@@ia@@diepte\!!zeropoint}
+
+\resetgoto
+
+\def\presetgoto
+ {\iflocationstrut
+ \setstrut
+ %\xdef\@@ia@@hoogte{\the\strutht}%
+ %\xdef\@@ia@@diepte{\the\strutdp}%
+ \globallet\@@ia@@hoogte\strutheight
+ \globallet\@@ia@@diepte\strutdepth
+ \else
+ \globallet\@@ia@@hoogte\@@iaheight
+ \globallet\@@ia@@diepte\@@iadepth
+ \fi}
+
+%D In the macros that deal with making areas into hyperlinks,
+%D we use:
+
+\newbox\driverresources
+
+\def\collectdriverresource#1%
+ {\global\setbox\driverresources\hbox{\box\driverresources#1}}
+
+\def\flushdriverresources
+ {\ifvoid\driverresources\else\box\driverresources\fi}
+
+\def\dohandlegoto#1#2#3%
+ {\ifsecondaryreference
+ \bgroup\setbox0\hbox{#2#3}\egroup
+ \else
+ \hbox
+ {\setbox0\hbox{#1}%
+ \ifdim\wd0<\@@iawidth\relax
+ \buttonwidth\@@iawidth\relax
+ \else
+ \buttonwidth\wd0
+ \fi
+ \ifdim\ht0<\@@ia@@hoogte\relax
+ \buttonheight\@@ia@@hoogte\relax
+ \else
+ \buttonheight\ht0
+ \fi
+ \ifdim\dp0<\@@ia@@diepte\relax
+ \dimen0=\@@ia@@diepte\relax % = !
+ \else
+ \dimen0\dp0
+ \fi
+ \advance\buttonheight \dimen0
+ \setbox2\hbox
+ {\lower\dimen0\hbox
+ {\dontcomplain
+ \dimen0=.5\wd0 % direct skipping is faster of course
+ \advance\dimen0 -.5\buttonwidth % buts this is nicer
+ \hskip\dimen0#2#3}}% when visualizing things
+ \naturalhbox % needed for omega / moved from plus-omg
+ {\ifreversegoto
+ \dimen0\wd0\box0\kern-\dimen0\smashbox2\box2\kern\dimen0
+ \else
+ \smashbox2\box2\box0
+ \fi
+ \flushdriverresources}%
+ \resetgoto}%
+ \fi}
+
+%D The secondary references are processed but not typeset. The
+%D special driver must collect the data needed.
+
+%D The width of the active area depends on the dimensions
+%D preset, the actual dimens and/or the height and depth of the
+%D strut.
+%D
+%D Normally the hyper active area is laid on top of the text.
+%D This enables stacking hyperlinks on top of each other. When,
+%D for some reason the opposite is prefered, one can use the
+%D next boolean to signal this wish.
+
+\newif\ifreversegoto \reversegotofalse
+
+%D As long as there a natural feeling of what can be considered
+%D hyper active or not, we have to tell users where they can
+%D possibly click. We've already seen a few macros that deal
+%D with this visualization, something we definitely do not let
+%D up to the viewer. One way of telling is using a distinctive
+%D typeface, another way is using color.
+%D
+%D There are two colors involved: one for normal hyperlinks,
+%D and one for those that point to the currentpage, the
+%D contrast color.
+
+\definecolor [interactioncolor] [r=0, g=.6, b=0]
+\definecolor [interactioncontrastcolor] [r=.8, g=0, b=0]
+
+\definecolor [interactiekleur] [interactioncolor]
+\definecolor [interactiecontrastkleur] [interactioncontrastcolor]
+
+%D The next few macros are responsible for highlighting hyper
+%D links. The first one, \type{\showlocation}, is used in those
+%D situations where the typeface is handled by the calling
+%D macro.
+
+\def\interactioncolor % todo \??ia as argument
+ {\iflocation
+ \ifrealreferencepage
+ \@@iacontrastcolor
+ \else
+ \@@iacolor
+ \fi
+ \fi}
+
+%D CHECK WHERE USED / CONSISTENCY
+
+\def\showlocation#1%
+ {\iflocation\color[\@@iacolor]{#1\presetgoto}\else#1\fi}
+
+%D When local color settings are to be used, we can use the
+%D next macro, where \type{#1} is a tag like \type{\??tg} and
+%D \type{#2} some text.
+
+\def\showcoloredlocation#1#2%
+ {\iflocation
+ \color[\getvalue{#1\c!color}]{#2\presetgoto}%
+ \else
+ #2%
+ \fi}
+
+%D When we're dealing with pure page references, contrast
+%D colors are used when we are already at the page mentioned.
+
+\def\showcontrastlocation#1#2#3% the \@EA is needed
+ {\iflocation
+ \ifnum#2=\realpageno\relax
+ \doifelsevaluenothing{#1\c!color}
+ {#3\presetgoto}
+ {\color[\getvalue{#1\c!contrastcolor}]{#3\presetgoto}}%
+ \else
+ \color[\getvalue{#1\c!color}]{#3\presetgoto}%
+ \fi
+ \else
+ #3%
+ \fi}
+
+%D The next simple macro can be used in color specifications,
+%D like \type{\color[\locationcolor{green}]}.
+
+\def\locationcolor#1%
+ {\iflocation#1\fi}
+
+%D More tokens are spend when we want both typeface and color
+%D highlighting.
+
+\def\dolocationattributes#1#2#3#4%
+ {\bgroup
+ \let\fontattribute\empty
+ \let\colorattribute\empty
+ \doifdefined{#1#2}{\def\fontattribute{\getvalue{#1#2}}}%
+ \iflocation
+ \doifdefined{#1#3}{\def\colorattribute{\getvalue{#1#3}}}%
+ \fi
+ \startcolor[\colorattribute]%
+ \@EA\doconvertfont\@EA{\fontattribute}{#4}% no \edef, but \@EA here
+ \stopcolor
+ \egroup}
+
+\def\navigating
+ {\dolocationattributes\??ia\c!style\c!color}
+
+%D Although not decently supported in current viewers, a
+%D provisory hiding mechanims is implemented. Areas marked as
+%D such, are visible on screen, but invisible on paper. Don't
+%D trust this mechanism yet!
+
+\def\dostartinteraction
+ {\bgroup
+ \let\stopinteraction\egroup
+ \dowithnextbox{\dostarthide\flushnextbox\dostophide\egroup}\hbox}
+
+\let\startinteraction = \relax
+\let\stopinteraction = \relax
+
+% in the future:
+%
+% eerst boolean invoeren bij menu, achtergrond, balk, button
+% enz; verder startinteractie een argument meegeven {#1} ->
+% \getvalue{#1\c!print}=={\v!ja} enz. Consequent menubutton
+% gebruiken!
+
+\def\@@iatimestamp
+ {\the\normalyear
+ \ifnum\normalmonth<10 0\fi\the\normalmonth
+ \ifnum\normalday <10 0\fi\the\normalday}
+
+% happens in core-fld
+%
+% \definereference [AtOpenInitializeForm] [\v!geen]
+
+\setupinteraction % start fit page and reset form
+ [\c!state=\v!stop,
+ \c!page=\v!no,
+ \c!click=\v!yes,
+ \c!display=,
+ %\c!openaction={\v!firstpage,AtOpenInitializeForm},
+ %\c!openaction={\v!firstpage,\v!ResetForm},
+ %\c!openaction=\v!ResetForm, % too buggy in reader 4.05
+ \c!openaction=,
+ \c!closeaction=,
+ \c!openpageaction=,
+ \c!closepageaction=,
+ \c!display=\v!normal,
+ \c!focus=\v!fit,
+ \c!menu=\v!off,
+ \c!style=\v!bold,
+ \c!calculate=,
+ \c!strut=\v!yes,
+ \c!split=\v!yes,
+ \c!color=interactioncolor,
+ \c!contrastcolor=interactioncontrastcolor,
+ \c!symbolset=,
+ \c!width=1em,
+ \c!height=\!!zeropoint,
+ \c!depth=\!!zeropoint,
+ \c!title=\jobname, % needed for fdf/x
+ \c!subtitle=,
+ \c!author=,
+ \c!keyword=,
+ \c!date=\@@iatimestamp]
+
+\protect \endinput
diff --git a/tex/context/base/core-nav.mkiv b/tex/context/base/core-nav.mkiv
new file mode 100644
index 000000000..e079f5f08
--- /dev/null
+++ b/tex/context/base/core-nav.mkiv
@@ -0,0 +1,425 @@
+%D \module
+%D [ file=core-nav,
+%D version=1998.01.15,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Navigation,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Core Macros / Navigation}
+
+\unprotect
+
+%D Support for interactive document is very present in
+%D \CONTEXT\ and interwoven in many modules. This means that in
+%D this module, where we deal with some common navigational
+%D features, there will be quite some forward references.
+%D
+%D When I started implementing hypertext support, the macros
+%D were mostly dealing with things related to locations, that
+%D is click in this location and goto that one. The
+%D functionality of many macro depends on the output medium:
+%D paper or screen. The next boolean holds the state:
+
+\newif\iflocation \def\ifinteractief{\iflocation} % upw comp
+
+%D We also allocate a scratchbox:
+
+\newbox\locationbox
+
+%D There is no interaction at all unless enabled by saying:
+%D
+%D \starttyping
+%D \setupinteraction[state=start]
+%D \stoptyping
+%D
+%D The other settings are:
+%D
+%D \showsetup{setupinteraction}
+%D
+%D In the special driver modules we introduced a switch that
+%D forces page destinations (instead of named ones). We set
+%D this switch here.
+
+\def\setinteractionparameter#1#2% use with case, no checking done
+ {\setvalue{\??ia#1}{#2}} % pass #2, can be \blabla
+
+\def\resetinteractionparameter#1% use with case, no checking done
+ {\letvalue{\??ia#1}\empty}
+
+% \def\interactionparameter#1%
+% {\csname\??ia#1\endcsname}
+
+\newtoks\everysetupinteraction
+
+\def\setupinteraction
+ {\dosingleargument\dodosetupinteraction}
+
+\def\dodosetupinteraction[#1]% % \dosetupinteraction == special
+ {\getparameters[\??ia][#1]%
+ \the\everysetupinteraction}
+
+% todo, move partial append to where the action happens
+
+\appendtoks
+ \doifelse\@@iastate\v!start
+ {\iflocation\else
+ \showmessage\m!interactions2{\ifusepagedestinations\space(PAGE)\fi}%
+ \global\locationtrue
+ \fi}
+ {\iflocation
+ \showmessage\m!interactions3{\ifusepagedestinations\space(PAGE)\fi}%
+ \global\locationfalse
+ \fi}%
+ \iflocation
+ \setsystemmode \v!interaction
+ \else
+ \resetsystemmode\v!interaction
+ \fi
+ \dosetuppageview\@@iafocus
+ \doifsomething\@@iacalculate
+ {\doregistercalculationset\@@iacalculate}%
+ \doifelse\@@iastrut\v!yes
+ \locationstruttrue
+ \locationstrutfalse
+ \doifelse\@@iaclick\v!yes
+ \highlighthyperlinkstrue
+ \highlighthyperlinksfalse
+ \doifelse\@@iasplit\v!yes
+ \locationsplittrue
+ \locationsplitfalse
+ \doifelse\@@iadisplay\v!new
+ \gotonewwindowtrue
+ \gotonewwindowfalse
+ \doifelse\@@iapage\v!yes
+ {\global\usepagedestinationstrue}
+ {\global\usepagedestinationsfalse}%
+\to \everysetupinteraction
+
+%D We have to make sure of some settings:
+
+\def\dolocationstartup
+ {\iflocation
+ \dosetupinteraction
+ \handlereferenceactions\@@iaopenaction \dosetupopenaction
+ \handlereferenceactions\@@iacloseaction\dosetupcloseaction
+ \setupinteractionscreens
+ \global\let\dolocationstartup\relax
+ \fi}
+
+\appendtoks \dolocationstartup \to \everyshipout
+
+\def\dolocationpagecheck % brr pdf dependent
+ {\iflocation
+ \handlereferenceactions\@@iaopenpageaction \dosetupopenpageaction
+ \handlereferenceactions\@@iaclosepageaction\dosetupclosepageaction
+ \fi}
+
+\appendtoks \dolocationpagecheck \to \everyshipout
+
+%D The next few macros are really horrible. For proper
+%D navigation a in||line hypertext fragment must have
+%D comfortable properties, so we must force some minimal
+%D dimensions. On the other hand button, and here I mean those
+%D pieces of text with fancy outlines and/or backgrounds, often
+%D have fixed, preset dimensions.
+%D
+%D To make things even worse, if we choose to let the optimal
+%D dimensions depend on the height and depth of a strut, a not
+%D too uncommon practice in \TEX, we have to deal with the fact
+%D that such a strut, set inside a box, is unknown too the
+%D outside world.
+%D
+%D The solution lays in passing the strut characteristics in
+%D a proper way, in our case by applying \type{\presetgoto}:
+%D
+%D \starttyping
+%D {some piece of text \presetgoto}
+%D \stoptyping
+%D
+%D This macro stores the current strut values.
+
+\newif\iflocationstrut
+\newif\iflocationsplit
+
+\def\resetgoto
+ {\globallet\@@ia@@hoogte\!!zeropoint
+ \globallet\@@ia@@diepte\!!zeropoint}
+
+\resetgoto
+
+\def\presetgoto
+ {\iflocationstrut
+ \setstrut
+ %\xdef\@@ia@@hoogte{\the\strutht}%
+ %\xdef\@@ia@@diepte{\the\strutdp}%
+ \globallet\@@ia@@hoogte\strutheight
+ \globallet\@@ia@@diepte\strutdepth
+ \else
+ \globallet\@@ia@@hoogte\@@iaheight
+ \globallet\@@ia@@diepte\@@iadepth
+ \fi}
+
+%D In the macros that deal with making areas into hyperlinks,
+%D we use:
+
+\newbox\driverresources
+
+\def\collectdriverresource#1%
+ {\global\setbox\driverresources\hbox{\box\driverresources#1}}
+
+\def\flushdriverresources
+ {\ifvoid\driverresources\else\box\driverresources\fi}
+
+% \def\dohandlegoto#1#2#3%
+% {\ifsecondaryreference
+% \bgroup\setbox0\hbox{#2#3}\egroup
+% \else
+% \hbox
+% {\setbox0\hbox{#1}%
+% \ifdim\wd0<\@@iawidth\relax
+% \buttonwidth\@@iawidth\relax
+% \else
+% \buttonwidth\wd0
+% \fi
+% \ifdim\ht0<\@@ia@@hoogte\relax
+% \buttonheight\@@ia@@hoogte\relax
+% \else
+% \buttonheight\ht0
+% \fi
+% \ifdim\dp0<\@@ia@@diepte\relax
+% \dimen0=\@@ia@@diepte\relax % = !
+% \else
+% \dimen0\dp0
+% \fi
+% \advance\buttonheight \dimen0
+% \setbox2\hbox
+% {\lower\dimen0\hbox
+% {\dontcomplain
+% \dimen0=.5\wd0 % direct skipping is faster of course
+% \advance\dimen0 -.5\buttonwidth % buts this is nicer
+% \hskip\dimen0#2#3}}% when visualizing things
+% \naturalhbox % needed for omega / moved from plus-omg
+% {\ifreversegoto
+% \dimen0\wd0\box0\kern-\dimen0\smashbox2\box2\kern\dimen0
+% \else
+% \smashbox2\box2\box0
+% \fi
+% \flushdriverresources}%
+% \resetgoto}%
+% \fi}
+
+\def\dohandlegoto#1#2#3%
+ {\ifcollectreferenceactions
+ % this happens here while in mkii elsewhere, better is to deal with
+ % in in the ref module but that's for later to deal with
+ \bgroup\setbox\scratchbox\hbox{#2#3}\egroup
+ \ifsecondaryreference \else
+ \resetgoto
+ \fi
+ \ifsecondaryreference\else#1\resetgoto\fi
+ \else\ifsecondaryreference
+ \bgroup\setbox\scratchbox\hbox{#2#3}\egroup
+ \else
+ \hbox
+ {\setbox0\hbox{#1}%
+ \ifdim\wd0<\@@iawidth\relax
+ \buttonwidth\@@iawidth\relax
+ \else
+ \buttonwidth\wd0
+ \fi
+ \ifdim\ht0<\@@ia@@hoogte\relax
+ \buttonheight\@@ia@@hoogte\relax
+ \else
+ \buttonheight\ht0
+ \fi
+ \ifdim\dp0<\@@ia@@diepte\relax
+ \dimen0=\@@ia@@diepte\relax % = !
+ \else
+ \dimen0\dp0
+ \fi
+ \advance\buttonheight \dimen0
+ \setbox2\hbox
+ {\lower\dimen0\hbox
+ {\dontcomplain
+ \dimen0=.5\wd0 % direct skipping is faster of course
+ \advance\dimen0 -.5\buttonwidth % buts this is nicer
+ \hskip\dimen0#2#3}}% when visualizing things
+ \naturalhbox % needed for omega / moved from plus-omg
+ {\ifreversegoto
+ \dimen0\wd0\box0\kern-\dimen0\smashbox2\box2\kern\dimen0
+ \else
+ \smashbox2\box2\box0
+ \fi
+ \flushdriverresources}%
+ \resetgoto}%
+ \fi\fi}
+
+%D The secondary references are processed but not typeset. The
+%D special driver must collect the data needed.
+
+%D The width of the active area depends on the dimensions
+%D preset, the actual dimens and/or the height and depth of the
+%D strut.
+%D
+%D Normally the hyper active area is laid on top of the text.
+%D This enables stacking hyperlinks on top of each other. When,
+%D for some reason the opposite is prefered, one can use the
+%D next boolean to signal this wish.
+
+\newif\ifreversegoto \reversegotofalse
+
+%D As long as there a natural feeling of what can be considered
+%D hyper active or not, we have to tell users where they can
+%D possibly click. We've already seen a few macros that deal
+%D with this visualization, something we definitely do not let
+%D up to the viewer. One way of telling is using a distinctive
+%D typeface, another way is using color.
+%D
+%D There are two colors involved: one for normal hyperlinks,
+%D and one for those that point to the currentpage, the
+%D contrast color.
+
+\definecolor [interactioncolor] [r=0, g=.6, b=0]
+\definecolor [interactioncontrastcolor] [r=.8, g=0, b=0]
+
+\definecolor [interactiekleur] [interactioncolor]
+\definecolor [interactiecontrastkleur] [interactioncontrastcolor]
+
+%D The next few macros are responsible for highlighting hyper
+%D links. The first one, \type{\showlocation}, is used in those
+%D situations where the typeface is handled by the calling
+%D macro.
+
+\def\interactioncolor % todo \??ia as argument
+ {\iflocation
+ \ifrealreferencepage
+ \@@iacontrastcolor
+ \else
+ \@@iacolor
+ \fi
+ \fi}
+
+%D CHECK WHERE USED / CONSISTENCY
+
+\def\showlocation#1%
+ {\iflocation\color[\@@iacolor]{#1\presetgoto}\else#1\fi}
+
+%D When local color settings are to be used, we can use the
+%D next macro, where \type{#1} is a tag like \type{\??tg} and
+%D \type{#2} some text.
+
+\def\showcoloredlocation#1#2%
+ {\iflocation
+ \color[\getvalue{#1\c!color}]{#2\presetgoto}%
+ \else
+ #2%
+ \fi}
+
+%D When we're dealing with pure page references, contrast
+%D colors are used when we are already at the page mentioned.
+
+\def\showcontrastlocation#1#2#3% the \@EA is needed
+ {\iflocation
+ \ifnum#2=\realpageno\relax
+ \doifelsevaluenothing{#1\c!color}
+ {#3\presetgoto}
+ {\color[\getvalue{#1\c!contrastcolor}]{#3\presetgoto}}%
+ \else
+ \color[\getvalue{#1\c!color}]{#3\presetgoto}%
+ \fi
+ \else
+ #3%
+ \fi}
+
+%D The next simple macro can be used in color specifications,
+%D like \type{\color[\locationcolor{green}]}.
+
+\def\locationcolor#1%
+ {\iflocation#1\fi}
+
+%D More tokens are spend when we want both typeface and color
+%D highlighting.
+
+\def\dolocationattributes#1#2#3#4%
+ {\bgroup
+ \let\fontattribute\empty
+ \let\colorattribute\empty
+ \doifdefined{#1#2}{\def\fontattribute{\getvalue{#1#2}}}%
+ \iflocation
+ \doifdefined{#1#3}{\def\colorattribute{\getvalue{#1#3}}}%
+ \fi
+ \startcolor[\colorattribute]%
+ \@EA\doconvertfont\@EA{\fontattribute}{#4}% no \edef, but \@EA here
+ \stopcolor
+ \egroup}
+
+\def\navigating
+ {\dolocationattributes\??ia\c!style\c!color}
+
+%D Although not decently supported in current viewers, a
+%D provisory hiding mechanims is implemented. Areas marked as
+%D such, are visible on screen, but invisible on paper. Don't
+%D trust this mechanism yet!
+
+\def\dostartinteraction
+ {\bgroup
+ \let\stopinteraction\egroup
+ \dowithnextbox{\dostarthide\flushnextbox\dostophide\egroup}\hbox}
+
+\let\startinteraction = \relax
+\let\stopinteraction = \relax
+
+% in the future:
+%
+% eerst boolean invoeren bij menu, achtergrond, balk, button
+% enz; verder startinteractie een argument meegeven {#1} ->
+% \getvalue{#1\c!print}=={\v!ja} enz. Consequent menubutton
+% gebruiken!
+
+\def\@@iatimestamp
+ {\the\normalyear
+ \ifnum\normalmonth<10 0\fi\the\normalmonth
+ \ifnum\normalday <10 0\fi\the\normalday}
+
+% happens in core-fld
+%
+% \definereference [AtOpenInitializeForm] [\v!geen]
+
+\setupinteraction % start fit page and reset form
+ [\c!state=\v!stop,
+ \c!page=\v!no,
+ \c!click=\v!yes,
+ \c!display=,
+ %\c!openaction={\v!firstpage,AtOpenInitializeForm},
+ %\c!openaction={\v!firstpage,\v!ResetForm},
+ %\c!openaction=\v!ResetForm, % too buggy in reader 4.05
+ \c!openaction=,
+ \c!closeaction=,
+ \c!openpageaction=,
+ \c!closepageaction=,
+ \c!display=\v!normal,
+ \c!focus=\v!fit,
+ \c!menu=\v!off,
+ \c!style=\v!bold,
+ \c!calculate=,
+ \c!strut=\v!yes,
+ \c!split=\v!yes,
+ \c!color=interactioncolor,
+ \c!contrastcolor=interactioncontrastcolor,
+ \c!symbolset=,
+ \c!width=1em,
+ \c!height=\!!zeropoint,
+ \c!depth=\!!zeropoint,
+ \c!title=\jobname, % needed for fdf/x
+ \c!subtitle=,
+ \c!author=,
+ \c!keyword=,
+ \c!date=\@@iatimestamp]
+
+\protect \endinput
diff --git a/tex/context/base/core-nav.tex b/tex/context/base/core-nav.tex
deleted file mode 100644
index 045a05123..000000000
--- a/tex/context/base/core-nav.tex
+++ /dev/null
@@ -1,379 +0,0 @@
-%D \module
-%D [ file=core-nav,
-%D version=1998.01.15,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Navigation,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Navigation}
-
-\unprotect
-
-%D Support for interactive document is very present in
-%D \CONTEXT\ and interwoven in many modules. This means that in
-%D this module, where we deal with some common navigational
-%D features, there will be quite some forward references.
-%D
-%D When I started implementing hypertext support, the macros
-%D were mostly dealing with things related to locations, that
-%D is click in this location and goto that one. The
-%D functionality of many macro depends on the output medium:
-%D paper or screen. The next boolean holds the state:
-
-\newif\iflocation \def\ifinteractief{\iflocation} % upw comp
-
-%D We also allocate a scratchbox:
-
-\newbox\locationbox
-
-%D There is no interaction at all unless enabled by saying:
-%D
-%D \starttyping
-%D \setupinteraction[state=start]
-%D \stoptyping
-%D
-%D The other settings are:
-%D
-%D \showsetup{setupinteraction}
-%D
-%D In the special driver modules we introduced a switch that
-%D forces page destinations (instead of named ones). We set
-%D this switch here.
-
-\def\setinteractionparameter#1#2% use with case, no checking done
- {\setvalue{\??ia#1}{#2}} % pass #2, can be \blabla
-
-\def\resetinteractionparameter#1% use with case, no checking done
- {\letvalue{\??ia#1}\empty}
-
-% \def\interactionparameter#1%
-% {\csname\??ia#1\endcsname}
-
-\newtoks\everysetupinteraction
-
-\def\setupinteraction
- {\dosingleargument\dodosetupinteraction}
-
-\def\dodosetupinteraction[#1]% % \dosetupinteraction == special
- {\getparameters[\??ia][#1]%
- \the\everysetupinteraction}
-
-% todo, move partial append to where the action happens
-
-\appendtoks
- \doifelse\@@iastate\v!start
- {\iflocation\else
- \showmessage\m!interactions2{\ifusepagedestinations\space(PAGE)\fi}%
- \global\locationtrue
- \fi}
- {\iflocation
- \showmessage\m!interactions3{\ifusepagedestinations\space(PAGE)\fi}%
- \global\locationfalse
- \fi}%
- \iflocation
- \setsystemmode \v!interaction
- \else
- \resetsystemmode\v!interaction
- \fi
- \dosetuppageview\@@iafocus
- \doifsomething\@@iacalculate
- {\doregistercalculationset\@@iacalculate}%
- \doifelse\@@iastrut\v!yes
- \locationstruttrue
- \locationstrutfalse
- \doifelse\@@iaclick\v!yes
- \highlighthyperlinkstrue
- \highlighthyperlinksfalse
- \doifelse\@@iasplit\v!yes
- \locationsplittrue
- \locationsplitfalse
- \doifelse\@@iadisplay\v!new
- \gotonewwindowtrue
- \gotonewwindowfalse
- \doifelse\@@iapage\v!yes
- {\global\usepagedestinationstrue}
- {\global\usepagedestinationsfalse}%
-\to \everysetupinteraction
-
-%D We have to make sure of some settings:
-
-\def\dolocationstartup
- {\iflocation
- \dosetupinteraction
- \handlereferenceactions\@@iaopenaction \dosetupopenaction
- \handlereferenceactions\@@iacloseaction\dosetupcloseaction
- \setupinteractionscreens
- \global\let\dolocationstartup\relax
- \fi}
-
-\appendtoks \dolocationstartup \to \everyshipout
-
-\def\dolocationpagecheck % brr pdf dependent
- {\iflocation
- \handlereferenceactions\@@iaopenpageaction \dosetupopenpageaction
- \handlereferenceactions\@@iaclosepageaction\dosetupclosepageaction
- \fi}
-
-\appendtoks \dolocationpagecheck \to \everyshipout
-
-%D The next few macros are really horrible. For proper
-%D navigation a in||line hypertext fragment must have
-%D comfortable properties, so we must force some minimal
-%D dimensions. On the other hand button, and here I mean those
-%D pieces of text with fancy outlines and/or backgrounds, often
-%D have fixed, preset dimensions.
-%D
-%D To make things even worse, if we choose to let the optimal
-%D dimensions depend on the height and depth of a strut, a not
-%D too uncommon practice in \TEX, we have to deal with the fact
-%D that such a strut, set inside a box, is unknown too the
-%D outside world.
-%D
-%D The solution lays in passing the strut characteristics in
-%D a proper way, in our case by applying \type{\presetgoto}:
-%D
-%D \starttyping
-%D {some piece of text \presetgoto}
-%D \stoptyping
-%D
-%D This macro stores the current strut values.
-
-\newif\iflocationstrut
-\newif\iflocationsplit
-
-\def\resetgoto
- {\globallet\@@ia@@hoogte\!!zeropoint
- \globallet\@@ia@@diepte\!!zeropoint}
-
-\resetgoto
-
-\def\presetgoto
- {\iflocationstrut
- \setstrut
- %\xdef\@@ia@@hoogte{\the\strutht}%
- %\xdef\@@ia@@diepte{\the\strutdp}%
- \globallet\@@ia@@hoogte\strutheight
- \globallet\@@ia@@diepte\strutdepth
- \else
- \globallet\@@ia@@hoogte\@@iaheight
- \globallet\@@ia@@diepte\@@iadepth
- \fi}
-
-%D In the macros that deal with making areas into hyperlinks,
-%D we use:
-
-\newbox\driverresources
-
-\def\collectdriverresource#1%
- {\global\setbox\driverresources\hbox{\box\driverresources#1}}
-
-\def\flushdriverresources
- {\ifvoid\driverresources\else\box\driverresources\fi}
-
-\def\dohandlegoto#1#2#3%
- {\ifsecondaryreference
- \bgroup\setbox0\hbox{#2#3}\egroup
- \else
- \hbox
- {\setbox0\hbox{#1}%
- \ifdim\wd0<\@@iawidth\relax
- \buttonwidth\@@iawidth\relax
- \else
- \buttonwidth\wd0
- \fi
- \ifdim\ht0<\@@ia@@hoogte\relax
- \buttonheight\@@ia@@hoogte\relax
- \else
- \buttonheight\ht0
- \fi
- \ifdim\dp0<\@@ia@@diepte\relax
- \dimen0=\@@ia@@diepte\relax % = !
- \else
- \dimen0\dp0
- \fi
- \advance\buttonheight \dimen0
- \setbox2\hbox
- {\lower\dimen0\hbox
- {\dontcomplain
- \dimen0=.5\wd0 % direct skipping is faster of course
- \advance\dimen0 -.5\buttonwidth % buts this is nicer
- \hskip\dimen0#2#3}}% when visualizing things
- \naturalhbox % needed for omega / moved from plus-omg
- {\ifreversegoto
- \dimen0\wd0\box0\kern-\dimen0\smashbox2\box2\kern\dimen0
- \else
- \smashbox2\box2\box0
- \fi
- \flushdriverresources}%
- \resetgoto}%
- \fi}
-
-%D The secondary references are processed but not typeset. The
-%D special driver must collect the data needed.
-
-%D The width of the active area depends on the dimensions
-%D preset, the actual dimens and/or the height and depth of the
-%D strut.
-%D
-%D Normally the hyper active area is laid on top of the text.
-%D This enables stacking hyperlinks on top of each other. When,
-%D for some reason the opposite is prefered, one can use the
-%D next boolean to signal this wish.
-
-\newif\ifreversegoto \reversegotofalse
-
-%D As long as there a natural feeling of what can be considered
-%D hyper active or not, we have to tell users where they can
-%D possibly click. We've already seen a few macros that deal
-%D with this visualization, something we definitely do not let
-%D up to the viewer. One way of telling is using a distinctive
-%D typeface, another way is using color.
-%D
-%D There are two colors involved: one for normal hyperlinks,
-%D and one for those that point to the currentpage, the
-%D contrast color.
-
-\definecolor [interactioncolor] [r=0, g=.6, b=0]
-\definecolor [interactioncontrastcolor] [r=.8, g=0, b=0]
-
-\definecolor [interactiekleur] [interactioncolor]
-\definecolor [interactiecontrastkleur] [interactioncontrastcolor]
-
-%D The next few macros are responsible for highlighting hyper
-%D links. The first one, \type{\showlocation}, is used in those
-%D situations where the typeface is handled by the calling
-%D macro.
-
-\def\interactioncolor % todo \??ia as argument
- {\iflocation
- \ifrealreferencepage
- \@@iacontrastcolor
- \else
- \@@iacolor
- \fi
- \fi}
-
-%D CHECK WHERE USED / CONSISTENCY
-
-\def\showlocation#1%
- {\iflocation\color[\@@iacolor]{#1\presetgoto}\else#1\fi}
-
-%D When local color settings are to be used, we can use the
-%D next macro, where \type{#1} is a tag like \type{\??tg} and
-%D \type{#2} some text.
-
-\def\showcoloredlocation#1#2%
- {\iflocation
- \color[\getvalue{#1\c!color}]{#2\presetgoto}%
- \else
- #2%
- \fi}
-
-%D When we're dealing with pure page references, contrast
-%D colors are used when we are already at the page mentioned.
-
-\def\showcontrastlocation#1#2#3% the \@EA is needed
- {\iflocation
- \ifnum#2=\realpageno\relax
- \doifelsevaluenothing{#1\c!color}
- {#3\presetgoto}
- {\color[\getvalue{#1\c!contrastcolor}]{#3\presetgoto}}%
- \else
- \color[\getvalue{#1\c!color}]{#3\presetgoto}%
- \fi
- \else
- #3%
- \fi}
-
-%D The next simple macro can be used in color specifications,
-%D like \type{\color[\locationcolor{green}]}.
-
-\def\locationcolor#1%
- {\iflocation#1\fi}
-
-%D More tokens are spend when we want both typeface and color
-%D highlighting.
-
-\def\dolocationattributes#1#2#3#4%
- {\bgroup
- \let\fontattribute\empty
- \let\colorattribute\empty
- \doifdefined{#1#2}{\def\fontattribute{\getvalue{#1#2}}}%
- \iflocation
- \doifdefined{#1#3}{\def\colorattribute{\getvalue{#1#3}}}%
- \fi
- \startcolor[\colorattribute]%
- \@EA\doconvertfont\@EA{\fontattribute}{#4}% no \edef, but \@EA here
- \stopcolor
- \egroup}
-
-\def\navigating
- {\dolocationattributes\??ia\c!style\c!color}
-
-%D Although not decently supported in current viewers, a
-%D provisory hiding mechanims is implemented. Areas marked as
-%D such, are visible on screen, but invisible on paper. Don't
-%D trust this mechanism yet!
-
-\def\dostartinteraction
- {\bgroup
- \let\stopinteraction\egroup
- \dowithnextbox{\dostarthide\flushnextbox\dostophide\egroup}\hbox}
-
-\let\startinteraction = \relax
-\let\stopinteraction = \relax
-
-% in the future:
-%
-% eerst boolean invoeren bij menu, achtergrond, balk, button
-% enz; verder startinteractie een argument meegeven {#1} ->
-% \getvalue{#1\c!print}=={\v!ja} enz. Consequent menubutton
-% gebruiken!
-
-\def\@@iatimestamp
- {\the\normalyear
- \ifnum\normalmonth<10 0\fi\the\normalmonth
- \ifnum\normalday <10 0\fi\the\normalday}
-
-% happens in core-fld
-%
-% \definereference [AtOpenInitializeForm] [\v!geen]
-
-\setupinteraction % start fit page and reset form
- [\c!state=\v!stop,
- \c!page=\v!no,
- \c!click=\v!yes,
- \c!display=,
- %\c!openaction={\v!firstpage,AtOpenInitializeForm},
- %\c!openaction={\v!firstpage,\v!ResetForm},
- %\c!openaction=\v!ResetForm, % too buggy in reader 4.05
- \c!openaction=,
- \c!closeaction=,
- \c!openpageaction=,
- \c!closepageaction=,
- \c!display=\v!normal,
- \c!focus=\v!fit,
- \c!menu=\v!off,
- \c!style=\v!bold,
- \c!calculate=,
- \c!strut=\v!yes,
- \c!split=\v!yes,
- \c!color=interactioncolor,
- \c!contrastcolor=interactioncontrastcolor,
- \c!symbolset=,
- \c!width=1em,
- \c!height=\!!zeropoint,
- \c!depth=\!!zeropoint,
- \c!title=\jobname, % needed for fdf/x
- \c!subtitle=,
- \c!author=,
- \c!keyword=,
- \c!date=\@@iatimestamp]
-
-\protect \endinput
diff --git a/tex/context/base/core-new.tex b/tex/context/base/core-new.tex
deleted file mode 100644
index e96039d10..000000000
--- a/tex/context/base/core-new.tex
+++ /dev/null
@@ -1,304 +0,0 @@
-%D \module
-%D [ file=core-nav,
-%D version=1995.01.01,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=New ones,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / New Ones}
-
-\unprotect
-
-\let\startsetups\relax % to please dep checker
-\let\stopsetups \relax % to please dep checker
-
-\expanded
- {\long\def\@EA\noexpand\csname\e!start\v!setups\endcsname
- {\begingroup\noexpand\doifnextcharelse[%
- {\noexpand\startsetupsA\@EA\noexpand\csname\e!stop\v!setups\endcsname}
- {\noexpand\startsetupsB\@EA\noexpand\csname\e!stop\v!setups\endcsname}}}
-
-\letvalue{\e!stop\v!setups}\relax
-
-\unexpanded \def\setups{\doifnextcharelse\bgroup\dosetupsA\dosetupsB} % {..} or [..]
-\unexpanded \def\setup {\doifnextcharelse\bgroup\dosetups \dosetupsC} % {..} or [..]
-
-\def\dosetupsA #1{\cleanuplabel{#1}\processcommacommand[\cleanlabel]\dosetups} % {..}
-\def\dosetupsB[#1]{\cleanuplabel{#1}\processcommacommand[\cleanlabel]\dosetups} % [..]
-\def\dosetupsC[#1]{\cleanuplabel{#1}\dosetups\cleanlabel} % [..]
-
-% \def\dosetups#1% the grid option will be extended to other main modes
-% {\executeifdefined{\??su\ifgridsnapping\v!grid\fi:#1}
-% {\executeifdefined{\??su :#1}\gobbleoneargument}\empty} % takes one argument
-%
-% \def\setupwithargument#1% the grid option will be extended to other main modes
-% {\executeifdefined{\??su:#1}\gobbleoneargument}
-
-% better:
-
-% \def\dosetups#1% the grid option will be extended to other main modes
-% {\executeifdefined{\??su\ifgridsnapping\v!grid\fi:#1}
-% {\executeifdefined{\??su :#1}\gobbleoneargument}\empty} % takes one argument
-%
-% \def\setupwithargument#1% the grid option will be extended to other main modes
-% {\executeifdefined{\??su:#1}\gobbleoneargument}
-
-% faster:
-
-\letvalue{\??su:\letterpercent}\gobbleoneargument
-
-\def\dosetups#1% the grid option will be extended to other main modes
- {\csname\??su
- \ifgridsnapping
- \ifcsname\??su\v!grid:#1\endcsname\v!grid:#1\else\ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi\fi
- \else
- \ifcsname\??su:#1\endcsname:#1\else:\letterpercent\fi
- \fi
- \endcsname\empty} % takes one argument
-
-\def\setupwithargument#1% the grid option will be extended to other main modes
- {\csname\??su:\ifcsname\??su:#1\endcsname#1\else\letterpercent\fi\endcsname}
-
-\let\directsetup\dosetups
-
-% somehow fails ...
-%
-% \letvalue{\??su:..}\gobbleoneargument
-%
-% \def\dosetups#1% the grid option will be extended to other main modes
-% {\csname \??su
-% \ifcsname\??su\ifgridsnapping\v!grid\fi:#1\endcsname\v!grid:#1\else
-% \ifcsname\??su :#1\endcsname :#1\else
-% :..\fi\fi
-% \endcsname\empty} % takes one argument
-%
-% \def\setupwithargument#1% the grid option will be extended to other main modes
-% {\csname\??su:\ifcsname\??su:#1\endcsname#1\else..\fi\endcsname}
-
-\let\directsetup\dosetups
-
-\def\doifsetupselse#1% to be done: grid
- {\doifdefinedelse{\??su:#1}}
-
-\chardef\setupseolmode\plusone
-
-\def\startsetups {\xxstartsetups\plusone \stopsetups } \let\stopsetups \relax
-\def\startlocalsetups{\xxstartsetups\plusone \stoplocalsetups} \let\stoplocalsetups\relax
-\def\startrawsetups {\xxstartsetups\zerocount\stoprawsetups } \let\stoprawsetups \relax
-\def\startxmlsetups {\xxstartsetups\plustwo \stopxmlsetups } \let\stopxmlsetups \relax
-
-\def\xxstartsetups#1#2%
- {\begingroup\chardef\setupseolmode#1\doifnextcharelse[{\startsetupsA#2}{\startsetupsB#2}}
-
-\def\startsetupsA#1% [ ] delimited
- {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
- \dotripleempty\dostartsetups[#1]}
-
-\def\startsetupsB#1#2 % space delimited
- {\ifcase\setupseolmode\or\catcode`\^^M\@@ignore\or\catcode`\^^M\@@ignore\catcode`\|\@@other\fi
- \dodostartsetups#1\empty{#2}}
-
-\def\startsetupsC[#1][#2][#3]{\dodostartsetups#1{#2}{#3}} % [..] [..]
-\def\startsetupsD[#1][#2][#3]{\dodostartsetups#1\empty{#2}} % [..]
-
-\def\dostartsetups
- {\ifthirdargument\@EA\startsetupsC\else\@EA\startsetupsD\fi}
-
-% \long\def\dodostartsetups#1#2#3% watch out: not \grabuntil
-% {\dograbuntil#1{\endgroup\dodoglobal\long\setvalue{\??su#2:#3}}} % \doglobal
-%
-% better:
-
-% \long\def\dodostartsetups#1#2#3% watch out: not \grabuntil
-% {\cleanuplabel{\??su#2:#3}\dograbuntil#1{\endgroup\dodoglobal\long\setvalue\cleanlabel}} % \doglobal
-
-% \long\def\dodostartsetups#1#2#3%
-% {\cleanuplabel{\??su#2:#3}%
-% \long\def\dododostartsetups##1#1{\endgroup\dodoglobal\long\setvalue\cleanlabel####1{##1}}\dododostartsetups}
-
-\long\def\dodostartsetups#1#2#3%
- {\cleanuplabel{\??su#2:#3}%
- \long\def\dododostartsetups##1#1%
- {\endgroup
- \dodoglobal % bah
- \long\expandafter\setvalue\expandafter\cleanlabel\expandafter####\expandafter1\expandafter{##1}}%
- \dododostartsetups\empty} % the empty trick prevents the { } in {arg} from being eaten up
-
-\def\systemsetupsprefix{*}
-
-\def\systemsetups#1{\dosetups{\systemsetupsprefix#1}}
-
-\def\resetsetups[#1]% see x-fo for usage
- {\ifundefined{\??su\ifgridsnapping\v!grid\fi:#1}%
- \dodoglobal\letbeundefined{\??su:#1}%
- \else
- \dodoglobal\letbeundefined{\??su\ifgridsnapping\v!grid\fi:#1}%
- \fi}
-
-% or
-%
-% \def\resetsetups[#1]%
-% {\letbeundefined
-% {\??su:%
-% \ifundefined{\??su\ifgridsnapping\v!grid\fi:#1}#1\else\ifgridsnapping\v!grid\fi%
-% #1}}
-
-%D new and beta
-
-% \def\defineshortcut
-% {\dodoubleargument\dodefineshortcut}
-%
-% \bgroup
-%
-% \catcode`\<=\@@active
-%
-% \gdef\dodefineshortcut[#1][#2]%
-% {\ifsecondargument
-% \catcode`\<=\@@active
-% \def<{\ifmmode\expandafter\normalless\else\expandafter\doshortcut\fi}%
-% \getparameters[\??te#1][\c!commands=,\c!command=,\c!style=,\c!color=,#2]%
-% \else
-% \defineshortcut[][#1]%
-% \fi}
-%
-% \egroup
-%
-% \def\doshortcut
-% {\bgroup
-% \catcode`\>=\@@other
-% \dodoshortcut}
-%
-% \def\dodoshortcut#1>%
-% {\def\shortcut{#1}%
-% \dododoshortcut#1:\end}
-%
-% \def\dododoshortcut#1:#2\end
-% {\doifelsenothing{#2}
-% {\doifundefinedelse{\??te\c!commands}
-% {\shortcut}
-% {\@EA\dodododoshortcut\@EA\??te\@EA:\shortcut:\end}}
-% {\doifundefinedelse{\??te#1\c!commands}
-% {\shortcut}
-% {\dodododoshortcut\??te#1:#2\end}}%
-% \egroup}
-%
-% \def\dodododoshortcut#1:#2:\end
-% {\getvalue{#1\c!commands}%
-% \doattributes{#1}\c!style\c!color{\getvalue{#1\c!command}{#2}}}
-
-\def\defineshortcut
- {\dotripleargument\dodefineshortcut}
-
-\def\dodefineshortcut[#1][#2][#3]%
- {\ifthirdargument
- \ConvertConstantAfter\doifelse{#1}{}
- {\dododefineshortcut[<>][#2][#3]}
- {\dododefineshortcut[#1][#2][#3]}%
- \else\ifsecondargument
- \dododefineshortcut[<>][#1][#2]%
- \else
- \dododefineshortcut[<>][][#1]%
- \fi\fi}
-
-\def\dododefineshortcut[#1#2][#3][#4]% #1 is the trigger, #2 the delimiter/tag
- {\doifundefined{\??te\??te\string#2}{\letvalue{\??te\??te\string#2}=#1}%
- \defineactivecharacter #1 {\@EA\doshortcut\string#2} %
- \getparameters
- [\??te\string#2#3]
- [\c!commands=,\c!command=,\c!style=,\c!color=,#4]}
-
-\def\doshortcut#1%
- {\ifmmode
- \getvalue{\??te\??te#1}%
- \else
- \bgroup
- \catcode`#1=\@@other
- \def\dodoshortcut##1#1%
- {\def\shorttag{\??te#1}%
- \def\shortcut{##1}%
- \dododoshortcut##1:\end}%
- \@EA\dodoshortcut
- \fi}
-
-\def\dododoshortcut#1:#2\end
- {\doifelsenothing{#2}
- {\doifundefinedelse{\shorttag\c!commands}
- {\shortcut}
- {\@EA\dodododoshortcut\@EA\shorttag\@EA:\shortcut:\end}}
- {\doifundefinedelse{\shorttag#1\c!commands}
- {\shortcut}
- {\dodododoshortcut\shorttag#1:#2\end}}%
- \egroup}
-
-\def\dodododoshortcut#1:#2:\end
- {\getvalue{#1\c!commands}%
- \doattributes{#1}\c!style\c!color{\getvalue{#1\c!command}{#2}}}
-
-%D \defineshortcut [style=type]
-%D \defineshortcut [b] [style=bold]
-%D \defineshortcut [e] [style=\em]
-%D \defineshortcut [t] [style=type]
-%D \defineshortcut [c] [style=cap]
-%D \defineshortcut [k] [style=cap]
-%D \defineshortcut [u] [style=type,command=\hyphenatedurl]
-%D
-%D \startlines
-%D test test
-%D test test
-%D test test
-%D test test
-%D zus<>zo zus<:>zo zus<::>zo
-%D test test dat (ziezo)
-%D test test dat (:ziezo)
-%D test test dat (ziezo:)
-%D test test dat (zi:ezo:)
-%D well, looks fuzzy
-%D $10<20$
-%D \stoplines
-%D
-%D \defineshortcut [<>] [i] [style=\it]
-%D \defineshortcut [()] [b] [style=\bf]
-%D \defineshortcut [++] [s] [style=\sl]
-%D \defineshortcut [//] [u] [style=\underbars]
-%D \defineshortcut [--] [a] [style=\overstrike]
-%D
-%D \startlines
-%D it seems well
-%D it seems (b:to work) well
-%D it seems +s:to work+ well
-%D it seems /u:to work/ well
-%D it seems -a:to work- well
-%D \stoplines
-
-% \def\setupenv{\dodoubleargument\rawgetparameters[\??en]}
-%
-% \def\doifenvelse#1{\doifdefinedelse{\??en#1}} % speed up
-% \def\doifenv #1{\doifdefined {\??en#1}} % speed up
-% \def\doifnotenv #1{\doifundefined {\??en#1}} % speed up
-%
-% \def\env#1{\csname\??en#1\endcsname}
-%
-% \def\envvar#1#2%
-% {\ifcsname\??en#1\endcsname
-% \csname\??en#1\endcsname\else#2%
-% \fi}
-
-% low level change, now also accessible as \getvariable{environment}{...}; the
-% next macros will become obsolete some day in favor of normal variables
-
-\def\s!environment{environment}
-
-\def\setupenv {\dotripleargument\dosetvariables[\getrawparameters][\s!environment]}
-\def\doifenvelse{\doifelsevariable \s!environment}
-\def\doifenv {\doifvariable \s!environment}
-\def\doifnotenv {\doifnotvariable \s!environment}
-\def\env {\getvariable \s!environment}
-\def\envvar {\getvariabledefault\s!environment}
-
-\protect \endinput
diff --git a/tex/context/base/core-not.tex b/tex/context/base/core-not.tex
index aa6edd0e6..70d3f8627 100644
--- a/tex/context/base/core-not.tex
+++ b/tex/context/base/core-not.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Note Handling}
+\writestatus{loading}{ConTeXt Core Macros / Note Handling}
%D Unfortunately we cannot force an even number of lines in
%D a two column footnote placement.
@@ -36,8 +36,8 @@
%D \stopitemize
%D
%D Because footnotes are declared at the location of their
-%D reference. Footnotes can be seen as a special kind of
-%D floating bodies. There placement is postponed but has to be
+%D reference they can be seen as a special kind of
+%D floating bodies. Their placement is postponed but has to be
%D taken into account in the pagebreak calculations. This kind
%D of calculations are forced by using \type{\insert}.
@@ -383,7 +383,7 @@
\placenoterule
\noteparameter\c!after}%
\global\skip\currentnoteins\ht\scratchbox
- \setbox\scratchbox\box\voidb@x} % scratchbox can be in use
+ \setbox\scratchbox\emptybox} % scratchbox can be in use
\ifx\setnotehsize\undefined
diff --git a/tex/context/base/core-ntb.tex b/tex/context/base/core-ntb.tex
deleted file mode 100644
index 5bfba05ad..000000000
--- a/tex/context/base/core-ntb.tex
+++ /dev/null
@@ -1,1573 +0,0 @@
-%D \module
-%D [ file=core-ntb,
-%D version=2000.04.18,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Natural Tables,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This is an unfinished, preliminary module. At least two
-%D runs are needed to get the table fixed. Ugly code.
-
-% todo: special parsetb for argless variant
-% todo: protect \tbl...
-% todo: tblnx also count
-% todo: get rid of recurse
-% todo: fast if
-% todo: avoid halign (just do it manual) and thereby globals
-
-% optie=rek beschrijven
-
-\writestatus{loading}{Context Core Macros / Natural Tables}
-
-%D As always, this is the nth version. Much time went in
-%D trying to speed up the many cell calculations, some
-%D optimizations were rejected in order not to complicate this
-%D module too much (and in order to prevail extensibility).
-
-% shapebox fails here in mkii
-%
-% \setupcolors[state=start]
-% \bTABLE
-% \bTR [align=middle]\bTH Range\eTH{}\bTH Value\eTH{}\eTR
-% \bTR \bTD \type{<} 12\eTD{}\bTD 3\eTD{}\eTR
-% \bTR \bTD 12--16\eTD{}\bTD 2\eTD{}\eTR
-% \bTR \bTD \type{>}16\eTD{}\bTD 1\eTD{}\eTR
-% \eTABLE
-
-% \starttext
-% \placefigure[left]{}{}
-% \startlinecorrection \dontleavehmode \bTABLE
-% \bTR \bTD oeps \eTD \eTR
-% \eTABLE
-% \stoplinecorrection
-% \placefigure[right]{}{}
-% \startlinecorrection \dontleavehmode \bTABLE
-% \bTR \bTD oeps \eTD \eTR
-% \eTABLE
-% \stoplinecorrection
-% \stoptext
-
-%D To Do:
-%D
-%D \starttyping
-%D splitsen = ja | herhaal => als nofTH>1 then ja als herhaal
-%D \stoptyping
-
-%D To Do:
-%D
-%D \starttyping
-%D break over pagina
-%D kop herhalen
-%D reset settings
-%D
-%D \setupTABLE [c|column|x] [nx|odd|even|first|last][a=b]
-%D \setupTABLE [r|row |y] [nx|odd|even|first|last][a=b]
-%D \setupTABLE [nx|odd|even|first|last][ny|odd|even|first|last][a=b]
-%D \setupTABLE [nx|odd|even|first|last] [a=b]
-%D \setupTABLE [a=b]
-%D
-%D \bTH \eTH
-%D \stoptyping
-
-% the section setup does not work yet, data needs to be stored,
-% i.e.each row should know if it's a head/body/foot, and there
-% should be \setupTABLE[head]... and alike
-
-\unprotect
-
-%D A simple way to force equal line spacing is to say:
-%D
-%D \starttyping
-%D \def\bTBLCELL{\begstrut}
-%D \def\eTBLCELL{\endstrut}
-%D \stoptyping
-
-%D However, the next alternative also takes care of preceding
-%D and following white space.
-
-% \def\bTBLCELL % why not \doinhibitblank
-% {\inhibitblank\doconvertfont\tbltblstyle\empty\everypar{\delayedbegstrut}}
-
-% \def\eTBLCELL
-% {\ifhmode
-% \delayedendstrut
-% \par % added 13/4/2006
-% \else
-% \par
-% \ifdim\prevdepth<\zeropoint % =-1000pt ?
-% \vskip-\strutdp
-% \else
-% \removebottomthings
-% \fi
-% \fi}
-
-%D \startbuffer
-%D \bTABLE[left={(},right={)},top=\startnarrower,bottom=\stopnarrower]
-%D \bTR \bTD something \eTD \eTR
-%D \eTABLE
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-\def\bTBLCELL % why not \doinhibitblank
- {\inhibitblank
- \doconvertfont\tbltblstyle\empty
- \everypar{\tbltblleft\delayedbegstrut}}
-
-\def\eTBLCELL
- {\ifhmode
- \delayedendstrut
- \tbltblright
- \par % added 13/4/2006
- \else
- % not sure yet:\tbltblright
- \par
- \ifdim\prevdepth<\zeropoint % =-1000pt ?
- \vskip-\strutdp
- \else
- \removebottomthings
- \fi
- \fi}
-
-\newcount\currenttbl
-
-\def\@@tbl{tbl} \def\tblcell{1} \def\tblnone{2}
-
-\def\@@tblprefix{tbl:} \let\@@rawtblprefix\@@tblprefix
-
-%D This should be done more efficient: soon
-
-% \let as well as \expandafter\edef's
-
-\newcounter\TBLlevel
-
-\def\@@tblprefix{\@@tbl:\ifnum\TBLlevel>1 :\TBLlevel:\fi}
-
-% \def\tblsetprefix % not yet used, figure out when .. may interfere with setup
-% {\edef\@@tblprefix{\@@tbl:\ifnum\TBLlevel>1 :\TBLlevel:\fi}}
-
-\def\settblnob#1{\expandafter\let\csname\@@tblprefix\number#1:b\endcsname\plusone}
-\def\gettblnob#1{\ifcsname\@@tblprefix\number#1:b\endcsname\plusone\else\zerocount\fi}
-
-\def\settbltag#1#2{\expandafter\edef\csname\@@tblprefix\number#1:\number#2:s\endcsname}
-\def\settblcol#1#2{\expandafter\edef\csname\@@tblprefix\number#1:\number#2:c\endcsname}
-\def\settblrow#1#2{\expandafter\edef\csname\@@tblprefix\number#1:\number#2:r\endcsname}
-
-\def\lettbltag#1#2{\expandafter\let\csname\@@tblprefix\number#1:\number#2:s\endcsname}
-\def\lettblcol#1#2{\expandafter\let\csname\@@tblprefix\number#1:\number#2:c\endcsname}
-\def\lettblrow#1#2{\expandafter\let\csname\@@tblprefix\number#1:\number#2:r\endcsname}
-
-\def\settblwd#1#2{\expandafter\xdef\csname\@@tblprefix\number#1:\number#2:wd\endcsname} % global !
-\def\settblht#1#2{\expandafter\xdef\csname\@@tblprefix\number#1:\number#2:ht\endcsname} % global !
-\def\lettblwd#1#2{\global\expandafter\let\csname\@@tblprefix\number#1:\number#2:wd\endcsname} % global !
-\def\lettblht#1#2{\global\expandafter\let\csname\@@tblprefix\number#1:\number#2:ht\endcsname} % global !
-
-\def\gettbltag#1#2{\csname\@@tblprefix\number#1:\number#2:s\endcsname}
-\def\gettblcol#1#2{\csname\@@tblprefix\number#1:\number#2:c\endcsname}
-\def\gettblrow#1#2{\csname\@@tblprefix\number#1:\number#2:r\endcsname}
-
-\def\gettblwd #1#2{\csname\@@tblprefix\number#1:\number#2:wd\endcsname}
-\def\gettblht #1#2{\csname\@@tblprefix\number#1:\number#2:ht\endcsname}
-
-\def\settblwid#1{\expandafter\xdef\csname\@@tblprefix\number#1:w\endcsname} % {#2} global !
-\def\settblhei#1{\expandafter\xdef\csname\@@tblprefix\number#1:h\endcsname} % {#2} global !
-\def\settbldis#1{\expandafter\xdef\csname\@@tblprefix\number#1:d\endcsname} % {#2} global !
-\def\settblaut#1{\expandafter\xdef\csname\@@tblprefix\number#1:a\endcsname} % {#2} global !
-
-\def\lettblwid#1{\global\expandafter\let\csname\@@tblprefix\number#1:w\endcsname} % {#2} global !
-\def\lettblhei#1{\global\expandafter\let\csname\@@tblprefix\number#1:h\endcsname} % {#2} global !
-\def\lettbldis#1{\global\expandafter\let\csname\@@tblprefix\number#1:d\endcsname} % {#2} global !
-\def\lettblaut#1{\global\expandafter\let\csname\@@tblprefix\number#1:a\endcsname} % {#2} global !
-
-\def\gettblwid#1{\ifcsname\@@tblprefix\number#1:w\endcsname\csname\@@tblprefix\number#1:w\endcsname\else\zeropoint\fi}
-\def\gettblhei#1{\ifcsname\@@tblprefix\number#1:h\endcsname\csname\@@tblprefix\number#1:h\endcsname\else\zeropoint\fi}
-\def\gettbldis#1{\ifcsname\@@tblprefix\number#1:d\endcsname\csname\@@tblprefix\number#1:d\endcsname\else\zeropoint\fi}
-\def\gettblaut#1{\csname \@@tblprefix\number#1:a\endcsname}
-
-\def\doiftbltag #1#2{\ifcsname\@@tblprefix\number#1:\number#2:s\endcsname\@EA\firstofoneargument \else\@EA\gobbleoneargument \fi}
-\def\doifnottbltag #1#2{\ifcsname\@@tblprefix\number#1:\number#2:s\endcsname\@EA\gobbleoneargument \else\@EA\firstofoneargument \fi}
-\def\doifelsetbltag#1#2{\ifcsname\@@tblprefix\number#1:\number#2:s\endcsname\@EA\firstoftwoarguments\else\@EA\secondoftwoarguments\fi}
-\def\doiftblrow #1#2{\ifcsname\@@tblprefix\number#1:\number#2:r\endcsname\@EA\firstofoneargument \else\@EA\gobbleoneargument \fi}
-\def\doiftblcol #1#2{\ifcsname\@@tblprefix\number#1:\number#2:c\endcsname\@EA\firstofoneargument \else\@EA\gobbleoneargument \fi}
-\def\doifnottblcol #1#2{\ifcsname\@@tblprefix\number#1:\number#2:c\endcsname\@EA\gobbleoneargument \else\@EA\firstofoneargument \fi}
-
-\def\tbltagstate#1#2{\ifcsname\@@tblprefix\number#1:\number#2:s\endcsname\zerocount\else\plusone\fi}
-\def\tblrowstate#1#2{\ifcsname\@@tblprefix\number#1:\number#2:r\endcsname\zerocount\else\plusone\fi}
-\def\tblcolstate#1#2{\ifcsname\@@tblprefix\number#1:\number#2:c\endcsname\zerocount\else\plusone\fi}
-
-\def\settblspn #1{\expandafter\let\csname\@@tblprefix\number#1:s\endcsname \!!plusone}
-\def\doifelsetblspn#1{\doifelse {\csname\@@tblprefix\number#1:s\endcsname}\!!plusone}
-% \def\doifelsetblspn#1{\@EA\ifx\csname\@@tblprefix\number#1:s\endcsname\plusone\@EA\firstoftwoarguments\else\@EA\secondoftwoarguments\fi}
-
-\def\settblspn #1{\setvalue {\@@tblprefix\number#1:s}{1}}
-\def\doifelsetblspn#1{\doifelsevalue{\@@tblprefix\number#1:s}{1}}
-
-% \long\def\settbltxt#1#2#3%
-% {\setxvalue{\@@tblprefix#1:#2:l}{\TBLlevel}%
-% \long\setvalue{\@@tblprefix#1:#2:t}%
-% {\doifdefined{\@@tblprefix#1:#2:l}
-% {\edef\TBLlevel{\getvalue{\@@tblprefix#1:#2:l}}}%
-% #3}}
-
-\long\def\settbltxt#1#2#3%
- {\long\@EA\def\csname\@@tblprefix\number#1:\number#2:t\@EA\endcsname\@EA{\@EA\def\@EA\TBLlevel\@EA{\TBLlevel}#3}}
-
-\def\gettbltxt#1#2%
- {\csname\@@tblprefix\number#1:\number#2:t\endcsname}
-
-\newtoks\tbltoks
-\newtoks\tblrowtoks
-
-\let\pushTBLparameters\relax
-\let\popTBLparameters \relax
-
-\newif\ifsqueezeTBLspan \squeezeTBLspantrue % spans one column cell over multi column par cells
-\newif\ifautosqueezeTBLspan \autosqueezeTBLspantrue % unless explicit widths are given
-\newif\ifautoTBLspread \autoTBLspreadfalse
-\newif\ifautoTBLhsize \autoTBLhsizetrue
-\newif\ifautoTBLrowspan \autoTBLrowspantrue
-\newif\ifautoTBLemptycell \autoTBLemptycelltrue
-\newif\ifautoTBLcheckwidth \autoTBLcheckwidthtrue
-\newif\ifappendTBLsetups \appendTBLsetupstrue
-\newif\ifenableTBLbreak \enableTBLbreakfalse
-\newif\ifmultipleTBLheads \multipleTBLheadsfalse
-
-\newif\iftraceTABLE \traceTABLEfalse
-
-\def\noftblheadlines{0}
-\def\noftblnextlines{0}
-\def\noftblhdnxlines{0}
-
-\presetlocalframed[\@@tbl\@@tbl]
-
-\long\def\handleTBLcell#1#2[#3]{}
-
-\long\def\bTC#1\eTC{\bTD#1\eTD}
-\long\def\bTX#1\eTX{\bTD#1\eTD}
-\long\def\bTY#1\eTY{\bTR#1\eTR}
-
-\let\getTABLEparameters\getparameters
-
-\unexpanded\def\setupTABLE
- {\dotripleempty\dosetupTABLE}
-
-\def\dosetupTABLE[#1][#2][#3]%
- {\ifthirdargument
- \processaction
- [#1]
- [ \v!row=>{\dosetupTABLExy[\c!y][#2][#3]},%
- \v!column=>{\dosetupTABLExy[\c!x][#2][#3]},%
- r=>{\dosetupTABLExy[\c!y][#2][#3]},%
- c=>{\dosetupTABLExy[\c!x][#2][#3]},%
- y=>{\dosetupTABLExy[\c!y][#2][#3]},%
- x=>{\dosetupTABLExy[\c!x][#2][#3]},%
- \v!start=>{\dosetupTABLExy[#1][#2][#3]},%
- \v!header=>{\dosetupTABLExy[#1][#2][#3]},%
- \s!unknown=>{\dosetupTABLEzz[#1][#2][#3]}]%
- \else\ifsecondargument
- \processaction
- [#1]
- [ \v!row=>{\dosetupTABLExy[\c!y][\v!each][#2]},%
- \v!column=>{\dosetupTABLExy[\c!x][\v!each][#2]},%
- r=>{\dosetupTABLExy[\c!y][\v!each][#2]},%
- c=>{\dosetupTABLExy[\c!x][\v!each][#2]},%
- y=>{\dosetupTABLExy[\c!y][\v!each][#2]},%
- x=>{\dosetupTABLExy[\c!x][\v!each][#2]},%
- \v!start=>{\dosetupTABLExy[#1][\v!each][#2]},%
- \v!header=>{\dosetupTABLExy[#1][\v!each][#2]},%
- \s!unknown=>{\dosetupTABLEzz[\c!x][#1][#2]}]%
- \else
- \getparameters[\@@tbl\@@tbl][#1]%
- \fi\fi}
-
-\def\dosetupTABLExy[#1][#2][#3]%
- {\def\dodosetupTABLE##1{\setTABLEparameters[#1##1][#3]}%
- \processcommalist[#2]\dodosetupTABLE}
-
-\def\dosetupTABLEzz[#1][#2][#3]%
- {\def\dodosetupTABLE##1%
- {\def\dododosetupTABLE####1{\setTABLEparameters[\c!x##1\c!y####1][#3]}%
- \processcommalist[#2]\dododosetupTABLE}%
- \processcommalist[#1]\dodosetupTABLE}
-
-\def\nopTABLEparameters[#1][#2]%
- {\letvalue{\@@tblprefix#1}\empty}
-
-\def\setTABLEparameters[#1][#2]%
- {\pushTBLparameters
- \ifappendTBLsetups
- \doifdefinedelse{\@@tblprefix#1}
- {\def\getTABLEparameters[##1][##2]%
- {\setvalue{\@@tblprefix#1}{\getTABLEparameters[\@@tbl\@@tbl][##2,#2]}}%
- \getvalue{\@@tblprefix#1}%
- \let\getTABLEparameters\getparameters}
- {\setvalue{\@@tblprefix#1}{\getTABLEparameters[\@@tbl\@@tbl][#2]}}%
- \else
- \setvalue{\@@tblprefix#1}{\getTABLEparameters[\@@tbl\@@tbl][#2]}%
- \fi
- \popTBLparameters}
-
-\let\setupTBLsection\relax
-
-% % \setupTABLE [y] [first][background=color,backgroundcolor=blue,frame=off,bottomframe=on,topframe=on,framecolor=white]
-% \setupTABLE [first][first][backgroundcorner=2,corner=10,frame=on]
-% \setupTABLE [last] [first][backgroundcorner=4,corner=12,frame=on]
-%
-% \setupTABLE [row] [each] [background=color,backgroundcolor=blue,frame=on,framecolor=white]
-% \setupTABLE [first][2] [corner=8]
-% \setupTABLE [last] [2] [corner=5]
-% \setupTABLE [first][last] [corner=7]
-% \setupTABLE [last] [last] [corner=6]
-%
-% \startTEXpage
-% \bTABLE[frame=off,align=middle]
-% \bTR \bTD one \eTD \bTD two \eTD \bTD three \eTD \eTR
-% \bTR \bTD first \eTD \bTD second \eTD \bTD third \eTD \eTR
-% \bTR \bTD alpha \eTD \bTD beta \eTD \bTD gamma \eTD \eTR
-% \eTABLE
-% \stopTEXpage
-%
-% \setupTABLE [first] [two][corner=2] % special case
-% \setupTABLE [last] [two][corner=4] % special case
-%
-% % % \setupTABLE [one] [first] ... special case of span
-%
-% \startTEXpage
-% \bTABLE[frame=off,align=middle]
-% \bTR \bTD one \eTD \bTD two \eTD \bTD three \eTD \eTR
-% \bTR \bTD first \eTD \bTD second \eTD \bTD third \eTD \eTR
-% \eTABLE
-% \stopTEXpage
-
-\def\setupTBLcell#1#2% cell over col over row
- {\setupTBLsection % already forgotten
- \edef\positiverow{\number#1}%
- \edef\positivecol{\number#2}%
- \edef\negativerow{\the\numexpr-\maximumrow+#1+\minusone\relax}%
- \edef\negativecol{\the\numexpr-\maximumcol+#2+\minusone\relax}%
- % each each
- \csname\@@tblprefix\c!x\v!each\c!y\v!each\endcsname
- \csname\@@tblprefix\c!y\v!each\endcsname
- \csname\@@tblprefix\c!x\v!each\endcsname
- % odd even
- \csname\@@tblprefix\c!y\v!oddeven\positiverow\endcsname
- \csname\@@tblprefix\c!x\v!oddeven\positivecol\endcsname
- \csname\@@tblprefix\c!x\v!oddeven\positivecol\c!y\v!oddeven\positiverow\endcsname
- % row/col number combinations
- \ifcsname\@@tblprefix\c!y\positiverow\endcsname\csname\@@tblprefix\c!y\positiverow\endcsname\fi
- \ifcsname\@@tblprefix\c!y\negativerow\endcsname\csname\@@tblprefix\c!y\negativerow\endcsname\fi
- \csname\@@tbl\@@tbl\c!extras\endcsname
- \@EA\let\csname\@@tbl\@@tbl\c!extras\endcsname\relax % new, see x-fo
- \ifcsname\@@tblprefix\c!x\positivecol\endcsname\csname\@@tblprefix\c!x\positivecol\endcsname\fi
- \ifcsname\@@tblprefix\c!x\negativecol\endcsname\csname\@@tblprefix\c!x\negativecol\endcsname\fi
- \csname\@@tbl\@@tbl\c!extras\endcsname
- \@EA\let\csname\@@tbl\@@tbl\c!extras\endcsname\relax % new, see x-fo
- % first/last combinations
- \ifnum\positiverow=\plusone
- \csname\@@tblprefix\c!y\v!first\endcsname
- \ifcsname\@@tblprefix\c!x\positivecol\c!y\v!first\endcsname\csname\@@tblprefix\c!x\positivecol\c!y\v!first\endcsname\fi
- \fi
- \ifnum\positivecol=\plusone
- \csname\@@tblprefix\c!x\v!first\endcsname
- \ifcsname\@@tblprefix\c!x\v!first\c!y\positiverow\endcsname\csname\@@tblprefix\c!x\v!first\c!y\positiverow\endcsname\fi
- \fi
- \ifnum\positiverow=\maximumrow\relax
- \csname\@@tblprefix\c!y\v!last\endcsname
- \ifcsname\@@tblprefix\c!x\positivecol\c!y\v!last\endcsname\csname\@@tblprefix\c!x\positivecol\c!y\v!last\endcsname\fi
- \fi
- \ifnum\positivecol=\maximumcol\relax
- \csname\@@tblprefix\c!x\v!last\endcsname
- \ifcsname\@@tblprefix\c!x\v!last\c!y\positiverow\endcsname\csname\@@tblprefix\c!x\v!last\c!y\positiverow\endcsname\fi
- \fi
- \ifnum\positiverow=\maximumrow\relax \ifnum\positivecol=\maximumcol\relax
- \csname\@@tblprefix\c!x\v!last\c!y\v!last\endcsname
- \fi\fi
- \ifnum\positiverow=\plusone \ifnum\positivecol=\plusone
- \csname\@@tblprefix\c!x\v!first\c!y\v!first\endcsname
- \fi\fi
- \ifnum\positiverow=\plusone \ifnum\positivecol=\maximumcol\relax
- \csname\@@tblprefix\c!x\v!last\c!y\v!first\endcsname
- \fi\fi
- \ifnum\positiverow=\maximumrow\relax \ifnum\positivecol=\plusone
- \csname\@@tblprefix\c!x\v!first\c!y\v!last\endcsname
- \fi\fi
- % special case: two rows and last row : two&first and two&last (round corners)
- \ifnum\maximumrow=\plustwo\relax
- \ifnum\positiverow=\maximumrow\relax \ifnum\positivecol=\plusone
- \csname\@@tblprefix\c!x\v!first\c!y\v!two\endcsname
- \fi\fi
- \ifnum\positiverow=\maximumrow\relax \ifnum\positivecol=\maximumcol\relax
- \csname\@@tblprefix\c!x\v!last\c!y\v!two\endcsname
- \fi\fi
- \fi
- \ifnum\gettblcol\positiverow\positivecol=\maximumcol\relax % top span over whole width
- \ifnum\positiverow=\plusone
- \csname\@@tblprefix\c!x\v!one\c!y\v!first\endcsname
- \fi
- \ifnum\positiverow=\maximumrow\relax
- \csname\@@tblprefix\c!x\v!one\c!y\v!last\endcsname
- \fi
- \fi
- % header things
- \ifnum#1>\noftblhdnxlines\else
- \ifcsname\@@tblprefix\v!header\v!each \endcsname\csname\@@tblprefix\v!header\v!each \endcsname\fi
- \ifcsname\@@tblprefix\v!header\positivecol\endcsname\csname\@@tblprefix\v!header\positivecol\endcsname\fi
- \fi
- % explicit cells
- \ifcsname\@@tblprefix\c!x\positivecol\c!y\positiverow\endcsname\csname\@@tblprefix\c!x\positivecol\c!y\positiverow\endcsname\fi
- \ifcsname\@@tblprefix\c!x\negativecol\c!y\negativerow\endcsname\csname\@@tblprefix\c!x\negativecol\c!y\negativerow\endcsname\fi
- % done
- \global\letcscsname\@@tblsplitafter\csname\@@tbl\@@tbl\c!after\endcsname
- \relax}
-
-% we cannot use +n (checking on number/last/first would slow down too much)
-%
-% \setupTABLE[r] [2][color=red]
-% \setupTABLE[r] [-2][color=red]
-% \setupTABLE[c] [2][color=green]
-% \setupTABLE[c] [-2][color=green]
-% \setupTABLE[4] [4][color=blue]
-% \setupTABLE[-4][-4][color=blue]
-%
-% \bTABLE
-% \dorecurse{10}{\bTR \dorecurse{6}{\bTD xxx \eTD} \eTR}
-% \eTABLE
-
-\globallet\@@tblsplitafter\relax
-
-% split + page:
-%
-% \bTABLE[split=yes]
-% \bTR \bTD left \eTD\bTD right \eTD\eTR
-% \bTR[after=\page] \bTD left \eTD\bTD right \eTD\eTR
-% \bTR \bTD left \eTD\bTD right \eTD\eTR
-% \eTABLE
-
-% todo: protect counters
-
-\newcount\row \newcount\col
-\newcount\xrow \newcount\xcol
-\newcount\xxrow \newcount\xxcol
-\newcount\maximumrow \newcount\maximumcol \newcount\maximumrowspan
- \newcount\currentcol
-\newcount\tblspn
-
-\def\parseTR[#1][#2]% [#2] is dummy that kills spaces / no #3 argument
- {\currentcol\zerocount
- \advance\maximumrow\plusone
- \let\eTR\relax % handy in \expanded
- \iffirstargument\setTABLEparameters[\c!y\number\maximumrow][#1]\fi}
-
-\def\settblref#1#2{\expandafter\xdef\csname\@@tblprefix\number#1:\number#2:x\endcsname}
-\def\gettblref#1#2{\ifcsname\@@tblprefix\number#1:\number#2:x\endcsname\csname\@@tblprefix\number#1:\number#2:x\endcsname\fi}
-
-\long\def\parseTD[#1][#2]#3\eTD % [#2] is dummy that kills spaces
- {\def\tblny{\tblnr}%
- \def\tblnx{\tblnc}%
- \let\tblnc\plusone
- \let\tblnr\plusone
- \let\tbln\currentcol
- \let\tblm\empty
- \iffirstargument
- \getparameters[\@@tbl][#1]%
- \fi
- % goto first cell % NEW, n/m=cellnumber
- \edef\@@tblnindeed{\csname\@@tbl\c!n\endcsname}%
- \ifx\@@tblnindeed\empty
- \global\advance\tblspn\tblnx\relax
- \else\ifnum\@@tblnindeed=\currentcol\else
- \scratchcounter\numexpr\@@tblnindeed-\currentcol+\minusone-\tblspn\relax
- \ifnum\scratchcounter>\zerocount
- \expanded{\parseTD[\c!nx=\the\scratchcounter,\c!n=,\c!m=,*sq=\v!no][]}\eTD
- \fi
- % can also be made faster
- \getparameters[\@@tbl][\c!ny=\tblnr,\c!nx=\tblnc,nc=1,nr=1,#1,\c!n=,\c!m=]%
- \fi\fi
- \edef\@@tblmindeed{\csname\@@tbl\c!m\endcsname}%
- \ifx\@@tblmindeed\empty \else
- \ifnum\@@tblmindeed=\currentcol \else
- \scratchcounter\numexpr\@@tblmindeed-\currentcol+\minusone-\tblspn\relax
- \dorecurse\scratchcounter{\expanded{\parseTD[\c!n=,\c!m=][]}\eTD}%
- % can be sped up
- \getparameters[\@@tbl][\c!ny=\tblnr,\c!nx=\tblnc,nc=1,nr=1,#1,\c!n=,\c!m=]%
- \fi
- \fi
- \doloop % skip over columns that result from earlier span
- {\advance\currentcol\plusone
- \doifnottbltag\maximumrow\currentcol\exitloop}%
- % == \def\next{\advance\currentcol\plusone\doiftbltag\maximumrow\currentcol\next}\next
- % fill r*c cells and set span
- \ifnum\tblnx=\plusone
- \ifnum\tblny=\plusone
- \ifnum\currentcol>\maximumcol\relax
- \maximumcol\currentcol
- \fi
- \else
- \presetTBLcell
- \fi
- \else
- \presetTBLcell
- \fi
- % set values
- \lettbltag\maximumrow\currentcol\tblcell
- \settblcol\maximumrow\currentcol{\number\tblnx}%
- \settblrow\maximumrow\currentcol{\number\tblny}%
- \settblref\maximumrow\currentcol{\ifcsname\@@tbl\c!action\endcsname\csname\@@tbl\c!action\endcsname\fi}%
- % save text
- \edef\celltag{{\number\maximumrow}{\number\currentcol}}%
- \@EA\settbltxt\@EA\maximumrow\@EA\currentcol\@EA{\@EA\handleTBLcell\celltag[#1]{#3}}}
-
-\def\presetTBLcell
- {\row\maximumrow
- \col\currentcol
- \dorecurse\tblny
- {\col\currentcol
- \settblcol\row\col{\number\tblnx}%
- \ifnum\tblnx>\maximumrowspan\relax
- \maximumrowspan\tblnx
- \fi
- \dorecurse\tblnx
- {\lettbltag\row\col\tblnone
- \advance\col\plusone}%
- \advance\row\plusone}%
- % check max column
- \advance\col\minusone
- \ifnum\col>\maximumcol\relax
- \maximumcol\col
- \fi}
-
-%D The usage of n and m:
-%D
-%D \startbuffer
-%D \bTABLE[width=3em]
-%D \bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR
-%D \bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR
-%D \eTABLE
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-%D
-%D \startbuffer
-%D \bTABLE[width=3em]
-%D \bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR
-%D \bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR
-%D \eTABLE
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-%D
-%D \startbuffer
-%D \bTABLE[frame=on]
-%D \bTR \bTH[nc=3] One \eTH \bTH[m=4] Four \eTH\eTR
-%D \bTR \bTD a \eTD\bTD b \eTD\bTD c \eTD\bTD d \eTD\eTR
-%D \eTABLE
-%D
-%D \bTABLE[frame=on]
-%D \bTR \bTH[nr=2] One \eTH \bTH[m=3] Three \eTH\eTR
-%D \bTR \bTD[m=3] a \eTD\bTD b \eTD\bTD c \eTD\bTD d \eTD\eTR
-%D \bTR \bTD[m=3] a \eTD\bTD b \eTD\bTD c \eTD\bTD d \eTD\eTR
-%D \eTABLE
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-\long\def\parseTH[#1]#2\eTH
- {\parseTD[#1,\c!color=\tbltblheadcolor,\c!style=\tbltblheadstyle,\c!aligncharacter=\v!no]#2\eTD}
-
-%D new
-
-\long\def\parseTN[#1]#2\eTN
- {\parseTD[#1]\digits#2\relax\eTD}
-
-%D Vit Zyka needed the option to create a distance between columns, so I
-%D added support for individual column distances.
-%D
-%D \startbuffer
-%D % \setupTABLE[c][each][distance=2em]
-%D \setupTABLE[c][1][distance=2em]
-%D \setupTABLE[c][2][distance=3em]
-%D
-%D \bTABLE
-%D \bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR
-%D \bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR
-%D \bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR
-%D \eTABLE
-%D
-%D \bTABLE[option=stretch]
-%D \bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR
-%D \bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR
-%D \bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR
-%D \eTABLE
-%D \stopbuffer
-%D
-%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
-%D
-%D and he provided patches for the global left and right margin distances
-%D as well as the columndistance (although i changed the names -). Here
-%D is his testcase:
-%D
-%D \startbuffer
-%D \framed[offset=overlay]\bgroup
-%D \setupTABLE[column][2][align=left]%
-%D \setupTABLE[column][3][align=right]%
-%D \bTABLE[columndistance=2cm,leftmargindistance=.3cm,rightmargindistance=.5cm]
-%D \bTR \bTH[nc=3] Table head\eTH \eTR
-%D \bTR \bTD[nc=2] AB\eTD \bTD C\eTD \eTR
-%D \bTR \bTD[nc=2,align=left] AB\eTD \bTD C\eTD \eTR
-%D \bTR \bTD[nc=2,align=middle] AB\eTD \bTD C\eTD \eTR
-%D \bTR \bTD A\eTD \bTD B\eTD \bTD C\eTD \eTR
-%D \bTR \bTD Aa\eTD \bTD Bb\eTD \bTD Cccc\eTD \eTR
-%D \bTR \bTD[nc=3,align=middle] ABC\eTD \eTR
-%D \eTABLE
-%D \egroup
-%D \stopbuffer
-%D
-%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
-
-\newtoks\TBLhead
-\newtoks\TBLnext
-\newtoks\TBLbody
-\newtoks\TBLfoot
-
-% to be done: head foot, dus state var
-
-\long\def\bTABLEhead{\dosingleempty\doTABLEhead}
-\long\def\bTABLEnext{\dosingleempty\doTABLEnext}
-\long\def\bTABLEbody{\dosingleempty\doTABLEbody}
-\long\def\bTABLEfoot{\dosingleempty\doTABLEfoot}
-
-\long\def\doTABLEhead[#1]#2\eTABLEhead{\appendtoks\doTABLEsection[#1]{#2}\to\TBLhead}
-\long\def\doTABLEnext[#1]#2\eTABLEnext{\appendtoks\doTABLEsection[#1]{#2}\to\TBLnext}
-\long\def\doTABLEbody[#1]#2\eTABLEbody{\appendtoks\doTABLEsection[#1]{#2}\to\TBLbody}
-\long\def\doTABLEfoot[#1]#2\eTABLEfoot{\appendtoks\doTABLEsection[#1]{#2}\to\TBLfoot}
-
-\long\def\doTABLEsection[#1]#2%
- {\def\setupTBLsection{\getparameters[\@@tbl\@@tbl][#1]}%
- #2%
- \let\setupTBLsection\relax}
-
-\let\pushTBL\relax
-\let\popTBL \relax
-
-\chardef\tblpass=0
-
-\def\presetallTABLEparameters% each odd|even level / can be sped up but only once per table
- {\executeifdefined{\@@rawtblprefix\v!start\v!each}\relax
- \executeifdefined{\@@rawtblprefix\v!start\v!oddeven\TBLlevel}\relax
- \executeifdefined{\@@rawtblprefix\v!start\number\TBLlevel}\relax}
-
-\def\bTABLE
- {\dosingleempty\dobTABLE}
-
-\def\dobTABLE[#1]%
- {\pushTBL
- % box not here
- \bgroup
- \TBLhead\emptytoks
- \TBLnext\emptytoks
- \TBLbody\emptytoks
- \TBLfoot\emptytoks
- \ifhmode\kern\zeropoint\fi % blocks \removeunwantedspaces: check this on icare handelingsschema
- \resetcharacteralign % new
- \getparameters
- [\@@tbl\@@tbl]
- [\c!align={\v!right,\v!broad,\v!high},#1]%
- \hsize\tbltbltextwidth
- \processaction
- [\tbltblsplit]
- [ \v!yes=>\enableTBLbreaktrue,
- \v!repeat=>\enableTBLbreaktrue\multipleTBLheadstrue,
- \v!auto=>\ifinsidesplitfloat\enableTBLbreaktrue\fi]
- \processaction
- [\tbltblheader]
- [\v!repeat=>\multipleTBLheadstrue]%
- \localcolortrue
- \presetallTABLEparameters
- \ExpandFirstAfter\processallactionsinset
- [\tbltbloption]
- [\v!stretch=>\autoTBLspreadtrue]%
- \linewidth\tbltblrulethickness % needs to be frozen
- \dontcomplain
- \currentcol\zerocount
- \maximumrowspan\plusone
- \maximumcol\zerocount
- \maximumrow\zerocount
- \def\bTR{\dodoubleempty\parseTR}%
- \def\bTD{\dodoubleempty\parseTD}%
- \def\bTH{\dodoubleempty\parseTH}%
- \def\bTN{\dodoubleempty\parseTN}}
-
-% permits \expanded{\bTD ... \eTD}
-
-\unexpanded\def\eTR{}
-\unexpanded\def\eTD{}
-\unexpanded\def\eTH{}
-\unexpanded\def\eTN{}
-
-\def\eTABLE % beware, we need to get rid of spurious spaces when in hmode
- {% tricky and dirty order -)
- \doifsometokselse\TBLhead % slow, better a flag
- {\the\TBLhead
- \edef\noftblheadlines{\number\maximumrow}%
- \doifsometokselse\TBLnext
- {\the\TBLnext
- \edef\noftblnextlines{\number\numexpr\maximumrow-\noftblheadlines\relax}}%
- {\let\noftblnextlines\zerocount}% was 1
- \edef\noftblhdnxlines{\number\maximumrow}}
- {\let\noftblheadlines\zerocount % was 1
- \let\noftblnextlines\zerocount
- \let\noftblhdnxlines\zerocount}%
- \the\TBLbody
- \the\TBLfoot
- \removeunwantedspaces % only if hmode
- % finish cells
- \dorecurse\maximumrow
- {\row\recurselevel\relax
- \dorecurse\maximumcol
- {\col\recurselevel\relax
- \doifnottbltag\row\col
- {\xxcol\col
- \xxrow\row
- \xrow\row
- \doloop
- {\xcol\col
- \doloop
- {\doifelsetbltag\xrow\xcol \exitloop
- {\advance\xcol\plusone
- \ifnum\xcol>\maximumcol\relax \exitloop \fi}}%
- \doifelsetbltag\xrow\xcol \exitloop
- {\xxrow\xrow \xxcol\xcol \advance\xrow\plusone
- \ifnum\xrow>\maximumrow \exitloop \fi}}%
- \ifnum\xxrow>\maximumrow\xxrow\maximumrow\fi
- \ifnum\xxcol>\maximumcol\xxcol\maximumcol\fi
- \xxrow\numexpr\xxrow-\row+\plusone\relax
- \xxcol\numexpr\xxcol-\col+\plusone\relax
- \xrow\row
- \dorecurse\xxrow
- {\xcol\col \settblcol\xrow\xcol{\number\xxcol}%
- \dorecurse\xxcol
- {\lettbltag\xrow\xcol\tblnone \advance\xcol\plusone}%
- \advance\xrow\plusone}%
- \lettbltag\row\col\tblcell
- \settblcol\row\col{\the\xxcol}%
- \settblrow\row\col{\the\xxrow}%
- \ifautoTBLemptycell
- \edef\celltag{{\number\row}{\number\col}}%
- \@EA\settbltxt\@EA\row\@EA\col\@EA{\@EA\handleTBLcell\celltag[]{\strut}}%
- \fi}}}%
- % to be sure
- \dorecurse\maximumrow
- {\row\recurselevel\relax
- \dorecurse\maximumcol
- {\col\recurselevel\relax
- \doiftblrow\row\col
- {\scratchcounter\numexpr\maximumrow-\row+\plusone\relax
- \ifnum\gettblrow\row\col>\scratchcounter
- \settblrow\row\col{\the\scratchcounter}%
- \fi}%
- \lettblht\row\col\zeropoint
- \lettblwd\row\col\zeropoint
- \doifnottblcol\row\col{\lettblcol\row\col\zerocount}%
- \doifnottbltag\row\col{\lettbltag\row\col\tblnone}}}%
- % check and do
- \ifcase\maximumcol\else
- \startTBLprocessing
- \begTBL
- \dorecurse\maximumrow
- {\bTBL
- \row\recurselevel\relax
- \dorecurse\maximumcol
- {\col\recurselevel\relax
- \expanded{\doTBL{\number\row}{\number\col}}}%
- \eTBL}%
- \removeunwantedspaces % only if hmode
- \endTBL
- \stopTBLprocessing
- % wrong ! ! ! better to have an auto-offset-overlay
- % \ifnum\TBLlevel>1
- % \vskip-\strutdp
- % \fi
- \fi
- \egroup
- \popTBL}
-
-\let\startTBLprocessing\relax
-\let\stopTBLprocessing \relax
-
-\newcount\prelocatedTBLrows % \prelocateTBLrows{1000} may speed up large tables
-
-\def\bTBL{\tblrowtoks\emptytoks}
-\def\eTBL{\tbltoks\@EA\@EA\@EA{\@EA\the\@EA\tbltoks\@EA\begintblrow\the\tblrowtoks\endtblrow}}%
-
-\def\prelocateTBLerror
- {\writestatus\m!systems{fatal error: use \string\prelocateTBLrows\space to increase table memory (now: \number\prelocatedTBLrows)}}
-
-\def\prelocateTBLrows#1% we start at zero so we have one to much, better play safe anyway
- {\dostepwiserecurse\prelocatedTBLrows{#1}\plusone{\expandafter\newtoks\csname tbl:\recurselevel\endcsname}%
- \def\bTBL
- {\ifnum\tblrow<\prelocatedTBLrows\relax
- \@EA\let\@EA\tblrowtoks\csname tbl:\the\tblrow\endcsname\tblrowtoks\emptytoks
- \else
- \prelocateTBLerror
- \fi}%
- \def\eTBL
- {\tbltoks\@EA\@EA\@EA{\@EA\the\@EA\tbltoks\@EA\begintblrow\@EA\the\csname tbl:\the\tblrow\endcsname\endtblrow}}%
- \global\prelocatedTBLrows#1\relax}
-
-% \prelocateTBLrows{1000} % may speed up large tables
-
-% We use aligments to handle the empty (skipped) columns, so
-% that we don't have to (re|)|calculate these.
-
-\def\skiptblcol
- {\global\advance\tblcol\plusone}
-
-\def\nexttblcol
- {\global\advance\tblcol\plusone
- \kern\tbltblcolumndistance
- &}
-
-\def\spantblcol
- {\span}
-
-\newcount\tblrow
-\newcount\tblcol
-
-\let\savedtblrow\!!zerocount
-\let\savedtblcol\!!zerocount
-
-\def\begintblrow
- {\noalign
- {\global\advance\tblrow\plusone
- \global\tblcol\zerocount
- \global\tblspn\zerocount}%
- \nexttblcol
- \kern\dimexpr\tbltblleftmargindistance-\tbltblcolumndistance\relax}
-
-\def\endtblrow
- {\kern\dimexpr\tbltblrightmargindistance-\tbltblcolumndistance\relax
- \crcr
- \noalign
- {\nointerlineskip
- \ifnum\gettblnob\tblrow=\zerocount
- \allowbreak
- \fi
- \bgroup % protect local vars
- \@@tblsplitafter
- \egroup
- \bgroup % protect local vars
- \scratchcounter\numexpr\tblrow+\plusone\relax
- \ifnum\scratchcounter>\noftblhdnxlines\relax
- \ifnum\scratchcounter<\maximumrow\relax
- \doifsomething\tbltblspaceinbetween{\blank[\tbltblspaceinbetween]}%
- \fi
- \fi
- \egroup}}
-
-\def\begintbl
- {\global\tblspn\zerocount
- \global\tblcol\zerocount
- \global\tblrow\zerocount
- \global\advance\tblrow\minusone
- \tabskip\zeropoint
- \halign\bgroup
- \registerparoptions % new
- \ignorespaces##\unskip&&\ignorespaces##\unskip\cr}
-
-\def\endtbl
- {\egroup}
-
-\setvalue{\tblnone TBL}#1#2%
- {\spanTBL{#1}{#2}}
-
-\setvalue{\tblcell TBL}#1#2%
- {\tblrowtoks\expandafter{\the\tblrowtoks\makeTBL #1 #2 }% space delimited -> less tokens
- \spanTBL{#1}{#2}}
-
-\def\spanTBL#1#2%
- {\scratchcounter\gettblcol{#1}{#2}\relax
- \ifnum\scratchcounter>\zerocount
- \advance\scratchcounter \minusone
- \dorecurse\scratchcounter{\tblrowtoks\expandafter{\the\tblrowtoks\spantblcol}}%
- \dorecurse\scratchcounter{\tblrowtoks\expandafter{\the\tblrowtoks\skiptblcol}}%
- \tblrowtoks\expandafter{\the\tblrowtoks\nexttblcol}%
- \fi}
-
-\def\doTBL#1#2%
- {\csname\gettbltag{#1}{#2}TBL\endcsname{#1}{#2}}
-
-\def\begTBL
- {\global\tblspn\zerocount
- \global\tblrow\zerocount
- \global\tblcol\zerocount
- \chardef\tblpass\zerocount
- \tbltoks\emptytoks}
-
-\def\flushtbltoks{\begintbl\the\tbltoks\endtbl}
-
-\def\domakeTBLone#1 #2 %
- {\gettbltxt{#1}{#2}}%
-
-\def\domakeTBLtwo#1 #2 % meer in cellD
- {\scratchdimen\zeropoint
- \scratchcounter\tblcol
- \!!counta\gettblcol{#1}{#2}\relax
- \dorecurse\!!counta
- {\advance\scratchdimen\dimexpr\gettblwid\scratchcounter+\tbltblcolumndistance\relax
- \ifnum\recurselevel<\!!counta \advance\scratchdimen \gettbldis\scratchcounter\fi
- \advance\scratchcounter\plusone}%
- \edef\widthTBL{\the\dimexpr\scratchdimen-\tbltblcolumndistance\relax}%
- \setbox\scratchbox\hbox{\gettbltxt{#1}{#2}}%
- \settblht{#1}{#2}{\the\ht\scratchbox}%
- \settblwd{#1}{#2}{\the\wd\scratchbox}%
- \ifdim\ht\scratchbox>\gettblhei{#1}\relax
- \settblhei{#1}{\the\ht\scratchbox}%
- \fi}%
-
-\def\domakeTBLthree#1 #2 %
- {% height
- \!!counta \gettblcol{#1}{#2}\relax
- \!!countb \gettblrow{#1}{#2}\relax
- \!!heighta\gettblht {#1}{#2}\relax
- \scratchdimen\zeropoint
- \ifnum\!!counta=\maximumcol\relax
- % case: nc=maxcolumns
- \else
- \scratchcounter#1\relax
- \dorecurse\!!countb
- {\advance\scratchdimen
- \gettblhei\scratchcounter
- \advance\scratchcounter\plusone}%
- \ifdim\scratchdimen<\!!heighta\relax
- \scratchdimen\!!heighta
- \fi
- \fi
- \edef\heightTBL{\the\scratchdimen}%
- % width
- \scratchdimen\zeropoint
- \scratchcounter\tblcol
- \dorecurse\!!counta
- {\advance\scratchdimen\dimexpr\gettblwid\scratchcounter+\tbltblcolumndistance\relax
- \ifnum\recurselevel<\!!counta \advance\scratchdimen \gettbldis\scratchcounter\fi
- \advance\scratchcounter\plusone}%
- \edef\widthTBL{\the\dimexpr\scratchdimen-\tbltblcolumndistance\relax}%
- % cell
- \setbox\scratchbox\hbox{\gettbltxt{#1}{#2}}%
- \ifnum\!!counta=\maximumcol\relax
- % case: nc=maxcolumns
- \else
- \scratchdimen\gettblhei{#1}%
- \setbox\scratchbox\hbox
- {\lower\ht\scratchbox\hbox{\raise\scratchdimen\box\scratchbox}}%
- \ht\scratchbox\scratchdimen
- \fi
- \dp\scratchbox\zeropoint
- \edef\!!stringa{\gettblref{#1}{#2}}%
- \ifx\!!stringa\empty
- \box\scratchbox
- \else
- \expanded{\gotobox{\box\scratchbox}[\!!stringa]}%
- \fi
- \box\scratchbox}
-
-\def\inTBLcell#1#2% hm, do we need #1 #2 ? we use tblcol anyway
- {\ExpandBothAfter\doifinsetelse\localwidth{\v!fit,\v!broad} % user set
- {}
- {\scratchdimen\gettblaut\tblcol\relax
- \ifdim\localwidth>\scratchdimen
- \settblaut\tblcol{\the\dimexpr\localwidth\relax}%
- \fi}}%
-
-\def\endTBL
- {\setbox\scratchbox\hbox
- {\localframed
- [\@@tbl\@@tbl]
- [\c!frame=\v!off,\c!background=,\c!align=\v!no]
- {\strut}}%
- \edef\minimalcellheight{\the\ht\scratchbox}%
- \dorecurse\maximumcol
- {\lettblaut\recurselevel\zeropoint
- % new
- \xcol\recurselevel\relax
- \dorecurse\maximumrow
- {\lettblwd\recurselevel\xcol\zeropoint
- \lettblht\recurselevel\xcol\zeropoint}%
- % till here
- \lettblwid\recurselevel\zeropoint
- \lettbldis\recurselevel\zeropoint}%
- \dorecurse\maximumrow
- {\lettblhei\recurselevel\maxdimen}%
- \chardef\tblpass\plusone
- \let\makeTBL\domakeTBLone
- \let\handleTBLcell\dohandleTBLcellA
- \setbox0\vbox{\trialtypesettingtrue \flushtbltoks}%
-% \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
- \lettbldis\maximumcol\zeropoint
- \ifautoTBLspread
- % experimental, stretch non fixed cells to \hsize
- \checktblwidthsone % trial run
- \checktblwidthstwo % real run
- \stretchtblwidths
- \let\handleTBLcell\dohandleTBLcellB
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
- \else\ifdim\wd0>\hsize
- \ifautoTBLhsize
- \checktblwidthsone % trial run
- \checktblwidthstwo % real run
- \let\handleTBLcell\dohandleTBLcellB
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
- \fi
- \else\ifautoTBLrowspan\ifnum\maximumrowspan>1 % max ?
- % added jan 2002 because nx=* did no longer work
- \edef\savedhsize{\the\hsize}%
- \hsize\wd0\relax % new per 17/04/2006
- \checktblwidthsone % trial run
- \checktblwidthstwo % real run
- \hsize\savedhsize
- %
- \let\handleTBLcell\dohandleTBLcellC
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
- \fi\fi\fi\fi
- \let\handleTBLcell\dohandleTBLcellD
- \chardef\tblpass\plustwo
- \let\makeTBL\domakeTBLtwo
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
- \checktblheightsone
- \checktblheightstwo
- \let\handleTBLcell\dohandleTBLcellE
- \chardef\tblpass\plusthree
- \let\makeTBL\domakeTBLthree
- \ifnum\TBLlevel>\plusone
- \@EA\notsplittblbox
- \else\ifenableTBLbreak
- \@EAEAEA\splittblbox
- \else
- \@EAEAEA\notsplittblbox
- \fi\fi{\flushtbltoks}}
-
-\def\stretchtblwidths % more variants, e.g. a max to \dimend
- {\ifcase\maximumcol\else % else division by zero
- \!!dimend\zeropoint
- \!!dimene\hsize
- \dorecurse\maximumcol
- {\advance\!!dimend\dimexpr\gettblwid\recurselevel+\tbltblcolumndistance\relax
- \advance\!!dimene-\gettbldis\recurselevel}%
- \advance\!!dimend\dimexpr-\tbltblcolumndistance+\tbltblleftmargindistance+\tbltblrightmargindistance\relax
- % distribute width (stretch)
- \ifdim\!!dimend<\!!dimene
- \advance\!!dimend-\!!dimene
- \!!dimend-\!!dimend
- \divide\!!dimend\maximumcol
- \dorecurse\maximumcol
- {\settblwid\recurselevel{\the\dimexpr\gettblwid\recurselevel+\!!dimend\relax}}%
- \fi
- \fi}
-
-\newbox\finaltblbox
-
-\def\notsplittblbox#1%
- {\setbox\finaltblbox\vbox{#1}%
- \postprocessTABLEbox\finaltblbox
- \beforeTABLEbox
- \box\finaltblbox
- \afterTABLEbox}
-
-\def\splittblbox#1%
- {\ifinsidesplitfloat
- \donetrue
- \else\ifinsidefloat
- \donefalse
- \else
- \donetrue
- \fi\fi
- \ifdone
- \executeifdefined{dosplittblbox\tbltblsplitmethod}\dosplittblbox{#1}%
- \else
- \notsplittblbox{#1}%
- \fi}
-
-\newbox\TABLEsplitbox % public, don't change
-
-\let\extratblsplitheight\zeropoint % additional space taken by before/afterTABLEsplitbox
-
-\def\dosplittblbox#1%
- {\resettsplit
- \def\tsplitminimumfreelines{2}%
- \def\tsplitminimumfreespace{\dimexpr\extratblsplitheight+\tbltblsplitoffset\relax}%
- \def\tsplitbeforeresult {\beforeTABLEsplitbox}%
- \def\tsplitafterresult {\afterTABLEsplitbox}%
- \def\tsplitafter {\@@tblsplitafter}%
- \setbox\tsplitcontent\vbox{#1}%
- \ifmultipleTBLheads
- \dorecurse\noftblheadlines
- {\setbox\scratchbox\vsplit\tsplitcontent to \lineheight
- \setbox\tsplithead\vbox{\unvcopy\tsplithead\unvcopy\scratchbox}}%
- \dorecurse\noftblnextlines
- {\setbox\scratchbox\vsplit\tsplitcontent to \lineheight
- \setbox\tsplitnext\vbox{\unvcopy\tsplitnext\unvcopy\scratchbox}}%
- \fi
- \doifsomething\tbltblspaceinbetween
- {\def\tsplitinbetween{\blank[\tbltblspaceinbetween]}}%
- \def\postprocesstsplit{\postprocessTABLEsplitbox{\box\tsplitresult}}%
- \handletsplit}
-
-% ! ! ! ! TODO: naast \postprocessTABLEsplitbox ook evt \postprocessTABLEbox voor niet split
-
-\let\postprocessTABLEsplitbox\gobbleoneargument
-\let\postprocessTABLEbox \gobbleoneargument
-
-\let\beforeTABLEsplitbox\relax
-\let\afterTABLEsplitbox \relax
-\let\beforeTABLEbox \relax
-\let\afterTABLEbox \relax
-
-\def\checktblwidthsone{\dochecktblwidths0} % 0 = trial run
-\def\checktblwidthstwo{\dochecktblwidths1} % 1 = real run
-
-\def\dochecktblwidths#1%
- {\iftraceTABLE\showtblwids{B#1}\fi
- \!!counta\zerocount
- \!!dimena\dimexpr\hsize-\tbltblleftmargindistance-\tbltblrightmargindistance-\tbltblcolumndistance\relax
- \dorecurse\maximumcol
- {\scratchdimen\gettblaut\recurselevel\relax
- \advance\!!dimena-\gettbldis\recurselevel\relax
- \ifdim\scratchdimen>\zeropoint\relax
- \advance\!!dimena -\scratchdimen
- \else
- \scratchdimen\gettblwid\recurselevel\relax
- \ifdim\scratchdimen>\tbltblmaxwidth\relax
- \ifcase#1\else\lettblwid\recurselevel\zeropoint\fi
- \advance\!!counta \plusone
- \else
- \ifdim\scratchdimen>\zeropoint\relax
- \advance\!!dimena -\scratchdimen
- \else
- % eigenlijk moet dit alleen als de kolom wordt overspannen door een
- % vorige, maw extra dubbele loop en status var
- \advance\!!counta \plusone
- \fi
- \fi
- \fi}%
- \ifcase\!!counta \else \divide\!!dimena \!!counta \fi
- \dorecurse\maximumcol
- {\scratchdimen\gettblwid\recurselevel\relax
- \ifcase#1\relax
- \ifdim\scratchdimen<\!!dimena % take natural width
- \settblaut\recurselevel{\the\scratchdimen}%
- \fi
- \else
- \ifdim\scratchdimen=\zeropoint % auto set width
- \settblwid\recurselevel{\the\!!dimena}%
- \fi
- \fi}%
- \iftraceTABLE\showtblwids{E#1}\fi}
-
-\newcount\xrowTBL
-\newcount\xcolTBL
-\newcount\xxrowTBL
-
-% dikke arg naar recurse wegwerken
-
-\def\dochecktblheightsone
- {\!!countb\gettblrow\xrowTBL\xcolTBL\relax
- % check row span
- \ifnum\!!countb>\plusone
- % current height in row
- \dimen0=\gettblht\xrowTBL\xcolTBL
- % find nearest height in row
- \dimen2=\zeropoint
- \dorecurse\maximumcol
- {\ifnum\recurselevel=\xcolTBL\else
- \doiftblrow\xrowTBL\recurselevel
- {\!!countc=\gettblrow\xrowTBL\recurselevel\relax
- \ifnum\!!countc=\plusone
- \dimen4=\gettblht\xrowTBL\recurselevel\relax
- \ifdim\dimen2<\dimen4
- \dimen2=\dimen4
- \fi
- \fi}%
- \fi}%
- \xxrowTBL\xrowTBL
- % calculate cummulative height
- \dimen4=\dimen2
- \!!countc\xrowTBL
- \advance\!!countc\minusone
- \dorecurse\!!countb
- {\ifnum\xxrowTBL=\xrowTBL\else
- \advance\dimen4 \gettblhei\xxrowTBL
- \fi
- \ifnum\recurselevel=\!!countb\else
- \settblnob\!!countc
- \advance\!!countc\plusone
- \fi
- \advance\xxrowTBL\plusone}%
- % distribute overshoot equally
- \ifdim\dimen4<\dimen0
- \advance\dimen0 -\dimen4
- \divide\dimen0 \!!countb
- \xxrowTBL\xrowTBL
- \settblhei\xrowTBL{\the\dimen2}%
- \dorecurse\!!countb
- {\dorecurse\maximumcol
- {\ifnum\recurselevel=\xcolTBL\else
- \scratchdimen\dimexpr\gettblht\xxrowTBL\recurselevel+\dimen0\relax
- \settblht\xxrowTBL\recurselevel{\the\scratchdimen}%
- \ifdim\gettblhei\xxrowTBL<\scratchdimen
- \settblhei\xxrowTBL{\the\scratchdimen}%
- \fi
- \fi}%
- \advance\xxrowTBL\plusone}%
- \else\ifdim\dimen4>\dimen0
- \settblhei\xrowTBL{\the\dimen2}%
- \fi\fi
- \fi}
-
-\def\checktblheightsone
- {\dorecurse\maximumrow
- {\xrowTBL\recurselevel\relax
- \dorecurse\maximumcol
- {\xcolTBL\recurselevel\relax
- \doiftblrow\xrowTBL\xcolTBL\dochecktblheightsone}}}
-
-\def\checktblheightstwo
- {}
-
-\def\showtblwids#1%
- {\vbox
- {\forgetall\tttf[#1]\dorecurse\maximumcol
- {\scratchdimen\gettblwid\recurselevel\relax
- [\recurselevel:\the\scratchdimen]}}}
-
-\def\TBLcharalign
- {\doifelse\tbltblaligncharacter\v!yes
- \doTBLcharalign\gobbleoneargument}
-
-\long\def\doTBLcharalign#1#2% column data
- {\edef\alignmentclass{#1}%
- \edef\alignmentcharacter{\tbltblalignmentcharacter}%
- \ifcase\tblpass\or
- \setfirstpasscharacteralign\checkalignment{#2}% {\strut#2\unskip}%
- \fi % force hsize, so always a second
- \setsecondpasscharacteralign \checkalignment{#2}% {\strut#2\unskip}%
- \ignorespaces}
-
-% new, needed for icare first col of 'doeltabel', experimental
-
-\long\def\dohandleTBLcellA#1#2[#3]#4% grouping added ! ! !
- {\bgroup
- \setupTBLcell{#1}{#2}%
- \setbox\scratchbox\hbox
- {\scratchdimen\tbltbldistance\relax
- \ifdim\scratchdimen>\gettbldis{#2}\relax
- \settbldis{#2}{\the\scratchdimen}%
- \fi
- \localframed
- [\@@tbl\@@tbl]
- [#3,\c!background=,\c!frame=\v!off]% 25% faster
- {\bTBLCELL\TBLcharalign{#2}{#4}\eTBLCELL\inTBLcell{#1}{#2}}}%
- \scratchdimen\gettblwid\tblcol\relax
- \ifdim\wd\scratchbox>\scratchdimen
- \ifsqueezeTBLspan
- \ifautosqueezeTBLspan
- \doifinsetelse\tbltblwidth{\v!fit,\v!fixed,\v!broad,\v!local}
- \donetrue \donefalse
- \else
- \donetrue
- \fi
- \ifdone % brr, 0
- \ifnum\number\gettblcol{#1}{#2}>\plusone \settblspn\tblcol\fi
- \fi
- \fi
- \doifelsetblspn\tblcol
- \donothing
- {\ifdim\gettblwid\tblcol<\wd\scratchbox
- \settblwid\tblcol{\the\wd\scratchbox}%
- \fi}% auto set
- \fi
- \scratchcounter\numexpr\tblrow+\plusone\relax
- \scratchdimen\gettblhei\scratchcounter\relax
- \ifdim\ht\scratchbox<\scratchdimen
- \settblhei\scratchcounter{\the\ht\scratchbox}% auto set
- \fi
- \settblht{#1}{#2}{\the\ht\scratchbox}%
- \settblwd{#1}{#2}{\the\wd\scratchbox}%
- \ifautoTBLcheckwidth
- \ifdim\wd\scratchbox<.75\hsize
- \ifdim\ht\scratchbox>2\openlineheight % honor width since this
- \scratchdimen\gettblaut\tblcol\relax % can be a figure or so
- \ifdim\scratchdimen=\zeropoint
- % side effect: when width is set to 0pt,
- % we can force a span that fits the sum of spans widths
- \settblaut\tblcol{\the\scratchdimen}%
- \else\ifdim\wd\scratchbox>\scratchdimen
- % unless span
- \settblaut\tblcol{\the\wd\scratchbox}%
- % to be translated
- \writestatus\m!TABLE
- {no auto width in (\number#1,\number#2)\space\the\wd\scratchbox/\the\hsize}%
- \fi\fi
- \fi
- \fi
- \fi
- \setbox2\null
- \wd2\wd\scratchbox \ht2\ht\scratchbox \dp2\dp\scratchbox
- \box2
- \egroup}
-
-\long\def\dohandleTBLcellBC#1#2#3[#4]#5%
- {\setbox\scratchbox\hbox
- {\setupTBLcell{#2}{#3}%
- \localframed
- [\@@tbl\@@tbl]
- [#4,#1,\c!frame=\v!off,\c!background=]
- {\bTBLCELL#5\eTBLCELL}}%
- \setbox2\null
- \wd2\wd\scratchbox \ht2\ht\scratchbox \dp2\dp\scratchbox
- \ifautoTBLrowspan
- \scratchcounter\numexpr\tblrow+\plusone\relax
- \doiftblrow\scratchcounter\tblcol
- {\scratchdimen\gettblhei\scratchcounter\relax % moved inside test
- \ifnum\gettblrow\scratchcounter\tblcol>\plusone \ifdim\ht\scratchbox>\scratchdimen
- \scratchdimen-\scratchdimen \advance\scratchdimen -\ht\scratchbox
- \ht2\scratchdimen
- \fi \fi}%
- \fi
- \box2 }
-
-\long\def\dohandleTBLcellB#1#2[#3]#4%
- {\scratchdimen\gettblaut\tblcol\relax
- \ifdim\scratchdimen>\zeropoint\relax
- \let\tblwidthkey\c!width
- \edef\tblwidth{\the\scratchdimen}%
- \else
- \scratchdimen\gettblwid\tblcol\relax
- \ifdim\scratchdimen>\zeropoint\relax
- \ifnum\gettblcol{#1}{#2}=\maximumcol\relax
- \scratchdimen\hsize
- \fi
- \let\tblwidthkey\c!width
- \edef\tblwidth{\the\scratchdimen}%
- \else
- \let\tblwidthkey\s!unknown
- \let\tblwidth\zeropoint
- \fi
- \fi
- \dohandleTBLcellBC{\tblwidthkey=\tblwidth}{#1}{#2}[#3]{\TBLcharalign{#2}{#4}}}
-
-\long\def\dohandleTBLcellC
- {\dohandleTBLcellBC{}}
-
-\long\def\dohandleTBLcellD#1#2[#3]#4%
- {\setupTBLcell{#1}{#2}%
- \bgroup
- \localframed
- [\@@tbl\@@tbl]
- [#3,\c!width=\widthTBL,\c!background=,\c!frame=\v!off]% 25% faster
- {\bTBLCELL\TBLcharalign{#2}{#4}\eTBLCELL}%
- \egroup}
-
-\long\def\dohandleTBLcellE#1#2[#3]#4%
- {\setupTBLcell{#1}{#2}%
- \getparameters[\@@tbl\@@tbl][#3]% to get the color right, the way we
- \color % handle color here prevents interference due to whatsit nodes
- [\tbltblcolor] % as well as permits local colors to take precedence
- {\ifdim\heightTBL=\zeropoint\relax % case: nc=maxcolumns
- \localframed
- [\@@tbl\@@tbl]
- [\c!color=,\c!width=\widthTBL]
- {\bTBLCELL\TBLcharalign{#2}{#4}\eTBLCELL}%
- \else
- \localframed
- [\@@tbl\@@tbl]
- [\c!color=,\c!width=\widthTBL,\c!height=\heightTBL]
- {\bTBLCELL\TBLcharalign{#2}{#4}\eTBLCELL}%
- \fi}%
- \hskip\gettbldis{#2}}
-
-\setupTABLE
- [\c!frameoffset=.5\linewidth,
- \c!backgroundoffset=\v!frame,
- \c!framecolor=\s!black,
- \c!color=,
- \c!style=,
- \c!headstyle=\v!bold,
- \c!headcolor=,
- \c!strut=\v!yes,
- \c!autostrut=\v!no,
- \c!aligncharacter=\v!no,
- \c!alignmentcharacter={,},
- \c!option=, % \v!stretch
- \c!header=,
- \c!spaceinbetween=,
- \c!maxwidth=8em,
- \c!textwidth=\hsize,
- \c!split=\v!auto,
- \c!splitoffset=0pt,
- \c!distance=\zeropoint, % individual column
- \c!columndistance=\zeropoint, % each column (whole table)
- \c!leftmargindistance=\zeropoint, % whole table
- \c!rightmargindistance=\zeropoint,% whole table
- \c!left=,
- \c!right=,
- \c!splitmethod=a]
-
-%D We have already prepared the previous macros for nesting,
-%D so we only have to pop in the right ones:
-
-%D New:
-
-\def\pushTBLparameters
- {\globalpushmacro\TBLlevel
- \ifcase\tblpass
- % we're just after \bTABLE
- \else\ifnum\TBLlevel>\zerocount
- \doglobal\increment\TBLlevel\relax
- \fi\fi}
-
-\def\popTBLparameters
- {\globalpopmacro\TBLlevel}
-
-\def\pushTBL
- {\ifnum\TBLlevel=\zerocount
- \global\advance\currenttbl\plusone
- \fi
- \doglobal\increment\TBLlevel\relax
- \ifnum\TBLlevel>\plusone
- \resetallTABLEparameters
- % we need a proper count push/pop
- \xdef\savedtblrow{\the\tblrow}\globalpushmacro\savedtblrow
- \xdef\savedtblcol{\the\tblcol}\globalpushmacro\savedtblcol
- \else
- \global\intabletrue
- \fi}
-
-\def\popTBL
- {\ifnum\TBLlevel>\plusone
- \globalpopmacro\savedtblrow\global\tblrow\savedtblrow
- \globalpopmacro\savedtblcol\global\tblcol\savedtblcol
- \else
- \global\intablefalse
- \fi
- \doglobal\decrement\TBLlevel\relax}
-
-% \bgroup
-% \setupTABLE[column][1][aligncharacter=yes, alignmentcharacter={,}]
-% \bTABLE
-% \bTR \bTD 1,2 \eTD \bTD 2 \eTD \eTR
-% \bTR \bTD 11,2 \eTD \bTD
-% {\setupTABLE[column][1][aligncharacter=yes, alignmentcharacter={,}]
-% \bTABLE
-% \bTR \bTD 1,2 \eTD \bTD 2 \eTD \eTR
-% \bTR \bTD 11,22 \eTD \bTD 2 \eTD \eTR
-% \bTR \bTD 11,2 \eTD \bTD 2 \eTD \eTR \eTABLE} \eTD \eTR
-% \bTR \bTD 11,22 \eTD \bTD 2 \eTD \eTR
-% \eTABLE
-% \egroup
-
-\newconditional\resetTABLEmode \settrue\resetTABLEmode
-
-\def\resetallTABLEparameters% moet genest wel werken
- {\ifnum\TBLlevel>\plusone % in ieder geval
- \ifconditional\resetTABLEmode
- \presetlocalframed % breedte hoogte diepte offset
- [\@@tbl\@@tbl]% % achtergrond, achtergrondraster, achtergrondkleur
- % not ok yet
- \setupTABLE
- [\c!frameoffset=.5\linewidth,
- \c!backgroundoffset=\v!frame,
- \c!framecolor=\s!black,
- \c!color=,
- \c!style=,
- \c!headstyle=,
- \c!headcolor=,
- \c!strut=\v!no,
- \c!aligncharacter=\v!no,
- \c!alignmentcharacter={,},
- \c!maxwidth=8em]%
- \else
- \setupTABLE
- [\c!width=\v!fit,
- \c!height=\v!fit]%
- \fi
- \fi}
-
-%D Spacing:
-%
-% \starttabulate
-% \NC text \NC text \NC \NR
-% \TB[small]
-% \NC text \NC text \NC \NR
-% \TB[4*big]
-% \NC text \NC text \NC \NR
-% \stoptabulate
-%
-% \starttable[|||]
-% \VL text \VL text \VL \AR
-% \TB[small]
-% \VL text \VL text \VL \AR
-% \TB[4*big]
-% \VL text \VL text \VL \AR
-% \stoptable
-
-\def\complexTableTB[#1]{\TABLEnoalign{\blank[#1]}}
-\def\simpleTableTB {\TABLEnoalign{\blank}}
-
-\def\TabulateTB
- {\complexorsimpleTable{TB}}
-
-\def\doTableinterline% #1
- {\ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \chuckTABLEautorow
- \else\ifnum\currentTABLEcolumn=\zerocount
- \TABLEnoalign
- {\globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow}%
- \else
- \setTABLEerror\TABLEmissingcolumn
- \handleTABLEerror
- \fi\fi
- \complexorsimpleTable} % {#1}
-
-\def\TableHL{\doTableinterline{HL}}
-\def\TableTB{\doTableinterline{TB}}
-
-\appendtoks\let\TB\TableTB \to\everytable
-\appendtoks\let\TB\TabulateTB\to\everytabulate % strange place
-
-\appendtoks \chardef\recodeverbatimmode\plustwo \to \everytable
-
-% new (for Olivier Turlier)
-%
-% \defineTABLEsetup [xx] [foregroundcolor=red]
-%
-% \bTABLE
-% \bTR \bTD oeps \eTD \bTD oeps \eTD \eTR
-% \bTR \bTDs[xx] oeps \eTDs \bTD oeps \eTD \eTR
-% \bTRs[xx] \bTD oeps \eTD \bTD oeps \eTD \eTRs
-% \eTABLE
-
-\def\defineTABLEsetup
- {\dodoubleargument\dodefineTABLEsetup}
-
-\def\dodefineTABLEsetup[#1][#2]%
- {\setvalue{\@@tbl:set:#1}{#2}}
-
-\long\def\bTDs[#1]#2\eTDs
- {\doifdefinedelse{\@@tbl:set:#1}
- {\@EA\@EA\@EA\bTD\@EA\@EA\@EA[\csname\@@tbl:set:#1\endcsname]#2\eTD}
- {\bTD[]#2\eTD}}
-
-\long\def\bTRs[#1]#2\eTRs
- {\doifdefinedelse{\@@tbl:set:#1}
- {\@EA\@EA\@EA\bTR\@EA\@EA\@EA[\csname\@@tbl:set:#1\endcsname]#2\eTR}
- {\bTR[]#2\eTR}}
-
-\protect \endinput
-
-% todo: mode: first|next (of niets)
diff --git a/tex/context/base/core-num.tex b/tex/context/base/core-num.tex
index 4dde1d4d3..a86ce8a1d 100644
--- a/tex/context/base/core-num.tex
+++ b/tex/context/base/core-num.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Numbering}
+\writestatus{loading}{ConTeXt Core Macros / Numbering}
\unprotect
diff --git a/tex/context/base/core-obj.lua b/tex/context/base/core-obj.lua
index 338ca9d1f..f879ddc8c 100644
--- a/tex/context/base/core-obj.lua
+++ b/tex/context/base/core-obj.lua
@@ -34,6 +34,10 @@ function jobobjects.set(tag,number,page)
collected[tag] = { number, page }
end
+function jobobjects.get(tag)
+ return collected[tag] or tobesaved[tag]
+end
+
function jobobjects.number(tag,default)
local o = collected[tag] or tobesaved[tag]
texsprint((o and o[1]) or default)
@@ -45,5 +49,6 @@ function jobobjects.page(tag,default)
end
function jobobjects.doifelse(tag)
- cs.testcase(collected[tag] or tobesaved[tag])
+ commands.testcase(collected[tag] or tobesaved[tag])
end
+
diff --git a/tex/context/base/core-obj.mkii b/tex/context/base/core-obj.mkii
index b0599dde9..6e210a0ab 100644
--- a/tex/context/base/core-obj.mkii
+++ b/tex/context/base/core-obj.mkii
@@ -11,9 +11,49 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+% todo, move more to mkiv, get rid of blabelgroup
+
+\writestatus{loading}{ConTeXt Core Macros / Object Handling}
+
\unprotect
-\def\mkcheckobjectreferences
+%D \macros
+%D {setobject,getobject,ifinobject}
+%D
+%D Boxes can be considered reuable objects. Unfortunaltely once
+%D passed to the \DVI\ file, such objects cannot be reused. In
+%D \PDF\ however, reusing is possible and sometimes even a
+%D necessity. Therefore, \CONTEXT\ supports reusable objects.
+%D
+%D During the \TEX\ processing run, boxes can serve the purpose
+%D of objects, and the \DVI\ driver module implements objects
+%D using packed boxes.
+%D
+%D The \PDF\ and \PDFTEX\ driver modules implement objects
+%D using \PDF\ forms. There is no (real) restriction on the
+%D number of objects there.
+%D
+%D The first application of objects in \CONTEXT\ concerned
+%D \METAPOST\ graphics and fill||in form fields. The first
+%D application can save lots of bytes, while the latter use is
+%D more a necessity than byte saving.
+%D
+%D \starttyping
+%D \setobject{class}{name}\somebox{}
+%D \getobject{class}{name}
+%D \stoptyping
+%D
+%D Here \type{\somebox} can be whatever box specification suits
+%D \TEX. We save the dimensions of an object, although some
+%D drivers will do so themselves. This means that when for
+%D instance using \PDFTEX\ we could save a hash entry plus some
+%D 20+ memory locations per object by delegating this
+%D housekeeping to the driver. The current approach permits
+%D us to keep the box characteristic too.
+
+\newif\ifinobject
+
+\def\checkobjectreferences
{\startnointerference
\protectlabels
\ifx\usedoutputdriver\currentoutput
@@ -24,6 +64,198 @@
\global\let\checkobjectreferences\relax
\stopnointerference}
+\def\objectplaceholder{NOT YET FLUSHED}%
+
+\def\presetobject#1#2% \global added
+ {\blabelgroup
+ \ifcsname\r!object#1::#2\endcsname\else
+ \global\@EA\let\csname\r!object#1::#2\endcsname\objectplaceholder
+ \fi
+ \elabelgroup}
+
+\def\dosetobject#1#2#3% \initializepaper this will move to \everyshipout
+ {\initializepaper
+ \blabelgroup
+ \ifcsname\r!object#2::#3\endcsname
+ \elabelgroup \expandafter\gobblefivearguments
+ \else % tzt, overload internal referenced objects to save entries
+ \elabelgroup \expandafter\dodosetobject
+ \fi
+ {#1}{#2}{#3}}
+
+\def\resetobject#1#2%
+ {\checkobjectreferences
+ \letbeundefined{\r!object#1::#2}}
+
+%D \macros
+%D {finalizeobjectbox}
+%D
+%D This one provides a hook for last minute object box processing
+%D we need this in \MKIV.
+
+\ifx\finalizeobjectbox\undefined
+ \let\finalizeobjectbox\gobbleoneargument
+\fi
+
+%D Somehow there is a rounding error problem in either \PDFTEX\
+%D or in viewers, or maybe it is conforming the specs. The next
+%D variable compensate for it by removing the rather tight
+%D clip.
+
+\def\objectoffset{1cm}
+
+% \def\dodosetobject#1#2#3%
+% {\bgroup
+% \inobjecttrue
+% \dowithnextbox{\dododosetobject{#1}{#2}{#3}\egroup}}
+
+\def\dodosetobject#1#2#3%
+ {\bgroup
+ \globalpushmacro\crossreferenceobject \objectreferenced
+ \inobjecttrue
+ \dowithnextbox
+ {\globalpopmacro\crossreferenceobject
+ \dododosetobject{#1}{#2}{#3}\egroup}}
+
+\def\dododosetobject#1#2#3%
+ {\blabelgroup
+ \dontshowcomposition % rather fuzzy in \setxvalue ... \hbox
+ \scratchdimen\objectoffset
+ \@EA\xdef\csname\r!object#2::#3\endcsname
+ {\noexpand\dohandleobject{#2}{#3}%
+ {\ifhbox\nextbox\hbox\else\vbox\fi}%
+ %{\the\nextboxwd}{\the\nextboxht}{\the\nextboxdp}}%
+ {\number\nextboxwd}{\number\nextboxht}{\number\nextboxdp}%
+ {\number\scratchdimen}}%
+ \expanded % freeze the dimensions since \dostartobject may use \nextbox
+ {\dostartobject
+ {#2}{#3}{\the\nextboxwd}{\the\nextboxht}{\the\nextboxdp}}%
+ \ifcase#1\relax\else \ifdim\objectoffset>\zeropoint
+ \setbox\nextbox\vbox spread 2\scratchdimen
+ {\forgetall \offinterlineskip
+ \vss\hbox spread 2\scratchdimen{\hss\flushnextbox\hss}\vss}%
+ \fi \fi
+ \flushnextbox
+ \dostopobject
+ \elabelgroup}
+
+\def\getobject#1#2%
+ {\blabelgroup
+ \let\dohandleobject\dogetobject
+ \csname\r!object#1::#2\endcsname}
+
+% \def\dogetobject#1#2#3#4#5#6%
+% {\initializepaper
+% \forgetall
+% \dontshowcomposition
+% \setbox\scratchbox\vbox
+% {\doinsertobject{#1}{#2}}%
+% \setbox\scratchbox#3%
+% {\vbox to #5\scaledpoint
+% {\ifdim\ht\scratchbox>#5\scaledpoint
+% % or \ifdim\wd\scratchbox>#4\scaledpoint
+% \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+% \else
+% \vss\box\scratchbox
+% \fi}}%
+% \wd\scratchbox#4\scaledpoint
+% \ht\scratchbox#5\scaledpoint
+% \dp\scratchbox#6\scaledpoint
+% \box\scratchbox
+% \elabelgroup}
+
+% \def\dogetobject#1#2#3#4#5#6#7%
+% {\initializepaper
+% \forgetall
+% \dontshowcomposition
+% \setbox\scratchbox\vbox
+% {\doinsertobject{#1}{#2}}%
+% \setbox\scratchbox#3%
+% {\vbox to #5\scaledpoint
+% {\ifdim\ht\scratchbox>#5\scaledpoint
+% % or \ifdim\wd\scratchbox>#4\scaledpoint
+% \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+% \else
+% \vss\box\scratchbox
+% \fi}}%
+% \scratchdimen#7\scaledpoint
+% \setbox\nextbox\hbox
+% {\hskip-\scratchdimen\lower\scratchdimen\flushnextbox}%
+% \wd\scratchbox#4\scaledpoint
+% \ht\scratchbox#5\scaledpoint
+% \dp\scratchbox#6\scaledpoint
+% \box\scratchbox
+% \elabelgroup}
+
+\def\dogetobject#1#2#3#4#5#6#7% don't change this, should work for dvi & pdf
+ {\initializepaper
+ \forgetall
+ \dontshowcomposition
+ \setbox\scratchbox\vbox
+ {\doinsertobject{#1}{#2}}%
+ \setbox\scratchbox#3%
+ {\vbox to #5\scaledpoint
+ {\ifdim\ht\scratchbox>#5\scaledpoint
+ \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+ \else\ifdim\wd\scratchbox>#4\scaledpoint
+ \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+ \else
+ %\vss\box\scratchbox
+ \vss\hbox to #4\scaledpoint{\box\scratchbox\hss}% fix Chof
+ \fi\fi}}%
+ \box\scratchbox
+ \elabelgroup}
+
+%D If needed one can ask for the dimensions of an object with:
+%D
+%D \starttyping
+%D \getobjectdimensions{class}{name}
+%D \stoptyping
+%D
+%D The results are reported in \type {\objectwidth}, \type
+%D {\objectheight} and \type {\objectdepth}.
+
+% \def\dogetobjectdimensions#1#2#3#4#5#6%
+% {\def\objectwidth {#4\s!sp}%
+% \def\objectheight{#5\s!sp}%
+% \def\objectdepth {#6\s!sp}}
+
+\def\dogetobjectdimensions#1#2#3#4#5#6#7%
+ {\def\objectwidth {#4\s!sp}%
+ \def\objectheight{#5\s!sp}%
+ \def\objectdepth {#6\s!sp}%
+ \def\objectmargin{#7\s!sp}}
+
+\def\getobjectdimensions#1#2%
+ {\let\dohandleobject\dogetobjectdimensions
+ \let\objectwidth \!!zeropoint
+ \let\objectheight\!!zeropoint
+ \let\objectdepth \!!zeropoint
+ \labelcsname\r!object#1::#2\endcsname}
+
+%D Apart from this kind of objects, that have typeset content,
+%D we can have low level driver specific objects. Both types
+%D can have references to internal representations, hidden for
+%D the user. We keep track of such references by means of a
+%D dedicated cross reference mechanism. Normally, objects are
+%D defined before they are used, but forward referencing
+%D sometimes occurs.
+%D
+%D \starttyping
+%D \dosetobjectreference {class} {identifier} {reference value} {page}
+%D \dogetobjectreference {class} {identifier} \csname
+%D \stoptyping
+%D
+%D These commands are to be called by the \type{\startobject},
+%D \type{\stopobject} and \type{\insertobject} specials.
+
+\def\objectreferenced{\global\chardef\crossreferenceobject\plusone}
+\def\driverreferenced{\global\chardef\crossreferenceobject\zerocount}
+
+\objectreferenced
+
+% no undefined test ! ! ! ! (pdftex fails on undefined objects)
+
\def\setobjectreferences
{\def\objectreference##1##2##3##4%
{\ifundefined{\r!driver##1::##2}%
@@ -37,19 +269,36 @@
\resetobjectreferences
-\def\mkregisterobjectreference#1#2#3%
+\def\doregisterobjectreference#1#2#3%
{\checkobjectreferences
\blabelgroup
\expanded{\writeutilitycommand{\noexpand\objectreference{#1}{#2}{#3}{\noexpand\realfolio}}}%
\setxvalue{\r!driver#1::#2}{{#3}{\noexpand\realfolio}}%
\elabelgroup}
-\def\mkoverloadobjectreference#1#2#3%
+\def\dooverloadobjectreference#1#2#3%
{\checkobjectreferences
\blabelgroup
\setxvalue{\r!driver#1::#2}{{#3}{\noexpand\realfolio}}%
\elabelgroup}
+\def\dosetobjectreference
+ {\ifcase\crossreferenceobject
+ \objectreferenced
+ \expandafter\dooverloadobjectreference
+ \else
+ \expandafter\doregisterobjectreference
+ \fi}
+
+\def\dosetdriverreference
+ {\driverreferenced\dosetobjectreference}
+
+\def\defaultobjectreference#1#2{0} % driver dependent
+\def\defaultobjectpage #1#2{\realfolio}
+
+\def\dogetobjectreference {\dodogetobjectreference\firstoftwoarguments\defaultobjectreference}
+\def\dogetobjectreferencepage{\dodogetobjectreference\secondoftwoarguments\defaultobjectpage}
+
\def\dodogetobjectreference#1#2#3#4#5%
{\checkobjectreferences
\blabelgroup
@@ -61,13 +310,28 @@
\fi
\elabelgroup}
-\def\mkgetobjectreference
- {\dodogetobjectreference\firstoftwoarguments\defaultobjectreference}
+\def\setobject {\driverreferenced\dosetobject1}
+\def\settightobject{\driverreferenced\dosetobject0}
+
+%D \macros
+%D {doifobjectfoundelse,doifobjectreferencefoundelse}
+%D
+%D To prevent redundant definition of objects, one can use
+%D the next tests:
+%D
+%D \starttyping
+%D \doifobjectfoundelse{class}{object}{do then}{do else}
+%D \doifobjectreferencefoundelse{class}{object}{do then}{do else}
+%D \stoptyping
-\def\mkgetobjectreferencepage
- {\dodogetobjectreference\secondoftwoarguments\defaultobjectpage}
+\def\doifobjectfoundelse#1#2%
+ {\blabelgroup \ifcsname\r!object#1::#2\endcsname
+ \elabelgroup \expandafter\firstoftwoarguments
+ \else
+ \elabelgroup \expandafter\secondoftwoarguments
+ \fi}
-\def\mkdoifobjectreferencefoundelse#1#2%
+\def\doifobjectreferencefoundelse#1#2%
{\checkobjectreferences
\blabelgroup \ifcsname\r!driver#1::#2\endcsname
\elabelgroup \expandafter\firstoftwoarguments
@@ -75,4 +339,33 @@
\elabelgroup \expandafter\secondoftwoarguments
\fi}
+%D \macros
+%D {doifobjectssupportedelse}
+%D
+%D Starting with reuse of graphics, we will implement object
+%D reuse when possible. To enable mechanisms to determine
+%D what method to use, we provide:
+%D
+%D \starttyping
+%D \doifobjectssupportedelse{true action}{false action}
+%D \stoptyping
+%D
+%D As we can see, currently objects depend on the special
+%D driver.
+
+\newif\ifobjectssupported \objectssupportedtrue
+
+\def\doifobjectssupportedelse
+ {\ifobjectssupported
+ \@EA\doifspecialavailableelse\@EA\doinsertobject
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+%D There is a conceptual problem here. Objects are not possible
+%D in \DVI, unless faked like in \type {spec-dvi}. This means
+%D that we must be careful in loading special drivers that do
+%D support objects while we still want to be able to use the
+%D \DVI\ output.
+
\protect \endinput
diff --git a/tex/context/base/core-obj.mkiv b/tex/context/base/core-obj.mkiv
index 3a54e6507..560a7012d 100644
--- a/tex/context/base/core-obj.mkiv
+++ b/tex/context/base/core-obj.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-obj,
-%D version=2006.10.16,
+%D version=1998.01.15,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Object Handling,
%D author=Hans Hagen,
@@ -11,16 +11,224 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Object Handling}
+
\unprotect
\let\objectreference\gobblefourarguments % catch mkii tuo stuff
\registerctxluafile{core-obj}{1.001}
-\def\mkregisterobjectreference #1#2#3{\expanded{\ctxlatelua{jobobjects.save("#1::#2",#3,\noexpand\the\realpageno)}}}
-\def\mkoverloadobjectreference #1#2#3{\ctxlua{jobobjects.set("#1::#2",#3,\the\realpageno)}}
-\def\mkgetobjectreference #1#2#3{\xdef#3{\ctxlua{jobobjects.number("#1::#2","\defaultobjectreference{#1}{#2}")}}}
-\def\mkgetobjectreferencepage #1#2#3{\xdef#3{\ctxlua{jobobjects.page("#1::#2","\defaultobjectpage{#1}{#2}")}}}
-\def\mkdoifobjectreferencefoundelse#1#2{\ctxlua{jobobjects.doifelse("#1::#2")}}
+%D \macros
+%D {setobject,getobject,ifinobject}
+%D
+%D Boxes can be considered reuable objects. Unfortunaltely once
+%D passed to the \DVI\ file, such objects cannot be reused. In
+%D \PDF\ however, reusing is possible and sometimes even a
+%D necessity. Therefore, \CONTEXT\ supports reusable objects.
+%D
+%D During the \TEX\ processing run, boxes can serve the purpose
+%D of objects, and the \DVI\ driver module implements objects
+%D using packed boxes.
+%D
+%D The \PDF\ and \PDFTEX\ driver modules implement objects
+%D using \PDF\ forms. There is no (real) restriction on the
+%D number of objects there.
+%D
+%D The first application of objects in \CONTEXT\ concerned
+%D \METAPOST\ graphics and fill||in form fields. The first
+%D application can save lots of bytes, while the latter use is
+%D more a necessity than byte saving.
+%D
+%D \starttyping
+%D \setobject{class}{name}\somebox{}
+%D \getobject{class}{name}
+%D \stoptyping
+%D
+%D Here \type{\somebox} can be whatever box specification suits
+%D \TEX. We save the dimensions of an object, although some
+%D drivers will do so themselves. This means that when for
+%D instance using \PDFTEX\ we could save a hash entry plus some
+%D 20+ memory locations per object by delegating this
+%D housekeeping to the driver. The current approach permits
+%D us to keep the box characteristic too.
+
+\newif\ifinobject
+
+\def\objectplaceholder{NOT YET FLUSHED}%
+
+\def\presetobject#1#2% \global added
+ {\ifcsname\r!object#1::#2\endcsname\else
+ \global\@EA\let\csname\r!object#1::#2\endcsname\objectplaceholder
+ \fi}
+
+\def\dosetobject#1#2#3% \initializepaper this will move to \everyshipout
+ {\initializepaper
+ \ifcsname\r!object#2::#3\endcsname
+ \expandafter\gobblefivearguments
+ \else % tzt, overload internal referenced objects to save entries
+ \expandafter\dodosetobject
+ \fi
+ {#1}{#2}{#3}}
+
+\def\resetobject#1#2%
+ {\letbeundefined{\r!object#1::#2}}
+
+%D \macros
+%D {finalizeobjectbox}
+%D
+%D This one provides a hook for last minute object box processing
+%D we need this in \MKIV.
+
+\ifx\finalizeobjectbox\undefined
+ \let\finalizeobjectbox\gobbleoneargument
+\fi
+
+%D Somehow there is a rounding error problem in either \PDFTEX\
+%D or in viewers, or maybe it is conforming the specs. The next
+%D variable compensate for it by removing the rather tight
+%D clip.
+
+\def\objectoffset{1cm}
+
+\def\dodosetobject#1#2#3%
+ {\bgroup
+ \globalpushmacro\crossreferenceobject \objectreferenced
+ \inobjecttrue
+ \dowithnextbox
+ {\globalpopmacro\crossreferenceobject
+ \dododosetobject{#1}{#2}{#3}\egroup}}
+
+\def\dododosetobject#1#2#3%
+ {\begingroup
+ \dontshowcomposition % rather fuzzy in \setxvalue ... \hbox
+ \scratchdimen\objectoffset
+ \@EA\xdef\csname\r!object#2::#3\endcsname
+ {\noexpand\dohandleobject{#2}{#3}%
+ {\ifhbox\nextbox\hbox\else\vbox\fi}%
+ {\number\nextboxwd}{\number\nextboxht}{\number\nextboxdp}%
+ {\number\scratchdimen}}%
+ \expanded % freeze the dimensions since \dostartobject may use \nextbox
+ {\dostartobject{#2}{#3}{\the\nextboxwd}{\the\nextboxht}{\the\nextboxdp}}%
+ \ifcase#1\relax\else \ifdim\objectoffset>\zeropoint
+ \setbox\nextbox\vbox spread 2\scratchdimen
+ {\forgetall \offinterlineskip
+ \vss\hbox spread 2\scratchdimen{\hss\flushnextbox\hss}\vss}%
+ \fi \fi
+ \flushnextbox
+ \dostopobject
+ \endgroup}
+
+\def\getobject#1#2%
+ {\begingroup
+ \let\dohandleobject\dogetobject
+ \csname\r!object#1::#2\endcsname}
+
+\def\dogetobject#1#2#3#4#5#6#7% don't change this, should work for dvi & pdf
+ {\initializepaper
+ \forgetall
+ \dontshowcomposition
+ \setbox\scratchbox\vbox
+ {\doinsertobject{#1}{#2}}%
+ \setbox\scratchbox#3%
+ {\vbox to #5\scaledpoint
+ {\ifdim\ht\scratchbox>#5\scaledpoint
+ \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+ \else\ifdim\wd\scratchbox>#4\scaledpoint
+ \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
+ \else
+ %\vss\box\scratchbox
+ \vss\hbox to #4\scaledpoint{\box\scratchbox\hss}% fix Chof
+ \fi\fi}}%
+ \box\scratchbox
+ \endgroup}
+
+%D If needed one can ask for the dimensions of an object with:
+%D
+%D \starttyping
+%D \getobjectdimensions{class}{name}
+%D \stoptyping
+%D
+%D The results are reported in \type {\objectwidth}, \type
+%D {\objectheight} and \type {\objectdepth}.
+
+\def\dogetobjectdimensions#1#2#3#4#5#6#7%
+ {\def\objectwidth {#4\s!sp}%
+ \def\objectheight{#5\s!sp}%
+ \def\objectdepth {#6\s!sp}%
+ \def\objectmargin{#7\s!sp}}
+
+\def\getobjectdimensions#1#2%
+ {\let\dohandleobject\dogetobjectdimensions
+ \let\objectwidth \!!zeropoint
+ \let\objectheight\!!zeropoint
+ \let\objectdepth \!!zeropoint
+ \labelcsname\r!object#1::#2\endcsname}
+
+%D Apart from this kind of objects, that have typeset content,
+%D we can have low level driver specific objects. Both types
+%D can have references to internal representations, hidden for
+%D the user. We keep track of such references by means of a
+%D dedicated cross reference mechanism. Normally, objects are
+%D defined before they are used, but forward referencing
+%D sometimes occurs.
+%D
+%D \starttyping
+%D \dosetobjectreference {class} {identifier} {reference value} {page}
+%D \dogetobjectreference {class} {identifier} \csname
+%D \stoptyping
+%D
+%D These commands are to be called by the \type{\startobject},
+%D \type{\stopobject} and \type{\insertobject} specials.
+
+\def\objectreferenced{\global\chardef\crossreferenceobject\plusone}
+\def\driverreferenced{\global\chardef\crossreferenceobject\zerocount}
+
+\objectreferenced
+
+% no undefined test ! ! ! ! (pdftex fails on undefined objects)
+
+\def\doregisterobjectreference#1#2#3{\normalexpanded{\noexpand\ctxlatelua{jobobjects.save("#1::#2",#3,\noexpand\the\realpageno)}}}
+\def\dooverloadobjectreference#1#2#3{\ctxlua{jobobjects.set("#1::#2",#3,\the\realpageno)}}
+
+\def\dosetobjectreference
+ {\ifcase\crossreferenceobject
+ \objectreferenced
+ \expandafter\dooverloadobjectreference
+ \else
+ \expandafter\doregisterobjectreference
+ \fi}
+
+\def\dosetdriverreference
+ {\driverreferenced\dosetobjectreference}
+
+\def\defaultobjectreference#1#2{0} % driver dependent
+\def\defaultobjectpage #1#2{\realfolio}
+
+\def\dogetobjectreference #1#2#3{\xdef#3{\ctxlua{jobobjects.number("#1::#2","\defaultobjectreference{#1}{#2}")}}}
+\def\dogetobjectreferencepage#1#2#3{\xdef#3{\ctxlua{jobobjects.page("#1::#2","\defaultobjectpage{#1}{#2}")}}}
+
+\def\setobject {\driverreferenced\dosetobject1}
+\def\settightobject{\driverreferenced\dosetobject0}
+
+%D \macros
+%D {doifobjectfoundelse,doifobjectreferencefoundelse}
+%D
+%D To prevent redundant definition of objects, one can use
+%D the next tests:
+%D
+%D \starttyping
+%D \doifobjectfoundelse{class}{object}{do then}{do else}
+%D \doifobjectreferencefoundelse{class}{object}{do then}{do else}
+%D \stoptyping
+
+\def\doifobjectfoundelse#1#2%
+ {\ifcsname\r!object#1::#2\endcsname
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\doifobjectreferencefoundelse#1#2{\ctxlua{jobobjects.doifelse("#1::#2")}}
\protect \endinput
diff --git a/tex/context/base/core-obj.tex b/tex/context/base/core-obj.tex
deleted file mode 100644
index 23873d2d6..000000000
--- a/tex/context/base/core-obj.tex
+++ /dev/null
@@ -1,365 +0,0 @@
-%D \module
-%D [ file=core-obj,
-%D version=1998.01.15,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Object Handling,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% todo, move more to mkiv, get rid of blabelgroup
-
-\writestatus{loading}{Context Core Macros / Object Handling}
-
-\unprotect
-
-\startmessages dutch library: references
- 30: onbekend object --
- 31: dubbel object --
-\stopmessages
-
-\startmessages english library: references
- 30: unknown object --
- 31: duplicate object --
-\stopmessages
-
-\startmessages german library: references
- 30: unbekanntes Object --
- 31: doppeltes Object --
-\stopmessages
-
-\startmessages czech library: references
- 30: neznamy objekt --
- 31: duplicitni object --
-\stopmessages
-
-\startmessages italian library: references
- 30: oggetto sconosciuto --
- 31: oggetto duplicato --
-\stopmessages
-
-\startmessages norwegian library: references
- 30: ukjent objekt --
- 31: duplikat objekt --
-\stopmessages
-
-\startmessages romanian library: references
- 30: obiect necunoscut --
- 31: obiect duplicat --
-\stopmessages
-
-\startmessages french library: references
- 30: objet -- inconnu
- 31: objet -- dupliqué
-\stopmessages
-
-%D \macros
-%D {setobject,getobject,ifinobject}
-%D
-%D Boxes can be considered reuable objects. Unfortunaltely once
-%D passed to the \DVI\ file, such objects cannot be reused. In
-%D \PDF\ however, reusing is possible and sometimes even a
-%D necessity. Therefore, \CONTEXT\ supports reusable objects.
-%D
-%D During the \TEX\ processing run, boxes can serve the purpose
-%D of objects, and the \DVI\ driver module implements objects
-%D using packed boxes.
-%D
-%D The \PDF\ and \PDFTEX\ driver modules implement objects
-%D using \PDF\ forms. There is no (real) restriction on the
-%D number of objects there.
-%D
-%D The first application of objects in \CONTEXT\ concerned
-%D \METAPOST\ graphics and fill||in form fields. The first
-%D application can save lots of bytes, while the latter use is
-%D more a necessity than byte saving.
-%D
-%D \starttyping
-%D \setobject{class}{name}\somebox{}
-%D \getobject{class}{name}
-%D \stoptyping
-%D
-%D Here \type{\somebox} can be whatever box specification suits
-%D \TEX. We save the dimensions of an object, although some
-%D drivers will do so themselves. This means that when for
-%D instance using \PDFTEX\ we could save a hash entry plus some
-%D 20+ memory locations per object by delegating this
-%D housekeeping to the driver. The current approach permits
-%D us to keep the box characteristic too.
-
-\newif\ifinobject
-
-\ifx\mkcheckobjectreferences\undefined \let\mkcheckobjectreferences\relax \fi
-
-\def\checkobjectreferences{\mkcheckobjectreferences}
-
-\def\objectplaceholder{NOT YET FLUSHED}%
-
-\def\presetobject#1#2% \global added
- {\blabelgroup
- \ifcsname\r!object#1::#2\endcsname\else
- \global\@EA\let\csname\r!object#1::#2\endcsname\objectplaceholder
- \fi
- \elabelgroup}
-
-\def\dosetobject#1#2#3% \initializepaper this will move to \everyshipout
- {\initializepaper
- \blabelgroup
- \ifcsname\r!object#2::#3\endcsname
- \elabelgroup \expandafter\gobblefivearguments
- \else % tzt, overload internal referenced objects to save entries
- \elabelgroup \expandafter\dodosetobject
- \fi
- {#1}{#2}{#3}}
-
-\def\resetobject#1#2%
- {\checkobjectreferences
- \letbeundefined{\r!object#1::#2}}
-
-%D \macros
-%D {finalizeobjectbox}
-%D
-%D This one provides a hook for last minute object box processing
-%D we need this in \MKIV.
-
-\ifx\finalizeobjectbox\undefined
- \let\finalizeobjectbox\gobbleoneargument
-\fi
-
-%D Somehow there is a rounding error problem in either \PDFTEX\
-%D or in viewers, or maybe it is conforming the specs. The next
-%D variable compensate for it by removing the rather tight
-%D clip.
-
-\def\objectoffset{1cm}
-
-% \def\dodosetobject#1#2#3%
-% {\bgroup
-% \inobjecttrue
-% \dowithnextbox{\dododosetobject{#1}{#2}{#3}\egroup}}
-
-\def\dodosetobject#1#2#3%
- {\bgroup
- \globalpushmacro\crossreferenceobject \objectreferenced
- \inobjecttrue
- \dowithnextbox
- {\globalpopmacro\crossreferenceobject
- \dododosetobject{#1}{#2}{#3}\egroup}}
-
-\def\dododosetobject#1#2#3%
- {\blabelgroup
- \dontshowcomposition % rather fuzzy in \setxvalue ... \hbox
- \scratchdimen\objectoffset
- \@EA\xdef\csname\r!object#2::#3\endcsname
- {\noexpand\dohandleobject{#2}{#3}%
- {\ifhbox\nextbox\hbox\else\vbox\fi}%
- %{\the\nextboxwd}{\the\nextboxht}{\the\nextboxdp}}%
- {\number\nextboxwd}{\number\nextboxht}{\number\nextboxdp}%
- {\number\scratchdimen}}%
- \expanded % freeze the dimensions since \dostartobject may use \nextbox
- {\dostartobject
- {#2}{#3}{\the\nextboxwd}{\the\nextboxht}{\the\nextboxdp}}%
- \ifcase#1\relax\else \ifdim\objectoffset>\zeropoint
- \setbox\nextbox\vbox spread 2\scratchdimen
- {\forgetall \offinterlineskip
- \vss\hbox spread 2\scratchdimen{\hss\flushnextbox\hss}\vss}%
- \fi \fi
- \flushnextbox
- \dostopobject
- \elabelgroup}
-
-\def\getobject#1#2%
- {\blabelgroup
- \let\dohandleobject\dogetobject
- \csname\r!object#1::#2\endcsname}
-
-% \def\dogetobject#1#2#3#4#5#6%
-% {\initializepaper
-% \forgetall
-% \dontshowcomposition
-% \setbox\scratchbox\vbox
-% {\doinsertobject{#1}{#2}}%
-% \setbox\scratchbox#3%
-% {\vbox to #5\scaledpoint
-% {\ifdim\ht\scratchbox>#5\scaledpoint
-% % or \ifdim\wd\scratchbox>#4\scaledpoint
-% \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
-% \else
-% \vss\box\scratchbox
-% \fi}}%
-% \wd\scratchbox#4\scaledpoint
-% \ht\scratchbox#5\scaledpoint
-% \dp\scratchbox#6\scaledpoint
-% \box\scratchbox
-% \elabelgroup}
-
-% \def\dogetobject#1#2#3#4#5#6#7%
-% {\initializepaper
-% \forgetall
-% \dontshowcomposition
-% \setbox\scratchbox\vbox
-% {\doinsertobject{#1}{#2}}%
-% \setbox\scratchbox#3%
-% {\vbox to #5\scaledpoint
-% {\ifdim\ht\scratchbox>#5\scaledpoint
-% % or \ifdim\wd\scratchbox>#4\scaledpoint
-% \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
-% \else
-% \vss\box\scratchbox
-% \fi}}%
-% \scratchdimen#7\scaledpoint
-% \setbox\nextbox\hbox
-% {\hskip-\scratchdimen\lower\scratchdimen\flushnextbox}%
-% \wd\scratchbox#4\scaledpoint
-% \ht\scratchbox#5\scaledpoint
-% \dp\scratchbox#6\scaledpoint
-% \box\scratchbox
-% \elabelgroup}
-
-\def\dogetobject#1#2#3#4#5#6#7% don't change this, should work for dvi & pdf
- {\initializepaper
- \forgetall
- \dontshowcomposition
- \setbox\scratchbox\vbox
- {\doinsertobject{#1}{#2}}%
- \setbox\scratchbox#3%
- {\vbox to #5\scaledpoint
- {\ifdim\ht\scratchbox>#5\scaledpoint
- \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
- \else\ifdim\wd\scratchbox>#4\scaledpoint
- \vss\hbox to #4\scaledpoint{\hss\box\scratchbox\hss}\vss
- \else
- %\vss\box\scratchbox
- \vss\hbox to #4\scaledpoint{\box\scratchbox\hss}% fix Chof
- \fi\fi}}%
- \box\scratchbox
- \elabelgroup}
-
-%D If needed one can ask for the dimensions of an object with:
-%D
-%D \starttyping
-%D \getobjectdimensions{class}{name}
-%D \stoptyping
-%D
-%D The results are reported in \type {\objectwidth}, \type
-%D {\objectheight} and \type {\objectdepth}.
-
-% \def\dogetobjectdimensions#1#2#3#4#5#6%
-% {\def\objectwidth {#4\s!sp}%
-% \def\objectheight{#5\s!sp}%
-% \def\objectdepth {#6\s!sp}}
-
-\def\dogetobjectdimensions#1#2#3#4#5#6#7%
- {\def\objectwidth {#4\s!sp}%
- \def\objectheight{#5\s!sp}%
- \def\objectdepth {#6\s!sp}%
- \def\objectmargin{#7\s!sp}}
-
-\def\getobjectdimensions#1#2%
- {\let\dohandleobject\dogetobjectdimensions
- \let\objectwidth \!!zeropoint
- \let\objectheight\!!zeropoint
- \let\objectdepth \!!zeropoint
- \labelcsname\r!object#1::#2\endcsname}
-
-%D Apart from this kind of objects, that have typeset content,
-%D we can have low level driver specific objects. Both types
-%D can have references to internal representations, hidden for
-%D the user. We keep track of such references by means of a
-%D dedicated cross reference mechanism. Normally, objects are
-%D defined before they are used, but forward referencing
-%D sometimes occurs.
-%D
-%D \starttyping
-%D \dosetobjectreference {class} {identifier} {reference value} {page}
-%D \dogetobjectreference {class} {identifier} \csname
-%D \stoptyping
-%D
-%D These commands are to be called by the \type{\startobject},
-%D \type{\stopobject} and \type{\insertobject} specials.
-
-\def\objectreferenced{\global\chardef\crossreferenceobject\plusone}
-\def\driverreferenced{\global\chardef\crossreferenceobject\zerocount}
-
-\objectreferenced
-
-% no undefined test ! ! ! ! (pdftex fails on undefined objects)
-
-\def\dosetobjectreference
- {\ifcase\crossreferenceobject
- \objectreferenced
- \expandafter\mkoverloadobjectreference
- \else
- \expandafter\mkregisterobjectreference
- \fi}
-
-\def\dosetdriverreference
- {\driverreferenced\dosetobjectreference}
-
-\def\defaultobjectreference#1#2{0} % driver dependent
-\def\defaultobjectpage #1#2{\realfolio}
-
-\def\dogetobjectreference {\mkgetobjectreference}
-\def\dogetobjectreferencepage{\mkgetobjectreferencepage}
-
-\def\setobject {\driverreferenced\dosetobject1}
-\def\settightobject{\driverreferenced\dosetobject0}
-
-%D \macros
-%D {doifobjectfoundelse,doifobjectreferencefoundelse}
-%D
-%D To prevent redundant definition of objects, one can use
-%D the next tests:
-%D
-%D \starttyping
-%D \doifobjectfoundelse{class}{object}{do then}{do else}
-%D \doifobjectreferencefoundelse{class}{object}{do then}{do else}
-%D \stoptyping
-
-\def\doifobjectfoundelse#1#2%
- {\blabelgroup \ifcsname\r!object#1::#2\endcsname
- \elabelgroup \expandafter\firstoftwoarguments
- \else
- \elabelgroup \expandafter\secondoftwoarguments
- \fi}
-
-\def\doifobjectreferencefoundelse{\mkdoifobjectreferencefoundelse}
-
-%D \macros
-%D {doifobjectssupportedelse}
-%D
-%D Starting with reuse of graphics, we will implement object
-%D reuse when possible. To enable mechanisms to determine
-%D what method to use, we provide:
-%D
-%D \starttyping
-%D \doifobjectssupportedelse{true action}{false action}
-%D \stoptyping
-%D
-%D As we can see, currently objects depend on the special
-%D driver.
-
-\newif\ifobjectssupported \objectssupportedtrue
-
-\def\doifobjectssupportedelse
- {\ifobjectssupported
- \@EA\doifspecialavailableelse\@EA\doinsertobject
- \else
- \@EA\secondoftwoarguments
- \fi}
-
-%D There is a conceptual problem here. Objects are not possible
-%D in \DVI, unless faked like in \type {spec-dvi}. This means
-%D that we must be careful in loading special drivers that do
-%D support objects while we still want to be able to use the
-%D \DVI\ output.
-
-%D Plugin code:
-
-\loadmarkfile{core-obj}
-
-\protect \endinput
diff --git a/tex/context/base/core-par.tex b/tex/context/base/core-par.tex
index aa58ebb1e..0b283b294 100644
--- a/tex/context/base/core-par.tex
+++ b/tex/context/base/core-par.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{ConTeXt Pararaph Tricks}
+\writestatus{loading}{ConTeXt Core Macros / Pararaph Tricks}
\unprotect
diff --git a/tex/context/base/core-pgr.tex b/tex/context/base/core-pgr.tex
index e6f91cec8..ab2378441 100644
--- a/tex/context/base/core-pgr.tex
+++ b/tex/context/base/core-pgr.tex
@@ -2,7 +2,7 @@
%D [ file=core-pgr, % split off core-pos
%D version=1999.08.01,
%D title=\CONTEXT\ Core Macros,
-%D subtitle=Positioning Support,
+%D subtitle=Positioning Graphics,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Positioning Grapics}
+\writestatus{loading}{ConTeXt Core Macros / Positioning Grapics}
%D Before we come to graphics support, we have to make sure of
%D the reference point on the page. The next macro does so and
@@ -898,7 +898,7 @@
\def\calculatenexttextpardimensions
{\docalculatetextpardimensions\nextbtbanchor\nextetbanchor\relax}
-\def\docalculatetextpardimensions#1#2#3%
+\def\docalculatetextpardimensions#1#2#3% todo: dimexpr
{\scratchcounter\MPp#2%\etbanchor
\advance\scratchcounter-\MPp#1%\btanchor
\edef\textparpages{\the\scratchcounter}%
@@ -911,7 +911,7 @@
\scratchdimen \MPy#1%\btanchor
\advance\scratchdimen-\MPy#2%\etbanchor
\advance\scratchdimen-\MPy\textanchor
- \advance\scratchdimen \MPy\textanchor
+ \advance\scratchdimen \MPy\textanchor % - and then + ?
\advance\scratchdimen \MPh\textanchor\relax
\ifcase\scratchcounter>2 \ifnum\scratchcounter<5
% more pages
@@ -1185,7 +1185,7 @@
% \stopbuffer
% \getbuffer \typebuffer \flushstatus \page
-\newdimen\laststackvmove
+\newdimen\laststackvmove % use \scratchdimenone instead of skip
\def\stackeddown
{\bgroup
@@ -1214,7 +1214,7 @@
-\MPd\currentposition % untested
+\MPd\previousposition % untested
+\MPh\currentposition
- \relax
+ \relax\relax % second relax realy needed, forgotten while dimexpressing
% todo: also take depth into account
\ifdim\scratchskip<\scratchdimen
%\registerstatus{no \the\scratchskip}%
diff --git a/tex/context/base/core-pos.lua b/tex/context/base/core-pos.lua
index 212c65190..be2ac1915 100644
--- a/tex/context/base/core-pos.lua
+++ b/tex/context/base/core-pos.lua
@@ -18,6 +18,8 @@ jobpositions = jobpositions or { }
jobpositions.collected = jobpositions.collected or { }
jobpositions.tobesaved = jobpositions.tobesaved or { }
+-- these are global since they are used often at the tex end
+
ptbs, pcol = jobpositions.tobesaved, jobpositions.collected -- global
local function initializer()
@@ -35,7 +37,7 @@ function jobpositions.replace(name,...)
end
function jobpositions.doifelse(name)
- cs.testcase(jobpositions.collected[name] or ptbs[name])
+ commands.testcase(jobpositions.collected[name] or ptbs[name])
end
function jobpositions.MPp(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[1]) or '0' ) end
diff --git a/tex/context/base/core-pos.mkii b/tex/context/base/core-pos.mkii
index 754673cfa..58784ed7b 100644
--- a/tex/context/base/core-pos.mkii
+++ b/tex/context/base/core-pos.mkii
@@ -11,35 +11,86 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
-
-%D A unique prefix used for storing data.
-
-\def\POSprefix{POS::}
-
-%D Reading form the utility file.
-
-\def\pxypos {\pospxy} % obsolete
-\def\pxyposwhd {\pospxywhd} % obsolete
-\def\pxyposplus{\pospxyplus} % obsolete
+% needs a cleanup, things may change; we also need to move the mp
+% related code to meta-pos
-\def\resetpositions
- {\let\pospxy \gobblefourarguments
- \let\pospxywhd \gobblesevenarguments
- \let\pospxyplus\gobbleeightarguments}
+% shorter tags, ..:achtergrond:.. etc in pos actions
-\def\setpositions
- {\let\pospxy \setpospxy
- \let\pospxywhd \setpospxywhd
- \let\pospxyplus\setpospxyplus}
+% dubbele text- * pos's eruit
-%D We need to initialize.
+% class pos -> als gelijk aan vorige, dan niet niet definieren
+% en erven, maw:
+%
+% 1 -> opslaan
+% 2 -> undef, dus == prev
+% 3 -> undef, dus == prev
+% 4 -> opslaan
+
+\writestatus{loading}{ConTeXt Core Macros / Positioning Support}
+
+% todo: topskip als optie voor eerste regel achtergrond
+% todo: build pos layers on top of layers
+% todo: positionlayer pos van text-1 etc delen
+
+%D Although \TEX\ has a rather powerful channel to the outside
+%D world, called \type {\special}, real communication with
+%D other programs is complicated by the fact that no positional
+%D information is available. Mid 1999, I discussed this with
+%D \THANH, the author of \PDFTEX, and after some experiments,
+%D \PDFTEX\ was extended with a simple but effective mechanism,
+%D that provided positional information. The interesting
+%D thought is that, although \TEX\ is frozen, similar
+%D functionality could have been achieved with \type
+%D {\specials} and an additional \DVI\ postprocessor.
+%D
+%D Since we want to be as compatible as can be, \CONTEXT\ will
+%D support both methods, although the development is primarily
+%D driven by the \PDFTEX\ way of doing things. Since the
+%D mechanism is basically not limited to one application, for
+%D the moment we stick to building the functionality around one
+%D \CONTEXT\ special command, but at the same time we keep our
+%D eyes open for extensions in other directions.
+%D
+%D A question that may arise when one reads this module, is to
+%D what extend these macros are generic, in the sense that they
+%D could be collected in a support module instead of a core
+%D module. Since the mechanism described here will closely
+%D cooperate with the \METAPOST\ support built in \CONTEXT,
+%D which in turn will be tightly integrated with the \CONTEXT\
+%D overlay mechanisms, I decided to write a core module instead
+%D of a support one. This makes even more sense, when one takes
+%D into account that this kind of support depends on special
+%D drivers.
-\resetpositions
+\unprotect
-\addutilityreset{positions}
+%D The first application of positional information was embedded
+%D graphics. Since we are interacting with text, it made sense
+%D to take the current line height and depth into account too.
+%D This is why we have two basic position macros: one for
+%D simple positions, and one for boxes.
+%D
+%D We could have sticked to one special, and actually did so in
+%D earlier experiments, but for convenience, as well for
+%D clearness, we now have two alternatives. This approach will
+%D save us quite some bytes when storing large quantities of
+%D positional information. We save as less information as
+%D needed, that is, we save no dimensions, in a \METAPOST\
+%D friendly way.
+%D
+%D The three specials involved are:
+%D
+%D \starttyping
+%D \dosetposition {identifier}
+%D \dosetpositionwhd {identifier} {width} {height} {depth}
+%D \dosetpositionplus {identifier} {width} {height} {depth} {list}
+%D \dosetpositionpapersize {width} {height}
+%D \stoptyping
+
+\newbox\positionbox
+\newif \ifpositioning
-%D Core set macros:
+\def\POSprefix{POS::}
\def\setpospxy#1#2#3#4%
{\@EA\xdef\csname\POSprefix#1\endcsname
@@ -66,6 +117,35 @@
\the\dimexpr#7\relax,%
#8}}
+%D This is real tricky! The page anchor is applied to the
+%D page box and therefore flushed first. So, when present, it
+%D is applied to all positions except itself.
+
+\chardef\positionanchormode=0 % don't relocate page origin
+\chardef\positionanchormode=1 % relocate page origin once
+
+%D The core set macros.
+
+\def\pxypos {\pospxy} % obsolete
+\def\pxyposwhd {\pospxywhd} % obsolete
+\def\pxyposplus{\pospxyplus} % obsolete
+
+\def\resetpositions
+ {\let\pospxy \gobblefourarguments
+ \let\pospxywhd \gobblesevenarguments
+ \let\pospxyplus\gobbleeightarguments}
+
+\def\setpositions
+ {\let\pospxy \setpospxy
+ \let\pospxywhd \setpospxywhd
+ \let\pospxyplus\setpospxyplus}
+
+%D We need to initialize.
+
+\resetpositions
+
+\addutilityreset{positions}
+
%D Sometimes we want to trick the position handler a bit:
\def\replacepospxywhd#1#2#3#4#5#6#7%
@@ -77,7 +157,55 @@
\the\dimexpr#6\relax,%
\the\dimexpr#7\relax}}
-%D Writing to the utility file.
+%D For postprocessing purposes, we save the number of
+%D positions.
+
+\newcount\currentpositions % current number of positions
+\newcounter\totalnofpositions % total from previous run
+
+\appendtoks
+ \expanded{\savecurrentvalue\noexpand\totalnofpositions{\the\currentpositions}}%
+\to \everybye
+
+%D The next switch can be used to communicate a special
+%D situation. Positioning and associated actions can be
+%D executed any time. However, in for instance backgrounds
+%D they can be collected in a layer, for instance the text
+%D layer (especially the hidden text layer). In the case of
+%D floats, we run into problems, since the page information is
+%D not applicable when the content floats indeed. In such
+%D situations one can treat positions and graphics local.
+
+\newif\iflocalpositioning
+
+%D Watch out: sometimes a pagebreak occurs inside a float
+%D placement, so there we need to disable local mode.
+
+\appendtoks
+ \localpositioningtrue
+\to \everyinsidefloat
+
+\appendtoks
+ \localpositioningfalse
+\to \everypagebody
+
+\def\checkpositions
+ {\startnointerference
+ \protectlabels
+ \doutilities{positions}\jobname\empty\relax\relax
+ \global\let\checkpositions\relax
+ \stopnointerference}
+
+%D Since the positional values are to be fully expandable, we
+%D need to preload them as soon as possible, which is why we
+%D load the data when we start a text.
+
+\appendtoks \checkpositions \to \everystarttext
+
+%D Positions are either generated at a delayed write time
+%D (in \PDFTEX), or derived from the dvi file. The actual
+%D method is implemented in a special driver. If needed, the
+%D driver can fall back on the following macros.
\def\dolazysaveposition#1#2#3#4% tag page x y
{\expanded{\writeutilitycommand{\noexpand\pospxy
@@ -103,6 +231,13 @@
{\expanded{\immediatewriteutilitycommand{\noexpand\pospxyplus
{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}}}
+%D \macros
+%D {MPp, MPx, MPy, MPw, MPh, MPd,
+%D MPxy, MPll, MPlr, MPur, MPul, MPpos}
+%D
+%D Access to the positional information is provided by macros
+%D with short names that are clearly meant for \METAPOST.
+
\def\MPp {\doMPxyhdwlr\doMPp }
\def\MPx {\doMPxyhdwlr\doMPx }
\def\MPy {\doMPxyhdwlr\doMPy }
@@ -136,12 +271,25 @@
#10,0pt,0pt,0pt,0pt,0pt,0pt\relax
\fi}
-% \def\doMPxyhdwlr#1#2% evt kan \s!unknown leeg zijn
-% {\@EA\@EA\@EA#1\csname\POSprefix
-% \ifcsname\POSprefix#2\endcsname#2\else\s!unknown\fi\endcsname
-% ,0pt,0pt,0pt,0pt\relax}
-%
-% \setvalue{\POSprefix\s!unknown}{0,0pt,0pt}
+%D \macros
+%D {MPplus, MPrest, MPv, MPvv}
+%D
+%D Since we will probably keep on extending, we provide a
+%D general extension macro. The plus alternative takes an
+%D extra argument, denoting what additional parameter to pick
+%D up. So, the third extra is fetched with,
+%D
+%D \starttyping
+%D \MPplus{identifier}{3}{default}
+%D \stoptyping
+%D
+%D All extras (comma separated) are fetched with:
+%D
+%D \starttyping
+%D \MPrest{identifier}
+%D \stoptyping
+%D
+%D The extra parameters are not treated.
\def\MPplus {\MPdoplus\doMPplus}
\def\MPrest#1{\MPdoplus\doMPrest{#1}{}}
@@ -165,7 +313,177 @@
\def\doMPrest#1,#2,#3,#4,#5,#6,#7,,#8\relax#9%
{#7}
-%D Testing:
+%D \macros
+%D {MPanchor}
+%D
+%D For readability we define a few synonyms:
+
+\def\MPanchor{\MPpos}
+
+%D \macros
+%D {POSp, POSx, POSy, POSh, POSd, POSw}
+%D
+%D and:
+
+\def\POSp{\MPp} \def\POSx{\MPx} \def\POSy{\MPy}
+\def\POSh{\MPh} \def\POSd{\MPd} \def\POSw{\MPw}
+
+%D There are two low level positioning macros. Both store the
+%D position as well as execute an action associated with that
+%D position.
+
+\def\initializenextposition
+ {\ifpositioning \else
+ \global\positioningtrue
+ \dosetpositionpapersize
+ {\printpaperwidth }%
+ {\printpaperheight}%
+ \fi
+ \global\advance\currentpositions\plusone}
+
+\def\setpositiononly#1%
+ {\iftrialtypesetting
+ % nothing
+ \else
+ \initializenextposition
+ \def\currentposition{#1}%
+ \dosetposition\currentposition
+ \fi}
+
+\def\setposition#1%
+ {\iftrialtypesetting
+ % nothing
+ \else
+ \initializenextposition
+ \def\currentposition{#1}%
+ \dosetposition\currentposition
+ \traceposstring\llap\green{\currentposition>}%
+ \dopositionaction\currentposition
+ \fi}
+
+\def\setpositiondata#1#2#3#4%
+ {\iftrialtypesetting \else
+ \initializenextposition
+ \hbox
+ {\def\currentposition{#1}%
+ \dosetpositionwhd\currentposition
+ {\the\dimexpr#2\relax}%
+ {\the\dimexpr#3\relax}%
+ {\the\dimexpr#4\relax}%
+ \traceposstring\llap\green{\currentposition>}%
+ \dopositionaction\currentposition
+ \hss}%
+ \fi}
+
+\def\setpositionbox#1%
+ {\dowithnextbox
+ {\iftrialtypesetting
+ \flushnextbox
+ \else
+ \initializenextposition
+ \hbox to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionwhd\currentposition
+ {\the\nextboxwd}%
+ {\the\nextboxht}%
+ {\the\nextboxdp}%
+ \traceposstring\llap\green{\currentposition>}%
+ \setbox\positionbox\flushnextbox
+ \dopositionaction\currentposition
+ \box\positionbox
+ \hss}%
+ \fi}}
+
+\def\setpositiondataplus#1#2#3#4#5%
+ {\iftrialtypesetting \else
+ \initializenextposition
+ \hbox % bug: to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition
+ {\the\dimexpr#2\relax}%
+ {\the\dimexpr#3\relax}%
+ {\the\dimexpr#4\relax}%
+ {#5}%
+ \traceposstring\rlap\magenta{<\currentposition}%
+ \dopositionaction\currentposition
+ \hss}%
+ \fi}
+
+\def\setpositionplus#1#2%
+ {\dowithnextbox
+ {\iftrialtypesetting
+ \flushnextbox
+ \else
+ \initializenextposition
+ \hbox to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition
+ {\the\nextboxwd}%
+ {\the\nextboxht}%
+ {\the\nextboxdp}%
+ {#2}%
+ \traceposstring\rlap\magenta{<\currentposition}%
+ \setbox\positionbox\flushnextbox
+ \dopositionaction\currentposition
+ \box\positionbox
+ \hss}%
+ \fi}}
+
+\let\currentposition\s!unknown
+
+%D A few more low level macros take care of defining and
+%D recalling actions. We could save this information in the
+%D position containers themselves, this would save hash
+%D entries, but at the cost of much more time consuming
+%D expansion. Actions are saved globally!
+
+\newtoks\everypositionaction
+
+\let\POSactionprefix\POSprefix
+
+\def\dosetpositionaction#1%
+ {\setgvalue{\POSactionprefix#1::}}
+
+%D The lists can become quite long (also because there can
+%D be lots of parameters passed on) so we provide a hook
+%D to clean up the list afterwards.
+
+\let\cleanuppositionaction\gobbleoneargument
+
+\def\doifpositionaction#1%
+ {\ifcsname\POSactionprefix#1::\endcsname
+ \@EA\firstofoneargument
+ \else
+ \@EA\gobbleoneargument
+ \fi}
+
+\def\doifpositionactionelse#1%
+ {\ifcsname\POSactionprefix#1::\endcsname
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+%D We can copy a position with:
+%D
+%D \starttyping
+%D \copyposition {to} {from}
+%D \stoptyping
+%D
+%D Again, this is a global action.
+
+\def\copyposition#1#2%
+ {\ifcsname\POSprefix#2\endcsname
+ \global\@EA\let\csname\POSprefix#1\@EA\endcsname\csname\POSprefix#2\endcsname
+ \fi}
+
+%D The fact that handling positions is a two pass operation, is
+%D one of the reasons why we need to be able to test for
+%D existence, using:
+%D
+%D \starttyping
+%D \doifpositionelse {identifier} {found action} {not found action}
+%D \stoptyping
\def\doifpositionelse#1%
{\ifcsname\POSprefix#1\endcsname
@@ -174,11 +492,382 @@
\expandafter\secondoftwoarguments
\fi}
-%D Copying:
+%D We have now arrived at a few macros that would make sense as
+%D support macros, but ended up in the core.
+
+%D \macros
+%D {xypos}
+%D
+%D We have several macros available to save positions. Later
+%D we will see applications.
+%D
+%D \starttabulate[|l|l||]
+%D \NC \type {\xypos} \NC \NC simple position with no dimensions \NC \NR
+%D \NC \type {\hpos} \NC \NC position and characteristics of a \type {\hbox} \NC \NR
+%D \NC \type {\vpos} \NC \NC position and characteristics of a \type {\vbox} \NC \NR
+%D \NC \type {\bpos} \NC b: \NC begin point in a line \NC \NR
+%D \NC \type {\epos} \NC e: \NC end point in a line \NC \NR
+%D \NC \type {\fpos} \NC f: \NC begin point in a paragraph \NC \NR
+%D \NC \type {\tpos} \NC t: \NC end point in a paragraph \NC \NR
+%D \stoptabulate
+%D
+%D Each macro takes an identifier as argument, and the \type
+%D {\hpos} and \type {\vpos} also expect box content.
+
+% \def\xypos{\initializenextposition\dosetposition}
+
+\let\xypos\setpositiononly
+
+\def\hpos#1{\dontleavehmode\setpositionbox{#1}\hbox}
+\def\vpos#1{\setpositionbox{#1}\vbox}
+
+\def\bpos#1{\hpos{b:#1}{\strut}\ignorespaces}
+\def\epos#1{\removelastspace\hpos{e:#1}{\strut}}
+
+\def\fpos#1%
+ {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut
+ \ignorespaces}
+
+\def\tpos#1%
+ {\removelastspace
+ \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
+
+\def\ffpos#1%
+ {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut\wpos{#1}%
+ \ignorespaces}
+
+\def\ttpos#1%
+ {\removelastspace
+ \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
+
+\def\wpos#1%
+ {\dontleavehmode\vadjust % may disappear if buried
+ {\setbox0\hbox{\raise\strutdp\hbox{\rawwpos{#1}}}%
+ \rlap{\smashedbox0}}}
+
+\def\wwpos#1% \hsmashed{\llap{\rawwpos{#1}}}
+ {\rlap
+ {\setbox0\hbox{\rawwpos{#1}}%
+ \smashedbox0}}
+
+\def\rawwpos#1%
+ {\hpos{w:#1}
+ {\strut
+ \hskip-\leftskip
+ \hskip\hsize
+ \hskip-\rightskip}}
+
+% the next macro disables par positions (in inner boxes) and
+% only registers the width
+
+\def\setinnerparpositions
+ {\let\fpos\ffpos
+ \let\tpos\ttpos
+ \let\wpos\wwpos}
+
+% example of usage: (see for application "techniek")
+%
+% \appendtoks
+% \setinnerparpositions
+% \to \everytabulate
+
+%D When we want to calculate more complex backgrounds, we
+%D need to know what the current indentation scheme is. At
+%D the cost of many positions and memory, we can keep track
+%D of them. This mechanism is activated automatically
+%D based on information collected in the previous pass.
+
+\newcount\parposcounter
+
+\newif\ifpositioningpar
+
+% we can check for used entries, and if not, then not add one
+
+\def\registerparoptions
+ {\ifpositioningpar \ifpositioning \iftrialtypesetting \else
+ \ifinpagebody \else \ifmmode \else \ifinformula \else
+ \ifprocessingverbatim
+ \iflinepar \doregisterparoptions \fi
+ \else
+ \doregisterparoptions
+ \fi
+ \fi \fi \fi
+ \fi \fi \fi}
+
+\chardef\parposstrut=1 % 0 => no strut data, so fall backs used
+
+\newif\iftracepositions
+
+% \def\doregisterparoptions
+% {\global\advance\parposcounter\plusone
+% \begingroup
+% \leftskip 1\leftskip
+% \rightskip1\rightskip
+% \setpositiondataplus
+% {p:\number\parposcounter}% identifier
+% {\the\zeropoint}%
+% {\the\strutht}%
+% {\the\strutdp}%
+% {\the\hsize ,% 1
+% \the\leftskip ,% 2
+% \the\rightskip ,% 3
+% \the\hangindent,% 4
+% \the\hangafter ,% 5 (num)
+% \the\parindent }% 6
+% %\normalhbox{\registerparsymbol}%
+% \registerparsymbol
+% \endgroup}
+
+\def\doregisterparoptions
+ {\global\advance\parposcounter\plusone
+ \setpositiondataplus
+ {p:\number\parposcounter}% identifier
+ {\the\zeropoint}%
+ {\the\strutht}%
+ {\the\strutdp}%
+ {\the\hsize,\the\dimexpr\leftskip\relax,\the\dimexpr\rightskip\relax,\the\hangindent,\the\hangafter,\the\parindent}%
+ %\normalhbox{\registerparsymbol}%
+ \iftracepositions\registerparsymbol\fi}
+
+\def\traceposstring#1#2#3%
+ {\iftracepositions\smashedhbox{#1{\infofont#2#3}}\fi}
+
+\def\registerparsymbol
+ {\iftracepositions
+ \smashedhbox to \zeropoint
+ {\hss
+ \startcolor[blue]%
+ \llap{\infofont\number\parposcounter}%
+ \scratchdimen\onepoint
+ \vrule
+ \!!width 4\scratchdimen
+ \!!height2\scratchdimen
+ \!!depth 2\scratchdimen
+ \stopcolor
+ \hss}%
+ \fi}
+
+% \appendtoks \registerparoptions \to \everypar
+
+%D Eperimental code, don't use this yet: (must be sped up anyway)
+
+\def\@@noden{node:n:}
+\def\@@nodeo{node:o:}
+\def\@@nodep{node:p:}
+
+\def\doifelsenodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\nextnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname\pluscounter{\@@noden#1}\fi}
-\def\copyposition#1#2%
- {\ifcsname\POSprefix#2\endcsname
- \global\@EA\let\csname\POSprefix#1\@EA\endcsname\csname\POSprefix#2\endcsname
+\def\newnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \setcounter{\@@noden#1}\zerocount
+ \letgvalue {\@@nodeo#1}\!!zerocount
\fi}
+\def\tagnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname\xypos{\@@nodep#1:\countervalue{\@@noden#1}}\fi}
+
+\def\getnodelocationp#1{\MPp{\@@nodep#1:\countervalue{\@@noden#1}}}
+\def\getnodelocationx#1{\MPx{\@@nodep#1:\countervalue{\@@noden#1}}}
+\def\getnodelocationy#1{\MPy{\@@nodep#1:\countervalue{\@@noden#1}}}
+
+\def\numnodelocationp#1#2{\MPp{\@@nodep#1:\number#2}}
+\def\numnodelocationx#1#2{\MPx{\@@nodep#1:\number#2}}
+\def\numnodelocationy#1#2{\MPy{\@@nodep#1:\number#2}}
+
+\def\getnodelocationn#1{\countervalue{\@@noden#1}}
+\def\getnodelocationo#1{\getvalue {\@@nodeo#1}}
+
+\chardef\nodelocationmode\plusone
+
+\def\analyzenodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \doanalyzenodelocation{#1}{\getnodelocationn{#1}}\zerocount
+ \fi}
+
+\def\doanalyzenodelocation#1#2#3% class n default
+ {\begingroup
+ \donefalse
+ \ifcase\nodelocationmode
+ % do nothing
+ \else
+ \edef\nodelocationselfn{#2}%
+ \edef\nodelocationselfp{\numnodelocationp{#1}\nodelocationselfn}%
+ \edef\nodelocationselfx{\numnodelocationx{#1}\nodelocationselfn}%
+ \edef\nodelocationselfy{\numnodelocationy{#1}\nodelocationselfn}%
+ \scratchcounter\plusone
+ \doloop
+ {\ifnum\recurselevel=\nodelocationselfn\relax
+ \donetrue
+ \else
+ \edef\nodelocationotherp{\numnodelocationp{#1}\recurselevel}%
+ \edef\nodelocationotherx{\numnodelocationx{#1}\recurselevel}%
+ \edef\nodelocationothery{\numnodelocationy{#1}\recurselevel}%
+ \ifcase\nodelocationmode
+ \or
+ % ok for single column
+ \ifcase\nodelocationotherp\relax
+ \exitloop
+ \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
+ % skip
+ \else\ifdim\nodelocationothery>\nodelocationselfy\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifdim\nodelocationothery<\nodelocationselfy\relax
+ % skip
+ \else\ifdim\nodelocationotherx<\nodelocationselfx\relax
+ \donetrue \advance\scratchcounter\plusone
+ \fi\fi\fi\fi\fi\fi
+ \or
+ % acceptable for double column
+ \ifcase\nodelocationotherp\relax
+ \exitloop
+ \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
+ % skip
+ \else\ifnum\recurselevel>\nodelocationselfn\relax
+ \donetrue \exitloop
+ \else
+ \donetrue \advance\scratchcounter\plusone
+ \fi\fi\fi\fi
+ \else
+ \exitloop
+ \fi
+ \fi}%
+ \fi
+ \ifdone \else
+ \scratchcounter#3\relax
+ \fi
+ \setxvalue{\@@nodeo#1}{\the\scratchcounter}%
+ \endgroup}
+
+\unexpanded\def\shownodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \analyzenodelocation{#1}%
+ (#1,%
+ n:\getnodelocationn{#1},%
+ p:\getnodelocationp{#1},%
+ x:\getnodelocationx{#1},%
+ y:\getnodelocationy{#1},%
+ o:\getnodelocationo{#1})%
+ \fi}
+
+%D \macros
+%D {doifoverlappingelse}
+%D
+%D A first application of positional information, is to
+%D determine if two boxes do overlap:
+%D
+%D \starttyping
+%D \doifoverlappingelse{point a}{point b}
+%D {action when overlapping}
+%D {action when not overlapping}
+%D \stoptyping
+
+\def\overlappingmargin{-2\scaledpoint}
+
+\def\doifoverlappingelse#1#2%
+ {\begingroup
+ \donefalse
+ \edef\!!stringa{#1}\edef\!!stringb{#2}%
+ \ifnum\MPp\!!stringa=\MPp\!!stringb\relax
+ \!!dimena\MPx\!!stringa
+ \!!dimenb\dimexpr\MPx\!!stringa+\MPw\!!stringa\relax
+ \!!dimenc\dimexpr\MPy\!!stringa-\MPd\!!stringa\relax
+ \!!dimend\dimexpr\MPy\!!stringa+\MPh\!!stringa\relax
+ \!!dimene\MPx\!!stringb
+ \!!dimenf\dimexpr\MPx\!!stringb+\MPw\!!stringb\relax
+ \!!dimeng\dimexpr\MPy\!!stringb-\MPd\!!stringb\relax
+ \!!dimenh\dimexpr\MPy\!!stringb+\MPh\!!stringb\relax
+ \ifdim\overlappingmargin=\zeropoint\else
+ \advance\!!dimena-\overlappingmargin
+ \advance\!!dimenb+\overlappingmargin
+ \advance\!!dimenc-\overlappingmargin
+ \advance\!!dimend+\overlappingmargin
+ \advance\!!dimene-\overlappingmargin
+ \advance\!!dimenf+\overlappingmargin
+ \advance\!!dimeng-\overlappingmargin
+ \advance\!!dimenh+\overlappingmargin
+ \fi
+ % more often eh fb eg fg
+ \def\checkone##1##2%
+ {\ifdim##1<\!!dimena \else \ifdim##1>\!!dimenb \else
+ \ifdim##2<\!!dimenc \else \ifdim##2>\!!dimend \else
+ \donetrue
+ \fi\fi
+ \fi\fi}%
+ \def\checktwo##1##2%
+ {\ifdim##1<\!!dimene \else \ifdim##1>\!!dimenf \else
+ \ifdim##2<\!!dimeng \else \ifdim##2>\!!dimenh \else
+ \donetrue
+ \fi\fi
+ \fi\fi}%
+ \checkone\!!dimene\!!dimeng \ifdone \else
+ \checkone\!!dimene\!!dimenh \ifdone \else
+ \checkone\!!dimenf\!!dimeng \ifdone \else
+ \checkone\!!dimenf\!!dimenh \ifdone \else
+ \checktwo\!!dimena\!!dimenc \ifdone \else
+ \checktwo\!!dimena\!!dimend \ifdone \else
+ \checktwo\!!dimenb\!!dimene \ifdone \else
+ \checktwo\!!dimenb\!!dimenc \fi \fi \fi \fi \fi \fi \fi
+ \fi
+ \ifdone
+ \endgroup\expandafter\firstoftwoarguments
+ \else
+ \endgroup\expandafter\secondoftwoarguments
+ \fi}
+
+%D \macros
+%D {doifpositionsonsamepageelse,
+%D doifpositionsonthispageelse}
+%D
+%D Instead of letting the user handle fuzzy expansion, we
+%D provide a simple test on positione being on the same page.
+%D
+%D \starttyping
+%D \doifpositionsonsamepageelse{point a}{point b}
+%D {action when on same page}
+%D {action when not on same page}
+%D \doifpositionsonthispageelse{point a}{point b}
+%D {action when on this page}
+%D {action when not on this page}
+%D \stoptyping
+
+\def\dodoifpositionsonsamepageelse#1#2#3#4%
+ {\bgroup
+ \scratchcounter#1\donefalse
+ \def\docommand##1%
+ {\ifcase\scratchcounter
+ \scratchcounter\MPp{##1}\donetrue
+ \else
+ \ifnum\scratchcounter=\MPp{##1}\relax\else\donefalse\fi
+ \fi}%
+ \rawprocesscommalist[#2]\docommand
+ \ifdone\egroup#3\else\egroup#4\fi}
+
+\def\doifpositionsonsamepageelse
+ {\dodoifpositionsonsamepageelse{0}}
+
+\def\doifpositionsonthispageelse#1#2#3%
+ {\dodoifpositionsonsamepageelse\realfolio}
+
+%D Plugins:
+
+\let\MPv \MPplus
+\let\MPvv\MPrest
+
+\let\MPanchor\MPpos
+
+\let\POSp\MPp \let\POSx\MPx \let\POSy\MPy
+\let\POSh\MPh \let\POSd\MPd \let\POSw\MPw
+
\protect \endinput
diff --git a/tex/context/base/core-pos.mkiv b/tex/context/base/core-pos.mkiv
index 860a7a967..16d5b229f 100644
--- a/tex/context/base/core-pos.mkiv
+++ b/tex/context/base/core-pos.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-pos,
-%D version=2006.09.18,
+%D version=1999.08.01,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Positioning Support,
%D author=Hans Hagen,
@@ -11,7 +11,22 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
+% needs a cleanup, things may change; we also need to move the mp
+% related code to meta-pos
+
+% shorter tags, ..:achtergrond:.. etc in pos actions
+
+% dubbele text- * pos's eruit
+
+% class pos -> als gelijk aan vorige, dan niet niet definieren
+% en erven, maw:
+%
+% 1 -> opslaan
+% 2 -> undef, dus == prev
+% 3 -> undef, dus == prev
+% 4 -> opslaan
+
+\writestatus{loading}{ConTeXt Core Macros / Positioning Support}
% saveposition : tag page x y
% savepositionwhd : tag page x y w h d
@@ -27,12 +42,71 @@
\registerctxluafile{core-pos}{1.001}
-% \def\dolazysaveposition #1#2#3#4{\expanded{\ctxlatelua{ptbs['#1']={#2,"#3","#4"}}}}
-% \def\dolazysavepositionwhd #1#2#3#4#5#6#7{\expanded{\ctxlatelua{ptbs['#1']={#2,"#3","#4","#5","#6","#7"}}}}
-% \def\dolazysavepositionplus#1#2#3#4#5#6#7#8{\expanded{\ctxlatelua{ptbs['#1']={#2,"#3","#4","#5","#6","#7","#8"}}}}
-% \def\dosaveposition #1#2#3#4{\expanded{\ctxlua {ptbs['#1']={#2,"#3","#4"}}}}
-% \def\dosavepositionwhd #1#2#3#4#5#6#7{\expanded{\ctxlua {ptbs['#1']={#2,"#3","#4","#5","#6","#7"}}}}
-% \def\dosavepositionplus #1#2#3#4#5#6#7#8{\expanded{\ctxlua {ptbs['#1']={#2,"#3","#4","#5","#6","#7","#8"}}}}
+% todo: topskip als optie voor eerste regel achtergrond
+% todo: build pos layers on top of layers
+% todo: positionlayer pos van text-1 etc delen
+
+%D Although \TEX\ has a rather powerful channel to the outside
+%D world, called \type {\special}, real communication with
+%D other programs is complicated by the fact that no positional
+%D information is available. Mid 1999, I discussed this with
+%D \THANH, the author of \PDFTEX, and after some experiments,
+%D \PDFTEX\ was extended with a simple but effective mechanism,
+%D that provided positional information. The interesting
+%D thought is that, although \TEX\ is frozen, similar
+%D functionality could have been achieved with \type
+%D {\specials} and an additional \DVI\ postprocessor.
+%D
+%D Since we want to be as compatible as can be, \CONTEXT\ will
+%D support both methods, although the development is primarily
+%D driven by the \PDFTEX\ way of doing things. Since the
+%D mechanism is basically not limited to one application, for
+%D the moment we stick to building the functionality around one
+%D \CONTEXT\ special command, but at the same time we keep our
+%D eyes open for extensions in other directions.
+%D
+%D A question that may arise when one reads this module, is to
+%D what extend these macros are generic, in the sense that they
+%D could be collected in a support module instead of a core
+%D module. Since the mechanism described here will closely
+%D cooperate with the \METAPOST\ support built in \CONTEXT,
+%D which in turn will be tightly integrated with the \CONTEXT\
+%D overlay mechanisms, I decided to write a core module instead
+%D of a support one. This makes even more sense, when one takes
+%D into account that this kind of support depends on special
+%D drivers.
+
+\unprotect
+
+%D The first application of positional information was embedded
+%D graphics. Since we are interacting with text, it made sense
+%D to take the current line height and depth into account too.
+%D This is why we have two basic position macros: one for
+%D simple positions, and one for boxes.
+%D
+%D We could have sticked to one special, and actually did so in
+%D earlier experiments, but for convenience, as well for
+%D clearness, we now have two alternatives. This approach will
+%D save us quite some bytes when storing large quantities of
+%D positional information. We save as less information as
+%D needed, that is, we save no dimensions, in a \METAPOST\
+%D friendly way.
+%D
+%D The three specials involved are:
+%D
+%D \starttyping
+%D \dosetposition {identifier}
+%D \dosetpositionwhd {identifier} {width} {height} {depth}
+%D \dosetpositionplus {identifier} {width} {height} {depth} {list}
+%D \dosetpositionpapersize {width} {height}
+%D \stoptyping
+%D
+%D Positions are either generated at a delayed write time
+%D (in \PDFTEX), or derived from the dvi file. The actual
+%D method is implemented in a special driver. If needed, the
+%D driver can fall back on the following macros.
+
+% TO BE MERGED
\def\dolazysaveposition #1#2#3#4{\normalexpanded{\ctxlatelua{ptbs['#1']={#2,"#3","#4"}}}}
\def\dolazysavepositionwhd #1#2#3#4#5#6#7{\normalexpanded{\ctxlatelua{ptbs['#1']={#2,"#3","#4","#5","#6","#7"}}}}
@@ -41,10 +115,131 @@
\def\dosavepositionwhd #1#2#3#4#5#6#7{\normalexpanded{\ctxlua {ptbs['#1']={#2,"#3","#4","#5","#6","#7"}}}}
\def\dosavepositionplus #1#2#3#4#5#6#7#8{\normalexpanded{\ctxlua {ptbs['#1']={#2,"#3","#4","#5","#6","#7","#8"}}}}
-\def\doifpositionelse #1{\ctxlua{jobpositions.doifelse('#1')}}
-\def\copyposition #1#2{\ctxlua{jobpositions.copy('#1','#2')}}
+% \def\dosetposition#1%
+% {\pdfsavepos
+% \dolazysaveposition
+% {#1}%
+% {\noexpand\realfolio}%
+% {\noexpand\the\dimexpr\pdflastxpos\scaledpoint\relax}%
+% {\noexpand\the\dimexpr\pdflastypos\scaledpoint\relax}}%
+%
+% \def\dosetpositionwhd#1#2#3#4%
+% {\pdfsavepos
+% \dolazysavepositionwhd
+% {#1}%
+% {\noexpand\realfolio}%
+% {\noexpand\the\dimexpr\pdflastxpos\scaledpoint\relax}%
+% {\noexpand\the\dimexpr\pdflastypos\scaledpoint\relax}%
+% {#2}{#3}{#4}}
+%
+% \def\dosetpositionplus#1#2#3#4#5%
+% {\pdfsavepos
+% \dolazysavepositionplus
+% {#1}%
+% {\noexpand\realfolio}%
+% {\noexpand\the\dimexpr\pdflastxpos\scaledpoint\relax}%
+% {\noexpand\the\dimexpr\pdflastypos\scaledpoint\relax}%
+% {#2}{#3}{#4}{#5}}
+
+\def\lastsavedpositionx {\the\dimexpr\pdflastxpos\scaledpoint\relax}
+\def\lastsavedpositiony {\the\dimexpr\pdflastypos\scaledpoint\relax}
+\let\savecurrentposition\pdfsavepos
+
+\def\dosetposition#1%
+ {\savecurrentposition
+ \normalexpanded{\ctxlatelua{ptbs['#1']={%
+ \noexpand\realfolio,"\noexpand\lastsavedpositionx","\noexpand\lastsavedpositiony"}}}}
+
+\def\dosetpositionwhd#1#2#3#4%
+ {\savecurrentposition
+ \normalexpanded{\ctxlatelua{ptbs['#1']={%
+ \noexpand\realfolio,"\noexpand\lastsavedpositionx","\noexpand\lastsavedpositiony","#2","#3","#4"}}}}
+
+\def\dosetpositionplus#1#2#3#4#5%
+ {\savecurrentposition
+ \normalexpanded{\ctxlatelua{ptbs['#1']={%
+ \noexpand\realfolio,"\noexpand\lastsavedpositionx","\noexpand\lastsavedpositiony","#2","#3","#4","#5"}}}}
+
+\let\dosetpositionpapersize\gobbletwoarguments
+
+\newbox\positionbox
+\newif \ifpositioning
+
+\def\POSprefix{POS::}
+
+\let\setpospx \gobblefourarguments % suppress errors with mkii tuo file
+\let\setpospxywhd \gobblesevenarguments % suppress errors with mkii tuo file
+\let\setpospxyplus\gobbleeightarguments % suppress errors with mkii tuo file
+
+%D This is real tricky! The page anchor is applied to the
+%D page box and therefore flushed first. So, when present, it
+%D is applied to all positions except itself.
+
+\chardef\positionanchormode=0 % don't relocate page origin
+\chardef\positionanchormode=1 % relocate page origin once
+
+%D The core set macros.
+
+\let\pospxy \gobblefourarguments
+\let\pospxywhd \gobblesevenarguments
+\let\pospxyplus\gobbleeightarguments
+
+%D Sometimes we want to trick the position handler a bit:
+
\def\replacepospxywhd#1#2#3#4#5#6#7{\ctxlua{jobpositions.replace('#1',\number#2,"\the\dimexpr#3\relax","\the\dimexpr#4\relax","\the\dimexpr#5\relax","\the\dimexpr#6\relax","\the\dimexpr#7\relax")}}
+%D For postprocessing purposes, we save the number of
+%D positions.
+
+\newcount\currentpositions % current number of positions
+\newcounter\totalnofpositions % total from previous run
+
+\appendtoks
+ \expanded{\savecurrentvalue\noexpand\totalnofpositions{\the\currentpositions}}%
+\to \everybye
+
+%D The next switch can be used to communicate a special
+%D situation. Positioning and associated actions can be
+%D executed any time. However, in for instance backgrounds
+%D they can be collected in a layer, for instance the text
+%D layer (especially the hidden text layer). In the case of
+%D floats, we run into problems, since the page information is
+%D not applicable when the content floats indeed. In such
+%D situations one can treat positions and graphics local.
+
+\newif\iflocalpositioning
+
+%D Watch out: sometimes a pagebreak occurs inside a float
+%D placement, so there we need to disable local mode.
+
+\appendtoks
+ \localpositioningtrue
+\to \everyinsidefloat
+
+\appendtoks
+ \localpositioningfalse
+\to \everypagebody
+
+\def\checkpositions
+ {\startnointerference
+ \protectlabels
+ \doutilities{positions}\jobname\empty\relax\relax
+ \global\let\checkpositions\relax
+ \stopnointerference}
+
+%D Since the positional values are to be fully expandable, we
+%D need to preload them as soon as possible, which is why we
+%D load the data when we start a text.
+
+\appendtoks \checkpositions \to \everystarttext
+
+%D \macros
+%D {MPp, MPx, MPy, MPw, MPh, MPd,
+%D MPxy, MPll, MPlr, MPur, MPul, MPpos}
+%D
+%D Access to the positional information is provided by macros
+%D with short names that are clearly meant for \METAPOST.
+
\def\MPp #1{\ctxlua{jobpositions.MPp("#1")}}
\def\MPx #1{\ctxlua{jobpositions.MPx("#1")}}
\def\MPy #1{\ctxlua{jobpositions.MPy("#1")}}
@@ -57,7 +252,577 @@
\def\MPur #1{\ctxlua{jobpositions.MPur("#1")}}
\def\MPul #1{\ctxlua{jobpositions.MPul("#1")}}
\def\MPpos #1{\ctxlua{jobpositions.MPpos("#1")}}
-\def\MPplus#1#2#3{\ctxlua{jobpositions.MPplus("#1",#2,"#3")}}
-\def\MPrest #1#2{\ctxlua{jobpositions.MPrest("#1","#2")}}
+
+%D \macros
+%D {MPplus, MPrest, MPv, MPvv}
+%D
+%D Since we will probably keep on extending, we provide a
+%D general extension macro. The plus alternative takes an
+%D extra argument, denoting what additional parameter to pick
+%D up. So, the third extra is fetched with,
+%D
+%D \starttyping
+%D \MPplus{identifier}{3}{default}
+%D \stoptyping
+%D
+%D All extras (comma separated) are fetched with:
+%D
+%D \starttyping
+%D \MPrest{identifier}
+%D \stoptyping
+%D
+%D The extra parameters are not treated.
+
+\def\MPplus#1#2#3{\ctxlua{jobpositions.MPplus("#1",#2,"#3")}} \let\MPv \MPplus
+\def\MPrest #1#2{\ctxlua{jobpositions.MPrest("#1","#2")}} \let\MPvv\MPrest
+
+%D \macros
+%D {MPanchor}
+%D
+%D For readability we define a few synonyms:
+
+\def\MPanchor{\MPpos}
+
+%D \macros
+%D {POSp, POSx, POSy, POSh, POSd, POSw}
+%D
+%D and:
+
+\def\POSp{\MPp} \def\POSx{\MPx} \def\POSy{\MPy}
+\def\POSh{\MPh} \def\POSd{\MPd} \def\POSw{\MPw}
+
+%D There are two low level positioning macros. Both store the
+%D position as well as execute an action associated with that
+%D position.
+
+\def\initializenextposition
+ {\ifpositioning \else
+ \global\positioningtrue
+ \dosetpositionpapersize
+ {\printpaperwidth }%
+ {\printpaperheight}%
+ \fi
+ \global\advance\currentpositions\plusone}
+
+\def\setpositiononly#1%
+ {\iftrialtypesetting
+ % nothing
+ \else
+ \initializenextposition
+ \def\currentposition{#1}%
+ \dosetposition\currentposition
+ \fi}
+
+\def\setposition#1%
+ {\iftrialtypesetting
+ % nothing
+ \else
+ \initializenextposition
+ \def\currentposition{#1}%
+ \dosetposition\currentposition
+ \traceposstring\llap\green{\currentposition>}%
+ \dopositionaction\currentposition
+ \fi}
+
+\def\setpositiondata#1#2#3#4%
+ {\iftrialtypesetting \else
+ \initializenextposition
+ \hbox
+ {\def\currentposition{#1}%
+ \dosetpositionwhd\currentposition
+ {\the\dimexpr#2\relax}%
+ {\the\dimexpr#3\relax}%
+ {\the\dimexpr#4\relax}%
+ \traceposstring\llap\green{\currentposition>}%
+ \dopositionaction\currentposition
+ \hss}%
+ \fi}
+
+\def\setpositionbox#1%
+ {\dowithnextbox
+ {\iftrialtypesetting
+ \flushnextbox
+ \else
+ \initializenextposition
+ \hbox to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionwhd\currentposition
+ {\the\nextboxwd}%
+ {\the\nextboxht}%
+ {\the\nextboxdp}%
+ \traceposstring\llap\green{\currentposition>}%
+ \setbox\positionbox\flushnextbox
+ \dopositionaction\currentposition
+ \box\positionbox
+ \hss}%
+ \fi}}
+
+\def\setpositiondataplus#1#2#3#4#5%
+ {\iftrialtypesetting \else
+ \initializenextposition
+ \hbox % bug: to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition
+ {\the\dimexpr#2\relax}%
+ {\the\dimexpr#3\relax}%
+ {\the\dimexpr#4\relax}%
+ {#5}%
+ \traceposstring\rlap\magenta{<\currentposition}%
+ \dopositionaction\currentposition
+ \hss}%
+ \fi}
+
+\def\setpositionplus#1#2%
+ {\dowithnextbox
+ {\iftrialtypesetting
+ \flushnextbox
+ \else
+ \initializenextposition
+ \hbox to \nextboxwd
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition
+ {\the\nextboxwd}%
+ {\the\nextboxht}%
+ {\the\nextboxdp}%
+ {#2}%
+ \traceposstring\rlap\magenta{<\currentposition}%
+ \setbox\positionbox\flushnextbox
+ \dopositionaction\currentposition
+ \box\positionbox
+ \hss}%
+ \fi}}
+
+\let\currentposition\s!unknown
+
+%D A few more low level macros take care of defining and
+%D recalling actions. We could save this information in the
+%D position containers themselves, this would save hash
+%D entries, but at the cost of much more time consuming
+%D expansion. Actions are saved globally!
+
+\newtoks\everypositionaction
+
+\let\POSactionprefix\POSprefix
+
+\def\dosetpositionaction#1%
+ {\setgvalue{\POSactionprefix#1::}}
+
+%D The lists can become quite long (also because there can
+%D be lots of parameters passed on) so we provide a hook
+%D to clean up the list afterwards.
+
+\let\cleanuppositionaction\gobbleoneargument
+
+\def\doifpositionaction#1%
+ {\ifcsname\POSactionprefix#1::\endcsname
+ \@EA\firstofoneargument
+ \else
+ \@EA\gobbleoneargument
+ \fi}
+
+\def\doifpositionactionelse#1%
+ {\ifcsname\POSactionprefix#1::\endcsname
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+%D We can copy a position with:
+%D
+%D \starttyping
+%D \copyposition {to} {from}
+%D \stoptyping
+%D
+%D Again, this is a global action.
+
+\def\copyposition#1#2{\ctxlua{jobpositions.copy('#1','#2')}}
+
+%D The fact that handling positions is a two pass operation, is
+%D one of the reasons why we need to be able to test for
+%D existence, using:
+%D
+%D \starttyping
+%D \doifpositionelse {identifier} {found action} {not found action}
+%D \stoptyping
+
+\def\doifpositionelse#1{\ctxlua{jobpositions.doifelse('#1')}}
+
+%D We have now arrived at a few macros that would make sense as
+%D support macros, but ended up in the core.
+
+%D \macros
+%D {xypos}
+%D
+%D We have several macros available to save positions. Later
+%D we will see applications.
+%D
+%D \starttabulate[|l|l||]
+%D \NC \type {\xypos} \NC \NC simple position with no dimensions \NC \NR
+%D \NC \type {\hpos} \NC \NC position and characteristics of a \type {\hbox} \NC \NR
+%D \NC \type {\vpos} \NC \NC position and characteristics of a \type {\vbox} \NC \NR
+%D \NC \type {\bpos} \NC b: \NC begin point in a line \NC \NR
+%D \NC \type {\epos} \NC e: \NC end point in a line \NC \NR
+%D \NC \type {\fpos} \NC f: \NC begin point in a paragraph \NC \NR
+%D \NC \type {\tpos} \NC t: \NC end point in a paragraph \NC \NR
+%D \stoptabulate
+%D
+%D Each macro takes an identifier as argument, and the \type
+%D {\hpos} and \type {\vpos} also expect box content.
+
+% \def\xypos{\initializenextposition\dosetposition}
+
+\let\xypos\setpositiononly
+
+\def\hpos#1{\dontleavehmode\setpositionbox{#1}\hbox}
+\def\vpos#1{\setpositionbox{#1}\vbox}
+
+\def\bpos#1{\hpos{b:#1}{\strut}\ignorespaces}
+\def\epos#1{\removelastspace\hpos{e:#1}{\strut}}
+
+\def\fpos#1%
+ {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut
+ \ignorespaces}
+
+\def\tpos#1%
+ {\removelastspace
+ \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
+
+\def\ffpos#1%
+ {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut\wpos{#1}%
+ \ignorespaces}
+
+\def\ttpos#1%
+ {\removelastspace
+ \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
+
+\def\wpos#1%
+ {\dontleavehmode\vadjust % may disappear if buried
+ {\setbox0\hbox{\raise\strutdp\hbox{\rawwpos{#1}}}%
+ \rlap{\smashedbox0}}}
+
+\def\wwpos#1% \hsmashed{\llap{\rawwpos{#1}}}
+ {\rlap
+ {\setbox0\hbox{\rawwpos{#1}}%
+ \smashedbox0}}
+
+\def\rawwpos#1%
+ {\hpos{w:#1}
+ {\strut
+ \hskip-\leftskip
+ \hskip\hsize
+ \hskip-\rightskip}}
+
+% the next macro disables par positions (in inner boxes) and
+% only registers the width
+
+\def\setinnerparpositions
+ {\let\fpos\ffpos
+ \let\tpos\ttpos
+ \let\wpos\wwpos}
+
+% example of usage: (see for application "techniek")
+%
+% \appendtoks
+% \setinnerparpositions
+% \to \everytabulate
+
+%D When we want to calculate more complex backgrounds, we
+%D need to know what the current indentation scheme is. At
+%D the cost of many positions and memory, we can keep track
+%D of them. This mechanism is activated automatically
+%D based on information collected in the previous pass.
+
+\newcount\parposcounter
+
+\newif\ifpositioningpar
+
+% we can check for used entries, and if not, then not add one
+
+\def\registerparoptions
+ {\ifpositioningpar \ifpositioning \iftrialtypesetting \else
+ \ifinpagebody \else \ifmmode \else \ifinformula \else
+ \ifprocessingverbatim
+ \iflinepar \doregisterparoptions \fi
+ \else
+ \doregisterparoptions
+ \fi
+ \fi \fi \fi
+ \fi \fi \fi}
+
+\chardef\parposstrut=1 % 0 => no strut data, so fall backs used
+
+\newif\iftracepositions
+
+% \def\doregisterparoptions
+% {\global\advance\parposcounter\plusone
+% \begingroup
+% \leftskip 1\leftskip
+% \rightskip1\rightskip
+% \setpositiondataplus
+% {p:\number\parposcounter}% identifier
+% {\the\zeropoint}%
+% {\the\strutht}%
+% {\the\strutdp}%
+% {\the\hsize ,% 1
+% \the\leftskip ,% 2
+% \the\rightskip ,% 3
+% \the\hangindent,% 4
+% \the\hangafter ,% 5 (num)
+% \the\parindent }% 6
+% %\normalhbox{\registerparsymbol}%
+% \registerparsymbol
+% \endgroup}
+
+\def\doregisterparoptions
+ {\global\advance\parposcounter\plusone
+ \setpositiondataplus
+ {p:\number\parposcounter}% identifier
+ {\the\zeropoint}%
+ {\the\strutht}%
+ {\the\strutdp}%
+ {\the\hsize,\the\dimexpr\leftskip\relax,\the\dimexpr\rightskip\relax,\the\hangindent,\the\hangafter,\the\parindent}%
+ %\normalhbox{\registerparsymbol}%
+ \iftracepositions\registerparsymbol\fi}
+
+\def\traceposstring#1#2#3%
+ {\iftracepositions\smashedhbox{#1{\infofont#2#3}}\fi}
+
+\def\registerparsymbol
+ {\iftracepositions
+ \smashedhbox to \zeropoint
+ {\hss
+ \startcolor[blue]%
+ \llap{\infofont\number\parposcounter}%
+ \scratchdimen\onepoint
+ \vrule
+ \!!width 4\scratchdimen
+ \!!height2\scratchdimen
+ \!!depth 2\scratchdimen
+ \stopcolor
+ \hss}%
+ \fi}
+
+% \appendtoks \registerparoptions \to \everypar
+
+%D Eperimental code, don't use this yet: (must be sped up anyway)
+
+\def\@@noden{node:n:}
+\def\@@nodeo{node:o:}
+\def\@@nodep{node:p:}
+
+\def\doifelsenodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\nextnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname\pluscounter{\@@noden#1}\fi}
+
+\def\newnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \setcounter{\@@noden#1}\zerocount
+ \letgvalue {\@@nodeo#1}\!!zerocount
+ \fi}
+
+\def\tagnodelocation#1%
+ {\ifcsname\@@noden#1\endcsname\xypos{\@@nodep#1:\countervalue{\@@noden#1}}\fi}
+
+\def\getnodelocationp#1{\MPp{\@@nodep#1:\countervalue{\@@noden#1}}}
+\def\getnodelocationx#1{\MPx{\@@nodep#1:\countervalue{\@@noden#1}}}
+\def\getnodelocationy#1{\MPy{\@@nodep#1:\countervalue{\@@noden#1}}}
+
+\def\numnodelocationp#1#2{\MPp{\@@nodep#1:\number#2}}
+\def\numnodelocationx#1#2{\MPx{\@@nodep#1:\number#2}}
+\def\numnodelocationy#1#2{\MPy{\@@nodep#1:\number#2}}
+
+\def\getnodelocationn#1{\countervalue{\@@noden#1}}
+\def\getnodelocationo#1{\getvalue {\@@nodeo#1}}
+
+\chardef\nodelocationmode\plusone
+
+\def\analyzenodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \doanalyzenodelocation{#1}{\getnodelocationn{#1}}\zerocount
+ \fi}
+
+\def\doanalyzenodelocation#1#2#3% class n default
+ {\begingroup
+ \donefalse
+ \ifcase\nodelocationmode
+ % do nothing
+ \else
+ \edef\nodelocationselfn{#2}%
+ \edef\nodelocationselfp{\numnodelocationp{#1}\nodelocationselfn}%
+ \edef\nodelocationselfx{\numnodelocationx{#1}\nodelocationselfn}%
+ \edef\nodelocationselfy{\numnodelocationy{#1}\nodelocationselfn}%
+ \scratchcounter\plusone
+ \doloop
+ {\ifnum\recurselevel=\nodelocationselfn\relax
+ \donetrue
+ \else
+ \edef\nodelocationotherp{\numnodelocationp{#1}\recurselevel}%
+ \edef\nodelocationotherx{\numnodelocationx{#1}\recurselevel}%
+ \edef\nodelocationothery{\numnodelocationy{#1}\recurselevel}%
+ \ifcase\nodelocationmode
+ \or
+ % ok for single column
+ \ifcase\nodelocationotherp\relax
+ \exitloop
+ \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
+ % skip
+ \else\ifdim\nodelocationothery>\nodelocationselfy\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifdim\nodelocationothery<\nodelocationselfy\relax
+ % skip
+ \else\ifdim\nodelocationotherx<\nodelocationselfx\relax
+ \donetrue \advance\scratchcounter\plusone
+ \fi\fi\fi\fi\fi\fi
+ \or
+ % acceptable for double column
+ \ifcase\nodelocationotherp\relax
+ \exitloop
+ \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
+ \donetrue \advance\scratchcounter\plusone
+ \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
+ % skip
+ \else\ifnum\recurselevel>\nodelocationselfn\relax
+ \donetrue \exitloop
+ \else
+ \donetrue \advance\scratchcounter\plusone
+ \fi\fi\fi\fi
+ \else
+ \exitloop
+ \fi
+ \fi}%
+ \fi
+ \ifdone \else
+ \scratchcounter#3\relax
+ \fi
+ \setxvalue{\@@nodeo#1}{\the\scratchcounter}%
+ \endgroup}
+
+\unexpanded\def\shownodelocation#1%
+ {\ifcsname\@@noden#1\endcsname
+ \analyzenodelocation{#1}%
+ (#1,%
+ n:\getnodelocationn{#1},%
+ p:\getnodelocationp{#1},%
+ x:\getnodelocationx{#1},%
+ y:\getnodelocationy{#1},%
+ o:\getnodelocationo{#1})%
+ \fi}
+
+%D \macros
+%D {doifoverlappingelse}
+%D
+%D A first application of positional information, is to
+%D determine if two boxes do overlap:
+%D
+%D \starttyping
+%D \doifoverlappingelse{point a}{point b}
+%D {action when overlapping}
+%D {action when not overlapping}
+%D \stoptyping
+
+\def\overlappingmargin{-2\scaledpoint}
+
+\def\doifoverlappingelse#1#2%
+ {\begingroup
+ \donefalse
+ \edef\!!stringa{#1}\edef\!!stringb{#2}%
+ \ifnum\MPp\!!stringa=\MPp\!!stringb\relax
+ \!!dimena\MPx\!!stringa
+ \!!dimenb\dimexpr\MPx\!!stringa+\MPw\!!stringa\relax
+ \!!dimenc\dimexpr\MPy\!!stringa-\MPd\!!stringa\relax
+ \!!dimend\dimexpr\MPy\!!stringa+\MPh\!!stringa\relax
+ \!!dimene\MPx\!!stringb
+ \!!dimenf\dimexpr\MPx\!!stringb+\MPw\!!stringb\relax
+ \!!dimeng\dimexpr\MPy\!!stringb-\MPd\!!stringb\relax
+ \!!dimenh\dimexpr\MPy\!!stringb+\MPh\!!stringb\relax
+ \ifdim\overlappingmargin=\zeropoint\else
+ \advance\!!dimena-\overlappingmargin
+ \advance\!!dimenb+\overlappingmargin
+ \advance\!!dimenc-\overlappingmargin
+ \advance\!!dimend+\overlappingmargin
+ \advance\!!dimene-\overlappingmargin
+ \advance\!!dimenf+\overlappingmargin
+ \advance\!!dimeng-\overlappingmargin
+ \advance\!!dimenh+\overlappingmargin
+ \fi
+ % more often eh fb eg fg
+ \def\checkone##1##2%
+ {\ifdim##1<\!!dimena \else \ifdim##1>\!!dimenb \else
+ \ifdim##2<\!!dimenc \else \ifdim##2>\!!dimend \else
+ \donetrue
+ \fi\fi
+ \fi\fi}%
+ \def\checktwo##1##2%
+ {\ifdim##1<\!!dimene \else \ifdim##1>\!!dimenf \else
+ \ifdim##2<\!!dimeng \else \ifdim##2>\!!dimenh \else
+ \donetrue
+ \fi\fi
+ \fi\fi}%
+ \checkone\!!dimene\!!dimeng \ifdone \else
+ \checkone\!!dimene\!!dimenh \ifdone \else
+ \checkone\!!dimenf\!!dimeng \ifdone \else
+ \checkone\!!dimenf\!!dimenh \ifdone \else
+ \checktwo\!!dimena\!!dimenc \ifdone \else
+ \checktwo\!!dimena\!!dimend \ifdone \else
+ \checktwo\!!dimenb\!!dimene \ifdone \else
+ \checktwo\!!dimenb\!!dimenc \fi \fi \fi \fi \fi \fi \fi
+ \fi
+ \ifdone
+ \endgroup\expandafter\firstoftwoarguments
+ \else
+ \endgroup\expandafter\secondoftwoarguments
+ \fi}
+
+%D \macros
+%D {doifpositionsonsamepageelse,
+%D doifpositionsonthispageelse}
+%D
+%D Instead of letting the user handle fuzzy expansion, we
+%D provide a simple test on positione being on the same page.
+%D
+%D \starttyping
+%D \doifpositionsonsamepageelse{point a}{point b}
+%D {action when on same page}
+%D {action when not on same page}
+%D \doifpositionsonthispageelse{point a}{point b}
+%D {action when on this page}
+%D {action when not on this page}
+%D \stoptyping
+
+\def\dodoifpositionsonsamepageelse#1#2#3#4%
+ {\bgroup
+ \scratchcounter#1\donefalse
+ \def\docommand##1%
+ {\ifcase\scratchcounter
+ \scratchcounter\MPp{##1}\donetrue
+ \else
+ \ifnum\scratchcounter=\MPp{##1}\relax\else\donefalse\fi
+ \fi}%
+ \rawprocesscommalist[#2]\docommand
+ \ifdone\egroup#3\else\egroup#4\fi}
+
+\def\doifpositionsonsamepageelse
+ {\dodoifpositionsonsamepageelse{0}}
+
+\def\doifpositionsonthispageelse#1#2#3%
+ {\dodoifpositionsonsamepageelse\realfolio}
+
+%D Plugins:
+
+\let\MPv \MPplus
+\let\MPvv\MPrest
+
+\let\MPanchor\MPpos
+
+\let\POSp\MPp \let\POSx\MPx \let\POSy\MPy
+\let\POSh\MPh \let\POSd\MPd \let\POSw\MPw
\protect \endinput
diff --git a/tex/context/base/core-pos.tex b/tex/context/base/core-pos.tex
deleted file mode 100644
index 06bf55cae..000000000
--- a/tex/context/base/core-pos.tex
+++ /dev/null
@@ -1,767 +0,0 @@
-%D \module
-%D [ file=core-pos,
-%D version=1999.08.01,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Positioning Support,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% needs a cleanup, things may change; we also need to move the mp
-% related code to meta-pos
-
-% shorter tags, ..:achtergrond:.. etc in pos actions
-
-% dubbele text- * pos's eruit
-
-% class pos -> als gelijk aan vorige, dan niet niet definieren
-% en erven, maw:
-%
-% 1 -> opslaan
-% 2 -> undef, dus == prev
-% 3 -> undef, dus == prev
-% 4 -> opslaan
-
-\writestatus{loading}{Context Positioning Support}
-
-% todo: topskip als optie voor eerste regel achtergrond
-% todo: build pos layers on top of layers
-% todo: positionlayer pos van text-1 etc delen
-
-%D Although \TEX\ has a rather powerful channel to the outside
-%D world, called \type {\special}, real communication with
-%D other programs is complicated by the fact that no positional
-%D information is available. Mid 1999, I discussed this with
-%D \THANH, the author of \PDFTEX, and after some experiments,
-%D \PDFTEX\ was extended with a simple but effective mechanism,
-%D that provided positional information. The interesting
-%D thought is that, although \TEX\ is frozen, similar
-%D functionality could have been achieved with \type
-%D {\specials} and an additional \DVI\ postprocessor.
-%D
-%D Since we want to be as compatible as can be, \CONTEXT\ will
-%D support both methods, although the development is primarily
-%D driven by the \PDFTEX\ way of doing things. Since the
-%D mechanism is basically not limited to one application, for
-%D the moment we stick to building the functionality around one
-%D \CONTEXT\ special command, but at the same time we keep our
-%D eyes open for extensions in other directions.
-%D
-%D A question that may arise when one reads this module, is to
-%D what extend these macros are generic, in the sense that they
-%D could be collected in a support module instead of a core
-%D module. Since the mechanism described here will closely
-%D cooperate with the \METAPOST\ support built in \CONTEXT,
-%D which in turn will be tightly integrated with the \CONTEXT\
-%D overlay mechanisms, I decided to write a core module instead
-%D of a support one. This makes even more sense, when one takes
-%D into account that this kind of support depends on special
-%D drivers.
-
-\unprotect
-
-%D The first application of positional information was embedded
-%D graphics. Since we are interacting with text, it made sense
-%D to take the current line height and depth into account too.
-%D This is why we have two basic position macros: one for
-%D simple positions, and one for boxes.
-%D
-%D We could have sticked to one special, and actually did so in
-%D earlier experiments, but for convenience, as well for
-%D clearness, we now have two alternatives. This approach will
-%D save us quite some bytes when storing large quantities of
-%D positional information. We save as less information as
-%D needed, that is, we save no dimensions, in a \METAPOST\
-%D friendly way.
-%D
-%D The three specials involved are:
-%D
-%D \starttyping
-%D \dosetposition {identifier}
-%D \dosetpositionwhd {identifier} {width} {height} {depth}
-%D \dosetpositionplus {identifier} {width} {height} {depth} {list}
-%D \dosetpositionpapersize {width} {height}
-%D \stoptyping
-
-\newbox\positionbox
-\newif \ifpositioning
-
-\def\POSprefix{POS::}
-
-\let\setpospx \gobblefourarguments % suppress errors with mkii tuo file
-\let\setpospxywhd \gobblesevenarguments % suppress errors with mkii tuo file
-\let\setpospxyplus\gobbleeightarguments % suppress errors with mkii tuo file
-
-%D This is real tricky! The page anchor is applied to the
-%D page box and therefore flushed first. So, when present, it
-%D is applied to all positions except itself.
-
-\chardef\positionanchormode=0 % don't relocate page origin
-\chardef\positionanchormode=1 % relocate page origin once
-
-%D The core set macros.
-
-\let\pospxy \gobblefourarguments
-\let\pospxywhd \gobblesevenarguments
-\let\pospxyplus\gobbleeightarguments
-
-%D Sometimes we want to trick the position handler a bit:
-
-\let\replacepospxywhd\gobbleeightarguments
-
-%D For postprocessing purposes, we save the number of
-%D positions.
-
-\newcount\currentpositions % current number of positions
-\newcounter\totalnofpositions % total from previous run
-
-\appendtoks
- \expanded{\savecurrentvalue\noexpand\totalnofpositions{\the\currentpositions}}%
-\to \everybye
-
-%D The next switch can be used to communicate a special
-%D situation. Positioning and associated actions can be
-%D executed any time. However, in for instance backgrounds
-%D they can be collected in a layer, for instance the text
-%D layer (especially the hidden text layer). In the case of
-%D floats, we run into problems, since the page information is
-%D not applicable when the content floats indeed. In such
-%D situations one can treat positions and graphics local.
-
-\newif\iflocalpositioning
-
-%D Watch out: sometimes a pagebreak occurs inside a float
-%D placement, so there we need to disable local mode.
-
-\appendtoks
- \localpositioningtrue
-\to \everyinsidefloat
-
-\appendtoks
- \localpositioningfalse
-\to \everypagebody
-
-\def\checkpositions
- {\startnointerference
- \protectlabels
- \doutilities{positions}\jobname\empty\relax\relax
- \global\let\checkpositions\relax
- \stopnointerference}
-
-%D Since the positional values are to be fully expandable, we
-%D need to preload them as soon as possible, which is why we
-%D load the data when we start a text.
-
-\appendtoks \checkpositions \to \everystarttext
-
-%D Positions are either generated at a delayed write time
-%D (in \PDFTEX), or derived from the dvi file. The actual
-%D method is implemented in a special driver. If needed, the
-%D driver can fall back on the following macros.
-
-\let\dolazysaveposition \gobblefourarguments % tag page x y
-\let\dolazysavepositionwhd \gobblesevenarguments % tag page x y w h d
-\let\dolazysavepositionplus\gobbleeightarguments % tag page x y w h d list
-\let\dosaveposition \gobblefourarguments % tag page x y
-\let\dosavepositionwhd \gobblesevenarguments % tag page x y w h d
-\let\dosavepositionplus \gobbleeightarguments % tag page x y w h d list
-
-%D \macros
-%D {MPp, MPx, MPy, MPw, MPh, MPd,
-%D MPxy, MPll, MPlr, MPur, MPul, MPpos}
-%D
-%D Access to the positional information is provided by macros
-%D with short names that are clearly meant for \METAPOST.
-
-\let\MPp \!!zerocount
-\def\MPx \!!zeropoint
-\def\MPy \!!zeropoint
-\def\MPw \!!zeropoint
-\def\MPh \!!zeropoint
-\def\MPd \!!zeropoint
-\def\MPxy \!!zeropoint
-\def\MPll \!!zeropoint
-\def\MPlr \!!zeropoint
-\def\MPur \!!zeropoint
-\def\MPul \!!zeropoint
-\def\MPpos{\!!zerocount,\!!zeropoint,\!!zeropoint,\!!zeropoint,\!!zeropoint,\!!zeropoint}
-
-%D \macros
-%D {MPplus, MPrest, MPv, MPvv}
-%D
-%D Since we will probably keep on extending, we provide a
-%D general extension macro. The plus alternative takes an
-%D extra argument, denoting what additional parameter to pick
-%D up. So, the third extra is fetched with,
-%D
-%D \starttyping
-%D \MPplus{identifier}{3}{default}
-%D \stoptyping
-%D
-%D All extras (comma separated) are fetched with:
-%D
-%D \starttyping
-%D \MPrest{identifier}
-%D \stoptyping
-%D
-%D The extra parameters are not treated.
-
-\def\MPplus#1#2{\!!zerocount} \def\MPv {\MPplus}
-\def\MPrest#1#2{#2} \def\MPvv{\MPrest}
-
-%D \macros
-%D {MPanchor}
-%D
-%D For readability we define a few synonyms:
-
-\def\MPanchor{\MPpos}
-
-%D \macros
-%D {POSp, POSx, POSy, POSh, POSd, POSw}
-%D
-%D and:
-
-\def\POSp{\MPp} \def\POSx{\MPx} \def\POSy{\MPy}
-\def\POSh{\MPh} \def\POSd{\MPd} \def\POSw{\MPw}
-
-%D There are two low level positioning macros. Both store the
-%D position as well as execute an action associated with that
-%D position.
-
-\def\initializenextposition
- {\ifpositioning \else
- \global\positioningtrue
- \dosetpositionpapersize
- {\printpaperwidth }%
- {\printpaperheight}%
- \fi
- \global\advance\currentpositions\plusone}
-
-\def\setpositiononly#1%
- {\iftrialtypesetting
- % nothing
- \else
- \initializenextposition
- \def\currentposition{#1}%
- \dosetposition\currentposition
- \fi}
-
-\def\setposition#1%
- {\iftrialtypesetting
- % nothing
- \else
- \initializenextposition
- \def\currentposition{#1}%
- \dosetposition\currentposition
- \traceposstring\llap\green{\currentposition>}%
- \dopositionaction\currentposition
- \fi}
-
-\def\setpositiondata#1#2#3#4%
- {\iftrialtypesetting \else
- \initializenextposition
- \hbox
- {\def\currentposition{#1}%
- \dosetpositionwhd\currentposition
- {\the\dimexpr#2\relax}%
- {\the\dimexpr#3\relax}%
- {\the\dimexpr#4\relax}%
- \traceposstring\llap\green{\currentposition>}%
- \dopositionaction\currentposition
- \hss}%
- \fi}
-
-\def\setpositionbox#1%
- {\dowithnextbox
- {\iftrialtypesetting
- \flushnextbox
- \else
- \initializenextposition
- \hbox to \nextboxwd
- {\edef\currentposition{#1}%
- \dosetpositionwhd\currentposition
- {\the\nextboxwd}%
- {\the\nextboxht}%
- {\the\nextboxdp}%
- \traceposstring\llap\green{\currentposition>}%
- \setbox\positionbox\flushnextbox
- \dopositionaction\currentposition
- \box\positionbox
- \hss}%
- \fi}}
-
-\def\setpositiondataplus#1#2#3#4#5%
- {\iftrialtypesetting \else
- \initializenextposition
- \hbox % bug: to \nextboxwd
- {\edef\currentposition{#1}%
- \dosetpositionplus\currentposition
- {\the\dimexpr#2\relax}%
- {\the\dimexpr#3\relax}%
- {\the\dimexpr#4\relax}%
- {#5}%
- \traceposstring\rlap\magenta{<\currentposition}%
- \dopositionaction\currentposition
- \hss}%
- \fi}
-
-\def\setpositionplus#1#2%
- {\dowithnextbox
- {\iftrialtypesetting
- \flushnextbox
- \else
- \initializenextposition
- \hbox to \nextboxwd
- {\edef\currentposition{#1}%
- \dosetpositionplus\currentposition
- {\the\nextboxwd}%
- {\the\nextboxht}%
- {\the\nextboxdp}%
- {#2}%
- \traceposstring\rlap\magenta{<\currentposition}%
- \setbox\positionbox\flushnextbox
- \dopositionaction\currentposition
- \box\positionbox
- \hss}%
- \fi}}
-
-\let\currentposition\s!unknown
-
-%D A few more low level macros take care of defining and
-%D recalling actions. We could save this information in the
-%D position containers themselves, this would save hash
-%D entries, but at the cost of much more time consuming
-%D expansion. Actions are saved globally!
-
-\newtoks\everypositionaction
-
-\let\POSactionprefix\POSprefix
-
-\def\dosetpositionaction#1%
- {\setgvalue{\POSactionprefix#1::}}
-
-%D The lists can become quite long (also because there can
-%D be lots of parameters passed on) so we provide a hook
-%D to clean up the list afterwards.
-
-\let\cleanuppositionaction\gobbleoneargument
-
-\def\doifpositionaction#1%
- {\ifcsname\POSactionprefix#1::\endcsname
- \@EA\firstofoneargument
- \else
- \@EA\gobbleoneargument
- \fi}
-
-\def\doifpositionactionelse#1%
- {\ifcsname\POSactionprefix#1::\endcsname
- \@EA\firstoftwoarguments
- \else
- \@EA\secondoftwoarguments
- \fi}
-
-%D We can copy a position with:
-%D
-%D \starttyping
-%D \copyposition {to} {from}
-%D \stoptyping
-%D
-%D Again, this is a global action.
-
-\let\copyposition\gobbletwoarguments
-
-%D The fact that handling positions is a two pass operation, is
-%D one of the reasons why we need to be able to test for
-%D existence, using:
-%D
-%D \starttyping
-%D \doifpositionelse {identifier} {found action} {not found action}
-%D \stoptyping
-
-\let\doifpositionelse\thirdofthreearguments
-
-%D We have now arrived at a few macros that would make sense as
-%D support macros, but ended up in the core.
-
-%D \macros
-%D {xypos}
-%D
-%D We have several macros available to save positions. Later
-%D we will see applications.
-%D
-%D \starttabulate[|l|l||]
-%D \NC \type {\xypos} \NC \NC simple position with no dimensions \NC \NR
-%D \NC \type {\hpos} \NC \NC position and characteristics of a \type {\hbox} \NC \NR
-%D \NC \type {\vpos} \NC \NC position and characteristics of a \type {\vbox} \NC \NR
-%D \NC \type {\bpos} \NC b: \NC begin point in a line \NC \NR
-%D \NC \type {\epos} \NC e: \NC end point in a line \NC \NR
-%D \NC \type {\fpos} \NC f: \NC begin point in a paragraph \NC \NR
-%D \NC \type {\tpos} \NC t: \NC end point in a paragraph \NC \NR
-%D \stoptabulate
-%D
-%D Each macro takes an identifier as argument, and the \type
-%D {\hpos} and \type {\vpos} also expect box content.
-
-% \def\xypos{\initializenextposition\dosetposition}
-
-\let\xypos\setpositiononly
-
-\def\hpos#1{\dontleavehmode\setpositionbox{#1}\hbox}
-\def\vpos#1{\setpositionbox{#1}\vbox}
-
-\def\bpos#1{\hpos{b:#1}{\strut}\ignorespaces}
-\def\epos#1{\removelastspace\hpos{e:#1}{\strut}}
-
-\def\fpos#1%
- {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut
- \ignorespaces}
-
-\def\tpos#1%
- {\removelastspace
- \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
-
-\def\ffpos#1%
- {\setpositionplus{b:#1}{\number\parposcounter}\horizontalstrut\wpos{#1}%
- \ignorespaces}
-
-\def\ttpos#1%
- {\removelastspace
- \setpositionplus{e:#1}{\number\parposcounter}\horizontalstrut}
-
-\def\wpos#1%
- {\dontleavehmode\vadjust % may disappear if buried
- {\setbox0\hbox{\raise\strutdp\hbox{\rawwpos{#1}}}%
- \rlap{\smashedbox0}}}
-
-\def\wwpos#1% \hsmashed{\llap{\rawwpos{#1}}}
- {\rlap
- {\setbox0\hbox{\rawwpos{#1}}%
- \smashedbox0}}
-
-\def\rawwpos#1%
- {\hpos{w:#1}
- {\strut
- \hskip-\leftskip
- \hskip\hsize
- \hskip-\rightskip}}
-
-% the next macro disables par positions (in inner boxes) and
-% only registers the width
-
-\def\setinnerparpositions
- {\let\fpos\ffpos
- \let\tpos\ttpos
- \let\wpos\wwpos}
-
-% example of usage: (see for application "techniek")
-%
-% \appendtoks
-% \setinnerparpositions
-% \to \everytabulate
-
-%D When we want to calculate more complex backgrounds, we
-%D need to know what the current indentation scheme is. At
-%D the cost of many positions and memory, we can keep track
-%D of them. This mechanism is activated automatically
-%D based on information collected in the previous pass.
-
-\newcount\parposcounter
-
-\newif\ifpositioningpar
-
-% we can check for used entries, and if not, then not add one
-
-\def\registerparoptions
- {\ifpositioningpar \ifpositioning \iftrialtypesetting \else
- \ifinpagebody \else \ifmmode \else \ifinformula \else
- \ifprocessingverbatim
- \iflinepar \doregisterparoptions \fi
- \else
- \doregisterparoptions
- \fi
- \fi \fi \fi
- \fi \fi \fi}
-
-\chardef\parposstrut=1 % 0 => no strut data, so fall backs used
-
-\newif\iftracepositions
-
-% \def\doregisterparoptions
-% {\global\advance\parposcounter\plusone
-% \begingroup
-% \leftskip 1\leftskip
-% \rightskip1\rightskip
-% \setpositiondataplus
-% {p:\number\parposcounter}% identifier
-% {\the\zeropoint}%
-% {\the\strutht}%
-% {\the\strutdp}%
-% {\the\hsize ,% 1
-% \the\leftskip ,% 2
-% \the\rightskip ,% 3
-% \the\hangindent,% 4
-% \the\hangafter ,% 5 (num)
-% \the\parindent }% 6
-% %\normalhbox{\registerparsymbol}%
-% \registerparsymbol
-% \endgroup}
-
-\def\doregisterparoptions
- {\global\advance\parposcounter\plusone
- \setpositiondataplus
- {p:\number\parposcounter}% identifier
- {\the\zeropoint}%
- {\the\strutht}%
- {\the\strutdp}%
- {\the\hsize,\the\dimexpr\leftskip\relax,\the\dimexpr\rightskip\relax,\the\hangindent,\the\hangafter,\the\parindent}%
- %\normalhbox{\registerparsymbol}%
- \iftracepositions\registerparsymbol\fi}
-
-\def\traceposstring#1#2#3%
- {\iftracepositions\smashedhbox{#1{\infofont#2#3}}\fi}
-
-\def\registerparsymbol
- {\iftracepositions
- \smashedhbox to \zeropoint
- {\hss
- \startcolor[blue]%
- \llap{\infofont\number\parposcounter}%
- \scratchdimen\onepoint
- \vrule
- \!!width 4\scratchdimen
- \!!height2\scratchdimen
- \!!depth 2\scratchdimen
- \stopcolor
- \hss}%
- \fi}
-
-% \appendtoks \registerparoptions \to \everypar
-
-%D Eperimental code, don't use this yet: (must be sped up anyway)
-
-\def\@@noden{node:n:}
-\def\@@nodeo{node:o:}
-\def\@@nodep{node:p:}
-
-\def\doifelsenodelocation#1%
- {\ifcsname\@@noden#1\endcsname
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\nextnodelocation#1%
- {\ifcsname\@@noden#1\endcsname\pluscounter{\@@noden#1}\fi}
-
-\def\newnodelocation#1%
- {\ifcsname\@@noden#1\endcsname
- \setcounter{\@@noden#1}\zerocount
- \letgvalue {\@@nodeo#1}\!!zerocount
- \fi}
-
-\def\tagnodelocation#1%
- {\ifcsname\@@noden#1\endcsname\xypos{\@@nodep#1:\countervalue{\@@noden#1}}\fi}
-
-\def\getnodelocationp#1{\MPp{\@@nodep#1:\countervalue{\@@noden#1}}}
-\def\getnodelocationx#1{\MPx{\@@nodep#1:\countervalue{\@@noden#1}}}
-\def\getnodelocationy#1{\MPy{\@@nodep#1:\countervalue{\@@noden#1}}}
-
-\def\numnodelocationp#1#2{\MPp{\@@nodep#1:\number#2}}
-\def\numnodelocationx#1#2{\MPx{\@@nodep#1:\number#2}}
-\def\numnodelocationy#1#2{\MPy{\@@nodep#1:\number#2}}
-
-\def\getnodelocationn#1{\countervalue{\@@noden#1}}
-\def\getnodelocationo#1{\getvalue {\@@nodeo#1}}
-
-\chardef\nodelocationmode\plusone
-
-\def\analyzenodelocation#1%
- {\ifcsname\@@noden#1\endcsname
- \doanalyzenodelocation{#1}{\getnodelocationn{#1}}\zerocount
- \fi}
-
-\def\doanalyzenodelocation#1#2#3% class n default
- {\begingroup
- \donefalse
- \ifcase\nodelocationmode
- % do nothing
- \else
- \edef\nodelocationselfn{#2}%
- \edef\nodelocationselfp{\numnodelocationp{#1}\nodelocationselfn}%
- \edef\nodelocationselfx{\numnodelocationx{#1}\nodelocationselfn}%
- \edef\nodelocationselfy{\numnodelocationy{#1}\nodelocationselfn}%
- \scratchcounter\plusone
- \doloop
- {\ifnum\recurselevel=\nodelocationselfn\relax
- \donetrue
- \else
- \edef\nodelocationotherp{\numnodelocationp{#1}\recurselevel}%
- \edef\nodelocationotherx{\numnodelocationx{#1}\recurselevel}%
- \edef\nodelocationothery{\numnodelocationy{#1}\recurselevel}%
- \ifcase\nodelocationmode
- \or
- % ok for single column
- \ifcase\nodelocationotherp\relax
- \exitloop
- \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
- \donetrue \advance\scratchcounter\plusone
- \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
- % skip
- \else\ifdim\nodelocationothery>\nodelocationselfy\relax
- \donetrue \advance\scratchcounter\plusone
- \else\ifdim\nodelocationothery<\nodelocationselfy\relax
- % skip
- \else\ifdim\nodelocationotherx<\nodelocationselfx\relax
- \donetrue \advance\scratchcounter\plusone
- \fi\fi\fi\fi\fi\fi
- \or
- % acceptable for double column
- \ifcase\nodelocationotherp\relax
- \exitloop
- \else\ifnum\nodelocationotherp<\nodelocationselfp\relax
- \donetrue \advance\scratchcounter\plusone
- \else\ifnum\nodelocationotherp>\nodelocationselfp\relax
- % skip
- \else\ifnum\recurselevel>\nodelocationselfn\relax
- \donetrue \exitloop
- \else
- \donetrue \advance\scratchcounter\plusone
- \fi\fi\fi\fi
- \else
- \exitloop
- \fi
- \fi}%
- \fi
- \ifdone \else
- \scratchcounter#3\relax
- \fi
- \setxvalue{\@@nodeo#1}{\the\scratchcounter}%
- \endgroup}
-
-\unexpanded\def\shownodelocation#1%
- {\ifcsname\@@noden#1\endcsname
- \analyzenodelocation{#1}%
- (#1,%
- n:\getnodelocationn{#1},%
- p:\getnodelocationp{#1},%
- x:\getnodelocationx{#1},%
- y:\getnodelocationy{#1},%
- o:\getnodelocationo{#1})%
- \fi}
-
-%D \macros
-%D {doifoverlappingelse}
-%D
-%D A first application of positional information, is to
-%D determine if two boxes do overlap:
-%D
-%D \starttyping
-%D \doifoverlappingelse{point a}{point b}
-%D {action when overlapping}
-%D {action when not overlapping}
-%D \stoptyping
-
-\def\overlappingmargin{-2\scaledpoint}
-
-\def\doifoverlappingelse#1#2%
- {\begingroup
- \donefalse
- \edef\!!stringa{#1}\edef\!!stringb{#2}%
- \ifnum\MPp\!!stringa=\MPp\!!stringb\relax
- \!!dimena\MPx\!!stringa
- \!!dimenb\dimexpr\MPx\!!stringa+\MPw\!!stringa\relax
- \!!dimenc\dimexpr\MPy\!!stringa-\MPd\!!stringa\relax
- \!!dimend\dimexpr\MPy\!!stringa+\MPh\!!stringa\relax
- \!!dimene\MPx\!!stringb
- \!!dimenf\dimexpr\MPx\!!stringb+\MPw\!!stringb\relax
- \!!dimeng\dimexpr\MPy\!!stringb-\MPd\!!stringb\relax
- \!!dimenh\dimexpr\MPy\!!stringb+\MPh\!!stringb\relax
- \ifdim\overlappingmargin=\zeropoint\else
- \advance\!!dimena-\overlappingmargin
- \advance\!!dimenb+\overlappingmargin
- \advance\!!dimenc-\overlappingmargin
- \advance\!!dimend+\overlappingmargin
- \advance\!!dimene-\overlappingmargin
- \advance\!!dimenf+\overlappingmargin
- \advance\!!dimeng-\overlappingmargin
- \advance\!!dimenh+\overlappingmargin
- \fi
- % more often eh fb eg fg
- \def\checkone##1##2%
- {\ifdim##1<\!!dimena \else \ifdim##1>\!!dimenb \else
- \ifdim##2<\!!dimenc \else \ifdim##2>\!!dimend \else
- \donetrue
- \fi\fi
- \fi\fi}%
- \def\checktwo##1##2%
- {\ifdim##1<\!!dimene \else \ifdim##1>\!!dimenf \else
- \ifdim##2<\!!dimeng \else \ifdim##2>\!!dimenh \else
- \donetrue
- \fi\fi
- \fi\fi}%
- \checkone\!!dimene\!!dimeng \ifdone \else
- \checkone\!!dimene\!!dimenh \ifdone \else
- \checkone\!!dimenf\!!dimeng \ifdone \else
- \checkone\!!dimenf\!!dimenh \ifdone \else
- \checktwo\!!dimena\!!dimenc \ifdone \else
- \checktwo\!!dimena\!!dimend \ifdone \else
- \checktwo\!!dimenb\!!dimene \ifdone \else
- \checktwo\!!dimenb\!!dimenc \fi \fi \fi \fi \fi \fi \fi
- \fi
- \ifdone
- \endgroup\expandafter\firstoftwoarguments
- \else
- \endgroup\expandafter\secondoftwoarguments
- \fi}
-
-%D \macros
-%D {doifpositionsonsamepageelse,
-%D doifpositionsonthispageelse}
-%D
-%D Instead of letting the user handle fuzzy expansion, we
-%D provide a simple test on positione being on the same page.
-%D
-%D \starttyping
-%D \doifpositionsonsamepageelse{point a}{point b}
-%D {action when on same page}
-%D {action when not on same page}
-%D \doifpositionsonthispageelse{point a}{point b}
-%D {action when on this page}
-%D {action when not on this page}
-%D \stoptyping
-
-\def\dodoifpositionsonsamepageelse#1#2#3#4%
- {\bgroup
- \scratchcounter#1\donefalse
- \def\docommand##1%
- {\ifcase\scratchcounter
- \scratchcounter\MPp{##1}\donetrue
- \else
- \ifnum\scratchcounter=\MPp{##1}\relax\else\donefalse\fi
- \fi}%
- \rawprocesscommalist[#2]\docommand
- \ifdone\egroup#3\else\egroup#4\fi}
-
-\def\doifpositionsonsamepageelse
- {\dodoifpositionsonsamepageelse{0}}
-
-\def\doifpositionsonthispageelse#1#2#3%
- {\dodoifpositionsonsamepageelse\realfolio}
-
-%D Plugins:
-
-\loadmarkfile{core-pos}
-
-\let\MPv \MPplus
-\let\MPvv\MPrest
-
-\let\MPanchor\MPpos
-
-\let\POSp\MPp \let\POSx\MPx \let\POSy\MPy
-\let\POSh\MPh \let\POSd\MPd \let\POSw\MPw
-
-\protect \endinput
diff --git a/tex/context/base/core-ref.lua b/tex/context/base/core-ref.lua
deleted file mode 100644
index 6aaef5cc9..000000000
--- a/tex/context/base/core-ref.lua
+++ /dev/null
@@ -1,106 +0,0 @@
-if not modules then modules = { } end modules ['core-ref'] = {
- version = 1.001,
- comment = "companion to core-ref.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
-local format, texsprint = string.format, tex.sprint
-
--- beware, this is a first step in the rewrite (just getting rid of
--- the tuo file); later all access and parsing will also move to lua
-
-jobreferences = jobreferences or { }
-jobreferences.tobesaved = jobreferences.tobesaved or { }
-jobreferences.collected = jobreferences.collected or { }
-
-local tobesaved, collected = jobreferences.tobesaved, jobreferences.collected
-
-local function initializer()
- tobesaved, collected = jobreferences.tobesaved, jobreferences.collected
- -- hack, just the old way
- texsprint(tex.ctxcatcodes,"\\bgroup\\the\\everyreference")
- for prefix, list in pairs(collected) do
- for tag, data in pairs(list) do
- texsprint(tex.ctxcatcodes,format("\\dosetjobreference{%s}{%s}{%s}{%s}{%s}",prefix,tag,data[1],data[2],data[3]))
- end
- end
- texsprint(tex.ctxcatcodes,"\\egroup")
-end
-
-if job then
- job.register('jobreferences.collected', jobreferences.tobesaved, initializer)
-end
-
-function jobreferences.set(prefix,tag,page,realpage,text)
- for ref in tag:gmatch("[^,]+") do
- local p, r = ref:match("^(%-):(.-)$")
- if p and r then
- prefix, ref = "", r
- end
- if ref ~= "" then
- local pd = tobesaved[prefix]
- if not pd then
- pd = { }
- tobesaved[prefix] = pd
- end
- pd[ref] = { page, realpage, text }
- end
- end
-end
-
-function jobreferences.with(tag)
- for ref in tag:gmatch("[^,]+") do
- texsprint(tex.ctxcatcodes,format("\\dowithjobreference{%s}",ref:gsub("^(%-):","")))
- end
-end
-
--- this reference parser is just an lpeg version of the tex based one
-
-local result = { }
-
-local lparent, rparent, lbrace, rbrace, dcolon = lpeg.P("("), lpeg.P(")"), lpeg.P("{"), lpeg.P("}"), lpeg.P("::")
-
-local reset = lpeg.P("") / function (s) result = { } end
-local outer = (1-dcolon-lparent-lbrace )^1 / function (s) result.outer = s end
-local operation = (1-rparent-rbrace-lparent-lbrace)^1 / function (s) result.operation = s end
-local arguments = (1-rbrace )^0 / function (s) result.arguments = s end
-local special = (1-lparent-lbrace-lparent-lbrace)^1 / function (s) result.special = s end
-local inner = (1-lparent-lbrace )^1 / function (s) result.inner = s end
-
-local outer_reference = (outer * dcolon)^0
-
-operation = outer_reference * operation -- special case: page(file::1) and file::page(1)
-
-local optional_arguments = (lbrace * arguments * rbrace)^0
-local inner_reference = inner * optional_arguments
-local special_reference = special * lparent * (operation * optional_arguments + operation^0) * rparent
-
-
-local scanner = (reset * outer_reference * (special_reference + inner_reference)^-1 * -1) / function() return result end
-
-function jobreferences.analyse(str)
- return scanner:match(str)
-end
-
-local template = "\\setreferencevariables{%s}{%s}{%s}{%s}{%s}"
-
-function jobreferences.split(str)
- local t = scanner:match(str)
- texsprint(tex.ctxcatcodes,format(template,t.special or "",t.operation or "",t.arguments or "",t.outer or "",t.inner or ""))
-end
-
---~ print(table.serialize(jobreferences.analyse("")))
---~ print(table.serialize(jobreferences.analyse("inner")))
---~ print(table.serialize(jobreferences.analyse("special(operation{argument,argument})")))
---~ print(table.serialize(jobreferences.analyse("special(operation)")))
---~ print(table.serialize(jobreferences.analyse("special()")))
---~ print(table.serialize(jobreferences.analyse("inner{argument}")))
---~ print(table.serialize(jobreferences.analyse("outer::")))
---~ print(table.serialize(jobreferences.analyse("outer::inner")))
---~ print(table.serialize(jobreferences.analyse("outer::special(operation{argument,argument})")))
---~ print(table.serialize(jobreferences.analyse("outer::special(operation)")))
---~ print(table.serialize(jobreferences.analyse("outer::special()")))
---~ print(table.serialize(jobreferences.analyse("outer::inner{argument}")))
---~ print(table.serialize(jobreferences.analyse("special(outer::operation)")))
diff --git a/tex/context/base/core-ref.mkii b/tex/context/base/core-ref.mkii
deleted file mode 100644
index a5937726a..000000000
--- a/tex/context/base/core-ref.mkii
+++ /dev/null
@@ -1,90 +0,0 @@
-%D \module
-%D [ file=core-ref,
-%D version=2008.10.14,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Cross Referencing,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-\def\rawreference#1#2#3%
- {\bgroup
- \the\everyreference
- \makesectionformat
- \writereference{#2}
- {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
- {\noexpand\realfolio}%
- {#3}%
- \egroup}
-
-\def\rawpagereference#1#2%
- {\bgroup
- \the\everyreference
- \makesectionformat
- \writereference{#2}
- {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
- {\noexpand\realfolio}%
- {}%
- \egroup}
-
-\def\rawtextreference#1#2#3%
- {\bgroup
- \the\everyreference
- \writereference{#2}
- {}%
- {\noexpand\realfolio}%
- {#3}%
- \egroup}
-
-%D The last reference is saved in a macro named \type
-%D {\lastreference} (indeed). To keep track of the order of
-%D references, later we will see for what purpose, we maintain
-%D a counter.
-
-\newcount\crossreferencenumber \crossreferencenumber\plusone
-
-\let\lastreference\empty
-
-\def\writereference#1#2#3#4%
- {\ifreferencing
- \edef\!!stringa{#1}%
- \ifx\!!stringa\empty \else
- \def\dowritereference##1%
- {\xdef\lastreference{##1}%
- \@EA\dodowritereference\lastreference\empty\empty\end{#2}{#3}{#4}}%
- \rawprocesscommalist[\!!stringa]\dowritereference
- \fi
- \fi}
-
-%D Beware: \type {#2} gobbles space in references so that
-%D \typ {a nice ref} becomes \typ {anice ref}.
-
-\def\dodowritereference#1#2#3\end#4#5#6%
- {\bgroup
- \global\advance\crossreferencenumber \plusone\relax
- \if#1-\if#2:%
- \let\referenceprefix\empty
- \xdef\lastreference{#3}%
- \else
- % \xdef\lastreference{#1#2#3}% here we loose the space
- \fi\else
- % \xdef\lastreference{#1#2#3}% here we loose the space
- \fi
- \ifx\lastreference\empty \else
- \doiffirstreferenceoccurance\lastreference
- {\thisisdestination{\referenceprefix\lastreference}}%
- \referenceinfo>\lastreference
- \expanded{\writeutilitycommand{\noexpand\mainreference{\referenceprefix}{\lastreference}{#4}{#5}{#6}}}%
- \fi
- \egroup}
-
-%D We will implement \type {\doiffirstreferenceoccurance}
-%D later on.
-
-\protect
diff --git a/tex/context/base/core-ref.mkiv b/tex/context/base/core-ref.mkiv
deleted file mode 100644
index 56ef77b37..000000000
--- a/tex/context/base/core-ref.mkiv
+++ /dev/null
@@ -1,107 +0,0 @@
-%D \module
-%D [ file=core-ref,
-%D version=2008.10.14,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Cross Referencing,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\let\mainreference\gobblefivearguments % catch mkii tuo stuff
-
-\registerctxluafile{core-ref}{1.001}
-
-\unprotect
-
-% later we will use the lua tables directly (first a hack)
-%
-% \the\everyreference % we're grouped anyway
-
-\newcount\crossreferencenumber \crossreferencenumber\plusone
-
-\def\dowithjobreference#1%
- {\global\advance\crossreferencenumber\plusone
- \doiffirstreferenceoccurance{#1}{\thisisdestination{\referenceprefix#1}}%
- \referenceinfo>{#1}}
-
-% \def\dowithjobreference#1{}
-
-\def\dosetjobreference#1#2#3#4#5%
- {\ifcsname\r!cross\fileprefix#1#2\endcsname
- \ifcase0#4\else
- \showmessage\m!references2{[#1][#2],#4 (\currentutilityfilename)}%
- \fi
- \else
- \ifcase\autocrossfilereferences
- \setglobalcrossreference{#1#2}{#3}{#4}{#5}%
- \or
- \setglobalcrossreference{#1#2}{#3}{#4}{#5}%
- \ifcsname\r!cross#1#2\endcsname
- \showmessage\m!references2{[#1][#2],#4 (auto \currentutilityfilename)}%
- \else
- \expanded{\definereference[#1#2][\fileprefix#1#2]}%
- \fi
- \or
- \ifcsname\r!cross#1#2\endcsname
- \showmessage\m!references2{[#1][#2],#4 (auto \currentutilityfilename)}%
- \else
- \expanded{\definereference[#1#2][\noexpand\v!page(\fileprefix#4)]}%
- \fi
- \fi
- \fi}
-
-\def\rawreference#1#2#3%
- {\ifreferencing
- \doifsomething{#2}
- {\bgroup
- \the\everyreference
- \makesectionformat
- \expanded{\ctxlua{jobreferences.with("#2")}}%
- \expanded{\ctxlatelua{jobreferences.set(
- "\referenceprefix",
- "#2",
- "\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber",
- "\noexpand\the\realpageno",
- \!!bs#3\!!es
- )}}%
- \egroup}%
- \fi}
-
-\def\rawpagereference#1#2%
- {\ifreferencing
- \doifsomething{#2}
- {\bgroup
- \the\everyreference
- \makesectionformat
- \expanded{\ctxlua{jobreferences.with("#2")}}%
- \expanded{\ctxlatelua{jobreferences.set(
- "\referenceprefix",
- "#2",
- "\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber",
- "\noexpand\the\realpageno",
- ""
- )}}%
- \egroup}%
- \fi}
-
-\def\rawtextreference#1#2#3%
- {\ifreferencing
- \doifsomething{#2}
- {\bgroup
- \the\everyreference
- \expanded{\ctxlua{jobreferences.with("#2")}}%
- \expanded{\ctxlatelua{jobreferences.set(
- "\referenceprefix",
- "#2",
- "",
- "\noexpand\the\realpageno",
- \!!bs#3\!!es
- )}}%
- \egroup}%
- \fi}
-
-\protect
diff --git a/tex/context/base/core-ref.tex b/tex/context/base/core-ref.tex
index b67928e45..8ca0a92bf 100644
--- a/tex/context/base/core-ref.tex
+++ b/tex/context/base/core-ref.tex
@@ -11,7 +11,9 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Cross Referencing}
+% we will merge mkii code back in here
+
+\writestatus{loading}{ConTeXt Core Macros / Cross Referencing}
% todo : unknown/illegal reference no arg
% todo : +n pages check on 'samepage' (contrastcolor)
@@ -42,93 +44,21 @@
\unprotect
-\startmessages dutch library: references
- title: verwijzingen
- 1: onbekende verwijzing --
- 2: dubbele verwijzing -- op pagina --
- 3: type verwijzing -- onbekend
- 4: verboden verwijzing --
- 21: document -- geladen
- 22: document -- is niet interactief
- 23: onduidelijke verwijzing -- (prefix=--)
-\stopmessages
-
-\startmessages english library: references
- title: references
- 1: unknown reference --
- 2: duplicate reference -- on page --
- 3: unknown reference type --
- 4: illegal reference --
- 21: document -- loaded
- 22: document -- is not interactive
- 23: obscure reference -- (prefix=--)
-\stopmessages
-
-\startmessages german library: references
- title: referenzen
- 1: unbekannte Referenz --
- 2: doppelte Referenz -- auf Seite --
- 3: unbekannte Referenz Typ --
- 4: illegale Referenz --
- 21: Dokument -- geladen
- 22: Dokument -- ist nicht aktiv
- 23: Obskure Referenz -- (Prefix=--)
-\stopmessages
-
-\startmessages czech library: references
- title: reference
- 1: neznama reference --
- 2: duplicitni reference -- na strane --
- 3: neznamy typ reference --
- 4: nedovolena reference --
- 21: dokument -- nacten
- 22: dokument -- neni interaktivni
- 23: obskurni (nejasna) reference -- (prefix=--)
-\stopmessages
-
-\startmessages italian library: references
- title: riferimenti
- 1: riferimento sconosciuto --
- 2: riferimento duplicato -- a pagina --
- 3: riferimento di tipo sconosciuto --
- 4: riferimento illecito --
- 21: documento -- caricato
- 22: il documento -- non ø interattivo
- 23: riferimento ambiguo -- (prefisso=--)
-\stopmessages
-
-\startmessages norwegian library: references
- title: referanser
- 1: ukjent referanse --
- 2: duplikat referanse -- pø side --
- 3: ukjent referansetype --
- 4: ulovlig referanse --
- 21: dokument -- er lest inn
- 22: dokument -- er ikke interaktivt
- 23: obskur referanse -- (Prefix=--)
-\stopmessages
-
-\startmessages romanian library: references
- title: referinte
- 1: referinta necunoscuta --
- 2: referinta duplicat -- la pagina --
- 3: tip necunoscut de referinta --
- 4: referinta eronata --
- 21: documentul -- este incarcat
- 22: documentul -- nu este interactiv
- 23: referinta obscura -- (prefix=--)
-\stopmessages
-
-\startmessages french library: references
- title: réferences
- 1: réference -- inconnue
- 2: réference -- dupliquée à la page --
- 3: type -- de réference inconnu
- 4: réference -- inconnue
- 21: document -- chargé
- 22: le document -- n'est pas interactif
- 23: reference -- indéterminé (préfixe=--)
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
%D This module deals with referencing. In \CONTEXT\ referencing
%D is one of the core features, although at a first glance
@@ -193,9 +123,79 @@
%D full reference, but it's the concept that counts. The low
%D level implementation is:
-\let\rawreference \gobblethreearguments
-\let\rawpagereference\gobbletwoarguments
-\let\rawtextreference\gobbletwoarguments
+\def\rawreference#1#2#3%
+ {\bgroup
+ \the\everyreference
+ \makesectionformat
+ \writereference{#2}
+ {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
+ {\noexpand\realfolio}%
+ {#3}%
+ \egroup}
+
+\def\rawpagereference#1#2%
+ {\bgroup
+ \the\everyreference
+ \makesectionformat
+ \writereference{#2}
+ {\sectionformat\sectionseparator\sectionseparator\noexpand\pagenumber}%
+ {\noexpand\realfolio}%
+ {}%
+ \egroup}
+
+\def\rawtextreference#1#2#3%
+ {\bgroup
+ \the\everyreference
+ \writereference{#2}
+ {}%
+ {\noexpand\realfolio}%
+ {#3}%
+ \egroup}
+
+%D The last reference is saved in a macro named \type
+%D {\lastreference} (indeed). To keep track of the order of
+%D references, later we will see for what purpose, we maintain
+%D a counter.
+
+\newcount\crossreferencenumber \crossreferencenumber\plusone
+
+\let\lastreference\empty
+
+\def\writereference#1#2#3#4%
+ {\ifreferencing
+ \edef\!!stringa{#1}%
+ \ifx\!!stringa\empty \else
+ \def\dowritereference##1%
+ {\xdef\lastreference{##1}%
+ \@EA\dodowritereference\lastreference\empty\empty\end{#2}{#3}{#4}}%
+ \rawprocesscommalist[\!!stringa]\dowritereference
+ \fi
+ \fi}
+
+%D Beware: \type {#2} gobbles space in references so that
+%D \typ {a nice ref} becomes \typ {anice ref}.
+
+\def\dodowritereference#1#2#3\end#4#5#6%
+ {\bgroup
+ \global\advance\crossreferencenumber \plusone\relax
+ \if#1-\if#2:%
+ \let\referenceprefix\empty
+ \xdef\lastreference{#3}%
+ \else
+ % \xdef\lastreference{#1#2#3}% here we loose the space
+ \fi\else
+ % \xdef\lastreference{#1#2#3}% here we loose the space
+ \fi
+ \ifx\lastreference\empty \else
+ \doiffirstreferenceoccurance\lastreference
+ {\thisisdestination{\referenceprefix\lastreference}}%
+ \referenceinfo>\lastreference
+ \expanded{\writeutilitycommand{\noexpand\mainreference{\referenceprefix}{\lastreference}{#4}{#5}{#6}}}%
+ \fi
+ \egroup}
+
+%D We will implement \type {\doiffirstreferenceoccurance}
+%D later on.
%D These macros depend on three other ones,
%D \type {\makesectionformat}, that generated \type
@@ -215,8 +215,6 @@
%D different alphabet and needs accented entries in registers.
\appendtoks
- %\def\dohandleaccent #1#2{\string#1\string#2}%
- %\def\dohandlecommand #1{\string#1}%
\cleanupfeatures
\to \everyreference
@@ -671,20 +669,19 @@
\newif\ifreferencefound
-\let\currentfullreference =\empty
-\let\currentreferencespecial =\empty
-\let\currentreferenceoperation=\empty
-\let\currentreferencearguments=\empty
-\let\currentouterreference =\empty
-\let\currentinnerreference =\empty
-
-\def\setreferencevariables#1#2#3#4#5#6%
- {\def\currentfullreference {#1}%
- \def\currentreferencespecial {#2}%
- \def\currentreferenceoperation{#3}%
- \def\currentreferencearguments{#4}%
- \def\currentouterreference {#5}%
- \def\currentinnerreference {#6}}
+\let\currentfullreference \empty
+\let\currentreferencespecial \empty
+\let\currentreferenceoperation\empty
+\let\currentreferencearguments\empty
+\let\currentouterreference \empty
+\let\currentinnerreference \empty
+
+\def\setreferencevariables#1#2#3#4#5%
+ {\def\currentreferencespecial {#1}%
+ \def\currentreferenceoperation{#2}%
+ \def\currentreferencearguments{#3}%
+ \def\currentouterreference {#4}%
+ \def\currentinnerreference {#5}}
\def\splitofffullreference#1%
{\edef\currentfullreference{#1}%
@@ -1835,12 +1832,15 @@
% \let\normalover \over
-\definecommand in {\doinatreference\currenttextreference}
-\definecommand at {\doinatreference\currentpagereference}
+\definecommand in {\dospecialin}
+\definecommand at {\dospecialat}
\definecommand about {\dospecialabout}
\definecommand from {\dospecialfrom}
\definecommand over {\dospecialabout} % needed here, else math problems
+\unexpanded\def\dospecialin{\doinatreference\currenttextreference}
+\unexpanded\def\dospecialat{\doinatreference\currentpagereference}
+
\unexpanded\def\dospecialabout[#1]%
{\dontleavehmode
\bgroup
@@ -1896,9 +1896,7 @@
%D in a different color and typeface).
\def\doinatreference#1%
- {\doifnextcharelse[% {[}
- {\dodoinatreference{#1}{}}
- {\dodoinatreference{#1}}}
+ {\doifnextoptionalelse{\dodoinatreference{#1}{}}{\dodoinatreference{#1}}}
\def\dodoinatreference#1%
{\def\dododoinatreference{\dodododoinatreference{#1}}%
@@ -2068,7 +2066,7 @@
{\dontleavehmode % replaces \leaveoutervmode
\bgroup
\forgetall
- \postponefootnotes
+ \postponenotes
%\leaveoutervmode % replaced by \dontleavehmode
\doifreferencefoundelse{#3}
{\bgroup
@@ -2120,7 +2118,7 @@
\def\dogoto#1[#2]%
{\dontleavehmode
\bgroup
- \postponefootnotes
+ \postponenotes
\doifreferencefoundelse{#2}
{\doifelsenothing{#1}
{\dosymbolreference{}{}[#2]}
@@ -2284,13 +2282,6 @@
\let\useurl\useURL
-% \def\dodouseURL[#1][#2][#3][#4]%
-% {\iffirstargument
-% \iffourthargument\setgvalue{\v!file:::#1}{\doexternaldocument{#2}{#3}{#4}}\else
-% \ifthirdargument \setgvalue{\v!file:::#1}{\doexternaldocument{#2}{#3}{\url[#1]}}\else
-% \ifsecondargument\setgvalue{\v!file:::#1}{\doexternaldocument{#2}{}{\url[#1]}}\fi\fi\fi
-% \fi}
-
\def\dodouseURL[#1][#2][#3][#4]% to be redone: not too tricky redefs ad reuse
{\iffirstargument
\iffourthargument\setgvalue{\v!file:::#1}{\doexternaldocument{#2}{#3}{#4}}\else
@@ -2633,31 +2624,15 @@
\let\currentinnerreference\currentreferenceoperation
\fi
\ifx\currentouterreference\empty
-% numexpr
- \doifinstringelse+\currentinnerreference
- {\scratchcounter\realpageno
- \advance\scratchcounter \currentinnerreference
- \edef\currentinnerreference{\the\scratchcounter}}
- {\doifinstringelse-\currentinnerreference
- {\scratchcounter\realpageno
- \advance\scratchcounter \currentinnerreference
- \edef\currentinnerreference{\the\scratchcounter}}
- \donothing}%
- \doifnonzeropositiveelse\currentinnerreference
- \donothing
- {\edef\currentinnerreference{1}}%
+ \doifinstringelse+\currentinnerreference{\edef\currentinnerreference{\the\numexpr\realpageno\currentinnerreference}}
+ {\doifinstring -\currentinnerreference{\edef\currentinnerreference{\the\numexpr\realpageno\currentinnerreference}}}%
+ \doifnonzeropositiveelse\currentinnerreference\donothing{\edef\currentinnerreference{1}}%
\docheckrealreferencepage\currentinnerreference % new
\let\currentrealreference\currentinnerreference % handy to have this available
\gotorealpage\empty\empty\currentinnerreference{#2}%
\else
\setouterlocation\currentouterreference
- \doifnonzeropositiveelse\currentinnerreference
- \donothing
- {\ifcsname\v!page:::\currentinnerreference\endcsname
- \edef\currentinnerreference{\getvalue{\v!page:::\currentinnerreference}}%
- \else
- \edef\currentinnerreference{1}%
- \fi}%
+ \doifnonzeropositiveelse\currentinnerreference\donothing{\edef\currentinnerreference{\executeifdefined{\v!page:::\currentinnerreference}1}}%
\gotorealpage\otherURL\otherfile\currentinnerreference{#2}%
\fi
\else
@@ -2761,7 +2736,7 @@
\endgroup
\fi}
-\def\coupledocument%
+\def\coupledocument
{\doquadrupleempty\docoupledocument}
%D --- STRANGE HERE, BETTER IN CORE-NAV ---
@@ -2983,8 +2958,6 @@
%D Plugin code:
-\loadmarkfile{core-ref}
-
%D In the next settings we see some variables that were not
%D used here and that concern the way the pagenumbers refered
%D to are typeset.
diff --git a/tex/context/base/core-reg.lua b/tex/context/base/core-reg.lua
deleted file mode 100644
index 820d316a6..000000000
--- a/tex/context/base/core-reg.lua
+++ /dev/null
@@ -1,186 +0,0 @@
-if not modules then modules = { } end modules ['core-reg'] = {
- version = 1.001,
- comment = "companion to core-reg.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
-sorters = sorters or { }
-sorters.register = sorters.register or { }
-
--- {'e','3','','test+test+test','2--0-0-0-0-0-0-0--1','1'}
-
-function sorters.register.compare(a,b)
- local result = 0
- for i=1,4 do
- if result == 0 then
- result = sorters.comparers.basic(a,b,i)
- else
- return result
- end
- end
- if a[1] ~= 's' then -- e/f/t
- local page_a, page_b = a[3], b[3]
- if page_a < page_b then
- return -1
- elseif page_a > page_b then
- return 1
- end
- end
- return 0
-end
-
-function sorters.register.prepare(data)
- sorters.prepare(data,sorters.splitters.utf,4)
-end
-
-function sorters.register.sort(data)
- sorters.sort(data,sorters.register.compare)
-end
-
-function sorters.register.unique(data)
- sorters.unique(data)
-end
-
-function sorters.register.cleanup(data)
- sorters.cleanup(data)
-end
-
-function sorters.register.finalize(data)
- local split = { }
- for k,v in ipairs(data) do
- local entry, tag = v[2][1][3][1], ""
- local se = sorters.entries[sorters.language]
- if se and se[entry] then
- if type(se[entry]) == "number" then
- entry = se[entry]
- end
- tag = se[entry]
- else
- entry = 0
- tag = "unknown"
- end
- split[entry] = split[entry] or { tag = tag, data = { } }
- split[entry].data[#split[entry].data+1] = v
- end
- return split
-end
-
--- \registerpage{index}{,}{6}{2--0-0-0-0-0-0-0--1}{1}
-
--- for the moment we use the old structure, some day mkiv code
--- will be different: more structure, less mess
-
-local template = {
- page = "\\registerpage{%s}{%s}{%s}{%s}{%s}",
- see = "\\registersee{%s}{%s}{%s}{%s}",
- letter = "\\registerentry{%s}{%s}",
- entry = {
- "\\registerentrya{%s}{%s}",
- "\\registerentryb{%s}{%s}",
- "\\registerentryc{%s}{%s}",
- "\\registerentryd{%s}{%s}",
- },
-}
-
-function sorters.register.flush(sorted,class)
- class = class or 'index'
- for k,v in ipairs(table.sortedkeys(sorted)) do
- local s = sorted[v]
- tex.sprint(tex.ctxcatcodes,template.letter:format(class,s.tag))
- local done = { false, false, false }
- for kk,vv in ipairs(s.data) do
- if vv[2][1] then
- local e = { false, false, false, false }
- for i=1,4,1 do
- if vv[2][i] then
- e[i] = vv[2][i][1]
- end
- if e[i] ~= done[i] then
- if e[i] and e[i] ~= "" then
- done[i] = e[i]
- tex.sprint(tex.ctxcatcodes,template.entry[i]:format(class,e[i]))
- else
- done[i] = false
- end
- end
- end
- if vv[1] == 'e' then
- -- format reference pagespec realpage
- tex.sprint(tex.ctxcatcodes,template.page:format(class,",",vv[4],vv[5],vv[3]))
- elseif vv[1] == 's' then
- tex.sprint(tex.ctxcatcodes,template.see:format(class,",",vv[5],vv[3]))
- end
- end
- end
- end
-end
-
-function sorters.register.process(data)
- return sorters.process('register',data)
-end
-
--- { { entry, key }, { entry, key }, { entry, key }, { entry, key } }, kind, realpage|see, reference, pagespec
-
-jobregisters = jobregisters or { }
-jobregisters.collected = jobregisters.collected or { }
-jobregisters.tobesaved = jobregisters.tobesaved or { }
-
-job.register('jobregisters.collected', jobregisters.tobesaved)
-
-local function allocate(class)
- local d = jobregisters.tobesaved[class]
- if not d then
- d = {
- language = 'en',
- entries = { },
- sorted = false,
- class = class
- }
- jobregisters.tobesaved[class] = d
- end
- return d
-end
-
-local function collect(class)
- return jobregisters.collected[class]
-end
-
-jobregisters.define = allocate
-
-function jobregisters.save_entry(class,kind,reference,key,entry,page,realpage) -- realpage|see
- local data = allocate(class).entries
- if type(entry) == 'string' then
- entry = entry:splitchr('+')
- end
- if type(key) == 'string' then
- key = key:splitchr('+')
- end
- data[#data+1] = {
- kind, -- kind (e, f, t, s)
- {
- { entry[1] or "", key[1] or "" },
- { entry[2] or "", key[2] or "" },
- { entry[3] or "", key[3] or "" },
- { entry[4] or "", key[4] or "" }
- },
- realpage, -- realpage or seeword (check see)
- reference, -- reference
- page, -- pagespec
- }
-end
-
-jobregisters.save_see = jobregisters.save_entry
-
-function jobregisters.save_variable(class,key,value)
- if key == "l" then key = "language" end
- allocate(class)[key] = value
-end
-
-function jobregisters.process(class)
- local data = collect(class)
- if data then
- return sorters.register.process(data)
- end
-end
diff --git a/tex/context/base/core-reg.mkii b/tex/context/base/core-reg.mkii
deleted file mode 100644
index bd925d568..000000000
--- a/tex/context/base/core-reg.mkii
+++ /dev/null
@@ -1,33 +0,0 @@
-%D \module
-%D [ file=core-reg,
-%D version=2007.05.07,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Register Management,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-% the spaces between } { are essential for texutil's split
-
-\def\mkdefineregister#1% class
- {\addutilityreset{#1}}
-
-\def\mksaveregisterentry#1#2#3#4#5#6#7% class type reference key entry pagespec realpage
- {\expanded{\writeutility{r #2 {#1} {#3} {#4} {#5} {#6} {#7}}}}
-
-\def\mksaveregistersee#1#2#3#4#5#6#7% class type reference key entry see pagespec
- {\expanded{\writeutility{r #2 {#1} {#3} {#4} {#5} {#6} {#7}}}}
-
-\def\mksaveregistervariable#1#2#3% class type value
- {\expanded{\immediatewriteutility{r #2 {#1} {#3}}}}
-
-\def\mkloadregister#1#2#3% class before after
- {\doutilities{#1}{\registerparameter\c!file}{#1}{#2}{#3}}
-
-\protect \endinput
diff --git a/tex/context/base/core-reg.mkiv b/tex/context/base/core-reg.mkiv
deleted file mode 100644
index 6b7ee4e30..000000000
--- a/tex/context/base/core-reg.mkiv
+++ /dev/null
@@ -1,40 +0,0 @@
-%D \module
-%D [ file=core-reg,
-%D version=2007.05.07,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Register Management,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-\registerctxluafile{core-reg}{1.001}
-
-\def\mkdefineregister#1% class
- {\ctxlua{jobregisters.define('#1')}}
-
-\def\mksaveregisterentry#1#2#3#4#5#6#7% class type reference key entry pagespec realpage
- {\expanded{\ctxlatelua{jobregisters.save_entry('#1','#2','#3',\!!bs#4\!!es,\!!bs#5\!!es,'#6','#7')}}}
-
-\def\mksaveregistersee#1#2#3#4#5#6#7% class type reference key entry see pagespec
- {\expanded{\ctxlatelua{jobregisters.save_see('#1','#2','#3',\!!bs#4\!!es,\!!bs#5\!!es,'#6','#7')}}}
-
-\def\mksaveregistervariable#1#2#3% class type value
- {\expanded{\ctxlua{jobregisters.save_variable('#1','#2','#3')}}}
-
-% Beware, we have no filename support here. For that we need to save the resulting
-% tex code in a file. No big deal.
-
-\def\mkloadregister#1#2#3% class, todo: loader macro just like mkii
- {\bgroup
- \getvalue{\s!set#1}% smells like a hack
- #2\ctxlua{jobregisters.process('#1')}#3% par needed for hanging indentation
- \getvalue{\s!reset#1}%
- \egroup}
-
-\protect \endinput
diff --git a/tex/context/base/core-reg.tex b/tex/context/base/core-reg.tex
index af779c0b2..1d139a2dc 100644
--- a/tex/context/base/core-reg.tex
+++ b/tex/context/base/core-reg.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Register Management}
+\writestatus{loading}{ConTeXt Core Macros / Register Management}
\newif \ifautoregisterhack % for the moment a private hack
@@ -81,14 +81,6 @@
\newif\ifwritetoregister \writetoregistertrue
-\ifx\undefined\mkdefineregister
- \let\mkdefineregister \gobbleoneargument
- \let\mksaveregistervariable\gobblethreearguments
- \let\mksaveregisterentry \gobblesevenarguments
- \let\mksaveregistersee \gobblesevenarguments
- \let\mkloadregister \gobbleoneargument
-\fi
-
\chardef\registerpagestatus\zerocount
\def\doprocesspageregister[#1]#2#3% key altnum entry
@@ -105,15 +97,13 @@
\makesectionformat
\doifelse{\registerparameter\c!ownnumber}\v!yes
\donetrue\donefalse
- \mksaveregisterentry
- {\currentregister}
- {\ifcase\registerpagestatus\space\or e\or f\or t\fi}
- {\nextinternalreference}
- {\asciiregisterentryA}
- {\asciiregisterentryB}
- {\sectionformat\sectionseparator\sectionseparator
- \ifdone#2\else\noexpand\pagenumber\fi}
- {\noexpand\realfolio}%
+ \expanded{\writeutility{r % spaces are essential
+ {\ifcase\registerpagestatus\space\or e\or f\or t\fi} {\currentregister} %
+ {\nextinternalreference} %
+ {\asciiregisterentryA} %
+ {\asciiregisterentryB} %
+ {\sectionformat\sectionseparator\sectionseparator\ifdone#2\else\noexpand\pagenumber\fi} %
+ {\noexpand\realfolio}}}%
\getfirstcharacter\currentregister
\registerinfo{> \firstcharacter}{#3}%
\endgroup
@@ -197,14 +187,13 @@
\defconvertexpanded\asciiregisterentryA{\registerparameter\c!keyexpansion}{#2}%
\fi}%
\makesectionformat
- \mksaveregistersee
- {\currentregister}
- {s}
- {\nextinternalreference}
- {\asciiregisterentryA}
- {\asciiregisterentryB}
- {\asciiregisterentryC}
- {\sectionformat}%
+ \expanded{\writeutility{r s %
+ {\currentregister} %
+ {\nextinternalreference} %
+ {\asciiregisterentryA} %
+ {\asciiregisterentryB} %
+ {\asciiregisterentryC} %
+ {\sectionformat}}}%
\endgroup
\registerinfo{> see}{#2}%
\fi}
@@ -890,7 +879,7 @@
\let\dosetregister\doloadregisterlinks
\def\currentregister{#1}%
\setupregister[#1][#2]%
- \mkloadregister\currentregister\dobeforeplaceregister\doafterplaceregister
+ \doutilities\currentregister{\registerparameter\c!file}\currentregister\dobeforeplaceregister\doafterplaceregister
\endgroup
\ifautoregisterhack
\doinitializeautoregister{#1}%
@@ -1109,7 +1098,7 @@
tolerance=stretch]%
\dontcomplain
\startpacked[\v!blank]%
- \mkloadregister\currentregister\dobeforeplaceregister\doafterplaceregister
+ \doutilities\currentregister{\registerparameter\c!file}\currentregister\dobeforeplaceregister\doafterplaceregister
\stoppacked
\stopcolumns
\endgroup
@@ -1138,7 +1127,7 @@
\def\doregisterregisterlanguage#1%
{\savesortlanguage{\getvalue{\??id#1\s!language}}%
- \mksaveregistervariable{#1}{l}{\getvalue{\??id#1\s!language}}}
+ \expanded{\immediatewriteutility{r l {#1} {\getvalue{\??id#1\s!language}}}}}
\def\dodefineregister[#1][#2]%
{\setupregister[#1]%
@@ -1174,7 +1163,7 @@
\doregisterregisterlanguage{#1}%
\to \everysavesortkeys
\presetheadtext[#1=\Word{#1}]%
- \mkdefineregister{#1}%
+ \addutilityreset{#1}%
\setvalue{#1}{\doregister{#1}}%
\setvalue{\e!coupled#1}{\dolinkedregister{#1}}%
\setvalue{\s!set#1}{\dosetregister{#1}}%
@@ -1204,7 +1193,7 @@
\global\utilitydonetrue}
{}}%
\doglobal\newcounter\utilityregisterlength
- \setbox0\vbox{\mkloadregister\currentregister\dobeforeplaceregister\doafterplaceregister}%
+ \setbox0\vbox{\doutilities\currentregister{\registerparameter\c!file}\currentregister\dobeforeplaceregister\doafterplaceregister}%
\endgroup
\ifregistergeplaatst
\setsystemmode \v!register
@@ -1215,10 +1204,6 @@
\def\determineregistercharacteristics
{\dodoubleempty\dodetermineregistercharacteristics}
-%D Plugins.
-
-\loadmarkfile{core-reg}
-
%D Default index:
\defineregister
diff --git a/tex/context/base/core-rul.lua b/tex/context/base/core-rul.lua
index 1c93542db..6947c7f7b 100644
--- a/tex/context/base/core-rul.lua
+++ b/tex/context/base/core-rul.lua
@@ -18,7 +18,6 @@ function commands.doreshapeframedbox(n)
local list = tex.box[n].list
for h in node.traverse_id('hlist',list) do
done = true
- -- local p = hpack(h.list)
local p = hpack(copy(h.list))
lastlinelength = p.width
if lastlinelength > width then
diff --git a/tex/context/base/core-rul.mkii b/tex/context/base/core-rul.mkii
index 4381a8d5a..59bfd2f3c 100644
--- a/tex/context/base/core-rul.mkii
+++ b/tex/context/base/core-rul.mkii
@@ -11,12 +11,1864 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Ruled Content Handling}
+
\unprotect
+%D We have removed the rather old and out dated raster methods. They
+%D have not been used for ages.
+
+%D \macros
+%D {linewidth, setuplinewidth}
+%D
+%D This module deals with rules (lines) in several ways. First
+%D we introduce two macros that can be used to set some common
+%D characteristics.
+%D
+%D \showsetup{setuplinewidth}
+%D
+%D The linewidth is available in \type{\linewidth}. The
+%D preset value of .4pt equals the default hard coded \TEX\
+%D rule width.
+
+\newdimen\linewidth
+
+\def\dosetuplinewidth[#1]%
+ {\assigndimension{#1}\linewidth{.2\points}{.4\points}{.6\points}}
+
+\def\setuplinewidth
+ {\dosingleargument\dosetuplinewidth}
+
+%D \macros
+%D {ruledlinewidth, inheritruledlinewidth}
+%D
+%D Inside framed boxed we will use a private dimensions. As
+%D an option one can let the linewidth inherit its value from
+%D this one.
+
+\newdimen\ruledlinewidth \newif\ifinheritruledlinewidth
+
+% %D \TEX\ lacks support for color and even gray scales. The next
+% %D macros can provide a sort of poor mans gray scales as well
+% %D as give access to more suitable methods of rendering. Such a
+% %D method looks like:
+% %D
+% %D \starttyping
+% %D \def\methodegraybox#1#2#3#4#5#6%
+% %D { ... }
+% %D \stoptyping
+% %D
+% %D The string \type{graybox} is a common element in the name,
+% %D so we can have for instance \type {\postscriptgraybox} or
+% %D \type {\texgraybox}. The first three arguments take a
+% %D dimension, the fourth one takes a number between~0 and~1,
+% %D and the last argument specifies a radius of the box when
+% %D rounded corners are used, so:
+% %D
+% %D \startbuffer
+% %D \dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}
+% %D \stopbuffer
+% %D
+% %D \typebuffer
+% %D
+% %D becomes:
+% %D
+% %D %\startlinecorrection
+% %D % \vbox to 1cm{\getbuffer}
+% %D %\stoplinecorrection
+% %D
+% %D \startlinecorrection
+% %D \unprotect
+% %D \vbox to 1cm{\dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}}
+% %D \protect
+% %D \stoplinecorrection
+% %D
+% %D There are two predefined methodes, one uses periods and the
+% %D other uses small rules. The second method is less
+% %D efficient, but sometimes give better results. The dimensions
+% %D of the resullting box are set to zero.
+%
+% \setvalue{\v!dot graybox}{\processraster\symbol\rasterdot}
+% \setvalue{\v!rule graybox}{\processraster\symbol\rasterbox}
+%
+% \def\rasterdot{\rasterfont.}
+% \def\rasterbox{\hss\vrule\!!width.4pt\!!height.4pt\!!depth\zeropoint}
+%
+% %D Now of course we need:
+%
+% \ifx\rasterfont\undefined \def\rasterfont{\fivepoint} \fi
+%
+% %D We implement two pure \TEX\ based generators, that use
+% %D \type{\leaders} to quickly gerenate the gray pattern. One
+% %D should beware of \DIMENSION\ conflicts, so we use some
+% %D registers above~8. These macros are memory hungry and byte
+% %D spoiling.
+%
+% \def\processraster#1#2#3#4#5#6#7%
+% {\bgroup
+% \forgetall
+% \dontcomplain
+% \dimen10=\onepoint
+% \dimen10=\@@rsfactor\dimen10
+% \dimen10=#5\dimen10
+% \setbox2\hbox to #2
+% {\cleaders\hbox to 2\dimen10{#1\hss}\hss}%
+% \dimen12=#3%
+% \advance\dimen12 #4%
+% % \setbox0\vbox to \dimen12
+% {\cleaders\vbox to 2\dimen10{\box2\vss}\vss}%
+% \setbox0\hbox
+% {\hskip-.5\dimen10\lower0.5\dimen10\copy0
+% \hskip-\wd0\hskip\dimen10\lower1.5\dimen10\box0}%
+% \box0
+% \egroup}
+
+%D \macros
+%D {setupscreens}
+%D
+%D The previous macro uses a predefined constant
+%D \type{\@@rsfactor}. This factor can be set by:
+%D
+%D \showsetup{setupscreens}
+
+\def\setupscreens
+ {\dodoubleargument\getparameters[\??rs]}
+
+% %D The most appropriate way to call for this feature is
+% %D using \type{\graybox}, which is defined as:
+%
+% \def\graybox{\getvalue{\@@rsmethod graybox}}
+%
+% %D We just introduced two pure \TEX\ methods for generating
+% %D rasters. However, it's far more efficient and comfortable in
+% %D terms of speed, memory usage and file size, to use a driver
+% %D supported method.
+%
+% \setvalue{\v!external graybox}{\setgraybox}
+%
+% %D For compatibility reasons we also define the original one:
+%
+% \setvalue{\v!postscript graybox}{\getvalue{\v!external graybox}}
+%
+% %D A quite valid way of letting drivers do the job, is giving
+% %D a solid rule a gray texture.
+
+%D We will communicate through module specific variables, current
+%D framed parameters and some reserved dimension registers.
+
+\newdimen \frameddimenwd
+\newdimen \frameddimenht
+\newdimen \frameddimendp
+
+%D We don't have to stick to a \TEX\ drawn rule, but
+%D also can use rounded or even fancier shapes, as we will
+%D see later on.
+
+\def\dofilledbox
+ {\bgroup
+ \doifelse{\framedparameter\c!backgroundcorner}\v!rectangular
+ {\dofilledlinedbox}
+ {\ifzeropt\dimexpr\framedparameter\c!backgroundradius\relax % just in case of .x\bodyfontsize
+ \dofilledlinedbox
+ \else
+ \dofilledroundbox
+ \fi}%
+ \egroup}
+
+\def\dophantombox
+ {\hphantom{\dofilledbox}}
+
+\def\dofilledlinedbox
+ {\vrule\!!width\frameddimenwd\!!height\frameddimenht\!!depth\frameddimendp\relax}%
+
+\def\dostrokedroundbox
+ {\doif{\framedparameter\c!frame}\v!on\dodostrokedroundbox}
+
+\def\dodostrokedroundbox
+ {\bgroup
+ \edef\ovalmod{\framedparameter\c!framecorner}%
+ \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
+ \edef\ovalwid{\the\frameddimenwd}%
+ \edef\ovalhei{\the\frameddimenht}%
+ \edef\ovaldep{\the\frameddimendp}%
+ \edef\ovallin{\the\dimexpr\ruledlinewidth}%
+ \edef\ovalrad{\the\dimexpr\framedparameter\c!frameradius}%
+ \let\ovalstr\!!plusone
+ \let\ovalfil\!!zerocount
+ \forcecolorhack
+ \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
+ \egroup}
+
+\def\dofilledroundbox
+ {\bgroup
+ \edef\ovalmod{\framedparameter\c!backgroundcorner}%
+ \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
+ \edef\ovalwid{\the\frameddimenwd}%
+ \edef\ovalhei{\the\frameddimenht}%
+ \edef\ovaldep{\the\frameddimendp}%
+ \edef\ovallin{\the\dimexpr\ruledlinewidth\relax}%
+ \edef\ovalrad{\the\dimexpr\framedparameter\c!backgroundradius\relax}%
+ \let\ovalstr\!!zerocount
+ \let\ovalfil\!!plusone
+ \forcecolorhack
+ \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
+ \egroup}
+
+% a lot of weird corners
+%
+% \startTEXpage
+% \dontleavehmode\framed
+% [corner=0,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {9}{12}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{13}{16}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{17}{20}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{21}{24}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{25}{28}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \stopTEXpage
+
+%D The oval box is drawn using a special macro, depending on
+%D the driver in use.
+
+\def\dograybox % avoid black rules when no gray
+ {\doifelsenothing{\framedparameter\c!backgroundscreen}
+ {\dophantombox}
+ {\raster[\framedparameter\c!backgroundscreen]{\dofilledbox}}}
+
+%D It won't be a surprise that we not only provide gray boxes,
+%D but also colored ones. Here it is:
+
+\def\docolorbox
+ {\hbox{\ifincolor
+ \doifcolorelse{\framedparameter\c!backgroundcolor}
+ {\localcolortrue\color[\framedparameter\c!backgroundcolor]{\dofilledbox}}
+ {\dophantombox}%
+ \else
+ \dophantombox
+ \fi}}
+
+%D \macros
+%D {defineoverlay, doifoverlayelse, overlayoffset,
+%D overlaywidth, overlayheight, overlaydepth,
+%D overlaycolor, overlaylinecolor, overlaylinewidth}
+%D
+%D Before we define the macro that actually takes card of the
+%D backgrounds, we introduce overlays. An overlay is something
+%D that contrary to its name lays {\em under} the text. An
+%D example of an overlay definition is:
+%D
+%D \startbuffer[tmp-1]
+%D \defineoverlay
+%D [fancy]
+%D [{\externalfigure
+%D [mp-cont.502]
+%D [width=\overlaywidth,
+%D height=\overlayheight]}]
+%D \stopbuffer
+%D
+%D \typebuffer[tmp-1]
+%D
+%D That for instance can be uses in:
+%D
+%D \startbuffer[tmp-2]
+%D \framed[backgroundachtergrond=fancy]{How Fancy!}
+%D \framed[backgroundachtergrond=fancy,frame=off]{Even More Fancy!}
+%D \stopbuffer
+%D
+%D and looks like:
+%D
+%D \startlinecorrection
+%D \vbox{\baselineskip24pt\getbuffer[tmp-1]\getbuffer[tmp-2]}
+%D \stoplinecorrection
+%D
+%D The formal definition is:
+%D
+%D \showsetup{defineoverlay}
+%D
+%D This macro's definition is a bit obscure, due the many
+%D non||used arguments and the two step call that enable the
+%D setting of the width, height and depth variables.
+%D Multiple backgrounds are possible and are specified as:
+%D
+%D \starttyping
+%D \framed[background={one,two,three}]{Three backgrounds!}
+%D \stoptyping
+%D
+%D Most drawing packages only know width and height. Therefore
+%D the dimensions have a slightly different meaning here:
+%D
+%D \startitemize[packed]
+%D \item \type{\overlaywidth }: width of the overlay
+%D \item \type{\overlayheight}: height plus depth of the overlay
+%D \item \type{\overlaydepth }: depth of the overlay
+%D \stopitemize
+%D
+%D The resulting box is lowered to the right depth.
+
+\def\overlaywidth {\the\hsize\space} % We preset the variables
+\def\overlayheight {\the\vsize\space} % to some reasonable default
+\let\overlaydepth \!!zeropoint % values. The attributes
+\let\overlayoffset \!!zeropoint % of the frame can be (are)
+\let\overlaycolor \empty % set somewhere else.
+\let\overlaylinewidth \!!zeropoint %
+\let\overlaylinecolor \empty %
+
+%D The next register is used to initialize overlays.
+
+\newtoks\everyoverlay
+
+%D An example of an initialization is the following (overlays
+%D can contain text and be executed under an regime where
+%D interlineskip is off).
+
+\appendtoks \oninterlineskip \to \everyoverlay
+
+\def\defineoverlay
+ {\dodoubleargument\dodefineoverlay}
+
+\def\dodefineoverlay[#1][#2]%
+ {\def\docommand##1{\setvalue{\??ov##1}{\executedefinedoverlay{##1}{#2}}}%
+ \processcommalist[#1]\docommand}
+
+\prependtoks
+ \hsize\overlaywidth
+ \vsize\overlayheight
+\to\everyoverlay
+
+\long\def\executedefinedoverlay#1#2%
+ {\bgroup
+ \edef\overlaywidth {\the\frameddimenwd\space}%
+ \edef\overlayheight{\the\dimexpr\frameddimenht+\frameddimendp\relax\space}%
+ \edef\overlaydepth {\the\frameddimendp\space}%
+ \edef\overlaycolor {\framedparameter\c!backgroundcolor}%
+ %\edef\overlaycorner{\framedparameter\c!backgroundcorner}%
+ %\edef\overlayradius{\framedparameter\c!backgroundradius}%
+ \let\overlayoffset\backgroundoffset % we steal this one
+ \setbox\scratchbox\hbox{\lower\overlaydepth\hbox{\the\everyoverlay#2}}%
+ \setbox\scratchbox\hbox
+ {\hskip-.5\dimexpr\wd\scratchbox-\overlaywidth \relax
+ \raise-.5\dimexpr\ht\scratchbox-\frameddimenht\relax % not overlayheight !
+ \box\scratchbox}%
+ \wd\scratchbox\overlaywidth
+ \ht\scratchbox\overlayheight
+ \dp\scratchbox\overlaydepth
+ \startlayoutcomponent{o:#1}{overlay #1}%
+ \box\scratchbox
+ \stoplayoutcomponent
+ \egroup}
+
+%D The empty case is:
+
+\let\executeoverlay\gobblesevenarguments
+
+%D For testing we provide:
+
+\def\doifoverlayelse#1%
+ {\doifdefinedelse{\??ov#1}}
+
+%D We predefine two already familiar backgrounds:
+
+\setvalue{\??ov\v!screen}{\dograybox }
+\setvalue{\??ov\v!color }{\docolorbox}
+
+% %D After all these preparations, the background macro does no
+% %D bring to many surprises. One has to keep in mind that this
+% %D macro starts up a call chain, depending on the background
+% %D one needs:
+% %D
+% %D \startitemize[packed]
+% %D \item a raster, color or user defined shape
+% %D \item square or round corners
+% %D \item a \TEX\ or driver based method
+% %D \stopitemize
+% %D
+% %D The macro can be extended by adding commands to the token
+% %D list register \type {\everybackgroundbox}. For this
+% %D purpose, the name of the current background is available in
+% %D \type {\currentbackgound}.
+
+%D The content of the box will be (temporary) saved in a box. We
+%D also have an extra box for backgrounds.
+
+\newbox\framebox
+\newbox\extraframebox
+
+\newtoks\everybackgroundbox
+
+\let\currentbackground\empty
+
+% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
+% {\bgroup
+% \def\currentbackground{#1}%
+% \the\everybackgroundbox
+% \setbox\extraframebox\hbox
+% {\vbox{\moveleft\backgroundoffset\hbox{\executeifdefined{\??ov\currentbackground}\donothing}}}%
+% \wd\extraframebox\zeropoint % \backgroundwidth
+% \ht\extraframebox\backgroundheight
+% \dp\extraframebox\backgrounddepth
+% \box\extraframebox % \hskip-\backgroundwidth
+% \egroup}
+
+% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
+% {\bgroup
+% \def\currentbackground{#1}%
+% \ifcsname\??ov\currentbackground\endcsname
+% \the\everybackgroundbox
+% \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
+% \wd\extraframebox\zeropoint % \backgroundwidth
+% \ht\extraframebox\backgroundheight
+% \dp\extraframebox\backgrounddepth
+% \box\extraframebox % \hskip-\backgroundwidth
+% \fi
+% \egroup}
+
+\def\dodobackgroundbox
+ {\bgroup
+ \ifcsname\??ov\currentbackground\endcsname
+ \the\everybackgroundbox
+ \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
+ \wd\extraframebox\zeropoint % \backgroundwidth
+ \ht\extraframebox\backgroundheight
+ \dp\extraframebox\backgrounddepth
+ \box\extraframebox % \hskip-\backgroundwidth
+ \fi
+ \egroup}
+
+\def\dododobackgroundbox#1,#2% #2 gobbles spaces
+ {\edef\currentbackground{#1}%
+ \ifx\currentbackground\s!unknown\else
+ \dodobackgroundbox\expandafter\dododobackgroundbox
+ \fi#2}
+
+\let\backgroundoffset\!!zeropoint
+\let\backgrounddepth \!!zeropoint
+\def\backgroundwidth {\the\hsize}
+\def\backgroundheight{\the\vsize}
+
+% todo: also \def\theforegroundbox{#1}
+
+% \def\dobackgroundbox#1%
+% {\setbox\framebox\vbox
+% {\forgetall
+% \boxmaxdepth\maxdimen
+% \scratchdimen \framedparameter{#1}\relax
+% \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
+% \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
+% \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
+% \edef\backgroundoffset{\the\scratchdimen}%
+% \edef\backgroundwidth {\the\wd\framebox}%
+% \edef\backgroundheight{\the\ht\framebox}%
+% \edef\backgrounddepth {\the\dp\framebox}%
+% %\edef\foregroundbox{\box#1}%
+% \def\foregroundbox% fuzzy but needed hack, this \vss, otherwise
+% {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
+% \edef\component{\framedparameter\c!component}%
+% \hbox to \backgroundwidth % in case 'foreground' is used as overlay
+% {\ifx\component\empty
+% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
+% \else
+% \startlayoutcomponent{b:\component}{\s!background\space\component}%
+% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
+% \stoplayoutcomponent
+% \fi
+% \box\framebox\hss}}}
+
+\def\normalforegroundbox% fuzzy but needed hack, this \vss, otherwise
+ {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
+
+\def\dobackgroundbox#1%
+ {\setbox\framebox\vbox
+ {\forgetall
+ \boxmaxdepth\maxdimen
+ \scratchdimen \framedparameter{#1}\relax
+ \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
+ \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
+ \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
+ \edef\backgroundoffset{\the\scratchdimen}%
+ \edef\backgroundwidth {\the\wd\framebox}%
+ \edef\backgroundheight{\the\ht\framebox}%
+ \edef\backgrounddepth {\the\dp\framebox}%
+ %\edef\foregroundbox{\box#1}%
+ \edef\component{\framedparameter\c!component}%
+ \let\foregroundbox\normalforegroundbox
+ \hbox to \backgroundwidth % in case 'foreground' is used as overlay
+ {\ifx\component\empty
+ \expanded{\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
+ \else
+ \startlayoutcomponent{b:\component}{background \component}%
+ \expanded{\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
+ \stoplayoutcomponent
+ \fi
+ \box\framebox\hss}}}
+
+%D One can explictly insert the foreground box. For that
+%D purpose we introduce the overlay \type {foreground}.
+
+\defineoverlay[\v!foreground][\foregroundbox]
+
+%D We can specify overlays as a comma separated list of
+%D overlays, a sometimes handy feature.
+
+%D Besides backgrounds (overlays) we also need some macros to
+%D draw outlines (ruled borders). Again we have to deal with
+%D square and round corners. The first category can be handled
+%D by \TEX\ itself, the latter one depends on the driver. This
+%D macro also support a negative offset.
+
+\ifx\scratchoffset\undefined \newdimen\scratchoffset \fi
+
+\def\dooutlinebox % we needed to move the color command in order to apply attributes properly
+ {\setbox\framebox\vbox % rules on top of box
+ {\scratchoffset \framedparameter\c!frameoffset\relax
+ \frameddimenwd\dimexpr\wd\framebox+2\scratchoffset\relax
+ \frameddimenht\dimexpr\ht\framebox+ \scratchoffset\relax
+ \frameddimendp\dimexpr\dp\framebox+ \scratchoffset+\framedparameter\c!framedepth\relax
+ \ifdim\frameddimendp<\zeropoint
+ \advance\frameddimenht \frameddimendp
+ \scratchdimen-\frameddimendp
+ \frameddimendp\zeropoint
+ \else
+ \scratchdimen\zeropoint
+ \fi
+ \setbox\extraframebox\hbox
+ {\doifsomething{\framedparameter\c!framecolor}{\color[\framedparameter\c!framecolor]}{\dostrokedbox}}%
+ \setbox\extraframebox\hbox
+ {\raise\scratchdimen\vbox
+ {\moveleft\scratchoffset
+ \box\extraframebox}}%
+ \wd\extraframebox\wd\framebox
+ \ht\extraframebox\ht\framebox
+ \dp\extraframebox\dp\framebox
+ \hbox{\box\framebox\hskip-\wd\extraframebox\box\extraframebox}}}
+
+\def\dostrokedbox
+ {\doifelse{\framedparameter\c!framecorner}\v!rectangular
+ {\dostrokedlinedbox}
+ {\ifzeropt\dimexpr\framedparameter\c!frameradius\relax % just in case of .x\bodyfontsize
+ \dostrokedlinedbox
+ \else
+ \dostrokedroundbox
+ \fi}}
+
+\def\dostrokedlinedbox
+ {\setbox\scratchbox\null
+ \wd\scratchbox\frameddimenwd
+ \ht\scratchbox\frameddimenht
+ \dp\scratchbox\frameddimendp
+ \setbox\scratchbox\vbox \bgroup
+ \csname t\@@frame@@\framedparameter\c!frame\framedparameter\c!topframe \endcsname
+ \hbox \bgroup
+ \csname l\@@frame@@\framedparameter\c!frame\framedparameter\c!leftframe \endcsname
+ \box\scratchbox
+ \csname r\@@frame@@\framedparameter\c!frame\framedparameter\c!rightframe \endcsname
+ \egroup
+ \csname b\@@frame@@\framedparameter\c!frame\framedparameter\c!bottomframe\endcsname
+ \egroup
+ \wd\scratchbox\frameddimenwd
+ \ht\scratchbox\frameddimenht
+ \dp\scratchbox\frameddimendp
+ \box\scratchbox}
+
+\def\@@frame@@{@@frame@@}
+
+% \setvalue{t\@@frame@@\v!on \v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{t\@@frame@@\v!off\v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{t\@@frame@@\v!on }{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!on }{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!on \v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!off\v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!on }{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!on }{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+
+\def\@@frame@@trule{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+\def\@@frame@@brule{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+\def\@@frame@@rrule{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+\def\@@frame@@lrule{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+
+\letvalue{t\@@frame@@\v!on \v!on}\@@frame@@trule
+\letvalue{t\@@frame@@\v!off\v!on}\@@frame@@trule
+\letvalue{t\@@frame@@\v!on }\@@frame@@trule
+
+\letvalue{b\@@frame@@\v!on \v!on}\@@frame@@brule
+\letvalue{b\@@frame@@\v!off\v!on}\@@frame@@brule
+\letvalue{b\@@frame@@\v!on }\@@frame@@brule
+
+\letvalue{l\@@frame@@\v!on \v!on}\@@frame@@lrule
+\letvalue{l\@@frame@@\v!off\v!on}\@@frame@@lrule
+\letvalue{l\@@frame@@\v!on }\@@frame@@lrule
+
+\letvalue{r\@@frame@@\v!on \v!on}\@@frame@@rrule
+\letvalue{r\@@frame@@\v!off\v!on}\@@frame@@rrule
+\letvalue{r\@@frame@@\v!on }\@@frame@@rrule
+
+% no overlapping rules
+
+\def\@@frame@@trules{\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}\nointerlineskip\kern-\ruledlinewidth}
+\def\@@frame@@brules{\kern-\ruledlinewidth\nointerlineskip\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}}
+\def\@@frame@@rrules{\kern-\ruledlinewidth\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth}
+\def\@@frame@@lrules{\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth\kern-\ruledlinewidth}
+
+% small is relatively new
+
+\letvalue{t\@@frame@@\v!small\v!small}\@@frame@@trules
+\letvalue{t\@@frame@@\v!off \v!small}\@@frame@@trules
+\letvalue{t\@@frame@@\v!small }\@@frame@@trules
+
+\letvalue{b\@@frame@@\v!small\v!small}\@@frame@@brules
+\letvalue{b\@@frame@@\v!off \v!small}\@@frame@@brules
+\letvalue{b\@@frame@@\v!small }\@@frame@@brules
+
+\letvalue{l\@@frame@@\v!small\v!small}\@@frame@@lrules
+\letvalue{l\@@frame@@\v!off \v!small}\@@frame@@lrules
+\letvalue{l\@@frame@@\v!small }\@@frame@@lrules
+
+\letvalue{r\@@frame@@\v!small\v!small}\@@frame@@rrules
+\letvalue{r\@@frame@@\v!off \v!small}\@@frame@@rrules
+\letvalue{r\@@frame@@\v!small }\@@frame@@rrules
+
+%D I condidered using the low level support command
+%D \type{\ruledhbox}, but this would slow down processing by a
+%D factor~3.
+
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=on,leftframe=on,topframe=on,bottomframe=on]
+% {}
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=small]
+% {}
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=on]
+% {}
+
+%D The next few macros are probably the most misused ones in
+%D \CONTEXT. They deal with putting rules around boxes, provide
+%D backgrounds, offer alignment features, and some more. We
+%D start with defining some booleans. These give an impression
+%D of what we are going to take into account.
+
+% todo: chardefs
+
+\newif\ifboxhasoffset
+\newif\ifboxhaswidth
+\newif\ifboxhasheight
+\newif\ifboxhasformat
+\newif\ifboxhasstrut
+\newif\ifboxisoverlaid
+\newif\ifboxhasframe
+\newif\ifdelayedstrut
+
+%D We also need a few \DIMENSIONS:
+
+\newdimen\@@localoffset
+\newdimen\@@globalwidth
+
+%D \macros
+%D {framed, setupframed}
+%D
+%D Ruled boxes are typeset using \type{\framed}. This command
+%D is quite versatile and, although some users will probably
+%D seldom use it, one cannot overlook its features.
+%D
+%D \showsetup{setupframed}
+%D \showsetup{framed}
+%D
+%D This general macro is a special version of an even more
+%D general case, that can easily be linked into other macros
+%D that need some kind of framing. The local version is called
+%D with an extra parameter: the variable identifier. The reason
+%D for passing this identifier between brackets lays in the
+%D mere fact that this way we can use the optional argument
+%D grabbers.
+
+\def\defaultframeoffset{.25ex}
+
+\unexpanded\def\framed
+ {\bgroup
+ \copylocalframed[\??ol][\??oi]% == \presetlocalframed[\??ol]%
+ \dodoubleempty\startlocalframed[\??ol]}
+
+\def\presetlocalframed[#1]%
+ {\copylocalframed[#1][\??oi]}
+
+% \def\copylocalframed[#1]#2[#3]%
+% {\copyparameters[#1][#3]%
+% [\c!width,\c!height,\c!radius,\c!corner,\c!depth,\c!offset,%
+% \c!autowidth,\c!empty,\c!component,\c!orientation,\c!lines,%
+% \c!align,\c!bottom,\c!top,\c!strut,\c!autostrut,\c!location,\c!setups,\c!extras,%
+% \c!foregroundstyle,\c!foregroundcolor,%
+% \c!background,\c!backgroundoffset,\c!backgroundcorner,\c!backgroundradius,\c!backgrounddepth,\c!backgroundcolor,\c!backgroundscreen,%
+% \c!frame,\c!frameoffset,\c!framecorner,\c!frameradius,\c!framedepth,\c!framecolor,\c!rulethickness,%
+% \c!topframe,\c!bottomframe,\c!leftframe,\c!rightframe]}
+
+% since framed is used all over the place, we have a (small) speedup)
+
+\def\copylocalframed[#1]#2[#3]%
+ {\edef\copiedfrom{#1}\edef\copiedto{#3}%
+ \docopyvalue\copiedfrom\copiedto\c!width
+ \docopyvalue\copiedfrom\copiedto\c!height
+ \docopyvalue\copiedfrom\copiedto\c!autowidth
+ \docopyvalue\copiedfrom\copiedto\c!offset
+ \docopyvalue\copiedfrom\copiedto\c!empty
+ \docopyvalue\copiedfrom\copiedto\c!rulethickness
+ \docopyvalue\copiedfrom\copiedto\c!radius
+ \docopyvalue\copiedfrom\copiedto\c!corner
+ \docopyvalue\copiedfrom\copiedto\c!depth
+ \docopyvalue\copiedfrom\copiedto\c!frame
+ \docopyvalue\copiedfrom\copiedto\c!framecolor
+ \docopyvalue\copiedfrom\copiedto\c!foregroundstyle
+ \docopyvalue\copiedfrom\copiedto\c!foregroundcolor
+ \docopyvalue\copiedfrom\copiedto\c!lines
+ \docopyvalue\copiedfrom\copiedto\c!orientation
+ \docopyvalue\copiedfrom\copiedto\c!topframe
+ \docopyvalue\copiedfrom\copiedto\c!bottomframe
+ \docopyvalue\copiedfrom\copiedto\c!leftframe
+ \docopyvalue\copiedfrom\copiedto\c!rightframe
+ \docopyvalue\copiedfrom\copiedto\c!rulethickness
+ \docopyvalue\copiedfrom\copiedto\c!frameoffset
+ \docopyvalue\copiedfrom\copiedto\c!background
+ \docopyvalue\copiedfrom\copiedto\c!component
+ \docopyvalue\copiedfrom\copiedto\c!backgroundoffset
+ \docopyvalue\copiedfrom\copiedto\c!backgroundscreen
+ \docopyvalue\copiedfrom\copiedto\c!backgroundcolor
+ \docopyvalue\copiedfrom\copiedto\c!align
+ \docopyvalue\copiedfrom\copiedto\c!bottom
+ \docopyvalue\copiedfrom\copiedto\c!top
+ \docopyvalue\copiedfrom\copiedto\c!strut
+ \docopyvalue\copiedfrom\copiedto\c!autostrut
+ \docopyvalue\copiedfrom\copiedto\c!location
+ \docopyvalue\copiedfrom\copiedto\c!component
+ \docopyvalue\copiedfrom\copiedto\c!extras
+ \docopyvalue\copiedfrom\copiedto\c!setups
+ \docopyvalue\copiedfrom\copiedto\c!backgroundradius
+ \docopyvalue\copiedfrom\copiedto\c!backgroundcorner
+ \docopyvalue\copiedfrom\copiedto\c!backgrounddepth
+ \docopyvalue\copiedfrom\copiedto\c!frameradius
+ \docopyvalue\copiedfrom\copiedto\c!framecorner
+ \docopyvalue\copiedfrom\copiedto\c!framedepth}
+
+\def\setupframed
+ {\dodoubleempty\dosetupframed}
+
+\def\dosetupframed
+ {\ifsecondargument
+ \@EA\dodoublesetupframed
+ \else
+ \@EA\dosinglesetupframed
+ \fi}
+
+\def\dosinglesetupframed[#1][#2]%
+ {\getparameters[\??oi][#1]}
+
+\def\dodoublesetupframed[#1][#2]%
+ {\bgroup
+ \let\dodoubleempty\empty
+ \def\doframed[##1]{\gdef\globalredefinedframed{\dodoubleempty\doframed[##1,#2]}}%
+ \getvalue{#1}%
+ \egroup
+ \letvalue{#1}\globalredefinedframed}
+
+%D \startbuffer
+%D \setupframed [framecolor=yellow] \framed{A}
+%D \defineframed[myframed] [framecolor=blue] \myframed{B}
+%D \setupframed [myframed] [framecolor=red] \myframed{C}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \presetlocalframed[myframed]
+%D \setuplocalframed[myframed][width=4cm,height=2cm]
+%D \localframed[myframed][framecolor=green]{oeps}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {ifinframed}
+%D
+%D The normal case first presets all parameters and next starts
+%D looking for the user supplied ones. The first step is
+%D omitted in the local case, because these are preset at
+%D declaration time and keep their values unless explictly
+%D changed. By presetting the variables everytime the normal
+%D command is called, we can use this command nested, without
+%D the unwanted side effect of inheritance. The boolean is
+%D used to speed up the color stack.
+
+\newif\ifinframed
+
+\def\localframed
+ {\bgroup
+ \dodoubleempty\startlocalframed}
+
+%D The next one is faster on multiple backgrounds per page. No
+%D dimensions can be set, only frames and backgrounds.
+
+\def\fastlocalframed[#1]#2[#3]#4% 3-4
+ {\bgroup
+ \inframedtrue
+ \edef\@@framed{#1}%
+ % more bytes
+ % \scratchdimen\framedparameter\c!frameoffset
+ % \setevalue{\@@framed\c!frameoffset}{\the\scratchdimen}%
+ % \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
+ % {\scratchdimen\framedparameter\c!backgroundoffset
+ % \setevalue{\@@framed\c!backgroundoffset}{\the\scratchdimen}}%
+ % less bytes
+ \@EA\freezedimenmacro\csname\@@framed\c!frameoffset\endcsname
+ \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
+ {\@EA\freezedimenmacro\csname\@@framed\c!backgroundoffset\endcsname}%
+ % so far
+ \setbox\framebox\hbox{#4}%
+ \getparameters[\@@framed][#3]% no \expanded !
+ % no, better in calling macro
+ %
+ % \edef\doframedsetups{\framedparameter\c!setups}%
+ % \ifx\doframedsetups\empty\else
+ % \edef\doframedsetups{\noexpand\setups[\doframedsetups]}%
+ % \fi
+ \removeframedboxdepth
+ \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
+ \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
+ \edef\overlaylinecolor{\framedparameter\c!framecolor}%
+ \edef\overlaylinewidth{\the\ruledlinewidth}%
+ \edef\@@localframing {\framedparameter\c!frame}%
+ \ifx\@@localframing\v!overlay \else \ifx\@@localframing\v!none \else
+ \edef\framedrulethickness{\framedparameter\c!rulethickness}%
+ \ifx\framedrulethickness\empty\else
+ \ruledlinewidth\framedrulethickness\relax
+ \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
+ \fi
+ \dooutlinebox % real or invisible frame
+ \fi \fi
+ \edef\framedbackground{\framedparameter\c!background}%
+ \ifx\framedbackground\empty\else\dobackedbox\fi
+ \restoreframedboxdepth
+ \box\framebox
+ \egroup}
+
+%D Before we go into details, we present (and implement) the
+%D main framing routine. I saw no real reason for splitting the
+%D next two macros into smaller pieces. The content will be
+%D collected in a horizontal or vertical box with fixed or free
+%D dimensions and specific settings concerning aligment and
+%D offsets.
+%D
+%D In the first few lines, we pre||expand the frame and
+%D background offsets. We do so, because the can be defined in
+%D terms of the main offset. However, see for instance page
+%D backgrounds, when \type {#2} sets the offset to \type
+%D {overlay}, both offsets become invalid.
+%D
+%D Because it is used so often the he next macro is (and
+%D looks) rather optimized.
+
+\let\postprocessframebox\relax
+
+\let\@@framed\s!unknown
+
+\def\framedparameter#1%
+ {\csname\@@framed#1\endcsname}
+
+\newdimen\!!framedwidth
+\newdimen\!!framedheight
+
+\def\startlocalframed[#1][#2]%
+ {\bgroup
+ \inframedtrue
+ \edef\@@framed{#1}%
+ % this piece of pre expansion is needed (sometimes used in frameoffset)
+ % \doifvaluesomething{\@@framed\c!rulethickness} % obsolete
+ % {\ruledlinewidth\getvalue{\@@framed\c!rulethickness}}% obsolete
+ % this piece of pre expansion is needed (sometimes used circular)
+ \setevalue{\@@framed\c!frameoffset}{\the\dimexpr\framedparameter\c!frameoffset\relax}%
+ \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
+ {\setevalue{\@@framed\c!backgroundoffset}{\the\dimexpr\framedparameter\c!backgroundoffset\relax}}%
+ % to prevent deadlock in case of self refering
+ \ifsecondargument % faster
+ \getparameters[\@@framed][#2]% here !
+ \fi
+ % new, experimental dirty hook
+ \framedparameter\c!extras
+ % to get the right spacing
+ \doifvaluesomething{\@@framed\c!foregroundstyle}
+ {\@EA\doconvertfont\csname\@@framed\c!foregroundstyle\endcsname\empty}%
+ % beware, both the frame and background offset can be overruled
+ %
+ \edef\doframedsetups{\framedparameter\c!setups}%
+ \ifx\doframedsetups\empty\else
+ \edef\doframedsetups{\noexpand\setups[\doframedsetups]}%
+ \fi
+ % the next macros are visible
+ \edef\localoffset{\framedparameter\c!offset}%
+ \edef\localwidth {\framedparameter\c!width}%
+ \edef\localheight{\framedparameter\c!height}%
+ \edef\localformat{\framedparameter\c!align}%
+ \edef\localstrut {\framedparameter\c!strut}%
+ % these are not
+ \edef\@@localautostrut {\framedparameter\c!autostrut}%
+ \edef\@@localframing {\framedparameter\c!frame}%
+ \edef\@@locallocation {\framedparameter\c!location}%
+ \edef\@@localorientation{\framedparameter\c!orientation}%
+ %
+ \edef\@@localautowidth {\framedparameter\c!autowidth}%
+ %
+ \ifx\@@localframing\v!overlay % no frame, no offset, no framewidth
+ \boxhasframefalse
+ \let\localoffset\v!overlay
+ \else\ifx\@@localframing\v!none % no frame, no framewidth
+ \boxhasframefalse
+ \else
+ \boxhasframetrue
+ \fi\fi
+ \ifboxhasframe
+ \edef\framedrulethickness{\framedparameter\c!rulethickness}%
+ \ifx\framedrulethickness\empty\else
+ \ruledlinewidth\framedrulethickness\relax
+ \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
+ \fi
+ \else
+ \ruledlinewidth\zeropoint
+ \fi
+ \ifx\localformat\empty
+ \boxhasformatfalse
+ \else
+ \boxhasformattrue
+ \dosetraggedcommand\localformat
+ \edef\dobeforeframedbox{\raggedtopcommand\framedparameter\c!top}%
+ \edef\doafterframedbox {\framedparameter\c!bottom\raggedbottomcommand}%
+ \fi
+ \ifx\localoffset\v!none
+ \boxhasoffsetfalse
+ \boxhasstrutfalse
+ \boxisoverlaidfalse
+ \@@localoffset\ruledlinewidth
+ \else\ifx\localoffset\v!overlay
+ % \ifx\@@localframing\v!no \boxhasframefalse \fi % test first
+ \boxhasoffsetfalse
+ \boxhasstrutfalse
+ \boxisoverlaidtrue
+ \@@localoffset\zeropoint
+ \else
+ \boxhasoffsettrue
+ \boxhasstruttrue
+ \boxisoverlaidfalse
+ \ifx\localoffset\v!default % new per 2-6-2000
+ \let\localoffset\defaultframeoffset
+ \letvalue{\@@framed\c!offset}\defaultframeoffset
+ \else
+ \let\defaultframeoffset\localoffset
+ \fi
+ \@@localoffset\dimexpr\localoffset+\ruledlinewidth\relax
+ \fi\fi
+ \!!framedheight\zeropoint
+ \!!framedwidth \zeropoint
+ \ifx\localwidth\v!fit
+ \ifboxhasformat
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else
+ \boxhaswidthfalse
+ \fi
+ \else\ifx\localwidth\v!fixed % equals \v!fit but no shapebox
+ \ifboxhasformat
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else
+ \boxhaswidthfalse
+ \fi
+ \else\ifx\localwidth\v!broad
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else\ifx\localwidth\v!local
+ \boxhaswidthtrue
+ \setlocalhsize
+ \!!framedwidth\localhsize
+ \else
+ \boxhaswidthtrue
+ \!!framedwidth\localwidth
+ \fi\fi\fi\fi
+ \ifx\localheight\v!fit
+ \boxhasheightfalse % no longer: \boxhasstrutfalse
+ \else\ifx\localheight\v!broad
+ \boxhasheightfalse
+ \else
+ \boxhasheighttrue
+ \!!framedheight\localheight
+ \fi\fi
+ \ifboxhasheight
+ % obey user set height, also downward compatible
+ \else
+ \doifvaluesomething{\@@framed\c!lines}
+ {\ifcase\framedparameter\c!lines\else
+ \!!framedheight\framedparameter\c!lines\lineheight
+ \edef\localheight{\the\!!framedheight}%
+ \boxhasheighttrue
+ \fi}%
+ \fi
+ % this is now an option: width=local
+ %
+ % \ifdim\!!framedwidth=\hsize
+ % \parindent\zeropoint
+ % \setlocalhsize
+ % \!!framedwidth\localhsize
+ % \fi
+ % i.e. disable (colsetbackgroundproblemintechniek)
+ \advance\!!framedwidth -2\@@localoffset
+ \advance\!!framedheight -2\@@localoffset
+ \ifx\localstrut\v!no
+ \boxhasstrutfalse
+ \else\ifx\localstrut\v!global
+ \setstrut
+ \else\ifx\localstrut\v!local
+ \setfontstrut
+ \else
+ \setstrut
+ \fi\fi\fi
+ \ifboxhasstrut
+ \let\localbegstrut\begstrut
+ \let\localendstrut\endstrut
+ \let\localstrut \strut
+ \else
+ \let\localbegstrut\pseudobegstrut % was: \relax
+ \let\localendstrut\pseudoendstrut % was: \relax
+ \let\localstrut \pseudostrut % was: \relax
+ %\ifboxhasheight\ifdim\!!framedheight<\strutht % saveguard
+ % \let\localbegstrut\relax % but not that
+ % \let\localstrut \relax % save after all
+ %\fi\fi
+ \fi
+ \ifx\@@localautostrut\v!yes
+ \let\delayedbegstrut\relax
+ \let\delayedendstrut\relax
+ \let\delayedstrut \relax
+ \else
+ \let\delayedbegstrut\localbegstrut
+ \let\delayedendstrut\localendstrut
+ \let\delayedstrut \localstrut
+ \let\localbegstrut \relax
+ \let\localendstrut \relax
+ \let\localstrut \relax
+ \fi
+ \ifboxhasheight
+ \let\\\vboxednewline
+ \ifboxhaswidth
+ \let\hairline\vboxedhairline
+ \ifboxhasformat
+ \let\next\doformatboxSomeFormat
+ \else
+ \let\next\doformatboxNoFormat
+ \fi
+ \else
+ \let\hairline\hboxedhairline
+ \ifboxhasformat
+ \let\next\doformatboxHeight
+ \else
+ \let\next\doformatboxVSize
+ \fi
+ \fi
+ \else
+ \ifboxhaswidth
+ \ifboxhasformat
+ \let\hairline\vboxedhairline
+ \let\\\vboxednewline
+ \let\next\doformatboxWidth
+ \else
+ \let\hairline\hboxedhairline
+ \let\\\hboxednewline
+ \let\next\doformatboxHSize
+ \fi
+ \else
+ \let\hairline\hboxedhairline
+ \let\\\hboxednewline
+ \let\next\doformatboxNoSize
+ \fi
+ \fi
+ \edef\framedwidth % a new feature, visible for user
+ {\ifdim\!!framedwidth >\zeropoint\the\!!framedwidth \else\zeropoint\fi}%
+ \edef\framedheight% a new feature, visible for user
+ {\ifdim\!!framedheight>\zeropoint\the\!!framedheight\else\zeropoint\fi}%
+ % we need to register the (outer) color
+ \startregistercolor[\framedparameter\c!foregroundcolor]%
+ % first alternative
+ %\def\dowithframedbox%
+ % {\let\postprocessframebox\relax %new
+ % \aftergroup\stoplocalframed}%
+ % \afterassignment\dowithframedbox
+ % \setbox\framebox=\next}
+ % second alternative
+ %\dowithnextbox
+ % {\setbox\framebox\flushnextbox
+ % \let\postprocessframebox\relax %new
+ % \stoplocalframed}
+ % \next}
+ \@@startframedorientation
+ \afterassignment\dodowithframebox
+ \setbox\framebox\next}
+
+\def\dowithframebox
+ {% moved : \let\postprocessframebox\relax
+ \stoplocalframed}
+
+\def\dodowithframebox
+ {\aftergroup\dowithframebox}
+
+\let\doafterframedbox \relax
+\let\dobeforeframedbox\relax
+
+%D Carefull analysis of this macro will learn us that not all
+%D branches in the last conditionals can be encountered, that
+%D is, some assignments to \type{\next} will never occur.
+%D Nevertheless we implement the whole scheme, if not for
+%D future extensions.
+
+%D \macros
+%D {ifreshapeframebox}
+%D
+%D The last few lines tell what to do after the content of the
+%D box is collected and passed to the next macro. In the case
+%D of a fixed width and centered alignment, the content is
+%D evaluated and used to determine the most natural width. The
+%D rest of the code deals with backgrounds and frames.
+
+\newif\ifreshapeframebox \reshapeframeboxtrue
+
+%D Beware: setting \type {top} and \type {bottom} to nothing, may
+%D result in a frame that is larger that the given height! try:
+%D
+%D \starttyping
+%D \framed
+%D [height=3cm,top=,bottom=,offset=overlay]
+%D {\strut test \shapefill \strut test}
+%D \stoptyping
+%D
+%D This is intended behaviour and not a bug! One can always set
+%D
+%D \starttyping
+%D ...,bottom=\kern0pt,...
+%D \stoptyping
+
+\def\stoplocalframed
+ {\dontshowcomposition
+ \@@stopframedorientation % hm, wrong place ! should rotate the result (after reshape)
+ \stopregistercolor
+ \handleframedlocator\c!before\@@locallocation
+ \ifboxhasformat
+ \ifx\@@localautowidth\v!force
+ \ifreshapeframebox\doreshapeframedbox\fi
+ \boxhaswidthfalse
+ \else
+ \ifx\localwidth\v!fit
+ \ifx\@@localautowidth\v!yes
+ \ifreshapeframebox\doreshapeframedbox\fi
+ \fi
+ \boxhaswidthfalse
+ \else\ifx\localwidth\v!fixed
+ \boxhaswidthfalse
+ \else
+ \resetshapeframebox
+ \fi\fi
+ \fi
+ \else
+ \resetshapeframebox
+ \fi
+ \ifboxhaswidth
+ \wd\framebox\!!framedwidth
+ \fi
+ \ifboxhasheight
+ \ht\framebox\!!framedheight
+ \fi
+ \doifvalue{\@@framed\c!empty}\v!yes
+ {\setbox\scratchbox\null
+ \wd\scratchbox\wd\framebox
+ \ht\scratchbox\ht\framebox
+ \dp\scratchbox\dp\framebox
+ \setbox\framebox\box\scratchbox}%
+ \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
+ \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
+ \ifboxhasoffset
+ \dooffsetframebox
+ \fi
+ \ifboxisoverlaid \else
+ \dolocateframebox
+ \fi
+ \ifx\postprocessframebox\relax \else
+ \let\next\postprocessframebox
+ \let\postprocessframebox\relax % prevent nesting
+ \next\framebox
+ \fi
+ \edef\overlaylinecolor{\framedparameter\c!framecolor}%
+ \edef\overlaylinewidth{\the\ruledlinewidth}% \@@...
+ \ifboxhasframe % real or invisible frame
+ \dooutlinebox
+ \fi
+ \edef\framedbackground{\framedparameter\c!background}%
+ \ifx\framedbackground\empty\else\dobackedbox\fi
+ \handleframedlocator\c!after\@@locallocation
+ \box\framebox
+ \egroup
+ \egroup}
+
+\def\installframedlocator#1#2#3%
+ {\setvalue{\??ol:\c!location:\c!before:#1}{#2}%
+ \setvalue{\??ol:\c!location:\c!after :#1}{#3}}
+
+\def\handleframedlocator#1#2%
+ {\getvalue{\??ol:\c!location:#1:#2}}
+
+\def\doprelocframedbox#1%
+ {\scratchdimen\dimexpr#1+\ruledlinewidth\relax
+ \ifboxhasoffset
+ \advance\scratchdimen \framedparameter\c!offset
+ \fi
+ \scratchskip\dimexpr\ht\framebox-\scratchdimen\relax}
+
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
+% \framed[width=2cm,align=middle,location=depth] {location\\equals\\depth}
+% \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
+% B}
+% \vskip2cm
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=low] {location\\equals\\low}
+% \framed[width=2cm,align=middle,location=line] {location\\equals\\line}
+% \framed[width=2cm,align=middle,location=high] {location\\equals\\high}
+% B}
+% \vskip2cm
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=top] {location\\equals\\top}
+% \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
+% \framed[width=2cm,align=middle,location=lohi] {location\\equals\\lohi}
+% \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
+% B}
+
+\installframedlocator \v!hanging % best with strut=no
+ {}
+ {\dp\framebox\ht\framebox
+ \ht\framebox\zeropoint}
+
+\installframedlocator \v!depth
+ {}
+ {\ht\framebox\dimexpr\ht\framebox-\strutdp\relax
+ \dp\framebox\strutdp
+ \box\framebox}
+
+\installframedlocator \v!height
+ {}
+ {\dp\framebox\dimexpr\ht\framebox-\strutht\relax
+ \ht\framebox\strutht
+ \box\framebox}
+
+\installframedlocator \v!high
+ {}
+ {\doprelocframedbox\strutht
+ \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!line
+ {}
+ {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}%
+ \ht\framebox.5\lineheight
+ \dp\framebox.5\lineheight
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!low
+ {}
+ {\doprelocframedbox\strutdp
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \box\framebox}
+
+\installframedlocator \v!top
+ {}
+ {\doprelocframedbox\strutht
+ \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
+ \ht\framebox\scratchdimen
+ \dp\framebox\scratchskip
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!middle
+ {}
+ {\scratchdimen.5\ht\framebox
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\scratchdimen
+ \dp\framebox\scratchdimen
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!lohi
+ {\handleframedlocator\c!before\v!middle}
+ {\handleframedlocator\c!after \v!middle}
+
+\installframedlocator \v!bottom
+ {}
+ {\doprelocframedbox\strutdp
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\scratchskip
+ \dp\framebox\scratchdimen
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!keep % retains height/depth
+ {\removeframedboxdepth}
+ {\restoreframedboxdepth}
+
+% also used in fastlocalframed
+
+\newdimen\originalframedwd
+\newdimen\originalframedht
+\newdimen\originalframeddp
+
+\def\removeframedboxdepth
+ {\originalframedwd\wd\framebox
+ \originalframedht\ht\framebox
+ \originalframeddp\dp\framebox
+ \ifzeropt\originalframeddp\else\setbox\framebox\hbox{\raise\originalframeddp\box\framebox}\fi
+ \wd\framebox\originalframedwd
+ \ht\framebox\dimexpr\originalframedht+\originalframeddp\relax
+ \dp\framebox\zeropoint}
+
+\def\restoreframedboxdepth
+ {\ifzeropt\originalframeddp\else\setbox\framebox\hbox{\lower\originalframeddp\box\framebox}\fi
+ \wd\framebox\originalframedwd
+ \ht\framebox\originalframedht
+ \dp\framebox\originalframeddp}
+
+% \let\@@startframedorientation\relax
+% \let\@@stopframedorientation \relax
+
+% \framed[width=12cm,height=3cm,orientation=0]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=90]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=180]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=270]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-90]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-180]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-270]{\input ward\relax}
+
+\def\@@startframedorientation
+ {\let\@@stopframedorientation \relax
+ \ifx\@@localorientation\empty\else
+ \ifcase\@@localorientation\else
+ \scratchcounter\@@localorientation
+ \divide\scratchcounter\plustwo
+ \ifodd\scratchcounter
+ \swapmacros\framedwidth \framedheight
+ \swapmacros\localwidth \localheight
+ \swapdimens\!!framedheight\!!framedwidth
+ \def\@@stopframedorientation{\@@dostopframedorientation\plusone}%
+ \else
+ \def\@@stopframedorientation{\@@dostopframedorientation\zerocount}%
+ \fi
+ \fi
+ \fi}
+
+\def\@@dostopframedorientation#1%
+ {\ifcase#1\else
+ \swapmacros\framedwidth \framedheight
+ \swapmacros\localwidth \localheight
+ \swapdimens\!!framedheight\!!framedwidth
+ \fi
+ \setbox\framebox\hbox{\dorotatebox\@@localorientation\hbox{\box\framebox}}}
+
+%D The last conditional takes care of the special situation of
+%D in||line \inframed[height=3cm]{framed} boxes. Such boxes have
+%D to be \inframed{aligned} with the running text.
+
+\def\doinframed[#1]% we could omit #1] but readibility ...
+ {\framed[\c!location=\v!low,#1]}
+
+\unexpanded\def\inframed
+ {\dosingleempty\doinframed}
+
+%D When we set \type{empty} to \type{yes}, we get
+%D ourselves a frame and/or background, but no content, so
+%D actually we have a sort of phantom framed box.
+
+%D Because color marks and specials can interfere with
+%D spacing, we provide a way to specify a foregroundcolor.
+
+\def\docolorframebox
+ {\doifvaluesomething{\@@framed\c!foregroundcolor}
+ {\doifcolorelse{\framedparameter\c!foregroundcolor}
+ {\setbox\framebox\hbox
+ {\localcolortrue
+ \color[\framedparameter\c!foregroundcolor]{\box\framebox}}}
+ {}}}
+
+%D \macros
+%D {mframed, minframed}
+%D
+%D When Tobias asked how to frame mathematical elements in
+%D formulas, Taco's posted the next macro:
+%D
+%D \starttyping
+%D \def\mframed#1%
+%D {\relax
+%D \ifmmode
+%D \vcenter{\hbox{\framed{$\ifinner\else\displaystyle\fi#1$}}}%
+%D \else
+%D \framed{$#1$}%
+%D \fi}
+%D \stoptyping
+%D
+%D Because \type {\ifinner} does not (always) reports what
+%D one would expect, we move the test to the outer level. We
+%D also want to pass arguments,
+%D
+%D \starttyping
+%D \def\mframed%
+%D {\dosingleempty\domframed}
+%D
+%D \def\domframed[#1]#2% % tzt \dowithnextmathbox ?
+%D {\relax
+%D \ifmmode
+%D \ifinner
+%D \inframed[#1]{$#2$}%
+%D \else
+%D \vcenter{\hbox{\framed[#1]{$\displaystyle#2$}}}%
+%D \fi
+%D \else
+%D \inframed[#1]{$#2$}%
+%D \fi}
+%D \stoptyping
+%D
+%D Still better is the next alternative, if only because it
+%D takes care of setting the super- and subscripts styles
+
+\ifx\restoremathstyle\undefined \let\restoremathstyle\relax \fi
+
+\def\domframed[#1][#2]#3%
+ {\begingroup
+ \ifmmode
+ \ifinner
+ \let\mframedstyle\restoremathstyle
+ \else
+ \let\mframedstyle\displaystyle
+ \fi
+ \else
+ \let\mframedstyle\restoremathstyle
+ \fi
+ #1\ifdone
+ \def\normalstrut{$\mframedstyle\vphantom($}%
+ \framed
+ [\c!frameoffset=\@@oioffset,\c!offset=\v!overlay,#2]
+ {$\mframedstyle#3$}%
+ \else
+ \inframed
+ [#2]
+ {$\mframedstyle#3$}%
+ \fi
+ \endgroup}
+
+\def\mframed
+ {\dodoubleempty\domframed[\donetrue]}
+
+\def\inmframed
+ {\dodoubleempty\domframed[\donefalse]}
+
+%D So instead of the rather versatile \type {\framed}, we ue
+%D the \type {\mframed}.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y^{z_z}
+%D x \times \inmframed{y} \times y^{z_z}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D However, we got into troubles when we want to nest sub- and
+%D superscripts, like in
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y^{\mframed{z}_{\mframed{z}}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D Therefore, we can best use \type {\super} and \type {\suber}
+%D instead of \type {^} and \type {_}. Both commands take care
+%D of proper font switching.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y\super{\mframed{z}\suber{\mframed{z}}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D As usual, one can specify in what way the text should be
+%D framed. One should be aware of the fact that, inorder to
+%D preserve the proper spacing, the \type {offset} is set to
+%D \type {overlay} and \type {frameoffset} is used used
+%D instead.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times y\super{\mframed[framecolor=red]{z}\suber{z}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D For inline use, we also provide the \type {\inmframed}
+%D alternative: we want $x \times \inmframed{y}$ in inline
+%D math, right?
+
+%D This previous framing macros needs a lot of alternatives for
+%D putting rules around boxes, inserting offsets and aligning
+%D text. Each step is handled by separate macros.
+
+\def\dowidenframebox#1%
+ {\setbox\framebox\vbox
+ {\kern#1\hbox{\kern#1\box\framebox\kern#1}\kern#1}}
+
+\def\dooffsetframebox{\dowidenframebox\localoffset}
+\def\dolocateframebox{\dowidenframebox\ruledlinewidth}
+
+%D Let's hope that the next few examples show us enough of
+%D what needs to be done by the auxiliary macros.
+%D
+%D \startbuffer
+%D \framed[height=1cm,offset=.5cm] {rule based learning}
+%D \framed[height=1cm,offset=0cm] {rule based learning}
+%D \framed[height=1cm,offset=none] {rule based learning}
+%D \framed[height=1cm,offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[offset=.5cm] {rule based learning}
+%D \framed[offset=0cm] {rule based learning}
+%D \framed[offset=none] {rule based learning}
+%D \framed[offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[strut=nee,offset=.5cm] {rule based learning}
+%D \framed[strut=nee,offset=0cm] {rule based learning}
+%D \framed[strut=nee,offset=none] {rule based learning}
+%D \framed[strut=nee,offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[width=3cm,align=left] {rule\\based\\learning}
+%D \framed[width=3cm,align=middle] {rule\\based\\learning}
+%D \framed[width=3cm,align=right] {rule\\based\\learning}
+%D \framed[width=fit,align=middle] {rule\\based\\learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\dontcomplain\getbuffer}
+%D \stoplinecorrection
+%D
+%D So now we're ready for the complicated stuff. We distinguish
+%D between borders with straight lines and those with round
+%D corners. When using the first alternative it is possible to
+%D turn off one or more lines. More fancy shapes are also
+%D possible by specifying dedicated backgrounds. Turning lines
+%D on and off is implemented as efficient as possible and as a
+%D result is interface language dependant. This next
+%D implementation evolved from simpler ones. It puts for
+%D instance the rules on top of the content and provides
+%D additional offset capabilities. The lot of calls to other
+%D macros makes this mechanism not that easy to comprehend.
+
+%D Getting the backgrounds right takes less code. Again we
+%D have to take care of additional offsets.
+
+\def\dobackedbox
+ {\doifelsevalue{\@@framed\c!backgroundoffset}\v!frame % new
+ {\dobackgroundbox\c!frameoffset}
+ {\dobackgroundbox\c!backgroundoffset}}
+
+%D We handle left, right or middle alignment as well as fixed
+%D or free widths and heights. Each combination gets its own
+%D macro.
+
+%D The following code handles one-liners: \type{align={line,flushright}}.
+%D Beware, since we entered a group and either or not grab the next
+%D bgroup token, we need to finish the group in the oneliner mode.
+
+\ifx\raggedoneliner\undefined \chardef\raggedoneliner\zerocount \fi
+
+\def\doformatonelinerbox % beware: assumes explicit preceding bgroup
+ {\ifcase\raggedoneliner
+ \expandafter\nodoformatonelinerbox
+ \else
+ \expandafter\dodoformatonelinerbox
+ \fi}
+
+\def\dodoformatonelinerbox
+ {\dowithnextboxcontent
+ {\ignorespaces}
+ {\hbox to \hsize
+ {\ifcase\raggedstatus\or\hss\or\hss\fi
+ \unhbox\nextbox \removeunwantedspaces
+ \ifcase\raggedstatus\or \or\hss\or\hss\fi}%
+ \egroup}
+ \hbox}
+
+\def\nodoformatonelinerbox % grabs {
+ {\let\next=}
+
+%D The handlers:
+
+\def\doformatboxSomeFormat
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \vsize\!!framedheight
+ \doframedsetups
+ \raggedcommand
+ \dobeforeframedbox
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\doafterframedbox
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxNoFormat
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \vsize\!!framedheight
+ \doframedsetups
+ \raggedcenter
+ \vss
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\vss
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxHeight
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \doframedsetups
+ \raggedcommand
+ \vss
+ \bgroup
+ \aftergroup\localendstrut
+ \aftergroup\vss
+ \aftergroup\egroup
+ \localbegstrut
+ \doformatonelinerbox}
+
+\def\doformatboxWidth
+ {\vbox
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \doframedsetups
+ \raggedcommand
+ \dobeforeframedbox
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\doafterframedbox
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxVSize
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \vsize\!!framedheight
+ \doframedsetups
+ \vss
+ \bgroup
+ \aftergroup\vss
+ \aftergroup\egroup
+ \hbox
+ \bgroup
+ \aftergroup\egroup
+ \localstrut
+ \doformatonelinerbox}
+
+\def\doformatboxHSize
+ {\hbox to \!!framedwidth
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \doframedsetups
+ \hss
+ \localstrut
+ \bgroup
+ \aftergroup\hss
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxNoSize
+ {\hbox
+ \bgroup
+ \let\postprocessframebox\relax
+ \doframedsetups
+ \localstrut
+ \doformatonelinerbox}
+
+\let\doframedsetups\relax
+
+%D On the next page we show some examples of how these macros
+%D come into action. The examples show us how
+%D \type {fit}, \type {broad} dimensions influence the
+%D formatting. Watch the visualized struts. \footnote {Here we
+%D used \type {\showstruts}.}
+%D
+%D \startpostponing
+%D \bgroup
+%D \showstruts
+%D \dontcomplain
+%D \startlinecorrection
+%D \halign{#\enskip\enskip\enskip\enskip\enskip\cr
+%D \framed[width=.2\hsize, height=.2\hsize, align=] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=yes] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=yes] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=yes] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=right] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=right] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=right] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=left] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=left] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=left] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=middle] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=middle] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=middle] {a\par b\par c}\cr}
+%D \stoplinecorrection
+%D \blank[2*big]
+%D \egroup
+%D \stoppostponing
+
+%D \macros
+%D {framednoflines, framedlastlength}
+%D
+%D It is possible to let the frame macro calculate the width
+%D of a centered box automatically (\type {fit}). When
+%D doing so, we need to reshape the box:
+
% The next implementation is frozen! It preserves the depth,
% otherwise we get problems with framed display math and auto
% width.
+\newcount\framednoflines
+\newdimen\framedlastlength
+
+\def\resetshapeframebox
+ {\framednoflines \zerocount
+ \framedlastlength\zeropoint}
+
+\chardef\reshapeframeboxmethod\plusone % 0=no flush, 1=old method 2=no depth messing
+
\def\shapeboxstrut % put this in front if needed !
{\vrule\!!width\zeropoint\!!height\ht\shapebox\!!depth\dp\shapebox}
@@ -72,4 +1924,1714 @@
\fi
\fi}
+%D The two variables \type {\framednoflines} and \type
+%D {\framedlastlength} can be used in a second pass to
+%D optimized framed material.
+
+% torture test / strange case (much depth) / method 2 needed
+%
+% \startTEXpage[frame=on]
+% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
+% test outside formula
+% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
+% \blank[big]
+% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
+% test outside formula
+% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
+% \stopTEXpage
+
+%D The examples on the next page show how one can give the
+%D frame as well as the background an additional offset and
+%D even a bit more depth. The blue outline is the frame, the
+%D red box is the background and the small black outline is the
+%D visualization of the resulting box, that is, we applied
+%D \type{\ruledhbox} to the result.
+
+%D \startpostponing
+%D \bgroup
+%D \unprotect
+%D \dontcomplain
+%D
+%D \startbuffer
+%D \vbox to \vsize
+%D \bgroup
+%D \startalignment[middle]
+%D \vss
+%D \dontleavehmode\vbox to .8\vsize
+%D \bgroup
+%D \hsize=300pt
+%D \setupframed
+%D [background=color,
+%D backgroundcolorachtergrondkleur=darkred,
+%D width=300pt,
+%D height=60pt,
+%D framecolorkaderkleur=DemoBlue,
+%D rulethickness=2pt]
+%D \def\status%
+%D {backgroundoffset=\framedparameter\c!backgroundoffset\\
+%D frameoffset=\framedparameter\c!frameoffset\\
+%D depth=\framedparameter\c!depth}
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=0pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=0pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=5pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=2pt,frameoffset=5pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=2pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=5pt]{\status}}
+%D \egroup
+%D \vss
+%D \stopalignment
+%D \egroup
+%D \stopbuffer
+%D
+%D \getbuffer \page
+%D
+%D {\setupframed[depth=4pt]\getbuffer} \page
+%D
+%D \protect
+%D \egroup
+%D \stoppostponing
+
+%D When typesetting the framed box inline, we have to keep the
+%D baseline intact outside as well as inside the framed box.
+
+\def\doinlineframedbox
+ {\scratchdimen\dimexpr\strutdp+\ruledlinewidth\relax
+ \ifboxhasoffset
+ \advance\scratchdimen \framedparameter\c!offset
+ \fi
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \box\framebox}
+
+%D We can also lower the box over the natural depth of the
+%D line.
+
+\def\doloweredframedbox
+ {\ht\framebox\dimexpr\ht\framebox+\dp\framebox-\strutdp\relax
+ \dp\framebox\strutdp
+ \box\framebox}
+
+%D Hanging the content is mainly meant for cases like the
+%D following:
+%D
+%D \starttyping
+%D \framed[strut=no]
+%D {\framed[height=2cm,location=hanging]{test}%
+%D \framed[height=1cm,location=hanging]{test}}
+%D \stoptyping
+
+\def\dohangingframedbox % best with strut=no
+ {\scratchdimen\dimexpr\ht\framebox+\dp\framebox\relax
+ \ht\framebox\zeropoint
+ \dp\framebox\scratchdimen}
+
+%D We can draw lines from left to right and top to bottom by
+%D using the normal \type{\hairline} command. Both directions
+%D need a different treatment.
+%D
+%D \startbuffer
+%D \framed[width=4cm] {alfa\hairline beta\hairline gamma}
+%D \framed[height=2cm] {alfa\hairline beta\hairline gamma}
+%D \framed[width=4cm,height=2cm]{alfa\hairline beta\hairline gamma}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D These macros try to adapt their behaviour as good as
+%D possible to the circumstances and act as natural as
+%D possible.
+
+\def\vboxedhairline
+ {\bgroup
+ \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
+ \dimen4=\dimexpr\dimen2+\ruledlinewidth\relax
+ \setbox0\vbox
+ {\advance\hsize 2\dimen4
+ \vskip\dimen2
+ \hrule
+ \!!height\ruledlinewidth
+ \!!depth\zeropoint
+ \!!width\hsize
+ \vskip\dimen2}%
+ %\endgraf\nointerlineskip\endgraf
+ %\moveleft\dimen4\box0
+ %\endgraf\nointerlineskip\localbegstrut
+ \endgraf\obeydepth\nointerlineskip
+ \moveleft\dimen4\box0
+ \endgraf\nointerlineskip\localbegstrut % beware, we might kill it in a style using \vskip\lineheight
+ \egroup} % so this must not be changed
+
+\def\hboxedhairline % use framed dimen
+ {\bgroup
+ \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
+ \ifboxhasheight
+ \dimen4\dimexpr\localheight/2+\strutdp-2\ruledlinewidth\relax
+ \dimen6\dimexpr\localheight/2-\strutdp+2\ruledlinewidth\relax
+ \else
+ \dimen4\dimexpr\strutht+\dimen2\relax
+ \dimen6\dimexpr\strutdp+\dimen2\relax
+ \fi
+ \unskip
+ \setbox\scratchbox\hbox
+ {\hskip\dimen2
+ \vrule\!!height\dimen4\!!depth\dimen6\!!width\ruledlinewidth
+ \hskip\dimen2}%
+ \ht\scratchbox\strutht
+ \dp\scratchbox\strutdp
+ \box\scratchbox
+ \ignorespaces
+ \egroup}
+
+%D The argument of the frame command accepts \type{\\} as a
+%D sort of newline signal. In horizontal boxes it expands to a
+%D space.
+
+\def\vboxednewline
+ {\endgraf\ignorespaces}
+
+\def\hboxednewline
+ {\unskip\normalspace\ignorespaces}
+
+%D We can set each rule on or off. The default setting is
+%D inherited from \type{frame}. An earlier implementation
+%D use a bit different approach, but the new one seems more
+%D natural:
+%D
+%D \bgroup
+%D \setuptyping[margin=0pt]
+%D \startlinecorrection
+%D \startbuffer
+%D \framed[offset=overlay,frame=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=on,bottomframe=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=on,bottomframe=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off,bottomframe=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off,bottomframe=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D \stoplinecorrection
+%D \egroup
+
+%D \macros
+%D {setupblackrules}
+%D
+%D The graphic capabilities of \TEX\ do not go beyond simple
+%D filled rules, except of course when using specials. Let's
+%D start with a warning: using this commands is far more slower
+%D than using the \TEX\ primitives \type{\hrule} and
+%D \type{\vrule}, but they save us some tokens. The
+%D characteristics of these rule drawing command can be set by:
+%D
+%D \showsetup{setupblackrules}
+
+\def\setupblackrules
+ {\dodoubleargument\getparameters[\??bj]}
+
+%D \macros
+%D {blackrule}
+%D
+%D The simple command draws only one rule. Its optional
+%D argument can be used to specify the dimensions. By setting
+%D the width, height or depth to \type {max}, one gets the
+%D natural dimensions.
+%D
+%D \showsetup{blackrule}
+
+\def\doblackrule[#1]%
+ {\hbox\bgroup
+ \getparameters[\??bj][#1]%
+ \setstrut
+ \doif\@@bjwidth \v!max{\def\@@bjwidth {1em}}%
+ \doif\@@bjheight\v!max{\def\@@bjheight{\strutht}}%
+ \doif\@@bjdepth \v!max{\def\@@bjdepth {\strutdp}}%
+ \localstartcolor[\@@bjcolor]%
+ \vrule
+ \!!width \@@bjwidth
+ \!!height\@@bjheight
+ \!!depth \@@bjdepth
+ \localstopcolor
+ \egroup}
+
+\unexpanded\def\blackrule
+ {\dosingleempty\doblackrule}
+
+%D \macros
+%D {blackrules}
+%D
+%D One can call for a sequence of black rules, if needed
+%D equally spaced over the given width.
+%D
+%D \showsetup{blackrules}
+%D
+%D The two alternative calls are therefore:
+%D
+%D \startbuffer
+%D Tell me, is this according to the \blackrules[n=6]?
+%D These \blackrules[alternativevariant=b,n=10,distance=.2em,width=4cm] are quite clear.
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or:
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D We could of course have implemented this macro using
+%D \type{\leaders}, but this would probably have taken more
+%D tokens.
+
+\def\doblackrules[#1]%
+ {\hbox\bgroup
+ \getparameters[\??bj][#1]%
+ \!!widtha\@@bjwidth
+ \!!widthb\@@bjdistance
+ \doif\@@bjalternative\c!b
+ {\scratchcounter\@@bjn
+ \ifnum\scratchcounter=\plusone
+ \!!widthb\zeropoint
+ \else
+ \advance\scratchcounter \minusone
+ \advance\!!widtha -\scratchcounter\!!widthb
+ \divide \!!widtha \@@bjn
+ \fi}%
+ \localstartcolor[\@@bjcolor]%
+ \dorecurse\@@bjn
+ {\vrule
+ \!!width \!!widtha
+ \!!height\@@bjheight
+ \!!depth \@@bjdepth
+ \hskip\!!widthb}%
+ \unskip
+ \localstopcolor
+ \egroup}
+
+\unexpanded\def\blackrules
+ {\dosingleempty\doblackrules}
+
+%D The next commands can be used to draw margin rules. We
+%D support two methods: \marginrule{one for in||line use} and
+%D one that acts on a paragraph. Drawing a margin rule is
+%D rather straightforward because we can use the commands that
+%D put text in the margin.
+
+\def\dodrawmarginrule
+ {\setbox\scratchbox\hbox
+ {\vrule\!!depth\strutdepth\!!height\strutheight\!!width\@@karulethickness}%
+ \smashbox\scratchbox % no \vsmash !!!
+ \box\scratchbox}
+
+\def\drawmarginrule
+ {\strut\inleft{\dodrawmarginrule}}
+
+%D \macros
+%D {marginrule}
+%D
+%D The first method gobbles words and simply puts a bar in the
+%D margin. This method is not entirely robust.
+%D
+%D \showsetup{marginrule}
+
+\definecomplexorsimple\marginrule
+
+\def\simplemarginrule
+ {\let\processword\drawmarginrule
+ \processwords}
+
+\def\complexmarginrule[#1]%
+ {\ifnum#1<\@@kalevel\relax \else
+ \def\@@kadefaultwidth{#1}%
+ \expandafter\simplemarginrule
+ \fi}
+
+%D We need an auxiliary variable
+
+\def\@@kadefaultwidth{1}
+
+%D \macros
+%D {setupmarginrules}
+%D
+%D This macro definitions show us that we can pass an optional
+%D level, which is matched against the previous set one. The
+%D level can be set up with
+%D
+%D \showsetup{setupmarginrules}
+
+\def\setupmarginrules
+ {\dodoubleargument\getparameters[\??ka]}
+
+%D \macros
+%D {startmarginrule}
+%D
+%D The second method collects text and reformats it afterwards,
+%D using the shapebox macros. We prevent local margin rules.
+%D
+%D \showsetup{startmarginrule}
+
+\definecomplexorsimple\startmarginrule
+
+\def\simplestartmarginrule
+ {\bgroup
+ \let\drawmarginrule\relax
+ \let\stopmarginrule\dostopmarginrule
+ \beginofshapebox}
+
+\def\complexstartmarginrule[#1]%
+ {\bgroup
+ \let\drawmarginrule\relax
+ \ifnum#1<\@@kalevel\relax
+ \let\stopmarginrule\egroup
+ \else
+ \def\@@kadefaultwidth{#1}%
+ \let\stopmarginrule\dostopmarginrule
+ \expandafter\beginofshapebox
+ \fi}
+
+\def\dostopmarginrule
+ {\endofshapebox
+ \reshapebox
+ {\hbox{\inleftmargin{\dodrawmarginrule}\box\shapebox}}%
+ \flushshapebox
+ \egroup}
+
+%D \startbuffer
+%D \setupmarginrules[level=5]
+%D
+%D \startmarginrule[1]
+%D First we set the level at~5. Next we typeset this first
+%D paragraph as a level~1 one. As expected no rule show up.
+%D \stopmarginrule
+%D
+%D \startmarginrule[5]
+%D The second paragraph is a level~5 one. As we can see here,
+%D the marginal rule gets a width according to its level.
+%D \stopmarginrule
+%D
+%D \startmarginrule[8]
+%D It will of course be no surprise that this third paragraph
+%D has a even thicker margin rule. This behavior can be
+%D overruled by specifying the width explictly.
+%D \stopmarginrule
+%D \stopbuffer
+%D
+%D In next example we show most features. Watch the rule
+%D thickness adapting itself to the level.
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D We just said:
+%D
+%D \typebuffer
+
+%D \macros
+%D {vl, hl}
+%D
+%D The command \type{\vl} draws a vertical rule \vl\ with strut
+%D dimensions, multiplied with the factor specified in the
+%D optional argument. The height and depth are clipped \vl[3]
+%D to the baselinedistance. Its horizontal counterpart
+%D \type{\hl} draws a horizontal rule \hl\ with a width of 1em,
+%D multiplied with the optional factor. The horizontal rule is
+%D drawn on top of the baseline.
+%D
+%D \showsetup{vl}
+%D \showsetup{hl}
+
+\def\complexvl[#1]%
+ {\bgroup
+ \!!dimena#1\strutht
+ \!!dimenb#1\strutdp
+ \setbox\scratchbox\hbox
+ {\vrule
+ \!!width \linewidth
+ \!!height\!!dimena
+ \!!depth \!!dimenb}%
+ \dp\scratchbox\strutdp
+ \ht\scratchbox\strutht
+ \box\scratchbox
+ \egroup}
+
+\def\complexhl[#1]%
+ {\hbox
+ {\vrule
+ \!!width #1\s!em
+ \!!height\linewidth
+ \!!depth \zeropoint}}
+
+\definecomplexorsimple\vl \def\simplevl{\complexvl[1]}
+\definecomplexorsimple\hl \def\simplehl{\complexhl[1]}
+
+%D \macros
+%D {hairline, thinrule, thinrules, setupthinrules}
+%D
+%D Drawing thin lines can of course easily be accomplished by
+%D the \TEX\ primitives \type{\hrule} and \type{\vrule}. The
+%D next few macros however free us from some specifications.
+%D
+%D \startbuffer
+%D some text
+%D
+%D \hairline
+%D
+%D some more text
+%D
+%D \thinrule
+%D
+%D more and more text
+%D
+%D hi \thinrule\ there
+%D
+%D and then the final text
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D becomes
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D So we've got
+%D
+%D \showsetup{hairline}
+%D \showsetup{thinrule}
+%D
+%D Both can be set up with:
+%D
+%D \showsetup{setupthinrules}
+%D
+%D We also have
+%D
+%D \showsetup{thinrules}
+%D
+%D which looks like: \thinrules[n=2]
+
+\def\thinrule
+ {\strut
+ \bgroup
+ \chardef\ruletype\plusone
+ \processaction
+ [\@@dlalternative]
+ [ \v!a=>\chardef\ruletype0,% no line
+ %\v!b=>\chardef\ruletype1,% height/depth
+ \v!c=>\chardef\ruletype2,% topheight/botdepth
+ % 11=>\chardef\ruletype1,% fallback for backgrounds
+ 0=>\chardef\ruletype0,% compatible with backgrounds
+ % 1=>\chardef\ruletype1,% compatible with backgrounds
+ 2=>\chardef\ruletype2]% compatible with backgrounds
+ \doifsomething\@@dlrulethickness
+ {\linewidth\@@dlrulethickness}%
+ \ifdim\linewidth=\zeropoint
+ \chardef\ruletype\zerocount
+ \else
+ \doifnot\@@dlframe\v!on{\chardef\ruletype\zerocount}%
+ \fi
+ \ifnum\ruletype=\plusone
+ \doif\@@dlheight\v!max{\let\@@dlheight\!!plusone}%
+ \doif\@@dldepth \v!max{\let\@@dldepth \!!plusone}%
+ \else
+ \let\@@dlheight\!!plusone
+ \let\@@dldepth\!!plusone
+ \fi
+ \freezedimensionwithunit\@@dlheight\strutht
+ \freezedimensionwithunit\@@dldepth\strutdp
+ \divide\linewidth \plustwo
+ \doifelse\@@dlbackground\v!color
+ {\startcolor[\@@dlbackgroundcolor]%
+ \ifnum\ruletype=\plustwo % prevent overshoot due to rounding
+ \leaders
+ \hrule
+ \!!height\dimexpr\@@dlheight-.5\linewidth\relax
+ \!!depth \dimexpr\@@dldepth -.5\linewidth\relax
+ \hfill
+ \else
+ \leaders
+ \hrule
+ \!!height\@@dlheight
+ \!!depth \@@dldepth
+ \hfill
+ \fi
+ \stopcolor
+ \ifcase\ruletype
+ % no rule
+ \or
+ \startcolor[\@@dlcolor]%
+ \hfillneg
+ \leaders\hrule\!!height\linewidth\!!depth\linewidth\hfill
+ \stopcolor
+ \or
+ \startcolor[\@@dlcolor]%
+ \hfillneg\leaders\hrule\!!height\dimexpr-\@@dldepth+\linewidth\relax\!!depth\@@dldepth\hfill
+ \hfillneg\leaders\hrule\!!height\@@dlheight\!!depth\dimexpr-\@@dlheight+\linewidth\relax\hfill
+ \stopcolor
+ \fi}
+ {\ifcase\ruletype \else
+ \startcolor[\@@dlcolor]%
+ \leaders\hrule\!!height\@@dlheight\!!depth\@@dldepth\hfill
+ \stopcolor
+ \fi}%
+ \strut
+ \carryoverpar\egroup}
+
+\def\hairline
+ {\endgraf
+ \thinrule
+ \endgraf}
+
+\def\dosetupthinrules[#1]%
+ {\getparameters[\??dl][#1]}
+
+\def\setupthinrules
+ {\dosingleargument\dosetupthinrules}
+
+\def\dothinrules[#1]%
+ {\bgroup
+ \dosetupthinrules[#1]%
+ \@@dlbefore
+ \assignvalue\@@dlinterlinespace\@@dlinterlinespace{1.0}{1.5}{2.0}%
+ \spacing\@@dlinterlinespace
+ \dorecurse\@@dln
+ {\ifnum\recurselevel=\@@dln \dothinrulesnobreak \else
+ \ifnum\recurselevel=2 \dothinrulesnobreak \fi\fi
+ \thinrule
+ \ifnum\recurselevel<\@@dln\relax
+ % test needed, else messed up whitespace
+ \ifx\@@dlinbetween\empty
+ \softbreak
+ \else
+ \endgraf
+ \nowhitespace
+ \@@dlinbetween
+ \fi
+ \fi}%
+ \doifelsenothing\@@dlafter
+ {\carryoverpar\egroup}
+ {\@@dlafter\egroup}}
+
+\def\thinrules
+ {\dosingleempty\dothinrules}
+
+%D A couple of examples are given below.
+%D
+%D \startbuffer
+%D \setupthinrules[n=3,inbetween=,color=gray]
+%D
+%D test test \thinrules\ test test \par
+%D test test \thinrules [color=green] test test \par
+%D test test \thinrules [height=max, depth=max] test test \par
+%D
+%D \setupthinrules[height=.9,depth=.9]
+%D
+%D test test \thinrules\ test test \par
+%D test test \thinrules [alternativevariant=b] test test \par
+%D test test \thinrules [alternativevariant=c] test test \par
+%D test test \thinrules [alternativevariant=c,inbetween=\vskip2ex] test test \par
+%D \stopbuffer
+%D
+%D \typebuffer {\getbuffer}
+%D
+%D There are a couple of alternative ways to visualize rules
+%D using backgrounds. At first sight these may look strange,
+%D but they make sense in educational settings. The
+%D alternatives are more or less compatible with the more
+%D advanced \METAPOST\ based implementation.
+%D
+%D \startbuffer[a]
+%D \setupthinrules
+%D [n=2,
+%D backgroundcolor=gray ,
+%D rulethickness=1pt,
+%D colorkleur=donkerblauw,
+%D after=\blank,
+%D before=\blank]
+%D \stopbuffer
+%D
+%D \typebuffer[a]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a]
+%D \thinrules[alternativevariant=b]
+%D \thinrules[alternativevariant=c]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a,background=color]
+%D \thinrules[alternativevariant=b,background=color]
+%D \thinrules[alternativevariant=c,background=color]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a,height=.8,depth=.8,background=color]
+%D \thinrules[alternativevariant=b,height=.8,depth=.8,background=color]
+%D \thinrules[alternativevariant=c,height=.8,depth=.8,background=color]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+
+%D \macros
+%D {optimizethinrules}
+%D
+%D By saying \type {\thinrulestrue} or \type {-false}, we
+%D can influence the way dangling lines are handled.
+
+\newif\ifoptimizethinrules \optimizethinrulestrue
+
+\def\dothinrulesnobreak
+ {\ifoptimizethinrules\penalty500\fi}
+
+%D \macros
+%D {startframedtext, setupframedtexts, defineframedtext}
+%D
+%D The general framing command we discussed previously, is not
+%D entirely suited for what we call framed texts, as for
+%D instance used in intermezzo's. The next examples show what
+%D we have in mind.
+%D
+%D \startbuffer[framed-0]
+%D \setupframedtexts
+%D [frame=off,
+%D width=\hsize,
+%D background=screen]
+%D
+%D \startframedtext
+%D By default the framed text is centered \dots
+%D \stopframedtext
+%D
+%D \startframedtext[right]
+%D \dots\ but we can also align left, middle and right.
+%D \stopframedtext
+%D \stopbuffer
+%D
+%D \startbuffer[framed-1]
+%D \defineframedtext
+%D [Example]
+%D [width=6cm,
+%D height=5cm]
+%D
+%D \startExample
+%D \typebuffer[framed-1]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-2]
+%D \defineframedtext
+%D [Example]
+%D [width=6cm]
+%D
+%D \startExample
+%D \typebuffer[framed-2]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-3]
+%D \defineframedtext
+%D [Example]
+%D [height=5cm]
+%D
+%D \startExample
+%D \typebuffer[framed-3]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-4]
+%D \defineframedtext
+%D [Example]
+%D [width=fit,height=broad]
+%D
+%D \Example{a very exciting example}
+%D \stopbuffer
+%D
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-0] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-1] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-2] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-3] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-4] \egroup
+%D
+%D Here we can see that we have a predefined framed text class
+%D as well as the tools for defining our own. So we have:
+%D
+%D \showsetup{setupframedtexts}
+%D
+%D as well as the definition command:
+%D
+%D \showsetup{defineframedtext}
+%D
+%D that generates two commands:
+%D
+%D \showsetup{start<>}
+%D \showsetup{<>}
+%D
+%D The next definition shows the defaults.
+
+\def\dodefineframedtext[#1][#2]%
+ {\presetlocalframed[\??kd#1]%
+ \getparameters[\??kd#1]
+ [\c!width=0.75\hsize,
+ \c!height=\v!fit,
+ \c!align=\v!yes,
+ \c!top=,
+ \c!bottom=\vfill,
+ \c!offset=1em,
+ \c!bodyfont=,
+ \c!style=,
+ \c!color=,
+ \c!left=,
+ \c!right=\hfill,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!inner=,
+ \c!frame=\v!on,
+ \c!topframe=,
+ \c!bottomframe=,
+ \c!leftframe=,
+ \c!rightframe=,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ \c!foregroundcolor=,
+ \c!foregroundstyle=,
+ \c!background=,
+ \c!backgroundcolor=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!linecorrection=\v!on,
+ \c!depthcorrection=\v!on,
+ \c!margin=\v!standard,
+ \c!orientation=,
+ \c!indenting=,
+ #2]%
+ \setvalue{\e!start#1}{\dostartframedtext[#1]}%
+ \setvalue{\e!stop #1}{\dostopframedtext }%
+ \setvalue {#1}{\doframedtext [#1]}}
+
+\def\defineframedtext
+ {\dodoubleempty\dodefineframedtext}
+
+%D We define the general (and original) case by just saying:
+
+\defineframedtext[\v!framedtext]
+
+%D We need several steps before the actual job is done,
+%D because we have to handle an optional identifier (and
+%D because these commands evolved out of a single case).
+
+\def\framedtextparameter#1#2%
+ {\csname\??kd#1#2\endcsname}
+
+\def\dosetupframedtexts[#1][#2]%
+ {\ifsecondargument
+ \def\docommand##1{\getparameters[\??kd##1][#2]}%
+ \processcommacommand[#1]\docommand % new, #1 may be macro
+ \else
+ \getparameters[\??kd\v!framedtext][#1]%
+ \fi}
+
+\def\setupframedtexts
+ {\dodoubleempty\dosetupframedtexts}
+
+\def\dostartframedtext
+ {\bgroup\dotripleempty\dodostartframedtext}
+
+\def\dodostartframedtext[#1][#2][#3]%
+ {\doifassignmentelse{#2}
+ {\dododostartframedtext[#1][][#2]}
+ {\dododostartframedtext[#1][#2][#3]}}
+
+\setfalse\framedtextlocationnone
+
+\def\dododostartframedtext[#1][#2][#3]% #3 only passed to framed, not to framedtext
+ {\doifsomething{#2}{\setvalue{\??kd#1\c!location}{#2}}% does not listen to #3
+ \setfalse\framedtextlocationnone
+ \processaction % \v!low en \v!depth are already taken !
+ [\framedtextparameter{#1}\c!location]
+ [ \v!left=>\letvalue{\??kd#1\c!left }\relax
+ \letvalue{\??kd#1\c!right}\hfill,
+ \v!right=>\letvalue{\??kd#1\c!left }\hfill
+ \letvalue{\??kd#1\c!right}\relax,
+ \v!middle=>\letvalue{\??kd#1\c!left }\hfill
+ \letvalue{\??kd#1\c!right}\hfill,
+ \v!none=>\letvalue{\??kd#1\c!left }\relax % new
+ \letvalue{\??kd#1\c!right}\relax % new
+ \settrue\framedtextlocationnone]%
+ \letvalue{\??kd#1\c!location}\empty
+ % removed 06/2001
+ % \forgetparindent
+ % added 06/2001 [see demo-bbv]
+ \localhsize\hsize \checkframedtext
+ % so far
+ \setbox\framebox\vbox
+ \startboxedcontent
+ \hsize\localhsize
+ % \insidefloattrue % ? better
+ \expanded{\switchtobodyfont[\framedtextparameter{#1}\c!bodyfont]}%
+ \startcolor[\framedtextparameter{#1}\c!color]%
+ \localframed[\??kd#1][\c!strut=\v!no,#3]% todo: use delayedstrut
+ \bgroup
+ \let\\=\endgraf
+ \framedtextparameter{#1}\c!inner % oud spul
+ \doifvalue{\??kd#1\c!depthcorrection}\v!on % new, inside box
+ {\bgroup
+ \verticalstrut
+ % we need \nowhitespace in case of setups setting whitespace
+ % nb, not safe, text vs \vbox as next
+ \vskip-\struttotal
+ \nowhitespace % na vskip ! new 20/05/2004, fails with next content being box (\scale{..})
+ }%
+ \doinhibitblank % \blank[\v!disable]% plaatst signal
+\setupindenting[\framedtextparameter{#1}\c!indenting]%
+ \doconvertfont{\framedtextparameter{#1}\c!style}\empty
+ \def\dostopframedtext{\dodostopframedtext{#1}{#2}}}
+
+%D The \type {none} option is handy for nested usage, as
+%D in the presentation styles, where we don't want
+%D interference.
+
+\def\dodostopframedtext#1#2% % no \baselinecorrection, see faq docs
+ {\endgraf
+ \removelastskip
+ \doifvalue{\??kd#1\c!depthcorrection}\v!on % local and global
+ {\forgetall
+ \vskip-\struttotal
+ \verticalstrut
+ \egroup
+ \forgetall
+ \vskip-\lineheight
+ % will be an option, not default
+ % \setbaselinecorrections
+ % \donegbotbaselinecorrection
+ \verticalstrut}
+ \stopboxedcontent
+ \stopcolor
+ \ifconditional\framedtextlocationnone
+ \egroup
+ \box\framebox
+ \else\ifinsidefloat
+ \egroup
+ \box\framebox
+ \else
+ \egroup
+ \doplacement[\??kd#1][\c!depthcorrection=\v!off]{\box\framebox}%
+ \fi\fi
+ \egroup}
+
+%D Placement can be ignored:
+%D
+%D \starttyping
+%D \hbox to \hsize \bgroup
+%D \startframedtext[none][width=.5\textwidth] \input tufte \stopframedtext
+%D \startframedtext[none][width=.5\textwidth] \input zapf \stopframedtext
+%D \egroup
+%D
+%D \hbox to \hsize \bgroup
+%D \setupframedtexts[location=none]%
+%D \startframedtext[width=.5\textwidth] \input zapf \stopframedtext
+%D \startframedtext[width=.5\textwidth] \input tufte \stopframedtext
+%D \egroup
+%D \stoptyping
+
+%D The simple brace (or group) delimited case is typeset
+%D slightly different and is not aligned.
+
+\def\doframedtext
+ {\bgroup\dodoubleempty\dodoframedtext}
+
+\def\dodoframedtext[#1][#2]% beware!
+ {\expanded{\switchtobodyfont[\getvalue{\??kd#1\c!bodyfont}]}%
+ \localframed[\??kd#1][\c!strut=\v!no,#2]%
+ \bgroup
+ \blank[\v!disable]%
+ \let\\=\endgraf
+ \getvalue{\??kd#1\c!inner}% % kleur naar outer level
+ \dostartattributes{\??kd#1}\c!style\c!color\empty
+ \bgroup
+ \aftergroup\docloseframedtext
+ \let\next=}
+
+\def\docloseframedtext
+ {\removelastskip
+ \dostopattributes
+ \egroup
+ \egroup}
+
+%D \macros
+%D {defineframed}
+%D
+%D One can also define simple framed texts, using:
+%D
+%D \showsetup{defineframed}
+
+\def\defineframed
+ {\dodoubleempty\dodefineframed}
+
+\def\dodefineframed[#1][#2]%
+ {\iffirstargument
+ \setvalue{#1}{\dodoubleempty\doframed[#2]}%
+ \fi}
+
+\def\doframed[#1][#2]%
+ {\framed[#1,#2]}
+
+%D \macros
+%D {textrule, starttextrule, setuptextrules}
+%D
+%D Putting rules before and after a paragraph is very space
+%D sensitive, but the next command handles that quite well. It
+%D comes in two disguises:
+%D
+%D \startbuffer
+%D \textrule[top]{fragments}
+%D \input reich
+%D \textrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D \startbuffer
+%D \setuptextrules
+%D [width=90pt,distance=12pt,rulecolor=blue,
+%D bodyfont=small,style=\sc,color=red]
+%D
+%D \starttextrule{Ship Building Tools}
+%D \nl \setuptolerance[tolerant] \input materie
+%D \stoptextrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D \startbuffer
+%D \setuptextrules
+%D [location=inmargin,
+%D bodyfont=small,style=slantedbold]
+%D
+%D \starttextrule{wonderful}
+%D \input tufte
+%D \stoptextrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D The formal definition of these commands is:
+%D
+%D \showsetup{textrule}
+%D \showsetup{starttextrule}
+%D \showsetup{setuptextrules}
+%D
+%D The implementation looks a bit complicated due to the
+%D optional arguments.
+
+\def\setuptextrules
+ {\dodoubleargument\getparameters[\??tl]}
+
+\def\complextextrule[#1]% if needed we can make it installable
+ {\let\next\dobottomtextrule
+ \processaction
+ [#1]
+ [ \v!top=>\let\next\dotoptextrule,
+ \v!middle=>\let\next\domiddletextrule,
+ \v!bottom=>\let\next\dobottomtextrule]%
+ \dosinglegroupempty\next}
+
+\definecomplexorsimple\textrule
+
+\def\simpletextrule
+ {\dosinglegroupempty\dounknowntextrule}
+
+\def\docomplextextrule#1%
+ {\bgroup
+ \advance\hsize\dimexpr-\rightskip-\leftskip\relax
+ \setbox\scratchbox\hbox to \hsize
+ {\dimen4\dimexpr .5ex+.5\linewidth\relax
+ \dimen6\dimexpr-.5ex+.5\linewidth\relax
+ \doifnothing{#1}\firstargumentfalse
+ \iffirstargument
+ \doifelse\@@tllocation\v!inmargin
+ {\llap{\doattributes\??tl\c!style\c!color{#1}\hskip\leftmargindistance}}
+ {\color[\@@tlrulecolor]
+ {\vrule\!!height\dimen4\!!depth\dimen6\!!width\@@tlwidth}%
+ \hbox spread 2\dimexpr\@@tldistance\relax
+ {\hss\doattributes\??tl\c!style\c!color{\strut#1}\hss}}%
+ \fi
+ \color[\@@tlrulecolor]
+ {\leaders\hrule\!!height\dimen4\!!depth\dimen6\hfill}}%
+ \ht\scratchbox\strutht
+ \dp\scratchbox\strutdp
+ \noindent\box\scratchbox
+%\nobreak\verticalstrut\kern-\struttotal
+% evt \witruimte
+ \egroup}
+
+\def\dotoptextrule#1%
+ {\page[\v!preference] % interferes
+ %\whitespace % no
+ \@@tlbefore
+ \docomplextextrule{#1}%
+% todo, option: \doifnothing{#1}{\ruledvskip-.5ex}
+ \nowhitespace
+ \@@tlinbetween
+ \endgraf}
+
+\def\dodobottomtextrule#1#2%
+ {\ifhmode
+ \endgraf
+ \fi
+ \dimen0\strutdp
+ \ifdim\prevdepth>\strutdp\else % was <\strutdp
+ \ifdim\prevdepth>\zeropoint
+ \advance\dimen0 -\prevdepth
+ \fi
+ \fi
+ \advance\dimen0 .5ex
+ \vskip\dimen0
+% ==
+% \vskip\dimexpr \strutdp + .5ex
+% \ifdim\prevdepth>\strutdp\else\ifdim\prevdepth>\zeropoint-\prevdepth\fi\fi\relax
+%
+ \@@tlinbetween
+ \doifelsenothing{#2}
+ {\bgroup
+ \advance\hsize\dimexpr-\rightskip-\leftskip\relax
+ \nointerlineskip
+ \moveleft-\leftskip\vbox
+ {\color[\@@tlrulecolor]
+ {\hrule\!!depth\linewidth\!!height\zeropoint\!!width\hsize}}%
+ \egroup}
+ {\docomplextextrule{#2}}%
+ \ifvmode\prevdepth\zeropoint\fi
+ #1%
+ \page[\v!preference]}
+
+\def\dobottomtextrule
+ {\dodobottomtextrule\@@tlafter}
+
+\def\domiddletextrule
+ {\dodobottomtextrule\@@tlinbetween}
+
+\def\dounknowntextrule
+ {\iffirstargument
+ \@EA\dotoptextrule
+ \else
+ \@EA\dobottomtextrule\@EA\empty
+ \fi}
+
+%D The grouped commands also supports bodyfont switching:
+
+\def\starttextrule#1%
+ {\bgroup
+ \def\dounknowntextrule{\domiddletextrule}
+ \dotoptextrule{#1}
+ \bgroup
+ \doifsomething\@@tlbodyfont{\switchtobodyfont[\@@tlbodyfont]}}
+
+\def\stoptextrule
+ {\par
+ \egroup
+ \dobottomtextrule\empty
+ \egroup}
+
+%D \macros
+%D {fillinrules, setupfillinrules}
+%D
+%D The next few commands do not really deserve a place in a
+%D core module, because they deal with specific typography.
+%D Nevertheless I decided to make them part of the core,
+%D because they permit us to make questionaires. Let's start
+%D with some examples.
+%D
+%D \fillinrules[n=2,width=fit]{first}
+%D \fillinrules[n=2,width=broad]{first}
+%D \fillinrules[n=2,width=3cm]{first}
+%D \fillinrules[n=2,width=3cm,distance=.5em,separator=:]{first}
+%D \fillinrules[n=2]{first}{last}
+%D \fillintext{first}{last} \input reich \par
+%D
+%D The main command is \type{\fillinrules}. This command takes
+%D one and an optional second argument and sets a paragraph with
+%D empty visualized lines.
+%D
+%D \showsetup{fillinrules}
+%D \showsetup{setupfillinrules}
+
+\def\setupfillinrules
+ {\dodoubleargument\getparameters[\??il]}
+
+\definecomplexorsimpleempty\fillinrules
+
+\def\complexfillinrules[#1]%
+ {\def\docomplexfillinrules##1##2%
+ {\dodocomplexfillinrules[#1]{##1}{##2}{\thinrules
+ [\c!n=\@@iln,\c!interlinespace=\@@ilinterlinespace,\c!before=,\c!after=]}}%
+ \dodoublegroupempty\docomplexfillinrules}
+
+\def\dodocomplexfillinrules[#1]#2#3#4%
+ {\endgraf
+ \@@ilbefore
+ \begingroup
+ \setupfillinrules[#1]%
+ \noindent
+ \doifsomething{#2}
+ {\doifelse\@@ilwidth\v!fit
+ {\let\@@ildistance\!!zeropoint
+ \hbox}
+ {\doifelse\@@ilwidth\v!broad
+ {\hbox}
+ {\hbox to \@@ilwidth}}%
+ \bgroup
+ \doattributes\??il\c!style\c!color{\strut#2\hfill\@@ilseparator}%
+ \hskip\@@ildistance
+ \egroup}%
+ %\hangindent=\wd0\relax % tzt hang=yes,n
+ %\parindent=\hangindent
+ %\box0\relax
+ \setupwhitespace[\v!big]%
+ \ignorespaces
+ #4%
+ \doifsomething{#3}
+ {\kern\@@ildistance
+ \doattributes\??il\c!style\c!color{#3\strut}}%
+ \endgroup
+ \endgraf
+ \@@ilafter}
+
+%D \macros
+%D {fillintext}
+%D
+%D To provide compatible layouts when texts and lines are
+%D mixed, one can typeset a paragraph by using the command
+%D \type{\fillintext}.
+%D
+%D \showsetup{fillintext}
+
+\definecomplexorsimpleempty\fillintext
+
+\def\complexfillintext[#1]% rather rough, using an \unhbox is suboptimal
+ {\def\docomplexfillintext##1##2%
+ {\dowithnextbox
+ {\dodocomplexfillinrules[#1]{##1}{\hfill##2}{\unhbox\nextbox\unskip}}%
+ \hbox\bgroup\let\par\egroup\ignorespaces}%
+ \dodoublegroupempty\docomplexfillintext}
+
+%D \macros
+%D {fillinline, setupfillinlines}
+%D
+%D Another member of the family takes care of putting a (often
+%D small) rule after a piece of text, like
+%D
+%D \startbuffer
+%D \fillinline \input reich \par
+%D \fillinline[margin=0cm] \input reich \par
+%D \stopbuffer
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D which was typeset by saying:
+%D
+%D \typebuffer
+%D
+%D The two commands that take care of this are:
+%D
+%D \showsetup{fillinline}
+%D \showsetup{setupfillinlines}
+
+\def\setupfillinlines
+ {\dodoubleargument\getparameters[\??iv]}
+
+\definecomplexorsimpleempty\fillinline
+
+\def\complexfillinline[#1]%
+ {%\endgraf % interferes with \definedescription cum suis
+ \@@ivbefore
+ \begingroup
+ \setupfillinlines[#1]%
+ \advance\rightskip \@@ivmargin
+ \parfillskip\zeropoint
+ \def\par % very dangerous
+ {\let\par\endgraf % -)
+ \ifhmode\unskip\hfill\fi
+ \scratchdimen\dimexpr\@@ivwidth-\@@ivdistance\relax
+ \ifdim\scratchdimen>\@@ivmargin\else\expandafter\rlap\fi
+ {\kern\@@ivdistance
+ \vrule
+ \!!width \scratchdimen
+ \!!height.5\linewidth
+ \!!depth .5\linewidth}%
+ \endgraf % !
+ \endgroup
+ \endgraf % !
+ \@@ilafter}}
+
+%D \stopdocumentation
+%D \bgroup
+%D
+%D \setupframedtexts
+%D [setuptext]
+%D [background=color,backgroundcolor=white]
+%D
+%D \startbuffer
+%D \setupbackground
+%D [backgroundoffset=4pt,
+%D background=screen,
+%D frame=on,
+%D framecolor=red,
+%D leftoffset=2pt]
+%D \stopbuffer
+%D
+%D \getbuffer
+%D
+%D \startbackground
+%D
+%D \macros
+%D {setupbackground,startbackground,background}
+%D
+%D The section deals with backgrounds in the running text. This
+%D means that texts is to be collected and split over pages. To
+%D show what can be done, we provide this part of the
+%D documentation with some gray background and a red frame.
+%D Both the background and frame can have all characteristics
+%D of \type{\framed}. This time we used the setting:
+%D
+%D \typebuffer
+%D
+%D The implementation is not that sophisticated, but suffices.
+%D The main problem with this kind of functionality is to get
+%D the spacing all right.
+
+%D Specifying the background is more or less the same as
+%D specifying a framed box.
+%D
+%D \showsetup{setupbackground}
+
+\presetlocalframed[\??ag]
+
+\def\dosetupbackground[#1]%
+ {\getparameters[\??ag][#1]%
+ \doifelse\@@agstate\v!start
+ {\let\startbackground\dostartbackground
+ \let\stopbackground \dostopbackground
+ \let\background \dobackground}
+ {\let\startbackground\relax
+ \let\stopbackground \relax
+ \let\background \relax}}
+
+\def\setupbackground
+ {\dosingleargument\dosetupbackground}
+
+%D Actually typesetting the background is implemented rather
+%D straightforward. We need to handle some spacing as well as
+%D the (often) a bit smaller horizontal size.
+%D
+%D \showsetup{startbackground}
+%D
+%D Although we could have used a scratch one, we first
+%D declare a boolean.
+
+% 0=no-split, 1=no-split+indent, 2=split, 3=split+indent
+
+\chardef\backgroundsplitmode\plusthree
+
+%D The \type{\vbox to \lineheight{}\vskip\zeropoint}
+%D construction gives the first real line a decent height by
+%D adding a dummy line.
+
+\def\dostartbackground
+ {\endgraf
+ \bgroup
+ \setbox0\vbox\bgroup
+ \vbox to \lineheight{}\vskip\zeropoint
+ \blank[\v!disable]
+ % \advance\hsize -\@@agleftoffset
+ % \advance\hsize -\@@agrightoffset
+ \leftskip \@@agleftoffset % new **
+ \rightskip\@@agrightoffset} % new **
+
+%D This dummy line is removed by \type{\setbox2=\vsplit0 to
+%D \lineheight}. That way \type{\topskip} takes care of the
+%D lineheight. I'll probably forget to apply this trick
+%D elsewhere.
+
+\def\dostopbackground % improved version (i hope)
+ {\endgraf
+ \removelastskip
+ \egroup
+ \dimen2\leftskip % new **
+ \forgetall
+ \ifinsidefloat
+ \chardef\backgroundsplitmode\zerocount
+ \fi
+ \ifcase\backgroundsplitmode
+ \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
+ \or
+ \hskip\dimen2
+ \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
+ \else
+ \splitmaxdepth\boxmaxdepth
+ \splittopskip\topskip
+ \setbox2\vsplit0 to \lineheight % get rid of fake line
+ \loop
+ \ifdim\pagetotal=\zeropoint % empty page
+ \scratchdimen\textheight
+ \chardef\backgroundsplit\plusone % split to max height
+ \else
+ \setbox\scratchbox\vbox{\@@agbefore}%
+ \scratchdimen\dimexpr\pagegoal-\ht\scratchbox-\pagetotal\relax
+ \chardef\backgroundsplit\plustwo % split to partial height
+ \fi
+ \advance\scratchdimen\dimexpr-\@@agtopoffset-\@@agbottomoffset\relax
+ \ifdim\scratchdimen>2\lineheight\relax % reasonable, will be configurable
+ \ifdim\ht0>\scratchdimen % larger than page
+ \setbox2\vsplit0 to \scratchdimen
+ \else
+ \setbox2\box0
+ \chardef\backgroundsplit\zerocount % no split
+ \fi
+ \setbox2\vbox \ifcase\backgroundsplit\or to \textheight \fi % max split
+ {\vskip\@@agtopoffset
+ \popsplitproperties
+ \unvcopy2
+ \prevdepth\dp2
+ \obeydepth
+ \vskip\@@agbottomoffset
+ \vfill}
+ \@@agbefore
+ \ifcase\backgroundsplit\or\or % partial split
+ \ifdim\pagegoal<\maxdimen
+ \pagegoal=1.2\pagegoal % be a bit more tolerant
+ \fi
+ \fi
+ \startlinecorrection
+ %\localframed[\??ag][\c!offset=\v!overlay]{\hskip\@@agleftoffset\box2\hskip\@@agrightoffset}%
+ \ifnum\backgroundsplitmode=\plusthree \hskip\dimen2 \fi %
+ \localframed[\??ag][\c!offset=\v!overlay]{\box2}% new **
+ \stoplinecorrection
+ \ifcase\backgroundsplit % no split
+ \@@agafter
+ \else % some split
+ \vfill\eject % geen \page !
+ \fi
+ \else
+ \page
+ \fi
+ \ifdim\ht0>\zeropoint \repeat
+ \fi
+ \egroup
+ \endgraf}
+
+%D As a bonus we also have a short command, that is of not
+%D much use, but kept there for historic reasons.
+%D
+%D \showsetup{background}
+
+\def\dobackground
+ {\bgroup
+ \dowithnextbox
+ {\localframed[\??ag][\c!offset=\v!overlay]{\flushnextbox}\egroup}
+ \vbox}
+
+%D \stopdocumentation
+%D \stopbackground
+%D \egroup
+
+%D New, for the moment private; let's see when GB finds out
+%D about this one and its obscure usage. It's used in:
+%D
+%D \startbuffer
+%D \defineframedtext
+%D [tabulateframe]
+%D [offset=overlay,
+%D backgroundoffset=3pt,
+%D background=color,
+%D backgroundcolor=green]
+%D
+%D \setuptabulate
+%D [tabulate]
+%D [frame=tabulateframe]
+%D
+%D \setuptables
+%D [frame=tabulateframe]
+%D
+%D \input tufte
+%D
+%D \starttabulate[|l|l|]
+%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
+%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
+%D \stoptabulate
+%D
+%D \input tufte
+%D
+%D \starttable[|l|l|]
+%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
+%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
+%D \stoptable
+%D \stopbuffer
+%D
+%D \typebuffer
+
+\def\defineframedcontent
+ {\dodoubleempty\dodefineframedcontent}
+
+\def\dodefineframedcontent[#1][#2]%
+ {\presetlocalframed[\??fc#1]%
+ \getparameters[\??fc#1]
+ [\c!leftoffset=\zeropoint,
+ \c!rightoffset=\getvalue{\??fc#1\c!leftoffset},
+ \c!topoffset=\zeropoint,
+ \c!bottomoffset=\getvalue{\??fc#1\c!topoffset},
+ \c!strut=\v!no,
+ \c!offset=\v!overlay,
+ \c!linecorrection=\v!no,
+ \c!left=,
+ \c!right=,
+ #2]}
+
+\let\setuplocalframed\getparameters
+
+\def\setupframedcontent
+ {\dodoubleempty\dosetupframedcontent}
+
+\def\dosetupframedcontent[#1][#2]%
+ {\def\docommand##1{\getparameters[\??fc##1][#2]}%
+ \processcommacommand[#1]\docommand}
+
+\def\startframedcontent[#1]%
+ {\bgroup
+ \let\stopframedcontent\egroup
+ \doifnot{#1}\v!off
+ {\doifdefined{\??fc#1\c!frame}
+ {\def\stopframedcontent{\dostopframedcontent{#1}}%
+ \dostartframedcontent{#1}}}}
+
+\def\dostartframedcontent#1%
+ {\setbox\framebox\hbox\bgroup
+ \setlocalhsize
+ \hsize\localhsize
+ \advance\hsize\dimexpr-\getvalue{\??fc#1\c!leftoffset}-\getvalue{\??fc#1\c!rightoffset} \relax
+ \advance\vsize\dimexpr-\getvalue{\??fc#1\c!topoffset} -\getvalue{\??fc#1\c!bottomoffset}\relax
+ \hskip\getvalue{\??fc#1\c!leftoffset}%
+ \vbox\bgroup
+ \vskip\getvalue{\??fc#1\c!topoffset}%
+ \vbox\bgroup
+ \forgetall
+ \blank[\v!disable]}
+
+\def\dostopframedcontent#1%
+ {\removelastskip
+ \egroup
+ \vskip\getvalue{\??fc#1\c!bottomoffset}%
+ \egroup
+ \hskip\getvalue{\??fc#1\c!rightoffset}%
+ \egroup
+ \doifvalue{\??fc#1\c!width}\v!fit
+ {\letvalue{\??fc#1\c!width}\v!fixed}% no shapebox
+ \ifinsidefloat
+ \donefalse
+ \else
+ \doifelsevalue{\??fc#1\c!linecorrection}\v!yes\donetrue\donefalse
+ \fi
+ % plaats ?
+ \ifdone\startlinecorrection\fi
+ \getvalue{\??fc#1\c!left}% new
+ \localframed[\??fc#1]{\box\framebox}%
+ \getvalue{\??fc#1\c!right}% new
+ \ifdone\stoplinecorrection\fi
+ \egroup}
+
+%D \macros
+%D {backgroundline}
+%D
+%D For the moment an undocumented feature, but a cancidate
+%D for going public.
+
+\def\backgroundline[#1]%
+ %{\doifsomething{#1}{\dobackgroundline{#1}}\hbox}
+ {\doifcolorelse{#1}{\dobackgroundline{#1}\hbox}\hbox}
+
+% \def\backgroundline[#1]%
+% {\doifcolor{#1}{\dobackgroundline{#1}}\hbox}
+
+\def\dobackgroundline#1%
+ {\dowithnextbox
+ {\hbox
+ {\localcolortrue
+ \startcolor[#1]%
+ \vrule
+ \!!width \nextboxwd
+ \!!height\nextboxht
+ \!!depth \nextboxdp
+ \stopcolor
+ \hskip-\nextboxwd
+ \flushnextbox}}}
+
+%D \macros
+%D {encircled}
+%D
+%D Some not so robust left||overs (borrowed from Knuth,
+%D \TEX Book\ page 356):
+
+\def\encircled#1%
+ {{\ooalign{\hfil\raise0.07ex\hbox{{\tx#1}}\hfil\crcr\mathhexbox20D}}}
+
+\let\omcirkeld\encircled
+
+\setuplinewidth
+ [\v!medium]
+
+\setupframed
+ [\c!width=\v!fit,
+ \c!height=\v!broad,
+ \c!lines=,
+ \c!offset=0.25ex, % \defaultframeoffset
+ \c!empty=\v!no,
+ \c!frame=\v!on,
+ \c!topframe=,
+ \c!bottomframe=,
+ \c!leftframe=,
+ \c!rightframe=,
+ \c!radius=.5\bodyfontsize,
+ \c!rulethickness=\linewidth,
+ \c!corner=\v!rectangular,
+ \c!depth=\!!zeropoint,
+ \c!foregroundcolor=,
+ \c!foregroundstyle=,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!backgroundoffset=\!!zeropoint,
+ \c!framecolor=,
+ \c!frameoffset=\!!zeropoint,
+ \c!backgroundcorner=\framedparameter\c!corner,
+ \c!backgroundradius=\framedparameter\c!radius,
+ \c!backgrounddepth=\framedparameter\c!depth,
+ \c!framecorner=\framedparameter\c!corner,
+ \c!frameradius=\framedparameter\c!radius,
+ \c!framedepth=\framedparameter\c!depth,
+ \c!component=,
+ \c!align=,
+ \c!bottom=\vss,
+ \c!top=,
+ \c!strut=\v!yes,
+ \c!autostrut=\v!yes,
+ \c!location=\v!normal,
+ \c!orientation=,
+ \c!autowidth=\v!yes,
+ \c!setups=]
+
+\setupscreens
+ [%\c!factor=1.0, % obsolete
+ %\c!method=\v!external, % obsolete
+ \c!screen=0.95]
+
+\setupblackrules
+ [\c!n=3,
+ \c!width=1em,
+ \c!height=1ex,
+ \c!depth=\!!zeropoint,
+ \c!alternative=\c!a,
+ \c!distance=.25ex,
+ \c!color=]
+
+\setupmarginrules
+ [\c!level=0,
+ \c!rulethickness=\@@kadefaultwidth\linewidth]
+
+\setupthinrules
+ [\c!interlinespace=\v!small,
+ \c!n=3,
+ \c!before=,
+ \c!inbetween={\blank[\v!white]},
+ \c!after=,
+ \c!color=,
+ \c!height=.5\linewidth,
+ \c!depth=.5\linewidth,
+ \c!frame=\v!on, % compatible with textbackgrounds
+ \c!alternative=\v!b,
+ \c!backgroundcolor=,
+ \c!background=,
+ \c!rulethickness=]
+
+\setuptextrules
+ [\c!location=\v!left,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!inbetween=,
+ \c!width=2em,
+ \c!style=\v!bold,
+ \c!color=,
+ \c!rulecolor=,
+ \c!bodyfont=,
+ \c!distance=.5em]
+
+\setupfillinrules
+ [\c!width=\v!broad,
+ \c!distance=1em,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!n=1,
+ \c!interlinespace=\v!small,
+ \c!separator=,
+ \c!style=\v!normal,
+ \c!color=]
+
+\setupfillinlines
+ [\c!width=3cm,
+ \c!margin=\@@ivwidth,
+ \c!distance=1em,
+ \c!before=\blank,
+ \c!after=\blank]
+
+\setupbackground
+ [\c!leftoffset=.5\bodyfontsize,
+ \c!rightoffset=\@@agleftoffset,
+ \c!topoffset=\!!zeropoint,
+ \c!bottomoffset=\@@agtopoffset,
+ \c!state=\v!start,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ \c!frame=\v!off,
+ \c!color=,
+ \c!depth=\!!zeropoint,
+ \c!background=\v!screen,
+ \c!backgroundcolor=\@@agcolor,
+ \c!screen=\@@rsscreen,
+ \c!before=,
+ \c!after=]
+
\protect \endinput
diff --git a/tex/context/base/core-rul.mkiv b/tex/context/base/core-rul.mkiv
index 24e05974d..78c7156b8 100644
--- a/tex/context/base/core-rul.mkiv
+++ b/tex/context/base/core-rul.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-rul,
-%D version=2008.06.05,
+%D version=1998.10.16,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Ruled Stuff Handling,
%D author=Hans Hagen,
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
+\writestatus{loading}{ConTeXt Core Macros / Ruled Content Handling}
%D After a few months testing this solution is now added
%D to the core. This introduces a possible incompatibility
@@ -23,16 +23,263 @@
% 4 lines oeps : 3.6 2.8 3.0
% tufte 7.5 4.1 4.3
-% \newbox\luashapebox
+\unprotect
+
+%D We have removed the rather old and out dated raster methods. They
+%D have not been used for ages.
+
+%D \macros
+%D {linewidth, setuplinewidth}
+%D
+%D This module deals with rules (lines) in several ways. First
+%D we introduce two macros that can be used to set some common
+%D characteristics.
+%D
+%D \showsetup{setuplinewidth}
+%D
+%D The linewidth is available in \type{\linewidth}. The
+%D preset value of .4pt equals the default hard coded \TEX\
+%D rule width.
+
+\newdimen\linewidth
+
+\def\dosetuplinewidth[#1]%
+ {\assigndimension{#1}\linewidth{.2\points}{.4\points}{.6\points}}
+
+\def\setuplinewidth
+ {\dosingleargument\dosetuplinewidth}
+
+%D \macros
+%D {ruledlinewidth, inheritruledlinewidth}
+%D
+%D Inside framed boxed we will use a private dimensions. As
+%D an option one can let the linewidth inherit its value from
+%D this one.
+
+\newdimen\ruledlinewidth \newif\ifinheritruledlinewidth
+
+% %D \TEX\ lacks support for color and even gray scales. The next
+% %D macros can provide a sort of poor mans gray scales as well
+% %D as give access to more suitable methods of rendering. Such a
+% %D method looks like:
+% %D
+% %D \starttyping
+% %D \def\methodegraybox#1#2#3#4#5#6%
+% %D { ... }
+% %D \stoptyping
+% %D
+% %D The string \type{graybox} is a common element in the name,
+% %D so we can have for instance \type {\postscriptgraybox} or
+% %D \type {\texgraybox}. The first three arguments take a
+% %D dimension, the fourth one takes a number between~0 and~1,
+% %D and the last argument specifies a radius of the box when
+% %D rounded corners are used, so:
+% %D
+% %D \startbuffer
+% %D \dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}
+% %D \stopbuffer
+% %D
+% %D \typebuffer
+% %D
+% %D becomes:
+% %D
+% %D %\startlinecorrection
+% %D % \vbox to 1cm{\getbuffer}
+% %D %\stoplinecorrection
+% %D
+% %D \startlinecorrection
+% %D \unprotect
+% %D \vbox to 1cm{\dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}}
+% %D \protect
+% %D \stoplinecorrection
+% %D
+% %D There are two predefined methodes, one uses periods and the
+% %D other uses small rules. The second method is less
+% %D efficient, but sometimes give better results. The dimensions
+% %D of the resullting box are set to zero.
%
-% \def\doreshapeframedbox
-% {\setbox\luashapebox\box\framebox
-% \ctxlua{commands.doreshapeframedbox(\number\luashapebox)}%
-% \setbox\framebox\box\luashapebox}
+% \setvalue{\v!dot graybox}{\processraster\symbol\rasterdot}
+% \setvalue{\v!rule graybox}{\processraster\symbol\rasterbox}
+%
+% \def\rasterdot{\rasterfont.}
+% \def\rasterbox{\hss\vrule\!!width.4pt\!!height.4pt\!!depth\zeropoint}
+%
+% %D Now of course we need:
+%
+% \ifx\rasterfont\undefined \def\rasterfont{\fivepoint} \fi
+%
+% %D We implement two pure \TEX\ based generators, that use
+% %D \type{\leaders} to quickly gerenate the gray pattern. One
+% %D should beware of \DIMENSION\ conflicts, so we use some
+% %D registers above~8. These macros are memory hungry and byte
+% %D spoiling.
+%
+% \def\processraster#1#2#3#4#5#6#7%
+% {\bgroup
+% \forgetall
+% \dontcomplain
+% \dimen10=\onepoint
+% \dimen10=\@@rsfactor\dimen10
+% \dimen10=#5\dimen10
+% \setbox2\hbox to #2
+% {\cleaders\hbox to 2\dimen10{#1\hss}\hss}%
+% \dimen12=#3%
+% \advance\dimen12 #4%
+% % \setbox0\vbox to \dimen12
+% {\cleaders\vbox to 2\dimen10{\box2\vss}\vss}%
+% \setbox0\hbox
+% {\hskip-.5\dimen10\lower0.5\dimen10\copy0
+% \hskip-\wd0\hskip\dimen10\lower1.5\dimen10\box0}%
+% \box0
+% \egroup}
-\def\doreshapeframedbox{\ifvbox\framebox\ctxlua{commands.doreshapeframedbox(\number\framebox)}\fi}
+%D \macros
+%D {setupscreens}
+%D
+%D The previous macro uses a predefined constant
+%D \type{\@@rsfactor}. This factor can be set by:
+%D
+%D \showsetup{setupscreens}
+
+\def\setupscreens
+ {\dodoubleargument\getparameters[\??rs]}
+
+% %D The most appropriate way to call for this feature is
+% %D using \type{\graybox}, which is defined as:
+%
+% \def\graybox{\getvalue{\@@rsmethod graybox}}
+%
+% %D We just introduced two pure \TEX\ methods for generating
+% %D rasters. However, it's far more efficient and comfortable in
+% %D terms of speed, memory usage and file size, to use a driver
+% %D supported method.
+%
+% \setvalue{\v!external graybox}{\setgraybox}
+%
+% %D For compatibility reasons we also define the original one:
+%
+% \setvalue{\v!postscript graybox}{\getvalue{\v!external graybox}}
+%
+% %D A quite valid way of letting drivers do the job, is giving
+% %D a solid rule a gray texture.
+
+%D We will communicate through module specific variables, current
+%D framed parameters and some reserved dimension registers.
+
+\newdimen \frameddimenwd
+\newdimen \frameddimenht
+\newdimen \frameddimendp
+
+%D We don't have to stick to a \TEX\ drawn rule, but
+%D also can use rounded or even fancier shapes, as we will
+%D see later on.
+
+\def\dofilledbox
+ {\bgroup
+ \doifelse{\framedparameter\c!backgroundcorner}\v!rectangular
+ {\dofilledlinedbox}
+ {\ifzeropt\dimexpr\framedparameter\c!backgroundradius\relax % just in case of .x\bodyfontsize
+ \dofilledlinedbox
+ \else
+ \dofilledroundbox
+ \fi}%
+ \egroup}
+
+\def\dophantombox
+ {\hphantom{\dofilledbox}}
+
+\def\dofilledlinedbox
+ {\vrule\!!width\frameddimenwd\!!height\frameddimenht\!!depth\frameddimendp\relax}%
+
+\def\dostrokedroundbox
+ {\doif{\framedparameter\c!frame}\v!on\dodostrokedroundbox}
+
+\def\dodostrokedroundbox
+ {\bgroup
+ \edef\ovalmod{\framedparameter\c!framecorner}%
+ \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
+ \edef\ovalwid{\the\frameddimenwd}%
+ \edef\ovalhei{\the\frameddimenht}%
+ \edef\ovaldep{\the\frameddimendp}%
+ \edef\ovallin{\the\dimexpr\ruledlinewidth}%
+ \edef\ovalrad{\the\dimexpr\framedparameter\c!frameradius}%
+ \let\ovalstr\!!plusone
+ \let\ovalfil\!!zerocount
+% \forcecolorhack
+ \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
+ \egroup}
+
+\def\dofilledroundbox
+ {\bgroup
+ \edef\ovalmod{\framedparameter\c!backgroundcorner}%
+ \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
+ \edef\ovalwid{\the\frameddimenwd}%
+ \edef\ovalhei{\the\frameddimenht}%
+ \edef\ovaldep{\the\frameddimendp}%
+ \edef\ovallin{\the\dimexpr\ruledlinewidth\relax}%
+ \edef\ovalrad{\the\dimexpr\framedparameter\c!backgroundradius\relax}%
+ \let\ovalstr\!!zerocount
+ \let\ovalfil\!!plusone
+% \forcecolorhack
+ \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
+ \egroup}
+
+% a lot of weird corners
+%
+% \startTEXpage
+% \dontleavehmode\framed
+% [corner=0,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green,
+% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse {9}{12}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{13}{16}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{17}{20}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{21}{24}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \vskip1em
+% \dontleavehmode\dostepwiserecurse{25}{28}{1}{\framed
+% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
+% \quad}
+% \stopTEXpage
+
+%D The oval box is drawn using a special macro, depending on
+%D the driver in use.
-% speedup, prelude to dedicated mkiv module
+\def\dograybox % avoid black rules when no gray
+ {\doifelsenothing{\framedparameter\c!backgroundscreen}
+ {\dophantombox}
+ {\raster[\framedparameter\c!backgroundscreen]{\dofilledbox}}}
+
+%D It won't be a surprise that we not only provide gray boxes,
+%D but also colored ones. Here it is:
\def\dobackgroundcolorbox
{\hbox{\faststartcolor[\framedbackgroundcolor]\dofilledbox\faststopcolor}}
@@ -50,9 +297,3379 @@
\dophantombox
\fi}
+%D \macros
+%D {defineoverlay, doifoverlayelse, overlayoffset,
+%D overlaywidth, overlayheight, overlaydepth,
+%D overlaycolor, overlaylinecolor, overlaylinewidth}
+%D
+%D Before we define the macro that actually takes card of the
+%D backgrounds, we introduce overlays. An overlay is something
+%D that contrary to its name lays {\em under} the text. An
+%D example of an overlay definition is:
+%D
+%D \startbuffer[tmp-1]
+%D \defineoverlay
+%D [fancy]
+%D [{\externalfigure
+%D [mp-cont.502]
+%D [width=\overlaywidth,
+%D height=\overlayheight]}]
+%D \stopbuffer
+%D
+%D \typebuffer[tmp-1]
+%D
+%D That for instance can be uses in:
+%D
+%D \startbuffer[tmp-2]
+%D \framed[backgroundachtergrond=fancy]{How Fancy!}
+%D \framed[backgroundachtergrond=fancy,frame=off]{Even More Fancy!}
+%D \stopbuffer
+%D
+%D and looks like:
+%D
+%D \startlinecorrection
+%D \vbox{\baselineskip24pt\getbuffer[tmp-1]\getbuffer[tmp-2]}
+%D \stoplinecorrection
+%D
+%D The formal definition is:
+%D
+%D \showsetup{defineoverlay}
+%D
+%D This macro's definition is a bit obscure, due the many
+%D non||used arguments and the two step call that enable the
+%D setting of the width, height and depth variables.
+%D Multiple backgrounds are possible and are specified as:
+%D
+%D \starttyping
+%D \framed[background={one,two,three}]{Three backgrounds!}
+%D \stoptyping
+%D
+%D Most drawing packages only know width and height. Therefore
+%D the dimensions have a slightly different meaning here:
+%D
+%D \startitemize[packed]
+%D \item \type{\overlaywidth }: width of the overlay
+%D \item \type{\overlayheight}: height plus depth of the overlay
+%D \item \type{\overlaydepth }: depth of the overlay
+%D \stopitemize
+%D
+%D The resulting box is lowered to the right depth.
+
+\def\overlaywidth {\the\hsize\space} % We preset the variables
+\def\overlayheight {\the\vsize\space} % to some reasonable default
+\let\overlaydepth \!!zeropoint % values. The attributes
+\let\overlayoffset \!!zeropoint % of the frame can be (are)
+\let\overlaycolor \empty % set somewhere else.
+\let\overlaylinewidth \!!zeropoint %
+\let\overlaylinecolor \empty %
+
+%D The next register is used to initialize overlays.
+
+\newtoks\everyoverlay
+
+%D An example of an initialization is the following (overlays
+%D can contain text and be executed under an regime where
+%D interlineskip is off).
+
+\appendtoks \oninterlineskip \to \everyoverlay
+
+\def\defineoverlay
+ {\dodoubleargument\dodefineoverlay}
+
+\def\dodefineoverlay[#1][#2]%
+ {\def\docommand##1{\setvalue{\??ov##1}{\executedefinedoverlay{##1}{#2}}}%
+ \processcommalist[#1]\docommand}
+
+\prependtoks
+ \hsize\overlaywidth
+ \vsize\overlayheight
+\to\everyoverlay
+
+\long\def\executedefinedoverlay#1#2%
+ {\bgroup
+ \edef\overlaywidth {\the\frameddimenwd\space}%
+ \edef\overlayheight{\the\dimexpr\frameddimenht+\frameddimendp\relax\space}%
+ \edef\overlaydepth {\the\frameddimendp\space}%
+ \edef\overlaycolor {\framedparameter\c!backgroundcolor}%
+ %\edef\overlaycorner{\framedparameter\c!backgroundcorner}%
+ %\edef\overlayradius{\framedparameter\c!backgroundradius}%
+ \let\overlayoffset\backgroundoffset % we steal this one
+ \setbox\scratchbox\hbox{\lower\overlaydepth\hbox{\the\everyoverlay#2}}%
+ \setbox\scratchbox\hbox
+ {\hskip-.5\dimexpr\wd\scratchbox-\overlaywidth \relax
+ \raise-.5\dimexpr\ht\scratchbox-\frameddimenht\relax % not overlayheight !
+ \box\scratchbox}%
+ \wd\scratchbox\overlaywidth
+ \ht\scratchbox\overlayheight
+ \dp\scratchbox\overlaydepth
+ \startlayoutcomponent{o:#1}{overlay #1}%
+ \box\scratchbox
+ \stoplayoutcomponent
+ \egroup}
+
+%D The empty case is:
+
+\let\executeoverlay\gobblesevenarguments
+
+%D For testing we provide:
+
+\def\doifoverlayelse#1%
+ {\doifdefinedelse{\??ov#1}}
+
+%D We predefine two already familiar backgrounds:
+
+\setvalue{\??ov\v!screen}{\dograybox }
+\setvalue{\??ov\v!color }{\docolorbox}
+
+% %D After all these preparations, the background macro does no
+% %D bring to many surprises. One has to keep in mind that this
+% %D macro starts up a call chain, depending on the background
+% %D one needs:
+% %D
+% %D \startitemize[packed]
+% %D \item a raster, color or user defined shape
+% %D \item square or round corners
+% %D \item a \TEX\ or driver based method
+% %D \stopitemize
+% %D
+% %D The macro can be extended by adding commands to the token
+% %D list register \type {\everybackgroundbox}. For this
+% %D purpose, the name of the current background is available in
+% %D \type {\currentbackgound}.
+
+%D The content of the box will be (temporary) saved in a box. We
+%D also have an extra box for backgrounds.
+
+\newbox\framebox
+\newbox\extraframebox
+
+\newtoks\everybackgroundbox
+
+\let\currentbackground\empty
+
+% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
+% {\bgroup
+% \def\currentbackground{#1}%
+% \the\everybackgroundbox
+% \setbox\extraframebox\hbox
+% {\vbox{\moveleft\backgroundoffset\hbox{\executeifdefined{\??ov\currentbackground}\donothing}}}%
+% \wd\extraframebox\zeropoint % \backgroundwidth
+% \ht\extraframebox\backgroundheight
+% \dp\extraframebox\backgrounddepth
+% \box\extraframebox % \hskip-\backgroundwidth
+% \egroup}
+
+% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
+% {\bgroup
+% \def\currentbackground{#1}%
+% \ifcsname\??ov\currentbackground\endcsname
+% \the\everybackgroundbox
+% \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
+% \wd\extraframebox\zeropoint % \backgroundwidth
+% \ht\extraframebox\backgroundheight
+% \dp\extraframebox\backgrounddepth
+% \box\extraframebox % \hskip-\backgroundwidth
+% \fi
+% \egroup}
+
+\def\dodobackgroundbox
+ {\bgroup
+ \ifcsname\??ov\currentbackground\endcsname
+ \the\everybackgroundbox
+ \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
+ \wd\extraframebox\zeropoint % \backgroundwidth
+ \ht\extraframebox\backgroundheight
+ \dp\extraframebox\backgrounddepth
+ \box\extraframebox % \hskip-\backgroundwidth
+ \fi
+ \egroup}
+
+\def\dododobackgroundbox#1,#2% #2 gobbles spaces
+ {\edef\currentbackground{#1}%
+ \ifx\currentbackground\s!unknown\else
+ \dodobackgroundbox\expandafter\dododobackgroundbox
+ \fi#2}
+
+\let\backgroundoffset\!!zeropoint
+\let\backgrounddepth \!!zeropoint
+\def\backgroundwidth {\the\hsize}
+\def\backgroundheight{\the\vsize}
+
+% todo: also \def\theforegroundbox{#1}
+
+% \def\dobackgroundbox#1%
+% {\setbox\framebox\vbox
+% {\forgetall
+% \boxmaxdepth\maxdimen
+% \scratchdimen \framedparameter{#1}\relax
+% \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
+% \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
+% \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
+% \edef\backgroundoffset{\the\scratchdimen}%
+% \edef\backgroundwidth {\the\wd\framebox}%
+% \edef\backgroundheight{\the\ht\framebox}%
+% \edef\backgrounddepth {\the\dp\framebox}%
+% %\edef\foregroundbox{\box#1}%
+% \def\foregroundbox% fuzzy but needed hack, this \vss, otherwise
+% {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
+% \edef\component{\framedparameter\c!component}%
+% \hbox to \backgroundwidth % in case 'foreground' is used as overlay
+% {\ifx\component\empty
+% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
+% \else
+% \startlayoutcomponent{b:\component}{\s!background\space\component}%
+% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
+% \stoplayoutcomponent
+% \fi
+% \box\framebox\hss}}}
+
+\def\normalforegroundbox% fuzzy but needed hack, this \vss, otherwise
+ {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
+
+\def\dobackgroundbox#1%
+ {\setbox\framebox\vbox
+ {\forgetall
+ \boxmaxdepth\maxdimen
+ \scratchdimen \framedparameter{#1}\relax
+ \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
+ \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
+ \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
+ \edef\backgroundoffset{\the\scratchdimen}%
+ \edef\backgroundwidth {\the\wd\framebox}%
+ \edef\backgroundheight{\the\ht\framebox}%
+ \edef\backgrounddepth {\the\dp\framebox}%
+ %\edef\foregroundbox{\box#1}%
+ \edef\component{\framedparameter\c!component}%
+ \let\foregroundbox\normalforegroundbox
+ \hbox to \backgroundwidth % in case 'foreground' is used as overlay
+ {\ifx\component\empty
+ \normalexpanded{\noexpand\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
+ \else
+ \startlayoutcomponent{b:\component}{background \component}%
+ \normalexpanded{\noexpand\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
+ \stoplayoutcomponent
+ \fi
+ \box\framebox\hss}}}
+
+%D One can explictly insert the foreground box. For that
+%D purpose we introduce the overlay \type {foreground}.
+
+\defineoverlay[\v!foreground][\foregroundbox]
+
+%D We can specify overlays as a comma separated list of
+%D overlays, a sometimes handy feature.
+
+%D Besides backgrounds (overlays) we also need some macros to
+%D draw outlines (ruled borders). Again we have to deal with
+%D square and round corners. The first category can be handled
+%D by \TEX\ itself, the latter one depends on the driver. This
+%D macro also support a negative offset.
+
+\ifx\scratchoffset\undefined \newdimen\scratchoffset \fi
+
+\def\dooutlinebox % we needed to move the color command in order to apply attributes properly
+ {\setbox\framebox\vbox % rules on top of box
+ {\scratchoffset \framedparameter\c!frameoffset\relax
+ \frameddimenwd\dimexpr\wd\framebox+2\scratchoffset\relax
+ \frameddimenht\dimexpr\ht\framebox+ \scratchoffset\relax
+ \frameddimendp\dimexpr\dp\framebox+ \scratchoffset+\framedparameter\c!framedepth\relax
+ \ifdim\frameddimendp<\zeropoint
+ \advance\frameddimenht \frameddimendp
+ \scratchdimen-\frameddimendp
+ \frameddimendp\zeropoint
+ \else
+ \scratchdimen\zeropoint
+ \fi
+ \setbox\extraframebox\hbox
+ {\doifsomething{\framedparameter\c!framecolor}{\color[\framedparameter\c!framecolor]}{\dostrokedbox}}%
+ \setbox\extraframebox\hbox
+ {\raise\scratchdimen\vbox
+ {\moveleft\scratchoffset
+ \box\extraframebox}}%
+ \wd\extraframebox\wd\framebox
+ \ht\extraframebox\ht\framebox
+ \dp\extraframebox\dp\framebox
+ \hbox{\box\framebox\hskip-\wd\extraframebox\box\extraframebox}}}
+
+\def\dostrokedbox
+ {\doifelse{\framedparameter\c!framecorner}\v!rectangular
+ {\dostrokedlinedbox}
+ {\ifzeropt\dimexpr\framedparameter\c!frameradius\relax % just in case of .x\bodyfontsize
+ \dostrokedlinedbox
+ \else
+ \dostrokedroundbox
+ \fi}}
+
+\def\dostrokedlinedbox
+ {\setbox\scratchbox\null
+ \wd\scratchbox\frameddimenwd
+ \ht\scratchbox\frameddimenht
+ \dp\scratchbox\frameddimendp
+ \setbox\scratchbox\vbox \bgroup
+ \csname t\@@frame@@\framedparameter\c!frame\framedparameter\c!topframe \endcsname
+ \hbox \bgroup
+ \csname l\@@frame@@\framedparameter\c!frame\framedparameter\c!leftframe \endcsname
+ \box\scratchbox
+ \csname r\@@frame@@\framedparameter\c!frame\framedparameter\c!rightframe \endcsname
+ \egroup
+ \csname b\@@frame@@\framedparameter\c!frame\framedparameter\c!bottomframe\endcsname
+ \egroup
+ \wd\scratchbox\frameddimenwd
+ \ht\scratchbox\frameddimenht
+ \dp\scratchbox\frameddimendp
+ \box\scratchbox}
+
+\def\@@frame@@{@@frame@@}
+
+% \setvalue{t\@@frame@@\v!on \v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{t\@@frame@@\v!off\v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{t\@@frame@@\v!on }{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{b\@@frame@@\v!on }{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!on \v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!off\v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{l\@@frame@@\v!on }{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+% \setvalue{r\@@frame@@\v!on }{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+
+\def\@@frame@@trule{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
+\def\@@frame@@brule{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
+\def\@@frame@@rrule{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
+\def\@@frame@@lrule{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
+
+\letvalue{t\@@frame@@\v!on \v!on}\@@frame@@trule
+\letvalue{t\@@frame@@\v!off\v!on}\@@frame@@trule
+\letvalue{t\@@frame@@\v!on }\@@frame@@trule
+
+\letvalue{b\@@frame@@\v!on \v!on}\@@frame@@brule
+\letvalue{b\@@frame@@\v!off\v!on}\@@frame@@brule
+\letvalue{b\@@frame@@\v!on }\@@frame@@brule
+
+\letvalue{l\@@frame@@\v!on \v!on}\@@frame@@lrule
+\letvalue{l\@@frame@@\v!off\v!on}\@@frame@@lrule
+\letvalue{l\@@frame@@\v!on }\@@frame@@lrule
+
+\letvalue{r\@@frame@@\v!on \v!on}\@@frame@@rrule
+\letvalue{r\@@frame@@\v!off\v!on}\@@frame@@rrule
+\letvalue{r\@@frame@@\v!on }\@@frame@@rrule
+
+% no overlapping rules
+
+\def\@@frame@@trules{\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}\nointerlineskip\kern-\ruledlinewidth}
+\def\@@frame@@brules{\kern-\ruledlinewidth\nointerlineskip\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}}
+\def\@@frame@@rrules{\kern-\ruledlinewidth\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth}
+\def\@@frame@@lrules{\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth\kern-\ruledlinewidth}
+
+% small is relatively new
+
+\letvalue{t\@@frame@@\v!small\v!small}\@@frame@@trules
+\letvalue{t\@@frame@@\v!off \v!small}\@@frame@@trules
+\letvalue{t\@@frame@@\v!small }\@@frame@@trules
+
+\letvalue{b\@@frame@@\v!small\v!small}\@@frame@@brules
+\letvalue{b\@@frame@@\v!off \v!small}\@@frame@@brules
+\letvalue{b\@@frame@@\v!small }\@@frame@@brules
+
+\letvalue{l\@@frame@@\v!small\v!small}\@@frame@@lrules
+\letvalue{l\@@frame@@\v!off \v!small}\@@frame@@lrules
+\letvalue{l\@@frame@@\v!small }\@@frame@@lrules
+
+\letvalue{r\@@frame@@\v!small\v!small}\@@frame@@rrules
+\letvalue{r\@@frame@@\v!off \v!small}\@@frame@@rrules
+\letvalue{r\@@frame@@\v!small }\@@frame@@rrules
+
+%D I condidered using the low level support command
+%D \type{\ruledhbox}, but this would slow down processing by a
+%D factor~3.
+
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=on,leftframe=on,topframe=on,bottomframe=on]
+% {}
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=small]
+% {}
+% \framed
+% [width=4cm,height=3cm,rulethickness=3mm,
+% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=on]
+% {}
+
+%D The next few macros are probably the most misused ones in
+%D \CONTEXT. They deal with putting rules around boxes, provide
+%D backgrounds, offer alignment features, and some more. We
+%D start with defining some booleans. These give an impression
+%D of what we are going to take into account.
+
+% todo: chardefs
+
+\newif\ifboxhasoffset
+\newif\ifboxhaswidth
+\newif\ifboxhasheight
+\newif\ifboxhasformat
+\newif\ifboxhasstrut
+\newif\ifboxisoverlaid
+\newif\ifboxhasframe
+\newif\ifdelayedstrut
+\newif\ifboxhasextraoffset
+
+%D We also need a few \DIMENSIONS:
+
+\newdimen\@@localoffset
+\newdimen\@@globalwidth
+
+%D \macros
+%D {framed, setupframed}
+%D
+%D Ruled boxes are typeset using \type{\framed}. This command
+%D is quite versatile and, although some users will probably
+%D seldom use it, one cannot overlook its features.
+%D
+%D \showsetup{setupframed}
+%D \showsetup{framed}
+%D
+%D This general macro is a special version of an even more
+%D general case, that can easily be linked into other macros
+%D that need some kind of framing. The local version is called
+%D with an extra parameter: the variable identifier. The reason
+%D for passing this identifier between brackets lays in the
+%D mere fact that this way we can use the optional argument
+%D grabbers.
+
+\def\defaultframeoffset{.25ex}
+
+\def\presetlocalframed [#1]{\letvalue{#1\s!parent}\??oi}
+\def\inheritlocalframed[#1]#2[#3]{\letvalue{#1\s!parent}#3}
+\def\copylocalframed [#1]#2[#3]{\setvalue{#1\s!parent}{#3}}
+
+\presetlocalframed[\??ol]
+
+% \unexpanded\def\framed
+% {\bgroup
+% \dodoubleempty\startlocalframed[\??ol]}
+
+\newcount\framednesting
+
+\unexpanded\def\framed
+ {\bgroup
+ \advance\framednesting\plusone
+ \letvalue{\??ol:\the\framednesting\s!parent}\??ol
+ \dodoubleempty\startlocalframed[\??ol:\the\framednesting]}
+
+\def\setupframed
+ {\dodoubleempty\dosetupframed}
+
+\def\dosetupframed
+ {\ifsecondargument
+ \@EA\dodoublesetupframed
+ \else
+ \@EA\dosinglesetupframed
+ \fi}
+
+\def\dosinglesetupframed[#1][#2]%
+ {\getparameters[\??ol][#1]}
+
+\def\dodoublesetupframed[#1][#2]%
+ {\bgroup
+ \let\dodoubleempty\empty
+ \def\doframed[##1]{\gdef\globalredefinedframed{\dodoubleempty\doframed[##1,#2]}}%
+ \getvalue{#1}%
+ \egroup
+ \letvalue{#1}\globalredefinedframed}
+
+%D \startbuffer
+%D \setupframed [framecolor=yellow] \framed{A}
+%D \defineframed[myframed] [framecolor=blue] \myframed{B}
+%D \setupframed [myframed] [framecolor=red] \myframed{C}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \presetlocalframed[myframed]
+%D \setuplocalframed[myframed][width=4cm,height=2cm]
+%D \localframed[myframed][framecolor=green]{oeps}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {ifinframed}
+%D
+%D The normal case first presets all parameters and next starts
+%D looking for the user supplied ones. The first step is
+%D omitted in the local case, because these are preset at
+%D declaration time and keep their values unless explictly
+%D changed. By presetting the variables everytime the normal
+%D command is called, we can use this command nested, without
+%D the unwanted side effect of inheritance. The boolean is
+%D used to speed up the color stack.
+
+\newif\ifinframed
+
+\def\localframed
+ {\bgroup
+ \dodoubleempty\startlocalframed}
+
+%D The next one is faster on multiple backgrounds per page. No
+%D dimensions can be set, only frames and backgrounds.
+
+\def\fastlocalframed[#1]#2[#3]#4% 3-4
+ {\bgroup
+ \inframedtrue
+ \edef\@@framed{#1}%
+ % some hackery (no \dimexpr)
+ \scratchdimen\framedparameter\c!frameoffset
+ \setevalue{\@@framed\c!frameoffset}{\the\scratchdimen}%
+ \doifnot{\framedparameter\c!backgroundoffset}\v!frame
+ {\scratchdimen\framedparameter\c!backgroundoffset
+ \setevalue{\@@framed\c!backgroundoffset}{\the\scratchdimen}}%
+ % so far
+ \setbox\framebox\hbox{#4}%
+ \getparameters[\@@framed][#3]% no \expanded !
+ % not here, in calling macro: setups
+ \removeframedboxdepth
+ \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
+ \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
+ \edef\overlaylinecolor{\framedparameter\c!framecolor}%
+ \edef\overlaylinewidth{\the\ruledlinewidth}%
+ \edef\@@localframing {\framedparameter\c!frame}%
+ \ifx\@@localframing\v!overlay \else \ifx\@@localframing\v!none \else
+ \edef\framedrulethickness{\framedparameter\c!rulethickness}%
+ \ifx\framedrulethickness\empty\else
+ \ruledlinewidth\framedrulethickness\relax
+ \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
+ \fi
+ \dooutlinebox % real or invisible frame
+ \fi \fi
+ \edef\framedbackground{\framedparameter\c!background}%
+ \ifx\framedbackground\empty\else\dobackedbox\fi
+ \restoreframedboxdepth
+ \box\framebox
+ \egroup}
+
+%D Before we go into details, we present (and implement) the
+%D main framing routine. I saw no real reason for splitting the
+%D next two macros into smaller pieces. The content will be
+%D collected in a horizontal or vertical box with fixed or free
+%D dimensions and specific settings concerning aligment and
+%D offsets.
+%D
+%D In the first few lines, we pre||expand the frame and
+%D background offsets. We do so, because the can be defined in
+%D terms of the main offset. However, see for instance page
+%D backgrounds, when \type {#2} sets the offset to \type
+%D {overlay}, both offsets become invalid.
+%D
+%D Because it is used so often the he next macro is (and
+%D looks) rather optimized.
+
+\let\postprocessframebox\relax
+
+\let\@@framed\s!unknown
+
+\def\framedparameter #1{\csname\doframedparameter\@@framed#1\endcsname}
+\def\framedparameterhash#1{\doframedparameterhash \@@framed#1}
+
+\def\doframedparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doframedparentparameter \csname#1\s!parent\endcsname#2\fi}
+\def\doframedparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doframedparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+
+\def\doframedparentparameter #1#2{\ifx#1\relax\s!empty\else\doframedparameter #1#2\fi}
+\def\doframedparentparameterhash#1#2{\ifx#1\relax \else\doframedparameterhash#1#2\fi}
+
+% \def\s!root{root} % maybe configurable
+
+\def\doframedparentparameter#1#2{\ifx#1\relax\doframedrootparameter#2\else\doframedparameter#1#2\fi}
+\def\doframedrootparameter #1{\ifcsname\??oi#1\endcsname\??oi#1\else\s!empty\fi}
+
+\def\dosetframedattributes#1#2% style color
+ {\edef\fontattributehash {\framedparameterhash#1}%
+ \edef\colorattributehash{\framedparameterhash#2}%
+ \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi
+ \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi}
+
+% defaults, kind of isolated now
+
+\getparameters
+ [\??oi]
+ [\c!width=\v!fit,
+ \c!height=\v!broad,
+ %\c!lines=,
+ \c!offset=0.25ex, % \defaultframeoffset
+ \c!empty=\v!no,
+ \c!frame=\v!on,
+ %\c!topframe=,
+ %\c!bottomframe=,
+ %\c!leftframe=,
+ %\c!rightframe=,
+ \c!radius=.5\bodyfontsize,
+ \c!rulethickness=\linewidth,
+ \c!corner=\v!rectangular,
+ \c!depth=\!!zeropoint,
+ %\c!foregroundcolor=,
+ %\c!foregroundstyle=,
+ %\c!background=,
+ %\c!backgroundscreen=,
+ %\c!backgroundcolor=,
+ \c!backgroundoffset=\!!zeropoint,
+ %\c!framecolor=,
+ \c!frameoffset=\!!zeropoint,
+ \c!backgroundcorner=\framedparameter\c!corner,
+ \c!backgroundradius=\framedparameter\c!radius,
+ \c!backgrounddepth=\framedparameter\c!depth,
+ \c!framecorner=\framedparameter\c!corner,
+ \c!frameradius=\framedparameter\c!radius,
+ \c!framedepth=\framedparameter\c!depth,
+ %\c!component=,
+ %\c!align=,
+ \c!bottom=\vss,
+ %\c!top=,
+ \c!strut=\v!yes,
+ \c!autostrut=\v!yes,
+ \c!location=\v!normal,
+ %\c!orientation=,
+ \c!autowidth=\v!yes,
+ %\c!setups=
+]
+
+\getparameters
+ [\??od] % for fast version
+ [\c!frame=\v!off,
+ \c!depth=\zeropoint,
+ \c!offset=\v!overlay,
+ %\c!component=,
+ \c!radius=.5\bodyfontsize,
+ \c!rulethickness=\linewidth,
+ \c!corner=\v!rectangular,
+ \c!backgroundoffset=\!!zeropoint,
+ \c!frameoffset=\!!zeropoint,
+ \c!backgroundcorner=\framedparameter\c!corner,
+ \c!backgroundradius=\framedparameter\c!radius,
+ \c!backgrounddepth=\framedparameter\c!depth,
+ \c!framecorner=\framedparameter\c!corner,
+ \c!frameradius=\framedparameter\c!radius,
+ \c!framedepth=\framedparameter\c!depth,
+ \c!location=\v!normal]
+
+% so far
+
+\newdimen\!!framedwidth
+\newdimen\!!framedheight
+\newdimen\!!framedscratch % so that users can use \scratchdimen
+
+\let\setextraframedoffsets \relax
+\let\applyextraframedoffsets\relax
+
+\def\startlocalframed[#1][#2]%
+ {\bgroup
+ \inframedtrue
+ \edef\@@framed{#1}%
+ % this piece of pre expansion is needed (sometimes used circular)
+ \!!framedscratch\framedparameter\c!frameoffset
+ \setevalue{\@@framed\c!frameoffset}{\the\!!framedscratch}%
+ \doifnot{\framedparameter\c!backgroundoffset}\v!frame
+ {\!!framedscratch\framedparameter\c!backgroundoffset
+ \setevalue{\@@framed\c!backgroundoffset}{\the\!!framedscratch}}%
+ % to prevent deadlock in case of self refering
+ \ifsecondargument % faster
+ \getparameters[\@@framed][#2]% here !
+ \fi
+ % new, experimental dirty hook
+ \framedparameter\c!extras
+ % to get the right spacing
+ \doifsomething{\framedparameter\c!foregroundstyle}
+ {\@EA\doconvertfont\csname\@@framed\c!foregroundstyle\endcsname\empty}%
+ % beware, both the frame and background offset can be overruled
+ %
+ \edef\doframedsetups{\framedparameter\c!setups}%
+ \ifx\doframedsetups\empty\else
+ \edef\doframedsetups{\noexpand\setups[\doframedsetups]}%
+ \fi
+ % the next macros are visible
+ \edef\localoffset{\framedparameter\c!offset}%
+ \edef\localwidth {\framedparameter\c!width}%
+ \edef\localheight{\framedparameter\c!height}%
+ \edef\localformat{\framedparameter\c!align}%
+ \edef\localstrut {\framedparameter\c!strut}%
+ % these are not
+ \edef\@@localautostrut {\framedparameter\c!autostrut}%
+ \edef\@@localframing {\framedparameter\c!frame}%
+ \edef\@@locallocation {\framedparameter\c!location}%
+ \edef\@@localorientation{\framedparameter\c!orientation}%
+ %
+ \edef\@@localautowidth {\framedparameter\c!autowidth}%
+ %
+ \ifx\@@localframing\v!overlay % no frame, no offset, no framewidth
+ \boxhasframefalse
+ \let\localoffset\v!overlay
+ \else\ifx\@@localframing\v!none % no frame, no framewidth
+ \boxhasframefalse
+ \else
+ \boxhasframetrue
+ \fi\fi
+ \ifboxhasframe
+ \edef\framedrulethickness{\framedparameter\c!rulethickness}%
+ \ifx\framedrulethickness\empty\else
+ \ruledlinewidth\framedrulethickness\relax
+ \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
+ \fi
+ \else
+ \ruledlinewidth\zeropoint
+ \fi
+ \ifx\localformat\empty
+ \boxhasformatfalse
+ \else
+ \boxhasformattrue
+ \dosetraggedcommand\localformat
+ \edef\dobeforeframedbox{\raggedtopcommand\framedparameter\c!top}%
+ \edef\doafterframedbox {\framedparameter\c!bottom\raggedbottomcommand}%
+ \fi
+ \ifx\localoffset\v!none
+ \boxhasoffsetfalse
+ \boxhasstrutfalse
+ \boxisoverlaidfalse
+ \@@localoffset\ruledlinewidth
+ \else\ifx\localoffset\v!overlay
+ % \ifx\@@localframing\v!no \boxhasframefalse \fi % test first
+ \boxhasoffsetfalse
+ \boxhasstrutfalse
+ \boxisoverlaidtrue
+ \@@localoffset\zeropoint
+ \else
+ \boxhasoffsettrue
+ \boxhasstruttrue
+ \boxisoverlaidfalse
+ \ifx\localoffset\v!default % new per 2-6-2000
+ \let\localoffset\defaultframeoffset
+ \letvalue{\@@framed\c!offset}\defaultframeoffset
+ \else
+ \let\defaultframeoffset\localoffset
+ \fi
+ \@@localoffset\dimexpr\localoffset+\ruledlinewidth\relax
+ \fi\fi
+ \!!framedheight\zeropoint
+ \!!framedwidth \zeropoint
+ \ifx\localwidth\v!fit
+ \ifboxhasformat
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else
+ \boxhaswidthfalse
+ \fi
+ \else\ifx\localwidth\v!fixed % equals \v!fit but no shapebox
+ \ifboxhasformat
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else
+ \boxhaswidthfalse
+ \fi
+ \else\ifx\localwidth\v!broad
+ \boxhaswidthtrue
+ \!!framedwidth\hsize
+ \else\ifx\localwidth\v!local
+ \boxhaswidthtrue
+ \setlocalhsize
+ \!!framedwidth\localhsize
+ \else
+ \boxhaswidthtrue
+ \!!framedwidth\localwidth
+ \fi\fi\fi\fi
+ \ifx\localheight\v!fit
+ \boxhasheightfalse % no longer: \boxhasstrutfalse
+ \else\ifx\localheight\v!broad
+ \boxhasheightfalse
+ \else
+ \boxhasheighttrue
+ \!!framedheight\localheight
+ \fi\fi
+ \ifboxhasheight
+ % obey user set height, also downward compatible
+ \else
+ \doifsomething{\framedparameter\c!lines}
+ {\ifcase\framedparameter\c!lines\else
+ \!!framedheight\framedparameter\c!lines\lineheight
+ \edef\localheight{\the\!!framedheight}%
+ \boxhasheighttrue
+ \fi}%
+ \fi
+ % this is now an option: width=local
+ %
+ % \ifdim\!!framedwidth=\hsize
+ % \parindent\zeropoint
+ % \setlocalhsize
+ % \!!framedwidth\localhsize
+ % \fi
+ % i.e. disable (colsetbackgroundproblemintechniek)
+ \advance\!!framedwidth -2\@@localoffset
+ \advance\!!framedheight -2\@@localoffset
+ \ifx\localstrut\v!no
+ \boxhasstrutfalse
+ \else\ifx\localstrut\v!global
+ \setstrut
+ \else\ifx\localstrut\v!local
+ \setfontstrut
+ \else
+ \setstrut
+ \fi\fi\fi
+ \ifboxhasstrut
+ \let\localbegstrut\begstrut
+ \let\localendstrut\endstrut
+ \let\localstrut \strut
+ \else
+ \let\localbegstrut\pseudobegstrut % was: \relax
+ \let\localendstrut\pseudoendstrut % was: \relax
+ \let\localstrut \pseudostrut % was: \relax
+ %\ifboxhasheight\ifdim\!!framedheight<\strutht % saveguard
+ % \let\localbegstrut\relax % but not that
+ % \let\localstrut \relax % save after all
+ %\fi\fi
+ \fi
+ \ifx\@@localautostrut\v!yes
+ \let\delayedbegstrut\relax
+ \let\delayedendstrut\relax
+ \let\delayedstrut \relax
+ \else
+ \let\delayedbegstrut\localbegstrut
+ \let\delayedendstrut\localendstrut
+ \let\delayedstrut \localstrut
+ \let\localbegstrut \relax
+ \let\localendstrut \relax
+ \let\localstrut \relax
+ \fi
+ \ifboxhasheight
+ \let\\\vboxednewline
+ \ifboxhaswidth
+ \let\hairline\vboxedhairline
+ \ifboxhasformat
+ \let\next\doformatboxSomeFormat
+ \else
+ \let\next\doformatboxNoFormat
+ \fi
+ \else
+ \let\hairline\hboxedhairline
+ \ifboxhasformat
+ \let\next\doformatboxHeight
+ \else
+ \let\next\doformatboxVSize
+ \fi
+ \fi
+ \else
+ \ifboxhaswidth
+ \ifboxhasformat
+ \let\hairline\vboxedhairline
+ \let\\\vboxednewline
+ \let\next\doformatboxWidth
+ \else
+ \let\hairline\hboxedhairline
+ \let\\\hboxednewline
+ \let\next\doformatboxHSize
+ \fi
+ \else
+ \let\hairline\hboxedhairline
+ \let\\\hboxednewline
+ \let\next\doformatboxNoSize
+ \fi
+ \fi
+ \setextraframedoffsets
+ \edef\framedwidth % a new feature, visible for user
+ {\ifdim\!!framedwidth >\zeropoint\the\!!framedwidth \else\zeropoint\fi}%
+ \edef\framedheight% a new feature, visible for user
+ {\ifdim\!!framedheight>\zeropoint\the\!!framedheight\else\zeropoint\fi}%
+ % we need to register the (outer) color
+ \startregistercolor[\framedparameter\c!foregroundcolor]%
+ % first alternative
+ %\def\dowithframedbox%
+ % {\let\postprocessframebox\relax %new
+ % \aftergroup\stoplocalframed}%
+ % \afterassignment\dowithframedbox
+ % \setbox\framebox=\next}
+ % second alternative
+ %\dowithnextbox
+ % {\setbox\framebox\flushnextbox
+ % \let\postprocessframebox\relax %new
+ % \stoplocalframed}
+ % \next}
+ \@@startframedorientation
+ \afterassignment\dodowithframebox
+ \setbox\framebox\next}
+
+\def\dowithframebox
+ {% moved : \let\postprocessframebox\relax
+ \stoplocalframed}
+
+\def\dodowithframebox
+ {\aftergroup\dowithframebox}
+
+\let\doafterframedbox \relax
+\let\dobeforeframedbox\relax
+
+%D Carefull analysis of this macro will learn us that not all
+%D branches in the last conditionals can be encountered, that
+%D is, some assignments to \type{\next} will never occur.
+%D Nevertheless we implement the whole scheme, if not for
+%D future extensions.
+
+%D \macros
+%D {ifreshapeframebox}
+%D
+%D The last few lines tell what to do after the content of the
+%D box is collected and passed to the next macro. In the case
+%D of a fixed width and centered alignment, the content is
+%D evaluated and used to determine the most natural width. The
+%D rest of the code deals with backgrounds and frames.
+
+\newif\ifreshapeframebox \reshapeframeboxtrue
+
+%D Beware: setting \type {top} and \type {bottom} to nothing, may
+%D result in a frame that is larger that the given height! try:
+%D
+%D \starttyping
+%D \framed
+%D [height=3cm,top=,bottom=,offset=overlay]
+%D {\strut test \shapefill \strut test}
+%D \stoptyping
+%D
+%D This is intended behaviour and not a bug! One can always set
+%D
+%D \starttyping
+%D ...,bottom=\kern0pt,...
+%D \stoptyping
+
+\def\stoplocalframed
+ {\dontshowcomposition
+ \@@stopframedorientation % hm, wrong place ! should rotate the result (after reshape)
+ \stopregistercolor
+ \handleframedlocator\c!before\@@locallocation
+ \ifboxhasformat
+ \ifx\@@localautowidth\v!force
+ \ifreshapeframebox\doreshapeframedbox\fi
+ \boxhaswidthfalse
+ \else
+ \ifx\localwidth\v!fit
+ \ifx\@@localautowidth\v!yes
+ \ifreshapeframebox\doreshapeframedbox\fi
+ \fi
+ \boxhaswidthfalse
+ \else\ifx\localwidth\v!fixed
+ \boxhaswidthfalse
+ \else
+ \resetshapeframebox
+ \fi\fi
+ \fi
+\ifconditional\boxcontentneedsprocessing
+ \mkdoprocessboxcontents\framebox
+\fi
+ \else
+ \resetshapeframebox
+ \fi
+ \ifboxhaswidth
+ \wd\framebox\!!framedwidth
+ \fi
+ \ifboxhasheight
+ \ht\framebox\!!framedheight
+ \fi
+ \doif{\framedparameter\c!empty}\v!yes
+ {\setbox\scratchbox\null
+ \wd\scratchbox\wd\framebox
+ \ht\scratchbox\ht\framebox
+ \dp\scratchbox\dp\framebox
+ \setbox\framebox\box\scratchbox}%
+ \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
+ \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
+ \ifboxhasextraoffset
+ \applyextraframedoffsets
+ \fi
+ \ifboxhasoffset
+ \dooffsetframebox
+ \fi
+ \ifboxisoverlaid \else
+ \dolocateframebox
+ \fi
+ \ifx\postprocessframebox\relax \else
+ \let\next\postprocessframebox
+ \let\postprocessframebox\relax % prevent nesting
+ \next\framebox
+ \fi
+ \edef\overlaylinecolor{\framedparameter\c!framecolor}%
+ \edef\overlaylinewidth{\the\ruledlinewidth}% \@@...
+ \ifboxhasframe % real or invisible frame
+ \dooutlinebox
+ \fi
+ \edef\framedbackground{\framedparameter\c!background}%
+ \ifx\framedbackground\empty\else\dobackedbox\fi
+ \handleframedlocator\c!after\@@locallocation
+ \box\framebox
+ \egroup
+ \egroup}
+
+\def\installframedlocator#1#2#3%
+ {\setvalue{\??oi:\c!location:\c!before:#1}{#2}%
+ \setvalue{\??oi:\c!location:\c!after :#1}{#3}}
+
+\def\handleframedlocator#1#2%
+ {\getvalue{\??oi:\c!location:#1:#2}}
+
+\def\doprelocframedbox#1%
+ {\scratchdimen\dimexpr#1+\ruledlinewidth\relax
+ \ifboxhasoffset
+ \advance\scratchdimen \framedparameter\c!offset
+ \fi
+ \scratchskip\dimexpr\ht\framebox-\scratchdimen\relax}
+
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
+% \framed[width=2cm,align=middle,location=depth] {location\\equals\\depth}
+% \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
+% B}
+% \vskip2cm
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=low] {location\\equals\\low}
+% \framed[width=2cm,align=middle,location=line] {location\\equals\\line}
+% \framed[width=2cm,align=middle,location=high] {location\\equals\\high}
+% B}
+% \vskip2cm
+% \ruledhbox
+% {A
+% \framed[width=2cm,align=middle,location=top] {location\\equals\\top}
+% \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
+% \framed[width=2cm,align=middle,location=lohi] {location\\equals\\lohi}
+% \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
+% B}
+
+\installframedlocator \v!hanging % best with strut=no
+ {}
+ {\dp\framebox\ht\framebox
+ \ht\framebox\zeropoint}
+
+\installframedlocator \v!depth
+ {}
+ {\ht\framebox\dimexpr\ht\framebox-\strutdp\relax
+ \dp\framebox\strutdp
+ \box\framebox}
+
+\installframedlocator \v!height
+ {}
+ {\dp\framebox\dimexpr\ht\framebox-\strutht\relax
+ \ht\framebox\strutht
+ \box\framebox}
+
+\installframedlocator \v!high
+ {}
+ {\doprelocframedbox\strutht
+ \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!line
+ {}
+ {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}%
+ \ht\framebox.5\lineheight
+ \dp\framebox.5\lineheight
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!low
+ {}
+ {\doprelocframedbox\strutdp
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \box\framebox}
+
+\installframedlocator \v!top
+ {}
+ {\doprelocframedbox\strutht
+ \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
+ \ht\framebox\scratchdimen
+ \dp\framebox\scratchskip
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!middle
+ {}
+ {\scratchdimen.5\ht\framebox
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\scratchdimen
+ \dp\framebox\scratchdimen
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!lohi
+ {\handleframedlocator\c!before\v!middle}
+ {\handleframedlocator\c!after \v!middle}
+
+\installframedlocator \v!bottom
+ {}
+ {\doprelocframedbox\strutdp
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\scratchskip
+ \dp\framebox\scratchdimen
+ \hbox{\box\framebox}}
+
+\installframedlocator \v!keep % retains height/depth
+ {\removeframedboxdepth}
+ {\restoreframedboxdepth}
+
+% also used in fastlocalframed
+
+\newdimen\originalframedwd
+\newdimen\originalframedht
+\newdimen\originalframeddp
+
+\def\removeframedboxdepth
+ {\originalframedwd\wd\framebox
+ \originalframedht\ht\framebox
+ \originalframeddp\dp\framebox
+ \ifzeropt\originalframeddp\else\setbox\framebox\hbox{\raise\originalframeddp\box\framebox}\fi
+ \wd\framebox\originalframedwd
+ \ht\framebox\dimexpr\originalframedht+\originalframeddp\relax
+ \dp\framebox\zeropoint}
+
+\def\restoreframedboxdepth
+ {\ifzeropt\originalframeddp\else\setbox\framebox\hbox{\lower\originalframeddp\box\framebox}\fi
+ \wd\framebox\originalframedwd
+ \ht\framebox\originalframedht
+ \dp\framebox\originalframeddp}
+
+% \let\@@startframedorientation\relax
+% \let\@@stopframedorientation \relax
+
+% \framed[width=12cm,height=3cm,orientation=0]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=90]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=180]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=270]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-90]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-180]{\input ward\relax}
+% \framed[width=12cm,height=3cm,orientation=-270]{\input ward\relax}
+
+\def\@@startframedorientation
+ {\let\@@stopframedorientation \relax
+ \ifx\@@localorientation\empty\else
+ \ifcase\@@localorientation\else
+ \scratchcounter\@@localorientation
+ \divide\scratchcounter\plustwo
+ \ifodd\scratchcounter
+ \swapmacros\framedwidth \framedheight
+ \swapmacros\localwidth \localheight
+ \swapdimens\!!framedheight\!!framedwidth
+ \def\@@stopframedorientation{\@@dostopframedorientation\plusone}%
+ \else
+ \def\@@stopframedorientation{\@@dostopframedorientation\zerocount}%
+ \fi
+ \fi
+ \fi}
+
+\def\@@dostopframedorientation#1%
+ {\ifcase#1\else
+ \swapmacros\framedwidth \framedheight
+ \swapmacros\localwidth \localheight
+ \swapdimens\!!framedheight\!!framedwidth
+ \fi
+ \setbox\framebox\hbox{\dorotatebox\@@localorientation\hbox{\box\framebox}}}
+
+%D The last conditional takes care of the special situation of
+%D in||line \inframed[height=3cm]{framed} boxes. Such boxes have
+%D to be \inframed{aligned} with the running text.
+
+\def\doinframed[#1]% we could omit #1] but readibility ...
+ {\framed[\c!location=\v!low,#1]}
+
+\unexpanded\def\inframed
+ {\dosingleempty\doinframed}
+
+%D When we set \type{empty} to \type{yes}, we get
+%D ourselves a frame and/or background, but no content, so
+%D actually we have a sort of phantom framed box.
+
+%D Because color marks and specials can interfere with
+%D spacing, we provide a way to specify a foregroundcolor.
+
\def\docolorframebox
{\doifcolor\framedforegroundcolor
{\setbox\framebox\hbox{\faststartcolor[\framedforegroundcolor]\box\framebox\faststopcolor}}}
%{\setbox\framebox\hbox{\doactivatecolor\framedforegroundcolor\box\framebox}}}
+%D \macros
+%D {mframed, minframed}
+%D
+%D When Tobias asked how to frame mathematical elements in
+%D formulas, Taco's posted the next macro:
+%D
+%D \starttyping
+%D \def\mframed#1%
+%D {\relax
+%D \ifmmode
+%D \vcenter{\hbox{\framed{$\ifinner\else\displaystyle\fi#1$}}}%
+%D \else
+%D \framed{$#1$}%
+%D \fi}
+%D \stoptyping
+%D
+%D Because \type {\ifinner} does not (always) reports what
+%D one would expect, we move the test to the outer level. We
+%D also want to pass arguments,
+%D
+%D \starttyping
+%D \def\mframed%
+%D {\dosingleempty\domframed}
+%D
+%D \def\domframed[#1]#2% % tzt \dowithnextmathbox ?
+%D {\relax
+%D \ifmmode
+%D \ifinner
+%D \inframed[#1]{$#2$}%
+%D \else
+%D \vcenter{\hbox{\framed[#1]{$\displaystyle#2$}}}%
+%D \fi
+%D \else
+%D \inframed[#1]{$#2$}%
+%D \fi}
+%D \stoptyping
+%D
+%D Still better is the next alternative, if only because it
+%D takes care of setting the super- and subscripts styles
+
+\newcount\mframedstyle
+
+\def\doinlinemframed[#1]#2%
+ {\begingroup
+ \mframedstyle\mathstyle\relax
+ \inframed[#1]{$\triggermathstyle\mframedstyle#2$}%
+ \endgroup}
+
+\def\dodisplaymframed[#1]#2%
+ {\begingroup
+ \mframedstyle\mathstyle\relax
+ \def\normalstrut{$\triggermathstyle\mframedstyle\vphantom{(}$}%
+ \framed[#1]{$\triggermathstyle\mframedstyle#2$}%
+ \endgroup}
+
+\def\mframed {\dosingleempty\dodisplaymframed}
+\def\inmframed{\dosingleempty\doinlinemframed }
+
+%D So instead of the rather versatile \type {\framed}, we ue
+%D the \type {\mframed}.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y^{z_z}
+%D x \times \inmframed{y} \times y^{z_z}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D However, we got into troubles when we want to nest sub- and
+%D superscripts, like in
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y^{\mframed{z}_{\mframed{z}}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D Therefore, we can best use \type {\super} and \type {\suber}
+%D instead of \type {^} and \type {_}. Both commands take care
+%D of proper font switching.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times \mframed{y} \times y\super{\mframed{z}\suber{\mframed{z}}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D As usual, one can specify in what way the text should be
+%D framed. One should be aware of the fact that, inorder to
+%D preserve the proper spacing, the \type {offset} is set to
+%D \type {overlay} and \type {frameoffset} is used used
+%D instead.
+%D
+%D \startbuffer
+%D \startformula
+%D x \times y\super{\mframed[framecolor=red]{z}\suber{z}}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D For inline use, we also provide the \type {\inmframed}
+%D alternative: we want $x \times \inmframed{y}$ in inline
+%D math, right?
+
+%D This previous framing macros needs a lot of alternatives for
+%D putting rules around boxes, inserting offsets and aligning
+%D text. Each step is handled by separate macros.
+
+\def\dowidenframebox#1%
+ {\setbox\framebox\vbox
+ {\kern#1\hbox{\kern#1\box\framebox\kern#1}\kern#1}}
+
+\def\dooffsetframebox{\dowidenframebox\localoffset}
+\def\dolocateframebox{\dowidenframebox\ruledlinewidth}
+
+%D Let's hope that the next few examples show us enough of
+%D what needs to be done by the auxiliary macros.
+%D
+%D \startbuffer
+%D \framed[height=1cm,offset=.5cm] {rule based learning}
+%D \framed[height=1cm,offset=0cm] {rule based learning}
+%D \framed[height=1cm,offset=none] {rule based learning}
+%D \framed[height=1cm,offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[offset=.5cm] {rule based learning}
+%D \framed[offset=0cm] {rule based learning}
+%D \framed[offset=none] {rule based learning}
+%D \framed[offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[strut=nee,offset=.5cm] {rule based learning}
+%D \framed[strut=nee,offset=0cm] {rule based learning}
+%D \framed[strut=nee,offset=none] {rule based learning}
+%D \framed[strut=nee,offset=overlay]{rule based learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D \startbuffer
+%D \framed[width=3cm,align=left] {rule\\based\\learning}
+%D \framed[width=3cm,align=middle] {rule\\based\\learning}
+%D \framed[width=3cm,align=right] {rule\\based\\learning}
+%D \framed[width=fit,align=middle] {rule\\based\\learning}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\dontcomplain\getbuffer}
+%D \stoplinecorrection
+%D
+%D So now we're ready for the complicated stuff. We distinguish
+%D between borders with straight lines and those with round
+%D corners. When using the first alternative it is possible to
+%D turn off one or more lines. More fancy shapes are also
+%D possible by specifying dedicated backgrounds. Turning lines
+%D on and off is implemented as efficient as possible and as a
+%D result is interface language dependant. This next
+%D implementation evolved from simpler ones. It puts for
+%D instance the rules on top of the content and provides
+%D additional offset capabilities. The lot of calls to other
+%D macros makes this mechanism not that easy to comprehend.
+
+%D Getting the backgrounds right takes less code. Again we
+%D have to take care of additional offsets.
+
+\def\dobackedbox
+ {\doifelsevalue{\@@framed\c!backgroundoffset}\v!frame % new
+ {\dobackgroundbox\c!frameoffset}
+ {\dobackgroundbox\c!backgroundoffset}}
+
+%D We handle left, right or middle alignment as well as fixed
+%D or free widths and heights. Each combination gets its own
+%D macro.
+
+%D The following code handles one-liners: \type{align={line,flushright}}.
+%D Beware, since we entered a group and either or not grab the next
+%D bgroup token, we need to finish the group in the oneliner mode.
+
+\ifx\raggedoneliner\undefined \chardef\raggedoneliner\zerocount \fi
+
+\def\doformatonelinerbox % beware: assumes explicit preceding bgroup
+ {\ifcase\raggedoneliner
+ \expandafter\nodoformatonelinerbox
+ \else
+ \expandafter\dodoformatonelinerbox
+ \fi}
+
+\def\dodoformatonelinerbox
+ {\dowithnextboxcontent
+ {\ignorespaces}
+ {\hbox to \hsize
+ {\ifcase\raggedstatus\or\hss\or\hss\fi
+ \unhbox\nextbox \removeunwantedspaces
+ \ifcase\raggedstatus\or \or\hss\or\hss\fi}%
+ \egroup}
+ \hbox}
+
+\def\nodoformatonelinerbox % grabs {
+ {\let\next=}
+
+%D The handlers:
+
+\def\doformatboxSomeFormat
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \vsize\!!framedheight
+ \doframedsetups
+ \raggedcommand
+ \dobeforeframedbox
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\doafterframedbox
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxNoFormat
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \vsize\!!framedheight
+ \doframedsetups
+ \raggedcenter
+ \vss
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\vss
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxHeight
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \doframedsetups
+ \raggedcommand
+ \vss
+ \bgroup
+ \aftergroup\localendstrut
+ \aftergroup\vss
+ \aftergroup\egroup
+ \localbegstrut
+ \doformatonelinerbox}
+
+\def\doformatboxWidth
+ {\vbox
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \oninterlineskip
+ \hsize\!!framedwidth
+ \doframedsetups
+ \raggedcommand
+ \dobeforeframedbox
+ \bgroup
+ \localbegstrut
+ \aftergroup\localendstrut
+ \aftergroup\doafterframedbox
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxVSize
+ {\vbox to \!!framedheight
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \vsize\!!framedheight
+ \doframedsetups
+ \vss
+ \bgroup
+ \aftergroup\vss
+ \aftergroup\egroup
+ \hbox
+ \bgroup
+ \aftergroup\egroup
+ \localstrut
+ \doformatonelinerbox}
+
+\def\doformatboxHSize
+ {\hbox to \!!framedwidth
+ \bgroup
+ \let\postprocessframebox\relax
+ \forgetall
+ \doframedsetups
+ \hss
+ \localstrut
+ \bgroup
+ \aftergroup\hss
+ \aftergroup\egroup
+ \doformatonelinerbox}
+
+\def\doformatboxNoSize
+ {\hbox
+ \bgroup
+ \let\postprocessframebox\relax
+ \doframedsetups
+ \localstrut
+ \doformatonelinerbox}
+
+\let\doframedsetups\relax
+
+%D On the next page we show some examples of how these macros
+%D come into action. The examples show us how
+%D \type {fit}, \type {broad} dimensions influence the
+%D formatting. Watch the visualized struts. \footnote {Here we
+%D used \type {\showstruts}.}
+%D
+%D \startpostponing
+%D \bgroup
+%D \showstruts
+%D \dontcomplain
+%D \startlinecorrection
+%D \halign{#\enskip\enskip\enskip\enskip\enskip\cr
+%D \framed[width=.2\hsize, height=.2\hsize, align=] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=yes] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=yes] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=yes] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=yes] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=right] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=right] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=right] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=right] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=left] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=left] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=left] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=left] {a\par b\par c}\cr
+%D \noalign{\vskip1em}
+%D \framed[width=.2\hsize, height=.2\hsize, align=middle] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=broad, align=middle] {a\par b\par c}&
+%D \framed[width=.2\hsize, height=fit, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=.2\hsize, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=broad, align=middle] {a\par b\par c}&
+%D \framed[width=fit, height=fit, align=middle] {a\par b\par c}\cr}
+%D \stoplinecorrection
+%D \blank[2*big]
+%D \egroup
+%D \stoppostponing
+
+%D \macros
+%D {framednoflines, framedlastlength}
+%D
+%D It is possible to let the frame macro calculate the width
+%D of a centered box automatically (\type {fit}). When
+%D doing so, we need to reshape the box:
+
+% The next implementation is frozen! It preserves the depth,
+% otherwise we get problems with framed display math and auto
+% width.
+
+\newcount\framednoflines
+\newdimen\framedlastlength
+
+\def\resetshapeframebox
+ {\framednoflines \zerocount
+ \framedlastlength\zeropoint}
+
+\let\framedboxwidth \!!zeropoint
+\let\framedboxheight\!!zeropoint
+\let\framedboxdepth \!!zeropoint
+
+\chardef\reshapeframeboxmethod\plusone % 0=no flush, 1=old method 2=no depth messing
+
+% \newbox\luashapebox
+%
+% \def\doreshapeframedbox
+% {\setbox\luashapebox\box\framebox
+% \ctxlua{commands.doreshapeframedbox(\number\luashapebox)}%
+% \setbox\framebox\box\luashapebox}
+
+\def\doreshapeframedbox{\ifvbox\framebox\ctxlua{commands.doreshapeframedbox(\number\framebox)}\fi}
+
+%D The two variables \type {\framednoflines} and \type
+%D {\framedlastlength} can be used in a second pass to
+%D optimized framed material.
+
+% torture test / strange case (much depth) / method 2 needed
+%
+% \startTEXpage[frame=on]
+% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
+% test outside formula
+% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
+% \blank[big]
+% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
+% test outside formula
+% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
+% \stopTEXpage
+
+%D The examples on the next page show how one can give the
+%D frame as well as the background an additional offset and
+%D even a bit more depth. The blue outline is the frame, the
+%D red box is the background and the small black outline is the
+%D visualization of the resulting box, that is, we applied
+%D \type{\ruledhbox} to the result.
+
+%D \startpostponing
+%D \bgroup
+%D \unprotect
+%D \dontcomplain
+%D
+%D \startbuffer
+%D \vbox to \vsize
+%D \bgroup
+%D \startalignment[middle]
+%D \vss
+%D \dontleavehmode\vbox to .8\vsize
+%D \bgroup
+%D \hsize=300pt
+%D \setupframed
+%D [background=color,
+%D backgroundcolorachtergrondkleur=darkred,
+%D width=300pt,
+%D height=60pt,
+%D framecolorkaderkleur=DemoBlue,
+%D rulethickness=2pt]
+%D \def\status%
+%D {backgroundoffset=\framedparameter\c!backgroundoffset\\
+%D frameoffset=\framedparameter\c!frameoffset\\
+%D depth=\framedparameter\c!depth}
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=0pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=0pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=5pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=2pt,frameoffset=5pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=2pt]{\status}}
+%D \vss
+%D \dontleavehmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=5pt]{\status}}
+%D \egroup
+%D \vss
+%D \stopalignment
+%D \egroup
+%D \stopbuffer
+%D
+%D \getbuffer \page
+%D
+%D {\setupframed[depth=4pt]\getbuffer} \page
+%D
+%D \protect
+%D \egroup
+%D \stoppostponing
+
+%D When typesetting the framed box inline, we have to keep the
+%D baseline intact outside as well as inside the framed box.
+
+\def\doinlineframedbox
+ {\scratchdimen\dimexpr\strutdp+\ruledlinewidth\relax
+ \ifboxhasoffset
+ \advance\scratchdimen \framedparameter\c!offset
+ \fi
+ \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
+ \ht\framebox\strutht
+ \dp\framebox\strutdp
+ \box\framebox}
+
+%D We can also lower the box over the natural depth of the
+%D line.
+
+\def\doloweredframedbox
+ {\ht\framebox\dimexpr\ht\framebox+\dp\framebox-\strutdp\relax
+ \dp\framebox\strutdp
+ \box\framebox}
+
+%D Hanging the content is mainly meant for cases like the
+%D following:
+%D
+%D \starttyping
+%D \framed[strut=no]
+%D {\framed[height=2cm,location=hanging]{test}%
+%D \framed[height=1cm,location=hanging]{test}}
+%D \stoptyping
+
+\def\dohangingframedbox % best with strut=no
+ {\scratchdimen\dimexpr\ht\framebox+\dp\framebox\relax
+ \ht\framebox\zeropoint
+ \dp\framebox\scratchdimen}
+
+%D We can draw lines from left to right and top to bottom by
+%D using the normal \type{\hairline} command. Both directions
+%D need a different treatment.
+%D
+%D \startbuffer
+%D \framed[width=4cm] {alfa\hairline beta\hairline gamma}
+%D \framed[height=2cm] {alfa\hairline beta\hairline gamma}
+%D \framed[width=4cm,height=2cm]{alfa\hairline beta\hairline gamma}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \hbox{\getbuffer}
+%D \stoplinecorrection
+%D
+%D These macros try to adapt their behaviour as good as
+%D possible to the circumstances and act as natural as
+%D possible.
+
+\def\vboxedhairline
+ {\bgroup
+ \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
+ \dimen4=\dimexpr\dimen2+\ruledlinewidth\relax
+ \setbox0\vbox
+ {\advance\hsize 2\dimen4
+ \vskip\dimen2
+ \hrule
+ \!!height\ruledlinewidth
+ \!!depth\zeropoint
+ \!!width\hsize
+ \vskip\dimen2}%
+ %\endgraf\nointerlineskip\endgraf
+ %\moveleft\dimen4\box0
+ %\endgraf\nointerlineskip\localbegstrut
+ \endgraf\obeydepth\nointerlineskip
+ \moveleft\dimen4\box0
+ \endgraf\nointerlineskip\localbegstrut % beware, we might kill it in a style using \vskip\lineheight
+ \egroup} % so this must not be changed
+
+\def\hboxedhairline % use framed dimen
+ {\bgroup
+ \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
+ \ifboxhasheight
+ \dimen4\dimexpr\localheight/2+\strutdp-2\ruledlinewidth\relax
+ \dimen6\dimexpr\localheight/2-\strutdp+2\ruledlinewidth\relax
+ \else
+ \dimen4\dimexpr\strutht+\dimen2\relax
+ \dimen6\dimexpr\strutdp+\dimen2\relax
+ \fi
+ \unskip
+ \setbox\scratchbox\hbox
+ {\hskip\dimen2
+ \vrule\!!height\dimen4\!!depth\dimen6\!!width\ruledlinewidth
+ \hskip\dimen2}%
+ \ht\scratchbox\strutht
+ \dp\scratchbox\strutdp
+ \box\scratchbox
+ \ignorespaces
+ \egroup}
+
+%D The argument of the frame command accepts \type{\\} as a
+%D sort of newline signal. In horizontal boxes it expands to a
+%D space.
+
+\def\vboxednewline
+ {\endgraf\ignorespaces}
+
+\def\hboxednewline
+ {\unskip\normalspace\ignorespaces}
+
+%D We can set each rule on or off. The default setting is
+%D inherited from \type{frame}. An earlier implementation
+%D use a bit different approach, but the new one seems more
+%D natural:
+%D
+%D \bgroup
+%D \setuptyping[margin=0pt]
+%D \startlinecorrection
+%D \startbuffer
+%D \framed[offset=overlay,frame=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=on,bottomframe=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=on,bottomframe=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off,bottomframe=off]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D
+%D \startbuffer
+%D \framed[offset=overlay,frame=off,bottomframe=on]{\darkred\blackrule}
+%D \stopbuffer
+%D \hbox{\getbuffer\vbox{\typebuffer}}
+%D \stoplinecorrection
+%D \egroup
+
+%D \macros
+%D {setupblackrules}
+%D
+%D The graphic capabilities of \TEX\ do not go beyond simple
+%D filled rules, except of course when using specials. Let's
+%D start with a warning: using this commands is far more slower
+%D than using the \TEX\ primitives \type{\hrule} and
+%D \type{\vrule}, but they save us some tokens. The
+%D characteristics of these rule drawing command can be set by:
+%D
+%D \showsetup{setupblackrules}
+
+\def\setupblackrules
+ {\dodoubleargument\getparameters[\??bj]}
+
+%D \macros
+%D {blackrule}
+%D
+%D The simple command draws only one rule. Its optional
+%D argument can be used to specify the dimensions. By setting
+%D the width, height or depth to \type {max}, one gets the
+%D natural dimensions.
+%D
+%D \showsetup{blackrule}
+
+\def\doblackrule[#1]%
+ {\hbox\bgroup
+ \getparameters[\??bj][#1]%
+ \setstrut
+ \doif\@@bjwidth \v!max{\def\@@bjwidth {1em}}%
+ \doif\@@bjheight\v!max{\def\@@bjheight{\strutht}}%
+ \doif\@@bjdepth \v!max{\def\@@bjdepth {\strutdp}}%
+ \localstartcolor[\@@bjcolor]%
+ \vrule
+ \!!width \@@bjwidth
+ \!!height\@@bjheight
+ \!!depth \@@bjdepth
+ \localstopcolor
+ \egroup}
+
+\unexpanded\def\blackrule
+ {\dosingleempty\doblackrule}
+
+%D \macros
+%D {blackrules}
+%D
+%D One can call for a sequence of black rules, if needed
+%D equally spaced over the given width.
+%D
+%D \showsetup{blackrules}
+%D
+%D The two alternative calls are therefore:
+%D
+%D \startbuffer
+%D Tell me, is this according to the \blackrules[n=6]?
+%D These \blackrules[alternativevariant=b,n=10,distance=.2em,width=4cm] are quite clear.
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or:
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D We could of course have implemented this macro using
+%D \type{\leaders}, but this would probably have taken more
+%D tokens.
+
+\def\doblackrules[#1]%
+ {\hbox\bgroup
+ \getparameters[\??bj][#1]%
+ \!!widtha\@@bjwidth
+ \!!widthb\@@bjdistance
+ \doif\@@bjalternative\c!b
+ {\scratchcounter\@@bjn
+ \ifnum\scratchcounter=\plusone
+ \!!widthb\zeropoint
+ \else
+ \advance\scratchcounter \minusone
+ \advance\!!widtha -\scratchcounter\!!widthb
+ \divide \!!widtha \@@bjn
+ \fi}%
+ \localstartcolor[\@@bjcolor]%
+ \dorecurse\@@bjn
+ {\vrule
+ \!!width \!!widtha
+ \!!height\@@bjheight
+ \!!depth \@@bjdepth
+ \hskip\!!widthb}%
+ \unskip
+ \localstopcolor
+ \egroup}
+
+\unexpanded\def\blackrules
+ {\dosingleempty\doblackrules}
+
+%D The next commands can be used to draw margin rules. We
+%D support two methods: \marginrule{one for in||line use} and
+%D one that acts on a paragraph. Drawing a margin rule is
+%D rather straightforward because we can use the commands that
+%D put text in the margin.
+
+\def\dodrawmarginrule
+ {\setbox\scratchbox\hbox
+ {\vrule\!!depth\strutdepth\!!height\strutheight\!!width\@@karulethickness}%
+ \smashbox\scratchbox % no \vsmash !!!
+ \box\scratchbox}
+
+\def\drawmarginrule
+ {\strut\inleft{\dodrawmarginrule}}
+
+%D \macros
+%D {marginrule}
+%D
+%D The first method gobbles words and simply puts a bar in the
+%D margin. This method is not entirely robust.
+%D
+%D \showsetup{marginrule}
+
+\definecomplexorsimple\marginrule
+
+\def\simplemarginrule
+ {\let\processword\drawmarginrule
+ \processwords}
+
+\def\complexmarginrule[#1]%
+ {\ifnum#1<\@@kalevel\relax \else
+ \def\@@kadefaultwidth{#1}%
+ \expandafter\simplemarginrule
+ \fi}
+
+%D We need an auxiliary variable
+
+\def\@@kadefaultwidth{1}
+
+%D \macros
+%D {setupmarginrules}
+%D
+%D This macro definitions show us that we can pass an optional
+%D level, which is matched against the previous set one. The
+%D level can be set up with
+%D
+%D \showsetup{setupmarginrules}
+
+\def\setupmarginrules
+ {\dodoubleargument\getparameters[\??ka]}
+
+%D \macros
+%D {startmarginrule}
+%D
+%D The second method collects text and reformats it afterwards,
+%D using the shapebox macros. We prevent local margin rules.
+%D
+%D \showsetup{startmarginrule}
+
+\definecomplexorsimple\startmarginrule
+
+\def\simplestartmarginrule
+ {\bgroup
+ \let\drawmarginrule\relax
+ \let\stopmarginrule\dostopmarginrule
+ \beginofshapebox}
+
+\def\complexstartmarginrule[#1]%
+ {\bgroup
+ \let\drawmarginrule\relax
+ \ifnum#1<\@@kalevel\relax
+ \let\stopmarginrule\egroup
+ \else
+ \def\@@kadefaultwidth{#1}%
+ \let\stopmarginrule\dostopmarginrule
+ \expandafter\beginofshapebox
+ \fi}
+
+\def\dostopmarginrule
+ {\endofshapebox
+ \reshapebox
+ {\hbox{\inleftmargin{\dodrawmarginrule}\box\shapebox}}%
+ \flushshapebox
+ \egroup}
+
+%D \startbuffer
+%D \setupmarginrules[level=5]
+%D
+%D \startmarginrule[1]
+%D First we set the level at~5. Next we typeset this first
+%D paragraph as a level~1 one. As expected no rule show up.
+%D \stopmarginrule
+%D
+%D \startmarginrule[5]
+%D The second paragraph is a level~5 one. As we can see here,
+%D the marginal rule gets a width according to its level.
+%D \stopmarginrule
+%D
+%D \startmarginrule[8]
+%D It will of course be no surprise that this third paragraph
+%D has a even thicker margin rule. This behavior can be
+%D overruled by specifying the width explictly.
+%D \stopmarginrule
+%D \stopbuffer
+%D
+%D In next example we show most features. Watch the rule
+%D thickness adapting itself to the level.
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D We just said:
+%D
+%D \typebuffer
+
+%D \macros
+%D {vl, hl}
+%D
+%D The command \type{\vl} draws a vertical rule \vl\ with strut
+%D dimensions, multiplied with the factor specified in the
+%D optional argument. The height and depth are clipped \vl[3]
+%D to the baselinedistance. Its horizontal counterpart
+%D \type{\hl} draws a horizontal rule \hl\ with a width of 1em,
+%D multiplied with the optional factor. The horizontal rule is
+%D drawn on top of the baseline.
+%D
+%D \showsetup{vl}
+%D \showsetup{hl}
+
+\def\complexvl[#1]%
+ {\bgroup
+ \!!dimena#1\strutht
+ \!!dimenb#1\strutdp
+ \setbox\scratchbox\hbox
+ {\vrule
+ \!!width \linewidth
+ \!!height\!!dimena
+ \!!depth \!!dimenb}%
+ \dp\scratchbox\strutdp
+ \ht\scratchbox\strutht
+ \box\scratchbox
+ \egroup}
+
+\def\complexhl[#1]%
+ {\hbox
+ {\vrule
+ \!!width #1\s!em
+ \!!height\linewidth
+ \!!depth \zeropoint}}
+
+\definecomplexorsimple\vl \def\simplevl{\complexvl[1]}
+\definecomplexorsimple\hl \def\simplehl{\complexhl[1]}
+
+%D \macros
+%D {hairline, thinrule, thinrules, setupthinrules}
+%D
+%D Drawing thin lines can of course easily be accomplished by
+%D the \TEX\ primitives \type{\hrule} and \type{\vrule}. The
+%D next few macros however free us from some specifications.
+%D
+%D \startbuffer
+%D some text
+%D
+%D \hairline
+%D
+%D some more text
+%D
+%D \thinrule
+%D
+%D more and more text
+%D
+%D hi \thinrule\ there
+%D
+%D and then the final text
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D becomes
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D So we've got
+%D
+%D \showsetup{hairline}
+%D \showsetup{thinrule}
+%D
+%D Both can be set up with:
+%D
+%D \showsetup{setupthinrules}
+%D
+%D We also have
+%D
+%D \showsetup{thinrules}
+%D
+%D which looks like: \thinrules[n=2]
+
+\def\thinrule
+ {\strut
+ \bgroup
+ \chardef\ruletype\plusone
+ \processaction
+ [\@@dlalternative]
+ [ \v!a=>\chardef\ruletype0,% no line
+ %\v!b=>\chardef\ruletype1,% height/depth
+ \v!c=>\chardef\ruletype2,% topheight/botdepth
+ % 11=>\chardef\ruletype1,% fallback for backgrounds
+ 0=>\chardef\ruletype0,% compatible with backgrounds
+ % 1=>\chardef\ruletype1,% compatible with backgrounds
+ 2=>\chardef\ruletype2]% compatible with backgrounds
+ \doifsomething\@@dlrulethickness
+ {\linewidth\@@dlrulethickness}%
+ \ifdim\linewidth=\zeropoint
+ \chardef\ruletype\zerocount
+ \else
+ \doifnot\@@dlframe\v!on{\chardef\ruletype\zerocount}%
+ \fi
+ \ifnum\ruletype=\plusone
+ \doif\@@dlheight\v!max{\let\@@dlheight\!!plusone}%
+ \doif\@@dldepth \v!max{\let\@@dldepth \!!plusone}%
+ \else
+ \let\@@dlheight\!!plusone
+ \let\@@dldepth\!!plusone
+ \fi
+ \freezedimensionwithunit\@@dlheight\strutht
+ \freezedimensionwithunit\@@dldepth\strutdp
+ \divide\linewidth \plustwo
+ \doifelse\@@dlbackground\v!color
+ {\startcolor[\@@dlbackgroundcolor]%
+ \ifnum\ruletype=\plustwo % prevent overshoot due to rounding
+ \leaders
+ \hrule
+ \!!height\dimexpr\@@dlheight-.5\linewidth\relax
+ \!!depth \dimexpr\@@dldepth -.5\linewidth\relax
+ \hfill
+ \else
+ \leaders
+ \hrule
+ \!!height\@@dlheight
+ \!!depth \@@dldepth
+ \hfill
+ \fi
+ \stopcolor
+ \ifcase\ruletype
+ % no rule
+ \or
+ \startcolor[\@@dlcolor]%
+ \hfillneg
+ \leaders\hrule\!!height\linewidth\!!depth\linewidth\hfill
+ \stopcolor
+ \or
+ \startcolor[\@@dlcolor]%
+ \hfillneg\leaders\hrule\!!height\dimexpr-\@@dldepth+\linewidth\relax\!!depth\@@dldepth\hfill
+ \hfillneg\leaders\hrule\!!height\@@dlheight\!!depth\dimexpr-\@@dlheight+\linewidth\relax\hfill
+ \stopcolor
+ \fi}
+ {\ifcase\ruletype \else
+ \startcolor[\@@dlcolor]%
+ \leaders\hrule\!!height\@@dlheight\!!depth\@@dldepth\hfill
+ \stopcolor
+ \fi}%
+ \strut
+ \carryoverpar\egroup}
+
+\def\hairline
+ {\endgraf
+ \thinrule
+ \endgraf}
+
+\def\dosetupthinrules[#1]%
+ {\getparameters[\??dl][#1]}
+
+\def\setupthinrules
+ {\dosingleargument\dosetupthinrules}
+
+\def\dothinrules[#1]%
+ {\bgroup
+ \dosetupthinrules[#1]%
+ \@@dlbefore
+ \assignvalue\@@dlinterlinespace\@@dlinterlinespace{1.0}{1.5}{2.0}%
+ \spacing\@@dlinterlinespace
+ \dorecurse\@@dln
+ {\ifnum\recurselevel=\@@dln \dothinrulesnobreak \else
+ \ifnum\recurselevel=2 \dothinrulesnobreak \fi\fi
+ \thinrule
+ \ifnum\recurselevel<\@@dln\relax
+ % test needed, else messed up whitespace
+ \ifx\@@dlinbetween\empty
+ \softbreak
+ \else
+ \endgraf
+ \nowhitespace
+ \@@dlinbetween
+ \fi
+ \fi}%
+ \doifelsenothing\@@dlafter
+ {\carryoverpar\egroup}
+ {\@@dlafter\egroup}}
+
+\def\thinrules
+ {\dosingleempty\dothinrules}
+
+%D A couple of examples are given below.
+%D
+%D \startbuffer
+%D \setupthinrules[n=3,inbetween=,color=gray]
+%D
+%D test test \thinrules\ test test \par
+%D test test \thinrules [color=green] test test \par
+%D test test \thinrules [height=max, depth=max] test test \par
+%D
+%D \setupthinrules[height=.9,depth=.9]
+%D
+%D test test \thinrules\ test test \par
+%D test test \thinrules [alternativevariant=b] test test \par
+%D test test \thinrules [alternativevariant=c] test test \par
+%D test test \thinrules [alternativevariant=c,inbetween=\vskip2ex] test test \par
+%D \stopbuffer
+%D
+%D \typebuffer {\getbuffer}
+%D
+%D There are a couple of alternative ways to visualize rules
+%D using backgrounds. At first sight these may look strange,
+%D but they make sense in educational settings. The
+%D alternatives are more or less compatible with the more
+%D advanced \METAPOST\ based implementation.
+%D
+%D \startbuffer[a]
+%D \setupthinrules
+%D [n=2,
+%D backgroundcolor=gray ,
+%D rulethickness=1pt,
+%D colorkleur=donkerblauw,
+%D after=\blank,
+%D before=\blank]
+%D \stopbuffer
+%D
+%D \typebuffer[a]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a]
+%D \thinrules[alternativevariant=b]
+%D \thinrules[alternativevariant=c]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a,background=color]
+%D \thinrules[alternativevariant=b,background=color]
+%D \thinrules[alternativevariant=c,background=color]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+%D
+%D \startbuffer[b]
+%D \thinrules[alternativevariant=a,height=.8,depth=.8,background=color]
+%D \thinrules[alternativevariant=b,height=.8,depth=.8,background=color]
+%D \thinrules[alternativevariant=c,height=.8,depth=.8,background=color]
+%D \stopbuffer
+%D
+%D \typebuffer[b] \getbuffer[a,b]
+
+%D \macros
+%D {optimizethinrules}
+%D
+%D By saying \type {\thinrulestrue} or \type {-false}, we
+%D can influence the way dangling lines are handled.
+
+\newif\ifoptimizethinrules \optimizethinrulestrue
+
+\def\dothinrulesnobreak
+ {\ifoptimizethinrules\penalty500\fi}
+
+%D \macros
+%D {startframedtext, setupframedtexts, defineframedtext}
+%D
+%D The general framing command we discussed previously, is not
+%D entirely suited for what we call framed texts, as for
+%D instance used in intermezzo's. The next examples show what
+%D we have in mind.
+%D
+%D \startbuffer[framed-0]
+%D \setupframedtexts
+%D [frame=off,
+%D width=\hsize,
+%D background=screen]
+%D
+%D \startframedtext
+%D By default the framed text is centered \dots
+%D \stopframedtext
+%D
+%D \startframedtext[right]
+%D \dots\ but we can also align left, middle and right.
+%D \stopframedtext
+%D \stopbuffer
+%D
+%D \startbuffer[framed-1]
+%D \defineframedtext
+%D [Example]
+%D [width=6cm,
+%D height=5cm]
+%D
+%D \startExample
+%D \typebuffer[framed-1]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-2]
+%D \defineframedtext
+%D [Example]
+%D [width=6cm]
+%D
+%D \startExample
+%D \typebuffer[framed-2]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-3]
+%D \defineframedtext
+%D [Example]
+%D [height=5cm]
+%D
+%D \startExample
+%D \typebuffer[framed-3]
+%D \stopExample
+%D \stopbuffer
+%D
+%D \startbuffer[framed-4]
+%D \defineframedtext
+%D [Example]
+%D [width=fit,height=broad]
+%D
+%D \Example{a very exciting example}
+%D \stopbuffer
+%D
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-0] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-1] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-2] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-3] \egroup
+%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-4] \egroup
+%D
+%D Here we can see that we have a predefined framed text class
+%D as well as the tools for defining our own. So we have:
+%D
+%D \showsetup{setupframedtexts}
+%D
+%D as well as the definition command:
+%D
+%D \showsetup{defineframedtext}
+%D
+%D that generates two commands:
+%D
+%D \showsetup{start<>}
+%D \showsetup{<>}
+%D
+%D The next definition shows the defaults.
+
+\def\dodefineframedtext[#1][#2]%
+ {\presetlocalframed[\??kd#1]%
+ \getparameters[\??kd#1]
+ [\c!width=0.75\hsize,
+ \c!height=\v!fit,
+ \c!align=\v!yes,
+ \c!top=,
+ \c!bottom=\vfill,
+ \c!offset=1em,
+ \c!bodyfont=,
+ \c!style=,
+ \c!color=,
+ \c!left=,
+ \c!right=\hfill,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!inner=,
+ \c!frame=\v!on,
+ \c!topframe=,
+ \c!bottomframe=,
+ \c!leftframe=,
+ \c!rightframe=,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ \c!foregroundcolor=,
+ \c!foregroundstyle=,
+ \c!background=,
+ \c!backgroundcolor=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!linecorrection=\v!on,
+ \c!depthcorrection=\v!on,
+ \c!margin=\v!standard,
+ \c!orientation=,
+ \c!indenting=,
+ #2]%
+ \setvalue{\e!start#1}{\dostartframedtext[#1]}%
+ \setvalue{\e!stop #1}{\dostopframedtext }%
+ \setvalue {#1}{\doframedtext [#1]}}
+
+\def\defineframedtext
+ {\dodoubleempty\dodefineframedtext}
+
+%D We define the general (and original) case by just saying:
+
+\defineframedtext[\v!framedtext]
+
+%D We need several steps before the actual job is done,
+%D because we have to handle an optional identifier (and
+%D because these commands evolved out of a single case).
+
+\def\framedtextparameter#1#2%
+ {\csname\??kd#1#2\endcsname}
+
+\def\dosetupframedtexts[#1][#2]%
+ {\ifsecondargument
+ \def\docommand##1{\getparameters[\??kd##1][#2]}%
+ \processcommacommand[#1]\docommand % new, #1 may be macro
+ \else
+ \getparameters[\??kd\v!framedtext][#1]%
+ \fi}
+
+\def\setupframedtexts
+ {\dodoubleempty\dosetupframedtexts}
+
+\def\dostartframedtext
+ {\bgroup\dotripleempty\dodostartframedtext}
+
+\def\dodostartframedtext[#1][#2][#3]%
+ {\doifassignmentelse{#2}
+ {\dododostartframedtext[#1][][#2]}
+ {\dododostartframedtext[#1][#2][#3]}}
+
+\setfalse\framedtextlocationnone
+
+\def\dododostartframedtext[#1][#2][#3]% #3 only passed to framed, not to framedtext
+ {\doifsomething{#2}{\setvalue{\??kd#1\c!location}{#2}}% does not listen to #3
+ \setfalse\framedtextlocationnone
+ \processaction % \v!low en \v!depth are already taken !
+ [\framedtextparameter{#1}\c!location]
+ [ \v!left=>\letvalue{\??kd#1\c!left }\relax
+ \letvalue{\??kd#1\c!right}\hfill,
+ \v!right=>\letvalue{\??kd#1\c!left }\hfill
+ \letvalue{\??kd#1\c!right}\relax,
+ \v!middle=>\letvalue{\??kd#1\c!left }\hfill
+ \letvalue{\??kd#1\c!right}\hfill,
+ \v!none=>\letvalue{\??kd#1\c!left }\relax % new
+ \letvalue{\??kd#1\c!right}\relax % new
+ \settrue\framedtextlocationnone]%
+ \letvalue{\??kd#1\c!location}\empty
+ % removed 06/2001
+ % \forgetparindent
+ % added 06/2001 [see demo-bbv]
+ \localhsize\hsize \checkframedtext
+ % so far
+ \setbox\framebox\vbox
+ \startboxedcontent
+ \hsize\localhsize
+ % \insidefloattrue % ? better
+ \normalexpanded{\noexpand\switchtobodyfont[\framedtextparameter{#1}\c!bodyfont]}%
+ \startcolor[\framedtextparameter{#1}\c!color]%
+ \localframed[\??kd#1][\c!strut=\v!no,#3]% todo: use delayedstrut
+ \bgroup
+ \let\\=\endgraf
+ \framedtextparameter{#1}\c!inner % oud spul
+ \doifvalue{\??kd#1\c!depthcorrection}\v!on % new, inside box
+ {\bgroup
+ \verticalstrut
+ % we need \nowhitespace in case of setups setting whitespace
+ % nb, not safe, text vs \vbox as next
+ \vskip-\struttotal
+ \nowhitespace % na vskip ! new 20/05/2004, fails with next content being box (\scale{..})
+ }%
+ \doinhibitblank % \blank[\v!disable]% plaatst signal
+\setupindenting[\framedtextparameter{#1}\c!indenting]%
+ \doconvertfont{\framedtextparameter{#1}\c!style}\empty
+ \def\dostopframedtext{\dodostopframedtext{#1}{#2}}}
+
+%D The \type {none} option is handy for nested usage, as
+%D in the presentation styles, where we don't want
+%D interference.
+
+\def\dodostopframedtext#1#2% % no \baselinecorrection, see faq docs
+ {\endgraf
+ \removelastskip
+ \doifvalue{\??kd#1\c!depthcorrection}\v!on % local and global
+ {\forgetall
+ \vskip-\struttotal
+ \verticalstrut
+ \egroup
+ \forgetall
+ \vskip-\lineheight
+ % will be an option, not default
+ % \setbaselinecorrections
+ % \donegbotbaselinecorrection
+ \verticalstrut}
+ \stopboxedcontent
+ \stopcolor
+ \ifconditional\framedtextlocationnone
+ \egroup
+ \box\framebox
+ \else\ifinsidefloat
+ \egroup
+ \box\framebox
+ \else
+ \egroup
+ \doplacement[\??kd#1][\c!depthcorrection=\v!off]{\box\framebox}%
+ \fi\fi
+ \egroup}
+
+%D Placement can be ignored:
+%D
+%D \starttyping
+%D \hbox to \hsize \bgroup
+%D \startframedtext[none][width=.5\textwidth] \input tufte \stopframedtext
+%D \startframedtext[none][width=.5\textwidth] \input zapf \stopframedtext
+%D \egroup
+%D
+%D \hbox to \hsize \bgroup
+%D \setupframedtexts[location=none]%
+%D \startframedtext[width=.5\textwidth] \input zapf \stopframedtext
+%D \startframedtext[width=.5\textwidth] \input tufte \stopframedtext
+%D \egroup
+%D \stoptyping
+
+%D The simple brace (or group) delimited case is typeset
+%D slightly different and is not aligned.
+
+\def\doframedtext
+ {\bgroup\dodoubleempty\dodoframedtext}
+
+\def\dodoframedtext[#1][#2]% beware!
+ {\normalexpanded{\noexpand\switchtobodyfont[\getvalue{\??kd#1\c!bodyfont}]}%
+ \localframed[\??kd#1][\c!strut=\v!no,#2]%
+ \bgroup
+ \blank[\v!disable]%
+ \let\\=\endgraf
+ \getvalue{\??kd#1\c!inner}% % kleur naar outer level
+ \dostartattributes{\??kd#1}\c!style\c!color\empty
+ \bgroup
+ \aftergroup\docloseframedtext
+ \let\next=}
+
+\def\docloseframedtext
+ {\removelastskip
+ \dostopattributes
+ \egroup
+ \egroup}
+
+%D \macros
+%D {defineframed}
+%D
+%D One can also define simple framed texts, using:
+%D
+%D \showsetup{defineframed}
+
+\def\defineframed
+ {\dodoubleempty\dodefineframed}
+
+\def\dodefineframed[#1][#2]%
+ {\iffirstargument
+ \setvalue{#1}{\dodoubleempty\doframed[#2]}%
+ \fi}
+
+\def\doframed[#1][#2]%
+ {\framed[#1,#2]}
+
+%D \macros
+%D {textrule, starttextrule, setuptextrules}
+%D
+%D Putting rules before and after a paragraph is very space
+%D sensitive, but the next command handles that quite well. It
+%D comes in two disguises:
+%D
+%D \startbuffer
+%D \textrule[top]{fragments}
+%D \input reich
+%D \textrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D \startbuffer
+%D \setuptextrules
+%D [width=90pt,distance=12pt,rulecolor=blue,
+%D bodyfont=small,style=\sc,color=red]
+%D
+%D \starttextrule{Ship Building Tools}
+%D \nl \setuptolerance[tolerant] \input materie
+%D \stoptextrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D \startbuffer
+%D \setuptextrules
+%D [location=inmargin,
+%D bodyfont=small,style=slantedbold]
+%D
+%D \starttextrule{wonderful}
+%D \input tufte
+%D \stoptextrule
+%D \stopbuffer
+%D
+%D \bgroup \typebuffer \getbuffer \egroup
+%D
+%D The formal definition of these commands is:
+%D
+%D \showsetup{textrule}
+%D \showsetup{starttextrule}
+%D \showsetup{setuptextrules}
+%D
+%D The implementation looks a bit complicated due to the
+%D optional arguments.
+
+\def\setuptextrules
+ {\dodoubleargument\getparameters[\??tl]}
+
+\def\complextextrule[#1]% if needed we can make it installable
+ {\let\next\dobottomtextrule
+ \processaction
+ [#1]
+ [ \v!top=>\let\next\dotoptextrule,
+ \v!middle=>\let\next\domiddletextrule,
+ \v!bottom=>\let\next\dobottomtextrule]%
+ \dosinglegroupempty\next}
+
+\definecomplexorsimple\textrule
+
+\def\simpletextrule
+ {\dosinglegroupempty\dounknowntextrule}
+
+\def\docomplextextrule#1%
+ {\bgroup
+ \advance\hsize\dimexpr-\rightskip-\leftskip\relax
+ \setbox\scratchbox\hbox to \hsize
+ {\dimen4\dimexpr .5ex+.5\linewidth\relax
+ \dimen6\dimexpr-.5ex+.5\linewidth\relax
+ \doifnothing{#1}\firstargumentfalse
+ \iffirstargument
+ \doifelse\@@tllocation\v!inmargin
+ {\llap{\doattributes\??tl\c!style\c!color{#1}\hskip\leftmargindistance}}
+ {\color[\@@tlrulecolor]
+ {\vrule\!!height\dimen4\!!depth\dimen6\!!width\@@tlwidth}%
+ \hbox spread 2\dimexpr\@@tldistance\relax
+ {\hss\doattributes\??tl\c!style\c!color{\strut#1}\hss}}%
+ \fi
+ \color[\@@tlrulecolor]
+ {\leaders\hrule\!!height\dimen4\!!depth\dimen6\hfill}}%
+ \ht\scratchbox\strutht
+ \dp\scratchbox\strutdp
+ \noindent\box\scratchbox
+%\nobreak\verticalstrut\kern-\struttotal
+% evt \witruimte
+ \egroup}
+
+\def\dotoptextrule#1%
+ {\page[\v!preference] % interferes
+ %\whitespace % no
+ \@@tlbefore
+ \docomplextextrule{#1}%
+% todo, option: \doifnothing{#1}{\ruledvskip-.5ex}
+ \nowhitespace
+ \@@tlinbetween
+ \endgraf}
+
+\def\dodobottomtextrule#1#2%
+ {\ifhmode
+ \endgraf
+ \fi
+ \dimen0\strutdp
+ \ifdim\prevdepth>\strutdp\else % was <\strutdp
+ \ifdim\prevdepth>\zeropoint
+ \advance\dimen0 -\prevdepth
+ \fi
+ \fi
+ \advance\dimen0 .5ex
+ \vskip\dimen0
+% ==
+% \vskip\dimexpr \strutdp + .5ex
+% \ifdim\prevdepth>\strutdp\else\ifdim\prevdepth>\zeropoint-\prevdepth\fi\fi\relax
+%
+ \@@tlinbetween
+ \doifelsenothing{#2}
+ {\bgroup
+ \advance\hsize\dimexpr-\rightskip-\leftskip\relax
+ \nointerlineskip
+ \moveleft-\leftskip\vbox
+ {\color[\@@tlrulecolor]
+ {\hrule\!!depth\linewidth\!!height\zeropoint\!!width\hsize}}%
+ \egroup}
+ {\docomplextextrule{#2}}%
+ \ifvmode\prevdepth\zeropoint\fi
+ #1%
+ \page[\v!preference]}
+
+\def\dobottomtextrule
+ {\dodobottomtextrule\@@tlafter}
+
+\def\domiddletextrule
+ {\dodobottomtextrule\@@tlinbetween}
+
+\def\dounknowntextrule
+ {\iffirstargument
+ \@EA\dotoptextrule
+ \else
+ \@EA\dobottomtextrule\@EA\empty
+ \fi}
+
+%D The grouped commands also supports bodyfont switching:
+
+\def\starttextrule#1%
+ {\bgroup
+ \def\dounknowntextrule{\domiddletextrule}
+ \dotoptextrule{#1}
+ \bgroup
+ \doifsomething\@@tlbodyfont{\switchtobodyfont[\@@tlbodyfont]}}
+
+\def\stoptextrule
+ {\par
+ \egroup
+ \dobottomtextrule\empty
+ \egroup}
+
+%D \macros
+%D {fillinrules, setupfillinrules}
+%D
+%D The next few commands do not really deserve a place in a
+%D core module, because they deal with specific typography.
+%D Nevertheless I decided to make them part of the core,
+%D because they permit us to make questionaires. Let's start
+%D with some examples.
+%D
+%D \fillinrules[n=2,width=fit]{first}
+%D \fillinrules[n=2,width=broad]{first}
+%D \fillinrules[n=2,width=3cm]{first}
+%D \fillinrules[n=2,width=3cm,distance=.5em,separator=:]{first}
+%D \fillinrules[n=2]{first}{last}
+%D \fillintext{first}{last} \input reich \par
+%D
+%D The main command is \type{\fillinrules}. This command takes
+%D one and an optional second argument and sets a paragraph with
+%D empty visualized lines.
+%D
+%D \showsetup{fillinrules}
+%D \showsetup{setupfillinrules}
+
+\def\setupfillinrules
+ {\dodoubleargument\getparameters[\??il]}
+
+\definecomplexorsimpleempty\fillinrules
+
+\def\complexfillinrules[#1]%
+ {\def\docomplexfillinrules##1##2%
+ {\dodocomplexfillinrules[#1]{##1}{##2}{\thinrules
+ [\c!n=\@@iln,\c!interlinespace=\@@ilinterlinespace,\c!before=,\c!after=]}}%
+ \dodoublegroupempty\docomplexfillinrules}
+
+\def\dodocomplexfillinrules[#1]#2#3#4%
+ {\endgraf
+ \@@ilbefore
+ \begingroup
+ \setupfillinrules[#1]%
+ \noindent
+ \doifsomething{#2}
+ {\doifelse\@@ilwidth\v!fit
+ {\let\@@ildistance\!!zeropoint
+ \hbox}
+ {\doifelse\@@ilwidth\v!broad
+ {\hbox}
+ {\hbox to \@@ilwidth}}%
+ \bgroup
+ \doattributes\??il\c!style\c!color{\strut#2\hfill\@@ilseparator}%
+ \hskip\@@ildistance
+ \egroup}%
+ %\hangindent=\wd0\relax % tzt hang=yes,n
+ %\parindent=\hangindent
+ %\box0\relax
+ \setupwhitespace[\v!big]%
+ \ignorespaces
+ #4%
+ \doifsomething{#3}
+ {\kern\@@ildistance
+ \doattributes\??il\c!style\c!color{#3\strut}}%
+ \endgroup
+ \endgraf
+ \@@ilafter}
+
+%D \macros
+%D {fillintext}
+%D
+%D To provide compatible layouts when texts and lines are
+%D mixed, one can typeset a paragraph by using the command
+%D \type{\fillintext}.
+%D
+%D \showsetup{fillintext}
+
+\definecomplexorsimpleempty\fillintext
+
+\def\complexfillintext[#1]% rather rough, using an \unhbox is suboptimal
+ {\def\docomplexfillintext##1##2%
+ {\dowithnextbox
+ {\dodocomplexfillinrules[#1]{##1}{\hfill##2}{\unhbox\nextbox\unskip}}%
+ \hbox\bgroup\let\par\egroup\ignorespaces}%
+ \dodoublegroupempty\docomplexfillintext}
+
+%D \macros
+%D {fillinline, setupfillinlines}
+%D
+%D Another member of the family takes care of putting a (often
+%D small) rule after a piece of text, like
+%D
+%D \startbuffer
+%D \fillinline \input reich \par
+%D \fillinline[margin=0cm] \input reich \par
+%D \stopbuffer
+%D
+%D \startvoorbeeld
+%D \getbuffer
+%D \stopvoorbeeld
+%D
+%D which was typeset by saying:
+%D
+%D \typebuffer
+%D
+%D The two commands that take care of this are:
+%D
+%D \showsetup{fillinline}
+%D \showsetup{setupfillinlines}
+
+\def\setupfillinlines
+ {\dodoubleargument\getparameters[\??iv]}
+
+\definecomplexorsimpleempty\fillinline
+
+\def\complexfillinline[#1]%
+ {%\endgraf % interferes with \definedescription cum suis
+ \@@ivbefore
+ \begingroup
+ \setupfillinlines[#1]%
+ \advance\rightskip \@@ivmargin
+ \parfillskip\zeropoint
+ \def\par % very dangerous
+ {\let\par\endgraf % -)
+ \ifhmode\unskip\hfill\fi
+ \scratchdimen\dimexpr\@@ivwidth-\@@ivdistance\relax
+ \ifdim\scratchdimen>\@@ivmargin\else\expandafter\rlap\fi
+ {\kern\@@ivdistance
+ \vrule
+ \!!width \scratchdimen
+ \!!height.5\linewidth
+ \!!depth .5\linewidth}%
+ \endgraf % !
+ \endgroup
+ \endgraf % !
+ \@@ilafter}}
+
+%D \stopdocumentation
+%D \bgroup
+%D
+%D \setupframedtexts
+%D [setuptext]
+%D [background=color,backgroundcolor=white]
+%D
+%D \startbuffer
+%D \setupbackground
+%D [backgroundoffset=4pt,
+%D background=screen,
+%D frame=on,
+%D framecolor=red,
+%D leftoffset=2pt]
+%D \stopbuffer
+%D
+%D \getbuffer
+%D
+%D \startbackground
+%D
+%D \macros
+%D {setupbackground,startbackground,background}
+%D
+%D The section deals with backgrounds in the running text. This
+%D means that texts is to be collected and split over pages. To
+%D show what can be done, we provide this part of the
+%D documentation with some gray background and a red frame.
+%D Both the background and frame can have all characteristics
+%D of \type{\framed}. This time we used the setting:
+%D
+%D \typebuffer
+%D
+%D The implementation is not that sophisticated, but suffices.
+%D The main problem with this kind of functionality is to get
+%D the spacing all right.
+
+%D Specifying the background is more or less the same as
+%D specifying a framed box.
+%D
+%D \showsetup{setupbackground}
+
+\presetlocalframed[\??ag]
+
+\def\dosetupbackground[#1]%
+ {\getparameters[\??ag][#1]%
+ \doifelse\@@agstate\v!start
+ {\let\startbackground\dostartbackground
+ \let\stopbackground \dostopbackground
+ \let\background \dobackground}
+ {\let\startbackground\relax
+ \let\stopbackground \relax
+ \let\background \relax}}
+
+\def\setupbackground
+ {\dosingleargument\dosetupbackground}
+
+%D Actually typesetting the background is implemented rather
+%D straightforward. We need to handle some spacing as well as
+%D the (often) a bit smaller horizontal size.
+%D
+%D \showsetup{startbackground}
+%D
+%D Although we could have used a scratch one, we first
+%D declare a boolean.
+
+% 0=no-split, 1=no-split+indent, 2=split, 3=split+indent
+
+\chardef\backgroundsplitmode\plusthree
+
+%D The \type{\vbox to \lineheight{}\vskip\zeropoint}
+%D construction gives the first real line a decent height by
+%D adding a dummy line.
+
+\def\dostartbackground
+ {\endgraf
+ \bgroup
+ \setbox0\vbox\bgroup
+ \vbox to \lineheight{}\vskip\zeropoint
+ \blank[\v!disable]
+ % \advance\hsize -\@@agleftoffset
+ % \advance\hsize -\@@agrightoffset
+ \leftskip \@@agleftoffset % new **
+ \rightskip\@@agrightoffset} % new **
+
+%D This dummy line is removed by \type{\setbox2=\vsplit0 to
+%D \lineheight}. That way \type{\topskip} takes care of the
+%D lineheight. I'll probably forget to apply this trick
+%D elsewhere.
+
+\def\dostopbackground % improved version (i hope)
+ {\endgraf
+ \removelastskip
+ \egroup
+ \dimen2\leftskip % new **
+ \forgetall
+ \ifinsidefloat
+ \chardef\backgroundsplitmode\zerocount
+ \fi
+ \ifcase\backgroundsplitmode
+ \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
+ \or
+ \hskip\dimen2
+ \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
+ \else
+ \splitmaxdepth\boxmaxdepth
+ \splittopskip\topskip
+ \setbox2\vsplit0 to \lineheight % get rid of fake line
+ \loop
+ \ifdim\pagetotal=\zeropoint % empty page
+ \scratchdimen\textheight
+ \chardef\backgroundsplit\plusone % split to max height
+ \else
+ \setbox\scratchbox\vbox{\@@agbefore}%
+ \scratchdimen\dimexpr\pagegoal-\ht\scratchbox-\pagetotal\relax
+ \chardef\backgroundsplit\plustwo % split to partial height
+ \fi
+ \advance\scratchdimen\dimexpr-\@@agtopoffset-\@@agbottomoffset\relax
+ \ifdim\scratchdimen>2\lineheight\relax % reasonable, will be configurable
+ \ifdim\ht0>\scratchdimen % larger than page
+ \setbox2\vsplit0 to \scratchdimen
+ \else
+ \setbox2\box0
+ \chardef\backgroundsplit\zerocount % no split
+ \fi
+ \setbox2\vbox \ifcase\backgroundsplit\or to \textheight \fi % max split
+ {\vskip\@@agtopoffset
+ \popsplitproperties
+ \unvcopy2
+ \prevdepth\dp2
+ \obeydepth
+ \vskip\@@agbottomoffset
+ \vfill}
+ \@@agbefore
+ \ifcase\backgroundsplit\or\or % partial split
+ \ifdim\pagegoal<\maxdimen
+ \pagegoal=1.2\pagegoal % be a bit more tolerant
+ \fi
+ \fi
+ \startlinecorrection
+ %\localframed[\??ag][\c!offset=\v!overlay]{\hskip\@@agleftoffset\box2\hskip\@@agrightoffset}%
+ \ifnum\backgroundsplitmode=\plusthree \hskip\dimen2 \fi %
+ \localframed[\??ag][\c!offset=\v!overlay]{\box2}% new **
+ \stoplinecorrection
+ \ifcase\backgroundsplit % no split
+ \@@agafter
+ \else % some split
+ \vfill\eject % geen \page !
+ \fi
+ \else
+ \page
+ \fi
+ \ifdim\ht0>\zeropoint \repeat
+ \fi
+ \egroup
+ \endgraf}
+
+%D As a bonus we also have a short command, that is of not
+%D much use, but kept there for historic reasons.
+%D
+%D \showsetup{background}
+
+\def\dobackground
+ {\bgroup
+ \dowithnextbox
+ {\localframed[\??ag][\c!offset=\v!overlay]{\flushnextbox}\egroup}
+ \vbox}
+
+%D \stopdocumentation
+%D \stopbackground
+%D \egroup
+
+%D New, for the moment private; let's see when GB finds out
+%D about this one and its obscure usage. It's used in:
+%D
+%D \startbuffer
+%D \defineframedtext
+%D [tabulateframe]
+%D [offset=overlay,
+%D backgroundoffset=3pt,
+%D background=color,
+%D backgroundcolor=green]
+%D
+%D \setuptabulate
+%D [tabulate]
+%D [frame=tabulateframe]
+%D
+%D \setuptables
+%D [frame=tabulateframe]
+%D
+%D \input tufte
+%D
+%D \starttabulate[|l|l|]
+%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
+%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
+%D \stoptabulate
+%D
+%D \input tufte
+%D
+%D \starttable[|l|l|]
+%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
+%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
+%D \stoptable
+%D \stopbuffer
+%D
+%D \typebuffer
+
+\def\defineframedcontent
+ {\dodoubleempty\dodefineframedcontent}
+
+\def\dodefineframedcontent[#1][#2]%
+ {\presetlocalframed[\??fc#1]%
+ \getparameters[\??fc#1]
+ [\c!leftoffset=\zeropoint,
+ \c!rightoffset=\getvalue{\??fc#1\c!leftoffset},
+ \c!topoffset=\zeropoint,
+ \c!bottomoffset=\getvalue{\??fc#1\c!topoffset},
+ \c!strut=\v!no,
+ \c!offset=\v!overlay,
+ \c!linecorrection=\v!no,
+ \c!left=,
+ \c!right=,
+ #2]}
+
+\let\setuplocalframed\getparameters
+
+\def\setupframedcontent
+ {\dodoubleempty\dosetupframedcontent}
+
+\def\dosetupframedcontent[#1][#2]%
+ {\def\docommand##1{\getparameters[\??fc##1][#2]}%
+ \processcommacommand[#1]\docommand}
+
+\def\startframedcontent[#1]%
+ {\bgroup
+ \let\stopframedcontent\egroup
+ \doifnot{#1}\v!off
+ {\doifdefined{\??fc#1\c!frame}
+ {\def\stopframedcontent{\dostopframedcontent{#1}}%
+ \dostartframedcontent{#1}}}}
+
+\def\dostartframedcontent#1%
+ {\setbox\framebox\hbox\bgroup
+ \setlocalhsize
+ \hsize\localhsize
+ \advance\hsize\dimexpr-\getvalue{\??fc#1\c!leftoffset}-\getvalue{\??fc#1\c!rightoffset} \relax
+ \advance\vsize\dimexpr-\getvalue{\??fc#1\c!topoffset} -\getvalue{\??fc#1\c!bottomoffset}\relax
+ \hskip\getvalue{\??fc#1\c!leftoffset}%
+ \vbox\bgroup
+ \vskip\getvalue{\??fc#1\c!topoffset}%
+ \vbox\bgroup
+ \forgetall
+ \blank[\v!disable]}
+
+\def\dostopframedcontent#1%
+ {\removelastskip
+ \egroup
+ \vskip\getvalue{\??fc#1\c!bottomoffset}%
+ \egroup
+ \hskip\getvalue{\??fc#1\c!rightoffset}%
+ \egroup
+ \doifvalue{\??fc#1\c!width}\v!fit
+ {\letvalue{\??fc#1\c!width}\v!fixed}% no shapebox
+ \ifinsidefloat
+ \donefalse
+ \else
+ \doifelsevalue{\??fc#1\c!linecorrection}\v!yes\donetrue\donefalse
+ \fi
+ % plaats ?
+ \ifdone\startlinecorrection\fi
+ \getvalue{\??fc#1\c!left}% new
+ \localframed[\??fc#1]{\box\framebox}%
+ \getvalue{\??fc#1\c!right}% new
+ \ifdone\stoplinecorrection\fi
+ \egroup}
+
+%D \macros
+%D {backgroundline}
+%D
+%D For the moment an undocumented feature, but a cancidate
+%D for going public.
+
+\def\backgroundline[#1]%
+ %{\doifsomething{#1}{\dobackgroundline{#1}}\hbox}
+ {\doifcolorelse{#1}{\dobackgroundline{#1}\hbox}\hbox}
+
+% \def\backgroundline[#1]%
+% {\doifcolor{#1}{\dobackgroundline{#1}}\hbox}
+
+\def\dobackgroundline#1%
+ {\dowithnextbox
+ {\hbox
+ {\localcolortrue
+ \startcolor[#1]%
+ \vrule
+ \!!width \nextboxwd
+ \!!height\nextboxht
+ \!!depth \nextboxdp
+ \stopcolor
+ \hskip-\nextboxwd
+ \flushnextbox}}}
+
+%D \macros
+%D {encircled}
+%D
+%D Some not so robust left||overs (borrowed from Knuth,
+%D \TEX Book\ page 356):
+
+\def\encircled#1%
+ {{\ooalign{\hfil\raise0.07ex\hbox{{\tx#1}}\hfil\crcr\mathhexbox20D}}}
+
+\let\omcirkeld\encircled
+
+\setuplinewidth
+ [\v!medium]
+
+\setupframed
+ [\c!width=\v!fit,
+ \c!height=\v!broad,
+ \c!lines=,
+ \c!offset=0.25ex, % \defaultframeoffset
+ \c!empty=\v!no,
+ \c!frame=\v!on,
+ \c!topframe=,
+ \c!bottomframe=,
+ \c!leftframe=,
+ \c!rightframe=,
+ \c!radius=.5\bodyfontsize,
+ \c!rulethickness=\linewidth,
+ \c!corner=\v!rectangular,
+ \c!depth=\!!zeropoint,
+ \c!foregroundcolor=,
+ \c!foregroundstyle=,
+ \c!background=,
+ \c!backgroundscreen=\@@rsscreen,
+ \c!backgroundcolor=,
+ \c!backgroundoffset=\!!zeropoint,
+ \c!framecolor=,
+ \c!frameoffset=\!!zeropoint,
+ \c!backgroundcorner=\framedparameter\c!corner,
+ \c!backgroundradius=\framedparameter\c!radius,
+ \c!backgrounddepth=\framedparameter\c!depth,
+ \c!framecorner=\framedparameter\c!corner,
+ \c!frameradius=\framedparameter\c!radius,
+ \c!framedepth=\framedparameter\c!depth,
+ \c!component=,
+ \c!align=,
+ \c!bottom=\vss,
+ \c!top=,
+ \c!strut=\v!yes,
+ \c!autostrut=\v!yes,
+ \c!location=\v!normal,
+ \c!orientation=,
+ \c!autowidth=\v!yes,
+ \c!setups=]
+
+\setupscreens
+ [%\c!factor=1.0, % obsolete
+ %\c!method=\v!external, % obsolete
+ \c!screen=0.95]
+
+\setupblackrules
+ [\c!n=3,
+ \c!width=1em,
+ \c!height=1ex,
+ \c!depth=\!!zeropoint,
+ \c!alternative=\c!a,
+ \c!distance=.25ex,
+ \c!color=]
+
+\setupmarginrules
+ [\c!level=0,
+ \c!rulethickness=\@@kadefaultwidth\linewidth]
+
+\setupthinrules
+ [\c!interlinespace=\v!small,
+ \c!n=3,
+ \c!before=,
+ \c!inbetween={\blank[\v!white]},
+ \c!after=,
+ \c!color=,
+ \c!height=.5\linewidth,
+ \c!depth=.5\linewidth,
+ \c!frame=\v!on, % compatible with textbackgrounds
+ \c!alternative=\v!b,
+ \c!backgroundcolor=,
+ \c!background=,
+ \c!rulethickness=]
+
+\setuptextrules
+ [\c!location=\v!left,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!inbetween=,
+ \c!width=2em,
+ \c!style=\v!bold,
+ \c!color=,
+ \c!rulecolor=,
+ \c!bodyfont=,
+ \c!distance=.5em]
+
+\setupfillinrules
+ [\c!width=\v!broad,
+ \c!distance=1em,
+ \c!before=\blank,
+ \c!after=\blank,
+ \c!n=1,
+ \c!interlinespace=\v!small,
+ \c!separator=,
+ \c!style=\v!normal,
+ \c!color=]
+
+\setupfillinlines
+ [\c!width=3cm,
+ \c!margin=\@@ivwidth,
+ \c!distance=1em,
+ \c!before=\blank,
+ \c!after=\blank]
+
+\setupbackground
+ [\c!leftoffset=.5\bodyfontsize,
+ \c!rightoffset=\@@agleftoffset,
+ \c!topoffset=\!!zeropoint,
+ \c!bottomoffset=\@@agtopoffset,
+ \c!state=\v!start,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ \c!frame=\v!off,
+ \c!color=,
+ \c!depth=\!!zeropoint,
+ \c!background=\v!screen,
+ \c!backgroundcolor=\@@agcolor,
+ \c!screen=\@@rsscreen,
+ \c!before=,
+ \c!after=]
+
+% Experimental extension:
+
+\def\c!loffset{loffset}
+\def\c!roffset{roffset}
+\def\c!toffset{toffset}
+\def\c!boffset{boffset}
+
+\getparameters
+ [\??oi]
+ [\c!loffset=\zeropoint,
+ \c!roffset=\zeropoint,
+ \c!toffset=\zeropoint,
+ \c!boffset=\zeropoint]
+
+\newdimen\!!framedloffset
+\newdimen\!!framedroffset
+\newdimen\!!framedtoffset
+\newdimen\!!framedboffset
+
+\def\setextraframedoffsets
+ {\boxhasextraoffsetfalse
+ \!!framedloffset\framedparameter\c!loffset
+ \!!framedroffset\framedparameter\c!roffset
+ \!!framedtoffset\framedparameter\c!toffset
+ \!!framedboffset\framedparameter\c!boffset
+ \ifzeropt\!!framedloffset\else \advance\!!framedwidth -\!!framedloffset \boxhasextraoffsettrue \fi
+ \ifzeropt\!!framedroffset\else \advance\!!framedwidth -\!!framedroffset \boxhasextraoffsettrue \fi
+ \ifzeropt\!!framedtoffset\else \advance\!!framedheight-\!!framedtoffset \boxhasextraoffsettrue \fi
+ \ifzeropt\!!framedboffset\else \advance\!!framedheight-\!!framedboffset \boxhasextraoffsettrue \fi}
+
+\def\applyextraframedoffsets
+ {\setbox\framebox\vbox\bgroup
+ \vskip\!!framedtoffset
+ \hbox\bgroup
+ \hskip\!!framedloffset
+ \box\framebox
+ \hskip\!!framedroffset
+ \egroup
+ \vskip\!!framedboffset
+ \egroup}
+
\protect \endinput
diff --git a/tex/context/base/core-rul.tex b/tex/context/base/core-rul.tex
deleted file mode 100644
index f9386d560..000000000
--- a/tex/context/base/core-rul.tex
+++ /dev/null
@@ -1,3590 +0,0 @@
-%D \module
-%D [ file=core-rul,
-%D version=1998.10.16,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Ruled Stuff Handling,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Ruled Content Handling}
-
-\loadmarkfile{core-rul}
-
-\unprotect
-
-%D We have removed the rather old and out dated raster methods. They
-%D have not been used for ages.
-
-%D \macros
-%D {linewidth, setuplinewidth}
-%D
-%D This module deals with rules (lines) in several ways. First
-%D we introduce two macros that can be used to set some common
-%D characteristics.
-%D
-%D \showsetup{setuplinewidth}
-%D
-%D The linewidth is available in \type{\linewidth}. The
-%D preset value of .4pt equals the default hard coded \TEX\
-%D rule width.
-
-\newdimen\linewidth
-
-\def\dosetuplinewidth[#1]%
- {\assigndimension{#1}\linewidth{.2\points}{.4\points}{.6\points}}
-
-\def\setuplinewidth
- {\dosingleargument\dosetuplinewidth}
-
-%D \macros
-%D {ruledlinewidth, inheritruledlinewidth}
-%D
-%D Inside framed boxed we will use a private dimensions. As
-%D an option one can let the linewidth inherit its value from
-%D this one.
-
-\newdimen\ruledlinewidth \newif\ifinheritruledlinewidth
-
-% %D \TEX\ lacks support for color and even gray scales. The next
-% %D macros can provide a sort of poor mans gray scales as well
-% %D as give access to more suitable methods of rendering. Such a
-% %D method looks like:
-% %D
-% %D \starttyping
-% %D \def\methodegraybox#1#2#3#4#5#6%
-% %D { ... }
-% %D \stoptyping
-% %D
-% %D The string \type{graybox} is a common element in the name,
-% %D so we can have for instance \type {\postscriptgraybox} or
-% %D \type {\texgraybox}. The first three arguments take a
-% %D dimension, the fourth one takes a number between~0 and~1,
-% %D and the last argument specifies a radius of the box when
-% %D rounded corners are used, so:
-% %D
-% %D \startbuffer
-% %D \dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}
-% %D \stopbuffer
-% %D
-% %D \typebuffer
-% %D
-% %D becomes:
-% %D
-% %D %\startlinecorrection
-% %D % \vbox to 1cm{\getbuffer}
-% %D %\stoplinecorrection
-% %D
-% %D \startlinecorrection
-% %D \unprotect
-% %D \vbox to 1cm{\dotgraybox{.5\hsize}{1cm}{0cm}{.85}{\v!no}{0pt}}
-% %D \protect
-% %D \stoplinecorrection
-% %D
-% %D There are two predefined methodes, one uses periods and the
-% %D other uses small rules. The second method is less
-% %D efficient, but sometimes give better results. The dimensions
-% %D of the resullting box are set to zero.
-%
-% \setvalue{\v!dot graybox}{\processraster\symbol\rasterdot}
-% \setvalue{\v!rule graybox}{\processraster\symbol\rasterbox}
-%
-% \def\rasterdot{\rasterfont.}
-% \def\rasterbox{\hss\vrule\!!width.4pt\!!height.4pt\!!depth\zeropoint}
-%
-% %D Now of course we need:
-%
-% \ifx\rasterfont\undefined \def\rasterfont{\fivepoint} \fi
-%
-% %D We implement two pure \TEX\ based generators, that use
-% %D \type{\leaders} to quickly gerenate the gray pattern. One
-% %D should beware of \DIMENSION\ conflicts, so we use some
-% %D registers above~8. These macros are memory hungry and byte
-% %D spoiling.
-%
-% \def\processraster#1#2#3#4#5#6#7%
-% {\bgroup
-% \forgetall
-% \dontcomplain
-% \dimen10=\onepoint
-% \dimen10=\@@rsfactor\dimen10
-% \dimen10=#5\dimen10
-% \setbox2\hbox to #2
-% {\cleaders\hbox to 2\dimen10{#1\hss}\hss}%
-% \dimen12=#3%
-% \advance\dimen12 #4%
-% % \setbox0\vbox to \dimen12
-% {\cleaders\vbox to 2\dimen10{\box2\vss}\vss}%
-% \setbox0\hbox
-% {\hskip-.5\dimen10\lower0.5\dimen10\copy0
-% \hskip-\wd0\hskip\dimen10\lower1.5\dimen10\box0}%
-% \box0
-% \egroup}
-
-%D \macros
-%D {setupscreens}
-%D
-%D The previous macro uses a predefined constant
-%D \type{\@@rsfactor}. This factor can be set by:
-%D
-%D \showsetup{setupscreens}
-
-\def\setupscreens
- {\dodoubleargument\getparameters[\??rs]}
-
-% %D The most appropriate way to call for this feature is
-% %D using \type{\graybox}, which is defined as:
-%
-% \def\graybox{\getvalue{\@@rsmethod graybox}}
-%
-% %D We just introduced two pure \TEX\ methods for generating
-% %D rasters. However, it's far more efficient and comfortable in
-% %D terms of speed, memory usage and file size, to use a driver
-% %D supported method.
-%
-% \setvalue{\v!external graybox}{\setgraybox}
-%
-% %D For compatibility reasons we also define the original one:
-%
-% \setvalue{\v!postscript graybox}{\getvalue{\v!external graybox}}
-%
-% %D A quite valid way of letting drivers do the job, is giving
-% %D a solid rule a gray texture.
-
-%D We will communicate through module specific variables, current
-%D framed parameters and some reserved dimension registers.
-
-\newdimen \frameddimenwd
-\newdimen \frameddimenht
-\newdimen \frameddimendp
-
-%D We don't have to stick to a \TEX\ drawn rule, but
-%D also can use rounded or even fancier shapes, as we will
-%D see later on.
-
-\def\dofilledbox
- {\bgroup
- \doifelse{\framedparameter\c!backgroundcorner}\v!rectangular
- {\dofilledlinedbox}
- {\ifzeropt\dimexpr\framedparameter\c!backgroundradius\relax % just in case of .x\bodyfontsize
- \dofilledlinedbox
- \else
- \dofilledroundbox
- \fi}%
- \egroup}
-
-\def\dophantombox
- {\hphantom{\dofilledbox}}
-
-\def\dofilledlinedbox
- {\vrule\!!width\frameddimenwd\!!height\frameddimenht\!!depth\frameddimendp\relax}%
-
-\def\dostrokedroundbox
- {\doif{\framedparameter\c!frame}\v!on\dodostrokedroundbox}
-
-\def\dodostrokedroundbox
- {\bgroup
- \edef\ovalmod{\framedparameter\c!framecorner}%
- \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
- \edef\ovalwid{\the\frameddimenwd}%
- \edef\ovalhei{\the\frameddimenht}%
- \edef\ovaldep{\the\frameddimendp}%
- \edef\ovallin{\the\dimexpr\ruledlinewidth}%
- \edef\ovalrad{\the\dimexpr\framedparameter\c!frameradius}%
- \let\ovalstr\!!plusone
- \let\ovalfil\!!zerocount
- \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
- \egroup}
-
-\def\dofilledroundbox
- {\bgroup
- \edef\ovalmod{\framedparameter\c!backgroundcorner}%
- \doifelse\ovalmod\v!round{\let\ovalmod\!!zerocount}{\edef\ovalmod{\number\ovalmod}}%
- \edef\ovalwid{\the\frameddimenwd}%
- \edef\ovalhei{\the\frameddimenht}%
- \edef\ovaldep{\the\frameddimendp}%
- \edef\ovallin{\the\dimexpr\ruledlinewidth\relax}%
- \edef\ovalrad{\the\dimexpr\framedparameter\c!backgroundradius\relax}%
- \let\ovalstr\!!zerocount
- \let\ovalfil\!!plusone
- \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod
- \egroup}
-
-% a lot of weird corners
-%
-% \startTEXpage
-% \dontleavehmode\framed
-% [corner=0,frame=on,framecolor=green,
-% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green,
-% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green,
-% background=color,backgroundcolor=yellow]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse {1} {4}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse {5} {8}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse {9}{12}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse{13}{16}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse{17}{20}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse{21}{24}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \vskip1em
-% \dontleavehmode\dostepwiserecurse{25}{28}{1}{\framed
-% [corner=\recurselevel,frame=on,framecolor=green]{\tttf TEST \twodigits\recurselevel}%
-% \quad}
-% \stopTEXpage
-
-%D The oval box is drawn using a special macro, depending on
-%D the driver in use.
-
-\def\dograybox % avoid black rules when no gray
- {\doifelsenothing{\framedparameter\c!backgroundscreen}
- {\dophantombox}
- {\raster[\framedparameter\c!backgroundscreen]{\dofilledbox}}}
-
-%D It won't be a surprise that we not only provide gray boxes,
-%D but also colored ones. Here it is:
-
-\def\docolorbox
- {\hbox{\ifincolor
- \doifcolorelse{\framedparameter\c!backgroundcolor}
- {\localcolortrue\color[\framedparameter\c!backgroundcolor]{\dofilledbox}}
- {\dophantombox}%
- \else
- \dophantombox
- \fi}}
-
-%D \macros
-%D {defineoverlay, doifoverlayelse, overlayoffset,
-%D overlaywidth, overlayheight, overlaydepth,
-%D overlaycolor, overlaylinecolor, overlaylinewidth}
-%D
-%D Before we define the macro that actually takes card of the
-%D backgrounds, we introduce overlays. An overlay is something
-%D that contrary to its name lays {\em under} the text. An
-%D example of an overlay definition is:
-%D
-%D \startbuffer[tmp-1]
-%D \defineoverlay
-%D [fancy]
-%D [{\externalfigure
-%D [mp-cont.502]
-%D [width=\overlaywidth,
-%D height=\overlayheight]}]
-%D \stopbuffer
-%D
-%D \typebuffer[tmp-1]
-%D
-%D That for instance can be uses in:
-%D
-%D \startbuffer[tmp-2]
-%D \framed[backgroundachtergrond=fancy]{How Fancy!}
-%D \framed[backgroundachtergrond=fancy,frame=off]{Even More Fancy!}
-%D \stopbuffer
-%D
-%D and looks like:
-%D
-%D \startlinecorrection
-%D \vbox{\baselineskip24pt\getbuffer[tmp-1]\getbuffer[tmp-2]}
-%D \stoplinecorrection
-%D
-%D The formal definition is:
-%D
-%D \showsetup{defineoverlay}
-%D
-%D This macro's definition is a bit obscure, due the many
-%D non||used arguments and the two step call that enable the
-%D setting of the width, height and depth variables.
-%D Multiple backgrounds are possible and are specified as:
-%D
-%D \starttyping
-%D \framed[background={one,two,three}]{Three backgrounds!}
-%D \stoptyping
-%D
-%D Most drawing packages only know width and height. Therefore
-%D the dimensions have a slightly different meaning here:
-%D
-%D \startitemize[packed]
-%D \item \type{\overlaywidth }: width of the overlay
-%D \item \type{\overlayheight}: height plus depth of the overlay
-%D \item \type{\overlaydepth }: depth of the overlay
-%D \stopitemize
-%D
-%D The resulting box is lowered to the right depth.
-
-\def\overlaywidth {\the\hsize\space} % We preset the variables
-\def\overlayheight {\the\vsize\space} % to some reasonable default
-\let\overlaydepth \!!zeropoint % values. The attributes
-\let\overlayoffset \!!zeropoint % of the frame can be (are)
-\let\overlaycolor \empty % set somewhere else.
-\let\overlaylinewidth \!!zeropoint %
-\let\overlaylinecolor \empty %
-
-%D The next register is used to initialize overlays.
-
-\newtoks\everyoverlay
-
-%D An example of an initialization is the following (overlays
-%D can contain text and be executed under an regime where
-%D interlineskip is off).
-
-\appendtoks \oninterlineskip \to \everyoverlay
-
-\def\defineoverlay
- {\dodoubleargument\dodefineoverlay}
-
-\def\dodefineoverlay[#1][#2]%
- {\def\docommand##1{\setvalue{\??ov##1}{\executedefinedoverlay{##1}{#2}}}%
- \processcommalist[#1]\docommand}
-
-\prependtoks
- \hsize\overlaywidth
- \vsize\overlayheight
-\to\everyoverlay
-
-\long\def\executedefinedoverlay#1#2%
- {\bgroup
- \edef\overlaywidth {\the\frameddimenwd\space}%
- \edef\overlayheight{\the\dimexpr\frameddimenht+\frameddimendp\relax\space}%
- \edef\overlaydepth {\the\frameddimendp\space}%
- \edef\overlaycolor {\framedparameter\c!backgroundcolor}%
- %\edef\overlaycorner{\framedparameter\c!backgroundcorner}%
- %\edef\overlayradius{\framedparameter\c!backgroundradius}%
- \let\overlayoffset\backgroundoffset % we steal this one
- \setbox\scratchbox\hbox{\lower\overlaydepth\hbox{\the\everyoverlay#2}}%
- \setbox\scratchbox\hbox
- {\hskip-.5\dimexpr\wd\scratchbox-\overlaywidth \relax
- \raise-.5\dimexpr\ht\scratchbox-\frameddimenht\relax % not overlayheight !
- \box\scratchbox}%
- \wd\scratchbox\overlaywidth
- \ht\scratchbox\overlayheight
- \dp\scratchbox\overlaydepth
- \startlayoutcomponent{o:#1}{overlay #1}%
- \box\scratchbox
- \stoplayoutcomponent
- \egroup}
-
-%D The empty case is:
-
-\let\executeoverlay\gobblesevenarguments
-
-%D For testing we provide:
-
-\def\doifoverlayelse#1%
- {\doifdefinedelse{\??ov#1}}
-
-%D We predefine two already familiar backgrounds:
-
-\setvalue{\??ov\v!screen}{\dograybox }
-\setvalue{\??ov\v!color }{\docolorbox}
-
-% %D After all these preparations, the background macro does no
-% %D bring to many surprises. One has to keep in mind that this
-% %D macro starts up a call chain, depending on the background
-% %D one needs:
-% %D
-% %D \startitemize[packed]
-% %D \item a raster, color or user defined shape
-% %D \item square or round corners
-% %D \item a \TEX\ or driver based method
-% %D \stopitemize
-% %D
-% %D The macro can be extended by adding commands to the token
-% %D list register \type {\everybackgroundbox}. For this
-% %D purpose, the name of the current background is available in
-% %D \type {\currentbackgound}.
-
-\newbox\extraframebox
-
-\newtoks\everybackgroundbox
-
-\let\currentbackground\empty
-
-% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
-% {\bgroup
-% \def\currentbackground{#1}%
-% \the\everybackgroundbox
-% \setbox\extraframebox\hbox
-% {\vbox{\moveleft\backgroundoffset\hbox{\executeifdefined{\??ov\currentbackground}\donothing}}}%
-% \wd\extraframebox\zeropoint % \backgroundwidth
-% \ht\extraframebox\backgroundheight
-% \dp\extraframebox\backgrounddepth
-% \box\extraframebox % \hskip-\backgroundwidth
-% \egroup}
-
-% \def\dodobackgroundbox#1% also less passing, we can get rid of the old method
-% {\bgroup
-% \def\currentbackground{#1}%
-% \ifcsname\??ov\currentbackground\endcsname
-% \the\everybackgroundbox
-% \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
-% \wd\extraframebox\zeropoint % \backgroundwidth
-% \ht\extraframebox\backgroundheight
-% \dp\extraframebox\backgrounddepth
-% \box\extraframebox % \hskip-\backgroundwidth
-% \fi
-% \egroup}
-
-\def\dodobackgroundbox
- {\bgroup
- \ifcsname\??ov\currentbackground\endcsname
- \the\everybackgroundbox
- \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}%
- \wd\extraframebox\zeropoint % \backgroundwidth
- \ht\extraframebox\backgroundheight
- \dp\extraframebox\backgrounddepth
- \box\extraframebox % \hskip-\backgroundwidth
- \fi
- \egroup}
-
-\def\dododobackgroundbox#1,#2% #2 gobbles spaces
- {\edef\currentbackground{#1}%
- \ifx\currentbackground\s!unknown\else
- \dodobackgroundbox\expandafter\dododobackgroundbox
- \fi#2}
-
-\let\backgroundoffset\!!zeropoint
-\let\backgrounddepth \!!zeropoint
-\def\backgroundwidth {\the\hsize}
-\def\backgroundheight{\the\vsize}
-
-% todo: also \def\theforegroundbox{#1}
-
-% \def\dobackgroundbox#1%
-% {\setbox\framebox\vbox
-% {\forgetall
-% \boxmaxdepth\maxdimen
-% \scratchdimen \framedparameter{#1}\relax
-% \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
-% \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
-% \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
-% \edef\backgroundoffset{\the\scratchdimen}%
-% \edef\backgroundwidth {\the\wd\framebox}%
-% \edef\backgroundheight{\the\ht\framebox}%
-% \edef\backgrounddepth {\the\dp\framebox}%
-% %\edef\foregroundbox{\box#1}%
-% \def\foregroundbox% fuzzy but needed hack, this \vss, otherwise
-% {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
-% \edef\component{\framedparameter\c!component}%
-% \hbox to \backgroundwidth % in case 'foreground' is used as overlay
-% {\ifx\component\empty
-% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
-% \else
-% \startlayoutcomponent{b:\component}{\s!background\space\component}%
-% \rawprocesscommalist[\framedbackground]\dodobackgroundbox
-% \stoplayoutcomponent
-% \fi
-% \box\framebox\hss}}}
-
-\def\normalforegroundbox% fuzzy but needed hack, this \vss, otherwise
- {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift
-
-\def\dobackgroundbox#1%
- {\setbox\framebox\vbox
- {\forgetall
- \boxmaxdepth\maxdimen
- \scratchdimen \framedparameter{#1}\relax
- \frameddimenwd\dimexpr\wd\framebox+2\scratchdimen\relax
- \frameddimenht\dimexpr\ht\framebox+ \scratchdimen\relax
- \frameddimendp\dimexpr\dp\framebox+ \scratchdimen+\framedparameter\c!backgrounddepth\relax
- \edef\backgroundoffset{\the\scratchdimen}%
- \edef\backgroundwidth {\the\wd\framebox}%
- \edef\backgroundheight{\the\ht\framebox}%
- \edef\backgrounddepth {\the\dp\framebox}%
- %\edef\foregroundbox{\box#1}%
- \edef\component{\framedparameter\c!component}%
- \let\foregroundbox\normalforegroundbox
- \hbox to \backgroundwidth % in case 'foreground' is used as overlay
- {\ifx\component\empty
- \expanded{\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
- \else
- \startlayoutcomponent{b:\component}{background \component}%
- \expanded{\dododobackgroundbox\framedparameter\c!background},\s!unknown,\relax
- \stoplayoutcomponent
- \fi
- \box\framebox\hss}}}
-
-%D One can explictly insert the foreground box. For that
-%D purpose we introduce the overlay \type {foreground}.
-
-\defineoverlay[\v!foreground][\foregroundbox]
-
-%D We can specify overlays as a comma separated list of
-%D overlays, a sometimes handy feature.
-
-%D Besides backgrounds (overlays) we also need some macros to
-%D draw outlines (ruled borders). Again we have to deal with
-%D square and round corners. The first category can be handled
-%D by \TEX\ itself, the latter one depends on the driver. This
-%D macro also support a negative offset.
-
-\ifx\scratchoffset\undefined \newdimen\scratchoffset \fi
-
-\def\dooutlinebox % we needed to move the color command in order to apply attributes properly
- {\setbox\framebox\vbox % rules on top of box
- {\scratchoffset \framedparameter\c!frameoffset\relax
- \frameddimenwd\dimexpr\wd\framebox+2\scratchoffset\relax
- \frameddimenht\dimexpr\ht\framebox+ \scratchoffset\relax
- \frameddimendp\dimexpr\dp\framebox+ \scratchoffset+\framedparameter\c!framedepth\relax
- \ifdim\frameddimendp<\zeropoint
- \advance\frameddimenht \frameddimendp
- \scratchdimen-\frameddimendp
- \frameddimendp\zeropoint
- \else
- \scratchdimen\zeropoint
- \fi
- \setbox\extraframebox\hbox
- {\doifsomething{\framedparameter\c!framecolor}{\color[\framedparameter\c!framecolor]}{\dostrokedbox}}%
- \setbox\extraframebox\hbox
- {\raise\scratchdimen\vbox
- {\moveleft\scratchoffset
- \box\extraframebox}}%
- \wd\extraframebox\wd\framebox
- \ht\extraframebox\ht\framebox
- \dp\extraframebox\dp\framebox
- \hbox{\box\framebox\hskip-\wd\extraframebox\box\extraframebox}}}
-
-\def\dostrokedbox
- {\doifelse{\framedparameter\c!framecorner}\v!rectangular
- {\dostrokedlinedbox}
- {\ifzeropt\dimexpr\framedparameter\c!frameradius\relax % just in case of .x\bodyfontsize
- \dostrokedlinedbox
- \else
- \dostrokedroundbox
- \fi}}
-
-\def\dostrokedlinedbox
- {\setbox\scratchbox\null
- \wd\scratchbox\frameddimenwd
- \ht\scratchbox\frameddimenht
- \dp\scratchbox\frameddimendp
- \setbox\scratchbox\vbox \bgroup
- \csname t\@@frame@@\framedparameter\c!frame\framedparameter\c!topframe \endcsname
- \hbox \bgroup
- \csname l\@@frame@@\framedparameter\c!frame\framedparameter\c!leftframe \endcsname
- \box\scratchbox
- \csname r\@@frame@@\framedparameter\c!frame\framedparameter\c!rightframe \endcsname
- \egroup
- \csname b\@@frame@@\framedparameter\c!frame\framedparameter\c!bottomframe\endcsname
- \egroup
- \wd\scratchbox\frameddimenwd
- \ht\scratchbox\frameddimenht
- \dp\scratchbox\frameddimendp
- \box\scratchbox}
-
-\def\@@frame@@{@@frame@@}
-
-% \setvalue{t\@@frame@@\v!on \v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{t\@@frame@@\v!off\v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{t\@@frame@@\v!on }{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{b\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
-% \setvalue{b\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
-% \setvalue{b\@@frame@@\v!on }{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
-% \setvalue{l\@@frame@@\v!on \v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{l\@@frame@@\v!off\v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{l\@@frame@@\v!on }{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
-% \setvalue{r\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
-% \setvalue{r\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
-% \setvalue{r\@@frame@@\v!on }{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
-
-\def\@@frame@@trule{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth}
-\def\@@frame@@brule{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth}
-\def\@@frame@@rrule{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth}
-\def\@@frame@@lrule{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth}
-
-\letvalue{t\@@frame@@\v!on \v!on}\@@frame@@trule
-\letvalue{t\@@frame@@\v!off\v!on}\@@frame@@trule
-\letvalue{t\@@frame@@\v!on }\@@frame@@trule
-
-\letvalue{b\@@frame@@\v!on \v!on}\@@frame@@brule
-\letvalue{b\@@frame@@\v!off\v!on}\@@frame@@brule
-\letvalue{b\@@frame@@\v!on }\@@frame@@brule
-
-\letvalue{l\@@frame@@\v!on \v!on}\@@frame@@lrule
-\letvalue{l\@@frame@@\v!off\v!on}\@@frame@@lrule
-\letvalue{l\@@frame@@\v!on }\@@frame@@lrule
-
-\letvalue{r\@@frame@@\v!on \v!on}\@@frame@@rrule
-\letvalue{r\@@frame@@\v!off\v!on}\@@frame@@rrule
-\letvalue{r\@@frame@@\v!on }\@@frame@@rrule
-
-% no overlapping rules
-
-\def\@@frame@@trules{\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}\nointerlineskip\kern-\ruledlinewidth}
-\def\@@frame@@brules{\kern-\ruledlinewidth\nointerlineskip\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}}
-\def\@@frame@@rrules{\kern-\ruledlinewidth\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth}
-\def\@@frame@@lrules{\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth\kern-\ruledlinewidth}
-
-% small is relatively new
-
-\letvalue{t\@@frame@@\v!small\v!small}\@@frame@@trules
-\letvalue{t\@@frame@@\v!off \v!small}\@@frame@@trules
-\letvalue{t\@@frame@@\v!small }\@@frame@@trules
-
-\letvalue{b\@@frame@@\v!small\v!small}\@@frame@@brules
-\letvalue{b\@@frame@@\v!off \v!small}\@@frame@@brules
-\letvalue{b\@@frame@@\v!small }\@@frame@@brules
-
-\letvalue{l\@@frame@@\v!small\v!small}\@@frame@@lrules
-\letvalue{l\@@frame@@\v!off \v!small}\@@frame@@lrules
-\letvalue{l\@@frame@@\v!small }\@@frame@@lrules
-
-\letvalue{r\@@frame@@\v!small\v!small}\@@frame@@rrules
-\letvalue{r\@@frame@@\v!off \v!small}\@@frame@@rrules
-\letvalue{r\@@frame@@\v!small }\@@frame@@rrules
-
-%D I condidered using the low level support command
-%D \type{\ruledhbox}, but this would slow down processing by a
-%D factor~3.
-
-% \framed
-% [width=4cm,height=3cm,rulethickness=3mm,
-% frame=off,rightframe=on,leftframe=on,topframe=on,bottomframe=on]
-% {}
-% \framed
-% [width=4cm,height=3cm,rulethickness=3mm,
-% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=small]
-% {}
-% \framed
-% [width=4cm,height=3cm,rulethickness=3mm,
-% frame=off,rightframe=small,leftframe=small,topframe=small,bottomframe=on]
-% {}
-
-%D The next few macros are probably the most misused ones in
-%D \CONTEXT. They deal with putting rules around boxes, provide
-%D backgrounds, offer alignment features, and some more. We
-%D start with defining some booleans. These give an impression
-%D of what we are going to take into account.
-
-% todo: chardefs
-
-\newif\ifboxhasoffset
-\newif\ifboxhaswidth
-\newif\ifboxhasheight
-\newif\ifboxhasformat
-\newif\ifboxhasstrut
-\newif\ifboxisoverlaid
-\newif\ifboxhasframe
-\newif\ifdelayedstrut
-
-%D We also need a few \DIMENSIONS:
-
-\newdimen\@@localoffset
-\newdimen\@@globalwidth
-
-%D The content of the box will be (temporary) saved in a box:
-
-\newbox\framebox
-
-%D We also need a box for outlines and backgrounds:
-
-\newbox\extraframebox
-
-%D \macros
-%D {framed, setupframed}
-%D
-%D Ruled boxes are typeset using \type{\framed}. This command
-%D is quite versatile and, although some users will probably
-%D seldom use it, one cannot overlook its features.
-%D
-%D \showsetup{setupframed}
-%D \showsetup{framed}
-%D
-%D This general macro is a special version of an even more
-%D general case, that can easily be linked into other macros
-%D that need some kind of framing. The local version is called
-%D with an extra parameter: the variable identifier. The reason
-%D for passing this identifier between brackets lays in the
-%D mere fact that this way we can use the optional argument
-%D grabbers.
-
-\def\defaultframeoffset{.25ex}
-
-\unexpanded\def\framed
- {\bgroup
- \copylocalframed[\??ol][\??oi]% == \presetlocalframed[\??ol]%
- \dodoubleempty\startlocalframed[\??ol]}
-
-\def\presetlocalframed[#1]%
- {\copylocalframed[#1][\??oi]}
-
-% \def\copylocalframed[#1]#2[#3]%
-% {\copyparameters[#1][#3]%
-% [\c!width,\c!height,\c!radius,\c!corner,\c!depth,\c!offset,%
-% \c!autowidth,\c!empty,\c!component,\c!orientation,\c!lines,%
-% \c!align,\c!bottom,\c!top,\c!strut,\c!autostrut,\c!location,\c!setups,\c!extras,%
-% \c!foregroundstyle,\c!foregroundcolor,%
-% \c!background,\c!backgroundoffset,\c!backgroundcorner,\c!backgroundradius,\c!backgrounddepth,\c!backgroundcolor,\c!backgroundscreen,%
-% \c!frame,\c!frameoffset,\c!framecorner,\c!frameradius,\c!framedepth,\c!framecolor,\c!rulethickness,%
-% \c!topframe,\c!bottomframe,\c!leftframe,\c!rightframe]}
-
-% since framed is used all over the place, we have a (small) speedup)
-
-\def\copylocalframed[#1]#2[#3]%
- {\edef\copiedfrom{#1}\edef\copiedto{#3}%
- \docopyvalue\copiedfrom\copiedto\c!width
- \docopyvalue\copiedfrom\copiedto\c!height
- \docopyvalue\copiedfrom\copiedto\c!autowidth
- \docopyvalue\copiedfrom\copiedto\c!offset
- \docopyvalue\copiedfrom\copiedto\c!empty
- \docopyvalue\copiedfrom\copiedto\c!rulethickness
- \docopyvalue\copiedfrom\copiedto\c!radius
- \docopyvalue\copiedfrom\copiedto\c!corner
- \docopyvalue\copiedfrom\copiedto\c!depth
- \docopyvalue\copiedfrom\copiedto\c!frame
- \docopyvalue\copiedfrom\copiedto\c!framecolor
- \docopyvalue\copiedfrom\copiedto\c!foregroundstyle
- \docopyvalue\copiedfrom\copiedto\c!foregroundcolor
- \docopyvalue\copiedfrom\copiedto\c!lines
- \docopyvalue\copiedfrom\copiedto\c!orientation
- \docopyvalue\copiedfrom\copiedto\c!topframe
- \docopyvalue\copiedfrom\copiedto\c!bottomframe
- \docopyvalue\copiedfrom\copiedto\c!leftframe
- \docopyvalue\copiedfrom\copiedto\c!rightframe
- \docopyvalue\copiedfrom\copiedto\c!rulethickness
- \docopyvalue\copiedfrom\copiedto\c!frameoffset
- \docopyvalue\copiedfrom\copiedto\c!background
- \docopyvalue\copiedfrom\copiedto\c!component
- \docopyvalue\copiedfrom\copiedto\c!backgroundoffset
- \docopyvalue\copiedfrom\copiedto\c!backgroundscreen
- \docopyvalue\copiedfrom\copiedto\c!backgroundcolor
- \docopyvalue\copiedfrom\copiedto\c!align
- \docopyvalue\copiedfrom\copiedto\c!bottom
- \docopyvalue\copiedfrom\copiedto\c!top
- \docopyvalue\copiedfrom\copiedto\c!strut
- \docopyvalue\copiedfrom\copiedto\c!autostrut
- \docopyvalue\copiedfrom\copiedto\c!location
- \docopyvalue\copiedfrom\copiedto\c!component
- \docopyvalue\copiedfrom\copiedto\c!extras
- \docopyvalue\copiedfrom\copiedto\c!setups
- \docopyvalue\copiedfrom\copiedto\c!backgroundradius
- \docopyvalue\copiedfrom\copiedto\c!backgroundcorner
- \docopyvalue\copiedfrom\copiedto\c!backgrounddepth
- \docopyvalue\copiedfrom\copiedto\c!frameradius
- \docopyvalue\copiedfrom\copiedto\c!framecorner
- \docopyvalue\copiedfrom\copiedto\c!framedepth}
-
-\def\setupframed
- {\dodoubleempty\dosetupframed}
-
-\def\dosetupframed
- {\ifsecondargument
- \@EA\dodoublesetupframed
- \else
- \@EA\dosinglesetupframed
- \fi}
-
-\def\dosinglesetupframed[#1][#2]%
- {\getparameters[\??oi][#1]}
-
-\def\dodoublesetupframed[#1][#2]%
- {\bgroup
- \let\dodoubleempty\empty
- \def\doframed[##1]{\gdef\globalredefinedframed{\dodoubleempty\doframed[##1,#2]}}%
- \getvalue{#1}%
- \egroup
- \letvalue{#1}\globalredefinedframed}
-
-%D \startbuffer
-%D \setupframed [framecolor=yellow] \framed{A}
-%D \defineframed[myframed] [framecolor=blue] \myframed{B}
-%D \setupframed [myframed] [framecolor=red] \myframed{C}
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-%D
-%D \startbuffer
-%D \presetlocalframed[myframed]
-%D \setuplocalframed[myframed][width=4cm,height=2cm]
-%D \localframed[myframed][framecolor=green]{oeps}
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-%D \macros
-%D {ifinframed}
-%D
-%D The normal case first presets all parameters and next starts
-%D looking for the user supplied ones. The first step is
-%D omitted in the local case, because these are preset at
-%D declaration time and keep their values unless explictly
-%D changed. By presetting the variables everytime the normal
-%D command is called, we can use this command nested, without
-%D the unwanted side effect of inheritance. The boolean is
-%D used to speed up the color stack.
-
-\newif\ifinframed
-
-\def\localframed
- {\bgroup
- \dodoubleempty\startlocalframed}
-
-%D The next one is faster on multiple backgrounds per page. No
-%D dimensions can be set, only frames and backgrounds.
-
-\def\fastlocalframed[#1]#2[#3]#4% 3-4
- {\bgroup
- \inframedtrue
- \edef\@@framed{#1}%
- % more bytes
- % \scratchdimen\framedparameter\c!frameoffset
- % \setevalue{\@@framed\c!frameoffset}{\the\scratchdimen}%
- % \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
- % {\scratchdimen\framedparameter\c!backgroundoffset
- % \setevalue{\@@framed\c!backgroundoffset}{\the\scratchdimen}}%
- % less bytes
- \@EA\freezedimenmacro\csname\@@framed\c!frameoffset\endcsname
- \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
- {\@EA\freezedimenmacro\csname\@@framed\c!backgroundoffset\endcsname}%
- % so far
- \setbox\framebox\hbox{#4}%
- \getparameters[\@@framed][#3]% no \expanded !
- % no, better in calling macro
- %
- % \edef\doframedsetups{\framedparameter\c!setups}%
- % \ifx\doframedsetups\empty\else
- % \edef\doframedsetups{\noexpand\setups[\doframedsetups]}%
- % \fi
- \removeframedboxdepth
- \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
- \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
- \edef\overlaylinecolor{\framedparameter\c!framecolor}%
- \edef\overlaylinewidth{\the\ruledlinewidth}%
- \edef\@@localframing {\framedparameter\c!frame}%
- \ifx\@@localframing\v!overlay \else \ifx\@@localframing\v!none \else
- \edef\framedrulethickness{\framedparameter\c!rulethickness}%
- \ifx\framedrulethickness\empty\else
- \ruledlinewidth\framedrulethickness\relax
- \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
- \fi
- \dooutlinebox % real or invisible frame
- \fi \fi
- \edef\framedbackground{\framedparameter\c!background}%
- \ifx\framedbackground\empty\else\dobackedbox\fi
- \restoreframedboxdepth
- \box\framebox
- \egroup}
-
-%D Before we go into details, we present (and implement) the
-%D main framing routine. I saw no real reason for splitting the
-%D next two macros into smaller pieces. The content will be
-%D collected in a horizontal or vertical box with fixed or free
-%D dimensions and specific settings concerning aligment and
-%D offsets.
-%D
-%D In the first few lines, we pre||expand the frame and
-%D background offsets. We do so, because the can be defined in
-%D terms of the main offset. However, see for instance page
-%D backgrounds, when \type {#2} sets the offset to \type
-%D {overlay}, both offsets become invalid.
-%D
-%D Because it is used so often the he next macro is (and
-%D looks) rather optimized.
-
-\let\postprocessframebox\relax
-
-\let\@@framed\s!unknown
-
-\def\framedparameter#1%
- {\csname\@@framed#1\endcsname}
-
-\newdimen\!!framedwidth
-\newdimen\!!framedheight
-
-\def\startlocalframed[#1][#2]%
- {\bgroup
- \inframedtrue
- \edef\@@framed{#1}%
- % this piece of pre expansion is needed (sometimes used in frameoffset)
- % \doifvaluesomething{\@@framed\c!rulethickness} % obsolete
- % {\ruledlinewidth\getvalue{\@@framed\c!rulethickness}}% obsolete
- % this piece of pre expansion is needed (sometimes used circular)
- \setevalue{\@@framed\c!frameoffset}{\the\dimexpr\framedparameter\c!frameoffset\relax}%
- \doifnotvalue{\@@framed\c!backgroundoffset}\v!frame
- {\setevalue{\@@framed\c!backgroundoffset}{\the\dimexpr\framedparameter\c!backgroundoffset\relax}}%
- % to prevent deadlock in case of self refering
- \ifsecondargument % faster
- \getparameters[\@@framed][#2]% here !
- \fi
- % new, experimental dirty hook
- \framedparameter\c!extras
- % to get the right spacing
- \doifvaluesomething{\@@framed\c!foregroundstyle}
- {\@EA\doconvertfont\csname\@@framed\c!foregroundstyle\endcsname\empty}%
- % beware, both the frame and background offset can be overruled
- %
- \edef\doframedsetups{\framedparameter\c!setups}%
- \ifx\doframedsetups\empty\else
- \edef\doframedsetups{\noexpand\setups[\doframedsetups]}%
- \fi
- % the next macros are visible
- \edef\localoffset{\framedparameter\c!offset}%
- \edef\localwidth {\framedparameter\c!width}%
- \edef\localheight{\framedparameter\c!height}%
- \edef\localformat{\framedparameter\c!align}%
- \edef\localstrut {\framedparameter\c!strut}%
- % these are not
- \edef\@@localautostrut {\framedparameter\c!autostrut}%
- \edef\@@localframing {\framedparameter\c!frame}%
- \edef\@@locallocation {\framedparameter\c!location}%
- \edef\@@localorientation{\framedparameter\c!orientation}%
- %
- \edef\@@localautowidth {\framedparameter\c!autowidth}%
- %
- \ifx\@@localframing\v!overlay % no frame, no offset, no framewidth
- \boxhasframefalse
- \let\localoffset\v!overlay
- \else\ifx\@@localframing\v!none % no frame, no framewidth
- \boxhasframefalse
- \else
- \boxhasframetrue
- \fi\fi
- \ifboxhasframe
- \edef\framedrulethickness{\framedparameter\c!rulethickness}%
- \ifx\framedrulethickness\empty\else
- \ruledlinewidth\framedrulethickness\relax
- \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi
- \fi
- \else
- \ruledlinewidth\zeropoint
- \fi
- \ifx\localformat\empty
- \boxhasformatfalse
- \else
- \boxhasformattrue
- \dosetraggedcommand\localformat
- \edef\dobeforeframedbox{\raggedtopcommand\framedparameter\c!top}%
- \edef\doafterframedbox {\framedparameter\c!bottom\raggedbottomcommand}%
- \fi
- \ifx\localoffset\v!none
- \boxhasoffsetfalse
- \boxhasstrutfalse
- \boxisoverlaidfalse
- \@@localoffset\ruledlinewidth
- \else\ifx\localoffset\v!overlay
- % \ifx\@@localframing\v!no \boxhasframefalse \fi % test first
- \boxhasoffsetfalse
- \boxhasstrutfalse
- \boxisoverlaidtrue
- \@@localoffset\zeropoint
- \else
- \boxhasoffsettrue
- \boxhasstruttrue
- \boxisoverlaidfalse
- \ifx\localoffset\v!default % new per 2-6-2000
- \let\localoffset\defaultframeoffset
- \letvalue{\@@framed\c!offset}\defaultframeoffset
- \else
- \let\defaultframeoffset\localoffset
- \fi
- \@@localoffset\dimexpr\localoffset+\ruledlinewidth\relax
- \fi\fi
- \!!framedheight\zeropoint
- \!!framedwidth \zeropoint
- \ifx\localwidth\v!fit
- \ifboxhasformat
- \boxhaswidthtrue
- \!!framedwidth\hsize
- \else
- \boxhaswidthfalse
- \fi
- \else\ifx\localwidth\v!fixed % equals \v!fit but no shapebox
- \ifboxhasformat
- \boxhaswidthtrue
- \!!framedwidth\hsize
- \else
- \boxhaswidthfalse
- \fi
- \else\ifx\localwidth\v!broad
- \boxhaswidthtrue
- \!!framedwidth\hsize
- \else\ifx\localwidth\v!local
- \boxhaswidthtrue
- \setlocalhsize
- \!!framedwidth\localhsize
- \else
- \boxhaswidthtrue
- \!!framedwidth\localwidth
- \fi\fi\fi\fi
- \ifx\localheight\v!fit
- \boxhasheightfalse % no longer: \boxhasstrutfalse
- \else\ifx\localheight\v!broad
- \boxhasheightfalse
- \else
- \boxhasheighttrue
- \!!framedheight\localheight
- \fi\fi
- \ifboxhasheight
- % obey user set height, also downward compatible
- \else
- \doifvaluesomething{\@@framed\c!lines}
- {\ifcase\framedparameter\c!lines\else
- \!!framedheight\framedparameter\c!lines\lineheight
- \edef\localheight{\the\!!framedheight}%
- \boxhasheighttrue
- \fi}%
- \fi
- % this is now an option: width=local
- %
- % \ifdim\!!framedwidth=\hsize
- % \parindent\zeropoint
- % \setlocalhsize
- % \!!framedwidth\localhsize
- % \fi
- % i.e. disable (colsetbackgroundproblemintechniek)
- \advance\!!framedwidth -2\@@localoffset
- \advance\!!framedheight -2\@@localoffset
- \ifx\localstrut\v!no
- \boxhasstrutfalse
- \else\ifx\localstrut\v!global
- \setstrut
- \else\ifx\localstrut\v!local
- \setfontstrut
- \else
- \setstrut
- \fi\fi\fi
- \ifboxhasstrut
- \let\localbegstrut\begstrut
- \let\localendstrut\endstrut
- \let\localstrut \strut
- \else
- \let\localbegstrut\pseudobegstrut % was: \relax
- \let\localendstrut\pseudoendstrut % was: \relax
- \let\localstrut \pseudostrut % was: \relax
- %\ifboxhasheight\ifdim\!!framedheight<\strutht % saveguard
- % \let\localbegstrut\relax % but not that
- % \let\localstrut \relax % save after all
- %\fi\fi
- \fi
- \ifx\@@localautostrut\v!yes
- \let\delayedbegstrut\relax
- \let\delayedendstrut\relax
- \let\delayedstrut \relax
- \else
- \let\delayedbegstrut\localbegstrut
- \let\delayedendstrut\localendstrut
- \let\delayedstrut \localstrut
- \let\localbegstrut \relax
- \let\localendstrut \relax
- \let\localstrut \relax
- \fi
- \ifboxhasheight
- \let\\\vboxednewline
- \ifboxhaswidth
- \let\hairline\vboxedhairline
- \ifboxhasformat
- \let\next\doformatboxSomeFormat
- \else
- \let\next\doformatboxNoFormat
- \fi
- \else
- \let\hairline\hboxedhairline
- \ifboxhasformat
- \let\next\doformatboxHeight
- \else
- \let\next\doformatboxVSize
- \fi
- \fi
- \else
- \ifboxhaswidth
- \ifboxhasformat
- \let\hairline\vboxedhairline
- \let\\\vboxednewline
- \let\next\doformatboxWidth
- \else
- \let\hairline\hboxedhairline
- \let\\\hboxednewline
- \let\next\doformatboxHSize
- \fi
- \else
- \let\hairline\hboxedhairline
- \let\\\hboxednewline
- \let\next\doformatboxNoSize
- \fi
- \fi
- \edef\framedwidth % a new feature, visible for user
- {\ifdim\!!framedwidth >\zeropoint\the\!!framedwidth \else\zeropoint\fi}%
- \edef\framedheight% a new feature, visible for user
- {\ifdim\!!framedheight>\zeropoint\the\!!framedheight\else\zeropoint\fi}%
- % we need to register the (outer) color
- \startregistercolor[\framedparameter\c!foregroundcolor]%
- % first alternative
- %\def\dowithframedbox%
- % {\let\postprocessframebox\relax %new
- % \aftergroup\stoplocalframed}%
- % \afterassignment\dowithframedbox
- % \setbox\framebox=\next}
- % second alternative
- %\dowithnextbox
- % {\setbox\framebox\flushnextbox
- % \let\postprocessframebox\relax %new
- % \stoplocalframed}
- % \next}
- \@@startframedorientation
- \afterassignment\dodowithframebox
- \setbox\framebox\next}
-
-\def\dowithframebox
- {% moved : \let\postprocessframebox\relax
- \stoplocalframed}
-
-\def\dodowithframebox
- {\aftergroup\dowithframebox}
-
-\let\doafterframedbox \relax
-\let\dobeforeframedbox\relax
-
-%D Carefull analysis of this macro will learn us that not all
-%D branches in the last conditionals can be encountered, that
-%D is, some assignments to \type{\next} will never occur.
-%D Nevertheless we implement the whole scheme, if not for
-%D future extensions.
-
-%D \macros
-%D {ifreshapeframebox}
-%D
-%D The last few lines tell what to do after the content of the
-%D box is collected and passed to the next macro. In the case
-%D of a fixed width and centered alignment, the content is
-%D evaluated and used to determine the most natural width. The
-%D rest of the code deals with backgrounds and frames.
-
-\newif\ifreshapeframebox \reshapeframeboxtrue
-
-%D Beware: setting \type {top} and \type {bottom} to nothing, may
-%D result in a frame that is larger that the given height! try:
-%D
-%D \starttyping
-%D \framed
-%D [height=3cm,top=,bottom=,offset=overlay]
-%D {\strut test \shapefill \strut test}
-%D \stoptyping
-%D
-%D This is intended behaviour and not a bug! One can always set
-%D
-%D \starttyping
-%D ...,bottom=\kern0pt,...
-%D \stoptyping
-
-\def\stoplocalframed
- {\dontshowcomposition
- \@@stopframedorientation % hm, wrong place ! should rotate the result (after reshape)
- \stopregistercolor
- \handleframedlocator\c!before\@@locallocation
- \ifboxhasformat
- \ifx\@@localautowidth\v!force
- \ifreshapeframebox\doreshapeframedbox\fi
- \boxhaswidthfalse
- \else
- \ifx\localwidth\v!fit
- \ifx\@@localautowidth\v!yes
- \ifreshapeframebox\doreshapeframedbox\fi
- \fi
- \boxhaswidthfalse
- \else\ifx\localwidth\v!fixed
- \boxhaswidthfalse
- \else
- \resetshapeframebox
- \fi\fi
- \fi
- \else
- \resetshapeframebox
- \fi
- \ifboxhaswidth
- \wd\framebox\!!framedwidth
- \fi
- \ifboxhasheight
- \ht\framebox\!!framedheight
- \fi
- \doifvalue{\@@framed\c!empty}\v!yes
- {\setbox\scratchbox\null
- \wd\scratchbox\wd\framebox
- \ht\scratchbox\ht\framebox
- \dp\scratchbox\dp\framebox
- \setbox\framebox\box\scratchbox}%
- \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}%
- \ifx\framedforegroundcolor\empty\else\docolorframebox\fi
- \ifboxhasoffset
- \dooffsetframebox
- \fi
- \ifboxisoverlaid \else
- \dolocateframebox
- \fi
- \ifx\postprocessframebox\relax \else
- \let\next\postprocessframebox
- \let\postprocessframebox\relax % prevent nesting
- \next\framebox
- \fi
- \edef\overlaylinecolor{\framedparameter\c!framecolor}%
- \edef\overlaylinewidth{\the\ruledlinewidth}% \@@...
- \ifboxhasframe % real or invisible frame
- \dooutlinebox
- \fi
- \edef\framedbackground{\framedparameter\c!background}%
- \ifx\framedbackground\empty\else\dobackedbox\fi
- \handleframedlocator\c!after\@@locallocation
- \box\framebox
- \egroup
- \egroup}
-
-\def\installframedlocator#1#2#3%
- {\setvalue{\??ol:\c!location:\c!before:#1}{#2}%
- \setvalue{\??ol:\c!location:\c!after :#1}{#3}}
-
-\def\handleframedlocator#1#2%
- {\getvalue{\??ol:\c!location:#1:#2}}
-
-\def\doprelocframedbox#1%
- {\scratchdimen\dimexpr#1+\ruledlinewidth\relax
- \ifboxhasoffset
- \advance\scratchdimen \framedparameter\c!offset
- \fi
- \scratchskip\dimexpr\ht\framebox-\scratchdimen\relax}
-
-% \ruledhbox
-% {A
-% \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
-% \framed[width=2cm,align=middle,location=depth] {location\\equals\\depth}
-% \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
-% B}
-% \vskip2cm
-% \ruledhbox
-% {A
-% \framed[width=2cm,align=middle,location=low] {location\\equals\\low}
-% \framed[width=2cm,align=middle,location=line] {location\\equals\\line}
-% \framed[width=2cm,align=middle,location=high] {location\\equals\\high}
-% B}
-% \vskip2cm
-% \ruledhbox
-% {A
-% \framed[width=2cm,align=middle,location=top] {location\\equals\\top}
-% \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
-% \framed[width=2cm,align=middle,location=lohi] {location\\equals\\lohi}
-% \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
-% B}
-
-\installframedlocator \v!hanging % best with strut=no
- {}
- {\dp\framebox\ht\framebox
- \ht\framebox\zeropoint}
-
-\installframedlocator \v!depth
- {}
- {\ht\framebox\dimexpr\ht\framebox-\strutdp\relax
- \dp\framebox\strutdp
- \box\framebox}
-
-\installframedlocator \v!height
- {}
- {\dp\framebox\dimexpr\ht\framebox-\strutht\relax
- \ht\framebox\strutht
- \box\framebox}
-
-\installframedlocator \v!high
- {}
- {\doprelocframedbox\strutht
- \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
- \ht\framebox\strutht
- \dp\framebox\strutdp
- \hbox{\box\framebox}}
-
-\installframedlocator \v!line
- {}
- {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}%
- \ht\framebox.5\lineheight
- \dp\framebox.5\lineheight
- \hbox{\box\framebox}}
-
-\installframedlocator \v!low
- {}
- {\doprelocframedbox\strutdp
- \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
- \ht\framebox\strutht
- \dp\framebox\strutdp
- \box\framebox}
-
-\installframedlocator \v!top
- {}
- {\doprelocframedbox\strutht
- \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
- \ht\framebox\scratchdimen
- \dp\framebox\scratchskip
- \hbox{\box\framebox}}
-
-\installframedlocator \v!middle
- {}
- {\scratchdimen.5\ht\framebox
- \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
- \ht\framebox\scratchdimen
- \dp\framebox\scratchdimen
- \hbox{\box\framebox}}
-
-\installframedlocator \v!lohi
- {\handleframedlocator\c!before\v!middle}
- {\handleframedlocator\c!after \v!middle}
-
-\installframedlocator \v!bottom
- {}
- {\doprelocframedbox\strutdp
- \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
- \ht\framebox\scratchskip
- \dp\framebox\scratchdimen
- \hbox{\box\framebox}}
-
-\installframedlocator \v!keep % retains height/depth
- {\removeframedboxdepth}
- {\restoreframedboxdepth}
-
-% also used in fastlocalframed
-
-\newdimen\originalframedwd
-\newdimen\originalframedht
-\newdimen\originalframeddp
-
-\def\removeframedboxdepth
- {\originalframedwd\wd\framebox
- \originalframedht\ht\framebox
- \originalframeddp\dp\framebox
- \ifzeropt\originalframeddp\else\setbox\framebox\hbox{\raise\originalframeddp\box\framebox}\fi
- \wd\framebox\originalframedwd
- \ht\framebox\dimexpr\originalframedht+\originalframeddp\relax
- \dp\framebox\zeropoint}
-
-\def\restoreframedboxdepth
- {\ifzeropt\originalframeddp\else\setbox\framebox\hbox{\lower\originalframeddp\box\framebox}\fi
- \wd\framebox\originalframedwd
- \ht\framebox\originalframedht
- \dp\framebox\originalframeddp}
-
-% \let\@@startframedorientation\relax
-% \let\@@stopframedorientation \relax
-
-% \framed[width=12cm,height=3cm,orientation=0]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=90]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=180]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=270]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=-90]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=-180]{\input ward\relax}
-% \framed[width=12cm,height=3cm,orientation=-270]{\input ward\relax}
-
-\def\@@startframedorientation
- {\let\@@stopframedorientation \relax
- \ifx\@@localorientation\empty\else
- \ifcase\@@localorientation\else
- \scratchcounter\@@localorientation
- \divide\scratchcounter\plustwo
- \ifodd\scratchcounter
- \swapmacros\framedwidth \framedheight
- \swapmacros\localwidth \localheight
- \swapdimens\!!framedheight\!!framedwidth
- \def\@@stopframedorientation{\@@dostopframedorientation\plusone}%
- \else
- \def\@@stopframedorientation{\@@dostopframedorientation\zerocount}%
- \fi
- \fi
- \fi}
-
-\def\@@dostopframedorientation#1%
- {\ifcase#1\else
- \swapmacros\framedwidth \framedheight
- \swapmacros\localwidth \localheight
- \swapdimens\!!framedheight\!!framedwidth
- \fi
- \setbox\framebox\hbox{\dorotatebox\@@localorientation\hbox{\box\framebox}}}
-
-%D The last conditional takes care of the special situation of
-%D in||line \inframed[height=3cm]{framed} boxes. Such boxes have
-%D to be \inframed{aligned} with the running text.
-
-\def\doinframed[#1]% we could omit #1] but readibility ...
- {\framed[\c!location=\v!low,#1]}
-
-\unexpanded\def\inframed
- {\dosingleempty\doinframed}
-
-%D When we set \type{empty} to \type{yes}, we get
-%D ourselves a frame and/or background, but no content, so
-%D actually we have a sort of phantom framed box.
-
-%D Because color marks and specials can interfere with
-%D spacing, we provide a way to specify a foregroundcolor.
-
-\def\docolorframebox
- {\doifvaluesomething{\@@framed\c!foregroundcolor}
- {\doifcolorelse{\framedparameter\c!foregroundcolor}
- {\setbox\framebox\hbox
- {\localcolortrue
- \color[\framedparameter\c!foregroundcolor]{\box\framebox}}}
- {}}}
-
-%D \macros
-%D {mframed, minframed}
-%D
-%D When Tobias asked how to frame mathematical elements in
-%D formulas, Taco's posted the next macro:
-%D
-%D \starttyping
-%D \def\mframed#1%
-%D {\relax
-%D \ifmmode
-%D \vcenter{\hbox{\framed{$\ifinner\else\displaystyle\fi#1$}}}%
-%D \else
-%D \framed{$#1$}%
-%D \fi}
-%D \stoptyping
-%D
-%D Because \type {\ifinner} does not (always) reports what
-%D one would expect, we move the test to the outer level. We
-%D also want to pass arguments,
-%D
-%D \starttyping
-%D \def\mframed%
-%D {\dosingleempty\domframed}
-%D
-%D \def\domframed[#1]#2% % tzt \dowithnextmathbox ?
-%D {\relax
-%D \ifmmode
-%D \ifinner
-%D \inframed[#1]{$#2$}%
-%D \else
-%D \vcenter{\hbox{\framed[#1]{$\displaystyle#2$}}}%
-%D \fi
-%D \else
-%D \inframed[#1]{$#2$}%
-%D \fi}
-%D \stoptyping
-%D
-%D Still better is the next alternative, if only because it
-%D takes care of setting the super- and subscripts styles
-
-\ifx\restoremathstyle\undefined \let\restoremathstyle\relax \fi
-
-\def\domframed[#1][#2]#3%
- {\begingroup
- \ifmmode
- \ifinner
- \let\mframedstyle\restoremathstyle
- \else
- \let\mframedstyle\displaystyle
- \fi
- \else
- \let\mframedstyle\restoremathstyle
- \fi
- #1\ifdone
- \def\normalstrut{$\mframedstyle\vphantom($}%
- \framed
- [\c!frameoffset=\@@oioffset,\c!offset=\v!overlay,#2]
- {$\mframedstyle#3$}%
- \else
- \inframed
- [#2]
- {$\mframedstyle#3$}%
- \fi
- \endgroup}
-
-\def\mframed
- {\dodoubleempty\domframed[\donetrue]}
-
-\def\inmframed
- {\dodoubleempty\domframed[\donefalse]}
-
-%D So instead of the rather versatile \type {\framed}, we ue
-%D the \type {\mframed}.
-%D
-%D \startbuffer
-%D \startformula
-%D x \times \mframed{y} \times y^{z_z}
-%D x \times \inmframed{y} \times y^{z_z}
-%D \stopformula
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D However, we got into troubles when we want to nest sub- and
-%D superscripts, like in
-%D
-%D \startbuffer
-%D \startformula
-%D x \times \mframed{y} \times y^{\mframed{z}_{\mframed{z}}}
-%D \stopformula
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D Therefore, we can best use \type {\super} and \type {\suber}
-%D instead of \type {^} and \type {_}. Both commands take care
-%D of proper font switching.
-%D
-%D \startbuffer
-%D \startformula
-%D x \times \mframed{y} \times y\super{\mframed{z}\suber{\mframed{z}}}
-%D \stopformula
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D As usual, one can specify in what way the text should be
-%D framed. One should be aware of the fact that, inorder to
-%D preserve the proper spacing, the \type {offset} is set to
-%D \type {overlay} and \type {frameoffset} is used used
-%D instead.
-%D
-%D \startbuffer
-%D \startformula
-%D x \times y\super{\mframed[framecolor=red]{z}\suber{z}}
-%D \stopformula
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D For inline use, we also provide the \type {\inmframed}
-%D alternative: we want $x \times \inmframed{y}$ in inline
-%D math, right?
-
-%D This previous framing macros needs a lot of alternatives for
-%D putting rules around boxes, inserting offsets and aligning
-%D text. Each step is handled by separate macros.
-
-\def\dowidenframebox#1%
- {\setbox\framebox\vbox
- {\kern#1\hbox{\kern#1\box\framebox\kern#1}\kern#1}}
-
-\def\dooffsetframebox{\dowidenframebox\localoffset}
-\def\dolocateframebox{\dowidenframebox\ruledlinewidth}
-
-%D Let's hope that the next few examples show us enough of
-%D what needs to be done by the auxiliary macros.
-%D
-%D \startbuffer
-%D \framed[height=1cm,offset=.5cm] {rule based learning}
-%D \framed[height=1cm,offset=0cm] {rule based learning}
-%D \framed[height=1cm,offset=none] {rule based learning}
-%D \framed[height=1cm,offset=overlay]{rule based learning}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \hbox{\getbuffer}
-%D \stoplinecorrection
-%D
-%D \startbuffer
-%D \framed[offset=.5cm] {rule based learning}
-%D \framed[offset=0cm] {rule based learning}
-%D \framed[offset=none] {rule based learning}
-%D \framed[offset=overlay]{rule based learning}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \hbox{\getbuffer}
-%D \stoplinecorrection
-%D
-%D \startbuffer
-%D \framed[strut=nee,offset=.5cm] {rule based learning}
-%D \framed[strut=nee,offset=0cm] {rule based learning}
-%D \framed[strut=nee,offset=none] {rule based learning}
-%D \framed[strut=nee,offset=overlay]{rule based learning}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \hbox{\getbuffer}
-%D \stoplinecorrection
-%D
-%D \startbuffer
-%D \framed[width=3cm,align=left] {rule\\based\\learning}
-%D \framed[width=3cm,align=middle] {rule\\based\\learning}
-%D \framed[width=3cm,align=right] {rule\\based\\learning}
-%D \framed[width=fit,align=middle] {rule\\based\\learning}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \hbox{\dontcomplain\getbuffer}
-%D \stoplinecorrection
-%D
-%D So now we're ready for the complicated stuff. We distinguish
-%D between borders with straight lines and those with round
-%D corners. When using the first alternative it is possible to
-%D turn off one or more lines. More fancy shapes are also
-%D possible by specifying dedicated backgrounds. Turning lines
-%D on and off is implemented as efficient as possible and as a
-%D result is interface language dependant. This next
-%D implementation evolved from simpler ones. It puts for
-%D instance the rules on top of the content and provides
-%D additional offset capabilities. The lot of calls to other
-%D macros makes this mechanism not that easy to comprehend.
-
-%D Getting the backgrounds right takes less code. Again we
-%D have to take care of additional offsets.
-
-\def\dobackedbox
- {\doifelsevalue{\@@framed\c!backgroundoffset}\v!frame % new
- {\dobackgroundbox\c!frameoffset}
- {\dobackgroundbox\c!backgroundoffset}}
-
-%D We handle left, right or middle alignment as well as fixed
-%D or free widths and heights. Each combination gets its own
-%D macro.
-
-%D The following code handles one-liners: \type{align={line,flushright}}.
-%D Beware, since we entered a group and either or not grab the next
-%D bgroup token, we need to finish the group in the oneliner mode.
-
-\ifx\raggedoneliner\undefined \chardef\raggedoneliner\zerocount \fi
-
-\def\doformatonelinerbox % beware: assumes explicit preceding bgroup
- {\ifcase\raggedoneliner
- \expandafter\nodoformatonelinerbox
- \else
- \expandafter\dodoformatonelinerbox
- \fi}
-
-\def\dodoformatonelinerbox
- {\dowithnextboxcontent
- {\ignorespaces}
- {\hbox to \hsize
- {\ifcase\raggedstatus\or\hss\or\hss\fi
- \unhbox\nextbox \removeunwantedspaces
- \ifcase\raggedstatus\or \or\hss\or\hss\fi}%
- \egroup}
- \hbox}
-
-\def\nodoformatonelinerbox % grabs {
- {\let\next=}
-
-%D The handlers:
-
-\def\doformatboxSomeFormat
- {\vbox to \!!framedheight
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \oninterlineskip
- \hsize\!!framedwidth
- \vsize\!!framedheight
- \doframedsetups
- \raggedcommand
- \dobeforeframedbox
- \bgroup
- \localbegstrut
- \aftergroup\localendstrut
- \aftergroup\doafterframedbox
- \aftergroup\egroup
- \doformatonelinerbox}
-
-\def\doformatboxNoFormat
- {\vbox to \!!framedheight
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \oninterlineskip
- \hsize\!!framedwidth
- \vsize\!!framedheight
- \doframedsetups
- \raggedcenter
- \vss
- \bgroup
- \localbegstrut
- \aftergroup\localendstrut
- \aftergroup\vss
- \aftergroup\egroup
- \doformatonelinerbox}
-
-\def\doformatboxHeight
- {\vbox to \!!framedheight
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \oninterlineskip
- \doframedsetups
- \raggedcommand
- \vss
- \bgroup
- \aftergroup\localendstrut
- \aftergroup\vss
- \aftergroup\egroup
- \localbegstrut
- \doformatonelinerbox}
-
-\def\doformatboxWidth
- {\vbox
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \oninterlineskip
- \hsize\!!framedwidth
- \doframedsetups
- \raggedcommand
- \dobeforeframedbox
- \bgroup
- \localbegstrut
- \aftergroup\localendstrut
- \aftergroup\doafterframedbox
- \aftergroup\egroup
- \doformatonelinerbox}
-
-\def\doformatboxVSize
- {\vbox to \!!framedheight
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \vsize\!!framedheight
- \doframedsetups
- \vss
- \bgroup
- \aftergroup\vss
- \aftergroup\egroup
- \hbox
- \bgroup
- \aftergroup\egroup
- \localstrut
- \doformatonelinerbox}
-
-\def\doformatboxHSize
- {\hbox to \!!framedwidth
- \bgroup
- \let\postprocessframebox\relax
- \forgetall
- \doframedsetups
- \hss
- \localstrut
- \bgroup
- \aftergroup\hss
- \aftergroup\egroup
- \doformatonelinerbox}
-
-\def\doformatboxNoSize
- {\hbox
- \bgroup
- \let\postprocessframebox\relax
- \doframedsetups
- \localstrut
- \doformatonelinerbox}
-
-\let\doframedsetups\relax
-
-%D On the next page we show some examples of how these macros
-%D come into action. The examples show us how
-%D \type {fit}, \type {broad} dimensions influence the
-%D formatting. Watch the visualized struts. \footnote {Here we
-%D used \type {\showstruts}.}
-%D
-%D \startpostponing
-%D \bgroup
-%D \showstruts
-%D \dontcomplain
-%D \startlinecorrection
-%D \halign{#\enskip\enskip\enskip\enskip\enskip\cr
-%D \framed[width=.2\hsize, height=.2\hsize, align=] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=broad, align=] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=fit, align=] {a\par b\par c}&
-%D \framed[width=fit, height=.2\hsize, align=] {a\par b\par c}&
-%D \framed[width=fit, height=broad, align=] {a\par b\par c}&
-%D \framed[width=fit, height=fit, align=] {a\par b\par c}\cr
-%D \noalign{\vskip1em}
-%D \framed[width=.2\hsize, height=.2\hsize, align=yes] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=broad, align=yes] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=fit, align=yes] {a\par b\par c}&
-%D \framed[width=fit, height=.2\hsize, align=yes] {a\par b\par c}&
-%D \framed[width=fit, height=broad, align=yes] {a\par b\par c}&
-%D \framed[width=fit, height=fit, align=yes] {a\par b\par c}\cr
-%D \noalign{\vskip1em}
-%D \framed[width=.2\hsize, height=.2\hsize, align=right] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=broad, align=right] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=fit, align=right] {a\par b\par c}&
-%D \framed[width=fit, height=.2\hsize, align=right] {a\par b\par c}&
-%D \framed[width=fit, height=broad, align=right] {a\par b\par c}&
-%D \framed[width=fit, height=fit, align=right] {a\par b\par c}\cr
-%D \noalign{\vskip1em}
-%D \framed[width=.2\hsize, height=.2\hsize, align=left] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=broad, align=left] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=fit, align=left] {a\par b\par c}&
-%D \framed[width=fit, height=.2\hsize, align=left] {a\par b\par c}&
-%D \framed[width=fit, height=broad, align=left] {a\par b\par c}&
-%D \framed[width=fit, height=fit, align=left] {a\par b\par c}\cr
-%D \noalign{\vskip1em}
-%D \framed[width=.2\hsize, height=.2\hsize, align=middle] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=broad, align=middle] {a\par b\par c}&
-%D \framed[width=.2\hsize, height=fit, align=middle] {a\par b\par c}&
-%D \framed[width=fit, height=.2\hsize, align=middle] {a\par b\par c}&
-%D \framed[width=fit, height=broad, align=middle] {a\par b\par c}&
-%D \framed[width=fit, height=fit, align=middle] {a\par b\par c}\cr}
-%D \stoplinecorrection
-%D \blank[2*big]
-%D \egroup
-%D \stoppostponing
-
-%D \macros
-%D {framednoflines, framedlastlength}
-%D
-%D It is possible to let the frame macro calculate the width
-%D of a centered box automatically (\type {fit}). When
-%D doing so, we need to reshape the box:
-
-% The next implementation is frozen! It preserves the depth,
-% otherwise we get problems with framed display math and auto
-% width.
-
-\newcount\framednoflines
-\newdimen\framedlastlength
-
-\def\resetshapeframebox
- {\framednoflines \zerocount
- \framedlastlength\zeropoint}
-
-\let\framedboxwidth \!!zeropoint
-\let\framedboxheight\!!zeropoint
-\let\framedboxdepth \!!zeropoint
-
-\chardef\reshapeframeboxmethod\plusone % 0=no flush, 1=old method 2=no depth messing
-
-%D The two variables \type {\framednoflines} and \type
-%D {\framedlastlength} can be used in a second pass to
-%D optimized framed material.
-
-% torture test / strange case (much depth) / method 2 needed
-%
-% \startTEXpage[frame=on]
-% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
-% test outside formula
-% \startformula \startalign \NC A \NC B \NR \intertext{test} \NC C \NC D \NR \stopalign \stopformula
-% \blank[big]
-% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
-% test outside formula
-% \startformula \startalign \NC \int_01 \NC B \NR \intertext{test} \NC \int_01 \NC D \NR \stopalign \stopformula
-% \stopTEXpage
-
-%D The examples on the next page show how one can give the
-%D frame as well as the background an additional offset and
-%D even a bit more depth. The blue outline is the frame, the
-%D red box is the background and the small black outline is the
-%D visualization of the resulting box, that is, we applied
-%D \type{\ruledhbox} to the result.
-
-%D \startpostponing
-%D \bgroup
-%D \unprotect
-%D \dontcomplain
-%D
-%D \startbuffer
-%D \vbox to \vsize
-%D \bgroup
-%D \startalignment[middle]
-%D \vss
-%D \leavevmode\vbox to .8\vsize
-%D \bgroup
-%D \hsize=300pt
-%D \setupframed
-%D [background=color,
-%D backgroundcolorachtergrondkleur=darkred,
-%D width=300pt,
-%D height=60pt,
-%D framecolorkaderkleur=DemoBlue,
-%D rulethickness=2pt]
-%D \def\status%
-%D {backgroundoffset=\framedparameter\c!backgroundoffset\\
-%D frameoffset=\framedparameter\c!frameoffset\\
-%D depth=\framedparameter\c!depth}
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=0pt]{\status}}
-%D \vss
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=0pt]{\status}}
-%D \vss
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=0pt,frameoffset=5pt]{\status}}
-%D \vss
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=2pt,frameoffset=5pt]{\status}}
-%D \vss
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=2pt]{\status}}
-%D \vss
-%D \leavevmode \ruledhbox{\framed[backgroundoffset=5pt,frameoffset=5pt]{\status}}
-%D \egroup
-%D \vss
-%D \stopalignment
-%D \egroup
-%D \stopbuffer
-%D
-%D \getbuffer \page
-%D
-%D {\setupframed[depth=4pt]\getbuffer} \page
-%D
-%D \protect
-%D \egroup
-%D \stoppostponing
-
-%D When typesetting the framed box inline, we have to keep the
-%D baseline intact outside as well as inside the framed box.
-
-\def\doinlineframedbox
- {\scratchdimen\dimexpr\strutdp+\ruledlinewidth\relax
- \ifboxhasoffset
- \advance\scratchdimen \framedparameter\c!offset
- \fi
- \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
- \ht\framebox\strutht
- \dp\framebox\strutdp
- \box\framebox}
-
-%D We can also lower the box over the natural depth of the
-%D line.
-
-\def\doloweredframedbox
- {\ht\framebox\dimexpr\ht\framebox+\dp\framebox-\strutdp\relax
- \dp\framebox\strutdp
- \box\framebox}
-
-%D Hanging the content is mainly meant for cases like the
-%D following:
-%D
-%D \starttyping
-%D \framed[strut=no]
-%D {\framed[height=2cm,location=hanging]{test}%
-%D \framed[height=1cm,location=hanging]{test}}
-%D \stoptyping
-
-\def\dohangingframedbox % best with strut=no
- {\scratchdimen\dimexpr\ht\framebox+\dp\framebox\relax
- \ht\framebox\zeropoint
- \dp\framebox\scratchdimen}
-
-%D We can draw lines from left to right and top to bottom by
-%D using the normal \type{\hairline} command. Both directions
-%D need a different treatment.
-%D
-%D \startbuffer
-%D \framed[width=4cm] {alfa\hairline beta\hairline gamma}
-%D \framed[height=2cm] {alfa\hairline beta\hairline gamma}
-%D \framed[width=4cm,height=2cm]{alfa\hairline beta\hairline gamma}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \hbox{\getbuffer}
-%D \stoplinecorrection
-%D
-%D These macros try to adapt their behaviour as good as
-%D possible to the circumstances and act as natural as
-%D possible.
-
-\def\vboxedhairline
- {\bgroup
- \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
- \dimen4=\dimexpr\dimen2+\ruledlinewidth\relax
- \setbox0\vbox
- {\advance\hsize 2\dimen4
- \vskip\dimen2
- \hrule
- \!!height\ruledlinewidth
- \!!depth\zeropoint
- \!!width\hsize
- \vskip\dimen2}%
- %\endgraf\nointerlineskip\endgraf
- %\moveleft\dimen4\box0
- %\endgraf\nointerlineskip\localbegstrut
- \endgraf\obeydepth\nointerlineskip
- \moveleft\dimen4\box0
- \endgraf\nointerlineskip\localbegstrut % beware, we might kill it in a style using \vskip\lineheight
- \egroup} % so this must not be changed
-
-\def\hboxedhairline % use framed dimen
- {\bgroup
- \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi
- \ifboxhasheight
- \dimen4\dimexpr\localheight/2+\strutdp-2\ruledlinewidth\relax
- \dimen6\dimexpr\localheight/2-\strutdp+2\ruledlinewidth\relax
- \else
- \dimen4\dimexpr\strutht+\dimen2\relax
- \dimen6\dimexpr\strutdp+\dimen2\relax
- \fi
- \unskip
- \setbox\scratchbox\hbox
- {\hskip\dimen2
- \vrule\!!height\dimen4\!!depth\dimen6\!!width\ruledlinewidth
- \hskip\dimen2}%
- \ht\scratchbox\strutht
- \dp\scratchbox\strutdp
- \box\scratchbox
- \ignorespaces
- \egroup}
-
-%D The argument of the frame command accepts \type{\\} as a
-%D sort of newline signal. In horizontal boxes it expands to a
-%D space.
-
-\def\vboxednewline
- {\endgraf\ignorespaces}
-
-\def\hboxednewline
- {\unskip\normalspace\ignorespaces}
-
-%D We can set each rule on or off. The default setting is
-%D inherited from \type{frame}. An earlier implementation
-%D use a bit different approach, but the new one seems more
-%D natural:
-%D
-%D \bgroup
-%D \setuptyping[margin=0pt]
-%D \startlinecorrection
-%D \startbuffer
-%D \framed[offset=overlay,frame=on]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D
-%D \startbuffer
-%D \framed[offset=overlay,frame=on,bottomframe=off]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D
-%D \startbuffer
-%D \framed[offset=overlay,frame=on,bottomframe=on]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D
-%D \startbuffer
-%D \framed[offset=overlay,frame=off]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D
-%D \startbuffer
-%D \framed[offset=overlay,frame=off,bottomframe=off]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D
-%D \startbuffer
-%D \framed[offset=overlay,frame=off,bottomframe=on]{\darkred\blackrule}
-%D \stopbuffer
-%D \hbox{\getbuffer\vbox{\typebuffer}}
-%D \stoplinecorrection
-%D \egroup
-
-%D \macros
-%D {setupblackrules}
-%D
-%D The graphic capabilities of \TEX\ do not go beyond simple
-%D filled rules, except of course when using specials. Let's
-%D start with a warning: using this commands is far more slower
-%D than using the \TEX\ primitives \type{\hrule} and
-%D \type{\vrule}, but they save us some tokens. The
-%D characteristics of these rule drawing command can be set by:
-%D
-%D \showsetup{setupblackrules}
-
-\def\setupblackrules
- {\dodoubleargument\getparameters[\??bj]}
-
-%D \macros
-%D {blackrule}
-%D
-%D The simple command draws only one rule. Its optional
-%D argument can be used to specify the dimensions. By setting
-%D the width, height or depth to \type {max}, one gets the
-%D natural dimensions.
-%D
-%D \showsetup{blackrule}
-
-\def\doblackrule[#1]%
- {\hbox\bgroup
- \getparameters[\??bj][#1]%
- \setstrut
- \doif\@@bjwidth \v!max{\def\@@bjwidth {1em}}%
- \doif\@@bjheight\v!max{\def\@@bjheight{\strutht}}%
- \doif\@@bjdepth \v!max{\def\@@bjdepth {\strutdp}}%
- \localstartcolor[\@@bjcolor]%
- \vrule
- \!!width \@@bjwidth
- \!!height\@@bjheight
- \!!depth \@@bjdepth
- \localstopcolor
- \egroup}
-
-\unexpanded\def\blackrule
- {\dosingleempty\doblackrule}
-
-%D \macros
-%D {blackrules}
-%D
-%D One can call for a sequence of black rules, if needed
-%D equally spaced over the given width.
-%D
-%D \showsetup{blackrules}
-%D
-%D The two alternative calls are therefore:
-%D
-%D \startbuffer
-%D Tell me, is this according to the \blackrules[n=6]?
-%D These \blackrules[alternativevariant=b,n=10,distance=.2em,width=4cm] are quite clear.
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D or:
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D We could of course have implemented this macro using
-%D \type{\leaders}, but this would probably have taken more
-%D tokens.
-
-\def\doblackrules[#1]%
- {\hbox\bgroup
- \getparameters[\??bj][#1]%
- \!!widtha\@@bjwidth
- \!!widthb\@@bjdistance
- \doif\@@bjalternative\c!b
- {\scratchcounter\@@bjn
- \ifnum\scratchcounter=\plusone
- \!!widthb\zeropoint
- \else
- \advance\scratchcounter \minusone
- \advance\!!widtha -\scratchcounter\!!widthb
- \divide \!!widtha \@@bjn
- \fi}%
- \localstartcolor[\@@bjcolor]%
- \dorecurse\@@bjn
- {\vrule
- \!!width \!!widtha
- \!!height\@@bjheight
- \!!depth \@@bjdepth
- \hskip\!!widthb}%
- \unskip
- \localstopcolor
- \egroup}
-
-\unexpanded\def\blackrules
- {\dosingleempty\doblackrules}
-
-%D The next commands can be used to draw margin rules. We
-%D support two methods: \marginrule{one for in||line use} and
-%D one that acts on a paragraph. Drawing a margin rule is
-%D rather straightforward because we can use the commands that
-%D put text in the margin.
-
-\def\dodrawmarginrule
- {\setbox\scratchbox\hbox
- {\vrule\!!depth\strutdepth\!!height\strutheight\!!width\@@karulethickness}%
- \smashbox\scratchbox % no \vsmash !!!
- \box\scratchbox}
-
-\def\drawmarginrule
- {\strut\inleft{\dodrawmarginrule}}
-
-%D \macros
-%D {marginrule}
-%D
-%D The first method gobbles words and simply puts a bar in the
-%D margin. This method is not entirely robust.
-%D
-%D \showsetup{marginrule}
-
-\definecomplexorsimple\marginrule
-
-\def\simplemarginrule
- {\let\processword\drawmarginrule
- \processwords}
-
-\def\complexmarginrule[#1]%
- {\ifnum#1<\@@kalevel\relax \else
- \def\@@kadefaultwidth{#1}%
- \expandafter\simplemarginrule
- \fi}
-
-%D We need an auxiliary variable
-
-\def\@@kadefaultwidth{1}
-
-%D \macros
-%D {setupmarginrules}
-%D
-%D This macro definitions show us that we can pass an optional
-%D level, which is matched against the previous set one. The
-%D level can be set up with
-%D
-%D \showsetup{setupmarginrules}
-
-\def\setupmarginrules
- {\dodoubleargument\getparameters[\??ka]}
-
-%D \macros
-%D {startmarginrule}
-%D
-%D The second method collects text and reformats it afterwards,
-%D using the shapebox macros. We prevent local margin rules.
-%D
-%D \showsetup{startmarginrule}
-
-\definecomplexorsimple\startmarginrule
-
-\def\simplestartmarginrule
- {\bgroup
- \let\drawmarginrule\relax
- \let\stopmarginrule\dostopmarginrule
- \beginofshapebox}
-
-\def\complexstartmarginrule[#1]%
- {\bgroup
- \let\drawmarginrule\relax
- \ifnum#1<\@@kalevel\relax
- \let\stopmarginrule\egroup
- \else
- \def\@@kadefaultwidth{#1}%
- \let\stopmarginrule\dostopmarginrule
- \expandafter\beginofshapebox
- \fi}
-
-\def\dostopmarginrule
- {\endofshapebox
- \reshapebox
- {\hbox{\inleftmargin{\dodrawmarginrule}\box\shapebox}}%
- \flushshapebox
- \egroup}
-
-%D \startbuffer
-%D \setupmarginrules[level=5]
-%D
-%D \startmarginrule[1]
-%D First we set the level at~5. Next we typeset this first
-%D paragraph as a level~1 one. As expected no rule show up.
-%D \stopmarginrule
-%D
-%D \startmarginrule[5]
-%D The second paragraph is a level~5 one. As we can see here,
-%D the marginal rule gets a width according to its level.
-%D \stopmarginrule
-%D
-%D \startmarginrule[8]
-%D It will of course be no surprise that this third paragraph
-%D has a even thicker margin rule. This behavior can be
-%D overruled by specifying the width explictly.
-%D \stopmarginrule
-%D \stopbuffer
-%D
-%D In next example we show most features. Watch the rule
-%D thickness adapting itself to the level.
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-%D
-%D We just said:
-%D
-%D \typebuffer
-
-%D \macros
-%D {vl, hl}
-%D
-%D The command \type{\vl} draws a vertical rule \vl\ with strut
-%D dimensions, multiplied with the factor specified in the
-%D optional argument. The height and depth are clipped \vl[3]
-%D to the baselinedistance. Its horizontal counterpart
-%D \type{\hl} draws a horizontal rule \hl\ with a width of 1em,
-%D multiplied with the optional factor. The horizontal rule is
-%D drawn on top of the baseline.
-%D
-%D \showsetup{vl}
-%D \showsetup{hl}
-
-\def\complexvl[#1]%
- {\bgroup
- \!!dimena#1\strutht
- \!!dimenb#1\strutdp
- \setbox\scratchbox\hbox
- {\vrule
- \!!width \linewidth
- \!!height\!!dimena
- \!!depth \!!dimenb}%
- \dp\scratchbox\strutdp
- \ht\scratchbox\strutht
- \box\scratchbox
- \egroup}
-
-\def\complexhl[#1]%
- {\hbox
- {\vrule
- \!!width #1\s!em
- \!!height\linewidth
- \!!depth \zeropoint}}
-
-\definecomplexorsimple\vl \def\simplevl{\complexvl[1]}
-\definecomplexorsimple\hl \def\simplehl{\complexhl[1]}
-
-%D \macros
-%D {hairline, thinrule, thinrules, setupthinrules}
-%D
-%D Drawing thin lines can of course easily be accomplished by
-%D the \TEX\ primitives \type{\hrule} and \type{\vrule}. The
-%D next few macros however free us from some specifications.
-%D
-%D \startbuffer
-%D some text
-%D
-%D \hairline
-%D
-%D some more text
-%D
-%D \thinrule
-%D
-%D more and more text
-%D
-%D hi \thinrule\ there
-%D
-%D and then the final text
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D becomes
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-%D
-%D So we've got
-%D
-%D \showsetup{hairline}
-%D \showsetup{thinrule}
-%D
-%D Both can be set up with:
-%D
-%D \showsetup{setupthinrules}
-%D
-%D We also have
-%D
-%D \showsetup{thinrules}
-%D
-%D which looks like: \thinrules[n=2]
-
-\def\thinrule
- {\strut
- \bgroup
- \chardef\ruletype\plusone
- \processaction
- [\@@dlalternative]
- [ \v!a=>\chardef\ruletype0,% no line
- %\v!b=>\chardef\ruletype1,% height/depth
- \v!c=>\chardef\ruletype2,% topheight/botdepth
- % 11=>\chardef\ruletype1,% fallback for backgrounds
- 0=>\chardef\ruletype0,% compatible with backgrounds
- % 1=>\chardef\ruletype1,% compatible with backgrounds
- 2=>\chardef\ruletype2]% compatible with backgrounds
- \doifsomething\@@dlrulethickness
- {\linewidth\@@dlrulethickness}%
- \ifdim\linewidth=\zeropoint
- \chardef\ruletype\zerocount
- \else
- \doifnot\@@dlframe\v!on{\chardef\ruletype\zerocount}%
- \fi
- \ifnum\ruletype=\plusone
- \doif\@@dlheight\v!max{\let\@@dlheight\!!plusone}%
- \doif\@@dldepth \v!max{\let\@@dldepth \!!plusone}%
- \else
- \let\@@dlheight\!!plusone
- \let\@@dldepth\!!plusone
- \fi
- \freezedimensionwithunit\@@dlheight\strutht
- \freezedimensionwithunit\@@dldepth\strutdp
- \divide\linewidth \plustwo
- \doifelse\@@dlbackground\v!color
- {\startcolor[\@@dlbackgroundcolor]%
- \ifnum\ruletype=\plustwo % prevent overshoot due to rounding
- \leaders
- \hrule
- \!!height\dimexpr\@@dlheight-.5\linewidth\relax
- \!!depth \dimexpr\@@dldepth -.5\linewidth\relax
- \hfill
- \else
- \leaders
- \hrule
- \!!height\@@dlheight
- \!!depth \@@dldepth
- \hfill
- \fi
- \stopcolor
- \ifcase\ruletype
- % no rule
- \or
- \startcolor[\@@dlcolor]%
- \hfillneg
- \leaders\hrule\!!height\linewidth\!!depth\linewidth\hfill
- \stopcolor
- \or
- \startcolor[\@@dlcolor]%
- \hfillneg\leaders\hrule\!!height\dimexpr-\@@dldepth+\linewidth\relax\!!depth\@@dldepth\hfill
- \hfillneg\leaders\hrule\!!height\@@dlheight\!!depth\dimexpr-\@@dlheight+\linewidth\relax\hfill
- \stopcolor
- \fi}
- {\ifcase\ruletype \else
- \startcolor[\@@dlcolor]%
- \leaders\hrule\!!height\@@dlheight\!!depth\@@dldepth\hfill
- \stopcolor
- \fi}%
- \strut
- \carryoverpar\egroup}
-
-\def\hairline
- {\endgraf
- \thinrule
- \endgraf}
-
-\def\dosetupthinrules[#1]%
- {\getparameters[\??dl][#1]}
-
-\def\setupthinrules
- {\dosingleargument\dosetupthinrules}
-
-\def\dothinrules[#1]%
- {\bgroup
- \dosetupthinrules[#1]%
- \@@dlbefore
- \assignvalue\@@dlinterlinespace\@@dlinterlinespace{1.0}{1.5}{2.0}%
- \spacing\@@dlinterlinespace
- \dorecurse\@@dln
- {\ifnum\recurselevel=\@@dln \dothinrulesnobreak \else
- \ifnum\recurselevel=2 \dothinrulesnobreak \fi\fi
- \thinrule
- \ifnum\recurselevel<\@@dln\relax
- % test needed, else messed up whitespace
- \ifx\@@dlinbetween\empty
- \softbreak
- \else
- \endgraf
- \nowhitespace
- \@@dlinbetween
- \fi
- \fi}%
- \doifelsenothing\@@dlafter
- {\carryoverpar\egroup}
- {\@@dlafter\egroup}}
-
-\def\thinrules
- {\dosingleempty\dothinrules}
-
-%D A couple of examples are given below.
-%D
-%D \startbuffer
-%D \setupthinrules[n=3,inbetween=,color=gray]
-%D
-%D test test \thinrules\ test test \par
-%D test test \thinrules [color=green] test test \par
-%D test test \thinrules [height=max, depth=max] test test \par
-%D
-%D \setupthinrules[height=.9,depth=.9]
-%D
-%D test test \thinrules\ test test \par
-%D test test \thinrules [alternativevariant=b] test test \par
-%D test test \thinrules [alternativevariant=c] test test \par
-%D test test \thinrules [alternativevariant=c,inbetween=\vskip2ex] test test \par
-%D \stopbuffer
-%D
-%D \typebuffer {\getbuffer}
-%D
-%D There are a couple of alternative ways to visualize rules
-%D using backgrounds. At first sight these may look strange,
-%D but they make sense in educational settings. The
-%D alternatives are more or less compatible with the more
-%D advanced \METAPOST\ based implementation.
-%D
-%D \startbuffer[a]
-%D \setupthinrules
-%D [n=2,
-%D backgroundcolor=gray ,
-%D rulethickness=1pt,
-%D colorkleur=donkerblauw,
-%D after=\blank,
-%D before=\blank]
-%D \stopbuffer
-%D
-%D \typebuffer[a]
-%D
-%D \startbuffer[b]
-%D \thinrules[alternativevariant=a]
-%D \thinrules[alternativevariant=b]
-%D \thinrules[alternativevariant=c]
-%D \stopbuffer
-%D
-%D \typebuffer[b] \getbuffer[a,b]
-%D
-%D \startbuffer[b]
-%D \thinrules[alternativevariant=a,background=color]
-%D \thinrules[alternativevariant=b,background=color]
-%D \thinrules[alternativevariant=c,background=color]
-%D \stopbuffer
-%D
-%D \typebuffer[b] \getbuffer[a,b]
-%D
-%D \startbuffer[b]
-%D \thinrules[alternativevariant=a,height=.8,depth=.8,background=color]
-%D \thinrules[alternativevariant=b,height=.8,depth=.8,background=color]
-%D \thinrules[alternativevariant=c,height=.8,depth=.8,background=color]
-%D \stopbuffer
-%D
-%D \typebuffer[b] \getbuffer[a,b]
-
-%D \macros
-%D {optimizethinrules}
-%D
-%D By saying \type {\thinrulestrue} or \type {-false}, we
-%D can influence the way dangling lines are handled.
-
-\newif\ifoptimizethinrules \optimizethinrulestrue
-
-\def\dothinrulesnobreak
- {\ifoptimizethinrules\penalty500\fi}
-
-%D \macros
-%D {startframedtext, setupframedtexts, defineframedtext}
-%D
-%D The general framing command we discussed previously, is not
-%D entirely suited for what we call framed texts, as for
-%D instance used in intermezzo's. The next examples show what
-%D we have in mind.
-%D
-%D \startbuffer[framed-0]
-%D \setupframedtexts
-%D [frame=off,
-%D width=\hsize,
-%D background=screen]
-%D
-%D \startframedtext
-%D By default the framed text is centered \dots
-%D \stopframedtext
-%D
-%D \startframedtext[right]
-%D \dots\ but we can also align left, middle and right.
-%D \stopframedtext
-%D \stopbuffer
-%D
-%D \startbuffer[framed-1]
-%D \defineframedtext
-%D [Example]
-%D [width=6cm,
-%D height=5cm]
-%D
-%D \startExample
-%D \typebuffer[framed-1]
-%D \stopExample
-%D \stopbuffer
-%D
-%D \startbuffer[framed-2]
-%D \defineframedtext
-%D [Example]
-%D [width=6cm]
-%D
-%D \startExample
-%D \typebuffer[framed-2]
-%D \stopExample
-%D \stopbuffer
-%D
-%D \startbuffer[framed-3]
-%D \defineframedtext
-%D [Example]
-%D [height=5cm]
-%D
-%D \startExample
-%D \typebuffer[framed-3]
-%D \stopExample
-%D \stopbuffer
-%D
-%D \startbuffer[framed-4]
-%D \defineframedtext
-%D [Example]
-%D [width=fit,height=broad]
-%D
-%D \Example{a very exciting example}
-%D \stopbuffer
-%D
-%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-0] \egroup
-%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-1] \egroup
-%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-2] \egroup
-%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-3] \egroup
-%D \bgroup \setuptyping[margin=0pt] \getbuffer[framed-4] \egroup
-%D
-%D Here we can see that we have a predefined framed text class
-%D as well as the tools for defining our own. So we have:
-%D
-%D \showsetup{setupframedtexts}
-%D
-%D as well as the definition command:
-%D
-%D \showsetup{defineframedtext}
-%D
-%D that generates two commands:
-%D
-%D \showsetup{start<>}
-%D \showsetup{<>}
-%D
-%D The next definition shows the defaults.
-
-\def\dodefineframedtext[#1][#2]%
- {\presetlocalframed[\??kd#1]%
- \getparameters[\??kd#1]
- [\c!width=0.75\hsize,
- \c!height=\v!fit,
- \c!align=\v!yes,
- \c!top=,
- \c!bottom=\vfill,
- \c!offset=1em,
- \c!bodyfont=,
- \c!style=,
- \c!color=,
- \c!left=,
- \c!right=\hfill,
- \c!before=\blank,
- \c!after=\blank,
- \c!inner=,
- \c!frame=\v!on,
- \c!topframe=,
- \c!bottomframe=,
- \c!leftframe=,
- \c!rightframe=,
- \c!radius=.5\bodyfontsize,
- \c!corner=\v!rectangular,
- \c!foregroundcolor=,
- \c!foregroundstyle=,
- \c!background=,
- \c!backgroundcolor=,
- \c!backgroundscreen=\@@rsscreen,
- \c!linecorrection=\v!on,
- \c!depthcorrection=\v!on,
- \c!margin=\v!standard,
- \c!orientation=,
- \c!indenting=,
- #2]%
- \setvalue{\e!start#1}{\dostartframedtext[#1]}%
- \setvalue{\e!stop #1}{\dostopframedtext }%
- \setvalue {#1}{\doframedtext [#1]}}
-
-\def\defineframedtext
- {\dodoubleempty\dodefineframedtext}
-
-%D We define the general (and original) case by just saying:
-
-\defineframedtext[\v!framedtext]
-
-%D We need several steps before the actual job is done,
-%D because we have to handle an optional identifier (and
-%D because these commands evolved out of a single case).
-
-\def\framedtextparameter#1#2%
- {\csname\??kd#1#2\endcsname}
-
-\def\dosetupframedtexts[#1][#2]%
- {\ifsecondargument
- \def\docommand##1{\getparameters[\??kd##1][#2]}%
- \processcommacommand[#1]\docommand % new, #1 may be macro
- \else
- \getparameters[\??kd\v!framedtext][#1]%
- \fi}
-
-\def\setupframedtexts
- {\dodoubleempty\dosetupframedtexts}
-
-\def\dostartframedtext
- {\bgroup\dotripleempty\dodostartframedtext}
-
-\def\dodostartframedtext[#1][#2][#3]%
- {\doifassignmentelse{#2}
- {\dododostartframedtext[#1][][#2]}
- {\dododostartframedtext[#1][#2][#3]}}
-
-\setfalse\framedtextlocationnone
-
-\def\dododostartframedtext[#1][#2][#3]% #3 only passed to framed, not to framedtext
- {\doifsomething{#2}{\setvalue{\??kd#1\c!location}{#2}}% does not listen to #3
- \setfalse\framedtextlocationnone
- \processaction % \v!low en \v!depth are already taken !
- [\framedtextparameter{#1}\c!location]
- [ \v!left=>\letvalue{\??kd#1\c!left }\relax
- \letvalue{\??kd#1\c!right}\hfill,
- \v!right=>\letvalue{\??kd#1\c!left }\hfill
- \letvalue{\??kd#1\c!right}\relax,
- \v!middle=>\letvalue{\??kd#1\c!left }\hfill
- \letvalue{\??kd#1\c!right}\hfill,
- \v!none=>\letvalue{\??kd#1\c!left }\relax % new
- \letvalue{\??kd#1\c!right}\relax % new
- \settrue\framedtextlocationnone]%
- \letvalue{\??kd#1\c!location}\empty
- % removed 06/2001
- % \forgetparindent
- % added 06/2001 [see demo-bbv]
- \localhsize\hsize \checkframedtext
- % so far
- \setbox\framebox\vbox
- \startboxedcontent
- \hsize\localhsize
- % \insidefloattrue % ? better
- \expanded{\switchtobodyfont[\framedtextparameter{#1}\c!bodyfont]}%
- \startcolor[\framedtextparameter{#1}\c!color]%
- \localframed[\??kd#1][\c!strut=\v!no,#3]% todo: use delayedstrut
- \bgroup
- \let\\=\endgraf
- \framedtextparameter{#1}\c!inner % oud spul
- \doifvalue{\??kd#1\c!depthcorrection}\v!on % new, inside box
- {\bgroup
- \verticalstrut
- % we need \nowhitespace in case of setups setting whitespace
- % nb, not safe, text vs \vbox as next
- \vskip-\struttotal
- \nowhitespace % na vskip ! new 20/05/2004, fails with next content being box (\scale{..})
- }%
- \doinhibitblank % \blank[\v!disable]% plaatst signal
-\setupindenting[\framedtextparameter{#1}\c!indenting]%
- \doconvertfont{\framedtextparameter{#1}\c!style}\empty
- \def\dostopframedtext{\dodostopframedtext{#1}{#2}}}
-
-%D The \type {none} option is handy for nested usage, as
-%D in the presentation styles, where we don't want
-%D interference.
-
-\def\dodostopframedtext#1#2% % no \baselinecorrection, see faq docs
- {\endgraf
- \removelastskip
- \doifvalue{\??kd#1\c!depthcorrection}\v!on % local and global
- {\forgetall
- \vskip-\struttotal
- \verticalstrut
- \egroup
- \forgetall
- \vskip-\lineheight
- % will be an option, not default
- % \setbaselinecorrections
- % \donegbotbaselinecorrection
- \verticalstrut}
- \stopboxedcontent
- \stopcolor
- \ifconditional\framedtextlocationnone
- \egroup
- \box\framebox
- \else\ifinsidefloat
- \egroup
- \box\framebox
- \else
- \egroup
- \doplacement[\??kd#1][\c!depthcorrection=\v!off]{\box\framebox}%
- \fi\fi
- \egroup}
-
-%D Placement can be ignored:
-%D
-%D \starttyping
-%D \hbox to \hsize \bgroup
-%D \startframedtext[none][width=.5\textwidth] \input tufte \stopframedtext
-%D \startframedtext[none][width=.5\textwidth] \input zapf \stopframedtext
-%D \egroup
-%D
-%D \hbox to \hsize \bgroup
-%D \setupframedtexts[location=none]%
-%D \startframedtext[width=.5\textwidth] \input zapf \stopframedtext
-%D \startframedtext[width=.5\textwidth] \input tufte \stopframedtext
-%D \egroup
-%D \stoptyping
-
-%D The simple brace (or group) delimited case is typeset
-%D slightly different and is not aligned.
-
-\def\doframedtext
- {\bgroup\dodoubleempty\dodoframedtext}
-
-\def\dodoframedtext[#1][#2]% beware!
- {\expanded{\switchtobodyfont[\getvalue{\??kd#1\c!bodyfont}]}%
- \localframed[\??kd#1][\c!strut=\v!no,#2]%
- \bgroup
- \blank[\v!disable]%
- \let\\=\endgraf
- \getvalue{\??kd#1\c!inner}% % kleur naar outer level
- \dostartattributes{\??kd#1}\c!style\c!color\empty
- \bgroup
- \aftergroup\docloseframedtext
- \let\next=}
-
-\def\docloseframedtext
- {\removelastskip
- \dostopattributes
- \egroup
- \egroup}
-
-%D \macros
-%D {defineframed}
-%D
-%D One can also define simple framed texts, using:
-%D
-%D \showsetup{defineframed}
-
-\def\defineframed
- {\dodoubleempty\dodefineframed}
-
-\def\dodefineframed[#1][#2]%
- {\iffirstargument
- \setvalue{#1}{\dodoubleempty\doframed[#2]}%
- \fi}
-
-\def\doframed[#1][#2]%
- {\framed[#1,#2]}
-
-%D \macros
-%D {textrule, starttextrule, setuptextrules}
-%D
-%D Putting rules before and after a paragraph is very space
-%D sensitive, but the next command handles that quite well. It
-%D comes in two disguises:
-%D
-%D \startbuffer
-%D \textrule[top]{fragments}
-%D \input reich
-%D \textrule
-%D \stopbuffer
-%D
-%D \bgroup \typebuffer \getbuffer \egroup
-%D
-%D \startbuffer
-%D \setuptextrules
-%D [width=90pt,distance=12pt,rulecolor=blue,
-%D bodyfont=small,style=\sc,color=red]
-%D
-%D \starttextrule{Ship Building Tools}
-%D \nl \setuptolerance[tolerant] \input materie
-%D \stoptextrule
-%D \stopbuffer
-%D
-%D \bgroup \typebuffer \getbuffer \egroup
-%D
-%D \startbuffer
-%D \setuptextrules
-%D [location=inmargin,
-%D bodyfont=small,style=slantedbold]
-%D
-%D \starttextrule{wonderful}
-%D \input tufte
-%D \stoptextrule
-%D \stopbuffer
-%D
-%D \bgroup \typebuffer \getbuffer \egroup
-%D
-%D The formal definition of these commands is:
-%D
-%D \showsetup{textrule}
-%D \showsetup{starttextrule}
-%D \showsetup{setuptextrules}
-%D
-%D The implementation looks a bit complicated due to the
-%D optional arguments.
-
-\def\setuptextrules
- {\dodoubleargument\getparameters[\??tl]}
-
-\def\complextextrule[#1]% if needed we can make it installable
- {\let\next\dobottomtextrule
- \processaction
- [#1]
- [ \v!top=>\let\next\dotoptextrule,
- \v!middle=>\let\next\domiddletextrule,
- \v!bottom=>\let\next\dobottomtextrule]%
- \dosinglegroupempty\next}
-
-\definecomplexorsimple\textrule
-
-\def\simpletextrule
- {\dosinglegroupempty\dounknowntextrule}
-
-\def\docomplextextrule#1%
- {\bgroup
- \advance\hsize\dimexpr-\rightskip-\leftskip\relax
- \setbox\scratchbox\hbox to \hsize
- {\dimen4\dimexpr .5ex+.5\linewidth\relax
- \dimen6\dimexpr-.5ex+.5\linewidth\relax
- \doifnothing{#1}\firstargumentfalse
- \iffirstargument
- \doifelse\@@tllocation\v!inmargin
- {\llap{\doattributes\??tl\c!style\c!color{#1}\hskip\leftmargindistance}}
- {\color[\@@tlrulecolor]
- {\vrule\!!height\dimen4\!!depth\dimen6\!!width\@@tlwidth}%
- \hbox spread 2\dimexpr\@@tldistance\relax
- {\hss\doattributes\??tl\c!style\c!color{\strut#1}\hss}}%
- \fi
- \color[\@@tlrulecolor]
- {\leaders\hrule\!!height\dimen4\!!depth\dimen6\hfill}}%
- \ht\scratchbox\strutht
- \dp\scratchbox\strutdp
- \noindent\box\scratchbox
-%\nobreak\verticalstrut\kern-\struttotal
-% evt \witruimte
- \egroup}
-
-\def\dotoptextrule#1%
- {\page[\v!preference] % interferes
- %\whitespace % no
- \@@tlbefore
- \docomplextextrule{#1}%
-% todo, option: \doifnothing{#1}{\ruledvskip-.5ex}
- \nowhitespace
- \@@tlinbetween
- \endgraf}
-
-\def\dodobottomtextrule#1#2%
- {\ifhmode
- \endgraf
- \fi
- \dimen0\strutdp
- \ifdim\prevdepth>\strutdp\else % was <\strutdp
- \ifdim\prevdepth>\zeropoint
- \advance\dimen0 -\prevdepth
- \fi
- \fi
- \advance\dimen0 .5ex
- \vskip\dimen0
-% ==
-% \vskip\dimexpr \strutdp + .5ex
-% \ifdim\prevdepth>\strutdp\else\ifdim\prevdepth>\zeropoint-\prevdepth\fi\fi\relax
-%
- \@@tlinbetween
- \doifelsenothing{#2}
- {\bgroup
- \advance\hsize\dimexpr-\rightskip-\leftskip\relax
- \nointerlineskip
- \moveleft-\leftskip\vbox
- {\color[\@@tlrulecolor]
- {\hrule\!!depth\linewidth\!!height\zeropoint\!!width\hsize}}%
- \egroup}
- {\docomplextextrule{#2}}%
- \ifvmode\prevdepth\zeropoint\fi
- #1%
- \page[\v!preference]}
-
-\def\dobottomtextrule
- {\dodobottomtextrule\@@tlafter}
-
-\def\domiddletextrule
- {\dodobottomtextrule\@@tlinbetween}
-
-\def\dounknowntextrule
- {\iffirstargument
- \@EA\dotoptextrule
- \else
- \@EA\dobottomtextrule\@EA\empty
- \fi}
-
-%D The grouped commands also supports bodyfont switching:
-
-\def\starttextrule#1%
- {\bgroup
- \def\dounknowntextrule{\domiddletextrule}
- \dotoptextrule{#1}
- \bgroup
- \doifsomething\@@tlbodyfont{\switchtobodyfont[\@@tlbodyfont]}}
-
-\def\stoptextrule
- {\par
- \egroup
- \dobottomtextrule\empty
- \egroup}
-
-%D \macros
-%D {fillinrules, setupfillinrules}
-%D
-%D The next few commands do not really deserve a place in a
-%D core module, because they deal with specific typography.
-%D Nevertheless I decided to make them part of the core,
-%D because they permit us to make questionaires. Let's start
-%D with some examples.
-%D
-%D \fillinrules[n=2,width=fit]{first}
-%D \fillinrules[n=2,width=broad]{first}
-%D \fillinrules[n=2,width=3cm]{first}
-%D \fillinrules[n=2,width=3cm,distance=.5em,separator=:]{first}
-%D \fillinrules[n=2]{first}{last}
-%D \fillintext{first}{last} \input reich \par
-%D
-%D The main command is \type{\fillinrules}. This command takes
-%D one and an optional second argument and sets a paragraph with
-%D empty visualized lines.
-%D
-%D \showsetup{fillinrules}
-%D \showsetup{setupfillinrules}
-
-\def\setupfillinrules
- {\dodoubleargument\getparameters[\??il]}
-
-\definecomplexorsimpleempty\fillinrules
-
-\def\complexfillinrules[#1]%
- {\def\docomplexfillinrules##1##2%
- {\dodocomplexfillinrules[#1]{##1}{##2}{\thinrules
- [\c!n=\@@iln,\c!interlinespace=\@@ilinterlinespace,\c!before=,\c!after=]}}%
- \dodoublegroupempty\docomplexfillinrules}
-
-\def\dodocomplexfillinrules[#1]#2#3#4%
- {\endgraf
- \@@ilbefore
- \begingroup
- \setupfillinrules[#1]%
- \noindent
- \doifsomething{#2}
- {\doifelse\@@ilwidth\v!fit
- {\let\@@ildistance\!!zeropoint
- \hbox}
- {\doifelse\@@ilwidth\v!broad
- {\hbox}
- {\hbox to \@@ilwidth}}%
- \bgroup
- \doattributes\??il\c!style\c!color{\strut#2\hfill\@@ilseparator}%
- \hskip\@@ildistance
- \egroup}%
- %\hangindent=\wd0\relax % tzt hang=yes,n
- %\parindent=\hangindent
- %\box0\relax
- \setupwhitespace[\v!big]%
- \ignorespaces
- #4%
- \doifsomething{#3}
- {\kern\@@ildistance
- \doattributes\??il\c!style\c!color{#3\strut}}%
- \endgroup
- \endgraf
- \@@ilafter}
-
-%D \macros
-%D {fillintext}
-%D
-%D To provide compatible layouts when texts and lines are
-%D mixed, one can typeset a paragraph by using the command
-%D \type{\fillintext}.
-%D
-%D \showsetup{fillintext}
-
-\definecomplexorsimpleempty\fillintext
-
-\def\complexfillintext[#1]% rather rough, using an \unhbox is suboptimal
- {\def\docomplexfillintext##1##2%
- {\dowithnextbox
- {\dodocomplexfillinrules[#1]{##1}{\hfill##2}{\unhbox\nextbox\unskip}}%
- \hbox\bgroup\let\par\egroup\ignorespaces}%
- \dodoublegroupempty\docomplexfillintext}
-
-%D \macros
-%D {fillinline, setupfillinlines}
-%D
-%D Another member of the family takes care of putting a (often
-%D small) rule after a piece of text, like
-%D
-%D \startbuffer
-%D \fillinline \input reich \par
-%D \fillinline[margin=0cm] \input reich \par
-%D \stopbuffer
-%D
-%D \startvoorbeeld
-%D \getbuffer
-%D \stopvoorbeeld
-%D
-%D which was typeset by saying:
-%D
-%D \typebuffer
-%D
-%D The two commands that take care of this are:
-%D
-%D \showsetup{fillinline}
-%D \showsetup{setupfillinlines}
-
-\def\setupfillinlines
- {\dodoubleargument\getparameters[\??iv]}
-
-\definecomplexorsimpleempty\fillinline
-
-\def\complexfillinline[#1]%
- {%\endgraf % interferes with \definedescription cum suis
- \@@ivbefore
- \begingroup
- \setupfillinlines[#1]%
- \advance\rightskip \@@ivmargin
- \parfillskip\zeropoint
- \def\par % very dangerous
- {\let\par\endgraf % -)
- \ifhmode\unskip\hfill\fi
- \scratchdimen\dimexpr\@@ivwidth-\@@ivdistance\relax
- \ifdim\scratchdimen>\@@ivmargin\else\expandafter\rlap\fi
- {\kern\@@ivdistance
- \vrule
- \!!width \scratchdimen
- \!!height.5\linewidth
- \!!depth .5\linewidth}%
- \endgraf % !
- \endgroup
- \endgraf % !
- \@@ilafter}}
-
-%D \stopdocumentation
-%D \bgroup
-%D
-%D \setupframedtexts
-%D [setuptext]
-%D [background=color,backgroundcolor=white]
-%D
-%D \startbuffer
-%D \setupbackground
-%D [backgroundoffset=4pt,
-%D background=screen,
-%D frame=on,
-%D framecolor=red,
-%D leftoffset=2pt]
-%D \stopbuffer
-%D
-%D \getbuffer
-%D
-%D \startbackground
-%D
-%D \macros
-%D {setupbackground,startbackground,background}
-%D
-%D The section deals with backgrounds in the running text. This
-%D means that texts is to be collected and split over pages. To
-%D show what can be done, we provide this part of the
-%D documentation with some gray background and a red frame.
-%D Both the background and frame can have all characteristics
-%D of \type{\framed}. This time we used the setting:
-%D
-%D \typebuffer
-%D
-%D The implementation is not that sophisticated, but suffices.
-%D The main problem with this kind of functionality is to get
-%D the spacing all right.
-
-%D Specifying the background is more or less the same as
-%D specifying a framed box.
-%D
-%D \showsetup{setupbackground}
-
-\presetlocalframed[\??ag]
-
-\def\dosetupbackground[#1]%
- {\getparameters[\??ag][#1]%
- \doifelse\@@agstate\v!start
- {\let\startbackground\dostartbackground
- \let\stopbackground \dostopbackground
- \let\background \dobackground}
- {\let\startbackground\relax
- \let\stopbackground \relax
- \let\background \relax}}
-
-\def\setupbackground
- {\dosingleargument\dosetupbackground}
-
-%D Actually typesetting the background is implemented rather
-%D straightforward. We need to handle some spacing as well as
-%D the (often) a bit smaller horizontal size.
-%D
-%D \showsetup{startbackground}
-%D
-%D Although we could have used a scratch one, we first
-%D declare a boolean.
-
-% 0=no-split, 1=no-split+indent, 2=split, 3=split+indent
-
-\chardef\backgroundsplitmode\plusthree
-
-%D The \type{\vbox to \lineheight{}\vskip\zeropoint}
-%D construction gives the first real line a decent height by
-%D adding a dummy line.
-
-\def\dostartbackground
- {\endgraf
- \bgroup
- \setbox0\vbox\bgroup
- \vbox to \lineheight{}\vskip\zeropoint
- \blank[\v!disable]
- % \advance\hsize -\@@agleftoffset
- % \advance\hsize -\@@agrightoffset
- \leftskip \@@agleftoffset % new **
- \rightskip\@@agrightoffset} % new **
-
-%D This dummy line is removed by \type{\setbox2=\vsplit0 to
-%D \lineheight}. That way \type{\topskip} takes care of the
-%D lineheight. I'll probably forget to apply this trick
-%D elsewhere.
-
-\def\dostopbackground % improved version (i hope)
- {\endgraf
- \removelastskip
- \egroup
- \dimen2\leftskip % new **
- \forgetall
- \ifinsidefloat
- \chardef\backgroundsplitmode\zerocount
- \fi
- \ifcase\backgroundsplitmode
- \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
- \or
- \hskip\dimen2
- \localframed[\??ag][\c!offset=\v!overlay]{\box0}%
- \else
- \splitmaxdepth\boxmaxdepth
- \splittopskip\topskip
- \setbox2\vsplit0 to \lineheight % get rid of fake line
- \loop
- \ifdim\pagetotal=\zeropoint % empty page
- \scratchdimen\textheight
- \chardef\backgroundsplit\plusone % split to max height
- \else
- \setbox\scratchbox\vbox{\@@agbefore}%
- \scratchdimen\dimexpr\pagegoal-\ht\scratchbox-\pagetotal\relax
- \chardef\backgroundsplit\plustwo % split to partial height
- \fi
- \advance\scratchdimen\dimexpr-\@@agtopoffset-\@@agbottomoffset\relax
- \ifdim\scratchdimen>2\lineheight\relax % reasonable, will be configurable
- \ifdim\ht0>\scratchdimen % larger than page
- \setbox2\vsplit0 to \scratchdimen
- \else
- \setbox2\box0
- \chardef\backgroundsplit\zerocount % no split
- \fi
- \setbox2\vbox \ifcase\backgroundsplit\or to \textheight \fi % max split
- {\vskip\@@agtopoffset
- \popsplitproperties
- \unvcopy2
- \prevdepth\dp2
- \obeydepth
- \vskip\@@agbottomoffset
- \vfill}
- \@@agbefore
- \ifcase\backgroundsplit\or\or % partial split
- \ifdim\pagegoal<\maxdimen
- \pagegoal=1.2\pagegoal % be a bit more tolerant
- \fi
- \fi
- \startlinecorrection
- %\localframed[\??ag][\c!offset=\v!overlay]{\hskip\@@agleftoffset\box2\hskip\@@agrightoffset}%
- \ifnum\backgroundsplitmode=\plusthree \hskip\dimen2 \fi %
- \localframed[\??ag][\c!offset=\v!overlay]{\box2}% new **
- \stoplinecorrection
- \ifcase\backgroundsplit % no split
- \@@agafter
- \else % some split
- \vfill\eject % geen \page !
- \fi
- \else
- \page
- \fi
- \ifdim\ht0>\zeropoint \repeat
- \fi
- \egroup
- \endgraf}
-
-%D As a bonus we also have a short command, that is of not
-%D much use, but kept there for historic reasons.
-%D
-%D \showsetup{background}
-
-\def\dobackground
- {\bgroup
- \dowithnextbox
- {\localframed[\??ag][\c!offset=\v!overlay]{\flushnextbox}\egroup}
- \vbox}
-
-%D \stopdocumentation
-%D \stopbackground
-%D \egroup
-
-%D New, for the moment private; let's see when GB finds out
-%D about this one and its obscure usage. It's used in:
-%D
-%D \startbuffer
-%D \defineframedtext
-%D [tabulateframe]
-%D [offset=overlay,
-%D backgroundoffset=3pt,
-%D background=color,
-%D backgroundcolor=green]
-%D
-%D \setuptabulate
-%D [tabulate]
-%D [frame=tabulateframe]
-%D
-%D \setuptables
-%D [frame=tabulateframe]
-%D
-%D \input tufte
-%D
-%D \starttabulate[|l|l|]
-%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
-%D \NC test \NC test \NC \NR \NC test \NC test \NC \NR
-%D \stoptabulate
-%D
-%D \input tufte
-%D
-%D \starttable[|l|l|]
-%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
-%D \NC test \NC test \NC \AR \NC test \NC test \NC \AR
-%D \stoptable
-%D \stopbuffer
-%D
-%D \typebuffer
-
-\def\defineframedcontent
- {\dodoubleempty\dodefineframedcontent}
-
-\def\dodefineframedcontent[#1][#2]%
- {\presetlocalframed[\??fc#1]%
- \getparameters[\??fc#1]
- [\c!leftoffset=\zeropoint,
- \c!rightoffset=\getvalue{\??fc#1\c!leftoffset},
- \c!topoffset=\zeropoint,
- \c!bottomoffset=\getvalue{\??fc#1\c!topoffset},
- \c!strut=\v!no,
- \c!offset=\v!overlay,
- \c!linecorrection=\v!no,
- \c!left=,
- \c!right=,
- #2]}
-
-\let\setuplocalframed\getparameters
-
-\def\setupframedcontent
- {\dodoubleempty\dosetupframedcontent}
-
-\def\dosetupframedcontent[#1][#2]%
- {\def\docommand##1{\getparameters[\??fc##1][#2]}%
- \processcommacommand[#1]\docommand}
-
-\def\startframedcontent[#1]%
- {\bgroup
- \let\stopframedcontent\egroup
- \doifnot{#1}\v!off
- {\doifdefined{\??fc#1\c!frame}
- {\def\stopframedcontent{\dostopframedcontent{#1}}%
- \dostartframedcontent{#1}}}}
-
-\def\dostartframedcontent#1%
- {\setbox\framebox\hbox\bgroup
- \setlocalhsize
- \hsize\localhsize
- \advance\hsize\dimexpr-\getvalue{\??fc#1\c!leftoffset}-\getvalue{\??fc#1\c!rightoffset} \relax
- \advance\vsize\dimexpr-\getvalue{\??fc#1\c!topoffset} -\getvalue{\??fc#1\c!bottomoffset}\relax
- \hskip\getvalue{\??fc#1\c!leftoffset}%
- \vbox\bgroup
- \vskip\getvalue{\??fc#1\c!topoffset}%
- \vbox\bgroup
- \forgetall
- \blank[\v!disable]}
-
-\def\dostopframedcontent#1%
- {\removelastskip
- \egroup
- \vskip\getvalue{\??fc#1\c!bottomoffset}%
- \egroup
- \hskip\getvalue{\??fc#1\c!rightoffset}%
- \egroup
- \doifvalue{\??fc#1\c!width}\v!fit
- {\letvalue{\??fc#1\c!width}\v!fixed}% no shapebox
- \ifinsidefloat
- \donefalse
- \else
- \doifelsevalue{\??fc#1\c!linecorrection}\v!yes\donetrue\donefalse
- \fi
- % plaats ?
- \ifdone\startlinecorrection\fi
- \getvalue{\??fc#1\c!left}% new
- \localframed[\??fc#1]{\box\framebox}%
- \getvalue{\??fc#1\c!right}% new
- \ifdone\stoplinecorrection\fi
- \egroup}
-
-%D \macros
-%D {backgroundline}
-%D
-%D For the moment an undocumented feature, but a cancidate
-%D for going public.
-
-\def\backgroundline[#1]%
- %{\doifsomething{#1}{\dobackgroundline{#1}}\hbox}
- {\doifcolorelse{#1}{\dobackgroundline{#1}\hbox}\hbox}
-
-% \def\backgroundline[#1]%
-% {\doifcolor{#1}{\dobackgroundline{#1}}\hbox}
-
-\def\dobackgroundline#1%
- {\dowithnextbox
- {\hbox
- {\localcolortrue
- \startcolor[#1]%
- \vrule
- \!!width \nextboxwd
- \!!height\nextboxht
- \!!depth \nextboxdp
- \stopcolor
- \hskip-\nextboxwd
- \flushnextbox}}}
-
-%D \macros
-%D {encircled}
-%D
-%D Some not so robust left||overs (borrowed from Knuth,
-%D \TEX Book\ page 356):
-
-\def\encircled#1%
- {{\ooalign{\hfil\raise0.07ex\hbox{{\tx#1}}\hfil\crcr\mathhexbox20D}}}
-
-\let\omcirkeld\encircled
-
-\setuplinewidth
- [\v!medium]
-
-\setupframed
- [\c!width=\v!fit,
- \c!height=\v!broad,
- \c!lines=,
- \c!offset=0.25ex, % \defaultframeoffset
- \c!empty=\v!no,
- \c!frame=\v!on,
- \c!topframe=,
- \c!bottomframe=,
- \c!leftframe=,
- \c!rightframe=,
- \c!radius=.5\bodyfontsize,
- \c!rulethickness=\linewidth,
- \c!corner=\v!rectangular,
- \c!depth=\!!zeropoint,
- \c!foregroundcolor=,
- \c!foregroundstyle=,
- \c!background=,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=,
- \c!backgroundoffset=\!!zeropoint,
- \c!framecolor=,
- \c!frameoffset=\!!zeropoint,
- \c!backgroundcorner=\framedparameter\c!corner,
- \c!backgroundradius=\framedparameter\c!radius,
- \c!backgrounddepth=\framedparameter\c!depth,
- \c!framecorner=\framedparameter\c!corner,
- \c!frameradius=\framedparameter\c!radius,
- \c!framedepth=\framedparameter\c!depth,
- \c!component=,
- \c!align=,
- \c!bottom=\vss,
- \c!top=,
- \c!strut=\v!yes,
- \c!autostrut=\v!yes,
- \c!location=\v!normal,
- \c!orientation=,
- \c!autowidth=\v!yes,
- \c!setups=]
-
-\setupscreens
- [%\c!factor=1.0, % obsolete
- %\c!method=\v!external, % obsolete
- \c!screen=0.95]
-
-\setupblackrules
- [\c!n=3,
- \c!width=1em,
- \c!height=1ex,
- \c!depth=\!!zeropoint,
- \c!alternative=\c!a,
- \c!distance=.25ex,
- \c!color=]
-
-\setupmarginrules
- [\c!level=0,
- \c!rulethickness=\@@kadefaultwidth\linewidth]
-
-\setupthinrules
- [\c!interlinespace=\v!small,
- \c!n=3,
- \c!before=,
- \c!inbetween={\blank[\v!white]},
- \c!after=,
- \c!color=,
- \c!height=.5\linewidth,
- \c!depth=.5\linewidth,
- \c!frame=\v!on, % compatible with textbackgrounds
- \c!alternative=\v!b,
- \c!backgroundcolor=,
- \c!background=,
- \c!rulethickness=]
-
-\setuptextrules
- [\c!location=\v!left,
- \c!before=\blank,
- \c!after=\blank,
- \c!inbetween=,
- \c!width=2em,
- \c!style=\v!bold,
- \c!color=,
- \c!rulecolor=,
- \c!bodyfont=,
- \c!distance=.5em]
-
-\setupfillinrules
- [\c!width=\v!broad,
- \c!distance=1em,
- \c!before=\blank,
- \c!after=\blank,
- \c!n=1,
- \c!interlinespace=\v!small,
- \c!separator=,
- \c!style=\v!normal,
- \c!color=]
-
-\setupfillinlines
- [\c!width=3cm,
- \c!margin=\@@ivwidth,
- \c!distance=1em,
- \c!before=\blank,
- \c!after=\blank]
-
-\setupbackground
- [\c!leftoffset=.5\bodyfontsize,
- \c!rightoffset=\@@agleftoffset,
- \c!topoffset=\!!zeropoint,
- \c!bottomoffset=\@@agtopoffset,
- \c!state=\v!start,
- \c!radius=.5\bodyfontsize,
- \c!corner=\v!rectangular,
- \c!frame=\v!off,
- \c!color=,
- \c!depth=\!!zeropoint,
- \c!background=\v!screen,
- \c!backgroundcolor=\@@agcolor,
- \c!screen=\@@rsscreen,
- \c!before=,
- \c!after=]
-
-\protect \endinput
diff --git a/tex/context/base/core-sec.mkii b/tex/context/base/core-sec.mkii
deleted file mode 100644
index 960de366f..000000000
--- a/tex/context/base/core-sec.mkii
+++ /dev/null
@@ -1,2620 +0,0 @@
-%D \module
-%D [ file=core-sec,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Sectioning,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% start-stop per section en dan combineren met sectieblok; in dat geval
-% eenvoudiger per-* acties
-
-% nummeren per sectieblok implementeren
-
-% this module needs a clean up, currently some manipulations
-% take place multiple times; also, some clever recursive level
-% thing makes more sense
-
-% in manual (zie prikkels) : tussen=\blanko is enige hook om
-% met kop-in-hoofd een spatiering af te dwingen
-
-\writestatus{loading}{Context Core Macros / Sectioning}
-
-\startmessages dutch library: structures
- title: structuur
- 1: begin van sectieblok --
- 2: eind van sectieblok --
-\stopmessages
-
-\startmessages english library: structures
- title: structure
- 1: begin of sectionblock --
- 2: end of sectionblock --
-\stopmessages
-
-\startmessages german library: structures
- title: struktur
- 1: Begin des Abschnittsblocks --
- 2: Ende des Abschnittsblocks --
-\stopmessages
-
-\startmessages czech library: structures
- title: struktury
- 1: zacatek oddilu (sekce) --
- 2: konec oddilu (sekce) --
-\stopmessages
-
-\startmessages italian library: structures
- title: struttura
- 1: inizio del blocco (sezione) --
- 2: fine del blocco (sezione) --
-\stopmessages
-
-\startmessages norwegian library: structures
- title: struktur
- 1: starten av blokk -- (seksjon)
- 2: slutten av blokk -- (seksjon)
-\stopmessages
-
-\startmessages romanian library: structures
- title: structuri
- 1: inceput de bloc sectiune --
- 2: sfarsit de bloc sectiune --
-\stopmessages
-
-\startmessages french library: structures
- title: structure
- 1: début de blocsection --
- 2: fin de blocsection --
-\stopmessages
-
-\unprotect
-
-% new and to be tested
-
-\unexpanded\def\separatorlist#1%
- {\ifx\sepnumber\undefined\def\sepnumber{0}\fi
- \increment\sepnumber
- \getfromcommacommand[#1][\sepnumber]%
- \ifx\commalistelement\empty
- \getcommalistsize[#1]%
- \def\sepnumber{\number\commalistsize}%
- \getfromcommacommand[#1][\sepnumber]%
- \fi
- \commalistelement}
-
-% \setuphead[section] [separator=\separatorlist{?,!,*}]
-% \setuphead[subsection][separator=\separatorlist{??,!!,**}]
-%
-% \let\spr\separatorlist % this will enable this feature
-%
-% \setuphead[section] [separator={?,!,*}]
-% \setuphead[subsection][separator={??,!!,**}]
-%
-% \setupheads[separator={A,B,C,D,E,F}]
-% \chapter{test}
-% \section{test} \subsection{test} \subsection{test}
-% \section{test} \subsection{test} \subsection{test}
-
-% from now on, internaly numbers are separated by a period
-% and postprocessed on demand; this will change to {} {} {}
-
-\def\numberseparator {.} % reasonable default
-\def\sectionseparator{-} % was : but is now -
-
-\def\@@filterfirstpart [#1--#2]{#1}
-\def\@@filtersecondpart [#1--#2]{#2}
-
-\def\@@filterblockpart [#1--#2--#3]{#1}
-\def\@@filternumberpart [#1--#2--#3]{#2}
-\def\@@filterpagepart [#1--#2--#3]{#3}
-\def\@@filterblocknumberpart[#1--#2--#3]{#1--#2}
-
-\def\@@filterheadpart[#1]{\@EA\@@dofilterheadpart\@EA[#1-0]}
-\def\@@filtertailpart[#1]{\@EA\@@dofiltertailpart\@EA[#1-0]}
-
-\def\@@dofilterheadpart[#1-#2]{#1}
-\def\@@dofiltertailpart[#1-#2]{#2}
-
-\def\@@filterlevelpart[#1--#2--#3]{\@@dofilterlevelpart[#2-0-0-0-0]}
-
-\def\@@dofilterlevelpart[#1-0-0-0-#2]{#1}
-
-\def\gobbleuntilrelax#1\relax{}
-
-\def\separatednumber #1{\doseparatednumber #1.\empty\relax}
-\def\removefirstprefix#1{\doremovefirstprefix#1.\empty\relax}
-\def\removeallprefixes#1{\doremoveallprefixes#1.\empty\relax}
-
-\def\doseparatednumber#1.#2%
- {#1%
- \ifx#2\empty
- \@EA\gobbleuntilrelax
- \else \numberseparator
- \@EA\doseparatednumber
- \fi#2}
-
-\def\doremoveallprefixes#1.#2%
- {\ifx#2\empty
- #1\@EA\gobbleuntilrelax
- \else
- \@EA\doremoveallprefixes
- \fi#2}
-
-\def\doremovefirstprefix#1.#2%
- {\ifx#2\empty
- #1\@EA\gobbleuntilrelax
- \else
- \@EA\noremovefirstprefix
- \fi#2}
-
-\def\noremovefirstprefix#1.\empty\relax
- {#1}
-
-% we need to expand in order to get something separatable
-
-\def\dohandleheadnumber#1%
- {\expanded{\separatednumber{#1}}}
-
-\def\dodochecknumber#1#2#3% will become ugly after speed up
- {\bgroup
- \doifinstringelse{.0}{.#2}
- {\doifnot{#3}\v!by
- {%\debuggerinfo\m!systems{number #1 #3 becomes \getnumbervariable{#1\c!way}}%
- \setevalue{\@@thenumber{#1}\c!way}{#3}% geen \xdef, gaat mis met \subpage
- \dochecknumber{#1}}} % tricky and ugly
- {\doifnotvalue{\@@thenumber{#1}\s!check}{#2}
- {% new, calculate accumulated number
- \scratchcounter\getvalue{\@@thenumber{#1}\c!n}\relax
- \advance\scratchcounter\countervalue{\@@thenumber{#1}}\relax
- \setxvalue{\@@thenumber{#1}\c!n}{\the\scratchcounter}%
- %
- \setcounter{\@@thenumber{#1}}{0\getvalue{\@@thenumber{#1}\c!start}}%
- \setxvalue{\@@thenumber{#1}\c!way\c!local}{\getvalue{\@@thenumber{#1}\c!way}}%
- \setxvalue{\@@thenumber{#1}\s!check}{#2}}}%
- \egroup}
-
-\def\dochecknumber#1%
- {\edef\currentsection{\csname\??by\csname\@@thenumber{#1}\c!way\endcsname\endcsname}%
- \ifx\currentsection\empty\else
- \dodochecknumber
- {#1}%
- {\csname\currentsection\c!number\endcsname}%
- {\v!by\previoussection\currentsection}%
- \fi}
-
-\def\checknumber[#1]%
- {\bgroup
- %\ifcase\blocklevel\else
- \ifdoingblocks
- \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
- \fi
- \dochecknumber{#1}%
- \egroup}
-
-\def\rawsectionnumber#1%
- {\countervalue{\??se#1}}
-
-\def\precedingseparator{\@@koseparator} % brrr
-
-\def\domakeprecedingsectionnumber[#1]% will become ugly after speed up
- {\bgroup % added
- \globallet\precedingsectionnumber\empty
- \ifsectionnumber
- \doifvalue{\??sb\@@sectionblock\c!number}\v!yes % added
- {\doifelsevalue{\@@thenumber{#1}\c!sectionnumber}\v!yes
- \donetrue\donefalse
- \doifvalue{\@@thenumber{#1}\c!sectionnumber}\v!number
- {\donetrue\let\@@sectionconversion\gobbleoneargument}%
- \ifdone
- \edef\currentsection
- {\getvalue{\??by\getvalue{\@@thenumber{#1}\c!way\c!local}}}%
- \doifnot\currentsection\zerosection
- {\doifnot{\@@sectionvalue\currentsection}{0}
- {\xdef\precedingsectionnumber
- {\getvalue{\currentsection\c!number}%
- \spr{\precedingseparator}}}}%
- \fi}%
- \fi
- \egroup}
-
-\def\makeprecedingsectionnumber[#1]%
- {\bgroup
- %\ifnum\blocklevel>0
- %\ifcase\blocklevel\else
- \ifdoingblocks
- \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
- \fi
- \domakeprecedingsectionnumber[#1]%
- \egroup}
-
-% \def\makesectionnumber[#1]%
-% {\makeprecedingsectionnumber[#1]%
-% \xdef\composedsectionnumber%
-% {\precedingsectionnumber\convertednumber[#1]}}%
-%
-% hack needed for chinese and oldstyle in normal tex, will change
-
-\def\makesectionnumber[#1]%
- {\bgroup
- \forceunexpanded % i don't like this hack
- \makeprecedingsectionnumber[#1]%
- \xdef\composedsectionnumber% was \xdef maar dat gaat fout met font switches
- {\precedingsectionnumber\convertednumber[#1]}%
- \egroup}
-
-% \def\preparethenumber#1#2#3% {\??id#1} \number \result
-% {\doifelsevaluenothing{#1\c!separator}
-% {\let\numberseparator\empty
-% \let#3#2}
-% {% was \unexpanded \edef, but we need it unexpanded !
-% \edef\numberseparator{\spr{\getvalue{#1\c!separator}}}%
-% \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
-% {\edef#3%
-% {\@EA\separatednumber\@EA{#2}%
-% }}%\stp{\getvalue{#1\c!stopper}}}}
-% {\edef#3%
-% {\@EA\separatednumber\@EA{#2}%
-% \spr{\getvalue{#1\c!separator}}%
-% \getvalue{#1\c!suffix}%
-% \stp{\getvalue{#1\c!stopper}}}}}}
-%
-% some day we do a real cleanup
-
-\def\analyzenumber#1#2#3% {\??id#1} \(precedingsection)number \result
- {% was \unexpanded \edef, but we need it unexpanded !
- \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
- {\let \numbersuffix \empty}
- {\edef\numbersuffix{\spr{\getvalue{#1\c!suffix}}}}%
- \doifelsenothing{\executeifdefined{#1\c!stopper}\empty}
- {\let \numberstopper \empty}
- {\edef\numberstopper{\spr{\getvalue{#1\c!stopper}}}}%
- \doifelsenothing{\executeifdefined{#1\c!separator}\empty}
- {\let \numberseparator \empty}
- {\edef\numberseparator{\spr{\getvalue{#1\c!separator}}}}%
- \let\numberprefix\empty}
-
-\def\preparefullnumber#1#2#3% {\??id#1} \(precedingsection)number \result
- {\analyzenumber{#1}#2#3%
- \ifx\numberseparator\empty
- \edef\numberprefix{#2}%
- \else
- \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
- \fi
- \ifx\numbersuffix\empty
- \ifx\numberprefix\empty
- \let #3\empty
- \else
- \edef#3{\numberprefix\numberstopper}%
- \fi
- \else
- \ifx\numberprefix\empty
- \edef#3{\numbersuffix\numberstopper}%
- \else
- \edef#3{\numberprefix\numberseparator\numbersuffix\numberstopper}%
- \fi
- \fi}
-
-\def\prepareprefixnumber#1#2#3% {\??id#1} \number \result
- {\analyzenumber{#1}#2#3%
- \ifx\numberseparator\empty
- \edef\numberprefix{#2}%
- \else
- \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
- \fi
- \let#3\numberprefix}
-
-\def\sectionnumberonly[#1]%
- {\makesectionnumber[#1]%
- \composedsectionnumber}
-
-% sectioning
-
-\newcount\nofsections
-
-\let\zerosection \v!text
-\let\firstsection\empty
-\let\lastsection \empty
-\let\@@sectie \empty
-\let\@@koppeling \empty
-
-\makecounter{\??se\v!text}
-
-\letvalueempty{\??se\v!text\c!before}
-\letvalueempty{\??se\v!text\c!after }
-
-\setvalue {\v!text\c!number}{0}
-\letvalueempty{\v!text\s!format}
-
-\letvalueempty{\??sk\v!text}
-\letvalueempty{\??sk }
-
-\letvalue{\??by }\v!text
-\letvalue{\??by\v!text }\v!text
-\letvalue{\??by\v!all }\v!text
-\letvalue{\??by\v!by }\v!text
-\letvalue{\??by\v!by\v!text}\v!text
-\letvalue{\??by\v!by\v!all }\v!text
-\letvalue{\??by\v!by\v!page}\v!text % see footnotes
-
-\def\sectionofhead#1{\executeifdefined{\??ko#1\c!section}\s!unknown}
-
-\def\setupsection
- {\dotripleempty\dosetupsection}
-
-\def\dosetupsection[#1]%
- {\doifdefinedelse{\??se#1}
- {\dodosetupsection[#1]}%
- {\dodosetupsection[\sectionofhead{#1}]}}
-
-\def\dodosetupsection[#1][#2][#3]%
- {\doifdefined{\??se#1}
- {\ifthirdargument
- \getparameters[\??se#1#2][#3]%
- \else
- \getparameters[\??se#1][#2]%
- \fi
- \doifelsevalue{\??se#1\c!previousnumber}\v!yes
- {\setvalue{#1\c!number}{\@@longsectionnumber {#1}}}
- {\setvalue{#1\c!number}{\@@shortsectionnumber{#1}}}}}
-
-\def\docouplemarking[#1][#2]%
- {\doifdefinedelse{\??ko#2\c!section}
- {\docouplemarking[#1][\getvalue{\??ko#2\c!section}]}
- {\def\donexttrackcommando##1%
- {\edef\coupledmarkings{\getvalue{\??se##1\c!marking}}%
- \doifelse{##1}{#2}
- {\addtocommalist{#1}\coupledmarkings}
- {\removefromcommalist{#1}\coupledmarkings}%
- \setevalue{\??se##1\c!marking}{\coupledmarkings}%
- \donexttracklevel{##1}}%
- \donexttracklevel{\zerosection}}} % \firstsection
-
-\def\couplemarking
- {\dodoubleargument\docouplemarking}
-
-\def\decouplemarking[#1]%
- {\couplemarking[#1][]}
-
-\def\definesection[#1]%
- {\doifundefined{\??se#1}
- {\doifelsenothing\firstsection
- {\def\firstsection{#1}%
- \setevalue{\??se#1\c!before}{\v!text}%
- \setevalue{\??se\v!text\c!after}{#1}}
- {\setevalue{\??se\commalistelement\c!after}{#1}% commalistelement ?
- \setevalue{\??se#1\c!before}{\lastsection}%
- \setevalue{\??se\lastsection\c!after}{#1}}%
- \advance\nofsections \plusone
- \setevalue{\??se#1\c!level}{\the\nofsections}%
- \letvalue{\??se#1\c!after}\empty
- \setvalue{\e!next#1}{\@@nextsectionnumber{#1}}%
- \setvalue{#1\c!number}{\@@longsectionnumber{#1}}%
- \setvalue{#1\s!format}{\@@longformatnumber{#1}}%
- \setevalue{\??by#1}{#1}%
- \setevalue{\??by\v!by#1}{#1}%
- \makecounter{\??se#1}%
- \makecounter{\??se\v!last#1}% GB
- \edef\lastsection{#1}%
- \setvalue{\??sk#1}{#1}%
- \letvalue{\??se#1\c!marking}\empty
- \setupsection[#1][\c!previousnumber=\v!yes]}}%
-
-\def\previoussection#1{\csname\??se#1\c!before\endcsname}
-\def\nextsection #1{\csname\??se#1\c!after \endcsname}
-
-\let\preservedsection\v!unknown % \def\preservedsection{\firstsection}
-
-\def\checkpreservevalueafter#1% GB
- {\ifnum\getvalue{\??se#1\c!level}<\nofsections
- \edef\preservedsection{\getvalue{\??se#1\c!after}}%
- \ifconditional\@@resetsubheadnumbers
- \setcounter{\??se\v!last\preservedsection}\zerocount % {0}%
- \else
- \setcounter{\??se\v!last\preservedsection}{\countervalue{\??se\preservedsection}}%
- \fi
- \fi}
-
-\def\@@setsectionnumber#1#2%
- {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
- \setcounter{\??se#1}{#2}%
- \checkpreservevalueafter{#1}% GB
- \resetsectioncounters{#1}%
- \checkpagecounter}
-
-\def\@@nextsectionnumber#1% patched by GB
- {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
- \ifnum\countervalue{\??se\v!last#1}>\zerocount
- \setcounter{\??se#1}{\countervalue{\??se\v!last#1}}%
- \setcounter{\??se\v!last#1}\zerocount % {0}%
- \fi
- \pluscounter{\??se#1}%
- \checkpreservevalueafter{#1}%
- \resetsectioncounters{#1}%
- \checkpagecounter}
-
-\def\@@sectionvalue#1% % nog niet overal doorgevoerd
- {\countervalue{\??se#1}} % zoeken op \??se
-
-% suited for chinese too:
-
-\def\@@sectionconversion#1#2% a doublure with \@@shortsectionnumber
- {\ifnum#2=0 0\else % else troubles with \uchar
- \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
- \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
- #2%
- \else
- \convertnumber{\getvalue{\??se#1\c!conversion}}{#2}%
- \fi
- \else
- \convertnumber{\getvalue{\??se#1\@@sectionblock\c!conversion}}{#2}%
- \fi
- \fi}
-
-% \def\@@sectionlevel#1%
-% {\ifundefined{\??se#1\c!level}0\else\getvalue{\??se#1\c!level}\fi}
-
-\def\@@sectionlevel#1%
- {\executeifdefined{\??se#1\c!level}0}
-
-% Omdat een markering kan worden herdefinieerd moeten we
-% eerst testen of er wel een keten||afhankelijkheid is.
-
-\def\resetsectionmarks#1% can invoke a break
- {\ifundefined{\??se#1}%
- \fastresetmarker[\mainmarking{#1}]% % redundant \mainmarking
- \else
- \let\donexttrackcommando\doresetsectionmarks
- \donexttracklevel{#1}%
- \fi}
-
-\def\doresetsectionmarks#1%
- {\ifundefined{\??se#1\c!marking}\else % skip zero level
- \fastresetmarkerlist[\csname\??se#1\c!marking\endcsname]%
- \fi
- \donexttracklevel{#1}}
-
-% I'm not sure if the next one is better:
-%
-% \def\doresetsectionmarks#1%
-% {\ifundefined{\??se#1\c!markering}% skip zero level
-% \donexttracklevel{#1}%
-% \else
-% \fastresetmarkerlist[\csname\??se#1\c!markering\endcsname]%
-% \fi}
-%
-% and indeed, it isn't, actually, it does not work at all, so let's drop it.
-
-% packaged:
-%
-% \def\resetsectioncounters#1%
-% {\def\donexttrackcommando##1%
-% {\resetcounter{\??se##1}%
-% \donexttracklevel{##1}}%
-% \donexttracklevel{#1}}
-%
-% nicer
-%
-% \def\doresetsectioncounters#1%
-% {\resetcounter{\??se#1}%
-% \donexttracklevel{#1}}
-%
-% obey eigennummer
-
-\def\doresetsectioncounters#1%
- {\resetcounter{\??se#1}%
- \letgvalue{\??se#1\c!ownnumber}\relax
- \donexttracklevel{#1}}
-
-\def\resetsectioncounters % #1
- {\let\donexttrackcommando\doresetsectioncounters
- \donexttracklevel} % #1
-
-% bij checken kan geen prefix worden bekeken, anders vallen
-% er titels buiten de inhoudsopgave
-
-% evt ook level gaan opslaan tbv snelle selectie
-
-% \def\makesectionformat
-% {\edef\sectionformat
-% {\@@sectiontype\sectionseparator
-% \csname\lastsection\s!format\endcsname}}
-
-\unprotected \def\makesectionformat % we don't want eigennummers here
- {\pushmacro\@@shortsectionnumber
- \let\@@shortsectionnumber\@@sectionvalue
- \edef\sectionformat
- {\@@sectiontype\sectionseparator
- \csname\lastsection\s!format\endcsname}%
- \popmacro\@@shortsectionnumber}
-
-\def\dobacktracklevel#1%
- {\doifnot{\previoussection{#1}}\zerosection
- {\dobacktrackcommando{\previoussection{#1}}}}
-
-\def\donexttracklevel#1%
- {\doifnot{#1}\lastsection
- {\donexttrackcommando{\nextsection{#1}}}}
-
-\chardef\alltoclevels\zerocount
-
-\let\currentlevel\empty
-
-\def\dosetcurrentlevel#1%
- {\global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\lastsection\s!format}}}
-
-\def\dosetpreviouslevel#1%
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty
- \def\dobacktrackcommando##1%
- {\ifnum\countervalue{\??se##1}>\zerocount
- \global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\previoussection{##1}\s!format}}%
- \else
- \dobacktracklevel{##1}%
- \fi}%
- \dobacktrackcommando\lastsection}
-
-\def\dosettextlevel#1%
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty}
-
-\def\dosetotherlevel#1%
- {\doifdefinedelse{\??ko#1\c!section} % beter alteratief: ook
- {\edef\@@sectie{\getvalue{\??ko#1\c!section}}} % hoofdstuk\c!format
- {\edef\@@sectie{#1}}%
- \doifdefinedelse{\??se\@@sectie}
- {\global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\@@sectie\s!format}}}
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty
- \def\dobacktrackcommando##1%
- {\@EA\ifx\csname\??se##1\c!start\endcsname\relax
- \dobacktracklevel{##1}%
- \else
- \ifnum\countervalue{\??se##1}>\zerocount
- \global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{##1\s!format}}%
- \else
- \dobacktracklevel{##1}%
- \fi
- \fi}%
- \dobacktrackcommando\lastsection}}
-
-% \def\ignoresectionconversion % brrr
-% {\let\@@sectionconversion\secondoftwoarguments}
-
-% todo: criterium=appendix|frontmatter|....
-
-\def\dosetfilterlevel#1#2% beware: this one is \let
- {\bgroup
- \let\@@shortsectionnumber\@@sectionvalue
-% \ignoresectionconversion
- \edef\askedlevel{#1}%
- \edef\askedfilter{#2}%
- \ifx\askedlevel\v!current
- \dosetcurrentlevel\askedlevel
- \else\ifx\askedlevel\v!previous
- \dosetpreviouslevel\askedlevel
- \else\ifx\askedlevel\v!all
- \global\chardef\alltoclevels\plusone
- \else\ifx\askedlevel\v!text
- \global\chardef\alltoclevels\plusone
- \else
- \edef\byaskedlevel{\csname\??by\askedlevel\endcsname}%
- \ifx\byaskedlevel\v!text
- \dosettextlevel\askedlevel
- \else
- \dosetotherlevel\askedlevel
- \fi
- \fi\fi\fi\fi
- % experiment
- \ifx\askedfilter\empty \else
- \xdef\currentlevel{\currentlevel\sectionseparator\askedfilter}%
- \fi
- \egroup}
-
-% \def\dontsetfilterlevel#1#2%
-% {\let\currentlevel\somesavedlevel
-% \chardef\alltoclevels\zerocount}
-
-\def\dontsetfilterlevel#1#2%
- {\let\currentlevel\somesavedlevel
- \let\@@sectiontype\@@tocsectiontype
- \chardef\alltoclevels\zerocount}
-
-\def\honorlocalfilterlevel % local lists will be real local
- {\let\dosetfilterlevel\dontsetfilterlevel}
-
-% cleaner
-%
-% \def\doifnextlevelelse[#1::#2]#3#4%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}{#4}{#3}}
-% {#4}}
-% {#4}%
-% \else
-% #3%
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]#3#4%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}{#3}{#4}}
-% {#4}%
-% \else
-% #3%
-% \fi}
-%
-% faster
-%
-% \def\doifnextlevelelse[#1::#2]%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
-% \donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% meaner
-%
-% \setuplist
-% [chapter]
-% [after={\startcolumns\placelist[section]\stopcolumns}]
-
-\def\somesavedlevel{0}
-
-% \def\dosavesomelevel[#1:0:0:0:#2]%
-% {\def\somesavedlevel{:#1}}
-
-% \def\doifnextlevelelse[#1::#2]%
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
-% \donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]%
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% again faster:
-
-% \def\doifnextlevelelse[#1::#2]% beware: this one is \let
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=#1
-% \def\levelstring{=:#2:}%
-% \doifincsnameelse{=\currentlevel:}\levelstring
-% {\doifincsnameelse{=\currentlevel:0}\levelstring\donefalse\donetrue}
-% \donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-%\def\doifprevlevelelse[#1::#2]% beware: this one is \let
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=#1
-% \doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \let\doiftoclevelelse\doifnextlevelelse
-% \let\doifreglevelelse\doifprevlevelelse
-% \let\doifblklevelelse\doifprevlevelelse
-%
-% we want to be able to overload them globally
-
-% This will be reimplemented some day soon
-%
-% {nn}{xx}{yy}
-%
-% -> \scan{..}{..}{0} met 0 als sentinel
-
-% still not perfect
-%
-% \def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
-% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
-% \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
-% \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
-% {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
-% \donefalse
-% \donetrue}
-% \donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
-% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
-% \doifinstringelse
-% {=\currentlevel\sectionseparator}
-% {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
-% \donetrue\donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-
-\def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
- {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
- \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
- \ifcase\alltoclevels
- \ifnum\@@sectiontype=\@@tocsectiontype\relax
- \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
- \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
- {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
- \donefalse
- \donetrue}
- \donefalse
- \else
- \donefalse
- \fi
- \else
- \donetrue
- \fi
- \ifdone
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
- {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
- \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
- \ifcase\alltoclevels
- \ifnum\@@sectiontype=\@@tocsectiontype\relax
- \doifinstringelse
- {=\currentlevel\sectionseparator}
- {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
- \donetrue\donefalse
- \else
- \donefalse
- \fi
- \else
- \donetrue
- \fi
- \ifdone
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-% we need to cover the special case of nested lists in section blocks
-%
-% \starttext
-%
-% \def\ChapterEntry#1#2#3%
-% {chapter : \hbox to \hsize{\strut\bf#2\hss#3}\endgraf\placelist[section]}
-%
-% \startfrontmatter % optional
-% \placelist[chapter][alternative=command,command=\ChapterEntry,criterium=text] \page
-% \stopfrontmatter % optional
-%
-% \startbodymatter % optional
-% \chapter{first} \section{one} test \section{two} test \page
-% \chapter{second} \section{alpha} test \section{beta} test \page
-% \stopbodymatter % optional
-%
-% \stoptext
-
-\def\doiftoclevelelse{\doifnextlevelelse}
-\def\doifreglevelelse{\doifprevlevelelse}
-\def\doifblklevelelse{\doifprevlevelelse}
-
-\def\@@longformatnumber#1%
- {\csname\previoussection{#1}\s!format\endcsname
- \sectionseparator
- \@@shortsectionnumber{#1}}
-
-% \def\@@longsectionnumber#1%
-% {\ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
-% \csname\previoussection{#1}\c!nummer\endcsname.%
-% \fi
-% \@@shortsectionnumber{#1}}
-
-\def\@@longsectionnumber#1%
- {\ifreversesectionnumbers
- \@@shortsectionnumber{#1}%
- \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
- .\csname\previoussection{#1}\c!number\endcsname
- \fi
- \else
- \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
- \csname\previoussection{#1}\c!number\endcsname.%
- \fi
- \@@shortsectionnumber{#1}%
- \fi}
-
-% suited for chinese too:
-%
-% \def\@@shortsectionnumber#1%
-% {\@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
-% \@@sectionvalue{#1}%
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi}
-%
-% obey eigennummer
-%
-% \def\@@shortsectionnumber#1%
-% {\@EA\ifx\csname\??se#1\c!eigennummer\endcsname\relax
-% \@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
-% \@EA\ifx\csname\??se#1\c!conversie\endcsname\relax
-% \@@sectionvalue{#1}%
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi
-% \else
-% \csname\??se#1\c!eigennummer\endcsname
-% \fi}
-
-\def\@@shortsectionnumber#1%
- {\@EA\ifx\csname\??se#1\c!ownnumber\endcsname\relax
- \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
- \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
- \@@sectionvalue{#1}%
- \else
- \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
- \fi
- \else
- \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
- \fi
- \else
- \csname\??se#1\c!ownnumber\endcsname
- \fi}
-
-\def\dosetlocalsectionblock#1#2#3% new \edef's
- {\edef\@@sectiontype {#1}%
- \edef\@@sectionblock {#2}%
- \edef\@@sectionblocks{#3}}
-
-% beware, the \resetsectionmarks generates some nodes that
-% will result in an additional last page, which needs to be
-% captured at the end
-
-% \def\doaroundsectionblock#1%
-% {\doifvaluesomething{\??sb#1\c!page}
-% {\ExpandFirstAfter\page[\getvalue{\??sb#1\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection}
-
-% \def\dostartsectionblock#1#2%
-% {\begingroup
-% \doaroundsectionblock{#1}% % going to a new page or so
-% \getvalue{\??sb#1}% % set name of section block
-% \getsectionblockenvironment{#1}% % special settings, grouped
-% %\expandafter\csname#2true\endcsname % obsolete
-% \setsystemmode{#1}% % can be used in conditionals
-% \getvalue{\??sb\@@sectionblock\c!before}% this one is not to be moved!
-% \showmessage\m!structures1\@@sectionblocks}
-
-% \def\dostopsectionblock
-% {\showmessage\m!structures2\@@sectionblocks
-% \getvalue{\??sb\@@sectionblock\c!after}% don't move
-% \doaroundsectionblock\@@sectionblock
-% \endgroup}
-
-\def\doaroundsectionblock
- {\doifvaluesomething{\??sb\@@sectionblock\c!page}
- {\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
- \resetsectioncounters\zerosection % was firstsection
- \resetsectionmarks\zerosection}
-
-\def\dostartsectionblock#1#2%
- {\begingroup
- \getvalue{\??sb#1}%
- \doaroundsectionblock
-% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection
- \getsectionblockenvironment\@@sectionblock
- \setsystemmode\@@sectionblock
- \getvalue{\??sb\@@sectionblock\c!before}%
- \showmessage\m!structures1\@@sectionblocks}
-
-\def\dostopsectionblock
- {\showmessage\m!structures2\@@sectionblocks
- \getvalue{\??sb\@@sectionblock\c!after}% don't move
- \doaroundsectionblock
-% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection
- \endgroup}
-
-\def\dosetupsectionblock[#1]% [#2]
- {\getparameters[\??sb#1]}
-
-\def\setupsectionblock
- {\dodoubleargument\dosetupsectionblock}
-
-\long\def\setsectionblockenvironment#1#2%
- {\long\setvalue{\??sb\s!do#1}{\do{#2}}}
-
-\def\getsectionblockenvironment#1%
- {\let\do\firstofoneargument\getvalue{\??sb\s!do#1}}
-
-\setvalue{\e!start\v!sectionblockenvironment}%
- {\dosingleargument\dostartsectionblockenvironment}
-
-\def\dostartsectionblockenvironment[#1]% evt \pushendofline \popendofline
- {\long\def\do##1##2{\setsectionblockenvironment{#1}{##1##2}}%
- \grabuntil{\e!stop\v!sectionblockenvironment}{\getvalue{\??sb\s!do#1}}}
-
-%D \starttyping
-%D \startsectionblockenvironment[frontpart]
-%D \setuppagenumbering[conversion=romannumerals]
-%D \stopsectionblockenvironment
-%D
-%D \startsectionblockenvironment[bodypart]
-%D \setuppagenumber[number=1]
-%D \stopsectionblockenvironment
-%D
-%D \startsectionblockenvironment[frontpart]
-%D \setuppagenumbering[conversion=character]
-%D \stopsectionblockenvironment
-%D
-%D \starttext
-%D \startfrontmatter \chapter{test} \stopfrontmatter
-%D \startbodymatter \chapter{test} \stopbodymatter
-%D \startappendices \chapter{test} \stopappendices
-%D \stoptext
-%D \stoptyping
-
-% We used to use the first char as id, but a counter is
-% better, because in english we get a name clash.
-
-\newcounter\currentsectionblock
-
-\def\currentsection{\@@sectionblock}
-
-\def\dodefinesectionblock[#1][#2][#3]%
- {\getparameters
- [\??sb#1]
- [\c!number=\v!yes,
- \c!page=\v!right, % anders worden marks te vroeg gereset !
- %\c!before=,
- %\c!after=,
- #3]%
- \expandafter\newif\csname if#2\endcsname % better a mode
- \doglobal\increment\currentsectionblock
- \setsectionblockenvironment{#1}{}%
- \setevalue{\??sb #1}{\noexpand\dosetlocalsectionblock{\currentsectionblock}{#1}{#2}}%
- \setvalue {\e!start#2}{\dostartsectionblock{#1}{#2}}%
- \setvalue {\e!stop #2}{\dostopsectionblock}}
-
-\def\definesectionblock
- {\dotripleargument\dodefinesectionblock}
-
-\def\sectionblocklabel#1#2%
- {\@EA\ifx\csname\??ko#1\@@sectionblock\c!label\endcsname\relax
- \labeltexts{#1}{#2}%
- \else
- \labeltexts{\getvalue{\??ko#1\@@sectionblock\c!label}}{#2}%
- \fi}
-
-\dosetlocalsectionblock{2}{\v!bodypart}{\v!bodymatter} % hm, dirty
-
-\def\setsectiontype[#1]%
- {\getvalue{\??sb#1}}
-
-\def\writesection#1#2#3% #3 -> \asciititle
- {\bgroup
- \edef\!!stringa{#1}%
- \@EA\writestatus\@EA
- {\!!stringa}
- {\ifsectionnumber#2\else(#2)\fi\normalspace\asciititle}%
- \egroup}
-
-\def\@@kolevel{1} \def\headlevel{\@@kolevel}
-
-\def\dohandlepagebreakAA#1%
- {\ifnum\lastpenalty>0
- \global\paginageblokkeerdtrue
- \fi}
-
-% \setuphead[section][aligntitle=float] % permits title next to sidefloat
-%
-% \placefigure[left]{}{} \section{\dorecurse{10}{bagger }} \input tufte
-
-% \def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
-% {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
-% \getvalue{\??ko#1\c!before}%
-% % \whitespace vervangen door \noindent elders
-% \relax
-% \ifpaginageblokkeerd
-% \global\paginageblokkeerdfalse
-% \else
-% \!!countb\getvalue{\??se\@@sectie\c!level}\relax
-% \ifnum\!!countb>\@@kolevel\relax
-% \!!counta20000
-% \multiply\!!countb 500
-% \advance\!!counta \!!countb
-% \dosomebreak{\penalty\!!counta}%
-% \else
-% \dosomebreak\allowbreak
-% \fi
-% \fi
-% \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
-% \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
-
-\chardef\somebreakmethod\plusone
-
-\def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
- {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
- \getvalue{\??ko#1\c!before}%
- % \whitespace vervangen door \noindent elders
- \relax
- \ifpaginageblokkeerd
- \global\paginageblokkeerdfalse
- \else
- \ifcase\somebreakmethod
- % 0 = nothing
- \or
- % 1 = old weighted version
- \!!countb\getvalue{\??se\@@sectie\c!level}\relax
- \ifnum\!!countb>\@@kolevel\relax
- \!!counta20000
- \multiply\!!countb 500
- \advance\!!counta \!!countb
- \dosomebreak{\penalty\!!counta}%
- \else
- \dosomebreak\allowbreak % brr
- \fi
- \or
- % 2 = strict version
- \dosomebreak{\penalty\maxdimen}%
- \else
- % nothing
- \fi
- \fi
- \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
- \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
-
-\def\dohandlepagebreakBB#1#2#3%
- {%\doifinsetelse{\getvalue{\??tk#2\c!state}}{\v!normal,\v!start}
- \doifelselayouttextline{#2}
- {\doifvaluesomething{\??ko#1#3}
- {\setuplayouttext[#2][\c!state=\getvalue{\??ko#1#3}]}}
- \donothing}
-
-\def\dohandlepagebreakB#1%
- {\doifvaluesomething{\??ko#1\c!page}
- {\def\resetcurrentsectionmarks% toegevoegd, zie \page
- {\resetsectionmarks{\previoussection\@@sectie}}%
- \page[\getvalue{\??ko#1\c!page}]%
- \dohandlepagebreakBB{#1}\v!header\c!header
- \dohandlepagebreakBB{#1}\v!text \c!text
- \dohandlepagebreakBB{#1}\v!footer\c!footer}}
-
-\def\dohandlepagebreakX#1% zie doordefinieren / boven
- {\bgroup
- \!!countb\@@kolevel
- \advance\!!countb #1
- \multiply\!!countb 500
- \!!counta20000
- \advance\!!counta \!!countb
- \dosomebreak{\penalty\!!counta}%
- \egroup}
-
-\newconditional\ignorehandlepagebreak
-
-\def\handlepagebreak#1%
- {\ifconditional\ignorehandlepagebreak
- \setfalse\ignorehandlepagebreak
- \else
- \dohandlepagebreakAA{#1}%
- \ifnum\countervalue{\??se\previoussection\@@sectie}>\zerocount\relax
- \ifnum\countervalue{\??se\@@sectie}>\zerocount
- \dohandlepagebreakB{#1}%
- \else
- \doifnotvalue{\??ko#1\c!continue}\v!yes{\dohandlepagebreakB{#1}}%
- \fi
- \else
- \dohandlepagebreakB{#1}%
- \fi
- \dohandlepagebreakAB{#1}%
- \fi}
-
-\def\handlenopagebreak#1%
- {\ifconditional\ignorehandlepagebreak
- \setfalse\ignorehandlepagebreak
- \else
- \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}%
- \nobreak
- \fi}
-
-\def\localheadheight {\strutht}
-\def\localheaddepth {\strutdp}
-\def\localheadlineheight{\lineheight}
-
-\def\dolocalheadsetup#1% koppeling met standaard kopcommando / engels
- {\forgetall % traag dus ...
- \doifvaluesomething{\??ko#1\c!align} % wordt al expanded in spa
- {\expanded{\setupalign[\getvalue{\??ko#1\c!align}]}}%
- \doifvaluesomething{\??ko#1\c!tolerance} % wordt al expanded in spa
- {\expanded{\setuptolerance[\getvalue{\??ko#1\c!tolerance}]}}%
- \doifvalue{\??ko#1\c!strut}\v!no % wordt al expanded in spa
- {\setnostrut}% new
- \def\\{\crlf\strut\ignorespaces}}
-
-\def\localkopsetup{\localheadsetup} % kan tzt weg
-
-% todo: make them conditionals:
-
-\newif\ifincrementnumber
-\newif\ifreversesectionnumbers % todo: key/val
-\newif\ifsectionnumber \sectionnumbertrue
-\newif\ifdisplaysectionhead \displaysectionheadtrue
-\newif\ifplacehead
-\newif\ifemptyhead
-\newif\ifwritetolist
-\newif\ifheadnumber
-\newif\ifheadnumbercontent % niet meer wijzigen / wordt mode
-\newif\ifheadprefix
-\newif\ifsomeheadconversion
-
-% new
-
-\newconditional\@@resetsubheadnumbers
-
-\def\setsectieenkoppeling#1%
- {\edef\@@koppeling{\getvalue{\??ko#1\c!coupling}}%
- \edef\@@sectie{\getvalue{\??ko#1\c!section}}%
- \doifnothing\@@koppeling
- {\edef\@@koppeling{#1}}%
- \doifnothing\@@sectie
- {\edef\@@sectie{\getvalue{\??ko\@@koppeling\c!section}}}}
-
-% \handlepagebreak komt het eerst omdat eventueel
-% subpaginanummers moeten worden afgehandeld. Vervolgens
-% worden de nummers opgehoogd en referenties geset, dan
-% volgt de kop en tot slot de worden de marks en de prefix
-% geset.
-
-% \hoofdstuk {tekst}
-% \hoofdstuk tekst
-% \hoofdstuk
-
-\let\finalsectionnumber\empty
-
-\def\dofinalsectionnumber
- {\ifundefined{\@@sectie\c!number}\else
- \ifsomeheadconversion
- \@@shortsectionnumber\@@sectie
- \else
- \getvalue{\@@sectie\c!number}%
- \fi
- \fi}
-
-\def\findsectionnumber#1#2#3% class file title / uti seperator --
- {\begingroup
- \setsectieenkoppeling{#1}%
- \xdef\foundsectionnumber{1}%
- \def\dolistelement##1##2##3##4##5##6%
- {\doif{##1}{#1}
- {\ConvertConstantAfter\doif{##4}{#3}
- {\global\utilitydonetrue
- \scratchcounter=0\getvalue{\??se\@@sectie\c!level}%
- %
- %\advance\scratchcounter 2
- %\@EA\def\@EA\do\@EA####\@EA1\sectionseparator####2]%
- % {\advance\scratchcounter -1
- % \ifcase\scratchcounter
- % \xdef\foundsectionnumber{####1}%
- % \else
- % \do####2]%
- % \fi}%
- %\do##5]}}}%
- %
- \def\do####1\relax % :/- clean
- {\advance\scratchcounter \minusone
- \ifcase\scratchcounter
- \xdef\foundsectionnumber{\@@filterheadpart[####1]}%
- \else
- \@EAEAEA\do\@@filtertailpart[####1]\relax
- \fi}%
- \@EA\do\@@filternumberpart[##5]\relax}}}%
- \setbox0\vbox
- {\doutilities{#1}{#2}{#1}\relax\relax}%
- \endgroup
- \doifnumberelse\foundsectionnumber
- {\doif\foundsectionnumber\!!zerocount
- {\globallet\foundsectionnumber\!!plusone}}
- {\globallet\foundsectionnumber\!!plusone}% an appendix or so
- \setupheadnumber[#1][\foundsectionnumber]%
- \setupheadnumber[#1][-1]}
-
-% deal with eigennummer
-
-\def\setsomeheadconversion#1#2%
- {\someheadconversionfalse
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\setgvalue{\??se\@@sectie\c!ownnumber}{#2}%
- \def\someheadconversion{#2}}
- {\letgvalue{\??se\@@sectie\c!ownnumber}\relax
- \determineheadnumber[#1]%
- \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\relax
- \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\relax
- \def\someheadconversion{#2}%
- \else
- \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\empty
- \def\someheadconversion{#2}%
- \else
- \someheadconversiontrue
- \def\someheadconversion%
- {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\c!headconversion}}{#2}}%
- \fi
- \fi
- \else
- \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\empty
- \def\someheadconversion{#2}%
- \else
- \someheadconversiontrue
- \def\someheadconversion%
- {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\@@sectionblock\c!headconversion}}{#2}}%
- \fi
- \fi}}
-
-\def\writtenfullsectionnumber
- {\string\fullsectionnumber}
-
-\def\ignoredfullsectionnumber#1#2#3%
- {#3}
-
-\let\storedfullsectionnumber\relax
-
-\def\expandablefullsectionnumber#1#2#3%
- {\convertnumber{#2}{#3}}
-
-\unexpanded\def\naturalfullsectionnumber#1#2#3%
- {\sectionblocklabel{#1}{\convertnumber{#2}{#3}}}
-
-\unexpanded\def\limitedfullsectionnumber#1#2#3%
- {\convertnumber{#2}{#3}}
-
-\def\setfullsectionnumber#1%
- {\doifelsevalue{#1\c!headconversion}\v!yes
- {\doifelsevalue{#1\c!headlabel}\v!yes
- {\let\fullsectionnumber\naturalfullsectionnumber}
- {\let\fullsectionnumber\limitedfullsectionnumber}}
- {\let\fullsectionnumber\ignoredfullsectionnumber}}
-
-\let\fullsectionnumber\limitedfullsectionnumber
-
-% \dodododoconstructhead IS NON GROUPED, SO WE NEED TO RESTORE !!!!
-%
-% dit kan dus beter \everyaroundhead zijn
-
-\let\currentheadnumber\empty
-\let\currentheadtext \empty
-
-\def\dodoconstructhead#1[#2]#3% [ref] {title}
- {\doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\doquadruplegroupempty\dododoconstructhead{#1}{#2}{#3}}
- {\fourthargumentfalse \dododoconstructhead{#1}{#2}{#3}{}}}
-
-\def\dododoconstructhead#1#2#3#4% [ref] {own} {title}
- {\iffourthargument
- \def\next{\dodododoconstructhead{#1}[#2]{#3}{#4}}%
- \else
- \def\next{\dodododoconstructhead{#1}[#2]{\finalsectionnumber}{#3}}%
- \fi
- \next}
-
-% pas met \ExpandFirstAfter op bij twee||taligheid
-
-\ifx\dohandleheadnumber\undefined
- \let\dohandleheadnumber\firstofoneargument
-\fi
-
-\unexpanded\def\\{\space}
-
-\def\emptyheadcorrection % experimental, should work
- {\ifemptyhead % well with na=\blank
- \vskip-\lineheight
- \dosomebreak\nobreak
- \kern\zeropoint
- \prevdepth\strutdepth
- \fi}
-
-\let\localkopprefix\empty
-
-\def\headparameter#1% to do: everywhere in core-sec
- {\executeifdefined{\??ko\currenthead#1}\empty}
-
-% todo: write to list etc in both args or in enclosing h/vbox else it gets
-% lost when no #1 or #2 is typeset
-
-% we will use variables here
-
-\def\dodododoconstructhead#1[#2]#3#4% [ref] {number} {title}
- {\def\currenthead{#1}% dus #1 overal vervangen
- \let\finalsectionnumber\dofinalsectionnumber % overloaded ungrouped -)
- \unexpanded\def\\{\space}%
- \edef\numberseparator{\spr{\getvalue{\??ko\currenthead\c!separator}}}%
- \flushingcolumnfloatsfalse % {number} can be \finalsectionnumber
- \someheadconversionfalse
- \let\fullsectionnumber\limitedfullsectionnumber
- \setsectieenkoppeling{#1}%
- \doifelsevaluenothing{\??ko#1\c!prefix}
- \headprefixfalse\headprefixtrue
- \ifheadprefix
- \doifelsevalue{\??ko#1\c!prefix}{+}
- {\doifelsenothing{#2}
- {\def\localkopprefix{+}}
- {\def\localkopprefix{#2}}} % eigenlijk alleen eerste
- {\edef\localkoprefix{\getvalue{\??ko#1\c!prefix}}}%
- \else
- \let\localkoprefix\empty
- \fi
- \placeheadtrue
- \processaction
- [\getvalue{\??ko#1\c!placehead}]
- [ \v!yes=>\emptyheadfalse,
- \v!empty=>\emptyheadtrue,
- \v!no=>\emptyheadtrue\placeheadfalse]%
- \doifelsevalue{\??ko#1\c!resetnumber}\v!no
- {\setfalse\@@resetsubheadnumbers}%
- {\settrue \@@resetsubheadnumbers}%
- \writetolistfalse
- \processaction
- [\getvalue{\??ko#1\c!incrementnumber}]
- [ \v!yes=>\incrementnumbertrue,
- \v!no=>\incrementnumberfalse,
- \v!list=>\incrementnumberfalse
- % beware, since no numbers are used, no nested lists are
- % possible here
- \writetolisttrue,
- \s!unknown=>{\ifx\currentproduct\empty
- \findsectionnumber{#1}\commalistelement{#4}%
- \fi
- \incrementnumbertrue}]%
- \edef\numberheaddistance {\getvalue{\??ko#1\c!distance}}%
- \edef\numberheadalternative{\getvalue{\??ko#1\c!alternative}}%
- \doifelsevalue{\??ko:\numberheadalternative}\v!horizontal
- \displaysectionheadfalse
- \displaysectionheadtrue
- \ifsectionnumber
- \doifelsevalue{\??sb\@@sectionblock\c!number}\v!yes
- {\doifelsevalue{\??ko#1\c!number}\v!yes
- \headnumbertrue
- \headnumberfalse}
- {\headnumberfalse}%
- \else
- \headnumberfalse
- \fi
- \defconvertexpanded\asciititle{\getvalue{\??ko#1\c!expansion}}{#4}%
- %
- \gdef\currentheadtext{#4}% scheelt args
- \globallet\currentheadnumber\empty
- %
- \ifincrementnumber
- \ifplacehead
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \ifheadprefix
- %\setupreferencing[\c!prefix=-]%
- \setupreferenceprefix[-]%
- \fi
- \getvalue{\e!next\@@sectie}%
- \ifheadnumber
- \setsomeheadconversion{#1}{#3}%
- \let\fullsectionnumber\expandablefullsectionnumber
- \xdef\currentheadnumber{\someheadconversion}%
- \getvalue{\??ko#1\c!inbetween}%
- \ifsomeheadconversion
- \let\fullsectionnumber\naturalfullsectionnumber
- \doplaceheadnumbertext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \let\fullsectionnumber\writtenfullsectionnumber
- \rawreference\s!sec{#2}{{\someheadconversion}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \let\fullsectionnumber\writtenfullsectionnumber
- \dowritetolist\@@koppeling\someheadconversion{#4}\v!head}%
- {\dohandleheadnumber\someheadconversion}% handle is new
- {#4}
- {\marking[#1]{#4}%
- \let\fullsectionnumber\storedfullsectionnumber
- \expanded{\marking[#1\v!number]{\someheadconversion}}}%
- \let\fullsectionnumber\ignoredfullsectionnumber
- \writesection{#1}{\someheadconversion}{#4}%
- \else
- \doplaceheadnumbertext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \dowritetolist\@@koppeling{#3}{#4}\v!head}
- {\sectionblocklabel{#1}{\dohandleheadnumber{#3}}}% handle is new
- {#4}
- {\marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % rommelig omdat
- {\edef\finalsectionnumber{#3}} % #3 al is toegekend
- {\determineheadnumber[#1]}% migreert naar 3e argument
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
- \writesection{#1}{#3}{#4}%
- \fi
- \else
- \getvalue{\??ko#1\c!inbetween}%
- \doplaceheadtext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr, new per 18/1/2005, sometimes we need
- {\dowritetolist\@@koppeling{#3}{#4}\v!head} % entries in the list (special purpose) but
- {\dowritetolist\@@koppeling {}{#4}\v!head}% not in the header, ok we could pop in a command
- }% \dowritetolist\@@koppeling{}{#4}\v!head}
- {#4}
- {\marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr
- {\edef\finalsectionnumber{#3}}
- {\determineheadnumber[#1]}%
- % todo : geen markering (leeg maken)
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
- \writesection{#1}{-}{#4}%
- \fi
- \ifheadprefix
- \setupreferenceprefix[\localkopprefix]%
- \fi
- \ifdisplaysectionhead
- \dosomebreak\nobreak
- \emptyheadcorrection
- \getvalue{\??ko#1\c!after}%
- \fi
- \else
- % Whatever future tex's will do with nodes,
- % we assume a node here, because other \c!after=\blank
- % will fail! See 'prikkels'
- %
- % so, maybe we need an explicit \kern
- %
- % do nothing / should be vbox to 0pt
- %
- \checknexthead\dohandlepagebreakB{#1}% toegevoegd ivm subpaginanr / tug sheets
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \ifheadprefix
- \setupreferenceprefix[-]%
- \fi
- \getvalue{\e!next\@@sectie}%
- \ifheadnumber
- \setsomeheadconversion{#1}{#3}%
- \let\fullsectionnumber\expandablefullsectionnumber
- \xdef\currentheadnumber{\someheadconversion}%
- \fi
- \getvalue{\??ko#1\c!inbetween}% documenteren, is enige hook
- \bgroup
- \setsectionlistreference{\@@sectie}{#1}%
- \resetsectionmarks\@@sectie
- \marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\edef\finalsectionnumber{#3}}
- {\determineheadnumber[#1]}%
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}%
- \pagetype[\@@koppeling]%
-% \bgroup
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \ifheadnumber
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \dowritetolist\@@koppeling{#3}{#4}\v!head
- \writesection{#1}{#3}{#4}%
- \else % hm, also no own number
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \dowritetolist\@@koppeling{}{#4}\v!head
- \writesection{#1}{-}{#4}%
- \fi
- \egroup
- \ifheadprefix
- \setupreferenceprefix[\localkopprefix]%
- \fi
- \fi
- \else
- % todo : ref prefix
- \ifplacehead
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \getvalue{\??ko#1\c!inbetween}%
- \doplaceheadtext
- {#1}
- {\forcesectiontolist{#1}{#4}%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}} % #3 ?
- {#4}
- %{}% new:
- {\marking[#1]{#4}%
- \marking[#1\v!number]{}}%
- \writesection{#1}{-}{#4}%
- \ifdisplaysectionhead
- \dosomebreak\nobreak
- \emptyheadcorrection
- \getvalue{\??ko#1\c!after}%
- \fi
- \else
- % do nothing / should be vbox to 0pt
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \getvalue{\??ko#1\c!inbetween}%
- \forcesectiontolist{#1}{#4}%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}% #3 ?
- \marking[#1]{#4}%
- \marking[#1\v!number]{}%
- \writesection{#1}{-}{#4}%
- \fi
- \fi
- \flushingcolumnfloatstrue
- \someheadconversionfalse
- \setfalse\ignorehandlepagebreak
- \let\fullsectionnumber\limitedfullsectionnumber
- % ignorespaces prevents spaces creeping in when after=\dontleavehmode
- \ifdisplaysectionhead\ignorespaces\else\expandafter\GotoPar\fi}
-
-\def\forcesectiontolist#1#2%
- {\ifwritetolist
- % we need to make sure that there is a number set (non
- % zero) else the list mechanism cannot determine the
- % level
- \bgroup
- \setupheadnumber[#1][+1]% traag, wordt \getvalue{\c!next...}
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \dowritetolist\@@koppeling{}{#2}\v!head
- \setupheadnumber[#1][-1]% traag, wordt \getvalue{\c!previous...}
- \egroup
- \fi}
-
-\let\previoussectionformat\empty
-\let\currentsectionformat \empty
-
-\let\updatelistreferences \relax
-\let\updatedlistreferences\empty
-
-\def\setsectionlistreference#1#2%
- {\ifnum\countervalue{\??se\previoussection{#1}}>0\relax
- \xdef\previoussectionformat{\@@longformatnumber{\previoussection{#1}}}%
- \else
- \globallet\previoussectionformat\empty
- \fi
- \xdef\currentsectionformat{\@@longformatnumber{#1}}}
-
-\def\startlistreferences#1%
- {\thisissomeinternal{\s!lst}{#1\currentsectionformat}%
- \setxvalue{\s!lst:#1}{\realfolio}% to be sure
- \setxvalue{\s!lst:#1\currentsectionformat}{\realfolio}%
- \setxvalue{\e!previouslocal#1}{\s!lst:#1\previoussectionformat}%
- \setxvalue{\e!currentlocal#1}{\s!lst:#1\currentsectionformat}%
- \doifelse{\currentsectionformat}{}
- {\setglobalcrossreference
- {\e!previous#1}{}{\realfolio}{}}
- {\setglobalsystemreference\rt!list
- {\e!previous#1}{\getvalue{\e!previouslocal#1}}}%
- \def\stoplistreferences{\dostoplistreferences{#1}}}
-
-\def\dostoplistreferences#1%
- {\ifutilitydone
- \addtocommalist{#1}\updatedlistreferences % nog global (\doglobal)
- \globallet\updatedlistreferences\updatedlistreferences % een noodverbandje
- \gdef\updatelistreferences%
- {\def\docommand####1%
- {\setglobalsystemreference\rt!list
- {\e!previous####1}{\getvalue{\e!currentlocal####1}}}%
- \processcommacommand[\updatedlistreferences]\docommand
- \globallet\updatelistreferences\relax
- \globallet\updatedlistreferences\empty}%
- \fi}
-
-\let\stoplistreferences\relax
-
-\appendtoks
- \updatelistreferences
-\to\aftereverypage
-
-% \prevdepth\strutdp % is belangrijk, vergelijk naast elkaar:
-%
-% \subject{test} \input tufte
-% \subject{test} \strut \input tufte
-% \subject{test} \placelist[...]
-
-% todo: kap
-
-% to be documented: \placeheadtext \placeheadnumber
-
-\unexpanded\def\placeheadtext
- {\doquintupleempty\doplaceheadtextornumber
- [\c!textstyle][\c!textcolor][\empty]}
-
-\unexpanded\def\placeheadnumber
- {\doquintupleempty\doplaceheadtextornumber
- [\c!numberstyle][\c!numbercolor][\v!number]}
-
-\def\doplaceheadtextornumber[#1][#2][#3][#4][#5]%
- {\bgroup
- \edef\@@sectie{\??ko\iffifthargument#5\else#4\fi}%
- \dostartattributes\@@sectie\c!style\c!color\empty
- \dontconvertfont
- \dostartattributes\@@sectie{#1}{#2}\empty
- \setupinterlinespace
- \begstrut\getmarking[\mainmarking{#4#3}]\endstrut
- \endgraf
- \dostopattributes
- \dostopattributes
- \egroup}
-
-\chardef\headtimingmode=0
-
-% \chardef\headtimingmode=1 % 0 also works ok now too
-%
-% Martin Kolarik's problem:
-%
-% \setuphead[section][command=\doTitle]
-%
-% \def\doTitle#1#2%
-% {\ruledvbox{\forgetall \hsize=4cm
-% \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}}
-%
-% \section{test test test test test test test test test test
-% test test test test test test test}
-
-\newevery \everyheadstart \relax
-
-\def\placeheadmargintexts#1%
- {\the\everyheadstart
- \doifvalue{\??ko#1\c!margintext}\v!yes\placemargincontent}
-
-\def\doplaceheadtext#1#2#3#4%
- {\beginheadplacement{#1}%
- \ifemptyhead % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
- {\headnumbercontentfalse
- \resetsystemmode\v!sectionnumber
- #2}%
- \makestrutofbox0
- \else % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
- {\headnumbercontentfalse
- \resetsystemmode\v!sectionnumber
- % less interfering
- \ifcase\headtimingmode\or#2\fi
- % outerside font determines distance
- \dosetfontattribute{\??ko#1}\c!style
- % but we don't want color to influence user commands
- % todo: get the if-else out of it
- \getvalue{\??ko#1\c!command}
- {} % no number
- {\dostartattributes{\??ko#1}\c!style\c!color\empty
- \dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
- \dontconvertfont
- \ifdisplaysectionhead
- \setupinterlinespace
- \else
- \setupspacing
- \fi
- % \ifcase\headtimingmode#2\fi % can introduce cr
- \getvalue{\??ko#1\c!commandbefore}%
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
- {\setstrut
- \begstrut
- \ifcase\headtimingmode\hbox{#2}\fi
- \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}%
- \endstrut}% \hbox prevents break
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdepth
- \else
- \ifcase\headtimingmode#2\fi
- \getvalue{\??ko#1\c!textcommand}%
- {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}}%
- \fi
- \getvalue{\??ko#1\c!commandafter}%
- \ifdisplaysectionhead\endgraf\fi
- \dostopattributes
- \dostopattributes}}%
- \fi
- \endheadplacement{#1}{#4}}
-
-\def\doplaceheadnumbertext#1#2#3#4#5% maybe move modes outside box
- {\beginheadplacement{#1}%
- \ifemptyhead % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
- {\doiftextelse{#3}
- {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
- {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
- #2}%
- \makestrutofbox0
- \else % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
- {\doiftextelse{#3}
- {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
- {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
- % less interfering
- \ifcase\headtimingmode\or#2\fi
- % outerside font determines distance
- \dosetfontattribute{\??ko#1}\c!style
- % but we don't want color to influence user commands
- \getvalue{\??ko#1\c!command}%
- {\dostartattributes{\??ko#1}\c!style\c!color\empty
- \dostartattributes{\??ko#1}\c!numberstyle\c!numbercolor\empty
- % \getvalue{\??ko#1\c!commandbefore}% strange, why here? moved 21/11/2005
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- % can be nilled with \setnostrut
- \getvalue{\??ko#1\c!numbercommand}%
- {\setstrut
- \begstrut
- \executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}%
- \endstrut}%
- \else
- \getvalue{\??ko#1\c!numbercommand}%
- {\executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}}%
- \fi
- \dostopattributes
- \dostopattributes}
- {\dostartattributes{\??ko#1}\c!style\c!color\empty
- \dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
- \dontconvertfont
- \ifdisplaysectionhead
- \setupinterlinespace
- \else
- \setupspacing
- \fi
- % \ifcase\headtimingmode#2\fi % can introduce cr
- \getvalue{\??ko#1\c!commandbefore}% makes more sense here
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
- {\setstrut
- \begstrut
- \ifcase\headtimingmode\hbox{#2}\fi
- \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}%
- \endstrut}% \hbox prevents break
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdepth
- \else
- \ifcase\headtimingmode#2\fi % inside textcommand ?
- \getvalue{\??ko#1\c!textcommand}%
- {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}}%
- \fi
- \getvalue{\??ko#1\c!commandafter}%
- \ifdisplaysectionhead\endgraf\fi
- \dostopattributes
- \dostopattributes}}%
- \fi
- \endheadplacement{#1}{#5}}
-
-%D \starttyping
-%D \def\StretchedBox#1%
-%D {\framed
-%D [frame=off,offset=.5em,align=middle,width=broad]
-%D {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}}
-%D
-%D \definehead[MySubject][subject]
-%D \setuphead [MySubject][deeptextcommand=\StretchedBox]
-%D
-%D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
-%D \stoptyping
-
-\newsignal\headsignal
-\let\headlastlinewidth\!!zeropoint
-
-\def\beginheadplacement#1%
- {\bgroup
- \setsystemmode{#1}% to be documented
- \ifgridsnapping\iftracegridsnapping\showstruts\fi\fi
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdp
- \everypar\emptytoks % needed indeed
- \noindent % ipv \whitespace elders, na \forgetall !
- \bgroup
- \doifinsetelse{\getvalue{\??ko#1\c!aligntitle}}{\v!yes,\v!float}% new
- {\skip0 1\leftskip
- \skip2 1\rightskip
- \xdef\localheadskip{\the\skip0}%
- \forgetall
- \leftskip\skip0
- \rightskip\skip2
- \setlocalhsize\hsize\localhsize
- \forgetbothskips}
- {\globallet\localheadskip\!!zeropoint
- \forgetall}%
- \dontcomplain
- \postponefootnotes
- \iflocation\ifdisplaysectionhead\else\noninterferingmarks\fi\fi
- \resetinteractionparameter\c!style
- \resetinteractionparameter\c!color
- \resetinteractionparameter\c!contrastcolor
- \strictouterreferencestrue % tzt instelling
- \def\localheadsetup{\dolocalheadsetup{#1}}%
- \startsynchronization}
-
-% \setuphead[chapter] [style=\bfd,after=,hang=line] % fit broad 2
-% \setuphead[section] [style=\bfc,after=,hang=line]
-% \setuphead[subsection] [style=\bfb,after=,hang=line]
-% \setuphead[subsubsection] [style=\bfa,after=,hang=line]
-% \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
-%
-% \chapter {Test} \input tufte \page
-% \section {Test} \input tufte \page
-% \subsection {Test} \input tufte \page
-% \subsubsection {Test} \input tufte \page
-% \subsubsubsection{Test} \input tufte \page
-%
-% \chapter {Test\\Test} \input tufte \page
-% \section {Test\\Test} \input tufte \page
-% \subsection {Test\\Test} \input tufte \page
-% \subsubsection {Test\\Test} \input tufte \page
-% \subsubsubsection{Test\\Test} \input tufte \page
-
-\def\hangheadplacement
- {\scratchdimen\localheadlineheight
- \bgroup
- \openlineheight\scratchdimen
- \scratchdimen\ht0
- \advance\scratchdimen\dp0
- \getnoflines\scratchdimen
- \advance\noflines\minusone
- \expanded{\egroup\noflines\the\noflines}% brrr
- \setbox0\hbox{\lower\noflines\scratchdimen\box0}%
- \scratchdimen\ht0
- \advance\scratchdimen\dp0
- \advance\scratchdimen-\localheadheight
- \advance\scratchdimen+\strutdp
- \ht0 \strutht
- \dp0 \strutdp
- \edef\localheaddepth{\the\strutdp}}
-
-\newconditional\continuoussectionhead % oeps, \newif\ifcontinuoushead got lost
-
-\def\endheadplacement#1#2%
- {\doifelsevalue{\??rf#1\c!state}\v!start
- {\doifvaluenothing{\??ko#1\c!file}{\autocrossdocumentfalse}}
- {\autocrossdocumentfalse}%
- % no message needed here, should be a proper switch
- \noflines\zerocount
- \ifdisplaysectionhead
- % new (tod tight == one following line up)
- \processaction
- [\getvalue{\??ko#1\c!hang}]
- [ \v!line=>\hangheadplacement\noflines\zerocount,
- \v!broad=>\hangheadplacement\getnoflines\scratchdimen,
- \v!fit=>\hangheadplacement\getrawnoflines\scratchdimen,
- \v!none=>\noflines\zerocount,
- \v!default=>\noflines\zerocount,
- \v!unknown=>\hangheadplacement\noflines0\commalistelement\advance\noflines\minusone]%
- % so far
- \let\headlastlinewidth\!!zeropoint
- \snaptogrid[\getvalue{\??ko#1\c!grid}]\hbox
- {\hskip\localheadskip
- \hskip\getvalue{\??ko#1\c!margin}\relax
- \iflocation
- \ifautocrossdocument
- \doifreferencefoundelse{\getvalue{\??ko#1\c!file}::#1}
- {\edef\currentinnerreference{\s!aut:\currenttextreference}% stored in
- \gotoouterlocation{}{\box0}} % text slot
- {\hbox{\box0}}%
- \else
- \hbox{\box0}%
- \fi
- \else
- \hbox{\box0}%
- \fi}%
- \doflushnotes % new, not really needed
- \endgraf
- \ifvmode
- \ifnum\noflines>\zerocount
- \dorecurse\noflines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}%
- \fi
- \nointerlineskip
- \dosomebreak\nobreak
- \fi
- #2%
- \else
- \strut
- \doflushnotes % new, here since we're in par mode
- \iflocation
- \ifautocrossdocument
- \hhboxindent=\ifconditional\continuoussectionhead\headlastlinewidth\else\zeropoint\fi
- \unhhbox0\with{\gotobox{\box\hhbox}[\getvalue{\??ko#1\c!file}::#1]}%
- \advance\lasthhboxwidth by \numberheaddistance
- \xdef\headlastlinewidth{\the\lasthhboxwidth}%
- \else
- \unhbox0
- \globallet\headlastlinewidth\!!zeropoint
- \fi
- \else
- \unhbox0
- \globallet\headlastlinewidth\!!zeropoint
- \fi
- #2%
- \dimen0=\numberheaddistance
- \hskip\dimen0 \!!plus \dimen0 \!!minus .25\dimen0
- \hskip\headsignal\ignorespaces
- \fi
- \ifdisplaysectionhead \ifvmode
- \ifgridsnapping % important, font related depth, see comment
- \prevdepth\strutdp
- \else
- \prevdepth\localheaddepth
- \fi
- \fi \fi
- \stopsynchronization
- \egroup
- \egroup
- \ifdisplaysectionhead
- \dochecknextindentation{\??ko#1}%
- \else
- \nonoindentation % recently added, was a bug
- \fi}
-
-\def\checknexthead#1#2% nog optioneel
- {\ifhmode
- \scratchcounter=\lastpenalty\unpenalty % no beauty in this
- \ifdim\lastskip=\headsignal
- \handlenopagebreak{#1}%
- \global\settrue\continuoussectionhead
- \else
- \penalty\scratchcounter
- \global\setfalse\continuoussectionhead
- #1{#2}%
- \fi
- \else
- \global\setfalse\continuoussectionhead
- #1{#2}%
- \fi}
-
-\def\dosetupheadnumber[#1][#2#3]% todo: = (don't reset)
- {\bgroup
- \setsectieenkoppeling{#1}%
- \doifinstringelse{#2}{+-}
- {\doifelsenothing{#3}
- {\@@nextsectionnumber\@@sectie}
- {\!!counta=#2#3\relax
- \advance\!!counta \@@sectionvalue\@@sectie
- \@@setsectionnumber\@@sectie\!!counta}}
- {\@@setsectionnumber\@@sectie{#2#3}}%
- \egroup}
-
-\def\setupheadnumber
- {\dodoubleargument\dosetupheadnumber}
-
-\def\currentheadnumber{0}
-
-\def\determineheadnumber[#1]%
- {\bgroup
- \setsectieenkoppeling{#1}%
- \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
- \egroup}
-
-\def\complexheadnumber[#1]%
- {\bgroup
- \edef\currentheadnumber{#1}%
- \doifinsetelse{-}{#1} % br undocumented
- {\removefromcommalist{-}\currentheadnumber % br
- \setsectieenkoppeling\currentheadnumber
- \setupsection[\@@sectie][\c!previousnumber=\v!no]}%
- {\setsectieenkoppeling\currentheadnumber}%
- \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
- \doifnot{\currentheadnumber}{0}{\finalsectionnumber}%
- \egroup}
-
-\def\simpleheadnumber
- {\currentheadnumber}
-
-\definecomplexorsimple\headnumber
-
-\def\alinea
- {\par}
-
-% nice testcase
-%
-% \setupheads[aligntitle=yes]
-%
-% \startnarrower
-% \subject{\dorecurse{100}{x }}
-% \section{\dorecurse{100}{x }}
-% \input tufte \par
-% \setupheads[alternative=inmargin]
-% \subject{\dorecurse{100}{x }}
-% \section{\dorecurse{100}{x }}
-% \input tufte \par
-% \stopnarrower
-
-\let\numberheadalternative\v!normal
-
-\def\defineheadplacement
- {\dodoubleargument\dodefineheadplacement}
-
-\def\dodefineheadplacement[#1][#2]% #3#4
- {\setvalue{\??ko:#1}{#2}%
- \setvalue{\??ko::#1}}
-
-\def\normalplacehead
- {\executeifdefined
- {\??ko::\numberheadalternative}
- {\getvalue{\??ko::\v!normal}}}
-
-\defineheadplacement[\v!paragraph][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \begstrut\ifheadnumbercontent#1\hskip\numberheaddistance\fi#2}}
-
-% \defineheadplacement[\v!normal][\v!vertical]#1#2%
-% {\ifheadnumbercontent
-% \setbox0\hbox{{#1}\hskip\numberheaddistance}%
-% \vbox
-% {\localheadsetup
-% \hangindent 1\wd0
-% \hangafter 1
-% \noindent
-% \unhbox0 % don't use \strut's here!
-% #2}%
-% \else
-% \vbox
-% {\localheadsetup\noindent#2}%
-% \fi}
-%
-% enhanced version:
-
-% \setuphead
-% [chapter]
-% [numberwidth=2cm,hang=line,after={\blank[3*line]}]
-%
-% \chapter{Oeps oeps oeps} \input tufte \section{Oeps}
-% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
-
-\defineheadplacement[\v!normal][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \edef\headwidth {\headparameter\c!width }%
- \edef\headnumberwidth{\headparameter\c!numberwidth}%
- \edef\headtextwidth {\headparameter\c!textwidth }%
- \ifheadnumbercontent
- \ifx\headwidth\empty
- \else
- \ifx\headnumberwidth\empty
- \ifx\headtextwidth\empty\else
- \edef\headnumberwidth{\the\dimexpr\headwidth-\headtextwidth\relax}%
- \fi
- \else
- \ifx\headtextwidth\empty
- \edef\headtextwidth{\the\dimexpr\headwidth-\headnumberwidth\relax}%
- \fi
- \fi
- \hsize\headwidth
- \fi
- \ifx\headnumberwidth\empty\else
- \let\numberheaddistance\!!zeropoint
- \fi
- \setbox\scratchbox\hbox \ifx\headnumberwidth\empty\else to \headnumberwidth\fi{{#1}}%
- \scratchdimen\dimexpr\wd\scratchbox+\numberheaddistance\relax
- \ifx\headtextwidth\empty\else
- \hsize\dimexpr\scratchdimen+\headparameter\c!textwidth\relax
- \fi
- \hangindent\scratchdimen
- \hangafter \plusone
- \noindent
- \box\scratchbox\hskip\numberheaddistance
- \else
- \ifx\headtextwidth\empty
- \ifx\headwidth\empty
- \else
- \hsize\headwidth
- \fi
- \else
- \hsize\headtextwidth
- \fi
- \noindent
- \fi
- #2}}
-
-\def\placeheadmargin#1#2%
- {\vbox
- {\localheadsetup
- \begstrut % use one \strut here!
- \dontleavehmode % in case there is no strut, else side effects with llap
- \ifheadnumbercontent
- \llap{\hbox to 5em{\hfill{#1}\hskip\localheadskip\hskip\leftmargindistance}}% introduces whitespace
- % maybe better:
- % \inleftmargin{\hbox{\hss{#1}\hskip\localheadskip}}%
- \fi
- {#2}}}
-
-\defineheadplacement[\v!inmargin][\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
-\defineheadplacement[\v!margin] [\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
-
-\defineheadplacement[\v!middle][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \veryraggedcenter
- \let\\\endgraf
- \let\crlf\endgraf
- \ifheadnumbercontent\strut#1\par\fi\begstrut#2}}
-
-\defineheadplacement[\v!text][\v!horizontal]#1#2%
- {\bgroup
- \localheadsetup % no stretch in distance
- \ifheadnumbercontent{#1}\kern\numberheaddistance\fi{\begstrut#2}%
- \egroup}
-
-\def\placeheadlohi#1#2#3%
- {\ifheadnumbercontent
- \setbox0\hbox{#2}
- \setbox2=#1{\localheadsetup\advance\hsize-\wd0\relax#3}%
- \hbox{\box0\hskip\numberheaddistance\box2}%
- \else
- #1{\localheadsetup\noindent#3}%
- \fi}
-
-% onder/boven lijnt het nummer op de onderste/bovenste regel
-% uit van een meerregelige kop
-
-\defineheadplacement[\v!bottom][\v!vertical]#1#2{\placeheadlohi\vbox{#1}{#2}}
-\defineheadplacement[\v!top] [\v!vertical]#1#2{\placeheadlohi\vtop{#1}{#2}}
-
-% default == instellingen
-% koppeling == koppen, breaks, marks, enz.
-% sectie == nummering
-
-\let\@@kolist=\empty
-
-\def\dododefinehead#1#2% % don't preset prefix to much
- {\presetlabeltext[#1=]%
- \getparameters
- [\??ko#1]
- [\c!numberstyle=\getvalue{\??ko#1\c!style},
- \c!textstyle=\getvalue{\??ko#1\c!style},
- \c!numbercolor=\getvalue{\??ko#1\c!color},
- \c!textcolor=\getvalue{\??ko#1\c!color}]%
- % deeptextcommand and deepnumbercommand are left undefined !
- \doifassignmentelse{#2}
- {\getparameters
- [\??ko#1]
- [\c!section=\getvalue{\??ko\getvalue{\??ko#1\c!coupling}\c!section},
- \c!default=,
- \c!coupling=,
- \c!prefix=,
- \c!before=,
- \c!after=,
- \c!distance=\!!zeropoint,
- \c!page=,
- \c!header=,
- \c!text=,
- \c!footer=,
- \c!style=,
- \c!numbercommand=,
- \c!textcommand=,
- \c!ownnumber=\v!no,
- \c!number=\v!yes,
- \c!color=,
- \c!continue=\v!yes,
- \c!placehead=\v!yes,
- \c!resetnumber=\v!yes,
- \c!incrementnumber=\v!yes,
- \c!alternative=\@@koalternative,
- \c!command=\normalplacehead,
- \c!separator=\@@koseparator,
- \c!stopper=\@@kostopper,
- \c!align=\@@koalign,
- \c!aligntitle=\@@koaligntitle,
- \c!tolerance=\@@kotolerance,
- \c!indentnext=\@@koindentnext,
- \c!strut=\@@kostrut,
- \c!hang=\@@kohang,
- \c!file=,
- \c!expansion=,
- \c!grid=,
- \c!margintext=,
- \c!margin=\@@komargin,
- #2]%
- \ConvertToConstant\doifnot{#1}{\getvalue{\??ko#1\c!default}}
- {\doifsomething{\getvalue{\??ko#1\c!default}}
- {\copyparameters
- [\??ko#1][\??ko\getvalue{\??ko#1\c!default}]
- [\c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
- \c!header,\c!text,\c!footer,\c!separator,\c!stopper,\c!resetnumber,
- \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
- \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
- % new per 20/03/3002 (o-pbu-l) / was too confusing
- % \c!numberstyle,\c!textstyle,\c!expansion,
- % again too confusing
- \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
- \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]}}%
- \getparameters[\??ko#1][#2]%
- \doifsomething{\getvalue{\??ko#1\c!section}}
- {\doifelsemarking{#1}% \doifundefined{\??mk#1}
- {}% marking #1 already defined
- {\definemarking[#1]%
- \couplemarking[#1][\getvalue{\??ko#1\c!section}]%
- \definemarking[#1\v!number]%
- \couplemarking[#1\v!number][\getvalue{\??ko#1\c!section}]}}%
- \doifundefined{\??li#1}{\definelist[#1]}}
- {\ConvertToConstant\doifelse{#1}{#2}
- {\doifundefined{\??li#1}{\definelist[#1]}}
- {\copyparameters
- [\??ko#1][\??ko#2]
- [\c!level,\c!section,\c!coupling,\c!prefix,
- \c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
- \c!separator,\c!stopper,
- \c!header,\c!text,\c!footer,\c!resetnumber,
- \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
- \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
- % new per 20/03/3002 (o-pbu-l) / was too confusing
- % \c!numberstyle,\c!textstyle,\c!expansion,
- % again too confusing
- \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
- \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]%
- \getparameters[\??ko#1][\c!expansion=]% iig een value, rather fuzzy
- \definemarking[#1][#2]%
- \definemarking[#1\v!number][#2\v!number]%
- \doifundefined{\??li#1}{\definelist[#1][#2]}}}%
- \addtocommalist{#1}\@@kolist
- \setevalue{\??sk#1}{\getvalue{\??ko#1\c!coupling}}%
- \setevalue{\??by#1}{\getvalue{\??ko#1\c!section}}%
- \setevalue{\??by\v!by#1}{\getvalue{\??ko#1\c!section}}%
- \setvalue{#1}{\dodoubleempty\doconstructhead[#1]}}
-
-\def\dodefinehead[#1][#2]%
- {\doifelsenothing{#2}
- {% todo: message that it's an invalid definition
- \setvalue{#1}{\endgraf[#1]\kern.5em}}
- {\doifassignmentelse{#2}
- {\dododefinehead{#1}{#2}}
- {\doifdefined{\??ko#2\c!section}
- {\dododefinehead{#1}{#2}}}}}
-
-\def\definehead
- {\dodoubleemptywithset\dodefinehead}
-
-\def\doconstructhead[#1][#2]%
- {\dowithpargument{\dodoconstructhead{#1}[#2]}}
-
-\def\dosetuphead[#1][#2]%
- {\getparameters[\??ko#1][#2]%
- % The next check prevents hard to trace problems. I once
- % set \c!command to nothing and (quite natural) got the
- % wrong references etc. The whole bunch should be boxed!
- \expandafter\defconvertedcommand\expandafter\ascii\csname\??ko#1\c!command\endcsname
- \doifnothing\ascii{\setvalue{\??ko#1\c!command}{\normalplacehead}}}
-
-\def\setuphead
- {\dodoubleargumentwithset\dosetuphead}
-
-\def\dosetupheads[#1]%
- {\getparameters[\??ko][#1]%
- \doifelse{\@@kosectionnumber}\v!yes\sectionnumbertrue\sectionnumberfalse}
-
-\def\setupheads
- {\dosingleargument\dosetupheads}
-
-\def\systemsuppliedchapter {\getvalue{\v!chapter}}
-\def\systemsuppliedtitle {\getvalue{\v!title}}
-
-% a left over
-
-\def\complexbijlage[#1]#2%
- {\page[\v!right]
- \setuppagenumbering[\c!state=\v!stop]
- \systemsuppliedchapter[#1]{#2}
- \page[\v!right]
- \setuppagenumbering[\c!state=\v!start]
- \setuppagenumbering[\c!number=1]}
-
-\setvalue{\v!appendix}%
- {\complexorsimpleempty\bijlage}
-
-\setupheads
- [\c!alternative=\v!normal,
- \c!sectionnumber=\v!yes,
- \c!separator=.,
- \c!stopper=,
- \c!limittext=\v!yes,
- \c!align=,
- \c!aligntitle=,
- \c!tolerance=,
- \c!strut=,
- \c!indentnext=\v!no,
- \c!margin=\zeropoint,
- \c!hang=\v!none,
- \c!command=]
-
-\definesectionblock [\v!frontpart] [\v!frontmatter] [\c!number=\v!no]
-\definesectionblock [\v!bodypart] [\v!bodymatter] [\c!number=\v!yes]
-\definesectionblock [\v!appendix] [\v!appendices] [\c!number=\v!yes]
-\definesectionblock [\v!backpart] [\v!backmatter] [\c!number=\v!no]
-
-\definesection[\s!section-1] % part
-\definesection[\s!section-2] % chapter
-\definesection[\s!section-3] % section
-\definesection[\s!section-4] % subsection
-\definesection[\s!section-5] % subsubsection
-\definesection[\s!section-6] % subsubsubsection
-\definesection[\s!section-7] % subsubsubsubsection
-
-% \c!eigennummer ook hier?
-
-\definehead
- [\v!part]
- [\c!section=\s!section-1,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!chapter]
- [\c!section=\s!section-2,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!section]
- [\c!section=\s!section-3,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsection]
- [\c!section=\s!section-4,
- \c!default=\v!section,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsection]
- [\c!section=\s!section-5,
- \c!default=\v!subsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsubsection]
- [\c!section=\s!section-6,
- \c!default=\v!subsubsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubsection]
- [\c!section=\s!section-7,
- \c!default=\v!subsubsubsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!title]
- [\c!coupling=\v!chapter,
- \c!default=\v!chapter,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subject]
- [\c!coupling=\v!section,
- \c!default=\v!section,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubject]
- [\c!coupling=\v!subsection,
- \c!default=\v!subsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubject]
- [\c!coupling=\v!subsubsection,
- \c!default=\v!subsubsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubject]
- [\c!coupling=\v!subsubsubsection,
- \c!default=\v!subsubsubsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubsubject]
- [\c!coupling=\v!subsubsubsubsection,
- \c!default=\v!subsubsubsubsection,
- \c!incrementnumber=\v!no]
-
-\setupsection
- [\s!section-2]
- [\v!appendix\c!conversion=\v!Character,
- \c!previousnumber=\v!no]
-
-\setuphead
- [\v!part]
- [\c!placehead=\v!no]
-
-\setuphead
- [\v!chapter]
- [\v!appendix\c!label=\v!appendix,
- \v!bodypart\c!label=\v!chapter] % bijlageconversie=\Character
-
-\setuphead
- [\v!section]
- [\v!appendix\c!label=\v!section,
- \v!bodypart\c!label=\v!section] % bijlageconversie=\Character
-
-\setuphead
- [\v!subsection]
- [\v!appendix\c!label=\v!subsection,
- \v!bodypart\c!label=\v!subsection] % bijlageconversie=\Character
-
-\setuphead
- [\v!subsubsection]
- [\v!appendix\c!label=\v!subsubsection,
- \v!bodypart\c!label=\v!subsubsection] % bijlageconversie=\Character
-
-\setuphead
- [\v!part,\v!chapter]
- [%\c!align=,
- %\c!indentnext=\v!no,
- \c!continue=\v!no,
- \c!page=\v!right,
- \c!header=,
- \c!style=\tfc,
- \c!distance=.75em,
- \c!before={\blank[2*\v!big]},
- \c!after={\blank[2*\v!big]}]
-
-\setuphead
- [\v!section]
- [%\c!align=,
- %\c!indentnext=\v!no,
- \c!style=\tfa,
- \c!distance=.75em,
- \c!before={\blank[2*\v!big]},
- \c!after=\blank]
-
-\setuphead % nieuw
- [\v!subsection]
- [\c!page=]
-
-\definecombinedlist
- [\v!content]
- [\v!part,
- \v!chapter,
- \v!section,
- \v!subsection,
- \v!subsubsection,
- \v!subsubsubsection,
- \v!subsubsubsubsection]
- [\c!level=\v!subsubsubsubsection,
- \c!criterium=\v!local]
-
-\setuplist
- [\v!part]
- [\c!before={\blank\page[\v!preference]},
- \c!after=\blank,
- \c!label=\v!yes,
- \c!separator=:,
- \c!distance=1em]
-
-\setuplist
- [\v!chapter]
- [\c!before={\blank\page[\v!preference]},
- \c!after=]
-
-\setuplist [\v!part] [\c!width=0em]
-\setuplist [\v!chapter] [\c!width=2em]
-\setuplist [\v!section] [\c!width=3em]
-\setuplist [\v!subsection] [\c!width=4em]
-\setuplist [\v!subsubsection] [\c!width=5em]
-\setuplist [\v!subsubsubsection] [\c!width=6em]
-\setuplist [\v!subsubsubsubsection] [\c!width=7em]
-
-% hm
-
-\setuppagenumbering % na instellen hoofdteksten !
- [\c!alternative=\v!singlesided,
- \c!location={\v!header,\v!middle},
- \c!conversion=\v!numbers,
- \c!width=, % in geval van \v!marginedge
- \c!left=,
- \c!right=,
- \c!way=\v!by\v!part,
- \c!text=,
- \v!chapter\v!number=\v!no, % v
- \v!part\v!number=\v!yes, % v
- \c!numberseparator=--,
- \c!textseparator=\tfskip,
- \c!state=\v!start,
- \c!command=,
- \c!strut=\v!yes, % nieuw
- \c!style=, % \v!normal, % empty, otherwise conflict
- \c!color=]
-
-\protect \endinput
diff --git a/tex/context/base/core-sec.mkiv b/tex/context/base/core-sec.mkiv
deleted file mode 100644
index fdab75bc8..000000000
--- a/tex/context/base/core-sec.mkiv
+++ /dev/null
@@ -1,2621 +0,0 @@
-%D \module
-%D [ file=core-sec,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Sectioning,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% start-stop per section en dan combineren met sectieblok; in dat geval
-% eenvoudiger per-* acties
-
-% nummeren per sectieblok implementeren
-
-% this module needs a clean up, currently some manipulations
-% take place multiple times; also, some clever recursive level
-% thing makes more sense
-
-% in manual (zie prikkels) : tussen=\blanko is enige hook om
-% met kop-in-hoofd een spatiering af te dwingen
-
-\writestatus{loading}{Context Core Macros / Sectioning}
-
-\startmessages dutch library: structures
- title: structuur
- 1: begin van sectieblok --
- 2: eind van sectieblok --
-\stopmessages
-
-\startmessages english library: structures
- title: structure
- 1: begin of sectionblock --
- 2: end of sectionblock --
-\stopmessages
-
-\startmessages german library: structures
- title: struktur
- 1: Begin des Abschnittsblocks --
- 2: Ende des Abschnittsblocks --
-\stopmessages
-
-\startmessages czech library: structures
- title: struktury
- 1: zacatek oddilu (sekce) --
- 2: konec oddilu (sekce) --
-\stopmessages
-
-\startmessages italian library: structures
- title: struttura
- 1: inizio del blocco (sezione) --
- 2: fine del blocco (sezione) --
-\stopmessages
-
-\startmessages norwegian library: structures
- title: struktur
- 1: starten av blokk -- (seksjon)
- 2: slutten av blokk -- (seksjon)
-\stopmessages
-
-\startmessages romanian library: structures
- title: structuri
- 1: inceput de bloc sectiune --
- 2: sfarsit de bloc sectiune --
-\stopmessages
-
-\startmessages french library: structures
- title: structure
- 1: début de blocsection --
- 2: fin de blocsection --
-\stopmessages
-
-\unprotect
-
-% new and to be tested
-
-\unexpanded\def\separatorlist#1%
- {\ifx\sepnumber\undefined\def\sepnumber{0}\fi
- \increment\sepnumber
- \getfromcommacommand[#1][\sepnumber]%
- \ifx\commalistelement\empty
- \getcommalistsize[#1]%
- \def\sepnumber{\number\commalistsize}%
- \getfromcommacommand[#1][\sepnumber]%
- \fi
- \commalistelement}
-
-% \setuphead[section] [separator=\separatorlist{?,!,*}]
-% \setuphead[subsection][separator=\separatorlist{??,!!,**}]
-%
-% \let\spr\separatorlist % this will enable this feature
-%
-% \setuphead[section] [separator={?,!,*}]
-% \setuphead[subsection][separator={??,!!,**}]
-%
-% \setupheads[separator={A,B,C,D,E,F}]
-% \chapter{test}
-% \section{test} \subsection{test} \subsection{test}
-% \section{test} \subsection{test} \subsection{test}
-
-% from now on, internaly numbers are separated by a period
-% and postprocessed on demand; this will change to {} {} {}
-
-\def\numberseparator {.} % reasonable default
-\def\sectionseparator{-} % was : but is now -
-
-\def\@@filterfirstpart [#1--#2]{#1}
-\def\@@filtersecondpart [#1--#2]{#2}
-
-\def\@@filterblockpart [#1--#2--#3]{#1}
-\def\@@filternumberpart [#1--#2--#3]{#2}
-\def\@@filterpagepart [#1--#2--#3]{#3}
-\def\@@filterblocknumberpart[#1--#2--#3]{#1--#2}
-
-\def\@@filterheadpart[#1]{\@EA\@@dofilterheadpart\@EA[#1-0]}
-\def\@@filtertailpart[#1]{\@EA\@@dofiltertailpart\@EA[#1-0]}
-
-\def\@@dofilterheadpart[#1-#2]{#1}
-\def\@@dofiltertailpart[#1-#2]{#2}
-
-\def\@@filterlevelpart[#1--#2--#3]{\@@dofilterlevelpart[#2-0-0-0-0]}
-
-\def\@@dofilterlevelpart[#1-0-0-0-#2]{#1}
-
-\def\gobbleuntilrelax#1\relax{}
-
-\def\separatednumber #1{\doseparatednumber #1.\empty\relax}
-\def\removefirstprefix#1{\doremovefirstprefix#1.\empty\relax}
-\def\removeallprefixes#1{\doremoveallprefixes#1.\empty\relax}
-
-\def\doseparatednumber#1.#2%
- {#1%
- \ifx#2\empty
- \@EA\gobbleuntilrelax
- \else \numberseparator
- \@EA\doseparatednumber
- \fi#2}
-
-\def\doremoveallprefixes#1.#2%
- {\ifx#2\empty
- #1\@EA\gobbleuntilrelax
- \else
- \@EA\doremoveallprefixes
- \fi#2}
-
-\def\doremovefirstprefix#1.#2%
- {\ifx#2\empty
- #1\@EA\gobbleuntilrelax
- \else
- \@EA\noremovefirstprefix
- \fi#2}
-
-\def\noremovefirstprefix#1.\empty\relax
- {#1}
-
-% we need to expand in order to get something separatable
-
-\def\dohandleheadnumber#1%
- {\expanded{\separatednumber{#1}}}
-
-\def\dodochecknumber#1#2#3% will become ugly after speed up
- {\bgroup
- \doifinstringelse{.0}{.#2}
- {\doifnot{#3}\v!by
- {%\debuggerinfo\m!systems{number #1 #3 becomes \getnumbervariable{#1\c!way}}%
- \setevalue{\@@thenumber{#1}\c!way}{#3}% geen \xdef, gaat mis met \subpage
- \dochecknumber{#1}}} % tricky and ugly
- {\doifnotvalue{\@@thenumber{#1}\s!check}{#2}
- {% new, calculate accumulated number
- \scratchcounter\getvalue{\@@thenumber{#1}\c!n}\relax
- \advance\scratchcounter\countervalue{\@@thenumber{#1}}\relax
- \setxvalue{\@@thenumber{#1}\c!n}{\the\scratchcounter}%
- %
- \setcounter{\@@thenumber{#1}}{0\getvalue{\@@thenumber{#1}\c!start}}%
- \setxvalue{\@@thenumber{#1}\c!way\c!local}{\getvalue{\@@thenumber{#1}\c!way}}%
- \setxvalue{\@@thenumber{#1}\s!check}{#2}}}%
- \egroup}
-
-\def\dochecknumber#1%
- {\edef\currentsection{\csname\??by\csname\@@thenumber{#1}\c!way\endcsname\endcsname}%
- \ifx\currentsection\empty\else
- \dodochecknumber
- {#1}%
- {\csname\currentsection\c!number\endcsname}%
- {\v!by\previoussection\currentsection}%
- \fi}
-
-\def\checknumber[#1]%
- {\bgroup
- %\ifcase\blocklevel\else
- \ifdoingblocks
- \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
- \fi
- \dochecknumber{#1}%
- \egroup}
-
-\def\rawsectionnumber#1%
- {\countervalue{\??se#1}}
-
-\def\precedingseparator{\@@koseparator} % brrr
-
-\def\domakeprecedingsectionnumber[#1]% will become ugly after speed up
- {\bgroup % added
- \globallet\precedingsectionnumber\empty
- \ifsectionnumber
- \doifvalue{\??sb\@@sectionblock\c!number}\v!yes % added
- {\doifelsevalue{\@@thenumber{#1}\c!sectionnumber}\v!yes
- \donetrue\donefalse
- \doifvalue{\@@thenumber{#1}\c!sectionnumber}\v!number
- {\donetrue\let\@@sectionconversion\gobbleoneargument}%
- \ifdone
- \edef\currentsection
- {\getvalue{\??by\getvalue{\@@thenumber{#1}\c!way\c!local}}}%
- \doifnot\currentsection\zerosection
- {\doifnot{\@@sectionvalue\currentsection}{0}
- {\xdef\precedingsectionnumber
- {\getvalue{\currentsection\c!number}%
- \spr{\precedingseparator}}}}%
- \fi}%
- \fi
- \egroup}
-
-\def\makeprecedingsectionnumber[#1]%
- {\bgroup
- %\ifnum\blocklevel>0
- %\ifcase\blocklevel\else
- \ifdoingblocks
- \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
- \fi
- \domakeprecedingsectionnumber[#1]%
- \egroup}
-
-% \def\makesectionnumber[#1]%
-% {\makeprecedingsectionnumber[#1]%
-% \xdef\composedsectionnumber%
-% {\precedingsectionnumber\convertednumber[#1]}}%
-%
-% hack needed for chinese and oldstyle in normal tex, will change
-
-\def\makesectionnumber[#1]%
- {\bgroup
- \forceunexpanded % i don't like this hack
- \makeprecedingsectionnumber[#1]%
- \xdef\composedsectionnumber% was \xdef maar dat gaat fout met font switches
- {\precedingsectionnumber\convertednumber[#1]}%
- \egroup}
-
-% \def\preparethenumber#1#2#3% {\??id#1} \number \result
-% {\doifelsevaluenothing{#1\c!separator}
-% {\let\numberseparator\empty
-% \let#3#2}
-% {% was \unexpanded \edef, but we need it unexpanded !
-% \edef\numberseparator{\spr{\getvalue{#1\c!separator}}}%
-% \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
-% {\edef#3%
-% {\@EA\separatednumber\@EA{#2}%
-% }}%\stp{\getvalue{#1\c!stopper}}}}
-% {\edef#3%
-% {\@EA\separatednumber\@EA{#2}%
-% \spr{\getvalue{#1\c!separator}}%
-% \getvalue{#1\c!suffix}%
-% \stp{\getvalue{#1\c!stopper}}}}}}
-%
-% some day we do a real cleanup
-
-\def\analyzenumber#1#2#3% {\??id#1} \(precedingsection)number \result
- {% was \unexpanded \edef, but we need it unexpanded !
- \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
- {\let \numbersuffix \empty}
- {\edef\numbersuffix{\spr{\getvalue{#1\c!suffix}}}}%
- \doifelsenothing{\executeifdefined{#1\c!stopper}\empty}
- {\let \numberstopper \empty}
- {\edef\numberstopper{\spr{\getvalue{#1\c!stopper}}}}%
- \doifelsenothing{\executeifdefined{#1\c!separator}\empty}
- {\let \numberseparator \empty}
- {\edef\numberseparator{\spr{\getvalue{#1\c!separator}}}}%
- \let\numberprefix\empty}
-
-\def\preparefullnumber#1#2#3% {\??id#1} \(precedingsection)number \result
- {\analyzenumber{#1}#2#3%
- \ifx\numberseparator\empty
- \edef\numberprefix{#2}%
- \else
- \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
- \fi
- \ifx\numbersuffix\empty
- \ifx\numberprefix\empty
- \let #3\empty
- \else
- \edef#3{\numberprefix\numberstopper}%
- \fi
- \else
- \ifx\numberprefix\empty
- \edef#3{\numbersuffix\numberstopper}%
- \else
- \edef#3{\numberprefix\numberseparator\numbersuffix\numberstopper}%
- \fi
- \fi}
-
-\def\prepareprefixnumber#1#2#3% {\??id#1} \number \result
- {\analyzenumber{#1}#2#3%
- \ifx\numberseparator\empty
- \edef\numberprefix{#2}%
- \else
- \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
- \fi
- \let#3\numberprefix}
-
-\def\sectionnumberonly[#1]%
- {\makesectionnumber[#1]%
- \composedsectionnumber}
-
-% sectioning
-
-\newcount\nofsections
-
-\let\zerosection \v!text
-\let\firstsection\empty
-\let\lastsection \empty
-\let\@@sectie \empty
-\let\@@koppeling \empty
-
-\makecounter{\??se\v!text}
-
-\letvalueempty{\??se\v!text\c!before}
-\letvalueempty{\??se\v!text\c!after }
-
-\setvalue {\v!text\c!number}{0}
-\letvalueempty{\v!text\s!format}
-
-\letvalueempty{\??sk\v!text}
-\letvalueempty{\??sk }
-
-\letvalue{\??by }\v!text
-\letvalue{\??by\v!text }\v!text
-\letvalue{\??by\v!all }\v!text
-\letvalue{\??by\v!by }\v!text
-\letvalue{\??by\v!by\v!text}\v!text
-\letvalue{\??by\v!by\v!all }\v!text
-\letvalue{\??by\v!by\v!page}\v!text % see footnotes
-
-\def\sectionofhead#1{\executeifdefined{\??ko#1\c!section}\s!unknown}
-
-\def\setupsection
- {\dotripleempty\dosetupsection}
-
-\def\dosetupsection[#1]%
- {\doifdefinedelse{\??se#1}
- {\dodosetupsection[#1]}%
- {\dodosetupsection[\sectionofhead{#1}]}}
-
-\def\dodosetupsection[#1][#2][#3]%
- {\doifdefined{\??se#1}
- {\ifthirdargument
- \getparameters[\??se#1#2][#3]%
- \else
- \getparameters[\??se#1][#2]%
- \fi
- \doifelsevalue{\??se#1\c!previousnumber}\v!yes
- {\setvalue{#1\c!number}{\@@longsectionnumber {#1}}}
- {\setvalue{#1\c!number}{\@@shortsectionnumber{#1}}}}}
-
-\def\docouplemarking[#1][#2]%
- {\doifdefinedelse{\??ko#2\c!section}
- {\docouplemarking[#1][\getvalue{\??ko#2\c!section}]}
- {\def\donexttrackcommando##1%
- {\edef\coupledmarkings{\getvalue{\??se##1\c!marking}}%
- \doifelse{##1}{#2}
- {\addtocommalist{#1}\coupledmarkings}
- {\removefromcommalist{#1}\coupledmarkings}%
- \setevalue{\??se##1\c!marking}{\coupledmarkings}%
- \donexttracklevel{##1}}%
- \donexttracklevel{\zerosection}}} % \firstsection
-
-\def\couplemarking
- {\dodoubleargument\docouplemarking}
-
-\def\decouplemarking[#1]%
- {\couplemarking[#1][]}
-
-\def\definesection[#1]%
- {\doifundefined{\??se#1}
- {\doifelsenothing\firstsection
- {\def\firstsection{#1}%
- \setevalue{\??se#1\c!before}{\v!text}%
- \setevalue{\??se\v!text\c!after}{#1}}
- {\setevalue{\??se\commalistelement\c!after}{#1}% commalistelement ?
- \setevalue{\??se#1\c!before}{\lastsection}%
- \setevalue{\??se\lastsection\c!after}{#1}}%
- \advance\nofsections \plusone
- \setevalue{\??se#1\c!level}{\the\nofsections}%
- \letvalue{\??se#1\c!after}\empty
- \setvalue{\e!next#1}{\@@nextsectionnumber{#1}}%
- \setvalue{#1\c!number}{\@@longsectionnumber{#1}}%
- \setvalue{#1\s!format}{\@@longformatnumber{#1}}%
- \setevalue{\??by#1}{#1}%
- \setevalue{\??by\v!by#1}{#1}%
- \makecounter{\??se#1}%
- \makecounter{\??se\v!last#1}% GB
- \edef\lastsection{#1}%
- \setvalue{\??sk#1}{#1}%
- \letvalue{\??se#1\c!marking}\empty
- \setupsection[#1][\c!previousnumber=\v!yes]}}%
-
-\def\previoussection#1{\csname\??se#1\c!before\endcsname}
-\def\nextsection #1{\csname\??se#1\c!after \endcsname}
-
-\let\preservedsection\v!unknown % \def\preservedsection{\firstsection}
-
-\def\checkpreservevalueafter#1% GB
- {\ifnum\getvalue{\??se#1\c!level}<\nofsections
- \edef\preservedsection{\getvalue{\??se#1\c!after}}%
- \ifconditional\@@resetsubheadnumbers
- \setcounter{\??se\v!last\preservedsection}\zerocount % {0}%
- \else
- \setcounter{\??se\v!last\preservedsection}{\countervalue{\??se\preservedsection}}%
- \fi
- \fi}
-
-\def\@@setsectionnumber#1#2%
- {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
- \setcounter{\??se#1}{#2}%
- \checkpreservevalueafter{#1}% GB
- \resetsectioncounters{#1}%
- \checkpagecounter}
-
-\def\@@nextsectionnumber#1% patched by GB
- {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
- \ifnum\countervalue{\??se\v!last#1}>\zerocount
- \setcounter{\??se#1}{\countervalue{\??se\v!last#1}}%
- \setcounter{\??se\v!last#1}\zerocount % {0}%
- \fi
- \pluscounter{\??se#1}%
- \checkpreservevalueafter{#1}%
- \resetsectioncounters{#1}%
- \checkpagecounter}
-
-\def\@@sectionvalue#1% % nog niet overal doorgevoerd
- {\countervalue{\??se#1}} % zoeken op \??se
-
-% suited for chinese too:
-
-\def\@@sectionconversion#1#2% a doublure with \@@shortsectionnumber
- {\ifnum#2=0 0\else % else troubles with \uchar
- \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
- \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
- #2%
- \else
- \convertnumber{\getvalue{\??se#1\c!conversion}}{#2}%
- \fi
- \else
- \convertnumber{\getvalue{\??se#1\@@sectionblock\c!conversion}}{#2}%
- \fi
- \fi}
-
-% \def\@@sectionlevel#1%
-% {\ifundefined{\??se#1\c!level}0\else\getvalue{\??se#1\c!level}\fi}
-
-\def\@@sectionlevel#1%
- {\executeifdefined{\??se#1\c!level}0}
-
-% Omdat een markering kan worden herdefinieerd moeten we
-% eerst testen of er wel een keten||afhankelijkheid is.
-
-\def\resetsectionmarks#1% can invoke a break
- {\ifundefined{\??se#1}%
- \fastresetmarker[\mainmarking{#1}]% % redundant \mainmarking
- \else
- \let\donexttrackcommando\doresetsectionmarks
- \donexttracklevel{#1}%
- \fi}
-
-\def\doresetsectionmarks#1%
- {\ifundefined{\??se#1\c!marking}\else % skip zero level
- \fastresetmarkerlist[\csname\??se#1\c!marking\endcsname]%
- \fi
- \donexttracklevel{#1}}
-
-% I'm not sure if the next one is better:
-%
-% \def\doresetsectionmarks#1%
-% {\ifundefined{\??se#1\c!markering}% skip zero level
-% \donexttracklevel{#1}%
-% \else
-% \fastresetmarkerlist[\csname\??se#1\c!markering\endcsname]%
-% \fi}
-%
-% and indeed, it isn't, actually, it does not work at all, so let's drop it.
-
-% packaged:
-%
-% \def\resetsectioncounters#1%
-% {\def\donexttrackcommando##1%
-% {\resetcounter{\??se##1}%
-% \donexttracklevel{##1}}%
-% \donexttracklevel{#1}}
-%
-% nicer
-%
-% \def\doresetsectioncounters#1%
-% {\resetcounter{\??se#1}%
-% \donexttracklevel{#1}}
-%
-% obey eigennummer
-
-\def\doresetsectioncounters#1%
- {\resetcounter{\??se#1}%
- \letgvalue{\??se#1\c!ownnumber}\relax
- \donexttracklevel{#1}}
-
-\def\resetsectioncounters % #1
- {\let\donexttrackcommando\doresetsectioncounters
- \donexttracklevel} % #1
-
-% bij checken kan geen prefix worden bekeken, anders vallen
-% er titels buiten de inhoudsopgave
-
-% evt ook level gaan opslaan tbv snelle selectie
-
-% \def\makesectionformat
-% {\edef\sectionformat
-% {\@@sectiontype\sectionseparator
-% \csname\lastsection\s!format\endcsname}}
-
-\unprotected \def\makesectionformat % we don't want eigennummers here
- {\pushmacro\@@shortsectionnumber
- \let\@@shortsectionnumber\@@sectionvalue
- \edef\sectionformat
- {\@@sectiontype\sectionseparator
- \csname\lastsection\s!format\endcsname}%
- \popmacro\@@shortsectionnumber}
-
-\def\dobacktracklevel#1%
- {\doifnot{\previoussection{#1}}\zerosection
- {\dobacktrackcommando{\previoussection{#1}}}}
-
-\def\donexttracklevel#1%
- {\doifnot{#1}\lastsection
- {\donexttrackcommando{\nextsection{#1}}}}
-
-\chardef\alltoclevels\zerocount
-
-\let\currentlevel\empty
-
-\def\dosetcurrentlevel#1%
- {\global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\lastsection\s!format}}}
-
-\def\dosetpreviouslevel#1%
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty
- \def\dobacktrackcommando##1%
- {\ifnum\countervalue{\??se##1}>\zerocount
- \global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\previoussection{##1}\s!format}}%
- \else
- \dobacktracklevel{##1}%
- \fi}%
- \dobacktrackcommando\lastsection}
-
-\def\dosettextlevel#1%
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty}
-
-\def\dosetotherlevel#1%
- {\doifdefinedelse{\??ko#1\c!section} % beter alteratief: ook
- {\edef\@@sectie{\getvalue{\??ko#1\c!section}}} % hoofdstuk\c!format
- {\edef\@@sectie{#1}}%
- \doifdefinedelse{\??se\@@sectie}
- {\global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{\@@sectie\s!format}}}
- {\global\chardef\alltoclevels\plusone
- \globallet\currentlevel\empty
- \def\dobacktrackcommando##1%
- {\@EA\ifx\csname\??se##1\c!start\endcsname\relax
- \dobacktracklevel{##1}%
- \else
- \ifnum\countervalue{\??se##1}>\zerocount
- \global\chardef\alltoclevels\zerocount
- \xdef\currentlevel{\getvalue{##1\s!format}}%
- \else
- \dobacktracklevel{##1}%
- \fi
- \fi}%
- \dobacktrackcommando\lastsection}}
-
-% \def\ignoresectionconversion % brrr
-% {\let\@@sectionconversion\secondoftwoarguments}
-
-% todo: criterium=appendix|frontmatter|....
-
-\def\dosetfilterlevel#1#2% beware: this one is \let
- {\bgroup
- \let\@@shortsectionnumber\@@sectionvalue
-% \ignoresectionconversion
- \edef\askedlevel{#1}%
- \edef\askedfilter{#2}%
- \ifx\askedlevel\v!current
- \dosetcurrentlevel\askedlevel
- \else\ifx\askedlevel\v!previous
- \dosetpreviouslevel\askedlevel
- \else\ifx\askedlevel\v!all
- \global\chardef\alltoclevels\plusone
- \else\ifx\askedlevel\v!text
- \global\chardef\alltoclevels\plusone
- \else
- \edef\byaskedlevel{\csname\??by\askedlevel\endcsname}%
- \ifx\byaskedlevel\v!text
- \dosettextlevel\askedlevel
- \else
- \dosetotherlevel\askedlevel
- \fi
- \fi\fi\fi\fi
- % experiment
- \ifx\askedfilter\empty \else
- \xdef\currentlevel{\currentlevel\sectionseparator\askedfilter}%
- \fi
- \egroup}
-
-% \def\dontsetfilterlevel#1#2%
-% {\let\currentlevel\somesavedlevel
-% \chardef\alltoclevels\zerocount}
-
-\def\dontsetfilterlevel#1#2%
- {\let\currentlevel\somesavedlevel
- \let\@@sectiontype\@@tocsectiontype
- \chardef\alltoclevels\zerocount}
-
-\def\honorlocalfilterlevel % local lists will be real local
- {\let\dosetfilterlevel\dontsetfilterlevel}
-
-% cleaner
-%
-% \def\doifnextlevelelse[#1::#2]#3#4%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}{#4}{#3}}
-% {#4}}
-% {#4}%
-% \else
-% #3%
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]#3#4%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}{#3}{#4}}
-% {#4}%
-% \else
-% #3%
-% \fi}
-%
-% faster
-%
-% \def\doifnextlevelelse[#1::#2]%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
-% \donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]%
-% {\ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% meaner
-%
-% \setuplist
-% [chapter]
-% [after={\startcolumns\placelist[section]\stopcolumns}]
-
-\def\somesavedlevel{0}
-
-% \def\dosavesomelevel[#1:0:0:0:#2]%
-% {\def\somesavedlevel{:#1}}
-
-% \def\doifnextlevelelse[#1::#2]%
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}
-% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
-% \donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1::#2]%
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \doifelse{\@@sectiontype}{#1}
-% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
-% \donefalse
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% again faster:
-
-% \def\doifnextlevelelse[#1::#2]% beware: this one is \let
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=#1
-% \def\levelstring{=:#2:}%
-% \doifincsnameelse{=\currentlevel:}\levelstring
-% {\doifincsnameelse{=\currentlevel:0}\levelstring\donefalse\donetrue}
-% \donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-%\def\doifprevlevelelse[#1::#2]% beware: this one is \let
-% {\dosavesomelevel[#2:0:0:0:0]%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=#1
-% \doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \let\doiftoclevelelse\doifnextlevelelse
-% \let\doifreglevelelse\doifprevlevelelse
-% \let\doifblklevelelse\doifprevlevelelse
-%
-% we want to be able to overload them globally
-
-% This will be reimplemented some day soon
-%
-% {nn}{xx}{yy}
-%
-% -> \scan{..}{..}{0} met 0 als sentinel
-
-% still not perfect
-%
-% \def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
-% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
-% \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
-% \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
-% {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
-% \donefalse
-% \donetrue}
-% \donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-%
-% \def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
-% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
-% \ifcase\alltoclevels
-% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
-% \doifinstringelse
-% {=\currentlevel\sectionseparator}
-% {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
-% \donetrue\donefalse
-% \else
-% \donefalse
-% \fi
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \expandafter\firstoftwoarguments
-% \else
-% \expandafter\secondoftwoarguments
-% \fi}
-
-\def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
- {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
- \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
- \ifcase\alltoclevels
- \ifnum\@@sectiontype=\@@tocsectiontype\relax
- \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
- \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
- {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
- \donefalse
- \donetrue}
- \donefalse
- \else
- \donefalse
- \fi
- \else
- \donetrue
- \fi
- \ifdone
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
- {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
- \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
- \ifcase\alltoclevels
- \ifnum\@@sectiontype=\@@tocsectiontype\relax
- \doifinstringelse
- {=\currentlevel\sectionseparator}
- {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
- \donetrue\donefalse
- \else
- \donefalse
- \fi
- \else
- \donetrue
- \fi
- \ifdone
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-% we need to cover the special case of nested lists in section blocks
-%
-% \starttext
-%
-% \def\ChapterEntry#1#2#3%
-% {chapter : \hbox to \hsize{\strut\bf#2\hss#3}\endgraf\placelist[section]}
-%
-% \startfrontmatter % optional
-% \placelist[chapter][alternative=command,command=\ChapterEntry,criterium=text] \page
-% \stopfrontmatter % optional
-%
-% \startbodymatter % optional
-% \chapter{first} \section{one} test \section{two} test \page
-% \chapter{second} \section{alpha} test \section{beta} test \page
-% \stopbodymatter % optional
-%
-% \stoptext
-
-\def\doiftoclevelelse{\doifnextlevelelse}
-\def\doifreglevelelse{\doifprevlevelelse}
-\def\doifblklevelelse{\doifprevlevelelse}
-
-\def\@@longformatnumber#1%
- {\csname\previoussection{#1}\s!format\endcsname
- \sectionseparator
- \@@shortsectionnumber{#1}}
-
-% \def\@@longsectionnumber#1%
-% {\ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
-% \csname\previoussection{#1}\c!nummer\endcsname.%
-% \fi
-% \@@shortsectionnumber{#1}}
-
-\def\@@longsectionnumber#1%
- {\ifreversesectionnumbers
- \@@shortsectionnumber{#1}%
- \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
- .\csname\previoussection{#1}\c!number\endcsname
- \fi
- \else
- \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
- \csname\previoussection{#1}\c!number\endcsname.%
- \fi
- \@@shortsectionnumber{#1}%
- \fi}
-
-% suited for chinese too:
-%
-% \def\@@shortsectionnumber#1%
-% {\@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
-% \@@sectionvalue{#1}%
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi}
-%
-% obey eigennummer
-%
-% \def\@@shortsectionnumber#1%
-% {\@EA\ifx\csname\??se#1\c!eigennummer\endcsname\relax
-% \@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
-% \@EA\ifx\csname\??se#1\c!conversie\endcsname\relax
-% \@@sectionvalue{#1}%
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi
-% \else
-% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
-% \fi
-% \else
-% \csname\??se#1\c!eigennummer\endcsname
-% \fi}
-
-\def\@@shortsectionnumber#1%
- {\@EA\ifx\csname\??se#1\c!ownnumber\endcsname\relax
- \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
- \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
- \@@sectionvalue{#1}%
- \else
- \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
- \fi
- \else
- \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
- \fi
- \else
- \csname\??se#1\c!ownnumber\endcsname
- \fi}
-
-\def\dosetlocalsectionblock#1#2#3% new \edef's
- {\edef\@@sectiontype {#1}%
- \edef\@@sectionblock {#2}%
- \edef\@@sectionblocks{#3}}
-
-% beware, the \resetsectionmarks generates some nodes that
-% will result in an additional last page, which needs to be
-% captured at the end
-
-% \def\doaroundsectionblock#1%
-% {\doifvaluesomething{\??sb#1\c!page}
-% {\ExpandFirstAfter\page[\getvalue{\??sb#1\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection}
-
-% \def\dostartsectionblock#1#2%
-% {\begingroup
-% \doaroundsectionblock{#1}% % going to a new page or so
-% \getvalue{\??sb#1}% % set name of section block
-% \getsectionblockenvironment{#1}% % special settings, grouped
-% %\expandafter\csname#2true\endcsname % obsolete
-% \setsystemmode{#1}% % can be used in conditionals
-% \getvalue{\??sb\@@sectionblock\c!before}% this one is not to be moved!
-% \showmessage\m!structures1\@@sectionblocks}
-
-% \def\dostopsectionblock
-% {\showmessage\m!structures2\@@sectionblocks
-% \getvalue{\??sb\@@sectionblock\c!after}% don't move
-% \doaroundsectionblock\@@sectionblock
-% \endgroup}
-
-\def\doaroundsectionblock
- {\doifvaluesomething{\??sb\@@sectionblock\c!page}
- {\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
- \resetsectioncounters\zerosection % was firstsection
- \resetsectionmarks\zerosection}
-
-\def\dostartsectionblock#1#2%
- {\begingroup
- \getvalue{\??sb#1}%
- \doaroundsectionblock
-% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection
- \getsectionblockenvironment\@@sectionblock
- \setsystemmode\@@sectionblock
- \getvalue{\??sb\@@sectionblock\c!before}%
- \showmessage\m!structures1\@@sectionblocks}
-
-\def\dostopsectionblock
- {\showmessage\m!structures2\@@sectionblocks
- \getvalue{\??sb\@@sectionblock\c!after}% don't move
- \doaroundsectionblock
-% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
-% \resetsectioncounters\zerosection % was firstsection
-% \resetsectionmarks\zerosection
- \endgroup}
-
-\def\dosetupsectionblock[#1]% [#2]
- {\getparameters[\??sb#1]}
-
-\def\setupsectionblock
- {\dodoubleargument\dosetupsectionblock}
-
-\long\def\setsectionblockenvironment#1#2%
- {\long\setvalue{\??sb\s!do#1}{\do{#2}}}
-
-\def\getsectionblockenvironment#1%
- {\let\do\firstofoneargument\getvalue{\??sb\s!do#1}}
-
-\setvalue{\e!start\v!sectionblockenvironment}%
- {\dosingleargument\dostartsectionblockenvironment}
-
-\def\dostartsectionblockenvironment[#1]% evt \pushendofline \popendofline
- {\long\def\do##1##2{\setsectionblockenvironment{#1}{##1##2}}%
- \grabuntil{\e!stop\v!sectionblockenvironment}{\getvalue{\??sb\s!do#1}}}
-
-%D \starttyping
-%D \startsectionblockenvironment[frontpart]
-%D \setuppagenumbering[conversion=romannumerals]
-%D \stopsectionblockenvironment
-%D
-%D \startsectionblockenvironment[bodypart]
-%D \setuppagenumber[number=1]
-%D \stopsectionblockenvironment
-%D
-%D \startsectionblockenvironment[frontpart]
-%D \setuppagenumbering[conversion=character]
-%D \stopsectionblockenvironment
-%D
-%D \starttext
-%D \startfrontmatter \chapter{test} \stopfrontmatter
-%D \startbodymatter \chapter{test} \stopbodymatter
-%D \startappendices \chapter{test} \stopappendices
-%D \stoptext
-%D \stoptyping
-
-% We used to use the first char as id, but a counter is
-% better, because in english we get a name clash.
-
-\newcounter\currentsectionblock
-
-\def\currentsection{\@@sectionblock}
-
-\def\dodefinesectionblock[#1][#2][#3]%
- {\getparameters
- [\??sb#1]
- [\c!number=\v!yes,
- \c!page=\v!right, % anders worden marks te vroeg gereset !
- %\c!before=,
- %\c!after=,
- #3]%
- \expandafter\newif\csname if#2\endcsname % better a mode
- \doglobal\increment\currentsectionblock
- \setsectionblockenvironment{#1}{}%
- \setevalue{\??sb #1}{\noexpand\dosetlocalsectionblock{\currentsectionblock}{#1}{#2}}%
- \setvalue {\e!start#2}{\dostartsectionblock{#1}{#2}}%
- \setvalue {\e!stop #2}{\dostopsectionblock}}
-
-\def\definesectionblock
- {\dotripleargument\dodefinesectionblock}
-
-\def\sectionblocklabel#1#2%
- {\@EA\ifx\csname\??ko#1\@@sectionblock\c!label\endcsname\relax
- \labeltexts{#1}{#2}%
- \else
- \labeltexts{\getvalue{\??ko#1\@@sectionblock\c!label}}{#2}%
- \fi}
-
-\dosetlocalsectionblock{2}{\v!bodypart}{\v!bodymatter} % hm, dirty
-
-\def\setsectiontype[#1]%
- {\getvalue{\??sb#1}}
-
-\def\writesection#1#2#3% #3 -> \asciititle
- {\bgroup
- \edef\!!stringa{#1}%
- \@EA\writestatus\@EA
- {\!!stringa}
- {\ifsectionnumber#2\else(#2)\fi\normalspace\asciititle}%
- \egroup}
-
-\def\@@kolevel{1} \def\headlevel{\@@kolevel}
-
-\def\dohandlepagebreakAA#1%
- {\ifnum\lastpenalty>0
- \global\paginageblokkeerdtrue
- \fi}
-
-% \setuphead[section][aligntitle=float] % permits title next to sidefloat
-%
-% \placefigure[left]{}{} \section{\dorecurse{10}{bagger }} \input tufte
-
-% \def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
-% {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
-% \getvalue{\??ko#1\c!before}%
-% % \whitespace vervangen door \noindent elders
-% \relax
-% \ifpaginageblokkeerd
-% \global\paginageblokkeerdfalse
-% \else
-% \!!countb\getvalue{\??se\@@sectie\c!level}\relax
-% \ifnum\!!countb>\@@kolevel\relax
-% \!!counta20000
-% \multiply\!!countb 500
-% \advance\!!counta \!!countb
-% \dosomebreak{\penalty\!!counta}%
-% \else
-% \dosomebreak\allowbreak
-% \fi
-% \fi
-% \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
-% \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
-
-\chardef\somebreakmethod\plusone
-
-\def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
- {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
- \getvalue{\??ko#1\c!before}%
- % \whitespace vervangen door \noindent elders
- \relax
- \ifpaginageblokkeerd
- \global\paginageblokkeerdfalse
- \else
- \ifcase\somebreakmethod
- % 0 = nothing
- \or
- % 1 = old weighted version
- \!!countb\getvalue{\??se\@@sectie\c!level}\relax
- \ifnum\!!countb>\@@kolevel\relax
- \!!counta20000
- \multiply\!!countb 500
- \advance\!!counta \!!countb
- \dosomebreak{\penalty\!!counta}%
- \else
- \dosomebreak\allowbreak % brr
- \fi
- \or
- % 2 = strict version
- \dosomebreak{\penalty\maxdimen}%
- \else
- % nothing
- \fi
- \fi
- \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
- \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
-
-\def\dohandlepagebreakBB#1#2#3%
- {%\doifinsetelse{\getvalue{\??tk#2\c!state}}{\v!normal,\v!start}
- \doifelselayouttextline{#2}
- {\doifvaluesomething{\??ko#1#3}
- {\setuplayouttext[#2][\c!state=\getvalue{\??ko#1#3}]}}
- \donothing}
-
-\def\dohandlepagebreakB#1%
- {\doifvaluesomething{\??ko#1\c!page}
- {\def\resetcurrentsectionmarks% toegevoegd, zie \page
- {\resetsectionmarks{\previoussection\@@sectie}}%
- \page[\getvalue{\??ko#1\c!page}]%
- \dohandlepagebreakBB{#1}\v!header\c!header
- \dohandlepagebreakBB{#1}\v!text \c!text
- \dohandlepagebreakBB{#1}\v!footer\c!footer}}
-
-\def\dohandlepagebreakX#1% zie doordefinieren / boven
- {\bgroup
- \!!countb\@@kolevel
- \advance\!!countb #1
- \multiply\!!countb 500
- \!!counta20000
- \advance\!!counta \!!countb
- \dosomebreak{\penalty\!!counta}%
- \egroup}
-
-\newconditional\ignorehandlepagebreak
-
-\def\handlepagebreak#1%
- {\ifconditional\ignorehandlepagebreak
- \setfalse\ignorehandlepagebreak
- \else
- \dohandlepagebreakAA{#1}%
- \ifnum\countervalue{\??se\previoussection\@@sectie}>\zerocount\relax
- \ifnum\countervalue{\??se\@@sectie}>\zerocount
- \dohandlepagebreakB{#1}%
- \else
- \doifnotvalue{\??ko#1\c!continue}\v!yes{\dohandlepagebreakB{#1}}%
- \fi
- \else
- \dohandlepagebreakB{#1}%
- \fi
- \dohandlepagebreakAB{#1}%
- \fi}
-
-\def\handlenopagebreak#1%
- {\ifconditional\ignorehandlepagebreak
- \setfalse\ignorehandlepagebreak
- \else
- \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}%
- \nobreak
- \fi}
-
-\def\localheadheight {\strutht}
-\def\localheaddepth {\strutdp}
-\def\localheadlineheight{\lineheight}
-
-\def\dolocalheadsetup#1% koppeling met standaard kopcommando / engels
- {\forgetall % traag dus ...
- \doifvaluesomething{\??ko#1\c!align} % wordt al expanded in spa
- {\expanded{\setupalign[\getvalue{\??ko#1\c!align}]}}%
- \doifvaluesomething{\??ko#1\c!tolerance} % wordt al expanded in spa
- {\expanded{\setuptolerance[\getvalue{\??ko#1\c!tolerance}]}}%
- \doifvalue{\??ko#1\c!strut}\v!no % wordt al expanded in spa
- {\setnostrut}% new
- \def\\{\crlf\strut\ignorespaces}}
-
-\def\localkopsetup{\localheadsetup} % kan tzt weg
-
-% todo: make them conditionals:
-
-\newif\ifincrementnumber
-\newif\ifreversesectionnumbers % todo: key/val
-\newif\ifsectionnumber \sectionnumbertrue
-\newif\ifdisplaysectionhead \displaysectionheadtrue
-\newif\ifplacehead
-\newif\ifemptyhead
-\newif\ifwritetolist
-\newif\ifheadnumber
-\newif\ifheadnumbercontent % niet meer wijzigen / wordt mode
-\newif\ifheadprefix
-\newif\ifsomeheadconversion
-
-% new
-
-\newconditional\@@resetsubheadnumbers
-
-\def\setsectieenkoppeling#1%
- {\edef\@@koppeling{\getvalue{\??ko#1\c!coupling}}%
- \edef\@@sectie{\getvalue{\??ko#1\c!section}}%
- \doifnothing\@@koppeling
- {\edef\@@koppeling{#1}}%
- \doifnothing\@@sectie
- {\edef\@@sectie{\getvalue{\??ko\@@koppeling\c!section}}}}
-
-% \handlepagebreak komt het eerst omdat eventueel
-% subpaginanummers moeten worden afgehandeld. Vervolgens
-% worden de nummers opgehoogd en referenties geset, dan
-% volgt de kop en tot slot de worden de marks en de prefix
-% geset.
-
-% \hoofdstuk {tekst}
-% \hoofdstuk tekst
-% \hoofdstuk
-
-\let\finalsectionnumber\empty
-
-\def\dofinalsectionnumber
- {\ifundefined{\@@sectie\c!number}\else
- \ifsomeheadconversion
- \@@shortsectionnumber\@@sectie
- \else
- \getvalue{\@@sectie\c!number}%
- \fi
- \fi}
-
-\def\findsectionnumber#1#2#3% class file title / uti seperator --
- {\begingroup
- \setsectieenkoppeling{#1}%
- \xdef\foundsectionnumber{1}%
- \def\dolistelement##1##2##3##4##5##6%
- {\doif{##1}{#1}
- {\ConvertConstantAfter\doif{##4}{#3}
- {\global\utilitydonetrue
- \scratchcounter=0\getvalue{\??se\@@sectie\c!level}%
- %
- %\advance\scratchcounter 2
- %\@EA\def\@EA\do\@EA####\@EA1\sectionseparator####2]%
- % {\advance\scratchcounter -1
- % \ifcase\scratchcounter
- % \xdef\foundsectionnumber{####1}%
- % \else
- % \do####2]%
- % \fi}%
- %\do##5]}}}%
- %
- \def\do####1\relax % :/- clean
- {\advance\scratchcounter \minusone
- \ifcase\scratchcounter
- \xdef\foundsectionnumber{\@@filterheadpart[####1]}%
- \else
- \@EAEAEA\do\@@filtertailpart[####1]\relax
- \fi}%
- \@EA\do\@@filternumberpart[##5]\relax}}}%
- \setbox0\vbox
- {\doutilities{#1}{#2}{#1}\relax\relax}%
- \endgroup
- \doifnumberelse\foundsectionnumber
- {\doif\foundsectionnumber\!!zerocount
- {\globallet\foundsectionnumber\!!plusone}}
- {\globallet\foundsectionnumber\!!plusone}% an appendix or so
- \setupheadnumber[#1][\foundsectionnumber]%
- \setupheadnumber[#1][-1]}
-
-% deal with eigennummer
-
-\def\setsomeheadconversion#1#2%
- {\someheadconversionfalse
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\setgvalue{\??se\@@sectie\c!ownnumber}{#2}%
- \def\someheadconversion{#2}}
- {\letgvalue{\??se\@@sectie\c!ownnumber}\relax
- \determineheadnumber[#1]%
- \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\relax
- \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\relax
- \def\someheadconversion{#2}%
- \else
- \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\empty
- \def\someheadconversion{#2}%
- \else
- \someheadconversiontrue
- \def\someheadconversion%
- {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\c!headconversion}}{#2}}%
- \fi
- \fi
- \else
- \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\empty
- \def\someheadconversion{#2}%
- \else
- \someheadconversiontrue
- \def\someheadconversion%
- {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\@@sectionblock\c!headconversion}}{#2}}%
- \fi
- \fi}}
-
-\def\writtenfullsectionnumber
- {\string\fullsectionnumber}
-
-\def\ignoredfullsectionnumber#1#2#3%
- {#3}
-
-\let\storedfullsectionnumber\relax
-
-\def\expandablefullsectionnumber#1#2#3%
- {\convertnumber{#2}{#3}}
-
-\unexpanded\def\naturalfullsectionnumber#1#2#3%
- {\sectionblocklabel{#1}{\convertnumber{#2}{#3}}}
-
-\unexpanded\def\limitedfullsectionnumber#1#2#3%
- {\convertnumber{#2}{#3}}
-
-\def\setfullsectionnumber#1%
- {\doifelsevalue{#1\c!headconversion}\v!yes
- {\doifelsevalue{#1\c!headlabel}\v!yes
- {\let\fullsectionnumber\naturalfullsectionnumber}
- {\let\fullsectionnumber\limitedfullsectionnumber}}
- {\let\fullsectionnumber\ignoredfullsectionnumber}}
-
-\let\fullsectionnumber\limitedfullsectionnumber
-
-% \dodododoconstructhead IS NON GROUPED, SO WE NEED TO RESTORE !!!!
-%
-% dit kan dus beter \everyaroundhead zijn
-
-\let\currentheadnumber\empty
-\let\currentheadtext \empty
-
-\def\dodoconstructhead#1[#2]#3% [ref] {title}
- {\doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\doquadruplegroupempty\dododoconstructhead{#1}{#2}{#3}}
- {\fourthargumentfalse \dododoconstructhead{#1}{#2}{#3}{}}}
-
-\def\dododoconstructhead#1#2#3#4% [ref] {own} {title}
- {\iffourthargument
- \def\next{\dodododoconstructhead{#1}[#2]{#3}{#4}}%
- \else
- \def\next{\dodododoconstructhead{#1}[#2]{\finalsectionnumber}{#3}}%
- \fi
- \next}
-
-% pas met \ExpandFirstAfter op bij twee||taligheid
-
-\ifx\dohandleheadnumber\undefined
- \let\dohandleheadnumber\firstofoneargument
-\fi
-
-\unexpanded\def\\{\space}
-
-\def\emptyheadcorrection % experimental, should work
- {\ifemptyhead % well with na=\blank
- \vskip-\lineheight
- \dosomebreak\nobreak
- \kern\zeropoint
- \prevdepth\strutdepth
- \fi}
-
-\let\localkopprefix\empty
-
-\def\headparameter#1% to do: everywhere in core-sec
- {\executeifdefined{\??ko\currenthead#1}\empty}
-
-% todo: write to list etc in both args or in enclosing h/vbox else it gets
-% lost when no #1 or #2 is typeset
-
-% we will use variables here
-
-\def\dodododoconstructhead#1[#2]#3#4% [ref] {number} {title}
- {\def\currenthead{#1}% dus #1 overal vervangen
- \let\finalsectionnumber\dofinalsectionnumber % overloaded ungrouped -)
- \unexpanded\def\\{\space}%
- \edef\numberseparator{\spr{\getvalue{\??ko\currenthead\c!separator}}}%
- \flushingcolumnfloatsfalse % {number} can be \finalsectionnumber
- \someheadconversionfalse
- \let\fullsectionnumber\limitedfullsectionnumber
- \setsectieenkoppeling{#1}%
- \doifelsevaluenothing{\??ko#1\c!prefix}
- \headprefixfalse\headprefixtrue
- \ifheadprefix
- \doifelsevalue{\??ko#1\c!prefix}{+}
- {\doifelsenothing{#2}
- {\def\localkopprefix{+}}
- {\def\localkopprefix{#2}}} % eigenlijk alleen eerste
- {\edef\localkoprefix{\getvalue{\??ko#1\c!prefix}}}%
- \else
- \let\localkoprefix\empty
- \fi
- \placeheadtrue
- \processaction
- [\getvalue{\??ko#1\c!placehead}]
- [ \v!yes=>\emptyheadfalse,
- \v!empty=>\emptyheadtrue,
- \v!no=>\emptyheadtrue\placeheadfalse]%
- \doifelsevalue{\??ko#1\c!resetnumber}\v!no
- {\setfalse\@@resetsubheadnumbers}%
- {\settrue \@@resetsubheadnumbers}%
- \writetolistfalse
- \processaction
- [\getvalue{\??ko#1\c!incrementnumber}]
- [ \v!yes=>\incrementnumbertrue,
- \v!no=>\incrementnumberfalse,
- \v!list=>\incrementnumberfalse
- % beware, since no numbers are used, no nested lists are
- % possible here
- \writetolisttrue,
- \s!unknown=>{\ifx\currentproduct\empty
- \findsectionnumber{#1}\commalistelement{#4}%
- \fi
- \incrementnumbertrue}]%
- \edef\numberheaddistance {\getvalue{\??ko#1\c!distance}}%
- \edef\numberheadalternative{\getvalue{\??ko#1\c!alternative}}%
- \doifelsevalue{\??ko:\numberheadalternative}\v!horizontal
- \displaysectionheadfalse
- \displaysectionheadtrue
- \ifsectionnumber
- \doifelsevalue{\??sb\@@sectionblock\c!number}\v!yes
- {\doifelsevalue{\??ko#1\c!number}\v!yes
- \headnumbertrue
- \headnumberfalse}
- {\headnumberfalse}%
- \else
- \headnumberfalse
- \fi
- \defconvertexpanded\asciititle{\getvalue{\??ko#1\c!expansion}}{#4}%
- %
- \gdef\currentheadtext{#4}% scheelt args
- \globallet\currentheadnumber\empty
- %
- \ifincrementnumber
- \ifplacehead
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \ifheadprefix
- %\setupreferencing[\c!prefix=-]%
- \setupreferenceprefix[-]%
- \fi
- \getvalue{\e!next\@@sectie}%
- \ifheadnumber
- \setsomeheadconversion{#1}{#3}%
- \let\fullsectionnumber\expandablefullsectionnumber
- \xdef\currentheadnumber{\someheadconversion}%
- \getvalue{\??ko#1\c!inbetween}%
- \ifsomeheadconversion
- \let\fullsectionnumber\naturalfullsectionnumber
- \doplaceheadnumbertext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \let\fullsectionnumber\writtenfullsectionnumber
- \rawreference\s!sec{#2}{{\someheadconversion}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \let\fullsectionnumber\writtenfullsectionnumber
- \dowritetolist\@@koppeling\someheadconversion{#4}\v!head}%
- {\dohandleheadnumber\someheadconversion}% handle is new
- {#4}
- {\marking[#1]{#4}%
- \let\fullsectionnumber\storedfullsectionnumber
- \expanded{\marking[#1\v!number]{\someheadconversion}}}%
- \let\fullsectionnumber\ignoredfullsectionnumber
- \writesection{#1}{\someheadconversion}{#4}%
- \else
- \doplaceheadnumbertext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \dowritetolist\@@koppeling{#3}{#4}\v!head}
- {\sectionblocklabel{#1}{\dohandleheadnumber{#3}}}% handle is new
- {#4}
- {\marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % rommelig omdat
- {\edef\finalsectionnumber{#3}} % #3 al is toegekend
- {\determineheadnumber[#1]}% migreert naar 3e argument
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
- \writesection{#1}{#3}{#4}%
- \fi
- \else
- \getvalue{\??ko#1\c!inbetween}%
- \doplaceheadtext
- {#1}
- {\setsectionlistreference{\@@sectie}{#1}%
- \pagetype[\@@koppeling]%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \resetsectionmarks\@@sectie
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr, new per 18/1/2005, sometimes we need
- {\dowritetolist\@@koppeling{#3}{#4}\v!head} % entries in the list (special purpose) but
- {\dowritetolist\@@koppeling {}{#4}\v!head}% not in the header, ok we could pop in a command
- }% \dowritetolist\@@koppeling{}{#4}\v!head}
- {#4}
- {\marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr
- {\edef\finalsectionnumber{#3}}
- {\determineheadnumber[#1]}%
- % todo : geen markering (leeg maken)
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
- \writesection{#1}{-}{#4}%
- \fi
- \ifheadprefix
- \setupreferenceprefix[\localkopprefix]%
- \fi
- \ifdisplaysectionhead
- \dosomebreak\nobreak
- \emptyheadcorrection
- \getvalue{\??ko#1\c!after}%
- \fi
- \else
- % Whatever future tex's will do with nodes,
- % we assume a node here, because other \c!after=\blank
- % will fail! See 'prikkels'
- %
- % so, maybe we need an explicit \kern
- %
- % do nothing / should be vbox to 0pt
- %
- \checknexthead\dohandlepagebreakB{#1}% toegevoegd ivm subpaginanr / tug sheets
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \ifheadprefix
- \setupreferenceprefix[-]%
- \fi
- \getvalue{\e!next\@@sectie}%
- \ifheadnumber
- \setsomeheadconversion{#1}{#3}%
- \let\fullsectionnumber\expandablefullsectionnumber
- \xdef\currentheadnumber{\someheadconversion}%
- \fi
- \getvalue{\??ko#1\c!inbetween}% documenteren, is enige hook
- \bgroup
- \setsectionlistreference{\@@sectie}{#1}%
- \resetsectionmarks\@@sectie
- \marking[#1]{#4}%
- \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
- {\edef\finalsectionnumber{#3}}
- {\determineheadnumber[#1]}%
- \expanded{\marking[#1\v!number]{\finalsectionnumber}}%
- \pagetype[\@@koppeling]%
-% \bgroup
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \ifheadnumber
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \dowritetolist\@@koppeling{#3}{#4}\v!head
- \writesection{#1}{#3}{#4}%
- \else % hm, also no own number
- \rawreference\s!sec{#2}{{#3}{\asciititle}}%
- \dowritetolist\@@koppeling{}{#4}\v!head
- \writesection{#1}{-}{#4}%
- \fi
- \egroup
- \ifheadprefix
- \setupreferenceprefix[\localkopprefix]%
- \fi
- \fi
- \else
- % todo : ref prefix
- \ifplacehead
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \getvalue{\??ko#1\c!inbetween}%
- \doplaceheadtext
- {#1}
- {\forcesectiontolist{#1}{#4}%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}} % #3 ?
- {#4}
- %{}% new:
- {\marking[#1]{#4}%
- \marking[#1\v!number]{}}%
- \writesection{#1}{-}{#4}%
- \ifdisplaysectionhead
- \dosomebreak\nobreak
- \emptyheadcorrection
- \getvalue{\??ko#1\c!after}%
- \fi
- \else
- % do nothing / should be vbox to 0pt
- \checknexthead\handlepagebreak{#1}%
- \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
- \getvalue{\??ko#1\c!inbetween}%
- \forcesectiontolist{#1}{#4}%
- \rawreference\s!sec{#2}{{#3}{\asciititle}}% #3 ?
- \marking[#1]{#4}%
- \marking[#1\v!number]{}%
- \writesection{#1}{-}{#4}%
- \fi
- \fi
- \flushingcolumnfloatstrue
- \someheadconversionfalse
- \setfalse\ignorehandlepagebreak
- \let\fullsectionnumber\limitedfullsectionnumber
- % ignorespaces prevents spaces creeping in when after=\dontleavehmode
- \ifdisplaysectionhead\ignorespaces\else\expandafter\GotoPar\fi}
-
-\def\forcesectiontolist#1#2%
- {\ifwritetolist
- % we need to make sure that there is a number set (non
- % zero) else the list mechanism cannot determine the
- % level
- \bgroup
- \setupheadnumber[#1][+1]% traag, wordt \getvalue{\c!next...}
- \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
- \dowritetolist\@@koppeling{}{#2}\v!head
- \setupheadnumber[#1][-1]% traag, wordt \getvalue{\c!previous...}
- \egroup
- \fi}
-
-\let\previoussectionformat\empty
-\let\currentsectionformat \empty
-
-\let\updatelistreferences \relax
-\let\updatedlistreferences\empty
-
-\def\setsectionlistreference#1#2%
- {\ifnum\countervalue{\??se\previoussection{#1}}>0\relax
- \xdef\previoussectionformat{\@@longformatnumber{\previoussection{#1}}}%
- \else
- \globallet\previoussectionformat\empty
- \fi
- \xdef\currentsectionformat{\@@longformatnumber{#1}}}
-
-\def\startlistreferences#1%
- {\thisissomeinternal{\s!lst}{#1\currentsectionformat}%
- \setxvalue{\s!lst:#1}{\realfolio}% to be sure
- \setxvalue{\s!lst:#1\currentsectionformat}{\realfolio}%
- \setxvalue{\e!previouslocal#1}{\s!lst:#1\previoussectionformat}%
- \setxvalue{\e!currentlocal#1}{\s!lst:#1\currentsectionformat}%
- \doifelse{\currentsectionformat}{}
- {\setglobalcrossreference
- {\e!previous#1}{}{\realfolio}{}}
- {\setglobalsystemreference\rt!list
- {\e!previous#1}{\getvalue{\e!previouslocal#1}}}%
- \def\stoplistreferences{\dostoplistreferences{#1}}}
-
-\def\dostoplistreferences#1%
- {\ifutilitydone
- \addtocommalist{#1}\updatedlistreferences % nog global (\doglobal)
- \globallet\updatedlistreferences\updatedlistreferences % een noodverbandje
- \gdef\updatelistreferences%
- {\def\docommand####1%
- {\setglobalsystemreference\rt!list
- {\e!previous####1}{\getvalue{\e!currentlocal####1}}}%
- \processcommacommand[\updatedlistreferences]\docommand
- \globallet\updatelistreferences\relax
- \globallet\updatedlistreferences\empty}%
- \fi}
-
-\let\stoplistreferences\relax
-
-\appendtoks
- \updatelistreferences
-\to\aftereverypage
-
-% \prevdepth\strutdp % is belangrijk, vergelijk naast elkaar:
-%
-% \subject{test} \input tufte
-% \subject{test} \strut \input tufte
-% \subject{test} \placelist[...]
-
-% todo: kap
-
-% to be documented: \placeheadtext \placeheadnumber
-
-\unexpanded\def\placeheadtext
- {\doquintupleempty\doplaceheadtextornumber
- [\c!textstyle][\c!textcolor][\empty]}
-
-\unexpanded\def\placeheadnumber
- {\doquintupleempty\doplaceheadtextornumber
- [\c!numberstyle][\c!numbercolor][\v!number]}
-
-\def\doplaceheadtextornumber[#1][#2][#3][#4][#5]%
- {\bgroup
- \edef\@@sectie{\??ko\iffifthargument#5\else#4\fi}%
- \dostartattributes\@@sectie\c!style\c!color\empty
- \dontconvertfont
- \dostartattributes\@@sectie{#1}{#2}\empty
- \setupinterlinespace
- \begstrut\getmarking[\mainmarking{#4#3}]\endstrut
- \endgraf
- \dostopattributes
- \dostopattributes
- \egroup}
-
-\chardef\headtimingmode=0
-
-% \chardef\headtimingmode=1 % 0 also works ok now too
-%
-% Martin Kolarik's problem:
-%
-% \setuphead[section][command=\doTitle]
-%
-% \def\doTitle#1#2%
-% {\ruledvbox{\forgetall \hsize=4cm
-% \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}}
-%
-% \section{test test test test test test test test test test
-% test test test test test test test}
-
-\newevery \everyheadstart \relax
-
-\def\placeheadmargintexts#1%
- {\the\everyheadstart
- \doifvalue{\??ko#1\c!margintext}\v!yes\placemargincontent}
-
-\def\doplaceheadtext#1#2#3#4%
- {\beginheadplacement{#1}%
- \ifemptyhead % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
- {\headnumbercontentfalse
- \resetsystemmode\v!sectionnumber
- #2}%
- \makestrutofbox0
- \else % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
- {\headnumbercontentfalse
- \resetsystemmode\v!sectionnumber
- % less interfering
- \ifcase\headtimingmode\or#2\fi
- % outerside font determines distance
- \dosetfontattribute{\??ko#1}\c!style
- \dosetcolorattribute{\??ko#1}\c!color
- % todo: get the if-else out of it
- \getvalue{\??ko#1\c!command}
- {} % no number
- {\dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
- \dontconvertfont
- \ifdisplaysectionhead
- \setupinterlinespace
- \else
- \setupspacing
- \fi
- % \ifcase\headtimingmode#2\fi % can introduce cr
- \getvalue{\??ko#1\c!commandbefore}%
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
- {\setstrut
- \begstrut
- \ifcase\headtimingmode\hbox{#2}\fi
- \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}%
- \endstrut}% \hbox prevents break
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdepth
- \else
- \ifcase\headtimingmode#2\fi
- \getvalue{\??ko#1\c!textcommand}%
- {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}}%
- \fi
- \getvalue{\??ko#1\c!commandafter}%
- \ifdisplaysectionhead\endgraf\fi
- \dostopattributes}}%
- \fi
- \endheadplacement{#1}{#4}}
-
-\def\doplaceheadnumbertext#1#2#3#4#5% maybe move modes outside box
- {\beginheadplacement{#1}%
- \ifemptyhead % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
- {\doiftextelse{#3}
- {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
- {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
- #2}%
- \makestrutofbox0
- \else % = needed
- \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
- {\doiftextelse{#3}
- {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
- {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
- % less interfering
- \ifcase\headtimingmode\or#2\fi
- % outerside font determines distance
- \dosetfontattribute{\??ko#1}\c!style
- \dosetcolorattribute{\??ko#1}\c!color
- % but we don't want color to influence user commands
- \getvalue{\??ko#1\c!command}%
- {\dostartattributes{\??ko#1}\c!numberstyle\c!numbercolor\empty
- % \getvalue{\??ko#1\c!commandbefore}% strange, why here? moved 21/11/2005
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- % can be nilled with \setnostrut
- \getvalue{\??ko#1\c!numbercommand}%
- {\setstrut
- \begstrut
- \executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}%
- \endstrut}%
- \else
- \getvalue{\??ko#1\c!numbercommand}%
- {\executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}}%
- \fi
- \dostopattributes}
- {\dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
- \dontconvertfont
- \ifdisplaysectionhead
- \setupinterlinespace
- \else
- \setupspacing
- \fi
- % \ifcase\headtimingmode#2\fi % can introduce cr
- \getvalue{\??ko#1\c!commandbefore}% makes more sense here
- \placeheadmargintexts{#1}% binnen #3?
- \ifdisplaysectionhead
- \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
- {\setstrut
- \begstrut
- \ifcase\headtimingmode\hbox{#2}\fi
- \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}%
- \endstrut}% \hbox prevents break
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdepth
- \else
- \ifcase\headtimingmode#2\fi % inside textcommand ?
- \getvalue{\??ko#1\c!textcommand}%
- {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}}%
- \fi
- \getvalue{\??ko#1\c!commandafter}%
- \ifdisplaysectionhead\endgraf\fi
- \dostopattributes}}%
- \fi
- \endheadplacement{#1}{#5}}
-
-
-
-%D \starttyping
-%D \def\StretchedBox#1%
-%D {\framed
-%D [frame=off,offset=.5em,align=middle,width=broad]
-%D {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}}
-%D
-%D \definehead[MySubject][subject]
-%D \setuphead [MySubject][deeptextcommand=\StretchedBox]
-%D
-%D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
-%D \stoptyping
-
-\newsignal\headsignal
-\let\headlastlinewidth\!!zeropoint
-
-\def\beginheadplacement#1%
- {\bgroup
- \setsystemmode{#1}% to be documented
- \ifgridsnapping\iftracegridsnapping\showstruts\fi\fi
- \xdef\localheadheight {\the\strutht}%
- \xdef\localheaddepth {\the\strutdp}%
- \xdef\localheadlineheight{\the\lineheight}%
- % == \globallet\localheaddepth\strutdp
- \everypar\emptytoks % needed indeed
- \noindent % ipv \whitespace elders, na \forgetall !
- \bgroup
- \doifinsetelse{\getvalue{\??ko#1\c!aligntitle}}{\v!yes,\v!float}% new
- {\skip0 1\leftskip
- \skip2 1\rightskip
- \xdef\localheadskip{\the\skip0}%
- \forgetall
- \leftskip\skip0
- \rightskip\skip2
- \setlocalhsize\hsize\localhsize
- \forgetbothskips}
- {\globallet\localheadskip\!!zeropoint
- \forgetall}%
- \dontcomplain
- \postponefootnotes
- \iflocation\ifdisplaysectionhead\else\noninterferingmarks\fi\fi
- \resetinteractionparameter\c!style
- \resetinteractionparameter\c!color
- \resetinteractionparameter\c!contrastcolor
- \strictouterreferencestrue % tzt instelling
- \def\localheadsetup{\dolocalheadsetup{#1}}%
- \startsynchronization}
-
-% \setuphead[chapter] [style=\bfd,after=,hang=line] % fit broad 2
-% \setuphead[section] [style=\bfc,after=,hang=line]
-% \setuphead[subsection] [style=\bfb,after=,hang=line]
-% \setuphead[subsubsection] [style=\bfa,after=,hang=line]
-% \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
-%
-% \chapter {Test} \input tufte \page
-% \section {Test} \input tufte \page
-% \subsection {Test} \input tufte \page
-% \subsubsection {Test} \input tufte \page
-% \subsubsubsection{Test} \input tufte \page
-%
-% \chapter {Test\\Test} \input tufte \page
-% \section {Test\\Test} \input tufte \page
-% \subsection {Test\\Test} \input tufte \page
-% \subsubsection {Test\\Test} \input tufte \page
-% \subsubsubsection{Test\\Test} \input tufte \page
-
-\def\hangheadplacement
- {\scratchdimen\localheadlineheight
- \bgroup
- \openlineheight\scratchdimen
- \scratchdimen\ht0
- \advance\scratchdimen\dp0
- \getnoflines\scratchdimen
- \advance\noflines\minusone
- \expanded{\egroup\noflines\the\noflines}% brrr
- \setbox0\hbox{\lower\noflines\scratchdimen\box0}%
- \scratchdimen\ht0
- \advance\scratchdimen\dp0
- \advance\scratchdimen-\localheadheight
- \advance\scratchdimen+\strutdp
- \ht0 \strutht
- \dp0 \strutdp
- \edef\localheaddepth{\the\strutdp}}
-
-\newconditional\continuoussectionhead % oeps, \newif\ifcontinuoushead got lost
-
-\def\endheadplacement#1#2%
- {\doifelsevalue{\??rf#1\c!state}\v!start
- {\doifvaluenothing{\??ko#1\c!file}{\autocrossdocumentfalse}}
- {\autocrossdocumentfalse}%
- % no message needed here, should be a proper switch
- \noflines\zerocount
- \ifdisplaysectionhead
- % new (tod tight == one following line up)
- \processaction
- [\getvalue{\??ko#1\c!hang}]
- [ \v!line=>\hangheadplacement\noflines\zerocount,
- \v!broad=>\hangheadplacement\getnoflines\scratchdimen,
- \v!fit=>\hangheadplacement\getrawnoflines\scratchdimen,
- \v!none=>\noflines\zerocount,
- \v!default=>\noflines\zerocount,
- \v!unknown=>\hangheadplacement\noflines0\commalistelement\advance\noflines\minusone]%
- % so far
- \let\headlastlinewidth\!!zeropoint
- \snaptogrid[\getvalue{\??ko#1\c!grid}]\hbox
- {\hskip\localheadskip
- \hskip\getvalue{\??ko#1\c!margin}\relax
- \iflocation
- \ifautocrossdocument
- \doifreferencefoundelse{\getvalue{\??ko#1\c!file}::#1}
- {\edef\currentinnerreference{\s!aut:\currenttextreference}% stored in
- \gotoouterlocation{}{\box0}} % text slot
- {\hbox{\box0}}%
- \else
- \hbox{\box0}%
- \fi
- \else
- \hbox{\box0}%
- \fi}%
- \doflushnotes % new, not really needed
- \endgraf
- \ifvmode
- \ifnum\noflines>\zerocount
- \dorecurse\noflines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}%
- \fi
- \nointerlineskip
- \dosomebreak\nobreak
- \fi
- #2%
- \else
- \strut
- \doflushnotes % new, here since we're in par mode
- \iflocation
- \ifautocrossdocument
- \hhboxindent=\ifconditional\continuoussectionhead\headlastlinewidth\else\zeropoint\fi
- \unhhbox0\with{\gotobox{\box\hhbox}[\getvalue{\??ko#1\c!file}::#1]}%
- \advance\lasthhboxwidth by \numberheaddistance
- \xdef\headlastlinewidth{\the\lasthhboxwidth}%
- \else
- \unhbox0
- \globallet\headlastlinewidth\!!zeropoint
- \fi
- \else
- \unhbox0
- \globallet\headlastlinewidth\!!zeropoint
- \fi
- #2%
- \dimen0=\numberheaddistance
- \hskip\dimen0 \!!plus \dimen0 \!!minus .25\dimen0
- \hskip\headsignal\ignorespaces
- \fi
- \ifdisplaysectionhead \ifvmode
- \ifgridsnapping % important, font related depth, see comment
- \prevdepth\strutdp
- \else
- \prevdepth\localheaddepth
- \fi
- \fi \fi
- \stopsynchronization
- \egroup
- \egroup
- \ifdisplaysectionhead
- \dochecknextindentation{\??ko#1}%
- \else
- \nonoindentation % recently added, was a bug
- \fi}
-
-\def\checknexthead#1#2% nog optioneel
- {\ifhmode
- \scratchcounter=\lastpenalty\unpenalty % no beauty in this
- \ifdim\lastskip=\headsignal
- \handlenopagebreak{#1}%
- \global\settrue\continuoussectionhead
- \else
- \penalty\scratchcounter
- \global\setfalse\continuoussectionhead
- #1{#2}%
- \fi
- \else
- \global\setfalse\continuoussectionhead
- #1{#2}%
- \fi}
-
-\def\dosetupheadnumber[#1][#2#3]% todo: = (don't reset)
- {\bgroup
- \setsectieenkoppeling{#1}%
- \doifinstringelse{#2}{+-}
- {\doifelsenothing{#3}
- {\@@nextsectionnumber\@@sectie}
- {\!!counta=#2#3\relax
- \advance\!!counta \@@sectionvalue\@@sectie
- \@@setsectionnumber\@@sectie\!!counta}}
- {\@@setsectionnumber\@@sectie{#2#3}}%
- \egroup}
-
-\def\setupheadnumber
- {\dodoubleargument\dosetupheadnumber}
-
-\def\currentheadnumber{0}
-
-\def\determineheadnumber[#1]%
- {\bgroup
- \setsectieenkoppeling{#1}%
- \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
- \egroup}
-
-\def\complexheadnumber[#1]%
- {\bgroup
- \edef\currentheadnumber{#1}%
- \doifinsetelse{-}{#1} % br undocumented
- {\removefromcommalist{-}\currentheadnumber % br
- \setsectieenkoppeling\currentheadnumber
- \setupsection[\@@sectie][\c!previousnumber=\v!no]}%
- {\setsectieenkoppeling\currentheadnumber}%
- \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
- \doifnot{\currentheadnumber}{0}{\finalsectionnumber}%
- \egroup}
-
-\def\simpleheadnumber
- {\currentheadnumber}
-
-\definecomplexorsimple\headnumber
-
-\def\alinea
- {\par}
-
-% nice testcase
-%
-% \setupheads[aligntitle=yes]
-%
-% \startnarrower
-% \subject{\dorecurse{100}{x }}
-% \section{\dorecurse{100}{x }}
-% \input tufte \par
-% \setupheads[alternative=inmargin]
-% \subject{\dorecurse{100}{x }}
-% \section{\dorecurse{100}{x }}
-% \input tufte \par
-% \stopnarrower
-
-\let\numberheadalternative\v!normal
-
-\def\defineheadplacement
- {\dodoubleargument\dodefineheadplacement}
-
-\def\dodefineheadplacement[#1][#2]% #3#4
- {\setvalue{\??ko:#1}{#2}%
- \setvalue{\??ko::#1}}
-
-\def\normalplacehead
- {\executeifdefined
- {\??ko::\numberheadalternative}
- {\getvalue{\??ko::\v!normal}}}
-
-\defineheadplacement[\v!paragraph][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \begstrut\ifheadnumbercontent#1\hskip\numberheaddistance\fi#2}}
-
-% \defineheadplacement[\v!normal][\v!vertical]#1#2%
-% {\ifheadnumbercontent
-% \setbox0\hbox{{#1}\hskip\numberheaddistance}%
-% \vbox
-% {\localheadsetup
-% \hangindent 1\wd0
-% \hangafter 1
-% \noindent
-% \unhbox0 % don't use \strut's here!
-% #2}%
-% \else
-% \vbox
-% {\localheadsetup\noindent#2}%
-% \fi}
-%
-% enhanced version:
-
-% \setuphead
-% [chapter]
-% [numberwidth=2cm,hang=line,after={\blank[3*line]}]
-%
-% \chapter{Oeps oeps oeps} \input tufte \section{Oeps}
-% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
-
-\defineheadplacement[\v!normal][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \edef\headwidth {\headparameter\c!width }%
- \edef\headnumberwidth{\headparameter\c!numberwidth}%
- \edef\headtextwidth {\headparameter\c!textwidth }%
- \ifheadnumbercontent
- \ifx\headwidth\empty
- \else
- \ifx\headnumberwidth\empty
- \ifx\headtextwidth\empty\else
- \edef\headnumberwidth{\the\dimexpr\headwidth-\headtextwidth\relax}%
- \fi
- \else
- \ifx\headtextwidth\empty
- \edef\headtextwidth{\the\dimexpr\headwidth-\headnumberwidth\relax}%
- \fi
- \fi
- \hsize\headwidth
- \fi
- \ifx\headnumberwidth\empty\else
- \let\numberheaddistance\!!zeropoint
- \fi
- \setbox\scratchbox\hbox \ifx\headnumberwidth\empty\else to \headnumberwidth\fi{{#1}}%
- \scratchdimen\dimexpr\wd\scratchbox+\numberheaddistance\relax
- \ifx\headtextwidth\empty\else
- \hsize\dimexpr\scratchdimen+\headparameter\c!textwidth\relax
- \fi
- \hangindent\scratchdimen
- \hangafter \plusone
- \noindent
- \box\scratchbox\hskip\numberheaddistance
- \else
- \ifx\headtextwidth\empty
- \ifx\headwidth\empty
- \else
- \hsize\headwidth
- \fi
- \else
- \hsize\headtextwidth
- \fi
- \noindent
- \fi
- #2}}
-
-\def\placeheadmargin#1#2%
- {\vbox
- {\localheadsetup
- \begstrut % use one \strut here!
- \dontleavehmode % in case there is no strut, else side effects with llap
- \ifheadnumbercontent
- \llap{\hbox to 5em{\hfill{#1}\hskip\localheadskip\hskip\leftmargindistance}}% introduces whitespace
- % maybe better:
- % \inleftmargin{\hbox{\hss{#1}\hskip\localheadskip}}%
- \fi
- {#2}}}
-
-\defineheadplacement[\v!inmargin][\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
-\defineheadplacement[\v!margin] [\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
-
-\defineheadplacement[\v!middle][\v!vertical]#1#2%
- {\vbox
- {\localheadsetup
- \veryraggedcenter
- \let\\\endgraf
- \let\crlf\endgraf
- \ifheadnumbercontent\strut#1\par\fi\begstrut#2}}
-
-\defineheadplacement[\v!text][\v!horizontal]#1#2%
- {\bgroup
- \localheadsetup % no stretch in distance
- \ifheadnumbercontent{#1}\kern\numberheaddistance\fi{\begstrut#2}%
- \egroup}
-
-\def\placeheadlohi#1#2#3%
- {\ifheadnumbercontent
- \setbox0\hbox{#2}
- \setbox2=#1{\localheadsetup\advance\hsize-\wd0\relax#3}%
- \hbox{\box0\hskip\numberheaddistance\box2}%
- \else
- #1{\localheadsetup\noindent#3}%
- \fi}
-
-% onder/boven lijnt het nummer op de onderste/bovenste regel
-% uit van een meerregelige kop
-
-\defineheadplacement[\v!bottom][\v!vertical]#1#2{\placeheadlohi\vbox{#1}{#2}}
-\defineheadplacement[\v!top] [\v!vertical]#1#2{\placeheadlohi\vtop{#1}{#2}}
-
-% default == instellingen
-% koppeling == koppen, breaks, marks, enz.
-% sectie == nummering
-
-\let\@@kolist=\empty
-
-\def\dododefinehead#1#2% % don't preset prefix to much
- {\presetlabeltext[#1=]%
-% \getparameters
-% [\??ko#1]
-% [\c!numberstyle=\getvalue{\??ko#1\c!style},
-% \c!textstyle=\getvalue{\??ko#1\c!style},
-% \c!numbercolor=\getvalue{\??ko#1\c!color},
-% \c!textcolor=\getvalue{\??ko#1\c!color}]%
- % deeptextcommand and deepnumbercommand are left undefined !
- \doifassignmentelse{#2}
- {\getparameters
- [\??ko#1]
- [\c!section=\getvalue{\??ko\getvalue{\??ko#1\c!coupling}\c!section},
-\c!numberstyle=,
-\c!textstyle=,
-\c!numbercolor=,
-\c!textcolor=,
- \c!default=,
- \c!coupling=,
- \c!prefix=,
- \c!before=,
- \c!after=,
- \c!distance=\!!zeropoint,
- \c!page=,
- \c!header=,
- \c!text=,
- \c!footer=,
- \c!style=,
- \c!numbercommand=,
- \c!textcommand=,
- \c!ownnumber=\v!no,
- \c!number=\v!yes,
- \c!color=,
- \c!continue=\v!yes,
- \c!placehead=\v!yes,
- \c!resetnumber=\v!yes,
- \c!incrementnumber=\v!yes,
- \c!alternative=\@@koalternative,
- \c!command=\normalplacehead,
- \c!separator=\@@koseparator,
- \c!stopper=\@@kostopper,
- \c!align=\@@koalign,
- \c!aligntitle=\@@koaligntitle,
- \c!tolerance=\@@kotolerance,
- \c!indentnext=\@@koindentnext,
- \c!strut=\@@kostrut,
- \c!hang=\@@kohang,
- \c!file=,
- \c!expansion=,
- \c!grid=,
- \c!margintext=,
- \c!margin=\@@komargin,
- #2]%
- \ConvertToConstant\doifnot{#1}{\getvalue{\??ko#1\c!default}}
- {\doifsomething{\getvalue{\??ko#1\c!default}}
- {\copyparameters
- [\??ko#1][\??ko\getvalue{\??ko#1\c!default}]
- [\c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
- \c!header,\c!text,\c!footer,\c!separator,\c!stopper,\c!resetnumber,
- \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
- \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
- % new per 20/03/3002 (o-pbu-l) / was too confusing
- % \c!numberstyle,\c!textstyle,\c!expansion,
- % again too confusing
- \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
- \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]}}%
- \getparameters[\??ko#1][#2]%
- \doifsomething{\getvalue{\??ko#1\c!section}}
- {\doifelsemarking{#1}% \doifundefined{\??mk#1}
- {}% marking #1 already defined
- {\definemarking[#1]%
- \couplemarking[#1][\getvalue{\??ko#1\c!section}]%
- \definemarking[#1\v!number]%
- \couplemarking[#1\v!number][\getvalue{\??ko#1\c!section}]}}%
- \doifundefined{\??li#1}{\definelist[#1]}}
- {\ConvertToConstant\doifelse{#1}{#2}
- {\doifundefined{\??li#1}{\definelist[#1]}}
- {\copyparameters
- [\??ko#1][\??ko#2]
- [\c!level,\c!section,\c!coupling,\c!prefix,
- \c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
- \c!separator,\c!stopper,
- \c!header,\c!text,\c!footer,\c!resetnumber,
- \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
- \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
- % new per 20/03/3002 (o-pbu-l) / was too confusing
- % \c!numberstyle,\c!textstyle,\c!expansion,
- % again too confusing
- \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
- \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]%
- \getparameters[\??ko#1][\c!expansion=]% iig een value, rather fuzzy
- \definemarking[#1][#2]%
- \definemarking[#1\v!number][#2\v!number]%
- \doifundefined{\??li#1}{\definelist[#1][#2]}}}%
- \addtocommalist{#1}\@@kolist
- \setevalue{\??sk#1}{\getvalue{\??ko#1\c!coupling}}%
- \setevalue{\??by#1}{\getvalue{\??ko#1\c!section}}%
- \setevalue{\??by\v!by#1}{\getvalue{\??ko#1\c!section}}%
- \setvalue{#1}{\dodoubleempty\doconstructhead[#1]}}
-
-\def\dodefinehead[#1][#2]%
- {\doifelsenothing{#2}
- {% todo: message that it's an invalid definition
- \setvalue{#1}{\endgraf[#1]\kern.5em}}
- {\doifassignmentelse{#2}
- {\dododefinehead{#1}{#2}}
- {\doifdefined{\??ko#2\c!section}
- {\dododefinehead{#1}{#2}}}}}
-
-\def\definehead
- {\dodoubleemptywithset\dodefinehead}
-
-\def\doconstructhead[#1][#2]%
- {\dowithpargument{\dodoconstructhead{#1}[#2]}}
-
-\def\dosetuphead[#1][#2]%
- {\getparameters[\??ko#1][#2]%
- % The next check prevents hard to trace problems. I once
- % set \c!command to nothing and (quite natural) got the
- % wrong references etc. The whole bunch should be boxed!
- \expandafter\defconvertedcommand\expandafter\ascii\csname\??ko#1\c!command\endcsname
- \doifnothing\ascii{\setvalue{\??ko#1\c!command}{\normalplacehead}}}
-
-\def\setuphead
- {\dodoubleargumentwithset\dosetuphead}
-
-\def\dosetupheads[#1]%
- {\getparameters[\??ko][#1]%
- \doifelse{\@@kosectionnumber}\v!yes\sectionnumbertrue\sectionnumberfalse}
-
-\def\setupheads
- {\dosingleargument\dosetupheads}
-
-\def\systemsuppliedchapter {\getvalue{\v!chapter}}
-\def\systemsuppliedtitle {\getvalue{\v!title}}
-
-% a left over
-
-\def\complexbijlage[#1]#2%
- {\page[\v!right]
- \setuppagenumbering[\c!state=\v!stop]
- \systemsuppliedchapter[#1]{#2}
- \page[\v!right]
- \setuppagenumbering[\c!state=\v!start]
- \setuppagenumbering[\c!number=1]}
-
-\setvalue{\v!appendix}%
- {\complexorsimpleempty\bijlage}
-
-\setupheads
- [\c!alternative=\v!normal,
- \c!sectionnumber=\v!yes,
- \c!separator=.,
- \c!stopper=,
- \c!limittext=\v!yes,
- \c!align=,
- \c!aligntitle=,
- \c!tolerance=,
- \c!strut=,
- \c!indentnext=\v!no,
- \c!margin=\zeropoint,
- \c!hang=\v!none,
- \c!command=]
-
-\definesectionblock [\v!frontpart] [\v!frontmatter] [\c!number=\v!no]
-\definesectionblock [\v!bodypart] [\v!bodymatter] [\c!number=\v!yes]
-\definesectionblock [\v!appendix] [\v!appendices] [\c!number=\v!yes]
-\definesectionblock [\v!backpart] [\v!backmatter] [\c!number=\v!no]
-
-\definesection[\s!section-1] % part
-\definesection[\s!section-2] % chapter
-\definesection[\s!section-3] % section
-\definesection[\s!section-4] % subsection
-\definesection[\s!section-5] % subsubsection
-\definesection[\s!section-6] % subsubsubsection
-\definesection[\s!section-7] % subsubsubsubsection
-
-% \c!eigennummer ook hier?
-
-\definehead
- [\v!part]
- [\c!section=\s!section-1,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!chapter]
- [\c!section=\s!section-2,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!section]
- [\c!section=\s!section-3,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsection]
- [\c!section=\s!section-4,
- \c!default=\v!section,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsection]
- [\c!section=\s!section-5,
- \c!default=\v!subsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsubsection]
- [\c!section=\s!section-6,
- \c!default=\v!subsubsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubsection]
- [\c!section=\s!section-7,
- \c!default=\v!subsubsubsection,
- \c!ownnumber=\v!no]
-
-\definehead
- [\v!title]
- [\c!coupling=\v!chapter,
- \c!default=\v!chapter,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subject]
- [\c!coupling=\v!section,
- \c!default=\v!section,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubject]
- [\c!coupling=\v!subsection,
- \c!default=\v!subsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubject]
- [\c!coupling=\v!subsubsection,
- \c!default=\v!subsubsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubject]
- [\c!coupling=\v!subsubsubsection,
- \c!default=\v!subsubsubsection,
- \c!incrementnumber=\v!no]
-
-\definehead
- [\v!subsubsubsubsubject]
- [\c!coupling=\v!subsubsubsubsection,
- \c!default=\v!subsubsubsubsection,
- \c!incrementnumber=\v!no]
-
-\setupsection
- [\s!section-2]
- [\v!appendix\c!conversion=\v!Character,
- \c!previousnumber=\v!no]
-
-\setuphead
- [\v!part]
- [\c!placehead=\v!no]
-
-\setuphead
- [\v!chapter]
- [\v!appendix\c!label=\v!appendix,
- \v!bodypart\c!label=\v!chapter] % bijlageconversie=\Character
-
-\setuphead
- [\v!section]
- [\v!appendix\c!label=\v!section,
- \v!bodypart\c!label=\v!section] % bijlageconversie=\Character
-
-\setuphead
- [\v!subsection]
- [\v!appendix\c!label=\v!subsection,
- \v!bodypart\c!label=\v!subsection] % bijlageconversie=\Character
-
-\setuphead
- [\v!subsubsection]
- [\v!appendix\c!label=\v!subsubsection,
- \v!bodypart\c!label=\v!subsubsection] % bijlageconversie=\Character
-
-\setuphead
- [\v!part,\v!chapter]
- [%\c!align=,
- %\c!indentnext=\v!no,
- \c!continue=\v!no,
- \c!page=\v!right,
- \c!header=,
- \c!style=\tfc,
- \c!distance=.75em,
- \c!before={\blank[2*\v!big]},
- \c!after={\blank[2*\v!big]}]
-
-\setuphead
- [\v!section]
- [%\c!align=,
- %\c!indentnext=\v!no,
- \c!style=\tfa,
- \c!distance=.75em,
- \c!before={\blank[2*\v!big]},
- \c!after=\blank]
-
-\setuphead % nieuw
- [\v!subsection]
- [\c!page=]
-
-\definecombinedlist
- [\v!content]
- [\v!part,
- \v!chapter,
- \v!section,
- \v!subsection,
- \v!subsubsection,
- \v!subsubsubsection,
- \v!subsubsubsubsection]
- [\c!level=\v!subsubsubsubsection,
- \c!criterium=\v!local]
-
-\setuplist
- [\v!part]
- [\c!before={\blank\page[\v!preference]},
- \c!after=\blank,
- \c!label=\v!yes,
- \c!separator=:,
- \c!distance=1em]
-
-\setuplist
- [\v!chapter]
- [\c!before={\blank\page[\v!preference]},
- \c!after=]
-
-\setuplist [\v!part] [\c!width=0em]
-\setuplist [\v!chapter] [\c!width=2em]
-\setuplist [\v!section] [\c!width=3em]
-\setuplist [\v!subsection] [\c!width=4em]
-\setuplist [\v!subsubsection] [\c!width=5em]
-\setuplist [\v!subsubsubsection] [\c!width=6em]
-\setuplist [\v!subsubsubsubsection] [\c!width=7em]
-
-% hm
-
-\setuppagenumbering % na instellen hoofdteksten !
- [\c!alternative=\v!singlesided,
- \c!location={\v!header,\v!middle},
- \c!conversion=\v!numbers,
- \c!width=, % in geval van \v!marginedge
- \c!left=,
- \c!right=,
- \c!way=\v!by\v!part,
- \c!text=,
- \v!chapter\v!number=\v!no, % v
- \v!part\v!number=\v!yes, % v
- \c!numberseparator=--,
- \c!textseparator=\tfskip,
- \c!state=\v!start,
- \c!command=,
- \c!strut=\v!yes, % nieuw
- \c!style=, % \v!normal, % empty, otherwise conflict
- \c!color=]
-
-\protect \endinput
diff --git a/tex/context/base/core-sec.tex b/tex/context/base/core-sec.tex
new file mode 100644
index 000000000..6cc0fbbf9
--- /dev/null
+++ b/tex/context/base/core-sec.tex
@@ -0,0 +1,2572 @@
+%D \module
+%D [ file=core-sec,
+%D version=1997.03.31,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Sectioning,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% start-stop per section en dan combineren met sectieblok; in dat geval
+% eenvoudiger per-* acties
+
+% nummeren per sectieblok implementeren
+
+% this module needs a clean up, currently some manipulations
+% take place multiple times; also, some clever recursive level
+% thing makes more sense
+
+% in manual (zie prikkels) : tussen=\blanko is enige hook om
+% met kop-in-hoofd een spatiering af te dwingen
+
+\writestatus{loading}{ConTeXt Core Macros / Sectioning}
+
+\unprotect
+
+% new and to be tested
+
+\unexpanded\def\separatorlist#1%
+ {\ifx\sepnumber\undefined\def\sepnumber{0}\fi
+ \increment\sepnumber
+ \getfromcommacommand[#1][\sepnumber]%
+ \ifx\commalistelement\empty
+ \getcommalistsize[#1]%
+ \def\sepnumber{\number\commalistsize}%
+ \getfromcommacommand[#1][\sepnumber]%
+ \fi
+ \commalistelement}
+
+% \setuphead[section] [separator=\separatorlist{?,!,*}]
+% \setuphead[subsection][separator=\separatorlist{??,!!,**}]
+%
+% \let\spr\separatorlist % this will enable this feature
+%
+% \setuphead[section] [separator={?,!,*}]
+% \setuphead[subsection][separator={??,!!,**}]
+%
+% \setupheads[separator={A,B,C,D,E,F}]
+% \chapter{test}
+% \section{test} \subsection{test} \subsection{test}
+% \section{test} \subsection{test} \subsection{test}
+
+% from now on, internaly numbers are separated by a period
+% and postprocessed on demand; this will change to {} {} {}
+
+\def\numberseparator {.} % reasonable default
+\def\sectionseparator{-} % was : but is now -
+
+\def\@@filterfirstpart [#1--#2]{#1}
+\def\@@filtersecondpart [#1--#2]{#2}
+
+\def\@@filterblockpart [#1--#2--#3]{#1}
+\def\@@filternumberpart [#1--#2--#3]{#2}
+\def\@@filterpagepart [#1--#2--#3]{#3}
+\def\@@filterblocknumberpart[#1--#2--#3]{#1--#2}
+
+\def\@@filterheadpart[#1]{\@EA\@@dofilterheadpart\@EA[#1-0]}
+\def\@@filtertailpart[#1]{\@EA\@@dofiltertailpart\@EA[#1-0]}
+
+\def\@@dofilterheadpart[#1-#2]{#1}
+\def\@@dofiltertailpart[#1-#2]{#2}
+
+\def\@@filterlevelpart[#1--#2--#3]{\@@dofilterlevelpart[#2-0-0-0-0]}
+
+\def\@@dofilterlevelpart[#1-0-0-0-#2]{#1}
+
+\def\gobbleuntilrelax#1\relax{}
+
+\def\separatednumber #1{\doseparatednumber #1.\empty\relax}
+\def\removefirstprefix#1{\doremovefirstprefix#1.\empty\relax}
+\def\removeallprefixes#1{\doremoveallprefixes#1.\empty\relax}
+
+\def\doseparatednumber#1.#2%
+ {#1%
+ \ifx#2\empty
+ \@EA\gobbleuntilrelax
+ \else \numberseparator
+ \@EA\doseparatednumber
+ \fi#2}
+
+\def\doremoveallprefixes#1.#2%
+ {\ifx#2\empty
+ #1\@EA\gobbleuntilrelax
+ \else
+ \@EA\doremoveallprefixes
+ \fi#2}
+
+\def\doremovefirstprefix#1.#2%
+ {\ifx#2\empty
+ #1\@EA\gobbleuntilrelax
+ \else
+ \@EA\noremovefirstprefix
+ \fi#2}
+
+\def\noremovefirstprefix#1.\empty\relax
+ {#1}
+
+% we need to expand in order to get something separatable
+
+\def\dohandleheadnumber#1%
+ {\expanded{\separatednumber{#1}}}
+
+\def\dodochecknumber#1#2#3% will become ugly after speed up
+ {\bgroup
+ \doifinstringelse{.0}{.#2}
+ {\doifnot{#3}\v!by
+ {%\debuggerinfo\m!systems{number #1 #3 becomes \getnumbervariable{#1\c!way}}%
+ \setevalue{\@@thenumber{#1}\c!way}{#3}% geen \xdef, gaat mis met \subpage
+ \dochecknumber{#1}}} % tricky and ugly
+ {\doifnotvalue{\@@thenumber{#1}\s!check}{#2}
+ {% new, calculate accumulated number
+ \scratchcounter\getvalue{\@@thenumber{#1}\c!n}\relax
+ \advance\scratchcounter\countervalue{\@@thenumber{#1}}\relax
+ \setxvalue{\@@thenumber{#1}\c!n}{\the\scratchcounter}%
+ %
+ \setcounter{\@@thenumber{#1}}{0\getvalue{\@@thenumber{#1}\c!start}}%
+ \setxvalue{\@@thenumber{#1}\c!way\c!local}{\getvalue{\@@thenumber{#1}\c!way}}%
+ \setxvalue{\@@thenumber{#1}\s!check}{#2}}}%
+ \egroup}
+
+\def\dochecknumber#1%
+ {\edef\currentsection{\csname\??by\csname\@@thenumber{#1}\c!way\endcsname\endcsname}%
+ \ifx\currentsection\empty\else
+ \dodochecknumber
+ {#1}%
+ {\csname\currentsection\c!number\endcsname}%
+ {\v!by\previoussection\currentsection}%
+ \fi}
+
+\def\checknumber[#1]%
+ {\bgroup
+ %\ifcase\blocklevel\else
+ \ifdoingblocks
+ \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
+ \fi
+ \dochecknumber{#1}%
+ \egroup}
+
+\def\rawsectionnumber#1%
+ {\countervalue{\??se#1}}
+
+\def\precedingseparator{\@@koseparator} % brrr
+
+\def\domakeprecedingsectionnumber[#1]% will become ugly after speed up
+ {\bgroup % added
+ \globallet\precedingsectionnumber\empty
+ \ifsectionnumber
+ \doifvalue{\??sb\@@sectionblock\c!number}\v!yes % added
+ {\doifelsevalue{\@@thenumber{#1}\c!sectionnumber}\v!yes
+ \donetrue\donefalse
+ \doifvalue{\@@thenumber{#1}\c!sectionnumber}\v!number
+ {\donetrue\let\@@sectionconversion\gobbleoneargument}%
+ \ifdone
+ \edef\currentsection
+ {\getvalue{\??by\getvalue{\@@thenumber{#1}\c!way\c!local}}}%
+ \doifnot\currentsection\zerosection
+ {\doifnot{\@@sectionvalue\currentsection}{0}
+ {\xdef\precedingsectionnumber
+ {\getvalue{\currentsection\c!number}%
+ \spr{\precedingseparator}}}}%
+ \fi}%
+ \fi
+ \egroup}
+
+\def\makeprecedingsectionnumber[#1]%
+ {\bgroup
+ %\ifnum\blocklevel>0
+ %\ifcase\blocklevel\else
+ \ifdoingblocks
+ \doifnotvalue{\@@thenumber{#1}\c!blockway}\v!no\setblockcounters
+ \fi
+ \domakeprecedingsectionnumber[#1]%
+ \egroup}
+
+% \def\makesectionnumber[#1]%
+% {\makeprecedingsectionnumber[#1]%
+% \xdef\composedsectionnumber%
+% {\precedingsectionnumber\convertednumber[#1]}}%
+%
+% hack needed for chinese and oldstyle in normal tex, will change
+
+\def\makesectionnumber[#1]%
+ {\bgroup
+ \forceunexpanded % i don't like this hack
+ \makeprecedingsectionnumber[#1]%
+ \xdef\composedsectionnumber% was \xdef maar dat gaat fout met font switches
+ {\precedingsectionnumber\convertednumber[#1]}%
+ \egroup}
+
+% \def\preparethenumber#1#2#3% {\??id#1} \number \result
+% {\doifelsevaluenothing{#1\c!separator}
+% {\let\numberseparator\empty
+% \let#3#2}
+% {% was \unexpanded \edef, but we need it unexpanded !
+% \edef\numberseparator{\spr{\getvalue{#1\c!separator}}}%
+% \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
+% {\edef#3%
+% {\@EA\separatednumber\@EA{#2}%
+% }}%\stp{\getvalue{#1\c!stopper}}}}
+% {\edef#3%
+% {\@EA\separatednumber\@EA{#2}%
+% \spr{\getvalue{#1\c!separator}}%
+% \getvalue{#1\c!suffix}%
+% \stp{\getvalue{#1\c!stopper}}}}}}
+%
+% some day we do a real cleanup
+
+\def\analyzenumber#1#2#3% {\??id#1} \(precedingsection)number \result
+ {% was \unexpanded \edef, but we need it unexpanded !
+ \doifelsenothing{\executeifdefined{#1\c!suffix}\empty}
+ {\let \numbersuffix \empty}
+ {\edef\numbersuffix{\spr{\getvalue{#1\c!suffix}}}}%
+ \doifelsenothing{\executeifdefined{#1\c!stopper}\empty}
+ {\let \numberstopper \empty}
+ {\edef\numberstopper{\spr{\getvalue{#1\c!stopper}}}}%
+ \doifelsenothing{\executeifdefined{#1\c!separator}\empty}
+ {\let \numberseparator \empty}
+ {\edef\numberseparator{\spr{\getvalue{#1\c!separator}}}}%
+ \let\numberprefix\empty}
+
+\def\preparefullnumber#1#2#3% {\??id#1} \(precedingsection)number \result
+ {\analyzenumber{#1}#2#3%
+ \ifx\numberseparator\empty
+ \edef\numberprefix{#2}%
+ \else
+ \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
+ \fi
+ \ifx\numbersuffix\empty
+ \ifx\numberprefix\empty
+ \let #3\empty
+ \else
+ \edef#3{\numberprefix\numberstopper}%
+ \fi
+ \else
+ \ifx\numberprefix\empty
+ \edef#3{\numbersuffix\numberstopper}%
+ \else
+ \edef#3{\numberprefix\numberseparator\numbersuffix\numberstopper}%
+ \fi
+ \fi}
+
+\def\prepareprefixnumber#1#2#3% {\??id#1} \number \result
+ {\analyzenumber{#1}#2#3%
+ \ifx\numberseparator\empty
+ \edef\numberprefix{#2}%
+ \else
+ \edef\numberprefix{\@EA\separatednumber\@EA{#2}}%
+ \fi
+ \let#3\numberprefix}
+
+\def\sectionnumberonly[#1]%
+ {\makesectionnumber[#1]%
+ \composedsectionnumber}
+
+% sectioning
+
+\newcount\nofsections
+
+\let\zerosection \v!text
+\let\firstsection\empty
+\let\lastsection \empty
+\let\@@sectie \empty
+\let\@@koppeling \empty
+
+\makecounter{\??se\v!text}
+
+\letvalueempty{\??se\v!text\c!before}
+\letvalueempty{\??se\v!text\c!after }
+
+\setvalue {\v!text\c!number}{0}
+\letvalueempty{\v!text\s!format}
+
+\letvalueempty{\??sk\v!text}
+\letvalueempty{\??sk }
+
+\letvalue{\??by }\v!text
+\letvalue{\??by\v!text }\v!text
+\letvalue{\??by\v!all }\v!text
+\letvalue{\??by\v!by }\v!text
+\letvalue{\??by\v!by\v!text}\v!text
+\letvalue{\??by\v!by\v!all }\v!text
+\letvalue{\??by\v!by\v!page}\v!text % see footnotes
+
+\def\sectionofhead#1{\executeifdefined{\??ko#1\c!section}\s!unknown}
+
+\def\setupsection
+ {\dotripleempty\dosetupsection}
+
+\def\dosetupsection[#1]%
+ {\doifdefinedelse{\??se#1}
+ {\dodosetupsection[#1]}%
+ {\dodosetupsection[\sectionofhead{#1}]}}
+
+\def\dodosetupsection[#1][#2][#3]%
+ {\doifdefined{\??se#1}
+ {\ifthirdargument
+ \getparameters[\??se#1#2][#3]%
+ \else
+ \getparameters[\??se#1][#2]%
+ \fi
+ \doifelsevalue{\??se#1\c!previousnumber}\v!yes
+ {\setvalue{#1\c!number}{\@@longsectionnumber {#1}}}
+ {\setvalue{#1\c!number}{\@@shortsectionnumber{#1}}}}}
+
+\def\docouplemarking[#1][#2]%
+ {\doifdefinedelse{\??ko#2\c!section}
+ {\docouplemarking[#1][\getvalue{\??ko#2\c!section}]}
+ {\def\donexttrackcommando##1%
+ {\edef\coupledmarkings{\getvalue{\??se##1\c!marking}}%
+ \doifelse{##1}{#2}
+ {\addtocommalist{#1}\coupledmarkings}
+ {\removefromcommalist{#1}\coupledmarkings}%
+ \setevalue{\??se##1\c!marking}{\coupledmarkings}%
+ \donexttracklevel{##1}}%
+ \donexttracklevel{\zerosection}}} % \firstsection
+
+\def\couplemarking
+ {\dodoubleargument\docouplemarking}
+
+\def\decouplemarking[#1]%
+ {\couplemarking[#1][]}
+
+\def\definesection[#1]%
+ {\doifundefined{\??se#1}
+ {\doifelsenothing\firstsection
+ {\def\firstsection{#1}%
+ \setevalue{\??se#1\c!before}{\v!text}%
+ \setevalue{\??se\v!text\c!after}{#1}}
+ {\setevalue{\??se\commalistelement\c!after}{#1}% commalistelement ?
+ \setevalue{\??se#1\c!before}{\lastsection}%
+ \setevalue{\??se\lastsection\c!after}{#1}}%
+ \advance\nofsections \plusone
+ \setevalue{\??se#1\c!level}{\the\nofsections}%
+ \letvalue{\??se#1\c!after}\empty
+ \setvalue{\e!next#1}{\@@nextsectionnumber{#1}}%
+ \setvalue{#1\c!number}{\@@longsectionnumber{#1}}%
+ \setvalue{#1\s!format}{\@@longformatnumber{#1}}%
+ \setevalue{\??by#1}{#1}%
+ \setevalue{\??by\v!by#1}{#1}%
+ \makecounter{\??se#1}%
+ \makecounter{\??se\v!last#1}% GB
+ \edef\lastsection{#1}%
+ \setvalue{\??sk#1}{#1}%
+ \letvalue{\??se#1\c!marking}\empty
+ \setupsection[#1][\c!previousnumber=\v!yes]}}%
+
+\def\previoussection#1{\csname\??se#1\c!before\endcsname}
+\def\nextsection #1{\csname\??se#1\c!after \endcsname}
+
+\let\preservedsection\v!unknown % \def\preservedsection{\firstsection}
+
+\def\checkpreservevalueafter#1% GB
+ {\ifnum\getvalue{\??se#1\c!level}<\nofsections
+ \edef\preservedsection{\getvalue{\??se#1\c!after}}%
+ \ifconditional\@@resetsubheadnumbers
+ \setcounter{\??se\v!last\preservedsection}\zerocount % {0}%
+ \else
+ \setcounter{\??se\v!last\preservedsection}{\countervalue{\??se\preservedsection}}%
+ \fi
+ \fi}
+
+\def\@@setsectionnumber#1#2%
+ {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
+ \setcounter{\??se#1}{#2}%
+ \checkpreservevalueafter{#1}% GB
+ \resetsectioncounters{#1}%
+ \checkpagecounter}
+
+\def\@@nextsectionnumber#1% patched by GB
+ {\letgvalueempty{\??se#1\s!start}% signal i.p.v. boolean
+ \ifnum\countervalue{\??se\v!last#1}>\zerocount
+ \setcounter{\??se#1}{\countervalue{\??se\v!last#1}}%
+ \setcounter{\??se\v!last#1}\zerocount % {0}%
+ \fi
+ \pluscounter{\??se#1}%
+ \checkpreservevalueafter{#1}%
+ \resetsectioncounters{#1}%
+ \checkpagecounter}
+
+\def\@@sectionvalue#1% % nog niet overal doorgevoerd
+ {\countervalue{\??se#1}} % zoeken op \??se
+
+% suited for chinese too:
+
+\def\@@sectionconversion#1#2% a doublure with \@@shortsectionnumber
+ {\ifnum#2=0 0\else % else troubles with \uchar
+ \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
+ \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
+ #2%
+ \else
+ \convertnumber{\getvalue{\??se#1\c!conversion}}{#2}%
+ \fi
+ \else
+ \convertnumber{\getvalue{\??se#1\@@sectionblock\c!conversion}}{#2}%
+ \fi
+ \fi}
+
+% \def\@@sectionlevel#1%
+% {\ifundefined{\??se#1\c!level}0\else\getvalue{\??se#1\c!level}\fi}
+
+\def\@@sectionlevel#1%
+ {\executeifdefined{\??se#1\c!level}0}
+
+% Omdat een markering kan worden herdefinieerd moeten we
+% eerst testen of er wel een keten||afhankelijkheid is.
+
+\def\resetsectionmarks#1% can invoke a break
+ {\ifundefined{\??se#1}%
+ \fastresetmarker[\mainmarking{#1}]% % redundant \mainmarking
+ \else
+ \let\donexttrackcommando\doresetsectionmarks
+ \donexttracklevel{#1}%
+ \fi}
+
+\def\doresetsectionmarks#1%
+ {\ifundefined{\??se#1\c!marking}\else % skip zero level
+ \fastresetmarkerlist[\csname\??se#1\c!marking\endcsname]%
+ \fi
+ \donexttracklevel{#1}}
+
+% I'm not sure if the next one is better:
+%
+% \def\doresetsectionmarks#1%
+% {\ifundefined{\??se#1\c!markering}% skip zero level
+% \donexttracklevel{#1}%
+% \else
+% \fastresetmarkerlist[\csname\??se#1\c!markering\endcsname]%
+% \fi}
+%
+% and indeed, it isn't, actually, it does not work at all, so let's drop it.
+
+% packaged:
+%
+% \def\resetsectioncounters#1%
+% {\def\donexttrackcommando##1%
+% {\resetcounter{\??se##1}%
+% \donexttracklevel{##1}}%
+% \donexttracklevel{#1}}
+%
+% nicer
+%
+% \def\doresetsectioncounters#1%
+% {\resetcounter{\??se#1}%
+% \donexttracklevel{#1}}
+%
+% obey eigennummer
+
+\def\doresetsectioncounters#1%
+ {\resetcounter{\??se#1}%
+ \letgvalue{\??se#1\c!ownnumber}\relax
+ \donexttracklevel{#1}}
+
+\def\resetsectioncounters % #1
+ {\let\donexttrackcommando\doresetsectioncounters
+ \donexttracklevel} % #1
+
+% bij checken kan geen prefix worden bekeken, anders vallen
+% er titels buiten de inhoudsopgave
+
+% evt ook level gaan opslaan tbv snelle selectie
+
+% \def\makesectionformat
+% {\edef\sectionformat
+% {\@@sectiontype\sectionseparator
+% \csname\lastsection\s!format\endcsname}}
+
+\unprotected \def\makesectionformat % we don't want eigennummers here
+ {\pushmacro\@@shortsectionnumber
+ \let\@@shortsectionnumber\@@sectionvalue
+ \edef\sectionformat
+ {\@@sectiontype\sectionseparator
+ \csname\lastsection\s!format\endcsname}%
+ \popmacro\@@shortsectionnumber}
+
+\def\dobacktracklevel#1%
+ {\doifnot{\previoussection{#1}}\zerosection
+ {\dobacktrackcommando{\previoussection{#1}}}}
+
+\def\donexttracklevel#1%
+ {\doifnot{#1}\lastsection
+ {\donexttrackcommando{\nextsection{#1}}}}
+
+\chardef\alltoclevels\zerocount
+
+\let\currentlevel\empty
+
+\def\dosetcurrentlevel#1%
+ {\global\chardef\alltoclevels\zerocount
+ \xdef\currentlevel{\getvalue{\lastsection\s!format}}}
+
+\def\dosetpreviouslevel#1%
+ {\global\chardef\alltoclevels\plusone
+ \globallet\currentlevel\empty
+ \def\dobacktrackcommando##1%
+ {\ifnum\countervalue{\??se##1}>\zerocount
+ \global\chardef\alltoclevels\zerocount
+ \xdef\currentlevel{\getvalue{\previoussection{##1}\s!format}}%
+ \else
+ \dobacktracklevel{##1}%
+ \fi}%
+ \dobacktrackcommando\lastsection}
+
+\def\dosettextlevel#1%
+ {\global\chardef\alltoclevels\plusone
+ \globallet\currentlevel\empty}
+
+\def\dosetotherlevel#1%
+ {\doifdefinedelse{\??ko#1\c!section} % beter alteratief: ook
+ {\edef\@@sectie{\getvalue{\??ko#1\c!section}}} % hoofdstuk\c!format
+ {\edef\@@sectie{#1}}%
+ \doifdefinedelse{\??se\@@sectie}
+ {\global\chardef\alltoclevels\zerocount
+ \xdef\currentlevel{\getvalue{\@@sectie\s!format}}}
+ {\global\chardef\alltoclevels\plusone
+ \globallet\currentlevel\empty
+ \def\dobacktrackcommando##1%
+ {\@EA\ifx\csname\??se##1\c!start\endcsname\relax
+ \dobacktracklevel{##1}%
+ \else
+ \ifnum\countervalue{\??se##1}>\zerocount
+ \global\chardef\alltoclevels\zerocount
+ \xdef\currentlevel{\getvalue{##1\s!format}}%
+ \else
+ \dobacktracklevel{##1}%
+ \fi
+ \fi}%
+ \dobacktrackcommando\lastsection}}
+
+% \def\ignoresectionconversion % brrr
+% {\let\@@sectionconversion\secondoftwoarguments}
+
+% todo: criterium=appendix|frontmatter|....
+
+\def\dosetfilterlevel#1#2% beware: this one is \let
+ {\bgroup
+ \let\@@shortsectionnumber\@@sectionvalue
+% \ignoresectionconversion
+ \edef\askedlevel{#1}%
+ \edef\askedfilter{#2}%
+ \ifx\askedlevel\v!current
+ \dosetcurrentlevel\askedlevel
+ \else\ifx\askedlevel\v!previous
+ \dosetpreviouslevel\askedlevel
+ \else\ifx\askedlevel\v!all
+ \global\chardef\alltoclevels\plusone
+ \else\ifx\askedlevel\v!text
+ \global\chardef\alltoclevels\plusone
+ \else
+ \edef\byaskedlevel{\csname\??by\askedlevel\endcsname}%
+ \ifx\byaskedlevel\v!text
+ \dosettextlevel\askedlevel
+ \else
+ \dosetotherlevel\askedlevel
+ \fi
+ \fi\fi\fi\fi
+ % experiment
+ \ifx\askedfilter\empty \else
+ \xdef\currentlevel{\currentlevel\sectionseparator\askedfilter}%
+ \fi
+ \egroup}
+
+% \def\dontsetfilterlevel#1#2%
+% {\let\currentlevel\somesavedlevel
+% \chardef\alltoclevels\zerocount}
+
+\def\dontsetfilterlevel#1#2%
+ {\let\currentlevel\somesavedlevel
+ \let\@@sectiontype\@@tocsectiontype
+ \chardef\alltoclevels\zerocount}
+
+\def\honorlocalfilterlevel % local lists will be real local
+ {\let\dosetfilterlevel\dontsetfilterlevel}
+
+% cleaner
+%
+% \def\doifnextlevelelse[#1::#2]#3#4%
+% {\ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}
+% {\doifinstringelse{=\currentlevel:0}{=:#2:}{#4}{#3}}
+% {#4}}
+% {#4}%
+% \else
+% #3%
+% \fi}
+%
+% \def\doifprevlevelelse[#1::#2]#3#4%
+% {\ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}{#3}{#4}}
+% {#4}%
+% \else
+% #3%
+% \fi}
+%
+% faster
+%
+% \def\doifnextlevelelse[#1::#2]%
+% {\ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}
+% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
+% \donefalse}
+% \donefalse
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% \def\doifprevlevelelse[#1::#2]%
+% {\ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
+% \donefalse
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% meaner
+%
+% \setuplist
+% [chapter]
+% [after={\startcolumns\placelist[section]\stopcolumns}]
+
+\def\somesavedlevel{0}
+
+% \def\dosavesomelevel[#1:0:0:0:#2]%
+% {\def\somesavedlevel{:#1}}
+
+% \def\doifnextlevelelse[#1::#2]%
+% {\dosavesomelevel[#2:0:0:0:0]%
+% \ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}
+% {\doifinstringelse{=\currentlevel:0}{=:#2:}\donefalse\donetrue}
+% \donefalse}
+% \donefalse
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% \def\doifprevlevelelse[#1::#2]%
+% {\dosavesomelevel[#2:0:0:0:0]%
+% \ifcase\alltoclevels
+% \doifelse{\@@sectiontype}{#1}
+% {\doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse}
+% \donefalse
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% again faster:
+
+% \def\doifnextlevelelse[#1::#2]% beware: this one is \let
+% {\dosavesomelevel[#2:0:0:0:0]%
+% \ifcase\alltoclevels
+% \ifnum\@@sectiontype=#1
+% \def\levelstring{=:#2:}%
+% \doifincsnameelse{=\currentlevel:}\levelstring
+% {\doifincsnameelse{=\currentlevel:0}\levelstring\donefalse\donetrue}
+% \donefalse
+% \else
+% \donefalse
+% \fi
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+%\def\doifprevlevelelse[#1::#2]% beware: this one is \let
+% {\dosavesomelevel[#2:0:0:0:0]%
+% \ifcase\alltoclevels
+% \ifnum\@@sectiontype=#1
+% \doifinstringelse{=\currentlevel:}{=:#2:}\donetrue\donefalse
+% \else
+% \donefalse
+% \fi
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% \let\doiftoclevelelse\doifnextlevelelse
+% \let\doifreglevelelse\doifprevlevelelse
+% \let\doifblklevelelse\doifprevlevelelse
+%
+% we want to be able to overload them globally
+
+% This will be reimplemented some day soon
+%
+% {nn}{xx}{yy}
+%
+% -> \scan{..}{..}{0} met 0 als sentinel
+
+% still not perfect
+%
+% \def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
+% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
+% \ifcase\alltoclevels
+% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
+% \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
+% \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
+% {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
+% \donefalse
+% \donetrue}
+% \donefalse
+% \else
+% \donefalse
+% \fi
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+%
+% \def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
+% {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
+% \ifcase\alltoclevels
+% \ifnum\@@sectiontype=\@@filterblockpart[#1]\relax
+% \doifinstringelse
+% {=\currentlevel\sectionseparator}
+% {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
+% \donetrue\donefalse
+% \else
+% \donefalse
+% \fi
+% \else
+% \donetrue
+% \fi
+% \ifdone
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+
+\def\doifnextlevelelse[#1]% !! this one is \let / uti seperator --
+ {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
+ \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
+ \ifcase\alltoclevels
+ \ifnum\@@sectiontype=\@@tocsectiontype\relax
+ \edef\levelstring{=\sectionseparator\@@filternumberpart[#1]\sectionseparator}%
+ \doifincsnameelse{=\currentlevel\sectionseparator}\levelstring
+ {\doifincsnameelse{=\currentlevel\sectionseparator0}\levelstring
+ \donefalse
+ \donetrue}
+ \donefalse
+ \else
+ \donefalse
+ \fi
+ \else
+ \donetrue
+ \fi
+ \ifdone
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\def\doifprevlevelelse[#1]% !! this one is \let / uti seperator --
+ {\edef\somesavedlevel{\sectionseparator\@@filterlevelpart[#1]}%
+ \edef\@@tocsectiontype{\@@filterblockpart[#1]}% needed for nested tocs
+ \ifcase\alltoclevels
+ \ifnum\@@sectiontype=\@@tocsectiontype\relax
+ \doifinstringelse
+ {=\currentlevel\sectionseparator}
+ {=\sectionseparator\@@filternumberpart[#1]\sectionseparator}
+ \donetrue\donefalse
+ \else
+ \donefalse
+ \fi
+ \else
+ \donetrue
+ \fi
+ \ifdone
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+% we need to cover the special case of nested lists in section blocks
+%
+% \starttext
+%
+% \def\ChapterEntry#1#2#3%
+% {chapter : \hbox to \hsize{\strut\bf#2\hss#3}\endgraf\placelist[section]}
+%
+% \startfrontmatter % optional
+% \placelist[chapter][alternative=command,command=\ChapterEntry,criterium=text] \page
+% \stopfrontmatter % optional
+%
+% \startbodymatter % optional
+% \chapter{first} \section{one} test \section{two} test \page
+% \chapter{second} \section{alpha} test \section{beta} test \page
+% \stopbodymatter % optional
+%
+% \stoptext
+
+\def\doiftoclevelelse{\doifnextlevelelse}
+\def\doifreglevelelse{\doifprevlevelelse}
+\def\doifblklevelelse{\doifprevlevelelse}
+
+\def\@@longformatnumber#1%
+ {\csname\previoussection{#1}\s!format\endcsname
+ \sectionseparator
+ \@@shortsectionnumber{#1}}
+
+% \def\@@longsectionnumber#1%
+% {\ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
+% \csname\previoussection{#1}\c!nummer\endcsname.%
+% \fi
+% \@@shortsectionnumber{#1}}
+
+\def\@@longsectionnumber#1%
+ {\ifreversesectionnumbers
+ \@@shortsectionnumber{#1}%
+ \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
+ .\csname\previoussection{#1}\c!number\endcsname
+ \fi
+ \else
+ \ifnum\countervalue{\??se\previoussection{#1}}>\zerocount
+ \csname\previoussection{#1}\c!number\endcsname.%
+ \fi
+ \@@shortsectionnumber{#1}%
+ \fi}
+
+% suited for chinese too:
+%
+% \def\@@shortsectionnumber#1%
+% {\@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
+% \@@sectionvalue{#1}%
+% \else
+% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
+% \fi}
+%
+% obey eigennummer
+%
+% \def\@@shortsectionnumber#1%
+% {\@EA\ifx\csname\??se#1\c!eigennummer\endcsname\relax
+% \@EA\ifx\csname\??se#1\@@sectionblock\c!conversie\endcsname\relax
+% \@EA\ifx\csname\??se#1\c!conversie\endcsname\relax
+% \@@sectionvalue{#1}%
+% \else
+% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
+% \fi
+% \else
+% \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
+% \fi
+% \else
+% \csname\??se#1\c!eigennummer\endcsname
+% \fi}
+
+\def\@@shortsectionnumber#1%
+ {\@EA\ifx\csname\??se#1\c!ownnumber\endcsname\relax
+ \@EA\ifx\csname\??se#1\@@sectionblock\c!conversion\endcsname\relax
+ \@EA\ifx\csname\??se#1\c!conversion\endcsname\relax
+ \@@sectionvalue{#1}%
+ \else
+ \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
+ \fi
+ \else
+ \@@sectionconversion{#1}{\@@sectionvalue{#1}}%
+ \fi
+ \else
+ \csname\??se#1\c!ownnumber\endcsname
+ \fi}
+
+\def\dosetlocalsectionblock#1#2#3% new \edef's
+ {\edef\@@sectiontype {#1}%
+ \edef\@@sectionblock {#2}%
+ \edef\@@sectionblocks{#3}}
+
+% beware, the \resetsectionmarks generates some nodes that
+% will result in an additional last page, which needs to be
+% captured at the end
+
+% \def\doaroundsectionblock#1%
+% {\doifvaluesomething{\??sb#1\c!page}
+% {\ExpandFirstAfter\page[\getvalue{\??sb#1\c!page}]}%
+% \resetsectioncounters\zerosection % was firstsection
+% \resetsectionmarks\zerosection}
+
+% \def\dostartsectionblock#1#2%
+% {\begingroup
+% \doaroundsectionblock{#1}% % going to a new page or so
+% \getvalue{\??sb#1}% % set name of section block
+% \getsectionblockenvironment{#1}% % special settings, grouped
+% %\expandafter\csname#2true\endcsname % obsolete
+% \setsystemmode{#1}% % can be used in conditionals
+% \getvalue{\??sb\@@sectionblock\c!before}% this one is not to be moved!
+% \showmessage\m!structures1\@@sectionblocks}
+
+% \def\dostopsectionblock
+% {\showmessage\m!structures2\@@sectionblocks
+% \getvalue{\??sb\@@sectionblock\c!after}% don't move
+% \doaroundsectionblock\@@sectionblock
+% \endgroup}
+
+\def\doaroundsectionblock
+ {\doifvaluesomething{\??sb\@@sectionblock\c!page}
+ {\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
+ \resetsectioncounters\zerosection % was firstsection
+ \resetsectionmarks\zerosection}
+
+\def\dostartsectionblock#1#2%
+ {\begingroup
+ \getvalue{\??sb#1}%
+ \doaroundsectionblock
+% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
+% \resetsectioncounters\zerosection % was firstsection
+% \resetsectionmarks\zerosection
+ \getsectionblockenvironment\@@sectionblock
+ \setsystemmode\@@sectionblock
+ \getvalue{\??sb\@@sectionblock\c!before}%
+ \showmessage\m!structures1\@@sectionblocks}
+
+\def\dostopsectionblock
+ {\showmessage\m!structures2\@@sectionblocks
+ \getvalue{\??sb\@@sectionblock\c!after}% don't move
+ \doaroundsectionblock
+% \doifvaluesomething{\??sb\@@sectionblock\c!page}{\page[\getvalue{\??sb\@@sectionblock\c!page}]}%
+% \resetsectioncounters\zerosection % was firstsection
+% \resetsectionmarks\zerosection
+ \endgroup}
+
+\def\dosetupsectionblock[#1]% [#2]
+ {\getparameters[\??sb#1]}
+
+\def\setupsectionblock
+ {\dodoubleargument\dosetupsectionblock}
+
+\long\def\setsectionblockenvironment#1#2%
+ {\long\setvalue{\??sb\s!do#1}{\do{#2}}}
+
+\def\getsectionblockenvironment#1%
+ {\let\do\firstofoneargument\getvalue{\??sb\s!do#1}}
+
+\setvalue{\e!start\v!sectionblockenvironment}%
+ {\dosingleargument\dostartsectionblockenvironment}
+
+\def\dostartsectionblockenvironment[#1]% evt \pushendofline \popendofline
+ {\long\def\do##1##2{\setsectionblockenvironment{#1}{##1##2}}%
+ \grabuntil{\e!stop\v!sectionblockenvironment}{\getvalue{\??sb\s!do#1}}}
+
+%D \starttyping
+%D \startsectionblockenvironment[frontpart]
+%D \setuppagenumbering[conversion=romannumerals]
+%D \stopsectionblockenvironment
+%D
+%D \startsectionblockenvironment[bodypart]
+%D \setuppagenumber[number=1]
+%D \stopsectionblockenvironment
+%D
+%D \startsectionblockenvironment[frontpart]
+%D \setuppagenumbering[conversion=character]
+%D \stopsectionblockenvironment
+%D
+%D \starttext
+%D \startfrontmatter \chapter{test} \stopfrontmatter
+%D \startbodymatter \chapter{test} \stopbodymatter
+%D \startappendices \chapter{test} \stopappendices
+%D \stoptext
+%D \stoptyping
+
+% We used to use the first char as id, but a counter is
+% better, because in english we get a name clash.
+
+\newcounter\currentsectionblock
+
+\def\currentsection{\@@sectionblock}
+
+\def\dodefinesectionblock[#1][#2][#3]%
+ {\getparameters
+ [\??sb#1]
+ [\c!number=\v!yes,
+ \c!page=\v!right, % anders worden marks te vroeg gereset !
+ %\c!before=,
+ %\c!after=,
+ #3]%
+ \expandafter\newif\csname if#2\endcsname % better a mode
+ \doglobal\increment\currentsectionblock
+ \setsectionblockenvironment{#1}{}%
+ \setevalue{\??sb #1}{\noexpand\dosetlocalsectionblock{\currentsectionblock}{#1}{#2}}%
+ \setvalue {\e!start#2}{\dostartsectionblock{#1}{#2}}%
+ \setvalue {\e!stop #2}{\dostopsectionblock}}
+
+\def\definesectionblock
+ {\dotripleargument\dodefinesectionblock}
+
+\def\sectionblocklabel#1#2%
+ {\@EA\ifx\csname\??ko#1\@@sectionblock\c!label\endcsname\relax
+ \labeltexts{#1}{#2}%
+ \else
+ \labeltexts{\getvalue{\??ko#1\@@sectionblock\c!label}}{#2}%
+ \fi}
+
+\dosetlocalsectionblock{2}{\v!bodypart}{\v!bodymatter} % hm, dirty
+
+\def\setsectiontype[#1]%
+ {\getvalue{\??sb#1}}
+
+\def\writesection#1#2#3% #3 -> \asciititle
+ {\bgroup
+ \edef\!!stringa{#1}%
+ \@EA\writestatus\@EA
+ {\!!stringa}
+ {\ifsectionnumber#2\else(#2)\fi\normalspace\asciititle}%
+ \egroup}
+
+\def\@@kolevel{1} \def\headlevel{\@@kolevel}
+
+\def\dohandlepagebreakAA#1%
+ {\ifnum\lastpenalty>0
+ \global\pagebreakdisabledtrue
+ \fi}
+
+% \setuphead[section][aligntitle=float] % permits title next to sidefloat
+%
+% \placefigure[left]{}{} \section{\dorecurse{10}{bagger }} \input tufte
+
+% \def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
+% {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
+% \getvalue{\??ko#1\c!before}%
+% % \whitespace vervangen door \noindent elders
+% \relax
+% \ifpagebreakdisabled
+% \global\pagebreakdisabledfalse
+% \else
+% \!!countb\getvalue{\??se\@@sectie\c!level}\relax
+% \ifnum\!!countb>\@@kolevel\relax
+% \!!counta20000
+% \multiply\!!countb 500
+% \advance\!!counta \!!countb
+% \dosomebreak{\penalty\!!counta}%
+% \else
+% \dosomebreak\allowbreak
+% \fi
+% \fi
+% \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
+% \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
+
+\chardef\somebreakmethod\plusone
+
+\def\dohandlepagebreakAB#1% will be replaced by a more clever (signaling) mechanism (in beta)
+ {\doifnotvalue{\??ko#1\c!aligntitle}\v!float\flushsidefloats
+ \getvalue{\??ko#1\c!before}%
+ % \whitespace vervangen door \noindent elders
+ \relax
+ \ifpagebreakdisabled
+ \global\pagebreakdisabledfalse
+ \else
+ \ifcase\somebreakmethod
+ % 0 = nothing
+ \or
+ % 1 = old weighted version
+ \!!countb\getvalue{\??se\@@sectie\c!level}\relax
+ \ifnum\!!countb>\@@kolevel\relax
+ \!!counta20000
+ \multiply\!!countb 500
+ \advance\!!counta \!!countb
+ \dosomebreak{\penalty\!!counta}%
+ \else
+ \dosomebreak\allowbreak % brr
+ \fi
+ \or
+ % 2 = strict version
+ \dosomebreak{\penalty\maxdimen}%
+ \else
+ % nothing
+ \fi
+ \fi
+ \doifvalue{\??ko#1\c!aligntitle}\v!float\indent
+ \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}}
+
+\def\dohandlepagebreakBB#1#2#3%
+ {%\doifinsetelse{\getvalue{\??tk#2\c!state}}{\v!normal,\v!start}
+ \doifelselayouttextline{#2}
+ {\doifvaluesomething{\??ko#1#3}
+ {\setuplayouttext[#2][\c!state=\getvalue{\??ko#1#3}]}}
+ \donothing}
+
+\def\dohandlepagebreakB#1%
+ {\doifvaluesomething{\??ko#1\c!page}
+ {\def\resetcurrentsectionmarks% toegevoegd, zie \page
+ {\resetsectionmarks{\previoussection\@@sectie}}%
+ \page[\getvalue{\??ko#1\c!page}]%
+ \dohandlepagebreakBB{#1}\v!header\c!header
+ \dohandlepagebreakBB{#1}\v!text \c!text
+ \dohandlepagebreakBB{#1}\v!footer\c!footer}}
+
+\def\dohandlepagebreakX#1% zie doordefinieren / boven
+ {\bgroup
+ \!!countb\@@kolevel
+ \advance\!!countb #1
+ \multiply\!!countb 500
+ \!!counta20000
+ \advance\!!counta \!!countb
+ \dosomebreak{\penalty\!!counta}%
+ \egroup}
+
+\newconditional\ignorehandlepagebreak
+
+\def\handlepagebreak#1%
+ {\ifconditional\ignorehandlepagebreak
+ \setfalse\ignorehandlepagebreak
+ \else
+ \dohandlepagebreakAA{#1}%
+ \ifnum\countervalue{\??se\previoussection\@@sectie}>\zerocount\relax
+ \ifnum\countervalue{\??se\@@sectie}>\zerocount
+ \dohandlepagebreakB{#1}%
+ \else
+ \doifnotvalue{\??ko#1\c!continue}\v!yes{\dohandlepagebreakB{#1}}%
+ \fi
+ \else
+ \dohandlepagebreakB{#1}%
+ \fi
+ \dohandlepagebreakAB{#1}%
+ \fi}
+
+\def\handlenopagebreak#1%
+ {\ifconditional\ignorehandlepagebreak
+ \setfalse\ignorehandlepagebreak
+ \else
+ \xdef\@@kolevel{\getvalue{\??se\@@sectie\c!level}}%
+ \nobreak
+ \fi}
+
+\def\localheadheight {\strutht}
+\def\localheaddepth {\strutdp}
+\def\localheadlineheight{\lineheight}
+
+\def\dolocalheadsetup#1% koppeling met standaard kopcommando / engels
+ {\forgetall % traag dus ...
+ \doifvaluesomething{\??ko#1\c!align} % wordt al expanded in spa
+ {\expanded{\setupalign[\getvalue{\??ko#1\c!align}]}}%
+ \doifvaluesomething{\??ko#1\c!tolerance} % wordt al expanded in spa
+ {\expanded{\setuptolerance[\getvalue{\??ko#1\c!tolerance}]}}%
+ \doifvalue{\??ko#1\c!strut}\v!no % wordt al expanded in spa
+ {\setnostrut}% new
+ \def\\{\crlf\strut\ignorespaces}}
+
+\def\localkopsetup{\localheadsetup} % kan tzt weg
+
+% todo: make them conditionals:
+
+\newif\ifincrementnumber
+\newif\ifreversesectionnumbers % todo: key/val
+\newif\ifsectionnumber \sectionnumbertrue
+\newif\ifdisplaysectionhead \displaysectionheadtrue
+\newif\ifplacehead
+\newif\ifemptyhead
+\newif\ifwritetolist
+\newif\ifheadnumber
+\newif\ifheadnumbercontent % niet meer wijzigen / wordt mode
+\newif\ifheadprefix
+\newif\ifsomeheadconversion
+
+% new
+
+\newconditional\@@resetsubheadnumbers
+
+\def\setsectieenkoppeling#1%
+ {\edef\@@koppeling{\getvalue{\??ko#1\c!coupling}}%
+ \edef\@@sectie{\getvalue{\??ko#1\c!section}}%
+ \doifnothing\@@koppeling
+ {\edef\@@koppeling{#1}}%
+ \doifnothing\@@sectie
+ {\edef\@@sectie{\getvalue{\??ko\@@koppeling\c!section}}}}
+
+% \handlepagebreak komt het eerst omdat eventueel
+% subpaginanummers moeten worden afgehandeld. Vervolgens
+% worden de nummers opgehoogd en referenties geset, dan
+% volgt de kop en tot slot de worden de marks en de prefix
+% geset.
+
+% \hoofdstuk {tekst}
+% \hoofdstuk tekst
+% \hoofdstuk
+
+\let\finalsectionnumber\empty
+
+\def\dofinalsectionnumber
+ {\ifundefined{\@@sectie\c!number}\else
+ \ifsomeheadconversion
+ \@@shortsectionnumber\@@sectie
+ \else
+ \getvalue{\@@sectie\c!number}%
+ \fi
+ \fi}
+
+\def\findsectionnumber#1#2#3% class file title / uti seperator --
+ {\begingroup
+ \setsectieenkoppeling{#1}%
+ \xdef\foundsectionnumber{1}%
+ \def\dolistelement##1##2##3##4##5##6%
+ {\doif{##1}{#1}
+ {\ConvertConstantAfter\doif{##4}{#3}
+ {\global\utilitydonetrue
+ \scratchcounter=0\getvalue{\??se\@@sectie\c!level}%
+ %
+ %\advance\scratchcounter 2
+ %\@EA\def\@EA\do\@EA####\@EA1\sectionseparator####2]%
+ % {\advance\scratchcounter -1
+ % \ifcase\scratchcounter
+ % \xdef\foundsectionnumber{####1}%
+ % \else
+ % \do####2]%
+ % \fi}%
+ %\do##5]}}}%
+ %
+ \def\do####1\relax % :/- clean
+ {\advance\scratchcounter \minusone
+ \ifcase\scratchcounter
+ \xdef\foundsectionnumber{\@@filterheadpart[####1]}%
+ \else
+ \@EAEAEA\do\@@filtertailpart[####1]\relax
+ \fi}%
+ \@EA\do\@@filternumberpart[##5]\relax}}}%
+ \setbox0\vbox
+ {\doutilities{#1}{#2}{#1}\relax\relax}%
+ \endgroup
+ \doifnumberelse\foundsectionnumber
+ {\doif\foundsectionnumber\!!zerocount
+ {\globallet\foundsectionnumber\!!plusone}}
+ {\globallet\foundsectionnumber\!!plusone}% an appendix or so
+ \setupheadnumber[#1][\foundsectionnumber]%
+ \setupheadnumber[#1][-1]}
+
+% deal with eigennummer
+
+\def\setsomeheadconversion#1#2%
+ {\someheadconversionfalse
+ \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
+ {\setgvalue{\??se\@@sectie\c!ownnumber}{#2}%
+ \def\someheadconversion{#2}}
+ {\letgvalue{\??se\@@sectie\c!ownnumber}\relax
+ \determineheadnumber[#1]%
+ \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\relax
+ \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\relax
+ \def\someheadconversion{#2}%
+ \else
+ \@EA\ifx\csname\??se\@@sectie\c!headconversion\endcsname\empty
+ \def\someheadconversion{#2}%
+ \else
+ \someheadconversiontrue
+ \def\someheadconversion%
+ {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\c!headconversion}}{#2}}%
+ \fi
+ \fi
+ \else
+ \@EA\ifx\csname\??se\@@sectie\@@sectionblock\c!headconversion\endcsname\empty
+ \def\someheadconversion{#2}%
+ \else
+ \someheadconversiontrue
+ \def\someheadconversion%
+ {\fullsectionnumber{#1}{\getvalue{\??se\@@sectie\@@sectionblock\c!headconversion}}{#2}}%
+ \fi
+ \fi}}
+
+\def\writtenfullsectionnumber
+ {\string\fullsectionnumber}
+
+\def\ignoredfullsectionnumber#1#2#3%
+ {#3}
+
+\let\storedfullsectionnumber\relax
+
+\def\expandablefullsectionnumber#1#2#3%
+ {\convertnumber{#2}{#3}}
+
+\unexpanded\def\naturalfullsectionnumber#1#2#3%
+ {\sectionblocklabel{#1}{\convertnumber{#2}{#3}}}
+
+\unexpanded\def\limitedfullsectionnumber#1#2#3%
+ {\convertnumber{#2}{#3}}
+
+\def\setfullsectionnumber#1%
+ {\doifelsevalue{#1\c!headconversion}\v!yes
+ {\doifelsevalue{#1\c!headlabel}\v!yes
+ {\let\fullsectionnumber\naturalfullsectionnumber}
+ {\let\fullsectionnumber\limitedfullsectionnumber}}
+ {\let\fullsectionnumber\ignoredfullsectionnumber}}
+
+\let\fullsectionnumber\limitedfullsectionnumber
+
+% \dodododoconstructhead IS NON GROUPED, SO WE NEED TO RESTORE !!!!
+%
+% dit kan dus beter \everyaroundhead zijn
+
+\let\currentheadnumber\empty
+\let\currentheadtext \empty
+
+\def\dodoconstructhead#1[#2]#3% [ref] {title}
+ {\doifelsevalue{\??ko#1\c!ownnumber}\v!yes
+ {\doquadruplegroupempty\dododoconstructhead{#1}{#2}{#3}}
+ {\fourthargumentfalse \dododoconstructhead{#1}{#2}{#3}{}}}
+
+\def\dododoconstructhead#1#2#3#4% [ref] {own} {title}
+ {\iffourthargument
+ \def\next{\dodododoconstructhead{#1}[#2]{#3}{#4}}%
+ \else
+ \def\next{\dodododoconstructhead{#1}[#2]{\finalsectionnumber}{#3}}%
+ \fi
+ \next}
+
+% pas met \ExpandFirstAfter op bij twee||taligheid
+
+\ifx\dohandleheadnumber\undefined
+ \let\dohandleheadnumber\firstofoneargument
+\fi
+
+\unexpanded\def\\{\space}
+
+\def\emptyheadcorrection % experimental, should work
+ {\ifemptyhead % well with na=\blank
+ \vskip-\lineheight
+ \dosomebreak\nobreak
+ \kern\zeropoint
+ \prevdepth\strutdepth
+ \fi}
+
+\let\localkopprefix\empty
+
+\def\headparameter#1% to do: everywhere in core-sec
+ {\executeifdefined{\??ko\currenthead#1}\empty}
+
+% todo: write to list etc in both args or in enclosing h/vbox else it gets
+% lost when no #1 or #2 is typeset
+
+% we will use variables here
+
+\def\dodododoconstructhead#1[#2]#3#4% [ref] {number} {title}
+ {\def\currenthead{#1}% dus #1 overal vervangen
+ \let\finalsectionnumber\dofinalsectionnumber % overloaded ungrouped -)
+ \unexpanded\def\\{\space}%
+ \edef\numberseparator{\spr{\getvalue{\??ko\currenthead\c!separator}}}%
+ \flushingcolumnfloatsfalse % {number} can be \finalsectionnumber
+ \someheadconversionfalse
+ \let\fullsectionnumber\limitedfullsectionnumber
+ \setsectieenkoppeling{#1}%
+ \doifelsevaluenothing{\??ko#1\c!prefix}
+ \headprefixfalse\headprefixtrue
+ \ifheadprefix
+ \doifelsevalue{\??ko#1\c!prefix}{+}
+ {\doifelsenothing{#2}
+ {\def\localkopprefix{+}}
+ {\def\localkopprefix{#2}}} % eigenlijk alleen eerste
+ {\edef\localkoprefix{\getvalue{\??ko#1\c!prefix}}}%
+ \else
+ \let\localkoprefix\empty
+ \fi
+ \placeheadtrue
+ \processaction
+ [\getvalue{\??ko#1\c!placehead}]
+ [ \v!yes=>\emptyheadfalse,
+ \v!empty=>\emptyheadtrue,
+ \v!no=>\emptyheadtrue\placeheadfalse]%
+ \doifelsevalue{\??ko#1\c!resetnumber}\v!no
+ {\setfalse\@@resetsubheadnumbers}%
+ {\settrue \@@resetsubheadnumbers}%
+ \writetolistfalse
+ \processaction
+ [\getvalue{\??ko#1\c!incrementnumber}]
+ [ \v!yes=>\incrementnumbertrue,
+ \v!no=>\incrementnumberfalse,
+ \v!list=>\incrementnumberfalse
+ % beware, since no numbers are used, no nested lists are
+ % possible here
+ \writetolisttrue,
+ \s!unknown=>{\ifx\currentproduct\empty
+ \findsectionnumber{#1}\commalistelement{#4}%
+ \fi
+ \incrementnumbertrue}]%
+ \edef\numberheaddistance {\getvalue{\??ko#1\c!distance}}%
+ \edef\numberheadalternative{\getvalue{\??ko#1\c!alternative}}%
+ \doifelsevalue{\??ko:\numberheadalternative}\v!horizontal
+ \displaysectionheadfalse
+ \displaysectionheadtrue
+ \ifsectionnumber
+ \doifelsevalue{\??sb\@@sectionblock\c!number}\v!yes
+ {\doifelsevalue{\??ko#1\c!number}\v!yes
+ \headnumbertrue
+ \headnumberfalse}
+ {\headnumberfalse}%
+ \else
+ \headnumberfalse
+ \fi
+ \defconvertexpanded\asciititle{\getvalue{\??ko#1\c!expansion}}{#4}%
+ %
+ \gdef\currentheadtext{#4}% scheelt args
+ \globallet\currentheadnumber\empty
+ %
+ \ifincrementnumber
+ \ifplacehead
+ \checknexthead\handlepagebreak{#1}%
+ \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
+ \ifheadprefix
+ %\setupreferencing[\c!prefix=-]%
+ \setupreferenceprefix[-]%
+ \fi
+ \getvalue{\e!next\@@sectie}%
+ \ifheadnumber
+ \setsomeheadconversion{#1}{#3}%
+ \let\fullsectionnumber\expandablefullsectionnumber
+ \xdef\currentheadnumber{\someheadconversion}%
+ \getvalue{\??ko#1\c!inbetween}%
+ \ifsomeheadconversion
+ \let\fullsectionnumber\naturalfullsectionnumber
+ \doplaceheadnumbertext
+ {#1}
+ {\setsectionlistreference{\@@sectie}{#1}%
+ \pagetype[\@@koppeling]%
+ \let\fullsectionnumber\writtenfullsectionnumber
+ \rawreference\s!sec{#2}{{\someheadconversion}{\asciititle}}%
+ \resetsectionmarks\@@sectie
+ \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
+ \let\fullsectionnumber\writtenfullsectionnumber
+ \dowritetolist\@@koppeling\someheadconversion{#4}\v!head}%
+ {\dohandleheadnumber\someheadconversion}% handle is new
+ {#4}
+ {\marking[#1]{#4}%
+ \let\fullsectionnumber\storedfullsectionnumber
+ \expanded{\marking[#1\v!number]{\someheadconversion}}}%
+ \let\fullsectionnumber\ignoredfullsectionnumber
+ \writesection{#1}{\someheadconversion}{#4}%
+ \else
+ \doplaceheadnumbertext
+ {#1}
+ {\setsectionlistreference{\@@sectie}{#1}%
+ \pagetype[\@@koppeling]%
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}%
+ \resetsectionmarks\@@sectie
+ \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
+ \dowritetolist\@@koppeling{#3}{#4}\v!head}
+ {\sectionblocklabel{#1}{\dohandleheadnumber{#3}}}% handle is new
+ {#4}
+ {\marking[#1]{#4}%
+ \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % rommelig omdat
+ {\edef\finalsectionnumber{#3}} % #3 al is toegekend
+ {\determineheadnumber[#1]}% migreert naar 3e argument
+ \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
+ \writesection{#1}{#3}{#4}%
+ \fi
+ \else
+ \getvalue{\??ko#1\c!inbetween}%
+ \doplaceheadtext
+ {#1}
+ {\setsectionlistreference{\@@sectie}{#1}%
+ \pagetype[\@@koppeling]%
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}%
+ \resetsectionmarks\@@sectie
+ \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
+ \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr, new per 18/1/2005, sometimes we need
+ {\dowritetolist\@@koppeling{#3}{#4}\v!head} % entries in the list (special purpose) but
+ {\dowritetolist\@@koppeling {}{#4}\v!head}% not in the header, ok we could pop in a command
+ }% \dowritetolist\@@koppeling{}{#4}\v!head}
+ {#4}
+ {\marking[#1]{#4}%
+ \doifelsevalue{\??ko#1\c!ownnumber}\v!yes % brrr
+ {\edef\finalsectionnumber{#3}}
+ {\determineheadnumber[#1]}%
+ % todo : geen markering (leeg maken)
+ \expanded{\marking[#1\v!number]{\finalsectionnumber}}}%
+ \writesection{#1}{-}{#4}%
+ \fi
+ \ifheadprefix
+ \setupreferenceprefix[\localkopprefix]%
+ \fi
+ \ifdisplaysectionhead
+ \dosomebreak\nobreak
+ \emptyheadcorrection
+ \getvalue{\??ko#1\c!after}%
+ \fi
+ \else
+ % Whatever future tex's will do with nodes,
+ % we assume a node here, because other \c!after=\blank
+ % will fail! See 'prikkels'
+ %
+ % so, maybe we need an explicit \kern
+ %
+ % do nothing / should be vbox to 0pt
+ %
+ \checknexthead\dohandlepagebreakB{#1}% toegevoegd ivm subpaginanr / tug sheets
+ \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
+ \ifheadprefix
+ \setupreferenceprefix[-]%
+ \fi
+ \getvalue{\e!next\@@sectie}%
+ \ifheadnumber
+ \setsomeheadconversion{#1}{#3}%
+ \let\fullsectionnumber\expandablefullsectionnumber
+ \xdef\currentheadnumber{\someheadconversion}%
+ \fi
+ \getvalue{\??ko#1\c!inbetween}% documenteren, is enige hook
+ \bgroup
+ \setsectionlistreference{\@@sectie}{#1}%
+ \resetsectionmarks\@@sectie
+ \marking[#1]{#4}%
+ \doifelsevalue{\??ko#1\c!ownnumber}\v!yes
+ {\edef\finalsectionnumber{#3}}
+ {\determineheadnumber[#1]}%
+ \expanded{\marking[#1\v!number]{\finalsectionnumber}}%
+ \pagetype[\@@koppeling]%
+% \bgroup
+ \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
+ \ifheadnumber
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}%
+ \dowritetolist\@@koppeling{#3}{#4}\v!head
+ \writesection{#1}{#3}{#4}%
+ \else % hm, also no own number
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}%
+ \dowritetolist\@@koppeling{}{#4}\v!head
+ \writesection{#1}{-}{#4}%
+ \fi
+ \egroup
+ \ifheadprefix
+ \setupreferenceprefix[\localkopprefix]%
+ \fi
+ \fi
+ \else
+ % todo : ref prefix
+ \ifplacehead
+ \checknexthead\handlepagebreak{#1}%
+ \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
+ \getvalue{\??ko#1\c!inbetween}%
+ \doplaceheadtext
+ {#1}
+ {\forcesectiontolist{#1}{#4}%
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}} % #3 ?
+ {#4}
+ %{}% new:
+ {\marking[#1]{#4}%
+ \marking[#1\v!number]{}}%
+ \writesection{#1}{-}{#4}%
+ \ifdisplaysectionhead
+ \dosomebreak\nobreak
+ \emptyheadcorrection
+ \getvalue{\??ko#1\c!after}%
+ \fi
+ \else
+ % do nothing / should be vbox to 0pt
+ \checknexthead\handlepagebreak{#1}%
+ \setsectieenkoppeling{#1}% can be changed when [voor=\somehead{..}...]
+ \getvalue{\??ko#1\c!inbetween}%
+ \forcesectiontolist{#1}{#4}%
+ \rawreference\s!sec{#2}{{#3}{\asciititle}}% #3 ?
+ \marking[#1]{#4}%
+ \marking[#1\v!number]{}%
+ \writesection{#1}{-}{#4}%
+ \fi
+ \fi
+ \flushingcolumnfloatstrue
+ \someheadconversionfalse
+ \setfalse\ignorehandlepagebreak
+ \let\fullsectionnumber\limitedfullsectionnumber
+ % ignorespaces prevents spaces creeping in when after=\dontleavehmode
+ \ifdisplaysectionhead\ignorespaces\else\expandafter\GotoPar\fi}
+
+\def\forcesectiontolist#1#2%
+ {\ifwritetolist
+ % we need to make sure that there is a number set (non
+ % zero) else the list mechanism cannot determine the
+ % level
+ \bgroup
+ \setupheadnumber[#1][+1]% traag, wordt \getvalue{\c!next...}
+ \setlistparameter\@@koppeling\c!expansion{\getvalue{\??ko#1\c!expansion}}%
+ \dowritetolist\@@koppeling{}{#2}\v!head
+ \setupheadnumber[#1][-1]% traag, wordt \getvalue{\c!previous...}
+ \egroup
+ \fi}
+
+\let\previoussectionformat\empty
+\let\currentsectionformat \empty
+
+\let\updatelistreferences \relax
+\let\updatedlistreferences\empty
+
+\def\setsectionlistreference#1#2%
+ {\ifnum\countervalue{\??se\previoussection{#1}}>0\relax
+ \xdef\previoussectionformat{\@@longformatnumber{\previoussection{#1}}}%
+ \else
+ \globallet\previoussectionformat\empty
+ \fi
+ \xdef\currentsectionformat{\@@longformatnumber{#1}}}
+
+\def\startlistreferences#1%
+ {\thisissomeinternal{\s!lst}{#1\currentsectionformat}%
+ \setxvalue{\s!lst:#1}{\realfolio}% to be sure
+ \setxvalue{\s!lst:#1\currentsectionformat}{\realfolio}%
+ \setxvalue{\e!previouslocal#1}{\s!lst:#1\previoussectionformat}%
+ \setxvalue{\e!currentlocal#1}{\s!lst:#1\currentsectionformat}%
+ \doifelse{\currentsectionformat}{}
+ {\setglobalcrossreference
+ {\e!previous#1}{}{\realfolio}{}}
+ {\setglobalsystemreference\rt!list
+ {\e!previous#1}{\getvalue{\e!previouslocal#1}}}%
+ \def\stoplistreferences{\dostoplistreferences{#1}}}
+
+\def\dostoplistreferences#1%
+ {\ifutilitydone
+ \addtocommalist{#1}\updatedlistreferences % nog global (\doglobal)
+ \globallet\updatedlistreferences\updatedlistreferences % een noodverbandje
+ \gdef\updatelistreferences%
+ {\def\docommand####1%
+ {\setglobalsystemreference\rt!list
+ {\e!previous####1}{\getvalue{\e!currentlocal####1}}}%
+ \processcommacommand[\updatedlistreferences]\docommand
+ \globallet\updatelistreferences\relax
+ \globallet\updatedlistreferences\empty}%
+ \fi}
+
+\let\stoplistreferences\relax
+
+\appendtoks
+ \updatelistreferences
+\to\aftereverypage
+
+% \prevdepth\strutdp % is belangrijk, vergelijk naast elkaar:
+%
+% \subject{test} \input tufte
+% \subject{test} \strut \input tufte
+% \subject{test} \placelist[...]
+
+% todo: kap
+
+% to be documented: \placeheadtext \placeheadnumber
+
+\unexpanded\def\placeheadtext
+ {\doquintupleempty\doplaceheadtextornumber
+ [\c!textstyle][\c!textcolor][\empty]}
+
+\unexpanded\def\placeheadnumber
+ {\doquintupleempty\doplaceheadtextornumber
+ [\c!numberstyle][\c!numbercolor][\v!number]}
+
+\def\doplaceheadtextornumber[#1][#2][#3][#4][#5]%
+ {\bgroup
+ \edef\@@sectie{\??ko\iffifthargument#5\else#4\fi}%
+ \dostartattributes\@@sectie\c!style\c!color\empty
+ \dontconvertfont
+ \dostartattributes\@@sectie{#1}{#2}\empty
+ \setupinterlinespace
+ \begstrut\getmarking[\mainmarking{#4#3}]\endstrut
+ \endgraf
+ \dostopattributes
+ \dostopattributes
+ \egroup}
+
+\chardef\headtimingmode=0
+
+% \chardef\headtimingmode=1 % 0 also works ok now too
+%
+% Martin Kolarik's problem:
+%
+% \setuphead[section][command=\doTitle]
+%
+% \def\doTitle#1#2%
+% {\ruledvbox{\forgetall \hsize=4cm
+% \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}}
+%
+% \section{test test test test test test test test test test
+% test test test test test test test}
+
+\newevery \everyheadstart \relax
+
+\def\placeheadmargintexts#1%
+ {\the\everyheadstart
+ \doifvalue{\??ko#1\c!margintext}\v!yes\placemargincontent}
+
+\def\doplaceheadtext#1#2#3#4%
+ {\beginheadplacement{#1}%
+ \ifemptyhead % = needed
+ \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
+ {\headnumbercontentfalse
+ \resetsystemmode\v!sectionnumber
+ #2}%
+ \makestrutofbox0
+ \else % = needed
+ \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
+ {\headnumbercontentfalse
+ \resetsystemmode\v!sectionnumber
+ % less interfering
+ \ifcase\headtimingmode\or#2\fi
+ % outerside font determines distance
+ \dosetfontattribute{\??ko#1}\c!style
+ % but we don't want color to influence user commands
+ % todo: get the if-else out of it
+ \getvalue{\??ko#1\c!command}
+ {} % no number
+ {\dostartattributes{\??ko#1}\c!style\c!color\empty
+ \dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
+ \dontconvertfont
+ \ifdisplaysectionhead
+ \setupinterlinespace
+ \else
+ \setupspacing
+ \fi
+ % \ifcase\headtimingmode#2\fi % can introduce cr
+ \getvalue{\??ko#1\c!commandbefore}%
+ \placeheadmargintexts{#1}% binnen #3?
+ \ifdisplaysectionhead
+ \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
+ {\setstrut
+ \begstrut
+ \ifcase\headtimingmode\hbox{#2}\fi
+ \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}%
+ \endstrut}% \hbox prevents break
+ \xdef\localheadheight {\the\strutht}%
+ \xdef\localheaddepth {\the\strutdp}%
+ \xdef\localheadlineheight{\the\lineheight}%
+ % == \globallet\localheaddepth\strutdepth
+ \else
+ \ifcase\headtimingmode#2\fi
+ \getvalue{\??ko#1\c!textcommand}%
+ {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#3}}%
+ \fi
+ \getvalue{\??ko#1\c!commandafter}%
+ \ifdisplaysectionhead\endgraf\fi
+ \dostopattributes
+ \dostopattributes}}%
+ \fi
+ \endheadplacement{#1}{#4}}
+
+\def\doplaceheadnumbertext#1#2#3#4#5% maybe move modes outside box
+ {\beginheadplacement{#1}%
+ \ifemptyhead % = needed
+ \setbox0=\ifvertical\vbox\else\hbox\fi to \zeropoint
+ {\doiftextelse{#3}
+ {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
+ {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
+ #2}%
+ \makestrutofbox0
+ \else % = needed
+ \setbox0=\ifvertical\vbox\else\hbox\fi % \vhbox
+ {\doiftextelse{#3}
+ {\setsystemmode \v!sectionnumber\headnumbercontenttrue }
+ {\resetsystemmode\v!sectionnumber\headnumbercontentfalse}%
+ % less interfering
+ \ifcase\headtimingmode\or#2\fi
+ % outerside font determines distance
+ \dosetfontattribute{\??ko#1}\c!style
+ % but we don't want color to influence user commands
+ \getvalue{\??ko#1\c!command}%
+ {\dostartattributes{\??ko#1}\c!style\c!color\empty
+ \dostartattributes{\??ko#1}\c!numberstyle\c!numbercolor\empty
+ % \getvalue{\??ko#1\c!commandbefore}% strange, why here? moved 21/11/2005
+ \placeheadmargintexts{#1}% binnen #3?
+ \ifdisplaysectionhead
+ % can be nilled with \setnostrut
+ \getvalue{\??ko#1\c!numbercommand}%
+ {\setstrut
+ \begstrut
+ \executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}%
+ \endstrut}%
+ \else
+ \getvalue{\??ko#1\c!numbercommand}%
+ {\executeifdefined{\??ko#1\c!deepnumbercommand}\firstofoneargument{#3}}%
+ \fi
+ \dostopattributes
+ \dostopattributes}
+ {\dostartattributes{\??ko#1}\c!style\c!color\empty
+ \dostartattributes{\??ko#1}\c!textstyle\c!textcolor\empty
+ \dontconvertfont
+ \ifdisplaysectionhead
+ \setupinterlinespace
+ \else
+ \setupspacing
+ \fi
+ % \ifcase\headtimingmode#2\fi % can introduce cr
+ \getvalue{\??ko#1\c!commandbefore}% makes more sense here
+ \placeheadmargintexts{#1}% binnen #3?
+ \ifdisplaysectionhead
+ \getvalue{\??ko#1\c!textcommand}% struts can be nilled with \setnostrut
+ {\setstrut
+ \begstrut
+ \ifcase\headtimingmode\hbox{#2}\fi
+ \executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}%
+ \endstrut}% \hbox prevents break
+ \xdef\localheadheight {\the\strutht}%
+ \xdef\localheaddepth {\the\strutdp}%
+ \xdef\localheadlineheight{\the\lineheight}%
+ % == \globallet\localheaddepth\strutdepth
+ \else
+ \ifcase\headtimingmode#2\fi % inside textcommand ?
+ \getvalue{\??ko#1\c!textcommand}%
+ {\executeifdefined{\??ko#1\c!deeptextcommand}\firstofoneargument{#4}}%
+ \fi
+ \getvalue{\??ko#1\c!commandafter}%
+ \ifdisplaysectionhead\endgraf\fi
+ \dostopattributes
+ \dostopattributes}}%
+ \fi
+ \endheadplacement{#1}{#5}}
+
+%D \starttyping
+%D \def\StretchedBox#1%
+%D {\framed
+%D [frame=off,offset=.5em,align=middle,width=broad]
+%D {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}}
+%D
+%D \definehead[MySubject][subject]
+%D \setuphead [MySubject][deeptextcommand=\StretchedBox]
+%D
+%D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
+%D \stoptyping
+
+\newsignal\headsignal
+\let\headlastlinewidth\!!zeropoint
+
+\def\beginheadplacement#1%
+ {\bgroup
+ \setsystemmode{#1}% to be documented
+ \ifgridsnapping\iftracegridsnapping\showstruts\fi\fi
+ \xdef\localheadheight {\the\strutht}%
+ \xdef\localheaddepth {\the\strutdp}%
+ \xdef\localheadlineheight{\the\lineheight}%
+ % == \globallet\localheaddepth\strutdp
+ \everypar\emptytoks % needed indeed
+ \noindent % ipv \whitespace elders, na \forgetall !
+ \bgroup
+ \doifinsetelse{\getvalue{\??ko#1\c!aligntitle}}{\v!yes,\v!float}% new
+ {\skip0 1\leftskip
+ \skip2 1\rightskip
+ \xdef\localheadskip{\the\skip0}%
+ \forgetall
+ \leftskip\skip0
+ \rightskip\skip2
+ \setlocalhsize\hsize\localhsize
+ \forgetbothskips}
+ {\globallet\localheadskip\!!zeropoint
+ \forgetall}%
+ \dontcomplain
+ \postponenotes
+ \iflocation\ifdisplaysectionhead\else\noninterferingmarks\fi\fi
+ \resetinteractionparameter\c!style
+ \resetinteractionparameter\c!color
+ \resetinteractionparameter\c!contrastcolor
+ \strictouterreferencestrue % tzt instelling
+ \def\localheadsetup{\dolocalheadsetup{#1}}%
+ \startsynchronization}
+
+% \setuphead[chapter] [style=\bfd,after=,hang=line] % fit broad 2
+% \setuphead[section] [style=\bfc,after=,hang=line]
+% \setuphead[subsection] [style=\bfb,after=,hang=line]
+% \setuphead[subsubsection] [style=\bfa,after=,hang=line]
+% \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
+%
+% \chapter {Test} \input tufte \page
+% \section {Test} \input tufte \page
+% \subsection {Test} \input tufte \page
+% \subsubsection {Test} \input tufte \page
+% \subsubsubsection{Test} \input tufte \page
+%
+% \chapter {Test\\Test} \input tufte \page
+% \section {Test\\Test} \input tufte \page
+% \subsection {Test\\Test} \input tufte \page
+% \subsubsection {Test\\Test} \input tufte \page
+% \subsubsubsection{Test\\Test} \input tufte \page
+
+\def\hangheadplacement
+ {\scratchdimen\localheadlineheight
+ \bgroup
+ \openlineheight\scratchdimen
+ \scratchdimen\ht0
+ \advance\scratchdimen\dp0
+ \getnoflines\scratchdimen
+ \advance\noflines\minusone
+ \expanded{\egroup\noflines\the\noflines}% brrr
+ \setbox0\hbox{\lower\noflines\scratchdimen\box0}%
+ \scratchdimen\ht0
+ \advance\scratchdimen\dp0
+ \advance\scratchdimen-\localheadheight
+ \advance\scratchdimen+\strutdp
+ \ht0 \strutht
+ \dp0 \strutdp
+ \edef\localheaddepth{\the\strutdp}}
+
+\newconditional\continuoussectionhead % oeps, \newif\ifcontinuoushead got lost
+
+\def\endheadplacement#1#2%
+ {\doifelsevalue{\??rf#1\c!state}\v!start
+ {\doifvaluenothing{\??ko#1\c!file}{\autocrossdocumentfalse}}
+ {\autocrossdocumentfalse}%
+ % no message needed here, should be a proper switch
+ \noflines\zerocount
+ \ifdisplaysectionhead
+ % new (tod tight == one following line up)
+ \processaction
+ [\getvalue{\??ko#1\c!hang}]
+ [ \v!line=>\hangheadplacement\noflines\zerocount,
+ \v!broad=>\hangheadplacement\getnoflines\scratchdimen,
+ \v!fit=>\hangheadplacement\getrawnoflines\scratchdimen,
+ \v!none=>\noflines\zerocount,
+ \v!default=>\noflines\zerocount,
+ \v!unknown=>\hangheadplacement\noflines0\commalistelement\advance\noflines\minusone]%
+ % so far
+ \let\headlastlinewidth\!!zeropoint
+ \snaptogrid[\getvalue{\??ko#1\c!grid}]\hbox
+ {\hskip\localheadskip
+ \hskip\getvalue{\??ko#1\c!margin}\relax
+ \iflocation
+ \ifautocrossdocument
+ \doifreferencefoundelse{\getvalue{\??ko#1\c!file}::#1}
+ {\edef\currentinnerreference{\s!aut:\currenttextreference}% stored in
+ \gotoouterlocation{}{\box0}} % text slot
+ {\hbox{\box0}}%
+ \else
+ \hbox{\box0}%
+ \fi
+ \else
+ \hbox{\box0}%
+ \fi}%
+ \doflushnotes % new, not really needed
+ \endgraf
+ \ifvmode
+ \ifnum\noflines>\zerocount
+ \dorecurse\noflines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}%
+ \fi
+ \nointerlineskip
+ \dosomebreak\nobreak
+ \fi
+ #2%
+ \else
+ \strut
+ \doflushnotes % new, here since we're in par mode
+ \iflocation
+ \ifautocrossdocument
+ \hhboxindent=\ifconditional\continuoussectionhead\headlastlinewidth\else\zeropoint\fi
+ \unhhbox0\with{\gotobox{\box\hhbox}[\getvalue{\??ko#1\c!file}::#1]}%
+ \advance\lasthhboxwidth by \numberheaddistance
+ \xdef\headlastlinewidth{\the\lasthhboxwidth}%
+ \else
+ \unhbox0
+ \globallet\headlastlinewidth\!!zeropoint
+ \fi
+ \else
+ \unhbox0
+ \globallet\headlastlinewidth\!!zeropoint
+ \fi
+ #2%
+ \dimen0=\numberheaddistance
+ \hskip\dimen0 \!!plus \dimen0 \!!minus .25\dimen0
+ \hskip\headsignal\ignorespaces
+ \fi
+ \ifdisplaysectionhead \ifvmode
+ \ifgridsnapping % important, font related depth, see comment
+ \prevdepth\strutdp
+ \else
+ \prevdepth\localheaddepth
+ \fi
+ \fi \fi
+ \stopsynchronization
+ \egroup
+ \egroup
+ \ifdisplaysectionhead
+ \dochecknextindentation{\??ko#1}%
+ \else
+ \nonoindentation % recently added, was a bug
+ \fi}
+
+\def\checknexthead#1#2% nog optioneel
+ {\ifhmode
+ \scratchcounter=\lastpenalty\unpenalty % no beauty in this
+ \ifdim\lastskip=\headsignal
+ \handlenopagebreak{#1}%
+ \global\settrue\continuoussectionhead
+ \else
+ \penalty\scratchcounter
+ \global\setfalse\continuoussectionhead
+ #1{#2}%
+ \fi
+ \else
+ \global\setfalse\continuoussectionhead
+ #1{#2}%
+ \fi}
+
+\def\dosetupheadnumber[#1][#2#3]% todo: = (don't reset)
+ {\bgroup
+ \setsectieenkoppeling{#1}%
+ \doifinstringelse{#2}{+-}
+ {\doifelsenothing{#3}
+ {\@@nextsectionnumber\@@sectie}
+ {\!!counta=#2#3\relax
+ \advance\!!counta \@@sectionvalue\@@sectie
+ \@@setsectionnumber\@@sectie\!!counta}}
+ {\@@setsectionnumber\@@sectie{#2#3}}%
+ \egroup}
+
+\def\setupheadnumber
+ {\dodoubleargument\dosetupheadnumber}
+
+\def\currentheadnumber{0}
+
+\def\determineheadnumber[#1]%
+ {\bgroup
+ \setsectieenkoppeling{#1}%
+ \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
+ \egroup}
+
+\def\complexheadnumber[#1]%
+ {\bgroup
+ \edef\currentheadnumber{#1}%
+ \doifinsetelse{-}{#1} % br undocumented
+ {\removefromcommalist{-}\currentheadnumber % br
+ \setsectieenkoppeling\currentheadnumber
+ \setupsection[\@@sectie][\c!previousnumber=\v!no]}%
+ {\setsectieenkoppeling\currentheadnumber}%
+ \xdef\currentheadnumber{\@@sectionvalue{\@@sectie}}%
+ \doifnot{\currentheadnumber}{0}{\finalsectionnumber}%
+ \egroup}
+
+\def\simpleheadnumber
+ {\currentheadnumber}
+
+\definecomplexorsimple\headnumber
+
+\def\alinea
+ {\par}
+
+% nice testcase
+%
+% \setupheads[aligntitle=yes]
+%
+% \startnarrower
+% \subject{\dorecurse{100}{x }}
+% \section{\dorecurse{100}{x }}
+% \input tufte \par
+% \setupheads[alternative=inmargin]
+% \subject{\dorecurse{100}{x }}
+% \section{\dorecurse{100}{x }}
+% \input tufte \par
+% \stopnarrower
+
+\let\numberheadalternative\v!normal
+
+\def\defineheadplacement
+ {\dodoubleargument\dodefineheadplacement}
+
+\def\dodefineheadplacement[#1][#2]% #3#4
+ {\setvalue{\??ko:#1}{#2}%
+ \setvalue{\??ko::#1}}
+
+\def\normalplacehead
+ {\executeifdefined
+ {\??ko::\numberheadalternative}
+ {\getvalue{\??ko::\v!normal}}}
+
+\defineheadplacement[\v!paragraph][\v!vertical]#1#2%
+ {\vbox
+ {\localheadsetup
+ \begstrut\ifheadnumbercontent#1\hskip\numberheaddistance\fi#2}}
+
+% \defineheadplacement[\v!normal][\v!vertical]#1#2%
+% {\ifheadnumbercontent
+% \setbox0\hbox{{#1}\hskip\numberheaddistance}%
+% \vbox
+% {\localheadsetup
+% \hangindent 1\wd0
+% \hangafter 1
+% \noindent
+% \unhbox0 % don't use \strut's here!
+% #2}%
+% \else
+% \vbox
+% {\localheadsetup\noindent#2}%
+% \fi}
+%
+% enhanced version:
+
+% \setuphead
+% [chapter]
+% [numberwidth=2cm,hang=line,after={\blank[3*line]}]
+%
+% \chapter{Oeps oeps oeps} \input tufte \section{Oeps}
+% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
+
+\defineheadplacement[\v!normal][\v!vertical]#1#2%
+ {\vbox
+ {\localheadsetup
+ \edef\headwidth {\headparameter\c!width }%
+ \edef\headnumberwidth{\headparameter\c!numberwidth}%
+ \edef\headtextwidth {\headparameter\c!textwidth }%
+ \ifheadnumbercontent
+ \ifx\headwidth\empty
+ \else
+ \ifx\headnumberwidth\empty
+ \ifx\headtextwidth\empty\else
+ \edef\headnumberwidth{\the\dimexpr\headwidth-\headtextwidth\relax}%
+ \fi
+ \else
+ \ifx\headtextwidth\empty
+ \edef\headtextwidth{\the\dimexpr\headwidth-\headnumberwidth\relax}%
+ \fi
+ \fi
+ \hsize\headwidth
+ \fi
+ \ifx\headnumberwidth\empty\else
+ \let\numberheaddistance\!!zeropoint
+ \fi
+ \setbox\scratchbox\hbox \ifx\headnumberwidth\empty\else to \headnumberwidth\fi{{#1}}%
+ \scratchdimen\dimexpr\wd\scratchbox+\numberheaddistance\relax
+ \ifx\headtextwidth\empty\else
+ \hsize\dimexpr\scratchdimen+\headparameter\c!textwidth\relax
+ \fi
+ \hangindent\scratchdimen
+ \hangafter \plusone
+ \noindent
+ \box\scratchbox\hskip\numberheaddistance
+ \else
+ \ifx\headtextwidth\empty
+ \ifx\headwidth\empty
+ \else
+ \hsize\headwidth
+ \fi
+ \else
+ \hsize\headtextwidth
+ \fi
+ \noindent
+ \fi
+ #2}}
+
+\def\placeheadmargin#1#2%
+ {\vbox
+ {\localheadsetup
+ \begstrut % use one \strut here!
+ \dontleavehmode % in case there is no strut, else side effects with llap
+ \ifheadnumbercontent
+ \llap{\hbox to 5em{\hfill{#1}\hskip\localheadskip\hskip\leftmargindistance}}% introduces whitespace
+ % maybe better:
+ % \inleftmargin{\hbox{\hss{#1}\hskip\localheadskip}}%
+ \fi
+ {#2}}}
+
+\defineheadplacement[\v!inmargin][\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
+\defineheadplacement[\v!margin] [\v!vertical]#1#2{\placeheadmargin{#1}{#2}}
+
+\defineheadplacement[\v!middle][\v!vertical]#1#2%
+ {\vbox
+ {\localheadsetup
+ \veryraggedcenter
+ \let\\\endgraf
+ \let\crlf\endgraf
+ \ifheadnumbercontent\strut#1\par\fi\begstrut#2}}
+
+\defineheadplacement[\v!text][\v!horizontal]#1#2%
+ {\bgroup
+ \localheadsetup % no stretch in distance
+ \ifheadnumbercontent{#1}\kern\numberheaddistance\fi{\begstrut#2}%
+ \egroup}
+
+\def\placeheadlohi#1#2#3%
+ {\ifheadnumbercontent
+ \setbox0\hbox{#2}
+ \setbox2=#1{\localheadsetup\advance\hsize-\wd0\relax#3}%
+ \hbox{\box0\hskip\numberheaddistance\box2}%
+ \else
+ #1{\localheadsetup\noindent#3}%
+ \fi}
+
+% onder/boven lijnt het nummer op de onderste/bovenste regel
+% uit van een meerregelige kop
+
+\defineheadplacement[\v!bottom][\v!vertical]#1#2{\placeheadlohi\vbox{#1}{#2}}
+\defineheadplacement[\v!top] [\v!vertical]#1#2{\placeheadlohi\vtop{#1}{#2}}
+
+% default == instellingen
+% koppeling == koppen, breaks, marks, enz.
+% sectie == nummering
+
+\let\@@kolist=\empty
+
+\def\dododefinehead#1#2% % don't preset prefix to much
+ {\presetlabeltext[#1=]%
+ \getparameters
+ [\??ko#1]
+ [\c!numberstyle=\getvalue{\??ko#1\c!style},
+ \c!textstyle=\getvalue{\??ko#1\c!style},
+ \c!numbercolor=\getvalue{\??ko#1\c!color},
+ \c!textcolor=\getvalue{\??ko#1\c!color}]%
+ % deeptextcommand and deepnumbercommand are left undefined !
+ \doifassignmentelse{#2}
+ {\getparameters
+ [\??ko#1]
+ [\c!section=\getvalue{\??ko\getvalue{\??ko#1\c!coupling}\c!section},
+ \c!default=,
+ \c!coupling=,
+ \c!prefix=,
+ \c!before=,
+ \c!after=,
+ \c!distance=\!!zeropoint,
+ \c!page=,
+ \c!header=,
+ \c!text=,
+ \c!footer=,
+ \c!style=,
+ \c!numbercommand=,
+ \c!textcommand=,
+ \c!ownnumber=\v!no,
+ \c!number=\v!yes,
+ \c!color=,
+ \c!continue=\v!yes,
+ \c!placehead=\v!yes,
+ \c!resetnumber=\v!yes,
+ \c!incrementnumber=\v!yes,
+ \c!alternative=\@@koalternative,
+ \c!command=\normalplacehead,
+ \c!separator=\@@koseparator,
+ \c!stopper=\@@kostopper,
+ \c!align=\@@koalign,
+ \c!aligntitle=\@@koaligntitle,
+ \c!tolerance=\@@kotolerance,
+ \c!indentnext=\@@koindentnext,
+ \c!strut=\@@kostrut,
+ \c!hang=\@@kohang,
+ \c!file=,
+ \c!expansion=,
+ \c!grid=,
+ \c!margintext=,
+ \c!margin=\@@komargin,
+ #2]%
+ \ConvertToConstant\doifnot{#1}{\getvalue{\??ko#1\c!default}}
+ {\doifsomething{\getvalue{\??ko#1\c!default}}
+ {\copyparameters
+ [\??ko#1][\??ko\getvalue{\??ko#1\c!default}]
+ [\c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
+ \c!header,\c!text,\c!footer,\c!separator,\c!stopper,\c!resetnumber,
+ \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
+ \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
+ % new per 20/03/3002 (o-pbu-l) / was too confusing
+ % \c!numberstyle,\c!textstyle,\c!expansion,
+ % again too confusing
+ \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
+ \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]}}%
+ \getparameters[\??ko#1][#2]%
+ \doifsomething{\getvalue{\??ko#1\c!section}}
+ {\doifelsemarking{#1}% \doifundefined{\??mk#1}
+ {}% marking #1 already defined
+ {\definemarking[#1]%
+ \couplemarking[#1][\getvalue{\??ko#1\c!section}]%
+ \definemarking[#1\v!number]%
+ \couplemarking[#1\v!number][\getvalue{\??ko#1\c!section}]}}%
+ \doifundefined{\??li#1}{\definelist[#1]}}
+ {\ConvertToConstant\doifelse{#1}{#2}
+ {\doifundefined{\??li#1}{\definelist[#1]}}
+ {\copyparameters
+ [\??ko#1][\??ko#2]
+ [\c!level,\c!section,\c!coupling,\c!prefix,
+ \c!before,\c!after,\c!command,\c!file,\c!page,\c!continue,
+ \c!separator,\c!stopper,
+ \c!header,\c!text,\c!footer,\c!resetnumber,
+ \c!number,\c!ownnumber,\c!placehead,\c!incrementnumber,
+ \c!style,\c!color,\c!distance,\c!alternative,\c!indentnext,
+ % new per 20/03/3002 (o-pbu-l) / was too confusing
+ % \c!numberstyle,\c!textstyle,\c!expansion,
+ % again too confusing
+ \c!align,\c!aligntitle,\c!tolerance,\c!grid,\c!hang,\c!strut,
+ \c!numbercommand,\c!textcommand,\c!margintext,\c!margin]%
+ \getparameters[\??ko#1][\c!expansion=]% iig een value, rather fuzzy
+ \definemarking[#1][#2]%
+ \definemarking[#1\v!number][#2\v!number]%
+ \doifundefined{\??li#1}{\definelist[#1][#2]}}}%
+ \addtocommalist{#1}\@@kolist
+ \setevalue{\??sk#1}{\getvalue{\??ko#1\c!coupling}}%
+ \setevalue{\??by#1}{\getvalue{\??ko#1\c!section}}%
+ \setevalue{\??by\v!by#1}{\getvalue{\??ko#1\c!section}}%
+ \setvalue{#1}{\dodoubleempty\doconstructhead[#1]}}
+
+\def\dodefinehead[#1][#2]%
+ {\doifelsenothing{#2}
+ {% todo: message that it's an invalid definition
+ \setvalue{#1}{\endgraf[#1]\kern.5em}}
+ {\doifassignmentelse{#2}
+ {\dododefinehead{#1}{#2}}
+ {\doifdefined{\??ko#2\c!section}
+ {\dododefinehead{#1}{#2}}}}}
+
+\def\definehead
+ {\dodoubleemptywithset\dodefinehead}
+
+\def\doconstructhead[#1][#2]%
+ {\dowithpargument{\dodoconstructhead{#1}[#2]}}
+
+\def\dosetuphead[#1][#2]%
+ {\getparameters[\??ko#1][#2]%
+ % The next check prevents hard to trace problems. I once
+ % set \c!command to nothing and (quite natural) got the
+ % wrong references etc. The whole bunch should be boxed!
+ \expandafter\defconvertedcommand\expandafter\ascii\csname\??ko#1\c!command\endcsname
+ \doifnothing\ascii{\setvalue{\??ko#1\c!command}{\normalplacehead}}}
+
+\def\setuphead
+ {\dodoubleargumentwithset\dosetuphead}
+
+\def\dosetupheads[#1]%
+ {\getparameters[\??ko][#1]%
+ \doifelse{\@@kosectionnumber}\v!yes\sectionnumbertrue\sectionnumberfalse}
+
+\def\setupheads
+ {\dosingleargument\dosetupheads}
+
+\def\systemsuppliedchapter {\getvalue{\v!chapter}}
+\def\systemsuppliedtitle {\getvalue{\v!title}}
+
+% a left over
+
+\def\complexbijlage[#1]#2%
+ {\page[\v!right]
+ \setuppagenumbering[\c!state=\v!stop]
+ \systemsuppliedchapter[#1]{#2}
+ \page[\v!right]
+ \setuppagenumbering[\c!state=\v!start]
+ \setuppagenumbering[\c!number=1]}
+
+\setvalue{\v!appendix}%
+ {\complexorsimpleempty\bijlage}
+
+\setupheads
+ [\c!alternative=\v!normal,
+ \c!sectionnumber=\v!yes,
+ \c!separator=.,
+ \c!stopper=,
+ \c!limittext=\v!yes,
+ \c!align=,
+ \c!aligntitle=,
+ \c!tolerance=,
+ \c!strut=,
+ \c!indentnext=\v!no,
+ \c!margin=\zeropoint,
+ \c!hang=\v!none,
+ \c!command=]
+
+\definesectionblock [\v!frontpart] [\v!frontmatter] [\c!number=\v!no]
+\definesectionblock [\v!bodypart] [\v!bodymatter] [\c!number=\v!yes]
+\definesectionblock [\v!appendix] [\v!appendices] [\c!number=\v!yes]
+\definesectionblock [\v!backpart] [\v!backmatter] [\c!number=\v!no]
+
+\definesection[\s!section-1] % part
+\definesection[\s!section-2] % chapter
+\definesection[\s!section-3] % section
+\definesection[\s!section-4] % subsection
+\definesection[\s!section-5] % subsubsection
+\definesection[\s!section-6] % subsubsubsection
+\definesection[\s!section-7] % subsubsubsubsection
+
+% \c!eigennummer ook hier?
+
+\definehead
+ [\v!part]
+ [\c!section=\s!section-1,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!chapter]
+ [\c!section=\s!section-2,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!section]
+ [\c!section=\s!section-3,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!subsection]
+ [\c!section=\s!section-4,
+ \c!default=\v!section,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!subsubsection]
+ [\c!section=\s!section-5,
+ \c!default=\v!subsection,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!subsubsubsection]
+ [\c!section=\s!section-6,
+ \c!default=\v!subsubsection,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!subsubsubsubsection]
+ [\c!section=\s!section-7,
+ \c!default=\v!subsubsubsection,
+ \c!ownnumber=\v!no]
+
+\definehead
+ [\v!title]
+ [\c!coupling=\v!chapter,
+ \c!default=\v!chapter,
+ \c!incrementnumber=\v!no]
+
+\definehead
+ [\v!subject]
+ [\c!coupling=\v!section,
+ \c!default=\v!section,
+ \c!incrementnumber=\v!no]
+
+\definehead
+ [\v!subsubject]
+ [\c!coupling=\v!subsection,
+ \c!default=\v!subsection,
+ \c!incrementnumber=\v!no]
+
+\definehead
+ [\v!subsubsubject]
+ [\c!coupling=\v!subsubsection,
+ \c!default=\v!subsubsection,
+ \c!incrementnumber=\v!no]
+
+\definehead
+ [\v!subsubsubsubject]
+ [\c!coupling=\v!subsubsubsection,
+ \c!default=\v!subsubsubsection,
+ \c!incrementnumber=\v!no]
+
+\definehead
+ [\v!subsubsubsubsubject]
+ [\c!coupling=\v!subsubsubsubsection,
+ \c!default=\v!subsubsubsubsection,
+ \c!incrementnumber=\v!no]
+
+\setupsection
+ [\s!section-2]
+ [\v!appendix\c!conversion=\v!Character,
+ \c!previousnumber=\v!no]
+
+\setuphead
+ [\v!part]
+ [\c!placehead=\v!no]
+
+\setuphead
+ [\v!chapter]
+ [\v!appendix\c!label=\v!appendix,
+ \v!bodypart\c!label=\v!chapter] % bijlageconversie=\Character
+
+\setuphead
+ [\v!section]
+ [\v!appendix\c!label=\v!section,
+ \v!bodypart\c!label=\v!section] % bijlageconversie=\Character
+
+\setuphead
+ [\v!subsection]
+ [\v!appendix\c!label=\v!subsection,
+ \v!bodypart\c!label=\v!subsection] % bijlageconversie=\Character
+
+\setuphead
+ [\v!subsubsection]
+ [\v!appendix\c!label=\v!subsubsection,
+ \v!bodypart\c!label=\v!subsubsection] % bijlageconversie=\Character
+
+\setuphead
+ [\v!part,\v!chapter]
+ [%\c!align=,
+ %\c!indentnext=\v!no,
+ \c!continue=\v!no,
+ \c!page=\v!right,
+ \c!header=,
+ \c!style=\tfc,
+ \c!distance=.75em,
+ \c!before={\blank[2*\v!big]},
+ \c!after={\blank[2*\v!big]}]
+
+\setuphead
+ [\v!section]
+ [%\c!align=,
+ %\c!indentnext=\v!no,
+ \c!style=\tfa,
+ \c!distance=.75em,
+ \c!before={\blank[2*\v!big]},
+ \c!after=\blank]
+
+\setuphead % nieuw
+ [\v!subsection]
+ [\c!page=]
+
+\definecombinedlist
+ [\v!content]
+ [\v!part,
+ \v!chapter,
+ \v!section,
+ \v!subsection,
+ \v!subsubsection,
+ \v!subsubsubsection,
+ \v!subsubsubsubsection]
+ [\c!level=\v!subsubsubsubsection,
+ \c!criterium=\v!local]
+
+\setuplist
+ [\v!part]
+ [\c!before={\blank\page[\v!preference]},
+ \c!after=\blank,
+ \c!label=\v!yes,
+ \c!separator=:,
+ \c!distance=1em]
+
+\setuplist
+ [\v!chapter]
+ [\c!before={\blank\page[\v!preference]},
+ \c!after=]
+
+\setuplist [\v!part] [\c!width=0em]
+\setuplist [\v!chapter] [\c!width=2em]
+\setuplist [\v!section] [\c!width=3em]
+\setuplist [\v!subsection] [\c!width=4em]
+\setuplist [\v!subsubsection] [\c!width=5em]
+\setuplist [\v!subsubsubsection] [\c!width=6em]
+\setuplist [\v!subsubsubsubsection] [\c!width=7em]
+
+% hm
+
+\setuppagenumbering % na instellen hoofdteksten !
+ [\c!alternative=\v!singlesided,
+ \c!location={\v!header,\v!middle},
+ \c!conversion=\v!numbers,
+ \c!width=, % in geval van \v!marginedge
+ \c!left=,
+ \c!right=,
+ \c!way=\v!by\v!part,
+ \c!text=,
+ \v!chapter\v!number=\v!no, % v
+ \v!part\v!number=\v!yes, % v
+ \c!numberseparator=--,
+ \c!textseparator=\tfskip,
+ \c!state=\v!start,
+ \c!command=,
+ \c!strut=\v!yes, % nieuw
+ \c!style=, % \v!normal, % empty, otherwise conflict
+ \c!color=]
+
+\protect \endinput
diff --git a/tex/context/base/core-snc.tex b/tex/context/base/core-snc.tex
index ac6960f4d..99c7d58f6 100644
--- a/tex/context/base/core-snc.tex
+++ b/tex/context/base/core-snc.tex
@@ -2,7 +2,7 @@
%D [ file=core-snc,
%D version=2003.12.01,
%D title=\CONTEXT\ Core Macros,
-%D subtitle=Synchronization Support,
+%D subtitle=Synchronization,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Synchronization}
+\writestatus{loading}{ConTeXt Core Macros / Synchronization}
\unprotect
diff --git a/tex/context/base/core-spa.lua b/tex/context/base/core-spa.lua
index 5f4df72a2..0f308b19c 100644
--- a/tex/context/base/core-spa.lua
+++ b/tex/context/base/core-spa.lua
@@ -6,13 +6,43 @@ if not modules then modules = { } end modules ['core-spa'] = {
license = "see context related readme files"
}
--- todo: test without unset
+-- this code dates from the beginning and is kind of experimental; it
+-- will be optimized and improved soon
-local format, insert = string.format, table.insert
-local utfchar = utf.char
+local next, type = next, type
+local format, gmatch, concat = string.format, string.gmatch, table.concat
+local texsprint, texlists = tex.sprint, tex.lists
+
+local ctxcatcodes = tex.ctxcatcodes
-- vertical space handler
+local trace_vbox_vspacing = false trackers.register("nodes.vbox_vspacing", function(v) trace_vbox_vspacing = v end)
+local trace_page_vspacing = false trackers.register("nodes.page_vspacing", function(v) trace_page_vspacing = v end)
+local trace_collect_vspacing = false trackers.register("nodes.collect_vspacing", function(v) trace_collect_vspacing = v end)
+local trace_vspacing = false trackers.register("nodes.vspacing", function(v) trace_vspacing = v end)
+
+local has_attribute = node.has_attribute
+local unset_attribute = node.unset_attribute
+local set_attribute = node.set_attribute
+local slide_node_list = node.slide
+local free_node = node.free
+local copy_node = node.copy
+local traverse_nodes = node.traverse
+local insert_node_before = node.insert_before
+local insert_node_after = node.insert_after
+local remove_node = nodes.remove
+local make_penalty_node = nodes.penalty
+local count_nodes = nodes.count
+local node_ids_to_string = nodes.ids_to_string
+
+local glyph = node.id("glyph")
+local penalty = node.id("penalty")
+local kern = node.id("kern")
+local glue = node.id('glue')
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+
vspacing = vspacing or { }
vspacing.categories = {
@@ -26,12 +56,14 @@ vspacing.categories = {
[7] = 'goback',
}
+local categories = vspacing.categories
+
function vspacing.tocategories(str)
local t = { }
- for s in str:gmatch("[^, ]") do
+ for s in gmatch(str,"[^, ]") do
local n = tonumber(s)
if n then
- t[vspacing.categories[n]] = true
+ t[categories[n]] = true
else
t[b] = true
end
@@ -43,7 +75,7 @@ function vspacing.tocategory(str)
if type(str) == "string" then
return set.tonumber(vspacing.tocategories(str))
else
- return set.tonumber({ [vspacing.categories[str]] = true })
+ return set.tonumber({ [categories[str]] = true })
end
end
@@ -51,90 +83,87 @@ vspacing.data = vspacing.data or { }
vspacing.data.map = vspacing.data.map or { }
vspacing.data.skip = vspacing.data.skip or { }
-input.storage.register(false, "vspacing/data/map", vspacing.data.map, "vspacing.data.map")
-input.storage.register(false, "vspacing/data/skip", vspacing.data.skip, "vspacing.data.skip")
+storage.register("vspacing/data/map", vspacing.data.map, "vspacing.data.map")
+storage.register("vspacing/data/skip", vspacing.data.skip, "vspacing.data.skip")
do
+ vspacing.fixed = false
+
local map = vspacing.data.map
local skip = vspacing.data.skip
- vspacing.fixed = false
- vspacing.trace = false
-
local multiplier = lpeg.C(lpeg.S("+-")^0 * lpeg.R("09")^1) * lpeg.P("*")
local category = lpeg.P(":") * lpeg.C(lpeg.P(1)^1)
local keyword = lpeg.C((1-category)^1)
-
local splitter = (multiplier + lpeg.Cc(1)) * keyword * (category + lpeg.Cc(false))
- function vspacing.analyse(str)
- local category, order, penalty, command, fixed = { }, 0, 0, { }, vspacing.fixed
- local function analyse(str)
- for s in str:gmatch("([^ ,]+)") do
- local amount, keyword, detail = splitter:match(s)
- if keyword then
- local mk = map[keyword]
- if mk then
- analyse(mk)
- elseif keyword == "fixed" then
- fixed = true
- elseif keyword == "flexible" then
- fixed = false
- elseif keyword == "category" then
- -- is a set
- local n = tonumber(detail)
- if n then
- category[vspacing.categories[n]] = true
- else
- category[detail] = true
- end
- elseif keyword == "order" then
- -- last one counts
- order = tonumber(detail) or 0
- elseif keyword == "penalty" then
- -- last one counts
- penalty = tonumber(detail) or 0
- elseif keyword == "skip" then
- -- last one counts
- command[#command+1] = { 1, tonumber(detail or 1) or 1}
+ local function analyse(str,category,order,penalty,command,fixed)
+ for s in gmatch(str,"([^ ,]+)") do
+ local amount, keyword, detail = splitter:match(s)
+ if keyword then
+ local mk = map[keyword]
+ if mk then
+ analyse(mk,category,order,penalty,command,fixed)
+ elseif keyword == "fixed" then
+ fixed = true
+ elseif keyword == "flexible" then
+ fixed = false
+ elseif keyword == "category" then
+ -- is a set
+ local n = tonumber(detail)
+ if n then
+ category[categories[n]] = true
else
- amount = tonumber(amount) or 1
- local sk = skip[keyword]
- if sk then
- command[#command+1] = { amount, sk[1], sk[2] or sk[1]}
- else -- no check
- command[#command+1] = { amount, keyword, keyword, keyword}
- end
+ category[detail] = true
end
+ elseif keyword == "order" then
+ -- last one counts
+ order = tonumber(detail) or 0
+ elseif keyword == "penalty" then
+ -- last one counts
+ penalty = tonumber(detail) or 0
+ elseif keyword == "skip" then
+ -- last one counts
+ command[#command+1] = { 1, tonumber(detail or 1) or 1}
else
- logs.report("vspacing","unknown directive: %s",str)
+ amount = tonumber(amount) or 1
+ local sk = skip[keyword]
+ if sk then
+ command[#command+1] = { amount, sk[1], sk[2] or sk[1]}
+ else -- no check
+ command[#command+1] = { amount, keyword, keyword, keyword}
+ end
end
+ else
+ logs.report("vspacing","unknown directive: %s",str)
end
end
- analyse(str)
+ end
+
+ local function logger(c,s)
+ logs.report("vspacing",s)
+ texsprint(c,s)
+ end
+
+ function vspacing.analyse(str)
+ local texsprint = (trace_vspacing and logger) or texsprint
+ local category, order, penalty, command, fixed = { }, 0, 0, { }, vspacing.fixed
+ analyse(str,category,order,penalty,command,fixed)
category = set.tonumber(category)
- local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
- if vspacing.trace then
- -- quick and dirty
- texsprint = function(c,s)
- logs.report("vspacing",s)
- tex.sprint(c,s)
- end
- end
texsprint(ctxcatcodes,"\\startblankhandling")
if category > 0 then
- texsprint(ctxcatcodes,("\\setblankcategory{%s}"):format(category))
+ texsprint(ctxcatcodes,format("\\setblankcategory{%s}",category))
end
if order > 0 then
- texsprint(ctxcatcodes,("\\setblankorder{%s}"):format(order))
+ texsprint(ctxcatcodes,format("\\setblankorder{%s}",order))
end
if penalty > 0 then
- texsprint(ctxcatcodes,("\\setblankpenalty{%s}"):format(penalty))
+ texsprint(ctxcatcodes,format("\\setblankpenalty{%s}",penalty))
end
for i=1,#command do
local c = command[i]
- texsprint(ctxcatcodes,("\\addblankskip{%s}{%s}{%s}"):format(c[1],c[2],c[3] or c[2]))
+ texsprint(ctxcatcodes,format("\\addblankskip{%s}{%s}{%s}",c[1],c[2],c[3] or c[2]))
end
if fixed then
texsprint(ctxcatcodes,"\\fixedblankskip")
@@ -165,1488 +194,488 @@ function nodes.setsnapvalue(n,ht,dp)
nodes.snapvalues[n] = { ht, dp, ht+dp }
end
-do
-
- nodes.trace_vbox_spacing = false
- nodes.trace_page_spacing = false
+local trace_list, tracing_info, before, after = { }, false, "", ""
- local kern, glue, penalty, hlist = node.id('kern'), node.id('glue'), node.id('penalty'), node.id('hlist')
-
- local has_attribute = node.has_attribute
- local unset_attribute = node.unset_attribute
- local set_attribute = node.set_attribute
- local has_field = node.has_field
-
- local trace_list, tracing_info, before, after = { }, false, "", ""
-
- local function glue_to_string(glue)
- local spec = glue.spec
- if spec then
- local t = { }
- t[#t+1] = aux.strip_zeros(number.topoints(spec.width))
- if spec.stretch_order and spec.stretch_order ~= 0 then
- t[#t+1] = format("plus -%sfi%s",spec.stretch/65536,string.rep("l",math.abs(spec.stretch_order)-1))
- elseif spec.stretch and spec.stretch ~= 0 then
- t[#t+1] = format("plus %s",aux.strip_zeros(number.topoints(spec.stretch)))
- end
- if spec.shrink_order and spec.shrink_order ~= 0 then
- t[#t+1] = format("minus -%sfi%s",spec.shrink/65536,string.rep("l",math.abs(spec.shrink_order)-1))
- elseif spec.shrink and spec.shrink ~= 0 then
- t[#t+1] = format("minus %s",aux.strip_zeros(number.topoints(spec.shrink)))
- end
- return table.concat(t," ")
- else
- return "[0pt]"
- end
- end
- local function nodes_to_string(head)
- local current, t = head, { }
- while current do
- local id = current.id
- local ty = node.type(id)
- if id == penalty then
- t[#t+1] = format("%s:%s",ty,current.penalty)
- elseif id == glue then
- if current.spec then
- t[#t+1] = format("%s:%s",ty,aux.strip_zeros(number.topoints(current.spec.width)))
- else
- t[#t+1] = format("%s:[0pt]",ty)
- end
- elseif id == kern then
- t[#t+1] = format("%s:%s",ty,aux.strip_zeros(number.topoints(current.kern)))
- else
- t[#t+1] = ty
- end
- current = current.next
- end
- return table.concat(t," + ")
- end
- local function reset_tracing(head)
- trace_list, tracing_info, before, after = { }, false, nodes_to_string(head), ""
- end
- local function trace_skip(str,sc,so,sp,data)
- trace_list[#trace_list+1] = { "skip", ("%s | %s | category %s | order %s | penalty %s"):format(str, glue_to_string(data), sc or "-", so or "-", sp or "-") }
- tracing_info = true
- end
- local function trace_natural(str,data)
- trace_list[#trace_list+1] = { "skip", ("%s | %s"):format(str, glue_to_string(data)) }
- tracing_info = true
- end
- local function trace_info(message, where, what)
- trace_list[#trace_list+1] = { "info", format("%s: %s/%s",message,where,what) }
- end
- local function trace_node(what)
- local nt = node.type(what.id)
- local tl = trace_list[#trace_list]
- if tl[1] == "node" then
- trace_list[#trace_list] = { "node", tl[2] .. " + " .. nt }
- else
- trace_list[#trace_list+1] = { "node", nt }
+local function glue_to_string(glue)
+ local spec = glue.spec
+ if spec then
+ local t = { }
+ t[#t+1] = aux.strip_zeros(number.topoints(spec.width))
+ if spec.stretch_order and spec.stretch_order ~= 0 then
+ t[#t+1] = format("plus -%sfi%s",spec.stretch/65536,string.rep("l",math.abs(spec.stretch_order)-1))
+ elseif spec.stretch and spec.stretch ~= 0 then
+ t[#t+1] = format("plus %s",aux.strip_zeros(number.topoints(spec.stretch)))
end
- end
- local function trace_done(str,data)
- if data.id == penalty then
- trace_list[#trace_list+1] = { "penalty", ("%s | %s"):format(str, data.penalty) }
- else
- trace_list[#trace_list+1] = { "glue", ("%s | %s"):format(str, glue_to_string(data)) }
- end
- tracing_info = true
- end
- local function show_tracing(head)
- if tracing_info then
- after = nodes_to_string(head)
- for i=1,#trace_list do
- local tag, text = unpack(trace_list[i])
- if tag == "info" then
- logs.report("collapse",text)
- else
- logs.report("collapse"," %s: %s",tag,text)
- end
- end
- logs.report("collapse","before: %s",before)
- logs.report("collapse","after : %s",after)
+ if spec.shrink_order and spec.shrink_order ~= 0 then
+ t[#t+1] = format("minus -%sfi%s",spec.shrink/65536,string.rep("l",math.abs(spec.shrink_order)-1))
+ elseif spec.shrink and spec.shrink ~= 0 then
+ t[#t+1] = format("minus %s",aux.strip_zeros(number.topoints(spec.shrink)))
end
+ return concat(t," ")
+ else
+ return "[0pt]"
end
+end
- -- we assume that these are defined
-
- local skip_category = attributes.numbers['skip-category'] or 101
- local skip_penalty = attributes.numbers['skip-penalty'] or 102
- local skip_order = attributes.numbers['skip-order'] or 103
- local snap_category = attributes.numbers['snap-category'] or 111
- local display_math = attributes.numbers['display-math'] or 121
-
- -- alignment box begin_of_par vmode_par hmode_par insert penalty before_display after_display
-
- local user_skip = 0
- local line_skip = 1
- local baseline_skip = 2
- local par_skip = 3
- local above_display_skip = 4
- local below_display_skip = 5
- local above_display_short_skip = 6
- local below_display_short_skip = 7
- local left_skip_code = 8
- local right_skip_code = 9
- local top_skip_code = 10
- local split_top_skip_code = 11
- local tab_skip_code = 12
- local space_skip_code = 13
- local xspace_skip_code = 14
- local par_fill_skip_code = 15
- local thin_mu_skip_code = 16
- local med_mu_skip_code = 17
- local thick_mu_skip_code = 18
-
- local skips = {
- [ 0] = "user_skip",
- [ 1] = "line_skip",
- [ 2] = "baseline_skip",
- [ 3] = "par_skip",
- [ 4] = "above_display_skip",
- [ 5] = "below_display_skip",
- [ 6] = "above_display_short_skip",
- [ 7] = "below_display_short_skip",
- [ 8] = "left_skip_code",
- [ 9] = "right_skip_code",
- [10] = "top_skip_code",
- [11] = "split_top_skip_code",
- [12] = "tab_skip_code",
- [13] = "space_skip_code",
- [14] = "xspace_skip_code",
- [15] = "par_fill_skip_code",
- [16] = "thin_mu_skip_code",
- [17] = "med_mu_skip_code",
- [18] = "thick_mu_skip_code",
- }
-
- function nodes.is_display_math(head)
- local n = head.prev
- while n do
- local id = n.id
- if id == penalty then
- elseif id == glue then
- if n.subtype == 6 then -- above_display_short_skip
- return true
- end
- else
- break
- end
- n = n.prev
- end
- n = head.next
- while n do
- local id = n.id
- if id == penalty then
- elseif id == glue then
- if n.subtype == 7 then -- below_display_short_skip
- return true
- end
+local function nodes_to_string(head)
+ local current, t = head, { }
+ while current do
+ local id = current.id
+ local ty = node.type(id)
+ if id == penalty then
+ t[#t+1] = format("%s:%s",ty,current.penalty)
+ elseif id == glue then
+ if current.spec then
+ t[#t+1] = format("%s:%s",ty,aux.strip_zeros(number.topoints(current.spec.width)))
else
- break
- end
- n = n.next
- end
- return false
- end
-
- local function collapser(head,where,what,trace,preceding)
- if head then
- input.starttiming(nodes)
- if trace then reset_tracing(head) end
- if trace then trace_info("start analyzing",where,what) end
- node.slide(head) -- hm, why
- local current, tail = head, nil
- local glue_order, glue_data = 0, nil
- local penalty_order, penalty_data, natural_penalty = 0, nil, nil
- local parskip, ignore_parskip, ignore_following, ignore_whitespace = nil, false, false, false
- while current do
- local id = current.id
- if id == glue and current.subtype == 0 then -- todo, other subtypes, like math
- local sc = has_attribute(current,skip_category)
- local so = has_attribute(current,skip_order)
- local sp = has_attribute(current,skip_penalty)
---~ if sc then unset_attribute(current,skip_category) end
---~ if so then unset_attribute(current,skip_order) end
---~ if sp then unset_attribute(current,skip_penalty) end
- so = so or 1
- if not sc then
- if glue_data then
- if trace then trace_done("flush",glue_data) end
- head, current = nodes.before(head,current,glue_data)
- if trace then trace_natural("natural",current) end
- else
- -- not look back across head
- local previous = current.prev
- if previous and previous.id == glue and previous.subtype == 0 then
- local ps = previous.spec
- if ps then
- local cs = current.spec
- if cs and ps.stretch_order == 0 and ps.shrink_order == 0 and cs.stretch_order == 0 and cs.shrink_order == 0 then
- local pw, pp, pm = ps.width, ps.stretch, ps.shrink
- local cw, cp, cm = cs.width, cs.stretch, cs.shrink
- ps.width, ps.stretch, ps.shrink = pw + cw, pp + cp, pm + cm
- if trace then trace_natural("removed",current) end
- head, current = nodes.remove(head, current, true)
- current = previous
- if trace then trace_natural("collapsed",current) end
- else
- if trace then trace_natural("filler",current) end
- end
- else
- if trace then trace_natural("natural (no prev spec)",current) end
- end
- else
- if trace then trace_natural("natural (no prev)",current) end
- end
- end
- glue_order, glue_data = 0, nil
- if current then
- current = current.next
- end
- else
- local sct = vspacing.categories[sc] -- or 'unknown'
- if sct == 'disable' then
- ignore_following = true
- if trace then trace_skip(sct,sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- elseif sct == 'nowhite' then
- ignore_whitespace = true
- head, current = nodes.remove(head, current, true)
- elseif sct == 'discard' then
- if trace then trace_skip(sct,sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- else
- if sp then
- if not penalty_data then
- penalty_data = sp
- elseif penalty_order < so then
- penalty_order, penalty_data = so, sp
- elseif penalty_order == so and sp > penalty_data then
- penalty_data = sp
- end
- end
- if ignore_following then
- if trace then trace_skip("disabled",sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- elseif not glue_data then
- if trace then trace_skip("assign " .. sct,sc,so,sp,current) end
- glue_order = so
- head, current, glue_data = nodes.remove(head, current)
- elseif glue_order < so then
- if trace then trace_skip("force",sc,so,sp,current) end
- glue_order = so
- node.free(glue_data)
- head, current, glue_data = nodes.remove(head, current)
- elseif glue_order == so then
- if sct == 'largest' then
- local cs, gs = current.spec, glue_data.spec
- local cw = (cs and cs.width) or 0
- local gw = (gs and gs.width) or 0
- if cw > gw then
- if trace then trace_skip(sct,sc,so,sp,current) end
- node.free(glue_data) -- also free spec
- head, current, glue_data = nodes.remove(head, current)
- else
- if trace then trace_skip('remove smallest',sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- end
- elseif sct == 'goback' then
- if trace then trace_skip(sct,sc,so,sp,current) end
- node.free(glue_data) -- also free spec
- head, current, glue_data = nodes.remove(head, current)
- elseif sct == 'force' then
- -- todo: inject kern
- if trace then trace_skip(sct,sc,so,sp,current) end
- node.free(glue_data) -- also free spec
- head, current, glue_data = nodes.remove(head, current)
- elseif sct == 'penalty' then
- if trace then trace_skip(sct,sc,so,sp,current) end
- node.free(glue_data) -- also free spec
- head, current = nodes.remove(head, current, true)
- elseif sct == 'add' then
- if trace then trace_skip(sct,sc,so,sp,current) end
- local old, new = glue_data.spec, current.spec
- old.width = old.width + new.width
- old.stretch = old.stretch + new.stretch
- old.shrink = old.shrink + new.shrink
- -- toto: order
- head, current = nodes.remove(head, current, true)
- else
- if trace then trace_skip("unknown",sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- end
- else
- if trace then trace_skip("unknown",sc,so,sp,current) end
- head, current = nodes.remove(head, current, true)
- end
- end
- end
- elseif id == penalty then
---~ natural_penalty = current.penalty
---~ if trace then trace_done("removed penalty",current) end
---~ head, current = nodes.remove(head, current, true)
-current = current.next
- elseif id == glue and current.subtype == 2 then
- local sn = has_attribute(current,snap_category)
- if sn then
- -- local sv = nodes.snapvalues[sn]
- -- if sv then
- if trace then trace_natural("removed baselineskip",current) end
- head, current = nodes.remove(head, current, true)
- -- else
- -- current = current.next
- -- end
- else
- if trace then trace_natural("keep baselineskip",current) end
- current = current.next
- end
- elseif id == glue and current.subtype == 3 then
- -- parskip always comes later
- if ignore_whitespace then
- if trace then trace_natural("ignored parskip",current) end
- head, current = nodes.remove(head,current,true)
- elseif glue_data then
- local ps, gs = current.spec, glue_data.spec
- if ps and gs and ps.width > gs.width then
- node.free(glue_data.spec)
- glue_data.spec = ps
- if trace then trace_natural("taking parskip",current) end
- else
- if trace then trace_natural("removed parskip",current) end
- end
- head, current = nodes.remove(head, current,true)
- else
- if trace then trace_natural("honored parskip",current) end
- head, current, glue_data = nodes.remove(head, current)
- end
---~ if trace then trace_natural("removed parskip",current) end
---~ current.spec = nil
---~ current = current.next
- else
- if glue_data then
- if trace then trace_done("flushed",glue_data) end
- head, current = node.insert_before(head,current,glue_data)
- glue_order, glue_data = 0, nil
- end
- if penalty_data then
- local p = nodes.penalty(penalty_data)
- if trace then trace_done("flushed",p) end
- head, current = node.insert_before(head,current,p)
- penalty_data = nil
- end
- if trace then trace_node(current) end
- if id == hlist and where == 'hmode_par' then
- local list = current.list
- if list then
- local sn = has_attribute(list,snap_category)
- if sn then
- local sv = nodes.snapvalues[sn]
- if sv then
- local height, depth, lineheight = sv[1], sv[2], sv[3]
- current.height = math.ceil((current.height-height)/lineheight)*lineheight + height
- current.depth = math.ceil((current.depth -depth )/lineheight)*lineheight + depth
- end
- end
- end
- end
- current = current.next
- end
- end
- tail = node.slide(head)
- if trace then trace_info("stop analyzing",where,what) end
---~ if natural_penalty and (not penalty_data or natural_penalty > penalty_data) then
---~ penalty_data = natural_penalty
---~ end
- if trace and (glue_data or penalty_data) then trace_info("start flushing",where,what) end
- if penalty_data then
- local p = nodes.penalty(penalty_data)
- if trace then trace_done("result",p) end
- head, tail = node.insert_after(head,tail,p)
- end
- if glue_data then
- if trace then trace_done("result",glue_data) end
- head, tail = node.insert_after(head,tail,glue_data)
+ t[#t+1] = format("%s:[0pt]",ty)
end
- if trace and (glue_data or penalty_data) then trace_info("stop flushing",where,what) end
- input.stoptiming(nodes)
- if trace then show_tracing(head) end
+ elseif id == kern then
+ t[#t+1] = format("%s:%s",ty,aux.strip_zeros(number.topoints(current.kern)))
+ else
+ t[#t+1] = ty
end
- return head, true
- end
-
- -- alignment after_output end box new_graf vmode_par hmode_par insert penalty before_display after_display
-
- function nodes.handle_page_spacing(where) -- no arguments
- --~ status.best_page_break
- --~ tex.lists.best_page_break
- --~ tex.lists.best_size (natural size to best_page_break)
- --~ tex.lists.least_page_cost ( badness van best_page_break)
- --~ tex.lists.page_head
- --~ tex.lists.contrib_head
- local head, done= collapser(tex.lists.contrib_head,"page",where,nodes.trace_page_spacing,tex.lists.page_head)
- tex.lists.contrib_head = head
+ current = current.next
end
-
- -- split_keep, split_off, vbox
-
- local not_needed = table.tohash {
- "split_keep",
- "split_off",
- }
-
- function nodes.handle_vbox_spacing(t,where)
- return (t and not not_needed[where] and t.next and collapser(t,"vbox",where,nodes.trace_vbox_spacing)) or t
- end
-
+ return concat(t," + ")
end
--- experimental callback definitions will be moved elsewhere
---
--- this will become a chain
-
-function vspacing.enable()
---~ callback.register('vpack_filter', nodes.handle_vbox_spacing)
- callback.register('buildpage_filter', nodes.handle_page_spacing)
+local function reset_tracing(head)
+ trace_list, tracing_info, before, after = { }, false, nodes_to_string(head), ""
end
-function vspacing.disable()
- callback.register('vpack_filter', nil)
- callback.register('buildpage_filter', nil)
-end
-
--- horizontal stuff
--- probably a has_glyphs is rather fast too
-
-do -- maybe just share these locals
-
- local has_attribute = node.has_attribute
- local unset_attribute = node.unset_attribute
- local set_attribute = node.set_attribute
- local traverse_id = node.traverse_id
-
---~ local function unset_attribute(n,attribute)
---~ set_attribute(n,attribute,0)
---~ end
-
- local glyph = node.id("glyph")
- local whatsit = node.id("whatsit")
- local penalty = node.id("penalty")
- local kern = node.id("kern")
- local disc = node.id('disc')
- local glue = node.id('glue')
- local hlist = node.id('hlist')
- local vlist = node.id('vlist')
-
- spacings = spacings or { }
- spacings.mapping = spacings.mapping or { }
- spacings.enabled = false
-
- input.storage.register(false,"spacings/mapping", spacings.mapping, "spacings.mapping")
+local function trace_skip(str,sc,so,sp,data)
+ trace_list[#trace_list+1] = { "skip", format("%s | %s | category %s | order %s | penalty %s", str, glue_to_string(data), sc or "-", so or "-", sp or "-") }
+ tracing_info = true
+end
- function spacings.setspacing(id,char,left,right,alternative)
- local mapping = spacings.mapping[id]
- if not mapping then
- mapping = { }
- spacings.mapping[id] = mapping
- end
- local map = mapping[char]
- if not map then
- map = { }
- mapping[char] = map
- end
- map.left, map.right, map.alternative = left, right, alternative
- end
+local function trace_natural(str,data)
+ trace_list[#trace_list+1] = { "skip", format("%s | %s", str, glue_to_string(data)) }
+ tracing_info = true
+end
- -- todo: no ligatures
+local function trace_info(message, where, what)
+ trace_list[#trace_list+1] = { "info", format("%s: %s/%s",message,where,what) }
+end
- function nodes.somespace(n,all)
- if n then
- local id = n.id
- if id == glue then
- return (all or (n.spec.width ~= 0)) and glue
- elseif id == kern then
- return (all or (n.kern ~= 0)) and kern
- elseif id == glyph then
- local category = characters.data[n.char].category
- -- maybe more category checks are needed
- return (category == "zs") and glyph
- end
- end
- return false
+local function trace_node(what)
+ local nt = node.type(what.id)
+ local tl = trace_list[#trace_list]
+ if tl[1] == "node" then
+ trace_list[#trace_list] = { "node", tl[2] .. " + " .. nt }
+ else
+ trace_list[#trace_list+1] = { "node", nt }
end
+end
- function nodes.somepenalty(n,value)
- if n then
- local id = n.id
- if id == penalty then
- if value then
- return n.penalty == value
- else
- return true
- end
- end
- end
- return false
+local function trace_done(str,data)
+ if data.id == penalty then
+ trace_list[#trace_list+1] = { "penalty", format("%s | %s", str, data.penalty) }
+ else
+ trace_list[#trace_list+1] = { "glue", format("%s | %s", str, glue_to_string(data)) }
end
+ tracing_info = true
+end
- spacings.trace = false
-
- function spacings.process(namespace,attribute,head)
- local done, mapping, fontids = false, spacings.mapping, fonts.tfm.id
- local start = head
- -- head is always begin of par (whatsit), so we have at least two prev nodes
- -- penalty followed by glue
- while start do
- if start.id == glyph then
- local attr = has_attribute(start,attribute)
- if attr and attr > 0 then
- local map = mapping[attr]
- if map then
- map = map[start.char]
- unset_attribute(start,attribute)
- if map then
- local trace = spacings.trace
- local left, right, alternative = map.left, map.right, map.alternative
- local quad = fontids[start.font].parameters.quad
- local prev = start.prev
- if left and left ~= 0 and prev then
- local ok = false
- if alternative == 1 then
- local somespace = nodes.somespace(prev,true)
- if somespace then
- local prevprev = prev.prev
- local somepenalty = nodes.somepenalty(prevprev,10000)
- if somepenalty then
- if trace then
- logs.report("spacing","removing penalty and space before %s", utfchar(start.char))
- end
- head, _ = nodes.remove(head,prev,true)
- head, _ = nodes.remove(head,prevprev,true)
- else
- local somespace = nodes.somespace(prev,true)
- if somespace then
- if trace then
- logs.report("spacing","removing space before %s", utfchar(start.char))
- end
- head, _ = nodes.remove(head,prev,true)
- end
- end
- end
- ok = true
- else
- ok = not (nodes.somespace(prev,true) and nodes.somepenalty(prev.prev,true)) or nodes.somespace(prev,true)
- end
- if ok then
- if trace then
- logs.report("spacing","inserting penalty and space before %s", utfchar(start.char))
- end
- node.insert_before(head,start,nodes.penalty(10000))
- node.insert_before(head,start,nodes.glue(tex.scale(quad,left)))
- done = true
- end
- end
- local next = start.next
- if right and right ~= 0 and next then
- local ok = false
- if alternative == 1 then
- local somepenalty = nodes.somepenalty(next,10000)
- if somepenalty then
- local nextnext = next.next
- local somespace = nodes.somespace(nextnext,true)
- if somespace then
- if trace then
- logs.report("spacing","removing penalty and space after %s", utfchar(start.char))
- end
- head, _ = nodes.remove(head,next,true)
- head, _ = nodes.remove(head,nextnext,true)
- end
- else
- local somespace = nodes.somespace(next,true)
- if somespace then
- if trace then
- logs.report("spacing","removing space after %s", utfchar(start.char))
- end
- head, _ = nodes.remove(head,next,true)
- end
- end
- ok = true
- else
- ok = not (nodes.somepenalty(next,10000) and nodes.somespace(next.next,true)) or nodes.somespace(next,true)
- end
- if ok then
- if trace then
- logs.report("spacing","inserting penalty and space after %s", utfchar(start.char))
- end
- node.insert_after(head,start,nodes.glue(tex.scale(quad,right)))
- node.insert_after(head,start,nodes.penalty(10000))
- done = true
- end
- end
- end
- end
- end
+local function show_tracing(head)
+ if tracing_info then
+ after = nodes_to_string(head)
+ for i=1,#trace_list do
+ local tag, text = unpack(trace_list[i])
+ if tag == "info" then
+ logs.report("collapse",text)
+ else
+ logs.report("collapse"," %s: %s",tag,text)
end
- start = start.next
end
- return head, done
- end
-
- lists.handle_spacing = nodes.install_attribute_handler {
- name = "spacing",
- namespace = spacings,
- processor = spacings.process,
- }
-
- kerns = kerns or { }
- kerns.mapping = kerns.mapping or { }
- kerns.enabled = false
-
- input.storage.register(false, "kerns/mapping", kerns.mapping, "kerns.mapping")
-
- function kerns.setspacing(id,factor)
- kerns.mapping[id] = factor
+ logs.report("collapse","before: %s",before)
+ logs.report("collapse","after : %s",after)
end
+end
- -- local marks = fti[font].shared.otfdata.luatex.marks
- -- if not marks[tchar] then
-
- -- todo: use node.* functions
+-- we assume that these are defined
+
+local skip_category = attributes.private('skip-category')
+local skip_penalty = attributes.private('skip-penalty')
+local skip_order = attributes.private('skip-order')
+local snap_category = attributes.private('snap-category')
+local display_math = attributes.private('display-math')
+
+-- alignment box begin_of_par vmode_par hmode_par insert penalty before_display after_display
+
+local user_skip = 0
+local line_skip = 1
+local baseline_skip = 2
+local par_skip = 3
+local above_display_skip = 4
+local below_display_skip = 5
+local above_display_short_skip = 6
+local below_display_short_skip = 7
+local left_skip_code = 8
+local right_skip_code = 9
+local top_skip_code = 10
+local split_top_skip_code = 11
+local tab_skip_code = 12
+local space_skip_code = 13
+local xspace_skip_code = 14
+local par_fill_skip_code = 15
+local thin_mu_skip_code = 16
+local med_mu_skip_code = 17
+local thick_mu_skip_code = 18
+
+local skips = {
+ [ 0] = "user_skip",
+ [ 1] = "line_skip",
+ [ 2] = "baseline_skip",
+ [ 3] = "par_skip",
+ [ 4] = "above_display_skip",
+ [ 5] = "below_display_skip",
+ [ 6] = "above_display_short_skip",
+ [ 7] = "below_display_short_skip",
+ [ 8] = "left_skip_code",
+ [ 9] = "right_skip_code",
+ [10] = "top_skip_code",
+ [11] = "split_top_skip_code",
+ [12] = "tab_skip_code",
+ [13] = "space_skip_code",
+ [14] = "xspace_skip_code",
+ [15] = "par_fill_skip_code",
+ [16] = "thin_mu_skip_code",
+ [17] = "med_mu_skip_code",
+ [18] = "thick_mu_skip_code",
+}
- function kerns.process(namespace,attribute,head) -- todo interchar kerns / disc nodes / can be made faster
- local fti, scale = fonts.tfm.id, tex.scale
- local start, done, mapping, fontids, lastfont = head, false, kerns.mapping, fonts.tfm.id, nil
- while start do
- -- faster to test for attr first
- local attr = has_attribute(start,attribute)
- if attr and attr > 0 then
- unset_attribute(start,attribute)
- local krn = mapping[attr]
- if krn and krn ~= 0 then
- local id = start.id
- if id == glyph then
- lastfont = start.font
- local c = start.components
- if c then
- local s = start
- local tail = node.slide(c)
- if s.prev then
- s.prev.next = c
- c.prev = s.prev
+local free_glue_node = free_node
+local free_glue_spec = free_node
+--~ local free_glue_node = function(n) free_node(n) end
+--~ local free_glue_spec = function(n) end
+
+local function collapser(head,where,what,trace) -- maybe also pass tail
+ if trace then
+ reset_tracing(head)
+ trace_info("start analyzing",where,what)
+ end
+ local current = head
+ local glue_order, glue_data = 0, nil
+ local penalty_order, penalty_data, natural_penalty = 0, nil, nil
+ local parskip, ignore_parskip, ignore_following, ignore_whitespace = nil, false, false, false
+ while current do
+ local id = current.id
+ if id == glue and current.subtype == 0 then -- todo, other subtypes, like math
+ local sc = has_attribute(current,skip_category) -- has no default, no unset (yet)
+ local so = has_attribute(current,skip_order ) or 1 -- has 1 default, no unset (yet)
+ local sp = has_attribute(current,skip_penalty ) -- has no degault, no unset (yet)
+ if not sc then
+ if glue_data then
+ if trace then trace_done("flush",glue_data) end
+ head, current = nodes.before(head,current,glue_data)
+ if trace then trace_natural("natural",current) end
+ else
+ -- not look back across head
+ local previous = current.prev
+ if previous and previous.id == glue and previous.subtype == 0 then
+ local ps = previous.spec
+ if ps then
+ local cs = current.spec
+ if cs and ps.stretch_order == 0 and ps.shrink_order == 0 and cs.stretch_order == 0 and cs.shrink_order == 0 then
+ local pw, pp, pm = ps.width, ps.stretch, ps.shrink
+ local cw, cp, cm = cs.width, cs.stretch, cs.shrink
+ ps.width, ps.stretch, ps.shrink = pw + cw, pp + cp, pm + cm
+ if trace then trace_natural("removed",current) end
+ head, current = remove_node(head, current, true)
+ current = previous
+ if trace then trace_natural("collapsed",current) end
else
- head = c
- end
- if s.next then
- s.next.prev = tail
- end
- tail.next = s.next
- start = c
- start.attr = s.attr
- s.attr = nil
- s.components = nil
- node.free(s)
- done = true
- end
- local prev = start.prev
- if prev then
- local pid = prev.id
- if not pid then
- -- nothing
- elseif pid == kern and prev.subtype == 0 then
- prev.subtype = 1
- prev.kern = prev.kern + scale(fontids[lastfont].parameters.quad,krn)
- done = true
- elseif pid == glyph then
- -- fontdata access can be done more efficient
- if prev.font == lastfont then
- local prevchar, lastchar = prev.char, start.char
- local tfm = fti[lastfont].characters[prevchar]
- local ickern = tfm.kerns
- if ickern and ickern[lastchar] then
- krn = scale(ickern[lastchar]+fontids[lastfont].parameters.quad,krn)
- else
- krn = scale(fontids[lastfont].parameters.quad,krn)
- end
- else
- krn = scale(fontids[lastfont].parameters.quad,krn)
- end
- node.insert_before(head,start,nodes.kern(krn))
- done = true
- elseif pid == disc then
- local disc = start.prev -- disc
- local pre, post, replace = disc.pre, disc.post, disc.replace
- if pre then -- must pair with start.prev
- local before = node.copy(disc.prev)
- pre.prev = before
- before.next = pre
- before.prev = nil
- pre = kerns.process(namespace,attribute,before)
- pre = pre.next
- pre.prev = nil
- disc.pre = pre
- node.free(before)
- end
- if post then -- must pair with start
- local after = node.copy(disc.next)
- local tail = node.slide(post)
- tail.next = after
- after.prev = tail
- after.next = nil
- post = kerns.process(namespace,attribute,post)
- tail.next = nil
- disc.post = post
- node.free(after)
- end
- if replace then -- must pair with start and start.prev
- local before = node.copy(disc.prev)
- local after = node.copy(disc.next)
- local tail = node.slide(post)
- replace.prev = before
- before.next = replace
- before.prev = nil
- tail.next = after
- after.prev = tail
- after.next = nil
- replace = kerns.process(namespace,attribute,before)
- replace = replace.next
- replace.prev = nil
- tail.next = nil
- disc.replace = replace
- node.free(after)
- node.free(before)
- end
+ if trace then trace_natural("filler",current) end
end
+ else
+ if trace then trace_natural("natural (no prev spec)",current) end
end
- elseif id == glue and start.subtype == 0 then
- local s = start.spec
- local w = s.width
- if w > 0 then
- local width, stretch, shrink = w+2*scale(w,krn), s.stretch, s.shrink
- start.spec = nodes.glue_spec(width,scale(stretch,width/w),scale(shrink,width/w))
- -- local width, stretch, shrink = w+2*w*krn, s.stretch, s.shrink
- -- start.spec = nodes.glue_spec(width,stretch*width/w,shrink*width/w))
- done = true
- end
- elseif false and id == kern and start.subtype == 0 then -- handle with glyphs
- local sk = start.kern
- if sk > 0 then
- -- start.kern = scale(sk,krn)
- start.kern = sk*krn
- done = true
- end
- elseif lastfont and (id == hlist or id == vlist) then -- todo: lookahead
- if start.prev then
- node.insert_before(head,start,nodes.kern(scale(fontids[lastfont].parameters.quad,krn)))
- done = true
- end
- if start.next then
- node.insert_after(head,start,nodes.kern(scale(fontids[lastfont].parameters.quad,krn)))
- done = true
- end
- end
- end
- end
- if start then
- start = start.next
- end
- end
- return head, done
- end
-
- lists.handle_kerning = nodes.install_attribute_handler {
- name = "kern",
- namespace = kerns,
- processor = kerns.process,
- }
-
- -- spacing == attributename !! does not belong here but we will
- -- relocate node and attribute stuff once it's more complete !!
-
- -- experimental, we may extend or change this
-
- --~ Analysis by Idris:
- --~
- --~ 1. Assuming the reading- vs word-order distinction (bidi-char types) is governing;
- --~ 2. Assuming that 'ARAB' represents an actual arabic string in raw input order, not word-order;
- --~ 3. Assuming that 'BARA' represent the correct RL word order;
- --~
- --~ Then we have, with input: LATIN ARAB
- --~
- --~ \textdir TLT LATIN ARAB => LATIN BARA
- --~ \textdir TRT LATIN ARAB => LATIN BARA
- --~ \textdir TRT LRO LATIN ARAB => LATIN ARAB
- --~ \textdir TLT LRO LATIN ARAB => LATIN ARAB
- --~ \textdir TLT RLO LATIN ARAB => NITAL ARAB
- --~ \textdir TRT RLO LATIN ARAB => NITAL ARAB
-
- -- elseif d == "es" then -- European Number Separator
- -- elseif d == "et" then -- European Number Terminator
- -- elseif d == "cs" then -- Common Number Separator
- -- elseif d == "nsm" then -- Non-Spacing Mark
- -- elseif d == "bn" then -- Boundary Neutral
- -- elseif d == "b" then -- Paragraph Separator
- -- elseif d == "s" then -- Segment Separator
- -- elseif d == "ws" then -- Whitespace
- -- elseif d == "on" then -- Other Neutrals
-
- mirror = mirror or { }
- mirror.enabled = false
- mirror.trace = false
- mirror.strip = false
-
- local state = attributes.numbers['state'] or 100
-
- function mirror.process(namespace,attribute,head)
- local done, data, directions, trace = false, characters.data, characters.directions, mirror.trace
- local current, inserted, obsolete = head, nil, { }
- local override, embedded, autodir = 0, 0, 0
- local list, glyphs = trace and { }, false
- local stack, top, finished, finidir, finipos = { }, 0, nil, nil, 1
- local finish = nil
- local lro, rlo, prevattr = false, false, 0
- -- todo: delayed inserts here
- local function finish_auto_before()
- head, inserted = node.insert_before(head,current,nodes.textdir("-"..finish))
- finished, finidir = inserted, finish
- if trace then insert(list,#list,format("finish %s",finish)) ; finipos = #list-1 end
- finish, autodir, done = nil, 0, true
- end
- local function finish_auto_after()
- head, current = node.insert_after(head,current,nodes.textdir("-"..finish))
- finished, finidir = current, finish
- if trace then list[#list+1] = format("finish %s",finish) ; finipos = #list end
- finish, autodir, done = nil, 0, true
- end
- local function force_auto_left_before()
- if finish then
- finish_auto_before()
- end
- if embedded >= 0 then
- finish, autodir, done = "TLT", 1, true
- else
- finish, autodir, done = "TRT", -1, true
- end
- if finidir == finish then
- nodes.remove(head,finished,true)
- if trace then list[finipos] = list[finipos].." (deleted)" end
- if trace then insert(list,#list,format("start %s (deleted)",finish)) end
- else
- head, inserted = node.insert_before(head,current,nodes.textdir("+"..finish))
- if trace then insert(list,#list,format("start %s",finish)) end
- end
- end
- local function force_auto_right_before()
- if finish then
- finish_auto_before()
- end
- if embedded <= 0 then
- finish, autodir, done = "TRT", -1, true
- else
- finish, autodir, done = "TLT", 1, true
- end
- if finidir == finish then
- nodes.remove(head,finished,true)
- if trace then list[finipos] = list[finipos].." (deleted)" end
- if trace then insert(list,#list,format("start %s (deleted)",finish)) end
- else
- head, inserted = node.insert_before(head,current,nodes.textdir("+"..finish))
- if trace then insert(list,#list,format("start %s",finish)) end
- end
- end
- local function is_right(n)
- if n then
- local id = n.id
- if id == glyph then
- local attr = has_attribute(n,attribute)
- if attr and attr > 0 then
- local d = directions[n.char]
- if d == "r" or d == "al" then -- override
- return true
- end
- end
- end
- end
- return false
- end
- while current do
- local id = current.id
- local attr = has_attribute(current,attribute)
- if attr and attr > 0 then
- unset_attribute(current,attribute)
- if attr == 1 then
- -- bidi parsing mode
- elseif attr ~= prevattr then
- -- no pop, grouped driven (2=normal,3=lro,4=rlo)
- if attr == 3 then
- if trace then list[#list+1] = format("override right -> left (lro) (bidi=%s)",attr) end
- lro, rlo = true, false
- elseif attr == 4 then
- if trace then list[#list+1] = format("override left -> right (rlo) (bidi=%s)",attr) end
- lro, rlo = false, true
else
- if trace and current ~= head then list[#list+1] = format("override reset (bidi=%s)",attr) end
- lro, rlo = false, false
+ if trace then trace_natural("natural (no prev)",current) end
end
- prevattr = attr
end
- end
- if id == glyph then
- glyphs = true
- if attr and attr > 0 then
- local char = current.char
- local d = directions[char]
- if rlo or override > 0 then
- if d == "l" then
- if trace then list[#list+1] = format("char %s of class %s overidden to r (bidi=%s)",utf.char(char),d,attr) end
- d = "r"
- elseif trace then
- if d == "lro" or d == "rlo" or d == "pdf" then -- else side effects on terminal
- list[#list+1] = format("override char of class %s (bidi=%s)",d,attr)
- else -- todo: rle lre
- list[#list+1] = format("char %s of class %s (bidi=%s)",utf.char(char),d,attr)
- end
- end
- elseif lro or override < 0 then
- if d == "r" or d == "al" then
- set_attribute(current,state,4) -- maybe better have a special bidi attr value -> override (9) -> todo
- if trace then list[#list+1] = format("char %s of class %s overidden to l (bidi=%s) (state=isol)",utf.char(char),d,attr) end
- d = "l"
- elseif trace then
- if d == "lro" or d == "rlo" or d == "pdf" then -- else side effects on terminal
- list[#list+1] = format("override char of class %s (bidi=%s)",d,attr)
- else -- todo: rle lre
- list[#list+1] = format("char %s of class %s (bidi=%s)",utf.char(char),d,attr)
- end
- end
- elseif trace then
- if d == "lro" or d == "rlo" or d == "pdf" then -- else side effects on terminal
- list[#list+1] = format("override char of class %s (bidi=%s)",d,attr)
- else -- todo: rle lre
- list[#list+1] = format("char %s of class %s (bidi=%s)",utf.char(char),d,attr)
+ glue_order, glue_data = 0, nil
+ if current then
+ current = current.next
+ end
+ else
+ local sct = categories[sc] -- or 'unknown'
+ if sct == 'disable' then
+ ignore_following = true
+ if trace then trace_skip(sct,sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
+ elseif sct == 'nowhite' then
+ ignore_whitespace = true
+ head, current = remove_node(head, current, true)
+ elseif sct == 'discard' then
+ if trace then trace_skip(sct,sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
+ else
+ if sp then
+ if not penalty_data then
+ penalty_data = sp
+ elseif penalty_order < so then
+ penalty_order, penalty_data = so, sp
+ elseif penalty_order == so and sp > penalty_data then
+ penalty_data = sp
end
end
- if d == "on" then
- local mirror = data[char].mirror
- if mirror and fonts.tfm.id[current.font].characters[mirror] then
- -- todo: set attribute
- if autodir < 0 then
- current.char = mirror
- done = true
- --~ elseif left or autodir > 0 then
- --~ if not is_right(current.prev) then
- --~ current.char = mirror
- --~ done = true
- --~ end
+ if ignore_following then
+ if trace then trace_skip("disabled",sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
+ elseif not glue_data then
+ if trace then trace_skip("assign " .. sct,sc,so,sp,current) end
+ glue_order = so
+ head, current, glue_data = remove_node(head, current)
+ elseif glue_order < so then
+ if trace then trace_skip("force",sc,so,sp,current) end
+ glue_order = so
+ free_glue_node(glue_data)
+ head, current, glue_data = remove_node(head, current)
+ elseif glue_order == so then
+ if sct == 'largest' then
+ local cs, gs = current.spec, glue_data.spec
+ local cw = (cs and cs.width) or 0
+ local gw = (gs and gs.width) or 0
+ if cw > gw then
+ if trace then trace_skip('largest',sc,so,sp,current) end
+ free_glue_node(glue_data) -- also free spec
+ head, current, glue_data = remove_node(head, current)
+ else
+ if trace then trace_skip('remove smallest',sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
end
- end
- elseif d == "l" or d == "en" then -- european number
- if autodir <= 0 then
- force_auto_left_before()
- end
- elseif d == "r" or d == "al" or d == "an" then -- arabic left, arabic number
- if autodir >= 0 then
- force_auto_right_before()
- end
- elseif d == "lro" then -- Left-to-Right Override -> right becomes left
- if trace then list[#list+1] = "override right -> left" end
- top = top + 1
- stack[top] = { override, embedded }
- override = -1
- obsolete[#obsolete+1] = current
- elseif d == "rlo" then -- Right-to-Left Override -> left becomes right
- if trace then list[#list+1] = "override left -> right" end
- top = top + 1
- stack[top] = { override, embedded }
- override = 1
- obsolete[#obsolete+1] = current
- elseif d == "lre" then -- Left-to-Right Embedding -> TLT
- if trace then list[#list+1] = "embedding left -> right" end
- top = top + 1
- stack[top] = { override, embedded }
- embedded = 1
- obsolete[#obsolete+1] = current
- elseif d == "rle" then -- Right-to-Left Embedding -> TRT
- if trace then list[#list+1] = "embedding right -> left" end
- top = top + 1
- stack[top] = { override, embedded }
- embedded = 1
- obsolete[#obsolete+1] = current
- elseif d == "pdf" then -- Pop Directional Format
- -- override = 0
- if top > 0 then
- local s = stack[top]
- override, embedded = s[1], s[2]
- top = top - 1
- if trace then list[#list+1] = format("state: override: %s, embedded: %s, autodir: %s",override,embedded,autodir) end
- else
- if trace then list[#list+1] = "pop (error, too many pops)" end
- end
- obsolete[#obsolete+1] = current
- end
- else
- if trace then
- local char = current.char
- local d = directions[char]
- list[#list+1] = format("char %s of class %s (no bidi)",utf.char(char),d)
- end
- end
- elseif id == whatsit then
- if finish then
- finish_auto_before()
- end
- local subtype = current.subtype
- if subtype == 6 then
- local dir = current.dir
- local d = dir:sub(2,2)
- if dir:find(".R.") then
- autodir = -1
- else
- autodir = 1
- end
- embeddded = autodir
- if trace then list[#list+1] = format("pardir %s",dir) end
- elseif subtype == 7 then
- local dir = current.dir
- local sign = dir:sub(1,1)
- local dire = dir:sub(3,3)
- if dire == "R" then
- if sign == "+" then
- finish, autodir = "TRT", -1
+ elseif sct == 'goback' then
+ if trace then trace_skip('goback',sc,so,sp,current) end
+ free_glue_node(glue_data) -- also free spec
+ head, current, glue_data = remove_node(head, current)
+ elseif sct == 'force' then
+ -- todo: inject kern
+ if trace then trace_skip('force',sc,so,sp,current) end
+ free_glue_node(glue_data) -- also free spec
+ head, current, glue_data = remove_node(head, current)
+ elseif sct == 'penalty' then
+ if trace then trace_skip('penalty',sc,so,sp,current) end
+ free_glue_node(glue_data) -- also free spec
+ glue_data = nil
+ head, current = remove_node(head, current, true)
+ elseif sct == 'add' then
+ if trace then trace_skip('add',sc,so,sp,current) end
+ local old, new = glue_data.spec, current.spec
+ old.width = old.width + new.width
+ old.stretch = old.stretch + new.stretch
+ old.shrink = old.shrink + new.shrink
+ -- toto: order
+ head, current = remove_node(head, current, true)
else
- finish, autodir = nil, 0
+ if trace then trace_skip("unknown",sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
end
else
- if sign == "+" then
- finish, autodir = "TLT", 1
- else
- finish, autodir = nil, 0
- end
+ if trace then trace_skip("unknown",sc,so,sp,current) end
+ head, current = remove_node(head, current, true)
end
- if trace then list[#list+1] = format("textdir %s",dir) end
- end
- else
- if trace then list[#list+1] = format("node %s",node.type(id)) end
- if finish then
- finish_auto_before()
end
end
- local cn = current.next
- if not cn then
- if finish then
- finish_auto_after()
+ elseif id == penalty then
+ --~ natural_penalty = current.penalty
+ --~ if trace then trace_done("removed penalty",current) end
+ --~ head, current = remove_node(head, current, true)
+ current = current.next
+ elseif id == glue and current.subtype == 2 then
+ local sn = has_attribute(current,snap_category)
+ if sn then
+ -- local sv = nodes.snapvalues[sn]
+ -- if sv then
+ if trace then trace_natural("removed baselineskip",current) end
+ head, current = remove_node(head, current, true)
+ -- else
+ -- current = current.next
+ -- end
+ else
+ if trace then trace_natural("keep baselineskip",current) end
+ current = current.next
+ end
+ elseif id == glue and current.subtype == 3 then
+ -- parskip always comes later
+ if ignore_whitespace then
+ if trace then trace_natural("ignored parskip",current) end
+ head, current = remove_node(head,current,true)
+ elseif glue_data then
+ local ps, gs = current.spec, glue_data.spec
+ if ps and gs and ps.width > gs.width then
+ -- free_glue_spec(glue_data.spec) -- result in double free
+ glue_data.spec = copy_node(ps)
+ if trace then trace_natural("taking parskip",current) end
+ else
+ if trace then trace_natural("removed parskip",current) end
end
+ head, current = remove_node(head, current,true)
+ else
+ if trace then trace_natural("honored parskip",current) end
+ head, current, glue_data = remove_node(head, current)
end
- current = cn
- end
- if trace and glyphs then
- logs.report("bidi","start log")
- for i=1,#list do
- logs.report("bidi","%02i: %s",i,list[i])
- end
- logs.report("bidi","stop log")
- end
- if done and mirror.strip then
- local n = #obsolete
- if n > 0 then
- for i=1,n do
- nodes.remove(head,obsolete[i],true)
- end
- logs.report("bidi","%s character nodes removed",n)
+ --~ if trace then trace_natural("removed parskip",current) end
+ --~ current.spec = nil
+ --~ current = current.next
+ else
+ if glue_data then
+ if trace then trace_done("flushed",glue_data) end
+ head, current = insert_node_before(head,current,glue_data)
+ glue_order, glue_data = 0, nil
end
- end
- return head, done
- end
-
- chars.handle_mirroring = nodes.install_attribute_handler {
- name = "mirror",
- namespace = mirror,
- processor = mirror.process,
- }
-
- cases = cases or { }
- cases.enabled = false
- cases.actions = { }
-
- local function helper(start, code, codes)
- local data, char = characters.data, start.char
- local dc = data[char]
- if dc then
- local fnt = start.font
- local ifc = fonts.tfm.id[fnt].characters
- local ucs = dc[codes]
- if ucs then
- local ok = true
- for i=1,#ucs do
- ok = ok and ifc[ucs[i]]
- end
- if ok then
- local prev, original, copy = start, start, node.copy
- for i=1,#ucs do
- local chr = ucs[i]
- prev = start
- if i == 1 then
- start.char = chr
- else
- local g = copy(original)
- g.char = chr
- local next = start.next
- g.prev = start
- if next then
- g.next = next
- start.next = g
- next.prev = g
- end
- start = g
+ if penalty_data then
+ local p = make_penalty_node(penalty_data)
+ if trace then trace_done("flushed",p) end
+ head, current = insert_node_before(head,current,p)
+ penalty_data = nil
+ end
+ if trace then trace_node(current) end
+ if id == hlist and where == 'hmode_par' then
+ local list = current.list
+ if list then
+ local sn = has_attribute(list,snap_category)
+ if sn then
+ local sv = nodes.snapvalues[sn]
+ if sv then
+ local height, depth, lineheight = sv[1], sv[2], sv[3]
+ -- is math.ceil really needed?
+ current.height = math.ceil((current.height-height)/lineheight)*lineheight + height
+ current.depth = math.ceil((current.depth -depth )/lineheight)*lineheight + depth
end
end
- return prev, true
end
- return start, false
- end
- local uc = dc[code]
- if uc and ifc[uc] then
- start.char = uc
- return start, true
end
+ current = current.next
end
- return start, false
end
-
- local function upper(start)
- return helper(start,'uccode','uccodes')
+ local tail = slide_node_list(head) -- still needed, check previous code ?
+ if trace then trace_info("stop analyzing",where,what) end
+ --~ if natural_penalty and (not penalty_data or natural_penalty > penalty_data) then
+ --~ penalty_data = natural_penalty
+ --~ end
+ if trace and (glue_data or penalty_data) then
+ trace_info("start flushing",where,what)
end
- local function lower(start)
- return helper(start,'lccode','lccodes')
+ if penalty_data then
+ local p = make_penalty_node(penalty_data)
+ if trace then trace_done("result",p) end
+ head, tail = insert_node_after(head,tail,p)
end
-
- cases.actions[1], cases.actions[2] = upper, lower
-
- cases.actions[3] = function(start,attribute)
- local prev = start.prev
- if prev and prev.id == kern and prev.subtype == 0 then
- prev = prev.prev
- end
- if not prev or prev.id ~= glyph then
- --- only the first character is treated
- for n in traverse_id(glyph,start.next) do
- if has_attribute(n,attribute) then
- unset_attribute(n,attribute)
- end
- end
- return upper(start)
- else
- return start, false
- end
+ if glue_data then
+ if trace then trace_done("result",glue_data) end
+ head, tail = insert_node_after(head,tail,glue_data)
end
-
- cases.actions[4] = function(start,attribute)
- local prev = start.prev
- if prev and prev.id == kern and prev.subtype == 0 then
- prev = prev.prev
- end
- if not prev or prev.id ~= glyph then
- return upper(start)
- else
- return start, false
+ if trace then
+ if glue_data or penalty_data then
+ trace_info("stop flushing",where,what)
end
+ show_tracing(head)
end
+ return head, true
+end
+
+-- alignment after_output end box new_graf vmode_par hmode_par insert penalty before_display after_display
+-- \par -> vmode_par
+--
+-- status.best_page_break
+-- tex.lists.best_page_break
+-- tex.lists.best_size (natural size to best_page_break)
+-- tex.lists.least_page_cost (badness of best_page_break)
+-- tex.lists.page_head
+-- tex.lists.contrib_head
+
+local stackhead, stacktail, stackhack = nil, nil, false
- -- cases.actions[5] = function(start)
- -- local prev, next = start.prev, start.next
- -- if prev and prev.id == kern and prev.subtype == 0 then
- -- prev = prev.prev
- -- end
- -- if next and next.id == kern and next.subtype == 0 then
- -- next = next.next
- -- end
- -- if (not prev or prev.id ~= glyph) and next and next.id == glyph then
- -- return upper(start)
- -- else
- -- return start, false
- -- end
- -- end
+local function report(message,lst)
+ logs.report("vspacing",message,count_nodes(lst,true),node_ids_to_string(lst))
+end
- cases.actions[8] = function(start)
- local data = characters.data
- local ch = start.char
- local mr = math.random
- local tfm = fonts.tfm.id[start.font].characters
- if data[ch].lccode then
- while true do
- local d = data[mr(1,0xFFFF)]
- if d then
- local uc = d.uccode
- if uc and tfm[uc] then
- start.char = uc
- return start, true
+function nodes.handle_page_spacing(where)
+ local newhead = texlists.contrib_head
+ if newhead then
+ statistics.starttiming(vspacing)
+ local newtail = slide_node_list(newhead)
+ local flush = false
+ for n in traverse_nodes(newhead) do
+ local id = n.id
+ if id == glue then
+ if n.subtype == 0 then
+ if has_attribute(n,skip_category) then
+ stackhack = true
+ else
+ flush = true
end
+ else
+ -- tricky
end
+ else
+ flush = true
end
- elseif data[ch].uccode then
- while true do
- local d = data[mr(1,0xFFFF)]
- if d then
- local lc = d.lccode
- if lc and tfm[lc] then
- start.char = lc
- return start, true
- end
- end
+ end
+ if flush then
+ if stackhead then
+ if trace_collect_vspacing then report("appending %s nodes to stack (final): %s",newhead) end
+ stacktail.next = newhead
+ newhead.prev = stacktail
+ newhead = stackhead
+ stackhead, stacktail = nil, nil
+ end
+ if stackhack then
+ stackhack = false
+ if trace_collect_vspacing then report("processing %s nodes: %s",newhead) end
+ texlists.contrib_head = collapser(newhead,"page",where,trace_page_vspacing)
+ else
+ if trace_collect_vspacing then report("flushing %s nodes: %s",newhead) end
+ texlists.contrib_head = newhead
end
else
- return start, false
- end
- end
-
- -- node.traverse_id_attr
-
- function cases.process(namespace,attribute,head) -- not real fast but also not used on much data
- local done, actions = false, cases.actions
- for start in traverse_id(glyph,head) do
- local attr = has_attribute(start,attribute)
- if attr and attr > 0 then
- unset_attribute(start,attribute)
- local action = actions[attr]
- if action then
- local _, ok = action(start,attribute)
- done = done and ok
- end
+ if stackhead then
+ if trace_collect_vspacing then report("appending %s nodes to stack (intermediate): %s",newhead) end
+ stacktail.next = newhead
+ newhead.prev = stacktail
+ else
+ if trace_collect_vspacing then report("storing %s nodes in stack (initial): %s",newhead) end
+ stackhead = newhead
end
+ stacktail = newtail
+ texlists.contrib_head = nil
end
- return head, done
+ statistics.stoptiming(vspacing)
end
+end
- chars.handle_casing = nodes.install_attribute_handler {
- name = "case",
- namespace = cases,
- processor = cases.process,
- }
-
- breakpoints = breakpoints or { }
- breakpoints.mapping = breakpoints.mapping or { }
- breakpoints.methods = breakpoints.methods or { }
- breakpoints.enabled = false
-
- input.storage.register(false,"breakpoints/mapping", breakpoints.mapping, "breakpoints.mapping")
+local ignore = table.tohash {
+ "split_keep",
+ "split_off",
+ -- "vbox",
+}
- function breakpoints.setreplacement(id,char,kind,before,after)
- local mapping = breakpoints.mapping[id]
- if not mapping then
- mapping = { }
- breakpoints.mapping[id] = mapping
- end
- mapping[char] = { kind or 1, before or 1, after or 1 }
+function nodes.handle_vbox_spacing(head,where)
+ if head and not ignore[where] and head.next then
+ statistics.starttiming(vspacing)
+ head = collapser(slide_node_list(head),"vbox",where,trace_vbox_vspacing)
+ statistics.stoptiming(vspacing)
end
+ return head
+end
- breakpoints.methods[1] = function(head,start)
- if start.prev and start.next then
- node.insert_before(head,start,nodes.penalty(10000))
- node.insert_before(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.penalty(0))
- end
- return head, start
- end
- breakpoints.methods[2] = function(head,start) -- ( => (-
- if start.prev and start.next then
- local tmp = start
- start = nodes.disc()
- start.prev, start.next = tmp.prev, tmp.next
- tmp.prev.next, tmp.next.prev = start, start
- tmp.prev, tmp.next = nil, nil
- start.replace = tmp
- local tmp, hyphen = node.copy(tmp), node.copy(tmp)
- hyphen.char = languages.prehyphenchar(tmp.lang)
- tmp.next, hyphen.prev = hyphen, tmp
- start.post = tmp
- node.insert_before(head,start,nodes.penalty(10000))
- node.insert_before(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.penalty(10000))
- end
- return head, start
- end
- breakpoints.methods[3] = function(head,start) -- ) => -)
- if start.prev and start.next then
- local tmp = start
- start = nodes.disc()
- start.prev, start.next = tmp.prev, tmp.next
- tmp.prev.next, tmp.next.prev = start, start
- tmp.prev, tmp.next = nil, nil
- start.replace = tmp
- local tmp, hyphen = node.copy(tmp), node.copy(tmp)
- hyphen.char = languages.prehyphenchar(tmp.lang)
- tmp.prev, hyphen.next = hyphen, tmp
- start.pre = hyphen
- node.insert_before(head,start,nodes.penalty(10000))
- node.insert_before(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.glue(0))
- node.insert_after(head,start,nodes.penalty(10000))
- end
- return head, start
+statistics.register("v-node processing time", function()
+ if statistics.elapsedindeed(vspacing) then
+ return format("%s seconds", statistics.elapsedtime(vspacing))
end
+end)
- function breakpoints.process(namespace,attribute,head)
- local done, mapping, fontids = false, breakpoints.mapping, fonts.tfm.id
- local start, n = head, 0
- while start do
- local id = start.id
- if id == glyph then
- local attr = has_attribute(start,attribute)
- if attr and attr > 0 then
- unset_attribute(start,attribute) -- maybe test for subtype > 256 (faster)
- -- look ahead and back n chars
- local map = mapping[attr]
- if map then
- local smap = map[start.char]
- if smap then
- if n >= smap[2] then
- local m = smap[3]
- local next = start.next
- while next do -- gamble on same attribute
- local id = next.id
- if id == glyph then -- gamble on same attribute
- if map[next.char] then
- break
- elseif m == 1 then
- local method = breakpoints.methods[smap[1]]
- if method then
- head, start = method(head,start)
- done = true
- end
- break
- else
- m = m - 1
- next = next.next
- end
- elseif id == kern and next.subtype == 0 then
- next = next.next
- -- ignore intercharacter kerning, will go way
- else
- -- we can do clever and set n and jump ahead but ... not now
- break
- end
- end
- end
- n = 0
- else
- n = n + 1
- end
- else
- n = 0
- end
- end
- elseif id == kern and start.subtype == 0 then
- -- ignore intercharacter kerning, will go way
- else
- n = 0
- end
- start = start.next
- end
- return head, done
- end
-
- chars.handle_breakpoints = nodes.install_attribute_handler {
- name = "breakpoint",
- namespace = breakpoints,
- processor = breakpoints.process,
- }
+-- these are experimental callback definitions that definitely will
+-- be moved elsewhere as part of a chain of vnode handling
+function vspacing.enable()
+--~ callback.register('vpack_filter', nodes.handle_vbox_spacing)
+ callback.register('buildpage_filter', nodes.handle_page_spacing)
end
--- educational: snapper
-
---~ function demo_snapper(head,where) -- snap_category 105 / nodes.snapvalue = { [1] = { 8*65536, 4*65536, 12*65536 } }
---~ if head then
---~ local current, tail, dummy = head, nil, nil
---~ while current do
---~ local id = current.id
---~ if id == glue and current.subtype == 2 then
---~ local sn = has_attribute(current,snap_category)
---~ if sn then
---~ local sv = nodes.snapvalues[sn]
---~ if sv then
---~ head, current, dummy = node.delete(head, current)
---~ node.free(dummy)
---~ else
---~ current = current.next
---~ end
---~ else
---~ current = current.next
---~ end
---~ else
---~ if id == hlist and where == 'hmode_par' and current.list then
---~ local sn = has_attribute(current.list,snap_category)
---~ if sn then
---~ local sv = nodes.snapvalues[sn]
---~ if sv then
---~ local height, depth, lineheight = sv[1], sv[2], sv[3]
---~ current.height = math.ceil((current.height-height)/lineheight)*lineheight + height
---~ current.depth = math.ceil((current.depth -depth )/lineheight)*lineheight + depth
---~ end
---~ end
---~ end
---~ current = current.next
---~ end
---~ tail = current
---~ end
---~ end
---~ return head
---~ end
-
---~ callback.register('buildpage_filter', demo_snapper)
-
--- obsolete, callback changed
-
---~ local head, tail = nil, nil
-
---~ function nodes.flush_vertical_spacing()
---~ if head and head.next then
---~ local t = collapser(head,'flush')
---~ head = nil
---~ -- tail = nil
---~ return t
---~ else
---~ return head
---~ end
---~ end
-
---~ function nodes.handle_page_spacing(t, where)
---~ where = where or "page"
---~ -- we need to add the latest t too, else we miss skips and such
---~ if t then
---~ --~ node.slide(t) -- redunant
---~ if t.next then
---~ local tt = node.slide(t)
---~ local id = tt.id
---~ if id == glue then -- or id == penalty then -- or maybe: if not hlist or vlist
---~ if head then
---~ t.prev = tail
---~ tail.next = t
---~ else
---~ head = t
---~ end
---~ tail = tt
---~ t = nil
---~ elseif head then
---~ t.prev = tail
---~ tail.next = t
---~ t = collapser(head,"page",where)
---~ head = nil
---~ else
---~ t = collapser(t,"page",where)
---~ end
---~ elseif head then
---~ t.prev = tail
---~ tail.next = t
---~ t = collapser(head,"page",where)
---~ head = nil
---~ else
---~ t = collapser(t,"page",where)
---~ end
---~ elseif head then
---~ t = collapser(head,"page",where)
---~ head = nil
---~ end
---~ return t
---~ end
+function vspacing.disable()
+ callback.register('vpack_filter', nil)
+ callback.register('buildpage_filter', nil)
+end
diff --git a/tex/context/base/core-spa.mkii b/tex/context/base/core-spa.mkii
index b3d71699d..356b2cbe3 100644
--- a/tex/context/base/core-spa.mkii
+++ b/tex/context/base/core-spa.mkii
@@ -11,36 +11,4644 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Spacing}
+
+% to be sorted out: dependencies, order of initialization / also some dutch code here
+
\unprotect
-% Just after we implemented the \MKIV\ code, Thanh posted a patch for
-% \PDFTEX. The following code is untested! (\LUATEX\ does not contain
-% this code!)
+% some will move to core-var
+
+\newif \ifgridsnapping
+\newif \iffuzzyvskip
+\let \fuzzyvskip \gobbleoneargument
+\let \removelastfuzzyvskip \relax
+
+\let \startbaselinecorrection \relax
+\let \stopbaselinecorrection \relax
+\let \baselinecorrection \relax
+\let \offbaselinecorrection \relax
+
+\appendtoks \spacing 1\to \everybodyfont
+\appendtoks \presetnormallineheight \to \everybodyfont
+\appendtoks \setnormalbaselines \to \everybodyfont % check if redundant
+\appendtoks \setstrut \to \everybodyfont % check if redundant
+\appendtoks \settopskip \to \everybodyfont
+\appendtoks \setmaxdepth \to \everybodyfont
+%appendtoks \spacing 1\to \everybodyfont
+\appendtoks \simplesetupindenting \to \everybodyfont
+\appendtoks \simplesetupblank \to \everybodyfont
+\appendtoks \simplesetupwhitespace \to \everybodyfont
+%appendtoks \checknotes \to \everybodyfont % not
+\appendtoks \simplesetupspacing \to \everybodyfont % nieuw
+\appendtoks \setrelativeinterlinespace \to \everybodyfont
+
+\appendtoks \updateraggedskips \to \everyfontswitch % under test
+\prependtoks \let\par\endgraf \to \everypagebody % see \fillinline
+\appendtoks \simplesetupspacing \to \everydefinedfont
+
+% if you want to hyphenate the first word of a paragraph ... \appendtoks\hskip0pt\to\everypar
+
+\def\stelfactorenin
+ {\simplesetupwhitespace
+ \simplesetupblank
+ \settopskip
+ \setmaxdepth}
+
+\def\softbreak
+ {\relax\ifhmode\hskip\parfillskip\break\fi}
+
+\let\poplastnode\relax
+
+\def\pushlastnode
+ {\ifdim\lastskip=\zeropoint
+ \ifnum\lastpenalty=\zerocount
+ \ifnum\lastkern=\zerocount
+ \let\poplastnode\relax
+ \else
+ \edef\poplastnode{\kern\the\lastkern\relax}\kern-\lastkern % untested
+ \fi
+ \else
+ \edef\poplastnode{\penalty\the\lastpenalty\relax}\nobreak % untested
+ \fi
+ \else
+ \edef\poplastnode{\vskip\the\lastskip\relax}\vskip-\lastskip % \removelastskip
+ \fi}
+
+%D The dreadful sequence \type {\bgroup} \unknown\
+%D \type {\carryoverpar} \unknown\ \type {\egroup} is needed
+%D when for instance sidefloats are used in combination with
+%D something that starts with a group. This is because
+%D otherwise the indentation as set (by the output routine)
+%D inside the group are forgotten afterwards. (I must
+%D not forget its existence).
+
+\global\let\carriedoverpar\relax
+
+\def\carryoverpar#1%
+ {\expanded % \scratchtoks{#1}%
+ {\noexpand#1% \the\scratchtoks
+ \hangindent\the\hangindent
+ \hangafter \the\hangafter
+ \parskip \the\parskip
+ \leftskip \the\leftskip
+ \rightskip \the\rightskip}}
+
+%D A quick way to determine left|/|middle|/|right states
+%D (experimental).
+
+\setvalue{\??as\v!left }{0}
+\setvalue{\??as\v!middle}{1}
+\setvalue{\??as\v!right }{2}
+
+\def\setalignmentswitch#1%
+ {\chardef\alignmentswitch0\csname\??as#1\endcsname\relax}
+
+%D There are two ways to influence the interline spacing. The
+%D most general and often most consistent way is using
+%D
+%D \showsetup{setupinterlinespace}
+%D
+%D For instance
+%D
+%D \starttyping
+%D \setupinterlinespace[line=2.8ex]
+%D \stoptyping
+%D
+%D This setting adapts itself to the bodyfontsize, while for
+%D instance saying
+%D
+%D \starttyping
+%D \setupinterlinespace[line=12pt]
+%D \stoptyping
+%D
+%D sets things fixed for all sizes, which is definitely not
+%D what we want. Therefore one can also say:
+%D
+%D \starttyping
+%D \definebodyfontenvironment[9pt][interlinespace=11pt]
+%D \stoptyping
+%D
+%D One can still use \type{\setupinterlinespace} (without
+%D arguments) to set the interline space according to the
+%D current font, e.g. a \type{\bfa}.
+
+\newif\iflocalinterlinespace
+
+% font-ini
+
+\ifx\bodyfontinterlinespecs\undefined
+
+ \let\bodyfontinterlinespecs\empty
+ \let\bodyfontinterlinespace\empty
+
+\fi
+
+\def\presetnormallineheight
+ {\edef\normallineheight{\@@itline}%
+% done elsewhere : \spacing\!!plusone % new per 10/08/2004, else problems in otr / !! needed
+ \iflocalinterlinespace \else
+ \doifdefined\bodyfontinterlinespecs
+ {\doifsomething\bodyfontinterlinespace
+ {\edef\normallineheight{\bodyfontinterlinespace}}}%
+ \fi}
+
+\def\setupspecifiedinterlinespace[#1]%
+ {\getparameters[\??it][#1]%
+ \scratchdimen0\@@itheight\points
+ \advance\scratchdimen 0\@@itdepth\points
+ \ifdim\scratchdimen>\onepoint
+ \showmessage\m!layouts{10}{\@@itheight,\@@itdepth}%
+ \let\@@itheight\strutheightfactor
+ \let\@@itdepth \strutdepthfactor
+ \else
+ \let\strutheightfactor\@@itheight
+ \let\strutdepthfactor \@@itdepth
+ \fi
+ \let\minimumstrutheight \@@itminheight
+ \let\minimumstrutdepth \@@itmindepth
+ \let\minimumlinedistance\@@itdistance
+ \let\normallineheight \@@itline % let ! ! ! ! ! ivm ex
+ \doifelse\@@ittop\v!height % new, topskip does more bad than good
+ {\let\topskipfactor \@@itheight}
+ {\let\topskipfactor \@@ittop }%
+ \let\maxdepthfactor \@@itbottom
+ \let\baselinegluefactor \@@itstretch
+ \setfontparameters % redundant, can be \setstrut, test first
+ \updateraggedskips} % yes indeed
+
+% \let\currentrelativeinterlinespace\empty
+%
+% \def\setuprelativeinterlinespace[#1]%
+% {\processallactionsinset
+% [#1]
+% [ \v!on=>\oninterlineskip,
+% \v!off=>\offinterlineskip,
+% \v!reset=>\let\currentrelativeinterlinespace\empty
+% \setfontparameters,% just \setstrut, test first
+% \s!unknown=>\assignvalue{#1}\currentrelativeinterlinespace{1.00}{1.25}{1.50}%
+% \spacing\currentrelativeinterlinespace]}
+
+% \setupinterlinespace[big] \switchtobodyfont[11pt] -> forgotten
+% \setupinterlinespace[auto,big] \switchtobodyfont[11pt] -> remembered
+
+\let\currentrelativeinterlinespace\empty
+
+\def\setuprelativeinterlinespace[#1]%
+ {\processallactionsinset
+ [#1]
+ [ \v!on=>\oninterlineskip,
+ \v!off=>\offinterlineskip,
+ \v!reset=>\let\currentrelativeinterlinespace\empty
+ \let\setrelativeinterlinespace\relax
+ \setfontparameters,
+ \v!auto=>\let\setrelativeinterlinespace\dosetrelativeinterlinespace,
+ \s!unknown=>\assignvalue\commalistelement\currentrelativeinterlinespace{1.00}{1.25}{1.50}%
+ \spacing\currentrelativeinterlinespace]}
+
+\def\dosetrelativeinterlinespace
+ {\ifx\currentrelativeinterlinespace\empty\else
+ \spacing\currentrelativeinterlinespace
+ \fi}
+
+\let\setrelativeinterlinespace\relax
+
+% \appendtoks \setrelativeinterlinespace \to \everybodyfont
+
+\def\complexsetupinterlinespace[#1]% \commalistelement ipv #1
+ {\doifassignmentelse{#1}\setupspecifiedinterlinespace\setuprelativeinterlinespace[#1]}
+
+\def\setuplocalinterlinespace[#1]%
+ {\localinterlinespacetrue
+ \setupinterlinespace[#1]%
+ \localinterlinespacefalse}
+
+\def\simplesetupinterlinespace
+ {\localinterlinespacetrue
+ \setfontparameters
+ \updateraggedskips % funny one here
+ \localinterlinespacefalse}
+
+\definecomplexorsimple\setupinterlinespace
+
+% In earlier versions \type{\bigskipamount} was
+% \type{\ht\strutbox} and the stretch was plus or minus
+% \type{.4\dp\strutbox}. Don't ask me why. The most recent
+% implementation is based on a user supplied distance, which
+% is by default \type{.75\normalskipamount} where
+% \type{\normalskipamount} equals the current baseline
+% distance.
+
+% \lineskiplimit = -\maxdimen -> freezes baselineskip
+
+% can be conditionals
+
+\newif\ifblanknowhite \blanknowhitefalse
+\newif\ifblankindeed \blankindeedfalse
+\newif\ifblankreset \blankresetfalse
+\newif\ifblankdisable \blankdisablefalse
+\newif\ifblankflexible \blankflexibletrue
+\newif\ifblankouter
+\newif\ifblankforce
+\newif\ifblankgoback
+
+\newskip\blankskip \blankskip=\bigskipamount
+\newskip\blankskipamount
+
+\def\skipfactor {.75}
+\def\skipgluefactor{.25}
+
+\def\normalskipamount
+ {\openlineheight
+ \ifgridsnapping \else \ifblankflexible
+ \!!plus \skipgluefactor\openlineheight
+ \!!minus\skipgluefactor\openlineheight
+ \fi \fi
+ \relax}
+
+\def\linedistance {\normalskipamount}
+\def\appliedblankskip{\skipfactor\linedistance}
+\def\lastblankskip {\blankskip}
+\def\currentblank {\v!big}
+\def\oldprevdepth {\prevdepth}
+\def\newprevdepth {-1001pt}
+\def\mindimen {1sp} % was: 0.00002pt
+
+\newif\iflocalblankfixed
+\newif\iflocalblankflexible
+
+\def\geenblanko{\removelastskip} % will become obsolete
+
+%%%% pas op, wordt ook in core-pos gebruikt
+
+\def\doassignsomeskip#1\to#2% ook nog \v!halfline+fuzzysnap
+ {\doifelse{#1}\v!line
+ {#2\openlineheight}
+ {\ifgridsnapping
+ \assigndimension{#1}{#2}{.25\openlineheight}{.5\openlineheight}\openlineheight
+ \else
+ \assigndimension{#1}{#2}\smallskipamount\medskipamount\bigskipamount
+ \fi}%
+ \relax}
+
+% \relax is really needed, else we may loose stretch due to lookahead; somehow
+% this bug was introduced a while ago but somehow went unnoticed; fixed 2/7/2008
+
+\def\addblankskip#1#2#3{\global\advance\blankskip#1\ifgridsnapping#3\else#2\fi\relax}
+
+\def\defineblankmethod[#1]#2{\setvalue{\??bo\??bo#1}{#2}}
+
+\defineblankmethod [\v!big] {\addblankskip+\bigskipamount \openlineheight}
+\defineblankmethod [-\v!big] {\addblankskip-\bigskipamount \openlineheight}
+\defineblankmethod [\v!medium] {\addblankskip+\medskipamount {.5\openlineheight}}
+\defineblankmethod [-\v!medium] {\addblankskip-\medskipamount {.5\openlineheight}}
+\defineblankmethod [\v!small] {\addblankskip+\smallskipamount{.25\openlineheight}}
+\defineblankmethod [-\v!small] {\addblankskip-\smallskipamount{.25\openlineheight}}
+\defineblankmethod [\v!white] {\addblankskip+\parskip \openlineheight}
+\defineblankmethod [-\v!white] {\addblankskip-\parskip \openlineheight}
+\defineblankmethod [\v!line] {\addblankskip+\openlineheight \openlineheight}
+\defineblankmethod [-\v!line] {\addblankskip-\openlineheight \openlineheight}
+
+\defineblankmethod [\v!formula] {\global\advance\blankskip\medskipamount}
+\defineblankmethod [\v!nowhite] {\global\blanknowhitetrue}
+\defineblankmethod [\v!disable] {\global\blankdisabletrue}
+\defineblankmethod [\v!force] {\global\blankforcetrue}
+\defineblankmethod [\v!outer] {\ifvmode\ifinner\blankoutertrue\fi\fi}
+\defineblankmethod [\v!reset] {\global\blankresettrue}
+\defineblankmethod [\v!flexible] {\global\localblankflexibletrue}
+\defineblankmethod [\v!fixed] {\global\localblankfixedtrue}
+\defineblankmethod [\v!back] {\global\blankgobacktrue} % {\geenblanko}
+\defineblankmethod [\v!halfline] {\ifgridsnapping\global\fuzzyvskiptrue\fi
+ \global\advance\blankskip .5\lineheight}
+
+\defineblankmethod [\v!none] {\global\blankresettrue}
+\defineblankmethod [\v!joinedup] {\ifvmode\nointerlineskip\fi}
+
+\defineblankmethod [\v!always] {\redowhitespace} % experimental
+
+% happens often, so we speed this up:
+%
+% \defineblankmethod [2*\v!line] {\addblankskip+{2\openlineheight}{2\openlineheight}}
+% \defineblankmethod [2*\v!big] {\addblankskip+{2\bigskipamount }{2\openlineheight}}
+%
+% no, with 2\whatever we loose the stretch and shrink! Taco's alternative:
+
+\defineblankmethod
+ [2*\v!line]
+ {\addblankskip+\openlineheight\openlineheight
+ \addblankskip+\openlineheight\openlineheight}
+
+\defineblankmethod
+ [2*\v!big]
+ {\addblankskip+\bigskipamount\openlineheight
+ \addblankskip+\bigskipamount\openlineheight}
+
+\def\doblank#1%
+ {\edefconvertedargument\ascii{#1}%
+ \ifx\ascii\empty\else
+ \ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+ \else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
+ \else
+ \dorepeatwithcommand[#1]\redoblank
+ \fi\fi
+ \fi
+ \relax}
+
+\def\redoblank#1%
+ {\edefconvertedargument\ascii{#1}%
+ \ifx\ascii\empty\else
+ \ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+ \else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
+ \else
+ \global\advance\blankskip#1\relax
+ \fi\fi
+ \fi
+ \relax}
+
+\unexpanded\def\blank % the \relax is definitely needed due to the many \if's
+ {\relax\complexorsimple\doblank}
+
+\def\complexdoblank
+ {\flushnotes
+ \ifmmode
+ \@EA\nocomplexdoblank
+ \else
+ \ifopelkaar
+ \ifinpagebody
+ \@EA\@EAEAEA\@EA\docomplexdoblank
+ \else
+ \@EA\@EAEAEA\@EA\nocomplexdoblank
+ \fi
+ \else
+ \@EAEAEA\docomplexdoblank
+ \fi
+ \fi}
+
+\def\nocomplexdoblank[#1]%
+ {% evt blokkeerfalse
+ \ifmmode\else\par\fi}
+
+% Overloaded in cont-new!
+
+\newsignal\noblanksignal
+
+% \def\doinhibitblank
+% {\kern\noblanksignal}
+
+% \def\inhibitblank% the fast, local way
+% {\endgraf\ifvmode\prevdepth\newprevdepth\fi}
+
+% \def\docomplexdoblank[#1]% pas op \relax's zijn nodig ivm volgende \if
+% {\global\blankresetfalse
+% \global\blankdisablefalse
+% \global\blanknowhitefalse
+% \global\localblankflexiblefalse
+% \global\localblankfixedfalse
+% \global\blankskip\zeropoint
+% \global\blankforcefalse
+% \global\blankgobackfalse
+% \blankouterfalse
+% \expanded{\rawprocesscommalist[#1]}\doblank
+% \ifdim\blankskip=\zeropoint\relax
+% \iflocalblankflexible
+% \doglobal\advance\blankskip \currentblank
+% \else\iflocalblankfixed
+% \doglobal\advance\blankskip \currentblank
+% \fi\fi
+% \fi
+% \ifblankouter
+% \else
+% \par
+% \ifvmode
+% \ifblankgoback
+% \removelastskip
+% \fi
+% \ifblankforce
+% % dit gaat mis in pos fonts
+% % \ifdim\prevdepth>\zeropoint\else ...
+% % -1000pt signals top of page or column (\ejectcolumn)
+% \bgroup\forgeteverypar\verticalstrut\egroup\kern-\struttotal
+% \fi
+% \ifblankdisable
+% \global\blankindeedfalse
+% \ifgridsnapping
+% \ifdim\prevdepth<\zeropoint
+% % brrr
+% \else
+% % dirty trick: smaller blanks are ignored after
+% % a larger one, so 10 lines is probably safe; first make
+% % sure that we honor penalties
+% \scratchcounter\lastpenalty
+% % now comes the trick (cross our fingers that this works
+% % well in multi columns; maybe an ifinner test is needed
+% % \vskip-10\lineheight
+% % \ifnum\scratchcounter=\zerocount \else \penalty\lastpenalty \fi
+% % \vskip 10\lineheight
+% % allas, this leads to overfull pages, so we try this:
+% \kern-\noblanksignal
+% \ifnum\scratchcounter=\zerocount
+% \else
+% \penalty\lastpenalty
+% \fi
+% \kern\noblanksignal
+% % end-of-dirty-trick
+% \fi
+% \else
+% \ifdim\prevdepth<\zeropoint
+% % brrr
+% \else
+% % ensure at least a proper prevdepth, this should be
+% % an option
+% \vskip-\prevdepth
+% \vskip\strutdepth
+% \prevdepth\strutdepth
+% \fi
+% % the old crappy piece of code
+% \edef\oldprevdepth{\the\prevdepth}%
+% \prevdepth\newprevdepth
+% \fi
+% \else
+% \global\blankindeedtrue
+% \fi
+% \ifblankreset
+% \global\blankindeedtrue
+% \ifgridsnapping
+% % let's play safe and not fool around with the depth, if
+% % only because it took a lot of effort to sort out the grid
+% % stuff in the first place
+% \else
+% \ifdim\prevdepth=\newprevdepth
+% \prevdepth\oldprevdepth
+% \fi
+% \fi
+% \fi
+% \ifblankindeed
+% \ifdim1\lastskip<1\blankskip\relax
+% % else when \blanko[2*groot] + \blanko[3*groot] with parskip
+% % equaling 1*groot, gives a groot=\parskip so adding a small
+% % value makes it distinguishable; can also be done at parskip
+% % setting time (better)
+% \global\advance\blankskip \mindimen\relax % = skip
+% % test this on 2* + 3* and parskip groot
+% \ifblanknowhite
+% \global\advance\blankskip -\parskip
+% \else
+% \ifdim\lastskip=\parskip
+% \else % force this due to previous comment
+% \ifdim\parskip>\zeropoint\relax
+% \ifdim\blankskip<\parskip\relax
+% \global\blankskip\zeropoint
+% \else
+% \global\advance\blankskip -\parskip
+% \fi
+% \fi
+% \fi
+% \fi
+% \ifblankflexible \else
+% \blankskip1\blankskip
+% \fi
+% \iflocalblankfixed
+% \blankskip1\blankskip
+% \fi
+% \iflocalblankflexible
+% \blankskip1\blankskip
+% \!!plus\skipgluefactor\blankskip
+% \!!minus\skipgluefactor\blankskip
+% \fi
+% \ifdim\lastkern=\noblanksignal % controled and grid
+% \global\blankindeedfalse
+% \else\ifgridsnapping\else\ifdim\prevdepth=\newprevdepth
+% \global\blankindeedfalse
+% \fi\fi\fi
+% \ifblankindeed
+% \iffuzzyvskip
+% \removelastfuzzyvskip
+% \fuzzyvskip\blankskip\relax
+% \else
+% \removelastskip
+% \vskip\blankskip\relax
+% \fi
+% \fi
+% \else
+% \iffuzzyvskip
+% \removelastfuzzyvskip
+% \fuzzyvskip\blankskip\relax
+% \else
+% % new, test this on pascal
+% \ifdim\blankskip<\zeropoint
+% \advance\blankskip-\lastskip
+% \removelastskip
+% \ifdim\blankskip>\zeropoint
+% \vskip\blankskip
+% \else
+% \vskip\zeropoint
+% \fi
+% \else
+% % also new
+% \ifdim\blankskip=\zeropoint
+% \ifblanknowhite
+% \geenwitruimte
+% \fi
+% \fi
+% \fi
+% \fi
+% \fi
+% \fi
+% \fi
+% \fi
+% \global\fuzzyvskipfalse
+% \presetindentation}
+
+% goback was broken:
-\ifx\pdfkeeplinedimen\undefined
+% \def\doinhibitblank
+% {\kern\noblanksignal}
- \let\mksetupgridsnapping \relax
- \let\mkenablegridsnapping \relax
- \let\mkdisablegridsnapping\relax
+% \def\inhibitblank% the fast, local way
+% {\endgraf\ifvmode\prevdepth\newprevdepth\fi}
+% problem: we cannot look back in the mvl so we need 3 kinds of signals
+
+\def\noblankpsignal{1010101}
+
+\def\inhibitgridblank % was doinhibitblank
+ {\ifvmode\else\endgraf\fi
+ \ifvmode
+ \ifnum\lastpenalty<10000
+ \kern-\noblanksignal % new
+ \kern \noblanksignal
+ \else
+ \penalty\noblankpsignal
+ \fi
+ \fi}
+
+\def\inhibittextblank % was inhibitblank
+ {\endgraf
+ \ifvmode
+ \prevdepth\newprevdepth
+ \fi}
+
+% new macro
+%
+% \def\inhibitblank % need some work
+% {\endgraf
+% \ifvmode
+% \ifgridsnapping
+% \inhibitgridblank
+% \else
+% % this one spoils the grid
+% \inhibittextblank
+% \fi
+% \fi}
+
+\def\doinhibitblank{\inhibitgridblank}
+\def\inhibitblank {\inhibittextblank}
+
+% will become obsolete
+
+\ifx\undefined\savedlastskip \newskip \savedlastskip \fi
+\ifx\undefined\savedlastpenalty \newcount\savedlastpenalty \fi
+
+% beware, prevdepth can have funny values (e.g. mvl value when in box)
+
+\def\docomplexdoblank[#1]% pas op \relax's zijn nodig ivm volgende \if
+ {\global\blankresetfalse
+ \global\blankdisablefalse
+ \global\blanknowhitefalse
+ \global\localblankflexiblefalse
+ \global\localblankfixedfalse
+ \global\blankforcefalse
+ \global\blankgobackfalse
+ \blankouterfalse
+ \global\blankskip\zeropoint
+%
+\edefconvertedargument\ascii{#1}% todo fast check for simple
+\ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+\else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
\else
+ \expanded{\rawprocesscommalist[#1]}\doblank
+\fi\fi
+%
+ \relax % to be sure
+ \ifdim\blankskip=\zeropoint\relax
+ \iflocalblankflexible
+ \doglobal\advance\blankskip \currentblank
+ \else\iflocalblankfixed
+ \doglobal\advance\blankskip \currentblank
+ \fi\fi
+ \fi
+ \relax % to be sure
+ \ifblankouter
+ % do nothing
+ \else
+ \par
+ \ifvmode
+ \ifblankgoback
+ \ifdim\lastskip>\zeropoint \vskip-\lastskip \fi
+ \savedlastskip\zeropoint
+ \else\ifdim\lastskip>\zeropoint
+ \savedlastskip\lastskip
+ \else % todo: lastnode, dan namelijk geen skip !
+ \savedlastskip\zeropoint
+ \fi\fi
+ \ifblankforce
+ % dit gaat mis in pos fonts
+ % \ifdim\prevdepth>\zeropoint\else ...
+ % -1000pt signals top of page or column (\ejectcolumn)
+ \bgroup\forgeteverypar\verticalstrut\egroup\kern-\struttotal
+ \savedlastskip\zeropoint
+ \fi
+ \savedlastpenalty\lastpenalty % hm, now it gets lost
+ \ifblankdisable
+ \global\blankindeedfalse % keep this, i.e. disable current too
+ \ifgridsnapping
+ \ifdim\prevdepth<\zeropoint
+ % brrr
+ \else
+ % dirty trick: smaller blanks are ignored after a
+ % larger one, so 10 lines is probably safe; we need
+ % to make sure that we honor penalties; here comes the
+ % trick (cross our fingers that this works well in
+ % multi columns; maybe an ifinner test is needed
+ % \scratchcounter\lastpenalty
+ % \vskip-10\lineheight
+ % \ifnum\scratchcounter=\zerocount \else \penalty\lastpenalty \fi
+ % \vskip 10\lineheight
+ % alas, this leads to overfull pages, so we try this:
+ \inhibitgridblank
+ \fi
+ \else
+ \ifdim\prevdepth<\zeropoint
+ % brrr
+ \else
+ % ensure at least a proper prevdepth, this should be
+ % an option
+ \vskip-\prevdepth
+ \vskip\strutdepth
+ \prevdepth\strutdepth
+ \fi
+ % the old crappy piece of code
+ \edef\oldprevdepth{\the\prevdepth}%
+ \prevdepth\newprevdepth % == \inhibittextblank
+ \fi
+ \else
+ \global\blankindeedtrue
+ \fi
+ \ifblankreset
+ \global\blankindeedtrue
+ \ifgridsnapping
+ % let's play safe and not fool around with the depth, if
+ % only because it took a lot of effort to sort out the grid
+ % stuff in the first place
+ \else
+ \ifdim\prevdepth=\newprevdepth
+ \prevdepth\oldprevdepth
+ \fi
+ \fi
+ \fi
+ \ifblankindeed
+ \ifdim1\savedlastskip<1\blankskip\relax
+ % else when \blank[2*groot] + \blank[3*groot] with parskip
+ % equaling 1*groot, gives a groot=\parskip so adding a small
+ % value makes it distinguishable; can also be done at parskip
+ % setting time (better)
+ \global\advance\blankskip \mindimen\relax % = skip
+ % test this on 2* + 3* and parskip groot
+ \ifblanknowhite
+ \global\advance\blankskip -\parskip
+ \else
+ \ifdim\savedlastskip=\parskip
+ \else % force this due to previous comment
+ \ifdim\parskip>\zeropoint\relax
+ \ifdim\blankskip<\parskip\relax
+ \global\blankskip\zeropoint
+ \else
+ \global\advance\blankskip -\parskip
+ \fi
+ \fi
+ \fi
+ \fi
+ \ifblankflexible \else
+ \blankskip1\blankskip
+ \fi
+ \iflocalblankfixed
+ \blankskip1\blankskip
+ \fi
+ \iflocalblankflexible
+ \blankskip1\blankskip
+ \!!plus \skipgluefactor\blankskip
+ \!!minus\skipgluefactor\blankskip
+ \fi
+ \ifdim\lastkern=\noblanksignal\relax % controlled and grid
+ \global\blankindeedfalse
+ \else\ifnum\savedlastpenalty=\noblankpsignal\relax % controlled and grid
+ \global\blankindeedfalse
+ \else\ifgridsnapping\else\ifdim\prevdepth=\newprevdepth
+ \global\blankindeedfalse
+ \fi\fi\fi\fi
+ \ifblankindeed
+ \iffuzzyvskip
+ \removelastfuzzyvskip
+ \fuzzyvskip\blankskip\relax
+ \else
+ \relax\ifdim\savedlastskip=\zeropoint\else
+ \vskip-\savedlastskip
+ \fi
+ \vskip\blankskip\relax
+ \fi
+ \fi
+ \else
+ \iffuzzyvskip
+ \removelastfuzzyvskip
+ \fuzzyvskip\blankskip\relax
+ \else
+ % new, test this on pascal
+ \ifdim\blankskip<\zeropoint
+ \relax\ifdim\savedlastskip=\zeropoint\else
+ \advance\blankskip-\savedlastskip
+ \vskip-\savedlastskip
+ \fi
+ \ifdim\blankskip>\zeropoint
+ \vskip\blankskip
+ \else
+ \vskip\zeropoint
+ \fi
+ \else
+ % also new
+ \ifdim\blankskip=\zeropoint
+ \ifblanknowhite
+ \nowhitespace
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \global\fuzzyvskipfalse
+ \presetindentation}
+
+%D For a long time we had:
+%D
+%D \starttyping
+%D \def\simpledoblank%
+%D {\doifelse{\currentwhitespace}{\v!geen}
+%D {\blank[\currentblank]}
+%D {\blank[\currentwhitespace]}}
+%D \stoptyping
+%D
+%D But Berend de Boer wanted more control, so now we have:
+
+\def\simpledoblank % ...
+ {\doifelse\currentwhitespace\v!none
+ {\blank[\currentblank]}
+ {\blank[\s!default]}}
+
+%D Another useful definition would be:
+%D
+%D \starttyping
+%D \defineblank
+%D [\s!default]
+%D [\v!groot]
+%D \stoptyping
+
+\def\dosetupblank#1% amount are an plain inheritance
+ {\bigskipamount#1\relax
+ \ifblankflexible \else
+ \bigskipamount1\bigskipamount
+ \fi
+ \medskipamount \bigskipamount \divide\medskipamount \plustwo
+ \smallskipamount\bigskipamount \divide\smallskipamount\plusfour}%
+
+\def\complexsetupblank[#1]% more \let's -> this also wil become installable
+ {\ifgridsnapping
+ \blankflexiblefalse
+ \else
+ \ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!flexible=>\blankflexibletrue,
+ \v!fixed=>\blankflexiblefalse]%
+ \fi
+ \ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!flexible=>\dosetupblank\appliedblankskip,
+ \v!fixed=>\dosetupblank\appliedblankskip,
+ \v!line=>\edef\appliedblankskip{\linedistance}%
+ \dosetupblank\appliedblankskip,
+ \v!halfline=>\scratchskip.5\linedistance
+ \edef\appliedblankskip{\the\scratchskip}%
+ \dosetupblank\appliedblankskip,
+ \v!big=>\ifgridsnapping
+ \edef\appliedblankskip{\linedistance}%
+ \dosetupblank\appliedblankskip
+ \fi
+ \let\currentblank\v!big,
+ \v!medium=>\let\currentblank\v!medium,
+ \v!small=>\let\currentblank\v!small,
+ \v!global=>\let\currentblank\v!global,
+ \v!normal=>\dosetupblank\appliedblankskip,
+ \v!standard=>\edef\appliedblankskip{\skipfactor\linedistance}%
+ \dosetupblank\appliedblankskip,
+ \s!default=>\dosetupblank\appliedblankskip,
+ \s!unknown=>\let\appliedblankskip\commalistelement
+ \dosetupblank\appliedblankskip]%
+ \simplesetupwhitespace}
+
+% \definecomplexorsimpleempty\setupblank
+%
+% speed gain: 60 sec -> 30 sec
+
+\definecomplexorsimple\setupblank
+
+\def\simplesetupblank % == snelle \setupblank[\s!default]
+ {\ifgridsnapping
+ \blankflexiblefalse
+ \fi
+ \dosetupblank\appliedblankskip
+ % \let\deblanko\v!big
+ \simplesetupwhitespace}
+
+\def\restorestandardblank% \v!standard
+ {\edef\appliedblankskip{\skipfactor\linedistance}%
+ \dosetupblank\appliedblankskip
+ }%\let\deblanko\v!big}
+
+\def\dodefineblank[#1][#2]%
+ {\def\docommand##1{\setvalue{\??bo##1}{#2}}%
+ \processcommalist[#1]\docommand}
+
+\def\defineblank
+ {\dodoubleargument\dodefineblank}
+
+\def\savecurrentblank
+ {\edef\restorecurrentblank
+ {\bigskipamount\the\bigskipamount
+ \medskipamount\the\medskipamount
+ \smallskipamount\the\smallskipamount
+ \noexpand\def\noexpand\currentblank{\currentblank}%
+ \ifblankflexible
+ \noexpand\blankflexibletrue
+ \else
+ \noexpand\blankflexiblefalse
+ \fi}}
+
+%D Now.
+
+\defineblank [\s!default] [\v!white]
+\defineblank [\v!height] [\strutheight]
+\defineblank [\v!depth] [\strutdepth]
+
+% old implementation
+%
+% \let\currentindentation=\empty
+%
+% \newdimen\ctxparindent
+%
+% \newif\ifindentfirstparagraph % \indentfirstparagraphtrue
+%
+% \def\presetindentation
+% {\doifoutervmode{\ifindentfirstparagraph\else\noindentation\fi}}
+%
+% \definecomplexorsimple\setupindenting
+%
+% \def\complexsetupindenting[#1]%
+% {\processallactionsinset
+% [#1]
+% [ \v!first=>\indentfirstparagraphtrue,
+% \v!next=>\indentfirstparagraphfalse,
+% \s!default=>\simplesetupindenting,
+% \s!unknown=>\edef\currentindentation{\commalistelement}%
+% \simplesetupindenting]}
+%
+% \def\simplesetupindenting
+% {\assigndimension\currentindentation\ctxparindent{1em}{1.5em}{2em}%
+% \parindent\ctxparindent\relax}
+%
+% \def\indenting % watch out: \dodo and no \do
+% {\dosingleargument\dodoindenting}
+%
+% \def\dodoindenting[#1]% oeps, we needed a commalist handler here!
+% {\edef\currentindenting{#1}%
+% \processcommacommand[#1]\dododoindenting}
+%
+% \def\dododoindenting#1%
+% {\executeifdefined{\??in:#1}\donothing}
+%
+% \let\currentindenting\empty
+%
+% \def\defineindentingmethod[#1]#2%
+% {\setvalue{\??in:#1}{#2}}
+%
+% \defineindentingmethod [\v!no] {\parindent\ctxparindent\noindent}
+% \defineindentingmethod [\v!not] {\parindent\ctxparindent\noindent}
+%
+% \defineindentingmethod [\v!first] {\indentfirstparagraphtrue}
+% \defineindentingmethod [\v!next] {\indentfirstparagraphfalse}
+%
+% \defineindentingmethod [\v!yes] {\parindent\ctxparindent\relax} % no \indent !
+% \defineindentingmethod [\v!always] {\parindent\ctxparindent\relax} % no \indent !
+%
+% \defineindentingmethod [\v!never] {\parindent\zeropoint\relax} % no \indent !
+%
+% \def\noindenting{\indenting[\v!no,\v!next]} % was \nietinspringen
+% \def\doindenting{\indenting[\v!yes,\v!first]} % was \welinspringen
+%
+% \def\dochecknextindentation#1% internal one
+% {\checknextindentation[\getvalue{#1\c!indentnext}]}
+%
+% \def\checknextindentation[#1]%
+% {\processaction[#1][%\v!keep=>,
+% \v!yes=>\doindentation,
+% \v!no=>\noindentation,
+% \v!auto=>\autoindentation]}
+%
+% \def\doindentation% too simple
+% {\gdef\checkindentation{\global\indentationtrue}}
+%
+% \ifx\autoindentation\undefined
+% \let\autoindentation\relax
+% \fi
+%
+% \newif\ifindentation \indentationtrue % documenteren, naar buiten
+%
+% \let\checkindentation=\relax
+%
+% \def\donoindentation
+% {\ifdim\parindent=\zeropoint \else
+% \bgroup \setbox\scratchbox\lastbox \egroup
+% \fi}
+%
+% \def\noindentation % made global
+% {\ifinpagebody \else
+% \global\indentationfalse
+% \gdef\checkindentation
+% {\donoindentation
+% \gdef\checkindentation{\global\indentationtrue}}%
+% \fi}
+%
+% \def\nonoindentation % bv bij floats
+% {\ifinpagebody \else
+% \global\indentationtrue
+% \gdef\checkindentation{\global\indentationtrue}%
+% \fi}
+%
+% \def\indentation
+% {\ifvmode \ifdim\parindent=\zeropoint \else
+% % was : \hskip\parindent
+% % can be: \indent
+% % but we test:
+% \noindent\hskip\parindent
+% \fi \fi}
+
+\let\currentindentation\empty % amount/keyword
+% \let\normalindentation \empty % used for reinstating normal indentation
+\let\currentindenting \empty % method
+
+\newdimen\ctxparindent
+
+\newif\ifindentfirstparagraph % \indentfirstparagraphtrue
+
+\chardef\indentingtoggle\zerocount
+
+%D After a blank or comparable situation (left side floats) we
+%D need to check if the next paragraph has to be indented.
+
+\def\presetindentation
+ {\doifoutervmode{\ifindentfirstparagraph\else\noindentation\fi}}
+
+%D This sets up the (normally) global indentation behavior as well
+%D as the amounts.
+
+\definecomplexorsimple\setupindenting
+
+% \def\complexsetupindenting[#1]%
+% {\edef\currentindenting{#1}%
+% \indentfirstparagraphtrue
+% \parindent\ctxparindent
+% \chardef\indentingtoggle\zerocount
+% \processcommalist[#1]\docomplexsetupindenting
+% \ifindentfirstparagraph\else\noindentation\fi % added
+% \toggleindentation}
+
+\indentfirstparagraphtrue
+\parindent\ctxparindent
+\chardef\indentingtoggle\zerocount
+
+% \newtoks\savedeverypar \savedeverypar\everypar
+% \def\restoreeverypar{\everypar\savedeverypar}
+
+% we need a better everypar model: for each option a switch, which we
+% set to false with \forgetall and can enable when needed (context 4);
+% that way we can control the order of execution of options
+
+\def\checkeverypar % currently a hack
+ {\ifzeropt\parindent\else
+ \doifsometokselse\everypar\donothing{\appendtoks\checkindentation\to\everypar}%
+ \fi}
+
+\def\complexsetupindenting[#1]%
+ {\edef\currentindenting{#1}%
+ \doifsomething\currentindenting % handy when a parameter is passed
+ {% not here: \indentfirstparagraphtrue
+ % not here: \parindent\ctxparindent
+ % not here: \chardef\indentingtoggle\zerocount
+ % we use commacommand in order to catch #1 being a command (expanded parameter)
+ \processcommacommand[\currentindenting]\docomplexsetupindentingA % catch small, medium, etc
+ \processcommacommand[\currentindenting]\docomplexsetupindentingB % catch rest
+ \checkeverypar % only when non-empty #1
+ \ifindentfirstparagraph\else\noindentation\fi % added
+ \toggleindentation}}
+
+\def\docomplexsetupindentingA#1%
+ {\edefconvertedargument\!!stringa{#1}%
+ \doifundefined{\??in:\!!stringa}%
+ {\edef\currentindentation{#1}%
+ \let\normalindentation\currentindentation
+ \simplesetupindenting}}
+
+\def\docomplexsetupindentingB#1%
+ {\edefconvertedargument\!!stringa{#1}% catch #1=\somedimen
+ \executeifdefined{\??in:\!!stringa}\donothing}
+
+\def\simplesetupindenting % empty case, a it strange, needed this way?
+ {\assigndimension\currentindentation\ctxparindent{1em}{1.5em}{2em}}
+
+\def\indenting % kind of obsolete
+ {\dosingleargument\complexsetupindenting}
+
+% use \noindentation to suppress next indentation
+
+\def\defineindentingmethod[#1]#2%
+ {\setvalue{\??in:#1}{#2}}
+
+\defineindentingmethod [\v!no] {\parindent\zeropoint}% was: \ctxparindent\noindent}
+\defineindentingmethod [\v!not] {\parindent\zeropoint}% was: \ctxparindent\noindent}
+
+\defineindentingmethod [\v!first] {\indentfirstparagraphtrue}
+\defineindentingmethod [\v!next] {\indentfirstparagraphfalse}
+
+\defineindentingmethod [\v!yes] {\parindent\ctxparindent\relax} % no \indent !
+\defineindentingmethod [\v!always] {\parindent\ctxparindent\relax} % no \indent !
+
+\defineindentingmethod [\v!never] {\parindent\zeropoint\relax % no \indent !
+ \chardef\indentingtoggle\zerocount}
+
+\defineindentingmethod [\v!odd] {\chardef\indentingtoggle\plusone}
+\defineindentingmethod [\v!even] {\chardef\indentingtoggle\plustwo}
+
+\defineindentingmethod [\v!normal] {\ifx\normalindentation\empty\else
+ \let\currentindentation\normalindentation
+ \simplesetupindenting
+ \fi}
+
+\defineindentingmethod [\v!reset] {\indentfirstparagraphtrue
+ \parindent\zeropoint
+ \chardef\indentingtoggle\zerocount}
+
+\def\noindenting{\indenting[\v!no, \v!next ]}
+\def\doindenting{\indenting[\v!yes,\v!first]}
+
+%D This one sets up the local indentation behaviour (i.e. either or not
+%D a next paragraph will be indented).
+
+\def\dochecknextindentation#1% internal one
+ {\checknextindentation[\getvalue{#1\c!indentnext}]}
+
+\def\checknextindentation[#1]%
+ {\processaction
+ [#1]
+ [%\v!keep=>,
+ \v!yes=>\doindentation,
+ \v!no=>\noindentation,
+ \v!auto=>\autoindentation]}
+
+%D Here come the handlers.
+
+\newif\ifindentation \indentationtrue % documenteren, naar buiten
+
+\let\checkindentation\relax
+
+\ifx\autoindentation\undefined \let\autoindentation\relax \fi % hook
+
+\def\doindentation
+ {\gdef\checkindentation{\global\indentationtrue}}
+
+\def\noindentation % made global
+ {\ifinpagebody \else
+ \global\indentationfalse
+ \gdef\checkindentation
+ {\donoindentation
+ \gdef\checkindentation{\global\indentationtrue}}%
+ \fi}
+
+\def\nonoindentation % bv bij floats
+ {\ifinpagebody \else
+ \global\indentationtrue
+ \gdef\checkindentation{\global\indentationtrue}%
+ \fi}
+
+\def\donoindentation
+ {\ifdim\parindent=\zeropoint \else
+ \bgroup \setbox\scratchbox\lastbox \egroup
+ \fi}
+
+\def\indentation
+ {\ifvmode \ifdim\parindent=\zeropoint \else
+ % was : \hskip\parindent
+ % can be: \indent
+ % but we test:
+ \noindent\hskip\parindent
+ \fi \fi}
+
+\def\toggleindentation
+ {\ifcase\indentingtoggle
+ % nothing
+ \or
+ \notoggleindentation
+ \or
+ \dotoggleindentation
+ \fi}
+
+\def\dokillindentation
+ {\gdef\checkindentation{\global\indentationfalse\donoindentation}}
- \def\mksetupgridsnapping
- {\pdfeachlineheight \openstrutheight
- \pdfeachlinedepth \openstrutdepth
- \pdffirstlineheight \pdfeachlineheight
- \pdflastlinedepth \pdfeachlinedepth}
+\def\dotoggleindentation
+ {\gdef\checkindentation{\global\indentationfalse\notoggleindentation\donoindentation}}
- \def\mkenablegridsnapping
- {\pdfkeeplinedimen\maxdimen
- \topskip\strutht
- \offinterlineskip}
+\def\notoggleindentation
+ {\gdef\checkindentation{\global\indentationtrue\dotoggleindentation}}
- \def\mkdisablegridsnapping
- {\pdfkeeplinedimen\zeropoint
- % reset topskip
- \oninterlineskip}
+\appendtoks
+ \pushmacro\checkindentation
+ \pushmacro\ifindentation
+\to \everypushsomestate
+
+\appendtoks
+ \popmacro\ifindentation
+ \popmacro\checkindentation
+\to \everypopsomestate
+
+% we need to save the state if we want to adapt behaviour to empty lines
+%
+% \def\setlasthvmode
+% {\global\chardef\savedhvmode\ifhmode\plusone\else\ifvmode\plustwo\else\zerocount\fi\fi}
+%
+% \def\resetlasthvmode
+% {\global\chardef\savedhvmode\zerocount}
+%
+% \chardef\savedhvmode\zerocount
+
+% This is a user requested hack (using the auto-hook).
+
+\chardef\recheckindentationmode\zerocount
+
+\def\dontrechecknextindentation
+ {\global\chardef\recheckindentationmode\zerocount}
+
+\def\dorechecknextindentation
+ {\ifcase\recheckindentationmode
+ % nothing
+ \or
+ \dontrechecknextindentation
+ \expandafter\doautoindentation
+ \fi}
+
+\def\doautoindentation
+ {\doifnextcharelse\par\donothing\noindentation}
+
+\def\autoindentation
+ {\global\chardef\recheckindentationmode\plusone}
+
+%D An example of usage:
+%D
+%D \starttyping
+%D \setupindenting[small,yes]
+%D
+%D \setupitemize [indentnext=auto]
+%D \setuptyping [indentnext=auto]
+%D \setupformulas[indentnext=auto]
+%D
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D
+%D \page
+%D
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D
+%D \page
+%D
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+%D
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+
+
+%D \macros
+%D {frenchspacing,nonfrenchspacing}
+%D
+%D Smehow \type{\frenchspacing} can lead to hyphenation between
+%D dashes so we now have \type {\newfrenchspacing} (moved from
+%D \type {syst-chr}).
+
+%D Hm ... todo:
+
+\sfcode`\)=0
+\sfcode`\'=0
+\sfcode`\]=0
+
+\def\setfrenchspacing#1%
+ {\sfcode`\.#1 \sfcode`\,#1\relax
+ \sfcode`\?#1 \sfcode`\!#1\relax
+ \sfcode`\:#1 \sfcode`\;#1\relax}
+
+\def\frenchspacing
+ {\setfrenchspacing{1000}}
+
+\def\resetfrenchspacing
+ {\sfcode`\.3000 \sfcode`\,1250
+ \sfcode`\?3000 \sfcode`\!3000
+ \sfcode`\:2000 \sfcode`\;1500 }
+
+\def\frenchspacing {\setfrenchspacing{1000}}
+\def\newfrenchspacing{\setfrenchspacing{1050}}
+\def\nonfrenchspacing{\resetfrenchspacing}
+
+\def\definespacingmethod[#1]#2{\setvalue{\??sg\??sg#1}{#2}}
+
+\definespacingmethod[\v!packed]{\newfrenchspacing}
+\definespacingmethod[\v!broad ]{\nonfrenchspacing}
+
+\def\complexsetupspacing[#1]%
+ {\executeifdefined{\??sg\??sg#1}\relax
+ \updateraggedskips}
+
+\def\simplesetupspacing
+ {\updateraggedskips}
+
+\definecomplexorsimple\setupspacing
+
+% \dorecurse{100}{\recurselevel\spacefactor 800 \space} \par
+% \dorecurse{100}{\recurselevel\spacefactor1200 \space} \par
+% \dorecurse{100}{\recurselevel\spacefactor 800 \normalspaceprimitive} \par
+% \dorecurse{100}{\recurselevel\spacefactor1200 \normalspaceprimitive} \par
+
+% When we don't add the % here, we effectively get \ and
+% since we have by default \def\^^M{\ } we get into a loop.
+
+\let\normalspaceprimitive=\ % space-comment is really needed
+
+\unexpanded\def\ {\mathortext\normalspaceprimitive\space} % no \dontleavehmode\space (else no frenchspacing)
+
+\unexpanded\def\nonbreakablespace{\penalty\plustenthousand\space}
+
+\letcatcodecommand \ctxcatcodes `\~ \nonbreakablespace % overloaded later
+
+\def\space { }
+\def\removelastspace{\ifhmode\unskip\fi}
+\def\nospace {\removelastspace\ignorespaces}
+
+% in tables we need:
+%
+% \def\fixedspace {\hskip.5em\relax}
+%
+% but, since not all fonts have .5em digits:
+
+\unexpanded\def\fixedspace
+ {\setbox\scratchbox\normalhbox{\mathortext{0}{0}}%
+ \hskip\wd\scratchbox\relax}
+
+\def\fixedspaces
+ {\letcatcodecommand \ctxcatcodes `\~ \fixedspace}
+
+\def\removeunwantedspaces
+ {\ifhmode % we also need to unskip 0pt skips
+ \unskip\unskip\unskip\unskip\unskip
+ \unskip\unskip\unskip\unskip\unskip
+ \fi}
+
+\appendtoks\let~\space\to\simplifiedcommands
+
+% still not fixed in aleph / luatex
+%
+% \def\removeunwantedspaces
+% {\ifhmode \ifnum\lastnodetype=\@@gluenode
+% \unskip \@EAEAEA\removeunwantedspaces
+% \fi \fi}
+
+%D For old time sake, will disappear soon.
+
+\let\hardespatie\fixedspace
+\let\geenspatie \nospace
+
+% \startbuffer
+% \startlines \tt \fixedspaces
+% 0~1~~2~~~3~~~~4~~~~~5
+% 0~~~~~~~~~~~~~~~~~~~5
+% $0~1~~2~~~3~~~~4~~~~~5$
+% $0~~~~~~~~~~~~~~~~~~~5$
+% \stoplines
+%
+% \starttabulate[|~|]
+% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \NR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \NR
+% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \NR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \NR
+% \stoptabulate
+%
+% \starttable[||]
+% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \AR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \AR
+% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \AR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \AR
+% \stoptable
+% \stopbuffer
+%
+% \setupbodyfont[cmr] \getbuffer
+% \setupbodyfont[lbr] \getbuffer
+
+\def\packed
+ {\nointerlineskip}
+
+\def\godown[#1]%
+ {\relax
+ \ifhmode\endgraf\fi
+ \ifvmode\nointerlineskip\vskip#1\relax\fi}
+
+%D A couple of plain macros:
+
+\ifx\thinspace\undefined
+
+ \def\thinspace {\kern .16667em }
+ \def\negthinspace{\kern-.16667em }
+ \def\enspace {\kern .5em }
+
+ \def\thinspace {\kern .16667\emwidth}
+ \def\negthinspace{\kern-.16667\emwidth}
+ \def\enspace {\kern .5\emwidth}
+
+\fi
+
+\ifx\quad\undefined
+
+ \def\enskip{\hskip.5em\relax}
+ \def\quad {\hskip 1em\relax}
+ \def\qquad {\hskip 2em\relax}
+
+ \def\enskip{\hskip.5\emwidth}
+ \def\quad {\hskip \emwidth}
+ \def\qquad {\hskip 2\emwidth}
+
+\fi
+
+\let\emspace\quad
+
+\ifx\smallskip\undefined
+
+ \def\smallskip{\vskip\smallskipamount}
+ \def\medskip {\vskip\medskipamount}
+ \def\bigskip {\vskip\bigskipamount}
+
+\fi
+
+\ifx\allowbreak\undefined
+
+ \def\break {\penalty\ifhmode-\plustenthousand\else\ejectpenalty\fi}
+ \def\nobreak {\penalty \plustenthousand}
+ \def\allowbreak{\penalty \zeropoint}
+ \def\filbreak {\par\vfil\penalty-200\vfilneg}
+ \def\goodbreak {\par\penalty-500 }
+
+\fi
+
+%D Made slightly more readable:
+
+\ifx\vglue\undefined
+
+ \def\vglue {\afterassignment\dovglue\scratchskip=}
+ \def\hglue {\afterassignment\dohglue\scratchskip=}
+ \def\topglue{\nointerlineskip\vglue-\topskip\vglue}
+
+ \def\dovglue
+ {\par
+ \scratchdimen\prevdepth
+ \hrule\!!height\zeropoint
+ \nobreak\vskip\scratchskip
+ \prevdepth\scratchdimen}
+
+ \def\dohglue
+ {\dontleavehmode % \leavevmode
+ \scratchcounter\spacefactor
+ \vrule\!!width\zeropoint
+ \nobreak\hskip\scratchskip
+ \spacefactor\scratchcounter}
+
+\fi
+
+\ifx\eject\undefined
+
+ \def\eject{\par\break}
+
+\fi
+
+\ifx\supereject\undefined
+
+ \def\supereject{\par\penalty\superpenalty}
+
+\fi
+
+\ifx\dosupereject\undefined
+
+ \def\dosupereject
+ {\ifnum\insertpenalties>\zerocount % something is being held over
+ \line{}
+ \kern-\topskip
+ \nobreak
+ \vfill\supereject
+ \fi}
+
+\fi
+
+%D We adapt plain's \type {\removelastskip} a bit:
+
+\ifx\removelastskip\undefined
+
+ \def\removelastskip
+ {\ifvmode \ifdim\lastskip=\zeropoint \else
+ \vskip-\lastskip
+ \fi \fi}
+
+\fi
+
+\ifx\smallbreak\undefined
+
+\def\smallbreak
+ {\par
+ \ifdim\lastskip<\smallskipamount
+ \removelastskip
+ \penalty-50
+ \smallskip
+ \fi}
+
+\def\medbreak
+ {\par
+ \ifdim\lastskip<\medskipamount
+ \removelastskip
+ \penalty-100
+ \medskip
+ \fi}
+
+\def\bigbreak
+ {\par
+ \ifdim\lastskip<\bigskipamount
+ \removelastskip
+ \penalty-200
+ \bigskip
+ \fi}
\fi
+
+\newskip\ctxparskip \ctxparskip\zeropoint
+
+\newconditional \flexiblewhitespace \settrue\flexiblewhitespace
+
+\def\blankokleinmaat {\smallskipamount}
+\def\blankomiddelmaat {\medskipamount}
+\def\blankogrootmaat {\bigskipamount}
+\def\currentwhitespace {\zeropoint}
+
+\definecomplexorsimple\setupwhitespace
+
+% \def\simplesetupwhitespace
+% {\doifnot\currentwhitespace\v!none\dosetupwhitespace}
+%
+% \def\complexsetupwhitespace[#1]%
+% {\doifelsenothing{#1}
+% {\simplesetupwhitespace}
+% {\edef\currentwhitespace{#1}%
+% \dosetupwhitespace}}
+%
+% \def\dosetupwhitespace
+% {\processcommacommand[\currentwhitespace]\dowhitespacemethod
+% \dodosetupwhitespace}
+
+\def\simplesetupwhitespace
+ {\doifnot\currentwhitespace\v!none\dosetupwhitespace}
+
+\def\complexsetupwhitespace[#1]%
+ {\edef\nextcurrentwhitespace{#1}%
+ \ifx\nextcurrentwhitespace\empty
+ \simplesetupwhitespace
+ \else
+ \let\currentwhitespace\nextcurrentwhitespace
+ \dosetupwhitespace
+ \fi}
+
+\def\dosetupwhitespace % quick test for no list
+ {\ifcsname\??ws\??ws\currentwhitespace\endcsname
+ \csname\??ws\??ws\currentwhitespace\endcsname
+ \else
+ \expandafter\processcommalist\expandafter[\currentwhitespace]\dowhitespacemethod % can be raw
+ \fi\relax
+ \ifgridsnapping
+ \setfalse\flexiblewhitespace
+ \ifdim\ctxparskip>\zeropoint
+ \ctxparskip
+ \ifcase\baselinegridmode
+ \baselineskip % normal ! ! ! ! !!
+ \or
+ \ifdim\scratchdimen=\baselineskip % maybe range
+ \baselineskip % normal ! ! ! ! !!
+ \else
+ \numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
+ \fi
+ \else
+ \baselineskip % normal ! ! ! ! !!
+ \fi
+ \fi
+ \else
+ \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
+ \fi
+ \parskip\ctxparskip}
+
+\chardef\baselinegridmode=0 % option in layout / 1=permit_half_lines
+
+\def\dodosetupwhitespace
+ {\ifgridsnapping
+ \setfalse\flexiblewhitespace
+ \ctxparskip1\ctxparskip
+ \ifdim\ctxparskip>\zeropoint
+ \ifcase\baselinegridmode
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \or
+ \ifdim\scratchdimen=\baselineskip % maybe range
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \else
+ \ctxparskip\numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
+ \fi
+ \else
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \fi
+ \fi
+ \else
+ \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
+ \fi
+ \parskip\ctxparskip}
+
+\definesystemvariable {ws} % whitespace
+
+\def\definewhitespacemethod[#1]#2{\setvalue{\??ws\??ws#1}{#2}}
+
+\definewhitespacemethod [\v!fix] {}
+\definewhitespacemethod [\v!fixed] {\setfalse\flexiblewhitespace}
+\definewhitespacemethod [\v!flexible] {\settrue\flexiblewhitespace}
+\definewhitespacemethod [\v!line] {\ctxparskip \baselineskip}
+\definewhitespacemethod [\v!halfline] {\ctxparskip.5\baselineskip}
+\definewhitespacemethod [\v!none] {\ctxparskip \zeropoint}
+\definewhitespacemethod [\v!big] {\ctxparskip \bigskipamount}
+\definewhitespacemethod [\v!medium] {\ctxparskip \medskipamount}
+\definewhitespacemethod [\v!small] {\ctxparskip \smallskipamount}
+
+\definewhitespacemethod [\s!default] {\simplesetupwhitespace} % {\stelwitruimteopnieuwin}
+
+% \def\dowhitespacemethod#1%
+% {\executeifdefined{\??ws\??ws#1}{\ctxparskip#1}\relax}
+
+\def\dowhitespacemethod#1%
+ {\ifcsname\??ws\??ws#1\endcsname\csname\??ws\??ws#1\endcsname\else\ctxparskip#1\fi\relax}
+
+\def\nowhitespace
+ {\ifdim\parskip>\zeropoint\relax
+ \ifdim\lastskip=-\parskip
+ \else
+ \vskip-\parskip
+ \fi
+ \fi}
+
+\def\nowhitespaceunlessskip
+ {\ifdim\lastskip>\zeropoint \else
+ \nowhitespace
+ \fi}
+
+\def\redowhitespace
+ {\ifdim\lastskip>-\parskip \else
+ \vskip\parskip
+ \fi}
+
+\def\savecurrentwhitespace
+ {\edef\restorecurrentwhitespace
+ {\ctxparskip\the\ctxparskip
+ \parskip\the\parskip
+ \noexpand\def\noexpand\currentwhitespace{\currentwhitespace}%
+ \ifconditional\flexiblewhitespace
+ \noexpand\settrue\flexiblewhitespace
+ \else
+ \noexpand\setfalse\flexiblewhitespace
+ \fi}}
+
+% deze variant is nodig binnen \startopelkaar
+% steeds testen:
+%
+% \hoofdstuk{..}
+% \plaatslijst[..]
+% \hoofdstuk{..}
+% \input tufte
+%
+% met/zonder witruimte
+
+\def\whitespace
+ {\par
+ \ifdim\parskip>\zeropoint\relax
+ %\ifdim\lastskip>\parskip \else
+ % \removelastskip interferes with blanko blokkeer en klein
+ \vskip\parskip
+ %\fi
+ \fi}
+
+\def\nonoblanko[#1]%
+ {\par}
+
+\def\noblanko
+ {\dosingleempty\nonoblanko}
+
+% De onderstaande macro handelt ook de situatie dat er geen
+% tekst tussen \start ... \stop is geplaatst. Daartoe wordt de
+% laatste skip over de lege tekst heen gehaald. Dit komt goed
+% van pas bij het plaatsen van (mogelijk lege) lijsten.
+
+\newif\ifopelkaar
+
+\newsignal \noparskipsignal % \def\noparskipsignal {0.00001pt}
+\def\lastdoneparskip {0pt}
+
+\def\startpacked
+ {\dosingleempty\dostartpacked}
+
+\def\dostartpacked[#1]% nesting afvangen
+ {\par
+ \ifvmode
+ \edef\lastdoneparskip {\the\lastskip}%
+ \edef\lastdoneprevdepth{\the\prevdepth}% zeer recent toegevoegd
+ \ifdim\prevdepth=-\thousandpoint % toegevoegd omdat binnen
+ \else % een vbox een extra skip
+ \whitespace % ongewenst is; dit kan
+ \baselinecorrection %% zie in \placeregister[n=1]
+ \vskip\noparskipsignal % waarschijnlijk ook in
+ \fi % blanko blokkeer
+ \bgroup
+ \doifelse{#1}\v!blank
+ \opelkaarfalse
+ \opelkaartrue
+ \blank[\v!disable] % dit is nog niet ok, gaat fout
+ \setupwhitespace[\v!none] % bovenin vtop (dwz, baseline)
+ \fi}
+
+\def\stoppacked
+ {\par
+ \ifvmode
+ \egroup
+ \ifdim\lastskip=\noparskipsignal\relax
+ \removelastskip
+ \nowhitespace
+ \vskip-\lastdoneparskip
+ \vskip+\lastdoneparskip
+ \prevdepth-\lastdoneprevdepth % zeer recent toegevoegd
+ \fi
+ \fi}
+
+\def\startunpacked
+ {\blank
+ \leavevmode
+ \bgroup}
+
+\def\stopunpacked
+ {\egroup
+ \blank}
+
+% De onderstaande macro's moeten nog eens nader worden uitgewerkt.
+% Ze spelen een rol bij de spatiering rond omkaderde teksten
+% en/of boxen zonder diepte.
+
+\def\toonregelcorrectie{\showbaselinecorrection}
+\def\regelcorrectie {\baselinecorrection}
+
+% \prevdepth crosses pageboundaries!
+%
+% todo: a version that works ok inside a box
+
+\let\doaroundlinecorrection\relax
+
+\def\startlinecorrection
+ {\dodoubleempty\dostartlinecorrection}
+
+\def\dostartlinecorrection[#1][#2]% #2 gobbles spaces
+ {\bgroup
+ \processaction
+ [#1]
+ [ \v!blank=>\let\doaroundlinecorrection\blank,
+ \s!default=>\let\doaroundlinecorrection\relax,
+ \s!unknown=>{\def\doaroundlinecorrection{\blank[#1]}}]%
+ \doaroundlinecorrection
+ \startbaselinecorrection
+ \offbaselinecorrection
+ \ignorespaces}
+
+\def\stoplinecorrection
+ {\stopbaselinecorrection
+ \doaroundlinecorrection
+ \egroup}
+
+\def\correctwhitespace
+ {\dowithnextbox
+ {\startbaselinecorrection
+ \flushnextbox
+ \stopbaselinecorrection}%
+ \vbox}
+
+\def\verticalstrut {\normalvbox{\hsize\zeropoint\forgetall\strut}}
+\def\horizontalstrut{\normalhbox {\strut}}
+
+% Hieronder volgen enkele instellingen en macro's ten behoeve
+% van de interlinie en \strut. De waarden 2.8, 0.07, 0.72 en
+% 0.28 zijn ooit eens ontleend aan INRS-TEX en moeten wellicht
+% nog eens instelbaar worden.
+%
+% \lineheight : de hoogte van een regel
+% \spacing{getal} : instellen interlinie
+% \normalbaselines : instellen regelafstend
+%
+% \setstrut : instellen \strut
+% \setnostrut : resetten \strut, \endstrut, \begstrut
+%
+% \setteststrut : instellen zichtbare struts
+% \resetteststrut : instellen onzichtbare struts
+%
+% \setfontparameters : instellen na fontset
+%
+% De hoogte van een regel (\lineheight) is gelijk aan de
+% som van de hoogte (\ht) en diepte (\dp) van \strutbox.
+%
+% \strut : denkbeeldig blokje met hoogte en diepte
+%
+% Een \hbox kan als deze aan het begin van een regel staat
+% een breedte \hsize krijgen. Dit is soms te voorkomen met het
+% commando \leavevmode. Binnen een \vbox geeft dit echter
+% niet altijd het gewenste resultaat, vandaar het commando
+%
+% \leaveoutervmode
+
+% Pas op: niet zomaar \topskip en \baselineskip aanpassen
+% en zeker niet \widowpenalty. Dit kan ernstige gevolgen
+% hebben voor kolommen.
+%
+% Enige glue kan op zich geen kwaad, echter als blanko=vast,
+% dan moet ook de rek 0 zijn. Binnen kolommen is rek ook
+% niet bepaald mooi. Een hele kleine waarde (0.025) voldoet,
+% omdat een positieve glue eindeloos rekbaar is.
+
+\newdimen\strutdimen
+\newdimen\lineheight
+\newdimen\openlineheight
+\newdimen\openstrutheight
+\newdimen\openstrutdepth
+\newdimen\topskipgap
+\newdimen\struttotal
+
+\def\strutheightfactor {.72}
+\def\strutdepthfactor {.28}
+
+\def\baselinefactor {2.8}
+\def\baselinegluefactor {0}
+
+\def\minimumstrutheight {0pt}
+\def\minimumstrutdepth {0pt}
+
+\def\normallineheight {\baselinefactor ex}
+\def\minimumlinedistance {\lineskip}
+
+\def\strutheight {0pt}
+\def\strutdepth {0pt}
+\def\strutwidth {0pt}
+
+\def\spacingfactor {1}
+
+\def\topskipfactor {1.0}
+\def\maxdepthfactor {0.5}
+
+\def\systemtopskipfactor {\topskipfactor}
+\def\systemmaxdepthfactor {\maxdepthfactor}
+
+% De onderstaande definitie wordt in de font-module overruled
+
+\ifdefined\globalbodyfontsize\else
+ \newdimen\globalbodyfontsize
+ \globalbodyfontsize=12pt
+\fi
+
+\ifx\normalizedbodyfontsize\undefined
+ \def\normalizedbodyfontsize{12pt}
+\fi
+
+% door een \dimen. Dit is geen probleem omdat (1) de default
+% korpsgrootte 12pt is en (2) de fonts nog niet geladen zijn
+% en de instellingen bij het laden nogmaals plaatsvinden.
+
+% \def\topskipcorrection
+% {\ifdim\topskip>\openstrutheight
+% % == \vskip\topskipgap
+% \vskip\topskip
+% \vskip-\openstrutheight
+% \fi
+% \verticalstrut
+% \vskip-\struttotal}
+
+\def\topskipcorrection
+ {\simpletopskipcorrection
+ \vskip-\struttotal
+ \verticalstrut}
+
+\def\simpletopskipcorrection
+ {\ifdim\topskip>\openstrutheight
+ % == \vskip\topskipgap
+ \vskip\topskip
+ \vskip-\openstrutheight
+ \fi}
+
+% \def\settopskip % the extra test is needed for the lbr family
+% {\topskip\systemtopskipfactor\globalbodyfontsize
+% \ifgridsnapping \else
+% \ifr@ggedbottom\!!plus5\globalbodyfontsize\fi
+% \fi
+% \relax % the skip
+% \topskipgap\topskip
+% \advance\topskipgap -\openstrutheight\relax
+% \ifdim\topskip<\strutheightfactor\openlineheight
+% \topskip\strutheightfactor\openlineheight\relax
+% \fi}
+
+\def\settopskip % the extra test is needed for the lbr family
+ {\topskip\systemtopskipfactor\globalbodyfontsize
+ \ifgridsnapping \else
+ \ifr@ggedbottom\!!plus5\globalbodyfontsize\fi
+ \fi
+ \relax % the skip
+ \topskipgap\topskip
+ \advance\topskipgap -\openstrutheight\relax
+\ifdim\minimumstrutheight>\zeropoint
+ \ifdim\topskip<\minimumstrutheight
+ \topskip\minimumstrutheight\relax
+ \fi
+\else
+ \ifdim\topskip<\strutheightfactor\openlineheight
+ \topskip\strutheightfactor\openlineheight\relax
+ \fi
+\fi}
+
+\def\setmaxdepth
+ {\maxdepth\systemmaxdepthfactor\globalbodyfontsize}
+
+\def\normalbaselines
+ {\baselineskip \normalbaselineskip
+ \lineskip \normallineskip
+ \lineskiplimit\normallineskiplimit}
+
+% \def\setnormalbaselines
+% {\ifdim\normallineheight>\zeropoint
+% \lineheight\normallineheight
+% \fi
+% \openlineheight\spacingfactor\lineheight
+% \openstrutheight\strutheightfactor\openlineheight
+% \openstrutdepth \strutdepthfactor \openlineheight
+% \normalbaselineskip\openlineheight
+% \!!plus\baselinegluefactor\openlineheight
+% \!!minus\baselinegluefactor\openlineheight
+% \normallineskip\minimumlinedistance\relax % \onepoint\relax
+% \normallineskiplimit\zeropoint\relax
+% \normalbaselines}
+
+\def\setnormalbaselines
+ {\ifdim\normallineheight>\zeropoint
+ \lineheight\normallineheight
+ \fi
+ \openlineheight\spacingfactor\lineheight
+ \openstrutheight \ifdim\minimumstrutheight>\zeropoint
+ \minimumstrutheight % new
+ \else
+ \strutheightfactor\openlineheight
+ \fi
+ \openstrutdepth \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth % new
+ \else
+ \strutdepthfactor \openlineheight
+ \fi
+ \ifdim\dimexpr\minimumstrutdepth+\minimumstrutheight\relax>\zeropoint
+ \openlineheight\dimexpr\openstrutheight+\openstrutdepth\relax % new
+ \fi
+ \normalbaselineskip\openlineheight
+ \ifgridsnapping\else
+ \!!plus \baselinegluefactor\openlineheight
+ \!!minus\baselinegluefactor\openlineheight
+ \fi
+ \normallineskip\minimumlinedistance\relax % \onepoint\relax
+ \normallineskiplimit\zeropoint\relax
+ \normalbaselines}
+
+% \def\setspacingfactor#1\to#2\by#3\\%
+% {\strutdimen#2\points
+% \strutdimen#3\strutdimen
+% \edef#1{\withoutpt\the\strutdimen}}
+%
+% \def\spacing#1%
+% {\ifgridsnapping
+% %\doifnot{#1}{1}{\showmessage\m!layouts{11}{#1}}%
+% \ifdim#1\points=\onepoint\else\showmessage\m!layouts{11}{#1}\fi
+% \edef\spacingfactor{1}%
+% \else
+% \edef\spacingfactor{#1}%
+% \fi
+% \setspacingfactor\systemtopskipfactor \to\topskipfactor \by#1\\% why no \spacingfactor ?
+% \setspacingfactor\systemmaxdepthfactor\to\maxdepthfactor\by#1\\% why no \spacingfactor ?
+% \setnormalbaselines
+% \setstrut}
+%
+% \def\setspacingfactor#1#2#3%
+% {\edef#1{\withoutpt\the\dimexpr#2\points*#3\relax}}
+
+\def\spacing#1%
+ {\ifgridsnapping
+ \ifdim#1\points=\onepoint\else\showmessage\m!layouts{11}{#1}\fi
+ \edef\spacingfactor{1}%
+ \else
+ \edef\spacingfactor{#1}%
+ \fi
+ %\setspacingfactor\systemtopskipfactor \topskipfactor {#1}% why no \spacingfactor ?
+ %\setspacingfactor\systemmaxdepthfactor\maxdepthfactor{#1}% why no \spacingfactor ?
+ \edef\systemtopskipfactor {\withoutpt\the\dimexpr#1\dimexpr\topskipfactor \points}%
+ \edef\systemmaxdepthfactor{\withoutpt\the\dimexpr#1\dimexpr\maxdepthfactor\points}%
+ \setnormalbaselines
+ \setstrut}
+
+%D Sometimes one needs to freeze the interlinespacing
+%D
+%D \starttyping
+%D \rm \saveinterlinespace .... {\ss \restoreinterlinespace .... \endgraf}
+%D \stoptyping
+
+\let\restoreinterlinespace\relax
+
+\def\saveinterlinespace
+ {\edef\restoreinterlinespace
+ {\lineheight \the\lineheight
+ \openstrutheight \the\openstrutheight
+ \openstrutdepth \the\openstrutdepth
+ \openlineheight \the\openlineheight
+ \normalbaselineskip \the\normalbaselineskip
+ \normallineskip \the\normallineskip
+ \normallineskiplimit\the\normallineskiplimit
+ \noexpand\def\noexpand\normallineheight{\the\dimexpr\normallineheight}%
+ \noexpand\normalbaselines}}
+
+% plain definition:
+%
+% \def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+%
+% could be:
+%
+% \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
+
+\ifx\strutbox\undefined
+
+ \newbox\strutbox
+
+ \setbox\strutbox=\normalhbox{\vrule height8.5pt depth3.5pt width\zeropoint}
+
+ %\def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+ \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
+
+\fi
+
+\let\normalstrut\strut
+
+% The double \hbox construction enables us to \backtrack
+% boxes.
+
+% \def\setstrutdimen#1#2#3% % een strut is n.m maal ex
+% {\strutdimen\normallineheight % wat niet per se \lineheight
+% \strutdimen#2\strutdimen % is omdat een strut lokaal
+% \strutdimen#3\strutdimen % kan afwijken van de globale
+% \edef#1{\the\strutdimen}} % macro % strut
+
+% \def\setstrutdimen#1#2#3% % een strut is n.m maal ex
+% {\strutdimen\normallineheight % wat niet per se \lineheight
+% \strutdimen#2\strutdimen % is omdat een strut lokaal
+% \strutdimen#3\strutdimen % kan afwijken van de globale
+% \edef#1{\the\strutdimen}} % macro % strut
+
+% \def\setstrut
+% {\setstrutdimen\strutheight\strutheightfactor\spacingfactor
+% \setstrutdimen\strutdepth \strutdepthfactor \spacingfactor
+% \let\strut=\normalstrut
+% \setbox\strutbox=\normalhbox
+% {\normalhbox
+% {\vrule
+% \!!width \strutwidth
+% \!!height \strutheight
+% \!!depth \strutdepth
+% \normalkern-\strutwidth}}}
+
+% \def\setstrut
+% {\setstrutdimen\strutheight\strutheightfactor\spacingfactor
+% \setstrutdimen\strutdepth \strutdepthfactor \spacingfactor
+% \dosetstrut}
+
+% \def\setstrut
+% {\strutdimen\normallineheight
+% \strutdimen\strutheightfactor\strutdimen
+% \strutdimen\spacingfactor\strutdimen
+% \edef\strutheight{\the\strutdimen}%
+% \strutdimen\normallineheight
+% \ifgridsnapping
+% \advance\strutdimen-\strutheight
+% \else
+% \strutdimen\strutdepthfactor\strutdimen
+% \strutdimen\spacingfactor\strutdimen
+% \fi
+% \edef\strutdepth{\the\strutdimen}%
+% \dosetstrut}
+
+% interesting, strutdepth is 4.05064pt vs 4.05066pt depending on grid
+% nasty rounding problem
+
+% \def\setstrut
+% {% height
+% \strutdimen\normallineheight
+% \ifdim\minimumstrutheight>\zeropoint
+% \strutdimen\minimumstrutheight
+% \else
+% \strutdimen\strutheightfactor\strutdimen
+% \fi
+% \strutdimen\spacingfactor\strutdimen
+% \edef\strutheight{\the\strutdimen}%
+% % depth
+% \strutdimen\normallineheight
+% \ifgridsnapping
+% \ifdim\minimumstrutdepth>\zeropoint
+% \strutdimen\minimumstrutdepth
+% \else
+% \advance\strutdimen-\strutheight
+% \fi
+% \else
+% \ifdim\minimumstrutdepth>\zeropoint
+% \strutdimen\minimumstrutdepth
+% \else
+% \strutdimen\strutdepthfactor\strutdimen
+% \fi
+% \strutdimen\spacingfactor\strutdimen
+% \fi
+% \edef\strutdepth{\the\strutdimen}%
+% % finish
+% \dosetstrut}
+
+% \def\setstrut
+% {% height
+% \ifdim\minimumstrutheight>\zeropoint
+% \edef\strutheight{\the\dimexpr\spacingfactor\dimexpr\minimumstrutheight}%
+% \else
+% \edef\strutheight{\the\dimexpr\spacingfactor\dimexpr\strutheightfactor\dimexpr\normallineheight}%
+% \fi
+% % depth
+% \ifgridsnapping
+% \ifdim\minimumstrutdepth>\zeropoint
+% \edef\strutdepth{\the\dimexpr\minimumstrutdepth}%
+% \else
+% \edef\strutdepth{\the\dimexpr\normallineheight-\strutheight}%
+% \fi
+% \else
+% \ifdim\minimumstrutdepth>\zeropoint
+% \edef\strutdepth{\the\dimexpr\spacingfactor\dimexpr\minimumstrutdepth}%
+% \else
+% \edef\strutdepth{\the\dimexpr\spacingfactor\dimexpr\strutdepthfactor\dimexpr\normallineheight}%
+% \fi
+% \fi
+% % finish
+% \dosetstrut}
+
+\unexpanded\def\setstrut
+ {% height
+ \edef\strutheight
+ {\the\dimexpr\spacingfactor\dimexpr
+ \ifdim\minimumstrutheight>\zeropoint
+ \minimumstrutheight
+ \else
+ \strutheightfactor\dimexpr\normallineheight
+ \fi}%
+ % depth
+ \edef\strutdepth
+ {\the\dimexpr
+ \ifgridsnapping
+ \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth
+ \else
+ \normallineheight-\strutheight
+ \fi
+ \else
+ \spacingfactor\dimexpr
+ \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth
+ \else
+ \strutdepthfactor\dimexpr\normallineheight
+ \fi
+ \fi}%
+ % finish
+ \dosetstrut}
+
+\unexpanded\def\setcharstrut#1%
+ {\setbox\strutbox\normalhbox{#1}%
+ \edef\strutheight{\the\strutht}%
+ \edef\strutdepth {\the\strutdp}%
+ \dosetstrut}
+
+% \def\setfontstrut
+% {\setcharstrut{(}}
+%
+% better, since some fonts have small (but descending Q etc)
+
+\unexpanded\def\setfontstrut
+ {\setcharstrut{(gplQT}}
+
+\unexpanded\def\setcapstrut% could be M, but Q has descender
+ {\setcharstrut{Q}}
+
+%D Handy for math (used in mathml):
+
+\def\charhtstrut
+ {\begingroup
+ \setcharstrut{GJY}%
+ \vrule\!!width\zeropoint\!!depth\zeropoint\!!height\strutht
+ \endgroup}
+
+\def\chardpstrut
+ {\begingroup
+ \setcharstrut{gjy}%
+ \vrule\!!width\zeropoint\!!depth\strutdp\!!height\zeropoint
+ \endgroup}
+
+%D Centered looks nicer:
+
+% \def\dosetstrut
+% {\let\strut\normalstrut
+% \setbox\strutbox\normalhbox
+% {\normalhbox to \zeropoint
+% {% \hss % new, will be option
+% \vrule
+% \!!width \strutwidth
+% \!!height\strutheight
+% \!!depth \strutdepth
+% \hss}}%
+% \struttotal\dimexpr\strutht+\strutdp\relax}
+%
+% because of all the callbacks in mkiv, we avoid unnecessary boxes ...
+% maybe use an attribute so that we can tag boxes that don't need a
+% treatment; tests with using an attribute so far have shown that
+% it's slower because testing the attribute takes time too
+
+\def\dosetstrut
+ {\let\strut\normalstrut
+ \ifdim\strutwidth=\zeropoint
+ \setbox\strutbox\normalhbox
+ {\vrule
+ \!!width \zeropoint
+ \!!height\strutheight
+ \!!depth \strutdepth}%
+ \else
+ \setbox\strutbox\normalhbox
+ {\normalhbox to \zeropoint
+ {% \hss % new, will be option
+ \vrule
+ \!!width \strutwidth
+ \!!height\strutheight
+ \!!depth \strutdepth
+ \hss}}%
+ \fi
+ \struttotal\dimexpr\strutht+\strutdp\relax}
+
+%D The dimen \type {\struttotal} holds the exact size of the
+%D strut; occasionally a one scaled point difference can show
+%D up with the lineheight.
+
+%D Sometimes a capstrut comes in handy
+%D
+%D \starttabulate[|Tl|l|l|]
+%D \NC yes \NC normal strut \NC {\showstruts\setupstrut[yes]\strut} \NC \NR
+%D \NC no \NC no strut \NC {\showstruts\setupstrut[no]\strut} \NC \NR
+%D \NC kap \NC a capital strut (i.e. Q) \NC {\showstruts\setupstrut[cap]\strut} \NC \NR
+%D \NC A B \unknown \NC a character strut (e.g. A) \NC {\showstruts\setupstrut[A]\strut} \NC \NR
+%D \NC \NC a normal strut \NC {\showstruts\setupstrut\strut} \NC \NR
+%D \stoptabulate
+
+\def\setupstrut
+ {\dosingleempty\dosetupstrut}
+
+\def\dosetupstrut[#1]% yet undocumented, todo: fontstrut
+ {\processaction
+ [#1]
+ [ \v!yes=>\setstrut,
+ \v!auto=>\setautostrut,
+ \v!no=>\setnostrut,
+ \v!cap=>\setcapstrut,
+ \v!fit=>\setfontstrut,
+ \v!line=>\setstrut,
+ \s!default=>\setstrut,
+ \s!unknown=>\setcharstrut\commalistelement]}
+
+\def\setteststrut
+ {\def\strutwidth{.8pt}%
+ \setstrut}
+
+\def\autostrutfactor{1.1}
+
+\def\setautostrut
+ {\begingroup
+ \setbox\scratchbox\copy\strutbox
+ \setstrut
+ \ifdim\ht\strutbox>\autostrutfactor\ht\scratchbox
+ \endgroup \setstrut
+ \else\ifdim\dp\strutbox>\autostrutfactor\dp\scratchbox
+ \endgroup \setstrut
+ \else
+ \endgroup
+ \fi\fi}
+
+% simple version
+%
+% \def\begstrut
+% {\relax\ifcase\strutht\else
+% \strut
+% \normalpenalty\plustenthousand
+% \normalhskip\zeropoint
+% \ignorespaces
+% \fi}
+%
+% \def\endstrut
+% {\relax\ifhmode\ifcase\strutht\else
+% \removeunwantedspaces
+% \normalpenalty\plustenthousand
+% \normalhskip\zeropoint
+% \strut
+% \fi\fi}
+
+% when enabled, sigstruts will remove themselves if nothing
+% goes inbetween
+
+\newsignal\strutsignal \setfalse\sigstruts
+
+\def\begstrut
+ {\relax\ifcase\strutht\else
+ \ifconditional\sigstruts
+ \noindent\horizontalstrut
+ \normalpenalty\plustenthousand
+ \normalhskip-\strutsignal
+ \normalhskip\strutsignal
+ \else
+ \strut
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \fi
+ \expandafter \ignorespaces
+ \fi}
+
+\def\endstrut
+ {\relax\ifhmode\ifcase\strutht\else
+ \ifconditional\sigstruts
+ \ifdim\lastskip=\strutsignal
+ \unskip\unskip\unpenalty\setbox\scratchbox\lastbox
+ \else
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \strut
+ \fi
+ \else
+ \removeunwantedspaces
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \strut
+ \fi
+ \fi\fi}
+
+\newbox\nostrutbox \setbox\nostrutbox\normalhbox{} % {\normalhbox{}}
+
+\def\setnostrut
+ {\setbox\strutbox\copy\nostrutbox
+ \let\strut\empty
+ \let\endstrut\empty
+ \let\begstrut\empty
+ \let\crlfplaceholder\empty}
+
+% unsave:
+%
+% \def\pseudostrut
+% {\bgroup
+% \setnostrut
+% \normalstrut
+% \egroup}
+%
+% try:
+%
+% \startchemie
+% \chemie[ONE,Z0,SB15,MOV1,SB15,Z0][C,C]
+% \stopchemie
+%
+% so:
+
+\def\pseudostrut
+ {\noindent} % better: \dontleavehmode
+
+\let\pseudobegstrut\pseudostrut
+
+\let\pseudoendstrut\removeunwantedspaces
+
+\def\resetteststrut
+ {\let\strutwidth\zeropoint
+ \setstrut}
+
+\ifx\setfontparameters\undefined
+ % problems ! ! ! !
+ \def\setfontparameters{\the\everybodyfont}
+\fi
+
+%D Handy:
+
+\def\baselinedistance{\the\lineheight}
+
+%D We need \type{\normaloffinterlineskip} because the new
+%D definition contains an assignment, and |<|don't ask me
+%D why|>| this assignment gives troubles in for instance the
+%D visual debugger.
+
+%D The plain ones:
+
+\def\offinterlineskip
+ {\baselineskip-\thousandpoint
+ \lineskip\zeropoint
+ \lineskiplimit\maxdimen}
+
+\def\nointerlineskip
+ {\prevdepth-\thousandpoint}
+
+\let\normaloffinterlineskip=\offinterlineskip % knuth's original
+
+%D My own one:
+
+\def\offinterlineskip
+ {\ifdim\baselineskip>\zeropoint
+ \edef\oninterlineskip
+ {\baselineskip\the\baselineskip
+ \lineskip\the\lineskip
+ \lineskiplimit\the\lineskiplimit
+ \let\noexpand\offinterlineskip\noexpand\normaloffinterlineskip}%
+ \else
+ \let\oninterlineskip\setnormalbaselines
+ \fi
+ \normaloffinterlineskip}
+
+\let\oninterlineskip=\relax
+
+\def\leaveoutervmode
+ {\ifvmode\ifinner\else
+ \leavevmode
+ \fi\fi}
+
+% We stellen enkele penalties anders in dan Plain TEX:
+
+% oud
+%
+% \widowpenalty=\defaultwidowpenalty\relax
+% \clubpenalty =\defaultclubpenalty \relax
+
+\def\resetpenalties#1%
+ {\ifx#1\undefined\else
+ #1\minusone
+ \fi}
+
+\def\setpenalties#1#2#3%
+ {\ifx#1\undefined\else % space before #3 prevents lookahead problems, needed when #3=text
+ #1\numexpr#2+\plusone\relax\space\doexpandedrecurse{\the\numexpr#2\relax}{ #3}\zerocount\relax
+ \fi}
+
+\def\doexpandedrecurse#1#2%
+ {\ifnum#1>\zerocount#2\@EA\doexpandedrecurse\@EA{\the\numexpr#1-1\relax}{#2}\fi}
+
+%D \macros
+%D {keeplinestogether}
+%D
+%D Dirty hack, needed in margin content that can run of a page.
+
+\def\keeplinestogether#1%
+ {\xdef\restoreinterlinepenalty{\global\resetpenalties\interlinepenalties}%
+ \global\setpenalties\interlinepenalties{#1}\plustenthousand}
+
+\newif\ifgridsnapping % to be sure
+
+\def\defaultwidowpenalty {2000} % was: 1000
+\def\defaultclubpenalty {2000} % was: 800
+\def\defaultdisplaywidowpenalty {50}
+\def\defaultbrokenpenalty {100}
+
+\def\defaultgridwidowpenalty {0}
+\def\defaultgridclubpenalty {0}
+\def\defaultgriddisplaywidowpenalty {0}
+\def\defaultgridbrokenpenalty {0}
+
+% The original approach:
+%
+% \def\setdefaultpenalties
+% {\ifgridsnapping
+% \widowpenalty\defaultgridwidowpenalty
+% \clubpenalty \defaultgridclubpenalty
+% \else
+% \widowpenalty\defaultwidowpenalty
+% \clubpenalty \defaultclubpenalty
+% \fi}
+%
+% However, we will use setups:
+
+% to be documented
+
+\def\nopenalties
+ {\widowpenalty \zerocount
+ \clubpenalty \zerocount
+ \brokenpenalty \zerocount
+ \doublehyphendemerits\zerocount
+ \finalhyphendemerits \zerocount
+ \adjdemerits \zerocount}
+
+\def\setdefaultpenalties
+ {\directsetup{\systemsetupsprefix\s!default}}
+
+\startsetups [\systemsetupsprefix\s!reset]
+ \resetpenalties\widowpenalties
+ \resetpenalties\clubpenalties
+ \resetpenalties\interlinepenalties
+\stopsetups
+
+% we use \directsetup because it's faster and we know there is no csl
+
+\startsetups [\systemsetupsprefix\s!default]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \widowpenalty \defaultwidowpenalty
+ \clubpenalty \defaultclubpenalty
+ \displaywidowpenalty\defaultdisplaywidowpenalty
+ \brokenpenalty \defaultbrokenpenalty
+
+\stopsetups
+
+\startsetups [\v!grid] [\systemsetupsprefix\s!default]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \widowpenalty \defaultgridwidowpenalty
+ \clubpenalty \defaultgridclubpenalty
+ \displaywidowpenalty\defaultgriddisplaywidowpenalty
+ \brokenpenalty \defaultgridbrokenpenalty
+
+\stopsetups
+
+% as an illustration:
+
+\startsetups [\systemsetupsprefix\v!strict]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \setpenalties\widowpenalties2\maxdimen
+ \setpenalties\clubpenalties 2\maxdimen
+ \brokenpenalty \maxdimen
+
+\stopsetups
+
+\setdefaultpenalties % will happen later in \setuplayout
+
+% Suggested by GB (not the name -):
+
+\def\rapfillskip{.5\hsize plus .092\hsize minus .5\hsize} % D.A.'s value
+
+% Bovendien definieren we enkele extra \fill's:
+
+\def\hfilll{\hskip\zeropoint\!!plus1filll\relax}
+\def\vfilll{\vskip\zeropoint\!!plus1filll\relax}
+
+% De onderstaande hulpmacro's moeten nog eens instelbaar worden
+% gemaakt.
+
+\def\tfskipsize{1em\relax}
+\def\tfkernsize{1ex\relax}
+
+\def\tfskip{\dotfskip\tfskipsize}
+\def\tfkern{\dotfkern\tfkernsize}
+
+\def\dotfskip#1{{\tf\hskip#1}}
+\def\dotfkern#1{{\tf\kern #1}}
+
+% needs a proper \definenarrower or installnarrower
+
+\newskip\ctxleftskip
+\newskip\ctxrightskip
+\newskip\ctxmidskip
+
+\def\dosinglenarrower#1%
+ {\processaction
+ [#1]
+ [ \v!left=>\global\advance\ctxleftskip \@@slleft,
+ \v!middle=>\global\advance\ctxmidskip \@@slmiddle,
+ \v!right=>\global\advance\ctxrightskip \@@slright,
+ \v!reset=>\global\ctxleftskip \zeropoint
+ \global\ctxmidskip \zeropoint
+ \global\ctxrightskip\zeropoint,
+ \v!none=>,
+ \s!unknown=>\global\advance\ctxmidskip \commalistelement]}
+
+% \def\donarrower[#1]% hm, can be dorepeat directly
+% {\processaction
+% [#1]
+% [ \v!left=>\global\advance\ctxleftskip \@@slleft,
+% \v!middle=>\global\advance\ctxmidskip \@@slmiddle,
+% \v!right=>\global\advance\ctxrightskip \@@slright,
+% \v!none=>,% handy for delimitedtexts
+% \s!unknown=>{\dorepeatwithcommand[#1]\dosinglenarrower}]}
+
+\def\donarrower[#1]% hm, can be dorepeat directly
+ {\dorepeatwithcommand[#1]\dosinglenarrower}
+
+\def\complexstartnarrower[#1]%
+ {\@@slbefore % was hard coded \par
+ \bgroup
+ \global\ctxleftskip \zeropoint
+ \global\ctxrightskip\zeropoint
+ \global\ctxmidskip \zeropoint
+ \processcommalistwithparameters[#1]\donarrower
+ \advance\leftskip \ctxleftskip
+ \advance\rightskip \ctxrightskip
+ \advance\leftskip \ctxmidskip
+ \advance\rightskip \ctxmidskip
+ \seteffectivehsize}
+
+% todo: definenarrower
+
+\def\simplestartnarrower
+ {\startnarrower[\v!middle]}
+
+\definecomplexorsimple\startnarrower
+
+\def\stopnarrower
+ {\@@slafter % was hard coded \par / needed, else skips forgotten
+ \egroup}
+
+\def\setupnarrower
+ {\dodoubleargument\getparameters[\??sl]}
+
+\newdimen\@@effectivehsize \def\effectivehsize {\hsize}
+\newdimen\@@effectiveleftskip \def\effectiveleftskip {\leftskip}
+\newdimen\@@effectiverightskip \def\effectiverightskip{\rightskip}
+
+\def\seteffectivehsize
+ {\setlocalhsize
+ \@@effectivehsize \localhsize
+ \@@effectiveleftskip \leftskip
+ \@@effectiverightskip \rightskip
+ \let\effectivehsize \@@effectivehsize
+ \let\effectiveleftskip \@@effectiveleftskip
+ \let\effectiverightskip\@@effectiverightskip}
+
+\def\dodefinehbox[#1][#2]%
+ {\setvalue{hbox#1}##1%
+ {\hbox to #2{\begstrut##1\endstrut\hss}}}
+
+\def\definehbox
+ {\dodoubleargument\dodefinehbox}
+
+\def\iobox#1#2#3#% here #3# is not really needed
+ {\vbox\bgroup % we want to return a vbox like the others
+ \hbox\bgroup% we need to pack the signal with the box
+ \signalrightpage
+ \dowithnextboxcontent
+ {\let\\=\endgraf\forgetall\doifrightpageelse#1#2}
+ {\box\nextbox\egroup\egroup}
+ \vbox#3}
+
+\def\obox{\iobox\raggedleft \raggedright} % outerbox
+\def\ibox{\iobox\raggedright\raggedleft} % innerbox
+
+\def\dosetraggedvbox#1%
+ {\let\raggedbox\vbox
+ \processfirstactioninset
+ [#1]
+ [ \v!left=>\let\raggedbox\lbox,
+ \v!right=>\let\raggedbox\rbox,
+ \v!middle=>\let\raggedbox\cbox,
+ \v!inner=>\let\raggedbox\ibox,
+ \v!outer=>\let\raggedbox\obox,
+ \v!flushleft=>\let\raggedbox\rbox,
+ \v!flushright=>\let\raggedbox\lbox,
+ \v!center=>\let\raggedbox\cbox,
+ \v!no=>\def\raggedbox{\vbox\bgroup\raggedright\let\next=}]}
+
+\def\dosetraggedhbox#1%
+ {\let\raggedbox\hbox
+ \processaction % slow
+ [#1]
+ [ \v!left=>\def\raggedbox{\doalignedline\v!left },
+ \v!right=>\def\raggedbox{\doalignedline\v!right },
+ \v!middle=>\def\raggedbox{\doalignedline\v!middle},
+ \v!inner=>\def\raggedbox{\doalignedline\v!inner },
+ \v!outer=>\def\raggedbox{\doalignedline\v!outer },
+ \v!flushleft=>\def\raggedbox{\doalignedline\v!right },
+ \v!flushright=>\def\raggedbox{\doalignedline\v!left },
+ \v!center=>\def\raggedbox{\doalignedline\v!middle}]}
+
+\def\dosetraggedcommand#1%
+ {\expanded{\dodosetraggedcommand{#1}}}
+
+% \def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that!
+% {\let\raggedcommand \relax
+% \let\raggedtopcommand \empty
+% \let\raggedbottomcommand\empty
+% \chardef\raggedoneliner\zerocount
+% \doifsomething{#1}
+% {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse
+% \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse
+% \!!donectrue
+% \rawprocesscommalist[#1]\dododosetraggedcommand}}
+
+\newtoks\everyraggedcommand
+
+\def\raggedcommand{\the\everyraggedcommand}
+
+\def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that!
+ {\everyraggedcommand \emptytoks
+ \let\raggedtopcommand \empty
+ \let\raggedbottomcommand\empty
+ \chardef\raggedoneliner\zerocount
+ \doifsomething{#1}
+ {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse
+ \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse
+ \!!donectrue
+ \rawprocesscommalist[#1]\dododosetraggedcommand}}
+
+\def\dododosetraggedcommand#1%
+ {\executeifdefined{\@@ragged@@command\string#1}\relax}
+
+\def\@@ragged@@command{@@raggedcommand}
+
+\setvalue{\@@ragged@@command\v!hanging }{\appendtoks\enableprotruding \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nothanging }{\appendtoks\disableprotruding \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!hz }{\appendtoks\enableadjusting \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nohz }{\appendtoks\disableadjusting \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!spacing }{\appendtoks\enablespacehandling
+ \enablekernhandling \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nospacing }{\appendtoks\disablespacehandling
+ \disablekernhandling \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!hyphenated }{\appendtoks\dohyphens \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nothyphenated}{\appendtoks\nohyphens \to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!tolerant }{\appendtoks\tolerance3000\relax \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!verytolerant}{\appendtoks\tolerance4500\relax \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!stretch }{\appendtoks\emergencystretch\bodyfontsize\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!left}%
+ {\if!!donea \appendtoks\veryraggedleft\to\everyraggedcommand
+ \else \appendtoks\raggedleft \to\everyraggedcommand
+ \fi
+ \!!donecfalse}
+
+\setvalue{\@@ragged@@command\v!right}%
+ {\if!!donea \appendtoks\veryraggedright\to\everyraggedcommand
+ \else \appendtoks\raggedright \to\everyraggedcommand
+ \fi
+ \!!donecfalse}
+
+\setvalue{\@@ragged@@command\v!middle}%
+ {\if!!donec
+ \if!!doneb \appendtoks\raggedwidecenter\to\everyraggedcommand
+ \else\if!!donea \appendtoks\veryraggedcenter\to\everyraggedcommand
+ \else \appendtoks\raggedcenter \to\everyraggedcommand
+ \fi\fi
+ \!!donecfalse
+ \else
+ \let\raggedbottomcommand\vfilll % bonus, pretty strong
+ \let\raggedtopcommand \vfilll % used with \framed for
+ \fi} % instance in tables
+
+\setvalue{\@@ragged@@command\v!flushleft }{\getvalue{\@@ragged@@command\v!right }}
+\setvalue{\@@ragged@@command\v!flushright}{\getvalue{\@@ragged@@command\v!left }}
+\setvalue{\@@ragged@@command\v!center }{\getvalue{\@@ragged@@command\v!middle}}
+
+\setvalue{\@@ragged@@command\v!high}%
+ {\let\raggedbottomcommand\vfilll} % and since we lack a
+
+\setvalue{\@@ragged@@command\v!low}%
+ {\let\raggedtopcommand\vfilll} % proper keyword, but
+
+\setvalue{\@@ragged@@command\v!lohi}%
+ {\let\raggedbottomcommand\vfilll % we do support the
+ \let\raggedtopcommand\vfilll} % ugly laho (lohi)
+
+\setvalue{\@@ragged@@command\v!no}%
+ {\appendtoks\raggedright\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!yes}%
+ {\appendtoks\notragged\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!normal}%
+ {\appendtoks\notragged\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!inner}% not yet perfect
+ {\signalrightpage % may interfere
+ \doifrightpageelse
+ {\getvalue{\@@ragged@@command\v!right}}
+ {\getvalue{\@@ragged@@command\v!left}}}
+
+\setvalue{\@@ragged@@command\v!outer}% not yet perfect
+ {\signalrightpage % may interfere
+ \doifrightpageelse
+ {\getvalue{\@@ragged@@command\v!left}}
+ {\getvalue{\@@ragged@@command\v!right}}}
+
+\setvalue{\@@ragged@@command\v!lesshyphenation}%
+ {\appendtoks\lesshyphens\to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!morehyphenation}%
+ {\appendtoks\morehyphens\to\everyraggedcommand}
+
+% compare:
+%
+% \framed[width=4cm,align=no] {\hfil xxx}
+% \framed[width=4cm,align=disable]{\hfil xxx}
+
+\setvalue{\@@ragged@@command\v!disable}% for one liners
+ {\appendtoks\raggedright\parfillskip\zeropoint\to\everyraggedcommand}
+
+\chardef\raggedoneliner\zerocount
+
+\setvalue{\@@ragged@@command\v!line}%
+ {\chardef\raggedoneliner\plusone}
+
+%D Unofficial, may disappear. Now handled directly in the
+%D core-rul module.
+
+% \def\@@startraggedoneliner
+% {\ifcase\raggedoneliner\else
+% \dontleavehmode\hbox to \hsize \bgroup % hsize added, else useless
+% \ifcase\raggedstatus\or\hss\or\hss\fi
+% \ignorespaces
+% \bgroup
+% \aftergroup\removeunwantedspaces
+% \fi}
+
+% \def\@@stopraggedoneliner
+% {\ifcase\raggedoneliner\else
+% \egroup
+% \ifcase\raggedstatus\or\or\hss\or\hss\fi
+% \egroup
+% \ignorespaces % ? ? ?
+% \fi}
+
+% \def\@@handleoneliner
+% {\ifcase\raggedoneliner\else
+% \@@startraggedoneliner
+% \aftergroup\@@stopraggedoneliner
+% \fi}
+
+% Nog doen:
+%
+% \goodbreak -> \allowbreak en \dosomebreak{..} in koppen
+%
+% bij koppen zowieso: \blanko[reset]
+
+% Nog in commando verwerken:
+%
+% \voorkeur la \blanko
+%
+% Om ongewenste witruimte te voorkomen kan met \dosomebreak{\break}
+% een \penalty voor witruimte worden geplaatst.
+
+\def\removelastskip % a redefinition of plain
+ {\ifvmode\ifdim\lastskip=\zeropoint\else\vskip-\lastskip\fi\fi}
+
+% first version:
+%
+% \def\dosomebreak#1%
+% {\scratchskip\lastskip
+% \removelastskip
+% %\type{#1}%
+% #1\relax
+% \ifdim\scratchskip=\zeropoint \else
+% \vskip\scratchskip
+% \fi}
+%
+% don't change the next improvement:
+
+% \def\dosomebreak#1%
+% {\endgraf % beware, this forces a newline
+% \ifvmode
+% \ifdim\lastskip=\zeropoint
+% #1\relax
+% \else
+% \scratchskip\lastskip
+% \removelastskip
+% #1\relax
+% \vskip\scratchskip
+% \fi
+% \fi}
+
+% beter, vooral in \vbox; nog in \pagina toepassen s!
+
+\def\doifoutervmode#1%
+ {\ifvmode\ifinner\else#1\fi\fi}
+
+\ifx\dosomebreak\undefined % defined in mkiv
+
+ \def\dosomebreak#1%
+ {\doifoutervmode
+ {\scratchskip\lastskip
+ \removelastskip
+ %\leavevmode\type{#1}%
+ #1\relax
+ \ifdim\scratchskip=\zeropoint % else interference with footnotes
+ \else
+ \vskip\scratchskip
+ \fi}}
+
+\fi
+
+\def\forgeteverypar
+ {\everypar{\the\neverypar}}
+
+%\def\forgetparindent
+% {\forgeteverypar
+% \indentfirstparagraphtrue % recently added
+% \setupindenting[\v!geen]}
+
+%\def\forgetparskip
+% {\setupwhitespace[\v!geen]}
+
+\def\forgetparindent
+ {\forgeteverypar
+ \indentfirstparagraphtrue % recently added
+ \let\currentindentation\v!none
+ \ctxparindent\zeropoint
+ \parindent\zeropoint\relax}
+
+\def\forgetparskip
+ {\let\currentwhitespace\v!none
+ \ctxparskip\zeropoint
+ \parskip\zeropoint\relax}
+
+\def\forgetbothskips
+ {\tolerance1500
+ \leftskip\zeropoint
+ \rightskip\zeropoint\relax}
+
+\def\forgetspacing
+ {\emergencystretch\zeropoint}
+
+\newif\ifforgotten % rather good signal for inner
+
+\appendtoks \forgottentrue \to \everyforgetall
+\appendtoks \forgetragged \to \everyforgetall
+\appendtoks \forgetparskip \to \everyforgetall
+\appendtoks \forgetparindent \to \everyforgetall
+\appendtoks \forgetbothskips \to \everyforgetall
+\appendtoks \forgetspacing \to \everyforgetall % i.v.m. funny spacing in pagebody
+\appendtoks \spacing\!!plusone \to \everyforgetall % new per 10/08/2004, else problems in otr / !! needed
+\appendtoks \everypar\emptytoks \to \everyforgetall % indeed!
+
+\def\localvbox#1#%
+ {\vbox#1\bgroup
+ \forgetparskip
+ \setlocalhsize
+ \hsize\localhsize
+ \forgetparindent
+ \forgetbothskips
+ \forgeteverypar
+ \let\next=}
+
+% ach ja, hoort niet hier
+
+% \unexpanded\def\dostartattributes#1#2#3%
+% {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+% \doifdefinedelse{#1#2}
+% {\def\fontattribute{\getvalue{#1#2}}}
+% {\let\fontattribute=\empty}%
+% \doifdefinedelse{#1#3}
+% {\def\colorattribute{\getvalue{#1#3}}}
+% {\let\colorattribute=\empty}%
+% \startcolor[\colorattribute]%
+% \@EA\doconvertfont\@EA{\fontattribute}}
+%
+% \unexpanded\def\dostopattributes%
+% {\stopcolor
+% \endgroup}
+%
+% \unexpanded\def\doattributes#1#2#3#4%
+% {\dostartattributes{#1}{#2}{#3}{#4}\dostopattributes}
+
+%D A hardly faster implementation follows. We cannot use
+%D \type {csname} testing since the first argument can be
+%D anything, even a raw fontswitch. No a real improvement
+%D (some 5 seconds on 260 seconds for the maps bibliography).
+
+\let\dostopattributes\relax % in case these commands end up in an edef
+
+\unexpanded\def\dostartattributes#1#2#3%
+ {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+ \ifcsname#1#3\endcsname
+ \let\dostopattributes\@@dostopattributes
+ \startcolor[\csname#1#3\endcsname]%
+ \else
+ \let\dostopattributes\@@nostopattributes
+ \fi
+ \ifcsname#1#2\endcsname
+ \expandafter\doconvertfont
+ \else
+ \expandafter\gobbleoneargument
+ \fi{\csname#1#2\endcsname}}
+
+\newconditional \parbasedattributes
+
+\def\finishparbasedattributes
+ {\ifconditional\parbasedattributes
+ \setfalse\parbasedattributes
+ \par
+ \fi}
+
+\def\dostopparbasedattributes
+ {\settrue\parbasedattributes
+ \dostopattributes}
+
+\unexpanded\def\@@dostopattributes
+ {\stopcolor
+ \finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\@@nostopattributes
+ {\finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\doattributes#1#2#3#4%
+ {\dostartattributes{#1}{#2}{#3}{#4}\dostopattributes}
+
+% An even faster \ETEX\ version:
+
+\unexpanded\def\dostartattributes#1#2#3%
+ {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+ \ifincolor
+ \ifcsname#1#3\endcsname
+ \let\dostopattributes\@@dostopattributes
+ \faststartcolor[\csname#1#3\endcsname]%
+ \else
+ \let\dostopattributes\@@nostopattributes
+ \fi
+ \else
+ \let\dostopattributes\@@nostopattributes
+ \fi
+ \ifcsname#1#2\endcsname
+ % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi}
+
+\unexpanded\def\@@dostopattributes
+ {\faststopcolor
+ \finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\@@nostopattributes
+ {\finishparbasedattributes
+ \endgroup}
+
+%D Bonus macro, see core-sec.tex
+
+\unexpanded\def\dosetfontattribute#1#2%
+ {\ifcsname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi\empty}
+
+%D Since this happens a lot, and sometimes large arguments
+%D are passed in \type {#4}, we just copy some code:
+
+\unexpanded\def\doattributes#1#2#3#4%
+ {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+ \ifincolor
+ \ifcsname#1#3\endcsname
+ \let\dostopattributes\@@dostopattributes
+ \faststartcolor[\csname#1#3\endcsname]%
+ \else
+ \let\dostopattributes\endgroup
+ \fi
+ \else
+ \let\dostopattributes\endgroup
+ \fi
+ \ifcsname#1#2\endcsname
+ % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi
+ {#4}%
+ \dostopattributes}
+
+% Kan vaker worden toegepast en moet bovendien sneller!
+
+\newskip\leftskipadaption
+\newskip\rightskipadaption
+
+\def\doadaptleftskip#1%
+ {\dosetleftskipadaption{#1}%
+ \advance\leftskip \leftskipadaption}
+
+\def\doadaptrightskip#1%
+ {\dosetrightskipadaption{#1}%
+ \advance\rightskip \rightskipadaption}
+
+\setvalue{@lsa@\v!standard}{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
+\setvalue{@lsa@\v!yes }{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
+\letvalue{@lsa@\v!no }\zeropoint
+\letvalue{@lsa@\empty }\zeropoint
+\setvalue{@rsa@\v!standard}{\@@slright}
+\setvalue{@rsa@\v!yes }{\@@slright}
+\letvalue{@rsa@\v!no }\zeropoint
+\letvalue{@rsa@\empty }\zeropoint
+
+% not safe for 2\parindent
+%
+% \def\dosetleftskipadaption#1%
+% {\leftskipadaption
+% \ifcsname @lsa@#1\endcsname
+% \csname @lsa@#1\endcsname
+% \else
+% #1%
+% \fi
+% \relax}
+
+\def\dosetleftskipadaption#1%
+ {\edefconvertedargument\ascii{@lsa@#1}%
+ \leftskipadaption
+ \ifcsname\ascii\endcsname
+ \csname\ascii\endcsname
+ \else
+ #1%
+ \fi
+ \relax}
+
+\def\dosetrightskipadaption#1%
+ {\edefconvertedargument\ascii{@rsa@#1}%
+ \rightskipadaption
+ \ifcsname\ascii\endcsname
+ \csname\ascii\endcsname
+ \else
+ #1%
+ \fi
+ \relax}
+
+\newcount \noftrackedpagestates
+\newif \ifpagestatemismatch
+\newcount \realpagestateno
+\chardef \frozenpagestate \zerocount
+
+\def\dotrackpagestate#1#2%
+ {\ifdoublesided \ifinpagebody \else
+ \doforcedtrackpagestate{#1}{#2}%
+ \fi \fi}
+
+\def\doforcedtrackpagestate#1#2%
+ {\ifcase\frozenpagestate
+ \global\advance\noftrackedpagestates\plusone
+ \global\advance#2\plusone
+ \lazysavetaggedtwopassdata{#1}{\number\noftrackedpagestates}{\number#2}{\noexpand\realfolio}%
+ %\llap{\infofont\number\noftrackedpagestates/\number#2}% tracing
+ \fi}
+
+\def\doifrightpagestateelse#1#2%
+ {\ifcase\frozenpagestate
+ \pagestatemismatchfalse
+ \realpagestateno\realfolio
+ \ifinpagebody
+ \ifdoublesided
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \twopassdatafoundtrue
+ \fi
+ \else\ifdoublesided
+ \findtwopassdata{#1}{\number#2}%
+ \iftwopassdatafound
+ \realpagestateno\twopassdata\relax
+ \ifnum\twopassdata=\realpageno \else
+ \pagestatemismatchtrue
+ \fi
+ \ifodd\twopassdata\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \else
+ \twopassdatafoundtrue
+ \fi\fi
+ \else
+ \ifodd\realpagestateno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \iftwopassdatafound
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+\def\doifforcedrightpagestateelse#1#2%
+ {\ifcase\frozenpagestate
+ \pagestatemismatchfalse
+ \realpagestateno\realfolio
+ \findtwopassdata{#1}{\number#2}%
+ \iftwopassdatafound
+ \realpagestateno\twopassdata\relax
+ \ifnum\twopassdata=\realpageno \else
+ \pagestatemismatchtrue
+ \fi
+ \ifodd\twopassdata\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \else
+ \ifodd\realpagestateno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \iftwopassdatafound
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+\def\freezepagestate {\chardef\frozenpagestate\plusone }
+\def\defrostpagestate{\chardef\frozenpagestate\zerocount}
+
+% we can make more of these on top, but how to deal with mixed frozen states
+
+\definetwopasslist\s!paragraph \newcount \nofraggedparagraphs
+
+\def\signalrightpage {\dotrackpagestate \s!paragraph\nofraggedparagraphs}
+\def\doifrightpageelse{\doifrightpagestateelse\s!paragraph\nofraggedparagraphs}
+
+\newcount\pagesignallevel
+
+\def\startsignalrightpage % one may do a \postsignalrightplace
+ {\advance\pagesignallevel\plusone
+ \presignalrightpage
+ \let\signalrightpage\relax
+ \let\presignalrightpage\relax
+ \let\startsignalrightpage\relax
+ \doifrightpageelse\donothing\donothing
+ \freezepagestate}
+
+\def\stopsignalrightpage
+ {\ifcase\pagesignallevel\or\postsignalrightpage\fi
+ \advance\pagesignallevel\minusone}
+
+\def\setraggedparagraphmode
+ {\signalrightpage\doifrightpageelse} % move it there
+
+\ifx\swapmargins\undefined \let\swapmargins\undefined \fi % todo
+
+\def\doifswappedrightpageelse#1#2% alleen in box construction !
+ {\doifrightpageelse
+ {#1}
+ {\scratchcounter\realpageno
+ \realpageno\realpagestateno\relax
+ \swapmargins
+ \realpageno\scratchcounter
+ #2}}
+
+\newbox\signaledrightpage % this way we can avoid interference, i.e. postpone placement
+
+\def\presignalrightpage {\global\setbox\signaledrightpage\hbox{\signalrightpage}}
+\def\postsignalrightpage{\ifvoid\signaledrightpage\else\box\signaledrightpage\fi}
+
+% The next feature is is used in:
+%
+% \definenumber[test][way=bypage]
+%
+% \def\Test
+% {\incrementnumber[test]\rawnumber[test]/%
+% \incrementnumber[test]\rawnumber[test]/%
+% \incrementnumber[test]\rawnumber[test]\space
+% \checkpagechange{oeps}\changedpage{oeps}\space
+% \ifpagechanged TRUE\else FALSE\fi}
+%
+% \Test\page \Test\par \Test\page \Test\par \Test\page \Test\page
+%
+% (adapted from cont-new.tex:)
+
+\newif\ifpagechanged \let\lastchangedpage\empty
+
+\def\docheckpagestatechange#1#2#3%
+ {\pagechangedfalse
+ \doforcedtrackpagestate{#2}{#3}%
+ \findtwopassdata{#2}{\number#3}%
+ \iftwopassdatafound
+ \ifnum\twopassdata>0\getvalue{#2:p:#1}\relax
+ \pagechangedtrue
+ \fi
+ \fi
+ \ifpagechanged
+ \letgvalue{#2:p:#1}\twopassdata
+ \globallet\lastchangedpage\twopassdata
+ \else
+ \globallet\lastchangedpage\realfolio
+ \fi}
+
+\def\changedpagestate#1#2%
+ {\executeifdefined{#2:p:#1}{0}}
+
+\def\checkpagechange#1{\docheckpagestatechange{#1}\s!paragraph\nofraggedparagraphs}
+\def\changedpage #1{\changedpagestate{#1}\s!paragraph}
+
+% saved struts
+
+\ifx\savedstrutbox\undefined \newbox\savedstrutbox \fi
+
+\def\savestrut {\setbox\savedstrutbox\copy\strutbox}
+\def\savedstrut{\copy \savedstrutbox}
+
+% De onderstaande macro's zijn opgenomen in Plain TeX.
+%
+% \def\raggedright%
+% {\rightskip\zeropoint plus2em \spaceskip.3333em \xspaceskip.5em\relax}
+%
+% \def\ttraggedright%
+% {\tttf\rightskip\zeropoint plus2em\relax}
+%
+% \newif\ifr@ggedbottom
+%
+% \def\raggedbottom%
+% {\topskip 10\points plus60\points \r@ggedbottomtrue}
+%
+% \def\normalbottom%
+% {\topskip 10\points \r@ggedbottomfalse}
+%
+% en worden hieronder wat aangepast.
+
+% the three boolean will become obsolete some day in favour
+% of \bottomraggedness
+
+\chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
+
+\def\bottomalignlimit{3\lineheight}
+
+\newif\ifn@rmalbottom
+\newif\ifr@ggedbottom
+\newif\ifb@selinebottom
+
+\def\normalbottom
+ {% \topskip 10pt
+ \r@ggedbottomfalse}
+
+\def\raggedbottom
+ {\chardef\bottomraggedness\zerocount
+ \n@rmalbottomfalse
+ \r@ggedbottomtrue
+ \b@selinebottomfalse
+ \settopskip}
+
+\def\alignbottom
+ {\chardef\bottomraggedness\plusone
+ \n@rmalbottomtrue
+ \r@ggedbottomfalse
+ \b@selinebottomfalse
+ \settopskip}
+
+\def\baselinebottom
+ {\chardef\bottomraggedness\plustwo
+ \n@rmalbottomfalse
+ \r@ggedbottomfalse
+ \b@selinebottomtrue
+ \settopskip}
+
+\let\normalbottom=\alignbottom % downward compatible
+
+% so, the new one will be
+%
+% \chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
+%
+% \def\bottomalignlimit{3\lineheight} % will be settable
+%
+% \def\raggedbottom {\chardef\bottomraggedness=0 \settopskip}
+% \def\alignbottom {\chardef\bottomraggedness=1 \settopskip}
+% \def\baselinebottom{\chardef\bottomraggedness=2 \settopskip}
+%
+% \let\normalbottom =\alignbottom
+
+% \hyphenpenalty = ( 2.5 * \hsize ) / \raggedness
+% \tolerance >= 1500 % was 200
+% \raggedness = 2 .. 6\bodyfontsize
+
+\chardef\raggedstatus=0 % normal left center right
+
+\def\leftraggedness {2\bodyfontsize}
+\def\rightraggedness {2\bodyfontsize}
+\def\middleraggedness {6\bodyfontsize}
+
+\def\middleraggedness {.5\hsize} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
+
+% oeps, hsize can be 0pt in which case we get a strange division
+
+\def\middleraggedness {\ifdim\hsize=\zeropoint6\bodyfontsize\else.5\hsize\fi} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
+
+%D More hyphenation control, will be combined with align
+%D setup.
+
+\def\nohyphens
+ {\ifx\dohyphens\relax
+ \edef\dohyphens
+ {\hyphenpenalty\the\hyphenpenalty
+ \exhyphenpenalty\the\exhyphenpenalty\relax}%
+ \fi
+ \hyphenpenalty\plustenthousand
+ \exhyphenpenalty\plustenthousand}
+
+\let\dohyphens\relax
+
+%D To prevent unwanted side effects, we also have to check
+%D for hyphens here:
+
+% \def\setraggedness#1%
+% {\ifnum\tolerance<1500\relax % small values have
+% \tolerance1500\relax % unwanted side effects
+% \fi
+% \spaceskip2.5\hsize % we misuse these registers
+% \xspaceskip#1\relax % for temporary storage;
+% \divide\spaceskip \xspaceskip % they are changed anyway
+% \ifx\dohyphens\relax
+% \hyphenpenalty\spaceskip % \else no hyphens is active
+% \fi}
+
+\newskip\@@raggedskipa
+\newskip\@@raggedskipb
+
+\def\setraggedness#1%
+ {\ifnum\tolerance<1500\relax % small values have
+ \tolerance1500\relax % unwanted side effects
+ \fi
+ \ifx\dohyphens\relax
+ % this code will be reconsidered / kind of fuzzy (and old)
+ \@@raggedskipa 2.5\hsize
+ \@@raggedskipb #1\relax
+ \divide\@@raggedskipa \@@raggedskipb
+ \hyphenpenalty\@@raggedskipa
+ \fi}
+
+\let\updateraggedskips\relax
+
+\def\setraggedskips#1#2#3#4#5#6#7% never change this name
+ {\def\updateraggedskips{\dosetraggedskips{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
+ \updateraggedskips}
+
+\def\dosetraggedskips#1#2#3#4#5#6#7%
+ {\chardef \raggedstatus#1\relax
+ \leftskip 1\leftskip \!!plus#2\relax % zie: Tex By Topic 8.1.3
+ \rightskip 1\rightskip\!!plus#3\relax % zie: Tex By Topic 8.1.3
+ \spaceskip #4\relax
+ \xspaceskip #5\relax
+ \parfillskip\zeropoint\!!plus#6\relax
+ \parindent #7\relax}
+
+% \def\notragged%
+% {\setraggedskips{0}{0em}{0em}{0em}{0em}{1fil}{\parindent}}
+
+% older (context) names:
+
+\let\spaceamount \interwordspace
+\let\emspaceamount\emwidth
+
+% tracing:
+
+\def\doshowpardata#1%
+ {\ifx#1\relax\else
+ \hbox{\string#1: \the#1}\endgraf
+ \expandafter\doshowpardata
+ \fi}
+
+\def\showpardata
+ {\edef\thepardata
+ {\hbox{font: \fontname\font}\endgraf
+ \doshowpardata
+ \interwordspace \interwordstretch \interwordshrink \emwidth \exheight \extraspace
+ \hsize \vsize
+ \leftskip \rightskip
+ \spaceskip \xspaceskip
+ \parindent \parfillskip
+ \hyphenpenalty \exhyphenpenalty
+ \displaywidowpenalty \widowpenalty \clubpenalty \brokenpenalty
+ \doublehyphendemerits \finalhyphendemerits \adjdemerits
+ \relax}%
+ \begingroup
+ \dontshowcomposition
+ \inleftmargin{\vsmash
+ {\switchtobodyfont[7pt,tt]%
+ \framed[\c!align=\v!right]{\thepardata}}}%
+ \endgroup}
+
+\def\startshowpardata
+ {\begingroup
+ \showcomposition
+ \showstruts\tracepositionstrue \tracingparagraphs\maxdimen
+ \appendtoksonce\showpardata\let\showpardata\relax\to\everypar}
+
+\def\stopshowpardata
+ {\endgraf
+ \endgroup}
+
+% \defineXMLenvironment[showpardata] \startshowpardata \stopshowpardata
+% \defineXMLsingular [showpardata] \showpardata
+
+% defaults
+
+\def\raggedfillamount {1fil}
+\def\raggedhalffillamount{.5fil}
+\def\raggedspaceamount {\interwordspace} % {.3333em}
+\def\raggedxspaceamount {.5em}
+
+\def\notragged
+ {\chardef\raggedstatus\zerocount
+ \leftskip 1\leftskip
+ \rightskip 1\rightskip
+ \spaceskip \zeropoint
+ \xspaceskip \zeropoint
+ \parfillskip\zeropoint\!!plus\raggedfillamount\relax
+ \let\updateraggedskips\relax} % new
+
+\let\forgetragged\notragged
+
+\def\raggedleft
+ {\setraggedness\leftraggedness
+ \setraggedskips1\leftraggedness\zeropoint\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+\def\raggedcenter
+ {\setraggedness\middleraggedness
+ \setraggedskips2\middleraggedness\middleraggedness\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+%D We used to have:
+%D
+%D \starttyping
+%D \def\raggedright
+%D {\setraggedness\rightraggedness
+%D \setraggedskips{3}{0em}{\rightraggedness}{.3333em}{.5em}{0em}{\parindent}}
+%D \stoptyping
+%D
+%D However, the next alternative, suggested by Taco, is better.
+
+\def\raggedright
+ {\setraggedness\rightraggedness
+ \setraggedskips3\zeropoint\rightraggedness\raggedspaceamount
+ \raggedxspaceamount\raggedfillamount\parindent}
+
+\def\veryraggedleft
+ {\setraggedskips1\raggedfillamount\zeropoint\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+%D When we want the last line to have a natural width:
+%D
+%D \starttyping
+%D \def\veryraggedleft%
+%D {\setraggedskips{1}{1fil}{0em}{.3333em}{.5em}{0em}{-1fil}}
+%D \stoptyping
+%D
+%D but this one is not accepted by the macros.
+
+\def\veryraggedcenter
+ {\setraggedskips2\raggedfillamount\raggedfillamount\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+\def\veryraggedright
+ {\setraggedskips3\zeropoint\raggedfillamount\raggedspaceamount
+ \raggedxspaceamount\zeropoint\parindent}
+
+\def\ttraggedright
+ {\tttf
+ \setraggedskips3\zeropoint\rightraggedness
+ \zeropoint\zeropoint\zeropoint\parindent} % \ctxparindent
+
+%D A bonus one:
+
+\def\raggedwidecenter
+ {\setraggedness\middleraggedness
+ \setraggedskips2\raggedhalffillamount\raggedhalffillamount
+ \raggedspaceamount\raggedxspaceamount\zeropoint\zeropoint}
+
+\newif\if@@asragged \@@asraggedtrue % old method
+
+% todo
+%
+% \setuplayout[grid=yes,lines=44] \showgrid
+% \starttext
+% test \vfill test \endgraf \strut \endgraf \vskip-\lineheight \removedepth \pagina test
+% \stoptext
+
+% \setupalign[reset,new,right,old]
+
+\def\@@align@@rl{\if!!donea\veryraggedleft \else\raggedleft \fi}
+\def\@@align@@rr{\if!!donea\veryraggedright \else\raggedright \fi}
+\def\@@align@@rc{\if!!donea\veryraggedcenter\else\raggedcenter\fi}
+
+\setvalue{@@ngila@@\v!broad }{\!!doneatrue}
+\setvalue{@@ngila@@\v!wide }{\!!donebtrue}
+
+\def\installalign#1#2{\setvalue{@@align@@#1}{#2}} % can be used for overloads
+
+\installalign \v!new {\@@asraggedfalse}
+\installalign \v!old {\@@asraggedtrue}
+\installalign \empty {}
+
+\installalign \v!line {\baselinebottom}
+\installalign \v!bottom {\raggedbottom}
+\installalign \v!height {\normalbottom}
+\installalign \v!width {\notragged}
+\installalign \v!normal {\notragged}
+\installalign \v!yes {\notragged}
+\installalign \v!no {\raggedright}
+\installalign \v!inner {\if@@asragged \setraggedparagraphmode\@@align@@rl\@@align@@rr \else
+ \setraggedparagraphmode\@@align@@rr\@@align@@rl \fi}
+\installalign \v!outer {\if@@asragged \setraggedparagraphmode\@@align@@rr\@@align@@rl \else
+ \setraggedparagraphmode\@@align@@rl\@@align@@rr \fi}
+\installalign \v!left {\if@@asragged\@@align@@rl\else\@@align@@rr\fi}
+\installalign \v!right {\if@@asragged\@@align@@rr\else\@@align@@rl\fi}
+\installalign \v!middle {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
+\installalign \v!flushleft {\if!!donea\veryraggedright \else\raggedright\fi}
+\installalign \v!flushright {\if!!donea\veryraggedleft \else\raggedleft \fi}
+\installalign \v!flushouter {\setraggedparagraphmode\raggedleft\raggedright}
+\installalign \v!flushinner {\setraggedparagraphmode\raggedright\raggedleft}
+\installalign \v!center {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
+\installalign \v!hanging {\enableprotruding}
+\installalign \v!nothanging {\disableprotruding}
+\installalign \v!hz {\enableadjusting}
+\installalign \v!nohz {\disableadjusting}
+\installalign \v!spacing {\enablespacehandling \enablekernhandling}
+\installalign \v!nospacing {\disablespacehandling\disablekernhandling}
+\installalign \v!hyphenated {\dohyphens}
+\installalign \v!nothyphenated {\nohyphens}
+\installalign \v!new {\@@asraggedfalse} % so new will give you consistency
+\installalign \v!reset {\notragged\normalbottom}
+
+\installalign \v!tolerant {\tolerance3000 \relax}
+\installalign \v!verytolerant {\tolerance4500 \relax}
+\installalign \v!stretch {\emergencystretch\bodyfontsize}
+
+\newcount\hyphenminoffset
+
+\ifx\sethyphenationvariables\undefined \let\sethyphenationvariables\relax \fi
+
+\def\lesshyphens
+ {\advance\hyphenminoffset\plusone
+ \sethyphenationvariables}
+
+\def\morehyphens
+ {\ifcase\hyphenminoffset \else
+ \advance\hyphenminoffset\minusone
+ \fi
+ \sethyphenationvariables}
+
+\installalign \v!lesshyphenation {\lesshyphens}
+\installalign \v!morehyphenation {\morehyphens}
+
+\def\dodosetupalign#1{\csname @@align@@#1\endcsname}
+\def\dodosetupngila#1{\csname @@ngila@@#1\endcsname}
+
+\def\setupalign
+ {\dosingleargument\dosetupalign}
+
+\def\dosetupalign[#1]% can be made faster by checking for defined #1
+ {\!!doneafalse
+ \!!donebfalse
+ \processcommacommand[#1]\dodosetupngila
+ \processcommacommand[#1]\dodosetupalign}
+
+% \setupalign[flushleft] \input ward \par % lijnlinks
+% \setupalign[right] \input ward \par
+
+% \setupalign[flushright] \input ward \par % lijnrechts
+% \setupalign[left] \input ward \par
+
+% \setupalign[middle] \input ward \par % centreer
+% \setupalign[center] \input ward \par
+
+\def\startalignment
+ {\bgroup
+ \setupalign}
+
+\def\stopalignment
+ {\par
+ \egroup}
+
+\chardef\alignstrutmode=1
+
+% see later for the real definition, which in the simple case is:
+
+\newtoks \everyleftofalignedline
+\newtoks \everyrightofalignedline
+
+\def\shiftalignedline#1#2#3#4% left, right, inner, outer
+ {\rightorleftpageaction
+ {\everyleftofalignedline {\hskip\dimexpr#1+#3\relax}%
+ \everyrightofalignedline{\hskip\dimexpr#2+#4\relax}}
+ {\everyleftofalignedline {\hskip\dimexpr#1+#4\relax}%
+ \everyrightofalignedline{\hskip\dimexpr#2+#3\relax}}}
+
+% \def\doalignline#1#2% \\ == newline
+% {\begingroup
+% \setlocalhsize % new
+% \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}%
+% \dowithnextbox
+% {\noindentation % was \noindent
+% \dontleavehmode % added in marrakesch at TUG 2006
+% \hbox to \localhsize
+% {\ifcase\alignstrutmode\or\strut\fi
+% \the\everyleftofalignedline
+% #1\unhbox\nextbox#2\relax
+% \the\everyrightofalignedline}%
+% \endgroup}
+% \hbox}
+
+\def\doalignline#1#2% \\ == newline
+ {\noindentation % was \noindent
+ \dontleavehmode % added in marrakesch at TUG 2006\begingroup
+ \begingroup
+ \setlocalhsize % new
+ \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}%
+ \dowithnextbox
+ {\hbox to \localhsize
+ {\ifcase\alignstrutmode\or\strut\fi
+ \the\everyleftofalignedline
+ #1\unhbox\nextbox#2\relax
+ \the\everyrightofalignedline}%
+ \endgroup}
+ \hbox}
+
+% plain commands
+
+\ifx\undefined\line \def\line {\hbox to\hsize} \fi
+\ifx\undefined\leftline \def\leftline #1{\line{#1\hss}} \fi
+\ifx\undefined\rightline \def\rightline #1{\line{\hss#1}} \fi
+\ifx\undefined\centerline \def\centerline#1{\line{\hss#1\hss}} \fi
+
+% directe commando's
+
+\def\leftaligned {\doalignline \relax \hss }
+\def\midaligned {\doalignline \hss \hss }
+\def\rightaligned{\doalignline \hss \relax}
+
+\let\centeraligned\midaligned
+
+\def\regelbegrensd#1{\limitatetext{#1}{\hsize}{\unknown}} % to be translated
+
+% indirecte commando's
+
+\letvalue{\s!do\v!line\v!left }\leftaligned
+\letvalue{\s!do\v!line\v!right }\rightaligned
+\letvalue{\s!do\v!line\v!middle }\midaligned
+\letvalue{\s!do\v!line\v!flushleft }\rightaligned
+\letvalue{\s!do\v!line\v!flushright}\leftaligned
+\letvalue{\s!do\v!line\v!center }\midaligned
+
+\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
+
+%D Experimental:
+
+% simple version
+%
+% \def\doxalignline#1#2%
+% {\bgroup
+% \setlocalhsize
+% \def\\{\egroup\par\doxalignline{#1}{#2}\bgroup}% inefficient
+% \dowithnextbox
+% {\noindent\hbox to \localhsize
+% {\ifcase\alignstrutmode\or\strut\fi
+% \signalrightpage
+% \doifrightpageelse{#1\unhbox\nextbox#2}{#2\unhbox\nextbox#1}}%
+% \egroup}
+% \hbox}
+%
+% \setvalue{\s!do\v!regel\v!binnen}{\doxalignline\relax\hss}
+% \setvalue{\s!do\v!regel\v!buiten}{\doxalignline\hss\relax}
+%
+% more extensive:
+
+\def\doxalignline#1#2#3#4#5#6%
+ {\noindentation % was \noindent
+ \dontleavehmode % added in marrakesch at TUG 2006\begingroup
+ \begingroup
+ \setlocalhsize
+ \def\\{\egroup\par\doxalignline#1#2#3#4#5#6\bgroup}% inefficient
+ \dowithnextbox
+ {%\noindent moved up
+ \hbox to \localhsize
+ {#1\hskip\ifdone#2\else#3\fi#4%
+ \hbox to \localhsize
+ {\the\everyleftofalignedline
+ \ifcase\alignstrutmode\or\strut\fi
+ \ifdone#5\unhbox\nextbox#6\else#6\unhbox\nextbox#5\fi
+ \the\everyrightofalignedline}%
+ \hss}%
+ \endgroup}
+ \hbox}
+
+\def\doxcheckline
+ {\signalrightpage\doifrightpageelse\donetrue\donefalse}
+
+\setvalue{\s!do\v!line\v!inner }{\doxalignline\doxcheckline++\zeropoint \relax\hss }
+\setvalue{\s!do\v!line\v!outer }{\doxalignline\doxcheckline++\zeropoint \hss \relax}
+\setvalue{\s!do\v!line\v!innermargin}{\doxalignline\doxcheckline-+\innermargintotal\relax\hss }
+\setvalue{\s!do\v!line\v!outermargin}{\doxalignline\doxcheckline+-\outermargintotal\hss \relax}
+\setvalue{\s!do\v!line\v!inneredge }{\doxalignline\doxcheckline-+\inneredgetotal \relax\hss }
+\setvalue{\s!do\v!line\v!outeredge }{\doxalignline\doxcheckline+-\outeredgetotal \hss \relax}
+\setvalue{\s!do\v!line\v!backspace }{\doxalignline\doxcheckline-+\backspace \relax\hss }
+\setvalue{\s!do\v!line\v!cutspace }{\doxalignline\doxcheckline+-\cutspace \hss \relax}
+
+\setvalue{\s!do\v!line\v!leftmargin }{\doxalignline\donefalse --\leftmargintotal \hss \relax}
+\setvalue{\s!do\v!line\v!rightmargin}{\doxalignline\donefalse ++\rightmargintotal\relax\hss }
+\setvalue{\s!do\v!line\v!leftedge }{\doxalignline\donefalse --\leftedgetotal \hss \relax}
+\setvalue{\s!do\v!line\v!rightedge }{\doxalignline\donefalse ++\rightedgetotal \relax\hss }
+
+% ! ! ! beware, redefining \doalignline gives the wrong results ! ! !
+%
+% \def\doalignline{\doxalignline\donefalse++\zeropoint}
+
+%D Better:
+
+\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
+
+% \def\alignedline#1#2% setting default
+% {\csname
+% \s!do\v!line
+% \ifundefined{\s!do\v!line#1}#2\else#1\fi
+% \endcsname}
+
+\def\alignedline#1#2% setting default
+ {\csname\s!do\v!line\ifcsname\s!do\v!line#1\endcsname#1\else#2\fi\endcsname}
+
+%D ...
+
+\def\dosetuptolerance[#1]%
+ {\doifinsetelse\v!vertical{#1}%
+ {\ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!verystrict=>\def\bottomtolerance{},
+ \v!strict=>\def\bottomtolerance{.050},
+ \v!tolerant=>\def\bottomtolerance{.075},
+ \v!verytolerant=>\def\bottomtolerance{.100}]}%
+ {\ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!stretch=>\emergencystretch\bodyfontsize,
+ \v!space=>\spaceskip.5em\!!plus.25em\!!minus.25em\relax,
+ \v!verystrict=>\tolerance 200,
+ \v!strict=>\tolerance1500,
+ \v!tolerant=>\tolerance3000,
+ \v!verytolerant=>\tolerance4500]}}
+
+\def\setuptolerance
+ {\dosingleargument\dosetuptolerance}
+
+% \def\woordrechts
+% {\groupedcommand{\hfill\hbox}{\parfillskip\zeropoint}}
+
+% beware: \wordright{whatever\kern-\rightskip} should work!
+% so, no funny boxing here
+
+\def\dowordright[#1]%
+ {% don't change
+ \groupedcommand
+ {\removeunwantedspaces
+ \hfill
+ \allowbreak % changed back from \hskip\zeropoint
+ \strut
+ \hfill
+ \quad % decent spacing
+ \hbox}
+ {\doifelse{#1}\v!right{\kern-\rightskip}{\doifsomething{#1}{\kern-#1}}%
+ \parfillskip\zeropoint
+ %\finalhyphendemerits\zerocount % yes or no
+ \par}}
+
+\def\wordright
+ {\dosingleempty\dowordright}
+
+% \dorecurse{5}{something } \wordright{--someone} \endgraf
+% \dorecurse{6}{something } \wordright{--someone} \endgraf
+% \dorecurse{7}{something } \wordright{--someone} \endgraf
+%
+% \dorecurse{5}{something } \wordright{--someone else entirely} \endgraf
+% \dorecurse{6}{something } \wordright{--someone else entirely} \endgraf
+% \dorecurse{7}{something } \wordright{--someone else entirely} \endgraf
+%
+% \wordright[\rightskip]{whatever}
+
+% \simplealignedbox{2cm}{right}{x}
+
+\setvalue{\s!simple\c!align\v!right }#1#2{\hbox to #1{#2\hss}}
+\setvalue{\s!simple\c!align\v!left }#1#2{\hbox to #1{\hss#2}}
+\setvalue{\s!simple\c!align\v!flushright }#1#2{\hbox to #1{\hss#2}}
+\setvalue{\s!simple\c!align\v!flushleft }#1#2{\hbox to #1{#2\hss}}
+\setvalue{\s!simple\c!align\v!middle }#1#2{\hbox to #1{\hss#2\hss}}
+
+\def\simplealignedbox#1{\executeifdefined{\s!simple\c!align#1}{\getvalue{\s!simple\c!align\v!right}}}
+
+%D \macros
+%D {pushindentation,popindentation}
+%D
+%D The pushing and popping is done by:
+
+\newbox\indentationboxA
+\newbox\indentationboxB
+
+\def\pushindentation
+ {\bgroup
+ \ifhmode
+ \unskip
+ \setbox\indentationboxA\lastbox % get \strut if present
+ \unskip
+ \setbox\indentationboxB\lastbox % get \indent generated box
+ \unskip
+ \else
+ \hskip\zeropoint % switch to horizontal mode
+ \unskip
+ \setbox\indentationboxA\lastbox % get \indent generated box
+ \setbox\indentationboxB\emptybox
+ \fi}
+
+\def\popindentation
+ {\box\indentationboxB\box\indentationboxA % put back the boxes
+ \egroup}
+
+%D The only complication lays in \type{\strut}. In \PLAIN\
+%D \TEX\ a \type{\strut} is defined as:
+%D
+%D \starttyping
+%D \def\strut%
+%D {\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+%D \stoptyping
+%D
+%D But what is a \type{\strut}? Normally it's a rule of width
+%D zero, but when made visual, it's a rule and a negative skip.
+%D The mechanism for putting things in the margins described
+%D here cannot handle this situation very well. One
+%D characteristic of \type{\strut} is that the \type{\unhcopy}
+%D results in entering horizontal mode, which in return leads
+%D to some indentation.
+%D
+%D To serve our purpose a bit better, the macro \type{\strut}
+%D can be redefined as:
+%D
+%D \starttyping
+%D \def\strut
+%D {\relax\ifmmode\else\hskip0pt\fi\copy\strutbox}
+%D \stoptyping
+%D
+%D Or more compatible:
+%D
+%D \starttyping
+%D \def\strut
+%D {\relax\ifmmode
+%D \copy\strutbox
+%D \else
+%D \bgroup\setbox\strutbox=\normalhbox{\box\strutbox}\unhcopy\strutbox\egroup
+%D \fi}
+%D \stoptyping
+%D
+%D In \CONTEXT\ however we save some processing time by putting
+%D an extra \type{\hbox} around the \type{\strutbox}.
+
+% moved from page-lin.tex to here (due to visualization added
+% in august 2003)
+%
+% \unexpanded \def\crlf
+% {\ifhmode\unskip\else\strut\fi\ifcase\raggedstatus\hfil\fi\break}
+
+\unexpanded \def\crlf
+ {\ifhmode
+ \unskip
+ \prewordbreak\crlfplaceholder
+ \ifcase\raggedstatus\hfil\or\or\or\hfil\fi
+ \break
+ \else
+ \crlfplaceholder
+ \endgraf
+ \fi}
+
+\def\crlfplaceholder
+ {\strut}
+
+\def\settestcrlf
+ {\def\crlfplaceholder
+ {\hbox to \zeropoint
+ {\strut{\infofont\kern.25em}\lohi{\infofont CR}{\infofont LF}\hss}}}
+
+%D \starttyping
+%D % \setuplayout[gridgrid=yes] \showgrid
+%D
+%D \startbuffer
+%D test 1\crlf
+%D test 2\crlf
+%D
+%D \crlf test 3
+%D
+%D test 4\crlf
+%D test 5
+%D
+%D \crlf
+%D \crlf
+%D \crlf
+%D test 6
+%D \stopbuffer
+%D
+%D \hbox
+%D {\hsize5em
+%D \ruledvtop{\getbuffer}\enspace
+%D \ruledvtop{\showstruts\getbuffer}\enspace
+%D \hsize15em \setuptyping[before=,after=]%
+%D \ruledvtop{\typebuffer}}
+%D \stoptyping
+
+\def\opeenregel % to be used grouped
+ {\def\crlf{\removelastspace\space}\let\\\crlf}
+
+\def\showstruts
+ {\setteststrut
+ \settestcrlf}
+
+\def\definehspace
+ {\dotripleempty\dodefinehspace}
+
+\def\dodefinehspace[#1][#2][#3]% #1 = optional namespace
+ {\ifthirdargument
+ \setvalue{\??hs#1:#2}{#3}%
+ \else
+ \setvalue{\??hs:#1}{#2}%
+ \fi}
+
+\unexpanded\def\hspace
+ {\dodoubleempty\dohspace}
+
+%\def\dohspace[#1][#2]%
+% {\ifhmode
+% \removeunwantedspaces
+% \hskip
+% \ifsecondargument
+% \hspaceamount{#1}{#2}%
+% \else
+% \hspaceamount\empty{\iffirstargument#1\else\s!default\fi}%
+% \fi
+% \expandafter\ignorespaces
+% \fi}
+
+\def\dohspace[#1][#2]%
+ {\ifsecondargument
+ \dodohspace[#1][#2]%
+ \else\iffirstargument
+ \hspace[][#1]%
+ \else
+ \hspace[][\s!default]%
+ \fi\fi}
+
+% \def\dodohspace[#1][#2#3]%
+% {\ifhmode
+% \removeunwantedspaces
+% \doifelse{#2}{-}
+% {{\scratchskip\hspaceamount{#1}{#3}\hskip-\scratchskip}}
+% {\hskip\hspaceamount{#1}{#2#3}}%
+% \expandafter\ignorespaces
+% \fi}
+%
+% not needed, tex handles -- as +
+
+\def\dodohspace[#1][#2]%
+ {\ifhmode
+ \removeunwantedspaces
+ \hskip\hspaceamount{#1}{#2}%
+ \expandafter\ignorespaces
+ \fi}
+
+\def\hspaceamount#1#2%
+ {\executeifdefined{\??hs#1:#2}{\executeifdefined{\??hs:#2}\zeropoint}}
+
+\definehspace [\v!small] [.25\emspaceamount]
+\definehspace [\v!medium] [.5\emspaceamount]
+\definehspace [\v!big] [1\emspaceamount]
+\definehspace [\v!normal] [1\spaceamount]
+\definehspace [\v!default] [\spaceamount]
+
+%D Taken from Taco's math module (cq. \AMS\ macros), but
+%D adapted to \type {\hspace}:
+
+\unexpanded\def\textormathspace#1#2#3%
+ {\ifmmode\mskip#1#2\else\kern#1\hspaceamount\empty{#3}\fi\relax}
+
+\newmuskip\hairmuskip \hairmuskip=.15mu
+
+\def\hairspace {\textormathspace+\hairmuskip{.5}}
+\def\thinspace {\textormathspace+\thinmuskip 1}
+\def\medspace {\textormathspace+\medmuskip 2}
+\def\thickspace {\textormathspace+\thickmuskip3}
+\def\neghairspace {\textormathspace-\thinmuskip{.5}}
+\def\negthinspace {\textormathspace-\thinmuskip 1}
+\def\negmedspace {\textormathspace-\medmuskip 2}
+\def\negthickspace{\textormathspace-\thickmuskip3}
+
+% needed for unicode:
+
+\def\twoperemspace {\hskip\dimexpr\emwidth/2\relax} % == \enspace
+\def\threeperemspace {\hskip\dimexpr\emwidth/3\relax}
+\def\fourperemspace {\hskip\dimexpr\emwidth/4\relax}
+\def\fiveperemspace {\hskip\dimexpr\emwidth/5\relax} % goodie
+\def\sixperemspace {\hskip\dimexpr\emwidth/6\relax}
+\def\figurespace {\begingroup\setbox\scratchbox\hbox{0}\hskip\wd\scratchbox\endgroup} % there is a command for this
+\def\punctuationspace {\begingroup\setbox\scratchbox\hbox{.}\hskip\wd\scratchbox\endgroup}
+\def\ideographicspace {\hskip\dimexpr\emwidth/1\relax}
+\def\ideographichalffillspace{\hskip\dimexpr\emwidth/2\relax}
+%def\nobreakspace {\penalty\plustenthousand\space}
+\def\nobreakspace {\penalty\plustenthousand\kern\interwordspace}
+\def\narrownobreakspace {\penalty\plustenthousand\thinspace}
+%def\zerowidthnobreakspace {\penalty\plustenthousand\hskip\zeropoint}
+\def\zerowidthnobreakspace {\penalty\plustenthousand\kern\zeropoint}
+\def\zerowidthspace {\hskip\zeropoint}
+
+\definehspace[.5][.1250\emspaceamount] % could also be [.1250\spaceamount]
+\definehspace[1] [.1667\emspaceamount]
+\definehspace[2] [.2222\emspaceamount]
+\definehspace[3] [.2777\emspaceamount]
+
+\let \, \thinspace
+\let \: \medspace
+\let \; \thickspace
+\let \! \negthinspace
+
+% this will become an alternative bunch of \blank settings
+%
+% \startlines
+% \scratchskip=.23pt plus 10pt minus 4pt \relax \number\scratchskip \space \the\scratchskip
+% \setsimplifiedskip\scratchskip1 \number\scratchskip \space \the\scratchskip
+% \setsimplifiedskip\scratchskip2 \number\scratchskip \space \the\scratchskip
+% \getsimplifiedskip\scratchskip\scratchcounter \number\scratchcounter
+% \stoplines
+%
+% \hrule width10cm \endgraf
+% \discardedskip{10pt}
+% \retainedskip {4pt}
+% \discardedskip {5pt}
+% \hrule width10cm \endgraf
+% \blockedskip{0pt}
+% \discardedskip{10pt}
+% \retainedskip {4pt}
+% \discardedskip {5pt}
+% \hrule width10cm \endgraf
+% \frozenskip {4cm}
+% \hrule width10cm \endgraf
+% \vskip10pt
+% \hrule width10cm \endgraf
+
+% ! ! ! etex only, evt splitskip macro gebruiken (syst-new)
+
+\newskip\simplifiedskip
+\newskip\simplifiedcounter
+
+\chardef\@@discardedskip1
+\chardef\@@retainedskip 2
+\chardef\@@forcedskip 3
+\chardef\@@blockedskip 4
+\chardef\@@frozenskip 5 % after heads, no break
+
+\def\setsimplifiedskip#1#2%
+ {#1\dimexpr(10\dimexpr(#1/10)) plus \gluestretch#1 minus \glueshrink#1\relax
+ \advance#1\numexpr(#2)sp\relax}
+
+\def\getsimplifiedskip#1#2%
+ {\simplifiedskip#1\relax
+ \ifzeropt\simplifiedskip % \ifdim\simplifiedskip=\zeropoint
+ #2\zerocount
+ \else
+ \simplifiedcounter\dimexpr10\dimexpr#1/10\relax\relax
+ \advance\simplifiedskip-\simplifiedcounter
+ #2\number\simplifiedskip\relax
+ \fi}
+
+\def\conditionalskip#1#2%
+ {\scratchskip#1\relax
+ \setsimplifiedskip\scratchskip#2\relax
+ \vskip\scratchskip\relax}
+
+\def\defrostskip
+ {\scratchskip\lastskip\penalty50000\normalvskip-\scratchskip\penalty50000\relax}
+
+\def\frozenskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \fi}
+
+\def\discardedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@discardedskip
+ \or % discard
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@discardedskip
+ \fi
+ \or % retain
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@discardedskip
+ \fi
+ \or % forced
+ \conditionalskip{#1}\@@discardedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+\def\retainedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@retainedskip
+ \or % discard
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@retainedskip
+ \or % retain
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@retainedskip
+ \fi
+ \or % forced
+ \conditionalskip{#1}\@@retainedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+\def\forcedskip#1%
+ {\endgraf
+ \ifvmode
+ \conditionalskip{#1}\@@forcedskip
+ \fi}
+
+\def\blockedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@blockedskip
+ \or % discard
+ \conditionalskip{#1}\@@blockedskip
+ \or % retain
+ \conditionalskip{#1}\@@blockedskip
+ \or % forced
+ \conditionalskip{#1}\@@blockedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+% beware, changing this will break some code (like pos/backgrounds)
+
+\newtoks\everyfirstparagraphintro
+\newtoks\everynextparagraphintro
+\newtoks\@@everyparagraphtoks
+
+\chardef\everyparagraphintro\zerocount
+
+\def\setupparagraphintro
+ {\dodoubleempty\dosetupparagraphintro}
+
+\def\dosetupparagraphintro[#1][#2]%
+ {\processallactionsinset
+ [#1]
+ [ \v!reset=>\global\chardef\everyparagraphintro\zerocount
+ \global\everyfirstparagraphintro\emptytoks
+ \global\everynextparagraphintro \emptytoks,
+ \v!first=>\global\chardef\everyparagraphintro\plusone
+ \doglobal\appendtoks#2\to\everyfirstparagraphintro,
+ \v!next=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plusone\fi
+ \doglobal\appendtoks#2\to\everynextparagraphintro,
+ \v!each=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plustwo\fi
+ \doglobal\appendtoks#2\to\everyfirstparagraphintro
+ \doglobal\appendtoks#2\to\everynextparagraphintro]}
+
+%D We can say:
+%D
+%D \starttyping
+%D \setupparagraphintro[first][\index{Knuth}]
+%D \stoptyping
+%D
+%D Maybe more convenient is:
+%D
+%D \starttyping
+%D \flushatparagraph{\index{Zapf}}
+%D \stoptyping
+
+\def\flushatparagraph#1%
+ {\global\chardef\everyparagraphintro\plusone
+ \global\appendtoks{#1}\to\everyfirstparagraphintro}
+
+% \def\doinsertparagraphintro
+% {\ifcase\everyparagraphintro\relax
+% % no data
+% \@@everyparagraphtoks\emptytoks
+% \or
+% % first data
+% \global\chardef\everyparagraphintro\plustwo
+% \@@everyparagraphtoks\everyfirstparagraphintro
+% \global\everyfirstparagraphintro\emptytoks
+% \or
+% % next data
+% \@@everyparagraphtoks\everynextparagraphintro
+% \fi
+% \the\@@everyparagraphtoks}
+
+\def\doinsertparagraphintro
+ {\begingroup
+ \everypar\emptytoks
+ \ifcase\everyparagraphintro\relax
+ % no data
+ \@@everyparagraphtoks\emptytoks
+ \or
+ % first data
+ \global\chardef\everyparagraphintro\plustwo
+ \@@everyparagraphtoks\everyfirstparagraphintro
+ \global\everyfirstparagraphintro\emptytoks
+ \or
+ % next data
+ \@@everyparagraphtoks\everynextparagraphintro
+ \fi
+ \the\@@everyparagraphtoks
+ \endgroup}
+
+\def\insertparagraphintro
+ {\ifcase\everyparagraphintro\else\@EA\doinsertparagraphintro\fi}
+
+% \appendtoksonce\insertparagraphintro\to\everypar % should come last
+
+%D \starttyping
+%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
+%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
+%D \setupparagraphintro[next] [\hbox to 3.5em{\tt NEXT \hss}]
+%D \setupparagraphintro[next] [\hbox to 3.5em{\tt TXEN \hss}]
+%D \setupparagraphintro[each] [\hbox to 3.0em{\tt EACH \hss}]
+%D \setupparagraphintro[each] [\hbox to 3.0em{\tt HCEA \hss}]
+%D
+%D some paragraph \par
+%D some paragraph \par
+%D some paragraph \par
+%D
+%D \definelabel[parnumber]
+%D
+%D \setupparagraphintro[reset,each][\inleft{\slxx\parnumber}]
+%D
+%D some paragraph \par
+%D some paragraph \par
+%D some paragraph \par
+%D \stoptyping
+
+%D \macros
+%D {flushatnextpar}
+%D
+%D This macro collects data that will be flushed at the next paragraph.
+%D By using this macro you can avoid interfering nodes (writes, etc).
+
+\newbox \postponednodedata
+
+\def\flushatnextpar
+ {\bgroup
+ \dowithnextbox
+ {\global\setbox\postponednodedata\hbox{\box\postponednodedata\box\nextbox}\egroup}%
+ \hbox}
+
+\def\flushpostponednodedata
+ {\ifvoid\postponednodedata\else
+ \hbox{\smashedbox\postponednodedata}%
+ \fi}
+
+% Very nasty but needed for margin stuff inside colored
+% paragraphs.
+
+\let\normalvadjust\vadjust
+
+% \def\graphicvadjust % bad, those low level color calls here
+% {\dowithnextbox
+% {\normalvadjust
+% {\dostartgraphicgroup
+% \localstarttextcolor
+% \unvbox\nextbox
+% \localstoptextcolor
+% \dostopgraphicgroup}}%
+% \vbox}
+
+% test this prikkels/pascal margin text before heads (mode
+% 1) as well as uitwerkingen (mode 2)
+
+%chardef\graphicvadjustmode=0 % fake
+%chardef\graphicvadjustmode=1 % normal
+\chardef\graphicvadjustmode=2 % normal + compensate (== default)
+
+\def\graphicvadjust % bad, those low level color calls here
+ {\dowithnextboxcontent
+ {\forgetall}
+ {\ifcase\graphicvadjustmode \@EA \fakedvadjust \else \@EA\normalvadjust \fi
+ {\dostartgraphicgroup % don't ask
+ \localstarttextcolor
+ \unvbox\nextbox
+ \localstoptextcolor % don't ask
+ \dostopgraphicgroup
+ \ifcase\graphicvadjustmode \or \or
+ % corrects for one line paragraphs
+ \nointerlineskip
+ \kern-\struttotal
+ \nointerlineskip
+ \verticalstrut
+ \fi}}%
+ \vbox}
+
+%D This works only in a properly strutted line, and is meant
+%D for deeply burried operations, like in heads.
+
+\def\fakedvadjust
+ {\dowithnextbox
+ {\setbox\nextbox\hbox{\llap{\lower\strutdepth\box\nextbox}}%
+ \smashedbox\nextbox}%
+ \vtop}
+
+\def\flexiblespaceamount#1#2#3%
+ {#1\interwordspace
+ \!!plus#2\interwordstretch
+ \!!minus#3\interwordshrink}
+
+\def\fixedspaceamount#1%
+ {#1\interwordspace}
+
+%D This is a dangerous feature because it makes the \TEX\ source
+%D less portable, i.e. any parser now needs to apply exactly the
+%D same algorithm when it wants to interpret the source. We
+%D strongly recommend not to mention this feature in manuals! It's
+%D provided for users who are hooked to such a mechanism.
+%D
+%D \starttyping
+%D \setupsorting[logo][next=\autoinsertnextspace] \logo[TEX]{\TeX}
+%D
+%D bla bla \TEX bla bla \TEX (bla) bla (\TEX)
+%D \stoptyping
+
+\def\autoinsertnextspace{\futurelet\nexttoken\doautoinsertnextspace}
+
+\def\doautoinsertnextspace % slightly extended version of a user supplied macro
+ {\ifx\nexttoken \bgroup\else \ifx\nexttoken\begingroup\else
+ \ifx\nexttoken \egroup\else \ifx\nexttoken \endgroup\else
+ \ifx\nexttoken \/\else \ifx\nexttoken /\else \ifx\nexttoken ~\else
+ \ifx\nexttoken \ \else \ifx\nexttoken \blankspace\else \ifx\nexttoken \space\else
+ \ifx\nexttoken .\else \ifx\nexttoken ,\else
+ \ifx\nexttoken !\else \ifx\nexttoken ?\else
+ \ifx\nexttoken :\else \ifx\nexttoken ;\else
+ \ifx\nexttoken '\else \ifx\nexttoken "\else
+ \ifx\nexttoken )\else \ifx\nexttoken -\else \ifx\nexttoken |\else
+ \ifx\nexttoken \%\else \ifx\nexttoken \&\else
+ \space
+ \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
+
+% moved from page-lin
+
+\def\installspacehandler#1#2% needs to set \obeyedspace
+ {\setvalue{\??sr#1}{#2}}
+
+\installspacehandler \v!on
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}%
+ \let\ =\obeyedspace}
+
+\installspacehandler \v!yes
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode \normalspace }}%
+ \let\ =\obeyedspace}
+
+\installspacehandler \v!off
+ {\normalspaces
+ \let\obeyedspace\normalspace
+ \let\ =\normalspace}
+
+\installspacehandler \v!fixed
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode\fixedspace}}%
+ \let\ =\obeyedspace}
+
+\def\activatespacehandler#1%
+ {\executeifdefined{\??sr#1}{\activatespacehandler\v!off}}
+
+% moved from page-lin
+
+%D When spacing is active we need to handle commands in
+%D a special way:
+%D
+%D \starttyping
+%D \setuplines[space=on]
+%D
+%D \startlines
+%D Let's talk about this{\ttsl\gobbleoneargument or}that.
+%D \stoplines
+%D
+%D \startlines
+%D Let's talk about this{\getvalue{ttsl}or}that.
+%D \stoplines
+%D \stoptyping
+%D
+%D One can indent in several ways:
+%D
+%D \starttyping
+%D \setupindenting[medium] \setuplines[indenting=odd] % no yes odd even
+%D
+%D \startlines
+%D first
+%D second
+%D third
+%D fourth
+%D \stoplines
+%D \stoptyping
+
+\def\setuplines
+ {\dodoubleargument\getparameters[\??rg]}
+
+\def\startlines
+ {\@@rgbefore
+ \pushmacro\checkindentation
+ \whitespace
+ %\page[\v!preference]} gaat mis na koppen, nieuw: later \nobreak
+ \begingroup
+ \setupindenting[\@@rgindenting]%
+ \typesettinglinestrue
+ \setupwhitespace[\v!none]%
+ \obeylines
+ \ignorespaces
+ \gdef\afterfirstobeyedline % tzt two pass, net als opsomming
+ {\gdef\afterfirstobeyedline
+ {\nobreak
+ \global\let\afterfirstobeyedline\relax}}%
+ \def\obeyedline
+ {\par
+ \afterfirstobeyedline
+ \futurelet\next\dobetweenthelines}%
+ \activatespacehandler\@@rgspace
+ \GotoPar}
+
+\def\stoplines
+ {\endgroup
+ \popmacro\checkindentation
+ \@@rgafter}
+
+\def\dobetweenthelines
+ {\doifmeaningelse\next\obeyedline\@@rginbetween\donothing}
+
+\setuplines
+ [\c!before=\blank,
+ \c!after=\blank,
+ \c!inbetween=\blank,
+ \c!indenting=\v!no,
+ \c!space=\v!default]
+
+\def\emptylines
+ {\dosingleempty\doemptylines}
+
+\def\doemptylines[#1]%
+ {\endgraf\dorecurse{\iffirstargument#1\else3\fi}\crlf}
+
+\setupwhitespace
+ [\v!none]
+
+% still old-fashioned
+
+\indenting
+ [\v!never]
+
+\setupindenting
+ [\v!none]
+
+\setupblank
+ [\v!standard,
+ \v!big]
+
+\defineblank[\v!default] [\currentblank]
+\defineblank[\v!before] [\v!default]
+\defineblank[\v!inbetween][\v!default]
+\defineblank[\v!after] [\v!before]
+
+\setupinterlinespace
+ [\c!minheight=0pt, % only special purpose
+ \c!mindepth=0pt, % only special purpose
+ \c!height=.72,
+ \c!depth=.28,
+ \c!top=1.0,
+ \c!bottom=0.4,
+ \c!distance=1pt,
+ \c!line=2.8ex,
+ \c!stretch=0]
+
+\setupnarrower
+ [\c!before=\endgraf,
+ \c!after=\endgraf,
+ \c!left=1.5em,
+ \c!right=1.5em,
+ \c!middle=1.5em]
+
+\setuptolerance
+ [\v!horizontal,\v!verystrict]
+
+\setuptolerance
+ [\v!vertical,\v!strict]
+
+\setupalign
+ [\v!bottom,
+ \v!width]
+
+\setupspacing
+ [\v!packed]
\protect \endinput
diff --git a/tex/context/base/core-spa.mkiv b/tex/context/base/core-spa.mkiv
index 8c1df68dc..dfb84da53 100644
--- a/tex/context/base/core-spa.mkiv
+++ b/tex/context/base/core-spa.mkiv
@@ -11,289 +11,2794 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Buffers}
+\writestatus{loading}{ConTeXt Core Macros / Spacing}
+
+% to be sorted out: dependencies, order of initialization / also some dutch code here
+% more documentation in the mkii file
\unprotect
-% category:
-%
-% 0 == discard
-% 1 == only if larger
-% 2 == force even if smaller
-% 3 == only take penalty component
-% 4 == add to existing skip
-% 5 == ignore following skips (== disable)
+% some will move to core-var
-% penalty:
+\newif \ifgridsnapping
+\newif \iffuzzyvskip
+\let \fuzzyvskip \gobbleoneargument
+\let \removelastfuzzyvskip \relax
+
+\let \startbaselinecorrection \relax
+\let \stopbaselinecorrection \relax
+\let \baselinecorrection \relax
+\let \offbaselinecorrection \relax
+
+\appendtoks \spacing 1\to \everybodyfont
+\appendtoks \presetnormallineheight \to \everybodyfont
+\appendtoks \setnormalbaselines \to \everybodyfont % check if redundant
+\appendtoks \setstrut \to \everybodyfont % check if redundant
+\appendtoks \settopskip \to \everybodyfont
+\appendtoks \setmaxdepth \to \everybodyfont
+%appendtoks \spacing 1\to \everybodyfont
+\appendtoks \simplesetupindenting \to \everybodyfont
+\appendtoks \simplesetupblank \to \everybodyfont
+\appendtoks \simplesetupwhitespace \to \everybodyfont
+%appendtoks \checknotes \to \everybodyfont % not
+\appendtoks \simplesetupspacing \to \everybodyfont % nieuw
+\appendtoks \setrelativeinterlinespace \to \everybodyfont
+
+\appendtoks \updateraggedskips \to \everyfontswitch % under test
+\prependtoks \let\par\endgraf \to \everypagebody % see \fillinline
+\appendtoks \simplesetupspacing \to \everydefinedfont
+
+% if you want to hyphenate the first word of a paragraph ... \appendtoks\hskip0pt\to\everypar
+
+\def\stelfactorenin
+ {\simplesetupwhitespace
+ \simplesetupblank
+ \settopskip
+ \setmaxdepth}
+
+\def\softbreak
+ {\relax\ifhmode\hskip\parfillskip\break\fi}
+
+\let\poplastnode\relax
+
+\def\pushlastnode
+ {\ifdim\lastskip=\zeropoint
+ \ifnum\lastpenalty=\zerocount
+ \ifnum\lastkern=\zerocount
+ \let\poplastnode\relax
+ \else
+ \edef\poplastnode{\kern\the\lastkern\relax}\kern-\lastkern % untested
+ \fi
+ \else
+ \edef\poplastnode{\penalty\the\lastpenalty\relax}\nobreak % untested
+ \fi
+ \else
+ \edef\poplastnode{\vskip\the\lastskip\relax}\vskip-\lastskip % \removelastskip
+ \fi}
+
+%D The dreadful sequence \type {\bgroup} \unknown\
+%D \type {\carryoverpar} \unknown\ \type {\egroup} is needed
+%D when for instance sidefloats are used in combination with
+%D something that starts with a group. This is because
+%D otherwise the indentation as set (by the output routine)
+%D inside the group are forgotten afterwards. (I must
+%D not forget its existence).
+
+\global\let\carriedoverpar\relax
+
+\def\carryoverpar#1%
+ {\expanded % \scratchtoks{#1}%
+ {\noexpand#1% \the\scratchtoks
+ \hangindent\the\hangindent
+ \hangafter \the\hangafter
+ \parskip \the\parskip
+ \leftskip \the\leftskip
+ \rightskip \the\rightskip}}
+
+%D A quick way to determine left|/|middle|/|right states
+%D (experimental).
+
+\setvalue{\??as\v!left }{0}
+\setvalue{\??as\v!middle}{1}
+\setvalue{\??as\v!right }{2}
+
+\def\setalignmentswitch#1%
+ {\chardef\alignmentswitch0\csname\??as#1\endcsname\relax}
+
+%D There are two ways to influence the interline spacing. The
+%D most general and often most consistent way is using
+%D
+%D \showsetup{setupinterlinespace}
+%D
+%D For instance
+%D
+%D \starttyping
+%D \setupinterlinespace[line=2.8ex]
+%D \stoptyping
+%D
+%D This setting adapts itself to the bodyfontsize, while for
+%D instance saying
+%D
+%D \starttyping
+%D \setupinterlinespace[line=12pt]
+%D \stoptyping
+%D
+%D sets things fixed for all sizes, which is definitely not
+%D what we want. Therefore one can also say:
+%D
+%D \starttyping
+%D \definebodyfontenvironment[9pt][interlinespace=11pt]
+%D \stoptyping
+%D
+%D One can still use \type{\setupinterlinespace} (without
+%D arguments) to set the interline space according to the
+%D current font, e.g. a \type{\bfa}.
+
+\newif\iflocalinterlinespace
+
+% font-ini
+
+\ifx\bodyfontinterlinespecs\undefined
+
+ \let\bodyfontinterlinespecs\empty
+ \let\bodyfontinterlinespace\empty
+
+\fi
+
+\def\presetnormallineheight
+ {\edef\normallineheight{\@@itline}%
+% done elsewhere : \spacing\!!plusone % new per 10/08/2004, else problems in otr / !! needed
+ \iflocalinterlinespace \else
+ \doifdefined\bodyfontinterlinespecs
+ {\doifsomething\bodyfontinterlinespace
+ {\edef\normallineheight{\bodyfontinterlinespace}}}%
+ \fi}
+
+\def\setupspecifiedinterlinespace[#1]%
+ {\getparameters[\??it][#1]%
+ \scratchdimen0\@@itheight\points
+ \advance\scratchdimen 0\@@itdepth\points
+ \ifdim\scratchdimen>\onepoint
+ \showmessage\m!layouts{10}{\@@itheight,\@@itdepth}%
+ \let\@@itheight\strutheightfactor
+ \let\@@itdepth \strutdepthfactor
+ \else
+ \let\strutheightfactor\@@itheight
+ \let\strutdepthfactor \@@itdepth
+ \fi
+ \let\minimumstrutheight \@@itminheight
+ \let\minimumstrutdepth \@@itmindepth
+ \let\minimumlinedistance\@@itdistance
+ \let\normallineheight \@@itline % let ! ! ! ! ! ivm ex
+ \doifelse\@@ittop\v!height % new, topskip does more bad than good
+ {\let\topskipfactor \@@itheight}
+ {\let\topskipfactor \@@ittop }%
+ \let\maxdepthfactor \@@itbottom
+ \let\baselinegluefactor \@@itstretch
+ \setfontparameters % redundant, can be \setstrut, test first
+ \updateraggedskips} % yes indeed
+
+\let\currentrelativeinterlinespace\empty
+
+\def\setuprelativeinterlinespace[#1]%
+ {\processallactionsinset
+ [#1]
+ [ \v!on=>\oninterlineskip,
+ \v!off=>\offinterlineskip,
+ \v!reset=>\let\currentrelativeinterlinespace\empty
+ \let\setrelativeinterlinespace\relax
+ \setfontparameters,
+ \v!auto=>\let\setrelativeinterlinespace\dosetrelativeinterlinespace,
+ \s!unknown=>\assignvalue\commalistelement\currentrelativeinterlinespace{1.00}{1.25}{1.50}%
+ \spacing\currentrelativeinterlinespace]}
+
+\def\dosetrelativeinterlinespace
+ {\ifx\currentrelativeinterlinespace\empty\else
+ \spacing\currentrelativeinterlinespace
+ \fi}
+
+\let\setrelativeinterlinespace\relax
+
+% \appendtoks \setrelativeinterlinespace \to \everybodyfont
+
+\def\complexsetupinterlinespace[#1]% \commalistelement ipv #1
+ {\doifassignmentelse{#1}\setupspecifiedinterlinespace\setuprelativeinterlinespace[#1]}
+
+\def\setuplocalinterlinespace[#1]%
+ {\localinterlinespacetrue
+ \setupinterlinespace[#1]%
+ \localinterlinespacefalse}
+
+\def\simplesetupinterlinespace
+ {\localinterlinespacetrue
+ \setfontparameters
+ \updateraggedskips % funny one here
+ \localinterlinespacefalse}
+
+\definecomplexorsimple\setupinterlinespace
+
+% In earlier versions \type{\bigskipamount} was
+% \type{\ht\strutbox} and the stretch was plus or minus
+% \type{.4\dp\strutbox}. Don't ask me why. The most recent
+% implementation is based on a user supplied distance, which
+% is by default \type{.75\normalskipamount} where
+% \type{\normalskipamount} equals the current baseline
+% distance.
+
+% \lineskiplimit = -\maxdimen -> freezes baselineskip
+
+% can be conditionals
+
+\newif\ifblanknowhite \blanknowhitefalse
+\newif\ifblankindeed \blankindeedfalse
+\newif\ifblankreset \blankresetfalse
+\newif\ifblankdisable \blankdisablefalse
+\newif\ifblankflexible \blankflexibletrue
+\newif\ifblankouter
+\newif\ifblankforce
+\newif\ifblankgoback
+
+\newskip\blankskip \blankskip=\bigskipamount
+\newskip\blankskipamount
+
+\def\skipfactor {.75}
+\def\skipgluefactor{.25}
+
+\def\normalskipamount
+ {\openlineheight
+ \ifgridsnapping \else \ifblankflexible
+ \!!plus \skipgluefactor\openlineheight
+ \!!minus\skipgluefactor\openlineheight
+ \fi \fi
+ \relax}
+
+\def\linedistance {\normalskipamount}
+\def\appliedblankskip{\skipfactor\linedistance}
+\def\lastblankskip {\blankskip}
+\def\currentblank {\v!big}
+\def\oldprevdepth {\prevdepth}
+\def\newprevdepth {-1001pt}
+\def\mindimen {1sp} % was: 0.00002pt
+
+\newif\iflocalblankfixed
+\newif\iflocalblankflexible
+
+\def\geenblanko{\removelastskip} % will become obsolete
+
+%%%% pas op, wordt ook in core-pos gebruikt
+
+\def\doassignsomeskip#1\to#2% ook nog \v!halfline+fuzzysnap
+ {\doifelse{#1}\v!line
+ {#2\openlineheight}
+ {\ifgridsnapping
+ \assigndimension{#1}{#2}{.25\openlineheight}{.5\openlineheight}\openlineheight
+ \else
+ \assigndimension{#1}{#2}\smallskipamount\medskipamount\bigskipamount
+ \fi}%
+ \relax}
+
+% \relax is really needed, else we may loose stretch due to lookahead; somehow
+% this bug was introduced a while ago but somehow went unnoticed; fixed 2/7/2008
+
+\def\addblankskip#1#2#3{\global\advance\blankskip#1\ifgridsnapping#3\else#2\fi\relax}
+
+\def\defineblankmethod[#1]#2{\setvalue{\??bo\??bo#1}{#2}}
+
+\defineblankmethod [\v!big] {\addblankskip+\bigskipamount \openlineheight}
+\defineblankmethod [-\v!big] {\addblankskip-\bigskipamount \openlineheight}
+\defineblankmethod [\v!medium] {\addblankskip+\medskipamount {.5\openlineheight}}
+\defineblankmethod [-\v!medium] {\addblankskip-\medskipamount {.5\openlineheight}}
+\defineblankmethod [\v!small] {\addblankskip+\smallskipamount{.25\openlineheight}}
+\defineblankmethod [-\v!small] {\addblankskip-\smallskipamount{.25\openlineheight}}
+\defineblankmethod [\v!white] {\addblankskip+\parskip \openlineheight}
+\defineblankmethod [-\v!white] {\addblankskip-\parskip \openlineheight}
+\defineblankmethod [\v!line] {\addblankskip+\openlineheight \openlineheight}
+\defineblankmethod [-\v!line] {\addblankskip-\openlineheight \openlineheight}
+
+\defineblankmethod [\v!formula] {\global\advance\blankskip\medskipamount}
+\defineblankmethod [\v!nowhite] {\global\blanknowhitetrue}
+\defineblankmethod [\v!disable] {\global\blankdisabletrue}
+\defineblankmethod [\v!force] {\global\blankforcetrue}
+\defineblankmethod [\v!outer] {\ifvmode\ifinner\blankoutertrue\fi\fi}
+\defineblankmethod [\v!reset] {\global\blankresettrue}
+\defineblankmethod [\v!flexible] {\global\localblankflexibletrue}
+\defineblankmethod [\v!fixed] {\global\localblankfixedtrue}
+\defineblankmethod [\v!back] {\global\blankgobacktrue} % {\geenblanko}
+\defineblankmethod [\v!halfline] {\ifgridsnapping\global\fuzzyvskiptrue\fi
+ \global\advance\blankskip .5\lineheight}
+
+\defineblankmethod [\v!none] {\global\blankresettrue}
+\defineblankmethod [\v!joinedup] {\ifvmode\nointerlineskip\fi}
+
+\defineblankmethod [\v!always] {\redowhitespace} % experimental
+
+% happens often, so we speed this up:
%
-% larger wins
+% \defineblankmethod [2*\v!line] {\addblankskip+{2\openlineheight}{2\openlineheight}}
+% \defineblankmethod [2*\v!big] {\addblankskip+{2\bigskipamount }{2\openlineheight}}
+%
+% no, with 2\whatever we loose the stretch and shrink! Taco's alternative:
-% order:
+\defineblankmethod
+ [2*\v!line]
+ {\addblankskip+\openlineheight\openlineheight
+ \addblankskip+\openlineheight\openlineheight}
+
+\defineblankmethod
+ [2*\v!big]
+ {\addblankskip+\bigskipamount\openlineheight
+ \addblankskip+\bigskipamount\openlineheight}
+
+\def\doblank#1%
+ {\edefconvertedargument\ascii{#1}%
+ \ifx\ascii\empty\else
+ \ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+ \else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
+ \else
+ \dorepeatwithcommand[#1]\redoblank
+ \fi\fi
+ \fi
+ \relax}
+
+\def\redoblank#1%
+ {\edefconvertedargument\ascii{#1}%
+ \ifx\ascii\empty\else
+ \ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+ \else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
+ \else
+ \global\advance\blankskip#1\relax
+ \fi\fi
+ \fi
+ \relax}
+
+\unexpanded\def\blank % the \relax is definitely needed due to the many \if's
+ {\relax\complexorsimple\doblank}
+
+\def\complexdoblank
+ {\flushnotes
+ \ifmmode
+ \@EA\nocomplexdoblank
+ \else
+ \ifopelkaar
+ \ifinpagebody
+ \@EA\@EAEAEA\@EA\docomplexdoblank
+ \else
+ \@EA\@EAEAEA\@EA\nocomplexdoblank
+ \fi
+ \else
+ \@EAEAEA\docomplexdoblank
+ \fi
+ \fi}
+
+\def\nocomplexdoblank[#1]%
+ {% evt blokkeerfalse
+ \ifmmode\else\par\fi}
+
+% Overloaded in cont-new!
+
+\newsignal\noblanksignal
+
+% problem: we cannot look back in the mvl so we need 3 kinds of signals
+
+\def\noblankpsignal{1010101}
+
+\def\inhibitgridblank % was doinhibitblank
+ {\ifvmode\else\endgraf\fi
+ \ifvmode
+ \ifnum\lastpenalty<10000
+ \kern-\noblanksignal % new
+ \kern \noblanksignal
+ \else
+ \penalty\noblankpsignal
+ \fi
+ \fi}
+
+\def\inhibittextblank % was inhibitblank
+ {\endgraf
+ \ifvmode
+ \prevdepth\newprevdepth
+ \fi}
+
+% new macro
%
-% larger wins
+% \def\inhibitblank % need some work
+% {\endgraf
+% \ifvmode
+% \ifgridsnapping
+% \inhibitgridblank
+% \else
+% % this one spoils the grid
+% \inhibittextblank
+% \fi
+% \fi}
-\defineattribute[kern-chars]
+\def\doinhibitblank{\inhibitgridblank}
+\def\inhibitblank {\inhibittextblank}
-\defineattribute[skip-category]
-\defineattribute[skip-penalty]
-\defineattribute[skip-order]
+% will become obsolete
-\defineattribute[snap-category]
+\ifx\undefined\savedlastskip \newskip \savedlastskip \fi
+\ifx\undefined\savedlastpenalty \newcount\savedlastpenalty \fi
-\defineattribute[display-math]
+% beware, prevdepth can have funny values (e.g. mvl value when in box)
-\registerctxluafile{core-spa}{1.001}
+\def\docomplexdoblank[#1]% pas op \relax's zijn nodig ivm volgende \if
+ {\global\blankresetfalse
+ \global\blankdisablefalse
+ \global\blanknowhitefalse
+ \global\localblankflexiblefalse
+ \global\localblankfixedfalse
+ \global\blankforcefalse
+ \global\blankgobackfalse
+ \blankouterfalse
+ \global\blankskip\zeropoint
+%
+\edefconvertedargument\ascii{#1}% todo fast check for simple
+\ifcsname\??bo\??bo\ascii\endcsname % internal def
+ \csname\??bo\??bo\ascii\endcsname
+\else\ifcsname\??bo\ascii\endcsname % user def / slow
+ \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
+\else
+ \expanded{\rawprocesscommalist[#1]}\doblank
+\fi\fi
+%
+ \relax % to be sure
+ \ifdim\blankskip=\zeropoint\relax
+ \iflocalblankflexible
+ \doglobal\advance\blankskip \currentblank
+ \else\iflocalblankfixed
+ \doglobal\advance\blankskip \currentblank
+ \fi\fi
+ \fi
+ \relax % to be sure
+ \ifblankouter
+ % do nothing
+ \else
+ \par
+ \ifvmode
+ \ifblankgoback
+ \ifdim\lastskip>\zeropoint \vskip-\lastskip \fi
+ \savedlastskip\zeropoint
+ \else\ifdim\lastskip>\zeropoint
+ \savedlastskip\lastskip
+ \else % todo: lastnode, dan namelijk geen skip !
+ \savedlastskip\zeropoint
+ \fi\fi
+ \ifblankforce
+ % dit gaat mis in pos fonts
+ % \ifdim\prevdepth>\zeropoint\else ...
+ % -1000pt signals top of page or column (\ejectcolumn)
+ \bgroup\forgeteverypar\verticalstrut\egroup\kern-\struttotal
+ \savedlastskip\zeropoint
+ \fi
+ \savedlastpenalty\lastpenalty % hm, now it gets lost
+ \ifblankdisable
+ \global\blankindeedfalse % keep this, i.e. disable current too
+ \ifgridsnapping
+ \ifdim\prevdepth<\zeropoint
+ % brrr
+ \else
+ % dirty trick: smaller blanks are ignored after a
+ % larger one, so 10 lines is probably safe; we need
+ % to make sure that we honor penalties; here comes the
+ % trick (cross our fingers that this works well in
+ % multi columns; maybe an ifinner test is needed
+ % \scratchcounter\lastpenalty
+ % \vskip-10\lineheight
+ % \ifnum\scratchcounter=\zerocount \else \penalty\lastpenalty \fi
+ % \vskip 10\lineheight
+ % alas, this leads to overfull pages, so we try this:
+ \inhibitgridblank
+ \fi
+ \else
+ \ifdim\prevdepth<\zeropoint
+ % brrr
+ \else
+ % ensure at least a proper prevdepth, this should be
+ % an option
+ \vskip-\prevdepth
+ \vskip\strutdepth
+ \prevdepth\strutdepth
+ \fi
+ % the old crappy piece of code
+ \edef\oldprevdepth{\the\prevdepth}%
+ \prevdepth\newprevdepth % == \inhibittextblank
+ \fi
+ \else
+ \global\blankindeedtrue
+ \fi
+ \ifblankreset
+ \global\blankindeedtrue
+ \ifgridsnapping
+ % let's play safe and not fool around with the depth, if
+ % only because it took a lot of effort to sort out the grid
+ % stuff in the first place
+ \else
+ \ifdim\prevdepth=\newprevdepth
+ \prevdepth\oldprevdepth
+ \fi
+ \fi
+ \fi
+ \ifblankindeed
+ \ifdim1\savedlastskip<1\blankskip\relax
+ % else when \blank[2*groot] + \blank[3*groot] with parskip
+ % equaling 1*groot, gives a groot=\parskip so adding a small
+ % value makes it distinguishable; can also be done at parskip
+ % setting time (better)
+ \global\advance\blankskip \mindimen\relax % = skip
+ % test this on 2* + 3* and parskip groot
+ \ifblanknowhite
+ \global\advance\blankskip -\parskip
+ \else
+ \ifdim\savedlastskip=\parskip
+ \else % force this due to previous comment
+ \ifdim\parskip>\zeropoint\relax
+ \ifdim\blankskip<\parskip\relax
+ \global\blankskip\zeropoint
+ \else
+ \global\advance\blankskip -\parskip
+ \fi
+ \fi
+ \fi
+ \fi
+ \ifblankflexible \else
+ \blankskip1\blankskip
+ \fi
+ \iflocalblankfixed
+ \blankskip1\blankskip
+ \fi
+ \iflocalblankflexible
+ \blankskip1\blankskip
+ \!!plus \skipgluefactor\blankskip
+ \!!minus\skipgluefactor\blankskip
+ \fi
+ \ifdim\lastkern=\noblanksignal\relax % controlled and grid
+ \global\blankindeedfalse
+ \else\ifnum\savedlastpenalty=\noblankpsignal\relax % controlled and grid
+ \global\blankindeedfalse
+ \else\ifgridsnapping\else\ifdim\prevdepth=\newprevdepth
+ \global\blankindeedfalse
+ \fi\fi\fi\fi
+ \ifblankindeed
+ \iffuzzyvskip
+ \removelastfuzzyvskip
+ \fuzzyvskip\blankskip\relax
+ \else
+ \relax\ifdim\savedlastskip=\zeropoint\else
+ \vskip-\savedlastskip
+ \fi
+ \vskip\blankskip\relax
+ \fi
+ \fi
+ \else
+ \iffuzzyvskip
+ \removelastfuzzyvskip
+ \fuzzyvskip\blankskip\relax
+ \else
+ % new, test this on pascal
+ \ifdim\blankskip<\zeropoint
+ \relax\ifdim\savedlastskip=\zeropoint\else
+ \advance\blankskip-\savedlastskip
+ \vskip-\savedlastskip
+ \fi
+ \ifdim\blankskip>\zeropoint
+ \vskip\blankskip
+ \else
+ \vskip\zeropoint
+ \fi
+ \else
+ % also new
+ \ifdim\blankskip=\zeropoint
+ \ifblanknowhite
+ \nowhitespace
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \fi
+ \global\fuzzyvskipfalse
+ \presetindentation}
-% \start \dosetstretch{.25em} \setuptolerance[tolerant,stretch] \input tufte \endgraf \stop
-% \start \dosetstretch{.5em} effe flink doorfietsen \stop
+%D For a long time we had:
+%D
+%D \starttyping
+%D \def\simpledoblank%
+%D {\doifelse{\currentwhitespace}{\v!geen}
+%D {\blank[\currentblank]}
+%D {\blank[\currentwhitespace]}}
+%D \stoptyping
+%D
+%D But Berend de Boer wanted more control, so now we have:
+
+\def\simpledoblank % ...
+ {\doifelse\currentwhitespace\v!none
+ {\blank[\currentblank]}
+ {\blank[\s!default]}}
+
+%D Another useful definition would be:
+%D
+%D \starttyping
+%D \defineblank
+%D [\s!default]
+%D [\v!groot]
+%D \stoptyping
-\def\dosetstretch#1% to be interfaces
- {\relax\ifdim#1>\zeropoint
- \dosetattribute{kern-chars}{\number\dimexpr#1\relax}%
+\def\dosetupblank#1% amount are an plain inheritance
+ {\bigskipamount#1\relax
+ \ifblankflexible \else
+ \bigskipamount1\bigskipamount
+ \fi
+ \medskipamount \bigskipamount \divide\medskipamount \plustwo
+ \smallskipamount\bigskipamount \divide\smallskipamount\plusfour}%
+
+\def\complexsetupblank[#1]% more \let's -> this also wil become installable
+ {\ifgridsnapping
+ \blankflexiblefalse
\else
- \doresetattribute{kern-chars}%
+ \ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!flexible=>\blankflexibletrue,
+ \v!fixed=>\blankflexiblefalse]%
+ \fi
+ \ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!flexible=>\dosetupblank\appliedblankskip,
+ \v!fixed=>\dosetupblank\appliedblankskip,
+ \v!line=>\edef\appliedblankskip{\linedistance}%
+ \dosetupblank\appliedblankskip,
+ \v!halfline=>\scratchskip.5\linedistance
+ \edef\appliedblankskip{\the\scratchskip}%
+ \dosetupblank\appliedblankskip,
+ \v!big=>\ifgridsnapping
+ \edef\appliedblankskip{\linedistance}%
+ \dosetupblank\appliedblankskip
+ \fi
+ \let\currentblank\v!big,
+ \v!medium=>\let\currentblank\v!medium,
+ \v!small=>\let\currentblank\v!small,
+ \v!global=>\let\currentblank\v!global,
+ \v!normal=>\dosetupblank\appliedblankskip,
+ \v!standard=>\edef\appliedblankskip{\skipfactor\linedistance}%
+ \dosetupblank\appliedblankskip,
+ \s!default=>\dosetupblank\appliedblankskip,
+ \s!unknown=>\let\appliedblankskip\commalistelement
+ \dosetupblank\appliedblankskip]%
+ \simplesetupwhitespace}
+
+% \definecomplexorsimpleempty\setupblank
+%
+% speed gain: 60 sec -> 30 sec
+
+\definecomplexorsimple\setupblank
+
+\def\simplesetupblank % == snelle \setupblank[\s!default]
+ {\ifgridsnapping
+ \blankflexiblefalse
+ \fi
+ \dosetupblank\appliedblankskip
+ % \let\deblanko\v!big
+ \simplesetupwhitespace}
+
+\def\restorestandardblank% \v!standard
+ {\edef\appliedblankskip{\skipfactor\linedistance}%
+ \dosetupblank\appliedblankskip
+ }%\let\deblanko\v!big}
+
+\def\dodefineblank[#1][#2]%
+ {\def\docommand##1{\setvalue{\??bo##1}{#2}}%
+ \processcommalist[#1]\docommand}
+
+\def\defineblank
+ {\dodoubleargument\dodefineblank}
+
+\def\savecurrentblank
+ {\edef\restorecurrentblank
+ {\bigskipamount\the\bigskipamount
+ \medskipamount\the\medskipamount
+ \smallskipamount\the\smallskipamount
+ \noexpand\def\noexpand\currentblank{\currentblank}%
+ \ifblankflexible
+ \noexpand\blankflexibletrue
+ \else
+ \noexpand\blankflexiblefalse
+ \fi}}
+
+%D Now.
+
+\defineblank [\s!default] [\v!white]
+\defineblank [\v!height] [\strutheight]
+\defineblank [\v!depth] [\strutdepth]
+
+\let\currentindentation\empty % amount/keyword
+% \let\normalindentation \empty % used for reinstating normal indentation
+\let\currentindenting \empty % method
+
+\newdimen\ctxparindent
+
+\newif\ifindentfirstparagraph % \indentfirstparagraphtrue
+
+\chardef\indentingtoggle\zerocount
+
+%D After a blank or comparable situation (left side floats) we
+%D need to check if the next paragraph has to be indented.
+
+\def\presetindentation
+ {\doifoutervmode{\ifindentfirstparagraph\else\noindentation\fi}}
+
+%D This sets up the (normally) global indentation behavior as well
+%D as the amounts.
+
+\definecomplexorsimple\setupindenting
+
+\indentfirstparagraphtrue
+\parindent\ctxparindent
+\chardef\indentingtoggle\zerocount
+
+% we need a better everypar model: for each option a switch, which we
+% set to false with \forgetall and can enable when needed (context 4);
+% that way we can control the order of execution of options
+
+\def\checkeverypar % currently a hack
+ {\ifzeropt\parindent\else
+ \doifsometokselse\everypar\donothing{\appendtoks\checkindentation\to\everypar}%
\fi}
-\appendtoks\doresetattribute{kern-chars}\to\everyforgetall
+\def\complexsetupindenting[#1]%
+ {\edef\currentindenting{#1}%
+ \doifsomething\currentindenting % handy when a parameter is passed
+ {% not here: \indentfirstparagraphtrue
+ % not here: \parindent\ctxparindent
+ % not here: \chardef\indentingtoggle\zerocount
+ % we use commacommand in order to catch #1 being a command (expanded parameter)
+ \processcommacommand[\currentindenting]\docomplexsetupindentingA % catch small, medium, etc
+ \processcommacommand[\currentindenting]\docomplexsetupindentingB % catch rest
+ \checkeverypar % only when non-empty #1
+ \ifindentfirstparagraph\else\noindentation\fi % added
+ \toggleindentation}}
-\def\mksetupgridsnapping
- {\ctxlua{nodes.setsnapvalue(1,\number\openstrutheight,\number\openstrutdepth)}}
+\def\docomplexsetupindentingA#1%
+ {\edefconvertedargument\!!stringa{#1}%
+ \doifundefined{\??in:\!!stringa}%
+ {\edef\currentindentation{#1}%
+ \let\normalindentation\currentindentation
+ \simplesetupindenting}}
-\def\mkenablegridsnapping
- {\dosetattribute{snap-category}{1}%
- \topskip\strutht
- \offinterlineskip}
+\def\docomplexsetupindentingB#1%
+ {\edefconvertedargument\!!stringa{#1}% catch #1=\somedimen
+ \executeifdefined{\??in:\!!stringa}\donothing}
-\def\mkdisablegridsnapping
- {\doresetattribute{snap-category}%
- % reset topskip
- \oninterlineskip}
+\def\simplesetupindenting % empty case, a it strange, needed this way?
+ {\assigndimension\currentindentation\ctxparindent{1em}{1.5em}{2em}}
+
+\def\indenting % kind of obsolete
+ {\dosingleargument\complexsetupindenting}
+
+% use \noindentation to suppress next indentation
+
+\def\defineindentingmethod[#1]#2%
+ {\setvalue{\??in:#1}{#2}}
+
+\defineindentingmethod [\v!no] {\parindent\zeropoint}% was: \ctxparindent\noindent}
+\defineindentingmethod [\v!not] {\parindent\zeropoint}% was: \ctxparindent\noindent}
+
+\defineindentingmethod [\v!first] {\indentfirstparagraphtrue}
+\defineindentingmethod [\v!next] {\indentfirstparagraphfalse}
-% experimental mirroring
+\defineindentingmethod [\v!yes] {\parindent\ctxparindent\relax} % no \indent !
+\defineindentingmethod [\v!always] {\parindent\ctxparindent\relax} % no \indent !
-\defineattribute[mirror]
+\defineindentingmethod [\v!never] {\parindent\zeropoint\relax % no \indent !
+ \chardef\indentingtoggle\zerocount}
-\def\setcharactermirroring
- {\ctxlua{mirror.enabled=true}%
- \gdef\setcharactermirroring[##1]{\dosetattribute{mirror}{\number##1}}%
- \setcharactermirroring}
+\defineindentingmethod [\v!odd] {\chardef\indentingtoggle\plusone}
+\defineindentingmethod [\v!even] {\chardef\indentingtoggle\plustwo}
-\def\resetcharactermirroring
- {\doresetattribute{mirror}}
+\defineindentingmethod [\v!normal] {\ifx\normalindentation\empty\else
+ \let\currentindentation\normalindentation
+ \simplesetupindenting
+ \fi}
-\newtoks\everysetupdirections
+\defineindentingmethod [\v!reset] {\indentfirstparagraphtrue
+ \parindent\zeropoint
+ \chardef\indentingtoggle\zerocount}
-\def\setupdirections[#1]% there will be more like setting up directions themselves
- {\getparameters[\??di][#1]%
- \the\everysetupdirections}
+\def\noindenting{\indenting[\v!no, \v!next ]}
+\def\doindenting{\indenting[\v!yes,\v!first]}
-\chardef\directionsbidimode=0
+%D This one sets up the local indentation behaviour (i.e. either or not
+%D a next paragraph will be indented).
-\letvalue{\??di:bidi:\v!off }\zerocount
-\letvalue{\??di:bidi:\v!global}\plusone
-\letvalue{\??di:bidi:\v!local }\plustwo
-\letvalue{\??di:bidi:\v!on }\plustwo
+\def\dochecknextindentation#1% internal one
+ {\checknextindentation[\csname#1\c!indentnext\endcsname]}
+
+\setvalue{\??in->\s!empty}{}
+\setvalue{\??in->\v!yes }{\doindentation}
+\setvalue{\??in->\v!no }{\noindentation}
+\setvalue{\??in->\v!auto }{\autoindentation}
+
+\def\checknextindentation[#1]%
+ {\csname\??in->\ifcsname\??in->#1\endcsname#1\else\s!empty\fi\endcsname}
+
+%D Here come the handlers.
+
+\newif\ifindentation \indentationtrue % documenteren, naar buiten
+
+\let\checkindentation\relax
+
+\ifx\autoindentation\undefined \let\autoindentation\relax \fi % hook
+
+\def\doindentation
+ {\gdef\checkindentation{\global\indentationtrue}}
+
+\def\noindentation % made global
+ {\ifinpagebody \else
+ \global\indentationfalse
+ \gdef\checkindentation
+ {\donoindentation
+ \gdef\checkindentation{\global\indentationtrue}}%
+ \fi}
+
+\def\nonoindentation % bv bij floats
+ {\ifinpagebody \else
+ \global\indentationtrue
+ \gdef\checkindentation{\global\indentationtrue}%
+ \fi}
+
+\def\donoindentation
+ {\ifdim\parindent=\zeropoint \else
+ \bgroup \setbox\scratchbox\lastbox \egroup
+ \fi}
+
+\def\indentation
+ {\ifvmode \ifdim\parindent=\zeropoint \else
+ % was : \hskip\parindent
+ % can be: \indent
+ % but we test:
+ \noindent\hskip\parindent
+ \fi \fi}
+
+\def\toggleindentation
+ {\ifcase\indentingtoggle
+ % nothing
+ \or
+ \notoggleindentation
+ \or
+ \dotoggleindentation
+ \fi}
+
+\def\dokillindentation
+ {\gdef\checkindentation{\global\indentationfalse\donoindentation}}
+
+\def\dotoggleindentation
+ {\gdef\checkindentation{\global\indentationfalse\notoggleindentation\donoindentation}}
+
+\def\notoggleindentation
+ {\gdef\checkindentation{\global\indentationtrue\dotoggleindentation}}
\appendtoks
- \chardef\directionsbidimode\executeifdefined{\??di:bidi:\@@dibidi}\zerocount\relax
- \ifcase\directionsbidimode
- \resetcharactermirroring
- \or
- \setcharactermirroring[1]% global, chars
- \or
- \setcharactermirroring[2]% local, attributes
- \or
- \setcharactermirroring[1]% default
- \fi
-\to \everysetupdirections
+ \pushmacro\checkindentation
+ \pushmacro\ifindentation
+\to \everypushsomestate
+
+\appendtoks
+ \popmacro\ifindentation
+ \popmacro\checkindentation
+\to \everypopsomestate
+
+% we need to save the state if we want to adapt behaviour to empty lines
+%
+% \def\setlasthvmode
+% {\global\chardef\savedhvmode\ifhmode\plusone\else\ifvmode\plustwo\else\zerocount\fi\fi}
+%
+% \def\resetlasthvmode
+% {\global\chardef\savedhvmode\zerocount}
+%
+% \chardef\savedhvmode\zerocount
+
+% This is a user requested hack (using the auto-hook).
+
+\chardef\recheckindentationmode\zerocount
+
+\def\dontrechecknextindentation
+ {\global\chardef\recheckindentationmode\zerocount}
+
+\def\dorechecknextindentation
+ {\ifcase\recheckindentationmode
+ % nothing
+ \or
+ \dontrechecknextindentation
+ \expandafter\doautoindentation
+ \fi}
+
+\def\doautoindentation
+ {\doifnextcharelse\par\donothing\noindentation}
-% bidi: local=obey grouping, global=ignore grouping (unicode has no grouping)
+\def\autoindentation
+ {\global\chardef\recheckindentationmode\plusone}
-\setupdirections % maybe start/stop
- [bidi=\v!off]
+%D An example of usage:
+%D
+%D \starttyping
+%D \setupindenting[small,yes]
+%D
+%D \setupitemize [indentnext=auto]
+%D \setuptyping [indentnext=auto]
+%D \setupformulas[indentnext=auto]
+%D
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D
+%D \input tufte
+%D
+%D \startitemize
+%D \item itemize
+%D \stopitemize
+%D
+%D \page
+%D
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D
+%D \input tufte
+%D
+%D \starttyping
+%D verbatim
+%D \stoptyping
+%D
+%D \page
+%D
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+%D
+%D \input tufte
+%D
+%D \startformula
+%D a = b
+%D \stopformula
+
-\unexpanded\def\bidilre{\utfchar{"0x202A}}
-\unexpanded\def\bidirle{\utfchar{"0x202B}}
-\unexpanded\def\bidipop{\utfchar{"0x202C}}
-\unexpanded\def\bidilro{\utfchar{"0x202D}}
-\unexpanded\def\bidirlo{\utfchar{"0x202E}}
+%D \macros
+%D {frenchspacing,nonfrenchspacing}
+%D
+%D Smehow \type{\frenchspacing} can lead to hyphenation between
+%D dashes so we now have \type {\newfrenchspacing} (moved from
+%D \type {syst-chr}).
-\unexpanded\def\dirlre{\ifcase\directionsbidimode\or\bidilre\or\textdir TLT\fi}
-\unexpanded\def\dirrle{\ifcase\directionsbidimode\or\bidirle\or\textdir TRT\fi}
-\unexpanded\def\dirlro{\ifcase\directionsbidimode\or\bidilro\or\setcharactermirroring[3]\fi}
-\unexpanded\def\dirrlo{\ifcase\directionsbidimode\or\bidirlo\or\setcharactermirroring[4]\fi}
+%D Hm ... todo:
-% test at end of file
+\sfcode`\)=0
+\sfcode`\'=0
+\sfcode`\]=0
-% for the moment: \setcharactermirroring[\plusone]
+\def\setfrenchspacing#1%
+ {\sfcode`\.#1 \sfcode`\,#1\relax
+ \sfcode`\?#1 \sfcode`\!#1\relax
+ \sfcode`\:#1 \sfcode`\;#1\relax}
-% experimental spacing
+\def\frenchspacing
+ {\setfrenchspacing{1000}}
+
+\def\resetfrenchspacing
+ {\sfcode`\.3000 \sfcode`\,1250
+ \sfcode`\?3000 \sfcode`\!3000
+ \sfcode`\:2000 \sfcode`\;1500 }
+
+\def\frenchspacing {\setfrenchspacing{1000}}
+\def\newfrenchspacing{\setfrenchspacing{1050}}
+\def\nonfrenchspacing{\resetfrenchspacing}
+
+\def\definespacingmethod[#1]#2{\setvalue{\??sg\??sg#1}{#2}}
+
+\definespacingmethod[\v!packed]{\newfrenchspacing}
+\definespacingmethod[\v!broad ]{\nonfrenchspacing}
+
+\def\complexsetupspacing[#1]%
+ {\executeifdefined{\??sg\??sg#1}\relax
+ \updateraggedskips}
+
+\def\simplesetupspacing
+ {\updateraggedskips}
+
+\definecomplexorsimple\setupspacing
+
+% \dorecurse{100}{\recurselevel\spacefactor 800 \space} \par
+% \dorecurse{100}{\recurselevel\spacefactor1200 \space} \par
+% \dorecurse{100}{\recurselevel\spacefactor 800 \normalspaceprimitive} \par
+% \dorecurse{100}{\recurselevel\spacefactor1200 \normalspaceprimitive} \par
+
+% When we don't add the % here, we effectively get \ and
+% since we have by default \def\^^M{\ } we get into a loop.
+
+\let\normalspaceprimitive=\ % space-comment is really needed
+
+\unexpanded\def\ {\mathortext\normalspaceprimitive\space} % no \dontleavehmode\space (else no frenchspacing)
+
+\unexpanded\def\nonbreakablespace{\penalty\plustenthousand\space}
+
+\letcatcodecommand \ctxcatcodes `\~ \nonbreakablespace % overloaded later
+
+\def\space { }
+\def\removelastspace{\ifhmode\unskip\fi}
+\def\nospace {\removelastspace\ignorespaces}
+
+% in tables we need:
+%
+% \def\fixedspace {\hskip.5em\relax}
%
-% test: oeps {\setcharacterspacing[frenchpunctuation]x: xx \bfd x: xx} oeps: test
+% but, since not all fonts have .5em digits:
-\defineattribute[spacing]
+\unexpanded\def\fixedspace
+ {\setbox\scratchbox\normalhbox{\mathortext{0}{0}}%
+ \hskip\wd\scratchbox\relax}
-\newcount \maxcharacterspacingid
+\def\fixedspaces
+ {\letcatcodecommand \ctxcatcodes `\~ \fixedspace}
-\def\definecharacterspacing[#1]%
- {\ifcsname\??ch#1\endcsname \else
- \global\advance\maxcharacterspacingid\plusone
- \setxvalue{\??ch:#1}{\the\maxcharacterspacingid}%
+\def\removeunwantedspaces
+ {\ifhmode % we also need to unskip 0pt skips
+ \unskip\unskip\unskip\unskip\unskip
+ \unskip\unskip\unskip\unskip\unskip
\fi}
-\def\setupcharacterspacing
- {\dotripleargument\dosetupcharacterspacing}
+\appendtoks\let~\space\to\simplifiedcommands
-\def\dosetupcharacterspacing[#1][#2][#3]%
- {\ifcsname\??ch:#1\endcsname
- \begingroup % for the moment we use modes, in ordere to avoid interface translation
- \getparameters[\??ch][\c!left=0,\c!right=0,\c!alternative=0,#3]%
- \ctxlua{spacings.setspacing(\getvalue{\??ch:#1},\number#2,\@@chleft,\@@chright,\@@chalternative)}%
- \endgroup
+% still not fixed in aleph / luatex
+%
+% \def\removeunwantedspaces
+% {\ifhmode \ifnum\lastnodetype=\@@gluenode
+% \unskip \@EAEAEA\removeunwantedspaces
+% \fi \fi}
+
+%D For old time sake, will disappear soon.
+
+\let\hardespatie\fixedspace
+\let\geenspatie \nospace
+
+% \startbuffer
+% \startlines \tt \fixedspaces
+% 0~1~~2~~~3~~~~4~~~~~5
+% 0~~~~~~~~~~~~~~~~~~~5
+% $0~1~~2~~~3~~~~4~~~~~5$
+% $0~~~~~~~~~~~~~~~~~~~5$
+% \stoplines
+%
+% \starttabulate[|~|]
+% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \NR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \NR
+% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \NR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \NR
+% \stoptabulate
+%
+% \starttable[||]
+% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \AR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \AR
+% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \AR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \AR
+% \stoptable
+% \stopbuffer
+%
+% \setupbodyfont[cmr] \getbuffer
+% \setupbodyfont[lbr] \getbuffer
+
+\def\packed
+ {\nointerlineskip}
+
+\def\godown[#1]%
+ {\relax
+ \ifhmode\endgraf\fi
+ \ifvmode\nointerlineskip\vskip#1\relax\fi}
+
+%D A couple of plain macros:
+
+\ifx\thinspace\undefined
+
+ \def\thinspace {\kern .16667em }
+ \def\negthinspace{\kern-.16667em }
+ \def\enspace {\kern .5em }
+
+ \def\thinspace {\kern .16667\emwidth}
+ \def\negthinspace{\kern-.16667\emwidth}
+ \def\enspace {\kern .5\emwidth}
+
+\fi
+
+\ifx\quad\undefined
+
+ \def\enskip{\hskip.5em\relax}
+ \def\quad {\hskip 1em\relax}
+ \def\qquad {\hskip 2em\relax}
+
+ \def\enskip{\hskip.5\emwidth}
+ \def\quad {\hskip \emwidth}
+ \def\qquad {\hskip 2\emwidth}
+
+\fi
+
+\let\emspace\quad
+
+\ifx\smallskip\undefined
+
+ \def\smallskip{\vskip\smallskipamount}
+ \def\medskip {\vskip\medskipamount}
+ \def\bigskip {\vskip\bigskipamount}
+
+\fi
+
+\ifx\allowbreak\undefined
+
+ \def\break {\penalty\ifhmode-\plustenthousand\else\ejectpenalty\fi}
+ \def\nobreak {\penalty \plustenthousand}
+ \def\allowbreak{\penalty \zeropoint}
+ \def\filbreak {\par\vfil\penalty-200\vfilneg}
+ \def\goodbreak {\par\penalty-500 }
+
+\fi
+
+%D Made slightly more readable:
+
+\ifx\vglue\undefined
+
+ \def\vglue {\afterassignment\dovglue\scratchskip=}
+ \def\hglue {\afterassignment\dohglue\scratchskip=}
+ \def\topglue{\nointerlineskip\vglue-\topskip\vglue}
+
+ \def\dovglue
+ {\par
+ \scratchdimen\prevdepth
+ \hrule\!!height\zeropoint
+ \nobreak\vskip\scratchskip
+ \prevdepth\scratchdimen}
+
+ \def\dohglue
+ {\dontleavehmode % \leavevmode
+ \scratchcounter\spacefactor
+ \vrule\!!width\zeropoint
+ \nobreak\hskip\scratchskip
+ \spacefactor\scratchcounter}
+
+\fi
+
+\ifx\eject\undefined
+
+ \def\eject{\par\break}
+
+\fi
+
+\ifx\supereject\undefined
+
+ \def\supereject{\par\penalty\superpenalty}
+
+\fi
+
+\ifx\dosupereject\undefined
+
+ \def\dosupereject
+ {\ifnum\insertpenalties>\zerocount % something is being held over
+ \line{}
+ \kern-\topskip
+ \nobreak
+ \vfill\supereject
+ \fi}
+
+\fi
+
+%D We adapt plain's \type {\removelastskip} a bit:
+
+\ifx\removelastskip\undefined
+
+ \def\removelastskip
+ {\ifvmode \ifdim\lastskip=\zeropoint \else
+ \vskip-\lastskip
+ \fi \fi}
+
+\fi
+
+\ifx\smallbreak\undefined
+
+\def\smallbreak
+ {\par
+ \ifdim\lastskip<\smallskipamount
+ \removelastskip
+ \penalty-50
+ \smallskip
+ \fi}
+
+\def\medbreak
+ {\par
+ \ifdim\lastskip<\medskipamount
+ \removelastskip
+ \penalty-100
+ \medskip
+ \fi}
+
+\def\bigbreak
+ {\par
+ \ifdim\lastskip<\bigskipamount
+ \removelastskip
+ \penalty-200
+ \bigskip
+ \fi}
+
+\fi
+
+\newskip\ctxparskip \ctxparskip\zeropoint
+
+\newconditional \flexiblewhitespace \settrue\flexiblewhitespace
+
+\def\blankokleinmaat {\smallskipamount}
+\def\blankomiddelmaat {\medskipamount}
+\def\blankogrootmaat {\bigskipamount}
+\def\currentwhitespace {\zeropoint}
+
+\definecomplexorsimple\setupwhitespace
+
+\def\simplesetupwhitespace
+ {\doifnot\currentwhitespace\v!none\dosetupwhitespace}
+
+\def\complexsetupwhitespace[#1]%
+ {\edef\nextcurrentwhitespace{#1}%
+ \ifx\nextcurrentwhitespace\empty
+ \simplesetupwhitespace
+ \else
+ \let\currentwhitespace\nextcurrentwhitespace
+ \dosetupwhitespace
+ \fi}
+
+\def\dosetupwhitespace % quick test for no list
+ {\ifcsname\??ws\??ws\currentwhitespace\endcsname
+ \csname\??ws\??ws\currentwhitespace\endcsname
+ \else
+ \expandafter\processcommalist\expandafter[\currentwhitespace]\dowhitespacemethod % can be raw
+ \fi\relax
+ \ifgridsnapping
+ \setfalse\flexiblewhitespace
+ \ifdim\ctxparskip>\zeropoint
+ \ctxparskip
+ \ifcase\baselinegridmode
+ \baselineskip % normal ! ! ! ! !!
+ \or
+ \ifdim\scratchdimen=\baselineskip % maybe range
+ \baselineskip % normal ! ! ! ! !!
+ \else
+ \numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
+ \fi
+ \else
+ \baselineskip % normal ! ! ! ! !!
+ \fi
+ \fi
+ \else
+ \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
+ \fi
+ \parskip\ctxparskip}
+
+\chardef\baselinegridmode=0 % option in layout / 1=permit_half_lines
+
+\def\dodosetupwhitespace
+ {\ifgridsnapping
+ \setfalse\flexiblewhitespace
+ \ctxparskip1\ctxparskip
+ \ifdim\ctxparskip>\zeropoint
+ \ifcase\baselinegridmode
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \or
+ \ifdim\scratchdimen=\baselineskip % maybe range
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \else
+ \ctxparskip\numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
+ \fi
+ \else
+ \ctxparskip\baselineskip % normal ! ! ! ! !!
+ \fi
+ \fi
+ \else
+ \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
+ \fi
+ \parskip\ctxparskip}
+
+\definesystemvariable {ws} % whitespace
+
+\def\definewhitespacemethod[#1]#2{\setvalue{\??ws\??ws#1}{#2}}
+
+\definewhitespacemethod [\v!fix] {}
+\definewhitespacemethod [\v!fixed] {\setfalse\flexiblewhitespace}
+\definewhitespacemethod [\v!flexible] {\settrue\flexiblewhitespace}
+\definewhitespacemethod [\v!line] {\ctxparskip \baselineskip}
+\definewhitespacemethod [\v!halfline] {\ctxparskip.5\baselineskip}
+\definewhitespacemethod [\v!none] {\ctxparskip \zeropoint}
+\definewhitespacemethod [\v!big] {\ctxparskip \bigskipamount}
+\definewhitespacemethod [\v!medium] {\ctxparskip \medskipamount}
+\definewhitespacemethod [\v!small] {\ctxparskip \smallskipamount}
+
+\definewhitespacemethod [\s!default] {\simplesetupwhitespace} % {\stelwitruimteopnieuwin}
+
+% \def\dowhitespacemethod#1%
+% {\executeifdefined{\??ws\??ws#1}{\ctxparskip#1}\relax}
+
+\def\dowhitespacemethod#1%
+ {\ifcsname\??ws\??ws#1\endcsname\csname\??ws\??ws#1\endcsname\else\ctxparskip#1\fi\relax}
+
+\def\nowhitespace
+ {\ifdim\parskip>\zeropoint\relax
+ \ifdim\lastskip=-\parskip
+ \else
+ \vskip-\parskip
+ \fi
+ \fi}
+
+\def\nowhitespaceunlessskip
+ {\ifdim\lastskip>\zeropoint \else
+ \nowhitespace
+ \fi}
+
+\def\redowhitespace
+ {\ifdim\lastskip>-\parskip \else
+ \vskip\parskip
+ \fi}
+
+\def\savecurrentwhitespace
+ {\edef\restorecurrentwhitespace
+ {\ctxparskip\the\ctxparskip
+ \parskip\the\parskip
+ \noexpand\def\noexpand\currentwhitespace{\currentwhitespace}%
+ \ifconditional\flexiblewhitespace
+ \noexpand\settrue\flexiblewhitespace
+ \else
+ \noexpand\setfalse\flexiblewhitespace
+ \fi}}
+
+% deze variant is nodig binnen \startopelkaar
+% steeds testen:
+%
+% \hoofdstuk{..}
+% \plaatslijst[..]
+% \hoofdstuk{..}
+% \input tufte
+%
+% met/zonder witruimte
+
+\def\whitespace
+ {\par
+ \ifdim\parskip>\zeropoint\relax
+ %\ifdim\lastskip>\parskip \else
+ % \removelastskip interferes with blanko blokkeer en klein
+ \vskip\parskip
+ %\fi
\fi}
-\def\setcharacterspacing
- {\ctxlua{spacings.enabled=true}%
- \gdef\setcharacterspacing[##1]{\dosetattribute{spacing}{\csname\??ch:##1\endcsname}}%
- \setcharacterspacing}
+\def\nonoblanko[#1]%
+ {\par}
+
+\def\noblanko
+ {\dosingleempty\nonoblanko}
+
+% De onderstaande macro handelt ook de situatie dat er geen
+% tekst tussen \start ... \stop is geplaatst. Daartoe wordt de
+% laatste skip over de lege tekst heen gehaald. Dit komt goed
+% van pas bij het plaatsen van (mogelijk lege) lijsten.
+
+\newif\ifopelkaar
+
+\newsignal \noparskipsignal % \def\noparskipsignal {0.00001pt}
+\def\lastdoneparskip {0pt}
+
+\def\startpacked
+ {\dosingleempty\dostartpacked}
+
+\def\dostartpacked[#1]% nesting afvangen
+ {\par
+ \ifvmode
+ \edef\lastdoneparskip {\the\lastskip}%
+ \edef\lastdoneprevdepth{\the\prevdepth}% zeer recent toegevoegd
+ \ifdim\prevdepth=-\thousandpoint % toegevoegd omdat binnen
+ \else % een vbox een extra skip
+ \whitespace % ongewenst is; dit kan
+ \baselinecorrection %% zie in \placeregister[n=1]
+ \vskip\noparskipsignal % waarschijnlijk ook in
+ \fi % blanko blokkeer
+ \bgroup
+ \doifelse{#1}\v!blank
+ \opelkaarfalse
+ \opelkaartrue
+ \blank[\v!disable] % dit is nog niet ok, gaat fout
+ \setupwhitespace[\v!none] % bovenin vtop (dwz, baseline)
+ \fi}
+
+\def\stoppacked
+ {\par
+ \ifvmode
+ \egroup
+ \ifdim\lastskip=\noparskipsignal\relax
+ \removelastskip
+ \nowhitespace
+ \vskip-\lastdoneparskip
+ \vskip+\lastdoneparskip
+ \prevdepth-\lastdoneprevdepth % zeer recent toegevoegd
+ \fi
+ \fi}
-\def\resetcharacterspacing
- {\doresetattribute{spacing}}
+\def\startunpacked
+ {\blank
+ \leavevmode
+ \bgroup}
-\letvalue{\??ch:\s!reset}\minusone
+\def\stopunpacked
+ {\egroup
+ \blank}
+
+% De onderstaande macro's moeten nog eens nader worden uitgewerkt.
+% Ze spelen een rol bij de spatiering rond omkaderde teksten
+% en/of boxen zonder diepte.
-% \setcharacterspacing[frenchpunctuation]
-% «\type{bla}»\crlf « \type{bla}»\crlf
-% «bla »\crlf « bla»\crlf « bla »\crlf
-% bla: bla\crlf bla : bla
+\def\toonregelcorrectie{\showbaselinecorrection}
+\def\regelcorrectie {\baselinecorrection}
-\definecharacterspacing [frenchpunctuation] % name may change / unit is em
+% \prevdepth crosses pageboundaries!
+%
+% todo: a version that works ok inside a box
+
+\let\doaroundlinecorrection\relax
+
+\def\startlinecorrection
+ {\dodoubleempty\dostartlinecorrection}
+
+\def\dostartlinecorrection[#1][#2]% #2 gobbles spaces
+ {\bgroup
+ \processaction
+ [#1]
+ [ \v!blank=>\let\doaroundlinecorrection\blank,
+ \s!default=>\let\doaroundlinecorrection\relax,
+ \s!unknown=>{\def\doaroundlinecorrection{\blank[#1]}}]%
+ \doaroundlinecorrection
+ \startbaselinecorrection
+ \offbaselinecorrection
+ \ignorespaces}
-\setupcharacterspacing [frenchpunctuation] ["003A] [\c!left =.25,\c!alternative=1] % : % strip preceding space(char)
-\setupcharacterspacing [frenchpunctuation] ["003B] [\c!left =.25,\c!alternative=1] % ; % strip preceding space(char)
-\setupcharacterspacing [frenchpunctuation] ["003F] [\c!left =.25,\c!alternative=1] % ? % strip preceding space(char)
-\setupcharacterspacing [frenchpunctuation] ["0021] [\c!left =.25,\c!alternative=1] % ! % strip preceding space(char)
-\setupcharacterspacing [frenchpunctuation] ["00AB] [\c!right=.25,\c!alternative=1] % guillemotleft/leftguillemot % strip following space(char)
-\setupcharacterspacing [frenchpunctuation] ["00BB] [\c!left =.25,\c!alternative=1] % guillemotright/rightguillemot % strip preceding space(char)
+\def\stoplinecorrection
+ {\stopbaselinecorrection
+ \doaroundlinecorrection
+ \egroup}
-% more
+\def\correctwhitespace
+ {\dowithnextbox
+ {\startbaselinecorrection
+ \flushnextbox
+ \stopbaselinecorrection}%
+ \vbox}
+
+\def\verticalstrut {\normalvbox{\hsize\zeropoint\forgetall\strut}}
+\def\horizontalstrut{\normalhbox {\strut}}
+
+% Hieronder volgen enkele instellingen en macro's ten behoeve
+% van de interlinie en \strut. De waarden 2.8, 0.07, 0.72 en
+% 0.28 zijn ooit eens ontleend aan INRS-TEX en moeten wellicht
+% nog eens instelbaar worden.
+%
+% \lineheight : de hoogte van een regel
+% \spacing{getal} : instellen interlinie
+% \normalbaselines : instellen regelafstend
+%
+% \setstrut : instellen \strut
+% \setnostrut : resetten \strut, \endstrut, \begstrut
+%
+% \setteststrut : instellen zichtbare struts
+% \resetteststrut : instellen onzichtbare struts
+%
+% \setfontparameters : instellen na fontset
%
-% {\setcharacterkerning[extrakerning]\input davis\relax}
+% De hoogte van een regel (\lineheight) is gelijk aan de
+% som van de hoogte (\ht) en diepte (\dp) van \strutbox.
+%
+% \strut : denkbeeldig blokje met hoogte en diepte
+%
+% Een \hbox kan als deze aan het begin van een regel staat
+% een breedte \hsize krijgen. Dit is soms te voorkomen met het
+% commando \leavevmode. Binnen een \vbox geeft dit echter
+% niet altijd het gewenste resultaat, vandaar het commando
+%
+% \leaveoutervmode
+
+% Pas op: niet zomaar \topskip en \baselineskip aanpassen
+% en zeker niet \widowpenalty. Dit kan ernstige gevolgen
+% hebben voor kolommen.
+%
+% Enige glue kan op zich geen kwaad, echter als blanko=vast,
+% dan moet ook de rek 0 zijn. Binnen kolommen is rek ook
+% niet bepaald mooi. Een hele kleine waarde (0.025) voldoet,
+% omdat een positieve glue eindeloos rekbaar is.
+
+\newdimen\strutdimen
+\newdimen\lineheight
+\newdimen\openlineheight
+\newdimen\openstrutheight
+\newdimen\openstrutdepth
+\newdimen\topskipgap
+\newdimen\struttotal
+
+\def\strutheightfactor {.72}
+\def\strutdepthfactor {.28}
+
+\def\baselinefactor {2.8}
+\def\baselinegluefactor {0}
+
+\def\minimumstrutheight {0pt}
+\def\minimumstrutdepth {0pt}
+
+\def\normallineheight {\baselinefactor ex}
+\def\minimumlinedistance {\lineskip}
+
+\def\strutheight {0pt}
+\def\strutdepth {0pt}
+\def\strutwidth {0pt}
+
+\def\spacingfactor {1}
+
+\def\topskipfactor {1.0}
+\def\maxdepthfactor {0.5}
+
+\def\systemtopskipfactor {\topskipfactor}
+\def\systemmaxdepthfactor {\maxdepthfactor}
+
+% De onderstaande definitie wordt in de font-module overruled
-\defineattribute[kern]
+\ifdefined\globalbodyfontsize\else
+ \newdimen\globalbodyfontsize
+ \globalbodyfontsize=12pt
+\fi
-\newcount \maxcharacterkerningid
+\ifx\normalizedbodyfontsize\undefined
+ \def\normalizedbodyfontsize{12pt}
+\fi
-\def\definecharacterkerning
- {\dosingleargument\dodefinecharacterkerning}
+% door een \dimen. Dit is geen probleem omdat (1) de default
+% korpsgrootte 12pt is en (2) de fonts nog niet geladen zijn
+% en de instellingen bij het laden nogmaals plaatsvinden.
-\def\dodefinecharacterkerning[#1]%
- {\ifcsname\??ck#1\endcsname \else
- \global\advance\maxcharacterkerningid\plusone
- \setxvalue{\??ck:#1}{\the\maxcharacterkerningid}%
+\def\topskipcorrection
+ {\simpletopskipcorrection
+ \vskip-\struttotal
+ \verticalstrut}
+
+\def\simpletopskipcorrection
+ {\ifdim\topskip>\openstrutheight
+ % == \vskip\topskipgap
+ \vskip\topskip
+ \vskip-\openstrutheight
\fi}
-\def\setupcharacterkerning
- {\dodoubleargument\dosetupcharacterkerning}
+\def\settopskip % the extra test is needed for the lbr family
+ {\topskip\systemtopskipfactor\globalbodyfontsize
+ \ifgridsnapping \else
+ \ifr@ggedbottom\!!plus5\globalbodyfontsize\fi
+ \fi
+ \relax % the skip
+ \topskipgap\topskip
+ \advance\topskipgap -\openstrutheight\relax
+\ifdim\minimumstrutheight>\zeropoint
+ \ifdim\topskip<\minimumstrutheight
+ \topskip\minimumstrutheight\relax
+ \fi
+\else
+ \ifdim\topskip<\strutheightfactor\openlineheight
+ \topskip\strutheightfactor\openlineheight\relax
+ \fi
+\fi}
+
+\def\setmaxdepth
+ {\maxdepth\systemmaxdepthfactor\globalbodyfontsize}
+
+\def\normalbaselines
+ {\baselineskip \normalbaselineskip
+ \lineskip \normallineskip
+ \lineskiplimit\normallineskiplimit}
+
+\def\setnormalbaselines
+ {\ifdim\normallineheight>\zeropoint
+ \lineheight\normallineheight
+ \fi
+ \openlineheight\spacingfactor\lineheight
+ \openstrutheight \ifdim\minimumstrutheight>\zeropoint
+ \minimumstrutheight % new
+ \else
+ \strutheightfactor\openlineheight
+ \fi
+ \openstrutdepth \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth % new
+ \else
+ \strutdepthfactor \openlineheight
+ \fi
+ \ifdim\dimexpr\minimumstrutdepth+\minimumstrutheight\relax>\zeropoint
+ \openlineheight\dimexpr\openstrutheight+\openstrutdepth\relax % new
+ \fi
+ \normalbaselineskip\openlineheight
+ \ifgridsnapping\else
+ \!!plus \baselinegluefactor\openlineheight
+ \!!minus\baselinegluefactor\openlineheight
+ \fi
+ \normallineskip\minimumlinedistance\relax % \onepoint\relax
+ \normallineskiplimit\zeropoint\relax
+ \normalbaselines
+ \dosetupgridsnapping}
+
+\def\spacing#1%
+ {\ifgridsnapping
+ \ifdim#1\points=\onepoint\else\showmessage\m!layouts{11}{#1}\fi
+ \edef\spacingfactor{1}%
+ \else
+ \edef\spacingfactor{#1}%
+ \fi
+ %\setspacingfactor\systemtopskipfactor \topskipfactor {#1}% why no \spacingfactor ?
+ %\setspacingfactor\systemmaxdepthfactor\maxdepthfactor{#1}% why no \spacingfactor ?
+ \edef\systemtopskipfactor {\withoutpt\the\dimexpr#1\dimexpr\topskipfactor \points}%
+ \edef\systemmaxdepthfactor{\withoutpt\the\dimexpr#1\dimexpr\maxdepthfactor\points}%
+ \setnormalbaselines
+ \setstrut}
+
+%D Sometimes one needs to freeze the interlinespacing
+%D
+%D \starttyping
+%D \rm \saveinterlinespace .... {\ss \restoreinterlinespace .... \endgraf}
+%D \stoptyping
+
+\let\restoreinterlinespace\relax
+
+\def\saveinterlinespace
+ {\edef\restoreinterlinespace
+ {\lineheight \the\lineheight
+ \openstrutheight \the\openstrutheight
+ \openstrutdepth \the\openstrutdepth
+ \openlineheight \the\openlineheight
+ \normalbaselineskip \the\normalbaselineskip
+ \normallineskip \the\normallineskip
+ \normallineskiplimit\the\normallineskiplimit
+ \noexpand\def\noexpand\normallineheight{\the\dimexpr\normallineheight}%
+ \noexpand\normalbaselines}}
+
+% plain definition:
+%
+% \def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+%
+% could be:
+%
+% \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
+
+\ifx\strutbox\undefined
+
+ \newbox\strutbox
+
+ \setbox\strutbox=\normalhbox{\vrule height8.5pt depth3.5pt width\zeropoint}
+
+ %\def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+ \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
+
+\fi
+
+\let\normalstrut\strut
+
+% The double \hbox construction enables us to \backtrack
+% boxes.
+
+\unexpanded\def\setstrut
+ {% height
+ \edef\strutheight
+ {\the\dimexpr\spacingfactor\dimexpr
+ \ifdim\minimumstrutheight>\zeropoint
+ \minimumstrutheight
+ \else
+ \strutheightfactor\dimexpr\normallineheight
+ \fi}%
+ % depth
+ \edef\strutdepth
+ {\the\dimexpr
+ \ifgridsnapping
+ \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth
+ \else
+ \normallineheight-\strutheight
+ \fi
+ \else
+ \spacingfactor\dimexpr
+ \ifdim\minimumstrutdepth>\zeropoint
+ \minimumstrutdepth
+ \else
+ \strutdepthfactor\dimexpr\normallineheight
+ \fi
+ \fi}%
+ % finish
+ \dosetstrut}
+
+\unexpanded\def\setcharstrut#1%
+ {\setbox\strutbox\normalhbox{#1}%
+ \edef\strutheight{\the\strutht}%
+ \edef\strutdepth {\the\strutdp}%
+ \dosetstrut}
+
+\unexpanded\def\setfontstrut
+ {\setcharstrut{(gplQT}}
+
+\unexpanded\def\setcapstrut% could be M, but Q has descender
+ {\setcharstrut{Q}}
+
+%D Handy for math (used in mathml):
+
+\def\charhtstrut
+ {\begingroup
+ \setcharstrut{GJY}%
+ \vrule\!!width\zeropoint\!!depth\zeropoint\!!height\strutht
+ \endgroup}
+
+\def\chardpstrut
+ {\begingroup
+ \setcharstrut{gjy}%
+ \vrule\!!width\zeropoint\!!depth\strutdp\!!height\zeropoint
+ \endgroup}
+
+% because of all the callbacks in mkiv, we avoid unnecessary boxes ...
+% maybe use an attribute so that we can tag boxes that don't need a
+% treatment; tests with using an attribute so far have shown that
+% it's slower because testing the attribute takes time too
-\def\dosetupcharacterkerning[#1][#2]%
- {\ifcsname\??ck:#1\endcsname
- \begingroup
- \getparameters[\??ck][\c!factor=0,#2]%
- \ctxlua{kerns.setspacing(\getvalue{\??ck:#1},\@@ckfactor)}%
+\def\dosetstrut
+ {\let\strut\normalstrut
+ \ifdim\strutwidth=\zeropoint
+ \setbox\strutbox\normalhbox
+ {\vrule
+ \!!width \zeropoint
+ \!!height\strutheight
+ \!!depth \strutdepth}%
+ \else
+ \setbox\strutbox\normalhbox
+ {\normalhbox to \zeropoint
+ {% \hss % new, will be option
+ \vrule
+ \!!width \strutwidth
+ \!!height\strutheight
+ \!!depth \strutdepth
+ \hss}}%
+ \fi
+ \struttotal\dimexpr\strutht+\strutdp\relax}
+
+%D The dimen \type {\struttotal} holds the exact size of the
+%D strut; occasionally a one scaled point difference can show
+%D up with the lineheight.
+
+%D Sometimes a capstrut comes in handy
+%D
+%D \starttabulate[|Tl|l|l|]
+%D \NC yes \NC normal strut \NC {\showstruts\setupstrut[yes]\strut} \NC \NR
+%D \NC no \NC no strut \NC {\showstruts\setupstrut[no]\strut} \NC \NR
+%D \NC kap \NC a capital strut (i.e. Q) \NC {\showstruts\setupstrut[cap]\strut} \NC \NR
+%D \NC A B \unknown \NC a character strut (e.g. A) \NC {\showstruts\setupstrut[A]\strut} \NC \NR
+%D \NC \NC a normal strut \NC {\showstruts\setupstrut\strut} \NC \NR
+%D \stoptabulate
+
+\def\setupstrut
+ {\dosingleempty\dosetupstrut}
+
+\def\dosetupstrut[#1]% yet undocumented, todo: fontstrut
+ {\processaction
+ [#1]
+ [ \v!yes=>\setstrut,
+ \v!auto=>\setautostrut,
+ \v!no=>\setnostrut,
+ \v!cap=>\setcapstrut,
+ \v!fit=>\setfontstrut,
+ \v!line=>\setstrut,
+ \s!default=>\setstrut,
+ \s!unknown=>\setcharstrut\commalistelement]}
+
+\def\setteststrut
+ {\def\strutwidth{.8pt}%
+ \setstrut}
+
+\def\autostrutfactor{1.1}
+
+\def\setautostrut
+ {\begingroup
+ \setbox\scratchbox\copy\strutbox
+ \setstrut
+ \ifdim\ht\strutbox>\autostrutfactor\ht\scratchbox
+ \endgroup \setstrut
+ \else\ifdim\dp\strutbox>\autostrutfactor\dp\scratchbox
+ \endgroup \setstrut
+ \else
\endgroup
+ \fi\fi}
+
+% when enabled, sigstruts will remove themselves if nothing
+% goes inbetween
+
+\newsignal\strutsignal \setfalse\sigstruts
+
+\def\begstrut
+ {\relax\ifcase\strutht\else
+ \ifconditional\sigstruts
+ \noindent\horizontalstrut
+ \normalpenalty\plustenthousand
+ \normalhskip-\strutsignal
+ \normalhskip\strutsignal
+ \else
+ \strut
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \fi
+ \expandafter \ignorespaces
+ \fi}
+
+\def\endstrut
+ {\relax\ifhmode\ifcase\strutht\else
+ \ifconditional\sigstruts
+ \ifdim\lastskip=\strutsignal
+ \unskip\unskip\unpenalty\setbox\scratchbox\lastbox
+ \else
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \strut
+ \fi
+ \else
+ \removeunwantedspaces
+ \normalpenalty\plustenthousand
+ \normalhskip\zeropoint
+ \strut
+ \fi
+ \fi\fi}
+
+\newbox\nostrutbox \setbox\nostrutbox\normalhbox{} % {\normalhbox{}}
+
+\def\setnostrut
+ {\setbox\strutbox\copy\nostrutbox
+ \let\strut\empty
+ \let\endstrut\empty
+ \let\begstrut\empty
+ \let\crlfplaceholder\empty}
+
+% unsave:
+%
+% \def\pseudostrut
+% {\bgroup
+% \setnostrut
+% \normalstrut
+% \egroup}
+%
+% try:
+%
+% \startchemie
+% \chemie[ONE,Z0,SB15,MOV1,SB15,Z0][C,C]
+% \stopchemie
+%
+% so:
+
+\def\pseudostrut
+ {\noindent} % better: \dontleavehmode
+
+\let\pseudobegstrut\pseudostrut
+
+\let\pseudoendstrut\removeunwantedspaces
+
+\def\resetteststrut
+ {\let\strutwidth\zeropoint
+ \setstrut}
+
+\ifx\setfontparameters\undefined
+ % problems ! ! ! !
+ \def\setfontparameters{\the\everybodyfont}
+\fi
+
+%D Handy:
+
+\def\baselinedistance{\the\lineheight}
+
+%D We need \type{\normaloffinterlineskip} because the new
+%D definition contains an assignment, and |<|don't ask me
+%D why|>| this assignment gives troubles in for instance the
+%D visual debugger.
+
+%D The plain ones:
+
+\def\offinterlineskip
+ {\baselineskip-\thousandpoint
+ \lineskip\zeropoint
+ \lineskiplimit\maxdimen}
+
+\def\nointerlineskip
+ {\prevdepth-\thousandpoint}
+
+\let\normaloffinterlineskip=\offinterlineskip % knuth's original
+
+%D My own one:
+
+\def\offinterlineskip
+ {\ifdim\baselineskip>\zeropoint
+ \edef\oninterlineskip
+ {\baselineskip\the\baselineskip
+ \lineskip\the\lineskip
+ \lineskiplimit\the\lineskiplimit
+ \let\noexpand\offinterlineskip\noexpand\normaloffinterlineskip}%
+ \else
+ \let\oninterlineskip\setnormalbaselines
+ \fi
+ \normaloffinterlineskip}
+
+\let\oninterlineskip=\relax
+
+\def\leaveoutervmode
+ {\ifvmode\ifinner\else
+ \leavevmode
+ \fi\fi}
+
+% We stellen enkele penalties anders in dan Plain TEX:
+
+% oud
+%
+% \widowpenalty=\defaultwidowpenalty\relax
+% \clubpenalty =\defaultclubpenalty \relax
+
+\def\resetpenalties#1%
+ {\ifx#1\undefined\else
+ #1\minusone
+ \fi}
+
+\def\setpenalties#1#2#3%
+ {\ifx#1\undefined\else % space before #3 prevents lookahead problems, needed when #3=text
+ #1\numexpr#2+\plusone\relax\space\doexpandedrecurse{\the\numexpr#2\relax}{ #3}\zerocount\relax
+ \fi}
+
+\def\doexpandedrecurse#1#2%
+ {\ifnum#1>\zerocount#2\@EA\doexpandedrecurse\@EA{\the\numexpr#1-1\relax}{#2}\fi}
+
+%D \macros
+%D {keeplinestogether}
+%D
+%D Dirty hack, needed in margin content that can run of a page.
+
+\def\keeplinestogether#1%
+ {\xdef\restoreinterlinepenalty{\global\resetpenalties\interlinepenalties}%
+ \global\setpenalties\interlinepenalties{#1}\plustenthousand}
+
+\newif\ifgridsnapping % to be sure
+
+\def\defaultwidowpenalty {2000} % was: 1000
+\def\defaultclubpenalty {2000} % was: 800
+\def\defaultdisplaywidowpenalty {50}
+\def\defaultbrokenpenalty {100}
+
+\def\defaultgridwidowpenalty {0}
+\def\defaultgridclubpenalty {0}
+\def\defaultgriddisplaywidowpenalty {0}
+\def\defaultgridbrokenpenalty {0}
+
+\def\nopenalties
+ {\widowpenalty \zerocount
+ \clubpenalty \zerocount
+ \brokenpenalty \zerocount
+ \doublehyphendemerits\zerocount
+ \finalhyphendemerits \zerocount
+ \adjdemerits \zerocount}
+
+\def\setdefaultpenalties
+ {\directsetup{\systemsetupsprefix\s!default}}
+
+\startsetups [\systemsetupsprefix\s!reset]
+ \resetpenalties\widowpenalties
+ \resetpenalties\clubpenalties
+ \resetpenalties\interlinepenalties
+\stopsetups
+
+% we use \directsetup because it's faster and we know there is no csl
+
+\startsetups [\systemsetupsprefix\s!default]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \widowpenalty \defaultwidowpenalty
+ \clubpenalty \defaultclubpenalty
+ \displaywidowpenalty\defaultdisplaywidowpenalty
+ \brokenpenalty \defaultbrokenpenalty
+
+\stopsetups
+
+\startsetups [\v!grid] [\systemsetupsprefix\s!default]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \widowpenalty \defaultgridwidowpenalty
+ \clubpenalty \defaultgridclubpenalty
+ \displaywidowpenalty\defaultgriddisplaywidowpenalty
+ \brokenpenalty \defaultgridbrokenpenalty
+
+\stopsetups
+
+% as an illustration:
+
+\startsetups [\systemsetupsprefix\v!strict]
+
+ \directsetup{\systemsetupsprefix\s!reset}
+
+ \setpenalties\widowpenalties2\maxdimen
+ \setpenalties\clubpenalties 2\maxdimen
+ \brokenpenalty \maxdimen
+
+\stopsetups
+
+\setdefaultpenalties % will happen later in \setuplayout
+
+% Suggested by GB (not the name -):
+
+\def\rapfillskip{.5\hsize plus .092\hsize minus .5\hsize} % D.A.'s value
+
+% Bovendien definieren we enkele extra \fill's:
+
+\def\hfilll{\hskip\zeropoint\!!plus1filll\relax}
+\def\vfilll{\vskip\zeropoint\!!plus1filll\relax}
+
+% De onderstaande hulpmacro's moeten nog eens instelbaar worden
+% gemaakt.
+
+\def\tfskipsize{1em\relax}
+\def\tfkernsize{1ex\relax}
+
+\def\tfskip{\dotfskip\tfskipsize}
+\def\tfkern{\dotfkern\tfkernsize}
+
+\def\dotfskip#1{{\tf\hskip#1}}
+\def\dotfkern#1{{\tf\kern #1}}
+
+% needs a proper \definenarrower or installnarrower
+
+\newskip\ctxleftskip
+\newskip\ctxrightskip
+\newskip\ctxmidskip
+
+\def\dosinglenarrower#1%
+ {\processaction
+ [#1]
+ [ \v!left=>\global\advance\ctxleftskip \@@slleft,
+ \v!middle=>\global\advance\ctxmidskip \@@slmiddle,
+ \v!right=>\global\advance\ctxrightskip \@@slright,
+ \v!reset=>\global\ctxleftskip \zeropoint
+ \global\ctxmidskip \zeropoint
+ \global\ctxrightskip\zeropoint,
+ \v!none=>,
+ \s!unknown=>\global\advance\ctxmidskip \commalistelement]}
+
+\def\donarrower[#1]% hm, can be dorepeat directly
+ {\dorepeatwithcommand[#1]\dosinglenarrower}
+
+\def\complexstartnarrower[#1]%
+ {\@@slbefore % was hard coded \par
+ \bgroup
+ \global\ctxleftskip \zeropoint
+ \global\ctxrightskip\zeropoint
+ \global\ctxmidskip \zeropoint
+ \processcommalistwithparameters[#1]\donarrower
+ \advance\leftskip \ctxleftskip
+ \advance\rightskip \ctxrightskip
+ \advance\leftskip \ctxmidskip
+ \advance\rightskip \ctxmidskip
+ \seteffectivehsize}
+
+% todo: definenarrower
+
+\def\simplestartnarrower
+ {\startnarrower[\v!middle]}
+
+\definecomplexorsimple\startnarrower
+
+\def\stopnarrower
+ {\@@slafter % was hard coded \par / needed, else skips forgotten
+ \egroup}
+
+\def\setupnarrower
+ {\dodoubleargument\getparameters[\??sl]}
+
+\newdimen\@@effectivehsize \def\effectivehsize {\hsize}
+\newdimen\@@effectiveleftskip \def\effectiveleftskip {\leftskip}
+\newdimen\@@effectiverightskip \def\effectiverightskip{\rightskip}
+
+\def\seteffectivehsize
+ {\setlocalhsize
+ \@@effectivehsize \localhsize
+ \@@effectiveleftskip \leftskip
+ \@@effectiverightskip \rightskip
+ \let\effectivehsize \@@effectivehsize
+ \let\effectiveleftskip \@@effectiveleftskip
+ \let\effectiverightskip\@@effectiverightskip}
+
+\unexpanded\def\lefttoright{\textdir TLT\pardir TLT\relax}
+\unexpanded\def\righttoleft{\textdir TRT\pardir TRT\relax}
+
+\def\dodefinehbox[#1][#2]%
+ {\setvalue{hbox#1}##1%
+ {\hbox to #2{\begstrut##1\endstrut\hss}}}
+
+\def\definehbox
+ {\dodoubleargument\dodefinehbox}
+
+\def\iobox#1#2#3#% here #3# is not really needed
+ {\vbox\bgroup % we want to return a vbox like the others
+ \hbox\bgroup% we need to pack the signal with the box
+ \signalrightpage
+ \dowithnextboxcontent
+ {\let\\=\endgraf\forgetall\doifrightpageelse#1#2}
+ {\box\nextbox\egroup\egroup}
+ \vbox#3}
+
+\def\obox{\iobox\raggedleft \raggedright} % outerbox
+\def\ibox{\iobox\raggedright\raggedleft} % innerbox
+
+\def\dosetraggedvbox#1%
+ {\let\raggedbox\vbox
+ \processfirstactioninset
+ [#1]
+ [ \v!left=>\let\raggedbox\lbox,
+ \v!right=>\let\raggedbox\rbox,
+ \v!middle=>\let\raggedbox\cbox,
+ \v!inner=>\let\raggedbox\ibox,
+ \v!outer=>\let\raggedbox\obox,
+ \v!flushleft=>\let\raggedbox\rbox,
+ \v!flushright=>\let\raggedbox\lbox,
+ \v!center=>\let\raggedbox\cbox,
+ \v!no=>\def\raggedbox{\vbox\bgroup\raggedright\let\next=}]}
+
+\def\dosetraggedhbox#1%
+ {\let\raggedbox\hbox
+ \processaction % slow
+ [#1]
+ [ \v!left=>\def\raggedbox{\doalignedline\v!left },
+ \v!right=>\def\raggedbox{\doalignedline\v!right },
+ \v!middle=>\def\raggedbox{\doalignedline\v!middle},
+ \v!inner=>\def\raggedbox{\doalignedline\v!inner },
+ \v!outer=>\def\raggedbox{\doalignedline\v!outer },
+ \v!flushleft=>\def\raggedbox{\doalignedline\v!right },
+ \v!flushright=>\def\raggedbox{\doalignedline\v!left },
+ \v!center=>\def\raggedbox{\doalignedline\v!middle}]}
+
+\def\dosetraggedcommand#1%
+ {\expanded{\dodosetraggedcommand{#1}}}
+
+\newtoks\everyraggedcommand
+
+\def\raggedcommand{\the\everyraggedcommand}
+
+\def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that!
+ {\everyraggedcommand \emptytoks
+ \let\raggedtopcommand \empty
+ \let\raggedbottomcommand\empty
+ \chardef\raggedoneliner\zerocount
+ \doifsomething{#1}
+ {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse
+ \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse
+ \!!donectrue
+ \rawprocesscommalist[#1]\dododosetraggedcommand}}
+
+\def\dododosetraggedcommand#1%
+ {\executeifdefined{\@@ragged@@command\string#1}\relax}
+
+\def\@@ragged@@command{@@raggedcommand}
+
+\setvalue{\@@ragged@@command\v!hanging }{\appendtoks\enableprotruding \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nothanging }{\appendtoks\disableprotruding \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!hz }{\appendtoks\enableadjusting \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nohz }{\appendtoks\disableadjusting \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!spacing }{\appendtoks\enablespacehandling
+ \enablekernhandling \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nospacing }{\appendtoks\disablespacehandling
+ \disablekernhandling \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!hyphenated }{\appendtoks\dohyphens \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!nothyphenated}{\appendtoks\nohyphens \to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!tolerant }{\appendtoks\tolerance3000\relax \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!verytolerant}{\appendtoks\tolerance4500\relax \to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!stretch }{\appendtoks\emergencystretch\bodyfontsize\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!left}%
+ {\if!!donea \appendtoks\veryraggedleft\to\everyraggedcommand
+ \else \appendtoks\raggedleft \to\everyraggedcommand
+ \fi
+ \!!donecfalse}
+
+\setvalue{\@@ragged@@command\v!right}%
+ {\if!!donea \appendtoks\veryraggedright\to\everyraggedcommand
+ \else \appendtoks\raggedright \to\everyraggedcommand
+ \fi
+ \!!donecfalse}
+
+\setvalue{\@@ragged@@command\v!middle}%
+ {\if!!donec
+ \if!!doneb \appendtoks\raggedwidecenter\to\everyraggedcommand
+ \else\if!!donea \appendtoks\veryraggedcenter\to\everyraggedcommand
+ \else \appendtoks\raggedcenter \to\everyraggedcommand
+ \fi\fi
+ \!!donecfalse
+ \else
+ \let\raggedbottomcommand\vfilll % bonus, pretty strong
+ \let\raggedtopcommand \vfilll % used with \framed for
+ \fi} % instance in tables
+
+\setvalue{\@@ragged@@command\v!flushleft }{\getvalue{\@@ragged@@command\v!right }}
+\setvalue{\@@ragged@@command\v!flushright}{\getvalue{\@@ragged@@command\v!left }}
+\setvalue{\@@ragged@@command\v!center }{\getvalue{\@@ragged@@command\v!middle}}
+
+\setvalue{\@@ragged@@command\v!high}%
+ {\let\raggedbottomcommand\vfilll} % and since we lack a
+
+\setvalue{\@@ragged@@command\v!low}%
+ {\let\raggedtopcommand\vfilll} % proper keyword, but
+
+\setvalue{\@@ragged@@command\v!lohi}%
+ {\let\raggedbottomcommand\vfilll % we do support the
+ \let\raggedtopcommand\vfilll} % ugly laho (lohi)
+
+\setvalue{\@@ragged@@command\v!no}%
+ {\appendtoks\raggedright\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!yes}%
+ {\appendtoks\notragged\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!normal}%
+ {\appendtoks\notragged\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!inner}% not yet perfect
+ {\signalrightpage % may interfere
+ \doifrightpageelse
+ {\getvalue{\@@ragged@@command\v!right}}
+ {\getvalue{\@@ragged@@command\v!left}}}
+
+\setvalue{\@@ragged@@command\v!outer}% not yet perfect
+ {\signalrightpage % may interfere
+ \doifrightpageelse
+ {\getvalue{\@@ragged@@command\v!left}}
+ {\getvalue{\@@ragged@@command\v!right}}}
+
+\setvalue{\@@ragged@@command\v!lesshyphenation}%
+ {\appendtoks\lesshyphens\to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!morehyphenation}%
+ {\appendtoks\morehyphens\to\everyraggedcommand}
+
+\setvalue{\@@ragged@@command\v!lefttoright}{\appendtoks\lefttoright\to\everyraggedcommand}
+\setvalue{\@@ragged@@command\v!righttoleft}{\appendtoks\righttoleft\to\everyraggedcommand}
+\setvalue{\@@ragged@@command l2r}{\appendtoks\lefttoright\to\everyraggedcommand}
+\setvalue{\@@ragged@@command r2l}{\appendtoks\righttoleft\to\everyraggedcommand}
+
+% compare:
+%
+% \framed[width=4cm,align=no] {\hfil xxx}
+% \framed[width=4cm,align=disable]{\hfil xxx}
+
+\setvalue{\@@ragged@@command\v!disable}% for one liners
+ {\appendtoks\raggedright\parfillskip\zeropoint\to\everyraggedcommand}
+
+\chardef\raggedoneliner\zerocount
+
+\setvalue{\@@ragged@@command\v!line}%
+ {\chardef\raggedoneliner\plusone}
+
+% Nog doen:
+%
+% \goodbreak -> \allowbreak en \dosomebreak{..} in koppen
+%
+% bij koppen zowieso: \blanko[reset]
+
+% Nog in commando verwerken:
+%
+% \voorkeur la \blanko
+%
+% Om ongewenste witruimte te voorkomen kan met \dosomebreak{\break}
+% een \penalty voor witruimte worden geplaatst.
+
+\def\removelastskip % a redefinition of plain
+ {\ifvmode\ifdim\lastskip=\zeropoint\else\vskip-\lastskip\fi\fi}
+
+\def\doifoutervmode#1%
+ {\ifvmode\ifinner\else#1\fi\fi}
+
+\ifx\dosomebreak\undefined % defined in mkiv
+
+ \def\dosomebreak#1%
+ {\doifoutervmode
+ {\scratchskip\lastskip
+ \removelastskip
+ %\leavevmode\type{#1}%
+ #1\relax
+ \ifdim\scratchskip=\zeropoint % else interference with footnotes
+ \else
+ \vskip\scratchskip
+ \fi}}
+
+\fi
+
+\def\forgeteverypar
+ {\everypar{\the\neverypar}}
+
+\def\forgetparindent
+ {\forgeteverypar
+ \indentfirstparagraphtrue % recently added
+ \let\currentindentation\v!none
+ \ctxparindent\zeropoint
+ \parindent\zeropoint\relax}
+
+\def\forgetparskip
+ {\let\currentwhitespace\v!none
+ \ctxparskip\zeropoint
+ \parskip\zeropoint\relax}
+
+\def\forgetbothskips
+ {\tolerance1500
+ \leftskip\zeropoint
+ \rightskip\zeropoint\relax}
+
+\def\forgetspacing
+ {\emergencystretch\zeropoint}
+
+\newif\ifforgotten % rather good signal for inner
+
+\appendtoks \forgottentrue \to \everyforgetall
+\appendtoks \forgetragged \to \everyforgetall
+\appendtoks \forgetparskip \to \everyforgetall
+\appendtoks \forgetparindent \to \everyforgetall
+\appendtoks \forgetbothskips \to \everyforgetall
+\appendtoks \forgetspacing \to \everyforgetall % i.v.m. funny spacing in pagebody
+\appendtoks \spacing\!!plusone \to \everyforgetall % new per 10/08/2004, else problems in otr / !! needed
+\appendtoks \everypar\emptytoks \to \everyforgetall % indeed!
+
+\def\localvbox#1#%
+ {\vbox#1\bgroup
+ \forgetparskip
+ \setlocalhsize
+ \hsize\localhsize
+ \forgetparindent
+ \forgetbothskips
+ \forgeteverypar
+ \let\next=}
+
+\let\dostopattributes\relax % in case these commands end up in an edef
+
+% \unexpanded\def\dostartattributes#1#2#3%
+% {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+% \ifcsname#1#3\endcsname
+% \let\dostopattributes\@@dostopattributes
+% \startcolor[\csname#1#3\endcsname]%
+% \else
+% \let\dostopattributes\@@nostopattributes
+% \fi
+% \ifcsname#1#2\endcsname
+% \expandafter\doconvertfont
+% \else
+% \expandafter\gobbleoneargument
+% \fi{\csname#1#2\endcsname}}
+
+\newconditional \parbasedattributes
+
+\def\finishparbasedattributes
+ {\ifconditional\parbasedattributes
+ \setfalse\parbasedattributes
+ \par
\fi}
-\def\setcharacterkerning
- {\ctxlua{kerns.enabled=true}%
- \gdef\setcharacterkerning[##1]{\dosetattribute{kern}{\csname\??ck:##1\endcsname}}%
- \setcharacterkerning}
+\def\dostopparbasedattributes
+ {\settrue\parbasedattributes
+ \dostopattributes}
+
+\unexpanded\def\@@dostopattributes
+ {\stopcolor
+ \finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\@@nostopattributes
+ {\finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\doattributes#1#2#3#4%
+ {\dostartattributes{#1}{#2}{#3}{#4}\dostopattributes}
+
+% An even faster \ETEX\ version:
+
+\unexpanded\def\dostartattributes#1#2#3%
+ {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+ \ifincolor
+ \ifcsname#1#3\endcsname
+ \let\dostopattributes\@@dostopattributes
+ \faststartcolor[\csname#1#3\endcsname]%
+ \else
+ \let\dostopattributes\@@nostopattributes
+ \fi
+ \else
+ \let\dostopattributes\@@nostopattributes
+ \fi
+ \ifcsname#1#2\endcsname
+ % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi}
+
+\unexpanded\def\@@dostopattributes
+ {\faststopcolor
+ \finishparbasedattributes
+ \endgroup}
+
+\unexpanded\def\@@nostopattributes
+ {\finishparbasedattributes
+ \endgroup}
+
+%D Bonus macro, see core-sec.tex
+
+\unexpanded\def\dosetfontattribute#1#2%
+ {\ifcsname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi\empty}
+
+%D Since this happens a lot, and sometimes large arguments
+%D are passed in \type {#4}, we just copy some code:
+
+\unexpanded\def\doattributes#1#2#3#4%
+ {\begingroup % geen \bgroup, anders in mathmode lege \hbox
+ \ifincolor
+ \ifcsname#1#3\endcsname
+ \let\dostopattributes\@@dostopattributes
+ \faststartcolor[\csname#1#3\endcsname]%
+ \else
+ \let\dostopattributes\endgroup
+ \fi
+ \else
+ \let\dostopattributes\endgroup
+ \fi
+ \ifcsname#1#2\endcsname
+ % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
+ \@EA\doconvertfont\csname#1#2\@EA\endcsname
+ \fi
+ {#4}%
+ \dostopattributes}
+
+% Kan vaker worden toegepast en moet bovendien sneller!
+
+\newskip\leftskipadaption
+\newskip\rightskipadaption
+
+\def\doadaptleftskip#1%
+ {\dosetleftskipadaption{#1}%
+ \advance\leftskip \leftskipadaption}
+
+\def\doadaptrightskip#1%
+ {\dosetrightskipadaption{#1}%
+ \advance\rightskip \rightskipadaption}
+
+\setvalue{@lsa@\v!standard}{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
+\setvalue{@lsa@\v!yes }{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
+\letvalue{@lsa@\v!no }\zeropoint
+\letvalue{@lsa@\empty }\zeropoint
+\setvalue{@rsa@\v!standard}{\@@slright}
+\setvalue{@rsa@\v!yes }{\@@slright}
+\letvalue{@rsa@\v!no }\zeropoint
+\letvalue{@rsa@\empty }\zeropoint
+
+\def\dosetleftskipadaption#1%
+ {\edefconvertedargument\ascii{@lsa@#1}%
+ \leftskipadaption
+ \ifcsname\ascii\endcsname
+ \csname\ascii\endcsname
+ \else
+ #1%
+ \fi
+ \relax}
+
+\def\dosetrightskipadaption#1%
+ {\edefconvertedargument\ascii{@rsa@#1}%
+ \rightskipadaption
+ \ifcsname\ascii\endcsname
+ \csname\ascii\endcsname
+ \else
+ #1%
+ \fi
+ \relax}
+
+\newcount \noftrackedpagestates
+\newif \ifpagestatemismatch
+\newcount \realpagestateno
+\chardef \frozenpagestate \zerocount
+
+\def\dotrackpagestate#1#2%
+ {\ifdoublesided \ifinpagebody \else
+ \doforcedtrackpagestate{#1}{#2}%
+ \fi \fi}
+
+\def\doforcedtrackpagestate#1#2%
+ {\ifcase\frozenpagestate
+ \global\advance\noftrackedpagestates\plusone
+ \global\advance#2\plusone
+ \lazysavetaggedtwopassdata{#1}{\number\noftrackedpagestates}{\number#2}{\noexpand\realfolio}%
+ %\llap{\infofont\number\noftrackedpagestates/\number#2}% tracing
+ \fi}
+
+\def\doifrightpagestateelse#1#2%
+ {\ifcase\frozenpagestate
+ \pagestatemismatchfalse
+ \realpagestateno\realfolio
+ \ifinpagebody
+ \ifdoublesided
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \twopassdatafoundtrue
+ \fi
+ \else\ifdoublesided
+ \findtwopassdata{#1}{\number#2}%
+ \iftwopassdatafound
+ \realpagestateno\twopassdata\relax
+ \ifnum\twopassdata=\realpageno \else
+ \pagestatemismatchtrue
+ \fi
+ \ifodd\twopassdata\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \else
+ \twopassdatafoundtrue
+ \fi\fi
+ \else
+ \ifodd\realpagestateno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \iftwopassdatafound
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+\def\doifforcedrightpagestateelse#1#2%
+ {\ifcase\frozenpagestate
+ \pagestatemismatchfalse
+ \realpagestateno\realfolio
+ \findtwopassdata{#1}{\number#2}%
+ \iftwopassdatafound
+ \realpagestateno\twopassdata\relax
+ \ifnum\twopassdata=\realpageno \else
+ \pagestatemismatchtrue
+ \fi
+ \ifodd\twopassdata\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \else
+ \ifodd\realpageno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \else
+ \ifodd\realpagestateno\relax
+ \twopassdatafoundtrue \else \twopassdatafoundfalse
+ \fi
+ \fi
+ \iftwopassdatafound
+ \@EA\firstoftwoarguments
+ \else
+ \@EA\secondoftwoarguments
+ \fi}
+
+\def\freezepagestate {\chardef\frozenpagestate\plusone }
+\def\defrostpagestate{\chardef\frozenpagestate\zerocount}
+
+% we can make more of these on top, but how to deal with mixed frozen states
+
+\definetwopasslist\s!paragraph \newcount \nofraggedparagraphs
+
+\def\signalrightpage {\dotrackpagestate \s!paragraph\nofraggedparagraphs}
+\def\doifrightpageelse{\doifrightpagestateelse\s!paragraph\nofraggedparagraphs}
+
+\newcount\pagesignallevel
+
+\def\startsignalrightpage % one may do a \postsignalrightplace
+ {\advance\pagesignallevel\plusone
+ \presignalrightpage
+ \let\signalrightpage\relax
+ \let\presignalrightpage\relax
+ \let\startsignalrightpage\relax
+ \doifrightpageelse\donothing\donothing
+ \freezepagestate}
+
+\def\stopsignalrightpage
+ {\ifcase\pagesignallevel\or\postsignalrightpage\fi
+ \advance\pagesignallevel\minusone}
+
+\def\setraggedparagraphmode
+ {\signalrightpage\doifrightpageelse} % move it there
+
+\ifx\swapmargins\undefined \let\swapmargins\undefined \fi % todo
+
+\def\doifswappedrightpageelse#1#2% alleen in box construction !
+ {\doifrightpageelse
+ {#1}
+ {\scratchcounter\realpageno
+ \realpageno\realpagestateno\relax
+ \swapmargins
+ \realpageno\scratchcounter
+ #2}}
+
+\newbox\signaledrightpage % this way we can avoid interference, i.e. postpone placement
+
+\def\presignalrightpage {\global\setbox\signaledrightpage\hbox{\signalrightpage}}
+\def\postsignalrightpage{\ifvoid\signaledrightpage\else\box\signaledrightpage\fi}
-\letvalue{\??ck:\s!reset}\minusone
+% The next feature is is used in:
+%
+% \definenumber[test][way=bypage]
+%
+% \def\Test
+% {\incrementnumber[test]\rawnumber[test]/%
+% \incrementnumber[test]\rawnumber[test]/%
+% \incrementnumber[test]\rawnumber[test]\space
+% \checkpagechange{oeps}\changedpage{oeps}\space
+% \ifpagechanged TRUE\else FALSE\fi}
+%
+% \Test\page \Test\par \Test\page \Test\par \Test\page \Test\page
+%
+% (adapted from cont-new.tex:)
-\definecharacterkerning[extrakerning]
+\newif\ifpagechanged \let\lastchangedpage\empty
-\setupcharacterkerning[extrakerning][\c!factor=.125]
+\def\docheckpagestatechange#1#2#3%
+ {\pagechangedfalse
+ \doforcedtrackpagestate{#2}{#3}%
+ \findtwopassdata{#2}{\number#3}%
+ \iftwopassdatafound
+ \ifnum\twopassdata>0\getvalue{#2:p:#1}\relax
+ \pagechangedtrue
+ \fi
+ \fi
+ \ifpagechanged
+ \letgvalue{#2:p:#1}\twopassdata
+ \globallet\lastchangedpage\twopassdata
+ \else
+ \globallet\lastchangedpage\realfolio
+ \fi}
-% sorry, here:
+\def\changedpagestate#1#2%
+ {\executeifdefined{#2:p:#1}{0}}
-% test \WORD{test TEST \TeX} test
-% test \word{test TEST \TeX} test
-% test \Word{test TEST \TeX} test
+\def\checkpagechange#1{\docheckpagestatechange{#1}\s!paragraph\nofraggedparagraphs}
+\def\changedpage #1{\changedpagestate{#1}\s!paragraph}
-\defineattribute[case]
+% saved struts
-\def\setcharactercasing
- {\ctxlua{cases.enabled=true}%
- \gdef\setcharactercasing[##1]{\dosetattribute{case}{\number##1}}%
- \setcharactercasing}
+\ifx\savedstrutbox\undefined \newbox\savedstrutbox \fi
-\def\WORD {\groupedcommand{\setcharactercasing[\plusone ]}{}}
-\def\word {\groupedcommand{\setcharactercasing[\plustwo ]}{}}
-\def\Word {\groupedcommand{\setcharactercasing[\plusthree]}{}}
-\def\Words{\groupedcommand{\setcharactercasing[\plusfour]}{}}
+\def\savestrut {\setbox\savedstrutbox\copy\strutbox}
+\def\savedstrut{\copy \savedstrutbox}
-\let\WORDS\WORD
-\let\words\word
+\chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
-% \definestartstop is not yet in available at core-spa time
-%
-% \startrandomized \input tufte \stoprandomized
-%
-% \definestartstop[randomized][\c!before=\dosetattribute{case}{8},\c!after=]
+\def\bottomalignlimit{3\lineheight}
-\def\randomizetext{\groupedcommand{\dosetattribute{case}{8}}{}}
+\newif\ifn@rmalbottom
+\newif\ifr@ggedbottom
+\newif\ifb@selinebottom
-% compound stuff (under construction)
+\def\normalbottom
+ {% \topskip 10pt
+ \r@ggedbottomfalse}
-\defineattribute[breakpoint]
+\def\raggedbottom
+ {\chardef\bottomraggedness\zerocount
+ \n@rmalbottomfalse
+ \r@ggedbottomtrue
+ \b@selinebottomfalse
+ \settopskip}
-\newbox\breakpointbox
+\def\alignbottom
+ {\chardef\bottomraggedness\plusone
+ \n@rmalbottomtrue
+ \r@ggedbottomfalse
+ \b@selinebottomfalse
+ \settopskip}
-\definesystemvariable {bp} % BreakPoint
+\def\baselinebottom
+ {\chardef\bottomraggedness\plustwo
+ \n@rmalbottomfalse
+ \r@ggedbottomfalse
+ \b@selinebottomtrue
+ \settopskip}
-\exhyphenchar=\minusone % we use a different order then base tex, so we really need this
+\let\normalbottom=\alignbottom % downward compatible
-\newcount \maxbreakpointsid
+% new code, not in use yet
-\def\definebreakpoints
- {\dosingleargument\dodefinebreakpoints}
+% for future chinese typo-module:
+%
+% % \let\raggedleft\veryraggedleft
+% % \let\raggedleft\veryraggedright
+%
+% \startbuffer
+% 中中中中中中中中中中中中中中中中中中中中中中中中中%
+% 中中中中中中中中中中中中中中中中中中中中中中中中中%
+% 中中中中中中中中中中中中中中中中中中中中中中中中中%
+% 中中中中中中中中中中中中中中中中中中中中中中中中中%
+% \stopbuffer
+%
+% \framedtext
+% [align={broad,flushright},width=90mm]
+% {\getbuffer}
+%
+% \framedtext
+% [align={broad,flushleft},width=90mm]
+% {\getbuffer}
+%
+% \framedtext
+% [align=middle,width=90mm]
+% {\getbuffer}
+%
+% using just flushleft is not okay here due to the fact that
+% leftskip has less stretch than the inter character spacing
-\def\dodefinebreakpoints[#1]%
- {\ifcsname\??bp:#1\endcsname \else
- \global\advance\maxbreakpointsid\plusone
- \setxvalue{\??bp:#1}{\the\maxbreakpointsid}%
- \fi}
+% category:
+%
+% 0 == discard
+% 1 == only if larger
+% 2 == force even if smaller
+% 3 == only take penalty component
+% 4 == add to existing skip
+% 5 == ignore following skips (== disable)
-\def\installbreakpoint
- {\dotripleempty\doinstallbreakpoint}
+% penalty:
+%
+% larger wins
-% hm, we cannot prebuild lists, font dependent
+% order:
+%
+% larger wins
-\def\doinstallbreakpoint[#1][#2][#3]%
- {\ifcsname\??bp:#1\endcsname
- \begingroup
- \getparameters[\??bp][\c!type=1,\c!nleft=3,\c!nright=3,#3]%
- \ctxlua{breakpoints.setreplacement(\csname\??bp:#1\endcsname,#2,\@@bptype,\@@bpnleft,\@@bpnright)}%
- \endgroup
- \fi}
+\registerctxluafile{core-spa}{1.001}
-\def\setbreakpoints
- {\ctxlua{breakpoints.enabled=true}%
- \gdef\setbreakpoints[##1]{\dosetattribute{breakpoint}{\csname\??bp:##1\endcsname}}%
- \setbreakpoints}
+\definesystemattribute[kern-chars]
+\definesystemattribute[skip-category]
+\definesystemattribute[skip-penalty]
+\definesystemattribute[skip-order]
+\definesystemattribute[snap-category]
+\definesystemattribute[display-math]
-\letvalue{\??bp:\s!reset}\minusone
+% \start \dosetstretch{.25em} \setuptolerance[tolerant,stretch] \input tufte \endgraf \stop
+% \start \dosetstretch{.5em} effe flink doorfietsen \stop
-\definebreakpoints[compound]
+\def\dosetupgridsnapping % calls too often, only needed in gridsnapping
+ {\ctxlua{nodes.setsnapvalue(1,\number\openstrutheight,\number\openstrutdepth)}}
-\installbreakpoint [compound] [\number`+] [\c!left=3,\c!right=3,\c!type=1]
-\installbreakpoint [compound] [\number`-] [\c!left=3,\c!right=3,\c!type=1]
-\installbreakpoint [compound] [\number`/] [\c!left=3,\c!right=3,\c!type=1]
-\installbreakpoint [compound] [\number`(] [\c!left=3,\c!right=3,\c!type=2]
-\installbreakpoint [compound] [\number`)] [\c!left=3,\c!right=3,\c!type=3]
+\def\doenablegridsnapping
+ {\dosetattribute{snap-category}{1}%
+ \topskip\strutht
+ \offinterlineskip}
-% \setbreakpoints[compound]
+\def\dodisablegridsnapping
+ {\doresetattribute{snap-category}%
+ % reset topskip
+ \oninterlineskip}
% experimental code, not yet interfaced:
@@ -355,7 +2860,7 @@
\def\dodefinevspacing[#1][#2]%
{\ctxlua{vspacing.setmap("#1","#2")}}
-\def\vspacing
+\unexpanded\def\vspacing
{\dosingleempty\dovspacing}
\def\dovspacing[#1]%
@@ -395,30 +2900,1209 @@
\setfalse\vspacingenabled
-% \def\dosomebreak#1%
-% {\doifoutervmode
-% {\scratchskip\lastskip
-% \removelastskip
-% #1\relax
-% \ifconditional\vspacingenabled
-% % we have collapsed so always 0pt
-% \vskip\scratchskip
-% \else\ifdim\scratchskip=\zeropoint
-% % else interference with footnotes
-% \else
-% \vskip\scratchskip
-% \fi\fi}}
-
% ! ! ! ! ! later, now each newline does a \par and call to the callback
-\def\enablevspacing {\settrue \vspacingenabled\ctxlua{vspacing.enable()}}
-\def\disablevspacing{\setfalse\vspacingenabled\ctxlua{vspacing.disable()}}
+\newtoks\everyenablevspacing
+\newtoks\everydisablevspacing
+
+\def\enablevspacing {\the\everyenablevspacing}
+\def\disablevspacing{\the\everydisablevspacing}
+
+\appendtoks
+ \writestatus\m!systems{! ! enabling vspacing ! !}%
+ \settrue\vspacingenabled
+ \ctxlua{vspacing.enable()}%
+\to \everyenablevspacing
+
+\appendtoks
+ \writestatus\m!systems{! ! disabling vspacing ! !}%
+ \setfalse\vspacingenabled
+ \ctxlua{vspacing.disable()}%
+\to \everydisablevspacing
+
+\let\originalblank \blank % we use \original for non-primitives
+\let\originalvspacing\vspacing
\let\setupvspacing\setupblank % for the moment
-\protect \endinput
+% so, the new one will be
+%
+% \chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
+%
+% \def\bottomalignlimit{3\lineheight} % will be settable
+%
+% \def\raggedbottom {\chardef\bottomraggedness=0 \settopskip}
+% \def\alignbottom {\chardef\bottomraggedness=1 \settopskip}
+% \def\baselinebottom{\chardef\bottomraggedness=2 \settopskip}
+%
+% \let\normalbottom =\alignbottom
+
+% \hyphenpenalty = ( 2.5 * \hsize ) / \raggedness
+% \tolerance >= 1500 % was 200
+% \raggedness = 2 .. 6\bodyfontsize
+
+\chardef\raggedstatus=0 % normal left center right
+
+\def\leftraggedness {2\bodyfontsize}
+\def\rightraggedness {2\bodyfontsize}
+\def\middleraggedness {6\bodyfontsize}
+
+\def\middleraggedness {.5\hsize} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
+
+% oeps, hsize can be 0pt in which case we get a strange division
+
+\def\middleraggedness {\ifdim\hsize=\zeropoint6\bodyfontsize\else.5\hsize\fi} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
+
+%D More hyphenation control, will be combined with align
+%D setup.
+
+\def\nohyphens
+ {\ifx\dohyphens\relax
+ \edef\dohyphens
+ {\hyphenpenalty\the\hyphenpenalty
+ \exhyphenpenalty\the\exhyphenpenalty\relax}%
+ \fi
+ \hyphenpenalty\plustenthousand
+ \exhyphenpenalty\plustenthousand}
+
+\let\dohyphens\relax
+
+%D To prevent unwanted side effects, we also have to check
+%D for hyphens here:
+
+\newskip\@@raggedskipa
+\newskip\@@raggedskipb
+
+\def\setraggedness#1%
+ {\ifnum\tolerance<1500\relax % small values have
+ \tolerance1500\relax % unwanted side effects
+ \fi
+ \ifx\dohyphens\relax
+ % this code will be reconsidered / kind of fuzzy (and old)
+ \@@raggedskipa 2.5\hsize
+ \@@raggedskipb #1\relax
+ \divide\@@raggedskipa \@@raggedskipb
+ \hyphenpenalty\@@raggedskipa
+ \fi}
+
+\let\updateraggedskips\relax
+
+\def\setraggedskips#1#2#3#4#5#6#7% never change this name
+ {\def\updateraggedskips{\dosetraggedskips{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
+ \updateraggedskips}
+
+\def\dosetraggedskips#1#2#3#4#5#6#7%
+ {\chardef \raggedstatus#1\relax
+ \leftskip 1\leftskip \!!plus#2\relax % zie: Tex By Topic 8.1.3
+ \rightskip 1\rightskip\!!plus#3\relax % zie: Tex By Topic 8.1.3
+ \spaceskip #4\relax
+ \xspaceskip #5\relax
+ \parfillskip\zeropoint\!!plus#6\relax
+ \parindent #7\relax}
+
+% \def\notragged%
+% {\setraggedskips{0}{0em}{0em}{0em}{0em}{1fil}{\parindent}}
+
+% older (context) names:
+
+\let\spaceamount \interwordspace
+\let\emspaceamount\emwidth
+
+% tracing:
+
+\def\doshowpardata#1%
+ {\ifx#1\relax\else
+ \hbox{\string#1: \the#1}\endgraf
+ \expandafter\doshowpardata
+ \fi}
+
+\def\showpardata
+ {\edef\thepardata
+ {\hbox{font: \fontname\font}\endgraf
+ \doshowpardata
+ \interwordspace \interwordstretch \interwordshrink \emwidth \exheight \extraspace
+ \hsize \vsize
+ \leftskip \rightskip
+ \spaceskip \xspaceskip
+ \parindent \parfillskip
+ \hyphenpenalty \exhyphenpenalty
+ \displaywidowpenalty \widowpenalty \clubpenalty \brokenpenalty
+ \doublehyphendemerits \finalhyphendemerits \adjdemerits
+ \relax}%
+ \begingroup
+ \dontshowcomposition
+ \inleftmargin{\vsmash
+ {\switchtobodyfont[7pt,tt]%
+ \framed[\c!align=\v!right]{\thepardata}}}%
+ \endgroup}
+
+\def\startshowpardata
+ {\begingroup
+ \showcomposition
+ \showstruts\tracepositionstrue \tracingparagraphs\maxdimen
+ \appendtoksonce\showpardata\let\showpardata\relax\to\everypar}
+
+\def\stopshowpardata
+ {\endgraf
+ \endgroup}
+
+% \defineXMLenvironment[showpardata] \startshowpardata \stopshowpardata
+% \defineXMLsingular [showpardata] \showpardata
+
+% defaults
+
+\def\raggedfillamount {1fil}
+\def\raggedhalffillamount{.5fil}
+\def\raggedspaceamount {\interwordspace} % {.3333em}
+\def\raggedxspaceamount {.5em}
+
+\def\notragged
+ {\chardef\raggedstatus\zerocount
+ \leftskip 1\leftskip
+ \rightskip 1\rightskip
+ \spaceskip \zeropoint
+ \xspaceskip \zeropoint
+ \parfillskip\zeropoint\!!plus\raggedfillamount\relax
+ \let\updateraggedskips\relax} % new
+
+\let\forgetragged\notragged
+
+\def\raggedleft
+ {\setraggedness\leftraggedness
+ \setraggedskips1\leftraggedness\zeropoint\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+\def\raggedcenter
+ {\setraggedness\middleraggedness
+ \setraggedskips2\middleraggedness\middleraggedness\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+%D We used to have:
+%D
+%D \starttyping
+%D \def\raggedright
+%D {\setraggedness\rightraggedness
+%D \setraggedskips{3}{0em}{\rightraggedness}{.3333em}{.5em}{0em}{\parindent}}
+%D \stoptyping
+%D
+%D However, the next alternative, suggested by Taco, is better.
+
+\def\raggedright
+ {\setraggedness\rightraggedness
+ \setraggedskips3\zeropoint\rightraggedness\raggedspaceamount
+ \raggedxspaceamount\raggedfillamount\parindent}
+
+\def\veryraggedleft
+ {\setraggedskips1\raggedfillamount\zeropoint\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+%D When we want the last line to have a natural width:
+%D
+%D \starttyping
+%D \def\veryraggedleft%
+%D {\setraggedskips{1}{1fil}{0em}{.3333em}{.5em}{0em}{-1fil}}
+%D \stoptyping
+%D
+%D but this one is not accepted by the macros.
+
+\def\veryraggedcenter
+ {\setraggedskips2\raggedfillamount\raggedfillamount\raggedspaceamount
+ \raggedxspaceamount\zeropoint\zeropoint}
+
+\def\veryraggedright
+ {\setraggedskips3\zeropoint\raggedfillamount\raggedspaceamount
+ \raggedxspaceamount\zeropoint\parindent}
+
+\def\ttraggedright
+ {\tttf
+ \setraggedskips3\zeropoint\rightraggedness
+ \zeropoint\zeropoint\zeropoint\parindent} % \ctxparindent
+
+%D A bonus one:
+
+\def\raggedwidecenter
+ {\setraggedness\middleraggedness
+ \setraggedskips2\raggedhalffillamount\raggedhalffillamount
+ \raggedspaceamount\raggedxspaceamount\zeropoint\zeropoint}
+
+\newif\if@@asragged \@@asraggedtrue % old method
+
+% todo
+%
+% \setuplayout[grid=yes,lines=44] \showgrid
+% \starttext
+% test \vfill test \endgraf \strut \endgraf \vskip-\lineheight \removedepth \pagina test
+% \stoptext
+
+% \setupalign[reset,new,right,old]
+
+\def\@@align@@rl{\if!!donea\veryraggedleft \else\raggedleft \fi}
+\def\@@align@@rr{\if!!donea\veryraggedright \else\raggedright \fi}
+\def\@@align@@rc{\if!!donea\veryraggedcenter\else\raggedcenter\fi}
+
+\setvalue{@@ngila@@\v!broad }{\!!doneatrue}
+\setvalue{@@ngila@@\v!wide }{\!!donebtrue}
+
+\def\installalign#1#2{\setvalue{@@align@@#1}{#2}} % can be used for overloads
+
+\installalign \v!new {\@@asraggedfalse}
+\installalign \v!old {\@@asraggedtrue}
+\installalign \empty {}
+
+\installalign \v!line {\baselinebottom}
+\installalign \v!bottom {\raggedbottom}
+\installalign \v!height {\normalbottom}
+\installalign \v!width {\notragged}
+\installalign \v!normal {\notragged}
+\installalign \v!yes {\notragged}
+\installalign \v!no {\raggedright}
+\installalign \v!inner {\if@@asragged \setraggedparagraphmode\@@align@@rl\@@align@@rr \else
+ \setraggedparagraphmode\@@align@@rr\@@align@@rl \fi}
+\installalign \v!outer {\if@@asragged \setraggedparagraphmode\@@align@@rr\@@align@@rl \else
+ \setraggedparagraphmode\@@align@@rl\@@align@@rr \fi}
+\installalign \v!left {\if@@asragged\@@align@@rl\else\@@align@@rr\fi}
+\installalign \v!right {\if@@asragged\@@align@@rr\else\@@align@@rl\fi}
+\installalign \v!middle {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
+\installalign \v!flushleft {\if!!donea\veryraggedright \else\raggedright\fi}
+\installalign \v!flushright {\if!!donea\veryraggedleft \else\raggedleft \fi}
+\installalign \v!flushouter {\setraggedparagraphmode\raggedleft\raggedright}
+\installalign \v!flushinner {\setraggedparagraphmode\raggedright\raggedleft}
+\installalign \v!center {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
+\installalign \v!hanging {\enableprotruding}
+\installalign \v!nothanging {\disableprotruding}
+\installalign \v!hz {\enableadjusting}
+\installalign \v!nohz {\disableadjusting}
+\installalign \v!spacing {\enablespacehandling \enablekernhandling}
+\installalign \v!nospacing {\disablespacehandling\disablekernhandling}
+\installalign \v!hyphenated {\dohyphens}
+\installalign \v!nothyphenated {\nohyphens}
+\installalign \v!new {\@@asraggedfalse} % so new will give you consistency
+\installalign \v!reset {\notragged\normalbottom}
+
+\installalign \v!tolerant {\tolerance3000 \relax}
+\installalign \v!verytolerant {\tolerance4500 \relax}
+\installalign \v!stretch {\emergencystretch\bodyfontsize}
+
+\installalign \v!grid {\doenablegridsnapping } % only mkiv
+\installalign \v!nogrid {\dodisablegridsnapping} % only mkiv
+
+\installalign \v!righttoleft {\lefttoright}
+\installalign \v!lefttoright {\righttoleft}
+\installalign {l2r} {\lefttoright}
+\installalign {r2l} {\righttoleft}
+
+\newcount\hyphenminoffset
+
+\ifx\sethyphenationvariables\undefined \let\sethyphenationvariables\relax \fi
+
+\def\lesshyphens
+ {\advance\hyphenminoffset\plusone
+ \sethyphenationvariables}
+
+\def\morehyphens
+ {\ifcase\hyphenminoffset \else
+ \advance\hyphenminoffset\minusone
+ \fi
+ \sethyphenationvariables}
+
+\installalign \v!lesshyphenation {\lesshyphens}
+\installalign \v!morehyphenation {\morehyphens}
+
+\def\dodosetupalign#1{\csname @@align@@#1\endcsname}
+\def\dodosetupngila#1{\csname @@ngila@@#1\endcsname}
+
+\def\setupalign
+ {\dosingleargument\dosetupalign}
+
+\def\dosetupalign[#1]% can be made faster by checking for defined #1
+ {\!!doneafalse
+ \!!donebfalse
+ \processcommacommand[#1]\dodosetupngila
+ \processcommacommand[#1]\dodosetupalign}
+
+% \setupalign[flushleft] \input ward \par % lijnlinks
+% \setupalign[right] \input ward \par
+
+% \setupalign[flushright] \input ward \par % lijnrechts
+% \setupalign[left] \input ward \par
+
+% \setupalign[middle] \input ward \par % centreer
+% \setupalign[center] \input ward \par
+
+\def\startalignment
+ {\bgroup
+ \setupalign}
+
+\def\stopalignment
+ {\par
+ \egroup}
+
+\chardef\alignstrutmode=1
+
+% see later for the real definition, which in the simple case is:
+
+\newtoks \everyleftofalignedline
+\newtoks \everyrightofalignedline
+
+\def\shiftalignedline#1#2#3#4% left, right, inner, outer
+ {\rightorleftpageaction
+ {\everyleftofalignedline {\hskip\dimexpr#1+#3\relax}%
+ \everyrightofalignedline{\hskip\dimexpr#2+#4\relax}}
+ {\everyleftofalignedline {\hskip\dimexpr#1+#4\relax}%
+ \everyrightofalignedline{\hskip\dimexpr#2+#3\relax}}}
+
+\def\doalignline#1#2% \\ == newline
+ {\noindentation % was \noindent
+ \dontleavehmode % added in marrakesch at TUG 2006\begingroup
+ \begingroup
+ \setlocalhsize % new
+ \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}%
+ \dowithnextbox
+ {\hbox to \localhsize
+ {\ifcase\alignstrutmode\or\strut\fi
+ \the\everyleftofalignedline
+ #1\unhbox\nextbox#2\relax
+ \the\everyrightofalignedline}%
+ \endgroup}
+ \hbox}
+
+% plain commands
+
+\ifx\undefined\line \def\line {\hbox to\hsize} \fi
+\ifx\undefined\leftline \def\leftline #1{\line{#1\hss}} \fi
+\ifx\undefined\rightline \def\rightline #1{\line{\hss#1}} \fi
+\ifx\undefined\centerline \def\centerline#1{\line{\hss#1\hss}} \fi
+
+% directe commando's
+
+\def\leftaligned {\doalignline \relax \hss }
+\def\midaligned {\doalignline \hss \hss }
+\def\rightaligned{\doalignline \hss \relax}
-\starttext
+\let\centeraligned\midaligned
+
+\def\regelbegrensd#1{\limitatetext{#1}{\hsize}{\unknown}} % to be translated
+
+% indirecte commando's
+
+\letvalue{\s!do\v!line\v!left }\leftaligned
+\letvalue{\s!do\v!line\v!right }\rightaligned
+\letvalue{\s!do\v!line\v!middle }\midaligned
+\letvalue{\s!do\v!line\v!flushleft }\rightaligned
+\letvalue{\s!do\v!line\v!flushright}\leftaligned
+\letvalue{\s!do\v!line\v!center }\midaligned
+
+\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
+
+%D Experimental:
+
+\def\doxalignline#1#2#3#4#5#6%
+ {\noindentation % was \noindent
+ \dontleavehmode % added in marrakesch at TUG 2006\begingroup
+ \begingroup
+ \setlocalhsize
+ \def\\{\egroup\par\doxalignline#1#2#3#4#5#6\bgroup}% inefficient
+ \dowithnextbox
+ {%\noindent moved up
+ \hbox to \localhsize
+ {#1\hskip\ifdone#2\else#3\fi#4%
+ \hbox to \localhsize
+ {\the\everyleftofalignedline
+ \ifcase\alignstrutmode\or\strut\fi
+ \ifdone#5\unhbox\nextbox#6\else#6\unhbox\nextbox#5\fi
+ \the\everyrightofalignedline}%
+ \hss}%
+ \endgroup}
+ \hbox}
+
+\def\doxcheckline
+ {\signalrightpage\doifrightpageelse\donetrue\donefalse}
+
+\setvalue{\s!do\v!line\v!inner }{\doxalignline\doxcheckline++\zeropoint \relax\hss }
+\setvalue{\s!do\v!line\v!outer }{\doxalignline\doxcheckline++\zeropoint \hss \relax}
+\setvalue{\s!do\v!line\v!innermargin}{\doxalignline\doxcheckline-+\innermargintotal\relax\hss }
+\setvalue{\s!do\v!line\v!outermargin}{\doxalignline\doxcheckline+-\outermargintotal\hss \relax}
+\setvalue{\s!do\v!line\v!inneredge }{\doxalignline\doxcheckline-+\inneredgetotal \relax\hss }
+\setvalue{\s!do\v!line\v!outeredge }{\doxalignline\doxcheckline+-\outeredgetotal \hss \relax}
+\setvalue{\s!do\v!line\v!backspace }{\doxalignline\doxcheckline-+\backspace \relax\hss }
+\setvalue{\s!do\v!line\v!cutspace }{\doxalignline\doxcheckline+-\cutspace \hss \relax}
+
+\setvalue{\s!do\v!line\v!leftmargin }{\doxalignline\donefalse --\leftmargintotal \hss \relax}
+\setvalue{\s!do\v!line\v!rightmargin}{\doxalignline\donefalse ++\rightmargintotal\relax\hss }
+\setvalue{\s!do\v!line\v!leftedge }{\doxalignline\donefalse --\leftedgetotal \hss \relax}
+\setvalue{\s!do\v!line\v!rightedge }{\doxalignline\donefalse ++\rightedgetotal \relax\hss }
+
+% ! ! ! beware, redefining \doalignline gives the wrong results ! ! !
+%
+% \def\doalignline{\doxalignline\donefalse++\zeropoint}
+
+%D Better:
+
+\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
+
+\def\alignedline#1#2% setting default
+ {\csname\s!do\v!line\ifcsname\s!do\v!line#1\endcsname#1\else#2\fi\endcsname}
+
+%D ...
+
+\def\dosetuptolerance[#1]%
+ {\doifinsetelse\v!vertical{#1}%
+ {\ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!verystrict=>\def\bottomtolerance{},
+ \v!strict=>\def\bottomtolerance{.050},
+ \v!tolerant=>\def\bottomtolerance{.075},
+ \v!verytolerant=>\def\bottomtolerance{.100}]}%
+ {\ExpandFirstAfter\processallactionsinset
+ [#1]
+ [ \v!stretch=>\emergencystretch\bodyfontsize,
+ \v!space=>\spaceskip.5em\!!plus.25em\!!minus.25em\relax,
+ \v!verystrict=>\tolerance 200,
+ \v!strict=>\tolerance1500,
+ \v!tolerant=>\tolerance3000,
+ \v!verytolerant=>\tolerance4500]}}
+
+\def\setuptolerance
+ {\dosingleargument\dosetuptolerance}
+
+% \def\woordrechts
+% {\groupedcommand{\hfill\hbox}{\parfillskip\zeropoint}}
+
+% beware: \wordright{whatever\kern-\rightskip} should work!
+% so, no funny boxing here
+
+\def\dowordright[#1]%
+ {% don't change
+ \groupedcommand
+ {\removeunwantedspaces
+ \hfill
+ \allowbreak % changed back from \hskip\zeropoint
+ \strut
+ \hfill
+ \quad % decent spacing
+ \hbox}
+ {\doifelse{#1}\v!right{\kern-\rightskip}{\doifsomething{#1}{\kern-#1}}%
+ \parfillskip\zeropoint
+ %\finalhyphendemerits\zerocount % yes or no
+ \par}}
+
+\def\wordright
+ {\dosingleempty\dowordright}
+
+% \dorecurse{5}{something } \wordright{--someone} \endgraf
+% \dorecurse{6}{something } \wordright{--someone} \endgraf
+% \dorecurse{7}{something } \wordright{--someone} \endgraf
+%
+% \dorecurse{5}{something } \wordright{--someone else entirely} \endgraf
+% \dorecurse{6}{something } \wordright{--someone else entirely} \endgraf
+% \dorecurse{7}{something } \wordright{--someone else entirely} \endgraf
+%
+% \wordright[\rightskip]{whatever}
+
+% \simplealignedbox{2cm}{right}{x}
+
+\setvalue{\s!simple\c!align\v!right }#1#2{\hbox to #1{#2\hss}}
+\setvalue{\s!simple\c!align\v!left }#1#2{\hbox to #1{\hss#2}}
+\setvalue{\s!simple\c!align\v!flushright }#1#2{\hbox to #1{\hss#2}}
+\setvalue{\s!simple\c!align\v!flushleft }#1#2{\hbox to #1{#2\hss}}
+\setvalue{\s!simple\c!align\v!middle }#1#2{\hbox to #1{\hss#2\hss}}
+
+\def\simplealignedbox#1{\executeifdefined{\s!simple\c!align#1}{\getvalue{\s!simple\c!align\v!right}}}
+
+%D \macros
+%D {pushindentation,popindentation}
+%D
+%D The pushing and popping is done by:
+
+\newbox\indentationboxA
+\newbox\indentationboxB
+
+\def\pushindentation
+ {\bgroup
+ \ifhmode
+ \unskip
+ \setbox\indentationboxA\lastbox % get \strut if present
+ \unskip
+ \setbox\indentationboxB\lastbox % get \indent generated box
+ \unskip
+ \else
+ \hskip\zeropoint % switch to horizontal mode
+ \unskip
+ \setbox\indentationboxA\lastbox % get \indent generated box
+ \setbox\indentationboxB\emptybox
+ \fi}
+
+\def\popindentation
+ {\box\indentationboxB\box\indentationboxA % put back the boxes
+ \egroup}
+
+%D The only complication lays in \type{\strut}. In \PLAIN\
+%D \TEX\ a \type{\strut} is defined as:
+%D
+%D \starttyping
+%D \def\strut%
+%D {\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
+%D \stoptyping
+%D
+%D But what is a \type{\strut}? Normally it's a rule of width
+%D zero, but when made visual, it's a rule and a negative skip.
+%D The mechanism for putting things in the margins described
+%D here cannot handle this situation very well. One
+%D characteristic of \type{\strut} is that the \type{\unhcopy}
+%D results in entering horizontal mode, which in return leads
+%D to some indentation.
+%D
+%D To serve our purpose a bit better, the macro \type{\strut}
+%D can be redefined as:
+%D
+%D \starttyping
+%D \def\strut
+%D {\relax\ifmmode\else\hskip0pt\fi\copy\strutbox}
+%D \stoptyping
+%D
+%D Or more compatible:
+%D
+%D \starttyping
+%D \def\strut
+%D {\relax\ifmmode
+%D \copy\strutbox
+%D \else
+%D \bgroup\setbox\strutbox=\normalhbox{\box\strutbox}\unhcopy\strutbox\egroup
+%D \fi}
+%D \stoptyping
+%D
+%D In \CONTEXT\ however we save some processing time by putting
+%D an extra \type{\hbox} around the \type{\strutbox}.
+
+% moved from page-lin.tex to here (due to visualization added
+% in august 2003)
+%
+% \unexpanded \def\crlf
+% {\ifhmode\unskip\else\strut\fi\ifcase\raggedstatus\hfil\fi\break}
+
+\unexpanded \def\crlf
+ {\ifhmode
+ \unskip
+ \prewordbreak\crlfplaceholder
+ \ifcase\raggedstatus\hfil\or\or\or\hfil\fi
+ \break
+ \else
+ \crlfplaceholder
+ \endgraf
+ \fi}
+
+\def\crlfplaceholder
+ {\strut}
+
+\def\settestcrlf
+ {\def\crlfplaceholder
+ {\hbox to \zeropoint
+ {\strut{\infofont\kern.25em}\lohi{\infofont CR}{\infofont LF}\hss}}}
+
+%D \starttyping
+%D % \setuplayout[gridgrid=yes] \showgrid
+%D
+%D \startbuffer
+%D test 1\crlf
+%D test 2\crlf
+%D
+%D \crlf test 3
+%D
+%D test 4\crlf
+%D test 5
+%D
+%D \crlf
+%D \crlf
+%D \crlf
+%D test 6
+%D \stopbuffer
+%D
+%D \hbox
+%D {\hsize5em
+%D \ruledvtop{\getbuffer}\enspace
+%D \ruledvtop{\showstruts\getbuffer}\enspace
+%D \hsize15em \setuptyping[before=,after=]%
+%D \ruledvtop{\typebuffer}}
+%D \stoptyping
+
+\def\justonespace
+ {\removelastspace\space} % \removeunwantedspaces\space
+
+\def\ignorecrlf
+ {\let\crlf\justonespace\let\\\crlf}
+
+\def\showstruts
+ {\setteststrut
+ \settestcrlf}
+
+\def\definehspace
+ {\dotripleempty\dodefinehspace}
+
+\def\dodefinehspace[#1][#2][#3]% #1 = optional namespace
+ {\ifthirdargument
+ \setvalue{\??hs#1:#2}{#3}%
+ \else
+ \setvalue{\??hs:#1}{#2}%
+ \fi}
+
+\unexpanded\def\hspace
+ {\dodoubleempty\dohspace}
+
+\def\dohspace[#1][#2]%
+ {\ifsecondargument
+ \dodohspace[#1][#2]%
+ \else\iffirstargument
+ \hspace[][#1]%
+ \else
+ \hspace[][\s!default]%
+ \fi\fi}
+
+\def\dodohspace[#1][#2]%
+ {\ifhmode
+ \removeunwantedspaces
+ \hskip\hspaceamount{#1}{#2}%
+ \expandafter\ignorespaces
+ \fi}
+
+\def\hspaceamount#1#2%
+ {\executeifdefined{\??hs#1:#2}{\executeifdefined{\??hs:#2}\zeropoint}}
+
+\definehspace [\v!small] [.25\emspaceamount]
+\definehspace [\v!medium] [.5\emspaceamount]
+\definehspace [\v!big] [1\emspaceamount]
+\definehspace [\v!normal] [1\spaceamount]
+\definehspace [\v!default] [\spaceamount]
+
+%D Taken from Taco's math module (cq. \AMS\ macros), but
+%D adapted to \type {\hspace}:
+
+\unexpanded\def\textormathspace#1#2#3%
+ {\ifmmode\mskip#1#2\else\kern#1\hspaceamount\empty{#3}\fi\relax}
+
+\newmuskip\hairmuskip \hairmuskip=.15mu
+
+\unexpanded\def\hairspace {\textormathspace+\hairmuskip{.5}}
+\unexpanded\def\thinspace {\textormathspace+\thinmuskip 1}
+\unexpanded\def\medspace {\textormathspace+\medmuskip 2}
+\unexpanded\def\thickspace {\textormathspace+\thickmuskip3}
+\unexpanded\def\neghairspace {\textormathspace-\thinmuskip{.5}}
+\unexpanded\def\negthinspace {\textormathspace-\thinmuskip 1}
+\unexpanded\def\negmedspace {\textormathspace-\medmuskip 2}
+\unexpanded\def\negthickspace{\textormathspace-\thickmuskip3}
+
+% needed for unicode:
+
+\unexpanded\def\twoperemspace {\hskip\dimexpr\emwidth/2\relax} % == \enspace
+\unexpanded\def\threeperemspace {\hskip\dimexpr\emwidth/3\relax}
+\unexpanded\def\fourperemspace {\hskip\dimexpr\emwidth/4\relax}
+\unexpanded\def\fiveperemspace {\hskip\dimexpr\emwidth/5\relax} % goodie
+\unexpanded\def\sixperemspace {\hskip\dimexpr\emwidth/6\relax}
+\unexpanded\def\figurespace {\begingroup\setbox\scratchbox\hbox{0}\hskip\wd\scratchbox\endgroup} % there is a command for this
+\unexpanded\def\punctuationspace {\begingroup\setbox\scratchbox\hbox{.}\hskip\wd\scratchbox\endgroup}
+\unexpanded\def\ideographicspace {\hskip\dimexpr\emwidth/1\relax}
+\unexpanded\def\ideographichalffillspace{\hskip\dimexpr\emwidth/2\relax}
+%unexpanded\def\nobreakspace {\penalty\plustenthousand\space}
+\unexpanded\def\nobreakspace {\penalty\plustenthousand\kern\interwordspace}
+\unexpanded\def\narrownobreakspace {\penalty\plustenthousand\thinspace}
+%unexpanded\def\zerowidthnobreakspace {\penalty\plustenthousand\hskip\zeropoint}
+\unexpanded\def\zerowidthnobreakspace {\penalty\plustenthousand\kern\zeropoint}
+\unexpanded\def\zerowidthspace {\hskip\zeropoint}
+
+\definehspace[.5][.1250\emspaceamount] % could also be [.1250\spaceamount]
+\definehspace[1] [.1667\emspaceamount]
+\definehspace[2] [.2222\emspaceamount]
+\definehspace[3] [.2777\emspaceamount]
+
+\let \, \thinspace
+\let \: \medspace
+\let \; \thickspace
+\let \! \negthinspace
+
+% this will become an alternative bunch of \blank settings
+%
+% \startlines
+% \scratchskip=.23pt plus 10pt minus 4pt \relax \number\scratchskip \space \the\scratchskip
+% \setsimplifiedskip\scratchskip1 \number\scratchskip \space \the\scratchskip
+% \setsimplifiedskip\scratchskip2 \number\scratchskip \space \the\scratchskip
+% \getsimplifiedskip\scratchskip\scratchcounter \number\scratchcounter
+% \stoplines
+%
+% \hrule width10cm \endgraf
+% \discardedskip{10pt}
+% \retainedskip {4pt}
+% \discardedskip {5pt}
+% \hrule width10cm \endgraf
+% \blockedskip{0pt}
+% \discardedskip{10pt}
+% \retainedskip {4pt}
+% \discardedskip {5pt}
+% \hrule width10cm \endgraf
+% \frozenskip {4cm}
+% \hrule width10cm \endgraf
+% \vskip10pt
+% \hrule width10cm \endgraf
+
+\newskip\simplifiedskip
+\newskip\simplifiedcounter
+
+\chardef\@@discardedskip1
+\chardef\@@retainedskip 2
+\chardef\@@forcedskip 3
+\chardef\@@blockedskip 4
+\chardef\@@frozenskip 5 % after heads, no break
+
+\def\setsimplifiedskip#1#2%
+ {#1\dimexpr(10\dimexpr(#1/10)) plus \gluestretch#1 minus \glueshrink#1\relax
+ \advance#1\numexpr(#2)sp\relax}
+
+\def\getsimplifiedskip#1#2%
+ {\simplifiedskip#1\relax
+ \ifzeropt\simplifiedskip % \ifdim\simplifiedskip=\zeropoint
+ #2\zerocount
+ \else
+ \simplifiedcounter\dimexpr10\dimexpr#1/10\relax\relax
+ \advance\simplifiedskip-\simplifiedcounter
+ #2\number\simplifiedskip\relax
+ \fi}
+
+\def\conditionalskip#1#2%
+ {\scratchskip#1\relax
+ \setsimplifiedskip\scratchskip#2\relax
+ \vskip\scratchskip\relax}
+
+\def\defrostskip
+ {\scratchskip\lastskip\penalty50000\normalvskip-\scratchskip\penalty50000\relax}
+
+\def\frozenskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \fi}
+
+\def\discardedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@discardedskip
+ \or % discard
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@discardedskip
+ \fi
+ \or % retain
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@discardedskip
+ \fi
+ \or % forced
+ \conditionalskip{#1}\@@discardedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+\def\retainedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@retainedskip
+ \or % discard
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@retainedskip
+ \or % retain
+ \ifdim\lastskip>#1\else
+ \normalvskip-\lastskip
+ \conditionalskip{#1}\@@retainedskip
+ \fi
+ \or % forced
+ \conditionalskip{#1}\@@retainedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+\def\forcedskip#1%
+ {\endgraf
+ \ifvmode
+ \conditionalskip{#1}\@@forcedskip
+ \fi}
+
+\def\blockedskip#1%
+ {\endgraf
+ \ifvmode
+ \getsimplifiedskip\lastskip\scratchcounter
+ \ifcase\scratchcounter
+ \conditionalskip{#1}\@@blockedskip
+ \or % discard
+ \conditionalskip{#1}\@@blockedskip
+ \or % retain
+ \conditionalskip{#1}\@@blockedskip
+ \or % forced
+ \conditionalskip{#1}\@@blockedskip
+ \or % ignored
+ \or % frozen
+ \ifdim\lastskip>#1\else
+ \defrostskip
+ \conditionalskip{#1}\@@frozenskip
+ \fi
+ \else\ifdim#1=\zeropoint\else
+ \vskip#1\relax
+ \fi\fi
+ \fi}
+
+% beware, changing this will break some code (like pos/backgrounds)
+
+\newtoks\everyfirstparagraphintro
+\newtoks\everynextparagraphintro
+\newtoks\@@everyparagraphtoks
+
+\chardef\everyparagraphintro\zerocount
+
+\def\setupparagraphintro
+ {\dodoubleempty\dosetupparagraphintro}
+
+\def\dosetupparagraphintro[#1][#2]%
+ {\processallactionsinset
+ [#1]
+ [ \v!reset=>\global\chardef\everyparagraphintro\zerocount
+ \global\everyfirstparagraphintro\emptytoks
+ \global\everynextparagraphintro \emptytoks,
+ \v!first=>\global\chardef\everyparagraphintro\plusone
+ \doglobal\appendtoks#2\to\everyfirstparagraphintro,
+ \v!next=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plusone\fi
+ \doglobal\appendtoks#2\to\everynextparagraphintro,
+ \v!each=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plustwo\fi
+ \doglobal\appendtoks#2\to\everyfirstparagraphintro
+ \doglobal\appendtoks#2\to\everynextparagraphintro]}
+
+%D We can say:
+%D
+%D \starttyping
+%D \setupparagraphintro[first][\index{Knuth}]
+%D \stoptyping
+%D
+%D Maybe more convenient is:
+%D
+%D \starttyping
+%D \flushatparagraph{\index{Zapf}}
+%D \stoptyping
+
+\def\flushatparagraph#1%
+ {\global\chardef\everyparagraphintro\plusone
+ \global\appendtoks{#1}\to\everyfirstparagraphintro}
+
+\def\doinsertparagraphintro
+ {\begingroup
+ \everypar\emptytoks
+ \ifcase\everyparagraphintro\relax
+ % no data
+ \@@everyparagraphtoks\emptytoks
+ \or
+ % first data
+ \global\chardef\everyparagraphintro\plustwo
+ \@@everyparagraphtoks\everyfirstparagraphintro
+ \global\everyfirstparagraphintro\emptytoks
+ \or
+ % next data
+ \@@everyparagraphtoks\everynextparagraphintro
+ \fi
+ \the\@@everyparagraphtoks
+ \endgroup}
+
+\def\insertparagraphintro
+ {\ifcase\everyparagraphintro\else\@EA\doinsertparagraphintro\fi}
+
+% \appendtoksonce\insertparagraphintro\to\everypar % should come last
+
+%D \starttyping
+%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
+%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
+%D \setupparagraphintro[next] [\hbox to 3.5em{\tt NEXT \hss}]
+%D \setupparagraphintro[next] [\hbox to 3.5em{\tt TXEN \hss}]
+%D \setupparagraphintro[each] [\hbox to 3.0em{\tt EACH \hss}]
+%D \setupparagraphintro[each] [\hbox to 3.0em{\tt HCEA \hss}]
+%D
+%D some paragraph \par
+%D some paragraph \par
+%D some paragraph \par
+%D
+%D \definelabel[parnumber]
+%D
+%D \setupparagraphintro[reset,each][\inleft{\slxx\parnumber}]
+%D
+%D some paragraph \par
+%D some paragraph \par
+%D some paragraph \par
+%D \stoptyping
+
+%D \macros
+%D {flushatnextpar}
+%D
+%D This macro collects data that will be flushed at the next paragraph.
+%D By using this macro you can avoid interfering nodes (writes, etc).
+
+\newbox \postponednodedata
+
+\def\flushatnextpar
+ {\bgroup
+ \dowithnextbox
+ {\global\setbox\postponednodedata\hbox{\box\postponednodedata\box\nextbox}\egroup}%
+ \hbox}
+
+\def\flushpostponednodedata
+ {\ifvoid\postponednodedata\else
+ \hbox{\smashedbox\postponednodedata}%
+ \fi}
+
+% Very nasty but needed for margin stuff inside colored
+% paragraphs.
+
+\let\normalvadjust\vadjust
+
+% test this prikkels/pascal margin text before heads (mode
+% 1) as well as uitwerkingen (mode 2)
+
+%chardef\graphicvadjustmode=0 % fake
+%chardef\graphicvadjustmode=1 % normal
+\chardef\graphicvadjustmode=2 % normal + compensate (== default)
+
+\def\graphicvadjust % bad, those low level color calls here
+ {\dowithnextboxcontent
+ {\forgetall}
+ {\ifcase\graphicvadjustmode \@EA \fakedvadjust \else \@EA\normalvadjust \fi
+ {\dostartgraphicgroup % don't ask
+ \localstarttextcolor
+ \unvbox\nextbox
+ \localstoptextcolor % don't ask
+ \dostopgraphicgroup
+ \ifcase\graphicvadjustmode \or \or
+ % corrects for one line paragraphs
+ \nointerlineskip
+ \kern-\struttotal
+ \nointerlineskip
+ \verticalstrut
+ \fi}}%
+ \vbox}
+
+%D This works only in a properly strutted line, and is meant
+%D for deeply burried operations, like in heads.
+
+\def\fakedvadjust
+ {\dowithnextbox
+ {\setbox\nextbox\hbox{\llap{\lower\strutdepth\box\nextbox}}%
+ \smashedbox\nextbox}%
+ \vtop}
+
+\def\flexiblespaceamount#1#2#3%
+ {#1\interwordspace
+ \!!plus#2\interwordstretch
+ \!!minus#3\interwordshrink}
+
+\def\fixedspaceamount#1%
+ {#1\interwordspace}
+
+%D This is a dangerous feature because it makes the \TEX\ source
+%D less portable, i.e. any parser now needs to apply exactly the
+%D same algorithm when it wants to interpret the source. We
+%D strongly recommend not to mention this feature in manuals! It's
+%D provided for users who are hooked to such a mechanism.
+%D
+%D \starttyping
+%D \setupsorting[logo][next=\autoinsertnextspace] \logo[TEX]{\TeX}
+%D
+%D bla bla \TEX bla bla \TEX (bla) bla (\TEX)
+%D \stoptyping
+
+\def\autoinsertnextspace{\futurelet\nexttoken\doautoinsertnextspace}
+
+\def\doautoinsertnextspace % slightly extended version of a user supplied macro
+ {\ifx\nexttoken \bgroup\else \ifx\nexttoken\begingroup\else
+ \ifx\nexttoken \egroup\else \ifx\nexttoken \endgroup\else
+ \ifx\nexttoken \/\else \ifx\nexttoken /\else \ifx\nexttoken ~\else
+ \ifx\nexttoken \ \else \ifx\nexttoken \blankspace\else \ifx\nexttoken \space\else
+ \ifx\nexttoken .\else \ifx\nexttoken ,\else
+ \ifx\nexttoken !\else \ifx\nexttoken ?\else
+ \ifx\nexttoken :\else \ifx\nexttoken ;\else
+ \ifx\nexttoken '\else \ifx\nexttoken "\else
+ \ifx\nexttoken )\else \ifx\nexttoken -\else \ifx\nexttoken |\else
+ \ifx\nexttoken \%\else \ifx\nexttoken \&\else
+ \space
+ \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
+
+% moved from page-lin
+
+\def\installspacehandler#1#2% needs to set \obeyedspace
+ {\setvalue{\??sr#1}{#2}}
+
+\installspacehandler \v!on
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}%
+ \let\ =\obeyedspace}
+
+\installspacehandler \v!yes
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode \normalspace }}%
+ \let\ =\obeyedspace}
+
+\installspacehandler \v!off
+ {\normalspaces
+ \let\obeyedspace\normalspace
+ \let\ =\normalspace}
+
+\installspacehandler \v!fixed
+ {\obeyspaces
+ \def\obeyedspace{\mathortext\normalspace{\dontleavehmode\fixedspace}}%
+ \let\ =\obeyedspace}
+
+\def\activatespacehandler#1%
+ {\executeifdefined{\??sr#1}{\activatespacehandler\v!off}}
+
+% moved from page-lin
+
+%D When spacing is active we need to handle commands in
+%D a special way:
+%D
+%D \starttyping
+%D \setuplines[space=on]
+%D
+%D \startlines
+%D Let's talk about this{\ttsl\gobbleoneargument or}that.
+%D \stoplines
+%D
+%D \startlines
+%D Let's talk about this{\getvalue{ttsl}or}that.
+%D \stoplines
+%D \stoptyping
+%D
+%D One can indent in several ways:
+%D
+%D \starttyping
+%D \setupindenting[medium] \setuplines[indenting=odd] % no yes odd even
+%D
+%D \startlines
+%D first
+%D second
+%D third
+%D fourth
+%D \stoplines
+%D \stoptyping
+
+\def\setuplines
+ {\dodoubleargument\getparameters[\??rg]}
+
+\def\startlines
+ {\@@rgbefore
+ \pushmacro\checkindentation
+ \whitespace
+ %\page[\v!preference]} gaat mis na koppen, nieuw: later \nobreak
+ \begingroup
+ \setupindenting[\@@rgindenting]%
+ \typesettinglinestrue
+ \setupwhitespace[\v!none]%
+ \obeylines
+ \ignorespaces
+ \gdef\afterfirstobeyedline % tzt two pass, net als opsomming
+ {\gdef\afterfirstobeyedline
+ {\nobreak
+ \global\let\afterfirstobeyedline\relax}}%
+ \def\obeyedline
+ {\par
+ \afterfirstobeyedline
+ \futurelet\next\dobetweenthelines}%
+ \activatespacehandler\@@rgspace
+ \GotoPar}
+
+\def\stoplines
+ {\endgroup
+ \popmacro\checkindentation
+ \@@rgafter}
+
+\def\dobetweenthelines
+ {\doifmeaningelse\next\obeyedline\@@rginbetween\donothing}
+
+\setuplines
+ [\c!before=\blank,
+ \c!after=\blank,
+ \c!inbetween=\blank,
+ \c!indenting=\v!no,
+ \c!space=\v!default]
+
+\def\emptylines
+ {\dosingleempty\doemptylines}
+
+\def\doemptylines[#1]%
+ {\endgraf\dorecurse{\iffirstargument#1\else3\fi}\crlf}
+
+\setupwhitespace
+ [\v!none]
+
+% still old-fashioned
+
+\indenting
+ [\v!never]
+
+\setupindenting
+ [\v!none]
+
+\setupblank
+ [\v!standard,
+ \v!big]
+
+\defineblank[\v!default] [\currentblank]
+\defineblank[\v!before] [\v!default]
+\defineblank[\v!inbetween][\v!default]
+\defineblank[\v!after] [\v!before]
+
+\setupinterlinespace
+ [\c!minheight=0pt, % only special purpose
+ \c!mindepth=0pt, % only special purpose
+ \c!height=.72,
+ \c!depth=.28,
+ \c!top=1.0,
+ \c!bottom=0.4,
+ \c!distance=1pt,
+ \c!line=2.8ex,
+ \c!stretch=0]
+
+\setupnarrower
+ [\c!before=\endgraf,
+ \c!after=\endgraf,
+ \c!left=1.5em,
+ \c!right=1.5em,
+ \c!middle=1.5em]
+
+\setuptolerance
+ [\v!horizontal,\v!verystrict]
+
+\setuptolerance
+ [\v!vertical,\v!strict]
+
+\setupalign
+ [\v!bottom,
+ \v!width]
+
+\setupspacing
+ [\v!packed]
+
+\protect \endinput
\dorecurse{2}{
$2^{2^{2^{2}}}$ $2_{2_{2_{2}}}^{2^{2^{2^{2^{2^{2^{2^{2^{2}}}}}}}}}$
@@ -470,71 +4154,3 @@
\vskip10pt
fifth
}
-
-% bidi test
-
-\definefontfeature
- [arab]
- [mode=node,language=dflt,script=arab,
- init=yes,medi=yes,fina=yes,isol=yes,
- liga=yes,dlig=yes,rlig=yes,clig=yes,
- mark=yes,mkmk=yes,kern=yes,curs=yes]
-
-\font\Arabic=arabtype*arab at 20pt
-
-\def\LATIN{LATIN} {\setcharactermirroring[1]} % enable this
-\def\ARAB {محمد}
-
-\startluacode
- function document.split_tokens(str)
- for s in str:bytes() do
- tex.sprint(tex.ctxcatcodes,string.format("\\hbox{\\char %s}",s))
- end
- end
-\stopluacode
-
-\def\biditest#1#2#3% font text raw
- {\dontleavehmode\hbox
- {\framed[offset=overlay]{\tttf#2}\quad
- \ctxlua{mirror.trace = true}%
- \framed[offset=overlay]{#1#3}\quad
- \ctxlua{mirror.trace = false}
- \tttf\ctxlua{document.split_tokens([[\detokenize{#3}]])}}}
-
-\startbuffer[bidi-sample]
-\biditest\Arabic{LATIN BARA}{\textdir TLT\relax \LATIN\ \ARAB}\par
-\biditest\Arabic{BARA LATIN}{\textdir TRT\relax \LATIN\ \ARAB}\par
-\biditest\Arabic{LATIN ARAB}{\textdir TLT{\bidilro \LATIN\ \ARAB}}\par % right -> left
-\biditest\Arabic{LATIN ARAB}{\textdir TRT{\bidilro \LATIN\ \ARAB}}\par % right -> left
-\biditest\Arabic{BARA NITAL}{\textdir TLT{\bidirlo \LATIN\ \ARAB}}\par % left -> right
-\biditest\Arabic{BARA NITAL}{\textdir TRT{\bidirlo \LATIN\ \ARAB}}\par % left -> right
-\stopbuffer
-
-\startbuffer[bidi-sample]
-\biditest\Arabic{LATIN BARA}{\textdir TLT\relax \LATIN\ \ARAB}\par
-\biditest\Arabic{BARA LATIN}{\textdir TRT\relax \LATIN\ \ARAB}\par
-\biditest\Arabic{LATIN ARAB}{\textdir TLT\bidilro \LATIN\ \ARAB}\par % right -> left
-\biditest\Arabic{LATIN ARAB}{\textdir TRT\bidilro \LATIN\ \ARAB}\par % right -> left
-\biditest\Arabic{BARA NITAL}{\textdir TLT\bidirlo \LATIN\ \ARAB}\par % left -> right
-\biditest\Arabic{BARA NITAL}{\textdir TRT\bidirlo \LATIN\ \ARAB}\par % left -> right
-\stopbuffer
-
-\startbuffer[bidi-setup]
-\setupdirections[bidi=off]
-\stopbuffer
-
-{\typebuffer[bidi-setup] \getbuffer[bidi-setup] \getbuffer[bidi-sample]}
-
-\startbuffer[bidi-setup]
-\setupdirections[bidi=global]
-\stopbuffer
-
-{\typebuffer[bidi-setup] \getbuffer[bidi-setup] \getbuffer[bidi-sample]}
-
-\startbuffer[bidi-setup]
-\setupdirections[bidi=local]
-\stopbuffer
-
-{\typebuffer[bidi-setup] \getbuffer[bidi-setup] \getbuffer[bidi-sample]}
-
-\stoptext
diff --git a/tex/context/base/core-spa.tex b/tex/context/base/core-spa.tex
deleted file mode 100644
index 31a75876e..000000000
--- a/tex/context/base/core-spa.tex
+++ /dev/null
@@ -1,4637 +0,0 @@
-%D \module
-%D [ file=core-spa,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Spacing,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Spacing Macros}
-
-% to be sorted out: dependencies, order of initialization / also some dutch code here
-
-\unprotect
-
-% interfacing mkii/mkiv
-
-\ifx\mksetupgridsnapping \undefined \let\mksetupgridsnapping \relax \fi
-\ifx\mkenablegridsnapping \undefined \let\mkenablegridsnapping \relax \fi
-\ifx\mkdisablegridsnapping\undefined \let\mkdisablegridsnapping\relax \fi
-
-% some will move to core-var
-
-\newif \ifgridsnapping
-\newif \iffuzzyvskip
-\let \fuzzyvskip \gobbleoneargument
-\let \removelastfuzzyvskip \relax
-
-\let \startbaselinecorrection \relax
-\let \stopbaselinecorrection \relax
-\let \baselinecorrection \relax
-\let \offbaselinecorrection \relax
-
-\appendtoks \spacing 1\to \everybodyfont
-\appendtoks \presetnormallineheight \to \everybodyfont
-\appendtoks \setnormalbaselines \to \everybodyfont % check if redundant
-\appendtoks \setstrut \to \everybodyfont % check if redundant
-\appendtoks \settopskip \to \everybodyfont
-\appendtoks \setmaxdepth \to \everybodyfont
-%appendtoks \spacing 1\to \everybodyfont
-\appendtoks \simplesetupindenting \to \everybodyfont
-\appendtoks \simplesetupblank \to \everybodyfont
-\appendtoks \simplesetupwhitespace \to \everybodyfont
-%appendtoks \checknotes \to \everybodyfont % not
-\appendtoks \simplesetupspacing \to \everybodyfont % nieuw
-\appendtoks \setrelativeinterlinespace \to \everybodyfont
-
-\appendtoks \updateraggedskips \to \everyfontswitch % under test
-\prependtoks \let\par\endgraf \to \everypagebody % see \fillinline
-\appendtoks \simplesetupspacing \to \everydefinedfont
-
-% if you want to hyphenate the first word of a paragraph ... \appendtoks\hskip0pt\to\everypar
-
-\def\stelfactorenin
- {\simplesetupwhitespace
- \simplesetupblank
- \settopskip
- \setmaxdepth}
-
-\def\softbreak
- {\relax\ifhmode\hskip\parfillskip\break\fi}
-
-\let\poplastnode\relax
-
-\def\pushlastnode
- {\ifdim\lastskip=\zeropoint
- \ifnum\lastpenalty=\zerocount
- \ifnum\lastkern=\zerocount
- \let\poplastnode\relax
- \else
- \edef\poplastnode{\kern\the\lastkern\relax}\kern-\lastkern % untested
- \fi
- \else
- \edef\poplastnode{\penalty\the\lastpenalty\relax}\nobreak % untested
- \fi
- \else
- \edef\poplastnode{\vskip\the\lastskip\relax}\vskip-\lastskip % \removelastskip
- \fi}
-
-%D The dreadful sequence \type {\bgroup} \unknown\
-%D \type {\carryoverpar} \unknown\ \type {\egroup} is needed
-%D when for instance sidefloats are used in combination with
-%D something that starts with a group. This is because
-%D otherwise the indentation as set (by the output routine)
-%D inside the group are forgotten afterwards. (I must
-%D not forget its existence).
-
-\global\let\carriedoverpar\relax
-
-\def\carryoverpar#1%
- {\expanded % \scratchtoks{#1}%
- {\noexpand#1% \the\scratchtoks
- \hangindent\the\hangindent
- \hangafter \the\hangafter
- \parskip \the\parskip
- \leftskip \the\leftskip
- \rightskip \the\rightskip}}
-
-%D A quick way to determine left|/|middle|/|right states
-%D (experimental).
-
-\setvalue{\??as\v!left }{0}
-\setvalue{\??as\v!middle}{1}
-\setvalue{\??as\v!right }{2}
-
-\def\setalignmentswitch#1%
- {\chardef\alignmentswitch0\csname\??as#1\endcsname\relax}
-
-%D There are two ways to influence the interline spacing. The
-%D most general and often most consistent way is using
-%D
-%D \showsetup{setupinterlinespace}
-%D
-%D For instance
-%D
-%D \starttyping
-%D \setupinterlinespace[line=2.8ex]
-%D \stoptyping
-%D
-%D This setting adapts itself to the bodyfontsize, while for
-%D instance saying
-%D
-%D \starttyping
-%D \setupinterlinespace[line=12pt]
-%D \stoptyping
-%D
-%D sets things fixed for all sizes, which is definitely not
-%D what we want. Therefore one can also say:
-%D
-%D \starttyping
-%D \definebodyfontenvironment[9pt][interlinespace=11pt]
-%D \stoptyping
-%D
-%D One can still use \type{\setupinterlinespace} (without
-%D arguments) to set the interline space according to the
-%D current font, e.g. a \type{\bfa}.
-
-\newif\iflocalinterlinespace
-
-% font-ini
-
-\ifx\bodyfontinterlinespecs\undefined
-
- \let\bodyfontinterlinespecs\empty
- \let\bodyfontinterlinespace\empty
-
-\fi
-
-\def\presetnormallineheight
- {\edef\normallineheight{\@@itline}%
-% done elsewhere : \spacing\!!plusone % new per 10/08/2004, else problems in otr / !! needed
- \iflocalinterlinespace \else
- \doifdefined\bodyfontinterlinespecs
- {\doifsomething\bodyfontinterlinespace
- {\edef\normallineheight{\bodyfontinterlinespace}}}%
- \fi}
-
-\def\setupspecifiedinterlinespace[#1]%
- {\getparameters[\??it][#1]%
- \scratchdimen0\@@itheight\points
- \advance\scratchdimen 0\@@itdepth\points
- \ifdim\scratchdimen>\onepoint
- \showmessage\m!layouts{10}{\@@itheight,\@@itdepth}%
- \let\@@itheight\strutheightfactor
- \let\@@itdepth \strutdepthfactor
- \else
- \let\strutheightfactor\@@itheight
- \let\strutdepthfactor \@@itdepth
- \fi
- \let\minimumstrutheight \@@itminheight
- \let\minimumstrutdepth \@@itmindepth
- \let\minimumlinedistance\@@itdistance
- \let\normallineheight \@@itline % let ! ! ! ! ! ivm ex
- \doifelse\@@ittop\v!height % new, topskip does more bad than good
- {\let\topskipfactor \@@itheight}
- {\let\topskipfactor \@@ittop }%
- \let\maxdepthfactor \@@itbottom
- \let\baselinegluefactor \@@itstretch
- \setfontparameters % redundant, can be \setstrut, test first
- \updateraggedskips} % yes indeed
-
-% \let\currentrelativeinterlinespace\empty
-%
-% \def\setuprelativeinterlinespace[#1]%
-% {\processallactionsinset
-% [#1]
-% [ \v!on=>\oninterlineskip,
-% \v!off=>\offinterlineskip,
-% \v!reset=>\let\currentrelativeinterlinespace\empty
-% \setfontparameters,% just \setstrut, test first
-% \s!unknown=>\assignvalue{#1}\currentrelativeinterlinespace{1.00}{1.25}{1.50}%
-% \spacing\currentrelativeinterlinespace]}
-
-% \setupinterlinespace[big] \switchtobodyfont[11pt] -> forgotten
-% \setupinterlinespace[auto,big] \switchtobodyfont[11pt] -> remembered
-
-\let\currentrelativeinterlinespace\empty
-
-\def\setuprelativeinterlinespace[#1]%
- {\processallactionsinset
- [#1]
- [ \v!on=>\oninterlineskip,
- \v!off=>\offinterlineskip,
- \v!reset=>\let\currentrelativeinterlinespace\empty
- \let\setrelativeinterlinespace\relax
- \setfontparameters,
- \v!auto=>\let\setrelativeinterlinespace\dosetrelativeinterlinespace,
- \s!unknown=>\assignvalue\commalistelement\currentrelativeinterlinespace{1.00}{1.25}{1.50}%
- \spacing\currentrelativeinterlinespace]}
-
-\def\dosetrelativeinterlinespace
- {\ifx\currentrelativeinterlinespace\empty\else
- \spacing\currentrelativeinterlinespace
- \fi}
-
-\let\setrelativeinterlinespace\relax
-
-% \appendtoks \setrelativeinterlinespace \to \everybodyfont
-
-\def\complexsetupinterlinespace[#1]% \commalistelement ipv #1
- {\doifassignmentelse{#1}\setupspecifiedinterlinespace\setuprelativeinterlinespace[#1]}
-
-\def\setuplocalinterlinespace[#1]%
- {\localinterlinespacetrue
- \setupinterlinespace[#1]%
- \localinterlinespacefalse}
-
-\def\simplesetupinterlinespace
- {\localinterlinespacetrue
- \setfontparameters
- \updateraggedskips % funny one here
- \localinterlinespacefalse}
-
-\definecomplexorsimple\setupinterlinespace
-
-% In earlier versions \type{\bigskipamount} was
-% \type{\ht\strutbox} and the stretch was plus or minus
-% \type{.4\dp\strutbox}. Don't ask me why. The most recent
-% implementation is based on a user supplied distance, which
-% is by default \type{.75\normalskipamount} where
-% \type{\normalskipamount} equals the current baseline
-% distance.
-
-% \lineskiplimit = -\maxdimen -> freezes baselineskip
-
-% can be conditionals
-
-\newif\ifblanknowhite \blanknowhitefalse
-\newif\ifblankindeed \blankindeedfalse
-\newif\ifblankreset \blankresetfalse
-\newif\ifblankdisable \blankdisablefalse
-\newif\ifblankflexible \blankflexibletrue
-\newif\ifblankouter
-\newif\ifblankforce
-\newif\ifblankgoback
-
-\newskip\blankskip \blankskip=\bigskipamount
-\newskip\blankskipamount
-
-\def\skipfactor {.75}
-\def\skipgluefactor{.25}
-
-\def\normalskipamount
- {\openlineheight
- \ifgridsnapping \else \ifblankflexible
- \!!plus \skipgluefactor\openlineheight
- \!!minus\skipgluefactor\openlineheight
- \fi \fi
- \relax}
-
-\def\linedistance {\normalskipamount}
-\def\appliedblankskip{\skipfactor\linedistance}
-\def\lastblankskip {\blankskip}
-\def\currentblank {\v!big}
-\def\oldprevdepth {\prevdepth}
-\def\newprevdepth {-1001pt}
-\def\mindimen {1sp} % was: 0.00002pt
-
-\newif\iflocalblankfixed
-\newif\iflocalblankflexible
-
-\def\geenblanko{\removelastskip} % will become obsolete
-
-%%%% pas op, wordt ook in core-pos gebruikt
-
-\def\doassignsomeskip#1\to#2% ook nog \v!halfline+fuzzysnap
- {\doifelse{#1}\v!line
- {#2\openlineheight}
- {\ifgridsnapping
- \assigndimension{#1}{#2}{.25\openlineheight}{.5\openlineheight}\openlineheight
- \else
- \assigndimension{#1}{#2}\smallskipamount\medskipamount\bigskipamount
- \fi}%
- \relax}
-
-% \relax is really needed, else we may loose stretch due to lookahead; somehow
-% this bug was introduced a while ago but somehow went unnoticed; fixed 2/7/2008
-
-\def\addblankskip#1#2#3{\global\advance\blankskip#1\ifgridsnapping#3\else#2\fi\relax}
-
-\def\defineblankmethod[#1]#2{\setvalue{\??bo\??bo#1}{#2}}
-
-\defineblankmethod [\v!big] {\addblankskip+\bigskipamount \openlineheight}
-\defineblankmethod [-\v!big] {\addblankskip-\bigskipamount \openlineheight}
-\defineblankmethod [\v!medium] {\addblankskip+\medskipamount {.5\openlineheight}}
-\defineblankmethod [-\v!medium] {\addblankskip-\medskipamount {.5\openlineheight}}
-\defineblankmethod [\v!small] {\addblankskip+\smallskipamount{.25\openlineheight}}
-\defineblankmethod [-\v!small] {\addblankskip-\smallskipamount{.25\openlineheight}}
-\defineblankmethod [\v!white] {\addblankskip+\parskip \openlineheight}
-\defineblankmethod [-\v!white] {\addblankskip-\parskip \openlineheight}
-\defineblankmethod [\v!line] {\addblankskip+\openlineheight \openlineheight}
-\defineblankmethod [-\v!line] {\addblankskip-\openlineheight \openlineheight}
-
-\defineblankmethod [\v!formula] {\global\advance\blankskip\medskipamount}
-\defineblankmethod [\v!nowhite] {\global\blanknowhitetrue}
-\defineblankmethod [\v!disable] {\global\blankdisabletrue}
-\defineblankmethod [\v!force] {\global\blankforcetrue}
-\defineblankmethod [\v!outer] {\ifvmode\ifinner\blankoutertrue\fi\fi}
-\defineblankmethod [\v!reset] {\global\blankresettrue}
-\defineblankmethod [\v!flexible] {\global\localblankflexibletrue}
-\defineblankmethod [\v!fixed] {\global\localblankfixedtrue}
-\defineblankmethod [\v!back] {\global\blankgobacktrue} % {\geenblanko}
-\defineblankmethod [\v!halfline] {\ifgridsnapping\global\fuzzyvskiptrue\fi
- \global\advance\blankskip .5\lineheight}
-
-\defineblankmethod [\v!none] {\global\blankresettrue}
-\defineblankmethod [\v!joinedup] {\ifvmode\nointerlineskip\fi}
-
-\defineblankmethod [\v!always] {\redowhitespace} % experimental
-
-% happens often, so we speed this up:
-%
-% \defineblankmethod [2*\v!line] {\addblankskip+{2\openlineheight}{2\openlineheight}}
-% \defineblankmethod [2*\v!big] {\addblankskip+{2\bigskipamount }{2\openlineheight}}
-%
-% no, with 2\whatever we loose the stretch and shrink! Taco's alternative:
-
-\defineblankmethod
- [2*\v!line]
- {\addblankskip+\openlineheight\openlineheight
- \addblankskip+\openlineheight\openlineheight}
-
-\defineblankmethod
- [2*\v!big]
- {\addblankskip+\bigskipamount\openlineheight
- \addblankskip+\bigskipamount\openlineheight}
-
-\def\doblank#1%
- {\edefconvertedargument\ascii{#1}%
- \ifx\ascii\empty\else
- \ifcsname\??bo\??bo\ascii\endcsname % internal def
- \csname\??bo\??bo\ascii\endcsname
- \else\ifcsname\??bo\ascii\endcsname % user def / slow
- \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
- \else
- \dorepeatwithcommand[#1]\redoblank
- \fi\fi
- \fi
- \relax}
-
-\def\redoblank#1%
- {\edefconvertedargument\ascii{#1}%
- \ifx\ascii\empty\else
- \ifcsname\??bo\??bo\ascii\endcsname % internal def
- \csname\??bo\??bo\ascii\endcsname
- \else\ifcsname\??bo\ascii\endcsname % user def / slow
- \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
- \else
- \global\advance\blankskip#1\relax
- \fi\fi
- \fi
- \relax}
-
-\unexpanded\def\blank % the \relax is definitely needed due to the many \if's
- {\relax\complexorsimple\doblank}
-
-\def\complexdoblank
- {\flushnotes
- \ifmmode
- \@EA\nocomplexdoblank
- \else
- \ifopelkaar
- \ifinpagebody
- \@EA\@EAEAEA\@EA\docomplexdoblank
- \else
- \@EA\@EAEAEA\@EA\nocomplexdoblank
- \fi
- \else
- \@EAEAEA\docomplexdoblank
- \fi
- \fi}
-
-\def\nocomplexdoblank[#1]%
- {% evt blokkeerfalse
- \ifmmode\else\par\fi}
-
-% Overloaded in cont-new!
-
-\newsignal\noblanksignal
-
-% \def\doinhibitblank
-% {\kern\noblanksignal}
-
-% \def\inhibitblank% the fast, local way
-% {\endgraf\ifvmode\prevdepth\newprevdepth\fi}
-
-% \def\docomplexdoblank[#1]% pas op \relax's zijn nodig ivm volgende \if
-% {\global\blankresetfalse
-% \global\blankdisablefalse
-% \global\blanknowhitefalse
-% \global\localblankflexiblefalse
-% \global\localblankfixedfalse
-% \global\blankskip\zeropoint
-% \global\blankforcefalse
-% \global\blankgobackfalse
-% \blankouterfalse
-% \expanded{\rawprocesscommalist[#1]}\doblank
-% \ifdim\blankskip=\zeropoint\relax
-% \iflocalblankflexible
-% \doglobal\advance\blankskip \currentblank
-% \else\iflocalblankfixed
-% \doglobal\advance\blankskip \currentblank
-% \fi\fi
-% \fi
-% \ifblankouter
-% \else
-% \par
-% \ifvmode
-% \ifblankgoback
-% \removelastskip
-% \fi
-% \ifblankforce
-% % dit gaat mis in pos fonts
-% % \ifdim\prevdepth>\zeropoint\else ...
-% % -1000pt signals top of page or column (\ejectcolumn)
-% \bgroup\forgeteverypar\verticalstrut\egroup\kern-\struttotal
-% \fi
-% \ifblankdisable
-% \global\blankindeedfalse
-% \ifgridsnapping
-% \ifdim\prevdepth<\zeropoint
-% % brrr
-% \else
-% % dirty trick: smaller blanks are ignored after
-% % a larger one, so 10 lines is probably safe; first make
-% % sure that we honor penalties
-% \scratchcounter\lastpenalty
-% % now comes the trick (cross our fingers that this works
-% % well in multi columns; maybe an ifinner test is needed
-% % \vskip-10\lineheight
-% % \ifnum\scratchcounter=\zerocount \else \penalty\lastpenalty \fi
-% % \vskip 10\lineheight
-% % allas, this leads to overfull pages, so we try this:
-% \kern-\noblanksignal
-% \ifnum\scratchcounter=\zerocount
-% \else
-% \penalty\lastpenalty
-% \fi
-% \kern\noblanksignal
-% % end-of-dirty-trick
-% \fi
-% \else
-% \ifdim\prevdepth<\zeropoint
-% % brrr
-% \else
-% % ensure at least a proper prevdepth, this should be
-% % an option
-% \vskip-\prevdepth
-% \vskip\strutdepth
-% \prevdepth\strutdepth
-% \fi
-% % the old crappy piece of code
-% \edef\oldprevdepth{\the\prevdepth}%
-% \prevdepth\newprevdepth
-% \fi
-% \else
-% \global\blankindeedtrue
-% \fi
-% \ifblankreset
-% \global\blankindeedtrue
-% \ifgridsnapping
-% % let's play safe and not fool around with the depth, if
-% % only because it took a lot of effort to sort out the grid
-% % stuff in the first place
-% \else
-% \ifdim\prevdepth=\newprevdepth
-% \prevdepth\oldprevdepth
-% \fi
-% \fi
-% \fi
-% \ifblankindeed
-% \ifdim1\lastskip<1\blankskip\relax
-% % else when \blanko[2*groot] + \blanko[3*groot] with parskip
-% % equaling 1*groot, gives a groot=\parskip so adding a small
-% % value makes it distinguishable; can also be done at parskip
-% % setting time (better)
-% \global\advance\blankskip \mindimen\relax % = skip
-% % test this on 2* + 3* and parskip groot
-% \ifblanknowhite
-% \global\advance\blankskip -\parskip
-% \else
-% \ifdim\lastskip=\parskip
-% \else % force this due to previous comment
-% \ifdim\parskip>\zeropoint\relax
-% \ifdim\blankskip<\parskip\relax
-% \global\blankskip\zeropoint
-% \else
-% \global\advance\blankskip -\parskip
-% \fi
-% \fi
-% \fi
-% \fi
-% \ifblankflexible \else
-% \blankskip1\blankskip
-% \fi
-% \iflocalblankfixed
-% \blankskip1\blankskip
-% \fi
-% \iflocalblankflexible
-% \blankskip1\blankskip
-% \!!plus\skipgluefactor\blankskip
-% \!!minus\skipgluefactor\blankskip
-% \fi
-% \ifdim\lastkern=\noblanksignal % controled and grid
-% \global\blankindeedfalse
-% \else\ifgridsnapping\else\ifdim\prevdepth=\newprevdepth
-% \global\blankindeedfalse
-% \fi\fi\fi
-% \ifblankindeed
-% \iffuzzyvskip
-% \removelastfuzzyvskip
-% \fuzzyvskip\blankskip\relax
-% \else
-% \removelastskip
-% \vskip\blankskip\relax
-% \fi
-% \fi
-% \else
-% \iffuzzyvskip
-% \removelastfuzzyvskip
-% \fuzzyvskip\blankskip\relax
-% \else
-% % new, test this on pascal
-% \ifdim\blankskip<\zeropoint
-% \advance\blankskip-\lastskip
-% \removelastskip
-% \ifdim\blankskip>\zeropoint
-% \vskip\blankskip
-% \else
-% \vskip\zeropoint
-% \fi
-% \else
-% % also new
-% \ifdim\blankskip=\zeropoint
-% \ifblanknowhite
-% \geenwitruimte
-% \fi
-% \fi
-% \fi
-% \fi
-% \fi
-% \fi
-% \fi
-% \fi
-% \global\fuzzyvskipfalse
-% \presetindentation}
-
-% goback was broken:
-
-% \def\doinhibitblank
-% {\kern\noblanksignal}
-
-% \def\inhibitblank% the fast, local way
-% {\endgraf\ifvmode\prevdepth\newprevdepth\fi}
-
-% problem: we cannot look back in the mvl so we need 3 kinds of signals
-
-\def\noblankpsignal{1010101}
-
-\def\inhibitgridblank % was doinhibitblank
- {\ifvmode\else\endgraf\fi
- \ifvmode
- \ifnum\lastpenalty<10000
- \kern-\noblanksignal % new
- \kern \noblanksignal
- \else
- \penalty\noblankpsignal
- \fi
- \fi}
-
-\def\inhibittextblank % was inhibitblank
- {\endgraf
- \ifvmode
- \prevdepth\newprevdepth
- \fi}
-
-% new macro
-%
-% \def\inhibitblank % need some work
-% {\endgraf
-% \ifvmode
-% \ifgridsnapping
-% \inhibitgridblank
-% \else
-% % this one spoils the grid
-% \inhibittextblank
-% \fi
-% \fi}
-
-\def\doinhibitblank{\inhibitgridblank}
-\def\inhibitblank {\inhibittextblank}
-
-% will become obsolete
-
-\ifx\undefined\savedlastskip \newskip \savedlastskip \fi
-\ifx\undefined\savedlastpenalty \newcount\savedlastpenalty \fi
-
-% beware, prevdepth can have funny values (e.g. mvl value when in box)
-
-\def\docomplexdoblank[#1]% pas op \relax's zijn nodig ivm volgende \if
- {\global\blankresetfalse
- \global\blankdisablefalse
- \global\blanknowhitefalse
- \global\localblankflexiblefalse
- \global\localblankfixedfalse
- \global\blankforcefalse
- \global\blankgobackfalse
- \blankouterfalse
- \global\blankskip\zeropoint
-%
-\edefconvertedargument\ascii{#1}% todo fast check for simple
-\ifcsname\??bo\??bo\ascii\endcsname % internal def
- \csname\??bo\??bo\ascii\endcsname
-\else\ifcsname\??bo\ascii\endcsname % user def / slow
- \@EA\rawprocesscommalist\@EA[\csname\??bo\ascii\endcsname]\doblank\relax
-\else
- \expanded{\rawprocesscommalist[#1]}\doblank
-\fi\fi
-%
- \relax % to be sure
- \ifdim\blankskip=\zeropoint\relax
- \iflocalblankflexible
- \doglobal\advance\blankskip \currentblank
- \else\iflocalblankfixed
- \doglobal\advance\blankskip \currentblank
- \fi\fi
- \fi
- \relax % to be sure
- \ifblankouter
- % do nothing
- \else
- \par
- \ifvmode
- \ifblankgoback
- \ifdim\lastskip>\zeropoint \vskip-\lastskip \fi
- \savedlastskip\zeropoint
- \else\ifdim\lastskip>\zeropoint
- \savedlastskip\lastskip
- \else % todo: lastnode, dan namelijk geen skip !
- \savedlastskip\zeropoint
- \fi\fi
- \ifblankforce
- % dit gaat mis in pos fonts
- % \ifdim\prevdepth>\zeropoint\else ...
- % -1000pt signals top of page or column (\ejectcolumn)
- \bgroup\forgeteverypar\verticalstrut\egroup\kern-\struttotal
- \savedlastskip\zeropoint
- \fi
- \savedlastpenalty\lastpenalty % hm, now it gets lost
- \ifblankdisable
- \global\blankindeedfalse % keep this, i.e. disable current too
- \ifgridsnapping
- \ifdim\prevdepth<\zeropoint
- % brrr
- \else
- % dirty trick: smaller blanks are ignored after a
- % larger one, so 10 lines is probably safe; we need
- % to make sure that we honor penalties; here comes the
- % trick (cross our fingers that this works well in
- % multi columns; maybe an ifinner test is needed
- % \scratchcounter\lastpenalty
- % \vskip-10\lineheight
- % \ifnum\scratchcounter=\zerocount \else \penalty\lastpenalty \fi
- % \vskip 10\lineheight
- % alas, this leads to overfull pages, so we try this:
- \inhibitgridblank
- \fi
- \else
- \ifdim\prevdepth<\zeropoint
- % brrr
- \else
- % ensure at least a proper prevdepth, this should be
- % an option
- \vskip-\prevdepth
- \vskip\strutdepth
- \prevdepth\strutdepth
- \fi
- % the old crappy piece of code
- \edef\oldprevdepth{\the\prevdepth}%
- \prevdepth\newprevdepth % == \inhibittextblank
- \fi
- \else
- \global\blankindeedtrue
- \fi
- \ifblankreset
- \global\blankindeedtrue
- \ifgridsnapping
- % let's play safe and not fool around with the depth, if
- % only because it took a lot of effort to sort out the grid
- % stuff in the first place
- \else
- \ifdim\prevdepth=\newprevdepth
- \prevdepth\oldprevdepth
- \fi
- \fi
- \fi
- \ifblankindeed
- \ifdim1\savedlastskip<1\blankskip\relax
- % else when \blank[2*groot] + \blank[3*groot] with parskip
- % equaling 1*groot, gives a groot=\parskip so adding a small
- % value makes it distinguishable; can also be done at parskip
- % setting time (better)
- \global\advance\blankskip \mindimen\relax % = skip
- % test this on 2* + 3* and parskip groot
- \ifblanknowhite
- \global\advance\blankskip -\parskip
- \else
- \ifdim\savedlastskip=\parskip
- \else % force this due to previous comment
- \ifdim\parskip>\zeropoint\relax
- \ifdim\blankskip<\parskip\relax
- \global\blankskip\zeropoint
- \else
- \global\advance\blankskip -\parskip
- \fi
- \fi
- \fi
- \fi
- \ifblankflexible \else
- \blankskip1\blankskip
- \fi
- \iflocalblankfixed
- \blankskip1\blankskip
- \fi
- \iflocalblankflexible
- \blankskip1\blankskip
- \!!plus \skipgluefactor\blankskip
- \!!minus\skipgluefactor\blankskip
- \fi
- \ifdim\lastkern=\noblanksignal\relax % controlled and grid
- \global\blankindeedfalse
- \else\ifnum\savedlastpenalty=\noblankpsignal\relax % controlled and grid
- \global\blankindeedfalse
- \else\ifgridsnapping\else\ifdim\prevdepth=\newprevdepth
- \global\blankindeedfalse
- \fi\fi\fi\fi
- \ifblankindeed
- \iffuzzyvskip
- \removelastfuzzyvskip
- \fuzzyvskip\blankskip\relax
- \else
- \relax\ifdim\savedlastskip=\zeropoint\else
- \vskip-\savedlastskip
- \fi
- \vskip\blankskip\relax
- \fi
- \fi
- \else
- \iffuzzyvskip
- \removelastfuzzyvskip
- \fuzzyvskip\blankskip\relax
- \else
- % new, test this on pascal
- \ifdim\blankskip<\zeropoint
- \relax\ifdim\savedlastskip=\zeropoint\else
- \advance\blankskip-\savedlastskip
- \vskip-\savedlastskip
- \fi
- \ifdim\blankskip>\zeropoint
- \vskip\blankskip
- \else
- \vskip\zeropoint
- \fi
- \else
- % also new
- \ifdim\blankskip=\zeropoint
- \ifblanknowhite
- \nowhitespace
- \fi
- \fi
- \fi
- \fi
- \fi
- \fi
- \fi
- \fi
- \global\fuzzyvskipfalse
- \presetindentation}
-
-%D For a long time we had:
-%D
-%D \starttyping
-%D \def\simpledoblank%
-%D {\doifelse{\currentwhitespace}{\v!geen}
-%D {\blank[\currentblank]}
-%D {\blank[\currentwhitespace]}}
-%D \stoptyping
-%D
-%D But Berend de Boer wanted more control, so now we have:
-
-\def\simpledoblank % ...
- {\doifelse\currentwhitespace\v!none
- {\blank[\currentblank]}
- {\blank[\s!default]}}
-
-%D Another useful definition would be:
-%D
-%D \starttyping
-%D \defineblank
-%D [\s!default]
-%D [\v!groot]
-%D \stoptyping
-
-\def\dosetupblank#1% amount are an plain inheritance
- {\bigskipamount#1\relax
- \ifblankflexible \else
- \bigskipamount1\bigskipamount
- \fi
- \medskipamount \bigskipamount \divide\medskipamount \plustwo
- \smallskipamount\bigskipamount \divide\smallskipamount\plusfour}%
-
-\def\complexsetupblank[#1]% more \let's -> this also wil become installable
- {\ifgridsnapping
- \blankflexiblefalse
- \else
- \ExpandFirstAfter\processallactionsinset
- [#1]
- [ \v!flexible=>\blankflexibletrue,
- \v!fixed=>\blankflexiblefalse]%
- \fi
- \ExpandFirstAfter\processallactionsinset
- [#1]
- [ \v!flexible=>\dosetupblank\appliedblankskip,
- \v!fixed=>\dosetupblank\appliedblankskip,
- \v!line=>\edef\appliedblankskip{\linedistance}%
- \dosetupblank\appliedblankskip,
- \v!halfline=>\scratchskip.5\linedistance
- \edef\appliedblankskip{\the\scratchskip}%
- \dosetupblank\appliedblankskip,
- \v!big=>\ifgridsnapping
- \edef\appliedblankskip{\linedistance}%
- \dosetupblank\appliedblankskip
- \fi
- \let\currentblank\v!big,
- \v!medium=>\let\currentblank\v!medium,
- \v!small=>\let\currentblank\v!small,
- \v!global=>\let\currentblank\v!global,
- \v!normal=>\dosetupblank\appliedblankskip,
- \v!standard=>\edef\appliedblankskip{\skipfactor\linedistance}%
- \dosetupblank\appliedblankskip,
- \s!default=>\dosetupblank\appliedblankskip,
- \s!unknown=>\let\appliedblankskip\commalistelement
- \dosetupblank\appliedblankskip]%
- \simplesetupwhitespace}
-
-% \definecomplexorsimpleempty\setupblank
-%
-% speed gain: 60 sec -> 30 sec
-
-\definecomplexorsimple\setupblank
-
-\def\simplesetupblank % == snelle \setupblank[\s!default]
- {\ifgridsnapping
- \blankflexiblefalse
- \fi
- \dosetupblank\appliedblankskip
- % \let\deblanko\v!big
- \simplesetupwhitespace}
-
-\def\restorestandardblank% \v!standard
- {\edef\appliedblankskip{\skipfactor\linedistance}%
- \dosetupblank\appliedblankskip
- }%\let\deblanko\v!big}
-
-\def\dodefineblank[#1][#2]%
- {\def\docommand##1{\setvalue{\??bo##1}{#2}}%
- \processcommalist[#1]\docommand}
-
-\def\defineblank
- {\dodoubleargument\dodefineblank}
-
-\def\savecurrentblank
- {\edef\restorecurrentblank
- {\bigskipamount\the\bigskipamount
- \medskipamount\the\medskipamount
- \smallskipamount\the\smallskipamount
- \noexpand\def\noexpand\currentblank{\currentblank}%
- \ifblankflexible
- \noexpand\blankflexibletrue
- \else
- \noexpand\blankflexiblefalse
- \fi}}
-
-%D Now.
-
-\defineblank [\s!default] [\v!white]
-\defineblank [\v!height] [\strutheight]
-\defineblank [\v!depth] [\strutdepth]
-
-% old implementation
-%
-% \let\currentindentation=\empty
-%
-% \newdimen\ctxparindent
-%
-% \newif\ifindentfirstparagraph % \indentfirstparagraphtrue
-%
-% \def\presetindentation
-% {\doifoutervmode{\ifindentfirstparagraph\else\noindentation\fi}}
-%
-% \definecomplexorsimple\setupindenting
-%
-% \def\complexsetupindenting[#1]%
-% {\processallactionsinset
-% [#1]
-% [ \v!first=>\indentfirstparagraphtrue,
-% \v!next=>\indentfirstparagraphfalse,
-% \s!default=>\simplesetupindenting,
-% \s!unknown=>\edef\currentindentation{\commalistelement}%
-% \simplesetupindenting]}
-%
-% \def\simplesetupindenting
-% {\assigndimension\currentindentation\ctxparindent{1em}{1.5em}{2em}%
-% \parindent\ctxparindent\relax}
-%
-% \def\indenting % watch out: \dodo and no \do
-% {\dosingleargument\dodoindenting}
-%
-% \def\dodoindenting[#1]% oeps, we needed a commalist handler here!
-% {\edef\currentindenting{#1}%
-% \processcommacommand[#1]\dododoindenting}
-%
-% \def\dododoindenting#1%
-% {\executeifdefined{\??in:#1}\donothing}
-%
-% \let\currentindenting\empty
-%
-% \def\defineindentingmethod[#1]#2%
-% {\setvalue{\??in:#1}{#2}}
-%
-% \defineindentingmethod [\v!no] {\parindent\ctxparindent\noindent}
-% \defineindentingmethod [\v!not] {\parindent\ctxparindent\noindent}
-%
-% \defineindentingmethod [\v!first] {\indentfirstparagraphtrue}
-% \defineindentingmethod [\v!next] {\indentfirstparagraphfalse}
-%
-% \defineindentingmethod [\v!yes] {\parindent\ctxparindent\relax} % no \indent !
-% \defineindentingmethod [\v!always] {\parindent\ctxparindent\relax} % no \indent !
-%
-% \defineindentingmethod [\v!never] {\parindent\zeropoint\relax} % no \indent !
-%
-% \def\noindenting{\indenting[\v!no,\v!next]} % was \nietinspringen
-% \def\doindenting{\indenting[\v!yes,\v!first]} % was \welinspringen
-%
-% \def\dochecknextindentation#1% internal one
-% {\checknextindentation[\getvalue{#1\c!indentnext}]}
-%
-% \def\checknextindentation[#1]%
-% {\processaction[#1][%\v!keep=>,
-% \v!yes=>\doindentation,
-% \v!no=>\noindentation,
-% \v!auto=>\autoindentation]}
-%
-% \def\doindentation% too simple
-% {\gdef\checkindentation{\global\indentationtrue}}
-%
-% \ifx\autoindentation\undefined
-% \let\autoindentation\relax
-% \fi
-%
-% \newif\ifindentation \indentationtrue % documenteren, naar buiten
-%
-% \let\checkindentation=\relax
-%
-% \def\donoindentation
-% {\ifdim\parindent=\zeropoint \else
-% \bgroup \setbox\scratchbox\lastbox \egroup
-% \fi}
-%
-% \def\noindentation % made global
-% {\ifinpagebody \else
-% \global\indentationfalse
-% \gdef\checkindentation
-% {\donoindentation
-% \gdef\checkindentation{\global\indentationtrue}}%
-% \fi}
-%
-% \def\nonoindentation % bv bij floats
-% {\ifinpagebody \else
-% \global\indentationtrue
-% \gdef\checkindentation{\global\indentationtrue}%
-% \fi}
-%
-% \def\indentation
-% {\ifvmode \ifdim\parindent=\zeropoint \else
-% % was : \hskip\parindent
-% % can be: \indent
-% % but we test:
-% \noindent\hskip\parindent
-% \fi \fi}
-
-\let\currentindentation\empty % amount/keyword
-% \let\normalindentation \empty % used for reinstating normal indentation
-\let\currentindenting \empty % method
-
-\newdimen\ctxparindent
-
-\newif\ifindentfirstparagraph % \indentfirstparagraphtrue
-
-\chardef\indentingtoggle\zerocount
-
-%D After a blank or comparable situation (left side floats) we
-%D need to check if the next paragraph has to be indented.
-
-\def\presetindentation
- {\doifoutervmode{\ifindentfirstparagraph\else\noindentation\fi}}
-
-%D This sets up the (normally) global indentation behavior as well
-%D as the amounts.
-
-\definecomplexorsimple\setupindenting
-
-% \def\complexsetupindenting[#1]%
-% {\edef\currentindenting{#1}%
-% \indentfirstparagraphtrue
-% \parindent\ctxparindent
-% \chardef\indentingtoggle\zerocount
-% \processcommalist[#1]\docomplexsetupindenting
-% \ifindentfirstparagraph\else\noindentation\fi % added
-% \toggleindentation}
-
-\indentfirstparagraphtrue
-\parindent\ctxparindent
-\chardef\indentingtoggle\zerocount
-
-% \newtoks\savedeverypar \savedeverypar\everypar
-% \def\restoreeverypar{\everypar\savedeverypar}
-
-% we need a better everypar model: for each option a switch, which we
-% set to false with \forgetall and can enable when needed (context 4);
-% that way we can control the order of execution of options
-
-\def\checkeverypar % currently a hack
- {\ifzeropt\parindent\else
- \doifsometokselse\everypar\donothing{\appendtoks\checkindentation\to\everypar}%
- \fi}
-
-\def\complexsetupindenting[#1]%
- {\edef\currentindenting{#1}%
- \doifsomething\currentindenting % handy when a parameter is passed
- {% not here: \indentfirstparagraphtrue
- % not here: \parindent\ctxparindent
- % not here: \chardef\indentingtoggle\zerocount
- % we use commacommand in order to catch #1 being a command (expanded parameter)
- \processcommacommand[\currentindenting]\docomplexsetupindentingA % catch small, medium, etc
- \processcommacommand[\currentindenting]\docomplexsetupindentingB % catch rest
- \checkeverypar % only when non-empty #1
- \ifindentfirstparagraph\else\noindentation\fi % added
- \toggleindentation}}
-
-\def\docomplexsetupindentingA#1%
- {\edefconvertedargument\!!stringa{#1}%
- \doifundefined{\??in:\!!stringa}%
- {\edef\currentindentation{#1}%
- \let\normalindentation\currentindentation
- \simplesetupindenting}}
-
-\def\docomplexsetupindentingB#1%
- {\edefconvertedargument\!!stringa{#1}% catch #1=\somedimen
- \executeifdefined{\??in:\!!stringa}\donothing}
-
-\def\simplesetupindenting % empty case, a it strange, needed this way?
- {\assigndimension\currentindentation\ctxparindent{1em}{1.5em}{2em}}
-
-\def\indenting % kind of obsolete
- {\dosingleargument\complexsetupindenting}
-
-% use \noindentation to suppress next indentation
-
-\def\defineindentingmethod[#1]#2%
- {\setvalue{\??in:#1}{#2}}
-
-\defineindentingmethod [\v!no] {\parindent\zeropoint}% was: \ctxparindent\noindent}
-\defineindentingmethod [\v!not] {\parindent\zeropoint}% was: \ctxparindent\noindent}
-
-\defineindentingmethod [\v!first] {\indentfirstparagraphtrue}
-\defineindentingmethod [\v!next] {\indentfirstparagraphfalse}
-
-\defineindentingmethod [\v!yes] {\parindent\ctxparindent\relax} % no \indent !
-\defineindentingmethod [\v!always] {\parindent\ctxparindent\relax} % no \indent !
-
-\defineindentingmethod [\v!never] {\parindent\zeropoint\relax % no \indent !
- \chardef\indentingtoggle\zerocount}
-
-\defineindentingmethod [\v!odd] {\chardef\indentingtoggle\plusone}
-\defineindentingmethod [\v!even] {\chardef\indentingtoggle\plustwo}
-
-\defineindentingmethod [\v!normal] {\ifx\normalindentation\empty\else
- \let\currentindentation\normalindentation
- \simplesetupindenting
- \fi}
-
-\defineindentingmethod [\v!reset] {\indentfirstparagraphtrue
- \parindent\zeropoint
- \chardef\indentingtoggle\zerocount}
-
-\def\noindenting{\indenting[\v!no, \v!next ]}
-\def\doindenting{\indenting[\v!yes,\v!first]}
-
-%D This one sets up the local indentation behaviour (i.e. either or not
-%D a next paragraph will be indented).
-
-\def\dochecknextindentation#1% internal one
- {\checknextindentation[\getvalue{#1\c!indentnext}]}
-
-\def\checknextindentation[#1]%
- {\processaction
- [#1]
- [%\v!keep=>,
- \v!yes=>\doindentation,
- \v!no=>\noindentation,
- \v!auto=>\autoindentation]}
-
-%D Here come the handlers.
-
-\newif\ifindentation \indentationtrue % documenteren, naar buiten
-
-\let\checkindentation\relax
-
-\ifx\autoindentation\undefined \let\autoindentation\relax \fi % hook
-
-\def\doindentation
- {\gdef\checkindentation{\global\indentationtrue}}
-
-\def\noindentation % made global
- {\ifinpagebody \else
- \global\indentationfalse
- \gdef\checkindentation
- {\donoindentation
- \gdef\checkindentation{\global\indentationtrue}}%
- \fi}
-
-\def\nonoindentation % bv bij floats
- {\ifinpagebody \else
- \global\indentationtrue
- \gdef\checkindentation{\global\indentationtrue}%
- \fi}
-
-\def\donoindentation
- {\ifdim\parindent=\zeropoint \else
- \bgroup \setbox\scratchbox\lastbox \egroup
- \fi}
-
-\def\indentation
- {\ifvmode \ifdim\parindent=\zeropoint \else
- % was : \hskip\parindent
- % can be: \indent
- % but we test:
- \noindent\hskip\parindent
- \fi \fi}
-
-\def\toggleindentation
- {\ifcase\indentingtoggle
- % nothing
- \or
- \notoggleindentation
- \or
- \dotoggleindentation
- \fi}
-
-\def\dokillindentation
- {\gdef\checkindentation{\global\indentationfalse\donoindentation}}
-
-\def\dotoggleindentation
- {\gdef\checkindentation{\global\indentationfalse\notoggleindentation\donoindentation}}
-
-\def\notoggleindentation
- {\gdef\checkindentation{\global\indentationtrue\dotoggleindentation}}
-
-\appendtoks
- \pushmacro\checkindentation
- \pushmacro\ifindentation
-\to \everypushsomestate
-
-\appendtoks
- \popmacro\ifindentation
- \popmacro\checkindentation
-\to \everypopsomestate
-
-% we need to save the state if we want to adapt behaviour to empty lines
-%
-% \def\setlasthvmode
-% {\global\chardef\savedhvmode\ifhmode\plusone\else\ifvmode\plustwo\else\zerocount\fi\fi}
-%
-% \def\resetlasthvmode
-% {\global\chardef\savedhvmode\zerocount}
-%
-% \chardef\savedhvmode\zerocount
-
-% This is a user requested hack (using the auto-hook).
-
-\chardef\recheckindentationmode\zerocount
-
-\def\dontrechecknextindentation
- {\global\chardef\recheckindentationmode\zerocount}
-
-\def\dorechecknextindentation
- {\ifcase\recheckindentationmode
- % nothing
- \or
- \dontrechecknextindentation
- \expandafter\doautoindentation
- \fi}
-
-\def\doautoindentation
- {\doifnextcharelse\par\donothing\noindentation}
-
-\def\autoindentation
- {\global\chardef\recheckindentationmode\plusone}
-
-%D An example of usage:
-%D
-%D \starttyping
-%D \setupindenting[small,yes]
-%D
-%D \setupitemize [indentnext=auto]
-%D \setuptyping [indentnext=auto]
-%D \setupformulas[indentnext=auto]
-%D
-%D \input tufte
-%D
-%D \startitemize
-%D \item itemize
-%D \stopitemize
-%D \input tufte
-%D
-%D \startitemize
-%D \item itemize
-%D \stopitemize
-%D
-%D \input tufte
-%D
-%D \startitemize
-%D \item itemize
-%D \stopitemize
-%D
-%D \page
-%D
-%D \input tufte
-%D
-%D \starttyping
-%D verbatim
-%D \stoptyping
-%D \input tufte
-%D
-%D \starttyping
-%D verbatim
-%D \stoptyping
-%D
-%D \input tufte
-%D
-%D \starttyping
-%D verbatim
-%D \stoptyping
-%D
-%D \page
-%D
-%D \input tufte
-%D
-%D \startformula
-%D a = b
-%D \stopformula
-%D \input tufte
-%D
-%D \startformula
-%D a = b
-%D \stopformula
-%D
-%D \input tufte
-%D
-%D \startformula
-%D a = b
-%D \stopformula
-
-% \frenchspacing leidt soms tot afbreken tussen -, vandaar
-% de variant \newfrenchspacing.
-
-\def\frenchspacing {\setfrenchspacing{1000}}
-\def\newfrenchspacing{\setfrenchspacing{1050}}
-\def\nonfrenchspacing{\resetfrenchspacing}
-
-\def\definespacingmethod[#1]#2{\setvalue{\??sg\??sg#1}{#2}}
-
-\definespacingmethod[\v!packed]{\newfrenchspacing}
-\definespacingmethod[\v!broad ]{\nonfrenchspacing}
-
-\def\complexsetupspacing[#1]%
- {\executeifdefined{\??sg\??sg#1}\relax
- \updateraggedskips}
-
-\def\simplesetupspacing
- {\updateraggedskips}
-
-\definecomplexorsimple\setupspacing
-
-% \dorecurse{100}{\recurselevel\spacefactor 800 \space} \par
-% \dorecurse{100}{\recurselevel\spacefactor1200 \space} \par
-% \dorecurse{100}{\recurselevel\spacefactor 800 \normalspaceprimitive} \par
-% \dorecurse{100}{\recurselevel\spacefactor1200 \normalspaceprimitive} \par
-
-% When we don't add the % here, we effectively get \ and
-% since we have by default \def\^^M{\ } we get into a loop.
-
-\let\normalspaceprimitive=\ % space-comment is really needed
-
-\unexpanded\def\ {\mathortext\normalspaceprimitive\space} % no \dontleavehmode\space (else no frenchspacing)
-
-\unexpanded\def\nonbreakablespace{\penalty\plustenthousand\space}
-
-\letcatcodecommand \ctxcatcodes `\~ \nonbreakablespace % overloaded later
-
-\def\space { }
-\def\removelastspace{\ifhmode\unskip\fi}
-\def\nospace {\removelastspace\ignorespaces}
-
-% in tables we need:
-%
-% \def\fixedspace {\hskip.5em\relax}
-%
-% but, since not all fonts have .5em digits:
-
-\unexpanded\def\fixedspace
- {\setbox\scratchbox\normalhbox{\mathortext{0}{0}}%
- \hskip\wd\scratchbox\relax}
-
-\def\fixedspaces
- {\letcatcodecommand \ctxcatcodes `\~ \fixedspace}
-
-\def\removeunwantedspaces
- {\ifhmode % we also need to unskip 0pt skips
- \unskip\unskip\unskip\unskip\unskip
- \unskip\unskip\unskip\unskip\unskip
- \fi}
-
-\appendtoks\let~\space\to\simplifiedcommands
-
-% still not fixed in aleph / luatex
-%
-% \def\removeunwantedspaces
-% {\ifhmode \ifnum\lastnodetype=\@@gluenode
-% \unskip \@EAEAEA\removeunwantedspaces
-% \fi \fi}
-
-%D For old time sake, will disappear soon.
-
-\let\hardespatie\fixedspace
-\let\geenspatie \nospace
-
-% \startbuffer
-% \startlines \tt \fixedspaces
-% 0~1~~2~~~3~~~~4~~~~~5
-% 0~~~~~~~~~~~~~~~~~~~5
-% $0~1~~2~~~3~~~~4~~~~~5$
-% $0~~~~~~~~~~~~~~~~~~~5$
-% \stoplines
-%
-% \starttabulate[|~|]
-% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \NR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \NR
-% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \NR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \NR
-% \stoptabulate
-%
-% \starttable[||]
-% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \AR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \AR
-% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \AR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \AR
-% \stoptable
-% \stopbuffer
-%
-% \setupbodyfont[cmr] \getbuffer
-% \setupbodyfont[lbr] \getbuffer
-
-\def\packed
- {\nointerlineskip}
-
-\def\godown[#1]%
- {\relax
- \ifhmode\endgraf\fi
- \ifvmode\nointerlineskip\vskip#1\relax\fi}
-
-%D A couple of plain macros:
-
-\ifx\thinspace\undefined
-
- \def\thinspace {\kern .16667em }
- \def\negthinspace{\kern-.16667em }
- \def\enspace {\kern .5em }
-
- \def\thinspace {\kern .16667\fontdimen6\font}
- \def\negthinspace{\kern-.16667\fontdimen6\font}
- \def\enspace {\kern .5\fontdimen6\font}
-
-\fi
-
-\ifx\quad\undefined
-
- \def\enskip{\hskip.5em\relax}
- \def\quad {\hskip 1em\relax}
- \def\qquad {\hskip 2em\relax}
-
- \def\enskip{\hskip.5\fontdimen6\font}
- \def\quad {\hskip \fontdimen6\font} % faster
- \def\qquad {\hskip 2\fontdimen6\font}
-
-\fi
-
-\let\emspace\quad
-
-\ifx\smallskip\undefined
-
- \def\smallskip{\vskip\smallskipamount}
- \def\medskip {\vskip\medskipamount}
- \def\bigskip {\vskip\bigskipamount}
-
-\fi
-
-\ifx\allowbreak\undefined
-
- \def\break {\penalty\ifhmode-\plustenthousand\else\ejectpenalty\fi}
- \def\nobreak {\penalty \plustenthousand}
- \def\allowbreak{\penalty \zeropoint}
- \def\filbreak {\par\vfil\penalty-200\vfilneg}
- \def\goodbreak {\par\penalty-500 }
-
-\fi
-
-%D Made slightly more readable:
-
-\ifx\vglue\undefined
-
- \def\vglue {\afterassignment\dovglue\scratchskip=}
- \def\hglue {\afterassignment\dohglue\scratchskip=}
- \def\topglue{\nointerlineskip\vglue-\topskip\vglue}
-
- \def\dovglue
- {\par
- \scratchdimen\prevdepth
- \hrule\!!height\zeropoint
- \nobreak\vskip\scratchskip
- \prevdepth\scratchdimen}
-
- \def\dohglue
- {\dontleavehmode % \leavevmode
- \scratchcounter\spacefactor
- \vrule\!!width\zeropoint
- \nobreak\hskip\scratchskip
- \spacefactor\scratchcounter}
-
-\fi
-
-\ifx\eject\undefined
-
- \def\eject{\par\break}
-
-\fi
-
-\ifx\supereject\undefined
-
- \def\supereject{\par\penalty\superpenalty}
-
-\fi
-
-\ifx\dosupereject\undefined
-
- \def\dosupereject
- {\ifnum\insertpenalties>\z@ % something is being held over
- \line{}
- \kern-\topskip
- \nobreak
- \vfill\supereject
- \fi}
-
-\fi
-
-%D We adapt plain's \type {\removelastskip} a bit:
-
-\ifx\removelastskip\undefined
-
- \def\removelastskip
- {\ifvmode \ifdim\lastskip=\zeropoint \else
- \vskip-\lastskip
- \fi \fi}
-
-\fi
-
-\ifx\smallbreak\undefined
-
-\def\smallbreak
- {\par
- \ifdim\lastskip<\smallskipamount
- \removelastskip
- \penalty-50
- \smallskip
- \fi}
-
-\def\medbreak
- {\par
- \ifdim\lastskip<\medskipamount
- \removelastskip
- \penalty-100
- \medskip
- \fi}
-
-\def\bigbreak
- {\par
- \ifdim\lastskip<\bigskipamount
- \removelastskip
- \penalty-200
- \bigskip
- \fi}
-
-\fi
-
-\newskip\ctxparskip \ctxparskip\zeropoint
-
-\newconditional \flexiblewhitespace \settrue\flexiblewhitespace
-
-\def\blankokleinmaat {\smallskipamount}
-\def\blankomiddelmaat {\medskipamount}
-\def\blankogrootmaat {\bigskipamount}
-\def\currentwhitespace {\zeropoint}
-
-\definecomplexorsimple\setupwhitespace
-
-% \def\simplesetupwhitespace
-% {\doifnot\currentwhitespace\v!none\dosetupwhitespace}
-%
-% \def\complexsetupwhitespace[#1]%
-% {\doifelsenothing{#1}
-% {\simplesetupwhitespace}
-% {\edef\currentwhitespace{#1}%
-% \dosetupwhitespace}}
-%
-% \def\dosetupwhitespace
-% {\processcommacommand[\currentwhitespace]\dowhitespacemethod
-% \dodosetupwhitespace}
-
-\def\simplesetupwhitespace
- {\doifnot\currentwhitespace\v!none\dosetupwhitespace}
-
-\def\complexsetupwhitespace[#1]%
- {\edef\nextcurrentwhitespace{#1}%
- \ifx\nextcurrentwhitespace\empty
- \simplesetupwhitespace
- \else
- \let\currentwhitespace\nextcurrentwhitespace
- \dosetupwhitespace
- \fi}
-
-\def\dosetupwhitespace % quick test for no list
- {\ifcsname\??ws\??ws\currentwhitespace\endcsname
- \csname\??ws\??ws\currentwhitespace\endcsname
- \else
- \expandafter\processcommalist\expandafter[\currentwhitespace]\dowhitespacemethod % can be raw
- \fi\relax
- \ifgridsnapping
- \setfalse\flexiblewhitespace
- \ifdim\ctxparskip>\zeropoint
- \ctxparskip
- \ifcase\baselinegridmode
- \baselineskip % normal ! ! ! ! !!
- \or
- \ifdim\scratchdimen=\baselineskip % maybe range
- \baselineskip % normal ! ! ! ! !!
- \else
- \numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
- \fi
- \else
- \baselineskip % normal ! ! ! ! !!
- \fi
- \fi
- \else
- \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
- \fi
- \parskip\ctxparskip}
-
-\chardef\baselinegridmode=0 % option in layout / 1=permit_half_lines
-
-\def\dodosetupwhitespace
- {\ifgridsnapping
- \setfalse\flexiblewhitespace
- \ctxparskip1\ctxparskip
- \ifdim\ctxparskip>\zeropoint
- \ifcase\baselinegridmode
- \ctxparskip\baselineskip % normal ! ! ! ! !!
- \or
- \ifdim\scratchdimen=\baselineskip % maybe range
- \ctxparskip\baselineskip % normal ! ! ! ! !!
- \else
- \ctxparskip\numexpr\ctxparskip/\dimexpr.5\lineheight\relax\relax\dimexpr.5\lineheight\relax
- \fi
- \else
- \ctxparskip\baselineskip % normal ! ! ! ! !!
- \fi
- \fi
- \else
- \ifconditional\flexiblewhitespace \else \ctxparskip1\ctxparskip \fi
- \fi
- \parskip\ctxparskip}
-
-\definesystemvariable {ws} % whitespace
-
-\def\definewhitespacemethod[#1]#2{\setvalue{\??ws\??ws#1}{#2}}
-
-\definewhitespacemethod [\v!fix] {}
-\definewhitespacemethod [\v!fixed] {\setfalse\flexiblewhitespace}
-\definewhitespacemethod [\v!flexible] {\settrue\flexiblewhitespace}
-\definewhitespacemethod [\v!line] {\ctxparskip \baselineskip}
-\definewhitespacemethod [\v!halfline] {\ctxparskip.5\baselineskip}
-\definewhitespacemethod [\v!none] {\ctxparskip \zeropoint}
-\definewhitespacemethod [\v!big] {\ctxparskip \bigskipamount}
-\definewhitespacemethod [\v!medium] {\ctxparskip \medskipamount}
-\definewhitespacemethod [\v!small] {\ctxparskip \smallskipamount}
-
-\definewhitespacemethod [\s!default] {\simplesetupwhitespace} % {\stelwitruimteopnieuwin}
-
-% \def\dowhitespacemethod#1%
-% {\executeifdefined{\??ws\??ws#1}{\ctxparskip#1}\relax}
-
-\def\dowhitespacemethod#1%
- {\ifcsname\??ws\??ws#1\endcsname\csname\??ws\??ws#1\endcsname\else\ctxparskip#1\fi\relax}
-
-\def\nowhitespace
- {\ifdim\parskip>\zeropoint\relax
- \ifdim\lastskip=-\parskip
- \else
- \vskip-\parskip
- \fi
- \fi}
-
-\def\nowhitespaceunlessskip
- {\ifdim\lastskip>\zeropoint \else
- \nowhitespace
- \fi}
-
-\def\redowhitespace
- {\ifdim\lastskip>-\parskip \else
- \vskip\parskip
- \fi}
-
-\def\savecurrentwhitespace
- {\edef\restorecurrentwhitespace
- {\ctxparskip\the\ctxparskip
- \parskip\the\parskip
- \noexpand\def\noexpand\currentwhitespace{\currentwhitespace}%
- \ifconditional\flexiblewhitespace
- \noexpand\settrue\flexiblewhitespace
- \else
- \noexpand\setfalse\flexiblewhitespace
- \fi}}
-
-% deze variant is nodig binnen \startopelkaar
-% steeds testen:
-%
-% \hoofdstuk{..}
-% \plaatslijst[..]
-% \hoofdstuk{..}
-% \input tufte
-%
-% met/zonder witruimte
-
-\def\whitespace
- {\par
- \ifdim\parskip>\zeropoint\relax
- %\ifdim\lastskip>\parskip \else
- % \removelastskip interferes with blanko blokkeer en klein
- \vskip\parskip
- %\fi
- \fi}
-
-\def\nonoblanko[#1]%
- {\par}
-
-\def\noblanko
- {\dosingleempty\nonoblanko}
-
-% De onderstaande macro handelt ook de situatie dat er geen
-% tekst tussen \start ... \stop is geplaatst. Daartoe wordt de
-% laatste skip over de lege tekst heen gehaald. Dit komt goed
-% van pas bij het plaatsen van (mogelijk lege) lijsten.
-
-\newif\ifopelkaar
-
-\newsignal \noparskipsignal % \def\noparskipsignal {0.00001pt}
-\def\lastdoneparskip {0pt}
-
-\def\startpacked
- {\dosingleempty\dostartpacked}
-
-\def\dostartpacked[#1]% nesting afvangen
- {\par
- \ifvmode
- \edef\lastdoneparskip {\the\lastskip}%
- \edef\lastdoneprevdepth{\the\prevdepth}% zeer recent toegevoegd
- \ifdim\prevdepth=-\thousandpoint % toegevoegd omdat binnen
- \else % een vbox een extra skip
- \whitespace % ongewenst is; dit kan
- \baselinecorrection %% zie in \placeregister[n=1]
- \vskip\noparskipsignal % waarschijnlijk ook in
- \fi % blanko blokkeer
- \bgroup
- \doifelse{#1}\v!blank
- \opelkaarfalse
- \opelkaartrue
- \blank[\v!disable] % dit is nog niet ok, gaat fout
- \setupwhitespace[\v!none] % bovenin vtop (dwz, baseline)
- \fi}
-
-\def\stoppacked
- {\par
- \ifvmode
- \egroup
- \ifdim\lastskip=\noparskipsignal\relax
- \removelastskip
- \nowhitespace
- \vskip-\lastdoneparskip
- \vskip+\lastdoneparskip
- \prevdepth-\lastdoneprevdepth % zeer recent toegevoegd
- \fi
- \fi}
-
-\def\startunpacked
- {\blank
- \leavevmode
- \bgroup}
-
-\def\stopunpacked
- {\egroup
- \blank}
-
-% De onderstaande macro's moeten nog eens nader worden uitgewerkt.
-% Ze spelen een rol bij de spatiering rond omkaderde teksten
-% en/of boxen zonder diepte.
-
-\def\toonregelcorrectie{\showbaselinecorrection}
-\def\regelcorrectie {\baselinecorrection}
-
-% \prevdepth crosses pageboundaries!
-%
-% todo: a version that works ok inside a box
-
-\let\doaroundlinecorrection\relax
-
-\def\startlinecorrection
- {\dodoubleempty\dostartlinecorrection}
-
-\def\dostartlinecorrection[#1][#2]% #2 gobbles spaces
- {\bgroup
- \processaction
- [#1]
- [ \v!blank=>\let\doaroundlinecorrection\blank,
- \s!default=>\let\doaroundlinecorrection\relax,
- \s!unknown=>{\def\doaroundlinecorrection{\blank[#1]}}]%
- \doaroundlinecorrection
- \startbaselinecorrection
- \offbaselinecorrection
- \ignorespaces}
-
-\def\stoplinecorrection
- {\stopbaselinecorrection
- \doaroundlinecorrection
- \egroup}
-
-\def\correctwhitespace
- {\dowithnextbox
- {\startbaselinecorrection
- \flushnextbox
- \stopbaselinecorrection}%
- \vbox}
-
-\def\verticalstrut {\normalvbox{\hsize\zeropoint\forgetall\strut}}
-\def\horizontalstrut{\normalhbox {\strut}}
-
-% Hieronder volgen enkele instellingen en macro's ten behoeve
-% van de interlinie en \strut. De waarden 2.8, 0.07, 0.72 en
-% 0.28 zijn ooit eens ontleend aan INRS-TEX en moeten wellicht
-% nog eens instelbaar worden.
-%
-% \lineheight : de hoogte van een regel
-% \spacing{getal} : instellen interlinie
-% \normalbaselines : instellen regelafstend
-%
-% \setstrut : instellen \strut
-% \setnostrut : resetten \strut, \endstrut, \begstrut
-%
-% \setteststrut : instellen zichtbare struts
-% \resetteststrut : instellen onzichtbare struts
-%
-% \setfontparameters : instellen na fontset
-%
-% De hoogte van een regel (\lineheight) is gelijk aan de
-% som van de hoogte (\ht) en diepte (\dp) van \strutbox.
-%
-% \strut : denkbeeldig blokje met hoogte en diepte
-%
-% Een \hbox kan als deze aan het begin van een regel staat
-% een breedte \hsize krijgen. Dit is soms te voorkomen met het
-% commando \leavevmode. Binnen een \vbox geeft dit echter
-% niet altijd het gewenste resultaat, vandaar het commando
-%
-% \leaveoutervmode
-
-% Pas op: niet zomaar \topskip en \baselineskip aanpassen
-% en zeker niet \widowpenalty. Dit kan ernstige gevolgen
-% hebben voor kolommen.
-%
-% Enige glue kan op zich geen kwaad, echter als blanko=vast,
-% dan moet ook de rek 0 zijn. Binnen kolommen is rek ook
-% niet bepaald mooi. Een hele kleine waarde (0.025) voldoet,
-% omdat een positieve glue eindeloos rekbaar is.
-
-\newdimen\strutdimen
-\newdimen\lineheight
-\newdimen\openlineheight
-\newdimen\openstrutheight
-\newdimen\openstrutdepth
-\newdimen\topskipgap
-\newdimen\struttotal
-
-\def\strutheightfactor {.72}
-\def\strutdepthfactor {.28}
-
-\def\baselinefactor {2.8}
-\def\baselinegluefactor {0}
-
-\def\minimumstrutheight {0pt}
-\def\minimumstrutdepth {0pt}
-
-\def\normallineheight {\baselinefactor ex}
-\def\minimumlinedistance {\lineskip}
-
-\def\strutheight {0pt}
-\def\strutdepth {0pt}
-\def\strutwidth {0pt}
-
-\def\spacingfactor {1}
-
-\def\topskipfactor {1.0}
-\def\maxdepthfactor {0.5}
-
-\def\systemtopskipfactor {\topskipfactor}
-\def\systemmaxdepthfactor {\maxdepthfactor}
-
-% De onderstaande definitie wordt in de font-module overruled
-
-\ifx\globalbodyfontsize\undefined
- \newdimen\globalbodyfontsize
- \globalbodyfontsize=12pt
-\fi
-
-\ifx\normalizedbodyfontsize\undefined
- \def\normalizedbodyfontsize{12pt}
-\fi
-
-% door een \dimen. Dit is geen probleem omdat (1) de default
-% korpsgrootte 12pt is en (2) de fonts nog niet geladen zijn
-% en de instellingen bij het laden nogmaals plaatsvinden.
-
-% \def\topskipcorrection
-% {\ifdim\topskip>\openstrutheight
-% % == \vskip\topskipgap
-% \vskip\topskip
-% \vskip-\openstrutheight
-% \fi
-% \verticalstrut
-% \vskip-\struttotal}
-
-\def\topskipcorrection
- {\simpletopskipcorrection
- \vskip-\struttotal
- \verticalstrut}
-
-\def\simpletopskipcorrection
- {\ifdim\topskip>\openstrutheight
- % == \vskip\topskipgap
- \vskip\topskip
- \vskip-\openstrutheight
- \fi}
-
-% \def\settopskip % the extra test is needed for the lbr family
-% {\topskip\systemtopskipfactor\globalbodyfontsize
-% \ifgridsnapping \else
-% \ifr@ggedbottom\!!plus5\globalbodyfontsize\fi
-% \fi
-% \relax % the skip
-% \topskipgap\topskip
-% \advance\topskipgap -\openstrutheight\relax
-% \ifdim\topskip<\strutheightfactor\openlineheight
-% \topskip\strutheightfactor\openlineheight\relax
-% \fi}
-
-\def\settopskip % the extra test is needed for the lbr family
- {\topskip\systemtopskipfactor\globalbodyfontsize
- \ifgridsnapping \else
- \ifr@ggedbottom\!!plus5\globalbodyfontsize\fi
- \fi
- \relax % the skip
- \topskipgap\topskip
- \advance\topskipgap -\openstrutheight\relax
-\ifdim\minimumstrutheight>\zeropoint
- \ifdim\topskip<\minimumstrutheight
- \topskip\minimumstrutheight\relax
- \fi
-\else
- \ifdim\topskip<\strutheightfactor\openlineheight
- \topskip\strutheightfactor\openlineheight\relax
- \fi
-\fi}
-
-\def\setmaxdepth
- {\maxdepth\systemmaxdepthfactor\globalbodyfontsize}
-
-\def\normalbaselines
- {\baselineskip \normalbaselineskip
- \lineskip \normallineskip
- \lineskiplimit\normallineskiplimit}
-
-% \def\setnormalbaselines
-% {\ifdim\normallineheight>\zeropoint
-% \lineheight\normallineheight
-% \fi
-% \openlineheight\spacingfactor\lineheight
-% \openstrutheight\strutheightfactor\openlineheight
-% \openstrutdepth \strutdepthfactor \openlineheight
-% \normalbaselineskip\openlineheight
-% \!!plus\baselinegluefactor\openlineheight
-% \!!minus\baselinegluefactor\openlineheight
-% \normallineskip\minimumlinedistance\relax % \onepoint\relax
-% \normallineskiplimit\zeropoint\relax
-% \normalbaselines}
-
-\def\setnormalbaselines
- {\ifdim\normallineheight>\zeropoint
- \lineheight\normallineheight
- \fi
- \openlineheight\spacingfactor\lineheight
- \openstrutheight \ifdim\minimumstrutheight>\zeropoint
- \minimumstrutheight % new
- \else
- \strutheightfactor\openlineheight
- \fi
- \openstrutdepth \ifdim\minimumstrutdepth>\zeropoint
- \minimumstrutdepth % new
- \else
- \strutdepthfactor \openlineheight
- \fi
- \ifdim\dimexpr\minimumstrutdepth+\minimumstrutheight\relax>\zeropoint
- \openlineheight\dimexpr\openstrutheight+\openstrutdepth\relax % new
- \fi
- \normalbaselineskip\openlineheight
- \ifgridsnapping\else
- \!!plus \baselinegluefactor\openlineheight
- \!!minus\baselinegluefactor\openlineheight
- \fi
- \normallineskip\minimumlinedistance\relax % \onepoint\relax
- \normallineskiplimit\zeropoint\relax
- \normalbaselines
- \mksetupgridsnapping}
-
-% \def\setspacingfactor#1\to#2\by#3\\%
-% {\strutdimen#2\points
-% \strutdimen#3\strutdimen
-% \edef#1{\withoutpt\the\strutdimen}}
-%
-% \def\spacing#1%
-% {\ifgridsnapping
-% %\doifnot{#1}{1}{\showmessage\m!layouts{11}{#1}}%
-% \ifdim#1\points=\onepoint\else\showmessage\m!layouts{11}{#1}\fi
-% \edef\spacingfactor{1}%
-% \else
-% \edef\spacingfactor{#1}%
-% \fi
-% \setspacingfactor\systemtopskipfactor \to\topskipfactor \by#1\\% why no \spacingfactor ?
-% \setspacingfactor\systemmaxdepthfactor\to\maxdepthfactor\by#1\\% why no \spacingfactor ?
-% \setnormalbaselines
-% \setstrut}
-%
-% \def\setspacingfactor#1#2#3%
-% {\edef#1{\withoutpt\the\dimexpr#2\points*#3\relax}}
-
-\def\spacing#1%
- {\ifgridsnapping
- \ifdim#1\points=\onepoint\else\showmessage\m!layouts{11}{#1}\fi
- \edef\spacingfactor{1}%
- \else
- \edef\spacingfactor{#1}%
- \fi
- %\setspacingfactor\systemtopskipfactor \topskipfactor {#1}% why no \spacingfactor ?
- %\setspacingfactor\systemmaxdepthfactor\maxdepthfactor{#1}% why no \spacingfactor ?
- \edef\systemtopskipfactor {\withoutpt\the\dimexpr#1\dimexpr\topskipfactor \points}%
- \edef\systemmaxdepthfactor{\withoutpt\the\dimexpr#1\dimexpr\maxdepthfactor\points}%
- \setnormalbaselines
- \setstrut}
-
-%D Sometimes one needs to freeze the interlinespacing
-%D
-%D \starttyping
-%D \rm \saveinterlinespace .... {\ss \restoreinterlinespace .... \endgraf}
-%D \stoptyping
-
-\let\restoreinterlinespace\relax
-
-\def\saveinterlinespace
- {\edef\restoreinterlinespace
- {\lineheight \the\lineheight
- \openstrutheight \the\openstrutheight
- \openstrutdepth \the\openstrutdepth
- \openlineheight \the\openlineheight
- \normalbaselineskip \the\normalbaselineskip
- \normallineskip \the\normallineskip
- \normallineskiplimit\the\normallineskiplimit
- \noexpand\def\noexpand\normallineheight{\the\dimexpr\normallineheight}%
- \noexpand\normalbaselines}}
-
-% plain definition:
-%
-% \def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
-%
-% could be:
-%
-% \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
-
-\ifx\strutbox\undefined
-
- \newbox\strutbox
-
- \setbox\strutbox=\normalhbox{\vrule height8.5pt depth3.5pt width\z@}
-
- %\def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
- \def\strut{\relax\ifmmode\copy\else\unhcopy\fi\strutbox}
-
-\fi
-
-\let\normalstrut=\strut
-
-% The double \hbox construction enables us to \backtrack
-% boxes.
-
-% \def\setstrutdimen#1#2#3% % een strut is n.m maal ex
-% {\strutdimen\normallineheight % wat niet per se \lineheight
-% \strutdimen#2\strutdimen % is omdat een strut lokaal
-% \strutdimen#3\strutdimen % kan afwijken van de globale
-% \edef#1{\the\strutdimen}} % macro % strut
-
-% \def\setstrutdimen#1#2#3% % een strut is n.m maal ex
-% {\strutdimen\normallineheight % wat niet per se \lineheight
-% \strutdimen#2\strutdimen % is omdat een strut lokaal
-% \strutdimen#3\strutdimen % kan afwijken van de globale
-% \edef#1{\the\strutdimen}} % macro % strut
-
-% \def\setstrut
-% {\setstrutdimen\strutheight\strutheightfactor\spacingfactor
-% \setstrutdimen\strutdepth \strutdepthfactor \spacingfactor
-% \let\strut=\normalstrut
-% \setbox\strutbox=\normalhbox
-% {\normalhbox
-% {\vrule
-% \!!width \strutwidth
-% \!!height \strutheight
-% \!!depth \strutdepth
-% \normalkern-\strutwidth}}}
-
-% \def\setstrut
-% {\setstrutdimen\strutheight\strutheightfactor\spacingfactor
-% \setstrutdimen\strutdepth \strutdepthfactor \spacingfactor
-% \dosetstrut}
-
-% \def\setstrut
-% {\strutdimen\normallineheight
-% \strutdimen\strutheightfactor\strutdimen
-% \strutdimen\spacingfactor\strutdimen
-% \edef\strutheight{\the\strutdimen}%
-% \strutdimen\normallineheight
-% \ifgridsnapping
-% \advance\strutdimen-\strutheight
-% \else
-% \strutdimen\strutdepthfactor\strutdimen
-% \strutdimen\spacingfactor\strutdimen
-% \fi
-% \edef\strutdepth{\the\strutdimen}%
-% \dosetstrut}
-
-% interesting, strutdepth is 4.05064pt vs 4.05066pt depending on grid
-% nasty rounding problem
-
-% \def\setstrut
-% {% height
-% \strutdimen\normallineheight
-% \ifdim\minimumstrutheight>\zeropoint
-% \strutdimen\minimumstrutheight
-% \else
-% \strutdimen\strutheightfactor\strutdimen
-% \fi
-% \strutdimen\spacingfactor\strutdimen
-% \edef\strutheight{\the\strutdimen}%
-% % depth
-% \strutdimen\normallineheight
-% \ifgridsnapping
-% \ifdim\minimumstrutdepth>\zeropoint
-% \strutdimen\minimumstrutdepth
-% \else
-% \advance\strutdimen-\strutheight
-% \fi
-% \else
-% \ifdim\minimumstrutdepth>\zeropoint
-% \strutdimen\minimumstrutdepth
-% \else
-% \strutdimen\strutdepthfactor\strutdimen
-% \fi
-% \strutdimen\spacingfactor\strutdimen
-% \fi
-% \edef\strutdepth{\the\strutdimen}%
-% % finish
-% \dosetstrut}
-
-% \def\setstrut
-% {% height
-% \ifdim\minimumstrutheight>\zeropoint
-% \edef\strutheight{\the\dimexpr\spacingfactor\dimexpr\minimumstrutheight}%
-% \else
-% \edef\strutheight{\the\dimexpr\spacingfactor\dimexpr\strutheightfactor\dimexpr\normallineheight}%
-% \fi
-% % depth
-% \ifgridsnapping
-% \ifdim\minimumstrutdepth>\zeropoint
-% \edef\strutdepth{\the\dimexpr\minimumstrutdepth}%
-% \else
-% \edef\strutdepth{\the\dimexpr\normallineheight-\strutheight}%
-% \fi
-% \else
-% \ifdim\minimumstrutdepth>\zeropoint
-% \edef\strutdepth{\the\dimexpr\spacingfactor\dimexpr\minimumstrutdepth}%
-% \else
-% \edef\strutdepth{\the\dimexpr\spacingfactor\dimexpr\strutdepthfactor\dimexpr\normallineheight}%
-% \fi
-% \fi
-% % finish
-% \dosetstrut}
-
-\unexpanded\def\setstrut
- {% height
- \edef\strutheight
- {\the\dimexpr\spacingfactor\dimexpr
- \ifdim\minimumstrutheight>\zeropoint
- \minimumstrutheight
- \else
- \strutheightfactor\dimexpr\normallineheight
- \fi}%
- % depth
- \edef\strutdepth%
- {\the\dimexpr
- \ifgridsnapping
- \ifdim\minimumstrutdepth>\zeropoint
- \minimumstrutdepth
- \else
- \normallineheight-\strutheight
- \fi
- \else
- \spacingfactor\dimexpr
- \ifdim\minimumstrutdepth>\zeropoint
- \minimumstrutdepth
- \else
- \strutdepthfactor\dimexpr\normallineheight
- \fi
- \fi}%
- % finish
- \dosetstrut}
-
-\unexpanded\def\setcharstrut#1%
- {\setbox\strutbox\normalhbox{#1}%
- \edef\strutheight{\the\strutht}%
- \edef\strutdepth {\the\strutdp}%
- \dosetstrut}
-
-% \def\setfontstrut
-% {\setcharstrut{(}}
-%
-% better, since some fonts have small (but descending Q etc)
-
-\unexpanded\def\setfontstrut
- {\setcharstrut{(gplQT}}
-
-\unexpanded\def\setcapstrut% could be M, but Q has descender
- {\setcharstrut{Q}}
-
-%D Handy for math (used in mathml):
-
-\def\charhtstrut
- {\begingroup
- \setcharstrut{GJY}%
- \vrule\!!width\zeropoint\!!depth\zeropoint\!!height\strutht
- \endgroup}
-
-\def\chardpstrut
- {\begingroup
- \setcharstrut{gjy}%
- \vrule\!!width\zeropoint\!!depth\strutdp\!!height\zeropoint
- \endgroup}
-
-%D Centered looks nicer:
-
-% \def\dosetstrut
-% {\let\strut\normalstrut
-% \setbox\strutbox\normalhbox
-% {\normalhbox to \zeropoint
-% {% \hss % new, will be option
-% \vrule
-% \!!width \strutwidth
-% \!!height\strutheight
-% \!!depth \strutdepth
-% \hss}}%
-% \struttotal\dimexpr\strutht+\strutdp\relax}
-%
-% because of all the callbacks in mkiv, we avoid unnecessary boxes ...
-% maybe use an attribute so that we can tag boxes that don't need a
-% treatment; tests with using an attribute so far have shown that
-% it's slower because testing the attribute takes time too
-
-\def\dosetstrut
- {\let\strut\normalstrut
- \ifdim\strutwidth=\zeropoint
- \setbox\strutbox\normalhbox
- {\vrule
- \!!width \zeropoint
- \!!height\strutheight
- \!!depth \strutdepth}%
- \else
- \setbox\strutbox\normalhbox
- {\normalhbox to \zeropoint
- {% \hss % new, will be option
- \vrule
- \!!width \strutwidth
- \!!height\strutheight
- \!!depth \strutdepth
- \hss}}%
- \fi
- \struttotal\dimexpr\strutht+\strutdp\relax}
-
-%D The dimen \type {\struttotal} holds the exact size of the
-%D strut; occasionally a one scaled point difference can show
-%D up with the lineheight.
-
-%D Sometimes a capstrut comes in handy
-%D
-%D \starttabulate[|Tl|l|l|]
-%D \NC yes \NC normal strut \NC {\showstruts\setupstrut[yes]\strut} \NC \NR
-%D \NC no \NC no strut \NC {\showstruts\setupstrut[no]\strut} \NC \NR
-%D \NC kap \NC a capital strut (i.e. Q) \NC {\showstruts\setupstrut[cap]\strut} \NC \NR
-%D \NC A B \unknown \NC a character strut (e.g. A) \NC {\showstruts\setupstrut[A]\strut} \NC \NR
-%D \NC \NC a normal strut \NC {\showstruts\setupstrut\strut} \NC \NR
-%D \stoptabulate
-
-\def\setupstrut
- {\dosingleempty\dosetupstrut}
-
-\def\dosetupstrut[#1]% yet undocumented, todo: fontstrut
- {\processaction
- [#1]
- [ \v!yes=>\setstrut,
- \v!auto=>\setautostrut,
- \v!no=>\setnostrut,
- \v!cap=>\setcapstrut,
- \v!fit=>\setfontstrut,
- \v!line=>\setstrut,
- \s!default=>\setstrut,
- \s!unknown=>\setcharstrut\commalistelement]}
-
-\def\setteststrut
- {\def\strutwidth{.8pt}%
- \setstrut}
-
-\def\autostrutfactor{1.1}
-
-\def\setautostrut
- {\begingroup
- \setbox\scratchbox\copy\strutbox
- \setstrut
- \ifdim\ht\strutbox>\autostrutfactor\ht\scratchbox
- \endgroup \setstrut
- \else\ifdim\dp\strutbox>\autostrutfactor\dp\scratchbox
- \endgroup \setstrut
- \else
- \endgroup
- \fi\fi}
-
-% simple version
-%
-% \def\begstrut
-% {\relax\ifcase\strutht\else
-% \strut
-% \normalpenalty\plustenthousand
-% \normalhskip\zeropoint
-% \ignorespaces
-% \fi}
-%
-% \def\endstrut
-% {\relax\ifhmode\ifcase\strutht\else
-% \removeunwantedspaces
-% \normalpenalty\plustenthousand
-% \normalhskip\zeropoint
-% \strut
-% \fi\fi}
-
-% when enabled, sigstruts will remove themselves if nothing
-% goes inbetween
-
-\newsignal\strutsignal \setfalse\sigstruts
-
-\def\begstrut
- {\relax\ifcase\strutht\else
- \ifconditional\sigstruts
- \noindent\horizontalstrut
- \normalpenalty\plustenthousand
- \normalhskip-\strutsignal
- \normalhskip\strutsignal
- \else
- \strut
- \normalpenalty\plustenthousand
- \normalhskip\zeropoint
- \fi
- \expandafter \ignorespaces
- \fi}
-
-\def\endstrut
- {\relax\ifhmode\ifcase\strutht\else
- \ifconditional\sigstruts
- \ifdim\lastskip=\strutsignal
- \unskip\unskip\unpenalty\setbox\scratchbox\lastbox
- \else
- \normalpenalty\plustenthousand
- \normalhskip\zeropoint
- \strut
- \fi
- \else
- \removeunwantedspaces
- \normalpenalty\plustenthousand
- \normalhskip\zeropoint
- \strut
- \fi
- \fi\fi}
-
-\newbox\nostrutbox \setbox\nostrutbox\normalhbox{} % {\normalhbox{}}
-
-\def\setnostrut
- {\setbox\strutbox\copy\nostrutbox
- \let\strut\empty
- \let\endstrut\empty
- \let\begstrut\empty
- \let\crlfplaceholder\empty}
-
-% unsave:
-%
-% \def\pseudostrut
-% {\bgroup
-% \setnostrut
-% \normalstrut
-% \egroup}
-%
-% try:
-%
-% \startchemie
-% \chemie[ONE,Z0,SB15,MOV1,SB15,Z0][C,C]
-% \stopchemie
-%
-% so:
-
-\def\pseudostrut
- {\noindent} % better: \dontleavehmode
-
-\let\pseudobegstrut\pseudostrut
-
-\let\pseudoendstrut\removeunwantedspaces
-
-\def\resetteststrut
- {\let\strutwidth\zeropoint
- \setstrut}
-
-\ifx\setfontparameters\undefined
- % problems ! ! ! !
- \def\setfontparameters{\the\everybodyfont}
-\fi
-
-%D Handy:
-
-\def\baselinedistance{\the\lineheight}
-
-%D We need \type{\normaloffinterlineskip} because the new
-%D definition contains an assignment, and |<|don't ask me
-%D why|>| this assignment gives troubles in for instance the
-%D visual debugger.
-
-%D The plain ones:
-
-\def\offinterlineskip
- {\baselineskip-\thousandpoint
- \lineskip\zeropoint
- \lineskiplimit\maxdimen}
-
-\def\nointerlineskip
- {\prevdepth-\thousandpoint}
-
-\let\normaloffinterlineskip=\offinterlineskip % knuth's original
-
-%D My own one:
-
-\def\offinterlineskip
- {\ifdim\baselineskip>\zeropoint
- \edef\oninterlineskip
- {\baselineskip\the\baselineskip
- \lineskip\the\lineskip
- \lineskiplimit\the\lineskiplimit
- \let\noexpand\offinterlineskip\noexpand\normaloffinterlineskip}%
- \else
- \let\oninterlineskip\setnormalbaselines
- \fi
- \normaloffinterlineskip}
-
-\let\oninterlineskip=\relax
-
-\def\leaveoutervmode
- {\ifvmode\ifinner\else
- \leavevmode
- \fi\fi}
-
-% We stellen enkele penalties anders in dan Plain TEX:
-
-% oud
-%
-% \widowpenalty=\defaultwidowpenalty\relax
-% \clubpenalty =\defaultclubpenalty \relax
-
-\def\resetpenalties#1%
- {\ifx#1\undefined\else
- #1\minusone
- \fi}
-
-\def\setpenalties#1#2#3%
- {\ifx#1\undefined\else % space before #3 prevents lookahead problems, needed when #3=text
- #1\numexpr#2+\plusone\relax\space\doexpandedrecurse{\the\numexpr#2\relax}{ #3}\zerocount\relax
- \fi}
-
-\def\doexpandedrecurse#1#2%
- {\ifnum#1>\zerocount#2\@EA\doexpandedrecurse\@EA{\the\numexpr#1-1\relax}{#2}\fi}
-
-%D \macros
-%D {keeplinestogether}
-%D
-%D Dirty hack, needed in margin content that can run of a page.
-
-\def\keeplinestogether#1%
- {\xdef\restoreinterlinepenalty{\global\resetpenalties\interlinepenalties}%
- \global\setpenalties\interlinepenalties{#1}\plustenthousand}
-
-\newif\ifgridsnapping % to be sure
-
-\def\defaultwidowpenalty {2000} % was: 1000
-\def\defaultclubpenalty {2000} % was: 800
-\def\defaultdisplaywidowpenalty {50}
-\def\defaultbrokenpenalty {100}
-
-\def\defaultgridwidowpenalty {0}
-\def\defaultgridclubpenalty {0}
-\def\defaultgriddisplaywidowpenalty {0}
-\def\defaultgridbrokenpenalty {0}
-
-% The original approach:
-%
-% \def\setdefaultpenalties
-% {\ifgridsnapping
-% \widowpenalty\defaultgridwidowpenalty
-% \clubpenalty \defaultgridclubpenalty
-% \else
-% \widowpenalty\defaultwidowpenalty
-% \clubpenalty \defaultclubpenalty
-% \fi}
-%
-% However, we will use setups:
-
-% to be documented
-
-\def\nopenalties
- {\widowpenalty \zerocount
- \clubpenalty \zerocount
- \brokenpenalty \zerocount
- \doublehyphendemerits\zerocount
- \finalhyphendemerits \zerocount
- \adjdemerits \zerocount}
-
-\def\setdefaultpenalties
- {\directsetup{\systemsetupsprefix\s!default}}
-
-\startsetups [\systemsetupsprefix\s!reset]
- \resetpenalties\widowpenalties
- \resetpenalties\clubpenalties
- \resetpenalties\interlinepenalties
-\stopsetups
-
-% we use \directsetup because it's faster and we know there is no csl
-
-\startsetups [\systemsetupsprefix\s!default]
-
- \directsetup{\systemsetupsprefix\s!reset}
-
- \widowpenalty \defaultwidowpenalty
- \clubpenalty \defaultclubpenalty
- \displaywidowpenalty\defaultdisplaywidowpenalty
- \brokenpenalty \defaultbrokenpenalty
-
-\stopsetups
-
-\startsetups [\v!grid] [\systemsetupsprefix\s!default]
-
- \directsetup{\systemsetupsprefix\s!reset}
-
- \widowpenalty \defaultgridwidowpenalty
- \clubpenalty \defaultgridclubpenalty
- \displaywidowpenalty\defaultgriddisplaywidowpenalty
- \brokenpenalty \defaultgridbrokenpenalty
-
-\stopsetups
-
-% as an illustration:
-
-\startsetups [\systemsetupsprefix\v!strict]
-
- \directsetup{\systemsetupsprefix\s!reset}
-
- \setpenalties\widowpenalties2\maxdimen
- \setpenalties\clubpenalties 2\maxdimen
- \brokenpenalty \maxdimen
-
-\stopsetups
-
-\setdefaultpenalties % will happen later in \setuplayout
-
-% Suggested by GB (not the name -):
-
-\def\rapfillskip{.5\hsize plus .092\hsize minus .5\hsize} % D.A.'s value
-
-% Bovendien definieren we enkele extra \fill's:
-
-\def\hfilll{\hskip\zeropoint\!!plus1filll\relax}
-\def\vfilll{\vskip\zeropoint\!!plus1filll\relax}
-
-% De onderstaande hulpmacro's moeten nog eens instelbaar worden
-% gemaakt.
-
-\def\tfskipsize{1em\relax}
-\def\tfkernsize{1ex\relax}
-
-\def\tfskip{\dotfskip\tfskipsize}
-\def\tfkern{\dotfkern\tfkernsize}
-
-\def\dotfskip#1{{\tf\hskip#1}}
-\def\dotfkern#1{{\tf\kern #1}}
-
-% needs a proper \definenarrower or installnarrower
-
-\newskip\ctxleftskip
-\newskip\ctxrightskip
-\newskip\ctxmidskip
-
-\def\dosinglenarrower#1%
- {\processaction
- [#1]
- [ \v!left=>\global\advance\ctxleftskip \@@slleft,
- \v!middle=>\global\advance\ctxmidskip \@@slmiddle,
- \v!right=>\global\advance\ctxrightskip \@@slright,
- \v!reset=>\global\ctxleftskip \zeropoint
- \global\ctxmidskip \zeropoint
- \global\ctxrightskip\zeropoint,
- \v!none=>,
- \s!unknown=>\global\advance\ctxmidskip \commalistelement]}
-
-% \def\donarrower[#1]% hm, can be dorepeat directly
-% {\processaction
-% [#1]
-% [ \v!left=>\global\advance\ctxleftskip \@@slleft,
-% \v!middle=>\global\advance\ctxmidskip \@@slmiddle,
-% \v!right=>\global\advance\ctxrightskip \@@slright,
-% \v!none=>,% handy for delimitedtexts
-% \s!unknown=>{\dorepeatwithcommand[#1]\dosinglenarrower}]}
-
-\def\donarrower[#1]% hm, can be dorepeat directly
- {\dorepeatwithcommand[#1]\dosinglenarrower}
-
-\def\complexstartnarrower[#1]%
- {\@@slbefore % was hard coded \par
- \bgroup
- \global\ctxleftskip \zeropoint
- \global\ctxrightskip\zeropoint
- \global\ctxmidskip \zeropoint
- \processcommalistwithparameters[#1]\donarrower
- \advance\leftskip \ctxleftskip
- \advance\rightskip \ctxrightskip
- \advance\leftskip \ctxmidskip
- \advance\rightskip \ctxmidskip
- \seteffectivehsize}
-
-% todo: definenarrower
-
-\def\simplestartnarrower
- {\startnarrower[\v!middle]}
-
-\definecomplexorsimple\startnarrower
-
-\def\stopnarrower
- {\@@slafter % was hard coded \par / needed, else skips forgotten
- \egroup}
-
-\def\setupnarrower
- {\dodoubleargument\getparameters[\??sl]}
-
-\newdimen\@@effectivehsize \def\effectivehsize {\hsize}
-\newdimen\@@effectiveleftskip \def\effectiveleftskip {\leftskip}
-\newdimen\@@effectiverightskip \def\effectiverightskip{\rightskip}
-
-\def\seteffectivehsize
- {\setlocalhsize
- \@@effectivehsize \localhsize
- \@@effectiveleftskip \leftskip
- \@@effectiverightskip \rightskip
- \let\effectivehsize \@@effectivehsize
- \let\effectiveleftskip \@@effectiveleftskip
- \let\effectiverightskip\@@effectiverightskip}
-
-\def\dodefinehbox[#1][#2]%
- {\setvalue{hbox#1}##1%
- {\hbox to #2{\begstrut##1\endstrut\hss}}}
-
-\def\definehbox
- {\dodoubleargument\dodefinehbox}
-
-\def\iobox#1#2#3#% here #3# is not really needed
- {\vbox\bgroup % we want to return a vbox like the others
- \hbox\bgroup% we need to pack the signal with the box
- \signalrightpage
- \dowithnextboxcontent
- {\let\\=\endgraf\forgetall\doifrightpageelse#1#2}
- {\box\nextbox\egroup\egroup}
- \vbox#3}
-
-\def\obox{\iobox\raggedleft \raggedright} % outerbox
-\def\ibox{\iobox\raggedright\raggedleft} % innerbox
-
-\def\dosetraggedvbox#1%
- {\let\raggedbox\vbox
- \processfirstactioninset
- [#1]
- [ \v!left=>\let\raggedbox\lbox,
- \v!right=>\let\raggedbox\rbox,
- \v!middle=>\let\raggedbox\cbox,
- \v!inner=>\let\raggedbox\ibox,
- \v!outer=>\let\raggedbox\obox,
- \v!flushleft=>\let\raggedbox\rbox,
- \v!flushright=>\let\raggedbox\lbox,
- \v!center=>\let\raggedbox\cbox,
- \v!no=>\def\raggedbox{\vbox\bgroup\raggedright\let\next=}]}
-
-\def\dosetraggedhbox#1%
- {\let\raggedbox\hbox
- \processaction % slow
- [#1]
- [ \v!left=>\def\raggedbox{\doalignedline\v!left },
- \v!right=>\def\raggedbox{\doalignedline\v!right },
- \v!middle=>\def\raggedbox{\doalignedline\v!middle},
- \v!inner=>\def\raggedbox{\doalignedline\v!inner },
- \v!outer=>\def\raggedbox{\doalignedline\v!outer },
- \v!flushleft=>\def\raggedbox{\doalignedline\v!right },
- \v!flushright=>\def\raggedbox{\doalignedline\v!left },
- \v!center=>\def\raggedbox{\doalignedline\v!middle}]}
-
-\def\dosetraggedcommand#1%
- {\expanded{\dodosetraggedcommand{#1}}}
-
-% \def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that!
-% {\let\raggedcommand \relax
-% \let\raggedtopcommand \empty
-% \let\raggedbottomcommand\empty
-% \chardef\raggedoneliner\zerocount
-% \doifsomething{#1}
-% {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse
-% \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse
-% \!!donectrue
-% \rawprocesscommalist[#1]\dododosetraggedcommand}}
-
-\newtoks\everyraggedcommand
-
-\def\raggedcommand{\the\everyraggedcommand}
-
-\def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that!
- {\everyraggedcommand \emptytoks
- \let\raggedtopcommand \empty
- \let\raggedbottomcommand\empty
- \chardef\raggedoneliner\zerocount
- \doifsomething{#1}
- {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse
- \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse
- \!!donectrue
- \rawprocesscommalist[#1]\dododosetraggedcommand}}
-
-\def\dododosetraggedcommand#1%
- {\executeifdefined{\@@ragged@@command\string#1}\relax}
-
-\def\@@ragged@@command{@@raggedcommand}
-
-\setvalue{\@@ragged@@command\v!hanging }{\appendtoks\enableprotruding \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!nothanging }{\appendtoks\disableprotruding \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!hz }{\appendtoks\enableadjusting \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!nohz }{\appendtoks\disableadjusting \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!spacing }{\appendtoks\enablespacehandling
- \enablekernhandling \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!nospacing }{\appendtoks\disablespacehandling
- \disablekernhandling \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!hyphenated }{\appendtoks\dohyphens \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!nothyphenated}{\appendtoks\nohyphens \to\everyraggedcommand}
-
-\setvalue{\@@ragged@@command\v!tolerant }{\appendtoks\tolerance3000\relax \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!verytolerant}{\appendtoks\tolerance4500\relax \to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!stretch }{\appendtoks\emergencystretch\bodyfontsize\to\everyraggedcommand}
-
-\setvalue{\@@ragged@@command\v!left}%
- {\if!!donea \appendtoks\veryraggedleft\to\everyraggedcommand
- \else \appendtoks\raggedleft \to\everyraggedcommand
- \fi
- \!!donecfalse}
-
-\setvalue{\@@ragged@@command\v!right}%
- {\if!!donea \appendtoks\veryraggedright\to\everyraggedcommand
- \else \appendtoks\raggedright \to\everyraggedcommand
- \fi
- \!!donecfalse}
-
-\setvalue{\@@ragged@@command\v!middle}%
- {\if!!donec
- \if!!doneb \appendtoks\raggedwidecenter\to\everyraggedcommand
- \else\if!!donea \appendtoks\veryraggedcenter\to\everyraggedcommand
- \else \appendtoks\raggedcenter \to\everyraggedcommand
- \fi\fi
- \!!donecfalse
- \else
- \let\raggedbottomcommand\vfilll % bonus, pretty strong
- \let\raggedtopcommand \vfilll % used with \framed for
- \fi} % instance in tables
-
-\setvalue{\@@ragged@@command\v!flushleft }{\getvalue{\@@ragged@@command\v!right }}
-\setvalue{\@@ragged@@command\v!flushright}{\getvalue{\@@ragged@@command\v!left }}
-\setvalue{\@@ragged@@command\v!center }{\getvalue{\@@ragged@@command\v!middle}}
-
-\setvalue{\@@ragged@@command\v!high}%
- {\let\raggedbottomcommand\vfilll} % and since we lack a
-
-\setvalue{\@@ragged@@command\v!low}%
- {\let\raggedtopcommand\vfilll} % proper keyword, but
-
-\setvalue{\@@ragged@@command\v!lohi}%
- {\let\raggedbottomcommand\vfilll % we do support the
- \let\raggedtopcommand\vfilll} % ugly laho (lohi)
-
-\setvalue{\@@ragged@@command\v!no}%
- {\appendtoks\raggedright\to\everyraggedcommand}
-
-\setvalue{\@@ragged@@command\v!yes}%
- {\appendtoks\notragged\to\everyraggedcommand}
-
-\setvalue{\@@ragged@@command\v!normal}%
- {\appendtoks\notragged\to\everyraggedcommand}
-
-\setvalue{\@@ragged@@command\v!inner}% not yet perfect
- {\signalrightpage % may interfere
- \doifrightpageelse
- {\getvalue{\@@ragged@@command\v!right}}
- {\getvalue{\@@ragged@@command\v!left}}}
-
-\setvalue{\@@ragged@@command\v!outer}% not yet perfect
- {\signalrightpage % may interfere
- \doifrightpageelse
- {\getvalue{\@@ragged@@command\v!left}}
- {\getvalue{\@@ragged@@command\v!right}}}
-
-\setvalue{\@@ragged@@command\v!lesshyphenation}%
- {\appendtoks\lesshyphens\to\everyraggedcommand}
-\setvalue{\@@ragged@@command\v!morehyphenation}%
- {\appendtoks\morehyphens\to\everyraggedcommand}
-
-% compare:
-%
-% \framed[width=4cm,align=no] {\hfil xxx}
-% \framed[width=4cm,align=disable]{\hfil xxx}
-
-\setvalue{\@@ragged@@command\v!disable}% for one liners
- {\appendtoks\raggedright\parfillskip\zeropoint\to\everyraggedcommand}
-
-\chardef\raggedoneliner\zerocount
-
-\setvalue{\@@ragged@@command\v!line}%
- {\chardef\raggedoneliner\plusone}
-
-%D Unofficial, may disappear. Now handled directly in the
-%D core-rul module.
-
-% \def\@@startraggedoneliner
-% {\ifcase\raggedoneliner\else
-% \dontleavehmode\hbox to \hsize \bgroup % hsize added, else useless
-% \ifcase\raggedstatus\or\hss\or\hss\fi
-% \ignorespaces
-% \bgroup
-% \aftergroup\removeunwantedspaces
-% \fi}
-
-% \def\@@stopraggedoneliner
-% {\ifcase\raggedoneliner\else
-% \egroup
-% \ifcase\raggedstatus\or\or\hss\or\hss\fi
-% \egroup
-% \ignorespaces % ? ? ?
-% \fi}
-
-% \def\@@handleoneliner
-% {\ifcase\raggedoneliner\else
-% \@@startraggedoneliner
-% \aftergroup\@@stopraggedoneliner
-% \fi}
-
-% Nodig i.v.m. inspringen eerste alineas
-
-\def\explicithmode{\unhbox\voidb@x} % can probably become \dontleavehmode
-
-% Nog doen:
-%
-% \goodbreak -> \allowbreak en \dosomebreak{..} in koppen
-%
-% bij koppen zowieso: \blanko[reset]
-
-% Nog in commando verwerken:
-%
-% \voorkeur la \blanko
-%
-% Om ongewenste witruimte te voorkomen kan met \dosomebreak{\break}
-% een \penalty voor witruimte worden geplaatst.
-
-\def\removelastskip % a redefinition of plain
- {\ifvmode\ifdim\lastskip=\zeropoint\else\vskip-\lastskip\fi\fi}
-
-% first version:
-%
-% \def\dosomebreak#1%
-% {\scratchskip\lastskip
-% \removelastskip
-% %\type{#1}%
-% #1\relax
-% \ifdim\scratchskip=\zeropoint \else
-% \vskip\scratchskip
-% \fi}
-%
-% don't change the next improvement:
-
-% \def\dosomebreak#1%
-% {\endgraf % beware, this forces a newline
-% \ifvmode
-% \ifdim\lastskip=\zeropoint
-% #1\relax
-% \else
-% \scratchskip\lastskip
-% \removelastskip
-% #1\relax
-% \vskip\scratchskip
-% \fi
-% \fi}
-
-% beter, vooral in \vbox; nog in \pagina toepassen s!
-
-\def\doifoutervmode#1%
- {\ifvmode\ifinner\else#1\fi\fi}
-
-\ifx\dosomebreak\undefined % defined in mkiv
-
- \def\dosomebreak#1%
- {\doifoutervmode
- {\scratchskip\lastskip
- \removelastskip
- %\leavevmode\type{#1}%
- #1\relax
- \ifdim\scratchskip=\zeropoint % else interference with footnotes
- \else
- \vskip\scratchskip
- \fi}}
-
-\fi
-
-\def\forgeteverypar
- {\everypar{\the\neverypar}}
-
-%\def\forgetparindent
-% {\forgeteverypar
-% \indentfirstparagraphtrue % recently added
-% \setupindenting[\v!geen]}
-
-%\def\forgetparskip
-% {\setupwhitespace[\v!geen]}
-
-\def\forgetparindent
- {\forgeteverypar
- \indentfirstparagraphtrue % recently added
- \let\currentindentation\v!none
- \ctxparindent\zeropoint
- \parindent\zeropoint\relax}
-
-\def\forgetparskip
- {\let\currentwhitespace\v!none
- \ctxparskip\zeropoint
- \parskip\zeropoint\relax}
-
-\def\forgetbothskips
- {\tolerance1500
- \leftskip\zeropoint
- \rightskip\zeropoint\relax}
-
-\def\forgetspacing
- {\emergencystretch\zeropoint}
-
-\newif\ifforgotten % rather good signal for inner
-
-\appendtoks \forgottentrue \to \everyforgetall
-\appendtoks \forgetragged \to \everyforgetall
-\appendtoks \forgetparskip \to \everyforgetall
-\appendtoks \forgetparindent \to \everyforgetall
-\appendtoks \forgetbothskips \to \everyforgetall
-\appendtoks \forgetspacing \to \everyforgetall % i.v.m. funny spacing in pagebody
-\appendtoks \spacing\!!plusone \to \everyforgetall % new per 10/08/2004, else problems in otr / !! needed
-\appendtoks \everypar\emptytoks \to \everyforgetall % indeed!
-
-\def\localvbox#1#%
- {\vbox#1\bgroup
- \forgetparskip
- \setlocalhsize
- \hsize\localhsize
- \forgetparindent
- \forgetbothskips
- \forgeteverypar
- \let\next=}
-
-% ach ja, hoort niet hier
-
-% \unexpanded\def\dostartattributes#1#2#3%
-% {\begingroup % geen \bgroup, anders in mathmode lege \hbox
-% \doifdefinedelse{#1#2}
-% {\def\fontattribute{\getvalue{#1#2}}}
-% {\let\fontattribute=\empty}%
-% \doifdefinedelse{#1#3}
-% {\def\colorattribute{\getvalue{#1#3}}}
-% {\let\colorattribute=\empty}%
-% \startcolor[\colorattribute]%
-% \@EA\doconvertfont\@EA{\fontattribute}}
-%
-% \unexpanded\def\dostopattributes%
-% {\stopcolor
-% \endgroup}
-%
-% \unexpanded\def\doattributes#1#2#3#4%
-% {\dostartattributes{#1}{#2}{#3}{#4}\dostopattributes}
-
-%D A hardly faster implementation follows. We cannot use
-%D \type {csname} testing since the first argument can be
-%D anything, even a raw fontswitch. No a real improvement
-%D (some 5 seconds on 260 seconds for the maps bibliography).
-
-\let\dostopattributes\relax % in case these commands end up in an edef
-
-\unexpanded\def\dostartattributes#1#2#3%
- {\begingroup % geen \bgroup, anders in mathmode lege \hbox
- \ifcsname#1#3\endcsname
- \let\dostopattributes\@@dostopattributes
- \startcolor[\csname#1#3\endcsname]%
- \else
- \let\dostopattributes\@@nostopattributes
- \fi
- \ifcsname#1#2\endcsname
- \expandafter\doconvertfont
- \else
- \expandafter\gobbleoneargument
- \fi{\csname#1#2\endcsname}}
-
-\newconditional \parbasedattributes
-
-\def\finishparbasedattributes
- {\ifconditional\parbasedattributes
- \setfalse\parbasedattributes
- \par
- \fi}
-
-\def\dostopparbasedattributes
- {\settrue\parbasedattributes
- \dostopattributes}
-
-\unexpanded\def\@@dostopattributes
- {\stopcolor
- \finishparbasedattributes
- \endgroup}
-
-\unexpanded\def\@@nostopattributes
- {\finishparbasedattributes
- \endgroup}
-
-\unexpanded\def\doattributes#1#2#3#4%
- {\dostartattributes{#1}{#2}{#3}{#4}\dostopattributes}
-
-% An even faster \ETEX\ version:
-
-\unexpanded\def\dostartattributes#1#2#3%
- {\begingroup % geen \bgroup, anders in mathmode lege \hbox
- \ifincolor
- \ifcsname#1#3\endcsname
- \let\dostopattributes\@@dostopattributes
- \faststartcolor[\csname#1#3\endcsname]%
- \else
- \let\dostopattributes\@@nostopattributes
- \fi
- \else
- \let\dostopattributes\@@nostopattributes
- \fi
- \ifcsname#1#2\endcsname
- % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
- \@EA\doconvertfont\csname#1#2\@EA\endcsname
- \fi}
-
-\unexpanded\def\@@dostopattributes
- {\faststopcolor
- \finishparbasedattributes
- \endgroup}
-
-\unexpanded\def\@@nostopattributes
- {\finishparbasedattributes
- \endgroup}
-
-%D Bonus macro, see core-sec.tex
-
-\unexpanded\def\dosetfontattribute#1#2%
- {\ifcsname#1#2\endcsname
- \@EA\doconvertfont\csname#1#2\@EA\endcsname
- \fi\empty}
-
-%D Since this happens a lot, and sometimes large arguments
-%D are passed in \type {#4}, we just copy some code:
-
-\unexpanded\def\doattributes#1#2#3#4%
- {\begingroup % geen \bgroup, anders in mathmode lege \hbox
- \ifincolor
- \ifcsname#1#3\endcsname
- \let\dostopattributes\@@dostopattributes
- \faststartcolor[\csname#1#3\endcsname]%
- \else
- \let\dostopattributes\endgroup
- \fi
- \else
- \let\dostopattributes\endgroup
- \fi
- \ifcsname#1#2\endcsname
- % \@EAEAEA\doconvertfont\@EA\@EA\csname#1#2\endcsname
- \@EA\doconvertfont\csname#1#2\@EA\endcsname
- \fi
- {#4}%
- \dostopattributes}
-
-% Kan vaker worden toegepast en moet bovendien sneller!
-
-\newskip\leftskipadaption
-\newskip\rightskipadaption
-
-\def\doadaptleftskip#1%
- {\dosetleftskipadaption{#1}%
- \advance\leftskip \leftskipadaption}
-
-\def\doadaptrightskip#1%
- {\dosetrightskipadaption{#1}%
- \advance\rightskip \rightskipadaption}
-
-\setvalue{@lsa@\v!standard}{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
-\setvalue{@lsa@\v!yes }{\ifdim\ctxparindent=\zeropoint\@@slleft\else\ctxparindent\fi}
-\letvalue{@lsa@\v!no }\zeropoint
-\letvalue{@lsa@\empty }\zeropoint
-\setvalue{@rsa@\v!standard}{\@@slright}
-\setvalue{@rsa@\v!yes }{\@@slright}
-\letvalue{@rsa@\v!no }\zeropoint
-\letvalue{@rsa@\empty }\zeropoint
-
-% not safe for 2\parindent
-%
-% \def\dosetleftskipadaption#1%
-% {\leftskipadaption
-% \ifcsname @lsa@#1\endcsname
-% \csname @lsa@#1\endcsname
-% \else
-% #1%
-% \fi
-% \relax}
-
-\def\dosetleftskipadaption#1%
- {\edefconvertedargument\ascii{@lsa@#1}%
- \leftskipadaption
- \ifcsname\ascii\endcsname
- \csname\ascii\endcsname
- \else
- #1%
- \fi
- \relax}
-
-\def\dosetrightskipadaption#1%
- {\edefconvertedargument\ascii{@rsa@#1}%
- \rightskipadaption
- \ifcsname\ascii\endcsname
- \csname\ascii\endcsname
- \else
- #1%
- \fi
- \relax}
-
-\newcount \noftrackedpagestates
-\newif \ifpagestatemismatch
-\newcount \realpagestateno
-\chardef \frozenpagestate \zerocount
-
-\def\dotrackpagestate#1#2%
- {\ifdoublesided \ifinpagebody \else
- \doforcedtrackpagestate{#1}{#2}%
- \fi \fi}
-
-\def\doforcedtrackpagestate#1#2%
- {\ifcase\frozenpagestate
- \global\advance\noftrackedpagestates\plusone
- \global\advance#2\plusone
- \lazysavetaggedtwopassdata{#1}{\number\noftrackedpagestates}{\number#2}{\noexpand\realfolio}%
- %\llap{\infofont\number\noftrackedpagestates/\number#2}% tracing
- \fi}
-
-\def\doifrightpagestateelse#1#2%
- {\ifcase\frozenpagestate
- \pagestatemismatchfalse
- \realpagestateno\realfolio
- \ifinpagebody
- \ifdoublesided
- \ifodd\realpageno\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \else
- \twopassdatafoundtrue
- \fi
- \else\ifdoublesided
- \findtwopassdata{#1}{\number#2}%
- \iftwopassdatafound
- \realpagestateno\twopassdata\relax
- \ifnum\twopassdata=\realpageno \else
- \pagestatemismatchtrue
- \fi
- \ifodd\twopassdata\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \else
- \ifodd\realpageno\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \fi
- \else
- \twopassdatafoundtrue
- \fi\fi
- \else
- \ifodd\realpagestateno\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \fi
- \iftwopassdatafound
- \@EA\firstoftwoarguments
- \else
- \@EA\secondoftwoarguments
- \fi}
-
-\def\doifforcedrightpagestateelse#1#2%
- {\ifcase\frozenpagestate
- \pagestatemismatchfalse
- \realpagestateno\realfolio
- \findtwopassdata{#1}{\number#2}%
- \iftwopassdatafound
- \realpagestateno\twopassdata\relax
- \ifnum\twopassdata=\realpageno \else
- \pagestatemismatchtrue
- \fi
- \ifodd\twopassdata\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \else
- \ifodd\realpageno\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \fi
- \else
- \ifodd\realpagestateno\relax
- \twopassdatafoundtrue \else \twopassdatafoundfalse
- \fi
- \fi
- \iftwopassdatafound
- \@EA\firstoftwoarguments
- \else
- \@EA\secondoftwoarguments
- \fi}
-
-\def\freezepagestate {\chardef\frozenpagestate\plusone }
-\def\defrostpagestate{\chardef\frozenpagestate\zerocount}
-
-% we can make more of these on top, but how to deal with mixed frozen states
-
-\definetwopasslist\s!paragraph \newcount \nofraggedparagraphs
-
-\def\signalrightpage {\dotrackpagestate \s!paragraph\nofraggedparagraphs}
-\def\doifrightpageelse{\doifrightpagestateelse\s!paragraph\nofraggedparagraphs}
-
-\newcount\pagesignallevel
-
-\def\startsignalrightpage % one may do a \postsignalrightplace
- {\advance\pagesignallevel\plusone
- \presignalrightpage
- \let\signalrightpage\relax
- \let\presignalrightpage\relax
- \let\startsignalrightpage\relax
- \doifrightpageelse\donothing\donothing
- \freezepagestate}
-
-\def\stopsignalrightpage
- {\ifcase\pagesignallevel\or\postsignalrightpage\fi
- \advance\pagesignallevel\minusone}
-
-\def\setraggedparagraphmode
- {\signalrightpage\doifrightpageelse} % move it there
-
-\ifx\swapmargins\undefined \let\swapmargins\undefined \fi % todo
-
-\def\doifswappedrightpageelse#1#2% alleen in box construction !
- {\doifrightpageelse
- {#1}
- {\scratchcounter\realpageno
- \realpageno\realpagestateno\relax
- \swapmargins
- \realpageno\scratchcounter
- #2}}
-
-\newbox\signaledrightpage % this way we can avoid interference, i.e. postpone placement
-
-\def\presignalrightpage {\global\setbox\signaledrightpage\hbox{\signalrightpage}}
-\def\postsignalrightpage{\ifvoid\signaledrightpage\else\box\signaledrightpage\fi}
-
-% The next feature is is used in:
-%
-% \definenumber[test][way=bypage]
-%
-% \def\Test
-% {\incrementnumber[test]\rawnumber[test]/%
-% \incrementnumber[test]\rawnumber[test]/%
-% \incrementnumber[test]\rawnumber[test]\space
-% \checkpagechange{oeps}\changedpage{oeps}\space
-% \ifpagechanged TRUE\else FALSE\fi}
-%
-% \Test\page \Test\par \Test\page \Test\par \Test\page \Test\page
-%
-% (adapted from cont-new.tex:)
-
-\newif\ifpagechanged \let\lastchangedpage\empty
-
-\def\docheckpagestatechange#1#2#3%
- {\pagechangedfalse
- \doforcedtrackpagestate{#2}{#3}%
- \findtwopassdata{#2}{\number#3}%
- \iftwopassdatafound
- \ifnum\twopassdata>0\getvalue{#2:p:#1}\relax
- \pagechangedtrue
- \fi
- \fi
- \ifpagechanged
- \letgvalue{#2:p:#1}\twopassdata
- \globallet\lastchangedpage\twopassdata
- \else
- \globallet\lastchangedpage\realfolio
- \fi}
-
-\def\changedpagestate#1#2%
- {\executeifdefined{#2:p:#1}{0}}
-
-\def\checkpagechange#1{\docheckpagestatechange{#1}\s!paragraph\nofraggedparagraphs}
-\def\changedpage #1{\changedpagestate{#1}\s!paragraph}
-
-% saved struts
-
-\ifx\savedstrutbox\undefined \newbox\savedstrutbox \fi
-
-\def\savestrut {\setbox\savedstrutbox\copy\strutbox}
-\def\savedstrut{\copy \savedstrutbox}
-
-% De onderstaande macro's zijn opgenomen in Plain TeX.
-%
-% \def\raggedright%
-% {\rightskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}
-%
-% \def\ttraggedright%
-% {\tttf\rightskip\z@ plus2em\relax}
-%
-% \newif\ifr@ggedbottom
-%
-% \def\raggedbottom%
-% {\topskip 10\p@ plus60\p@ \r@ggedbottomtrue}
-%
-% \def\normalbottom%
-% {\topskip 10\p@ \r@ggedbottomfalse}
-%
-% en worden hieronder wat aangepast.
-
-% the three boolean will become obsolete some day in favour
-% of \bottomraggedness
-
-\chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
-
-\def\bottomalignlimit{3\lineheight}
-
-\newif\ifn@rmalbottom
-\newif\ifr@ggedbottom
-\newif\ifb@selinebottom
-
-\def\normalbottom
- {% \topskip 10pt
- \r@ggedbottomfalse}
-
-\def\raggedbottom
- {\chardef\bottomraggedness\zerocount
- \n@rmalbottomfalse
- \r@ggedbottomtrue
- \b@selinebottomfalse
- \settopskip}
-
-\def\alignbottom
- {\chardef\bottomraggedness\plusone
- \n@rmalbottomtrue
- \r@ggedbottomfalse
- \b@selinebottomfalse
- \settopskip}
-
-\def\baselinebottom
- {\chardef\bottomraggedness\plustwo
- \n@rmalbottomfalse
- \r@ggedbottomfalse
- \b@selinebottomtrue
- \settopskip}
-
-\let\normalbottom=\alignbottom % downward compatible
-
-% so, the new one will be
-%
-% \chardef\bottomraggedness=0 % 0=ragged 1=normal/align 2=baseline
-%
-% \def\bottomalignlimit{3\lineheight} % will be settable
-%
-% \def\raggedbottom {\chardef\bottomraggedness=0 \settopskip}
-% \def\alignbottom {\chardef\bottomraggedness=1 \settopskip}
-% \def\baselinebottom{\chardef\bottomraggedness=2 \settopskip}
-%
-% \let\normalbottom =\alignbottom
-
-% \hyphenpenalty = ( 2.5 * \hsize ) / \raggedness
-% \tolerance >= 1500 % was 200
-% \raggedness = 2 .. 6\bodyfontsize
-
-\chardef\raggedstatus=0 % normal left center right
-
-\def\leftraggedness {2\bodyfontsize}
-\def\rightraggedness {2\bodyfontsize}
-\def\middleraggedness {6\bodyfontsize}
-
-\def\middleraggedness {.5\hsize} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
-
-% oeps, hsize can be 0pt in which case we get a strange division
-
-\def\middleraggedness {\ifdim\hsize=\zeropoint6\bodyfontsize\else.5\hsize\fi} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
-
-%D More hyphenation control, will be combined with align
-%D setup.
-
-\def\nohyphens
- {\ifx\dohyphens\relax
- \edef\dohyphens
- {\hyphenpenalty\the\hyphenpenalty
- \exhyphenpenalty\the\exhyphenpenalty\relax}%
- \fi
- \hyphenpenalty\plustenthousand
- \exhyphenpenalty\plustenthousand}
-
-\let\dohyphens\relax
-
-%D To prevent unwanted side effects, we also have to check
-%D for hyphens here:
-
-% \def\setraggedness#1%
-% {\ifnum\tolerance<1500\relax % small values have
-% \tolerance1500\relax % unwanted side effects
-% \fi
-% \spaceskip2.5\hsize % we misuse these registers
-% \xspaceskip#1\relax % for temporary storage;
-% \divide\spaceskip \xspaceskip % they are changed anyway
-% \ifx\dohyphens\relax
-% \hyphenpenalty\spaceskip % \else no hyphens is active
-% \fi}
-
-\newskip\@@raggedskipa
-\newskip\@@raggedskipb
-
-\def\setraggedness#1%
- {\ifnum\tolerance<1500\relax % small values have
- \tolerance1500\relax % unwanted side effects
- \fi
- \ifx\dohyphens\relax
- % this code will be reconsidered / kind of fuzzy (and old)
- \@@raggedskipa 2.5\hsize
- \@@raggedskipb #1\relax
- \divide\@@raggedskipa \@@raggedskipb
- \hyphenpenalty\@@raggedskipa
- \fi}
-
-\let\updateraggedskips\relax
-
-\def\setraggedskips#1#2#3#4#5#6#7% never change this name
- {\def\updateraggedskips{\dosetraggedskips{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
- \updateraggedskips}
-
-\def\dosetraggedskips#1#2#3#4#5#6#7%
- {\chardef \raggedstatus#1\relax
- \leftskip 1\leftskip \!!plus#2\relax % zie: Tex By Topic 8.1.3
- \rightskip 1\rightskip\!!plus#3\relax % zie: Tex By Topic 8.1.3
- \spaceskip #4\relax
- \xspaceskip #5\relax
- \parfillskip\zeropoint\!!plus#6\relax
- \parindent #7\relax}
-
-% \def\notragged%
-% {\setraggedskips{0}{0em}{0em}{0em}{0em}{1fil}{\parindent}}
-
-% older (context) names:
-
-\let\spaceamount \interwordspace
-\let\emspaceamount\emwidth
-
-% tracing:
-
-\def\doshowpardata#1%
- {\ifx#1\relax\else
- \hbox{\string#1: \the#1}\endgraf
- \expandafter\doshowpardata
- \fi}
-
-\def\showpardata
- {\edef\thepardata
- {\hbox{font: \fontname\font}\endgraf
- \doshowpardata
- \interwordspace \interwordstretch \interwordshrink \emwidth \exheight \extraspace
- \hsize \vsize
- \leftskip \rightskip
- \spaceskip \xspaceskip
- \parindent \parfillskip
- \hyphenpenalty \exhyphenpenalty
- \displaywidowpenalty \widowpenalty \clubpenalty \brokenpenalty
- \doublehyphendemerits \finalhyphendemerits \adjdemerits
- \relax}%
- \begingroup
- \dontshowcomposition
- \inleftmargin{\vsmash
- {\switchtobodyfont[7pt,tt]%
- \framed[\c!align=\v!right]{\thepardata}}}%
- \endgroup}
-
-\def\startshowpardata
- {\begingroup
- \showcomposition
- \showstruts\tracepositionstrue \tracingparagraphs\maxdimen
- \appendtoksonce\showpardata\let\showpardata\relax\to\everypar}
-
-\def\stopshowpardata
- {\endgraf
- \endgroup}
-
-% \defineXMLenvironment[showpardata] \startshowpardata \stopshowpardata
-% \defineXMLsingular [showpardata] \showpardata
-
-% defaults
-
-\def\raggedfillamount {1fil}
-\def\raggedhalffillamount{.5fil}
-\def\raggedspaceamount {\interwordspace} % {.3333em}
-\def\raggedxspaceamount {.5em}
-
-\def\notragged
- {\chardef\raggedstatus\zerocount
- \leftskip 1\leftskip
- \rightskip 1\rightskip
- \spaceskip \zeropoint
- \xspaceskip \zeropoint
- \parfillskip\zeropoint\!!plus\raggedfillamount\relax
- \let\updateraggedskips\relax} % new
-
-\let\forgetragged\notragged
-
-\def\raggedleft
- {\setraggedness\leftraggedness
- \setraggedskips1\leftraggedness\zeropoint\raggedspaceamount
- \raggedxspaceamount\zeropoint\zeropoint}
-
-\def\raggedcenter
- {\setraggedness\middleraggedness
- \setraggedskips2\middleraggedness\middleraggedness\raggedspaceamount
- \raggedxspaceamount\zeropoint\zeropoint}
-
-%D We used to have:
-%D
-%D \starttyping
-%D \def\raggedright
-%D {\setraggedness\rightraggedness
-%D \setraggedskips{3}{0em}{\rightraggedness}{.3333em}{.5em}{0em}{\parindent}}
-%D \stoptyping
-%D
-%D However, the next alternative, suggested by Taco, is better.
-
-\def\raggedright
- {\setraggedness\rightraggedness
- \setraggedskips3\zeropoint\rightraggedness\raggedspaceamount
- \raggedxspaceamount\raggedfillamount\parindent}
-
-\def\veryraggedleft
- {\setraggedskips1\raggedfillamount\zeropoint\raggedspaceamount
- \raggedxspaceamount\zeropoint\zeropoint}
-
-%D When we want the last line to have a natural width:
-%D
-%D \starttyping
-%D \def\veryraggedleft%
-%D {\setraggedskips{1}{1fil}{0em}{.3333em}{.5em}{0em}{-1fil}}
-%D \stoptyping
-%D
-%D but this one is not accepted by the macros.
-
-\def\veryraggedcenter
- {\setraggedskips2\raggedfillamount\raggedfillamount\raggedspaceamount
- \raggedxspaceamount\zeropoint\zeropoint}
-
-\def\veryraggedright
- {\setraggedskips3\zeropoint\raggedfillamount\raggedspaceamount
- \raggedxspaceamount\zeropoint\parindent}
-
-\def\ttraggedright
- {\tttf
- \setraggedskips3\zeropoint\rightraggedness
- \zeropoint\zeropoint\zeropoint\parindent} % \ctxparindent
-
-%D A bonus one:
-
-\def\raggedwidecenter
- {\setraggedness\middleraggedness
- \setraggedskips2\raggedhalffillamount\raggedhalffillamount
- \raggedspaceamount\raggedxspaceamount\zeropoint\zeropoint}
-
-\newif\if@@asragged \@@asraggedtrue % old method
-
-% todo
-%
-% \setuplayout[grid=yes,lines=44] \showgrid
-% \starttext
-% test \vfill test \endgraf \strut \endgraf \vskip-\lineheight \removedepth \pagina test
-% \stoptext
-
-% \setupalign[reset,new,right,old]
-
-\def\@@align@@rl{\if!!donea\veryraggedleft \else\raggedleft \fi}
-\def\@@align@@rr{\if!!donea\veryraggedright \else\raggedright \fi}
-\def\@@align@@rc{\if!!donea\veryraggedcenter\else\raggedcenter\fi}
-
-\setvalue{@@ngila@@\v!broad }{\!!doneatrue}
-\setvalue{@@ngila@@\v!wide }{\!!donebtrue}
-
-\def\installalign#1#2{\setvalue{@@align@@#1}{#2}} % can be used for overloads
-
-\installalign \v!new {\@@asraggedfalse}
-\installalign \v!old {\@@asraggedtrue}
-\installalign \empty {}
-
-\installalign \v!line {\baselinebottom}
-\installalign \v!bottom {\raggedbottom}
-\installalign \v!height {\normalbottom}
-\installalign \v!width {\notragged}
-\installalign \v!normal {\notragged}
-\installalign \v!yes {\notragged}
-\installalign \v!no {\raggedright}
-\installalign \v!inner {\if@@asragged \setraggedparagraphmode\@@align@@rl\@@align@@rr \else
- \setraggedparagraphmode\@@align@@rr\@@align@@rl \fi}
-\installalign \v!outer {\if@@asragged \setraggedparagraphmode\@@align@@rr\@@align@@rl \else
- \setraggedparagraphmode\@@align@@rl\@@align@@rr \fi}
-\installalign \v!left {\if@@asragged\@@align@@rl\else\@@align@@rr\fi}
-\installalign \v!right {\if@@asragged\@@align@@rr\else\@@align@@rl\fi}
-\installalign \v!middle {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
-\installalign \v!flushleft {\if!!donea\veryraggedright \else\raggedright\fi}
-\installalign \v!flushright {\if!!donea\veryraggedleft \else\raggedleft \fi}
-\installalign \v!flushouter {\setraggedparagraphmode\raggedleft\raggedright}
-\installalign \v!flushinner {\setraggedparagraphmode\raggedright\raggedleft}
-\installalign \v!center {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi}
-\installalign \v!hanging {\enableprotruding}
-\installalign \v!nothanging {\disableprotruding}
-\installalign \v!hz {\enableadjusting}
-\installalign \v!nohz {\disableadjusting}
-\installalign \v!spacing {\enablespacehandling \enablekernhandling}
-\installalign \v!nospacing {\disablespacehandling\disablekernhandling}
-\installalign \v!hyphenated {\dohyphens}
-\installalign \v!nothyphenated {\nohyphens}
-\installalign \v!new {\@@asraggedfalse} % so new will give you consistency
-\installalign \v!reset {\notragged\normalbottom}
-
-\installalign \v!tolerant {\tolerance3000 \relax}
-\installalign \v!verytolerant {\tolerance4500 \relax}
-\installalign \v!stretch {\emergencystretch\bodyfontsize}
-
-\installalign \v!grid {\mkenablegridsnapping } % only mkiv
-\installalign \v!nogrid {\mkdisablegridsnapping} % only mkiv
-
-\newcount\hyphenminoffset
-
-\ifx\sethyphenationvariables\undefined \let\sethyphenationvariables\relax \fi
-
-\def\lesshyphens
- {\advance\hyphenminoffset\plusone
- \sethyphenationvariables}
-
-\def\morehyphens
- {\ifcase\hyphenminoffset \else
- \advance\hyphenminoffset\minusone
- \fi
- \sethyphenationvariables}
-
-\installalign \v!lesshyphenation {\lesshyphens}
-\installalign \v!morehyphenation {\morehyphens}
-
-\def\dodosetupalign#1{\csname @@align@@#1\endcsname}
-\def\dodosetupngila#1{\csname @@ngila@@#1\endcsname}
-
-\def\setupalign
- {\dosingleargument\dosetupalign}
-
-\def\dosetupalign[#1]% can be made faster by checking for defined #1
- {\!!doneafalse
- \!!donebfalse
- \processcommacommand[#1]\dodosetupngila
- \processcommacommand[#1]\dodosetupalign}
-
-% \setupalign[flushleft] \input ward \par % lijnlinks
-% \setupalign[right] \input ward \par
-
-% \setupalign[flushright] \input ward \par % lijnrechts
-% \setupalign[left] \input ward \par
-
-% \setupalign[middle] \input ward \par % centreer
-% \setupalign[center] \input ward \par
-
-\def\startalignment
- {\bgroup
- \setupalign}
-
-\def\stopalignment
- {\par
- \egroup}
-
-\chardef\alignstrutmode=1
-
-% see later for the real definition, which in the simple case is:
-
-\newtoks \everyleftofalignedline
-\newtoks \everyrightofalignedline
-
-\def\shiftalignedline#1#2#3#4% left, right, inner, outer
- {\rightorleftpageaction
- {\everyleftofalignedline {\hskip\dimexpr#1+#3\relax}%
- \everyrightofalignedline{\hskip\dimexpr#2+#4\relax}}
- {\everyleftofalignedline {\hskip\dimexpr#1+#4\relax}%
- \everyrightofalignedline{\hskip\dimexpr#2+#3\relax}}}
-
-% \def\doalignline#1#2% \\ == newline
-% {\begingroup
-% \setlocalhsize % new
-% \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}%
-% \dowithnextbox
-% {\noindentation % was \noindent
-% \dontleavehmode % added in marrakesch at TUG 2006
-% \hbox to \localhsize
-% {\ifcase\alignstrutmode\or\strut\fi
-% \the\everyleftofalignedline
-% #1\unhbox\nextbox#2\relax
-% \the\everyrightofalignedline}%
-% \endgroup}
-% \hbox}
-
-\def\doalignline#1#2% \\ == newline
- {\noindentation % was \noindent
- \dontleavehmode % added in marrakesch at TUG 2006\begingroup
- \begingroup
- \setlocalhsize % new
- \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}%
- \dowithnextbox
- {\hbox to \localhsize
- {\ifcase\alignstrutmode\or\strut\fi
- \the\everyleftofalignedline
- #1\unhbox\nextbox#2\relax
- \the\everyrightofalignedline}%
- \endgroup}
- \hbox}
-
-% directe commando's
-
-\def\leftaligned {\doalignline \relax \hss }
-\def\midaligned {\doalignline \hss \hss }
-\def\rightaligned{\doalignline \hss \relax}
-
-\def\regelbegrensd#1{\limitatetext{#1}{\hsize}{\unknown}} % to be translated
-
-% indirecte commando's
-
-\letvalue{\s!do\v!line\v!left }\leftaligned
-\letvalue{\s!do\v!line\v!right }\rightaligned
-\letvalue{\s!do\v!line\v!middle }\midaligned
-\letvalue{\s!do\v!line\v!flushleft }\rightaligned
-\letvalue{\s!do\v!line\v!flushright}\leftaligned
-\letvalue{\s!do\v!line\v!center }\midaligned
-
-\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
-
-%D Experimental:
-
-% simple version
-%
-% \def\doxalignline#1#2%
-% {\bgroup
-% \setlocalhsize
-% \def\\{\egroup\par\doxalignline{#1}{#2}\bgroup}% inefficient
-% \dowithnextbox
-% {\noindent\hbox to \localhsize
-% {\ifcase\alignstrutmode\or\strut\fi
-% \signalrightpage
-% \doifrightpageelse{#1\unhbox\nextbox#2}{#2\unhbox\nextbox#1}}%
-% \egroup}
-% \hbox}
-%
-% \setvalue{\s!do\v!regel\v!binnen}{\doxalignline\relax\hss}
-% \setvalue{\s!do\v!regel\v!buiten}{\doxalignline\hss\relax}
-%
-% more extensive:
-
-\def\doxalignline#1#2#3#4#5#6%
- {\noindentation % was \noindent
- \dontleavehmode % added in marrakesch at TUG 2006\begingroup
- \begingroup
- \setlocalhsize
- \def\\{\egroup\par\doxalignline#1#2#3#4#5#6\bgroup}% inefficient
- \dowithnextbox
- {%\noindent moved up
- \hbox to \localhsize
- {#1\hskip\ifdone#2\else#3\fi#4%
- \hbox to \localhsize
- {\the\everyleftofalignedline
- \ifcase\alignstrutmode\or\strut\fi
- \ifdone#5\unhbox\nextbox#6\else#6\unhbox\nextbox#5\fi
- \the\everyrightofalignedline}%
- \hss}%
- \endgroup}
- \hbox}
-
-\def\doxcheckline
- {\signalrightpage\doifrightpageelse\donetrue\donefalse}
-
-\setvalue{\s!do\v!line\v!inner }{\doxalignline\doxcheckline++\zeropoint \relax\hss }
-\setvalue{\s!do\v!line\v!outer }{\doxalignline\doxcheckline++\zeropoint \hss \relax}
-\setvalue{\s!do\v!line\v!innermargin}{\doxalignline\doxcheckline-+\innermargintotal\relax\hss }
-\setvalue{\s!do\v!line\v!outermargin}{\doxalignline\doxcheckline+-\outermargintotal\hss \relax}
-\setvalue{\s!do\v!line\v!inneredge }{\doxalignline\doxcheckline-+\inneredgetotal \relax\hss }
-\setvalue{\s!do\v!line\v!outeredge }{\doxalignline\doxcheckline+-\outeredgetotal \hss \relax}
-\setvalue{\s!do\v!line\v!backspace }{\doxalignline\doxcheckline-+\backspace \relax\hss }
-\setvalue{\s!do\v!line\v!cutspace }{\doxalignline\doxcheckline+-\cutspace \hss \relax}
-
-\setvalue{\s!do\v!line\v!leftmargin }{\doxalignline\donefalse --\leftmargintotal \hss \relax}
-\setvalue{\s!do\v!line\v!rightmargin}{\doxalignline\donefalse ++\rightmargintotal\relax\hss }
-\setvalue{\s!do\v!line\v!leftedge }{\doxalignline\donefalse --\leftedgetotal \hss \relax}
-\setvalue{\s!do\v!line\v!rightedge }{\doxalignline\donefalse ++\rightedgetotal \relax\hss }
-
-% ! ! ! beware, redefining \doalignline gives the wrong results ! ! !
-%
-% \def\doalignline{\doxalignline\donefalse++\zeropoint}
-
-%D Better:
-
-\def\doalignedline#1{\csname\s!do\v!line#1\endcsname}
-
-% \def\alignedline#1#2% setting default
-% {\csname
-% \s!do\v!line
-% \ifundefined{\s!do\v!line#1}#2\else#1\fi
-% \endcsname}
-
-\def\alignedline#1#2% setting default
- {\csname\s!do\v!line\ifcsname\s!do\v!line#1\endcsname#1\else#2\fi\endcsname}
-
-%D ...
-
-\def\dosetuptolerance[#1]%
- {\doifinsetelse\v!vertical{#1}%
- {\ExpandFirstAfter\processallactionsinset
- [#1]
- [ \v!verystrict=>\def\bottomtolerance{},
- \v!strict=>\def\bottomtolerance{.050},
- \v!tolerant=>\def\bottomtolerance{.075},
- \v!verytolerant=>\def\bottomtolerance{.100}]}%
- {\ExpandFirstAfter\processallactionsinset
- [#1]
- [ \v!stretch=>\emergencystretch\bodyfontsize,
- \v!space=>\spaceskip.5em\!!plus.25em\!!minus.25em\relax,
- \v!verystrict=>\tolerance 200,
- \v!strict=>\tolerance1500,
- \v!tolerant=>\tolerance3000,
- \v!verytolerant=>\tolerance4500]}}
-
-\def\setuptolerance
- {\dosingleargument\dosetuptolerance}
-
-% \def\woordrechts
-% {\groupedcommand{\hfill\hbox}{\parfillskip\zeropoint}}
-
-% beware: \wordright{whatever\kern-\rightskip} should work!
-% so, no funny boxing here
-
-\def\dowordright[#1]%
- {% don't change
- \groupedcommand
- {\removeunwantedspaces
- \hfill
- \allowbreak % changed back from \hskip\zeropoint
- \strut
- \hfill
- \quad % decent spacing
- \hbox}
- {\doifelse{#1}\v!right{\kern-\rightskip}{\doifsomething{#1}{\kern-#1}}%
- \parfillskip\zeropoint
- %\finalhyphendemerits\zerocount % yes or no
- \par}}
-
-\def\wordright
- {\dosingleempty\dowordright}
-
-% \dorecurse{5}{something } \wordright{--someone} \endgraf
-% \dorecurse{6}{something } \wordright{--someone} \endgraf
-% \dorecurse{7}{something } \wordright{--someone} \endgraf
-%
-% \dorecurse{5}{something } \wordright{--someone else entirely} \endgraf
-% \dorecurse{6}{something } \wordright{--someone else entirely} \endgraf
-% \dorecurse{7}{something } \wordright{--someone else entirely} \endgraf
-%
-% \wordright[\rightskip]{whatever}
-
-% \simplealignedbox{2cm}{right}{x}
-
-\setvalue{\s!simple\c!align\v!right }#1#2{\hbox to #1{#2\hss}}
-\setvalue{\s!simple\c!align\v!left }#1#2{\hbox to #1{\hss#2}}
-\setvalue{\s!simple\c!align\v!flushright }#1#2{\hbox to #1{\hss#2}}
-\setvalue{\s!simple\c!align\v!flushleft }#1#2{\hbox to #1{#2\hss}}
-\setvalue{\s!simple\c!align\v!middle }#1#2{\hbox to #1{\hss#2\hss}}
-
-\def\simplealignedbox#1{\executeifdefined{\s!simple\c!align#1}{\getvalue{\s!simple\c!align\v!right}}}
-
-%D \macros
-%D {pushindentation,popindentation}
-%D
-%D The pushing and popping is done by:
-
-\newbox\indentationboxA
-\newbox\indentationboxB
-
-\def\pushindentation
- {\bgroup
- \ifhmode
- \unskip
- \setbox\indentationboxA\lastbox % get \strut if present
- \unskip
- \setbox\indentationboxB\lastbox % get \indent generated box
- \unskip
- \else
- \hskip\zeropoint % switch to horizontal mode
- \unskip
- \setbox\indentationboxA\lastbox % get \indent generated box
- \setbox\indentationboxB\box\voidb@x
- \fi}
-
-\def\popindentation
- {\box\indentationboxB\box\indentationboxA % put back the boxes
- \egroup}
-
-%D The only complication lays in \type{\strut}. In \PLAIN\
-%D \TEX\ a \type{\strut} is defined as:
-%D
-%D \starttyping
-%D \def\strut%
-%D {\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
-%D \stoptyping
-%D
-%D But what is a \type{\strut}? Normally it's a rule of width
-%D zero, but when made visual, it's a rule and a negative skip.
-%D The mechanism for putting things in the margins described
-%D here cannot handle this situation very well. One
-%D characteristic of \type{\strut} is that the \type{\unhcopy}
-%D results in entering horizontal mode, which in return leads
-%D to some indentation.
-%D
-%D To serve our purpose a bit better, the macro \type{\strut}
-%D can be redefined as:
-%D
-%D \starttyping
-%D \def\strut
-%D {\relax\ifmmode\else\hskip0pt\fi\copy\strutbox}
-%D \stoptyping
-%D
-%D Or more compatible:
-%D
-%D \starttyping
-%D \def\strut
-%D {\relax\ifmmode
-%D \copy\strutbox
-%D \else
-%D \bgroup\setbox\strutbox=\normalhbox{\box\strutbox}\unhcopy\strutbox\egroup
-%D \fi}
-%D \stoptyping
-%D
-%D In \CONTEXT\ however we save some processing time by putting
-%D an extra \type{\hbox} around the \type{\strutbox}.
-
-% moved from page-lin.tex to here (due to visualization added
-% in august 2003)
-%
-% \unexpanded \def\crlf
-% {\ifhmode\unskip\else\strut\fi\ifcase\raggedstatus\hfil\fi\break}
-
-\unexpanded \def\crlf
- {\ifhmode
- \unskip
- \prewordbreak\crlfplaceholder
- \ifcase\raggedstatus\hfil\or\or\or\hfil\fi
- \break
- \else
- \crlfplaceholder
- \endgraf
- \fi}
-
-\def\crlfplaceholder
- {\strut}
-
-\def\settestcrlf
- {\def\crlfplaceholder
- {\hbox to \zeropoint
- {\strut{\infofont\kern.25em}\lohi{\infofont CR}{\infofont LF}\hss}}}
-
-%D \starttyping
-%D % \setuplayout[gridgrid=yes] \showgrid
-%D
-%D \startbuffer
-%D test 1\crlf
-%D test 2\crlf
-%D
-%D \crlf test 3
-%D
-%D test 4\crlf
-%D test 5
-%D
-%D \crlf
-%D \crlf
-%D \crlf
-%D test 6
-%D \stopbuffer
-%D
-%D \hbox
-%D {\hsize5em
-%D \ruledvtop{\getbuffer}\enspace
-%D \ruledvtop{\showstruts\getbuffer}\enspace
-%D \hsize15em \setuptyping[before=,after=]%
-%D \ruledvtop{\typebuffer}}
-%D \stoptyping
-
-\def\opeenregel % to be used grouped
- {\def\crlf{\removelastspace\space}\let\\\crlf}
-
-\def\showstruts
- {\setteststrut
- \settestcrlf}
-
-\def\definehspace
- {\dotripleempty\dodefinehspace}
-
-\def\dodefinehspace[#1][#2][#3]% #1 = optional namespace
- {\ifthirdargument
- \setvalue{\??hs#1:#2}{#3}%
- \else
- \setvalue{\??hs:#1}{#2}%
- \fi}
-
-\unexpanded\def\hspace
- {\dodoubleempty\dohspace}
-
-%\def\dohspace[#1][#2]%
-% {\ifhmode
-% \removeunwantedspaces
-% \hskip
-% \ifsecondargument
-% \hspaceamount{#1}{#2}%
-% \else
-% \hspaceamount\empty{\iffirstargument#1\else\s!default\fi}%
-% \fi
-% \expandafter\ignorespaces
-% \fi}
-
-\def\dohspace[#1][#2]%
- {\ifsecondargument
- \dodohspace[#1][#2]%
- \else\iffirstargument
- \hspace[][#1]%
- \else
- \hspace[][\s!default]%
- \fi\fi}
-
-% \def\dodohspace[#1][#2#3]%
-% {\ifhmode
-% \removeunwantedspaces
-% \doifelse{#2}{-}
-% {{\scratchskip\hspaceamount{#1}{#3}\hskip-\scratchskip}}
-% {\hskip\hspaceamount{#1}{#2#3}}%
-% \expandafter\ignorespaces
-% \fi}
-%
-% not needed, tex handles -- as +
-
-\def\dodohspace[#1][#2]%
- {\ifhmode
- \removeunwantedspaces
- \hskip\hspaceamount{#1}{#2}%
- \expandafter\ignorespaces
- \fi}
-
-\def\hspaceamount#1#2%
- {\executeifdefined{\??hs#1:#2}{\executeifdefined{\??hs:#2}\zeropoint}}
-
-\definehspace [\v!small] [.25\emspaceamount]
-\definehspace [\v!medium] [.5\emspaceamount]
-\definehspace [\v!big] [1\emspaceamount]
-\definehspace [\v!normal] [1\spaceamount]
-\definehspace [\v!default] [\spaceamount]
-
-%D Taken from Taco's math module (cq. \AMS\ macros), but
-%D adapted to \type {\hspace}:
-
-\unexpanded\def\textormathspace#1#2#3%
- {\ifmmode\mskip#1#2\else\kern#1\hspaceamount\empty{#3}\fi\relax}
-
-\newmuskip\hairmuskip \hairmuskip=.15mu
-
-\def\hairspace {\textormathspace+\hairmuskip{.5}}
-\def\thinspace {\textormathspace+\thinmuskip 1}
-\def\medspace {\textormathspace+\medmuskip 2}
-\def\thickspace {\textormathspace+\thickmuskip3}
-\def\neghairspace {\textormathspace-\thinmuskip{.5}}
-\def\negthinspace {\textormathspace-\thinmuskip 1}
-\def\negmedspace {\textormathspace-\medmuskip 2}
-\def\negthickspace{\textormathspace-\thickmuskip3}
-
-% needed for unicode:
-
-\def\twoperemspace {\hskip\dimexpr\emwidth/2\relax} % == \enspace
-\def\threeperemspace {\hskip\dimexpr\emwidth/3\relax}
-\def\fourperemspace {\hskip\dimexpr\emwidth/4\relax}
-\def\fiveperemspace {\hskip\dimexpr\emwidth/5\relax} % goodie
-\def\sixperemspace {\hskip\dimexpr\emwidth/6\relax}
-\def\figurespace {\begingroup\setbox\scratchbox\hbox{0}\hskip\wd\scratchbox\endgroup} % there is a command for this
-\def\punctuationspace {\begingroup\setbox\scratchbox\hbox{.}\hskip\wd\scratchbox\endgroup}
-\def\ideographicspace {\hskip\dimexpr\emwidth/1\relax}
-\def\ideographichalffillspace{\hskip\dimexpr\emwidth/2\relax}
-\def\nobreakspace {\penalty\plustenthousand\space}
-\def\narrownobreakspace {\penalty\plustenthousand\thinspace}
-\def\zerowidthnobreakspace {\penalty\plustenthousand\hskip\zeropoint}
-\def\zerowidthspace {\hskip\zeropoint}
-
-\definehspace[.5][.1250\emspaceamount] % could also be [.1250\spaceamount]
-\definehspace[1] [.1667\emspaceamount]
-\definehspace[2] [.2222\emspaceamount]
-\definehspace[3] [.2777\emspaceamount]
-
-\let \, \thinspace
-\let \: \medspace
-\let \; \thickspace
-\let \! \negthinspace
-
-% this will become an alternative bunch of \blank settings
-%
-% \startlines
-% \scratchskip=.23pt plus 10pt minus 4pt \relax \number\scratchskip \space \the\scratchskip
-% \setsimplifiedskip\scratchskip1 \number\scratchskip \space \the\scratchskip
-% \setsimplifiedskip\scratchskip2 \number\scratchskip \space \the\scratchskip
-% \getsimplifiedskip\scratchskip\scratchcounter \number\scratchcounter
-% \stoplines
-%
-% \hrule width10cm \endgraf
-% \discardedskip{10pt}
-% \retainedskip {4pt}
-% \discardedskip {5pt}
-% \hrule width10cm \endgraf
-% \blockedskip{0pt}
-% \discardedskip{10pt}
-% \retainedskip {4pt}
-% \discardedskip {5pt}
-% \hrule width10cm \endgraf
-% \frozenskip {4cm}
-% \hrule width10cm \endgraf
-% \vskip10pt
-% \hrule width10cm \endgraf
-
-% ! ! ! etex only, evt splitskip macro gebruiken (syst-new)
-
-\newskip\simplifiedskip
-\newskip\simplifiedcounter
-
-\chardef\@@discardedskip1
-\chardef\@@retainedskip 2
-\chardef\@@forcedskip 3
-\chardef\@@blockedskip 4
-\chardef\@@frozenskip 5 % after heads, no break
-
-\def\setsimplifiedskip#1#2%
- {#1\dimexpr(10\dimexpr(#1/10)) plus \gluestretch#1 minus \glueshrink#1\relax
- \advance#1\numexpr(#2)sp\relax}
-
-\def\getsimplifiedskip#1#2%
- {\simplifiedskip#1\relax
- \ifzeropt\simplifiedskip % \ifdim\simplifiedskip=\zeropoint
- #2\zerocount
- \else
- \simplifiedcounter\dimexpr10\dimexpr#1/10\relax\relax
- \advance\simplifiedskip-\simplifiedcounter
- #2\number\simplifiedskip\relax
- \fi}
-
-\def\conditionalskip#1#2%
- {\scratchskip#1\relax
- \setsimplifiedskip\scratchskip#2\relax
- \vskip\scratchskip\relax}
-
-\def\defrostskip
- {\scratchskip\lastskip\penalty50000\normalvskip-\scratchskip\penalty50000\relax}
-
-\def\frozenskip#1%
- {\endgraf
- \ifvmode
- \getsimplifiedskip\lastskip\scratchcounter
- \ifdim\lastskip>#1\else
- \defrostskip
- \conditionalskip{#1}\@@frozenskip
- \fi
- \fi}
-
-\def\discardedskip#1%
- {\endgraf
- \ifvmode
- \getsimplifiedskip\lastskip\scratchcounter
- \ifcase\scratchcounter
- \conditionalskip{#1}\@@discardedskip
- \or % discard
- \ifdim\lastskip>#1\else
- \normalvskip-\lastskip
- \conditionalskip{#1}\@@discardedskip
- \fi
- \or % retain
- \ifdim\lastskip>#1\else
- \normalvskip-\lastskip
- \conditionalskip{#1}\@@discardedskip
- \fi
- \or % forced
- \conditionalskip{#1}\@@discardedskip
- \or % ignored
- \or % frozen
- \ifdim\lastskip>#1\else
- \defrostskip
- \conditionalskip{#1}\@@frozenskip
- \fi
- \else\ifdim#1=\zeropoint\else
- \vskip#1\relax
- \fi\fi
- \fi}
-
-\def\retainedskip#1%
- {\endgraf
- \ifvmode
- \getsimplifiedskip\lastskip\scratchcounter
- \ifcase\scratchcounter
- \conditionalskip{#1}\@@retainedskip
- \or % discard
- \normalvskip-\lastskip
- \conditionalskip{#1}\@@retainedskip
- \or % retain
- \ifdim\lastskip>#1\else
- \normalvskip-\lastskip
- \conditionalskip{#1}\@@retainedskip
- \fi
- \or % forced
- \conditionalskip{#1}\@@retainedskip
- \or % ignored
- \or % frozen
- \ifdim\lastskip>#1\else
- \defrostskip
- \conditionalskip{#1}\@@frozenskip
- \fi
- \else\ifdim#1=\zeropoint\else
- \vskip#1\relax
- \fi\fi
- \fi}
-
-\def\forcedskip#1%
- {\endgraf
- \ifvmode
- \conditionalskip{#1}\@@forcedskip
- \fi}
-
-\def\blockedskip#1%
- {\endgraf
- \ifvmode
- \getsimplifiedskip\lastskip\scratchcounter
- \ifcase\scratchcounter
- \conditionalskip{#1}\@@blockedskip
- \or % discard
- \conditionalskip{#1}\@@blockedskip
- \or % retain
- \conditionalskip{#1}\@@blockedskip
- \or % forced
- \conditionalskip{#1}\@@blockedskip
- \or % ignored
- \or % frozen
- \ifdim\lastskip>#1\else
- \defrostskip
- \conditionalskip{#1}\@@frozenskip
- \fi
- \else\ifdim#1=\zeropoint\else
- \vskip#1\relax
- \fi\fi
- \fi}
-
-% beware, changing this will break some code (like pos/backgrounds)
-
-\newtoks\everyfirstparagraphintro
-\newtoks\everynextparagraphintro
-\newtoks\@@everyparagraphtoks
-
-\chardef\everyparagraphintro\zerocount
-
-\def\setupparagraphintro
- {\dodoubleempty\dosetupparagraphintro}
-
-\def\dosetupparagraphintro[#1][#2]%
- {\processallactionsinset
- [#1]
- [ \v!reset=>\global\chardef\everyparagraphintro\zerocount
- \global\everyfirstparagraphintro\emptytoks
- \global\everynextparagraphintro \emptytoks,
- \v!first=>\global\chardef\everyparagraphintro\plusone
- \doglobal\appendtoks#2\to\everyfirstparagraphintro,
- \v!next=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plusone\fi
- \doglobal\appendtoks#2\to\everynextparagraphintro,
- \v!each=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro\plustwo\fi
- \doglobal\appendtoks#2\to\everyfirstparagraphintro
- \doglobal\appendtoks#2\to\everynextparagraphintro]}
-
-%D We can say:
-%D
-%D \starttyping
-%D \setupparagraphintro[first][\index{Knuth}]
-%D \stoptyping
-%D
-%D Maybe more convenient is:
-%D
-%D \starttyping
-%D \flushatparagraph{\index{Zapf}}
-%D \stoptyping
-
-\def\flushatparagraph#1%
- {\global\chardef\everyparagraphintro\plusone
- \global\appendtoks{#1}\to\everyfirstparagraphintro}
-
-% \def\doinsertparagraphintro
-% {\ifcase\everyparagraphintro\relax
-% % no data
-% \@@everyparagraphtoks\emptytoks
-% \or
-% % first data
-% \global\chardef\everyparagraphintro\plustwo
-% \@@everyparagraphtoks\everyfirstparagraphintro
-% \global\everyfirstparagraphintro\emptytoks
-% \or
-% % next data
-% \@@everyparagraphtoks\everynextparagraphintro
-% \fi
-% \the\@@everyparagraphtoks}
-
-\def\doinsertparagraphintro
- {\begingroup
- \everypar\emptytoks
- \ifcase\everyparagraphintro\relax
- % no data
- \@@everyparagraphtoks\emptytoks
- \or
- % first data
- \global\chardef\everyparagraphintro\plustwo
- \@@everyparagraphtoks\everyfirstparagraphintro
- \global\everyfirstparagraphintro\emptytoks
- \or
- % next data
- \@@everyparagraphtoks\everynextparagraphintro
- \fi
- \the\@@everyparagraphtoks
- \endgroup}
-
-\def\insertparagraphintro
- {\ifcase\everyparagraphintro\else\@EA\doinsertparagraphintro\fi}
-
-% \appendtoksonce\insertparagraphintro\to\everypar % should come last
-
-%D \starttyping
-%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
-%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
-%D \setupparagraphintro[next] [\hbox to 3.5em{\tt NEXT \hss}]
-%D \setupparagraphintro[next] [\hbox to 3.5em{\tt TXEN \hss}]
-%D \setupparagraphintro[each] [\hbox to 3.0em{\tt EACH \hss}]
-%D \setupparagraphintro[each] [\hbox to 3.0em{\tt HCEA \hss}]
-%D
-%D some paragraph \par
-%D some paragraph \par
-%D some paragraph \par
-%D
-%D \definelabel[parnumber]
-%D
-%D \setupparagraphintro[reset,each][\inleft{\slxx\parnumber}]
-%D
-%D some paragraph \par
-%D some paragraph \par
-%D some paragraph \par
-%D \stoptyping
-
-%D \macros
-%D {flushatnextpar}
-%D
-%D This macro collects data that will be flushed at the next paragraph.
-%D By using this macro you can avoid interfering nodes (writes, etc).
-
-\newbox \postponednodedata
-
-\def\flushatnextpar
- {\bgroup
- \dowithnextbox
- {\global\setbox\postponednodedata\hbox{\box\postponednodedata\box\nextbox}\egroup}%
- \hbox}
-
-\def\flushpostponednodedata
- {\ifvoid\postponednodedata\else
- \hbox{\smashedbox\postponednodedata}%
- \fi}
-
-% Very nasty but needed for margin stuff inside colored
-% paragraphs.
-
-\let\normalvadjust\vadjust
-
-% \def\graphicvadjust % bad, those low level color calls here
-% {\dowithnextbox
-% {\normalvadjust
-% {\dostartgraphicgroup
-% \localstarttextcolor
-% \unvbox\nextbox
-% \localstoptextcolor
-% \dostopgraphicgroup}}%
-% \vbox}
-
-% test this prikkels/pascal margin text before heads (mode
-% 1) as well as uitwerkingen (mode 2)
-
-%chardef\graphicvadjustmode=0 % fake
-%chardef\graphicvadjustmode=1 % normal
-\chardef\graphicvadjustmode=2 % normal + compensate (== default)
-
-\def\graphicvadjust % bad, those low level color calls here
- {\dowithnextboxcontent
- {\forgetall}
- {\ifcase\graphicvadjustmode \@EA \fakedvadjust \else \@EA\normalvadjust \fi
- {\dostartgraphicgroup % don't ask
- \localstarttextcolor
- \unvbox\nextbox
- \localstoptextcolor % don't ask
- \dostopgraphicgroup
- \ifcase\graphicvadjustmode \or \or
- % corrects for one line paragraphs
- \nointerlineskip
- \kern-\struttotal
- \nointerlineskip
- \verticalstrut
- \fi}}%
- \vbox}
-
-%D This works only in a properly strutted line, and is meant
-%D for deeply burried operations, like in heads.
-
-\def\fakedvadjust
- {\dowithnextbox
- {\setbox\nextbox\hbox{\llap{\lower\strutdepth\box\nextbox}}%
- \smashedbox\nextbox}%
- \vtop}
-
-\def\flexiblespaceamount#1#2#3%
- {#1\interwordspace
- \!!plus#2\interwordstretch
- \!!minus#3\interwordshrink}
-
-\def\fixedspaceamount#1%
- {#1\interwordspace}
-
-%D This is a dangerous feature because it makes the \TEX\ source
-%D less portable, i.e. any parser now needs to apply exactly the
-%D same algorithm when it wants to interpret the source. We
-%D strongly recommend not to mention this feature in manuals! It's
-%D provided for users who are hooked to such a mechanism.
-%D
-%D \starttyping
-%D \setupsorting[logo][next=\autoinsertnextspace] \logo[TEX]{\TeX}
-%D
-%D bla bla \TEX bla bla \TEX (bla) bla (\TEX)
-%D \stoptyping
-
-\def\autoinsertnextspace{\futurelet\nexttoken\doautoinsertnextspace}
-
-\def\doautoinsertnextspace % slightly extended version of a user supplied macro
- {\ifx\nexttoken \bgroup\else \ifx\nexttoken\begingroup\else
- \ifx\nexttoken \egroup\else \ifx\nexttoken \endgroup\else
- \ifx\nexttoken \/\else \ifx\nexttoken /\else \ifx\nexttoken ~\else
- \ifx\nexttoken \ \else \ifx\nexttoken \blankspace\else \ifx\nexttoken \space\else
- \ifx\nexttoken .\else \ifx\nexttoken ,\else
- \ifx\nexttoken !\else \ifx\nexttoken ?\else
- \ifx\nexttoken :\else \ifx\nexttoken ;\else
- \ifx\nexttoken '\else \ifx\nexttoken "\else
- \ifx\nexttoken )\else \ifx\nexttoken -\else \ifx\nexttoken |\else
- \ifx\nexttoken \%\else \ifx\nexttoken \&\else
- \space
- \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
-
-% moved from page-lin
-
-\def\installspacehandler#1#2% needs to set \obeyedspace
- {\setvalue{\??sr#1}{#2}}
-
-\installspacehandler \v!on
- {\obeyspaces
- \def\obeyedspace{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}%
- \let\ =\obeyedspace}
-
-\installspacehandler \v!yes
- {\obeyspaces
- \def\obeyedspace{\mathortext\normalspace{\dontleavehmode \normalspace }}%
- \let\ =\obeyedspace}
-
-\installspacehandler \v!off
- {\normalspaces
- \let\obeyedspace\normalspace
- \let\ =\normalspace}
-
-\installspacehandler \v!fixed
- {\obeyspaces
- \def\obeyedspace{\mathortext\normalspace{\dontleavehmode\fixedspace}}%
- \let\ =\obeyedspace}
-
-\def\activatespacehandler#1%
- {\executeifdefined{\??sr#1}{\activatespacehandler\v!off}}
-
-% moved from page-lin
-
-%D When spacing is active we need to handle commands in
-%D a special way:
-%D
-%D \starttyping
-%D \setuplines[space=on]
-%D
-%D \startlines
-%D Let's talk about this{\ttsl\gobbleoneargument or}that.
-%D \stoplines
-%D
-%D \startlines
-%D Let's talk about this{\getvalue{ttsl}or}that.
-%D \stoplines
-%D \stoptyping
-%D
-%D One can indent in several ways:
-%D
-%D \starttyping
-%D \setupindenting[medium] \setuplines[indenting=odd] % no yes odd even
-%D
-%D \startlines
-%D first
-%D second
-%D third
-%D fourth
-%D \stoplines
-%D \stoptyping
-
-\def\setuplines
- {\dodoubleargument\getparameters[\??rg]}
-
-\def\startlines
- {\@@rgbefore
- \pushmacro\checkindentation
- \whitespace
- %\page[\v!preference]} gaat mis na koppen, nieuw: later \nobreak
- \begingroup
- \setupindenting[\@@rgindenting]%
- \typesettinglinestrue
- \setupwhitespace[\v!none]%
- \obeylines
- \ignorespaces
- \gdef\afterfirstobeyedline % tzt two pass, net als opsomming
- {\gdef\afterfirstobeyedline
- {\nobreak
- \global\let\afterfirstobeyedline\relax}}%
- \def\obeyedline
- {\par
- \afterfirstobeyedline
- \futurelet\next\dobetweenthelines}%
- \activatespacehandler\@@rgspace
- \GotoPar}
-
-\def\stoplines
- {\endgroup
- \popmacro\checkindentation
- \@@rgafter}
-
-\def\dobetweenthelines
- {\doifmeaningelse\next\obeyedline\@@rginbetween\donothing}
-
-\setuplines
- [\c!before=\blank,
- \c!after=\blank,
- \c!inbetween=\blank,
- \c!indenting=\v!no,
- \c!space=\v!default]
-
-\def\emptylines
- {\dosingleempty\doemptylines}
-
-\def\doemptylines[#1]%
- {\endgraf\dorecurse{\iffirstargument#1\else3\fi}\crlf}
-
-% plugins
-
-\loadmarkfile{core-spa}
-
-\setupwhitespace
- [\v!none]
-
-% still old-fashioned
-
-\indenting
- [\v!never]
-
-\setupindenting
- [\v!none]
-
-\setupblank
- [\v!standard,
- \v!big]
-
-\defineblank[\v!default] [\currentblank]
-\defineblank[\v!before] [\v!default]
-\defineblank[\v!inbetween][\v!default]
-\defineblank[\v!after] [\v!before]
-
-\setupinterlinespace
- [\c!minheight=0pt, % only special purpose
- \c!mindepth=0pt, % only special purpose
- \c!height=.72,
- \c!depth=.28,
- \c!top=1.0,
- \c!bottom=0.4,
- \c!distance=1pt,
- \c!line=2.8ex,
- \c!stretch=0]
-
-\setupnarrower
- [\c!before=\endgraf,
- \c!after=\endgraf,
- \c!left=1.5em,
- \c!right=1.5em,
- \c!middle=1.5em]
-
-\setuptolerance
- [\v!horizontal,\v!verystrict]
-
-\setuptolerance
- [\v!vertical,\v!strict]
-
-\setupalign
- [\v!bottom,
- \v!width]
-
-\setupspacing
- [\v!packed]
-
-\protect \endinput
diff --git a/tex/context/base/core-stg.tex b/tex/context/base/core-stg.tex
index 94e5250e5..429e1e894 100644
--- a/tex/context/base/core-stg.tex
+++ b/tex/context/base/core-stg.tex
@@ -12,7 +12,7 @@
%C details.
%D This is a prelude to strategies. It is rather old code
-%D used in a project may years ago. Use with care since I
+%D used in a project many years ago. Use with care since I
%D will pick up this thread. (moved from cont-new)
\unprotect
@@ -28,7 +28,7 @@
\definetwopasslist{\s!strategy}
-\def\registerstrategypass%
+\def\registerstrategypass
{\ifnum\currentstrategypass>\maximumstrategypass \else
\ifconditional\strategypassforced
\doglobal\increment\currentstrategypass
diff --git a/tex/context/base/core-syn.lua b/tex/context/base/core-syn.lua
deleted file mode 100644
index 10bd9d6d9..000000000
--- a/tex/context/base/core-syn.lua
+++ /dev/null
@@ -1,127 +0,0 @@
-if not modules then modules = { } end modules ['core-syn'] = {
- version = 1.001,
- comment = "companion to core-syn.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
-sorters = sorters or { }
-sorters.list = sorters.list or { }
-
-function sorters.list.compare(a,b)
- return sorters.comparers.basic(a,b,1)
-end
-
-function sorters.list.prepare(data)
- sorters.prepare(data,sorters.splitters.utf,1)
-end
-
-function sorters.list.sort(data)
- sorters.sort(data,sorters.list.compare)
-end
-
-function sorters.list.unique(data)
- sorters.unique(data)
-end
-
-function sorters.list.cleanup(data)
- sorters.cleanup(data)
-end
-
-function sorters.list.finalize(data) -- hm, this really needs documentation
- -- we use the same splitter as with indices
- local split = { }
- for k,v in ipairs(data) do
- local entry, tag = v[2][1][3][1], ""
- local se = sorters.entries[sorters.language]
- if se and se[entry] then
- if type(se[entry]) == "number" then
- entry = se[entry]
- end
- tag = se[entry]
- else
- entry = 0
- tag = "unknown"
- end
- split[entry] = split[entry] or { tag = tag, data = { } }
- split[entry].data[#split[entry].data+1] = v
- end
- return split
-end
-
--- for the moment we use the old structure, some day mkiv code
--- will be different: more structure, less mess
-
-local template = {
- entry = "\\synonymentry{%s}{%s}{%s}{%s}"
-}
-
-function sorters.list.flush(sorted,class)
- -- for the moment we don't add split data (letters) yet
- class = class or 'abbreviation'
- for k,v in ipairs(table.sortedkeys(sorted)) do
- for _, vv in ipairs(sorted[v].data) do
- tex.sprint(tex.ctxcatcodes,template.entry:format(class,vv[2][1][1],vv[2][1][2],vv[3]))
- end
- end
-end
-
-function sorters.list.process(data)
- return sorters.process('list',data)
-end
-
--- interface to tex end
-
-joblists = joblists or { }
-joblists.collected = joblists.collected or { }
-joblists.tobesaved = joblists.tobesaved or { }
-
-local collected, tobesaved = joblists.collected, joblists.tobesaved
-
-local function initializer()
- collected, tobesaved = joblists.collected, joblists.tobesaved
-end
-
-job.register('joblists.collected', joblists.tobesaved, initializer, nil)
-
-local function allocate(class)
- local d = tobesaved[class]
- if not d then
- d = {
- language = 'en',
- entries = { },
- sorted = false,
- class = class
- }
- tobesaved[class] = d
- end
- return d
-end
-
-local function collect(class)
- return collected[class]
-end
-
-joblists.define = allocate
-
--- this should be more generic, i.e. userdata = { meaning = "" }
--- or at least we should get rid of the { { } } which is a quick
--- hack to share code with the indexer
-
-function joblists.save_entry(class,kind,entry,key,meaning)
- local data = allocate(class).entries
- data[#data+1] = { kind, { { entry, key } }, meaning } -- { kind, entry, key, meaning }
-end
-
-function joblists.save_variable(class,key,value)
- if key == "l" then key = "language" end
- allocate(class)[key] = value
-end
-
-function joblists.process(class)
- local data = collect(class)
- if data then
- sorters.list.process(data)
- end
-end
diff --git a/tex/context/base/core-syn.mkii b/tex/context/base/core-syn.mkii
deleted file mode 100644
index b3fdb1738..000000000
--- a/tex/context/base/core-syn.mkii
+++ /dev/null
@@ -1,28 +0,0 @@
-%D \module
-%D [ file=core-syn,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Synonyms and Sorts,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-\def\mkdefinesortedlist#1% class
- {\addutilityreset{#1}}
-
-\def\mksavesortedlistentry#1#2#3#4%
- {\immediatewriteutility{s e {#1} {#2} {#3} {#4}}}
-
-\def\mksavesortedlistvariable#1#2#3% class type value
- {\immediatewriteutility{s #2 {#1} {#3}}}
-
-\def\mkloadsortedlist#1% class
- {\doutilities{#1}\jobname{#1}\relax\relax}
-
-\protect \endinput
diff --git a/tex/context/base/core-syn.mkiv b/tex/context/base/core-syn.mkiv
deleted file mode 100644
index 3b5398b56..000000000
--- a/tex/context/base/core-syn.mkiv
+++ /dev/null
@@ -1,34 +0,0 @@
-%D \module
-%D [ file=core-syn,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Synonyms and Sorts,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-\registerctxluafile{core-syn}{1.001}
-
-\def\mkdefinesortedlist#1% class
- {\ctxlua{joblists.define('#1')}}
-
-\def\mksavesortedlistentry#1#2#3#4% class key entry meaning
- {\ctxlua{joblists.save_entry('#1','e','#2',\!!bs#3\!!es,\!!bs#4\!!es)}}
-
-\def\mksavesortedlistvariable#1#2#3% class type value
- {\ctxlua{joblists.save_variable('#1','#2','#3')}}
-
-\def\mkloadsortedlist#1% class
- {\bgroup
- \getvalue{\s!set#1}%
- \ctxlua{joblists.process('#1')}%
- \getvalue{\s!reset#1}%
- \egroup}
-
-\protect \endinput
diff --git a/tex/context/base/core-syn.tex b/tex/context/base/core-syn.tex
index 926e58233..b5c87c487 100644
--- a/tex/context/base/core-syn.tex
+++ b/tex/context/base/core-syn.tex
@@ -11,17 +11,10 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Synonyms and Sorts}
+\writestatus{loading}{ConTeXt Core Macros / Synonyms and Sorts}
\unprotect
-\ifx\mkdefinesortedlist\undefined
- \let\mkdefinesortedlist \gobbleoneargument
- \let\mksavesortedlistentry \gobblefourarguments
- \let\mksavesortedlistvariable\gobblethreearguments
- \let\mkloadsortedlist \gobbleoneargument
-\fi
-
% \checkdefined kan hierheen
% Formaat tex-utility-input-file :
@@ -86,7 +79,7 @@
\c!color=]%
\setupwhitespace[\v!none]%
%doutilities{#1}\jobname{#2}\relax\par % no longer \par
- \mkloadsortedlist{#1}%
+ \doutilities{#1}\jobname{#1}\relax\relax
\endgroup
\ifutilitydone\else\nowhitespace\fi}
@@ -101,7 +94,7 @@
\synonymmeaningfalse
\doattributes{\??sm#1}\c!synonymstyle\c!synonymcolor{#3}%
\else
- \explicithmode
+ \dontleavehmode
\doattributes{\??sm#1}\c!textstyle\c!textcolor{#2}%
\fi
\endgroup}
@@ -119,7 +112,7 @@
{\begingroup % anders in mathmode lege \hbox
\defconvertexpanded\asciisynonym{\getvalue{\??sm#1\c!expansion}}{#3}%
\defconvertexpanded\asciimeaning{\getvalue{\??sm#1\c!expansion}}{#4}%
- \mksavesortedlistentry{#1}{#2}{\asciisynonym}{\asciimeaning}%
+ \immediatewriteutility{s e {#1} {#2} {\asciisynonym} {\asciimeaning}}%
\endgroup}
\def\reprocesssynonym#1#2#3%
@@ -155,7 +148,7 @@
{\bgroup
\let\dosetsynonym\doloadsynonym
\showmessage\m!systems{19}{#2}%
- \mkloadsortedlist{#1}%
+ \doutilities{#1}\jobname{#1}\relax\relax
\egroup
\setvalue{\s!check#1}##1{}}
@@ -180,7 +173,7 @@
\def\doregistersynonymlanguage#1%
{\savesortlanguage{\getvalue{\??sm#1\s!language}}%
- \mksavesortedlistvariable{#1}{l}{\getvalue{\??sm#1\s!language}}}
+ \immediatewriteutility{s l {#1} {\getvalue{\??sm#1\s!language}}}}
\def\dodefinesynonyms[#1][#2][#3][#4]%
{\iffourthargument
@@ -210,7 +203,7 @@
\doregistersynonymlanguage{#1}%
\to \everysavesortkeys
\presetheadtext[#2=\Word{#2}]% changes the \if...argument
- \mkdefinesortedlist{#1}%
+ \addutilityreset{#1}%
\setvalue{\e!setup #2\e!endsetup}{\dodoubleargument\getparameters[\??sm#1]}% to be obsolete
\setvalue{\s!set #1}{\dosetsynonym{#1}}%
\setvalue{\s!reset #1}{\doresetsynonym{#1}}%
@@ -256,8 +249,7 @@
{\whitespace % ZONDER WITRUIMTE ETC ETC
\begingroup
\setupwhitespace[\v!none]%
- %doutilities{#1}\jobname{#1}\relax\par % brr \par
- \mkloadsortedlist{#1}%
+ \doutilities{#1}\jobname{#1}\relax\relax
\endgroup
\ifutilitydone\else\nowhitespace\fi}
@@ -266,7 +258,7 @@
% \def\doplacelistofsorts#1% NOG EEN RUWE VERSIE MAKEN
% {\startpacked
% %doutilities{#1}\jobname{#1}\relax\par
-% \mkloadsortedlist{#1}%
+% \doutilities{#1}\jobname{#1}\relax\relax
% \stoppacked}
\def\docompletelistofsorts#1#2%
@@ -280,7 +272,7 @@
% {\doplacelistofsorts{#1}}
\def\processsort#1#2#3%
- {\explicithmode
+ {\dontleavehmode
\begingroup % was \bgroup
\doattributes{\??so#1}\c!style\c!color{#2}%
\endgroup} % was \egroup
@@ -288,7 +280,7 @@
\def\dowritesort#1#2#3%
{\bgroup
\defconvertexpanded\asciisynonym{\getvalue{\??so#1\c!expansion}}{#3}%
- \mksavesortedlistentry{#1}{#2}{\asciisynonym}{}%
+ \immediatewriteutility{s e {#1} {#2} {\asciisynonym} {}}%
\egroup}
\def\synonymentry#1%
@@ -321,7 +313,7 @@
{\bgroup
\let\dosetsort\doloadsort
\showmessage\m!systems{20}{#2}%
- \mkloadsortedlist{#1}%
+ \doutilities{#1}\jobname{#1}\relax\relax
\egroup
\setvalue{\s!check#1}##1{}}
@@ -346,7 +338,7 @@
\def\doregistersortinglanguage#1%
{\savesortlanguage{\getvalue{\??so#1\s!language}}%
- \mksavesortedlistvariable{#1}{l}{\getvalue{\??so#1\s!language}}}
+ \immediatewriteutility{s l {#1} {\getvalue{\??so#1\s!language}}}}
\def\dodefinesorting[#1][#2][#3]%
{\getparameters[\??so#1]
@@ -370,7 +362,7 @@
\else
\setvalue{#1}{\dotripleempty\docomplexsort[][#1]}%
\fi
- \mkdefinesortedlist{#1}%
+ \addutilityreset{#1}%
\presetheadtext[#2=\Word{#2}]% after \ifthirdargument -)
\setvalue{\e!setup#2\e!endsetup}[##1]{\getparameters[\??so#1][##1]}% to be obsolete
\setvalue{\s!set#1}{\dosetsort{#1}}%
@@ -388,7 +380,7 @@
%D written by Taco.
\def\processlistofsorts[#1]%
- {\mkloadsortedlist{#1}}
+ {\doutilities{#1}\jobname{#1}\relax\relax}
\newcounter\nofsortedalphalists
@@ -410,10 +402,6 @@
% \def\whatever{ax,bx,qx,dx,rx,fx} \sortalphacommacommand\whatever \whatever \endgraf
% \stoptext
-%D Plugins.
-
-\loadmarkfile{core-syn}
-
%D Presets.
\definesynonyms
diff --git a/tex/context/base/core-sys.mkii b/tex/context/base/core-sys.mkii
index 6816364de..24975ffb6 100644
--- a/tex/context/base/core-sys.mkii
+++ b/tex/context/base/core-sys.mkii
@@ -11,4 +11,386 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-%D For the moment this file is empty.
+\writestatus{loading}{ConTeXt Core Macros / System}
+
+\unprotect
+
+%D Version checking:
+
+\def\newcontextversion#1%
+ {\doifelse{#1}\contextversion
+ {\let\newcontextversion\gobbleoneargument}
+ {\writeline
+ \writestatus{Fatal Error}{Your format does not match the base files!}%
+ \writeline
+ \writestatus{Format Version}{\contextversion\space\contextmark}%
+ \writestatus{Files Version}{#1}%
+ \batchmode
+ \normalend}}
+
+%D End of lines to the output. \TEX\ will map this onto the platform specific
+%D line ending. I hate this mess.
+
+%newlinechar=10 \def\outputnewlinechar{\rawcharacter{10}}
+\newlinechar=10 \edef\outputnewlinechar{^^J}
+
+% in case formats are shared:
+
+\def\initializenewlinechar
+ {\bgroup\newlinechar=10\xdef\outputnewlinechar{^^J}\egroup}
+
+%D Job names.
+
+\def\outputfilename {\@@svfile}
+\def\inputfilename {\@@svinputfile}
+\def\operatingsystem{\@@svtype}
+
+\let\jobfilename \jobname
+\let\jobfilesuffix\c!tex
+
+\def\splitjobfilename % todo: mkiv
+ {\resetsystemmode{suffix-\jobfilesuffix}%
+ \edef\ascii{\inputfilename}\defconvertedcommand\ascii\ascii
+ \splitstring\ascii\at.\to\jobfilename\and\jobfilesuffix
+ \lowercasestring\jobfilesuffix\to\jobfilesuffix
+ \doifnothing\jobfilename {\let\jobfilename \jobname}%
+ % todo and totest: \defconvertedcommand\jobfilename\jobfilename
+ \doifnothing\jobfilesuffix{\let\jobfilesuffix\c!tex}%
+ \setsystemmode{suffix-\jobfilesuffix}}
+
+% Some mechanisms (see x-res-01) use either \jobfilename or
+% \jobfilename.somesuffix, in which case we need to use the
+% full name if given or a default (like \jobfilename.xml);
+% this comes down to replacing the default tex suffix.
+
+\def\jobfullname{\jobfilename.\jobfilesuffix}
+
+\def\setjobfullname#1% #1 = default if not given
+ {\doifelsenothing\jobfilename
+ {\let\jobfullname\empty}
+ {\doif\jobfilesuffix\c!tex{\edef\jobfullname{\jobfilename.#1}}}}
+
+% ...
+
+\def\dosetupsystem[#1]%
+ {\getparameters[\??sv][#1]%
+ \setuprandomize[\@@svrandom]%
+ \beforesplitstring\@@svresolution\at dpi\to\@@svresolution
+ \let\outputresolution\@@svresolution
+ \ifcase\@@svn
+ % % 0 : unknown
+ \or
+ \setsystemmode\v!first % 1 : first run
+ \or
+ % % 2 : successive run
+ \or
+ \setsystemmode\v!first % 3 : first and only run
+ \or
+ \setsystemmode\v!last % 4 : (extra) last run
+ \fi
+% \processaction
+% [\@@svtype]
+% %[ mswin=>\edef\@@svline{\rawcharacter{13}\rawcharacter{10}}, % crlf
+% [ mswin=>\edef\@@svline{\rawcharacter{13}}, % cr % crlf
+% darwin=>\edef\@@svline{\rawcharacter{13}}, % cr
+% \s!unknown=>\edef\@@svline{\rawcharacter{10}}]% % lf
+ \splitjobfilename}
+
+% \edef\@@svline{\rawcharacter{10}} % unix is the most critical/sensitive system
+
+\let\systemendofline\outputnewlinechar % will become obsolete
+
+\def\setupsystem
+ {\dosingleargument\dosetupsystem}
+
+\def\systemparameter#1{\executeifdefined{\??sv#1}\empty}
+
+%D The system modes set by the setup command can be used in
+%D situations like:
+%D
+%D \starttyping
+%D \startmode[*first]
+%D \executesystemcommand{cleanupxml text.xml clean-text.xml}
+%D \stopmode
+%D
+%D \starttext
+%D \typefile{clean-text.xml}
+%D \stoptext
+%D \stoptyping
+
+\def\setuprandomize[#1]%
+ {\doifsomething{#1}
+ {\bgroup
+ % tex's time is in minutes
+ \scratchcounter\normaltime
+ \processaction
+ [#1]
+ [ \v!small=>\divide\scratchcounter 15, % 900,
+ \v!medium=>\divide\scratchcounter 30, % 1800,
+ \v!big=>\divide\scratchcounter 60, % 3600,
+ \v!normal=>\getnewrandomseed\scratchcounter,
+ \s!default=>\getnewrandomseed\scratchcounter,
+ \s!unknown=>\scratchcounter#1]%
+ \expanded{\setrandomseed{\the\scratchcounter}}%
+% \writestatus\m!systems{randomseed: \the\scratchcounter}%
+ \egroup}}
+
+
+\setupsystem
+ [\c!directory=,
+ \c!n=0, % 0:unknown 1: one run 2: first 3: successive 4: final run
+ \c!resolution=600dpi,
+ \c!random=,
+ \c!file=\jobname,
+ \c!inputfile=\outputfilename,
+ \c!type=unix, % windows is normally less sensitive to handle
+ \c!bodyfont=\normalizedlocalbodyfontsize] % of iets anders
+
+%D Remark: windows programs normally handle \type {cr|lf|crlf} but unix
+%D is more picky, so we default to the \type {cr}. I never understood why
+%D \type {crlf} was not used in all systems, since it makes most sense.
+
+\def\dostartglobaldefs#1#2%
+ {\edef\!!stringa{\the\globaldefs}%
+ \ifnum\globaldefs#10
+ \globaldefs-\globaldefs
+ \fi
+ \advance\globaldefs #21
+ \setevalue{@gd@\the\globaldefs}{\!!stringa}}
+
+\def\dostopglobaldefs
+ {\doifdefinedelse{@gd@\the\globaldefs}
+ {\globaldefs\getvalue{@gd@\the\globaldefs}\relax}
+ {\globaldefs\zerocount}}
+
+\def\startlocal {\dostartglobaldefs>-}
+\def\stoplocal {\dostopglobaldefs}
+\def\startglobal {\dostartglobaldefs<+}
+\def\stopglobal {\dostopglobaldefs}
+
+\def\complexstart[#1]{\bgroup\getvalue{\e!start#1}}
+\def\complexstop [#1]{\getvalue{\e!stop #1}\egroup}
+
+\let\simplestart\bgroup
+\let\simplestop \egroup
+
+\definecomplexorsimple\start
+\definecomplexorsimple\stop
+
+\def\dododefinestartstop[#1][#2]% todo: use indirect commands
+ {\getparameters
+ [\??be#1]
+ [\c!before=,
+ \c!after=,
+ \c!inbetween=,
+ \c!commands=,
+ \c!style=,
+ #2]%
+ \unexpanded\setvalue{#1}%
+ {\groupedcommand
+ {\getvalue{\??be#1\c!commands}%
+ \dostartattributes{\??be#1}\c!style\c!color}
+ {\dostopattributes
+ \getvalue{\??be#1\c!inbetween}}}%
+ \setvalue{\e!start#1}%
+ {\getvalue{\??be#1\c!before}%
+ \bgroup
+ \getvalue{\??be#1\c!commands}%
+ \dostartattributes{\??be#1}\c!style\c!color\empty}%
+ \setvalue{\e!stop#1}%
+ {\dostopattributes
+ \egroup
+ \getvalue{\??be#1\c!after}}}
+
+\def\dodefinestartstop[#1][#2]%
+ {\def\docommand##1{\dododefinestartstop[##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\def\definestartstop
+ {\dodoubleargument\dodefinestartstop}
+
+\def\dosetupstartstop[#1][#2]%
+ {\def\docommand##1{\getparameters[\??be##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\def\setupstartstop
+ {\dodoubleargument\dosetupstartstop}
+
+% \docommand kan niet worden gebruikt omdat deze macro
+% soms lokaal wordt gebruikt
+
+% te zijner tijd:
+%
+% \definevariable {pc} % ProtectedCommand
+%
+% \def\executeprotected#1%
+% {\csname\??pc\string#1\endcsname}
+%
+% \def\defineprotected#1#2%
+% {\expandafter\def\csname\??pc\string#2\endcsname}
+%
+% \def\defineunprotected#1%
+% {\def#1}
+%
+% \def\doprotected%
+% {\ifx\next\define
+% \let\next=\defineprotected
+% \else
+% \let\next=\executeprotected
+% \fi
+% \next}
+%
+% \def\unexpanded%
+% {\futurelet\next\doprotected}
+%
+% \unexpanded\define\ziezo{ziezo}
+%
+% \unexpanded\ziezo
+
+\def\complexdefine[#1]#2#3%
+ {\ifx#2\undefined
+ \else
+ \showmessage\m!systems4{\string#2}%
+ \fi
+ \ifcase0#1\def#2{#3}%
+ \or\def#2##1{#3}%
+ \or\def#2##1##2{#3}%
+ \or\def#2##1##2##3{#3}%
+ \or\def#2##1##2##3##4{#3}%
+ \or\def#2##1##2##3##4##5{#3}%
+ \or\def#2##1##2##3##4##5##6{#3}%
+ \or\def#2##1##2##3##4##5##6##7{#3}%
+ \or\def#2##1##2##3##4##5##6##7##8{#3}%
+ \or\def#2##1##2##3##4##5##6##7##8##9{#3}%
+ \else\def#2{#3}%
+ \fi}
+
+\definecomplexorsimpleempty\define
+
+\unexpanded\def\macroname#1% brrr
+ {\executeifdefined{#1}\empty}
+
+\def\usecommands#1%
+ {\bgroup
+ \def\docommand##1{\setbox0\hbox{\getvalue{\string##1}##1}}%
+ \processcommalist[#1]\docommand
+ \egroup}
+
+\newif\ifforcefileexpansion % handy for document level overload
+
+%D The next implementation is about 4 times as faster than a
+%D processaction alternative on an string of average length.
+%D Since this feature is used in XML processing, it made sense
+%D to support this faster alternative. It's installable as well.
+
+\def\installexpander#1#2#3% changed, no longer \convert..\to...
+ {\setvalue{\s!do\c!expansion#1l}{#2}%
+ \setvalue{\s!do\c!expansion#1g}{#3}}%
+
+% \convertexpanded is obsolete
+
+\long\def\doconvertexpanded#1#2#3% #4 % [l|g] \cs {kind} {data}
+ {\csname % that we assign all exp a value
+ \s!do\c!expansion
+ \ifforcefileexpansion
+ \v!yes
+ \else\ifcsname\s!do\c!expansion#3#1\endcsname
+ #3%
+ \else
+ \s!default
+ \fi\fi
+ #1%
+ \endcsname#2}% #3
+
+\long\def\defconvertexpanded {\doconvertexpanded l}
+\long\def\gdefconvertexpanded{\doconvertexpanded g}
+
+\installexpander\v!command \defconvertedcommand \gdefconvertedcommand
+\installexpander\s!default \defconvertedargument \gdefconvertedargument
+\installexpander\empty \defconvertedargument \gdefconvertedargument
+\installexpander\v!no \defconvertedargument \gdefconvertedargument
+\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
+\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
+\installexpander\v!strict \defreducedargument \gdefreducedargument
+\installexpander {utf} \defreducedtoutf \gdefreducedtoutf
+
+%installexpander {xml} {see xtag-ext}
+
+\def\dodefconvertedmeaning#1#2#3% watch the double expansion !
+ {\bgroup
+ \honorunexpanded
+ \convertencodedtokens % can be overloaded
+ \xdef\@@globalexpanded{#3}%
+ \xdef\@@globalexpanded{\@@globalexpanded}%
+ \egroup
+ #1#2\@@globalexpanded}
+
+\def\defconvertedmeaning {\dodefconvertedmeaning\defconvertedcommand}
+\def\gdefconvertedmeaning{\dodefconvertedmeaning\gdefconvertedcommand}
+
+\def\dodefreducedargument#1#2#3%
+ {\begingroup
+ \reducetocoding[raw]%
+ \edef\ascii{#3}%
+ \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
+
+\def\defreducedargument {\dodefreducedargument\edef}
+\def\gdefreducedargument{\dodefreducedargument\xdef}
+
+% \setupindex[expansion=utf]\index{\eacute}
+
+\def\dodefreducedtoutf#1#2#3%
+ {\begingroup
+ \reducetocoding[uc]%
+ \let\uchar\uchartoutf
+ \let\unicodechar\numbertoutf
+ \edef\ascii{#3}%
+ \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
+
+\def\defreducedtoutf {\dodefreducedtoutf\edef}
+\def\gdefreducedtoutf{\dodefreducedtoutf\xdef}
+
+% old syntax:
+
+\def\convertmeaning#1\to#2% watch the double expansion !
+ {\bgroup
+ \honorunexpanded
+ \convertencodedtokens % can be overloaded
+ \xdef\@@globalexpanded{#1}%
+ \xdef\@@globalexpanded{\@@globalexpanded}%
+ \egroup
+ \defconvertedcommand#2\@@globalexpanded}
+
+\def\reduceargument#1\to#2%
+ {\begingroup
+ \reducetocoding[raw]%
+ \edef\ascii{#1}%
+ \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
+
+\def\reducetoutf#1\to#2%
+ {\begingroup
+ \reducetocoding[uc]%
+ \let\uchar\uchartoutf
+ \let\unicodechar\numbertoutf
+ \edef\ascii{#1}%
+ \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
+
+% \setvalue{statevalue\v!stop }{0}
+% \setvalue{statevalue\v!start }{1}
+% \setvalue{statevalue\v!normaal}{2}
+% \setvalue{statevalue\v!leeg }{3}
+% \setvalue{statevalue\v!geen }{4}
+%
+% \def\setcurrentstate#1%
+% {\chardef\currentstate=0\getvalue{statevalue\getvalue{#1\c!state}\relax}
+%
+% \ifcase\currentstate ...
+
+\def\redo{\dorepeat} % [n*10], kind of obsolete
+
+% obsolete, use \dorecurse instead
+%
+% \def\herhaler {\repeater}
+% \def\herhaalmetcommando {\dorepeatwithcommand}
+
+\protect \endinput
diff --git a/tex/context/base/core-sys.mkiv b/tex/context/base/core-sys.mkiv
index 0cef6c236..073c29b66 100644
--- a/tex/context/base/core-sys.mkiv
+++ b/tex/context/base/core-sys.mkiv
@@ -1,6 +1,6 @@
%D \module
-%D [ file=core-sys,
-%D version=2006.09.18,
+%D [ file=core-sys, % moved from main-001
+%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=System,
%D author=Hans Hagen,
@@ -11,6 +11,371 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+% we need to mkiv-ize this file !
+
+\writestatus{loading}{ConTeXt Core Macros / System}
+
+\unprotect
+
+%D Version checking:
+
+\def\newcontextversion#1%
+ {\doifelse{#1}\contextversion
+ {\let\newcontextversion\gobbleoneargument}
+ {\writeline
+ \writestatus{Fatal Error}{Your format does not match the base files!}%
+ \writeline
+ \writestatus{Format Version}{\contextversion\space\contextmark}%
+ \writestatus{Files Version}{#1}%
+ \batchmode
+ \normalend}}
+
+%D End of lines to the output. \TEX\ will map this onto the platform specific
+%D line ending. I hate this mess.
+
+%newlinechar=10 \def\outputnewlinechar{\rawcharacter{10}}
+\newlinechar=10 \edef\outputnewlinechar{^^J}
+
+% in case formats are shared:
+
+\def\initializenewlinechar
+ {\bgroup\newlinechar=10\xdef\outputnewlinechar{^^J}\egroup}
+
+%D Job names.
+
+\def\outputfilename {\@@svfile}
+\def\inputfilename {\@@svinputfile}
+\def\operatingsystem{\@@svtype}
+
+\let\jobfilename \jobname
+\let\jobfilesuffix\c!tex
+
+\def\splitjobfilename % todo: mkiv
+ {\resetsystemmode{suffix-\jobfilesuffix}%
+ \edef\ascii{\inputfilename}\defconvertedcommand\ascii\ascii
+ \splitstring\ascii\at.\to\jobfilename\and\jobfilesuffix
+ \lowercasestring\jobfilesuffix\to\jobfilesuffix
+ \doifnothing\jobfilename {\let\jobfilename \jobname}%
+ % todo and totest: \defconvertedcommand\jobfilename\jobfilename
+ \doifnothing\jobfilesuffix{\let\jobfilesuffix\c!tex}%
+ \setsystemmode{suffix-\jobfilesuffix}}
+
+% Some mechanisms (see x-res-01) use either \jobfilename or
+% \jobfilename.somesuffix, in which case we need to use the
+% full name if given or a default (like \jobfilename.xml);
+% this comes down to replacing the default tex suffix.
+
+\def\jobfullname{\jobfilename.\jobfilesuffix}
+
+\def\setjobfullname#1% #1 = default if not given
+ {\doifelsenothing\jobfilename
+ {\let\jobfullname\empty}
+ {\doif\jobfilesuffix\c!tex{\edef\jobfullname{\jobfilename.#1}}}}
+
+% ...
+
+\def\dosetupsystem[#1]%
+ {\getparameters[\??sv][#1]%
+ \setuprandomize[\@@svrandom]%
+ \beforesplitstring\@@svresolution\at dpi\to\@@svresolution
+ \let\outputresolution\@@svresolution
+ \ifcase\@@svn
+ % % 0 : unknown
+ \or
+ \setsystemmode\v!first % 1 : first run
+ \or
+ % % 2 : successive run
+ \or
+ \setsystemmode\v!first % 3 : first and only run
+ \or
+ \setsystemmode\v!last % 4 : (extra) last run
+ \fi
+% \processaction
+% [\@@svtype]
+% %[ mswin=>\edef\@@svline{\rawcharacter{13}\rawcharacter{10}}, % crlf
+% [ mswin=>\edef\@@svline{\rawcharacter{13}}, % cr % crlf
+% darwin=>\edef\@@svline{\rawcharacter{13}}, % cr
+% \s!unknown=>\edef\@@svline{\rawcharacter{10}}]% % lf
+ \splitjobfilename}
+
+% \edef\@@svline{\rawcharacter{10}} % unix is the most critical/sensitive system
+
+\let\systemendofline\outputnewlinechar % will become obsolete
+
+\def\setupsystem
+ {\dosingleargument\dosetupsystem}
+
+\def\systemparameter#1{\executeifdefined{\??sv#1}\empty}
+
+%D The system modes set by the setup command can be used in
+%D situations like:
+%D
+%D \starttyping
+%D \startmode[*first]
+%D \executesystemcommand{cleanupxml text.xml clean-text.xml}
+%D \stopmode
+%D
+%D \starttext
+%D \typefile{clean-text.xml}
+%D \stoptext
+%D \stoptyping
+
+\def\setuprandomize[#1]%
+ {\doifsomething{#1}
+ {\bgroup
+ % tex's time is in minutes
+ \scratchcounter\normaltime
+ \processaction
+ [#1]
+ [ \v!small=>\divide\scratchcounter 15, % 900,
+ \v!medium=>\divide\scratchcounter 30, % 1800,
+ \v!big=>\divide\scratchcounter 60, % 3600,
+ \v!normal=>\getnewrandomseed\scratchcounter,
+ \s!default=>\getnewrandomseed\scratchcounter,
+ \s!unknown=>\scratchcounter#1]%
+ \expanded{\setrandomseed{\the\scratchcounter}}%
+% \writestatus\m!systems{randomseed: \the\scratchcounter}%
+ \egroup}}
+
+\setupsystem
+ [\c!directory=,
+ \c!n=0, % 0:unknown 1: one run 2: first 3: successive 4: final run
+ \c!resolution=600dpi,
+ \c!random=,
+ \c!file=\jobname,
+ \c!inputfile=\outputfilename,
+ \c!type=unix, % windows is normally less sensitive to handle
+ \c!bodyfont=\normalizedlocalbodyfontsize] % of iets anders
+
+%D Remark: windows programs normally handle \type {cr|lf|crlf} but unix
+%D is more picky, so we default to the \type {cr}. I never understood why
+%D \type {crlf} was not used in all systems, since it makes most sense.
+
+\def\dostartglobaldefs#1#2%
+ {\edef\!!stringa{\the\globaldefs}%
+ \ifnum\globaldefs#10
+ \globaldefs-\globaldefs
+ \fi
+ \advance\globaldefs #21
+ \setevalue{@gd@\the\globaldefs}{\!!stringa}}
+
+\def\dostopglobaldefs
+ {\doifdefinedelse{@gd@\the\globaldefs}
+ {\globaldefs\getvalue{@gd@\the\globaldefs}\relax}
+ {\globaldefs\zerocount}}
+
+\def\startlocal {\dostartglobaldefs>-}
+\def\stoplocal {\dostopglobaldefs}
+\def\startglobal {\dostartglobaldefs<+}
+\def\stopglobal {\dostopglobaldefs}
+
+\def\complexstart[#1]{\bgroup\getvalue{\e!start#1}}
+\def\complexstop [#1]{\getvalue{\e!stop #1}\egroup}
+
+\let\simplestart\bgroup
+\let\simplestop \egroup
+
+\definecomplexorsimple\start
+\definecomplexorsimple\stop
+
+\def\dododefinestartstop[#1][#2]% todo: use indirect commands
+ {\getparameters
+ [\??be#1]
+ [\c!before=,
+ \c!after=,
+ \c!inbetween=,
+ \c!commands=,
+ \c!style=,
+ #2]%
+ \unexpanded\setvalue{#1}%
+ {\groupedcommand
+ {\getvalue{\??be#1\c!commands}%
+ \dostartattributes{\??be#1}\c!style\c!color}
+ {\dostopattributes
+ \getvalue{\??be#1\c!inbetween}}}%
+ \setvalue{\e!start#1}%
+ {\getvalue{\??be#1\c!before}%
+ \bgroup
+ \getvalue{\??be#1\c!commands}%
+ \dostartattributes{\??be#1}\c!style\c!color\empty}%
+ \setvalue{\e!stop#1}%
+ {\dostopattributes
+ \egroup
+ \getvalue{\??be#1\c!after}}}
+
+\def\dodefinestartstop[#1][#2]%
+ {\def\docommand##1{\dododefinestartstop[##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\def\definestartstop
+ {\dodoubleargument\dodefinestartstop}
+
+\def\dosetupstartstop[#1][#2]%
+ {\def\docommand##1{\getparameters[\??be##1][#2]}%
+ \processcommalist[#1]\docommand}
+
+\def\setupstartstop
+ {\dodoubleargument\dosetupstartstop}
+
+% \docommand kan niet worden gebruikt omdat deze macro
+% soms lokaal wordt gebruikt
+
+% te zijner tijd:
+%
+% \definevariable {pc} % ProtectedCommand
+%
+% \def\executeprotected#1%
+% {\csname\??pc\string#1\endcsname}
+%
+% \def\defineprotected#1#2%
+% {\expandafter\def\csname\??pc\string#2\endcsname}
+%
+% \def\defineunprotected#1%
+% {\def#1}
+%
+% \def\doprotected%
+% {\ifx\next\define
+% \let\next=\defineprotected
+% \else
+% \let\next=\executeprotected
+% \fi
+% \next}
+%
+% \def\unexpanded%
+% {\futurelet\next\doprotected}
+%
+% \unexpanded\define\ziezo{ziezo}
+%
+% \unexpanded\ziezo
+
+\def\complexdefine[#1]#2#3%
+ {\ifx#2\undefined
+ \else
+ \showmessage\m!systems4{\string#2}%
+ \fi
+ \ifcase0#1\def#2{#3}%
+ \or\def#2##1{#3}%
+ \or\def#2##1##2{#3}%
+ \or\def#2##1##2##3{#3}%
+ \or\def#2##1##2##3##4{#3}%
+ \or\def#2##1##2##3##4##5{#3}%
+ \or\def#2##1##2##3##4##5##6{#3}%
+ \or\def#2##1##2##3##4##5##6##7{#3}%
+ \or\def#2##1##2##3##4##5##6##7##8{#3}%
+ \or\def#2##1##2##3##4##5##6##7##8##9{#3}%
+ \else\def#2{#3}%
+ \fi}
+
+\definecomplexorsimpleempty\define
+
+\unexpanded\def\macroname#1% brrr
+ {\executeifdefined{#1}\empty}
+
+\def\usecommands#1%
+ {\bgroup
+ \def\docommand##1{\setbox0\hbox{\getvalue{\string##1}##1}}%
+ \processcommalist[#1]\docommand
+ \egroup}
+
+\newif\ifforcefileexpansion % handy for document level overload
+
+%D The next implementation is about 4 times as faster than a
+%D processaction alternative on an string of average length.
+%D Since this feature is used in XML processing, it made sense
+%D to support this faster alternative. It's installable as well.
+
+\def\installexpander#1#2#3% changed, no longer \convert..\to...
+ {\setvalue{\s!do\c!expansion#1l}{#2}%
+ \setvalue{\s!do\c!expansion#1g}{#3}}%
+
+% \convertexpanded is obsolete
+
+\long\def\doconvertexpanded#1#2#3% #4 % [l|g] \cs {kind} {data}
+ {\csname % that we assign all exp a value
+ \s!do\c!expansion
+ \ifforcefileexpansion
+ \v!yes
+ \else\ifcsname\s!do\c!expansion#3#1\endcsname
+ #3%
+ \else
+ \s!default
+ \fi\fi
+ #1%
+ \endcsname#2}% #3
+
+\long\def\defconvertexpanded {\doconvertexpanded l}
+\long\def\gdefconvertexpanded{\doconvertexpanded g}
+
+\installexpander\v!command \defconvertedcommand \gdefconvertedcommand
+\installexpander\s!default \defconvertedargument \gdefconvertedargument
+\installexpander\empty \defconvertedargument \gdefconvertedargument
+\installexpander\v!no \defconvertedargument \gdefconvertedargument
+\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
+\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
+\installexpander\v!strict \defreducedargument \gdefreducedargument
+\installexpander {utf} \defreducedtoutf \gdefreducedtoutf
+
+%installexpander {xml} {see xtag-ext}
+
+\def\dodefconvertedmeaning#1#2#3% watch the double expansion !
+ {\bgroup
+ \honorunexpanded
+ \convertencodedtokens % can be overloaded
+ \xdef\@@globalexpanded{#3}%
+ \xdef\@@globalexpanded{\@@globalexpanded}%
+ \egroup
+ #1#2\@@globalexpanded}
+
+\def\defconvertedmeaning {\dodefconvertedmeaning\defconvertedcommand}
+\def\gdefconvertedmeaning{\dodefconvertedmeaning\gdefconvertedcommand}
+
+\def\dodefreducedargument#1#2#3%
+ {\begingroup
+ \reducetocoding[raw]%
+ \edef\ascii{#3}%
+ \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
+
+\def\defreducedargument {\dodefreducedargument\edef}
+\def\gdefreducedargument{\dodefreducedargument\xdef}
+
+% \setupindex[expansion=utf]\index{\eacute}
+
+\def\dodefreducedtoutf#1#2#3%
+ {\begingroup
+ \reducetocoding[uc]%
+ \let\uchar\uchartoutf
+ \let\unicodechar\numbertoutf
+ \edef\ascii{#3}%
+ \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
+
+\def\defreducedtoutf {\dodefreducedtoutf\edef}
+\def\gdefreducedtoutf{\dodefreducedtoutf\xdef}
+
+% old syntax:
+
+\def\convertmeaning#1\to#2% watch the double expansion !
+ {\bgroup
+ \honorunexpanded
+ \convertencodedtokens % can be overloaded
+ \xdef\@@globalexpanded{#1}%
+ \xdef\@@globalexpanded{\@@globalexpanded}%
+ \egroup
+ \defconvertedcommand#2\@@globalexpanded}
+
+\def\reduceargument#1\to#2%
+ {\begingroup
+ \reducetocoding[raw]%
+ \edef\ascii{#1}%
+ \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
+
+\def\reducetoutf#1\to#2%
+ {\begingroup
+ \reducetocoding[uc]%
+ \let\uchar\uchartoutf
+ \let\unicodechar\numbertoutf
+ \edef\ascii{#1}%
+ \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
+
\startruntimeluacode
\ctxlua {
environment.inputfilename = "\inputfilename"
@@ -19,5 +384,5 @@
environment.jobfilesuffix = "\jobfilesuffix"
}
\stopruntimeluacode
-
-\endinput
+
+\protect \endinput
diff --git a/tex/context/base/core-sys.tex b/tex/context/base/core-sys.tex
deleted file mode 100644
index 7e3aa3c04..000000000
--- a/tex/context/base/core-sys.tex
+++ /dev/null
@@ -1,401 +0,0 @@
-%D \module
-%D [ file=core-sys, % moved from main-001
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=System,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros (System)}
-
-\unprotect
-
-%D Version checking:
-
-\def\newcontextversion#1%
- {\doifelse{#1}\contextversion
- {\let\newcontextversion\gobbleoneargument}
- {\writeline
- \writestatus{Fatal Error}{Your format does not match the base files!}%
- \writeline
- \writestatus{Format Version}{\contextversion\space\contextmark}%
- \writestatus{Files Version}{#1}%
- \batchmode
- \normalend}}
-
-%D End of lines to the output. \TEX\ will map this onto the platform specific
-%D line ending. I hate this mess.
-
-%newlinechar=10 \def\outputnewlinechar{\rawcharacter{10}}
-\newlinechar=10 \edef\outputnewlinechar{^^J}
-
-% in case formats are shared:
-
-\appendtoks
- \bgroup\newlinechar=10\xdef\outputnewlinechar{^^J}\egroup
-\to \everyjob
-
-%D Job names.
-
-\def\outputfilename {\@@svfile}
-\def\inputfilename {\@@svinputfile}
-\def\operatingsystem{\@@svtype}
-
-\let\jobfilename \jobname
-\let\jobfilesuffix\c!tex
-
-\def\splitjobfilename % todo: mkiv
- {\resetsystemmode{suffix-\jobfilesuffix}%
- \edef\ascii{\inputfilename}\defconvertedcommand\ascii\ascii
- \splitstring\ascii\at.\to\jobfilename\and\jobfilesuffix
- \lowercasestring\jobfilesuffix\to\jobfilesuffix
- \doifnothing\jobfilename {\let\jobfilename \jobname}%
- % todo and totest: \defconvertedcommand\jobfilename\jobfilename
- \doifnothing\jobfilesuffix{\let\jobfilesuffix\c!tex}%
- \setsystemmode{suffix-\jobfilesuffix}}
-
-\appendtoks \splitjobfilename \to \everyjob
-
-% Some mechanisms (see x-res-01) use either \jobfilename or
-% \jobfilename.somesuffix, in which case we need to use the
-% full name if given or a default (like \jobfilename.xml);
-% this comes down to replacing the default tex suffix.
-
-\def\jobfullname{\jobfilename.\jobfilesuffix}
-
-\def\setjobfullname#1% #1 = default if not given
- {\doifelsenothing\jobfilename
- {\let\jobfullname\empty}
- {\doif\jobfilesuffix\c!tex{\edef\jobfullname{\jobfilename.#1}}}}
-
-% ...
-
-\def\dosetupsystem[#1]%
- {\getparameters[\??sv][#1]%
- \setuprandomize[\@@svrandom]%
- \beforesplitstring\@@svresolution\at dpi\to\@@svresolution
- \let\outputresolution\@@svresolution
- \ifcase\@@svn
- % % 0 : unknown
- \or
- \setsystemmode\v!first % 1 : first run
- \or
- % % 2 : successive run
- \or
- \setsystemmode\v!first % 3 : first and only run
- \or
- \setsystemmode\v!last % 4 : (extra) last run
- \fi
-% \processaction
-% [\@@svtype]
-% %[ mswin=>\edef\@@svline{\rawcharacter{13}\rawcharacter{10}}, % crlf
-% [ mswin=>\edef\@@svline{\rawcharacter{13}}, % cr % crlf
-% darwin=>\edef\@@svline{\rawcharacter{13}}, % cr
-% \s!unknown=>\edef\@@svline{\rawcharacter{10}}]% % lf
- \splitjobfilename}
-
-% \edef\@@svline{\rawcharacter{10}} % unix is the most critical/sensitive system
-
-\let\systemendofline\outputnewlinechar % will become obsolete
-
-\def\setupsystem
- {\dosingleargument\dosetupsystem}
-
-\def\systemparameter#1{\executeifdefined{\??sv#1}\empty}
-
-%D The system modes set by the setup command can be used in
-%D situations like:
-%D
-%D \starttyping
-%D \startmode[*first]
-%D \executesystemcommand{cleanupxml text.xml clean-text.xml}
-%D \stopmode
-%D
-%D \starttext
-%D \typefile{clean-text.xml}
-%D \stoptext
-%D \stoptyping
-
-\def\setuprandomize[#1]%
- {\doifsomething{#1}
- {\bgroup
- % tex's time is in minutes
- \scratchcounter\normaltime
- \processaction
- [#1]
- [ \v!small=>\divide\scratchcounter 15, % 900,
- \v!medium=>\divide\scratchcounter 30, % 1800,
- \v!big=>\divide\scratchcounter 60, % 3600,
- \v!normal=>\getnewrandomseed\scratchcounter,
- \s!default=>\getnewrandomseed\scratchcounter,
- \s!unknown=>\scratchcounter#1]%
- \expanded{\setrandomseed{\the\scratchcounter}}%
- \egroup}}
-
-\setupsystem
- [\c!directory=,
- \c!n=0, % 0:unknown 1: one run 2: first 3: successive 4: final run
- \c!resolution=600dpi,
- \c!random=,
- \c!file=\jobname,
- \c!inputfile=\outputfilename,
- \c!type=unix, % windows is normally less sensitive to handle
- \c!bodyfont=\normalizedlocalbodyfontsize] % of iets anders
-
-%D Remark: windows programs normally handle \type {cr|lf|crlf} but unix
-%D is more picky, so we default to the \type {cr}. I never understood why
-%D \type {crlf} was not used in all systems, since it makes most sense.
-
-\def\dostartglobaldefs#1#2%
- {\edef\!!stringa{\the\globaldefs}%
- \ifnum\globaldefs#10
- \globaldefs-\globaldefs
- \fi
- \advance\globaldefs #21
- \setevalue{@gd@\the\globaldefs}{\!!stringa}}
-
-\def\dostopglobaldefs
- {\doifdefinedelse{@gd@\the\globaldefs}
- {\globaldefs\getvalue{@gd@\the\globaldefs}\relax}
- {\globaldefs\zerocount}}
-
-\def\startlocal {\dostartglobaldefs>-}
-\def\stoplocal {\dostopglobaldefs}
-\def\startglobal {\dostartglobaldefs<+}
-\def\stopglobal {\dostopglobaldefs}
-
-\def\complexstart[#1]{\bgroup\getvalue{\e!start#1}}
-\def\complexstop [#1]{\getvalue{\e!stop #1}\egroup}
-
-\let\simplestart\bgroup
-\let\simplestop \egroup
-
-\definecomplexorsimple\start
-\definecomplexorsimple\stop
-
-\def\dododefinestartstop[#1][#2]% todo: use indirect commands
- {\getparameters
- [\??be#1]
- [\c!before=,
- \c!after=,
- \c!inbetween=,
- \c!commands=,
- \c!style=,
- #2]%
- \unexpanded\setvalue{#1}%
- {\groupedcommand
- {\getvalue{\??be#1\c!commands}%
- \dostartattributes{\??be#1}\c!style\c!color}
- {\dostopattributes
- \getvalue{\??be#1\c!inbetween}}}%
- \setvalue{\e!start#1}%
- {\getvalue{\??be#1\c!before}%
- \bgroup
- \getvalue{\??be#1\c!commands}%
- \dostartattributes{\??be#1}\c!style\c!color\empty}%
- \setvalue{\e!stop#1}%
- {\dostopattributes
- \egroup
- \getvalue{\??be#1\c!after}}}
-
-\def\dodefinestartstop[#1][#2]%
- {\def\docommand##1{\dododefinestartstop[##1][#2]}%
- \processcommalist[#1]\docommand}
-
-\def\definestartstop
- {\dodoubleargument\dodefinestartstop}
-
-\def\dosetupstartstop[#1][#2]%
- {\def\docommand##1{\getparameters[\??be##1][#2]}%
- \processcommalist[#1]\docommand}
-
-\def\setupstartstop
- {\dodoubleargument\dosetupstartstop}
-
-% \docommand kan niet worden gebruikt omdat deze macro
-% soms lokaal wordt gebruikt
-
-% te zijner tijd:
-%
-% \definevariable {pc} % ProtectedCommand
-%
-% \def\executeprotected#1%
-% {\csname\??pc\string#1\endcsname}
-%
-% \def\defineprotected#1#2%
-% {\expandafter\def\csname\??pc\string#2\endcsname}
-%
-% \def\defineunprotected#1%
-% {\def#1}
-%
-% \def\doprotected%
-% {\ifx\next\define
-% \let\next=\defineprotected
-% \else
-% \let\next=\executeprotected
-% \fi
-% \next}
-%
-% \def\unexpanded%
-% {\futurelet\next\doprotected}
-%
-% \unexpanded\define\ziezo{ziezo}
-%
-% \unexpanded\ziezo
-
-\def\complexdefine[#1]#2#3%
- {\ifx#2\undefined
- \else
- \showmessage\m!systems4{\string#2}%
- \fi
- \ifcase0#1\def#2{#3}%
- \or\def#2##1{#3}%
- \or\def#2##1##2{#3}%
- \or\def#2##1##2##3{#3}%
- \or\def#2##1##2##3##4{#3}%
- \or\def#2##1##2##3##4##5{#3}%
- \or\def#2##1##2##3##4##5##6{#3}%
- \or\def#2##1##2##3##4##5##6##7{#3}%
- \or\def#2##1##2##3##4##5##6##7##8{#3}%
- \or\def#2##1##2##3##4##5##6##7##8##9{#3}%
- \else\def#2{#3}%
- \fi}
-
-\definecomplexorsimpleempty\define
-
-\unexpanded\def\macroname#1% brrr
- {\executeifdefined{#1}\empty}
-
-\def\usecommands#1%
- {\bgroup
- \def\docommand##1{\setbox0\hbox{\getvalue{\string##1}##1}}%
- \processcommalist[#1]\docommand
- \egroup}
-
-\newif\ifforcefileexpansion % handy for document level overload
-
-%D The next implementation is about 4 times as faster than a
-%D processaction alternative on an string of average length.
-%D Since this feature is used in XML processing, it made sense
-%D to support this faster alternative. It's installable as well.
-
-\def\installexpander#1#2#3% changed, no longer \convert..\to...
- {\setvalue{\s!do\c!expansion#1l}{#2}%
- \setvalue{\s!do\c!expansion#1g}{#3}}%
-
-% \convertexpanded is obsolete
-
-\long\def\doconvertexpanded#1#2#3% #4 % [l|g] \cs {kind} {data}
- {\csname % that we assign all exp a value
- \s!do\c!expansion
- \ifforcefileexpansion
- \v!yes
- \else\ifcsname\s!do\c!expansion#3#1\endcsname
- #3%
- \else
- \s!default
- \fi\fi
- #1%
- \endcsname#2}% #3
-
-\long\def\defconvertexpanded {\doconvertexpanded l}
-\long\def\gdefconvertexpanded{\doconvertexpanded g}
-
-\installexpander\v!command \defconvertedcommand \gdefconvertedcommand
-\installexpander\s!default \defconvertedargument \gdefconvertedargument
-\installexpander\empty \defconvertedargument \gdefconvertedargument
-\installexpander\v!no \defconvertedargument \gdefconvertedargument
-\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
-\installexpander\v!yes \defconvertedmeaning \gdefconvertedmeaning
-\installexpander\v!strict \defreducedargument \gdefreducedargument
-\installexpander {utf} \defreducedtoutf \gdefreducedtoutf
-
-%installexpander {xml} {see xtag-ext}
-
-\def\dodefconvertedmeaning#1#2#3% watch the double expansion !
- {\bgroup
- \honorunexpanded
- \convertencodedtokens % can be overloaded
- \xdef\@@globalexpanded{#3}%
- \xdef\@@globalexpanded{\@@globalexpanded}%
- \egroup
- #1#2\@@globalexpanded}
-
-\def\defconvertedmeaning {\dodefconvertedmeaning\defconvertedcommand}
-\def\gdefconvertedmeaning{\dodefconvertedmeaning\gdefconvertedcommand}
-
-\def\dodefreducedargument#1#2#3%
- {\begingroup
- \reducetocoding[raw]%
- \edef\ascii{#3}%
- \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
-
-\def\defreducedargument {\dodefreducedargument\edef}
-\def\gdefreducedargument{\dodefreducedargument\xdef}
-
-% \setupindex[expansion=utf]\index{\eacute}
-
-\def\dodefreducedtoutf#1#2#3%
- {\begingroup
- \reducetocoding[uc]%
- \let\uchar\uchartoutf
- \let\unicodechar\numbertoutf
- \edef\ascii{#3}%
- \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}
-
-\def\defreducedtoutf {\dodefreducedtoutf\edef}
-\def\gdefreducedtoutf{\dodefreducedtoutf\xdef}
-
-% old syntax:
-
-\def\convertmeaning#1\to#2% watch the double expansion !
- {\bgroup
- \honorunexpanded
- \convertencodedtokens % can be overloaded
- \xdef\@@globalexpanded{#1}%
- \xdef\@@globalexpanded{\@@globalexpanded}%
- \egroup
- \defconvertedcommand#2\@@globalexpanded}
-
-\def\reduceargument#1\to#2%
- {\begingroup
- \reducetocoding[raw]%
- \edef\ascii{#1}%
- \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
-
-\def\reducetoutf#1\to#2%
- {\begingroup
- \reducetocoding[uc]%
- \let\uchar\uchartoutf
- \let\unicodechar\numbertoutf
- \edef\ascii{#1}%
- \expandafter\endgroup\expandafter\edef\expandafter#2\expandafter{\ascii}}
-
-% \setvalue{statevalue\v!stop }{0}
-% \setvalue{statevalue\v!start }{1}
-% \setvalue{statevalue\v!normaal}{2}
-% \setvalue{statevalue\v!leeg }{3}
-% \setvalue{statevalue\v!geen }{4}
-%
-% \def\setcurrentstate#1%
-% {\chardef\currentstate=0\getvalue{statevalue\getvalue{#1\c!state}\relax}
-%
-% \ifcase\currentstate ...
-
-\def\redo{\dorepeat} % [n*10], kind of obsolete
-
-% obsolete, use \dorecurse instead
-%
-% \def\herhaler {\repeater}
-% \def\herhaalmetcommando {\dorepeatwithcommand}
-
-%D Plugins
-
-\loadmarkfile{core-sys}
-
-\protect \endinput
diff --git a/tex/context/base/core-tab.tex b/tex/context/base/core-tab.tex
deleted file mode 100644
index 2e843eae8..000000000
--- a/tex/context/base/core-tab.tex
+++ /dev/null
@@ -1,2499 +0,0 @@
-%D \module
-%D [ file=core-tab,
-%D version=1997.10.10,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=\TABLE\ Embedding,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / TaBlE Embedding}
-
-% By now it makes more sense to merge the patches into the original
-% and clean that one up too.
-
-% Don't change the splitter:
-%
-% ... \NR
-% \TABLEnoalign{\page}\TABLEhead
-% \NC ...
-
-% e-tex: reverse rows or vadjust or ... in tables
-% \ifalign
-% \xhrule : calls for 'special' with width
-% BUG:
-%
-% \starttable[|l|l|]
-% \HL
-% \RL\FR \VL Head 1 \VL Head 2 \VL\FR
-% \RL\LR \VL Head A \VL Head B \VL\LR % niet grijs ??
-% \HL
-% \VL 1 \VL 2 \VL\FR
-% \VL a \VL b \VL\LR
-% \HL
-% \stoptable
-
-% melden als in kleur conflict, uitgestelde test op \SR\SR
-
-% verengelsen
-% interface
-
-% footnotes flushen
-% \......TABLE........ namen
-% kolommen testen
-% unbreakable kop definieren
-% voetnoten
-% meldingen
-% als direct \use{max} dan fout
-% \BREAKPOINT
-% breedte lijn telt
-% errors: ook gray in handle
-
-% \AR -> als in DL dan \DR
-
-% nieuw:
-%
-% \NL / \NL[blanko] is skip, nog default?
-% geen \HL in a row
-% \HL[n]
-% \VL[n] + remembers
-% c{colorspec} key
-% \HC[color][width]
-% \VC[color]
-% meldingen row, column, use, advise
-% \AR: UITSTELLEN / EXPERIMENTEEL
-
-% WAARDELOZE ERROR HANDLER
-% THIS RENEWED MODULE WORKS OK BUT STILL LOOKS BAD
-
-%D We felt no need to write our own table building macros,
-%D simply because Michael Wichura made a terrific one. This
-%D package is quite complete and well documented. In \CONTEXT\
-%D we provide a shell for consistent spacing as well as color
-%D support. Implementing these features without adapting the
-%D original macros is not trivial. One easilly gets conflicts
-%D with \type{\omit}, \type{\span} and \type{\noalign}, which
-%D means that we end up postponing and overloading macros,
-%D mostly global. Now, let's start with loading the main
-%D macros:
-
-\doifundefined{BeginTable}{\doinputonce{table.tex}}
-
-\unprotect
-
-%D \macros
-%D {inintable, ifsplittables}
-%D
-%D First we declare some variables. These show a bit what we
-%D are dealing with. First we introdoce some booleans that
-%D enable us, inside as well as outside this module, to
-%D determine in what mode we are.
-
-\newif\ifintable
-\newif\ifsplittables
-
-%D \macros
-%D {tracetablestrue}
-%D
-%D When I documented this module, I felt the need for tracing
-%D options. After implementing this feature, I also added
-%D warnings, error recovery and automatic spacing.
-
-\newif\iftracetables
-
-%D We show this feature in an eample that also shows some of
-%D the basic table typesetting commands.
-%D
-%D \startbuffer
-%D \starttable[|||]
-%D \HL
-%D \VL first \VL second \VL\AR
-%D \HL
-%D \VL alfa \VL 1 \VL\AR
-%D \VL beta \VL 2 \VL\AR
-%D \VL gamma \VL 3 \VL\AR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \startcombination
-%D {\tracetablesfalse\getbuffer} {\type{\tracetablesfalse}}
-%D {\tracetablestrue\getbuffer} {\type{\tracetablestrue}}
-%D \stopcombination
-%D
-%D This table is specified as:
-%D
-%D \typebuffer
-%D
-%D This examples shows about the minimum of commands needed to
-%D typeset such a table. In this table, the \type {\AR} is
-%D automatically translated into the more primitive (but more
-%D verbose) commands \type {\SR}, \type {\FR}, \type {\MR} and
-%D \type {\LR} commands.
-%D
-%D \startbuffer
-%D \starttables[|||]
-%D \HL
-%D \VL first \VL second \VL\AR
-%D \HL
-%D \VL alfa \VL 1 \VL\AR
-%D \VL beta \VL 2 \VL\AR
-%D \VL gamma \VL 3 \VL\AR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D When we use the split table feature, we get a bit more
-%D information.
-%D
-%D {\tracetablesfalse\getbuffer}
-%D
-%D Sometimes in tables information shows up that is not typed
-%D in by the user. These messages give a cue in what aspect a
-%D table definition is wrong.
-%D
-%D \startbuffer
-%D \starttable[||||]
-%D \HL
-%D \VL first second \VL third \VL\AR
-%D \HL
-%D \VL alfa \VL 1 \VL a \VL\AR
-%D \VL beta \VL 2 \VL b \VL
-%D \VL gamma \VL \THREE{3} c \VL\AR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Those terrible table has three errors, which all show up in
-%D typeset messages. Errors cannot always recovered 100\% and
-%D therefore can result in two or more succesive messages, like
-%D in the last row.
-%D
-%D \getbuffer
-
-%D Bringing color into tables is complicated by the mere fact
-%D that color is not part of \TEX. The main complication is
-%D that we don't know in advance how wide a column will be. I
-%D implemented color support in tables in the early 90's
-%D because I needed it for some articles on color. I have to
-%D admit that I seldom use the mechanism.
-%D
-%D Most color support in \CONTEXT\ makes use of colored rules.
-%D At first sight, one is tempted to implement colors in tables
-%D in a similar way, but as said, we don't know the dimensions
-%D in advance. It turns out however that we don't have to,
-%D simply because alignments take care of stretching rules to
-%D the appropritate dimensions. This means that we can provide
-%D backgrounds by coloring rules with the height of a row,
-%D skipping upwards and finally drawing the content, like in:
-%D
-%D \gdef\ShowExample
-%D {\startfiguretext
-%D {none}
-%D {\getbuffer}
-%D \typebuffer
-%D \stopfiguretext}
-%D
-%D \startbuffer
-%D \starttable[|c|c|]
-%D \HL
-%D \BL[2] \SR
-%D \VL test \VL test \VL\SR
-%D \HL
-%D \VL test \VL test \VL\FR
-%D \VL test \VL test \VL\MR
-%D \VL test \VL test \VL\LR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D Just to be complete we show how the other columns can be
-%D given a background. Later we will provide more details over
-%D the commands used.
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \HL
-%D \BL[3] \SR
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \HL
-%D \BC \BL[2] \SR
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \HL
-%D \BC \BC \BL \SR
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \HL
-%D \BC \BL \SR
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \BL \BL \SR
-%D \HL
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-
-%D In these examples we can clearly see that for being a real
-%D background, the color or gray specification has to precede
-%D the content. Just to keep things simple, we can recall this
-%D specification later on:
-%D
-%D \startbuffer
-%D \starttable[|c|c|c|]
-%D \BC \BL \SR
-%D \HL
-%D \VL test \VL test \VL test \VL\SR
-%D \HL
-%D \BR\FR
-%D \VL test \VL test \VL test \VL\FR
-%D \BR\MR
-%D \VL test \VL test \VL test \VL\MR
-%D \BR\LR
-%D \VL test \VL test \VL test \VL\LR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D Close study learns that we can put the specification
-%D before or after the \type{\HL}, whatever suits best. Keeping
-%D track of these specifications is taken care of by the next
-%D variables:
-
-\newif \ifTABLEgrayline % executing gray line
-\newif \ifTABLEgraydone % gray line executed
-\newtoks \TABLEgraytoks % gray line specification
-
-\newif\ifTABLEinbreak
-
-%D Nog vervangen:
-
-\def\c!Table{Table}
-\def\m!TABLE{TABLE}
-
-%D We already saw that the table macros report errors and
-%D provide automatic spacing. These features can only be
-%D implemented by keeping track of the state, often the last
-%D command on a row.
-
-\chardef\TABLEunknown = 0
-
-\chardef\TABLEseparaterow = 1
-\chardef\TABLEfirstrow = 2
-\chardef\TABLEmidrow = 3
-\chardef\TABLElastrow = 4
-\chardef\TABLErule = 5
-\chardef\TABLEskip = 6
-\chardef\TABLEautorow = 7
-
-\chardef\TABLEforcefirstrow = 1
-\chardef\TABLEforcelastrow = 2
-
-\chardef\TABLEmissingrow = 1
-\chardef\TABLEmissingcolumn = 2
-\chardef\TABLEspanoverflow = 3
-\chardef\TABLEdivisionoverflow = 4
-
-%D We store these states using efficient \type {\chardef}'s.
-%D Like most variables, these are global ones. When needed,
-%D especially when we flush the backgrounds, we can temporary
-%D disable the assignment.
-
-\newif\ifsetTABLEaction
-
-\def\setTABLEaction#1%
- {\ifsetTABLEaction\global\chardef\TABLEaction#1\fi}
-
-\def\setTABLEforce#1%
- {\ifsetTABLEaction\global\chardef\TABLEforce#1\fi}
-
-\def\setTABLEerror#1%
- {\global\chardef\TABLEerror#1}
-
-%D Before we come to using these variables, we redefine and/or
-%D adapt some \TABLE\ macros. Within \TABLE's the \type{|} and
-%D \type{"} have special meanings in templates and are active
-%D during. Their meaning can therefore conflict with those
-%D elsewhere defined. To be compatible with traditional \TABLE\
-%D as well as \CONTEXT's \type{||} and the active \type{"}
-%D extensions for my german friends, we do some catcode magic.
-
-\newif\ifForgetTableBarAndQuote \ForgetTableBarAndQuotetrue
-
-% \bgroup
-
-% \catcode`\|=\@@active
-% \catcode`\"=\@@active
-%
-% \gdef\pushouterbarandquote
-% {\ifForgetTableBarAndQuote
-% \ifnum\catcode`\|=\@@active \let\outertablebar |\else\let\outertablebar \relax\fi
-% \ifnum\catcode`\"=\@@active \let\outertablequote"\else\let\outertablequote\relax\fi
-% \let|\letterbar
-% \let"\letterdoublequote
-% \fi}
-%
-% \gdef\popouterbarandquote
-% {\ifForgetTableBarAndQuote
-% \ifx\outertablebar \relax\else\let|\outertablebar \fi
-% \ifx\outertablequote\relax\else\let"\outertablequote\fi
-% \else
-% \redefinetablebarandquote
-% \fi}
-%
-% \egroup
-%
-% \def\ObeyTableBarAndQuote
-% {\ForgetTableBarAndQuotefalse
-% \ifintable
-% \redefinetablebarandquote
-% \fi}
-
-\let\ActivateBarAndQuote \relax
-\let\ObeyTableBarAndQuote\relax
-\let\pushouterbarandquote\relax
-\let\popouterbarandquote \relax
-
-%D \macros
-%D {ObeyTableBarAndQuote}
-%D
-%D As said, the \type{|} and \type{"} active characters are
-%D often used for other purposes. By default, the outside
-%D meanings are therefore preserved and available inside
-%D tables. If for some reason one wants to use the \TABLE\
-%D primitives, one can say:
-%D
-%D \starttyping
-%D \ObeyTableBarAndQuote
-%D \stoptyping
-%D
-%D To keep things verbose, as well as to show what \TABLE\
-%D commands we affect, we show some meanings.
-
-\def\normalTABLEshortrule {\!ttShortHrule} % \-
-\def\normalTABLElongrule {\!ttLongHrule} % \=
-\def\normalTABLEfullrule {\!ttFullHrule} % \_
-\def\normalTABLEendofrow {\!ttEndOfRow} % \\
-\def\normalTABLEsimplebar {\unskip\!ttRightGlue&&} % |
-\def\normalTABLEcomplexbar {\unskip\!ttRightGlue&\omit\!ttAlternateVrule} % \|
-\def\normalTABLEquote {\unskip\!ttRightGlue&\omit&} % "
-\def\normalTABLElineformat {\normalTABLEendofrow+}
-\def\normalTABLElineending {\normalTABLEendofrow0 }
-\def\normalTABLEsinglerule {&\normalTABLElongrule&}
-\def\normalTABLEmultirule#1{&\use{#1}\normalTABLElongrule&}
-
-%D The next hack is dedicated to Tobias, who found out that
-%D paragraph entries don't break well.
-
-\def\TABLEhack{\hskip\zeropoint}
-
-%D The first attemp to solve this problem was:
-%D
-%D \starttyping
-%D \def\normalTABLEquote%
-%D {\unskip\TABLEhack\!ttRightGlue&\omit&\TABLEhack}
-%D \stoptyping
-%D
-%D But, as usual, this interfered with \type {\omit}.
-%D
-%D The next attempt is redefining some core \TABLE\ macro:.
-%D This works ok, but breaks for instance the~\type{b}
-%D key handling.
-%D
-%D \starttyping
-%D \def\!tfAdjoinPriorColumn%
-%D {\ifnum\!taColumnNumber=0
-%D \!taPreamble=\!taRuleColumnTemplate
-%D ...
-%D \if!taOnceOnlyTabskip
-%D \!thToksEdef\!taDataColumnTemplate=
-%D {\TABLEhack####\TABLEhack\tabskip\the\!taLastRegularTabskip}
-%D \else
-%D \!taDataColumnTemplate{\TABLEhack##\TABLEhack}%
-%D \fi
-%D ...
-%D \ReadFormatKeys}
-%D \stoptyping
-
-% \newdimen\TABLEparheight
-
-\def\BeginTableParBox#1%
- {\setbox\scratchbox\vtop\bgroup % \setbox added
- \hsize#1\relax
- \normalbaselines
- \let~\!ttTie
- \let\-\!ttDH
- \blank[\v!disable]% % added
- \the\EveryTableParBox}
-
-\def\EndTableParBox
- {\removelastskip % itemize or so
- \endgraf
- \ifnum\prevgraf>\zerocount % we want at least
- \verticalstrut \nowhitespace \vskip-\struttotal% one line of text
- \egroup
- \ifdim\dp\scratchbox>\lineheight % see (*) for an
- \getnoflines{\dp\scratchbox}% % example of where
- \dp\scratchbox\zeropoint % saving can go
- \setbox\scratchbox % terrible wrong
- \vtop to \noflines\lineheight{\box\scratchbox}%
- \fi % esp between rows
- \else % of paragraphs
- \egroup
- \fi
-% \getboxheight\scratchdimen\of\box\scratchbox\relax% compensate for
-% \ifdim\scratchdimen>\TABLEparheight % funny depth of
-% \global\TABLEparheight\scratchdimen % multi-line box
-% \fi % i.e. vtop
- \box\scratchbox}
-
-% We also need to patch away the interfering math switch:
-
-% \mathpunctuationtrue
-
-% test, test
-% \starttable[|c|]
-% \NC1,,10\NC\AR
-% \stoptable
-% test, test
-
-\def\!ttBeginTableA[#1]{%
- \if #1u% % "unboxed" table
- \ifmmode
- \def\!ttEndTable{% % user had better be in display math mode
- \relax}% % and have only one table at the outer level
- \else % user had better be in vertical mode
- \bgroup
- \def\!ttEndTable{%
- \egroup}%
- \fi
- \else
- %\hbox\bgroup $
- %\def\!ttEndTable{%
- % \egroup % for the \vtop, \vbox, or \vcenter, yet to come
- % $% for math mode
- % \egroup}% for the \hbox
- %\if #1t%
- % \vtop
- %\else
- % \if #1b%
- % \vbox
- % \else
- % \vcenter % math mode was essential for this
- % \fi
- %\fi
- %
- \hbox\bgroup
- \def\!ttEndTable{\egroup\egroup}%
- \if#1t%
- \vtop
- \else\if#1b%
- \vbox
- \else
- \def\!ttEndTable{\egroup$\egroup}%
- %$\vcenter
- \scratchtoks\everymath\everymath\emptytoks$\everymath\scratchtoks\vcenter
- \fi\fi
- %
- \bgroup % for the \vtop, \vbox, or \vcenter
- \fi
- \advance\!taRecursionLevel 1 % RecursionLevel governs initialization
- \let\!ttRightGlue=\relax % This may be changed by \JustCenter, etc
- \everycr\emptytoks % ={}
- \ifnum \!taRecursionLevel=1
- \!ttInitializeTable
- \fi}
-
-%D The next redefinition is more robust than the original:
-
-\def\SetTableToWidth#1%
- {\doifelsenothing{#1}{\!taTableSpread\emptytoks}{\!taTableSpread{to #1}}}
-
-% (*) Try this one with \type {direction} and {girection};
-% the \PPCHTEX\ manual is a nice testcase.
-%
-% \startoverlay
-% {\starttable[ | l w(2cm) | w(8cm) | ]
-% \HL
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \FR
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \MR
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \LR
-% \HL
-% \stoptable}
-% {\starttable[ | l w(2cm) | p(8cm) | ]
-% \HL
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \FR
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \MR
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \LR
-% \HL
-% \stoptable}
-% \stopoverlay
-% \vskip2cm
-% \starttable[ | l w(2cm) | p(8cm) | ]
-% \HL
-% \VL direction \VL \showbaselines \dorecurse{3}{direction }\VL \FR
-% \VL direction \VL \showbaselines \dorecurse{8}{direction }\VL \LR
-% \HL
-% \stoptable
-% \vskip2cm
-% \starttable[ | l w(2cm) | p(8cm) | ]
-% \HL
-% \VL direction \VL \showbaselines \dorecurse{8}{direction }\VL \FR
-% \VL direction \VL \showbaselines \dorecurse{8}{direction }\VL \LR
-% \HL
-% \stoptable
-
-%D To give an impression of what the (well documented) source
-%D of \TABLE\ looks like, we first implement an alternative for
-%D the numeric keys. The quantity keys (\type{q} and \type{Q})
-%D support the more european way of writing numbers:
-%D
-%D \startnarrower
-%D 100.000.000,00 instead of 100,000,000.00
-%D \stopnarrower
-%D
-%D The next table shows how to use these keys. We use braces
-%D instead of brackets because we need brackets to specify the
-%D format.
-%D
-%D \startbuffer
-%D \starttable{|q[00,000]|Q[00,00]|}
-%D \HL
-%D \VL -1,2 \VL 12,35 \VL\FR
-%D \VL 11,203 \VL 2,4 \VL\LR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-%D
-%D Although a more efficient implementation is possible |<|we
-%D can for instance share common macros|>| we just adapt a copy
-%D of the numeric ones. To permit double loading of this
-%D module, we check for the existence of one of the macros.
-
-\letvalue{!tk<\string q>}=\undefined
-\letvalue{!tk<\string Q>}=\undefined
-
-%D We just copy the original {\em comments}.
-%D
-%D \em Key \type{q}: quantity item, non||math mode.
-
-\NewFormatKey q%
- {\letempty\!tqStyle
- \futurelet\!tnext\!tqTestForBracket}
-
-%D \em Key \type{Q}: quantity item, math mode.
-
-\NewFormatKey Q%
- {\def\!tqStyle{$}%
- \futurelet\!tnext\!tqTestForBracket}
-
-%D \em Note: the space between a quantity entry and the
-%D following \type{|}, \type{"}, or \type{\|} is mandatory.
-%D empty quantity entries are not allowed: use \type{{}} or
-%D \type{\omit} instead.
-%D
-%D \em Test for bracket: invoked by the keys \type{q} and
-%D \type{Q}.
-
-\def\!tqTestForBracket
- {\ifx[\!tnext
- \!thx\!tqGetArgument
- \else
- \!thx\!tqGetCode
- \fi}
-
-%D \em Get code: e.g. \type{4}, or \type{4,0}, \type{0,4}, or
-%D \type{10,2}.
-
-\def\!tqGetCode#1 % note the blank
- {\!tqConvertCode #1,,!}
-
-%D \em Convert code: e.g. converts above to \type{[0000]},
-%D \type{[0000,]}, \type{[,0000]}, \type{[0000000000,00]}.
-
-\def\!tqConvertCode #1,#2,#3!%
- {\begingroup
- \aftergroup\edef
- \aftergroup\!ttemp
- \aftergroup{%
- \aftergroup[%
- \!taCountA #1
- \!thLoop
- \ifnum \!taCountA>\zerocount
- \advance\!taCountA \minusone
- \aftergroup0
- \repeat
- \def\!ttemp{#3}%
- \ifx\!ttemp\empty
- \else
- \aftergroup,
- \!taCountA #2
- \!thLoop
- \ifnum\!taCountA>\zerocount
- \advance\!taCountA \minusone
- \aftergroup0
- \repeat
- \fi
- \aftergroup]\aftergroup}%
- \endgroup\relax
- \!thx\!tqGetArgument\!ttemp}
-
-%D \em Get argument:
-%D
-%D \starttyping
-%D
-%D \stoptyping
-
-\def\!tqGetArgument[#1]%
- {\!tqMakeQuantityTemplate\!tqStyle#1,,!}
-
-%D \em Make quantity template.
-
-\def\!tqMakeQuantityTemplate#1#2,#3,#4!% #1= or $
- {\def\!ttemp{#4}%
- \ifx\!ttemp\empty
- \!taDimenC\zeropoint
- \else
- \setbox0\hbox{\m@th #1,#3#1}%
- \!taDimenC\wd0
- \fi
- \setbox0\hbox{\m@th #1#2#1}%
- \!thToksEdef\!taDataColumnTemplate
- ={\noexpand\!tqSetQuantityItem{\the\wd0 }{\the\!taDimenC}{#1}%
- \the\!taDataColumnTemplate}%
- \ReadFormatKeys}
-
-%D \em Set numeric item.
-
-\def\!tqSetQuantityItem #1#2#3#4 %
- {\!tqSetQuantityItemA{#1}{#2}{#3}#4,,!}
-
-\def\!tqSetQuantityItemA #1#2#3#4,#5,#6!%
- {\def\!ttemp{#6}%
- \hbox to #1{\hss\m@th#3#4#3}%
- \hbox to #2{\ifx\!ttemp\empty\else\m@th#3,#5#3\fi\hss}}
-
-%D Here ends the Q||extension. Did you watch the clever use
-%D of aftergroup in \type{\!tqConvertCode}.
-
-% %D We also (have to) define a key for \type{\cap}:
-%
-% \letvalue{!tk<\string K>}=\undefined
-%
-% \NewFormatKey K%
-% {\ReadFormatKeys b\smallcapped}
-
-%D A few pages back we saw backgrounds, further on we will see
-%D colored rules, and here we provide a means to color the
-%D entries in a column. (We can of course always use the normal
-%D color commands for individual entries.) We could not use the
-%D lowercase~\type{c}, because that one is used to force {\em
-%D centering}.
-%D
-%D \startbuffer
-%D \starttable[|C{red}|C{green}|C{blue}|]
-%D \VL R(ed) \VL G(reen) \VL B(lue) \VL\SR
-%D \stoptable
-%D \stopbuffer
-%D
-%D \ShowExample
-
-\letvalue{!tk<\string C>}=\undefined
-
-\NewFormatKey C#1%
- {\ReadFormatKeys b{\localstartcolor[#1]} a{\localstopcolor}}
-
-%D So now we have three new keys:
-%D
-%D \starttable[|||]
-%D \HL
-%D \NC \bf key \NC \bf meaning \NC\AR
-%D \HL
-%D \NC Q[x,y] \NC math mode formatted numbers \NC\AR
-%D \NC q[x,y] \NC text mode formatted numbers \NC\AR
-%D \NC C{identifier} \NC column entry color \NC\AR
-%D \HL
-%D \stoptable
-
-%D To be compatible with the tabulate environment, we also
-%D support the \type {l}, \type {c} and \type {r} keys for
-%D paragraph entries.
-
-\letvalue{!tk<\string l>}=\undefined
-\letvalue{!tk<\string c>}=\undefined
-\letvalue{!tk<\string r>}=\undefined
-\letvalue{!tk<\string x>}=\undefined % not that needed
-
-\NewFormatKey c%
- {\prependtoks\raggedcenter\to\!taDataColumnTemplate
- \ReadFormatKeys \LeftGlue\hfil \RightGlue\hfil}
-
-\NewFormatKey l%
- {\prependtoks\raggedright\to\!taDataColumnTemplate
- \ReadFormatKeys \LeftGlue\empty \RightGlue\hfil}
-
-\NewFormatKey r%
- {\prependtoks\raggedleft\to\!taDataColumnTemplate
- \ReadFormatKeys \LeftGlue\hfil \RightGlue\empty}
-
-\NewFormatKey x%
- {\prependtoks\notragged\to\!taDataColumnTemplate
- \ReadFormatKeys \LeftGlue\hfil \RightGlue\empty}
-
-\appendtoks \TABLEparalignment \to \EveryTableParBox
-
-\def\!tfReFormat#1%
- {\the \!taLeftGlue
- \vbox{\forgetall\ialign{\span\the\!taDataColumnTemplate\cr#1\cr}}%
- \the \!taRightGlue
- \kern\zeropoint} % prevents \unskip / really needed
-
-%D Later on, we're going to implement multiple page table
-%D support, therefore the next \TABLE\ macro needs to be
-%D slightly adapted, i.c. the penalty is removed. We also
-%D add basic color support.
-
-\def\!ttFullHruleA
- {\!ttGetHalfRuleThickness
- \startglobalTABLEcolor % added
- \hrule\!thHeight\dimen0\!thDepth\dimen0
- \stopglobalTABLEcolor % added
- %\penalty0 % removed
- \egroup}
-
-%D We'll see that when we want to give a vertical rule a color,
-%D we have to set and reset states. After heavy testing it
-%D proved most useful to extend a \TABLE\ primitive with some
-%D hooks. One thing to keep in mind is that \type{&} keeps
-%D assignments local. Again, we add basic color support.
-
-\let\TABLEbeforebar\empty
-\let\TABLEafterbar \empty
-
-\def\@VLn{1}
-\def\@VLd{.125em}
-
-\def\do!ttInsertVrule % will be merged in 2005
- {\vrule \!thWidth
- \ifnum\!tgCode=\plusone
- \ifx\!tgValue\empty
- \LineThicknessFactor
- \else
- \!tgValue
- \fi
- \LineThicknessUnit
- \else
- \!tgValue
- \fi
- \hskip\@VLd}
-
-\def\!ttInsertVrule
- {\hfil
- \TABLEbeforebar % added
- \startglobalTABLEcolor % added
- % we could do without this speedup, some day merge 'm
- \ifcase\@VLn\or
- \do!ttInsertVrule
- \unskip
- \else
- \dorecurse\@VLn\do!ttInsertVrule
- \gdef\@VLn{1}%
- \unskip
- \fi
- \stopglobalTABLEcolor % added
- \TABLEafterbar % added
- \hfil
- &}
-
-%D The next two macros are only adapted to basis rule
-%D color support.
-
-\def\!tfSetVrule
- {\!thToksEdef\!taRuleColumnTemplate=
- {\noexpand\hfil
- \noexpand\startglobalTABLEcolor % added
- \noexpand\vrule
- \noexpand\!thWidth
- \ifnum\!tgCode=\plusone
- \ifx\!tgValue\empty
- \the\LineThicknessFactor
- \else
- \!tgValue
- \fi
- \!taLTU
- \else
- \!tgValue
- \fi
- ####%
- \noexpand\hfil
- \noexpand\stopglobalTABLEcolor % added
- \the\!taRuleColumnTemplate}%
- \!tfAdjoinPriorColumn}
-
-\def\!ttShortHruleA
- {\!ttGetHalfRuleThickness
- \startglobalTABLEcolor % added
- \leaders\hrule\!thHeight\dimen0\!thDepth\dimen0\hfill
- \stopglobalTABLEcolor % added
- \null
- \ignorespaces}
-
-%D We already showed the next one, but here we slightly adapt
-%D the macro by adding an \type{\expandafter}. The space after
-%D \type{#1} is crucial!
-
-\def\normalTABLEcomplexbar#1%
- {\unskip\!ttRightGlue&\omit\expandafter\!ttAlternateVrule#1 }
-
-%D To get rid of interfering \type{\omit}'s when we are
-%D checking the number of columns and reporting problems. The
-%D extensions concern the second level check, the first
-%D subbranch and advancing the column.
-
-\ifx\mscount\undefined \newcount\mscount \fi
-
-\def\!ttuse#1%
- {\ifnum#1>\plusone
- \omit
- \global\TABLEdivisionfalse
- \scratchcounter\currentTABLEcolumn % added
- \advance\scratchcounter #1% % added
- \advance\scratchcounter \minusone % added
- \ifnum\scratchcounter>\maxTABLEcolumn % added
- \def\next % added
- {\setTABLEerror\TABLEspanoverflow % added
- \handleTABLEerror}% % added
- \else % added
- \def\next % added
- {\global\advance\currentTABLEcolumn #1% % added
- \global\advance\currentTABLEcolumn \minusone % added
- \mscount#1% \mscount is in Plain
- \advance\mscount \minusone
- \advance\mscount \mscount
- \!thLoop
- \ifnum\mscount>\plusone
- \sp@n % from Plain (\span\omit \advance\mscount\m@ne)
- \repeat
- \span}%
- \fi % added
- \else % added
- \def\next % conflicts with possible next \omit % added
- {\global\advance\currentTABLEcolumn \plusone}% % added
- \fi
- \next} % added
-
-% \starttable[|c|c|c|c|]
-% \HL
-% \VL {test} \VL \TWO{} \VL test \VL\FR
-% \DL \DC \DL\DR
-% \VL {test} \VL \TWO{} \VL test \VL\LR
-% \HL
-% \stoptable
-
-%D All commands that are executed between rows are to be put in
-%D \type {\noalign}. We can however not verify if we (that is
-%D \TABLE) does or did not enter this mode. A moderate dirty
-%D but useful trick is using our own alternative:\footnote{Once
-%D one has entered the stage of redefining \TEX\ primitives,
-%D such hacks become a second nature. However, redefining \type
-%D {\omit} and \type{\span} is not that easy.}
-
-\def\TABLEnoalign
- {\noalign\bgroup\let\noalign\relax\let\next=}
-
-%D \macros
-%D {starttable}
-%D
-%D The rest of this module is not easy to comprehend, mainly
-%D because we have to take care of:
-%D
-%D \startitemize[packed]
-%D \item \type{\startitemize[template]}
-%D \item \type{\startitemize{template}}
-%D \item \type{\startitemize[predefined]}
-%D \stopitemize
-%D
-%D as well as:
-%D
-%D \startitemize[continue]
-%D \item restart after table break
-%D \stopitemize
-%D
-%D The official specification of the start command is:
-%D
-%D \showsetup{starttable}
-
-\newconditional\tablerepeathead
-\newconditional\tablerepeattail
-
-\def\starttable
- {\bgroup
- \doif\@@tisplit\v!auto
- {\ifinsidesplitfloat\let\@@tisplit\v!yes\fi}%
- \doifinsetelse\@@tisplit{\v!yes,\v!repeat}
- {\def\stoptable{\stoptables\egroup}%
- \starttables}
- {\doifelsenothing\@@tiframe
- {\ifinsidefloat\else\startbaselinecorrection\fi}
- {\startframedcontent[\@@tiframe]}%
- \postponefootnotes
- \firststagestartTABLE}}
-
-\def\stoptable
- {\chuckTABLEautorow % before the tail, else noalign problem
- \insertTABLEtail
- \TABLEnoalign{\globalletempty\@@TABLEhead}%
- \TABLEnoalign{\globalletempty\@@TABLEtail}%
- \finishTABLE
- \doifelsenothing\@@tiframe
- {\ifinsidefloat\else
- \stopbaselinecorrection
- \goodbreak % compensates all the nobreaks
- \fi}
- \stopframedcontent
- \egroup}
-
-%D Before we can grab the argument, we have to make sure that
-%D the \CATCODES\ are set. The first stage takes care of that.
-
-\def\firststagestartTABLE
- {\bgroup % kan-ie weg?
- \global\intabletrue
- \pushouterbarandquote
- %catcode`\|=\@@other
- \complexorsimple\secondstagestartTABLE}
-
-\def\simplesecondstagestartTABLE#1%
- {\complexsecondstagestartTABLE[{#1}]}
-
-%D \macros
-%D {definetabletemplate}
-%D
-%D The complex (and main) start macro first takes care of the
-%D predefined case. Such a predefined setup looks like:
-%D
-%D \starttyping
-%D \definetabletemplate[test][|||]
-%D
-%D \starttable[test]
-%D \VL test \VL test \VL\AR
-%D \VL test \VL test \VL\AR
-%D \VL test \VL test \VL\AR
-%D \stoptable
-%D \stoptyping
-%D
-%D The implementation of the definition macro is not that
-%D complicated:
-
-\def\definetabletemplate % to be redone
- {\bgroup
- \catcode`\|=\@@other
- \doquadrupleempty\dodefinetabletemplate}
-
-\def\dodefinetabletemplate[#1][#2][#3][#4]%
- {\ifsecondargument
- \setgvalue{\c!Table#1}{\douseTABLEtemplate{#2}{#3}{#4}}%
- \fi
- \egroup}
-
-\def\douseTABLEtemplate#1#2#3%
- {\gdef\TABLEhead{\getvalue{@@TABLEhead#2}}%
- \gdef\TABLEtail{\getvalue{@@TABLEtail#3}}%
- \complexsecondstagestartTABLE[#1]}
-
-%D The optional third and fourth arguments define which table
-%D head and tail to use.
-%D
-%D \starttyping
-%D \definetabletemplate[test][|||][before][after]
-%D \stoptyping
-%D
-%D This also means that one can define table heads and tails
-%D by name!
-%D
-%D \starttyping
-%D \starttablehead[before]
-%D \HL \VL first \VL second \VL \SR \HL
-%D \stoptablehead
-%D \stoptyping
-%D
-%D Templates defined this way get protected names, that cannot
-%D conflict with existing commands.
-%D
-%D \showsetup{definetabletemplate}
-%D
-%D The second half of the next macro prepares table
-%D splitting.
-
-\def\insertTABLEhead
- {\TABLEnoalign{\global\settrue \preventTABLEbreak \global\setfalse\someTABLEhead}%
- \TABLEhead
- \TABLEnoalign{\global\setfalse\preventTABLEbreak}}
-
-\def\insertTABLEtail
- {\TABLEnoalign{\global\settrue \preventTABLEbreak \global\setfalse\someTABLEtail}%
- \TABLEtail
- \TABLEnoalign{\global\setfalse\preventTABLEbreak}}
-
-% \def\dorestartTABLE#1%
-% {\gdef\restartTABLE{#1}%
-% \restartTABLE
-% \insertTABLEhead
-% \ifsplittables \ifconditional \tablerepeattail
-% \TABLEnoalign{\goodbreak}%
-% \insertTABLEtail
-% \TABLEnoalign{\goodbreak}%
-% \fi \fi}
-
-\def\verysimpleTableHL
- {\TABLEnoalign{\expandafter\normalTABLEfullrule\@@tiHLheight}}
-
-\def\dorestartTABLE#1%
- {\gdef\restartTABLE{#1}%
- \restartTABLE
- \TABLEnoalign{\globalpushmacro\simpleTableHL\global\let\simpleTableHL\verysimpleTableHL}%
- \insertTABLEhead
- \ifsplittables \ifconditional \tablerepeattail
- \TABLEnoalign{\goodbreak}%
- \insertTABLEtail
- \TABLEnoalign{\goodbreak}%
- \fi \fi
- \TABLEnoalign{\globalpopmacro\simpleTableHL}}
-
-\bgroup \catcode`|=\@@other \catcode`"=\@@other
-
-\gdef\complexsecondstagestartTABLE#1[#2]% brr nested mess
- {\bgroup
- \@@useotherbar
- \@@useotherquote
- \global\setfalse\someTABLEhead
- \global\setfalse\someTABLEtail
- \expanded{\doifinstringelse{|}{#2}}
- {\xdef\restartTABLE{\noexpand\dorestartTABLE{\noexpand\thirdstagestartTABLE{#2}}}}
- {\doifdefinedelse{\c!Table#2}
- {\gdef\restartTABLE{\getvalue{\c!Table#2}}}
- {\gdef\restartTABLE{\dorestartTABLE{\getvalue{#2}}}}}%
- \egroup
- \restartTABLE}
-
-\egroup
-
-%D The third stage involves a lot of (re)sets, which we will
-%D explain later.
-
-%D The next definition is convenient and more in tune with
-%D \CONTEXT.
-
-\let \everytable \EveryTable
-
-%D We immediately use this register:
-
-\appendtoks
- \fixedspaces
- \let\_\normalunderscore
-\to \everytable
-
-%D Now we can start the table.
-
-\def\thirdstagestartTABLE#1%
- {\global\setTABLEactiontrue
- \setTABLEaction\TABLEunknown
- \setTABLEforce\TABLEunknown
- \setTABLEerror\TABLEunknown
- \global\TABLEgraylinefalse
- \global\TABLEgraydonefalse
- \globalletempty\TABLEgrayline
- \globalletempty\nextTABLEgrayline
- \globalletempty\TABLEgraylineerror
- \globalletempty\TABLEgraylinestatus
- \resetVLvalues
- \appendtoks\popouterbarandquote\to\EveryTable
- \appendtoks\localTABLEsetup\to\EveryTable
- \BeginTable[\ifsplittables u\else b\fi]%
- \defineTABLEunits
- \defineTABLEsteps
- \defineTABLErules
- \defineTABLEdivisions
- \defineTABLEshorthands
- \defineTABLEbackgrounds
- \defineTABLEendings
- \forgetall % added
- \doifsomething{#1}
- {\def\TABLEformat{#1}%
- \getTABLEnofcolumns\TABLEformat
- % more modern is to use catcode tables
- \expandafter\BeginFormat\TABLEformat\EndFormat}}
-
-\def\finishTABLE
- {\chuckTABLEautorow
- \unskip\crcr
- \EndTable
- \global\intablefalse
- \egroup}
-
-%D \macros
-%D {starttables}
-%D
-%D Split tables are specified using the plural form of the
-%D start and stop commands.
-%D
-%D \showsetup{starttables}
-%D
-%D For example:
-%D
-%D \starttyping
-%D \starttables[|||]
-%D \HL
-%D \VL element \VL atom weight \VL\AR
-%D \HL
-%D \VL ....... \VL ........... \VL\AR
-%D \VL ....... \VL ........... \VL\AR
-%D \HL
-%D \stoptables
-%D \stoptyping
-
-\newbox\tablecontentbox
-
-\def\starttables
- {\bgroup
- \splittablestrue
- \doifelse\@@tisplit\v!repeat
- {\settrue \tablerepeathead\settrue \tablerepeattail}
- {\setfalse\tablerepeathead\setfalse\tablerepeattail}%
- \flushnotes
- \setbox\tablecontentbox\vbox\bgroup
- \forgetall
- \global\TABLEinbreakfalse
- \firststagestartTABLE}
-
-% \def\stoptables
-% {\ifconditional\tablerepeattail\else\insertTABLEtail\fi
-% \finishTABLE
-% \egroup
-% \dosplittablebox\tablecontentbox
-% \flushnotes
-% \egroup}
-
-\def\stoptables
- {\chuckTABLEautorow % AM: before the tail, else noalign problem
- \ifconditional\tablerepeattail\else\insertTABLEtail\fi
- \finishTABLE
- \egroup
- \dosplittablebox\tablecontentbox
- \flushnotes
- \egroup}
-
-\newdimen\TABLEcaptionheight % obsolete
-
-\def\dosplittablebox#1%
- {\resettsplit
- \def\tsplitminimumfreelines{2}%
- \def\tsplitminimumfreespace{\TABLEcaptionheight}%
- \setbox\tsplitcontent\box#1%
- \ifconditional\tablerepeathead \ifconditional\someTABLEhead
- \setbox\tsplithead\vsplit\tsplitcontent to \lineheight
- \setbox\tsplithead\vbox{\unvbox\tsplithead}%
- \fi \fi
- \ifconditional\tablerepeattail \ifconditional\someTABLEtail
- \setbox\tsplittail\vsplit\tsplitcontent to \lineheight
- \setbox\tsplittail\vbox{\unvbox\tsplittail}%
- \fi \fi
- \ifinsidefloat\else
- \def\tsplitbeforeresult{\startbaselinecorrection}%
- \def\tsplitafterresult {\stopbaselinecorrection}%
- \fi
- \handletsplit}
-
-%D When the table in the previous example is split across
-%D pages, only the first gets a head. We could have said
-%D something like:
-%D
-%D \starttyping
-%D \starttablekop
-%D \HL
-%D \VL element \VL atom weight \VL\AR
-%D \HL
-%D \stoptablekop
-%D
-%D \starttablestaart
-%D \HL
-%D \stoptablestaart
-%D
-%D \starttables[|||]
-%D \VL ....... \VL ........... \VL\AR
-%D \VL ....... \VL ........... \VL\AR
-%D \stoptables
-%D \stoptyping
-%D
-%D This time each split table gets a head line and ends with
-%D a rule. Keep in mind that such heads also apply to the
-%D unbroken ones and should be defined local (grouped) if
-%D needed. The rather complicated definition below is due to
-%D the fact that the stopcondition is interface language
-%D dependant.
-
-\let\@@TABLEhead\empty \def\TABLEhead{\@@TABLEhead}
-\let\@@TABLEtail\empty \def\TABLEtail{\@@TABLEtail}
-
-\letvalue{\e!start\v!tablehead}=\undefined
-\letvalue{\e!stop \v!tablehead}=\undefined
-\letvalue{\e!start\v!tabletail}=\undefined
-\letvalue{\e!stop \v!tabletail}=\undefined
-
-\expanded
- {\def\csname\e!start\v!tablehead\endcsname##1\csname\e!stop\v!tablehead\endcsname%
- {\noexpand\setTABLEhead##1\noexpand\end}}
-
-\expanded
- {\def\csname\e!start\v!tabletail\endcsname##1\csname\e!stop\v!tabletail\endcsname%
- {\noexpand\setTABLEtail##1\noexpand\end}}
-
-%D The second argument is a dummy one, by scanning for it, we
-%D get rid of interfering spaces.
-
-\def\setTABLEhead{\dodoubleempty\dosetTABLEhead}
-\def\setTABLEtail{\dodoubleempty\dosetTABLEtail}
-
-\newconditional\preventTABLEbreak
-\newconditional\someTABLEhead
-
-\def\dosetTABLEhead[#1][#2]#3\end{\setvalue{@@TABLEhead#1}{\TABLEnoalign{\global\settrue\someTABLEhead}#3}}
-\def\dosetTABLEtail[#1][#2]#3\end{\setvalue{@@TABLEtail#1}{\TABLEnoalign{\global\settrue\someTABLEtail}#3}}
-
-%D Redudant \type{\HL}'s are removed automatically, so
-%D mid||lines can be used without problems.
-
-%D We need an alternative for the normal complex or simple
-%D commands, because assignments in these system commands
-%D conflict with \type{\noalign}. This alternative is about
-%D as efficient as possible.
-
-\def\complexorsimpleTable#1#2%
- {\csname\if[\noexpand#2\s!complex\else\s!simple\fi\c!Table#1\endcsname#2}
-
-%D The next one is used in \type{\VL} cum suis and honours
-%D the next grouping.
-
-\def\docomplexorsimpleTable#1#2%
- {\ifx\next\bgroup\@EA#2\else\@EA\dodocomplexorsimpleTable\@EA#1\@EA#2\fi}
-
-\def\dodocomplexorsimpleTable#1#2#3%
- {\if[\noexpand#3\@EA#1\else\@EA#2\fi#3}
-
-%D The order of the next macros is more or less random. First
-%D we implement error recovery. Errors are reported to the
-%D screen and log file as well as visualized in the table in
-%D teletype.
-
-\def\handleTABLEerror
- {\ifTABLEgrayline \else
- \ifnum\TABLEerror=\TABLEunknown \else
- \setTABLEaction\TABLEunknown
- \globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow
- \fi
- \ifcase\TABLEerror
- % no error
- \or
- % \TABLEmissingrow
- \tttf [missing row]%
- \writestatus\m!TABLE{missing row}%
- \SR
- \or
- % \TABLEmissingcolumn
- \fillTABLEcolumns
- \tttf [missing column]%
- \writestatus\m!TABLE{missing column}%
- \SR
- \or
- % \TABLEspanoverflow
- \fillTABLEcolumns
- \tttf [columnspan too large]%
- \writestatus\m!TABLE{columnspan too large}%
- \SR
- \or
- % \TABLEdivisionoverflow
- \fillTABLEcolumns
- \tttf [division line too long]%
- \writestatus\m!TABLE{division line too long}%
- \SR
- \fi
- \fi
- \ifnum\TABLEerror=\TABLEunknown \else
- \finishTABLErow
- \fi}
-
-\def\finishTABLErow
- {\crcr
- \TABLEnoalign
- {\nobreak
- \setTABLEaction\TABLEunknown
- \setTABLEerror\TABLEunknown
- \globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow
- \global\currentTABLEcolumn\zerocount}}
-
-\def\fillTABLEcolumns
- {\ifnum\currentTABLEcolumn>\maxTABLEcolumn \else
- \global\advance\currentTABLEcolumn \plusone
- \normalTABLEquote
- \expandafter\fillTABLEcolumns
- \fi}
-
-%D Next we enter the more complicated area of column and row
-%D switching. I won't go into much detail from now on, but just
-%D mention the general principles.
-%D
-%D \startitemize[3*ruim]
-%D \sym{\type{\SR}} end a separate row (between rules)
-%D \sym{\type{\FR}} end a first row (after a rule)
-%D \sym{\type{\MR}} end a mid row (between text lines)
-%D \sym{\type{\LR}} end a last row (before a rule)
-%D \stopitemize
-%D
-%D and best of all:
-%D
-%D \startitemize[continue]
-%D \sym{\type{\AR}} end a row with automatic spacing
-%D \stopitemize
-%D
-%D As far as possible, we report confusing situations. In
-%D most cases one can use \type{\AR}, which transfigurates
-%D itself into one of the other types.
-%D
-%D \starttyping
-%D \starttable[||]
-%D \HL
-%D \VL a separate row \VL\SR
-%D \HL
-%D \VL a first row \VL\FR
-%D \VL a mid row \VL\MR
-%D \VL a last row \VL\LR
-%D \HL
-%D \stoptable
-%D \stoptyping
-%D
-%D In this example we could have used \type{\AR} without
-%D problems.
-%D
-%D Color or gray scale backgrounds precede the content. They
-%D are passed over horizontal (division) lines when needed.
-%D Errors in the color template are traced elsewhere. Here we
-%D only check for inconsistent spacing. Due to the way \TEX\
-%D handles alignments, we cannot automate spacing for colored
-%D rows and columns.
-
-\chardef\TABLErowzero=0
-
-\def\checkTABLErow#1% pure for message purposes
- {\unskip % added
- \ifTABLEgraydone
- \defconvertedargument\asciia{#1}%
- \defconvertedcommand \asciib\TABLEendBCL
- \ifx\asciia\asciib \else
- \writestatus\m!TABLE{confusing \asciia\space and \asciib}%
- \gdef\TABLEgraylineerror%
- {\globalletempty\TABLEgraylineerror
- [\asciia\unskip<->\asciib\unskip]}%
- \fi
- \global\TABLEgraydonefalse
- \fi}
-
-\def\defineTABLEendings
- {\let\SR\TableSR
- \let\FR\TableFR
- \let\MR\TableMR
- \let\LR\TableLR
- \let\AR\TableAR}
-
-\def\TableSR
- {\ifTABLEgrayline \else
- \ifnum\TABLEaction=\TABLEfirstrow
- \writestatus\m!TABLE{change \string\SR\space into \string\MR/\string\LR}%
- \else\ifnum\TABLEaction=\TABLEmidrow
- \writestatus\m!TABLE{change \string\SR\space into \string\MR/\string\LR}%
- \else\ifnum\TABLEaction=\TABLEmidrow
- \writestatus\m!TABLE{change \string\SR\space into \string\MR/\string\LR}%
- \fi\fi\fi
- \fi
- \checkTABLErow\SR
- \endTABLErow\TABLEseparaterow\TABLErowfactor\TABLErowfactor}
-
-\def\TableFR
- {\ifTABLEgrayline \else
- \ifnum\TABLEaction=\TABLEmidrow
- \writestatus\m!TABLE{change \string\FR\space into \string\MR/\string\LR}%
- \else\ifnum\TABLEaction=\TABLElastrow
- \writestatus\m!TABLE{change \string\FR\space into \string\MR/\string\LR}%
- \fi\fi
- \fi
- \checkTABLErow\FR
- \endTABLErow\TABLEfirstrow\TABLErowfactor\TABLErowzero}
-
-\def\TableMR
- {\ifTABLEgrayline \else
- \ifnum\TABLEaction=\TABLErule
- \writestatus\m!TABLE{change \string\MR\space into \string\FR/\string\SR}%
- \else\ifnum\TABLEaction=\TABLElastrow
- \writestatus\m!TABLE{change \string\MR\space into \string\FR}%
- \fi\fi
- \fi
- \checkTABLErow\MR
- \endTABLErow\TABLEmidrow00}
-
-\def\TableLR
- {\ifTABLEgrayline \else
- \ifnum\TABLEaction=\TABLErule
- \writestatus\m!TABLE{change \string\LR\space into \string\FR/\string\SR}%
- \fi
- \fi
- \checkTABLErow\LR
- \endTABLErow\TABLElastrow\TABLErowzero\TABLErowfactor}
-
-%D \macros
-%D {ifcheckTABLEcolums}
-%D
-%D
-%D The next macros handle the actual row ending. This macro
-%D also take care of space corrections due to table splitting
-%D when \type{\MR} and collegues are used. When tracing is
-%D enabled, the corrections as well as the values used to
-%D determine the available space are shown (in color). By default
-%D checking is off.
-
-\newif\ifcheckTABLEcolumns
-
-\let\beforeTABLEline\empty
-\let\afterTABLEline \empty
-
-\def\doendTABLErow#1#2#3%
- {\handleTABLEbreak#2#3%
- \beforeTABLEline
- \ifcase#1\relax
- % unknown
- \or
- \endofTABLEline[blue][\SR->\SR]\TABLErowfactor\TABLErowfactor
- \or
- \endofTABLEline[red][\FR->\FR]\TABLErowfactor\TABLErowzero
- \or
- \ifnum\TABLEforce=\TABLEforcelastrow
- \endofTABLEline[red][\MR->\LR]\TABLErowzero\TABLErowfactor
- \else\ifnum\TABLEforce=\TABLEforcefirstrow
- \endofTABLEline[red][\MR->\FR]\TABLErowfactor\TABLErowzero
- \else
- \endofTABLEline[green][\MR->\MR]\TABLErowzero\TABLErowzero
- \fi\fi
- \or
- \endofTABLEline[red][\LR->\LR]\TABLErowzero\TABLErowfactor
- \fi
- \TABLEnoalign
- {\setTABLEforce\TABLEunknown
- \global\currentTABLEcolumn\zerocount}%
- \afterTABLEline}
-
-\def\endTABLErow#1#2#3%
- {\setTABLEaction#1%
- \ifTABLEgrayline
- \finishTABLErow
- \else
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \doendTABLErow{#1}{#2}{#3}%
- \else\ifcheckTABLEcolumns
- \setTABLEerror\TABLEmissingcolumn
- \handleTABLEerror
- \else
- \doendTABLErow{#1}{#2}{#3}%
- \fi\fi
- \fi}
-
-%D Handling \type{\AR} is postponed till the next row. The
-%D check takes care of the first and mid rows, the chuck macro
-%D |<|how about that name|>| handles the last row.
-
-\def\TableAR
- {\ifTABLEgraydone
- \globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow
- \global\TABLEgraydonefalse
- \TABLEendBCL
- \else
- \globallet\checkTABLEautorow\docheckTABLEautorow
- \globallet\chuckTABLEautorow\dochuckTABLEautorow
- \fi}
-
-\let\checkTABLEautorow\empty
-\let\chuckTABLEautorow\empty
-
-\def\docheckTABLEautorow
- {\globallet\checkTABLEautorow\empty
- \ifnum\TABLEaction=\TABLErule \FR
- \else\ifnum\TABLEaction=\TABLEunknown \FR
- \else \MR
- \fi\fi}
-
-\def\dochuckTABLEautorow
- {\globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow
- \ifnum\TABLEaction=\TABLErule \SR
- \else\ifnum\TABLEaction=\TABLEunknown \SR
- \else \LR
- \fi\fi}
-
-%D When a table is split, we also add a tail and when present
-%D we repeat the table head.
-
-\def\handleTABLEbreak#1#2%
- {\globalletempty\beforeTABLEline
- \gdef\afterTABLEline{\TABLEnoalign{\ifconditional\preventTABLEbreak\nobreak\else\goodbreak\fi}}}
-
-%D When tables are split, the spacing before and after a
-%D horizontal rule is corrected according to what we expect.
-
-\def\endofTABLEline[#1][#2->#3]#4#5%
- {\ifx#2#3\else
- \writestatus\m!TABLE{\string#2\space changed into \string#3}%
- \fi
- \iftracetables
- \bgroup
- \tttf\space
- \ifnum\TABLEerror=\TABLEunknown
- \ifx#2#3\else\string#2->\fi
- \else
- ->%
- \fi
- \color[#1]{\string#3}%
- \ifx\TABLEgraylineerror\empty
- \space\TABLEgraylinestatus
- \else
- \space\TABLEgraylineerror
- \fi
- \egroup
- \else\ifx\TABLEgraylineerror\empty \else
- % \bgroup
- % \tttf\space\TABLEgraylineerror
- % \egroup
- \fi\fi
- \globalletempty\TABLEgraylinestatus
- \globalletempty\TABLEgraylineerror
- \expandafter\normalTABLElineformat#4#5\crcr % \crcr nodig ?
- \TABLEnoalign{\nobreak\global\setTABLEactiontrue}}
-
-%D In order to prevent (as good as possible) alignment overflow
-%D and therefore \TEX\ error messages, we check the maximum
-%D number of columns. We keep track of the current column and
-%D maximum column by means of two \COUNTERS. Keep in mind that
-%D the number of \type{|}'s and \type{\VL}'s or alike is always
-%D one more than the number of columns.
-
-\newcount\currentTABLEcolumn
-\newcount\maxTABLEcolumn
-
-%D While defining this macro we change the \CATCODE\ of
-%D \type{|}. When counting the bars, we use a non active
-%D representation of the bar, simply because we cannot be sure
-%D if the bar is active or not.\footnote{Normally it is, but
-%D \TABLE\ changes the catcode when needed.}
-
-\bgroup
- \catcode`\|=\@@other \gdef\@@otherbar {|}
- \catcode`\"=\@@other \gdef\@@otherquote {"}
- \catcode`\|=\@@active \gdef\@@useotherbar {\let|\@@otherbar}
- \catcode`\"=\@@active \gdef\@@useotherquote{\let"\@@otherquote}
-\egroup
-
-\bgroup \catcode`\|=\@@other
-
-\gdef\getTABLEnofcolumns#1%
- {\bgroup
- \cleanupfeatures % needed !
- \@@useotherbar
- \@@useotherquote
- \expanded{\defconvertedargument\noexpand\ascii{#1}}%
- \@EA\doglobal\@EA\counttoken\@EA|\@EA\in\ascii\to\maxTABLEcolumn
- \global\advance\maxTABLEcolumn \minusone
- % in case of & counting, divide by 2
- \egroup}
-
-\egroup
-
-\def\!ttDoHalign
- {\baselineskip \zeropoint
- \lineskiplimit\zeropoint
- \lineskip \zeropoint
- \tabskip \zeropoint
- % does not work in normal tex
- % \expanded{\getTABLEnofcolumns{\the\!taPreamble}}% added
- \halign \the\!taTableSpread \bgroup
- \span\the\!taPreamble
- \ifx \!tfRowOfWidths \empty \else \!tfRowOfWidths \cr \fi}
-
-%D \startitemize[3*ruim]
-%D \sym{\type{\VL}} a vertical line
-%D \sym{\type{\VC}} a vertical colored line
-%D \sym{\type{\HL}} a horizontal line
-%D \sym{\type{\HC}} a horizontal colored line
-%D \stopitemize
-
-% \def\defineTABLErules
-% {\let\VL\TableVL
-% \let\VC\TableVC
-% \let\HL\TableHL
-% \let\HC\TableHC}
-
-\def\defineTABLErules
- {\let\VL\TableVL
- \let\VC\TableVC
- \let\HL\TableHL
- \let\HC\TableHC
- \let\VS\TableVS
- \let\VD\TableVD
- \let\VT\TableVT
- \let\VN\TableVN}
-
-\def\TableVL
- {\checkTABLEautorow
- \nextTABLEgrayline
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \setTABLEerror\TABLEmissingrow
- \handleTABLEerror
- \else
- \global\advance\currentTABLEcolumn \plusone
- \expandafter\doTableVL
- \fi}
-
-\def\doTableVL
- {\futurelet\next\dodoTableVL}
-
-\def\dodoTableVL
- {\docomplexorsimpleTable\complexTableVL\simpleTableVL}
-
-\def\complexTableVL[#1]%
- {\scratchcounter=0#1%
- \multiply\scratchcounter \@@tiVLwidth
- \setxvalue{wVL\the\currentTABLEcolumn}{\the\scratchcounter}%
- \simpleTableVL}
-
-\def\simpleTableVL
- {\doifundefined{wVL\the\currentTABLEcolumn}%
- {\setgvalue{wVL\the\currentTABLEcolumn}{\@@tiVLwidth}}%
- \gdef\TABLEbeforebar
- {\getvalue{bVL\the\currentTABLEcolumn}%
- \letgvalueempty{bVL\the\currentTABLEcolumn}}%
- \gdef\TABLEafterbar
- {\getvalue{eVL\the\currentTABLEcolumn}%
- \letgvalueempty{eVL\the\currentTABLEcolumn}}%
- \edef\@@tiVLwidth{\getvalue{wVL\the\currentTABLEcolumn}}%
- \expanded{\normalTABLEcomplexbar\@@tiVLwidth\space}}% \relax breaks \use
-
-% \starttable[|||]
-% \HL
-% \VL test \VS test \VL \FR
-% \VL test \VD test \VL \MR
-% \VL test \VT test \VL \LR
-% \HL
-% \stoptable
-
-\def\TableVS {\VN1}
-\def\TableVD {\VN2}
-\def\TableVT {\VN3}
-\def\TableVN#1{\gdef\@VLn{#1}\VL}
-
-\def\resetVLvalues
- {\dostepwiserecurse\zerocount\maxTABLEcolumn\plusone
- {\setgvalue{wVL\recurselevel}{\@@tiVLwidth}%
- \letgvalueempty{bVL\recurselevel}%
- \letgvalueempty{eVL\recurselevel}}%
- \global\currentTABLEcolumn\zerocount}
-
-\def\TableVC
- {\checkTABLEautorow
- \nextTABLEgrayline
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \setTABLEerror\TABLEmissingrow
- \handleTABLEerror
- \else
- \global\advance\currentTABLEcolumn \plusone
- \expandafter\doTableVC
- \fi}
-
-\def\doTableVC
- {\futurelet\next\dodoTableVC}
-
-\def\dodoTableVC
- {\docomplexorsimpleTable\complexTableVC\simpleTableVC}
-
-\def\complexTableVC[#1]%
- {\global\setvalue{bVC\the\currentTABLEcolumn}{\localstartcolor[#1]}%
- \global\setvalue{eVC\the\currentTABLEcolumn}{\localstopcolor}%
- \simpleTableVC}
-
-\def\simpleTableVC
- {\global\setvalue{bVL\the\currentTABLEcolumn}%
- {\getvalue{bVC\the\currentTABLEcolumn}}%
- \global\setvalue{eVL\the\currentTABLEcolumn}%
- {\getvalue{eVC\the\currentTABLEcolumn}}%
- \doTableVL}
-
-\def\TableHL
- {\ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \chuckTABLEautorow
- \else\ifnum\currentTABLEcolumn=\zerocount
- %\chuckTABLEautorow
- \TABLEnoalign
- {\globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow}%
- \else
- \setTABLEerror\TABLEmissingcolumn
- \handleTABLEerror
- \fi\fi
- \complexorsimpleTable{HL}}
-
-\def\complexTableHL[#1]%
- {\TABLEnoalign
- {\scratchcounter0#1%
- \multiply\scratchcounter \@@tiHLheight
- \edef\@@tiHLheight{\the\scratchcounter}%
- \simpleTableHL}}
-
-\def\simpleTableHL
- {\TABLEnoalign
- {\nobreak
- \ifnum\TABLEaction=\TABLErule
- \writestatus\m!TABLE{skipping \string\HL}% \statusmessage
- \else
- \ifnum\TABLEaction=\TABLEmidrow
- \writestatus\m!TABLE{change \string\MR\space into \string\LR/\string\SR}%
- \else\ifnum\TABLEaction=\TABLEfirstrow
- \writestatus\m!TABLE{change \string\MR\space into \string\SR}%
- \fi\fi
- \startHLcommand
- \expandafter\normalTABLEfullrule\@@tiHLheight
- \stopHLcommand
- \globalletempty\startHLcommand
- \globalletempty\stopHLcommand
- \accountTABLElinewidth
- \fi
- \setTABLEaction\TABLErule
- \nobreak}}
-
-\let\startHLcommand\empty
-\let\stopHLcommand \empty
-
-\def\TableHC
- {\complexorsimpleTable{HC}}
-
-\def\complexTableHC[#1]%
- {\TABLEnoalign
- {\gdef\startHCcommand{\localstartcolor[#1]}%
- \gdef\stopHCcommand {\localstopcolor}}%
- \simpleTableHC}
-
-\def\simpleTableHC
- {\TABLEnoalign
- {\globallet\startHLcommand\startHCcommand
- \globallet\stopHLcommand \stopHCcommand}%
- \HL}
-
-%D \startitemize[3*ruim]
-%D \sym{\type{\NL}} a vertical skip
-%D \sym{\type{\NR}} goto the next row
-%D \sym{\type{\NC}} goto the next column
-%D \sym{\type{\FC}} a first column
-%D \sym{\type{\MC}} a mid column
-%D \sym{\type{\LC}} a last column
-%D \stopitemize
-
-% n+1 uitleggen
-
-\def\defineTABLEsteps
- {\let\NL\TableNL
- \let\NR\TableNR
- \let\NC\TableNC
- \let\FC\TableNC
- \let\MC\TableNC
- \let\LC\TableNC}
-
-\def\TableNL
- {\complexorsimpleTable{NL}}
-
-\def\complexTableNL[#1]%
- {\TABLEnoalign
- {\edef\@@tiNL{#1}%
- \simpleTableNL}}%
-
-\def\simpleTableNL
- {\TABLEnoalign
- {\nobreak
- \setbox0\vbox{\blank[\@@tiNL]}%
- \vskip\ht0
- \nobreak}}
-
-\def\TableNR
- {\ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \global\currentTABLEcolumn\zerocount
- \normalTABLElineending
- \else
- \setTABLEerror\TABLEmissingcolumn
- \handleTABLEerror
- \fi
- \TABLEnoalign
- {\nobreak
- \setTABLEaction\TABLEunknown}}
-
-\def\TableNC
- {\checkTABLEautorow
- \nextTABLEgrayline
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \setTABLEerror\TABLEmissingrow
- \handleTABLEerror
- \else
- \global\advance\currentTABLEcolumn \plusone
- \normalTABLEquote
- \fi}
-
-% \bgroup
-% \catcode`\|=\@@active
-% \catcode`\"=\@@active
-% \gdef\redefinetablebarandquote
-% {\def|{\VL}% % \normalTABLEsimplebar
-% \def\|##1{\VL[##1]}% % \normalTABLEcomplexbar
-% \def"{\NC}} % \normalTABLEquote
-% \egroup
-
-\let\redefinetablebarandquote\relax
-
-%D \startitemize[3*ruim]
-%D \sym{\type{\DL}}
-%D \sym{\type{\DV}} (\type{\VD})
-%D \sym{\type{\DC}}
-%D \sym{\type{\DR}}
-%D \stopitemize
-
-\newif\ifTABLEdivision
-
-% \def\defineTABLEdivisions
-% {\global\TABLEdivisionfalse % in start
-% \let\DL\TableDL
-% \let\DC\TableDC
-% \let\DV\TableDV
-% \let\VD\TableDV
-% \let\DR\TableDR}
-
-\def\defineTABLEdivisions
- {\global\TABLEdivisionfalse % in start
- \let\DL\TableDL
- \let\DC\TableDC
- \let\DV\TableDV
- \let\DR\TableDR}
-
-\def\checkTABLEdivision
- {\ifTABLEdivision \else
- \chuckTABLEautorow
- \global\currentTABLEcolumn\zerocount
- \global\TABLEdivisiontrue
- \fi}
-
-\def\TableDL
- {\checkTABLEdivision
- \complexorsimpleTable{DL}}
-
-\def\simpleTableDL
- {\complexTableDL[1]}
-
-\def\complexTableDL[#1]%
- {\ifnum\TABLEaction=\TABLErule
- \writestatus\m!TABLE{skipping \string\DL}%
- \else
- \ifnum\TABLEaction=\TABLEmidrow
- \writestatus\m!TABLE{change \string\MR\space into \string\LR/\string\SR}%
- \else\ifnum\TABLEaction=\TABLEfirstrow
- \writestatus\m!TABLE{change \string\MR\space into \string\SR}%
- \fi\fi
- \setTABLEaction=\TABLEunknown
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \setTABLEerror\TABLEmissingrow
- \handleTABLEerror
- \fi
- %\startHLcommand
- \ifnum#1=\plusone
- \global\advance\currentTABLEcolumn \plustwo
- \let\next\normalTABLEsinglerule
- \else
- \ifnum#1<\maxTABLEcolumn
- \global\advance\currentTABLEcolumn \plusone
- \def\next{\normalTABLEmultirule{#1}}%
- \else
- \setTABLEerror\TABLEdivisionoverflow
- \let\next\handleTABLEerror
- \fi
- \fi
- \next
- %\stopHLcommand
- %\globalletempty\startHLcommand
- %\globalletempty\stopHLcommand
- \fi}
-
-\def\TableDV
- {\TableDCV\normalTABLEsimplebar}
-
-\def\TableDC
- {\TableDCV\normalTABLEquote}
-
-\def\TableDCV#1%
- {\checkTABLEdivision
- \checkTABLEautorow
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \setTABLEerror\TABLEmissingrow
- \handleTABLEerror
- \else
- \global\advance\currentTABLEcolumn \plusone
- #1%
- \fi}
-
-\def\TableDR
- {\ifnum\currentTABLEcolumn<\maxTABLEcolumn % silent recovery
- %\setTABLEerror\TABLEmissingcolumn % some day warning
- %\handleTABLEerror
- \finishTABLErow
- \else
- \global\currentTABLEcolumn\zerocount % nog check
- \normalTABLElineending
- \fi
- \TABLEnoalign
- {\nobreak
- \global\TABLEdivisionfalse
- \accountTABLElinewidth % temporary solution
- \setTABLEaction\TABLErule}}
-
-\def\accountTABLElinewidth
- {\scratchdimen\LineThicknessUnit}
-
-%D \startitemize[3*ruim]
-%D \sym{\type{\BC}}
-%D \sym{\type{\BR}}
-%D \sym{\type{\BACKGROUND}}
-%D \sym{\type{\CL}}
-%D \sym{\type{\RL}}
-%D \sym{\type{\BL}}
-%D \sym{\type{\RASTER}}
-%D \sym{\type{\COLOR}}
-%D \stopitemize
-
-% definieer: \BC \BL
-% herhaal: \BR
-% definieer: \CL \RL (eerste \CL[green] = hele row! / \CL[1,green])
-% dus: \CL en \RL mix tussen \HL en \BL
-
-\def\defineTABLEbackgrounds
- {\let\BC \TableBC
- \let\BL \TableBL
- \let\BR \TableBR
- \let\BACKGROUND\TableBR
- \let\CL \TableCL
- \let\RL \TableRL
- \let\COLOR \TableCOLOR
- \let\RASTER \TableRASTER
- \globallet\lastTABLEc\@@tibackgroundcolor
- \globallet\lastTABLEr\@@tibackgroundscreen
- \doifinsetelse\@@tibackground{c,color} % \v!color
- {\global\chardef\TABLEcr\plusone}
- {\global\chardef\TABLEcr\plustwo}}
-
-\def\TableBC
- {\ifTABLEgrayline
- \normalTABLEquote
- \else
- \TABLEnoalign\bgroup
- \globallet\nextTABLEgrayline\executeTABLEgrayline
- \globalletempty\TABLEgrayline % new
- \let\BL\doTableBL
- \let\BC\doTableBC
- \expandafter\doTableBC
- \fi}
-
-\def\doTableBC
- {\addtoTABLEgrayline{\BC}%
- \gobbleTableBCL}
-
-\def\TableBL
- {\TABLEnoalign\bgroup
- \globallet\nextTABLEgrayline\executeTABLEgrayline
- \globalletempty\TABLEgrayline % new
- \let\BL\doTableBL
- \let\CL\doTableCL
- \let\RL\doTableRL
- \let\BC\doTableBC
- \doTableBL}
-
-\def\doTableBL
- {\complexorsimpleTable{BL}}
-
-\def\simpleTableBL
- {\complexTableBL[,]}
-
-\def\complexTableBL[#1]%
- {\analyzeTABLEcr[#1]%
- \handleTABLEcr}
-
-\def\TableBR#1%
- {\TABLEnoalign
- {\globallet\nextTABLEgrayline\executeTABLEgrayline
- \checkTABLEgrayline#1\BR
- \global\TABLEgraylinetrue}}
-
-\def\analyzeTABLEcr[#1]%
- {\doanalyzeTABLEcr[#1,,]}
-
-\def\doanalyzeTABLEcr[#1,#2,#3]%
- {\doifnumberelse{#1x} % Is the x still needed here?
- {\dodoanalyzeTABLEcr[#1,#2,#3]}
- {\dodoanalyzeTABLEcr[1,#1,#2]}}
-
-\def\dodoanalyzeTABLEcr[#1,#2,#3]%
- {\global\chardef\TABLEn#1\relax
- \processaction
- [#2]
- [ c=>\global\chardef\TABLEcr1,%
- color=>\global\chardef\TABLEcr1,%
- r=>\global\chardef\TABLEcr2,%
- raster=>\global\chardef\TABLEcr2]%
- \ifcase\TABLEcr \or
- \doifsomething{#3}{\xdef\lastTABLEc{#3}}%
- \or
- \doifsomething{#3}{\xdef\lastTABLEr{#3}}%
- \fi}
-
-\def\handleTABLEcr
- {\relax % else funny side effect
- \ifcase\TABLEcr
- % Can't happen!
- \or
- \addtoTABLEgrayline{\complexTableCOLOR[\the\TABLEn,\lastTABLEc]}%
- \else
- \addtoTABLEgrayline{\complexTableRASTER[\the\TABLEn,\lastTABLEr]}%
- \fi
- \gobbleTableBCL}
-
-\def\analyzeTABLEcrl#1[#2]%
- {\doanalyzeTABLEcrl#1[#2,,]}
-
-\def\doanalyzeTABLEcrl#1[#2,#3,#4]%
- {\doifnumberelse{#2x} % x ????????????????????
- {\dodoanalyzeTABLEcr[#2,#1,#3]}
- {\dodoanalyzeTABLEcr[\ifTABLEgrayline1\else\maxTABLEcolumn\fi,#1,#2]}}
-
-\def\TableCL
- {\TABLEnoalign\bgroup
- \globallet\nextTABLEgrayline\executeTABLEgrayline
- \globalletempty\TABLEgrayline % new
- \let\BL\doTableBL
- \let\CL\doTableCL
- \let\RL\doTableRL
- \let\BC\doTableBC
- \doTableCL}
-
-\def\doTableCL
- {\complexorsimpleTable{CL}}
-
-\def\simpleTableCL% nog eens \'e\'en lijn van maken
- {\BL[\the\maxTABLEcolumn,c,\lastTABLEc]}
-
-\def\complexTableCL[#1]%
- {\analyzeTABLEcrl{c}[#1]%
- \handleTABLEcr}
-
-\def\TableRL
- {\TABLEnoalign\bgroup
- \globallet\nextTABLEgrayline\executeTABLEgrayline
- \globalletempty\TABLEgrayline % new
- \let\BL\doTableBL
- \let\CL\doTableCL
- \let\RL\doTableRL
- \let\BC\doTableBC
- \doTableRL}
-
-\def\doTableRL
- {\complexorsimpleTable{RL}}
-
-\def\simpleTableRL
- {\BL[\the\maxTABLEcolumn,r,\lastTABLEr]}
-
-\def\complexTableRL[#1]%
- {\analyzeTABLEcrl{r}[#1]%
- \handleTABLEcr}
-
-\def\checkTABLEgrayline#1#2%
- {\!!doneatrue
- \ifx#1\AR
- \!!doneafalse
- \else\ifx#1\SR\else\ifx#1\FR\else\ifx#1\MR\else\ifx#1\LR\else
- \!!doneafalse
- \fi\fi\fi\fi\fi
- \if!!donea
- \gdef\TABLEgraylinestatus
- {[\string#1]}%
- \gdef\TABLEendBCL
- {#1}%
- \else
- \gdef\TABLEgraylineerror
- {[\string#2\string#1->\string#2\string\SR]}%
- \gdef\TABLEendBCL
- {\SR}%
- \fi}
-
-\def\endTABLErowGL#1#2#3%
- {\ifcase#1\relax
- % unknown
- \or
- \doPreTableGL\TABLErowfactor\TABLErowfactor
- \or
- \doPreTableGL\TABLErowfactor\TABLErowzero
- \or
- \ifnum\TABLEforce=\TABLEforcelastrow
- \doPreTableGL\TABLErowzero\TABLErowfactor
- \else\ifnum\TABLEforce=\TABLEforcefirstrow
- \doPreTableGL\TABLErowfactor\TABLErowzero
- \else
- \doPreTableGL\TABLErowzero\TABLErowzero
- \fi\fi
- \or
- \doPreTableGL\TABLErowzero\TABLErowfactor
- \fi}
-
-\def\doPreTableGL#1#2% betere namen
- {\xdef\OldLineThicknessFactor{\the\LineThicknessFactor}%
- \xdef\OldLineThicknessUnit{\the\LineThicknessUnit}%
- \global\LineThicknessFactor\plusone
- \setbox0\hbox{\AugmentedTableStrut{#1}{#2}}%
- \getboxheight\dimen0\of\box0\relax
- \xdef\TABLEgraylineHeight{\the\dimen0}%
- \global\LineThicknessUnit\TABLEgraylineHeight}
-
-\def\doPostTableGL
- {\global\LineThicknessFactor\OldLineThicknessFactor
- \global\LineThicknessUnit \OldLineThicknessUnit}
-
-% kan simpeler
-
-\def\docomplexTableCOLOR[#1]%
- {\dodocomplexTableGL\localstartcolor \localstopcolor [#1,\lastTABLEc,,]}
-
-\gdef\docomplexTableRASTER[#1]%
- {\dodocomplexTableGL\localstartraster\localstopraster[#1,\lastTABLEr,,]}
-
-\def\dodocomplexTableGL#1#2[#3,#4,#5,#6]%
- {\doifelsenothing{#4}{#1[#5]}{#1[#4]}%
- \doPreTableGL\TABLEendofrowheight\TABLEendofrowdepth
- \ifnum#3=\plusone % else conflict with \omit in \=
- \let\next\normalTABLEsinglerule
- \else
- \def\next{\normalTABLEmultirule{#3}}%
- \fi
- \next
- \doPostTableGL
- #2}
-
-\def\TableBACKGROUND
- {\TableBR}
-
-\def\simpleTableRASTER #1{\docomplexTableRASTER[1]#1}
-\def\complexTableRASTER[#1]{\docomplexTableRASTER[#1]}
-\def\simpleTableCOLOR {\docomplexTableCOLOR [1]}
-\def\complexTableCOLOR [#1]{\docomplexTableCOLOR [#1]}
-
-\def\TableRASTER{\complexorsimpleTable{RASTER}}
-\def\TableCOLOR {\complexorsimpleTable{COLOR}}
-
-\def\addtoTABLEgrayline#1%
- {\TABLEgraytoks\expandafter{\TABLEgrayline}%
- \xdef\TABLEgrayline{\the\TABLEgraytoks\noexpand#1}}
-
-\def\setTableBCL#1#2%
- {\ifx#1#2%
- \gdef\TABLEgraylinestatus{[\string#1]}%
- \gdef\TABLEendBCL{#1}%
- \addtoTABLEgrayline{#1}%
- \else
- \gdef\TABLEgraylineerror{[\string#1->\string#2]}%
- \gdef\TABLEendBCL{#2}%
- \addtoTABLEgrayline{#2}%
- \fi}
-
-\def\gobbleTableBCL#1%
- {\ifx#1\BC \let\next\doTableBC \else
- \ifx#1\BL \let\next\doTableBL \else
- \ifx#1\SR \setTableBCL\SR\SR \let\next\egroup \else
- \ifx#1\FR \setTableBCL\FR\FR \let\next\egroup \else
- \ifx#1\MR \setTableBCL\MR\MR \let\next\egroup \else
- \ifx#1\LR \setTableBCL\LR\LR \let\next\egroup \else
- \setTableBCL #1\SR \let\next\egroup
- \fi\fi\fi\fi\fi\fi
- \next}
-
-\def\executeTABLEgrayline
- {\TABLEnoalign
- {\def\BC
- {\advance\currentTABLEcolumn \plusone}%
- \def\dodocomplexTableGL##1##2[##3,##4,##5,##6]%
- {\BC\advance\currentTABLEcolumn ##3 }%
- \let\endTABLErow\endTABLEgrayrow
- \currentTABLEcolumn\zerocount
- \TABLEgrayline\TABLEendBCL % determine n of columns and height
- \advance\currentTABLEcolumn \minusone
- \ifnum\currentTABLEcolumn>\maxTABLEcolumn
- % error message too long line
- \globalletempty\TABLEgrayline
- \else
- % \message{n of color columns: \the\currentTABLEcolumn}\wait
- \global\TABLEgraylinetrue % vanaf hier nog checken
- \fi
- \global\currentTABLEcolumn\zerocount}%
- \unskip\TABLEgrayline\TABLEendBCL
- \TABLEnoalign
- {\nobreak
- \vskip-\TABLEgraylineHeight
- \nobreak
- \global\setTABLEactiontrue
- \global\currentTABLEcolumn\zerocount
- \globalletempty\nextTABLEgrayline
- \global\TABLEgraydonetrue
- \global\TABLEgraylinefalse}}
-
-\def\endTABLEgrayrow#1#2#3%
- {\ifcase#1\relax
- \global\chardef\TABLEendofrowheight\TABLErowfactor
- \global\chardef\TABLEendofrowdepth \TABLErowfactor
- \or
- \global\chardef\TABLEendofrowheight\TABLErowfactor
- \global\chardef\TABLEendofrowdepth \TABLErowfactor
- \or
- \global\chardef\TABLEendofrowheight\TABLErowfactor
- \global\chardef\TABLEendofrowdepth \TABLErowzero
- \or
- \ifnum\TABLEforce=\TABLEforcelastrow
- \global\chardef\TABLEendofrowheight\TABLErowzero
- \global\chardef\TABLEendofrowdepth \TABLErowfactor
- \else\ifnum\TABLEforce=\TABLEforcefirstrow
- \global\chardef\TABLEendofrowheight\TABLErowfactor
- \global\chardef\TABLEendofrowdepth \TABLErowzero
- \else
- \global\chardef\TABLEendofrowheight\TABLErowzero
- \global\chardef\TABLEendofrowdepth \TABLErowzero
- \fi\fi
- \or
- \global\chardef\TABLEendofrowheight\TABLErowzero
- \global\chardef\TABLEendofrowdepth \TABLErowfactor
- \fi}
-
-\def\defineTABLEshorthands%
- {\def\SPAN##1{\use{##1}}%
- \def\TWO {\use2}%
- \def\THREE {\use3}%
- \def\FOUR {\use4}%
- \def\FIVE {\use5}%
- \def\SIX {\use6}%
- \def\REF {\ReFormat}}
-
-\def\defineTABLEunits
- {\processaction
- [\@@tidistance]
- [ \v!none=>\OpenUp00\def\LOW{\Lower6 },
- \v!small=>\OpenUp00\def\LOW{\Lower6 }, % == baseline
- \v!medium=>\OpenUp11\def\LOW{\Lower7 },
- \v!big=>\OpenUp22\def\LOW{\Lower8 }]%
- \doifelse\@@tidistance\v!none
- {\chardef\TABLErowfactor\zerocount}
- {\chardef\TABLErowfactor\plustwo }}
-
-\def\dohandlebar % here ?
- {\ifmmode
- \@EA\domathmodebar
- \else\ifintable
- \@EAEAEA\domathmodebar
- \else
- \@EAEAEA\dotextmodebar
- \fi\fi}
-
-% De macro's t.b.v. instellingen.
-
-\def\setuptables
- {\dosingleargument\dosetuptables}
-
-\def\dosetuptables[#1]%
- {\getparameters[\??ti][#1]%
- \processaction
- [\@@tialign]
- [ \v!right=>\def\TABLEparalignment{\raggedright},
- \v!left=>\def\TABLEparalignment{\raggedleft},
- \v!middle=>\def\TABLEparalignment{\raggedcenter},
- \s!default=>\def\TABLEparalignment{\notragged},
- \s!unknown=>\def\TABLEparalignment{\notragged}]%
- \assignalfadimension\@@tiVL\@@tiVLwidth 246%
- \assignalfadimension\@@tiHL\@@tiHLheight246}
-
-\def\localTABLEsetup
- {\@@ticommands\relax
- \expanded{\switchtobodyfont[\@@tibodyfont]}%
- \StrutHeightFactor 8
- \StrutDepthFactor 4
- \LineThicknessFactor4
- \NormalTLTU {.1pt}%
- \NormalTSU {\normalbaselineskip\divide\StrutUnit 12 }%
- \NormalTableUnits}
-
-%D And then I wrote the tabulate environment. That
-%D alternative supports setting the rule thickness and color,
-%D so here is the table alternative.
-
-\let\startglobalTABLEcolor\empty
-\let\stopglobalTABLEcolor \empty
-
-\def\localTABLEsetup
- {\@@ticommands\relax
- % bodyfont
- \expanded{\switchtobodyfont[\@@tibodyfont]}%
- % linecolor
- \doifsomething\@@tirulecolor
- {\def\startglobalTABLEcolor{\localstartcolor[\@@tirulecolor]}%
- \def\stopglobalTABLEcolor {\localstopcolor}}%
- % linethickness
- \LineThicknessFactor4
- \scratchdimen\@@tirulethickness
- \divide\scratchdimen \LineThicknessFactor
- \expanded{\NormalTLTU{\the\scratchdimen}}%
- % spacing, was depth=4 height=8 (counters, sigh, now macros)
- \doifelse\@@tiheight\v!strut
- {\let\StrutHeightFactor\@@itheight}
- {\let\StrutHeightFactor\@@tiheight}%
- \doifelse\@@tidepth\v!strut
- {\let\StrutDepthFactor\@@itdepth}
- {\let\StrutDepthFactor\@@tidepth}%
- \scratchdimen\StrutHeightFactor\points \multiply\scratchdimen 10%
- \edef\StrutHeightFactor{\withoutpt\the\scratchdimen}%
- \scratchdimen\StrutDepthFactor \points \multiply\scratchdimen 10%
- \edef\StrutDepthFactor{\withoutpt\the\scratchdimen}%
- % units
- \NormalTSU{\normalbaselineskip\divide\StrutUnit 12 }%
- \NormalTableUnits}
-
-\def\OpenUp#1#2%
- {\scratchdimen\StrutHeightFactor \points \advance\scratchdimen #1\points
- \edef\StrutHeightFactor{\withoutpt\the\scratchdimen}%
- \scratchdimen\StrutDepthFactor \points \advance\scratchdimen #2\points
- \edef\StrutDepthFactor{\withoutpt\the\scratchdimen}}
-
-%D As one can see, we didn't only add color, but also more
-%D control over spacing.
-%D
-%D \startbuffer[a]
-%D \starttable[|c|]
-%D \HL
-%D \VL \strut test \VL \FR
-%D \VL \strut test \VL \MR
-%D \VL \strut test \VL \MR
-%D \VL \strut test \VL \LR
-%D \HL
-%D \stoptable
-%D \stopbuffer
-%D
-%D \startbuffer[b]
-%D \starttabulate[|c|]
-%D \HL
-%D \NC test \NC \NR
-%D \NC test \NC \NR
-%D \NC test \NC \NR
-%D \NC test \NC \NR
-%D \HL
-%D \stoptabulate
-%D \stopbuffer
-%D
-%D In the next example, the first table is defined as:
-%D
-%D \typebuffer[a]
-%D
-%D and the second one as:
-%D
-%D \typebuffer[b]
-%D
-%D The first table is typeset using the default height and
-%D depth factors .8 and .4. The second table has both factors
-%D set to \type {strut}, and the third table shows what
-%D happens when we set the values to zero. The rightmost table
-%D is typeset using the tabulate environment.
-%D
-%D \startcombination[4*1]
-%D {$\vcenter{\getbuffer[a]}$}
-%D {\hbox{h=.8 d=.4}}
-%D {\setuptables[height=strut,depth=strut]$\vcenter{\getbuffer[a]}$}
-%D {\hbox{h=d=\type{strut}}}
-%D {\setuptables[height=0,depth=0]$\vcenter{\getbuffer[a]}$}
-%D {\hbox{h=d=0}}
-%D {$\vcenter{\getbuffer[b]}$}
-%D {\hbox{tabulate}}
-%D \stopcombination
-
-\setuptables
- [HL=\v!medium,
- VL=\v!medium,
- NL=\v!small,
- \c!frame=,
- \c!align=\v!right,
- \c!depth=.40, % \v!strut
- \c!height=.80, % \v!strut
- \c!rulethickness=\linewidth,
- \c!rulecolor=,
- \c!distance=\v!medium,
- \c!bodyfont=\the\bodyfontsize,
- \c!commands=,
- \c!background=\v!screen,
- \c!backgroundscreen=\@@rsscreen,
- \c!backgroundcolor=,
- \c!split=\v!auto]
-
-\def\ifintabel{\ifintable} % upward compatible
-
-\protect \endinput
diff --git a/tex/context/base/core-tbl.tex b/tex/context/base/core-tbl.tex
deleted file mode 100644
index a5d5a37da..000000000
--- a/tex/context/base/core-tbl.tex
+++ /dev/null
@@ -1,1436 +0,0 @@
-%D \module
-%D [ file=core-tbl,
-%D version=1998.11.03,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Text Flow Tabulation,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Tabulation}
-
-% \processbetween gebruiken in head/tail macros
-
-\unprotect
-
-% WATCH OUT: don't change this model else trialtypesetting
-% compatibility problems
-
-% watch out, cells expand pretty late on a per row basis
-
-% |p2|p3| 2:3
-% spanning
-
-% Be careful with changing the hsize calculation in p mode;
-% the following code works quite well:
-%
-% \setupfield [line][location=low,height=1.2\lineheight,width=\hsize]
-% \definefield [test] [line] [line] []
-%
-% \starttabulate[|l|p|]
-% \NC test \NC \field [test] \NC \NR
-% \stoptabulate
-
-% In-text tabbing environment
-%
-% \starttabulate[| separated template] % eg [|l|p|] or [|l|p|p|]
-% \NC ... \NC ... \NC\NR
-% \stoptabulate
-%
-% with: two pass auto width calculation when no p-width
-% specified, even with multiple p's, see examples.
-
-% TaBlE compatible specifications:
-%
-% l align column/paragraph left
-% r align column/paragraph right
-% c align column/paragraph center
-% p p(dimen) of automatisch als alleen p
-% w column width
-% f font#1
-% B bold
-% I italic
-% S slanted
-% T type
-% R roman
-% m math
-% M display math
-% h hook (inner level or par lines)
-% b before (may be command#1)
-% a after
-% i i skip left of column
-% j i skip right of column
-% k i skip around column
-
-% s setups
-
-% g g{char} align at char
-% . align at .
-% , align at ,
-
-% Still to be done
-
-% N math numbers (best hook into existing digits mechanism)
-% n numbers (best hook into existing digits mechanism)
-% Q math numbers (best hook into existing digits mechanism)
-% q numbers (best hook into existing digits mechanism)
-% ~ \hskip.5em
-% | check
-
-% nesting
-
-% 10 evt auto stack; dan wel andere signal dan void nodig
-
-% present but not yet 100% ok
-%
-% \FL top hrule
-% \ML mid hrule (with auto split)
-% \LL bottom hrule
-% \HL
-
-% \VL as soon as needed
-% color as soon as needed
-
-% \EQ \RQ \HQ equal (raw, hook)
-% \NC \RC \HC normal (raw, hook)
-%
-% \NR
-
-% \HR : rule with lineheight
-
-% \autotabulaterule : with lineheight, not first/last
-% \autotabulateline : spaced, not first/last
-% \tabulaterule : with lineheight
-% \tabulateline : spaced
-
-% tricky: align scans ahead, over # and expands ones before
-% while doing
-
-% new:
-%
-% \starttabulate[|cg{.}|cg{,}|cg{,}|]
-% \NC period \NC comma \NC comma \NC\NR
-% \NG 100.000,00 \NG 100.000,00 \NG 100,00 \NC\NR
-% \NG 10.000,00 \NG 10.000,00 \NG 1000,00 \NC\NR
-% \NG 100,00 \NG 100,00 \NG 10,00 \NC\NR
-% \NG 10 \NG 10 \NG 0,00 \NC\NR
-% \stoptabulate
-%
-% \starttabulate[|c.|c,|c,|]
-% \NC period \NC comma \NC comma \NC\NR
-% \NG 100.000,00 \NG 100.000,00 \NG 100,00 \NC\NR
-% \NG 10.000,00 \NG 10.000,00 \NG 1000,00 \NC\NR
-% \NG 100,00 \NG 100,00 \NG 10,00 \NC\NR
-% \NG 10 \NG 10 \NG 0,00 \NC\NR
-% \stoptabulate
-
-% nice demo (for BG)
-%
-% \starttabulate[|r|b{$\star$}|ra{\percent}|b{=}|r|]
-% \NC 500 \NC \NC 60 \NC \NC 300 \NC \NR
-% \NC 500 \NC \NC 55 \NC \NC 275 \NC \NR
-% \NC 500 \NC \NC 50 \NC \NC 250 \NC \NR
-% \NC 500 \NC \NC 45 \NC \NC 225 \NC \NR
-% \NC 500 \NC \NC 40 \NC \NC 200 \NC \NR
-% \NC 500 \NC \NC 35 \NC \NC 175 \NC \NR
-% \NC 500 \NC \NC 30 \NC \NC 150 \NC \NR
-% \NC 500 \NC \NC 25 \NC \NC 125 \NC \NR
-% \NC 500 \NC \NC 20 \NC \NC 100 \NC \NR
-% \stoptabulate
-
-\newtoks \tabulatepreamble
-\newtoks \tabulatebefore
-\newtoks \tabulateafter
-\newtoks \tabulatebmath
-\newtoks \tabulateemath
-\newtoks \tabulatefont
-\newtoks \tabulatesettings
-\newtoks \tabulatedummy
-
-\newcount \nofautotabulate
-\newcount \tabulatecolumns
-\newcount \tabulatecolumn
-
-\newcount \tabulateminplines
-\newcount \tabulatemaxplines
-
-\newif \ifautotabulate
-\newif \ifsplittabulate \splittabulatetrue
-
-\newif \ifhandletabulatepbreak \handletabulatepbreaktrue
-\newif \iftabulatenopbreak \tabulatenopbreakfalse
-
-\newif \iftabulateequal
-\newif \iftracetabulate
-\newif \ifframedtabulate
-
-\newdimen \tabulatepwidth
-\newdimen \tabulatewidth
-\newdimen \tabulateunit
-\newdimen \tabulatemaxpheight
-
-\newbox \tabulatebox
-
-% [|lg{.}|] => \NG 12.34 \NC
-
-\gdef\handletabulatecharalign#1 % space delimited !
- {\edef\alignmentclass{\the\tabulatecolumn}%
- \edef\alignmentcharacter{\getvalue{\@@tabalign@@\the\tabulatecolumn}}%
- \ifcase\tabulatepass\or
- \setfirstpasscharacteralign\checkalignment{#1}%
- \fi % force hsize
- \setsecondpasscharacteralign\checkalignment{#1}}
-
-\def\noftabcolumns{16}
-
-\def\@@tabbox@@ {@@tabbox@}
-\def\@@tabhook@@ {@@tabhook@}
-\def\@@tabalign@@ {@@tabalign@}
-\def\@@tabsetups@@{@@tabsetups@}
-
-% \dorecurse\noftabcolumns % quick and dirty stack
-% {\@EA\newbox\csname\@@tabbox@@\recurselevel\endcsname}
-
-\def\tablebox#1%
- {\csname\@@tabbox@@\number#1\endcsname}
-
-% \def\checktablebox#1%
-% {\ifundefinedelse{\@@tabbox@@\number#1}%
-% \expandafter\newbox\csname\@@tabbox@@\number#1\endcsname
-% \fi}
-
-\def\initializetablebox#1% also used elsewhere
- {\ifcsname\@@tabbox@@\number#1\endcsname
- \global\setbox\csname\@@tabbox@@\number#1\endcsname\box\voidb@x
- \else
- \expandafter\newbox\csname\@@tabbox@@\number#1\endcsname
- \fi}
-
-% \def\initializetableboxes#1% hm, not that efficient, best make a simple dedicated tail recurser
-% {\dorecurse#1{\initializetablebox\recurselevel}}
-
-\def\initializetableboxes#1%
- {\scratchcounter#1\relax
- \doinitializetableboxes}
-
-\def\doinitializetableboxes
- {\ifnum\scratchcounter>\zerocount
- \initializetablebox\scratchcounter
- \advance\scratchcounter\minusone
- \expandafter\doinitializetableboxes
- \fi}
-
-\initializetableboxes\noftabcolumns
-
-\def\dotabulatenobreak
- {\noalign
- {\nobreak
- \iftracetabulate
- \red\hrule\!!height.5\linewidth\!!depth.5\linewidth
- \par
- \kern-\linewidth
- \nobreak
- \fi}}
-
-\let\notabulatehook\empty
-
-\def\checktabulatehook
- {\ifnum\tabulatetype<\plustwo
- \global\let\tabulatehook\notabulatehook
- \else
- \global\let\tabulatehook\dotabulatehook
- \fi}
-
-\def\checktabulatesetups
- {\getvalue{\@@tabsetups@@\the\tabulatecolumn}}
-
-\let\pretabrule \donothing
-\let\posttabrule\donothing
-
-\def\dodosettabulatepreamble#1#2%
- {\ifzeropt\tabulatewidth
- \ifcase\tabulatemodus\relax
- \let\preamblebox\empty
- \else
- \def\preamblebox{\autotabulatetrue}%
- \fi
- \else
- \ifcase\tabulatemodus\relax
- \edef\preamblebox{\hbox to \the\tabulatewidth}%
- \else
- \edef\preamblebox{\hsize\the\tabulatewidth}%
- \fi
- \fi
- %
- % less bytes
- %
- %\edef\preamblebox%
- % {\ifcase\tabulatewidth
- % \ifcase\tabulatemodus\relax\else\noexpand\autotabulatetrue\fi
- % \els
- % \ifcase\tabulatemodus\relax\hbox to\else\hsize\fi\the\tabulatewidth
- % \fi}%
- %
- % 0 = NC column next EQ equal column
- % 1 = RC column raw RQ equal column raw
- % 2 = HC column hook HQ equal column hook
- % some entries can be left out if we test for them being set
- \@EA\appendtoks \@EA&\@EA\hskip\pretabskip\pretabrule##&\to\!!toksa
- \appendtoks \ignorespaces\to\!!toksa
- \@EA\appendtoks\@EA\global\@EA\tabulatecolumn\the\tabulatecolumns\relax\to\!!toksa
- \appendtoks \checktabulatesetups\to\!!toksa
- \appendtoks \checktabulatehook\to\!!toksa
- \@EA\appendtoks \preamblebox\to\!!toksa
- \appendtoks \bgroup\bbskip\bgroup#1\to\!!toksa
- \appendtoks\ifnum\tabulatetype=\plusone \else \to\!!toksa
- \@EA\appendtoks \the\tabulatebmath\to\!!toksa
- \@EA\appendtoks \the\tabulatefont\to\!!toksa
- \@EA\appendtoks \the\tabulatesettings\to\!!toksa
- \@EA\appendtoks \the\tabulatebefore\to\!!toksa
- \appendtoks\fi \to\!!toksa
- \appendtoks \bgroup\ignorespaces\to\!!toksa
- %
- \appendtoks \tabulatehook##\to\!!toksa
- %
- %%\doifdefinedelse{\@@tabalign@@\tabulatecolumns}
- %\doifdefinedelse{\@@tabalign@@\the\tabulatecolumns}
- % {\appendtoks\handletabulatecharalign## \to\!!toksa}
- % {\appendtoks\tabulatehook ##\to \!!toksa}%
- % waarom kan ik hier geen \xx{##} geven, om een of
- % andere reden passeert dan tex de hele regel (incl \NC's)
- % als argument; elke delimiter <> space gaat trouwens fout
- \appendtoks \unskip\unskip\ifmmode\else\endgraf\fi\egroup\to\!!toksa
- \appendtoks\ifnum\tabulatetype=1 \else \to\!!toksa
- \@EA\appendtoks \the\tabulateafter\to\!!toksa
- \@EA\appendtoks \the\tabulateemath\to\!!toksa
- \appendtoks\fi \to\!!toksa
- \appendtoks #2\egroup\egroup\to\!!toksa
- \@EA\appendtoks \@EA&\@EA\posttabrule\@EA\hskip\postabskip##\to\!!toksa
- \appendtoks\NC\to\tabulatedummy
- \let\bbskip\empty
- \def\pretabskip{.5\tabulateunit}%
- \let\postabskip\pretabskip
- \let\gettabulateexit\dogettabulateexit
- \tabulatewidth\zeropoint}
-
-% todo: we can speed up this module a bit
-%
-% \expanded{\!!toksa{\the\!!toksa
-% &\hskip\pretabskip\noexpand\pretabrule####&
-% \ignorespaces
-% \global\tabulatecolumn\the\tabulatecolumns
-% \noexpand\checktabulatesetups
-% \noexpand\checktabulatehook
-% \preamblebox
-% \bgroup\noexpand\bbskip\bgroup\normalunexpanded{#1}%
-% \noexpand\ifnum\tabulatetype=\plusone \noexpand\else
-% \the\tabulatebmath
-% \the\tabulatefont
-% \the\tabulatesettings
-% \the\tabulatebefore
-% \noexpand\fi
-% \bgroup\ignorespaces
-% \noexpand\tabulatehook####%
-% \unskip\unskip\noexpand\ifmmode\noexpand\else\endgraf\noexpand\fi\egroup
-% \noexpand\ifnum\noexpand\tabulatetype=1 \noexpand\else
-% \the\tabulateafter
-% \the\tabulateemath
-% \noexpand\fi
-% \normalunexpanded{#2}\egroup\egroup
-% &\noexpand\posttabrule\hskip\noexpand\postabskip####}}%
-
-\def\dosettabulatepreamble
- {\ifx\next\relax
- \let\nextnext\relax % == \expandafter\gobbleoneargument
- \else
- \let\nextnext\settabulatepreamble
- \ifx x\next \chardef\tabulatealign\zerocount % internal
- \else\ifx l\next \chardef\tabulatealign\plusone
- \else\ifx r\next \chardef\tabulatealign\plustwo
- \else\ifx c\next \chardef\tabulatealign\plusthree
- \else\ifx p\next \let\nextnext\gettabulateparagraph
- \else\ifx s\next \let\nextnext\gettabulatesetups
- \else\ifx w\next \let\nextnext\gettabulatewidth
- \else\ifx f\next \let\nextnext\gettabulatefont
- \else\ifx B\next \tabulatefont{\bf}%
- \else\ifx I\next \tabulatefont{\it}%
- \else\ifx S\next \tabulatefont{\sl}%
- \else\ifx T\next \tabulatefont{\tt}%
- \else\ifx R\next \tabulatefont{\rm}%
- \else\ifx m\next \tabulatebmath{$}\tabulateemath{$}%
- \else\ifx M\next \tabulatebmath{$\displaystyle}\tabulateemath{$}%
- \else\ifx h\next \let\nextnext\gettabulatehook
- \else\ifx b\next \let\nextnext\gettabulatebefore
- \else\ifx a\next \let\nextnext\gettabulateafter
- \else\ifx i\next \let\nextnext\gettabulatepreskip
- \else\ifx j\next \let\nextnext\gettabulateposskip
- \else\ifx k\next \let\nextnext\gettabulatepreposskip
- \else\ifx X\next \let\nextnext\gettabulateexit % internal
- \else\ifx e\next \appendtoks\global\tabulateequaltrue\to\tabulatesettings
- \else\ifx ~\next \appendtoks\fixedspaces\to\tabulatesettings
- \else\ifx g\next \let\nextnext\gettabulatealign
- \else\ifx .\next \def\nextnext{\gettabulatealign.}%
- \else\ifx ,\next \def\nextnext{\gettabulatealign,}%
- \else \message{unknown preamble key [\meaning\next]}%
- \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
- \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi \fi\fi
- \fi
- \nextnext}
-
-\def\dogettabulateexit
- {\let\postabskip\!!zeropoint
- \settabulatepreamble}
-
-\let\gettabulateexit\dogettabulateexit
-
-\def\gettabulatepreskip#1%
- {\doifnumberelse{#1}
- {\scratchdimen#1\tabulateunit\let\next\empty}
- {\scratchdimen.5\tabulateunit\def\next{#1}}%
- \edef\pretabskip{\the\scratchdimen}%
- \@EA\settabulatepreamble\next}
-
-\def\gettabulateposskip#1%
- {\doifnumberelse{#1}
- {\scratchdimen#1\tabulateunit\let\next\empty}
- {\scratchdimen.5\tabulateunit\def\next{#1}}%
- \edef\postabskip{\the\scratchdimen}%
- \let\gettabulateexit\settabulatepreamble
- \@EA\settabulatepreamble\next}
-
-\def\gettabulatepreposskip#1%
- {\doifnumberelse{#1}
- {\scratchdimen#1\tabulateunit\let\next\empty}
- {\scratchdimen.5\tabulateunit\def\next{#1}}%
- \edef\pretabskip{\the\scratchdimen}%
- \let\postabskip\pretabskip
- \let\gettabulateexit\settabulatepreamble
- \@EA\settabulatepreamble\next}
-
-\def\gettabulatesetups#1%
- {\setvalue{\@@tabsetups@@\the\tabulatecolumns}{\setups[#1]}%
- \settabulatepreamble}
-
-\def\gettabulatehook#1%
- {\setvalue{\@@tabhook@@\the\tabulatecolumns}{#1}%
- \settabulatepreamble}
-
-\def\gettabulatealign#1%
- {\setvalue{\@@tabalign@@\the\tabulatecolumns}{#1}%
- \settabulatepreamble}
-
-\def\gettabulatebefore#1%
- {\tabulatebefore{#1}%
- \settabulatepreamble}
-
-\def\gettabulateafter#1%
- {\tabulateafter{#1}%
- \settabulatepreamble}
-
-\def\gettabulatefont#1%
- {\tabulatefont{#1}%
- \settabulatepreamble}
-
-\def\gettabulatewidth
- {\chardef\tabulatemodus\zerocount
- \chardef\tabulatedimen\zerocount
- \doifnextcharelse(\dogettabulatewidth\settabulatepreamble}
-
-\def\gettabulateparagraph
- {\doifnextcharelse{(}
- {\chardef\tabulatemodus\plusone
- \chardef\tabulatedimen\plusone
- \dogettabulatewidth}
- {\chardef\tabulatemodus\plustwo
- \chardef\tabulatedimen\zerocount
- \settabulatepreamble}}
-
-% \def\dogettabulatewidth(#1)%
-% {\tabulatewidth#1\relax
-% \ifnum\tabulatedimen=\plusone
-% \global\advance\tabulatepwidth\tabulatewidth
-% \fi
-% \settabulatepreamble}
-
-% \def\dogettabulatewidth(#1)%
-% {\doifelse{#1}\v!passend
-% {\chardef\tabulatemodus\plusthree}
-% {\tabulatewidth#1\relax}%
-% \ifnum\tabulatedimen=\plusone
-% \global\advance\tabulatepwidth\tabulatewidth
-% \fi
-% \settabulatepreamble}
-
-% \startbuffer
-% \toplinebox{\framed[width=3cm,height=2cm]{tufte}}
-% \stopbuffer
-% \starttabulate[|p(fixed)|p|]
-% \dorecurse{100}{\NC \getbuffer \NC test \par test \par \NC \NR}
-% \stoptabulate
-% \starttabulate[|p(fit)|p|]
-% \dorecurse{100}{\NC \getbuffer \NC test \par test \par \NC \NR}
-% \stoptabulate
-
-\def\dogettabulatewidth(#1)%
- {\processallactionsinset
- [#1]%
- [ \v!fit=>\chardef\tabulatemodus\plusthree,
- \v!fixed=>\chardef\tabulatemodus\plusthree
- \tabulatenopbreaktrue,
- \s!unknown=>\tabulatewidth#1\relax]%
- \ifnum\tabulatedimen=\plusone
- \global\advance\tabulatepwidth\tabulatewidth
- \fi
- \settabulatepreamble}
-
-\def\settabulatepreamble
- {\afterassignment\dosettabulatepreamble\let\next=}
-
-\def\tabulateraggedright {\ifnum\tabulatetype=\plusone \else\raggedright \fi}
-\def\tabulateraggedcenter{\ifnum\tabulatetype=\plusone \else\raggedcenter\fi}
-\def\tabulateraggedleft {\ifnum\tabulatetype=\plusone \else\raggedleft \fi}
-\def\tabulatenotragged {\ifnum\tabulatetype=\plusone \else\notragged \fi}
-\def\tabulatehss {\ifnum\tabulatetype=\plusone \else\hss \fi}
-
-\bgroup \catcode`\|=\@@other
-
-\gdef\nexttabulate#1|%
- {\chardef\tabulatealign\@@tabulatealign
- \chardef\tabulatemodus\zerocount
- \chardef\tabulatedimen\zerocount
- \tabulatebefore \emptytoks
- \tabulateafter \emptytoks
- \tabulatebmath \emptytoks
- \tabulateemath \emptytoks
- \tabulatefont \emptytoks
- \tabulatesettings\emptytoks
- \global\advance\tabulatecolumns\plusone
- \letvalue{\@@tabsetups@@\the\tabulatecolumns}\donothing
- \settabulatepreamble#1\relax\relax % permits i without n
- \ifcase\tabulatemodus\relax
- \ifcase\tabulatealign\relax
- \dodosettabulatepreamble\empty \tabulatehss \or
- \dodosettabulatepreamble\empty \tabulatehss \or
- \dodosettabulatepreamble\tabulatehss\empty \or
- \dodosettabulatepreamble\tabulatehss\tabulatehss \fi
- \or % fixed width
- \ifcase\tabulatealign\relax
- \dodosettabulatepreamble \bskip \eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedright }\eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedleft }\eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedcenter}\eskip \fi
- \or % auto width
- \global\advance\nofautotabulate\plusone
- \ifcase\tabulatealign\relax
- \dodosettabulatepreamble \bskip \eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedright }\eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedleft }\eskip \or
- \dodosettabulatepreamble{\bskip\tabulateraggedcenter}\eskip \fi
- \or % simple
- \dodosettabulatepreamble \xbskip \xeskip
- \fi
- \futurelet\next\donexttabulate}
-
-\egroup
-
-\def\donexttabulate
- {\ifx\next\relax\else
- \expandafter\nexttabulate
- \fi}
-
-\def\splitofftabulatebox
- {\dontcomplain
- \global\setbox\tabulatebox % % % global ? % % %
- \vsplit\tablebox\tabulatecolumn to \lineheight
- \setbox\tabulatebox\normalvbox
- {\unvbox\tabulatebox}%
- \setbox\tabulatebox\hbox to \wd\tabulatebox
- {\hss\dotabulatehook{\box\tabulatebox}\hss}%
- \ht\tabulatebox\strutht
- \dp\tabulatebox\strutdp
- \box\tabulatebox}
-
-\def\dotabulatehook {\getvalue{\@@tabhook@@ \the\tabulatecolumn}}
-\def\dotabulatealign {\getvalue{\@@tabalign@@ \the\tabulatecolumn}}
-
-\def\resettabulatepheight
- {\global\tabulateminplines\plusone
- \getnoflines\tabulatemaxpheight
- \global\tabulatemaxplines\noflines
- \global\tabulatemaxpheight\zeropoint}
-
-\def\settabulatepheight
- {\scratchdimen\ht\tablebox\tabulatecolumn\relax
- \ifdim\scratchdimen>\tabulatemaxpheight
- \global\tabulatemaxpheight\scratchdimen
- \fi}
-
-\def\handletabulatepbreak
- {\TABLEnoalign
- {\ifhandletabulatepbreak
- \iftabulatenopbreak
- \dotabulatenobreak
- \else\ifnum\tabulatemaxplines>\plusone
- \ifnum\tabulateminplines=\plusone
- \dotabulatenobreak
- \fi
- \global\advance\tabulateminplines\plusone
- \ifnum\tabulateminplines=\tabulatemaxplines\relax
- \dotabulatenobreak
- \fi
- \fi \fi
- \fi}}
-
-%D \startbuffer
-%D \starttabulate[|c|p|p|]
-%D \NC \bf Alpha \NC \bf Beta \NC \bf Gamma \NC\NR
-%D \NC 1 \NC right indeed \NC definitely wrong \NC\NR
-%D \NC 2 \NC \thinrules[n=3] \NC \thinrules[n=3] \NC\NR
-%D \NC 3 \NC oh yes \NC simply no \NC\NR
-%D \NC 4 \NC very true \NC as false as can be \NC\NR
-%D \NC 5 \NC \thinrules[n=5] \NC \thinrules[n=5] \NC\NR
-%D \NC 6 \NC \thinrules[n=3] \NC \thinrules[n=4] \NC\NR
-%D \stoptabulate
-%D \stopbuffer
-%D
-%D \typebuffer {\tracetabulatetrue\getbuffer}
-%D
-%D \startbuffer
-%D \starttabulate[|c|p|p|]
-%D \NC \bf Alpha \NC \bf Beta \NC \bf Gamma \NC\NR
-%D \NC 1 \NC right indeed \NC definitely wrong \NC\NR
-%D \NC 2 \NC oh yes \NC simply no \NC\NR
-%D \NC 3 \NC very true \NC as false as can be \NC\NR
-%D \NC 4 \NC the whole truth \NC but the truth \NC\NR
-%D \stoptabulate
-%D \stopbuffer
-%D
-%D \typebuffer {\tracetabulatetrue\getbuffer}
-
-% \definetabulate
-% \redefinetabulate
-% \starttabulate[preamble]
-% \starttabulate -> \starttabulate[|l|p|]
-
-\bgroup \catcode`\|=\@@other
-
-\gdef\definetabulate
- {\dotripleempty\dodefinetabulate}
-
-\gdef\dodefinetabulate[#1][#2][#3]%
- {\ifthirdargument
- \doifundefined{\??tt#1::\c!unit}
- {\copyparameters
- [\??tt#1::][\??tt\v!tabulate::]%
- [\c!frame,\c!distance,\c!unit,\c!before,\c!bodyfont,\c!after,
- \c!inner,\c!indenting,\c!margin,\c!align,\c!header,\c!title,
- \c!rulecolor,\c!rulethickness,\c!split,EQ]}%
- \copyparameters
- [\??tt#1::#2][\??tt#1::]%
- [\c!unit,\c!distance,\c!before,\c!bodyfont,\c!after,
- \c!inner,\c!indenting,\c!frame,\c!split,\c!header,\c!title,
- \c!margin,\c!align,\c!rulecolor,\c!rulethickness,EQ]%
- \setvalue{\e!start#1::#2}{\dofinalstarttabulate[#1][#2][#3]}%
- \setvalue{\e!start#1}{\bgroup\dosubstarttabulate[#1]}%
- \letvalue{\??tt#1-\v!header}\empty
- \letvalue{\??tt#1-\v!footer }\empty
- \else\ifsecondargument
- \definetabulate[#1][][#2]%
- \else
- \definetabulate[#1][][|l|p|]%
- \fi\fi}
-
-\egroup
-
-\let\tabulateheadcontent\empty
-\let\tabulatetailcontent\empty
-
-\newconditional\tabulatesomeamble
-
-\def\checkfulltabulatecontent % - needed, else confusion with \c!header
- {\ifundefined{\??tt\currenttabulate-\v!header}%
- \let\tabulateheadcontent\empty
- \else
- \def\tabulateheadcontent
- {\TABLEnoalign{\global\settrue\tabulatesomeamble}%
- \csname\??tt\currenttabulate-\v!header\endcsname
- \TABLEnoalign{\global\setfalse\tabulatesomeamble}}%
- \fi
- \ifundefined{\??tt\currenttabulate-\v!footer}%
- \let\tabulatetailcontent\empty
- \else
- \def\tabulatetailcontent
- {\TABLEnoalign{\global\settrue\tabulatesomeamble}%
- \csname\??tt\currenttabulate-\v!footer\endcsname
- \TABLEnoalign{\global\setfalse\tabulatesomeamble}}%
- \fi}
-
-% \def\fulltabulatecontent
-% {\tabulateheadcontent
-% \tabulatecontent
-% \tabulatetailcontent}
-
-\def\fulltabulatecontent
- {\tabulateheadcontent
- \tabulatecontent
- \tabulatetailcontent
- \removefunnytabulateline}
-
-\def\removefunnytabulateline
- {\ifhmode
- \strut\crcr
- \TABLEnoalign{\kern-\lineheight}%
- \fi}
-
-\setvalue{\e!start\v!tabulatehead}%
- {\dosingleempty\dostartstarttabulatehead}
-
-\def\dostartstarttabulatehead[#1]%
- {\processcontent{\e!stop\v!tabulatehead}\next
- {\letvalue{\??tt\iffirstargument#1\else\v!tabulate\fi::-\v!header}\next}}
-
-\setvalue{\e!start\v!tabulatetail}%
- {\dosingleempty\dostartstarttabulatetail}
-
-\def\dostartstarttabulatetail[#1]%
- {\processcontent{\e!stop\v!tabulatetail}\next
- {\letvalue{\??tt\iffirstargument#1\else\v!tabulate\fi::-\v!footer}\next}}
-
-\def\dosubstarttabulate
- {\dodoubleempty\dodosubstarttabulate}
-
-\def\dodosubstarttabulate[#1][#2]%
- {\getvalue{\e!start#1::\ifundefined{\e!start#1::#2}\else#2\fi}}
-
-\setvalue{\e!start\v!tabulate}%
- {\bgroup\dodoubleempty\donormalstarttabulate}
-
-\bgroup
-
-\gdef\donormalstarttabulate[#1][#2]%
- {\ifsecondargument
- \getparameters[\??tt\v!tabulate::][#2]%
- \fi
- \iffirstargument
- \def\next{\dofinalstarttabulate[\v!tabulate][][#1]}%
- \else
- \def\next{\dofinalstarttabulate[\v!tabulate][][|l|p|]}%
- \fi
- \next}
-
-\egroup
-
-% The much neede hook:
-
-\newtoks\everytabulate
-
-% An example of its usage:
-
-\appendtoks \optimizeverbatimfalse \to \everytabulate
-\appendtoks \chardef\recodeverbatimmode\plustwo \to \everytabulate
-
-% A status variable:
-
-\chardef\tabulatepass=0
-
-\def\tabulateparameter#1{\csname\??tt\currenttabulate#1\endcsname}
-
-\bgroup
- \catcode`\|=\@@other \gdef\@@otherbar{|}
- \catcode`\|=\@@active \gdef\@@useotherbar{\let|\@@otherbar}
-\egroup
-
-\def\dofinalstarttabulate[#1][#2][#3]% identifier sub preamble
- {\edef\currenttabulate{#1::#2}%
- \ifinsidefloat \else
- \whitespace
- \tabulateparameter\c!before
- \fi
- \bgroup
- \resetcharacteralign
- % todo: spacing around tabulate when bodyfont is set
- % expansion en test needed ?
- \splittabulatetrue
- \processaction
- [\tabulateparameter\c!split]
- [% \v!yes=>\splittabulatetrue,
- % \v!repeat=>\splittabulatetrue, % todo, default yes
- \v!no=>\splittabulatefalse,
- \v!auto=>\ifinsidefloat\ifinsidesplitfloat\else\splittabulatefalse\fi\fi]%
- \doifvaluesomething{\??tt\currenttabulate\c!bodyfont}
- {\expanded{\switchtobodyfont
- [\tabulateparameter\c!bodyfont]}}%
- \postponefootnotes % new, to be tested / will be configurable
- \chardef\tabulatepass\plusone
- \widowpenalty\zerocount % otherwise lines are not broken
- \clubpenalty \zerocount % but overlap in funny ways
- \the\everytabulate
- \tabulateparameter\c!inner
- \scratchdimen\leftskip
- \advance\scratchdimen \hangindent
- \doifvalue{\??tt\currenttabulate\c!indenting}\v!yes
- {\advance\scratchdimen \parindent}% \ctxparindent
- \edef\tabulateindent{\the\scratchdimen}%
- \!!toksb\emptytoks
- \def\dorepeat*##1##2%
- {\dorecurse{##1}{\appendtoks##2\to\!!toksb}\do}%
- \def\do
- {\futurelet\next\dodo}%
- \def\dodo % \@EAEAEA gebruiken
- {\ifx\next\relax
- % exit
- \else\ifx*\next
- \let\next\dorepeat
- \else\ifx\bgroup\next
- \let\next\dododo
- \else
- \let\next\dodododo
- \fi\fi\fi
- \next}%
- \def\dododo##1%
- {\appendtoks{##1}\to\!!toksb\do}%
- \def\dodododo##1%
- {\appendtoks##1\to\!!toksb\do}%
- \global\tabulatecolumn\zerocount
-% \do#3\relax
-\bgroup\@@useotherbar\expanded{\egroup\noexpand\do#3\relax}%
- \processcontent
- {\e!stop#1}% \currenttabulate}
- \tabulatecontent
- {\@EA\processtabulate\@EA[\the\!!toksb]}}
-
-\chardef\tabulatetype=0
-
-% 0 = NC column next EQ equal column
-% 1 = RC column raw RQ equal column raw
-% 2 = HC column hook HQ equal column hook
-
-\newif\iftabulatefirstflushed
-
-\def\tabulateEQ
- {\iftabulatefirstflushed\else\tabulateparameter{EQ}\fi
- \global\tabulateequalfalse}
-
-% \def\tabulatenormalcolumn#1%
-% {&\iftabulateequal\tabulateEQ\fi&\global\chardef\tabulatetype#1&}
-%
-% \def\tabulateequalcolumn#1%
-% {&\tabulateEQ&\global\chardef\tabulatetype#1&}
-%
-% however, \unskip en \ignorespaces permit usage in complex XML/\starttabulate
-
-\def\tabulatenormalcolumn#1%
- {\unskip&\iftabulateequal\tabulateEQ\fi&\global\chardef\tabulatetype#1&%
- \ignorespaces}
-
-\def\tabulateequalcolumn#1%
- {\unskip&\tabulateEQ&\global\chardef\tabulatetype#1&%
- \ignorespaces}
-
-\def\tabulateautocolumn
- {\tabulatenormalcolumn\zerocount
- \ifnum\tabulatecolumn>\tabulatecolumns\relax
- \expandafter\NR
- \else
- \expandafter\ignorespaces % interferes with the more tricky hooks
- \fi}
-
-\def\setquicktabulate#1% see \startlegend \startgiven
- {\let#1\tabulateautocolumn
- \let\\\tabulateautocolumn}
-
-%\def\dotabulateruleseperator
-% {\vskip\strutdp}
-
-\def\dotabulateruleseperator % can be sped up
- {\bgroup
- \let\factor\!!plusone
- \scratchskip\strutdp
- \ExpandFirstAfter\processallactionsinset
- [\tabulateparameter\c!distance]
- [ \v!blank=>\scratchskip\bigskipamount,
- \v!depth=>\scratchskip\strutdp,
- \v!small=>\def\factor{.25},
- \v!medium=>\def\factor{.5},
- \v!big=>,
- \v!none=>\scratchskip\zeropoint\def\factor{0},
- \v!grid=>\scratchskip\zeropoint\def\factor{0},
- \s!unknown=>\scratchskip\commalistelement]%
- \scratchdimen\factor\scratchskip
- \ifconditional\tabulatesomeamble\kern\else\vskip\fi\scratchdimen % new
- \egroup}
-
-\def\dodotabulaterule#1%
- {\color
- [\tabulateparameter\c!rulecolor]
- {\scratchdimen\tabulateparameter\c!rulethickness#1}}
-
-\def\dotabulaterule
- {\dodotabulaterule
- {\hrule\!!height.5\scratchdimen\!!depth.5\scratchdimen\relax
- \doifvalue{\??tt\currenttabulate\c!distance}\v!grid
- {\kern-\scratchdimen}}} % experimental tm-prikkels
-
-\def\dotabulatelinerule
- {\multispan\totaltabulatecolumns % \multispan is a plain macro
- % for the moment this one
- \strut\hskip\tabulateparameter\c!margin
- % neg values are ok !
- \hskip\tabulateindent % new august 2003
- \dodotabulaterule
- {\!!heighta.5\lineheight
- \advance\!!heighta-\strutdepth
- \!!deptha-\!!heighta
- \advance\!!deptha\scratchdimen
- \leaders\hrule\!!height\!!heighta\!!depth\!!deptha\hfill}%
- \cr}
-
-%D When set to true, no (less) break optimization is done.
-
-\newif\iftolerantTABLEbreak
-
-%D The main processing macro is large but splitting it up
-%D would make things less clear.
-
-\def\doregistertabulateparoptions
- {\iftrialtypesetting \else
- \registerparoptions
- \ifinsidefloat
- % that is, an unbreakable one
- \global\let\registertabulateparoptions\empty
- \else
- % unsafe in crossing pages, at each b...
- % \global\let\registertabulateparoptions\empty
- \fi
- \fi}
-
-\appendtoks
- \global\let\registertabulateparoptions\doregistertabulateparoptions
-\to \everytabulate
-
-\newtoks\everytabulaterow
-
-\appendtoks
- \registertabulateparoptions
-\to \everytabulaterow
-
-\def\flushtabulateindent
- {\ifnum\tabulatecolumn=\zerocount
- \hbox to \tabulateindent
- {% we now have a local hsize, and since we want to
- % register positional info (i.e. real hsizes) we
- % need to reconstitute the original hsize
- \advance\hsize\tabulateindent
- % this is indeed rather messy and took a few hours
- % to dis/uncover
- \the\everytabulaterow
- \hss}%
- \fi}
-
-\def\totaltabulatecolumns{0}
-
-\def\handletabulatedigits{\digits}
-
-%D Beware, we cannot use \type {\unexpanded} on \type {\HL}
-%D cum suis, since \TEX's hard coded noalign lookahead fails
-%D on it! I mistakenly added this for a while.
-
-\chardef\tabulaterepeathead\zerocount
-
-\newcount\noftabulatelines
-\newcount\totalnoftabulatelines
-\newcount\minusnoftabulatelines
-
-\setvalue{\??tt:\c!align:\v!normal}{0}
-\setvalue{\??tt:\c!align:\v!right }{1}
-\setvalue{\??tt:\c!align:\v!left }{2}
-\setvalue{\??tt:\c!align:\v!middle}{3}
-
-\setvalue{\??tt:\c!header:\v!repeat}{\plusone}
-\setvalue{\??tt:\c!header:\v!text }{\plustwo}
-
-\bgroup \catcode`\|=\@@other
-
-\gdef\processtabulate[|#1|]% in the process of optimizing
- {\tabulateunit\tabulateparameter\c!unit
- \checkfulltabulatecontent
- \globallet\tabulateruledepth \!!zeropoint
- \globallet\tabulateruleheight\!!zeropoint
- \edef\@@tabulatealign{\executeifdefined{\??tt:\c!align:\tabulateparameter\c!align}0}%
-% \ExpandFirstAfter\processaction % use \setalignmentswitch instead
-% [\tabulateparameter\c!align]
-% [ \v!normal=>\def\@@tabulatealign{0},% = default value
-% \v!right=>\def\@@tabulatealign{1},% chardefs gebruiken
-% \v!left=>\def\@@tabulatealign{2},%
-% \v!middle=>\def\@@tabulatealign{3},%
-% \s!default=>\def\@@tabulatealign{0},%
-% \s!unknown=>\def\@@tabulatealign{0}]%
- \let\pretabskip\!!zeropoint
- \def\postabskip{.5\tabulateunit}%
- \global\tabulatecolumns\zerocount
- \global\nofautotabulate\zerocount
- \global\noftabulatelines\zerocount
- \totalnoftabulatelines\noftabulatelines
- \minusnoftabulatelines\noftabulatelines
- \global\tabulatepwidth\zeropoint
- \global\tabulateequalfalse
- \resettabulatepheight
- \ifinsidesplitfloat
- \donetrue
- \else\ifinsidefloat
- \donefalse
- \else
- \donetrue
- \fi\fi
- \ifdone
- \chardef\tabulaterepeathead\executeifdefined{\??tt:\c!header:\tabulateparameter\c!header}\zerocount
-% \processaction
-% [\tabulateparameter\c!header]
-% [\v!repeat=>\chardef\tabulaterepeathead\plusone,
-% \v!text=>\chardef\tabulaterepeathead\plustwo]%
- \fi
- \unexpanded \def\NC{\tabulatenormalcolumn0}%
- \unexpanded \def\RC{\tabulatenormalcolumn1}%
- \unexpanded \def\HC{\tabulatenormalcolumn2}%
- \unexpanded \def\EQ{\tabulateequalcolumn 0}%
- \unexpanded \def\RQ{\tabulateequalcolumn 1}%
- \unexpanded \def\HQ{\tabulateequalcolumn 2}%
- \unexpanded \def\NG{\NC\handletabulatecharalign}%
- \unexpanded \def\NN{\NC\handletabulatedigits}% new, undocumented, test first
- \unexpanded \def\ND{\NC\handletabulatedigits}% same, for old times sake
- \def\tabulaterule{\HR}% a rule with lineheight
- \def\tabulateline{\HL}% just a spaced rule
- \def\tabulateautorule{\doHR\plusone}%
- \def\tabulateautoline{\doHL\plusone}%
- \def\HR{\doHR\zerocount}
- \def\HL{\doHL\zerocount}
- \unexpanded \def\NR % next row
- {\global\advance\noftabulatelines\plusone
- \global\tabulatefirstflushedfalse
- \global\tabulateequalfalse
- \global\tabulatecolumn\zerocount
- \resettabulatepheight
- \unskip\unskip\crcr\flushtabulated
- \TABLEnoalign
- {\iftolerantTABLEbreak\else
- \ifconditional\tabulatesomeamble \ifcase\tabulaterepeathead \else
- \allowbreak
- \fi \fi
- \ifnum\noftabulatelines=\plusone
- \dotabulatenobreak
- \else\ifnum\noftabulatelines=\minusnoftabulatelines
- \ifnum\tabulatemaxplines<\plustwo
- \dotabulatenobreak
- \else
- \allowbreak % needed with pbreak prevention
- \fi
- \else
- \allowbreak % needed with pbreak prevention
- \fi\fi
- \fi
- \global\tabulatefirstflushedfalse}}%
- \let\HL\empty % not needed
- \let\SR\NR \let\AR\NR
- \let\FL\empty \let\FR\NR
- \let\ML\empty \let\MR\NR
- \let\LL\empty \let\LR\NR
- \let\doHR\gobbleoneargument
- \let\doHL\gobbleoneargument
- \global\let\flushtabulated\empty
-% \let\savedbar|\let|\nexttabulate
- \tabskip\zeropoint
- \ifdim\tabulateparameter\c!margin>\zeropoint
- \!!toksa{&\flushtabulateindent\strut##%
- \tabskip\tabulateparameter\c!margin\strut
- #\tabskip\zeropoint}%
- \else
- \!!toksa{&\flushtabulateindent\strut##%
- #\tabskip\zeropoint}%
- \fi
- \tabulatewidth\zeropoint
- % |#1X|\relax
- \nexttabulate #1X|\relax
- \scratchcounter\tabulatecolumns
- \multiply\scratchcounter3%
- \advance\scratchcounter4%
- \edef\totaltabulatecolumns{\the\scratchcounter}%
- \tabulatewidth\zeropoint
- % \dorecurse\tabulatecolumns % can be made faster
- % {\doifundefinedelse{\@@tabbox@@\recurselevel}
- % {\expandafter\newbox\csname\@@tabbox@@\recurselevel\endcsname}%
- % {\global\setbox\csname\@@tabbox@@\recurselevel\endcsname\box\voidb@x}}%
- \initializetableboxes\tabulatecolumns
- \appendtoks#\to\!!toksa
- \appendtoks\global\advance\tabulatecolumn\plusone\to\!!toksa
- \appendtoks\NC\unskip\unskip\crcr\flushtabulated\to\tabulatedummy % no count
- \global\tabulatecolumn\zerocount
- \resettabulatepheight
- \def\bskip
- {\setbox\tabulatebox\vbox\bgroup
- \global\let\tabulatehook\notabulatehook}%
- \def\eskip
- {\par\egroup
- \global\let\tabulatehook\dotabulatehook}%
- \def\xbskip
- {\hbox\bgroup\vbox\bgroup
- \global\let\tabulatehook\notabulatehook}%
- \def\xeskip
- {\par\egroup\egroup
- \global\let\tabulatehook\dotabulatehook}%
- % \let|\savedbar
- \global\let\tabulatehook\dotabulatehook
- \doifvalue{\??tt\currenttabulate\c!indenting}\v!no\forgetparindent
- \ifinsidefloat
- \let\tabulateindent\!!zeropoint
- \else
- \setlocalhsize \hsize\localhsize
- \fi
- \dontcomplain
- \forgetall % hm, interference with \forgetparindent ^^^ probably bug, to be solved
- \setbox0\vbox % outside \if because of line counting
- {\notesenabledfalse
- \let\tabulateindent\!!zeropoint
- \trialtypesettingtrue % very important
- \@EA\halign\@EA{\the\!!toksa\crcr\fulltabulatecontent\crcr}}%
- \ifnum\nofautotabulate>\zerocount
- % so, even if the natural size is larger, in the final
- % run, we force the calculated width
- \tabulatewidth\hsize
- \advance\tabulatewidth -\wd0
- \advance\tabulatewidth -\tabulatepwidth
- \ifnum\nofautotabulate>\zerocount
- \divide\tabulatewidth \nofautotabulate\relax
- \fi
- \fi
- \def\xbskip{\bskip}%
- \def\xeskip{\eskip}%
- \ifsplittabulate
- \splittopskip\strutht
- \global\let\flushtabulatedindeed\empty
- \long\def\bbskip
- {\ifvoid\tablebox\tabulatecolumn
- \ifx\flushtabulatedindeed\empty\else
- \setbox0\hbox
- \fi
- \fi}%
- \def\bskip
- {\ifvoid\tablebox\tabulatecolumn
- \global\setbox\tablebox\tabulatecolumn\vbox
- \bgroup
- \global\let\tabulatehook\notabulatehook
- \ifautotabulate\hsize\tabulatewidth\fi
- % \begstrut % interferes with pre-\pars
- % evt: \appendtoks\begstrut\to\everypar
- \ignorespaces
- \def\eskip
- {\par\egroup
- \settabulatepheight
- \global\let\tabulatehook\dotabulatehook
- \splitofftabulatebox}%
- \else
- \let\eskip\empty
- \dontcomplain
- \global\let\tabulatehook\dotabulatehook
- \expandafter\splitofftabulatebox
- \fi}%
- \gdef\flushtabulated
- {\TABLEnoalign % noalign % no interference !
- {\global\let\flushtabulatedindeed\empty
- \global\tabulatecolumn\zerocount
- \handletabulatepbreak
- \dorecurse\tabulatecolumns % was: \noftabcolumns
- {\ifvoid\tablebox\recurselevel\else
- \gdef\flushtabulatedindeed{\the\tabulatedummy}%
- \fi}%
- \global\tabulatefirstflushedtrue}%
- \flushtabulatedindeed}%
- \else
- % tabhook op alles ?
- \def\bskip
- {\vtop\bgroup
- \ifautotabulate\hsize\tabulatewidth\fi
- % \begstrut % interferes with pre-\pars
- % evt: \appendtoks\begstrut\to\everypar
- \ignorespaces}%
- \def\eskip % vertical strut added august 2003
- {\par\verticalstrut\vskip-\struttotal\egroup}%
- \fi
- \totalnoftabulatelines\noftabulatelines
- \minusnoftabulatelines\numexpr\noftabulatelines+\minusone\relax
- \global\noftabulatelines\zerocount
- \def\doHL##1% ##1 ignored
- {\TABLEnoalign
- {\csname
- \ifnum\noftabulatelines=\zerocount F\else
- \ifnum\noftabulatelines=\totalnoftabulatelines L\else
- M\fi\fi
- L\endcsname}}%
- \def\doHR##1% horizontal rule line (break untested)
- {\TABLEnoalign
- {\globallet\TABLEautoline\dotabulatelinerule
- \ifcase##1\or
- \ifnum\noftabulatelines=\zerocount
- \gdef\TABLEautoline{\TABLEnoalign{}}%
- \else\ifnum\noftabulatelines=\totalnoftabulatelines
- \gdef\TABLEautoline{\TABLEnoalign{}}%
- \fi\fi
- \fi
- \dotabulatenobreak}%
- \TABLEautoline
- \TABLEnoalign
- {\nobreak
- \ifx\TABLEautoline\dotabulatelinerule\kern-\lineheight\fi
- \ifnum\noftabulatelines=\totalnoftabulatelines
- \@EA\dotabulatenobreak
- \else
- \@EA\allowbreak
- \fi}%
- \TABLEautoline
- \TABLEnoalign
- {\dotabulatenobreak}}%
- \doifelsevalue{\??tt\currenttabulate\c!rule}\v!line
- {\let\HL \HR
- \let\tabulateautoline\tabulateautorule
- \let\tabulateline \tabulaterule}%
- {\def\HL{\doHL\zerocount}}%
- \def\tablebaselinecorrection
- {\def\dobaselinecorrection
- {\vskip-\prevdepth
- \vskip\strutdp
- \vskip\strutdp}%
- \baselinecorrection}%
- \def\FL{\TABLEnoalign
- {\ifinsidefloat\else
- \doifemptyvalue{\??tt\currenttabulate\c!before} % no expansion
- {\tablebaselinecorrection}%
- \fi
- \dotabulaterule
- \dotabulatenobreak
- \dotabulateruleseperator
- \prevdepth\strutdp
- \dotabulatenobreak}}%
- \def\ML{\TABLEnoalign
- {\dotabulateruleseperator
- \dotabulaterule
- \ifnum\noftabulatelines>\plusone
- \ifnum\noftabulatelines<\minusnoftabulatelines
- \vskip\topskip\allowbreak\vskip-\topskip
- \vskip-\tabulateparameter\c!rulethickness
- \dotabulaterule
- \fi
- \fi
- \dotabulateruleseperator}}%
- \def\LL{\TABLEnoalign
- {\dotabulatenobreak
- \dotabulateruleseperator
- \dotabulatenobreak
- \dotabulaterule
- \ifinsidefloat\else
- \doifemptyvalue{\??tt\currenttabulate\c!after} % no expansion
- {\vskip\strutdp
- \verticalstrut
- \vskip-\struttotal}%
- \fi}}%
- \chardef\tabulatepass\plustwo
- %
- \ifcase\tabulaterepeathead
- \ifinsidesplitfloat
- \setbox\tabulatebox\vbox \bgroup
- \else
- \startframedcontent[\tabulateparameter\c!frame]%
- \fi
- \else
- \setbox\tabulatebox\vbox \bgroup
- \fi
- %
- \@EA\halign\@EA{\the\!!toksa\crcr\fulltabulatecontent\crcr}%
- \prevdepth\strutdp % nog eens beter, temporary hack
- \doifvalue{\??tt\currenttabulate\c!distance}\v!grid
- {\vskip-\strutdp}% experimental tm-prikkels
- %
- \ifcase\tabulaterepeathead
- \ifinsidesplitfloat
- \egroup \splittabulatebox\tabulatebox
- \else
- \stopframedcontent
- \fi
- \else
- \egroup \splittabulatebox\tabulatebox
- \fi
- %
- \egroup
- \ifinsidefloat \else
- \tabulateparameter\c!after
- \fi
- \egroup}
-
-\egroup
-
-% \setuptabulate[split=yes,header=text,title=Vervolg van Tabel]
-%
-% % \starttabulatehead
-% % \NC test \NC hans\NC \NR
-% % \stoptabulatehead
-%
-% \starttabulate
-% \NC test \NC \input tufte \relax \NC \NR
-% \NC test \NC \input knuth \relax \NC \NR
-% \NC test \NC \input knuth \relax \NC \NR
-% \NC test \NC \input tufte \relax \NC \NR
-% \NC test \NC \input tufte \relax \NC \NR
-% \NC test \NC \input tufte \relax \NC \NR
-% \stoptabulate
-
-% \def\splittabulatebox#1% #1 <> 0/2 / derived from the one in core-ntb.tex
-% {\ifinsidefloat
-% \unvbox#1%
-% \else
-% \ifcase\tabulaterepeathead\or
-% \setbox2\copy#1%
-% \setbox2\vsplit2 to \lineheight
-% \setbox2\vbox{\unvbox2}%
-% \fi
-% \doloop
-% {\setbox0\vsplit#1 to \onepoint % \lineheight
-% \ifdim\pagegoal<\maxdimen
-% \donetrue
-% \else\ifdim\pagetotal=\zeropoint
-% \donetrue
-% \else
-% \donefalse
-% \fi\fi
-% \ifdone
-% \setbox0\vbox{\unvbox0}%
-% \dimen0\pagetotal
-% \advance\dimen0\dp0
-% \advance\dimen0\ht0
-% \ifdim\dimen0>\pagegoal
-% \bgroup \page \egroup % make sure that local vars are kept
-% \ifcase\tabulaterepeathead\or
-% \unvcopy2
-% \or
-% \hbox{\strut\tabulateparameter\c!title}%
-% \fi
-% \fi
-% \fi
-% % test this on icare checklists / quite hacky ! ! !
-% \ifdim\ht0>\tabulateparameter\c!rulethickness\else
-% \kern-2\ht0 % brrrr
-% \fi
-% %
-% \unvbox0
-% \allowbreak
-% \ifvoid#1 \exitloop \fi}%
-% \fi}
-
-\def\splittabulatebox#1% #1 <> 0/2 / derived from the one in core-ntb.tex
- {\ifinsidesplitfloat
- \dosplittabulatebox#1%
- \else\ifinsidefloat
- \unvbox#1%
- \else
- \dosplittabulatebox#1%
- \fi\fi}
-
-\def\dosplittabulatebox#1%
- {\resettsplit
- \def\tsplitminimumfreelines{2}%
- \def\tsplitminimumfreespace{0pt}%
- \setbox\tsplitcontent\box#1%
- \ifcase\tabulaterepeathead\or
- \setbox\tsplithead\vsplit\tsplitcontent to \lineheight
- \setbox\tsplithead\vbox{\unvbox\tsplithead}%
- \or
- \setbox\tsplithead\vbox{\hbox{\strut\tabulateparameter\c!title}}%
- \fi
- \handletsplit}
-
-%D \starttyping
-%D \setuptabulate[split=no,rule=line]
-%D
-%D \starttabulate
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \NC tufte \NC \input tufte \NC \NR \tabulateautorule
-%D \stoptabulate
-%D \stoptyping
-
-% \starttabulatie[|mc|]
-% \NC \digits{100.000,00} \NC\NR
-% \NC \digits{@10.000,00} \NC\NR
-% \NC \digits{@@@.100,00} \NC\NR
-% \NC \digits{@@@.@10,@@} \NC\NR
-% \NC \digits{@@@.@@1,@@} \NC\NR
-% \stoptabulatie
-%
-% \starttabulatie[|mc|]
-% \ND 100.000,00 \NC\NR
-% \ND @10.000,00 \NC\NR
-% \ND @@@.100,00 \NC\NR
-% \ND @@@.@10,@@ \NC\NR
-% \ND @@@.@@1,@@ \NC\NR
-% \stoptabulatie
-%
-% \starttabulatie[|c|]
-% \ND $100.000,00$ \NC\NR
-% \ND $@10.000,00$ \NC\NR
-% \ND $@@@.100,00$ \NC\NR
-% \ND $@@@.@10,@@$ \NC\NR
-% \ND $@@@.@@1,@@$ \NC\NR
-% \stoptabulatie
-%
-% \starttabulatie[|c|]
-% \NC $\digits 100.000,00 $ \NC\NR
-% \NC $\digits @10.000,00 $ \NC\NR
-% \NC $\digits @@@.100,00 $ \NC\NR
-% \NC $\digits @@@.@10,@@ $ \NC\NR
-% \NC $\digits @@@.@@1,@@ $ \NC\NR
-% \stoptabulatie
-%
-% \starttabulatie[|c|]
-% \NC \digits $100.000,00$ \NC\NR
-% \NC \digits $@10.000,00$ \NC\NR
-% \NC \digits $@@@.100,00$ \NC\NR
-% \NC \digits $@@@.@10,@@$ \NC\NR
-% \NC \digits $@@@.@@1,@@$ \NC\NR
-% \stoptabulatie
-
-\def\setuptabulate
- {\dotripleempty\dosetuptabulate}
-
-\def\dosetuptabulate[#1][#2][#3]%
- {\ifthirdargument
- \getparameters[\??tt#1::#2][#3]%
- \else\ifsecondargument
- \getparameters[\??tt#1::][#2]%
- \else
- \getparameters[\??tt\v!tabulate::][#1]%
- \fi\fi}
-
-\setuptabulate
- [\c!unit=1em,
- EQ={:},
- \c!frame=\v!off,
- \c!bodyfont=,
- \c!rule=\v!normal,
- \c!rulecolor=,
- \c!rulethickness=\linewidth,
- \c!inner=,
- \c!before=\blank,
- \c!after=\blank,
- \c!distance={\v!depth,\v!medium},
- \c!align=\v!normal,
- \c!margin=\!!zeropoint,
- \c!split=\v!auto,
- \c!header=\v!yes,
- \c!title=,
- \c!indenting=\v!no]
-
-\protect \endinput
diff --git a/tex/context/base/core-trf.tex b/tex/context/base/core-trf.tex
index 2049667d0..c7fa8d42b 100644
--- a/tex/context/base/core-trf.tex
+++ b/tex/context/base/core-trf.tex
@@ -14,7 +14,7 @@
%D It may be that some functionality got lost. If it concerns
%D defined features, let me know and it will be sorted out.
-\writestatus{loading}{Context Core Macros / Transformations}
+\writestatus{loading}{ConTeXt Core Macros / Transformations}
\unprotect
@@ -200,6 +200,14 @@
\xdef\finalscaleboxxscale {\withoutpt\the\dimexpr\scax\points/\plushundred\relax}%
\xdef\finalscaleboxyscale {\withoutpt\the\dimexpr\scay\points/\plushundred\relax}}
+
+\setvalue{\??xy:\c!grid:\v!yes }{\getnoflines \fighei\setevalue{\currentscaletag\c!height}{\the\noflines\lineheight}}
+\setvalue{\??xy:\c!grid:\v!height }{\getrawnoflines\fighei\setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight+\strutdepth\relax}}
+\setvalue{\??xy:\c!grid:\v!depth }{\getrawnoflines\fighei\setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight-\strutdepth\relax}}
+\setvalue{\??xy:\c!grid:\v!halfline}{\getrawnoflines\fighei\setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight+.5\lineheight\relax}}
+\setvalue{\??xy:\c!grid:\v!fit }{\getrawnoflines\fighei\setevalue{\currentscaletag\c!height}{\the\noflines\lineheight}}
+\letvalue{\??xy:\c!grid:\empty }\donothing
+
\def\checkscaleboxsettings
{\doifsomething{\scaleparameter\c!maxwidth }% can be defined in itself
{\setevalue{\currentscaletag\c!maxwidth }{\the\dimexpr\scaleparameter\c!maxwidth \relax}}%
@@ -207,19 +215,7 @@
{\setevalue{\currentscaletag\c!maxheight}{\the\dimexpr\scaleparameter\c!maxheight\relax}}%
\doifsomething{\scaleparameter\c!lines}
{\setevalue{\currentscaletag\c!height}{\the\dimexpr\scaleparameter\c!lines\lineheight\relax}}%
- \doifsomething{\scaleparameter\c!grid}
- {\processaction
- [\scaleparameter\c!grid]
- [ \v!yes=>\getnoflines\fighei
- \setevalue{\currentscaletag\c!height}{\the\noflines\lineheight},
- \v!height=>\getrawnoflines\fighei
- \setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight+\strutdepth\relax},
- \v!depth=>\getrawnoflines\fighei
- \setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight-\strutdepth\relax},
- \v!halfline=>\getrawnoflines\fighei
- \setevalue{\currentscaletag\c!height}{\the\dimexpr\noflines\lineheight+.5\lineheight\relax},
- \v!fit=>\getrawnoflines\fighei
- \setevalue{\currentscaletag\c!height}{\the\noflines\lineheight}]}}
+ \getvalue{\??xy:\c!grid:\scaleparameter\c!grid}}
\def\setscaleboxbynature % where ! ! ! ! !
{\doifsomething{\scaleparameter\c!width }{\global\scaleboxdimx\scaleparameter\c!width }%
@@ -260,7 +256,7 @@
\docalculatescaleboxnorm\scaleboxdimx\c!wfactor\c!width \hsize \hsize
\donefalse}}}%
\ifdone
-\settrue\scaleboxscalingdone
+ \settrue\scaleboxscalingdone
\ifdim\scaleboxdimx>\scaleboxhsize
\global\scaleboxdimy\zeropoint \global\scaleboxdimx\scaleboxhsize
\else\ifdim\scaleboxdimy>\scaleboxvsize
@@ -327,7 +323,7 @@
#3\relax
\fi}}
-\def\docalculatescaleboxnorm#1#2#3#4#5% 2 3 parameters
+\def\docalculatescaleboxnorm#1#2#3#4#5% 2 3 parameters (dodo:speedup)
{\processaction
[\scaleparameter#2]
[ \v!max=>\global#1\dimexpr#4\relax,
diff --git a/tex/context/base/core-tsp.tex b/tex/context/base/core-tsp.tex
deleted file mode 100644
index e9f0e7d58..000000000
--- a/tex/context/base/core-tsp.tex
+++ /dev/null
@@ -1,427 +0,0 @@
-%D \module
-%D [ file=core-tsp,
-%D version=2000.10.20,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Splitting Tables,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context OTR Macros / Floating Bodies}
-
-%D The code in this file is move here from other places.
-
-\unprotect
-
-% only to be used with single tokens (will be prim)
-
-\ifx\htdp\undefined \def\htdp#1{\dimexpr\ht#1+\dp#1\relax} \fi
-
-%D Although the name resembles floats, and therefore this should be
-%D a page module, we decided to make it core functionality because the
-%D table code depends on it. Othrwise there would be too much
-%D overloading afterwards involved. Actually, the float part is rather
-%D generic and not that related to floats.
-
-% \splitfloat [settings] {\placetable[optional args]{test}} {content}
-
-\definenumber
- [\??si]
- [\c!way=\v!by\v!text,
- \c!conversion=\@@siconversion]
-
-\def\setupfloatsplitting
- {\dodoubleargument\getparameters[\??si]}
-
-\newif\ifinsidesplitfloat % will become chardef
-
-\newtoks \everysplitfloatsetup
-
-\def\splitfloat
- {\dosingleempty\dosplitfloat}
-
-\ifx\floatcaptionsuffix\undefined \else
- \let\floatcaptionsuffix\empty % will become \splitfloatcaptionsuffix
-\fi
-
-\def\extrasplitfloatlines{0}
-
-\def\dosplitfloat[#1]#2% nog dubbele refs
- {\bgroup
- \global\setfalse\splitfloatdone
- \aftergroup\checksplitfloat
- \insidefloattrue
- \insidesplitfloattrue
- \getparameters[\??si][#1]%
- \resetnumber[\??si]%
- \def\floatcaptionsuffix{\convertednumber[\??si]}%
- \let\extrasplitfloatlines\@@silines
- \the\everysplitfloatsetup
- \def\splitfloatcommand{#2}%
- \global\settrue \onlyonesplitofffloat
- \global\setfalse\somenextplitofffloat
- \dopushsavedfloats
- \@@sibefore
- \let\next} % \bgroup
-
-\def\checksplitfloat
- {\ifconditional\splitfloatdone\else
- \blank{\tttf \getmessage\m!floatblocks{13}\empty}\blank
- \showmessage\m!floatblocks{13}\empty
- \fi}
-
-\settrue \onlyonesplitofffloat
-\setfalse\somenextplitofffloat
-
-%D When \type {inbetween} is made empty instead of the
-%D default \type {\page}, we will get delayed flushing
-%D and text may continue below the graphic.
-%D
-%D \starttyping
-%D \dorecurse{2}{\input tufte }
-%D
-%D \splitfloat[lines=auto,inbetween=]
-%D {\placetable{\dorecurse{5}{test\recurselevel\endgraf}}}
-%D {\bTABLE[split=yes]
-%D \bTR \bTD 11 \eTD \bTD \input tufte \eTD \eTR
-%D \bTR \bTD 12 \eTD \bTD \input zapf \eTD \eTR
-%D \bTR \bTD 13 \eTD \bTD \input bryson \eTD \eTR
-%D \bTR \bTD 14 \eTD \bTD test \eTD \eTR
-%D \bTR \bTD 21 \eTD \bTD \input tufte \eTD \eTR
-%D \bTR \bTD 22 \eTD \bTD \input zapf \eTD \eTR
-%D \bTR \bTD 23 \eTD \bTD \input bryson \eTD \eTR
-%D \bTR \bTD 24 \eTD \bTD test \eTD \eTR
-%D \bTR \bTD 31 \eTD \bTD \input tufte \eTD \eTR
-%D \bTR \bTD 32 \eTD \bTD \input zapf \eTD \eTR
-%D \bTR \bTD 33 \eTD \bTD \input bryson \eTD \eTR
-%D \bTR \bTD 34 \eTD \bTD test \eTD \eTR
-%D \eTABLE}
-%D
-%D \dorecurse{10}{\input tufte }
-%D \stoptyping
-
-\newconditional\splitfloatdone
-
-\def\dodowithsplitofffloat
- {\dowithnextbox
- {\forgetall
- \dontcomplain
- \global\settrue\splitfloatdone
- \chardef\nodelocationmode\zerocount % bypass auto-renumbering
- \incrementnumber[\??si]%
- \ifcase\rawnumber[\??si]\or \ifconditional\onlyonesplitofffloat
- \let\floatcaptionsuffix\empty
- \fi \fi
- \bgroup
- \ifconditional\somenextplitofffloat
- \settrue\retainfloatnumber
-\notesenabledfalse % best here, experimental, brrr; test with note in caption
- \else
- \setfalse\retainfloatnumber
- \fi
- \splitfloatcommand{\box\nextbox}%
- \egroup
- \ifconditional\somenextplitofffloat
- \doifelsenothing\@@siinbetween
- {\ifconditional\splitfloatfirstdone\else\page\fi}
- \@@siinbetween
- \else
- \@@siafter
- \dopopsavedfloats
- \doflushsavedfloats
- \fi
- \global\settrue\splitfloatfirstdone}%
- \vbox}
-
-\def\nodowithsplitofffloat
- {\dowithnextbox
- {\forgetall
- \dontcomplain
- \box\nextbox % maybe an option to unvbox
- \global\settrue\splitfloatfirstdone}%
- \vbox}
-
-\def\dochecksplitofffloat#1% box
- {\ifinsidesplitfloat
- \ifdim\ht#1=\zeropoint
- \global\setfalse\somenextplitofffloat
- \else
- \global\settrue \somenextplitofffloat
- \global\setfalse\onlyonesplitofffloat
- \fi
- \fi}
-
-\def\analyzesplitfloatcaption#1% depends on page-flt
- {\doif\extrasplitfloatlines\v!auto
- {\bgroup
- \settrue\retainfloatnumber
- \chardef\nodelocationmode\zerocount
- \forcelocalfloats
- \setuplocalfloats[\c!before=,\c!after=,\c!inbetween=]%
- \splitfloatcommand{\hbox to \wd#1{\strut}}% dummy line
- \setbox\scratchbox\vbox{\flushlocalfloats}%
- \getnoflines{\ht\scratchbox}%
- \resetlocalfloats
- \advance\noflines\minusone % compensate dummy line
- \expanded{\egroup\noexpand\edef\noexpand\extrasplitfloatlines{\the\noflines}}}}
-
-% \def\analyzesplitfloatcaption#1%
-% {\edef\extrasplitfloatlines{11}}
-
-\def\dowithsplitofffloat % nextbox
- {\ifinsidesplitfloat
- \expandafter\dodowithsplitofffloat
- \else
- \expandafter\nodowithsplitofffloat
- \fi}
-
-\def\doifnotinsidesplitfloat
- {\ifinsidesplitfloat\expandafter\gobbleoneargument\fi}
-
-%D Some defaults:
-
-\setupfloatsplitting
- [\c!conversion=\v!character, % \v!romannumerals
- \c!lines=3,
- \c!before=,
- \c!inbetween=\page,
- \c!after=]
-
-%D Table splitter, on top of previous code:
-
-\newbox\tsplitcontent
-\newbox\tsplitresult
-\newbox\tsplithead
-\newbox\tsplitnext
-\newbox\tsplittail
-
-\def\resettsplit{% only \def's starting a a new line are seen by the dep checker
- \def\tsplitminimumfreelines{0}%
- \def\tsplitminimumfreespace{0pt}%
- \setbox\tsplitcontent \vbox{}%
- \setbox\tsplitresult \vbox{}%
- \setbox\tsplithead \vbox{}%
- \setbox\tsplitnext \vbox{}%
- \setbox\tsplittail \vbox{}%
- \let\tsplitbeforeresult\donothing
- \let\tsplitafterresult \donothing
- \let\tsplitinbetween \donothing
- \let\tsplitbefore \donothing
- \let\tsplitafter \donothing
- \let\postprocesstsplit \donothing
-}
-
-\resettsplit
-
-% todo: keep tail to rest, so we need a lookahead
-
-\newconditional\splitfloatfirstdone
-
-\def\handletsplit
- {\analyzesplitfloatcaption\tsplitcontent
- \global\setfalse\splitfloatfirstdone
- \testpagesync % new, sync, but still tricky
- [\tsplitminimumfreelines]
- [\dimexpr\tsplitminimumfreespace+\extrasplitfloatlines\lineheight\relax]%
- \setbox\scratchbox\vbox{\tsplitinbetween}%
- \edef\tsplitinbetweenheight{\the\htdp\scratchbox}% etex
- \!!doneafalse
- \doloop
- {\ifinsidecolumns
- % brrr, assumes empty columns
- \global\setfalse\splitfloatfirstdone
- \scratchdimen\textheight
- \!!donectrue
- \else
- \ifconditional\splitfloatfirstdone
- \scratchdimen\textheight
- \!!donectrue
- \else\ifdim\pagegoal<\maxdimen
- \scratchdimen\dimexpr\pagegoal-\pagetotal\relax
- \!!donecfalse
- \else
- \scratchdimen\textheight
- \!!donectrue
- \fi\fi
- \fi
- \scratchdimen\dimexpr\scratchdimen-\tsplitinbetweenheight-\tsplitminimumfreespace-\extrasplitfloatlines\lineheight\relax
- \ifdim\htdp\tsplittail>\zeropoint
- \advance\scratchdimen-\htdp\tsplittail
- \fi
- \setbox\tsplitresult\vbox
- {\ifdim\ht\tsplithead>\zeropoint
- \unvcopy\tsplithead
- \tsplitinbetween
- \fi}%
- \if!!donea\else\ifdim\ht\tsplitnext>\zeropoint
- \setbox\tsplithead\box\tsplitnext
- \fi\fi
- \!!doneatrue
- \ifdim\ht\tsplitresult>\zeropoint
- \!!donedtrue % table head
- \else
- \!!donedfalse % no tablehead
- \fi
- \splittopskip\zeropoint
- \doloop
- {\setbox\scratchbox\vsplit\tsplitcontent to \onepoint % \lineheight
- \setbox\scratchbox\vbox{\unvbox\scratchbox}%
- \ifdim\dimexpr\scratchdimen-\htdp\scratchbox-\htdp\tsplitresult\relax>\zeropoint
- \setbox\tsplitresult\vbox
- {\unvbox\tsplitresult
- \tsplitinbetween
- \unvbox\scratchbox}%
- \ifvoid\tsplitcontent \exitloop \fi
- \else\if!!doned
- % we only have a tablehead so far
- \setbox\tsplitresult\vbox{\unvbox\tsplitresult\unvbox\scratchbox}%
- \exitloop
- \else\if!!donec
- % we have text height available, but the (one) cell is too
- % large to fit, so, in order to avoid loops/deadcycles we do:
- \setbox\tsplitresult\vbox
- {\unvbox\tsplitresult
- \tsplitinbetween
- \unvbox\scratchbox}%
- \exitloop
- \else
- \setbox\tsplitcontent\vbox
- {\unvbox\scratchbox
- \tsplitinbetween
- \ifvoid\tsplitcontent\else\unvbox\tsplitcontent\fi}%
- \exitloop
- \fi\fi\fi
- \!!donedfalse
- \!!donecfalse}%
- \postprocesstsplit
- \dochecksplitofffloat\tsplitcontent
- \ifvoid\tsplitcontent
- \setbox\tsplitresult\vbox
- {\unvbox\tsplitresult
- \tsplitinbetween
- \unvcopy\tsplittail}%
- \dowithsplitofffloat{\tsplitbeforeresult\box\tsplitresult\tsplitafterresult}%
- \doifnotinsidesplitfloat\tsplitafter
- \endgraf
- \exitloop
- \else
- % hack
- \ifdim\pagegoal<\maxdimen
- \global\pagegoal\dimexpr\pagegoal+\lineheight\relax % etex
- \fi
- % brrr
- \ifdim\ht\tsplitresult>\zeropoint
- \setbox\tsplitresult\vbox
- {\unvbox\tsplitresult
- \tsplitinbetween
- \unvcopy\tsplittail}%
- \dowithsplitofffloat{\tsplitbeforeresult\box\tsplitresult\tsplitafterresult}%
- \doifnotinsidesplitfloat\tsplitafter
- \endgraf
- \fi
- \ifinsidecolumns
- \doifnotinsidesplitfloat\goodbreak
- \else
- \doifnotinsidesplitfloat\page
- \fi
- \fi}%
- \global\setfalse\splitfloatfirstdone} % we can use this one for tests
-
-\protect \endinput
-
-% test cases
-
-% \setupTABLE[split=repeat]
-%
-% \input tufte \endgraf
-% \splitfloat[lines=11]
-% {\placetable{\dorecurse{10}{test\recurselevel\endgraf}}}
-% {\bTABLE\dorecurse{100}{\bTR \bTD test \eTD \eTR}\eTABLE}
-% \input tufte \page
-%
-% \input tufte \endgraf
-% \splitfloat[lines=0]
-% {}
-% {\bTABLE\dorecurse{100}{\bTR \bTD test \eTD \eTR}\eTABLE}
-% \input tufte \endgraf \page
-%
-% \input tufte \endgraf
-% \bTABLE\dorecurse{100}{\bTR \bTD test \eTD \eTR}\eTABLE
-% \input tufte \page
-
-% \setuptabulate[split=yes]
-%
-% \input tufte \endgraf
-% \splitfloat[lines=11]
-% {\placetable{\dorecurse{10}{test\recurselevel\endgraf}}}
-% {\starttabulate\dorecurse{200}{\NC test \NC test \NC \NR}\stoptabulate}
-% \input tufte \page
-%
-% \input tufte \endgraf
-% \splitfloat[lines=0]
-% {}
-% {\starttabulate\dorecurse{200}{\NC test \NC test \NC \NR}\stoptabulate}
-% \input tufte \page
-%
-% \input tufte \endgraf
-% \starttabulate\dorecurse{200}{\NC test \NC test \NC \NR}\stoptabulate
-% \input tufte \page
-
-% \setuptables[split=yes]
-%
-% \newtoks\TestToks
-%
-% \TestToks\emptytoks
-% \appendtoks\starttablehead\to\TestToks
-% \dorecurse{3}{\appendtoks\VL head \VL head \VL \SR\to\TestToks}
-% \appendtoks\stoptablehead\to\TestToks
-% \appendtoks\starttabletail\to\TestToks
-% \dorecurse{3}{\appendtoks\VL tail \VL tail \VL \SR\to\TestToks}
-% \appendtoks\stoptabletail\to\TestToks
-% \appendtoks\starttables[|c|c|]\to\TestToks
-% \dorecurse{100}{\appendtoks\VL test \VL test \VL \SR\to\TestToks}
-% \appendtoks\stoptables\to\TestToks
-%
-% \input tufte \endgraf
-% \splitfloat[lines=auto] % [lines=11]
-% {\placetable{\dorecurse{10}{test\recurselevel\endgraf}}}
-% {\the\TestToks}
-% \input tufte \page
-%
-% \input tufte \endgraf
-% \splitfloat[lines=0]
-% {}
-% {\the\TestToks}
-% \input tufte \page
-%
-% \input tufte \endgraf
-% \the\TestToks
-% \input tufte \page
-%
-% multiple floats
-%
-% \starttext
-% \dorecurse{3}{\input tufte } \endgraf
-% \dorecurse{5}{\placefigure{}{\framed[height=.5\textheight]{}}}
-% \splitfloat[lines=auto,inbetween=]
-% {\placetable{\dorecurse{5}{test\recurselevel\endgraf}}}
-% {\bTABLE[split=yes]
-% \bTR \bTD 11 \eTD \bTD \input tufte \eTD \eTR
-% \bTR \bTD 12 \eTD \bTD \input zapf \eTD \eTR
-% \bTR \bTD 13 \eTD \bTD \input bryson \eTD \eTR
-% \bTR \bTD 14 \eTD \bTD test \eTD \eTR
-% \bTR \bTD 21 \eTD \bTD \input tufte \eTD \eTR
-% \bTR \bTD 22 \eTD \bTD \input zapf \eTD \eTR
-% \bTR \bTD 23 \eTD \bTD \input bryson \eTD \eTR
-% \bTR \bTD 24 \eTD \bTD test \eTD \eTR
-% \bTR \bTD 31 \eTD \bTD \input tufte \eTD \eTR
-% \bTR \bTD 32 \eTD \bTD \input zapf \eTD \eTR
-% \bTR \bTD 33 \eTD \bTD \input bryson \eTD \eTR
-% \bTR \bTD 34 \eTD \bTD test \eTD \eTR
-% \eTABLE}
-% \dorecurse{10}{\input tufte }
-% \stoptext
diff --git a/tex/context/base/core-two.lua b/tex/context/base/core-two.lua
index 748c4eb97..5749d406d 100644
--- a/tex/context/base/core-two.lua
+++ b/tex/context/base/core-two.lua
@@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['core-two'] = {
license = "see context related readme files"
}
+local remove, concat = table.remove, table.concat
+
local texprint = tex.print
--[[ldx--
@@ -49,21 +51,21 @@ end
function jobpasses.get(id)
local jti = collected[id]
if jti and #jti > 0 then
- tex.print(table.remove(jti,1))
+ texprint(remove(jti,1))
end
end
function jobpasses.first(id)
local jti = collected[id]
if jti and #jti > 0 then
- tex.print(jti[1])
+ texprint(jti[1])
end
end
function jobpasses.last(id)
local jti = collected[id]
if jti and #jti > 0 then
- tex.print(jti[#jti])
+ texprint(jti[#jti])
end
end
@@ -84,7 +86,7 @@ end
function jobpasses.list(id)
local jti = collected[id]
if jti then
- texprint(table.concat(jti,','))
+ texprint(concat(jti,','))
end
end
@@ -92,15 +94,15 @@ function jobpasses.doifinlistelse(id,str)
local jti = collected[id]
if jti then
local found = false
- for _, v in pairs(jti) do
+ for _, v in next, jti do
if v == str then
found = true
break
end
end
- cs.testcase(found)
+ commands.testcase(found)
else
- cs.testcase(false)
+ commands.testcase(false)
end
end
@@ -119,7 +121,7 @@ end
function jobpasses.getfield(id,index,tag,default)
local jti = collected[id]
- jti = jit and jti[index]
- texprint((jit and jti[tag]) or default)
+ jti = jti and jti[index]
+ texprint((jti and jti[tag]) or default)
end
diff --git a/tex/context/base/core-two.mkii b/tex/context/base/core-two.mkii
index a14586dc4..0f2e0048c 100644
--- a/tex/context/base/core-two.mkii
+++ b/tex/context/base/core-two.mkii
@@ -11,9 +11,72 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Two Pass Data}
+
+%D This is a rather old mechanism which has not changed much over
+%D time, apart from adding a few more selectors. This code used
+%D to be part of \type {core-uti}. The following examples demonstrate
+%D the interface.
+%D
+%D \startbuffer
+%D \definetwopasslist{test-1}
+%D
+%D \gettwopassdatalist{test-1} [\twopassdatalist=]
+%D \checktwopassdata {test-1} [\twopassdata=]
+%D \checktwopassdata {test-1} [\twopassdata=]
+%D \gettwopassdata {test-1} [\twopassdata=]
+%D \gettwopassdata {test-1} [\twopassdata=]
+%D
+%D \definetwopasslist{test-2}
+%D
+%D \lazysavetwopassdata{test-2}{1}{x}
+%D \lazysavetwopassdata{test-2}{2}{y}
+%D \lazysavetwopassdata{test-2}{3}{z}
+%D
+%D \gettwopassdatalist{test-2} [\twopassdatalist=x,y,z]
+%D \checktwopassdata {test-2} [\twopassdata=x]
+%D \checktwopassdata {test-2} [\twopassdata=x]
+%D \gettwopassdata {test-2} [\twopassdata=x]
+%D \gettwopassdata {test-2} [\twopassdata=y]
+%D \gettwopassdata {test-2} [\twopassdata=z]
+%D \gettwopassdata {test-2} [\twopassdata=]
+%D
+%D \definetwopasslist{test-3}
+%D
+%D \lazysavetaggedtwopassdata{test-3}{1}{x}{a}
+%D \lazysavetaggedtwopassdata{test-3}{2}{y}{b}
+%D \lazysavetaggedtwopassdata{test-3}{3}{z}{c}
+%D
+%D \findtwopassdata{test-3}{x} [\twopassdata=a]
+%D \findtwopassdata{test-3}{y} [\twopassdata=b]
+%D \findtwopassdata{test-3}{z} [\twopassdata=c]
+%D \findtwopassdata{test-3}{w} [\twopassdata=]
+%D
+%D \definetwopasslist{test-4}
+%D
+%D \lazysavetwopassdata{test-4}{1}{A}
+%D \lazysavetwopassdata{test-4}{2}{B}
+%D \lazysavetwopassdata{test-4}{3}{C}
+%D
+%D \getfirsttwopassdata{test-4} [\twopassdata=A]
+%D \getlasttwopassdata {test-4} [\twopassdata=C]
+%D \getfirsttwopassdata{test-4} [\twopassdata=A]
+%D \getlasttwopassdata {test-4} [\twopassdata=C]
+%D \getfromtwopassdata {test-4}{1} [\twopassdata=A]
+%D \getfromtwopassdata {test-4}{3} [\twopassdata=C]
+%D \getfromtwopassdata {test-4}{2} [\twopassdata=B]
+%D \stopbuffer
+%D
+%D \getbuffer \typebuffer
+
\unprotect
-%D We save two pass information in the utility file.
+\let\alltwopasslists\empty
+\let\twopassentry \gobblethreearguments % permits loading a MK II file
+\let\twopassdata \empty
+\let\twopassdatalist\empty
+
+\newif\iftwopassdatafound
\addutilityreset{twopassentries}
diff --git a/tex/context/base/core-two.mkiv b/tex/context/base/core-two.mkiv
index f4062725a..f7dbd4c91 100644
--- a/tex/context/base/core-two.mkiv
+++ b/tex/context/base/core-two.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-two, % moved from core-uti
-%D version=2006.09.24,
+%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Two Pass Data,
%D author=Hans Hagen,
@@ -11,17 +11,82 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Two Pass Data}
+
+%D This is a rather old mechanism which has not changed much over
+%D time, apart from adding a few more selectors. This code used
+%D to be part of \type {core-uti}. The following examples demonstrate
+%D the interface.
+%D
+%D \startbuffer
+%D \definetwopasslist{test-1}
+%D
+%D \gettwopassdatalist{test-1} [\twopassdatalist=]
+%D \checktwopassdata {test-1} [\twopassdata=]
+%D \checktwopassdata {test-1} [\twopassdata=]
+%D \gettwopassdata {test-1} [\twopassdata=]
+%D \gettwopassdata {test-1} [\twopassdata=]
+%D
+%D \definetwopasslist{test-2}
+%D
+%D \lazysavetwopassdata{test-2}{1}{x}
+%D \lazysavetwopassdata{test-2}{2}{y}
+%D \lazysavetwopassdata{test-2}{3}{z}
+%D
+%D \gettwopassdatalist{test-2} [\twopassdatalist=x,y,z]
+%D \checktwopassdata {test-2} [\twopassdata=x]
+%D \checktwopassdata {test-2} [\twopassdata=x]
+%D \gettwopassdata {test-2} [\twopassdata=x]
+%D \gettwopassdata {test-2} [\twopassdata=y]
+%D \gettwopassdata {test-2} [\twopassdata=z]
+%D \gettwopassdata {test-2} [\twopassdata=]
+%D
+%D \definetwopasslist{test-3}
+%D
+%D \lazysavetaggedtwopassdata{test-3}{1}{x}{a}
+%D \lazysavetaggedtwopassdata{test-3}{2}{y}{b}
+%D \lazysavetaggedtwopassdata{test-3}{3}{z}{c}
+%D
+%D \findtwopassdata{test-3}{x} [\twopassdata=a]
+%D \findtwopassdata{test-3}{y} [\twopassdata=b]
+%D \findtwopassdata{test-3}{z} [\twopassdata=c]
+%D \findtwopassdata{test-3}{w} [\twopassdata=]
+%D
+%D \definetwopasslist{test-4}
+%D
+%D \lazysavetwopassdata{test-4}{1}{A}
+%D \lazysavetwopassdata{test-4}{2}{B}
+%D \lazysavetwopassdata{test-4}{3}{C}
+%D
+%D \getfirsttwopassdata{test-4} [\twopassdata=A]
+%D \getlasttwopassdata {test-4} [\twopassdata=C]
+%D \getfirsttwopassdata{test-4} [\twopassdata=A]
+%D \getlasttwopassdata {test-4} [\twopassdata=C]
+%D \getfromtwopassdata {test-4}{1} [\twopassdata=A]
+%D \getfromtwopassdata {test-4}{3} [\twopassdata=C]
+%D \getfromtwopassdata {test-4}{2} [\twopassdata=B]
+%D \stopbuffer
+%D
+%D \getbuffer \typebuffer
+
\unprotect
+\let\alltwopasslists\empty
+\let\twopassentry \empty
+\let\twopassentry \gobblethreearguments % permits loading a MK II file
+\let\twopassdatalist\empty
+
+\newif\iftwopassdatafound
+
\registerctxluafile{core-two}{1.001}
%D I'm not that sure if this behaves exactly like mkii. This needs a cleanup.
-\def\immediatesavetwopassdata #1#2#3{\expanded{\ctxlua {jobpasses.save('#1',"#3")}}}
-\def\savetwopassdata #1#2#3{\expanded{\ctxlatetua{jobpasses.save('#1',"#3")}}}
-\def\lazysavetwopassdata #1#2#3{\expanded{\ctxlatelua{jobpasses.save('#1',"#3")}}}
-\def\savetaggedtwopassdata #1#2#3#4{\expanded{\ctxlua {jobpasses.savetagged('#1','#3',"#4")}}}
-\def\lazysavetaggedtwopassdata#1#2#3#4{\expanded{\ctxlatelua{jobpasses.savetagged('#1','#3',"#4")}}}
+\def\immediatesavetwopassdata #1#2#3{\normalexpanded{\noexpand\ctxlua {jobpasses.save('#1',"#3")}}}
+\def\savetwopassdata #1#2#3{\normalexpanded{\noexpand\ctxlatelua{jobpasses.save('#1',"#3")}}}
+\def\lazysavetwopassdata #1#2#3{\normalexpanded{\noexpand\ctxlatelua{jobpasses.save('#1',"#3")}}}
+\def\savetaggedtwopassdata #1#2#3#4{\normalexpanded{\noexpand\ctxlua {jobpasses.savetagged('#1','#3',"#4")}}}
+\def\lazysavetaggedtwopassdata#1#2#3#4{\normalexpanded{\noexpand\ctxlatelua{jobpasses.savetagged('#1','#3',"#4")}}}
% temp hack: needs a proper \starteverytimeluacode
diff --git a/tex/context/base/core-two.tex b/tex/context/base/core-two.tex
deleted file mode 100644
index 5a845c614..000000000
--- a/tex/context/base/core-two.tex
+++ /dev/null
@@ -1,103 +0,0 @@
-%D \module
-%D [ file=core-two, % moved from core-uti
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Two Pass Data,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Two Pass Data}
-
-%D This is a rather old mechanism which has not changed much over
-%D time, apart from adding a few more selectors. This code used
-%D to be part of \type {core-uti}. The following examples demonstrate
-%D the interface.
-%D
-%D \startbuffer
-%D \definetwopasslist{test-1}
-%D
-%D \gettwopassdatalist{test-1} [\twopassdatalist=]
-%D \checktwopassdata {test-1} [\twopassdata=]
-%D \checktwopassdata {test-1} [\twopassdata=]
-%D \gettwopassdata {test-1} [\twopassdata=]
-%D \gettwopassdata {test-1} [\twopassdata=]
-%D
-%D \definetwopasslist{test-2}
-%D
-%D \lazysavetwopassdata{test-2}{1}{x}
-%D \lazysavetwopassdata{test-2}{2}{y}
-%D \lazysavetwopassdata{test-2}{3}{z}
-%D
-%D \gettwopassdatalist{test-2} [\twopassdatalist=x,y,z]
-%D \checktwopassdata {test-2} [\twopassdata=x]
-%D \checktwopassdata {test-2} [\twopassdata=x]
-%D \gettwopassdata {test-2} [\twopassdata=x]
-%D \gettwopassdata {test-2} [\twopassdata=y]
-%D \gettwopassdata {test-2} [\twopassdata=z]
-%D \gettwopassdata {test-2} [\twopassdata=]
-%D
-%D \definetwopasslist{test-3}
-%D
-%D \lazysavetaggedtwopassdata{test-3}{1}{x}{a}
-%D \lazysavetaggedtwopassdata{test-3}{2}{y}{b}
-%D \lazysavetaggedtwopassdata{test-3}{3}{z}{c}
-%D
-%D \findtwopassdata{test-3}{x} [\twopassdata=a]
-%D \findtwopassdata{test-3}{y} [\twopassdata=b]
-%D \findtwopassdata{test-3}{z} [\twopassdata=c]
-%D \findtwopassdata{test-3}{w} [\twopassdata=]
-%D
-%D \definetwopasslist{test-4}
-%D
-%D \lazysavetwopassdata{test-4}{1}{A}
-%D \lazysavetwopassdata{test-4}{2}{B}
-%D \lazysavetwopassdata{test-4}{3}{C}
-%D
-%D \getfirsttwopassdata{test-4} [\twopassdata=A]
-%D \getlasttwopassdata {test-4} [\twopassdata=C]
-%D \getfirsttwopassdata{test-4} [\twopassdata=A]
-%D \getlasttwopassdata {test-4} [\twopassdata=C]
-%D \getfromtwopassdata {test-4}{1} [\twopassdata=A]
-%D \getfromtwopassdata {test-4}{3} [\twopassdata=C]
-%D \getfromtwopassdata {test-4}{2} [\twopassdata=B]
-%D \stopbuffer
-%D
-%D \getbuffer \typebuffer
-
-\unprotect
-
-\let\alltwopasslists\empty
-\let\twopassentry \empty
-\let\twopassdata \empty
-\let\twopassdatalist\empty
-
-\newif\iftwopassdatafound
-
-\let\savetwopassdata \gobblethreearguments
-\let\immediatesavetwopassdata \gobblethreearguments
-\let\lazysavetwopassdata \gobblethreearguments
-\let\savetaggedtwopassdata \gobblefourarguments
-\let\lazysavetaggedtwopassdata\gobblefourarguments
-
-\let\twopassentry \gobblethreearguments % permits loading a MK II file
-\let\loadtwopassdata\relax % permits loading a MK II file
-
-\let\definetwopasslist\gobbleoneargument
-
-\def\gettwopassdata #1{\let\twopassdata \empty \twopassdatafoundfalse}
-\def\checktwopassdata #1{\let\twopassdata \empty \twopassdatafoundfalse}
-\def\findtwopassdata #1#2{\let\twopassdata \empty \twopassdatafoundfalse}
-\def\getlasttwopassdata #1{\let\twopassdata \empty \twopassdatafoundfalse}
-\def\getfromtwopassdata #1#2{\let\twopassdata \empty \twopassdatafoundfalse}
-\def\gettwopassdatalist #1{\let\twopassdatalist\empty \twopassdatafoundfalse}
-\def\getnamedtwopassdatalist#1#2{\let#1 \empty \twopassdatafoundfalse}
-\def\doifelseintwopassdata #1#2{\secondoftwoarguments}
-
-\loadmarkfile{core-two}
-
-\protect \endinput
diff --git a/tex/context/base/core-uti.lua b/tex/context/base/core-uti.lua
index fc99f67cb..20c63efd1 100644
--- a/tex/context/base/core-uti.lua
+++ b/tex/context/base/core-uti.lua
@@ -17,12 +17,13 @@ utility file under different setups, we now load a table once. This
saves much runtime but at the cost of more memory usage.
--ldx]]--
-local format = string.format
+local sort, concat, format = table.sort, table.concat, string.format
+local next, type, tostring = next, type, tostring
if not jobs then jobs = { } end
if not job then jobs['main'] = { } end job = jobs['main']
-jobs.version = 1.01
+jobs.version = 1.10
--[[ldx--
Variables are saved using in the previously defined table and passed
@@ -32,39 +33,206 @@ directly access the variable using a call.
local savelist, comment = { }, { }
-function job.comment(...)
- for _, str in ipairs({...}) do
- comment[#comment+1] = str
- end
+function job.comment(str)
+ comment[#comment+1] = str
end
job.comment(format("version: %1.2f",jobs.version))
job._save_, job._load_ = { }, { }
+function job.initialize(loadname,savename)
+ job.load(loadname)
+ main.register_stop_actions(function()
+ if not status.lasterrorstring or status.lasterrorstring == "" then
+ job.save(savename)
+ end
+ end)
+end
+
+function job.register(...) -- collected, tobesaved, initializer, finalizer
+ savelist[#savelist+1] = { ... }
+end
+
+-- as an example we implement variables
+
+jobvariables = jobvariables or { }
+jobvariables.collected = jobvariables.collected or { }
+jobvariables.tobesaved = jobvariables.tobesaved or { }
+
+jobvariables.checksums = jobvariables.checksums or { }
+
+if not jobvariables.checksums.old then jobvariables.checksums.old = md5.HEX("old") end
+if not jobvariables.checksums.new then jobvariables.checksums.new = md5.HEX("new") end
+
+job.register('jobvariables.checksums', jobvariables.checksums)
+
+local function initializer()
+ local r = jobvariables.collected.randomseed
+ if not r then
+ r = math.random()
+ end
+ math.randomseed(r)
+ jobvariables.tobesaved.randomseed = r
+ for cs, value in next, jobvariables.collected do
+ tex.sprint(format("\\xdef\\%s{%s}",cs,value))
+ end
+end
+
+job.register('jobvariables.collected', jobvariables.tobesaved, initializer)
+
+function jobvariables.save(cs,value)
+ jobvariables.tobesaved[cs] = value
+end
+
+-- experiment (bugged: some loop in running)
+
+-- for the moment here, very experimental stuff
+
+packer = packer or { }
+packer.version = 1.00
+
+local function hashed(t)
+ local s = { }
+ for k, v in next, t do
+ if type(v) == "table" then
+ s[#s+1] = k.."={"..hashed(v).."}"
+ else
+ s[#s+1] = k.."="..tostring(v)
+ end
+ end
+ sort(s)
+ return concat(s,",")
+end
+
+local function pack(t,keys,hash,index)
+ for k,v in next, t do
+ if type(v) == "table" then
+ pack(v,keys,hash,index)
+ end
+ if keys[k] and type(v) == "table" then
+ local h = hashed(v)
+ local i = hash[h]
+ if not i then
+ i = #index+1
+ index[i] = v
+ hash[h] = i
+ end
+ t[k] = i
+ end
+ end
+end
+
+local function unpack(t,keys,index)
+ for k,v in next, t do
+ if keys[k] and type(v) == "number" then
+ local iv = index[v]
+ if iv then
+ v = iv
+ t[k] = v
+ end
+ end
+ if type(v) == "table" then
+ unpack(v,keys,index)
+ end
+ end
+end
+
+function packer.new(keys,version)
+ return {
+ version = version or packer.version,
+ keys = table.tohash(keys),
+ hash = { },
+ index = { },
+ }
+end
+
+function packer.pack(t,p,shared)
+ if shared then
+ pack(t,p.keys,p.hash,p.index)
+ elseif not t.packer then
+ pack(t,p.keys,p.hash,p.index)
+ if #p.index > 0 then
+ t.packer = {
+ version = p.version or packer.version,
+ keys = p.keys,
+ index = p.index,
+ }
+ end
+ p.hash, p.index = { }, { }
+ end
+end
+
+function packer.unpack(t,p,shared)
+ if shared then
+ if p then
+ unpack(t,p.keys,p.index)
+ end
+ else
+ local tp = t.packer
+ if tp then
+ if tp.version == (p and p.version or packer.version) then
+ unpack(t,tp.keys,tp.index)
+ else
+ -- fatal error, wrong version
+ end
+ t.packer = nil
+ end
+ end
+end
+
+function packer.strip(p)
+ p.hash = nil
+end
+
+
+local packlist = {
+ "numbers",
+ "metadata",
+ "sectiondata",
+ "prefixdata",
+ "numberdata",
+ "pagedata",
+ "directives",
+ "specification",
+--~ "references",
+}
+
+local jobpacker = packer.new(packlist,1.01)
+
+job.pack = true
+
function job.save(filename)
- input.starttiming(job._save_)
+ statistics.starttiming(job._save_)
local f = io.open(filename,'w')
if f then
- for _, str in ipairs(comment) do
- f:write("-- ",str,"\n")
+ for c=1,#comment do
+ f:write("-- ",comment[c],"\n")
end
f:write("\n")
- for _, list in ipairs(savelist) do
+ for l=1,#savelist do
+ local list = savelist[l]
local target, data, finalizer = list[1], list[2], list[4]
if type(finalizer) == "function" then
finalizer()
end
+ if job.pack then
+ packer.pack(data,jobpacker,true)
+ end
f:write(aux.definetable(target),"\n")
f:write(table.serialize(data,target,true,true),"\n")
end
+ if job.pack then
+ packer.strip(jobpacker)
+ f:write(table.serialize(jobpacker,"job.packer",true,true),"\n")
+ end
f:close()
end
- input.stoptiming(job._save_)
+ statistics.stoptiming(job._save_)
end
function job.load(filename)
- input.starttiming(job._load_)
+ statistics.starttiming(job._load_)
local data = io.loaddata(filename)
if data and data ~= "" then
local version = tonumber(data:match("^-- version: ([%d%.]+)"))
@@ -72,46 +240,51 @@ function job.load(filename)
logs.report("job","version mismatch with jobfile: %s <> %s", version or "?", jobs.version)
else
loadstring(data)()
- for _, list in ipairs(savelist) do
+ for l=1,#savelist do
+ local list = savelist[l]
local target, initializer = list[1], list[3]
+ packer.unpack(aux.accesstable(target),job.packer,true)
if type(initializer) == "function" then
initializer(aux.accesstable(target))
end
end
+ job.packer = nil
end
end
- input.stoptiming(job._load_)
-end
-
-function job.initialize(loadname,savename)
- job.load(loadname)
- table.insert(input.stop_actions, function()
- if not status.lasterrorstring or status.lasterrorstring == "" then
- job.save(savename)
- end
- end)
+ statistics.stoptiming(job._load_)
end
-function job.register(...) -- collected, tobesaved, initializer, finalizer
- savelist[#savelist+1] = { ... }
-end
+-- eventually this will end up in strc-ini
--- as an example we implement variables
-
-jobvariables = jobvariables or { }
-jobvariables.collected = jobvariables.collected or { }
-jobvariables.tobesaved = jobvariables.tobesaved or { }
+statistics.register("startup time", function()
+ if statistics.elapsedindeed(ctx) then
+ return format("%s seconds (including runtime option file processing)", statistics.elapsedtime(ctx))
+ end
+end)
-local function initializer()
- for cs, value in pairs(jobvariables.collected) do
- tex.sprint(string.format("\\xdef\\%s{%s}",cs,value))
+statistics.register("jobdata time",function()
+ if statistics.elapsedindeed(job._save_) or statistics.elapsedindeed(job._load_) then
+ return format("%s seconds saving, %s seconds loading", statistics.elapsedtime(job._save_), statistics.elapsedtime(job._load_))
end
-end
+end)
-job.register('jobvariables.collected', jobvariables.tobesaved, initializer)
+statistics.register("callbacks", function()
+ local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
+ local pages = tex.count['realpageno'] - 1
+ if pages > 1 then
+ return format("direct: %s, indirect: %s, total: %s (%i per page)", total-indirect, indirect, total, total/pages)
+ else
+ return format("direct: %s, indirect: %s, total: %s", total-indirect, indirect, total)
+ end
+end)
-function jobvariables.save(cs,value)
- jobvariables.tobesaved[cs] = value
+function statistics.formatruntime(runtime)
+ local shipped = tex.count['nofshipouts']
+ local pages = tex.count['realpageno'] - 1
+ if shipped > 0 or pages > 0 then
+ local persecond = shipped / runtime
+ return format("%s seconds, %i processed pages, %i shipped pages, %.3f pages/second",runtime,pages,shipped,persecond)
+ else
+ return format("%s seconds",runtime)
+ end
end
-
-
diff --git a/tex/context/base/core-uti.mkii b/tex/context/base/core-uti.mkii
index 8d8fc6dcb..b348ba358 100644
--- a/tex/context/base/core-uti.mkii
+++ b/tex/context/base/core-uti.mkii
@@ -11,6 +11,154 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Utility File Handling}
+
+\unprotect
+
+% todo : safe lan etc too
+% todo : load all commands at once (tok)
+% todo : merge status info patch into tui file (language, encoding, etc),
+
+% Utility-file
+%
+% De onderstaande macro's ondersteunen het gebruik van de
+% zogeheten utility-file. Alle extern onder te brengen
+% informatie wordt opgeslagen in de file \jobname.tui, tenzij
+% er selectief pagina's worden gezet. In dat geval wordt de
+% file \jobname.tmp gebruikt. Informatie wordt ingelezen uit
+% de file \jobname.tuo, welke door TeXUtil wordt aangemaakt.
+
+\edef\utilityversion{1998.07.07} % was: 1996.03.15 % status variables
+\edef\utilityversion{1998.12.20} % was: 1998.07.07 % index attributes
+\edef\utilityversion{2003.07.19} % was: 1998.12.20 % object pages
+\edef\utilityversion{2006.06.23} % was: 2003.07.19 % -- instead of :
+\edef\utilityversion{2006.09.21} % pt in pos
+\edef\utilityversion{2008.10.14} % moved more to lua in mkiv
+
+% Bepaalde commando's worden als string weggeschreven. Deze
+% zijn aan het eind van deze file gedefinieerd.
+
+% Om een opbouw van spaties te voorkomen (???) moet ^^M een
+% andere betekenis krijgen:
+%
+% \catcode`\^^M=14 (comment)
+%
+% read file
+%
+% \catcode`\^^M=5 (end of line)
+
+\newwrite\utility@tui
+\newif\ifutilitydone
+
+\ifx\sectionseparator\undefined \def\sectionseparator{-} \fi
+
+\def\@@utilityerrormessage
+ {\showmessage\m!systems8\empty
+ \globallet\@@utilityerrormessage\relax}
+
+\def\thisisutilityversion#1%
+ {\doifelse\utilityversion{#1}%
+ {\checksectionseparator}
+ {\@@utilityerrormessage\resetutilities\endinput}}
+
+\def\checksectionseparator % catches backward compatibility conflict
+ {}% \doifnot\sectionseparator:\endinput} % this dependency may go in a few years
+
+\def\dosplitofffoliopart[#1--#2--#3]{#3}
+
+\def\thisissectionseparator#1%
+ {\bgroup
+ \globallet\checksectionseparator\relax
+ \defconvertedcommand \asciia\sectionseparator
+ \defconvertedargument\asciib{#1}%
+ \expanded{\gdef\noexpand\dosplitofffoliopart[####1\sectionseparator
+ \sectionseparator####2\sectionseparator\sectionseparator####3]{####3}}%
+ \ifx\asciia\asciib
+ \egroup
+ \else
+ \egroup
+ % todo \@@utilityerrormessage
+ \resetutilities
+ \endinput
+ \fi}
+
+\def\writeutility {\write\utility@tui}
+\def\writeutilitycommand#1{\write\utility@tui{c \string#1}}
+
+% less tokens
+%
+% \def\immediatewriteutility {\immediate\writeutility}
+% \def\immediatewriteutilitycommand{\immediate\writeutilitycommand}
+%
+% more flexible (for overloading)
+
+\def\immediatewriteutility {\immediate\write\utility@tui}
+\def\immediatewriteutilitycommand#1{\immediate\write\utility@tui{c \string#1}}
+
+% as in:
+
+\def\cwriteutility#1%
+ {\write\utility@tui{\noexpand\checkedutility{\number\nofshipouts}{#1}}}
+
+\def\cwriteutilitycommand#1%
+ {\write\utility@tui{\noexpand\checkedutility{\number\nofshipouts}{c \string#1}}}
+
+\let\checkedutility\secondoftwoarguments
+
+\def\docheckedutility#1#2{\ifnum#1=\nofshipouts#2\else\letterpercent\fi}
+
+\prependtoks
+ \let\checkedutility\docheckedutility
+\to \everybeforeshipout
+
+% Better use marks.
+
+\newtoks \everyopenutilities
+\newtoks \everycloseutilities
+\newtoks \everycheckutilities
+
+\def\openutilities {\the\everyopenutilities } % \global\everyopenutilities\emptytoks
+\def\closeutilities{\the\everycloseutilities}
+\def\checkutilities{\the\everycheckutilities}
+
+\appendtoks
+ \let\writeutility \cwriteutility
+ \let\writeutilitycommand \cwriteutilitycommand
+ %\let\immediatewriteutility \cimmediatewriteutility
+ %\let\immediatewriteutilitycommand\cimmediatewriteutilitycommand
+ \let\checkutilities \relax
+\to \everycheckutilities
+
+\appendtoks
+ \immediate\openout\utility@tui\jobname.\f!inputextension
+ \immediatewriteutilitycommand{\thisissectionseparator{\sectionseparator}}% for the moment
+ \immediatewriteutilitycommand{\thisisutilityversion {\utilityversion }}% in this order
+\to \everyopenutilities
+
+\appendtoks
+% \immediate\closeout\utility@tui % niet echt nodig
+ \reportutilityproblems
+ % should be a message :
+ \let\writeutilitycommand \gobbleoneargument
+ \let\writeutility \gobbleoneargument
+ \let\immediatewriteutilitycommand\gobbleoneargument
+ \let\immediatewriteutility \gobbleoneargument
+\to \everycloseutilities
+
+% \def\reopenutilities
+% {\immediate\closeout\utility@tui
+% \openutilities}
+
+\def\abortutilitygeneration
+ {\immediatewriteutilitycommand\utilitygenerationaborted
+ \immediatewriteutility{q {quit}}}
+
+\def\utilitygenerationaborted
+ {\showmessage\m!systems{21}\empty
+ \globallet\utilitygenerationaborted\endinput
+ \gdef\reportutilityproblems{\showmessage\m!systems{22}\empty}%
+ \endinput}
+
\def\savecurrentvalue#1#2%
{\immediatewriteutilitycommand{\initializevariable\string#1{#2}}}
@@ -20,6 +168,46 @@
\globallet\initializevariable\gobbletwoarguments
\to \everyafterutilityread
+\let\reportutilityproblems\relax
+
+\newtoks\utilityresetlist
+
+\def\addutilityreset#1%
+ {\@EA\appendtoks\csname\s!reset#1\endcsname\to\utilityresetlist}
+
+\def\resetutilities
+ {\the\utilityresetlist}
+
+% #1=type #2=file #3=melding #4=voor #5=na
+%
+% Er wordt gegroepeerd. Als binnen een lijst (bijvoorbeeld) de
+% \leftskip is aangepast, maar nog geen \par is gegeven, dan
+% geldt buiten de groep de oude \leftskip. Aan #5 kan dan
+% ook \par worden meegegeven om de paragraaf af te sluiten.
+
+\newif\ifdoinpututilities
+\newif\ifunprotectutilities % voor't geval er \v!xxxxxx's zijn
+
+\def\currentutilityfilename{\jobname}
+
+% we need to pop and push, else problems with reading
+% utility files (toc) in xml mode and (e.g.) in a toc
+% entry doing a doifmode
+%
+% the following is not ok because we have no way to signal
+% xml content (yet), so for the moment we use this:
+
+\appendtoks
+ \ifprocessingXML
+ \processingXMLfalse
+ \enableXML
+ \catcode`\\=\@@escape
+ \catcode`\{=\@@begingroup
+ \catcode`\}=\@@endgroup
+ \catcode`\%=\@@comment\relax
+ \fi
+\to \everybeforeutilityread
+
\edef\testbytesequence
{\rawcharacter{7}%
\rawcharacter{27}%
@@ -36,12 +224,123 @@
\fi
\global\let\thisisbytesequence\gobbleoneargument}
-\beginXETEX
+\ifnum\texengine=\xetexengine
\let\testbytesequence\empty
-\endXETEX
+\fi
\appendtoks
\immediatewriteutilitycommand{\thisisbytesequence{\testbytesequence}}%
\to \everyopenutilities
-\endinput
+\long\def\doutilities#1#2#3#4#5% % introduceren in utility file
+ {\resetutilities
+ % more than one utility thing can be handled in one pass,
+ % for instance lists, so we process ##1 as list
+ \def\douticommand##1{\csname\s!set##1\endcsname}%
+ \processcommacommand[#1]\douticommand
+ \begingroup
+ \def\currentutilityfilename{#2}%
+ \notesenabledfalse
+ \doinpututilitiestrue
+ \global\utilitydonefalse
+ \pushendofline % geeft problemen zodra andere file wordt ingelezen
+ \pushcatcodetable
+ \setcatcodetable\ctxcatcodes
+ \ifunprotectutilities % nog nodig ?
+ \unprotect
+ \fi
+ #4%
+ \the\everybeforeutilityread
+ \readjobfile{#2.\f!outputextension}\donothing\donothing
+ \the\everyafterutilityread
+ \popcatcodetable
+ #5%
+ \relax
+ \ifunprotectutilities
+ \protect
+ \fi
+ \popendofline
+ \ifutilitydone\else
+ \doifsomething{#3}
+ {\showmessage\m!systems9{{#3}}%
+ \doifconcepttracing
+ {\blank
+ \setmessagetext\m!systems9{{#3}}%
+ \type{[\currentmessagetext]}%
+ \blank}}%
+ \fi
+ \endgroup}
+
+% Default-instellingen (verborgen)
+
+\prependtoks \resetutilities \to \everyjob
+
+% Experiment
+%
+% \installprogram{Hello World}
+% \installprogram[hw]{Hello World}
+% \installedprogram[hw]
+
+\def\installprogram
+ {\dosingleempty\doinstallprogram}
+
+\def\doinstallprogram[#1]#2%
+ {\doifelsenothing{#1}
+ {\dodoinstallprogram{#2}}
+ {\setvalue{\??up#1}{\dodoinstallprogram{#2}}}}
+
+\def\dodoinstallprogram#1%
+ {\immediatewriteutility{e p {#1}}}
+
+\def\installedprogram[#1]%
+ {\getvalue{\??up#1}}
+
+% \writeplugindata{texutil}{{alpha}}
+% \writeplugindata{texutil}{{beta}}
+% \writeplugindata{texutil}{{gamma}}
+% \writeplugindata{texutil}{{delta}}
+%
+% \loadplugindata {plugintest}
+
+\def\immediatewriteplugindata#1#2%
+ {\immediatewriteutility{p u {#1} #2}}
+
+\def\writeplugindata#1#2%
+ {\writeutility{p u {#1} #2}}
+
+\def\loadplugindata#1%
+ {\doutilities{#1}\jobname\empty\relax\relax}
+
+% \plugincommand{\command{}{}{}}
+%
+% this way we can catch undefined commands
+
+\long\def\plugincommand#1%
+ {\doplugincommand#1\relax}
+
+\long\def\doplugincommand#1%
+ {\ifx#1\undefined
+ \expandafter\noplugincommand
+ \else
+ \expandafter#1%
+ \fi}
+
+\long\def\noplugincommand#1\relax
+ {}
+
+% \addutilityreset{plugintest}
+%
+% \def\resetplugintest{\let\plugintest\gobbletwoarguments}
+% \def\setplugintest {\let\plugintest\writestatus}
+%
+% \installplugin
+% {plugintest}
+% {\let\plugintest\gobbletwoarguments}
+% {\let\plugintest\writestatus}
+
+\long\def\installplugin#1#2#3%
+ {\addutilityreset {#1}%
+ \long\setvalue{\s!reset#1}{#2}%
+ \long\setvalue{\s!set #1}{#3}}
+
+\protect \endinput
diff --git a/tex/context/base/core-uti.mkiv b/tex/context/base/core-uti.mkiv
index ddbc47311..77cf91dd9 100644
--- a/tex/context/base/core-uti.mkiv
+++ b/tex/context/base/core-uti.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-uti,
-%D version=2006.09.19,
+%D version=1997.03.31, % 2006.09.19 mkiv
%D title=\CONTEXT\ Core Macros,
%D subtitle=Utility File Handling,
%D author=Hans Hagen,
@@ -11,67 +11,86 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
-
-\registerctxluafile{core-uti}{1.001}
+%D Most will disappear!
-%D We need a way to pass strings safely to \LUA\ without the
-%D need for tricky escaping. Compare:
-%D
-%D \starttyping
-%D \ctxlua {something("anything tricky can go here")}
-%D \ctxlua {something([\luastringsep[anything tricky can go here]\luastringsep])}
-%D \stoptyping
+\writestatus{loading}{ConTeXt Core Macros / Utility File Handling}
-\def\luastringsep{===} % this permits \typefile{self} otherwise nested b/e sep problems
-
-\edef\!!bs{[\luastringsep[}
-\edef\!!es{]\luastringsep]}
-
-%D We have a the following available as primitive so there is no need
-%D for it:
-%D
-%D \starttyping
-%D \long\edef\luaescapestring#1{\!!bs#1\!!es}
-%D \stoptyping
+\unprotect
-% variables
+\registerctxluafile{core-uti}{1.001}
\def\savecurrentvalue#1#2%
{\ctxlua{jobvariables.save("\strippedcsname#1","#2")}}
-% temp
-
+\let\initializevariable\gobbletwoarguments % mkii/mkiv
\let\thisisbytesequence\gobbleoneargument
-% wrong place but we need to have it someplace
+\appendtoks
+ \globallet\initializevariable\gobbletwoarguments
+\to \everyafterutilityread
\appendtoks
- \ctxlua{input.storage.dump()}%
+ \ctxlua{storage.dump()}%
\to \everydump
\appendtoks
- \ctxlua{input.storage.finalize()}%
+ \ctxlua{storage.finalize()}%
\to \everyfinalizeluacode
\appendtoks
\ctxlua{nodes.cleanup_reserved()}%
\to \everydump
-% new
-
-% this loads and also sets the saving
-
\appendtoks
\ctxlua {
- job.comment(
- "file: \jobname",
- "format: \contextformat",
- "stamp: \contextversion",
- "escape: \!!bs\space...\space\!!es"
- )
+ job.comment("file: \jobname")
+ job.comment("format: \contextformat")
+ job.comment("stamp: \contextversion")
+ job.comment("escape: \!!bs\space...\space\!!es")
job.initialize("\jobname.tuc","\jobname.tua")
}%
\to \everystarttext
+% cleaner, for the moment
+
+% \appendtoks
+% \ctxlua {
+% os.remove("\jobname.tui")
+% os.remove("\jobname.tuo")
+% }%
+% \to \everystarttext
+
+% keep this for a while
+
+\newif\ifutilitydone
+\newif\ifdoinpututilities
+\newif\ifunprotectutilities
+
+\let\writeutility \gobbleoneargument
+\let\writeutilitycommand \gobbleoneargument
+\let\immediatewriteutility \gobbleoneargument
+\let\immediatewriteutilitycommand\gobbleoneargument
+\let\cwriteutility \gobbleoneargument
+\let\cwriteutilitycommand \gobbleoneargument
+\let\checkedutility \secondoftwoarguments
+\let\doutilities \gobblefivearguments
+\let\abortutilitygeneration \relax
+
+\newtoks \everyopenutilities \let\openutilities \relax
+\newtoks \everycloseutilities \let\closeutilities\relax
+\newtoks \everycheckutilities \let\checkutilities\relax
+\newtoks \utilityresetlist
+
+\def\addutilityreset#1{\@EA\appendtoks\csname\s!reset#1\endcsname\to\utilityresetlist}
+\def\resetutilities {\the\utilityresetlist}
+
+\def\currentutilityfilename{\jobname}
+
+\prependtoks \resetutilities \to \everyjob
+
+\def\installprogram {\dosingleempty\doinstallprogram}
+\def\doinstallprogram[#1]{\gobbleoneargument}
+\def\installedprogram[#1]{}
+\let\installplugin \gobblethreearguments
+
\protect \endinput
diff --git a/tex/context/base/core-uti.tex b/tex/context/base/core-uti.tex
deleted file mode 100644
index e84a6db5c..000000000
--- a/tex/context/base/core-uti.tex
+++ /dev/null
@@ -1,382 +0,0 @@
-%D \module
-%D [ file=core-uti,
-%D version=1997.03.31,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Utility File Handling,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Utility File Handling}
-
-\unprotect
-
-% todo : safe lan etc too
-% todo : load all commands at once (tok)
-% todo : merge status info patch into tui file (language, encoding, etc),
-
-% Utility-file
-%
-% De onderstaande macro's ondersteunen het gebruik van de
-% zogeheten utility-file. Alle extern onder te brengen
-% informatie wordt opgeslagen in de file \jobname.tui, tenzij
-% er selectief pagina's worden gezet. In dat geval wordt de
-% file \jobname.tmp gebruikt. Informatie wordt ingelezen uit
-% de file \jobname.tuo, welke door TeXUtil wordt aangemaakt.
-
-\edef\utilityversion{1998.07.07} % was: 1996.03.15 % status variables
-\edef\utilityversion{1998.12.20} % was: 1998.07.07 % index attributes
-\edef\utilityversion{2003.07.19} % was: 1998.12.20 % object pages
-\edef\utilityversion{2006.06.23} % was: 2003.07.19 % -- instead of :
-\edef\utilityversion{2006.09.21} % pt in pos
-\edef\utilityversion{2008.10.14} % moved more to lua in mkiv
-
-% Bepaalde commando's worden als string weggeschreven. Deze
-% zijn aan het eind van deze file gedefinieerd.
-
-% Om een opbouw van spaties te voorkomen (???) moet ^^M een
-% andere betekenis krijgen:
-%
-% \catcode`\^^M=14 (comment)
-%
-% read file
-%
-% \catcode`\^^M=5 (end of line)
-
-\newwrite\utility@tui
-\newif\ifutilitydone
-
-\def\@@utilityerrormessage
- {\showmessage\m!systems8\empty
- \globallet\@@utilityerrormessage\relax}
-
-\def\thisisutilityversion#1%
- {\doifelse\utilityversion{#1}%
- {\checksectionseparator}
- {\@@utilityerrormessage\resetutilities\endinput}}
-
-\def\checksectionseparator % catches backward compatibility conflict
- {}% \doifnot\sectionseparator:\endinput} % this dependency may go in a few years
-
-\def\dosplitofffoliopart[#1--#2--#3]{#3}
-
-\def\thisissectionseparator#1%
- {\bgroup
- \globallet\checksectionseparator\relax
- \defconvertedcommand \asciia\sectionseparator
- \defconvertedargument\asciib{#1}%
- \expanded{\gdef\noexpand\dosplitofffoliopart[####1\sectionseparator
- \sectionseparator####2\sectionseparator\sectionseparator####3]{####3}}%
- \ifx\asciia\asciib
- \egroup
- \else
- \egroup
- % todo \@@utilityerrormessage
- \resetutilities
- \endinput
- \fi}
-
-\def\writeutility {\write\utility@tui}
-\def\writeutilitycommand#1{\write\utility@tui{c \string#1}}
-
-% less tokens
-%
-% \def\immediatewriteutility {\immediate\writeutility}
-% \def\immediatewriteutilitycommand{\immediate\writeutilitycommand}
-%
-% more flexible (for overloading)
-
-\def\immediatewriteutility {\immediate\write\utility@tui}
-\def\immediatewriteutilitycommand#1{\immediate\write\utility@tui{c \string#1}}
-
-% as in:
-
-\def\cwriteutility#1%
- {\write\utility@tui{\noexpand\checkedutility{\number\nofshipouts}{#1}}}
-
-\def\cwriteutilitycommand#1%
- {\write\utility@tui{\noexpand\checkedutility{\number\nofshipouts}{c \string#1}}}
-
-\let\checkedutility\secondoftwoarguments
-
-\def\docheckedutility#1#2{\ifnum#1=\nofshipouts#2\else\letterpercent\fi}
-
-\prependtoks
- \let\checkedutility\docheckedutility
-\to \everybeforeshipout
-
-% Better use marks.
-
-\newtoks \everyopenutilities
-\newtoks \everycloseutilities
-\newtoks \everycheckutilities
-
-\def\openutilities {\the\everyopenutilities } % \global\everyopenutilities\emptytoks
-\def\closeutilities{\the\everycloseutilities}
-\def\checkutilities{\the\everycheckutilities}
-
-\appendtoks
- \let\writeutility \cwriteutility
- \let\writeutilitycommand \cwriteutilitycommand
- %\let\immediatewriteutility \cimmediatewriteutility
- %\let\immediatewriteutilitycommand\cimmediatewriteutilitycommand
- \let\checkutilities \relax
-\to \everycheckutilities
-
-\appendtoks
- \immediate\openout\utility@tui\jobname.\f!inputextension
- \immediatewriteutilitycommand{\thisissectionseparator{\sectionseparator}}% for the moment
- \immediatewriteutilitycommand{\thisisutilityversion {\utilityversion }}% in this order
-\to \everyopenutilities
-
-\appendtoks
-% \immediate\closeout\utility@tui % niet echt nodig
- \reportutilityproblems
- % should be a message :
- \let\writeutilitycommand \gobbleoneargument
- \let\writeutility \gobbleoneargument
- \let\immediatewriteutilitycommand\gobbleoneargument
- \let\immediatewriteutility \gobbleoneargument
-\to \everycloseutilities
-
-% \def\reopenutilities
-% {\immediate\closeout\utility@tui
-% \openutilities}
-
-\def\abortutilitygeneration
- {\immediatewriteutilitycommand\utilitygenerationaborted
- \immediatewriteutility{q {quit}}}
-
-\def\utilitygenerationaborted
- {\showmessage\m!systems{21}\empty
- \globallet\utilitygenerationaborted\endinput
- \gdef\reportutilityproblems{\showmessage\m!systems{22}\empty}%
- \endinput}
-
-\let\savecurrentvalue \gobbletwoarguments % mkii/mkiv
-\let\initializevariable\gobbletwoarguments % mkii/mkiv
-
-\appendtoks
- \globallet\initializevariable\gobbletwoarguments
-\to \everyafterutilityread
-
-\let\reportutilityproblems\relax
-\let\utilityresetlist \empty
-
-\newtoks\utilityresetlist
-
-\def\addutilityreset#1%
- {\@EA\appendtoks\csname\s!reset#1\endcsname\to\utilityresetlist}
-
-\def\resetutilities
- {\the\utilityresetlist}
-
-% #1=type
-% #2=file
-% #3=melding
-
-% #4=voor
-% #5=na
-
-% Er wordt gegroepeerd. Als binnen een lijst (bijvoorbeeld) de
-% \leftskip is aangepast, maar nog geen \par is gegeven, dan
-% geldt buiten de groep de oude \leftskip. Aan #5 kan dan
-% ook \par worden meegegeven om de paragraaf af te sluiten.
-
-\newif\ifdoinpututilities
-\newif\ifunprotectutilities % voor't geval er \v!xxxxxx's zijn
-
-\def\currentutilityfilename{\jobname}
-
-% \long\def\doutilities#1#2#3#4#5% % introduceren in utility file
-% {\restorecatcodes
-% \resetutilities
-% % more than one utility thing can be handled in one pass,
-% % for instance lists, so we process ##1 as list
-% \def\douticommand##1{\csname\s!set##1\endcsname}%
-% \processcommacommand[#1]\douticommand
-% \begingroup
-% \def\currentutilityfilename{#2}%
-% \notesenabledfalse
-% \doinpututilitiestrue
-% \global\utilitydonefalse
-% \catcode`\\=\@@escape
-% \catcode`\{=\@@begingroup
-% \catcode`\}=\@@endgroup
-% \catcode`\%=\@@comment\relax
-% \pushendofline % geeft problemen zodra andere file wordt ingelezen
-% \ifunprotectutilities % nog nodig ?
-% \unprotect
-% \fi
-% \ifnum\catcode`\@=\@@active \else
-% \catcode`\@=\@@letter % permits expanded commands with \@'s
-% \fi
-% \ifnum\catcode`\!=\@@active \else
-% \catcode`\!=\@@letter % permits multilingual constants
-% \fi
-% #4%
-% \the\everybeforeutilityread
-% \readjobfile{#2.\f!outputextension}\donothing\donothing
-% \the\everyafterutilityread
-% #5%
-% \relax
-% \ifunprotectutilities
-% \protect
-% \fi
-% \popendofline
-% \ifutilitydone\else
-% \doifsomething{#3}
-% {\showmessage\m!systems9{{#3}}%
-% \doifconcepttracing
-% {\blank
-% \type{[\currentmessagetext]}%
-% \blank}}%
-% \fi
-% \endgroup}
-
-% we need to pop and push, else problems with reading
-% utility files (toc) in xml mode and (e.g.) in a toc
-% entry doing a doifmode
-%
-% the following is not ok because we have no way to signal
-% xml content (yet), so for the moment we use this:
-
-\appendtoks
- \ifprocessingXML
- \processingXMLfalse
- \enableXML
- \catcode`\\=\@@escape
- \catcode`\{=\@@begingroup
- \catcode`\}=\@@endgroup
- \catcode`\%=\@@comment\relax
- \fi
-\to \everybeforeutilityread
-
-\long\def\doutilities#1#2#3#4#5% % introduceren in utility file
- {\resetutilities
- % more than one utility thing can be handled in one pass,
- % for instance lists, so we process ##1 as list
- \def\douticommand##1{\csname\s!set##1\endcsname}%
- \processcommacommand[#1]\douticommand
- \begingroup
- \def\currentutilityfilename{#2}%
- \notesenabledfalse
- \doinpututilitiestrue
- \global\utilitydonefalse
- \pushendofline % geeft problemen zodra andere file wordt ingelezen
- \pushcatcodetable
- \setcatcodetable\ctxcatcodes
- \ifunprotectutilities % nog nodig ?
- \unprotect
- \fi
- #4%
- \the\everybeforeutilityread
- \readjobfile{#2.\f!outputextension}\donothing\donothing
- \the\everyafterutilityread
- \popcatcodetable
- #5%
- \relax
- \ifunprotectutilities
- \protect
- \fi
- \popendofline
- \ifutilitydone\else
- \doifsomething{#3}
- {\showmessage\m!systems9{{#3}}%
- \doifconcepttracing
- {\blank
- \setmessagetext\m!systems9{{#3}}%
- \type{[\currentmessagetext]}%
- \blank}}%
- \fi
- \endgroup}
-
-% Default-instellingen (verborgen)
-
-\prependtoks \resetutilities \to \everyjob
-
-% Experiment
-%
-% \installprogram{Hello World}
-% \installprogram[hw]{Hello World}
-% \installedprogram[hw]
-
-\def\installprogram
- {\dosingleempty\doinstallprogram}
-
-\def\doinstallprogram[#1]#2%
- {\doifelsenothing{#1}
- {\dodoinstallprogram{#2}}
- {\setvalue{\??up#1}{\dodoinstallprogram{#2}}}}
-
-% \def\doinstallprogram[#1][#2]% less code
-% {\doifsomething{#1}{\setvalue{\??up#1}}{\dodoinstallprogram{#2}}}
-
-\def\dodoinstallprogram#1%
- {\immediatewriteutility{e p {#1}}}
-
-\def\installedprogram[#1]%
- {\getvalue{\??up#1}}
-
-% \writeplugindata{texutil}{{alpha}}
-% \writeplugindata{texutil}{{beta}}
-% \writeplugindata{texutil}{{gamma}}
-% \writeplugindata{texutil}{{delta}}
-%
-% \loadplugindata {plugintest}
-
-\def\immediatewriteplugindata#1#2%
- {\immediatewriteutility{p u {#1} #2}}
-
-\def\writeplugindata#1#2%
- {\writeutility{p u {#1} #2}}
-
-\def\loadplugindata#1%
- {\doutilities{#1}\jobname\empty\relax\relax}
-
-% \plugincommand{\command{}{}{}}
-%
-% this way we can catch undefined commands
-
-\long\def\plugincommand#1%
- {\doplugincommand#1\relax}
-
-\long\def\doplugincommand#1%
- {\ifx#1\undefined
- \expandafter\noplugincommand
- \else
- \expandafter#1%
- \fi}
-
-% shorter:
-%
-% \long\def\doplugincommand#1%
-% {\ifx#1\undefined\expandafter\noplugincommand\fi#1}
-
-\long\def\noplugincommand#1\relax
- {}
-
-% \addutilityreset{plugintest}
-%
-% \def\resetplugintest{\let\plugintest\gobbletwoarguments}
-% \def\setplugintest {\let\plugintest\writestatus}
-%
-% \installplugin
-% {plugintest}
-% {\let\plugintest\gobbletwoarguments}
-% {\let\plugintest\writestatus}
-
-\long\def\installplugin#1#2#3%
- {\addutilityreset {#1}%
- \long\setvalue{\s!reset#1}{#2}%
- \long\setvalue{\s!set #1}{#3}}
-
-% plugins
-
-\loadmarkfile{core-uti}
-
-\protect \endinput
diff --git a/tex/context/base/core-var.tex b/tex/context/base/core-var.tex
index 38c434e0b..4de1b8718 100644
--- a/tex/context/base/core-var.tex
+++ b/tex/context/base/core-var.tex
@@ -11,304 +11,121 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Variables}
+\writestatus{loading}{ConTeXt Core Macros / Variables}
\unprotect
-%D Modes:
-%D
-%D \starttyping
-%D \enablemode[screen,paper,bound]
-%D
-%D \doifmodeelse {paper} {this} {that}
-%D \doifmode {paper,screen} {this}
-%D \doifnotmode {paper,bound} {that}
-%D
-%D \startmode [list]
-%D \stopmode
-%D
-%D \startnotmode [list]
-%D \stopnotmode
-%D \stoptyping
-%D
-%D system modes have a * as prefix
+%D We introduce a couple of variables that are used all over
+%D \CONTEXT. Alternatively we could define them in each module
+%D but as they are part of the bigger picture we prefer to do
+%D it here.
+
+%D \macros
+%D {every...}
%D
-%D Sometimes, we want to prevent a mode for being set. Think
-%D of situations where a style enables a mode, but an outer
-%D level style does not want that. Preventing can be
-%D considered a permanent disabling on forehand.
-
-% \def\systemmodeprefix{*}
-%
-% \let\currentmode \empty
-% \let\preventedmodes\empty
-%
-% \def\preventmode[#1]%
-% {\expanded{\addtocommalist{#1}\noexpand\preventedmodes}}
-%
-% \def\enablemode[#1]%
-% {\expanded
-% {\doifnotinset{#1}{\preventedmodes}
-% {\noexpand\addtocommalist{#1}\noexpand\currentmode}}}
-%
-% \def\disablemode[#1]%
-% {\expanded{\removefromcommalist{#1}\noexpand\currentmode}}
-%
-% \def\doifmodeelse{\unprotect\dodoifmodeelse}
-% \def\doifmode {\unprotect\dodoifmode }
-% \def\doifnotmode {\unprotect\dodoifnotmode }
-% \def\startmode {\unprotect\dostartmode }
-% \def\startnotmode{\unprotect\dostartnotmode}
-%
-% \long\def\dodoifmodeelse#1%
-% {\protect\expanded{\doifcommonelse{#1}{\currentmode}}}
-%
-% \long\def\dodoifmode#1%
-% {\protect\expanded{\doifcommon {#1}{\currentmode}}}
-%
-% \long\def\dodoifnotmode#1%
-% {\protect\expanded{\doifnotcommon {#1}{\currentmode}}}
-%
-% \let\stopmode \relax
-% \let\stopnotmode\relax
-%
-% \long\def\dostartmode[#1]%
-% {\protect
-% \expanded{\doifnotcommon{#1}{\currentmode}}{\gobbleuntil\stopmode}}
-%
-% \long\def\dostartnotmode[#1]%
-% {\protect
-% \expanded{\doifcommon {#1}{\currentmode}}{\gobbleuntil\stopnotmode}}
-%
-% \def\doifallmodeselse{\unprotect\dodoifallmodeselse}
-% \def\doifallmodes {\unprotect\dodoifallmodes}
-% \def\doifnotallmodes {\unprotect\dodoifnotallmodes}
-% \def\startallmodes {\unprotect\dostartallmodes}
-% \def\startnotallmodes{\unprotect\dostartnotallmodes}
-%
-% \long\def\dodoifallmodeselse#1%
-% {\protect\expanded{\doifallcommonelse{#1}{\currentmode}}}
-%
-% \long\def\dodoifallmodes#1%
-% {\protect\expanded{\doifallcommon {#1}{\currentmode}}}
-%
-% \long\def\dodoifnotallmodes#1%
-% {\protect\expanded{\doifnotallcommon {#1}{\currentmode}}}
-%
-% \let\stopallmodes \relax
-% \let\stopnotallmodes\relax
-%
-% \long\def\dostartallmodes[#1]%
-% {\protect
-% \expanded{\doifnotallcommon{#1}{\currentmode}}{\gobbleuntil\stopallmodes}}
-%
-% \long\def\dostartnotallmodes[#1]%
-% {\protect
-% \expanded{\doifallcommon {#1}{\currentmode}}{\gobbleuntil\stopnotallmodes}}
-
-% faster
-
-\def\@mode@{@md@}
-
-\def\systemmodeprefix{*}
-
-\def\disabledmode {0}
-\def\enabledmode {1}
-\def\preventedmode {2}
-
-% fast internal ones
-
-\def\setmode #1{\@EA\let\csname\@mode@#1\endcsname\enabledmode }
-\def\resetmode#1{\@EA\let\csname\@mode@#1\endcsname\disabledmode}
-
-\def\setsystemmode #1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\enabledmode }
-\def\resetsystemmode#1{\@EA\let\csname\@mode@\systemmodeprefix#1\endcsname\disabledmode}
-
-% user ones
-
-\def\preventmode{\unprotect\dopreventmode}
-\def\enablemode {\unprotect\doenablemode }
-\def\disablemode{\unprotect\dodisablemode}
-
-% \def\dopreventmode[#1]{\protect\rawprocesscommalist[#1]\dodopreventmode}
-% \def\doenablemode [#1]{\protect\rawprocesscommalist[#1]\dodoenablemode }
-% \def\dodisablemode[#1]{\protect\rawprocesscommalist[#1]\dododisablemode}
-%
-% better:
-
-\def\dopreventmode[#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dodopreventmode}
-\def\doenablemode [#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dodoenablemode }
-\def\dodisablemode[#1]{\protect\cleanuplabel{#1}\rawprocesscommalist[\cleanlabel]\dododisablemode}
-
-\def\dodopreventmode#1%
- {\@EA\let\csname\@mode@#1\endcsname\preventedmode}
-
-\def\dodoenablemode#1% mode can be relax
- {\ifcase0\csname\@mode@#1\endcsname\relax
- \@EA\let\csname\@mode@#1\endcsname\enabledmode
- \fi}
+%D A few every's. Some are only used in \MKII\ or \MKIV.
-\def\dododisablemode#1%
- {\ifcase0\csname\@mode@#1\endcsname\or
- \@EA\let\csname\@mode@#1\endcsname\disabledmode
- \fi}
+%D Output routine:
-% handy for mp
+\newtoks \everybeforeoutput
+\newtoks \everyafteroutput
-\def\booleanmodevalue#1% can be \relax
- {\expandafter\ifx\csname\@mode@#1\endcsname\relax
- fals%
- \else\ifnum0\csname\@mode@#1\endcsname=0
- fals%
- \else
- tru%
- \fi\fi e}
+%D Shipout:
-% check macros
+\newtoks \everyshipout
+\newtoks \everybeforeshipout
+\newtoks \everyaftershipout
+\newtoks \everyfirstshipout
+\newtoks \everylastshipout
-\newif\ifcheckedmode
+%D End of run:
-\def\dodocheckformode#1%
- {\ifcase0\csname\@mode@#1\endcsname\or\checkedmodetrue\fi}
+\newtoks \everybye
+\newtoks \everygoodbye
+\newtoks \everynotabene
-\def\docheckformode#1#2#3% will be sped up with a quit
- {\cleanuplabel{#3}%
- \protect\checkedmodefalse\rawprocesscommacommand[\cleanlabel]\dodocheckformode
- \ifcheckedmode\@EA#1\else\@EA#2\fi}
+%D Document
-\def\dodocheckforallmodes#1%
- {\ifcase0\csname\@mode@#1\endcsname\relax\checkedmodefalse\or\or\checkedmodefalse\fi}
+\newtoks \everysetupdocument
+\newtoks \everyendoftextbody
-\def\docheckforallmodes#1#2#3% will be sped up with a quit
- {\cleanuplabel{#3}%
- \protect\checkedmodetrue\rawprocesscommacommand[\cleanlabel]\dodocheckforallmodes
- \ifcheckedmode\@EA#1\else\@EA#2\fi}
+\newtoks \everystarttext
+\newtoks \everystoptext
-% simple ones
+%D Purity:
-\def\doifmodeelse{\unprotect\dodoifmodeelse}
-\def\doifmode {\unprotect\dodoifmode}
-\def\doifnotmode {\unprotect\dodoifnotmode}
-\def\startmode {\unprotect\dostartmode}
-\def\startnotmode{\unprotect\dostartnotmode}
+\newtoks \everyforgetall
+\newtoks \everycleanupfeatures
-\def\dodoifmodeelse
- {\docheckformode\firstoftwoarguments\secondoftwoarguments}
+\def\cleanupfeatures{\the\everycleanupfeatures}
+\def\forgetall {\the\everyforgetall}
-\def\dodoifmode
- {\docheckformode\firstofoneargument\gobbleoneargument}
+%D Page building:
-\def\dodoifnotmode
- {\docheckformode\gobbleoneargument\firstofoneargument}
+\newtoks \everybeforepagebody
+\newtoks \everyafterpagebody
-\long\def\dostartmode[#1]%
- {\docheckformode\donothing\dostopmode{#1}}
+\let \everypagebody \everybeforepagebody % backward compatible
-\long\def\dostartnotmode[#1]%
- {\docheckformode\dostopnotmode\donothing{#1}}
+%D Multipass:
-\let\stopmode \donothing
-\let\stopnotmode\donothing
+\newtoks \everybeforeutilityread
+\newtoks \everyafterutilityread
-\long\def\dostopmode #1\stopmode {}
-\long\def\dostopnotmode#1\stopnotmode{}
+%D Floats:
-\def\doifallmodeselse{\unprotect\dodoifallmodeselse}
-\def\doifallmodes {\unprotect\dodoifallmodes}
-\def\doifnotallmodes {\unprotect\dodoifnotallmodes}
-\def\startallmodes {\unprotect\dostartallmodes}
-\def\startnotallmodes{\unprotect\dostartnotallmodes}
+\newtoks \everyinsidefloat
-\def\dodoifallmodeselse
- {\docheckforallmodes\firstoftwoarguments\secondoftwoarguments}
+%D Sectioning:
-\def\dodoifallmodes
- {\docheckforallmodes\firstofoneargument\gobbleoneargument}
+\newtoks \everyheadstart
-\def\dodoifnotallmodes
- {\docheckforallmodes\gobbleoneargument\firstofoneargument}
+%D Par building (experimental, used in xml
+\newtoks \everytable
-\def\bpar{\the\everybeginofpar\ignorespaces} % may interfere with \everypar
-\def\epar{\ifhmode\removeunwantedspaces\the\everyendofpar\fi} % test prevents problems with \bpar\epar
+%D State mess:
+
+\newtoks \everypushsomestate
+\newtoks \everypopsomestate
+
+\def\pushsomestates{\the\everypushsomestate}
+\def\popsomestates {\the\everypopsomestate }
%D More generic (used to be pushcolor etc)
@@ -337,8 +154,9 @@
%D
%D New. Some work needs to be done.
+% not in mkiv
+
\def\defineinputmode[#1]{\@EA\newtoks\csname every#1inputmode\endcsname}
-%def\setinputmode [#1]{\the \csname every#1inputmode\endcsname}
\def\setinputmode [#1]{\the\executeifdefined{every#1inputmode}\emptytoks}
\defineinputmode [TEX]
@@ -352,7 +170,7 @@
%D We disable trial typesetting in the output routine,
%D just to be sure.
-% defined in syst-ext
+\newif\iftrialtypesetting
\prependtoks \trialtypesettingfalse \to \everybeforepagebody
@@ -372,7 +190,7 @@
%D
%D We need this one even if no \XML\ is supported.
-\newif\ifprocessingXML
+\newif\ifprocessingXML % old way
%D \macros
%D {ifproductionrun}
@@ -382,7 +200,9 @@
\ifx\protectionlevel\undefined \newcount\protectionlevel \fi
-\newif\ifproductionrun \appendtoks \productionruntrue \to \everydump
+\newif\ifproductionrun
+
+\appendtoks \productionruntrue \to \everydump
\appendtoks \ifcase\protectionlevel\else\reportunprotection\fi \to \everydump
@@ -393,8 +213,8 @@
%D This one is relatively new and will be used as a more
%D robust test for inner situations.
-\newif \ifboxedcontent
-\newevery \everyboxedcontent \relax
+\newif \ifboxedcontent
+\newtoks\everyboxedcontent
\appendtoks \boxedcontenttrue \to \everyboxedcontent
@@ -402,145 +222,12 @@
\let\stopboxedcontent \egroup
%D \macros
-%D {fastmode}
-%D
-%D The command \type {\fastmode} disables some time consuming
-%D typesetting.
-
-\newevery \everyfastmode \relax
-
-\newif\iffastmode
-
-\def\fastmode
- {\fastmodetrue
- \the\everyfastmode}
-
-\def\silentmode % ook hier \everysilentmode net als \fastmode
- {\showmessagesfalse
- \showwarningsfalse
- \let\writestatus\gobbletwoarguments}
-
-%D \macros
-%D {pdfoutput}
-%D
-%D There are some fundamental differences between producing
-%D \DVI\ and \PDF\ output, especially when we use \PDFTEX, like
-%D object reuse, one pass graphic inclusion and the lack of a
-%D postprocessing stage. Because we must make sure that
-%D \CONTEXT\ knows what it's up to, we always default to \DVI\
-%D mode, even when users explicitly ask for \PDF\ output in the
-%D \PDFTEX\ configuration file.
-
-% we assume no pdfcontext or whatever
-%
-% \ifx\pdfoutput\undefined \else
-% \prependtoks \pdfoutput=0 \to \everyjob
-% \fi
-
-%D \macros
-%D {setvariables,getvariable,getvariabledefault}
+%D {fastmode,silentmode}
%D
-%D \starttyping
-%D \setvariables[xx][title=]
-%D \setvariables[xx][title=test test]
-%D \setvariables[xx][title=test $x=1$ test] % fatal error reported
-%D \setvariables[xx][title=test {$x=1$} test]
-%D \setvariables[xx][title] % fatal error reported
-%D \setvariables[xx][titletitel=e]
-%D \stoptyping
-
-\def\??vars{@@vars}
-
-\def\setvariables {\dotripleargument\dosetvariables[\getrawparameters ]}
-\def\setevariables{\dotripleargument\dosetvariables[\getraweparameters]}
-\def\setgvariables{\dotripleargument\dosetvariables[\getrawgparameters]}
-\def\setxvariables{\dotripleargument\dosetvariables[\getrawxparameters]}
-
-\def\globalsetvariables % obsolete
- {\dotripleargument\dosetvariables[\globalgetrawparameters]}
-
-% \long\def\dosetvariables[#1][#2][#3]%
-% {\errorisfataltrue
-% \def\currentvariableclass{#2}%
-% \getvariable{#2}\s!reset
-% #1[\??vars:#2:][#3]%
-% \getvariable{#2}\s!set
-% \errorisfatalfalse}
-%
-% permit nested definitions while preventing nested set/reset
-%
-% wrong:
-%
-% \long\def\dosetvariables[#1][#2][#3]%
-% {\errorisfataltrue
-% \getrawparameters[\??vars:*:][\s!reset=*,\s!set=*,#3]%
-% \doifelse{\getvalue{\??vars:*:\s!reset}\getvalue{\??vars:*:\s!set}}{**}
-% {\doifelse{#2}\currentvariableclass
-% {#1[\??vars:#2:][#3]}
-% {\pushmacro\currentvariableclass
-% \def\currentvariableclass{#2}%
-% \getvariable{#2}\s!reset
-% #1[\??vars:#2:][#3]%
-% \getvariable{#2}\s!set
-% \popmacro\currentvariableclass}}%
-% {#1[\??vars:#2:][#3]}%
-% \errorisfatalfalse}
-
-\long\def\dosetvariables[#1][#2][#3]% tricky, test on s-pre-60
- {\errorisfataltrue
- \doifelse{#2}\currentvariableclass
- {#1[\??vars:#2:][#3]}%
- {\pushmacro\currentvariableclass
- \def\currentvariableclass{#2}%
- \getvariable{#2}\s!reset
- #1[\??vars:#2:][#3]%
- \getvariable{#2}\s!set
- \popmacro\currentvariableclass}%
- \errorisfatalfalse}
-
-\long\def\setvariable #1#2#3{\long\setvalue {\??vars:#1:#2}{#3}}
-\long\def\setevariable#1#2#3{\long\setevalue{\??vars:#1:#2}{#3}}
-\long\def\setgvariable#1#2#3{\long\setgvalue{\??vars:#1:#2}{#3}}
-\long\def\setxvariable#1#2#3{\long\setxvalue{\??vars:#1:#2}{#3}}
-
-\def\getvariable#1#2% to be sped up
- {\csname
- \ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi
- \endcsname}
-
-\def\showvariable#1#2%
- {\showvalue{\ifcsname\??vars:#1:#2\endcsname\??vars:#1:#2\else\s!empty\fi}}
-
-\let\currentvariableclass\empty
-
-%D \macros
-%D {doifelsevariable,doifvariable,doifnotvariable}
-%D
-%D A few trivial macros:
-
-\def\doifelsevariable#1#2%
- {\ifcsname\??vars:#1:#2\endcsname
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\doifvariable#1#2%
- {\ifcsname\??vars:#1:#2\endcsname
- \expandafter\firstofoneargument
- \else
- \expandafter\gobbleoneargument
- \fi}
-
-\def\doifnotvariable#1#2%
- {\ifcsname\??vars:#1:#2\endcsname
- \expandafter\gobbleoneargument
- \else
- \expandafter\firstofoneargument
- \fi}
+%D These commands are obsolete.
-\def\getvariabledefault#1#2% #3% can be command, so no ifcsname here
- {\executeifdefined{\??vars:#1:#2}}% {#3}
+\let\fastmode \relax
+\let\silentmode\relax
%D \macros
%D {defineselector,setupselector}
@@ -571,95 +258,20 @@
{\executeifdefined{\??sx#1\c!max}1}
{\executeifdefined{\??sx#1\c!n }1}}
-%D \macros
-%D {checkvariables}
-%D
-%D I'll probably forget that this on exists.
-
-\def\checkvariables
- {\dodoubleargument\docheckvariables}
-
-\def\docheckvariables
- {\dogetparameters\docheckrawvalue}
-
-\def\docheckrawvalue#1#2#3%
- {\doifundefined {\??vars:#1:#2}{\setvalue{\??vars:#1:#2}{#3}}
- {\doifvaluenothing{\??vars:#1:#2}{\setvalue{\??vars:#1:#2}{#3}}}}
-
%D We store some original meanings, maybe in \type
%D {math-ini}.
-\let\normalat \at
-\let\normalin \in
-\let\normalfrom \from
-\let\normalover \over
-\let\normalabout \about
-
-\let\normalabove \above
-\let\normalatop \atop
-
-\let\normaloverwithdelims \overwithdelims
-\let\normalabovewithdelims\abovewithdelims
-\let\normalatopwithdelims \atopwithdelims
+\let\normalat \at
+\let\normalin \in
+\let\normalfrom \from
+%let\normalover \over
+\let\normalabout\about
%D Add-ons:
\let\startlayoutcomponent\gobbletwoarguments
\let\stoplayoutcomponent \relax
-
-%D Label cleanup:
-\bgroup % some day this will go away / we could use detokenize as well
-
-% actually we should handle all discretionaries here
-
-\catcode`:=\@@active
-
-\gdef\cleanuplabel#1%
- {\begingroup
- \let:\lettercolon
- \xdef\cleanlabel{#1}%
- \endgroup}
-
-\gdef\cleanupprefixedlabel#1#2%
- {\begingroup
- \let:\lettercolon
- \xdef\cleanprefix{#1}%
- \xdef\cleanlabel {#2}%
- \endgroup}
-
-\gdef\protectlabels
- {\let:\lettercolon}
-
-\global\def\blabelgroup {\begingroup \let:\lettercolon}
-\global\let\elabelgroup \endgroup
-
-\gdef\labelcsname
- {\begingroup\let:\lettercolon
- \expandafter\endgroup\csname}
-
-\gdef\labelvalue#1%
- {\labelcsname#1\endcsname}
-
-\egroup
-
-%D TO BE TESTED FIRST (needs changes in usage too)
-
-% \def\cleanuplabel#1%
-% {\edef\cleanlabel{\detokenize{#1}}}
-%
-% \def\cleanupprefixedlabel#1#2%
-% {\edef\cleanprefix{\detokenize{#1}}%
-% \edef\cleanlabel {\detokenize{#2}}}
-%
-% \def\labelvalue#1%
-% {\csname\detokenize{#1}\endcsname}
-%
-% \let\protectlabels\donothing
-%
-% \def\blabelgroup {\begingroup} % why no \let ?
-% \let\elabelgroup \endgroup
-
%D Concepts:
\chardef\conceptmode\zerocount
diff --git a/tex/context/base/core-ver.mkii b/tex/context/base/core-ver.mkii
index 4e51c934c..dd8f5f84f 100644
--- a/tex/context/base/core-ver.mkii
+++ b/tex/context/base/core-ver.mkii
@@ -11,12 +11,51 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Verbatim}
+
\unprotect
-% uses \prettyidentifier and sets \setupprettytype
+\ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
+\ifx\stoplinenumbering \undefined \let\stoplinenumbering\relax \fi
+\ifx\setuplinenumbering\undefined \def\setuplinenumbering[#1]{} \fi
+
+% \type{ char} geeft bagger
+
+%D We are going to embed the general verbatim support macros in
+%D a proper environment. First we show the common setup
+%D macro, so we know what features are supported. The options
+%D are hooked into the support macros via the \type{\obey}
+%D macros.
+
+\newif\ifslantedtypeactivated
+\newif\ifslantedtypepermitted
-\def\mksetupprettiesintype
- {\doifundefined{setuppretty\prettyidentifier type}%
+\def\switchslantedtype
+ {\ifslantedtypepermitted
+ \ifslantedtypeactivated
+ \slantedtypeactivatedfalse\tttf
+ \else
+ \slantedtypeactivatedtrue\ttsl
+ \fi
+ \fi}
+
+\newprettytrue % movet to here from cont-sys.tex
+
+\def\prettyidentifier {TEX}
+\def\prettypalet {}
+
+\def\installprettytype
+ {\dodoubleargument\doinstallprettytype}
+
+\def\doinstallprettytype[#1][#2]% map #1 onto #2
+ {\uppercasestring#1\to\asciia
+ \uppercasestring#2\to\asciib
+ \setevalue{\??ty\??ty\asciia}{\asciib}}
+
+\def\setupprettiesintype#1%
+ {\uppercasestring#1\to\ascii
+ \edef\prettyidentifier{\executeifdefined{\??ty\??ty\ascii}{TEX}}%
+ \doifundefined{setuppretty\prettyidentifier type}%
{\startnointerference
\restorecatcodes % also needed when loading during \newpretty
\startreadingfile % restore < and > if needed
@@ -26,8 +65,229 @@
\stopnointerference}%
\doifdefinedelse{setuppretty\prettyidentifier type}%
{\let\uncatcodecharacters\uncatcodeallcharacters % ugly, should be switch / todo
- \def\mksetupprettytype{\getvalue{setuppretty\prettyidentifier type}}}
- {\let\mksetupprettytype\relax}}
+ \def\dosetupprettytype{\getvalue{setuppretty\prettyidentifier type}}}
+ {\let\dosetupprettytype\relax}}
+
+\def\setupprettytype{\dosetupprettytype}
+
+% \def\setupcommonverbatim
+% {\recatcodeuppercharactersfalse % obey regime / encoding
+% %
+% \let\prettyidentifier\s!default
+% %
+% \doifelse{\typingparameter\c!text}\v!yes
+% \naturaltextexttrue
+% \naturaltextextfalse
+% \def\prettyidentifierfont{\typingparameter\c!icommand}%
+% \def\prettyvariablefont {\typingparameter\c!vcommand}%
+% \def\prettynaturalfont {\typingparameter\c!ccommand}%
+% %
+% \doif{\typingparameter\c!space}\v!on
+% {\def\obeyspaces{\setcontrolspaces}}%
+% \doif{\typingparameter\c!page }\v!no
+% {\def\obeypages {\ignorepages}}%
+% %
+% \doifelse{\typingparameter\c!tab}\v!yes
+% {\def\obeytabs{\settabskips}}%
+% {\doif{\typingparameter\c!tab}\s!ascii
+% {\chardef\tabskipmode\plustwo % quit on >127
+% \def\obeytabs{\settabskips}}}%
+% %
+% \ignorehyphens % default
+% \ExpandFirstAfter\processaction
+% [\typingparameter\c!lines]
+% [ \v!yes=>\obeybreakpoints,
+% \v!hyphenated=>\obeyhyphens]%
+% \processaction
+% [\typingparameter\c!empty]
+% [\v!yes=>\obeyemptylines,
+% \v!all=>\obeyallemptylines]%
+% %
+% \ExpandFirstAfter\processaction
+% [\typingparameter\c!option]
+% [ \v!none=>\let\obeycharacters\relax,
+% \v!color=>\setupprettiesintype{TEX}%
+% \let\obeycharacters\setupprettytype
+% \let\obeytabs\ignoretabs,
+% \v!normal=>\let\obeycharacters\setupgroupedtype,
+% \v!commands=>\def\obeycharacters{\setupcommandsintype}% \let
+% \let\obeytabs\ignoretabs,
+% \v!slanted=>\let\obeycharacters\setupslantedtype
+% \let\obeytabs\ignoretabs,
+% \s!unknown=>\setupprettiesintype{\typingparameter\c!option}%
+% \let\obeycharacters\setupprettytype
+% \let\obeytabs\ignoretabs]%
+% \doifnumberelse{\typingparameter\c!tab}
+% {\def\obeytabs{\setfixedtabskips{\typingparameter\c!tab}}}%
+% \donothing
+% %\def\verbatimfont{\typingparameter\c!style\normalnoligatures\font}%
+% % more generic, but beware of the \redoconvertfont (else no typing in titles and such)
+% \def\verbatimfont{\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style\normalnoligatures\font}%
+% \setupverbatimcolor}
+
+\setvalue{\??tp:\c!lines:\v!yes }{\obeybreakpoints}
+\setvalue{\??tp:\c!lines:\v!hyphenated}{\obeyhyphens}
+
+\setvalue{\??tp:\c!empty:\v!yes }{\obeyemptylines}
+\setvalue{\??tp:\c!empty:\v!all }{\obeyallemptylines}
+
+\setvalue{\??tp:\c!option:\v!none }{\let\obeycharacters\relax}
+\setvalue{\??tp:\c!option:\v!color }{\setupprettiesintype{TEX}%
+ \let\obeycharacters\setupprettytype
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\v!normal }{\let\obeycharacters\setupgroupedtype}
+\setvalue{\??tp:\c!option:\v!commands }{\def\obeycharacters{\setupcommandsintype}%
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\v!slanted }{\let\obeycharacters\setupslantedtype
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\s!unknown }{\setupprettiesintype{\typingparameter\c!option}%
+ \let\obeycharacters\setupprettytype
+ \let\obeytabs\ignoretabs}
+
+
+\def\setupcommonverbatim
+ {\recatcodeuppercharactersfalse % obey regime / encoding
+ %
+ \let\prettyidentifier\s!default
+ %
+ \doifelse{\typingparameter\c!text}\v!yes
+ \naturaltextexttrue
+ \naturaltextextfalse
+ \def\prettyidentifierfont{\typingparameter\c!icommand}%
+ \def\prettyvariablefont {\typingparameter\c!vcommand}%
+ \def\prettynaturalfont {\typingparameter\c!ccommand}%
+ %
+ \doif{\typingparameter\c!space}\v!on
+ {\def\obeyspaces{\setcontrolspaces}}%
+ \doif{\typingparameter\c!page }\v!no
+ {\def\obeypages {\ignorepages}}%
+ %
+ \doifelse{\typingparameter\c!tab}\v!yes
+ {\def\obeytabs{\settabskips}}%
+ {\doif{\typingparameter\c!tab}\s!ascii % not needed in mkiv
+ {\chardef\tabskipmode\plustwo % quit on >127
+ \def\obeytabs{\settabskips}}}%
+ %
+ \ignorehyphens % default
+ \getvalue{\??tp:\c!lines:\typingparameter\c!lines}%
+ \getvalue{\??tp:\c!empty:\typingparameter\c!empty}%
+ \getvalue{\??tp:\c!option:\ifcsname\??tp:\c!option:\typingparameter\c!option\endcsname\typingparameter\c!option\else\s!unknown\fi}%
+ \doifnumberelse{\typingparameter\c!tab}
+ {\def\obeytabs{\setfixedtabskips{\typingparameter\c!tab}}}%
+ \donothing
+ %\def\verbatimfont{\typingparameter\c!style\normalnoligatures\font}%
+ % more generic, but beware of the \redoconvertfont (else no typing in titles and such)
+ \def\verbatimfont{\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style\normalnoligatures\font}%
+ \setupverbatimcolor}
+
+% BEWARE: the noligatures will globally change the verbatim font's behaviour
+
+% test case:
+%
+% \definetype[typeTEX][option=tex]
+%
+% \typeTEX|\example---oeps|. this---ligates---again.
+% \typeTEX{\example---oeps}. this---ligates---again.
+% \type {\example---oeps}. this---ligates---again.
+
+\def\setupcommandsintype % can also be \string\
+ {\setupgroupedtype
+ \edef\\{\typingparameter\c!escape}%
+ \letvalue{\\}=\\% for instance \/=/
+ \@EA\catcode\@EA`\\=\@@escape
+ \def\BTEX##1\ETEX##2% ##2 gobbles active space
+ {\naturaltextext##1\unskip\relax}}
+
+\def\setupslantedtype
+ {\slantedtypepermittedtrue\setupgroupedtype}
+
+\ifx\setupprettytype \undefined \let\setupprettytype \relax \fi
+\ifx\setupslantedtype \undefined \let\setupslantedtype \relax \fi
+\ifx\setupgroupedtype \undefined \let\setupgroupedtype \relax \fi
+\ifx\normalnoligatures\undefined \let\normalnoligatures\gobbleoneargument \fi
+
+%D The verbatim commands have a rather long and turbulent
+%D history. Most users of \CONTEXT\ probably will never use
+%D some of the features, but I've kept in mind that when one is
+%D writing a users manual, about everything can and undoubtly
+%D will be subject to a verbatim treatment.
+%D
+%D Verbatim command are very sensitive to argument processing,
+%D which is a direct result of the \CATCODES\ being fixed at
+%D reading time. With our growing understanding of \TEX,
+%D especially of the mechanism that can be used for looking
+%D ahead and manipulating \CATCODES, the verbatim support
+%D became more and more advanced and natural.
+%D
+%D Typesetting inline verbatim can be accomplished by
+%D \type{\type}, which in this sentence was typeset by saying
+%D just \type{\type{\type}}, which in turn was typeset by
+%D \unknown. Using the normal grouping characters \type{{}} is
+%D the most natural way of using this command.
+%D
+%D A second, more or less redundant, alternative is delimiting
+%D the argument with an own character. This method was
+%D implemented in the context of a publication in the \MAPS,
+%D where this way of delimiting is recognized by \LATEX\ users.
+%D
+%D The third, more original alternative, is the one using
+%D \type{<<} and \type{>>} as delimiters. This alternative can
+%D be used in situations where slanted typeseting is needed.
+
+% todo: we can use \letter... here:
+
+\def\lesscharacter {<}
+\def\morecharacter {>}
+
+\chardef\texescape = `\\
+\chardef\leftargument = `\{
+\chardef\rightargument = `\}
+
+%D \macros
+%D {type}
+%D
+%D We define \type{\type} as a protected command. This command
+%D has several invocations: grouped, wirt boundary characters,
+%D and with font switches.
+
+% \starttyping
+% normal: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
+% normal: \par \type{xx<..xx.. >..>xx} \par \type{<....>} \par \type{<....>}
+% \setuptype[option=slanted]
+% slanted: \par \type{xx<<..sl..<> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<>..>> \par
+% slanted: \par \type{xx<<..sl.. xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<....>> \par
+% \setuptype[option=none]
+% none: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
+% \stoptyping
+
+%D When writing the manual to \CONTEXT\ and documenting this
+%D source we needed to typeset \type{<<} and \type{>>}. Because
+%D we wanted to do this in the natural way, we've adapted the
+%D original definition a bit. This implementation went through
+%D several live cycles. The final implementation looks a bit
+%D further and treats the lone \type{<<} and \type{>>} a bit
+%D different. The \type {\null} prevents ligatures, which
+%D unfortunately turn up in Lucida fonts.
+
+%D The following lines show what happens when we set
+%D \type {option=commands}.
+%D
+%D \startbuffer
+%D \starttyping
+%D test//test test/BTEX \footnote{test test test}/ETEX test
+%D test//test test/BTEX \footnote{test test test}/ETEX test
+%D test test test/BTEX \bf(nota bene)/ETEX test
+%D test test test /BTEX \bf(nota bene)/ETEX test
+%D \stoptyping
+%D \stopbuffer
+%D
+%D % \bgroup\setuptyping[option=commands]\getbuffer\egroup
+%D
+%D this was keyed in as:
+%D
+%D \typebuffer
+
+\unexpanded\def\type{\dotype\empty}
% not that fast but catches \type{\command} % nothing more after \command
%
@@ -51,7 +311,7 @@
% the rather messy \type command
-\def\mktype#1% was \dotype
+\def\dotype#1% was \dotype
{\bgroup
\resumecoloraftergroup % a problem is that we can still be in color mode, tricky hack
\begstrut % new, enables leading space in \type { abc } at par start / begstrut else no hyphenation
@@ -101,6 +361,32 @@
\@EAEAEA\dodotypeD
\fi\fi}
+% The next one is safe for: \def\xx#1{\type{#1}} \xx{\ifx}
+
+\let\protectedfirsttype\string % \relax for special cases
+
+\bgroup
+\catcode`\<=\active
+\catcode`\>=\active
+\gdef\doprotectfirsttype
+ {\normalifx\next<%
+ \endrobusttest \let\next\relax
+ \normalelse\normalifx\next\bgroup
+ \endrobusttest \let\next\relax
+ \normalelse\normalifx\next\egroup % takes care of \type{}
+ \endrobusttest \let\next\relax
+ \normalelse\normalifx\next\activeleftargument
+ \endrobusttest \let\next\relax
+ \normalelse
+ \endrobusttest \let\next\protectedfirsttype
+ \normalfi\normalfi\normalfi\normalfi
+ \next}
+\egroup
+
+\def\protectfirsttype
+ {\beginrobusttest
+ \futurelet\next\doprotectfirsttype}
+
% Verbatim does not work when passed as an argument, so here is a
% workaround. Beware, spaces are introduced after a \type {\csname}.
@@ -247,52 +533,802 @@
\def>{\futurelet\next\domore}}
\egroup
-\def\mksetupcommandsintype% can also be \string\
- {\setupgroupedtype
- \edef\\{\typingparameter\c!escape}%
- \letvalue{\\}=\\% for instance \/=/
- \@EA\catcode\@EA`\\=\@@escape
- \def\BTEX##1\ETEX##2% ##2 gobbles active space
- {\naturaltextext##1\unskip\relax}}
+%D The neccessary initializations are done by calling
+%D \type{\initializetype} which in return calls for the support
+%D macro \type{\setupinlineverbatim}.
-\def\mksetupslantedtype
- {\setupgroupedtype}
+\def\initializetype
+ {\let\obeylines\ignorelines
+ \setupcommonverbatim
+ \setupinlineverbatim}
-\let\protectedfirsttype\string % \relax for special cases
+%D \macros
+%D {setuptype}
+%D
+%D Some characteristics of \type{\type} can be set up by:
-% The next one is safe for: \def\xx#1{\type{#1}} \xx{\ifx}
+\def\setuptype
+ {\dodoubleempty\dosetuptype}
-\bgroup
-\catcode`\<=\active
-\catcode`\>=\active
-\gdef\doprotectfirsttype
- {\normalifx\next<%
- \endrobusttest \let\next\relax
- \normalelse\normalifx\next\bgroup
- \endrobusttest \let\next\relax
- \normalelse\normalifx\next\egroup % takes care of \type{}
- \endrobusttest \let\next\relax
- \normalelse\normalifx\next\activeleftargument
- \endrobusttest \let\next\relax
- \normalelse
- \endrobusttest \let\next\protectedfirsttype
- \normalfi\normalfi\normalfi\normalfi
- \next}
-\egroup
+\def\dosetuptype[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??ty#1][#2]%
+ \else
+ \getparameters[\??ty][#1]%
+ \fi}
-\def\protectfirsttype
- {\beginrobusttest
- \futurelet\next\doprotectfirsttype}
+%D \macros
+%D {typ,obeyhyphens,obeybreakpoints}
+%D
+%D Although it's not clear from the macros, one character
+%D trait of this macros, which are build on top of the support
+%D module, is that they don't hyphenate. We therefore offer
+%D the alternative \type{\typ}. The current implementation
+%D works all right, but a decent hyphenation support of
+%D \type{\tt} text will be implemented soon.
+
+\def\obeyhyphens
+ {\def\obeyedspace {\hskip\interwordspace\relax}% better than spaceskip
+ \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax}%
+ \spaceskip.25em\relax} % hm a bit of stretch !
-% typing:
+\def\obeybreakpoints
+ {\ignorehyphens
+ \veryraggedright}
-\def\mktypeblockverbatim#1#2%
- {\processdisplayverbatim{#2}} % needs to be fixed
+\def\ignorehyphens
+ {% \language\minusone % extra bonus, the \null should do the job too
+ \def\obeyedspace {\hskip\interwordspace\relax}% better than spaceskip
+ \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax}%
+ \spaceskip.5em\relax}
-% typefile:
+\unexpanded\def\typ
+ {\bgroup
+ \let\@@tylines\v!hyphenated
+ \futurelet\next\dodotype}
-\def\mktypefileverbatim {\processfileverbatim \readfilename} % #1
-\def\mktypefilelinesverbatim{\processfilelinesverbatim\readfilename} % #1 / #2#3
+%D \macros
+%D {tex,arg,mat,dis}
+%D
+%D Sometimes, for instance when we pass verbatim text as an
+%D argument, the fixed \CATCODES\ interfere with our wishes. An
+%D experimental implementation of character by character
+%D processing of verbatim text did overcome this limitation,
+%D but we've decided not to use that slow and sometimes
+%D troublesome solution. Instead we stick to some 'old'
+%D \CONTEXT\ macros for typesetting typical \TEX\ characters.
+%D
+%D The next implementation is more clear but less versatile,
+%D so we treated it for a beter one.
+%D
+%D \starttyping
+%D \def\dospecialtype#1#2%
+%D {\bgroup
+%D \initializetype
+%D \catcode`\{=\@@begingroup
+%D \catcode`\}=\@@endgroup
+%D \def\dospecialtype%
+%D {\def\dospecialtype{#2\egroup}%
+%D \bgroup
+%D \aftergroup\dospecialtype
+%D #1}%
+%D \afterassignment\dospecialtype
+%D \let\next=}
+%D
+%D \unexpanded\def\tex{\dospecialtype\texescape\relax}
+%D \unexpanded\def\arg{\dospecialtype\leftargument\rightargument}
+%D \unexpanded\def\mat{\dospecialtype\$\$}
+%D \unexpanded\def\dis{\dospecialtype{\$\$}{\$\$}}
+%D \stoptyping
-\protect \endinput
+\def\setgroupedtype
+ {\let\currenttypingclass\??ty
+ \initializetype
+ \verbatimcolor
+ %\setcatcodetable \typcatcodesa
+ \catcode`\{=\@@begingroup
+ \catcode`\}=\@@endgroup}
+
+\unexpanded\def\tex{\groupedcommand{\setgroupedtype\texescape}{\relax}}
+\unexpanded\def\arg{\groupedcommand{\setgroupedtype\leftargument}{\rightargument}}
+\unexpanded\def\mat{\groupedcommand{\setgroupedtype\$}{\$}}
+\unexpanded\def\dis{\groupedcommand{\setgroupedtype\$\$}{\$\$}}
+
+%D \macros
+%D {starttyping}
+%D
+%D Display verbatim is realized far more easy, which is mostly
+%D due to the fact that we use \type{\stop...} as delimiter.
+%D The implementation inherits some features, for instance the
+%D support of linenumbering, which can best be studied in the
+%D documented support module.
+
+\let\currenttyping \empty
+\let\currenttypingclass\??ty % saveguard
+
+% \def\typingparameter#1%
+% {\executeifdefined
+% {\currenttypingclass\currenttyping#1}%
+% {\executeifdefined{\currenttypingclass#1}\empty}}
+
+\def\typingparameter#1%
+ {\ifcsname\currenttypingclass\currenttyping#1\endcsname
+ \csname\currenttypingclass\currenttyping#1\endcsname
+ \else\ifcsname\currenttypingclass#1\endcsname
+ \csname\currenttypingclass#1\endcsname
+ \fi\fi}
+
+\def\settypingparameter#1#2%
+ {\setvalue{\currenttypingclass\currenttyping#1}{#2}}
+
+\def\setxtypingparameter#1#2%
+ {\setxvalue{\currenttypingclass\currenttyping#1}{#2}}
+
+% \def\initializetyping
+% {%\donefalse
+% \switchtobodyfont[\typingparameter\c!bodyfont]%
+% \donefalse
+% \scratchskip\typingparameter\c!oddmargin\relax
+% \ifzeropt\scratchskip\else\donetrue\fi
+% \scratchskip\typingparameter\c!evenmargin\relax
+% \ifzeropt\scratchskip\else\donetrue\fi
+% \ifdone
+% \def\doopenupverbatimline
+% {\getpagestatus
+% \ifrightpage
+% \hskip\typingparameter\c!oddmargin\relax
+% \else
+% \hskip\typingparameter\c!evenmargin\relax
+% \fi}%
+% \else
+% \doadaptleftskip{\typingparameter\c!margin}%
+% \fi
+% \doifdefinedelse{\??bo\typingparameter\c!blank}
+% {\edef\!!stringa{\csname\??bo\typingparameter\c!blank\endcsname}}
+% {\edef\!!stringa{\typingparameter\c!blank}}%
+% \processaction
+% [\!!stringa]
+% [ \v!standard=>\scratchskip\ctxparskip,
+% \v!small=>\scratchskip\blankokleinmaat,
+% \v!medium=>\scratchskip\blankomiddelmaat,
+% \v!big=>\scratchskip\blankogrootmaat,
+% \v!halfline=>\scratchskip.5\baselineskip,
+% \v!line=>\scratchskip\baselineskip,
+% \v!none=>\scratchskip\zeropoint,
+% \s!unknown=>\scratchskip\commalistelement]%
+% \ifgridsnapping
+% \ifdim\scratchskip=.5\baselineskip\relax
+% \edef\verbatimbaselineskip{\the\scratchskip}% new
+% \else
+% \edef\verbatimbaselineskip{\the\baselineskip}%
+% \fi
+% \else
+% \edef\verbatimbaselineskip{\the\scratchskip}%
+% \fi
+% \setupcommonverbatim}
+
+\setvalue{\??tp:\c!blank:\v!standard}{\ctxparskip}
+\setvalue{\??tp:\c!blank:\v!small }{\blankokleinmaat}
+\setvalue{\??tp:\c!blank:\v!medium }{\blankomiddelmaat}
+\setvalue{\??tp:\c!blank:\v!big }{\blankogrootmaat}
+\setvalue{\??tp:\c!blank:\v!halfline}{.5\baselineskip}
+\setvalue{\??tp:\c!blank:\v!line }{\baselineskip}
+\setvalue{\??tp:\c!blank:\v!none }{\zeropoint}
+
+\def\initializetyping
+ {%\donefalse
+ \switchtobodyfont[\typingparameter\c!bodyfont]%
+ \donefalse
+ \scratchskip\typingparameter\c!oddmargin\relax
+ \ifzeropt\scratchskip\else\donetrue\fi
+ \scratchskip\typingparameter\c!evenmargin\relax
+ \ifzeropt\scratchskip\else\donetrue\fi
+ \ifdone
+ \def\doopenupverbatimline
+ {\getpagestatus
+ \ifrightpage
+ \hskip\typingparameter\c!oddmargin\relax
+ \else
+ \hskip\typingparameter\c!evenmargin\relax
+ \fi}%
+ \else
+ \doadaptleftskip{\typingparameter\c!margin}%
+ \fi
+ \edef\!!stringa{\executeifdefined{\??bo\typingparameter\c!blank}{\typingparameter\c!blank}}%
+ \scratchskip\executeifdefined{\??tp:\c!blank:\!!stringa}\!!stringa\relax
+ \ifgridsnapping
+ \ifdim\scratchskip=.5\baselineskip\relax
+ \edef\verbatimbaselineskip{\the\scratchskip}% new
+ \else
+ \edef\verbatimbaselineskip{\the\baselineskip}%
+ \fi
+ \else
+ \edef\verbatimbaselineskip{\the\scratchskip}%
+ \fi
+ \setupcommonverbatim}
+
+%D The basic display verbatim commands are defined in an
+%D indirect way. As we will see, they are a specific case of a
+%D more general mechanism.
+
+% we need this hack because otherwise verbatim skips
+% the first line (everything after the initial command)
+
+\def\dostarttyping#1% tricky non standard lookahead
+ {\bgroup
+ \let\currenttypingclass\??tp
+ \edef\currenttyping{#1}%
+ \obeylines
+ \futurelet\nexttoken\dodostarttyping}
+
+\def\dodostarttyping
+ {\ifx\nexttoken[%
+ \expandafter\dododostarttyping
+ \else
+ \expandafter\nododostarttyping
+ \fi}
+
+\def\nododostarttyping
+ {\dododostarttyping[]}
+
+\def\dododostarttyping[#1]%
+ {\typingparameter\c!before
+ \startpacked % includes \bgroup
+ \dosetuptypelinenumbering{#1}%
+ \initializetyping
+ \startverbatimcolor
+ \expanded{\processdisplayverbatim{\s!stop\currenttyping}}}
+
+\def\dostoptyping#1% hm, currenttyping
+ {\stopverbatimcolor
+ \stoppacked % includes \egroup
+ \typingparameter\c!after
+ \egroup
+ \dochecknextindentation{\??tp#1}%
+ \dorechecknextindentation}
+
+%D Line numbering for files is combined with filtering, while
+%D display verbatim has the ability to continue.
+%D
+%D \starttyping
+%D \typefile[numbering=file,start=10,stop=12]{test.tex}
+%D
+%D \definetyping[code][numbering=line]
+%D
+%D \starttext
+%D \startcode
+%D ...
+%D ...
+%D \stopcode
+%D
+%D \startcode[continue]
+%D ...
+%D ...
+%D \stopcode
+%D
+%D \startcode[start=10]
+%D ...
+%D \stopcode
+%D \stoptyping
+
+%D \macros
+%D {setuptyping}
+%D
+%D The setup of typing accepts two arguments. The optional
+%D first one identifies the user defined ones. If only one
+%D argument is given, the values apply to both the standard
+%D command \type{\starttyping} and \type{\typefile}.
+
+\def\dosetuptyping[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??tp#1][#2]%
+ \else
+ \getparameters[\??tp][#1]%
+ \fi}
+
+\def\setuptyping
+ {\dodoubleempty\dosetuptyping}
+
+%D \macros
+%D {definetype}
+%D
+%D Specific inline verbatim commands can be defined with the
+%D following command.
+
+\def\definetype
+ {\dodoubleempty\dodefinetype}
+
+\def\dodefinetype[#1][#2]%
+ {\unexpanded\setvalue{#1}{\dotype{#1}}%
+ \getparameters[\??ty#1][#2]}
+
+%D \macros
+%D {definetyping}
+%D
+%D For most users the standard \type{\start}||\type{\stop}||pair
+%D will suffice, but for documentation purposes the next
+%D definition command can be of use:
+%D
+%D \starttyping
+%D \definetyping[extratyping][margin=3em]
+%D
+%D \startextratyping
+%D these extra ones are indented by 1 em
+%D \stopextratyping
+%D \stoptyping
+%D
+%D The definitions default to the standard typing values.
+
+\def\presettyping[#1][#2]%
+ {\copyparameters[\??tp#1][\??tp][\c!color,\c!style]%
+ \getparameters [\??tp#1][#2]}
+
+\def\dodefinetyping[#1][#2]%
+ {\setvalue{\e!start#1}{\dostarttyping{#1}}%
+ \setvalue{\e!stop #1}{\dostoptyping {#1}}%
+ \presettyping[#1][#2]}
+
+\def\definetyping
+ {\dodoubleempty\dodefinetyping}
+
+%D We can use some core color commands. These are faster than
+%D the standard color switching ones and work ok on a line by
+%D line basis.
+%D
+%D \starttyping
+%D \def\setupverbatimcolor%
+%D {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}%
+%D \def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
+%D \def\endofpretty {\stopcolormode}}
+%D \stoptyping
+%D
+%D Since we support a global color too, the folowing
+%D definition is better:
+
+% \def\setupverbatimcolor% fast and local versus slow and global
+% {\doifelsenothing{\typingparameter\c!color}
+% {\def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
+% \let\endofpretty \restorecolormode % \stopcolormode
+% \let\startverbatimcolor \relax
+% \let\stopverbatimcolor \relax
+% \let\verbatimcolor \relax}
+% {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
+% \let\endofpretty \stopcolor
+% \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
+% \let\stopverbatimcolor \stopcolor
+% \def\verbatimcolor {\getvalue{\typingparameter\c!color}}}% command !
+% \doifelsenothing{\typingparameter\c!palet}
+% {\let\prettypalet\empty
+% \let\endofpretty\relax
+% \def\beginofpretty[##1]{}}
+% {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
+%
+% let's forget about this optimization not that we have mkiv
+
+\def\setupverbatimcolor
+ {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
+ \let\endofpretty \stopcolor
+ \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
+ \let\stopverbatimcolor \stopcolor
+ \def\verbatimcolor {\getvalue{\typingparameter\c!color}}% command !
+ \doifelsenothing{\typingparameter\c!palet}
+ {\let\prettypalet\empty
+ \let\endofpretty\relax
+ \def\beginofpretty[##1]{}}
+ {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
+
+\let\prettypalet \empty
+\let\startverbatimcolor\relax
+\let\stopverbatimcolor \relax
+\let\verbatimcolor \relax
+
+%D In the verbatim module, there are some examples given of
+%D the more obscure features of the verbatim environments.
+%D
+%D \startbuffer
+%D \startTEX
+%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
+%D \stopTEX
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D This gives, as can be expected:
+%D
+%D \getbuffer
+%D
+%D When we want to see some typeset \TEX\ too, we can say:
+%D
+%D \startbuffer
+%D \startTEX
+%D \def\mathematics#1% %%\ N usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} %%\ N becomes: \mathematics{x^2}
+%D \stopTEX
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or:
+%D
+%D \getbuffer
+%D
+%D In a similar way:
+%D
+%D \startbuffer
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D gives:
+%D
+%D \getbuffer
+%D
+%D The next examples sow how we can directly call for natural
+%D \TEX\ comments:
+%D
+%D \startbuffer
+%D \setuptyping
+%D [TEX]
+%D [text=yes]
+%D
+%D \startTEX
+%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
+%D \stopTEX
+%D
+%D \setuptyping
+%D [SQL]
+%D [text=yes,palet=,icommand=\bf,vcommand=,ccommand=\it]
+%D
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D
+%D \setuptyping
+%D [SQL]
+%D [ccommand=\tf\underbar]
+%D
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D Now watch:
+%D
+%D \getbuffer
+%D
+%D The natural \TEX\ typesetting was introduced when Tobias
+%D and Berend started using verbatim \JAVASCRIPT\ and \SQL.
+
+%D \macros
+%D {EveryPar, EveryLine, iflinepar}
+%D
+%D One of the features of these commands is the support of
+%D \type{\EveryPar}, \type{\EveryLine} and \type{\iflinepar}.
+%D In the documentation of the verbatim support module we give
+%D some examples of line- and paragraph numbering using these
+%D macros.
+
+%D \macros
+%D {typefile}
+%D
+%D Typesetting files verbatim (for the moment) only supports
+%D colorization of \TEX\ sources as valid option. The other
+%D setup values are inherited from display verbatim.
+%D The implementation of \type{\typefile} is straightforward:
+% new feature (not yet 100\% ok)
+%
+% \setuptyping[file][numbering=file]
+%
+% \typefile[start=2,nlines=3]{zapf}
+% \typefile[start=continue,nlines=13]{zapf}
+% \typefile{zapf}
+%
+% \setuptyping[file][numbering=line]
+%
+% \typefile[start=4,step=3]{zapf}
+% \typefile{zapf}
+
+\def\typefile
+ {\dodoubleempty\dotypefile}
+
+\def\dotypefile[#1][#2]#3%
+ {\ifsecondargument
+ \dodotypefile[#1][#2]{#3}%
+ \else\iffirstargument
+ \doifassignmentelse{#1}
+ {\dodotypefile[\v!file][#1]{#3}}
+ {\dodotypefile[#1][]{#3}}%
+ \else
+ \dodotypefile[\v!file][]{#3}%
+ \fi\fi}
+
+\def\dosetuptypelinenumbering#1% fuzzy
+ {\doifundefined{\currenttypingclass\currenttyping\c!start}
+ {\setuptyping[\currenttyping][\c!start=1,\c!stop=,\c!step=1,\c!nlines=]}%
+ \setuptyping[\currenttyping][#1]%
+ \doifelse{\typingparameter\c!numbering}\v!file
+ {% kind of special: filters lines !
+ \setuplinenumbering[\c!method=\v!file]%
+ \donetrue}
+ {\doifelse{\typingparameter\c!numbering}\v!line
+ {% \setuplinenumbering defaults start/step to 1/1, so we need
+ \doifinsetelse\v!continue{#1,\typingparameter\c!start}
+ {\scratchcounter0\typingparameter\c!n
+ \setxtypingparameter\c!start{\ifnum\scratchcounter=0 1\else\number\scratchcounter\fi}}%
+ {\doifnothing{\typingparameter\c!start}{\settypingparameter\c!start{1}}}%
+ \doifnothing{\typingparameter\c!step}{\settypingparameter\c!step{1}}%
+ \setuplinenumbering
+ [\c!method=\v!type,
+ \c!start=\typingparameter\c!start,
+ \c!stop=\typingparameter\c!stop,
+ \c!step=\typingparameter\c!step]%
+ \donetrue}
+ {\donefalse}}%
+ \ifdone
+ \ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
+ \ifx\stoplinenumbering \undefined \let\stoplinenumbering \relax \fi
+ \def\beginofverbatimlines{\startlinenumbering}%
+ \def\endofverbatimlines {\stoplinenumbering\setxtypingparameter\c!n{\number\linenumber}}%
+ \fi}
+
+\def\reporttypingerror#1% temp hack
+ {\blank
+ \dontleavehmode\hbox\bgroup
+ \expanded{\defconvertedargument\noexpand\ascii{#1}}%
+ \tttf[\makemessage\m!verbatims1\ascii]%
+ \showmessage\m!verbatims1\ascii
+ \egroup
+ \blank}
+
+\def\dosometyping#1#2#3#4#5%
+ {\bgroup
+ \let\currenttypingclass\??tp
+ \edef\currenttyping{#1}%
+ \typingparameter\c!before
+ \startpacked % includes \bgroup
+ \dosetuptypelinenumbering{#2}%
+ \doifinset{\typingparameter\c!option}{\v!commands,\v!slanted,\v!normal}
+ {\setuptyping[#1][\c!option=\v!none]}%
+ \doif{\typingparameter\c!option}\v!color
+ {\expandafter\aftersplitstring#3\at.\to\prettyidentifier
+ \settypingparameter\c!option{\prettyidentifier}}%
+ \initializetyping
+ \startverbatimcolor
+ \doifundefinedelse{\currenttypingclass#3\v!global\c!start}
+ {\scratchcounter\zerocount}
+ {\scratchcounter\getvalue{\currenttypingclass#3\v!global\c!start}}%
+ \advance\scratchcounter\plusone
+ \setxvalue{\currenttypingclass#3\v!global\c!start}{\the\scratchcounter}%
+ \doifelsenothing{\typingparameter\c!start}
+ {#4}
+ {\doif{\typingparameter\c!start}\v!continue
+ {\setevalue{\currenttypingclass#1\c!start}%
+ {\getvalue{\currenttypingclass#3\v!global\c!start}}}%
+ \doifelsenothing{\typingparameter\c!stop}
+ {\doifelsenothing{\typingparameter\c!nlines}
+ {#4}
+ {\setxvalue{\currenttypingclass#3\v!global\c!start}%
+ {\the\numexpr\typingparameter\c!start+\typingparameter\c!nlines+\minusone\relax}%
+ #5{\typingparameter\c!start}{\getvalue{\currenttypingclass#3\v!global\c!start}}}}%
+ {#5{\typingparameter\c!start}{\typingparameter\c!stop}}}%
+ \stopverbatimcolor
+ \stoppacked
+ \typingparameter\c!after
+ \egroup}
+
+\def\doifelsetypingfile#1% sets \readfilename (we will make this proper mkiv i.e. less messy)
+ {\doiflocfileelse{#1}
+ {\firstoftwoarguments}
+ {\doifinputfileelse{#1}
+ {\def\readfilename{\pathplusfile\filepath{#1}}\firstoftwoarguments} % messy, looks wrong too
+ {\secondoftwoarguments}}}
+
+\def\dodotypefile[#1][#2]#3%
+ {\doifelsetypingfile{#3}
+ {\dosometyping{#1}{#2}{#3}{\processfileverbatim\readfilename}{\processfilelinesverbatim\readfilename}}
+ {\reporttypingerror{#3}}}
+
+%D \macros
+%D {filename}
+%D
+%D Typesetting filenames in monospaced fonts is possible with
+%D
+%D \starttyping
+%D \filename{here/there/filename.suffix}
+%D \stoptyping
+%D
+%D The definition is not that spectacular.
+
+\unexpanded\def\filename#1{{\tttf\hyphenatedfilename{#1}}}
+
+%D This leaves some settings:
+
+\permitshiftedendofverbatim
+\optimizeverbatimtrue
+
+%D And a bonus macro:
+
+\def\verbatim#1{\defconvertedargument\ascii{#1}\ascii}
+
+%D The setups for display verbatim and file verbatim are
+%D shared. One can adapt the extra defined typing environments,
+%D but they also default to the values below. Watch the
+%D alternative escape character.
+
+\setuptyping
+ [ \c!before=\blank,
+ \c!after=\blank,
+ \c!bodyfont=,
+ \c!color=,
+ \c!space=\v!off,
+ \c!page=\v!no,
+ \c!tab=\s!ascii,
+ \c!option=\v!none,
+ \c!palet=colorpretty,
+ \c!text=\v!no,
+ \c!style=\tttf,
+ \c!icommand=\ttsl,
+ \c!vcommand=,
+ \c!ccommand=\tttf,
+ \c!indentnext=\v!yes,
+ \c!margin=\!!zeropoint,
+ \c!evenmargin=\!!zeropoint,
+ \c!oddmargin=\!!zeropoint,
+ \c!blank=\v!line,
+ \c!escape=/, % beware \string\ , should also be accepted
+ \c!numbering=\v!no,
+ \c!lines=,
+ \c!empty=,
+ \c!start=1,
+ \c!stop=,
+ \c!step=1,
+ \c!continue=,
+ \c!nlines=]
+
+\definetyping[\v!typing]
+
+\presettyping[\v!file][]
+
+% \setuptyping % not needed
+% [\v!file]
+% [\c!start=1,
+% \c!stop=,
+% \c!step=1,
+% \c!continue=,
+% \c!nlines=]
+
+%D The setups for inline verbatim default to:
+
+\setuptype
+ [ \c!space=\v!off,
+ \c!color=,
+ \c!style=\tt\tf, % \tttf gives problems with {\tx \type...}
+ \c!page=\v!no,
+ \c!tab=\v!yes,
+ \c!palet=colorpretty,
+ \c!option=\v!normal]
+
+\definetyping[RAW] [\c!option=RAW]
+\definetyping[MP] [\c!option=MP]
+\definetyping[PL] [\c!option=PL]
+\definetyping[PM] [\c!option=PL]
+\definetyping[JS] [\c!option=JS]
+\definetyping[JV] [\c!option=JV]
+\definetyping[SQL] [\c!option=SQL]
+\definetyping[TEX] [\c!option=TEX]
+\definetyping[PAS] [\c!option=PAS]
+\definetyping[PASCAL][\c!option=PAS]
+\definetyping[MOD] [\c!option=PAS]
+\definetyping[MODULA][\c!option=PAS]
+\definetyping[DELPHI][\c!option=PAS]
+\definetyping[EIFFEL][\c!option=EIF]
+\definetyping[XML] [\c!option=XML]
+\definetyping[LUA] [\c!option=LUA]
+
+\installprettytype [RAW] [RAW]
+
+\installprettytype [TEX] [TEX]
+
+\installprettytype [PERL] [PL]
+\installprettytype [PL] [PL]
+\installprettytype [PM] [PL]
+
+\installprettytype [METAPOST] [MP]
+\installprettytype [METAFONT] [MP]
+\installprettytype [MP] [MP]
+\installprettytype [MF] [MP]
+
+\installprettytype [JAVASCRIPT] [JS]
+\installprettytype [JAVA] [JV]
+\installprettytype [JS] [JS]
+\installprettytype [JV] [JV]
+
+\installprettytype [SQL] [SQL]
+
+\installprettytype [PASCAL] [PAS]
+\installprettytype [PAS] [PAS]
+\installprettytype [MODULA] [PAS]
+\installprettytype [MOD] [PAS]
+
+\installprettytype [EIFFEL] [EIF]
+\installprettytype [EIF] [EIF]
+\installprettytype [E] [EIF]
+
+\installprettytype [XML] [XML]
+
+\installprettytype [LUA] [LUA]
+
+\installnewpretty M {\setupprettiesintype {MP}\setupprettytype}
+\installnewpretty P {\setupprettiesintype {PL}\setupprettytype}
+\installnewpretty T {\setupprettiesintype{TEX}\setupprettytype}
+\installnewpretty J {\setupprettiesintype {JV}\setupprettytype}
+\installnewpretty S {\setupprettiesintype{SQL}\setupprettytype}
+\installnewpretty W {\setupprettiesintype{PAS}\setupprettytype} % Wirth
+\installnewpretty I {\setupprettiesintype{EIF}\setupprettytype} % E taken
+\installnewpretty X {\setupprettiesintype{XML}\setupprettytype}
+
+%D We use the \CONTEXT\ color system for switching to and from
+%D color mode. We can always redefine these colors afterwards.
+
+\definecolor [colorprettyone] [r=.9, g=.0, b=.0] % red
+\definecolor [colorprettytwo] [r=.0, g=.8, b=.0] % green
+\definecolor [colorprettythree] [r=.0, g=.0, b=.9] % blue
+\definecolor [colorprettyfour] [r=.8, g=.8, b=.6] % yellow
+
+\definecolor [grayprettyone] [s=.30]
+\definecolor [grayprettytwo] [s=.45]
+\definecolor [grayprettythree] [s=.60]
+\definecolor [grayprettyfour] [s=.75]
+
+\definepalet
+ [colorpretty]
+ [ prettyone=colorprettyone,
+ prettytwo=colorprettytwo,
+ prettythree=colorprettythree,
+ prettyfour=colorprettyfour]
+
+\definepalet
+ [graypretty]
+ [ prettyone=grayprettyone,
+ prettytwo=grayprettytwo,
+ prettythree=grayprettythree,
+ prettyfour=grayprettyfour]
+
+\definepalet [TEXcolorpretty] [colorpretty]
+\definepalet [TEXgraypretty] [graypretty]
+\definepalet [PLcolorpretty] [colorpretty]
+\definepalet [PLgraypretty] [graypretty]
+\definepalet [PMcolorpretty] [colorpretty]
+\definepalet [PMgraypretty] [graypretty]
+\definepalet [MPcolorpretty] [colorpretty]
+\definepalet [MPgraypretty] [graypretty]
+\definepalet [JVcolorpretty] [colorpretty]
+\definepalet [JVgraypretty] [graypretty]
+\definepalet [JScolorpretty] [colorpretty]
+\definepalet [JSgraypretty] [graypretty]
+\definepalet [SQLcolorpretty] [colorpretty]
+\definepalet [SQLgraypretty] [graypretty]
+\definepalet [PAScolorpretty] [colorpretty]
+\definepalet [PASgraypretty] [graypretty]
+\definepalet [EIFcolorpretty] [colorpretty]
+\definepalet [EIFgraypretty] [graypretty]
+\definepalet [XMLcolorpretty] [colorpretty]
+\definepalet [XMLgraypretty] [graypretty]
+\definepalet [LUAcolorpretty] [colorpretty]
+\definepalet [LUAgraypretty] [graypretty]
+
+\protect \endinput
diff --git a/tex/context/base/core-ver.mkiv b/tex/context/base/core-ver.mkiv
index dcc283d6f..e9c092f66 100644
--- a/tex/context/base/core-ver.mkiv
+++ b/tex/context/base/core-ver.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=core-ver,
-%D version=2000.10.13,
+%D version=2000.05.09,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Verbatim,
%D author=Hans Hagen,
@@ -11,45 +11,122 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Core Macros / Verbatim}
+
\unprotect
-\def\mksetupprettiesintype
- {\begingroup
+\ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
+\ifx\stoplinenumbering \undefined \let\stoplinenumbering\relax \fi
+\ifx\setuplinenumbering\undefined \def\setuplinenumbering[#1]{} \fi
+
+% \type{ char} geeft bagger
+
+%D We are going to embed the general verbatim support macros in
+%D a proper environment. First we show the common setup
+%D macro, so we know what features are supported. The options
+%D are hooked into the support macros via the \type{\obey}
+%D macros.
+
+\newif\ifslantedtypeactivated
+\newif\ifslantedtypepermitted
+
+\def\switchslantedtype
+ {\ifslantedtypepermitted
+ \ifslantedtypeactivated
+ \slantedtypeactivatedfalse\tttf
+ \else
+ \slantedtypeactivatedtrue\ttsl
+ \fi
+ \fi}
+
+\newprettytrue % movet to here from cont-sys.tex
+
+\def\prettyidentifier {TEX}
+\def\prettypalet {}
+
+\def\installprettytype
+ {\dodoubleargument\doinstallprettytype}
+
+\def\doinstallprettytype[#1][#2]% map #1 onto #2
+ {\uppercasestring#1\to\asciia
+ \uppercasestring#2\to\asciib
+ \setevalue{\??ty\??ty\asciia}{\asciib}}
+
+% \ctxluafileload{verb-tex}{}
+% \ctxluafileload{verb-mp} {}
+% \registerctxluafile{core-buf-tex}{}
+% \registerctxluafile{core-buf-mp} {}
+
+\def\setupprettiesintype#1%
+ {\uppercasestring#1\to\ascii
+ \edef\prettyidentifier{\executeifdefined{\??ty\??ty\ascii}{TEX}}%
+ \begingroup
\lowercasestring verb-\prettyidentifier\to\filename
\doonlyonce\filename{\ctxloadluafile\filename\empty}%
\endgroup}
-% todo: obeytabs|spaces|lines|pages
-
-% \def\mksetupprettytype % todo check
-% {\processingverbatimtrue % will move
-% \ctxlua{buffers.doifelsevisualizer("\prettyidentifier")}
-% {\ctxlua{buffers.setvisualizer("\prettyidentifier")}%
-% % \def\obs{\obeyedspace}%
-% % \def\bop{\bgroup\beginofpretty}%
-% % \def\eop{\endofpretty\egroup}%
-% % \def\sop{\endofpretty\egroup\bgroup\beginofpretty}}
-% }
-% {\def\obs{\obeyedspace}}}
-% \def\mkinitializeverbatim
-% {\ctxlua{buffers.visualizers.reset()}%
-% \localcolortrue % tricky, maybe not here
-% \def\obs{\obeyedspace}%
-% \def\obs{\obeyedspace}%
-% \def\bop{\bgroup\beginofpretty}%
-% \def\eop{\endofpretty\egroup}%
-% \def\sop{\endofpretty\egroup\bgroup\beginofpretty}%
-% \verbatimfont
-% \resetfontfeature
-% \obeycharacters}
-
-\def\mksetupprettytype % todo check
+\def\setupprettytype
{\processingverbatimtrue % will move
\ctxlua{buffers.visualizers.reset()}}
+\setvalue{\??tp:\c!lines:\v!yes }{\obeybreakpoints}
+\setvalue{\??tp:\c!lines:\v!hyphenated}{\obeyhyphens}
+
+\setvalue{\??tp:\c!empty:\v!yes }{\obeyemptylines}
+\setvalue{\??tp:\c!empty:\v!all }{\obeyallemptylines}
+
+\setvalue{\??tp:\c!option:\v!none }{\let\obeycharacters\relax}
+\setvalue{\??tp:\c!option:\v!color }{\setupprettiesintype{TEX}%
+ \let\obeycharacters\setupprettytype
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\v!normal }{\let\obeycharacters\setupgroupedtype}
+\setvalue{\??tp:\c!option:\v!commands }{\def\obeycharacters{\setupcommandsintype}%
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\v!slanted }{\let\obeycharacters\setupslantedtype
+ \let\obeytabs\ignoretabs}
+\setvalue{\??tp:\c!option:\s!unknown }{\setupprettiesintype{\typingparameter\c!option}%
+ \let\obeycharacters\setupprettytype
+ \let\obeytabs\ignoretabs}
+
+
+\def\setupcommonverbatim
+ {\recatcodeuppercharactersfalse % obey regime / encoding
+ %
+ \let\prettyidentifier\s!default
+ %
+ \doifelse{\typingparameter\c!text}\v!yes
+ \naturaltextexttrue
+ \naturaltextextfalse
+ \def\prettyidentifierfont{\typingparameter\c!icommand}%
+ \def\prettyvariablefont {\typingparameter\c!vcommand}%
+ \def\prettynaturalfont {\typingparameter\c!ccommand}%
+ %
+ \doif{\typingparameter\c!space}\v!on
+ {\def\obeyspaces{\setcontrolspaces}}%
+ \doif{\typingparameter\c!page }\v!no
+ {\def\obeypages {\ignorepages}}%
+ %
+ \doifelse{\typingparameter\c!tab}\v!yes
+ {\def\obeytabs{\settabskips}}%
+ {\doif{\typingparameter\c!tab}\s!ascii % not needed in mkiv
+ {\chardef\tabskipmode\plustwo % quit on >127
+ \def\obeytabs{\settabskips}}}%
+ %
+ \ignorehyphens % default
+ \getvalue{\??tp:\c!lines:\typingparameter\c!lines}%
+ \getvalue{\??tp:\c!empty:\typingparameter\c!empty}%
+ \getvalue{\??tp:\c!option:\ifcsname\??tp:\c!option:\typingparameter\c!option\endcsname\typingparameter\c!option\else\s!unknown\fi}%
+ \doifnumberelse{\typingparameter\c!tab}
+ {\def\obeytabs{\setfixedtabskips{\typingparameter\c!tab}}}%
+ \donothing
+ %\def\verbatimfont{\typingparameter\c!style\normalnoligatures\font}%
+ % more generic, but beware of the \redoconvertfont (else no typing in titles and such)
+ \def\verbatimfont{\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style\normalnoligatures\font}%
+ \setupverbatimcolor}
+
\newtoks \everyinitializeverbatim
-\def\mkinitializeverbatim
+\def\doinitializeverbatim
{\ctxlua{buffers.visualizers.reset()}%
\def\obs{\obeyedspace}%
\ctxlua{buffers.doifelsevisualizer("\prettyidentifier")}
@@ -69,37 +146,116 @@
\resetcharacterspacing
\to \everyinitializeverbatim
-% \ctxluafileload{verb-tex}{}
-% \ctxluafileload{verb-mp} {}
-
-% \registerctxluafile{core-buf-tex}{}
-% \registerctxluafile{core-buf-mp} {}
-
-% \def\mktype#1%
-% {\bgroup
-% \begstrut % new, enables leading space in \type { abc } at par start
-% \let\currenttypingclass\??ty
-% \edef\currenttyping{#1}%
-% \initializetype % probably too much
-% \verbatimcolor
-% \setcatcodetable \typcatcodesa
-% \dodotype}
-% \def\dodotype#1%
-% {\obeycharacters % everyinitializeverbatim
-% \ctxlua{buffers.hooks.flush_line(\!!bs\detokenize{#1}\!!es)}%
-% \egroup}
+% BEWARE: the noligatures will globally change the verbatim font's behaviour
-\let\mksetupslantedtype \relax
+% test case:
+%
+% \definetype[typeTEX][option=tex]
+%
+% \typeTEX|\example---oeps|. this---ligates---again.
+% \typeTEX{\example---oeps}. this---ligates---again.
+% \type {\example---oeps}. this---ligates---again.
-\def\mksetupcommandsintype% can also be \string\
+\def\setupcommandsintype % can also be \string\
{\ctxlua{
buffers.visualizers.enableescape = true
buffers.visualizers.escapetoken = \!!bs\typingparameter\c!escape\!!es
}%
\setevalue{\typingparameter\c!escape}{\typingparameter\c!escape}}
-\def\mktype#1% was \dotype
+\def\setupslantedtype
+ {\slantedtypepermittedtrue}
+
+\ifx\setupprettytype \undefined \let\setupprettytype \relax \fi
+\ifx\setupslantedtype \undefined \let\setupslantedtype \relax \fi
+\ifx\setupgroupedtype \undefined \let\setupgroupedtype \relax \fi
+\ifx\normalnoligatures\undefined \let\normalnoligatures\gobbleoneargument \fi
+
+%D The verbatim commands have a rather long and turbulent
+%D history. Most users of \CONTEXT\ probably will never use
+%D some of the features, but I've kept in mind that when one is
+%D writing a users manual, about everything can and undoubtly
+%D will be subject to a verbatim treatment.
+%D
+%D Verbatim command are very sensitive to argument processing,
+%D which is a direct result of the \CATCODES\ being fixed at
+%D reading time. With our growing understanding of \TEX,
+%D especially of the mechanism that can be used for looking
+%D ahead and manipulating \CATCODES, the verbatim support
+%D became more and more advanced and natural.
+%D
+%D Typesetting inline verbatim can be accomplished by
+%D \type{\type}, which in this sentence was typeset by saying
+%D just \type{\type{\type}}, which in turn was typeset by
+%D \unknown. Using the normal grouping characters \type{{}} is
+%D the most natural way of using this command.
+%D
+%D A second, more or less redundant, alternative is delimiting
+%D the argument with an own character. This method was
+%D implemented in the context of a publication in the \MAPS,
+%D where this way of delimiting is recognized by \LATEX\ users.
+%D
+%D The third, more original alternative, is the one using
+%D \type{<<} and \type{>>} as delimiters. This alternative can
+%D be used in situations where slanted typeseting is needed.
+
+% todo: we can use \letter... here:
+
+\def\lesscharacter {<}
+\def\morecharacter {>}
+
+\chardef\texescape = `\\
+\chardef\leftargument = `\{
+\chardef\rightargument = `\}
+
+%D \macros
+%D {type}
+%D
+%D We define \type{\type} as a protected command. This command
+%D has several invocations: grouped, wirt boundary characters,
+%D and with font switches.
+
+% \starttyping
+% normal: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
+% normal: \par \type{xx<..xx.. >..>xx} \par \type{<....>} \par \type{<....>}
+% \setuptype[option=slanted]
+% slanted: \par \type{xx<<..sl..<> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<>..>> \par
+% slanted: \par \type{xx<<..sl.. xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<....>> \par
+% \setuptype[option=none]
+% none: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
+% \stoptyping
+
+%D When writing the manual to \CONTEXT\ and documenting this
+%D source we needed to typeset \type{<<} and \type{>>}. Because
+%D we wanted to do this in the natural way, we've adapted the
+%D original definition a bit. This implementation went through
+%D several live cycles. The final implementation looks a bit
+%D further and treats the lone \type{<<} and \type{>>} a bit
+%D different. The \type {\null} prevents ligatures, which
+%D unfortunately turn up in Lucida fonts.
+
+%D The following lines show what happens when we set
+%D \type {option=commands}.
+%D
+%D \startbuffer
+%D \starttyping
+%D test//test test/BTEX \footnote{test test test}/ETEX test
+%D test//test test/BTEX \footnote{test test test}/ETEX test
+%D test test test/BTEX \bf(nota bene)/ETEX test
+%D test test test /BTEX \bf(nota bene)/ETEX test
+%D \stoptyping
+%D \stopbuffer
+%D
+%D % \bgroup\setuptyping[option=commands]\getbuffer\egroup
+%D
+%D this was keyed in as:
+%D
+%D \typebuffer
+
+\unexpanded\def\type{\dotype\empty}
+
+\def\dotype#1% was \dotype
{\bgroup
\begstrut % new, enables leading space in \type { abc } at par start / begstrut else no hyphenation
\let\currenttypingclass\??ty
@@ -124,7 +280,7 @@
\dodotypeAA}
\def\dodotypeAA#1%
- {\mkinitializeverbatim
+ {\doinitializeverbatim
\def\obs{\obeyedspace}%
\ctxlua{buffers.hooks.flush_line(\!!bs\detokenize{#1}\!!es)}%
\egroup}
@@ -136,7 +292,7 @@
\dodotypeBB}
\def\dodotypeBB#1%
- {\mkinitializeverbatim
+ {\doinitializeverbatim
\ctxlua{buffers.visualizers.flush_nested(\!!bs\detokenize{#1}\!!es,false)}%
\egroup
\gobbleoneargument} % grab last >
@@ -148,7 +304,7 @@
\dodotypeCC}
\def\dodotypeCC#1%
- {\mkinitializeverbatim
+ {\doinitializeverbatim
\ifx\obeycharacters\setupprettytype % temp hack, we need a proper signal
\ctxlua{buffers.hooks.flush_line([\!!bs\detokenize{#1}\!!es,true)}%
\else
@@ -166,33 +322,827 @@
\dodotypeDD}
\def\dodotypeDD#1%
- {\mkinitializeverbatim
+ {\doinitializeverbatim
\ctxlua{buffers.hooks.flush_line(\!!bs\detokenize{#1}\!!es,true)}%
\egroup
\gobbleoneargument} % grab last >
-% \typing:
+%D The neccessary initializations are done by calling
+%D \type{\initializetype} which in return calls for the support
+%D macro \type{\setupinlineverbatim}.
+
+\def\initializetype
+ {\let\obeylines\ignorelines
+ \setupcommonverbatim
+ \setupinlineverbatim}
+
+%D \macros
+%D {setuptype}
+%D
+%D Some characteristics of \type{\type} can be set up by:
+
+\def\setuptype
+ {\dodoubleempty\dosetuptype}
+
+\def\dosetuptype[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??ty#1][#2]%
+ \else
+ \getparameters[\??ty][#1]%
+ \fi}
+
+%D \macros
+%D {typ,obeyhyphens,obeybreakpoints}
+%D
+%D Although it's not clear from the macros, one character
+%D trait of this macros, which are build on top of the support
+%D module, is that they don't hyphenate. We therefore offer
+%D the alternative \type{\typ}. The current implementation
+%D works all right, but a decent hyphenation support of
+%D \type{\tt} text will be implemented soon.
+
+\def\obeyhyphens
+ {\def\obeyedspace {\hskip\interwordspace\relax}% better than spaceskip
+ \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax}%
+ \spaceskip.25em\relax} % hm a bit of stretch !
+
+\def\obeybreakpoints
+ {\ignorehyphens
+ \veryraggedright}
+
+\def\ignorehyphens
+ {% \language\minusone % extra bonus, the \null should do the job too
+ \def\obeyedspace {\hskip\interwordspace\relax}% better than spaceskip
+ \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax}%
+ \spaceskip.5em\relax}
+
+\unexpanded\def\typ
+ {\bgroup
+ \let\@@tylines\v!hyphenated
+ \futurelet\next\dodotype}
+
+%D \macros
+%D {tex,arg,mat,dis}
+%D
+%D Sometimes, for instance when we pass verbatim text as an
+%D argument, the fixed \CATCODES\ interfere with our wishes. An
+%D experimental implementation of character by character
+%D processing of verbatim text did overcome this limitation,
+%D but we've decided not to use that slow and sometimes
+%D troublesome solution. Instead we stick to some 'old'
+%D \CONTEXT\ macros for typesetting typical \TEX\ characters.
+%D
+%D The next implementation is more clear but less versatile,
+%D so we treated it for a beter one.
+%D
+%D \starttyping
+%D \def\dospecialtype#1#2%
+%D {\bgroup
+%D \initializetype
+%D \catcode`\{=\@@begingroup
+%D \catcode`\}=\@@endgroup
+%D \def\dospecialtype%
+%D {\def\dospecialtype{#2\egroup}%
+%D \bgroup
+%D \aftergroup\dospecialtype
+%D #1}%
+%D \afterassignment\dospecialtype
+%D \let\next=}
+%D
+%D \unexpanded\def\tex{\dospecialtype\texescape\relax}
+%D \unexpanded\def\arg{\dospecialtype\leftargument\rightargument}
+%D \unexpanded\def\mat{\dospecialtype\$\$}
+%D \unexpanded\def\dis{\dospecialtype{\$\$}{\$\$}}
+%D \stoptyping
+
+\def\setgroupedtype
+ {\let\currenttypingclass\??ty
+ \initializetype
+ \verbatimcolor
+ %\setcatcodetable \typcatcodesa
+ \catcode`\{=\@@begingroup
+ \catcode`\}=\@@endgroup}
+
+\unexpanded\def\tex{\groupedcommand{\setgroupedtype\texescape}{\relax}}
+\unexpanded\def\arg{\groupedcommand{\setgroupedtype\leftargument}{\rightargument}}
+\unexpanded\def\mat{\groupedcommand{\setgroupedtype\$}{\$}}
+\unexpanded\def\dis{\groupedcommand{\setgroupedtype\$\$}{\$\$}}
+
+%D \macros
+%D {starttyping}
+%D
+%D Display verbatim is realized far more easy, which is mostly
+%D due to the fact that we use \type{\stop...} as delimiter.
+%D The implementation inherits some features, for instance the
+%D support of linenumbering, which can best be studied in the
+%D documented support module.
+
+\let\currenttyping \empty
+\let\currenttypingclass\??ty % saveguard
+
+% \def\typingparameter#1%
+% {\executeifdefined
+% {\currenttypingclass\currenttyping#1}%
+% {\executeifdefined{\currenttypingclass#1}\empty}}
+
+\def\typingparameter#1%
+ {\ifcsname\currenttypingclass\currenttyping#1\endcsname
+ \csname\currenttypingclass\currenttyping#1\endcsname
+ \else\ifcsname\currenttypingclass#1\endcsname
+ \csname\currenttypingclass#1\endcsname
+ \fi\fi}
+
+\def\settypingparameter#1#2%
+ {\setvalue{\currenttypingclass\currenttyping#1}{#2}}
+
+\def\setxtypingparameter#1#2%
+ {\setxvalue{\currenttypingclass\currenttyping#1}{#2}}
+
+% \def\initializetyping
+% {%\donefalse
+% \switchtobodyfont[\typingparameter\c!bodyfont]%
+% \donefalse
+% \scratchskip\typingparameter\c!oddmargin\relax
+% \ifzeropt\scratchskip\else\donetrue\fi
+% \scratchskip\typingparameter\c!evenmargin\relax
+% \ifzeropt\scratchskip\else\donetrue\fi
+% \ifdone
+% \def\doopenupverbatimline
+% {\getpagestatus
+% \ifrightpage
+% \hskip\typingparameter\c!oddmargin\relax
+% \else
+% \hskip\typingparameter\c!evenmargin\relax
+% \fi}%
+% \else
+% \doadaptleftskip{\typingparameter\c!margin}%
+% \fi
+% \doifdefinedelse{\??bo\typingparameter\c!blank}
+% {\edef\!!stringa{\csname\??bo\typingparameter\c!blank\endcsname}}
+% {\edef\!!stringa{\typingparameter\c!blank}}%
+% \processaction
+% [\!!stringa]
+% [ \v!standard=>\scratchskip\ctxparskip,
+% \v!small=>\scratchskip\blankokleinmaat,
+% \v!medium=>\scratchskip\blankomiddelmaat,
+% \v!big=>\scratchskip\blankogrootmaat,
+% \v!halfline=>\scratchskip.5\baselineskip,
+% \v!line=>\scratchskip\baselineskip,
+% \v!none=>\scratchskip\zeropoint,
+% \s!unknown=>\scratchskip\commalistelement]%
+% \ifgridsnapping
+% \ifdim\scratchskip=.5\baselineskip\relax
+% \edef\verbatimbaselineskip{\the\scratchskip}% new
+% \else
+% \edef\verbatimbaselineskip{\the\baselineskip}%
+% \fi
+% \else
+% \edef\verbatimbaselineskip{\the\scratchskip}%
+% \fi
+% \setupcommonverbatim}
+
+\setvalue{\??tp:\c!blank:\v!standard}{\ctxparskip}
+\setvalue{\??tp:\c!blank:\v!small }{\blankokleinmaat}
+\setvalue{\??tp:\c!blank:\v!medium }{\blankomiddelmaat}
+\setvalue{\??tp:\c!blank:\v!big }{\blankogrootmaat}
+\setvalue{\??tp:\c!blank:\v!halfline}{.5\baselineskip}
+\setvalue{\??tp:\c!blank:\v!line }{\baselineskip}
+\setvalue{\??tp:\c!blank:\v!none }{\zeropoint}
+
+\def\initializetyping
+ {%\donefalse
+ \switchtobodyfont[\typingparameter\c!bodyfont]%
+ \donefalse
+ \scratchskip\typingparameter\c!oddmargin\relax
+ \ifzeropt\scratchskip\else\donetrue\fi
+ \scratchskip\typingparameter\c!evenmargin\relax
+ \ifzeropt\scratchskip\else\donetrue\fi
+ \ifdone
+ \def\doopenupverbatimline
+ {\getpagestatus
+ \ifrightpage
+ \hskip\typingparameter\c!oddmargin\relax
+ \else
+ \hskip\typingparameter\c!evenmargin\relax
+ \fi}%
+ \else
+ \doadaptleftskip{\typingparameter\c!margin}%
+ \fi
+ \edef\!!stringa{\executeifdefined{\??bo\typingparameter\c!blank}{\typingparameter\c!blank}}%
+ \scratchskip\executeifdefined{\??tp:\c!blank:\!!stringa}\!!stringa\relax
+ \ifgridsnapping
+ \ifdim\scratchskip=.5\baselineskip\relax
+ \edef\verbatimbaselineskip{\the\scratchskip}% new
+ \else
+ \edef\verbatimbaselineskip{\the\baselineskip}%
+ \fi
+ \else
+ \edef\verbatimbaselineskip{\the\scratchskip}%
+ \fi
+ \setupcommonverbatim}
+
+%D The basic display verbatim commands are defined in an
+%D indirect way. As we will see, they are a specific case of a
+%D more general mechanism.
+
+% we need this hack because otherwise verbatim skips
+% the first line (everything after the initial command)
+
+\def\dostarttyping#1% tricky non standard lookahead
+ {\bgroup
+ \let\currenttypingclass\??tp
+ \edef\currenttyping{#1}%
+ \obeylines
+ \futurelet\nexttoken\dodostarttyping}
+
+\def\dodostarttyping
+ {\ifx\nexttoken[%
+ \expandafter\dododostarttyping
+ \else
+ \expandafter\nododostarttyping
+ \fi}
+
+\def\nododostarttyping
+ {\dododostarttyping[]}
-\def\mktypeblockverbatim#1#2%
+\def\dotypefileverbatim
+ {\doinitializeverbatim
+ \ctxlua{buffers.typefile("\readfilename")}}
+
+\def\dotypefilelinesverbatim#1#2%
+ {#1%
+ \doinitializeverbatim
+ \ctxlua{buffers.typefile("\readfilename")}%
+ #2}
+
+\def\dotypeblockverbatim#1#2%
{\dowithbuffer{_typing_}{#1}{#2}
{}
- {\mkinitializeverbatim
+ {\doinitializeverbatim
\beginofverbatimlines
\ctxlua{buffers.type("_typing_")}%
\endofverbatimlines
\getvalue{\strippedcsname#2}}}
-% \typefile:
+\def\dododostarttyping[#1]%
+ {\typingparameter\c!before
+ \startpacked % includes \bgroup
+ \dosetuptypelinenumbering{#1}%
+ \initializetyping
+ \startverbatimcolor
+ \expanded{\dotypeblockverbatim{\s!start\currenttyping}{\s!stop\currenttyping}}}
-\def\mktypefileverbatim
- {\mkinitializeverbatim
- \ctxlua{buffers.typefile("\readfilename")}}
+\def\dostoptyping#1% hm, currenttyping
+ {\stopverbatimcolor
+ \stoppacked % includes \egroup
+ \typingparameter\c!after
+ \egroup
+ \dochecknextindentation{\??tp#1}%
+ \dorechecknextindentation}
-\def\mktypefilelinesverbatim#1#2%
- {#1%
- \mkinitializeverbatim
- \ctxlua{buffers.typefile("\readfilename")}%
- #2}
+%D Line numbering for files is combined with filtering, while
+%D display verbatim has the ability to continue.
+%D
+%D \starttyping
+%D \typefile[numbering=file,start=10,stop=12]{test.tex}
+%D
+%D \definetyping[code][numbering=line]
+%D
+%D \starttext
+%D \startcode
+%D ...
+%D ...
+%D \stopcode
+%D
+%D \startcode[continue]
+%D ...
+%D ...
+%D \stopcode
+%D
+%D \startcode[start=10]
+%D ...
+%D \stopcode
+%D \stoptyping
+
+%D \macros
+%D {setuptyping}
+%D
+%D The setup of typing accepts two arguments. The optional
+%D first one identifies the user defined ones. If only one
+%D argument is given, the values apply to both the standard
+%D command \type{\starttyping} and \type{\typefile}.
+
+\def\dosetuptyping[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??tp#1][#2]%
+ \else
+ \getparameters[\??tp][#1]%
+ \fi}
+
+\def\setuptyping
+ {\dodoubleempty\dosetuptyping}
+
+%D \macros
+%D {definetype}
+%D
+%D Specific inline verbatim commands can be defined with the
+%D following command.
+
+\def\definetype
+ {\dodoubleempty\dodefinetype}
+
+\def\dodefinetype[#1][#2]%
+ {\unexpanded\setvalue{#1}{\dotype{#1}}%
+ \getparameters[\??ty#1][#2]}
+
+%D \macros
+%D {definetyping}
+%D
+%D For most users the standard \type{\start}||\type{\stop}||pair
+%D will suffice, but for documentation purposes the next
+%D definition command can be of use:
+%D
+%D \starttyping
+%D \definetyping[extratyping][margin=3em]
+%D
+%D \startextratyping
+%D these extra ones are indented by 1 em
+%D \stopextratyping
+%D \stoptyping
+%D
+%D The definitions default to the standard typing values.
+
+\def\presettyping[#1][#2]%
+ {\copyparameters[\??tp#1][\??tp][\c!color,\c!style]%
+ \getparameters [\??tp#1][#2]}
+
+\def\dodefinetyping[#1][#2]%
+ {\setvalue{\e!start#1}{\dostarttyping{#1}}%
+ \setvalue{\e!stop #1}{\dostoptyping {#1}}%
+ \presettyping[#1][#2]}
+
+\def\definetyping
+ {\dodoubleempty\dodefinetyping}
+
+%D We can use some core color commands. These are faster than
+%D the standard color switching ones and work ok on a line by
+%D line basis.
+%D
+%D \starttyping
+%D \def\setupverbatimcolor%
+%D {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}%
+%D \def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
+%D \def\endofpretty {\stopcolormode}}
+%D \stoptyping
+%D
+%D Since we support a global color too, the folowing
+%D definition is better:
+
+% \def\setupverbatimcolor% fast and local versus slow and global
+% {\doifelsenothing{\typingparameter\c!color}
+% {\def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
+% \let\endofpretty \restorecolormode % \stopcolormode
+% \let\startverbatimcolor \relax
+% \let\stopverbatimcolor \relax
+% \let\verbatimcolor \relax}
+% {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
+% \let\endofpretty \stopcolor
+% \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
+% \let\stopverbatimcolor \stopcolor
+% \def\verbatimcolor {\getvalue{\typingparameter\c!color}}}% command !
+% \doifelsenothing{\typingparameter\c!palet}
+% {\let\prettypalet\empty
+% \let\endofpretty\relax
+% \def\beginofpretty[##1]{}}
+% {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
+%
+% let's forget about this optimization not that we have mkiv
+
+\def\setupverbatimcolor
+ {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
+ \let\endofpretty \stopcolor
+ \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
+ \let\stopverbatimcolor \stopcolor
+ \def\verbatimcolor {\getvalue{\typingparameter\c!color}}% command !
+ \doifelsenothing{\typingparameter\c!palet}
+ {\let\prettypalet\empty
+ \let\endofpretty\relax
+ \def\beginofpretty[##1]{}}
+ {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
+
+\let\prettypalet \empty
+\let\startverbatimcolor\relax
+\let\stopverbatimcolor \relax
+\let\verbatimcolor \relax
+
+%D In the verbatim module, there are some examples given of
+%D the more obscure features of the verbatim environments.
+%D
+%D \startbuffer
+%D \startTEX
+%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
+%D \stopTEX
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D This gives, as can be expected:
+%D
+%D \getbuffer
+%D
+%D When we want to see some typeset \TEX\ too, we can say:
+%D
+%D \startbuffer
+%D \startTEX
+%D \def\mathematics#1% %%\ N usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} %%\ N becomes: \mathematics{x^2}
+%D \stopTEX
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or:
+%D
+%D \getbuffer
+%D
+%D In a similar way:
+%D
+%D \startbuffer
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D gives:
+%D
+%D \getbuffer
+%D
+%D The next examples sow how we can directly call for natural
+%D \TEX\ comments:
+%D
+%D \startbuffer
+%D \setuptyping
+%D [TEX]
+%D [text=yes]
+%D
+%D \startTEX
+%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
+%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
+%D \stopTEX
+%D
+%D \setuptyping
+%D [SQL]
+%D [text=yes,palet=,icommand=\bf,vcommand=,ccommand=\it]
+%D
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D
+%D \setuptyping
+%D [SQL]
+%D [ccommand=\tf\underbar]
+%D
+%D \startSQL
+%D select * -- indeed, here we {\em do} select
+%D from tableA
+%D where 1 = 2
+%D \stopSQL
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D Now watch:
+%D
+%D \getbuffer
+%D
+%D The natural \TEX\ typesetting was introduced when Tobias
+%D and Berend started using verbatim \JAVASCRIPT\ and \SQL.
+
+%D \macros
+%D {EveryPar, EveryLine, iflinepar}
+%D
+%D One of the features of these commands is the support of
+%D \type{\EveryPar}, \type{\EveryLine} and \type{\iflinepar}.
+%D In the documentation of the verbatim support module we give
+%D some examples of line- and paragraph numbering using these
+%D macros.
+
+%D \macros
+%D {typefile}
+%D
+%D Typesetting files verbatim (for the moment) only supports
+%D colorization of \TEX\ sources as valid option. The other
+%D setup values are inherited from display verbatim.
+%D The implementation of \type{\typefile} is straightforward:
+
+% new feature (not yet 100\% ok)
+%
+% \setuptyping[file][numbering=file]
+%
+% \typefile[start=2,nlines=3]{zapf}
+% \typefile[start=continue,nlines=13]{zapf}
+% \typefile{zapf}
+%
+% \setuptyping[file][numbering=line]
+%
+% \typefile[start=4,step=3]{zapf}
+% \typefile{zapf}
+
+\def\typefile
+ {\dodoubleempty\dotypefile}
+
+\def\dotypefile[#1][#2]#3%
+ {\ifsecondargument
+ \dodotypefile[#1][#2]{#3}%
+ \else\iffirstargument
+ \doifassignmentelse{#1}
+ {\dodotypefile[\v!file][#1]{#3}}
+ {\dodotypefile[#1][]{#3}}%
+ \else
+ \dodotypefile[\v!file][]{#3}%
+ \fi\fi}
+
+\def\dosetuptypelinenumbering#1% fuzzy
+ {\doifundefined{\currenttypingclass\currenttyping\c!start}
+ {\setuptyping[\currenttyping][\c!start=1,\c!stop=,\c!step=1,\c!nlines=]}%
+ \setuptyping[\currenttyping][#1]%
+ \doifelse{\typingparameter\c!numbering}\v!file
+ {% kind of special: filters lines !
+ \setuplinenumbering[\c!method=\v!file]%
+ \donetrue}
+ {\doifelse{\typingparameter\c!numbering}\v!line
+ {% \setuplinenumbering defaults start/step to 1/1, so we need
+ \doifinsetelse\v!continue{#1,\typingparameter\c!start}
+ {\scratchcounter0\typingparameter\c!n
+ \setxtypingparameter\c!start{\ifnum\scratchcounter=0 1\else\number\scratchcounter\fi}}%
+ {\doifnothing{\typingparameter\c!start}{\settypingparameter\c!start{1}}}%
+ \doifnothing{\typingparameter\c!step}{\settypingparameter\c!step{1}}%
+ \setuplinenumbering
+ [\c!method=\v!type,
+ \c!start=\typingparameter\c!start,
+ \c!stop=\typingparameter\c!stop,
+ \c!step=\typingparameter\c!step]%
+ \donetrue}
+ {\donefalse}}%
+ \ifdone
+ \ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
+ \ifx\stoplinenumbering \undefined \let\stoplinenumbering \relax \fi
+ \def\beginofverbatimlines{\startlinenumbering}%
+ \def\endofverbatimlines {\stoplinenumbering\setxtypingparameter\c!n{\number\linenumber}}%
+ \fi}
+
+\def\reporttypingerror#1% temp hack
+ {\blank
+ \dontleavehmode\hbox\bgroup
+ \expanded{\defconvertedargument\noexpand\ascii{#1}}%
+ \tttf[\makemessage\m!verbatims1\ascii]%
+ \showmessage\m!verbatims1\ascii
+ \egroup
+ \blank}
+
+\def\dosometyping#1#2#3#4#5%
+ {\bgroup
+ \let\currenttypingclass\??tp
+ \edef\currenttyping{#1}%
+ \typingparameter\c!before
+ \startpacked % includes \bgroup
+ \dosetuptypelinenumbering{#2}%
+ \doifinset{\typingparameter\c!option}{\v!commands,\v!slanted,\v!normal}
+ {\setuptyping[#1][\c!option=\v!none]}%
+ \doif{\typingparameter\c!option}\v!color
+ {\expandafter\aftersplitstring#3\at.\to\prettyidentifier
+ \settypingparameter\c!option{\prettyidentifier}}%
+ \initializetyping
+ \startverbatimcolor
+ \doifundefinedelse{\currenttypingclass#3\v!global\c!start}
+ {\scratchcounter\zerocount}
+ {\scratchcounter\getvalue{\currenttypingclass#3\v!global\c!start}}%
+ \advance\scratchcounter\plusone
+ \setxvalue{\currenttypingclass#3\v!global\c!start}{\the\scratchcounter}%
+ \doifelsenothing{\typingparameter\c!start}
+ {#4}
+ {\doif{\typingparameter\c!start}\v!continue
+ {\setevalue{\currenttypingclass#1\c!start}%
+ {\getvalue{\currenttypingclass#3\v!global\c!start}}}%
+ \doifelsenothing{\typingparameter\c!stop}
+ {\doifelsenothing{\typingparameter\c!nlines}
+ {#4}
+ {\setxvalue{\currenttypingclass#3\v!global\c!start}%
+ {\the\numexpr\typingparameter\c!start+\typingparameter\c!nlines+\minusone\relax}%
+ #5{\typingparameter\c!start}{\getvalue{\currenttypingclass#3\v!global\c!start}}}}%
+ {#5{\typingparameter\c!start}{\typingparameter\c!stop}}}%
+ \stopverbatimcolor
+ \stoppacked
+ \typingparameter\c!after
+ \egroup}
+
+\def\doifelsetypingfile#1% sets \readfilename (we will make this proper mkiv i.e. less messy)
+ {\doiflocfileelse{#1}
+ {\firstoftwoarguments}
+ {\doifinputfileelse{#1}
+ {\def\readfilename{\pathplusfile\filepath{#1}}\firstoftwoarguments} % messy, looks wrong too
+ {\secondoftwoarguments}}}
+
+\def\dodotypefile[#1][#2]#3%
+ {\doifelsetypingfile{#3}
+ {\dosometyping{#1}{#2}{#3}\dotypefileverbatim\dotypefilelinesverbatim}
+ {\reporttypingerror{#3}}}
+
+%D \macros
+%D {filename}
+%D
+%D Typesetting filenames in monospaced fonts is possible with
+%D
+%D \starttyping
+%D \filename{here/there/filename.suffix}
+%D \stoptyping
+%D
+%D The definition is not that spectacular.
+
+\unexpanded\def\filename#1{{\tttf\hyphenatedfilename{#1}}}
+
+%D This leaves some settings:
+
+\permitshiftedendofverbatim
+\optimizeverbatimtrue
+
+%D And a bonus macro:
+
+\def\verbatim#1{\defconvertedargument\ascii{#1}\ascii}
+
+%D The setups for display verbatim and file verbatim are
+%D shared. One can adapt the extra defined typing environments,
+%D but they also default to the values below. Watch the
+%D alternative escape character.
+
+\setuptyping
+ [ \c!before=\blank,
+ \c!after=\blank,
+ \c!bodyfont=,
+ \c!color=,
+ \c!space=\v!off,
+ \c!page=\v!no,
+ \c!tab=\s!ascii,
+ \c!option=\v!none,
+ \c!palet=colorpretty,
+ \c!text=\v!no,
+ \c!style=\tttf,
+ \c!icommand=\ttsl,
+ \c!vcommand=,
+ \c!ccommand=\tttf,
+ \c!indentnext=\v!yes,
+ \c!margin=\!!zeropoint,
+ \c!evenmargin=\!!zeropoint,
+ \c!oddmargin=\!!zeropoint,
+ \c!blank=\v!line,
+ \c!escape=/, % beware \string\ , should also be accepted
+ \c!numbering=\v!no,
+ \c!lines=,
+ \c!empty=,
+ \c!start=1,
+ \c!stop=,
+ \c!step=1,
+ \c!continue=,
+ \c!nlines=]
+
+\definetyping[\v!typing]
+
+\presettyping[\v!file][]
+
+% \setuptyping % not needed
+% [\v!file]
+% [\c!start=1,
+% \c!stop=,
+% \c!step=1,
+% \c!continue=,
+% \c!nlines=]
+
+%D The setups for inline verbatim default to:
+
+\setuptype
+ [ \c!space=\v!off,
+ \c!color=,
+ \c!style=\tt\tf, % \tttf gives problems with {\tx \type...}
+ \c!page=\v!no,
+ \c!tab=\v!yes,
+ \c!palet=colorpretty,
+ \c!option=\v!normal]
+
+\definetyping[RAW] [\c!option=RAW]
+\definetyping[MP] [\c!option=MP]
+\definetyping[PL] [\c!option=PL]
+\definetyping[PM] [\c!option=PL]
+\definetyping[JS] [\c!option=JS]
+\definetyping[JV] [\c!option=JV]
+\definetyping[SQL] [\c!option=SQL]
+\definetyping[TEX] [\c!option=TEX]
+\definetyping[PAS] [\c!option=PAS]
+\definetyping[PASCAL][\c!option=PAS]
+\definetyping[MOD] [\c!option=PAS]
+\definetyping[MODULA][\c!option=PAS]
+\definetyping[DELPHI][\c!option=PAS]
+\definetyping[EIFFEL][\c!option=EIF]
+\definetyping[XML] [\c!option=XML]
+\definetyping[LUA] [\c!option=LUA]
+
+\installprettytype [RAW] [RAW]
+
+\installprettytype [TEX] [TEX]
+
+\installprettytype [PERL] [PL]
+\installprettytype [PL] [PL]
+\installprettytype [PM] [PL]
+
+\installprettytype [METAPOST] [MP]
+\installprettytype [METAFONT] [MP]
+\installprettytype [MP] [MP]
+\installprettytype [MF] [MP]
+
+\installprettytype [JAVASCRIPT] [JS]
+\installprettytype [JAVA] [JV]
+\installprettytype [JS] [JS]
+\installprettytype [JV] [JV]
+
+\installprettytype [SQL] [SQL]
+
+\installprettytype [PASCAL] [PAS]
+\installprettytype [PAS] [PAS]
+\installprettytype [MODULA] [PAS]
+\installprettytype [MOD] [PAS]
+
+\installprettytype [EIFFEL] [EIF]
+\installprettytype [EIF] [EIF]
+\installprettytype [E] [EIF]
+
+\installprettytype [XML] [XML]
+
+\installprettytype [LUA] [LUA]
+
+\installnewpretty M {\setupprettiesintype {MP}\setupprettytype}
+\installnewpretty P {\setupprettiesintype {PL}\setupprettytype}
+\installnewpretty T {\setupprettiesintype{TEX}\setupprettytype}
+\installnewpretty J {\setupprettiesintype {JV}\setupprettytype}
+\installnewpretty S {\setupprettiesintype{SQL}\setupprettytype}
+\installnewpretty W {\setupprettiesintype{PAS}\setupprettytype} % Wirth
+\installnewpretty I {\setupprettiesintype{EIF}\setupprettytype} % E taken
+\installnewpretty X {\setupprettiesintype{XML}\setupprettytype}
+
+%D We use the \CONTEXT\ color system for switching to and from
+%D color mode. We can always redefine these colors afterwards.
+
+\definecolor [colorprettyone] [r=.9, g=.0, b=.0] % red
+\definecolor [colorprettytwo] [r=.0, g=.8, b=.0] % green
+\definecolor [colorprettythree] [r=.0, g=.0, b=.9] % blue
+\definecolor [colorprettyfour] [r=.8, g=.8, b=.6] % yellow
+
+\definecolor [grayprettyone] [s=.30]
+\definecolor [grayprettytwo] [s=.45]
+\definecolor [grayprettythree] [s=.60]
+\definecolor [grayprettyfour] [s=.75]
+
+\definepalet
+ [colorpretty]
+ [ prettyone=colorprettyone,
+ prettytwo=colorprettytwo,
+ prettythree=colorprettythree,
+ prettyfour=colorprettyfour]
+
+\definepalet
+ [graypretty]
+ [ prettyone=grayprettyone,
+ prettytwo=grayprettytwo,
+ prettythree=grayprettythree,
+ prettyfour=grayprettyfour]
+
+\definepalet [TEXcolorpretty] [colorpretty]
+\definepalet [TEXgraypretty] [graypretty]
+\definepalet [PLcolorpretty] [colorpretty]
+\definepalet [PLgraypretty] [graypretty]
+\definepalet [PMcolorpretty] [colorpretty]
+\definepalet [PMgraypretty] [graypretty]
+\definepalet [MPcolorpretty] [colorpretty]
+\definepalet [MPgraypretty] [graypretty]
+\definepalet [JVcolorpretty] [colorpretty]
+\definepalet [JVgraypretty] [graypretty]
+\definepalet [JScolorpretty] [colorpretty]
+\definepalet [JSgraypretty] [graypretty]
+\definepalet [SQLcolorpretty] [colorpretty]
+\definepalet [SQLgraypretty] [graypretty]
+\definepalet [PAScolorpretty] [colorpretty]
+\definepalet [PASgraypretty] [graypretty]
+\definepalet [EIFcolorpretty] [colorpretty]
+\definepalet [EIFgraypretty] [graypretty]
+\definepalet [XMLcolorpretty] [colorpretty]
+\definepalet [XMLgraypretty] [graypretty]
+\definepalet [LUAcolorpretty] [colorpretty]
+\definepalet [LUAgraypretty] [graypretty]
% patched from verb-ini (todo)
diff --git a/tex/context/base/core-ver.tex b/tex/context/base/core-ver.tex
deleted file mode 100644
index 57dba0af1..000000000
--- a/tex/context/base/core-ver.tex
+++ /dev/null
@@ -1,1120 +0,0 @@
-%D \module
-%D [ file=core-ver,
-%D version=2000.05.09,
-%D title=\CONTEXT\ Core Macros,
-%D subtitle=Verbatim,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Core Macros / Verbatim}
-
-\startmessages dutch library: verbatims
- title: typen
- 1: file -- bestaat niet
-\stopmessages
-
-\startmessages english library: verbatims
- title: verbatim
- 1: file -- does not exist
-\stopmessages
-
-\startmessages german library: verbatims
- title: verbatim
- 1: Datei -- existiert nicht
-\stopmessages
-
-\startmessages czech library: verbatims
- title: verbatim
- 1: soubor -- neexistuje
-\stopmessages
-
-\startmessages italian library: verbatims
- title: verbatim
- 1: il file -- non esiste
-\stopmessages
-
-\startmessages norwegian library: verbatims
- title: verbatim
- 1: fil -- eksisterer ikke
-\stopmessages
-
-\startmessages romanian library: verbatims
- title: verbatim
- 1: fisierul -- nu exista
-\stopmessages
-
-\startmessages french library: verbatims
- title: verbatim
- 1: le fichier -- n'existe pas
-\stopmessages
-
-\unprotect
-
-\ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
-\ifx\stoplinenumbering \undefined \let\stoplinenumbering\relax \fi
-\ifx\setuplinenumbering\undefined \def\setuplinenumbering[#1]{} \fi
-
-% \type{ char} geeft bagger
-
-%D We are going to embed the general verbatim support macros in
-%D a proper environment. First we show the common setup
-%D macro, so we know what features are supported. The options
-%D are hooked into the support macros via the \type{\obey}
-%D macros.
-
-\newif\ifslantedtypeactivated
-\newif\ifslantedtypepermitted
-
-\def\switchslantedtype
- {\ifslantedtypepermitted
- \ifslantedtypeactivated
- \slantedtypeactivatedfalse\tttf
- \else
- \slantedtypeactivatedtrue\ttsl
- \fi
- \fi}
-
-\newprettytrue % movet to here from cont-sys.tex
-
-\def\prettyidentifier {TEX}
-\def\prettypalet {}
-
-\def\installprettytype
- {\dodoubleargument\doinstallprettytype}
-
-\def\doinstallprettytype[#1][#2]% map #1 onto #2
- {\uppercasestring#1\to\asciia
- \uppercasestring#2\to\asciib
- \setevalue{\??ty\??ty\asciia}{\asciib}}
-
-\def\setupprettiesintype#1%
- {\uppercasestring#1\to\ascii
- \edef\prettyidentifier{\executeifdefined{\??ty\??ty\ascii}{TEX}}%
- \mksetupprettiesintype}
-
-\def\setupprettytype{\mksetupprettytype}
-
-% \def\setupcommonverbatim
-% {\recatcodeuppercharactersfalse % obey regime / encoding
-% %
-% \let\prettyidentifier\s!default
-% %
-% \doifelse{\typingparameter\c!text}\v!yes
-% \naturaltextexttrue
-% \naturaltextextfalse
-% \def\prettyidentifierfont{\typingparameter\c!icommand}%
-% \def\prettyvariablefont {\typingparameter\c!vcommand}%
-% \def\prettynaturalfont {\typingparameter\c!ccommand}%
-% %
-% \doif{\typingparameter\c!space}\v!on
-% {\def\obeyspaces{\setcontrolspaces}}%
-% \doif{\typingparameter\c!page }\v!no
-% {\def\obeypages {\ignorepages}}%
-% %
-% \doifelse{\typingparameter\c!tab}\v!yes
-% {\def\obeytabs{\settabskips}}%
-% {\doif{\typingparameter\c!tab}\s!ascii
-% {\chardef\tabskipmode\plustwo % quit on >127
-% \def\obeytabs{\settabskips}}}%
-% %
-% \ignorehyphens % default
-% \ExpandFirstAfter\processaction
-% [\typingparameter\c!lines]
-% [ \v!yes=>\obeybreakpoints,
-% \v!hyphenated=>\obeyhyphens]%
-% \processaction
-% [\typingparameter\c!empty]
-% [\v!yes=>\obeyemptylines,
-% \v!all=>\obeyallemptylines]%
-% %
-% \ExpandFirstAfter\processaction
-% [\typingparameter\c!option]
-% [ \v!none=>\let\obeycharacters\relax,
-% \v!color=>\setupprettiesintype{TEX}%
-% \let\obeycharacters\setupprettytype
-% \let\obeytabs\ignoretabs,
-% \v!normal=>\let\obeycharacters\setupgroupedtype,
-% \v!commands=>\def\obeycharacters{\setupcommandsintype}% \let
-% \let\obeytabs\ignoretabs,
-% \v!slanted=>\let\obeycharacters\setupslantedtype
-% \let\obeytabs\ignoretabs,
-% \s!unknown=>\setupprettiesintype{\typingparameter\c!option}%
-% \let\obeycharacters\setupprettytype
-% \let\obeytabs\ignoretabs]%
-% \doifnumberelse{\typingparameter\c!tab}
-% {\def\obeytabs{\setfixedtabskips{\typingparameter\c!tab}}}%
-% \donothing
-% %\def\verbatimfont{\typingparameter\c!style\normalnoligatures\font}%
-% % more generic, but beware of the \redoconvertfont (else no typing in titles and such)
-% \def\verbatimfont{\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style\normalnoligatures\font}%
-% \setupverbatimcolor}
-
-\setvalue{\??tp:\c!lines:\v!yes }{\obeybreakpoints}
-\setvalue{\??tp:\c!lines:\v!hyphenated}{\obeyhyphens}
-
-\setvalue{\??tp:\c!empty:\v!yes }{\obeyemptylines}
-\setvalue{\??tp:\c!empty:\v!all }{\obeyallemptylines}
-
-\setvalue{\??tp:\c!option:\v!none }{\let\obeycharacters\relax}
-\setvalue{\??tp:\c!option:\v!color }{\setupprettiesintype{TEX}%
- \let\obeycharacters\setupprettytype
- \let\obeytabs\ignoretabs}
-\setvalue{\??tp:\c!option:\v!normal }{\let\obeycharacters\setupgroupedtype}
-\setvalue{\??tp:\c!option:\v!commands }{\def\obeycharacters{\setupcommandsintype}%
- \let\obeytabs\ignoretabs}
-\setvalue{\??tp:\c!option:\v!slanted }{\let\obeycharacters\setupslantedtype
- \let\obeytabs\ignoretabs}
-\setvalue{\??tp:\c!option:\s!unknown }{\setupprettiesintype{\typingparameter\c!option}%
- \let\obeycharacters\setupprettytype
- \let\obeytabs\ignoretabs}
-
-
-\def\setupcommonverbatim
- {\recatcodeuppercharactersfalse % obey regime / encoding
- %
- \let\prettyidentifier\s!default
- %
- \doifelse{\typingparameter\c!text}\v!yes
- \naturaltextexttrue
- \naturaltextextfalse
- \def\prettyidentifierfont{\typingparameter\c!icommand}%
- \def\prettyvariablefont {\typingparameter\c!vcommand}%
- \def\prettynaturalfont {\typingparameter\c!ccommand}%
- %
- \doif{\typingparameter\c!space}\v!on
- {\def\obeyspaces{\setcontrolspaces}}%
- \doif{\typingparameter\c!page }\v!no
- {\def\obeypages {\ignorepages}}%
- %
- \doifelse{\typingparameter\c!tab}\v!yes
- {\def\obeytabs{\settabskips}}%
- {\doif{\typingparameter\c!tab}\s!ascii % not needed in mkiv
- {\chardef\tabskipmode\plustwo % quit on >127
- \def\obeytabs{\settabskips}}}%
- %
- \ignorehyphens % default
- \getvalue{\??tp:\c!lines:\typingparameter\c!lines}%
- \getvalue{\??tp:\c!empty:\typingparameter\c!empty}%
- \getvalue{\??tp:\c!option:\ifcsname\??tp:\c!option:\typingparameter\c!option\endcsname\typingparameter\c!option\else\s!unknown\fi}%
- \doifnumberelse{\typingparameter\c!tab}
- {\def\obeytabs{\setfixedtabskips{\typingparameter\c!tab}}}%
- \donothing
- %\def\verbatimfont{\typingparameter\c!style\normalnoligatures\font}%
- % more generic, but beware of the \redoconvertfont (else no typing in titles and such)
- \def\verbatimfont{\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style\normalnoligatures\font}%
- \setupverbatimcolor}
-
-% BEWARE: the noligatures will globally change the verbatim font's behaviour
-
-% test case:
-%
-% \definetype[typeTEX][option=tex]
-%
-% \typeTEX|\example---oeps|. this---ligates---again.
-% \typeTEX{\example---oeps}. this---ligates---again.
-% \type {\example---oeps}. this---ligates---again.
-
-\def\setupcommandsintype{\mksetupcommandsintype}
-\def\setupslantedtype {\slantedtypepermittedtrue\mksetupslantedtype}
-
-\ifx\setupprettytype \undefined \let\setupprettytype \relax \fi
-\ifx\setupslantedtype \undefined \let\setupslantedtype \relax \fi
-\ifx\setupgroupedtype \undefined \let\setupgroupedtype \relax \fi
-\ifx\normalnoligatures\undefined \let\normalnoligatures\gobbleoneargument \fi
-
-%D The verbatim commands have a rather long and turbulent
-%D history. Most users of \CONTEXT\ probably will never use
-%D some of the features, but I've kept in mind that when one is
-%D writing a users manual, about everything can and undoubtly
-%D will be subject to a verbatim treatment.
-%D
-%D Verbatim command are very sensitive to argument processing,
-%D which is a direct result of the \CATCODES\ being fixed at
-%D reading time. With our growing understanding of \TEX,
-%D especially of the mechanism that can be used for looking
-%D ahead and manipulating \CATCODES, the verbatim support
-%D became more and more advanced and natural.
-%D
-%D Typesetting inline verbatim can be accomplished by
-%D \type{\type}, which in this sentence was typeset by saying
-%D just \type{\type{\type}}, which in turn was typeset by
-%D \unknown. Using the normal grouping characters \type{{}} is
-%D the most natural way of using this command.
-%D
-%D A second, more or less redundant, alternative is delimiting
-%D the argument with an own character. This method was
-%D implemented in the context of a publication in the \MAPS,
-%D where this way of delimiting is recognized by \LATEX\ users.
-%D
-%D The third, more original alternative, is the one using
-%D \type{<<} and \type{>>} as delimiters. This alternative can
-%D be used in situations where slanted typeseting is needed.
-
-% todo: we can use \letter... here:
-
-\def\lesscharacter {<}
-\def\morecharacter {>}
-
-\chardef\texescape = `\\
-\chardef\leftargument = `\{
-\chardef\rightargument = `\}
-
-%D \macros
-%D {type}
-%D
-%D We define \type{\type} as a protected command. This command
-%D has several invocations: grouped, wirt boundary characters,
-%D and with font switches.
-
-% \starttyping
-% normal: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
-% normal: \par \type{xx<..xx.. >..>xx} \par \type{<....>} \par \type{<....>}
-% \setuptype[option=slanted]
-% slanted: \par \type{xx<<..sl..<> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<>..>> \par
-% slanted: \par \type{xx<<..sl.. xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<....>> \par
-% \setuptype[option=none]
-% none: \par \type{xx<<..xx..<> >>..>>xx} \par \type<<....>> \par \type<<..<>..>> \par
-% \stoptyping
-
-%D When writing the manual to \CONTEXT\ and documenting this
-%D source we needed to typeset \type{<<} and \type{>>}. Because
-%D we wanted to do this in the natural way, we've adapted the
-%D original definition a bit. This implementation went through
-%D several live cycles. The final implementation looks a bit
-%D further and treats the lone \type{<<} and \type{>>} a bit
-%D different. The \type {\null} prevents ligatures, which
-%D unfortunately turn up in Lucida fonts.
-
-%D The following lines show what happens when we set
-%D \type {option=commands}.
-%D
-%D \startbuffer
-%D \starttyping
-%D test//test test/BTEX \footnote{test test test}/ETEX test
-%D test//test test/BTEX \footnote{test test test}/ETEX test
-%D test test test/BTEX \bf(nota bene)/ETEX test
-%D test test test /BTEX \bf(nota bene)/ETEX test
-%D \stoptyping
-%D \stopbuffer
-%D
-%D % \bgroup\setuptyping[option=commands]\getbuffer\egroup
-%D
-%D this was keyed in as:
-%D
-%D \typebuffer
-
-\unexpanded\def\type{\mktype\empty}
-
-\let\mktype\gobbleoneargument
-
-%D The neccessary initializations are done by calling
-%D \type{\initializetype} which in return calls for the support
-%D macro \type{\setupinlineverbatim}.
-
-\def\initializetype
- {\let\obeylines\ignorelines
- \setupcommonverbatim
- \setupinlineverbatim}
-
-%D \macros
-%D {setuptype}
-%D
-%D Some characteristics of \type{\type} can be set up by:
-
-\def\setuptype
- {\dodoubleempty\dosetuptype}
-
-\def\dosetuptype[#1][#2]%
- {\ifsecondargument
- \getparameters[\??ty#1][#2]%
- \else
- \getparameters[\??ty][#1]%
- \fi}
-
-%D \macros
-%D {typ,obeyhyphens,obeybreakpoints}
-%D
-%D Although it's not clear from the macros, one character
-%D trait of this macros, which are build on top of the support
-%D module, is that they don't hyphenate. We therefore offer
-%D the alternative \type{\typ}. The current implementation
-%D works all right, but a decent hyphenation support of
-%D \type{\tt} text will be implemented soon.
-
-\def\obeyhyphens
- {\def\obeyedspace {\hskip\interwordspace\relax}% better than spaceskip
- \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint}%
- \spaceskip.25em\relax} % hm a bit of stretch !
-
-\def\obeybreakpoints
- {\ignorehyphens
- \veryraggedright}
-
-% \def\ignorehyphens
-% {\def\obeyedspace {\null\hskip\interwordspace\null}% better than spaceskip
-% \def\controlspace{\null\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\null}%
-% \spaceskip.5em\relax}
-
-\def\ignorehyphens
- {% \language\minusone % extra bonus, the \null should do the job too
- \def\obeyedspace {\hskip\interwordspace}% better than spaceskip
- \def\controlspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint}%
- \spaceskip.5em\relax}
-
-\unexpanded\def\typ
- {\bgroup
- \let\@@tylines\v!hyphenated
- \futurelet\next\dodotype}
-
-%D \macros
-%D {tex,arg,mat,dis}
-%D
-%D Sometimes, for instance when we pass verbatim text as an
-%D argument, the fixed \CATCODES\ interfere with our wishes. An
-%D experimental implementation of character by character
-%D processing of verbatim text did overcome this limitation,
-%D but we've decided not to use that slow and sometimes
-%D troublesome solution. Instead we stick to some 'old'
-%D \CONTEXT\ macros for typesetting typical \TEX\ characters.
-%D
-%D The next implementation is more clear but less versatile,
-%D so we treated it for a beter one.
-%D
-%D \starttyping
-%D \def\dospecialtype#1#2%
-%D {\bgroup
-%D \initializetype
-%D \catcode`\{=\@@begingroup
-%D \catcode`\}=\@@endgroup
-%D \def\dospecialtype%
-%D {\def\dospecialtype{#2\egroup}%
-%D \bgroup
-%D \aftergroup\dospecialtype
-%D #1}%
-%D \afterassignment\dospecialtype
-%D \let\next=}
-%D
-%D \unexpanded\def\tex{\dospecialtype\texescape\relax}
-%D \unexpanded\def\arg{\dospecialtype\leftargument\rightargument}
-%D \unexpanded\def\mat{\dospecialtype\$\$}
-%D \unexpanded\def\dis{\dospecialtype{\$\$}{\$\$}}
-%D \stoptyping
-
-\def\setgroupedtype
- {\let\currenttypingclass\??ty
- \initializetype
- \catcode`\{=\@@begingroup
- \catcode`\}=\@@endgroup}
-
-\unexpanded\def\tex{\groupedcommand{\setgroupedtype\texescape}{\relax}}
-\unexpanded\def\arg{\groupedcommand{\setgroupedtype\leftargument}{\rightargument}}
-\unexpanded\def\mat{\groupedcommand{\setgroupedtype\$}{\$}}
-\unexpanded\def\dis{\groupedcommand{\setgroupedtype\$\$}{\$\$}}
-
-%D \macros
-%D {starttyping}
-%D
-%D Display verbatim is realized far more easy, which is mostly
-%D due to the fact that we use \type{\stop...} as delimiter.
-%D The implementation inherits some features, for instance the
-%D support of linenumbering, which can best be studied in the
-%D documented support module.
-
-\let\currenttyping \empty
-\let\currenttypingclass\??ty % saveguard
-
-% \def\typingparameter#1%
-% {\executeifdefined
-% {\currenttypingclass\currenttyping#1}%
-% {\executeifdefined{\currenttypingclass#1}\empty}}
-
-\def\typingparameter#1%
- {\ifcsname\currenttypingclass\currenttyping#1\endcsname
- \csname\currenttypingclass\currenttyping#1\endcsname
- \else\ifcsname\currenttypingclass#1\endcsname
- \csname\currenttypingclass#1\endcsname
- \fi\fi}
-
-\def\settypingparameter#1#2%
- {\setvalue{\currenttypingclass\currenttyping#1}{#2}}
-
-\def\setxtypingparameter#1#2%
- {\setxvalue{\currenttypingclass\currenttyping#1}{#2}}
-
-% \def\initializetyping
-% {%\donefalse
-% \switchtobodyfont[\typingparameter\c!bodyfont]%
-% \donefalse
-% \scratchskip\typingparameter\c!oddmargin\relax
-% \ifzeropt\scratchskip\else\donetrue\fi
-% \scratchskip\typingparameter\c!evenmargin\relax
-% \ifzeropt\scratchskip\else\donetrue\fi
-% \ifdone
-% \def\doopenupverbatimline
-% {\getpagestatus
-% \ifrightpage
-% \hskip\typingparameter\c!oddmargin\relax
-% \else
-% \hskip\typingparameter\c!evenmargin\relax
-% \fi}%
-% \else
-% \doadaptleftskip{\typingparameter\c!margin}%
-% \fi
-% \doifdefinedelse{\??bo\typingparameter\c!blank}
-% {\edef\!!stringa{\csname\??bo\typingparameter\c!blank\endcsname}}
-% {\edef\!!stringa{\typingparameter\c!blank}}%
-% \processaction
-% [\!!stringa]
-% [ \v!standard=>\scratchskip\ctxparskip,
-% \v!small=>\scratchskip\blankokleinmaat,
-% \v!medium=>\scratchskip\blankomiddelmaat,
-% \v!big=>\scratchskip\blankogrootmaat,
-% \v!halfline=>\scratchskip.5\baselineskip,
-% \v!line=>\scratchskip\baselineskip,
-% \v!none=>\scratchskip\zeropoint,
-% \s!unknown=>\scratchskip\commalistelement]%
-% \ifgridsnapping
-% \ifdim\scratchskip=.5\baselineskip\relax
-% \edef\verbatimbaselineskip{\the\scratchskip}% new
-% \else
-% \edef\verbatimbaselineskip{\the\baselineskip}%
-% \fi
-% \else
-% \edef\verbatimbaselineskip{\the\scratchskip}%
-% \fi
-% \setupcommonverbatim}
-
-\setvalue{\??tp:\c!blank:\v!standard}{\ctxparskip}
-\setvalue{\??tp:\c!blank:\v!small }{\blankokleinmaat}
-\setvalue{\??tp:\c!blank:\v!medium }{\blankomiddelmaat}
-\setvalue{\??tp:\c!blank:\v!big }{\blankogrootmaat}
-\setvalue{\??tp:\c!blank:\v!halfline}{.5\baselineskip}
-\setvalue{\??tp:\c!blank:\v!line }{\baselineskip}
-\setvalue{\??tp:\c!blank:\v!none }{\zeropoint}
-
-\def\initializetyping
- {%\donefalse
- \switchtobodyfont[\typingparameter\c!bodyfont]%
- \donefalse
- \scratchskip\typingparameter\c!oddmargin\relax
- \ifzeropt\scratchskip\else\donetrue\fi
- \scratchskip\typingparameter\c!evenmargin\relax
- \ifzeropt\scratchskip\else\donetrue\fi
- \ifdone
- \def\doopenupverbatimline
- {\getpagestatus
- \ifrightpage
- \hskip\typingparameter\c!oddmargin\relax
- \else
- \hskip\typingparameter\c!evenmargin\relax
- \fi}%
- \else
- \doadaptleftskip{\typingparameter\c!margin}%
- \fi
- \edef\!!stringa{\executeifdefined{\??bo\typingparameter\c!blank}{\typingparameter\c!blank}}%
- \scratchskip\executeifdefined{\??tp:\c!blank:\!!stringa}\!!stringa\relax
- \ifgridsnapping
- \ifdim\scratchskip=.5\baselineskip\relax
- \edef\verbatimbaselineskip{\the\scratchskip}% new
- \else
- \edef\verbatimbaselineskip{\the\baselineskip}%
- \fi
- \else
- \edef\verbatimbaselineskip{\the\scratchskip}%
- \fi
- \setupcommonverbatim}
-
-%D The basic display verbatim commands are defined in an
-%D indirect way. As we will see, they are a specific case of a
-%D more general mechanism.
-
-% we need this hack because otherwise verbatim skips
-% the first line (everything after the initial command)
-
-\def\dostarttyping#1% tricky non standard lookahead
- {\bgroup
- \let\currenttypingclass\??tp
- \edef\currenttyping{#1}%
- \obeylines
- \futurelet\nexttoken\dodostarttyping}
-
-\def\dodostarttyping
- {\ifx\nexttoken[%
- \expandafter\dododostarttyping
- \else
- \expandafter\nododostarttyping
- \fi}
-
-\def\nododostarttyping
- {\dododostarttyping[]}
-
-\def\dododostarttyping[#1]%
- {\typingparameter\c!before
- \startpacked % includes \bgroup
- \dosetuptypelinenumbering{#1}%
- \initializetyping
- \startverbatimcolor
- \expanded{\mktypeblockverbatim{\s!start\currenttyping}{\s!stop\currenttyping}}}
-
-\def\dostoptyping#1% hm, currenttyping
- {\stopverbatimcolor
- \stoppacked % includes \egroup
- \typingparameter\c!after
- \egroup
- \dochecknextindentation{\??tp#1}%
- \dorechecknextindentation}
-
-%D Line numbering for files is combined with filtering, while
-%D display verbatim has the ability to continue.
-%D
-%D \starttyping
-%D \typefile[numbering=file,start=10,stop=12]{test.tex}
-%D
-%D \definetyping[code][numbering=line]
-%D
-%D \starttext
-%D \startcode
-%D ...
-%D ...
-%D \stopcode
-%D
-%D \startcode[continue]
-%D ...
-%D ...
-%D \stopcode
-%D
-%D \startcode[start=10]
-%D ...
-%D \stopcode
-%D \stoptyping
-
-%D \macros
-%D {setuptyping}
-%D
-%D The setup of typing accepts two arguments. The optional
-%D first one identifies the user defined ones. If only one
-%D argument is given, the values apply to both the standard
-%D command \type{\starttyping} and \type{\typefile}.
-
-\def\dosetuptyping[#1][#2]%
- {\ifsecondargument
- \getparameters[\??tp#1][#2]%
- \else
- \getparameters[\??tp][#1]%
- \fi}
-
-\def\setuptyping
- {\dodoubleempty\dosetuptyping}
-
-%D \macros
-%D {definetype}
-%D
-%D Specific inline verbatim commands can be defined with the
-%D following command.
-
-\def\definetype
- {\dodoubleempty\dodefinetype}
-
-\def\dodefinetype[#1][#2]%
- {\unexpanded\setvalue{#1}{\mktype{#1}}%
- \getparameters[\??ty#1][#2]}
-
-%D \macros
-%D {definetyping}
-%D
-%D For most users the standard \type{\start}||\type{\stop}||pair
-%D will suffice, but for documentation purposes the next
-%D definition command can be of use:
-%D
-%D \starttyping
-%D \definetyping[extratyping][margin=3em]
-%D
-%D \startextratyping
-%D these extra ones are indented by 1 em
-%D \stopextratyping
-%D \stoptyping
-%D
-%D The definitions default to the standard typing values.
-
-\def\presettyping[#1][#2]%
- {\copyparameters[\??tp#1][\??tp][\c!color,\c!style]%
- \getparameters [\??tp#1][#2]}
-
-\def\dodefinetyping[#1][#2]%
- {\setvalue{\e!start#1}{\dostarttyping{#1}}%
- \setvalue{\e!stop #1}{\dostoptyping {#1}}%
- \presettyping[#1][#2]}
-
-\def\definetyping
- {\dodoubleempty\dodefinetyping}
-
-%D We can use some core color commands. These are faster than
-%D the standard color switching ones and work ok on a line by
-%D line basis.
-%D
-%D \starttyping
-%D \def\setupverbatimcolor%
-%D {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}%
-%D \def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
-%D \def\endofpretty {\stopcolormode}}
-%D \stoptyping
-%D
-%D Since we support a global color too, the folowing
-%D definition is better:
-
-% \def\setupverbatimcolor% fast and local versus slow and global
-% {\doifelsenothing{\typingparameter\c!color}
-% {\def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}%
-% \let\endofpretty \restorecolormode % \stopcolormode
-% \let\startverbatimcolor \relax
-% \let\stopverbatimcolor \relax
-% \let\verbatimcolor \relax}
-% {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
-% \let\endofpretty \stopcolor
-% \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
-% \let\stopverbatimcolor \stopcolor
-% \def\verbatimcolor {\getvalue{\typingparameter\c!color}}}% command !
-% \doifelsenothing{\typingparameter\c!palet}
-% {\let\prettypalet\empty
-% \let\endofpretty\relax
-% \def\beginofpretty[##1]{}}
-% {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
-%
-% let's forget about this optimization not that we have mkiv
-
-\def\setupverbatimcolor
- {\def\beginofpretty[##1]{\startcolor[\prettypalet:##1]}%
- \let\endofpretty \stopcolor
- \def\startverbatimcolor{\startcolor[\typingparameter\c!color]}%
- \let\stopverbatimcolor \stopcolor
- \def\verbatimcolor {\getvalue{\typingparameter\c!color}}% command !
- \doifelsenothing{\typingparameter\c!palet}
- {\let\prettypalet\empty
- \let\endofpretty\relax
- \def\beginofpretty[##1]{}}
- {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}}}
-
-\let\prettypalet \empty
-\let\startverbatimcolor\relax
-\let\stopverbatimcolor \relax
-\let\verbatimcolor \relax
-
-%D In the verbatim module, there are some examples given of
-%D the more obscure features of the verbatim environments.
-%D
-%D \startbuffer
-%D \startTEX
-%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
-%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
-%D \stopTEX
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D This gives, as can be expected:
-%D
-%D \getbuffer
-%D
-%D When we want to see some typeset \TEX\ too, we can say:
-%D
-%D \startbuffer
-%D \startTEX
-%D \def\mathematics#1% %%\ N usage: \type {\mathematics{x^2}}
-%D {\ifmmode#1\else$#1$\fi} %%\ N becomes: \mathematics{x^2}
-%D \stopTEX
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D or:
-%D
-%D \getbuffer
-%D
-%D In a similar way:
-%D
-%D \startbuffer
-%D \startSQL
-%D select * -- indeed, here we {\em do} select
-%D from tableA
-%D where 1 = 2
-%D \stopSQL
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D gives:
-%D
-%D \getbuffer
-%D
-%D The next examples sow how we can directly call for natural
-%D \TEX\ comments:
-%D
-%D \startbuffer
-%D \setuptyping
-%D [TEX]
-%D [text=yes]
-%D
-%D \startTEX
-%D \def\mathematics#1% % usage: \type {\mathematics{x^2}}
-%D {\ifmmode#1\else$#1$\fi} % becomes: \mathematics{x^2}
-%D \stopTEX
-%D
-%D \setuptyping
-%D [SQL]
-%D [text=yes,palet=,icommand=\bf,vcommand=,ccommand=\it]
-%D
-%D \startSQL
-%D select * -- indeed, here we {\em do} select
-%D from tableA
-%D where 1 = 2
-%D \stopSQL
-%D
-%D \setuptyping
-%D [SQL]
-%D [ccommand=\tf\underbar]
-%D
-%D \startSQL
-%D select * -- indeed, here we {\em do} select
-%D from tableA
-%D where 1 = 2
-%D \stopSQL
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Now watch:
-%D
-%D \getbuffer
-%D
-%D The natural \TEX\ typesetting was introduced when Tobias
-%D and Berend started using verbatim \JAVASCRIPT\ and \SQL.
-
-%D \macros
-%D {EveryPar, EveryLine, iflinepar}
-%D
-%D One of the features of these commands is the support of
-%D \type{\EveryPar}, \type{\EveryLine} and \type{\iflinepar}.
-%D In the documentation of the verbatim support module we give
-%D some examples of line- and paragraph numbering using these
-%D macros.
-
-%D \macros
-%D {typefile}
-%D
-%D Typesetting files verbatim (for the moment) only supports
-%D colorization of \TEX\ sources as valid option. The other
-%D setup values are inherited from display verbatim.
-%D The implementation of \type{\typefile} is straightforward:
-
-% new feature (not yet 100\% ok)
-%
-% \setuptyping[file][numbering=file]
-%
-% \typefile[start=2,nlines=3]{zapf}
-% \typefile[start=continue,nlines=13]{zapf}
-% \typefile{zapf}
-%
-% \setuptyping[file][numbering=line]
-%
-% \typefile[start=4,step=3]{zapf}
-% \typefile{zapf}
-
-\def\typefile
- {\dodoubleempty\dotypefile}
-
-\def\dotypefile[#1][#2]#3%
- {\ifsecondargument
- \dodotypefile[#1][#2]{#3}%
- \else\iffirstargument
- \doifassignmentelse{#1}
- {\dodotypefile[\v!file][#1]{#3}}
- {\dodotypefile[#1][]{#3}}%
- \else
- \dodotypefile[\v!file][]{#3}%
- \fi\fi}
-
-\def\dosetuptypelinenumbering#1% fuzzy
- {\doifundefined{\currenttypingclass\currenttyping\c!start}
- {\setuptyping[\currenttyping][\c!start=1,\c!stop=,\c!step=1,\c!nlines=]}%
- \setuptyping[\currenttyping][#1]%
- \doifelse{\typingparameter\c!numbering}\v!file
- {% kind of special: filters lines !
- \setuplinenumbering[\c!method=\v!file]%
- \donetrue}
- {\doifelse{\typingparameter\c!numbering}\v!line
- {% \setuplinenumbering defaults start/step to 1/1, so we need
- \doifinsetelse\v!continue{#1,\typingparameter\c!start}
- {\scratchcounter0\typingparameter\c!n
- \setxtypingparameter\c!start{\ifnum\scratchcounter=0 1\else\number\scratchcounter\fi}}%
- {\doifnothing{\typingparameter\c!start}{\settypingparameter\c!start{1}}}%
- \doifnothing{\typingparameter\c!step}{\settypingparameter\c!step{1}}%
- \setuplinenumbering
- [\c!method=\v!type,
- \c!start=\typingparameter\c!start,
- \c!stop=\typingparameter\c!stop,
- \c!step=\typingparameter\c!step]%
- \donetrue}
- {\donefalse}}%
- \ifdone
- \ifx\startlinenumbering\undefined \let\startlinenumbering\relax \fi
- \ifx\stoplinenumbering \undefined \let\stoplinenumbering \relax \fi
- \def\beginofverbatimlines{\startlinenumbering}%
- \def\endofverbatimlines {\stoplinenumbering\setxtypingparameter\c!n{\number\linenumber}}%
- \fi}
-
-\def\reporttypingerror#1% temp hack
- {\blank
- \dontleavehmode\hbox\bgroup
- \expanded{\defconvertedargument\noexpand\ascii{#1}}%
- \tttf[\makemessage\m!verbatims1\ascii]%
- \showmessage\m!verbatims1\ascii
- \egroup
- \blank}
-
-\def\dosometyping#1#2#3#4#5%
- {\bgroup
- \let\currenttypingclass\??tp
- \edef\currenttyping{#1}%
- \typingparameter\c!before
- \startpacked % includes \bgroup
- \dosetuptypelinenumbering{#2}%
- \doifinset{\typingparameter\c!option}{\v!commands,\v!slanted,\v!normal}
- {\setuptyping[#1][\c!option=\v!none]}%
- \doif{\typingparameter\c!option}\v!color
- {\expandafter\aftersplitstring#3\at.\to\prettyidentifier
- \settypingparameter\c!option{\prettyidentifier}}%
- \initializetyping
- \startverbatimcolor
- \doifundefinedelse{\currenttypingclass#3\v!global\c!start}
- {\scratchcounter\zerocount}
- {\scratchcounter\getvalue{\currenttypingclass#3\v!global\c!start}}%
- \advance\scratchcounter\plusone
- \setxvalue{\currenttypingclass#3\v!global\c!start}{\the\scratchcounter}%
- \doifelsenothing{\typingparameter\c!start}
- {#4}
- {\doif{\typingparameter\c!start}\v!continue
- {\setevalue{\currenttypingclass#1\c!start}%
- {\getvalue{\currenttypingclass#3\v!global\c!start}}}%
- \doifelsenothing{\typingparameter\c!stop}
- {\doifelsenothing{\typingparameter\c!nlines}
- {#4}
- {\setxvalue{\currenttypingclass#3\v!global\c!start}%
- {\the\numexpr\typingparameter\c!start+\typingparameter\c!nlines+\minusone\relax}%
- #5{\typingparameter\c!start}{\getvalue{\currenttypingclass#3\v!global\c!start}}}}%
- {#5{\typingparameter\c!start}{\typingparameter\c!stop}}}%
- \stopverbatimcolor
- \stoppacked
- \typingparameter\c!after
- \egroup}
-
-\def\doifelsetypingfile#1% sets \readfilename
- {\doiflocfileelse{#1}
- {\firstoftwoarguments}
- {\doifinputfileelse{#1}
- {\def\readfilename{\pathplusfile\filepath{#1}}\firstoftwoarguments}
- {\secondoftwoarguments}}}
-
-\def\dodotypefile[#1][#2]#3%
- {\doifelsetypingfile{#3}
- {\dosometyping{#1}{#2}{#3}\mktypefileverbatim\mktypefilelinesverbatim}
- {\reporttypingerror{#3}}}
-
-%D \macros
-%D {filename}
-%D
-%D Typesetting filenames in monospaced fonts is possible with
-%D
-%D \starttyping
-%D \filename{here/there/filename.suffix}
-%D \stoptyping
-%D
-%D The definition is not that spectacular.
-
-\unexpanded\def\filename#1{{\tttf\hyphenatedfilename{#1}}}
-
-%D This leaves some settings:
-
-\permitshiftedendofverbatim
-\optimizeverbatimtrue
-
-%D And a bonus macro:
-
-\def\verbatim#1{\defconvertedargument\ascii{#1}\ascii}
-
-%D Plugins
-
-\loadmarkfile{core-ver}
-
-%D The setups for display verbatim and file verbatim are
-%D shared. One can adapt the extra defined typing environments,
-%D but they also default to the values below. Watch the
-%D alternative escape character.
-
-\setuptyping
- [ \c!before=\blank,
- \c!after=\blank,
- \c!bodyfont=,
- \c!color=,
- \c!space=\v!off,
- \c!page=\v!no,
- \c!tab=\s!ascii,
- \c!option=\v!none,
- \c!palet=colorpretty,
- \c!text=\v!no,
- \c!style=\tttf,
- \c!icommand=\ttsl,
- \c!vcommand=,
- \c!ccommand=\tttf,
- \c!indentnext=\v!yes,
- \c!margin=\!!zeropoint,
- \c!evenmargin=\!!zeropoint,
- \c!oddmargin=\!!zeropoint,
- \c!blank=\v!line,
- \c!escape=/, % beware \string\ , should also be accepted
- \c!numbering=\v!no,
- \c!lines=,
- \c!empty=,
- \c!start=1,
- \c!stop=,
- \c!step=1,
- \c!continue=,
- \c!nlines=]
-
-\definetyping[\v!typing]
-
-\presettyping[\v!file][]
-
-% \setuptyping % not needed
-% [\v!file]
-% [\c!start=1,
-% \c!stop=,
-% \c!step=1,
-% \c!continue=,
-% \c!nlines=]
-
-%D The setups for inline verbatim default to:
-
-\setuptype
- [ \c!space=\v!off,
- \c!color=,
- \c!style=\tt\tf, % \tttf gives problems with {\tx \type...}
- \c!page=\v!no,
- \c!tab=\v!yes,
- \c!palet=colorpretty,
- \c!option=\v!normal]
-
-\definetyping[RAW] [\c!option=RAW]
-\definetyping[MP] [\c!option=MP]
-\definetyping[PL] [\c!option=PL]
-\definetyping[PM] [\c!option=PL]
-\definetyping[JS] [\c!option=JS]
-\definetyping[JV] [\c!option=JV]
-\definetyping[SQL] [\c!option=SQL]
-\definetyping[TEX] [\c!option=TEX]
-\definetyping[PAS] [\c!option=PAS]
-\definetyping[PASCAL][\c!option=PAS]
-\definetyping[MOD] [\c!option=PAS]
-\definetyping[MODULA][\c!option=PAS]
-\definetyping[DELPHI][\c!option=PAS]
-\definetyping[EIFFEL][\c!option=EIF]
-\definetyping[XML] [\c!option=XML]
-\definetyping[LUA] [\c!option=LUA]
-
-\installprettytype [RAW] [RAW]
-
-\installprettytype [TEX] [TEX]
-
-\installprettytype [PERL] [PL]
-\installprettytype [PL] [PL]
-\installprettytype [PM] [PL]
-
-\installprettytype [METAPOST] [MP]
-\installprettytype [METAFONT] [MP]
-\installprettytype [MP] [MP]
-\installprettytype [MF] [MP]
-
-\installprettytype [JAVASCRIPT] [JS]
-\installprettytype [JAVA] [JV]
-\installprettytype [JS] [JS]
-\installprettytype [JV] [JV]
-
-\installprettytype [SQL] [SQL]
-
-\installprettytype [PASCAL] [PAS]
-\installprettytype [PAS] [PAS]
-\installprettytype [MODULA] [PAS]
-\installprettytype [MOD] [PAS]
-
-\installprettytype [EIFFEL] [EIF]
-\installprettytype [EIF] [EIF]
-\installprettytype [E] [EIF]
-
-\installprettytype [XML] [XML]
-
-\installprettytype [LUA] [LUA]
-
-\installnewpretty M {\setupprettiesintype {MP}\setupprettytype}
-\installnewpretty P {\setupprettiesintype {PL}\setupprettytype}
-\installnewpretty T {\setupprettiesintype{TEX}\setupprettytype}
-\installnewpretty J {\setupprettiesintype {JV}\setupprettytype}
-\installnewpretty S {\setupprettiesintype{SQL}\setupprettytype}
-\installnewpretty W {\setupprettiesintype{PAS}\setupprettytype} % Wirth
-\installnewpretty I {\setupprettiesintype{EIF}\setupprettytype} % E taken
-\installnewpretty X {\setupprettiesintype{XML}\setupprettytype}
-
-%D We use the \CONTEXT\ color system for switching to and from
-%D color mode. We can always redefine these colors afterwards.
-
-\definecolor [colorprettyone] [r=.9, g=.0, b=.0] % red
-\definecolor [colorprettytwo] [r=.0, g=.8, b=.0] % green
-\definecolor [colorprettythree] [r=.0, g=.0, b=.9] % blue
-\definecolor [colorprettyfour] [r=.8, g=.8, b=.6] % yellow
-
-\definecolor [grayprettyone] [s=.30]
-\definecolor [grayprettytwo] [s=.45]
-\definecolor [grayprettythree] [s=.60]
-\definecolor [grayprettyfour] [s=.75]
-
-\definepalet
- [colorpretty]
- [ prettyone=colorprettyone,
- prettytwo=colorprettytwo,
- prettythree=colorprettythree,
- prettyfour=colorprettyfour]
-
-\definepalet
- [graypretty]
- [ prettyone=grayprettyone,
- prettytwo=grayprettytwo,
- prettythree=grayprettythree,
- prettyfour=grayprettyfour]
-
-\definepalet [TEXcolorpretty] [colorpretty]
-\definepalet [TEXgraypretty] [graypretty]
-\definepalet [PLcolorpretty] [colorpretty]
-\definepalet [PLgraypretty] [graypretty]
-\definepalet [PMcolorpretty] [colorpretty]
-\definepalet [PMgraypretty] [graypretty]
-\definepalet [MPcolorpretty] [colorpretty]
-\definepalet [MPgraypretty] [graypretty]
-\definepalet [JVcolorpretty] [colorpretty]
-\definepalet [JVgraypretty] [graypretty]
-\definepalet [JScolorpretty] [colorpretty]
-\definepalet [JSgraypretty] [graypretty]
-\definepalet [SQLcolorpretty] [colorpretty]
-\definepalet [SQLgraypretty] [graypretty]
-\definepalet [PAScolorpretty] [colorpretty]
-\definepalet [PASgraypretty] [graypretty]
-\definepalet [EIFcolorpretty] [colorpretty]
-\definepalet [EIFgraypretty] [graypretty]
-\definepalet [XMLcolorpretty] [colorpretty]
-\definepalet [XMLgraypretty] [graypretty]
-\definepalet [LUAcolorpretty] [colorpretty]
-\definepalet [LUAgraypretty] [graypretty]
-
-\protect \endinput
diff --git a/tex/context/base/core-vis.tex b/tex/context/base/core-vis.tex
index b20c9b9ce..949cd176f 100644
--- a/tex/context/base/core-vis.tex
+++ b/tex/context/base/core-vis.tex
@@ -25,14 +25,12 @@
%D %\leftskip only if explicit one
%D %\rightskip only if explicit one
-\writestatus{loading}{Context Support Macros / Visualization}
+\writestatus{loading}{ConTeXt Support Macros / Visualization}
\unprotect
%D \macros
-%D {indent, noindent,
-%D leavevmode,
-%D par}
+%D {indent, noindent, par}
%D
%D \TeX\ acts upon paragraphs. In mosts documents paragraphs
%D are separated by empty lines, which internally are handled as
@@ -43,17 +41,11 @@
%D Because the actual typesetting is based on both explicit
%D user and implicit system actions, visualization is only
%D possible for the user supplied \type{\indent},
-%D \type{\noindent}, \type{\leavevmode} and \type{\par}. Other
+%D \type{\noindent}, and \type{\par}. Other
%D 'clever' tricks will quite certainly lead to more failures
%D than successes, so we only support these three explicit
%D primitives and one macro:
-\let\normalnoindent = \noindent
-\let\normalindent = \indent
-\let\normalpar = \par
-
-\let\normalleavevmode = \leavevmode
-
\def\showparagraphcue#1#2#3#4#5%
{\bgroup
\scratchdimen#1\relax
@@ -128,30 +120,15 @@
\fi
\normalhskip\parindent}
-\def\ruledleavevmode
- {\relax
- \normalleavevmode
- \ifdim\parindent>\zeropoint
- \normalhskip-\parindent
- \ruledparagraphcues
- \showparagraphcue\parindent\relax\leftrulefalse\rightrulefalse\!!height
- \normalhskip\parindent
- \else
- \ruledparagraphcues
- \showparagraphcue{40\testrulewidth}\llap\leftrulefalse\rightrulefalse\!!height
- \fi}
-
\def\dontshowimplicits
{\let\noindent \normalnoindent
\let\indent \normalindent
- \let\leavevmode \normalleavevmode
\let\par \normalpar}
\def\showimplicits
{\testrulewidth \defaulttestrulewidth
\let\noindent \rulednoindent
\let\indent \ruledindent
- \let\leavevmode \ruledleavevmode
\let\par \ruledpar}
%D The next few||line examples show the four cues. Keep in
@@ -170,18 +147,15 @@
%D
%D \voorbeeld \indent
%D \voorbeeld \noindent
-%D \voorbeeld \leavevmode
%D
%D \parindent=60pt
%D
%D \voorbeeld \indent
%D \voorbeeld \noindent
-%D \voorbeeld \leavevmode
%D
%D \startnarrower
%D \voorbeeld \indent
%D \voorbeeld \noindent
-%D \voorbeeld \leavevmode
%D \stopnarrower
%D \egroup
%D
diff --git a/tex/context/base/data-aux.lua b/tex/context/base/data-aux.lua
new file mode 100644
index 000000000..492cce6fd
--- /dev/null
+++ b/tex/context/base/data-aux.lua
@@ -0,0 +1,57 @@
+if not modules then modules = { } end modules ['data-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local find = string.find
+
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+
+function resolvers.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
+ local scriptpath = "scripts/context/lua"
+ newname = file.addsuffix(newname,"lua")
+ local oldscript = resolvers.clean_path(oldname)
+ if trace_verbose then
+ logs.report("fileio","to be replaced old script %s", oldscript)
+ end
+ local newscripts = resolvers.find_files(newname) or { }
+ if #newscripts == 0 then
+ if trace_verbose then
+ logs.report("fileio","unable to locate new script")
+ end
+ else
+ for i=1,#newscripts do
+ local newscript = resolvers.clean_path(newscripts[i])
+ if trace_verbose then
+ logs.report("fileio","checking new script %s", newscript)
+ end
+ if oldscript == newscript then
+ if trace_verbose then
+ logs.report("fileio","old and new script are the same")
+ end
+ elseif not find(newscript,scriptpath) then
+ if trace_verbose then
+ logs.report("fileio","new script should come from %s",scriptpath)
+ end
+ elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then
+ if trace_verbose then
+ logs.report("fileio","invalid new script name")
+ end
+ else
+ local newdata = io.loaddata(newscript)
+ if newdata then
+ if trace_verbose then
+ logs.report("fileio","old script content replaced by new content")
+ end
+ io.savedata(oldscript,newdata)
+ break
+ elseif trace_verbose then
+ logs.report("fileio","unable to load new script")
+ end
+ end
+ end
+ end
+end
diff --git a/tex/context/base/data-bin.lua b/tex/context/base/data-bin.lua
new file mode 100644
index 000000000..5f342c339
--- /dev/null
+++ b/tex/context/base/data-bin.lua
@@ -0,0 +1,26 @@
+if not modules then modules = { } end modules ['data-bin'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+
+function resolvers.findbinfile(filename, filetype)
+ return resolvers.methodhandler('finders',file.collapse_path(filename), filetype)
+end
+
+function resolvers.openbinfile(filename)
+ return resolvers.methodhandler('loaders',file.collapse_path(filename))
+end
+
+function resolvers.loadbinfile(filename, filetype)
+ local fname = resolvers.findbinfile(file.collapse_path(filename), filetype)
+ if fname and fname ~= "" then
+ return resolvers.openbinfile(fname)
+ else
+ return unpack(loaders.notfound)
+ end
+end
diff --git a/tex/context/base/data-con.lua b/tex/context/base/data-con.lua
new file mode 100644
index 000000000..02ee9eedd
--- /dev/null
+++ b/tex/context/base/data-con.lua
@@ -0,0 +1,122 @@
+if not modules then modules = { } end modules ['data-con'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, lower, gsub = string.format, string.lower, string.gsub
+
+local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
+local trace_containers = false trackers.register("resolvers.containers", function(v) trace_containers = v end)
+local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+
+--[[ldx--
+
Once we found ourselves defining similar cache constructs
+several times, containers were introduced. Containers are used
+to collect tables in memory and reuse them when possible based
+on (unique) hashes (to be provided by the calling function).
+
+
Caching to disk is disabled by default. Version numbers are
+stored in the saved table which makes it possible to change the
+table structures without bothering about the disk cache.
+
+
Examples of usage can be found in the font related code.
+--ldx]]--
+
+containers = containers or { }
+
+containers.usecache = true
+
+local function report(container,tag,name)
+ if trace_cache or trace_containers then
+ logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
+ end
+end
+
+local allocated = { }
+
+-- tracing
+
+function containers.define(category, subcategory, version, enabled)
+ return function()
+ if category and subcategory then
+ local c = allocated[category]
+ if not c then
+ c = { }
+ allocated[category] = c
+ end
+ local s = c[subcategory]
+ if not s then
+ s = {
+ category = category,
+ subcategory = subcategory,
+ storage = { },
+ enabled = enabled,
+ version = version or 1.000,
+ trace = false,
+ path = caches and caches.setpath and caches.setpath(category,subcategory),
+ }
+ c[subcategory] = s
+ end
+ return s
+ else
+ return nil
+ end
+ end
+end
+
+function containers.is_usable(container, name)
+ return container.enabled and caches and caches.iswritable(container.path, name)
+end
+
+function containers.is_valid(container, name)
+ if name and name ~= "" then
+ local storage = container.storage[name]
+ return storage and not table.is_empty(storage) and storage.cache_version == container.version
+ else
+ return false
+ end
+end
+
+function containers.read(container,name)
+ if container.enabled and caches and not container.storage[name] and containers.usecache then
+ container.storage[name] = caches.loaddata(container.path,name)
+ if containers.is_valid(container,name) then
+ report(container,"loaded",name)
+ else
+ container.storage[name] = nil
+ end
+ end
+ if container.storage[name] then
+ report(container,"reusing",name)
+ end
+ return container.storage[name]
+end
+
+function containers.write(container, name, data)
+ if data then
+ data.cache_version = container.version
+ if container.enabled and caches then
+ local unique, shared = data.unique, data.shared
+ data.unique, data.shared = nil, nil
+ caches.savedata(container.path, name, data)
+ report(container,"saved",name)
+ data.unique, data.shared = unique, shared
+ end
+ report(container,"stored",name)
+ container.storage[name] = data
+ end
+ return data
+end
+
+function containers.content(container,name)
+ return container.storage[name]
+end
+
+function containers.cleanname(name)
+ return (gsub(lower(name),"[^%w%d]+","-"))
+end
diff --git a/tex/context/base/data-crl.lua b/tex/context/base/data-crl.lua
new file mode 100644
index 000000000..5cad241a6
--- /dev/null
+++ b/tex/context/base/data-crl.lua
@@ -0,0 +1,58 @@
+if not modules then modules = { } end modules ['data-crl'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+curl = curl or { }
+
+curl.cached = { }
+curl.cachepath = caches.definepath("curl")
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+
+function curl.fetch(protocol, name)
+ local cachename = curl.cachepath() .. "/" .. name:gsub("[^%a%d%.]+","-")
+-- cachename = cachename:gsub("[\\/]", io.fileseparator)
+ cachename = cachename:gsub("[\\]", "/") -- cleanup
+ if not curl.cached[name] then
+ if not io.exists(cachename) then
+ curl.cached[name] = cachename
+ local command = "curl --silent --create-dirs --output " .. cachename .. " " .. name -- no protocol .. "://"
+ os.spawn(command)
+ end
+ if io.exists(cachename) then
+ curl.cached[name] = cachename
+ else
+ curl.cached[name] = ""
+ end
+ end
+ return curl.cached[name]
+end
+
+function finders.curl(protocol,filename)
+ local foundname = curl.fetch(protocol, filename)
+ return finders.generic(protocol,foundname,filetype)
+end
+
+function openers.curl(protocol,filename)
+ return openers.generic(protocol,filename)
+end
+
+function loaders.curl(protocol,filename)
+ return loaders.generic(protocol,filename)
+end
+
+-- todo: metamethod
+
+function curl.install(protocol)
+ finders[protocol] = function (filename,filetype) return finders.curl(protocol,filename) end
+ openers[protocol] = function (filename) return openers.curl(protocol,filename) end
+ loaders[protocol] = function (filename) return loaders.curl(protocol,filename) end
+end
+
+curl.install('http')
+curl.install('https')
+curl.install('ftp')
diff --git a/tex/context/base/data-ctx.lua b/tex/context/base/data-ctx.lua
new file mode 100644
index 000000000..00d307b6d
--- /dev/null
+++ b/tex/context/base/data-ctx.lua
@@ -0,0 +1,29 @@
+if not modules then modules = { } end modules ['data-ctx'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+function resolvers.save_used_files_in_trees(filename,jobname)
+ if not filename then filename = 'luatex.jlg' end
+ local found = instance.foundintrees
+ local f = io.open(filename,'w')
+ if f then
+ f:write("\n")
+ f:write("\n")
+ if jobname then
+ f:write(format("\t%s\n",jobname))
+ end
+ f:write("\t\n")
+ for _,v in ipairs(table.sortedkeys(found)) do
+ f:write(format("\t\t%s\n",found[v],v))
+ end
+ f:write("\t\n")
+ f:write("\n")
+ f:close()
+ end
+end
diff --git a/tex/context/base/data-gen.lua b/tex/context/base/data-gen.lua
new file mode 100644
index 000000000..8537b0526
--- /dev/null
+++ b/tex/context/base/data-gen.lua
@@ -0,0 +1,9 @@
+if not modules then modules = { } end modules ['data-gen'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- move generators here
diff --git a/tex/context/base/data-inp.lua b/tex/context/base/data-inp.lua
new file mode 100644
index 000000000..700e982c2
--- /dev/null
+++ b/tex/context/base/data-inp.lua
@@ -0,0 +1,15 @@
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+resolvers.finders = resolvers.finders or { }
+resolvers.openers = resolvers.openers or { }
+resolvers.loaders = resolvers.loaders or { }
+
+resolvers.finders.notfound = { nil }
+resolvers.openers.notfound = { nil }
+resolvers.loaders.notfound = { false, nil, 0 }
diff --git a/tex/context/base/data-kps.lua b/tex/context/base/data-kps.lua
new file mode 100644
index 000000000..09d502409
--- /dev/null
+++ b/tex/context/base/data-kps.lua
@@ -0,0 +1,101 @@
+if not modules then modules = { } end modules ['luat-kps'] = {
+ version = 1.001,
+ comment = "companion to luatools.lua",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This file is used when we want the input handlers to behave like
+kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
+the next bunch:
+--ldx]]--
+
+formats['bib'] = ''
+formats['bst'] = ''
+formats['mft'] = ''
+formats['ist'] = ''
+formats['web'] = ''
+formats['cweb'] = ''
+formats['MetaPost support'] = ''
+formats['TeX system documentation'] = ''
+formats['TeX system sources'] = ''
+formats['Troff fonts'] = ''
+formats['dvips config'] = ''
+formats['graphic/figure'] = ''
+formats['ls-R'] = ''
+formats['other text files'] = ''
+formats['other binary files'] = ''
+
+formats['gf'] = ''
+formats['pk'] = ''
+formats['base'] = 'MFBASES'
+formats['cnf'] = ''
+formats['mem'] = 'MPMEMS'
+formats['mf'] = 'MFINPUTS'
+formats['mfpool'] = 'MFPOOL'
+formats['mppool'] = 'MPPOOL'
+formats['texpool'] = 'TEXPOOL'
+formats['PostScript header'] = 'TEXPSHEADERS'
+formats['cmap files'] = 'CMAPFONTS'
+formats['type42 fonts'] = 'T42FONTS'
+formats['web2c files'] = 'WEB2C'
+formats['pdftex config'] = 'PDFTEXCONFIG'
+formats['texmfscripts'] = 'TEXMFSCRIPTS'
+formats['bitmap font'] = ''
+formats['lig files'] = 'LIGFONTS'
diff --git a/tex/context/base/data-lst.lua b/tex/context/base/data-lst.lua
new file mode 100644
index 000000000..10d3ea479
--- /dev/null
+++ b/tex/context/base/data-lst.lua
@@ -0,0 +1,58 @@
+if not modules then modules = { } end modules ['data-lst'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- used in mtxrun
+
+local find, concat, upper, format = string.find, table.concat, string.upper, string.format
+
+resolvers.listers = resolvers.listers or { }
+
+local function tabstr(str)
+ if type(str) == 'table' then
+ return concat(str," | ")
+ else
+ return str
+ end
+end
+
+local function list(list,report)
+ local instance = resolvers.instance
+ local pat = upper(pattern or "","")
+ local report = report or texio.write_nl
+ for _,key in pairs(table.sortedkeys(list)) do
+ if instance.pattern == "" or find(upper(key),pat) then
+ if instance.kpseonly then
+ if instance.kpsevars[key] then
+ report(format("%s=%s",key,tabstr(list[key])))
+ end
+ else
+ report(format('%s %s=%s',(instance.kpsevars[key] and 'K') or 'E',key,tabstr(list[key])))
+ end
+ end
+ end
+end
+
+function resolvers.listers.variables () list(resolvers.instance.variables ) end
+function resolvers.listers.expansions() list(resolvers.instance.expansions) end
+
+function resolvers.listers.configurations(report)
+ local report = report or texio.write_nl
+ local instance = resolvers.instance
+ for _,key in ipairs(table.sortedkeys(instance.kpsevars)) do
+ if not instance.pattern or (instance.pattern=="") or find(key,instance.pattern) then
+ report(format("%s\n",key))
+ for i,c in ipairs(instance.order) do
+ local str = c[key]
+ if str then
+ report(format("\t%s\t%s",i,str))
+ end
+ end
+ report("")
+ end
+ end
+end
diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua
new file mode 100644
index 000000000..86231b3a3
--- /dev/null
+++ b/tex/context/base/data-lua.lua
@@ -0,0 +1,55 @@
+if not modules then modules = { } end modules ['data-lua'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- some loading stuff ... we might move this one to slot 1 depending
+-- on the developments (the loaders must not trigger kpse); we could
+-- of course use a more extensive lib path spec
+
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end)
+
+local gsub = string.gsub
+
+local libformats = { 'luatexlibs', 'tex', 'texmfscripts', 'othertextfiles' }
+local libpaths = file.split_path(package.path)
+
+package.loaders[#package.loaders+1] = function(name)
+ for i=1,#libformats do
+ local format = libformats[i]
+ local resolved = resolvers.find_file(name,format) or ""
+ if resolved ~= "" then
+ if trace_locating then
+ logs.report("fileio","! lib '%s' located via environment: '%s'",name,resolved)
+ end
+ return function() return dofile(resolved) end
+ end
+ end
+ local simple = file.removesuffix(name)
+ for i=1,#libpaths do
+ local resolved = gsub(libpaths[i],"?",simple)
+ if resolvers.isreadable.file(resolved) then
+ if trace_locating then
+ logs.report("fileio","! lib '%s' located via 'package.path': '%s'",name,resolved)
+ end
+ return function() return dofile(resolved) end
+ end
+ end
+ -- just in case the distribution is messed up
+ local resolved = resolvers.find_file(file.basename(name),'luatexlibs') or ""
+ if resolved ~= "" then
+ if trace_locating then
+ logs.report("fileio","! lib '%s' located by basename via environment: '%s'",name,resolved)
+ end
+ return function() return dofile(resolved) end
+ end
+ if trace_locating then
+ logs.report("fileio",'? unable to locate lib: %s',name)
+ end
+ return "unable to locate " .. name
+end
+
+resolvers.loadlualib = require
diff --git a/tex/context/base/data-out.lua b/tex/context/base/data-out.lua
new file mode 100644
index 000000000..b774e25fc
--- /dev/null
+++ b/tex/context/base/data-out.lua
@@ -0,0 +1,10 @@
+if not modules then modules = { } end modules ['data-out'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+outputs = outputs or { }
+
diff --git a/tex/context/base/data-pre.lua b/tex/context/base/data-pre.lua
new file mode 100644
index 000000000..deee9ebf4
--- /dev/null
+++ b/tex/context/base/data-pre.lua
@@ -0,0 +1,90 @@
+if not modules then modules = { } end modules ['data-res'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--~ print(resolvers.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
+
+local upper, lower, gsub = string.upper, string.lower, string.gsub
+
+local prefixes = { }
+
+prefixes.environment = function(str)
+ return resolvers.clean_path(os.getenv(str) or os.getenv(upper(str)) or os.getenv(lower(str)) or "")
+end
+
+prefixes.relative = function(str,n)
+ if io.exists(str) then
+ -- nothing
+ elseif io.exists("./" .. str) then
+ str = "./" .. str
+ else
+ local p = "../"
+ for i=1,n or 2 do
+ if io.exists(p .. str) then
+ str = p .. str
+ break
+ else
+ p = p .. "../"
+ end
+ end
+ end
+ return resolvers.clean_path(str)
+end
+
+prefixes.locate = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path((fullname ~= "" and fullname) or str)
+end
+
+prefixes.filename = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.basename((fullname ~= "" and fullname) or str))
+end
+
+prefixes.pathname = function(str)
+ local fullname = resolvers.find_given_file(str) or ""
+ return resolvers.clean_path(file.dirname((fullname ~= "" and fullname) or str))
+end
+
+prefixes.env = prefixes.environment
+prefixes.rel = prefixes.relative
+prefixes.loc = prefixes.locate
+prefixes.kpse = prefixes.locate
+prefixes.full = prefixes.locate
+prefixes.file = prefixes.filename
+prefixes.path = prefixes.pathname
+
+local function _resolve_(method,target)
+ if prefixes[method] then
+ return prefixes[method](target)
+ else
+ return method .. ":" .. target
+ end
+end
+
+local function resolve(str)
+ if type(str) == "table" then
+ for k, v in pairs(str) do -- ipairs
+ str[k] = resolve(v) or v
+ end
+ elseif str and str ~= "" then
+ str = gsub(str,"([a-z]+):([^ \"\']*)",_resolve_)
+ end
+ return str
+end
+
+resolvers.resolve = resolve
+
+if os.uname then
+
+ for k, v in pairs(os.uname()) do
+ if not prefixes[k] then
+ prefixes[k] = function() return v end
+ end
+ end
+
+end
diff --git a/tex/context/base/data-res.lua b/tex/context/base/data-res.lua
new file mode 100644
index 000000000..0981881a2
--- /dev/null
+++ b/tex/context/base/data-res.lua
@@ -0,0 +1,2029 @@
+if not modules then modules = { } end modules ['data-inp'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+ comment = "companion to luat-lib.tex",
+}
+
+-- After a few years using the code the large luat-inp.lua file
+-- has been split up a bit. In the process some functionality was
+-- dropped:
+--
+-- * support for reading lsr files
+-- * selective scanning (subtrees)
+-- * some public auxiliary functions were made private
+--
+-- TODO: os.getenv -> os.env[]
+-- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
+-- TODO: check escaping in find etc, too much, too slow
+
+-- This lib is multi-purpose and can be loaded again later on so that
+-- additional functionality becomes available. We will split thislogs.report("fileio",
+-- module in components once we're done with prototyping. This is the
+-- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
+-- something in this module one can best check with Taco or Hans first; there
+-- is some nasty trickery going on that relates to traditional kpse support.
+
+-- To be considered: hash key lowercase, first entry in table filename
+-- (any case), rest paths (so no need for optimization). Or maybe a
+-- separate table that matches lowercase names to mixed case when
+-- present. In that case the lower() cases can go away. I will do that
+-- only when we run into problems with names ... well ... Iwona-Regular.
+
+-- Beware, loading and saving is overloaded in luat-tmp!
+
+local format, gsub, find, lower, upper, match, gmatch = string.format, string.gsub, string.find, string.lower, string.upper, string.match, string.gmatch
+local concat, insert, sortedkeys = table.concat, table.insert, table.sortedkeys
+local next, type = next, type
+
+local trace_locating, trace_detail, trace_verbose = false, false, false
+
+trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
+trackers.register("resolvers.detail", function(v) trace_detail = v trackers.enable("resolvers.verbose,resolvers.detail") end)
+
+if not resolvers then
+ resolvers = {
+ suffixes = { },
+ formats = { },
+ dangerous = { },
+ suffixmap = { },
+ alternatives = { },
+ locators = { }, -- locate databases
+ hashers = { }, -- load databases
+ generators = { }, -- generate databases
+ }
+end
+
+local resolvers = resolvers
+
+resolvers.locators .notfound = { nil }
+resolvers.hashers .notfound = { nil }
+resolvers.generators.notfound = { nil }
+
+resolvers.cacheversion = '1.0.1'
+resolvers.cnfname = 'texmf.cnf'
+resolvers.luaname = 'texmfcnf.lua'
+resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
+
+local dummy_path_expr = "^!*unset/*$"
+
+local formats = resolvers.formats
+local suffixes = resolvers.suffixes
+local dangerous = resolvers.dangerous
+local suffixmap = resolvers.suffixmap
+local alternatives = resolvers.alternatives
+
+formats['afm'] = 'AFMFONTS' suffixes['afm'] = { 'afm' }
+formats['enc'] = 'ENCFONTS' suffixes['enc'] = { 'enc' }
+formats['fmt'] = 'TEXFORMATS' suffixes['fmt'] = { 'fmt' }
+formats['map'] = 'TEXFONTMAPS' suffixes['map'] = { 'map' }
+formats['mp'] = 'MPINPUTS' suffixes['mp'] = { 'mp' }
+formats['ocp'] = 'OCPINPUTS' suffixes['ocp'] = { 'ocp' }
+formats['ofm'] = 'OFMFONTS' suffixes['ofm'] = { 'ofm', 'tfm' }
+formats['otf'] = 'OPENTYPEFONTS' suffixes['otf'] = { 'otf' } -- 'ttf'
+formats['opl'] = 'OPLFONTS' suffixes['opl'] = { 'opl' }
+formats['otp'] = 'OTPINPUTS' suffixes['otp'] = { 'otp' }
+formats['ovf'] = 'OVFFONTS' suffixes['ovf'] = { 'ovf', 'vf' }
+formats['ovp'] = 'OVPFONTS' suffixes['ovp'] = { 'ovp' }
+formats['tex'] = 'TEXINPUTS' suffixes['tex'] = { 'tex' }
+formats['tfm'] = 'TFMFONTS' suffixes['tfm'] = { 'tfm' }
+formats['ttf'] = 'TTFONTS' suffixes['ttf'] = { 'ttf', 'ttc' }
+formats['pfb'] = 'T1FONTS' suffixes['pfb'] = { 'pfb', 'pfa' }
+formats['vf'] = 'VFFONTS' suffixes['vf'] = { 'vf' }
+
+formats['fea'] = 'FONTFEATURES' suffixes['fea'] = { 'fea' }
+formats['cid'] = 'FONTCIDMAPS' suffixes['cid'] = { 'cid', 'cidmap' }
+
+formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
+suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
+
+formats ['lua'] = 'LUAINPUTS' -- new
+suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
+
+-- backward compatible ones
+
+alternatives['map files'] = 'map'
+alternatives['enc files'] = 'enc'
+alternatives['cid files'] = 'cid'
+alternatives['fea files'] = 'fea'
+alternatives['opentype fonts'] = 'otf'
+alternatives['truetype fonts'] = 'ttf'
+alternatives['truetype collections'] = 'ttc'
+alternatives['type1 fonts'] = 'pfb'
+
+-- obscure ones
+
+formats ['misc fonts'] = ''
+suffixes['misc fonts'] = { }
+
+formats ['sfd'] = 'SFDFONTS'
+suffixes ['sfd'] = { 'sfd' }
+alternatives['subfont definition files'] = 'sfd'
+
+-- In practice we will work within one tds tree, but i want to keep
+-- the option open to build tools that look at multiple trees, which is
+-- why we keep the tree specific data in a table. We used to pass the
+-- instance but for practical pusposes we now avoid this and use a
+-- instance variable.
+
+-- here we catch a few new thingies (todo: add these paths to context.tmf)
+--
+-- FONTFEATURES = .;$TEXMF/fonts/fea//
+-- FONTCIDMAPS = .;$TEXMF/fonts/cid//
+
+-- we always have one instance active
+
+resolvers.instance = resolvers.instance or nil -- the current one (slow access)
+local instance = resolvers.instance or nil -- the current one (fast access)
+
+function resolvers.newinstance()
+
+ -- store once, freeze and faster (once reset we can best use
+ -- instance.environment) maybe better have a register suffix
+ -- function
+
+ for k, v in next, suffixes do
+ for i=1,#v do
+ local vi = v[i]
+ if vi then
+ suffixmap[vi] = k
+ end
+ end
+ end
+
+ -- because vf searching is somewhat dangerous, we want to prevent
+ -- too liberal searching esp because we do a lookup on the current
+ -- path anyway; only tex (or any) is safe
+
+ for k, v in next, formats do
+ dangerous[k] = true
+ end
+ dangerous.tex = nil
+
+ -- the instance
+
+ local newinstance = {
+ rootpath = '',
+ treepath = '',
+ progname = 'context',
+ engine = 'luatex',
+ format = '',
+ environment = { },
+ variables = { },
+ expansions = { },
+ files = { },
+ remap = { },
+ configuration = { },
+ setup = { },
+ order = { },
+ found = { },
+ foundintrees = { },
+ kpsevars = { },
+ hashes = { },
+ cnffiles = { },
+ luafiles = { },
+ lists = { },
+ remember = true,
+ diskcache = true,
+ renewcache = false,
+ scandisk = true,
+ cachepath = nil,
+ loaderror = false,
+ sortdata = false,
+ savelists = true,
+ cleanuppaths = true,
+ allresults = false,
+ pattern = nil, -- lists
+ data = { }, -- only for loading
+ force_suffixes = true,
+ fakepaths = { },
+ }
+
+ local ne = newinstance.environment
+
+ for k,v in next, os.env do
+ ne[k] = resolvers.bare_variable(v)
+ end
+
+ return newinstance
+
+end
+
+function resolvers.setinstance(someinstance)
+ instance = someinstance
+ resolvers.instance = someinstance
+ return someinstance
+end
+
+function resolvers.reset()
+ return resolvers.setinstance(resolvers.newinstance())
+end
+
+local function reset_hashes()
+ instance.lists = { }
+ instance.found = { }
+end
+
+local function check_configuration() -- not yet ok, no time for debugging now
+ local ie = instance.environment
+ local function fix(varname,default)
+ local proname = varname .. "." .. instance.progname or "crap"
+ local p, v = ie[proname], ie[varname]
+ if not ((p and p ~= "") or (v and v ~= "")) then
+ instance.variables[varname] = default -- or environment?
+ end
+ end
+ local name = os.name
+ if name == "windows" then
+ fix("OSFONTDIR", "c:/windows/fonts//")
+ elseif name == "macosx" then
+ fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
+ else
+ -- bad luck
+ end
+ fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
+ fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
+ fix("LUATEXLIBS" , ".;$TEXMF/luatex/lua//")
+end
+
+function resolvers.bare_variable(str) -- assumes str is a string
+ return (gsub(str,"\s*([\"\']?)(.+)%1\s*", "%2"))
+end
+
+function resolvers.settrace(n) -- no longer number but: 'locating' or 'detail'
+ if n then
+ trackers.disable("resolvers.*")
+ trackers.enable("resolvers."..n)
+ end
+end
+
+resolvers.settrace(os.getenv("MTX.resolvers.TRACE") or os.getenv("MTX_INPUT_TRACE"))
+
+function resolvers.osenv(key)
+ local ie = instance.environment
+ local value = ie[key]
+ if value == nil then
+ -- local e = os.getenv(key)
+ local e = os.env[key]
+ if e == nil then
+ -- value = "" -- false
+ else
+ value = resolvers.bare_variable(e)
+ end
+ ie[key] = value
+ end
+ return value or ""
+end
+
+function resolvers.env(key)
+ return instance.environment[key] or resolvers.osenv(key)
+end
+
+--
+
+local function expand_vars(lst) -- simple vars
+ local variables, env = instance.variables, resolvers.env
+ local function resolve(a)
+ return variables[a] or env(a)
+ end
+ for k=1,#lst do
+ lst[k] = gsub(lst[k],"%$([%a%d%_%-]+)",resolve)
+ end
+end
+
+local function expanded_var(var) -- simple vars
+ local function resolve(a)
+ return instance.variables[a] or resolvers.env(a)
+ end
+ return (gsub(var,"%$([%a%d%_%-]+)",resolve))
+end
+
+local function entry(entries,name)
+ if name and (name ~= "") then
+ name = gsub(name,'%$','')
+ local result = entries[name..'.'..instance.progname] or entries[name]
+ if result then
+ return result
+ else
+ result = resolvers.env(name)
+ if result then
+ instance.variables[name] = result
+ resolvers.expand_variables()
+ return instance.expansions[name] or ""
+ end
+ end
+ end
+ return ""
+end
+
+local function is_entry(entries,name)
+ if name and name ~= "" then
+ name = gsub(name,'%$','')
+ return (entries[name..'.'..instance.progname] or entries[name]) ~= nil
+ else
+ return false
+ end
+end
+
+-- {a,b,c,d}
+-- a,b,c/{p,q,r},d
+-- a,b,c/{p,q,r}/d/{x,y,z}//
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
+-- a{b,c}{d,e}f
+-- {a,b,c,d}
+-- {a,b,c/{p,q,r},d}
+-- {a,b,c/{p,q,r}/d/{x,y,z}//}
+-- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
+-- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
+-- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
+
+-- this one is better and faster, but it took me a while to realize
+-- that this kind of replacement is cleaner than messy parsing and
+-- fuzzy concatenating we can probably gain a bit with selectively
+-- applying lpeg, but experiments with lpeg parsing this proved not to
+-- work that well; the parsing is ok, but dealing with the resulting
+-- table is a pain because we need to work inside-out recursively
+
+local function splitpathexpr(str, t, validate)
+ -- no need for further optimization as it is only called a
+ -- few times, we can use lpeg for the sub; we could move
+ -- the local functions outside the body
+ t = t or { }
+ str = gsub(str,",}",",@}")
+ str = gsub(str,"{,","{@,")
+ -- str = "@" .. str .. "@"
+ local ok, done
+ local function do_first(a,b)
+ local t = { }
+ for s in gmatch(b,"[^,]+") do t[#t+1] = a .. s end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_second(a,b)
+ local t = { }
+ for s in gmatch(a,"[^,]+") do t[#t+1] = s .. b end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_both(a,b)
+ local t = { }
+ for sa in gmatch(a,"[^,]+") do
+ for sb in gmatch(b,"[^,]+") do
+ t[#t+1] = sa .. sb
+ end
+ end
+ return "{" .. concat(t,",") .. "}"
+ end
+ local function do_three(a,b,c)
+ return a .. b.. c
+ end
+ while true do
+ done = false
+ while true do
+ str, ok = gsub(str,"([^{},]+){([^{}]+)}",do_first)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}([^{},]+)",do_second)
+ if ok > 0 then done = true else break end
+ end
+ while true do
+ str, ok = gsub(str,"{([^{}]+)}{([^{}]+)}",do_both)
+ if ok > 0 then done = true else break end
+ end
+ str, ok = gsub(str,"({[^{}]*){([^{}]+)}([^{}]*})",do_three)
+ if ok > 0 then done = true end
+ if not done then break end
+ end
+ str = gsub(str,"[{}]", "")
+ str = gsub(str,"@","")
+ if validate then
+ for s in gmatch(str,"[^,]+") do
+ s = validate(s)
+ if s then t[#t+1] = s end
+ end
+ else
+ for s in gmatch(str,"[^,]+") do
+ t[#t+1] = s
+ end
+ end
+ return t
+end
+
+local function expanded_path_from_list(pathlist) -- maybe not a list, just a path
+ -- a previous version fed back into pathlist
+ local newlist, ok = { }, false
+ for k=1,#pathlist do
+ if find(pathlist[k],"[{}]") then
+ ok = true
+ break
+ end
+ end
+ if ok then
+ local function validate(s)
+ s = file.collapse_path(s)
+ return s ~= "" and not find(s,dummy_path_expr) and s
+ end
+ for k=1,#pathlist do
+ splitpathexpr(pathlist[k],newlist,validate)
+ end
+ else
+ for k=1,#pathlist do
+ for p in gmatch(pathlist[k],"([^,]+)") do
+ p = file.collapse_path(p)
+ if p ~= "" then newlist[#newlist+1] = p end
+ end
+ end
+ end
+ return newlist
+end
+
+-- we follow a rather traditional approach:
+--
+-- (1) texmf.cnf given in TEXMFCNF
+-- (2) texmf.cnf searched in default variable
+--
+-- also we now follow the stupid route: if not set then just assume *one*
+-- cnf file under texmf (i.e. distribution)
+
+resolvers.ownpath = resolvers.ownpath or nil
+resolvers.ownbin = resolvers.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
+resolvers.autoselfdir = true -- false may be handy for debugging
+
+function resolvers.getownpath()
+ if not resolvers.ownpath then
+ if resolvers.autoselfdir and os.selfdir then
+ resolvers.ownpath = os.selfdir
+ else
+ local binary = resolvers.ownbin
+ if os.platform == "windows" then
+ binary = file.replacesuffix(binary,"exe")
+ end
+ for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
+ local b = file.join(p,binary)
+ if lfs.isfile(b) then
+ -- we assume that after changing to the path the currentdir function
+ -- resolves to the real location and use this side effect here; this
+ -- trick is needed because on the mac installations use symlinks in the
+ -- path instead of real locations
+ local olddir = lfs.currentdir()
+ if lfs.chdir(p) then
+ local pp = lfs.currentdir()
+ if trace_verbose and p ~= pp then
+ logs.report("fileio","following symlink %s to %s",p,pp)
+ end
+ resolvers.ownpath = pp
+ lfs.chdir(olddir)
+ else
+ if trace_verbose then
+ logs.report("fileio","unable to check path %s",p)
+ end
+ resolvers.ownpath = p
+ end
+ break
+ end
+ end
+ end
+ if not resolvers.ownpath then resolvers.ownpath = '.' end
+ end
+ return resolvers.ownpath
+end
+
+local own_places = { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF" }
+
+local function identify_own()
+ local ownpath = resolvers.getownpath() or lfs.currentdir()
+ local ie = instance.environment
+ if ownpath then
+ if resolvers.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
+ if resolvers.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
+ if resolvers.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
+ else
+ logs.report("fileio","error: unable to locate ownpath")
+ os.exit()
+ end
+ if resolvers.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = resolvers.cnfdefault end
+ if resolvers.env('TEXOS') == "" then os.env['TEXOS'] = resolvers.env('SELFAUTODIR') end
+ if resolvers.env('TEXROOT') == "" then os.env['TEXROOT'] = resolvers.env('SELFAUTOPARENT') end
+ if trace_verbose then
+ for i=1,#own_places do
+ local v = own_places[i]
+ logs.report("fileio","variable %s set to %s",v,resolvers.env(v) or "unknown")
+ end
+ end
+ identify_own = function() end
+end
+
+function resolvers.identify_cnf()
+ if #instance.cnffiles == 0 then
+ -- fallback
+ identify_own()
+ -- the real search
+ resolvers.expand_variables()
+ local t = resolvers.split_path(resolvers.env('TEXMFCNF'))
+ t = expanded_path_from_list(t)
+ expand_vars(t) -- redundant
+ local function locate(filename,list)
+ for i=1,#t do
+ local ti = t[i]
+ local texmfcnf = file.collapse_path(file.join(ti,filename))
+ if lfs.isfile(texmfcnf) then
+ list[#list+1] = texmfcnf
+ end
+ end
+ end
+ locate(resolvers.luaname,instance.luafiles)
+ locate(resolvers.cnfname,instance.cnffiles)
+ end
+end
+
+local function load_cnf_file(fname)
+ fname = resolvers.clean_path(fname)
+ local lname = file.replacesuffix(fname,'lua')
+ local f = io.open(lname)
+ if f then -- this will go
+ f:close()
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ resolvers.load_data(dname,'configuration',lname and file.basename(lname))
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ else
+ f = io.open(fname)
+ if f then
+ if trace_verbose then
+ logs.report("fileio","loading %s", fname)
+ end
+ local line, data, n, k, v
+ local dname = file.dirname(fname)
+ if not instance.configuration[dname] then
+ instance.configuration[dname] = { }
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ end
+ local data = instance.configuration[dname]
+ while true do
+ local line, n = f:read(), 0
+ if line then
+ while true do -- join lines
+ line, n = gsub(line,"\\%s*$", "")
+ if n > 0 then
+ line = line .. f:read()
+ else
+ break
+ end
+ end
+ if not find(line,"^[%%#]") then
+ local l = gsub(line,"%s*%%.*$","")
+ local k, v = match(l,"%s*(.-)%s*=%s*(.-)%s*$")
+ if k and v and not data[k] then
+ v = gsub(v,"[%%#].*",'')
+ data[k] = gsub(v,"~","$HOME")
+ instance.kpsevars[k] = true
+ end
+ end
+ else
+ break
+ end
+ end
+ f:close()
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s", fname)
+ end
+ end
+end
+
+local function collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
+ for _,c in ipairs(instance.order) do
+ for k,v in next, c do
+ if not instance.variables[k] then
+ if instance.environment[k] then
+ instance.variables[k] = instance.environment[k]
+ else
+ instance.kpsevars[k] = true
+ instance.variables[k] = resolvers.bare_variable(v)
+ end
+ end
+ end
+ end
+end
+
+function resolvers.load_cnf()
+ local function loadoldconfigdata()
+ for _, fname in ipairs(instance.cnffiles) do
+ load_cnf_file(fname)
+ end
+ end
+ -- instance.cnffiles contain complete names now !
+ if #instance.cnffiles == 0 then
+ if trace_verbose then
+ logs.report("fileio","no cnf files found (TEXMFCNF may not be set/known)")
+ end
+ else
+ instance.rootpath = instance.cnffiles[1]
+ for k,fname in ipairs(instance.cnffiles) do
+ instance.cnffiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadoldconfig(instance.cnffiles)
+ if instance.loaderror then
+ loadoldconfigdata()
+ resolvers.saveoldconfig()
+ end
+ else
+ loadoldconfigdata()
+ if instance.renewcache then
+ resolvers.saveoldconfig()
+ end
+ end
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+function resolvers.load_lua()
+ if #instance.luafiles == 0 then
+ -- yet harmless
+ else
+ instance.rootpath = instance.luafiles[1]
+ for k,fname in ipairs(instance.luafiles) do
+ instance.luafiles[k] = file.collapse_path(gsub(fname,"\\",'/'))
+ end
+ for i=1,3 do
+ instance.rootpath = file.dirname(instance.rootpath)
+ end
+ instance.rootpath = file.collapse_path(instance.rootpath)
+ resolvers.loadnewconfig()
+ collapse_cnf_data()
+ end
+ check_configuration()
+end
+
+-- database loading
+
+function resolvers.load_hash()
+ resolvers.locatelists()
+ if instance.diskcache and not instance.renewcache then
+ resolvers.loadfiles()
+ if instance.loaderror then
+ resolvers.loadlists()
+ resolvers.savefiles()
+ end
+ else
+ resolvers.loadlists()
+ if instance.renewcache then
+ resolvers.savefiles()
+ end
+ end
+end
+
+function resolvers.append_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash append: %s",tag)
+ end
+ insert(instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.prepend_hash(type,tag,name)
+ if trace_locating then
+ logs.report("fileio","= hash prepend: %s",tag)
+ end
+ insert(instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
+end
+
+function resolvers.extend_texmf_var(specification) -- crap, we could better prepend the hash
+-- local t = resolvers.expanded_path_list('TEXMF') -- full expansion
+ local t = resolvers.split_path(resolvers.env('TEXMF'))
+ insert(t,1,specification)
+ local newspec = concat(t,";")
+ if instance.environment["TEXMF"] then
+ instance.environment["TEXMF"] = newspec
+ elseif instance.variables["TEXMF"] then
+ instance.variables["TEXMF"] = newspec
+ else
+ -- weird
+ end
+ resolvers.expand_variables()
+ reset_hashes()
+end
+
+-- locators
+
+function resolvers.locatelists()
+ for _, path in ipairs(resolvers.clean_path_list('TEXMF')) do
+ if trace_verbose then
+ logs.report("fileio","locating list of %s",path)
+ end
+ resolvers.locatedatabase(file.collapse_path(path))
+ end
+end
+
+function resolvers.locatedatabase(specification)
+ return resolvers.methodhandler('locators', specification)
+end
+
+function resolvers.locators.tex(specification)
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ if trace_locating then
+ logs.report("fileio",'! tex locator found: %s',specification)
+ end
+ resolvers.append_hash('file',specification,filename)
+ elseif trace_locating then
+ logs.report("fileio",'? tex locator not found: %s',specification)
+ end
+end
+
+-- hashers
+
+function resolvers.hashdatabase(tag,name)
+ return resolvers.methodhandler('hashers',tag,name)
+end
+
+function resolvers.loadfiles()
+ instance.loaderror = false
+ instance.files = { }
+ if not instance.renewcache then
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.hashdatabase(hash.tag,hash.name)
+ if instance.loaderror then break end
+ end
+ end
+end
+
+function resolvers.hashers.tex(tag,name)
+ resolvers.load_data(tag,'files')
+end
+
+-- generators:
+
+function resolvers.loadlists()
+ for _, hash in ipairs(instance.hashes) do
+ resolvers.generatedatabase(hash.tag)
+ end
+end
+
+function resolvers.generatedatabase(specification)
+ return resolvers.methodhandler('generators', specification)
+end
+
+-- starting with . or .. etc or funny char
+
+local weird = lpeg.P(".")^1 + lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
+
+function resolvers.generators.tex(specification)
+ local tag = specification
+ if trace_verbose then
+ logs.report("fileio","scanning path %s",specification)
+ end
+ instance.files[tag] = { }
+ local files = instance.files[tag]
+ local n, m, r = 0, 0, 0
+ local spec = specification .. '/'
+ local attributes = lfs.attributes
+ local directory = lfs.dir
+ local function action(path)
+ local full
+ if path then
+ full = spec .. path .. '/'
+ else
+ full = spec
+ end
+ for name in directory(full) do
+ if not weird:match(name) then
+ local mode = attributes(full..name,'mode')
+ if mode == 'file' then
+ if path then
+ n = n + 1
+ local f = files[name]
+ if f then
+ if type(f) == 'string' then
+ files[name] = { f, path }
+ else
+ f[#f+1] = path
+ end
+ else -- probably unique anyway
+ files[name] = path
+ local lower = lower(name)
+ if name ~= lower then
+ files["remap:"..lower] = name
+ r = r + 1
+ end
+ end
+ end
+ elseif mode == 'directory' then
+ m = m + 1
+ if path then
+ action(path..'/'..name)
+ else
+ action(name)
+ end
+ end
+ end
+ end
+ end
+ action()
+ if trace_verbose then
+ logs.report("fileio","%s files found on %s directories with %s uppercase remappings",n,m,r)
+ end
+end
+
+-- savers, todo
+
+function resolvers.savefiles()
+ resolvers.save_data('files')
+end
+
+-- A config (optionally) has the paths split in tables. Internally
+-- we join them and split them after the expansion has taken place. This
+-- is more convenient.
+
+function resolvers.splitconfig()
+ for i,c in ipairs(instance) do
+ for k,v in pairs(c) do
+ if type(v) == 'string' then
+ local t = file.split_path(v)
+ if #t > 1 then
+ c[k] = t
+ end
+ end
+ end
+ end
+end
+
+function resolvers.joinconfig()
+ for i,c in ipairs(instance.order) do
+ for k,v in pairs(c) do -- ipairs?
+ if type(v) == 'table' then
+ c[k] = file.join_path(v)
+ end
+ end
+ end
+end
+function resolvers.split_path(str)
+ if type(str) == 'table' then
+ return str
+ else
+ return file.split_path(str)
+ end
+end
+function resolvers.join_path(str)
+ if type(str) == 'table' then
+ return file.join_path(str)
+ else
+ return str
+ end
+end
+
+function resolvers.splitexpansions()
+ local ie = instance.expansions
+ for k,v in next, ie do
+ local t, h = { }, { }
+ for _,vv in ipairs(file.split_path(v)) do
+ if vv ~= "" and not h[vv] then
+ t[#t+1] = vv
+ h[vv] = true
+ end
+ end
+ if #t > 1 then
+ ie[k] = t
+ else
+ ie[k] = t[1]
+ end
+ end
+end
+
+-- end of split/join code
+
+function resolvers.saveoldconfig()
+ resolvers.splitconfig()
+ resolvers.save_data('configuration')
+ resolvers.joinconfig()
+end
+
+resolvers.configbanner = [[
+-- This is a Luatex configuration file created by 'luatools.lua' or
+-- 'luatex.exe' directly. For comment, suggestions and questions you can
+-- contact the ConTeXt Development Team. This configuration file is
+-- not copyrighted. [HH & TH]
+]]
+
+function resolvers.serialize(files)
+ -- This version is somewhat optimized for the kind of
+ -- tables that we deal with, so it's much faster than
+ -- the generic serializer. This makes sense because
+ -- luatools and mtxtools are called frequently. Okay,
+ -- we pay a small price for properly tabbed tables.
+ local t = { }
+ local function dump(k,v,m) -- could be moved inline
+ if type(v) == 'string' then
+ return m .. "['" .. k .. "']='" .. v .. "',"
+ elseif #v == 1 then
+ return m .. "['" .. k .. "']='" .. v[1] .. "',"
+ else
+ return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
+ end
+ end
+ t[#t+1] = "return {"
+ if instance.sortdata then
+ for _, k in pairs(sortedkeys(files)) do -- ipairs
+ local fk = files[k]
+ if type(fk) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for _, kk in pairs(sortedkeys(fk)) do -- ipairs
+ t[#t+1] = dump(kk,fk[kk],"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,fk,"\t")
+ end
+ end
+ else
+ for k, v in next, files do
+ if type(v) == 'table' then
+ t[#t+1] = "\t['" .. k .. "']={"
+ for kk,vv in next, v do
+ t[#t+1] = dump(kk,vv,"\t\t")
+ end
+ t[#t+1] = "\t},"
+ else
+ t[#t+1] = dump(k,v,"\t")
+ end
+ end
+ end
+ t[#t+1] = "}"
+ return concat(t,"\n")
+end
+
+function resolvers.save_data(dataname, makename) -- untested without cache overload
+ for cachename, files in next, instance[dataname] do
+ local name = (makename or file.join)(cachename,dataname)
+ local luaname, lucname = name .. ".lua", name .. ".luc"
+ if trace_verbose then
+ logs.report("fileio","preparing %s for %s",dataname,cachename)
+ end
+ for k, v in next, files do
+ if type(v) == "table" and #v == 1 then
+ files[k] = v[1]
+ end
+ end
+ local data = {
+ type = dataname,
+ root = cachename,
+ version = resolvers.cacheversion,
+ date = os.date("%Y-%m-%d"),
+ time = os.date("%H:%M:%S"),
+ content = files,
+ }
+ local ok = io.savedata(luaname,resolvers.serialize(data))
+ if ok then
+ if trace_verbose then
+ logs.report("fileio","%s saved in %s",dataname,luaname)
+ end
+ if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
+ if trace_verbose then
+ logs.report("fileio","%s compiled to %s",dataname,lucname)
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","compiling failed for %s, deleting file %s",dataname,lucname)
+ end
+ os.remove(lucname)
+ end
+ elseif trace_verbose then
+ logs.report("fileio","unable to save %s in %s (access error)",dataname,luaname)
+ end
+ end
+end
+
+function resolvers.load_data(pathname,dataname,filename,makename) -- untested without cache overload
+ filename = ((not filename or (filename == "")) and dataname) or filename
+ filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
+ local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ if blob then
+ local data = blob()
+ if data and data.content and data.type == dataname and data.version == resolvers.cacheversion then
+ if trace_verbose then
+ logs.report("fileio","loading %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = data.content
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+ instance[dataname][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping %s for %s from %s",dataname,pathname,filename)
+ end
+end
+
+-- some day i'll use the nested approach, but not yet (actually we even drop
+-- engine/progname support since we have only luatex now)
+--
+-- first texmfcnf.lua files are located, next the cached texmf.cnf files
+--
+-- return {
+-- TEXMFBOGUS = 'effe checken of dit werkt',
+-- }
+
+function resolvers.resetconfig()
+ identify_own()
+ instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
+end
+
+function resolvers.loadnewconfig()
+ for _, cnf in ipairs(instance.luafiles) do
+ local pathname = file.dirname(cnf)
+ local filename = file.join(pathname,resolvers.luaname)
+ local blob = loadfile(filename)
+ if blob then
+ local data = blob()
+ if data then
+ if trace_verbose then
+ logs.report("fileio","loading configuration file %s",filename)
+ end
+ if true then
+ -- flatten to variable.progname
+ local t = { }
+ for k, v in next, data do -- v = progname
+ if type(v) == "string" then
+ t[k] = v
+ else
+ for kk, vv in next, v do -- vv = variable
+ if type(vv) == "string" then
+ t[vv.."."..v] = kk
+ end
+ end
+ end
+ end
+ instance['setup'][pathname] = t
+ else
+ instance['setup'][pathname] = data
+ end
+ else
+ if trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance['setup'][pathname] = { }
+ instance.loaderror = true
+ end
+ elseif trace_verbose then
+ logs.report("fileio","skipping configuration file %s",filename)
+ end
+ instance.order[#instance.order+1] = instance.setup[pathname]
+ if instance.loaderror then break end
+ end
+end
+
+function resolvers.loadoldconfig()
+ if not instance.renewcache then
+ for _, cnf in ipairs(instance.cnffiles) do
+ local dname = file.dirname(cnf)
+ resolvers.load_data(dname,'configuration')
+ instance.order[#instance.order+1] = instance.configuration[dname]
+ if instance.loaderror then break end
+ end
+ end
+ resolvers.joinconfig()
+end
+
+function resolvers.expand_variables()
+ local expansions, environment, variables = { }, instance.environment, instance.variables
+ local env = resolvers.env
+ instance.expansions = expansions
+ if instance.engine ~= "" then environment['engine'] = instance.engine end
+ if instance.progname ~= "" then environment['progname'] = instance.progname end
+ for k,v in next, environment do
+ local a, b = match(k,"^(%a+)%_(.*)%s*$")
+ if a and b then
+ expansions[a..'.'..b] = v
+ else
+ expansions[k] = v
+ end
+ end
+ for k,v in next, environment do -- move environment to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ for k,v in next, variables do -- move variables to expansions
+ if not expansions[k] then expansions[k] = v end
+ end
+ local busy = false
+ local function resolve(a)
+ busy = true
+ return expansions[a] or env(a)
+ end
+ while true do
+ busy = false
+ for k,v in next, expansions do
+ local s, n = gsub(v,"%$([%a%d%_%-]+)",resolve)
+ local s, m = gsub(s,"%$%{([%a%d%_%-]+)%}",resolve)
+ if n > 0 or m > 0 then
+ expansions[k]= s
+ end
+ end
+ if not busy then break end
+ end
+ for k,v in next, expansions do
+ expansions[k] = gsub(v,"\\", '/')
+ end
+end
+
+function resolvers.variable(name)
+ return entry(instance.variables,name)
+end
+
+function resolvers.expansion(name)
+ return entry(instance.expansions,name)
+end
+
+function resolvers.is_variable(name)
+ return is_entry(instance.variables,name)
+end
+
+function resolvers.is_expansion(name)
+ return is_entry(instance.expansions,name)
+end
+
+function resolvers.unexpanded_path_list(str)
+ local pth = resolvers.variable(str)
+ local lst = resolvers.split_path(pth)
+ return expanded_path_from_list(lst)
+end
+
+function resolvers.unexpanded_path(str)
+ return file.join_path(resolvers.unexpanded_path_list(str))
+end
+
+do -- no longer needed
+
+ local done = { }
+
+ function resolvers.reset_extra_path()
+ local ep = instance.extra_paths
+ if not ep then
+ ep, done = { }, { }
+ instance.extra_paths = ep
+ elseif #ep > 0 then
+ instance.lists, done = { }, { }
+ end
+ end
+
+ function resolvers.register_extra_path(paths,subpaths)
+ local ep = instance.extra_paths or { }
+ local n = #ep
+ if paths and paths ~= "" then
+ if subpaths and subpaths ~= "" then
+ for p in gmatch(paths,"[^,]+") do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = p .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ else
+ for p in gmatch(paths,"[^,]+") do
+ if not done[p] then
+ ep[#ep+1] = resolvers.clean_path(p)
+ done[p] = true
+ end
+ end
+ end
+ elseif subpaths and subpaths ~= "" then
+ for i=1,n do
+ -- we gmatch each step again, not that fast, but used seldom
+ for s in gmatch(subpaths,"[^,]+") do
+ local ps = ep[i] .. "/" .. s
+ if not done[ps] then
+ ep[#ep+1] = resolvers.clean_path(ps)
+ done[ps] = true
+ end
+ end
+ end
+ end
+ if #ep > 0 then
+ instance.extra_paths = ep -- register paths
+ end
+ if #ep > n then
+ instance.lists = { } -- erase the cache
+ end
+ end
+
+end
+
+local function made_list(instance,list)
+ local ep = instance.extra_paths
+ if not ep or #ep == 0 then
+ return list
+ else
+ local done, new = { }, { }
+ -- honour . .. ../.. but only when at the start
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ if find(v,"^[%.%/]$") then
+ done[v] = true
+ new[#new+1] = v
+ else
+ break
+ end
+ end
+ end
+ -- first the extra paths
+ for k=1,#ep do
+ local v = ep[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ -- next the formal paths
+ for k=1,#list do
+ local v = list[k]
+ if not done[v] then
+ done[v] = true
+ new[#new+1] = v
+ end
+ end
+ return new
+ end
+end
+
+function resolvers.clean_path_list(str)
+ local t = resolvers.expanded_path_list(str)
+ if t then
+ for i=1,#t do
+ t[i] = file.collapse_path(resolvers.clean_path(t[i]))
+ end
+ end
+ return t
+end
+
+function resolvers.expand_path(str)
+ return file.join_path(resolvers.expanded_path_list(str))
+end
+
+function resolvers.expanded_path_list(str)
+ if not str then
+ return ep or { }
+ elseif instance.savelists then
+ -- engine+progname hash
+ str = gsub(str,"%$","")
+ if not instance.lists[str] then -- cached
+ local lst = made_list(instance,resolvers.split_path(resolvers.expansion(str)))
+ instance.lists[str] = expanded_path_from_list(lst)
+ end
+ return instance.lists[str]
+ else
+ local lst = resolvers.split_path(resolvers.expansion(str))
+ return made_list(instance,expanded_path_from_list(lst))
+ end
+end
+
+function resolvers.expanded_path_list_from_var(str) -- brrr
+ local tmp = resolvers.var_of_format_or_suffix(gsub(str,"%$",""))
+ if tmp ~= "" then
+ return resolvers.expanded_path_list(str)
+ else
+ return resolvers.expanded_path_list(tmp)
+ end
+end
+
+function resolvers.expand_path_from_var(str)
+ return file.join_path(resolvers.expanded_path_list_from_var(str))
+end
+
+function resolvers.format_of_var(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+function resolvers.format_of_suffix(str)
+ return suffixmap[file.extname(str)] or 'tex'
+end
+
+function resolvers.variable_of_format(str)
+ return formats[str] or formats[alternatives[str]] or ''
+end
+
+function resolvers.var_of_format_or_suffix(str)
+ local v = formats[str]
+ if v then
+ return v
+ end
+ v = formats[alternatives[str]]
+ if v then
+ return v
+ end
+ v = suffixmap[file.extname(str)]
+ if v then
+ return formats[isf]
+ end
+ return ''
+end
+
+function resolvers.expand_braces(str) -- output variable and brace expansion of STRING
+ local ori = resolvers.variable(str)
+ local pth = expanded_path_from_list(resolvers.split_path(ori))
+ return file.join_path(pth)
+end
+
+resolvers.isreadable = { }
+
+function resolvers.isreadable.file(name)
+ local readable = lfs.isfile(name) -- brrr
+ if trace_detail then
+ if readable then
+ logs.report("fileio","+ readable: %s",name)
+ else
+ logs.report("fileio","- readable: %s", name)
+ end
+ end
+ return readable
+end
+
+resolvers.isreadable.tex = resolvers.isreadable.file
+
+-- name
+-- name/name
+
+local function collect_files(names)
+ local filelist = { }
+ for k=1,#names do
+ local fname = names[k]
+ if trace_detail then
+ logs.report("fileio","? blobpath asked: %s",fname)
+ end
+ local bname = file.basename(fname)
+ local dname = file.dirname(fname)
+ if dname == "" or find(dname,"^%.") then
+ dname = false
+ else
+ dname = "/" .. dname .. "$"
+ end
+ local hashes = instance.hashes
+ for h=1,#hashes do
+ local hash = hashes[h]
+ local blobpath = hash.tag
+ local files = blobpath and instance.files[blobpath]
+ if files then
+ if trace_detail then
+ logs.report("fileio",'? blobpath do: %s (%s)',blobpath,bname)
+ end
+ local blobfile = files[bname]
+ if not blobfile then
+ local rname = "remap:"..bname
+ blobfile = files[rname]
+ if blobfile then
+ bname = files[rname]
+ blobfile = files[bname]
+ end
+ end
+ if blobfile then
+ if type(blobfile) == 'string' then
+ if not dname or find(blobfile,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,blobfile,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,blobfile,bname) -- result
+ }
+ end
+ else
+ for kk=1,#blobfile do
+ local vv = blobfile[kk]
+ if not dname or find(vv,dname) then
+ filelist[#filelist+1] = {
+ hash.type,
+ file.join(blobpath,vv,bname), -- search
+ resolvers.concatinators[hash.type](blobpath,vv,bname) -- result
+ }
+ end
+ end
+ end
+ end
+ elseif trace_locating then
+ logs.report("fileio",'! blobpath no: %s (%s)',blobpath,bname)
+ end
+ end
+ end
+ if #filelist > 0 then
+ return filelist
+ else
+ return nil
+ end
+end
+
+function resolvers.suffix_of_format(str)
+ if suffixes[str] then
+ return suffixes[str][1]
+ else
+ return ""
+ end
+end
+
+function resolvers.suffixes_of_format(str)
+ if suffixes[str] then
+ return suffixes[str]
+ else
+ return {}
+ end
+end
+
+function resolvers.register_in_trees(name)
+ if not find(name,"^%.") then
+ instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
+ end
+end
+
+-- split the next one up for readability (bu this module needs a cleanup anyway)
+
+local function can_be_dir(name) -- can become local
+ local fakepaths = instance.fakepaths
+ if not fakepaths[name] then
+ if lfs.isdir(name) then
+ fakepaths[name] = 1 -- directory
+ else
+ fakepaths[name] = 2 -- no directory
+ end
+ end
+ return (fakepaths[name] == 1)
+end
+
+local function collect_instance_files(filename,collected) -- todo : plugin (scanners, checkers etc)
+ local result = collected or { }
+ local stamp = nil
+ filename = file.collapse_path(filename) -- elsewhere
+ filename = file.collapse_path(gsub(filename,"\\","/")) -- elsewhere
+ -- speed up / beware: format problem
+ if instance.remember then
+ stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
+ if instance.found[stamp] then
+ if trace_locating then
+ logs.report("fileio",'! remembered: %s',filename)
+ end
+ return instance.found[stamp]
+ end
+ end
+ if not dangerous[instance.format or "?"] then
+ if resolvers.isreadable.file(filename) then
+ if trace_detail then
+ logs.report("fileio",'= found directly: %s',filename)
+ end
+ instance.found[stamp] = { filename }
+ return { filename }
+ end
+ end
+ if find(filename,'%*') then
+ if trace_locating then
+ logs.report("fileio",'! wildcard: %s', filename)
+ end
+ result = resolvers.find_wildcard_files(filename)
+ elseif file.is_qualified_path(filename) then
+ if resolvers.isreadable.file(filename) then
+ if trace_locating then
+ logs.report("fileio",'! qualified: %s', filename)
+ end
+ result = { filename }
+ else
+ local forcedname, ok, suffix = "", false, file.extname(filename)
+ if suffix == "" then -- why
+ if instance.format == "" then
+ forcedname = filename .. ".tex"
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing standard filetype: tex')
+ end
+ result, ok = { forcedname }, true
+ end
+ else
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ forcedname = filename .. "." .. s
+ if resolvers.isreadable.file(forcedname) then
+ if trace_locating then
+ logs.report("fileio",'! no suffix, forcing format filetype: %s', s)
+ end
+ result, ok = { forcedname }, true
+ break
+ end
+ end
+ end
+ end
+ if not ok and suffix ~= "" then
+ -- try to find in tree (no suffix manipulation), here we search for the
+ -- matching last part of the name
+ local basename = file.basename(filename)
+ local pattern = (filename .. "$"):gsub("([%.%-])","%%%1")
+ local savedformat = instance.format
+ local format = savedformat or ""
+ if format == "" then
+ instance.format = resolvers.format_of_suffix(suffix)
+ end
+ if not format then
+ instance.format = "othertextfiles" -- kind of everything, maybe texinput is better
+ end
+ --
+ local resolved = collect_instance_files(basename)
+ if #result == 0 then
+ local lowered = lower(basename)
+ if filename ~= lowered then
+ resolved = collect_instance_files(lowered)
+ end
+ end
+ resolvers.format = savedformat
+ --
+ for r=1,#resolved do
+ local rr = resolved[r]
+ if rr:find(pattern) then
+ result[#result+1], ok = rr, true
+ end
+ end
+ -- a real wildcard:
+ --
+ -- if not ok then
+ -- local filelist = collect_files({basename})
+ -- for f=1,#filelist do
+ -- local ff = filelist[f][3] or ""
+ -- if ff:find(pattern) then
+ -- result[#result+1], ok = ff, true
+ -- end
+ -- end
+ -- end
+ end
+ if not ok and trace_locating then
+ logs.report("fileio",'? qualified: %s', filename)
+ end
+ end
+ else
+ -- search spec
+ local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
+ if ext == "" then
+ if not instance.force_suffixes then
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ else
+ wantedfiles[#wantedfiles+1] = filename
+ end
+ if instance.format == "" then
+ if ext == "" then
+ local forcedname = filename .. '.tex'
+ wantedfiles[#wantedfiles+1] = forcedname
+ filetype = resolvers.format_of_suffix(forcedname)
+ if trace_locating then
+ logs.report("fileio",'! forcing filetype: %s',filetype)
+ end
+ else
+ filetype = resolvers.format_of_suffix(filename)
+ if trace_locating then
+ logs.report("fileio",'! using suffix based filetype: %s',filetype)
+ end
+ end
+ else
+ if ext == "" then
+ local suffixes = resolvers.suffixes_of_format(instance.format)
+ for _, s in next, suffixes do
+ wantedfiles[#wantedfiles+1] = filename .. "." .. s
+ end
+ end
+ filetype = instance.format
+ if trace_locating then
+ logs.report("fileio",'! using given filetype: %s',filetype)
+ end
+ end
+ local typespec = resolvers.variable_of_format(filetype)
+ local pathlist = resolvers.expanded_path_list(typespec)
+ if not pathlist or #pathlist == 0 then
+ -- no pathlist, access check only / todo == wildcard
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ logs.report("fileio",'? filetype: %s',filetype or '?')
+ logs.report("fileio",'? wanted files: %s',concat(wantedfiles," | "))
+ end
+ for k=1,#wantedfiles do
+ local fname = wantedfiles[k]
+ if fname and resolvers.isreadable.file(fname) then
+ filename, done = fname, true
+ result[#result+1] = file.join('.',fname)
+ break
+ end
+ end
+ -- this is actually 'other text files' or 'any' or 'whatever'
+ local filelist = collect_files(wantedfiles)
+ local fl = filelist and filelist[1]
+ if fl then
+ filename = fl[3]
+ result[#result+1] = filename
+ done = true
+ end
+ else
+ -- list search
+ local filelist = collect_files(wantedfiles)
+ local doscan, recurse
+ if trace_detail then
+ logs.report("fileio",'? filename: %s',filename)
+ end
+ -- a bit messy ... esp the doscan setting here
+ for k=1,#pathlist do
+ local path = pathlist[k]
+ if find(path,"^!!") then doscan = false else doscan = true end
+ if find(path,"//$") then recurse = true else recurse = false end
+ local pathname = gsub(path,"^!+", '')
+ done = false
+ -- using file list
+ if filelist and not (done and not instance.allresults) and recurse then
+ -- compare list entries with permitted pattern
+ pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
+ pathname = gsub(pathname,"/+$", '/.*') -- later usage of pathname
+ pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
+ local expr = "^" .. pathname
+ for k=1,#filelist do
+ local fl = filelist[k]
+ local f = fl[2]
+ if find(f,expr) then
+ if trace_detail then
+ logs.report("fileio",'= found in hash: %s',f)
+ end
+ --- todo, test for readable
+ result[#result+1] = fl[3]
+ resolvers.register_in_trees(f) -- for tracing used files
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ end
+ if not done and doscan then
+ -- check if on disk / unchecked / does not work at all / also zips
+ if resolvers.splitmethod(pathname).scheme == 'file' then -- ?
+ local pname = gsub(pathname,"%.%*$",'')
+ if not find(pname,"%*") then
+ local ppname = gsub(pname,"/+$","")
+ if can_be_dir(ppname) then
+ for k=1,#wantedfiles do
+ local w = wantedfiles[k]
+ local fname = file.join(ppname,w)
+ if resolvers.isreadable.file(fname) then
+ if trace_detail then
+ logs.report("fileio",'= found by scanning: %s',fname)
+ end
+ result[#result+1] = fname
+ done = true
+ if not instance.allresults then break end
+ end
+ end
+ else
+ -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
+ end
+ end
+ end
+ end
+ if not done and doscan then
+ -- todo: slow path scanning
+ end
+ if done and not instance.allresults then break end
+ end
+ end
+ end
+ for k=1,#result do
+ result[k] = file.collapse_path(result[k])
+ end
+ if instance.remember then
+ instance.found[stamp] = result
+ end
+ return result
+end
+
+if not resolvers.concatinators then resolvers.concatinators = { } end
+
+resolvers.concatinators.tex = file.join
+resolvers.concatinators.file = resolvers.concatinators.tex
+
+function resolvers.find_files(filename,filetype,mustexist)
+ if type(mustexist) == boolean then
+ -- all set
+ elseif type(filetype) == 'boolean' then
+ filetype, mustexist = nil, false
+ elseif type(filetype) ~= 'string' then
+ filetype, mustexist = nil, false
+ end
+ instance.format = filetype or ''
+ local result = collect_instance_files(filename)
+ if #result == 0 then
+ local lowered = lower(filename)
+ if filename ~= lowered then
+ return collect_instance_files(lowered)
+ end
+ end
+ instance.format = ''
+ return result
+end
+
+function resolvers.find_file(filename,filetype,mustexist)
+ return (resolvers.find_files(filename,filetype,mustexist)[1] or "")
+end
+
+function resolvers.find_given_files(filename)
+ local bname, result = file.basename(filename), { }
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local files = instance.files[hash.tag]
+ local blist = files[bname]
+ if not blist then
+ local rname = "remap:"..bname
+ blist = files[rname]
+ if blist then
+ bname = files[rname]
+ blist = files[bname]
+ end
+ end
+ if blist then
+ if type(blist) == 'string' then
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,blist,bname) or ""
+ if not instance.allresults then break end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ result[#result+1] = resolvers.concatinators[hash.type](hash.tag,vv,bname) or ""
+ if not instance.allresults then break end
+ end
+ end
+ end
+ end
+ return result
+end
+
+function resolvers.find_given_file(filename)
+ return (resolvers.find_given_files(filename)[1] or "")
+end
+
+local function doit(path,blist,bname,tag,kind,result,allresults)
+ local done = false
+ if blist and kind then
+ if type(blist) == 'string' then
+ -- make function and share code
+ if find(lower(blist),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,blist,bname) or ""
+ done = true
+ end
+ else
+ for kk=1,#blist do
+ local vv = blist[kk]
+ if find(lower(vv),path) then
+ result[#result+1] = resolvers.concatinators[kind](tag,vv,bname) or ""
+ done = true
+ if not allresults then break end
+ end
+ end
+ end
+ end
+ return done
+end
+
+function resolvers.find_wildcard_files(filename) -- todo: remap:
+ local result = { }
+ local bname, dname = file.basename(filename), file.dirname(filename)
+ local path = gsub(dname,"^*/","")
+ path = gsub(path,"*",".*")
+ path = gsub(path,"-","%%-")
+ if dname == "" then
+ path = ".*"
+ end
+ local name = bname
+ name = gsub(name,"*",".*")
+ name = gsub(name,"-","%%-")
+ path = lower(path)
+ name = lower(name)
+ local files, allresults, done = instance.files, instance.allresults, false
+ if find(name,"%*") then
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ for kk, hh in next, files[hash.tag] do
+ if not find(kk,"^remap:") then
+ if find(lower(kk),name) then
+ if doit(path,hh,kk,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ end
+ end
+ else
+ local hashes = instance.hashes
+ for k=1,#hashes do
+ local hash = hashes[k]
+ local tag, kind = hash.tag, hash.type
+ if doit(path,files[tag][bname],bname,tag,kind,result,allresults) then done = true end
+ if done and not allresults then break end
+ end
+ end
+ -- we can consider also searching the paths not in the database, but then
+ -- we end up with a messy search (all // in all path specs)
+ return result
+end
+
+function resolvers.find_wildcard_file(filename)
+ return (resolvers.find_wildcard_files(filename)[1] or "")
+end
+
+-- main user functions
+
+function resolvers.automount()
+ -- implemented later
+end
+
+function resolvers.load(option)
+ statistics.starttiming(instance)
+ resolvers.resetconfig()
+ resolvers.identify_cnf()
+ resolvers.load_lua()
+ resolvers.expand_variables()
+ resolvers.load_cnf()
+ resolvers.expand_variables()
+ if option ~= "nofiles" then
+ resolvers.load_hash()
+ resolvers.automount()
+ end
+ statistics.stoptiming(instance)
+end
+
+function resolvers.for_files(command, files, filetype, mustexist)
+ if files and #files > 0 then
+ local function report(str)
+ if trace_verbose then
+ logs.report("fileio",str) -- has already verbose
+ else
+ print(str)
+ end
+ end
+ if trace_verbose then
+ report('')
+ end
+ for _, file in ipairs(files) do
+ local result = command(file,filetype,mustexist)
+ if type(result) == 'string' then
+ report(result)
+ else
+ for _,v in ipairs(result) do
+ report(v)
+ end
+ end
+ end
+ end
+end
+
+-- strtab
+
+resolvers.var_value = resolvers.variable -- output the value of variable $STRING.
+resolvers.expand_var = resolvers.expansion -- output variable expansion of STRING.
+
+function resolvers.show_path(str) -- output search path for file type NAME
+ return file.join_path(resolvers.expanded_path_list(resolvers.format_of_var(str)))
+end
+
+-- resolvers.find_file(filename)
+-- resolvers.find_file(filename, filetype, mustexist)
+-- resolvers.find_file(filename, mustexist)
+-- resolvers.find_file(filename, filetype)
+
+function resolvers.register_file(files, name, path)
+ if files[name] then
+ if type(files[name]) == 'string' then
+ files[name] = { files[name], path }
+ else
+ files[name] = path
+ end
+ else
+ files[name] = path
+ end
+end
+
+function resolvers.splitmethod(filename)
+ if not filename then
+ return { } -- safeguard
+ elseif type(filename) == "table" then
+ return filename -- already split
+ elseif not find(filename,"://") then
+ return { scheme="file", path = filename, original=filename } -- quick hack
+ else
+ return url.hashed(filename)
+ end
+end
+
+function table.sequenced(t,sep) -- temp here
+ local s = { }
+ for k, v in pairs(t) do -- pairs?
+ s[#s+1] = k .. "=" .. v
+ end
+ return concat(s, sep or " | ")
+end
+
+function resolvers.methodhandler(what, filename, filetype) -- ...
+ local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
+ local scheme = specification.scheme
+ if resolvers[what][scheme] then
+ if trace_locating then
+ logs.report("fileio",'= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
+ end
+ return resolvers[what][scheme](filename,filetype) -- todo: specification
+ else
+ return resolvers[what].tex(filename,filetype) -- todo: specification
+ end
+end
+
+function resolvers.clean_path(str)
+ if str then
+ str = gsub(str,"\\","/")
+ str = gsub(str,"^!+","")
+ str = gsub(str,"^~",resolvers.homedir)
+ return str
+ else
+ return nil
+ end
+end
+
+function resolvers.do_with_path(name,func)
+ for _, v in pairs(resolvers.expanded_path_list(name)) do -- pairs?
+ func("^"..resolvers.clean_path(v))
+ end
+end
+
+function resolvers.do_with_var(name,func)
+ func(expanded_var(name))
+end
+
+function resolvers.with_files(pattern,handle)
+ for _, hash in ipairs(instance.hashes) do
+ local blobpath = hash.tag
+ local blobtype = hash.type
+ if blobpath then
+ local files = instance.files[blobpath]
+ if files then
+ for k,v in next, files do
+ if find(k,"^remap:") then
+ k = files[k]
+ v = files[k] -- chained
+ end
+ if find(k,pattern) then
+ if type(v) == "string" then
+ handle(blobtype,blobpath,v,k)
+ else
+ for _,vv in pairs(v) do -- ipairs?
+ handle(blobtype,blobpath,vv,k)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function resolvers.locate_format(name)
+ local barename, fmtname = name:gsub("%.%a+$",""), ""
+ if resolvers.usecache then
+ local path = file.join(caches.setpath("formats")) -- maybe platform
+ fmtname = file.join(path,barename..".fmt") or ""
+ end
+ if fmtname == "" then
+ fmtname = resolvers.find_files(barename..".fmt")[1] or ""
+ end
+ fmtname = resolvers.clean_path(fmtname)
+ if fmtname ~= "" then
+ local barename = file.removesuffix(fmtname)
+ local luaname, lucname, luiname = barename .. ".lua", barename .. ".luc", barename .. ".lui"
+ if lfs.isfile(luiname) then
+ return barename, luiname
+ elseif lfs.isfile(lucname) then
+ return barename, lucname
+ elseif lfs.isfile(luaname) then
+ return barename, luaname
+ end
+ end
+ return nil, nil
+end
+
+function resolvers.boolean_variable(str,default)
+ local b = resolvers.expansion(str)
+ if b == "" then
+ return default
+ else
+ b = toboolean(b)
+ return (b == nil and default) or b
+ end
+end
+
+texconfig.kpse_init = false
+
+kpse = { original = kpse } setmetatable(kpse, { __index = function(k,v) return resolvers[v] end } )
+
+-- for a while
+
+input = resolvers
diff --git a/tex/context/base/data-tex.lua b/tex/context/base/data-tex.lua
new file mode 100644
index 000000000..792c48fec
--- /dev/null
+++ b/tex/context/base/data-tex.lua
@@ -0,0 +1,220 @@
+if not modules then modules = { } end modules ['data-tex'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- special functions that deal with io
+
+local format, lower = string.format, string.lower
+
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end)
+
+local texiowrite_nl = (texio and texio.write_nl) or print
+local texiowrite = (texio and texio.write) or print
+
+local finders, openers, loaders = resolvers.finders, resolvers.openers, resolvers.loaders
+
+function finders.generic(tag,filename,filetype)
+ local foundname = resolvers.find_file(filename,filetype)
+ if foundname and foundname ~= "" then
+ if trace_locating then
+ logs.report("fileio",'+ finder: %s, file: %s', tag,filename)
+ end
+ return foundname
+ else
+ if trace_locating then
+ logs.report("fileio",'- finder: %s, file: %s', tag,filename)
+ end
+ return unpack(finders.notfound)
+ end
+end
+
+--~ local getlines = lpeg.Ct(lpeg.linebyline)
+
+local input_translator, utf_translator, user_translator = nil, nil, nil
+
+function resolvers.install_text_filter(name,func)
+ if name == "input" then input_translator = func
+ elseif name == "utf" then utf_translator = func
+ elseif name == "user" then user_translator = func end
+end
+
+function openers.text_opener(filename,file_handle,tag)
+ local u = unicode.utftype(file_handle)
+ local t = { }
+ if u > 0 then
+ if trace_locating then
+ logs.report("fileio",'+ opener: %s (%s), file: %s',tag,unicode.utfname[u],filename)
+ end
+ local l
+ if u > 2 then
+ l = unicode.utf32_to_utf8(file_handle:read("*a"),u==4)
+ else
+ l = unicode.utf16_to_utf8(file_handle:read("*a"),u==2)
+ end
+ file_handle:close()
+ t = {
+ utftype = u, -- may go away
+ lines = l,
+ current = 0, -- line number, not really needed
+ handle = nil,
+ noflines = #l,
+ close = function()
+ if trace_locating then
+ logs.report("fileio",'= closer: %s (%s), file: %s',tag,unicode.utfname[u],filename)
+ end
+ logs.show_close(filename)
+ t = nil
+ end,
+ reader = function(self)
+ self = self or t
+ local current, lines = self.current, self.lines
+ if current >= #lines then
+ return nil
+ else
+ current = current + 1
+ self.current = current
+ local line = lines[current]
+ if not line then
+ return nil
+ elseif line == "" then
+ return ""
+ else
+ if input_translator then
+ line = input_translator(line)
+ end
+ if utf_translator then
+ line = utf_translator(line)
+ end
+ if user_translator then
+ line = user_translator(line)
+ end
+ return line
+ end
+ end
+ end
+ }
+ else
+ if trace_locating then
+ logs.report("fileio",'+ opener: %s, file: %s',tag,filename)
+ end
+ -- todo: file;name -> freeze / eerste regel scannen -> freeze
+ --~ local data = getlines:match(file_handle:read("*a"))
+ --~ local n = 0
+ t = {
+ reader = function() -- self
+ local line = file_handle:read()
+ --~ n = n + 1
+ --~ local line = data[n]
+ --~ print(line)
+ if not line then
+ return nil
+ elseif line == "" then
+ return ""
+ else
+ if input_translator then
+ line = input_translator(line)
+ end
+ if utf_translator then
+ line = utf_translator(line)
+ end
+ if user_translator then
+ line = user_translator(line)
+ end
+ return line
+ end
+ end,
+ close = function()
+ if trace_locating then
+ logs.report("fileio",'= closer: %s, file: %s',tag,filename)
+ end
+ logs.show_close(filename)
+ file_handle:close()
+ t = nil
+ end,
+ handle = function()
+ return file_handle
+ end,
+ noflines = function()
+ t.noflines = io.noflines(file_handle)
+ return t.noflines
+ end
+ }
+ end
+ return t
+end
+
+function openers.generic(tag,filename)
+ if filename and filename ~= "" then
+ local f = io.open(filename,"r")
+ if f then
+ logs.show_open(filename)
+ return openers.text_opener(filename,f,tag)
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- opener: %s, file: %s',tag,filename)
+ end
+ return unpack(openers.notfound)
+end
+
+function loaders.generic(tag,filename)
+ if filename and filename ~= "" then
+ local f = io.open(filename,"rb")
+ if f then
+ logs.show_load(filename)
+ if trace_locating then
+ logs.report("fileio",'+ loader: %s, file: %s',tag,filename)
+ end
+ local s = f:read("*a")
+ if garbagecollector and garbagecollector.check then garbagecollector.check(#s) end
+ f:close()
+ if s then
+ return true, s, #s
+ end
+ end
+ end
+ if trace_locating then
+ logs.report("fileio",'- loader: %s, file: %s',tag,filename)
+ end
+ return unpack(loaders.notfound)
+end
+
+function finders.tex(filename,filetype)
+ return finders.generic('tex',filename,filetype)
+end
+
+function openers.tex(filename)
+ return openers.generic('tex',filename)
+end
+
+function loaders.tex(filename)
+ return loaders.generic('tex',filename)
+end
+
+function resolvers.findtexfile(filename, filetype)
+ return resolvers.methodhandler('finders',file.collapse_path(filename), filetype)
+end
+
+function resolvers.opentexfile(filename)
+ return resolvers.methodhandler('openers',file.collapse_path(filename))
+end
+
+function resolvers.openfile(filename)
+ local fullname = resolvers.findtexfile(filename)
+ if fullname and (fullname ~= "") then
+ return resolvers.opentexfile(fullname)
+ else
+ return nil
+ end
+end
+
+function resolvers.texdatablob(filename, filetype)
+ local ok, data, size = resolvers.loadbinfile(filename, filetype)
+ return data or ""
+end
+
+resolvers.loadtexfile = resolvers.texdatablob
diff --git a/tex/context/base/data-tmf.lua b/tex/context/base/data-tmf.lua
new file mode 100644
index 000000000..302841a65
--- /dev/null
+++ b/tex/context/base/data-tmf.lua
@@ -0,0 +1,72 @@
+if not modules then modules = { } end modules ['data-tmf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- loads *.tmf files in minimal tree roots (to be optimized and documented)
+
+function resolvers.check_environment(tree)
+ logs.simpleline()
+ os.setenv('TMP', os.getenv('TMP') or os.getenv('TEMP') or os.getenv('TMPDIR') or os.getenv('HOME'))
+ os.setenv('TEXOS', os.getenv('TEXOS') or ("texmf-" .. os.currentplatform()))
+ os.setenv('TEXPATH', (tree or "tex"):gsub("\/+$",''))
+ os.setenv('TEXMFOS', os.getenv('TEXPATH') .. "/" .. os.getenv('TEXOS'))
+ logs.simpleline()
+ logs.simple("preset : TEXPATH => %s", os.getenv('TEXPATH'))
+ logs.simple("preset : TEXOS => %s", os.getenv('TEXOS'))
+ logs.simple("preset : TEXMFOS => %s", os.getenv('TEXMFOS'))
+ logs.simple("preset : TMP => %s", os.getenv('TMP'))
+ logs.simple('')
+end
+
+function resolvers.load_environment(name) -- todo: key=value as well as lua
+ local f = io.open(name)
+ if f then
+ for line in f:lines() do
+ if line:find("^[%%%#]") then
+ -- skip comment
+ else
+ local key, how, value = line:match("^(.-)%s*([<=>%?]+)%s*(.*)%s*$")
+ if how then
+ value = value:gsub("%%(.-)%%", function(v) return os.getenv(v) or "" end)
+ if how == "=" or how == "<<" then
+ os.setenv(key,value)
+ elseif how == "?" or how == "??" then
+ os.setenv(key,os.getenv(key) or value)
+ elseif how == "<" or how == "+=" then
+ if os.getenv(key) then
+ os.setenv(key,os.getenv(key) .. io.fileseparator .. value)
+ else
+ os.setenv(key,value)
+ end
+ elseif how == ">" or how == "=+" then
+ if os.getenv(key) then
+ os.setenv(key,value .. io.pathseparator .. os.getenv(key))
+ else
+ os.setenv(key,value)
+ end
+ end
+ end
+ end
+ end
+ f:close()
+ end
+end
+
+function resolvers.load_tree(tree)
+ if tree and tree ~= "" then
+ local setuptex = 'setuptex.tmf'
+ if lfs.attributes(tree, "mode") == "directory" then -- check if not nil
+ setuptex = tree .. "/" .. setuptex
+ else
+ setuptex = tree
+ end
+ if io.exists(setuptex) then
+ resolvers.check_environment(tree)
+ resolvers.load_environment(setuptex)
+ end
+ end
+end
diff --git a/tex/context/base/data-tmp.lua b/tex/context/base/data-tmp.lua
new file mode 100644
index 000000000..31d0147ea
--- /dev/null
+++ b/tex/context/base/data-tmp.lua
@@ -0,0 +1,174 @@
+if not modules then modules = { } end modules ['data-tmp'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This module deals with caching data. It sets up the paths and
+implements loaders and savers for tables. Best is to set the
+following variable. When not set, the usual paths will be
+checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
+problem because most caching involves fonts and the chance of them
+being written at the same time is small. We also need to extend
+luatools with a recache feature.
So far we haven't really dealt with features (or whatever we want
+to pass along with the font definition. We distinguish the following
+situations:
+situations:
+
+
+name:xetex like specs
+name@virtual font spec
+name*context specification
+
+--ldx]]--
+
+function specify.predefined(specification)
+ local detail = specification.detail
+ if detail ~= "" then
+ -- detail = detail:gsub("["..define.splitsymbols.."].*$","") -- get rid of *whatever specs and such
+ if define.methods[detail] then -- since these may be appended at the
+ specification.features.vtf = { preset = detail } -- tex end by default
+ end
+ end
+ return specification
+end
+
+define.register_split("@", specify.predefined)
+
+storage.register("fonts/setups" , define.specify.context_setups , "fonts.define.specify.context_setups" )
+storage.register("fonts/numbers", define.specify.context_numbers, "fonts.define.specify.context_numbers")
+storage.register("fonts/merged", define.specify.context_merged, "fonts.define.specify.context_merged")
+storage.register("fonts/synonyms", define.specify.synonyms, "fonts.define.specify.synonyms")
+
+local normalize_meanings = fonts.otf.meanings.normalize
+local settings_to_hash = aux.settings_to_hash
+local default_features = fonts.otf.features.default
+
+local function preset_context(name,parent,features) -- currently otf only
+ if features == "" then
+ if find(parent,"=") then
+ features = parent
+ parent = ""
+ end
+ end
+ local number = (setups[name] and setups[name].number) or 0
+ local t = (features == "" and { }) or normalize_meanings(settings_to_hash(features))
+ -- todo: synonyms, and not otf bound
+ if parent ~= "" then
+ for p in gmatch(parent,"[^, ]+") do
+ local s = setups[p]
+ if s then
+ for k,v in next, s do
+ if t[k] == nil then
+ t[k] = v
+ end
+ end
+ end
+ end
+ end
+ -- these are auto set so in order to prevent redundant definitions
+ -- we need to preset them (we hash the features and adding a default
+ -- setting during initialization may result in a different hash)
+ for k,v in next, triggers do
+ if type(t[v]) == "nil" then
+ local vv = default_features[v]
+ if vv then t[v] = vv end
+ end
+ end
+ -- sparse 'm so that we get a better hash and less test (experimental
+ -- optimization)
+ local tt = { } -- maybe avoid tt
+ for k,v in next, t do
+ if v then tt[k] = v end
+ end
+ -- needed for dynamic features
+ if number == 0 then
+ number = #numbers + 1
+ numbers[number] = name
+ end
+ tt.number = number
+ setups[name] = tt
+ return number
+end
+
+local function context_number(name) -- will be replaced
+ local t = setups[name]
+ if not t then
+ return 0
+ elseif t.auto then
+ local lng = tonumber(tex.language)
+ local tag = name .. ":" .. lng
+ local s = setups[tag]
+ if s then
+ return s.number or 0
+ else
+ local script, language = languages.association(lng)
+ if t.script ~= script or t.language ~= language then
+ local s = table.fastcopy(t)
+ local n = #numbers + 1
+ setups[tag] = s
+ numbers[n] = tag
+ s.number = n
+ s.script = script
+ s.language = language
+ return n
+ else
+ setups[tag] = t
+ return t.number or 0
+ end
+ end
+ else
+ return t.number or 0
+ end
+end
+
+local function merge_context(currentnumber,extraname,option)
+ local current = setups[numbers[currentnumber]]
+ local extra = setups[extraname]
+ if extra then
+ local mergedfeatures, mergedname = { }, nil
+ if option < 0 then
+ if current then
+ for k, v in next, current do
+ if not extra[k] then
+ mergedfeatures[k] = v
+ end
+ end
+ end
+ mergedname = currentnumber .. "-" .. extraname
+ else
+ if current then
+ for k, v in next, current do
+ mergedfeatures[k] = v
+ end
+ end
+ for k, v in next, extra do
+ mergedfeatures[k] = v
+ end
+ mergedname = currentnumber .. "+" .. extraname
+ end
+ local number = #numbers + 1
+ mergedfeatures.number = number
+ numbers[number] = mergedname
+ merged[number] = option
+ setups[mergedname] = mergedfeatures
+ return number -- context_number(mergedname)
+ else
+ return currentnumber
+ end
+end
+
+local function register_context(fontnumber,extraname,option)
+ local extra = setups[extraname]
+ if extra then
+ local mergedfeatures, mergedname = { }, nil
+ if option < 0 then
+ mergedname = fontnumber .. "-" .. extraname
+ else
+ mergedname = fontnumber .. "+" .. extraname
+ end
+ for k, v in next, extra do
+ mergedfeatures[k] = v
+ end
+ local number = #numbers + 1
+ mergedfeatures.number = number
+ numbers[number] = mergedname
+ merged[number] = option
+ setups[mergedname] = mergedfeatures
+ return number -- context_number(mergedname)
+ else
+ return 0
+ end
+end
+
+specify.preset_context = preset_context
+specify.context_number = context_number
+specify.merge_context = merge_context
+specify.register_context = register_context
+
+local current_font = font.current
+local tex_attribute = tex.attribute
+
+local cache = { } -- concat might be less efficient than nested tables
+
+function fonts.withset(name,what)
+ local zero = tex_attribute[0]
+ local hash = zero .. "+" .. name .. "*" .. what
+ local done = cache[hash]
+ if not done then
+ done = merge_context(zero,name,what)
+ cache[hash] = done
+ end
+ tex_attribute[0] = done
+end
+function fonts.withfnt(name,what)
+ local font = current_font()
+ local hash = font .. "*" .. name .. "*" .. what
+ local done = cache[hash]
+ if not done then
+ done = register_context(font,name,what)
+ cache[hash] = done
+ end
+ tex_attribute[0] = done
+end
+
+function specify.show_context(name)
+ return setups[name] or setups[numbers[name]] or setups[numbers[tonumber(name)]] or { }
+end
+
+local function split_context(features)
+ return setups[features] or (preset_context(features,"","") and setups[features])
+end
+
+specify.split_context = split_context
+
+function specify.context_tostring(name,kind,separator,yes,no,strict,omit) -- not used
+ return aux.hash_to_string(table.merged(fonts[kind].features.default or {},setups[name] or {}),separator,yes,no,strict,omit)
+end
+
+local splitter = lpeg.splitat(",")
+
+function specify.starred(features) -- no longer fallbacks here
+ local detail = features.detail
+ if detail and detail ~= "" then
+ features.features.normal = split_context(detail)
+ else
+ features.features.normal = { }
+ end
+ return features
+end
+
+define.register_split('*',specify.starred)
+
+-- define (two steps)
+
+local P, C, Cc = lpeg.P, lpeg.C, lpeg.Cc
+
+local space = P(" ")
+local spaces = space^0
+local value = C((1-space)^1)
+local rest = C(P(1)^0)
+local scale_none = Cc(0)
+local scale_at = P("at") * Cc(1) * spaces * value
+local scale_sa = P("sa") * Cc(2) * spaces * value
+local scale_mo = P("mo") * Cc(3) * spaces * value
+local scale_scaled = P("scaled") * Cc(4) * spaces * value
+
+local sizepattern = spaces * (scale_at + scale_sa + scale_mo + scale_scaled + scale_none)
+local splitpattern = spaces * value * spaces * rest
+
+local specification --
+
+local get_specification = define.get_specification
+
+function define.command_1(str)
+ statistics.starttiming(fonts)
+ local fullname, size = splitpattern:match(str)
+ local lookup, name, sub, method, detail = get_specification(fullname)
+ if not name then
+ logs.report("define font","strange definition '%s'",str)
+ texsprint(ctxcatcodes,"\\glet\\somefontname\\defaultfontfile")
+ elseif name == "unknown" then
+ texsprint(ctxcatcodes,"\\glet\\somefontname\\defaultfontfile")
+ else
+ texsprint(ctxcatcodes,format("\\xdef\\somefontname{%s}",name))
+ end
+ -- we can also use a count for the size
+ if size and size ~= "" then
+ local mode, size = sizepattern:match(size)
+ if size and mode then
+ count.scaledfontmode = mode
+ texsprint(ctxcatcodes,format("\\def\\somefontsize{%s}",size))
+ else
+ count.scaledfontmode = 0
+ texsprint(ctxcatcodes,format("\\let\\somefontsize\\empty",size))
+ end
+ elseif true then
+ -- so we don't need to check in tex
+ count.scaledfontmode = 2
+--~ texsprint(ctxcatcodes,format("\\def\\somefontsize{*}",size))
+ texsprint(ctxcatcodes,format("\\let\\somefontsize\\empty",size))
+ else
+ count.scaledfontmode = 0
+ texsprint(ctxcatcodes,format("\\let\\somefontsize\\empty",size))
+ end
+ specification = define.makespecification(str,lookup,name,sub,method,detail,size)
+end
+
+function define.command_2(global,cs,str,size,classfeatures,fontfeatures,classfallbacks,fontfallbacks,mathsize,textsize)
+ -- name is now resolved and size is scaled cf sa/mo
+ local lookup, name, sub, method, detail = get_specification(str or "")
+ -- asome settings can be overloaded
+ if lookup and lookup ~= "" then specification.lookup = lookup end
+ specification.name = name
+ specification.size = size
+ specification.sub = sub
+ specification.mathsize = mathsize
+ specification.textsize = textsize
+ if detail and detail ~= "" then
+ specification.method, specification.detail = method or "*", detail
+ elseif specification.detail and specification.detail ~= "" then
+ -- already set
+ elseif fontfeatures and fontfeatures ~= "" then
+ specification.method, specification.detail = "*", fontfeatures
+ elseif classfeatures and classfeatures ~= "" then
+ specification.method, specification.detail = "*", classfeatures
+ end
+ if trace_defining then
+ logs.report("define font","memory usage before: %s",statistics.memused())
+ end
+ if fontfallbacks and fontfallbacks ~= "" then
+ specification.fallbacks = fontfallbacks
+ elseif classfallbacks and classfallbacks ~= "" then
+ specification.fallbacks = classfallbacks
+ end
+ local tfmdata = define.read(specification,size) -- id not yet known
+ if not tfmdata then
+ logs.report("define font","unable to define %s as \\%s",name,cs)
+ elseif type(tfmdata) == "number" then
+ if trace_defining then
+ logs.report("define font","reusing %s with id %s as \\%s (features: %s/%s, fallbacks: %s/%s)",name,tfmdata,cs,classfeatures,fontfeatures,classfallbacks,fontfallbacks)
+ end
+ tex.definefont(global,cs,tfmdata)
+ -- resolved (when designsize is used):
+ texsprint(ctxcatcodes,format("\\def\\somefontsize{%isp}",fontdata[tfmdata].size))
+ else
+ -- local t = os.clock(t)
+ local id = font.define(tfmdata)
+ -- print(name,os.clock()-t)
+ tfmdata.id = id
+ define.register(tfmdata,id)
+ tex.definefont(global,cs,id)
+ tfm.cleanup_table(tfmdata)
+ if trace_defining then
+ logs.report("define font","defining %s with id %s as \\%s (features: %s/%s, fallbacks: %s/%s)",name,id,cs,classfeatures,fontfeatures,classfallbacks,fontfallbacks)
+ end
+ -- resolved (when designsize is used):
+ texsprint(ctxcatcodes,format("\\def\\somefontsize{%isp}",tfmdata.size))
+ --~ if specification.fallbacks then
+ --~ fonts.collections.prepare(specification.fallbacks)
+ --~ end
+ end
+ if trace_defining then
+ logs.report("define font","memory usage after: %s",statistics.memused())
+ end
+ statistics.stoptiming(fonts)
+end
+
+--~ table.insert(readers.sequence,1,'vtf')
+
+--~ function readers.vtf(specification)
+--~ if specification.features.vtf and specification.features.vtf.preset then
+--~ return tfm.make(specification)
+--~ else
+--~ return nil
+--~ end
+--~ end
diff --git a/tex/context/base/font-def.lua b/tex/context/base/font-def.lua
index 474cde41d..8c367e148 100644
--- a/tex/context/base/font-def.lua
+++ b/tex/context/base/font-def.lua
@@ -6,9 +6,13 @@ if not modules then modules = { } end modules ['font-def'] = {
license = "see context related readme files"
}
--- check reuse of lmroman1o-regular vs lmr10
+local format, concat, gmatch, match, find, lower = string.format, table.concat, string.gmatch, string.match, string.find, string.lower
+local tostring, next = tostring, next
-local texsprint, count, dimen, format, concat = tex.sprint, tex.count, tex.dimen, string.format, table.concat
+local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end)
+
+trackers.register("fonts.loading", "fonts.defining", "otf.loading", "afm.loading", "tfm.loading")
+trackers.register("fonts.all", "fonts.*", "otf.*", "afm.*", "tfm.*")
--[[ldx--
Here we deal with defining fonts. We do so by intercepting the
@@ -18,43 +22,30 @@ default loader that only handles .
Choosing a font by name and specififying its size is only part of the
-game. In order to prevent complex commands, introduced
-a method to pass feature information as part of the font name. At the
-risk of introducing nasty parsing and compatinility problems, this
-syntax was expanded over time.
-
-
For the sake of users who have defined fonts using that syntax, we
-will support it, but we will provide additional methods as well.
-Normally users will not use this direct way, but use a more abstract
-interface.
- --ldx]]--
-
---~ name, kind, features = fonts.features.split_xetex("blabla / B : + lnum ; foo = bar ; - whatever ; whow ; + hans ; test = yes")
-
-fonts.define.method = 3 -- 1: tfm 2: tfm and if not then afm 3: afm and if not then tfm
-fonts.define.auto_afm = true
-fonts.define.auto_otf = true
-fonts.define.specify = fonts.define.specify or { }
-fonts.define.methods = fonts.define.methods or { }
+define.method = "afm or tfm" -- afm, tfm, afm or tfm, tfm or afm
+define.specify = fonts.define.specify or { }
+define.methods = fonts.define.methods or { }
tfm.fonts = tfm.fonts or { }
tfm.readers = tfm.readers or { }
tfm.internalized = tfm.internalized or { } -- internal tex numbers
-tfm.id = tfm.id or { } -- font data, maybe use just fonts.ids (faster lookup)
tfm.readers.sequence = { 'otf', 'ttf', 'afm', 'tfm' }
+local readers = tfm.readers
+local sequence = readers.sequence
+
--[[ldx--
We hardly gain anything when we cache the final (pre scaled)
table. But it can be handy for debugging.
@@ -84,7 +75,7 @@ and prepares a table that will move along as we proceed.
local splitter, specifiers = nil, ""
-function fonts.define.add_specifier(symbol)
+function define.add_specifier(symbol)
specifiers = specifiers .. symbol
local left = lpeg.P("(")
local right = lpeg.P(")")
@@ -92,27 +83,32 @@ function fonts.define.add_specifier(symbol)
local method = lpeg.S(specifiers)
local lookup = lpeg.C(lpeg.P("file")+lpeg.P("name")) * colon -- hard test, else problems with : method
local sub = left * lpeg.C(lpeg.P(1-left-right-method)^1) * right
- local specification = lpeg.C(method) * lpeg.C(lpeg.P(1-method)^1)
+--~ local specification = lpeg.C(method) * lpeg.C(lpeg.P(1-method)^1)
+ local specification = lpeg.C(method) * lpeg.C(lpeg.P(1)^1)
local name = lpeg.C((1-sub-specification)^1)
splitter = lpeg.P((lookup + lpeg.Cc("")) * name * (sub + lpeg.Cc("")) * (specification + lpeg.Cc("")))
end
-function fonts.define.get_specification(str)
+function define.get_specification(str)
return splitter:match(str)
end
-function fonts.define.register_split(symbol,action)
- fonts.define.add_specifier(symbol)
- fonts.define.specify[symbol] = action
+function define.register_split(symbol,action)
+ define.add_specifier(symbol)
+ define.specify[symbol] = action
end
-function fonts.define.makespecification(specification, lookup, name, sub, method, detail, size)
+function define.makespecification(specification, lookup, name, sub, method, detail, size)
size = size or 655360
- if fonts.trace then
+ if trace_defining then
logs.report("define font","%s -> lookup: %s, name: %s, sub: %s, method: %s, detail: %s",
specification, (lookup ~= "" and lookup) or "[file]", (name ~= "" and name) or "-",
(sub ~= "" and sub) or "-", (method ~= "" and method) or "-", (detail ~= "" and detail) or "-")
end
+--~ if specification.lookup then
+--~ lookup = specification.lookup -- can come from xetex [] syntax
+--~ specification.lookup = nil
+--~ end
if lookup ~= 'name' then -- for the moment only two lookups, maybe some day also system:
lookup = 'file'
end
@@ -131,37 +127,43 @@ function fonts.define.makespecification(specification, lookup, name, sub, method
return t
end
-function fonts.define.analyze(specification, size)
- local lookup, name, sub, method, detail = fonts.define.get_specification(specification or "")
- return fonts.define.makespecification(specification,lookup, name, sub, method, detail, size)
+function define.analyze(specification, size)
+ -- can be optimized with locals
+ local lookup, name, sub, method, detail = define.get_specification(specification or "")
+ return define.makespecification(specification,lookup, name, sub, method, detail, size)
end
--[[ldx--
A unique hash value is generated by:
--ldx]]--
+local sortedhashkeys = table.sortedhashkeys
+
function tfm.hash_features(specification)
local features = specification.features
if features then
local t = { }
local normal = features.normal
if normal and next(normal) then
- local f = table.sortedhashkeys(normal)
+ local f = sortedhashkeys(normal)
for i=1,#f do
local v = f[i]
- if v ~= "number" then
+ if v ~= "number" and v ~= "features" then -- i need to figure this out, features
t[#t+1] = v .. '=' .. tostring(normal[v])
end
end
end
local vtf = features.vtf
if vtf and next(vtf) then
- local f = table.sortedhashkeys(vtf)
+ local f = sortedhashkeys(vtf)
for i=1,#f do
local v = f[i]
t[#t+1] = v .. '=' .. tostring(vtf[v])
end
end
+--~ if specification.mathsize then
+--~ t[#t] = "mathsize=" .. specification.mathsize
+--~ end
if #t > 0 then
return concat(t,"+")
end
@@ -189,18 +191,28 @@ function tfm.hash_instance(specification,force)
size = math.round(tfm.scaled(size, fonts.designsizes[hash]))
specification.size = size
end
- if fallbacks then
- return hash .. ' @ ' .. tostring(size) .. ' @ ' .. fallbacks
- else
- return hash .. ' @ ' .. tostring(size)
- end
+--~ local mathsize = specification.mathsize or 0
+--~ if mathsize > 0 then
+--~ local textsize = specification.textsize
+--~ if fallbacks then
+--~ return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ] @ ' .. fallbacks
+--~ else
+--~ return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ]'
+--~ end
+--~ else
+ if fallbacks then
+ return hash .. ' @ ' .. tostring(size) .. ' @ ' .. fallbacks
+ else
+ return hash .. ' @ ' .. tostring(size)
+ end
+--~ end
end
--[[ldx--
We can resolve the filename using the next function:
--ldx]]--
-function fonts.define.resolve(specification)
+function define.resolve(specification)
if not specification.resolved or specification.resolved == "" then -- resolved itself not per se in mapping hash
if specification.lookup == 'name' then
specification.resolved, specification.sub = fonts.names.resolve(specification.name,specification.sub)
@@ -218,7 +230,8 @@ function fonts.define.resolve(specification)
else
specification.forced = specification.forced
end
- specification.hash = specification.name .. ' @ ' .. tfm.hash_features(specification)
+--~ specification.hash = specification.name .. ' @ ' .. tfm.hash_features(specification)
+ specification.hash = lower(specification.name .. ' @ ' .. tfm.hash_features(specification))
if specification.sub and specification.sub ~= "" then
specification.hash = specification.sub .. ' @ ' .. specification.hash
end
@@ -242,22 +255,23 @@ specification yet.
--ldx]]--
function tfm.read(specification)
---~ input.starttiming(fonts)
local hash = tfm.hash_instance(specification)
local tfmtable = tfm.fonts[hash] -- hashes by size !
if not tfmtable then
- if specification.forced and specification.forced ~= "" then
- tfmtable = tfm.readers[specification.forced:lower()](specification)
+ local forced = specification.forced or ""
+ if forced ~= "" then
+ tfmtable = readers[lower(forced)](specification)
if not tfmtable then
- logs.report("define font","forced type %s of %s not found",specification.forced,specification.name)
+ logs.report("define font","forced type %s of %s not found",forced,specification.name)
end
else
- for _, reader in ipairs(tfm.readers.sequence) do
- if tfm.readers[reader] then -- not really needed
- if fonts.trace then
+ for s=1,#sequence do -- reader sequence
+ local reader = sequence[s]
+ if readers[reader] then -- not really needed
+ if trace_defining then
logs.report("define font","trying type %s for %s with file %s",reader,specification.name,specification.filename or "unknown")
end
- tfmtable = tfm.readers[reader](specification)
+ tfmtable = readers[reader](specification)
if tfmtable then break end
end
end
@@ -273,7 +287,6 @@ function tfm.read(specification)
--~ tfmtable.mode = specification.features.normal.mode or "base"
end
end
---~ input.stoptiming(fonts)
if not tfmtable then
logs.report("define font","font with name %s is not found",specification.name)
end
@@ -285,26 +298,26 @@ end
--ldx]]--
function tfm.read_and_define(name,size) -- no id
- local specification = fonts.define.analyze(name,size)
+ local specification = define.analyze(name,size)
local method = specification.method
- if method and fonts.define.specify[method] then
- specification = fonts.define.specify[method](specification)
+ if method and define.specify[method] then
+ specification = define.specify[method](specification)
end
- specification = fonts.define.resolve(specification)
+ specification = define.resolve(specification)
local hash = tfm.hash_instance(specification)
- local id = fonts.define.registered(hash)
+ local id = define.registered(hash)
if not id then
local fontdata = tfm.read(specification)
if fontdata then
fontdata.hash = hash
id = font.define(fontdata)
- fonts.define.register(fontdata,id)
-tfm.cleanup_table(fontdata)
+ define.register(fontdata,id)
+ tfm.cleanup_table(fontdata)
else
id = 0 -- signal
end
end
- return tfm.id[id], id
+ return fonts.ids[id], id
end
--[[ldx--
@@ -312,275 +325,113 @@ end
evolved. Each one has its own way of dealing with its format.
--ldx]]--
-function tfm.readers.opentype(specification,suffix,what)
- if fonts.define.auto_otf then
- local fullname, tfmtable = nil, nil
- fullname = input.findbinfile(specification.name,suffix) or ""
- if fullname == "" then
- local fb = fonts.names.old_to_new[specification.name]
- if fb then
- fullname = input.findbinfile(fb,suffix) or ""
- end
- end
- if fullname == "" then
- local fb = fonts.names.new_to_old[specification.name]
- if fb then
- fullname = input.findbinfile(fb,suffix) or ""
- end
- end
- if fullname ~= "" then
- specification.filename, specification.format = fullname, what -- hm, so we do set the filename, then
- tfmtable = tfm.read_from_open_type(specification) -- we need to do it for all matches / todo
- end
- return tfmtable
- else
- return nil
+local function check_tfm(specification,fullname)
+ -- ofm directive blocks local path search unless set
+ fullname = resolvers.findbinfile(fullname, 'tfm') or "" -- just to be sure
+ if fullname ~= "" then
+ specification.filename, specification.format = fullname, "ofm"
+ return tfm.read_from_tfm(specification)
end
end
-function tfm.readers.otf(specification) return tfm.readers.opentype(specification,"otf","opentype") end
-function tfm.readers.ttf(specification) return tfm.readers.opentype(specification,"ttf","truetype") end
-function tfm.readers.ttc(specification) return tfm.readers.opentype(specification,"ttf","truetype") end -- !!
-
-function tfm.readers.afm(specification,method)
- local fullname, tfmtable = nil, nil
- method = method or fonts.define.method
- if method == 2 then
- fullname = input.findbinfile(specification.name,"ofm") or ""
- if fullname == "" then
- tfmtable = tfm.read_from_afm(specification)
- else -- redundant
- specification.filename = fullname
- tfmtable = tfm.read_from_tfm(specification)
- end
- elseif method == 3 then -- maybe also findbinfile here
- if fonts.define.auto_afm then
- tfmtable = tfm.read_from_afm(specification)
- end
- elseif method == 4 then -- maybe also findbinfile here
- tfmtable = tfm.read_from_afm(specification)
+local function check_afm(specification,fullname)
+ fullname = resolvers.findbinfile(fullname, 'afm') or "" -- just to be sure
+ if fullname ~= "" then
+ specification.filename, specification.format = fullname, "afm"
+ return tfm.read_from_afm(specification)
end
- return tfmtable
end
-function tfm.readers.tfm(specification)
- local fullname, tfmtable = nil, nil
- tfmtable = tfm.read_from_tfm(specification)
- return tfmtable
-end
-
---[[ldx--
-
So far we haven't really dealt with features (or whatever we want
-to pass along with the font definition. We distinguish the following
-situations:
-situations:
-
-
-name:xetex like specs
-name@virtual font spec
-name*context specification
-
-
-
Of course one can always define more.
---ldx]]--
-
-function fonts.define.specify.predefined(specification)
- local detail = specification.detail
- if detail ~= "" then
- -- detail = detail:gsub("["..fonts.define.splitsymbols.."].*$","") -- get rid of *whatever specs and such
- if fonts.define.methods[detail] then -- since these may be appended at the
- specification.features.vtf = { preset = detail } -- tex end by default
+function readers.tfm(specification)
+ local fullname, tfmtable = specification.filename or "", nil
+ if fullname == "" then
+ local forced = specification.forced or ""
+ if forced ~= "" then
+ tfmtable = check_tfm(specification,specification.name .. "." .. forced)
end
- end
- return specification
-end
-
-fonts.define.register_split("@", fonts.define.specify.predefined)
-
-function fonts.define.specify.colonized(specification) -- xetex mode
- local list = { }
- if specification.detail and specification.detail ~= "" then
- local expanded_features = { }
- local function expand(features)
- for _,v in pairs(features:split(";")) do --just gmatch
- expanded_features[#expanded_features+1] = v
- end
- end
- expand(specification.detail)
- for _,v in pairs(expanded_features) do
- local a, b = v:match("^%s*(%S+)%s*=%s*(%S+)%s*$")
- if a and b then
- list[a] = b:is_boolean()
- if type(list[a]) == "nil" then
- list[a] = b
- end
- else
- local a, b = v:match("^%s*([%+%-]?)%s*(%S+)%s*$")
- if a and b then
- list[b] = a ~= "-"
- end
- end
+ if not tfmtable then
+ tfmtable = check_tfm(specification,specification.name)
end
- end
- specification.features.normal = list
- return specification
-end
-
-function tfm.make(specification)
- -- currently fonts are scaled while constructing the font, so we
- -- have to do scaling of commands in the vf at that point using
- -- e.g. "local scale = g.factor or 1" after all, we need to work
- -- with copies anyway and scaling needs to be done at some point;
- -- however, when virtual tricks are used as feature (makes more
- -- sense) we scale the commands in fonts.tfm.scale (and set the
- -- factor there)
- local fvm = fonts.define.methods[specification.features.vtf.preset]
- if fvm then
- return fvm(specification)
else
- return nil
+ tfmtable = check_tfm(specification,fullname)
end
+ return tfmtable
end
-fonts.define.register_split(":", fonts.define.specify.colonized)
-
-fonts.define.specify.context_setups = fonts.define.specify.context_setups or { }
-fonts.define.specify.context_numbers = fonts.define.specify.context_numbers or { }
-fonts.define.specify.synonyms = fonts.define.specify.synonyms or { }
-
-input.storage.register(false,"fonts/setups" , fonts.define.specify.context_setups , "fonts.define.specify.context_setups" )
-input.storage.register(false,"fonts/numbers", fonts.define.specify.context_numbers, "fonts.define.specify.context_numbers")
-
-fonts.triggers = fonts.triggers or { }
-
-function fonts.define.specify.preset_context(name,parent,features)
- if features == "" then
- if parent:find("=") then
- features = parent
- parent = ""
+function readers.afm(specification,method)
+ local fullname, tfmtable = specification.filename or "", nil
+ if fullname == "" then
+ local forced = specification.forced or ""
+ if forced ~= "" then
+ tfmtable = check_afm(specification,specification.name .. "." .. forced)
end
- end
- local fds = fonts.define.specify
- local setups, numbers, synonyms = fds.context_setups, fds.context_numbers, fds.synonyms
- local number = (setups[name] and setups[name].number) or 0
- local t = (features == "" and { }) or fonts.otf.meanings.normalize(aux.settings_to_hash(features))
- -- todo: synonyms, and not otf bound
- if parent ~= "" then
- for p in parent:gmatch("[^, ]+") do
- local s = setups[p]
- if s then
- for k,v in pairs(s) do
- if t[k] == nil then
- t[k] = v
- end
- end
+ if not tfmtable then
+ method = method or define.method or "afm or tfm"
+ if method == "tfm" then
+ tfmtable = check_tfm(specification,specification.name)
+ elseif method == "afm" then
+ tfmtable = check_afm(specification,specification.name)
+ elseif method == "tfm or afm" then
+ tfmtable = check_tfm(specification,specification.name) or check_afm(specification,specification.name)
+ else -- method == "afm or tfm" or method == "" then
+ tfmtable = check_afm(specification,specification.name) or check_tfm(specification,specification.name)
end
end
- end
- -- these are auto set so in order to prevent redundant definitions
- -- we need to preset them (we hash the features and adding a default
- -- setting during initialization may result in a different hash)
- local default = fonts.otf.features.default
- for k,v in pairs(fonts.triggers) do
- if type(t[v]) == "nil" then
- local vv = default[v]
- if vv then t[v] = vv end
- end
- end
- -- sparse 'm so that we get a better hash and less test (experimental
- -- optimization)
- local tt = { }
- for k,v in pairs(t) do
- if v then tt[k] = v end
- end
- -- needed for dynamic features
- if number == 0 then
- numbers[#numbers+1] = name
- tt.number = #numbers
else
- tt.number = number
+ tfmtable = check_afm(specification,fullname)
end
- setups[name] = tt
+ return tfmtable
end
-do
-
- -- here we clone features according to languages
-
- local default = 0
- local setups = fonts.define.specify.context_setups
- local numbers = fonts.define.specify.context_numbers
-
- function fonts.define.specify.context_number(name)
- local t = setups[name]
- if not t then
- return default
- elseif t.auto then
- local lng = tonumber(tex.language)
- local tag = name .. ":" .. lng
- local s = setups[tag]
- if s then
- return s.number or default
- else
- local script, language = languages.association(lng)
- if t.script ~= script or t.language ~= language then
- local s = table.fastcopy(t)
- local n = #numbers + 1
- setups[tag] = s
- numbers[n] = tag
- s.number = n
- s.script = script
- s.language = language
- return n
- else
- setups[tag] = t
- return t.number or default
- end
- end
- else
- return t.number or default
+local function check_otf(specification,suffix,what)
+ local fullname, tfmtable = resolvers.findbinfile(specification.name,suffix) or "", nil
+ if fullname == "" then
+ local fb = fonts.names.old_to_new[specification.name]
+ if fb then
+ fullname = resolvers.findbinfile(fb,suffix) or ""
end
end
-
-end
-
-function fonts.define.specify.context_tostring(name,kind,separator,yes,no,strict,omit) -- not used
- return aux.hash_to_string(table.merged(fonts[kind].features.default or {},fonts.define.specify.context_setups[name] or {}),separator,yes,no,strict,omit)
-end
-
-function fonts.define.specify.split_context(features)
- if fonts.define.specify.context_setups[features] then
- return fonts.define.specify.context_setups[features]
- else -- ? ? ?
- return fonts.define.specify.preset_context("***",features)
+ if fullname == "" then
+ local fb = fonts.names.new_to_old[specification.name]
+ if fb then
+ fullname = resolvers.findbinfile(fb,suffix) or ""
+ end
+ end
+ if fullname ~= "" then
+ specification.filename, specification.format = fullname, what -- hm, so we do set the filename, then
+ tfmtable = tfm.read_from_open_type(specification) -- we need to do it for all matches / todo
end
+ return tfmtable
end
-local splitter = lpeg.splitat(",")
-
-function fonts.define.specify.starred(features) -- no longer fallbacks here
- local detail = features.detail
- if detail and detail ~= "" then
- features.features.normal = fonts.define.specify.split_context(detail)
+function readers.opentype(specification,suffix,what)
+ local forced = specification.forced or ""
+ if forced == "otf" then
+ return check_otf(specification,forced,"opentype")
+ elseif forced == "ttf" then
+ return check_otf(specification,forced,"truetype")
+ elseif forced == "ttf" then
+ return check_otf(specification,forced,"truetype")
else
- features.features.normal = { }
+ return check_otf(specification,suffix,what)
end
- return features
end
-fonts.define.register_split('*',fonts.define.specify.starred)
+function readers.otf(specification) return readers.opentype(specification,"otf","opentype") end
+function readers.ttf(specification) return readers.opentype(specification,"ttf","truetype") end
+function readers.ttc(specification) return readers.opentype(specification,"ttf","truetype") end -- !!
--[[ldx--
We need to check for default features. For this we provide
a helper function.
--ldx]]--
-function fonts.define.check(features,defaults) -- nb adapts features !
+function define.check(features,defaults) -- nb adapts features !
local done = false
if table.is_empty(features) then
features, done = table.fastcopy(defaults), true
else
- for k,v in pairs(defaults) do
+ for k,v in next, defaults do
if features[k] == nil then
features[k], done = v, true
end
@@ -601,43 +452,59 @@ not gain much. By the way, passing id's back to in the callback was
introduced later in the development.
--ldx]]--
-fonts.define.last = nil
+define.last = nil
-function fonts.define.register(fontdata,id)
+function define.register(fontdata,id)
if fontdata and id then
local hash = fontdata.hash
if not tfm.internalized[hash] then
- if fonts.trace then
+ if trace_defining then
logs.report("define font","loading at 2 id %s, hash: %s",id or "?",hash or "?")
end
- tfm.id[id] = fontdata
+ fonts.ids[id] = fontdata
tfm.internalized[hash] = id
end
end
end
-function fonts.define.registered(hash)
+function define.registered(hash)
local id = tfm.internalized[hash]
- return id, id and tfm.id[id]
+ return id, id and fonts.ids[id]
end
local cache_them = false
-function fonts.define.read(specification,size,id) -- id can be optional, name can already be table
- input.starttiming(fonts)
+function tfm.make(specification)
+ -- currently fonts are scaled while constructing the font, so we
+ -- have to do scaling of commands in the vf at that point using
+ -- e.g. "local scale = g.factor or 1" after all, we need to work
+ -- with copies anyway and scaling needs to be done at some point;
+ -- however, when virtual tricks are used as feature (makes more
+ -- sense) we scale the commands in fonts.tfm.scale (and set the
+ -- factor there)
+ local fvm = define.methods[specification.features.vtf.preset]
+ if fvm then
+ return fvm(specification)
+ else
+ return nil
+ end
+end
+
+function define.read(specification,size,id) -- id can be optional, name can already be table
+ statistics.starttiming(fonts)
if type(specification) == "string" then
- specification = fonts.define.analyze(specification,size)
+ specification = define.analyze(specification,size)
end
local method = specification.method
- if method and fonts.define.specify[method] then
- specification = fonts.define.specify[method](specification)
+ if method and define.specify[method] then
+ specification = define.specify[method](specification)
end
- specification = fonts.define.resolve(specification)
+ specification = define.resolve(specification)
local hash = tfm.hash_instance(specification)
if cache_them then
local fontdata = containers.read(fonts.cache(),hash) -- for tracing purposes
end
- local fontdata = fonts.define.registered(hash) -- id
+ local fontdata = define.registered(hash) -- id
if not fontdata then
if specification.features.vtf and specification.features.vtf.preset then
fontdata = tfm.make(specification)
@@ -652,15 +519,16 @@ function fonts.define.read(specification,size,id) -- id can be optional, name ca
end
if fontdata then
fontdata.hash = hash
+ fontdata.cache = "no"
if id then
- fonts.define.register(fontdata,id)
+ define.register(fontdata,id)
end
end
end
- fonts.define.last = fontdata or id -- todo ! ! ! ! !
+ define.last = fontdata or id -- todo ! ! ! ! !
if not fontdata then
logs.report("define font", "unknown font %s, loading aborted",specification.name)
- elseif fonts.trace and type(fontdata) == "table" then
+ elseif trace_defining and type(fontdata) == "table" then
logs.report("define font","using %s font with id %s, n:%s s:%s b:%s e:%s p:%s f:%s",
fontdata.type or "unknown",
id or "?",
@@ -671,148 +539,30 @@ function fonts.define.read(specification,size,id) -- id can be optional, name ca
fontdata.fullname or "?",
file.basename(fontdata.filename or "?"))
end
- input.stoptiming(fonts)
+ statistics.stoptiming(fonts)
return fontdata
end
--- define (two steps)
-
-local P, C, Cc = lpeg.P, lpeg.C, lpeg.Cc
-
-local space = P(" ")
-local spaces = space^0
-local value = C((1-space)^1)
-local rest = C(P(1)^0)
-local scale_none = Cc(0)
-local scale_at = P("at") * Cc(1) * spaces * value
-local scale_sa = P("sa") * Cc(2) * spaces * value
-local scale_mo = P("mo") * Cc(3) * spaces * value
-local scale_scaled = P("scaled") * Cc(4) * spaces * value
-
-local sizepattern = spaces * (scale_at + scale_sa + scale_mo + scale_scaled + scale_none)
-local splitpattern = spaces * value * spaces * rest
-
-local specification --
-
-function fonts.define.command_1(str)
- input.starttiming(fonts)
- local fullname, size = splitpattern:match(str)
- local lookup, name, sub, method, detail = fonts.define.get_specification(fullname)
- if not name then
- logs.report("define font","strange definition '%s'",str)
- texsprint(tex.ctxcatcodes,"\\glet\\somefontname\\defaultfontfile")
- elseif name == "unknown" then
- texsprint(tex.ctxcatcodes,"\\glet\\somefontname\\defaultfontfile")
- else
- texsprint(tex.ctxcatcodes,format("\\xdef\\somefontname{%s}",name))
- end
- -- we can also use a count for the size
- if size and size ~= "" then
- local mode, size = sizepattern:match(size)
- if size and mode then
- count.scaledfontmode = mode
- texsprint(tex.ctxcatcodes,format("\\def\\somefontsize{%s}",size))
- else
- count.scaledfontmode = 0
- texsprint(tex.ctxcatcodes,format("\\let\\somefontsize\\empty",size))
- end
- else
- count.scaledfontmode = 0
- texsprint(tex.ctxcatcodes,format("\\let\\somefontsize\\empty",size))
- end
- specification = fonts.define.makespecification(str,lookup,name,sub,method,detail,size)
-end
-
-function fonts.define.command_2(global,cs,name,size,classfeatures,fontfeatures,classfallbacks,fontfallbacks)
- local trace = fonts.trace
- -- name is now resolved and size is scaled cf sa/mo
- local lookup, name, sub, method, detail = fonts.define.get_specification(name or "")
- -- asome settings can be overloaded
- if lookup and lookup ~= "" then specification.lookup = lookup end
- specification.name = name
- specification.size = size
- specification.sub = sub
- if detail and detail ~= "" then
- specification.method, specification.detail = method or "*", detail
- elseif specification.detail and specification.detail ~= "" then
- -- already set
- elseif fontfeatures and fontfeatures ~= "" then
- specification.method, specification.detail = "*", fontfeatures
- elseif classfeatures and classfeatures ~= "" then
- specification.method, specification.detail = "*", classfeatures
- end
- if trace then
- logs.report("define font","memory usage before: %s",ctx.memused())
- end
-if fontfallbacks and fontfallbacks ~= "" then
- specification.fallbacks = fontfallbacks
-elseif classfallbacks and classfallbacks ~= "" then
- specification.fallbacks = classfallbacks
-end
- local tfmdata = fonts.define.read(specification,size) -- id not yet known
- if not tfmdata then
- logs.report("define font","unable to define %s as \\%s",name,cs)
- elseif type(tfmdata) == "number" then
- if trace then
- logs.report("define font","reusing %s with id %s as \\%s (features: %s/%s, fallbacks: %s/%s)",name,tfmdata,cs,classfeatures,fontfeatures,classfallbacks,fontfallbacks)
- end
- tex.definefont(global,cs,tfmdata)
- -- resolved (when designsize is used):
- texsprint(tex.ctxcatcodes,format("\\def\\somefontsize{%isp}",tfm.id[tfmdata].size))
- else
- -- local t = os.clock(t)
- local id = font.define(tfmdata)
- -- print(name,os.clock()-t)
- tfmdata.id = id
- fonts.define.register(tfmdata,id)
- tex.definefont(global,cs,id)
- tfm.cleanup_table(tfmdata)
- if fonts.trace then
- logs.report("define font","defining %s with id %s as \\%s (features: %s/%s, fallbacks: %s/%s)",name,id,cs,classfeatures,fontfeatures,classfallbacks,fontfallbacks)
- end
- -- resolved (when designsize is used):
- texsprint(tex.ctxcatcodes,format("\\def\\somefontsize{%isp}",tfmdata.size))
- --~ if specification.fallbacks then
- --~ fonts.collections.prepare(specification.fallbacks)
- --~ end
- end
- if trace then
- logs.report("define font","memory usage after: %s",ctx.memused())
- end
- input.stoptiming(fonts)
-end
-
-
---~ table.insert(tfm.readers.sequence,1,'vtf')
-
---~ function tfm.readers.vtf(specification)
---~ if specification.features.vtf and specification.features.vtf.preset then
---~ return tfm.make(specification)
---~ else
---~ return nil
---~ end
---~ end
-
-function fonts.vf.find(name)
+function vf.find(name)
name = file.removesuffix(file.basename(name))
if tfm.resolve_vf then
local format = fonts.logger.format(name)
if format == 'tfm' or format == 'ofm' then
- if fonts.trace then
+ if trace_defining then
logs.report("define font","locating vf for %s",name)
end
- return input.findbinfile(name,"ovf")
+ return resolvers.findbinfile(name,"ovf")
else
- if fonts.trace then
+ if trace_defining then
logs.report("define font","vf for %s is already taken care of",name)
end
return nil -- ""
end
else
- if fonts.trace then
+ if trace_defining then
logs.report("define font","locating vf for %s",name)
end
- return input.findbinfile(name,"ovf")
+ return resolvers.findbinfile(name,"ovf")
end
end
@@ -820,5 +570,5 @@ end
We overload both the and readers.
--ldx]]--
-callback.register('define_font' , fonts.define.read)
-callback.register('find_vf_file', fonts.vf.find ) -- not that relevant any more
+callback.register('define_font' , define.read)
+callback.register('find_vf_file', vf.find ) -- not that relevant any more
diff --git a/tex/context/base/font-dum.lua b/tex/context/base/font-dum.lua
new file mode 100644
index 000000000..0d28128d8
--- /dev/null
+++ b/tex/context/base/font-dum.lua
@@ -0,0 +1,113 @@
+if not modules then modules = { } end modules ['font-dum'] = {
+ version = 1.001,
+ comment = "companion to luatex-*.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+fonts = fonts or { }
+
+-- general
+
+fonts.otf.pack = false
+fonts.tfm.resolve_vf = false -- no sure about this
+
+-- readers
+
+fonts.tfm.readers = fonts.tfm.readers or { }
+fonts.tfm.readers.sequence = { 'otf', 'ttf', 'tfm' }
+fonts.tfm.readers.afm = nil
+
+-- define
+
+fonts.define = fonts.define or { }
+
+--~ fonts.define.method = "tfm"
+
+fonts.define.specify.colonized_default_lookup = "name"
+
+function fonts.define.get_specification(str)
+ return "", str, "", ":", str
+end
+
+-- logger
+
+fonts.logger = fonts.logger or { }
+
+function fonts.logger.save()
+end
+
+-- names
+
+fonts.names = fonts.names or { }
+
+fonts.names.basename = "luatex-fonts-names.lua"
+fonts.names.new_to_old = { }
+fonts.names.old_to_new = { }
+
+local data, loaded = nil, false
+
+function fonts.names.resolve(name,sub)
+ if not loaded then
+ local basename = fonts.names.basename
+ if basename and basename ~= "" then
+ for _, format in ipairs { "lua", "tex", "other text files" } do
+ local foundname = resolvers.find_file(basename,format) or ""
+ if foundname ~= "" then
+ data = dofile(foundname)
+ if data then
+ local d = { }
+ for k, v in pairs(data.mapping) do
+ local t = v[1]
+ if t == "ttf" or t == "otf" or t == "ttc" then
+ d[k] = v
+ end
+ end
+ data.mapping = d
+ end
+ break
+ end
+ end
+ end
+ loaded = true
+ end
+ if type(data) == "table" and data.version == 1.08 then
+ local condensed = string.gsub(name,"[^%a%d]","")
+ local found = data.mapping and data.mapping[condensed]
+ if found then
+ local filename, is_sub = found[3], found[4]
+ if is_sub then is_sub = found[2] end
+ return filename, is_sub
+ else
+ return name, false -- fallback to filename
+ end
+ end
+end
+
+-- For the moment we put this (adapted) pseudo feature here.
+
+table.insert(fonts.triggers,"itlc")
+
+local function itlc(tfmdata,value)
+ if value then
+ -- the magic 40 and it formula come from Dohyun Kim
+ local metadata = tfmdata.shared.otfdata.metadata
+ if metadata then
+ local italicangle = metadata.italicangle
+ if italicangle and italicangle ~= 0 then
+ local uwidth = (metadata.uwidth or 40)/2
+ for unicode, d in next, tfmdata.descriptions do
+ local it = d.boundingbox[3] - d.width + uwidth
+ if it ~= 0 then
+ d.italic = it
+ end
+ end
+ tfmdata.has_italic = true
+ end
+ end
+ end
+end
+
+fonts.initializers.base.otf.itlc = itlc
+fonts.initializers.node.otf.itlc = itlc
diff --git a/tex/context/base/font-enc.lua b/tex/context/base/font-enc.lua
index 86ace93c6..faeae3a10 100644
--- a/tex/context/base/font-enc.lua
+++ b/tex/context/base/font-enc.lua
@@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['font-enc'] = {
license = "see context related readme files"
}
+local match, gmatch, gsub = string.match, string.gmatch, string.gsub
+
--[[ldx--
Because encodings are going to disappear, we don't bother defining
them in tables. But we may do so some day, for consistency.
@@ -62,15 +64,15 @@ function fonts.enc.load(filename)
return data
end
local vector, tag, hash, unicodes = { }, "", { }, { }
- local foundname = input.find_file(filename,'enc')
+ local foundname = resolvers.find_file(filename,'enc')
if foundname and foundname ~= "" then
- local ok, encoding, size = input.loadbinfile(foundname)
+ local ok, encoding, size = resolvers.loadbinfile(foundname)
if ok and encoding then
local enccodes = characters.enccodes
- encoding = encoding:gsub("%%(.-)\n","")
- local tag, vec = encoding:match("/(%w+)%s*%[(.*)%]%s*def")
+ encoding = gsub(encoding,"%%(.-)\n","")
+ local tag, vec = match(encoding,"/(%w+)%s*%[(.*)%]%s*def")
local i = 0
- for ch in vec:gmatch("/([%a%d%.]+)") do
+ for ch in gmatch(vec,"/([%a%d%.]+)") do
if ch ~= ".notdef" then
vector[i] = ch
if not hash[ch] then
@@ -105,7 +107,7 @@ one.
function fonts.enc.make_unicode_vector()
local vector, hash = { }, { }
- for code, v in pairs(characters.data) do
+ for code, v in next, characters.data do
local name = v.adobename
if name then
vector[code], hash[name] = name, code
@@ -113,7 +115,7 @@ function fonts.enc.make_unicode_vector()
vector[code] = '.notdef'
end
end
- for name, code in pairs(characters.synonyms) do
+ for name, code in next, characters.synonyms do
vector[code], hash[name] = name, code
end
return containers.write(fonts.enc.cache(), 'unicode', { name='unicode', tag='unicode', vector=vector, hash=hash })
diff --git a/tex/context/base/font-ext.lua b/tex/context/base/font-ext.lua
index c3979fad6..17c302c53 100644
--- a/tex/context/base/font-ext.lua
+++ b/tex/context/base/font-ext.lua
@@ -6,7 +6,191 @@ if not modules then modules = { } end modules ['font-ext'] = {
license = "see context related readme files"
}
-local byte = string.byte
+local next, type, byte = next, type, string.byte
+
+--[[ldx--
+
When we implement functions that deal with features, most of them
+will depend of the font format. Here we define the few that are kind
+of neutral.
+--ldx]]--
+
+fonts.triggers = fonts.triggers or { }
+fonts.initializers = fonts.initializers or { }
+fonts.initializers.common = fonts.initializers.common or { }
+
+local initializers = fonts.initializers
+
+--[[ldx--
+
This feature will remove inter-digit kerns.
+--ldx]]--
+
+table.insert(fonts.triggers,"equaldigits")
+
+function initializers.common.equaldigits(tfmdata,value)
+ if value then
+ local chr = tfmdata.characters
+ for i = utfbyte('0'), utfbyte('9') do
+ local c = chr[i]
+ if c then
+ c.kerns = nil
+ end
+ end
+ end
+end
+
+--[[ldx--
+
This feature will give all glyphs an equal height and/or depth. Valid
+values are none, height, depth and
+both.
+--ldx]]--
+
+table.insert(fonts.triggers,"lineheight")
+
+function initializers.common.lineheight(tfmdata,value)
+ if value and type(value) == "string" then
+ if value == "none" then
+ for _,v in next, tfmdata.characters do
+ v.height, v.depth = 0, 0
+ end
+ else
+ local ascender, descender = tfmdata.ascender, tfmdata.descender
+ if ascender and descender then
+ local ht, dp = ascender or 0, descender or 0
+ if value == "height" then
+ dp = 0
+ elseif value == "depth" then
+ ht = 0
+ end
+ if ht > 0 then
+ if dp > 0 then
+ for _,v in next, tfmdata.characters do
+ v.height, v.depth = ht, dp
+ end
+ else
+ for _,v in next, tfmdata.characters do
+ v.height = ht
+ end
+ end
+ elseif dp > 0 then
+ for _,v in next, tfmdata.characters do
+ v.depth = dp
+ end
+ end
+ end
+ end
+ end
+end
+
+--[[ldx--
+
It does not make sense any more to support messed up encoding vectors
+so we stick to those that implement oldstyle and small caps. After all,
+we move on. We can extend the next function on demand. This features is
+only used with files.
+--ldx]]--
+
+--~ do
+--~
+--~ local smallcaps = lpeg.P(".sc") + lpeg.P(".smallcaps") + lpeg.P(".caps") + lpeg.P("small")
+--~ local oldstyle = lpeg.P(".os") + lpeg.P(".oldstyle") + lpeg.P(".onum")
+--~
+--~ smallcaps = lpeg.Cs((1-smallcaps)^1) * smallcaps^1
+--~ oldstyle = lpeg.Cs((1-oldstyle )^1) * oldstyle ^1
+--~
+--~ function initializers.common.encoding(tfmdata,value)
+--~ if value then
+--~ local afmdata = tfmdata.shared.afmdata
+--~ if afmdata then
+--~ local encodingfile = value .. '.enc'
+--~ local encoding = fonts.enc.load(encodingfile)
+--~ if encoding then
+--~ local vector = encoding.vector
+--~ local characters = tfmdata.characters
+--~ local unicodes = afmdata.luatex.unicodes
+--~ local function remap(pattern,name)
+--~ local p = pattern:match(name)
+--~ if p then
+--~ local oldchr, newchr = unicodes[p], unicodes[name]
+--~ if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
+--~ -- logs.report("encoding","%s (%s) -> %s (%s)",p,oldchr or -1,name,newchr or -1)
+--~ characters[oldchr] = characters[newchr]
+--~ end
+--~ end
+--~ return p
+--~ end
+--~ for _, name in next, vector do
+--~ local ok = remap(smallcaps,name) or remap(oldstyle,name)
+--~ end
+--~ if fonts.map.data[tfmdata.name] then
+--~ fonts.map.data[tfmdata.name].encoding = encodingfile
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~
+--~ -- when needed we can provide this as features in e.g. afm files
+--~
+--~ function initializers.common.remap(tfmdata,value,pattern) -- will go away
+--~ if value then
+--~ local afmdata = tfmdata.shared.afmdata
+--~ if afmdata then
+--~ local characters = tfmdata.characters
+--~ local descriptions = tfmdata.descriptions
+--~ local unicodes = afmdata.luatex.unicodes
+--~ local done = false
+--~ for u, _ in next, characters do
+--~ local name = descriptions[u].name
+--~ if name then
+--~ local p = pattern:match(name)
+--~ if p then
+--~ local oldchr, newchr = unicodes[p], unicodes[name]
+--~ if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
+--~ characters[oldchr] = characters[newchr]
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~
+--~ function initializers.common.oldstyle(tfmdata,value)
+--~ initializers.common.remap(tfmdata,value,oldstyle)
+--~ end
+--~ function initializers.common.smallcaps(tfmdata,value)
+--~ initializers.common.remap(tfmdata,value,smallcaps)
+--~ end
+--~
+--~ function initializers.common.fakecaps(tfmdata,value)
+--~ if value then
+--~ -- todo: scale down
+--~ local afmdata = tfmdata.shared.afmdata
+--~ if afmdata then
+--~ local characters = tfmdata.characters
+--~ local descriptions = tfmdata.descriptions
+--~ local unicodes = afmdata.luatex.unicodes
+--~ for u, _ in next, characters do
+--~ local name = descriptions[u].name
+--~ if name then
+--~ local p = lower(name)
+--~ if p then
+--~ local oldchr, newchr = unicodes[p], unicodes[name]
+--~ if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
+--~ characters[oldchr] = characters[newchr]
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~ end
+--~
+--~ end
+--~
+--~ function initializers.common.install(format,feature) -- 'afm','lineheight'
+--~ initializers.base[format][feature] = initializers.common[feature]
+--~ initializers.node[format][feature] = initializers.common[feature]
+--~ end
-- -- -- -- -- --
-- expansion (hz)
@@ -16,19 +200,23 @@ fonts.expansions = fonts.expansions or { }
fonts.expansions.classes = fonts.expansions.classes or { }
fonts.expansions.vectors = fonts.expansions.vectors or { }
+local expansions = fonts.expansions
+local classes = fonts.expansions.classes
+local vectors = fonts.expansions.vectors
+
-- beware, pdftex itself uses percentages * 10
-fonts.expansions.classes.preset = { stretch = 2, shrink = 2, step = .5, factor = 1 }
+classes.preset = { stretch = 2, shrink = 2, step = .5, factor = 1 }
function commands.setupfontexpansion(class,settings)
- aux.getparameters(fonts.expansions.classes,class,'preset',settings)
+ aux.getparameters(classes,class,'preset',settings)
end
-fonts.expansions.classes['quality'] = {
+classes['quality'] = {
stretch = 2, shrink = 2, step = .5, vector = 'default', factor = 1
}
-fonts.expansions.vectors['default'] = {
+vectors['default'] = {
[byte('A')] = 0.5, [byte('B')] = 0.7, [byte('C')] = 0.7, [byte('D')] = 0.5, [byte('E')] = 0.7,
[byte('F')] = 0.7, [byte('G')] = 0.5, [byte('H')] = 0.7, [byte('K')] = 0.7, [byte('M')] = 0.7,
[byte('N')] = 0.7, [byte('O')] = 0.5, [byte('P')] = 0.7, [byte('Q')] = 0.5, [byte('R')] = 0.7,
@@ -40,11 +228,11 @@ fonts.expansions.vectors['default'] = {
[byte('2')] = 0.7, [byte('3')] = 0.7, [byte('6')] = 0.7, [byte('8')] = 0.7, [byte('9')] = 0.7,
}
-function fonts.initializers.common.expansion(tfmdata,value)
+function initializers.common.expansion(tfmdata,value)
if value then
- local class = fonts.expansions.classes[value]
+ local class = classes[value]
if class then
- local vector = fonts.expansions.vectors[class.vector]
+ local vector = vectors[class.vector]
if vector then
tfmdata.stretch = (class.stretch or 0) * 10
tfmdata.shrink = (class.shrink or 0) * 10
@@ -52,7 +240,7 @@ function fonts.initializers.common.expansion(tfmdata,value)
tfmdata.auto_expand = true
local factor = class.factor or 1
local data = characters.data
- for i, chr in pairs(tfmdata.characters) do
+ for i, chr in next, tfmdata.characters do
local v = vector[i]
if not v then
local d = data[i]
@@ -80,11 +268,11 @@ end
table.insert(fonts.manipulators,"expansion")
-fonts.initializers.base.otf.expansion = fonts.initializers.common.expansion
-fonts.initializers.node.otf.expansion = fonts.initializers.common.expansion
+initializers.base.otf.expansion = initializers.common.expansion
+initializers.node.otf.expansion = initializers.common.expansion
-fonts.initializers.base.afm.expansion = fonts.initializers.common.expansion
-fonts.initializers.node.afm.expansion = fonts.initializers.common.expansion
+initializers.base.afm.expansion = initializers.common.expansion
+initializers.node.afm.expansion = initializers.common.expansion
-- -- -- -- -- --
-- protrusion
@@ -94,28 +282,32 @@ fonts.protrusions = fonts.protrusions or { }
fonts.protrusions.classes = fonts.protrusions.classes or { }
fonts.protrusions.vectors = fonts.protrusions.vectors or { }
+local protrusions = fonts.protrusions
+local classes = fonts.protrusions.classes
+local vectors = fonts.protrusions.vectors
+
-- the values need to be revisioned
-fonts.protrusions.classes.preset = { factor = 1 }
+classes.preset = { factor = 1 }
function commands.setupfontprotrusion(class,settings)
- aux.getparameters(fonts.protrusions.classes,class,'preset',settings)
+ aux.getparameters(classes,class,'preset',settings)
end
-fonts.protrusions.classes['pure'] = {
+classes['pure'] = {
vector = 'pure', factor = 1
}
-fonts.protrusions.classes['punctuation'] = {
+classes['punctuation'] = {
vector = 'punctuation', factor = 1
}
-fonts.protrusions.classes['alpha'] = {
+classes['alpha'] = {
vector = 'alpha', factor = 1
}
-fonts.protrusions.classes['quality'] = {
+classes['quality'] = {
vector = 'quality', factor = 1
}
-fonts.protrusions.vectors['pure'] = {
+vectors['pure'] = {
[0x002C] = { 0, 1 }, -- comma
[0x002E] = { 0, 1 }, -- period
@@ -126,10 +318,13 @@ fonts.protrusions.vectors['pure'] = {
[0x2014] = { 0, 0.33 }, -- emdash
[0x3001] = { 0, 1 }, -- ideographic comma 、
[0x3002] = { 0, 1 }, -- ideographic full stop 。
+ [0x060C] = { 0, 1 }, -- arabic comma ،
+ [0x061B] = { 0, 1 }, -- arabic semicolon ؛
+ [0x06D4] = { 0, 1 }, -- arabic full stop ۔
}
-fonts.protrusions.vectors['punctuation'] = {
+vectors['punctuation'] = {
[0x003F] = { 0, 0.20 }, -- ?
[0x00BF] = { 0, 0.20 }, -- ¿
@@ -146,6 +341,10 @@ fonts.protrusions.vectors['punctuation'] = {
[0x002D] = { 0, 0.70 }, -- hyphen
[0x2013] = { 0, 0.30 }, -- endash
[0x2014] = { 0, 0.20 }, -- emdash
+ [0x060C] = { 0, 0.70 }, -- arabic comma
+ [0x061B] = { 0, 0.50 }, -- arabic semicolon
+ [0x06D4] = { 0, 0.70 }, -- arabic full stop
+ [0x061F] = { 0, 0.20 }, -- ؟
-- todo: left and right quotes: .5 double, .7 single
@@ -165,7 +364,7 @@ fonts.protrusions.vectors['punctuation'] = {
}
-fonts.protrusions.vectors['alpha'] = {
+vectors['alpha'] = {
[byte("A")] = { .05, .05 },
[byte("F")] = { 0, .05 },
@@ -188,21 +387,22 @@ fonts.protrusions.vectors['alpha'] = {
}
-fonts.protrusions.vectors['quality'] = table.merge( {},
- fonts.protrusions.vectors['punctuation'],
- fonts.protrusions.vectors['alpha']
+vectors['quality'] = table.merge( {},
+ vectors['punctuation'],
+ vectors['alpha']
)
-function fonts.initializers.common.protrusion(tfmdata,value)
+function initializers.common.protrusion(tfmdata,value)
if value then
- local class = fonts.protrusions.classes[value]
+ local class = classes[value]
if class then
- local vector = fonts.protrusions.vectors[class.vector]
+ local vector = vectors[class.vector]
if vector then
local factor = class.factor or 1
local data = characters.data
local emwidth = tfmdata.parameters.quad
- for i, chr in pairs(tfmdata.characters) do
+ tfmdata.auto_protrude = true
+ for i, chr in next, tfmdata.characters do
local v, pl, pr = vector[i], nil, nil
if v then
pl, pr = v[1], v[2]
@@ -234,8 +434,46 @@ end
table.insert(fonts.manipulators,"protrusion")
-fonts.initializers.base.otf.protrusion = fonts.initializers.common.protrusion
-fonts.initializers.node.otf.protrusion = fonts.initializers.common.protrusion
+initializers.base.otf.protrusion = initializers.common.protrusion
+initializers.node.otf.protrusion = initializers.common.protrusion
+
+initializers.base.afm.protrusion = initializers.common.protrusion
+initializers.node.afm.protrusion = initializers.common.protrusion
+
+function initializers.common.nostackmath(tfmdata,value)
+ tfmdata.ignore_stack_math = value
+end
+
+table.insert(fonts.manipulators,"nostackmath")
+
+initializers.base.otf.nostackmath = initializers.common.nostackmath
+initializers.node.otf.nostackmath = initializers.common.nostackmath
+
+table.insert(fonts.triggers,"itlc")
+
+function initializers.common.itlc(tfmdata,value)
+ if value then
+ -- the magic 40 and it formula come from Dohyun Kim
+ local fontdata = tfmdata.shared.otfdata or tfmdata.shared.afmdata
+ local metadata = fontdata and fontdata.metadata
+ if metadata then
+ local italicangle = metadata.italicangle
+ if italicangle and italicangle ~= 0 then
+ local uwidth = (metadata.uwidth or 40)/2
+ for unicode, d in next, tfmdata.descriptions do
+ local it = d.boundingbox[3] - d.width + uwidth
+ if it ~= 0 then
+ d.italic = it
+ end
+ end
+ tfmdata.has_italic = true
+ end
+ end
+ end
+end
+
+initializers.base.otf.itlc = initializers.common.itlc
+initializers.node.otf.itlc = initializers.common.itlc
-fonts.initializers.base.afm.protrusion = fonts.initializers.common.protrusion
-fonts.initializers.node.afm.protrusion = fonts.initializers.common.protrusion
+initializers.base.afm.itlc = initializers.common.itlc
+initializers.node.afm.itlc = initializers.common.itlc
diff --git a/tex/context/base/font-fbk.lua b/tex/context/base/font-fbk.lua
index d3287c393..6c4f78a3c 100644
--- a/tex/context/base/font-fbk.lua
+++ b/tex/context/base/font-fbk.lua
@@ -6,34 +6,37 @@ if not modules then modules = { } end modules ['font-fbk'] = {
license = "see context related readme files"
}
+local cos, tan, rad, format = math.cos, math.tan, math.rad, string.format
+
+local trace_combining = false trackers.register("fonts.combining", function(v) trace_combining = v end)
+
--[[ldx--
This is very experimental code!
--ldx]]--
-fonts.fallbacks = fonts.fallbacks or { }
-fonts.vf.aux.combine.trace = false
+fonts.fallbacks = fonts.fallbacks or { }
local vf = fonts.vf
local tfm = fonts.tfm
vf.aux.combine.commands["enable-tracing"] = function(g,v)
- vf.aux.combine.trace = true
+ trace_combining = true
end
vf.aux.combine.commands["disable-tracing"] = function(g,v)
- vf.aux.combine.trace = false
+ trace_combining = false
end
vf.aux.combine.commands["set-tracing"] = function(g,v)
if v[2] == nil then
- vf.aux.combine.trace = true
+ trace_combining = true
else
- vf.aux.combine.trace = v[2]
+ trace_combining = v[2]
end
end
function vf.aux.combine.initialize_trace()
- if vf.aux.combine.trace then
+ if trace_combining then
return "special", "pdf: .8 0 0 rg .8 0 0 RG", "pdf: 0 .8 0 rg 0 .8 0 RG", "pdf: 0 0 .8 rg 0 0 .8 RG", "pdf: 0 g 0 G"
else
return "comment", "", "", "", ""
@@ -54,7 +57,7 @@ end
fonts.fallbacks['textcent'] = function (g)
local c = ("c"):byte()
local t = table.fastcopy(g.characters[c])
- local a = - math.tan(math.rad(g.italicangle or 0))
+ local a = - tan(rad(g.italicangle or 0))
local special, red, green, blue, black = vf.aux.combine.initialize_trace()
local quad = g.parameters.quad
if a == 0 then
@@ -71,7 +74,7 @@ fonts.fallbacks['textcent'] = function (g)
{"push"},
{"right", .5*t.width-.025*quad},
{"down", .2*t.height},
- {"special",("pdf: q 1 0 %s 1 0 0 cm"):format(a)},
+ {"special",format("pdf: q 1 0 %s 1 0 0 cm",a)},
{special, green},
{"rule", 1.4*t.height, .025*quad},
{special, black},
@@ -84,6 +87,7 @@ fonts.fallbacks['textcent'] = function (g)
-- todo: set height
t.height = 1.2*t.height
t.depth = 0.2*t.height
+ g.virtualized = true
local d = g.descriptions
return t, d and d[c]
end
@@ -91,7 +95,7 @@ end
fonts.fallbacks['texteuro'] = function (g)
local c = ("C"):byte()
local t = table.fastcopy(g.characters[c])
- local d = math.cos(math.rad(90+(g.italicangle)))
+ local d = cos(rad(90+(g.italicangle)))
local special, red, green, blue, black = vf.aux.combine.initialize_trace()
local quad = g.parameters.quad
t.width = 1.05*t.width
@@ -104,6 +108,7 @@ fonts.fallbacks['texteuro'] = function (g)
{"rule", .05*quad, .4*quad},
{special, black},
}
+ g.virtualized = true
return t, g.descriptions[c]
end
@@ -111,6 +116,10 @@ end
vf.aux.combine.force_composed = false
+local push, pop = { "push" }, { "pop" }
+
+local cache = { } -- we could make these weak
+
function vf.aux.compose_characters(g) -- todo: scaling depends on call location
-- this assumes that slot 1 is self, there will be a proper self some day
local chars, descs = g.characters, g.descriptions
@@ -120,14 +129,16 @@ function vf.aux.compose_characters(g) -- todo: scaling depends on call location
if xchar and xdesc then
local scale = g.factor or 1
local cap_lly = scale*xdesc.boundingbox[4]
- local ita_cor = math.cos(math.rad(90+(g.italicangle or 0)))
+ local ita_cor = cos(rad(90+(g.italicangle or 0)))
local force = vf.aux.combine.force_composed
local fallbacks = characters.fallbacks
- local special, red, green, blue, black = vf.aux.combine.initialize_trace()
- red, green, blue, black = { special, red }, { special, green }, { special, blue }, { special, black }
- local push, pop = { "push" }, { "pop" }
- local trace = vf.aux.combine.trace -- saves mem
- for i,c in pairs(characters.data) do
+ local special, red, green, blue, black
+ if trace_combining then
+ special, red, green, blue, black = vf.aux.combine.initialize_trace()
+ red, green, blue, black = { special, red }, { special, green }, { special, blue }, { special, black }
+ end
+ local done = false
+ for i,c in next, characters.data do
if force or not chars[i] then
local s = c.specials
if s and s[1] == 'char' then
@@ -138,17 +149,35 @@ function vf.aux.compose_characters(g) -- todo: scaling depends on call location
if cc == 'll' or cc == 'lu' or cc == 'lt' then
local acc = s[3]
local t = { }
- for k, v in pairs(charschr) do
+ for k, v in next, charschr do
if k ~= "commands" then
t[k] = v
end
end
local charsacc = chars[acc]
+--~ local ca = charsacc.category
+--~ if ca == "mn" then
+--~ -- mark nonspacing
+--~ elseif ca == "ms" then
+--~ -- mark spacing combining
+--~ elseif ca == "me" then
+--~ -- mark enclosing
+--~ else
if not charsacc then
acc = fallbacks[acc]
charsacc = acc and chars[acc]
end
if charsacc then
+ local chr_t = cache[chr]
+ if not cht_t then
+ chr_t = {"slot", 1, chr}
+ cache[chr] = chr_t
+ end
+ local acc_t = cache[acc]
+ if not acc_t then
+ acc_t = {"slot", 1, acc}
+ cache[acc] = acc_t
+ end
local cb = descs[chr].boundingbox
local ab = descs[acc].boundingbox
if cb and ab then
@@ -158,77 +187,75 @@ function vf.aux.compose_characters(g) -- todo: scaling depends on call location
local dx = (c_urx - a_urx - a_llx + c_llx)/2
local dd = (c_urx - c_llx)*ita_cor
if a_ury < 0 then
- -- local dy = cap_lly-a_lly
- if trace then
+ if trace_combining then
t.commands = {
push,
{"right", dx-dd},
- -- {"down", -dy}, -- added
red,
- {"slot", 1, acc},
+ acc_t,
black,
pop,
- {"slot", 1, chr},
+ chr_t,
}
else
t.commands = {
push,
{"right", dx-dd},
- -- {"down", -dy}, -- added
- {"slot", 1, acc},
+ acc_t,
pop,
- {"slot", 1, chr},
+ chr_t,
}
end
elseif c_ury > a_lly then
local dy = cap_lly-a_lly
- if trace then
+ if trace_combining then
t.commands = {
push,
{"right", dx+dd},
{"down", -dy},
green,
- {"slot", 1, acc},
+ acc_t,
black,
pop,
- {"slot", 1, chr},
+ chr_t,
}
else
t.commands = {
push,
{"right", dx+dd},
{"down", -dy},
- {"slot", 1, acc},
+ acc_t,
pop,
- {"slot", 1, chr},
+ chr_t,
}
end
else
- if trace then
+ if trace_combining then
t.commands = {
{"push"},
{"right", dx+dd},
blue,
- {"slot", 1, acc},
+ acc_t,
black,
{"pop"},
- {"slot", 1, chr},
+ chr_t,
}
else
t.commands = {
{"push"},
{"right", dx+dd},
- {"slot", 1, acc},
+ acc_t,
{"pop"},
- {"slot", 1, chr},
+ chr_t,
}
end
end
+ done = true
end
end
chars[i] = t
local d = { }
- for k, v in pairs(descs[chr]) do
+ for k, v in next, descs[chr] do
d[k] = v
end
d.name = c.adobename or "unknown"
@@ -239,6 +266,9 @@ function vf.aux.compose_characters(g) -- todo: scaling depends on call location
end
end
end
+ if done then
+ g.virtualized = true
+ end
end
end
diff --git a/tex/context/base/font-ini.lua b/tex/context/base/font-ini.lua
index 5db2973a1..248a2baca 100644
--- a/tex/context/base/font-ini.lua
+++ b/tex/context/base/font-ini.lua
@@ -10,34 +10,44 @@ if not modules then modules = { } end modules ['font-ini'] = {
Not much is happening here.
--ldx]]--
+local utf = unicode.utf8
+
+if not fontloader then fontloader = fontforge end
+
+fontloader.totable = fontloader.to_table
+
-- vtf comes first
-- fix comes last
-fonts = fonts or { }
+fonts = fonts or { }
+fonts.ids = fonts.ids or { } -- aka fontdata
+fonts.tfm = fonts.tfm or { }
-fonts.trace = false -- true
fonts.mode = 'base'
-fonts.private = 0xE000
+fonts.private = 0xF0000 -- 0x10FFFF
fonts.verbose = false -- more verbose cache tables
-fonts.methods = {
+fonts.methods = fonts.methods or {
base = { tfm = { }, afm = { }, otf = { }, vtf = { }, fix = { } },
node = { tfm = { }, afm = { }, otf = { }, vtf = { }, fix = { } },
}
-fonts.initializers = {
+fonts.initializers = fonts.initializers or {
base = { tfm = { }, afm = { }, otf = { }, vtf = { }, fix = { } },
node = { tfm = { }, afm = { }, otf = { }, vtf = { }, fix = { } }
}
-fonts.triggers = {
+fonts.triggers = fonts.triggers or {
'mode',
'language',
'script',
'strategy',
}
-fonts.manipulators = {
+fonts.processors = fonts.processors or {
+}
+
+fonts.manipulators = fonts.manipulators or {
}
fonts.define = fonts.define or { }
@@ -48,18 +58,35 @@ fonts.define.specify.synonyms = fonts.define.specify.synonyms or { }
fonts.color = fonts.color or { }
-fonts.color.trace = false
-
-local attribute = attributes.numbers['color'] or 7 -- we happen to know this -)
-local mapping = attributes.list[attribute]
+local attribute = attributes.private('color')
+local mapping = (attributes and attributes.list[attribute]) or { }
local set_attribute = node.set_attribute
local unset_attribute = node.unset_attribute
function fonts.color.set(n,c)
--- local mc = mapping[c] if mc then unset_attribute((n,attribute) else set_attribute(n,attribute,mc) end
- set_attribute(n,attribute,mapping[c] or -1) -- also handles -1 now
+ local mc = mapping[c]
+ if not mc then
+ unset_attribute(n,attribute)
+ else
+ set_attribute(n,attribute,mc)
+ end
end
function fonts.color.reset(n)
unset_attribute(n,attribute)
end
+
+-- this will change ...
+
+function fonts.show_char_data(n)
+ local tfmdata = fonts.ids[font.current()]
+ if tfmdata then
+ if type(n) == "string" then
+ n = utf.byte(n)
+ end
+ local chr = tfmdata.characters[n]
+ if chr then
+ texio.write_nl(table.serialize(chr,string.format("U_%04X",n)))
+ end
+ end
+end
diff --git a/tex/context/base/font-ini.mkii b/tex/context/base/font-ini.mkii
index 9b9f5ac83..658d06f70 100644
--- a/tex/context/base/font-ini.mkii
+++ b/tex/context/base/font-ini.mkii
@@ -12,7 +12,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Font Macros (ini)}
+\writestatus{loading}{ConTeXt Font Macros / Initialization}
\unprotect
@@ -121,125 +121,21 @@
%%% message 14 added
-\startmessages dutch library: fonts
- title: korps
- 1: codering --
- 2: variant -- wordt geladen
- 3: onbekende variant --
- 4: korps -- is niet gedefinieerd
- 5: stijl -- is niet gedefinieerd
- 6: -- wordt geladen
- 7: onbekend formaat --
- 8: stijl -- gedefinieerd
-% 9: mapping -- is geladen
- 10: onbekende font file --
- 14: korps -- is gedefinieerd (kan beter globaal plaatsvinden)
-\stopmessages
-
-\startmessages english library: fonts
- title: bodyfont
- 1: coding --
- 2: variant -- is loaded
- 3: unknown variant --
- 4: bodyfont -- is not defined
- 5: style -- is not defined
- 6: -- is loaded
- 7: unknown format --
- 8: style -- defined
-% 9: mapping -- is loaded
- 10: unknown font file --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages german library: fonts
- title: Fliesstext
- 1: Kodierung --
- 2: Variante -- ist geladen
- 3: Unbekannte Variante --
- 4: Fliesstext -- ist nicht definiert
- 5: Stil -- ist nicht definiert
- 6: -- ist geladen
- 7: unbekanntes Format --
- 8: Stil -- definiert
-% 9: Map -- ist geladen
- 10: unbekanntes Font --
- 14: Fliesstext -- wurde definiert (besser waere globale Definition)
-\stopmessages
-
-\startmessages czech library: fonts
- title: zakladnifont
- 1: kodovani --
- 2: varianta -- je nactena
- 3: neznama varianta --
- 4: zakladni font -- neni definovan
- 5: styl -- neni definovan
- 6: -- je nacten
- 7: neznamy format --
- 8: styl -- definovan
-% 9: mapovani -- je nacteno
- 10: neznamy font --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages italian library: fonts
- title: font del corpo
- 1: codifica --
- 2: variante -- caricata
- 3: variante sconosciuta --
- 4: corpo del testo -- non definito
- 5: stile -- non definito
- 6: -- caricato
- 7: formato sconosciuto --
- 8: stile -- definito
-% 9: mappatura -- caricata
- 10: file di font sconosciuto --
- 14: corpo del testo -- definito (sarebbe meglio globale)
-\stopmessages
-
-\startmessages norwegian library: fonts
- title: hovedfont
- 1: koding --
- 2: variant -- er lest inn
- 3: ukjent variant --
- 4: hovedfont -- er ikke definert
- 5: stil -- er ikke definert
- 6: -- er lest inn
- 7: ukjent format --
- 8: stil -- definert
-% 9: avbildning -- er lest inn
- 10: ukjent fontfil --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages romanian library: fonts
- title: corp de litere
- 1: codificarea --
- 2: varianta -- este incarcata
- 3: varianta necunoscuta --
- 4: corpul de litere -- nu este definit
- 5: stilul -- nu este definit
- 6: -- este incarcat
- 7: format necunoscut --
- 8: stilul -- definit
-% 9: maparea -- este incarcat
- 10: fisier font necunoscut --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages french library: fonts
- title: corps de texte
- 1: encodage --
- 2: la variante -- est chargée
- 3: variante -- inconnue
- 4: policecorps -- n'est pas définie
- 5: le style -- n'est pas défini
- 6: -- est chargé
- 7: format -- inconnu
- 8: style -- défini
-% 9: mapping -- is loaded
- 10: fichier de police -- inconnu
- 14: policecorps -- est défini (une définition globale pourrait être plus adéquat)
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
%D This module is one of the oldest modules of \CONTEXT. The
%D macros below evolved out of the \PLAIN\ \TEX\ macros and
@@ -682,8 +578,6 @@
%D
%D We can fix this by defining
-\let\normalmathop\mathop
-
\unexpanded\def\mathop
{\normalmathop
\bgroup
@@ -694,8 +588,6 @@
%D \TEX\ primitive \type{\hbox}:
%D
%D \starttyping
-%D \let\normalhbox=\hbox
-%D
%D \def\hbox{\ifmmode\mbox\else\normalhbox\fi}
%D \stoptyping
%D
@@ -875,6 +767,7 @@
\def\@shortstyle@ {@f@sh@} % short style prefix (rm etc)
\def\@letter@ {@f@le@} % first alternative typeface
\def\@noletter@ {@f@no@} % second alternative typeface
+\def\@fontclass@ {@f@cl@} % fontclass
%D The families can be grouped into math specific ones and
%D more text related families, although text ones can be
@@ -1060,9 +953,7 @@
%D separated list. Appart from practical limitations one can
%D define as many styles as needed.
-\let\stylelist=\empty
-
-\def\fontsizelist{\s!text,\s!script,\s!scriptscript,\c!x,\c!xx,\c!big,\c!small}
+\def\fontrelativesizelist{\s!text,\s!script,\s!scriptscript,\c!x,\c!xx,\c!big,\c!small}
%D \macros
%D {magfactor,magfactorhalf}
@@ -1099,7 +990,7 @@
%D \stoptable
\def\magstep#1% \relax removed, otherwise space after it sticks, else added
- {\ifcase#1 \@m\or1200\or1440\or1728\or2074\or2488\or\@m\fi}
+ {\ifcase#1 1000\or1200\or1440\or1728\or2074\or2488\or1000\fi}
\def\magstephalf
{1095}
@@ -1287,25 +1178,21 @@
% [encoding=ec]
% \definedfont[blabla] test \currentencoding/\fontfile \par
-\beginOLDTEX
-
- \def\checkfontfilename
- {\expandafter\docheckfontfilename\fontfile:\empty:\empty\relax}
-
- \def\docheckfontfilename#1:#2:#3#4\relax
- {\edef\!!stringa{#1}%
- \edef\!!stringb{#2}%
- \ifx\!!stringb\empty
- \edef\checkedfontfile{\!!stringa}%
- \else\ifx\!!stringa\v!file
- \edef\checkedfontfile{"\!!stringb"}%
- \else\ifx\!!stringa\v!name
- \edef\checkedfontfile{"\!!stringb"}%
- \else
- \edef\checkedfontfile{\!!stringb}%
- \fi\fi\fi}
-
-\endOLDTEX
+\def\checkfontfilename
+ {\expandafter\docheckfontfilename\fontfile:\empty:\empty\relax}
+
+\def\docheckfontfilename#1:#2:#3#4\relax
+ {\edef\!!stringa{#1}%
+ \edef\!!stringb{#2}%
+ \ifx\!!stringb\empty
+ \edef\checkedfontfile{\!!stringa}%
+ \else\ifx\!!stringa\v!file
+ \edef\checkedfontfile{"\!!stringb"}%
+ \else\ifx\!!stringa\v!name
+ \edef\checkedfontfile{"\!!stringb"}%
+ \else
+ \edef\checkedfontfile{\!!stringb}%
+ \fi\fi\fi}
% \definefontfeature[default] [liga=yes,texligatures=yes,texquotes=yes]
% \definefontfeature[default-caps][liga=yes,texligatures=yes,texquotes=yes,smcp=yes,script=latn]
@@ -1389,156 +1276,6 @@
%
% \stoptext
-% xetex / todo: disable default features ! file:, name:, [], "" etc etc
-
-\beginXETEX
-
- % for some reason xetex does not support [filename] for tfm files and
- % quotes also behave kind of strange " vs ' vs [ vs ...
-
- % we need to use the specs,
- %
- % \font\myfont = msam7 % ok
- % \font\myfont = "msam7" % also ok
- % \font\myfont = "msam7" at 8pt % error
-
- \ifx\suppressfontnotfounderror\undefined
-
- \newcount\xetexsavedinteractionmode
- \newbox \xetexcrappyhackbox
-
- \def\doiffoundxetexfontelse#1#2%
- {\xetexsavedinteractionmode\interactionmode
- \batchmode
- \setbox\xetexcrappyhackbox\vbox{\par}% resets error count
- \font\xetextempfont=#2\somefontspec\relax
- \edef\xetextempfont{\fontname\xetextempfont}%
- \ifx\xetextempfont\nullfontname
- \interactionmode\xetexsavedinteractionmode
- %\writestatus\m!fonts{fails #1: #2 (\xetextempfont)}%
- \expandafter\secondoftwoarguments
- \else
- \interactionmode\xetexsavedinteractionmode
- %\writestatus\m!fonts{succeeds #1: #2 (\xetextempfont)}%
- \expandafter\firstoftwoarguments
- \fi}
-
- \else
-
- \def\doiffoundxetexfontelse#1#2%
- {\suppressfontnotfounderror\plusone
- \font\xetextempfont=#2\somefontspec\relax
- \suppressfontnotfounderror\zerocount
- \edef\xetextempfont{\fontname\xetextempfont}%
- \ifx\xetextempfont\nullfontname
- %\writestatus\m!fonts{fails #1: #2 (\xetextempfont)}%
- \expandafter\secondoftwoarguments
- \else
- %\writestatus\m!fonts{succeeds #1: #2 (\xetextempfont)}%
- \expandafter\firstoftwoarguments
- \fi}
-
- \fi
-
- \def\docheckfontfilenameprefix#1:#2:#3#4\relax
- {\edef\!!stringa{#1}%
- \edef\!!stringb{#2}%
- \ifx\!!stringb\empty
- % no prefix
- \let\checkedfontfile\!!stringa
- \doiffoundxetexfontelse{1a}{\checkedfontfile\checkedfontfeatures}
- {\edef\checkedfontfile{\checkedfontfile\checkedfontfeatures}}
- {\doiffoundxetexfontelse{1b}{"\checkedfontfile\checkedfontfeatures"}
- {\edef\checkedfontfile{"\checkedfontfile\checkedfontfeatures"}}
- {\doiffoundxetexfontelse{1c}{"[\checkedfontfile]\checkedfontfeatures"}
- {\edef\checkedfontfile{"[\checkedfontfile]\checkedfontfeatures"}}
- {}}}%
- \else\ifx\!!stringa\v!file
- % force file, only file check when no spaces
- \let\checkedfontfile\!!stringb
- \doiffoundxetexfontelse{2b}{"[\checkedfontfile]\checkedfontfeatures"}
- {\edef\checkedfontfile{"[\checkedfontfile]\checkedfontfeatures"}}
- {\doiffoundxetexfontelse{2c}{"\checkedfontfile\checkedfontfeatures"}
- {\edef\checkedfontfile{"\checkedfontfile\checkedfontfeatures"}}
- {}}%
- \else\ifx\!!stringa\v!name
- % force name, always lookup by xetex itself, "" forces otf/ttf/type1
- \edef\checkedfontfile{"\!!stringb\checkedfontfeatures"}%
- \else
- % whatever, maybe even xetex spec, forget about features
- \edef\checkedfontfile{"\!!stringa\!!stringb"}%
- \fi\fi\fi}
-
- \def\checkfontfilename% -- todo: integrate so that we call do.. directly
- {\expandafter\docheckfontfilename\fontfile*\empty*\relax}
-
- \def\docheckfontfilename#1*#2#3*#4\relax % class overrules file
- {\edef\checkedfontfeatures
- {\expandafter\ifx\csname\fontclass\s!features\endcsname\empty
- \ifx\@@fontfeatures\empty\ifx#2\empty\else#2#3\fi\else\@@fontfeatures\fi
- \else\expandafter\ifx\csname\fontclass\s!features\endcsname\relax % redundant, will go away
- \ifx\@@fontfeatures\empty\ifx#2\empty\else#2#3\fi\else\@@fontfeatures\fi
- \else
- \csname\fontclass\s!features\endcsname
- \fi\fi}%
- \ifx\checkedfontfeatures\empty
- % done
- \else
- \edef\checkedfontfeatures{\executeifdefined{\??fa\checkedfontfeatures}\empty}%
- \ifx\checkedfontfeatures\empty
- % done
- \else
- \let\convertedfontfeatures\empty
- \processcommacommand[\checkedfontfeatures]\doconvertfontfeatures % raw
- \ifx\convertedfontfeatures\empty
- \let\checkedfontfeatures\empty
- \else
- \edef\checkedfontfeatures{:\convertedfontfeatures}%
- \fi
- \fi
- \fi
- \docheckfontfilenameprefix#1:\empty:\empty\relax
- \doshowcheckedfontfeatures}
-
- \def\dodoconvertfontfeatures#1=#2#3=#4\relax
- {\ifx#2\empty
- % invalid feature
- \else\ifcsname @xtx@#1@#2#3\endcsname
- \expandafter\ifx\csname @xtx@#1@#2#3\endcsname\empty\else
- \edef\convertedfontfeatures{\convertedfontfeatures\csname @xtx@#1@#2#3\endcsname;}%
- \fi
- \else
- \edef\!!stringa{#1}%
- \edef\!!stringb{#2#3}%
- \edef\convertedfontfeatures
- {\convertedfontfeatures
- \ifx\!!stringb\v!yes
- +\!!stringa
- \else\ifx\!!stringb\v!no
- -\!!stringa
- \else
- \!!stringa=\!!stringb
- \fi\fi;}%
- \fi\fi}
-
- \def\doconvertfontfeatures#1%
- {\dodoconvertfontfeatures#1=\empty=\relax}
-
- \def\remapfontfeature #1 #2 #3 {\setevalue{@xtx@#1@#2}{#3}}
-
- % this may move to another file, maybe font-xtx
-
- \remapfontfeature tlig yes mapping=tlig
- %remapfontfeature tlig no mapping=
- \remapfontfeature trep yes {}
- \remapfontfeature trep no {}
- \remapfontfeature texligatures yes mapping=tlig
- %remapfontfeature texligatures no mapping=
- %remapfontfeature texquotes yes mapping=tex-text
- %remapfontfeature texquotes no mapping=
-
-\endXETEX
-
\let\doshowcheckedfontfeatures\relax
\def\showcheckedfontfeatures
@@ -1550,7 +1287,7 @@
\def\donoparsefontspec % #1 == \cs
{\edef\fontfile{\truefontname\somefontname}%
- \ifx\fontfile\s!unknown \let\fontfile\defaultfontfile \fi
+ \ifx\fontfile\s!unknown \let\fontfile\defaultfontfile \fi % can for instance happen with MathGamma
\updatefontparameters
\checkfontfilename
\edef\lastfontname{\checkedfontfile\somefontspec}%
@@ -1606,10 +1343,6 @@
\edef\nullfontname {\fontname\nullfont}
\edef\dummyfontname {font\strippedcsname\\}
-\beginXETEX
- \def\defaultfontfile{lmtypewriter10-regular}
-\endXETEX
-
%D \macros
%D {everyfont,everyfontswitch}
%D
@@ -1688,12 +1421,10 @@
\def\classfont#1#2{#1#2} % \definefont[whatever][\classfont{xx}{yy} at 10pt]
-\beginOLDTEX
-
\def\definefontsynonym[#1]#2[#3]%
{\edef\@@fontfile{#3}%
\@EA\let\csname\??ff\fontclass#1\endcsname\@@fontfile
- \doifnextcharelse[\dodefinefontsynonym\donothing}
+ \doifnextoptionalelse\dodefinefontsynonym\donothing}
\def\dodefinefontsynonym[#1]%
{\edef\@@fontdata{#1}%
@@ -1703,48 +1434,6 @@
\getglobalfontparameters
\fi \fi}
-\endOLDTEX
-
-% We need to move the feature into the filename else it may be
-% overloaded by another reference. For instance the definition of
-% a regular and caps variant can use the same font.
-
-% We could use an indirect method ... store in 'array' and refer to
-% slot.
-
-\beginNEWTEX
-
-\def\definefontsynonym[#1]#2[#3]%
- {\edef\@@fontname{#1}%
- \edef\@@fontfile{#3}%
- \doifnextcharelse[\dodefinefontsynonym\nodefinefontsynonym}
-
-\def\nodefinefontsynonym
- {\@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile}
-
-\def\dodefinefontsynonym[#1]%
- {\edef\@@fontdata{#1}%
- \ifx\@@fontdata\empty
- \nodefinefontsynonym
- \else
- \ifx\fontclass\empty
- \getfontparameters
- \else
- \getglobalfontparameters
- \fi
- \ifcsname\??ff\@@fontfile\s!features\endcsname
- \@EA\edef\csname\??ff\fontclass\@@fontname\endcsname{\@@fontfile*\csname\??ff\@@fontfile\s!features\endcsname}%
- \@EA\let\csname\??ff\@@fontfile\s!features\endcsname\undefined
- \else
- \nodefinefontsynonym
- \fi
- \fi}
-
-\endNEWTEX
-
-% \def\resetfontsynonym[#1]% fails
-% {\letbeundefined{\??ff\fontclass#1}\letbeundefined{\??ff#1}}
-
\let\definefontfile\definefontsynonym % dedicated to Taco Hoekwater
\def\setupfontsynonym
@@ -1776,8 +1465,6 @@
\csname\??ff#2\endcsname
\fi\fi\fi\fi}
-\beginOLDTEX
-
\def\truefontname#1%
{\ifcsname\??ff\fontclass#1\endcsname
\@EA\truefontname\csname\??ff\fontclass#1\endcsname
@@ -1787,86 +1474,6 @@
#1%
\fi\fi}
-\endOLDTEX
-
-\beginNEWTEX
-
-% simple version
-%
-% \def\truefontname#1%
-% {\@EA\dotruefontname#1*\relax}
-%
-% \def\dotruefontname#1*#2\relax
-% {\ifcsname\??ff\fontclass#1\endcsname
-% \@EA\truefontname\csname\??ff\fontclass#1\endcsname
-% \else\ifcsname\??ff#1\endcsname
-% \@EA\truefontname\csname\??ff#1\endcsname
-% \else
-% #1%
-% \fi\fi}
-%
-% last counts
-%
-% \def\truefontname#1%
-% {\@EA\dotruefontname#1*\empty*\relax}
-%
-% \def\dotruefontname#1*#2#3*#4\relax
-% {\ifcsname\??ff\fontclass#1\endcsname
-% \ifx#2\empty
-% \@EA\truefontname\csname\??ff\fontclass#1\endcsname
-% \else
-% \@EA\truefontname\csname\??ff\fontclass#1\endcsname*#2#3%
-% \fi
-% \else\ifcsname\??ff#1\endcsname
-% \ifx#2\empty
-% \@EA\truefontname\csname\??ff#1\endcsname
-% \else
-% \@EA\truefontname\csname\??ff#1\endcsname*#2#3%
-% \fi
-% \else
-% \ifx#2\empty
-% #1%
-% \else
-% #1*#2#3%
-% \fi
-% \fi\fi}
-%
-% first counts
-
-\def\truefontname#1%
- {\@EA\dotruefontname#1*\empty*\relax}
-
-\def\dotruefontname#1*#2#3*#4\relax
- {\ifcsname\??ff\fontclass#1\endcsname
- \ifx#2\empty
- \@EA\truefontname\csname\??ff\fontclass#1\endcsname
- \else
- \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname*#2#3%
- \fi
- \else\ifcsname\??ff#1\endcsname
- \ifx#2\empty
- \@EA\truefontname\csname\??ff#1\endcsname
- \else
- \@EA\redotruefontname\csname\??ff#1\endcsname*#2#3%
- \fi
- \else
- #1\ifx#2\empty\else*#2#3\fi
- \fi\fi}
-
-\def\redotruefontname#1%
- {\@EA\dodotruefontname#1*\relax}
-
-\def\dodotruefontname#1*#2\relax
- {\ifcsname\??ff\fontclass#1\endcsname
- \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname
- \else\ifcsname\??ff#1\endcsname
- \@EA\redotruefontname\csname\??ff#1\endcsname
- \else
- #1%
- \fi\fi}
-
-\endNEWTEX
-
\def\expandfontsynonym#1#2% #2 := onelevelexpansion(#1)
{\ifcsname\??ff\fontclass#2\endcsname
\expandafter\def\expandafter#1\expandafter{\csname\??ff\fontclass#2\endcsname}%
@@ -2109,26 +1716,24 @@
%D To be documented.
-\let\sizelist\empty
+\let\fontsizelist\empty
+\let\fontstylelist\empty
\def\definefontsize[#1]% sneller met toks
- {\addtocommalist{#1}\sizelist
+ {\addtocommalist{#1}\fontsizelist
\def\docommand##1%
{\def\dodocommand####1%
{\def\dododocommand########1%
%{\checkbodyfont{}{########1}{####1}{##1}}%
{\checkbodyfont{########1}{####1}{##1}}%
- \processcommacommand[\stylelist]\dododocommand}%
- \processcommacommand[\alternativelist]\dodocommand}%
- \processcommacommand[\sizelist]\docommand}
-
-\def\alternativetextlist{\c!tf,\c!bf,\c!it,\c!sl,\c!bs,\c!bi,\c!sc}
-\def\alternativemathlist{\c!mr,\c!mi,\c!sy,\c!ex,\c!ma,\c!mb}
+ \processcommacommand[\fontstylelist]\dododocommand}%
+ \processcommacommand[\fontalternativelist]\dodocommand}%
+ \processcommacommand[\fontsizelist]\docommand}
-\let\alternativelist\alternativetextlist % upward compatible
+\def\fontalternativetextlist{\c!tf,\c!bf,\c!it,\c!sl,\c!bs,\c!bi,\c!sc}
+\def\fontalternativemathlist{\c!mr,\c!mi,\c!sy,\c!ex,\c!ma,\c!mb}
-%\definefontsize[\c!a] \definefontsize[\c!b]
-%\definefontsize[\c!c] \definefontsize[\c!d]
+\let\fontalternativelist\fontalternativetextlist % upward compatible
%D \macros
%D {currentfontscale,currentfontbodyscale}
@@ -2268,7 +1873,7 @@
\scratchdimen\csname\??ft\s!default##1\endcsname\scratchdimen
\normalizebodyfontsize\scratchdimen\to\tempbodyfontsize
\setevalue{\??ft#2#1##1}{\tempbodyfontsize}}%
- \processcommacommand[\fontsizelist]\docommand
+ \processcommacommand[\fontrelativesizelist]\docommand
\copyparameters
[\??ft#2#1][\??ft\s!default]
[\c!interlinespace,\c!em]}%
@@ -2595,7 +2200,7 @@
% \scratchdimen\csname\??ft\s!default##1\endcsname\scratchdimen
% \normalizebodyfontsize\scratchdimen\to\!!stringa
% \letvalue{\??ft#1##1}\!!stringa}}%
-% \processcommacommand[\fontsizelist]\docommand
+% \processcommacommand[\fontrelativesizelist]\docommand
% \let\c!text\c!savedtext
% \ifdone
% \donefalse
@@ -2605,7 +2210,7 @@
% {\doifdefined{\s!default\s!default##1}
% {\donetrue\getvalue{\s!default\s!default##1}{#1}{##1}}}%
% \processcommacommand
-% [\stylelist]
+% [\fontstylelist]
% \defineunknownbodyfont
% \ifdone
% \setvalue{\@size@#1}{\docompletefontswitch[#1]}%
@@ -2614,7 +2219,7 @@
% \def\defineunknownsubfont##1%
% {\doifundefined{\@size@\getvalue{\??ft#1##1}}
% {\defineunknownfont{\getvalue{\??ft#1##1}}}}%
-% \processcommacommand[\fontsizelist]\defineunknownsubfont
+% \processcommacommand[\fontrelativesizelist]\defineunknownsubfont
% \definingunknownfontfalse
% \fi
% \fi
@@ -2659,19 +2264,19 @@
{\let\c!savedtext\c!text
\let\c!text\s!text
\donefalse
- \processcommacommand[\fontsizelist]{\dodefineunknownfont{#1}}%
+ \processcommacommand[\fontrelativesizelist]{\dodefineunknownfont{#1}}%
\let\c!text\c!savedtext
\ifdone
\donefalse
\processcommacommand
- [\stylelist]
+ [\fontstylelist]
{\dodefineunknownbodyfont{#1}}%
\ifdone
\donefalse
\setvalue{\@size@#1}{\docompletefontswitch[#1]}%
\ifdefiningunknownfont \else
\definingunknownfonttrue
- \processcommacommand[\fontsizelist]{\dodefineunknownsubfont{#1}}%
+ \processcommacommand[\fontrelativesizelist]{\dodefineunknownsubfont{#1}}%
\definingunknownfontfalse
\fi
\fi
@@ -2683,7 +2288,7 @@
% \def\defineunknownfontstyles#1%
% {\def\defineunknownbodyfont##1% see ***
% {\executeifdefined{\s!default\s!default##1}\gobbletwoarguments{#1}{##1}}%
-% \rawprocesscommacommand[\stylelist]\defineunknownbodyfont}
+% \rawprocesscommacommand[\fontstylelist]\defineunknownbodyfont}
%D These macros show that quite some definitions take place.
%D Fonts are not loaded yet! This means that at format
@@ -2741,8 +2346,8 @@
%D size and the local (sometimes in the textflow) size. We
%D store these dimensions in two \DIMENSION\ registers.
-\newdimen\globalbodyfontsize \globalbodyfontsize=12pt
-\newdimen\localbodyfontsize \localbodyfontsize =\globalbodyfontsize
+\ifdefined\globalbodyfontsize\else \newdimen\globalbodyfontsize \fi \globalbodyfontsize=12pt
+\ifdefined\localbodyfontsize \else \newdimen\localbodyfontsize \fi \localbodyfontsize =\globalbodyfontsize
%D \macros
%D {bodyfontsize}
@@ -2776,27 +2381,37 @@
%D often not the way users specify the bodyfont size. Therefore
%D we also store the normalized value.
-\chardef\fontdigits=1
+\chardef\fontdigits=2 % was 1
+
+% \def\normalizebodyfontsize#1\to#2%
+% {\scratchdimen#1\relax
+% \ifcase\fontdigits\advance\scratchdimen.5\points\fi
+% \@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\scratchdimen00\to#2}
+%
+% \def\donormalizedbodyfontsize#1.#2#3#4\to#5% \points ?
+% {\edef#5%
+% {#1%
+% \ifcase\fontdigits\or
+% \ifcase#2 \else.#2\fi % and not: \ifcase#2\else ...
+% \else
+% \ifcase#2#3 \else.#2\ifcase#3 \else#3\fi\fi % not: \ifcase#2#3\else ...
+% \fi
+% \s!pt}}
\def\normalizebodyfontsize#1\to#2%
- {\scratchdimen#1\relax
- \ifcase\fontdigits\advance\scratchdimen.5\points\fi
- \@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\scratchdimen00\to#2}
+ {\scratchdimen\dimexpr#1+\ifcase\fontdigits.5\or.05\or.005\fi\points\relax
+ \@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\scratchdimen000\to#2}
-\def\donormalizedbodyfontsize#1.#2#3#4\to#5% \points ?
- {\edef#5%
+\def\donormalizedbodyfontsize#1.#2#3#4#5\to#6% \points ?
+ {\edef#6% not \ifcase#2\else due to \relax adding
{#1%
- \ifcase\fontdigits\or
- \ifcase#2 \else.#2\fi % and not: \ifcase#2\else ...
- \else
- \ifcase#2#3 \else.#2\ifcase#3 \else#3\fi\fi % not: \ifcase#2#3\else ...
+ \ifcase\fontdigits
+ \or \ifcase#2 \else .#2\fi % 1
+ \or \ifcase#2#3 \else .#2\ifcase#3 \else #3\fi\fi % 2
+ \else \ifcase#2#3#4 \else .#2\ifcase#4 \ifcase#3 \else#3\fi \else#3#4\fi\fi % 3
\fi
\s!pt}}
-\normalizebodyfontsize\bodyfontsize\to\normalizedglobalbodyfontsize
-\normalizebodyfontsize\bodyfontsize\to\normalizedlocalbodyfontsize
-\normalizebodyfontsize\bodyfontsize\to\normalizedbodyfontsize
-
%D To be internationalized:
\def\korpsgrootte {\bodyfontsize}
@@ -3018,8 +2633,16 @@
\let\fontclass\empty \let\globalfontclass\fontclass
+% \def\setcurrentfontclass#1%
+% {\edef\fontclass{#1}}
+
+\def\registerfontclass#1%
+ {\letgvalue{\@fontclass@#1}\v!yes} % global ?
+
\def\setcurrentfontclass#1%
- {\edef\fontclass{#1}}
+ {\ifcsname\@fontclass@#1\endcsname
+ \edef\fontclass{#1}%
+ \fi}
\let\defaultfontstyle \c!rm
\let\defaultfontalternative \c!tf
@@ -3317,9 +2940,9 @@
%D \stoptyping
\def\dodefinefontstyle[#1][#2]%
- {\rawdoifinsetelse{#2}{\stylelist}
+ {\rawdoifinsetelse{#2}{\fontstylelist}
{}%\debuggerinfo\m!fonts{unknown style #2}}
- {\addtocommalist{#2}\stylelist
+ {\addtocommalist{#2}\fontstylelist
\showmessage\m!fonts8{#2\space (#1)}}%
% check kan hier
\def\docommand##1%
@@ -4389,7 +4012,7 @@
%D {bordermatrix}
%D
%D In \PLAIN\ \TEX\ the width of a parenthesis is stored in
-%D the \DIMENSION\ \type{\p@renwd}. This value is derived from
+%D the \DIMENSION\ \type{\mathparentwd}. This value is derived from
%D the width of \type{\tenrm B}, so let's take care of it now:
\let\normalbordermatrix=\bordermatrix
@@ -4397,7 +4020,7 @@
\def\bordermatrix%
{\bgroup
\setbox0\hbox{\getvalue{\textface\c!mm\c!ex}B}%
- \global\p@renwd\wd0\relax
+ \global\mathparentwd\wd0\relax
\egroup
\normalbordermatrix}
@@ -4678,6 +4301,7 @@
%D So far.
+\definefontstyle [\c!mm] [\c!mm]
\definefontstyle [\c!rm,\v!roman,\v!serif,\v!regular] [\c!rm]
\definefontstyle [\c!ss,\v!sansserif,\v!sans,\v!support] [\c!ss]
\definefontstyle [\c!tt,\v!teletype,\v!type,\v!mono] [\c!tt]
@@ -4800,24 +4424,6 @@
\def\fontvariant#1#2{\executeifdefined{\??fv#1#2}\empty}
-% original:
-%
-% \def\variant[#1]%
-% {\expanded{\definedfont
-% [\truefontname{\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1}}
-% at \currentfontscale\bodyfontsize]}}
-%
-% \beginXETEX \font
-%
-% \def\variant[#1]%
-% {\font\variantfont\truefontname{\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1}}
-% at \currentfontscale\bodyfontsize
-% \variantfont}
-%
-% \endXETEX
-%
-% better
-
\def\dosetscaledfont
{\checkrelativefontsize\fontstyle
\scaledfont\currentfontscale\bodyfontsize
@@ -4830,16 +4436,6 @@
at \scaledfont]}%
\ignoreimplicitspaces}
-\beginXETEX \font
-
- \unexpanded\def\variant[#1]%
- {\dosetscaledfont
- \font\variantfont\truefontname{\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1}}
- at \scaledfont
- \variantfont}
-
-\endXETEX
-
\ifx\Var\undefined \let\Var\variant \fi
%D By default we load the Computer Modern Roman fonts (but
@@ -4847,7 +4443,7 @@
%D bodyfont. Sans serif and teletype are also available and
%D can be called for by \type{\ss} and \type{\tt}.
-\setupbodyfont [unk, rm]
+% \setupbodyfont [unk, rm]
%D Also needed is:
@@ -4889,4 +4485,83 @@
\egroup\expandafter\firstoftwoarguments
\fi}
+%D New commands (not yet interfaced):
+
+\def\style[#1]% for inline usage, like \color
+ {\groupedcommand{\ifcsname#1\endcsname\csname#1\endcsname\else\definedfont[#1]\fi}{}}
+
+\def\startstyle[#1]%
+ {\begingroup
+ \ifcsname#1\endcsname\csname#1\endcsname\else\definedfont[#1]\fi}
+
+\def\stopstyle
+ {\endgroup}
+
+%D Still experimental (might even go away).
+
+% \definestylecollection[mine]
+
+% \definestyleinstance[mine][default][sorry]
+% \definestyleinstance[mine][tt][bs][ttbs:\rm\sl]
+% \definestyleinstance[mine][tt][bf][ttbf:\rm\sl]
+% \definestyleinstance[mine][bf][\sl]
+% \definestyleinstance[mine][sl][\tt]
+
+% {\bf test \mine test \sl test \mine test \bs oeps \mine oeps {\tt test \mine \bf test}}
+
+\definesystemvariable{sx}
+
+\def\definestylecollection
+ {\dosingleargument\dodefinestylecollection}
+
+\def\dodefinestylecollection[#1]%
+ {\iffirstargument
+ \unexpanded\setvalue{#1}{\styleinstance[#1]}%
+ \def\docommand##1%
+ {\def\dodocommand####1{\letbeundefined{\??sx##1:####1:\commalistelement}}%
+ \processcommacommand[\fontalternativelist,\s!default]\dodocommand}%
+ \processcommacommand[\fontstylelist,\s!default]\docommand
+ \fi}
+
+\def\definestyleinstance
+ {\doquadrupleargument\dodefinestyleinstance}
+
+\def\dodefinestyleinstance[#1][#2][#3][#4]% [name] [rm|ss|tt|..] [sl|bf|...] [whatever]
+ {\iffirstargument
+ \doifundefined{#1}{\definestylecollection[#1]}%
+ \fi
+ \iffourthargument
+ \setvalue{\??sx#1:#2:#3}{#4}%
+ \else\ifthirdargument
+ \setvalue{\??sx#1::#2}{#3}%
+ \else\ifsecondargument
+ \letvalue{\??sx#1::#2}\empty
+ \fi\fi\fi}
+
+\unexpanded\def\styleinstance[#1]% will be faster
+ {%\begingroup\expanded{\infofont[#1:\fontstyle:\fontalternative]}\endgroup
+ \executeifdefined{\??sx#1:\fontstyle:\fontalternative}%
+ {\executeifdefined{\??sx#1:\fontstyle:\s!default}%
+ {\executeifdefined{\??sx#1::\fontalternative}
+ {\getvalue {\??sx#1::\s!default}}}}}
+
+% \unexpanded\def\styleinstance[#1]%
+% {\csname\??sx#1%
+% \ifcsname:\fontstyle:\fontalternative\endcsname
+% :\fontstyle:\fontalternative
+% \else\ifcsname:\fontstyle:\s!default\endcsname
+% :\fontstyle:\s!default
+% \else\ifcsname::\fontalternative\endcsname
+% ::\fontalternative
+% \else\ifcsname::\s!default\endcsname
+% ::\s!default
+% \else
+% % nothing, \relax
+% \fi\fi\fi\fi
+% \endcsname}
+
+%D \Compatibility with \MKIV:
+
+\def\somefontsize{\scaledfont}
+
\protect \endinput
diff --git a/tex/context/base/font-ini.mkiv b/tex/context/base/font-ini.mkiv
index 3e2e57145..4d0d92fc5 100644
--- a/tex/context/base/font-ini.mkiv
+++ b/tex/context/base/font-ini.mkiv
@@ -12,26 +12,64 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+% simplification ... we no longer deal with specific mmtfa specifications
-% \rm\bf --> \song
-% \rm\it --> \kai
-% \ss\it --> \kai
-% \tt\bf --> \hei
+% todo: always fontclass, then less testing
-\writestatus{loading}{Context Font Macros (ini)}
+% \starttext
+% \definefontfeature[basekerned][default][mode=base]
+% \definefontfeature[nodekerned][default][mode=node]
+% \definefontfeature[nonekerned][default][mode=base,kern=no]
+% \setupcolors[state=start]
+% \startoverlay
+% {\vbox{\red \definedfont[Serif*nonekerned at 12pt]\input tufte }}
+% {\vbox{\blue \definedfont[Serif*basekerned at 12pt]\input tufte }}
+% {\vbox{\green\definedfont[Serif*nodekerned at 12pt]\input tufte }}
+% \stopoverlay
+% \stoptext
+
+% \enabletrackers[otf.kerns]
+%
+% \definefontfeature[withkern][default][mode=node]
+% \definefontfeature[nokern] [default][mode=node,kern=no]
+% \definefontfeature[single] [default][mode=node,cpsp=yes]
+% \definefontfeature[simple] [default][mode=node,cpsp=yes,kern=no]
+%
+% {\definedfont[Serif*default] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
+% {\definedfont[Serif*nokern] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
+% {\definedfont[Serif*single] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
+% {\definedfont[Serif*simple] [FGFGFGFGFGFGFGFGFGFGFGFGFG ABCDEFGHIJKLMNOPQRSTUVWXYZ] \par}
+
+% figure out why \fontbody is not expanded
+
+\writestatus{loading}{ConTeXt Font Macros / Initialization}
\registerctxluafile{font-ini}{1.001}
+\registerctxluafile{node-fnt}{1.001} % here
\registerctxluafile{font-enc}{1.001}
\registerctxluafile{font-map}{1.001}
\registerctxluafile{font-syn}{1.001}
+\registerctxluafile{font-log}{1.001}
\registerctxluafile{font-tfm}{1.001}
\registerctxluafile{font-afm}{1.001}
-\registerctxluafile{font-otf}{1.001}
+\registerctxluafile{font-cid}{1.001} % cid maps
+\registerctxluafile{font-ott}{1.001} % otf tables
+\registerctxluafile{font-otf}{1.001} % otf main
+\registerctxluafile{font-otd}{1.001} % otf dynamics
+\registerctxluafile{font-oti}{1.001} % otf initialization
+\registerctxluafile{font-otb}{1.001} % otf main base
+\registerctxluafile{font-otn}{1.001} % otf main node
+\registerctxluafile{font-ota}{1.001} % otf analyzers
+\registerctxluafile{font-otp}{1.001} % otf pack
+\registerctxluafile{font-otc}{1.001} % otf context
\registerctxluafile{font-vf} {1.001}
\registerctxluafile{font-def}{1.001}
+\registerctxluafile{font-ctx}{1.001}
+\registerctxluafile{font-xtx}{1.001}
\registerctxluafile{font-fbk}{1.001}
\registerctxluafile{font-ext}{1.001}
\registerctxluafile{font-pat}{1.001}
+\registerctxluafile{font-chk}{1.001}
\unprotect
@@ -107,10 +145,10 @@
%D
%D A couple of relatively new macros:
-\newevery \everydefinedfont \relax % not ot be confused with \everydefinefont
+% \newtoks \everydefinedfont % not ot be confused with \everydefinefont
\def\dodefinedfont[#1]%
- {\iffirstargument\definefont[thedefinedfont][#1]\fi
+ {\iffirstargument\definefont[thedefinedfont][#1]\fi % we can speed this one up
\csname thedefinedfont\endcsname
\the\everydefinedfont}
@@ -132,158 +170,10 @@
\egroup\expandafter\secondoftwoarguments
\fi}
-%%% message 14 added
-
-\startmessages dutch library: fonts
- title: korps
- 1: codering --
- 2: variant -- wordt geladen
- 3: onbekende variant --
- 4: korps -- is niet gedefinieerd
- 5: stijl -- is niet gedefinieerd
- 6: -- wordt geladen
- 7: onbekend formaat --
- 8: stijl -- gedefinieerd
-% 9: mapping -- is geladen
- 10: onbekende font file --
- 14: korps -- is gedefinieerd (kan beter globaal plaatsvinden)
-\stopmessages
-
-\startmessages english library: fonts
- title: bodyfont
- 1: coding --
- 2: variant -- is loaded
- 3: unknown variant --
- 4: bodyfont -- is not defined
- 5: style -- is not defined
- 6: -- is loaded
- 7: unknown format --
- 8: style -- defined
-% 9: mapping -- is loaded
- 10: unknown font file --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages german library: fonts
- title: Fliesstext
- 1: Kodierung --
- 2: Variante -- ist geladen
- 3: Unbekannte Variante --
- 4: Fliesstext -- ist nicht definiert
- 5: Stil -- ist nicht definiert
- 6: -- ist geladen
- 7: unbekanntes Format --
- 8: Stil -- definiert
-% 9: Map -- ist geladen
- 10: unbekanntes Font --
- 14: Fliesstext -- wurde definiert (besser waere globale Definition)
-\stopmessages
-
-\startmessages czech library: fonts
- title: zakladnifont
- 1: kodovani --
- 2: varianta -- je nactena
- 3: neznama varianta --
- 4: zakladni font -- neni definovan
- 5: styl -- neni definovan
- 6: -- je nacten
- 7: neznamy format --
- 8: styl -- definovan
-% 9: mapovani -- je nacteno
- 10: neznamy font --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages italian library: fonts
- title: font del corpo
- 1: codifica --
- 2: variante -- caricata
- 3: variante sconosciuta --
- 4: corpo del testo -- non definito
- 5: stile -- non definito
- 6: -- caricato
- 7: formato sconosciuto --
- 8: stile -- definito
-% 9: mappatura -- caricata
- 10: file di font sconosciuto --
- 14: corpo del testo -- definito (sarebbe meglio globale)
-\stopmessages
-
-\startmessages norwegian library: fonts
- title: hovedfont
- 1: koding --
- 2: variant -- er lest inn
- 3: ukjent variant --
- 4: hovedfont -- er ikke definert
- 5: stil -- er ikke definert
- 6: -- er lest inn
- 7: ukjent format --
- 8: stil -- definert
-% 9: avbildning -- er lest inn
- 10: ukjent fontfil --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages romanian library: fonts
- title: corp de litere
- 1: codificarea --
- 2: varianta -- este incarcata
- 3: varianta necunoscuta --
- 4: corpul de litere -- nu este definit
- 5: stilul -- nu este definit
- 6: -- este incarcat
- 7: format necunoscut --
- 8: stilul -- definit
-% 9: maparea -- este incarcat
- 10: fisier font necunoscut --
- 14: bodyfont -- is defined (can better be done global)
-\stopmessages
-
-\startmessages french library: fonts
- title: corps de texte
- 1: encodage --
- 2: la variante -- est chargée
- 3: variante -- inconnue
- 4: policecorps -- n'est pas définie
- 5: le style -- n'est pas défini
- 6: -- est chargé
- 7: format -- inconnu
- 8: style -- défini
-% 9: mapping -- is loaded
- 10: fichier de police -- inconnu
- 14: policecorps -- est défini (une définition globale pourrait être plus adéquat)
-\stopmessages
-
-%D This module is one of the oldest modules of \CONTEXT. The
-%D macros below evolved out of the \PLAIN\ \TEX\ macros and
-%D therefore use a similar naming scheme (\type{\rm},
-%D \type{\bf}, etc). This module grew out of our needs. We
-%D started with the \PLAIN\ \TEX\ definitions, generalized the
-%D underlaying macros, and extended those to a level at which
-%D probably no one will ever recognize them.
-%D
-%D In 2001 we ran into a couple of projects where more than
-%D one combined set of fonts was involved in a document. To
-%D make definitions more readable, as well as to overcome the
-%D problem of ever growing file name lists, and also because
-%D we needed to scale fonts relative to each other, the low
-%D level implementation was partly rewritten. Global
-%D font assignments, relative scaling, font classes and alike
-%D were added then. At the same time some macros were made a
-%D bit more readable, and math support was extended to the
-%D larger sizes.
-%D
-%D One important characteristic of the font mechanism presented
-%D here is the postponing of font loading. This makes it
-%D possible to distribute \type{fmt} files without bothering
-%D about the specific breed of \type{tfm} files.
-%D
-%D Another feature implemented here is the massive switching
-%D from roman to {\ss sans serif}, {\tt teletype} or else. This
-%D means one doesn't have to take care of all kind of relations
-%D between fonts.
-%D
-%D \page[bigpreference]
+%D For more detailed (and historic information) we refer to the file
+%D \type {font-ini.mkii}. Here we have a much simplified lower level
+%D implementation due to a different approach to math. Also the chapter
+%D on fonts in the reference manual explains a lot.
%D \macros
%D {rm,ss,tt,hw,cg}
@@ -314,56 +204,6 @@
%D \stoptable
%D \stoplinecorrection
%D
-%D Anyone who feels the need, can define additional ones, like
-%D
-%D \startlinecorrection
-%D \starttable[|l||]
-%D \HL
-%D \NC faxfont \NC \type{\ff} \NC\FR
-%D \NC blackboard \NC \type{\bb} \NC\LR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D Or even
-%D
-%D \startlinecorrection
-%D \starttable[|l||]
-%D \HL
-%D \NC hebrew \NC \type{\hb} \NC\SR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D Styles are grouped in font sets. At the moment there are
-%D three main sets defined:
-%D
-%D \startlinecorrection
-%D \starttable[|l|l||]
-%D \HL
-%D \NC Computer Modern Roman \NC Knuth \NC \type{cmr} \NC\FR
-%D \NC Lucida Bright \NC Bigelow \& Holmes \NC \type{lbr} \NC\MR
-%D \NC Standard Postscript Fonts \NC Adobe \NC \type{pos} \NC\LR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D There are also some Computer Modern Roman alternatives:
-%D
-%D \startlinecorrection
-%D \starttable[|l|l||]
-%D \HL
-%D \NC Computer Modern Roman \NC Knuth \& Sauter \NC \type{sau} \NC\FR
-%D \NC Euler fonts \NC Zapf \NC \type{eul} \NC\MR
-%D \NC Computer Modern Concrete \NC Knuth \& Zapf \NC \type{con} \NC\LR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D All these definitions are ordered in files with names like
-%D \type{font-cmr} and \type{font-pos}, where the last three
-%D characters specify the name as known to \CONTEXT.
-%D
%D Within such a font set (\type{cmr}) and style (\type{\rm})
%D we can define a number of text font alternatives:
%D
@@ -380,43 +220,6 @@
%D \HL
%D \stoptable
%D \stoplinecorrection
-
-%D For old stylish Frans Goddijn we have:
-%D
-%D \startlinecorrection
-%D \starttable[|l||]
-%D \HL
-%D \NC oldstyle \NC \type{\os} \NC\SR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D The availability of these alternatives depends on the
-%D completeness of a font family and of course the definitions
-%D in the font files.
-%D
-%D But let's not forget math. In addition to the previous \TEX\
-%D families (the mysterious \type{\fam}'s) we've got some more:
-%D
-%D \startlinecorrection
-%D \starttable[|l||]
-%D \HL
-%D \NC Math Roman \NC \type{\mr} \NC\FR
-%D \NC Math Italic \NC \type{\mi} \NC\MR
-%D \NC Math Symbol \NC \type{\sy} \NC\MR
-%D \NC Math Extra \NC \type{\ex} \NC\MR
-%D \NC Math A \NC \type{\ma} \NC\MR
-%D \NC Math B \NC \type{\mb} \NC\MR
-%D \NC Math C \NC \type{\mc} \NC\LR
-%D \HL
-%D \stoptable
-%D \stoplinecorrection
-%D
-%D Users can call for specific fonts in many ways. Switches to
-%D other typefaces, like the switch from normal to bold, are as
-%D intuitive as possible, which means that all dependant fonts
-%D also switch. One can imagine that this takes quite some
-%D processing time.
%D
%D Internally fonts are stored as combination of size, style
%D and alternative, e.g. \type{12pt}+\type{\ss}+\type{\bf}.
@@ -514,7 +317,7 @@
%D And compare $\rm \scriptstyle THIS$ with the slightly larger
%D \cap{THIS}: \ruledhbox{$\rm \scriptstyle scriptstyle: THIS$}
%D or \ruledhbox{\cap{x style: THIS}} makes a big difference.
-
+%D
%D The \type{x..d} sizes should be used grouped. If you
%D don't group them, i.e. call them in a row, \CONTEXT\ will
%D not be able to sort out your intention (\type {x} inside
@@ -592,282 +395,8 @@
%D \NC \NR
%D \HL
%D \stoptabulate
-
-%D \macros
-%D {mf}
-%D
-%D Math fonts are a species in their own. They are tightly
-%D hooked into smaller and even smaller ones of similar breed
-%D to form a tight family. Let's first see how these are
-%D related:
-%D
-%D \startbuffer
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\rm 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+{\bi x^2}=\rm 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\tf 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+{\bi x^2}=\tf 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\bf 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+{\bi x^2}=\bf 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\sl 6x^2$
-%D $\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+{\bi x^2}=\sl 6x^2$
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Gives both an expected and unexpected result:
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D We see here that the character shapes change accordingly to
-%D the current family, but that the symbols are always typeset
-%D in the font assigned to \type{\fam0}.
-%D
-%D \startbuffer
-%D $\tf\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D $\bf\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D $\sl\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D $\bs\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D $\it\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D $\bi\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
-%D \stopbuffer
-%D
-%D \startvoorbeeld
-%D \startlines
-%D \getbuffer
-%D \stoplines
-%D \stopvoorbeeld
-%D
-%D In this example we see a new command \type{\mf} surface
-%D which means as much as {\em math font}. This commands
-%D reactivates the last font alternative and therefore equals
-%D \type{\bf}, \type{\sl} etc. but by default it equals
-%D \type{\tf}:
-
-\unexpanded\def\mf
- {\dodosetmathfont\fontalternative
- \csname\fontalternative\endcsname}
-
-%D The previous example was typeset saying:
-%D
-%D \typebuffer
-%D
-%D Beware: the exact location of \type{\mf} is not that
-%D important, we could as well has said
-%D
-%D \startbuffer
-%D $\bf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = \mf 6x^2$
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D This is due to the way \TEX\ handles fonts in math mode.
%D
-%D Of course we'll have to redefine \type{\mf} every time we
-%D change the current \type{\fam}.
-
-%D \macros
-%D {mbox,enablembox,mathop}
-%D
-%D Now how can we put this to use? Will the next sequence
-%D give the desired result?
-%D
-%D \startbuffer
-%D $\bf x^2 + \hbox{\mf whatever} + \sin(2x)$
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D It won't!
-%D
-%D \startvoorbeeld
-%D \let\mathop=\normalmathop \getbuffer
-%D \stopvoorbeeld
-%D
-%D The reason for this is that \type{\sin} is defined as:
-%D
-%D \starttyping
-%D \def\sin{\mathop{\rm sin}\nolimits}
-%D \stoptyping
-%D
-%D We can fix this by defining
-
-\let\normalmathop\mathop
-
-\unexpanded\def\mathop
- {\normalmathop
- \bgroup
- \let\rm\mf
- \let\next=}
-
-%D We can fix arbitrary horizontal boxes by redefining the
-%D \TEX\ primitive \type{\hbox}:
-%D
-%D \starttyping
-%D \let\normalhbox=\hbox
-%D
-%D \def\hbox{\ifmmode\mbox\else\normalhbox\fi}
-%D \stoptyping
-%D
-%D with
-%D
-%D \starttyping
-%D \def\mbox#1#%
-%D {\normalhbox#1\bgroup\mf\let\next=}
-%D \stoptyping
-%D
-%D or more robust, that is, also accepting \type{\hbox\bgroup}:
-%D
-%D \starttyping
-%D \def\mbox%
-%D {\normalhbox\bgroup\mf
-%D \dowithnextbox{\flushnextbox\egroup}%
-%D \normalhbox}
-%D \stoptyping
-%D
-%D And now:
-%D
-%D \startbuffer
-%D $\bf x^2 + \hbox{whatever} + \sin(2x)$
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Indeed gives:
-%D
-%D \startvoorbeeld
-%D \enablembox\getbuffer
-%D \stopvoorbeeld
-%D
-%D But, do we want this kind of trickery to be activated? No,
-%D simply because we cannot be sure of incompatibilities,
-%D although for instance unboxing goes ok. Therefore we
-%D introduce:
-
-% best can go to math-ini and make \mf a hook then
-
-% better use \dowithnextboxcontent
-
-\def\normalmbox
- {\normalhbox\bgroup\mf
- \dowithnextbox{\flushnextbox\egroup}\normalhbox}
-
-% to test:
-%
-% \def\normalmbox
-% {\dowithnextboxcontent\mf\flushnextbox\normalhbox}
-
-\def\mbox
- {\ifmmode\normalmbox\else\normalhbox\fi}
-
-\def\enablembox
- {\appendtoks
- \ifx\normalhbox\undefined\let\normalhbox\hbox\fi
- \let\hbox\mbox
- \to\everymathematics}
-
-%D So in fact one can enable this feature if needed. I would say:
-%D go along, but use grouping if needed!
-
-%D \macros
-%D {mrfam,mifam,syfam,exfam,
-%D bsfam,bifam,scfam,tffam,
-%D mafam,mbfam,msfam}
-%D
-%D After this short mathematical excursion, we enter the world
-%D of fonts and fontswitching. We start with something very
-%D \TEX: \type{\fam} specified font families. \TEX\ uses
-%D families for managing fonts in math mode. Such a family has
-%D three members: text, script and scriptscript: $x^{y^z}$. In
-%D \CONTEXT\ we take a bit different approach than \PLAIN\
-%D \TEX\ does. \PLAIN\ \TEX\ needs at least four families for
-%D typesetting math. We use those but give them symbolic names.
-
-\chardef\mrfam = 0 % (Plain TeX) Math Roman
-\chardef\mifam = 1 % (Plain TeX) Math Italic
-\chardef\syfam = 2 % (Plain TeX) Math Symbol
-\chardef\exfam = 3 % (Plain TeX) Math Extra
-
-%D \PLAIN\ \TEX\ also defines families for {\it italic}, {\sl
-%D slanted} and {\bf bold} typefaces, so we don't have to
-%D define them here.
-
-\ifx\itfam\undefined
-
-\chardef\itfam = 4 % (Plain TeX) Italic
-\chardef\slfam = 5 % (Plain TeX) Slanted
-\chardef\bffam = 6 % (Plain TeX) Boldface
-
-\fi
-
-%D Family~7 in \PLAIN\ \TEX\ is not used in \CONTEXT, because
-%D we do massive switches from roman to sans serif, teletype or
-%D other faces.
-
-\ifx\ttfam\undefined
- \chardef\ttfam = 7 % (Plain TeX) can be reused!
-\fi
-
-%D We define ourselves some more families for {\bs bold
-%D slanted}, {\bi bold italic} and {\sc Small Caps}, so
-%D we can use them in math mode too. Instead of separate
-%D families for {\ss sans serif} and \type{teletype} we use the
-%D more general \type{\tffam}, which stands for typeface.
-
-\chardef\bsfam = 8 % (ConTeXt) BoldSlanted
-\chardef\bifam = 9 % (ConTeXt) BoldItalic
-\chardef\scfam = 10 % (ConTeXt) SmallCaps
-\chardef\tffam = 11 % (ConTeXt) TypeFace
-
-%D Because Taco needs a few more math families, we reuse
-%D family~7 for all those typefaces that have no related
-%D family, and therefore are grouped into one.
-
-\chardef\nnfam = 7 % (ReUsed) NoName
-
-%D Normally \type{\mrfam} equals \type{\tffam}, but a more
-%D distinctive alternatives are possible, for instance the
-%D Euler and Concrete Typefaces.
-%D
-%D After having defined all those in nature non||mathematical
-%D families, we define ourselves some real math ones. These are
-%D needed for the \AMS\ Symbol Fonts and Extended Lucida
-%D Bright.
-
-\chardef\mafam = 12 % (ConTeXt) Math A Fam (AmsTeX A)
-\chardef\mbfam = 13 % (ConTeXt) Math B Fam (AmsTeX B)
-\chardef\mcfam = 14 % (ConTeXt) Math C Fam (MathTime)
-\chardef\mdfam = 15 % (ConTeXt) Math D Fam (MathTime)
-
-%D Because there are 16~families and because \type{\ttfam}
-%D is reused, at the moment we have no so many families
-%D left. By default, we map any newly defined family on the
-%D last one (F).
-
-\def\newfam#1{\chardef#1=15 }
-
-%D This hack is also needed because in \ETEX\ we are going
-%D to reuse the \type {\newfam} allocation counter.
-
-%D To ease the support of font packages, we als define
-%D shortcuts to these familynames. This is necessary because
-%D the family names are in fact \type{\chardef}'s, which means
-%D that we're dealing with numbers (one can check this by
-%D applying \type{\showthe} and \type{\show}). In the
-%D specification of math symbols however we need hexadecimal
-%D numbers, so we have to convert the \type{\fam}'s value.
-
-\edef\hexmrfam {\hexnumber\mrfam} \edef\hexbsfam {\hexnumber\bsfam}
-\edef\hexmifam {\hexnumber\mifam} \edef\hexbifam {\hexnumber\bifam}
-\edef\hexsyfam {\hexnumber\syfam} \edef\hexscfam {\hexnumber\scfam}
-\edef\hexexfam {\hexnumber\exfam} \edef\hextffam {\hexnumber\tffam}
-\edef\hexitfam {\hexnumber\itfam} \edef\hexmafam {\hexnumber\mafam}
-\edef\hexslfam {\hexnumber\slfam} \edef\hexmbfam {\hexnumber\mbfam}
-\edef\hexbffam {\hexnumber\bffam} \edef\hexmcfam {\hexnumber\mcfam}
-\edef\hexnnfam {\hexnumber\nnfam} \edef\hexmdfam {\hexnumber\mdfam}
+%D Remark: math support has changed a bit.
%D \macros
%D {uchar}
@@ -886,244 +415,122 @@
\def\@shortstyle@ {@f@sh@} % short style prefix (rm etc)
\def\@letter@ {@f@le@} % first alternative typeface
\def\@noletter@ {@f@no@} % second alternative typeface
+\def\@fontclass@ {@f@cl@} % fontclass
-%D The families can be grouped into math specific ones and
-%D more text related families, although text ones can be
-%D mapped onto the math ones to get for instance bold math.
+%D \macros
+%D {fontclass, defaultfontclass}
%D
-%D Both groups of families are handles by a couple of token
-%D list tagged as strategies. This implementation makes
-%D implementing extensions more comfortable.
+%D The fontclass model was introduced a while after we implement
+%D the basic font model and at that time we still defaulted to
+%D no model at all. Nowadays we default to the \type {modern}
+%D fontclass.
+
+\let\fontclass \empty
+\let\defaultfontclass\empty
+
+%D \macros
+%D {textonly}
+%D
+%D Traditionally math has a big impact on font definitions, mainly
+%D because we need to define alphabet variants using families and
+%D fonts. This means that one can easily get 10 fonts loaded per
+%D math size. In \MKIV\ we use a different approach: one family
+%D which has either a virtual font made of traditional fonts, or
+%D an \OPENTYPE\ font that has it all.
+%D
+%D We currently use only one math family but in the future we
+%D might consider using a second one for bold math. For the
+%D moment we keep the \MKII\ method of using a token register
+%D for definitions but we already dropped the text and symbols
+%D ones since they now live in the same family.
-\newtoks \textstrategies
\newtoks \mathstrategies
-\newtoks \symbstrategies
\newif\ifsynchronizemathfonts \synchronizemathfontstrue
-\def\synchronizetext % stylish text in mmode
- {\ifsynchronizemathfonts\the\textstrategies\fi} % \if...\fam\minusone\fi}
-
\def\synchronizemath % math stuff in mmode
- {\ifsynchronizemathfonts\the\mathstrategies\fi} % \if...\fam\minusone\fi}
+ {\ifsynchronizemathfonts\the\mathstrategies\fi}
-\def\synchronizesymb % stylish math stuff in mmode
- {\ifsynchronizemathfonts\the\symbstrategies\fi} % \if...\fam\minusone\fi}
+\def\textonly{\synchronizemathfontsfalse} % document this
-%D By not setting the family we can append a font switch to \type
-%D {\everymath}. On the other hand, one never knows in what family
-%D state the strategies brought us.
-%D
-%D \starttyping
-%D {\bfa $\the\fam$} {\bfa \everymath{} $\the\fam$}
-%D \stoptyping
+%D The main math font definer. We have removed some optimized
+%D code simply because we now always have a fontclass. We could
+%D check for fontclass being default or empty and save a few
+%D tests but it does not help us when no math is defined.
-%D \macros
-%D {textonly}
-%D
-%D We can inhibit this slow||downer with:
+\chardef\mrfam\zerocount % math regular
+\chardef\mbfam\zerocount % math bold
-\def\textonly{\synchronizemathfontsfalse} % document this
+\def\mathtextsuffix {-text}
+\def\mathscriptsuffix {-script}
+\def\mathscriptscriptsuffix{-scriptscript}
-\appendtoks
- \dosettextfamily\c!tf
- \dosettextfamily\c!bf
- \dosettextfamily\c!sl
- \dosettextfamily\c!it
- \dosettextfamily\c!bs
- \dosettextfamily\c!bi
- \dosettextfamily\c!sc
-\to \textstrategies
-
-\def\dosettextfamily#1% better pass fontbody to dodoset
- {\let\savedfontbody\fontbody
- \let\fontfamily#1%
- \let\fontbody\scriptscriptface\dodosettextfamily\scriptscriptfont
- \let\fontbody\scriptface \dodosettextfamily \scriptfont
- \let\fontbody\textface \dodosettextfamily \textfont
- \let\fontbody\savedfontbody}
-
-% \def\s!nullfont{nullfont}
-
-\def\dodosettextfamily
- {\ifx\fontclass\empty
- \@EA\dodosettextfamilyA
- \else
- \@EA\dodosettextfamilyB
- \fi}
+% \let\mathsizesuffix\empty
-\def\dodosettextfamilyA#1%
- {\ifcsname \fontbody\c!mm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname \fontbody\c!mm\fontfamily\fontsize\endcsname \else
- \ifcsname \fontbody\c!mm\fontfamily\endcsname \autofontsizetrue
- \csname \fontbody\c!mm\fontfamily\endcsname \else
- \ifcsname \fontbody\c!rm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname \fontbody\c!rm\fontfamily\fontsize\endcsname \else
- \ifcsname \fontbody\c!rm\fontfamily\endcsname \autofontsizetrue
- \csname \fontbody\c!rm\fontfamily\endcsname \else
- \nullfont \autofontsizetrue
- \fi\fi\fi\fi
- #1\csname\fontfamily\s!fam\endcsname\font}
-
-\def\dodosettextfamilyB#1%
- {\ifcsname\fontclass\fontbody\c!mm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname\fontclass\fontbody\c!mm\fontfamily\fontsize\endcsname \else
- \ifcsname\fontclass\fontbody\c!mm\fontfamily\endcsname \autofontsizetrue
- \csname\fontclass\fontbody\c!mm\fontfamily\endcsname \else
- \ifcsname\fontclass\fontbody\c!rm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname\fontclass\fontbody\c!rm\fontfamily\fontsize\endcsname \else
- \ifcsname\fontclass\fontbody\c!rm\fontfamily\endcsname \autofontsizetrue
- \csname\fontclass\fontbody\c!rm\fontfamily\endcsname \else
- \dodosettextfamilyA#1%
- \fi\fi\fi\fi
- #1\csname\fontfamily\s!fam\endcsname\font}
-
-\def\mrfallback{\c!rm\c!tf}
+\chardef\currentmathsize\zerocount
-\appendtoks
- \dosetmathfamily\mrfam\textface\scriptface\scriptscriptface\c!mr\mrfallback
- \dosetmathfamily\mifam\textface\scriptface\scriptscriptface\c!mi\empty
- \dosetmathfamily\syfam\textface\scriptface\scriptscriptface\c!sy\empty
- \dosetmathfamily\exfam\textface\textface \textface \c!ex\empty
- \dosetmathfamily\mafam\textface\scriptface\scriptscriptface\c!ma\empty
- \dosetmathfamily\mbfam\textface\scriptface\scriptscriptface\c!mb\empty
- \dosetmathfamily\mcfam\textface\scriptface\scriptscriptface\c!mc\empty
-% \dosetmathfamily\mdfam\textface\scriptface\scriptscriptface\c!md\empty
- \dosetmathfamily\nnfam\textface\scriptface\scriptscriptface\c!nn\empty
-\to \mathstrategies
+\def\mathsizesuffix{\ifcase\currentmathsize\or\mathtextsuffix\or\mathscriptscriptsuffix\or\mathscriptsuffix\fi}
-\appendtoks
- \dosetskewchar\mifam\defaultskewcharmi % implemented later on
- \dosetskewchar\syfam\defaultskewcharsy % implemented later on
-\to \mathstrategies
+\def\dodosetmathfamily#1#2%
+ {\ifcsname\fontclass \fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \autofontsizefalse
+ \csname\fontclass \fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \else
+ \ifcsname\fontclass \fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \autofontsizetrue
+ \csname\fontclass \fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \else
+ \dodosetmathfamilyx#1#2%
+ \fi\fi
+ #1#2\font}
-\def\dosetmathfamily#1#2#3#4#5#6%
- {\let\savedfontbody\fontbody % op hoger plan
- \let\fontfamily#5%
- \let\backfamily#6%
- \let\fontbody #4\dodosetmathfamily\scriptscriptfont#1%
- \let\fontbody #3\dodosetmathfamily \scriptfont#1%
- \let\fontbody #2\dodosetmathfamily \textfont#1%
- \let\fontbody\savedfontbody}
-
-\def\dodosetmathfamily
- {\ifx\fontclass\empty
- \@EA\dodosetmathfamilyA
- \else
- \@EA\dodosetmathfamilyB
- \fi}
+\def\dodosetmathfamilyx#1#2%
+ {\ifcsname\defaultfontclass\fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \autofontsizefalse
+ \csname\defaultfontclass\fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \else
+ \ifcsname\defaultfontclass\fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \autofontsizetrue
+ \csname\defaultfontclass\fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \else
+ \dodosetmathfamilyxx#1#2%
+ \fi\fi}
-\def\dodosetmathfamilyA#1#2%
- {\ifcsname \fontbody\c!mm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname \fontbody\c!mm\fontfamily\fontsize\endcsname \else
- \ifcsname \fontbody\c!mm\fontfamily \endcsname \autofontsizetrue
- \csname \fontbody\c!mm\fontfamily \endcsname \else
- \ifcsname \fontbody \backfamily\fontsize\endcsname \autofontsizefalse
- \csname \fontbody \backfamily\fontsize\endcsname \else
- \ifcsname \fontbody \backfamily \endcsname \autofontsizetrue
- \csname \fontbody \backfamily \endcsname \else
- \nullfont \autofontsizetrue
- \fi\fi\fi\fi
- #1#2\font}
+\def\dodosetmathfamilyxx#1#2%
+ {\ifcsname \fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \autofontsizefalse
+ \csname \fontbody\c!mm\fontfamily\fontsize\the\currentmathsize\endcsname \else
+ \ifcsname \fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \autofontsizetrue
+ \csname \fontbody\c!mm\fontfamily \the\currentmathsize\endcsname \else
+ \nullfont \autofontsizetrue
+ \fi\fi}
-\def\dodosetmathfamilyB#1#2%
- {\ifcsname\fontclass\fontbody\c!mm\fontfamily\fontsize\endcsname \autofontsizefalse
- \csname\fontclass\fontbody\c!mm\fontfamily\fontsize\endcsname \else
- \ifcsname\fontclass\fontbody\c!mm\fontfamily \endcsname \autofontsizetrue
- \csname\fontclass\fontbody\c!mm\fontfamily \endcsname \else
- \ifcsname\fontclass\fontbody \backfamily\fontsize\endcsname \autofontsizefalse
- \csname\fontclass\fontbody \backfamily\fontsize\endcsname \else
- \ifcsname\fontclass\fontbody \backfamily \endcsname \autofontsizetrue
- \csname\fontclass\fontbody \backfamily \endcsname \else
- \dodosetmathfamilyA#1#2%
- \fi\fi\fi\fi
- #1#2\font}
+\def\dosetmathfamily#1#2%
+ {\let\savedfontbody\fontbody % op hoger plan
+ \let\fontfamily#2%
+ \let\currentmathsize\plusthree\let\fontbody\scriptscriptface\dodosetmathfamily\scriptscriptfont#1%
+ \let\currentmathsize\plustwo \let\fontbody\scriptface \dodosetmathfamily\scriptfont #1%
+ \let\currentmathsize\plusone \let\fontbody\textface \dodosetmathfamily\textfont #1%
+ \let\currentmathsize\zerocount
+ \let\fontbody\savedfontbody
+ \autofontsizefalse}
\appendtoks
- \dosetsymbfamily\mrfam\textface\scriptface\scriptscriptface\c!mr
- \dosetsymbfamily\mifam\textface\scriptface\scriptscriptface\c!mi
- \dosetsymbfamily\syfam\textface\scriptface\scriptscriptface\c!sy
- \dosetsymbfamily\exfam\textface\textface \textface \c!ex
- \dosetsymbfamily\mafam\textface\scriptface\scriptscriptface\c!ma
- \dosetsymbfamily\mbfam\textface\scriptface\scriptscriptface\c!mb
- \dosetsymbfamily\mcfam\textface\scriptface\scriptscriptface\c!mc
-% \dosetsymbfamily\mdfam\textface\scriptface\scriptscriptface\c!md % also ?
-\to \symbstrategies
-
-\def\dosetsymbfamily#1#2#3#4#5%
- {\let\savedfontbody\fontbody
- \let\fontfamily#5%
- \let\fontbody #4\dodosetsymbfamily\scriptscriptfont#1%
- \let\fontbody #3\dodosetsymbfamily \scriptfont#1%
- \let\fontbody #2\dodosetsymbfamily \textfont#1%
- \let\fontbody\savedfontbody}
-
-\def\dodosetsymbfamily#1#2%
- {\ifcsname\fontclass\fontbody\c!mm\fontfamily\fontalternative\fontsize\endcsname
- \csname\fontclass\fontbody\c!mm\fontfamily\fontalternative\fontsize\endcsname
- #1#2\font
- \else\ifcsname\fontbody\c!mm\fontfamily\fontalternative\fontsize\endcsname
- \csname\fontbody\c!mm\fontfamily\fontalternative\fontsize\endcsname
- #1#2\font
- \fi\fi}
+ \dosetmathfamily\mrfam\c!mr
+ %\dosetmathfamily\mbfam\c!mb % some day, only when defined, else equivalent to 0
+\to \mathstrategies
%D All used styles, like rm, ss and tt, are saved in a comma
%D separated list. Appart from practical limitations one can
%D define as many styles as needed.
-\let\stylelist=\empty
-
-\def\fontsizelist{\s!text,\s!script,\s!scriptscript,\c!x,\c!xx,\c!big,\c!small}
+\def\fontrelativesizelist{\s!text,\s!script,\s!scriptscript,\c!x,\c!xx,\c!big,\c!small}
-%D \macros
-%D {magfactor,magfactorhalf}
-%D
%D There are several ways to specify a font. Three of them are
%D pure \TeX\ ones, the fourth one is new:
%D
%D \starttyping
%D \font\name=cmr12
%D \font\name=cmr12 at 10pt
-%D \font\name=cmr12 scaled \magstep2
+%D \font\name=cmr12 scaled 2
%D \font\name=cmr12 sa 1.440
%D \stoptyping
%D
%D The non||\TEX\ alternative \type{sa} stands for {\em scaled
%D at}. This means as much as: scale the bodyfontsize with this
-%D factor. The value 1.440 in this example is derived
-%D from the \type{\magstep}'s as mentioned in
-%D \in{table}[tab:magstep]. We therefore introduce
-%D \type{\magfactor} as an alternative for \type{\magstep}.
-%D
-%D \placetable[here][tab:magstep]
-%D {Factors to be used with \type{sa.}}
-%D \starttable[|c|c|c|]
-%D \HL
-%D \NC \bf magstep \NC \bf equivalent \NC \bf factor \NC\SR
-%D \HL
-%D \NC 1 \NC \type{\magfactor1} \NC 1.200 \NC\FR
-%D \NC 2 \NC \type{\magfactor2} \NC 1.440 \NC\MR
-%D \NC 3 \NC \type{\magfactor3} \NC 1.728 \NC\MR
-%D \NC 4 \NC \type{\magfactor4} \NC 2.074 \NC\MR
-%D \NC 5 \NC \type{\magfactor5} \NC 2.488 \NC\LR
-%D \HL
-%D \stoptable
-
-\def\magstep#1% \relax removed, otherwise space after it sticks, else added
- {\ifcase#1 \@m\or1200\or1440\or1728\or2074\or2488\or\@m\fi}
-
-\def\magstephalf
- {1095}
-
-\def\magfactor#1%
- {\ifcase#1 1.000\or1.200\or1.440\or1.728\or2.074\or2.488\or1\fi}
-
-\def\magfactorhalf
- {1.095}
-
-%D These macros enable the use of definitions like \type{sa
-%D \magfactor3} which saves us both (mis|)|calculations and
-%D potential mistypings.
+%D factor. The scaled option is not that useful as one needs to
+%D know the design size.
%D
%D Because \type {sa} (scaled at) and \type {mo} (mapped on)
%D are not low level \TEX\ supported alternatives, we have to
@@ -1146,9 +553,25 @@
{\edef\relativefontsize
{\ifcsname\fontclass#1\s!rscale\endcsname
\csname\fontclass#1\s!rscale\endcsname
+ \else\ifcsname\defaultfontclass#1\s!rscale\endcsname
+ \csname\defaultfontclass#1\s!rscale\endcsname
\else
\defaultrelativefontsize
- \fi}}
+ \fi\fi}}
+
+% \letvalue{\s!default\s!rscale}\defaultrelativefontsize
+%
+% \def\checkrelativefontsize#1%
+% {\edef\relativefontsize
+% {\csname
+% \ifcsname\fontclass#1\s!rscale\endcsname
+% \fontclass#1%
+% \else\ifcsname\defaultfontclass#1\s!rscale\endcsname
+% \defaultfontclass#1%
+% \else
+% \s!default
+% \fi\fi
+% \s!rscale\endcsname}}
%D We also save:
@@ -1159,6 +582,38 @@
{\executeifdefined{\fontclass\c!mm\s!text}\empty}
%D Scaling macros:
+%D
+%D This system is somewhat complicated by two (possible conflicting)
+%D demands:
+%D
+%D \startitemize
+%D \item We support wildcards like \type {sa *} which will adapt
+%D to the current size. This is also the default specification.
+%D \item We support named scales like \type {sa d}; beware: \type
+%D {x} and \type {xx} are valid scales but they are not alway
+%D the same as the ones used in for instance \type {\bfx} because
+%D there the sized come from the bodyfont environment. In the
+%D future there maybe a switch that also honors the environment
+%D in named scales.
+%D \stopitemize
+
+%D Keep in mind that the smaller sizes are just for text super and
+%D subscripts while larger sizes can be used in titles where for
+%D instance math follows the size.
+
+% b:x{\definedfont[SerifBold sa b]x}{\bfb x $x^x$}\par
+% 1:x{\definedfont[SerifBold sa 1]x}{\bf x $x^x$}\par
+% x:x{\definedfont[SerifBold sa x]x}{\bfx x $x^x$}\par
+% xx:x{\definedfont[SerifBold sa xx]x}{\bfxx x $x^x$}\par
+%
+% *:x{\definedfont[Serif sa *]x}\par
+% 1:x{\definedfont[Serif sa 1]x}\par
+% 2:x{\definedfont[Serif sa 2]x}\par
+% 3:x{\definedfont[Serif sa 3]x}\par
+% 4:x{\definedfont[Serif sa 4]x}\par
+% 5:x{\definedfont[Serif sa 5]x}\par
+%
+% {\definedfont[cmbx10 at 10pt]x\definedfont[cmbx8 at 10pt]x}
\def\safontscale{\number\dimexpr\localabsolutefontsize\relax}
\def\mofontscale{\number\dimexpr\setmappedfontsize\localabsolutefontsize\relax}
@@ -1171,29 +626,39 @@
\newdimen\scaledfontsize
\newtoks\everydefinefont
+\def\currentfontbodysize
+ {\ifcsname\??ft\s!default\somefontsize\endcsname
+ \csname\??ft\s!default\somefontsize\endcsname
+ \else
+ \somefontsize
+ \fi}
+
\def\lowleveldefinefont#1#2% #2 = cs
- {\ctxlua{fonts.define.command_1("\luaescapestring{#1}")}% the escapestring catches at \somedimen
+ {%
+ \ctxlua{fonts.define.command_1("\luaescapestring{#1}")}% the escapestring catches at \somedimen
% sets \scaledfontmode and \somefontname and \somefontsize
\ifcase\scaledfontmode\relax
- % none
+ % none, avoid the designsize if possible
\scaledfontsize-1000\scaledpoint
\or
% at
\scaledfontsize\somefontsize
\or
% sa
- \scaledfontsize\localabsolutefontsize
- \scaledfontsize\ifcsname\??ft\s!default\somefontsize\endcsname\csname\??ft\s!default\somefontsize\endcsname\else\somefontsize\fi\scaledfontsize
+ \scaledfontsize\localabsolutefontsize\relax
+ \scaledfontsize\currentfontbodysize\scaledfontsize
\or
% mo
\scaledfontsize\setmappedfontsize\localabsolutefontsize
- \scaledfontsize\ifcsname\??ft\s!default\somefontsize\endcsname\csname\??ft\s!default\somefontsize\endcsname\else\somefontsize\fi\scaledfontsize
+ \scaledfontsize\currentfontbodysize\scaledfontsize
\or
- % scaled
+ % scaled, don't use this one as it's unpredictable
\scaledfontsize-\somefontsize\scaledpoint
\fi
\scaledfontsize\localrelativefontsize\scaledfontsize
- \ifautofontsize\scaledfontsize\currentfontbodyscale\scaledfontsize\fi
+ \ifautofontsize
+ \scaledfontsize\currentfontbodyscale\scaledfontsize
+ \fi
\edef\somefontspec{at \number\scaledfontsize sp}%
\edef\somefontfile{\truefontname\somefontname}%
\ifx\somefontfile\s!unknown
@@ -1209,7 +674,9 @@
"\@@fontclassfeatures",
"\@@fontfeatures",
"\@@fontclassfallbacks",
- "\@@fontfallbacks"
+ "\@@fontfallbacks",
+ \number\currentmathsize,
+ \number\dimexpr\textface\relax
)}%
\edef\somefontspec{at \somefontsize}% we need the resolved designsize (for fallbacks)
\expandafter\let\expandafter\lastrawfontcall\csname#2\endcsname
@@ -1219,12 +686,48 @@
{\edef\@@fontclassfeatures {\ifcsname\fontclass\s!features \endcsname\csname\fontclass\s!features \endcsname\fi}%
\edef\@@fontclassfallbacks{\ifcsname\fontclass\s!fallbacks\endcsname\csname\fontclass\s!fallbacks\endcsname\fi}}
+% resolve
+
+\def\@@thefeaturesyes#1%
+ {\ifcsname\??ff\fontclass#1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff\fontclass#1\s!features \endcsname\else
+ \ifcsname\??ff #1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff #1\s!features \endcsname\else
+ \ifcsname\??ff\fontclass #1\endcsname\@EA \@@thefeaturesyes \csname\??ff\fontclass #1\endcsname\else
+ \ifcsname\??ff #1\endcsname\@EA \@@thefeaturesyes \csname\??ff #1\endcsname\else
+ \let \@@fontfeatures \empty \fi\fi\fi\fi}
+
+\def\@@thefallbacksyes#1%
+ {\ifcsname\??ff\fontclass#1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff\fontclass#1\s!fallbacks\endcsname\else
+ \ifcsname\??ff #1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff #1\s!fallbacks\endcsname\else
+ \ifcsname\??ff\fontclass #1\endcsname\@EA \@@thefallbacksyes\csname\??ff\fontclass #1\endcsname\else
+ \ifcsname\??ff #1\endcsname\@EA \@@thefallbacksyes\csname\??ff #1\endcsname\else
+ \let \@@fontfallbacks \empty \fi\fi\fi\fi}
+
+\def\@@thefeaturesnop#1%
+ {\ifcsname\??ff#1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff#1\s!features \endcsname\else
+ \ifcsname\??ff #1\endcsname\@EA \@@thefeaturesnop \csname\??ff #1\endcsname\else
+ \let \@@fontfeatures \empty \fi\fi}
+
+\def\@@thefallbacksnop#1%
+ {\ifcsname\??ff#1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff#1\s!fallbacks\endcsname\else
+ \ifcsname\??ff #1\endcsname\@EA \@@thefallbacksnop\csname\??ff #1\endcsname\else
+ \let \@@fontfallbacks \empty \fi\fi}
+
+\def\updatefontparametersyes
+ {\@@thefeaturesyes \somefontname
+ \@@thefallbacksyes\somefontname}
+
+\def\updatefontparametersnop
+ {\@@thefeaturesnop \somefontname
+ \@@thefallbacksnop\somefontname}
+
+\def\updatefontparameters
+ {\ifx\fontclass\empty\updatefontparametersnop\else\updatefontparametersyes\fi}
+
\let\@@fontclassfeatures \empty
\let\@@fontclassfallbacks\empty
\let\@@fontfallbacks\empty
\let\@@fontfeatures \empty
-\let\@@skewchar \empty
\let\@@hyphenchar \empty % todo, will go to encoding
%D This brings down maps processing from 466 to 309 seconds
@@ -1334,14 +837,6 @@
%D We also accept \type{sa a}||\type{sa d} as specification.
-%D The duplicate font definition, using the ever the same dummy
-%D font name, results in less fuzzy error messages. In the log
-%D file, for instance when overfull boxes are reported, the
-%D simple keyword `font' replaces the \TEX\ ordinated name. The
-%D latter can be too misleading, due to the fact that \TEX\ has
-%D a rather optimized font memory management. Thanks to Taco
-%D for helping me sort this out.
-
%D \macros
%D {definefontsynonym, doifelsefontsynonym,
%D expandfontsynonym, truefontname, truefontdata}
@@ -1366,47 +861,64 @@
\def\definefontsynonym[#1]#2[#3]%
{\edef\@@fontname{#1}%
\edef\@@fontfile{#3}%
- \doifnextcharelse[\dodefinefontsynonym\nodefinefontsynonym}
-
-\def\nodefinefontsynonym
- {\@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile}
-
-\def\dodefinefontsynonym[#1]%
- {\edef\@@fontdata{#1}%
- \ifx\@@fontdata\empty
- \nodefinefontsynonym
+ \ifx\fontclass\empty
+ \expandafter\dodefinefontsynonymnop
\else
- \ifx\fontclass\empty
- \getfontparameters
- \else
- \getglobalfontparameters
- \fi
- \ifcsname\??ff\@@fontfile\s!features\endcsname
- \@EA\edef\csname\??ff\fontclass\@@fontname\endcsname{\@@fontfile*\csname\??ff\@@fontfile\s!features\endcsname}%
- \@EA\let\csname\??ff\@@fontfile\s!features\endcsname\undefined
- \else
- \nodefinefontsynonym
- \fi
+ \expandafter\dodefinefontsynonymyes
\fi}
-\def\getfontparameters
- {\expandafter\dogetfontparameter\@@fontdata,]=,}
+\def\dodefinefontsynonymnop
+ {\@EA\let\csname\??ff\@@fontname\endcsname\@@fontfile % maybe just #1 #3, saves expansion
+ \doifnextoptionalelse\dododefinefontsynonymnop\nonodefinefontsynonymnop}
+
+\def\dodefinefontsynonymyes
+ {\@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile % maybe just #1 #3, saves expansion
+ \doifnextoptionalelse\dododefinefontsynonymyes\nonodefinefontsynonymyes}
-\def\getglobalfontparameters
- {\expandafter\dogetglobalfontparameter\@@fontdata,]=,}
+\def\dododefinefontsynonymnop[#1]%
+ {\let\@@ff@@features \undefined
+ \let\@@ff@@fallbacks\undefined
+ \expandafter\dogetfontparameternop#1,]=,}
-\def\dogetfontparameter#1=#2,%
- {\if]#1\else
- \expandafter\def\csname\??ff\@@fontfile#1\endcsname{#2}%
- \expandafter\dogetfontparameter
+\def\dododefinefontsynonymyes[#1]%
+ {\let\@@ff@@features \undefined
+ \let\@@ff@@fallbacks\undefined
+ \expandafter\dogetfontparameteryes#1,]=,}
+
+\def\dogetfontparameternop#1=#2,%
+ {\if]#1%
+ \dodododefinefontsynonymnop
+ \else
+ \expandafter\def\csname @@ff@@#1\endcsname{#2}%
+ \expandafter\dogetfontparameternop
\fi}
-\def\dogetglobalfontparameter#1=#2,%
- {\if]#1\else
- \expandafter\gdef\csname\??ff\@@fontfile#1\endcsname{#2}%
- \expandafter\dogetglobalfontparameter
+\def\dogetfontparameteryes#1=#2,%
+ {\if]#1%
+ \dodododefinefontsynonymyes
+ \else
+ \expandafter\def\csname @@ff@@#1\endcsname{#2}%
+ \expandafter\dogetfontparameteryes
\fi}
+% hm, was wrong, class/global reversed
+
+\def\nonodefinefontsynonymnop
+ {\@EA\let\csname\??ff\@@fontname\s!features \endcsname\undefined
+ \@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\undefined}
+
+\def\nonodefinefontsynonymyes
+ {\global\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\undefined
+ \global\@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\undefined}
+
+\def\dodododefinefontsynonymnop
+ {\@EA\let\csname\??ff\@@fontname\s!features \endcsname\@@ff@@features
+ \@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks}
+
+\def\dodododefinefontsynonymyes
+ {\global\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\@@ff@@features
+ \global\@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks}
+
\let\definefontfile\definefontsynonym % dedicated to Taco Hoekwater
\def\setupfontsynonym
@@ -1423,20 +935,51 @@
\fi
\fi}
-\def\truefontdata#1#2%
- {\ifcsname\??ff#1#2\endcsname
- % raw(Regular) raw(key)
- \csname\??ff#1#2\endcsname
- \else\ifcsname\??ff\fontclass#1\endcsname
- % exp(palatino Regular) raw(key)
- \expandafter\truefontdata\csname\??ff\fontclass#1\endcsname#2%
- \else\ifcsname\??ff#1\endcsname
- % exp(Regular) raw(key)
- \expandafter\truefontdata\csname\??ff#1\endcsname#2%
- \else\ifcsname\??ff#2\endcsname
- % raw(key)
- \csname\??ff#2\endcsname
- \fi\fi\fi\fi}
+% \def\truefontname#1%
+% {\@EA\dotruefontname#1*\empty*\relax}
+%
+% \def\dotruefontname#1*#2#3*#4\relax
+% {\ifcsname\??ff\fontclass#1\endcsname
+% \ifx#2\empty
+% \@EA\truefontname\csname\??ff\fontclass#1\endcsname
+% \else
+% \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname*#2#3%
+% \fi
+% \else\ifcsname\??ff#1\endcsname
+% \ifx#2\empty
+% \@EA\truefontname\csname\??ff#1\endcsname
+% \else
+% \@EA\redotruefontname\csname\??ff#1\endcsname*#2#3%
+% \fi
+% \else
+% #1\ifx#2\empty\else*#2#3\fi
+% \fi\fi}
+%
+% \def\redotruefontname#1%
+% {\@EA\dodotruefontname#1*\relax}
+%
+% \def\dodotruefontname#1*#2\relax
+% {\ifcsname\??ff\fontclass#1\endcsname
+% \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname
+% \else\ifcsname\??ff#1\endcsname
+% \@EA\redotruefontname\csname\??ff#1\endcsname
+% \else
+% #1%
+% \fi\fi}
+%
+% \def\expandfontsynonym#1#2% #2 := onelevelexpansion(#1)
+% {\ifcsname\??ff\fontclass#2\endcsname
+% \expandafter\def\expandafter#1\expandafter{\csname\??ff\fontclass#2\endcsname}%
+% \fi}
+%
+% \def\doifelsefontsynonym#1%
+% {\ifcsname\??ff\fontclass#1\endcsname
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi}
+
+% maybe we need to stick in one branch
\def\truefontname#1%
{\@EA\dotruefontname#1*\empty*\relax}
@@ -1448,6 +991,12 @@
\else
\@EA\redotruefontname\csname\??ff\fontclass#1\endcsname*#2#3%
\fi
+ \else\ifcsname\??ff\defaultfontclass#1\endcsname
+ \ifx#2\empty
+ \@EA\truefontname\csname\??ff\defaultfontclass#1\endcsname
+ \else
+ \@EA\redotruefontname\csname\??ff\defaultfontclass#1\endcsname*#2#3%
+ \fi
\else\ifcsname\??ff#1\endcsname
\ifx#2\empty
\@EA\truefontname\csname\??ff#1\endcsname
@@ -1456,7 +1005,7 @@
\fi
\else
#1\ifx#2\empty\else*#2#3\fi
- \fi\fi}
+ \fi\fi\fi}
\def\redotruefontname#1%
{\@EA\dodotruefontname#1*\relax}
@@ -1464,23 +1013,29 @@
\def\dodotruefontname#1*#2\relax
{\ifcsname\??ff\fontclass#1\endcsname
\@EA\redotruefontname\csname\??ff\fontclass#1\endcsname
+ \else\ifcsname\??ff\defaultfontclass#1\endcsname
+ \@EA\redotruefontname\csname\??ff\defaultfontclass#1\endcsname
\else\ifcsname\??ff#1\endcsname
\@EA\redotruefontname\csname\??ff#1\endcsname
\else
#1%
- \fi\fi}
+ \fi\fi\fi}
\def\expandfontsynonym#1#2% #2 := onelevelexpansion(#1)
{\ifcsname\??ff\fontclass#2\endcsname
\expandafter\def\expandafter#1\expandafter{\csname\??ff\fontclass#2\endcsname}%
- \fi}
+ \else\ifcsname\??ff\defaultfontclass#2\endcsname
+ \expandafter\def\expandafter#1\expandafter{\csname\??ff\defaultfontclass#2\endcsname}%
+ \fi\fi}
\def\doifelsefontsynonym#1%
{\ifcsname\??ff\fontclass#1\endcsname
- \expandafter\firstoftwoarguments
+ \@EA\firstoftwoarguments
+ \else\ifcsname\??ff\defaultfontclass#1\endcsname
+ \@EAEAEA\firstoftwoarguments
\else
- \expandafter\secondoftwoarguments
- \fi}
+ \@EAEAEA\secondoftwoarguments
+ \fi\fi}
% \definetypeface[palatino][rm][serif][palatino,allbold][default]
%
@@ -1498,7 +1053,7 @@
\def\dostartfontclass[#1]%
{\pushmacro\fontclass
- \doifelse{#1}{\v!each}
+ \doifelse{#1}\v!each
{\let\fontclass\empty}
{\doifsomething{#1}{\def\fontclass{#1}}}}
@@ -1510,46 +1065,13 @@
%D
%D A goody:
-\def\tracedfontencoding#1%
- {\ifcsname\??ff#1\s!encoding\endcsname
- \space[\csname\??ff#1\s!encoding\endcsname]%
- \fi}
-
\def\tracedfontname#1%
- {\ifcsname\??ff\fontclass#1\endcsname
- #1\tracedfontencoding{\fontclass#1}\space->\space
- \@EA\tracedfontname\csname\??ff\fontclass#1\endcsname
+ {#1\ifcsname\??ff\fontclass#1\endcsname
+ \@EA\tracedfontname\csname\??ff\fontclass#1\endcsname
\else\ifcsname\??ff#1\endcsname
- #1\tracedfontencoding{#1}\space->\space
- \@EA\tracedfontname\csname\??ff#1\endcsname
- \else
- #1%
+ \@EA\tracedfontname\csname\??ff#1\endcsname
\fi\fi}
-%D \macros
-%D {getfontfileparameters}
-%D
-%D For special purposes, one can use the next macro to
-%D access font file characteristics, for instance:
-%D
-%D \starttyping
-%D \getfontfileparameters{Regular}
-%D \stoptyping
-%D
-%D can result in:
-%D
-%D \starttyping
-%D \def\currentfontfileencoding{texnansi}
-%D \stoptyping
-
-% \let\currentfontfileencoding\s!unknown
-% \let\currentfontfilemapping \s!unknown
-% \let\currentfontfilehandling\s!unknown
-
-% \def\getfontfileparameters#1%
-% {\edef\@@truefontname{\truefontname{#1}}%
-% \edef\currentfontfilefeatures{\truefontdata\@@truefontname\s!features}}
-
%D \macros
%D {definefont}
%D
@@ -1568,14 +1090,23 @@
\def\definefont
{\dotripleempty\dodefinefont}
+% \def\dodefinefont[#1][#2][#3]% [name][spec][1.6 | line=10pt | setup_id]
+% {\doifinstringelse{ }{#2}
+% {\ifthirdargument
+% \unexpanded\setvalue{#1}{\redodefinefont{#1}{#2}{#3}}%
+% \else
+% \unexpanded\setvalue{#1}{\dododefinefont{#1}{#2}}%
+% \fi}
+% {\definefont[#1][#2 sa *][#3]}}
+
+% we moved the unspecified size check to lua
+
\def\dodefinefont[#1][#2][#3]% [name][spec][1.6 | line=10pt | setup_id]
- {\doifinstringelse{ }{#2}
- {\ifthirdargument
- \unexpanded\setvalue{#1}{\redodefinefont{#1}{#2}{#3}}%
- \else
- \unexpanded\setvalue{#1}{\dododefinefont{#1}{#2}}%
- \fi}
- {\definefont[#1][#2 sa *][#3]}}
+ {\ifthirdargument
+ \unexpanded\setvalue{#1}{\redodefinefont{#1}{#2}{#3}}%
+ \else
+ \unexpanded\setvalue{#1}{\dododefinefont{#1}{#2}}%
+ \fi}
\def\redodefinefont#1#2#3%
{\dododefinefont{#1}{#2}%
@@ -1636,11 +1167,6 @@
\the\everyfontswitch
\fi}
-%D I considered checking for mistakenly use of \PLAIN's
-%D \type{\magstep}'s but although it would take only a few
-%D lines of code, this would not add to consistent use. I
-%D therefore removed this check.
-
%D \macros
%D {mapfontsize}
%D
@@ -1673,8 +1199,7 @@
{\dodoubleargument\domapfontsize}
\def\domapfontsize[#1][#2]%
- {\scratchdimen#1\relax % \relax is really needed here
- \setvalue{\??ft*\the\scratchdimen}{#2}}
+ {\setvalue{\??ft*\the\dimexpr#1\relax}{#2}}
\def\setmappedfontsize#1%
{\ifcsname\??ft*#1\endcsname
@@ -1695,26 +1220,25 @@
%D To be documented.
-\let\sizelist\empty
+\let\fontsizelist \empty
+\let\fontalternativelist\empty
+\let\fontstylelist \empty
-\def\definefontsize[#1]% sneller met toks
- {\addtocommalist{#1}\sizelist
- \def\docommand##1%
+\def\checkfontnamecombinations
+ {\def\docommand##1%
{\def\dodocommand####1%
- {\def\dododocommand########1%
- %{\checkbodyfont{}{########1}{####1}{##1}}%
- {\checkbodyfont{########1}{####1}{##1}}%
- \processcommacommand[\stylelist]\dododocommand}%
- \processcommacommand[\alternativelist]\dodocommand}%
- \processcommacommand[\sizelist]\docommand}
+ {\def\dododocommand########1{\checkbodyfont{########1}{####1}{##1}}%
+ \processcommacommand[\fontstylelist]\dododocommand}%
+ \processcommacommand[\fontalternativelist]\dodocommand}%
+ \processcommacommand[\fontsizelist]\docommand}
-\def\alternativetextlist{\c!tf,\c!bf,\c!it,\c!sl,\c!bs,\c!bi,\c!sc}
-\def\alternativemathlist{\c!mr,\c!mi,\c!sy,\c!ex,\c!ma,\c!mb}
-
-\let\alternativelist\alternativetextlist % upward compatible
+\def\definefontsize[#1]% sneller met toks
+ {\addtocommalist{#1}\fontsizelist
+ \checkfontnamecombinations}
-%\definefontsize[\c!a] \definefontsize[\c!b]
-%\definefontsize[\c!c] \definefontsize[\c!d]
+\def\definefontalternative[#1]%
+ {\addtocommalist{#1}\fontalternativelist
+ \checkfontnamecombinations}
%D \macros
%D {currentfontscale,currentfontbodyscale}
@@ -1810,7 +1334,7 @@
\let\bodyfontenvironmentlist\empty
-\newcount\@@fontdefhack
+\newcount\@@fontdefhack % check if this is still needed
\def\@@beginfontdef
{\ifcase\@@fontdefhack
@@ -1843,29 +1367,44 @@
\@EA\dododefinebodyfontenvironment\@EA[\tempbodyfontsize][#1][#3]}%
\@@endfontdef
\else
+ \ifx\fontclass\empty\else
+ \writestatus\m!fonts{beware: fontclass ignored (if needed use: [fontclass][size][settings])}%
+ \fi
+ \pushmacro\fontclass
+ \let\fontclass\empty
\definebodyfontenvironment[\fontclass][#1][#2]% change */*
+ \popmacro\fontclass
\fi}
\def\dododefinebodyfontenvironment[#1][#2][#3]% size class settings
- {\@@beginfontdef
- \doifundefined{\??ft#2#1\c!em} % \s!text goes wrong in testing because
- {\def\docommand##1% % the 12pt alternative will called when
- {\scratchdimen#1\relax % typesetting the test (or so)
- \scratchdimen\csname\??ft\s!default##1\endcsname\scratchdimen
+ {\@@beginfontdef % \s!text goes wrong in testing because the 12pt alternative will called when typesetting the test (or so)
+ \ifcsname\??ft#2#1\c!em\endcsname
+ % we test for em as we assume it to be set
+ \else
+ \def\docommand##1%
+% fails: \def\checkbodyfontenvironment[#1]{! #1 ! \definebodyfontenvironment[\fontclass][#1][]} \setupbodyfont[8.5pt]
+% {\normalizebodyfontsize\csname\??ft\s!default##1\endcsname\dimexpr#1\relax\to\tempbodyfontsize
+% \letvalue{\??ft#2#1##1}\tempbodyfontsize}%
+ {\scratchdimen\csname\??ft\s!default##1\endcsname\dimexpr#1\relax
\normalizebodyfontsize\scratchdimen\to\tempbodyfontsize
- \setevalue{\??ft#2#1##1}{\tempbodyfontsize}}%
- \processcommacommand[\fontsizelist]\docommand
+ \letvalue{\??ft#2#1##1}\tempbodyfontsize}%
+ \processcommacommand[\fontrelativesizelist]\docommand
\copyparameters
[\??ft#2#1][\??ft\s!default]
- [\c!interlinespace,\c!em]}%
+ [\c!interlinespace,\c!em]%
+ \fi
\getparameters[\??ft#2#1][#3]%
\@@endfontdef
% new code, see remark
- \ifloadingfonts \else % only runtime
- \doifundefined{\@size@#1} % only once
- {\letvalue{\@size@#1}\empty % prevent loop
- \defineunknownfont{#1}}% % safeguard
- \fi
+ \ifloadingfonts
+ % only runtime
+ \else\ifcsname\@size@#1\endcsname
+ % only once
+ \else
+ % prevent loop (hence \empty)
+ \letvalue{\@size@#1}\empty
+ \defineunknownfont{#1}%
+ \fi\fi
% so far
\setvalue{\@size@#1}{\docompletefontswitch[#1]}}
@@ -1891,28 +1430,18 @@
\def\checkbodyfontenvironment[#1]%
{\definebodyfontenvironment[\fontclass][#1][]}
+
+\def\checkbodyfontenvironment[#1]%
+ {\ifcsname\??ft\fontclass#1\c!em\endcsname
+ % we test for em as we assume it to be set
+ \else
+ \definebodyfontenvironment[\fontclass][#1][]%
+ \fi}
% this one already catches both define/setup
\def\setupbodyfontenvironment{\definebodyfontenvironment}
-% officially, but not needed (yet):
-%
-% \def\dosetupbodyfontenvironment[#1][#2][#3]% class size settings
-% {\ifthirdargument
-% \localbodyfontsize#2\relax
-% \normalizebodyfontsize\localbodyfontsize\to\normalizedbodyfontsize
-% \doifundefinedelse{\??ft#1\normalizedbodyfontsize\c!em}
-% {\definebodyfontenvironment[#1][#2][#3]}%
-% {\getparameters[\??ft#1\normalizedbodyfontsize][#3]}%
-% \else
-% \localbodyfontsize#1\relax
-% \normalizebodyfontsize\localbodyfontsize\to\normalizedbodyfontsize
-% \doifundefinedelse{\??ft\normalizedbodyfontsize\c!em}
-% {\definebodyfontenvironment[#1][#2]}%
-% {\getparameters[\??ft\normalizedbodyfontsize][#2]}%
-% \fi}
-
%D Just a couple of interface macros:
\def\bodyfontvariable#1%
@@ -1952,7 +1481,8 @@
%D We show two examples, that show all the alternative
%D scaling options. The \type{\tfa} alternatives can be
%D extended with \type{\bfa}, \type{\slb}, etc. or even
-%D \type{e} and higher alternatives.
+%D \type{e} and higher alternatives. The magic scaled
+%D values are derived from plain \TEX's \type {\magstep}:
%D
%D \starttyping
%D \definebodyfont [12pt] [rm]
@@ -1962,10 +1492,10 @@
%D sl=cmsl12,
%D bi=cmbxti10 at 12pt,
%D bs=cmbxsl10 at 12pt,
-%D tfa=cmr12 scaled \magstep1,
-%D tfb=cmr12 scaled \magstep2,
-%D tfc=cmr12 scaled \magstep3,
-%D tfd=cmr12 scaled \magstep4,
+%D tfa=cmr12 scaled 1.200,
+%D tfb=cmr12 scaled 1.440,
+%D tfc=cmr12 scaled 1.728,
+%D tfd=cmr12 scaled 2.074,
%D sc=cmcsc10 at 12pt]
%D
%D \definebodyfont [12pt,11pt,10pt,9pt,8pt] [rm]
@@ -2026,12 +1556,12 @@
\doifnumberelse{#1}
{\doifassignmentelse{#3}
{% [12pt] [style] [settings]
- \doifundefined{#2}{\expanded{\definefontstyle[#2][#2]}}% new
+ \doifundefined{#2}{\normalexpanded{\noexpand\definefontstyle[#2][#2]}}% new
\processcommalist[#1]{\dododefinebodyfont{#2}{#3}}}
{% [12pt] [style] [identifier]
\dodefinedefaultbodyfont[#1][#2][#3]}} % body style identifier
{% [identifier] [style] [settings] % see ***
- \setvalue{\s!default#1#2}##1##2{\expanded{\xdodefinebodyfont[##1][##2][#3]}}}%
+ \setvalue{\s!default#1#2}##1##2{\normalexpanded{\noexpand\xdodefinebodyfont[##1][##2][#3]}}}%
\else\ifsecondargument
\definebodyfont[#1][\c!rm][#2]%
\else
@@ -2042,9 +1572,8 @@
\fi\fi}
\def\xdodefinebodyfont[#1][#2][#3]% body|identifier style defs|identifier
- {%\writestatus{[#1]}{[#2][#3]}%
- \checkrelativefontsize{#2}% rather new, inherit from other defs
- \ifundefined{#2}\expanded{\definefontstyle[#2][#2]}\fi % new
+ {\checkrelativefontsize{#2}% rather new, inherit from other defs
+ \ifcsname#2\endcsname\else\normalexpanded{\noexpand\definefontstyle[#2][#2]}\fi % new
\processcommalist[#1]{\dododefinebodyfont{#2}{#3}}%
\let\relativefontsize\defaultrelativefontsize}
@@ -2055,47 +1584,56 @@
\def\dodododefinebodyfont#1#2#3% style body def
{\dododododefinebodyfont{#1}{#2}[#3]}
-\def\iflocalclassfonts{\ifx\fontclass\empty}
-
-\def\dododododefinebodyfont#1#2[#3#4#5=#6]% style body def
- {\ifundefined{#1#3#4#5}%
- %\checkbodyfont{#2}{#1}{#3#4}{#5}% not \definefontsize[#5]
- \checkbodyfont{#1}{#3#4}{#5}% not \definefontsize[#5]
- \fi
- \iflocalclassfonts
- \letbeundefined{*\fontclass#2#1#3#4#5*}%
- \scratchtoks{#6}%
- \expanded{\unexpanded\noexpand\setvalue{#2#1#3#4#5}%
- {\noexpand\xxdododefinefont{\relativefontsize}{#2}%
- {#2#1#3#4#5}{\the\scratchtoks}}}%
+\def\dododododefinebodyfont
+ {\ifx\fontclass\empty
+ \expandafter\dododododefinebodyfontnop
\else
- %\expanded{\writestatus{defining}{[\fontclass][#2#1#3#4#5] \resolvefontname#6 }}%
- \global\letbeundefined{*\fontclass#2#1#3#4#5*}%
- \scratchtoks{#6}%
- \expanded{\unexpanded\noexpand\setgvalue{\fontclass#2#1#3#4#5}%
- {\noexpand\xxdododefinefont{\relativefontsize}{#2}%
- {#2#1#3#4#5}{\the\scratchtoks}}}%
+ \expandafter\dododododefinebodyfontyes
\fi}
-% \def\checkbodyfont#1#2#3#4% body style alt size / gdef % #4 can be empty
-% {\def\c!!mm{#2}%
-% \ifx\c!!mm\c!mm % prevents \max and alike (re)defs
-% \unexpanded\setgvalue {#2}{\setcurrentfontstyle {#2}}% \rm
-% \unexpanded\setgvalue {#3}{\setcurrentfontalternative {#3}}% \sl
-% \else
-% \unexpanded\setgvalue {#2#4}{\setcurrentfontstylesize {#2}{#4}}% \rma
-% \unexpanded\setgvalue {#3#4}{\setcurrentfontalternativesize {#3}{#4}}% \sla
-% \unexpanded\setgvalue {#2#3#4}{\setcurrentfontstylealternativesize{#2}{#3}{#4}}% \rmsla
-% \unexpanded\setgvalue {#2}{\setcurrentfontstyle {#2}}% \rm
-% \unexpanded\setgvalue {#3}{\setcurrentfontalternative {#3}}% \sl
-% \unexpanded\setgvalue {#2\c!x}{\setcurrentfontxstylealternative {#2}}% \rmx
-% \unexpanded\setgvalue{#2\c!xx}{\setcurrentfontxxstylealternative {#2}}% \rmxx
-% \unexpanded\setgvalue {#3\c!x}{\setcurrentfontxalternative {#3}}% \slx
-% \unexpanded\setgvalue{#3\c!xx}{\setcurrentfontxxalternative {#3}}% \slxx
-% \unexpanded\setgvalue {#2#3}{\setcurrentfontstylealternative {#2}{#3}}% \rmsl
-% \fi}
-%
-% leaner
+\def\dododododefinebodyfontyes#1% style body def
+ {\edef\askedbodyfontstyle{#1}%
+ \ifx\askedbodyfontstyle\c!mm
+ \expandafter\dodefinebodyfontyesmm
+ \else
+ \expandafter\dodefinebodyfontyesxx
+ \fi\askedbodyfontstyle} % we can get rid of #1
+
+\def\dododododefinebodyfontnop#1% style body def
+ {\edef\askedbodyfontstyle{#1}%
+ \ifx\askedbodyfontstyle\c!mm
+ \expandafter\dodefinebodyfontnopmm
+ \else
+ \expandafter\dodefinebodyfontnopxx
+ \fi\askedbodyfontstyle} % we can get rid of #1
+
+\def\dodefinebodyfontnopxx#1#2[#3#4#5=#6]% style body def
+ {\ifcsname#1#3#4#5\endcsname\else\checkbodyfont{#1}{#3#4}{#5}\fi% not \definefontsize[#5]
+ \@EA\let\csname*#2#1#3#4#5*\endcsname\undefined
+ \normalprotected\@EA\edef\csname#2#1#3#4#5\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#5}{\normalunexpanded{#6}}}}
+
+\def\dodefinebodyfontyesxx#1#2[#3#4#5=#6]% style body def
+ {\ifcsname#1#3#4#5\endcsname\else\checkbodyfont{#1}{#3#4}{#5}\fi% not \definefontsize[#5]
+ \global\@EA\let\csname*\fontclass#2#1#3#4#5*\endcsname\undefined
+ \normalprotected\@EA\xdef\csname\fontclass#2#1#3#4#5\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#5}{\normalunexpanded{#6}}}}
+
+\def\dodefinebodyfontnopmm#1#2[#3#4#5=#6]% style body def
+ {\ifcsname#1#3#4#5\endcsname\else\checkbodyfont{#1}{#3#4}{#5}\fi% not \definefontsize[#5]
+ \@EA\let\csname*#2#1#3#4#51*\endcsname\undefined
+ \@EA\let\csname*#2#1#3#4#52*\endcsname\undefined
+ \@EA\let\csname*#2#1#3#4#53*\endcsname\undefined
+ \normalprotected\@EA\edef\csname#2#1#3#4#51\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#51}{\normalunexpanded{#6}}}%
+ \normalprotected\@EA\edef\csname#2#1#3#4#52\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#52}{\normalunexpanded{#6}}}%
+ \normalprotected\@EA\edef\csname#2#1#3#4#53\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#53}{\normalunexpanded{#6}}}}
+
+\def\dodefinebodyfontyesmm#1#2[#3#4#5=#6]% style body def
+ {\ifcsname#1#3#4#5\endcsname\else\checkbodyfont{#1}{#3#4}{#5}\fi% not \definefontsize[#5]
+ \global\@EA\let\csname*\fontclass#2#1#3#4#51*\endcsname\undefined
+ \global\@EA\let\csname*\fontclass#2#1#3#4#52*\endcsname\undefined
+ \global\@EA\let\csname*\fontclass#2#1#3#4#53*\endcsname\undefined
+ \normalprotected\@EA\xdef\csname\fontclass#2#1#3#4#51\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#51}{\normalunexpanded{#6}}}%
+ \normalprotected\@EA\xdef\csname\fontclass#2#1#3#4#52\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#52}{\normalunexpanded{#6}}}%
+ \normalprotected\@EA\xdef\csname\fontclass#2#1#3#4#53\endcsname{\noexpand\xxdododefinefont{\number\relativefontsize}{#2}{#2#1#3#4#53}{\normalunexpanded{#6}}}}
\def\checkbodyfont#1% tests for ttsl mmbf
{\def\c!!mm{#1}%
@@ -2108,9 +1646,9 @@
\def\checkmathbodyfont#1#2#3% style alt size / gdef % #3 can be empty
{%\message{!m #1 #2 #3!}%
% #1 #2 #3 = signal
- \unexpanded\setgvalue {#1#2#3}{\setcurrentfontstylealternativesize{#1}{#2}{#3}}% \mmsla
- \unexpanded\setgvalue {#1}{\setcurrentfontstyle {#1}}% \mm
- \unexpanded\setgvalue {#2}{\setcurrentfontalternative {#2}}}% \sl
+ %unexpanded\setgvalue {#1#2#3}{\setcurrentfontstylealternativesize{#1}{#2}{#3}}% \mmsla
+ \unexpanded\setgvalue {#2}{\setcurrentfontalternative {#2}}% \sl
+ \unexpanded\setgvalue {#1}{\setcurrentfontstyle {#1}}}% \mm
\def\checktextbodyfont#1#2#3% style alt size / gdef % #3 can be empty
{%\message{!t #1 #2 #3!}%
@@ -2144,40 +1682,42 @@
\newif\ifdefiningunknownfont
\def\dodefineunknownfont#1#2%
- {\doifdefined{\??ft\s!default#2}
- {\donetrue
- \scratchdimen#1\relax
- \scratchdimen\csname\??ft\s!default#2\endcsname\scratchdimen
- \normalizebodyfontsize\scratchdimen\to\!!stringa
- \letvalue{\??ft#1#2}\!!stringa}}
+ {\ifcsname\??ft\s!default#2\endcsname
+ \donetrue
+ \normalizebodyfontsize\csname\??ft\s!default#2\endcsname\dimexpr#1\relax\to\tempbodyfontsize
+ \letvalue{\??ft#1#2}\tempbodyfontsize
+ \fi}
\def\dodefineunknownbodyfont#1#2% see ***
- {\doifdefined{\s!default\s!default#2}% somehow related to */*
- {\donetrue
- \getvalue{\s!default\s!default#2}{#1}{#2}}}
+ {\ifcsname\s!default\s!default#2\endcsname % somehow related to */*
+ \donetrue
+ \getvalue{\s!default\s!default#2}{#1}{#2}%
+ \fi}
\def\dodefineunknownsubfont#1#2%
- {\doifundefined{\@size@\getvalue{\??ft#1#2}}
- {\donetrue
- \defineunknownfont{\getvalue{\??ft#1#2}}}}
+ {\ifcsname\@size@\getvalue{\??ft#1#2}\endcsname
+ \else
+ \donetrue
+ \defineunknownfont{\getvalue{\??ft#1#2}}%
+ \fi}
\def\defineunknownfont#1%
{\let\c!savedtext\c!text
\let\c!text\s!text
\donefalse
- \processcommacommand[\fontsizelist]{\dodefineunknownfont{#1}}%
+ \processcommacommand[\fontrelativesizelist]{\dodefineunknownfont{#1}}%
\let\c!text\c!savedtext
\ifdone
\donefalse
\processcommacommand
- [\stylelist]
+ [\fontstylelist]
{\dodefineunknownbodyfont{#1}}%
\ifdone
\donefalse
\setvalue{\@size@#1}{\docompletefontswitch[#1]}%
\ifdefiningunknownfont \else
\definingunknownfonttrue
- \processcommacommand[\fontsizelist]{\dodefineunknownsubfont{#1}}%
+ \processcommacommand[\fontrelativesizelist]{\dodefineunknownsubfont{#1}}%
\definingunknownfontfalse
\fi
\fi
@@ -2238,8 +1778,8 @@
%D size and the local (sometimes in the textflow) size. We
%D store these dimensions in two \DIMENSION\ registers.
-\newdimen\globalbodyfontsize \globalbodyfontsize=12pt
-\newdimen\localbodyfontsize \localbodyfontsize =\globalbodyfontsize
+\ifdefined\globalbodyfontsize\else \newdimen\globalbodyfontsize \fi \globalbodyfontsize=12pt
+\ifdefined\localbodyfontsize \else \newdimen\localbodyfontsize \fi \localbodyfontsize =\globalbodyfontsize
%D \macros
%D {bodyfontsize}
@@ -2273,34 +1813,41 @@
%D often not the way users specify the bodyfont size. Therefore
%D we also store the normalized value.
-\chardef\fontdigits=1
+\chardef\fontdigits=2 % was 1
\def\normalizebodyfontsize#1\to#2%
- {\scratchdimen#1\relax
- \ifcase\fontdigits\advance\scratchdimen.5\points\fi
- \@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\scratchdimen00\to#2}
+ {\@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\dimexpr#1+\ifcase\fontdigits.5\or.05\or.005\fi\points\relax000\to#2}
-\def\donormalizedbodyfontsize#1.#2#3#4\to#5% \points ?
- {\edef#5%
+\def\donormalizedbodyfontsize#1.#2#3#4#5\to#6% \points ?
+ {\edef#6% not \ifcase#2\else due to \relax adding
{#1%
- \ifcase\fontdigits\or
- \ifcase#2 \else.#2\fi % and not: \ifcase#2\else ...
- \else
- \ifcase#2#3 \else.#2\ifcase#3 \else#3\fi\fi % not: \ifcase#2#3\else ...
+ \ifcase\fontdigits
+ \or \ifcase#2 \else .#2\fi % 1
+ \or \ifcase#2#3 \else .#2\ifcase#3 \else #3\fi\fi % 2
+ \else \ifcase#2#3#4 \else .#2\ifcase#4 \ifcase#3 \else#3\fi \else#3#4\fi\fi % 3
\fi
\s!pt}}
+% not faster, just less tracing
+%
+% \def\setfontdigits#1%
+% {\chardef\fontdigits\ifnum#1>\plusthree\plusthree\else#1\fi\relax
+% \@EA\let\@EA\normalizedbfs\csname normalizedbfs\number\fontdigits\endcsname}
+%
+% \def\normalizebodyfontsize#1\to#2%
+% {\@EA\@EA\@EA\normalizedbfs\@EA\WITHOUTPT\the\dimexpr#1+\ifcase\fontdigits.5\or.05\or.005\fi\points\relax000\to#2}
+%
+% \setvalue{normalizedbfs0}#1.#2\to #3{\edef#3{#1\s!pt}}
+% \setvalue{normalizedbfs1}#1.#2#3\to #4{\edef#4{#1\ifcase#2 \else.#2\fi\s!pt}}
+% \setvalue{normalizedbfs2}#1.#2#3#4\to #5{\edef#5{#1\ifcase#2#3 \else.#2\ifcase#3 \else#3\fi\fi\s!pt}}
+% \setvalue{normalizedbfs3}#1.#2#3#4#5\to#6{\edef#6{#1\ifcase#2#3#4 \else.#2\ifcase#4 \ifcase#3 \else#3\fi\else#3#4\fi\fi\s!pt}}
+%
+% \setfontdigits2
+
\normalizebodyfontsize\bodyfontsize\to\normalizedglobalbodyfontsize
\normalizebodyfontsize\bodyfontsize\to\normalizedlocalbodyfontsize
\normalizebodyfontsize\bodyfontsize\to\normalizedbodyfontsize
-%D To be internationalized:
-
-\def\korpsgrootte {\bodyfontsize}
-\def\korpspunten {\bodyfontpoints}
-
-%D some day.
-
%D \macros
%D {fontstyle,fontalternative,fontsize}
%D
@@ -2320,29 +1867,7 @@
\let\fontalternative = \defaultfontalternative
\let\fontstyle = \defaultfontstyle
-\let\fontsize = \defaultfontsize
-
-%D {\em The following approach is obsolete.}
-%D
-%D All things related to fonts are grouped into files with
-%D names like \type{font-cmr}. These files are loaded by:
-
-\def\resetfontdefinitionfile[#1]%
- {\letbeundefined{\c!file\f!fontprefix#1}}
-
-\newif\ifloadfontfileonce
-
-\def\doreadfontdefinitionfile#1#2% #1 = set/switch state
- {\doifundefined{\c!file\f!fontprefix#2}%
- {\ifloadfontfileonce
- \letvalue{\c!file\f!fontprefix#2}\empty
- \fi
- \makeshortfilename[\truefilename{\f!fontprefix#2}]%
- \startreadingfile
- \readsysfile\shortfilename
- {\showmessage\m!fonts2{#2}}
- {\showmessage\m!fonts3{#2}}%
- \stopreadingfile}}
+\let\fontsize = \defaultfontsize
%D When \type {\loadfontfileoncetrue}, such files are
%D only loaded once! This permits redundant loading, but at
@@ -2352,8 +1877,10 @@
%D needed to prevent problems with loading files that use this
%D character in numbers.
+% can be made faster (only used internally now)
+
\def\doswitchpoints[#1]%
- {\expanded{\dodoswitchpoints{#1}}}
+ {\normalexpanded{\noexpand\dodoswitchpoints{#1}}}
\def\dodoswitchpoints#1%
{\doifundefined{\@size@#1}
@@ -2363,6 +1890,7 @@
{\getvalue{\@size@#1}%
\localbodyfontsize#1\relax
\normalizebodyfontsize\localbodyfontsize\to\normalizedbodyfontsize
+% \edef\fontbody{\fontbody}% to be tested but we can clean up mkiv further
\checkbodyfontenvironment[\normalizedbodyfontsize]}
{\showmessage\m!fonts4{#1}}}
@@ -2425,17 +1953,29 @@
%D sequence of a session. After the loading job is done, the
%D macro relaxes itself and reset the signal.
+% \appendtoks
+% \to \everysetupdocument
+
+\newconditional\fontsareloaded
+
\def\preloadfonts % never called, needs a clean up
- {\showmessage\m!fonts6{\normalizedbodyfontsize\normalspace\fontstyle}%
- \global\loadingfontsfalse
- \doswitchpoints[\normalizedbodyfontsize]%
- \doswitchstyle[\fontstyle]%
- \the\everybodyfont
- \the\everyglobalbodyfont
- \saveinterlinespace
+ {\global\loadingfontsfalse
+ \ifconditional\fontsareloaded \else
+ \doifmodeelse {*nofonts}
+ {\writestatus\m!fonts{latin modern fonts are not preloaded}}
+ {\writestatus\m!fonts{preloading latin modern fonts}%
+ \usetypescript[modern]%
+ \setuptypeface[modern]%
+ \showmessage\m!fonts6{\normalizedbodyfontsize\normalspace\fontstyle}}%
+ \fi
\global\let\preloadfonts\relax}
-% \prependtoks \preloadfonts \to \everydump % saves .1 s on a DELL P60 - 2GHZ
+% maybe add this to \everystarttext
+%
+% \ifconditional\fontsareloaded\else
+% \usetypescript[modern]%
+% \setuptypeface[modern]%
+% \fi
%D Here comes the main font switching macros. These macros
%D handle changes in size as well as returning to the global
@@ -2446,36 +1986,68 @@
{\restoreglobalbodyfont}
{\processcommacommand[#2]{\dodosetfont{#1}}% ##1 get also passed
\ifloadingfonts\else
+ \global\settrue\fontsareloaded
\doswitchpoints[\normalizedbodyfontsize]%
\doswitchstyle[\fontstyle]%
+ \ifx\defaultfontclass\empty
+ \let\defaultfontclass\fontclass
+ \fi
\fi}%
\chardef\currentxfontsize\zerocount}
\def\dodosetfont#1#2% #1 = set/switch state | check fo rempty, else space
{\doifsomething{#2}{\dododosetfont{#1}{#2}{\showmessage\m!fonts4{#2}}}}
-\def\dododosetfont#1#2#3% #1 = set/switch state
- {\doifnumberelse{#2}
- {\dodododosetfont{#1}{#2}{#3}}
- {\doifdefinedelse{\??ft\normalizedbodyfontsize\interfaced{#2}}
- {\edef\fontstep{\csname\bodyfontvariable\normalizedbodyfontsize\interfaced{#2}\endcsname}%
- \expanded{\dodododosetfont{#1}{\fontstep}}{#3}}
- {\doifelse{#2}\v!reset
- {\let\fontstyle\empty % new 31/7/2006
- \let\fontsize \empty}
- {\doifdefinedelse{\@style@#2}
- {\edef\fontstyle{#2}}
- {\doreadfontdefinitionfile{#1}{#2}}}}}}
+% % % this can be retrofitted in mkii code % % %
+
+% \def\normalizebodyfontsize#1\to#2%
+% {\@EA\@EA\@EA\donormalizedbodyfontsize\@EA\WITHOUTPT\the\dimexpr#1+\ifcase\fontdigits.5\or.05\or.005\fi\points\relax000\to#2}
+
+\def\dododosetfont#1#2#3% #1 = set/switch state ! ! ! !could also be used for mkii
+ {\doifnumberelse{#2}\dodododosetfont\redododosetfont{#1}{#2}{#3}}
+
+\def\redododosetfont#1#2#3% #1 = set/switch state ! ! ! !could also be used for mkii
+ {\edef\expandedfontthing{#2}%
+ \def\interfacedfontsize{\normalizedbodyfontsize\interfaced\expandedfontthing}%
+ \ifcsname\??ft\interfacedfontsize\endcsname
+ \edef\fontstep{\csname\bodyfontvariable\interfacedfontsize\endcsname}%
+ \normalexpanded{\noexpand\dodododosetfont{#1}{\fontstep}}{#3}%
+ \else\ifx\expandedfontthing\v!reset
+ \let\fontstyle\empty % new 31/7/2006
+ \let\fontsize \empty
+ \else
+ \ifcsname\@style@\expandedfontthing\endcsname
+ \let\fontstyle\expandedfontthing
+ \else
+ \setcurrentfontclass\expandedfontthing
+ \ifcase#1\relax
+ \let\globalfontclass\globalfontclass
+ \else
+ \let\globalfontclass\fontclass
+ \fi
+ \ifx\fontclass\empty
+ \let\fontstyle\c!rm
+ \else\ifcsname\??tf\fontclass\s!default\endcsname
+ \edef\fontstyle{\csname\??tf\fontclass\s!default\endcsname}%
+ \else
+ \let\fontstyle\c!rm
+ \fi\fi
+ \fi
+ \fi\fi}
\def\dodododosetfont#1#2#3% #1 = set/switch state
- {\scratchdimen#2\relax
- \normalizebodyfontsize\scratchdimen\to\normalizedsetfont
- \doifundefined{\@size@\normalizedsetfont}
- {\defineunknownfont{#2}}%
- \doifdefinedelse{\@size@\normalizedsetfont}
- {\localbodyfontsize\normalizedsetfont
- \let\normalizedbodyfontsize\normalizedsetfont}
- {#3\dosetsubstitutefont{#1}{#2}}}
+ {\normalizebodyfontsize#2\to\normalizedsetfont
+ \ifcsname\@size@\normalizedsetfont\endcsname \else
+ \defineunknownfont{#2}%
+ \fi
+ \ifcsname\@size@\normalizedsetfont\endcsname
+ \localbodyfontsize\normalizedsetfont
+ \let\normalizedbodyfontsize\normalizedsetfont
+ \else
+ #3\dosetsubstitutefont{#1}{#2}%
+ \fi}
+
+% % %
%D In the previous macros we use \type{\currentxfontsize} to
%D hold the current x||size of the font. This enables us to
@@ -2515,8 +2087,15 @@
\let\fontclass\empty \let\globalfontclass\fontclass
+% we need to check the fontclass
+
+\def\registerfontclass#1%
+ {\letgvalue{\@fontclass@#1}\v!yes} % global ?
+
\def\setcurrentfontclass#1%
- {\edef\fontclass{#1}}
+ {\ifcsname\@fontclass@#1\endcsname
+ \edef\fontclass{#1}%
+ \fi}
\let\defaultfontstyle \c!rm
\let\defaultfontalternative \c!tf
@@ -2553,7 +2132,7 @@
% already in sync
\else
\let\bigmathfontsize\fontsize
- \synchronizemath \synchronizetext
+ \synchronizemath
\fi}
\def\checkbigmathsynchronization
@@ -2572,10 +2151,7 @@
\checkbigmathsynchronization}
\def\dosetcurrentfontalternative#1%
- {\edef\fontalternative{#1}%
- \ifmmode % maybe no test, or actually, an option
- \fam\csname\fontalternative\s!fam\endcsname
- \fi}
+ {\edef\fontalternative{#1}}
\def\setcurrentfont#1#2#3#4%
{%\message{[1 #1 #2 #3 #4]}%
@@ -2660,6 +2236,7 @@
\global\let\fontstrategy\dofontstrategy
\the\fontstrategies \relax % \relax still needed ?
\fi
+ \autofontsizefalse
\ifskipfontcharacteristics
\setfontcharacteristics
\the\everyfontswitch
@@ -2675,6 +2252,8 @@
#1\csname\fontclass#2#3#4#5\endcsname \tryingfontfalse
\fi}
+% old sequence
+
\appendtoks \iftryingfont \fontstrategy \autofontsizefalse % --- --- --- --- % pt tt bf a
\fontbody \fontstyle \fontalternative \fontsize
\fi \to \fontstrategies
@@ -2706,7 +2285,6 @@
\prependtoks
\ifsynchronizefonts
\synchronizemath
- \synchronizetext
\synchronizefont % problem: syncs last font
\fi
\to \everybodyfont
@@ -2757,9 +2335,6 @@
% This alterative is not really needed, but for old time's sake
% we keep it there. We can speed it up when needed.
-% \def\setcurrentfontxstylealternative #1{\csname#1\endcsname\tfx}
-% \def\setcurrentfontxxstylealternative#1{\csname#1\endcsname\tfxx}
-
\def\setcurrentfontxstylealternative #1{\csname#1\endcsname\tx}
\def\setcurrentfontxxstylealternative#1{\csname#1\endcsname\txx}
@@ -2808,10 +2383,11 @@
%D \stoptyping
\def\dodefinefontstyle[#1][#2]%
- {\rawdoifinsetelse{#2}{\stylelist}
- {}%\debuggerinfo\m!fonts{unknown style #2}}
- {\addtocommalist{#2}\stylelist
- \showmessage\m!fonts8{#2\space (#1)}}%
+ {\rawdoifinsetelse{#2}{\fontstylelist}
+ {%\debuggerinfo\m!fonts{unknown style #2}%
+ }
+ {%\debuggerinfo\m!fonts8{#2\space (#1)}%
+ \addtocommalist{#2}\fontstylelist}%
% check kan hier
\def\docommand##1%
{\setvalue{\@shortstyle@##1}{#2}%
@@ -2823,25 +2399,9 @@
\def\setfontstyle#1#2% #1:name (roman, romaan) #2:style (rm)
{\edef\fontstyle{#1}%
+ \checkfontnamecombinations
\setcurrentfontstyle\normalizedbodyfontsize}
-\chardef\defaultskewcharmi=127 % '177
-\chardef\defaultskewcharsy= 48 % '60
-
-% \def\dosetskewchar#1%
-% {\skewchar\font\ifx\@@fontskewchar\empty#1\else\@@fontskewchar\fi}
-
-\def\dosetskewchar#1#2%
- {\ifx\@@fontskewchar\empty
- \skewchar\textfont #1#2%
- \skewchar\scriptfont #1#2%
- \skewchar\scriptscriptfont#1#2%
- \else
- \skewchar\textfont #1\@@fontskewchar
- \skewchar\scriptfont #1\@@fontskewchar
- \skewchar\scriptscriptfont#1\@@fontskewchar
- \fi}
-
%D The previous macros show that it's is not always
%D neccessary to define the whole bunch of fonts, take for
%D instance the sequence:
@@ -2878,7 +2438,7 @@
\def\docompletefontswitch[#1]%
{\bodyfontsize#1\relax
- \dimensiontocount\bodyfontsize\bodyfontpoints
+ \dimensiontocount\bodyfontsize\bodyfontpoints % rounded, still used in m-chart
\edef\bodyfontfactor{\withoutpt\the\bodyfontsize}%
\normalizebodyfontsize\bodyfontsize\to\normalizedbodyfontsize
\dosetbodyfontface \textface \s!text
@@ -2948,8 +2508,7 @@
\def\fastswitchtobodyfont#1%
{\ifcsname\??ft\normalizedbodyfontsize#1\endcsname
- \edef\futurebodyfontsize
- {\csname\??ft\normalizedbodyfontsize#1\endcsname}%
+ \edef\futurebodyfontsize{\csname\??ft\normalizedbodyfontsize#1\endcsname}%
\ifcsname\@size@\futurebodyfontsize\endcsname
\csname\@size@\futurebodyfontsize\endcsname
\localbodyfontsize\futurebodyfontsize\relax
@@ -2958,46 +2517,10 @@
\csname\@style@\fontstyle\endcsname
\the\everybodyfont}
-%D Because the last macro can appear in arguments or be assigned
-%D to parameters, we protect this one for unwanted expansion.
-
-\def\dodosetmathfont#1%
- {\setcurrentfontalternative{#1}%
- % \doifdefinedelse{#1\s!fam} % adapted
- % {\edef\mffam{\getvalue{#1\s!fam}}}
- % {\edef\mffam{\getvalue{\c!nn\s!fam}}}%
- \textfont \mrfam\textfont \mffam
- \scriptfont \mrfam\scriptfont \mffam
- \scriptscriptfont\mrfam\scriptscriptfont\mffam}
-
-\def\domffam#1%
- {\csname\ifcsname#1\s!fam\endcsname#1\else\c!nn\fi\s!fam\endcsname}
-
-\def\mffam
- {\domffam\fontalternative}
-
-\def\dosetmathfont
- {\def\rm{\fam\mrfam}\dodosetmathfont}
-
-\def\enableencodinginmath
- {\appendtoks
- \everyhbox{\mr\everyhbox\emptytoks}%
- \everyvbox{\mr\everyvbox\emptytoks}%
- \to \everymathematics} % was \everymath
-
-% \enableencodinginmath % too untested to enable by default
-
%D \starttyping
%D $\cases{& \ccaron}$ $x=\hbox{\ccaron $x=\hbox{\ccaron}$}$
%D \stoptyping
-%D The font specific features are bound to the filename.
-
-\def\updatefontparameters
- {\edef\@@fontfeatures {\truefontdata\somefontfile\s!features}%
- \edef\@@fontfallbacks{\truefontdata\somefontname\s!fallbacks}%
- \edef\@@fontskewchar {\truefontdata\somefontfile\s!skewchar}} % will be replaced
-
\def\setfontcharacteristics
{\the\everyfont}
@@ -3020,27 +2543,53 @@
{\dotripleargument\dodefinefontfeature}
\def\dodefinefontfeature[#1][#2][#3]%
- {\ctxlua{fonts.define.specify.preset_context("#1","#2","#3")}}
+ {\global\expandafter\chardef\csname\??fq=#1\endcsname
+ \ctxlua{tex.write(fonts.define.specify.preset_context("#1","#2","#3"))}\relax}
\definefontfeature
[default]
- [liga=yes,kern=yes,tlig=yes,trep=yes] % texligatures=yes,texquotes=yes
+ [%mode=node,%
+ liga=yes,kern=yes,tlig=yes,trep=yes] % texligatures=yes,texquotes=yes
\definefontfeature
[smallcaps]
- [liga=yes,kern=yes,tlig=yes,trep=yes,smcp=yes] % texligatures=yes,texquotes=yes
+ [%mode=node,%
+ liga=yes,kern=yes,tlig=yes,trep=yes,smcp=yes] % texligatures=yes,texquotes=yes
\definefontfeature
[oldstyle]
- [liga=yes,kern=yes,tlig=yes,trep=yes,onum=yes] % texligatures=yes,texquotes=yes
+ [%mode=node,%
+ liga=yes,kern=yes,tlig=yes,trep=yes,onum=yes] % texligatures=yes,texquotes=yes
-\definefontfeature % no calt
+\definefontfeature
[arabic]
- [mode=node,language=dflt,script=arab,
+ [mode=node,language=dflt,script=arab,ccmp=yes,
init=yes,medi=yes,fina=yes,isol=yes,
- liga=yes,dlig=yes,rlig=yes,clig=yes,
+ liga=yes,dlig=yes,rlig=yes,clig=yes,calt=yes,
mark=yes,mkmk=yes,kern=yes,curs=yes]
+\definefontfeature
+ [none]
+ [mode=none,features=off]
+
+\definefontfeature
+ [virtualmath]
+ [mode=base,liga=yes,kern=yes,tlig=yes,trep=yes]
+
+% for the moment here, this will change but we need it for mk.tex
+
+\definefontfeature[math-text] [virtualmath][ssty=no]
+\definefontfeature[math-script] [virtualmath][ssty=1,mathsize=yes]
+\definefontfeature[math-scriptscript][virtualmath][ssty=2,mathsize=yes]
+
+\definefontfeature [math-nostack-text] [math-text] [nostackmath=yes]
+\definefontfeature [math-nostack-script] [math-script] [nostackmath=yes]
+\definefontfeature [math-nostack-scriptscript][math-scriptscript][nostackmath=yes]
+
+% \definefontfeature[mathtext] [math-text]
+% \definefontfeature[mathscript] [math-script]
+% \definefontfeature[mathscriptscript] [math-scriptscript]
+
%D Also new:
% handy for manuals
@@ -3052,32 +2601,9 @@
\definecolor[font:init][r=.75]
\definecolor[font:medi][g=.75]
\definecolor[font:fina][b=.75]
-\definecolor[font:isol][y=.75]
-\definecolor[font:mark][m=.75]
-\definecolor[font:rest][c=.75]
-
-%D goodies:
-%D
-%D \starttyping
-%D \showinstalledfonts[officinasans.*][all]
-%D \showinstalledfonts[officinaserif.*][all]
-%D \showinstalledfonts[officina.*itc.*][all]
-%D
-%D \showinstalledfonts[officina.*itc.*][all,new]
-%D \stoptyping
-
-\def\showinstalledfonts
- {\dodoubleempty\doshowinstalledfonts}
-
-\def\doshowinstalledfonts[#1][#2]%
- {\bgroup
- \def\pattern{#1}%
- \def\all{false}%
- \def\reload{false}%
- \doifnothing\pattern{\def\pattern{.*}}%
- \processallactionsinset[#2][\v!new=>\def\reload{true},\v!all=>\def\all{true}]%
- \ctxlua{fonts.names.table("#1",\reload,\all)}%
- \egroup}
+\definecolor[font:isol][r=.75,g=.75] % [y=.75]
+\definecolor[font:mark][r=.75,b=.75] % [m=.75]
+\definecolor[font:rest][g=.75,b=.75] % [c=.75]
%D Experimental!
@@ -3085,7 +2611,7 @@
{\dodoubleargument\doinstallfontfeature}
\def\doinstallfontfeature[#1][#2]%
- {\ctxlua{fonts.install_feature("#1","#2")}}
+ {\writestatus\m!fonts{installing font features was experimental}} % \ctxlua{fonts.install_feature("#1","#2")}}
%D Not yet in \MKII.
@@ -3099,13 +2625,35 @@
\let\currentfeature\empty
+% ! ! ! very experimental, some test code for idris advanced features ! ! !
+%
+% \startbuffer
+% \definefontfeature[smallcaps][smallcaps][script=latn]
+% \definefontfeature[oldstyle] [oldstyle] [script=latn]
+%
+% \definedfont[name:cambria at 15pt]
+%
+% Hello there {\setff{smallcaps}capped 123 \setff{oldstyle}123!} \blank
+% Hello there {\addff{smallcaps}capped 123 \addff{oldstyle}123!} \blank
+% Hello there {\addff{smallcaps}capped \subff{smallcaps}normal} \blank
+% \stopbuffer
+%
+% \typebuffer \getbuffer
+
\def\featureattribute#1{\ctxlua{tex.sprint(fonts.define.specify.context_number("#1"))}}
\def\setfontfeature #1{\edef\currentfeature{#1}\attribute\zerocount\featureattribute{#1}\relax}
-\def\resetfontfeature#1{\let\currentfeature\empty\attribute\zerocount\zerocount}
+\def\resetfontfeature#1{\let\currentfeature\empty\attribute\zerocount\zerocount} % initial value
-\appendtoks
- \setfontfeature\currentfeature
-\to \everylanguage
+\def\addfontfeaturetoset #1{\ctxlua{fonts.withset("#1", 1)}}
+\def\subtractfontfeaturefromset #1{\ctxlua{fonts.withset("#1",-1)}}
+\def\addfontfeaturetofont #1{\ctxlua{fonts.withfnt("#1", 2)}}
+\def\subtractfontfeaturefromfont#1{\ctxlua{fonts.withfnt("#1",-2)}}
+
+\let\setff\setfontfeature
+\let\addfs\addfontfeaturetoset
+\let\subfs\subtractfontfeaturefromset
+\let\addff\addfontfeaturetofont
+\let\subff\subtractfontfeaturefromfont
%D The next auxilliary macro is an alternative to \type
%D {\fontname}.
@@ -3140,75 +2688,23 @@
\the\everybodyfont} % needed ?
%D \macros
-%D {os,frak, goth, cal}
-%D
-%D Old style numerals can be typeset with \type{\os} and look
-%D like {\os 1234567890} instead of the more common looking
-%D 1234567890.
+%D {os}
%D
-%D On behalf of {\frac Tobias Burnus}, we define some more of
-%D these. Later we will link these names to real file names.
+%D In good old \TEX, the old style numerals were often taken
+%D from the math fonts. No longer.
-% older
-%
-% \definefont [os] [OldStyle sa *]
-% \definefont [frak] [Fraktur sa *]
-% \definefont [goth] [Gothic sa *]
-% \definefont [cal] [Calligraphic sa *]
-% \definefont [bbd] [Blackboard sa *]
-%
-% newer
-
-\def\os {\mathortext{\fam\purefamily {oldstyle}}{\symbolicfont {OldStyle}}}
-\def\frak{\mathortext{\fam\purefamily {fraktur}}{\symbolicfont {Fraktur}}}
-\def\goth{\mathortext{\fam\purefamily {gothic}}{\symbolicfont {Gothic}}}
-\def\cal {\mathortext{\fam\purefamily{calligraphic}}{\symbolicfont{Calligraphic}}}
-\def\bbd {\mathortext{\fam\purefamily {blackboard}}{\symbolicfont {Blackboard}}}
+\definefontfeature
+ [just-os]
+ [mode=node,onum=yes]
-\definefontsynonym [OldStyle] [Serif]
-\definefontsynonym [Fraktur] [Serif]
-\definefontsynonym [Gothic] [Serif]
-\definefontsynonym [Calligraphic] [Serif]
-\definefontsynonym [Blackboard] [Serif]
+% \def\sc{\setfontfeature{smallcaps}}
+\def\os{\setfontfeature{just-os}}
-%D \macros
-%D {fraktur, gothic, calligraphic, blackboard}
-%D
-%D These macros assume that we use text fonts, and not math
-%D families.
+%D Code for swithcing to fraktur and script has also been
+%D changed. We now have an alphabet switcher.
\ifx\mathtext\undefined \let\mathtext\hbox \fi
-\def\fraktur #1{\mathortext\domathtext\donothing{\frak#1}}
-\def\gothic #1{\mathortext\domathtext\donothing{\goth#1}}
-\def\calligraphic#1{\mathortext\domathtext\donothing{\cal #1}}
-\def\blackboard #1{\mathortext\domathtext\donothing{\bbd#1}}
-
-%D Torture test:
-%D
-%D \starttyping
-%D \usetypescript[modern] [texnansi]
-%D \usetypescript[lucida] [texnansi]
-%D \usetypescript[palatino][texnansi]
-%D \usetypescript[times] [texnansi]
-%D \usetypescript[fourier] [ec]
-%D
-%D \startbuffer
-%D \section{\blackboard{T\high{\blackboard{T}}} \blackboard{E}\high{\blackboard{E}} \blackboard{X}\high{\blackboard{X}}}
-%D
-%D {\fontclass: 123 \os123 \cal TEX $\os 123$}
-%D
-%D $\blackboard{T}^{\blackboard{T}} \blackboard{E}^{\blackboard{E}} \blackboard{X}^{\blackboard{X}}$
-%D \blackboard{T}\high{\blackboard{T}} \blackboard{E}\high{\blackboard{E}} \blackboard{X}\high{\blackboard{X}}
-%D \stopbuffer
-%D
-%D {\setupbodyfont[lucida] \getbuffer}
-%D {\setupbodyfont[modern] \getbuffer}
-%D {\setupbodyfont[palatino] \getbuffer}
-%D {\setupbodyfont[times] \getbuffer}
-%D {\setupbodyfont[fourier] \getbuffer}
-%D \stoptyping
-
%D \macros
%D {definebodyfontswitch}
%D
@@ -3264,7 +2760,7 @@
%D in the main bodyfont and style of the document. Returning to
%D the global state can be done with the next macro:
-\let\mainfontclass\empty
+\let\globalfontstyle\c!rm
\def\fullrestoreglobalbodyfont
{\let\fontsize\defaultfontsize
@@ -3420,7 +2916,7 @@
%D \stoptyping
%D
%D We deliberately pass an argument. This enables us to
-%D assign converters that handle one agrument, like
+%D assign converters that handle one argument, like
%D \type{\cap}.
%D
%D By default the first specification is used to set the style,
@@ -3429,43 +2925,11 @@
%D \type{\noconvertfont}. In nested calls, we can restore the
%D conversion by saying \type{\redoconvertfont}.
-% \def\@@dodoconvertfont#1{\csname\@letter@ #1\endcsname}
-% \def\@@donoconvertfont#1{\csname\@noletter@#1\endcsname}
-%
-% \unexpanded\def\dodoconvertfont#1% #2% we need the protection
-% {\doifdefinedelse{\@letter@#1} % in testing
-% {\doifelsenothing{#1}\gobbleoneargument\@@dodoconvertfont}
-% {\doifdefinedelse{#1}\getvalue \firstofoneargument}%
-% {#1}} % {#2}}
-%
-% \let\doconvertfont\dodoconvertfont
-%
-% \def\noconvertfont#1% #2%
-% {\doifdefinedelse{\@noletter@#1}
-% {\doifelsenothing{#1}\gobbleoneargument\@@donoconvertfont}\gobbleoneargument
-% {#1}} % {#2}}
-
-% \def\@@dodoconvertfont{\csname\@letter@ \p!defined\endcsname}
-% \def\@@donoconvertfont{\csname\@noletter@\p!defined\endcsname}
-% \def\@@redoconvertfont{\csname \p!defined\endcsname}
-%
-% \unexpanded\def\dodoconvertfont#1% #2% we need the protection
-% {\edef\p!defined{#1}%
-% \ifcsname\@letter@\detokenize\@EA{\p!defined}\endcsname
-% \ifx\p!defined\empty\else\@EAEAEA\@@dodoconvertfont\fi
-% \else
-% \ifcsname\detokenize\@EA{\p!defined}\endcsname\@EAEAEA\@@redoconvertfont\else\@EAEAEA\p!defined\fi
-% \fi} % {#2}}
-%
-% \unexpanded\def\noconvertfont#1% #2%
-% {\edef\p!defined{#1}%
-% \ifcsname\@noletter@\detokenize\@EA{\p!defined}\endcsname
-% \ifx\p!defined\empty\else\@EAEAEA\@@donoconvertfont\fi
-% \fi} % {#2}}
+% subtle ... \expandafter is needed else problems with lookahead caps
-\def\@@dodoconvertfont{\csname\@letter@ \p!defined\endcsname\gobbleoneargument}
+\def\@@dodoconvertfont{\csname\@letter@ \p!defined\expandafter\endcsname\gobbleoneargument}
\def\@@donoconvertfont{\csname\@noletter@\p!defined\endcsname}
-\def\@@redoconvertfont{\csname \p!defined\endcsname\gobbleoneargument}
+\def\@@redoconvertfont{\csname \p!defined\expandafter\endcsname\gobbleoneargument}
% beware: p!defined can contain crap like \edef crap {...} and such
% so we need to pass #1 as well
@@ -3501,11 +2965,8 @@
%D Extras:
-\unexpanded\def\dontconvertfont
- {\let\doconvertfont\noconvertfont}
-
-\unexpanded\def\redoconvertfont
- {\let\doconvertfont\dodoconvertfont}
+\unexpanded\def\dontconvertfont{\let\doconvertfont\noconvertfont}
+\unexpanded\def\redoconvertfont{\let\doconvertfont\dodoconvertfont}
%D These commands are not grouped! Grouping is most probably
%D done by the calling macro's and would lead to unnecessary
@@ -3534,13 +2995,7 @@
%D or even better:
-% \def\doemphasistypeface#1#2%
-% {\doifelsevalue{\??ft\fontclass\normalizedbodyfontsize\c!em}\v!slanted#1%
-% {\doifelsevalue{\??ft\fontclass\normalizedbodyfontsize\c!em}\v!italic #2%
-% {\doifelsevalue{\??ft \normalizedbodyfontsize\c!em}\v!slanted#1%
-% {\doifvalue {\??ft \normalizedbodyfontsize\c!em}\v!italic #2}}}}
-
-\def\doemphasistypeface#1#2%
+\def\doemphasistypeface#1#2% slow
{\doifelsevalue{\??ft\fontclass\normalizedbodyfontsize\c!em}\v!slanted
{#1}%
{\doifelsevalue{\??ft\fontclass\normalizedbodyfontsize\c!em}\v!italic
@@ -3553,6 +3008,25 @@
{\getvalue{\??ft\normalizedbodyfontsize\c!em}}}}
{\getvalue{\??ft\fontclass\normalizedbodyfontsize\c!em}}}}}
+% \def\doemphasistypeface#1#2%
+% {\edef\emphasizedtypeface{\csname\??ft\fontclass\normalizedbodyfontsize\c!em\endcsname}%
+% \ifx\emphasizedtypeface\v!slanted
+% #1%
+% \else\ifx\emphasizedtypeface\v!italic
+% #2%
+% \else\ifx\emphasizedtypeface\v!empty
+% \edef\emphasizedtypeface{\csname\??ft\normalizedbodyfontsize\c!em\endcsname}%
+% \ifx\emphasizedtypeface\v!slanted
+% #1%
+% \else\ifx\emphasizedtypeface\v!italic
+% #2%
+% \else
+% \getvalue\emphasizedtypeface
+% \fi\fi
+% \else
+% \getvalue\emphasizedtypeface
+% \fi\fi\fi}
+
\def\emphasistypeface{\doemphasistypeface\sl\it}
\def\emphasisboldface{\doemphasistypeface\bs\bi}
@@ -3571,15 +3045,15 @@
\setfalse\emneeded
\fi
\setemphasisboldface % new
- \ifx\fontalternative\c!it % \ifnum\fam=\itfam
+ \ifx\fontalternative\c!it
\def\emphasistypeface{\it}\tf
- \else\ifx\fontalternative\c!sl % \ifnum\fam=\slfam
+ \else\ifx\fontalternative\c!sl
\def\emphasistypeface{\sl}\tf
- \else\ifx\fontalternative\c!bf % \ifnum\fam=\bffam
+ \else\ifx\fontalternative\c!bf
\emphasisboldface
- \else\ifx\fontalternative\c!bs % \ifnum\fam=\bsfam
+ \else\ifx\fontalternative\c!bs
\def\emphasisboldface{\bs}\bf
- \else\ifx\fontalternative\c!bi % \ifnum\fam=\bifam
+ \else\ifx\fontalternative\c!bi
\def\emphasisboldface{\bi}\bf
\else
\emphasistypeface
@@ -3605,9 +3079,9 @@
\unexpanded\def\bf
{%\relax
\let\bf\relax % new
- \ifx\fontalternative\c!it % \ifnum\fam=\itfam
+ \ifx\fontalternative\c!it
\bi
- \else\ifx\fontalternative\c!sl % \ifnum\fam=\slfam
+ \else\ifx\fontalternative\c!sl
\bs
\else
\normalbf
@@ -3619,24 +3093,35 @@
%D look for something that looks like a dash, in which case we
%D don't correct.
-\let\italiccorrection=\/
+\let\italiccorrection=\/ % tex primitive
\def\emphasiscorrection
{\ifhmode
\expandafter\emphasislook
\fi}
+% \def\emphasislook
+% {\begingroup
+% \beginrobusttest
+% \futurelet\next\emphasistest}
+
+% \def\emphasistest
+% {\normalifcat\noexpand\next,%
+% \endrobusttest\expandafter\doemphasiscorrection
+% \normalelse
+% \endrobusttest\expandafter\dododoemphasiscorrection
+% \normalfi}
+
\def\emphasislook
{\begingroup
- \beginrobusttest
\futurelet\next\emphasistest}
\def\emphasistest
- {\normalifcat\noexpand\next,%
- \endrobusttest\expandafter\doemphasiscorrection
- \normalelse
- \endrobusttest\expandafter\dododoemphasiscorrection
- \normalfi}
+ {\ifcat\noexpand\next,% still ok?
+ \expandafter\doemphasiscorrection
+ \else
+ \expandafter\dododoemphasiscorrection
+ \fi}
\def\doemphasiscorrection
{\futurelet\next\dodoemphasiscorrection}
@@ -3792,11 +3277,6 @@
%D \stopbuffer
%D
%D \typebuffer
-%D
-%D Below the table the name, encoding, mapping and handling are
-%D shown. Special characters like the \type {\skewchar} and
-%D \type {\hyphenchar} als marked.
-%D
%D \getbuffer
% to be internationalized
@@ -3954,49 +3434,6 @@
%D The shape as well as the size is adapted to the current
%D environment.
-%D Fonts can only be used when loaded. In \CONTEXT\ we
-%D postpone the loading of fonts, even when we load \PLAIN.
-%D This means that we have to redefine one of the \PLAIN\
-%D macros. Let's tell that to the user first:
-
-\writestatus{loading}{Postponed Plain TeX Font Definitions}
-
-%D \macros
-%D {bordermatrix}
-%D
-%D In \PLAIN\ \TEX\ the width of a parenthesis is stored in
-%D the \DIMENSION\ \type{\p@renwd}. This value is derived from
-%D the width of \type{\tenrm B}, so let's take care of it now:
-
-\let\normalbordermatrix=\bordermatrix
-
-\def\bordermatrix%
- {\bgroup
- \setbox0\hbox{\getvalue{\textface\c!mm\c!ex}B}%
- \global\p@renwd\wd0\relax
- \egroup
- \normalbordermatrix}
-
-%D Because we want to be as \PLAIN\ compatible as possible, we
-%D make most of \PLAIN's font mechanisme available to the
-%D \CONTEXT\ user.
-
-\def\setplainfonts#1#2%
- {\setvalue {ten#1}{\getvalue{\!!tenpoint #2}}%
- \setvalue{seven#1}{\getvalue{\!!sevenpoint#2}}%
- \setvalue {five#1}{\getvalue{\!!fivepoint #2}}}
-
-\setplainfonts {\c!rm} {\c!rm\c!tf}
-\setplainfonts {\c!bf} {\c!rm\c!bf}
-\setplainfonts {\c!sl} {\c!rm\c!sl}
-\setplainfonts {\c!it} {\c!rm\c!it}
-\setplainfonts {\c!tt} {\c!rm\c!tt}
-\setplainfonts {\c!sy} {\c!mm\c!sy}
-\setplainfonts {\c!ex} {\c!mm\c!ex}
-\setplainfonts {\c!i} {\c!mm\c!mi}
-
-\let\setplainfonts=\undefined
-
%D \macros
%D {ss, SS, sz}
%D
@@ -4008,81 +3445,11 @@
\ifx\undefined\SS \let\SS=\ss \fi
\ifx\undefined\sz \let\sz=\ss \fi
-%D \macros
-%D {xi}
-%D
-%D We are going to redefine \type{\xi}, but fortunately this
-%D is a math mode character, so we can just say:
-
-\let\normalxi=\xi
-
-%D \macros
-%D {smashaccent}
-%D
-%D When we let \TEX\ put an accent on top of a character, such
-%D composed characters can get more height that height of a
-%D standard \type{\strut}. The next macro takes care of such
-%D unwanted compositions.
-%D
-%D We need to reach over the number that specifies the accent,
-%D and in doing so we use \type{\scratchcounter} as a placeholder
-%D because it accepts 8 bit numbers in octal, decimal or
-%D hexadecimal format. Next we set the height of the accented
-%D character to the natural height of the character.
-
-\unexpanded\def\smashaccent#1%
- {\dontleavehmode
- \bgroup
- \setbox\scratchbox\hbox{#1}%
- \ifdim\ht\scratchbox>\strutheight\relax\ht\scratchbox\strutheight\fi
- \ifdim\dp\scratchbox>\strutdepth \relax\dp\scratchbox\strutdepth \fi
- \box\scratchbox
- \egroup}
-
-%D For instance we can say:
-%D
-%D \starttyping
-%D \smashaccent{\"Uberhaupt}
-%D \stoptyping
-%D
-%D But normally one will use it as a prefix in definitions.
-%D The difference is in the height:
-%D
-%D \leavevmode\ruledhbox
-%D {\ruledhbox{\smashaccent{\"U}berhaupt}\quad
-%D oder\quad
-%D \ruledhbox{\"Uberhaupt}}
-
-%D \macros
-%D {moveaccent}
-%D
-%D Exact positioning of accents can be realized by saying:
-%D
-%D \starttyping
-%D \moveaccent{-.1ex}{\"u}berhaupt
-%D \stoptyping
-%D
-%D Again, this one will mostly used as a prefix in definitions.
-%D Here the difference is in the position:
-%D
-%D \leavevmode\ruledhbox
-%D {\ruledhbox{\moveaccent{-.1ex}{\"}Uberhaupt}\quad
-%D oder\quad
-%D \ruledhbox{\"Uberhaupt}}
-
-\unexpanded\def\moveaccent#1#2%
- {\smashaccent
- {\dimen0\exheight
- \dimen2\dimen0
- \advance\dimen2 -#1%
- \exheight\dimen2
- #2\relax
- \exheight\dimen0}}
-
-%D Personally I think that using \TEX\ is complicated by the
-%D way fonts are handled. Apart from the many encodings, we
-%D also deal with different naming schemes. Confronted with
-%D this problem, I decided to change the definitions into:
+%D Personally I think that using \TEX\ macro packages is
+%D complicated by the way fonts are handled. Apart from the
+%D many encodings, we also deal with different naming schemes.
+%D Confronted with this problem, I decided to change the
+%D definitions into:
%D
%D \starttyping
%D \definebodyfont [12pt] [rm] [tf=Times-Roman at 12pt]
@@ -4244,22 +3611,31 @@
\definebodyfontswitch [fivepoint] [\!!fivepoint]
\definebodyfontswitch [fourpoint] [\!!fourpoint]
-\definebodyfontswitch [xii] [\!!twelvepoint]
-\definebodyfontswitch [xi] [\!!elevenpoint]
-\definebodyfontswitch [x] [\!!tenpoint]
-\definebodyfontswitch [ix] [\!!ninepoint]
-\definebodyfontswitch [viii] [\!!eightpoint]
-\definebodyfontswitch [vii] [\!!sevenpoint]
-\definebodyfontswitch [vi] [\!!sixpoint]
+% \definebodyfontswitch [xii] [\!!twelvepoint]
+% \definebodyfontswitch [xi] [\!!elevenpoint]
+% \definebodyfontswitch [x] [\!!tenpoint]
+% \definebodyfontswitch [ix] [\!!ninepoint]
+% \definebodyfontswitch [viii] [\!!eightpoint]
+% \definebodyfontswitch [vii] [\!!sevenpoint]
+% \definebodyfontswitch [vi] [\!!sixpoint]
%D So far.
+\definefontstyle [\c!mm] [\c!mm]
\definefontstyle [\c!rm,\v!roman,\v!serif,\v!regular] [\c!rm]
\definefontstyle [\c!ss,\v!sansserif,\v!sans,\v!support] [\c!ss]
\definefontstyle [\c!tt,\v!teletype,\v!type,\v!mono] [\c!tt]
\definefontstyle [\c!hw,\v!handwritten] [\c!hw]
\definefontstyle [\c!cg,\v!calligraphic] [\c!cg]
+\definefontalternative[\c!tf]
+\definefontalternative[\c!bf]
+\definefontalternative[\c!it]
+\definefontalternative[\c!sl]
+\definefontalternative[\c!bs]
+\definefontalternative[\c!bi]
+\definefontalternative[\c!sc]
+
\definefontsize[\c!a] \definefontsize[\c!b]
\definefontsize[\c!c] \definefontsize[\c!d]
@@ -4294,42 +3670,12 @@
\definealternativestyle [\v!smallcaps] [\sc] [\sc]
\definealternativestyle [\v!WORD] [\WORD] [\WORD]
-%D \macros
-%D {...math}
-%D
-%D New or old?
-
-% tzt proper \define...
-%
-% watch out: \synchronizesymb resets the family so we need a second
-% \mf (or maybe \mr): messy and to be sorted out
-
-\def\tfmath{\tf\mf\synchronizesymb\mf}
-\def\bfmath{\bf\mf\synchronizesymb\mf}
-\def\slmath{\sl\mf\synchronizesymb\mf}
-\def\itmath{\it\mf\synchronizesymb\mf}
-\def\bsmath{\bs\mf\synchronizesymb\mf}
-\def\bimath{\bi\mf\synchronizesymb\mf}
-\def\scmath{\sc\mf\synchronizesymb\mf}
-\def\nnmath{\nn\mf\synchronizesymb\mf}
-
-\def\textmath {\synchronizesymb}
-
%D \macros
%D {fontstylesuffix}
%D
%D The next macro is used to map non latin fontnames on
%D fonts. See \type {font-uni} for an example of its use.
-%\def\fontstylesuffix%
-% {\ifnum\fam=\tffam \s!Regular \else
-% \ifnum\fam=\bffam \s!Bold \else
-% \ifnum\fam=\slfam \s!Slanted \else
-% \ifnum\fam=\itfam \s!Italic \else
-% \ifnum\fam=\bsfam \s!BoldSlanted \else
-% \ifnum\fam=\bifam \s!BoldItalic \else
-% \s!Regular \fi\fi\fi\fi\fi\fi}%
-
\def\fontstylesuffix% why the \s!Regular ? see \getglyph
{\ifx\fontalternative\c!tf \s!Regular \else
\ifx\fontalternative\c!bf \s!Bold \else
@@ -4340,10 +3686,6 @@
\ifx\fontalternative\c!sc \s!Caps \else
\s!Regular \fi\fi\fi\fi\fi\fi\fi}%
-%D We still have to take care of \type{\xi}, so:
-
-\def\xi{\ifmmode\normalxi\else\elevenpoint\fi}
-
%D \macros
%D {definefontvariant,fontvariant,variant}
%D
@@ -4383,7 +3725,7 @@
\unexpanded\def\variant[#1]% slow
{\dosetscaledfont
- \expanded{\definedfont[\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1} at \the\dimexpr\scaledfontsize\relax]}%
+ \normalexpanded{\noexpand\definedfont[\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1} at \the\dimexpr\scaledfontsize\relax]}%
\ignoreimplicitspaces}
\ifx\Var\undefined \let\Var\variant \fi
@@ -4393,262 +3735,113 @@
%D bodyfont. Sans serif and teletype are also available and
%D can be called for by \type{\ss} and \type{\tt}.
-\setupbodyfont [unk, rm]
+% \setupbodyfont [unk, rm]
+% \setupbodyfont [rm]
%D Also needed is:
\definefont[tinyfont][Mono at 1ex]
-%D \macros
-%D {doiffontpresentelse}
-%D
-%D \starttyping
-%D \doiffontpresentelse{texnansi-lmr10}{YES}{NO}
-%D \doiffontpresentelse{adam-lindsay-modern-serif}{YES}{NO}
-%D \stoptyping
+% \tracinglostchars=1
-\def\doiffontpresentelse#1{\ctxlua{commands.doifelse(fonts.names.exists("#1"))}}
+% this needs some interfacing
+%
+% \setupfonts[check=...]
-%D OPTIMIZATIONS
+\def\checkcharactersinfont {\ctxlua{fonts.checkers.enabled=true}}
+\def\removemissingcharacters{\ctxlua{fonts.checkers.enabled=true fonts.checkers.delete=true}}
-\def\definefontsynonym[#1]#2[#3]%
- {\edef\@@fontname{#1}%
- \edef\@@fontfile{#3}%
- \@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile % maybe just #1 #3, saves expansion
- \doifnextcharelse[\dodefinefontsynonym\nodefinefontsynonym}
+%D New commands (not yet interfaced):
-\def\dodefinefontsynonym[#1]%
- {\let\@@ff@@features \undefined
- \let\@@ff@@fallbacks\undefined
- \let\@@ff@@skewchar \undefined
- \expandafter\dogetfontparameter#1,]=,}
+\def\style[#1]% for inline usage, like \color
+ {\groupedcommand{\ifcsname#1\endcsname\csname#1\endcsname\else\definedfont[#1]\fi}{}}
-\def\dogetfontparameter#1=#2,%
- {\if]#1%
- \dododefinefontsynonym
- \else
- \expandafter\def\csname @@ff@@#1\endcsname{#2}%
- \expandafter\dogetfontparameter
- \fi}
+\def\startstyle[#1]%
+ {\begingroup
+ \ifcsname#1\endcsname\csname#1\endcsname\else\definedfont[#1]\fi}
-\def\nodefinefontsynonym
- {\ifx\fontclass\empty
- \@EA\let\csname\??ff\@@fontname\s!features \endcsname\undefined
- \@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\undefined
- \@EA\let\csname\??ff\@@fontfile\s!skewchar \endcsname\undefined
- \else
- \global\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\undefined
- \global\@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\undefined
- \global\@EA\let\csname\??ff\fontclass\@@fontfile\s!skewchar \endcsname\undefined
- \fi}
+\def\stopstyle
+ {\endgroup}
-\def\dododefinefontsynonym
- {\ifx\fontclass\empty
- \@EA\let\csname\??ff\@@fontname\s!features \endcsname\@@ff@@features
- \@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks
- \@EA\let\csname\??ff\@@fontfile\s!skewchar \endcsname\@@ff@@skewchar
- \else
- \global\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\@@ff@@features
- \global\@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks
- \global\@EA\let\csname\??ff\fontclass\@@fontfile\s!skewchar \endcsname\@@ff@@skewchar
- \fi}
+%D Still experimental (might even go away).
-\def\truefontname#1%
- {\ifcsname\??ff\fontclass#1\endcsname
- \@EA\truefontname\csname\??ff\fontclass#1\endcsname
- \else\ifcsname\??ff#1\endcsname
- \@EA\truefontname\csname\??ff#1\endcsname
- \else
- #1%
- \fi\fi}
+% \definestylecollection[mine]
-\def\updatefontparameters
- {\edef\@@fontfeatures {\@@thefeatures \somefontname}%
- \edef\@@fontfallbacks{\@@thefallbacks\somefontname}%
- \edef\@@fontskewchar {\@@theskewchar \somefontname}}
-
-\def\@@thefeatures#1%
- {\ifcsname\??ff\fontclass#1\s!features\endcsname \csname\??ff\fontclass#1\s!features\endcsname\else % class + symbolic_name
- \ifcsname\??ff #1\s!features\endcsname \csname\??ff #1\s!features\endcsname\else % symbolic_name
- \ifcsname\??ff\fontclass#1\endcsname \@EA\@@thefeatures\csname\??ff\fontclass#1\endcsname \else % fontclass + parent_name
- \ifcsname\??ff #1\endcsname \@EA\@@thefeatures\csname\??ff #1\endcsname \fi\fi\fi\fi} % parent_name
-
-\def\@@thefallbacks#1%
- {\ifcsname\??ff\fontclass#1\s!fallbacks\endcsname \csname\??ff\fontclass#1\s!fallbacks\endcsname\else % class + symbolic_name
- \ifcsname\??ff #1\s!fallbacks\endcsname \csname\??ff #1\s!fallbacks\endcsname\else % symbolic_name
- \ifcsname\??ff\fontclass#1\endcsname \@EA\@@thefallbacks\csname\??ff\fontclass#1\endcsname \else % fontclass + parent_name
- \ifcsname\??ff #1\endcsname \@EA\@@thefallbacks\csname\??ff #1\endcsname \fi\fi\fi\fi} % parent_name
-
-\def\@@theskewchar#1% skew chars will be done differently (just a hash with registered skewchars)
- {\ifcsname\??ff\fontclass#1\s!skewchar\endcsname \csname\??ff\fontclass#1\s!skewchar\endcsname\else % class + symbolic_name
- \ifcsname\??ff #1\s!skewchar\endcsname \csname\??ff #1\s!skewchar\endcsname\else % symbolic_name
- \ifcsname\??ff\fontclass#1\endcsname \@EA\@@theskewchar\csname\??ff\fontclass#1\endcsname \else % fontclass + parent_name
- \ifcsname\??ff #1\endcsname \@EA\@@theskewchar\csname\??ff #1\endcsname \fi\fi\fi\fi} % parent_name
-
-% more efficient ?
+% \definestyleinstance[mine][default][sorry]
+% \definestyleinstance[mine][tt][bs][ttbs:\rm\sl]
+% \definestyleinstance[mine][tt][bf][ttbf:\rm\sl]
+% \definestyleinstance[mine][bf][\sl]
+% \definestyleinstance[mine][sl][\tt]
-\def\definefontsynonym[#1]#2[#3]%
- {\edef\@@fontname{#1}%
- \edef\@@fontfile{#3}%
- \ifx\fontclass\empty
- \expandafter\dodefinefontsynonymnop
- \else
- \expandafter\dodefinefontsynonymyes
- \fi}
+% {\bf test \mine test \sl test \mine test \bs oeps \mine oeps {\tt test \mine \bf test}}
-\def\dodefinefontsynonymyes
- {\@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile % maybe just #1 #3, saves expansion
- \doifnextcharelse[\dododefinefontsynonymyes\nonodefinefontsynonymyes}
-\def\dodefinefontsynonymnop
- {\@EA\let\csname\??ff\@@fontname\endcsname\@@fontfile % maybe just #1 #3, saves expansion
- \doifnextcharelse[\dododefinefontsynonymnop\nonodefinefontsynonymnop}
+\definesystemvariable{sx}
-\def\dododefinefontsynonymyes[#1]%
- {\let\@@ff@@features \undefined
- \let\@@ff@@fallbacks\undefined
- \let\@@ff@@skewchar \undefined
- \expandafter\dogetfontparameteryes#1,]=,}
-\def\dododefinefontsynonymnop[#1]%
- {\let\@@ff@@features \undefined
- \let\@@ff@@fallbacks\undefined
- \let\@@ff@@skewchar \undefined
- \expandafter\dogetfontparameternop#1,]=,}
+\def\definestylecollection
+ {\dosingleargument\dodefinestylecollection}
-\def\dogetfontparameteryes#1=#2,%
- {\if]#1%
- \dodododefinefontsynonymyes
- \else
- \expandafter\def\csname @@ff@@#1\endcsname{#2}%
- \expandafter\dogetfontparameteryes
- \fi}
-\def\dogetfontparameternop#1=#2,%
- {\if]#1%
- \dodododefinefontsynonymnop
- \else
- \expandafter\def\csname @@ff@@#1\endcsname{#2}%
- \expandafter\dogetfontparameternop
+\def\dodefinestylecollection[#1]%
+ {\iffirstargument
+ \unexpanded\setvalue{#1}{\styleinstance[#1]}%
+ \def\docommand##1%
+ {\def\dodocommand####1{\letbeundefined{\??sx##1:####1:\commalistelement}}%
+ \processcommacommand[\fontalternativelist,\s!default]\dodocommand}%
+ \processcommacommand[\fontstylelist,\s!default]\docommand
\fi}
-\def\nonodefinefontsynonymyes
- {\global\@EA\let\csname\??ff\@@fontname\s!features \endcsname\undefined
- \global\@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\undefined
- \global\@EA\let\csname\??ff\@@fontfile\s!skewchar \endcsname\undefined}
-\def\nonodefinefontsynonymnop
- {\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\undefined
- \@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\undefined
- \@EA\let\csname\??ff\fontclass\@@fontfile\s!skewchar \endcsname\undefined}
-
-\def\dodododefinefontsynonymyes
- {\global\@EA\let\csname\??ff\@@fontname\s!features \endcsname\@@ff@@features
- \global\@EA\let\csname\??ff\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks
- \global\@EA\let\csname\??ff\@@fontfile\s!skewchar \endcsname\@@ff@@skewchar}
-\def\dodododefinefontsynonymnop
- {\@EA\let\csname\??ff\fontclass\@@fontname\s!features \endcsname\@@ff@@features
- \@EA\let\csname\??ff\fontclass\@@fontname\s!fallbacks\endcsname\@@ff@@fallbacks
- \@EA\let\csname\??ff\fontclass\@@fontfile\s!skewchar \endcsname\@@ff@@skewchar}
-
-% resolve
-
-\def\@@thefeaturesyes#1%
- {\ifcsname\??ff\fontclass#1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff\fontclass#1\s!features \endcsname\else
- \ifcsname\??ff #1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff #1\s!features \endcsname\else
- \ifcsname\??ff\fontclass #1\endcsname\@EA \@@thefeaturesyes \csname\??ff\fontclass #1\endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@thefeaturesyes \csname\??ff #1\endcsname\else
- \let \@@fontfeatures \empty \fi\fi\fi\fi}
-\def\@@thefallbacksyes#1%
- {\ifcsname\??ff\fontclass#1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff\fontclass#1\s!fallbacks\endcsname\else
- \ifcsname\??ff #1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff #1\s!fallbacks\endcsname\else
- \ifcsname\??ff\fontclass #1\endcsname\@EA \@@thefallbacksyes\csname\??ff\fontclass #1\endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@thefallbacksyes\csname\??ff #1\endcsname\else
- \let \@@fontfallbacks \empty \fi\fi\fi\fi}
-\def\@@theskewcharyes#1%
- {\ifcsname\??ff\fontclass#1\s!skewchar \endcsname\@EA\let\@EA\@@fontskewchar \csname\??ff\fontclass#1\s!skewchar \endcsname\else
- \ifcsname\??ff #1\s!skewchar \endcsname\@EA\let\@EA\@@fontskewchar \csname\??ff #1\s!skewchar \endcsname\else
- \ifcsname\??ff\fontclass #1\endcsname\@EA \@@theskewcharyes \csname\??ff\fontclass #1\endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@theskewcharyes \csname\??ff #1\endcsname\else
- \let \@@fontskewchar \empty \fi\fi\fi\fi}
-
-\def\@@thefeaturesnop#1%
- {\ifcsname\??ff#1\s!features \endcsname\@EA\let\@EA\@@fontfeatures \csname\??ff#1\s!features \endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@thefeaturesnop \csname\??ff #1\endcsname\else
- \let \@@fontfeatures \empty \fi\fi}
-\def\@@thefallbacksnop#1%
- {\ifcsname\??ff#1\s!fallbacks\endcsname\@EA\let\@EA\@@fontfallbacks \csname\??ff#1\s!fallbacks\endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@thefallbacksnop\csname\??ff #1\endcsname\else
- \let \@@fontfallbacks \empty \fi\fi}
-\def\@@theskewcharnop#1%
- {\ifcsname\??ff#1\s!skewchar \endcsname\@EA\let\@EA\@@fontskewchar \csname\??ff#1\s!skewchar \endcsname\else
- \ifcsname\??ff #1\endcsname\@EA \@@theskewcharnop \csname\??ff #1\endcsname\else
- \let \@@fontskewchar \empty \fi\fi}
+\def\definestyleinstance
+ {\doquadrupleargument\dodefinestyleinstance}
-\def\updatefontparametersyes
- {\@@thefeaturesyes \somefontname
- \@@thefallbacksyes\somefontname
- \@@theskewcharyes \somefontname}
-\def\updatefontparametersnop
- {\@@thefeaturesnop \somefontname
- \@@thefallbacksnop\somefontname
- \@@theskewcharnop \somefontname}
-
-\def\updatefontparameters
- {\ifx\fontclass\empty\updatefontparametersnop\else\updatefontparametersyes\fi}
+\def\dodefinestyleinstance[#1][#2][#3][#4]% [name] [rm|ss|tt|..] [sl|bf|...] [whatever]
+ {\iffirstargument
+ \doifundefined{#1}{\definestylecollection[#1]}%
+ \fi
+ \iffourthargument
+ \setvalue{\??sx#1:#2:#3}{#4}%
+ \else\ifthirdargument
+ \setvalue{\??sx#1::#2}{#3}%
+ \else\ifsecondargument
+ \letvalue{\??sx#1::#2}\empty
+ \fi\fi\fi}
+
+\unexpanded\def\styleinstance[#1]% will be faster
+ {%\begingroup\normalexpanded{\noexpand\infofont[#1:\fontstyle:\fontalternative]}\endgroup
+ \executeifdefined{\??sx#1:\fontstyle:\fontalternative}%
+ {\executeifdefined{\??sx#1:\fontstyle:\s!default}%
+ {\executeifdefined{\??sx#1::\fontalternative}
+ {\getvalue {\??sx#1::\s!default}}}}}
+
+% \unexpanded\def\styleinstance[#1]%
+% {\csname\??sx#1%
+% \ifcsname:\fontstyle:\fontalternative\endcsname
+% :\fontstyle:\fontalternative
+% \else\ifcsname:\fontstyle:\s!default\endcsname
+% :\fontstyle:\s!default
+% \else\ifcsname::\fontalternative\endcsname
+% ::\fontalternative
+% \else\ifcsname::\s!default\endcsname
+% ::\s!default
+% \else
+% % nothing, \relax
+% \fi\fi\fi\fi
+% \endcsname}
\protect \endinput
-% bewaren
-%
-% \def\truefontdata#1#2%
-% {\ifcsname\??ff\fontclass#1#2\endcsname
-% % raw(Regular) raw(key)
-% \csname\??ff\fontclass#1#2\endcsname
-% \else\ifcsname\??ff\fontclass#1\endcsname
-% % exp(palatino Regular) raw(key)
-% \expandafter\truefontdata\csname\??ff\fontclass#1\endcsname#2%
-% \else\ifcsname\??ff#1\endcsname
-% % exp(Regular) raw(key)
-% \expandafter\truefontdata\csname\??ff#1\endcsname#2%
-% \else\ifcsname\??ff#2\endcsname
-% % raw(key)
-% \csname\??ff#2\endcsname
-% \fi\fi\fi\fi}
-
-% test file
-%
-% \starttypescript[serif][mine-1]
-% \definefontsynonym[Serif] [TeXGyrePagella-Regular]
-% \definefontsynonym[TeXGyrePagella-Regular][file:texgyrepagella-regular]
-% \stoptypescript
-%
-% \starttypescript[serif][mine-2]
-% \definefontsynonym[Serif] [TeXGyrePagella-Regular] [features=default]
-% \definefontsynonym[TeXGyrePagella-Regular][file:texgyrepagella-regular] [features=oldstyle]
-% \stoptypescript
-%
-% \starttypescript[serif][mine-3]
-% \definefontsynonym[Serif] [TeXGyrePagella-Regular] [features=oldstyle]
-% \definefontsynonym[TeXGyrePagella-Regular][file:texgyrepagella-regular] [features=default]
-% \stoptypescript
-%
-% \starttypescript[serif][mine-4]
-% \definefontsynonym[Serif] [TeXGyrePagella-Regular] [features=default]
-% \definefontsynonym[TeXGyrePagella-Regular][file:texgyrepagella-regular] [features=default]
-% \stoptypescript
-%
-% \starttypescript[serif][mine-5]
-% \definefontsynonym[Serif] [TeXGyrePagella-Regular] [features=oldstyle]
-% \definefontsynonym[TeXGyrePagella-Regular][file:texgyrepagella-regular] [features=oldstyle]
-% \stoptypescript
-%
-% \starttext
-% \dorecurse {5} {
-% \expanded{\definetypeface[mine-\recurselevel][rm][serif][mine-\recurselevel][default]}
-% \expanded{\setupbodyfont [mine-\recurselevel] mine-\recurselevel: text 1234567890 done}
-% \par
-% }
-% \blank
-% \dorecurse {5} {
-% \expanded{\definetypeface[more-\recurselevel][rm][serif][mine-\recurselevel][default][features=oldstyle]}
-% \expanded{\setupbodyfont [more-\recurselevel] mine-\recurselevel: text 1234567890 done}
-% \par
-% }
-% \stoptext
+% \startluacode
+% function commands.doifelsecurrentfonthasfeature(name)
+% local f = fonts.ids[font.current()]
+% f = f and f.shared
+% f = f and f.otfdata
+% f = f and f.luatex
+% f = f and f.features
+% commands.doifelse(f and (f.gpos[name] or f.gsub[name]))
+% end
+% \stopluacode
+
+% \def\doifelsecurrentfonthasfeature#1%
+% {\ctxlua{commands.doifelsecurrentfonthasfeature("#1")}}
+
+% \doifelsecurrentfonthasfeature{smcp}{YES}{NO}
+% \doifelsecurrentfonthasfeature{crap}{YES}{NO}
+% \doifelsecurrentfonthasfeature{kern}{YES}{NO}
diff --git a/tex/context/base/font-jap.tex b/tex/context/base/font-jap.tex
index 6bb813ccc..42480df43 100644
--- a/tex/context/base/font-jap.tex
+++ b/tex/context/base/font-jap.tex
@@ -15,7 +15,7 @@
\ifx\handlejapaneseunicodeglyph\undefined \else \endinput \fi
\ifx\handlechineseunicodeglyph \undefined \input font-chi.tex \fi
-\writestatus{loading}{Context Font Macros / Japanese}
+\writestatus{loading}{ConTeXt Font Macros / Japanese}
\unprotect
diff --git a/tex/context/base/font-log.lua b/tex/context/base/font-log.lua
new file mode 100644
index 000000000..499bd4304
--- /dev/null
+++ b/tex/context/base/font-log.lua
@@ -0,0 +1,53 @@
+if not modules then modules = { } end modules ['font-log'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local next, format, lower, concat = next, string.format, string.lower, table.concat
+
+local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end)
+
+fonts.logger = fonts.logger or { }
+
+--[[ldx--
+
The following functions are used for reporting about the fonts
+used. The message itself is not that useful in regular runs but since
+we now have several readers it may be handy to know what reader is
+used for which font.
+--ldx]]--
+
+function fonts.logger.save(tfmtable,source,specification) -- save file name in spec here ! ! ! ! ! !
+ if tfmtable and specification and specification.specification then
+ local name = lower(specification.name)
+ if trace_defining and not fonts.used[name] then
+ logs.report("define font","registering %s as %s",file.basename(specification.name),source)
+ end
+ specification.source = source
+ fonts.loaded[lower(specification.specification)] = specification
+ fonts.used[name] = source
+ end
+end
+
+function fonts.logger.report()
+ local t = { }
+ for name, used in table.sortedpairs(fonts.used) do
+ t[#t+1] = file.basename(name) .. ":" .. used
+ end
+ return t
+end
+
+function fonts.logger.format(name)
+ return fonts.used[name] or "unknown"
+end
+
+statistics.register("loaded fonts", function()
+ if next(fonts.used) then
+ local t = fonts.logger.report(separator)
+ return (#t > 0 and format("%s files: %s",#t,concat(t,separator or " "))) or "none"
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/font-map.lua b/tex/context/base/font-map.lua
index 64ff268fb..35cfaf32f 100644
--- a/tex/context/base/font-map.lua
+++ b/tex/context/base/font-map.lua
@@ -6,6 +6,10 @@ if not modules then modules = { } end modules ['font-map'] = {
license = "see context related readme files"
}
+local match, format, find = string.match, string.format, string.find
+
+local ctxcatcodes = tex.ctxcatcodes
+
--[[ldx--
Eventually this code will disappear because map files are kind
of obsolete. Some code may move to runtime or auxiliary modules.
@@ -29,21 +33,21 @@ function fonts.map.line.pdftex(e) -- so far no combination of slant and stretch
local fullname = e.fullname or ""
if e.slant and e.slant ~= 0 then
if e.encoding then
- return fonts.map.line.pdfmapline("=",string.format('%s %s "%g SlantFont" <%s <%s',e.name,fullname,e.slant,e.encoding,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s "%g SlantFont" <%s <%s',e.name,fullname,e.slant,e.encoding,e.fontfile))
else
- return fonts.map.line.pdfmapline("=",string.format('%s %s "%g SlantFont" <%s',e.name,fullname,e.slant,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s "%g SlantFont" <%s',e.name,fullname,e.slant,e.fontfile))
end
elseif e.stretch and e.stretch ~= 1 and e.stretch ~= 0 then
if e.encoding then
- return fonts.map.line.pdfmapline("=",string.format('%s %s "%g ExtendFont" <%s <%s',e.name,fullname,e.stretch,e.encoding,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s "%g ExtendFont" <%s <%s',e.name,fullname,e.stretch,e.encoding,e.fontfile))
else
- return fonts.map.line.pdfmapline("=",string.format('%s %s "%g ExtendFont" <%s',e.name,fullname,e.stretch,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s "%g ExtendFont" <%s',e.name,fullname,e.stretch,e.fontfile))
end
else
if e.encoding then
- return fonts.map.line.pdfmapline("=",string.format('%s %s <%s <%s',e.name,fullname,e.encoding,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s <%s <%s',e.name,fullname,e.encoding,e.fontfile))
else
- return fonts.map.line.pdfmapline("=",string.format('%s %s <%s',e.name,fullname,e.fontfile))
+ return fonts.map.line.pdfmapline("=",format('%s %s <%s',e.name,fullname,e.fontfile))
end
end
else
@@ -54,7 +58,7 @@ end
function fonts.map.flush(backend) -- will also erase the accumulated data
local flushline = fonts.map.line[backend or "pdftex"] or fonts.map.line.pdftex
for _, e in pairs(fonts.map.data) do
- tex.sprint(tex.ctxcatcodes,flushline(e))
+ tex.sprint(ctxcatcodes,flushline(e))
end
fonts.map.data = { }
end
@@ -76,27 +80,27 @@ function fonts.map.load_file(filename, entries, encodings)
if f then
local data = f:read("*a")
if data then
- for line in data:gmatch("(.-)[\n\t]") do
- if line:find("^[%#%%%s]") then
+ for line in gmatch(data,"(.-)[\n\t]") do
+ if find(line,"^[%#%%%s]") then
-- print(line)
else
local stretch, slant, name, fullname, fontfile, encoding
line = line:gsub('"(.+)"', function(s)
- stretch = s:find('"([^"]+) ExtendFont"')
- slant = s:find('"([^"]+) SlantFont"')
+ stretch = find(s,'"([^"]+) ExtendFont"')
+ slant = find(s,'"([^"]+) SlantFont"')
return ""
end)
if not name then
-- name fullname encoding fontfile
- name, fullname, encoding, fontfile = line:match("^(%S+)%s+(%S*)[%s<]+(%S*)[%s<]+(%S*)%s*$")
+ name, fullname, encoding, fontfile = match(line,"^(%S+)%s+(%S*)[%s<]+(%S*)[%s<]+(%S*)%s*$")
end
if not name then
-- name fullname (flag) fontfile encoding
- name, fullname, fontfile, encoding = line:match("^(%S+)%s+(%S*)[%d%s<]+(%S*)[%s<]+(%S*)%s*$")
+ name, fullname, fontfile, encoding = match(line,"^(%S+)%s+(%S*)[%d%s<]+(%S*)[%s<]+(%S*)%s*$")
end
if not name then
-- name fontfile
- name, fontfile = line:match("^(%S+)%s+[%d%s<]+(%S*)%s*$")
+ name, fontfile = match(line,"^(%S+)%s+[%d%s<]+(%S*)%s*$")
end
if name then
if encoding == "" then encoding = nil end
diff --git a/tex/context/base/font-mis.lua b/tex/context/base/font-mis.lua
new file mode 100644
index 000000000..520f9e7a6
--- /dev/null
+++ b/tex/context/base/font-mis.lua
@@ -0,0 +1,91 @@
+if not modules then modules = { } end modules ['font-mis'] = {
+ version = 1.001,
+ comment = "companion to luatex-fonts.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local next, pairs, ipairs = next, pairs, ipairs
+local lower, strip = string.lower, string.strip
+
+fonts.otf = fonts.otf or { }
+
+fonts.otf.version = fonts.otf.version or 2.626
+fonts.otf.pack = true
+fonts.otf.cache = containers.define("fonts", "otf", fonts.otf.version, true)
+
+function fonts.otf.loadcached(filename,format,sub)
+ -- no recache when version mismatch
+ local name = file.basename(file.removesuffix(filename))
+ if sub == "" then sub = false end
+ local hash = name
+ if sub then
+ hash = hash .. "-" .. sub
+ end
+ hash = containers.cleanname(hash)
+ local data = containers.read(fonts.otf.cache(), hash)
+ if data and not data.verbose then
+ fonts.otf.enhancers.unpack(data)
+ return data
+ else
+ return nil
+ end
+end
+
+function fonts.get_features(name,t,script,language)
+ local t = lower(t or (name and file.extname(name)) or "")
+ if t == "otf" or t == "ttf" or t == "ttc" then
+ local filename = resolvers.find_file(name,t) or ""
+ if filename ~= "" then
+ local data = fonts.otf.loadcached(filename)
+ if data and data.luatex and data.luatex.features then
+ return data.luatex.features
+ else
+ local ff = fontloader.open(filename)
+ if ff then
+ local data = fontloader.to_table(ff)
+ fontloader.close(ff)
+ local features = { }
+ for k, what in pairs { "gsub", "gpos" } do
+ local dw = data[what]
+ if dw then
+ local f = { }
+ features[what] = f
+ for _, d in ipairs(dw) do
+ if d.features then
+ for _, df in ipairs(d.features) do
+ local tag = strip(lower(df.tag))
+ local ft = f[tag] if not ft then ft = {} f[tag] = ft end
+ for _, ds in ipairs(df.scripts) do
+ local scri = strip(lower(ds.script))
+ local fts = ft[scri] if not fts then fts = {} ft[scri] = fts end
+ for _, lang in ipairs(ds.langs) do
+ lang = strip(lower(lang))
+ if scri == script then
+ if lang == language then
+ fts[lang] = 'sl'
+ else
+ fts[lang] = 's'
+ end
+ else
+ if lang == language then
+ fts[lang] = 'l'
+ else
+ fts[lang] = true
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ return features
+ end
+ end
+ end
+ end
+ return nil, nil
+end
diff --git a/tex/context/base/font-ota.lua b/tex/context/base/font-ota.lua
new file mode 100644
index 000000000..72e7414c8
--- /dev/null
+++ b/tex/context/base/font-ota.lua
@@ -0,0 +1,320 @@
+if not modules then modules = { } end modules ['font-ota'] = {
+ version = 1.001,
+ comment = "companion to font-otf.lua (analysing)",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this might become scrp-*.lua
+
+local type, tostring, match, format, concat = type, tostring, string.match, string.format, table.concat
+
+if not trackers then trackers = { register = function() end } end
+
+local trace_analyzing = false trackers.register("otf.analyzing", function(v) trace_analyzing = v end)
+local trace_cjk = false trackers.register("cjk.injections", function(v) trace_cjk = v end)
+
+trackers.register("cjk.analyzing","otf.analyzing")
+
+fonts = fonts or { }
+fonts.analyzers = fonts.analyzers or { }
+fonts.analyzers.initializers = fonts.analyzers.initializers or { node = { otf = { } } }
+fonts.analyzers.methods = fonts.analyzers.methods or { node = { otf = { } } }
+
+local otf = fonts.otf
+local tfm = fonts.tfm
+
+local initializers = fonts.analyzers.initializers
+local methods = fonts.analyzers.methods
+
+local glyph = node.id('glyph')
+local glue = node.id('glue')
+local penalty = node.id('penalty')
+
+local set_attribute = node.set_attribute
+local has_attribute = node.has_attribute
+local traverse_id = node.traverse_id
+local delete_node = nodes.delete
+local replace_node = nodes.replace
+local insert_node_after = node.insert_after
+local insert_node_before = node.insert_before
+local traverse_node_list = node.traverse
+
+local fontdata = fonts.ids
+local state = attributes.private('state')
+
+local fcs = (fonts.color and fonts.color.set) or function() end
+local fcr = (fonts.color and fonts.color.reset) or function() end
+
+local a_to_script = otf.a_to_script
+local a_to_language = otf.a_to_language
+
+-- in the future we will use language/script attributes instead of the
+-- font related value, but then we also need dynamic features which is
+-- somewhat slower; and .. we need a chain of them
+
+
+function fonts.initializers.node.otf.analyze(tfmdata,value,attr)
+ if attr and attr > 0 then
+ script, language = a_to_script[attr], a_to_language[attr]
+ else
+ script, language = tfmdata.script, tfmdata.language
+ end
+ local action = initializers[script]
+ if action then
+ if type(action) == "function" then
+ return action(tfmdata,value)
+ else
+ local action = action[language]
+ if action then
+ return action(tfmdata,value)
+ end
+ end
+ end
+ return nil
+end
+
+function fonts.methods.node.otf.analyze(head,font,attr)
+ local tfmdata = fontdata[font]
+ local script, language
+ if attr and attr > 0 then
+ script, language = a_to_script[attr], a_to_language[attr]
+ else
+ script, language = tfmdata.script, tfmdata.language
+ end
+ local action = methods[script]
+ if action then
+ if type(action) == "function" then
+ return action(head,font,attr)
+ else
+ action = action[language]
+ if action then
+ return action(head,font,attr)
+ end
+ end
+ end
+ return head, false
+end
+
+otf.features.register("analyze",true) -- we always analyze
+table.insert(fonts.triggers,"analyze") -- we need a proper function for doing this
+
+-- latin
+
+fonts.analyzers.methods.latn = fonts.analyzers.aux.setstate
+
+-- this info eventually will go into char-def
+
+local zwnj = 0x200C
+local zwj = 0x200D
+
+local isol = {
+ [0x0600] = true, [0x0601] = true, [0x0602] = true, [0x0603] = true,
+ [0x0608] = true, [0x060B] = true, [0x0621] = true, [0x0674] = true,
+ [0x06DD] = true, [zwnj] = true,
+}
+
+local isol_fina = {
+ [0x0622] = true, [0x0623] = true, [0x0624] = true, [0x0625] = true,
+ [0x0627] = true, [0x0629] = true, [0x062F] = true, [0x0630] = true,
+ [0x0631] = true, [0x0632] = true, [0x0648] = true, [0x0671] = true,
+ [0x0672] = true, [0x0673] = true, [0x0675] = true, [0x0676] = true,
+ [0x0677] = true, [0x0688] = true, [0x0689] = true, [0x068A] = true,
+ [0x068B] = true, [0x068C] = true, [0x068D] = true, [0x068E] = true,
+ [0x068F] = true, [0x0690] = true, [0x0691] = true, [0x0692] = true,
+ [0x0693] = true, [0x0694] = true, [0x0695] = true, [0x0696] = true,
+ [0x0697] = true, [0x0698] = true, [0x0699] = true, [0x06C0] = true,
+ [0x06C3] = true, [0x06C4] = true, [0x06C5] = true, [0x06C6] = true,
+ [0x06C7] = true, [0x06C8] = true, [0x06C9] = true, [0x06CA] = true,
+ [0x06CB] = true, [0x06CD] = true, [0x06CF] = true, [0x06D2] = true,
+ [0x06D3] = true, [0x06D5] = true, [0x06EE] = true, [0x06EF] = true,
+ [0x0759] = true, [0x075A] = true, [0x075B] = true, [0x076B] = true,
+ [0x076C] = true, [0x0771] = true, [0x0773] = true, [0x0774] = true,
+ [0x0778] = true, [0x0779] = true,
+}
+
+local isol_fina_medi_init = {
+ [0x0626] = true, [0x0628] = true, [0x062A] = true, [0x062B] = true,
+ [0x062C] = true, [0x062D] = true, [0x062E] = true, [0x0633] = true,
+ [0x0634] = true, [0x0635] = true, [0x0636] = true, [0x0637] = true,
+ [0x0638] = true, [0x0639] = true, [0x063A] = true, [0x063B] = true,
+ [0x063C] = true, [0x063D] = true, [0x063E] = true, [0x063F] = true,
+ [0x0640] = true, [0x0641] = true, [0x0642] = true, [0x0643] = true,
+ [0x0644] = true, [0x0645] = true, [0x0646] = true, [0x0647] = true,
+ [0x0649] = true, [0x064A] = true, [0x066E] = true, [0x066F] = true,
+ [0x0678] = true, [0x0679] = true, [0x067A] = true, [0x067B] = true,
+ [0x067C] = true, [0x067D] = true, [0x067E] = true, [0x067F] = true,
+ [0x0680] = true, [0x0681] = true, [0x0682] = true, [0x0683] = true,
+ [0x0684] = true, [0x0685] = true, [0x0686] = true, [0x0687] = true,
+ [0x069A] = true, [0x069B] = true, [0x069C] = true, [0x069D] = true,
+ [0x069E] = true, [0x069F] = true, [0x06A0] = true, [0x06A1] = true,
+ [0x06A2] = true, [0x06A3] = true, [0x06A4] = true, [0x06A5] = true,
+ [0x06A6] = true, [0x06A7] = true, [0x06A8] = true, [0x06A9] = true,
+ [0x06AA] = true, [0x06AB] = true, [0x06AC] = true, [0x06AD] = true,
+ [0x06AE] = true, [0x06AF] = true, [0x06B0] = true, [0x06B1] = true,
+ [0x06B2] = true, [0x06B3] = true, [0x06B4] = true, [0x06B5] = true,
+ [0x06B6] = true, [0x06B7] = true, [0x06B8] = true, [0x06B9] = true,
+ [0x06BA] = true, [0x06BB] = true, [0x06BC] = true, [0x06BD] = true,
+ [0x06BE] = true, [0x06BF] = true, [0x06C1] = true, [0x06C2] = true,
+ [0x06CC] = true, [0x06CE] = true, [0x06D0] = true, [0x06D1] = true,
+ [0x06FA] = true, [0x06FB] = true, [0x06FC] = true, [0x06FF] = true,
+ [0x0750] = true, [0x0751] = true, [0x0752] = true, [0x0753] = true,
+ [0x0754] = true, [0x0755] = true, [0x0756] = true, [0x0757] = true,
+ [0x0758] = true, [0x075C] = true, [0x075D] = true, [0x075E] = true,
+ [0x075F] = true, [0x0760] = true, [0x0761] = true, [0x0762] = true,
+ [0x0763] = true, [0x0764] = true, [0x0765] = true, [0x0766] = true,
+ [0x0767] = true, [0x0768] = true, [0x0769] = true, [0x076A] = true,
+ [0x076D] = true, [0x076E] = true, [0x076F] = true, [0x0770] = true,
+ [0x0772] = true, [0x0775] = true, [0x0776] = true, [0x0777] = true,
+ [0x077A] = true, [0x077B] = true, [0x077C] = true, [0x077D] = true,
+ [0x077E] = true, [0x077F] = true, [zwj] = true,
+}
+
+local arab_warned = { }
+
+-- todo: gref
+
+local function warning(current,what)
+ local char = current.char
+ if not arab_warned[char] then
+ log.report("analyze","arab: character %s (U+%04X) has no %s class", char, char, what)
+ arab_warned[char] = true
+ end
+end
+
+function fonts.analyzers.methods.nocolor(head,font,attr)
+ for n in traverse_node_list(head,glyph) do
+ if not font or n.font == font then
+ fcr(n)
+ end
+ end
+ return head, true
+end
+
+otf.remove_joiners = false -- true -- for idris who want it as option
+
+local function finish(first,last)
+ if last then
+ if first == last then
+ local fc = first.char
+ if isol_fina_medi_init[fc] or isol_fina[fc] then
+ set_attribute(first,state,4) -- isol
+ if trace_analyzing then fcs(first,"font:isol") end
+ else
+ warning(first,"isol")
+ set_attribute(first,state,0) -- error
+ if trace_analyzing then fcr(first) end
+ end
+ else
+ local lc = last.char
+ if isol_fina_medi_init[lc] or isol_fina[lc] then -- why isol here ?
+ -- if laststate == 1 or laststate == 2 or laststate == 4 then
+ set_attribute(last,state,3) -- fina
+ if trace_analyzing then fcs(last,"font:fina") end
+ else
+ warning(last,"fina")
+ set_attribute(last,state,0) -- error
+ if trace_analyzing then fcr(last) end
+ end
+ end
+ first, last = nil, nil
+ elseif first then
+ -- first and last are either both set so we never com here
+ local fc = first.char
+ if isol_fina_medi_init[fc] or isol_fina[fc] then
+ set_attribute(first,state,4) -- isol
+ if trace_analyzing then fcs(first,"font:isol") end
+ else
+ warning(first,"isol")
+ set_attribute(first,state,0) -- error
+ if trace_analyzing then fcr(first) end
+ end
+ first = nil
+ end
+ return first, last
+end
+
+function fonts.analyzers.methods.arab(head,font,attr) -- maybe make a special version with no trace
+ local tfmdata = fontdata[font]
+ local marks = tfmdata.marks
+ local first, last, current, done = nil, nil, head, false
+ local joiners, nonjoiners
+ local removejoiners = tfmdata.remove_joiners -- or otf.remove_joiners
+ if removejoiners then
+ joiners, nonjoiners = { }, { }
+ end
+ while current do
+ if current.id == glyph and current.subtype<256 and current.font == font and not has_attribute(current,state) then
+ done = true
+ local char = current.char
+ if removejoiners then
+ if char == zwj then
+ joiners[#joiners+1] = current
+ elseif char == zwnj then
+ nonjoiners[#nonjoiners+1] = current
+ end
+ end
+ if marks[char] then
+ set_attribute(current,state,5) -- mark
+ if trace_analyzing then fcs(current,"font:mark") end
+ elseif isol[char] then -- can be zwj or zwnj too
+ first, last = finish(first,last)
+ set_attribute(current,state,4) -- isol
+ if trace_analyzing then fcs(current,"font:isol") end
+ first, last = nil, nil
+ elseif not first then
+ if isol_fina_medi_init[char] then
+ set_attribute(current,state,1) -- init
+ if trace_analyzing then fcs(current,"font:init") end
+ first, last = first or current, current
+ elseif isol_fina[char] then
+ set_attribute(current,state,4) -- isol
+ if trace_analyzing then fcs(current,"font:isol") end
+ first, last = nil, nil
+ else -- no arab
+ first, last = finish(first,last)
+ end
+ elseif isol_fina_medi_init[char] then
+ first, last = first or current, current
+ set_attribute(current,state,2) -- medi
+ if trace_analyzing then fcs(current,"font:medi") end
+ elseif isol_fina[char] then
+ if not has_attribute(last,state,1) then
+ -- tricky, we need to check what last may be !
+ set_attribute(last,state,2) -- medi
+ if trace_analyzing then fcs(last,"font:medi") end
+ end
+ set_attribute(current,state,3) -- fina
+ if trace_analyzing then fcs(current,"font:fina") end
+ first, last = nil, nil
+ elseif char >= 0x0600 and char <= 0x06FF then
+ if trace_analyzing then fcs(current,"font:rest") end
+ first, last = finish(first,last)
+ else --no
+ first, last = finish(first,last)
+ end
+ else
+ first, last = finish(first,last)
+ end
+ current = current.next
+ end
+ first, last = finish(first,last)
+ if removejoiners then
+ for i=1,#joiners do
+ head = delete_node(head,joiners[i])
+ end
+ for i=1,#nonjoiners do
+ head = replace_node(head,nonjoiners[i],nodes.glue(0)) -- or maybe a kern
+ end
+ end
+ return head, done
+end
+
+table.insert(fonts.manipulators,"joiners")
+
+function fonts.initializers.node.otf.joiners(tfmdata,value)
+ if value == "strip" then
+ tfmdata.remove_joiners = true
+ end
+end
diff --git a/tex/context/base/font-otb.lua b/tex/context/base/font-otb.lua
new file mode 100644
index 000000000..2a14085d6
--- /dev/null
+++ b/tex/context/base/font-otb.lua
@@ -0,0 +1,364 @@
+if not modules then modules = { } end modules ['font-otb'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat = table.concat
+local format, gmatch, gsub, find, match, lower, strip = string.format, string.gmatch, string.gsub, string.find, string.match, string.lower, string.strip
+local type, next, tonumber, tostring = type, next, tonumber, tostring
+
+local otf = fonts.otf
+local tfm = fonts.tfm
+
+local trace_baseinit = false trackers.register("otf.baseinit", function(v) trace_baseinit = v end)
+local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end)
+local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end)
+local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end)
+local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end)
+local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end)
+local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end)
+
+local wildcard = "*"
+local default = "dflt"
+
+local split_at_space = lpeg.Ct(lpeg.splitat(" ")) -- no trailing or multiple spaces anyway
+
+local pcache, fcache = { }, { } -- could be weak
+
+local function gref(descriptions,n)
+ if type(n) == "number" then
+ local name = descriptions[n].name
+ if name then
+ return format("U+%04X (%s)",n,name)
+ else
+ return format("U+%04X")
+ end
+ elseif n then
+ local num, nam = { }, { }
+ for i=1,#n do
+ local ni = n[i]
+ num[i] = format("U+%04X",ni)
+ nam[i] = descriptions[ni].name or "?"
+ end
+ return format("%s (%s)",concat(num," "), concat(nam," "))
+ else
+ return "?"
+ end
+end
+
+local function cref(kind,lookupname)
+ if lookupname then
+ return format("feature %s, lookup %s",kind,lookupname)
+ else
+ return format("feature %s",kind)
+ end
+end
+
+local function resolve_ligatures(tfmdata,ligatures,kind)
+ kind = kind or "unknown"
+ local unicodes = tfmdata.unicodes
+ local characters = tfmdata.characters
+ local descriptions = tfmdata.descriptions
+ local changed = tfmdata.changed
+ local done = { }
+ while true do
+ local ok = false
+ for k,v in next, ligatures do
+ local lig = v[1]
+ if not done[lig] then
+ local ligs = split_at_space:match(lig)
+ if #ligs == 2 then
+ local uc = v[2]
+ local c, f, s = characters[uc], ligs[1], ligs[2]
+ local uft, ust = unicodes[f] or 0, unicodes[s] or 0
+ if not uft or not ust then
+ logs.report("define otf","%s: unicode problem with base ligature %s = %s + %s",cref(kind),gref(descriptions,uc),gref(descriptions,uft),gref(descriptions,ust))
+ -- some kind of error
+ else
+ if type(uft) == "number" then uft = { uft } end
+ if type(ust) == "number" then ust = { ust } end
+ for ufi=1,#uft do
+ local uf = uft[ufi]
+ for usi=1,#ust do
+ local us = ust[usi]
+ if changed[uf] or changed[us] then
+ if trace_baseinit and trace_ligatures then
+ logs.report("define otf","%s: base ligature %s + %s ignored",cref(kind),gref(descriptions,uf),gref(descriptions,us))
+ end
+ else
+ local first, second = characters[uf], us
+ if first and second then
+ local t = first.ligatures
+ if not t then
+ t = { }
+ first.ligatures = t
+ end
+ if type(uc) == "number" then
+ t[second] = { type = 0, char = uc }
+ else
+ t[second] = { type = 0, char = uc[1] } -- can this still happen?
+ end
+ if trace_baseinit and trace_ligatures then
+ logs.report("define otf","%s: base ligature %s + %s => %s",cref(kind),gref(descriptions,uf),gref(descriptions,us),gref(descriptions,uc))
+ end
+ end
+ end
+ end
+ end
+ end
+ ok, done[lig] = true, descriptions[uc].name
+ end
+ end
+ end
+ if ok then
+ -- done has "a b c" = "a_b_c" and ligatures the already set ligatures: "a b" = 123
+ -- and here we add extras (f i i = fi + i and alike)
+ --
+ -- we could use a hash for fnc and pattern
+ --
+ -- this might be interfering !
+ for d,n in next, done do
+ local pattern = pcache[d] if not pattern then pattern = "^(" .. d .. ") " pcache[d] = pattern end
+ local fnc = fcache[n] if not fnc then fnc = function() return n .. " " end fcache[n] = fnc end
+ for k,v in next, ligatures do
+ v[1] = gsub(v[1],pattern,fnc)
+ end
+ end
+ else
+ break
+ end
+ end
+end
+
+local function collect_lookups(otfdata,kind,script,language)
+ -- maybe store this in the font
+ local sequences = otfdata.luatex.sequences
+ if sequences then
+ local featuremap, featurelist = { }, { }
+ for s=1,#sequences do
+ local sequence = sequences[s]
+ local features = sequence.features
+ features = features and features[kind]
+ features = features and (features[script] or features[default] or features[wildcard])
+ features = features and (features[language] or features[default] or features[wildcard])
+ if features then
+ local subtables = sequence.subtables
+ if subtables then
+ for s=1,#subtables do
+ local ss = subtables[s]
+ if not featuremap[s] then
+ featuremap[ss] = true
+ featurelist[#featurelist+1] = ss
+ end
+ end
+ end
+ end
+ end
+ if #featurelist > 0 then
+ return featuremap, featurelist
+ end
+ end
+ return nil, nil
+end
+
+local splitter = lpeg.splitat(" ")
+
+function prepare_base_substitutions(tfmdata,kind,value) -- we can share some code with the node features
+ if value then
+ local otfdata = tfmdata.shared.otfdata
+ local validlookups, lookuplist = collect_lookups(otfdata,kind,tfmdata.script,tfmdata.language)
+ if validlookups then
+ local ligatures = { }
+ local unicodes = tfmdata.unicodes -- names to unicodes
+ local indices = tfmdata.indices
+ local characters = tfmdata.characters
+ local descriptions = tfmdata.descriptions
+ local changed = tfmdata.changed
+ for k,c in next, characters do
+ local glyph = descriptions[k]
+ local lookups = glyph.lookups
+ if lookups then
+ for l=1,#lookuplist do
+ local lookup = lookuplist[l]
+ local ps = lookups[lookup]
+ if ps then
+ for i=1,#ps do
+ local p = ps[i]
+ local t = p[1]
+ if t == 'substitution' then
+ local pv = p[2] -- p.variant
+ if pv then
+ local upv = unicodes[pv]
+ if upv then
+ if type(upv) == "table" then
+ upv = upv[1]
+ end
+ if characters[upv] then
+ if trace_baseinit and trace_singles then
+ logs.report("define otf","%s: base substitution %s => %s",cref(kind,lookup),gref(descriptions,k),gref(descriptions,upv))
+ end
+ changed[k] = upv
+ end
+ end
+ end
+ elseif t == 'alternate' then
+ local pc = p[2] -- p.components
+ if pc then
+ -- a bit optimized ugliness
+ if value == 1 then
+ pc = splitter:match(pc)
+ elseif value == 2 then
+ local a, b = splitter:match(pc)
+ pc = b or a
+ else
+ pc = { splitter:match(pc) }
+ pc = pc[value] or pc[#pc]
+ end
+ if pc then
+ local upc = unicodes[pc]
+ if upc then
+ if type(upc) == "table" then
+ upc = upc[1]
+ end
+ if characters[upc] then
+ if trace_baseinit and trace_alternatives then
+ logs.report("define otf","%s: base alternate %s => %s",cref(kind,lookup),gref(descriptions,k),gref(descriptions,upc))
+ end
+ changed[k] = upc
+ end
+ end
+ end
+ end
+ elseif t == 'ligature' and not changed[k] then
+ local pc = p[2]
+ if pc then
+ if trace_baseinit and trace_ligatures then
+ local upc = { splitter:match(pc) }
+ for i=1,#upc do upc[i] = unicodes[upc[i]] end
+ -- we assume that it's no table
+ logs.report("define otf","%s: base ligature %s => %s",cref(kind,lookup),gref(descriptions,upc),gref(descriptions,k))
+ end
+ ligatures[#ligatures+1] = { pc, k }
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ resolve_ligatures(tfmdata,ligatures,kind)
+ end
+ else
+ tfmdata.ligatures = tfmdata.ligatures or { } -- left over from what ?
+ end
+end
+
+local function prepare_base_kerns(tfmdata,kind,value) -- todo what kind of kerns, currently all
+ if value then
+ local otfdata = tfmdata.shared.otfdata
+ local validlookups, lookuplist = collect_lookups(otfdata,kind,tfmdata.script,tfmdata.language)
+ if validlookups then
+ local unicodes = tfmdata.unicodes -- names to unicodes
+ local indices = tfmdata.indices
+ local characters = tfmdata.characters
+ local descriptions = tfmdata.descriptions
+ for u, chr in next, characters do
+ local d = descriptions[u]
+ if d then
+ local dk = d.mykerns
+ if dk then
+ local t, done = chr.kerns or { }, false
+ for l=1,#lookuplist do
+ local lookup = lookuplist[l]
+ local kerns = dk[lookup]
+ if kerns then
+ for k, v in next, kerns do
+ if v ~= 0 and not t[k] then -- maybe no 0 test here
+ t[k], done = v, true
+ if trace_baseinit and trace_kerns then
+ logs.report("define otf","%s: base kern %s + %s => %s",cref(kind,lookup),gref(descriptions,u),gref(descriptions,k),v)
+ end
+ end
+ end
+ end
+ end
+ if done then
+ chr.kerns = t -- no empty assignments
+ end
+ -- elseif d.kerns then
+ -- logs.report("define otf","%s: invalid mykerns for %s",cref(kind),gref(descriptions,u))
+ end
+ end
+ end
+ end
+ end
+end
+
+-- In principle we could register each feature individually which was
+-- what we did in earlier versions. However, after the rewrite it
+-- made more sense to collect them in an overall features initializer
+-- just as with the node variant. There it was needed because we need
+-- to do complete mixed runs and not run featurewise (as we did before).
+
+local supported_gsub = {
+ 'liga','dlig','rlig','hlig',
+ 'pnum','onum','tnum','lnum',
+ 'zero',
+ 'smcp','cpsp','c2sc','ornm','aalt',
+ 'hwid','fwid',
+ 'ssty', -- math
+}
+
+local supported_gpos = {
+ 'kern'
+}
+
+function otf.features.register_base_substitution(tag)
+ supported_gsub[#supported_gsub+1] = tag
+end
+function otf.features.register_base_kern(tag)
+ supported_gsub[#supported_gpos+1] = tag
+end
+
+local basehash, basehashes = { }, 1
+
+function fonts.initializers.base.otf.features(tfmdata,value)
+ if true then -- value then
+ -- not shared
+ local t = trace_preparing and os.clock()
+ local features = tfmdata.shared.features
+ if features then
+ local h = { }
+ for f=1,#supported_gsub do
+ local feature = supported_gsub[f]
+ prepare_base_substitutions(tfmdata,feature,features[feature])
+ h[#h+1] = feature
+ end
+ for f=1,#supported_gpos do
+ local feature = supported_gpos[f]
+ prepare_base_kerns(tfmdata,feature,features[feature])
+ h[#h+1] = feature
+ end
+ local hash = concat(h," ")
+ local base = basehash[hash]
+ if not base then
+ basehashes = basehashes + 1
+ base = basehashes
+ basehash[hash] = base
+ end
+ -- We need to make sure that luatex sees the difference between
+ -- base fonts that have different glyphs in the same slots in fonts
+ -- that have the same fullname (or filename). LuaTeX will merge fonts
+ -- eventually (and subset later on). If needed we can use a more
+ -- verbose name as long as we don't use <()<>[]{}/%> and the length
+ -- is < 128.
+ tfmdata.fullname = tfmdata.fullname .. base
+ end
+ if trace_preparing then
+ logs.report("otf define","preparation time is %0.3f seconds for %s",os.clock()-t,tfmdata.fullname or "?")
+ end
+ end
+end
diff --git a/tex/context/base/font-otc.lua b/tex/context/base/font-otc.lua
new file mode 100644
index 000000000..f75da39cd
--- /dev/null
+++ b/tex/context/base/font-otc.lua
@@ -0,0 +1,238 @@
+if not modules then modules = { } end modules ['font-otc'] = {
+ version = 1.001,
+ comment = "companion to font-otf.lua (context)",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, insert = string.format, table.insert
+local type, next = type, next
+
+local ctxcatcodes = tex.ctxcatcodes
+
+-- we assume that the other otf stuff is loaded already
+
+local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end)
+
+local otf = fonts.otf
+local tfm = fonts.tfm
+
+-- instead of "script = "DFLT", langs = { 'dflt' }" we now use wildcards (we used to
+-- have always); some day we can write a "force always when true" trick for other
+-- features as well
+
+local extra_lists = {
+ tlig = {
+ {
+ endash = "hyphen hyphen",
+ emdash = "hyphen hyphen hyphen",
+ -- quotedblleft = "quoteleft quoteleft",
+ -- quotedblright = "quoteright quoteright",
+ -- quotedblleft = "grave grave",
+ -- quotedblright = "quotesingle quotesingle",
+ -- quotedblbase = "comma comma",
+ },
+ },
+ trep = {
+ {
+ -- [0x0022] = 0x201D,
+ [0x0027] = 0x2019,
+ -- [0x0060] = 0x2018,
+ },
+ },
+ anum = {
+ { -- arabic
+ [0x0030] = 0x0660,
+ [0x0031] = 0x0661,
+ [0x0032] = 0x0662,
+ [0x0033] = 0x0663,
+ [0x0034] = 0x0664,
+ [0x0035] = 0x0665,
+ [0x0036] = 0x0666,
+ [0x0037] = 0x0667,
+ [0x0038] = 0x0668,
+ [0x0039] = 0x0669,
+ },
+ { -- persian
+ [0x0030] = 0x06F0,
+ [0x0031] = 0x06F1,
+ [0x0032] = 0x06F2,
+ [0x0033] = 0x06F3,
+ [0x0034] = 0x06F4,
+ [0x0035] = 0x06F5,
+ [0x0036] = 0x06F6,
+ [0x0037] = 0x06F7,
+ [0x0038] = 0x06F8,
+ [0x0039] = 0x06F9,
+ },
+ },
+}
+
+local extra_features = { -- maybe just 1..n so that we prescribe order
+ tlig = {
+ {
+ features = { { scripts = { { script = "*", langs = { "*" }, } }, tag = "tlig", comment = "added bij mkiv" }, },
+ name = "ctx_tlig_1",
+ subtables = { { name = "ctx_tlig_1_s" } },
+ type = "gsub_ligature",
+ flags = { },
+ },
+ },
+ trep = {
+ {
+ features = { { scripts = { { script = "*", langs = { "*" }, } }, tag = "trep", comment = "added bij mkiv" }, },
+ name = "ctx_trep_1",
+ subtables = { { name = "ctx_trep_1_s" } },
+ type = "gsub_single",
+ flags = { },
+ },
+ },
+ anum = {
+ {
+ features = { { scripts = { { script = "arab", langs = { "dflt", "FAR" }, } }, tag = "anum", comment = "added bij mkiv" }, },
+ name = "ctx_anum_1",
+ subtables = { { name = "ctx_anum_1_s" } },
+ type = "gsub_single",
+ flags = { },
+ },
+ {
+ features = { { scripts = { { script = "arab", langs = { "URD" }, } }, tag = "anum", comment = "added bij mkiv" }, },
+ name = "ctx_anum_2",
+ subtables = { { name = "ctx_anum_2_s" } },
+ type = "gsub_single",
+ flags = { },
+ },
+ },
+}
+
+fonts.otf.enhancers["add some missing characters"] = function(data,filename)
+ -- todo
+end
+
+fonts.otf.enhancers["enrich with features"] = function(data,filename)
+ -- could be done elsewhere (true can be #)
+ local used = { }
+ for i=1,#otf.glists do
+ local g = data[otf.glists[i]]
+ if g then
+ for i=1,#g do
+ local f = g[i].features
+ if f then
+ for i=1,#f do
+ local t = f[i].tag
+ if t then used[t] = true end
+ end
+ end
+ end
+ end
+ end
+ --
+ local glyphs = data.glyphs
+ local indices = data.map.map
+ data.gsub = data.gsub or { }
+ for kind, specifications in next, extra_features do
+ if not used[kind] then
+ local done = 0
+ for s=1,#specifications do
+ local added = false
+ local specification = specifications[s]
+ local list = extra_lists[kind][s]
+ local name = specification.name .. "_s"
+ if specification.type == "gsub_ligature" then
+ for unicode, index in next, indices do
+ local glyph = glyphs[index]
+ local ligature = list[glyph.name]
+ if ligature then
+ local o = glyph.lookups or { }
+ -- o[name] = { "ligature", ligature, glyph.name }
+ o[name] = {
+ {
+ ["type"] = "ligature",
+ ["specification"] = {
+ char = glyph.name,
+ components = ligature,
+ }
+ }
+ }
+ glyph.lookups, done, added = o, done+1, true
+ end
+ end
+ elseif specification.type == "gsub_single" then
+ for unicode, index in next, indices do
+ local glyph = glyphs[index]
+ local r = list[unicode]
+ if r then
+ local replacement = indices[r]
+ if replacement and glyphs[replacement] then
+ local o = glyph.lookups or { }
+ -- o[name] = { { "substitution", glyphs[replacement].name } }
+ o[name] = {
+ {
+ ["type"] = "substitution",
+ ["specification"] = {
+ variant = glyphs[replacement].name,
+ }
+ }
+ }
+ glyph.lookups, done, added = o, done+1, true
+ end
+ end
+ end
+ end
+ if added then
+ insert(data.gsub,s,table.fastcopy(specification)) -- right order
+ end
+ end
+ if done > 0 then
+ if trace_loading then
+ logs.report("load otf","enhance: registering %s feature (%s glyphs affected)",kind,done)
+ end
+ end
+ end
+ end
+end
+
+otf.tables.features['tlig'] = 'TeX Ligatures'
+otf.tables.features['trep'] = 'TeX Replacements'
+otf.tables.features['anum'] = 'Arabic Digits'
+
+otf.features.register_base_substitution('tlig')
+otf.features.register_base_substitution('trep')
+otf.features.register_base_substitution('anum')
+
+-- the functionality is defined elsewhere
+
+fonts.initializers.base.otf.equaldigits = fonts.initializers.common.equaldigits
+fonts.initializers.node.otf.equaldigits = fonts.initializers.common.equaldigits
+
+fonts.initializers.base.otf.lineheight = fonts.initializers.common.lineheight
+fonts.initializers.node.otf.lineheight = fonts.initializers.common.lineheight
+
+fonts.initializers.base.otf.compose = fonts.initializers.common.compose
+fonts.initializers.node.otf.compose = fonts.initializers.common.compose
+
+-- bonus function
+
+function otf.name_to_slot(name) -- todo: afm en tfm
+ local tfmdata = fonts.ids[font.current()]
+ if tfmdata and tfmdata.shared then
+ local otfdata = tfmdata.shared.otfdata
+ local unicode = otfdata.luatex.unicodes[name]
+ if type(unicode) == "number" then
+ return unicode
+ else
+ return unicode[1]
+ end
+ end
+ return nil
+end
+
+function otf.char(n) -- todo: afm en tfm
+ if type(n) == "string" then
+ n = otf.name_to_slot(n)
+ end
+ if n then
+ tex.sprint(ctxcatcodes,format("\\char%s ",n))
+ end
+end
diff --git a/tex/context/base/font-otd.lua b/tex/context/base/font-otd.lua
new file mode 100644
index 000000000..78a828146
--- /dev/null
+++ b/tex/context/base/font-otd.lua
@@ -0,0 +1,78 @@
+if not modules then modules = { } end modules ['font-otd'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local trace_dynamics = false trackers.register("otf.dynamics", function(v) trace_dynamics = v end)
+
+fonts = fonts or { }
+fonts.otf = fonts.otf or { }
+
+local otf = fonts.otf
+local fontdata = fonts.ids
+
+otf.features = otf.features or { }
+otf.features.default = otf.features.default or { }
+
+local context_setups = fonts.define.specify.context_setups
+local context_numbers = fonts.define.specify.context_numbers
+
+local a_to_script = { } otf.a_to_script = a_to_script
+local a_to_language = { } otf.a_to_language = a_to_language
+
+function otf.set_dynamics(font,dynamics,attribute)
+ features = context_setups[context_numbers[attribute]] -- can be moved to caller
+ if features then
+ local script = features.script or 'dflt'
+ local language = features.language or 'dflt'
+ local ds = dynamics[script]
+ if not ds then
+ ds = { }
+ dynamics[script] = ds
+ end
+ local dsl = ds[language]
+ if not dsl then
+ dsl = { }
+ ds[language] = dsl
+ end
+ local dsla = dsl[attribute]
+ if dsla then
+ -- if trace_dynamics then
+ -- logs.report("otf define","using dynamics %s: attribute %s, script %s, language %s",context_numbers[attribute],attribute,script,language)
+ -- end
+ return dsla
+ else
+ local tfmdata = fontdata[font]
+ a_to_script [attribute] = script
+ a_to_language[attribute] = language
+ -- we need to save some values
+ local saved = {
+ script = tfmdata.script,
+ language = tfmdata.language,
+ mode = tfmdata.mode,
+ features = tfmdata.shared.features
+ }
+ tfmdata.mode = "node"
+ tfmdata.language = language
+ tfmdata.script = script
+ tfmdata.shared.features = { }
+ -- end of save
+ dsla = otf.set_features(tfmdata,fonts.define.check(features,otf.features.default))
+ if trace_dynamics then
+ logs.report("otf define","setting dynamics %s: attribute %s, script %s, language %s",context_numbers[attribute],attribute,script,language)
+ end
+ -- we need to restore some values
+ tfmdata.script = saved.script
+ tfmdata.language = saved.language
+ tfmdata.mode = saved.mode
+ tfmdata.shared.features = saved.features
+ -- end of restore
+ dynamics[script][language][attribute] = dsla -- cache
+ return dsla
+ end
+ end
+ return nil -- { }
+end
diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua
index fffd4eeda..20273f8f5 100644
--- a/tex/context/base/font-otf.lua
+++ b/tex/context/base/font-otf.lua
@@ -6,829 +6,210 @@ if not modules then modules = { } end modules ['font-otf'] = {
license = "see context related readme files"
}
-local format, concat, getn = string.format, table.concat, table.getn
-local type, pairs, ipairs, next, tonumber, tostring = type, pairs, ipairs, next, tonumber, tostring
+local utf = unicode.utf8
-local space = lpeg.P(" ")
-local nospaces = (1-space)^1
-local optionalspace = space^0
+local concat, getn, utfbyte = table.concat, table.getn, utf.byte
+local format, gmatch, gsub, find, match, lower, strip = string.format, string.gmatch, string.gsub, string.find, string.match, string.lower, string.strip
+local type, next, tonumber, tostring = type, next, tonumber, tostring
-local split_at_space = lpeg.Ct((lpeg.C(nospaces) * optionalspace)^0) -- table !
+local trace_private = false trackers.register("otf.private", function(v) trace_private = v end)
+local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end)
+local trace_features = false trackers.register("otf.features", function(v) trace_features = v end)
+local trace_dynamics = false trackers.register("otf.dynamics", function(v) trace_dynamics = v end)
+local trace_sequences = false trackers.register("otf.sequences", function(v) trace_sequences = v end)
+local trace_math = false trackers.register("otf.math", function(v) trace_math = v end)
--- we can use more lpegs when lpeg is extended with function args and so
+--~ trackers.enable("otf.loading")
--- the flattening code is a prelude to a more compact table format (so, we're now
--- at the fourth version); maybe we will go unicode, although that will mean that we
--- miss some glyphs (unicode -1)
-
--- todo: featuredata is now indexed by kind,lookup but probably lookup is okay too
-
--- todo: now that we pack ... resolve strings to unicode points
--- todo: unpack already in tmc file, i.e. save tables and return ref''d version
--- todo: dependents etc resolve too, maybe even reorder glyphs to unicode
--- todo: pack ignoreflags
-
--- abvf abvs blwf blws dist falt half halt jalt lfbd ljmo
--- mset opbd palt pwid qwid rand rtbd ruby size tjmo twid valt vatu vert
--- vhal vjmo vkna vkrn vpal vrt2
-
--- The specification of OpenType is vague, very vague. Apart from a lack of proper
--- specifications (a free one) there's also the problem that Microsoft and Adobe
--- may have their own rules. Anyhow, the following is from Adobe's feature file
--- specification:
---
--- http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#6.h
---
--- The following is a reference summary of the algorithm used by an OpenType layout
--- (OTL) engine to perform substitutions and positionings. The important aspect of
--- this for a feature file editor is that each lookup corresponds to one "pass" over
--- the glyph run (see step 4 below). Thus, each lookup has as input the accumulated
--- result of all previous lookups in the LookupList (whether in the same feature or
--- in other features).
--- 1. All glyphs in the client's glyph run must belong to the same language
--- system. Glyph sequence matching may not occur across language
--- systems. Do the following first for the GSUB and then for the GPOS:
--- 2. Assemble all features (including any required feature) for the glyph
--- run's language system.
--- 3. Assemble all lookups in these features, in LookupList order, removing
--- any duplicates. All features and thus all lookups needn't be applied to
--- every glyph in the run.
--- 4. For each lookup:
--- 5. For each glyph in the glyph run:
--- 6. If the lookup is applied to that glyph and the lookupflag doesn't
--- indicate that that glyph is to be ignored:
--- 7. For each subtable in the lookup:
--- 8. If the subtable's target context is matched:
--- 9. Do the glyph substitution or positioning,
--- --- OR: ---
--- If this is a (chain) contextual lookup do the following
--- [(10)-(11)] in the subtable's Subst/PosLookupRecord order:
--- 10. For each (sequenceIndex, lookupListIndex) pair:
--- 11. Apply lookup[lookupListIndex] at input sequence[sequenceIndex]
--- [steps (7)-(11)]
--- 12. Goto the glyph after the input sequence matched in (8)
--- (i.e. skip any remaining subtables in the lookup).
--- The "target context" in step 8 above comprises the input sequence and any
--- backtrack and lookahead sequences.
--- The input sequence must be matched entirely within the lookup's "application
--- range" at that glyph (that contiguous subrun of glyphs including and around
--- the current glyph on which the lookup is applied). There is no such restriction
--- on the backtrack and lookahead sequences.
--- "Matching" includes matching any glyphs designated to be skipped in the
--- lookup's LookupFlag.
+local zwnj = 0x200C
+local zwj = 0x200D
--[[ldx--
-
This module is sparsely documented because it is a moving target.
-The table format of the reader changes and we experiment a lot with
-different methods for supporting features.
+
The fontforge table has organized lookups in a certain way. A first implementation
+of this code was organized featurewise: information related to features was
+collected and processing boiled down to a run over the features. The current
+implementation honors the order in the main feature table. Since we can reorder this
+table as we want, we can eventually support several models of processing. We kept
+the static as well as dynamic feature processing, because it had proved to be
+rather useful. The formerly three loop variants have beem discarded but will
+reapear at some time.
+
+
+we loop over all lookups
+for each lookup we do a run over the list of glyphs
+but we only process them for features that are enabled
+if we're dealing with a contextual lookup, we loop over all contexts
+in that loop we quit at a match and then process the list of sublookups
+we always continue after the match
+
+
+
In we do this for each font that is used in a list, so in
+practice we have quite some nested loops.
+
+
We process the whole list and then consult the glyph nodes. An alternative approach
+is to collect strings of characters using the same font including spaces (because some
+lookups involve spaces). However, we then need to reconstruct the list which is no fun.
+Also, we need to carry quite some information, like attributes, so eventually we don't
+gain much (if we gain something at all).
+
+
Another consideration has been to operate on sublists (subhead, subtail) but again
+this would complicate matters as we then neext to keep track of a changing subhead
+and subtail. On the other hand, this might save some runtime. The number of changes
+involved is not that large. This only makes sense when we have many fonts in a list
+and don't change to frequently.
+--ldx]]--
-
As with the code, we may decide to store more information
-in the table.
+fonts = fonts or { }
+fonts.otf = fonts.otf or { }
+fonts.tfm = fonts.tfm or { }
-
Incrementing the version number will force a re-cache. We jump the
-number by one when there's a fix in the library or
- code that results in different tables.
---ldx]]--
+local otf = fonts.otf
+local tfm = fonts.tfm
---~ The node based processing functions look quite complex which is mainly due to
---~ the fact that we need to share data and cache resolved issues (saves much memory and
---~ is also faster). A further complication is that we support static as well as dynamic
---~ features.
+local fontdata = fonts.ids
-fonts = fonts or { }
-fonts.otf = fonts.otf or { }
+otf.tables = otf.tables or { } -- defined in font-ott.lua
+otf.meanings = otf.meanings or { } -- defined in font-ott.lua
+otf.tables.features = otf.tables.features or { } -- defined in font-ott.lua
+otf.tables.languages = otf.tables.languages or { } -- defined in font-ott.lua
+otf.tables.scripts = otf.tables.scripts or { } -- defined in font-ott.lua
-local otf = fonts.otf
-local tfm = fonts.tfm
+otf.features = otf.features or { }
+otf.features.list = otf.features.list or { }
+otf.features.default = otf.features.default or { }
-otf.version = 2.24
-otf.pack = true
-otf.tables = otf.tables or { }
-otf.meanings = otf.meanings or { }
-otf.enhance_data = false
-otf.syncspace = true
-otf.features = { }
-otf.features.aux = { }
-otf.features.data = { }
-otf.features.list = { } -- not (yet) used, oft fonts have gpos/gsub lists
-otf.features.default = { }
-otf.trace_features = false
-otf.trace_set_features = false
-otf.trace_replacements = false
-otf.trace_contexts = false
-otf.trace_anchors = false
-otf.trace_ligatures = false
-otf.trace_kerns = false
-otf.trace_cursive = false
-otf.notdef = false
-otf.cache = containers.define("fonts", "otf", otf.version, true)
+otf.enhancers = otf.enhancers or { }
+otf.glists = { "gsub", "gpos" }
-function otf.trace_process()
- otf.trace_replacements = true
- otf.trace_contexts = true
- otf.trace_anchors = true
- otf.trace_ligatures = true
- otf.trace_kerns = true
- otf.trace_cursive = true
-end
+otf.version = 2.626 -- beware: also sync font-mis.lua
+otf.pack = true -- beware: also sync font-mis.lua
+otf.syncspace = true
+otf.notdef = false
+otf.cache = containers.define("fonts", "otf", otf.version, true)
+otf.cleanup_aat = false -- only context
--[[ldx--
We start with a lot of tables and related functions.
+--ldx]]--
-function otf.meanings.resolve(tab,id)
- if tab and id then
- id = id:lower()
- return tab[id] or tab[id:gsub(" ","")] or tab['dflt'] or ''
- else
- return "unknown"
+local function load_featurefile(ff,featurefile)
+ if featurefile then
+ featurefile = resolvers.find_file(file.addsuffix(featurefile,'fea')) -- "FONTFEATURES"
+ if featurefile and featurefile ~= "" then
+ if trace_loading then
+ logs.report("load otf", "featurefile: %s", featurefile)
+ end
+ fontloader.apply_featurefile(ff, featurefile)
+ end
end
end
-function otf.meanings.script(id)
- return otf.meanings.resolve(otf.tables.scripts,id)
-end
-function otf.meanings.language(id)
- return otf.meanings.resolve(otf.tables.languages,id)
-end
-function otf.meanings.feature(id)
- return otf.meanings.resolve(otf.tables.features,id)
-end
-function otf.meanings.baseline(id)
- return otf.meanings.resolve(otf.tables.baselines,id)
-end
-
-otf.tables.to_scripts = table.reverse_hash(otf.tables.scripts )
-otf.tables.to_languages = table.reverse_hash(otf.tables.languages)
-otf.tables.to_features = table.reverse_hash(otf.tables.features )
-
-do
-
- local scripts = otf.tables.scripts
- local languages = otf.tables.languages
- local features = otf.tables.features
-
- local to_scripts = otf.tables.to_scripts
- local to_languages = otf.tables.to_languages
- local to_features = otf.tables.to_features
-
- function otf.meanings.normalize(features)
- local h = { }
- for k,v in pairs(features) do
- k = k:lower() -- :gsub("[^a-z0-9%-%.]" -- not needed
- if k == "language" or k == "lang" then
- v = (v:lower()):gsub("[^a-z0-9%-]","")
- k = language
- if not languages[v] then
- h.language = to_languages[v] or "dflt"
- else
- h.language = v
- end
- elseif k == "script" then
- v = (v:lower()):gsub("[^a-z0-9%-]","")
- if not scripts[v] then
- h.script = to_scripts[v] or "dflt"
- else
- h.script = v
- end
- else
- if type(v) == "string" then
- local b = v:is_boolean()
- if type(b) == "nil" then
- v = tonumber(v) or v:lower() -- gsub("[^a-z0-9%-]") -- too dangerous, e.g. featurefiles
- else
- v = b
- end
- end
- h[to_features[k] or k] = v
- end
+function otf.enhance(name,data,filename,verbose)
+ local enhancer = otf.enhancers[name]
+ if enhancer then
+ if (verbose ~= nil and verbose) or trace_loading then
+ logs.report("load otf","enhance: %s",name)
end
- return h
+ enhancer(data,filename)
end
-
end
---[[ldx--
-
Here we go.
---ldx]]--
-
-otf.enhance = otf.enhance or { }
-otf.enhance.add_kerns = true
-
-otf.featurefiles = {
---~ "texhistoric.fea"
+local enhancers = {
+ -- pack and unpack are handled separately; they might even be moved
+ -- away from the enhancers namespace
+ "patch bugs",
+ "merge cid fonts", "prepare unicode", "cleanup ttf tables", "compact glyphs", "reverse coverage",
+ "cleanup aat", "enrich with features", "add some missing characters",
+ "reorganize kerns", -- moved here
+ "flatten glyph lookups", "flatten anchor tables", "flatten feature tables",
+ "prepare luatex tables",
+ "analyse features", "rehash features",
+ "analyse anchors", "analyse marks", "analyse unicodes", "analyse subtables",
+ "check italic correction","check math",
+ "share widths",
+ "strip not needed data",
+ "migrate metadata",
}
function otf.load(filename,format,sub,featurefile)
@@ -838,72 +219,45 @@ function otf.load(filename,format,sub,featurefile)
end
if sub == "" then sub = false end
local hash = name
- if sub then -- name cleanup will move to cache code
+ if sub then
hash = hash .. "-" .. sub
- hash = hash:lower()
- hash = hash:gsub("[^%w%d]+","-")
end
+ hash = containers.cleanname(hash)
local data = containers.read(otf.cache(), hash)
- if data and data.verbose ~= fonts.verbose then
- data = nil
- end
local size = lfs.attributes(filename,"size") or 0
- if data and data.size ~= size then
- data = nil
- end
- if not data then
+ if not data or data.verbose ~= fonts.verbose or data.size ~= size then
logs.report("load otf","loading: %s",filename)
local ff, messages
if sub then
- ff, messages = fontforge.open(filename,sub)
+ ff, messages = fontloader.open(filename,sub)
else
- ff, messages = fontforge.open(filename)
+ ff, messages = fontloader.open(filename)
end
- if messages and #messages > 0 then
- for _, m in ipairs(messages) do
- logs.report("load otf","warning: %s",m)
+ if trace_loading and messages and #messages > 0 then
+ for m=1,#messages do
+ logs.report("load otf","warning: %s",messages[m])
end
end
if ff then
- local function load_featurefile(featurefile)
- if featurefile then
- featurefile = input.find_file(file.addsuffix(featurefile,'fea')) -- "FONTFEATURES"
- if featurefile and featurefile ~= "" then
- logs.report("load otf", "featurefile: %s", featurefile)
- fontforge.apply_featurefile(ff, featurefile)
- end
- end
- end
- -- for _, featurefile in pairs(otf.featurefiles) do
- -- load_featurefile(featurefile)
- -- end
- load_featurefile(featurefile)
- data = fontforge.to_table(ff)
- fontforge.close(ff)
+ load_featurefile(ff,featurefile)
+ data = fontloader.to_table(ff)
+ fontloader.close(ff)
if data then
- logs.report("load otf","enhance: patch")
- otf.enhance.patch(data,filename)
- logs.report("load otf","enhance: before")
- otf.enhance.before(data,filename)
- logs.report("load otf","enhance: enrich")
- otf.enhance.enrich(data,filename)
- logs.report("load otf","enhance: flatten")
- otf.enhance.flatten(data,filename)
- logs.report("load otf","enhance: analyze")
- otf.enhance.analyze(data,filename)
- logs.report("load otf","enhance: after")
- otf.enhance.after(data,filename)
- logs.report("load otf","enhance: strip")
- otf.enhance.strip(data,filename)
+ logs.report("load otf","file size: %s", size)
+ logs.report("load otf","enhancing ...")
+ for e=1,#enhancers do
+ otf.enhance(enhancers[e],data,filename)
+ end
if otf.pack and not fonts.verbose then
- logs.report("load otf","enhance: pack")
- otf.enhance.pack(data)
+ otf.enhance("pack",data,filename)
end
- logs.report("load otf","file size: %s", size)
data.size = size
data.verbose = fonts.verbose
- logs.report("load otf","saving: in cache")
+ logs.report("load otf","saving in cache: %s",filename)
data = containers.write(otf.cache(), hash, data)
+ collectgarbage("collect")
+ data = containers.read(otf.cache(), hash) -- this frees the old table and load the sparse one
+ collectgarbage("collect")
else
logs.report("load otf","loading failed (table conversion error)")
end
@@ -911,375 +265,357 @@ function otf.load(filename,format,sub,featurefile)
logs.report("load otf","loading failed (file read error)")
end
end
- otf.enhance.unpack(data)
+ if data then
+ otf.enhance("unpack",data,filename,false) -- no message here
+ otf.add_dimensions(data)
+ if trace_sequences then
+ otf.show_feature_order(data,filename)
+ end
+ end
return data
end
--- memory saver ..
-
-local criterium, threshold = 1, 0
-
-function otf.enhance.pack(data)
+function otf.add_dimensions(data)
+ -- todo: forget about the width if it's the defaultwidth (saves mem)
+ -- we could also build the marks hash here (instead of storing it)
if data then
- local h, t, c = { }, { }, { }
- local hh, tt, cc = { }, { }, { }
- local function tabstr(t)
- for i=1,#t do
- -- tricky, was if type(t[i]) == "boolean" then, but if no [1] then error
- local ti = type(t[i])
- if ti ~= "string" or ti ~= "number" then
- local s = tostring(t[1])
- for i=2,#t do
- s = s .. ",".. tostring(t[i])
- end
- return s
- end
- end
- return concat(t,",")
- end
- for pass=1,2 do
- local pack
- if pass == 1 then
- pack = function(v)
- -- v == table
- local tag = tabstr(v,",")
- local ht = h[tag]
- if not ht then
- ht = #t+1
- t[ht] = v
- h[tag] = ht
- c[ht] = 1
- else
- c[ht] = c[ht] + 1
- end
- return ht
- end
- else
- pack = function(v)
- -- v == number
- if c[v] <= criterium then
- return t[v]
- else
- -- compact hash
- local hv = hh[v]
- if not hv then
- hv = #tt+1
- tt[hv] = t[v]
- hh[v] = hv
- cc[hv] = c[v]
- end
- return hv
- end
- end
- end
- for k, v in pairs(data.glyphs) do
- v.boundingbox = pack(v.boundingbox)
- if v.lookups then
- for k,v in pairs(v.lookups) do
- for kk=1,#v do
- v[kk] = pack(v[kk])
- end
- end
- end
- local a = v.anchors
- if a then
- for k,v in pairs(a) do
- if k == "baselig" then
- for kk, vv in pairs(v) do
- for kkk=1,#vv do
- vv[kkk] = pack(vv[kkk])
- end
- end
- else
- for kk, vv in pairs(v) do
- v[kk] = pack(vv)
- end
- end
- end
- end
+ local force = otf.notdef
+ local luatex = data.luatex
+ local defaultwidth = luatex.defaultwidth or 0
+ local defaultheight = luatex.defaultheight or 0
+ local defaultdepth = luatex.defaultdepth or 0
+ for _, d in next, data.glyphs do
+ local bb, wd = d.boundingbox, d.width
+ if not wd then
+ d.width = defaultwidth
+ elseif wd ~= 0 and d.class == "mark" then
+ d.width = -wd
end
- if data.lookups then
- for k, v in pairs(data.lookups) do
- if v.rules then
- for kk, vv in pairs(v.rules) do
- local l = vv.lookups
- if l then
- vv.lookups = pack(l)
- end
- local c = vv.coverage
- if c then
- c.before = c.before and pack(c.before )
- c.after = c.after and pack(c.after )
- c.current = c.current and pack(c.current)
- end
- end
- end
- end
+ if force and not d.name then
+ d.name = ".notdef"
end
- if data.luatex then
- local li = data.luatex.ignore_flags
- if li then
- for k, v in pairs(li) do
- li[k] = pack(v)
- end
+ if bb then
+ local ht, dp = bb[4], -bb[2]
+ if ht == 0 or ht < 0 then
+ -- no need to set it and no negative heights, nil == 0
+ else
+ d.height = ht
end
- end
- if #t == 0 then
- logs.report("load otf","pack quality: nothing to pack")
- break
- elseif #t >= threshold then
- local one, two, rest = 0, 0, 0
- if pass == 1 then
- for k,v in pairs(c) do
- if v == 1 then
- one = one + 1
- elseif v == 2 then
- two = two + 1
- else
- rest = rest + 1
- end
- end
+ if dp == 0 or dp < 0 then
+ -- no negative depths and no negative depths, nil == 0
else
- for k,v in pairs(cc) do
- if v >20 then
- rest = rest + 1
- elseif v >10 then
- two = two + 1
- else
- one = one + 1
- end
- end
- data.tables = tt
+ d.depth = dp
end
- logs.report("load otf","pack quality: pass %s, %s packed, 1-10:%s, 11-20:%s, rest:%s (criterium: %s)", pass, one+two+rest, one, two, rest, criterium)
- else
- logs.report("load otf","pack quality: pass 1, %s packed, aborting pack (threshold: %s)", #t, threshold)
- break
end
end
end
end
-function otf.enhance.unpack(data)
- if data then
- local t = data.tables
- if t then
- for k, v in pairs(data.glyphs) do
- local tv = t[v.boundingbox] if tv then v.boundingbox = tv end
- local l = v.lookups
- if l then
- for k,v in pairs(l) do
- for i=1,#v do
- local tv = t[v[i]] if tv then v[i] = tv end
- end
- end
- end
- local a = v.anchors
- if a then
- for k,v in pairs(a) do
- if k == "baselig" then
- for kk, vv in pairs(v) do
- for kkk=1,#vv do
- local tv = t[vv[kkk]] if tv then vv[kkk] = tv end
- end
- end
- else
- for kk, vv in pairs(v) do
- local tv = t[vv] if tv then v[kk] = tv end
- end
- end
- end
- end
+function otf.show_feature_order(otfdata,filename)
+ local sequences = otfdata.luatex.sequences
+ if sequences and #sequences > 0 then
+ if trace_loading then
+ logs.report("otf check","font %s has %s sequences",filename,#sequences)
+ logs.report("otf check"," ")
+ end
+ for nos=1,#sequences do
+ local sequence = sequences[nos]
+ local typ = sequence.type or "no-type"
+ local name = sequence.name or "no-name"
+ local subtables = sequence.subtables or { "no-subtables" }
+ local features = sequence.features
+ if trace_loading then
+ logs.report("otf check","%3i %-15s %-20s [%s]",nos,name,typ,concat(subtables,","))
end
- if data.lookups then
- for k, v in pairs(data.lookups) do
- local r = v.rules
- if r then
- for kk, vv in pairs(r) do
- local l = vv.lookups
- if l then
- local tv = t[l] if tv then vv.lookups = tv end
- end
- local c = vv.coverage
- if c then
- local cc = c.before if cc then local tv = t[cc] if tv then c.before = tv end end
- cc = c.after if cc then local tv = t[cc] if tv then c.after = tv end end
- cc = c.current if cc then local tv = t[cc] if tv then c.current = tv end end
- end
+ if features then
+ for feature, scripts in next, features do
+ local tt = { }
+ for script, languages in next, scripts do
+ local ttt = { }
+ for language, _ in next, languages do
+ ttt[#ttt+1] = language
end
+ tt[#tt+1] = format("[%s: %s]",script,concat(ttt," "))
end
- end
- end
- if data.luatex then
- local li = data.luatex.ignore_flags
- if li then
- for k, v in pairs(li) do
- local tv = t[v] if tv then li[k] = tv end
+ if trace_loading then
+ logs.report("otf check"," %s: %s",feature,concat(tt," "))
end
end
end
- data.tables = nil
end
+ if trace_loading then
+ logs.report("otf check","\n")
+ end
+ elseif trace_loading then
+ logs.report("otf check","font %s has no sequences",filename)
end
end
-- todo: normalize, design_size => designsize
-function otf.enhance.analyze(data,filename)
- local t = {
---~ filename = file.basename(filename),
- filename = filename,
- version = otf.version,
- creator = "context mkiv",
- unicodes = otf.analyze_unicodes(data),
- gposfeatures = otf.analyze_features(data.gpos),
- gsubfeatures = otf.analyze_features(data.gsub),
- marks = otf.analyze_class(data,'mark'),
- }
- t.subtables, t.name_to_type, t.internals, t.always_valid, t.ignore_flags, t.ctx_always = otf.analyze_subtables(data)
- data.luatex = t
+otf.enhancers["prepare luatex tables"] = function(data,filename)
+ data.luatex = data.luatex or { }
+ local luatex = data.luatex
+ luatex.filename = filename
+ luatex.version = otf.version
+ luatex.creator = "context mkiv"
end
-do
- -- original string parser: 0.109, lpeg parser: 0.036 seconds for Adobe-CNS1-4.cidmap
- --
- -- 18964 18964 (leader)
- -- 0 /.notdef
- -- 1..95 0020
- -- 99 3000
-
- local number = lpeg.C(lpeg.R("09","af","AF")^1)
- local space = lpeg.S(" \n\r\t")
- local spaces = space^0
- local period = lpeg.P(".")
- local periods = period * period
- local name = lpeg.P("/") * lpeg.C((1-space)^1)
-
- local unicodes, names = { }, {}
-
- local function do_one(a,b)
- unicodes[tonumber(a)] = tonumber(b,16)
+otf.enhancers["cleanup aat"] = function(data,filename)
+ if otf.cleanup_aat then
end
- local function do_range(a,b,c)
- c = tonumber(c,16)
- for i=tonumber(a),tonumber(b) do
- unicodes[i] = c
- c = c + 1
- end
- end
- local function do_name(a,b)
- names[tonumber(a)] = b
- end
-
- local grammar = lpeg.P { "start",
- start = number * spaces * number * lpeg.V("series"),
- series = (spaces * (lpeg.V("one") + lpeg.V("range") + lpeg.V("named")) )^1,
- one = (number * spaces * number) / do_one,
- range = (number * periods * number * spaces * number) / do_range,
- named = (number * spaces * name) / do_name
- }
+end
- function otf.load_cidmap(filename) -- lpeg
- local data = io.loaddata(filename)
- if data then
- unicodes, names = { }, { }
- grammar:match(data)
- local supplement, registry, ordering = filename:match("^(.-)%-(.-)%-()%.(.-)$")
- return {
- supplement = supplement,
- registry = registry,
- ordering = ordering,
- filename = filename,
- unicodes = unicodes,
- names = names
- }
- else
- return nil
+local function analyze_features(g, features)
+ if g then
+ local t, done = { }, { }
+ for k=1,#g do
+ local f = features or g[k].features
+ if f then
+ for k=1,#f do
+ -- scripts and tag
+ local tag = f[k].tag
+ if not done[tag] then
+ t[#t+1] = tag
+ done[tag] = true
+ end
+ end
+ end
+ end
+ if #t > 0 then
+ return t
end
end
-
+ return nil
end
-otf.cidmaps = { }
-otf.cidmax = 10
+otf.enhancers["analyse features"] = function(data,filename)
+ -- local luatex = data.luatex
+ -- luatex.gposfeatures = analyze_features(data.gpos)
+ -- luatex.gsubfeatures = analyze_features(data.gsub)
+end
-function otf.cidmap(registry,ordering,supplement)
- -- cf Arthur R. we can safely scan upwards since cids are downward compatible
- local template = "%s-%s-%s.cidmap"
- local supplement = tonumber(supplement)
- logs.report("load otf","needed cidmap, registry: %s, ordering: %s, supplement: %s",registry,ordering,supplement)
- local function locate(registry,ordering,supplement)
- local filename = format(template,registry,ordering,supplement)
- local cidmap = otf.cidmaps[filename]
- if not cidmap then
- logs.report("load otf","checking cidmap, registry: %s, ordering: %s, supplement: %s, filename: %s",registry,ordering,supplement,filename)
- local fullname = input.find_file(filename,'cid') or ""
- if fullname ~= "" then
- cidmap = otf.load_cidmap(fullname)
- if cidmap then
- logs.report("load otf","using cidmap file %s",filename)
- otf.cidmaps[filename] = cidmap
- return cidmap
+otf.enhancers["rehash features"] = function(data,filename)
+ local features = { }
+ data.luatex.features = features
+ for k, what in next, otf.glists do
+ local dw = data[what]
+ if dw then
+ local f = { }
+ features[what] = f
+ for i=1,#dw do
+ local d= dw[i]
+ local dfeatures = d.features
+ if dfeatures then
+ for i=1,#dfeatures do
+ local df = dfeatures[i]
+ local tag = strip(lower(df.tag))
+ local ft = f[tag] if not ft then ft = {} f[tag] = ft end
+ local dscripts = df.scripts
+ for script, languages in next, dscripts do
+ script = strip(lower(script))
+ local fts = ft[script] if not fts then fts = {} ft[script] = fts end
+ for i=1,#languages do
+ fts[strip(lower(languages[i]))] = true
+ end
+ end
+ end
end
end
end
- return cidmap
end
- local cidmap = locate(registry,ordering,supplement)
- if not cidmap then
- local cidnum = nil
- -- next highest (alternatively we could start high)
- if supplement < otf.cidmax then
- for supplement=supplement+1,otf.cidmax do
- local c = locate(registry,ordering,supplement)
- if c then
- cidmap, cidnum = c, supplement
- break
- end
+end
+
+otf.enhancers["analyse anchors"] = function(data,filename)
+ local classes = data.anchor_classes
+ local luatex = data.luatex
+ local anchor_to_lookup, lookup_to_anchor = { }, { }
+ luatex.anchor_to_lookup, luatex.lookup_to_anchor = anchor_to_lookup, lookup_to_anchor
+ if classes then
+ for c=1,#classes do
+ local class = classes[c]
+ local anchor = class.name
+ local lookups = class.lookup
+ if type(lookups) ~= "table" then
+ lookups = { lookups }
+ end
+ local a = anchor_to_lookup[anchor]
+ if not a then a = { } anchor_to_lookup[anchor] = a end
+ for l=1,#lookups do
+ local lookup = lookups[l]
+ local l = lookup_to_anchor[lookup]
+ if not l then l = { } lookup_to_anchor[lookup] = l end
+ l[anchor] = true
+ a[lookup] = true
end
end
- -- next lowest (least worse fit)
- if not cidmap and supplement > 0 then
- for supplement=supplement-1,0,-1 do
- local c = locate(registry,ordering,supplement)
- if c then
- cidmap, cidnum = c, supplement
- break
- end
- end
+ end
+end
+
+otf.enhancers["analyse marks"] = function(data,filename)
+ local glyphs = data.glyphs
+ local marks = { }
+ data.luatex.marks = marks
+ for unicode, index in next, data.luatex.indices do
+ local glyph = glyphs[index]
+ if glyph.class == "mark" then
+ marks[unicode] = true
end
- -- prevent further lookups
- if cidmap and cidnum > 0 then
- for s=0,cidnum-1 do
- filename = format(template,registry,ordering,s)
- if not otf.cidmaps[filename] then
- otf.cidmaps[filename] = cidmap -- copy of ref
+ end
+end
+
+local other = lpeg.C((1 - lpeg.S("_."))^0)
+local ligsplitter = lpeg.Ct(other * (lpeg.P("_") * other)^0)
+
+--~ print(splitter:match("this"))
+--~ print(splitter:match("this.that"))
+--~ print(splitter:match("such_so_more"))
+--~ print(splitter:match("such_so_more.that"))
+
+otf.enhancers["analyse unicodes"] = function(data,filename)
+ local unicodes = data.luatex.unicodes
+ -- we need to move this code
+ unicodes['space'] = unicodes['space'] or 32 -- handly later on
+ unicodes['hyphen'] = unicodes['hyphen'] or 45 -- handly later on
+ unicodes['zwj'] = unicodes['zwj'] or zwj -- handly later on
+ unicodes['zwnj'] = unicodes['zwnj'] or zwnj -- handly later on
+ -- the tounicode mapping is sparse and only needed for alternatives
+ local tounicode, originals, ns, nl, private, unknown = { }, { }, 0, 0, fonts.private, format("%04X",utfbyte("?"))
+ data.luatex.tounicode, data.luatex.originals = tounicode, originals
+ for index, glyph in next, data.glyphs do
+ local name, unic = glyph.name, glyph.unicode or -1 -- play safe
+ if unic == -1 or unic >= private or (unic >= 0xE000 and unic <= 0xF8FF) or unic == 0xFFFE or unic == 0xFFFF then
+ -- a.whatever or a_b_c.whatever or a_b_c
+ local split = ligsplitter:match(name)
+ if #split == 0 then
+ -- skip
+ elseif #split == 1 then
+ local u = unicodes[split[1]]
+ if u then
+ if type(u) == "table" then
+ u = u[1]
+ end
+ if u < 0x10000 then
+ originals[index], tounicode[index] = u, format("%04X",u)
+ else
+ originals[index], tounicode[index] = u, format("%04X%04X",u/1024+0xD800,u%1024+0xDC00)
+ end
+ ns = ns + 1
+ else
+ originals[index], tounicode[index] = 0xFFFD, "FFFD"
+ end
+ else
+ local as = { }
+ for l=1,#split do
+ local u = unicodes[split[l]]
+ if not u then
+ as[l], split[l] = 0xFFFD, "FFFD"
+ else
+ if type(u) == "table" then
+ u = u[1]
+ end
+ if u < 0x10000 then
+ as[l], split[l] = u, format("%04X",u)
+ else
+ as[l], split[l] = u, format("%04X%04X",u/1024+0xD800,u%1024+0xDC00)
+ end
+ end
+ end
+ split = concat(split)
+ if split ~= "" then
+ originals[index], tounicode[index] = as, split
+ nl = nl + 1
+ else
+ originals[index], tounicode[index] = 0xFFFD, "FFFD"
end
end
end
end
- return cidmap
+ if trace_loading and (ns > 0 or nl > 0) then
+ logs.report("load otf","enhance: %s tounicode entries added (%s ligatures)",nl+ns, ns)
+ end
end
---~ ["cidinfo"]={
---~ ["ordering"]="Japan1",
---~ ["registry"]="Adobe",
---~ ["supplement"]=6,
---~ ["version"]=6,
---~ },
+otf.enhancers["analyse subtables"] = function(data,filename)
+ data.luatex = data.luatex or { }
+ local luatex = data.luatex
+ local sequences = { }
+ local lookups = { }
+ luatex.sequences = sequences
+ luatex.lookups = lookups
+ for _, g in next, { data.gsub, data.gpos } do
+ for k=1,#g do
+ local gk = g[k]
-function otf.enhance.before(data,filename)
- local private = fonts.private
+local typ = gk.type
+if typ == "gsub_contextchain" or typ == "gpos_contextchain" then
+ gk.chain = 1
+elseif typ == "gsub_reversecontextchain" or typ == "gpos_reversecontextchain" then
+ gk.chain = -1
+else
+ gk.chain = 0
+end
+
+ local features = gk.features
+ if features then
+ sequences[#sequences+1] = gk
+ -- scripts, tag, ismac
+ local t = { }
+ for f=1,#features do
+ local feature = features[f]
+ local hash = { }
+ -- only script and langs matter
+ for s, languages in next, feature.scripts do
+ s = lower(s)
+ local h = hash[s]
+ if not h then h = { } hash[s] = h end
+ for l=1,#languages do
+ h[strip(lower(languages[l]))] = true
+ end
+ end
+ t[feature.tag] = hash
+ end
+ gk.features = t
+ else
+ lookups[gk.name] = gk
+ gk.name = nil
+ end
+ local subtables = gk.subtables
+ if subtables then
+ local t = { }
+ for s=1,#subtables do
+ local subtable = subtables[s]
+ local name = subtable.name
+ t[#t+1] = name
+ end
+ gk.subtables = t
+ end
+ local flags = gk.flags
+ if flags then
+ gk.flags = { -- forcing false packs nicer
+ (flags.ignorecombiningmarks and "mark") or false,
+ (flags.ignoreligatures and "ligature") or false,
+ (flags.ignorebaseglyphs and "base") or false,
+ flags.r2l or false
+ }
+ end
+ end
+ end
+end
+
+otf.enhancers["merge cid fonts"] = function(data,filename)
+ -- we can also move the names to data.luatex.names which might
+ -- save us some more memory (at the cost of harder tracing)
if data.subfonts and table.is_empty(data.glyphs) then
local cidinfo = data.cidinfo
local verbose = fonts.verbose
if cidinfo.registry then
- local cidmap = otf.cidmap(cidinfo.registry,cidinfo.ordering,cidinfo.supplement)
+ local cidmap = fonts.cid.getmap and fonts.cid.getmap(cidinfo.registry,cidinfo.ordering,cidinfo.supplement)
if cidmap then
local glyphs, uni_to_int, int_to_uni, nofnames, nofunicodes = { }, { }, { }, 0, 0
local unicodes, names = cidmap.unicodes, cidmap.names
- for n, subfont in pairs(data.subfonts) do
- for index, g in pairs(subfont.glyphs) do
+ for n, subfont in next, data.subfonts do
+ for index, g in next, subfont.glyphs do
if not next(g) then
-- dummy entry
else
@@ -1288,90 +624,143 @@ function otf.enhance.before(data,filename)
g.boundingbox = g.boundingbox -- or zerobox
g.name = g.name or name or "unknown"
if unicode then
--- g.unicode = unicode
uni_to_int[unicode] = index
int_to_uni[index] = unicode
nofunicodes = nofunicodes + 1
+ g.unicode = unicode
elseif name then
--- g.unicode = -1
nofnames = nofnames + 1
+ g.unicode = -1
end
glyphs[index] = g
end
end
subfont.glyphs = nil
end
- logs.report("load otf","cid font remapped, %s unicode points, %s symbolic names, %s glyphs",nofunicodes, nofnames, nofunicodes+nofnames)
+ if trace_loading then
+ logs.report("load otf","cid font remapped, %s unicode points, %s symbolic names, %s glyphs",nofunicodes, nofnames, nofunicodes+nofnames)
+ end
data.glyphs = glyphs
data.map = data.map or { }
data.map.map = uni_to_int
data.map.backmap = int_to_uni
- else
+ elseif trace_loading then
logs.report("load otf","unable to remap cid font, missing cid file for %s",filename)
end
- else
+ elseif trace_loading then
logs.report("load otf","font %s has no glyphs",filename)
end
end
- if data.map then
- local uni_to_int = data.map.map -- [unic] = slot
- local int_to_uni = data.map.backmap -- { [0|1] = unic, ... }
- for index, glyph in pairs(data.glyphs) do
- if glyph.name then
--- local unic = glyph.unicode or glyph.unicodeenc or -1
-local unic = int_to_uni[index] or -1
- if index > 0 and (unic == -1 or unic >= 0x110000) then
- while uni_to_int[private] do
- private = private + 1
- end
- uni_to_int[private] = index
- int_to_uni[index] = private
--- glyph.unicode = private
- if fonts.trace then
- logs.report("load otf","enhance: glyph %s at index %s is moved to private unicode slot %s",glyph.name,index,private)
- end
+end
+
+otf.enhancers["prepare unicode"] = function(data,filename)
+ local luatex = data.luatex
+ if not luatex then luatex = { } data.luatex = luatex end
+ local indices, unicodes, multiples, internals = { }, { }, { }, { }
+ local glyphs = data.glyphs
+ local mapmap = data.map
+ if not mapmap then
+ logs.report("load otf","no map in %s",filename)
+ mapmap = { }
+ data.map = { map = mapmap }
+ elseif not mapmap.map then
+ logs.report("load otf","no unicode map in %s",filename)
+ mapmap = { }
+ data.map.map = mapmap
+ else
+ mapmap = mapmap.map
+ end
+ local criterium = fonts.private
+ local private = fonts.private
+ for index, glyph in next, glyphs do
+ if index > 0 then
+ local name = glyph.name
+ if name then
+ local unicode = glyph.unicode
+ if unicode == -1 or unicode >= criterium then
+ glyph.unicode = private
+ indices[private] = index
+ unicodes[name] = private
+ internals[index] = true
+ if trace_private then
+ logs.report("load otf","enhance: glyph %s at index U+%04X is moved to private unicode slot U+%04X",name,index,private)
+ end
+ private = private + 1
else
- glyph.unicode = unic -- safeguard for older version
+ indices[unicode] = index
+ unicodes[name] = unicode
end
end
end
- local n = 0
- for k,v in pairs(int_to_uni) do
- if v == -1 or v >= 0x110000 then
- int_to_uni[k], n = nil, n+1
- end
- end
- if fonts.trace then
- logs.report("load otf","enhance: %s entries removed from map.backmap",n)
- end
- local n = 0
- for k,v in pairs(uni_to_int) do
- if k == -1 or k >= 0x110000 then
- uni_to_int[k], n = nil, n+1
+ end
+ -- beware: the indeces table is used to initialize the tfm table
+ for unicode, index in next, mapmap do
+ if not internals[index] then
+ local name = glyphs[index].name
+ if name then
+ local un = unicodes[name]
+ if not un then
+ unicodes[name] = unicode -- or 0
+ elseif type(un) == "number" then
+ if un ~= unicode then
+ multiples[#multiples+1] = name
+ unicodes[name] = { un, unicode }
+ indices[unicode] = index
+ end
+ else
+ local ok = false
+ for u=1,#un do
+ if un[u] == unicode then
+ ok = true
+ break
+ end
+ end
+ if not ok then
+ multiples[#multiples+1] = name
+ un[#un+1] = unicode
+ indices[unicode] = index
+ end
+ end
end
end
- if fonts.trace then
- logs.report("load otf","enhance: %s entries removed from map.mapmap",n)
+ end
+ if trace_loading then
+ if #multiples > 0 then
+ logs.report("load otf","%s glyph are reused: %s",#multiples, concat(multiples," "))
+ else
+ logs.report("load otf","no glyph are reused")
end
- else
- data.map = { map = {}, backmap = {} }
end
- if data.ttf_tables then
- for _, v in ipairs(data.ttf_tables) do
- if v.data then v.data = "deleted" end
+ luatex.indices = indices
+ luatex.unicodes = unicodes
+ luatex.private = private
+end
+
+otf.enhancers["cleanup ttf tables"] = function(data,filename)
+ local ttf_tables = data.ttf_tables
+ if ttf_tables then
+ for k=1,#ttf_tables do
+ if ttf_tables[k].data then ttf_tables[k].data = "deleted" end
end
end
- table.compact(data.glyphs)
+ data.ttf_tab_saved = nil
+end
+
+otf.enhancers["compact glyphs"] = function(data,filename)
+ table.compact(data.glyphs) -- needed?
if data.subfonts then
- for _, subfont in pairs(data.subfonts) do
- table.compact(subfont.glyphs)
+ for _, subfont in next, data.subfonts do
+ table.compact(subfont.glyphs) -- needed?
end
end
+end
+
+otf.enhancers["reverse coverage"] = function(data,filename)
-- we prefer the before lookups in a normal order
if data.lookups then
- for _, v in pairs(data.lookups) do
+ for _, v in next, data.lookups do
if v.rules then
- for _, vv in pairs(v.rules) do
+ for _, vv in next, v.rules do
local c = vv.coverage
if c and c.before then
c.before = table.reverse(c.before)
@@ -1382,91 +771,239 @@ local unic = int_to_uni[index] or -1
end
end
-function otf.enhance.after(data,filename) -- to be split
- if otf.enhance.add_kerns then
- local glyphs, mapmap, unicodes = data.glyphs, data.map.map, data.luatex.unicodes
- local mkdone = false
- for index, glyph in pairs(data.glyphs) do
- if glyph.kerns then
- local mykerns = { } -- unicode indexed !
- for k,v in pairs(glyph.kerns) do
- local vc, vo, vl = v.char, v.off, v.lookup
- if vc and vo and vl then -- brrr, wrong! we miss the non unicode ones
- local uvc = unicodes[vc]
- if not uvc then
- logs.report("load otf","problems with unicode %s of kern %s at glyph %s",vc,k,index)
- else
- local mkl = mykerns[vl]
- if not mkl then
- mkl = { }
- mykerns[v.lookup] = mkl
+otf.enhancers["check italic correction"] = function(data,filename)
+ local glyphs = data.glyphs
+ local ok = false
+ for index, glyph in next, glyphs do
+ local ic = glyph.italic_correction
+ if ic then
+ if ic ~= 0 then
+ glyph.italic = ic
+ end
+ glyph.italic_correction = nil
+ ok = true
+ end
+ end
+ -- we can use this to avoid calculations
+ otf.tables.valid_fields[#otf.tables.valid_fields+1] = "has_italic"
+ data.has_italic = true
+end
+
+otf.enhancers["check math"] = function(data,filename)
+ if data.math then
+ -- we move the math stuff into a math subtable because we then can
+ -- test faster in the tfm copy
+ local glyphs = data.glyphs
+ local unicodes = data.luatex.unicodes
+ for index, glyph in next, glyphs do
+ local mk = glyph.mathkern
+ local hv = glyph.horiz_variants
+ local vv = glyph.vert_variants
+ if mk or hv or vv then
+ local math = { }
+ glyph.math = math
+ if mk then
+ for k, v in next, mk do
+ if not next(v) then
+ mk[k] = nil
+ end
+ end
+ math.kerns = mk
+ glyph.mathkern = nil
+ end
+ if hv then
+ math.horiz_variants = hv.variants
+ local p = hv.parts
+ if p then
+ if #p>0 then
+ for i=1,#p do
+ local pi = p[i]
+ pi.glyph = unicodes[pi.component] or 0
end
- if type(uvc) == "table" then
- for u=1,#uvc do
- mkl[uvc[u]] = vo
- end
- else
- mkl[uvc] = vo
+ math.horiz_parts = p
+ end
+ end
+ local ic = hv.italic_correction
+ if ic and ic ~= 0 then
+ math.horiz_italic_correction = ic
+ end
+ glyph.horiz_variants = nil
+ end
+ if vv then
+ local uc = unicodes[index]
+ math.vert_variants = vv.variants
+ local p = vv.parts
+ if p then
+ if #p>0 then
+ for i=1,#p do
+ local pi = p[i]
+ pi.glyph = unicodes[pi.component] or 0
end
+ math.vert_parts = p
end
end
+ local ic = vv.italic_correction
+ if ic and ic ~= 0 then
+ math.vert_italic_correction = ic
+ end
+ glyph.vert_variants = nil
+ end
+ local ic = glyph.italic_correction
+ if ic then
+ if ic ~= 0 then
+ math.italic_correction = ic
+ end
+ glyph.italic_correction = nil
end
- glyph.mykerns = mykerns
- glyph.kerns = nil -- saves space and time
- mkdone = true
end
end
- if mkdone then
- logs.report("load otf", "replacing 'kerns' tables by 'mykerns' tables")
+ end
+end
+
+otf.enhancers["share widths"] = function(data,filename)
+ local glyphs = data.glyphs
+ local widths = { }
+ for index, glyph in next, glyphs do
+ local width = glyph.width
+ widths[width] = (widths[width] or 0) + 1
+ end
+ -- share width for cjk fonts
+ local wd, most = 0, 1
+ for k,v in next, widths do
+ if v > most then
+ wd, most = k, v
end
- if data.gpos then
- for _, gpos in ipairs(data.gpos) do
- if gpos.subtables then
- for _, subtable in ipairs(gpos.subtables) do
- local kernclass = subtable.kernclass
- if kernclass then
- for _, kcl in ipairs(kernclass) do
- local firsts, seconds, offsets, lookup = kcl.firsts, kcl.seconds, kcl.offsets, kcl.lookup
+ end
+ if most > 1000 then
+ if trace_loading then
+ logs.report("load otf", "most common width: %s (%s times), sharing (cjk font)",wd,most)
+ end
+ for k, v in next, glyphs do
+ if v.width == wd then
+ v.width = nil
+ end
+ end
+ data.luatex.defaultwidth = wd
+ end
+end
+
+-- kern: ttf has a table with kerns
+
+otf.enhancers["reorganize kerns"] = function(data,filename)
+ local glyphs, mapmap, unicodes = data.glyphs, data.luatex.indices, data.luatex.unicodes
+ local mkdone = false
+ for index, glyph in next, data.glyphs do
+ if glyph.kerns then
+ local mykerns = { }
+ for k,v in next, glyph.kerns do
+ local vc, vo, vl = v.char, v.off, v.lookup
+ if vc and vo and vl then -- brrr, wrong! we miss the non unicode ones
+ local uvc = unicodes[vc]
+ if not uvc then
+ if trace_loading then
+ logs.report("load otf","problems with unicode %s of kern %s at glyph %s",vc,k,index)
+ end
+ else
+ if type(vl) ~= "table" then
+ vl = { vl }
+ end
+ for l=1,#vl do
+ local vll = vl[l]
+ local mkl = mykerns[vll]
+ if not mkl then
+ mkl = { }
+ mykerns[vll] = mkl
+ end
+ if type(uvc) == "table" then
+ for u=1,#uvc do
+ mkl[uvc[u]] = vo
+ end
+ else
+ mkl[uvc] = vo
+ end
+ end
+ end
+ end
+ end
+ glyph.mykerns = mykerns
+ glyph.kerns = nil -- saves space and time
+ mkdone = true
+ end
+ end
+ if trace_loading and mkdone then
+ logs.report("load otf", "replacing 'kerns' tables by 'mykerns' tables")
+ end
+ if data.kerns then
+ if trace_loading then
+ logs.report("load otf", "removing global 'kern' table")
+ end
+ data.kerns = nil
+ end
+ local dgpos = data.gpos
+ if dgpos then
+ for gp=1,#dgpos do
+ local gpos = dgpos[gp]
+ local subtables = gpos.subtables
+ if subtables then
+ for s=1,#subtables do
+ local subtable = subtables[s]
+ local kernclass = subtable.kernclass -- name is inconsistent with anchor_classes
+ if kernclass then
+ for k=1,#kernclass do
+ local kcl = kernclass[k]
+ local firsts, seconds, offsets, lookups = kcl.firsts, kcl.seconds, kcl.offsets, kcl.lookup -- singular
+ if type(lookups) ~= "table" then
+ lookups = { lookups }
+ end
+ for l=1,#lookups do
+ local lookup = lookups[l]
local maxfirsts, maxseconds = getn(firsts), getn(seconds)
- logs.report("load otf", "adding kernclass %s with %s times %s pairs)",lookup, maxfirsts, maxseconds)
- for fk, fv in pairs(firsts) do
- for first in fv:gmatch("[^ ]+") do
+ if trace_loading then
+ logs.report("load otf", "adding kernclass %s with %s times %s pairs",lookup, maxfirsts, maxseconds)
+ end
+ for fk, fv in next, firsts do
+ for first in gmatch(fv,"[^ ]+") do
local first_unicode = unicodes[first]
if type(first_unicode) == "number" then
first_unicode = { first_unicode }
end
for f=1,#first_unicode do
local glyph = glyphs[mapmap[first_unicode[f]]]
- local mykerns = glyph.mykerns
- if not mykerns then
- mykerns = { } -- unicode indexed !
- glyph.mykerns = mykerns
- end
- local lookupkerns = mykerns[lookup]
- if not lookupkerns then
- lookupkerns = { }
- mykerns[lookup] = lookupkerns
- end
- for sk, sv in pairs(seconds) do
- local offset = offsets[(fk-1) * maxseconds + sk]
- for second in sv:gmatch("[^ ]+") do
- local second_unicode = unicodes[second]
- if type(second_unicode) == "number" then
- lookupkerns[second_unicode] = offset
- else
- for s=1,#second_unicode do
- lookupkerns[second_unicode[s]] = offset
+ if glyph then
+ local mykerns = glyph.mykerns
+ if not mykerns then
+ mykerns = { } -- unicode indexed !
+ glyph.mykerns = mykerns
+ end
+ local lookupkerns = mykerns[lookup]
+ if not lookupkerns then
+ lookupkerns = { }
+ mykerns[lookup] = lookupkerns
+ end
+ for sk, sv in next, seconds do
+ local offset = offsets[(fk-1) * maxseconds + sk]
+ --~ local offset = offsets[sk] -- (fk-1) * maxseconds + sk]
+ for second in gmatch(sv,"[^ ]+") do
+ local second_unicode = unicodes[second]
+ if type(second_unicode) == "number" then
+ lookupkerns[second_unicode] = offset
+ else
+ for s=1,#second_unicode do
+ lookupkerns[second_unicode[s]] = offset
+ end
end
end
end
+ elseif trace_loading then
+ logs.report("load otf", "no glyph data for U+%04X", first_unicode[f])
end
end
end
end
end
- subtable.comment = "The kernclass table is merged into mykerns in the indexed glyph tables."
- subtable.kernclass = { }
end
+ subtable.comment = "The kernclass table is merged into mykerns in the indexed glyph tables."
+ subtable.kernclass = { }
end
end
end
@@ -1474,21 +1011,28 @@ function otf.enhance.after(data,filename) -- to be split
end
end
-function otf.enhance.strip(data)
+otf.enhancers["strip not needed data"] = function(data,filename)
local verbose = fonts.verbose
- local int_to_uni = data.map.backmap
- for k, v in pairs(data.glyphs) do
+ local int_to_uni = data.luatex.unicodes
+ for k, v in next, data.glyphs do
local d = v.dependents
if d then v.dependents = nil end
+ local a = v.altuni
+ if a then v.altuni = nil end
if verbose then
local code = int_to_uni[k]
+ -- looks like this is done twice ... bug?
if code then
local vu = v.unicode
if not vu then
v.unicode = code
elseif type(vu) == "table" then
- vu[#bu+1] = code
- else
+ if vu[#vu] == code then
+ -- weird
+ else
+ vu[#vu+1] = code
+ end
+ elseif vu ~= code then
v.unicode = { vu, code }
end
end
@@ -1498,19 +1042,39 @@ function otf.enhance.strip(data)
end
end
data.luatex.comment = "Glyph tables have their original index. When present, mykern tables are indexed by unicode."
- data.luatex.indices = data.map.map -- needed for shared glyphs
data.map = nil
- data.names = nil
+ data.names = nil -- funny names for editors
data.glyphcnt = nil
data.glyphmax = nil
+ if true then
+ data.gpos = nil
+ data.gsub = nil
+ data.anchor_classes = nil
+ end
+end
+
+otf.enhancers["migrate metadata"] = function(data,filename)
+ local global_fields = otf.tables.global_fields
+ local metadata = { }
+ for k,v in next, data do
+ if not global_fields[k] then
+ metadata[k] = v
+ data[k] = nil
+ end
+ end
+ data.metadata = metadata
+ -- goodies
+ local pfminfo = data.pfminfo
+ metadata.isfixedpitch = metadata.isfixedpitch or (pfminfo.panose and pfminfo.panose["proportion"] == "Monospaced")
+ metadata.charwidth = pfminfo and pfminfo.avgwidth
end
-function otf.enhance.flatten(data,filename) -- to be split
- logs.report("load otf", "flattening 'specifications' tables")
- for k, v in pairs(data.glyphs) do
+otf.enhancers["flatten glyph lookups"] = function(data,filename)
+ for k, v in next, data.glyphs do
if v.lookups then
- for kk, vv in pairs(v.lookups) do
- for kkk, vvv in ipairs(vv) do
+ for kk, vv in next, v.lookups do
+ for kkk=1,#vv do
+ local vvv = vv[kkk]
local s = vvv.specification
if s then
local t = vvv.type
@@ -1523,27 +1087,29 @@ function otf.enhance.flatten(data,filename) -- to be split
elseif t == "multiple" then
vv[kkk] = { "multiple", s.components }
elseif t == "position" then
- vv[kkk] = { "position", s.x or 0, s.y or 0, s.h or 0, s.v or 0 }
+ vv[kkk] = { "position", { s.x or 0, s.y or 0, s.h or 0, s.v or 0 } }
elseif t == "pair" then
local one, two, paired = s.offsets[1], s.offsets[2], s.paired or ""
if one then
if two then
- vv[kkk] = { "pair", paired, one.x or 0, one.y or 0, one.h or 0, one.v or 0, two.x or 0, two.y or 0, two.h or 0, two.v or 0 }
+ vv[kkk] = { "pair", paired, { one.x or 0, one.y or 0, one.h or 0, one.v or 0 }, { two.x or 0, two.y or 0, two.h or 0, two.v or 0 } }
else
- vv[kkk] = { "pair", paired, one.x or 0, one.y or 0, one.h or 0 }
+ vv[kkk] = { "pair", paired, { one.x or 0, one.y or 0, one.h or 0, one.v or 0 } }
end
else
if two then
- vv[kkk] = { "pair", paired, 0, 0, 0, 0, two.x or 0, two.y or 0, two.h or 0, two.v or 0 }
+ vv[kkk] = { "pair", paired, { }, { two.x or 0, two.y or 0, two.h or 0, two.v or 0} } -- maybe nil instead of { }
else
vv[kkk] = { "pair", paired }
end
end
else
- logs.report("load otf", "flattening needed, warn Hans and/or Taco")
- for a, b in pairs(s) do
- if vvv[a] then
- logs.report("load otf", "flattening conflict, warn Hans and/or Taco")
+ if trace_loading then
+ logs.report("load otf", "flattening needed, report to context list")
+ end
+ for a, b in next, s do
+ if trace_loading and vvv[a] then
+ logs.report("load otf", "flattening conflict, report to context list")
end
vvv[a] = b
end
@@ -1554,15 +1120,18 @@ function otf.enhance.flatten(data,filename) -- to be split
end
end
end
- logs.report("load otf", "flattening 'anchor' tables")
- for k, v in pairs(data.glyphs) do
+end
+
+otf.enhancers["flatten anchor tables"] = function(data,filename)
+ for k, v in next, data.glyphs do
if v.anchors then
- for kk, vv in pairs(v.anchors) do
- for kkk, vvv in pairs(vv) do
- if vvv.x or vvv.y then -- kkk == "centry"
+ for kk, vv in next, v.anchors do
+ for kkk, vvv in next, vv do
+ if vvv.x or vvv.y then
vv[kkk] = { vvv.x or 0, vvv.y or 0 }
else
- for kkkk, vvvv in ipairs(vvv) do
+ for kkkk=1,#vvv do
+ local vvvv = vvv[kkkk]
vvv[kkkk] = { vvvv.x or 0, vvvv.y or 0 }
end
end
@@ -1570,14 +1139,24 @@ function otf.enhance.flatten(data,filename) -- to be split
end
end
end
- for _, tag in pairs({"gpos","gsub"}) do
+end
+
+otf.enhancers["flatten feature tables"] = function(data,filename)
+ -- is this needed? do we still use them at all?
+ for _, tag in next, otf.glists do
if data[tag] then
- logs.report("load otf", "flattening '%s' tables", tag)
- for k, v in pairs(data[tag]) do
- if v.features then
- for kk, vv in ipairs(v.features) do
+ if trace_loading then
+ logs.report("load otf", "flattening %s table", tag)
+ end
+ for k, v in next, data[tag] do
+ local features = v.features
+ if features then
+ for kk=1,#features do
+ local vv = features[kk]
local t = { }
- for kkk, vvv in ipairs(vv.scripts) do
+ local scripts = vv.scripts
+ for kkk=1,#scripts do
+ local vvv = scripts[kkk]
t[vvv.script] = vvv.langs
end
vv.scripts = t
@@ -1588,12 +1167,12 @@ function otf.enhance.flatten(data,filename) -- to be split
end
end
-otf.enhance.patches = { }
+otf.enhancers.patches = otf.enhancers.patches or { }
-function otf.enhance.patch(data,filename)
- local basename = file.basename(filename:lower())
- for pattern, action in pairs(otf.enhance.patches) do
- if basename:find(pattern) then
+otf.enhancers["patch bugs"] = function(data,filename)
+ local basename = file.basename(lower(filename))
+ for pattern, action in next, otf.enhancers.patches do
+ if find(basename,pattern) then
action(data,filename)
end
end
@@ -1601,160 +1180,8 @@ end
-- tex features
-function otf.enhance.enrich(data,filename)
- -- later
-end
-
-function otf.analyze_class(data,class)
- local classes = { }
- local glyphs = data.glyphs
- for unicode, index in pairs(data.map.map) do
- local glyph = glyphs[index]
- if glyph.class == class then
- classes[unicode] = true
- end
- end
- return classes
-end
-
-function otf.analyze_subtables(data)
- local subtables, name_to_type, internals, always_valid, ignore_flags, ctx_always = { }, { }, { }, { }, { }, { }
- local function collect(g)
- if g then
- for k,v in ipairs(g) do
- if v.features then
- local ignored = { false, false, false }
- local flags = v.flags
- if flags.ignorecombiningmarks then ignored[1] = 'mark' end
- if flags.ignorebasechars then ignored[2] = 'base' end
- if flags.ignoreligatures then ignored[3] = 'ligature' end
- if v.subtables then
- local type = v.type
- for _, feature in ipairs(v.features) do
- local ft = feature.tag:lower()
- subtables[ft] = subtables[ft] or { }
- ctx_always[ft] = v.always
- for script, languages in pairs(feature.scripts) do
- script = script:lower()
- script = script:strip()
- sft = subtables[ft]
- local sfts = sft[script]
- if not sfts then
- sfts = { }
- sft[script] = sfts
- end
- for _, language in ipairs(languages) do
- language = language:lower()
- language = language:strip()
- local sftsl = sfts[language]
- if not sftsl then
- sftsl = sfts[language] or { }
- sfts[language] = sftsl
- end
- local lookups, valid = sftsl.lookups or { }, sftsl.valid or { }
- for n, subtable in ipairs(v.subtables) do
- local stl = subtable.name
- if stl then
- lookups[#lookups+1] = stl
- valid[stl] = true
- name_to_type[stl] = type
- ignore_flags[stl] = ignored
- end
- end
- sftsl.lookups, sftsl.valid = lookups, valid
- end
- end
- end
- end
- else
- -- we have an internal feature, say ss_l_83 that resolves to
- -- subfeatures like ss_l_83_s which we find in the glyphs
- name_to_type[v.name] = v.type
- local lookups, valid = { }, { }
- for n, subtable in ipairs(v.subtables) do
- local stl = subtable.name
- if stl then
- lookups[#lookups+1] = stl
- valid[stl] = true
- always_valid[stl] = true
- end
- end
- internals[v.name] = {
- lookups = lookups,
- valid = valid
- }
- always_valid[v.name] = true -- bonus
- end
- end
- end
- end
- collect(data.gsub)
- collect(data.gpos)
- return subtables, name_to_type, internals, always_valid, ignore_flags, ctx_always
-end
-
-function otf.analyze_unicodes(data)
- local unicodes = { }
- local indices = data.map.map
- local glyphs = data.glyphs
- local multiples = { }
- for unicode, index in pairs(indices) do
- local name = glyphs[index].name
- if name then
- local un = unicodes[name]
- if not un then
- unicodes[name] = unicode -- or 0
- elseif type(un) == "number" then
- multiples[#multiples+1] = name
- unicodes[name] = { un, unicode }
- else
- un[#un+1] = unicode
- end
- end
- end
- if #multiples > 0 then
- logs.report("load otf","%s glyph are reused: %s",#multiples, concat(multiples," "))
- end
- unicodes['space'] = unicodes['space'] or 32 -- handly later on
- unicodes['hyphen'] = unicodes['hyphen'] or 45 -- handly later on
- return unicodes
-end
-
-function otf.analyze_features(g, features)
- if g then
- local t, done = { }, { }
- for k=1,#g do
- local f = features or g[k].features
- if f then
- for k=1,#f do
- -- scripts and tag
- local tag = f[k].tag
- if not done[tag] then
- t[#t+1] = tag
- done[tag] = true
- end
- end
- end
- end
- if #t > 0 then
- return t
- end
- end
- return nil
-end
-
-function otf.valid_subtable(otfdata,kind,script,language)
- local tk = otfdata.luatex.subtables[kind]
- if tk then
- local tks = tk[script] or tk.dflt
- if tks then
- local tksl = tks[language] or tks.dflt
- if tksl then
- return tksl.lookups
- end
- end
- end
- return false
+fonts.otf.enhancers["enrich with features"] = function(data,filename)
+ -- later, ctx only
end
function otf.features.register(name,default)
@@ -1762,75 +1189,70 @@ function otf.features.register(name,default)
otf.features.default[name] = default
end
-function otf.set_features(tfmdata) -- node and base, simple mapping
- local shared = tfmdata.shared
- local otfdata = shared.otfdata
- shared.features = fonts.define.check(shared.features,otf.features.default)
- local features = shared.features
- local trace = otf.trace_features or otf.trace_set_features
- if not tfmdata.language then tfmdata.language = 'dflt' end
- if not tfmdata.script then tfmdata.script = 'dflt' end
+function otf.set_features(tfmdata,features)
+ local processes = { }
if not table.is_empty(features) then
- local gposlist = otfdata.luatex.gposfeatures
- local gsublist = otfdata.luatex.gsubfeatures
- local mode = tfmdata.mode or fonts.mode
+ local lists = {
+ fonts.triggers,
+ fonts.processors,
+ fonts.manipulators,
+ }
+ local mode = tfmdata.mode or fonts.mode -- or features.mode
local initializers = fonts.initializers
local fi = initializers[mode]
- if fi then -- todo: delay initilization for mode 'node'
+ if fi then
local fiotf = fi.otf
if fiotf then
local done = { }
- local function initialize(list) -- using tex lig and kerning
+ for l=1,4 do
+ local list = lists[l]
if list then
for i=1,#list do
local f = list[i]
local value = features[f]
if value and fiotf[f] then -- brr
if not done[f] then -- so, we can move some to triggers
- if trace then
+ if trace_features then
logs.report("define otf","initializing feature %s to %s for mode %s for font %s",f,tostring(value),mode or 'unknown', tfmdata.fullname or 'unknown')
end
fiotf[f](tfmdata,value) -- can set mode (no need to pass otf)
mode = tfmdata.mode or fonts.mode -- keep this, mode can be set local !
- local fi = initializers[mode]
- fiotf = fi.otf
+ local im = initializers[mode]
+ if im then
+ fiotf = initializers[mode].otf
+ end
done[f] = true
end
end
end
end
end
- initialize(fonts.triggers)
- initialize(gsublist)
- initialize(gposlist)
- initialize(fonts.manipulators)
end
end
local fm = fonts.methods[mode]
if fm then
local fmotf = fm.otf
- local sp = shared.processors
if fmotf then
- local function register(list) -- node manipulations
+ for l=1,4 do
+ local list = lists[l]
if list then
for i=1,#list do
local f = list[i]
- if features[f] and fmotf[f] then -- brr
- if trace then
+ if fmotf[f] then -- brr
+ if trace_features then
logs.report("define otf","installing feature handler %s for mode %s for font %s",f,mode or 'unknown', tfmdata.fullname or 'unknown')
end
- sp[#sp+1] = fmotf[f]
+ processes[#processes+1] = fmotf[f]
end
end
end
end
- register(fonts.triggers)
- register(gsublist)
- register(gposlist)
- register(fonts.manipulators)
end
+ else
+ -- message
end
end
+ return processes, features
end
function otf.otf_to_tfm(specification)
@@ -1841,38 +1263,37 @@ function otf.otf_to_tfm(specification)
local features = specification.features.normal
local cache_id = specification.hash
local tfmdata = containers.read(tfm.cache(),cache_id)
+--~ print(cache_id)
if not tfmdata then
local otfdata = otf.load(filename,format,sub,features and features.featurefile)
if not table.is_empty(otfdata) then
- otf.add_dimensions(otfdata)
- if true then
- otfdata._shared_ = otfdata._shared_ or { -- aggressive sharing
- processes = { },
- lookuptable = { },
- featuredata = { },
- featurecache = { },
- }
- end
- tfmdata = otf.copy_to_tfm(otfdata)
+ otfdata.shared = otfdata.shared or {
+ featuredata = { },
+ anchorhash = { },
+ initialized = false,
+ }
+ tfmdata = otf.copy_to_tfm(otfdata,cache_id)
if not table.is_empty(tfmdata) then
tfmdata.unique = tfmdata.unique or { }
tfmdata.shared = tfmdata.shared or { } -- combine
local shared = tfmdata.shared
shared.otfdata = otfdata
- shared.features = features
- shared.processors = { }
+ shared.features = features -- default
shared.dynamics = { }
shared.processes = { }
- shared.lookuptable = { }
- shared.featuredata = { }
- shared.featurecache = { }
- if otfdata._shared_ then
- shared.processes = otfdata._shared_.processes
- shared.lookuptable = otfdata._shared_.lookuptable
- shared.featuredata = otfdata._shared_.featuredata
- shared.featurecache = otfdata._shared_.featurecache
- end
- otf.set_features(tfmdata)
+ shared.set_dynamics = otf.set_dynamics -- fast access and makes other modules independent
+ -- this will be done later anyway, but it's convenient to have
+ -- them already for fast access
+ tfmdata.luatex = otfdata.luatex
+ tfmdata.indices = otfdata.luatex.indices
+ tfmdata.unicodes = otfdata.luatex.unicodes
+ tfmdata.marks = otfdata.luatex.marks
+ tfmdata.originals = otfdata.luatex.originals
+ tfmdata.changed = { }
+ tfmdata.has_italic = otfdata.metadata.has_italic
+ if not tfmdata.language then tfmdata.language = 'dflt' end
+ if not tfmdata.script then tfmdata.script = 'dflt' end
+ shared.processes, shared.features = otf.set_features(tfmdata,fonts.define.check(features,otf.features.default))
end
end
containers.write(tfm.cache(),cache_id,tfmdata)
@@ -1880,108 +1301,106 @@ function otf.otf_to_tfm(specification)
return tfmdata
end
-function otf.features.prepare_base_kerns(tfmdata,kind,value) -- todo what kind of kerns, currently all
- if value then
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local unicodes = otfdata.luatex.unicodes -- names to unicodes
- local somevalid = otf.some_valid_feature(otfdata,kind,tfmdata.script,tfmdata.language)
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- for u, chr in pairs(characters) do
- -- hm, maybe just use descriptions, and why still index? font is already in
- -- unicode with private slots, so: d = glyphs[u] should work ok
- local d = glyphs[descriptions[u].index]
- if d then
- local dk = d.mykerns
- if dk then
- local t, done = chr.kerns or { }, false
- for lookup,kerns in pairs(dk) do
- if somevalid[lookup] then
- for k, v in pairs(kerns) do
- if v ~= 0 then
- t[k], done = v, true
+--~ {
+--~ ['boundingbox']={ 95, -458, 733, 1449 },
+--~ ['class']="base",
+--~ ['name']="braceleft",
+--~ ['unicode']=123,
+--~ ['vert_variants']={
+--~ ['italic_correction']=0,
+--~ ['parts']={
+--~ { ['component']="uni23A9", ['endConnectorLength']=1000, ['fullAdvance']=2546, ['is_extender']=0, ['startConnectorLength']=0, }, -- bot
+--~ { ['component']="uni23AA", ['endConnectorLength']=2500, ['fullAdvance']=2501, ['is_extender']=1, ['startConnectorLength']=2500, }, -- rep
+--~ { ['component']="uni23A8", ['endConnectorLength']=1000, ['fullAdvance']=4688, ['is_extender']=0, ['startConnectorLength']=1000, }, -- mid
+--~ { ['component']="uni23AA", ['endConnectorLength']=2500, ['fullAdvance']=2501, ['is_extender']=1, ['startConnectorLength']=2500, }, -- rep
+--~ { ['component']="uni23A7", ['endConnectorLength']=0, ['fullAdvance']=2546, ['is_extender']=0, ['startConnectorLength']=1000, }, -- top
+--~ },
+--~ ['variants']="braceleft braceleft.vsize1 braceleft.vsize2 braceleft.vsize3 braceleft.vsize4 braceleft.vsize5 braceleft.vsize6 braceleft.vsize7",
+--~ },
+--~ ['width']=793,
+--~ },
+
+-- the first version made a top/mid/not extensible table, now we just pass on the variants data
+-- and deal with it in the tfm scaler (there is no longer an extensible table anyway)
+
+-- we cannot share descriptions as virtual fonts might extend them (ok, we could
+-- use a cache with a hash
+
+function otf.copy_to_tfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many)
+ if data then
+ local glyphs, pfminfo, metadata = data.glyphs or { }, data.pfminfo or { }, data.metadata or { }
+ local luatex = data.luatex
+ local unicodes = luatex.unicodes -- names to unicodes
+ local indices = luatex.indices
+ local characters, parameters, math_parameters, descriptions = { }, { }, { }, { }
+ local tfm = {
+ characters = characters,
+ parameters = parameters,
+ math_parameters = math_parameters,
+ descriptions = descriptions,
+ indices = indices,
+ unicodes = unicodes,
+ }
+ -- indices maps from unicodes to indices
+ for u, i in next, indices do
+ characters[u] = { } -- we need this because for instance we add protruding info
+ descriptions[u] = glyphs[i]
+ end
+ -- math
+ if metadata.math then
+ -- parameters
+ for name, value in next, metadata.math do
+ math_parameters[name] = value
+ end
+ -- we could use a subset
+ for u, char in next, characters do
+ local d = descriptions[u]
+ local m = d.math
+ -- we have them shared because that packs nicer
+ -- we could prepare the variants and keep 'm in descriptions
+ if m then
+ local variants = m.horiz_variants
+ if variants then
+ local c = char
+ for n in variants:gmatch("[^ ]+") do
+ local un = unicodes[n]
+ if un and u ~= un then
+ c.next = un
+ c = characters[un]
+ end
+ end
+ c.horiz_variants = m.horiz_parts
+ else
+ local variants = m.vert_variants
+ if variants then
+ local c = char
+ for n in variants:gmatch("[^ ]+") do
+ local un = unicodes[n]
+ if un and u ~= un then
+ c.next = un
+ c = characters[un]
end
end
+ c.vert_variants = m.vert_parts
end
end
- if done then
- chr.kerns = t -- no empty assignments
- end
- else
- dk = d.kerns
- if dk then
- local t, done = chr.kerns or { }, false
- for _, v in pairs(dk) do
- if somevalid[v.lookup] then
- local k = unicodes[v.char]
- local o = v.off
- if type(k) == "number" then
- if k > 0 then
- t[k], done = o, true
- end
- else
- for i=1,#k do
- local ki = k[i]
- if ki > 0 then
- t[ki], done = o, true
- end
- end
- end
- end
- end
- if done then
- chr.kerns = t -- no empty assignments
- end
+ local kerns = m.kerns
+ if kerns then
+ char.mathkerns = kerns
end
end
end
end
- end
-end
-
-function otf.add_dimensions(data)
- if data then
- local force = otf.notdef
- for k, d in pairs(data.glyphs) do
- local bb, wd = d.boundingbox, d.width or 0
- if force and not d.name then
- d.name = ".notdef"
- end
- if wd ~= 0 and d.class == "mark" then
- d.width = -wd
- end
- if bb then
- local ht, dp = bb[4], -bb[2]
- if ht ~= 0 then d.height = ht end
- if dp ~= 0 then d.depth = dp end
- end
- d.index = k
- end
- end
-end
-
-function otf.copy_to_tfm(data) -- we can save a copy when we reorder the tma to unicode
- if data then
- local characters, parameters, descriptions = { }, { }, { }
- local tfm = { characters = characters, parameters = parameters, descriptions = descriptions }
- local luatex = data.luatex
- local indices = luatex.indices -- unicodes to indices
- local glyphs = data.glyphs
- for u, i in pairs(indices) do
- local d = glyphs[i]
- characters[u] = { } -- not needed
- descriptions[u] = d
- end
- local designsize = data.designsize or data.design_size or 100
+ -- end math
+ local designsize = metadata.designsize or metadata.design_size or 100
if designsize == 0 then
designsize = 100
end
local spaceunits = 500
- tfm.units = data.units_per_em or 1000
+ tfm.units = metadata.units_per_em or 1000
-- we need a runtime lookup because of running from cdrom or zip, brrr
- tfm.filename = input.findbinfile(data.luatex.filename,"") or data.luatex.filename
- tfm.fullname = data.fontname or data.fullname
+ tfm.filename = resolvers.findbinfile(luatex.filename,"") or luatex.filename
+ tfm.fullname = metadata.fontname or metadata.fullname
tfm.encodingbytes = 2
tfm.cidinfo = data.cidinfo
tfm.cidinfo.registry = tfm.cidinfo.registry or ""
@@ -1993,21 +1412,16 @@ function otf.copy_to_tfm(data) -- we can save a copy when we reorder the tma to
tfm.boundarychar = 65536
tfm.designsize = (designsize/10)*65536
tfm.spacer = "500 units"
- data.isfixedpitch = data.pfminfo and data.pfminfo.panose and data.pfminfo.panose["proportion"] == "Monospaced"
- data.charwidth = nil
- if data.pfminfo then
- data.charwidth = data.pfminfo.avgwidth
- end
local endash, emdash = 0x20, 0x2014 -- unicodes['space'], unicodes['emdash']
- if data.isfixedpitch then
+ if metadata.isfixedpitch then
if descriptions[endash] then
spaceunits, tfm.spacer = descriptions[endash].width, "space"
end
if not spaceunits and descriptions[emdash] then
spaceunits, tfm.spacer = descriptions[emdash].width, "emdash"
end
- if not spaceunits and data.charwidth then
- spaceunits, tfm.spacer = data.charwidth, "charwidth"
+ if not spaceunits and metadata.charwidth then
+ spaceunits, tfm.spacer = metadata.charwidth, "charwidth"
end
else
if descriptions[endash] then
@@ -2016,36 +1430,37 @@ function otf.copy_to_tfm(data) -- we can save a copy when we reorder the tma to
if not spaceunits and descriptions[emdash] then
spaceunits, tfm.spacer = descriptions[emdash].width/2, "emdash/2"
end
- if not spaceunits and data.charwidth then
- spaceunits, tfm.spacer = data.charwidth, "charwidth"
+ if not spaceunits and metadata.charwidth then
+ spaceunits, tfm.spacer = metadata.charwidth, "charwidth"
end
end
spaceunits = tonumber(spaceunits) or tfm.units/2 -- 500 -- brrr
parameters.slant = 0
- parameters.space = spaceunits
- parameters.space_stretch = tfm.units/2 -- 500
- parameters.space_shrink = 2*tfm.units/3 -- 333
- parameters.x_height = 4*tfm.units/5 -- 400
+ parameters.space = spaceunits -- 3.333 (cmr10)
+ parameters.space_stretch = tfm.units/2 -- 500 -- 1.666 (cmr10)
+ parameters.space_shrink = 1*tfm.units/3 -- 333 -- 1.111 (cmr10)
+ parameters.x_height = 2*tfm.units/5 -- 400
parameters.quad = tfm.units -- 1000
- parameters.extra_space = 0
if spaceunits < 2*tfm.units/5 then
-- todo: warning
end
- tfm.italicangle = data.italicangle
- tfm.ascender = math.abs(data.ascent or 0)
- tfm.descender = math.abs(data.descent or 0)
- if data.italicangle then -- maybe also in afm _
- parameters.slant = parameters.slant - math.round(math.tan(data.italicangle*math.pi/180))
+ local italicangle = metadata.italicangle
+ tfm.ascender = math.abs(metadata.ascent or 0)
+ tfm.descender = math.abs(metadata.descent or 0)
+ if italicangle then -- maybe also in afm _
+ tfm.italicangle = italicangle
+ parameters.slant = parameters.slant - math.round(math.tan(italicangle*math.pi/180))
end
- if data.isfixedpitch then
+ if metadata.isfixedpitch then
parameters.space_stretch = 0
parameters.space_shrink = 0
elseif otf.syncspace then --
parameters.space_stretch = spaceunits/2
parameters.space_shrink = spaceunits/3
end
- if data.pfminfo and data.pfminfo.os2_xheight and data.pfminfo.os2_xheight > 0 then
- parameters.x_height = data.pfminfo.os2_xheight
+ parameters.extra_space = parameters.space_shrink -- 1.111 (cmr10)
+ if pfminfo.os2_xheight and pfminfo.os2_xheight > 0 then
+ parameters.x_height = pfminfo.os2_xheight
else
local x = 0x78 -- unicodes['x']
if x then
@@ -2062,23 +1477,55 @@ function otf.copy_to_tfm(data) -- we can save a copy when we reorder the tma to
end
end
+otf.features.register('mathsize')
+
function tfm.read_from_open_type(specification)
local tfmtable = otf.otf_to_tfm(specification)
if tfmtable then
+ local otfdata = tfmtable.shared.otfdata
tfmtable.name = specification.name
tfmtable.sub = specification.sub
- tfmtable = tfm.scale(tfmtable, specification.size)
+ local s = specification.size
+ local m = otfdata.metadata.math
+ if m then
+ local f = specification.features
+ if f then
+ local f = f.normal
+ if f and f.mathsize then
+ local mathsize = specification.mathsize or 0
+ if mathsize == 2 then
+ local p = m.ScriptPercentScaleDown
+ if p then
+ local ps = p * specification.textsize / 100
+ if trace_math then
+ logs.report("define font","asked script size: %s, used: %s (%2.2f %%)",s,ps,(ps/s)*100)
+ end
+ s = ps
+ end
+ elseif mathsize == 3 then
+ local p = m.ScriptScriptPercentScaleDown
+ if p then
+ local ps = p * specification.textsize / 100
+ if trace_math then
+ logs.report("define font","asked scriptscript size: %s, used: %s (%2.2f %%)",s,ps,(ps/s)*100)
+ end
+ s = ps
+ end
+ end
+ end
+ end
+ end
+ tfmtable = tfm.scale(tfmtable,s)
-- here we resolve the name; file can be relocated, so this info is not in the cache
- local otfdata = tfmtable.shared.otfdata
local filename = (otfdata and otfdata.luatex and otfdata.luatex.filename) or specification.filename
if not filename then
-- try to locate anyway and set otfdata.luatex.filename
end
if filename then
tfmtable.encodingbytes = 2
- tfmtable.filename = input.findbinfile(filename,"") or filename
- tfmtable.fullname = otfdata.fontname or otfdata.fullname
- local order = otfdata and otfdata.order2
+ tfmtable.filename = resolvers.findbinfile(filename,"") or filename
+ tfmtable.fullname = otfdata.metadata.fontname or otfdata.metadata.fullname
+ local order = otfdata and otfdata.metadata.order2
if order == 0 then
tfmtable.format = 'opentype'
elseif order == 1 then
@@ -2092,3295 +1539,3 @@ function tfm.read_from_open_type(specification)
end
return tfmtable
end
-
-function otf.analyze_only(otfdata)
- local analyze = otf.analyze_features
- return analyze(otfdata.gpos), analyze(otfdata.gsub)
-end
-
-local a_to_script = { }
-local a_to_language = { }
-
-do
-
- local context_setups = fonts.define.specify.context_setups
- local context_numbers = fonts.define.specify.context_numbers
-
- function otf.set_dynamics(tfmdata,attribute,features) --currently experimental and slow / hackery
- local shared = tfmdata.shared
- if shared then
- local dynamics = shared.dynamics
- if dynamics then
- features = features or context_setups[context_numbers[attribute]]
- if features then
- local script = features.script or 'dflt'
- local language = features.language or 'dflt'
- local ds = dynamics[script]
- if not ds then
- ds = { }
- dynamics[script] = ds
- end
- local dsl = ds[language]
- if not dsl then
- dsl = { }
- ds[language] = dsl
- end
- local dsla = dsl[attribute]
- if dsla then
- return dsla
- else
- a_to_script [attribute] = script
- a_to_language[attribute] = language
- dsla = { }
- local otfdata = shared.otfdata
- local methods = fonts.methods.node.otf
- local initializers = fonts.initializers.node.otf
- local gposfeatures, gsubfeatures = otf.analyze_only(otfdata,features)
- local default = otf.features.default
- local function register(list)
- if list then
- for i=1,#list do
- local f = list[i]
- local value = features[f] or default[f]
- if value then
- local i, m = initializers[f], methods[f]
- if i then
- i(tfmdata,value)
- end
- if m then
- dsla[#dsla+1] = m
- end
- end
- end
- end
- end
- register(fonts.triggers)
- register(gsubfeatures)
- register(gposfeatures)
- dynamics[script][language][attribute] = dsla
- return dsla
- end
- end
- end
- end
- return { } -- todo: false
- end
-
-end
-
--- scripts
-
-otf.default_language = 'latn'
-otf.default_script = 'dflt'
-
-function otf.valid_feature(otfdata,kind,script,language) -- return hash is faster
- local luatex = otfdata.luatex
- if luatex.ctx_always[kind] then
- script, language = 'dflt', 'dflt'
- else
- script = script or otf.default_script
- language = language or otf.default_language
- end
- script, language = script:lower(), language:lower() -- will go away, we will lowercase values
- local ft = luatex.subtables[kind]
- local st = ft[script] or ft.dflt
- local lt = st and (st[language] or st.dflt)
- return false, luatex.always_valid, lt.valid
-end
-
-function otf.some_valid_feature(otfdata,kind,script,language)
- local luatex = otfdata.luatex
- if luatex.ctx_always[kind] then
- script, language = 'dflt', 'dflt'
- else
- script = script or otf.default_script
- language = language or otf.default_language
- script, language = script:lower(), language:lower() -- will go away, we will lowercase values
- end
- local t = luatex.subtables[kind]
- if t then
- local ts = t[script] or t.dflt
- if ts then
- local tsl = ts[language] or ts.dflt
- return (tsl and tsl.valid) or { }
- end
- end
- return { }
-end
-
-function otf.features.aux.resolve_ligatures(tfmdata,ligatures,kind)
- local otfdata = tfmdata.shared.otfdata
- local unicodes = otfdata.luatex.unicodes
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local changed = tfmdata.changed or { }
- local done = { }
- kind = kind or "unknown"
- local trace = otf.trace_features
- while true do
- local ok = false
- for k,v in pairs(ligatures) do
- local lig = v[1]
- if not done[lig] then
- local ligs = split_at_space:match(lig)
- if #ligs == 2 then
- local uc = v[2]
- local c, f, s = characters[uc], ligs[1], ligs[2]
---~ local uf, us = unicodes[f], unicodes[s]
-
-local uft, ust = unicodes[f], unicodes[s]
-if not uft or not ust then
- logs.report("define otf","%s: unicode problem with ligature (%s->%s=%s->%s+%s->%s)",kind,descriptions[uc].name or "?",uc,f,uft or "?",s,ust or "?")
- -- some kind of error
-else
- if type(uft) == "number" then uft = { uft } end
- if type(ust) == "number" then ust = { ust } end
- for ufi=1,#uft do
- local uf = uft[ufi]
- for usi=1,#ust do
- local us = ust[usi]
-
- if changed[uf] or changed[us] then
- if trace then
- logs.report("define otf","%s: %s (%s) + %s (%s) ignored",kind,f,uf,s,us)
- end
- else
- local first, second = characters[uf], us
- if first and second then
- local t = first.ligatures
- if not t then
- t = { }
- first.ligatures = t
- end
- local uuc = unicodes[descriptions[uc].name]
- if type(uuc) == "number" then
- t[second] = { type = 0, char = uuc }
- else
- t[second] = { type = 0, char = uuc[1] }
- end
- if trace then
- logs.report("define otf","%s: %s (%s) + %s (%s) = %s (%s)",kind,f,uf,s,us,descriptions[uc].name,unicodes[descriptions[uc].name])
- end
- end
- end
-
- end
- end
-end
-
- ok, done[lig] = true, descriptions[uc].name
- end
- end
- end
- if ok then
- for d,n in pairs(done) do
- local pattern = "^(" .. d .. ") "
- for k,v in pairs(ligatures) do
- v[1] = v[1]:gsub(pattern, function(str)
- return n .. " "
- end)
- end
- end
- else
- break
- end
- end
-end
-
-function otf.features.prepare_base_substitutions(tfmdata,kind,value) -- we can share some code with the node features
- if value then
- local ligatures = { }
- local otfdata = tfmdata.shared.otfdata
- local unicodes = otfdata.luatex.unicodes
- local trace = otf.trace_features
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local somevalid = otf.some_valid_feature(otfdata,kind,tfmdata.script,tfmdata.language)
- if not table.is_empty(somevalid) then
- tfmdata.changed = tfmdata.changed or { }
- local changed = tfmdata.changed
- local glyphs = otfdata.glyphs
- for k,c in pairs(characters) do
- local o = glyphs[descriptions[k].index]
- if o and o.lookups then
- for lookup,ps in pairs(o.lookups) do
- if somevalid[lookup] then
- for i=1,#ps do
- local p = ps[i]
- local t = p[1]
- if t == 'substitution' then
- local pv = p[2] -- p.variant
- if pv then
- local upv = unicodes[pv]
- if upv then
- if type(upv) == "number" then
- if characters[upv] then
- if trace then
- logs.report("define otf","%s: %s (%s) => %s (%s)",kind,descriptions[k].name,k,descriptions[upv].name,upv)
- end
- characters[k] = characters[upv]
- descriptions[k] = descriptions[upv]
- changed[k] = true
- end
- else
- for i=1,#upv do
- local upv = upv[i]
- if characters[upv] then
- if trace then
- logs.report("define otf","%s: %s (%s) => %s (%s)",kind,descriptions[k].name,k,descriptions[upv].name,upv)
- end
- characters[k] = characters[upv]
- descriptions[k] = descriptions[upv]
- changed[k] = true
- end
- end
- end
- end
- end
- elseif t == 'alternate' then
- local pc = p[2] -- p.components
- if pc then
- pc = pa.components:match("([^ ]+)") -- todo: selector
- if pc then
- local upc = unicodes[pc]
- if upc then
- if type(upc) == "number" then
- if chars[upc] then
- if trace then
- logs.report("define otf","%s: %s (%s) => %s (%s)",kind,descriptions[k].name,k,descriptions[upc].name,upc)
- end
- characters[k] = characters[upc]
- descriptions[k] = descriptions[upc]
- changed[k] = true
- end
- else
- for i=1,#upc do
- local upc = upc[i]
- if chars[upc] then
- if trace then
- logs.report("define otf","%s: %s (%s) => %s (%s)",kind,descriptions[k].name,k,descriptions[upc].name,upc)
- end
- characters[k] = characters[upc]
- descriptions[k] = descriptions[upc]
- changed[k] = true
- end
- end
- end
- end
- end
- end
- elseif t == 'ligature' and not changed[k] then
- local pc = p[2]
- if pc then
- if trace then
- logs.report("define otf","%s: %s => %s (%s)",kind,pc,descriptions[k].name,k)
- end
- ligatures[#ligatures+1] = { pc, k }
- end
- end
- end
- end
- end
- end
- end
- otf.features.aux.resolve_ligatures(tfmdata,ligatures,kind)
- end
- else
- tfmdata.ligatures = tfmdata.ligatures or { }
- end
-end
-
-function fonts.initializers.base.otf.liga(tfm,value) otf.features.prepare_base_substitutions(tfm,'liga',value) end
-function fonts.initializers.base.otf.dlig(tfm,value) otf.features.prepare_base_substitutions(tfm,'dlig',value) end
-function fonts.initializers.base.otf.rlig(tfm,value) otf.features.prepare_base_substitutions(tfm,'rlig',value) end
-function fonts.initializers.base.otf.hlig(tfm,value) otf.features.prepare_base_substitutions(tfm,'hlig',value) end
-function fonts.initializers.base.otf.pnum(tfm,value) otf.features.prepare_base_substitutions(tfm,'pnum',value) end
-function fonts.initializers.base.otf.onum(tfm,value) otf.features.prepare_base_substitutions(tfm,'onum',value) end
-function fonts.initializers.base.otf.tnum(tfm,value) otf.features.prepare_base_substitutions(tfm,'tnum',value) end
-function fonts.initializers.base.otf.lnum(tfm,value) otf.features.prepare_base_substitutions(tfm,'lnum',value) end
-function fonts.initializers.base.otf.zero(tfm,value) otf.features.prepare_base_substitutions(tfm,'zero',value) end
-function fonts.initializers.base.otf.smcp(tfm,value) otf.features.prepare_base_substitutions(tfm,'smcp',value) end
-function fonts.initializers.base.otf.cpsp(tfm,value) otf.features.prepare_base_substitutions(tfm,'cpsp',value) end
-function fonts.initializers.base.otf.c2sc(tfm,value) otf.features.prepare_base_substitutions(tfm,'c2sc',value) end
-function fonts.initializers.base.otf.ornm(tfm,value) otf.features.prepare_base_substitutions(tfm,'ornm',value) end
-function fonts.initializers.base.otf.aalt(tfm,value) otf.features.prepare_base_substitutions(tfm,'aalt',value) end
-
-function fonts.initializers.base.otf.hwid(tfm,value) otf.features.prepare_base_substitutions(tfm,'hwid',value) end
-function fonts.initializers.base.otf.fwid(tfm,value) otf.features.prepare_base_substitutions(tfm,'fwid',value) end
-
--- Here comes the real thing ... node processing! The next session prepares
--- things. The main features (unchained by rules) have their own caches,
--- while the private ones cache locally.
-
-do
-
- otf.features.prepare = { }
-
- local falsetable = { false, false, false }
-
- function otf.features.prepare.feature(tfmdata,kind,value)
- if value then
- local language, script = tfmdata.language or "dflt", tfmdata.script or "dflt"
- local shared = tfmdata.shared
- local otfdata = shared.otfdata
- local lookuptable = otf.valid_subtable(otfdata,kind,script,language)
- if lookuptable then
- local fullkind = kind .. script .. language
- if not shared.lookuptable [fullkind] then
- --~ print(tfmdata,file.basename(tfmdata.fullname or ""),kind,script,language,lookuptable,fullkind)
- local processes = { }
- -- featuredata and featurecache are indexed by lookup so we can share them
- shared.featuredata [kind] = shared.featuredata [kind] or { }
- shared.featurecache[kind] = shared.featurecache[kind] or false -- signal
- shared.lookuptable [fullkind] = lookuptable
- shared.processes [fullkind] = processes
- local luatex = otfdata.luatex
- local types = luatex.name_to_type
- local flags = luatex.ignore_flags
- local preparers = otf.features.prepare
- local process = otf.features.process
- for i=1,#lookuptable do
- local lookupname = lookuptable[i]
- local lookuptype = types[lookupname]
- local prepare = preparers[lookuptype]
- if prepare then
- local processdata = prepare(tfmdata,kind,lookupname)
- if processdata then
- local processflags = flags[lookupname] or falsetable --- share false table
- -- local chain = (lookuptype == "gsub_contextchain") or (lookuptype == "gpos_contextchain")
- local chain = lookuptype:find("context") ~= nil
- processes[#processes+1] = { process[lookuptype], lookupname, processdata, processflags, chain }
- end
- end
- end
- end
- end
- end
- end
-
- -- helper: todo, we don't need to store non local ones for chains so we can pass the
- -- validator as parameter
-
- function otf.features.collect_ligatures(tfmdata,kind) -- ligs are spread all over the place
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes -- names to unicode
- local indices = luatex.indices -- unicode to index
- local trace = otf.trace_features
- local ligatures = { }
- local function collect(lookup,unicode,glyph,ps)
- for i=1,#ps do
- local p = ps[i]
- if p[1] == 'ligature' then
- if trace then
- logs.report("define otf","feature %s lookup %s ligature %s => %s",kind,lookup,p[2],glyph.name)
- end
- local t = ligatures[lookup]
- if not t then
- t = { }
- ligatures[lookup] = t
- end
- -- this table is kind of special:
- -- unicode -> tree of names/indices -> unicode
- -- this way we can handle multiple unicode to one glyph cases
- local first = true
- for s in p[2]:gmatch("[^ ]+") do
- if first then
- local u = unicodes[s]
- if not u then
- logs.report("define otf","feature %s lookup %s ligature %s => %s ignored due to invalid unicode",kind,lookup,p[2],glyph.name)
- elseif type(u) == "number" then
- if not t[u] then
- t[u] = { { } }
- end
- t = t[u]
- else
- local tt = t
- local tu
- for i=1,#u do
- local u = u[i]
- if i==1 then
- if not t[u] then
- t[u] = { { } }
- end
- tu = t[u]
- t = tu
- else
- if not t[u] then
- tt[u] = tu
- end
- end
- end
- end
- first = false
- else
- -- beware, we mix unicodes and indices, we can comment these
- -- lines when testing, see (*lig*)
- s = unicodes[s]
- if type(s) == "number" then
- s = indices[s]
- else
- s = indices[s[1]]
- end
- -- maybe we will introduce a names table some day
- local t1 = t[1]
- if not t1[s] then
- t1[s] = { { } }
- end
- t = t1[s]
- end
- end
- t[2] = unicode
- end
- end
- end
- local forced, always, okay = otf.valid_feature(otfdata,kind,tfmdata.script,tfmdata.language)
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local lookups = glyph.lookups
- if lookups then
- if forced then
- for lookup, ps in pairs(lookups) do collect(lookup,unicode,glyph,ps) end
- elseif okay then
- for lookup, ps in pairs(lookups) do if always[lookup] or okay[lookup] then collect(lookup,unicode,glyph,ps) end end
- else
- for lookup, ps in pairs(lookups) do if always[lookup] then collect(lookup,unicode,glyph,ps) end end
- end
- end
- end
- return ligatures
- end
-
- -- gsub_single -> done
- -- gsub_multiple -> done
- -- gsub_alternate -> done
- -- gsub_ligature -> done
- -- gsub_context -> todo
- -- gsub_contextchain -> done
- -- gsub_reversecontextchain -> todo
-
- -- we used to share code in the following functions but that was relatively
- -- due to extensive calls to functions (easily hundreds of thousands per
- -- document)
-
- function otf.features.prepare.gsub_single(tfmdata,kind,lookupname)
- local featuredata = tfmdata.shared.featuredata[kind]
- local substitutions = featuredata[lookupname]
- if not substitutions then
- substitutions = { }
- featuredata[lookupname] = substitutions
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes -- names to unicode
- local indices = luatex.indices -- unicode to index
- local trace = otf.trace_features
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local lookups = glyph.lookups
- if lookups then
- for lookup,ps in pairs(lookups) do
- if lookup == lookupname then
- for i=1,#ps do
- local p = ps[i]
- if p[1] == 'substitution' then
- local old, new = unicode, unicodes[p[2]]
- if type(new) == "table" then
- new = new[1]
- end
- substitutions[old] = new
- if trace then
- logs.report("define otf","%s:%s substitution %s => %s",kind,lookupname,old,new)
- end
- end
- end
- end
- end
- end
- end
- end
- return substitutions
- end
-
- function otf.features.prepare.gsub_multiple(tfmdata,kind,lookupname)
- local featuredata = tfmdata.shared.featuredata[kind]
- local substitutions = featuredata[lookupname]
- if not substitutions then
- substitutions = { }
- featuredata[lookupname] = substitutions
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes -- names to unicode
- local indices = luatex.indices -- unicode to index
- local trace = otf.trace_features
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local lookups = glyph.lookups
- if lookups then
- for lookup,ps in pairs(lookups) do
- if lookup == lookupname then
- for i=1,#ps do
- local p = ps[i]
- if p[1] == 'multiple' then
- local old, new = unicode, { }
- substitutions[old] = new
- for pc in p[2]:gmatch("[^ ]+") do
- local upc = unicodes[pc]
- if type(upc) == "number" then
- new[#new+1] = upc
- else
- new[#new+1] = upc[1]
- end
- end
- if trace then
- logs.report("define otf","%s:%s multiple %s => %s",kind,lookupname,old,concat(new," "))
- end
- end
- end
- end
- end
- end
- end
- end
- return substitutions
- end
-
- function otf.features.prepare.gsub_alternate(tfmdata,kind,lookupname)
- -- todo: configurable preference list
- local featuredata = tfmdata.shared.featuredata[kind]
- local substitutions = featuredata[lookupname]
- if not substitutions then
- featuredata[lookupname] = { }
- substitutions = featuredata[lookupname]
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes -- names to unicode
- local indices = luatex.indices -- unicode to index
- local trace = otf.trace_features
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local lookups = glyph.lookups
- if lookups then
- for lookup,ps in pairs(lookups) do
- if lookup == lookupname then
- for i=1,#ps do
- local p = ps[i]
- if p[1] == 'alternate' then
- local old = unicode
- local t = { }
- for pc in p[2]:gmatch("[^ ]+") do
- local upc = unicodes[pc]
- if type(upc) == "number" then
- t[#t+1] = upc
- else
- t[#t+1] = upc[1]
- end
- end
- substitutions[old] = t
- if trace then
- logs.report("define otf","%s:%s alternate %s => %s",kind,lookupname,old,concat(substitutions,"|"))
- end
- end
- end
- end
- end
- end
- end
- end
- return substitutions
- end
-
- function otf.features.prepare.gsub_ligature(tfmdata,kind,lookupname)
- -- we collect them for all lookups, this saves loops, we only use the
- -- lookupname for testing, we need to check if this leads to redundant
- -- collections
- local ligatures = tfmdata.shared.featuredata[kind]
- if not ligatures[lookupname] then
- ligatures = otf.features.collect_ligatures(tfmdata,kind)
- tfmdata.shared.featuredata[kind] = ligatures
- end
- return ligatures[lookupname]
- end
-
- function otf.features.prepare.contextchain(tfmdata,kind,lookupname)
- local featuredata = tfmdata.shared.featuredata[kind]
- local contexts = featuredata[lookupname]
- if not contexts then
- contexts = { }
- featuredata[lookupname] = contexts
- local characters = tfmdata.characters
- local otfdata = tfmdata.shared.otfdata
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes
- local internals = luatex.internals
- local flags = luatex.ignore_flags
- local types = luatex.name_to_type
- local cache = luatex.covers
- if not cache then
- cache = { }
- luatex.covers = cache
- end
- local function uncover(covers,result)
- -- lpeg hardly faster (.005 sec on mk)
- for n=1,#covers do
- local c = covers[n]
- local cc = cache[c]
- if not cc then
- local t = { }
- for s in c:gmatch("[^ ]+") do
- local us = unicodes[s]
- if type(us) == "number" then
- t[us] = true
- else
- for i=1,#us do
- t[us[i]] = true
- end
- end
- end
- cache[c] = t
- result[#result+1] = t
- else
- result[#result+1] = cc
- end
- end
- end
- local lookupdata = otfdata.lookups[lookupname]
- if not lookupdata then
- logs.report("otf process","missing lookupdata table %s",lookupname)
- elseif lookupdata.rules then
- local rules = lookupdata.rules
- local center_match = otf.center_match
- for nofrules=1,#rules do
- local rule = rules[nofrules]
- local coverage = rule.coverage
- if coverage and coverage.current then
- local current, before, after, sequence = coverage.current, coverage.before, coverage.after, { }
- if before then
- uncover(before,sequence)
- end
- local start = #sequence + 1
- uncover(current,sequence)
- local stop = #sequence
- if after then
- uncover(after,sequence)
- end
- if sequence[1] then
- local lookups, lookuptype = rule.lookups, 'self'
- -- for the moment only lookup index 1
- if lookups then
- if #lookups > 1 then
- logs.report("otf process","WARNING: more than one lookup in rule")
- end
- lookuptype = types[lookups[1]]
- end
- -- this may be wrong; we cannot copy inside the for loop (out of memory with hz);
- -- so we may end up with a different usage of sequence in the chainproc handlers
- sequence = table.copy(sequence)
- -- we trigger on the first character in current
- for unic, _ in pairs(sequence[start]) do
- local t = contexts[unic]
- if not t then
- contexts[unic] = { lookups={}, flags=flags[lookupname] }
- t = contexts[unic].lookups
- end
- t[#t+1] = { nofrules, lookuptype, sequence, start, stop, lookups }
- end
- end
- end
- end
- end
- end
- return contexts
- end
-
- otf.features.prepare.gsub_context = otf.features.prepare.contextchain
- otf.features.prepare.gsub_contextchain = otf.features.prepare.contextchain
- otf.features.prepare.gsub_reversecontextchain = otf.features.prepare.contextchain
-
- -- ruled->lookup=ks_latn_l_27_c_4 => internal[ls_l_84] => valid[ls_l_84_s]
-
- -- gpos_mark2base -> done
- -- gpos_mark2ligature -> done
- -- gpos_mark2mark -> done
- -- gpos_single -> not done
- -- gpos_pair -> not done
- -- gpos_cursive -> not done
- -- gpos_context -> not done
- -- gpos_reversecontextchain -> not done
-
- function otf.features.prepare.anchors(tfmdata,kind,lookupname) -- tracing
- local featuredata = tfmdata.shared.featuredata[kind]
- local anchors = featuredata[lookupname]
- if not anchors then
- anchors = { }
- featuredata[lookupname] = anchors
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes
- local indices = luatex.indices
- local validanchors = { }
- local trace = otf.trace_features
- local classes = otfdata.anchor_classes
- if classes then
- for k=1,#classes do
- local class = classes[k]
- if class.lookup == lookupname then
- if trace then
- logs.report("define otf","%s:%s anchor -> %s",kind,lookupname,class.name)
- end
- validanchors[class.name] = true
- end
- end
- end
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local oanchor = glyph.anchors
- if oanchor then
- local t, ok = { }, false
- for type, anchors in pairs(oanchor) do -- types
- local tt = false
- for name, anchor in pairs(anchors) do
- if validanchors[name] then
- if not tt then
- tt = { [name] = anchor }
- t[type] = tt
- ok = true
- else
- tt[name] = anchor
- end
- end
- end
- end
- if ok then
- anchors[unicode] = t
- end
- end
- end
- end
---~ if kind == "mkmk" then print(lookupname,table.serialize(anchors)) end
- return anchors
- end
-
- otf.features.prepare.gpos_mark2base = otf.features.prepare.anchors
- otf.features.prepare.gpos_mark2ligature = otf.features.prepare.anchors
- otf.features.prepare.gpos_mark2mark = otf.features.prepare.anchors
- otf.features.prepare.gpos_cursive = otf.features.prepare.anchors
- otf.features.prepare.gpos_context = otf.features.prepare.contextchain
- otf.features.prepare.gpos_contextchain = otf.features.prepare.contextchain
-
- function otf.features.prepare.gpos_single(tfmdata,kind,lookupname)
- logs.report("otf define","gpos_single not yet supported")
- end
-
- -- ["kerns"]={ { ["char"]="ytilde", ["lookup"]="pp_l_1_s", ["off"]=-83, ...
- -- ["mykerns"] = { ["pp_l_1_s"] = { [67] = -28, ...
-
- function otf.features.prepare.gpos_pair(tfmdata,kind,lookupname)
- local featuredata = tfmdata.shared.featuredata[kind]
- local kerns = featuredata[lookupname]
- if not kerns then
- local trace = otf.trace_features
- featuredata[lookupname] = { }
- kerns = featuredata[lookupname]
- local otfdata = tfmdata.shared.otfdata
- local glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- local unicodes = luatex.unicodes
- local indices = luatex.indices
- -- ff has isolated kerns in a separate table
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local list = glyph.mykerns
- if list then
- local omk = list[lookupname]
- if omk then
- local krn = kerns[unicode]
- for other, off in pairs(omk) do
- if not krn then
- krn = { }
- kerns[unicode] = krn
- end
- krn[other] = off
- if trace then
- logs.report("define otf","feature %s kern pair %s - %s",kind,unicode,other)
- end
- end
- end
- else
- list = glyph.kerns
- if list then
- local krn
- for ok=1,#list do
- local k = list[ok]
- if k.lookup == lookupname then
- local char = k.char
- if char then
- if not krn then
- krn = kerns[unicode]
- if not krn then
- krn = { }
- kerns[unicode] = krn
- end
- end
- local second = unicodes[char]
- local off = k.off
- if type(second) == "number" then
- krn[second] = off
- if trace then
- logs.report("define otf","feature %s kern pair %s - %s",kind,unicode,second)
- end
- else
- for i=1,#second do
- local second = second[i]
- krn[second] = off
- if trace then
- logs.report("define otf","feature %s kern pair %s - %s",kind,unicode,second)
- end
- end
- end
- end
- end
- end
- end
- end
- list = glyphs.lookups
- if list then
- for lookup,ps in pairs(list) do
- if lookup == lookupname then
- local krn
- for i=1,#ps do
- local p = ps[i]
- if p[1] == 'pair' then
- if not krn then
- krn = kerns[unicode]
- if not krn then
- krn = { }
- kerns[unicode] = krn
- end
- end
- local second = unicodes[p[2]]
- if type(second) == "number" then
- krn[second] = p
- if trace then
- logs.report("define otf","feature %s kern pair %s - %s",kind,unicode,second)
- end
- else
- for i=1,#second do
- local second = second[i]
- krn[second] = p
- if trace then
- logs.report("define otf","feature %s kern pair %s - %s",kind,unicode,second)
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- return kerns
- end
-
- otf.features.prepare.gpos_contextchain = otf.features.prepare.contextchain
-
-end
-
--- can be generalized: one loop in main
-
-do
-
- local prepare = otf.features.prepare.feature
-
- function fonts.initializers.node.otf.aalt(tfm,value) return prepare(tfm,'aalt',value) end
- function fonts.initializers.node.otf.abvm(tfm,value) return prepare(tfm,'abvm',value) end
- function fonts.initializers.node.otf.afrc(tfm,value) return prepare(tfm,'afrc',value) end
- function fonts.initializers.node.otf.akhn(tfm,value) return prepare(tfm,'akhn',value) end
- function fonts.initializers.node.otf.blwm(tfm,value) return prepare(tfm,'blwm',value) end
- function fonts.initializers.node.otf.c2pc(tfm,value) return prepare(tfm,'c2pc',value) end
- function fonts.initializers.node.otf.c2sc(tfm,value) return prepare(tfm,'c2sc',value) end
- function fonts.initializers.node.otf.calt(tfm,value) return prepare(tfm,'calt',value) end
- function fonts.initializers.node.otf.case(tfm,value) return prepare(tfm,'case',value) end
- function fonts.initializers.node.otf.ccmp(tfm,value) return prepare(tfm,'ccmp',value) end
- function fonts.initializers.node.otf.clig(tfm,value) return prepare(tfm,'clig',value) end
- function fonts.initializers.node.otf.cpsp(tfm,value) return prepare(tfm,'cpsp',value) end
- function fonts.initializers.node.otf.cswh(tfm,value) return prepare(tfm,'cswh',value) end
- function fonts.initializers.node.otf.curs(tfm,value) return prepare(tfm,'curs',value) end
- function fonts.initializers.node.otf.dlig(tfm,value) return prepare(tfm,'dlig',value) end
- function fonts.initializers.node.otf.dnom(tfm,value) return prepare(tfm,'dnom',value) end
- function fonts.initializers.node.otf.expt(tfm,value) return prepare(tfm,'expt',value) end
- function fonts.initializers.node.otf.fin2(tfm,value) return prepare(tfm,'fin2',value) end
- function fonts.initializers.node.otf.fin3(tfm,value) return prepare(tfm,'fin3',value) end
- function fonts.initializers.node.otf.fina(tfm,value) return prepare(tfm,'fina',value) end
- function fonts.initializers.node.otf.frac(tfm,value) return prepare(tfm,'frac',value) end
- function fonts.initializers.node.otf.fwid(tfm,value) return prepare(tfm,'fwid',value) end
- function fonts.initializers.node.otf.haln(tfm,value) return prepare(tfm,'haln',value) end
- function fonts.initializers.node.otf.hist(tfm,value) return prepare(tfm,'hist',value) end
- function fonts.initializers.node.otf.hkna(tfm,value) return prepare(tfm,'hkna',value) end
- function fonts.initializers.node.otf.hlig(tfm,value) return prepare(tfm,'hlig',value) end
- function fonts.initializers.node.otf.hngl(tfm,value) return prepare(tfm,'hngl',value) end
- function fonts.initializers.node.otf.hwid(tfm,value) return prepare(tfm,'hwid',value) end
- function fonts.initializers.node.otf.init(tfm,value) return prepare(tfm,'init',value) end
- function fonts.initializers.node.otf.isol(tfm,value) return prepare(tfm,'isol',value) end
- function fonts.initializers.node.otf.ital(tfm,value) return prepare(tfm,'ital',value) end
- function fonts.initializers.node.otf.jp78(tfm,value) return prepare(tfm,'jp78',value) end
- function fonts.initializers.node.otf.jp83(tfm,value) return prepare(tfm,'jp83',value) end
- function fonts.initializers.node.otf.jp90(tfm,value) return prepare(tfm,'jp90',value) end
- function fonts.initializers.node.otf.kern(tfm,value) return prepare(tfm,'kern',value) end
- function fonts.initializers.node.otf.liga(tfm,value) return prepare(tfm,'liga',value) end
- function fonts.initializers.node.otf.lnum(tfm,value) return prepare(tfm,'lnum',value) end
- function fonts.initializers.node.otf.locl(tfm,value) return prepare(tfm,'locl',value) end
- function fonts.initializers.node.otf.mark(tfm,value) return prepare(tfm,'mark',value) end
- function fonts.initializers.node.otf.med2(tfm,value) return prepare(tfm,'med2',value) end
- function fonts.initializers.node.otf.medi(tfm,value) return prepare(tfm,'medi',value) end
- function fonts.initializers.node.otf.mgrk(tfm,value) return prepare(tfm,'mgrk',value) end
- function fonts.initializers.node.otf.mkmk(tfm,value) return prepare(tfm,'mkmk',value) end
- function fonts.initializers.node.otf.nalt(tfm,value) return prepare(tfm,'nalt',value) end
- function fonts.initializers.node.otf.nlck(tfm,value) return prepare(tfm,'nlck',value) end
- function fonts.initializers.node.otf.nukt(tfm,value) return prepare(tfm,'nukt',value) end
- function fonts.initializers.node.otf.numr(tfm,value) return prepare(tfm,'numr',value) end
- function fonts.initializers.node.otf.onum(tfm,value) return prepare(tfm,'onum',value) end
- function fonts.initializers.node.otf.ordn(tfm,value) return prepare(tfm,'ordn',value) end
- function fonts.initializers.node.otf.ornm(tfm,value) return prepare(tfm,'ornm',value) end
- function fonts.initializers.node.otf.pnum(tfm,value) return prepare(tfm,'pnum',value) end
- function fonts.initializers.node.otf.pref(tfm,value) return prepare(tfm,'pref',value) end
- function fonts.initializers.node.otf.pres(tfm,value) return prepare(tfm,'pres',value) end
- function fonts.initializers.node.otf.pstf(tfm,value) return prepare(tfm,'pstf',value) end
- function fonts.initializers.node.otf.rlig(tfm,value) return prepare(tfm,'rlig',value) end
- function fonts.initializers.node.otf.rphf(tfm,value) return prepare(tfm,'rphf',value) end
- function fonts.initializers.node.otf.rtla(tfm,value) return prepare(tfm,'rtla',value) end
- function fonts.initializers.node.otf.salt(tfm,value) return prepare(tfm,'salt',value) end
- function fonts.initializers.node.otf.sinf(tfm,value) return prepare(tfm,'sinf',value) end
- function fonts.initializers.node.otf.smcp(tfm,value) return prepare(tfm,'smcp',value) end
- function fonts.initializers.node.otf.smpl(tfm,value) return prepare(tfm,'smpl',value) end
- function fonts.initializers.node.otf.ss01(tfm,value) return prepare(tfm,'ss01',value) end
- function fonts.initializers.node.otf.ss02(tfm,value) return prepare(tfm,'ss02',value) end
- function fonts.initializers.node.otf.ss03(tfm,value) return prepare(tfm,'ss03',value) end
- function fonts.initializers.node.otf.ss04(tfm,value) return prepare(tfm,'ss04',value) end
- function fonts.initializers.node.otf.ss05(tfm,value) return prepare(tfm,'ss05',value) end
- function fonts.initializers.node.otf.ss06(tfm,value) return prepare(tfm,'ss06',value) end
- function fonts.initializers.node.otf.ss07(tfm,value) return prepare(tfm,'ss07',value) end
- function fonts.initializers.node.otf.ss08(tfm,value) return prepare(tfm,'ss08',value) end
- function fonts.initializers.node.otf.ss09(tfm,value) return prepare(tfm,'ss09',value) end
- function fonts.initializers.node.otf.subs(tfm,value) return prepare(tfm,'subs',value) end
- function fonts.initializers.node.otf.sups(tfm,value) return prepare(tfm,'sups',value) end
- function fonts.initializers.node.otf.swsh(tfm,value) return prepare(tfm,'swsh',value) end
- function fonts.initializers.node.otf.titl(tfm,value) return prepare(tfm,'titl',value) end
- function fonts.initializers.node.otf.tnam(tfm,value) return prepare(tfm,'tnam',value) end
- function fonts.initializers.node.otf.tnum(tfm,value) return prepare(tfm,'tnum',value) end
- function fonts.initializers.node.otf.trad(tfm,value) return prepare(tfm,'trad',value) end
- function fonts.initializers.node.otf.unic(tfm,value) return prepare(tfm,'unic',value) end
- function fonts.initializers.node.otf.zero(tfm,value) return prepare(tfm,'zero',value) end
-
-end
-
-do
-
- -- todo: use nodes helpers
-
- local glyph = node.id('glyph')
- local glue = node.id('glue')
- local kern = node.id('kern')
- local disc = node.id('disc')
- local whatsit = node.id('whatsit')
-
- local fontdata = tfm.id
- local has_attribute = node.has_attribute
- local set_attribute = node.set_attribute
- local state = attributes.numbers['state'] or 100
- local marknumber = attributes.numbers['mark'] or 200
- local report = logs.report
- local scale = tex.scale
-
- otf.features.process = { }
-
- -- we share some vars here, after all, we have no nested lookups and
- -- less code
-
- local tfmdata = false
- local otfdata = false
- local characters = false
- local descriptions = false
- local marks = false
- local indices = false
- local glyphs = false
- local currentfont = false
- local rlmode = 0
-
- -- we cheat a bit and assume that a font,attr combination are kind of ranged
-
- local context_setups = fonts.define.specify.context_setups
- local context_numbers = fonts.define.specify.context_numbers
-
- -- 1 loop over glyphs loop over lookups, quit at match
- -- 2 loop over glyphs loop over lookups, continue at match
- -- 3 loop over lookups loop over glyphs
-
- otf.strategy = 2
-
- function otf.features.process.feature(head,font,attr,kind,attribute)
- tfmdata = fontdata[font]
- local shared = tfmdata.shared
- otfdata = shared.otfdata
- characters = tfmdata.characters
- descriptions = tfmdata.descriptions
- glyphs = otfdata.glyphs
- local luatex = otfdata.luatex
- marks = luatex.marks
- indices = luatex.indices
- currentfont = font
- rlmode = 0
- local script, language, strategy
- if attr and attr > 0 then
- local features = context_setups[context_numbers[attr]]
- language, script, strategy = features.language or "dflt", features.script or "dflt", features.strategy or otf.strategy
- else
- language, script, strategy = tfmdata.language or "dflt", tfmdata.script or "dflt", tfmdata.strategy or otf.strategy
- end
- local fullkind = kind .. script .. language
- local lookuptable = shared.lookuptable[fullkind]
- if lookuptable then
- -- local strategy = otf.strategy
- local types = otfdata.luatex.name_to_type
- local start, done, ok = head, false, false
- local processes = shared.processes[fullkind]
- if #processes == 1 then
- local p = processes[1]
- while start do -- evt splitsen
- local id = start.id
- if id == glyph then
- if start.subtype<256 and start.font == font and
- (not attr or has_attribute(start,0,attr)) and -- dynamic feature
- (not attribute or has_attribute(start,state,attribute)) then
- -- we can make the p vars also global to this closure
- local pp = p[3] -- all lookups
- local pc = pp[start.char]
- if pc then
- start, ok = p[1](start,kind,p[2],pc,pp,p[4])
- done = done or ok
- if start then start = start.next end
- else
- start = start.next
- end
- else
- start = start.next
- end
- elseif id == glue and p[5] then
- local pp = p[3] -- all lookups
- local pc = pp[32] -- space, todo: more generic spacing
- if pc then
- start, ok = p[1](start,kind,p[2],pc,pp,p[4])
- done = done or ok
- if start then start = start.next end
- else
- start = start.next
- end
- elseif id == whatsit then
- local subtype = start.subtype
- if subtype == 7 then
- local dir = start.dir
- if dir == "+TRT" then
- rlmode = -1
- elseif dir == "+TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- elseif subtype == 6 then
- local dir = start.dir
- if dir == "TRT" then
- rlmode = -1
- elseif dir == "TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- end
- start = start.next
- else
- start = start.next
- end
- end
- elseif strategy == 3 then
- for i=1,#processes do local p = processes[i]
- local pp = p[3]
- start = head
- while start do
- local id = start.id
- if id == glyph then
- if start.subtype<256 and start.font == font and
- (not attr or has_attribute(start,0,attr)) and -- dynamic feature
- (not attribute or has_attribute(start,state,attribute)) then
- local pc = pp[start.char]
- if pc then
- start, ok = p[1](start,kind,p[2],pc,pp,p[4])
- if ok then
- done = true
- end -- else
- if start then start = start.next end
- else
- start = start.next
- end
- else
- start = start.next
- end
- elseif id == glue then
- if p[5] then -- chain
- local pc = pp[32]
- if pc then
- start, ok = p[1](start,kind,p[2],pc,p[3],p[4])
- if ok then
- done = true
- end
- if start then start = start.next end
- else
- start = start.next
- end
- else
- start = start.next
- end
- elseif id == whatsit then
- local subtype = start.subtype
- if subtype == 7 then
- local dir = start.dir
- if dir == "+TRT" then
- rlmode = -1
- elseif dir == "+TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- elseif subtype == 6 then
- local dir = start.dir
- if dir == "TRT" then
- rlmode = -1
- elseif dir == "TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- end
- start = start.next
- else
- start = start.next
- end
- end
- end
- else
- while start do
- local id = start.id
- if id == glyph then
- if start.subtype<256 and start.font == font and
- (not attr or has_attribute(start,0,attr)) and -- dynamic feature
- (not attribute or has_attribute(start,state,attribute)) then
- local chr = start.char -- used ?
- for i=1,#processes do local p = processes[i]
- local pp = p[3]
---~ local pc = pp[chr]
- local pc = pp[start.char]
- if pc then
- start, ok = p[1](start,kind,p[2],pc,pp,p[4])
- if ok then
- done = true
- if strategy == 1 then
- break
- end
- end -- else
- if not start then
- break
- end
- end
- end
- if start then start = start.next end
- else
- start = start.next
- end
- elseif id == glue then
- for i=1,#processes do local p = processes[i]
- if p[5] then -- chain
- local pp = p[3]
- local pc = pp[32]
- if pc then
- start, ok = p[1](start,kind,p[2],pc,pp,p[4])
- if ok then
- done = true
- if strategy == 1 then
- break
- end
- end
- if not start then
- break
- end
- end
- end
- end
- if start then start = start.next end
- elseif id == whatsit then
- local subtype = start.subtype
- if subtype == 7 then
- local dir = start.dir
- if dir == "+TRT" then
- rlmode = -1
- elseif dir == "+TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- elseif subtype == 6 then
- local dir = start.dir
- if dir == "TRT" then
- rlmode = -1
- elseif dir == "TLT" then
- rlmode = 1
- else
- rlmode = 0
- end
- end
- start = start.next
- else
- start = start.next
- end
- end
- end
- return head, done
- else
- return head, false
- end
- end
-
- -- we can assume that languages that use marks are not hyphenated
- -- we can also assume that at most one discretionary is present
-
- local copy_list, slide, free = node.copy_list, node.slide, node.free
-
- local function toligature(start,stop,char,markflag,discfound) -- brr head
- if start ~= stop then
- if discfound then
- local lignode = node.copy(start)
- lignode.font = start.font
- lignode.char = char
- lignode.subtype = 2
- start = node.do_ligature_n(start, stop, lignode)
- if start.id == disc then
- local prev = start.prev
- start = start.next
- end
- else -- start is the ligature
- -- to be checked: this marknum mess (sensitive for looping)
- local deletemarks = markflag ~= "mark"
---~ deletemarks = false
- start.components = copy_list(start,stop)
- local last = slide(start.components)
- start.components.prev, last.next = nil, nil
- start.char, start.subtype = char, 2
- local next, done, marknum = start.next, false, 1
- local after = stop.next
- while not done do
- done = next == stop
- if not deletemarks and marks[next.char] then
- set_attribute(next,marknumber,marknum)
- next = next.next
- --~ marknum = marknum + 1
- else
- marknum = marknum + 1
- start, next = nodes.remove(start,next,true)
- end
- end
- while after and after.id == glyph and after.font == currentfont and marks[after.char] do
- if deletemarks then
- start, after = nodes.remove(start,after,true)
- else
- set_attribute(after,marknumber,marknum)
- after = after.next
- --~ marknum = marknum + 1
- end
- end
-
- end
- end
- return start
- end
-
- function otf.features.process.gsub_single(start,kind,lookupname,replacements)
- if replacements then
- if otf.trace_replacements then
- report("otf process","%s:%s replacing 0x%04X by 0x%04X",kind,lookupname,start.char,replacements)
- end
- start.char = replacements
- return start, true
- else
- return start, false
- end
- end
-
- function otf.features.process.gsub_alternate(start,kind,lookupname,alternatives)
- if alternatives then
- if otf.trace_replacements then
- report("otf process","%s:%s alternative 0x%04X => %s",kind,lookupname,start.char,table.hexed(alternatives))
- end
- start.char = alternatives[1] -- will be preference
- return start, true
- else
- return start, false
- end
- end
-
- function otf.features.process.gsub_multiple(start,kind,lookupname,multiples)
- if multiples then
- if otf.trace_replacements then
- report("otf process","%s:%s multiple 0x%04X => %s",kind,lookupname,start.char,table.hexed(multiples))
- end
- start.char = multiples[1]
- if #multiples > 1 then
- for k=2,#multiples do
- local n = node.copy(start)
- local sn = start.next
- n.char = multiples[k]
- n.next = sn
- n.prev = start
- if sn then
- sn.prev = n
- end
- start.next = n
- start = n
- end
- end
- return start, true
- else
- return start, false
- end
- end
-
- function otf.features.process.gsub_ligature(start,kind,lookupname,ligatures,alldata,flags)
- local s, stop, discfound = start.next, nil, false
- while s do
- local id = s.id
- if id == glyph and s.subtype<256 then
- if s.font == currentfont then
- local char = s.char
- if marks[char] then
- s = s.next
- else
- -- we use indices, which saves a lookup, but we can use
- -- names when we comment the line after (*lig*)
- -- local lg = ligatures[1][glyphs[indices[char]].name]
- local lg = ligatures[1][indices[char]]
- -- mayb esome day we introduce a more efficient method
- if not lg then
- break
- else
- stop = s
- ligatures = lg
- s = s.next
- end
- end
- else
- break
- end
- elseif id == disc then
- discfound = true
- s = s.next
- else
- break
- end
- end
- if stop and ligatures[2] then
- start = toligature(start,stop,ligatures[2],flags[1],discfound)
- if otf.trace_ligatures then
- report("otf process","%s: inserting ligature 0x%04X (%s)",kind,start.char,utf.char(start.char))
- end
- return start, true
- end
- return start, false
- end
-
- function otf.features.process.gpos_mark2base(start,kind,lookupname,m_anchors,b_anchors)
- local markchar = start.char
- if marks[markchar] then
- local markanchors = m_anchors['mark']
- if markanchors then
- local component = start.prev
- while component and component.id == glyph and component.subtype<256 and component.font == currentfont do
- local basechar = component.char
- if marks[basechar] then
- component = component.prev
- else
- local baseanchors = b_anchors[basechar]
- if baseanchors then
- baseanchors = baseanchors['basechar']
- if baseanchors then
- for anchor, ma in pairs(markanchors) do
- local ba = baseanchors[anchor]
- if ba then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- start.xoffset, start.yoffset = component.xoffset - dx, component.yoffset + dy
- if otf.trace_anchors then
- report("otf process","%s: anchoring mark 0x%04X to basechar 0x%04X => (%s,%s) => (%s,%s)",
- kind,markchar,basechar,dx,dy,start.xoffset,start.yoffset)
- end
- return start, true
- end
- end
- end
- end
- break
- end
- end
- end
- end
- return start, false
- end
-
- function otf.features.process.gpos_mark2ligature(start,kind,lookupname,m_anchors,b_anchors) -- maybe use copies
- local markchar = start.char
- if marks[markchar] then
- local markanchors = m_anchors['mark']
- if markanchors then
- local component = start.prev
- while component and component.id == glyph and component.subtype<256 and component.font == currentfont do
- local basechar = component.char
- if marks[basechar] then
- component = component.prev
- else
- local baseanchors = b_anchors[basechar]
- if baseanchors then
- baseanchors = baseanchors['baselig']
- if baseanchors then
- for anchor, ma in pairs(markanchors) do
- local ba = baseanchors[anchor]
- if ba then
- local n = has_attribute(start,marknumber)
- ba = ba[n]
- if ba then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- start.xoffset, start.yoffset = component.xoffset - dx, component.yoffset + dy
- if otf.trace_anchors then
- report("otf process","%s: anchoring mark 0x%04X to baseligature 0x%04X => (%s,%s) => (%s,%s)",
- kind,markchar,basechar,dx,dy,component.xoffset,component.yoffset)
- end
- return start, true
- end
- end
- end
- end
- end
- break
- end
- end
- return start, done
- end
- end
- return start, false
- end
-
- -- hm which one is the correct one? chainprocs.gpos_mark2mark ot the next; the next one
- -- had more tracing so might be the best
-
- function otf.features.process.gpos_mark2mark(start,kind,lookupname,b_anchors,m_anchors)
- local basemarkchar = start.char
- if marks[basemarkchar] then
- local baseanchors = b_anchors['basemark']
- if baseanchors then
- local component = start.next
- while component and component.id == glyph and component.subtype<256 and component.font == currentfont do
- local markchar = component.char
- if not marks[markchar] then
- break
- else
- local basemarkattr = has_attribute(start,marknumber) or 1
- local markattr = has_attribute(component,marknumber) or 1
- if basemarkattr == markattr then -- still needed?
- local markanchors = m_anchors[markchar]
- if markanchors then
- local markanchor = markanchors['mark']
- if markanchor then
- for anchor,ma in pairs(markanchor) do
- local ba = baseanchors[anchor]
- if ba then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- component.xoffset, component.yoffset = start.xoffset - dx, start.yoffset + dy
- if otf.trace_anchors then
- report("otf process","%s:%s:%s anchoring mark 0x%04X to basemark 0x%04X => (%s,%s) => (%s,%s)",
- kind,anchor,markattr,markchar,basemarkchar,dx,dy,component.xoffset,component.yoffset)
- end
- return start, true
- end
- end
- end
- end
- -- weird, was here
- end
- component = component.next
- end
- end
- end
- end
- return start, false
- end
-
- function otf.features.process.gpos_cursive(start,kind,lookupname,exitanchors,anchors)
- local trace = otf.trace_cursive
- if rlmode >= 0 then
- local prev, done = start.prev, false
- while prev do
- if prev.id == glyph and prev.subtype<256 and prev.font == currentfont then
- local prevchar = prev.char
- if marks[prevchar] then
- -- what do do with marks, give them the offset of the previous glyph?
- prev = prev.prev
- else
- local startchar = start.char
- local entryanchors, exitanchors = anchors[startchar], anchors[prevchar]
- if entryanchors and exitanchors then
- local centry, cexit = entryanchors['centry'], exitanchors['cexit']
- if centry and cexit then
- for anchor, entry in pairs(centry) do
- local exit = cexit[anchor]
- if exit then
- local factor = tfmdata.factor
- local dx = -(descriptions[prevchar].width-exit[1]) - entry[1]
- local dy = -(entry[2]-exit[2])
- start.yoffset = prev.yoffset + scale(dy, factor)
- -- start.xoffset = scale(tx[i], factor)
- node.insert_before(prev,start,nodes.kern(scale(dx,factor)))
- if trace then
- report("otf process","%s:%s move 0x%04X cursive (%s,%s)",kind,lookupname,startchar,dx,dy)
- end
- done = true
- end
- end
- end
- end
- break
- end
- else
- break
- end
- end
- else
- local trace, factor = fonts.otf.trace_anchors, tfmdata.factor
- local next, done, total_x, total_y, tx, ty, stack = start.next, false, 0, 0, { }, { }, { }
- local function finish()
- done = true
- for i=1,#stack do
- local s = stack[i]
- s.yoffset = scale(total_y, factor)
- node.insert_before(s.prev,s,nodes.kern(scale(tx[i],factor)))
- if fonts.otf.trace_cursive then
- report("otf process",format("%s:%s move 0x%04X cursive (%s,%s)",kind,lookupname,s.char,tx[i],total_y))
- end
- total_y = total_y - (ty[i] or 0)
- end
- total_x, total_y, tx, ty, stack = 0, 0, { }, { }, { }
- end
- while next do
- if next.id == glyph and next.subtype<256 and next.font == currentfont then
- local nextchar = next.char
- if marks[nextchar] then
- next = next.next
- else
- local entryanchors, exitanchors = anchors[nextchar], anchors[start.char]
- if entryanchors and exitanchors then
- local centry, cexit = entryanchors['centry'], exitanchors['cexit']
- if centry and cexit then
- for anchor, entry in pairs(centry) do
- local exit = cexit[anchor]
- if exit then
- local dy = -exit[2] + entry[2]
- local dx = -(descriptions[nextchar].width-entry[1]) - exit[1] -- often width == entry 1
- tx[#tx+1], ty[#ty+1] = dx, dy
- total_x, total_y = total_x + dx, total_y + dy
- stack[#stack+1] = start
- break
- end
- end
- else
- finish()
- end
- else
- finish()
- end
- start = next
- next = start.next
- end
- else
- finish()
- break
- end
- end
- return start, done
- end
- return start, done
- end
-
- function otf.features.process.gpos_single(start,kind,lookupname,basekerns,kerns)
- report("otf process","gpos_single not yet supported")
- return start, false
- end
-
- function otf.features.process.gpos_pair(start,kind,lookupname,basekerns,kerns)
- -- todo: kerns in disc nodes: pre, post, replace -> loop over disc too
- -- todo: kerns in components of ligatures
- local next = start.next
- if not next then
- return start, false
- else
- local prev, done = start, false
- local trace = otf.trace_kerns
- local factor = tfmdata.factor
- while next and next.id == glyph and next.subtype<256 and next.font == currentfont do
- local cn = descriptions[next.char]
- if not cn or cn.class == 'mark' then
- prev = next
- next = next.next
- else
- local krn = basekerns[next.char]
- if not krn then
- -- skip
- elseif type(krn) == "table" then
- local a, b = krn[3], krn[7]
- if a and a ~= 0 then
- local k = nodes.kern(scale(a,factor))
- k.next = next
- k.prev = prev
- prev.next = k
- next.prev = k
- if trace then
- -- todo
- end
- end
- if b and b ~= 0 then
- report("otf process","we need to do something with the second kern xoff %s",b)
- end
- else
- -- todo, just start, next = node.insert_before(head,next,nodes.kern(scale(kern,factor)))
- if otf.trace_kerns then
- report("otf process","%s: inserting kern %s between 0x%04X and 0x%04X",kind,krn,prev.char,next.char)
- end
- local k = nodes.kern(scale(krn,factor))
- k.next = next
- k.prev = prev
- prev.next = k
- next.prev = k
- end
- break
- end
- end
- return start, done
- end
- end
-
--- -- -- temp here, needs to be tested first -- -- --
-
---~ function do_gpos_pair(start,kind,lookupname,basekerns,kerns)
---~ local trace = otf.trace_kerns
---~ local factor = tfmdata.factor
---~ local next, prev, middle = start.next, start, nil
---~ -- to be optimized, we can consider using basemode for fonts without lookups
---~ -- todo: kerns in disc nodes: pre, post, replace -> loop over disc too
---~ -- todo: kerns in components of ligatures
---~ --
---~ -- find valid next
---~ while next do
---~ local id = next.id
---~ if id == glyph and next.subtype<256 and next.font == currentfont then
---~ local cn = characters[next.char]
---~ if not cn or cn.description.class == 'mark' then
---~ prev = next
---~ next = next.next
---~ else
---~ break
---~ end
---~ elseif id == disc then -- assume same font
---~ middle = next
---~ else
---~ return start, false
---~ end
---~ end
---~ local function inject(head, prevkern, nextkern)
---~ if head then
---~ -- kern between prevchar and head
---~ local tail = node.slide(head) -- tail
---~ if head.id == glyph then
---~ local c = head.char
---~ local pc = prevkern[c]
---~ if pc then
---~ local k = nodes.kern(scale(pc,factor))
---~ k.next = head
---~ head = k
---~ end
---~ end
---~ -- kern between prevchar and tail
---~ if tail.id == glyph then
---~ local c = tail.char
---~ local nc = nextkern[c]
---~ if nc then
---~ tail.next = nodes.kern(scale(nc,factor))
---~ end
---~ end
---~ -- kern between head .. tail
---~ local c = head
---~ while c do do_gpos_pair(c,kind,lookupname,basekerns,kerns) ; c = c.next end
---~ end
---~ return head
---~ end
---~ if middle then
---~ -- prev middle next - assumes same lookup
---~ local prevkern, nextkern = kerns[prev.char], kerns[next.char]
---~ local m = middle.pre ; if m then middle.pre = inject(m, prevkern, nextkern) end
---~ local m = middle.post ; if m then middle.post = inject(m, prevkern, nextkern) end
---~ local m = middle.replace ; if m then middle.replace = inject(m, prevkern, nextkern) end
---~ elseif next then
---~ local prevchar, nextchar = prev.char, next.char
---~ if prev.components then
---~ local prevkern, nextkern = kerns[prev.char], kerns[next.char]
---~ local p = prev.components ; if p then prev.components = inject(p, prevkern, nextkern) end
---~ end
---~ local krn = basekerns[nextchar]
---~ if not krn then
---~ return start, false
---~ elseif type(krn) == "table" then
---~ local a, b = krn[3], krn[7]
---~ if a and a ~= 0 then
---~ start, next = node.insert_before(start,next,nodes.kern(scale(a,factor)))
---~ if trace then
---~ report("otf process","%s: inserting kern %s between 0x%04X and 0x%04X",kind,a,prevchar,nextchar)
---~ end
---~ end
---~ if b and b ~= 0 then
---~ report("otf process","we need to do something with the second kern xoff %s",b)
---~ end
---~ return start, true -- could be next
---~ else
---~ if otf.trace_kerns then
---~ report("otf process","%s: inserting kern %s between 0x%04X and 0x%04X",kind,krn,prevchar,nextchar)
---~ end
---~ start, next = node.insert_before(start,next,nodes.kern(scale(krn,factor)))
---~ return start, true -- could be next
---~ end
---~ end
---~ return start, false
---~ end
-
---~ otf.features.process.gpos_pair = do_gpos_pair
-
--- -- -- temp here, needs to be tested -- -- --
-
-
- local chainprocs = { } -- we can probably optimize this because they're all internal lookups
-
- -- For the moment we save each looked up glyph in the sequence, which is ok because
- -- each lookup in the chain has its own sequence. This saves memory. Only ligatures
- -- are stored in the featurecache, because we don't want to loop over all characters
- -- in order to locate them.
-
- function chainprocs.gsub_single(start,stop,kind,lookupname,sequence,f,l,lookups)
- local trace = otf.trace_replacements
- local c, r = trace and { }, trace and { }
- local lookup, index, current = 1, f, start
- while current ~= nil do
- if current.id == glyph then -- test for more ?
- local char = current.char
- local cacheslot = sequence[index]
- local replacement = cacheslot[char]
- if replacement == true then
- if lookups then
- -- didn't we have the arrays available?
- local looks = glyphs[descriptions[char].index].lookups -- SLOW, USE OTFDATA
- if looks then
- local luatex = otfdata.luatex
- local glyphlookups = luatex.internals[lookups[lookup]].lookups
- local unicodes = luatex.unicodes
- for gl=1,#glyphlookups do
- local lv = looks[glyphlookups[gl]]
- if lv then
- local ulv = unicodes[lv[1][2]]
- if not ulv then
- replacement = char
- elseif type(ulv) == "number" then
- replacement = ulv
- else
- replacement = ulv[1]
- end
- cacheslot[char] = replacement
- break
- end
- end
- else
- replacement, cacheslot[char] = char, char
- end
- else
- replacement, cacheslot[char] = char, char
- end
- end
- if trace then
- c[#c+1], r[#r+1] = char, replacement
- end
- current.char = replacement
- if current == stop then
- break
- else
- current, lookup, index = current.next, lookup + 1, index + 1
- end
- elseif current == stop then
- break
- else
- current = current.next
- end
- end
- if trace then
- report("otf chain","%s: single replacement %s by %s",kind,table.hexed(c),table.hexed(r))
- end
- return start
- end
-
- function chainprocs.gsub_multiple(start,stop,kind,lookupname,sequence,f,l,lookups)
- local char = start.char
- local cacheslot = sequence[f] -- [1]
- local replacement = cacheslot[char]
- if replacement == true then
- if lookups then
- local looks = glyphs[descriptions[char].index].lookups
- if looks then
- local luatex = otfdata.luatex
- local lookups = luatex.internals[lookups[1]].lookups
- local unicodes = luatex.unicodes
- for l=1,#lookups do
- local lv = looks[lookups[l]]
- if lv then
- replacement = { }
- for c in lv[1][2]:gmatch("[^ ]+") do
- local uc = unicodes[c]
- if type(uc) == "number" then
- replacement[#replacement+1] = uc
- else
- replacement[#replacement+1] = uc[1]
- end
- end
- cacheslot[char] = replacement
- break
- end
- end
- else
- replacement = { char }
- cacheslot[char] = replacement
- end
- else
- replacement = { char }
- cacheslot[char] = replacement
- end
- end
- if otf.trace_replacements then
- report("otf chain","%s: replacing character 0x%04X by multiple 0x%04X",kind,char,table.hexed(replacement))
- end
- start.char = replacement[1]
- if #replacement > 1 then
- for k=2,#replacement do
- local n = node.copy(start)
- local sn = start.next
- n.char = replacement[k]
- n.next = sn
- n.prev = start
- if sn then
- sn.prev = n
- end
- start.next = n
- start = n
- end
- end
- return start
- end
-
- function chainprocs.gsub_alternate(start,stop,kind,lookupname,sequence,f,l,lookups)
- local char = start.char
- local cacheslot = sequence[f] -- [1]
- local replacement = cacheslot[char]
- if replacement == true then
- if lookups then
- local looks = glyphs[descriptions[char].index].lookups
- if looks then
- local luatex = otfdata.luatex
- local lookups = luatex.internals[lookups[1]].lookups
- local unicodes = luatex.unicodes
- for l=1,#lookups do
- local lv = looks[lookups[l]]
- if lv then
- replacement = { }
- for c in lv[1][2]:gmatch("[^ ]+") do
- local uc = unicodes[c]
- if type(uc) == "number" then
- replacement[#replacement+1] = uc
- else
- replacement[#replacement+1] = uc[1]
- end
- end
- cacheslot[char] = replacement
- break
- end
- end
- else
- replacement = { char }
- cacheslot[char] = replacement
- end
- else
- replacement = { char }
- cacheslot[char] = replacement
- end
- end
- if otf.trace_replacements then
- report("otf chain","%s: replacing character 0x%04X by alternate",kind,char)
- end
- start.char = replacement[1]
- return start
- end
-
- function chainprocs.gsub_ligature(start,stop,kind,lookupname,sequence,f,l,lookups,flags)
- if lookups then
- if start == stop then
- -- print("todo: optimize")
- end
- local featurecache = fontdata[currentfont].shared.featurecache
- local ligaturecache = featurecache[kind]
- if not ligaturecache then
- ligaturecache = otf.features.collect_ligatures(tfmdata,kind) -- double cached ?
- featurecache[kind] = ligaturecache
- end
- local lookups = otfdata.luatex.internals[lookups[1]].lookups
- local trace = otf.trace_ligatures
- for i=1,#lookups do
- local ligatures = ligaturecache[lookups[i]]
- if ligatures and ligatures[start.char] then
- ligatures = ligatures[start.char]
- local s, discfound = start.next, false
- while s do
- local id = s.id
- if id == disc then
- s = s.next
- discfound = true
- elseif descriptions[s.char].class == 'mark' then -- marks
- s = s.next
- else
- local lg = ligatures[1][s.char]
- if not lg then
- break
- else
- ligatures = lg
- if s == stop then
- break
- else
- s = s.next
- end
- end
- end
- end
- if ligatures[2] then
- if trace then
- if start == stop then
- report("otf chain","%s: replacing character 0x%04X by ligature 0x%04X",kind,start.char,ligatures[2])
- else
- report("otf chain","%s: replacing character 0x%04X upto 0x%04X by ligature 0x%04X",kind,start.char,stop.char,ligatures[2])
- end
- end
- return toligature(start,stop,ligatures[2],flags[1],discfound)
- end
- break
- end
- end
- end
- return stop
- end
-
- -- weird, mkmk can have a mark2base, in idris font
-
- function chainprocs.gpos_mark2base(start,stop,kind,lookupname,sequence,f,l,lookups,flags)
- -- dynamic resolver
- local markchar = start.char
- if marks[markchar] then
- local anchortag = sequence[f][markchar]
- if anchortag == true then
- local ok = false
- local classes = otfdata.anchor_classes
- local lookups = otfdata.luatex.internals[lookups[1]].lookups
- for k=1,#classes do
- local v = classes[k]
- if v.lookup == lookups[1] then -- let's gamble for uniqueness: and v.type == kind then
- anchortag = v.name
- sequence[f][markchar] = anchortag
- ok = true
- break
- end
- end
- if not ok and otf.trace_anchors then
- report("otf chain","%s: no matching mark2base anchor class for 0x%04X, lookup %s",kind,markchar,lookups[1])
- end
- end
- if anchortag ~= true then
- local component = start.prev
- while component and component.id == glyph and component.subtype<256 and component.font == currentfont do
- local basechar = component.char
- if marks[basechar] then
- component = component.prev
- else
- local bglyph = glyphs[descriptions[basechar].index] -- startchar
- local baseanchors = bglyph.anchors['basechar']
- if baseanchors then
- local ba = baseanchors[anchortag]
- if ba then
- local mglyph = glyphs[descriptions[markchar].index]
- local markanchors = mglyph.anchors['mark']
- if markanchors then
- local ma = markanchors[anchortag]
- if ma then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- start.xoffset, start.yoffset = component.xoffset - dx, component.yoffset + dy
- if otf.trace_anchors then
- report("otf chain","%s: anchoring mark 0x%04X to basechar 0x%04X => (%s,%s) => (%s,%s)",
- kind,markchar,basechar,dx,dy,start.xoffset,start.yoffset)
- end
- return start, true
- end
- end
- end
- end
- break
- end
- end
- end
- end
- return start, false
- end
-
- function chainprocs.gpos_mark2ligature(start,stop,kind,lookupname,sequence,f,l,lookups,flags)
- -- dynamic resolver
- local markchar = start.char
- if marks[markchar] then
- local anchortag = sequence[f][markchar]
- if anchortag == true then
- local classes = otfdata.anchor_classes
- local lookups = otfdata.luatex.internals[lookups[1]].lookups
- local ok = false
- for k=1,#classes do
- local v = classes[k]
- if v.lookup == lookups[1] then -- and v.type == kind then
- anchortag = v.name
- sequence[f][markchar] = anchortag
- ok = true
- break
- end
- end
- if not ok and otf.trace_anchors then
- report("otf chain","%s: no matching mark2ligature anchor class for 0x%04X, lookup %s",kind,markchar,lookups[1])
- end
- end
- if anchortag ~= true then
- local component = start.prev
- while component and component.id == glyph and component.subtype<256 and component.font == currentfont do
- local basechar = component.char
- if marks[basechar] then
- component = component.prev
- else
- local bglyph = glyphs[descriptions[basechar].index] -- startchar
- local baseanchors = bglyph.anchors['baselig']
- if baseanchors then
- local ba = baseanchors[anchortag]
- if ba then
- local n = has_attribute(start,marknumber)
- ba = ba[n] -- ok ?
- if ba then
- local mglyph = glyphs[descriptions[markchar].index]
- local markanchors = mglyph.anchors['mark']
- if markanchors then
- local ma = markanchors[anchortag]
- if ma then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- start.xoffset, start.yoffset = component.xoffset - dx, component.yoffset + dy
- if otf.trace_anchors then
- report("otf chain","%s: anchoring mark 0x%04X to baseligature 0x%04X => (%s,%s) => (%s,%s)",
- kind,basechar,markchar,dx,dy,start.xoffset,start.yoffset)
- end
- return start, true
- end
- end
- end
- end
- end
- break
- end
- end
- end
- end
- return start, false
- end
-
- -- to be checked (see previous generic mark2mark)
-
- function chainprocs.gpos_mark2mark(start,stop,kind,lookupname,sequence,f,l,lookups)
- local component = start.next
- if component and component.id == glyph and component.subtype<256 and component.font == currentfont and marks[component.char] then
- local markchar = start.char
- local anchortag = sequence[f][markchar] -- [1][char]
- if anchortag == true then
- local classes = otfdata.anchor_classes
- local ok = false
- for k=1,#classes do
- local v = classes[k]
- if v.lookup == lookupname then -- and v.type == kind then
- anchortag = v.name
- sequence[f][markchar] = anchortag
- ok = true
- break
- end
- end
- if not ok and otf.trace_anchors then
- report("otf chain","%s: no matching mark2mark anchor class for 0x%04X, lookup %s",kind,markchar,lookups[1])
- end
- end
- if anchortag ~= true then
- -- the following may have been be spoiled while idrising the other ones
- local markattr = has_attribute(start, marknumber) or 1 -- i need to check this ! 1 is new !
- local baseattr = has_attribute(component,marknumber) or 1 -- i need to check this ! 1 is new !
- if baseattr == markattr then
- local glyph = glyphs[descriptions[markchar].index]
- if glyph.anchors and glyph.anchors[anchortag] then
- local trace = otf.trace_anchors
- local done = false
- local baseanchors = glyph.anchors['basemark'][anchortag]
- while component do
- local basechar = component.char
- local markanchors = glyphs[descriptions[basechar].index].anchors['mark'][anchortag]
- if markanchors then
- for anchor,data in pairs(markanchors) do
- local ba = baseanchors[anchor]
- if ba then
- local factor = tfmdata.factor
- local dx, dy = scale(ba[1]-ma[1],factor), scale(ba[2]-ma[2],factor)
- start.xoffset, start.yoffset = component.xoffset - dx, component.yoffset + dy
- if otf.trace_anchors then
- report("otf chain","%s: anchoring mark 0x%04X to basemark 0x%04X => (%s,%s) => (%s,%s)",
- kind,markchar,basechar,dx,dy,component.xoffset,component.yoffset)
- end
- done = true
- break
- end
- end
- end
- component = component.next
- if component and component.id == glyph and component.subtype<256 and component.font == currentfont and marks[component.char] then
- markattr = has_attribute(component,marknumber)
- if baseattr ~= markattr then
- break
- end
- else
- break
- end
- end
- return start, done
- end
- end
- end
- end
- return start, false
- end
-
- function chainprocs.gpos_cursive(start,stop,kind,lookupname,sequence,f,l,lookups)
- report("otf chain","chainproc gpos_cursive not yet supported")
- return start
- end
- function chainprocs.gpos_single(start,stop,kind,lookupname,sequence,f,l,lookups)
- report("otf process","chainproc gpos_single not yet supported")
- return start
- end
- function chainprocs.gpos_pair(start,stop,kind,lookupname,sequence,f,l,lookups)
- report("otf process","chainproc gpos_pair not yet supported")
- return start
- end
-
- function chainprocs.self(start,stop,kind,lookupname,sequence,f,l,lookups)
- report("otf process","self refering lookup cannot happen")
- return stop
- end
-
- local zwnj = 0x200C
- local zwj = 0x200D
-
- -- what pointer to return, spec says stop
-
- -- to be discussed ... is bidi changer a space?
-
- function otf.features.process.contextchain(start,kind,lookupname,contextdata)
- local contexts, flags, done = contextdata.lookups, contextdata.flags, false
- local skipmark, skipligature, skipbase = unpack(flags) -- unpack slower than assignment
- for k=1,#contexts do
- local match, next, last = true, start, start
- local rule, lookuptype, sequence, f, l, lookups = unpack(contexts[k]) -- unpack is slow
- local s = #sequence
- if s == 1 then
- match = next.id == glyph and next.subtype<256 and next.font == currentfont and sequence[1][next.char]
- else
- -- todo: better space check (maybe check for glue)
- local n = f
- while n <= l do
- if last then
- local id = last.id
- if id == glyph and last.subtype<256 and last.font == currentfont then
- local char = last.char
- local cc = characters[char]
- if cc then
- local ccd = descriptions[char]
- if ccd then
- local class = ccd.class
- if class == skipmark or class == skipligature or class == skipbase then
- -- skip 'm
- last = last.next
- elseif sequence[n][char] then
- if n < l then
- last = last.next
- end
- n = n + 1
- else
- match = false break
- end
- else
- match = false break
- end
- else -- play safe
- match = false break
- end
- elseif id == disc then -- what to do with kerns?
- last = last.next
- else
- match = false break
- end
- else
- match = false break
- end
- end
- if match and f > 1 then
- local prev = start.prev
- if prev then
- -- removed optimiziation for f == 2, we have to deal with marks anyway
- local n = f-1
- while n >= 1 do
- if prev then
- local id = prev.id
- if id == glyph and prev.subtype<256 and prev.font == currentfont then -- normal char
- local char = prev.char
- local cc = characters[char]
- if cc then
- local ccd = descriptions[char]
- if ccd then
- local class = ccd.class
- if class == skipmark or class == skipligature or class == skipbase then
- -- skip 'm
- elseif sequence[n][char] then
- n = n -1
- else
- match = false break
- end
- else
- match = false break
- end
- else
- match = false break
- end
- elseif id == disc then
- -- skip 'm
- elseif sequence[n][32] then
- n = n -1
- else
- match = false break
- end
- prev = prev.prev
- elseif sequence[n][32] then
- n = n -1
- else
- match = false break
- end
- end
- elseif f == 2 then
- match = sequence[1][32]
- else
- for n=f-1,1 do
- if not sequence[n][32] then
- match = false break
- end
- end
- end
- end
- if match and s > l then
- local next = last.next
- if next then
- -- removed optimiziation for s-l == 1, we have to deal with marks anyway
- local n = l+ 1
- while n <= s do
- if next then
- local id = next.id
- if id == glyph and next.subtype<256 and next.font == currentfont then -- normal char
- local char = next.char
- local cc = characters[char]
- if cc then
- local ccd = descriptions[char]
- if ccd then
- local class = ccd.class
- if class == skipmark or class == skipligature or class == skipbase then
- -- skip 'm
- elseif sequence[n][char] then
- n = n + 1
- else
- match = false break
- end
- else
- match = false break
- end
- else
- match = false break
- end
- elseif id == disc then
- -- skip 'm
- elseif sequence[n][32] then -- brrr
- n = n + 1
- else
- match = false break
- end
- next = next.next
- elseif sequence[n][32] then
- n = n + 1
- else
- match = false break
- end
- end
- elseif s-l == 1 then
- match = sequence[s][32]
- else
- for n=l+1,s do
- if not sequence[n][32] then
- match = false break
- end
- end
- end
- end
- end
- if match then
- local trace = otf.trace_contexts
- if trace then
- local char = start.char
- report("otf chain","%s: rule %s of %s matches at char 0x%04X (%s) for (%s,%s,%s) chars, lookuptype %s",kind,rule,lookupname,char,utf.char(char),f-1,l-f+1,s-l,lookuptype)
- end
- if lookups then
- local cp = chainprocs[lookuptype]
- if cp then
- start = cp(start,last,kind,lookupname,sequence,f,l,lookups,flags)
- else
- report("otf chain","%s: lookuptype %s not supported yet for %s",kind,lookuptype,lookupname)
- end
- elseif trace then
- report("otf chain","%s: skipping match for %s",kind,lookupname)
- end
- done = true
- break
- end
- end
- return start, done
- end
-
---~ if true then
---~ if n < f then
---~ texio.write_nl(format("%s before %s %04x %s %s %s",lookupname,n,char,class,skipmark or "?",tostring(sequence[n][char])))
---~ elseif n > l then
---~ texio.write_nl(format("%s after %s %04x %s %s %s",lookupname,n,char,class,skipmark or "?",tostring(sequence[n][char])))
---~ else
---~ texio.write_nl(format("%s current %s %04x %s %s %s",lookupname,n,char,class,skipmark or "?",tostring(sequence[n][char])))
---~ end
---~ end
-
---~ elseif char == zwnj and sequence[n][32] then -- brrr
-
- -- this needs to be fixed ! ! ! ! ! ! ! !
-
- function otf.features.process.reversecontextchain(start,kind,lookupname,contextdata)
- -- PROBABLY WRONG, WE NEED TO WALK BACK OVER THE LIST
- local done = false
- local contexts = contextdata.lookups
- local flags = contextdata.flags
- local skipmark, skipligature, skipbase = unpack(flags)
- for k=1,#contexts do
- local match, next, first, last = true, start, start, start
- local rule, lookuptype, sequence, f, l, lookups = unpack(contexts[k]) -- unpack is slow
- if #sequence == 1 then
- match = next.id == glyph and next.subtype<256 and next.font == currentfont and sequence[1][next.char]
- else
- local n, s = #sequence, 1
- while n > 0 do
- if next then
- local id = next.id
- if id == glyph and next.subtype<256 and next.font == currentfont then -- normal char
- local char = next.char
- local class = descriptions[char].class
- if class == skipmark or class == skipligature or class == skipbase then
- -- skip
- elseif sequence[n][char] then
- if n == f then
- first = next -- ok ?
- end
- if n == l then
- last = next -- ok ?
- end
- n = n - 1
- else
- match = false break
- end
- elseif id == disc then
- -- skip
- elseif not sequence[n][32] then -- brrr
- match = false break
- end
- next = next.next
- elseif sequence[n][32] then
- n = n - 1
- else
- match = false break
- end
- end
- end
- if match then
- local trace = otf.trace_contexts
- if trace then
- local char = first.char
- report("otf reverse chain","%s: rule %s of %s matches, replacing starts at char 0x%04X (%s) lookuptype %s",kind,rule,lookupname,char,utf.char(char),lookuptype)
- end
- if lookups then
- local cp = chainprocs[lookuptype]
- if cp then
- if start == first then
- start = cp(first,last,kind,lookupname,sequence,f,l,lookups,flags)
- else
- first = cp(first,last,kind,lookupname,sequence,f,l,lookups,flags)
- end
- else
- report("otf reverse chain","%s: lookuptype %s not supported yet for %s",kind,lookuptype,lookupname)
- end
- elseif trace then
- report("otf reverse chain","%s: skipping match for %s",kind,lookupname)
- end
- done = true
- break
- end
- end
- return start, done
- end
-
- otf.features.process.gsub_context = otf.features.process.contextchain
- otf.features.process.gsub_contextchain = otf.features.process.contextchain
- otf.features.process.gsub_reversecontextchain = otf.features.process.reversecontextchain
-
- otf.features.process.gpos_contextchain = otf.features.process.contextchain
- otf.features.process.gpos_context = otf.features.process.contextchain
-
-end
-
-do
-
- local process = otf.features.process.feature
-
- function fonts.methods.node.otf.aalt(head,font,attr) return process(head,font,attr,'aalt') end
- function fonts.methods.node.otf.abvm(head,font,attr) return process(head,font,attr,'abvm') end
- function fonts.methods.node.otf.afrc(head,font,attr) return process(head,font,attr,'afrc') end
- function fonts.methods.node.otf.akhn(head,font,attr) return process(head,font,attr,'akhn') end
- function fonts.methods.node.otf.blwm(head,font,attr) return process(head,font,attr,'blwm') end
- function fonts.methods.node.otf.c2pc(head,font,attr) return process(head,font,attr,'c2pc') end
- function fonts.methods.node.otf.c2sc(head,font,attr) return process(head,font,attr,'c2sc') end
- function fonts.methods.node.otf.calt(head,font,attr) return process(head,font,attr,'calt') end
- function fonts.methods.node.otf.case(head,font,attr) return process(head,font,attr,'case') end
- function fonts.methods.node.otf.ccmp(head,font,attr) return process(head,font,attr,'ccmp') end
- function fonts.methods.node.otf.clig(head,font,attr) return process(head,font,attr,'clig') end
- function fonts.methods.node.otf.cpsp(head,font,attr) return process(head,font,attr,'cpsp') end
- function fonts.methods.node.otf.cswh(head,font,attr) return process(head,font,attr,'cswh') end
- function fonts.methods.node.otf.curs(head,font,attr) return process(head,font,attr,'curs') end
- function fonts.methods.node.otf.dlig(head,font,attr) return process(head,font,attr,'dlig') end
- function fonts.methods.node.otf.dnom(head,font,attr) return process(head,font,attr,'dnom') end
- function fonts.methods.node.otf.expt(head,font,attr) return process(head,font,attr,'expt') end
- function fonts.methods.node.otf.fin2(head,font,attr) return process(head,font,attr,'fin2') end
- function fonts.methods.node.otf.fin3(head,font,attr) return process(head,font,attr,'fin3') end
- function fonts.methods.node.otf.fina(head,font,attr) return process(head,font,attr,'fina',3) end
- function fonts.methods.node.otf.frac(head,font,attr) return process(head,font,attr,'frac') end
- function fonts.methods.node.otf.fwid(head,font,attr) return process(head,font,attr,'fwid') end
- function fonts.methods.node.otf.haln(head,font,attr) return process(head,font,attr,'haln') end
- function fonts.methods.node.otf.hist(head,font,attr) return process(head,font,attr,'hist') end
- function fonts.methods.node.otf.hkna(head,font,attr) return process(head,font,attr,'hkna') end
- function fonts.methods.node.otf.hlig(head,font,attr) return process(head,font,attr,'hlig') end
- function fonts.methods.node.otf.hngl(head,font,attr) return process(head,font,attr,'hngl') end
- function fonts.methods.node.otf.hwid(head,font,attr) return process(head,font,attr,'hwid') end
- function fonts.methods.node.otf.init(head,font,attr) return process(head,font,attr,'init',1) end
- function fonts.methods.node.otf.isol(head,font,attr) return process(head,font,attr,'isol',4) end
- function fonts.methods.node.otf.ital(head,font,attr) return process(head,font,attr,'ital') end
- function fonts.methods.node.otf.jp78(head,font,attr) return process(head,font,attr,'jp78') end
- function fonts.methods.node.otf.jp83(head,font,attr) return process(head,font,attr,'jp83') end
- function fonts.methods.node.otf.jp90(head,font,attr) return process(head,font,attr,'jp90') end
- function fonts.methods.node.otf.kern(head,font,attr) return process(head,font,attr,'kern') end
- function fonts.methods.node.otf.liga(head,font,attr) return process(head,font,attr,'liga') end
- function fonts.methods.node.otf.lnum(head,font,attr) return process(head,font,attr,'lnum') end
- function fonts.methods.node.otf.locl(head,font,attr) return process(head,font,attr,'locl') end
- function fonts.methods.node.otf.mark(head,font,attr) return process(head,font,attr,'mark') end
- function fonts.methods.node.otf.med2(head,font,attr) return process(head,font,attr,'med2') end
- function fonts.methods.node.otf.medi(head,font,attr) return process(head,font,attr,'medi',2) end
- function fonts.methods.node.otf.mgrk(head,font,attr) return process(head,font,attr,'mgrk') end
- function fonts.methods.node.otf.mkmk(head,font,attr) return process(head,font,attr,'mkmk') end
- function fonts.methods.node.otf.nalt(head,font,attr) return process(head,font,attr,'nalt') end
- function fonts.methods.node.otf.nlck(head,font,attr) return process(head,font,attr,'nlck') end
- function fonts.methods.node.otf.nukt(head,font,attr) return process(head,font,attr,'nukt') end
- function fonts.methods.node.otf.numr(head,font,attr) return process(head,font,attr,'numr') end
- function fonts.methods.node.otf.onum(head,font,attr) return process(head,font,attr,'onum') end
- function fonts.methods.node.otf.ordn(head,font,attr) return process(head,font,attr,'ordn') end
- function fonts.methods.node.otf.ornm(head,font,attr) return process(head,font,attr,'ornm') end
- function fonts.methods.node.otf.pnum(head,font,attr) return process(head,font,attr,'pnum') end
- function fonts.methods.node.otf.pref(head,font,attr) return process(head,font,attr,'pref') end
- function fonts.methods.node.otf.pres(head,font,attr) return process(head,font,attr,'pres') end
- function fonts.methods.node.otf.pstf(head,font,attr) return process(head,font,attr,'pstf') end
- function fonts.methods.node.otf.rlig(head,font,attr) return process(head,font,attr,'rlig') end
- function fonts.methods.node.otf.rphf(head,font,attr) return process(head,font,attr,'rphf') end
- function fonts.methods.node.otf.rtla(head,font,attr) return process(head,font,attr,'rtla') end
- function fonts.methods.node.otf.salt(head,font,attr) return process(head,font,attr,'calt') end
- function fonts.methods.node.otf.sinf(head,font,attr) return process(head,font,attr,'sinf') end
- function fonts.methods.node.otf.smcp(head,font,attr) return process(head,font,attr,'smcp') end
- function fonts.methods.node.otf.smpl(head,font,attr) return process(head,font,attr,'smpl') end
- function fonts.methods.node.otf.ss01(head,font,attr) return process(head,font,attr,'ss01') end
- function fonts.methods.node.otf.ss02(head,font,attr) return process(head,font,attr,'ss02') end
- function fonts.methods.node.otf.ss03(head,font,attr) return process(head,font,attr,'ss03') end
- function fonts.methods.node.otf.ss04(head,font,attr) return process(head,font,attr,'ss04') end
- function fonts.methods.node.otf.ss05(head,font,attr) return process(head,font,attr,'ss05') end
- function fonts.methods.node.otf.ss06(head,font,attr) return process(head,font,attr,'ss06') end
- function fonts.methods.node.otf.ss07(head,font,attr) return process(head,font,attr,'ss07') end
- function fonts.methods.node.otf.ss08(head,font,attr) return process(head,font,attr,'ss08') end
- function fonts.methods.node.otf.ss09(head,font,attr) return process(head,font,attr,'ss09') end
- function fonts.methods.node.otf.subs(head,font,attr) return process(head,font,attr,'subs') end
- function fonts.methods.node.otf.sups(head,font,attr) return process(head,font,attr,'sups') end
- function fonts.methods.node.otf.swsh(head,font,attr) return process(head,font,attr,'swsh') end
- function fonts.methods.node.otf.titl(head,font,attr) return process(head,font,attr,'titl') end
- function fonts.methods.node.otf.tnam(head,font,attr) return process(head,font,attr,'tnam') end
- function fonts.methods.node.otf.tnum(head,font,attr) return process(head,font,attr,'tnum') end
- function fonts.methods.node.otf.trad(head,font,attr) return process(head,font,attr,'trad') end
- function fonts.methods.node.otf.unic(head,font,attr) return process(head,font,attr,'unic') end
- function fonts.methods.node.otf.zero(head,font,attr) return process(head,font,attr,'zero') end
-
-end
-
--- common stuff
-
-function otf.features.language(tfmdata,value)
- if value then
- value = value:lower()
- if otf.tables.languages[value] then
- tfmdata.language = value
- end
- end
-end
-
-function otf.features.script(tfmdata,value)
- if value then
- value = value:lower()
- if otf.tables.scripts[value] then
- tfmdata.script = value
- end
- end
-end
-
-function otf.features.mode(tfmdata,value)
- if value then
- tfmdata.mode = value:lower()
- end
-end
-
-function otf.features.strategy(tfmdata,value)
- if value then
- tfmdata.strategy = tonumber(value) or otf.strategy
- end
-end
-
-fonts.initializers.base.otf.language = otf.features.language
-fonts.initializers.base.otf.script = otf.features.script
-fonts.initializers.base.otf.mode = otf.features.mode
-fonts.initializers.base.otf.method = otf.features.mode
-fonts.initializers.base.otf.strategy = otf.features.strategy -- not needed
-
-fonts.initializers.node.otf.language = otf.features.language
-fonts.initializers.node.otf.script = otf.features.script
-fonts.initializers.node.otf.mode = otf.features.mode
-fonts.initializers.node.otf.method = otf.features.mode
-fonts.initializers.node.otf.strategy = otf.features.strategy
-
-do
-
- local tlig_list = {
- endash = "hyphen hyphen",
- emdash = "hyphen hyphen hyphen",
- --~ quotedblleft = "quoteleft quoteleft",
- --~ quotedblright = "quoteright quoteright",
- --~ quotedblleft = "grave grave",
- --~ quotedblright = "quotesingle quotesingle",
- --~ quotedblbase = "comma comma",
- }
- local trep_list = {
- --~ [0x0022] = 0x201D,
- [0x0027] = 0x2019,
- --~ [0x0060] = 0x2018,
- }
-
- local tlig_feature = {
- features = { { scripts = { { script = "DFLT", langs = { "dflt" }, } }, tag = "tlig", comment = "added bij mkiv" }, },
- name = "ctx_tlig",
- subtables = { { name = "ctx_tlig_1" } },
- type = "gsub_ligature",
- flags = { },
- always = true
- }
- local trep_feature = {
- features = { { scripts = { { script = "DFLT", langs = { "dflt" }, } }, tag = "trep", comment = "added bij mkiv" }, },
- name = "ctx_trep",
- subtables = { { name = "ctx_trep_1" } },
- type = "gsub_single",
- flags = { },
- always = true
- }
-
- function otf.enhance.enrich(data,filename)
- local glyphs = data.glyphs
- local indices = data.map.map
- for unicode, index in pairs(indices) do
- local glyph = glyphs[index]
- local l = tlig_list[glyph.name]
- if l then
- local o = glyph.lookups or { }
- o["ctx_tlig_1"] = { { "ligature", l, glyph.name } }
- glyph.lookups = o
- end
- local r = trep_list[unicode]
- if r then
- local replacement = indices[r]
- if replacement then
- local o = glyph.lookups or { }
- o["ctx_trep_1"] = { { "substitution", glyphs[replacement].name } } ---
- glyph.lookups = o
- end
- end
- end
- data.gsub = data.gsub or { }
- logs.report("load otf","enhance: registering tlig feature")
- table.insert(data.gsub,1,table.fastcopy(tlig_feature))
- logs.report("load otf","enhance: registering trep feature")
- table.insert(data.gsub,1,table.fastcopy(trep_feature))
- end
-
- local prepare = otf.features.prepare.feature
- local process = otf.features.process.feature
-
- otf.tables.features['tlig'] = 'TeX Ligatures'
- otf.tables.features['trep'] = 'TeX Replacements'
-
- function fonts.initializers.node.otf.tlig(tfm,value) return prepare(tfm,'tlig',value) end
- function fonts.initializers.node.otf.trep(tfm,value) return prepare(tfm,'trep',value) end
-
- function fonts.methods.node.otf.tlig(head,font,attr) return process(head,font,attr,'tlig') end
- function fonts.methods.node.otf.trep(head,font,attr) return process(head,font,attr,'trep') end
-
- function fonts.initializers.base.otf.tlig(tfm,value) otf.features.prepare_base_substitutions(tfm,'tlig',value) end
- function fonts.initializers.base.otf.trep(tfm,value) otf.features.prepare_base_substitutions(tfm,'trep',value) end
-
-end
-
--- we need this because fonts can be bugged
-
--- \definefontfeature[calt][language=nld,script=latn,mode=node,calt=yes,clig=yes,rlig=yes]
--- \definefontfeature[dflt][language=nld,script=latn,mode=node,calt=no, clig=yes,rlig=yes]
--- \definefontfeature[fixd][language=nld,script=latn,mode=node,calt=no, clig=yes,rlig=yes,ignoredrules={44,45,47}]
-
--- \starttext
-
--- {\type{dflt:}\font\test=ZapfinoExtraLTPro*dflt at 24pt \test \char57777\char57812 c/o} \endgraf
--- {\type{calt:}\font\test=ZapfinoExtraLTPro*calt at 24pt \test \char57777\char57812 c/o} \endgraf
--- {\type{fixd:}\font\test=ZapfinoExtraLTPro*fixd at 24pt \test \char57777\char57812 c/o} \endgraf
-
--- \stoptext
-
---~ table.insert(fonts.triggers,"ignoredrules")
-
---~ function fonts.initializers.node.otf.ignoredrules(tfmdata,value)
---~ if value then
---~ -- these tests must move !
---~ tfmdata.unique = tfmdata.unique or { }
---~ tfmdata.unique.ignoredrules = tfmdata.unique.ignoredrules or { }
---~ local ignored = tfmdata.unique.ignoredrules
---~ -- value is already ok now
---~ for s in string.gmatch(value:gsub("[{}]","")..",", "%s*(.-),") do
---~ ignored[tonumber(s)] = true
---~ end
---~ end
---~ end
-
-fonts.initializers.base.otf.equaldigits = fonts.initializers.common.equaldigits
-fonts.initializers.node.otf.equaldigits = fonts.initializers.common.equaldigits
-
-fonts.initializers.base.otf.lineheight = fonts.initializers.common.lineheight
-fonts.initializers.node.otf.lineheight = fonts.initializers.common.lineheight
-
-fonts.initializers.base.otf.compose = fonts.initializers.common.compose
-fonts.initializers.node.otf.compose = fonts.initializers.common.compose
-
--- temp hack, may change
-
-function fonts.initializers.base.otf.kern(tfmdata,value)
- otf.features.prepare_base_kerns(tfmdata,'kern',value)
-end
-
--- bonus function
-
-function otf.name_to_slot(name) -- todo: afm en tfm
- local tfmdata = tfm.id[font.current()]
- if tfmdata and tfmdata.shared then
- local otfdata = tfmdata.shared.otfdata
- if otfdata and otfdata.luatex then
- local unicode = otfdata.luatex.unicodes[name]
- if type(unicode) == "number" then
- return unicode
- else
- return unicode[1]
- end
- end
- end
- return nil
-end
-
-function otf.char(n) -- todo: afm en tfm
- if type(n) == "string" then
- n = otf.name_to_slot(n)
- end
- if n then
- tex.sprint(tex.ctxcatcodes,format("\\char%s ",n))
- end
-end
-
--- Here we plug in some analyzing code (will move to font-tfm).
-
-do
-
- local glyph = node.id('glyph')
- local glue = node.id('glue')
- local penalty = node.id('penalty')
-
- local fontdata = tfm.id
- local set_attribute = node.set_attribute
- local has_attribute = node.has_attribute
- local state = attributes.numbers['state'] or 100
-
- local fcs = fonts.color.set
- local fcr = fonts.color.reset
- local remove = node.remove
-
- -- in the future we will use language/script attributes instead of the
- -- font related value, but then we also need dynamic features which is
- -- somewhat slower; and .. we need a chain of them
-
- local type = type
-
- local initializers, methods = fonts.analyzers.initializers, fonts.analyzers.methods
-
- function fonts.initializers.node.otf.analyze(tfmdata,value,attr)
- if attr and attr > 0 then
- script, language = a_to_script[attr], a_to_language[attr]
- else
- script, language = tfmdata.script, tfmdata.language
- end
- local action = initializers[script]
- if action then
- if type(action) == "function" then
- return action(tfmdata,value)
- else
- local action = action[language]
- if action then
- return action(tfmdata,value)
- end
- end
- end
- return nil
- end
-
- function fonts.methods.node.otf.analyze(head,font,attr)
- local tfmdata = fontdata[font]
- local script, language
- if attr and attr > 0 then
- script, language = a_to_script[attr], a_to_language[attr]
- else
- script, language = tfmdata.script, tfmdata.language
- end
- local action = methods[script]
- if action then
- if type(action) == "function" then
- return action(head,font,attr)
- else
- action = action[language]
- if action then
- return action(head,font,attr)
- end
- end
- end
- return head, false
- end
-
- otf.features.register("analyze",true) -- we always analyze
- table.insert(fonts.triggers,"analyze") -- we need a proper function for doing this
-
- -- latin
-
- fonts.analyzers.methods.latn = fonts.analyzers.aux.setstate
-
- -- this info eventually will go into char-def
-
- local zwnj = 0x200C
- local zwj = 0x200D
-
- local isol = {
- [0x0621] = true, [zwnj] = true,
- }
-
- local isol_fina = {
- [0x0622] = true, [0x0623] = true, [0x0624] = true, [0x0625] = true, [0x0627] = true, [0x062F] = true,
- [0x0630] = true, [0x0631] = true, [0x0632] = true,
- [0x0648] = true, [0x0698] = true,
- [0xFEF5] = true, [0xFEF7] = true, [0xFEF9] = true, [0xFEFB] = true,
- }
-
- local isol_fina_medi_init = {
- [0x0626] = true, [0x0628] = true, [0x0629] = true, [0x062A] = true, [0x062B] = true, [0x062C] = true, [0x062D] = true, [0x062E] = true,
- [0x0633] = true, [0x0634] = true, [0x0635] = true, [0x0636] = true, [0x0637] = true, [0x0638] = true, [0x0639] = true, [0x063A] = true,
- [0x0640] = true, -- tadwil
- [0x0641] = true, [0x0642] = true, [0x0643] = true, [0x0644] = true, [0x0645] = true, [0x0646] = true, [0x0647] = true, [0x0649] = true, [0x064A] = true,
- [0x067E] = true, [0x0686] = true, [0x06AF] = true, [0x06A9] = true, [0x06CC] = true,
- [zwj] = true,
- }
-
- local arab_warned = { }
-
- local function warning(current,what)
- local char = current.char
- if not arab_warned[char] then
- log.report("analyze","arab: character %s (0x%04X) has no %s class", char, char, what)
- arab_warned[char] = true
- end
- end
-
- function fonts.analyzers.methods.nocolor(head,font,attr)
- for n in node.traverse(head,glyph) do
- if not font or n.font == font then
- fcr(n)
- end
- end
- return head, true
- end
-
- otf.remove_joiners = true -- for idris who want it as option
-
- function fonts.analyzers.methods.arab(head,font,attr) -- maybe make a special version with no trace
- local tfmdata = fontdata[font]
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local first, last, current, done = nil, nil, head, false
- local trace, removejoiners = fonts.color.trace, otf.remove_joiners
- --~ local laststate = 0
- local joiners = { }
- local function finish()
- if last then
- if first == last then
- local fc = first.char
- if isol_fina_medi_init[fc] or isol_fina[fc] then
- set_attribute(first,state,4) -- isol
- if trace then fcs(first,"font:isol") end
- else
- warning(first,"isol")
- set_attribute(first,state,0) -- error
- if trace then fcr(first) end
- end
- else
- local lc = last.char
- if isol_fina_medi_init[lc] or isol_fina[lc] then -- why isol here ?
- -- if laststate == 1 or laststate == 2 or laststate == 4 then
- set_attribute(last,state,3) -- fina
- if trace then fcs(last,"font:fina") end
- else
- warning(last,"fina")
- set_attribute(last,state,0) -- error
- if trace then fcr(last) end
- end
- end
- first, last = nil, nil
- elseif first then
- -- first and last are either both set so we never com here
- local fc = first.char
- if isol_fina_medi_init[fc] or isol_fina[fc] then
- set_attribute(first,state,4) -- isol
- if trace then fcs(first,"font:isol") end
- else
- warning(first,"isol")
- set_attribute(first,state,0) -- error
- if trace then fcr(first) end
- end
- first = nil
- end
- --~ laststate = 0
- end
- while current do
- if current.id == glyph and current.subtype<256 and current.font == font and not has_attribute(current,state) then
- done = true
- -- some day we will make a characters.marks hash
- -- this is also more efficient since it's shared
- local char = current.char
- local descriptions = descriptions[char]
- if removejoiners and char == zwj or char == zwnj then
- joiners[#joiners+1] = current
- end
- if descriptions and descriptions.class == "mark" then
- set_attribute(current,state,5) -- mark
- if trace then fcs(current,"font:mark") end
- elseif isol[char] then -- can be zwj or zwnj too
- finish()
- set_attribute(current,state,4) -- isol
- if trace then fcs(current,"font:isol") end
- first, last = nil, nil
- --~ laststate = 0
- elseif not first then
- if isol_fina_medi_init[char] then
- set_attribute(current,state,1) -- init
- if trace then fcs(current,"font:init") end
- first, last = first or current, current
- --~ laststate = 1
- elseif isol_fina[char] then
- set_attribute(current,state,4) -- isol
- if trace then fcs(current,"font:isol") end
- first, last = nil, nil
- --~ laststate = 0
- else -- no arab
- finish()
- end
- elseif isol_fina_medi_init[char] then
- first, last = first or current, current
- set_attribute(current,state,2) -- medi
- if trace then fcs(current,"font:medi") end
- --~ laststate = 2
- elseif isol_fina[char] then
- -- if not laststate == 1 then
- if not has_attribute(last,state,1) then
- -- tricky, we need to check what last may be !
- set_attribute(last,state,2) -- medi
- if trace then fcs(last,"font:medi") end
- end
- set_attribute(current,state,3) -- fina
- if trace then fcs(current,"font:fina") end
- first, last = nil, nil
- --~ laststate = 0
- elseif char >= 0x0600 and char <= 0x06FF then
- if trace then fcs(current,"font:rest") end
- finish()
- else --no
- finish()
- end
- else
- finish()
- end
- current = current.next
- end
- finish()
- if removejoiners then
- for i=1,#joiners do
- head = remove(head,joiners[i])
- end
- end
- return head, done
- end
-
- -- han (chinese) (unfinished)
-
- -- this info eventually will go into char-def
-
- -- in the future we will use language/script attributes instead of the
- -- font related value, but then we also need dynamic features which is
- -- somewhat slower; and .. we need a chain of them
-
- local type = type
-
- local opening_parenthesis_hw = table.tohash { -- half width
- 0x0028,
- 0x005B,
- 0x007B,
- 0x2018, -- ‘
- 0x201C, -- “
- }
-
- local opening_parenthesis_fw = table.tohash { -- full width
- 0x3008, -- 〈 Left book quote
- 0x300A, -- 《 Left double book quote
- 0x300C, -- 「 left quote
- 0x300E, -- 『 left double quote
- 0x3010, -- 【 left double book quote
- 0x3014, -- 〔 left book quote
- 0x3016, --〖 left double book quote
- 0x3018, -- left tortoise bracket
- 0x301A, -- left square bracket
- 0x301D, -- reverse double prime qm
- 0xFF08, -- ( left parenthesis
- 0xFF3B, -- [ left square brackets
- 0xFF5B, -- { left curve bracket
- 0xFF62, -- left corner bracket
- }
-
- local closing_parenthesis_hw = table.tohash { -- half width
- 0x0029,
- 0x005D,
- 0x007D,
- 0x2019, -- ’ right quote, right
- 0x201D, -- ” right double quote
- }
-
- local closing_parenthesis_fw = table.tohash { -- full width
- 0x3009, -- 〉 book quote
- 0x300B, -- 》 double book quote
- 0x300D, -- 」 right quote, right
- 0x300F, -- 』 right double quote
- 0x3011, -- 】 right double book quote
- 0x3015, -- 〕 right book quote
- 0x3017, -- 〗 right double book quote
- 0x3019, -- right tortoise bracket
- 0x301B, -- right square bracket
- 0x301E, -- double prime qm
- 0x301F, -- low double prime qm
- 0xFF09, -- ) right parenthesis
- 0xFF3D, -- ] right square brackets
- 0xFF5D, -- } right curve brackets
- 0xFF63, -- right corner bracket
- }
-
- local opening_vertical = table.tohash {
- 0xFE35, 0xFE37, 0xFE39, 0xFE3B, 0xFE3D, 0xFE3F, 0xFE41, 0xFE43, 0xFE47,
- }
-
- local closing_vertical = table.tohash {
- 0xFE36, 0xFE38, 0xFE3A, 0xFE3C, 0xFE3E, 0xFE40, 0xFE42, 0xFE44, 0xFE48,
- }
-
- local opening_punctuation_hw = table.tohash { -- half width
- }
-
- local opening_punctuation_fw = table.tohash {
- -- 0x2236, -- ∶
- -- 0xFF0C, -- ,
- }
-
- local closing_punctuation_hw = table.tohash { -- half width
- 0x0021, -- !
- 0x002C, -- ,
- 0x002E, -- .
- 0x003A, -- :
- 0x003B, -- ;
- 0x003F, -- ?
- 0xFF61, -- hw full stop
- }
-
- local closing_punctuation_fw = table.tohash { -- full width
- 0x3001, -- 、
- 0x3002, -- 。
- 0xFF01, -- !
- 0xFF0C, -- ,
- 0xFF0E, -- .
- 0xFF1A, -- :
- 0xFF1B, -- ;
- 0xFF1F, -- ?
- }
-
- local non_starter = table.tohash { -- japanese
- 0x3005, 0x3041, 0x3043, 0x3045, 0x3047,
- 0x3049, 0x3063, 0x3083, 0x3085, 0x3087,
- 0x308E, 0x3095, 0x3096, 0x309B, 0x309C,
- 0x309D, 0x309E, 0x30A0, 0x30A1, 0x30A3,
- 0x30A5, 0x30A7, 0x30A9, 0x30C3, 0x30E3,
- 0x30E5, 0x30E7, 0x30EE, 0x30F5, 0x30F6,
- 0x30FC, 0x30FD, 0x30FE, 0x31F0, 0x31F1,
- 0x30F2, 0x30F3, 0x30F4, 0x31F5, 0x31F6,
- 0x30F7, 0x30F8, 0x30F9, 0x31FA, 0x31FB,
- 0x30FC, 0x30FD, 0x30FE, 0x31FF,
- }
-
- -- the characters below are always appear in a double form, so there
- -- will be two Chinese ellipsis characters together that denote
- -- ellipsis marks and it is not allowed to break between them
-
- local hyphenation = table.tohash {
- 0x2026, -- … ellipsis
- 0x2014, -- — hyphen
- }
-
- local function is_han_character(char)
- -- we might add such info to char-def
- return
- (char>=0x03040 and char<=0x0309F) or
- (char>=0x030A0 and char<=0x030FF) or
- (char>=0x031F0 and char<=0x031FF) or
- (char>=0x03400 and char<=0x04DFF) or
- (char>=0x04E00 and char<=0x09FFF) or
- (char>=0x0F900 and char<=0x0FAFF) or
- (char>=0x0FF00 and char<=0x0FFEF) or
- (char>=0x20000 and char<=0x2A6DF) or
- (char>=0x2F800 and char<=0x2FA1F)
- end
- -- maybe an entry in the character table: hanclass
-
- --~ opening_parenthesis_hw / closing_parenthesis_hw
- --~ opening_parenthesis_fw / closing_parenthesis_fw
- --~ opening_punctuation_hw / closing_punctuation_hw
- --~ opening_punctuation_fw / closing_punctuation_fw
-
- --~ non_starter
- --~ hyphenation
-
- --~ opening_vertical / closing_vertical
-
- fonts.analyzers.methods.stretch_hang = true
-
- fonts.analyzers.methods.hang_data = {
- inter_char_stretch_factor = 2.00, -- we started with 0.5, then 1.0
- inter_char_half_factor = 0.50, -- normally there is no reason to change this
- inter_char_half_shrink_factor = 0.25, -- normally there is no reason to change this
- }
-
- local hang_data = fonts.analyzers.methods.hang_data
-
- local insert_after, insert_before, delete = node.insert_after, node.insert_before, nodes.delete
-
- local function nobreak_before(head,current)
- local p = current.prev
- if p then
- p = p.prev
- if p and p.id == penalty then
- p.penalty = 10000
- return head, current
- end
- end
- return insert_before(head,current,nodes.penalty(10000))
- end
-
- function fonts.analyzers.methods.hani(head,font,attr)
- -- maybe make a special version with no trace
- local tfmdata = fontdata[font]
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local current, done, stretch, prevclass = head, false, 0, 0
- if fonts.analyzers.methods.stretch_hang then
- stretch = fontdata[font].parameters.quad
- end
- -- penalty before break
- local interspecialskip = - stretch * hang_data.inter_char_half_factor
- local interspecialshrink = stretch * hang_data.inter_char_half_shrink_factor
- local internormalstretch = stretch * hang_data.inter_char_stretch_factor
- local trace = fonts.color.trace
- -- todo: check for first and last
- -- maybe it's better to look back
--- we need to backtrack a glyph (also other font)
- while current do
- if current.id == glyph and current.subtype<256 then
- if current.font == font then
- local char = current.char
- if false then
- -- don't ask -)
- elseif opening_punctuation_fw[char] or opening_parenthesis_fw[char] then
- if trace then fcs(current,"font:init") end
- if head ~= current then
- head, _ = insert_before(head,current,nodes.glue(interspecialskip,0,interspecialshrink))
- end
- head, current = insert_after(head,current,nodes.penalty(10000))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- prevclass, done = 1, true
- elseif closing_punctuation_fw[char] or closing_parenthesis_fw[char] then
- if trace then fcs(current,"font:fina") end
- if prevclass > 0 then
- head, current = nobreak_before(head,current)
- head, current = insert_after(head,current,nodes.penalty(10000))
- head, current = insert_after(head,current,nodes.glue(interspecialskip,0,interspecialshrink))
- head, current = insert_after(head,current,nodes.penalty(0))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- end
- prevclass, done = 2, true
- elseif opening_punctuation_hw[char] or opening_parenthesis_hw[char] then
- if trace then fcs(current,"font:init") end
- head, current = insert_after(head,current,nodes.penalty(10000))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- prevclass, done = 3, true
- elseif closing_punctuation_hw[char] or closing_parenthesis_hw[char] then
- if trace then fcs(current,"font:fina") end
- if prevclass > 0 then
- head, current = nobreak_before(head,current)
- head, current = insert_after(head,current,nodes.penalty(0))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- end
- prevclass, done = 4, true
- elseif hyphenation[char] then
- if trace then fcs(current,"font:medi") end
- if prevclass > 0 then
- head, current = nobreak_before(head,current)
- head, current = insert_after(head,current,nodes.penalty(0))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- end
- prevclass, done = 5, true
- elseif non_starter[char] then
- if trace then fcs(current,"font:isol") end
- head, current = insert_after(head,current,nodes.penalty(10000))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- prevclass, done = 6, true
- elseif is_han_character(char) then
- -- if trace then fcs(current,"font:isol") end
- prevclass, done = 7, true
- head, current = insert_after(head,current,nodes.penalty(0))
- head, current = insert_after(head,current,nodes.glue(0,internormalstretch,0))
- end
- else
--- here we might have a mixed font
- prevclass = 0
- end
- elseif prevclass > 0 and current.id == glue and current.spec and current.spec.width > 0 then
- -- hack, it might be better to look back and flush (we need to delete end-of-line spaces)
- local next = current.next
- if next.id == glyph and next.font == font then
- head, current = delete(head,current)
- end
- end
- if current then
- current = current.next
- end
- end
- return head, done
- end
-
- fonts.analyzers.methods.hang = fonts.analyzers.methods.hani
-
-end
-
--- experimental and will probably change
-
-do
- local process = otf.features.process.feature
- local prepare = otf.features.prepare.feature
- function fonts.install_feature(type,...)
- if fonts[type] and fonts[type].install_feature then
- fonts[type].install_feature(...)
- end
- end
- function otf.install_feature(tag)
- fonts.methods.node.otf [tag] = function(head,font,attr) return process(head,font,attr,tag) end
- fonts.initializers.node.otf[tag] = function(tfm,value) return prepare(tfm,tag,value) end
- end
-end
diff --git a/tex/context/base/font-oti.lua b/tex/context/base/font-oti.lua
new file mode 100644
index 000000000..cbac6d36a
--- /dev/null
+++ b/tex/context/base/font-oti.lua
@@ -0,0 +1,57 @@
+if not modules then modules = { } end modules ['font-oti'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- i need to check features=yes|no also in relation to hashing
+
+local lower = string.lower
+
+local otf = fonts.otf
+
+otf.default_language = 'latn'
+otf.default_script = 'dflt'
+
+local languages = otf.tables.languages
+local scripts = otf.tables.scripts
+
+function otf.features.language(tfmdata,value)
+ if value then
+ value = lower(value)
+ if languages[value] then
+ tfmdata.language = value
+ end
+ end
+end
+
+function otf.features.script(tfmdata,value)
+ if value then
+ value = lower(value)
+ if scripts[value] then
+ tfmdata.script = value
+ end
+ end
+end
+
+function otf.features.mode(tfmdata,value)
+ if value then
+ tfmdata.mode = lower(value)
+ end
+end
+
+fonts.initializers.base.otf.language = otf.features.language
+fonts.initializers.base.otf.script = otf.features.script
+fonts.initializers.base.otf.mode = otf.features.mode
+fonts.initializers.base.otf.method = otf.features.mode
+
+fonts.initializers.node.otf.language = otf.features.language
+fonts.initializers.node.otf.script = otf.features.script
+fonts.initializers.node.otf.mode = otf.features.mode
+fonts.initializers.node.otf.method = otf.features.mode
+
+otf.features.register("features",true) -- we always do features
+table.insert(fonts.processors,"features") -- we need a proper function for doing this
+
diff --git a/tex/context/base/font-otn.lua b/tex/context/base/font-otn.lua
new file mode 100644
index 000000000..113f90470
--- /dev/null
+++ b/tex/context/base/font-otn.lua
@@ -0,0 +1,2496 @@
+if not modules then modules = { } end modules ['font-otn'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is still somewhat preliminary and it will get better in due time;
+-- much functionality could only be implemented thanks to the husayni font
+-- of Idris Samawi Hamid to who we dedicate this module.
+
+-- we can use more lpegs when lpeg is extended with function args and so
+-- resolving to unicode does not gain much
+
+-- in retrospect it always looks easy but believe it or not, it took a lot
+-- of work to get proper open type support done: buggy fonts, fuzzy specs,
+-- special made testfonts, many skype sessions between taco, idris and me,
+-- torture tests etc etc ... unfortunately the code does not show how much
+-- time it took ...
+
+-- todo:
+--
+-- kerning is probably not yet ok for latin around dics nodes
+-- extension infrastructure (for usage out of context)
+-- sorting features according to vendors/renderers
+-- alternative loop quitters
+-- check cursive and r2l
+-- find out where ignore-mark-classes went
+-- remove unused tables
+-- slide tail (always glue at the end so only needed once
+-- default features (per language, script)
+-- cleanup kern(class) code, remove double info
+-- handle positions (we need example fonts)
+-- handle gpos_single (we might want an extra width field in glyph nodes because adding kerns might interfere)
+
+--[[ldx--
+
This module is a bit more split up that I'd like but since we also want to test
+with plain it has to be so. This module is part of
+and discussion about improvements and functionality mostly happens on the
+ mailing list.
+
+
The specification of OpenType is kind of vague. Apart from a lack of a proper
+free specifications there's also the problem that Microsoft and Adobe
+may have their own interpretation of how and in what order to apply features.
+In general the Microsoft website has more detailed specifications and is a
+better reference. There is also some information in the FontForge help files.
+
+
Because there is so much possible, fonts might contain bugs and/or be made to
+work with certain rederers. These may evolve over time which may have the side
+effect that suddenly fonts behave differently.
+
+
After a lot of experiments (mostly by Taco, me and Idris) we're now at yet another
+implementation. Of course all errors are mine and of course the code can be
+improved. There are quite some optimizations going on here and processing speed
+is currently acceptable. Not all functions are implemented yet, often because I
+lack the fonts for testing. Many scripts are not yet supported either, but I will
+look into them as soon as users ask for it.
+
+
Because there are different interpretations possible, I will extend the code
+with more (configureable) variants. I can also add hooks for users so that they can
+write their own extensions.
+
+
Glyphs are indexed not by unicode but in their own way. This is because there is no
+relationship with unicode at all, apart from the fact that a font might cover certain
+ranges of characters. One character can have multiple shapes. However, at the
+ end we use unicode so and all extra glyphs are mapped into a private
+space. This is needed because we need to access them and has to include
+then in the output eventually.
+
+
The raw table as it coms from gets reorganized in to fit out needs.
+In that table is packed (similar tables are shared) and cached on disk
+so that successive runs can use the optimized table (after loading the table is
+unpacked). The flattening code used later is a prelude to an even more compact table
+format (and as such it keeps evolving).
+
+
This module is sparsely documented because it is a moving target. The table format
+of the reader changes and we experiment a lot with different methods for supporting
+features.
+
+
As with the code, we may decide to store more information in the
+ table.
+
+
Incrementing the version number will force a re-cache. We jump the number by one
+when there's a fix in the library or code that
+results in different tables.
+--ldx]]--
+
+-- action handler chainproc chainmore comment
+--
+-- gsub_single ok ok ok
+-- gsub_multiple ok ok not implemented yet
+-- gsub_alternate ok ok not implemented yet
+-- gsub_ligature ok ok ok
+-- gsub_context ok --
+-- gsub_contextchain ok --
+-- gsub_reversecontextchain ok --
+-- chainsub -- ok
+-- reversesub -- ok
+-- gpos_mark2base ok ok
+-- gpos_mark2ligature ok ok
+-- gpos_mark2mark ok ok
+-- gpos_cursive ok untested
+-- gpos_single ok ok
+-- gpos_pair ok ok
+-- gpos_context ok --
+-- gpos_contextchain ok --
+--
+-- actions:
+--
+-- handler : actions triggered by lookup
+-- chainproc : actions triggered by contextual lookup
+-- chainmore : multiple substitutions triggered by contextual lookup (e.g. fij -> f + ij)
+--
+-- remark: the 'not implemented yet' variants will be done when we have fonts that use them
+-- remark: we need to check what to do with discretionaries
+
+local concat = table.concat
+local format, gmatch, gsub, find, match, lower, strip = string.format, string.gmatch, string.gsub, string.find, string.match, string.lower, string.strip
+local type, next, tonumber, tostring = type, next, tonumber, tostring
+
+local otf = fonts.otf
+local tfm = fonts.tfm
+
+local trace_lookups = false trackers.register("otf.lookups", function(v) trace_lookups = v end)
+local trace_singles = false trackers.register("otf.singles", function(v) trace_singles = v end)
+local trace_multiples = false trackers.register("otf.multiples", function(v) trace_multiples = v end)
+local trace_alternatives = false trackers.register("otf.alternatives", function(v) trace_alternatives = v end)
+local trace_ligatures = false trackers.register("otf.ligatures", function(v) trace_ligatures = v end)
+local trace_contexts = false trackers.register("otf.contexts", function(v) trace_contexts = v end)
+local trace_marks = false trackers.register("otf.marks", function(v) trace_marks = v end)
+local trace_kerns = false trackers.register("otf.kerns", function(v) trace_kerns = v end)
+local trace_cursive = false trackers.register("otf.cursive", function(v) trace_cursive = v end)
+local trace_preparing = false trackers.register("otf.preparing", function(v) trace_preparing = v end)
+local trace_bugs = false trackers.register("otf.bugs", function(v) trace_bugs = v end)
+local trace_details = false trackers.register("otf.details", function(v) trace_details = v end)
+local trace_applied = false trackers.register("otf.applied", function(v) trace_applied = v end)
+local trace_steps = false trackers.register("otf.steps", function(v) trace_steps = v end)
+
+trackers.register("otf.verbose_chain", function(v) otf.setcontextchain(v and "verbose") end)
+trackers.register("otf.normal_chain", function(v) otf.setcontextchain(v and "normal") end)
+
+trackers.register("otf.replacements", "otf.singles,otf.multiples,otf.alternatives,otf.ligatures")
+trackers.register("otf.positions","otf.marks,otf.kerns,otf.cursive")
+trackers.register("otf.actions","otf.replacements,otf.positions")
+trackers.register("otf.injections","nodes.injections")
+
+trackers.register("*otf.sample","otf.steps,otf.actions,otf.analyzing")
+
+local insert_node_after = node.insert_after
+local delete_node = nodes.delete
+local copy_node = node.copy
+local slide_node_list = node.slide
+local set_attribute = node.set_attribute
+local has_attribute = node.has_attribute
+
+local zwnj = 0x200C
+local zwj = 0x200D
+local wildcard = "*"
+local default = "dflt"
+
+local split_at_space = lpeg.Ct(lpeg.splitat(" ")) -- no trailing or multiple spaces anyway
+
+local glyph = node.id('glyph')
+local glue = node.id('glue')
+local kern = node.id('kern')
+local disc = node.id('disc')
+local whatsit = node.id('whatsit')
+
+local state = attributes.private('state')
+local markbase = attributes.private('markbase')
+local markmark = attributes.private('markmark')
+local markdone = attributes.private('markdone')
+local cursbase = attributes.private('cursbase')
+local curscurs = attributes.private('curscurs')
+local cursdone = attributes.private('cursdone')
+local kernpair = attributes.private('kernpair')
+
+local set_mark = nodes.set_mark
+local set_cursive = nodes.set_cursive
+local set_kern = nodes.set_kern
+local set_pair = nodes.set_pair
+
+local markonce = true
+local cursonce = true
+local kernonce = true
+
+local fontdata = fonts.ids
+
+otf.features.process = { }
+
+-- we share some vars here, after all, we have no nested lookups and
+-- less code
+
+local tfmdata = false
+local otfdata = false
+local characters = false
+local descriptions = false
+local marks = false
+local indices = false
+local unicodes = false
+local currentfont = false
+local lookuptable = false
+local anchorlookups = false
+local handlers = { }
+local rlmode = 0
+local featurevalue = false
+
+-- we cheat a bit and assume that a font,attr combination are kind of ranged
+
+local context_setups = fonts.define.specify.context_setups
+local context_numbers = fonts.define.specify.context_numbers
+local context_merged = fonts.define.specify.context_merged
+
+-- we cannot optimize with "start = first_character(head)" because then we don't
+-- know which rlmode we're in which messes up cursive handling later on
+--
+-- head is always a whatsit so we can safely assume that head is not changed
+
+local special_attributes = {
+ init = 1,
+ medi = 2,
+ fina = 3,
+ isol = 4
+}
+
+-- we use this for special testing and documentation
+
+local checkstep = (nodes and nodes.tracers and nodes.tracers.steppers.check) or function() end
+local registerstep = (nodes and nodes.tracers and nodes.tracers.steppers.register) or function() end
+local registermessage = (nodes and nodes.tracers and nodes.tracers.steppers.message) or function() end
+
+local function logprocess(...)
+ if trace_steps then
+ registermessage(...)
+ end
+ logs.report("otf direct",...)
+end
+local function logwarning(...)
+ logs.report("otf direct",...)
+end
+
+local function gref(n)
+ if type(n) == "number" then
+ local description = descriptions[n]
+ local name = description and description.name
+ if name then
+ return format("U+%04X (%s)",n,name)
+ else
+ return format("U+%04X",n)
+ end
+ elseif not n then
+ return ""
+ else
+ local num, nam = { }, { }
+ for i=1,#n do
+ local ni = n[i]
+ num[#num+1] = format("U+%04X",ni)
+ local dni = descriptions[ni]
+ nam[#num] = (dni and dni.name) or "?"
+ end
+ return format("%s (%s)",concat(num," "), concat(nam," "))
+ end
+end
+
+local function cref(kind,chainname,chainlookupname,lookupname,index)
+ if index then
+ return format("feature %s, chain %s, sub %s, lookup %s, index %s",kind,chainname,chainlookupname,lookupname,index)
+ elseif lookupname then
+ return format("feature %s, chain %s, sub %s, lookup %s",kind,chainname or "?",chainlookupname or "?",lookupname)
+ elseif chainlookupname then
+ return format("feature %s, chain %s, sub %s",kind,chainname or "?",chainlookupname)
+ elseif chainname then
+ return format("feature %s, chain %s",kind,chainname)
+ else
+ return format("feature %s",kind)
+ end
+end
+
+local function pref(kind,lookupname)
+ return format("feature %s, lookup %s",kind,lookupname)
+end
+
+-- we can assume that languages that use marks are not hyphenated
+-- we can also assume that at most one discretionary is present
+
+local function markstoligature(kind,lookupname,start,stop,char)
+ local n = copy_node(start)
+ local keep = start
+ local current
+ current, start = insert_node_after(start,start,n)
+ local snext = stop.next
+ current.next = snext
+ if snext then
+ snext.prev = current
+ end
+ start.prev, stop.next = nil, nil
+ current.char, current.subtype, current.components = char, 2, start
+ return keep
+end
+
+local function toligature(kind,lookupname,start,stop,char,markflag,discfound) -- brr head
+ if start ~= stop then
+ if discfound then
+ local lignode = copy_node(start)
+ lignode.font = start.font
+ lignode.char = char
+ lignode.subtype = 2
+ start = node.do_ligature_n(start, stop, lignode)
+ if start.id == disc then
+ local prev = start.prev
+ start = start.next
+ end
+ else -- start is the ligature
+ local deletemarks = markflag ~= "mark"
+ local n = copy_node(start)
+ local current
+ current, start = insert_node_after(start,start,n)
+ local snext = stop.next
+ current.next = snext
+ if snext then
+ snext.prev = current
+ end
+ start.prev, stop.next = nil, nil
+ current.char, current.subtype, current.components = char, 2, start
+ local head = current
+ if deletemarks then
+ if trace_marks then
+ while start do
+ if marks[start.char] then
+ logwarning("%s: remove mark %s",pref(kind,lookupname),gref(start.char))
+ end
+ start = start.next
+ end
+ end
+ else
+ local i = 0
+ while start do
+ if marks[start.char] then
+ set_attribute(start,markdone,i)
+ if trace_marks then
+ logwarning("%s: keep mark %s, gets index %s",pref(kind,lookupname),gref(start.char),i)
+ end
+ head, current = insert_node_after(head,current,copy_node(start))
+ else
+ i = i + 1
+ end
+ start = start.next
+ end
+ start = current.next
+ while start and start.id == glyph do
+ if marks[start.char] then
+ set_attribute(start,markdone,i)
+ if trace_marks then
+ logwarning("%s: keep mark %s, gets index %s",pref(kind,lookupname),gref(start.char),i)
+ end
+ else
+ break
+ end
+ start = start.next
+ end
+ end
+ return head
+ end
+ else
+ start.char = char
+ end
+ return start
+end
+
+function handlers.gsub_single(start,kind,lookupname,replacement)
+ if trace_singles then
+ logprocess("%s: replacing %s by single %s",pref(kind,lookupname),gref(start.char),gref(replacement))
+ end
+ start.char = replacement
+ return start, true
+end
+
+local function alternative_glyph(start,alternatives,kind,chainname,chainlookupname,lookupname) -- chainname and chainlookupname optional
+ local value, choice, n = featurevalue or tfmdata.shared.features[kind], nil, #alternatives -- global value, brrr
+ if value == "random" then
+ local r = math.random(1,n)
+ value, choice = format("random, choice %s",r), alternatives[r]
+ elseif value == "first" then
+ value, choice = format("first, choice %s",1), alternatives[1]
+ elseif value == "last" then
+ value, choice = format("last, choice %s",n), alternatives[n]
+ elseif type(value) ~= "number" then
+ value, choice = "default, choice 1", alternatives[1]
+ elseif value > n then
+ value, choice = format("no %s variants, taking %s",value,n), alternatives[n]
+ elseif value == 0 then
+ value, choice = format("choice %s (no change)",value), start.char
+ elseif value < 1 then
+ value, choice = format("no %s variants, taking %s",value,1), alternatives[1]
+ else
+ value, choice = format("choice %s",value), alternatives[value]
+ end
+ if not choice then
+ logwarning("%s: no variant %s for %s",cref(kind,chainname,chainlookupname,lookupname),value,gref(start.char))
+ choice, value = start.char, format("no replacement instead of %s",value)
+ end
+ return choice, value
+end
+
+function handlers.gsub_alternate(start,kind,lookupname,alternative,sequence)
+ local choice, index = alternative_glyph(start,alternative,kind,lookupname)
+ if trace_alternatives then
+ logprocess("%s: replacing %s by alternative %s (%s)",pref(kind,lookupname),gref(start.char),gref(choice),index)
+ end
+ start.char = choice
+ return start, true
+end
+
+function handlers.gsub_multiple(start,kind,lookupname,multiple)
+ if trace_multiples then
+ logprocess("%s: replacing %s by multiple %s",pref(kind,lookupname),gref(start.char),gref(multiple))
+ end
+ start.char = multiple[1]
+ if #multiple > 1 then
+ for k=2,#multiple do
+ local n = copy_node(start)
+ n.char = multiple[k]
+ local sn = start.next
+ n.next = sn
+ n.prev = start
+ if sn then
+ sn.prev = n
+ end
+ start.next = n
+ start = n
+ end
+ end
+ return start, true
+end
+
+function handlers.gsub_ligature(start,kind,lookupname,ligature,sequence) --or maybe pass lookup ref
+ local s, stop, discfound = start.next, nil, false
+ if marks[start.char] then
+ while s do
+ local id = s.id
+ if id == glyph and s.subtype<256 then
+ if s.font == currentfont then
+ local char = s.char
+ local lg = ligature[1][char]
+ if not lg then
+ break
+ else
+ stop = s
+ ligature = lg
+ s = s.next
+ end
+ else
+ break
+ end
+ else
+ break
+ end
+ end
+ if stop and ligature[2] then
+ if trace_ligatures then
+ local startchar, stopchar = start.char, stop.char
+ start = markstoligature(kind,lookupname,start,stop,ligature[2])
+ logprocess("%s: replacing %s upto %s by ligature %s",pref(kind,lookupname),gref(startchar),gref(stopchar),gref(start.char))
+ else
+ start = markstoligature(kind,lookupname,start,stop,ligature[2])
+ end
+ return start, true
+ end
+ else
+ local skipmark = sequence.flags[1]
+ while s do
+ local id = s.id
+ if id == glyph and s.subtype<256 then
+ if s.font == currentfont then
+ local char = s.char
+ if skipmark and marks[char] then
+ s = s.next
+ else
+ local lg = ligature[1][char]
+ if not lg then
+ break
+ else
+ stop = s
+ ligature = lg
+ s = s.next
+ end
+ end
+ else
+ break
+ end
+ elseif id == disc then
+ discfound = true
+ s = s.next
+ else
+ break
+ end
+ end
+ if stop and ligature[2] then
+ if trace_ligatures then
+ local startchar, stopchar = start.char, stop.char
+ start = toligature(kind,lookupname,start,stop,ligature[2],skipmark,discfound)
+ logprocess("%s: replacing %s upto %s by ligature %s",pref(kind,lookupname),gref(startchar),gref(stopchar),gref(start.char))
+ else
+ start = toligature(kind,lookupname,start,stop,ligature[2],skipmark,discfound)
+ end
+ return start, true
+ end
+ end
+ return start, false
+end
+
+--[[ldx--
+
We get hits on a mark, but we're not sure if the it has to be applied so
+we need to explicitly test for basechar, baselig and basemark entries.
+--ldx]]--
+
+function handlers.gpos_mark2base(start,kind,lookupname,markanchors,sequence)
+ local markchar = start.char
+ if marks[markchar] then
+ local base = start.prev -- [glyph] [start=mark]
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ local basechar = base.char
+ if marks[basechar] then
+ while true do
+ base = base.prev
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ basechar = base.char
+ if not marks[basechar] then
+ break
+ end
+ else
+ if trace_bugs then
+ logwarning("%s: no base for mark %s",pref(kind,lookupname),gref(markchar))
+ end
+ return start, false
+ end
+ end
+ end
+ local baseanchors = descriptions[basechar]
+ if baseanchors then
+ baseanchors = baseanchors.anchors
+ end
+ if baseanchors then
+ local baseanchors = baseanchors['basechar']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma)
+ if trace_marks then
+ logprocess("%s, anchor %s, bound %s: anchoring mark %s to basechar %s => (%s,%s)",
+ pref(kind,lookupname),anchor,bound,gref(markchar),gref(basechar),dx,dy)
+ end
+ return start, true
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s, no matching anchors for mark %s and base %s",pref(kind,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ else -- if trace_bugs then
+ -- logwarning("%s: char %s is missing in font",pref(kind,lookupname),gref(basechar))
+ fonts.register_message(currentfont,basechar,"no base anchors")
+ end
+ elseif trace_bugs then
+ logwarning("%s: prev node is no char",pref(kind,lookupname))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",pref(kind,lookupname),gref(markchar))
+ end
+ return start, false
+end
+
+function handlers.gpos_mark2ligature(start,kind,lookupname,markanchors,sequence)
+ -- check chainpos variant
+ local markchar = start.char
+ if marks[markchar] then
+ local base = start.prev -- [glyph] [optional marks] [start=mark]
+ local index = 1
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ local basechar = base.char
+ if marks[basechar] then
+ index = index + 1
+ while true do
+ base = base.prev
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ basechar = base.char
+ if marks[basechar] then
+ index = index + 1
+ else
+ break
+ end
+ else
+ if trace_bugs then
+ logwarning("%s: no base for mark %s",pref(kind,lookupname),gref(markchar))
+ end
+ return start, false
+ end
+ end
+ end
+ local i = has_attribute(start,markdone)
+ if i then index = i end
+ local baseanchors = descriptions[basechar]
+ if baseanchors then
+ baseanchors = baseanchors.anchors
+ if baseanchors then
+ local baseanchors = baseanchors['baselig']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ ba = ba[index]
+ if ba then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma,index)
+ if trace_marks then
+ logprocess("%s, anchor %s, index %s, bound %s: anchoring mark %s to baselig %s at index %s => (%s,%s)",
+ pref(kind,lookupname),anchor,index,bound,gref(markchar),gref(basechar),index,dx,dy)
+ end
+ return start, true
+ end
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s: no matching anchors for mark %s and baselig %s",pref(kind,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ end
+ else -- if trace_bugs then
+ -- logwarning("%s: char %s is missing in font",pref(kind,lookupname),gref(basechar))
+ fonts.register_message(currentfont,basechar,"no base anchors")
+ end
+ elseif trace_bugs then
+ logwarning("%s: prev node is no char",pref(kind,lookupname))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",pref(kind,lookupname),gref(markchar))
+ end
+ return start, false
+end
+
+function handlers.gpos_mark2mark(start,kind,lookupname,markanchors,sequence)
+ local markchar = start.char
+ if marks[markchar] then
+--~ local alreadydone = markonce and has_attribute(start,markmark)
+--~ if not alreadydone then
+ local base = start.prev -- [glyph] [basemark] [start=mark]
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then -- subtype test can go
+ local basechar = base.char
+ local baseanchors = descriptions[basechar]
+ if baseanchors then
+ baseanchors = baseanchors.anchors
+ if baseanchors then
+ baseanchors = baseanchors['basemark']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma)
+ if trace_marks then
+ logprocess("%s, anchor %s, bound %s: anchoring mark %s to basemark %s => (%s,%s)",
+ pref(kind,lookupname),anchor,bound,gref(markchar),gref(basechar),dx,dy)
+ end
+ return start,true
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s: no matching anchors for mark %s and basemark %s",pref(kind,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ end
+ else -- if trace_bugs then
+ -- logwarning("%s: char %s is missing in font",pref(kind,lookupname),gref(basechar))
+ fonts.register_message(currentfont,basechar,"no base anchors")
+ end
+ elseif trace_bugs then
+ logwarning("%s: prev node is no mark",pref(kind,lookupname))
+ end
+--~ elseif trace_marks and trace_details then
+--~ logprocess("%s, mark %s is already bound (n=%s), ignoring mark2mark",pref(kind,lookupname),gref(markchar),alreadydone)
+--~ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",pref(kind,lookupname),gref(markchar))
+ end
+ return start,false
+end
+
+function handlers.gpos_cursive(start,kind,lookupname,exitanchors,sequence) -- to be checked
+ local alreadydone = cursonce and has_attribute(start,cursbase)
+ if not alreadydone then
+ local done = false
+ local startchar = start.char
+ if marks[startchar] then
+ if trace_cursive then
+ logprocess("%s: ignoring cursive for mark %s",pref(kind,lookupname),gref(startchar))
+ end
+ else
+ local nxt = start.next
+ while not done and nxt and nxt.id == glyph and nxt.subtype<256 and nxt.font == currentfont do
+ local nextchar = nxt.char
+ if marks[nextchar] then
+ -- should not happen (maybe warning)
+ nxt = nxt.next
+ else
+ local entryanchors = descriptions[nextchar]
+ if entryanchors then
+ entryanchors = entryanchors.anchors
+ if entryanchors then
+ entryanchors = entryanchors['centry']
+ if entryanchors then
+ local al = anchorlookups[lookupname]
+ for anchor, entry in next, entryanchors do
+ if al[anchor] then
+ local exit = exitanchors[anchor]
+ if exit then
+ local dx, dy, bound = set_cursive(start,nxt,tfmdata.factor,rlmode,exit,entry,characters[startchar],characters[nextchar])
+ if trace_cursive then
+ logprocess("%s: moving %s to %s cursive (%s,%s) using anchor %s and bound %s",pref(kind,lookupname),gref(startchar),gref(nextchar),dx,dy,anchor,bound)
+ end
+ done = true
+ break
+ end
+ end
+ end
+ end
+ end
+ else -- if trace_bugs then
+ -- logwarning("%s: char %s is missing in font",pref(kind,lookupname),gref(startchar))
+ fonts.register_message(currentfont,startchar,"no entry anchors")
+ end
+ break
+ end
+ end
+ end
+ return start, done
+ else
+ if trace_cursive and trace_details then
+ logprocess("%s, cursive %s is already done",pref(kind,lookupname),gref(start.char),alreadydone)
+ end
+ return start, false
+ end
+end
+
+function handlers.gpos_single(start,kind,lookupname,kerns,sequence)
+ local startchar = start.char
+ local dx, dy = set_pair(start,tfmdata.factor,rlmode,kerns,characters[startchar])
+ if trace_kerns then
+ logprocess("%s: shifting single %s by (%s,%s)",pref(kind,lookupname),gref(startchar),dx,dy)
+ end
+ return start, false
+end
+
+function handlers.gpos_pair(start,kind,lookupname,kerns,sequence)
+ -- todo: kerns in disc nodes: pre, post, replace -> loop over disc too
+ -- todo: kerns in components of ligatures
+ local snext = start.next
+ if not snext then
+ return start, false
+ else
+ local prev, done = start, false
+ local factor = tfmdata.factor
+ while snext and snext.id == glyph and snext.subtype<256 and snext.font == currentfont do
+ local nextchar = snext.char
+local krn = kerns[nextchar]
+ if not krn and marks[nextchar] then
+ prev = snext
+ snext = snext.next
+ else
+ local krn = kerns[nextchar]
+ if not krn then
+ -- skip
+ elseif type(krn) == "table" then
+ if krn[1] == "pair" then
+ local a, b = krn[3], krn[4]
+ if a and #a > 0 then
+ local startchar = start.char
+ local x, y, w, h = set_pair(start,factor,rlmode,a,characters[startchar])
+ if trace_kerns then
+ logprocess("%s: shifting first of pair %s and %s by (%s,%s) and correction (%s,%s)",pref(kind,lookupname),gref(startchar),gref(nextchar),x,y,w,h)
+ end
+ end
+ if b and #b > 0 then
+ local startchar = start.char
+ local x, y, w, h = set_pair(snext,factor,rlmode,b,characters[nextchar])
+ if trace_kerns then
+ logprocess("%s: shifting second of pair %s and %s by (%s,%s) and correction (%s,%s)",pref(kind,lookupname),gref(startchar),gref(nextchar),x,y,w,h)
+ end
+ end
+ else
+ logs.report("%s: check this out (old kern stuff)",pref(kind,lookupname))
+ local a, b = krn[3], krn[7]
+ if a and a ~= 0 then
+ local k = set_kern(snext,factor,rlmode,a)
+ if trace_kerns then
+ logprocess("%s: inserting first kern %s between %s and %s",pref(kind,lookupname),k,gref(prev.char),gref(nextchar))
+ end
+ end
+ if b and b ~= 0 then
+ logwarning("%s: ignoring second kern xoff %s",pref(kind,lookupname),b*factor)
+ end
+ end
+ done = true
+ elseif krn ~= 0 then
+ local k = set_kern(snext,factor,rlmode,krn)
+ if trace_kerns then
+ logprocess("%s: inserting kern %s between %s and %s",pref(kind,lookupname),k,gref(prev.char),gref(nextchar))
+ end
+ done = true
+ end
+ break
+ end
+ end
+ return start, done
+ end
+end
+
+--[[ldx--
+
I will implement multiple chain replacements once I run into a font that uses
+it. It's not that complex to handle.
+--ldx]]--
+
+local chainmores = { }
+local chainprocs = { }
+
+local function logprocess(...)
+ if trace_steps then
+ registermessage(...)
+ end
+ logs.report("otf subchain",...)
+end
+local function logwarning(...)
+ logs.report("otf subchain",...)
+end
+
+-- ['coverage']={
+-- ['after']={ "r" },
+-- ['before']={ "q" },
+-- ['current']={ "a", "b", "c" },
+-- },
+-- ['lookups']={ "ls_l_1", "ls_l_1", "ls_l_1" },
+
+function chainmores.chainsub(start,stop,kind,chainname,currentcontext,cache,lookuplist,chainlookupname,n)
+ logprocess("%s: a direct call to chainsub cannot happen",cref(kind,chainname,chainlookupname))
+ return start, false
+end
+
+-- handled later:
+--
+-- function chainmores.gsub_single(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+-- return chainprocs.gsub_single(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+-- end
+
+function chainmores.gsub_multiple(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+ logprocess("%s: gsub_multiple not yet supported",cref(kind,chainname,chainlookupname))
+ return start, false
+end
+function chainmores.gsub_alternate(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+ logprocess("%s: gsub_alternate not yet supported",cref(kind,chainname,chainlookupname))
+ return start, false
+end
+
+-- handled later:
+--
+-- function chainmores.gsub_ligature(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+-- return chainprocs.gsub_ligature(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,n)
+-- end
+
+local function logprocess(...)
+ if trace_steps then
+ registermessage(...)
+ end
+ logs.report("otf chain",...)
+end
+local function logwarning(...)
+ logs.report("otf chain",...)
+end
+
+-- We could share functions but that would lead to extra function calls with many
+-- arguments, redundant tests and confusing messages.
+
+function chainprocs.chainsub(start,stop,kind,chainname,currentcontext,cache,lookuplist,chainlookupname)
+ logwarning("%s: a direct call to chainsub cannot happen",cref(kind,chainname,chainlookupname))
+ return start, false
+end
+
+-- The reversesub is a special case, which is why we need to store the replacements
+-- in a bit weird way. There is no lookup and the replacement comes from the lookup
+-- itself. It is meant mostly for dealing with Urdu.
+
+function chainprocs.reversesub(start,stop,kind,chainname,currentcontext,cache,replacements)
+ local char = start.char
+ local replacement = replacements[char]
+ if replacement then
+ if trace_singles then
+ logprocess("%s: single reverse replacement of %s by %s",cref(kind,chainname),gref(char),gref(replacement))
+ end
+ start.char = replacement
+ return start, true
+ else
+ return start, false
+ end
+end
+
+--[[ldx--
+
This chain stuff is somewhat tricky since we can have a sequence of actions to be
+applied: single, alternate, multiple or ligature where ligature can be an invalid
+one in the sense that it will replace multiple by one but not neccessary one that
+looks like the combination (i.e. it is the counterpart of multiple then). For
+example, the following is valid:
Therefore we we don't really do the replacement here already unless we have the
+single lookup case. The efficiency of the replacements can be improved by deleting
+as less as needed but that would also mke the code even more messy.
+--ldx]]--
+
+local function delete_till_stop(start,stop,ignoremarks)
+ if start ~= stop then
+ -- todo keep marks
+ local done = false
+ while not done do
+ done = start == stop
+ delete_node(start,start.next)
+ end
+ end
+end
+
+--[[ldx--
+
Here we replace start by a single variant, First we delete the rest of the
+match.
+--ldx]]--
+
+function chainprocs.gsub_single(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,chainindex)
+ -- todo: marks ?
+ if not chainindex then
+ delete_till_stop(start,stop) -- ,currentlookup.flags[1])
+ end
+ local current = start
+ local subtables = currentlookup.subtables
+ while current do
+ if current.id == glyph then
+ local currentchar = current.char
+ local lookupname = subtables[1]
+ local replacement = cache.gsub_single[lookupname]
+ if not replacement then
+ if trace_bugs then
+ logwarning("%s: no single hits",cref(kind,chainname,chainlookupname,lookupname,chainindex))
+ end
+ else
+ replacement = replacement[currentchar]
+ if not replacement then
+ if trace_bugs then
+ logwarning("%s: no single for %s",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(currentchar))
+ end
+ else
+ if trace_singles then
+ logprocess("%s: replacing single %s by %s",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(currentchar),gref(replacement))
+ end
+ current.char = replacement
+ end
+ end
+ return start, true
+ elseif current == stop then
+ break
+ else
+ current = current.next
+ end
+ end
+ return start, false
+end
+
+chainmores.gsub_single = chainprocs.gsub_single
+
+--[[ldx--
+
Here we replace start by a sequence of new glyphs. First we delete the rest of
+the match.
+--ldx]]--
+
+function chainprocs.gsub_multiple(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ delete_till_stop(start,stop)
+ local startchar = start.char
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local replacements = cache.gsub_multiple[lookupname]
+ if not replacements then
+ if trace_bugs then
+ logwarning("%s: no multiple hits",cref(kind,chainname,chainlookupname,lookupname))
+ end
+ else
+ replacements = replacements[startchar]
+ if not replacements then
+ if trace_bugs then
+ logwarning("%s: no multiple for %s",cref(kind,chainname,chainlookupname,lookupname),gref(startchar))
+ end
+ else
+ if trace_multiples then
+ logprocess("%s: replacing %s by multiple characters %s",cref(kind,chainname,chainlookupname,lookupname),gref(startchar),gref(replacements))
+ end
+ local sn = start.next
+ for k=1,#replacements do
+ if k == 1 then
+ start.char = replacements[k]
+ else
+ local n = copy_node(start) -- maybe delete the components and such
+ n.char = replacements[k]
+ n.next, n.prev = sn, start
+ if sn then
+ sn.prev = n
+ end
+ start.next, start = n, n
+ end
+ end
+ return start, true
+ end
+ end
+ return start, false
+end
+
+--[[ldx--
+
Here we replace start by new glyph. First we delete the rest of the match.
+--ldx]]--
+
+function chainprocs.gsub_alternate(start,stop,kind,lookupname,currentcontext,cache,currentlookup)
+ -- todo: marks ?
+ delete_till_stop(start,stop)
+ local current = start
+ local subtables = currentlookup.subtables
+ while current do
+ if current.id == glyph then
+ local currentchar = current.char
+ local lookupname = subtables[1]
+ local alternatives = cache.gsub_alternate[lookupname]
+ if not alternatives then
+ if trace_bugs then
+ logwarning("%s: no alternative hits",cref(kind,chainname,chainlookupname,lookupname))
+ end
+ else
+ alternatives = alternatives[currentchar]
+ if not alternatives then
+ if trace_bugs then
+ logwarning("%s: no alternative for %s",cref(kind,chainname,chainlookupname,lookupname),gref(currentchar))
+ end
+ else
+ local choice, index = alternative_glyph(current,alternatives,kind,chainname,chainlookupname,lookupname)
+ current.char = choice
+ if trace_alternatives then
+ logprocess("%s: replacing single %s by alternative %s (%s)",cref(kind,chainname,chainlookupname,lookupname),index,gref(currentchar),gref(choice),index)
+ end
+ end
+ end
+ return start, true
+ elseif current == stop then
+ break
+ else
+ current = current.next
+ end
+ end
+ return start, false
+end
+
+--[[ldx--
+
When we replace ligatures we use a helper that handles the marks. I might change
+this function (move code inline and handle the marks by a separate function). We
+assume rather stupid ligatures (no complex disc nodes).
+--ldx]]--
+
+function chainprocs.gsub_ligature(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname,chainindex)
+ local startchar = start.char
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local ligatures = cache.gsub_ligature[lookupname]
+ if not ligatures then
+ if trace_bugs then
+ logwarning("%s: no ligature hits",cref(kind,chainname,chainlookupname,lookupname,chainindex))
+ end
+ else
+ ligatures = ligatures[startchar]
+ if not ligatures then
+ if trace_bugs then
+ logwarning("%s: no ligatures starting with %s",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(startchar))
+ end
+ else
+ local s, discfound, last, nofreplacements = start.next, false, stop, 0
+ while s do
+ local id = s.id
+ if id == disc then
+ s = s.next
+ discfound = true
+ else
+ local schar = s.char
+ if marks[schar] then -- marks
+ s = s.next
+ else
+ local lg = ligatures[1][schar]
+ if not lg then
+ break
+ else
+ ligatures, last, nofreplacements = lg, s, nofreplacements + 1
+ if s == stop then
+ break
+ else
+ s = s.next
+ end
+ end
+ end
+ end
+ end
+ local l2 = ligatures[2]
+ if l2 then
+ if chainindex then
+ stop = last
+ end
+ if trace_ligatures then
+ if start == stop then
+ logprocess("%s: replacing character %s by ligature %s",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(startchar),gref(l2))
+ else
+ logprocess("%s: replacing character %s upto %s by ligature %s",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(startchar),gref(stop.char),gref(l2))
+ end
+ end
+ start = toligature(kind,lookup,start,stop,l2,currentlookup.flags[1],discfound)
+ return start, true, nofreplacements
+ elseif trace_bugs then
+ if start == stop then
+ logwarning("%s: replacing character %s by ligature fails",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(startchar))
+ else
+ logwarning("%s: replacing character %s upto %s by ligature fails",cref(kind,chainname,chainlookupname,lookupname,chainindex),gref(startchar),gref(stop.char))
+ end
+ end
+ end
+ end
+ return start, false, 0
+end
+
+chainmores.gsub_ligature = chainprocs.gsub_ligature
+
+function chainprocs.gpos_mark2base(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ local markchar = start.char
+ if marks[markchar] then
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local markanchors = cache.gpos_mark2base[lookupname]
+ if markanchors then
+ markanchors = markanchors[markchar]
+ end
+ if markanchors then
+ local base = start.prev -- [glyph] [start=mark]
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ local basechar = base.char
+ if marks[basechar] then
+ while true do
+ base = base.prev
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ basechar = base.char
+ if not marks[basechar] then
+ break
+ end
+ else
+ if trace_bugs then
+ logwarning("%s: no base for mark %s",pref(kind,lookupname),gref(markchar))
+ end
+ return start, false
+ end
+ end
+ end
+ local baseanchors = descriptions[basechar].anchors
+ if baseanchors then
+ local baseanchors = baseanchors['basechar']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma)
+ if trace_marks then
+ logprocess("%s, anchor %s, bound %s: anchoring mark %s to basechar %s => (%s,%s)",
+ cref(kind,chainname,chainlookupname,lookupname),anchor,bound,gref(markchar),gref(basechar),dx,dy)
+ end
+ return start, true
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s, no matching anchors for mark %s and base %s",cref(kind,chainname,chainlookupname,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ end
+ elseif trace_bugs then
+ logwarning("%s: prev node is no char",cref(kind,chainname,chainlookupname,lookupname))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s has no anchors",cref(kind,chainname,chainlookupname,lookupname),gref(markchar))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",cref(kind,chainname,chainlookupname),gref(markchar))
+ end
+ return start, false
+end
+
+function chainprocs.gpos_mark2ligature(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ local markchar = start.char
+ if marks[markchar] then
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local markanchors = cache.gpos_mark2ligature[lookupname]
+ if markanchors then
+ markanchors = markanchors[markchar]
+ end
+ if markanchors then
+ local base = start.prev -- [glyph] [optional marks] [start=mark]
+ local index = 1
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ local basechar = base.char
+ if marks[basechar] then
+ index = index + 1
+ while true do
+ base = base.prev
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then
+ basechar = base.char
+ if marks[basechar] then
+ index = index + 1
+ else
+ break
+ end
+ else
+ if trace_bugs then
+ logwarning("%s: no base for mark %s",cref(kind,chainname,chainlookupname,lookupname),markchar)
+ end
+ return start, false
+ end
+ end
+ end
+ -- todo: like marks a ligatures hash
+ local i = has_attribute(start,markdone)
+ if i then index = i end
+ local baseanchors = descriptions[basechar].anchors
+ if baseanchors then
+ local baseanchors = baseanchors['baselig']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ ba = ba[index]
+ if ba then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma,index)
+ if trace_marks then
+ logprocess("%s, anchor %s, bound %s: anchoring mark %s to baselig %s at index %s => (%s,%s)",
+ cref(kind,chainname,chainlookupname,lookupname),anchor,a or bound,gref(markchar),gref(basechar),index,dx,dy)
+ end
+ return start, true
+ end
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s: no matching anchors for mark %s and baselig %s",cref(kind,chainname,chainlookupname,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ end
+ elseif trace_bugs then
+ logwarning("feature %s, lookup %s: prev node is no char",kind,lookupname)
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s has no anchors",cref(kind,chainname,chainlookupname,lookupname),gref(markchar))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",cref(kind,chainname,chainlookupname),gref(markchar))
+ end
+ return start, false
+end
+
+function chainprocs.gpos_mark2mark(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ local markchar = start.char
+ if marks[markchar] then
+--~ local alreadydone = markonce and has_attribute(start,markmark)
+--~ if not alreadydone then
+ -- local markanchors = descriptions[markchar].anchors markanchors = markanchors and markanchors.mark
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local markanchors = cache.gpos_mark2mark[lookupname]
+ if markanchors then
+ markanchors = markanchors[markchar]
+ end
+ if markanchors then
+ local base = start.prev -- [glyph] [basemark] [start=mark]
+ if base and base.id == glyph and base.subtype<256 and base.font == currentfont then -- subtype test can go
+ local basechar = base.char
+ local baseanchors = descriptions[basechar].anchors
+ if baseanchors then
+ baseanchors = baseanchors['basemark']
+ if baseanchors then
+ local al = anchorlookups[lookupname]
+ for anchor,ba in next, baseanchors do
+ if al[anchor] then
+ local ma = markanchors[anchor]
+ if ma then
+ local dx, dy, bound = set_mark(start,base,tfmdata.factor,rlmode,ba,ma)
+ if trace_marks then
+ logprocess("%s, anchor %s, bound %s: anchoring mark %s to basemark %s => (%s,%s)",
+ cref(kind,chainname,chainlookupname,lookupname),anchor,bound,gref(markchar),gref(basechar),dx,dy)
+ end
+ return start, true
+ end
+ end
+ end
+ if trace_bugs then
+ logwarning("%s: no matching anchors for mark %s and basemark %s",gref(kind,chainname,chainlookupname,lookupname),gref(markchar),gref(basechar))
+ end
+ end
+ end
+ elseif trace_bugs then
+ logwarning("%s: prev node is no mark",cref(kind,chainname,chainlookupname,lookupname))
+ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s has no anchors",cref(kind,chainname,chainlookupname,lookupname),gref(markchar))
+ end
+--~ elseif trace_marks and trace_details then
+--~ logprocess("%s, mark %s is already bound (n=%s), ignoring mark2mark",pref(kind,lookupname),gref(markchar),alreadydone)
+--~ end
+ elseif trace_bugs then
+ logwarning("%s: mark %s is no mark",cref(kind,chainname,chainlookupname),gref(markchar))
+ end
+ return start, false
+end
+
+-- ! ! ! untested ! ! !
+
+function chainprocs.gpos_cursive(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ local alreadydone = cursonce and has_attribute(start,cursbase)
+ if not alreadydone then
+ local startchar = start.char
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local exitanchors = cache.gpos_cursive[lookupname]
+ if exitanchors then
+ exitanchors = exitanchors[startchar]
+ end
+ if exitanchors then
+ local done = false
+ if marks[startchar] then
+ if trace_cursive then
+ logprocess("%s: ignoring cursive for mark %s",pref(kind,lookupname),gref(startchar))
+ end
+ else
+ local nxt = start.next
+ while not done and nxt and nxt.id == glyph and nxt.subtype<256 and nxt.font == currentfont do
+ local nextchar = nxt.char
+ if marks[nextchar] then
+ -- should not happen (maybe warning)
+ nxt = nxt.next
+ else
+ local entryanchors = descriptions[nextchar]
+ if entryanchors then
+ entryanchors = entryanchors.anchors
+ if entryanchors then
+ entryanchors = entryanchors['centry']
+ if entryanchors then
+ local al = anchorlookups[lookupname]
+ for anchor, entry in next, entryanchors do
+ if al[anchor] then
+ local exit = exitanchors[anchor]
+ if exit then
+ local dx, dy, bound = set_cursive(start,nxt,tfmdata.factor,rlmode,exit,entry,characters[startchar],characters[nextchar])
+ if trace_cursive then
+ logprocess("%s: moving %s to %s cursive (%s,%s) using anchor %s and bound %s",pref(kind,lookupname),gref(startchar),gref(nextchar),dx,dy,anchor,bound)
+ end
+ done = true
+ break
+ end
+ end
+ end
+ end
+ end
+ else -- if trace_bugs then
+ -- logwarning("%s: char %s is missing in font",pref(kind,lookupname),gref(startchar))
+ fonts.register_message(currentfont,startchar,"no entry anchors")
+ end
+ break
+ end
+ end
+ end
+ return start, done
+ else
+ if trace_cursive and trace_details then
+ logprocess("%s, cursive %s is already done",pref(kind,lookupname),gref(start.char),alreadydone)
+ end
+ return start, false
+ end
+ end
+ return start, false
+end
+
+function chainprocs.gpos_single(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+ -- untested
+ local startchar = start.char
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local kerns = cache.gpos_single[lookupname]
+ if kerns then
+ kerns = kerns[startchar]
+ if kerns then
+ local dx, dy = set_pair(start,tfmdata.factor,rlmode,kerns,characters[startchar])
+ if trace_kerns then
+ logprocess("%s: shifting single %s by (%s,%s)",cref(kind,chainname,chainlookupname),gref(startchar),dx,dy)
+ end
+ end
+ end
+ return start, false
+end
+
+-- when machines become faster i will make a shared function
+
+function chainprocs.gpos_pair(start,stop,kind,chainname,currentcontext,cache,currentlookup,chainlookupname)
+-- logwarning("%s: gpos_pair not yet supported",cref(kind,chainname,chainlookupname))
+ local snext = start.next
+ if snext then
+ local startchar = start.char
+ local subtables = currentlookup.subtables
+ local lookupname = subtables[1]
+ local kerns = cache.gpos_pair[lookupname]
+ if kerns then
+ kerns = kerns[startchar]
+ if kerns then
+ local prev, done = start, false
+ local factor = tfmdata.factor
+ while snext and snext.id == glyph and snext.subtype<256 and snext.font == currentfont do
+ local nextchar = snext.char
+local krn = kerns[nextchar]
+ if not krn and marks[nextchar] then
+ prev = snext
+ snext = snext.next
+ else
+--~ local krn = kerns[nextchar]
+ if not krn then
+ -- skip
+ elseif type(krn) == "table" then
+ if krn[1] == "pair" then
+ local a, b = krn[3], krn[4]
+ if a and #a > 0 then
+ local startchar = start.char
+ local x, y, w, h = set_pair(start,factor,rlmode,a,characters[startchar])
+ if trace_kerns then
+ logprocess("%s: shifting first of pair %s and %s by (%s,%s) and correction (%s,%s)",cref(kind,chainname,chainlookupname),gref(startchar),gref(nextchar),x,y,w,h)
+ end
+ end
+ if b and #b > 0 then
+ local startchar = start.char
+ local x, y, w, h = set_pair(snext,factor,rlmode,b,characters[nextchar])
+ if trace_kerns then
+ logprocess("%s: shifting second of pair %s and %s by (%s,%s) and correction (%s,%s)",cref(kind,chainname,chainlookupname),gref(startchar),gref(nextchar),x,y,w,h)
+ end
+ end
+ else
+ logs.report("%s: check this out (old kern stuff)",cref(kind,chainname,chainlookupname))
+ local a, b = krn[3], krn[7]
+ if a and a ~= 0 then
+ local k = set_kern(snext,factor,rlmode,a)
+ if trace_kerns then
+ logprocess("%s: inserting first kern %s between %s and %s",cref(kind,chainname,chainlookupname),k,gref(prev.char),gref(nextchar))
+ end
+ end
+ if b and b ~= 0 then
+ logwarning("%s: ignoring second kern xoff %s",cref(kind,chainname,chainlookupname),b*factor)
+ end
+ end
+ done = true
+ elseif krn ~= 0 then
+ local k = set_kern(snext,factor,rlmode,krn)
+ if trace_kerns then
+ logprocess("%s: inserting kern %s between %s and %s",cref(kind,chainname,chainlookupname),k,gref(prev.char),gref(nextchar))
+ end
+ done = true
+ end
+ break
+ end
+ end
+ return start, done
+ end
+ end
+ end
+ return start, false
+end
+
+-- what pointer to return, spec says stop
+-- to be discussed ... is bidi changer a space?
+-- elseif char == zwnj and sequence[n][32] then -- brrr
+
+-- somehow l or f is global
+-- we don't need to pass the currentcontext, saves a bit
+-- make a slow variant then can be activated but with more tracing
+
+local function normal_handle_contextchain(start,kind,chainname,contexts,sequence,cache)
+ -- local rule, lookuptype, sequence, f, l, lookups = ck[1], ck[2] ,ck[3], ck[4], ck[5], ck[6]
+ local flags, done = sequence.flags, false
+ local skipmark, skipligature, skipbase = flags[1], flags[2], flags[3]
+ local someskip = skipmark or skipligature or skipbase -- could be stored in flags for a fast test (hm, flags could be false !)
+ for k=1,#contexts do
+ local match, current, last = true, start, start
+ local ck = contexts[k]
+ local sequence = ck[3]
+ local s = #sequence
+ if s == 1 then
+ -- never happens
+ match = current.id == glyph and current.subtype<256 and current.font == currentfont and sequence[1][current.char]
+ else
+ -- todo: better space check (maybe check for glue)
+ local f, l = ck[4], ck[5]
+ if f == l then
+ -- already a hit
+ match = true
+ else
+ -- no need to test first hit (to be optimized)
+ local n = f + 1
+ last = last.next
+ -- we cannot optimize for n=2 because there can be disc nodes
+ -- if not someskip and n == l then
+ -- -- n=2 and no skips then faster loop
+ -- match = last and last.id == glyph and last.subtype<256 and last.font == currentfont and sequence[n][last.char]
+ -- else
+ while n <= l do
+ if last then
+ local id = last.id
+ if id == glyph then
+ if last.subtype<256 and last.font == currentfont then
+ local char = last.char
+ local ccd = descriptions[char]
+ if ccd then
+ local class = ccd.class
+ if class == skipmark or class == skipligature or class == skipbase then
+--~ if someskip and class == skipmark or class == skipligature or class == skipbase then
+ -- skip 'm
+ last = last.next
+ elseif sequence[n][char] then
+ if n < l then
+ last = last.next
+ end
+ n = n + 1
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ elseif id == disc then -- what to do with kerns?
+ last = last.next
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ end
+ -- end
+ end
+ if match and f > 1 then
+ local prev = start.prev
+ if prev then
+ local n = f-1
+ while n >= 1 do
+ if prev then
+ local id = prev.id
+ if id == glyph then
+ if prev.subtype<256 and prev.font == currentfont then -- normal char
+ local char = prev.char
+ local ccd = descriptions[char]
+ if ccd then
+ local class = ccd.class
+ if class == skipmark or class == skipligature or class == skipbase then
+--~ if someskip and class == skipmark or class == skipligature or class == skipbase then
+ -- skip 'm
+ elseif sequence[n][char] then
+ n = n -1
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ elseif id == disc then
+ -- skip 'm
+ elseif sequence[n][32] then
+ n = n -1
+ else
+ match = false break
+ end
+ prev = prev.prev
+ elseif sequence[n][32] then
+ n = n -1
+ else
+ match = false break
+ end
+ end
+ elseif f == 2 then
+ match = sequence[1][32]
+ else
+ for n=f-1,1 do
+ if not sequence[n][32] then
+ match = false break
+ end
+ end
+ end
+ end
+ if match and s > l then
+ local current = last.next
+ if current then
+ -- removed optimiziation for s-l == 1, we have to deal with marks anyway
+ local n = l + 1
+ while n <= s do
+ if current then
+ local id = current.id
+ if id == glyph then
+ if current.subtype<256 and current.font == currentfont then -- normal char
+ local char = current.char
+ local ccd = descriptions[char]
+ if ccd then
+ local class = ccd.class
+ if class == skipmark or class == skipligature or class == skipbase then
+--~ if someskip and class == skipmark or class == skipligature or class == skipbase then
+ -- skip 'm
+ elseif sequence[n][char] then
+ n = n + 1
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ else
+ match = false break
+ end
+ elseif id == disc then
+ -- skip 'm
+ elseif sequence[n][32] then -- brrr
+ n = n + 1
+ else
+ match = false break
+ end
+ current = current.next
+ elseif sequence[n][32] then
+ n = n + 1
+ else
+ match = false break
+ end
+ end
+ elseif s-l == 1 then
+ match = sequence[s][32]
+ else
+ for n=l+1,s do
+ if not sequence[n][32] then
+ match = false break
+ end
+ end
+ end
+ end
+ end
+ if match then
+ -- ck == currentcontext
+ if trace_contexts then
+ local rule, lookuptype, sequence, f, l = ck[1], ck[2] ,ck[3], ck[4], ck[5]
+ local char = start.char
+ if ck[9] then
+ logwarning("%s: rule %s matches at char %s for (%s,%s,%s) chars, lookuptype %s (%s=>%s)",cref(kind,chainname),rule,gref(char),f-1,l-f+1,s-l,lookuptype,ck[9],ck[10])
+ else
+ logwarning("%s: rule %s matches at char %s for (%s,%s,%s) chars, lookuptype %s",cref(kind,chainname),rule,gref(char),f-1,l-f+1,s-l,lookuptype)
+ end
+ end
+ local chainlookups = ck[6]
+ if chainlookups then
+ local nofchainlookups = #chainlookups
+ -- we can speed this up if needed
+ if nofchainlookups == 1 then
+ local chainlookupname = chainlookups[1]
+ local chainlookup = lookuptable[chainlookupname]
+ local cp = chainprocs[chainlookup.type]
+ if cp then
+ start, done = cp(start,last,kind,chainname,ck,cache,chainlookup,chainlookupname)
+ else
+ logprocess("%s: %s is not yet supported",cref(kind,chainname,chainlookupname),chainlookup.type)
+ end
+ else
+ -- actually this needs a more complex treatment for which we will use chainmores
+ local i = 1
+ repeat
+ local chainlookupname = chainlookups[i]
+ local chainlookup = lookuptable[chainlookupname]
+ local cp = chainmores[chainlookup.type]
+ if cp then
+ local ok, n
+ start, ok, n = cp(start,last,kind,chainname,ck,cache,chainlookup,chainlookupname,i)
+ -- messy since last can be changed !
+ if ok then
+ done = true
+ start = start.next
+ if n then
+ -- skip next one(s) if ligature
+ i = i + n - 1
+ end
+ end
+ else
+ logprocess("%s: multiple subchains for %s are not yet supported",cref(kind,chainname,chainlookupname),chainlookup.type)
+ end
+ i = i + 1
+ until i > nofchainlookups
+ end
+ else
+ local replacements = ck[7]
+ if replacements then
+ start, done = chainprocs.reversesub(start,last,kind,chainname,ck,cache,replacements)
+ else
+ done = true -- can be meant to be skipped
+ if trace_contexts then
+ logprocess("%s: skipping match",cref(kind,chainname))
+ end
+ end
+ end
+ end
+ end
+ return start, done
+end
+
+-- Because we want to keep this elsewhere (an because speed is less an issue) we
+-- pass the font id so that the verbose variant can access the relevant helper tables.
+
+local verbose_handle_contextchain = function(font,...)
+ logwarning("no verbose handler installed, reverting to 'normal'")
+ otf.setcontextchain()
+ return normal_handle_contextchain(...)
+end
+
+otf.chainhandlers = {
+ normal = normal_handle_contextchain,
+ verbose = verbose_handle_contextchain,
+}
+
+function otf.setcontextchain(method)
+ if not method or method == "normal" or not otf.chainhandlers[method] then
+ if handlers.contextchain then -- no need for a message while making the format
+ logwarning("installing normal contextchain handler")
+ end
+ handlers.contextchain = normal_handle_contextchain
+ else
+ logwarning("installing contextchain handler '%s'",method)
+ local handler = otf.chainhandlers[method]
+ handlers.contextchain = function(...)
+ return handler(currentfont,...)
+ end
+ end
+ handlers.gsub_context = handlers.contextchain
+ handlers.gsub_contextchain = handlers.contextchain
+ handlers.gsub_reversecontextchain = handlers.contextchain
+ handlers.gpos_contextchain = handlers.contextchain
+ handlers.gpos_context = handlers.contextchain
+end
+
+otf.setcontextchain()
+
+local missing = { } -- we only report once
+
+local function logprocess(...)
+ if trace_steps then
+ registermessage(...)
+ end
+ logs.report("otf process",...)
+end
+local function logwarning(...)
+ logs.report("otf process",...)
+end
+
+local function report_missing_cache(typ,lookup)
+ local f = missing[currentfont] if not f then f = { } missing[currentfont] = f end
+ local t = f[typ] if not t then t = { } f[typ] = t end
+ if not t[lookup] then
+ t[lookup] = true
+ logwarning("missing cache for lookup %s of type %s in font %s (%s)",lookup,typ,currentfont,tfmdata.fullname)
+ end
+end
+
+local resolved = { } -- we only resolve a font,script,language pair once
+
+function fonts.methods.node.otf.features(head,font,attr)
+ if trace_steps then
+ checkstep(head)
+ end
+ tfmdata = fontdata[font]
+ local shared = tfmdata.shared
+ otfdata = shared.otfdata
+ local luatex = otfdata.luatex
+ descriptions = tfmdata.descriptions
+ characters = tfmdata.characters
+ indices = tfmdata.indices
+ unicodes = tfmdata.unicodes
+ marks = tfmdata.marks
+ anchorlookups = luatex.lookup_to_anchor
+ currentfont = font
+ rlmode = 0
+ local featuredata = otfdata.shared.featuredata -- can be made local to closure
+ local sequences = luatex.sequences
+ lookuptable = luatex.lookups
+ local done = false
+ local script, language, s_enabled, a_enabled, dyn
+ local attribute_driven = attr and attr ~= 0
+ if attribute_driven then
+ local features = context_setups[context_numbers[attr]] -- could be a direct list
+ dyn = context_merged[attr] or 0
+ language, script = features.language or "dflt", features.script or "dflt"
+ a_enabled = features -- shared.features -- can be made local to the resolver
+ if dyn == 2 or dyn == -2 then
+ -- font based
+ s_enabled = shared.features
+ end
+ else
+ language, script = tfmdata.language or "dflt", tfmdata.script or "dflt"
+ s_enabled = shared.features -- can be made local to the resolver
+ dyn = 0
+ end
+ -- we can save some runtime by caching feature tests
+ local res = resolved[font] if not res then res = { } resolved[font] = res end
+ local rs = res [script] if not rs then rs = { } res [script] = rs end
+ local rl = rs [language] if not rl then rl = { } rs [language] = rl end
+ local ra = rl [attr] if ra == nil then ra = { } rl [attr] = ra end -- attr can be false
+ -- sequences always > 1 so no need for optimization
+ for s=1,#sequences do
+ local success = false
+ local sequence = sequences[s]
+ local r = ra[s] -- cache
+ if r == nil then
+ --
+ -- this bit will move to font-ctx and become a function
+ ---
+ local chain = sequence.chain or 0
+ local features = sequence.features
+ if not features then
+ -- indirect lookup, part of chain (todo: make this a separate table)
+ r = false -- { false, false, chain }
+ else
+ local valid, attribute, kind, what = false, false
+ for k,v in next, features do
+ -- we can quit earlier but for the moment we want the tracing
+ local s_e = s_enabled and s_enabled[k]
+ local a_e = a_enabled and a_enabled[k]
+ if s_e or a_e then
+ local l = v[script] or v[wildcard]
+ if l then
+ -- not l[language] or l[default] or l[wildcard] because we want tracing
+ -- only first attribute match check, so we assume simple fina's
+ -- default can become a font feature itself
+ if l[language] then
+--~ valid, what = true, language
+ valid, what = s_e or a_e, language
+ -- elseif l[default] then
+ -- valid, what = true, default
+ elseif l[wildcard] then
+--~ valid, what = true, wildcard
+ valid, what = s_e or a_e, wildcard
+ end
+ if valid then
+ kind, attribute = k, special_attributes[k] or false
+ if a_e and dyn < 0 then
+ valid = false
+ end
+ if trace_applied then
+ local typ, action = match(sequence.type,"(.*)_(.*)")
+ logs.report("otf node mode",
+ "%s font: %03i, dynamic: %03i, kind: %s, lookup: %3i, script: %-4s, language: %-4s (%-4s), type: %s, action: %s, name: %s",
+ (valid and "+") or "-",font,attr or 0,kind,s,script,language,what,typ,action,sequence.name)
+ end
+ break
+ end
+ end
+ end
+ end
+ if valid then
+ r = { valid, attribute, chain, kind }
+ else
+ r = false -- { valid, attribute, chain, "generic" } -- false anyway, could be flag instead of table
+ end
+ end
+ ra[s] = r
+ end
+featurevalue = r and r[1] -- toto: pass to function instead
+ if featurevalue then
+ local attribute, chain, typ, subtables = r[2], r[3], sequence.type, sequence.subtables
+ if chain < 0 then
+ -- this is a limited case, no special treatments like 'init' etc
+ local handler = handlers[typ]
+ local thecache = featuredata[typ] or { }
+ -- we need to get rid of this slide !
+ start = slide_node_list(head) -- slow (we can store tail because there's always a skip at the end): todo
+ while start do
+ local id = start.id
+ if id == glyph then
+--~ if start.subtype<256 and start.font == font and (not attr or has_attribute(start,0,attr)) then
+ if start.subtype<256 and start.font == font and has_attribute(start,0,attr) then
+ for i=1,#subtables do
+ local lookupname = subtables[i]
+ local lookupcache = thecache[lookupname]
+ if lookupcache then
+ local lookupmatch = lookupcache[start.char]
+ if lookupmatch then
+ start, success = handler(start,r[4],lookupname,lookupmatch,sequence,featuredata,i)
+ if success then
+ break
+ end
+ end
+ else
+ report_missing_cache(typ,lookupname)
+ end
+ end
+ if start then start = start.prev end
+ else
+ start = start.prev
+ end
+ else
+ start = start.prev
+ end
+ end
+ else
+ local handler = handlers[typ]
+ local ns = #subtables
+ local thecache = featuredata[typ] or { }
+ start = head -- local ?
+ rlmode = 0
+ if ns == 1 then
+ local lookupname = subtables[1]
+ local lookupcache = thecache[lookupname]
+ if not lookupcache then
+ report_missing_cache(typ,lookupname)
+ else
+ while start do
+ local id = start.id
+ if id == glyph then
+--~ if start.font == font and start.subtype<256 and (not attr or has_attribute(start,0,attr)) and (not attribute or has_attribute(start,state,attribute)) then
+ if start.font == font and start.subtype<256 and has_attribute(start,0,attr) and (not attribute or has_attribute(start,state,attribute)) then
+ local lookupmatch = lookupcache[start.char]
+ if lookupmatch then
+ -- sequence kan weg
+ local ok
+ start, ok = handler(start,r[4],lookupname,lookupmatch,sequence,featuredata,1)
+ if ok then
+ success = true
+ end
+ end
+ if start then start = start.next end
+ else
+ start = start.next
+ end
+ -- elseif id == glue then
+ -- if p[5] then -- chain
+ -- local pc = pp[32]
+ -- if pc then
+ -- start, ok = start, false -- p[1](start,kind,p[2],pc,p[3],p[4])
+ -- if ok then
+ -- done = true
+ -- end
+ -- if start then start = start.next end
+ -- else
+ -- start = start.next
+ -- end
+ -- else
+ -- start = start.next
+ -- end
+ elseif id == whatsit then
+ local subtype = start.subtype
+ if subtype == 7 then
+ local dir = start.dir
+ if dir == "+TRT" then
+ rlmode = -1
+ elseif dir == "+TLT" then
+ rlmode = 1
+ else
+ rlmode = 0
+ end
+ elseif subtype == 6 then
+ local dir = start.dir
+ if dir == "TRT" then
+ rlmode = -1
+ elseif dir == "TLT" then
+ rlmode = 1
+ else
+ rlmode = 0
+ end
+ end
+ start = start.next
+ else
+ start = start.next
+ end
+ end
+
+ end
+ else
+ while start do
+ local id = start.id
+ if id == glyph then
+--~ if start.subtype<256 and start.font == font and (not attr or has_attribute(start,0,attr)) and (not attribute or has_attribute(start,state,attribute)) then
+ if start.subtype<256 and start.font == font and has_attribute(start,0,attr) and (not attribute or has_attribute(start,state,attribute)) then
+ for i=1,ns do
+ local lookupname = subtables[i]
+ local lookupcache = thecache[lookupname]
+ if lookupcache then
+ local lookupmatch = lookupcache[start.char]
+ if lookupmatch then
+ -- we could move all code inline but that makes things even more unreadable
+ local ok
+ start, ok = handler(start,r[4],lookupname,lookupmatch,sequence,featuredata,i)
+ if ok then
+ success = true
+ break
+ end
+ end
+ else
+ report_missing_cache(typ,lookupname)
+ end
+ end
+ if start then start = start.next end
+ else
+ start = start.next
+ end
+ -- elseif id == glue then
+ -- if p[5] then -- chain
+ -- local pc = pp[32]
+ -- if pc then
+ -- start, ok = start, false -- p[1](start,kind,p[2],pc,p[3],p[4])
+ -- if ok then
+ -- done = true
+ -- end
+ -- if start then start = start.next end
+ -- else
+ -- start = start.next
+ -- end
+ -- else
+ -- start = start.next
+ -- end
+ elseif id == whatsit then
+ local subtype = start.subtype
+ if subtype == 7 then
+ local dir = start.dir
+ if dir == "+TRT" then
+ rlmode = -1
+ elseif dir == "+TLT" then
+ rlmode = 1
+ else
+ rlmode = 0
+ end
+ elseif subtype == 6 then
+ local dir = start.dir
+ if dir == "TRT" then
+ rlmode = -1
+ elseif dir == "TLT" then
+ rlmode = 1
+ else
+ rlmode = 0
+ end
+ end
+ start = start.next
+ else
+ start = start.next
+ end
+ end
+ end
+ end
+ if success then
+ done = true
+ end
+ if trace_steps then -- ?
+ registerstep(head)
+ end
+ end
+ end
+ return head, done
+end
+
+otf.features.prepare = { }
+
+-- we used to share code in the following functions but that costs a lot of
+-- memory due to extensive calls to functions (easily hundreds of thousands per
+-- document)
+
+local function split(replacement,original,cache,unicodes)
+ -- we can cache this too, but not the same
+ local o, t, n = { }, { }, 0
+ for s in gmatch(original,"[^ ]+") do
+ local us = unicodes[s]
+ if type(us) == "number" then
+ o[#o+1] = us
+ else
+ o[#o+1] = us[1]
+ end
+ end
+ for s in gmatch(replacement,"[^ ]+") do
+ n = n + 1
+ local us = unicodes[s]
+ if type(us) == "number" then
+ t[o[n]] = us
+ else
+ t[o[n]] = us[1]
+ end
+ end
+ return t
+end
+
+local function uncover(covers,result,cache,unicodes)
+ -- lpeg hardly faster (.005 sec on mk)
+ for n=1,#covers do
+ local c = covers[n]
+ local cc = cache[c]
+ if not cc then
+ local t = { }
+ for s in gmatch(c,"[^ ]+") do
+ local us = unicodes[s]
+ if type(us) == "number" then
+ t[us] = true
+ else
+ for i=1,#us do
+ t[us[i]] = true
+ end
+ end
+ end
+ cache[c] = t
+ result[#result+1] = t
+ else
+ result[#result+1] = cc
+ end
+ end
+end
+
+local function prepare_lookups(tfmdata)
+ local otfdata = tfmdata.shared.otfdata
+ local featuredata = otfdata.shared.featuredata
+ local anchor_to_lookup = otfdata.luatex.anchor_to_lookup
+ local lookup_to_anchor = otfdata.luatex.lookup_to_anchor
+ --
+ local multiple = featuredata.gsub_multiple
+ local alternate = featuredata.gsub_alternate
+ local single = featuredata.gsub_single
+ local ligature = featuredata.gsub_ligature
+ local pair = featuredata.gpos_pair
+ local position = featuredata.gpos_single
+ local kerns = featuredata.gpos_pair
+ local mark = featuredata.gpos_mark2mark
+ local cursive = featuredata.gpos_cursive
+ --
+ local unicodes = tfmdata.unicodes -- names to unicodes
+ local indices = tfmdata.indices
+ local descriptions = tfmdata.descriptions
+ --
+ -- we can change the otf table after loading but then we need to adapt base mode
+ -- as well (no big deal)
+ --
+ for unicode, glyph in next, descriptions do
+ local lookups = glyph.lookups
+ if lookups then
+ for lookup, whatever in next, lookups do
+ for i=1,#whatever do -- normaly one
+ local p = whatever[i]
+ local what = p[1]
+ if what == 'substitution' then
+ local old, new = unicode, unicodes[p[2]]
+ if type(new) == "table" then
+ new = new[1]
+ end
+ local s = single[lookup]
+ if not s then s = { } single[lookup] = s end
+ s[old] = new
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: substitution %s => %s",lookup,old,new)
+--~ end
+ break
+ elseif what == 'multiple' then
+ local old, new = unicode, { }
+ local m = multiple[lookup]
+ if not m then m = { } multiple[lookup] = m end
+ m[old] = new
+ for pc in gmatch(p[2],"[^ ]+") do
+ local upc = unicodes[pc]
+ if type(upc) == "number" then
+ new[#new+1] = upc
+ else
+ new[#new+1] = upc[1]
+ end
+ end
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: multiple %s => %s",lookup,old,concat(new," "))
+--~ end
+ break
+ elseif what == 'alternate' then
+ local old, new = unicode, { }
+ local a = alternate[lookup]
+ if not a then a = { } alternate[lookup] = a end
+ a[old] = new
+ for pc in gmatch(p[2],"[^ ]+") do
+ local upc = unicodes[pc]
+ if type(upc) == "number" then
+ new[#new+1] = upc
+ else
+ new[#new+1] = upc[1]
+ end
+ end
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: alternate %s => %s",lookup,old,concat(new,"|"))
+--~ end
+ break
+ elseif what == "ligature" then
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: ligature %s => %s",lookup,p[2],glyph.name)
+--~ end
+ local first = true
+ local t = ligature[lookup]
+ if not t then t = { } ligature[lookup] = t end
+ for s in gmatch(p[2],"[^ ]+") do
+ if first then
+ local u = unicodes[s]
+ if not u then
+ logs.report("define otf","lookup %s: ligature %s => %s ignored due to invalid unicode",lookup,p[2],glyph.name)
+ break
+ elseif type(u) == "number" then
+ if not t[u] then
+ t[u] = { { } }
+ end
+ t = t[u]
+ else
+ local tt = t
+ local tu
+ for i=1,#u do
+ local u = u[i]
+ if i==1 then
+ if not t[u] then
+ t[u] = { { } }
+ end
+ tu = t[u]
+ t = tu
+ else
+ if not t[u] then
+ tt[u] = tu
+ end
+ end
+ end
+ end
+ first = false
+ else
+ s = unicodes[s]
+ local t1 = t[1]
+ if not t1[s] then
+ t1[s] = { { } }
+ end
+ t = t1[s]
+ end
+ end
+ t[2] = unicode
+ elseif what == 'position' then
+ -- not used
+ local s = position[lookup]
+ if not s then s = { } position[lookup] = s end
+ s[unicode] = p[2] -- direct pointer to kern spec
+ elseif what == 'pair' then
+ local s = pair[lookup]
+ if not s then s = { } pair[lookup] = s end
+ local others = s[unicode]
+ if not others then others = { } s[unicode] = others end
+ -- todo: fast check for space
+ local two = p[2]
+ local upc = unicodes[two]
+ if not upc then
+ for pc in gmatch(two,"[^ ]+") do
+ local upc = unicodes[pc]
+ if type(upc) == "number" then
+ others[upc] = p -- direct pointer to main table
+ else
+ for i=1,#upc do
+ others[upc[i]] = p -- direct pointer to main table
+ end
+ end
+ end
+ elseif type(upc) == "number" then
+ others[upc] = p -- direct pointer to main table
+ else
+ for i=1,#upc do
+ others[upc[i]] = p -- direct pointer to main table
+ end
+ end
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: pair for U+%04X",lookup,unicode)
+--~ end
+ end
+ end
+ end
+ end
+ local list = glyph.mykerns
+ if list then
+ for lookup, krn in next, list do
+ local k = kerns[lookup]
+ if not k then k = { } kerns[lookup] = k end
+ k[unicode] = krn -- ref to glyph, saves lookup
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: kern for U+%04X",lookup,unicode)
+--~ end
+ end
+ end
+ local oanchor = glyph.anchors
+ if oanchor then
+ for typ, anchors in next, oanchor do -- types
+ if typ == "mark" then
+ for name, anchor in next, anchors do
+ local lookups = anchor_to_lookup[name]
+ if lookups then
+ for lookup, _ in next, lookups do
+ local f = mark[lookup]
+ if not f then f = { } mark[lookup] = f end
+ f[unicode] = anchors -- ref to glyph, saves lookup
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: mark anchor %s for U+%04X",lookup,name,unicode)
+--~ end
+ end
+ end
+ end
+ elseif typ == "cexit" then -- or entry?
+ for name, anchor in next, anchors do
+ local lookups = anchor_to_lookup[name]
+ if lookups then
+ for lookup, _ in next, lookups do
+ local f = cursive[lookup]
+ if not f then f = { } cursive[lookup] = f end
+ f[unicode] = anchors -- ref to glyph, saves lookup
+--~ if trace_lookups then
+--~ logs.report("define otf","lookup %s: exit anchor %s for U+%04X",lookup,name,unicode)
+--~ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+-- local cache = { }
+luatex = luatex or {} -- this has to change ... we need a better one
+
+function prepare_contextchains(tfmdata)
+ local otfdata = tfmdata.shared.otfdata
+ local lookups = otfdata.lookups
+ if lookups then
+ local featuredata = otfdata.shared.featuredata
+ local contextchain = featuredata.gsub_contextchain -- shared with gpos
+ local reversecontextchain = featuredata.gsub_reversecontextchain -- shared with gpos
+ local characters = tfmdata.characters
+ local unicodes = tfmdata.unicodes
+ local indices = tfmdata.indices
+ local cache = luatex.covers
+ if not cache then
+ cache = { }
+ luatex.covers = cache
+ end
+ --
+ for lookupname, lookupdata in next, otfdata.lookups do
+ local lookuptype = lookupdata.type
+ if not lookuptype then
+ logs.report("otf process","missing lookuptype for %s",lookupname)
+ else
+ local rules = lookupdata.rules
+ if rules then
+ local fmt = lookupdata.format
+ -- contextchain[lookupname][unicode]
+ if fmt == "coverage" then
+ if lookuptype ~= "chainsub" and lookuptype ~= "chainpos" then
+ logs.report("otf process","unsupported coverage %s for %s",lookuptype,lookupname)
+ else
+ local contexts = contextchain[lookupname]
+ if not contexts then
+ contexts = { }
+ contextchain[lookupname] = contexts
+ end
+ local t = { }
+ for nofrules=1,#rules do -- does #rules>1 happen often?
+ local rule = rules[nofrules]
+ local coverage = rule.coverage
+ if coverage and coverage.current then
+ local current, before, after, sequence = coverage.current, coverage.before, coverage.after, { }
+ if before then
+ uncover(before,sequence,cache,unicodes)
+ end
+ local start = #sequence + 1
+ uncover(current,sequence,cache,unicodes)
+ local stop = #sequence
+ if after then
+ uncover(after,sequence,cache,unicodes)
+ end
+ if sequence[1] then
+ t[#t+1] = { nofrules, lookuptype, sequence, start, stop, rule.lookups }
+ for unic, _ in next, sequence[start] do
+ local cu = contexts[unic]
+ if not cu then
+ contexts[unic] = t
+ end
+ end
+ end
+ end
+ end
+ end
+ elseif fmt == "reversecoverage" then
+ if lookuptype ~= "reversesub" then
+ logs.report("otf process","unsupported reverse coverage %s for %s",lookuptype,lookupname)
+ else
+ local contexts = reversecontextchain[lookupname]
+ if not contexts then
+ contexts = { }
+ reversecontextchain[lookupname] = contexts
+ end
+ local t = { }
+ for nofrules=1,#rules do
+ local rule = rules[nofrules]
+ local reversecoverage = rule.reversecoverage
+ if reversecoverage and reversecoverage.current then
+ local current, before, after, replacements, sequence = reversecoverage.current, reversecoverage.before, reversecoverage.after, reversecoverage.replacements, { }
+ if before then
+ uncover(before,sequence,cache,unicodes)
+ end
+ local start = #sequence + 1
+ uncover(current,sequence,cache,unicodes)
+ local stop = #sequence
+ if after then
+ uncover(after,sequence,cache,unicodes)
+ end
+ if replacements then
+ replacements = split(replacements,current[1],cache,unicodes)
+ end
+ if sequence[1] then
+ -- this is different from normal coverage, we assume only replacements
+ t[#t+1] = { nofrules, lookuptype, sequence, start, stop, rule.lookups, replacements }
+ for unic, _ in next, sequence[start] do
+ local cu = contexts[unic]
+ if not cu then
+ contexts[unic] = t
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function fonts.initializers.node.otf.features(tfmdata,value)
+ if true then -- value then
+ if not tfmdata.shared.otfdata.shared.initialized then
+ local t = trace_preparing and os.clock()
+ local otfdata = tfmdata.shared.otfdata
+ local featuredata = otfdata.shared.featuredata
+ -- caches
+ featuredata.gsub_multiple = { }
+ featuredata.gsub_alternate = { }
+ featuredata.gsub_single = { }
+ featuredata.gsub_ligature = { }
+ featuredata.gsub_contextchain = { }
+ featuredata.gsub_reversecontextchain = { }
+ featuredata.gpos_pair = { }
+ featuredata.gpos_single = { }
+ featuredata.gpos_mark2base = { }
+ featuredata.gpos_mark2ligature = featuredata.gpos_mark2base
+ featuredata.gpos_mark2mark = featuredata.gpos_mark2base
+ featuredata.gpos_cursive = { }
+ featuredata.gpos_contextchain = featuredata.gsub_contextchain
+ featuredata.gpos_reversecontextchain = featuredata.gsub_reversecontextchain
+ --
+ prepare_contextchains(tfmdata)
+ prepare_lookups(tfmdata)
+ otfdata.shared.initialized = true
+ if trace_preparing then
+ logs.report("otf process","preparation time is %0.3f seconds for %s",os.clock()-t,tfmdata.fullname or "?")
+ end
+ end
+ end
+end
diff --git a/tex/context/base/font-otp.lua b/tex/context/base/font-otp.lua
new file mode 100644
index 000000000..3cdc80737
--- /dev/null
+++ b/tex/context/base/font-otp.lua
@@ -0,0 +1,420 @@
+if not modules then modules = { } end modules ['font-otp'] = {
+ version = 1.001,
+ comment = "companion to font-otf.lua (packing)",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- todo: pack math (but not that much to share)
+
+local next = next
+
+local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end)
+
+fonts = fonts or { }
+fonts.otf = fonts.otf or { }
+fonts.otf.enhancers = fonts.otf.enhancers or { }
+fonts.otf.glists = fonts.otf.glists or { "gsub", "gpos" }
+
+local criterium, threshold, tabstr = 1, 0, table.serialize
+
+function fonts.otf.enhancers.pack(data)
+ if data then
+ local h, t, c = { }, { }, { }
+ local hh, tt, cc = { }, { }, { }
+ local function pack_1(v)
+ -- v == table
+ local tag = tabstr(v)
+ local ht = h[tag]
+ if not ht then
+ ht = #t+1
+ t[ht] = v
+ h[tag] = ht
+ c[ht] = 1
+ else
+ c[ht] = c[ht] + 1
+ end
+ return ht
+ end
+ local function pack_2(v)
+ -- v == number
+ if c[v] <= criterium then
+ return t[v]
+ else
+ -- compact hash
+ local hv = hh[v]
+ if not hv then
+ hv = #tt+1
+ tt[hv] = t[v]
+ hh[v] = hv
+ cc[hv] = c[v]
+ end
+ return hv
+ end
+ end
+ local function success(stage,pass)
+ if #t == 0 then
+ if trace_loading then
+ logs.report("load otf","pack quality: nothing to pack")
+ end
+ return false
+ elseif #t >= threshold then
+ local one, two, rest = 0, 0, 0
+ if pass == 1 then
+ for k,v in next, c do
+ if v == 1 then
+ one = one + 1
+ elseif v == 2 then
+ two = two + 1
+ else
+ rest = rest + 1
+ end
+ end
+ else
+ for k,v in next, cc do
+ if v >20 then
+ rest = rest + 1
+ elseif v >10 then
+ two = two + 1
+ else
+ one = one + 1
+ end
+ end
+ data.tables = tt
+ end
+ if trace_loading then
+ logs.report("load otf","pack quality: stage %s, pass %s, %s packed, 1-10:%s, 11-20:%s, rest:%s (criterium: %s)", stage, pass, one+two+rest, one, two, rest, criterium)
+ end
+ return true
+ else
+ if trace_loading then
+ logs.report("load otf","pack quality: stage %s, pass %s, %s packed, aborting pack (threshold: %s)", stage, pass, #t, threshold)
+ end
+ return false
+ end
+ end
+ for pass=1,2 do
+ local pack = (pass == 1 and pack_1) or pack_2
+ for k, v in next, data.glyphs do
+ v.boundingbox = pack(v.boundingbox)
+ local l = v.lookups
+ if l then
+ for k,v in next, l do
+ for kk=1,#v do
+ local vkk = v[kk]
+ local what = vkk[1]
+ if what == "pair" then
+ local t = vkk[3] if t then vkk[3] = pack(t) end
+ local t = vkk[4] if t then vkk[4] = pack(t) end
+ elseif what == "position" then
+ local t = vkk[2] if t then vkk[2] = pack(t) end
+ end
+ -- v[kk] = pack(vkk)
+ end
+ end
+ end
+ local m = v.mykerns
+ if m then
+ for k,v in next, m do
+ m[k] = pack(v)
+ end
+ end
+ local m = v.math
+ if m then
+ local mk = m.kerns
+ if mk then
+ for k,v in next, mk do
+ mk[k] = pack(v)
+ end
+ end
+ end
+ local a = v.anchors
+ if a then
+ for k,v in next, a do
+ if k == "baselig" then
+ for kk, vv in next, v do
+ for kkk=1,#vv do
+ vv[kkk] = pack(vv[kkk])
+ end
+ end
+ else
+ for kk, vv in next, v do
+ v[kk] = pack(vv)
+ end
+ end
+ end
+ end
+ end
+ if data.lookups then
+ for k, v in next, data.lookups do
+ if v.rules then
+ for kk, vv in next, v.rules do
+ local l = vv.lookups
+ if l then
+ vv.lookups = pack(l)
+ end
+ local c = vv.coverage
+ if c then
+ c.before = c.before and pack(c.before )
+ c.after = c.after and pack(c.after )
+ c.current = c.current and pack(c.current)
+ end
+ local c = vv.reversecoverage
+ if c then
+ c.before = c.before and pack(c.before )
+ c.after = c.after and pack(c.after )
+ c.current = c.current and pack(c.current)
+ end
+ end
+ end
+ end
+ end
+ if data.luatex then
+ local la = data.luatex.anchor_to_lookup
+ if la then
+ for lookup, ldata in next, la do
+ la[lookup] = pack(ldata)
+ end
+ end
+ local la = data.luatex.lookup_to_anchor
+ if la then
+ for lookup, ldata in next, la do
+ la[lookup] = pack(ldata)
+ end
+ end
+ local ls = data.luatex.sequences
+ if ls then
+ for feature, fdata in next, ls do
+ local flags = fdata.flags
+ if flags then
+ fdata.flags = pack(flags)
+ end
+ local subtables = fdata.subtables
+ if subtables then
+ fdata.subtables = pack(subtables)
+ end
+ local features = fdata.features
+ if features then
+ for script, sdata in next, features do
+ features[script] = pack(sdata)
+ end
+ end
+ end
+ end
+ local ls = data.luatex.lookups
+ if ls then
+ for lookup, fdata in next, ls do
+ local flags = fdata.flags
+ if flags then
+ fdata.flags = pack(flags)
+ end
+ local subtables = fdata.subtables
+ if subtables then
+ fdata.subtables = pack(subtables)
+ end
+ end
+ end
+ local lf = data.luatex.features
+ if lf then
+ for _, g in next, fonts.otf.glists do
+ local gl = lf[g]
+ if gl then
+ for feature, spec in next, gl do
+ gl[feature] = pack(spec)
+ end
+ end
+ end
+ end
+ end
+ if not success(1,pass) then
+ return
+ end
+ end
+ if #t > 0 then
+ for pass=1,2 do
+ local pack = (pass == 1 and pack_1) or pack_2
+ for k, v in next, data.glyphs do
+ local m = v.mykerns
+ if m then
+ v.mykerns = pack(m)
+ end
+ local m = v.math
+ if m then
+ local mk = m.kerns
+ if mk then
+ m.kerns = pack(mk)
+ end
+ end
+ local a = v.anchors
+ if a then
+ v.anchors = pack(a)
+ end
+ local l = v.lookups
+ if l then
+ for k,v in next, l do
+ for kk=1,#v do
+ v[kk] = pack(v[kk])
+ end
+ end
+ end
+ end
+ local ls = data.luatex.sequences
+ if ls then
+ for feature, fdata in next, ls do
+ fdata.features = pack(fdata.features)
+ end
+ end
+ if not success(2,pass) then
+--~ return
+ end
+ end
+ end
+ end
+end
+
+function fonts.otf.enhancers.unpack(data)
+ if data then
+ local t = data.tables
+ if t then
+ for k, v in next, data.glyphs do
+ local tv = t[v.boundingbox] if tv then v.boundingbox = tv end
+ local l = v.lookups
+ if l then
+ for k,v in next, l do
+ for i=1,#v do
+ local tv = t[v[i]] if tv then v[i] = tv end
+ local vi = v[i]
+ local what = vi[1]
+ if what == "pair" then
+ local tv = t[vi[3]] if tv then vi[3] = tv end
+ local tv = t[vi[4]] if tv then vi[4] = tv end
+ elseif what == "position" then
+ local tv = t[vi[2]] if tv then vi[2] = tv end
+ end
+ end
+ end
+ end
+ local m = v.mykerns
+ if m then
+ local tv = t[m] if tv then m = tv v.mykerns = m end -- secondary optimization
+ for k,v in next, m do
+ local tv = t[v] if tv then m[k] = tv end
+ end
+ end
+ local m = v.math
+ if m then
+ local mk = m.kerns
+ if mk then
+ local tv = t[mk] if tv then mk = tv m.kerns = mk end -- secondary optimization
+ for k,v in next, mk do
+ local tv = t[v] if tv then mk[k] = tv end
+ end
+ end
+ end
+ local a = v.anchors
+ if a then
+ local tv = t[a] if tv then a = tv v.anchors = a end -- secondary optimization
+ for k,v in next, a do
+ if k == "baselig" then
+ for kk, vv in next, v do
+ for kkk=1,#vv do
+ local tv = t[vv[kkk]] if tv then vv[kkk] = tv end
+ end
+ end
+ else
+ for kk, vv in next, v do
+ local tv = t[vv] if tv then v[kk] = tv end
+ end
+ end
+ end
+ end
+ end
+ if data.lookups then
+ for k, v in next, data.lookups do
+ local r = v.rules
+ if r then
+ for kk, vv in next, r do
+ local l = vv.lookups
+ if l then
+ local tv = t[l] if tv then vv.lookups = tv end
+ end
+ local c = vv.coverage
+ if c then
+ local cc = c.before if cc then local tv = t[cc] if tv then c.before = tv end end
+ cc = c.after if cc then local tv = t[cc] if tv then c.after = tv end end
+ cc = c.current if cc then local tv = t[cc] if tv then c.current = tv end end
+ end
+ local c = vv.reversecoverage
+ if c then
+ local cc = c.before if cc then local tv = t[cc] if tv then c.before = tv end end
+ cc = c.after if cc then local tv = t[cc] if tv then c.after = tv end end
+ cc = c.current if cc then local tv = t[cc] if tv then c.current = tv end end
+ end
+ end
+ end
+ end
+ end
+ local luatex = data.luatex
+ if luatex then
+ local la = luatex.anchor_to_lookup
+ if la then
+ for lookup, ldata in next, la do
+ local tv = t[ldata] if tv then la[lookup] = tv end
+ end
+ end
+ local la = luatex.lookup_to_anchor
+ if la then
+ for lookup, ldata in next, la do
+ local tv = t[ldata] if tv then la[lookup] = tv end
+ end
+ end
+ local ls = luatex.sequences
+ if ls then
+ for feature, fdata in next, ls do
+ local flags = fdata.flags
+ if flags then
+ local tv = t[flags] if tv then fdata.flags = tv end
+ end
+ local subtables = fdata.subtables
+ if subtables then
+ local tv = t[subtables] if tv then fdata.subtables = tv end
+ end
+ local features = fdata.features
+ if features then
+ local tv = t[features] if tv then fdata.features = tv features = tv end -- secondary pack
+ for script, sdata in next, features do
+ local tv = t[sdata] if tv then features[script] = tv end
+ end
+ end
+ end
+ end
+ local ls = luatex.lookups
+ if ls then
+ for lookups, fdata in next, ls do
+ local flags = fdata.flags
+ if flags then
+ local tv = t[flags] if tv then fdata.flags = tv end
+ end
+ local subtables = fdata.subtables
+ if subtables then
+ local tv = t[subtables] if tv then fdata.subtables = tv end
+ end
+ end
+ end
+ local lf = luatex.features
+ if lf then
+ for _, g in next, fonts.otf.glists do
+ local gl = lf[g]
+ if gl then
+ for feature, spec in next, gl do
+ local tv = t[spec] if tv then gl[feature] = tv end
+ end
+ end
+ end
+ end
+ end
+ data.tables = nil
+ end
+ end
+end
diff --git a/tex/context/base/font-ott.lua b/tex/context/base/font-ott.lua
new file mode 100644
index 000000000..6676ff64b
--- /dev/null
+++ b/tex/context/base/font-ott.lua
@@ -0,0 +1,935 @@
+if not modules then modules = { } end modules ['font-otf'] = {
+ version = 1.001,
+ comment = "companion to font-otf.lua (tables)",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type, next, tonumber, tostring = type, next, tonumber, tostring
+local gsub, lower = string.gsub, string.lower
+
+fonts = fonts or { }
+fonts.otf = fonts.otf or { }
+
+local otf = fonts.otf
+
+otf.tables = otf.tables or { }
+otf.meanings = otf.meanings or { }
+
+otf.tables.scripts = {
+ ['dflt'] = 'Default',
+
+ ['arab'] = 'Arabic',
+ ['armn'] = 'Armenian',
+ ['bali'] = 'Balinese',
+ ['beng'] = 'Bengali',
+ ['bopo'] = 'Bopomofo',
+ ['brai'] = 'Braille',
+ ['bugi'] = 'Buginese',
+ ['buhd'] = 'Buhid',
+ ['byzm'] = 'Byzantine Music',
+ ['cans'] = 'Canadian Syllabics',
+ ['cher'] = 'Cherokee',
+ ['copt'] = 'Coptic',
+ ['cprt'] = 'Cypriot Syllabary',
+ ['cyrl'] = 'Cyrillic',
+ ['deva'] = 'Devanagari',
+ ['dsrt'] = 'Deseret',
+ ['ethi'] = 'Ethiopic',
+ ['geor'] = 'Georgian',
+ ['glag'] = 'Glagolitic',
+ ['goth'] = 'Gothic',
+ ['grek'] = 'Greek',
+ ['gujr'] = 'Gujarati',
+ ['guru'] = 'Gurmukhi',
+ ['hang'] = 'Hangul',
+ ['hani'] = 'CJK Ideographic',
+ ['hano'] = 'Hanunoo',
+ ['hebr'] = 'Hebrew',
+ ['ital'] = 'Old Italic',
+ ['jamo'] = 'Hangul Jamo',
+ ['java'] = 'Javanese',
+ ['kana'] = 'Hiragana and Katakana',
+ ['khar'] = 'Kharosthi',
+ ['khmr'] = 'Khmer',
+ ['knda'] = 'Kannada',
+ ['lao' ] = 'Lao',
+ ['latn'] = 'Latin',
+ ['limb'] = 'Limbu',
+ ['linb'] = 'Linear B',
+ ['math'] = 'Mathematical Alphanumeric Symbols',
+ ['mlym'] = 'Malayalam',
+ ['mong'] = 'Mongolian',
+ ['musc'] = 'Musical Symbols',
+ ['mymr'] = 'Myanmar',
+ ['nko' ] = "N'ko",
+ ['ogam'] = 'Ogham',
+ ['orya'] = 'Oriya',
+ ['osma'] = 'Osmanya',
+ ['phag'] = 'Phags-pa',
+ ['phnx'] = 'Phoenician',
+ ['runr'] = 'Runic',
+ ['shaw'] = 'Shavian',
+ ['sinh'] = 'Sinhala',
+ ['sylo'] = 'Syloti Nagri',
+ ['syrc'] = 'Syriac',
+ ['tagb'] = 'Tagbanwa',
+ ['tale'] = 'Tai Le',
+ ['talu'] = 'Tai Lu',
+ ['taml'] = 'Tamil',
+ ['telu'] = 'Telugu',
+ ['tfng'] = 'Tifinagh',
+ ['tglg'] = 'Tagalog',
+ ['thaa'] = 'Thaana',
+ ['thai'] = 'Thai',
+ ['tibt'] = 'Tibetan',
+ ['ugar'] = 'Ugaritic Cuneiform',
+ ['xpeo'] = 'Old Persian Cuneiform',
+ ['xsux'] = 'Sumero-Akkadian Cuneiform',
+ ['yi' ] = 'Yi'
+}
+
+otf.tables.languages = {
+ ['dflt'] = 'Default',
+
+ ['aba'] = 'Abaza',
+ ['abk'] = 'Abkhazian',
+ ['ady'] = 'Adyghe',
+ ['afk'] = 'Afrikaans',
+ ['afr'] = 'Afar',
+ ['agw'] = 'Agaw',
+ ['als'] = 'Alsatian',
+ ['alt'] = 'Altai',
+ ['amh'] = 'Amharic',
+ ['ara'] = 'Arabic',
+ ['ari'] = 'Aari',
+ ['ark'] = 'Arakanese',
+ ['asm'] = 'Assamese',
+ ['ath'] = 'Athapaskan',
+ ['avr'] = 'Avar',
+ ['awa'] = 'Awadhi',
+ ['aym'] = 'Aymara',
+ ['aze'] = 'Azeri',
+ ['bad'] = 'Badaga',
+ ['bag'] = 'Baghelkhandi',
+ ['bal'] = 'Balkar',
+ ['bau'] = 'Baule',
+ ['bbr'] = 'Berber',
+ ['bch'] = 'Bench',
+ ['bcr'] = 'Bible Cree',
+ ['bel'] = 'Belarussian',
+ ['bem'] = 'Bemba',
+ ['ben'] = 'Bengali',
+ ['bgr'] = 'Bulgarian',
+ ['bhi'] = 'Bhili',
+ ['bho'] = 'Bhojpuri',
+ ['bik'] = 'Bikol',
+ ['bil'] = 'Bilen',
+ ['bkf'] = 'Blackfoot',
+ ['bli'] = 'Balochi',
+ ['bln'] = 'Balante',
+ ['blt'] = 'Balti',
+ ['bmb'] = 'Bambara',
+ ['bml'] = 'Bamileke',
+ ['bos'] = 'Bosnian',
+ ['bre'] = 'Breton',
+ ['brh'] = 'Brahui',
+ ['bri'] = 'Braj Bhasha',
+ ['brm'] = 'Burmese',
+ ['bsh'] = 'Bashkir',
+ ['bti'] = 'Beti',
+ ['cat'] = 'Catalan',
+ ['ceb'] = 'Cebuano',
+ ['che'] = 'Chechen',
+ ['chg'] = 'Chaha Gurage',
+ ['chh'] = 'Chattisgarhi',
+ ['chi'] = 'Chichewa',
+ ['chk'] = 'Chukchi',
+ ['chp'] = 'Chipewyan',
+ ['chr'] = 'Cherokee',
+ ['chu'] = 'Chuvash',
+ ['cmr'] = 'Comorian',
+ ['cop'] = 'Coptic',
+ ['cos'] = 'Corsican',
+ ['cre'] = 'Cree',
+ ['crr'] = 'Carrier',
+ ['crt'] = 'Crimean Tatar',
+ ['csl'] = 'Church Slavonic',
+ ['csy'] = 'Czech',
+ ['dan'] = 'Danish',
+ ['dar'] = 'Dargwa',
+ ['dcr'] = 'Woods Cree',
+ ['deu'] = 'German',
+ ['dgr'] = 'Dogri',
+ ['div'] = 'Divehi',
+ ['djr'] = 'Djerma',
+ ['dng'] = 'Dangme',
+ ['dnk'] = 'Dinka',
+ ['dri'] = 'Dari',
+ ['dun'] = 'Dungan',
+ ['dzn'] = 'Dzongkha',
+ ['ebi'] = 'Ebira',
+ ['ecr'] = 'Eastern Cree',
+ ['edo'] = 'Edo',
+ ['efi'] = 'Efik',
+ ['ell'] = 'Greek',
+ ['eng'] = 'English',
+ ['erz'] = 'Erzya',
+ ['esp'] = 'Spanish',
+ ['eti'] = 'Estonian',
+ ['euq'] = 'Basque',
+ ['evk'] = 'Evenki',
+ ['evn'] = 'Even',
+ ['ewe'] = 'Ewe',
+ ['fan'] = 'French Antillean',
+ ['far'] = 'Farsi',
+ ['fin'] = 'Finnish',
+ ['fji'] = 'Fijian',
+ ['fle'] = 'Flemish',
+ ['fne'] = 'Forest Nenets',
+ ['fon'] = 'Fon',
+ ['fos'] = 'Faroese',
+ ['fra'] = 'French',
+ ['fri'] = 'Frisian',
+ ['frl'] = 'Friulian',
+ ['fta'] = 'Futa',
+ ['ful'] = 'Fulani',
+ ['gad'] = 'Ga',
+ ['gae'] = 'Gaelic',
+ ['gag'] = 'Gagauz',
+ ['gal'] = 'Galician',
+ ['gar'] = 'Garshuni',
+ ['gaw'] = 'Garhwali',
+ ['gez'] = "Ge'ez",
+ ['gil'] = 'Gilyak',
+ ['gmz'] = 'Gumuz',
+ ['gon'] = 'Gondi',
+ ['grn'] = 'Greenlandic',
+ ['gro'] = 'Garo',
+ ['gua'] = 'Guarani',
+ ['guj'] = 'Gujarati',
+ ['hai'] = 'Haitian',
+ ['hal'] = 'Halam',
+ ['har'] = 'Harauti',
+ ['hau'] = 'Hausa',
+ ['haw'] = 'Hawaiin',
+ ['hbn'] = 'Hammer-Banna',
+ ['hil'] = 'Hiligaynon',
+ ['hin'] = 'Hindi',
+ ['hma'] = 'High Mari',
+ ['hnd'] = 'Hindko',
+ ['ho'] = 'Ho',
+ ['hri'] = 'Harari',
+ ['hrv'] = 'Croatian',
+ ['hun'] = 'Hungarian',
+ ['hye'] = 'Armenian',
+ ['ibo'] = 'Igbo',
+ ['ijo'] = 'Ijo',
+ ['ilo'] = 'Ilokano',
+ ['ind'] = 'Indonesian',
+ ['ing'] = 'Ingush',
+ ['inu'] = 'Inuktitut',
+ ['iri'] = 'Irish',
+ ['irt'] = 'Irish Traditional',
+ ['isl'] = 'Icelandic',
+ ['ism'] = 'Inari Sami',
+ ['ita'] = 'Italian',
+ ['iwr'] = 'Hebrew',
+ ['jan'] = 'Japanese',
+ ['jav'] = 'Javanese',
+ ['jii'] = 'Yiddish',
+ ['jud'] = 'Judezmo',
+ ['jul'] = 'Jula',
+ ['kab'] = 'Kabardian',
+ ['kac'] = 'Kachchi',
+ ['kal'] = 'Kalenjin',
+ ['kan'] = 'Kannada',
+ ['kar'] = 'Karachay',
+ ['kat'] = 'Georgian',
+ ['kaz'] = 'Kazakh',
+ ['keb'] = 'Kebena',
+ ['kge'] = 'Khutsuri Georgian',
+ ['kha'] = 'Khakass',
+ ['khk'] = 'Khanty-Kazim',
+ ['khm'] = 'Khmer',
+ ['khs'] = 'Khanty-Shurishkar',
+ ['khv'] = 'Khanty-Vakhi',
+ ['khw'] = 'Khowar',
+ ['kik'] = 'Kikuyu',
+ ['kir'] = 'Kirghiz',
+ ['kis'] = 'Kisii',
+ ['kkn'] = 'Kokni',
+ ['klm'] = 'Kalmyk',
+ ['kmb'] = 'Kamba',
+ ['kmn'] = 'Kumaoni',
+ ['kmo'] = 'Komo',
+ ['kms'] = 'Komso',
+ ['knr'] = 'Kanuri',
+ ['kod'] = 'Kodagu',
+ ['koh'] = 'Korean Old Hangul',
+ ['kok'] = 'Konkani',
+ ['kon'] = 'Kikongo',
+ ['kop'] = 'Komi-Permyak',
+ ['kor'] = 'Korean',
+ ['koz'] = 'Komi-Zyrian',
+ ['kpl'] = 'Kpelle',
+ ['kri'] = 'Krio',
+ ['krk'] = 'Karakalpak',
+ ['krl'] = 'Karelian',
+ ['krm'] = 'Karaim',
+ ['krn'] = 'Karen',
+ ['krt'] = 'Koorete',
+ ['ksh'] = 'Kashmiri',
+ ['ksi'] = 'Khasi',
+ ['ksm'] = 'Kildin Sami',
+ ['kui'] = 'Kui',
+ ['kul'] = 'Kulvi',
+ ['kum'] = 'Kumyk',
+ ['kur'] = 'Kurdish',
+ ['kuu'] = 'Kurukh',
+ ['kuy'] = 'Kuy',
+ ['kyk'] = 'Koryak',
+ ['lad'] = 'Ladin',
+ ['lah'] = 'Lahuli',
+ ['lak'] = 'Lak',
+ ['lam'] = 'Lambani',
+ ['lao'] = 'Lao',
+ ['lat'] = 'Latin',
+ ['laz'] = 'Laz',
+ ['lcr'] = 'L-Cree',
+ ['ldk'] = 'Ladakhi',
+ ['lez'] = 'Lezgi',
+ ['lin'] = 'Lingala',
+ ['lma'] = 'Low Mari',
+ ['lmb'] = 'Limbu',
+ ['lmw'] = 'Lomwe',
+ ['lsb'] = 'Lower Sorbian',
+ ['lsm'] = 'Lule Sami',
+ ['lth'] = 'Lithuanian',
+ ['ltz'] = 'Luxembourgish',
+ ['lub'] = 'Luba',
+ ['lug'] = 'Luganda',
+ ['luh'] = 'Luhya',
+ ['luo'] = 'Luo',
+ ['lvi'] = 'Latvian',
+ ['maj'] = 'Majang',
+ ['mak'] = 'Makua',
+ ['mal'] = 'Malayalam Traditional',
+ ['man'] = 'Mansi',
+ ['map'] = 'Mapudungun',
+ ['mar'] = 'Marathi',
+ ['maw'] = 'Marwari',
+ ['mbn'] = 'Mbundu',
+ ['mch'] = 'Manchu',
+ ['mcr'] = 'Moose Cree',
+ ['mde'] = 'Mende',
+ ['men'] = "Me'en",
+ ['miz'] = 'Mizo',
+ ['mkd'] = 'Macedonian',
+ ['mle'] = 'Male',
+ ['mlg'] = 'Malagasy',
+ ['mln'] = 'Malinke',
+ ['mlr'] = 'Malayalam Reformed',
+ ['mly'] = 'Malay',
+ ['mnd'] = 'Mandinka',
+ ['mng'] = 'Mongolian',
+ ['mni'] = 'Manipuri',
+ ['mnk'] = 'Maninka',
+ ['mnx'] = 'Manx Gaelic',
+ ['moh'] = 'Mohawk',
+ ['mok'] = 'Moksha',
+ ['mol'] = 'Moldavian',
+ ['mon'] = 'Mon',
+ ['mor'] = 'Moroccan',
+ ['mri'] = 'Maori',
+ ['mth'] = 'Maithili',
+ ['mts'] = 'Maltese',
+ ['mun'] = 'Mundari',
+ ['nag'] = 'Naga-Assamese',
+ ['nan'] = 'Nanai',
+ ['nas'] = 'Naskapi',
+ ['ncr'] = 'N-Cree',
+ ['ndb'] = 'Ndebele',
+ ['ndg'] = 'Ndonga',
+ ['nep'] = 'Nepali',
+ ['new'] = 'Newari',
+ ['ngr'] = 'Nagari',
+ ['nhc'] = 'Norway House Cree',
+ ['nis'] = 'Nisi',
+ ['niu'] = 'Niuean',
+ ['nkl'] = 'Nkole',
+ ['nko'] = "N'ko",
+ ['nld'] = 'Dutch',
+ ['nog'] = 'Nogai',
+ ['nor'] = 'Norwegian',
+ ['nsm'] = 'Northern Sami',
+ ['nta'] = 'Northern Tai',
+ ['nto'] = 'Esperanto',
+ ['nyn'] = 'Nynorsk',
+ ['oci'] = 'Occitan',
+ ['ocr'] = 'Oji-Cree',
+ ['ojb'] = 'Ojibway',
+ ['ori'] = 'Oriya',
+ ['oro'] = 'Oromo',
+ ['oss'] = 'Ossetian',
+ ['paa'] = 'Palestinian Aramaic',
+ ['pal'] = 'Pali',
+ ['pan'] = 'Punjabi',
+ ['pap'] = 'Palpa',
+ ['pas'] = 'Pashto',
+ ['pgr'] = 'Polytonic Greek',
+ ['pil'] = 'Pilipino',
+ ['plg'] = 'Palaung',
+ ['plk'] = 'Polish',
+ ['pro'] = 'Provencal',
+ ['ptg'] = 'Portuguese',
+ ['qin'] = 'Chin',
+ ['raj'] = 'Rajasthani',
+ ['rbu'] = 'Russian Buriat',
+ ['rcr'] = 'R-Cree',
+ ['ria'] = 'Riang',
+ ['rms'] = 'Rhaeto-Romanic',
+ ['rom'] = 'Romanian',
+ ['roy'] = 'Romany',
+ ['rsy'] = 'Rusyn',
+ ['rua'] = 'Ruanda',
+ ['rus'] = 'Russian',
+ ['sad'] = 'Sadri',
+ ['san'] = 'Sanskrit',
+ ['sat'] = 'Santali',
+ ['say'] = 'Sayisi',
+ ['sek'] = 'Sekota',
+ ['sel'] = 'Selkup',
+ ['sgo'] = 'Sango',
+ ['shn'] = 'Shan',
+ ['sib'] = 'Sibe',
+ ['sid'] = 'Sidamo',
+ ['sig'] = 'Silte Gurage',
+ ['sks'] = 'Skolt Sami',
+ ['sky'] = 'Slovak',
+ ['sla'] = 'Slavey',
+ ['slv'] = 'Slovenian',
+ ['sml'] = 'Somali',
+ ['smo'] = 'Samoan',
+ ['sna'] = 'Sena',
+ ['snd'] = 'Sindhi',
+ ['snh'] = 'Sinhalese',
+ ['snk'] = 'Soninke',
+ ['sog'] = 'Sodo Gurage',
+ ['sot'] = 'Sotho',
+ ['sqi'] = 'Albanian',
+ ['srb'] = 'Serbian',
+ ['srk'] = 'Saraiki',
+ ['srr'] = 'Serer',
+ ['ssl'] = 'South Slavey',
+ ['ssm'] = 'Southern Sami',
+ ['sur'] = 'Suri',
+ ['sva'] = 'Svan',
+ ['sve'] = 'Swedish',
+ ['swa'] = 'Swadaya Aramaic',
+ ['swk'] = 'Swahili',
+ ['swz'] = 'Swazi',
+ ['sxt'] = 'Sutu',
+ ['syr'] = 'Syriac',
+ ['tab'] = 'Tabasaran',
+ ['taj'] = 'Tajiki',
+ ['tam'] = 'Tamil',
+ ['tat'] = 'Tatar',
+ ['tcr'] = 'TH-Cree',
+ ['tel'] = 'Telugu',
+ ['tgn'] = 'Tongan',
+ ['tgr'] = 'Tigre',
+ ['tgy'] = 'Tigrinya',
+ ['tha'] = 'Thai',
+ ['tht'] = 'Tahitian',
+ ['tib'] = 'Tibetan',
+ ['tkm'] = 'Turkmen',
+ ['tmn'] = 'Temne',
+ ['tna'] = 'Tswana',
+ ['tne'] = 'Tundra Nenets',
+ ['tng'] = 'Tonga',
+ ['tod'] = 'Todo',
+ ['trk'] = 'Turkish',
+ ['tsg'] = 'Tsonga',
+ ['tua'] = 'Turoyo Aramaic',
+ ['tul'] = 'Tulu',
+ ['tuv'] = 'Tuvin',
+ ['twi'] = 'Twi',
+ ['udm'] = 'Udmurt',
+ ['ukr'] = 'Ukrainian',
+ ['urd'] = 'Urdu',
+ ['usb'] = 'Upper Sorbian',
+ ['uyg'] = 'Uyghur',
+ ['uzb'] = 'Uzbek',
+ ['ven'] = 'Venda',
+ ['vit'] = 'Vietnamese',
+ ['wa' ] = 'Wa',
+ ['wag'] = 'Wagdi',
+ ['wcr'] = 'West-Cree',
+ ['wel'] = 'Welsh',
+ ['wlf'] = 'Wolof',
+ ['xbd'] = 'Tai Lue',
+ ['xhs'] = 'Xhosa',
+ ['yak'] = 'Yakut',
+ ['yba'] = 'Yoruba',
+ ['ycr'] = 'Y-Cree',
+ ['yic'] = 'Yi Classic',
+ ['yim'] = 'Yi Modern',
+ ['zhh'] = 'Chinese Hong Kong',
+ ['zhp'] = 'Chinese Phonetic',
+ ['zhs'] = 'Chinese Simplified',
+ ['zht'] = 'Chinese Traditional',
+ ['znd'] = 'Zande',
+ ['zul'] = 'Zulu'
+}
+
+otf.tables.features = {
+ ['aalt'] = 'Access All Alternates',
+ ['abvf'] = 'Above-Base Forms',
+ ['abvm'] = 'Above-Base Mark Positioning',
+ ['abvs'] = 'Above-Base Substitutions',
+ ['afrc'] = 'Alternative Fractions',
+ ['akhn'] = 'Akhands',
+ ['blwf'] = 'Below-Base Forms',
+ ['blwm'] = 'Below-Base Mark Positioning',
+ ['blws'] = 'Below-Base Substitutions',
+ ['c2pc'] = 'Petite Capitals From Capitals',
+ ['c2sc'] = 'Small Capitals From Capitals',
+ ['calt'] = 'Contextual Alternates',
+ ['case'] = 'Case-Sensitive Forms',
+ ['ccmp'] = 'Glyph Composition/Decomposition',
+ ['cjct'] = 'Conjunct Forms',
+ ['clig'] = 'Contextual Ligatures',
+ ['cpsp'] = 'Capital Spacing',
+ ['cswh'] = 'Contextual Swash',
+ ['curs'] = 'Cursive Positioning',
+ ['dflt'] = 'Default Processing',
+ ['dist'] = 'Distances',
+ ['dlig'] = 'Discretionary Ligatures',
+ ['dnom'] = 'Denominators',
+ ['dtls'] = 'Dotless Forms', -- math
+ ['expt'] = 'Expert Forms',
+ ['falt'] = 'Final glyph Alternates',
+ ['fin2'] = 'Terminal Forms #2',
+ ['fin3'] = 'Terminal Forms #3',
+ ['fina'] = 'Terminal Forms',
+ ['flac'] = 'Flattened Accents Over Capitals', -- math
+ ['frac'] = 'Fractions',
+ ['fwid'] = 'Full Width',
+ ['half'] = 'Half Forms',
+ ['haln'] = 'Halant Forms',
+ ['halt'] = 'Alternate Half Width',
+ ['hist'] = 'Historical Forms',
+ ['hkna'] = 'Horizontal Kana Alternates',
+ ['hlig'] = 'Historical Ligatures',
+ ['hngl'] = 'Hangul',
+ ['hojo'] = 'Hojo Kanji Forms',
+ ['hwid'] = 'Half Width',
+ ['init'] = 'Initial Forms',
+ ['isol'] = 'Isolated Forms',
+ ['ital'] = 'Italics',
+ ['jalt'] = 'Justification Alternatives',
+ ['jp04'] = 'JIS2004 Forms',
+ ['jp78'] = 'JIS78 Forms',
+ ['jp83'] = 'JIS83 Forms',
+ ['jp90'] = 'JIS90 Forms',
+ ['kern'] = 'Kerning',
+ ['lfbd'] = 'Left Bounds',
+ ['liga'] = 'Standard Ligatures',
+ ['ljmo'] = 'Leading Jamo Forms',
+ ['lnum'] = 'Lining Figures',
+ ['locl'] = 'Localized Forms',
+ ['mark'] = 'Mark Positioning',
+ ['med2'] = 'Medial Forms #2',
+ ['medi'] = 'Medial Forms',
+ ['mgrk'] = 'Mathematical Greek',
+ ['mkmk'] = 'Mark to Mark Positioning',
+ ['mset'] = 'Mark Positioning via Substitution',
+ ['nalt'] = 'Alternate Annotation Forms',
+ ['nlck'] = 'NLC Kanji Forms',
+ ['nukt'] = 'Nukta Forms',
+ ['numr'] = 'Numerators',
+ ['onum'] = 'Old Style Figures',
+ ['opbd'] = 'Optical Bounds',
+ ['ordn'] = 'Ordinals',
+ ['ornm'] = 'Ornaments',
+ ['palt'] = 'Proportional Alternate Width',
+ ['pcap'] = 'Petite Capitals',
+ ['pnum'] = 'Proportional Figures',
+ ['pref'] = 'Pre-base Forms',
+ ['pres'] = 'Pre-base Substitutions',
+ ['pstf'] = 'Post-base Forms',
+ ['psts'] = 'Post-base Substitutions',
+ ['pwid'] = 'Proportional Widths',
+ ['qwid'] = 'Quarter Widths',
+ ['rand'] = 'Randomize',
+ ['rkrf'] = 'Rakar Forms',
+ ['rlig'] = 'Required Ligatures',
+ ['rphf'] = 'Reph Form',
+ ['rtbd'] = 'Right Bounds',
+ ['rtla'] = 'Right-To-Left Alternates',
+ ['ruby'] = 'Ruby Notation Forms',
+ ['salt'] = 'Stylistic Alternates',
+ ['sinf'] = 'Scientific Inferiors',
+ ['size'] = 'Optical Size',
+ ['smcp'] = 'Small Capitals',
+ ['smpl'] = 'Simplified Forms',
+ ['ss01'] = 'Stylistic Set 1',
+ ['ss02'] = 'Stylistic Set 2',
+ ['ss03'] = 'Stylistic Set 3',
+ ['ss04'] = 'Stylistic Set 4',
+ ['ss05'] = 'Stylistic Set 5',
+ ['ss06'] = 'Stylistic Set 6',
+ ['ss07'] = 'Stylistic Set 7',
+ ['ss08'] = 'Stylistic Set 8',
+ ['ss09'] = 'Stylistic Set 9',
+ ['ss10'] = 'Stylistic Set 10',
+ ['ss11'] = 'Stylistic Set 11',
+ ['ss12'] = 'Stylistic Set 12',
+ ['ss13'] = 'Stylistic Set 13',
+ ['ss14'] = 'Stylistic Set 14',
+ ['ss15'] = 'Stylistic Set 15',
+ ['ss16'] = 'Stylistic Set 16',
+ ['ss17'] = 'Stylistic Set 17',
+ ['ss18'] = 'Stylistic Set 18',
+ ['ss19'] = 'Stylistic Set 19',
+ ['ss20'] = 'Stylistic Set 20',
+ ['ssty'] = 'Script Style', -- math
+ ['subs'] = 'Subscript',
+ ['sups'] = 'Superscript',
+ ['swsh'] = 'Swash',
+ ['titl'] = 'Titling',
+ ['tjmo'] = 'Trailing Jamo Forms',
+ ['tnam'] = 'Traditional Name Forms',
+ ['tnum'] = 'Tabular Figures',
+ ['trad'] = 'Traditional Forms',
+ ['twid'] = 'Third Widths',
+ ['unic'] = 'Unicase',
+ ['valt'] = 'Alternate Vertical Metrics',
+ ['vatu'] = 'Vattu Variants',
+ ['vert'] = 'Vertical Writing',
+ ['vhal'] = 'Alternate Vertical Half Metrics',
+ ['vjmo'] = 'Vowel Jamo Forms',
+ ['vkna'] = 'Vertical Kana Alternates',
+ ['vkrn'] = 'Vertical Kerning',
+ ['vpal'] = 'Proportional Alternate Vertical Metrics',
+ ['vrt2'] = 'Vertical Rotation',
+ ['zero'] = 'Slashed Zero',
+
+ ['trep'] = 'Traditional TeX Replacements',
+ ['tlig'] = 'Traditional TeX Ligatures',
+}
+
+otf.tables.baselines = {
+ ['hang'] = 'Hanging baseline',
+ ['icfb'] = 'Ideographic character face bottom edge baseline',
+ ['icft'] = 'Ideographic character face tope edige baseline',
+ ['ideo'] = 'Ideographic em-box bottom edge baseline',
+ ['idtp'] = 'Ideographic em-box top edge baseline',
+ ['math'] = 'Mathmatical centered baseline',
+ ['romn'] = 'Roman baseline'
+}
+
+-- can be sped up by local tables
+
+function otf.tables.to_tag(id)
+ return stringformat("%4s",lower(id))
+end
+
+local function resolve(tab,id)
+ if tab and id then
+ id = lower(id)
+ return tab[id] or tab[gsub(id," ","")] or tab['dflt'] or ''
+ else
+ return "unknown"
+ end
+end
+
+function otf.meanings.script(id)
+ return resolve(otf.tables.scripts,id)
+end
+function otf.meanings.language(id)
+ return resolve(otf.tables.languages,id)
+end
+function otf.meanings.feature(id)
+ return resolve(otf.tables.features,id)
+end
+function otf.meanings.baseline(id)
+ return resolve(otf.tables.baselines,id)
+end
+
+otf.tables.to_scripts = table.reverse_hash(otf.tables.scripts )
+otf.tables.to_languages = table.reverse_hash(otf.tables.languages)
+otf.tables.to_features = table.reverse_hash(otf.tables.features )
+
+local scripts = otf.tables.scripts
+local languages = otf.tables.languages
+local features = otf.tables.features
+
+local to_scripts = otf.tables.to_scripts
+local to_languages = otf.tables.to_languages
+local to_features = otf.tables.to_features
+
+function otf.meanings.normalize(features)
+ local h = { }
+ for k,v in next, features do
+ k = lower(k)
+ if k == "language" or k == "lang" then
+ v = gsub(lower(v),"[^a-z0-9%-]","")
+ k = language
+ if not languages[v] then
+ h.language = to_languages[v] or "dflt"
+ else
+ h.language = v
+ end
+ elseif k == "script" then
+ v = gsub(lower(v),"[^a-z0-9%-]","")
+ if not scripts[v] then
+ h.script = to_scripts[v] or "dflt"
+ else
+ h.script = v
+ end
+ else
+ if type(v) == "string" then
+ local b = v:is_boolean()
+ if type(b) == "nil" then
+ v = tonumber(v) or lower(v)
+ else
+ v = b
+ end
+ end
+ h[to_features[k] or k] = v
+ end
+ end
+ return h
+end
+
+-- When I feel the need ...
+
+--~ otf.tables.aat = {
+--~ [ 0] = {
+--~ name = "allTypographicFeaturesType",
+--~ [ 0] = "allTypeFeaturesOnSelector",
+--~ [ 1] = "allTypeFeaturesOffSelector",
+--~ },
+--~ [ 1] = {
+--~ name = "ligaturesType",
+--~ [0 ] = "requiredLigaturesOnSelector",
+--~ [1 ] = "requiredLigaturesOffSelector",
+--~ [2 ] = "commonLigaturesOnSelector",
+--~ [3 ] = "commonLigaturesOffSelector",
+--~ [4 ] = "rareLigaturesOnSelector",
+--~ [5 ] = "rareLigaturesOffSelector",
+--~ [6 ] = "logosOnSelector ",
+--~ [7 ] = "logosOffSelector ",
+--~ [8 ] = "rebusPicturesOnSelector",
+--~ [9 ] = "rebusPicturesOffSelector",
+--~ [10] = "diphthongLigaturesOnSelector",
+--~ [11] = "diphthongLigaturesOffSelector",
+--~ [12] = "squaredLigaturesOnSelector",
+--~ [13] = "squaredLigaturesOffSelector",
+--~ [14] = "abbrevSquaredLigaturesOnSelector",
+--~ [15] = "abbrevSquaredLigaturesOffSelector",
+--~ },
+--~ [ 2] = {
+--~ name = "cursiveConnectionType",
+--~ [ 0] = "unconnectedSelector",
+--~ [ 1] = "partiallyConnectedSelector",
+--~ [ 2] = "cursiveSelector ",
+--~ },
+--~ [ 3] = {
+--~ name = "letterCaseType",
+--~ [ 0] = "upperAndLowerCaseSelector",
+--~ [ 1] = "allCapsSelector ",
+--~ [ 2] = "allLowerCaseSelector",
+--~ [ 3] = "smallCapsSelector ",
+--~ [ 4] = "initialCapsSelector",
+--~ [ 5] = "initialCapsAndSmallCapsSelector",
+--~ },
+--~ [ 4] = {
+--~ name = "verticalSubstitutionType",
+--~ [ 0] = "substituteVerticalFormsOnSelector",
+--~ [ 1] = "substituteVerticalFormsOffSelector",
+--~ },
+--~ [ 5] = {
+--~ name = "linguisticRearrangementType",
+--~ [ 0] = "linguisticRearrangementOnSelector",
+--~ [ 1] = "linguisticRearrangementOffSelector",
+--~ },
+--~ [ 6] = {
+--~ name = "numberSpacingType",
+--~ [ 0] = "monospacedNumbersSelector",
+--~ [ 1] = "proportionalNumbersSelector",
+--~ },
+--~ [ 7] = {
+--~ name = "appleReserved1Type",
+--~ },
+--~ [ 8] = {
+--~ name = "smartSwashType",
+--~ [ 0] = "wordInitialSwashesOnSelector",
+--~ [ 1] = "wordInitialSwashesOffSelector",
+--~ [ 2] = "wordFinalSwashesOnSelector",
+--~ [ 3] = "wordFinalSwashesOffSelector",
+--~ [ 4] = "lineInitialSwashesOnSelector",
+--~ [ 5] = "lineInitialSwashesOffSelector",
+--~ [ 6] = "lineFinalSwashesOnSelector",
+--~ [ 7] = "lineFinalSwashesOffSelector",
+--~ [ 8] = "nonFinalSwashesOnSelector",
+--~ [ 9] = "nonFinalSwashesOffSelector",
+--~ },
+--~ [ 9] = {
+--~ name = "diacriticsType",
+--~ [ 0] = "showDiacriticsSelector",
+--~ [ 1] = "hideDiacriticsSelector",
+--~ [ 2] = "decomposeDiacriticsSelector",
+--~ },
+--~ [10] = {
+--~ name = "verticalPositionType",
+--~ [ 0] = "normalPositionSelector",
+--~ [ 1] = "superiorsSelector ",
+--~ [ 2] = "inferiorsSelector ",
+--~ [ 3] = "ordinalsSelector ",
+--~ },
+--~ [11] = {
+--~ name = "fractionsType",
+--~ [ 0] = "noFractionsSelector",
+--~ [ 1] = "verticalFractionsSelector",
+--~ [ 2] = "diagonalFractionsSelector",
+--~ },
+--~ [12] = {
+--~ name = "appleReserved2Type",
+--~ },
+--~ [13] = {
+--~ name = "overlappingCharactersType",
+--~ [ 0] = "preventOverlapOnSelector",
+--~ [ 1] = "preventOverlapOffSelector",
+--~ },
+--~ [14] = {
+--~ name = "typographicExtrasType",
+--~ [0 ] = "hyphensToEmDashOnSelector",
+--~ [1 ] = "hyphensToEmDashOffSelector",
+--~ [2 ] = "hyphenToEnDashOnSelector",
+--~ [3 ] = "hyphenToEnDashOffSelector",
+--~ [4 ] = "unslashedZeroOnSelector",
+--~ [5 ] = "unslashedZeroOffSelector",
+--~ [6 ] = "formInterrobangOnSelector",
+--~ [7 ] = "formInterrobangOffSelector",
+--~ [8 ] = "smartQuotesOnSelector",
+--~ [9 ] = "smartQuotesOffSelector",
+--~ [10] = "periodsToEllipsisOnSelector",
+--~ [11] = "periodsToEllipsisOffSelector",
+--~ },
+--~ [15] = {
+--~ name = "mathematicalExtrasType",
+--~ [ 0] = "hyphenToMinusOnSelector",
+--~ [ 1] = "hyphenToMinusOffSelector",
+--~ [ 2] = "asteriskToMultiplyOnSelector",
+--~ [ 3] = "asteriskToMultiplyOffSelector",
+--~ [ 4] = "slashToDivideOnSelector",
+--~ [ 5] = "slashToDivideOffSelector",
+--~ [ 6] = "inequalityLigaturesOnSelector",
+--~ [ 7] = "inequalityLigaturesOffSelector",
+--~ [ 8] = "exponentsOnSelector",
+--~ [ 9] = "exponentsOffSelector",
+--~ },
+--~ [16] = {
+--~ name = "ornamentSetsType",
+--~ [ 0] = "noOrnamentsSelector",
+--~ [ 1] = "dingbatsSelector ",
+--~ [ 2] = "piCharactersSelector",
+--~ [ 3] = "fleuronsSelector ",
+--~ [ 4] = "decorativeBordersSelector",
+--~ [ 5] = "internationalSymbolsSelector",
+--~ [ 6] = "mathSymbolsSelector",
+--~ },
+--~ [17] = {
+--~ name = "characterAlternativesType",
+--~ [ 0] = "noAlternatesSelector",
+--~ },
+--~ [18] = {
+--~ name = "designComplexityType",
+--~ [ 0] = "designLevel1Selector",
+--~ [ 1] = "designLevel2Selector",
+--~ [ 2] = "designLevel3Selector",
+--~ [ 3] = "designLevel4Selector",
+--~ [ 4] = "designLevel5Selector",
+--~ },
+--~ [19] = {
+--~ name = "styleOptionsType",
+--~ [ 0] = "noStyleOptionsSelector",
+--~ [ 1] = "displayTextSelector",
+--~ [ 2] = "engravedTextSelector",
+--~ [ 3] = "illuminatedCapsSelector",
+--~ [ 4] = "titlingCapsSelector",
+--~ [ 5] = "tallCapsSelector ",
+--~ },
+--~ [20] = {
+--~ name = "characterShapeType",
+--~ [0 ] = "traditionalCharactersSelector",
+--~ [1 ] = "simplifiedCharactersSelector",
+--~ [2 ] = "jis1978CharactersSelector",
+--~ [3 ] = "jis1983CharactersSelector",
+--~ [4 ] = "jis1990CharactersSelector",
+--~ [5 ] = "traditionalAltOneSelector",
+--~ [6 ] = "traditionalAltTwoSelector",
+--~ [7 ] = "traditionalAltThreeSelector",
+--~ [8 ] = "traditionalAltFourSelector",
+--~ [9 ] = "traditionalAltFiveSelector",
+--~ [10] = "expertCharactersSelector",
+--~ },
+--~ [21] = {
+--~ name = "numberCaseType",
+--~ [ 0] = "lowerCaseNumbersSelector",
+--~ [ 1] = "upperCaseNumbersSelector",
+--~ },
+--~ [22] = {
+--~ name = "textSpacingType",
+--~ [ 0] = "proportionalTextSelector",
+--~ [ 1] = "monospacedTextSelector",
+--~ [ 2] = "halfWidthTextSelector",
+--~ [ 3] = "normallySpacedTextSelector",
+--~ },
+--~ [23] = {
+--~ name = "transliterationType",
+--~ [ 0] = "noTransliterationSelector",
+--~ [ 1] = "hanjaToHangulSelector",
+--~ [ 2] = "hiraganaToKatakanaSelector",
+--~ [ 3] = "katakanaToHiraganaSelector",
+--~ [ 4] = "kanaToRomanizationSelector",
+--~ [ 5] = "romanizationToHiraganaSelector",
+--~ [ 6] = "romanizationToKatakanaSelector",
+--~ [ 7] = "hanjaToHangulAltOneSelector",
+--~ [ 8] = "hanjaToHangulAltTwoSelector",
+--~ [ 9] = "hanjaToHangulAltThreeSelector",
+--~ },
+--~ [24] = {
+--~ name = "annotationType",
+--~ [ 0] = "noAnnotationSelector",
+--~ [ 1] = "boxAnnotationSelector",
+--~ [ 2] = "roundedBoxAnnotationSelector",
+--~ [ 3] = "circleAnnotationSelector",
+--~ [ 4] = "invertedCircleAnnotationSelector",
+--~ [ 5] = "parenthesisAnnotationSelector",
+--~ [ 6] = "periodAnnotationSelector",
+--~ [ 7] = "romanNumeralAnnotationSelector",
+--~ [ 8] = "diamondAnnotationSelector",
+--~ },
+--~ [25] = {
+--~ name = "kanaSpacingType",
+--~ [ 0] = "fullWidthKanaSelector",
+--~ [ 1] = "proportionalKanaSelector",
+--~ },
+--~ [26] = {
+--~ name = "ideographicSpacingType",
+--~ [ 0] = "fullWidthIdeographsSelector",
+--~ [ 1] = "proportionalIdeographsSelector",
+--~ },
+--~ [103] = {
+--~ name = "cjkRomanSpacingType",
+--~ [ 0] = "halfWidthCJKRomanSelector",
+--~ [ 1] = "proportionalCJKRomanSelector",
+--~ [ 2] = "defaultCJKRomanSelector",
+--~ [ 3] = "fullWidthCJKRomanSelector",
+--~ },
+--~ }
diff --git a/tex/context/base/font-pat.lua b/tex/context/base/font-pat.lua
index 8f1817ec2..ae91700a9 100644
--- a/tex/context/base/font-pat.lua
+++ b/tex/context/base/font-pat.lua
@@ -6,19 +6,56 @@ if not modules then modules = { } end modules ['font-pat'] = {
license = "see context related readme files"
}
+local match, lower = string.match, string.lower
+
+local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end)
+
-- older versions of latin modern didn't have the designsize set
-- so for them we get it from the name
-local patches = fonts.otf.enhance.patches
+local patches = fonts.otf.enhancers.patches
local function patch(data,filename)
if data.design_size == 0 then
- local ds = (file.basename(filename:lower())):match("(%d+)")
+ local ds = match(file.basename(lower(filename)),"(%d+)")
if ds then
- logs.report("load otf","patching design size (%s)",ds)
+ if trace_loading then
+ logs.report("load otf","patching design size (%s)",ds)
+ end
data.design_size = tonumber(ds) * 10
end
end
+ local uni_to_ind = data.map.map
+ if not uni_to_ind[0x391] then
+ -- beware, this is a hack, features for latin often don't apply to greek
+ -- but lm has not much features anyway (and only greek for math)
+ if trace_loading then
+ logs.report("load otf","adding 13 greek capitals")
+ end
+ uni_to_ind[0x391] = uni_to_ind[0x41]
+ uni_to_ind[0x392] = uni_to_ind[0x42]
+ uni_to_ind[0x395] = uni_to_ind[0x45]
+ uni_to_ind[0x397] = uni_to_ind[0x48]
+ uni_to_ind[0x399] = uni_to_ind[0x49]
+ uni_to_ind[0x39A] = uni_to_ind[0x4B]
+ uni_to_ind[0x39C] = uni_to_ind[0x4D]
+ uni_to_ind[0x39D] = uni_to_ind[0x4E]
+ uni_to_ind[0x39F] = uni_to_ind[0x4F]
+ uni_to_ind[0x3A1] = uni_to_ind[0x52]
+ uni_to_ind[0x3A4] = uni_to_ind[0x54]
+ uni_to_ind[0x3A7] = uni_to_ind[0x58]
+ uni_to_ind[0x396] = uni_to_ind[0x5A]
+ end
+ -- better make this into a feature
+ --
+ -- local glyphs = data.glyphs
+ -- for i=0x300,0x36F do
+ -- local c = glyphs[uni_to_ind[i]]
+ -- if c and c.width == 0 then
+ -- local boundingbox = c.boundingbox
+ -- c.width = boundingbox[3] - boundingbox[1]
+ -- end
+ -- end
end
patches["^lmroman"] = patch
@@ -30,10 +67,14 @@ patches["^lmtypewriter"] = patch
-- have the mkmk features properly set up
local function patch(data,filename)
- if data.gpos then
- for _, v in ipairs(data.gpos) do
+ local gpos = data.gpos
+ if gpos then
+ for k=1,#gpos do
+ local v = gpos[k]
if not v.features and v.type == "gpos_mark2mark" then
- logs.report("load otf","patching mkmk feature (name: %s)", v.name or "?")
+ if trace_loading then
+ logs.report("load otf","patching mkmk feature (name: %s)", v.name or "?")
+ end
v.features = {
{
scripts = {
diff --git a/tex/context/base/font-run.tex b/tex/context/base/font-run.tex
index 83da04b62..0a0ddd057 100644
--- a/tex/context/base/font-run.tex
+++ b/tex/context/base/font-run.tex
@@ -213,8 +213,7 @@
\processcommalist[#2]\docommand
\egroup
\else\ifsecondargument
- \showfontstyle[#1][#2][\alternativetextlist]%
- \doif{#2}{\c!mm}{\showfontstyle[#1][#2][\alternativemathlist]}%
+ \showfontstyle[#1][#2][\fontalternativelist]% math is gone
\else
\showfontstyle[#1][\c!rm]\showfontstyle[#1][\c!ss]
\showfontstyle[#1][\c!tt]\showfontstyle[#1][\c!mm]
diff --git a/tex/context/base/font-syn.lua b/tex/context/base/font-syn.lua
index 70f859cde..2f4bebbaf 100644
--- a/tex/context/base/font-syn.lua
+++ b/tex/context/base/font-syn.lua
@@ -6,53 +6,62 @@ if not modules then modules = { } end modules ['font-syn'] = {
license = "see context related readme files"
}
+local next = next
+local gsub, lower, match, find, lower, upper = string.gsub, string.lower, string.match, string.find, string.lower, string.upper
+
+local trace_names = false trackers.register("fonts.names", function(v) trace_names = v end)
+
--[[ldx--
This module implements a name to filename resolver. Names are resolved
using a table that has keys filtered from the font related files.
--ldx]]--
-local texsprint = tex.sprint
+local texsprint = (tex and tex.sprint) or print
fonts = fonts or { }
input = input or { }
texmf = texmf or { }
-fonts.names = { }
-fonts.names.filters = { }
-fonts.names.data = { }
-fonts.names.version = 1.07
-fonts.names.saved = false
-fonts.names.loaded = false
-fonts.names.be_clever = true
-fonts.names.enabled = true
-fonts.names.autoreload = toboolean(os.env['MTX.FONTS.AUTOLOAD'] or os.env['MTX_FONTS_AUTOLOAD'] or "no")
-fonts.names.cache = containers.define("fonts","data",fonts.names.version,true)
-fonts.names.trace = false
+fonts.names = fonts.names or { }
+fonts.names.filters = fonts.names.filters or { }
+fonts.names.data = fonts.names.data or { }
+
+local names = fonts.names
+local filters = fonts.names.filters
+
+names.version = 1.08 -- when adapting this, also changed font-dum.lua
+names.basename = "names"
+names.saved = false
+names.loaded = false
+names.be_clever = true
+names.enabled = true
+names.autoreload = toboolean(os.env['MTX.FONTS.AUTOLOAD'] or os.env['MTX_FONTS_AUTOLOAD'] or "no")
+names.cache = containers.define("fonts","data",names.version,true)
--[[ldx--
It would make sense to implement the filters in the related modules,
but to keep the overview, we define them here.
--ldx]]--
-fonts.names.filters.otf = fontforge.info
-fonts.names.filters.ttf = fontforge.info
-fonts.names.filters.ttc = fontforge.info
+filters.otf = fontloader.info
+filters.ttf = fontloader.info
+filters.ttc = fontloader.info
-function fonts.names.filters.afm(name)
- local pfbname = input.find_file(file.removesuffix(name)..".pfb","pfb") or ""
+function filters.afm(name)
+ local pfbname = resolvers.find_file(file.removesuffix(name)..".pfb","pfb") or ""
if pfbname == "" then
- pfbname = input.find_file(file.removesuffix(file.basename(name))..".pfb","pfb") or ""
+ pfbname = resolvers.find_file(file.removesuffix(file.basename(name))..".pfb","pfb") or ""
end
if pfbname ~= "" then
local f = io.open(name)
if f then
local hash = { }
for line in f:lines() do
- local key, value = line:match("^(.+)%s+(.+)%s*$")
+ local key, value = match(line,"^(.+)%s+(.+)%s*$")
if key and #key > 0 then
- hash[key:lower()] = value
+ hash[lower(key)] = value
end
- if line:find("StartCharMetrics") then
+ if find(line,"StartCharMetrics") then
break
end
end
@@ -63,8 +72,8 @@ function fonts.names.filters.afm(name)
return nil
end
-function fonts.names.filters.pfb(name)
- return fontforge.info(name)
+function filters.pfb(name)
+ return fontloader.info(name)
end
--[[ldx--
@@ -73,101 +82,103 @@ the file databases. Watch how we check not only for the names, but also
for combination with the weight of a font.
--ldx]]--
-fonts.names.filters.list = {
+filters.list = {
"otf", "ttf", "ttc", "afm",
}
-fonts.names.filters.fixes = {
+filters.fixes = {
{ "reg$", "regular", },
{ "ita$", "italic", },
{ "ital$", "italic", },
{ "cond$", "condensed", },
+ { "book$", "", },
}
-fonts.names.xml_configuration_file = "fonts.conf" -- a bit weird format, bonus feature
-fonts.names.environment_path_variable = "OSFONTDIR" -- the official way, in minimals etc
+names.xml_configuration_file = "fonts.conf" -- a bit weird format, bonus feature
+names.environment_path_variable = "OSFONTDIR" -- the official way, in minimals etc
-fonts.names.filters.paths = { }
-fonts.names.filters.names = { }
+filters.paths = { }
+filters.names = { }
-function fonts.names.getpaths()
+function names.getpaths()
local hash, result = { }, { }
local function collect(t)
for i=1, #t do
- local v = input.clean_path(t[i])
- v = v:gsub("/+$","")
- local key = v:lower()
+ local v = resolvers.clean_path(t[i])
+ v = gsub(v,"/+$","")
+ local key = lower(v)
if not hash[key] then
hash[key], result[#result+1] = true, v
end
end
end
- local path = fonts.names.environment_path_variable or ""
+ local path = names.environment_path_variable or ""
if path ~= "" then
- collect(input.expanded_path_list(path))
+ collect(resolvers.expanded_path_list(path))
end
- local name = fonts.names.xml_configuration_file or ""
- if name ~= "" then
- local name = input.find_file(name,"other")
+ if xml then
+ local name = names.xml_configuration_file or ""
if name ~= "" then
- collect(xml.collect_texts(xml.load(name),"dir",true))
+ local name = resolvers.find_file(name,"other")
+ if name ~= "" then
+ collect(xml.collect_texts(xml.load(name),"dir",true))
+ end
end
end
- function fonts.names.getpaths()
+ function names.getpaths()
return result
end
return result
end
-function fonts.names.cleanname(name)
- return ((name:lower()):gsub("[^%a%d]",""))
+function names.cleanname(name)
+ return (gsub(lower(name),"[^%a%d]",""))
end
-function fonts.names.identify(verbose)
- fonts.names.data = {
- version = fonts.names.version,
+function names.identify(verbose) -- lsr is for kpse
+ names.data = {
+ version = names.version,
mapping = { },
-- sorted = { },
fallback_mapping = { },
-- fallback_sorted = { },
}
- local done, mapping, fallback_mapping, nofread, nofok = { }, fonts.names.data.mapping, fonts.names.data.fallback_mapping, 0, 0
- local cleanname = fonts.names.cleanname
+ local done, mapping, fallback_mapping, nofread, nofok = { }, names.data.mapping, names.data.fallback_mapping, 0, 0
+ local cleanname = names.cleanname
local function check(result, filename, suffix, is_sub)
local fontname = result.fullname
if fontname then
local n = cleanname(result.fullname)
if not mapping[n] then
- mapping[n], nofok = { suffix, fontname, filename, is_sub }, nofok + 1
+ mapping[n], nofok = { lower(suffix), fontname, filename, is_sub }, nofok + 1
end
end
if result.fontname then
fontname = fontname or result.fontname
local n = cleanname(result.fontname)
if not mapping[n] then
- mapping[n], nofok = { suffix, fontname, filename, is_sub }, nofok + 1
+ mapping[n], nofok = { lower(suffix), fontname, filename, is_sub }, nofok + 1
end
end
if result.familyname and result.weight and result.italicangle == 0 then
local madename = result.familyname .. " " .. result.weight
fontname = fontname or madename
- local n = cleanname(madename)
+ local n = cleanname(fontname)
if not mapping[n] and not fallback_mapping[n] then
- fallback_mapping[n], nofok = { suffix, fontname, filename, is_sub }, nofok + 1
+ fallback_mapping[n], nofok = { lower(suffix), fontname, filename, is_sub }, nofok + 1
end
end
end
- local trace = verbose or fonts.names.trace
- local filters = fonts.names.filters
- local skip_paths = fonts.names.filters.paths
- local skip_names = fonts.names.filters.names
+ local trace = verbose or trace_names
+ local skip_paths = filters.paths
+ local skip_names = filters.names
local function identify(completename,name,suffix,storedname)
if not done[name] and io.exists(completename) then
nofread = nofread + 1
if #skip_paths > 0 then
local path = file.dirname(completename)
for i=1,#skip_paths do
- if path:find(skip_paths[i]) then
+ if find(path,skip_paths[i]) then
if trace then
logs.report("fontnames","rejecting path of %s font %s",suffix,completename)
logs.push()
@@ -179,7 +190,7 @@ function fonts.names.identify(verbose)
if #skip_names > 0 then
local base = file.basename(completename)
for i=1,#skip_paths do
- if base:find(skip_names[i]) then
+ if find(base,skip_names[i]) then
done[name] = true
if trace then
logs.report("fontnames","rejecting name of %s font %s",suffix,completename)
@@ -189,51 +200,46 @@ function fonts.names.identify(verbose)
end
end
end
- if trace then
+ if trace_names then
logs.report("fontnames","identifying %s font %s",suffix,completename)
logs.push()
end
- local result = filters[suffix:lower()](completename)
+ local result = filters[lower(suffix)](completename)
if trace then
logs.pop()
end
if result then
if not result[1] then
check(result,storedname,suffix,false) -- was name
- else for _, r in ipairs(result) do
- check(r,storedname,suffix,true) -- was name
- end end
+ else
+ for r=1,#result do
+ check(result[r],storedname,suffix,true) -- was name
+ end
+ end
end
done[name] = true
end
end
+ local totalread, totalok = 0, 0
local function traverse(what, method)
- for n, suffix in ipairs(fonts.names.filters.list) do
+ for n, suffix in ipairs(filters.list) do
nofread, nofok = 0, 0
local t = os.gettimeofday() -- use elapser
- suffix = suffix:lower()
+ suffix = lower(suffix)
logs.report("fontnames", "identifying %s font files with suffix %s",what,suffix)
method(suffix)
- suffix = suffix:upper()
+ suffix = upper(suffix)
logs.report("fontnames", "identifying %s font files with suffix %s",what,suffix)
method(suffix)
logs.report("fontnames", "%s %s files identified, %s hash entries added, runtime %0.3f seconds",nofread,what,nofok,os.gettimeofday()-t)
+ totalread, totalok = totalread + nofread, totalok + nofok
end
end
- traverse("tree", function(suffix) -- TEXTREE only
- input.with_files(".*%." .. suffix .. "$", function(method,root,path,name)
- if method == "file" then
- local completename = root .."/" .. path .. "/" .. name
- identify(completename,name,suffix,name,name)
- end
- end)
- end)
- traverse("system", function(suffix) -- OSFONTDIR cum suis
- local pathlist = fonts.names.getpaths()
+ local function walk_tree(pathlist,suffix)
if pathlist then
for _, path in ipairs(pathlist) do
- path = input.clean_path(path .. "/")
- path = path:gsub("/+","/")
+ path = resolvers.clean_path(path .. "/")
+ path = gsub(path,"/+","/")
local pattern = path .. "**." .. suffix -- ** forces recurse
logs.report("fontnames", "globbing path %s",pattern)
local t = dir.glob(pattern)
@@ -242,67 +248,115 @@ function fonts.names.identify(verbose)
end
end
end
+ end
+ traverse("tree", function(suffix) -- TEXTREE only
+ resolvers.with_files(".*%." .. suffix .. "$", function(method,root,path,name)
+ if method == "file" then
+ local completename = root .."/" .. path .. "/" .. name
+ identify(completename,name,suffix,name,name)
+ end
+ end)
end)
+ if texconfig.kpse_init then
+ -- we do this only for a stupid names run, not used for context itself,
+ -- using the vars is to clumsy so we just stick to a full scan instead
+ traverse("lsr", function(suffix) -- all trees
+ local pathlist = resolvers.split_path(resolvers.show_path("ls-R") or "")
+ walk_tree(pathlist,suffix)
+ end)
+ else
+ traverse("system", function(suffix) -- OSFONTDIR cum suis
+ walk_tree(names.getpaths(),suffix)
+ end)
+ end
local t = { }
- for _, f in ipairs(fonts.names.filters.fixes) do
+ for _, f in ipairs(filters.fixes) do
local expression, replacement = f[1], f[2]
- for k,v in pairs(mapping) do
- local fix, pos = k:gsub(expression,replacement)
+ for k,v in next, mapping do
+ local fix, pos = gsub(k,expression,replacement)
if pos > 0 and not mapping[fix] then
t[fix] = v
end
end
end
- for k,v in pairs(t) do
+ local n = 0
+ for k,v in next, t do
mapping[k] = v
+ n = n + 1
end
+ local rejected = 0
+ for k, v in next, mapping do
+ local kind, filename = v[1], v[3]
+ if not file.is_qualified_path(filename) and resolvers.find_file(filename,kind) == "" then
+ mapping[k] = nil
+ rejected = rejected + 1
+ end
+ end
+ if n > 0 then
+ logs.report("fontnames", "%s files read, %s normal and %s extra entries added, %s rejected, %s valid",totalread,totalok,n,rejected,totalok+n-rejected)
+ end
+end
+
+function names.is_permitted(name)
+ return containers.is_usable(names.cache(), name)
+end
+function names.write_data(name,data)
+ containers.write(names.cache(),name,data)
+end
+function names.read_data(name)
+ return containers.read(names.cache(),name)
end
-function fonts.names.load(reload,verbose)
- if not fonts.names.loaded then
+function names.load(reload,verbose)
+ if not names.loaded then
if reload then
- if containers.is_usable(fonts.names.cache(), "names") then
- fonts.names.identify(verbose)
- containers.write(fonts.names.cache(), "names", fonts.names.data)
+ if names.is_permitted(names.basename) then
+ names.identify(verbose)
+ names.write_data(names.basename,names.data)
+ else
+ logs.report("font table", "unable to access database cache")
end
- fonts.names.saved = true
+ names.saved = true
else
- fonts.names.data = containers.read(fonts.names.cache(), "names")
- if not fonts.names.saved then
- if table.is_empty(fonts.names.data) or table.is_empty(fonts.names.data.mapping) then
- fonts.names.load(true)
+ names.data = names.read_data(names.basename)
+ if not names.saved then
+ if table.is_empty(names.data) or table.is_empty(names.data.mapping) then
+ names.load(true)
end
- fonts.names.saved = true
+ names.saved = true
end
end
- local data = fonts.names.data
+ local data = names.data
if data then
data.sorted = table.sortedkeys(data.mapping or { }) or { }
data.fallback_sorted = table.sortedkeys(data.fallback_mapping or { }) or { }
else
logs.report("font table", "accessing the data table failed")
end
- fonts.names.loaded = true
+ names.loaded = true
end
end
-function fonts.names.list(pattern,reload)
- fonts.names.load(reload)
- if fonts.names.loaded then
+function names.list(pattern,reload)
+ names.load(reload)
+ if names.loaded then
local t = { }
local function list_them(mapping,sorted)
if mapping[pattern] then
t[pattern] = mapping[pattern]
else
for k,v in ipairs(sorted) do
- if v:find(pattern) then
+ if find(v,pattern) then
t[v] = mapping[v]
end
end
end
end
- list_them(fonts.names.data.mapping,fonts.names.data.sorted)
- list_them(fonts.names.data.fallback_mapping,fonts.names.data.fallback_sorted)
+ local data = names.data
+ if data then
+ list_them(data.mapping,data.sorted)
+ list_them(data.fallback_mapping,data.fallback_sorted)
+ end
return t
else
return nil
@@ -315,110 +369,81 @@ here is for testing purposes only (it deals with names prefixed by an
encoding name).
--ldx]]--
-do
-
- local function found(name)
- if fonts.names.data then
- name = fonts.names.cleanname(name)
- local function found_indeed(mapping,sorted)
- local mn = mapping[name]
- if mn then
- return mn[2], mn[3], mn[4]
- end
- if fonts.names.be_clever then -- this will become obsolete
- local encoding, tag = name:match("^(.-)[%-%:](.+)$")
- local mt = mapping[tag]
- if tag and fonts.enc.is_known(encoding) and mt then
- return mt[1], encoding .. "-" .. mt[3], mt[4]
- end
- end
- -- name, type, file
- for k,v in pairs(mapping) do
- if k:find(name) then
- return v[2], v[3], v[4]
- end
- end
- local condensed = name:gsub("[^%a%d]","")
- local mc = mapping[condensed]
- if mc then
- return mc[2], mc[3], mc[4]
- end
- for k,v in ipairs(sorted) do
- if v:find(condensed) then
- v = mapping[v]
- return v[2], v[3], v[4]
- end
- end
- return nil, nil, nil
- end
- local data = fonts.names.data
- local fontname, filename, is_sub = found_indeed(data.mapping, data.sorted)
- if not fontname or not filename then
- fontname, filename, is_sub = found_indeed(data.fallback_mapping, data.fallback_sorted)
- end
- return fontname, filename, is_sub
- else
- return nil, nil, nil
+local function found_indeed(mapping,sorted,name)
+ local mn = mapping[name]
+ if mn then
+ return mn[2], mn[3], mn[4]
+ end
+ if names.be_clever then -- this will become obsolete
+ local encoding, tag = match(name,"^(.-)[%-%:](.+)$")
+ local mt = mapping[tag]
+ if tag and fonts.enc.is_known(encoding) and mt then
+ return mt[1], encoding .. "-" .. mt[3], mt[4]
end
end
-
- local reloaded = false
-
- function fonts.names.resolve(askedname, sub)
- if not askedname then
- return nil, nil
- elseif fonts.names.enabled then
- askedname = askedname:lower()
- fonts.names.load()
- local name, filename, is_sub = found(askedname)
- if not filename and not reloaded and fonts.names.autoreload then
- fonts.names.loaded = false
- reloaded = true
- io.flush()
- fonts.names.load(true)
- name, filename, is_sub = found(askedname)
- end
- if is_sub then
- return filename, name
- else
- return filename, sub
- end
- else
- return filename, sub
+ -- name, type, file
+ for k,v in next, mapping do
+ if find(k,name) then
+ return v[2], v[3], v[4]
end
end
+ local condensed = gsub(name,"[^%a%d]","")
+ local mc = mapping[condensed]
+ if mc then
+ return mc[2], mc[3], mc[4]
+ end
+ for k=1,#sorted do
+ local v = sorted[k]
+ if find(v,condensed) then
+ v = mapping[v]
+ return v[2], v[3], v[4]
+ end
+ end
+ return nil, nil, nil
+end
+local function found(name)
+ if name and name ~= "" and names.data then
+ name = names.cleanname(name)
+ local data = names.data
+ local fontname, filename, is_sub = found_indeed(data.mapping, data.sorted, name)
+ if not fontname or not filename then
+ fontname, filename, is_sub = found_indeed(data.fallback_mapping, data.fallback_sorted, name)
+ end
+ return fontname, filename, is_sub
+ else
+ return nil, nil, nil
+ end
end
---[[ldx--
-
A handy helper.
---ldx]]--
+local reloaded = false
-function fonts.names.table(pattern,reload,all)
- local t = fonts.names.list(pattern,reload)
- if t then
- texsprint(tex.ctxcatcodes,"\\start\\nonknuthmode\\starttabulate[|T|T|T|T|T|]")
- texsprint(tex.ctxcatcodes,"\\NC hashname\\NC type\\NC fontname\\NC filename\\NC\\NR\\HL")
- for k,v in pairs(table.sortedkeys(t)) do
- if all or v == t[v][2]:lower() then
- local type, name, file = unpack(t[v])
- if type and name and file then
- texsprint(tex.ctxcatcodes,string.format("\\NC %s\\NC %s\\NC %s\\NC %s\\NC\\NR",v,type, name, file))
- else
- logs.report("font table", "skipping %s", v)
- end
- end
+function names.specification(askedname, sub)
+ if askedname and askedname ~= "" and names.enabled then
+ askedname = lower(askedname)
+ names.load()
+ local name, filename, is_sub = found(askedname)
+ if not filename and not reloaded and names.autoreload then
+ names.loaded = false
+ reloaded = true
+ io.flush()
+ names.load(true)
+ name, filename, is_sub = found(askedname)
end
- texsprint(tex.ctxcatcodes,"\\stoptabulate\\stop")
+ return name, filename, is_sub
end
end
+function names.resolve(askedname, sub)
+ local name, filename, is_sub = names.specification(askedname, sub)
+ return filename, (is_sub and name) or sub
+end
--[[ldx--
Fallbacks, not permanent but a transition thing.
--ldx]]--
-fonts.names.new_to_old = {
+names.new_to_old = {
["lmroman10-capsregular"] = "lmromancaps10-oblique",
["lmroman10-capsoblique"] = "lmromancaps10-regular",
["lmroman10-demi"] = "lmromandemi10-oblique",
@@ -460,19 +485,19 @@ fonts.names.new_to_old = {
["lmtypewritervarwd10-darkoblique"] = "lmmonoproplt10-boldoblique",
}
-fonts.names.old_to_new = table.swapped(fonts.names.new_to_old)
+names.old_to_new = table.swapped(names.new_to_old)
-function fonts.names.exists(name)
- local fna, found = fonts.names.autoreload, false
- fonts.names.autoreload = false
- for k,v in ipairs(fonts.names.filters.list) do
- found = (input.find_file(name,v) or "") ~= ""
+function names.exists(name)
+ local fna, found = names.autoreload, false
+ names.autoreload = false
+ for k,v in ipairs(filters.list) do
+ found = (resolvers.find_file(name,v) or "") ~= ""
if found then
break
end
end
- found = found or (input.find_file(name,"tfm") or "") ~= ""
- found = found or (fonts.names.resolve(name) or "") ~= ""
- fonts.names.autoreload = fna
+ found = found or (resolvers.find_file(name,"tfm") or "") ~= ""
+ found = found or (names.resolve(name) or "") ~= ""
+ names.autoreload = fna
return found
end
diff --git a/tex/context/base/font-tfm.lua b/tex/context/base/font-tfm.lua
index 1955b58bc..2ee633b77 100644
--- a/tex/context/base/font-tfm.lua
+++ b/tex/context/base/font-tfm.lua
@@ -6,31 +6,51 @@ if not modules then modules = { } end modules ['font-tfm'] = {
license = "see context related readme files"
}
+local utf = unicode.utf8
+
+local next, format, match, lower = next, string.format, string.match, string.lower
+local concat, sortedkeys, utfbyte, serialize = table.concat, table.sortedkeys, utf.byte, table.serialize
+
+local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end)
+local trace_scaling = false trackers.register("fonts.scaling" , function(v) trace_scaling = v end)
+
+-- tfmdata has also fast access to indices and unicodes
+-- to be checked: otf -> tfm -> tfmscaled
+--
+-- watch out: no negative depths and negative eights permitted in regular fonts
+
--[[ldx--
Here we only implement a few helper functions.
--ldx]]--
fonts = fonts or { }
fonts.tfm = fonts.tfm or { }
+fonts.ids = fonts.ids or { }
local tfm = fonts.tfm
-fonts.loaded = fonts.loaded or { }
-fonts.dontembed = fonts.dontembed or { }
-fonts.logger = fonts.logger or { }
-fonts.loadtime = 0
-fonts.triggers = fonts.triggers or { } -- brrr
+fonts.loaded = fonts.loaded or { }
+fonts.dontembed = fonts.dontembed or { }
+fonts.triggers = fonts.triggers or { } -- brrr
+fonts.initializers = fonts.initializers or { }
+fonts.initializers.common = fonts.initializers.common or { }
+
+local fontdata = fonts.ids
+local glyph = node.id('glyph')
+local set_attribute = node.set_attribute
--[[ldx--
The next function encapsulates the standard loader as
supplied by .
--ldx]]--
-tfm.resolve_vf = true -- false
+tfm.resolve_vf = true -- false
+tfm.share_base_kerns = false -- true (.5 sec slower on mk but brings down mem from 410M to 310M, beware: then script/lang share too)
+tfm.mathactions = { }
function tfm.enhance(tfmdata,specification)
local name, size = specification.name, specification.size
- local encoding, filename = name:match("^(.-)%-(.*)$") -- context: encoding-name.*
+ local encoding, filename = match(name,"^(.-)%-(.*)$") -- context: encoding-name.*
if filename and encoding and fonts.enc.known[encoding] then
local data = fonts.enc.load(encoding)
if data then
@@ -38,14 +58,14 @@ function tfm.enhance(tfmdata,specification)
tfmdata.encoding = encoding
local vector = data.vector
local original = { }
- for k, v in pairs(characters) do
+ for k, v in next, characters do
v.name = vector[k]
v.index = k
original[k] = v
end
- for k,v in pairs(data.unicodes) do
+ for k,v in next, data.unicodes do
if k ~= v then
- if fonts.trace then
+ if trace_defining then
logs.report("define font","mapping %s onto %s",k,v)
end
characters[k] = original[v]
@@ -56,21 +76,9 @@ function tfm.enhance(tfmdata,specification)
end
function tfm.read_from_tfm(specification)
- local fname, tfmdata = specification.filename, nil
- if fname then
- -- safeguard, we use tfm as fallback
- local suffix = file.extname(fname)
- if suffix ~= "" and suffix ~= "tfm" then
- fname = ""
- end
- end
- if not fname or fname == "" then
- fname = input.findbinfile(specification.name, 'ofm')
- else
- fname = input.findbinfile(fname, 'ofm')
- end
- if fname and fname ~= "" then
- if fonts.trace then
+ local fname, tfmdata = specification.filename or "", nil
+ if fname ~= "" then
+ if trace_defining then
logs.report("define font","loading tfm file %s at size %s",fname,specification.size)
end
tfmdata = font.read_tfm(fname,specification.size) -- not cached, fast enough
@@ -78,12 +86,12 @@ function tfm.read_from_tfm(specification)
tfmdata.descriptions = tfmdata.descriptions or { }
if tfm.resolve_vf then
fonts.logger.save(tfmdata,file.extname(fname),specification) -- strange, why here
- fname = input.findbinfile(specification.name, 'ovf')
+ fname = resolvers.findbinfile(specification.name, 'ovf')
if fname and fname ~= "" then
local vfdata = font.read_vf(fname,specification.size) -- not cached, fast enough
if vfdata then
local chars = tfmdata.characters
- for k,v in pairs(vfdata.characters) do -- no ipairs, can have holes
+ for k,v in next, vfdata.characters do
chars[k].commands = v.commands
end
tfmdata.type = 'virtual'
@@ -93,10 +101,8 @@ function tfm.read_from_tfm(specification)
end
tfm.enhance(tfmdata,specification)
end
- else
- if fonts.trace then
- logs.report("define font","loading tfm with name %s fails",specification.name)
- end
+ elseif trace_defining then
+ logs.report("define font","loading tfm with name %s fails",specification.name)
end
return tfmdata
end
@@ -107,21 +113,17 @@ do with the fact that uses a negative multiple of 1000 as
a signal for a font scaled based on the design size.
--ldx]]--
-do
-
- local factors = {
- pt = 65536.0,
- bp = 65781.8,
- }
-
- function tfm.setfactor(f)
- tfm.factor = factors[f or 'pt'] or factors.pt
- end
-
- tfm.setfactor()
+local factors = {
+ pt = 65536.0,
+ bp = 65781.8,
+}
+function tfm.setfactor(f)
+ tfm.factor = factors[f or 'pt'] or factors.pt
end
+tfm.setfactor()
+
function tfm.scaled(scaledpoints, designsize) -- handles designsize in sp as well
if scaledpoints < 0 then
if designsize then
@@ -160,9 +162,11 @@ function tfm.check_virtual_id(tfmdata, id)
if not tfmdata.fonts or #tfmdata.fonts == 0 then
tfmdata.type, tfmdata.fonts = "real", nil
else
- for k,v in ipairs(tfmdata.fonts) do
- if v.id and v.id == 0 then
- v.id = id
+ local vfonts = tfmdata.fonts
+ for f=1,#vfonts do
+ local fnt = vfonts[f]
+ if fnt.id and fnt.id == 0 then
+ fnt.id = id
end
end
end
@@ -177,25 +181,91 @@ excessive memory usage in CJK fonts, we no longer pass the boundingbox.)
fonts.trace_scaling = false
+-- the following hack costs a bit of runtime but safes memory
+--
+-- basekerns are scaled and will be hashed by table id
+-- sharedkerns are unscaled and are be hashed by concatenated indexes
+
+function tfm.check_base_kerns(tfmdata)
+ if tfm.share_base_kerns then
+ local sharedkerns = tfmdata.sharedkerns
+ if sharedkerns then
+ local basekerns = { }
+ tfmdata.basekerns = basekerns
+ return sharedkerns, basekerns
+ end
+ end
+ return nil, nil
+end
+
+function tfm.prepare_base_kerns(tfmdata)
+ if tfm.share_base_kerns and not tfmdata.sharedkerns then
+ local sharedkerns = { }
+ tfmdata.sharedkerns = sharedkerns
+ for u, chr in next, tfmdata.characters do
+ local kerns = chr.kerns
+ if kerns then
+ local hash = concat(sortedkeys(kerns), " ")
+ local base = sharedkerns[hash]
+ if not base then
+ sharedkerns[hash] = kerns
+ else
+ chr.kerns = base
+ end
+ end
+ end
+ end
+end
+
+-- we can have cache scaled characters when we are in node mode and don't have
+-- protruding and expansion: hash == fullname @ size @ protruding @ expansion
+-- but in practice (except from mk) the otf hash will be enough already so it
+-- makes no sense to mess up the code now
+
+local charactercache = { }
+
+-- The scaler is only used for otf and afm and virtual fonts. If
+-- a virtual font has italic correction make sur eto set the
+-- has_italic flag. Some more flags will be added in the future.
+
function tfm.do_scale(tfmtable, scaledpoints)
- local trace = fonts.trace_scaling
+ tfm.prepare_base_kerns(tfmtable) -- optimalization
if scaledpoints < 0 then
scaledpoints = (- scaledpoints/1000) * tfmtable.designsize -- already in sp
end
---~ print(">>>",tfmtable.units)
local delta = scaledpoints/(tfmtable.units or 1000) -- brr, some open type fonts have 2048
local t = { }
- t.factor = delta
- for k,v in pairs(tfmtable) do
- t[k] = (type(v) == "table" and { }) or v
- end
- -- new
+ -- unicoded unique descriptions shared cidinfo characters changed parameters indices
+ for k,v in next, tfmtable do
+ if type(v) == "table" then
+ -- print(k)
+ else
+ t[k] = v
+ end
+ end
+ -- status
+ local isvirtual = tfmtable.type == "virtual" or tfmtable.virtualized
+ local hasmath = tfmtable.math_parameters ~= nil or tfmtable.MathConstants ~= nil
+ local nodemode = tfmtable.mode == "node"
+ local hasquality = tfmtable.auto_expand or tfmtable.auto_protrude
+ local hasitalic = tfmtable.has_italic
+ --
+ t.parameters = { }
+ t.characters = { }
+ t.MathConstants = { }
+ -- fast access
+ local descriptions = tfmtable.descriptions or { }
+ t.unicodes = tfmtable.unicodes
+ t.indices = tfmtable.indices
+ t.marks = tfmtable.marks
+ t.descriptions = descriptions
if tfmtable.fonts then
- t.fonts = table.fastcopy(tfmtable.fonts)
+ t.fonts = table.fastcopy(tfmtable.fonts) -- hm also at the end
end
- -- local zerobox = { 0, 0, 0, 0 }
local tp = t.parameters
+ local mp = t.math_parameters
local tfmp = tfmtable.parameters -- let's check for indexes
+ --
tp.slant = (tfmp.slant or tfmp[1] or 0)
tp.space = (tfmp.space or tfmp[2] or 0)*delta
tp.space_stretch = (tfmp.space_stretch or tfmp[3] or 0)*delta
@@ -205,107 +275,271 @@ function tfm.do_scale(tfmtable, scaledpoints)
tp.extra_space = (tfmp.extra_space or tfmp[7] or 0)*delta
local protrusionfactor = (tp.quad ~= 0 and 1000/tp.quad) or 0
local tc = t.characters
- -- we can loop over (descriptions or characters), in which case
- -- we don't need to init characters in afm/otf (saves some mem)
- -- but then .. beware of protruding etc
- local descriptions = tfmtable.descriptions or { }
- t.descriptions = descriptions
+ local characters = tfmtable.characters
local nameneeded = not tfmtable.shared.otfdata --hack
--- loop over descriptions
- -- afm and otf have descriptions, tfm not
- for k,v in pairs(tfmtable.characters) do
- local description = descriptions[k] or v
- local chr
- -- there is no need (yet) to assign a value to chr.tonunicode
- if nameneeded then
- chr = {
- name = description.name, -- is this used at all?
- index = description.index or k,
- width = delta*(description.width or 0),
- height = delta*(description.height or 0),
- depth = delta*(description.depth or 0),
- }
+ local changed = tfmtable.changed or { } -- for base mode
+ local ischanged = not table.is_empty(changed)
+ local indices = tfmtable.indices
+ local luatex = tfmtable.luatex
+ local tounicode = luatex and luatex.tounicode
+ local defaultwidth = luatex and luatex.defaultwidth or 0
+ local defaultheight = luatex and luatex.defaultheight or 0
+ local defaultdepth = luatex and luatex.defaultdepth or 0
+ -- experimental, sharing kerns (unscaled and scaled) saves memory
+ local sharedkerns, basekerns = tfm.check_base_kerns(tfmtable)
+ -- loop over descriptions (afm and otf have descriptions, tfm not)
+ -- there is no need (yet) to assign a value to chr.tonunicode
+ local scaledwidth = defaultwidth * delta
+ local scaledheight = defaultheight * delta
+ local scaleddepth = defaultdepth * delta
+ local stackmath = tfmtable.ignore_stack_math ~= true
+ for k,v in next, characters do
+ local chr, description, index
+ if ischanged then
+ -- basemode hack
+ local c = changed[k]
+ if c then
+ description = descriptions[c] or v
+ v = characters[c] or v
+ index = (indices and indices[c]) or c
+ else
+ description = descriptions[k] or v
+ index = (indices and indices[k]) or k
+ end
else
- chr = {
- index = description.index or k,
- width = delta*(description.width or 0),
- height = delta*(description.height or 0),
- depth = delta*(description.depth or 0),
- }
- end
- if trace then
- logs.report("define font","t=%s, u=%s, i=%s, n=%s c=%s",k,chr.tounicode or k,description.index,description.name or '-',description.class or '-')
- end
- local ve = v.expansion_factor
- if ve then
- chr.expansion_factor = ve*1000 -- expansionfactor
- end
- local vl = v.left_protruding
- if vl then
- chr.left_protruding = protrusionfactor*chr.width*vl
+ description = descriptions[k] or v
+ index = (indices and indices[k]) or k
+ end
+ local width = description.width
+ local height = description.height
+ local depth = description.depth
+ if width then width = delta*width else width = scaledwidth end
+ if height then height = delta*height else height = scaledheight end
+ -- if depth then depth = delta*depth else depth = scaleddepth end
+ if depth and depth ~= 0 then
+ depth = delta*depth
+ if nameneeded then
+ chr = {
+ name = description.name,
+ index = index,
+ height = height,
+ depth = depth,
+ width = width,
+ }
+ else
+ chr = {
+ index = index,
+ height = height,
+ depth = depth,
+ width = width,
+ }
+ end
+ else
+ -- this saves a little bit of memory time and memory, esp for big cjk fonts
+ if nameneeded then
+ chr = {
+ name = description.name,
+ index = index,
+ height = height,
+ width = width,
+ }
+ else
+ chr = {
+ index = index,
+ height = height,
+ width = width,
+ }
+ end
end
- local vr = v.right_protruding
- if vr then
- chr.right_protruding = protrusionfactor*chr.width*vr
+ -- if trace_scaling then
+ -- logs.report("define font","t=%s, u=%s, i=%s, n=%s c=%s",k,chr.tounicode or k,description.index,description.name or '-',description.class or '-')
+ -- end
+ if tounicode then
+ local tu = tounicode[index]
+ if tu then
+ chr.tounicode = tu
+ end
end
- local vi = description.italic
- if vi then
- chr.italic = vi*delta
+ if hasquality then
+ local ve = v.expansion_factor
+ if ve then
+ chr.expansion_factor = ve*1000 -- expansionfactor, hm, can happen elsewhere
+ end
+ local vl = v.left_protruding
+ if vl then
+ chr.left_protruding = protrusionfactor*width*vl
+ end
+ local vr = v.right_protruding
+ if vr then
+ chr.right_protruding = protrusionfactor*width*vr
+ end
end
- local vk = v.kerns
- if vk then
- local tt = {}
- for k,v in pairs(vk) do tt[k] = v*delta end
- chr.kerns = tt
+ -- todo: hasitalic
+ if hasitalic then
+ local vi = description.italic or v.italic
+ if vi and vi ~= 0 then
+ chr.italic = vi*delta
+ end
end
- local vl = v.ligatures
- if vl then
- if true then
- chr.ligatures = vl -- shared
+ -- to be tested
+ if hasmath then
+ -- todo, just operate on descriptions.math
+ local vn = v.next
+ if vn then
+ chr.next = vn
else
- local tt = { }
- for i,l in pairs(vl) do
- tt[i] = l
+ local vv = v.vert_variants
+ if vv then
+ local t = { }
+ for i=1,#vv do
+ local vvi = vv[i]
+ t[i] = {
+ ["start"] = (vvi["start"] or 0)*delta,
+ ["end"] = (vvi["end"] or 0)*delta,
+ ["advance"] = (vvi["advance"] or 0)*delta,
+ ["extender"] = vvi["extender"],
+ ["glyph"] = vvi["glyph"],
+ }
+ end
+ chr.vert_variants = t
+ else
+ local hv = v.horiz_variants
+ if hv then
+ local t = { }
+ for i=1,#hv do
+ local hvi = hv[i]
+ t[i] = {
+ ["start"] = (hvi["start"] or 0)*delta,
+ ["end"] = (hvi["end"] or 0)*delta,
+ ["advance"] = (hvi["advance"] or 0)*delta,
+ ["extender"] = hvi["extender"],
+ ["glyph"] = hvi["glyph"],
+ }
+ end
+ chr.horiz_variants = t
+ end
+ end
+ end
+ local vt = description.top_accent
+ if vt then
+ chr.top_accent = delta*vt
+ end
+ if stackmath then
+ local mk = v.mathkerns
+ if mk then
+ local kerns = { }
+ -- for k, v in next, mk do
+ -- local kk = { }
+ -- for i=1,#v do
+ -- local vi = v[i]
+ -- kk[i] = { height = delta*vi.height, kern = delta*vi.kern }
+ -- end
+ -- kerns[k] = kk
+ -- end
+ local v = mk.top_right if v then local k = { } for i=1,#v do local vi = v[i]
+ k[i] = { height = delta*vi.height, kern = delta*vi.kern }
+ end kerns.top_right = k end
+ local v = mk.top_left if v then local k = { } for i=1,#v do local vi = v[i]
+ k[i] = { height = delta*vi.height, kern = delta*vi.kern }
+ end kerns.top_left = k end
+ local v = mk.bottom_left if v then local k = { } for i=1,#v do local vi = v[i]
+ k[i] = { height = delta*vi.height, kern = delta*vi.kern }
+ end kerns.bottom_left = k end
+ local v = mk.bottom_right if v then local k = { } for i=1,#v do local vi = v[i]
+ k[i] = { height = delta*vi.height, kern = delta*vi.kern }
+ end kerns.bottom_right = k end
+ chr.mathkern = kerns -- singular
end
- chr.ligatures = tt
end
end
- local vc = v.commands
- if vc then
- -- we assume non scaled commands here
- local ok = false
- for i=1,#vc do
- local key = vc[i][1]
- -- if key == "right" or key == "left" or key == "down" or key == "up" then
- if key == "right" or key == "down" then
- ok = true
- break
+ if not nodemode then
+ local vk = v.kerns
+ if vk then
+ if sharedkerns then
+ local base = basekerns[vk] -- hashed by table id, not content
+ if not base then
+ base = {}
+ for k,v in next, vk do base[k] = v*delta end
+ basekerns[vk] = base
+ end
+ chr.kerns = base
+ else
+ local tt = {}
+ for k,v in next, vk do tt[k] = v*delta end
+ chr.kerns = tt
+ end
+ end
+ local vl = v.ligatures
+ if vl then
+ if true then
+ chr.ligatures = vl -- shared
+ else
+ local tt = { }
+ for i,l in next, vl do
+ tt[i] = l
+ end
+ chr.ligatures = tt
end
end
- if ok then
- local tt = { }
+ end
+ if isvirtual then
+ local vc = v.commands
+ if vc then
+ -- we assume non scaled commands here
+ local ok = false
for i=1,#vc do
- local ivc = vc[i]
- local key = ivc[1]
- -- if key == "right" or key == "left" or key == "down" or key == "up" then
+ local key = vc[i][1]
if key == "right" or key == "down" then
- tt[#tt+1] = { key, ivc[2]*delta }
- else -- not comment
- tt[#tt+1] = ivc -- shared since in cache and untouched
+ ok = true
+ break
end
end
- chr.commands = tt
- else
- chr.commands = vc
+ if ok then
+ local tt = { }
+ for i=1,#vc do
+ local ivc = vc[i]
+ local key = ivc[1]
+ if key == "right" or key == "down" then
+ tt[#tt+1] = { key, ivc[2]*delta }
+ else -- not comment
+ tt[#tt+1] = ivc -- shared since in cache and untouched
+ end
+ end
+ chr.commands = tt
+ else
+ chr.commands = vc
+ end
end
end
tc[k] = chr
end
-- t.encodingbytes, t.filename, t.fullname, t.name: elsewhere
t.size = scaledpoints
+ t.factor = delta
if t.fonts then
t.fonts = table.fastcopy(t.fonts) -- maybe we virtualize more afterwards
end
+ if hasmath then
+ -- mathematics.extras.copy(t) -- can be done elsewhere if needed
+ local ma = tfm.mathactions
+ for i=1,#ma do
+ ma[i](t,tfmtable,delta)
+ end
+ end
+ -- needed for \high cum suis
+ local tpx = tp.x_height
+ if not tp[13] then tp[13] = .86*tpx end -- mathsupdisplay
+ if not tp[14] then tp[14] = .86*tpx end -- mathsupnormal
+ if not tp[15] then tp[15] = .86*tpx end -- mathsupcramped
+ if not tp[16] then tp[16] = .48*tpx end -- mathsubnormal
+ if not tp[17] then tp[17] = .48*tpx end -- mathsubcombined
+ if not tp[22] then tp[22] = 0 end -- mathaxisheight
+ if t.MathConstants then t.MathConstants.AccentBaseHeight = nil end -- safeguard
+ t.tounicode = 1
+ -- we have t.name=metricfile and t.fullname=RealName and t.filename=diskfilename
+ -- when collapsing fonts, luatex looks as both t.name and t.fullname as ttc files
+ -- can have multiple subfonts
+--~ collectgarbage("collect")
return t, delta
end
@@ -320,14 +554,25 @@ tfm.auto_cleanup = true
local lastfont = nil
--- we can get rid of the tfm instance when we hav efast access to the
+-- we can get rid of the tfm instance when we have fast access to the
-- scaled character dimensions at the tex end, e.g. a fontobject.width
+--
+-- flushing the kern and ligature tables from memory saves a lot (only
+-- base mode) but it complicates vf building where the new characters
+-- demand this data
+
+--~ for id, f in pairs(fonts.ids) do -- or font.fonts
+--~ local ffi = font.fonts[id]
+--~ f.characters = ffi.characters
+--~ f.kerns = ffi.kerns
+--~ f.ligatures = ffi.ligatures
+--~ end
function tfm.cleanup_table(tfmdata) -- we need a cleanup callback, now we miss the last one
if tfm.auto_cleanup then -- ok, we can hook this into everyshipout or so ... todo
- if tfmdata.type == 'virtual' then
- for k, v in pairs(tfmdata.characters) do
- if v.commands then v.commands = nil end
+ if tfmdata.type == 'virtual' or tfmdata.virtualized then
+ for k, v in next, tfmdata.characters do
+ if v.commands then v.commands = nil end
end
end
end
@@ -348,235 +593,6 @@ function tfm.scale(tfmtable, scaledpoints)
return t
end
---[[ldx--
-
The following functions are used for reporting about the fonts
-used. The message itself is not that useful in regular runs but since
-we now have several readers it may be handy to know what reader is
-used for which font.
---ldx]]--
-
-function fonts.logger.save(tfmtable,source,specification) -- save file name in spec here ! ! ! ! ! !
- if tfmtable and specification and specification.specification then
- if fonts.trace then
- logs.report("define font","registering %s as %s",specification.name,source)
- end
- specification.source = source
- fonts.loaded[specification.specification] = specification
- fonts.used[specification.name] = source
- end
-end
-
---~ function fonts.logger.report(separator)
---~ local s = table.sortedkeys(fonts.loaded)
---~ if #s > 0 then
---~ local t = { }
---~ for _,v in ipairs(s) do
---~ t[#t+1] = v .. ":" .. fonts.loaded[v].source
---~ end
---~ return table.concat(t,separator or " ")
---~ else
---~ return "none"
---~ end
---~ end
-
-function fonts.logger.report(separator)
- local s = table.sortedkeys(fonts.used)
- if #s > 0 then
- local t = { }
- for _,v in ipairs(s) do
- t[#t+1] = v .. ":" .. fonts.used[v]
- end
- return table.concat(t,separator or " ")
- else
- return "none"
- end
-end
-
-function fonts.logger.format(name)
- return fonts.used[name] or "unknown"
-end
-
---[[ldx--
-
When we implement functions that deal with features, most of them
-will depend of the font format. Here we define the few that are kind
-of neutral.
---ldx]]--
-
-fonts.initializers = fonts.initializers or { }
-fonts.initializers.common = fonts.initializers.common or { }
-
---[[ldx--
-
This feature will remove inter-digit kerns.
---ldx]]--
-
-table.insert(fonts.triggers,"equaldigits")
-
-function fonts.initializers.common.equaldigits(tfmdata,value)
- if value then
- local chr = tfmdata.characters
- for i = utf.byte('0'), utf.byte('9') do
- local c = chr[i]
- if c then
- c.kerns = nil
- end
- end
- end
-end
-
---[[ldx--
-
This feature will give all glyphs an equal height and/or depth. Valid
-values are none, height, depth and
-both.
---ldx]]--
-
-table.insert(fonts.triggers,"lineheight")
-
-function fonts.initializers.common.lineheight(tfmdata,value)
- if value and type(value) == "string" then
- if value == "none" then
- for _,v in pairs(tfmdata.characters) do
- v.height, v.depth = 0, 0
- end
- else
- local ascender, descender = tfmdata.ascender, tfmdata.descender
- if ascender and descender then
- local ht, dp = ascender or 0, descender or 0
- if value == "height" then
- dp = 0
- elseif value == "depth" then
- ht = 0
- end
- if ht > 0 then
- if dp > 0 then
- for _,v in pairs(tfmdata.characters) do
- v.height, v.depth = ht, dp
- end
- else
- for _,v in pairs(tfmdata.characters) do
- v.height = ht
- end
- end
- elseif dp > 0 then
- for _,v in pairs(tfmdata.characters) do
- v.depth = dp
- end
- end
- end
- end
- end
-end
-
---[[ldx--
-
It does not make sense any more to support messed up encoding vectors
-so we stick to those that implement oldstyle and small caps. After all,
-we move on. We can extend the next function on demand. This features is
-only used with files.
---ldx]]--
-
-do
-
- local smallcaps = lpeg.P(".sc") + lpeg.P(".smallcaps") + lpeg.P(".caps") + lpeg.P("small")
- local oldstyle = lpeg.P(".os") + lpeg.P(".oldstyle") + lpeg.P(".onum")
-
- smallcaps = lpeg.Cs((1-smallcaps)^1) * smallcaps^1
- oldstyle = lpeg.Cs((1-oldstyle )^1) * oldstyle ^1
-
- function fonts.initializers.common.encoding(tfmdata,value)
- if value then
- local afmdata = tfmdata.shared.afmdata
- if afmdata then
- local encodingfile = value .. '.enc'
- local encoding = fonts.enc.load(encodingfile)
- if encoding then
- local vector = encoding.vector
- local characters = tfmdata.characters
- local unicodes = afmdata.luatex.unicodes
- local function remap(pattern,name)
- local p = pattern:match(name)
- if p then
- local oldchr, newchr = unicodes[p], unicodes[name]
- if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
- -- logs.report("encoding","%s (%s) -> %s (%s)",p,oldchr or -1,name,newchr or -1)
- characters[oldchr] = characters[newchr]
- end
- end
- return p
- end
- for _, name in pairs(vector) do
- local ok = remap(smallcaps,name) or remap(oldstyle,name)
- end
- if fonts.map.data[tfmdata.name] then
- fonts.map.data[tfmdata.name].encoding = encodingfile
- end
- end
- end
- end
- end
-
- -- when needed we can provide this as features in e.g. afm files
-
- function fonts.initializers.common.remap(tfmdata,value,pattern) -- will go away
- if value then
- local afmdata = tfmdata.shared.afmdata
- if afmdata then
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local unicodes = afmdata.luatex.unicodes
- local done = false
- for u, _ in pairs(characters) do
- local name = descriptions[u].name
- if name then
- local p = pattern:match(name)
- if p then
- local oldchr, newchr = unicodes[p], unicodes[name]
- if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
- characters[oldchr] = characters[newchr]
- end
- end
- end
- end
- end
- end
- end
-
- function fonts.initializers.common.oldstyle(tfmdata,value)
- fonts.initializers.common.remap(tfmdata,value,oldstyle)
- end
- function fonts.initializers.common.smallcaps(tfmdata,value)
- fonts.initializers.common.remap(tfmdata,value,smallcaps)
- end
-
- function fonts.initializers.common.fakecaps(tfmdata,value)
- if value then
- -- todo: scale down
- local afmdata = tfmdata.shared.afmdata
- if afmdata then
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local unicodes = afmdata.luatex.unicodes
- for u, _ in pairs(characters) do
- local name = descriptions[u].name
- if name then
- local p = name:lower()
- if p then
- local oldchr, newchr = unicodes[p], unicodes[name]
- if oldchr and newchr and type(oldchr) == "number" and type(newchr) == "number" then
- characters[oldchr] = characters[newchr]
- end
- end
- end
- end
- end
- end
- end
-
-end
-
---~ function fonts.initializers.common.install(format,feature) -- 'afm','lineheight'
---~ fonts.initializers.base[format][feature] = fonts.initializers.common[feature]
---~ fonts.initializers.node[format][feature] = fonts.initializers.common[feature]
---~ end
-
--[[ldx--
Analyzers run per script and/or language and are needed in order to
process features right.
@@ -587,47 +603,31 @@ fonts.analyzers.aux = fonts.analyzers.aux or { }
fonts.analyzers.methods = fonts.analyzers.methods or { }
fonts.analyzers.initializers = fonts.analyzers.initializers or { }
-do
-
- local glyph = node.id('glyph')
- local fontdata = tfm.id
- local set_attribute = node.set_attribute
--- local unset_attribute = node.unset_attribute
--- local has_attribute = node.has_attribute
-
- local state = attributes.numbers['state'] or 100
-
- -- todo: analyzers per script/lang, cross font, so we need an font id hash -> script
- -- e.g. latin -> hyphenate, arab -> 1/2/3 analyze
-
- -- an example analyzer
-
- function fonts.analyzers.aux.setstate(head,font)
- local tfmdata = fontdata[font]
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local first, last, current, n, done = nil, nil, head, 0, false -- maybe make n boolean
- while current do
- if current.id == glyph and current.font == font then
- local d = descriptions[current.char]
- if d then
- if d.class == "mark" then
- done = true
- set_attribute(current,state,5) -- mark
- elseif n == 0 then
- first, last, n = current, current, 1
- set_attribute(current,state,1) -- init
- else
- last, n = current, n+1
- set_attribute(current,state,2) -- medi
- end
- else -- finish
- if first and first == last then
- set_attribute(last,state,4) -- isol
- elseif last then
- set_attribute(last,state,3) -- fina
- end
- first, last, n = nil, nil, 0
+-- todo: analyzers per script/lang, cross font, so we need an font id hash -> script
+-- e.g. latin -> hyphenate, arab -> 1/2/3 analyze
+
+-- an example analyzer (should move to font-ota.lua)
+
+local state = attributes.private('state')
+
+function fonts.analyzers.aux.setstate(head,font)
+ local tfmdata = fontdata[font]
+ local characters = tfmdata.characters
+ local descriptions = tfmdata.descriptions
+ local first, last, current, n, done = nil, nil, head, 0, false -- maybe make n boolean
+ while current do
+ if current.id == glyph and current.font == font then
+ local d = descriptions[current.char]
+ if d then
+ if d.class == "mark" then
+ done = true
+ set_attribute(current,state,5) -- mark
+ elseif n == 0 then
+ first, last, n = current, current, 1
+ set_attribute(current,state,1) -- init
+ else
+ last, n = current, n+1
+ set_attribute(current,state,2) -- medi
end
else -- finish
if first and first == last then
@@ -637,132 +637,22 @@ do
end
first, last, n = nil, nil, 0
end
- current = current.next
- end
- if first and first == last then
- set_attribute(last,state,4) -- isol
- elseif last then
- set_attribute(last,state,3) -- fina
- end
- return head, done
- end
-
-end
-
---[[ldx--
-
We move marks into the components list. This saves much nasty testing later on.
---ldx]]--
-
-do
-
- local glyph = node.id('glyph')
- local fontdata = tfm.id
- local marknumber = attributes.numbers['mark'] or 200
- local set_attribute = node.set_attribute
-
- function fonts.pushmarks(head,font)
- local tfmdata = fontdata[font]
- local characters = tfmdata.characters
- local descriptions = tfmdata.descriptions
- local current, last, done, n = head, nil, false, 0
- while current do
- if current.id == glyph and current.font == font then
- local d = descriptions[current.char]
- if d and d.class == "mark" then
- -- check if head
- if last and not last.components then
- last.components = current
- current.prev = nil -- last.components.prev = nil
- done = true
- n = 1
- else
- n = n + 1
- end
- set_attribute(current,marknumber,n)
- current = current.next
- elseif last and last.components then
- -- finish 'm
- current.prev.next = nil
- current.prev = last
- last.next = current
- last = current
- last = nil
- else
- last = current
- current = current.next
- end
- elseif last and last.components then
- current.prev.next = nil
- current.prev = last
- last.next = current
- last = nil
- else
- last = nil
- current = current.next
- end
- end
- if last and last.components then
- last.next = nil
- end
- tfmdata.shared.markspushed = done
- return head, done
- end
-
- function fonts.removemarks(head,font)
- local current, done, characters, descriptions = head, false, tfmdata.characters, tfmdata.descriptions
- while current do
- if current.id == glyph and current.font == font and descriptions[current.char].class == "mark" then
- local next, prev = current.next, current.prev
- if next then
- next.prev = prev
- end
- if prev then
- prev.next = next
- else
- head = next
- end
- node.free(current)
- current = next
- done = true
- else
- current = current.next
+ else -- finish
+ if first and first == last then
+ set_attribute(last,state,4) -- isol
+ elseif last then
+ set_attribute(last,state,3) -- fina
end
+ first, last, n = nil, nil, 0
end
- return head, done
+ current = current.next
end
-
- function fonts.popmarks(head,font)
- local tfmdata = fontdata[font]
- if tfmdata.shared.markspushed then
- local current, done, characters = head, false, tfmdata.characters
- while current do
- if current.id == glyph and current.font == font then
- local components = current.components
- if components then
- local last, next = components, current.next
- while last.next do last = last.next end
- if next then
- next.prev = last
- end
- last.next= next
- current.next = components
- components.prev = current
- current.components = nil
- current = last.next
- done = true
- else
- current = current.next
- end
- else
- current = current.next
- end
- end
- return head, done
- else
- return head, false
- end
+ if first and first == last then
+ set_attribute(last,state,4) -- isol
+ elseif last then
+ set_attribute(last,state,3) -- fina
end
-
+ return head, done
end
function tfm.replacements(tfm,value)
@@ -800,7 +690,7 @@ function tfm.enhance(tfmdata,specification)
tfmdata.filename = specification.name
if not features.encoding then
local name, size = specification.name, specification.size
- local encoding, filename = name:match("^(.-)%-(.*)$") -- context: encoding-name.*
+ local encoding, filename = match(name,"^(.-)%-(.*)$") -- context: encoding-name.*
if filename and encoding and fonts.enc.known[encoding] then
features.encoding = encoding
end
@@ -809,6 +699,7 @@ tfmdata.filename = specification.name
end
function tfm.set_features(tfmdata)
+ -- todo: no local functions
local shared = tfmdata.shared
-- local tfmdata = shared.tfmdata
local features = shared.features
@@ -818,7 +709,8 @@ function tfm.set_features(tfmdata)
if fi and fi.tfm then
local function initialize(list) -- using tex lig and kerning
if list then
- for _, f in ipairs(list) do
+ for i=1,#list do
+ local f = list[i]
local value = features[f]
if value and fi.tfm[f] then -- brr
if tfm.trace_features then
@@ -839,7 +731,8 @@ function tfm.set_features(tfmdata)
if fm and fm.tfm then
local function register(list) -- node manipulations
if list then
- for _, f in ipairs(list) do
+ for i=1,#list do
+ local f = list[i]
if features[f] and fm.tfm[f] then -- brr
if not shared.processors then -- maybe also predefine
shared.processors = { fm.tfm[f] }
@@ -866,13 +759,13 @@ function tfm.reencode(tfmdata,encoding)
if data then
local characters, original, vector = tfmdata.characters, { }, data.vector
tfmdata.encoding = encoding -- not needed
- for k, v in pairs(characters) do
+ for k, v in next, characters do
v.name, v.index, original[k] = vector[k], k, v
end
- for k,v in pairs(data.unicodes) do
+ for k,v in next, data.unicodes do
if k ~= v then
- if fonts.trace then
- logs.report("define font","reencoding %04X to %04X",k,v)
+ if trace_defining then
+ logs.report("define font","reencoding U+%04X to U+%04X",k,v)
end
characters[k] = original[v]
end
@@ -893,13 +786,13 @@ function tfm.remap(tfmdata,remapping)
local vector = remapping and fonts.enc.remappings[remapping]
if vector then
local characters, original = tfmdata.characters, { }
- for k, v in pairs(characters) do
+ for k, v in next, characters do
original[k], characters[k] = v, nil
end
- for k,v in pairs(vector) do
+ for k,v in next, vector do
if k ~= v then
- if fonts.trace then
- logs.report("define font","remapping %04X to %04X",k,v)
+ if trace_defining then
+ logs.report("define font","remapping U+%04X to U+%04X",k,v)
end
local c = original[k]
characters[v] = c
@@ -915,3 +808,11 @@ tfm.features.register('remap')
fonts.initializers.base.tfm.remap = tfm.remap
fonts.initializers.node.tfm.remap = tfm.remap
+
+-- status info
+
+statistics.register("fonts load time", function()
+ if statistics.elapsedindeed(fonts) then
+ return format("%s seconds",statistics.elapsedtime(fonts))
+ end
+end)
diff --git a/tex/context/base/font-tra.mkiv b/tex/context/base/font-tra.mkiv
new file mode 100644
index 000000000..c45e1394d
--- /dev/null
+++ b/tex/context/base/font-tra.mkiv
@@ -0,0 +1,113 @@
+%D \module
+%D [ file=font-tra,
+%D version=2009.01.02, % or so
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=Tracing,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\unprotect
+
+%D \macros
+%D {doiffontpresentelse}
+%D
+%D \starttyping
+%D \doiffontpresentelse{texnansi-lmr10}{YES}{NO}
+%D \doiffontpresentelse{adam-lindsay-modern-serif}{YES}{NO}
+%D \stoptyping
+
+\def\doiffontpresentelse#1{\ctxlua{commands.doifelse(fonts.names.exists("#1"))}}
+
+% experimental, maybe this becomes a module
+
+\newbox\otfcollector
+
+\def\startotfcollecting{\ctxlua{nodes.tracers.steppers.start()}}
+\def\stopotfcollecting {\ctxlua{nodes.tracers.steppers.stop()}}
+\def\resetotfcollecting{\ctxlua{nodes.tracers.steppers.reset()}}
+
+% Rather experimental:
+%
+% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{الضَّرَّ} \page
+% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{لِلّٰهِ} \page
+
+\def\showotfstepglyphs#1%
+ {\ctxlua{nodes.tracers.steppers.glyphs(\number\otfcollector,#1)}%
+ \unhbox\otfcollector}
+
+\def\otfstepcharcommand#1#2% font char
+ {\removeunwantedspaces
+ \hskip.5em plus .125em\relax
+ U+\hexnumber{#2}:\ruledhbox{\ctxlua{nodes.tracers.fontchar(#1,#2)}}%
+ \hskip.5em plus .125em\relax}
+
+\def\otfstepmessagecommand#1#2%
+ {\begingroup
+ \tttf\language\minusone
+ \veryraggedright
+ \hangindent1em
+ \hangafter\plusone
+ \dontleavehmode\hbox{\detokenize{#1}}\removeunwantedspaces
+ \doifsomething{#2}{\break\detokenize{#2}}\endgraf
+ \endgroup
+ \blank}
+
+\def\showotfstepchars#1%
+ {\ctxlua{nodes.tracers.steppers.codes(#1,\!!bs\detokenize{\otfstepcharcommand}\!!es)}}
+
+\def\showotfstepmessages#1%
+ {\ctxlua{nodes.tracers.steppers.messages(#1,\!!bs\detokenize{\otfstepmessagecommand}\!!es,true)}}
+
+\def\showotfstepfeatures
+ {\ctxlua{nodes.tracers.steppers.features()}}
+
+\def\showotfsteps
+ {\dontleavehmode\bgroup\tttf \language\minusone features: \showotfstepfeatures\egroup
+ \blank
+ \dontleavehmode\bgroup\tttf result:\egroup
+ \blank
+ \startlinecorrection
+ \ruledhbox\bgroup\box\otfcompositionbox\egroup
+ \stoplinecorrection
+ \dorecurse{\ctxlua{nodes.tracers.steppers.nofsteps()}}
+ {\blank
+ \showotfstepmessages\recurselevel
+ \blank
+ \startlinecorrection
+ \dontleavehmode\bgroup\resetallattributes\pardir TLT\textdir TLT\relax\tttf\recurselevel: \showotfstepchars\recurselevel\egroup
+ \stoplinecorrection
+ \blank
+ \startlinecorrection
+ \ruledhbox % can be mode
+ \bgroup\resetallattributes\showotfstepglyphs\recurselevel\egroup % reset is new, we don't want additional processing
+ \stoplinecorrection
+ \blank}}
+
+\def\startotfsample
+ {\enabletrackers[*otf.sample]% beware, kind of global
+ \startotfcollecting
+ \begingroup}
+
+\def\stopotfsample
+ {\endgroup
+ \stopotfcollecting
+ \disabletrackers[*otf.sample]% beware, kind of global: otf.sample
+ \showotfsteps
+ \resetotfcollecting}
+
+\newbox\otfcompositionbox
+
+\def\showotfcomposition#1#2#3% {font*features at size}, rl=-1, text
+ {\begingroup
+ \setupcolors[\c!state=\v!start]% can be option
+ \startotfsample
+ \global\setbox\otfcompositionbox\hbox{\definedfont[#1]\ifnum#2<0 \textdir TRT\else\ifnum#2>0 \textdir TLT\fi\fi\relax#3}%
+ \stopotfsample
+ \endgroup}
+
+\protect \endinput
diff --git a/tex/context/base/font-uni.mkii b/tex/context/base/font-uni.mkii
new file mode 100644
index 000000000..1b8ce8e43
--- /dev/null
+++ b/tex/context/base/font-uni.mkii
@@ -0,0 +1,444 @@
+%D \module
+%D [ file=font-uni,
+%D version=1999.10.10,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=\UNICODE,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Font Macros / Unicode}
+
+%D In \XETEX, unicode support is straightforward, so we
+%D simply output a \type {\char} with a 16||bit number.
+
+\ifnum\texengine=\xetexengine
+ \unexpanded\def\uchar#1#2{\char\numexpr#2+#1*\pluscclvi\relax}
+ \let\uc\uchar
+ \endinput
+\fi
+
+%D Now comes the more traditional 8 bit \TEX\ hackery.
+
+%D I wrote this module when Wang Lei asked me how to use
+%D Chinese in \CONTEXT. From the samples he sent me, I deduced
+%D that some mixture of one and two byte encoding was used,
+%D which he confirmed. Since \TEX\ normally does not use the
+%D characters $>127$, so as long as the two byte characters
+%D have a first character with code $>127$, we can use active
+%D characters to handle them. In an optimistic mood, I called
+%D this module the \UNICODE\ font module. In the module that
+%D handles Chinese, we will see that some more interpretation
+%D is involved, which is why the macros handling those
+%D characters look ahead.
+
+\unprotect
+
+%D \macros
+%D {handleunicodeflowglyph, uchar,
+%D handleunicodeglyph, insertunicodeglyph,
+%D unicodeposition, unicodeone, unicodetwo}
+%D
+%D For the moment \UNICODE\ support is rather primitive but
+%D nevertheless effective. The reference to \UNICODE\ is not
+%D entirely correct, since in many cases one will use \quote
+%D {older} mappings, but in principle, \UNICODE\ can be
+%D supported.
+%D
+%D We expect each character to come as two eight bit
+%D characters. Those doubles are handled by making all
+%D characters in the range $>127$ active, so that they can
+%D pick up the next one, and act upon both their values.
+%D Internally only numbers are used. A first implementation
+%D simply internally prefixed the second part of the \UNICODE\
+%D pair with \type {\string} or \type {\char}, but this was
+%D not that handy when it came to testing those values.
+%D Because in principle we are dealing with an encoding, the
+%D making active is handled in \type {enco-uni}.
+%D
+%D There are two commands to handle unicode characters:
+%D
+%D \starttyping
+%D \handleunicodeflowglyph{number}{character}
+%D \uchar{number}{number}
+%D \stoptyping
+%D
+%D The first one can be assigned to an active character, the
+%D second one can be used to directly access a glyph. Both
+%D command call \type {\handleunicodeglyph} that in turn
+%D calls \type {\insertunicodeglyph}. Both can be overruled
+%D in specialized modules. The low level command \type
+%D {\unicodeglyph} can best be left untouched, which is not
+%D so much a problem because there is a hook into this macro:
+%D \type {\unicodecharcommand}.
+%D
+%D In most cases one will redefine \type {\handleunicodeglyph}
+%D in such a way that it identifies special situations first,
+%D takes some actions next, calls \type {\insertunicodeglyph},
+%D if needed with \type {\unicodecharcommand} changed, and
+%D finally does some finishing:
+%D
+%D \starttyping
+%D \def\handleunicodeglyph
+%D {take actions based on \unicodeone-two-position cq. \nextutoken
+%D redefine \unicodecharcommand if needed
+%D expand \insertunicodeglyph
+%D take some final actions}
+%D \stoptyping
+
+\newcount\unicodeposition
+
+%D The multistep approach is needed to pick up the second
+%D token, since this token can have any value and any
+%D catcode.
+
+% the \relax trick prevents eating up the space (needed for
+% korean
+
+\def\handleunicodeflowglyph#1#2%
+ {\begingroup
+ \edef\unicodeone{#1}%
+ \@EA\afterassignment\@EA\dohandleunicodeflowglyph % two redundant ea's
+ \@EA\chardef\@EA\nexttoken\@EA`\string#2\relax}
+
+\def\dohandleunicodeflowglyph\relax
+ {\futurelet\nextutoken\dodohandleunicodeflowglyph}
+
+\def\dodohandleunicodeflowglyph % todo tex (or maybe no longer)
+ {\edef\unicodetwo{\the\nexttoken}%
+ \unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
+ \handleunicodeglyph
+ \endgroup}
+
+\unexpanded\def\uchar#1#2% use as standalone glyph
+ {\begingroup
+ \edef\unicodeone{#1}%
+ \edef\unicodetwo{#2}%
+ \unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
+ \handleunicodeglyph
+ \endgroup}
+
+\let\nextutoken\relax
+
+\unexpanded\def\lookaheaduchar#1#2%
+ {\def\dolookaheaduchar{\uchar{#1}{#2}\let\nextutoken\relax}%
+ \futurelet\nextutoken\dolookaheaduchar}
+
+\def\dohandleucflowglyph
+ {\unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
+ \handleunicodeglyph
+ \endgroup}
+
+\unexpanded\def\uc#1#2% used in tricky situations
+ {\begingroup
+ \edef\unicodeone{#1}%
+ \edef\unicodetwo{#2}%
+ \futurelet\nextutoken\dohandleucflowglyph}
+
+\def\insertunicodeglyph
+ {\unicodeglyph\unicodeone\unicodetwo}
+
+\let\handleunicodeglyph\insertunicodeglyph
+
+%D One can use the \type {\unicodeposition} in the macros
+%D that handle pre and post material.
+
+%D \macros
+%D {unicodestyle, unicodecharcommand}
+%D
+%D Each character pair will become one glyph. Because \TEX\
+%D cannot handle fonts with more that 256 characters, we use
+%D \TFM\ files for each range. The first character of the pair
+%D is appended to the name of a font, and the second is used to
+%D access the glyph in that font. This means that a particular
+%D font is split up in subfonts with names in the range:
+%D
+%D \starttyping
+%D 80 ... ff
+%D \stoptyping
+%D
+%D The \type {} as well as the composed name are
+%D mapped ones. The next macros take care of this mapping.
+%D Let us assume that the next mapping has taken place,
+%D
+%D \starttyping
+%D \definefontsynonym [UnicodeRegular] [gbsong]
+%D \stoptyping
+%D
+%D Let us also assume that we are dealing with the range \type
+%D {b1}. Given that a font name results from:
+%D
+%D \starttyping
+%D \truefontname{\truefontname{UnicodeRegular}b1}
+%D \stoptyping
+%D
+%D we get \type {gbsongb1}. The outer \type {\truefontname}
+%D takes care of additional mapping, so when we say:
+%D
+%D \starttyping
+%D \definefontsynonym [gbsongb1] [gbsong-b1]
+%D \stoptyping
+%D
+%D the filename used will be \type {gbsong-b1}. From the next
+%D definition it will be clear that other fontshapes are also
+%D supported. The prefix \type {Unicode} is mapped!
+%D
+%D The command \type {\unicodecharcommand} can be used to
+%D handle special cases. At that moment \type {1em} is known.
+
+\def\unicodestyle
+ {\truefontname\s!Unicode\fontstylesuffix}
+
+\let\unicodecharcommand\firstofoneargument
+
+\unexpanded\def\unicodeglyph#1#2% watch the double mapping
+ {\begingroup
+ \getvalue{@@\currentucharmapping\strippedcsname\uchar}{#1}{#2}% map to a to hex font range
+ \bodyfontsize\unicodescale\bodyfontsize
+ % readable:
+ % \doifelsefontsynonym{\unicodestyle\unicodeone}
+ % {\font\unicodefont=\truefontname{\unicodestyle\unicodeone}
+ % at \currentfontscale\bodyfontsize}
+ % {\font\unicodefont=\truefontname{\truefontname\unicodestyle\unicodeone}
+ % at \currentfontscale\bodyfontsize}%
+ % unreadable but more efficient:
+ \font\unicodefont=\truefontname{\doifelsefontsynonym{\unicodestyle
+ \unicodeone}\empty\truefontname\unicodestyle\unicodeone}
+ at \currentfontscale\bodyfontsize
+ \unicodestrut % off by default
+ \unicodefont\unicodecharcommand{\char\unicodetwo\relax}%
+ \endgroup}
+
+%D This handler is used by default, for instance in:
+%D
+%D \starttyping
+%D \defineunicodefont [MySwitch] [MyFont] % [strut=no,command=\insertunicodeglyph]
+%D
+%D \definefontsynonym [MyFontRegular40] [Sans]
+%D \definefontsynonym [MyFontBold40] [SansBold]
+%D
+%D {\MySwitch \uchar{"40}{`a}}
+%D {\MySwitch \bf \uchar{"40}{`a}}
+%D \stoptyping
+%D
+%D \starttyping
+%D \definefontsynonym [MyFontRegular] [Sans]
+%D \definefontsynonym [MyFontBold] [SansBold]
+%D \stoptyping
+%D
+%D Is also possible, but in that case the number is appended to the raw font
+%D name!
+
+%D \macros
+%D {currentucharmapping,defineucharmapping}
+%D
+%D A (plane,char) pair can be remapped using a uchar mapping
+%D function. The default mapping is to convert the plane to a
+%D lowercase hexadecimal number, and leave the number
+%D untouched. The current remapping is kept in a macro.
+
+\let\currentucharmapping\s!default
+
+\def\defineucharmapping#1%
+ {\setvalue{@@#1\strippedcsname\uchar}}
+
+\defineucharmapping{\s!default}#1#2%
+ {\edef\unicodeone{\lchexnumbers{#1}}\edef\unicodetwo{#2}}
+
+%D An example of a remapping is the following:
+%D
+%D \starttyping
+%D \defineucharmapping{GBK}#1#2%
+%D {\unicodeposition=#1
+%D \advance\unicodeposition -129
+%D \multiply\unicodeposition 190
+%D \advance\unicodeposition #2
+%D \advance\unicodeposition-\ifnum#2>127 65\else64\fi
+%D \dorepositionunicode}
+%D \stoptyping
+%D
+%D This maps the GBK vector onto a compact GBK one. The
+%D auxiliary macro is defined here as a goody.
+
+\def\dorepositionunicode
+ {\dosetdivision\unicodeposition{256}\scratchcounter
+ \advance\scratchcounter \plusone
+ \edef\unicodeone{\ifnum\scratchcounter<10 0\fi\the\scratchcounter}%
+ \dosetmodulo\unicodeposition{256}\scratchcounter
+ \edef\unicodetwo{\the\scratchcounter}}
+
+%D \macros
+%D {setunicodestrut, setunicodescale, nextutoken,
+%D handleunicodeglyph, insertunicodeglyph}
+%D
+%D A careful analysis of the previous macros, learns that the
+%D process of mapping comes down to:
+%D
+%D \startitemize[packed,n]
+%D \item taking care of preceding material (and spacing)
+%D \item defining the font at \type {\currentfontscale} $\times$
+%D \type {\unicodescale} $\times$ \type {\bodyfontsize}
+%D \item inserting a \type {\unicodestrut}
+%D \item inserting the character (glyph)
+%D \item executing some actions afterwards
+%D \stopitemize
+%D
+%D The actions before and after placing the glyph, is up to
+%D the user supplied handler. This handler (\type
+%D {\handleunicodeglpyh}) must, at a certain moment, insert
+%D the glyph using \type {\insertunicodeglyph}
+
+\def\setunicodescale#1%
+ {\def\unicodescale{#1}}
+
+\def\dosetunicodestrut#1#2% height depth
+ {\def\unicodestrut
+ {\vrule
+ \!!width \zeropoint
+ \!!height#1\strutht
+ \!!depth #2\strutdp
+ \relax}}
+
+\def\setunicodestrut#1#2% height depth
+ {\ifdim#1\strutht>\zeropoint
+ \dosetunicodestrut{#1}{#2}%
+ \else\ifdim#1\strutdp>\zeropoint
+ \dosetunicodestrut{#1}{#2}%
+ \else
+ \let\unicodestrut\empty
+ \fi\fi}
+
+\def\resetunicodestrut
+ {\let\unicodestrut\empty}
+
+%D The additional scaling and strut default to:
+
+\setunicodescale{1}
+\setunicodestrut{1}{1}
+
+%D But better is not to have a strut added by default:
+
+\resetunicodestrut
+
+%D The actual code for the additional actions as well as
+%D specific spacing is handled outside these routines. The
+%D character after the two that are under treatment is
+%D available in \type {\nextutoken}.
+
+%D \macros
+%D {defineunicodefont, setupunicodefont}
+%D
+%D Apart from this rather low level implementation, we also
+%D provide a more user friendly alternative. Given that one
+%D has defined:
+%D
+%D \starttyping
+%D \defineunicodefont
+%D [SimChi] [SimplifiedChinese]
+%D [\c!scale=0.85,
+%D \c!height=1.25,
+%D \c!depth=1.00,
+%D \c!interlinespaceinterlinie=yes,
+%D \c!conversion=\chinesenumber,
+%D \c!command=\handlechineseunicodeglyph]
+%D \stoptyping
+%D
+%D Together with:
+%D
+%D \starttyping
+%D \definefontsynonym [SimplifiedChineseRegular] [gbsong]
+%D \definefontsynonym [SimplifiedChineseSlanted] [gbsongsl]
+%D \stoptyping
+%D
+%D we can now switch to Simplified Chinese by saying \type
+%D {SimChi}. Some values can be changed afterwards with
+%D
+%D \starttyping
+%D \setupunicodefont[SimChi][...=...]
+%D \stoptyping
+%D
+%D Specific initializations can be assigned to \type
+%D {commands}.
+
+\def\defineunicodefont
+ {\dotripleempty\dodefineunicodefont}
+
+\def\dodefineunicodefont[#1][#2][#3]%
+ {\doifassignmentelse{#3}
+ {\setupunicodefont[#1][#3]}
+ {\doifelsenothing{#3}
+ {\setupunicodefont[#1][#3]}
+ {\copyparameters
+ [\??uc#1][\??uc#3]
+ [\c!height,\c!depth,\c!scale,\c!commands,\c!strut,
+ \c!interlinespace,\c!command,\c!conversion]}}%
+ \doifelsenothing{#2}
+ {\setvalue{#1}{[uc font #1 undefined]}}
+ {\setvalue{\??uc#1\c!file}{#2}%
+ \doifundefined{\??ff#2\s!Bold}
+ {\definefontsynonym[#2\s!Bold] [#2\s!Regular]%
+ \definefontsynonym[#2\s!Slanted] [#2\s!Regular]%
+ \definefontsynonym[#2\s!Italic] [#2\s!Regular]%
+ \definefontsynonym[#2\s!BoldSlanted][#2\s!Slanted]%
+ \definefontsynonym[#2\s!BoldItalic] [#2\s!Italic]}%
+ \unexpanded\setvalue{#1}{\enableunicodefont{#1}}}}
+
+\def\setupunicodefont
+ {\dodoubleempty\dosetupunicodefont}
+
+\def\dosetupunicodefont[#1][#2]% also predefines
+ {\doifundefined{\??uc#1\c!command}
+ {\copyparameters
+ [\??uc#1][\??uc\s!default]
+ [\c!height,\c!depth,\c!scale,\c!commands,\v!strut,
+ \c!interlinespace,\c!command,\c!conversion]}%
+ \getparameters[\??uc#1][#2]}
+
+\def\enableunicodefont#1%
+ {\definefontsynonym[\s!Unicode][\getvalue{\??uc#1\c!file}]%
+ \def\unicodescale {\getvalue{\??uc#1\c!scale}}%
+ \def\unicodeheight {\getvalue{\??uc#1\c!height}}%
+ \def\unicodedepth {\getvalue{\??uc#1\c!depth}}%
+ \def\unicodedigits {\getvalue{\??uc#1\c!conversion}}%
+ \def\handleunicodeglyph {\getvalue{\??uc#1\c!command}}%
+ \doifnot\currentregime{utf}{\enableregime[unicode]}%
+ % the following \relax's are realy needed
+ \doifvalue{\??uc#1\c!interlinespace}\v!yes
+ \setupinterlinespace\relax
+ \doifelsevalue{\??uc#1\c!strut}\v!yes
+ {\setunicodestrut\unicodeheight\unicodedepth}
+ {\resetunicodestrut}%
+ \getvalue{\??uc#1\c!commands}\relax}
+
+%D \macros
+%D {unicodedigits}
+%D
+%D For convenience we also predefine a number conversion
+%D macro:
+
+\let\unicodedigits\number
+
+%D Because we cannot be sure of the pressence of all font
+%D styles, we remap some by default.
+
+\definefontsynonym [\s!Unicode\s!Bold] [\s!Unicode\s!Regular]
+\definefontsynonym [\s!Unicode\s!Slanted] [\s!Unicode\s!Regular]
+\definefontsynonym [\s!Unicode\s!Italic] [\s!Unicode\s!Regular]
+\definefontsynonym [\s!Unicode\s!BoldSlanted] [\s!Unicode\s!Slanted]
+\definefontsynonym [\s!Unicode\s!BoldItalic] [\s!Unicode\s!Italic]
+
+\setupunicodefont
+ [\s!default]
+ [\c!height=1,
+ \c!depth=1,
+ \c!scale=1,
+ \c!strut=\v!no,
+ \c!interlinespace=\v!no,
+ \c!command=\insertunicodeglyph,
+ \c!conversion=\number]
+
+\protect \endinput
diff --git a/tex/context/base/font-uni.mkiv b/tex/context/base/font-uni.mkiv
new file mode 100644
index 000000000..40ab75ed6
--- /dev/null
+++ b/tex/context/base/font-uni.mkiv
@@ -0,0 +1,26 @@
+%D \module
+%D [ file=font-uni,
+%D version=2008.11.03, % 1999.10.10,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=\UNICODE,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Font Macros / Unicode}
+
+%D In \MKIV\ we only provide the \type {\uchar} macro and
+%D implement it as just an \UTF\ converter. We expand it so
+%D best not use not use it for active characters.
+
+\unprotect
+
+\def\uchar#1#2{\ctxlua{commands.uchar(\number#1,\number#2)}}
+
+\let\uc\uchar
+
+\protect \endinput
diff --git a/tex/context/base/font-uni.tex b/tex/context/base/font-uni.tex
deleted file mode 100644
index 7d4f3e442..000000000
--- a/tex/context/base/font-uni.tex
+++ /dev/null
@@ -1,465 +0,0 @@
-%D \module
-%D [ file=font-uni,
-%D version=1999.10.10,
-%D title=\CONTEXT\ Font Macros,
-%D subtitle=\UNICODE\ Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Font Macros / UNICODE Support}
-
-%D I wrote this module when Wang Lei asked me how to use
-%D Chinese in \CONTEXT. From the samples he sent me, I deduced
-%D that some mixture of one and two byte encoding was used,
-%D which he confirmed. Since \TEX\ normally does not use the
-%D characters $>127$, so as long as the two byte characters
-%D have a first character with code $>127$, we can use active
-%D characters to handle them. In an optimistic mood, I called
-%D this module the \UNICODE\ font module. In the module that
-%D handles Chinese, we will see that some more interpretation
-%D is involved, which is why the macros handling those
-%D characters look ahead.
-
-% \startmessages dutch library: fonts
-% 21: het is veiliger om (pdf)eTeX te gebruiken
-% \stopmessages
-% \startmessages english library: fonts
-% 21: using (pdf)eTeX is more save
-% \stopmessages
-% \startmessages german library: fonts
-% 21: Verwenden von (pdf)eTeX ist sicherer
-% \stopmessages
-% \startmessages italian library: fonts
-% 21: l'uso di (pdf)eTeX è più sicuro
-% \stopmessages
-% \startmessages norwegian library: fonts
-% 21: å bruke (pdf)eTeX er tryggere
-% \stopmessages
-% \startmessages french library: fonts
-% 21: l'utilisation de (pdf)eTeX est plus économe
-% \stopmessages
-
-\unprotect
-
-%D \macros
-%D {handleunicodeflowglyph, uchar,
-%D handleunicodeglyph, insertunicodeglyph,
-%D unicodeposition, unicodeone, unicodetwo}
-%D
-%D For the moment \UNICODE\ support is rather primitive but
-%D nevertheless effective. The reference to \UNICODE\ is not
-%D entirely correct, since in many cases one will use \quote
-%D {older} mappings, but in principle, \UNICODE\ can be
-%D supported.
-%D
-%D We expect each character to come as two eight bit
-%D characters. Those doubles are handled by making all
-%D characters in the range $>127$ active, so that they can
-%D pick up the next one, and act upon both their values.
-%D Internally only numbers are used. A first implementation
-%D simply internally prefixed the second part of the \UNICODE\
-%D pair with \type {\string} or \type {\char}, but this was
-%D not that handy when it came to testing those values.
-%D Because in principle we are dealing with an encoding, the
-%D making active is handled in \type {enco-uni}.
-%D
-%D There are two commands to handle unicode characters:
-%D
-%D \starttyping
-%D \handleunicodeflowglyph{number}{character}
-%D \uchar{number}{number}
-%D \stoptyping
-%D
-%D The first one can be assigned to an active character, the
-%D second one can be used to directly access a glyph. Both
-%D command call \type {\handleunicodeglyph} that in turn
-%D calls \type {\insertunicodeglyph}. Both can be overruled
-%D in specialized modules. The low level command \type
-%D {\unicodeglyph} can best be left untouched, which is not
-%D so much a problem because there is a hook into this macro:
-%D \type {\unicodecharcommand}.
-%D
-%D In most cases one will redefine \type {\handleunicodeglyph}
-%D in such a way that it identifies special situations first,
-%D takes some actions next, calls \type {\insertunicodeglyph},
-%D if needed with \type {\unicodecharcommand} changed, and
-%D finally does some finishing:
-%D
-%D \starttyping
-%D \def\handleunicodeglyph
-%D {take actions based on \unicodeone-two-position cq. \nextutoken
-%D redefine \unicodecharcommand if needed
-%D expand \insertunicodeglyph
-%D take some final actions}
-%D \stoptyping
-
-\newcount\unicodeposition
-
-%D The multistep approach is needed to pick up the second
-%D token, since this token can have any value and any
-%D catcode.
-
-% the \relax trick prevents eating up the space (needed for
-% korean
-
-\def\handleunicodeflowglyph#1#2%
- {\begingroup
- \edef\unicodeone{#1}%
- \@EA\afterassignment\@EA\dohandleunicodeflowglyph % two redundant ea's
- \@EA\chardef\@EA\nexttoken\@EA`\string#2\relax}
-
-\def\dohandleunicodeflowglyph\relax
- {\futurelet\nextutoken\dodohandleunicodeflowglyph}
-
-\def\dodohandleunicodeflowglyph % todo tex (or maybe no longer)
- {\edef\unicodetwo{\the\nexttoken}%
- \unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
- \handleunicodeglyph
- \endgroup}
-
-\unexpanded\def\uchar#1#2% use as standalone glyph
- {\begingroup
- \edef\unicodeone{#1}%
- \edef\unicodetwo{#2}%
- \unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
- \handleunicodeglyph
- \endgroup}
-
-\let\nextutoken\relax
-
-\unexpanded\def\lookaheaduchar#1#2%
- {\def\dolookaheaduchar{\uchar{#1}{#2}\let\nextutoken\relax}%
- \futurelet\nextutoken\dolookaheaduchar}
-
-%D In \XETEX, unicode support is straightforward, so we
-%D simply output a \type {\char} with a 16||bit number.
-%D
-%D \starttyping
-%D \def\uchar#1#2{\char\numexpr(#2+(#1*256))\relax}
-%D \stoptyping
-
-\beginXETEX \uchar
-
- \unexpanded\def\uchar#1#2{\char\numexpr#2+#1*\@cclvi\relax}
-
-\endXETEX
-
-\def\dohandleucflowglyph
- {\unicodeposition\numexpr\unicodeone*256+\unicodetwo\relax
- \handleunicodeglyph
- \endgroup}
-
-\unexpanded\def\uc#1#2% used in tricky situations
- {\begingroup
- \edef\unicodeone{#1}%
- \edef\unicodetwo{#2}%
- \futurelet\nextutoken\dohandleucflowglyph}
-
-\def\insertunicodeglyph
- {\unicodeglyph\unicodeone\unicodetwo}
-
-\let\handleunicodeglyph\insertunicodeglyph
-
-%D One can use the \type {\unicodeposition} in the macros
-%D that handle pre and post material.
-
-%D \macros
-%D {unicodestyle, unicodecharcommand}
-%D
-%D Each character pair will become one glyph. Because \TEX\
-%D cannot handle fonts with more that 256 characters, we use
-%D \TFM\ files for each range. The first character of the pair
-%D is appended to the name of a font, and the second is used to
-%D access the glyph in that font. This means that a particular
-%D font is split up in subfonts with names in the range:
-%D
-%D \starttyping
-%D 80 ... ff
-%D \stoptyping
-%D
-%D The \type {} as well as the composed name are
-%D mapped ones. The next macros take care of this mapping.
-%D Let us assume that the next mapping has taken place,
-%D
-%D \starttyping
-%D \definefontsynonym [UnicodeRegular] [gbsong]
-%D \stoptyping
-%D
-%D Let us also assume that we are dealing with the range \type
-%D {b1}. Given that a font name results from:
-%D
-%D \starttyping
-%D \truefontname{\truefontname{UnicodeRegular}b1}
-%D \stoptyping
-%D
-%D we get \type {gbsongb1}. The outer \type {\truefontname}
-%D takes care of additional mapping, so when we say:
-%D
-%D \starttyping
-%D \definefontsynonym [gbsongb1] [gbsong-b1]
-%D \stoptyping
-%D
-%D the filename used will be \type {gbsong-b1}. From the next
-%D definition it will be clear that other fontshapes are also
-%D supported. The prefix \type {Unicode} is mapped!
-%D
-%D The command \type {\unicodecharcommand} can be used to
-%D handle special cases. At that moment \type {1em} is known.
-
-\def\unicodestyle
- {\truefontname\s!Unicode\fontstylesuffix}
-
-\let\unicodecharcommand\firstofoneargument
-
-\unexpanded\def\unicodeglyph#1#2% watch the double mapping
- {\begingroup
- \getvalue{@@\currentucharmapping\strippedcsname\uchar}{#1}{#2}% map to a to hex font range
- \bodyfontsize\unicodescale\bodyfontsize
- % readable:
- % \doifelsefontsynonym{\unicodestyle\unicodeone}
- % {\font\unicodefont=\truefontname{\unicodestyle\unicodeone}
- % at \currentfontscale\bodyfontsize}
- % {\font\unicodefont=\truefontname{\truefontname\unicodestyle\unicodeone}
- % at \currentfontscale\bodyfontsize}%
- % unreadable but more efficient:
- \font\unicodefont=\truefontname{\doifelsefontsynonym{\unicodestyle
- \unicodeone}\empty\truefontname\unicodestyle\unicodeone}
- at \currentfontscale\bodyfontsize
- \unicodestrut % off by default
- \unicodefont\unicodecharcommand{\char\unicodetwo\relax}%
- \endgroup}
-
-%D This handler is used by default, for instance in:
-%D
-%D \starttyping
-%D \defineunicodefont [MySwitch] [MyFont] % [strut=no,command=\insertunicodeglyph]
-%D
-%D \definefontsynonym [MyFontRegular40] [Sans]
-%D \definefontsynonym [MyFontBold40] [SansBold]
-%D
-%D {\MySwitch \uchar{"40}{`a}}
-%D {\MySwitch \bf \uchar{"40}{`a}}
-%D \stoptyping
-%D
-%D \starttyping
-%D \definefontsynonym [MyFontRegular] [Sans]
-%D \definefontsynonym [MyFontBold] [SansBold]
-%D \stoptyping
-%D
-%D Is also possible, but in that case the number is appended to the raw font
-%D name!
-
-%D \macros
-%D {currentucharmapping,defineucharmapping}
-%D
-%D A (plane,char) pair can be remapped using a uchar mapping
-%D function. The default mapping is to convert the plane to a
-%D lowercase hexadecimal number, and leave the number
-%D untouched. The current remapping is kept in a macro.
-
-\let\currentucharmapping\s!default
-
-\def\defineucharmapping#1%
- {\setvalue{@@#1\strippedcsname\uchar}}
-
-\defineucharmapping{\s!default}#1#2%
- {\edef\unicodeone{\lchexnumbers{#1}}\edef\unicodetwo{#2}}
-
-%D An example of a remapping is the following:
-%D
-%D \starttyping
-%D \defineucharmapping{GBK}#1#2%
-%D {\unicodeposition=#1
-%D \advance\unicodeposition -129
-%D \multiply\unicodeposition 190
-%D \advance\unicodeposition #2
-%D \advance\unicodeposition-\ifnum#2>127 65\else64\fi
-%D \dorepositionunicode}
-%D \stoptyping
-%D
-%D This maps the GBK vector onto a compact GBK one. The
-%D auxiliary macro is defined here as a goody.
-
-\def\dorepositionunicode
- {\dosetdivision\unicodeposition{256}\scratchcounter
- \advance\scratchcounter \plusone
- \edef\unicodeone{\ifnum\scratchcounter<10 0\fi\the\scratchcounter}%
- \dosetmodulo\unicodeposition{256}\scratchcounter
- \edef\unicodetwo{\the\scratchcounter}}
-
-%D \macros
-%D {setunicodestrut, setunicodescale, nextutoken,
-%D handleunicodeglyph, insertunicodeglyph}
-%D
-%D A careful analysis of the previous macros, learns that the
-%D process of mapping comes down to:
-%D
-%D \startitemize[packed,n]
-%D \item taking care of preceding material (and spacing)
-%D \item defining the font at \type {\currentfontscale} $\times$
-%D \type {\unicodescale} $\times$ \type {\bodyfontsize}
-%D \item inserting a \type {\unicodestrut}
-%D \item inserting the character (glyph)
-%D \item executing some actions afterwards
-%D \stopitemize
-%D
-%D The actions before and after placing the glyph, is up to
-%D the user supplied handler. This handler (\type
-%D {\handleunicodeglpyh}) must, at a certain moment, insert
-%D the glyph using \type {\insertunicodeglyph}
-
-\def\setunicodescale#1%
- {\def\unicodescale{#1}}
-
-\def\dosetunicodestrut#1#2% height depth
- {\def\unicodestrut
- {\vrule
- \!!width \zeropoint
- \!!height#1\strutht
- \!!depth #2\strutdp
- \relax}}
-
-\def\setunicodestrut#1#2% height depth
- {\ifdim#1\strutht>\zeropoint
- \dosetunicodestrut{#1}{#2}%
- \else\ifdim#1\strutdp>\zeropoint
- \dosetunicodestrut{#1}{#2}%
- \else
- \let\unicodestrut\empty
- \fi\fi}
-
-\def\resetunicodestrut
- {\let\unicodestrut\empty}
-
-%D The additional scaling and strut default to:
-
-\setunicodescale{1}
-\setunicodestrut{1}{1}
-
-%D But better is not to have a strut added by default:
-
-\resetunicodestrut
-
-%D The actual code for the additional actions as well as
-%D specific spacing is handled outside these routines. The
-%D character after the two that are under treatment is
-%D available in \type {\nextutoken}.
-
-%D \macros
-%D {defineunicodefont, setupunicodefont}
-%D
-%D Apart from this rather low level implementation, we also
-%D provide a more user friendly alternative. Given that one
-%D has defined:
-%D
-%D \starttyping
-%D \defineunicodefont
-%D [SimChi] [SimplifiedChinese]
-%D [\c!scale=0.85,
-%D \c!height=1.25,
-%D \c!depth=1.00,
-%D \c!interlinespaceinterlinie=yes,
-%D \c!conversion=\chinesenumber,
-%D \c!command=\handlechineseunicodeglyph]
-%D \stoptyping
-%D
-%D Together with:
-%D
-%D \starttyping
-%D \definefontsynonym [SimplifiedChineseRegular] [gbsong]
-%D \definefontsynonym [SimplifiedChineseSlanted] [gbsongsl]
-%D \stoptyping
-%D
-%D we can now switch to Simplified Chinese by saying \type
-%D {SimChi}. Some values can be changed afterwards with
-%D
-%D \starttyping
-%D \setupunicodefont[SimChi][...=...]
-%D \stoptyping
-%D
-%D Specific initializations can be assigned to \type
-%D {commands}.
-
-\def\defineunicodefont
- {\dotripleempty\dodefineunicodefont}
-
-\def\dodefineunicodefont[#1][#2][#3]%
- {\doifassignmentelse{#3}
- {\setupunicodefont[#1][#3]}
- {\doifelsenothing{#3}
- {\setupunicodefont[#1][#3]}
- {\copyparameters
- [\??uc#1][\??uc#3]
- [\c!height,\c!depth,\c!scale,\c!commands,\c!strut,
- \c!interlinespace,\c!command,\c!conversion]}}%
- \doifelsenothing{#2}
- {\setvalue{#1}{[uc font #1 undefined]}}
- {\setvalue{\??uc#1\c!file}{#2}%
- \doifundefined{\??ff#2\s!Bold}
- {\definefontsynonym[#2\s!Bold] [#2\s!Regular]%
- \definefontsynonym[#2\s!Slanted] [#2\s!Regular]%
- \definefontsynonym[#2\s!Italic] [#2\s!Regular]%
- \definefontsynonym[#2\s!BoldSlanted][#2\s!Slanted]%
- \definefontsynonym[#2\s!BoldItalic] [#2\s!Italic]}%
- \unexpanded\setvalue{#1}{\enableunicodefont{#1}}}}
-
-\def\setupunicodefont
- {\dodoubleempty\dosetupunicodefont}
-
-\def\dosetupunicodefont[#1][#2]% also predefines
- {\doifundefined{\??uc#1\c!command}
- {\copyparameters
- [\??uc#1][\??uc\s!default]
- [\c!height,\c!depth,\c!scale,\c!commands,\v!strut,
- \c!interlinespace,\c!command,\c!conversion]}%
- \getparameters[\??uc#1][#2]}
-
-\def\enableunicodefont#1%
- {\definefontsynonym[\s!Unicode][\getvalue{\??uc#1\c!file}]%
- \def\unicodescale {\getvalue{\??uc#1\c!scale}}%
- \def\unicodeheight {\getvalue{\??uc#1\c!height}}%
- \def\unicodedepth {\getvalue{\??uc#1\c!depth}}%
- \def\unicodedigits {\getvalue{\??uc#1\c!conversion}}%
- \def\handleunicodeglyph {\getvalue{\??uc#1\c!command}}%
- \doifnot\currentregime{utf}{\enableregime[unicode]}%
- % the following \relax's are realy needed
- \doifvalue{\??uc#1\c!interlinespace}\v!yes
- \setupinterlinespace\relax
- \doifelsevalue{\??uc#1\c!strut}\v!yes
- {\setunicodestrut\unicodeheight\unicodedepth}
- {\resetunicodestrut}%
- \getvalue{\??uc#1\c!commands}\relax}
-
-%D \macros
-%D {unicodedigits}
-%D
-%D For convenience we also predefine a number conversion
-%D macro:
-
-\let\unicodedigits\number
-
-%D Because we cannot be sure of the pressence of all font
-%D styles, we remap some by default.
-
-\definefontsynonym [\s!Unicode\s!Bold] [\s!Unicode\s!Regular]
-\definefontsynonym [\s!Unicode\s!Slanted] [\s!Unicode\s!Regular]
-\definefontsynonym [\s!Unicode\s!Italic] [\s!Unicode\s!Regular]
-\definefontsynonym [\s!Unicode\s!BoldSlanted] [\s!Unicode\s!Slanted]
-\definefontsynonym [\s!Unicode\s!BoldItalic] [\s!Unicode\s!Italic]
-
-\setupunicodefont
- [\s!default]
- [\c!height=1,
- \c!depth=1,
- \c!scale=1,
- \c!strut=\v!no,
- \c!interlinespace=\v!no,
- \c!command=\insertunicodeglyph,
- \c!conversion=\number]
-
-\protect \endinput
diff --git a/tex/context/base/font-unk.mkii b/tex/context/base/font-unk.mkii
new file mode 100644
index 000000000..30f824781
--- /dev/null
+++ b/tex/context/base/font-unk.mkii
@@ -0,0 +1,187 @@
+%D \module
+%D [ file=font-unk,
+%D version=1998.09.10,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=Unknown Defaults,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This module is rather important, because it enables us to
+%D define and call for not yet defined fonts in a way
+%D completely independant of real font names. First we map
+%D some meaningful names onto unknown filenames.
+
+\unprotect
+
+\definefontsynonym [Serif] [unknown]
+\definefontsynonym [SerifBold] [unknown]
+\definefontsynonym [SerifItalic] [unknown]
+\definefontsynonym [SerifSlanted] [unknown]
+\definefontsynonym [SerifBoldItalic] [unknown]
+\definefontsynonym [SerifBoldSlanted] [unknown]
+\definefontsynonym [SerifCaps] [unknown]
+
+\definefontsynonym [Sans] [unknown]
+\definefontsynonym [SansBold] [unknown]
+\definefontsynonym [SansItalic] [unknown]
+\definefontsynonym [SansSlanted] [unknown]
+\definefontsynonym [SansBoldItalic] [unknown]
+\definefontsynonym [SansBoldSlanted] [unknown]
+\definefontsynonym [SansCaps] [unknown]
+
+\definefontsynonym [Mono] [unknown]
+\definefontsynonym [MonoBold] [unknown]
+\definefontsynonym [MonoItalic] [unknown]
+\definefontsynonym [MonoSlanted] [unknown]
+\definefontsynonym [MonoBoldItalic] [unknown]
+\definefontsynonym [MonoBoldSlanted] [unknown]
+\definefontsynonym [MonoCaps] [unknown]
+
+\definefontsynonym [MathRoman] [unknown]
+\definefontsynonym [MathExtension] [unknown]
+\definefontsynonym [MathItalic] [unknown]
+\definefontsynonym [MathSymbol] [unknown]
+
+\definefontsynonym [MathNoName] [unknown]
+
+\definefontsynonym [MathAlpha] [unknown]
+\definefontsynonym [MathBeta] [unknown]
+\definefontsynonym [MathGamma] [unknown]
+\definefontsynonym [MathDelta] [unknown]
+
+\definefontsynonym [MathRomanBold] [MathRoman]
+\definefontsynonym [MathExtensionBold] [MathExtension]
+\definefontsynonym [MathItalicBold] [MathItalic]
+\definefontsynonym [MathSymbolBold] [MathSymbol]
+\definefontsynonym [MathAlphaBold] [MathAlpha]
+\definefontsynonym [MathBetaBold] [MathBeta]
+\definefontsynonym [MathGammaBold] [MathGamma]
+\definefontsynonym [MathDeltaBold] [MathDelta]
+
+\definefontsynonym [Handwriting] [unknown]
+\definefontsynonym [Calligraphic] [unknown]
+
+%D This permit us to define (use) fonts that refer to the default
+%D style (so, Bold may expand to SansBold or SerifBold, depending
+%D on the default style in the typeface).
+
+% \def\setfontsynonym[#1]#2[#3]{\setvalue{\??ff\fontclass#1}{#3}}
+%
+% \setfontsynonym[\s!Normal] [\fontstringD]
+% \setfontsynonym[\s!Bold] [\fontstringD\s!Bold]
+% \setfontsynonym[\s!Italic] [\fontstringD\s!Italic]
+% \setfontsynonym[\s!Slanted] [\fontstringD\s!Slanted]
+% \setfontsynonym[\s!BoldItalic] [\fontstringD\s!BoldItalic]
+% \setfontsynonym[\s!BoldSlanted][\fontstringD\s!BoldSlanted]
+% \setfontsynonym[\s!Caps] [\fontstringD\s!Caps]
+
+\definefontsynonym[\s!Normal] [\noexpand\fontstringD]
+\definefontsynonym[\s!Bold] [\noexpand\fontstringD\noexpand\s!Bold]
+\definefontsynonym[\s!Italic] [\noexpand\fontstringD\noexpand\s!Italic]
+\definefontsynonym[\s!Slanted] [\noexpand\fontstringD\noexpand\s!Slanted]
+\definefontsynonym[\s!BoldItalic] [\noexpand\fontstringD\noexpand\s!BoldItalic]
+\definefontsynonym[\s!BoldSlanted][\noexpand\fontstringD\noexpand\s!BoldSlanted]
+\definefontsynonym[\s!Caps] [\noexpand\fontstringD\noexpand\s!Caps]
+
+%D Also handy:
+
+\definefontsynonym [Regular] [Serif]
+\definefontsynonym [RegularBold] [SerifBold]
+\definefontsynonym [RegularItalic] [SerifItalic]
+\definefontsynonym [RegularSlanted] [SerifSlanted]
+\definefontsynonym [RegularBoldItalic] [SerifBoldItalic]
+\definefontsynonym [RegularBoldSlanted] [SerifBoldSlanted]
+\definefontsynonym [RegularCaps] [SerifCaps]
+
+\definefontsynonym [Support] [Sans]
+\definefontsynonym [SupportBold] [SansBold]
+\definefontsynonym [SupportItalic] [SansItalic]
+\definefontsynonym [SupportSlanted] [SansSlanted]
+\definefontsynonym [SupportBoldItalic] [SansBoldItalic]
+\definefontsynonym [SupportBoldSlanted] [SansBoldSlanted]
+\definefontsynonym [SupportCaps] [SansCaps]
+
+%D Well, not that good an idea:
+
+\definefontsynonym [Roman] [Serif]
+\definefontsynonym [RomanBold] [SerifBold]
+\definefontsynonym [RomanItalic] [SerifItalic]
+\definefontsynonym [RomanSlanted] [SerifSlanted]
+\definefontsynonym [RomanBoldItalic] [SerifBoldItalic]
+\definefontsynonym [RomanBoldSlanted] [SerifBoldSlanted]
+\definefontsynonym [RomanCaps] [SerifCaps]
+
+\definefontsynonym [Type] [Mono]
+\definefontsynonym [TypeBold] [MonoBold]
+\definefontsynonym [TypeItalic] [MonoItalic]
+\definefontsynonym [TypeSlanted] [MonoSlanted]
+\definefontsynonym [TypeBoldItalic] [MonoBoldItalic]
+\definefontsynonym [TypeBoldSlanted] [MonoBoldSlanted]
+\definefontsynonym [TypeCaps] [MonoCaps]
+
+%D Next we define roman, sans and monospaced font sets.
+
+\definebodyfont [default] [rm]
+ [tf=Serif sa 1,
+ bf=SerifBold sa 1,
+ it=SerifItalic sa 1,
+ sl=SerifSlanted sa 1,
+ bi=SerifBoldItalic sa 1,
+ bs=SerifBoldSlanted sa 1,
+ sc=SerifCaps sa 1]
+
+\definebodyfont [default] [ss]
+ [tf=Sans sa 1,
+ bf=SansBold sa 1,
+ it=SansItalic sa 1,
+ sl=SansSlanted sa 1,
+ bi=SansBoldItalic sa 1,
+ bs=SansBoldSlanted sa 1,
+ sc=SansCaps sa 1]
+
+\definebodyfont [default] [tt]
+ [tf=Mono sa 1,
+ bf=MonoBold sa 1,
+ it=MonoItalic sa 1,
+ sl=MonoSlanted sa 1,
+ bi=MonoBoldItalic sa 1,
+ bs=MonoBoldSlanted sa 1,
+ sc=MonoCaps sa 1]
+
+\definebodyfont [default] [mm]
+ [mr=MathRoman mo 1,
+ ex=MathExtension mo 1,
+ mi=MathItalic mo 1,
+ sy=MathSymbol mo 1,
+ nn=MathNoName mo 1,
+ ma=MathAlpha mo 1,
+ mb=MathBeta mo 1,
+ mc=MathGamma mo 1,
+ md=MathDelta mo 1]
+
+\definebodyfont [bfmath] [mm]
+ [mrbf=MathRomanBold mo 1,
+ exbf=MathExtensionBold mo 1,
+ mibf=MathItalicBold mo 1,
+ sybf=MathSymbolBold mo 1,
+ mabf=MathAlphaBold mo 1,
+ mbbf=MathBetaBold mo 1,
+ mcbf=MathGammaBold mo 1,
+ mdbf=MathDeltaBold mo 1]
+
+\definebodyfont [default] [hw]
+ [tf=Handwriting sa 1]
+
+\definebodyfont [default] [cg]
+ [tf=Calligraphy sa 1]
+
+%D These definitions come into action as soon as names are
+%D mapped onto real file names (or names that themselves are
+%D mapped).
+
+\protect \endinput
diff --git a/tex/context/base/font-unk.mkiv b/tex/context/base/font-unk.mkiv
new file mode 100644
index 000000000..bd699ef71
--- /dev/null
+++ b/tex/context/base/font-unk.mkiv
@@ -0,0 +1,162 @@
+%D \module
+%D [ file=font-unk,
+%D version=1998.09.10,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=Unknown Defaults,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This module is rather important, because it enables us to
+%D define and call for not yet defined fonts in a way
+%D completely independant of real font names. First we map
+%D some meaningful names onto unknown filenames.
+
+\unprotect
+
+\definefontsynonym [Serif] [unknown]
+\definefontsynonym [SerifBold] [unknown]
+\definefontsynonym [SerifItalic] [unknown]
+\definefontsynonym [SerifSlanted] [unknown]
+\definefontsynonym [SerifBoldItalic] [unknown]
+\definefontsynonym [SerifBoldSlanted] [unknown]
+\definefontsynonym [SerifCaps] [unknown]
+
+\definefontsynonym [Sans] [unknown]
+\definefontsynonym [SansBold] [unknown]
+\definefontsynonym [SansItalic] [unknown]
+\definefontsynonym [SansSlanted] [unknown]
+\definefontsynonym [SansBoldItalic] [unknown]
+\definefontsynonym [SansBoldSlanted] [unknown]
+\definefontsynonym [SansCaps] [unknown]
+
+\definefontsynonym [Mono] [unknown]
+\definefontsynonym [MonoBold] [unknown]
+\definefontsynonym [MonoItalic] [unknown]
+\definefontsynonym [MonoSlanted] [unknown]
+\definefontsynonym [MonoBoldItalic] [unknown]
+\definefontsynonym [MonoBoldSlanted] [unknown]
+\definefontsynonym [MonoCaps] [unknown]
+
+\definefontsynonym [MathRoman] [unknown]
+\definefontsynonym [MathExtension] [unknown]
+\definefontsynonym [MathItalic] [unknown]
+\definefontsynonym [MathSymbol] [unknown]
+
+\definefontsynonym [MathNoName] [unknown]
+
+\definefontsynonym [MathAlpha] [unknown]
+\definefontsynonym [MathBeta] [unknown]
+\definefontsynonym [MathGamma] [unknown]
+\definefontsynonym [MathDelta] [unknown]
+
+\definefontsynonym [MathRomanBold] [MathRoman] % todo:
+\definefontsynonym [MathExtensionBold] [MathExtension] % [MathRoman]
+\definefontsynonym [MathItalicBold] [MathItalic] % [MathRoman]
+\definefontsynonym [MathSymbolBold] [MathSymbol] % [MathRoman]
+\definefontsynonym [MathAlphaBold] [MathAlpha] % [MathRoman]
+\definefontsynonym [MathBetaBold] [MathBeta] % [MathRoman]
+\definefontsynonym [MathGammaBold] [MathGamma] % [MathRoman]
+\definefontsynonym [MathDeltaBold] [MathDelta] % [MathRoman]
+
+\definefontsynonym [Handwriting] [unknown]
+\definefontsynonym [Calligraphic] [unknown]
+
+%D This permit us to define (use) fonts that refer to the default
+%D style (so, Bold may expand to SansBold or SerifBold, depending
+%D on the default style in the typeface).
+
+\definefontsynonym[\s!Normal] [\noexpand\fontstringD]
+\definefontsynonym[\s!Bold] [\noexpand\fontstringD\noexpand\s!Bold]
+\definefontsynonym[\s!Italic] [\noexpand\fontstringD\noexpand\s!Italic]
+\definefontsynonym[\s!Slanted] [\noexpand\fontstringD\noexpand\s!Slanted]
+\definefontsynonym[\s!BoldItalic] [\noexpand\fontstringD\noexpand\s!BoldItalic]
+\definefontsynonym[\s!BoldSlanted][\noexpand\fontstringD\noexpand\s!BoldSlanted]
+\definefontsynonym[\s!Caps] [\noexpand\fontstringD\noexpand\s!Caps]
+
+%D Also handy:
+
+\definefontsynonym [Regular] [Serif]
+\definefontsynonym [RegularBold] [SerifBold]
+\definefontsynonym [RegularItalic] [SerifItalic]
+\definefontsynonym [RegularSlanted] [SerifSlanted]
+\definefontsynonym [RegularBoldItalic] [SerifBoldItalic]
+\definefontsynonym [RegularBoldSlanted] [SerifBoldSlanted]
+\definefontsynonym [RegularCaps] [SerifCaps]
+
+\definefontsynonym [Support] [Sans]
+\definefontsynonym [SupportBold] [SansBold]
+\definefontsynonym [SupportItalic] [SansItalic]
+\definefontsynonym [SupportSlanted] [SansSlanted]
+\definefontsynonym [SupportBoldItalic] [SansBoldItalic]
+\definefontsynonym [SupportBoldSlanted] [SansBoldSlanted]
+\definefontsynonym [SupportCaps] [SansCaps]
+
+%D Well, not that good an idea:
+
+\definefontsynonym [Roman] [Serif]
+\definefontsynonym [RomanBold] [SerifBold]
+\definefontsynonym [RomanItalic] [SerifItalic]
+\definefontsynonym [RomanSlanted] [SerifSlanted]
+\definefontsynonym [RomanBoldItalic] [SerifBoldItalic]
+\definefontsynonym [RomanBoldSlanted] [SerifBoldSlanted]
+\definefontsynonym [RomanCaps] [SerifCaps]
+
+\definefontsynonym [Type] [Mono]
+\definefontsynonym [TypeBold] [MonoBold]
+\definefontsynonym [TypeItalic] [MonoItalic]
+\definefontsynonym [TypeSlanted] [MonoSlanted]
+\definefontsynonym [TypeBoldItalic] [MonoBoldItalic]
+\definefontsynonym [TypeBoldSlanted] [MonoBoldSlanted]
+\definefontsynonym [TypeCaps] [MonoCaps]
+
+%D Next we define roman, sans and monospaced font sets.
+
+\definebodyfont [default] [rm]
+ [tf=Serif sa 1,
+ bf=SerifBold sa 1,
+ it=SerifItalic sa 1,
+ sl=SerifSlanted sa 1,
+ bi=SerifBoldItalic sa 1,
+ bs=SerifBoldSlanted sa 1,
+ sc=SerifCaps sa 1]
+
+\definebodyfont [default] [ss]
+ [tf=Sans sa 1,
+ bf=SansBold sa 1,
+ it=SansItalic sa 1,
+ sl=SansSlanted sa 1,
+ bi=SansBoldItalic sa 1,
+ bs=SansBoldSlanted sa 1,
+ sc=SansCaps sa 1]
+
+\definebodyfont [default] [tt]
+ [tf=Mono sa 1,
+ bf=MonoBold sa 1,
+ it=MonoItalic sa 1,
+ sl=MonoSlanted sa 1,
+ bi=MonoBoldItalic sa 1,
+ bs=MonoBoldSlanted sa 1,
+ sc=MonoCaps sa 1]
+
+\definebodyfont [default] [mm]
+ [mr=MathRoman mo 1]
+
+\definebodyfont [bfmath] [mm]
+ [mr=MathRomanBold mo 1]
+
+\definebodyfont [default] [hw]
+ [tf=Handwriting sa 1]
+
+\definebodyfont [default] [cg]
+ [tf=Calligraphy sa 1]
+
+%D These definitions come into action as soon as names are
+%D mapped onto real file names (or names that themselves are
+%D mapped).
+
+\protect \endinput
diff --git a/tex/context/base/font-unk.tex b/tex/context/base/font-unk.tex
deleted file mode 100644
index 4e450ae74..000000000
--- a/tex/context/base/font-unk.tex
+++ /dev/null
@@ -1,185 +0,0 @@
-%D \module
-%D [ file=font-unk,
-%D version=1998.09.10,
-%D title=\CONTEXT\ Font Macros,
-%D subtitle=Unknown Defaults,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This module is rather important, because it enables us to
-%D define and call for not yet defined fonts in a way
-%D completely independant of real font names. First we map
-%D some meaningful names onto unknown filenames.
-
-\definefontsynonym [Serif] [unknown]
-\definefontsynonym [SerifBold] [unknown]
-\definefontsynonym [SerifItalic] [unknown]
-\definefontsynonym [SerifSlanted] [unknown]
-\definefontsynonym [SerifBoldItalic] [unknown]
-\definefontsynonym [SerifBoldSlanted] [unknown]
-\definefontsynonym [SerifCaps] [unknown]
-
-\definefontsynonym [Sans] [unknown]
-\definefontsynonym [SansBold] [unknown]
-\definefontsynonym [SansItalic] [unknown]
-\definefontsynonym [SansSlanted] [unknown]
-\definefontsynonym [SansBoldItalic] [unknown]
-\definefontsynonym [SansBoldSlanted] [unknown]
-\definefontsynonym [SansCaps] [unknown]
-
-\definefontsynonym [Mono] [unknown]
-\definefontsynonym [MonoBold] [unknown]
-\definefontsynonym [MonoItalic] [unknown]
-\definefontsynonym [MonoSlanted] [unknown]
-\definefontsynonym [MonoBoldItalic] [unknown]
-\definefontsynonym [MonoBoldSlanted] [unknown]
-\definefontsynonym [MonoCaps] [unknown]
-
-\definefontsynonym [MathRoman] [unknown]
-\definefontsynonym [MathExtension] [unknown]
-\definefontsynonym [MathItalic] [unknown]
-\definefontsynonym [MathSymbol] [unknown]
-
-\definefontsynonym [MathNoName] [unknown]
-
-\definefontsynonym [MathAlpha] [unknown]
-\definefontsynonym [MathBeta] [unknown]
-\definefontsynonym [MathGamma] [unknown]
-\definefontsynonym [MathDelta] [unknown]
-
-\definefontsynonym [MathRomanBold] [MathRoman]
-\definefontsynonym [MathExtensionBold] [MathExtension]
-\definefontsynonym [MathItalicBold] [MathItalic]
-\definefontsynonym [MathSymbolBold] [MathSymbol]
-\definefontsynonym [MathAlphaBold] [MathAlpha]
-\definefontsynonym [MathBetaBold] [MathBeta]
-\definefontsynonym [MathGammaBold] [MathGamma]
-\definefontsynonym [MathDeltaBold] [MathDelta]
-
-\definefontsynonym [Handwriting] [unknown]
-\definefontsynonym [Calligraphic] [unknown]
-
-%D This permit us to define (use) fonts that refer to the default
-%D style (so, Bold may expand to SansBold or SerifBold, depending
-%D on the default style in the typeface).
-
-% \def\setfontsynonym[#1]#2[#3]{\setvalue{\??ff\fontclass#1}{#3}}
-%
-% \setfontsynonym[\s!Normal] [\fontstringD]
-% \setfontsynonym[\s!Bold] [\fontstringD\s!Bold]
-% \setfontsynonym[\s!Italic] [\fontstringD\s!Italic]
-% \setfontsynonym[\s!Slanted] [\fontstringD\s!Slanted]
-% \setfontsynonym[\s!BoldItalic] [\fontstringD\s!BoldItalic]
-% \setfontsynonym[\s!BoldSlanted][\fontstringD\s!BoldSlanted]
-% \setfontsynonym[\s!Caps] [\fontstringD\s!Caps]
-
-\definefontsynonym[\s!Normal] [\noexpand\fontstringD]
-\definefontsynonym[\s!Bold] [\noexpand\fontstringD\noexpand\s!Bold]
-\definefontsynonym[\s!Italic] [\noexpand\fontstringD\noexpand\s!Italic]
-\definefontsynonym[\s!Slanted] [\noexpand\fontstringD\noexpand\s!Slanted]
-\definefontsynonym[\s!BoldItalic] [\noexpand\fontstringD\noexpand\s!BoldItalic]
-\definefontsynonym[\s!BoldSlanted][\noexpand\fontstringD\noexpand\s!BoldSlanted]
-\definefontsynonym[\s!Caps] [\noexpand\fontstringD\noexpand\s!Caps]
-
-%D Also handy:
-
-\definefontsynonym [Regular] [Serif]
-\definefontsynonym [RegularBold] [SerifBold]
-\definefontsynonym [RegularItalic] [SerifItalic]
-\definefontsynonym [RegularSlanted] [SerifSlanted]
-\definefontsynonym [RegularBoldItalic] [SerifBoldItalic]
-\definefontsynonym [RegularBoldSlanted] [SerifBoldSlanted]
-\definefontsynonym [RegularCaps] [SerifCaps]
-
-\definefontsynonym [Support] [Sans]
-\definefontsynonym [SupportBold] [SansBold]
-\definefontsynonym [SupportItalic] [SansItalic]
-\definefontsynonym [SupportSlanted] [SansSlanted]
-\definefontsynonym [SupportBoldItalic] [SansBoldItalic]
-\definefontsynonym [SupportBoldSlanted] [SansBoldSlanted]
-\definefontsynonym [SupportCaps] [SansCaps]
-
-%D Well, not that good an idea:
-
-\definefontsynonym [Roman] [Serif]
-\definefontsynonym [RomanBold] [SerifBold]
-\definefontsynonym [RomanItalic] [SerifItalic]
-\definefontsynonym [RomanSlanted] [SerifSlanted]
-\definefontsynonym [RomanBoldItalic] [SerifBoldItalic]
-\definefontsynonym [RomanBoldSlanted] [SerifBoldSlanted]
-\definefontsynonym [RomanCaps] [SerifCaps]
-
-\definefontsynonym [Type] [Mono]
-\definefontsynonym [TypeBold] [MonoBold]
-\definefontsynonym [TypeItalic] [MonoItalic]
-\definefontsynonym [TypeSlanted] [MonoSlanted]
-\definefontsynonym [TypeBoldItalic] [MonoBoldItalic]
-\definefontsynonym [TypeBoldSlanted] [MonoBoldSlanted]
-\definefontsynonym [TypeCaps] [MonoCaps]
-
-%D Next we define roman, sans and monospaced font sets.
-
-\definebodyfont [default] [rm]
- [tf=Serif sa 1,
- bf=SerifBold sa 1,
- it=SerifItalic sa 1,
- sl=SerifSlanted sa 1,
- bi=SerifBoldItalic sa 1,
- bs=SerifBoldSlanted sa 1,
- sc=SerifCaps sa 1]
-
-\definebodyfont [default] [ss]
- [tf=Sans sa 1,
- bf=SansBold sa 1,
- it=SansItalic sa 1,
- sl=SansSlanted sa 1,
- bi=SansBoldItalic sa 1,
- bs=SansBoldSlanted sa 1,
- sc=SansCaps sa 1]
-
-\definebodyfont [default] [tt]
- [tf=Mono sa 1,
- bf=MonoBold sa 1,
- it=MonoItalic sa 1,
- sl=MonoSlanted sa 1,
- bi=MonoBoldItalic sa 1,
- bs=MonoBoldSlanted sa 1,
- sc=MonoCaps sa 1]
-
-\definebodyfont [default] [mm]
- [mr=MathRoman mo 1,
- ex=MathExtension mo 1,
- mi=MathItalic mo 1,
- sy=MathSymbol mo 1,
- nn=MathNoName mo 1,
- ma=MathAlpha mo 1,
- mb=MathBeta mo 1,
- mc=MathGamma mo 1,
- md=MathDelta mo 1]
-
-\definebodyfont [bfmath] [mm]
- [mrbf=MathRomanBold mo 1,
- exbf=MathExtensionBold mo 1,
- mibf=MathItalicBold mo 1,
- sybf=MathSymbolBold mo 1,
- mabf=MathAlphaBold mo 1,
- mbbf=MathBetaBold mo 1,
- mcbf=MathGammaBold mo 1,
- mdbf=MathDeltaBold mo 1]
-
-\definebodyfont [default] [hw]
- [tf=Handwriting sa 1]
-
-\definebodyfont [default] [cg]
- [tf=Calligraphy sa 1]
-
-%D These definitions come into action as soon as names are
-%D mapped onto real file names (or names that themselves are
-%D mapped).
-
-\endinput
diff --git a/tex/context/base/font-vf.lua b/tex/context/base/font-vf.lua
index 37e4eeb6e..c103555a3 100644
--- a/tex/context/base/font-vf.lua
+++ b/tex/context/base/font-vf.lua
@@ -64,7 +64,7 @@ end
function vf.aux.combine.process(g,list)
if list then
- for _,v in pairs(list) do
+ for _,v in next, list do
(vf.aux.combine.commands[v[1]] or nop)(g,v)
end
end
@@ -81,7 +81,7 @@ function vf.aux.combine.names(g,name,force)
local fd, gd = f.descriptions, g.descriptions
g.fonts[#g.fonts+1] = { id = id } -- no need to be sparse
local hn = #g.fonts
- for k, v in pairs(fc) do
+ for k, v in next, fc do
if force or not gc[k] then
gc[k] = table.fastcopy(v)
gc[k].commands = { { 'slot', hn, k } }
@@ -113,7 +113,8 @@ vf.aux.combine.commands = {
function vf.combine(specification,tag)
local g = {
name = specification.name,
- type = 'virtual',
+ -- type = 'virtual',
+ virtualized = true,
fonts = { },
characters = { },
descriptions = { },
@@ -180,12 +181,11 @@ fonts.define.methods.install(
fonts.define.methods["demo-1"] = function(specification)
local name = specification.name -- symbolic name
local size = specification.size -- given size
---~ specification.name = 'lmroman10-regular' -- forced base name
---~ specification.features.vtf = { }
local f, id = tfm.read_and_define('lmroman10-regular',size)
if f and id then
local capscale, digscale = 0.85, 0.75
- f.name, f.type = name, 'virtual'
+ -- f.name, f.type = name, 'virtual'
+ f.name, f.virtualized = name, true
f.fonts = {
{ id = id },
{ name = 'lmsans10-regular' , size = size*capscale }, -- forced extra name
@@ -193,65 +193,21 @@ fonts.define.methods["demo-1"] = function(specification)
}
local i_is_of_category = characters.i_is_of_category
local characters, descriptions = f.characters, f.descriptions
- for u,v in pairs(characters) do
+ local red = {'special','pdf: 1 0 0 rg'}
+ local green = {'special','pdf: 0 1 0 rg'}
+ local blue = {'special','pdf: 0 0 1 rg'}
+ local black = {'special','pdf: 0 g'}
+ for u,v in next, characters do
if u and i_is_of_category(u,'lu') then
v.width = capscale*v.width
- v.commands = {
- {'special','pdf: 1 0 0 rg'},
- {'slot',2, u},
- {'special','pdf: 0 g'},
- }
+ v.commands = { red, {'slot',2,u}, black }
elseif u and i_is_of_category(u,'nd') then
v.width = digscale*v.width
- v.commands = {
- {'special','pdf: 0 0 1 rg'},
- {'slot',3,u},
- {'special','pdf: 0 g'},
- }
+ v.commands = { blue, {'slot',3,u}, black }
else
- v.commands = {
- {'special','pdf: 0 1 0 rg'},
- {'slot',1,u},
- {'special','pdf: 0 g'},
- }
+ v.commands = { green, {'slot',1,u}, black }
end
end
end
return f
end
-
--- keep as example, now tfm feature
-
---~ vf.aux.combine.commands["lineheight"] = function(g,v)
---~ if g.ascender and g.descender then
---~ local ht, dp = g.ascender or 0, g.descender or 0
---~ if v[2] == "none" then
---~ for _,v in pairs(g.characters) do
---~ v.height = 0
---~ v.depth = 0
---~ end
---~ else
---~ if v[2] == "height" then
---~ dp = 0
---~ elseif v[2] == "depth" then
---~ ht = 0
---~ end
---~ if ht > 0 then
---~ if dp > 0 then
---~ for _,v in pairs(g.characters) do
---~ v.height = ht
---~ v.depth = dp
---~ end
---~ else
---~ for _,v in pairs(g.characters) do
---~ v.height = ht
---~ end
---~ end
---~ elseif dp > 0 then
---~ for _,v in pairs(g.characters) do
---~ v.depth = dp
---~ end
---~ end
---~ end
---~ end
---~ end
diff --git a/tex/context/base/font-xtx.lua b/tex/context/base/font-xtx.lua
new file mode 100644
index 000000000..63e421fa4
--- /dev/null
+++ b/tex/context/base/font-xtx.lua
@@ -0,0 +1,115 @@
+if not modules then modules = { } end modules ['font-xtx'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local texsprint, count = tex.sprint, tex.count
+local format, concat, gmatch, match, find, lower = string.format, table.concat, string.gmatch, string.match, string.find, string.lower
+local tostring, next = tostring, next
+
+local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end)
+
+--[[ldx--
+
Choosing a font by name and specififying its size is only part of the
+game. In order to prevent complex commands, introduced
+a method to pass feature information as part of the font name. At the
+risk of introducing nasty parsing and compatinility problems, this
+syntax was expanded over time.
+
+
For the sake of users who have defined fonts using that syntax, we
+will support it, but we will provide additional methods as well.
+Normally users will not use this direct way, but use a more abstract
+interface.
+
+
The next one is the official one. However, in the plain
+variant we need to support the crappy [] specification as
+well and that does not work too well with the general design
+of the specifier.
+--ldx]]--
+
+--~ function fonts.define.specify.colonized(specification) -- xetex mode
+--~ local list = { }
+--~ if specification.detail and specification.detail ~= "" then
+--~ for v in gmatch(specification.detail,"%s*([^;]+)%s*") do
+--~ local a, b = match(v,"^(%S*)%s*=%s*(%S*)$")
+--~ if a and b then
+--~ list[a] = b:is_boolean()
+--~ if type(list[a]) == "nil" then
+--~ list[a] = b
+--~ end
+--~ else
+--~ local a, b = match(v,"^([%+%-]?)%s*(%S+)$")
+--~ if a and b then
+--~ list[b] = a ~= "-"
+--~ end
+--~ end
+--~ end
+--~ end
+--~ specification.features.normal = list
+--~ return specification
+--~ end
+
+--~ check("oeps/BI:+a;-b;c=d")
+--~ check("[oeps]/BI:+a;-b;c=d")
+--~ check("file:oeps/BI:+a;-b;c=d")
+--~ check("name:oeps/BI:+a;-b;c=d")
+
+local list = { }
+
+fonts.define.specify.colonized_default_lookup = "file"
+
+local function issome () list.lookup = fonts.define.specify.colonized_default_lookup end
+local function isfile () list.lookup = 'file' end
+local function isname () list.lookup = 'name' end
+local function thename(s) list.name = s end
+local function issub (v) list.sub = v end
+local function iscrap (s) list.crap = string.lower(s) end
+local function istrue (s) list[s] = 'yes' end
+local function isfalse(s) list[s] = 'no' end
+local function iskey (k,v) list[k] = v end
+
+local spaces = lpeg.P(" ")^0
+local namespec = (1-lpeg.S("/: ("))^0
+local crapspec = spaces * lpeg.P("/") * (((1-lpeg.P(":"))^0)/iscrap) * spaces
+local filename = (lpeg.P("file:")/isfile * (namespec/thename)) + (lpeg.P("[") * lpeg.P(true)/isname * (((1-lpeg.P("]"))^0)/thename) * lpeg.P("]"))
+local fontname = (lpeg.P("name:")/isname * (namespec/thename)) + lpeg.P(true)/issome * (namespec/thename)
+local sometext = (lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09"))^1
+local truevalue = lpeg.P("+") * spaces * (sometext/istrue)
+local falsevalue = lpeg.P("-") * spaces * (sometext/isfalse)
+local keyvalue = (lpeg.C(sometext) * spaces * lpeg.P("=") * spaces * lpeg.C(sometext))/iskey
+local somevalue = sometext/istrue
+local subvalue = lpeg.P("(") * (lpeg.C(lpeg.P(1-lpeg.S("()"))^1)/issub) * lpeg.P(")") -- for Kim
+local option = spaces * (keyvalue + falsevalue + truevalue + somevalue) * spaces
+local options = lpeg.P(":") * spaces * (lpeg.P(";")^0 * option)^0
+local pattern = (filename + fontname) * subvalue^0 * crapspec^0 * options^0
+
+function fonts.define.specify.colonized(specification) -- xetex mode
+ list = { }
+ pattern:match(specification.specification)
+ for k, v in next, list do
+ list[k] = v:is_boolean()
+ if type(list[a]) == "nil" then
+ list[k] = v
+ end
+ end
+ list.crap = nil -- style not supported, maybe some day
+ if list.name then
+ specification.name = list.name
+ list.name = nil
+ end
+ if list.lookup then
+ specification.lookup = list.lookup
+ list.lookup = nil
+ end
+ if list.sub then
+ specification.sub = list.sub
+ list.sub = nil
+ end
+ specification.features.normal = list
+ return specification
+end
+
+fonts.define.register_split(":", fonts.define.specify.colonized)
diff --git a/tex/context/base/font-xtx.tex b/tex/context/base/font-xtx.tex
new file mode 100644
index 000000000..5f4b85879
--- /dev/null
+++ b/tex/context/base/font-xtx.tex
@@ -0,0 +1,357 @@
+%D \module
+%D [ file=font-xtx,
+%D version=2004.09.11,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=\XETEX\ Hacks,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\ifnum\texengine=\xetexengine
+ \writestatus{loading}{ConTeXt Font Macros / XeTeX Hacks}
+\else
+ \endinput
+\fi
+
+\unprotect
+
+%D Loading:
+
+%D for some reason xetex does not support [filename] for tfm files and
+%D quotes also behave kind of strange " vs ' vs [ vs ...
+%D
+%D \starttyping
+%D \font\myfont = msam7 % ok
+%D \font\myfont = "msam7" % also ok
+%D \font\myfont = "msam7" at 8pt % error
+%D \stoptyping
+
+\newconditional\tracexetexfonts
+
+%D Because \XETEX\ is not that fast on locating fonts we cache lookups so
+%D that we minimize the test. It saves a little bit of runtime, depending
+%D on the number of fonts loaded (which is normally not that much).
+
+\def\doiffoundXTXfontelse#1#2%
+ {\ifcsname xtx@fnt@#2\somefontspec\endcsname
+ \ifconditional\tracexetexfonts
+ \writestatus\m!fonts{already checked #1: #2\somefontspec\space (state: \number\csname xtx@fnt@#2\somefontspec\endcsname)}%
+ \fi
+ \else
+ \suppressfontnotfounderror\plusone
+ \font\xetextempfont=#2\somefontspec\relax
+ \suppressfontnotfounderror\zerocount
+ \edef\xetextempfont{\fontname\xetextempfont}%
+ \global\expandafter\chardef\csname xtx@fnt@#2\somefontspec\endcsname
+ \ifx\xetextempfont\nullfontname
+ \zerocount \ifconditional\tracexetexfonts
+ \writestatus\m!fonts{not found #1: #2\somefontspec}%
+ \fi
+ \else
+ \plusone \ifconditional\tracexetexfonts
+ \writestatus\m!fonts{found #1: #2\somefontspec}%
+ \fi
+ \fi
+ \fi
+ \ifcase\csname xtx@fnt@#2\somefontspec\endcsname
+ \expandafter\secondoftwoarguments
+ \else
+ \expandafter\firstoftwoarguments
+ \fi}
+
+\def\docheckfontfilenameprefix#1:#2:#3#4\relax
+ {\edef\!!stringa{#1}%
+ \edef\!!stringb{#2}%
+ \ifx\!!stringb\empty
+ % no prefix
+ \let\checkedfontfile\!!stringa
+ \doiffoundXTXfontelse{1a}{\checkedfontfile\checkedfontfeatures}
+ {\edef\checkedfontfile{\checkedfontfile\checkedfontfeatures}}
+ {\doiffoundXTXfontelse{1b}{"\checkedfontfile\checkedfontfeatures"}
+ {\edef\checkedfontfile{"\checkedfontfile\checkedfontfeatures"}}
+ {\doiffoundXTXfontelse{1c}{"[\checkedfontfile]\checkedfontfeatures"}
+ {\edef\checkedfontfile{"[\checkedfontfile]\checkedfontfeatures"}}
+ {}}}%
+ \else\ifx\!!stringa\v!file
+ % force file, only file check when no spaces
+ \let\checkedfontfile\!!stringb
+ \doiffoundXTXfontelse{2a}{"[\checkedfontfile]\checkedfontfeatures"}
+ {\edef\checkedfontfile{"[\checkedfontfile]\checkedfontfeatures"}}
+ {\doiffoundXTXfontelse{2b}{"\checkedfontfile\checkedfontfeatures"}
+ {\edef\checkedfontfile{"\checkedfontfile\checkedfontfeatures"}}
+ {}}%
+ \else\ifx\!!stringa\v!name
+ % force name, always lookup by xetex itself, "" forces otf/ttf/type1
+ \edef\checkedfontfile{"\!!stringb\checkedfontfeatures"}%
+ \ifconditional\tracexetexfonts
+ \writestatus\m!fonts{no checking 3a: \checkedfontfile}%
+ \fi
+ \else
+ % whatever, maybe even xetex spec, forget about features
+ \edef\checkedfontfile{"\!!stringa\!!stringb"}%
+ \ifconditional\tracexetexfonts
+ \writestatus\m!fonts{no checking 3b: \checkedfontfile}%
+ \fi
+ \fi\fi\fi}
+
+\def\checkfontfilename% -- todo: integrate so that we call do.. directly
+ {\expandafter\docheckfontfilename\fontfile*\empty*\relax}
+
+\def\docheckfontfilename#1*#2#3*#4\relax % class overrules file
+ {\edef\checkedfontfeatures
+ {\expandafter\ifx\csname\fontclass\s!features\endcsname\empty
+ \ifx\@@fontfeatures\empty\ifx#2\empty\else#2#3\fi\else\@@fontfeatures\fi
+ \else\expandafter\ifx\csname\fontclass\s!features\endcsname\relax % redundant, will go away
+ \ifx\@@fontfeatures\empty\ifx#2\empty\else#2#3\fi\else\@@fontfeatures\fi
+ \else
+ \csname\fontclass\s!features\endcsname
+ \fi\fi}%
+ \ifx\checkedfontfeatures\empty
+ % done
+ \else
+ \edef\checkedfontfeatures{\executeifdefined{\??fa\checkedfontfeatures}\empty}%
+ \ifx\checkedfontfeatures\empty
+ % done
+ \else
+ \let\convertedfontfeatures\empty
+ \processcommacommand[\checkedfontfeatures]\doconvertfontfeatures % raw
+ \ifx\convertedfontfeatures\empty
+ \let\checkedfontfeatures\empty
+ \else
+ \edef\checkedfontfeatures{:\convertedfontfeatures}%
+ \fi
+ \fi
+ \fi
+ \docheckfontfilenameprefix#1:\empty:\empty\relax
+ \doshowcheckedfontfeatures}
+
+\def\dodoconvertfontfeatures#1=#2#3=#4\relax
+ {\ifx#2\empty
+ % invalid feature
+ \else\ifcsname @xtx@#1@#2#3\endcsname
+ \expandafter\ifx\csname @xtx@#1@#2#3\endcsname\empty\else
+ \edef\convertedfontfeatures{\convertedfontfeatures\csname @xtx@#1@#2#3\endcsname;}%
+ \fi
+ \else
+ \edef\!!stringa{#1}%
+ \edef\!!stringb{#2#3}%
+ \edef\convertedfontfeatures
+ {\convertedfontfeatures
+ \ifx\!!stringb\v!yes
+ +\!!stringa
+ \else\ifx\!!stringb\v!no
+ -\!!stringa
+ \else
+ \!!stringa=\!!stringb
+ \fi\fi;}%
+ \fi\fi}
+
+\def\doconvertfontfeatures#1%
+ {\dodoconvertfontfeatures#1=\empty=\relax}
+
+\def\remapfontfeature #1 #2 #3 {\setevalue{@xtx@#1@#2}{#3}}
+
+% this may move to another file, maybe font-xtx
+
+\remapfontfeature tlig yes mapping=tlig
+%remapfontfeature tlig no mapping=
+\remapfontfeature trep yes {}
+\remapfontfeature trep no {}
+\remapfontfeature texligatures yes mapping=tlig
+%remapfontfeature texligatures no mapping=
+%remapfontfeature texquotes yes mapping=tex-text
+%remapfontfeature texquotes no mapping=
+
+%D Variants:
+
+\unexpanded\def\variant[#1]%
+ {\dosetscaledfont
+ \font\variantfont\truefontname{\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1}} at \scaledfont
+ \variantfont}
+
+%D Possible optimizations:
+
+% \def\updatefontparameters
+% {\edef\@@fontfeatures{\truefontdata\fontfile\s!features}%
+% \edef\@@fontskewchar{\truefontdata\fontfile\s!skewchar}}
+
+% \def\setfontcharacteristics
+% {\updatefontparameters % redundant, will go away, faster too
+% \the\everyfont}
+
+% \let\synchronizepatternswithfont\relax
+
+%D Names:
+
+% We need to move the feature into the filename else it may be
+% overloaded by another reference. For instance the definition of
+% a regular and caps variant can use the same font.
+
+% We could use an indirect method ... store in 'array' and refer to
+% slot.
+
+\def\definefontsynonym[#1]#2[#3]%
+ {\edef\@@fontname{#1}%
+ \edef\@@fontfile{#3}%
+ \doifnextoptionalelse\dodefinefontsynonym\nodefinefontsynonym}
+
+\def\nodefinefontsynonym
+ {\@EA\let\csname\??ff\fontclass\@@fontname\endcsname\@@fontfile}
+
+\def\dodefinefontsynonym[#1]%
+ {\edef\@@fontdata{#1}%
+ \ifx\@@fontdata\empty
+ \nodefinefontsynonym
+ \else
+ \ifx\fontclass\empty
+ \getfontparameters
+ \else
+ \getglobalfontparameters
+ \fi
+ \ifcsname\??ff\@@fontfile\s!features\endcsname
+ \@EA\edef\csname\??ff\fontclass\@@fontname\endcsname{\@@fontfile*\csname\??ff\@@fontfile\s!features\endcsname}%
+ \@EA\let\csname\??ff\@@fontfile\s!features\endcsname\undefined
+ \else
+ \nodefinefontsynonym
+ \fi
+ \fi}
+
+\let\definefontfile\definefontsynonym % dedicated to Taco Hoekwater
+
+% simple version
+%
+% \def\truefontname#1%
+% {\@EA\dotruefontname#1*\relax}
+%
+% \def\dotruefontname#1*#2\relax
+% {\ifcsname\??ff\fontclass#1\endcsname
+% \@EA\truefontname\csname\??ff\fontclass#1\endcsname
+% \else\ifcsname\??ff#1\endcsname
+% \@EA\truefontname\csname\??ff#1\endcsname
+% \else
+% #1%
+% \fi\fi}
+%
+% last counts
+%
+% \def\truefontname#1%
+% {\@EA\dotruefontname#1*\empty*\relax}
+%
+% \def\dotruefontname#1*#2#3*#4\relax
+% {\ifcsname\??ff\fontclass#1\endcsname
+% \ifx#2\empty
+% \@EA\truefontname\csname\??ff\fontclass#1\endcsname
+% \else
+% \@EA\truefontname\csname\??ff\fontclass#1\endcsname*#2#3%
+% \fi
+% \else\ifcsname\??ff#1\endcsname
+% \ifx#2\empty
+% \@EA\truefontname\csname\??ff#1\endcsname
+% \else
+% \@EA\truefontname\csname\??ff#1\endcsname*#2#3%
+% \fi
+% \else
+% \ifx#2\empty
+% #1%
+% \else
+% #1*#2#3%
+% \fi
+% \fi\fi}
+%
+% first counts
+
+\def\truefontname#1%
+ {\@EA\dotruefontname#1*\empty*\relax}
+
+\def\dotruefontname#1*#2#3*#4\relax
+ {\ifcsname\??ff\fontclass#1\endcsname
+ \ifx#2\empty
+ \@EA\truefontname\csname\??ff\fontclass#1\endcsname
+ \else
+ \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname*#2#3%
+ \fi
+ \else\ifcsname\??ff#1\endcsname
+ \ifx#2\empty
+ \@EA\truefontname\csname\??ff#1\endcsname
+ \else
+ \@EA\redotruefontname\csname\??ff#1\endcsname*#2#3%
+ \fi
+ \else
+ #1\ifx#2\empty\else*#2#3\fi
+ \fi\fi}
+
+\def\redotruefontname#1%
+ {\@EA\dodotruefontname#1*\relax}
+
+\def\dodotruefontname#1*#2\relax
+ {\ifcsname\??ff\fontclass#1\endcsname
+ \@EA\redotruefontname\csname\??ff\fontclass#1\endcsname
+ \else\ifcsname\??ff#1\endcsname
+ \@EA\redotruefontname\csname\??ff#1\endcsname
+ \else
+ #1%
+ \fi\fi}
+
+%D Default:
+
+\def\defaultfontfile{file:lmmono10-regular}
+
+%D Maybe:
+
+% \def\updatefontparameters
+% {\edef\@@fontfeatures{\truefontdata\fontfile \s!features}%
+% \edef\@@fontskewchar{\truefontdata\fontfile \s!skewchar}}
+
+% \def\setfontcharacteristics
+% {%\updatefontparameters % redundant, will go away, faster too
+% \the\everyfont
+% \synchronizepatternswithfont}
+
+\protect \endinput
+
+% \starttypescript[serif] [myzhfont]
+% \definefontsynonym [Serif] [file:SimSun]
+% \definefontsynonym [SerifBold] [file:SimSun]
+% \definefontsynonym [SerifItalic] [file:SimSun]
+% \definefontsynonym [SerifBoldItalic] [file:SimSun]
+% \stoptypescript
+% \starttypescript[sans] [myzhfont]
+% \definefontsynonym [Sans] [file:SimSun]
+% \definefontsynonym [SansBold] [file:SimSun]
+% \definefontsynonym [SansItalic] [file:SimSun]
+% \definefontsynonym [SansBoldItalic] [file:SimSun]
+% \stoptypescript
+% \starttypescript[mono] [myzhfont]
+% \definefontsynonym [Mono] [file:SimSun]
+% \definefontsynonym [MonoBold] [file:SimSun]
+% \definefontsynonym [MonoItalic] [file:SimSun]
+% \definefontsynonym [MonoBoldItalic] [file:SimSun]
+% \stoptypescript
+% \definetypeface [myzhfont] [rm] [serif][myzhfont] [default]
+% \definetypeface [myzhfont] [ss] [sans] [myzhfont] [default]
+% \definetypeface [myzhfont] [tt] [mono] [myzhfont] [default]
+
+% \starttext
+% % on windows: make sure fonts.conf has no cache mentioned
+% %
+% % 64 sec xetex, 11 sec luatex (56 sec xetex when \nobigmath)
+% %
+% \setupbodyfont[myzhfont] \dorecurse{10000}{{hello {\switchtobodyfont[myzhfont] 你好}}\par}
+% %
+% % 67 sec xetex, 11.5 sec luatex
+% %
+% % \dorecurse{10000}{{hello {\switchtobodyfont[myzhfont] 你好}}\par}
+% %
+% % 5 sec xetex, 7 sec luatex
+% %
+% % \setupbodyfont[myzhfont] \dorecurse{10000}{{hello {你好}}\par}
+% %
+% % 5 sec xetex, 7 sec luatex
+% %
+% % \setupbodyfont[myzhfont] \dorecurse{10000}{{\bf hello {你好}}\par}
+% \stoptext
+
diff --git a/tex/context/base/hand-ini.mkii b/tex/context/base/hand-ini.mkii
index 59c98fa06..42d248df6 100644
--- a/tex/context/base/hand-ini.mkii
+++ b/tex/context/base/hand-ini.mkii
@@ -16,61 +16,21 @@
\unprotect
-\startmessages dutch library: handlings
- title: handling
- 1: font afhandeling --
- 2: font afhandeling -- wordt geladen
- 3: onbekende font afhandeling --
-\stopmessages
-
-\startmessages english library: handlings
- title: handling
- 1: font handling --
- 2: font handling -- is loaded
- 3: unknown font handling --
-\stopmessages
-
-\startmessages german library: handlings % to do
- title: handling
- 1: Font Verarbeitung --
- 2: Font Verarbeitung -- ist geladen
- 3: unknown font handling --
-\stopmessages
-
-\startmessages czech library: handlings % to do
- title: handling
- 1: font handling --
- 2: font handling -- is loaded
- 3: unknown font handling --
-\stopmessages
-
-\startmessages italian library: handlings % to do
- title: handling
- 1: font handling --
- 2: font handling -- is loaded
- 3: unknown font handling --
-\stopmessages
-
-\startmessages norwegian library: handlings % to do
- title: handling
- 1: font handling --
- 2: font handling -- is loaded
- 3: unknown font handling --
-\stopmessages
-
-\startmessages romanian library: handlings % to do
- title: handling
- 1: font handling --
- 2: font handling -- is loaded
- 3: unknown font handling --
-\stopmessages
-
-\startmessages french library: handlings
- title: manipulation
- 1: manipulation -- de police
- 2: la manipulation -- de police est chargée
- 3: manipulation -- inconnue de police
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
\newif\iftracefonthandling % \tracefonthandlingtrue
@@ -81,8 +41,6 @@
% much in common with hz/protruding defs
% todo: fix others
-\let\normalchar\char % also done in enco-ini
-
\def\dosetsomehandling#1#2#3 #4 % no define since directly set
{\ifskiphandlingdef \else
\doifnumberelse{\string#2}
@@ -105,17 +63,6 @@
\let\char\normalchar}}%
\fi}
-% \def\dosettriplethandling#1#2#3 #4 #5 #6 % no define since directly set
-% {\ifskiphandlingdef \else
-% \doifnumberelse{\string#2}
-% {#1{#2#3}{#4}{#5}{#6}}
-% {\doifelsenothing{#3}
-% {#1{`#2}{#4}{#5}{#6}}
-% {\let\char\empty
-% \doifnumberelse{\csname#2#3\endcsname}{#1{\csname#2#3\endcsname}{#4}{#5}{#6}}\donothing
-% \let\char\normalchar}}%
-% \fi}
-
\def\dosetquartethandling#1#2#3 #4 #5 #6 #7 % no define since directly set
{\ifskiphandlingdef \else
\doifnumberelse{\string#2}
@@ -127,14 +74,6 @@
\let\char\normalchar}}%
\fi}
-
-% \def\doinhsomehandling#1#2 #3 %
-% {\ifskiphandlingdef \else
-% \let\char\empty
-% \doifnumberelse{\csname#2\endcsname}{#1{\csname#2\endcsname}{`#3}}\donothing
-% \let\char\normalchar
-% \fi}
-
\def\doinhsomehandling#1#2#3 #4 % to be checked
{\ifskiphandlingdef \else
\if#3\relax\relax
diff --git a/tex/context/base/hand-ini.mkiv b/tex/context/base/hand-ini.mkiv
index 527c32da7..41e9db415 100644
--- a/tex/context/base/hand-ini.mkiv
+++ b/tex/context/base/hand-ini.mkiv
@@ -36,7 +36,7 @@
\appendtoks \disableadjusting \to \everyforgetall % Here or not here?
\appendtoks \disableprotruding \to \everyforgetall % Here or not here?
-\def\startfonthandling #1{\fonthandlingerror\gobbleuntil\stopfonthandling} % can't happen
+\def\startfonthandling #1{\fonthandlingerror\fonthandlingerror\gobbleuntil\stopfonthandling} % can't happen
\def\definefonthandling {\dotripleempty\dodefinefonthandling}
\def\setupfonthandling {\dodoubleempty\dosetupfonthandling }
\def\dodefinefonthandling[#1][#2][#3]{\fonthandlingerror}
diff --git a/tex/context/base/hand-ini.tex b/tex/context/base/hand-ini.tex
deleted file mode 100644
index 4d19b5284..000000000
--- a/tex/context/base/hand-ini.tex
+++ /dev/null
@@ -1,18 +0,0 @@
-%D \module
-%D [ file=hand-ini, % moved from enco-ini / pro
-%D version=2000.12.27, % 1998.12.03,
-%D title=\CONTEXT\ Handling Macros,
-%D subtitle=Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Handling Macros (ini)}
-
-\loadmarkfile{hand-ini}
-
-\endinput
diff --git a/tex/context/base/java-ini.mkii b/tex/context/base/java-ini.mkii
new file mode 100644
index 000000000..e929da108
--- /dev/null
+++ b/tex/context/base/java-ini.mkii
@@ -0,0 +1,713 @@
+%D \module
+%D [ file=java-ini,
+%D version=1998.01.30,
+%D title=\CONTEXT\ JavaScript Macros,
+%D subtitle=Initialization,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt JavaScript Macros / Initialization}
+
+% BUG: preamble zonder used/used en split
+
+% todo: lua sanitizer
+
+% JavaScript support is under development. In the near future
+% a slightly different model will be used. The JScode stuff
+% will probably become just auto function inclusion and the
+% JS_* things will disappear. First I have to find a way to
+% deal with global variables so the 'uses' thing will remain.
+
+% ook p{ref}
+% documentation should be corrected to JS(
+
+% Also, obeylines will be supported.
+
+\unprotect
+
+%D \JAVA\ support is not implemented as a generic support
+%D module. The main reason for this is that passing system
+%D variables to a \JAVASCRIPT\ is closely related to other core
+%D macros. First some messages:
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+
+%D \TEX\ is not the right tool to check the \JAVA\ code; the
+%D most we can do is reporting some passed variables:
+
+\newif\iftraceJScode \traceJScodefalse
+
+\let\traceJScode\traceJScodetrue
+
+%D A bit out of place, but not dangerous:
+
+\bgroup
+\catcode127=\@@letter
+\gdef\delcharacter{^^7f}
+\egroup
+
+%D The number of passed variables is minimalized by setting the
+%D next switch.
+
+\newif\ifminimalizeJScode \minimalizeJScodetrue
+
+%D \macros
+%D {JS*}
+%D
+%D Because \JAVASCRIPT's are activated by the user, for
+%D instance by activating on a button, their support is closely
+%D related to the referencing mechanism. Integration takes
+%D place by
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum()]
+%D \stoptyping
+%D
+%D The \type{()} classify this as a script. If they are absent,
+%D the keyword is treated as a normal reference.
+%D
+%D One can pass arguments to such a script by saying:
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum(1.5,2.3)]
+%D \stoptyping
+%D
+%D References are passed by using the \type{R{}} classifier.
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum(1.5,2.3,R{overflow})]
+%D \stoptyping
+%D
+%D The last call calls the script \type{Sum} and passes the
+%D next set of variables:
+%D
+%D \starttyping
+%D JS_S_1="1.5";
+%D JS_S_2="2.3";
+%D JS_R_3="overflow";
+%D JS_P_3=3;
+%D \stoptyping
+%D
+%D The first two parameters are just strings, the third one
+%D however is treated as a reference and results in passing the
+%D reference (if needed this references is prefixed) and the
+%D (real) page number. The alternative:
+%D
+%D \starttyping
+%D \goto{calculate total}[JS(Sum{V{1.5},V{2.3},R{overflow}})]
+%D \stoptyping
+%D
+%D does a verbose passing:
+%D
+%D \starttyping
+%D JS_V_1=1.5;
+%D JS_V_2=2.3;
+%D JS_R_3="overflow";
+%D JS_P_3=3;
+%D \stoptyping
+% %D
+% %D Finally we have a counter that tells\JAVA\ how many
+% %D arguments were passed,
+% %D
+% %D \starttyping
+% %D JS_N
+% %D \stoptyping
+
+%D We will also support direct function calls. In that case
+%D no intermediate variables are used.
+
+%D \macros
+%D {startJScode}
+%D
+%D A piece of \JAVASCRIPT\ code is defined by saying:
+%D
+%D \starttyping
+%D \startJScode{SomeScript}
+%D var Item=this.getField("item");
+%D N=Item.getArray();
+%D Total=this.getField("total");
+%D Total.value=0;
+%D for (j=0; j0) && (JS_R_1!=""))
+%D { gotoNamedDest(JS_R_1) };
+%D \stopJScode
+%D \stoptyping
+%D
+%D Such a piece of code is closely related to the interpreter
+%D used. Watch the last two lines, here the script adapts
+%D itself to the presence of a reference.
+%D
+%D While
+%D
+%D \starttyping
+%D \startJScode{name}
+%D name = 4 ;
+%D \stopJScode
+%D \stoptyping
+%D
+%D assumes uses no preamble or presumes that the preamble is
+%D always loaded, the next definition also tells \CONTEXT\ to
+%D actually include the preamble needed.
+%D
+%D \starttyping
+%D \startJScode{uses} uses {later}
+%D uses = 6 ;
+%D \stopJScode
+%D \stoptyping
+
+\long\def\startJScode#1 #2
+ {\doifelse{#2}{uses}
+ {\dostartJScodeA{#1}}
+ {\dostartJScodeB{#1} #2 }}
+
+\long\def\dostartJScodeA#1#2 #3\stopJScode
+ {\long\setgvalue{\r!java#1}{\do{#2}{#3}}}
+
+\long\def\dostartJScodeB#1#2\stopJScode
+ {\long\setgvalue{\r!java#1}{\do{}{#2}}}
+
+\let\stopJScode\relax
+
+%D \macros
+%D {presetJScode}
+%D
+%D The code can be retrieved by saying
+%D
+%D \starttyping
+%D \presetJScode{SomeScript}{template}
+%D \stoptyping
+%D
+%D Such a template is a comma separated list, where
+%D individual entries can optionally be transformed by
+%D \type{R{}} and \type{V{}}.
+%D
+%D After this call, the code is available in \type{\JScode}.
+
+\newif\ifdirectJScode
+
+\def\presetJScode#1#2% #1=operation #2=arguments
+ {\setverbosecscharacters
+ \def\par{\delcharacter}% was: { }
+ \scratchcounter\zerocount
+ \globallet\JScode\empty
+ \def\do##1##2%
+ {\doifelse{##2}{!}\directJScodetrue\directJScodefalse}%
+ \getvalue{\r!java#1}%
+ \edef\!!stringa{#2}%
+ \ifx\!!stringa\empty \else
+ \processcommacommand[\!!stringa]\dopresetJSvariables
+ \fi
+ \def\docommand##1%
+ {\doifundefinedelse{\r!java\r!java##1}
+ {\showmessage\m!javascript2{##1}}
+ {\useJSpreamblenow{##1}}}%
+% {\doglobal\increment\currentJSpreamble
+% \doglobal\addtocommalist{##1}\allJSpreambles}}%
+ \def\do##1##2%
+ {\xdef\JScode{\ifdirectJScode#1(\JScode)\else\JScode##2\fi}%
+ %\xdef\JScode{JS\string_N=\the\scratchcounter;\JScode}%
+ \processcommalist[##1]\docommand}%
+ \getvalue{\r!java#1}}
+
+\def\dopresetJSvariables#1%
+ {\advance\scratchcounter \plusone
+ \donefalse
+ \dodopresetJSvariables#1\end}%
+
+\def\dodopresetJSvariables
+ {\doifnextcharelse R\dodopresetJSrefvariables
+ {\doifnextcharelse V\dodopresetJSvervariables
+ {\doifnextcharelse S\dodopresetJSstrvariables
+ \dodopresetJSrawvariables}}}
+
+\def\dodopresetJSrefvariables R#1\end
+ {\doifreferencefoundelse{#1}
+ {\donetrue \dododopresetJSvariables R{\referenceprefix#1}%
+ \donefalse\dododopresetJSvariables P{\currentrealreference}}
+ {\unknownreference{#1}}%
+ \ifminimalizeJScode \else
+ \donetrue\dododopresetJSvariables S{#1}%
+ \fi}
+
+\def\dodopresetJSvervariables V#1\end
+ {\donefalse\dododopresetJSvariables V{#1}%
+ \ifminimalizeJScode \else
+ \donetrue\dododopresetJSvariables S{#1}%
+ \fi}
+
+\def\dodopresetJSstrvariables S#1\end
+ {\donetrue\dododopresetJSvariables S{#1}}
+
+\def\dodopresetJSrawvariables #1\end
+ {\donetrue\dododopresetJSvariables S{#1}}
+
+\def\JSprefix#1%
+ {JS\string_#1\string_\the\scratchcounter}
+
+\def\dododopresetJSvariables#1#2%
+ {\iftraceJScode
+ \writestatus{JavaScript}{\JSprefix#1=#2}
+ \xdef\JScode{\JScode console.println("\JSprefix#1=#2"); }%
+ \fi
+ \ifdirectJScode
+ \xdef\JScode{\ifx\JScode\empty\else\JScode,\fi\ifdone"#2"\else#2\fi}%
+ \else
+ \xdef\JScode{\JScode\JSprefix#1=\ifdone"#2"\else#2\fi; }%
+ \fi}
+
+%D \macros
+%D {startJSpreamble, flushJSpreamble}
+%D
+%D One can define insert \JAVASCRIPT\ code at the document level
+%D by using:
+%D
+%D \starttyping
+%D \startJSpreamble{oeps}
+%D oeps = 1 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D which is the same as:
+%D
+%D \starttyping
+%D \startJSpreamble{now} used now
+%D now = 2 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D while the next definition is only included when actually
+%D used.
+%D
+%D \starttyping
+%D \startJSpreamble{later} used later
+%D later = 3 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D This command may be used more that once, but always before
+%D the first page is shipped out.
+
+\newif\ifoneJSpreamble \oneJSpreamblefalse
+
+\let\allJSpreambles\empty
+\newcounter\nofJSpreambles
+\newcounter\currentJSpreamble
+
+\long\def\startJSpreamble#1 #2 %
+ {\bgroup % we need to restore the catcodes
+ \restoreendofline % just in case it happens while reading lists
+ \doifelse{#2}{used}
+ {\dostartJSpreamble#1 }
+ {\dostartJSpreamble#1 now #2 }}
+
+\long\def\dostartJSpreamble#1 #2 %
+ {\processaction
+ [#2]
+ [ later=>\chardef\JSstatus\zerocount,%
+ now=>\chardef\JSstatus\plusone ,%
+ \s!default=>\chardef\JSstatus\plustwo ,%
+ \s!unknown=>\chardef\JSstatus\plustwo ]%
+ \ifaddJSlinebreaks
+ \obeylines \let\obeyedline \normalpar
+ \obeyspaces \let\obeyedspace\normalspace
+ \fi
+ \dodostartJSpreamble{#1}}
+
+\long\def\dodostartJSpreamble#1#2\stopJSpreamble
+ {\presetJSfunctions #2function ()\end
+ \long\setgvalue{\r!java\r!java#1}{#2}%
+ \ifcase\JSstatus \else
+ \useJSpreamblenow{#1}%
+ \fi
+ \egroup}
+
+%D \macros
+%D {setJSpreamble, addtoJSpreamble}
+%D
+%D In addition to the previous preamble definitions, we can
+%D set a preamble \quote {in||line} and add tokens to a
+%D preamble.
+
+\def\setJSpreamble#1#2%
+ {\doifundefined{\r!java\r!java#1}
+ {\setgvalue{\r!java\r!java#1}{#2;}%
+ \doglobal\increment\currentJSpreamble
+ \doglobal\addtocommalist{#1}\allJSpreambles}}
+
+\def\addtoJSpreamble#1#2%
+ {\doifdefinedelse{\r!java\r!java#1}
+ {\edef\!!stringa{\r!java\r!java#1}%
+ \edef\!!stringb{\csname\!!stringa\endcsname}%
+ \@EA\setgvalue\@EA\!!stringa\@EA{\!!stringb #2;}}
+ {\setJSpreamble{#1}{#2}}}
+
+%D \macros
+%D {useJSpreamblenow}
+%D
+%D The next macro can be used to force inclusion of postponed
+%D \JAVASCRIPT\ preambles.
+
+\def\useJSpreamblenow#1%
+ {\doglobal\increment\currentJSpreamble
+ \doglobal\addtocommalist{#1}\allJSpreambles}
+
+%D Because we want to check for valid calls, we preload the
+%D functions. This means that we can call them directly as
+%D well as indirectly when defined by \type {\startJScode} etc.
+
+% \long\def\presetJSfunctions#1function #2(#3)%
+% {\doifelsenothing{#2}
+% {\long\def\presetJSfunctions##1\end{}}
+% {\stripspaces\from#2\to\ascii
+% \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
+% \presetJSfunctions}
+
+\long\def\presetJSfunctions#1function#2(#3)%
+ {\doifelse{#2}\space
+ {\long\def\presetJSfunctions##1\end{}}
+ {\stripspaces\from#2\to\ascii
+ \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
+ \presetJSfunctions}
+
+\def\getJSpreamble#1%
+ {\getvalue{\r!java\r!java#1}}
+
+\def\presetJSpreamble
+ {\ifx\allJSpreambles\empty\else
+ \bgroup
+ \setverbosecscharacters
+ \obeyspaces \let\obeyedspace\normalspace
+ \def\par{\delcharacter}% was: { }
+ \globallet\JSpreamble\empty
+ \def\@@collectedJSpreamble{\r!java\r!java collected}%
+ \letvalue{\@@collectedJSpreamble}=\empty
+ \def\docommand##1%
+ {\xdef\JScode{\getvalue{\r!java\r!java##1}}%
+ \ifoneJSpreamble % \global\letcdcsname
+ \@EA\setxvalue\@EA\@@collectedJSpreamble\@EA
+ {\csname\@@collectedJSpreamble\endcsname\JScode}%
+ \else
+ \setxvalue{\r!java\r!java##1}{\JScode}%
+ \fi}%
+ \processcommacommand[\allJSpreambles]\docommand
+ \ifoneJSpreamble
+ \gdef\allJSpreambles{collected}%
+ \fi
+ \globallet\presetJSpreamble\relax
+ \egroup
+ \fi}
+
+\def\flushJSpreamble
+ {\iflocation\ifx\allJSpreambles\empty\else
+ \ifcase\nofJSpreambles\else\ifnum\nofJSpreambles=\currentJSpreamble
+ \bgroup
+ \presetJSpreamble
+ \expanded{\doflushJSpreamble{\allJSpreambles}}%
+ \globallet\flushJSpreamble\relax
+ \globallet\allJSpreambles\empty
+ \egroup
+ \fi\fi
+ \fi\fi}
+
+\def\finalflushJSpreamble
+ {\iflocation
+ \flushJSpreamble
+ \ifcase\currentJSpreamble\relax\else
+ \savecurrentvalue\nofJSpreambles\currentJSpreamble
+ \globallet\currentJSpreamble\nofJSpreambles
+ \fi
+ \fi}
+
+\prependtoks \flushJSpreamble \to \everyshipout
+\prependtoks \finalflushJSpreamble \to \everylastshipout
+
+%D \macros
+%D {doPSsanitizeJScode}
+%D
+%D Before the code can be passed to the (\POSTSCRIPT\ or \PDF)
+%D output file, some precautions must be made concerning the
+%D use of \type{(} and~\type{)}. Here we use a beautiful
+%D \type{\aftergroup} trick I discovered in the \TABLE\ format.
+
+\def\doPSsanitizeJScode#1\to#2%
+ {\begingroup
+ \scratchcounter\zerocount % \aftergroup counter
+ \aftergroup\xdef
+ \aftergroup#2%
+ \aftergroup{%
+ \expanded{\defconvertedargument\noexpand\JScode{#1}}%
+ \expandafter\handletokens\JScode\with\dodoPSsanitizeJScode
+ \aftergroup}%
+ \endgroup
+ \iftraceJScode
+ \writestatus{JS trace}{#2}%
+ \fi}
+
+%D I started with:
+%D
+%D \starttyping
+%D \def\dodoPSsanitizeJScode#1%
+%D {\aftergroup\string
+%D \if#1(%
+%D \expandafter\aftergroup\csname#1\endcsname
+%D \else\if#1)%
+%D \expandafter\aftergroup\csname#1\endcsname
+%D \else\if#1;%
+%D \aftergroup;\aftergroup\string\expandafter\aftergroup\
+%D \else
+%D \expandafter\aftergroup#1%
+%D \fi\fi\fi
+%D \advance\scratchcounter by 1
+%D \ifnum\scratchcounter=500
+%D \expandafter\dododoPSsanitizeJScode
+%D \fi}
+%D \stoptyping
+%D
+%D For pretty printing purposes, we need some way to signal
+%D \TEX\ macros. Therefore we introduce a special keyword
+%D \type{TEX}. When followed by a space, this keyword is
+%D ignored, that is, filtered from the stream. Now we have:
+
+\chardef\JSisTEX \zerocount
+\chardef\JScomment\zerocount
+
+\newif\ifaddJSlinebreaks \addJSlinebreakstrue
+
+\def\flushJSisTEX
+ {\ifcase\JSisTEX
+ \or \aftergroup T%
+ \or \aftergroup T\aftergroup E%
+ \or \aftergroup T\aftergroup E\aftergroup X%
+ \fi
+ \chardef\JSisTEX\zerocount}
+
+% \def\doJSlinebreak
+% {\ifaddJSlinebreaks
+% \aftergroup\string\aftergroup\n%
+% \fi}
+%
+% \def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
+% {\if#1/%
+% \ifnum\JScomment=0
+% \chardef\JScomment\plusone
+% \else\ifnum\JScomment=1
+% \chardef\JScomment\plustwo
+% \fi\fi
+% \else
+% \ifnum\JScomment=1
+% \aftergroup/%
+% \chardef\JScomment\zerocount
+% \fi
+% \ifnum\JScomment=2
+% \if#1\delcharacter
+% \chardef\JScomment\zerocount
+% \fi
+% \else
+% \if#1\delcharacter
+% \flushJSisTEX\doJSlinebreak
+% \else\if#1(%
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+% \else\if#1)%
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+% \else\if#1;%
+% \flushJSisTEX\aftergroup;\doJSlinebreak
+% \else\if#1T%
+% \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
+% \else\if#1E%
+% \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
+% \else\if#1X%
+% \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
+% \else\if#1\normalspace
+% \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
+% \else
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
+% \fi\fi\fi\fi\fi\fi\fi\fi
+% \fi
+% \fi
+% \dododoPSsanitizeJScode}
+
+% todo: "http:\\" -> simple. maar wel \" afvangen
+%
+% use new pdftex escape mechanism or make fully expandable version, not used that often btw
+
+\chardef\JSstring\zerocount
+
+\def\doJSlinebreak
+ {\chardef\JScomment\zerocount
+ \chardef\JSstring\zerocount
+ \ifaddJSlinebreaks
+ \aftergroup\string\aftergroup\n%
+ \fi}
+
+\def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
+ {\if#1/%
+ \ifnum\JSstring=0
+ \ifnum\JScomment=0
+ \chardef\JScomment\plusone
+ \else\ifnum\JScomment=1
+ \chardef\JScomment\plustwo
+ \fi\fi
+ \else
+ \aftergroup/%
+ \fi
+ \else
+ \ifnum\JScomment=1
+ \aftergroup/%
+ \chardef\JScomment\zerocount
+ \fi
+ % is the delchar trick still needed?
+ \ifnum\JScomment=2
+ \ifnum`#1=13 % brrr
+ \doJSlinebreak
+ \else\if#1\par
+ \doJSlinebreak
+ \else\if#1\delcharacter
+ \doJSlinebreak
+ \fi\fi\fi
+ \else
+ \ifnum`#1=13 % brrr
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1\par
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1\delcharacter
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1(%
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+ \else\if#1)%
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+ %\else\if#1;%
+ % \flushJSisTEX\aftergroup;\doJSlinebreak
+ \else\if#1T%
+ \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
+ \else\if#1E%
+ \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
+ \else\if#1X%
+ \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
+ \else\if#1\normalspace
+ \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
+ \else
+ % todo: "test\"test"
+ \if#1"%
+ \ifcase\JSstring
+ \chardef\JSstring\plusone
+ \else
+ \chardef\JSstring\zerocount
+ \fi
+ \fi
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
+ \fi\fi\fi\fi\fi\fi\fi\fi\fi % \fi
+ \fi
+ \fi
+ \dododoPSsanitizeJScode}
+
+%D Close reading learns that one line comments (\type{// ...})
+%D are removed from the stream. This permits switching in
+%D pretty printing \JAVASCRIPT\ sources as well as saves
+%D some bytes.
+
+%D The magic 500 in the next hack prevents the input stack from
+%D overflowing when large scripts are sanitized.
+
+\def\dododoPSsanitizeJScode
+ {\ifcase\JSisTEX\ifcase\JScomment
+ \advance\scratchcounter \plusone
+ \fi\fi
+ \ifnum\scratchcounter=500
+ \expandafter\dodododoPSsanitizeJScode
+ \fi}
+
+\def\dodododoPSsanitizeJScode
+ {\let\next={%
+ \aftergroup}%
+ \endgroup
+ \begingroup
+ \aftergroup\xdef
+ \aftergroup\sanitizedJScode
+ \aftergroup{%
+ \aftergroup\sanitizedJScode
+ \let\next=}}
+
+%D The macro \type{\doPSsanitizeJScode} converts its argument
+%D into the macro \type{\sanitizedJScode}, thereby prefixing
+%D each \type{(} and \type{)} by a slash.
+
+%D Hooking this mechanism into the general \CONTEXT\ reference
+%D mechanism does not take much effort:
+
+\definespecialtest{JS}%
+ {\doifdefinedelse{\r!java\currentreferenceoperation}}
+
+\definespeciallocation{JS}#1#2%
+ {\iflocation
+ \bgroup
+ \bgroup
+ \presetJScode
+ \currentreferenceoperation
+ \currentreferencearguments
+ \egroup
+ \dohandlegoto
+ {#2}%
+ {\dostartgotoJS\buttonwidth\buttonheight\JScode}%
+ {\dostopgotoJS}%
+ \egroup
+ \else
+ {#2}%
+ \fi}
+
+%D \macros
+%D {useJSscripts}
+%D
+%D In due time, users will build their collections of scripts,
+%D which can be used (loaded) when applicable. Although not all
+%D public, we will provide some general purpose scripts,
+%D collected in files with names like \type{java-...}. One can
+%D load these scripts with \type{\useJSscripts}, like:
+%D
+%D \starttyping
+%D \useJSscripts[fld]
+%D \stoptyping
+%D
+%D The not so complicated implementation of this macro is:
+
+\def\dodouseJSscripts#1%
+ {\doifelse{#1}\v!reset
+ {\let\allJSpreambles\empty}
+ {\doifundefined{\c!file\f!javascriptprefix#1}
+ {\startnointerference
+ \letgvalueempty{\c!file\f!javascriptprefix#1}%
+ \makeshortfilename[\f!javascriptprefix#1]%
+ \startreadingfile
+ \readsysfile\shortfilename{\showmessage\m!javascript1{#1}}\donothing
+ \stopreadingfile
+ \stopnointerference}}}
+
+\def\douseJSscripts[#1][#2]%
+ {\processcommalist[#1]\dodouseJSscripts
+ \processcommalist[#2]\useJSpreamblenow}
+
+\def\useJSscripts
+ {\dodoubleempty\douseJSscripts}
+
+\protect \endinput
diff --git a/tex/context/base/java-ini.mkiv b/tex/context/base/java-ini.mkiv
new file mode 100644
index 000000000..53c36d65f
--- /dev/null
+++ b/tex/context/base/java-ini.mkiv
@@ -0,0 +1,688 @@
+%D \module
+%D [ file=java-ini,
+%D version=1998.01.30,
+%D title=\CONTEXT\ JavaScript Macros,
+%D subtitle=Initialization,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt JavaScript Macros / Initialization}
+
+% BUG: preamble zonder used/used en split
+
+% todo: lua sanitizer
+
+% JavaScript support is under development. In the near future
+% a slightly different model will be used. The JScode stuff
+% will probably become just auto function inclusion and the
+% JS_* things will disappear. First I have to find a way to
+% deal with global variables so the 'uses' thing will remain.
+
+% ook p{ref}
+% documentation should be corrected to JS(
+
+% Also, obeylines will be supported.
+
+\unprotect
+
+%D \JAVA\ support is not implemented as a generic support
+%D module. The main reason for this is that passing system
+%D variables to a \JAVASCRIPT\ is closely related to other core
+%D macros. First some messages:
+
+%D \TEX\ is not the right tool to check the \JAVA\ code; the
+%D most we can do is reporting some passed variables:
+
+\newif\iftraceJScode \traceJScodefalse
+
+\let\traceJScode\traceJScodetrue
+
+%D A bit out of place, but not dangerous:
+
+\bgroup
+\catcode127=\@@letter
+\gdef\delcharacter{^^7f}
+\egroup
+
+%D The number of passed variables is minimalized by setting the
+%D next switch.
+
+\newif\ifminimalizeJScode \minimalizeJScodetrue
+
+%D \macros
+%D {JS*}
+%D
+%D Because \JAVASCRIPT's are activated by the user, for
+%D instance by activating on a button, their support is closely
+%D related to the referencing mechanism. Integration takes
+%D place by
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum()]
+%D \stoptyping
+%D
+%D The \type{()} classify this as a script. If they are absent,
+%D the keyword is treated as a normal reference.
+%D
+%D One can pass arguments to such a script by saying:
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum(1.5,2.3)]
+%D \stoptyping
+%D
+%D References are passed by using the \type{R{}} classifier.
+%D
+%D \starttyping
+%D \goto{calculate total}[Sum(1.5,2.3,R{overflow})]
+%D \stoptyping
+%D
+%D The last call calls the script \type{Sum} and passes the
+%D next set of variables:
+%D
+%D \starttyping
+%D JS_S_1="1.5";
+%D JS_S_2="2.3";
+%D JS_R_3="overflow";
+%D JS_P_3=3;
+%D \stoptyping
+%D
+%D The first two parameters are just strings, the third one
+%D however is treated as a reference and results in passing the
+%D reference (if needed this references is prefixed) and the
+%D (real) page number. The alternative:
+%D
+%D \starttyping
+%D \goto{calculate total}[JS(Sum{V{1.5},V{2.3},R{overflow}})]
+%D \stoptyping
+%D
+%D does a verbose passing:
+%D
+%D \starttyping
+%D JS_V_1=1.5;
+%D JS_V_2=2.3;
+%D JS_R_3="overflow";
+%D JS_P_3=3;
+%D \stoptyping
+% %D
+% %D Finally we have a counter that tells\JAVA\ how many
+% %D arguments were passed,
+% %D
+% %D \starttyping
+% %D JS_N
+% %D \stoptyping
+
+%D We will also support direct function calls. In that case
+%D no intermediate variables are used.
+
+%D \macros
+%D {startJScode}
+%D
+%D A piece of \JAVASCRIPT\ code is defined by saying:
+%D
+%D \starttyping
+%D \startJScode{SomeScript}
+%D var Item=this.getField("item");
+%D N=Item.getArray();
+%D Total=this.getField("total");
+%D Total.value=0;
+%D for (j=0; j0) && (JS_R_1!=""))
+%D { gotoNamedDest(JS_R_1) };
+%D \stopJScode
+%D \stoptyping
+%D
+%D Such a piece of code is closely related to the interpreter
+%D used. Watch the last two lines, here the script adapts
+%D itself to the presence of a reference.
+%D
+%D While
+%D
+%D \starttyping
+%D \startJScode{name}
+%D name = 4 ;
+%D \stopJScode
+%D \stoptyping
+%D
+%D assumes uses no preamble or presumes that the preamble is
+%D always loaded, the next definition also tells \CONTEXT\ to
+%D actually include the preamble needed.
+%D
+%D \starttyping
+%D \startJScode{uses} uses {later}
+%D uses = 6 ;
+%D \stopJScode
+%D \stoptyping
+
+\long\def\startJScode#1 #2
+ {\doifelse{#2}{uses}
+ {\dostartJScodeA{#1}}
+ {\dostartJScodeB{#1} #2 }}
+
+\long\def\dostartJScodeA#1#2 #3\stopJScode
+ {\long\setgvalue{\r!java#1}{\do{#2}{#3}}}
+
+\long\def\dostartJScodeB#1#2\stopJScode
+ {\long\setgvalue{\r!java#1}{\do{}{#2}}}
+
+\let\stopJScode\relax
+
+%D \macros
+%D {presetJScode}
+%D
+%D The code can be retrieved by saying
+%D
+%D \starttyping
+%D \presetJScode{SomeScript}{template}
+%D \stoptyping
+%D
+%D Such a template is a comma separated list, where
+%D individual entries can optionally be transformed by
+%D \type{R{}} and \type{V{}}.
+%D
+%D After this call, the code is available in \type{\JScode}.
+
+\newif\ifdirectJScode
+
+\def\presetJScode#1#2% #1=operation #2=arguments
+ {\setverbosecscharacters
+ \def\par{\delcharacter}% was: { }
+ \scratchcounter\zerocount
+ \globallet\JScode\empty
+ \def\do##1##2%
+ {\doifelse{##2}{!}\directJScodetrue\directJScodefalse}%
+ \getvalue{\r!java#1}%
+ \edef\!!stringa{#2}%
+ \ifx\!!stringa\empty \else
+ \processcommacommand[\!!stringa]\dopresetJSvariables
+ \fi
+ \def\docommand##1%
+ {\doifundefinedelse{\r!java\r!java##1}
+ {\showmessage\m!javascript2{##1}}
+ {\useJSpreamblenow{##1}}}%
+% {\doglobal\increment\currentJSpreamble
+% \doglobal\addtocommalist{##1}\allJSpreambles}}%
+ \def\do##1##2%
+ {\xdef\JScode{\ifdirectJScode#1(\JScode)\else\JScode##2\fi}%
+ %\xdef\JScode{JS\string_N=\the\scratchcounter;\JScode}%
+ \processcommalist[##1]\docommand}%
+ \getvalue{\r!java#1}}
+
+\def\dopresetJSvariables#1%
+ {\advance\scratchcounter \plusone
+ \donefalse
+ \dodopresetJSvariables#1\end}%
+
+\def\dodopresetJSvariables
+ {\doifnextcharelse R\dodopresetJSrefvariables
+ {\doifnextcharelse V\dodopresetJSvervariables
+ {\doifnextcharelse S\dodopresetJSstrvariables
+ \dodopresetJSrawvariables}}}
+
+\def\dodopresetJSrefvariables R#1\end
+ {\doifreferencefoundelse{#1}
+ {\donetrue \dododopresetJSvariables R{\referenceprefix#1}%
+ \donefalse\dododopresetJSvariables P{\currentrealreference}}
+ {\unknownreference{#1}}%
+ \ifminimalizeJScode \else
+ \donetrue\dododopresetJSvariables S{#1}%
+ \fi}
+
+\def\dodopresetJSvervariables V#1\end
+ {\donefalse\dododopresetJSvariables V{#1}%
+ \ifminimalizeJScode \else
+ \donetrue\dododopresetJSvariables S{#1}%
+ \fi}
+
+\def\dodopresetJSstrvariables S#1\end
+ {\donetrue\dododopresetJSvariables S{#1}}
+
+\def\dodopresetJSrawvariables #1\end
+ {\donetrue\dododopresetJSvariables S{#1}}
+
+\def\JSprefix#1%
+ {JS\string_#1\string_\the\scratchcounter}
+
+\def\dododopresetJSvariables#1#2%
+ {\iftraceJScode
+ \writestatus{JavaScript}{\JSprefix#1=#2}
+ \xdef\JScode{\JScode console.println("\JSprefix#1=#2"); }%
+ \fi
+ \ifdirectJScode
+ \xdef\JScode{\ifx\JScode\empty\else\JScode,\fi\ifdone"#2"\else#2\fi}%
+ \else
+ \xdef\JScode{\JScode\JSprefix#1=\ifdone"#2"\else#2\fi; }%
+ \fi}
+
+%D \macros
+%D {startJSpreamble, flushJSpreamble}
+%D
+%D One can define insert \JAVASCRIPT\ code at the document level
+%D by using:
+%D
+%D \starttyping
+%D \startJSpreamble{oeps}
+%D oeps = 1 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D which is the same as:
+%D
+%D \starttyping
+%D \startJSpreamble{now} used now
+%D now = 2 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D while the next definition is only included when actually
+%D used.
+%D
+%D \starttyping
+%D \startJSpreamble{later} used later
+%D later = 3 ;
+%D \stopJSpreamble
+%D \stoptyping
+%D
+%D This command may be used more that once, but always before
+%D the first page is shipped out.
+
+\newif\ifoneJSpreamble \oneJSpreamblefalse
+
+\let\allJSpreambles\empty
+\newcounter\nofJSpreambles
+\newcounter\currentJSpreamble
+
+\long\def\startJSpreamble#1 #2 %
+ {\bgroup % we need to restore the catcodes
+ \restoreendofline % just in case it happens while reading lists
+ \doifelse{#2}{used}
+ {\dostartJSpreamble#1 }
+ {\dostartJSpreamble#1 now #2 }}
+
+\long\def\dostartJSpreamble#1 #2 %
+ {\processaction
+ [#2]
+ [ later=>\chardef\JSstatus\zerocount,%
+ now=>\chardef\JSstatus\plusone ,%
+ \s!default=>\chardef\JSstatus\plustwo ,%
+ \s!unknown=>\chardef\JSstatus\plustwo ]%
+ \ifaddJSlinebreaks
+ \obeylines \let\obeyedline \normalpar
+ \obeyspaces \let\obeyedspace\normalspace
+ \fi
+ \dodostartJSpreamble{#1}}
+
+\long\def\dodostartJSpreamble#1#2\stopJSpreamble
+ {\presetJSfunctions #2function ()\end
+ \long\setgvalue{\r!java\r!java#1}{#2}%
+ \ifcase\JSstatus \else
+ \useJSpreamblenow{#1}%
+ \fi
+ \egroup}
+
+%D \macros
+%D {setJSpreamble, addtoJSpreamble}
+%D
+%D In addition to the previous preamble definitions, we can
+%D set a preamble \quote {in||line} and add tokens to a
+%D preamble.
+
+\def\setJSpreamble#1#2%
+ {\doifundefined{\r!java\r!java#1}
+ {\setgvalue{\r!java\r!java#1}{#2;}%
+ \doglobal\increment\currentJSpreamble
+ \doglobal\addtocommalist{#1}\allJSpreambles}}
+
+\def\addtoJSpreamble#1#2%
+ {\doifdefinedelse{\r!java\r!java#1}
+ {\edef\!!stringa{\r!java\r!java#1}%
+ \edef\!!stringb{\csname\!!stringa\endcsname}%
+ \@EA\setgvalue\@EA\!!stringa\@EA{\!!stringb #2;}}
+ {\setJSpreamble{#1}{#2}}}
+
+%D \macros
+%D {useJSpreamblenow}
+%D
+%D The next macro can be used to force inclusion of postponed
+%D \JAVASCRIPT\ preambles.
+
+\def\useJSpreamblenow#1%
+ {\doglobal\increment\currentJSpreamble
+ \doglobal\addtocommalist{#1}\allJSpreambles}
+
+%D Because we want to check for valid calls, we preload the
+%D functions. This means that we can call them directly as
+%D well as indirectly when defined by \type {\startJScode} etc.
+
+% \long\def\presetJSfunctions#1function #2(#3)%
+% {\doifelsenothing{#2}
+% {\long\def\presetJSfunctions##1\end{}}
+% {\stripspaces\from#2\to\ascii
+% \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
+% \presetJSfunctions}
+
+\long\def\presetJSfunctions#1function#2(#3)%
+ {\doifelse{#2}\space
+ {\long\def\presetJSfunctions##1\end{}}
+ {\stripspaces\from#2\to\ascii
+ \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
+ \presetJSfunctions}
+
+\def\getJSpreamble#1%
+ {\getvalue{\r!java\r!java#1}}
+
+\def\presetJSpreamble
+ {\ifx\allJSpreambles\empty\else
+ \bgroup
+ \setverbosecscharacters
+ \obeyspaces \let\obeyedspace\normalspace
+ \def\par{\delcharacter}% was: { }
+ \globallet\JSpreamble\empty
+ \def\@@collectedJSpreamble{\r!java\r!java collected}%
+ \letvalue{\@@collectedJSpreamble}=\empty
+ \def\docommand##1%
+ {\xdef\JScode{\getvalue{\r!java\r!java##1}}%
+ \ifoneJSpreamble % \global\letcdcsname
+ \@EA\setxvalue\@EA\@@collectedJSpreamble\@EA
+ {\csname\@@collectedJSpreamble\endcsname\JScode}%
+ \else
+ \setxvalue{\r!java\r!java##1}{\JScode}%
+ \fi}%
+ \processcommacommand[\allJSpreambles]\docommand
+ \ifoneJSpreamble
+ \gdef\allJSpreambles{collected}%
+ \fi
+ \globallet\presetJSpreamble\relax
+ \egroup
+ \fi}
+
+\def\flushJSpreamble
+ {\iflocation\ifx\allJSpreambles\empty\else
+ \ifcase\nofJSpreambles\else\ifnum\nofJSpreambles=\currentJSpreamble
+ \bgroup
+ \presetJSpreamble
+ \expanded{\doflushJSpreamble{\allJSpreambles}}%
+ \globallet\flushJSpreamble\relax
+ \globallet\allJSpreambles\empty
+ \egroup
+ \fi\fi
+ \fi\fi}
+
+\def\finalflushJSpreamble
+ {\iflocation
+ \flushJSpreamble
+ \ifcase\currentJSpreamble\relax\else
+ \savecurrentvalue\nofJSpreambles\currentJSpreamble
+ \globallet\currentJSpreamble\nofJSpreambles
+ \fi
+ \fi}
+
+%D \macros
+%D {doPSsanitizeJScode}
+%D
+%D Before the code can be passed to the (\POSTSCRIPT\ or \PDF)
+%D output file, some precautions must be made concerning the
+%D use of \type{(} and~\type{)}. Here we use a beautiful
+%D \type{\aftergroup} trick I discovered in the \TABLE\ format.
+
+\def\doPSsanitizeJScode#1\to#2%
+ {\begingroup
+ \scratchcounter\zerocount % \aftergroup counter
+ \aftergroup\xdef
+ \aftergroup#2%
+ \aftergroup{%
+ \expanded{\defconvertedargument\noexpand\JScode{#1}}%
+ \expandafter\handletokens\JScode\with\dodoPSsanitizeJScode
+ \aftergroup}%
+ \endgroup
+ \iftraceJScode
+ \writestatus{JS trace}{#2}%
+ \fi}
+
+%D I started with:
+%D
+%D \starttyping
+%D \def\dodoPSsanitizeJScode#1%
+%D {\aftergroup\string
+%D \if#1(%
+%D \expandafter\aftergroup\csname#1\endcsname
+%D \else\if#1)%
+%D \expandafter\aftergroup\csname#1\endcsname
+%D \else\if#1;%
+%D \aftergroup;\aftergroup\string\expandafter\aftergroup\
+%D \else
+%D \expandafter\aftergroup#1%
+%D \fi\fi\fi
+%D \advance\scratchcounter by 1
+%D \ifnum\scratchcounter=500
+%D \expandafter\dododoPSsanitizeJScode
+%D \fi}
+%D \stoptyping
+%D
+%D For pretty printing purposes, we need some way to signal
+%D \TEX\ macros. Therefore we introduce a special keyword
+%D \type{TEX}. When followed by a space, this keyword is
+%D ignored, that is, filtered from the stream. Now we have:
+
+\chardef\JSisTEX \zerocount
+\chardef\JScomment\zerocount
+
+\newif\ifaddJSlinebreaks \addJSlinebreakstrue
+
+\def\flushJSisTEX
+ {\ifcase\JSisTEX
+ \or \aftergroup T%
+ \or \aftergroup T\aftergroup E%
+ \or \aftergroup T\aftergroup E\aftergroup X%
+ \fi
+ \chardef\JSisTEX\zerocount}
+
+% \def\doJSlinebreak
+% {\ifaddJSlinebreaks
+% \aftergroup\string\aftergroup\n%
+% \fi}
+%
+% \def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
+% {\if#1/%
+% \ifnum\JScomment=0
+% \chardef\JScomment\plusone
+% \else\ifnum\JScomment=1
+% \chardef\JScomment\plustwo
+% \fi\fi
+% \else
+% \ifnum\JScomment=1
+% \aftergroup/%
+% \chardef\JScomment\zerocount
+% \fi
+% \ifnum\JScomment=2
+% \if#1\delcharacter
+% \chardef\JScomment\zerocount
+% \fi
+% \else
+% \if#1\delcharacter
+% \flushJSisTEX\doJSlinebreak
+% \else\if#1(%
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+% \else\if#1)%
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+% \else\if#1;%
+% \flushJSisTEX\aftergroup;\doJSlinebreak
+% \else\if#1T%
+% \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
+% \else\if#1E%
+% \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
+% \else\if#1X%
+% \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
+% \else\if#1\normalspace
+% \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
+% \else
+% \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
+% \fi\fi\fi\fi\fi\fi\fi\fi
+% \fi
+% \fi
+% \dododoPSsanitizeJScode}
+
+% todo: "http:\\" -> simple. maar wel \" afvangen
+%
+% use new pdftex escape mechanism or make fully expandable version, not used that often btw
+
+\chardef\JSstring\zerocount
+
+\def\doJSlinebreak
+ {\chardef\JScomment\zerocount
+ \chardef\JSstring\zerocount
+ \ifaddJSlinebreaks
+ \aftergroup\string\aftergroup\n%
+ \fi}
+
+\def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
+ {\if#1/%
+ \ifnum\JSstring=0
+ \ifnum\JScomment=0
+ \chardef\JScomment\plusone
+ \else\ifnum\JScomment=1
+ \chardef\JScomment\plustwo
+ \fi\fi
+ \else
+ \aftergroup/%
+ \fi
+ \else
+ \ifnum\JScomment=1
+ \aftergroup/%
+ \chardef\JScomment\zerocount
+ \fi
+ % is the delchar trick still needed?
+ \ifnum\JScomment=2
+ \ifnum`#1=13 % brrr
+ \doJSlinebreak
+ \else\if#1\par
+ \doJSlinebreak
+ \else\if#1\delcharacter
+ \doJSlinebreak
+ \fi\fi\fi
+ \else
+ \ifnum`#1=13 % brrr
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1\par
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1\delcharacter
+ \flushJSisTEX\doJSlinebreak
+ \else\if#1(%
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+ \else\if#1)%
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
+ %\else\if#1;%
+ % \flushJSisTEX\aftergroup;\doJSlinebreak
+ \else\if#1T%
+ \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
+ \else\if#1E%
+ \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
+ \else\if#1X%
+ \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
+ \else\if#1\normalspace
+ \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
+ \else
+ % todo: "test\"test"
+ \if#1"%
+ \ifcase\JSstring
+ \chardef\JSstring\plusone
+ \else
+ \chardef\JSstring\zerocount
+ \fi
+ \fi
+ \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
+ \fi\fi\fi\fi\fi\fi\fi\fi\fi % \fi
+ \fi
+ \fi
+ \dododoPSsanitizeJScode}
+
+%D Close reading learns that one line comments (\type{// ...})
+%D are removed from the stream. This permits switching in
+%D pretty printing \JAVASCRIPT\ sources as well as saves
+%D some bytes.
+
+%D The magic 500 in the next hack prevents the input stack from
+%D overflowing when large scripts are sanitized.
+
+\def\dododoPSsanitizeJScode
+ {\ifcase\JSisTEX\ifcase\JScomment
+ \advance\scratchcounter \plusone
+ \fi\fi
+ \ifnum\scratchcounter=500
+ \expandafter\dodododoPSsanitizeJScode
+ \fi}
+
+\def\dodododoPSsanitizeJScode
+ {\let\next={%
+ \aftergroup}%
+ \endgroup
+ \begingroup
+ \aftergroup\xdef
+ \aftergroup\sanitizedJScode
+ \aftergroup{%
+ \aftergroup\sanitizedJScode
+ \let\next=}}
+
+%D The macro \type{\doPSsanitizeJScode} converts its argument
+%D into the macro \type{\sanitizedJScode}, thereby prefixing
+%D each \type{(} and \type{)} by a slash.
+
+%D Hooking this mechanism into the general \CONTEXT\ reference
+%D mechanism does not take much effort:
+
+\definespecialtest{JS}%
+ {\doifdefinedelse{\r!java\currentreferenceoperation}}
+
+\def\gotojavascriptspecial#1#2#3#4% special operation arguments data
+ {\begingroup
+ \iflocation
+ \bgroup
+ \presetJScode{#2}{#3}%
+ \egroup
+ \dohandlegoto{#4}{\dostartgotoJS\buttonwidth\buttonheight\JScode}{\dostopgotoJS}%
+ \else
+ #4%
+ \fi
+ \endgroup}
+
+%D \macros
+%D {useJSscripts}
+%D
+%D In due time, users will build their collections of scripts,
+%D which can be used (loaded) when applicable. Although not all
+%D public, we will provide some general purpose scripts,
+%D collected in files with names like \type{java-...}. One can
+%D load these scripts with \type{\useJSscripts}, like:
+%D
+%D \starttyping
+%D \useJSscripts[fld]
+%D \stoptyping
+%D
+%D The not so complicated implementation of this macro is:
+
+\def\dodouseJSscripts#1%
+ {\doifelse{#1}\v!reset
+ {\let\allJSpreambles\empty}
+ {\doifundefined{\c!file\f!javascriptprefix#1}
+ {\startnointerference
+ \letgvalueempty{\c!file\f!javascriptprefix#1}%
+ \makeshortfilename[\f!javascriptprefix#1]%
+ \startreadingfile
+ \readsysfile\shortfilename{\showmessage\m!javascript1{#1}}\donothing
+ \stopreadingfile
+ \stopnointerference}}}
+
+\def\douseJSscripts[#1][#2]%
+ {\processcommalist[#1]\dodouseJSscripts
+ \processcommalist[#2]\useJSpreamblenow}
+
+\def\useJSscripts
+ {\dodoubleempty\douseJSscripts}
+
+\protect \endinput
diff --git a/tex/context/base/java-ini.tex b/tex/context/base/java-ini.tex
deleted file mode 100644
index 7dc2cfe04..000000000
--- a/tex/context/base/java-ini.tex
+++ /dev/null
@@ -1,742 +0,0 @@
-%D \module
-%D [ file=java-ini,
-%D version=1998.01.30,
-%D title=\CONTEXT\ JavaScript Macros,
-%D subtitle=Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context JavaScript Macros / Initialization}
-
-% BUG: preamble zonder used/used en split
-
-% JavaScript support is under development. In the near future
-% a slightly different model will be used. The JScode stuff
-% will probably become just auto function inclusion and the
-% JS_* things will disappear. First I have to find a way to
-% deal with global variables so the 'uses' thing will remain.
-
-% ook p{ref}
-% documentation should be corrected to JS(
-
-% Also, obeylines will be supported.
-
-\unprotect
-
-%D \JAVA\ support is not implemented as a generic support
-%D module. The main reason for this is that passing system
-%D variables to a \JAVASCRIPT\ is closely related to other core
-%D macros. First some messages:
-
-\startmessages dutch library: javascript
- title: javascript
- 1: script set -- wordt geladen
- 2: onbekende preamble --
-\stopmessages
-
-\startmessages english library: javascript
- title: javascript
- 1: loading script set --
- 2: unknown preamble --
-\stopmessages
-
-\startmessages german library: javascript
- title: javascript
- 1: Lade Scriptdatei --
- 2: unbekannte Preamble --
-\stopmessages
-
-\startmessages czech library: javascript
- title: javascript
- 1: nacita se soubor skriptu --
- 2: neznama preambule --
-\stopmessages
-
-\startmessages italian library: javascript
- title: javascript
- 1: caricamento dello script set --
- 2: preambolo sconosciuto --
-\stopmessages
-
-\startmessages norwegian library: javascript
- title: javascript
- 1: leser inn scriptsett --
- 2: ukjent 'preamble' --
-\stopmessages
-
-\startmessages romanian library: javascript
- title: javascript
- 1: se incarca scriptul --
- 2: preambul necunoscut --
-\stopmessages
-
-\startmessages french library: javascript
- title: javascript
- 1: chargement du jeu de script --
- 2: préambule -- inconnu
-\stopmessages
-
-
-%D \TEX\ is not the right tool to check the \JAVA\ code; the
-%D most we can do is reporting some passed variables:
-
-\newif\iftraceJScode \traceJScodefalse
-
-\let\traceJScode\traceJScodetrue
-
-%D A bit out of place, but not dangerous:
-
-\bgroup
-\catcode127=\@@letter
-\gdef\delcharacter{^^7f}
-\egroup
-
-%D The number of passed variables is minimalized by setting the
-%D next switch.
-
-\newif\ifminimalizeJScode \minimalizeJScodetrue
-
-%D \macros
-%D {JS*}
-%D
-%D Because \JAVASCRIPT's are activated by the user, for
-%D instance by activating on a button, their support is closely
-%D related to the referencing mechanism. Integration takes
-%D place by
-%D
-%D \starttyping
-%D \goto{calculate total}[Sum()]
-%D \stoptyping
-%D
-%D The \type{()} classify this as a script. If they are absent,
-%D the keyword is treated as a normal reference.
-%D
-%D One can pass arguments to such a script by saying:
-%D
-%D \starttyping
-%D \goto{calculate total}[Sum(1.5,2.3)]
-%D \stoptyping
-%D
-%D References are passed by using the \type{R{}} classifier.
-%D
-%D \starttyping
-%D \goto{calculate total}[Sum(1.5,2.3,R{overflow})]
-%D \stoptyping
-%D
-%D The last call calls the script \type{Sum} and passes the
-%D next set of variables:
-%D
-%D \starttyping
-%D JS_S_1="1.5";
-%D JS_S_2="2.3";
-%D JS_R_3="overflow";
-%D JS_P_3=3;
-%D \stoptyping
-%D
-%D The first two parameters are just strings, the third one
-%D however is treated as a reference and results in passing the
-%D reference (if needed this references is prefixed) and the
-%D (real) page number. The alternative:
-%D
-%D \starttyping
-%D \goto{calculate total}[JS(Sum{V{1.5},V{2.3},R{overflow}})]
-%D \stoptyping
-%D
-%D does a verbose passing:
-%D
-%D \starttyping
-%D JS_V_1=1.5;
-%D JS_V_2=2.3;
-%D JS_R_3="overflow";
-%D JS_P_3=3;
-%D \stoptyping
-% %D
-% %D Finally we have a counter that tells\JAVA\ how many
-% %D arguments were passed,
-% %D
-% %D \starttyping
-% %D JS_N
-% %D \stoptyping
-
-%D We will also support direct function calls. In that case
-%D no intermediate variables are used.
-
-%D \macros
-%D {startJScode}
-%D
-%D A piece of \JAVASCRIPT\ code is defined by saying:
-%D
-%D \starttyping
-%D \startJScode{SomeScript}
-%D var Item=this.getField("item");
-%D N=Item.getArray();
-%D Total=this.getField("total");
-%D Total.value=0;
-%D for (j=0; j0) && (JS_R_1!=""))
-%D { gotoNamedDest(JS_R_1) };
-%D \stopJScode
-%D \stoptyping
-%D
-%D Such a piece of code is closely related to the interpreter
-%D used. Watch the last two lines, here the script adapts
-%D itself to the presence of a reference.
-%D
-%D While
-%D
-%D \starttyping
-%D \startJScode{name}
-%D name = 4 ;
-%D \stopJScode
-%D \stoptyping
-%D
-%D assumes uses no preamble or presumes that the preamble is
-%D always loaded, the next definition also tells \CONTEXT\ to
-%D actually include the preamble needed.
-%D
-%D \starttyping
-%D \startJScode{uses} uses {later}
-%D uses = 6 ;
-%D \stopJScode
-%D \stoptyping
-
-\long\def\startJScode#1 #2
- {\doifelse{#2}{uses}
- {\dostartJScodeA{#1}}
- {\dostartJScodeB{#1} #2 }}
-
-\long\def\dostartJScodeA#1#2 #3\stopJScode
- {\long\setgvalue{\r!java#1}{\do{#2}{#3}}}
-
-\long\def\dostartJScodeB#1#2\stopJScode
- {\long\setgvalue{\r!java#1}{\do{}{#2}}}
-
-\let\stopJScode\relax
-
-%D \macros
-%D {presetJScode}
-%D
-%D The code can be retrieved by saying
-%D
-%D \starttyping
-%D \presetJScode{SomeScript}{template}
-%D \stoptyping
-%D
-%D Such a template is a comma separated list, where
-%D individual entries can optionally be transformed by
-%D \type{R{}} and \type{V{}}.
-%D
-%D After this call, the code is available in \type{\JScode}.
-
-\newif\ifdirectJScode
-
-\def\presetJScode#1#2% #1=operation #2=arguments
- {\setverbosecscharacters
- \def\par{\delcharacter}% was: { }
- \scratchcounter\zerocount
- \globallet\JScode\empty
- \def\do##1##2%
- {\doifelse{##2}{!}\directJScodetrue\directJScodefalse}%
- \getvalue{\r!java#1}%
- \edef\!!stringa{#2}%
- \ifx\!!stringa\empty \else
- \processcommacommand[\!!stringa]\dopresetJSvariables
- \fi
- \def\docommand##1%
- {\doifundefinedelse{\r!java\r!java##1}
- {\showmessage\m!javascript2{##1}}
- {\useJSpreamblenow{##1}}}%
-% {\doglobal\increment\currentJSpreamble
-% \doglobal\addtocommalist{##1}\allJSpreambles}}%
- \def\do##1##2%
- {\xdef\JScode{\ifdirectJScode#1(\JScode)\else\JScode##2\fi}%
- %\xdef\JScode{JS\string_N=\the\scratchcounter;\JScode}%
- \processcommalist[##1]\docommand}%
- \getvalue{\r!java#1}}
-
-\def\dopresetJSvariables#1%
- {\advance\scratchcounter \plusone
- \donefalse
- \dodopresetJSvariables#1\end}%
-
-\def\dodopresetJSvariables
- {\doifnextcharelse R\dodopresetJSrefvariables
- {\doifnextcharelse V\dodopresetJSvervariables
- {\doifnextcharelse S\dodopresetJSstrvariables
- \dodopresetJSrawvariables}}}
-
-\def\dodopresetJSrefvariables R#1\end
- {\doifreferencefoundelse{#1}
- {\donetrue \dododopresetJSvariables R{\referenceprefix#1}%
- \donefalse\dododopresetJSvariables P{\currentrealreference}}
- {\unknownreference{#1}}%
- \ifminimalizeJScode \else
- \donetrue\dododopresetJSvariables S{#1}%
- \fi}
-
-\def\dodopresetJSvervariables V#1\end
- {\donefalse\dododopresetJSvariables V{#1}%
- \ifminimalizeJScode \else
- \donetrue\dododopresetJSvariables S{#1}%
- \fi}
-
-\def\dodopresetJSstrvariables S#1\end
- {\donetrue\dododopresetJSvariables S{#1}}
-
-\def\dodopresetJSrawvariables #1\end
- {\donetrue\dododopresetJSvariables S{#1}}
-
-\def\JSprefix#1%
- {JS\string_#1\string_\the\scratchcounter}
-
-\def\dododopresetJSvariables#1#2%
- {\iftraceJScode
- \writestatus{JavaScript}{\JSprefix#1=#2}
- \xdef\JScode{\JScode console.println("\JSprefix#1=#2"); }%
- \fi
- \ifdirectJScode
- \xdef\JScode{\ifx\JScode\empty\else\JScode,\fi\ifdone"#2"\else#2\fi}%
- \else
- \xdef\JScode{\JScode\JSprefix#1=\ifdone"#2"\else#2\fi; }%
- \fi}
-
-%D \macros
-%D {startJSpreamble, flushJSpreamble}
-%D
-%D One can define insert \JAVASCRIPT\ code at the document level
-%D by using:
-%D
-%D \starttyping
-%D \startJSpreamble{oeps}
-%D oeps = 1 ;
-%D \stopJSpreamble
-%D \stoptyping
-%D
-%D which is the same as:
-%D
-%D \starttyping
-%D \startJSpreamble{now} used now
-%D now = 2 ;
-%D \stopJSpreamble
-%D \stoptyping
-%D
-%D while the next definition is only included when actually
-%D used.
-%D
-%D \starttyping
-%D \startJSpreamble{later} used later
-%D later = 3 ;
-%D \stopJSpreamble
-%D \stoptyping
-%D
-%D This command may be used more that once, but always before
-%D the first page is shipped out.
-
-\newif\ifoneJSpreamble \oneJSpreamblefalse
-
-\let\allJSpreambles\empty
-\newcounter\nofJSpreambles
-\newcounter\currentJSpreamble
-
-\long\def\startJSpreamble#1 #2 %
- {\bgroup % we need to restore the catcodes
- \restoreendofline % just in case it happens while reading lists
- \doifelse{#2}{used}
- {\dostartJSpreamble#1 }
- {\dostartJSpreamble#1 now #2 }}
-
-\long\def\dostartJSpreamble#1 #2 %
- {\processaction
- [#2]
- [ later=>\chardef\JSstatus\zerocount,%
- now=>\chardef\JSstatus\plusone ,%
- \s!default=>\chardef\JSstatus\plustwo ,%
- \s!unknown=>\chardef\JSstatus\plustwo ]%
- \ifaddJSlinebreaks
- \obeylines \let\obeyedline \normalpar
- \obeyspaces \let\obeyedspace\normalspace
- \fi
- \dodostartJSpreamble{#1}}
-
-\long\def\dodostartJSpreamble#1#2\stopJSpreamble
- {\presetJSfunctions #2function ()\end
- \long\setgvalue{\r!java\r!java#1}{#2}%
- \ifcase\JSstatus \else
- \useJSpreamblenow{#1}%
- \fi
- \egroup}
-
-%D \macros
-%D {setJSpreamble, addtoJSpreamble}
-%D
-%D In addition to the previous preamble definitions, we can
-%D set a preamble \quote {in||line} and add tokens to a
-%D preamble.
-
-\def\setJSpreamble#1#2%
- {\doifundefined{\r!java\r!java#1}
- {\setgvalue{\r!java\r!java#1}{#2;}%
- \doglobal\increment\currentJSpreamble
- \doglobal\addtocommalist{#1}\allJSpreambles}}
-
-\def\addtoJSpreamble#1#2%
- {\doifdefinedelse{\r!java\r!java#1}
- {\edef\!!stringa{\r!java\r!java#1}%
- \edef\!!stringb{\csname\!!stringa\endcsname}%
- \@EA\setgvalue\@EA\!!stringa\@EA{\!!stringb #2;}}
- {\setJSpreamble{#1}{#2}}}
-
-%D \macros
-%D {useJSpreamblenow}
-%D
-%D The next macro can be used to force inclusion of postponed
-%D \JAVASCRIPT\ preambles.
-
-\def\useJSpreamblenow#1%
- {\doglobal\increment\currentJSpreamble
- \doglobal\addtocommalist{#1}\allJSpreambles}
-
-%D Because we want to check for valid calls, we preload the
-%D functions. This means that we can call them directly as
-%D well as indirectly when defined by \type {\startJScode} etc.
-
-% \long\def\presetJSfunctions#1function #2(#3)%
-% {\doifelsenothing{#2}
-% {\long\def\presetJSfunctions##1\end{}}
-% {\stripspaces\from#2\to\ascii
-% \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
-% \presetJSfunctions}
-
-\long\def\presetJSfunctions#1function#2(#3)%
- {\doifelse{#2}\space
- {\long\def\presetJSfunctions##1\end{}}
- {\stripspaces\from#2\to\ascii
- \doifundefined{\r!java\ascii}{\setgvalue{\r!java\ascii}{\do{}{!}}}}%
- \presetJSfunctions}
-
-\def\getJSpreamble#1%
- {\getvalue{\r!java\r!java#1}}
-
-\def\presetJSpreamble
- {\ifx\allJSpreambles\empty\else
- \bgroup
- \setverbosecscharacters
- \def\par{\delcharacter}% was: { }
- \globallet\JSpreamble\empty
- \def\@@collectedJSpreamble{\r!java\r!java collected}%
- \letvalue{\@@collectedJSpreamble}=\empty
- \def\docommand##1%
- {\xdef\JScode{\getvalue{\r!java\r!java##1}}%
- \ifoneJSpreamble % \global\letcdcsname
- \@EA\setxvalue\@EA\@@collectedJSpreamble\@EA
- {\csname\@@collectedJSpreamble\endcsname\JScode}%
- \else
- \setxvalue{\r!java\r!java##1}{\JScode}%
- \fi}%
- \processcommacommand[\allJSpreambles]\docommand
- \ifoneJSpreamble
- \gdef\allJSpreambles{collected}%
- \fi
- \globallet\presetJSpreamble\relax
- \egroup
- \fi}
-
-\def\flushJSpreamble
- {\iflocation\ifx\allJSpreambles\empty\else
- \ifcase\nofJSpreambles\else\ifnum\nofJSpreambles=\currentJSpreamble
- \bgroup
- \presetJSpreamble
- \expanded{\doflushJSpreamble{\allJSpreambles}}%
- \globallet\flushJSpreamble\relax
- \globallet\allJSpreambles\empty
- \egroup
- \fi\fi
- \fi\fi}
-
-\def\finalflushJSpreamble
- {\iflocation
- \flushJSpreamble
- \ifcase\currentJSpreamble\relax\else
- \savecurrentvalue\nofJSpreambles\currentJSpreamble
- \globallet\currentJSpreamble\nofJSpreambles
- \fi
- \fi}
-
-\prependtoks \flushJSpreamble \to \everyshipout
-\prependtoks \finalflushJSpreamble \to \everylastshipout
-
-%D \macros
-%D {doPSsanitizeJScode}
-%D
-%D Before the code can be passed to the (\POSTSCRIPT\ or \PDF)
-%D output file, some precautions must be made concerning the
-%D use of \type{(} and~\type{)}. Here we use a beautiful
-%D \type{\aftergroup} trick I discovered in the \TABLE\ format.
-
-\def\doPSsanitizeJScode#1\to#2%
- {\begingroup
- \scratchcounter\zerocount % \aftergroup counter
- \aftergroup\xdef
- \aftergroup#2%
- \aftergroup{%
- \expanded{\defconvertedargument\noexpand\JScode{#1}}%
- \expandafter\handletokens\JScode\with\dodoPSsanitizeJScode
- \aftergroup}%
- \endgroup
- \iftraceJScode
- \writestatus{JS trace}{#2}%
- \fi}
-
-%D I started with:
-%D
-%D \starttyping
-%D \def\dodoPSsanitizeJScode#1%
-%D {\aftergroup\string
-%D \if#1(%
-%D \expandafter\aftergroup\csname#1\endcsname
-%D \else\if#1)%
-%D \expandafter\aftergroup\csname#1\endcsname
-%D \else\if#1;%
-%D \aftergroup;\aftergroup\string\expandafter\aftergroup\
-%D \else
-%D \expandafter\aftergroup#1%
-%D \fi\fi\fi
-%D \advance\scratchcounter by 1
-%D \ifnum\scratchcounter=500
-%D \expandafter\dododoPSsanitizeJScode
-%D \fi}
-%D \stoptyping
-%D
-%D For pretty printing purposes, we need some way to signal
-%D \TEX\ macros. Therefore we introduce a special keyword
-%D \type{TEX}. When followed by a space, this keyword is
-%D ignored, that is, filtered from the stream. Now we have:
-
-\chardef\JSisTEX \zerocount
-\chardef\JScomment\zerocount
-
-\newif\ifaddJSlinebreaks \addJSlinebreakstrue
-
-\def\flushJSisTEX
- {\ifcase\JSisTEX
- \or \aftergroup T%
- \or \aftergroup T\aftergroup E%
- \or \aftergroup T\aftergroup E\aftergroup X%
- \fi
- \chardef\JSisTEX\zerocount}
-
-% \def\doJSlinebreak
-% {\ifaddJSlinebreaks
-% \aftergroup\string\aftergroup\n%
-% \fi}
-%
-% \def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
-% {\if#1/%
-% \ifnum\JScomment=0
-% \chardef\JScomment\plusone
-% \else\ifnum\JScomment=1
-% \chardef\JScomment\plustwo
-% \fi\fi
-% \else
-% \ifnum\JScomment=1
-% \aftergroup/%
-% \chardef\JScomment\zerocount
-% \fi
-% \ifnum\JScomment=2
-% \if#1\delcharacter
-% \chardef\JScomment\zerocount
-% \fi
-% \else
-% \if#1\delcharacter
-% \flushJSisTEX\doJSlinebreak
-% \else\if#1(%
-% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
-% \else\if#1)%
-% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
-% \else\if#1;%
-% \flushJSisTEX\aftergroup;\doJSlinebreak
-% \else\if#1T%
-% \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
-% \else\if#1E%
-% \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
-% \else\if#1X%
-% \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
-% \else\if#1\normalspace
-% \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
-% \else
-% \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
-% \fi\fi\fi\fi\fi\fi\fi\fi
-% \fi
-% \fi
-% \dododoPSsanitizeJScode}
-
-% todo: "http:\\" -> simple. maar wel \" afvangen
-%
-% use new pdftex escape mechanism or make fully expandable version, not used that often btw
-
-\chardef\JSstring\zerocount
-
-\def\doJSlinebreak
- {\chardef\JScomment\zerocount
- \chardef\JSstring\zerocount
- \ifaddJSlinebreaks
- \aftergroup\string\aftergroup\n%
- \fi}
-
-\def\dodoPSsanitizeJScode#1% % input stack>500 & TEX check
- {\if#1/%
- \ifnum\JSstring=0
- \ifnum\JScomment=0
- \chardef\JScomment\plusone
- \else\ifnum\JScomment=1
- \chardef\JScomment\plustwo
- \fi\fi
- \else
- \aftergroup/%
- \fi
- \else
- \ifnum\JScomment=1
- \aftergroup/%
- \chardef\JScomment\zerocount
- \fi
- % is the delchar trick still needed?
- \ifnum\JScomment=2
- \ifnum`#1=13 % brrr
- \doJSlinebreak
- \else\if#1\par
- \doJSlinebreak
- \else\if#1\delcharacter
- \doJSlinebreak
- \fi\fi\fi
- \else
- \ifnum`#1=13 % brrr
- \flushJSisTEX\doJSlinebreak
- \else\if#1\par
- \flushJSisTEX\doJSlinebreak
- \else\if#1\delcharacter
- \flushJSisTEX\doJSlinebreak
- \else\if#1(%
- \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
- \else\if#1)%
- \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname
- %\else\if#1;%
- % \flushJSisTEX\aftergroup;\doJSlinebreak
- \else\if#1T%
- \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi
- \else\if#1E%
- \ifnum\JSisTEX=1 \chardef\JSisTEX\plustwo \else\flushJSisTEX\aftergroup E\fi
- \else\if#1X%
- \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi
- \else\if#1\normalspace
- \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi
- \else
- % todo: "test\"test"
- \if#1"%
- \ifcase\JSstring
- \chardef\JSstring\plusone
- \else
- \chardef\JSstring\zerocount
- \fi
- \fi
- \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1%
- \fi\fi\fi\fi\fi\fi\fi\fi\fi % \fi
- \fi
- \fi
- \dododoPSsanitizeJScode}
-
-%D Close reading learns that one line comments (\type{// ...})
-%D are removed from the stream. This permits switching in
-%D pretty printing \JAVASCRIPT\ sources as well as saves
-%D some bytes.
-
-%D The magic 500 in the next hack prevents the input stack from
-%D overflowing when large scripts are sanitized.
-
-\def\dododoPSsanitizeJScode
- {\ifcase\JSisTEX\ifcase\JScomment
- \advance\scratchcounter \plusone
- \fi\fi
- \ifnum\scratchcounter=500
- \expandafter\dodododoPSsanitizeJScode
- \fi}
-
-\def\dodododoPSsanitizeJScode
- {\let\next={%
- \aftergroup}%
- \endgroup
- \begingroup
- \aftergroup\xdef
- \aftergroup\sanitizedJScode
- \aftergroup{%
- \aftergroup\sanitizedJScode
- \let\next=}}
-
-%D The macro \type{\doPSsanitizeJScode} converts its argument
-%D into the macro \type{\sanitizedJScode}, thereby prefixing
-%D each \type{(} and \type{)} by a slash.
-
-%D Hooking this mechanism into the general \CONTEXT\ reference
-%D mechanism does not take much effort:
-
-\definespecialtest{JS}%
- {\doifdefinedelse{\r!java\currentreferenceoperation}}
-
-\definespeciallocation{JS}#1#2%
- {\iflocation
- \bgroup
- \bgroup
- \presetJScode
- \currentreferenceoperation
- \currentreferencearguments
- \egroup
- \dohandlegoto
- {#2}%
- {\dostartgotoJS\buttonwidth\buttonheight\JScode}%
- {\dostopgotoJS}%
- \egroup
- \else
- {#2}%
- \fi}
-
-%D \macros
-%D {useJSscripts}
-%D
-%D In due time, users will build their collections of scripts,
-%D which can be used (loaded) when applicable. Although not all
-%D public, we will provide some general purpose scripts,
-%D collected in files with names like \type{java-...}. One can
-%D load these scripts with \type{\useJSscripts}, like:
-%D
-%D \starttyping
-%D \useJSscripts[fld]
-%D \stoptyping
-%D
-%D The not so complicated implementation of this macro is:
-
-\def\dodouseJSscripts#1%
- {\doifelse{#1}\v!reset
- {\let\allJSpreambles\empty}
- {\doifundefined{\c!file\f!javascriptprefix#1}
- {\startnointerference
- \letgvalueempty{\c!file\f!javascriptprefix#1}%
- \makeshortfilename[\f!javascriptprefix#1]%
- \startreadingfile
- \readsysfile\shortfilename{\showmessage\m!javascript1{#1}}\donothing
- \stopreadingfile
- \stopnointerference}}}
-
-\def\douseJSscripts[#1][#2]%
- {\processcommalist[#1]\dodouseJSscripts
- \processcommalist[#2]\useJSpreamblenow}
-
-\def\useJSscripts
- {\dodoubleempty\douseJSscripts}
-
-\protect \endinput
diff --git a/tex/context/base/l-aux.lua b/tex/context/base/l-aux.lua
index 9705fb711..6b1fd67ff 100644
--- a/tex/context/base/l-aux.lua
+++ b/tex/context/base/l-aux.lua
@@ -1,68 +1,94 @@
--- filename : l-aux.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-aux'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-aux'] = 1.001
-if not aux then aux = { } end
+aux = aux or { }
-local concat, format = table.concat, string.format
+local concat, format, gmatch = table.concat, string.format, string.gmatch
local tostring, type = tostring, type
-do
+local space = lpeg.P(' ')
+local equal = lpeg.P("=")
+local comma = lpeg.P(",")
+local lbrace = lpeg.P("{")
+local rbrace = lpeg.P("}")
+local nobrace = 1 - (lbrace+rbrace)
+local nested = lpeg.P{ lbrace * (nobrace + lpeg.V(1))^0 * rbrace }
+local spaces = space^0
- local hash = { }
+local value = lpeg.P(lbrace * lpeg.C((nobrace + nested)^0) * rbrace) + lpeg.C((nested + (1-comma))^0)
- local function set(key,value) -- using Carg is slower here
- hash[key] = value
+local key = lpeg.C((1-equal-comma)^1)
+local pattern_a = (space+comma)^0 * (key * equal * value + key * lpeg.C(""))
+
+local key = lpeg.C((1-space-equal-comma)^1)
+local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces * value) + lpeg.C("")))
+
+-- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored
+
+local hash = { }
+
+local function set(key,value) -- using Carg is slower here
+ hash[key] = value
+end
+
+local pattern_a_s = (pattern_a/set)^1
+local pattern_b_s = (pattern_b/set)^1
+
+aux.settings_to_hash_pattern_a = pattern_a_s
+aux.settings_to_hash_pattern_b = pattern_b_s
+
+function aux.make_settings_to_hash_pattern(set,moretolerant)
+ if moretolerant then
+ return (pattern_b/set)^1
+ else
+ return (pattern_a/set)^1
end
+end
- local space = lpeg.P(' ')
- local equal = lpeg.P("=")
- local comma = lpeg.P(",")
- local lbrace = lpeg.P("{")
- local rbrace = lpeg.P("}")
- local nobrace = 1 - (lbrace+rbrace)
- local nested = lpeg.P{ lbrace * (nobrace + lpeg.V(1))^0 * rbrace }
-
- local key = lpeg.C((1-equal-comma)^1)
- local value = lpeg.P(lbrace * lpeg.C((nobrace + nested)^0) * rbrace) + lpeg.C((nested + (1-comma))^0)
--- local pattern = (((space+comma)^0 * (key * equal * value + key) * comma^0) / set)^1
- local pattern = (((space+comma)^0 * (key * equal * value + key * lpeg.C(""))) / set)^1
-
- -- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored
-
- function aux.settings_to_hash(str)
- if str and str ~= "" then
- hash = { }
- pattern:match(str)
- return hash
+function aux.settings_to_hash(str,moretolerant)
+ if str and str ~= "" then
+ hash = { }
+ if moretolerant then
+ pattern_b_s:match(str)
else
- return { }
+ pattern_a_s:match(str)
end
+ return hash
+ else
+ return { }
end
+end
- local seperator = comma * space^0
- local value = lpeg.P(lbrace * lpeg.C((nobrace + nested)^0) * rbrace) + lpeg.C((nested + (1-comma))^0)
- local pattern = lpeg.Ct(value*(seperator*value)^0)
+local seperator = comma * space^0
+local value = lpeg.P(lbrace * lpeg.C((nobrace + nested)^0) * rbrace) + lpeg.C((nested + (1-comma))^0)
+local pattern = lpeg.Ct(value*(seperator*value)^0)
- -- "aap, {noot}, mies" : outer {} removes, leading spaces ignored
+-- "aap, {noot}, mies" : outer {} removes, leading spaces ignored
- function aux.settings_to_array(str)
- return pattern:match(str)
- end
+aux.settings_to_array_pattern = pattern
- local function set(t,v)
- t[#t+1] = v
+function aux.settings_to_array(str)
+ if not str or str == "" then
+ return { }
+ else
+ return pattern:match(str)
end
+end
- local value = lpeg.P(lpeg.Carg(1)*value) / set
- local pattern = value*(seperator*value)^0 * lpeg.Carg(1)
+local function set(t,v)
+ t[#t+1] = v
+end
- function aux.add_settings_to_array(t,str)
- return pattern:match(str, nil, t)
- end
+local value = lpeg.P(lpeg.Carg(1)*value) / set
+local pattern = value*(seperator*value)^0 * lpeg.Carg(1)
+function aux.add_settings_to_array(t,str)
+ return pattern:match(str, nil, t)
end
function aux.hash_to_string(h,separator,yes,no,strict,omit)
@@ -102,9 +128,9 @@ function aux.array_to_string(a,separator)
end
end
-function aux.settings_to_set(str)
- local t = { }
- for s in str:gmatch("%s*([^,]+)") do
+function aux.settings_to_set(str,t)
+ t = t or { }
+ for s in gmatch(str,"%s*([^,]+)") do
t[s] = true
end
return t
@@ -152,7 +178,7 @@ end
function aux.definetable(target) -- defines undefined tables
local composed, t = nil, { }
- for name in target:gmatch("([^%.]+)") do
+ for name in gmatch(target,"([^%.]+)") do
if composed then
composed = composed .. "." .. name
else
@@ -165,7 +191,7 @@ end
function aux.accesstable(target)
local t = _G
- for name in target:gmatch("([^%.]+)") do
+ for name in gmatch(target,"([^%.]+)") do
t = t[name]
end
return t
diff --git a/tex/context/base/l-boolean.lua b/tex/context/base/l-boolean.lua
index 1542238c4..c8c919eda 100644
--- a/tex/context/base/l-boolean.lua
+++ b/tex/context/base/l-boolean.lua
@@ -1,11 +1,14 @@
--- filename : l-boolean.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-boolean'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-boolean'] = 1.001
-if not boolean then boolean = { } end
+boolean = boolean or { }
+
+local type, tonumber = type, tonumber
function boolean.tonumber(b)
if b then return 1 else return 0 end
diff --git a/tex/context/base/l-dimen.lua b/tex/context/base/l-dimen.lua
index 103cb2d88..32becb276 100644
--- a/tex/context/base/l-dimen.lua
+++ b/tex/context/base/l-dimen.lua
@@ -15,6 +15,8 @@ done by using the conversion factors collected in the following
table.
--ldx]]--
+local format, type = string.format, type
+
local dimenfactors = {
["pt"] = 1/65536,
["in"] = ( 100/ 7227)/65536,
@@ -39,7 +41,7 @@ local function todimen(n,unit,fmt)
return n
else
unit = unit or 'pt'
- return (fmt or "%.5f%s"):format(n*dimenfactors[unit],unit)
+ return format(fmt or "%.5f%s",n*dimenfactors[unit],unit)
end
end
@@ -73,10 +75,10 @@ a number and optionally a unit. When no unit is given a constant
capture takes place.
--ldx]]--
-local amount = lpeg.S("+-")^0 * lpeg.R("09")^0 * (lpeg.P(".") * lpeg.R("09")^1)^0
-local unit = lpeg.R("az")^1 / dimenfactors -- produces a capture
+local amount = (lpeg.S("+-")^0 * lpeg.R("09")^0 * lpeg.P(".")^0 * lpeg.R("09")^0) + lpeg.Cc("0")
+local unit = lpeg.R("az")^1
-local pattern = lpeg.C(amount) * (unit^1 + lpeg.Cc(1))
+local pattern = amount/tonumber * (unit^1/dimenfactors + lpeg.Cc(1)) -- tonumber is new
--[[ldx--
We use a metatable to intercept errors. When no key is found in
@@ -96,6 +98,7 @@ function string:todimen()
return self
else
local value, unit = pattern:match(self)
+ print(value,unit)
return value/unit
end
end
@@ -260,7 +263,7 @@ yet be available.
--ldx]]--
function dimensions.texify()
- local fti, fc = fonts and fonts.tfm and fonts.tfm.id, font and font.current
+ local fti, fc = fonts and fonts.ids and fonts.ids, font and font.current
if fti and fc then
dimenfactors["ex"] = function() return fti[fc()].ex_height end
dimenfactors["em"] = function() return fti[fc()].quad end
diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua
index 0a174e18a..5a726303f 100644
--- a/tex/context/base/l-dir.lua
+++ b/tex/context/base/l-dir.lua
@@ -1,202 +1,203 @@
--- filename : l-dir.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-dir'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-dir'] = 1.001
+local type = type
+local find, gmatch = string.find, string.gmatch
-dir = { }
+dir = dir or { }
-- optimizing for no string.find (*) does not save time
-if lfs then do
+local attributes = lfs.attributes
+local walkdir = lfs.dir
- local attributes = lfs.attributes
- local walkdir = lfs.dir
-
- local function glob_pattern(path,patt,recurse,action)
- local ok, scanner
- if path == "/" then
- ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
- else
- ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
- end
- if ok and type(scanner) == "function" then
- if not path:find("/$") then path = path .. '/' end
- for name in scanner do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if full:find(patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- glob_pattern(full,patt,recurse,action)
+local function glob_pattern(path,patt,recurse,action)
+ local ok, scanner
+ if path == "/" then
+ ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe
+ else
+ ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe
+ end
+ if ok and type(scanner) == "function" then
+ if not find(path,"/$") then path = path .. '/' end
+ for name in scanner do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ glob_pattern(full,patt,recurse,action)
end
end
end
+end
- dir.glob_pattern = glob_pattern
+dir.glob_pattern = glob_pattern
- local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
+local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
- local pattern = Ct {
- [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
- [2] = C(((1-S("*?/"))^0 * P("/"))^0),
- [3] = C(P(1)^0)
- }
+local pattern = Ct {
+ [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3),
+ [2] = C(((1-S("*?/"))^0 * P("/"))^0),
+ [3] = C(P(1)^0)
+}
- local filter = Cs ( (
- P("**") / ".*" +
- P("*") / "[^/]*" +
- P("?") / "[^/]" +
- P(".") / "%%." +
- P("+") / "%%+" +
- P("-") / "%%-" +
- P(1)
- )^0 )
+local filter = Cs ( (
+ P("**") / ".*" +
+ P("*") / "[^/]*" +
+ P("?") / "[^/]" +
+ P(".") / "%%." +
+ P("+") / "%%+" +
+ P("-") / "%%-" +
+ P(1)
+)^0 )
- local function glob(str,t)
- if type(str) == "table" then
- local t = t or { }
- for _, s in ipairs(str) do
- glob(s,t)
- end
- return t
- elseif lfs.isfile(str) then
+local function glob(str,t)
+ if type(str) == "table" then
+ local t = t or { }
+ for s=1,#str do
+ glob(str[s],t)
+ end
+ return t
+ elseif lfs.isfile(str) then
+ local t = t or { }
+ t[#t+1] = str
+ return t
+ else
+ local split = pattern:match(str)
+ if split then
local t = t or { }
- t[#t+1] = str
+ local action = action or function(name) t[#t+1] = name end
+ local root, path, base = split[1], split[2], split[3]
+ local recurse = find(base,"%*%*")
+ local start = root .. path
+ local result = filter:match(start .. base)
+ glob_pattern(start,result,recurse,action)
return t
else
- local split = pattern:match(str)
- if split then
- local t = t or { }
- local action = action or function(name) t[#t+1] = name end
- local root, path, base = split[1], split[2], split[3]
- local recurse = base:find("%*%*")
- local start = root .. path
- local result = filter:match(start .. base)
- glob_pattern(start,result,recurse,action)
- return t
- else
- return { }
- end
+ return { }
end
end
+end
- dir.glob = glob
+dir.glob = glob
- --~ list = dir.glob("**/*.tif")
- --~ list = dir.glob("/**/*.tif")
- --~ list = dir.glob("./**/*.tif")
- --~ list = dir.glob("oeps/**/*.tif")
- --~ list = dir.glob("/oeps/**/*.tif")
+--~ list = dir.glob("**/*.tif")
+--~ list = dir.glob("/**/*.tif")
+--~ list = dir.glob("./**/*.tif")
+--~ list = dir.glob("oeps/**/*.tif")
+--~ list = dir.glob("/oeps/**/*.tif")
- local function globfiles(path,recurse,func,files) -- func == pattern or function
- if type(func) == "string" then
- local s = func -- alas, we need this indirect way
- func = function(name) return name:find(s) end
- end
- files = files or { }
- for name in walkdir(path) do
- if name:find("^%.") then
- --- skip
- else
- local mode = attributes(name,'mode')
- if mode == "directory" then
- if recurse then
- globfiles(path .. "/" .. name,recurse,func,files)
- end
- elseif mode == "file" then
- if func then
- if func(name) then
- files[#files+1] = path .. "/" .. name
- end
- else
+local function globfiles(path,recurse,func,files) -- func == pattern or function
+ if type(func) == "string" then
+ local s = func -- alas, we need this indirect way
+ func = function(name) return find(name,s) end
+ end
+ files = files or { }
+ for name in walkdir(path) do
+ if find(name,"^%.") then
+ --- skip
+ else
+ local mode = attributes(name,'mode')
+ if mode == "directory" then
+ if recurse then
+ globfiles(path .. "/" .. name,recurse,func,files)
+ end
+ elseif mode == "file" then
+ if func then
+ if func(name) then
files[#files+1] = path .. "/" .. name
end
+ else
+ files[#files+1] = path .. "/" .. name
end
end
end
- return files
end
+ return files
+end
- dir.globfiles = globfiles
+dir.globfiles = globfiles
- -- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
- -- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
- -- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
- -- t = dir.glob("f:/minimal/tex/**/*")
- -- print(dir.ls("f:/minimal/tex/**/*"))
- -- print(dir.ls("*.tex"))
+-- t = dir.glob("c:/data/develop/context/sources/**/????-*.tex")
+-- t = dir.glob("c:/data/develop/tex/texmf/**/*.tex")
+-- t = dir.glob("c:/data/develop/context/texmf/**/*.tex")
+-- t = dir.glob("f:/minimal/tex/**/*")
+-- print(dir.ls("f:/minimal/tex/**/*"))
+-- print(dir.ls("*.tex"))
- function dir.ls(pattern)
- return table.concat(glob(pattern),"\n")
- end
+function dir.ls(pattern)
+ return table.concat(glob(pattern),"\n")
+end
- --~ mkdirs("temp")
- --~ mkdirs("a/b/c")
- --~ mkdirs(".","/a/b/c")
- --~ mkdirs("a","b","c")
+--~ mkdirs("temp")
+--~ mkdirs("a/b/c")
+--~ mkdirs(".","/a/b/c")
+--~ mkdirs("a","b","c")
- local make_indeed = true -- false
+local make_indeed = true -- false
- if string.find(os.getenv("PATH"),";") then
+if string.find(os.getenv("PATH"),";") then
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- local first, middle, last
- local drive = false
- first, middle, last = str:match("^(//)(//*)(.*)$")
+ end
+ local first, middle, last
+ local drive = false
+ first, middle, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ -- empty network path == local path
+ else
+ first, last = str:match("^(//)/*(.-)$")
if first then
- -- empty network path == local path
+ middle, last = str:match("([^/]+)/+(.-)$")
+ if middle then
+ pth = "//" .. middle
+ else
+ pth = "//" .. last
+ last = ""
+ end
else
- first, last = str:match("^(//)/*(.-)$")
+ first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
if first then
- middle, last = str:match("([^/]+)/+(.-)$")
- if middle then
- pth = "//" .. middle
- else
- pth = "//" .. last
- last = ""
- end
+ pth, drive = first .. middle, true
else
- first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$")
- if first then
- pth, drive = first .. middle, true
- else
- middle, last = str:match("^(/*)(.-)$")
- if not middle then
- last = str
- end
+ middle, last = str:match("^(/*)(.-)$")
+ if not middle then
+ last = str
end
end
end
- for s in last:gmatch("[^/]+") do
- if pth == "" then
- pth = s
- elseif drive then
- pth, drive = pth .. s, false
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ for s in gmatch(last,"[^/]+") do
+ if pth == "" then
+ pth = s
+ elseif drive then
+ pth, drive = pth .. s, false
+ else
+ pth = pth .. "/" .. s
+ end
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -210,79 +211,79 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- local first, nothing, last = str:match("^(//)(//*)(.*)$")
- if first then
- first = lfs.currentdir() .. "/"
- first = first:gsub("\\","/")
- end
- if not first then
- first, last = str:match("^(//)/*(.*)$")
- end
- if not first then
- first, last = str:match("^([a-zA-Z]:)(.*)$")
- if first and not last:find("^/") then
- local d = lfs.currentdir()
- if lfs.chdir(first) then
- first = lfs.currentdir()
- first = first:gsub("\\","/")
- end
- lfs.chdir(d)
+ function dir.expand_name(str)
+ local first, nothing, last = str:match("^(//)(//*)(.*)$")
+ if first then
+ first = lfs.currentdir() .. "/"
+ first = first:gsub("\\","/")
+ end
+ if not first then
+ first, last = str:match("^(//)/*(.*)$")
+ end
+ if not first then
+ first, last = str:match("^([a-zA-Z]:)(.*)$")
+ if first and not find(last,"^/") then
+ local d = lfs.currentdir()
+ if lfs.chdir(first) then
+ first = lfs.currentdir()
+ first = first:gsub("\\","/")
end
+ lfs.chdir(d)
end
- if not first then
- first, last = lfs.currentdir(), str
- first = first:gsub("\\","/")
- end
- last = last:gsub("//","/")
- last = last:gsub("/%./","/")
- last = last:gsub("^/*","")
- first = first:gsub("/*$","")
- if last == "" then
- return first
- else
- return first .. "/" .. last
- end
end
+ if not first then
+ first, last = lfs.currentdir(), str
+ first = first:gsub("\\","/")
+ end
+ last = last:gsub("//","/")
+ last = last:gsub("/%./","/")
+ last = last:gsub("^/*","")
+ first = first:gsub("/*$","")
+ if last == "" then
+ return first
+ else
+ return first .. "/" .. last
+ end
+ end
- else
+else
- function dir.mkdirs(...)
- local str, pth = "", ""
- for _, s in ipairs({...}) do
- if s ~= "" then
- if str ~= "" then
- str = str .. "/" .. s
- else
- str = s
- end
+ function dir.mkdirs(...)
+ local str, pth = "", ""
+ for _, s in ipairs({...}) do
+ if s ~= "" then
+ if str ~= "" then
+ str = str .. "/" .. s
+ else
+ str = s
end
end
- str = str:gsub("/+","/")
- if str:find("^/") then
- pth = "/"
- for s in str:gmatch("[^/]+") do
- local first = (pth == "/")
- if first then
- pth = pth .. s
- else
- pth = pth .. "/" .. s
- end
- if make_indeed and not first and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
- end
- else
- pth = "."
- for s in str:gmatch("[^/]+") do
+ end
+ str = str:gsub("/+","/")
+ if find(str,"^/") then
+ pth = "/"
+ for s in gmatch(str,"[^/]+") do
+ local first = (pth == "/")
+ if first then
+ pth = pth .. s
+ else
pth = pth .. "/" .. s
- if make_indeed and not lfs.isdir(pth) then
- lfs.mkdir(pth)
- end
+ end
+ if make_indeed and not first and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
+ end
+ end
+ else
+ pth = "."
+ for s in gmatch(str,"[^/]+") do
+ pth = pth .. "/" .. s
+ if make_indeed and not lfs.isdir(pth) then
+ lfs.mkdir(pth)
end
end
- return pth, (lfs.isdir(pth) == true)
end
+ return pth, (lfs.isdir(pth) == true)
+ end
--~ print(dir.mkdirs("","","a","c"))
--~ print(dir.mkdirs("a"))
@@ -292,17 +293,15 @@ if lfs then do
--~ print(dir.mkdirs("///a/b/c"))
--~ print(dir.mkdirs("a/bbb//ccc/"))
- function dir.expand_name(str)
- if not str:find("^/") then
- str = lfs.currentdir() .. "/" .. str
- end
- str = str:gsub("//","/")
- str = str:gsub("/%./","/")
- return str
+ function dir.expand_name(str)
+ if not find(str,"^/") then
+ str = lfs.currentdir() .. "/" .. str
end
-
+ str = str:gsub("//","/")
+ str = str:gsub("/%./","/")
+ return str
end
- dir.makedirs = dir.mkdirs
+end
-end end
+dir.makedirs = dir.mkdirs
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua
index ae4cd426a..0782ac676 100644
--- a/tex/context/base/l-file.lua
+++ b/tex/context/base/l-file.lua
@@ -1,23 +1,24 @@
--- filename : l-file.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-file'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-file'] = 1.001
+-- needs a cleanup
-if not file then file = { } end
+file = file or { }
local concat = table.concat
+local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
function file.removesuffix(filename)
- return (filename:gsub("%.[%a%d]+$",""))
+ return (gsub(filename,"%.[%a%d]+$",""))
end
-file.stripsuffix = file.removesuffix
-
function file.addsuffix(filename, suffix)
- if not filename:find("%.[%a%d]+$") then
+ if not find(filename,"%.[%a%d]+$") then
return filename .. "." .. suffix
else
return filename
@@ -25,23 +26,23 @@ function file.addsuffix(filename, suffix)
end
function file.replacesuffix(filename, suffix)
- return (filename:gsub("%.[%a%d]+$","")) .. "." .. suffix
+ return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
end
-function file.dirname(name)
- return name:match("^(.+)[/\\].-$") or ""
+function file.dirname(name,default)
+ return match(name,"^(.+)[/\\].-$") or (default or "")
end
function file.basename(name)
- return name:match("^.+[/\\](.-)$") or name
+ return match(name,"^.+[/\\](.-)$") or name
end
function file.nameonly(name)
- return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$",""))
+ return (gsub(match(name,"^.+[/\\](.-)$") or name,"%..*$",""))
end
function file.extname(name)
- return name:match("^.+%.([^/\\]-)$") or ""
+ return match(name,"^.+%.([^/\\]-)$") or ""
end
file.suffix = file.extname
@@ -54,40 +55,20 @@ file.suffix = file.extname
function file.join(...)
local pth = concat({...},"/")
- pth = pth:gsub("\\","/")
- local a, b = pth:match("^(.*://)(.*)$")
+ pth = gsub(pth,"\\","/")
+ local a, b = match(pth,"^(.*://)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
+ return a .. gsub(b,"//+","/")
end
- a, b = pth:match("^(//)(.*)$")
+ a, b = match(pth,"^(//)(.*)$")
if a and b then
- return a .. b:gsub("//+","/")
- end
- return (pth:gsub("//+","/"))
-end
-
-function file.is_writable(name)
- local f = io.open(name, 'w')
- if f then
- f:close()
- return true
- else
- return false
- end
-end
-
-function file.is_readable(name)
- local f = io.open(name,'r')
- if f then
- f:close()
- return true
- else
- return false
+ return a .. gsub(b,"//+","/")
end
+ return (gsub(pth,"//+","/"))
end
function file.iswritable(name)
- local a = lfs.attributes(name)
+ local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,"."))
return a and a.permissions:sub(2,2) == "w"
end
@@ -96,24 +77,18 @@ function file.isreadable(name)
return a and a.permissions:sub(1,1) == "r"
end
---~ function file.split_path(str)
---~ if str:find(';') then
---~ return str:splitchr(";")
---~ else
---~ return str:splitchr(io.pathseparator)
---~ end
---~ end
+file.is_readable = file.isreadable
+file.is_writable = file.iswritable
-- todo: lpeg
function file.split_path(str)
local t = { }
- str = str:gsub("\\", "/")
- str = str:gsub("(%a):([;/])", "%1\001%2")
- for name in str:gmatch("([^;:]+)") do
+ str = gsub(str,"\\", "/")
+ str = gsub(str,"(%a):([;/])", "%1\001%2")
+ for name in gmatch(str,"([^;:]+)") do
if name ~= "" then
- name = name:gsub("\001",":")
- t[#t+1] = name
+ t[#t+1] = gsub(name,"\001",":")
end
end
return t
@@ -124,15 +99,15 @@ function file.join_path(tab)
end
function file.collapse_path(str)
- str = str:gsub("/%./","/")
+ str = gsub(str,"/%./","/")
local n, m = 1, 1
while n > 0 or m > 0 do
- str, n = str:gsub("[^/%.]+/%.%.$","")
- str, m = str:gsub("[^/%.]+/%.%./","")
+ str, n = gsub(str,"[^/%.]+/%.%.$","")
+ str, m = gsub(str,"[^/%.]+/%.%./","")
end
- str = str:gsub("([^/])/$","%1")
- str = str:gsub("^%./","")
- str = str:gsub("/%.$","")
+ str = gsub(str,"([^/])/$","%1")
+ str = gsub(str,"^%./","")
+ str = gsub(str,"/%.$","")
if str == "" then str = "." end
return str
end
@@ -145,7 +120,7 @@ end
--~ print(file.collapse_path("a/b/c/../.."))
function file.robustname(str)
- return (str:gsub("[^%a%d%/%-%.\\]+","-"))
+ return (gsub(str,"[^%a%d%/%-%.\\]+","-"))
end
file.readdata = io.loaddata
@@ -175,8 +150,6 @@ end
--~ return pattern:match(name)
--~ end
---~ file.stripsuffix = file.removesuffix
-
--~ local pattern = (noslashes^0 * slashes)^1 * lpeg.C(noslashes^1) * -1
--~ function file.basename(name)
@@ -230,7 +203,6 @@ end
--~ end
--~ local test = file.extname
---~ local test = file.stripsuffix
--~ local test = file.basename
--~ local test = file.dirname
--~ local test = file.addsuffix
@@ -246,3 +218,41 @@ end
--~ print(7,test("def.xxx","!!!"))
--~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+
+-- also rewrite previous
+
+local letter = lpeg.R("az","AZ") + lpeg.S("_-+")
+local separator = lpeg.P("://")
+
+local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator + letter^1 * lpeg.P("/")
+local rootbased = lpeg.P("/") + letter*lpeg.P(":")
+
+-- ./name ../name /name c: :// name/name
+
+function file.is_qualified_path(filename)
+ return qualified:match(filename)
+end
+
+function file.is_rootbased_path(filename)
+ return rootbased:match(filename)
+end
+
+local slash = lpeg.S("\\/")
+local period = lpeg.P(".")
+local drive = lpeg.C(lpeg.R("az","AZ")) * lpeg.P(":")
+local path = lpeg.C(((1-slash)^0 * slash)^0)
+local suffix = period * lpeg.C(lpeg.P(1-period)^0 * lpeg.P(-1))
+local base = lpeg.C((1-suffix)^0)
+
+local pattern = (drive + lpeg.Cc("")) * (path + lpeg.Cc("")) * (base + lpeg.Cc("")) * (suffix + lpeg.Cc(""))
+
+function file.splitname(str) -- returns drive, path, base, suffix
+ return pattern:match(str)
+end
+
+-- function test(t) for k, v in pairs(t) do print(v, "=>", file.splitname(v)) end end
+--
+-- test { "c:", "c:/aa", "c:/aa/bb", "c:/aa/bb/cc", "c:/aa/bb/cc.dd", "c:/aa/bb/cc.dd.ee" }
+-- test { "c:", "c:aa", "c:aa/bb", "c:aa/bb/cc", "c:aa/bb/cc.dd", "c:aa/bb/cc.dd.ee" }
+-- test { "/aa", "/aa/bb", "/aa/bb/cc", "/aa/bb/cc.dd", "/aa/bb/cc.dd.ee" }
+-- test { "aa", "aa/bb", "aa/bb/cc", "aa/bb/cc.dd", "aa/bb/cc.dd.ee" }
diff --git a/tex/context/base/l-io.lua b/tex/context/base/l-io.lua
index 6d773c582..4b937a322 100644
--- a/tex/context/base/l-io.lua
+++ b/tex/context/base/l-io.lua
@@ -1,10 +1,12 @@
--- filename : l-io.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-io'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-io'] = 1.001
+local byte = string.byte
if string.find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator = "\\", ";"
@@ -12,8 +14,8 @@ else
io.fileseparator, io.pathseparator = "/" , ":"
end
-function io.loaddata(filename)
- local f = io.open(filename,'rb')
+function io.loaddata(filename,textmode)
+ local f = io.open(filename,(textmode and 'r') or 'rb')
if f then
local data = f:read('*all')
-- garbagecollector.check(data)
@@ -71,146 +73,83 @@ function io.noflines(f)
return n
end
-do
+local nextchar = {
+ [ 4] = function(f)
+ return f:read(1,1,1,1)
+ end,
+ [ 2] = function(f)
+ return f:read(1,1)
+ end,
+ [ 1] = function(f)
+ return f:read(1)
+ end,
+ [-2] = function(f)
+ local a, b = f:read(1,1)
+ return b, a
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ return d, c, b, a
+ end
+}
- local sb = string.byte
+function io.characters(f,n)
+ if f then
+ return nextchar[n or 1], f
+ else
+ return nil, nil
+ end
+end
- local nextchar = {
- [ 4] = function(f)
- return f:read(1,1,1,1)
- end,
- [ 2] = function(f)
- return f:read(1,1)
- end,
- [ 1] = function(f)
- return f:read(1)
- end,
- [-2] = function(f)
- local a, b = f:read(1,1)
- return b, a
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- return d, c, b, a
+local nextbyte = {
+ [4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(a), byte(b), byte(c), byte(d)
+ else
+ return nil, nil, nil, nil
end
- }
-
- function io.characters(f,n)
- if f then
- return nextchar[n or 1], f
+ end,
+ [2] = function(f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(a), byte(b)
else
return nil, nil
end
- end
-
-end
-
-do
-
- local sb = string.byte
-
---~ local nextbyte = {
---~ [4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(a), sb(b), sb(c), sb(d)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end,
---~ [2] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(a), sb(b)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [1] = function (f)
---~ local a = f:read(1)
---~ if a then
---~ return sb(a)
---~ else
---~ return nil
---~ end
---~ end,
---~ [-2] = function (f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ if b then
---~ return sb(b), sb(a)
---~ else
---~ return nil, nil
---~ end
---~ end,
---~ [-4] = function(f)
---~ local a = f:read(1)
---~ local b = f:read(1)
---~ local c = f:read(1)
---~ local d = f:read(1)
---~ if d then
---~ return sb(d), sb(c), sb(b), sb(a)
---~ else
---~ return nil, nil, nil, nil
---~ end
---~ end
---~ }
-
- local nextbyte = {
- [4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(a), sb(b), sb(c), sb(d)
- else
- return nil, nil, nil, nil
- end
- end,
- [2] = function(f)
- local a, b = f:read(1,1)
- if b then
- return sb(a), sb(b)
- else
- return nil, nil
- end
- end,
- [1] = function (f)
- local a = f:read(1)
- if a then
- return sb(a)
- else
- return nil
- end
- end,
- [-2] = function (f)
- local a, b = f:read(1,1)
- if b then
- return sb(b), sb(a)
- else
- return nil, nil
- end
- end,
- [-4] = function(f)
- local a, b, c, d = f:read(1,1,1,1)
- if d then
- return sb(d), sb(c), sb(b), sb(a)
- else
- return nil, nil, nil, nil
- end
+ end,
+ [1] = function (f)
+ local a = f:read(1)
+ if a then
+ return byte(a)
+ else
+ return nil
end
- }
-
- function io.bytes(f,n)
- if f then
- return nextbyte[n or 1], f
+ end,
+ [-2] = function (f)
+ local a, b = f:read(1,1)
+ if b then
+ return byte(b), byte(a)
else
return nil, nil
end
+ end,
+ [-4] = function(f)
+ local a, b, c, d = f:read(1,1,1,1)
+ if d then
+ return byte(d), byte(c), byte(b), byte(a)
+ else
+ return nil, nil, nil, nil
+ end
end
+}
+function io.bytes(f,n)
+ if f then
+ return nextbyte[n or 1], f
+ else
+ return nil, nil
+ end
end
function io.ask(question,default,options)
diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua
index cd61dc926..88b445717 100644
--- a/tex/context/base/l-lpeg.lua
+++ b/tex/context/base/l-lpeg.lua
@@ -1,9 +1,12 @@
--- filename : l-lpeg.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-lpeg'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-lpeg'] = 1.001
+local P, S, Ct, C, Cs, Cc = lpeg.P, lpeg.S, lpeg.Ct, lpeg.C, lpeg.Cs, lpeg.Cc
--~ l-lpeg.lua :
@@ -27,35 +30,33 @@ if not versions then versions = { } end versions['l-lpeg'] = 1.001
local hash = { }
function lpeg.anywhere(pattern) --slightly adapted from website
- return lpeg.P { lpeg.P(pattern) + 1 * lpeg.V(1) }
+ return P { P(pattern) + 1 * lpeg.V(1) }
end
function lpeg.startswith(pattern) --slightly adapted
- return lpeg.P(pattern)
+ return P(pattern)
end
---~ g = lpeg.splitter(" ",function(s) ... end) -- gmatch:lpeg = 3:2
-
function lpeg.splitter(pattern, action)
- return (((1-lpeg.P(pattern))^1)/action+1)^0
+ return (((1-P(pattern))^1)/action+1)^0
end
-- variant:
--~ local parser = lpeg.Ct(lpeg.splitat(newline))
-local crlf = lpeg.P("\r\n")
-local cr = lpeg.P("\r")
-local lf = lpeg.P("\n")
-local space = lpeg.S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
+local crlf = P("\r\n")
+local cr = P("\r")
+local lf = P("\n")
+local space = S(" \t\f\v") -- + string.char(0xc2, 0xa0) if we want utf (cf mail roberto)
local newline = crlf + cr + lf
local spacing = space^0 * newline
-local empty = spacing * lpeg.Cc("")
-local nonempty = lpeg.Cs((1-spacing)^1) * spacing^-1
+local empty = spacing * Cc("")
+local nonempty = Cs((1-spacing)^1) * spacing^-1
local content = (empty + nonempty)^1
-local capture = lpeg.Ct(content^0)
+local capture = Ct(content^0)
function string:splitlines()
return capture:match(self)
@@ -70,19 +71,32 @@ lpeg.linebyline = content -- better make a sublibrary
local splitters_s, splitters_m = { }, { }
-function lpeg.splitat(separator,single)
+local function splitat(separator,single)
local splitter = (single and splitters_s[separator]) or splitters_m[separator]
if not splitter then
- separator = lpeg.P(separator)
+ separator = P(separator)
if single then
- local other, any = lpeg.C((1 - separator)^0), lpeg.P(1)
- splitter = other * (separator * lpeg.C(any^0) + "")
+ local other, any = C((1 - separator)^0), P(1)
+ splitter = other * (separator * C(any^0) + "")
splitters_s[separator] = splitter
else
- local other = lpeg.C((1 - separator)^0)
+ local other = C((1 - separator)^0)
splitter = other * (separator * other)^0
splitters_m[separator] = splitter
end
end
return splitter
end
+
+lpeg.splitat = splitat
+
+local cache = { }
+
+function string:split(separator)
+ local c = cache[separator]
+ if not c then
+ c = Ct(splitat(separator))
+ cache[separator] = c
+ end
+ return c:match(self)
+end
diff --git a/tex/context/base/l-math.lua b/tex/context/base/l-math.lua
index 00b72dba5..bfb3d506b 100644
--- a/tex/context/base/l-math.lua
+++ b/tex/context/base/l-math.lua
@@ -1,12 +1,12 @@
--- filename : l-math.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-math'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-math'] = 1.001
-
-local floor = math.floor
+local floor, sin, cos, tan = math.floor, math.sin, math.cos, math.tan
if not math.round then
function math.round(x)
@@ -25,3 +25,17 @@ if not math.mod then
return n % m
end
end
+
+local pipi = 2*math.pi/360
+
+function math.sind(d)
+ return sin(d*pipi)
+end
+
+function math.cosd(d)
+ return cos(d*pipi)
+end
+
+function math.tand(d)
+ return tan(d*pipi)
+end
diff --git a/tex/context/base/l-md5.lua b/tex/context/base/l-md5.lua
index 4deb9bd74..8640ad54e 100644
--- a/tex/context/base/l-md5.lua
+++ b/tex/context/base/l-md5.lua
@@ -1,18 +1,72 @@
--- filename : l-md5.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-md5'] = {
+ version = 1.001,
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-md5'] = 1.001
+-- This also provides file checksums and checkers.
-if md5 then do
+local gsub, format, byte = string.gsub, string.format, string.byte
- local function convert(str,fmt)
- return (string.gsub(md5.sum(str),".",function(chr) return string.format(fmt,string.byte(chr)) end))
+local function convert(str,fmt)
+ return (gsub(md5.sum(str),".",function(chr) return format(fmt,byte(chr)) end))
+end
+
+if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
+if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
+if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+
+--~ if not md5.HEX then
+--~ local function remap(chr) return format("%02X",byte(chr)) end
+--~ function md5.HEX(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.hex then
+--~ local function remap(chr) return format("%02x",byte(chr)) end
+--~ function md5.hex(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+--~ if not md5.dec then
+--~ local function remap(chr) return format("%03i",byte(chr)) end
+--~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end
+--~ end
+
+file.needs_updating_threshold = 1
+
+function file.needs_updating(oldname,newname) -- size modification access change
+ local oldtime = lfs.attributes(oldname, modification)
+ local newtime = lfs.attributes(newname, modification)
+ if newtime >= oldtime then
+ return false
+ elseif oldtime - newtime < file.needs_updating_threshold then
+ return false
+ else
+ return true
end
+end
- if not md5.HEX then function md5.HEX(str) return convert(str,"%02X") end end
- if not md5.hex then function md5.hex(str) return convert(str,"%02x") end end
- if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end
+function file.checksum(name)
+ if md5 then
+ local data = io.loaddata(name)
+ if data then
+ return md5.HEX(data)
+ end
+ end
+ return nil
+end
+
+function file.loadchecksum(name)
+ if md5 then
+ local data = io.loaddata(name .. ".md5")
+ return data and data:gsub("%s","")
+ end
+ return nil
+end
-end end
+function file.savechecksum(name, checksum)
+ if not checksum then checksum = file.checksum(name) end
+ if checksum then
+ io.savedata(name .. ".md5",checksum)
+ return checksum
+ end
+ return nil
+end
diff --git a/tex/context/base/l-number.lua b/tex/context/base/l-number.lua
index 180b4c544..18d488a1a 100644
--- a/tex/context/base/l-number.lua
+++ b/tex/context/base/l-number.lua
@@ -1,12 +1,14 @@
--- filename : l-number.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-number'] = 1.001
+local format = string.format
-if not number then number = { } end
+number = number or { }
-- a,b,c,d,e,f = number.toset(100101)
@@ -14,8 +16,6 @@ function number.toset(n)
return (tostring(n)):match("(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)")
end
-local format = string.format
-
function number.toevenhex(n)
local s = format("%X",n)
if #s % 2 == 0 then
@@ -36,11 +36,10 @@ end
--
-- of course dedicated "(.)(.)(.)(.)" matches are even faster
-do
- local one = lpeg.C(1-lpeg.S(''))^1
+local one = lpeg.C(1-lpeg.S(''))^1
- function number.toset(n)
- return one:match(tostring(n))
- end
+function number.toset(n)
+ return one:match(tostring(n))
end
+
diff --git a/tex/context/base/l-os.lua b/tex/context/base/l-os.lua
index 1dba5262f..47b47fa4f 100644
--- a/tex/context/base/l-os.lua
+++ b/tex/context/base/l-os.lua
@@ -1,13 +1,12 @@
--- filename : l-os.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-os'] = {
+ version = 1.001,
+ comment = "companion to luat-lub.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-
---~ print(table.serialize(os.uname()))
-
-if not versions then versions = { } end versions['l-os'] = 1.001
+local find = string.find
function os.resultof(command)
return io.popen(command,"r"):read("*all")
@@ -20,7 +19,7 @@ if not os.spawn then os.spawn = os.execute end
--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
if not io.fileseparator then
- if string.find(os.getenv("PATH"),";") then
+ if find(os.getenv("PATH"),";") then
io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
else
io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
@@ -58,11 +57,10 @@ end
os.gettimeofday = os.gettimeofday or os.clock
-do
- local startuptime = os.gettimeofday()
- function os.runtime()
- return os.gettimeofday() - startuptime
- end
+local startuptime = os.gettimeofday()
+
+function os.runtime()
+ return os.gettimeofday() - startuptime
end
--~ print(os.gettimeofday()-os.time())
@@ -70,3 +68,63 @@ end
--~ print (">>",os.runtime())
--~ print(os.date("%H:%M:%S",os.gettimeofday()))
--~ print(os.date("%H:%M:%S",os.time()))
+
+os.arch = os.arch or function()
+ local a = os.resultof("uname -m") or "linux"
+ os.arch = function()
+ return a
+ end
+ return a
+end
+
+local platform
+
+function os.currentplatform(name,default)
+ if not platform then
+ local name = os.name or os.platform or name -- os.name is built in, os.platform is mine
+ if not name then
+ platform = default or "linux"
+ elseif name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+ if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
+ platform = "mswin-64"
+ else
+ platform = "mswin"
+ end
+ else
+ local architecture = os.arch()
+ if name == "linux" then
+ if find(architecture,"x86_64") then
+ platform = "linux-64"
+ elseif find(architecture,"ppc") then
+ platform = "linux-ppc"
+ else
+ platform = "linux"
+ end
+ elseif name == "macosx" then
+ if find(architecture,"i386") then
+ platform = "osx-intel"
+ else
+ platform = "osx-ppc"
+ end
+ elseif name == "sunos" then
+ if find(architecture,"sparc") then
+ platform = "solaris-sparc"
+ else -- if architecture == 'i86pc'
+ platform = "solaris-intel"
+ end
+ elseif name == "freebsd" then
+ if find(architecture,"amd64") then
+ platform = "freebsd-amd64"
+ else
+ platform = "freebsd"
+ end
+ else
+ platform = default or name
+ end
+ end
+ function os.currentplatform()
+ return platform
+ end
+ end
+ return platform
+end
diff --git a/tex/context/base/l-set.lua b/tex/context/base/l-set.lua
index 2bcf664f8..199253ee2 100644
--- a/tex/context/base/l-set.lua
+++ b/tex/context/base/l-set.lua
@@ -1,59 +1,56 @@
--- filename : l-set.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-set'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-set'] = 1.001
+set = set or { }
-if not set then set = { } end
+local nums = { }
+local tabs = { }
+local concat = table.concat
-do
+set.create = table.tohash
- local nums = { }
- local tabs = { }
- local concat = table.concat
-
- set.create = table.tohash
-
- function set.tonumber(t)
- if next(t) then
- local s = ""
- -- we could save mem by sorting, but it slows down
- for k, v in pairs(t) do
- if v then
- -- why bother about the leading space
- s = s .. " " .. k
- end
- end
- if not nums[s] then
- tabs[#tabs+1] = t
- nums[s] = #tabs
+function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
end
- return nums[s]
- else
- return 0
end
- end
-
- function set.totable(n)
- if n == 0 then
- return { }
- else
- return tabs[n] or { }
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
end
+ return nums[s]
+ else
+ return 0
end
+end
- function set.contains(n,s)
- if type(n) == "table" then
- return n[s]
- elseif n == 0 then
- return false
- else
- local t = tabs[n]
- return t and t[s]
- end
+function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
end
+end
+function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
end
--~ local c = set.create{'aap','noot','mies'}
diff --git a/tex/context/base/l-string.lua b/tex/context/base/l-string.lua
index 90af72c87..ab7d314e4 100644
--- a/tex/context/base/l-string.lua
+++ b/tex/context/base/l-string.lua
@@ -1,137 +1,31 @@
--- filename : l-string.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-string'] = 1.001
-
---~ function string.split(str, pat) -- taken from the lua wiki
---~ local t = {n = 0} -- so this table has a length field, traverse with ipairs then!
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = string.find(str, fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ table.insert(t,cap)
---~ end
---~ last_end = e+1
---~ s, e, cap = string.find(str, fpat, last_end)
---~ end
---~ if last_end<=string.len(str) then
---~ table.insert(t,(string.sub(str,last_end)))
---~ end
---~ return t
---~ end
-
---~ function string:split(pat) -- taken from the lua wiki but adapted
---~ local t = { } -- self and colon usage (faster)
---~ local fpat = "(.-)"..pat
---~ local last_end = 1
---~ local s, e, cap = self:find(fpat, 1)
---~ while s ~= nil do
---~ if s~=1 or cap~="" then
---~ t[#t+1] = cap
---~ end
---~ last_end = e+1
---~ s, e, cap = self:find(fpat, last_end)
---~ end
---~ if last_end <= #self then
---~ t[#t+1] = self:sub(last_end)
---~ end
---~ return t
---~ end
-
---~ a piece of brilliant code by Rici Lake (posted on lua list) -- only names changed
---~
---~ function string:splitter(pat)
---~ local st, g = 1, self:gmatch("()"..pat.."()")
---~ local function splitter(self)
---~ if st then
---~ local s, f = g()
---~ local rv = self:sub(st, (s or 0)-1)
---~ st = f
---~ return rv
---~ end
---~ end
---~ return splitter, self
---~ end
-
-function string:splitter(pat)
- -- by Rici Lake (posted on lua list) -- only names changed
- -- p 79 ref man: () returns position of match
- local st, g = 1, self:gmatch("()("..pat..")")
- local function strgetter(self, segs, seps, sep, cap1, ...)
- st = sep and seps + #sep
- return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
- end
- local function strsplitter(self)
- if st then return strgetter(self, st, g()) end
- end
- return strsplitter, self
-end
+if not modules then modules = { } end modules ['l-string'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-function string:split(separator)
- local t = {}
- for k in self:splitter(separator) do t[#t+1] = k end
- return t
-end
+local sub, gsub, find, match, gmatch, format, char, byte, rep = string.sub, string.gsub, string.find, string.match, string.gmatch, string.format, string.char, string.byte, string.rep
--- faster than a string:split:
+if not string.split then
-function string:splitchr(chr)
- if #self > 0 then
- local t = { }
- for s in (self..chr):gmatch("(.-)"..chr) do
- t[#t+1] = s
+ -- this will be overloaded by a faster lpeg variant
+
+ function string:split(pattern)
+ if #self > 0 then
+ local t = { }
+ for s in gmatch(self..pattern,"(.-)"..pattern) do
+ t[#t+1] = s
+ end
+ return t
+ else
+ return { }
end
- return t
- else
- return { }
end
-end
-function string.piecewise(str, pat, fnc) -- variant of split
- for k in string.splitter(str,pat) do fnc(k) end
end
---~ function string.piecewise(str, pat, fnc) -- variant of split
---~ for k in str:splitter(pat) do fnc(k) end
---~ end
-
---~ do if lpeg then
-
---~ -- this alternative is 30% faster esp when we cache them
---~ -- problem: no expressions
-
---~ splitters = { }
-
---~ function string:split(separator)
---~ if #self > 0 then
---~ local split = splitters[separator]
---~ if not split then
---~ -- based on code by Roberto
---~ local p = lpeg.P(separator)
---~ local c = lpeg.C((1-p)^0)
---~ split = lpeg.Ct(c*(p*c)^0)
---~ splitters[separator] = split
---~ end
---~ return split:match(self)
---~ else
---~ return { }
---~ end
---~ end
-
---~ string.splitchr = string.split
-
---~ function string:piecewise(separator,fnc)
---~ for _,v in pairs(self:split(separator)) do
---~ fnc(v)
---~ end
---~ end
-
---~ end end
-
local chr_to_esc = {
["%"] = "%%",
["."] = "%.",
@@ -145,20 +39,20 @@ local chr_to_esc = {
string.chr_to_esc = chr_to_esc
function string:esc() -- variant 2
- return (self:gsub("(.)",chr_to_esc))
+ return (gsub(self,"(.)",chr_to_esc))
end
function string:unquote()
- return (self:gsub("^([\"\'])(.*)%1$","%2"))
+ return (gsub(self,"^([\"\'])(.*)%1$","%2"))
end
-function string:quote()
+function string:quote() -- we could use format("%q")
return '"' .. self:unquote() .. '"'
end
function string:count(pattern) -- variant 3
local n = 0
- for _ in self:gmatch(pattern) do
+ for _ in gmatch(self,pattern) do
n = n + 1
end
return n
@@ -167,29 +61,25 @@ end
function string:limit(n,sentinel)
if #self > n then
sentinel = sentinel or " ..."
- return self:sub(1,(n-#sentinel)) .. sentinel
+ return sub(self,1,(n-#sentinel)) .. sentinel
else
return self
end
end
function string:strip()
- return (self:gsub("^%s*(.-)%s*$", "%1"))
+ return (gsub(self,"^%s*(.-)%s*$", "%1"))
end
---~ function string.strip(str) -- slightly different
---~ return (string.gsub(string.gsub(str,"^%s*(.-)%s*$","%1"),"%s+"," "))
---~ end
-
function string:is_empty()
- return not self:find("%S")
+ return not find(find,"%S")
end
function string:enhance(pattern,action)
local ok, n = true, 0
while ok do
ok = false
- self = self:gsub(pattern, function(...)
+ self = gsub(self,pattern, function(...)
ok, n = true, n + 1
return action(...)
end)
@@ -197,59 +87,19 @@ function string:enhance(pattern,action)
return self, n
end
---~ function string:enhance(pattern,action)
---~ local ok, n = 0, 0
---~ repeat
---~ self, ok = self:gsub(pattern, function(...)
---~ n = n + 1
---~ return action(...)
---~ end)
---~ until ok == 0
---~ return self, n
---~ end
-
---~ function string:to_hex()
---~ if self then
---~ return (self:gsub("(.)",function(c)
---~ return string.format("%02X",c:byte())
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
---~ function string:from_hex()
---~ if self then
---~ return (self:gsub("(..)",function(c)
---~ return string.char(tonumber(c,16))
---~ end))
---~ else
---~ return ""
---~ end
---~ end
-
-string.chr_to_hex = { }
-string.hex_to_chr = { }
+local chr_to_hex, hex_to_chr = { }, { }
for i=0,255 do
- local c, h = string.char(i), string.format("%02X",i)
- string.chr_to_hex[c], string.hex_to_chr[h] = h, c
+ local c, h = char(i), format("%02X",i)
+ chr_to_hex[c], hex_to_chr[h] = h, c
end
---~ function string:to_hex()
---~ if self then return (self:gsub("(.)",string.chr_to_hex)) else return "" end
---~ end
-
---~ function string:from_hex()
---~ if self then return (self:gsub("(..)",string.hex_to_chr)) else return "" end
---~ end
-
function string:to_hex()
- return ((self or ""):gsub("(.)",string.chr_to_hex))
+ return (gsub(self or "","(.)",chr_to_hex))
end
function string:from_hex()
- return ((self or ""):gsub("(..)",string.hex_to_chr))
+ return (gsub(self or "","(..)",hex_to_chr))
end
if not string.characters then
@@ -263,7 +113,7 @@ if not string.characters then
end
local function nextbyte(str, index)
index = index + 1
- return (index <= #str) and index or nil, string.byte(str:sub(index,index))
+ return (index <= #str) and index or nil, byte(str:sub(index,index))
end
function string:bytes()
return nextbyte, self, 0
@@ -271,9 +121,7 @@ if not string.characters then
end
---~ function string:padd(n,chr)
---~ return self .. self.rep(chr or " ",n-#self)
---~ end
+-- we can use format for this (neg n)
function string:rpadd(n,chr)
local m = n-#self
@@ -295,8 +143,8 @@ end
string.padd = string.rpadd
-function is_number(str)
- return str:find("^[%-%+]?[%d]-%.?[%d+]$") == 1
+function is_number(str) -- tonumber
+ return find(str,"^[%-%+]?[%d]-%.?[%d+]$") == 1
end
--~ print(is_number("1"))
@@ -308,9 +156,9 @@ end
--~ print(is_number("+.1"))
function string:split_settings() -- no {} handling, see l-aux for lpeg variant
- if self:find("=") then
+ if find(self,"=") then
local t = { }
- for k,v in self:gmatch("(%a+)=([^%,]*)") do
+ for k,v in gmatch(self,"(%a+)=([^%,]*)") do
t[k] = v
end
return t
@@ -332,13 +180,49 @@ local patterns_escapes = {
}
function string:pattesc()
- return (self:gsub(".",patterns_escapes))
+ return (gsub(self,".",patterns_escapes))
end
function string:tohash()
local t = { }
- for s in self:gmatch("([^, ]+)") do -- lpeg
+ for s in gmatch(self,"([^, ]+)") do -- lpeg
t[s] = true
end
return t
end
+
+local pattern = lpeg.Ct(lpeg.C(1)^0)
+
+function string:totable()
+ return pattern:match(self)
+end
+
+--~ for _, str in ipairs {
+--~ "1234567123456712345671234567",
+--~ "a\tb\tc",
+--~ "aa\tbb\tcc",
+--~ "aaa\tbbb\tccc",
+--~ "aaaa\tbbbb\tcccc",
+--~ "aaaaa\tbbbbb\tccccc",
+--~ "aaaaaa\tbbbbbb\tcccccc",
+--~ } do print(string.tabtospace(str)) end
+
+function string.tabtospace(str,tab)
+ -- we don't handle embedded newlines
+ while true do
+ local s = find(str,"\t")
+ if s then
+ if not tab then tab = 7 end -- only when found
+ local d = tab-(s-1)%tab
+ if d > 0 then
+ str = gsub(str,"\t",rep(" ",d),1)
+ else
+ str = gsub(str,"\t","",1)
+ end
+ else
+ break
+ end
+ end
+ return str
+end
+
diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua
index 23d4bed63..bfe33ff85 100644
--- a/tex/context/base/l-table.lua
+++ b/tex/context/base/l-table.lua
@@ -1,22 +1,22 @@
--- filename : l-table.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['l-table'] = 1.001
+if not modules then modules = { } end modules ['l-table'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
table.join = table.concat
local concat, sort, insert, remove = table.concat, table.sort, table.insert, table.remove
-local format = string.format
+local format, find, gsub, lower, dump = string.format, string.find, string.gsub, string.lower, string.dump
local getmetatable, setmetatable = getmetatable, setmetatable
-local pairs, ipairs, type, next, tostring = pairs, ipairs, type, next, tostring
+local type, next, tostring, ipairs = type, next, tostring, ipairs
function table.strip(tab)
local lst = { }
for i=1,#tab do
- local s = tab[i]:gsub("^%s*(.-)%s*$","%1")
+ local s = gsub(tab[i],"^%s*(.-)%s*$","%1")
if s == "" then
-- skip this one
else
@@ -28,7 +28,7 @@ end
local function sortedkeys(tab)
local srt, kind = { }, 0 -- 0=unknown 1=string, 2=number 3=mixed
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
if kind == 3 then
-- no further check
@@ -55,7 +55,7 @@ end
local function sortedhashkeys(tab) -- fast one
local srt = { }
- for key,_ in pairs(tab) do
+ for key,_ in next, tab do
srt[#srt+1] = key
end
sort(srt)
@@ -65,14 +65,25 @@ end
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
+function table.sortedpairs(t)
+ local s = sortedhashkeys(t) -- maybe just sortedkeys
+ local n = 0
+ local function kv(s)
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
+ return kv, s
+end
+
function table.append(t, list)
- for _,v in pairs(list) do
+ for _,v in next, list do
insert(t,v)
end
end
function table.prepend(t, list)
- for k,v in pairs(list) do
+ for k,v in next, list do
insert(t,k,v)
end
end
@@ -81,7 +92,7 @@ function table.merge(t, ...) -- first one is target
t = t or {}
local lst = {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
t[k] = v
end
end
@@ -91,7 +102,7 @@ end
function table.merged(...)
local tmp, lst = { }, {...}
for i=1,#lst do
- for k, v in pairs(lst[i]) do
+ for k, v in next, lst[i] do
tmp[k] = v
end
end
@@ -123,13 +134,14 @@ end
local function fastcopy(old) -- fast one
if old then
local new = { }
- for k,v in pairs(old) do
+ for k,v in next, old do
if type(v) == "table" then
new[k] = fastcopy(v) -- was just table.copy
else
new[k] = v
end
end
+ -- optional second arg
local mt = getmetatable(old)
if mt then
setmetatable(new,mt)
@@ -146,7 +158,7 @@ local function copy(t, tables) -- taken from lua wiki, slightly adapted
if not tables[t] then
tables[t] = tcopy
end
- for i,v in pairs(t) do -- brrr, what happens with sparse indexed
+ for i,v in next, t do -- brrr, what happens with sparse indexed
if type(i) == "table" then
if tables[i] then
i = tables[i]
@@ -179,7 +191,7 @@ function table.sub(t,i,j)
end
function table.replace(a,b)
- for k,v in pairs(b) do
+ for k,v in next, b do
a[k] = v
end
end
@@ -201,16 +213,18 @@ end
function table.tohash(t,value)
local h = { }
- if value == nil then value = true end
- for _, v in pairs(t) do -- no ipairs here
- h[v] = value
+ if t then
+ if value == nil then value = true end
+ for _, v in next, t do -- no ipairs here
+ h[v] = value
+ end
end
return h
end
function table.fromhash(t)
local h = { }
- for k, v in pairs(t) do -- no ipairs here
+ for k, v in next, t do -- no ipairs here
if v then h[#h+1] = k end
end
return h
@@ -234,24 +248,10 @@ local reserved = table.tohash { -- intercept a language flaw, no reserved words
'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while',
}
-local function key(k)
- if type(k) == "number" then -- or k:find("^%d+$") then
- if hexify then
- return ("[0x%04X]"):format(k)
- else
- return "["..k.."]"
- end
- elseif noquotes and not reserved[k] and k:find("^%a[%a%d%_]*$") then
- return k
- else
- return '["'..k..'"]'
- end
-end
-
local function simple_table(t)
if #t > 0 then
local n = 0
- for _,v in pairs(t) do
+ for _,v in next, t do
n = n + 1
end
if n == #t then
@@ -261,14 +261,14 @@ local function simple_table(t)
local tv = type(v)
if tv == "number" then
if hexify then
- tt[#tt+1] = ("0x%04X"):format(v)
+ tt[#tt+1] = format("0x%04X",v)
else
- tt[#tt+1] = tostring(v)
+ tt[#tt+1] = tostring(v) -- tostring not needed
end
elseif tv == "boolean" then
tt[#tt+1] = tostring(v)
elseif tv == "string" then
- tt[#tt+1] = ("%q"):format(v)
+ tt[#tt+1] = format("%q",v)
else
tt = nil
break
@@ -280,21 +280,40 @@ local function simple_table(t)
return nil
end
+-- Because this is a core function of mkiv I moved some function calls
+-- inline.
+--
+-- twice as fast in a test:
+--
+-- local propername = lpeg.P(lpeg.R("AZ","az","__") * lpeg.R("09","AZ","az", "__")^0 * lpeg.P(-1) )
+
local function do_serialize(root,name,depth,level,indexed)
if level > 0 then
depth = depth .. " "
if indexed then
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
elseif name then
- handle(("%s%s={"):format(depth,key(name)))
+ --~ handle(format("%s%s={",depth,key(name)))
+ if type(name) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s[0x%04X]={",depth,name))
+ else
+ handle(format("%s[%s]={",depth,name))
+ end
+ elseif noquotes and not reserved[name] and find(name,"^%a[%w%_]*$") then
+ handle(format("%s%s={",depth,name))
+ else
+ handle(format("%s[%q]={",depth,name))
+ end
else
- handle(("%s{"):format(depth))
+ handle(format("%s{",depth))
end
end
if root and next(root) then
local first, last = nil, 0 -- #root cannot be trusted here
if compact then
- for k,v in ipairs(root) do -- NOT: for k=1,#root do (we need to quit at nil)
+ -- NOT: for k=1,#root do (we need to quit at nil)
+ for k,v in ipairs(root) do -- can we use next?
if not first then first = k end
last = last + 1
end
@@ -303,30 +322,30 @@ local function do_serialize(root,name,depth,level,indexed)
for i=1,#sk do
local k = sk[i]
local v = root[k]
---~ if v == root then
- -- circular
---~ else
+ --~ if v == root then
+ -- circular
+ --~ else
local t = type(v)
if compact and first and type(k) == "number" and k >= first and k <= last then
if t == "number" then
if hexify then
- handle(("%s 0x%04X,"):format(depth,v))
+ handle(format("%s 0x%04X,",depth,v))
else
- handle(("%s %s,"):format(depth,v))
+ handle(format("%s %s,",depth,v))
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s,"):format(depth,v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ handle(format("%s %s,",depth,v))
else
- handle(("%s %q,"):format(depth,v))
+ handle(format("%s %q,",depth,v))
end
elseif t == "table" then
if not next(v) then
- handle(("%s {},"):format(depth))
- elseif inline then
+ handle(format("%s {},",depth))
+ elseif inline then -- and #t > 0
local st = simple_table(v)
if st then
- handle(("%s { %s },"):format(depth,concat(st,", ")))
+ handle(format("%s { %s },",depth,concat(st,", ")))
else
do_serialize(v,k,depth,level+1,true)
end
@@ -334,39 +353,102 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1,true)
end
elseif t == "boolean" then
- handle(("%s %s,"):format(depth,tostring(v)))
+ handle(format("%s %s,",depth,tostring(v)))
elseif t == "function" then
if functions then
- handle(('%s loadstring(%q),'):format(depth,v:dump()))
+ handle(format('%s loadstring(%q),',depth,dump(v)))
else
- handle(('%s "function",'):format(depth))
+ handle(format('%s "function",',depth))
end
else
- handle(("%s %q,"):format(depth,tostring(v)))
+ handle(format("%s %q,",depth,tostring(v)))
end
elseif k == "__p__" then -- parent
if false then
- handle(("%s __p__=nil,"):format(depth))
+ handle(format("%s __p__=nil,",depth))
end
elseif t == "number" then
- if hexify then
- handle(("%s %s=0x%04X,"):format(depth,key(k),v))
+ --~ if hexify then
+ --~ handle(format("%s %s=0x%04X,",depth,key(k),v))
+ --~ else
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ --~ end
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ if hexify then
+ handle(format("%s %s=0x%04X,",depth,k,v))
+ else
+ handle(format("%s %s=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if hexify then
+ handle(format("%s [%q]=0x%04X,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
end
elseif t == "string" then
- if reduce and (v:find("^[%-%+]?[%d]-%.?[%d+]$") == 1) then
- handle(("%s %s=%s,"):format(depth,key(k),v))
+ if reduce and (find(v,"^[%-%+]?[%d]-%.?[%d+]$") == 1) then
+ --~ handle(format("%s %s=%s,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,v))
+ else
+ handle(format("%s [%s]=%s,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,v))
+ else
+ handle(format("%s [%q]=%s,",depth,k,v))
+ end
else
- handle(("%s %s=%q,"):format(depth,key(k),v))
+ --~ handle(format("%s %s=%q,",depth,key(k),v))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,v))
+ else
+ handle(format("%s [%s]=%q,",depth,k,v))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,v))
+ else
+ handle(format("%s [%q]=%q,",depth,k,v))
+ end
end
elseif t == "table" then
if not next(v) then
- handle(("%s %s={},"):format(depth,key(k)))
+ --~ handle(format("%s %s={},",depth,key(k)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={},",depth,k))
+ else
+ handle(format("%s [%s]={},",depth,k))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={},",depth,k))
+ else
+ handle(format("%s [%q]={},",depth,k))
+ end
elseif inline then
local st = simple_table(v)
if st then
- handle(("%s %s={ %s },"):format(depth,key(k),concat(st,", ")))
+ --~ handle(format("%s %s={ %s },",depth,key(k),concat(st,", ")))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
+ else
+ handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
+ end
else
do_serialize(v,k,depth,level+1)
end
@@ -374,25 +456,58 @@ local function do_serialize(root,name,depth,level,indexed)
do_serialize(v,k,depth,level+1)
end
elseif t == "boolean" then
- handle(("%s %s=%s,"):format(depth,key(k),tostring(v)))
+ --~ handle(format("%s %s=%s,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%s,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%s,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%s,",depth,k,tostring(v)))
+ end
elseif t == "function" then
if functions then
- handle(('%s %s=loadstring(%q),'):format(depth,key(k),v:dump()))
- else
- handle(('%s %s="function",'):format(depth,key(k)))
+ --~ handle(format('%s %s=loadstring(%q),',depth,key(k),dump(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%s]=loadstring(%q),",depth,k,dump(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=loadstring(%q),",depth,k,dump(v)))
+ else
+ handle(format("%s [%q]=loadstring(%q),",depth,k,dump(v)))
+ end
end
else
- handle(("%s %s=%q,"):format(depth,key(k),tostring(v)))
- -- handle(('%s %s=loadstring(%q),'):format(depth,key(k),string.dump(function() return v end)))
+ --~ handle(format("%s %s=%q,",depth,key(k),tostring(v)))
+ if type(k) == "number" then -- or find(k,"^%d+$") then
+ if hexify then
+ handle(format("%s [0x%04X]=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%s]=%q,",depth,k,tostring(v)))
+ end
+ elseif noquotes and not reserved[k] and find(k,"^%a[%w%_]*$") then
+ handle(format("%s %s=%q,",depth,k,tostring(v)))
+ else
+ handle(format("%s [%q]=%q,",depth,k,tostring(v)))
+ end
end
---~ end
+ --~ end
end
end
if level > 0 then
- handle(("%s},"):format(depth))
+ handle(format("%s},",depth))
end
end
+-- replacing handle by a direct t[#t+1] = ... (plus test) is not much
+-- faster (0.03 on 1.00 for zapfino.tma)
+
local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
noquotes = _noquotes
hexify = _hexify
@@ -410,7 +525,7 @@ local function serialize(root,name,_handle,_reduce,_noquotes,_hexify)
end
elseif tname == "number" then
if hexify then
- handle(("[0x%04X]={"):format(name))
+ handle(format("[0x%04X]={",name))
else
handle("[" .. name .. "]={")
end
@@ -561,14 +676,18 @@ function table.insert_after_value(t,value,str)
end
end
-function table.are_equal(a,b,n,m)
+local function are_equal(a,b,n,m) -- indexed
if #a == #b then
n = n or 1
m = m or #a
for i=n,m do
local ai, bi = a[i], b[i]
- if (ai==bi) or (type(ai)=="table" and type(bi)=="table" and table.are_equal(ai,bi)) then
- -- continue
+ if ai==bi then
+ -- same
+ elseif type(ai)=="table" and type(bi)=="table" then
+ if not are_equal(ai,bi) then
+ return false
+ end
else
return false
end
@@ -579,9 +698,30 @@ function table.are_equal(a,b,n,m)
end
end
+local function identical(a,b) -- assumes same structure
+ for ka, va in next, a do
+ local vb = b[k]
+ if va == vb then
+ -- same
+ elseif type(va) == "table" and type(vb) == "table" then
+ if not identical(va,vb) then
+ return false
+ end
+ else
+ return false
+ end
+ end
+ return true
+end
+
+table.are_equal = are_equal
+table.identical = identical
+
+-- maybe also make a combined one
+
function table.compact(t)
if t then
- for k,v in pairs(t) do
+ for k,v in next, t do
if not next(v) then
t[k] = nil
end
@@ -610,7 +750,7 @@ end
function table.swapped(t)
local s = { }
- for k, v in pairs(t) do
+ for k, v in next, t do
s[v] = k
end
return s
@@ -632,14 +772,14 @@ end
function table.hexed(t,seperator)
local tt = { }
- for i=1,#t do tt[i] = ("0x%04X"):format(t[i]) end
+ for i=1,#t do tt[i] = format("0x%04X",t[i]) end
return concat(tt,seperator or " ")
end
function table.reverse_hash(h)
local r = { }
- for k,v in pairs(h) do
- r[v] = (k:gsub(" ","")):lower()
+ for k,v in next, h do
+ r[v] = lower(gsub(k," ",""))
end
return r
end
@@ -653,3 +793,19 @@ function table.reverse(t)
end
return tt
end
+
+--~ function table.keys(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return k
+--~ end
+
+--~ function table.keys_as_string(t)
+--~ local k = { }
+--~ for k,_ in next, t do
+--~ k[#k+1] = k
+--~ end
+--~ return concat(k,"")
+--~ end
diff --git a/tex/context/base/l-unicode.lua b/tex/context/base/l-unicode.lua
index ebd67db1c..124a1e240 100644
--- a/tex/context/base/l-unicode.lua
+++ b/tex/context/base/l-unicode.lua
@@ -1,14 +1,17 @@
--- filename : l-unicode.lua
--- comment : split off from luat-inp
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-unicode'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+utf = utf or unicode.utf8
-if not versions then versions = { } end versions['l-unicode'] = 1.001
-if not unicode then unicode = { } end
+local concat, utfchar, utfgsub = table.concat, utf.char, utf.gsub
+local char, byte, find, bytepairs = string.char, string.byte, string.find, string.bytepairs
-local concat, utfchar, utfgsub = table.concat, unicode.utf8.char, unicode.utf8.gsub
-local char, byte = string.char, string.byte
+unicode = unicode or { }
-- 0 EF BB BF UTF-8
-- 1 FF FE UTF-16-little-endian
@@ -29,17 +32,17 @@ function unicode.utftype(f) -- \000 fails !
if not str then
f:seek('set')
return 0
- elseif str:find("^%z%z\254\255") then
+ elseif find(str,"^%z%z\254\255") then
return 4
- elseif str:find("^\255\254%z%z") then
+ elseif find(str,"^\255\254%z%z") then
return 3
- elseif str:find("^\254\255") then
+ elseif find(str,"^\254\255") then
f:seek('set',2)
return 2
- elseif str:find("^\255\254") then
+ elseif find(str,"^\255\254") then
f:seek('set',2)
return 1
- elseif str:find("^\239\187\191") then
+ elseif find(str,"^\239\187\191") then
f:seek('set',3)
return 0
else
@@ -67,7 +70,7 @@ function unicode.utf16_to_utf8(str, endian) -- maybe a gsub is faster or an lpeg
p = 0
end
end
- for l,r in str:bytepairs() do
+ for l,r in bytepairs(str) do
if r then
if endian then
n = l*256 + r
@@ -111,7 +114,7 @@ function unicode.utf32_to_utf8(str, endian)
p = 0
end
end
- for a,b in str:bytepairs() do
+ for a,b in bytepairs(str) do
if a and b then
if m < 0 then
if endian then
@@ -138,28 +141,32 @@ function unicode.utf32_to_utf8(str, endian)
return result
end
+local function little(c)
+ local b = byte(c) -- b = c:byte()
+ if b < 0x10000 then
+ return char(b%256,b/256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1%256,b1/256,b2%256,b2/256)
+ end
+end
+
+local function big(c)
+ local b = byte(c)
+ if b < 0x10000 then
+ return char(b/256,b%256)
+ else
+ b = b - 0x10000
+ local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
+ return char(b1/256,b1%256,b2/256,b2%256)
+ end
+end
+
function unicode.utf8_to_utf16(str,littleendian)
if littleendian then
- return char(255,254) .. utfgsub(str,".",function(c)
- local b = byte(c) -- b = c:byte()
- if b < 0x10000 then
- return char(b%256,b/256)
- else
- b = b - 0x10000
- local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
- return char(b1%256,b1/256,b2%256,b2/256)
- end
- end)
+ return char(255,254) .. utfgsub(str,".",little)
else
- return char(254,255) .. utfgsub(str,".",function(c)
- local b = byte(c)
- if b < 0x10000 then
- return char(b/256,b%256)
- else
- b = b - 0x10000
- local b1, b2 = b/1024 + 0xD800, b%1024 + 0xDC00
- return char(b1/256,b1%256,b2/256,b2%256)
- end
- end)
+ return char(254,255) .. utfgsub(str,".",big)
end
end
diff --git a/tex/context/base/l-url.lua b/tex/context/base/l-url.lua
index 3bb2b1f11..097c94467 100644
--- a/tex/context/base/l-url.lua
+++ b/tex/context/base/l-url.lua
@@ -1,10 +1,13 @@
--- filename : l-url.lua
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-url'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-url'] = 1.001
-if not url then url = { } end
+local char, gmatch = string.char, string.gmatch
+local tonumber, type = tonumber, type
-- from the spec (on the web):
--
@@ -16,29 +19,28 @@ if not url then url = { } end
-- / \ / \
-- urn:example:animal:ferret:nose
-do
+url = url or { }
- local function tochar(s)
- return string.char(tonumber(s,16))
- end
+local function tochar(s)
+ return char(tonumber(s,16))
+end
- local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
+local colon, qmark, hash, slash, percent, endofstring = lpeg.P(":"), lpeg.P("?"), lpeg.P("#"), lpeg.P("/"), lpeg.P("%"), lpeg.P(-1)
- local hexdigit = lpeg.R("09","AF","af")
- local escaped = percent * lpeg.C(hexdigit * hexdigit) / tochar
+local hexdigit = lpeg.R("09","AF","af")
+local plus = lpeg.P("+")
+local escaped = (plus / " ") + (percent * lpeg.C(hexdigit * hexdigit) / tochar)
- local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
- local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
- local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
- local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
- local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
+local scheme = lpeg.Cs((escaped+(1-colon-slash-qmark-hash))^0) * colon + lpeg.Cc("")
+local authority = slash * slash * lpeg.Cs((escaped+(1- slash-qmark-hash))^0) + lpeg.Cc("")
+local path = slash * lpeg.Cs((escaped+(1- qmark-hash))^0) + lpeg.Cc("")
+local query = qmark * lpeg.Cs((escaped+(1- hash))^0) + lpeg.Cc("")
+local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0) + lpeg.Cc("")
- local parser = lpeg.Ct(scheme * authority * path * query * fragment)
-
- function url.split(str)
- return (type(str) == "string" and parser:match(str)) or str
- end
+local parser = lpeg.Ct(scheme * authority * path * query * fragment)
+function url.split(str)
+ return (type(str) == "string" and parser:match(str)) or str
end
function url.hashed(str)
@@ -61,7 +63,7 @@ end
function url.query(str)
if type(str) == "string" then
local t = { }
- for k, v in str:gmatch("([^&=]*)=([^&=]*)") do
+ for k, v in gmatch(str,"([^&=]*)=([^&=]*)") do
t[k] = v
end
return t
@@ -76,12 +78,12 @@ end
--~ print(url.filename("file:///etc/test.txt"))
--~ print(url.filename("/oeps.txt"))
--- from the spec on the web (sort of):
+--~ from the spec on the web (sort of):
--~
--~ function test(str)
--~ print(table.serialize(url.hashed(str)))
--~ end
----~
+--~
--~ test("%56pass%20words")
--~ test("file:///c:/oeps.txt")
--~ test("file:///c|/oeps.txt")
diff --git a/tex/context/base/l-utils.lua b/tex/context/base/l-utils.lua
index fa8e31ba8..8d531711f 100644
--- a/tex/context/base/l-utils.lua
+++ b/tex/context/base/l-utils.lua
@@ -1,10 +1,12 @@
--- filename : l-utils.lua
--- comment : split off from luat-lib
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['l-utils'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['l-utils'] = 1.001
+-- hm, quite unreadable
if not utils then utils = { } end
if not utils.merger then utils.merger = { } end
@@ -69,24 +71,52 @@ function utils.merger._self_swap_(data,code)
end
end
+--~ stripper:
+--~
+--~ data = string.gsub(data,"%-%-~[^\n]*\n","")
+--~ data = string.gsub(data,"\n\n+","\n")
+
function utils.merger._self_libs_(libs,list)
- local result, f = { }, nil
+ local result, f, frozen = { }, nil, false
+ result[#result+1] = "\n"
if type(libs) == 'string' then libs = { libs } end
if type(list) == 'string' then list = { list } end
+ local foundpath = nil
for _, lib in ipairs(libs) do
for _, pth in ipairs(list) do
- local name = string.gsub(pth .. "/" .. lib,"\\","/")
- f = io.open(name)
- if f then
- utils.report("merging library %s",name)
- result[#result+1] = f:read("*all")
- f:close()
- list = { pth } -- speed up the search
- break
+ pth = string.gsub(pth,"\\","/") -- file.clean_path
+ utils.report("checking library path %s",pth)
+ local name = pth .. "/" .. lib
+ if lfs.isfile(name) then
+ foundpath = pth
+ end
+ end
+ if foundpath then break end
+ end
+ if foundpath then
+ utils.report("using library path %s",foundpath)
+ local right, wrong = { }, { }
+ for _, lib in ipairs(libs) do
+ local fullname = foundpath .. "/" .. lib
+ if lfs.isfile(fullname) then
+ -- right[#right+1] = lib
+ utils.report("merging library %s",fullname)
+ result[#result+1] = "do -- create closure to overcome 200 locals limit"
+ result[#result+1] = io.loaddata(fullname,true)
+ result[#result+1] = "end -- of closure"
else
- utils.report("no library %s",name)
+ -- wrong[#wrong+1] = lib
+ utils.report("no library %s",fullname)
end
end
+ if #right > 0 then
+ utils.report("merged libraries: %s",table.concat(right," "))
+ end
+ if #wrong > 0 then
+ utils.report("skipped libraries: %s",table.concat(wrong," "))
+ end
+ else
+ utils.report("no valid library path found")
end
return table.concat(result, "\n\n")
end
diff --git a/tex/context/base/l-xml.lua b/tex/context/base/l-xml.lua
index cdb9dacc5..d6c48fe7b 100644
--- a/tex/context/base/l-xml.lua
+++ b/tex/context/base/l-xml.lua
@@ -10,6 +10,7 @@ if not modules then modules = { } end modules ['l-xml'] = {
-- some code may move to l-xmlext
-- some day we will really compile the lpaths (just construct functions)
+-- todo: some things per xml file, like namespace remapping
--[[ldx--
The parser used here is inspired by the variant discussed in the lua book, but
@@ -38,15 +39,30 @@ optimize the code.
xml = xml or { }
tex = tex or { }
-xml.trace_lpath = false
-xml.trace_print = false
-xml.trace_remap = false
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, lower, gmatch, gsub, find = string.format, string.lower, string.gmatch, string.gsub, string.find
-local format, concat, remove, insert, type, next = string.format, table.concat, table.remove, table.insert, type, next
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers.
+--ldx]]--
---~ local pairs, next, type = pairs, next, type
+local trace_lpath, trace_remap = false, false
--- todo: some things per xml file, like namespace remapping
+if trackers then
+ trackers.register("xml.lpath", function(v) trace_lpath = v end)
+ trackers.register("xml.remap", function(v) trace_remap = v end)
+end
+
+function xml.settrace(str,value)
+ if str == "lpath" then
+ trace_lpath = value or false
+ elseif str == "remap" then
+ trace_remap = value or false
+ end
+end
--[[ldx--
First a hack to enable namespace resolving. A namespace is characterized by
@@ -73,7 +89,7 @@ do
--ldx]]--
function xml.registerns(namespace, pattern) -- pattern can be an lpeg
- check = check + lpeg.C(lpeg.P(pattern:lower())) / namespace
+ check = check + lpeg.C(lpeg.P(lower(pattern))) / namespace
parse = lpeg.P { lpeg.P(check) + 1 * lpeg.V(1) }
end
@@ -88,7 +104,7 @@ do
--ldx]]--
function xml.checkns(namespace,url)
- local ns = parse:match(url:lower())
+ local ns = parse:match(lower(url))
if ns and namespace ~= ns then
xml.xmlns[namespace] = ns
end
@@ -106,7 +122,7 @@ do
--ldx]]--
function xml.resolvens(url)
- return parse:match(url:lower()) or ""
+ return parse:match(lower(url)) or ""
end
--[[ldx--
@@ -173,6 +189,9 @@ do
end
local function add_attribute(namespace,tag,value)
+ if cleanup and #value > 0 then
+ value = cleanup(value) -- new
+ end
if tag == "xmlns" then
xmlns[#xmlns+1] = resolvens(value)
at[tag] = value
@@ -245,7 +264,7 @@ dt[0] = top
end
end
local function set_message(txt)
- errorstr = "garbage at the end of the file: " .. txt:gsub("([ \n\r\t]*)","")
+ errorstr = "garbage at the end of the file: " .. gsub(txt,"([ \n\r\t]*)","")
end
local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
@@ -293,7 +312,7 @@ dt[0] = top
local somecomment = C((1 - endcomment )^0)
local somecdata = C((1 - endcdata )^0)
- function entity(k,v) entities[k] = v end
+ local function entity(k,v) entities[k] = v end
local begindoctype = open * P("!DOCTYPE")
local enddoctype = close
@@ -389,7 +408,7 @@ dt[0] = top
return root and not root.error
end
- xml.error_handler = (logs and logs.report) or (input and input.report) or print
+ xml.error_handler = (logs and logs.report) or (input and logs.report) or print
end
@@ -535,16 +554,16 @@ do
local ats = eat and next(eat) and { } -- type test maybe faster
if ats then
if attributeconverter then
- for k,v in pairs(eat) do
+ for k,v in next, eat do
ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
end
else
- for k,v in pairs(eat) do
+ for k,v in next, eat do
ats[#ats+1] = format('%s=%q',k,v)
end
end
end
- if ern and xml.trace_remap and ern ~= ens then
+ if ern and trace_remap and ern ~= ens then
ens = ern
end
if ens ~= "" then
@@ -640,7 +659,8 @@ do
function xml.checkbom(root) -- can be made faster
if root.ri then
local dt, found = root.dt, false
- for k,v in ipairs(dt) do
+ for k=1,#dt do
+ local v = dt[k]
if type(v) == "table" and v.special and v.tg == "@pi" and v.dt:find("xml.*version=") then
found = true
break
@@ -913,8 +933,6 @@ do
local bar = P('|')
local hat = P('^')
local valid = R('az', 'AZ', '09') + S('_-')
---~ local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
---~ local name_nop = C(P(true)) * C(valid^1)
local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
local name_nop = Cc("*") * C(valid^1)
local name = name_yes + name_nop
@@ -1051,7 +1069,7 @@ do
if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
insert(map, 1, { 16 })
end
- -- print((table.serialize(map)):gsub("[ \n]+"," "))
+ -- print(gsub(table.serialize(map),"[ \n]+"," "))
return map
end
end
@@ -1068,7 +1086,7 @@ do
cache[pattern] = result
lpathcached = lpathcached + 1
end
- if trace or xml.trace_lpath then
+ if trace or trace_lpath then
xml.lshow(result)
end
return result
@@ -1077,14 +1095,17 @@ do
end
end
- function lpath_cached_patterns()
+ function xml.cached_patterns()
return cache
end
- local fallbackreport = (texio and texio.write) or io.write
+-- we run out of locals (limited to 200)
+--
+-- local fallbackreport = (texio and texio.write) or io.write
function xml.lshow(pattern,report)
- report = report or fallbackreport
+-- report = report or fallbackreport
+ report = report or (texio and texio.write) or io.write
local lp = xml.lpath(pattern)
if lp == false then
report(" -: root\n")
@@ -1116,7 +1137,8 @@ do
function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
local t = { ... }
- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+-- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+ local report = (type(t[#t]) == "function" and t[#t]) or (texio and texio.write) or io.write
if e == nil then
report("\n")
elseif type(e) ~= "table" then
@@ -1636,7 +1658,7 @@ do
local rt, dt, dk
traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
- return (ekat and (ekat[arguments] or ekat[arguments:gsub("^([\"\'])(.*)%1$","%2")])) or ""
+ return (ekat and (ekat[arguments] or ekat[gsub(arguments,"^([\"\'])(.*)%1$","%2")])) or ""
end
function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
@@ -1698,9 +1720,6 @@ do
function xml.filter(root,pattern)
local kind, a, b, c = parser:match(pattern)
---~ if xml.trace_lpath then
---~ print(pattern,kind,a,b,c)
---~ end
if kind == 1 or kind == 3 then
return (filters[b] or default_filter)(root,a,c)
elseif kind == 2 then
@@ -2013,7 +2032,7 @@ do
end
if not name then
if ek.at then
- for a in (attribute or "href"):gmatch("([^|]+)") do
+ for a in gmatch(attribute or "href","([^|]+)") do
name = ek.at[a]
if name then break end
end
@@ -2052,7 +2071,7 @@ do
-- stripped
else
if nolines then
- str = str:gsub("[ \n\r\t]+"," ")
+ str = gsub(str,"[ \n\r\t]+"," ")
end
if str == "" then
-- stripped
@@ -2069,9 +2088,8 @@ do
end)
end
- function xml.rename_space(root, oldspace, newspace) -- fast variant
+ local function rename_space(root, oldspace, newspace) -- fast variant
local ndt = #root.dt
- local rename = xml.rename_space
for i=1,ndt or 0 do
local e = root[i]
if type(e) == "table" then
@@ -2083,12 +2101,14 @@ do
end
local edt = e.dt
if edt then
- rename(edt, oldspace, newspace)
+ rename_space(edt, oldspace, newspace)
end
end
end
end
+ xml.rename_space = rename_space
+
function xml.remap_tag(root, pattern, newtg)
traverse(root, lpath(pattern), function(r,d,k)
d[k].tg = newtg
@@ -2167,10 +2187,12 @@ put them here instead of loading mode modules there then needed.
--ldx]]--
function xml.gsub(t,old,new)
- if t.dt then
- for k,v in ipairs(t.dt) do
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
if type(v) == "string" then
- t.dt[k] = v:gsub(old,new)
+ dt[k] = gsub(v,old,new)
else
xml.gsub(v,old,new)
end
@@ -2195,9 +2217,9 @@ end
--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
---~ function xml.escaped (str) return str:gsub("(.)" , xml.escapes ) end
---~ function xml.unescaped(str) return str:gsub("(&.-;)", xml.unescapes) end
---~ function xml.cleansed (str) return str:gsub("<.->" , '' ) end -- "%b<>"
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
do
@@ -2229,6 +2251,10 @@ do
local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+ xml.escaped_pattern = escaped
+ xml.unescaped_pattern = unescaped
+ xml.cleansed_pattern = cleansed
+
function xml.escaped (str) return escaped :match(str) end
function xml.unescaped(str) return unescaped:match(str) end
function xml.cleansed (str) return cleansed :match(str) end
@@ -2273,14 +2299,14 @@ do if unicode and unicode.utf8 then
return char(tonumber(s,16))
end
- function utfize(root)
+ local function utfize(root)
local d = root.dt
for k=1,#d do
local dk = d[k]
if type(dk) == "string" then
-- test prevents copying if no match
- if dk:find(".-;") then
- d[k] = dk:gsub("(.-);",toutf)
+ if find(dk,".-;") then
+ d[k] = gsub(dk,"(.-);",toutf)
end
else
utfize(dk)
@@ -2291,8 +2317,10 @@ do if unicode and unicode.utf8 then
xml.utfize = utfize
local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
- if e:find("#x") then
+ if find(e,"^#x") then
return char(tonumber(e:sub(3),16))
+ elseif find(e,"^#") then
+ return char(tonumber(e:sub(2)))
else
local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
if ee then
@@ -2310,8 +2338,8 @@ do if unicode and unicode.utf8 then
for k=1,#d do
local dk = d[k]
if type(dk) == "string" then
- if dk:find("&.-;") then
- d[k] = dk:gsub("&(.-);",resolve)
+ if find(dk,"&.-;") then
+ d[k] = gsub(dk,"&(.-);",resolve)
end
else
resolve_entities(dk)
@@ -2323,24 +2351,24 @@ do if unicode and unicode.utf8 then
xml.resolve_entities = resolve_entities
function xml.utfize_text(str)
- if str:find("") then
- return (str:gsub("(.-);",toutf))
+ if find(str,"") then
+ return (gsub(str,"(.-);",toutf))
else
return str
end
end
function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
- if str:find("&") then
- return (str:gsub("&(.-);",resolve))
+ if find(str,"&") then
+ return (gsub(str,"&(.-);",resolve))
else
return str
end
end
function xml.show_text_entities(str)
- if str:find("&") then
- return (str:gsub("&(.-);","[%1]"))
+ if find(str,"&") then
+ return (gsub(str,"&(.-);","[%1]"))
else
return str
end
@@ -2352,7 +2380,7 @@ do if unicode and unicode.utf8 then
local documententities = root.entities
local allentities = xml.entities
if documententities then
- for k, v in pairs(documententities) do
+ for k, v in next, documententities do
allentities[k] = v
end
end
@@ -2386,7 +2414,7 @@ end
--~
--~ ]])
---~ xml.trace_lpath = true
+--~ xml.settrace("lpath",true)
--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
diff --git a/tex/context/base/lang-alt.tex b/tex/context/base/lang-alt.tex
index d59df78bd..e45748ead 100644
--- a/tex/context/base/lang-alt.tex
+++ b/tex/context/base/lang-alt.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Altaic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Altaic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -37,8 +37,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!year,\ ,\v!month,\ ,\v!day},
- \c!state=\v!stop]
+ \c!date={\v!year,\ ,\v!month,\ ,\v!day}]
\installlanguage [turkish] [\s!tr]
diff --git a/tex/context/base/lang-ana.tex b/tex/context/base/lang-ana.tex
index 336be50f2..c108655c4 100644
--- a/tex/context/base/lang-ana.tex
+++ b/tex/context/base/lang-ana.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Anatolian Languages}
+\writestatus{loading}{ConTeXt Language Macros / Anatolian Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -21,6 +21,4 @@
\unprotect
-\protect
-
-\endinput
+\protect \endinput
diff --git a/tex/context/base/lang-ara.tex b/tex/context/base/lang-ara.tex
index 91bd6ae38..3c4d3c522 100644
--- a/tex/context/base/lang-ara.tex
+++ b/tex/context/base/lang-ara.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Arabic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Arabic Languages}
\unprotect
@@ -29,8 +29,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!day,\ ,\v!month,{،\ },\v!year},
- \c!state=\v!stop] % elders always preloaded!
+ \c!date={\v!day,\ ,\v!month,{،\ },\v!year}]
\installlanguage [\s!arabic] [\s!ar]
diff --git a/tex/context/base/lang-art.tex b/tex/context/base/lang-art.tex
index 3f857e11e..e8be91630 100644
--- a/tex/context/base/lang-art.tex
+++ b/tex/context/base/lang-art.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Artificial Languages}
+\writestatus{loading}{ConTeXt Language Macros / Artificial Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -23,6 +23,4 @@
\unprotect
-\protect
-
-\endinput
+\protect \endinput
diff --git a/tex/context/base/lang-bal.tex b/tex/context/base/lang-bal.tex
index c4e0f31f7..9b0528a27 100644
--- a/tex/context/base/lang-bal.tex
+++ b/tex/context/base/lang-bal.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Baltic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Baltic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -23,6 +23,4 @@
\unprotect
-\protect
-
-\endinput
+\protect \endinput
diff --git a/tex/context/base/lang-cel.tex b/tex/context/base/lang-cel.tex
index abbeb10c6..4d93957f1 100644
--- a/tex/context/base/lang-cel.tex
+++ b/tex/context/base/lang-cel.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Celtic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Celtic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -23,6 +23,4 @@
\unprotect
-\protect
-
-\endinput
+\protect \endinput
diff --git a/tex/context/base/lang-chi.tex b/tex/context/base/lang-chi.tex
index 7458268f7..278e10745 100644
--- a/tex/context/base/lang-chi.tex
+++ b/tex/context/base/lang-chi.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Language Macros / Chinese}
+\writestatus{loading}{ConTeXt Language Macros / Chinese}
%D This module is coded using the \UNICODE\ support built in
%D \CONTEXT. Therefore, \type {\uchar} is used instead of latin
@@ -31,9 +31,7 @@
\c!rightquote=\cnencoding\cnupperrightsinglequote,
\c!leftquotation=\cnencoding\cnupperleftdoublequote,
\c!rightquotation=\cnencoding\cnupperrightdoublequote,
- \c!date={\v!year,\cnyear,\ ,\v!month,\v!day,\cnday},
- \c!state=\v!stop]
-
+ \c!date={\v!year,\cnyear,\ ,\v!month,\v!day,\cnday}]
\setupheadtext [\s!cn] [\v!content={\cnencoding\cnencodedcontents}]
\setupheadtext [\s!cn] [\v!tables={\cnencoding\cnencodedtables}]
diff --git a/tex/context/base/lang-cjk.tex b/tex/context/base/lang-cjk.tex
new file mode 100644
index 000000000..138f6d263
--- /dev/null
+++ b/tex/context/base/lang-cjk.tex
@@ -0,0 +1,328 @@
+%D \module
+%D [ file=lang-chi,
+%D version=2009.03.02,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Chinese,
+%D author={Hans Hagen \& Wang Lei},
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D Derived from \MKII\ files.
+
+\writestatus{loading}{ConTeXt Language Macros / CJK}
+
+\definesystemconstant {chinese} \definesystemconstant {cn}
+\definesystemconstant {japanese} \definesystemconstant {ja}
+\definesystemconstant {korean} \definesystemconstant {kr}
+
+\unprotect
+
+% Chinese
+
+\installlanguage
+ [\s!cn]
+ [\c!leftsentence=——,
+ \c!rightsentence=——,
+ \c!leftsubsentence=——,
+ \c!rightsubsentence=——,
+ \c!leftquote=‘,
+ \c!rightquote=’,
+ \c!leftquotation=“,
+ \c!rightquotation=”,
+ \c!date={\v!year,年,\ ,\v!month,\v!day,日}]
+
+\setupheadtext [\s!cn] [\v!content=目录]
+\setupheadtext [\s!cn] [\v!tables=表格]
+\setupheadtext [\s!cn] [\v!figures=图形]
+\setupheadtext [\s!cn] [\v!graphics=图]
+\setupheadtext [\s!cn] [\v!intermezzi=퉣]
+\setupheadtext [\s!cn] [\v!index=索引]
+\setupheadtext [\s!cn] [\v!abbreviations=缩略语]
+\setupheadtext [\s!cn] [\v!logos=徽贬]
+\setupheadtext [\s!cn] [\v!units=计量单位]
+
+\setuplabeltext [\s!cn] [\v!table=表]
+\setuplabeltext [\s!cn] [\v!figure=图]
+\setuplabeltext [\s!cn] [\v!intermezzo=퉣]
+\setuplabeltext [\s!cn] [\v!graphic=插图]
+\setuplabeltext [\s!cn] [\v!appendix=附录]
+\setuplabeltext [\s!cn] [\v!part={第,部分}]
+\setuplabeltext [\s!cn] [\v!chapter={第,章}]
+\setuplabeltext [\s!cn] [\v!section={第,节}]
+\setuplabeltext [\s!cn] [\v!line=行]
+\setuplabeltext [\s!cn] [\v!lines=行]
+
+\setuplabeltext [\s!cn] [\v!subsection=]
+\setuplabeltext [\s!cn] [\v!subsubsection=]
+\setuplabeltext [\s!cn] [\v!subsubsubsection=]
+
+\setuplabeltext [\s!cn] [\v!january=一月]
+\setuplabeltext [\s!cn] [\v!february=二月]
+\setuplabeltext [\s!cn] [\v!march=三月]
+\setuplabeltext [\s!cn] [\v!april=四月]
+\setuplabeltext [\s!cn] [\v!may=五月]
+\setuplabeltext [\s!cn] [\v!june=六月]
+\setuplabeltext [\s!cn] [\v!july=七月]
+\setuplabeltext [\s!cn] [\v!august=八月]
+\setuplabeltext [\s!cn] [\v!september=九月]
+\setuplabeltext [\s!cn] [\v!october=十月]
+\setuplabeltext [\s!cn] [\v!november=十一月]
+\setuplabeltext [\s!cn] [\v!december=十二月]
+
+\setuplabeltext [\s!cn] [\v!sunday=星期日]
+\setuplabeltext [\s!cn] [\v!monday=星期一]
+\setuplabeltext [\s!cn] [\v!tuesday=星期二]
+\setuplabeltext [\s!cn] [\v!wednesday=星期三]
+\setuplabeltext [\s!cn] [\v!thursday=星期四]
+\setuplabeltext [\s!cn] [\v!friday=星期五]
+\setuplabeltext [\s!cn] [\v!saturday=星期六]
+
+%D Japanese
+
+\installlanguage
+ [\s!ja]
+ [\c!leftsentence=——,
+ \c!rightsentence=——,
+ \c!leftsubsentence=——,
+ \c!rightsubsentence=——,
+ \c!leftquote=‘,
+ \c!rightquote=’,
+ \c!leftquotation=「,
+ \c!rightquotation=」,
+ \c!date={西暦,\v!year,年,\v!month,月,\v!day,日}]
+
+\setupheadtext [\s!ja] [\v!content=目次]
+\setupheadtext [\s!ja] [\v!tables=机]
+\setupheadtext [\s!ja] [\v!figures=図]
+\setupheadtext [\s!ja] [\v!graphics=グラフ]
+\setupheadtext [\s!ja] [\v!intermezzi=間奏曲]
+\setupheadtext [\s!ja] [\v!index=目次]
+\setupheadtext [\s!ja] [\v!abbreviations=略語]
+\setupheadtext [\s!ja] [\v!logos=理性]
+\setupheadtext [\s!ja] [\v!units=ユニッツ]
+
+\setuplabeltext [\s!ja] [\v!table=表]
+\setuplabeltext [\s!ja] [\v!figure=図]
+\setuplabeltext [\s!ja] [\v!intermezzo=間奏曲]
+\setuplabeltext [\s!ja] [\v!graphic=イラスト]
+\setuplabeltext [\s!ja] [\v!appendix=付録]
+\setuplabeltext [\s!ja] [\v!part={第,パート}]
+\setuplabeltext [\s!ja] [\v!chapter={第,章}]
+\setuplabeltext [\s!ja] [\v!section={第,項}]
+\setuplabeltext [\s!ja] [\v!line=線]
+\setuplabeltext [\s!ja] [\v!lines=線]
+
+\setuplabeltext [\s!ja] [\v!subsection=]
+\setuplabeltext [\s!ja] [\v!subsubsection=]
+\setuplabeltext [\s!ja] [\v!subsubsubsection=]
+
+\setuplabeltext [\s!ja] [\v!january=1]
+\setuplabeltext [\s!ja] [\v!february=2]
+\setuplabeltext [\s!ja] [\v!march=3]
+\setuplabeltext [\s!ja] [\v!april=4]
+\setuplabeltext [\s!ja] [\v!may=5]
+\setuplabeltext [\s!ja] [\v!june=6]
+\setuplabeltext [\s!ja] [\v!july=7]
+\setuplabeltext [\s!ja] [\v!august=8]
+\setuplabeltext [\s!ja] [\v!september=9]
+\setuplabeltext [\s!ja] [\v!october=10]
+\setuplabeltext [\s!ja] [\v!november=11]
+\setuplabeltext [\s!ja] [\v!december=12]
+
+\setuplabeltext [\s!ja] [\v!sunday=月曜日]
+\setuplabeltext [\s!ja] [\v!monday=火曜日]
+\setuplabeltext [\s!ja] [\v!tuesday=水曜日]
+\setuplabeltext [\s!ja] [\v!wednesday=木曜日]
+\setuplabeltext [\s!ja] [\v!thursday=金曜日]
+\setuplabeltext [\s!ja] [\v!friday=土曜日]
+\setuplabeltext [\s!ja] [\v!saturday=日曜日]
+
+%D Korean
+
+% todo
+
+\protect \endinput
+
+cn={
+ ["abbreviations"]="缩略语",
+ ["appendix"]="附录",
+ ["april"]="四月",
+ ["august"]="八月",
+ ["chapter"]="章",
+ ["contents"]="目录",
+ ["day"]="日",
+ ["december"]="十二月",
+ ["febrary"]="二月",
+ ["figure"]="图",
+ ["figures"]="图形",
+ ["friday"]="星期五",
+ ["graphics"]="图",
+ ["illustration"]="插图",
+ ["index"]="索引",
+ ["intermezzo"]="퉣",
+ ["intro"]="第",
+ ["january"]="一月",
+ ["july"]="七月",
+ ["june"]="六月",
+ ["leftsentence"]="——",
+ ["leftsubsentence"]="——",
+ ["line"]="行",
+ ["logos"]="徽贬",
+ ["march"]="三月",
+ ["may"]="五月",
+ ["monday"]="星期一",
+ ["month"]="月",
+ ["november"]="十一月",
+ ["october"]="十月",
+ ["part"]="部分",
+ ["rightsentence"]="——",
+ ["rightsubsentence"]="——",
+ ["saturday"]="星期六",
+ ["section"]="节",
+ ["september"]="九月",
+ ["sunday"]="星期日",
+ ["table"]="表",
+ ["tables"]="表格",
+ ["thursday"]="星期四",
+ ["tuesday"]="星期二",
+ ["units"]="计量单位",
+ ["upperleftdoublequote"]="“",
+ ["upperleftdoublequote-v"]="『",
+ ["upperleftsinglequote"]="‘",
+ ["upperleftsinglequote-v"]="「",
+ ["upperrightdoublequote"]="”",
+ ["upperrightdoublequote-v"]="』",
+ ["upperrightsinglequote"]="’",
+ ["upperrightsinglequote-v"]="」",
+ ["wednesday"]="星期三",
+ ["year"]="年",
+}
+
+ja={
+ ["abbreviations"]="略語",
+ ["abstract"]="概要",
+ ["and"]="、",
+ ["answer"]="答:",
+ ["appendix"]="付録",
+ ["april"]="四月",
+ ["article"]="項目",
+ ["august"]="八月",
+ ["bibliography"]="参考文献",
+ ["book"]="ブック",
+ ["bridgehead"]="項",
+ ["bullet"]="●",
+ ["by"]=":",
+ ["caution"]="注意",
+ ["chapter"]="章",
+ ["christiandate"]="西暦",
+ ["colophon"]="奥付",
+ ["copyright"]="製作著作",
+ ["day"]="日",
+ ["december"]="十二月",
+ ["dedication"]="謝辞",
+ ["edited"]="編者",
+ ["editedby"]="編者:",
+ ["edition"]="編集",
+ ["endquote"]="」",
+ ["equation"]="式",
+ ["example"]="例",
+ ["february"]="二月",
+ ["figure"]="図",
+ ["figures"]="図",
+ ["friday"]="土曜日",
+ ["glossary"]="用語集",
+ ["glosssee"]="参照",
+ ["glossseealso"]="参照",
+ ["graphics"]="グラフ",
+ ["illustration"]="イラスト",
+ ["important"]="重要項目",
+ ["index"]="目次",
+ ["indexsymbols"]="シンボル",
+ ["intermezzo"]="間奏曲",
+ ["intermezzos"]="間奏曲",
+ ["intro"]="第",
+ ["january"]="一月",
+ ["july"]="七月",
+ ["june"]="六月",
+ ["leftsentence"]="——",
+ ["leftsubsentence"]="——",
+ ["line"]="線",
+ ["lines"]="線",
+ ["listofequations"]="式目次",
+ ["listofexamples"]="例目次",
+ ["listoffigures"]="図目次",
+ ["listoftables"]="表目次",
+ ["listofunknown"]="不明目次",
+ ["logos"]="理性",
+ ["march"]="三月",
+ ["may"]="五月",
+ ["monday"]="火曜日",
+ ["month"]="月",
+ ["msgaud"]="対象者",
+ ["msglevel"]="レベル",
+ ["msgorig"]="発信元",
+ ["navhome"]="ホーム",
+ ["navnext"]="次のページ",
+ ["navnextsibling"]="早送り",
+ ["navprev"]="前のページ",
+ ["navprevsibling"]="巻戻し",
+ ["navup"]="上に戻る",
+ ["nestedendquote"]="』",
+ ["nestedstartquote"]="『",
+ ["nonexistantelement"]="要素が存在しません",
+ ["note"]="注意",
+ ["notes"]="注意",
+ ["november"]="十一月",
+ ["october"]="十月",
+ ["pages"]="偧献",
+ ["part"]="パート",
+ ["preface"]="序文",
+ ["procedure"]="手順",
+ ["procedureformal"]="手順",
+ ["productionset"]="プロダクション",
+ ["productionsetformal"]="プロダクション",
+ ["published"]="発行",
+ ["qandadiv"]="問:、答:",
+ ["qandaentry"]="問:",
+ ["question"]="問:",
+ ["reference"]="参照",
+ ["refname"]="名前",
+ ["refsection"]="項",
+ ["refsynopsisdiv"]="概要",
+ ["revhistory"]="改訂履歴",
+ ["revision"]="改訂",
+ ["rightsentence"]="——",
+ ["rightsubsentence"]="——",
+ ["saturday"]="日曜日",
+ ["section"]="項",
+ ["see"]="参照",
+ ["seealso"]="参照",
+ ["separator"]="、",
+ ["september"]="九月",
+ ["set"]="設定",
+ ["setindex"]="目次設定",
+ ["sidebar"]="サイドバー",
+ ["simplesect"]="項",
+ ["singleendquote"]="’",
+ ["singlestartquote"]="‘",
+ ["startquote"]="「",
+ ["step"]="ステップ",
+ ["sunday"]="月曜日",
+ ["table"]="表",
+ ["tablenotes"]="注意",
+ ["tableofcontents"]="目次",
+ ["tables"]="机",
+ ["thursday"]="金曜日",
+ ["tip"]="ティップ",
+ ["tuesday"]="水曜日",
+ ["unexpectedelementname"]="不明な要素名",
+ ["units"]="ユニッツ",
+ ["unsupported"]="サポートしません",
+ ["warning"]="警告",
+ ["wednesday"]="木曜日",
+ ["year"]="年",
+}
diff --git a/tex/context/base/lang-ctx.tex b/tex/context/base/lang-ctx.tex
index 5364c1af6..09f28dda1 100644
--- a/tex/context/base/lang-ctx.tex
+++ b/tex/context/base/lang-ctx.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Language Macros / Generic Patterns}
+\writestatus{loading}{ConTeXt Language Macros / Generic Patterns}
\unprotect
@@ -28,31 +28,26 @@
%D than one font encoding is in use. I can add more defaults here
%D if users let me know what encoding they use.
-\installlanguage [\s!nl] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
-\installlanguage [\s!fr] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
-\installlanguage [\s!de] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
-\installlanguage [\s!it] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
-
-\installlanguage [\s!pt] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
-
-\installlanguage [\s!hr] [\s!mapping=ec,\s!encoding=ec] % no il2, misses cacute characters
-
-\installlanguage [\s!pl] [\s!mapping={pl0,ec,qx},\s!encoding={pl0,ec,qx}] % pl0 may go
-\installlanguage [\s!cs] [\s!mapping={il2,ec},\s!encoding={il2,ec}] % il2 may go
-\installlanguage [\s!sk] [\s!mapping={il2,ec},\s!encoding={il2,ec}] % il2 may go
-\installlanguage [\s!sl] [\s!mapping=ec,\s!encoding=ec] % il2 has gone
-
-\installlanguage [\s!vn] [\s!mapping=t5,\s!encoding=t5]
-
-\installlanguage [\s!ru] [\s!mapping=t2a,\s!encoding=t2a]
+% \installlanguage [\s!nl] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
+% \installlanguage [\s!fr] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
+% \installlanguage [\s!de] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
+% \installlanguage [\s!it] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
+% \installlanguage [\s!pt] [\s!mapping={texnansi,ec},\s!encoding={texnansi,ec}]
+% \installlanguage [\s!hr] [\s!mapping=ec,\s!encoding=ec] % no il2, misses cacute characters
+% \installlanguage [\s!pl] [\s!mapping={pl0,ec,qx},\s!encoding={pl0,ec,qx}] % pl0 may go
+% \installlanguage [\s!cs] [\s!mapping={il2,ec},\s!encoding={il2,ec}] % il2 may go
+% \installlanguage [\s!sk] [\s!mapping={il2,ec},\s!encoding={il2,ec}] % il2 may go
+% \installlanguage [\s!sl] [\s!mapping=ec,\s!encoding=ec] % il2 has gone
+% \installlanguage [\s!vi] [\s!mapping=t5,\s!encoding=t5]
+% \installlanguage [\s!ru] [\s!mapping=t2a,\s!encoding=t2a]
% beware, don't use \setuplanguage here
-\installlanguage[\s!gb][\s!lefthyphenmin=3,\s!righthyphenmin=3] % patterns can only handle this
-\installlanguage[\s!us][\s!lefthyphenmin=2,\s!righthyphenmin=3] % patterns can only handle this
+% \installlanguage[\s!gb][\s!lefthyphenmin=3,\s!righthyphenmin=3] % patterns can only handle this
+% \installlanguage[\s!us][\s!lefthyphenmin=2,\s!righthyphenmin=3] % patterns can only handle this
% greek
-\installlanguage[\s!agr][\s!mapping=\s!agr,\s!encoding=\s!agr]
+% \installlanguage[\s!agr][\s!mapping=\s!agr,\s!encoding=\s!agr]
\protect \endinput
diff --git a/tex/context/base/lang-cyr.tex b/tex/context/base/lang-cyr.tex
index 34b5e78c3..470402bb1 100644
--- a/tex/context/base/lang-cyr.tex
+++ b/tex/context/base/lang-cyr.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Cyrillic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Cyrillic Languages}
%D The cyrillic languages always use a dedicated input regime.
%D Therefore we define the labels using symbolic names.
@@ -37,7 +37,8 @@
\c!leftquotation=\leftguillemot,
\c!rightquotation=\rightguillemot,
\c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping=t2a,
+ \s!encoding=t2a]
\installlanguage
[\s!ua]
@@ -53,11 +54,12 @@
\c!leftquotation=\leftguillemot,
\c!rightquotation=\rightguillemot,
\c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
-
-\installlanguage [russian] [\s!ru]
-\installlanguage [ukrainian] [\s!ua]
+ \s!patterns=\s!uk,
+ \s!mapping=t2a,
+ \s!encoding=t2a]
+\installlanguage [russian] [\s!ru]
+\installlanguage [ukrainian] [\s!ua]
%D Labels and header texts.
diff --git a/tex/context/base/lang-dis.tex b/tex/context/base/lang-dis.tex
index db932d68a..f081bf4a9 100644
--- a/tex/context/base/lang-dis.tex
+++ b/tex/context/base/lang-dis.tex
@@ -15,7 +15,7 @@
%D use more generic pattern files, we decided to isolate these
%D mappings.
-\writestatus{loading}{Context Language Macros / Distribution Patterns}
+\writestatus{loading}{ConTeXt Language Macros / Distribution Patterns}
%D Hyphenation patterns are normally sought in filed named
%D \type {lang-xx.pat}. When present on the system, those
@@ -52,8 +52,8 @@
% \definefilefallback [lang-sk.pat] [skhyphen.tex,skhyph.pat]
% \definefilefallback [lang-deo.pat] [dehypht.tex]
-\definefilesynonym [lang-af.pat] [lang-nl.pat]
-\definefilesynonym [lang-en.pat] [lang-us.pat]
-\definefilesynonym [lang-en.hyp] [lang-us.hyp]
+% \definefilesynonym [lang-af.pat] [lang-nl.pat]
+% \definefilesynonym [lang-en.pat] [lang-us.pat]
+% \definefilesynonym [lang-en.hyp] [lang-us.hyp]
\protect \endinput
diff --git a/tex/context/base/lang-frq.tex b/tex/context/base/lang-frq.tex
index 372813f70..773230e6c 100644
--- a/tex/context/base/lang-frq.tex
+++ b/tex/context/base/lang-frq.tex
@@ -2,7 +2,7 @@
%D [ file=lang-frq,
%D version=2004.01.15,
%D title=\CONTEXT\ Language Macros,
-%D subtitle=Language Frequency Table Support,
+%D subtitle=Frequency Tables,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Language Frequency Table Support}
+\writestatus{loading}{ConTeXt Language Macros / Frequency Tables}
\unprotect
diff --git a/tex/context/base/lang-ger.tex b/tex/context/base/lang-ger.tex
index bdcaa9cb3..b9717ce9a 100644
--- a/tex/context/base/lang-ger.tex
+++ b/tex/context/base/lang-ger.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Germanic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Germanic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -42,7 +42,8 @@
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={texnansi,ec},
+ \s!encoding={texnansi,ec}]
\installlanguage
[\s!en]
@@ -57,11 +58,14 @@
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!month,\ ,\v!day,{,\ },\v!year},
\s!patterns=\s!us,
- \c!state=\v!stop] % elders always preloaded!
+ \s!lefthyphenmin=2,
+ \s!righthyphenmin=3]
\installlanguage
[\s!de]
[\c!spacing=\v!packed,
+ \s!lefthyphenmin=3,
+ \s!righthyphenmin=3,
\c!leftsentence={\hbox{--~}},
\c!rightsentence={\hbox{~--}},
\c!leftsubsentence={--},
@@ -71,7 +75,8 @@
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoublesixquote,
\c!date={\v!day,{.},\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={texnansi,ec},
+ \s!encoding={texnansi,ec}]
\installlanguage
[\s!da]
@@ -84,8 +89,7 @@
\c!rightquote=\upperrightsinglesixquote,
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoublesixquote,
- \c!date={\v!day,{.},\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,{.},\ ,\v!month,\ ,\v!year}]
\installlanguage
[\s!sv]
@@ -98,8 +102,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperrightdoubleninequote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
\installlanguage
[\s!af]
@@ -113,7 +116,7 @@
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!year,\ ,\v!month,\ ,\v!day},
- \c!state=\v!stop]
+ \s!patterns=\s!nl]
\installlanguage
[\s!nb]
@@ -180,14 +183,12 @@
\installlanguage % old german
[deo]
[\c!spacing=\v!packed,
- \c!default=\s!de,
- \c!state=\v!stop]
+ \c!default=\s!de]
\installlanguage
[de-de]
[\c!spacing=\v!packed,
- \c!default=\s!de,
- \c!state=\v!stop]
+ \c!default=\s!de]
\installlanguage
[de-at]
@@ -196,14 +197,12 @@
\c!leftquote=\leftguillemot,
\c!rightquote=\rightguillemot,
\c!leftquotation=\leftguillemot,
- \c!rightquotation=\rightguillemot,
- \c!state=\v!stop]
+ \c!rightquotation=\rightguillemot]
\installlanguage
[de-ch]
[\c!spacing=\v!packed,
- \c!default=\s!de,
- \c!state=\v!stop]
+ \c!default=\s!de]
%D And some alternative (but very real) english patterns:
@@ -211,24 +210,23 @@
[en-gb]
[\c!default=\s!en,
\s!patterns=\s!gb,
- \c!state=\v!stop]
+ \s!lefthyphenmin=3,
+ \s!righthyphenmin=3]
\installlanguage
[en-us]
- [\c!default=\s!en,
- %\s!patterns=\s!us,
- \c!state=\v!stop]
+ [\c!default=\s!en]
\installlanguage [\s!uk] [en-gb]
\installlanguage [\s!us] [en-us]
%D For compatibility reasons we also define:
-\installlanguage [du] [\s!de] % old times context
+%installlanguage [du] [\s!de] % old times context
%installlanguage [sp] [\s!es] % old times context /lang-ita
\installlanguage [usenglish] [en-us]
-\installlanguage [ukenglish] [en-uk]
+\installlanguage [ukenglish] [en-gb]
\installlanguage [english] [en-us]
\installlanguage [dutch] [\s!nl]
\installlanguage [german] [\s!de]
diff --git a/tex/context/base/lang-grk.tex b/tex/context/base/lang-grk.tex
index 13cebb207..e4ba781eb 100644
--- a/tex/context/base/lang-grk.tex
+++ b/tex/context/base/lang-grk.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Greek Language}
+\writestatus{loading}{ConTeXt Language Macros / Greek}
%D The framework of this module is set up by Hans Hagen while
%D all the translations have been done by Apostolos Syropoulos
@@ -29,8 +29,7 @@
\c!rightquote=\greekrightquot,
\c!leftquotation=\greekleftquot,
\c!rightquotation=\greekrightquot,
- \c!date={\v!day\ \v!month\ \v!year},
- \c!state=\v!stop]
+ \c!date={\v!day\ \v!month\ \v!year}]
\installlanguage [greek] [\s!gr]
@@ -86,7 +85,9 @@
\installlanguage
[\s!agr]
[\s!default=\s!gr,
- \c!state=\v!stop]
+ \s!patterns=\s!agr,
+ \s!mapping=\s!agr,
+ \s!encoding=\s!agr]
\installlanguage [ancientgreek] [\s!agr]
diff --git a/tex/context/base/lang-ind.tex b/tex/context/base/lang-ind.tex
index f9bbad0d7..9b6e5ff1d 100644
--- a/tex/context/base/lang-ind.tex
+++ b/tex/context/base/lang-ind.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Indo-Iranian Languages}
+\writestatus{loading}{ConTeXt Language Macros / Indo-Iranian Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
diff --git a/tex/context/base/lang-ini.lua b/tex/context/base/lang-ini.lua
index e9e9af1b6..e188ad36c 100644
--- a/tex/context/base/lang-ini.lua
+++ b/tex/context/base/lang-ini.lua
@@ -6,6 +6,13 @@ if not modules then modules = { } end modules ['lang-ini'] = {
license = "see context related readme files"
}
+-- needs a cleanup (share locals)
+
+local utf = unicode.utf8
+
+local find, lower, format, utfchar = string.find, string.lower, string.format, utf.char
+local concat = table.concat
+
if lang.use_new then lang.use_new(true) end
languages = languages or {}
@@ -13,6 +20,8 @@ languages.version = 1.009
languages.hyphenation = languages.hyphenation or { }
languages.hyphenation.data = languages.hyphenation.data or { }
+local langdata = languages.hyphenation.data
+
-- 002D : hyphen-minus (ascii)
-- 2010 : hyphen
-- 2011 : nonbreakable hyphen
@@ -26,7 +35,7 @@ languages.hyphenation.data = languages.hyphenation.data or { }
-- we can consider hiding data (faster access too)
--~ local function filter(filename,what)
---~ local data = io.loaddata(input.find_file(filename))
+--~ local data = io.loaddata(resolvers.find_file(filename))
--~ local data = data:match(string.format("\\%s%%s*(%%b{})",what or "patterns"))
--~ return data:match("{%s*(.-)%s*}") or ""
--~ end
@@ -47,29 +56,29 @@ local command = lpeg.P("\\patterns")
local parser = (1-command)^0 * command * content
local function filterpatterns(filename)
- if filename:find("%.rpl") then
- return io.loaddata(input.find_file(filename)) or ""
+ if find(filename,"%.rpl") then
+ return io.loaddata(resolvers.find_file(filename)) or ""
else
- return parser:match(io.loaddata(input.find_file(filename)) or "")
+ return parser:match(io.loaddata(resolvers.find_file(filename)) or "")
end
end
-local command = lpeg.P("\\hyphenation")
-local parser = (1-command)^0 * command * content
+local command = lpeg.P("\\hyphenation")
+local parser = (1-command)^0 * command * content
local function filterexceptions(filename)
- if filename:find("%.rhl") then
- return io.loaddata(input.find_file(filename)) or ""
+ if find(filename,"%.rhl") then
+ return io.loaddata(resolvers.find_file(filename)) or ""
else
- return parser:match(io.loaddata(input.find_file(filename)) or {}) -- "" ?
+ return parser:match(io.loaddata(resolvers.find_file(filename)) or {}) -- "" ?
end
end
local function record(tag)
- local data = languages.hyphenation.data[tag]
+ local data = langdata[tag]
if not data then
data = lang.new()
- languages.hyphenation.data[tag] = data or 0
+ langdata[tag] = data or 0
end
return data
end
@@ -82,31 +91,31 @@ function languages.hyphenation.define(tag)
end
function languages.hyphenation.number(tag)
- local d = languages.hyphenation.data[tag]
+ local d = langdata[tag]
return (d and d:id()) or 0
end
-function languages.hyphenation.load(tag, filename, filter, target)
- input.starttiming(languages)
+local function loadthem(tag, filename, filter, target)
+ statistics.starttiming(languages)
local data = record(tag)
- filename = (filename and filename ~= "" and input.find_file(filename)) or ""
+ filename = (filename and filename ~= "" and resolvers.find_file(filename)) or ""
local ok = filename ~= ""
if ok then
lang[target](data,filterpatterns(filename))
else
lang[target](data,"")
end
- languages.hyphenation.data[tag] = data
- input.stoptiming(languages)
+ langdata[tag] = data
+ statistics.stoptiming(languages)
return ok
end
function languages.hyphenation.loadpatterns(tag, patterns)
- return languages.hyphenation.load(tag, patterns, filterpatterns, "patterns")
+ return loadthem(tag, patterns, filterpatterns, "patterns")
end
function languages.hyphenation.loadexceptions(tag, exceptions)
- return languages.hyphenation.load(tag, patterns, filterexceptions, "hyphenation")
+ return loadthem(tag, patterns, filterexceptions, "hyphenation")
end
function languages.hyphenation.exceptions(tag, ...)
@@ -130,16 +139,17 @@ function languages.hyphenation.righthyphenmin(tag, value)
end
function languages.hyphenation.n()
- return table.count(languages.hyphenation.data)
+ return table.count(langdata)
end
-- we can speed this one up with locals if needed
local function tolang(what)
- if type(what) == "number" then
- return languages.hyphenation.data[languages.numbers[what]]
- elseif type(what) == "string" then
- return languages.hyphenation.data[what]
+ local kind = type(what)
+ if kind == "number" then
+ return langdata[languages.numbers[what]]
+ elseif kind == "string" then
+ return langdata[what]
else
return what
end
@@ -158,15 +168,15 @@ languages.registered = languages.registered or { }
languages.associated = languages.associated or { }
languages.numbers = languages.numbers or { }
-input.storage.register(false,"languages/registered",languages.registered,"languages.registered")
-input.storage.register(false,"languages/associated",languages.associated,"languages.associated")
+storage.register("languages/registered",languages.registered,"languages.registered")
+storage.register("languages/associated",languages.associated,"languages.associated")
function languages.register(tag,parent,patterns,exceptions)
parent = parent or tag
languages.registered[tag] = {
parent = parent,
- patterns = patterns or string.format("lang-%s.pat",parent),
- exceptions = exceptions or string.format("lang-%s.hyp",parent),
+ patterns = patterns or format("lang-%s.pat",parent),
+ exceptions = exceptions or format("lang-%s.hyp",parent),
loaded = false,
number = 0,
}
@@ -190,7 +200,7 @@ end
function languages.loadable(tag)
local l = languages.registered[tag]
- if l and l.patterns and input.find_file(patterns) then
+ if l and l.patterns and resolvers.find_file(patterns) then
return true
else
return false
@@ -237,10 +247,10 @@ function languages.hyphenation.loadwords(tag, filename)
local id = languages.hyphenation.number(tag)
if id > 0 then
local l = lang.new(id) or 0
- input.starttiming(languages)
+ statistics.starttiming(languages)
local data = io.loaddata(filename) or ""
l:hyphenation(data)
- input.stoptiming(languages)
+ statistics.stoptiming(languages)
end
end
@@ -257,10 +267,10 @@ function languages.logger.report()
if l.loaded then
local p = (l.patterns and "pat") or '-'
local e = (l.exceptions and "exc") or '-'
- result[#result+1] = string.format("%s:%s:%s:%s:%s", tag, l.parent, p, e, l.number)
+ result[#result+1] = format("%s:%s:%s:%s:%s", tag, l.parent, p, e, l.number)
end
end
- return (#result > 0 and table.concat(result," ")) or "none"
+ return (#result > 0 and concat(result," ")) or "none"
end
languages.words = languages.words or {}
@@ -283,15 +293,15 @@ do
local word = lpeg.Cs((markup/"" + disc/"" + (1-spacing))^1)
function languages.words.load(tag, filename)
- local filename = input.find_file(filename,'other text file') or ""
+ local filename = resolvers.find_file(filename,'other text file') or ""
if filename ~= "" then
- input.starttiming(languages)
+ statistics.starttiming(languages)
local data = io.loaddata(filename) or ""
local words = languages.words.data[tag] or {}
parser = (spacing + word/function(s) words[s] = true end)^0
parser:match(data)
languages.words.data[tag] = words
- input.stoptiming(languages)
+ statistics.stoptiming(languages)
end
end
@@ -301,7 +311,7 @@ function languages.words.found(id, str)
local tag = languages.numbers[id]
if tag then
local data = languages.words.data[tag]
- return data and (data[str] or data[str:lower()])
+ return data and (data[str] or data[lower(str)])
else
return false
end
@@ -314,11 +324,10 @@ do
local glyph, disc, kern = node.id('glyph'), node.id('disc'), node.id('kern')
- local bynode = node.traverse
+ local bynode = node.traverse
+ local chardata = characters.data
local function mark_words(head,found) -- can be optimized
- local cd = characters.data
- local uc = utf.char
local current, start, str, language, n = head, nil, "", nil, 0
local function action()
if #str > 0 then
@@ -347,25 +356,25 @@ do
action()
language = a
end
- if current.subtype > 0 then
+ local components = current.components
+ if components then
start = start or current
n = n + 1
- for g in bynode(current.components) do
- str = str .. uc(g.char)
+ for g in bynode(components) do
+ str = str .. utfchar(g.char)
end
else
local code = current.char
- if cd[code].uccode or cd[code].lccode then
+ if chardata[code].uccode or chardata[code].lccode then
start = start or current
n = n + 1
- str = str .. uc(code)
- else
- if start then
- action()
- end
+ str = str .. utfchar(code)
+ elseif start then
+ action()
end
end
elseif id == disc then
+ if n > 0 then n = n + 1 end
-- ok
elseif id == kern and current.subtype == 0 and start then
-- ok
@@ -383,18 +392,20 @@ do
languages.words.methods = { }
languages.words.method = 1
+ local lw = languages.words
+
languages.words.methods[1] = function(head, attribute, yes, nop)
local set = node.set_attribute
local unset = node.unset_attribute
- local wrong, right = false, false
- if nop then wrong = function(n) set(n,attribute,nop) end end
+ local right, wrong = false, false
if yes then right = function(n) set(n,attribute,yes) end end
+ if nop then wrong = function(n) set(n,attribute,nop) end end
for n in node.traverse(head) do
unset(n,attribute) -- hm
end
local found, done = languages.words.found, false
mark_words(head, function(language,str)
- if #str < languages.words.threshold then
+ if #str < lw.threshold then
return false
elseif found(language,str) then
done = true
@@ -407,11 +418,10 @@ do
return head, done
end
- local lw = languages.words
+ local color = attributes.private('color')
function languages.words.check(head)
if lw.enable and head.next then
- local color = attributes.numbers['color']
local colors = lw.colors
local alc = attributes.list[color]
return lw.methods[lw.method](head, color, alc[colors.known], alc[colors.unknown])
@@ -443,3 +453,16 @@ languages.associate('uk','latn','eng')
languages.associate('nl','latn','nld')
languages.associate('de','latn','deu')
languages.associate('fr','latn','fra')
+
+statistics.register("loaded patterns", function()
+ local result = languages.logger.report()
+ if result ~= "none" then
+ return result
+ end
+end)
+
+statistics.register("language load time", function()
+ if statistics.elapsedindeed(languages) then
+ return format("%s seconds, n=%s", statistics.elapsedtime(languages), languages.hyphenation.n())
+ end
+end)
diff --git a/tex/context/base/lang-ini.mkii b/tex/context/base/lang-ini.mkii
index 46b9f51ce..e5759bc84 100644
--- a/tex/context/base/lang-ini.mkii
+++ b/tex/context/base/lang-ini.mkii
@@ -11,13 +11,159 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D This module needs a further cleanup (real split between ii/iv).
+
+%D This module implements the (for the moment still simple)
+%D multi||language support of \CONTEXT, which should not be
+%D confused with the multi||lingual interface. This support
+%D will be extended when needed.
+
+\writestatus{loading}{ConTeXt Language Macros / Initialization}
+
\unprotect
+\ifx\nonfrenchspacing\undefined \let\nonfrenchspacing\relax \fi
+\ifx\frenchspacing \undefined \let\frenchspacing \relax \fi
+
+%D When loading hyphenation patterns, \TEX\ assign a number to
+%D each loaded table, starting with~0. Switching to a specific
+%D table is done by assigning the relevant number to the
+%D predefined \COUNTER\ \type{\language}.
+
+%D We keep track of the last loaded patterns by means of a
+%D pseudo \COUNTER. This just one of those situations in which
+%D we don't want to spent a real one. Language zero has no
+%D patterns, first of all because I like to start numbering
+%D at one. It may come in handy for special purposes as well.
+
+\normallanguage\zerocount \def\loadedlanguage{1}
+
+%D \macros
+%D {currentlanguage, setupcurrentlanguage}
+%D
+%D Instead of numbers,we are going to use symbolic names for
+%D the languages. The current langage is saved in the macro
+%D \type {\currentlanguage}. The setup macro is mainly used
+%D for cosmetic purposes.
+%D
+%D \starttyping
+%D \dorecurse{3}
+%D {\language[nl]
+%D \startmode[*en] english \stopmode
+%D \startmode[*nl] dutch \stopmode
+%D \language[en]
+%D \startmode[*en] english \stopmode
+%D \startmode[*nl] dutch \stopmode}
+%D \stoptyping
+
+\let\currentlanguage \empty
+\let\currentmainlanguage\empty
+
+\def\setupcurrentlanguage[#1]{\setcurrentlanguage\currentmainlanguage{#1}}
+
+\def\setcurrentlanguage#1#2% sets modes: **id (currentmain) *id (current)
+ {\doifsomething{#1}
+ {\ifx\currentmainlanguage\empty\else\resetsystemmode{\systemmodeprefix\currentmainlanguage}\fi
+ \edef\currentmainlanguage{#1}%
+ \setsystemmode{\systemmodeprefix\currentmainlanguage}}%
+ \doifsomething{#2}
+ {\ifx\currentlanguage\empty\else\resetsystemmode\currentlanguage\fi
+ \edef\currentlanguage{#2}%
+ \setsystemmode\currentlanguage}}
+
+%D The internal macros will be defined later.
+
+%D \macros
+%D {installlanguage}
+%D
+%D Hyphenation patterns can only be loaded when the format file
+%D is prepared. The next macro takes care of this loading. A
+%D language is specified with
+%D
+%D \showsetup{installlanguage}
+%D
+%D When \type {state} equals \type {start}, both patterns
+%D and additional hyphenation specifications are loaded. These
+%D files are seached for on the system path and are to be
+%D named:
+%D
+%D \starttyping
+%D \f!languageprefix-identifier.\f!patternsextension
+%D \f!languageprefix-identifier.\f!hyhensextension
+%D \stoptyping
+%D
+%D The \type{spacing} variable specifies how the spaces after
+%D punctuation has to be handled. English is by tradition more
+%D tolerant to inter||sentence spacing than other languages.
+%D
+%D This macro also defines \type {\identifier} as a shortcut
+%D switch to the language. Furthermore the command defined as
+%D being language specific, are executed. With
+%D \type {default} we can default to another language
+%D (patterns) at format generation time. This default language
+%D is overruled when the appropriate patterns are loaded (some
+%D implementations support run time addition of patterns to a
+%D preloaded format).
+
+\def\dodoinstalllanguage#1#2% #2 added
+ {\doifundefined{#1}{\setvalue{#1}{\complexlanguage[#2]}}%
+ \expanded{\noexpand\uppercase{\noexpand\edef\noexpand\ascii{#1}}}%
+ \doifundefined\ascii{\setvalue\ascii{\complexlanguage[#2]}}}
+
+%D \macros
+%D {preloadlanguages}
+%D
+%D We first try to load the files defined as file synonym
+%D for \type {lang-*.pat} and \type {lang-*.hyp}. After that we
+%D fall back on those files. The macro \type {\preloadpatterns}
+%D reports which patterns are loaded and what hyphenmin
+%D values are set.
+
+\let\installedlanguages\empty
+
+\def\doiflanguageelse#1{\doifdefinedelse{\??la#1\c!state}}
+
+\def\doloadlanguagefiles#1%
+ {\doifelsevalue{\??la#1\c!state}\v!start
+ {\edef\languagesuffix{\specificlanguageparameter{#1}\s!patterns}%
+ \ifx\languagesuffix\empty
+ \edef\languagesuffix{\defaultlanguage{#1}}%
+ \else\ifx\languagesuffix\relax
+ \edef\languagesuffix{\defaultlanguage{#1}}%
+ \fi\fi
+ \ifx\languagesuffix\empty
+ \edef\languagesuffix{#1}%
+ \fi
+ \doifundefinedelse{\??la\??la:\currentencoding:\currentmapping:\languagesuffix}
+ {\doloadpatterns{#1}\languagesuffix}
+ {\bgroup
+ \edef\loadedlanguage{\getvalue{\??la\??la:\currentencoding:\currentmapping:\languagesuffix}}%
+ %\showmessage\m!linguals1{\languagesuffix,#1,\loadedlanguage,*,*}%
+ %\showmessage\m!linguals3{\languagesuffix,#1,\loadedlanguage,*,*}%
+ \egroup}}
+ {\showmessage\m!linguals5{#1}}}
+
+\def\doinstalllanguage[#1][#2]%
+ {\doifassignmentelse{#2}
+ {\doiflanguageelse{#1}
+ {\getparameters[\??la#1][#2]}
+ {\setvalue{\l!prefix!#1}{#1}%
+ \addtocommalist{#1}\installedlanguages
+ \dodoinstalllanguage{#1}{#1}%
+ \getparameters[\??la#1][\c!state=\v!start,#2]}%
+ \doloadlanguagefiles{#1}}
+ {\setvalue{\l!prefix!#1}{#2}%
+ \getparameters[\??la#1][\s!default=#2]%
+ \dodoinstalllanguage{#1}{#2}}}
+
+\def\reallanguagetag#1%
+ {\ifcsname\l!prefix!#1\endcsname\csname\l!prefix!#1\endcsname\else#1\fi}
+
\let\preloadedpatterns\empty
\let\preloadedpmessage\empty
\def\doshowpatterns#1#2#3#4% language number encoding mapping
- {#1->#3:#4->#2->\xxlanguageparameter{#1}\s!lefthyphenmin:\xxlanguageparameter{#1}\s!righthyphenmin\space}
+ {#1->#3:#4->#2->\specificlanguageparameter{#1}\s!lefthyphenmin:\specificlanguageparameter{#1}\s!righthyphenmin\space}
\def\preloadlanguages
{\doifsomething\preloadedpmessage{\showmessage\m!linguals{10}\preloadedpmessage}}
@@ -27,16 +173,33 @@
\processcommacommand[\installedlanguages]\preloadallpatterns
\global\let\preloadallpatterns\relax}
-\fetchruntimecommand \showpatterns {\f!languageprefix\s!run}
+% ^^ \language[#1] gave unwanted side effect of loading language specifics
+
+\def\installlanguage
+ {\dodoubleargument\doinstalllanguage}
+
+%D When the second argument is a language identifier, a
+%D synonym is created. This feature is present because we
+%D used dutch mnemonics in the dutch version, but nowadays
+%D conform a standard.
+
+\let \patternencoding \s!default
+\let \patternmapping \s!default
-\def\mkdoloadpatterns#1#2%
- {\expanded{\getcommacommandsize[\getvalue{\??la#2\s!encoding}]}%
+\def\doifpatternselse#1%
+ {\expanded{\doifinsetelse{#1}{\preloadedpatterns}}}
+
+\def\doloadpatterns#1#2%
+ {\edef\askedlanguageencoding{\specificlanguageparameter{#1}\s!encoding}%
+ \edef\askedlanguagemapping {\specificlanguageparameter{#1}\s!mapping}%
+ \expanded{\getcommacommandsize[\askedlanguageencoding]}%
+ % slightly faster: \let\unicodechar\utfunihashglyph
\ifnum\commalistsize>0
- %\message{[nofpatterns #2: \commalistsize/\getvalue{\??la#2\s!encoding}]}%
+ %\message{[nofpatterns #2: \commalistsize/\askedlanguageencoding]}%
\dorecurse\commalistsize
- {\expanded{\getfromcommacommand[\getvalue{\??la#2\s!encoding}][\recurselevel]}%
+ {\expanded{\getfromcommacommand[\askedlanguageencoding][\recurselevel]}%
\let\patternencoding\commalistelement
- \expanded{\getfromcommacommand[\getvalue{\??la#2\s!mapping }][\recurselevel]}%
+ \expanded{\getfromcommacommand[\askedlanguagemapping][\recurselevel]}%
\let\patternmapping \commalistelement
%\message{[patterns: #1/#2/\patternencoding/\patternmapping]}%
\dodoloadpatterns{#1}{#2}\patternencoding\patternmapping}%
@@ -45,14 +208,14 @@
\dodoloadpatterns{#1}{#2}{}{}%
\fi}
-\beginXETEX
+\ifnum\texengine=\xetexengine
-\def\mkdoloadpatterns#1#2%
- {\letvalue{\??la#2\s!encoding}\empty
- \letvalue{\??la#2\s!mapping }\empty
- \dodoloadpatterns{#1}{#2}{}{}}
+ \def\doloadpatterns#1#2%
+ {%\letvalue{\??la#2\s!encoding}\empty
+ %\letvalue{\??la#2\s!mapping }\empty
+ \dodoloadpatterns{#1}{#2}{}{}}
-\endXETEX
+\fi
\def\setuphyppatencoding
{\pathypsettings
@@ -102,6 +265,8 @@
\fi
\egroup}
+\fetchruntimecommand \showpatterns {\f!languageprefix\s!run}
+
%D Since we can only load patterns in ini\TeX, we nil the
%D loading before dumping (which saves a bit of memory, but
%D strangely enough not in the format).
@@ -111,30 +276,130 @@
\globallet\dodoloadpatterns\gobblefourarguments
\to \everydump
-\def\mkdoifpatternselse#1%
- {\expanded{\doifinsetelse{#1}{\preloadedpatterns}}}
+%D \macros
+%D {setuplanguage}
+%D
+%D Quick and dirty, but useful:
+%D
+%D \showsetup{setuplanguage}
+%D
+%D Beware, this command can only be used when a language is installed.
-\def\mkloadlanguagefiles#1%
- {\doifelsevalue{\??la#1\c!state}\v!start
- {\doifelsevaluenothing{\??la#1\s!patterns}
- {\edef\languagesuffix{#1}}
- {\edef\languagesuffix{\getvalue{\??la#1\s!patterns}}}%
- \doifundefinedelse{\??la\??la:\currentencoding:\currentmapping:\languagesuffix}
- {\mkdoloadpatterns{#1}\languagesuffix}
- {\bgroup
- \edef\loadedlanguage{\getvalue{\??la\??la:\currentencoding:\currentmapping:\languagesuffix}}%
- \showmessage\m!linguals1{\languagesuffix,#1,\loadedlanguage,*,*}%
- \showmessage\m!linguals3{\languagesuffix,#1,\loadedlanguage,*,*}%
- \egroup}}
- {\showmessage\m!linguals5{#1}}}
+\unprotected \def\setuplanguage
+ {\dodoubleempty\dosetuplanguage}
+
+\def\dosetuplanguage[#1][#2]% handy patch for testing
+ {\ifsecondargument
+ \getparameters[\??la#1][#2]%
+ \doif{#1}\currentlanguage\docomplexlanguage
+ \else
+ \getparameters[\??la\currentlanguage][#1]%
+ \docomplexlanguage
+ \fi}
+
+\setuplanguage
+ [\s!default]
+ [\s!lefthyphenmin=2,
+ \s!righthyphenmin=2,
+ \s!patterns=,
+ \c!spacing=\v!packed,
+ \s!encoding=,
+ \s!mapping=,
+ \c!lefthyphen=,
+ \c!righthyphen=-,
+ \c!hyphen=-,
+ \c!midsentence=---,
+ \c!leftsentence=---,
+ \c!rightsentence=---,
+ \c!leftsubsentence=---,
+ \c!rightsubsentence=---,
+ \c!leftquote=\upperleftsinglesixquote,
+ \c!rightquote=\upperrightsingleninequote,
+ \c!leftquotation=\upperleftdoublesixquote,
+ \c!rightquotation=\upperrightdoubleninequote,
+ \c!leftspeech=\languageparameter\c!leftquotation,
+ \c!middlespeech=,
+ \c!rightspeech=\languageparameter\c!rightquotation,
+ \c!limittext=\unknown,
+ \c!date={\v!year,\ ,\v!month,\ ,\v!day},
+ \c!text=Ag]
+
+% rather new, split and per language
+
+\setuplanguage
+ [\s!default]
+ [\c!compoundhyphen=\compoundhyphen,
+ \c!leftcompoundhyphen=\compoundhyphen,
+ \c!rightcompoundhyphen=]
-\def\mksetnormallanguage#1#2% current default
+%D The values \type {leftsentence} and \type
+%D {rightsentence} can be (and are) used to implement
+%D automatic subsentence boundary glyphs, like in {\fr
+%D |<|french guillemots|>|} or {\de |<|german guillemots|>|} or
+%D {\nl |<|dutch dashes|>|} like situations. Furthermore \type
+%D {leftquotation} and \type {leftquote} come into view
+%D \quotation {when we quote} or \quote {quote} something.
+
+%D \macros
+%D {currentdatespecification}
+%D
+%D Just to make things easy we can ask for the current date
+%D specification by saying:
+
+\def\currentdatespecification{\languageparameter\c!date}
+
+%D This command is not meant for users.
+
+%D Carefull reading of these macros shows that it's legal to
+%D say
+%D
+%D \starttyping
+%D \installlanguage [du] [de]
+%D \stoptyping
+
+%D \macros
+%D {language,mainlanguage}
+%D
+%D Switching to another language (actually another hyphenation
+%D pattern) is done with:
+%D
+%D \starttyping
+%D \language[identifier]
+%D \stoptyping
+%D
+%D or with \type{\identifier}. Just to be compatible with
+%D \PLAIN\ \TEX, we still support the original meaning, so
+%D
+%D \starttyping
+%D \language=1
+%D \stoptyping
+%D
+%D is a valid operation, where the relation between number
+%D and language depends on the order in installing languages.
+%D
+%D \showsetup{language}
+%D \showsetup{mainlanguage}
+%D
+%D Both commands take a predefined language identifier as
+%D argument. We can use \type{\mainlanguage[identifier]} for
+%D setting the (indeed) main language. This is the language
+%D used for translating labels like {\em figure} and {\em
+%D table}. The main language defaults to the current language.
+%D
+%D We take care of local as well as standardized language
+%D switching (fr and fa, de and du, but nl and nl).
+
+\ifx\synchronizepatterns \undefined \let\synchronizepatterns\relax \fi
+\ifx\synchronizepatternswithfont\undefined \def\synchronizepatternswithfont{\synchronizepatterns} \fi
+
+\def\setnormallanguage#1#2% current default
{% called quite often, so we use \csname
% \def\synchronizepatterns{\setnormallanguage
% {\csname\??la\currentlanguage\s!patterns\endcsname}}% called often
% of even better pre-expand in an ugly way:
- \@EA\def\@EA\synchronizepatterns\@EA{\@EA\dosetnormallanguage
- \csname\??la\currentlanguage\s!patterns\endcsname}%
+% \@EA\def\@EA\synchronizepatterns\@EA{\@EA\dosetnormallanguage
+% \csname\??la\currentlanguage\s!patterns\endcsname}%
+\edef\synchronizepatterns{\noexpand\dosetnormallanguage{\languageparameter\s!patterns}}%
\donefalse
\synchronizepatterns
\ifdone\else
@@ -142,8 +407,9 @@
\synchronizepatterns
\ifdone\else
\ifx\currentdefaultlanguage\empty\else
- \@EA\def\@EA\synchronizepatterns\@EA{\@EA\dosetnormallanguage
- \csname\??la\currentdefaultlanguage\s!patterns\endcsname}%
+% \@EA\def\@EA\synchronizepatterns\@EA{\@EA\dosetnormallanguage
+% \csname\??la\currentdefaultlanguage\s!patterns\endcsname}%
+\edef\synchronizepatterns{\noexpand\dosetnormallanguage{\specificlanguageparameter\currentdefaultlanguage\s!patterns}}%
\synchronizepatterns
\ifdone\else
\dosetnormallanguage\currentdefaultlanguage
@@ -153,11 +419,11 @@
\fi
\fi}
-\def\dosetnormallanguage#1% #1 == \cs
- {\dodosetnormallanguage{:\currentencoding:\currentmapping:}#1{%
- \dodosetnormallanguage{:\currentencoding:\s!default :}#1{%
- \dodosetnormallanguage{:\s!default :\currentmapping:}#1{%
- \dodosetnormallanguage{:\s!default :\s!default :}#1\empty}}}}
+\def\dosetnormallanguage#1% #1 == \cs (no longer)
+ {\dodosetnormallanguage{:\currentencoding:\currentmapping:}{#1}{%
+ \dodosetnormallanguage{:\currentencoding:\s!default :}{#1}{%
+ \dodosetnormallanguage{:\s!default :\currentmapping:}{#1}{%
+ \dodosetnormallanguage{:\s!default :\s!default :}{#1}\empty}}}}
\def\dodosetnormallanguage#1#2%
{\ifcsname\??la\??la#1#2\endcsname
@@ -174,11 +440,251 @@
\@EA\firstofoneargument
\fi}
-\beginXETEX
+\newevery \everylanguage \relax
+
+\def\disablelanguagespecifics
+ {\ignorecompoundcharacter}
+
+\def\sethyphenationvariables
+ {\lefthyphenmin 0\languageparameter\s!lefthyphenmin \relax
+ \righthyphenmin0\languageparameter\s!righthyphenmin\relax
+ \lefthyphenmin \numexpr\lefthyphenmin +\hyphenminoffset\relax
+ \righthyphenmin\numexpr\righthyphenmin+\hyphenminoffset\relax}
+
+\def\docomplexlanguage% assumes that \currentlanguage is set
+ {\edef\currentdefaultlanguage{\defaultlanguage\currentlanguage}%
+ \setnormallanguage\currentlanguage\currentdefaultlanguage
+ \the\everylanguage
+ \enablelanguagespecifics[\currentlanguage]%
+ \sethyphenationvariables
+ \relax
+ % will be definable and move to core-spa !
+ \doifelse{\languageparameter\c!spacing}\v!broad\nonfrenchspacing\frenchspacing}
+
+\ifx\enablelanguagespecifics\undefined \def\enablelanguagespecifics[#1]{} \fi
+
+% The following may be a solution for the fact that one cannot
+% change catcodes of characters like : and ; inside an environment.
+
+\appendtoks
+ \enablelanguagespecifics[\currentlanguage]%
+\to \everystarttext
+
+\def\complexlanguage[#1]%
+ {\edef\askedlanguage{#1}%
+ \ifx\askedlanguage\empty \else
+ \ifcsname\l!prefix!\askedlanguage\endcsname
+ \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
+ \ifx\currentlanguage\askedlanguage \else
+ \setcurrentlanguage\currentmainlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \else
+ \showmessage\m!linguals6{#1}%
+ \fi
+ \fi}
+
+\let\simplelanguage\normallanguage
+
+\definecomplexorsimple\language
+
+\def\mainlanguage[#1]%
+ {\edef\askedlanguage{#1}%
+ \ifx\askedlanguage\empty \else
+ \ifcsname\l!prefix!\askedlanguage\endcsname
+ \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
+ \ifx\currentlanguage\askedlanguage
+ \ifx\currentmainlanguage\askedlanguage
+ \else
+ \setcurrentlanguage\askedlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \else
+ \setcurrentlanguage\askedlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \fi
+ \fi}
+
+%D \macros
+%D {defaultlanguage,languageparameter,specificlanguageparameter}
+
+\def\defaultlanguage#1%
+ {\ifcsname\??la#1\s!default\endcsname
+ \expandafter\defaultlanguage\csname\??la#1\s!default\endcsname
+ \else
+ #1%
+ \fi}
+
+\def\languageparameter#1%
+ {\ifcsname\??la\currentlanguage#1\endcsname
+ \csname\??la\currentlanguage#1\endcsname
+ \else\ifcsname\??la\currentlanguage\s!default\endcsname
+ \expandafter\specificlanguageparameter\csname\??la\currentlanguage\s!default\endcsname{#1}%
+ \else\ifcsname\??la\s!default#1\endcsname
+ \csname\??la\s!default#1\endcsname
+ \fi\fi\fi}
+
+\def\specificlanguageparameter#1#2%
+ {\ifcsname\??la#1#2\endcsname
+ \csname\??la#1#2\endcsname
+ \else\ifcsname\??la#1\s!default\endcsname
+ \expandafter\specificlanguageparameter\csname\??la#1\s!default\endcsname{#2}%
+ \else\ifcsname\??la\s!default#2\endcsname
+ \csname\??la\s!default#2\endcsname
+ \fi\fi\fi}
+
+%D New (see nomarking and nolist):
+
+\def\splitsequence#1#2%
+ {\doifelse{#1}\v!no{#2}{\doifelse{#1}\v!yes{\languageparameter\c!limittext}{#1}}}
+
+\def\splitsymbol#1%
+ {\splitsequence{#1}{\languageparameter\c!limittext}}
+
+%D Just like with subsentence boundary symbols, quotes
+%D placement depends on the current language, therefore we show
+%D the defaults here.
+%D
+%D \def\ShowLanguageValues [#1] [#2] #3 #4
+%D {\blank
+%D \startlinecorrection
+%D \vbox\bgroup
+%D \language[#1]%
+%D \setbox0=\hbox to \hsize{\hss\bf#2 subsentence symbol and quotes\hss}
+%D \dp0=0pt
+%D \box0
+%D \vskip.5em
+%D \hrule
+%D \vskip.5em
+%D \let\normalbar=|
+%D \hbox to \hsize
+%D {\hfil\quotation{#3 #4}\hfil\quote{#2}\hfil
+%D \let|=\normalbar\strut|<||<|#3|>|#4|>|\hfil}
+%D \vskip.5em
+%D \hrule
+%D \egroup
+%D \stoplinecorrection
+%D \blank}
+%D
+%D \ShowLanguageValues [af] [afrikaans] afrikaanse ...
+%D \ShowLanguageValues [ca] [catalan] catalan ...
+%D \ShowLanguageValues [cs] [czech] tjechisch tex
+%D \ShowLanguageValues [cs] [slovak] slowaakse ...
+%D \ShowLanguageValues [da] [danish] deense ...
+%D \ShowLanguageValues [de] [german] duitse degelijkheid
+%D \ShowLanguageValues [en] [english] engelse humor
+%D \ShowLanguageValues [fi] [finnish] finse ...
+%D \ShowLanguageValues [fr] [french] franse slag
+%D \ShowLanguageValues [it] [italian] italiaanse ...
+%D \ShowLanguageValues [la] [latin] latijnse missen
+%D \ShowLanguageValues [nl] [dutch] nederlandse zuinigheid
+%D \ShowLanguageValues [nb] [bokmal] noorse zalm
+%D \ShowLanguageValues [nn] [nnynorsk] noorse zalm
+%D \ShowLanguageValues [pl] [polish] poolse vlag
+%D \ShowLanguageValues [pt] [portuguese] portugese ...
+%D \ShowLanguageValues [es] [spanish] spaans benauwd
+%D \ShowLanguageValues [sv] [swedish] zweedse ...
+%D \ShowLanguageValues [tr] [turkish] turks fruit
+
+%D We support a lot of languages. These are specified and
+%D loaded in separate files, according to their roots. Here
+%D we only take care of (postponed) setting of the current
+%D language.
+%D
+%D \unprotect
+%D \placetable{The germanic languages (\type{lang-ger})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!nl \NC dutch \NC germanic \NC\FR
+%D \NC \s!en \NC english \NC germanic \NC\MR
+%D \NC \s!de \NC german \NC germanic \NC\MR
+%D \NC \s!da \NC danish \NC germanic \NC\MR
+%D \NC \s!sv \NC swedish \NC germanic \NC\MR
+%D \NC \s!af \NC afrikaans \NC germanic \NC\MR
+%D \NC \s!nb \NC bokmal \NC germanic \NC\LR
+%D \NC \s!nn \NC nynorsk \NC germanic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D
+%D \unprotect
+%D \placetable{The italic languages (\type{lang-ita})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!fr \NC french \NC italic \NC\FR
+%D \NC \s!ca \NC catalan \NC italic \NC\MR
+%D \NC \s!es \NC spanish \NC italic \NC\MR
+%D \NC \s!it \NC italian \NC italic \NC\MR
+%D \NC \s!la \NC latin \NC italic \NC\MR
+%D \NC \s!pt \NC portuguese \NC italic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D
+%D \unprotect
+%D \placetable{The slavic languages (\type{lang-sla})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!pl \NC polish \NC slavic \NC\FR
+%D \NC \s!cs \NC czech \NC slavic \NC\MR
+%D \NC \s!sk \NC slavik \NC slavic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D \unprotect
+%D
+%D \placetable{The altaic languages (\type{lang-alt})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!tr \NC turkish \NC altaic \NC\SR
+%D \HL
+%D \stoptable
+%D
+%D \placetable{The uralic languages (\type{lang-ura})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!fi \NC finnish \NC uralic \NC\SR
+%D \HL
+%D \stoptable
+%D \protect
+
+% \bgroup \normallanguage255 \patterns{} \egroup
+% \def\nopatterns{\normallanguage255 }
+
+\def\nopatterns{\normallanguage\minusone}
+
+%D \XETEX\ is \UNICODE:
+
+\ifnum\texengine=\xetexengine
+
\def\synchronizepatternswithfont{}
\def\doloadpatterns #1#2{\dodoloadpatterns{#1}{#2}\s!default\s!default}
- \def\setnormallanguage #1{\dosetnormallanguage{:\s!default:\s!default:}#1\empty}
+ \def\dosetnormallanguage #1{\dodosetnormallanguage{:\s!default:\s!default:}{#1}\empty}
\def\setuphyppatencoding {\pathypsettings}
-\endXETEX
+
+\fi
+
+%D We default to the language belonging to the interface. This
+%D is one of the few places outside the interface modules where
+%D \type{\startinterface} is used.
+
+%D We default to english:
+
+\setupcurrentlanguage[\s!en]
+
+\def\initializemainlanguage
+ {\mainlanguage[\currentlanguage]%
+ \showmessage\m!linguals9\currentlanguage}
\protect \endinput
diff --git a/tex/context/base/lang-ini.mkiv b/tex/context/base/lang-ini.mkiv
index ce82b5a47..7cb945ef9 100644
--- a/tex/context/base/lang-ini.mkiv
+++ b/tex/context/base/lang-ini.mkiv
@@ -11,16 +11,133 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
+%D This module needs a further cleanup (real split between ii/iv).
+
+%D This module implements the (for the moment still simple)
+%D multi||language support of \CONTEXT, which should not be
+%D confused with the multi||lingual interface. This support
+%D will be extended when needed.
+
+\writestatus{loading}{ConTeXt Language Macros / Initialization}
\registerctxluafile{lang-ini}{1.001}
-\let\synchronizepatterns \relax % todo: cleanup
-\let\synchronizepatternswithfont\relax % todo: cleanup
-\let\preloadallpatterns \relax % just for old times sake
-\let\preloadlanguages \relax % just for old times sake
+\unprotect
+
+% \def\testlanguage[#1]%
+% {\start
+% \language[#1]
+% \number\normallanguage/\the\lefthyphenmin/\the\righthyphenmin:
+% \input tufte
+% \hyphenatedword{effetestenofditwerkt}
+% \par
+% \stop}
+%
+% \testlanguage[de] \testlanguage[de-de] \testlanguage[de-at] \testlanguage[de-ch] \page
+% \testlanguage[en] \testlanguage[us] \testlanguage[en-us] \testlanguage[uk] \testlanguage[en-gb] \page
+
+\ifx\nonfrenchspacing\undefined \let\nonfrenchspacing\relax \fi
+\ifx\frenchspacing \undefined \let\frenchspacing \relax \fi
+
+%D When loading hyphenation patterns, \TEX\ assign a number to
+%D each loaded table, starting with~0. Switching to a specific
+%D table is done by assigning the relevant number to the
+%D predefined \COUNTER\ \type{\language}.
+
+%D We keep track of the last loaded patterns by means of a
+%D pseudo \COUNTER. This just one of those situations in which
+%D we don't want to spent a real one. Language zero has no
+%D patterns, first of all because I like to start numbering
+%D at one. It may come in handy for special purposes as well.
+
+\normallanguage\zerocount \def\loadedlanguage{1}
+
+%D \macros
+%D {currentlanguage, setupcurrentlanguage}
+%D
+%D Instead of numbers,we are going to use symbolic names for
+%D the languages. The current langage is saved in the macro
+%D \type {\currentlanguage}. The setup macro is mainly used
+%D for cosmetic purposes.
+%D
+%D \starttyping
+%D \dorecurse{3}
+%D {\language[nl]
+%D \startmode[*en] english \stopmode
+%D \startmode[*nl] dutch \stopmode
+%D \language[en]
+%D \startmode[*en] english \stopmode
+%D \startmode[*nl] dutch \stopmode}
+%D \stoptyping
+
+\let\currentlanguage \empty
+\let\currentmainlanguage\empty
+
+\def\setupcurrentlanguage[#1]{\setcurrentlanguage\currentmainlanguage{#1}}
+
+\def\setcurrentlanguage#1#2% sets modes: **id (currentmain) *id (current)
+ {\doifsomething{#1}
+ {\ifx\currentmainlanguage\empty\else\resetsystemmode{\systemmodeprefix\currentmainlanguage}\fi
+ \edef\currentmainlanguage{#1}%
+ \setsystemmode{\systemmodeprefix\currentmainlanguage}}%
+ \doifsomething{#2}
+ {\ifx\currentlanguage\empty\else\resetsystemmode\currentlanguage\fi
+ \edef\currentlanguage{#2}%
+ \setsystemmode\currentlanguage}}
+
+%D The internal macros will be defined later.
+
+%D \macros
+%D {installlanguage}
+%D
+%D Hyphenation patterns can only be loaded when the format file
+%D is prepared. The next macro takes care of this loading. A
+%D language is specified with
+%D
+%D \showsetup{installlanguage}
+%D
+%D When \type {state} equals \type {start}, both patterns
+%D and additional hyphenation specifications are loaded. These
+%D files are seached for on the system path and are to be
+%D named:
+%D
+%D \starttyping
+%D \f!languageprefix-identifier.\f!patternsextension
+%D \f!languageprefix-identifier.\f!hyhensextension
+%D \stoptyping
+%D
+%D The \type{spacing} variable specifies how the spaces after
+%D punctuation has to be handled. English is by tradition more
+%D tolerant to inter||sentence spacing than other languages.
+%D
+%D This macro also defines \type {\identifier} as a shortcut
+%D switch to the language. Furthermore the command defined as
+%D being language specific, are executed. With
+%D \type {default} we can default to another language
+%D (patterns) at format generation time. This default language
+%D is overruled when the appropriate patterns are loaded (some
+%D implementations support run time addition of patterns to a
+%D preloaded format).
+
+\def\dodoinstalllanguage#1#2% #2 added
+ {\doifundefined{#1}{\setvalue{#1}{\complexlanguage[#2]}}%
+ \expanded{\noexpand\uppercase{\noexpand\edef\noexpand\ascii{#1}}}%
+ \doifundefined\ascii{\setvalue\ascii{\complexlanguage[#2]}}}
+
+%D \macros
+%D {preloadlanguages}
+%D
+%D We first try to load the files defined as file synonym
+%D for \type {lang-*.pat} and \type {lang-*.hyp}. After that we
+%D fall back on those files. The macro \type {\preloadpatterns}
+%D reports which patterns are loaded and what hyphenmin
+%D values are set.
-\def\mkdoloadpatterns#1#2%
+\let\installedlanguages\empty
+
+\def\doiflanguageelse#1{\doifdefinedelse{\??la#1\c!state}}
+
+\def\doloadpatterns#1#2%
{\ctxlua{languages.register(
"#1",
"#2",
@@ -28,43 +145,431 @@
"\truefilename{\f!languageprefix#2.\f!hyphensextension }")
}}
-\def\mkdoifpatternselse#1%
+% \def\doloadlanguagefiles#1%
+% {\doifelsevaluenothing{\??la#1\s!patterns}
+% {\doloadpatterns{#1}{#1}}
+% {\doloadpatterns{#1}{\getvalue{\??la#1\s!patterns}}}}
+
+\def\doloadlanguagefiles#1%
+ {\edef\languagesuffix{\specificlanguageparameter{#1}\s!patterns}%
+ \ifx\languagesuffix\empty
+ \edef\languagesuffix{\defaultlanguage{#1}}%
+ \else\ifx\languagesuffix\relax
+ \edef\languagesuffix{\defaultlanguage{#1}}%
+ \fi\fi
+ \ifx\languagesuffix\empty
+ \edef\languagesuffix{#1}%
+ \fi
+ \doloadpatterns{#1}\languagesuffix}
+
+\def\doinstalllanguage[#1][#2]%
+ {\doifassignmentelse{#2}
+ {\doiflanguageelse{#1}
+ {\getparameters[\??la#1][#2]}
+ {\setvalue{\l!prefix!#1}{#1}%
+ \addtocommalist{#1}\installedlanguages
+ \dodoinstalllanguage{#1}{#1}%
+ \getparameters[\??la#1][\c!state=\v!start,#2]}%
+ \doloadlanguagefiles{#1}}
+ {\setvalue{\l!prefix!#1}{#2}%
+ \getparameters[\??la#1][\s!default=#2]%
+ \dodoinstalllanguage{#1}{#2}}}
+
+\def\reallanguagetag#1%
+ {\ifcsname\l!prefix!#1\endcsname\csname\l!prefix!#1\endcsname\else#1\fi}
+
+% ^^ \language[#1] gave unwanted side effect of loading language specifics
+
+\def\installlanguage
+ {\dodoubleargument\doinstalllanguage}
+
+%D When the second argument is a language identifier, a
+%D synonym is created. This feature is present because we
+%D used dutch mnemonics in the dutch version, but nowadays
+%D conform a standard.
+
+\def\doifpatternselse#1%
{\ctxlua{cs.testcase(languages.loadable("#1"))}}
-\def\mkloadlanguagefiles#1%
- {\doifelsevaluenothing{\??la#1\s!patterns}
- {\mkdoloadpatterns{#1}{#1}}
- {\mkdoloadpatterns{#1}{\getvalue{\??la#1\s!patterns}}}}
+%D \macros
+%D {setuplanguage}
+%D
+%D Quick and dirty, but useful:
+%D
+%D \showsetup{setuplanguage}
+%D
+%D Beware, this command can only be used when a language is installed.
-\def\mksetnormallanguage#1#2% current default / we can freeze the number here
- {\normallanguage=\ctxlua{tex.sprint(languages.enable({
- "\csname\??la#1\s!patterns\endcsname","#1",
- "\csname\??la#2\s!patterns\endcsname","#2",
- }))}\relax}
+\unprotected \def\setuplanguage
+ {\dodoubleempty\dosetuplanguage}
-% to be tested
-%
-% \def\mkdosetnormallanguage#1#2% current default
-% {\normallanguage=\ctxlua{tex.sprint(languages.enable({
-% "\csname\??la#1\s!patterns\endcsname","#1",
-% "\csname\??la#2\s!patterns\endcsname","#2",
-% }))}}%
-% \setxvalue{\??la\??la#1#2}{\number\normallanguage}}
-%
-% \def\mksetnormallanguage#1#2% current default / we can freeze the number here
-% {\normallanguage\executeifdefined{\??la\??la#1#2}{\mkdosetnormallanguage{#1}{#2}}}
+\def\dosetuplanguage[#1][#2]% handy patch for testing
+ {\ifsecondargument
+ \getparameters[\??la#1][#2]%
+ \doif{#1}\currentlanguage\docomplexlanguage
+ \else
+ \getparameters[\??la\currentlanguage][#1]%
+ \docomplexlanguage
+ \fi}
+\setuplanguage
+ [\s!default]
+ [\s!lefthyphenmin=2,
+ \s!righthyphenmin=2,
+ \s!patterns=,
+ \c!spacing=\v!packed,
+ \c!lefthyphen=,
+ \c!righthyphen=-,
+ \c!hyphen=-,
+ \c!midsentence=---,
+ \c!leftsentence=---,
+ \c!rightsentence=---,
+ \c!leftsubsentence=---,
+ \c!rightsubsentence=---,
+ \c!leftquote=\upperleftsinglesixquote,
+ \c!rightquote=\upperrightsingleninequote,
+ \c!leftquotation=\upperleftdoublesixquote,
+ \c!rightquotation=\upperrightdoubleninequote,
+ \c!leftspeech=\languageparameter\c!leftquotation,
+ \c!middlespeech=,
+ \c!rightspeech=\languageparameter\c!rightquotation,
+ \c!limittext=\unknown,
+ \c!date={\v!year,\ ,\v!month,\ ,\v!day},
+ \c!text=Ag]
-\def\loadspellchecklist
- {\dodoubleempty\doloadspellchecklist}
+% rather new, split and per language
+
+\setuplanguage
+ [\s!default]
+ [\c!compoundhyphen=\compoundhyphen,
+ \c!leftcompoundhyphen=\compoundhyphen,
+ \c!rightcompoundhyphen=]
+
+%D The values \type {leftsentence} and \type
+%D {rightsentence} can be (and are) used to implement
+%D automatic subsentence boundary glyphs, like in {\fr
+%D |<|french guillemots|>|} or {\de |<|german guillemots|>|} or
+%D {\nl |<|dutch dashes|>|} like situations. Furthermore \type
+%D {leftquotation} and \type {leftquote} come into view
+%D \quotation {when we quote} or \quote {quote} something.
+
+%D \macros
+%D {currentdatespecification}
+%D
+%D Just to make things easy we can ask for the current date
+%D specification by saying:
+
+\def\currentdatespecification{\languageparameter\c!date}
+
+%D This command is not meant for users.
+
+%D Carefull reading of these macros shows that it's legal to
+%D say
+%D
+%D \starttyping
+%D \installlanguage [du] [de]
+%D \stoptyping
+
+%D \macros
+%D {language,mainlanguage}
+%D
+%D Switching to another language (actually another hyphenation
+%D pattern) is done with:
+%D
+%D \starttyping
+%D \language[identifier]
+%D \stoptyping
+%D
+%D or with \type{\identifier}. Just to be compatible with
+%D \PLAIN\ \TEX, we still support the original meaning, so
+%D
+%D \starttyping
+%D \language=1
+%D \stoptyping
+%D
+%D is a valid operation, where the relation between number
+%D and language depends on the order in installing languages.
+%D
+%D \showsetup{language}
+%D \showsetup{mainlanguage}
+%D
+%D Both commands take a predefined language identifier as
+%D argument. We can use \type{\mainlanguage[identifier]} for
+%D setting the (indeed) main language. This is the language
+%D used for translating labels like {\em figure} and {\em
+%D table}. The main language defaults to the current language.
+%D
+%D We take care of local as well as standardized language
+%D switching (fr and fa, de and du, but nl and nl).
+
+\def\dosetnormallanguage#1#2% current default
+ {\edef\askedlanguagepatterns{\specificlanguageparameter{#1}\s!patterns}%
+ \normallanguage=\ctxlua{tex.sprint(languages.enable({"\askedlanguagepatterns","#1","\askedlanguagepatterns","#2"}))}%
+ \ifproductionrun
+ \setxvalue{\??la\??la#1#2}{\number\normallanguage}%
+ \fi}
+
+\def\setnormallanguage#1#2% current default / we can freeze the number here
+ {\ifcsname\??la\??la#1#2\endcsname
+ \normallanguage\csname\??la\??la#1#2\endcsname % todo: we can set language at the lua end now
+ \else
+ \dosetnormallanguage{#1}{#2}%
+ \fi}
+
+\newtoks \everylanguage
+
+\def\disablelanguagespecifics
+ {\ignorecompoundcharacter}
+
+\def\sethyphenationvariables
+ {\lefthyphenmin 0\languageparameter\s!lefthyphenmin \relax
+ \righthyphenmin0\languageparameter\s!righthyphenmin\relax
+ \lefthyphenmin \numexpr\lefthyphenmin +\hyphenminoffset\relax
+ \righthyphenmin\numexpr\righthyphenmin+\hyphenminoffset\relax}
+
+\def\docomplexlanguage% assumes that \currentlanguage is set
+ {\edef\currentdefaultlanguage{\defaultlanguage\currentlanguage}%
+ \setnormallanguage\currentlanguage\currentdefaultlanguage
+ \the\everylanguage
+ \enablelanguagespecifics[\currentlanguage]%
+ \sethyphenationvariables
+ \relax
+ % will be definable and move to core-spa !
+ \doifelse{\languageparameter\c!spacing}\v!broad\nonfrenchspacing\frenchspacing}
+
+\ifx\enablelanguagespecifics\undefined \def\enablelanguagespecifics[#1]{} \fi
+
+% The following may be a solution for the fact that one cannot
+% change catcodes of characters like : and ; inside an environment.
+
+\appendtoks
+ \enablelanguagespecifics[\currentlanguage]%
+\to \everystarttext
+
+\def\complexlanguage[#1]%
+ {\edef\askedlanguage{#1}%
+ \ifx\askedlanguage\empty \else
+ \ifcsname\l!prefix!\askedlanguage\endcsname
+ \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
+ \ifx\currentlanguage\askedlanguage \else
+ \setcurrentlanguage\currentmainlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \else
+ \showmessage\m!linguals6{#1}%
+ \fi
+ \fi}
+
+\let\simplelanguage\normallanguage
+
+\definecomplexorsimple\language
+
+\def\mainlanguage[#1]%
+ {\edef\askedlanguage{#1}%
+ \ifx\askedlanguage\empty \else
+ \ifcsname\l!prefix!\askedlanguage\endcsname
+ \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
+ \ifx\currentlanguage\askedlanguage
+ \ifx\currentmainlanguage\askedlanguage
+ \else
+ \setcurrentlanguage\askedlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \else
+ \setcurrentlanguage\askedlanguage\askedlanguage
+ \docomplexlanguage
+ \fi
+ \fi
+ \fi}
+
+%D \macros
+%D {defaultlanguage,languageparameter,specificlanguageparameter}
+
+\def\defaultlanguage#1%
+ {\ifcsname\??la#1\s!default\endcsname
+ \expandafter\defaultlanguage\csname\??la#1\s!default\endcsname
+ \else
+ #1%
+ \fi}
+
+\def\languageparameter#1%
+ {\ifcsname\??la\currentlanguage#1\endcsname
+ \csname\??la\currentlanguage#1\endcsname
+ \else\ifcsname\??la\currentlanguage\s!default\endcsname
+ \expandafter\specificlanguageparameter\csname\??la\currentlanguage\s!default\endcsname{#1}%
+ \else\ifcsname\??la\s!default#1\endcsname
+ \csname\??la\s!default#1\endcsname
+ \fi\fi\fi}
+
+\def\specificlanguageparameter#1#2%
+ {\ifcsname\??la#1#2\endcsname
+ \csname\??la#1#2\endcsname
+ \else\ifcsname\??la#1\s!default\endcsname
+ \expandafter\specificlanguageparameter\csname\??la#1\s!default\endcsname{#2}%
+ \else\ifcsname\??la\s!default#2\endcsname
+ \csname\??la\s!default#2\endcsname
+ \fi\fi\fi}
+
+%D New (see nomarking and nolist):
+
+\def\splitsequence#1#2%
+ {\doifelse{#1}\v!no{#2}{\doifelse{#1}\v!yes{\languageparameter\c!limittext}{#1}}}
+
+\def\splitsymbol#1%
+ {\splitsequence{#1}{\languageparameter\c!limittext}}
+
+%D Just like with subsentence boundary symbols, quotes
+%D placement depends on the current language, therefore we show
+%D the defaults here.
+%D
+%D \def\ShowLanguageValues [#1] [#2] #3 #4
+%D {\blank
+%D \startlinecorrection
+%D \vbox\bgroup
+%D \language[#1]%
+%D \setbox0=\hbox to \hsize{\hss\bf#2 subsentence symbol and quotes\hss}
+%D \dp0=0pt
+%D \box0
+%D \vskip.5em
+%D \hrule
+%D \vskip.5em
+%D \let\normalbar=|
+%D \hbox to \hsize
+%D {\hfil\quotation{#3 #4}\hfil\quote{#2}\hfil
+%D \let|=\normalbar\strut|<||<|#3|>|#4|>|\hfil}
+%D \vskip.5em
+%D \hrule
+%D \egroup
+%D \stoplinecorrection
+%D \blank}
+%D
+%D \ShowLanguageValues [af] [afrikaans] afrikaanse ...
+%D \ShowLanguageValues [ca] [catalan] catalan ...
+%D \ShowLanguageValues [cs] [czech] tjechisch tex
+%D \ShowLanguageValues [cs] [slovak] slowaakse ...
+%D \ShowLanguageValues [da] [danish] deense ...
+%D \ShowLanguageValues [de] [german] duitse degelijkheid
+%D \ShowLanguageValues [en] [english] engelse humor
+%D \ShowLanguageValues [fi] [finnish] finse ...
+%D \ShowLanguageValues [fr] [french] franse slag
+%D \ShowLanguageValues [it] [italian] italiaanse ...
+%D \ShowLanguageValues [la] [latin] latijnse missen
+%D \ShowLanguageValues [nl] [dutch] nederlandse zuinigheid
+%D \ShowLanguageValues [nb] [bokmal] noorse zalm
+%D \ShowLanguageValues [nn] [nnynorsk] noorse zalm
+%D \ShowLanguageValues [pl] [polish] poolse vlag
+%D \ShowLanguageValues [pt] [portuguese] portugese ...
+%D \ShowLanguageValues [es] [spanish] spaans benauwd
+%D \ShowLanguageValues [sv] [swedish] zweedse ...
+%D \ShowLanguageValues [tr] [turkish] turks fruit
+
+%D We support a lot of languages. These are specified and
+%D loaded in separate files, according to their roots. Here
+%D we only take care of (postponed) setting of the current
+%D language.
+%D
+%D \unprotect
+%D \placetable{The germanic languages (\type{lang-ger})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!nl \NC dutch \NC germanic \NC\FR
+%D \NC \s!en \NC english \NC germanic \NC\MR
+%D \NC \s!de \NC german \NC germanic \NC\MR
+%D \NC \s!da \NC danish \NC germanic \NC\MR
+%D \NC \s!sv \NC swedish \NC germanic \NC\MR
+%D \NC \s!af \NC afrikaans \NC germanic \NC\MR
+%D \NC \s!nb \NC bokmal \NC germanic \NC\LR
+%D \NC \s!nn \NC nynorsk \NC germanic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D
+%D \unprotect
+%D \placetable{The italic languages (\type{lang-ita})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!fr \NC french \NC italic \NC\FR
+%D \NC \s!ca \NC catalan \NC italic \NC\MR
+%D \NC \s!es \NC spanish \NC italic \NC\MR
+%D \NC \s!it \NC italian \NC italic \NC\MR
+%D \NC \s!la \NC latin \NC italic \NC\MR
+%D \NC \s!pt \NC portuguese \NC italic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D
+%D \unprotect
+%D \placetable{The slavic languages (\type{lang-sla})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!pl \NC polish \NC slavic \NC\FR
+%D \NC \s!cs \NC czech \NC slavic \NC\MR
+%D \NC \s!sk \NC slavik \NC slavic \NC\LR
+%D \HL
+%D \stoptable
+%D \protect
+%D \unprotect
+%D
+%D \placetable{The altaic languages (\type{lang-alt})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!tr \NC turkish \NC altaic \NC\SR
+%D \HL
+%D \stoptable
+%D
+%D \placetable{The uralic languages (\type{lang-ura})}
+%D \starttable[||||]
+%D \HL
+%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
+%D \HL
+%D \NC \s!fi \NC finnish \NC uralic \NC\SR
+%D \HL
+%D \stoptable
+%D \protect
+
+% \bgroup \normallanguage255 \patterns{} \egroup
+% \def\nopatterns{\normallanguage255 }
+
+\def\nopatterns{\normallanguage\minusone}
+
+%D We default to the language belonging to the interface. This
+%D is one of the few places outside the interface modules where
+%D \type{\startinterface} is used.
+
+%D We default to english:
+
+\setupcurrentlanguage[\s!en]
+
+\def\initializemainlanguage
+ {\mainlanguage[\currentlanguage]%
+ \showmessage\m!linguals9\currentlanguage}
+
+%D Might be in use:
+
+\let\preloadallpatterns\relax % just for old times sake
+\let\preloadlanguages \relax % just for old times sake
+
+%D This might bexcome a seperate file:
% mkiv only -- todo: internationalize command names
% \loadspellchecklist[en][words-en.txt]
+% \loadspellchecklist[us][words-en.txt]
% \loadspellchecklist[nl][words-nl.txt]
% \setupspellchecking[state=start]
-\def\loadspellchecklist[#1][#2]%
+\def\loadspellchecklist
+ {\dodoubleempty\doloadspellchecklist}
+
+\def\doloadspellchecklist[#1][#2]%
{\ctxlua{languages.words.load("#1","#2")}}
\def\setupspellchecking
diff --git a/tex/context/base/lang-ini.tex b/tex/context/base/lang-ini.tex
deleted file mode 100644
index 17393da33..000000000
--- a/tex/context/base/lang-ini.tex
+++ /dev/null
@@ -1,692 +0,0 @@
-%D \module
-%D [ file=lang-ini,
-%D version=1996.01.25,
-%D title=\CONTEXT\ Language Macros,
-%D subtitle=Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This module needs a further cleanup (real split between ii/iv).
-
-%D This module implements the (for the moment still simple)
-%D multi||language support of \CONTEXT, which should not be
-%D confused with the multi||lingual interface. This support
-%D will be extended when needed.
-
-\writestatus{loading}{Context Language Macros / Initialization}
-
-\startmessages dutch library: linguals
- title: taal
- 1: afbreekpatronen -- voor -- geladen (n=--,e=--,m=--)
- 2: geen afbreekpatronen -- voor -- (n=--,e=--,m=--) (--,--)
- 3: afbreekdefinities -- voor -- geladen (n=--,e=--,m=--)
- 4: geen afbreekdefinities -- voor -- (n=--,e=--,m=--)
- 5: afbreekpatronen voor -- niet geladen
- 6: taal -- is niet gedefinieerd
- 7: taal specifieke opties [--] introduceren een skip van --
- 8: taal specifieke opties [--] naadloos toegevoegd
- 9: taal -- is actief
- 10: patronen --geladen
-\stopmessages
-
-\startmessages english library: linguals
- title: language
- 1: patterns -- for -- loaded (n=--,e=--,m=--)
- 2: no patterns -- for -- (n=--,e=--,m=--) (--,--)
- 3: hyphenations -- for -- loaded (n=--,e=--,m=--)
- 4: no hyphenations -- for -- (n=--,e=--,m=--)
- 5: patterns for -- not loaded
- 6: language -- is undefined
- 7: language specific options [--] introduce a -- skip
- 8: language specific options [--] seamless appended
- 9: language -- is active
- 10: patterns --loaded
-\stopmessages
-
-\startmessages german library: linguals
- title: Sprache
- 1: Trennmuster -- fuer -- geladen (n=--,e=--,m=--)
- 2: Keine Trennmuster -- fuer -- (n=--,e=--,m=--) (--,--)
- 3: Trenndefinitionen -- fuer -- geladen (n=--,e=--,m=--)
- 4: Keine Trenndefinitionen -- fuer -- (n=--,e=--,m=--)
- 5: Trennmuster fuer -- nicht geladen
- 6: Sprache -- ist undefiniert
- 7: Sprachenspezifische Option [--] fuegt eine Luecke von -- ein
- 8: Sprachenspezifische Option [--] nahtlos hinzugefuegt
- 9: Sprache -- ist aktiv
- 10: Trennmuster --geladen
-\stopmessages
-
-% TOM: 9 and 10
-
-\startmessages czech library: linguals
- title: jazyky
- 1: vzory -- pro -- nacteny (n=--,e=--,m=--)
- 2: zadne vzory -- pro -- (n=--,e=--,m=--) (--,--)
- 3: deleni slov -- pro -- nacteno (n=--,e=--,m=--)
- 4: zadne deleni slov -- pro -- (n=--,e=--,m=--)
- 5: vzory pro -- nenacteny
- 6: jazyk -- neni definovan
- 7: specificke volby jazyka [--] zavadeji -- (zavlecenou) mezeru
- 8: specificke volby jazyka [--] bez mezer pripojeny
- 9: language -- is active
- 10: vzory --nacteny
-\stopmessages
-
-\startmessages italian library: linguals
- title: lingua
- 1: schemi -- per -- caricati (n=--,e=--,m=--)
- 2: niente schemi -- per -- (n=--,e=--,m=--) (--,--)
- 3: sillabazione -- per -- caricata (n=--,e=--,m=--)
- 4: niente sillabazione -- per -- (n=--,e=--,m=--)
- 5: schemi per -- non caricati
- 6: lingua -- non definita
- 7: opzioni specifiche per la lingua [--] introducono un salto --
- 8: opzioni specifiche per la lingua [--] aggiunte trasparentemente
- 9: lingua -- attiva
- 10: schemi -- caricati
-\stopmessages
-
-\startmessages norwegian library: linguals
- title: sprøk
- 1: orddelingsmønster -- for -- er lest inn (n=--,e=--,m=--)
- 2: ingen orddelingsmønster -- for -- (n=--,e=--,m=--) (--,--)
- 3: orddelingsdefinisjon -- for -- er lest inn (n=--,e=--,m=--)
- 4: ingen orddelingsdefinisjon -- for -- (n=--,e=--,m=--)
- 5: orddelingsmønster for -- er ikke lest inn
- 6: spràk -- er udefinert
- 7: spràk spesifikk opsjon [--] introduserer et -- hopp
- 8: spràk spesifikk opsjon [--] problemfritt tilføyd
- 9: spràk -- er aktivt
- 10: orddelingsmønster -- er lest inn
-\stopmessages
-
-\startmessages romanian library: linguals
- title: limbi
- 1: sablonul -- pentru -- s-a incarcat (n=--,e=--,m=--)
- 2: nu exista sabloane -- pentru -- (n=--,e=--,m=--) (--,--)
- 3: despartirea in silabe -- pentru -- s-a incarcat (n=--,e=--,m=--)
- 4: nu exista despartire in silabe -- pentru -- (n=--,e=--,m=--)
- 5: sabloanele pentru -- nu sunt incarcate
- 6: limba -- nu este definita
- 7: optiunile specifice ale limbii [--] introduc un spatiu --
- 8: optiunile specifice ale limbii [--] adaugate
- 9: limba -- este activa
- 10: sabloanele -- incarcate
-\stopmessages
-
-\startmessages french library: linguals
- title: langue
- 1: les motifs -- pour -- sont chargés (n=--,e=--,m=--)
- 2: pas de motifs -- pour -- (n=--,e=--,m=--) (--,--)
- 3: hyphenations -- pour -- chargés (n=--,e=--,m=--)
- 4: pas d'hyphenations -- pour -- (n=--,e=--,m=--)
- 5: les motifs pour -- ne sont pas chargés
- 6: langue -- non définie
- 7: les options spécifiques de langue [--] introduisent un -- saut
- 8: les options spécifiques de langue [--] sont ajoutés en douceur
- 9: la langue -- est active
- 10: motifs -- chargés
-\stopmessages
-
-\unprotect
-
-\ifx\nonfrenchspacing\undefined \let\nonfrenchspacing\relax \fi
-\ifx\frenchspacing \undefined \let\frenchspacing \relax \fi
-
-%D When loading hyphenation patterns, \TEX\ assign a number to
-%D each loaded table, starting with~0. Switching to a specific
-%D table is done by assigning the relevant number to the
-%D predefined \COUNTER\ \type{\language}. Unfortunately the
-%D name of this command suits very well the name of the
-%D language switching command we are to define, so let's save
-%D this primitive under another name:
-
-\let\normallanguage\language
-
-%D We keep track of the last loaded patterns by means of a
-%D pseudo \COUNTER. This just one of those situations in which
-%D we don't want to spent a real one. Language zero has no
-%D patterns, first of all because I like to start numbering
-%D at one. It may come in handy for special purposes as well.
-
-\normallanguage\zerocount \def\loadedlanguage{1}
-
-%D \macros
-%D {currentlanguage, setupcurrentlanguage}
-%D
-%D Instead of numbers,we are going to use symbolic names for
-%D the languages. The current langage is saved in the macro
-%D \type {\currentlanguage}. The setup macro is mainly used
-%D for cosmetic purposes.
-%D
-%D \starttyping
-%D \dorecurse{3}
-%D {\language[nl]
-%D \startmode[*en] english \stopmode
-%D \startmode[*nl] dutch \stopmode
-%D \language[en]
-%D \startmode[*en] english \stopmode
-%D \startmode[*nl] dutch \stopmode}
-%D \stoptyping
-
-\let\currentlanguage \empty
-\let\currentmainlanguage\empty
-
-\def\setupcurrentlanguage[#1]{\setcurrentlanguage\currentmainlanguage{#1}}
-
-\def\setcurrentlanguage#1#2% sets modes: **id (currentmain) *id (current)
- {\doifsomething{#1}
- {\ifx\currentmainlanguage\empty\else\resetsystemmode{\systemmodeprefix\currentmainlanguage}\fi
- \edef\currentmainlanguage{#1}%
- \setsystemmode{\systemmodeprefix\currentmainlanguage}}%
- \doifsomething{#2}
- {\ifx\currentlanguage\empty\else\resetsystemmode\currentlanguage\fi
- \edef\currentlanguage{#2}%
- \setsystemmode\currentlanguage}}
-
-%D The internal macros will be defined later.
-
-%D \macros
-%D {installlanguage}
-%D
-%D Hyphenation patterns can only be loaded when the format file
-%D is prepared. The next macro takes care of this loading. A
-%D language is specified with
-%D
-%D \showsetup{installlanguage}
-%D
-%D When \type {state} equals \type {start}, both patterns
-%D and additional hyphenation specifications are loaded. These
-%D files are seached for on the system path and are to be
-%D named:
-%D
-%D \starttyping
-%D \f!languageprefix-identifier.\f!patternsextension
-%D \f!languageprefix-identifier.\f!hyhensextension
-%D \stoptyping
-%D
-%D The \type{spacing} variable specifies how the spaces after
-%D punctuation has to be handled. English is by tradition more
-%D tolerant to inter||sentence spacing than other languages.
-%D
-%D This macro also defines \type {\identifier} as a shortcut
-%D switch to the language. Furthermore the command defined as
-%D being language specific, are executed. With
-%D \type {default} we can default to another language
-%D (patterns) at format generation time. This default language
-%D is overruled when the appropriate patterns are loaded (some
-%D implementations support run time addition of patterns to a
-%D preloaded format).
-
-\def\dodoinstalllanguage#1#2% #2 added
- {\doifundefined{#1}{\setvalue{#1}{\complexlanguage[#2]}}%
- \expanded{\noexpand\uppercase{\noexpand\edef\noexpand\ascii{#1}}}%
- \doifundefined\ascii{\setvalue\ascii{\complexlanguage[#2]}}}
-
-%D \macros
-%D {preloadlanguages}
-%D
-%D We first try to load the files defined as file synonym
-%D for \type {lang-*.pat} and \type {lang-*.hyp}. After that we
-%D fall back on those files. The macro \type {\preloadpatterns}
-%D reports which patterns are loaded and what hyphenmin
-%D values are set.
-
-\let\installedlanguages\empty
-
-\def\doiflanguageelse#1{\doifdefinedelse{\??la#1\c!state}}
-
-\ifx\mkloadlanguagefiles\undefined \let\mkloadlanguagefiles\gobbleoneargument \fi
-
-\def\doinstalllanguage[#1][#2]% some day we will make one for mkii and mkiv
- {\doifassignmentelse{#2}
- {\doiflanguageelse{#1}
- {\getparameters[\??la#1][#2]}
- {\setvalue{\l!prefix!#1}{#1}%
- \addtocommalist{#1}\installedlanguages
- \dodoinstalllanguage{#1}{#1}%
- \getparameters
- [\??la#1]
- [\c!state=\v!stop,
- \c!default=,
- \s!patterns=,
- \s!mapping=,
- \s!encoding=,
- \s!lefthyphenmin=\defaultlanguageparameter\s!lefthyphenmin,
- \s!righthyphenmin=\defaultlanguageparameter\s!righthyphenmin,
- #2]}%
- \doifvalue{\??la#1\c!default}{#1}{\letvalue{\??la#1\c!default}\empty}%
- % loop in deo: \doifvalue{\??la#1\s!patterns}{#1}{\letvalue{\??la#1\c!default}\empty}%
- \mkloadlanguagefiles{#1}}
- {\setvalue{\l!prefix!#1}{#2}%
- \dodoinstalllanguage{#1}{#2}}}
-
-\def\reallanguagetag#1%
- {\ifcsname\l!prefix!#1\endcsname
- %\expandafter\reallanguagetag\csname\l!prefix!#1\endcsname % evt undefined en dan wel
- \csname\l!prefix!#1\endcsname
- \else
- #1%
- \fi}
-
-% ^^ \language[#1] gave unwanted side effect of loading language specifics
-
-\def\installlanguage
- {\dodoubleargument\doinstalllanguage}
-
-%D When the second argument is a language identifier, a
-%D synonym is created. This feature is present because we
-%D used dutch mnemonics in the dutch version, but nowadays
-%D conform a standard.
-
-\let \patternencoding \s!default
-\let \patternmapping \s!default
-
-\ifx\mkloadpatterns \undefined \let\mkloadpatterns \gobbletwoarguments \fi
-\ifx\mkdoifpatternselse\undefined \let\mkdoifpatternselse\gobbletwoarguments \fi
-
-\def\doloadpatterns {\mkdoloadpatterns}
-\def\doifpatternselse{\mkdoifpatternselse}
-
-%D \macros
-%D {setuplanguage}
-%D
-%D Quick and dirty, but useful:
-%D
-%D \showsetup{setuplanguage}
-%D
-%D Beware, this command can only be used when a language is installed.
-
-\unprotected \def\setuplanguage
- {\dodoubleempty\dosetuplanguage}
-
-\def\dosetuplanguage[#1][#2]% handy patch for testing
- {\ifsecondargument
- \getparameters[\??la#1][#2]%
- \doif{#1}\currentlanguage\docomplexlanguage
- \else
- \getparameters[\??la\currentlanguage][#1]%
- \docomplexlanguage
- \fi}
-
-\setuplanguage
- [\s!default]
- [\s!lefthyphenmin=2,
- \s!righthyphenmin=2,
- \c!spacing=\v!packed,
- \c!lefthyphen=,
- \c!righthyphen=-,
- \c!hyphen=-,
- \c!midsentence=---,
- \c!leftsentence=---,
- \c!rightsentence=---,
- \c!leftsubsentence=---,
- \c!rightsubsentence=---,
- \c!leftquote=\upperleftsinglesixquote,
- \c!rightquote=\upperrightsingleninequote,
- \c!leftquotation=\upperleftdoublesixquote,
- \c!rightquotation=\upperrightdoubleninequote,
- \c!leftspeech=\languageparameter\c!leftquotation,
- \c!middlespeech=,
- \c!rightspeech=\languageparameter\c!rightquotation,
- \c!limittext=\unknown,
- \c!date={\v!year,\ ,\v!month,\ ,\v!day},
- \c!text=Ag]
-
-% rather new, split and per language
-
-\setuplanguage
- [\s!default]
- [\c!compoundhyphen=\compoundhyphen,
- \c!leftcompoundhyphen=\compoundhyphen,
- \c!rightcompoundhyphen=]
-
-%D The values \type {leftsentence} and \type
-%D {rightsentence} can be (and are) used to implement
-%D automatic subsentence boundary glyphs, like in {\fr
-%D |<|french guillemots|>|} or {\de |<|german guillemots|>|} or
-%D {\nl |<|dutch dashes|>|} like situations. Furthermore \type
-%D {leftquotation} and \type {leftquote} come into view
-%D \quotation {when we quote} or \quote {quote} something.
-
-%D \macros
-%D {currentdatespecification}
-%D
-%D Just to make things easy we can ask for the current date
-%D specification by saying:
-
-\def\currentdatespecification{\languageparameter\c!date}
-
-%D This command is not meant for users.
-
-%D Carefull reading of these macros shows that it's legal to
-%D say
-%D
-%D \starttyping
-%D \installlanguage [du] [de]
-%D \stoptyping
-
-%D \macros
-%D {language,mainlanguage}
-%D
-%D Switching to another language (actually another hyphenation
-%D pattern) is done with:
-%D
-%D \starttyping
-%D \language[identifier]
-%D \stoptyping
-%D
-%D or with \type{\identifier}. Just to be compatible with
-%D \PLAIN\ \TEX, we still support the original meaning, so
-%D
-%D \starttyping
-%D \language=1
-%D \stoptyping
-%D
-%D is a valid operation, where the relation between number
-%D and language depends on the order in installing languages.
-%D
-%D \showsetup{language}
-%D \showsetup{mainlanguage}
-%D
-%D Both commands take a predefined language identifier as
-%D argument. We can use \type{\mainlanguage[identifier]} for
-%D setting the (indeed) main language. This is the language
-%D used for translating labels like {\em figure} and {\em
-%D table}. The main language defaults to the current language.
-%D
-%D We take care of local as well as standardized language
-%D switching (fr and fa, de and du, but nl and nl).
-
-\ifx\synchronizepatterns \undefined \let\synchronizepatterns\relax \fi
-\ifx\synchronizepatternswithfont\undefined \def\synchronizepatternswithfont{\synchronizepatterns} \fi
-
-\ifx\mksetnormallanguage\undefined \let\mksetnormallanguage\gobbletwoarguments \fi
-
-\def\setnormallanguage{\mksetnormallanguage}
-
-\newevery \everylanguage \relax
-\newevery \everyresetlanguagespecifics \relax
-
-\def\disablelanguagespecifics
- {\ignorecompoundcharacter}
-
-\def\sethyphenationvariables
- {\lefthyphenmin 0\languageparameter\s!lefthyphenmin \relax
- \righthyphenmin0\languageparameter\s!righthyphenmin\relax
- \lefthyphenmin \numexpr\lefthyphenmin +\hyphenminoffset\relax
- \righthyphenmin\numexpr\righthyphenmin+\hyphenminoffset\relax}
-
-\def\docomplexlanguage% assumes that \currentlanguage is set
- {\edef\currentdefaultlanguage{\defaultlanguage\currentlanguage}%
- \mksetnormallanguage\currentlanguage\currentdefaultlanguage
- \the\everylanguage
- \enablelanguagespecifics[\currentlanguage]%
- \sethyphenationvariables
- \relax
- % will be definable and move to core-spa !
- \doifelse{\languageparameter\c!spacing}\v!broad
- \nonfrenchspacing\frenchspacing}
-
-\ifx\enablelanguagespecifics\undefined \def\enablelanguagespecifics[#1]{} \fi
-
-% The following may be a solution for the fact that one cannot
-% change catcodes of characters like : and ; inside an environment.
-
-\appendtoks
- \enablelanguagespecifics[\currentlanguage]%
-\to \everystarttext
-
-\def\complexlanguage[#1]%
- {\edef\askedlanguage{#1}%
- \ifx\askedlanguage\empty \else
- \ifcsname\l!prefix!\askedlanguage\endcsname
- \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
- \ifx\currentlanguage\askedlanguage \else
- \setcurrentlanguage\currentmainlanguage\askedlanguage
- \docomplexlanguage
- \fi
- \else
- \showmessage\m!linguals6{#1}%
- \fi
- \fi}
-
-\let\simplelanguage\normallanguage
-
-\definecomplexorsimple\language
-
-% \def\mainlanguage[#1]%
-% {\edef\askedlanguage{#1}%
-% \ifx\askedlanguage\empty \else
-% \ifcsname\l!prefix!\askedlanguage\endcsname
-% \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
-% \ifx\currentmainlanguage\askedlanguage \else
-% \setcurrentlanguage\askedlanguage\askedlanguage
-% \docomplexlanguage
-% \fi
-% \fi
-% \fi}
-
-\def\mainlanguage[#1]%
- {\edef\askedlanguage{#1}%
- \ifx\askedlanguage\empty \else
- \ifcsname\l!prefix!\askedlanguage\endcsname
- \edef\askedlanguage{\csname\l!prefix!\askedlanguage\endcsname}%
- \ifx\currentlanguage\askedlanguage
- \ifx\currentmainlanguage\askedlanguage
- \else
- \setcurrentlanguage\askedlanguage\askedlanguage
- \docomplexlanguage
- \fi
- \else
- \setcurrentlanguage\askedlanguage\askedlanguage
- \docomplexlanguage
- \fi
- \fi
- \fi}
-
-%D \macros
-%D {defaultlanguage,languagedefault}
-%D
-%D The macro \type {\defaultlanguage{id}} expands into the
-%D default language, when defined, while \type
-%D {\languagedefault{id}\c!parameter} returns the default's
-%D parameter.
-
-\def\defaultlanguage#1%
- {\@EA\ifx\csname\??la#1\c!default\endcsname\empty
- #1%
- \else
- \@EA\defaultlanguage\csname\??la#1\c!default\endcsname
- \fi}
-
-\def\languagedefault#1#2%
- {\csname\??la\defaultlanguage{#1}#2\endcsname}
-
-\def\languageparameter % @EA = speedup
- {\@EA\dolanguageparameter\@EA{\defaultlanguage\currentlanguage}}
-
-\def\specificlanguageparameter#1% @EA = speedup
- {\@EA\dospecificlanguageparameter\@EA{\defaultlanguage{#1}}{#1}}
-
-\def\xxlanguageparameter#1% @EA = speedup
- {\@EA\dolanguageparameter\@EA{\defaultlanguage{#1}}}
-
-\def\defaultlanguageparameter#1%
- {\csname\??la\s!default#1\endcsname}
-
-\def\dolanguageparameter#1#2%
- {\csname\??la
- \ifcsname\??la\currentlanguage#2\endcsname
- \currentlanguage
- \else\ifcsname\??la#1#2\endcsname
- \@EA\ifx\csname\??la#1#2\endcsname\empty\s!default\else#1\fi
- \else
- \s!default
- \fi\fi
- #2\endcsname}
-
-\def\dospecificlanguageparameter#1#2#3%
- {\csname\??la
- \ifcsname\??la#2#3\endcsname
- \@EA\ifx\csname\??la#2#3\endcsname\empty\s!default\else#2\fi
- \else\ifcsname\??la#1#3\endcsname
- \@EA\ifx\csname\??la#1#3\endcsname\empty\s!default\else#1\fi
- \else
- \s!default
- \fi\fi
- #3\endcsname}
-
-%D New (see nomarking and nolist):
-
-\def\splitsequence#1#2%
- {\doifelse{#1}\v!no{#2}{\doifelse{#1}\v!yes{\languageparameter\c!limittext}{#1}}}
-
-\def\splitsymbol#1%
- {\splitsequence{#1}{\languageparameter\c!limittext}}
-
-%D Just like with subsentence boundary symbols, quotes
-%D placement depends on the current language, therefore we show
-%D the defaults here.
-%D
-%D \def\ShowLanguageValues [#1] [#2] #3 #4
-%D {\blank
-%D \startlinecorrection
-%D \vbox\bgroup
-%D \language[#1]%
-%D \setbox0=\hbox to \hsize{\hss\bf#2 subsentence symbol and quotes\hss}
-%D \dp0=0pt
-%D \box0
-%D \vskip.5em
-%D \hrule
-%D \vskip.5em
-%D \let\normalbar=|
-%D \hbox to \hsize
-%D {\hfil\quotation{#3 #4}\hfil\quote{#2}\hfil
-%D \let|=\normalbar\strut|<||<|#3|>|#4|>|\hfil}
-%D \vskip.5em
-%D \hrule
-%D \egroup
-%D \stoplinecorrection
-%D \blank}
-%D
-%D \ShowLanguageValues [af] [afrikaans] afrikaanse ...
-%D \ShowLanguageValues [ca] [catalan] catalan ...
-%D \ShowLanguageValues [cs] [czech] tjechisch tex
-%D \ShowLanguageValues [cs] [slovak] slowaakse ...
-%D \ShowLanguageValues [da] [danish] deense ...
-%D \ShowLanguageValues [de] [german] duitse degelijkheid
-%D \ShowLanguageValues [en] [english] engelse humor
-%D \ShowLanguageValues [fi] [finnish] finse ...
-%D \ShowLanguageValues [fr] [french] franse slag
-%D \ShowLanguageValues [it] [italian] italiaanse ...
-%D \ShowLanguageValues [la] [latin] latijnse missen
-%D \ShowLanguageValues [nl] [dutch] nederlandse zuinigheid
-%D \ShowLanguageValues [nb] [bokmal] noorse zalm
-%D \ShowLanguageValues [nn] [nnynorsk] noorse zalm
-%D \ShowLanguageValues [pl] [polish] poolse vlag
-%D \ShowLanguageValues [pt] [portuguese] portugese ...
-%D \ShowLanguageValues [es] [spanish] spaans benauwd
-%D \ShowLanguageValues [sv] [swedish] zweedse ...
-%D \ShowLanguageValues [tr] [turkish] turks fruit
-
-%D We support a lot of languages. These are specified and
-%D loaded in separate files, according to their roots. Here
-%D we only take care of (postponed) setting of the current
-%D language.
-%D
-%D \unprotect
-%D \placetable{The germanic languages (\type{lang-ger})}
-%D \starttable[||||]
-%D \HL
-%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
-%D \HL
-%D \NC \s!nl \NC dutch \NC germanic \NC\FR
-%D \NC \s!en \NC english \NC germanic \NC\MR
-%D \NC \s!de \NC german \NC germanic \NC\MR
-%D \NC \s!da \NC danish \NC germanic \NC\MR
-%D \NC \s!sv \NC swedish \NC germanic \NC\MR
-%D \NC \s!af \NC afrikaans \NC germanic \NC\MR
-%D \NC \s!nb \NC bokmal \NC germanic \NC\LR
-%D \NC \s!nn \NC nynorsk \NC germanic \NC\LR
-%D \HL
-%D \stoptable
-%D \protect
-%D
-%D \unprotect
-%D \placetable{The italic languages (\type{lang-ita})}
-%D \starttable[||||]
-%D \HL
-%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
-%D \HL
-%D \NC \s!fr \NC french \NC italic \NC\FR
-%D \NC \s!ca \NC catalan \NC italic \NC\MR
-%D \NC \s!es \NC spanish \NC italic \NC\MR
-%D \NC \s!it \NC italian \NC italic \NC\MR
-%D \NC \s!la \NC latin \NC italic \NC\MR
-%D \NC \s!pt \NC portuguese \NC italic \NC\LR
-%D \HL
-%D \stoptable
-%D \protect
-%D
-%D \unprotect
-%D \placetable{The slavic languages (\type{lang-sla})}
-%D \starttable[||||]
-%D \HL
-%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
-%D \HL
-%D \NC \s!pl \NC polish \NC slavic \NC\FR
-%D \NC \s!cs \NC czech \NC slavic \NC\MR
-%D \NC \s!sk \NC slavik \NC slavic \NC\LR
-%D \HL
-%D \stoptable
-%D \protect
-%D \unprotect
-%D
-%D \placetable{The altaic languages (\type{lang-alt})}
-%D \starttable[||||]
-%D \HL
-%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
-%D \HL
-%D \NC \s!tr \NC turkish \NC altaic \NC\SR
-%D \HL
-%D \stoptable
-%D
-%D \placetable{The uralic languages (\type{lang-ura})}
-%D \starttable[||||]
-%D \HL
-%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
-%D \HL
-%D \NC \s!fi \NC finnish \NC uralic \NC\SR
-%D \HL
-%D \stoptable
-%D \protect
-
-% \bgroup \normallanguage255 \patterns{} \egroup
-% \def\nopatterns{\normallanguage255 }
-
-\def\nopatterns{\normallanguage\minusone}
-
-%D Mark plugin:
-
-\loadmarkfile{lang-ini} % not yet
-
-%D We default to the language belonging to the interface. This
-%D is one of the few places outside the interface modules where
-%D \type{\startinterface} is used.
-
-%D We default to english:
-
-\setupcurrentlanguage[\s!en]
-
-\appendtoks\mainlanguage[\currentlanguage]\to\everyjob
-
-\appendtoks\showmessage\m!linguals9\currentlanguage\to\everyjob
-
-\protect \endinput
diff --git a/tex/context/base/lang-ita.tex b/tex/context/base/lang-ita.tex
index 93a169112..ae3b7a514 100644
--- a/tex/context/base/lang-ita.tex
+++ b/tex/context/base/lang-ita.tex
@@ -13,7 +13,7 @@
% Todo: replace \'.. by \namedglyph
-\writestatus{loading}{Italic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Italic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -47,7 +47,8 @@
\c!leftquotation=\leftguillemot,
\c!rightquotation=\rightguillemot,
\c!date={\v!day+,\v!space,\v!month,\v!space,\v!year},
- \c!state=\v!stop]
+ \s!mapping={texnansi,ec},
+ \s!encoding={texnansi,ec}]
\installlanguage
[\s!es]
@@ -60,8 +61,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
\installlanguage [sp] [\s!es] % old times context
@@ -76,8 +76,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
% Note GB left|/|right (sub)sentences are for \quote {incisi}.
@@ -96,7 +95,8 @@
\c!middlespeech=\leftguillemot,
\c!rightspeech=\rightguillemot,
\c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={texnansi,ec},
+ \s!encoding={texnansi,ec}]
\installlanguage % the same as italian
[\s!la]
@@ -109,8 +109,7 @@
\c!rightquote=\lowerrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\lowerrightdoubleninequote,
- \c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
\installlanguage
[\s!pt]
@@ -124,7 +123,8 @@
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!year,\ ,\v!month,\ ,\v!day},
- \c!state=\v!stop]
+ \s!mapping={texnansi,ec},
+ \s!encoding={texnansi,ec}]
\installlanguage
[\s!ro]
@@ -137,8 +137,7 @@
\c!rightquote=\rightguillemot,
\c!leftquotation=\lowerrightdoubleninequote,
\c!rightquotation=\upperleftdoublesixquote,
- \c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
%D For compatibility reasons we also define:
@@ -227,8 +226,8 @@
\setupheadtext [\s!ro] [\v!units=Unit\u{a}\c{t}i]
\setuplabeltext [\s!fr] [\v!table=Tableau ]
-\setuplabeltext [\s!es] [\v!table=Tablas ]
-\setuplabeltext [\s!ca] [\v!table=Taules ]
+\setuplabeltext [\s!es] [\v!table=Tabla ]
+\setuplabeltext [\s!ca] [\v!table=Taula ]
\setuplabeltext [\s!it] [\v!table=Tabella ]
\setuplabeltext [\s!la] [\v!table=Tabula ]
\setuplabeltext [\s!pt] [\v!table=Tabela ]
@@ -259,48 +258,48 @@
\setuplabeltext [\s!ro] [\v!graphic=Graficul ]
\setuplabeltext [\s!fr] [\v!chapter=]
-\setuplabeltext [\s!es] [\v!chapter=]
-\setuplabeltext [\s!ca] [\v!chapter=]
+\setuplabeltext [\s!es] [\v!chapter=Cap\'\itulo]
+\setuplabeltext [\s!ca] [\v!chapter=Cap\'\itol]
\setuplabeltext [\s!it] [\v!chapter=]
\setuplabeltext [\s!la] [\v!chapter=]
\setuplabeltext [\s!pt] [\v!chapter=]
\setuplabeltext [\s!ro] [\v!chapter=]
\setuplabeltext [\s!fr] [\v!section=]
-\setuplabeltext [\s!es] [\v!section=]
-\setuplabeltext [\s!ca] [\v!section=]
+\setuplabeltext [\s!es] [\v!section=Secci\'on]
+\setuplabeltext [\s!ca] [\v!section=Secci\'o]
\setuplabeltext [\s!it] [\v!section=]
\setuplabeltext [\s!la] [\v!section=]
\setuplabeltext [\s!pt] [\v!section=]
\setuplabeltext [\s!ro] [\v!section=]
\setuplabeltext [\s!fr] [\v!subsection=]
-\setuplabeltext [\s!es] [\v!subsection=]
-\setuplabeltext [\s!ca] [\v!subsection=]
+\setuplabeltext [\s!es] [\v!subsection=Subsecci\'on]
+\setuplabeltext [\s!ca] [\v!subsection=Subsecci\'o]
\setuplabeltext [\s!it] [\v!subsection=]
\setuplabeltext [\s!la] [\v!subsection=]
\setuplabeltext [\s!pt] [\v!subsection=]
\setuplabeltext [\s!ro] [\v!subsection=]
\setuplabeltext [\s!fr] [\v!subsubsection=]
-\setuplabeltext [\s!es] [\v!subsubsection=]
-\setuplabeltext [\s!ca] [\v!subsubsection=]
+\setuplabeltext [\s!es] [\v!subsubsection=Subsubsecci\'on]
+\setuplabeltext [\s!ca] [\v!subsubsection=Subsubsecci\'o]
\setuplabeltext [\s!it] [\v!subsubsection=]
\setuplabeltext [\s!la] [\v!subsubsection=]
\setuplabeltext [\s!pt] [\v!subsubsection=]
\setuplabeltext [\s!ro] [\v!subsubsection=]
\setuplabeltext [\s!fr] [\v!subsubsubsection=]
-\setuplabeltext [\s!es] [\v!subsubsubsection=]
-\setuplabeltext [\s!ca] [\v!subsubsubsection=]
+\setuplabeltext [\s!es] [\v!subsubsubsection=Subsubsubsecci\'on]
+\setuplabeltext [\s!ca] [\v!subsubsubsection=Subsubsubsecci\'o]
\setuplabeltext [\s!it] [\v!subsubsubsection=]
\setuplabeltext [\s!la] [\v!subsubsubsection=]
\setuplabeltext [\s!pt] [\v!subsubsubsection=]
\setuplabeltext [\s!ro] [\v!subsubsubsection=]
\setuplabeltext [\s!fr] [\v!appendix=]
-\setuplabeltext [\s!es] [\v!appendix=]
-\setuplabeltext [\s!ca] [\v!appendix=]
+\setuplabeltext [\s!es] [\v!appendix=Ap\'endice]
+\setuplabeltext [\s!ca] [\v!appendix=Ap\`endix]
\setuplabeltext [\s!it] [\v!appendix=]
\setuplabeltext [\s!la] [\v!appendix=]
\setuplabeltext [\s!pt] [\v!appendix=]
@@ -479,14 +478,12 @@
%D Rather new \unknown
-\setuplabeltext [\s!it] [\v!page=pagina ]
-\setuplabeltext [\s!it] [\v!atpage=a pagina ]
+\setuplabeltext [\s!it] [\v!page=pagina ]
+\setuplabeltext [\s!it] [\v!atpage=a pagina ]
\setuplabeltext [\s!it] [\v!hencefore=come mostrato sopra]
\setuplabeltext [\s!it] [\v!hereafter=come mostrato sotto]
\setuplabeltext [\s!it] [\v!see=cf. ]
-\setuplabeltext[\s!fr] [\v!see=voir ]
-
%D Ordinal converters:
\def\frordinaldaynumber#1% date is masculine
diff --git a/tex/context/base/lang-jap.tex b/tex/context/base/lang-jap.tex
index ffb53ea70..05c9b1d41 100644
--- a/tex/context/base/lang-jap.tex
+++ b/tex/context/base/lang-jap.tex
@@ -13,7 +13,7 @@
% rgabriel@kerio.com
-\writestatus{loading}{Context Language Macros / Japanese}
+\writestatus{loading}{ConTeXt Language Macros / Japanese}
\unprotect
@@ -29,8 +29,7 @@
\c!rightquote=\jaencoding\jaencodedsingleendquote,
\c!leftquotation=\jaencoding\jaencodedstartquote,
\c!rightquotation=\jaencoding\jaencodedendquote,
- \c!date={\jaencodedchristiandate,\v!year,\jaencodedyear,\v!month,\jaencodedmonth,\v!day,\jaencodedday},
- \c!state=\v!stop]
+ \c!date={\jaencodedchristiandate,\v!year,\jaencodedyear,\v!month,\jaencodedmonth,\v!day,\jaencodedday}]
\setupheadtext [\s!ja] [\v!content={\jaencoding\jaencodedtableofcontents}]
\setupheadtext [\s!ja] [\v!tables={\jaencoding\jaencodedtables}]
diff --git a/tex/context/base/lang-lab.mkii b/tex/context/base/lang-lab.mkii
new file mode 100644
index 000000000..269ac249b
--- /dev/null
+++ b/tex/context/base/lang-lab.mkii
@@ -0,0 +1,295 @@
+%D \module
+%D [ file=lang-lab,
+%D version=1997.08.27,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Labels,
+%D author=Hans Hagen / Tobias Burnus,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\unprotect
+
+%D In this module we deal with language dependant labels and
+%D prefixes, like in {\em Figure~12} and {\em Chapter 1}. In
+%D this file we set the default values. Users can easily
+%D overrule these.
+%D
+%D This module is dedicated to the grandfather of Tobias
+%D Burnus, who's extensive languages oriented library helped us
+%D a lot in finding the right translations. All those labels
+%D are collected in files that reflect their common ancestor.
+%D
+%D Not all languages can be satisfied with the labeling
+%D mechanism as provided here. Chinese for instance put a label
+%D in front as well as after a part number. This is why the
+%D current implementation of labels supports two labels too.
+
+%D \macros
+%D {setupheadtext, setuplabeltext}
+%D
+%D First we present some macros that deal with what we will
+%D call head and label texts. Such texts are defines by:
+%D
+%D \showsetup{setupheadtext}
+%D \showsetup{setuplabeltext}
+%D
+%D In a few paragraphs we'll show quite a lot of examples
+%D of its use.
+
+\let\handletextprefix\relax
+
+\def\setupheadtext {\dosetupsometextprefix[\c!title]}
+\def\setuplabeltext{\dosetupsometextprefix[\c!label]}
+
+\def\dosetupsometextprefix
+ {\let\dodocommand\xdosetupsometextprefix
+ \dotripleempty\dodosetupsometextprefix}
+
+% \def\dodosetupsometextprefix[#1][#2][#3]%
+% {\ifthirdargument
+% \def\docommand##1{\dodocommand[#1#2][##1]}%
+% \processcommalist[#3]\docommand
+% \else
+% \def\docommand##1{\dodocommand[#1\currentmainlanguage][##1]}%
+% \processcommalist[#2]\docommand
+% \fi}
+
+\def\dodosetupsometextprefix[#1][#2][#3]%
+ {\ifthirdargument
+ \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag{#2}]}[##1]}%
+ \processcommalist[#3]\docommand
+ \else
+ \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag\currentmainlanguage]}[##1]}%
+ \processcommalist[#2]\docommand
+ \fi}
+
+\def\doassignsometextprefix[#1][#2,#3,#4]%
+ {\setvalue{#1}{\handletextprefix{#2}{#3}}}
+
+\def\xdosetupsometextprefix[#1][#2=#3]%
+ {\doassignsometextprefix[#1#2][#3,,]}
+
+%D By changing the meaning of \type {\handletextprefix} we
+%D can filter the left and right labeltext as well as convert
+%D labels to uppercase.
+%D
+%D These commands accept all kind of inputs:
+%D
+%D \starttyping
+%D \setuplabeltext [language] [labellabel=text]
+%D \setuplabeltext [language] [labellabel=text,labellabel=text,...]
+%D \setuplabeltext [labellabel=text]
+%D \setuplabeltext [labellabel=text,labellabel=text,...]
+%D \stoptyping
+%D
+%D The last two cases concern the current language.
+
+%D \macros
+%D {headtext,
+%D labeltext, leftlabeltext, rightlabeltext, labeltexts,
+%D LABELTEXT, LEFTLABELTEXT, RIGHTLABELTEXT, LABELTEXTS}
+%D
+%D Once defined, head and label texts can be called upon using:
+%D
+%D \showsetup{headtext}
+%D \showsetup{labeltext}
+%D
+%D The latter one has an upcased alternative \type{\LABELTEXT}.
+
+% \def\labellanguage{\currentmainlanguage}
+% \def\headlanguage {\currentmainlanguage}
+
+% \def\labellanguage{\defaultlanguage\currentmainlanguage}
+% \def\headlanguage {\defaultlanguage\currentmainlanguage}
+
+\def\labellanguage{\reallanguagetag{\defaultlanguage\currentmainlanguage}}
+\def\headlanguage {\reallanguagetag{\defaultlanguage\currentmainlanguage}}
+
+\appendtoks \let\labellanguage\currentlanguage \to \everycurrentdate
+
+\unexpanded\def\headtext
+ {\let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\headlanguage\c!title}
+
+\unexpanded\def\leftlabeltext
+ {\let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label}
+
+\unexpanded\def\rightlabeltext
+ {\let\handletextprefix\secondoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label}
+
+\unexpanded\def\LEFTLABELTEXT
+ {\def\handletextprefix##1##2{\uppercase{##1}}\DOLABELTEXT}
+
+\unexpanded\def\RIGHTLABELTEXT
+ {\def\handletextprefix##1##2{\uppercase{##2}}\DOLABELTEXT}
+
+\def\DOLABELTEXT#1%
+ {\bgroup
+ \the\everyuppercase
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label{#1}% not \labeltext (see \MONTH)
+ \egroup}
+
+\let\labeltext \leftlabeltext
+\let\LABELTEXT \LEFTLABELTEXT
+
+\unexpanded\def\labeltexts#1#2{\leftlabeltext{#1}#2\rightlabeltext{#1}}
+\unexpanded\def\LABELTEXTS#1#2{\LEFTLABELTEXT{#1}#2\RIGHTLABELTEXT{#1}}
+
+\newif\iflabeltextdone % needs to be reset elsewhere
+\newif\iftracelabels % shows missing labels
+
+\def\doreporttextprefixerror#1#2#3%
+ {\iftracelabels{\tttf[#2:~#3/#1]~}\fi}
+
+\def\dosetexpandedheadlabeltext#1#2#3%
+ {\bgroup
+ \let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\gobblethreearguments
+ \keepencodedtokens % test on multilingual pascal, ok in stretched
+ %\dontexpandencodedtokens % not usable in token handler
+ \expanded
+ {\egroup\noexpand\def\noexpand#2% watch out, no \edef
+ {\dogetupsometextprefix{\headlanguage}{#1}{#3}}}}
+
+\def\setexpandedheadtext {\dosetexpandedheadlabeltext\c!title}
+\def\setexpandedlabeltext{\dosetexpandedheadlabeltext\c!label}
+
+% \def\dogetupsometextprefix#1#2#3%
+% {\ifcsname#2#1#3\endcsname
+% \csname#2#1#3\endcsname \else
+% \ifcsname#2#3\endcsname
+% \csname#2#3\endcsname \else
+% \ifcsname#2\defaultlanguage#1#3\endcsname
+% \csname#2\defaultlanguage#1#3\endcsname \else
+% \ifcsname#2\s!en#3\endcsname
+% \csname#2\s!en#3\endcsname \else
+% \ifcsname#2\s!nl#3\endcsname
+% \csname#2\s!nl#3\endcsname \else
+% \reporttextprefixerror{#1}{#2}{#3}%
+% \fi\fi\fi\fi\fi}
+%
+% \def\dogetupsometextprefix#1#2#3% must be expandable !
+% {\ifcsname#2#1#3\endcsname
+% \csname#2#1#3\endcsname
+% \else\@EA\ifx\csname\??la#1\c!default\endcsname\empty
+% \ifcsname#2#3\endcsname
+% \csname#2#3\endcsname
+% \else\ifcsname#2\s!en#3\endcsname
+% \csname#2\s!en#3\endcsname
+% \else
+% \reporttextprefixerror{#1}{#2}{#3}%
+% \fi\fi
+% \else
+% \dogetupsometextprefix{\csname\??la#1\c!default\endcsname}{#2}{#3}%
+% \fi\fi}
+
+\def\dogetupsometextprefix#1#2#3% must be expandable ! #1 == language
+ {\ifcsname#2#1#3\endcsname
+ \csname#2#1#3\endcsname
+ \else\ifcsname\??la#1\s!default\endcsname
+ \expandafter\dogetupsometextprefix\csname\??la#1\s!default\endcsname{#2}{#3}%
+ \else\ifcsname#2#3\endcsname
+ \csname#2#3\endcsname
+ \else\ifcsname#1\s!en#3\endcsname
+ \csname#2\s!en#3\endcsname
+ \else
+ \reporttextprefixerror{#1}{#2}{#3}%
+ \fi\fi\fi\fi}
+
+\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
+
+\appendtoks
+ \let \headtext \firstofoneargument
+ \let \labeltext \firstofoneargument
+ \let \leftlabeltext \firstofoneargument
+ \let \rightlabeltext \firstofoneargument
+ \let \HEADTEXT \firstofoneargument
+ \let \LABELTEXT \firstofoneargument
+ \let \LEFTLABELTEXT \firstofoneargument
+ \let \RIGHTLABELTEXT \firstofoneargument
+\to \simplifiedcommands
+
+%D \macros
+%D {presetheadtext,presetlabeltext}
+%D
+%D The next two macros enable us to automatically define
+%D head and label texts without replacing predefined ones.
+%D These are internal macros.
+
+\def\xdopresetsometextprefix[#1][#2=#3]%
+ {\ifundefined{#1#2}\doassignsometextprefix[#1\reallanguagetag{#2}][#3,,]\fi}
+
+\def\dopresetsometextprefix
+ {\let\dodocommand\xdopresetsometextprefix
+ \dotripleempty\dodosetupsometextprefix}
+
+\def\presetheadtext {\dopresetsometextprefix[\c!title]}
+\def\presetlabeltext{\dopresetsometextprefix[\c!label]}
+
+%D \macros
+%D {translate}
+%D
+%D Sometismes macros contain language specific words that are to
+%D be typeset. Such macros can be made (more) language
+%D independant by using:
+%D
+%D \showsetup{translate}
+%D
+%D like for instance:
+%D
+%D \starttyping
+%D \translate[en=something,nl=iets]
+%D \stoptyping
+%D
+%D which expands to {\em something} or {\em iets}, depending on
+%D de current language.
+
+\def\dotranslate[#1]%
+ {\getparameters[\??lg][#1]%
+ \ifcsname\??lg\currentlanguage\endcsname
+ \csname\??lg\currentlanguage\endcsname
+ \else\ifcsname\??lg\s!en\endcsname
+ \csname\??lg\s!en\endcsname
+ \else
+ [translation #1]%
+ \fi\fi}
+
+\unexpanded\def\translate
+ {\dosingleempty\dotranslate}
+
+%D When used without argument, the last defined values are
+%D used. This enables repetitive use like
+%D
+%D \starttyping
+%D \en \translate\ means \nl \translate
+%D \stoptyping
+
+%D \macros
+%D {assigntranslation}
+%D
+%D This macro is a system macro, and can be used to assign a
+%D translation to a macro. Its form is:
+%D
+%D \starttyping
+%D \assigntranslation[en=something,nl=iets]\to\command
+%D \stoptyping
+
+\def\assigntranslation[#1]\to#2%
+ {\getparameters[\??lg][#1]%
+ \edef#2{\csname\??lg\currentlanguage\endcsname}}
+
+\protect \endinput
diff --git a/tex/context/base/lang-lab.mkiv b/tex/context/base/lang-lab.mkiv
new file mode 100644
index 000000000..60408f787
--- /dev/null
+++ b/tex/context/base/lang-lab.mkiv
@@ -0,0 +1,266 @@
+%D \module
+%D [ file=lang-lab,
+%D version=1997.08.27,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Labels,
+%D author=Hans Hagen / Tobias Burnus,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\unprotect
+
+%D In this module we deal with language dependant labels and
+%D prefixes, like in {\em Figure~12} and {\em Chapter 1}. In
+%D this file we set the default values. Users can easily
+%D overrule these.
+%D
+%D This module is dedicated to the grandfather of Tobias
+%D Burnus, who's extensive languages oriented library helped us
+%D a lot in finding the right translations. All those labels
+%D are collected in files that reflect their common ancestor.
+%D
+%D Not all languages can be satisfied with the labeling
+%D mechanism as provided here. Chinese for instance put a label
+%D in front as well as after a part number. This is why the
+%D current implementation of labels supports two labels too.
+
+%D \macros
+%D {setupheadtext, setuplabeltext}
+%D
+%D First we present some macros that deal with what we will
+%D call head and label texts. Such texts are defines by:
+%D
+%D \showsetup{setupheadtext}
+%D \showsetup{setuplabeltext}
+%D
+%D In a few paragraphs we'll show quite a lot of examples
+%D of its use.
+
+\let\handletextprefix\relax
+
+\def\setupheadtext {\dosetupsometextprefix[\c!title]}
+\def\setuplabeltext{\dosetupsometextprefix[\c!label]}
+
+\def\dosetupsometextprefix
+ {\let\dodocommand\xdosetupsometextprefix
+ \dotripleempty\dodosetupsometextprefix}
+
+% \def\dodosetupsometextprefix[#1][#2][#3]%
+% {\ifthirdargument
+% \def\docommand##1{\dodocommand[#1#2][##1]}%
+% \processcommalist[#3]\docommand
+% \else
+% \def\docommand##1{\dodocommand[#1\currentmainlanguage][##1]}%
+% \processcommalist[#2]\docommand
+% \fi}
+
+\def\dodosetupsometextprefix[#1][#2][#3]%
+ {\ifthirdargument
+ \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag{#2}]}[##1]}%
+ \processcommalist[#3]\docommand
+ \else
+ \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag\currentmainlanguage]}[##1]}%
+ \processcommalist[#2]\docommand
+ \fi}
+
+\def\doassignsometextprefix[#1][#2,#3,#4]%
+ {\setvalue{#1}{\handletextprefix{#2}{#3}}}
+
+\def\xdosetupsometextprefix[#1][#2=#3]%
+ {\doassignsometextprefix[#1#2][#3,,]}
+
+%D By changing the meaning of \type {\handletextprefix} we
+%D can filter the left and right labeltext as well as convert
+%D labels to uppercase.
+%D
+%D These commands accept all kind of inputs:
+%D
+%D \starttyping
+%D \setuplabeltext [language] [labellabel=text]
+%D \setuplabeltext [language] [labellabel=text,labellabel=text,...]
+%D \setuplabeltext [labellabel=text]
+%D \setuplabeltext [labellabel=text,labellabel=text,...]
+%D \stoptyping
+%D
+%D The last two cases concern the current language.
+
+%D \macros
+%D {headtext,
+%D labeltext, leftlabeltext, rightlabeltext, labeltexts,
+%D LABELTEXT, LEFTLABELTEXT, RIGHTLABELTEXT, LABELTEXTS}
+%D
+%D Once defined, head and label texts can be called upon using:
+%D
+%D \showsetup{headtext}
+%D \showsetup{labeltext}
+%D
+%D The latter one has an upcased alternative \type{\LABELTEXT}.
+
+% \def\labellanguage{\currentmainlanguage}
+% \def\headlanguage {\currentmainlanguage}
+
+% \def\labellanguage{\defaultlanguage\currentmainlanguage}
+% \def\headlanguage {\defaultlanguage\currentmainlanguage}
+
+\def\labellanguage{\reallanguagetag{\defaultlanguage\currentmainlanguage}}
+\def\headlanguage {\reallanguagetag{\defaultlanguage\currentmainlanguage}}
+
+\appendtoks \let\labellanguage\currentlanguage \to \everycurrentdate
+
+\unexpanded\def\headtext
+ {\let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\headlanguage\c!title}
+
+\unexpanded\def\leftlabeltext
+ {\let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label}
+
+\unexpanded\def\rightlabeltext
+ {\let\handletextprefix\secondoftwoarguments
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label}
+
+\unexpanded\def\LEFTLABELTEXT
+ {\def\handletextprefix##1##2{\uppercase{##1}}\DOLABELTEXT}
+
+\unexpanded\def\RIGHTLABELTEXT
+ {\def\handletextprefix##1##2{\uppercase{##2}}\DOLABELTEXT}
+
+\def\DOLABELTEXT#1%
+ {\bgroup
+ \the\everyuppercase
+ \let\reporttextprefixerror\doreporttextprefixerror
+ \global\labeltextdonetrue
+ \dogetupsometextprefix\labellanguage\c!label{#1}% not \labeltext (see \MONTH)
+ \egroup}
+
+\let\labeltext \leftlabeltext
+\let\LABELTEXT \LEFTLABELTEXT
+
+\unexpanded\def\labeltexts#1#2{\leftlabeltext{#1}#2\rightlabeltext{#1}}
+\unexpanded\def\LABELTEXTS#1#2{\LEFTLABELTEXT{#1}#2\RIGHTLABELTEXT{#1}}
+
+\newif\iflabeltextdone % needs to be reset elsewhere
+\newif\iftracelabels % shows missing labels
+
+\def\doreporttextprefixerror#1#2#3%
+ {\iftracelabels{\tttf[#2:~#3/#1]~}\fi}
+
+\def\dosetexpandedheadlabeltext#1#2#3%
+ {\bgroup
+ \let\handletextprefix\firstoftwoarguments
+ \let\reporttextprefixerror\gobblethreearguments
+ \keepencodedtokens % test on multilingual pascal, ok in stretched
+ %\dontexpandencodedtokens % not usable in token handler
+ \expanded
+ {\egroup\noexpand\def\noexpand#2% watch out, no \edef
+ {\dogetupsometextprefix{\headlanguage}{#1}{#3}}}}
+
+\def\setexpandedheadtext {\dosetexpandedheadlabeltext\c!title}
+\def\setexpandedlabeltext{\dosetexpandedheadlabeltext\c!label}
+
+\def\dogetupsometextprefix#1#2#3% must be expandable ! #1 == language
+ {\ifcsname#2#1#3\endcsname
+ \csname#2#1#3\endcsname
+ \else\ifcsname\??la#1\s!default\endcsname
+ \expandafter\dogetupsometextprefix\csname\??la#1\s!default\endcsname{#2}{#3}%
+ \else\ifcsname#2#3\endcsname
+ \csname#2#3\endcsname
+ \else\ifcsname#1\s!en#3\endcsname
+ \csname#2\s!en#3\endcsname
+ \else
+ % \doreporttextprefixerror{#1}{#2}{#3}%
+ \fi\fi\fi\fi}
+
+\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
+
+\appendtoks
+ \let \headtext \firstofoneargument
+ \let \labeltext \firstofoneargument
+ \let \leftlabeltext \firstofoneargument
+ \let \rightlabeltext \firstofoneargument
+ \let \HEADTEXT \firstofoneargument
+ \let \LABELTEXT \firstofoneargument
+ \let \LEFTLABELTEXT \firstofoneargument
+ \let \RIGHTLABELTEXT \firstofoneargument
+\to \simplifiedcommands
+
+%D \macros
+%D {presetheadtext,presetlabeltext}
+%D
+%D The next two macros enable us to automatically define
+%D head and label texts without replacing predefined ones.
+%D These are internal macros.
+
+\def\xdopresetsometextprefix[#1][#2=#3]%
+ {\ifundefined{#1#2}\doassignsometextprefix[#1\reallanguagetag{#2}][#3,,]\fi}
+
+\def\dopresetsometextprefix
+ {\let\dodocommand\xdopresetsometextprefix
+ \dotripleempty\dodosetupsometextprefix}
+
+\def\presetheadtext {\dopresetsometextprefix[\c!title]}
+\def\presetlabeltext{\dopresetsometextprefix[\c!label]}
+
+%D \macros
+%D {translate}
+%D
+%D Sometismes macros contain language specific words that are to
+%D be typeset. Such macros can be made (more) language
+%D independant by using:
+%D
+%D \showsetup{translate}
+%D
+%D like for instance:
+%D
+%D \starttyping
+%D \translate[en=something,nl=iets]
+%D \stoptyping
+%D
+%D which expands to {\em something} or {\em iets}, depending on
+%D de current language.
+
+\def\dotranslate[#1]%
+ {\getparameters[\??lg][#1]%
+ \ifcsname\??lg\currentlanguage\endcsname
+ \csname\??lg\currentlanguage\endcsname
+ \else\ifcsname\??lg\s!en\endcsname
+ \csname\??lg\s!en\endcsname
+ \else
+ [translation #1]%
+ \fi\fi}
+
+\unexpanded\def\translate
+ {\dosingleempty\dotranslate}
+
+%D When used without argument, the last defined values are
+%D used. This enables repetitive use like
+%D
+%D \starttyping
+%D \en \translate\ means \nl \translate
+%D \stoptyping
+
+%D \macros
+%D {assigntranslation}
+%D
+%D This macro is a system macro, and can be used to assign a
+%D translation to a macro. Its form is:
+%D
+%D \starttyping
+%D \assigntranslation[en=something,nl=iets]\to\command
+%D \stoptyping
+
+\def\assigntranslation[#1]\to#2%
+ {\getparameters[\??lg][#1]%
+ \edef#2{\csname\??lg\currentlanguage\endcsname}}
+
+\protect \endinput
diff --git a/tex/context/base/lang-lab.tex b/tex/context/base/lang-lab.tex
deleted file mode 100644
index 664460129..000000000
--- a/tex/context/base/lang-lab.tex
+++ /dev/null
@@ -1,284 +0,0 @@
-%D \module
-%D [ file=lang-lab,
-%D version=1997.08.27,
-%D title=\CONTEXT\ Language Macros,
-%D subtitle=Language Head and Label Texts,
-%D author=Hans Hagen / Tobias Burnus,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Language Head and Label Texts}
-
-\unprotect
-
-%D In this module we deal with language dependant labels and
-%D prefixes, like in {\em Figure~12} and {\em Chapter 1}. In
-%D this file we set the default values. Users can easily
-%D overrule these.
-%D
-%D This module is dedicated to the grandfather of Tobias
-%D Burnus, who's extensive languages oriented library helped us
-%D a lot in finding the right translations. All those labels
-%D are collected in files that reflect their common ancestor.
-%D
-%D Not all languages can be satisfied with the labeling
-%D mechanism as provided here. Chinese for instance put a label
-%D in front as well as after a part number. This is why the
-%D current implementation of labels supports two labels too.
-
-%D \macros
-%D {setupheadtext, setuplabeltext}
-%D
-%D First we present some macros that deal with what we will
-%D call head and label texts. Such texts are defines by:
-%D
-%D \showsetup{setupheadtext}
-%D \showsetup{setuplabeltext}
-%D
-%D In a few paragraphs we'll show quite a lot of examples
-%D of its use.
-
-\let\handletextprefix\relax
-
-\def\setupheadtext {\dosetupsometextprefix[\c!title]}
-\def\setuplabeltext{\dosetupsometextprefix[\c!label]}
-
-\def\dosetupsometextprefix
- {\let\dodocommand\xdosetupsometextprefix
- \dotripleempty\dodosetupsometextprefix}
-
-% \def\dodosetupsometextprefix[#1][#2][#3]%
-% {\ifthirdargument
-% \def\docommand##1{\dodocommand[#1#2][##1]}%
-% \processcommalist[#3]\docommand
-% \else
-% \def\docommand##1{\dodocommand[#1\currentmainlanguage][##1]}%
-% \processcommalist[#2]\docommand
-% \fi}
-
-\def\dodosetupsometextprefix[#1][#2][#3]%
- {\ifthirdargument
- \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag{#2}]}[##1]}%
- \processcommalist[#3]\docommand
- \else
- \def\docommand##1{\expanded{\dodocommand[#1\reallanguagetag\currentmainlanguage]}[##1]}%
- \processcommalist[#2]\docommand
- \fi}
-
-\def\doassignsometextprefix[#1][#2,#3,#4]%
- {\setvalue{#1}{\handletextprefix{#2}{#3}}}
-
-\def\xdosetupsometextprefix[#1][#2=#3]%
- {\doassignsometextprefix[#1#2][#3,,]}
-
-%D By changing the meaning of \type {\handletextprefix} we
-%D can filter the left and right labeltext as well as convert
-%D labels to uppercase.
-%D
-%D These commands accept all kind of inputs:
-%D
-%D \starttyping
-%D \setuplabeltext [language] [labellabel=text]
-%D \setuplabeltext [language] [labellabel=text,labellabel=text,...]
-%D \setuplabeltext [labellabel=text]
-%D \setuplabeltext [labellabel=text,labellabel=text,...]
-%D \stoptyping
-%D
-%D The last two cases concern the current language.
-
-%D \macros
-%D {headtext,
-%D labeltext, leftlabeltext, rightlabeltext, labeltexts,
-%D LABELTEXT, LEFTLABELTEXT, RIGHTLABELTEXT, LABELTEXTS}
-%D
-%D Once defined, head and label texts can be called upon using:
-%D
-%D \showsetup{headtext}
-%D \showsetup{labeltext}
-%D
-%D The latter one has an upcased alternative \type{\LABELTEXT}.
-
-% \def\labellanguage{\currentmainlanguage}
-% \def\headlanguage {\currentmainlanguage}
-
-% \def\labellanguage{\defaultlanguage\currentmainlanguage}
-% \def\headlanguage {\defaultlanguage\currentmainlanguage}
-
-\def\labellanguage{\reallanguagetag{\defaultlanguage\currentmainlanguage}}
-\def\headlanguage {\reallanguagetag{\defaultlanguage\currentmainlanguage}}
-
-\appendtoks \let\labellanguage\currentlanguage \to \everycurrentdate
-
-\unexpanded\def\headtext
- {\let\handletextprefix\firstoftwoarguments
- \let\reporttextprefixerror\doreporttextprefixerror
- \global\labeltextdonetrue
- \dogetupsometextprefix\headlanguage\c!title}
-
-\unexpanded\def\leftlabeltext
- {\let\handletextprefix\firstoftwoarguments
- \let\reporttextprefixerror\doreporttextprefixerror
- \global\labeltextdonetrue
- \dogetupsometextprefix\labellanguage\c!label}
-
-\unexpanded\def\rightlabeltext
- {\let\handletextprefix\secondoftwoarguments
- \let\reporttextprefixerror\doreporttextprefixerror
- \global\labeltextdonetrue
- \dogetupsometextprefix\labellanguage\c!label}
-
-\unexpanded\def\LEFTLABELTEXT
- {\def\handletextprefix##1##2{\uppercase{##1}}\DOLABELTEXT}
-
-\unexpanded\def\RIGHTLABELTEXT
- {\def\handletextprefix##1##2{\uppercase{##2}}\DOLABELTEXT}
-
-\def\DOLABELTEXT#1%
- {\bgroup
- \the\everyuppercase
- \let\reporttextprefixerror\doreporttextprefixerror
- \global\labeltextdonetrue
- \dogetupsometextprefix\labellanguage\c!label{#1}% not \labeltext (see \MONTH)
- \egroup}
-
-\let\labeltext \leftlabeltext
-\let\LABELTEXT \LEFTLABELTEXT
-
-\unexpanded\def\labeltexts#1#2{\leftlabeltext{#1}#2\rightlabeltext{#1}}
-\unexpanded\def\LABELTEXTS#1#2{\LEFTLABELTEXT{#1}#2\RIGHTLABELTEXT{#1}}
-
-\newif\iflabeltextdone % needs to be reset elsewhere
-\newif\iftracelabels % shows missing labels
-
-\def\doreporttextprefixerror#1#2#3%
- {\iftracelabels{\tttf[#2:~#3/#1]~}\fi}
-
-\def\dosetexpandedheadlabeltext#1#2#3%
- {\bgroup
- \let\handletextprefix\firstoftwoarguments
- \let\reporttextprefixerror\gobblethreearguments
- \keepencodedtokens % test on multilingual pascal, ok in stretched
- %\dontexpandencodedtokens % not usable in token handler
- \expanded
- {\egroup\noexpand\def\noexpand#2% watch out, no \edef
- {\dogetupsometextprefix{\headlanguage}{#1}{#3}}}}
-
-\def\setexpandedheadtext {\dosetexpandedheadlabeltext\c!title}
-\def\setexpandedlabeltext{\dosetexpandedheadlabeltext\c!label}
-
-% \def\dogetupsometextprefix#1#2#3%
-% {\ifcsname#2#1#3\endcsname
-% \csname#2#1#3\endcsname \else
-% \ifcsname#2#3\endcsname
-% \csname#2#3\endcsname \else
-% \ifcsname#2\defaultlanguage#1#3\endcsname
-% \csname#2\defaultlanguage#1#3\endcsname \else
-% \ifcsname#2\s!en#3\endcsname
-% \csname#2\s!en#3\endcsname \else
-% \ifcsname#2\s!nl#3\endcsname
-% \csname#2\s!nl#3\endcsname \else
-% \reporttextprefixerror{#1}{#2}{#3}%
-% \fi\fi\fi\fi\fi}
-
-\def\dogetupsometextprefix#1#2#3% must be expandable !
- {\ifcsname#2#1#3\endcsname
- \csname#2#1#3\endcsname
- \else\@EA\ifx\csname\??la#1\c!default\endcsname\empty
- \ifcsname#2#3\endcsname
- \csname#2#3\endcsname
- \else\ifcsname#2\s!en#3\endcsname
- \csname#2\s!en#3\endcsname
- \else
- \reporttextprefixerror{#1}{#2}{#3}%
- \fi\fi
- \else
- \dogetupsometextprefix{\csname\??la#1\c!default\endcsname}{#2}{#3}%
- \fi\fi}
-
-\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi
-
-\appendtoks
- \let \headtext \firstofoneargument
- \let \labeltext \firstofoneargument
- \let \leftlabeltext \firstofoneargument
- \let \rightlabeltext \firstofoneargument
- \let \HEADTEXT \firstofoneargument
- \let \LABELTEXT \firstofoneargument
- \let \LEFTLABELTEXT \firstofoneargument
- \let \RIGHTLABELTEXT \firstofoneargument
-\to \simplifiedcommands
-
-%D \macros
-%D {presetheadtext,presetlabeltext}
-%D
-%D The next two macros enable us to automatically define
-%D head and label texts without replacing predefined ones.
-%D These are internal macros.
-
-\def\xdopresetsometextprefix[#1][#2=#3]%
- {\ifundefined{#1#2}\doassignsometextprefix[#1\reallanguagetag{#2}][#3,,]\fi}
-
-\def\dopresetsometextprefix
- {\let\dodocommand\xdopresetsometextprefix
- \dotripleempty\dodosetupsometextprefix}
-
-\def\presetheadtext {\dopresetsometextprefix[\c!title]}
-\def\presetlabeltext{\dopresetsometextprefix[\c!label]}
-
-%D \macros
-%D {translate}
-%D
-%D Sometismes macros contain language specific words that are to
-%D be typeset. Such macros can be made (more) language
-%D independant by using:
-%D
-%D \showsetup{translate}
-%D
-%D like for instance:
-%D
-%D \starttyping
-%D \translate[en=something,nl=iets]
-%D \stoptyping
-%D
-%D which expands to {\em something} or {\em iets}, depending on
-%D de current language.
-
-\def\dotranslate[#1]% don't group! SLOW if really used: speed up
- {\getparameters[\??lg][#1]%
- \doifdefinedelse{\??lg\currentlanguage}%
- {\getvalue{\??lg\currentlanguage}}
- {\doifdefinedelse{\??lg\s!en}
- {\getvalue{\??lg\s!en}}
- {\doifdefinedelse{\??lg\s!nl}
- {\getvalue{\??lg\s!nl}}
- {[translation #1]}}}}
-
-\unexpanded\def\translate
- {\dosingleempty\dotranslate}
-
-%D When used without argument, the last defined values are
-%D used. This enables repetitive use like
-%D
-%D \starttyping
-%D \en \translate\ means \nl \translate
-%D \stoptyping
-
-%D \macros
-%D {assigntranslation}
-%D
-%D This macro is a system macro, and can be used to assign a
-%D translation to a macro. Its form is:
-%D
-%D \starttyping
-%D \assigntranslation[en=something,nl=iets]\to\command
-%D \stoptyping
-
-\def\assigntranslation[#1]\to#2%
- {\getparameters[\??lg][#1]%
- \edef#2{\csname\??lg\currentlanguage\endcsname}}
-
-\protect \endinput
diff --git a/tex/context/base/lang-mis.tex b/tex/context/base/lang-mis.tex
index 41f370974..eb7bb1a04 100644
--- a/tex/context/base/lang-mis.tex
+++ b/tex/context/base/lang-mis.tex
@@ -2,7 +2,7 @@
%D [ file=lang-mis,
%D version=1997.03.20, % used to be supp-lan.tex
%D title=\CONTEXT\ Language Macros,
-%D subtitle=Language Options,
+%D subtitle=Compounds,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Language Macros / Compounds}
+\writestatus{loading}{ConTeXt Language Macros / Compounds}
%D \gdef\starttest
%D {\blank
@@ -181,7 +181,7 @@
%ifx\postwordbreak \undefined \def\postwordbreak{\penalty\zerocount \prewordbreak } \fi
\ifx\postwordbreak \undefined \def\postwordbreak{\penalty\zerocount \hskip\zeropoint\relax} \fi
-\ifx\hspaceamount \undefined \def\hspaceamount#1#2{\kern.16667em} \fi % language specific
+\ifx\hspaceamount \undefined \def\hspaceamount#1#2{.16667em} \fi % language specific
%D \macros
%D {beginofsubsentencespacing,endofsubsentencespacing}
diff --git a/tex/context/base/lang-sla.tex b/tex/context/base/lang-sla.tex
index 50ebed127..0832e3f46 100644
--- a/tex/context/base/lang-sla.tex
+++ b/tex/context/base/lang-sla.tex
@@ -32,7 +32,7 @@
% Lusatian/Sorbian/Wendish, Polish, Slovak, Albanian,
% Illyrian, Armenian
-\writestatus{loading}{Slavic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Slavic Languages}
\unprotect
@@ -77,7 +77,8 @@
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!day,{.},\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={pl0,ec,qx},
+ \s!encoding={pl0,ec,qx}]
\installlanguage
[\s!cs]
@@ -91,7 +92,8 @@
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoublesixquote,
\c!date={\v!day,{.\,},\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={il2,ec},
+ \s!encoding={il2,ec}]
\installlanguage
[\s!sk]
@@ -105,7 +107,8 @@
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!day,{.\,},\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping={il2,ec},
+ \s!encoding={il2,ec}]
\installlanguage
[\s!hr]
@@ -119,7 +122,8 @@
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!day,\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping=ec,
+ \s!encoding=ec]
%D The default quotation marks for Slovenian were chosen as
%D \lowerleftdoubleninequote these ones\upperrightdoublesixquote\
@@ -168,7 +172,8 @@
\c!leftquotation=\rightguillemot,
\c!rightquotation=\leftguillemot,
\c!date={\v!day,{.},\ ,\v!month,\ ,\v!year},
- \c!state=\v!stop]
+ \s!mapping=ec,
+ \s!encoding=ec]
\installlanguage [polish] [\s!pl]
\installlanguage [czech] [\s!cs]
@@ -177,6 +182,8 @@
\installlanguage [slovenian] [\s!sl]
\installlanguage [slovene] [\s!sl] % both possible (mojca: still needed?)
+\installlanguage [cz] [\s!cs]
+
% If this is really needed we should make an enco-fhr.
%
% \startlanguagespecifics[\s!hr]
@@ -443,9 +450,7 @@
% \c!rightquote=\upperrightsinglesixquote,
% \c!leftquotation=\lowerleftdoubleninequote,
% \c!rightquotation=\upperrightdoublesixquote,
-% \c!date={\v!day,\ ,\v!month,\ ,\v!year},
-% \c!state=\v!stop]
-
+% \c!date={\v!day,\ ,\v!month,\ ,\v!year}]
\setuplabeltext [\s!sl] [\v!page=stran ]
\setuplabeltext [\s!sl] [\v!atpage=na strani ]
diff --git a/tex/context/base/lang-spa.tex b/tex/context/base/lang-spa.tex
index 1ec45cd69..f6e22aa51 100644
--- a/tex/context/base/lang-spa.tex
+++ b/tex/context/base/lang-spa.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Language Macros / Spacing}
+\writestatus{loading}{ConTeXt Language Macros / Spacing}
%D This module was created in the process of enhancing
%D support for French (with the help of Daniel Flipo).
diff --git a/tex/context/base/lang-spe.mkii b/tex/context/base/lang-spe.mkii
new file mode 100644
index 000000000..7911b0c95
--- /dev/null
+++ b/tex/context/base/lang-spe.mkii
@@ -0,0 +1,244 @@
+%D \module
+%D [ file=lang-spe,
+%D version=2002.05.07, % 1996.01.25,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Specifics,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This code was originally placed in the language
+%D initialization module, but isolating it is clearer. Language
+%D specifics evolved out of user demands for special features,
+%D like the german active quote. After a while I decided to
+%D associate them to languages in a more general way so that we
+%D could associate all kind of things with language switching.
+%D
+%D This is a typical example of functionality that occasionally
+%D gets improved based on user input and experience. Much of the
+%D code is pretty old and could probabbly be done in better ways.
+%D It's probably also the kind of code that has been and will be
+%D written over and over again by \TEX\ users around the world,
+%D so there are probably better implementations of similar
+%D functionality around. Therefore, users are invited to pop in
+%D their own handling as long as it does not interfere with
+%D existing code. Writing the more obscure macros that deal with
+%D this is a good learning experience (catcodes, lccodes, token
+%D lists, expansion, \unknown).
+
+\writestatus{loading}{ConTeXt Language Macros / Specifics}
+
+\unprotect
+
+%D \macros
+%D {everyresetlanguagespecifics,resetlanguagespecifics}
+%D
+%D Cleanup macros.
+
+\newevery \everyresetlanguagespecifics \relax
+
+\def\resetlanguagespecifics
+ {\ifcase\protectionlevel
+ \the\everyresetlanguagespecifics
+ \else % to be translated
+ % \writestatus\m!systems{don't change language in unprotected mode!}%
+ \fi}
+
+\appendtoks
+ \resetlanguagespecifics
+\to \everycleanupfeatures
+
+%D \macros
+%D {startlanguagespecifics,enablelanguagespecifics}
+%D
+%D Each language has its own typographic pecularities. Some of
+%D those can be influenced by parameters, others are handled by
+%D the interface, but as soon as specific commands come into
+%D view we need another mechanism. In the macro that activates
+%D a language, we call \type{\enablelanguagespecifics}. This
+%D macro in return calls for the setup of language specific
+%D macros. Such specifics are defined as:
+%D
+%D \starttyping
+%D \startlanguagespecifics[de]
+%D \installcompoundcharacter "a {\"a}
+%D \installcompoundcharacter "e {\"e}
+%D \installcompoundcharacter "s {\SS}
+%D \stoplanguagespecifics
+%D \stoptyping
+%D
+%D Instead of \type{[du]} we can pass a comma separated
+%D list, like \type{[du,nl]}. Next calls to this macro add the
+%D specifics to the current list.
+%D
+%D Before we actually read the specifics, we first take some
+%D precautions that will prevent spurious spaces to creep into
+%D the list.
+
+% We should use token registers, but alas, we run out of them and
+% \ETEX\ has a bug. Well, let's use a token register now (2006).
+
+\def\startlanguagespecifics% % we use double to
+ {\bgroup
+ \catcode`\^^I=\@@ignore
+ \catcode`\^^M=\@@ignore
+ \catcode`\^^L=\@@ignore
+ \dodoubleempty\dostartlanguagespecifics} % get rid of spaces
+
+%D The main macro looks quite complicated but actually does
+%D nothing special. By embedding \type{\do} we can easily
+%D append to the lists and also execute them at will. Just to
+%D be sure, we check on spurious spaces. The second dummy
+%D argument gobbles spaces.
+
+\def\languageencoding
+ {\ifx\characterencoding\nocharacterencoding \else
+ \characterencoding-%
+ \fi}
+
+\long\def\dostartlanguagespecifics[#1][#2]#3\stoplanguagespecifics
+ {\egroup
+ \processcommalist[#1]{\dosetlanguagespecifics{#3}}}
+
+% \long\def\dosetlanguagespecifics#1#2%
+% {\ifundefined{\??la\languageencoding#2\??la}\forgetlanguagespecifics[#2]\fi
+% % the next line catches the case that specifics are enabled *before* they are defined
+% \expandafter\ifx\csname\??la\languageencoding#2\??la\endcsname\relax\forgetlanguagespecifics[#2]\fi
+% \appendvalue{\??la\languageencoding#2\??la}{#1}%
+% \bgroup
+% \setbox\scratchbox\hbox{\enablelanguagespecifics[#2]}%
+% \ifdim\wd\scratchbox>\zeropoint
+% \showmessage\m!linguals7{\currentencoding-#2,\the\wd\scratchbox\space}\wait
+% \else
+% \showmessage\m!linguals8{\currentencoding-#2}%
+% \fi
+% \egroup
+% \doif{#2}\currentmainlanguage{\enablelanguagespecifics[#2]}}
+
+\def\languagespectag#1{\??la\languageencoding#1\??la}
+
+\long\def\dosetlanguagespecifics#1#2%
+ {\edef\askedlanguagespecificstag{\languagespectag{#2}}%
+ \ifcsname\askedlanguagespecificstag\endcsname \else
+ \expandafter\newtoks\csname\askedlanguagespecificstag\endcsname
+ \fi
+ \csname\askedlanguagespecificstag\endcsname\@EA{\the\csname\askedlanguagespecificstag\endcsname#1}%
+ \bgroup
+ \setbox\scratchbox\hbox{\enablelanguagespecifics[#2]}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \showmessage\m!linguals7{\currentencoding-#2,\the\wd\scratchbox\space}\wait
+ \else
+ \showmessage\m!linguals8{\currentencoding-#2}%
+ \fi
+ \egroup
+ \doif{#2}\currentmainlanguage{\enablelanguagespecifics[#2]}}
+
+\def\forgetlanguagespecifics[#1]%
+ {\csname\languagespectag{#1}\endcsname\emptytoks}
+
+%D Enabling them is rather straightforward. We only have to
+%D define \type{\do} in such a way that \type{{ }} is removed
+%D and the language key is gobbled.
+
+% \def\enablelanguagespecifics[#1]%
+% {\the\executeifdefined{\??la
+% \@EA\ifx\csname\??la#1\c!default\endcsname\relax
+% \languageencoding
+% \else
+% \csname\??la#1\c!default\endcsname
+% \fi
+% \??la}\emptytoks
+% \the\executeifdefined{\??la#1\??la}\emptytoks
+% \the\executeifdefined{\??la\languageencoding#1\??la}\emptytoks} % dup ?
+
+\def\enablelanguagespecifics[#1]%
+ {\edef\askedlanguagespecificslanguage{\defaultlanguage{#1}}%
+ \ifcsname\??la\askedlanguagespecificslanguage\??la\endcsname
+ \the\csname\??la\askedlanguagespecificslanguage\??la\endcsname
+ \fi
+ \ifx\languageencoding\empty\else
+ \ifcsname\??la\languageencoding\askedlanguagespecificslanguage\??la\endcsname
+ \the\csname\??la\languageencoding\askedlanguagespecificslanguage\??la\endcsname
+ \fi
+ \fi}
+
+%D \macros
+%D {deactivatelanguagespecific}
+%D
+%D The next code makes it possible to disable the specifics.
+
+% \def\deactivatelanguagespecific#1%
+% {\ifundefined{l g s \string#1}%
+% \letgvalueempty{l g s \string#1}% signal to prevent dup def
+% \bgroup
+% \catcode`#1=\@@active
+% \uccode`~=`#1
+% \uppercase{\doglobal\appendtoks\dodeactivatetoken{~}\to\everyresetlanguagespecifics}%
+% \egroup
+% \expanded{\doglobal\noexpand\appendtoks{#1}{\the\catcode`#1}}\to\everyresetlanguagespecifics
+% \fi}
+
+% \def\dodeactivatetoken#1#2#3% test needed to avoid clash with \unprotect
+% {\def#1{#2}\ifnum\catcode`#2=\@@active\catcode`#2=#3\relax\fi}
+
+%D We cannot hook this into the installer since language
+%D specifics can be anything. So far, we have the following
+%D potentially active characters.
+
+%D Beware, this should happen under an unprotected regime;
+%D thanks to Giuseppe Oblomov Bilotta, who first noticed
+%D that something was wrong.
+
+\protect
+
+% \deactivatelanguagespecific "
+% \deactivatelanguagespecific /
+% \deactivatelanguagespecific :
+% \deactivatelanguagespecific ;
+% \deactivatelanguagespecific ?
+% \deactivatelanguagespecific !
+
+\unprotect
+
+% yes or no (taco wins: no)
+
+% \startlanguagespecifics[nl,cs,sk,fr]
+% \lccode`\'=`\'
+% \stoplanguagespecifics
+
+%D \macros
+%D {ordinaldaynumber, highordinalstr, ordinalstr}
+%D
+%D Efficient general ordinal number converters are sometimes
+%D difficult to implement. Fortunately dates never exceed the
+%D number~31.
+
+\ifx\high \undefined \let\high \firstofoneargument \fi % todo
+\ifx\notsmallcapped\undefined \let\notsmallcapped\firstofoneargument \fi % todo
+
+\def\highordinalstr#1{\high{\notsmallcapped{#1}}}
+\def\ordinalstr #1{\notsmallcapped{#1}}
+
+\def\ordinaldaynumber#1% \strippedcsname\ordinaldaynumber
+ {\expanded{\executeifdefined{\currentlanguage ordinaldaynumber}%
+ \noexpand\firstofoneargument{\number#1}}}
+
+%D Language specific converters have definitions like:
+%D
+%D \starttyping
+%D \def\enordinaldaynumber#1{...}
+%D \stoptyping
+%D
+%D Examples can be found in the other \type {lang} modules.
+
+% \ifprocessingXML is a nasty dependency
+
+\appendtoks
+ \ifprocessingXML \else \resetlanguagespecifics \fi
+\to \everylanguage
+
+\protect \endinput
diff --git a/tex/context/base/lang-spe.mkiv b/tex/context/base/lang-spe.mkiv
new file mode 100644
index 000000000..6f32888e6
--- /dev/null
+++ b/tex/context/base/lang-spe.mkiv
@@ -0,0 +1,111 @@
+%D \module
+%D [ file=lang-spe,
+%D version=2002.05.07, % 1996.01.25,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Specifics,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Language Macros / Specifics}
+
+%D In \MKIV\ we will get away from this feature. See \MKII\ file
+%D for comments. So, consider this a temporary feature.
+
+\unprotect
+
+%D \macros
+%D {everyresetlanguagespecifics,resetlanguagespecifics}
+%D
+%D Cleanup macros.
+
+\newevery \everyresetlanguagespecifics \relax
+
+\def\resetlanguagespecifics
+ {\ifcase\protectionlevel
+ \the\everyresetlanguagespecifics
+ \fi}
+
+\appendtoks
+ \resetlanguagespecifics
+\to \everycleanupfeatures
+
+%D \macros
+%D {startlanguagespecifics,enablelanguagespecifics}
+
+\def\startlanguagespecifics
+ {\bgroup
+ \catcode`\^^I=\@@ignore
+ \catcode`\^^M=\@@ignore
+ \catcode`\^^L=\@@ignore
+ \dodoubleempty\dostartlanguagespecifics} % get rid of spaces
+
+\long\def\dostartlanguagespecifics[#1][#2]#3\stoplanguagespecifics
+ {\egroup
+ \processcommalist[#1]{\dosetlanguagespecifics{#3}}}
+
+\long\def\dosetlanguagespecifics#1#2% specifics language
+ {\ifcsname\??la#2\??la\endcsname \else
+ \expandafter\newtoks\csname\??la#2\??la\endcsname
+ \fi
+ \csname\??la#2\??la\endcsname\@EA{\the\csname\??la#2\??la\endcsname#1}%
+ \bgroup
+ \setbox\scratchbox\hbox{\enablelanguagespecifics[#2]}%
+ \ifdim\wd\scratchbox>\zeropoint
+ \showmessage\m!linguals7{#2,\the\wd\scratchbox\space}\wait
+ \else
+ \showmessage\m!linguals8{#2}%
+ \fi
+ \egroup
+ \doif{#2}\currentmainlanguage{\enablelanguagespecifics[#2]}}
+
+\def\forgetlanguagespecifics[#1]%
+ {\ifcsname\??la#1\??la\endcsname
+ \csname\??la#1\??la\endcsname\emptytoks
+ \fi}
+
+% \def\enablelanguagespecifics[#1]% no default language fallback (yet)
+% {\ifcsname\??la#1\??la\endcsname
+% \the\csname\??la#1\??la\endcsname\relax
+% \fi}
+
+\def\enablelanguagespecifics[#1]%
+ {\edef\askedlanguagespecificslanguage{\defaultlanguage{#1}}%
+ \ifcsname\??la\askedlanguagespecificslanguage\??la\endcsname
+ \the\csname\??la\askedlanguagespecificslanguage\??la\endcsname
+ \fi}
+
+%D \macros
+%D {ordinaldaynumber, highordinalstr, ordinalstr}
+%D
+%D Efficient general ordinal number converters are sometimes
+%D difficult to implement. Fortunately dates never exceed the
+%D number~31.
+
+\ifx\high \undefined \let\high \firstofoneargument \fi % todo
+\ifx\notsmallcapped\undefined \let\notsmallcapped\firstofoneargument \fi % todo
+
+\def\highordinalstr#1{\high{\notsmallcapped{#1}}}
+\def\ordinalstr #1{\notsmallcapped{#1}}
+
+\def\ordinaldaynumber#1% \strippedcsname\ordinaldaynumber
+ {\expanded{\executeifdefined{\currentlanguage ordinaldaynumber}%
+ \noexpand\firstofoneargument{\number#1}}}
+
+%D Language specific converters have definitions like:
+%D
+%D \starttyping
+%D \def\enordinaldaynumber#1{...}
+%D \stoptyping
+%D
+%D Examples can be found in the other \type {lang} modules.
+
+\appendtoks
+ \ifprocessingXML \else \resetlanguagespecifics \fi
+\to \everylanguage
+
+\protect \endinput
diff --git a/tex/context/base/lang-spe.tex b/tex/context/base/lang-spe.tex
deleted file mode 100644
index 00b514be2..000000000
--- a/tex/context/base/lang-spe.tex
+++ /dev/null
@@ -1,242 +0,0 @@
-%D \module
-%D [ file=lang-spe,
-%D version=2002.05.07, % 1996.01.25,
-%D title=\CONTEXT\ Language Macros,
-%D subtitle=Specifics,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This code was originally placed in the language
-%D initialization module, but isolating it is clearer. Language
-%D specifics evolved out of user demands for special features,
-%D like the german active quote. After a while I decided to
-%D associate them to languages in a more general way so that we
-%D could associate all kind of things with language switching.
-%D
-%D This is a typical example of functionality that occasionally
-%D gets improved based on user input and experience. Much of the
-%D code is pretty old and could probabbly be done in better ways.
-%D It's probably also the kind of code that has been and will be
-%D written over and over again by \TEX\ users around the world,
-%D so there are probably better implementations of similar
-%D functionality around. Therefore, users are invited to pop in
-%D their own handling as long as it does not interfere with
-%D existing code. Writing the more obscure macros that deal with
-%D this is a good learning experience (catcodes, lccodes, token
-%D lists, expansion, \unknown).
-
-\writestatus{loading}{Context Language Macros / Specifics}
-
-\unprotect
-
-%D \macros
-%D {everyresetlanguagespecifics,resetlanguagespecifics}
-%D
-%D Cleanup macros.
-
-\newevery \everyresetlanguagespecifics \relax
-
-\def\resetlanguagespecifics
- {\ifcase\protectionlevel
- \the\everyresetlanguagespecifics
- \else % to be translated
- % \writestatus\m!systems{don't change language in unprotected mode!}%
- \fi}
-
-\appendtoks
- \resetlanguagespecifics
-\to \everycleanupfeatures
-
-%D \macros
-%D {startlanguagespecifics,enablelanguagespecifics}
-%D
-%D Each language has its own typographic pecularities. Some of
-%D those can be influenced by parameters, others are handled by
-%D the interface, but as soon as specific commands come into
-%D view we need another mechanism. In the macro that activates
-%D a language, we call \type{\enablelanguagespecifics}. This
-%D macro in return calls for the setup of language specific
-%D macros. Such specifics are defined as:
-%D
-%D \starttyping
-%D \startlanguagespecifics[de]
-%D \installcompoundcharacter "a {\"a}
-%D \installcompoundcharacter "e {\"e}
-%D \installcompoundcharacter "s {\SS}
-%D \stoplanguagespecifics
-%D \stoptyping
-%D
-%D Instead of \type{[du]} we can pass a comma separated
-%D list, like \type{[du,nl]}. Next calls to this macro add the
-%D specifics to the current list.
-%D
-%D Before we actually read the specifics, we first take some
-%D precautions that will prevent spurious spaces to creep into
-%D the list.
-
-% We should use token registers, but alas, we run out of them and
-% \ETEX\ has a bug. Well, let's use a token register now (2006).
-
-\def\startlanguagespecifics% % we use double to
- {\bgroup
- \catcode`\^^I=\@@ignore
- \catcode`\^^M=\@@ignore
- \catcode`\^^L=\@@ignore
- \dodoubleempty\dostartlanguagespecifics} % get rid of spaces
-
-%D The main macro looks quite complicated but actually does
-%D nothing special. By embedding \type{\do} we can easily
-%D append to the lists and also execute them at will. Just to
-%D be sure, we check on spurious spaces. The second dummy
-%D argument gobbles spaces.
-
-\def\languageencoding
- {\ifx\characterencoding\nocharacterencoding \else
- \characterencoding-%
- \fi}
-
-\long\def\dostartlanguagespecifics[#1][#2]#3\stoplanguagespecifics
- {\egroup
- \processcommalist[#1]{\dosetlanguagespecifics{#3}}}
-
-% \long\def\dosetlanguagespecifics#1#2%
-% {\ifundefined{\??la\languageencoding#2\??la}\forgetlanguagespecifics[#2]\fi
-% % the next line catches the case that specifics are enabled *before* they are defined
-% \expandafter\ifx\csname\??la\languageencoding#2\??la\endcsname\relax\forgetlanguagespecifics[#2]\fi
-% \appendvalue{\??la\languageencoding#2\??la}{#1}%
-% \bgroup
-% \setbox\scratchbox\hbox{\enablelanguagespecifics[#2]}%
-% \ifdim\wd\scratchbox>\zeropoint
-% \showmessage\m!linguals7{\currentencoding-#2,\the\wd\scratchbox\space}\wait
-% \else
-% \showmessage\m!linguals8{\currentencoding-#2}%
-% \fi
-% \egroup
-% \doif{#2}\currentmainlanguage{\enablelanguagespecifics[#2]}}
-
-\def\languagespectag#1{\??la\languageencoding#1\??la}
-
-\long\def\dosetlanguagespecifics#1#2%
- {\ifcsname\languagespectag{#2}\endcsname \else
- \expandafter\newtoks\csname\languagespectag{#2}\endcsname
- \fi
- \csname\languagespectag{#2}\endcsname\@EA{\the\csname\languagespectag{#2}\endcsname#1}%
- \bgroup
- \setbox\scratchbox\hbox{\enablelanguagespecifics[#2]}%
- \ifdim\wd\scratchbox>\zeropoint
- \showmessage\m!linguals7{\currentencoding-#2,\the\wd\scratchbox\space}\wait
- \else
- \showmessage\m!linguals8{\currentencoding-#2}%
- \fi
- \egroup
- \doif{#2}\currentmainlanguage{\enablelanguagespecifics[#2]}}
-
-% \def\forgetlanguagespecifics[#1]%
-% {\letvalue{\??la\languageencoding#1\??la}\empty}
-
-\def\forgetlanguagespecifics[#1]%
- {\csname\languagespectag{#1}\endcsname\emptytoks}
-
-%D Enabling them is rather straightforward. We only have to
-%D define \type{\do} in such a way that \type{{ }} is removed
-%D and the language key is gobbled.
-
-\def\enablelanguagespecifics[#1]%
- {\the\executeifdefined{\??la
- \@EA\ifx\csname\??la#1\c!default\endcsname\relax
- \languageencoding
- \else
- \csname\??la#1\c!default\endcsname
- \fi
- \??la}\emptytoks
- \the\executeifdefined{\??la#1\??la}\emptytoks
- \the\executeifdefined{\??la\languageencoding#1\??la}\emptytoks} % dup ?
-
-% check:
-
-% \def\enablelanguagespecifics[#1]%
-% {\the\executeifdefined{\??la\executeifdefined{\??la#1\c!default}\languageencoding\??la}\emptytoks
-% \the\executeifdefined{\??la#1\??la}\emptytoks
-% \the\executeifdefined{\??la\languageencoding#1\??la}\emptytoks} % dup ?
-
-%D \macros
-%D {deactivatelanguagespecific}
-%D
-%D The next code makes it possible to disable the specifics.
-
-% \def\deactivatelanguagespecific#1%
-% {\ifundefined{l g s \string#1}%
-% \letgvalueempty{l g s \string#1}% signal to prevent dup def
-% \bgroup
-% \catcode`#1=\@@active
-% \uccode`~=`#1
-% \uppercase{\doglobal\appendtoks\dodeactivatetoken{~}\to\everyresetlanguagespecifics}%
-% \egroup
-% \expanded{\doglobal\noexpand\appendtoks{#1}{\the\catcode`#1}}\to\everyresetlanguagespecifics
-% \fi}
-
-% \def\dodeactivatetoken#1#2#3% test needed to avoid clash with \unprotect
-% {\def#1{#2}\ifnum\catcode`#2=\@@active\catcode`#2=#3\relax\fi}
-
-%D We cannot hook this into the installer since language
-%D specifics can be anything. So far, we have the following
-%D potentially active characters.
-
-%D Beware, this should happen under an unprotected regime;
-%D thanks to Giuseppe Oblomov Bilotta, who first noticed
-%D that something was wrong.
-
-\protect
-
-% \deactivatelanguagespecific "
-% \deactivatelanguagespecific /
-% \deactivatelanguagespecific :
-% \deactivatelanguagespecific ;
-% \deactivatelanguagespecific ?
-% \deactivatelanguagespecific !
-
-\unprotect
-
-% yes or no (taco wins: no)
-
-% \startlanguagespecifics[nl,cs,sk,fr]
-% \lccode`\'=`\'
-% \stoplanguagespecifics
-
-%D \macros
-%D {ordinaldaynumber, highordinalstr, ordinalstr}
-%D
-%D Efficient general ordinal number converters are sometimes
-%D difficult to implement. Fortunately dates never exceed the
-%D number~31.
-
-\ifx\high \undefined \let\high \firstofoneargument \fi % todo
-\ifx\notsmallcapped\undefined \let\notsmallcapped\firstofoneargument \fi % todo
-
-\def\highordinalstr#1{\high{\notsmallcapped{#1}}}
-\def\ordinalstr #1{\notsmallcapped{#1}}
-
-\def\ordinaldaynumber#1% \strippedcsname\ordinaldaynumber
- {\expanded{\executeifdefined{\currentlanguage ordinaldaynumber}%
- \noexpand\firstofoneargument{\number#1}}}
-
-%D Language specific converters have definitions like:
-%D
-%D \starttyping
-%D \def\enordinaldaynumber#1{...}
-%D \stoptyping
-%D
-%D Examples can be found in the other \type {lang} modules.
-
-% \ifprocessingXML is a nasty dependency
-
-\appendtoks
- \ifprocessingXML \else \resetlanguagespecifics \fi
-\to \everylanguage
-
-\protect \endinput
diff --git a/tex/context/base/lang-ura.tex b/tex/context/base/lang-ura.tex
index 2ecb31e6b..a2bcd3d2b 100644
--- a/tex/context/base/lang-ura.tex
+++ b/tex/context/base/lang-ura.tex
@@ -13,7 +13,7 @@
% Todo: replace \'.. by \namedglyph
-\writestatus{loading}{Uralic Languages}
+\writestatus{loading}{ConTeXt Language Macros / Uralic Languages}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -42,8 +42,7 @@
\c!rightquote=\upperrightsingleninequote,
\c!leftquotation=\upperleftdoublesixquote,
\c!rightquotation=\upperrightdoubleninequote,
- \c!date={\v!year,\ ,\v!month,\ ,\v!day},
- \c!state=\v!stop]
+ \c!date={\v!year,\ ,\v!month,\ ,\v!day}]
\installlanguage
[\s!hu]
@@ -57,7 +56,6 @@
\c!leftquotation=\lowerleftdoubleninequote,
\c!rightquotation=\upperrightdoubleninequote,
\c!date={\v!year,.,\ ,\v!month,\ ,\v!day,.},
- \c!state=\v!stop,
\s!mapping=ec,
\s!encoding=ec]
diff --git a/tex/context/base/lang-url.lua b/tex/context/base/lang-url.lua
index b732dcef0..1524878cf 100644
--- a/tex/context/base/lang-url.lua
+++ b/tex/context/base/lang-url.lua
@@ -6,6 +6,12 @@ if not modules then modules = { } end modules ['lang-url'] = {
license = "see context related readme files"
}
+local utf = unicode.utf8
+
+local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
+
+local ctxcatcodes = tex.ctxcatcodes
+
commands = commands or { }
--[[
@@ -76,13 +82,13 @@ do
return "\\a{" .. u(s) .. "}"
end
end )
- tex.sprint(tex.ctxcatcodes,str)
+ tex.sprint(ctxcatcodes,str)
end
-- todo, no interface in mkiv yet
function commands.hyphenatedurl.setcharacters(str,value) -- 1, 2 == before, after
- for s in str:utfcharacters() do
+ for s in utfcharacters(str) do
chars[s] = value or 1
end
end
diff --git a/tex/context/base/lang-url.mkii b/tex/context/base/lang-url.mkii
index f3310cceb..fdf530b45 100644
--- a/tex/context/base/lang-url.mkii
+++ b/tex/context/base/lang-url.mkii
@@ -18,6 +18,29 @@
\ifx\\\undefined \let\\\crlf \fi
+%D \macros
+%D {hyphenatedurl}
+%D
+%D For those who want to put full \URL's in a text, we offer
+%D
+%D \startbuffer
+%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D which breaks at the appropriate places. Watch the \type{#}
+%D hack.
+%D
+%D When passed as argument, like in \type {\goto}, one needs
+%D to substitute a \type {\\} for each \type{#}.
+%D
+%D \startbuffer
+%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
+%D \stopbuffer
+%D
+%D \typebuffer
+
\ifx\urlsplitmode\undefined \chardef\urlsplitmode\plusone \fi
% 0 => don't split
@@ -229,4 +252,55 @@
%
% {\hsize1cm\hyphenatedstring{ABXXXXXXXXXXC-12345-12345}}
+%D \macros
+%D {hyphenatedfilename}
+%D
+%D For the moment we treat filenames in a similar way,
+%D
+%D \starttyping
+%D \hyphenatedfilename{here/there/filename.suffix}
+%D \stoptyping
+
+\ifx\hyphenatedfilename\undefined \let\hyphenatedfilename\hyphenatedurl \fi
+
+% \def\test#1%
+% {\dontleavehmode
+% \begingroup
+% \tttf
+% \hyphenatedurl {%
+% \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
+% \letterhash #1\letterhash #1\letterpercent #1\letterslash #1\letterampersand
+% }%
+% \endgroup}
+
+% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
+
\protect \endinput
+
+% \bgroup
+
+% \gdef\lettercolon{:}
+
+% \catcode`\:=\active
+% \catcode`\^=\active
+% \catcode`\/=\active
+% \catcode`\~=\active
+
+% \gdef\theurlcolon {\nobreak\hbox{\lettercolon}\allowbreak}
+% \gdef\theurlslash#1{\nobreak\hbox{\letterslash}\ifx#1\relax\else\ifnum`/=\expandafter`\string#1\else\allowbreak\fi#1\fi}
+% \gdef\theurlhat {\allowbreak\hbox{\letterhat}\nobreak}
+% \gdef\theurltilde {\allowbreak\hbox{\lettertilde}\nobreak}
+
+% \gdef\ForMojcaWhoLikesHacks#1%
+% {\dontleavehmode
+% \begingroup
+% \mathcode`\:="8000 \let:\theurlcolon
+% \mathcode`\^="8000 \let^\theurlhat
+% \mathcode`\/="8000 \let/\theurlslash
+% \mathcode`\~="8000 \let~\theurltilde
+% \everymath\emptytoks
+% \mathsurround\zeropoint$\tf#1\relax$%
+% \endgroup}
+% \egroup
+
+% \hsize 1mm \ForMojcaWhoLikesHacks{http://www.sil.org//silesr/}
diff --git a/tex/context/base/lang-url.mkiv b/tex/context/base/lang-url.mkiv
index 7479fed68..c22f9f420 100644
--- a/tex/context/base/lang-url.mkiv
+++ b/tex/context/base/lang-url.mkiv
@@ -15,7 +15,30 @@
\unprotect
-% \urlsplitmode is not (yet) supported (not that much needed)
+%D \macros
+%D {hyphenatedurl}
+%D
+%D For those who want to put full \URL's in a text, we offer
+%D
+%D \startbuffer
+%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D which breaks at the appropriate places. Watch the \type{#}
+%D hack.
+%D
+%D When passed as argument, like in \type {\goto}, one needs
+%D to substitute a \type {\\} for each \type{#}.
+%D
+%D \startbuffer
+%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
+%D \stopbuffer
+%D
+%D \typebuffer
+
+\ifx\urlsplitmode\undefined \chardef\urlsplitmode\zerocount \fi % not supported in mkiv
\newtoks\everyhyphenatedurl
@@ -54,11 +77,34 @@
\let\n\dohyphenatedurlnormal
\let\b\dohyphenatedurlbefore
\let\a\dohyphenatedurlafter
- \expanded{\ctxlua{commands.hyphenatedurl.action(
+ \normalexpanded{\noexpand\ctxlua{commands.hyphenatedurl.action(
\!!bs\noexpand\detokenize{#1}\!!es,
\number\hyphenatedurllefthyphenmin,
\number\hyphenatedurlrighthyphenmin
)}}%
\endgroup}
+%D \macros
+%D {hyphenatedfilename}
+%D
+%D For the moment we treat filenames in a similar way,
+%D
+%D \starttyping
+%D \hyphenatedfilename{here/there/filename.suffix}
+%D \stoptyping
+
+\ifx\hyphenatedfilename\undefined \let\hyphenatedfilename\hyphenatedurl \fi
+
+% \def\test#1%
+% {\dontleavehmode
+% \begingroup
+% \tttf
+% \hyphenatedurl {%
+% \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
+% \letterhash #1\letterhash #1\letterpercent #1\letterslash #1\letterampersand
+% }%
+% \endgroup}
+
+% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
+
\protect \endinput
diff --git a/tex/context/base/lang-url.tex b/tex/context/base/lang-url.tex
deleted file mode 100644
index 3eb891914..000000000
--- a/tex/context/base/lang-url.tex
+++ /dev/null
@@ -1,70 +0,0 @@
-%D \module
-%D [ file=lang-url,
-%D version=2008.01.22, % used to be lang-mis
-%D title=\CONTEXT\ Language Macros,
-%D subtitle=Language Options,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Language Macros / URL}
-
-\loadmarkfile{lang-url}
-
-\unprotect
-
-\ifx\urlsplitmode\undefined \chardef\urlsplitmode\zerocount \fi % not supported in mkiv
-
-%D \macros
-%D {hyphenatedurl}
-%D
-%D For those who want to put full \URL's in a text, we offer
-%D
-%D \startbuffer
-%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D which breaks at the appropriate places. Watch the \type{#}
-%D hack.
-%D
-%D When passed as argument, like in \type {\goto}, one needs
-%D to substitute a \type {\\} for each \type{#}.
-%D
-%D \startbuffer
-%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
-%D \stopbuffer
-%D
-%D \typebuffer
-
-\ifx\hyphenatedurl\undefined \let\hyphenatedurl\firstofoneargument \fi
-
-%D \macros
-%D {hyphenatedfilename}
-%D
-%D For the moment we treat filenames in a similar way,
-%D
-%D \starttyping
-%D \hyphenatedfilename{here/there/filename.suffix}
-%D \stoptyping
-
-\ifx\hyphenatedfilename\undefined \let\hyphenatedfilename\hyphenatedurl \fi
-
-% \def\test#1%
-% {\dontleavehmode
-% \begingroup
-% \tttf
-% \hyphenatedurl {%
-% \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
-% \letterhash #1\letterhash #1\letterpercent #1\letterslash #1\letterampersand
-% }%
-% \endgroup}
-
-% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
-
-\protect \endinput
diff --git a/tex/context/base/lang-vn.tex b/tex/context/base/lang-vn.tex
index 22bbe9ff6..27d2a48a1 100644
--- a/tex/context/base/lang-vn.tex
+++ b/tex/context/base/lang-vn.tex
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Vietnamese Language}
+\writestatus{loading}{ConTeXt Language Macros / Vietnamese Language}
%D The framework of this module is set up by Hans Hagen while
%D many of the first translations were done by Tobias. Later
@@ -37,7 +37,8 @@
\c!leftquotation=\quotedblleft,
\c!rightquotation=\quotedblright,
\c!date={{ },dd,{/},mm,{/},yy},
- \c!state=\v!stop]
+ \s!mapping=t5,
+ \s!encoding=t5]
\installlanguage [vietnamese] [\s!vi]
diff --git a/tex/context/base/luat-bas.tex b/tex/context/base/luat-bas.tex
new file mode 100644
index 000000000..a78455173
--- /dev/null
+++ b/tex/context/base/luat-bas.tex
@@ -0,0 +1,64 @@
+%D \module
+%D [ file=luat-bas, % moved from luat-lib,
+%D version=2006.09.11,
+%D title=\CONTEXT\ Lua Macros,
+%D subtitle=Basic \LUA\ Libraries,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% \writestatus{loading}{ConTeXt Lua Macros / Basic Lua Libraries}
+
+%D This will move cq. become configurable. The XML like output is just
+%D an example.
+
+% todo \let\normaleverytoks\everytoks \newtoks\everytoke \normaleverytoks{\the\everytoks}
+
+\chardef\statuswidth=15
+\chardef\statuswrite=16
+
+\newtoks\everywritestring
+
+\def\writedirect {\immediate\write\statuswrite}
+\def\writeline {\writedirect{}}
+\def\writestring#1{\begingroup\the\everywritestring\writedirect{#1}\endgroup}
+
+\ifx\normalwritestatus\undefined \def\normalwritestatus#1#2{\writedirect{#1 : #2}} \fi
+
+% Because all libs are also on bytecodes we can start without stub. However,
+% some initializations need to take place before the \TEX\ engine itself
+% kicks in, especially memory settings and so. In due time we might make the
+% stub smaller and just create a configuration startup file.
+
+\registerctxluafile{l-string} {1.001}
+\registerctxluafile{l-lpeg} {1.001}
+\registerctxluafile{l-boolean}{1.001}
+\registerctxluafile{l-number} {1.001}
+\registerctxluafile{l-math} {1.001}
+\registerctxluafile{l-table} {1.001}
+\registerctxluafile{l-aux} {1.001}
+\registerctxluafile{l-io} {1.001}
+\registerctxluafile{l-os} {1.001}
+\registerctxluafile{l-file} {1.001}
+\registerctxluafile{l-md5} {1.001}
+\registerctxluafile{l-dir} {1.001}
+\registerctxluafile{l-unicode}{1.001}
+\registerctxluafile{l-utils} {1.001}
+\registerctxluafile{l-dimen} {1.001}
+\registerctxluafile{l-url} {1.001}
+\registerctxluafile{l-set} {1.001}
+
+% \registerctxluafile{socket.lua}{}
+% \registerctxluafile{ltn12.lua} {}
+% \registerctxluafile{mime.lua} {}
+% \registerctxluafile{http.lua} {}
+% \registerctxluafile{url.lua} {}
+% \registerctxluafile{tp.lua} {}
+% \registerctxluafile{ftp.lua} {}
+% %registerctxluafile{smtp.lua} {}
+
+\endinput
diff --git a/tex/context/base/luat-cbk.lua b/tex/context/base/luat-cbk.lua
index 4069fe61f..d8b508c13 100644
--- a/tex/context/base/luat-cbk.lua
+++ b/tex/context/base/luat-cbk.lua
@@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['luat-cbk'] = {
license = "see context related readme files"
}
+local trace_checking = false trackers.register("memory.checking", function(v) trace_checking = v end)
+
--[[ldx--
Callbacks are the real asset of . They permit you to hook
your own code into the engine. Here we implement a few handy
@@ -67,7 +69,6 @@ end)
This does a one-shot.
--ldx]]--
-
--[[ldx--
Callbacks may result in doing some hard work
which takes time and above all resourses. Sometimes it makes
@@ -97,8 +98,8 @@ because messing aroudn with the gc is too unpredictable.
garbagecollector = garbagecollector or { }
-garbagecollector.trace = false
-garbagecollector.enabled = false
+garbagecollector.enabled = false
+garbagecollector.criterium = 4*1024*1024
-- Lua allocates up to 12 times the amount of memory needed for
-- handling a string, and for large binary chunks (like chinese otf
@@ -122,13 +123,11 @@ garbagecollector.enabled = false
-- As a result of this, LuaTeX now uses an optimized version of f:read("*a"),
-- one that does not use the 4K allocations but allocates in one step.
-garbagecollector.criterium = 4*1024*1024
-
function garbagecollector.check(size,criterium)
if garbagecollector.enabled then
criterium = criterium or garbagecollector.criterium
if not size or (criterium and criterium > 0 and size > criterium) then
- if garbagecollector.trace then
+ if trace_checking then
local round = math.round or math.floor
local b = collectgarbage("count")
collectgarbage("collect")
@@ -140,5 +139,3 @@ function garbagecollector.check(size,criterium)
end
end
end
-
-
diff --git a/tex/context/base/luat-cnf.lua b/tex/context/base/luat-cnf.lua
new file mode 100644
index 000000000..9f237b981
--- /dev/null
+++ b/tex/context/base/luat-cnf.lua
@@ -0,0 +1,114 @@
+if not modules then modules = { } end modules ['luat-cnf'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, concat = string.format, table.concat
+
+luatex = luatex or { }
+
+luatex.variablenames = {
+ 'main_memory', 'extra_mem_bot', 'extra_mem_top',
+ 'buf_size','expand_depth',
+ 'font_max', 'font_mem_size',
+ 'hash_extra', 'max_strings', 'pool_free', 'pool_size', 'string_vacancies',
+ 'obj_tab_size', 'pdf_mem_size', 'dest_names_size',
+ 'nest_size', 'param_size', 'save_size', 'stack_size','expand_depth',
+ 'trie_size', 'hyph_size', 'max_in_open',
+ 'ocp_stack_size', 'ocp_list_size', 'ocp_buf_size',
+ 'max_print_line',
+}
+
+function luatex.variables()
+ local t, x = { }, nil
+ for _,v in next, luatex.variablenames do
+ x = resolvers.var_value(v)
+ if x and x:find("^%d+$") then
+ t[v] = tonumber(x)
+ end
+ end
+ return t
+end
+
+if not luatex.variables_set then
+ for k, v in next, luatex.variables() do
+ texconfig[k] = v
+ end
+ luatex.variables_set = true
+end
+
+local stub = [[
+-- checking
+
+storage = storage or {}
+luatex = luatex or {}
+
+-- as soon as possible
+
+luatex.starttime = os.gettimeofday()
+
+-- we provide our own file handling
+
+texconfig.kpse_init = false
+texconfig.shell_escape = 't'
+
+-- this will happen after the format is loaded
+
+function texconfig.init()
+
+ -- shortcut and helper
+
+ local b = lua.bytecode
+
+ local function init(start)
+ local i = start
+ while b[i] do
+ b[i]() ; b[i] = nil ; i = i + 1
+ end
+ return i - start
+ end
+
+ -- the stored tables and modules
+
+ storage.noftables = init(0)
+ storage.nofmodules = init(%s)
+
+end
+
+-- we provide a qualified path
+
+callback.register('find_format_file',function(name)
+ texconfig.formatname = name
+ return name
+end)
+
+-- done, from now on input and callbacks are internal
+]]
+
+function luatex.dumpstate(name,firsttable)
+ if tex and tex.luatexversion < 38 then
+ os.remove(name)
+ elseif true then
+ local t = {
+ "-- this file is generated, don't change it\n",
+ "-- configuration (can be overloaded later)\n"
+ }
+ for _,v in next, luatex.variablenames do
+ local tv = texconfig[v]
+ if tv then
+ t[#t+1] = format("texconfig.%s=%s",v,tv)
+ end
+ end
+ io.savedata(name,format("%s\n\n%s",concat(t,"\n"),format(stub,firsttable or 501)))
+ else
+ io.savedata(name,format(stub,firsttable or 501))
+ end
+end
+
+texconfig.kpse_init = false
+texconfig.max_print_line = 100000
+texconfig.max_in_open = 127
+texconfig.shell_escape = 't'
diff --git a/tex/context/base/luat-cod.tex b/tex/context/base/luat-cod.tex
new file mode 100644
index 000000000..07db36483
--- /dev/null
+++ b/tex/context/base/luat-cod.tex
@@ -0,0 +1,161 @@
+%D \module
+%D [ file=luat-cod,
+%D version=2005.05.26,
+%D title=\CONTEXT\ Lua Macros,
+%D subtitle=Code,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% \writestatus{loading}{ConTeXt Lua Macros / Code}
+
+%D Originally we compiled the lua files externally and loaded
+%D then at runtime, but when the amount grew, we realized that
+%D we needed away to store them in the format, which is what
+%D bytecode arrays do. And so the following is obsolete:
+%D
+%D \starttyping
+%D \chardef\ctxluaembeddingmode \plusone
+%D
+%D 0 = external compilation and loading
+%D 1 = runtime compilation and embedding
+%D \stoptyping
+%D
+%D Allocation of \LUA\ engines has changed too. The original idea
+%D was to have multiple \LUA\ instances and it worked that way for
+%D several years. Hoewver in practice we used only one engine because
+%D scripts need to share data anyway. So eventually \LUATEX\ got only
+%D one instance. Because each call is reentrant there is not much
+%D danger for crashes.
+
+\def\ctxdirectlua{\directlua\zerocount}
+\def\ctxlatelua {\latelua \zerocount}
+
+%D Take your choice \unknown
+
+\let\ctxlua \ctxdirectlua
+\let\luacode \ctxdirectlua
+\let\lateluacode \ctxlatelua
+\let\directluacode\ctxdirectlua
+
+%D Reporting the version of \LUA\ that we use is done as follows:
+
+\edef\luaversion{\ctxlua{tex.print(_VERSION)}}
+
+%D We want to define \LUA\ related things in the format but
+%D need to reload code because \LUA\ instances themselves are
+%D not dumped into the format.
+
+\newtoks\everyloadluacode
+\newtoks\everyfinalizeluacode
+
+\normaleveryjob{\the\everyloadluacode\the\everyfinalizeluacode\the\everyjob}
+
+\newif\ifproductionrun
+
+%D Here we operate in the \TEX\ catcode regime as we haven't yet defined
+%D catcode regimes. A chicken or egg problem.
+
+\long\def\startruntimeluacode#1\stopruntimeluacode % only simple code (load +init)
+ {\ifproductionrun
+ \global\let\startruntimeluacode\relax
+ \global\let\stopruntimeluacode \relax
+ \else
+ \global\everyloadluacode\expandafter{\the\everyloadluacode#1}%
+ \fi
+ #1} % maybe no interference
+
+\long\def\startruntimectxluacode#1\stopruntimectxluacode
+ {\startruntimeluacode\ctxlua{#1}\stopruntimeluacode}
+
+%D Next we load the initialization code.
+
+\startruntimectxluacode
+ environment = environment or { }
+ environment.jobname = "\jobname" % tex.jobname
+ environment.initex = \ifproductionrun false \else true \fi % tex.formatname == ""
+ environment.version = "\fmtversion"
+\stopruntimectxluacode
+
+% we start at 500, below this, we store predefined data (dumps)
+
+\newcount\luabytecodecounter \luabytecodecounter=500
+
+\startruntimectxluacode
+ lua.bytedata = lua.bytedata or { }
+\stopruntimectxluacode
+
+%D Handy when we expand:
+
+\let\stopruntimeluacode \relax
+\let\stopruntimectxluacode\relax
+
+\long\def\lastexpanded{} % todo: elsewhere we use \@@expanded
+
+\long\def\expanded#1{\long\xdef\lastexpanded{\noexpand#1}\lastexpanded}
+
+%D More code:
+
+% \def\ctxluabytecode#1% executes an already loaded chunk
+% {\ctxlua {
+% local str = ''
+% if lua.bytedata[#1] then
+% str = " from file " .. lua.bytedata[#1][1] .. " version " .. lua.bytedata[#1][2]
+% end
+% if lua.bytecode[#1] then
+% if environment.initex then
+% texio.write_nl("bytecode: executing blob " .. "#1" .. str)
+% assert(lua.bytecode[#1])()
+% else
+% texio.write_nl("bytecode: initializing blob " .. "#1" .. str)
+% assert(lua.bytecode[#1])()
+% lua.bytecode[#1] = nil
+% end
+% else
+% texio.write_nl("bytecode: invalid blob " .. "#1" .. str)
+% end
+% }}
+
+\def\ctxluabytecode#1% executes an already loaded chunk
+ {\ctxlua {
+ local lbc = lua.bytecode
+ if lbc[#1] then
+ assert(lbc[#1])()
+ if not environment.initex then
+ lbc[#1] = nil
+ end
+ end
+ }}
+
+\def\ctxluabyteload#1#2% registers and compiles chunk
+ {\global\advance\luabytecodecounter \plusone
+ \expanded{\startruntimectxluacode
+ lua.bytedata[\the\luabytecodecounter] = { "#1", "#2" }
+ \stopruntimectxluacode}%
+ \ctxlua {
+ lua.bytedata[\the\luabytecodecounter] = { "#1", "#2" }
+ lua.bytecode[\the\luabytecodecounter] = environment.luafilechunk("#1")
+ }}
+
+\def\ctxloadluafile#1#2% load a (either not compiled) chunk at runtime
+ {\doifelsenothing{#2}
+ {\ctxlua{environment.loadluafile("#1")}}
+ {\ctxlua{environment.loadluafile("#1",#2)}}}
+
+\def\registerctxluafile#1#2% name version
+ {\ifproductionrun
+ \ctxloadluafile{#1}{#2}%
+ \else
+ \ctxluabyteload{#1}{#2}% can go away
+ \fi
+ \global\everyloadluacode\expandafter\expandafter\expandafter{\expandafter\the\expandafter\everyloadluacode
+ \expandafter\ctxluabytecode\expandafter{\the\luabytecodecounter}}%
+ \ctxluabytecode{\the\luabytecodecounter}}
+
+\everydump\expandafter{\the\everydump\ctxlua{luatex.dumpstate(environment.jobname..".lui",501)}}
+
+\endinput
diff --git a/tex/context/base/luat-crl.lua b/tex/context/base/luat-crl.lua
deleted file mode 100644
index 5ebd62d22..000000000
--- a/tex/context/base/luat-crl.lua
+++ /dev/null
@@ -1,53 +0,0 @@
--- filename : luat-crl.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-crl'] = 1.001
-if not curl then curl = { } end
-
-curl.cached = { }
-curl.cachepath = caches.definepath("curl")
-
-function curl.fetch(protocol, name)
- local cachename = curl.cachepath() .. "/" .. name:gsub("[^%a%d%.]+","-")
--- cachename = cachename:gsub("[\\/]", io.fileseparator)
- cachename = cachename:gsub("[\\]", "/")
- if not curl.cached[name] then
- if not io.exists(cachename) then
- curl.cached[name] = cachename
- local command = "curl --silent --create-dirs --output " .. cachename .. " " .. name -- no protocol .. "://"
- os.spawn(command)
- end
- if io.exists(cachename) then
- curl.cached[name] = cachename
- else
- curl.cached[name] = ""
- end
- end
- return curl.cached[name]
-end
-
-function input.finders.curl(protocol,filename)
- local foundname = curl.fetch(protocol, filename)
- return input.finders.generic(protocol,foundname,filetype)
-end
-function input.openers.curl(protocol,filename)
- return input.openers.generic(protocol,filename)
-end
-function input.loaders.curl(protocol,filename)
- return input.loaders.generic(protocol,filename)
-end
-
--- todo: metamethod
-
-function curl.install(protocol)
- input.finders[protocol] = function (filename,filetype) return input.finders.curl(protocol,filename) end
- input.openers[protocol] = function (filename) return input.openers.curl(protocol,filename) end
- input.loaders[protocol] = function (filename) return input.loaders.curl(protocol,filename) end
-end
-
-curl.install('http')
-curl.install('https')
-curl.install('ftp')
diff --git a/tex/context/base/luat-deb.lua b/tex/context/base/luat-deb.lua
deleted file mode 100644
index a32d923bd..000000000
--- a/tex/context/base/luat-deb.lua
+++ /dev/null
@@ -1,154 +0,0 @@
--- filename : luat-deb.lua
--- comment : companion to luat-deb.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-deb'] = 1.001
-if not lmx then lmx = { } end
-if not lmx.variables then lmx.variables = { } end
-
-lmx.variables['color-background-green'] = '#4F6F6F'
-lmx.variables['color-background-blue'] = '#6F6F8F'
-lmx.variables['color-background-yellow'] = '#8F8F6F'
-lmx.variables['color-background-purple'] = '#8F6F8F'
-
-lmx.variables['color-background-body'] = '#808080'
-lmx.variables['color-background-main'] = '#3F3F3F'
-lmx.variables['color-background-one'] = lmx.variables['color-background-green']
-lmx.variables['color-background-two'] = lmx.variables['color-background-blue']
-
-lmx.variables['title-default'] = 'ConTeXt Status Information'
-lmx.variables['title'] = lmx.variables['title-default']
-
-if not tracers then tracers = { } end
-if not tracers.list then tracers.list = { } end
-if not tracers.strings then tracers.strings = { } end
-
-tracers.strings.undefined = "undefined"
-
-function tracers.split(csname)
- return csname:match("^(.+):(.+)$")
-end
-
-function tracers.type(csname)
- tag, name = tracers.split(csname)
- if tag then return tag else return nil end
-end
-
-function tracers.name(csname)
- tag, name = tracers.split(csname)
- if tag then return name else return csname end
-end
-
-function tracers.cs(csname)
- tag, name = tracers.split(csname)
- if tracers.types[tag] then
- return tracers.types[tag](name)
- else
- return tracers.primitive(csname)
- end
-end
-
-function tracers.dimen(name)
- return (tex.dimen[name] and number.topoints(tex.dimen[name])) or tracers.strings.undefined
-end
-
-function tracers.count(name)
- return tex.count[name] or tracers.strings.undefined
-end
-
-function tracers.toks(name)
- return (tex.toks[name] and string.limit(tex.toks[name],40)) or tracers.strings.undefined
-end
-
-function tracers.primitive(name)
- return tex[name] or tracers.strings.undefined
-end
-
-tracers.types = {
- ['d'] = tracers.dimen,
- ['c'] = tracers.count,
- ['t'] = tracers.toks,
- ['p'] = tracers.primitive
-}
-
-function tracers.knownlist(name)
- return tracers.list[name] and #tracers.list[name] > 0
-end
-
-function tracers.showdebuginfo()
- lmx.set('title', 'ConTeXt Debug Information')
- lmx.set('color-background-one', lmx.get('color-background-green'))
- lmx.set('color-background-two', lmx.get('color-background-blue'))
- lmx.show('context-debug.lmx')
- lmx.restore()
-end
-
-function tracers.showerror()
- lmx.set('title', 'ConTeXt Error Information')
- lmx.set('errormessage', status.lasterrorstring)
- lmx.set('linenumber', status.linenumber)
- lmx.set('color-background-one', lmx.get('color-background-yellow'))
- lmx.set('color-background-two', lmx.get('color-background-purple'))
- local filename = status.filename
- local linenumber = tonumber(status.linenumber or "0")
- if not filename then
- lmx.set('filename', 'unknown')
- lmx.set('errorcontext', 'error in filename')
- elseif type(filename) == "number" then
- lmx.set('filename', "")
- lmx.set('errorcontext', 'unknown error')
- elseif io.exists(filename) then
- -- todo: use an input opener so that we also catch utf16 an reencoding
- lmx.set('filename', filename)
- lines = io.lines(filename)
- if lines then
- local context = { }
- n, m = 1, linenumber
- b, e = m-10, m+10
- s = string.len(tostring(e))
- for line in lines do
- if n > e then
- break
- elseif n > b then
- if n == m then
- context[#context+1] = string.format("%" .. s .. "d",n) .. " >> " .. line
- else
- context[#context+1] = string.format("%" .. s .. "d",n) .. " " .. line
- end
- end
- n = n + 1
- end
- lmx.set('errorcontext', table.concat(context,"\n"))
- else
- lmx.set('errorcontext', "")
- end
- else
- lmx.set('filename', filename)
- lmx.set('errorcontext', 'file not found')
- end
- lmx.show('context-error.lmx')
- lmx.restore()
-end
-
-function tracers.overloaderror()
---~ callback.register('show_error_hook', function(identifier, filename, linenumber)
---~ tracers.showerror(identifier, filename, linenumber)
---~ end )
- callback.register('show_error_hook', tracers.showerror)
-end
-
-tracers.list['scratch'] = {
- 0, 2, 4, 6, 8
-}
-
-tracers.list['internals'] = {
- 'p:hsize', 'p:parindent', 'p:leftskip','p:rightskip',
- 'p:vsize', 'p:parskip', 'p:baselineskip', 'p:lineskip', 'p:topskip'
-}
-
-tracers.list['context'] = {
- 'd:lineheight',
- 'c:realpageno', 'c:pageno', 'c:subpageno'
-}
diff --git a/tex/context/base/luat-deb.tex b/tex/context/base/luat-deb.tex
deleted file mode 100644
index 55686ac11..000000000
--- a/tex/context/base/luat-deb.tex
+++ /dev/null
@@ -1,49 +0,0 @@
-%D \module
-%D [ file=luat-deb,
-%D version=2005.11.06,
-%D title=\CONTEXT\ Communication Macros,
-%D subtitle=Initialization,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Communication Support (initialization)}
-
-\registerctxluafile{luat-deb}{1.001}
-
-\startruntimeluacode
- \ctxlua {
- lmx.htmfile = function(name) return environment.jobname .. "-status.html" end
- lmx.lmxfile = function(name) return environment.texfile(name) end
- }
-\stopruntimeluacode
-
-\def\showdebuginfo{\ctxlua{tracers.showdebuginfo()}}
-\def\overloaderror{\ctxlua{tracers.overloaderror()}}
-
-\def\breakpoint{\showdebuginfo\wait}
-
-\registerctxluafile{luat-tra}{1.001}
-
-\appendtoks
- \ctxlua {
- if debugger.tracing() then
- debugger.enable() ;
- end
- }%
-\to \everyjob
-
-\appendtoks
- \ctxlua {
- if debugger.tracing() then
- debugger.disable() ;
- debugger.savestats("\jobname-luacalls.log") ;
- end
- }%
-\to \everybye
-
-\endinput
diff --git a/tex/context/base/luat-dum.lua b/tex/context/base/luat-dum.lua
new file mode 100644
index 000000000..f2ff50577
--- /dev/null
+++ b/tex/context/base/luat-dum.lua
@@ -0,0 +1,60 @@
+if not modules then modules = { } end modules ['luat-dum'] = {
+ version = 1.001,
+ comment = "companion to luatex-*.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local dummyfunction = function() end
+
+statistics = {
+ register = dummyfunction,
+ starttiming = dummyfunction,
+ stoptiming = dummyfunction,
+}
+trackers = {
+ register = dummyfunction,
+ enable = dummyfunction,
+ disable = dummyfunction,
+}
+storage = {
+ register = dummyfunction,
+ shared = { },
+}
+logs = {
+ report = dummyfunction,
+ simple = dummyfunction,
+}
+tasks = {
+ new = dummyfunction,
+ actions = dummyfunction,
+ appendaction = dummyfunction,
+ prependaction = dummyfunction,
+}
+
+-- we need to cheat a bit here
+
+texconfig.kpse_init = true
+
+resolvers = resolvers or { } -- no fancy file helpers used
+
+local remapper = {
+ otf = "opentype fonts",
+ ttf = "truetype fonts",
+ ttc = "truetype fonts",
+ cid = "other text files", -- will become "cid files"
+}
+
+function resolvers.find_file(name,kind)
+ name = string.gsub(name,"\\","\/")
+ kind = string.lower(kind)
+ return kpse.find_file(name,(kind and kind ~= "" and (remapper[kind] or kind)) or "tex")
+end
+
+function resolvers.findbinfile(name,kind)
+ if not kind or kind == "" then
+ kind = file.extname(name) -- string.match(name,"%.([^%.]-)$")
+ end
+ return resolvers.find_file(name,(kind and remapper[kind]) or kind)
+end
diff --git a/tex/context/base/luat-env.lua b/tex/context/base/luat-env.lua
index 67e2f7050..9c05b249c 100644
--- a/tex/context/base/luat-env.lua
+++ b/tex/context/base/luat-env.lua
@@ -1,50 +1,217 @@
--- filename : luat-env.lua
--- comment : companion to luat-env.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['luat-env'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
--- here we don't assume any extra libraries
-
--- A former version provides functionality for non embeded core
+-- A former version provided functionality for non embeded core
-- scripts i.e. runtime library loading. Given the amount of
-- Lua code we use now, this no longer makes sense. Much of this
--- evolved before bytecode arrays were available. Much code has
--- disappeared already.
+-- evolved before bytecode arrays were available and so a lot of
+-- code has disappeared already.
-if not versions then versions = { } end versions['luat-env'] = 1.001
+local trace_verbose = false trackers.register("resolvers.verbose", function(v) trace_verbose = v end)
+local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v trackers.enable("resolvers.verbose") end)
--- environment
+local format = string.format
+
+-- precautions
+
+os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
+
+function os.setlocale()
+ -- no way you can mess with it
+end
-if not environment then environment = { } end
+-- dirty tricks
-environment.trace = false
+if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
+ arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
+end
+
+if profiler and os.env["MTX_PROFILE_RUN"] == "YES" then
+ profiler.start("luatex-profile.log")
+end
+
+-- environment
--- kpse is overloaded by this time
+environment = environment or { }
+environment.arguments = { }
+environment.files = { }
+environment.sortedflags = nil
if not environment.jobname or environment.jobname == "" then if tex then environment.jobname = tex.jobname end end
if not environment.version or environment.version == "" then environment.version = "unknown" end
+if not environment.jobname then environment.jobname = "unknown" end
+
+function environment.initialize_arguments(arg)
+ local arguments, files = { }, { }
+ environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
+ for index, argument in pairs(arg) do
+ if index > 0 then
+ local flag, value = argument:match("^%-+(.+)=(.-)$")
+ if flag then
+ arguments[flag] = string.unquote(value or "")
+ else
+ flag = argument:match("^%-+(.+)")
+ if flag then
+ arguments[flag] = true
+ else
+ files[#files+1] = argument
+ end
+ end
+ end
+ end
+ environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
+end
+
+function environment.setargument(name,value)
+ environment.arguments[name] = value
+end
+
+-- todo: defaults, better checks e.g on type (boolean versus string)
+--
+-- tricky: too many hits when we support partials unless we add
+-- a registration of arguments so from now on we have 'partial'
+
+function environment.argument(name,partial)
+ local arguments, sortedflags = environment.arguments, environment.sortedflags
+ if arguments[name] then
+ return arguments[name]
+ elseif partial then
+ if not sortedflags then
+ sortedflags = { }
+ for _,v in pairs(table.sortedkeys(arguments)) do
+ sortedflags[#sortedflags+1] = "^" .. v
+ end
+ environment.sortedflags = sortedflags
+ end
+ -- example of potential clash: ^mode ^modefile
+ for _,v in ipairs(sortedflags) do
+ if name:find(v) then
+ return arguments[v:sub(2,#v)]
+ end
+ end
+ end
+ return nil
+end
+
+function environment.split_arguments(separator) -- rather special, cut-off before separator
+ local done, before, after = false, { }, { }
+ for _,v in ipairs(environment.original_arguments) do
+ if not done and v == separator then
+ done = true
+ elseif done then
+ after[#after+1] = v
+ else
+ before[#before+1] = v
+ end
+ end
+ return before, after
+end
+
+function environment.reconstruct_commandline(arg,noquote)
+ arg = arg or environment.original_arguments
+ if noquote and #arg == 1 then
+ local a = arg[1]
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ return a
+ elseif next(arg) then
+ local result = { }
+ for _,a in ipairs(arg) do -- ipairs 1 .. #n
+ a = resolvers.resolve(a)
+ a = a:unquote()
+ a = a:gsub('"','\\"') -- tricky
+ if a:find(" ") then
+ result[#result+1] = a:quote()
+ else
+ result[#result+1] = a
+ end
+ end
+ return table.join(result," ")
+ else
+ return ""
+ end
+end
+
+if arg then
+
+ -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
+ local newarg, instring = { }, false
+
+ for index, argument in ipairs(arg) do
+ if argument:find("^\"") then
+ newarg[#newarg+1] = argument:gsub("^\"","")
+ if not argument:find("\"$") then
+ instring = true
+ end
+ elseif argument:find("\"$") then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
+ instring = false
+ elseif instring then
+ newarg[#newarg] = newarg[#newarg] .. " " .. argument
+ else
+ newarg[#newarg+1] = argument
+ end
+ end
+ for i=1,-5,-1 do
+ newarg[i] = arg[i]
+ end
+
+ environment.initialize_arguments(newarg)
+ environment.original_arguments = newarg
+ environment.raw_arguments = arg
+
+ arg = { } -- prevent duplicate handling
+
+end
+
+-- weird place ... depends on a not yet loaded module
function environment.texfile(filename)
- return input.find_file(filename,'tex')
+ return resolvers.find_file(filename,'tex')
end
function environment.luafile(filename)
- return input.find_file(filename,'tex') or input.find_file(filename,'texmfscripts')
+ local resolved = resolvers.find_file(filename,'tex') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ resolved = resolvers.find_file(filename,'texmfscripts') or ""
+ if resolved ~= "" then
+ return resolved
+ end
+ return resolvers.find_file(filename,'luatexlibs') or ""
end
-if not environment.jobname then environment.jobname = "unknown" end
-
environment.loadedluacode = loadfile -- can be overloaded
+--~ function environment.loadedluacode(name)
+--~ if os.spawn("texluac -s -o texluac.luc " .. name) == 0 then
+--~ local chunk = loadstring(io.loaddata("texluac.luc"))
+--~ os.remove("texluac.luc")
+--~ return chunk
+--~ else
+--~ environment.loadedluacode = loadfile -- can be overloaded
+--~ return loadfile(name)
+--~ end
+--~ end
+
function environment.luafilechunk(filename) -- used for loading lua bytecode in the format
filename = file.replacesuffix(filename, "lua")
local fullname = environment.luafile(filename)
if fullname and fullname ~= "" then
- input.report("loading file %s", fullname)
+ if trace_verbose then
+ logs.report("fileio","loading file %s", fullname)
+ end
return environment.loadedluacode(fullname)
else
- input.report("unknown file %s", filename)
+ if trace_verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
return nil
end
end
@@ -62,7 +229,9 @@ function environment.loadluafile(filename, version)
-- when not overloaded by explicit suffix we look for a luc file first
local fullname = (lucname and environment.luafile(lucname)) or ""
if fullname ~= "" then
- input.report("loading %s", fullname)
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
chunk = loadfile(fullname) -- this way we don't need a file exists check
end
if chunk then
@@ -78,7 +247,9 @@ function environment.loadluafile(filename, version)
if v == version then
return true
else
- input.report("version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ if trace_verbose then
+ logs.report("fileio","version mismatch for %s: lua=%s, luc=%s", filename, v, version)
+ end
environment.loadluafile(filename)
end
else
@@ -87,10 +258,14 @@ function environment.loadluafile(filename, version)
end
fullname = (luaname and environment.luafile(luaname)) or ""
if fullname ~= "" then
- input.report("loading %s", fullname)
+ if trace_verbose then
+ logs.report("fileio","loading %s", fullname)
+ end
chunk = loadfile(fullname) -- this way we don't need a file exists check
if not chunk then
- input.report("unknown file %s", filename)
+ if verbose then
+ logs.report("fileio","unknown file %s", filename)
+ end
else
assert(chunk)()
return true
@@ -98,82 +273,3 @@ function environment.loadluafile(filename, version)
end
return false
end
-
--- -- -- the next function was posted by Peter Cawley on the lua list -- -- --
--- -- -- -- -- --
--- -- -- stripping makes the compressed format file about 1MB smaller -- -- --
--- -- -- -- -- --
--- -- -- using this trick is at your own risk -- -- --
--- -- -- -- -- --
--- -- -- this is just an experiment, this feature may disappear -- -- --
-
-local function strip_code(dump)
- local version, format, endian, int, size, ins, num = dump:byte(5, 11)
- local subint
- if endian == 1 then
- subint = function(dump, i, l)
- local val = 0
- for n = l, 1, -1 do
- val = val * 256 + dump:byte(i + n - 1)
- end
- return val, i + l
- end
- else
- subint = function(dump, i, l)
- local val = 0
- for n = 1, l, 1 do
- val = val * 256 + dump:byte(i + n - 1)
- end
- return val, i + l
- end
- end
- local strip_function
- strip_function = function(dump)
- local count, offset = subint(dump, 1, size)
- local stripped, dirty = string.rep("\0", size), offset + count
- offset = offset + count + int * 2 + 4
- offset = offset + int + subint(dump, offset, int) * ins
- count, offset = subint(dump, offset, int)
- for n = 1, count do
- local t
- t, offset = subint(dump, offset, 1)
- if t == 1 then
- offset = offset + 1
- elseif t == 4 then
- offset = offset + size + subint(dump, offset, size)
- elseif t == 3 then
- offset = offset + num
- end
- end
- count, offset = subint(dump, offset, int)
- stripped = stripped .. dump:sub(dirty, offset - 1)
- for n = 1, count do
- local proto, off = strip_function(dump:sub(offset, -1))
- stripped, offset = stripped .. proto, offset + off - 1
- end
- offset = offset + subint(dump, offset, int) * int + int
- count, offset = subint(dump, offset, int)
- for n = 1, count do
- offset = offset + subint(dump, offset, size) + size + int * 2
- end
- count, offset = subint(dump, offset, int)
- for n = 1, count do
- offset = offset + subint(dump, offset, size) + size
- end
- stripped = stripped .. string.rep("\0", int * 3)
- return stripped, offset
- end
- return dump:sub(1,12) .. strip_function(dump:sub(13,-1))
-end
-
-environment.stripcode = false -- true
-
-function environment.loadedluacode(fullname)
- if environment.stripcode then
- return loadstring(strip_code(string.dump(loadstring(io.loaddata(fullname)))))
- else
- return loadfile(fullname)
- end
-end
-
--- -- end of stripping code -- --
diff --git a/tex/context/base/luat-env.tex b/tex/context/base/luat-env.tex
deleted file mode 100644
index 164be174c..000000000
--- a/tex/context/base/luat-env.tex
+++ /dev/null
@@ -1,172 +0,0 @@
-%D \module
-%D [ file=luat-env,
-%D version=2005.05.26,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=ConTeXt features,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D Originally we compiled the lua files externally and loaded
-%D then at runtime, but when the amount grew, we realized that
-%D we needed away to store them in the format, which is what
-%D bytecode arrays do. And so the following is obsolete:
-%D
-%D \starttyping
-%D \chardef\ctxluaembeddingmode \plusone
-%D
-%D 0 = external compilation and loading
-%D 1 = runtime compilation and embedding
-%D \stoptyping
-
-% \writestatus{loading}{Lua Support Macros (environment)}
-
-% print (lua.id)
-% print (lua.version)
-% print (lua.startupfile)
-
-%D Allocation of \LUA\ engines.
-
-\newcount\luadefcounter
-
-\ifx\zerocount\undefined \chardef\zerocount=0 \fi
-\ifx\plusone \undefined \chardef\plusone =1 \fi
-
-\def\newlua#1%
- {\global\advance\luadefcounter\plusone
- \mathchardef#1\luadefcounter}
-
-%D We use a dedicated instance for \CONTEXT\ core functionality. In
-%D \CONTEXT we also use this as callback instance. Instance 0 is
-%D the scratch instance.
-
-\ifx\luastartup\undefined \newcount\luastartup \fi
-
-\chardef\CTXlua\zerocount \luadefcounter\CTXlua \luastartup\CTXlua
-
-\def\ctxdirectlua{\directlua\CTXlua} \let\ctxlua\ctxdirectlua
-\def\ctxlatelua {\latelua \CTXlua}
-
-%D The simple \type {\lua} command is just a shortcut to the
-%D zero instance. Beware, we don't use the 0--9 range for
-%D scratch purposes as we do with other registers. First of all
-%D we want to avoid the overhead, but mostly, users can just define
-%D their own.
-
-\newlua \luadefault
-
-\def \lua {\directlua\luadefault} % zero is the main one, and reserved for ctx
-\edef\luaversion{\ctxlua{tex.print(_VERSION)}}
-
-%D We want to define \LUA\ related things in the format but
-%D need to reluad code because \LUA\ instances are not dumped
-%D into the format.
-
-\ifx\undefined\normaleveryjob \let\normaleveryjob\everyjob \newtoks\everyjob \fi
-
-\newtoks\everyloadluacode
-\newtoks\everyfinalizeluacode
-
-\normaleveryjob{\the\everyloadluacode\the\everyfinalizeluacode\the\everyjob}
-
-\newif\ifproductionrun
-
-\long\def\startruntimeluacode#1\stopruntimeluacode % only simple code (load +init)
- {\ifproductionrun
- \global\let\startruntimeluacode\relax
- \global\let\stopruntimeluacode \relax
- \else
- \global\everyloadluacode\expandafter{\the\everyloadluacode#1}%
- \fi
- #1} % maybe no interference
-
-\long\def\startruntimectxluacode#1\stopruntimectxluacode
- {\startruntimeluacode\ctxlua{#1}\stopruntimeluacode}
-
-%D Next we load the initialization code.
-
-\startruntimectxluacode
- environment = environment or { }
- environment.jobname = "\jobname" % tex.jobname
- environment.initex = \ifproductionrun false \else true \fi % tex.formatname == ""
- environment.version = "\contextversion"
-\stopruntimectxluacode
-
-\chardef\ctxluaexecutionmode \zerocount % private
-
-% we start at 500, below this, we store predefined data (dumps)
-
-\newcount\luabytecodecounter \luabytecodecounter=500
-
-\startruntimectxluacode
- if not lua.bytedata then lua.bytedata = { } end
-\stopruntimectxluacode
-
-%D Handy when we expand:
-
-\let\stopruntimeluacode \relax
-\let\stopruntimectxluacode\relax
-
-\ifx\normalprotected \undefined \let\normalprotected \protected \fi
-\ifx\normalunexpanded\undefined \let\normalunexpanded\unexpanded \fi
-\ifx\normalexpanded \undefined \let\normalexpanded \expanded \fi
-
-\long\def\lastexpanded{} % todo: elsewhere we use \@@expanded
-
-\long\def\expanded#1{\long\xdef\lastexpanded{\noexpand#1}\lastexpanded}
-
-%D More code:
-
-\def\ctxluabytecode#1% executes an already loaded chunk
- {\ctxlua {
- do
- local str = ''
- if lua.bytedata[#1] then
- str = " from file " .. lua.bytedata[#1][1] .. " version " .. lua.bytedata[#1][2]
- end
- if lua.bytecode[#1] then
- if environment.initex then
- % logs.report("bytecode","executing blob " .. "#1" .. str)
- assert(lua.bytecode[#1])()
- else
- assert(lua.bytecode[#1])()
- lua.bytecode[#1] = nil
- end
- else
- % logs.report("bytecode", "invalid blob " .. "#1" .. str)
- end
- end
- }}
-
-\def\ctxluabyteload#1#2% registers and compiles chunk
- {\global\advance\luabytecodecounter \plusone
- \expanded{\startruntimectxluacode
- lua.bytedata[\the\luabytecodecounter] = { "#1", "#2" }
- \stopruntimectxluacode}%
- \ctxlua {
- lua.bytedata[\the\luabytecodecounter] = { "#1", "#2" }
- lua.bytecode[\the\luabytecodecounter] = environment.luafilechunk("#1")
- }}
-
-\def\ctxloadluafile#1#2% load a (either not compiled) chunk at runtime
- {\doifelsenothing{#2}
- {\ctxlua{environment.loadluafile("#1")}}
- {\ctxlua{environment.loadluafile("#1",#2)}}}
-
-\def\registerctxluafile#1#2% name version
- {\ifproductionrun \else
- \ctxluabyteload{#1}{#2}%
- \fi
- \global\everyloadluacode\expandafter\expandafter\expandafter{\expandafter\the\expandafter\everyloadluacode
- \expandafter\ctxluabytecode\expandafter{\the\luabytecodecounter}}%
- \ifcase\ctxluaexecutionmode\or\ctxluabytecode{\the\luabytecodecounter}\fi}
-
-\registerctxluafile{luat-env}{1.001}
-
-\chardef\ctxluaexecutionmode \plusone
-
-\endinput
diff --git a/tex/context/base/luat-exe.lua b/tex/context/base/luat-exe.lua
index c2245d568..fd93ad382 100644
--- a/tex/context/base/luat-exe.lua
+++ b/tex/context/base/luat-exe.lua
@@ -1,10 +1,11 @@
--- filename : luat-exe.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['luat-exe'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-if not versions then versions = { } end versions['luat-exe'] = 1.001
if not executer then executer = { } end
executer.permitted = { }
diff --git a/tex/context/base/luat-fio.lua b/tex/context/base/luat-fio.lua
new file mode 100644
index 000000000..3f42b4497
--- /dev/null
+++ b/tex/context/base/luat-fio.lua
@@ -0,0 +1,81 @@
+if not modules then modules = { } end modules ['luat-fio'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local texiowrite_nl = (texio and texio.write_nl) or print
+local texiowrite = (texio and texio.write) or print
+
+local format = string.format
+
+texconfig.kpse_init = false
+texconfig.trace_file_names = true -- also influences pdf fonts reporting .. todo
+texconfig.max_print_line = 100000
+
+kpse = { } setmetatable(kpse, { __index = function(k,v) return input[v] end } )
+
+-- if still present, we overload kpse (put it off-line so to say)
+
+if not resolvers.instance then
+
+ resolvers.reset()
+
+ resolvers.instance.progname = 'context'
+ resolvers.instance.engine = 'luatex'
+ resolvers.instance.validfile = resolvers.validctxfile
+
+ resolvers.load()
+
+ if callback then
+
+ callback.register('find_read_file' , function(id,name) return resolvers.findtexfile(name) end)
+ callback.register('open_read_file' , function( name) return resolvers.opentexfile(name) end)
+
+ callback.register('find_data_file' , function(name) return resolvers.findbinfile(name,"tex") end)
+ callback.register('find_enc_file' , function(name) return resolvers.findbinfile(name,"enc") end)
+ callback.register('find_font_file' , function(name) return resolvers.findbinfile(name,"tfm") end)
+ callback.register('find_format_file' , function(name) return resolvers.findbinfile(name,"fmt") end)
+ callback.register('find_image_file' , function(name) return resolvers.findbinfile(name,"tex") end)
+ callback.register('find_map_file' , function(name) return resolvers.findbinfile(name,"map") end)
+ callback.register('find_ocp_file' , function(name) return resolvers.findbinfile(name,"ocp") end)
+ callback.register('find_opentype_file' , function(name) return resolvers.findbinfile(name,"otf") end)
+ callback.register('find_output_file' , function(name) return name end)
+ callback.register('find_pk_file' , function(name) return resolvers.findbinfile(name,"pk") end)
+ callback.register('find_sfd_file' , function(name) return resolvers.findbinfile(name,"sfd") end)
+ callback.register('find_truetype_file' , function(name) return resolvers.findbinfile(name,"ttf") end)
+ callback.register('find_type1_file' , function(name) return resolvers.findbinfile(name,"pfb") end)
+ callback.register('find_vf_file' , function(name) return resolvers.findbinfile(name,"vf") end)
+
+ callback.register('read_data_file' , function(file) return resolvers.loadbinfile(file,"tex") end)
+ callback.register('read_enc_file' , function(file) return resolvers.loadbinfile(file,"enc") end)
+ callback.register('read_font_file' , function(file) return resolvers.loadbinfile(file,"tfm") end)
+ -- format
+ -- image
+ callback.register('read_map_file' , function(file) return resolvers.loadbinfile(file,"map") end)
+ callback.register('read_ocp_file' , function(file) return resolvers.loadbinfile(file,"ocp") end)
+ -- callback.register('read_opentype_file' , function(file) return resolvers.loadbinfile(file,"otf") end)
+ -- output
+ callback.register('read_pk_file' , function(file) return resolvers.loadbinfile(file,"pk") end)
+ callback.register('read_sfd_file' , function(file) return resolvers.loadbinfile(file,"sfd") end)
+ -- callback.register('read_truetype_file' , function(file) return resolvers.loadbinfile(file,"ttf") end)
+ -- callback.register('read_type1_file' , function(file) return resolvers.loadbinfile(file,"pfb") end)
+ callback.register('read_vf_file' , function(file) return resolvers.loadbinfile(file,"vf" ) end)
+
+ callback.register('find_font_file' , function(name) return resolvers.findbinfile(name,"ofm") end)
+ callback.register('read_font_file' , function(file) return resolvers.loadbinfile(file,"ofm") end)
+ callback.register('find_vf_file' , function(name) return resolvers.findbinfile(name,"ovf") end)
+ callback.register('read_vf_file' , function(file) return resolvers.loadbinfile(file,"ovf") end)
+
+ callback.register('find_write_file' , function(id,name) return name end)
+ callback.register('find_format_file' , function(name) return name end)
+
+ end
+
+end
+
+statistics.register("input load time", function()
+ return format("%s seconds", statistics.elapsedtime(resolvers.instance))
+end)
diff --git a/tex/context/base/luat-ini.lua b/tex/context/base/luat-ini.lua
index 092593541..d9f39e61b 100644
--- a/tex/context/base/luat-ini.lua
+++ b/tex/context/base/luat-ini.lua
@@ -6,15 +6,25 @@ if not modules then modules = { } end modules ['luat-ini'] = {
license = "see context related readme files"
}
+--~ local ctxcatcodes = tex.ctxcatcodes
+
--[[ldx--
We cannot load anything yet. However what we will do us reserve a fewtables.
These can be used for runtime user data or third party modules and will not be
cluttered by macro package code.
--ldx]]--
-userdata = userdata or { }
-thirddata = thirddata or { }
-document = document or { }
+userdata = userdata or { } -- might be used
+thirddata = thirddata or { } -- might be used
+moduledata = moduledata or { } -- might be used
+document = document or { }
+
+--[[ldx--
+
These can be used/set by the caller program; mtx-context.lua does it.
+--ldx]]--
+
+document.arguments = document.arguments or { }
+document.files = document.files or { }
--[[ldx--
Please create a namespace within these tables before using them!
We could cook up a readonly model for global tables but it
+makes more sense to invite users to use one of the predefined
+namespaces. One can redefine the protector. After all, it's
+just a lightweight suggestive system, not a watertight
+one.
+--ldx]]--
+
+local string, table, lpeg, math, io, system = string, table, lpeg, math, io, system
+local next, setfenv = next, setfenv
+local format = string.format
+
+local global = _G
+
+global.global = global
+
+local dummy = function() end
+
+local protected = {
+ -- global table
+ global = global,
+ -- user tables
+ userdata = userdata,
+ moduledata = moduledata,
+ thirddata = thirddata,
+ document = document,
+ -- reserved
+ protect = dummy,
+ unprotect = dummy,
+ -- luatex
+ tex = tex,
+ -- lua
+ string = string,
+ table = table,
+ lpeg = lpeg,
+ math = math,
+ io = io,
+ system = system,
+}
+
+userdata, thirddata, moduledata = nil, nil, nil
+
+function protect(name)
+ if name == "isolateddata" then
+ local t = { }
+ for k, v in next, protected do
+ t[k] = v
+ end
+ setfenv(2,t)
+ else
+ if not name then
+ name = "shareddata"
+ end
+ local t = global[name]
+ if not t then
+ t = { }
+ for k, v in next, protected do
+ t[k] = v
+ end
+ global[name] = t
+ end
+ setfenv(2,t)
+ end
+end
+
+lua.numbers = { }
+lua.messages = { }
+
+function lua.registername(name,message)
+ local lnn = lua.numbers[name]
+ if not lnn then
+ lnn = #lua.messages + 1
+ lua.messages[lnn] = message
+ lua.numbers[name] = lnn
+ end
+ lua.name[lnn] = message
+ tex.write(lnn)
+end
+
+--~ function lua.checknames()
+--~ lua.name[0] = "ctx"
+--~ for k, v in next, lua.messages do
+--~ lua.name[k] = v
+--~ end
+--~ end
+
+storage.register("lua/numbers", lua.numbers, "lua.numbers")
+storage.register("lua/messages", lua.messages, "lua.messages")
+
+function document.setargument(key,value)
+ document.arguments[key] = value
+end
+
+function document.setdefaultargument(key,default)
+ local v = document.arguments[key]
+ if v == nil or v == "" then
+ document.arguments[key] = default
+ end
+end
+
+function document.getargument(key,default)
+ local v = document.arguments[key]
+ if type(v) == "boolean" then
+ v = (v and "yes") or "no"
+ document.arguments[key] = v
+ end
+ tex.sprint(tex.ctxcatcodes,v or default or "")
+end
+
+function document.getfilename(i)
+ tex.sprint(tex.ctxcatcodes,document.files[i] or "")
+end
diff --git a/tex/context/base/luat-ini.tex b/tex/context/base/luat-ini.tex
index 1e1e20ebe..265f1b643 100644
--- a/tex/context/base/luat-ini.tex
+++ b/tex/context/base/luat-ini.tex
@@ -11,15 +11,10 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Lua Support Macros (initialization)}
+\writestatus{loading}{ConTeXt Lua Macros / Initialization}
\unprotect
-%D We have to load this module in a very early stage. Therefore we
-%D cannot rely on support macros being available.
-
-% \long\def\rescan#1{\expanded{\scantextokens{#1}}}
-
%D Loading lua code can be done using \type {startup.lua}. The following
%D method uses the \TEX\ input file locator of kpse. At least we need to
%D use that way of loading when we haven't yet define our own code, which
@@ -30,36 +25,27 @@
\ifx\obeylualines \undefined \let\obeylualines \relax \fi
\ifx\obeyluatokens \undefined \let\obeyluatokens \relax \fi
-% \def\loadluacode#1#2% instance filename
-% {\bgroup
-% \everyeof{\noexpand}% hack to make \input nicely expandable
-% \setnaturalcatcodes
-% \obeylualines
-% %message{[Lua Load: #2]}%
-% \directlua#1\expandafter{\normalinput#2\space}\relax
-% \egroup}
-
%D A few more goodies:
-\long\def\dostartlua#1%
+\long\def\dostartlua
{\begingroup
\obeylualines
- \dodostartlua{#1}}
+ \dodostartlua}
-\long\def\dodostartlua#1#2\stoplua
- {\expanded{\endgroup\noexpand\directlua#1{#2}}}
+\long\def\dodostartlua#1\stoplua
+ {\normalexpanded{\endgroup\noexpand\directlua\zerocount{#1}}}
-\long\def\dostartluacode#1%
+\long\def\dostartluacode
{\begingroup
\obeylualines
\obeyluatokens
- \dodostartluacode{#1}}
+ \dodostartluacode}
-\long\def\dodostartluacode#1#2\stopluacode
- {\expanded{\endgroup\noexpand\directlua#1{#2}}}
+\long\def\dodostartluacode#1\stopluacode
+ {\normalexpanded{\endgroup\noexpand\directlua\zerocount{#1}}}
-\def\startlua {\dostartlua \zerocount}
-\def\startluacode{\dostartluacode\zerocount}
+\def\startlua {\dostartlua } % tex catcodes
+\def\startluacode{\dostartluacode} % lua catcodes
%D Some delayed definitions:
@@ -69,40 +55,164 @@
\ifx\obeyedspace \undefined \let\obeyedspace \relax \fi
\ifx\outputnewlinechar\undefined \let\outputnewlinechar\relax \fi
-\def\obeylualines
- {\obeylines \let\obeyedline \outputnewlinechar
- \obeyspaces \let\obeyedspace\space}
-
-\def\obeyluatokens % todo: make this a proper catcode table, use let's
- {\catcode`\%=12 \catcode`\#=12
- \catcode`\_=12 \catcode`\^=12
- \catcode`\&=12 \catcode`\|=12
- \catcode`\{=12 \catcode`\}=12
- \catcode`\~=12 \catcode`\$=12
- \def\\{\string\\}\def\|{\string\|}\def\-{\string\-}%
- \def\({\string\(}\def\){\string\)}\def\{{\string\{}\def\}{\string\}}%
- \def\'{\string\'}\def\"{\string\"}%
- \def\n{\string\n}\def\r{\string\r}\def\f{\string\f}\def\t{\string\t}%
- \def\a{\string\a}\def\b{\string\b}\def\v{\string\v}\def\s{\string\s}%
- \def\1{\string1}\def\2{\string2}\def\3{\string3}\def\4{\string\4}\def\5{\string\5}%
- \def\6{\string6}\def\7{\string7}\def\8{\string8}\def\9{\string\9}\def\0{\string\0}}
-
+%D A previous version used a bit less code and no catcode table,
+%D simply becaus ethey were not around at the time of writing.
+%
+% we keep it around for archival purposes
+%
+% \def\obeylualines
+% {\obeylines \let\obeyedline \outputnewlinechar
+% \obeyspaces \let\obeyedspace\space}
+%
+% \def\obeyluatokens % todo: make this a proper catcode table, use let's
+% {\catcode`\%=12 \catcode`\#=12
+% \catcode`\_=12 \catcode`\^=12
+% \catcode`\&=12 \catcode`\|=12
+% \catcode`\{=12 \catcode`\}=12
+% \catcode`\~=12 \catcode`\$=12
+% \def\\{\string\\}\def\|{\string\|}\def\-{\string\-}%
+% \def\({\string\(}\def\){\string\)}\def\{{\string\{}\def\}{\string\}}%
+% \def\'{\string\'}\def\"{\string\"}%
+% \def\n{\string\n}\def\r{\string\r}\def\f{\string\f}\def\t{\string\t}%
+% \def\a{\string\a}\def\b{\string\b}\def\v{\string\v}\def\s{\string\s}%
+% \def\1{\string\1}\def\2{\string\2}\def\3{\string\3}\def\4{\string\4}\def\5{\string\5}%
+% \def\6{\string\6}\def\7{\string\7}\def\8{\string\8}\def\9{\string\9}\def\0{\string\0}}
+
+\let\obeylualines\relax
+
+\newtoks\everyluacode
+
+\edef\lualetterbackslash{\string\\}
+\edef\lualetterbar {\string\|} \edef\lualetterdash {\string\-}
+\edef\lualetterlparent {\string\(} \edef\lualetterrparent {\string\)}
+\edef\lualetterlbrace {\string\{} \edef\lualetterrbrace {\string\}}
+\edef\lualettersquote {\string\'} \edef\lualetterdquote {\string\"}
+\edef\lualettern {\string\n} \edef\lualetterr {\string\r}
+\edef\lualetterf {\string\f} \edef\lualettert {\string\t}
+\edef\lualettera {\string\a} \edef\lualetterb {\string\b}
+\edef\lualetterv {\string\v} \edef\lualetters {\string\s}
+\edef\lualetterone {\string\1} \edef\lualettertwo {\string\2}
+\edef\lualetterthree {\string\3} \edef\lualetterfour {\string\4}
+\edef\lualetterfive {\string\5} \edef\lualettersix {\string\6}
+\edef\lualetterseven {\string\7} \edef\lualettereight {\string\8}
+\edef\lualetternine {\string\9} \edef\lualetterzero {\string\0}
+
+\appendtoks
+ \let\\\lualetterbackslash
+ \let\|\lualetterbar \let\-\lualetterdash
+ \let\(\lualetterlparent \let\)\lualetterrparent
+ \let\{\lualetterlbrace \let\}\lualetterrbrace
+ \let\'\lualettersquote \let\"\lualetterdquote
+ \let\n\lualettern \let\r\lualetterr
+ \let\f\lualetterf \let\t\lualettert
+ \let\a\lualettera \let\b\lualetterb
+ \let\v\lualetterv \let\s\lualetters
+ \let\1\lualetterone \let\2\lualettertwo
+ \let\3\lualetterthree \let\4\lualetterfour
+ \let\5\lualetterfive \let\6\lualettersix
+ \let\7\lualetterseven \let\8\lualettereight
+ \let\9\lualetternine \let\0\lualetterzero
+\to \everyluacode
+
+\def\obeyluatokens
+ {\setcatcodetable \luacatcodes
+ \the\everyluacode}
+
+%D \macros
+%D {definenamedlua}
+%D
%D We provide an interface for defining instances:
-\def\s!lua{lua} \def\v!code{code} \let\@EA\expandafter
+\def\s!lua{lua} \def\v!code{code} \def\!!name{name} \def\s!data{data}
-\def\setluainstancename#1#2%
- {\ifproductionrun\else\appendtoks\setluainstancename{#1}{#2}\to\everyjob\fi
- \directlua0{if lua.instancename then lua.instancename[\number#1]="#2" end}}
+%D Beware: because \type {\expanded} is een convert command, the error
+%D message will show \type{} as part of the message.
-\def\definelua[#1]% no ptional arg handling here yet
- {\ifcsname#1\s!lua\endcsname\else\expandafter\newlua\csname#1\s!lua\endcsname\fi
- \setluainstancename{\csname#1\s!lua\endcsname}{#1}%
- \setevalue{\e!start#1\s!lua }{\noexpand\dostartlua \csname#1\s!lua\endcsname}%
- \setevalue{\e!start#1\s!lua\v!code}{\noexpand\dostartluacode\csname#1\s!lua\endcsname}%
- \setvalue {\e!stop #1\s!lua }{\dostoplua }%
- \setvalue {\e!stop #1\s!lua\v!code}{\dostopluacode}}
-
-\definelua[CTX] \setluainstancename\CTXlua{main ctx instance}
+\long\def\dostartnamedluacode#1%
+ {\begingroup
+ \obeylualines
+ \obeyluatokens
+ \csname dodostartnamed#1\v!code\endcsname}
+
+\ifdefined\closelua
+
+ \def\definenamedlua[#1]#2[#3]% no optional arg handling here yet
+ {\expanded{\long\def\csname dodostartnamed#1\v!code\endcsname####1\csname\e!stop#1\v!code\endcsname}%
+ {\normalexpanded{\endgroup\noexpand\directlua\!!name{#3}\zerocount{protect("#1\s!data")##1}}}%
+ \long\expandafter\def\csname\e!start#1\v!code\endcsname {\dostartnamedluacode{#1}}%
+ \long\expandafter\def\csname #1\v!code\endcsname##1{\directlua\!!name{#3}\zerocount{protect("#1\s!data")##1}}}
+
+\else
+
+ \def\definenamedlua[#1]#2[#3]% no optional arg handling here yet
+ {\scratchcounter\ctxlua{lua.registername("#1","#3")}%
+ \expanded{\long\edef\csname dodostartnamed#1\v!code\endcsname####1\csname\e!stop#1\v!code\endcsname}%
+ {\endgroup\noexpand\directlua\the\scratchcounter{protect("#1\s!data")##1}}%
+ \long\expandafter\def \csname\e!start#1\v!code\endcsname {\dostartnamedluacode{#1}}%
+ \long\expandafter\edef\csname #1\v!code\endcsname##1{\noexpand\directlua\the\scratchcounter{protect("#1\s!data")##1}}}
+
+\fi
+
+%D We predefine a few.
+
+\definenamedlua[user] [private user instance]
+\definenamedlua[third] [third party module instance]
+\definenamedlua[module] [module instance]
+\definenamedlua[isolated][isolated instance]
+
+%D In practice this works out as follows:
+%D
+%D \startbuffer
+%D \startluacode
+%D tex.print("LUA")
+%D \stopluacode
+%D
+%D \startusercode
+%D global.tex.print("USER 1")
+%D tex.print("USER 2")
+%D if characters then
+%D tex.print("ACCESS")
+%D else
+%D tex.print("NO ACCESS")
+%D end
+%D \stopusercode
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D We need a way to pass strings safely to \LUA\ without the
+%D need for tricky escaping. Compare:
+%D
+%D \starttyping
+%D \ctxlua {something("anything tricky can go here")}
+%D \ctxlua {something([\luastringsep[anything tricky can go here]\luastringsep])}
+%D \stoptyping
+
+\def\luastringsep{===} % this permits \typefile{self} otherwise nested b/e sep problems
+
+\edef\!!bs{[\luastringsep[}
+\edef\!!es{]\luastringsep]}
+
+%D We have a the following available as primitive so there is no need
+%D for it:
+%D
+%D \starttyping
+%D \long\edef\luaescapestring#1{\!!bs#1\!!es}
+%D \stoptyping
+
+\def\setdocumentfilename #1#2{\ctxlua{document.setfilename(#1,"#2")}}
+\def\setdocumentargument #1#2{\ctxlua{document.setargument("#1","#2")}}
+\def\setdefaultdocumentargument#1#2{\ctxlua{document.getargument("#1","#2")}}
+\def\getdocumentfilename #1{\ctxlua{document.getfilename(#1)}}
+\def\getdocumentargument #1{\ctxlua{document.getargument(#1)}}
+\def\doifdocumentargumentelse #1{\doifsomethingelse{\getdocumentargument{#1}}}
+\def\doifdocumentargument #1{\doifsomething {\getdocumentargument{#1}}}
+\def\doifnotdocumentargument #1{\doifnothing {\getdocumentargument{#1}}}
+
+\let\doifelsedocumentargument\doifdocumentargumentelse
+
+%D A handy helper:
+
+\def\luaexpanded#1{\luaescapestring\expandafter{\normalexpanded{#1}}}
\protect \endinput
diff --git a/tex/context/base/luat-inp.lua b/tex/context/base/luat-inp.lua
deleted file mode 100644
index d71ab3b73..000000000
--- a/tex/context/base/luat-inp.lua
+++ /dev/null
@@ -1,2300 +0,0 @@
-if not modules then modules = { } end modules ['luat-inp'] = {
- version = 1.001,
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
- comment = "companion to luat-lib.tex",
-}
-
--- TODO: os.getenv -> os.env[]
--- TODO: instances.[hashes,cnffiles,configurations,522] -> ipairs (alles check, sneller)
--- TODO: check escaping in find etc, too much, too slow
-
--- This lib is multi-purpose and can be loaded again later on so that
--- additional functionality becomes available. We will split this
--- module in components once we're done with prototyping. This is the
--- first code I wrote for LuaTeX, so it needs some cleanup. Before changing
--- something in this module one can best check with Taco or Hans first; there
--- is some nasty trickery going on that relates to traditional kpse support.
-
--- To be considered: hash key lowercase, first entry in table filename
--- (any case), rest paths (so no need for optimization). Or maybe a
--- separate table that matches lowercase names to mixed case when
--- present. In that case the lower() cases can go away. I will do that
--- only when we run into problems with names ... well ... Iwona-Regular.
-
--- Beware, loading and saving is overloaded in luat-tmp!
-
-if not input then input = { } end
-if not input.suffixes then input.suffixes = { } end
-if not input.formats then input.formats = { } end
-if not input.aux then input.aux = { } end
-
-if not input.suffixmap then input.suffixmap = { } end
-
-if not input.locators then input.locators = { } end -- locate databases
-if not input.hashers then input.hashers = { } end -- load databases
-if not input.generators then input.generators = { } end -- generate databases
-if not input.filters then input.filters = { } end -- conversion filters
-
-local format, concat, sortedkeys = string.format, table.concat, table.sortedkeys
-
-input.locators.notfound = { nil }
-input.hashers.notfound = { nil }
-input.generators.notfound = { nil }
-
-input.cacheversion = '1.0.1'
-input.banner = nil
-input.verbose = false
-input.debug = false
-input.cnfname = 'texmf.cnf'
-input.luaname = 'texmfcnf.lua'
-input.lsrname = 'ls-R'
-input.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
-
---~ input.luasuffix = 'tma'
---~ input.lucsuffix = 'tmc'
-
--- for the moment we have .local but this will disappear
-input.cnfdefault = '{$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- chances are low that the cnf file is in the bin path
-input.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
-
--- we use a cleaned up list / format=any is a wildcard, as is *name
-
-input.formats['afm'] = 'AFMFONTS' input.suffixes['afm'] = { 'afm' }
-input.formats['enc'] = 'ENCFONTS' input.suffixes['enc'] = { 'enc' }
-input.formats['fmt'] = 'TEXFORMATS' input.suffixes['fmt'] = { 'fmt' }
-input.formats['map'] = 'TEXFONTMAPS' input.suffixes['map'] = { 'map' }
-input.formats['mp'] = 'MPINPUTS' input.suffixes['mp'] = { 'mp' }
-input.formats['ocp'] = 'OCPINPUTS' input.suffixes['ocp'] = { 'ocp' }
-input.formats['ofm'] = 'OFMFONTS' input.suffixes['ofm'] = { 'ofm', 'tfm' }
-input.formats['otf'] = 'OPENTYPEFONTS' input.suffixes['otf'] = { 'otf' } -- 'ttf'
-input.formats['opl'] = 'OPLFONTS' input.suffixes['opl'] = { 'opl' }
-input.formats['otp'] = 'OTPINPUTS' input.suffixes['otp'] = { 'otp' }
-input.formats['ovf'] = 'OVFFONTS' input.suffixes['ovf'] = { 'ovf', 'vf' }
-input.formats['ovp'] = 'OVPFONTS' input.suffixes['ovp'] = { 'ovp' }
-input.formats['tex'] = 'TEXINPUTS' input.suffixes['tex'] = { 'tex' }
-input.formats['tfm'] = 'TFMFONTS' input.suffixes['tfm'] = { 'tfm' }
-input.formats['ttf'] = 'TTFONTS' input.suffixes['ttf'] = { 'ttf', 'ttc' }
-input.formats['pfb'] = 'T1FONTS' input.suffixes['pfb'] = { 'pfb', 'pfa' }
-input.formats['vf'] = 'VFFONTS' input.suffixes['vf'] = { 'vf' }
-
-input.formats['fea'] = 'FONTFEATURES' input.suffixes['fea'] = { 'fea' }
-input.formats['cid'] = 'FONTCIDMAPS' input.suffixes['cid'] = { 'cid', 'cidmap' }
-
-input.formats ['texmfscripts'] = 'TEXMFSCRIPTS' -- new
-input.suffixes['texmfscripts'] = { 'rb', 'pl', 'py' } -- 'lua'
-
-input.formats ['lua'] = 'LUAINPUTS' -- new
-input.suffixes['lua'] = { 'lua', 'luc', 'tma', 'tmc' }
-
--- here we catch a few new thingies (todo: add these paths to context.tmf)
---
--- FONTFEATURES = .;$TEXMF/fonts/fea//
--- FONTCIDMAPS = .;$TEXMF/fonts/cid//
-
-function input.checkconfigdata() -- not yet ok, no time for debugging now
- local instance = input.instance
- local function fix(varname,default)
- local proname = varname .. "." .. instance.progname or "crap"
- local p = instance.environment[proname]
- local v = instance.environment[varname]
- if not ((p and p ~= "") or (v and v ~= "")) then
- instance.variables[varname] = default -- or environment?
- end
- end
- local name = os.name
- if name == "windows" then
- fix("OSFONTDIR", "c:/windows/fonts//")
- elseif name == "macosx" then
- fix("OSFONTDIR", "$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")
- else
- -- bad luck
- end
- fix("LUAINPUTS" , ".;$TEXINPUTS;$TEXMFSCRIPTS") -- no progname, hm
- fix("FONTFEATURES", ".;$TEXMF/fonts/fea//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
- fix("FONTCIDMAPS" , ".;$TEXMF/fonts/cid//;$OPENTYPEFONTS;$TTFONTS;$T1FONTS;$AFMFONTS")
-end
-
--- backward compatible ones
-
-input.alternatives = { }
-
-input.alternatives['map files'] = 'map'
-input.alternatives['enc files'] = 'enc'
-input.alternatives['cid files'] = 'cid'
-input.alternatives['fea files'] = 'fea'
-input.alternatives['opentype fonts'] = 'otf'
-input.alternatives['truetype fonts'] = 'ttf'
-input.alternatives['truetype collections'] = 'ttc'
-input.alternatives['type1 fonts'] = 'pfb'
-
--- obscure ones
-
-input.formats ['misc fonts'] = ''
-input.suffixes['misc fonts'] = { }
-
-input.formats ['sfd'] = 'SFDFONTS'
-input.suffixes ['sfd'] = { 'sfd' }
-input.alternatives['subfont definition files'] = 'sfd'
-
--- In practice we will work within one tds tree, but i want to keep
--- the option open to build tools that look at multiple trees, which is
--- why we keep the tree specific data in a table. We used to pass the
--- instance but for practical pusposes we now avoid this and use a
--- instance variable.
-
-function input.newinstance()
-
- local instance = { }
-
- instance.rootpath = ''
- instance.treepath = ''
- instance.progname = 'context'
- instance.engine = 'luatex'
- instance.format = ''
- instance.environment = { }
- instance.variables = { }
- instance.expansions = { }
- instance.files = { }
- instance.remap = { }
- instance.configuration = { }
- instance.setup = { }
- instance.order = { }
- instance.found = { }
- instance.foundintrees = { }
- instance.kpsevars = { }
- instance.hashes = { }
- instance.cnffiles = { }
- instance.luafiles = { }
- instance.lists = { }
- instance.remember = true
- instance.diskcache = true
- instance.renewcache = false
- instance.scandisk = true
- instance.cachepath = nil
- instance.loaderror = false
- instance.smallcache = false
- instance.sortdata = false
- instance.savelists = true
- instance.cleanuppaths = true
- instance.allresults = false
- instance.pattern = nil -- lists
- instance.kpseonly = false -- lists
- instance.loadtime = 0
- instance.starttime = 0
- instance.stoptime = 0
- instance.validfile = function(path,name) return true end
- instance.data = { } -- only for loading
- instance.force_suffixes = true
- instance.dummy_path_expr = "^!*unset/*$"
- instance.fakepaths = { }
- instance.lsrmode = false
-
- -- store once, freeze and faster (once reset we can best use instance.environment)
-
- for k,v in pairs(os.env) do
- instance.environment[k] = input.bare_variable(v)
- end
-
- -- cross referencing, delayed because we can add suffixes
-
- for k, v in pairs(input.suffixes) do
- for _, vv in pairs(v) do
- if vv then
- input.suffixmap[vv] = k
- end
- end
- end
-
- return instance
-
-end
-
-input.instance = input.instance or nil
-
-function input.reset()
- input.instance = input.newinstance()
- return input.instance
-end
-
-function input.reset_hashes()
- input.instance.lists = { }
- input.instance.found = { }
-end
-
-function input.bare_variable(str) -- assumes str is a string
- -- return string.gsub(string.gsub(string.gsub(str,"%s+$",""),'^"(.+)"$',"%1"),"^'(.+)'$","%1")
- return (str:gsub("\s*([\"\']?)(.+)%1\s*", "%2"))
-end
-
-function input.settrace(n)
- input.trace = tonumber(n or 0)
- if input.trace > 0 then
- input.verbose = true
- end
-end
-
-input.log = (texio and texio.write_nl) or print
-
-function input.report(...)
- if input.verbose then
- input.log("<<"..format(...)..">>")
- end
-end
-
-function input.report(...)
- if input.trace > 0 then -- extra test
- input.log("<<"..format(...)..">>")
- end
-end
-
-input.settrace(tonumber(os.getenv("MTX.INPUT.TRACE") or os.getenv("MTX_INPUT_TRACE") or input.trace or 0))
-
--- These functions can be used to test the performance, especially
--- loading the database files.
-
-do
- local clock = os.gettimeofday or os.clock
-
- function input.hastimer(instance)
- return instance and instance.starttime
- end
-
- function input.starttiming(instance)
- if instance then
- local it = instance.timing
- if not it then
- it = 0
- end
- if it == 0 then
- instance.starttime = clock()
- if not instance.loadtime then
- instance.loadtime = 0
- end
- end
- instance.timing = it + 1
- end
- end
-
- function input.stoptiming(instance, report)
- if instance then
- local it = instance.timing
- if it > 1 then
- instance.timing = it - 1
- else
- local starttime = instance.starttime
- if starttime then
- local stoptime = clock()
- local loadtime = stoptime - starttime
- instance.stoptime = stoptime
- instance.loadtime = instance.loadtime + loadtime
- if report then
- input.report("load time %0.3f",loadtime)
- end
- instance.timing = 0
- return loadtime
- end
- end
- end
- return 0
- end
-
-end
-
-function input.elapsedtime(instance)
- return format("%0.3f",(instance and instance.loadtime) or 0)
-end
-
-function input.report_loadtime(instance)
- if instance then
- input.report('total load time %s', input.elapsedtime(instance))
- end
-end
-
-input.loadtime = input.elapsedtime
-
-function input.env(key)
- return input.instance.environment[key] or input.osenv(key)
-end
-
-function input.osenv(key)
- local ie = input.instance.environment
- local value = ie[key]
- if value == nil then
- -- local e = os.getenv(key)
- local e = os.env[key]
- if e == nil then
- -- value = "" -- false
- else
- value = input.bare_variable(e)
- end
- ie[key] = value
- end
- return value or ""
-end
-
--- we follow a rather traditional approach:
---
--- (1) texmf.cnf given in TEXMFCNF
--- (2) texmf.cnf searched in default variable
---
--- also we now follow the stupid route: if not set then just assume *one*
--- cnf file under texmf (i.e. distribution)
-
-input.ownpath = input.ownpath or nil
-input.ownbin = input.ownbin or arg[-2] or arg[-1] or arg[0] or "luatex"
-input.autoselfdir = true -- false may be handy for debugging
-
-function input.getownpath()
- if not input.ownpath then
- if input.autoselfdir and os.selfdir then
- input.ownpath = os.selfdir
- else
- local binary = input.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
- end
- for p in string.gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
- local b = file.join(p,binary)
- if lfs.isfile(b) then
- -- we assume that after changing to the path the currentdir function
- -- resolves to the real location and use this side effect here; this
- -- trick is needed because on the mac installations use symlinks in the
- -- path instead of real locations
- local olddir = lfs.currentdir()
- if lfs.chdir(p) then
- local pp = lfs.currentdir()
- if input.verbose and p ~= pp then
- input.report("following symlink %s to %s",p,pp)
- end
- input.ownpath = pp
- lfs.chdir(olddir)
- else
- if input.verbose then
- input.report("unable to check path %s",p)
- end
- input.ownpath = p
- end
- break
- end
- end
- end
- if not input.ownpath then input.ownpath = '.' end
- end
- return input.ownpath
-end
-
-function input.identify_own()
- local instance = input.instance
- local ownpath = input.getownpath() or lfs.currentdir()
- local ie = instance.environment
- if ownpath then
- if input.env('SELFAUTOLOC') == "" then os.env['SELFAUTOLOC'] = file.collapse_path(ownpath) end
- if input.env('SELFAUTODIR') == "" then os.env['SELFAUTODIR'] = file.collapse_path(ownpath .. "/..") end
- if input.env('SELFAUTOPARENT') == "" then os.env['SELFAUTOPARENT'] = file.collapse_path(ownpath .. "/../..") end
- else
- input.verbose = true
- input.report("error: unable to locate ownpath")
- os.exit()
- end
- if input.env('TEXMFCNF') == "" then os.env['TEXMFCNF'] = input.cnfdefault end
- if input.env('TEXOS') == "" then os.env['TEXOS'] = input.env('SELFAUTODIR') end
- if input.env('TEXROOT') == "" then os.env['TEXROOT'] = input.env('SELFAUTOPARENT') end
- if input.verbose then
- for _,v in ipairs({"SELFAUTOLOC","SELFAUTODIR","SELFAUTOPARENT","TEXMFCNF"}) do
- input.report("variable %s set to %s",v,input.env(v) or "unknown")
- end
- end
- function input.identify_own() end
-end
-
-function input.identify_cnf()
- local instance = input.instance
- if #instance.cnffiles == 0 then
- -- fallback
- input.identify_own()
- -- the real search
- input.expand_variables()
- local t = input.split_path(input.env('TEXMFCNF'))
- t = input.aux.expanded_path(t)
- input.aux.expand_vars(t) -- redundant
- local function locate(filename,list)
- for _,v in ipairs(t) do
- local texmfcnf = input.normalize_name(file.join(v,filename))
- if lfs.isfile(texmfcnf) then
- table.insert(list,texmfcnf)
- end
- end
- end
- locate(input.luaname,instance.luafiles)
- locate(input.cnfname,instance.cnffiles)
- end
-end
-
-function input.load_cnf()
- local instance = input.instance
- local function loadoldconfigdata()
- for _, fname in ipairs(instance.cnffiles) do
- input.aux.load_cnf(fname)
- end
- end
- -- instance.cnffiles contain complete names now !
- if #instance.cnffiles == 0 then
- input.report("no cnf files found (TEXMFCNF may not be set/known)")
- else
- instance.rootpath = instance.cnffiles[1]
- for k,fname in ipairs(instance.cnffiles) do
- instance.cnffiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- if instance.lsrmode then
- loadoldconfigdata()
- elseif instance.diskcache and not instance.renewcache then
- input.loadoldconfig(instance.cnffiles)
- if instance.loaderror then
- loadoldconfigdata()
- input.saveoldconfig()
- end
- else
- loadoldconfigdata()
- if instance.renewcache then
- input.saveoldconfig()
- end
- end
- input.aux.collapse_cnf_data()
- end
- input.checkconfigdata()
-end
-
-function input.load_lua()
- local instance = input.instance
- if #instance.luafiles == 0 then
- -- yet harmless
- else
- instance.rootpath = instance.luafiles[1]
- for k,fname in ipairs(instance.luafiles) do
- instance.luafiles[k] = input.normalize_name(fname:gsub("\\",'/'))
- end
- for i=1,3 do
- instance.rootpath = file.dirname(instance.rootpath)
- end
- instance.rootpath = input.normalize_name(instance.rootpath)
- input.loadnewconfig()
- input.aux.collapse_cnf_data()
- end
- input.checkconfigdata()
-end
-
-function input.aux.collapse_cnf_data() -- potential optimization: pass start index (setup and configuration are shared)
- local instance = input.instance
- for _,c in ipairs(instance.order) do
- for k,v in pairs(c) do
- if not instance.variables[k] then
- if instance.environment[k] then
- instance.variables[k] = instance.environment[k]
- else
- instance.kpsevars[k] = true
- instance.variables[k] = input.bare_variable(v)
- end
- end
- end
- end
-end
-
-function input.aux.load_cnf(fname)
- local instance = input.instance
- fname = input.clean_path(fname)
- local lname = file.replacesuffix(fname,'lua')
- local f = io.open(lname)
- if f then -- this will go
- f:close()
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- input.aux.load_configuration(dname,lname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
- else
- f = io.open(fname)
- if f then
- input.report("loading %s", fname)
- local line, data, n, k, v
- local dname = file.dirname(fname)
- if not instance.configuration[dname] then
- instance.configuration[dname] = { }
- instance.order[#instance.order+1] = instance.configuration[dname]
- end
- local data = instance.configuration[dname]
- while true do
- local line, n = f:read(), 0
- if line then
- while true do -- join lines
- line, n = line:gsub("\\%s*$", "")
- if n > 0 then
- line = line .. f:read()
- else
- break
- end
- end
- if not line:find("^[%%#]") then
- local k, v = (line:gsub("%s*%%.*$","")):match("%s*(.-)%s*=%s*(.-)%s*$")
- if k and v and not data[k] then
- data[k] = (v:gsub("[%%#].*",'')):gsub("~", "$HOME")
- instance.kpsevars[k] = true
- end
- end
- else
- break
- end
- end
- f:close()
- else
- input.report("skipping %s", fname)
- end
- end
-end
-
--- database loading
-
-function input.load_hash()
- local instance = input.instance
- input.locatelists()
- if instance.lsrmode then
- input.loadlists()
- elseif instance.diskcache and not instance.renewcache then
- input.loadfiles()
- if instance.loaderror then
- input.loadlists()
- input.savefiles()
- end
- else
- input.loadlists()
- if instance.renewcache then
- input.savefiles()
- end
- end
-end
-
-function input.aux.append_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash append: %s",tag)
- end
- table.insert(input.instance.hashes, { ['type']=type, ['tag']=tag, ['name']=name } )
-end
-
-function input.aux.prepend_hash(type,tag,name)
- if input.trace > 0 then
- input.logger("= hash prepend: %s",tag)
- end
- table.insert(input.instance.hashes, 1, { ['type']=type, ['tag']=tag, ['name']=name } )
-end
-
-function input.aux.extend_texmf_var(specification) -- crap, we could better prepend the hash
- local instance = input.instance
--- local t = input.expanded_path_list('TEXMF') -- full expansion
- local t = input.split_path(input.env('TEXMF'))
- table.insert(t,1,specification)
- local newspec = table.join(t,";")
- if instance.environment["TEXMF"] then
- instance.environment["TEXMF"] = newspec
- elseif instance.variables["TEXMF"] then
- instance.variables["TEXMF"] = newspec
- else
- -- weird
- end
- input.expand_variables()
- input.reset_hashes()
-end
-
--- locators
-
-function input.locatelists()
- local instance = input.instance
- for _, path in pairs(input.clean_path_list('TEXMF')) do
- input.report("locating list of %s",path)
- input.locatedatabase(input.normalize_name(path))
- end
-end
-
-function input.locatedatabase(specification)
- return input.methodhandler('locators', specification)
-end
-
-function input.locators.tex(specification)
- if specification and specification ~= '' and lfs.isdir(specification) then
- if input.trace > 0 then
- input.logger('! tex locator found: %s',specification)
- end
- input.aux.append_hash('file',specification,filename)
- elseif input.trace > 0 then
- input.logger('? tex locator not found: %s',specification)
- end
-end
-
--- hashers
-
-function input.hashdatabase(tag,name)
- return input.methodhandler('hashers',tag,name)
-end
-
-function input.loadfiles()
- local instance = input.instance
- instance.loaderror = false
- instance.files = { }
- if not instance.renewcache then
- for _, hash in ipairs(instance.hashes) do
- input.hashdatabase(hash.tag,hash.name)
- if instance.loaderror then break end
- end
- end
-end
-
-function input.hashers.tex(tag,name)
- input.aux.load_files(tag)
-end
-
--- generators:
-
-function input.loadlists()
- for _, hash in ipairs(input.instance.hashes) do
- input.generatedatabase(hash.tag)
- end
-end
-
-function input.generatedatabase(specification)
- return input.methodhandler('generators', specification)
-end
-
-local weird = lpeg.anywhere(lpeg.S("~`!#$%^&*()={}[]:;\"\'||<>,?\n\r\t"))
-
-function input.generators.tex(specification)
- local instance = input.instance
- local tag = specification
- if not instance.lsrmode and lfs.dir then
- input.report("scanning path %s",specification)
- instance.files[tag] = { }
- local files = instance.files[tag]
- local n, m, r = 0, 0, 0
- local spec = specification .. '/'
- local attributes = lfs.attributes
- local directory = lfs.dir
- local small = instance.smallcache
- local function action(path)
- local mode, full
- if path then
- full = spec .. path .. '/'
- else
- full = spec
- end
- for name in directory(full) do
- if name:find("^%.") then
- -- skip
- -- elseif name:find("[%~%`%!%#%$%%%^%&%*%(%)%=%{%}%[%]%:%;\"\'%|%<%>%,%?\n\r\t]") then -- too much escaped
- elseif weird:match(name) then
- -- texio.write_nl("skipping " .. name)
- -- skip
- else
- mode = attributes(full..name,'mode')
- if mode == 'directory' then
- m = m + 1
- if path then
- action(path..'/'..name)
- else
- action(name)
- end
- elseif path and mode == 'file' then
- n = n + 1
- local f = files[name]
- if f then
- if not small then
- if type(f) == 'string' then
- files[name] = { f, path }
- else
- f[#f+1] = path
- end
- end
- else
- files[name] = path
- local lower = name:lower()
- if name ~= lower then
- files["remap:"..lower] = name
- r = r + 1
- end
- end
- end
- end
- end
- end
- action()
- input.report("%s files found on %s directories with %s uppercase remappings",n,m,r)
- else
- local fullname = file.join(specification,input.lsrname)
- local path = '.'
- local f = io.open(fullname)
- if f then
- instance.files[tag] = { }
- local files = instance.files[tag]
- local small = instance.smallcache
- input.report("loading lsr file %s",fullname)
- -- for line in f:lines() do -- much slower then the next one
- for line in (f:read("*a")):gmatch("(.-)\n") do
- if line:find("^[%a%d]") then
- local fl = files[line]
- if fl then
- if not small then
- if type(fl) == 'string' then
- files[line] = { fl, path } -- table
- else
- fl[#fl+1] = path
- end
- end
- else
- files[line] = path -- string
- local lower = line:lower()
- if line ~= lower then
- files["remap:"..lower] = line
- end
- end
- else
- path = line:match("%.%/(.-)%:$") or path -- match could be nil due to empty line
- end
- end
- f:close()
- end
- end
-end
-
--- savers, todo
-
-function input.savefiles()
- input.aux.save_data('files', function(k,v)
- return input.instance.validfile(k,v) -- path, name
- end)
-end
-
--- A config (optionally) has the paths split in tables. Internally
--- we join them and split them after the expansion has taken place. This
--- is more convenient.
-
-function input.splitconfig()
- for i,c in ipairs(input.instance) do
- for k,v in pairs(c) do
- if type(v) == 'string' then
- local t = file.split_path(v)
- if #t > 1 then
- c[k] = t
- end
- end
- end
- end
-end
-
-function input.joinconfig()
- for i,c in ipairs(input.instance.order) do
- for k,v in pairs(c) do
- if type(v) == 'table' then
- c[k] = file.join_path(v)
- end
- end
- end
-end
-function input.split_path(str)
- if type(str) == 'table' then
- return str
- else
- return file.split_path(str)
- end
-end
-function input.join_path(str)
- if type(str) == 'table' then
- return file.join_path(str)
- else
- return str
- end
-end
-
-function input.splitexpansions()
- local ie = input.instance.expansions
- for k,v in pairs(ie) do
- local t, h = { }, { }
- for _,vv in pairs(file.split_path(v)) do
- if vv ~= "" and not h[vv] then
- t[#t+1] = vv
- h[vv] = true
- end
- end
- if #t > 1 then
- ie[k] = t
- else
- ie[k] = t[1]
- end
- end
-end
-
--- end of split/join code
-
-function input.saveoldconfig()
- input.splitconfig()
- input.aux.save_data('configuration', nil)
- input.joinconfig()
-end
-
-input.configbanner = [[
--- This is a Luatex configuration file created by 'luatools.lua' or
--- 'luatex.exe' directly. For comment, suggestions and questions you can
--- contact the ConTeXt Development Team. This configuration file is
--- not copyrighted. [HH & TH]
-]]
-
-function input.serialize(files)
- -- This version is somewhat optimized for the kind of
- -- tables that we deal with, so it's much faster than
- -- the generic serializer. This makes sense because
- -- luatools and mtxtools are called frequently. Okay,
- -- we pay a small price for properly tabbed tables.
- local t = { }
- local function dump(k,v,m)
- if type(v) == 'string' then
- return m .. "['" .. k .. "']='" .. v .. "',"
- elseif #v == 1 then
- return m .. "['" .. k .. "']='" .. v[1] .. "',"
- else
- return m .. "['" .. k .. "']={'" .. concat(v,"','").. "'},"
- end
- end
- t[#t+1] = "return {"
- if input.instance.sortdata then
- for _, k in pairs(sortedkeys(files)) do
- local fk = files[k]
- if type(fk) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for _, kk in pairs(sortedkeys(fk)) do
- t[#t+1] = dump(kk,fk[kk],"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,fk,"\t")
- end
- end
- else
- for k, v in pairs(files) do
- if type(v) == 'table' then
- t[#t+1] = "\t['" .. k .. "']={"
- for kk,vv in pairs(v) do
- t[#t+1] = dump(kk,vv,"\t\t")
- end
- t[#t+1] = "\t},"
- else
- t[#t+1] = dump(k,v,"\t")
- end
- end
- end
- t[#t+1] = "}"
- return concat(t,"\n")
-end
-
-if not texmf then texmf = {} end -- no longer needed, at least not here
-
-function input.aux.save_data(dataname, check, makename) -- untested without cache overload
- for cachename, files in pairs(input.instance[dataname]) do
- local name = (makename or file.join)(cachename,dataname)
- local luaname, lucname = name .. ".lua", name .. ".luc"
- input.report("preparing %s for %s",dataname,cachename)
- for k, v in pairs(files) do
- if not check or check(v,k) then -- path, name
- if type(v) == "table" and #v == 1 then
- files[k] = v[1]
- end
- else
- files[k] = nil -- false
- end
- end
- local data = {
- type = dataname,
- root = cachename,
- version = input.cacheversion,
- date = os.date("%Y-%m-%d"),
- time = os.date("%H:%M:%S"),
- content = files,
- }
- local ok = io.savedata(luaname,input.serialize(data))
- if ok then
- input.report("%s saved in %s",dataname,luaname)
- if utils.lua.compile(luaname,lucname,false,true) then -- no cleanup but strip
- input.report("%s compiled to %s",dataname,lucname)
- else
- input.report("compiling failed for %s, deleting file %s",dataname,lucname)
- os.remove(lucname)
- end
- else
- input.report("unable to save %s in %s (access error)",dataname,luaname)
- end
- end
-end
-
-function input.aux.load_data(pathname,dataname,filename,makename) -- untested without cache overload
- local instance = input.instance
- filename = ((not filename or (filename == "")) and dataname) or filename
- filename = (makename and makename(dataname,filename)) or file.join(pathname,filename)
- local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
- if blob then
- local data = blob()
- if data and data.content and data.type == dataname and data.version == input.cacheversion then
- input.report("loading %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = data.content
- else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
- end
- else
- input.report("skipping %s for %s from %s",dataname,pathname,filename)
- end
-end
-
--- some day i'll use the nested approach, but not yet (actually we even drop
--- engine/progname support since we have only luatex now)
---
--- first texmfcnf.lua files are located, next the cached texmf.cnf files
---
--- return {
--- TEXMFBOGUS = 'effe checken of dit werkt',
--- }
-
-function input.aux.load_texmfcnf(dataname,pathname)
- local instance = input.instance
- local filename = file.join(pathname,input.luaname)
- local blob = loadfile(filename)
- if blob then
- local data = blob()
- if data then
- input.report("loading configuration file %s",filename)
- if true then
- -- flatten to variable.progname
- local t = { }
- for k, v in pairs(data) do -- v = progname
- if type(v) == "string" then
- t[k] = v
- else
- for kk, vv in pairs(v) do -- vv = variable
- if type(vv) == "string" then
- t[vv.."."..v] = kk
- end
- end
- end
- end
- instance[dataname][pathname] = t
- else
- instance[dataname][pathname] = data
- end
- else
- input.report("skipping configuration file %s",filename)
- instance[dataname][pathname] = { }
- instance.loaderror = true
- end
- else
- input.report("skipping configuration file %s",filename)
- end
-end
-
-function input.aux.load_configuration(dname,lname)
- input.aux.load_data(dname,'configuration',lname and file.basename(lname))
-end
-function input.aux.load_files(tag)
- input.aux.load_data(tag,'files')
-end
-
-function input.resetconfig()
- input.identify_own()
- local instance = input.instance
- instance.configuration, instance.setup, instance.order, instance.loaderror = { }, { }, { }, false
-end
-
-function input.loadnewconfig()
- local instance = input.instance
- for _, cnf in ipairs(instance.luafiles) do
- local dname = file.dirname(cnf)
- input.aux.load_texmfcnf('setup',dname)
- instance.order[#instance.order+1] = instance.setup[dname]
- if instance.loaderror then break end
- end
-end
-
-function input.loadoldconfig()
- local instance = input.instance
- if not instance.renewcache then
- for _, cnf in ipairs(instance.cnffiles) do
- local dname = file.dirname(cnf)
- input.aux.load_configuration(dname)
- instance.order[#instance.order+1] = instance.configuration[dname]
- if instance.loaderror then break end
- end
- end
- input.joinconfig()
-end
-
-function input.expand_variables()
- local instance = input.instance
- local expansions, environment, variables = { }, instance.environment, instance.variables
- local env = input.env
- instance.expansions = expansions
- if instance.engine ~= "" then environment['engine'] = instance.engine end
- if instance.progname ~= "" then environment['progname'] = instance.progname end
- for k,v in pairs(environment) do
- local a, b = k:match("^(%a+)%_(.*)%s*$")
- if a and b then
- expansions[a..'.'..b] = v
- else
- expansions[k] = v
- end
- end
- for k,v in pairs(environment) do -- move environment to expansions
- if not expansions[k] then expansions[k] = v end
- end
- for k,v in pairs(variables) do -- move variables to expansions
- if not expansions[k] then expansions[k] = v end
- end
- while true do
- local busy = false
- for k,v in pairs(expansions) do
- local s, n = v:gsub("%$([%a%d%_%-]+)", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- local s, m = s:gsub("%$%{([%a%d%_%-]+)%}", function(a)
- busy = true
- return expansions[a] or env(a)
- end)
- if n > 0 or m > 0 then
- expansions[k]= s
- end
- end
- if not busy then break end
- end
- for k,v in pairs(expansions) do
- expansions[k] = v:gsub("\\", '/')
- end
-end
-
-function input.aux.expand_vars(lst) -- simple vars
- local instance = input.instance
- local variables, env = instance.variables, input.env
- for k,v in pairs(lst) do
- lst[k] = v:gsub("%$([%a%d%_%-]+)", function(a)
- return variables[a] or env(a)
- end)
- end
-end
-
-function input.aux.expanded_var(var) -- simple vars
- local instance = input.instance
- return var:gsub("%$([%a%d%_%-]+)", function(a)
- return instance.variables[a] or input.env(a)
- end)
-end
-
-function input.aux.entry(entries,name)
- if name and (name ~= "") then
- local instance = input.instance
- name = name:gsub('%$','')
- local result = entries[name..'.'..instance.progname] or entries[name]
- if result then
- return result
- else
- result = input.env(name)
- if result then
- instance.variables[name] = result
- input.expand_variables()
- return instance.expansions[name] or ""
- end
- end
- end
- return ""
-end
-function input.variable(name)
- return input.aux.entry(input.instance.variables,name)
-end
-function input.expansion(name)
- return input.aux.entry(input.instance.expansions,name)
-end
-
-function input.aux.is_entry(entries,name)
- if name and name ~= "" then
- name = name:gsub('%$','')
- return (entries[name..'.'..input.instance.progname] or entries[name]) ~= nil
- else
- return false
- end
-end
-
-function input.is_variable(name)
- return input.aux.is_entry(input.instance.variables,name)
-end
-
-function input.is_expansion(name)
- return input.aux.is_entry(input.instance.expansions,name)
-end
-
-function input.unexpanded_path_list(str)
- local pth = input.variable(str)
- local lst = input.split_path(pth)
- return input.aux.expanded_path(lst)
-end
-
-function input.unexpanded_path(str)
- return file.join_path(input.unexpanded_path_list(str))
-end
-
-do
- local done = { }
-
- function input.reset_extra_path()
- local instance = input.instance
- local ep = instance.extra_paths
- if not ep then
- ep, done = { }, { }
- instance.extra_paths = ep
- elseif #ep > 0 then
- instance.lists, done = { }, { }
- end
- end
-
- function input.register_extra_path(paths,subpaths)
- local instance = input.instance
- local ep = instance.extra_paths or { }
- local n = #ep
- if paths and paths ~= "" then
- if subpaths and subpaths ~= "" then
- for p in paths:gmatch("[^,]+") do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = p .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
- else
- for p in paths:gmatch("[^,]+") do
- if not done[p] then
- ep[#ep+1] = input.clean_path(p)
- done[p] = true
- end
- end
- end
- elseif subpaths and subpaths ~= "" then
- for i=1,n do
- -- we gmatch each step again, not that fast, but used seldom
- for s in subpaths:gmatch("[^,]+") do
- local ps = ep[i] .. "/" .. s
- if not done[ps] then
- ep[#ep+1] = input.clean_path(ps)
- done[ps] = true
- end
- end
- end
- end
- if #ep > 0 then
- instance.extra_paths = ep -- register paths
- end
- if #ep > n then
- instance.lists = { } -- erase the cache
- end
- end
-
-end
-
-function input.expanded_path_list(str)
- local instance = input.instance
- local function made_list(list)
- local ep = instance.extra_paths
- if not ep or #ep == 0 then
- return list
- else
- local done, new = { }, { }
- -- honour . .. ../.. but only when at the start
- for k, v in ipairs(list) do
- if not done[v] then
- if v:find("^[%.%/]$") then
- done[v] = true
- new[#new+1] = v
- else
- break
- end
- end
- end
- -- first the extra paths
- for k, v in ipairs(ep) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- -- next the formal paths
- for k, v in ipairs(list) do
- if not done[v] then
- done[v] = true
- new[#new+1] = v
- end
- end
- return new
- end
- end
- if not str then
- return ep or { }
- elseif instance.savelists then
- -- engine+progname hash
- str = str:gsub("%$","")
- if not instance.lists[str] then -- cached
- local lst = made_list(input.split_path(input.expansion(str)))
- instance.lists[str] = input.aux.expanded_path(lst)
- end
- return instance.lists[str]
- else
- local lst = input.split_path(input.expansion(str))
- return made_list(input.aux.expanded_path(lst))
- end
-end
-
-
-function input.clean_path_list(str)
- local t = input.expanded_path_list(str)
- if t then
- for i=1,#t do
- t[i] = file.collapse_path(input.clean_path(t[i]))
- end
- end
- return t
-end
-
-function input.expand_path(str)
- return file.join_path(input.expanded_path_list(str))
-end
-
-function input.expanded_path_list_from_var(str) -- brrr
- local tmp = input.var_of_format_or_suffix(str:gsub("%$",""))
- if tmp ~= "" then
- return input.expanded_path_list(str)
- else
- return input.expanded_path_list(tmp)
- end
-end
-function input.expand_path_from_var(str)
- return file.join_path(input.expanded_path_list_from_var(str))
-end
-
-function input.format_of_var(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
-end
-function input.format_of_suffix(str)
- return input.suffixmap[file.extname(str)] or 'tex'
-end
-
-function input.variable_of_format(str)
- return input.formats[str] or input.formats[input.alternatives[str]] or ''
-end
-
-function input.var_of_format_or_suffix(str)
- local v = input.formats[str]
- if v then
- return v
- end
- v = input.formats[input.alternatives[str]]
- if v then
- return v
- end
- v = input.suffixmap[file.extname(str)]
- if v then
- return input.formats[isf]
- end
- return ''
-end
-
-function input.expand_braces(str) -- output variable and brace expansion of STRING
- local ori = input.variable(str)
- local pth = input.aux.expanded_path(input.split_path(ori))
- return file.join_path(pth)
-end
-
--- {a,b,c,d}
--- a,b,c/{p,q,r},d
--- a,b,c/{p,q,r}/d/{x,y,z}//
--- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
--- a,b,c/{p,q/{x,y,z},r},d/{p,q,r}
--- a{b,c}{d,e}f
--- {a,b,c,d}
--- {a,b,c/{p,q,r},d}
--- {a,b,c/{p,q,r}/d/{x,y,z}//}
--- {a,b,c/{p,q/{x,y,z}},d/{p,q,r}}
--- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}}
--- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}
-
--- this one is better and faster, but it took me a while to realize
--- that this kind of replacement is cleaner than messy parsing and
--- fuzzy concatenating we can probably gain a bit with selectively
--- applying lpeg, but experiments with lpeg parsing this proved not to
--- work that well; the parsing is ok, but dealing with the resulting
--- table is a pain because we need to work inside-out recursively
-
-function input.aux.splitpathexpr(str, t, validate)
- -- no need for optimization, only called a few times, we can use lpeg for the sub
- t = t or { }
- str = str:gsub(",}",",@}")
- str = str:gsub("{,","{@,")
- -- str = "@" .. str .. "@"
- while true do
- local done = false
- while true do
- local ok = false
- str = str:gsub("([^{},]+){([^{}]+)}", function(a,b)
- local t = { }
- for s in b:gmatch("[^,]+") do t[#t+1] = a .. s end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- while true do
- local ok = false
- str = str:gsub("{([^{}]+)}([^{},]+)", function(a,b)
- local t = { }
- for s in a:gmatch("[^,]+") do t[#t+1] = s .. b end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- while true do
- local ok = false
- str = str:gsub("{([^{}]+)}{([^{}]+)}", function(a,b)
- local t = { }
- for sa in a:gmatch("[^,]+") do
- for sb in b:gmatch("[^,]+") do
- t[#t+1] = sa .. sb
- end
- end
- ok, done = true, true
- return "{" .. concat(t,",") .. "}"
- end)
- if not ok then break end
- end
- str = str:gsub("({[^{}]*){([^{}]+)}([^{}]*})", function(a,b,c)
- done = true
- return a .. b.. c
- end)
- if not done then break end
- end
- str = str:gsub("[{}]", "")
- str = str:gsub("@","")
- if validate then
- for s in str:gmatch("[^,]+") do
- s = validate(s)
- if s then t[#t+1] = s end
- end
- else
- for s in str:gmatch("[^,]+") do
- t[#t+1] = s
- end
- end
- return t
-end
-
-function input.aux.expanded_path(pathlist) -- maybe not a list, just a path
- local instance = input.instance
- -- a previous version fed back into pathlist
- local newlist, ok = { }, false
- for _,v in ipairs(pathlist) do
- if v:find("[{}]") then
- ok = true
- break
- end
- end
- if ok then
- for _, v in ipairs(pathlist) do
- input.aux.splitpathexpr(v, newlist, function(s)
- s = file.collapse_path(s)
- return s ~= "" and not s:find(instance.dummy_path_expr) and s
- end)
- end
- else
- for _,v in ipairs(pathlist) do
- for vv in string.gmatch(v..',',"(.-),") do
- vv = file.collapse_path(v)
- if vv ~= "" then newlist[#newlist+1] = vv end
- end
- end
- end
- return newlist
-end
-
-input.is_readable = { }
-
-function input.aux.is_readable(readable, name)
- if input.trace > 2 then
- if readable then
- input.logger("+ readable: %s",name)
- else
- input.logger("- readable: %s", name)
- end
- end
- return readable
-end
-
-function input.is_readable.file(name)
- return input.aux.is_readable(lfs.isfile(name), name)
-end
-
-input.is_readable.tex = input.is_readable.file
-
--- name
--- name/name
-
-function input.aux.collect_files(names)
- local instance = input.instance
- local filelist = { }
- for _, fname in pairs(names) do
- if fname then
- if input.trace > 2 then
- input.logger("? blobpath asked: %s",fname)
- end
- local bname = file.basename(fname)
- local dname = file.dirname(fname)
- if dname == "" or dname:find("^%.") then
- dname = false
- else
- dname = "/" .. dname .. "$"
- end
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local files = blobpath and instance.files[blobpath]
- if files then
- if input.trace > 2 then
- input.logger('? blobpath do: %s (%s)',blobpath,bname)
- end
- local blobfile = files[bname]
- if not blobfile then
- local rname = "remap:"..bname
- blobfile = files[rname]
- if blobfile then
- bname = files[rname]
- blobfile = files[bname]
- end
- end
- if blobfile then
- if type(blobfile) == 'string' then
- if not dname or blobfile:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,blobfile,bname), -- search
- input.concatinators[hash.type](blobpath,blobfile,bname) -- result
- }
- end
- else
- for _, vv in pairs(blobfile) do
- if not dname or vv:find(dname) then
- filelist[#filelist+1] = {
- hash.type,
- file.join(blobpath,vv,bname), -- search
- input.concatinators[hash.type](blobpath,vv,bname) -- result
- }
- end
- end
- end
- end
- elseif input.trace > 1 then
- input.logger('! blobpath no: %s (%s)',blobpath,bname)
- end
- end
- end
- end
- if #filelist > 0 then
- return filelist
- else
- return nil
- end
-end
-
-function input.suffix_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str][1]
- else
- return ""
- end
-end
-
-function input.suffixes_of_format(str)
- if input.suffixes[str] then
- return input.suffixes[str]
- else
- return {}
- end
-end
-
-do
-
- -- called about 700 times for an empty doc (font initializations etc)
- -- i need to weed the font files for redundant calls
-
- local letter = lpeg.R("az","AZ")
- local separator = lpeg.P("://")
-
- local qualified = lpeg.P(".")^0 * lpeg.P("/") + letter*lpeg.P(":") + letter^1*separator
- local rootbased = lpeg.P("/") + letter*lpeg.P(":")
-
- -- ./name ../name /name c: ://
- function input.aux.qualified_path(filename)
- return qualified:match(filename)
- end
- function input.aux.rootbased_path(filename)
- return rootbased:match(filename)
- end
-
- function input.normalize_name(original)
- return original
- end
-
- input.normalize_name = file.collapse_path
-
-end
-
-function input.aux.register_in_trees(name)
- if not name:find("^%.") then
- local instance = input.instance
- instance.foundintrees[name] = (instance.foundintrees[name] or 0) + 1 -- maybe only one
- end
-end
-
--- split the next one up, better for jit
-
-function input.aux.find_file(filename) -- todo : plugin (scanners, checkers etc)
- local instance = input.instance
- local result = { }
- local stamp = nil
- filename = input.normalize_name(filename) -- elsewhere
- filename = file.collapse_path(filename:gsub("\\","/")) -- elsewhere
- -- speed up / beware: format problem
- if instance.remember then
- stamp = filename .. "--" .. instance.engine .. "--" .. instance.progname .. "--" .. instance.format
- if instance.found[stamp] then
- if input.trace > 0 then
- input.logger('! remembered: %s',filename)
- end
- return instance.found[stamp]
- end
- end
- if filename:find('%*') then
- if input.trace > 0 then
- input.logger('! wildcard: %s', filename)
- end
- result = input.find_wildcard_files(filename)
- elseif input.aux.qualified_path(filename) then
- if input.is_readable.file(filename) then
- if input.trace > 0 then
- input.logger('! qualified: %s', filename)
- end
- result = { filename }
- else
- local forcedname, ok = "", false
- if file.extname(filename) == "" then
- if instance.format == "" then
- forcedname = filename .. ".tex"
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing standard filetype: tex')
- end
- result, ok = { forcedname }, true
- end
- else
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- forcedname = filename .. "." .. s
- if input.is_readable.file(forcedname) then
- if input.trace > 0 then
- input.logger('! no suffix, forcing format filetype: %s', s)
- end
- result, ok = { forcedname }, true
- break
- end
- end
- end
- end
- if not ok and input.trace > 0 then
- input.logger('? qualified: %s', filename)
- end
- end
- else
- -- search spec
- local filetype, extra, done, wantedfiles, ext = '', nil, false, { }, file.extname(filename)
- if ext == "" then
- if not instance.force_suffixes then
- wantedfiles[#wantedfiles+1] = filename
- end
- else
- wantedfiles[#wantedfiles+1] = filename
- end
- if instance.format == "" then
- if ext == "" then
- local forcedname = filename .. '.tex'
- wantedfiles[#wantedfiles+1] = forcedname
- filetype = input.format_of_suffix(forcedname)
- if input.trace > 0 then
- input.logger('! forcing filetype: %s',filetype)
- end
- else
- filetype = input.format_of_suffix(filename)
- if input.trace > 0 then
- input.logger('! using suffix based filetype: %s',filetype)
- end
- end
- else
- if ext == "" then
- for _, s in pairs(input.suffixes_of_format(instance.format)) do
- wantedfiles[#wantedfiles+1] = filename .. "." .. s
- end
- end
- filetype = instance.format
- if input.trace > 0 then
- input.logger('! using given filetype: %s',filetype)
- end
- end
- local typespec = input.variable_of_format(filetype)
- local pathlist = input.expanded_path_list(typespec)
- if not pathlist or #pathlist == 0 then
- -- no pathlist, access check only / todo == wildcard
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- input.logger('? filetype: %s',filetype or '?')
- input.logger('? wanted files: %s',concat(wantedfiles," | "))
- end
- for _, fname in pairs(wantedfiles) do
- if fname and input.is_readable.file(fname) then
- filename, done = fname, true
- result[#result+1] = file.join('.',fname)
- break
- end
- end
- -- this is actually 'other text files' or 'any' or 'whatever'
- local filelist = input.aux.collect_files(wantedfiles)
- local fl = filelist and filelist[1]
- if fl then
- filename = fl[3]
- result[#result+1] = filename
- done = true
- end
- else
- -- list search
- local filelist = input.aux.collect_files(wantedfiles)
- local doscan, recurse
- if input.trace > 2 then
- input.logger('? filename: %s',filename)
- -- if pathlist then input.logger('? path list: %s',concat(pathlist," | ")) end
- -- if filelist then input.logger('? file list: %s',concat(filelist," | ")) end
- end
- -- a bit messy ... esp the doscan setting here
- for _, path in pairs(pathlist) do
- if path:find("^!!") then doscan = false else doscan = true end
- if path:find("//$") then recurse = true else recurse = false end
- local pathname = path:gsub("^!+", '')
- done = false
- -- using file list
- if filelist and not (done and not instance.allresults) and recurse then
- -- compare list entries with permitted pattern
- pathname = pathname:gsub("([%-%.])","%%%1") -- this also influences
- pathname = pathname:gsub("/+$", '/.*') -- later usage of pathname
- pathname = pathname:gsub("//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname
- -- input.debug('?',expr)
- for _, fl in ipairs(filelist) do
- local f = fl[2]
- if f:find(expr) then
- -- input.debug('T',' '..f)
- if input.trace > 2 then
- input.logger('= found in hash: %s',f)
- end
- --- todo, test for readable
- result[#result+1] = fl[3]
- input.aux.register_in_trees(f) -- for tracing used files
- done = true
- if not instance.allresults then break end
- else
- -- input.debug('F',' '..f)
- end
- end
- end
- if not done and doscan then
- -- check if on disk / unchecked / does not work at all / also zips
- if input.method_is_file(pathname) then -- ?
- local pname = pathname:gsub("%.%*$",'')
- if not pname:find("%*") then
- local ppname = pname:gsub("/+$","")
- if input.aux.can_be_dir(ppname) then
- for _, w in pairs(wantedfiles) do
- local fname = file.join(ppname,w)
- if input.is_readable.file(fname) then
- if input.trace > 2 then
- input.logger('= found by scanning: %s',fname)
- end
- result[#result+1] = fname
- done = true
- if not instance.allresults then break end
- end
- end
- else
- -- no access needed for non existing path, speedup (esp in large tree with lots of fake)
- end
- end
- end
- end
- if not done and doscan then
- -- todo: slow path scanning
- end
- if done and not instance.allresults then break end
- end
- end
- end
- for k,v in pairs(result) do
- result[k] = file.collapse_path(v)
- end
- if instance.remember then
- instance.found[stamp] = result
- end
- return result
-end
-
-input.aux._find_file_ = input.aux.find_file -- frozen variant
-
-function input.aux.find_file(filename) -- maybe make a lowres cache too
- local result = input.aux._find_file_(filename)
- if #result == 0 then
- local lowered = filename:lower()
- if filename ~= lowered then
- return input.aux._find_file_(lowered)
- end
- end
- return result
-end
-
-function input.aux.can_be_dir(name)
- local instance = input.instance
- if not instance.fakepaths[name] then
- if lfs.isdir(name) then
- instance.fakepaths[name] = 1 -- directory
- else
- instance.fakepaths[name] = 2 -- no directory
- end
- end
- return (instance.fakepaths[name] == 1)
-end
-
-if not input.concatinators then input.concatinators = { } end
-
-input.concatinators.tex = file.join
-input.concatinators.file = input.concatinators.tex
-
-function input.find_files(filename,filetype,mustexist)
- local instance = input.instance
- if type(mustexist) == boolean then
- -- all set
- elseif type(filetype) == 'boolean' then
- filetype, mustexist = nil, false
- elseif type(filetype) ~= 'string' then
- filetype, mustexist = nil, false
- end
- instance.format = filetype or ''
- local t = input.aux.find_file(filename,true)
- instance.format = ''
- return t
-end
-
-function input.find_file(filename,filetype,mustexist)
- return (input.find_files(filename,filetype,mustexist)[1] or "")
-end
-
-function input.find_given_files(filename)
- local instance = input.instance
- local bname, result = file.basename(filename), { }
- for k, hash in ipairs(instance.hashes) do
- local files = instance.files[hash.tag]
- local blist = files[bname]
- if not blist then
- local rname = "remap:"..bname
- blist = files[rname]
- if blist then
- bname = files[rname]
- blist = files[bname]
- end
- end
- if blist then
- if type(blist) == 'string' then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- if not instance.allresults then break end
- else
- for kk,vv in pairs(blist) do
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- if not instance.allresults then break end
- end
- end
- end
- end
- return result
-end
-
-function input.find_given_file(filename)
- return (input.find_given_files(filename)[1] or "")
-end
-
-function input.find_wildcard_files(filename) -- todo: remap:
- local instance = input.instance
- local result = { }
- local bname, dname = file.basename(filename), file.dirname(filename)
- local path = dname:gsub("^*/","")
- path = path:gsub("*",".*")
- path = path:gsub("-","%%-")
- if dname == "" then
- path = ".*"
- end
- local name = bname
- name = name:gsub("*",".*")
- name = name:gsub("-","%%-")
- path = path:lower()
- name = name:lower()
- local function doit(blist,bname,hash,allresults)
- local done = false
- if blist then
- if type(blist) == 'string' then
- -- make function and share code
- if (blist:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,blist,bname) or ""
- done = true
- end
- else
- for kk,vv in pairs(blist) do
- if (vv:lower()):find(path) then
- result[#result+1] = input.concatinators[hash.type](hash.tag,vv,bname) or ""
- done = true
- if not allresults then break end
- end
- end
- end
- end
- return done
- end
- local files, allresults, done = instance.files, instance.allresults, false
- if name:find("%*") then
- for k, hash in ipairs(instance.hashes) do
- for kk, hh in pairs(files[hash.tag]) do
- if not kk:find("^remap:") then
- if (kk:lower()):find(name) then
- if doit(hh,kk,hash,allresults) then done = true end
- if done and not allresults then break end
- end
- end
- end
- end
- else
- for k, hash in ipairs(instance.hashes) do
- if doit(files[hash.tag][bname],bname,hash,allresults) then done = true end
- if done and not allresults then break end
- end
- end
- -- we can consider also searching the paths not in the database, but then
- -- we end up with a messy search (all // in all path specs)
- return result
-end
-
-function input.find_wildcard_file(filename)
- return (input.find_wildcard_files(filename)[1] or "")
-end
-
--- main user functions
-
-function input.save_used_files_in_trees(filename,jobname)
- local instance = input.instance
- if not filename then filename = 'luatex.jlg' end
- local f = io.open(filename,'w')
- if f then
- f:write("\n")
- f:write("\n")
- if jobname then
- f:write("\t" .. jobname .. "\n")
- end
- f:write("\t\n")
- for _,v in pairs(sorted(instance.foundintrees)) do -- ipairs
- f:write("\t\t" .. v .. "\n")
- end
- f:write("\t\n")
- f:write("\n")
- f:close()
- end
-end
-
-function input.automount()
- -- implemented later
-end
-
-function input.load()
- input.starttiming(input.instance)
- input.resetconfig()
- input.identify_cnf()
- input.load_lua()
- input.expand_variables()
- input.load_cnf()
- input.expand_variables()
- input.load_hash()
- input.automount()
- input.stoptiming(input.instance)
-end
-
-function input.for_files(command, files, filetype, mustexist)
- if files and #files > 0 then
- local function report(str)
- if input.verbose then
- input.report(str) -- has already verbose
- else
- print(str)
- end
- end
- if input.verbose then
- report('')
- end
- for _, file in pairs(files) do
- local result = command(file,filetype,mustexist)
- if type(result) == 'string' then
- report(result)
- else
- for _,v in pairs(result) do
- report(v)
- end
- end
- end
- end
-end
-
--- strtab
-
-input.var_value = input.variable -- output the value of variable $STRING.
-input.expand_var = input.expansion -- output variable expansion of STRING.
-
-function input.show_path(str) -- output search path for file type NAME
- return file.join_path(input.expanded_path_list(input.format_of_var(str)))
-end
-
--- input.find_file(filename)
--- input.find_file(filename, filetype, mustexist)
--- input.find_file(filename, mustexist)
--- input.find_file(filename, filetype)
-
-function input.aux.register_file(files, name, path)
- if files[name] then
- if type(files[name]) == 'string' then
- files[name] = { files[name], path }
- else
- files[name] = path
- end
- else
- files[name] = path
- end
-end
-
-if not input.finders then input.finders = { } end
-if not input.openers then input.openers = { } end
-if not input.loaders then input.loaders = { } end
-
-input.finders.notfound = { nil }
-input.openers.notfound = { nil }
-input.loaders.notfound = { false, nil, 0 }
-
-function input.splitmethod(filename)
- if not filename then
- return { } -- safeguard
- elseif type(filename) == "table" then
- return filename -- already split
- elseif not filename:find("://") then
- return { scheme="file", path = filename, original=filename } -- quick hack
- else
- return url.hashed(filename)
- end
-end
-
-function input.method_is_file(filename)
- return input.splitmethod(filename).scheme == 'file'
-end
-
-function table.sequenced(t,sep) -- temp here
- local s = { }
- for k, v in pairs(t) do
- s[#s+1] = k .. "=" .. v
- end
- return concat(s, sep or " | ")
-end
-
-function input.methodhandler(what, filename, filetype) -- ...
- local specification = (type(filename) == "string" and input.splitmethod(filename)) or filename -- no or { }, let it bomb
- local scheme = specification.scheme
- if input[what][scheme] then
- if input.trace > 0 then
- input.logger('= handler: %s -> %s -> %s',specification.original,what,table.sequenced(specification))
- end
- return input[what][scheme](filename,filetype) -- todo: specification
- else
- return input[what].tex(filename,filetype) -- todo: specification
- end
-end
-
--- also inside next test?
-
-function input.findtexfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
-end
-function input.opentexfile(filename)
- return input.methodhandler('openers',input.normalize_name(filename))
-end
-
-function input.findbinfile(filename, filetype)
- return input.methodhandler('finders',input.normalize_name(filename), filetype)
-end
-function input.openbinfile(filename)
- return input.methodhandler('loaders',input.normalize_name(filename))
-end
-
-function input.loadbinfile(filename, filetype)
- local fname = input.findbinfile(input.normalize_name(filename), filetype)
- if fname and fname ~= "" then
- return input.openbinfile(fname)
- else
- return unpack(input.loaders.notfound)
- end
-end
-
-function input.texdatablob(filename, filetype)
- local ok, data, size = input.loadbinfile(filename, filetype)
- return data or ""
-end
-
-input.loadtexfile = input.texdatablob
-
-function input.openfile(filename)
- local fullname = input.findtexfile(filename)
- if fullname and (fullname ~= "") then
- return input.opentexfile(fullname)
- else
- return nil
- end
-end
-
-function input.logmode()
- return (os.getenv("MTX.LOG.MODE") or os.getenv("MTX_LOG_MODE") or "tex"):lower()
-end
-
--- this is a prelude to engine/progname specific configuration files
--- in which case we can omit files meant for other programs and
--- packages
-
---- ctx
-
--- maybe texinputs + font paths
--- maybe positive selection tex/context fonts/tfm|afm|vf|opentype|type1|map|enc
-
-input.validators = { }
-input.validators.visibility = { }
-
-function input.validators.visibility.default(path, name)
- return true
-end
-
-function input.validators.visibility.context(path, name)
- path = path[1] or path -- some day a loop
- return not (
- path:find("latex") or
--- path:find("doc") or
- path:find("tex4ht") or
- path:find("source") or
--- path:find("config") or
--- path:find("metafont") or
- path:find("lists$") or
- name:find("%.tpm$") or
- name:find("%.bak$")
- )
-end
-
--- todo: describe which functions are public (maybe input.private. ... )
-
--- beware: i need to check where we still need a / on windows:
-
-function input.clean_path(str)
- if str then
- str = str:gsub("\\","/")
- str = str:gsub("^!+","")
- str = str:gsub("^~",input.homedir)
- return str
- else
- return nil
- end
-end
-
-function input.do_with_path(name,func)
- for _, v in pairs(input.expanded_path_list(name)) do
- func("^"..input.clean_path(v))
- end
-end
-
-function input.do_with_var(name,func)
- func(input.aux.expanded_var(name))
-end
-
-function input.with_files(pattern,handle)
- local instance = input.instance
- for _, hash in ipairs(instance.hashes) do
- local blobpath = hash.tag
- local blobtype = hash.type
- if blobpath then
- local files = instance.files[blobpath]
- if files then
- for k,v in pairs(files) do
- if k:find("^remap:") then
- k = files[k]
- v = files[k] -- chained
- end
- if k:find(pattern) then
- if type(v) == "string" then
- handle(blobtype,blobpath,v,k)
- else
- for _,vv in pairs(v) do
- handle(blobtype,blobpath,vv,k)
- end
- end
- end
- end
- end
- end
- end
-end
-
-function input.update_script(oldname,newname) -- oldname -> own.name, not per se a suffix
- local scriptpath = "scripts/context/lua"
- newname = file.addsuffix(newname,"lua")
- local oldscript = input.clean_path(oldname)
- input.report("to be replaced old script %s", oldscript)
- local newscripts = input.find_files(newname) or { }
- if #newscripts == 0 then
- input.report("unable to locate new script")
- else
- for _, newscript in ipairs(newscripts) do
- newscript = input.clean_path(newscript)
- input.report("checking new script %s", newscript)
- if oldscript == newscript then
- input.report("old and new script are the same")
- elseif not newscript:find(scriptpath) then
- input.report("new script should come from %s",scriptpath)
- elseif not (oldscript:find(file.removesuffix(newname).."$") or oldscript:find(newname.."$")) then
- input.report("invalid new script name")
- else
- local newdata = io.loaddata(newscript)
- if newdata then
- input.report("old script content replaced by new content")
- io.savedata(oldscript,newdata)
- break
- else
- input.report("unable to load new script")
- end
- end
- end
- end
-end
-
-
---~ print(table.serialize(input.aux.splitpathexpr("/usr/share/texmf-{texlive,tetex}", {})))
-
--- command line resolver:
-
---~ print(input.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex"))
-
-do
-
- local resolvers = { }
-
- resolvers.environment = function(str)
- return input.clean_path(os.getenv(str) or os.getenv(str:upper()) or os.getenv(str:lower()) or "")
- end
- resolvers.relative = function(str,n)
- if io.exists(str) then
- -- nothing
- elseif io.exists("./" .. str) then
- str = "./" .. str
- else
- local p = "../"
- for i=1,n or 2 do
- if io.exists(p .. str) then
- str = p .. str
- break
- else
- p = p .. "../"
- end
- end
- end
- return input.clean_path(str)
- end
- resolvers.locate = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path((fullname ~= "" and fullname) or str)
- end
- resolvers.filename = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.basename((fullname ~= "" and fullname) or str))
- end
- resolvers.pathname = function(str)
- local fullname = input.find_given_file(str) or ""
- return input.clean_path(file.dirname((fullname ~= "" and fullname) or str))
- end
-
- resolvers.env = resolvers.environment
- resolvers.rel = resolvers.relative
- resolvers.loc = resolvers.locate
- resolvers.kpse = resolvers.locate
- resolvers.full = resolvers.locate
- resolvers.file = resolvers.filename
- resolvers.path = resolvers.pathname
-
- local function resolve(str)
- if type(str) == "table" then
- for k, v in pairs(str) do
- str[k] = resolve(v) or v
- end
- elseif str and str ~= "" then
- str = str:gsub("([a-z]+):([^ \"\']*)", function(method,target)
- if resolvers[method] then
- return resolvers[method](target)
- else
- return method .. ":" .. target
- end
- end)
- end
- return str
- end
-
- if os.uname then
- for k, v in pairs(os.uname()) do
- if not resolvers[k] then
- resolvers[k] = function() return v end
- end
- end
- end
-
- input.resolve = resolve
-
-end
-
-function input.boolean_variable(str,default)
- local b = input.expansion(str)
- if b == "" then
- return default
- else
- b = toboolean(b)
- return (b == nil and default) or b
- end
-end
diff --git a/tex/context/base/luat-iop.lua b/tex/context/base/luat-iop.lua
index 469b7c034..883ec43ce 100644
--- a/tex/context/base/luat-iop.lua
+++ b/tex/context/base/luat-iop.lua
@@ -1,16 +1,16 @@
--- filename : luat-iop.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
+if not modules then modules = { } end modules ['luat-iop'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-- this paranoid stuff in web2c ... we cannot hook checks into the
-- input functions because one can always change the callback but
-- we can feed back specific patterns and paths into the next
-- mechanism
-if not versions then versions = { } end versions['luat-exe'] = 1.001
-
if not io.inp then io.inp = { } end
if not io.out then io.out = { } end
@@ -127,11 +127,11 @@ function io.inp.modes.paranoid()
io.inp.inhibit('%.%.')
io.inp.permit('^%./')
io.inp.permit('[^/]')
- input.do_with_path('TEXMF',io.inp.permit)
+ resolvers.do_with_path('TEXMF',io.inp.permit)
end
function io.out.modes.paranoid()
io.out.inhibit('.*')
- input.do_with_path('TEXMFOUTPUT',io.out.permit)
+ resolvers.do_with_path('TEXMFOUTPUT',io.out.permit)
end
-- handy
diff --git a/tex/context/base/luat-kps.lua b/tex/context/base/luat-kps.lua
deleted file mode 100644
index 15dadbb84..000000000
--- a/tex/context/base/luat-kps.lua
+++ /dev/null
@@ -1,102 +0,0 @@
-if not modules then modules = { } end modules ['luat-kps'] = {
- version = 1.001,
- comment = "companion to luatools.lua",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This file is used when we want the input handlers to behave like
-kpsewhich. What to do with the following:
If you wondered abou tsome of the previous mappings, how about
-the next bunch:
---ldx]]--
-
-input.formats['bib'] = ''
-input.formats['bst'] = ''
-input.formats['mft'] = ''
-input.formats['ist'] = ''
-input.formats['web'] = ''
-input.formats['cweb'] = ''
-input.formats['MetaPost support'] = ''
-input.formats['TeX system documentation'] = ''
-input.formats['TeX system sources'] = ''
-input.formats['Troff fonts'] = ''
-input.formats['dvips config'] = ''
-input.formats['graphic/figure'] = ''
-input.formats['ls-R'] = ''
-input.formats['other text files'] = ''
-input.formats['other binary files'] = ''
-
-input.formats['gf'] = ''
-input.formats['pk'] = ''
-input.formats['base'] = 'MFBASES'
-input.formats['cnf'] = ''
-input.formats['mem'] = 'MPMEMS'
-input.formats['mf'] = 'MFINPUTS'
-input.formats['mfpool'] = 'MFPOOL'
-input.formats['mppool'] = 'MPPOOL'
-input.formats['texpool'] = 'TEXPOOL'
-input.formats['PostScript header'] = 'TEXPSHEADERS'
-input.formats['cmap files'] = 'CMAPFONTS'
-input.formats['type42 fonts'] = 'T42FONTS'
-input.formats['web2c files'] = 'WEB2C'
-input.formats['pdftex config'] = 'PDFTEXCONFIG'
-input.formats['texmfscripts'] = 'TEXMFSCRIPTS'
-input.formats['bitmap font'] = ''
-input.formats['lig files'] = 'LIGFONTS'
diff --git a/tex/context/base/luat-lib.lua b/tex/context/base/luat-lib.lua
deleted file mode 100644
index 06d00e778..000000000
--- a/tex/context/base/luat-lib.lua
+++ /dev/null
@@ -1,174 +0,0 @@
-if not modules then modules = { } end modules ['luat-lib'] = {
- version = 1.001,
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files",
- comment = "companion to luat-lib.tex",
-}
-
--- most code already moved to the l-*.lua and other luat-*.lua files
-
-os.setlocale(nil,nil) -- useless feature and even dangerous in luatex
-
-function os.setlocale()
- -- no way you can mess with it
-end
-
-if arg and (arg[0] == 'luatex' or arg[0] == 'luatex.exe') and arg[1] == "--luaonly" then
- arg[-1]=arg[0] arg[0]=arg[2] for k=3,#arg do arg[k-2]=arg[k] end arg[#arg]=nil arg[#arg]=nil
-end
-
-environment = environment or { }
-environment.arguments = { }
-environment.files = { }
-environment.sortedflags = nil
-
-function environment.initialize_arguments(arg)
- local arguments, files = { }, { }
- environment.arguments, environment.files, environment.sortedflags = arguments, files, nil
- for index, argument in pairs(arg) do
- if index > 0 then
- local flag, value = argument:match("^%-+(.+)=(.-)$")
- if flag then
- arguments[flag] = string.unquote(value or "")
- else
- flag = argument:match("^%-+(.+)")
- if flag then
- arguments[flag] = true
- else
- files[#files+1] = argument
- end
- end
- end
- end
- environment.ownname = environment.ownname or arg[0] or 'unknown.lua'
-end
-
-function environment.showarguments()
- for k,v in pairs(environment.arguments) do
- print(k .. " : " .. tostring(v))
- end
- if #environment.files > 0 then
- print("files : " .. table.concat(environment.files, " "))
- end
-end
-
-function environment.setargument(name,value)
- environment.arguments[name] = value
-end
-
-function environment.argument(name) -- todo: default (plus typecheck on default)
- local arguments, sortedflags = environment.arguments, environment.sortedflags
- if arguments[name] then
- return arguments[name]
- else
- if not sortedflags then
- sortedflags = { }
- for _,v in pairs(table.sortedkeys(arguments)) do
- sortedflags[#sortedflags+1] = "^" .. v
- end
- environment.sortedflags = sortedflags
- end
- for _,v in ipairs(sortedflags) do
- if name:find(v) then
- return arguments[v:sub(2,#v)]
- end
- end
- end
- return nil
-end
-
-function environment.split_arguments(separator) -- rather special, cut-off before separator
- local done, before, after = false, { }, { }
- for _,v in ipairs(environment.original_arguments) do
- if not done and v == separator then
- done = true
- elseif done then
- after[#after+1] = v
- else
- before[#before+1] = v
- end
- end
- return before, after
-end
-
---~ function environment.reconstruct_commandline(arg)
---~ if not arg then arg = environment.original_arguments end
---~ local result = { }
---~ for _,a in ipairs(arg) do -- ipairs 1 .. #n
---~ local kk, vv = a:match("^(%-+.-)=(.+)$")
---~ if kk and vv then
---~ if vv:find(" ") then
---~ vv = vv:unquote()
---~ vv = vv:gsub('"','\\"')
---~ result[#result+1] = kk .. "=" .. vv:quote()
---~ else
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a
---~ end
---~ elseif a:find(" ") then
---~ a = a:unquote()
---~ a = a:gsub('"','\\"')
---~ result[#result+1] = a:quote()
---~ else
---~ result[#result+1] = a
---~ end
---~ end
---~ return table.join(result," ")
---~ end
-
-function environment.reconstruct_commandline(arg,noquote)
- if not arg then arg = environment.original_arguments end
- if noquote and #arg == 1 then
- local a = arg[1]
- a = input.resolve(a)
- a = a:unquote()
- return a
- elseif #arg == 1 then
- local result = { }
- for _,a in ipairs(arg) do -- ipairs 1 .. #n
- a = input.resolve(a)
- a = a:unquote()
- a = a:gsub('"','\\"') -- tricky
- if a:find(" ") then
- result[#result+1] = a:quote()
- else
- result[#result+1] = a
- end
- end
- return table.join(result," ")
- end
-end
-
-if arg then
-
- -- new, reconstruct quoted snippets (maybe better just remnove the " then and add them later)
- local newarg, instring = { }, false
-
- for index, argument in ipairs(arg) do
- if argument:find("^\"") then
- newarg[#newarg+1] = argument:gsub("^\"","")
- if not argument:find("\"$") then
- instring = true
- end
- elseif argument:find("\"$") then
- newarg[#newarg] = newarg[#newarg] .. " " .. argument:gsub("\"$","")
- instring = false
- elseif instring then
- newarg[#newarg] = newarg[#newarg] .. " " .. argument
- else
- newarg[#newarg+1] = argument
- end
- end
- for i=1,-5,-1 do
- newarg[i] = arg[i]
- end
-
- environment.initialize_arguments(newarg)
- environment.original_arguments = newarg
- environment.raw_arguments = arg
-
- arg = { } -- prevent duplicate handling
-
-end
diff --git a/tex/context/base/luat-lib.tex b/tex/context/base/luat-lib.tex
index 9693595b2..ec781f3cf 100644
--- a/tex/context/base/luat-lib.tex
+++ b/tex/context/base/luat-lib.tex
@@ -2,7 +2,7 @@
%D [ file=luat-lib,
%D version=2006.09.11,
%D title=\CONTEXT\ Lua Macros,
-%D subtitle=Unicode Support,
+%D subtitle=Libraries,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
@@ -11,60 +11,41 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-% \writestatus{loading}{Lua Support Macros (libs)}
+% \writestatus{loading}{ConTeXt Lua Macros / Libraries}
-%D For the moment we only load this lib.
+\registerctxluafile{trac-inf} {1.001}
+\registerctxluafile{trac-tra} {1.001}
+\registerctxluafile{trac-log} {1.001}
-%D This will move cq. become configurable. The XML like output is just
-%D an example.
-
-% todo \let\normaleverytoks\everytoks \newtoks\everytoke \normaleverytoks{\the\everytoks}
-
-\chardef\statuswidth=15
-\chardef\statuswrite=16
-
-\newtoks\everywritestring
-
-\def\writedirect {\immediate\write\statuswrite}
-\def\writeline {\writedirect{}}
-\def\writestring#1{\begingroup\the\everywritestring\writedirect{#1}\endgroup}
-
-\ifx\normalmessage \undefined \let\normalmessage \message \fi
-\ifx\normalwritestatus\undefined \def\normalwritestatus#1#2{\writedirect{#1 : #2}} \fi
-
-% this will change once we have proper write overloads
+\registerctxluafile{luat-cbk} {1.001}
-\registerctxluafile{l-string} {1.001}
-\registerctxluafile{l-lpeg} {1.001}
-\registerctxluafile{l-boolean}{1.001}
-\registerctxluafile{l-number} {1.001}
-\registerctxluafile{l-set} {1.001}
-\registerctxluafile{l-math} {1.001}
-\registerctxluafile{l-table} {1.001}
-\registerctxluafile{l-md5} {1.001}
-\registerctxluafile{l-aux} {1.001}
-\registerctxluafile{l-io} {1.001}
-\registerctxluafile{l-os} {1.001}
-\registerctxluafile{l-file} {1.001}
-\registerctxluafile{l-dir} {1.001}
-\registerctxluafile{l-unicode}{1.001}
-\registerctxluafile{l-utils} {1.001}
-\registerctxluafile{l-dimen} {1.001}
-\registerctxluafile{l-url} {1.001}
-\registerctxluafile{l-xml} {1.001}
-%registerctxluafile{l-xmlctx} {1.001}
+\registerctxluafile{data-res} {1.001}
+\registerctxluafile{data-tmp} {1.001}
+\registerctxluafile{data-pre} {1.001}
+\registerctxluafile{data-inp} {1.001}
+\registerctxluafile{data-out} {1.001}
+\registerctxluafile{data-tex} {1.001}
+\registerctxluafile{data-bin} {1.001}
+\registerctxluafile{data-zip} {1.001}
+\registerctxluafile{data-crl} {1.001}
+\registerctxluafile{data-tre} {1.001}
+\registerctxluafile{data-lua} {1.001}
+\registerctxluafile{data-ctx} {1.001}
+\registerctxluafile{data-con} {1.001}
+\registerctxluafile{data-use} {1.001}
-\registerctxluafile{luat-cbk} {1.001}
-\registerctxluafile{luat-lib} {1.001}
-\registerctxluafile{luat-inp} {1.001}
-\registerctxluafile{luat-log} {1.001}
-\registerctxluafile{luat-zip} {1.001}
-\registerctxluafile{luat-tex} {1.001}
+\registerctxluafile{luat-run} {1.001}
+\registerctxluafile{luat-fio} {1.001} % not needed, part of startup file
+\registerctxluafile{luat-cnf} {1.001} % not needed, part of startup file
\registerctxluafile{luat-lua} {1.001}
-\registerctxluafile{luat-tre} {1.001}
+\registerctxluafile{luat-sto} {1.001}
+\registerctxluafile{luat-ini} {1.001}
+\registerctxluafile{luat-env} {1.001}
+
+\registerctxluafile{l-xml} {1.001} % we want tracking
\startruntimeluacode
- \edef\asciia{\ctxlua{tex.sprint(input.logmode())}}
+ \edef\asciia{\ctxlua{tex.sprint(logs.mode)}}
\edef\asciib{xml}
\ifx\asciia\asciib % brrr
\long\def\writebanner #1{\writestring {#1}}
@@ -77,15 +58,8 @@
\fi
\stopruntimeluacode
-\registerctxluafile{luat-tmp}{1.001}
-\registerctxluafile{luat-crl}{1.001}
+%registerctxluafile{luat-tmp}{1.001}
\registerctxluafile{luat-exe}{1.001}
\registerctxluafile{luat-iop}{1.001}
-% trace used files (only from trees)
-%
-% \ctxlua{input.register_stop_actions(function() input.save_used_files_in_trees() end)}
-% \ctxlua{table.insert(input.stop_actions, function() input.save_used_files_in_trees() end)}
-% \ctxlua{function input.stop_actions.trace_used_files() input.save_used_files_in_trees() end}
-
\endinput
diff --git a/tex/context/base/luat-lmx.lua b/tex/context/base/luat-lmx.lua
deleted file mode 100644
index b9bab7df1..000000000
--- a/tex/context/base/luat-lmx.lua
+++ /dev/null
@@ -1,141 +0,0 @@
--- filename : luat-lmx.lua
--- comment : companion to luat-lmx.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-mlx'] = 1.001
-
--- we can now use l-xml, and we can also use lpeg
-
-lmx = { }
-
-lmx.escapes = {
- ['&'] = '&',
- ['<'] = '<',
- ['>'] = '>',
- ['"'] = '"'
-}
-
--- local function p -> ends up in lmx.p, so we need to cast
-
-lmx.variables = { }
-
-lmx.variables['title-default'] = 'LMX File'
-lmx.variables['title'] = lmx.variables['title-default']
-
--- demonstrates: local, *all, gsub using tables, nil or value, loadstring
-
-function lmx.loadedfile(filename)
- return input.texdatablob(filename)
-end
-
-lmx.converting = false
-
-function lmx.convert(template,result) -- todo: use lpeg instead
- if not lmx.converting then -- else, if error then again tex error and loop
- local data = input.texdatablob(template)
- local f = false
- if result then
- f = io.open(result,"w")
- function lmx.print(str) f:write(str) end
- else
- lmx.print = io.write
- end
- function lmx.variable(str)
- return lmx.variables[str] or ""
- end
- function lmx.escape(str)
- return string.gsub(str:gsub('&','&'),'[<>"]',lmx.escapes)
- end
- function lmx.type(str)
- if str then lmx.print("" .. lmx.escape(str) .. "") end
- end
- function lmx.pv(str)
- lmx.print(lmx.variable(str))
- end
- function lmx.tv(str)
- lmx.type(lmx.variable(str))
- end
- data = data:gsub("<%?lmx%-include%s+(.-)%s-%?>", function(filename)
- return lmx.loadedfile(filename)
- end)
- local definitions = { }
- data = data:gsub("<%?lmx%-define%-begin%s+(%S-)%s-%?>(.-)<%?lmx%-define%-end%s-%?>", function(tag,content)
- definitions[tag] = content
- return ""
- end)
- data = data:gsub("<%?lmx%-resolve%s+(%S-)%s-%?>", function(tag)
- return definitions[tag] or ""
- end)
- data = data:gsub("%c%s-(<%?lua .-%?>)%s-%c", function(lua)
- return "\n" .. lua .. " "
- end)
- data = string.gsub(data .. "","(.-)<%?lua%s+(.-)%?>", function(txt, lua)
- txt = txt:gsub("%c+", "\\n")
- txt = txt:gsub('"' , '\\"')
- txt = txt:gsub("'" , "\\'")
- -- txt = string.gsub(txt, "([\'\"])", { ["'"] = '\\"', ['"'] = "\\'" } )
- return "p(\"" .. txt .. "\")\n" .. lua .. "\n"
- end)
- lmx.converting = true
- data = "local p,v,e,t,pv,tv = lmx.print,lmx.variable,lmx.escape,lmx.type,lmx.pv,lmx.tv " .. data
- assert(loadstring(data))()
- lmx.converting = false
- if f then
- f:close()
- end
- end
-end
-
--- these can be overloaded; we assume that the os handles filename associations
-
-lmx.lmxfile = function(filename) return filename end
-lmx.htmfile = function(filename) return filename end
-
-if os.platform == "windows" then
- lmx.popupfile = function(filename) os.execute("start " .. filename) end
-else
- lmx.popupfile = function(filename) os.execute(filename) end
-end
-
-function lmx.show(name)
- local lmxfile = lmx.lmxfile(name)
- local htmfile = lmx.htmfile(name)
- if lmxfile == htmfile then
- htmfile = string.gsub(lmxfile, "%.%a+$", "html")
- end
- lmx.convert(lmxfile, htmfile)
- lmx.popupfile(htmfile)
-end
-
--- kind of private
-
-lmx.restorables = { }
-
-function lmx.set(key, value)
- if not lmx.restorables[key] then
- table.insert(lmx.restorables, key)
- lmx.variables['@@' .. key] = lmx.variables[key]
- end
- lmx.variables[key] = value
-end
-
-function lmx.get(key)
- return lmx.variables[key] or ""
-end
-
-function lmx.restore()
- for _,key in pairs(lmx.restorables) do
- lmx.variables[key] = lmx.variables['@@' .. key]
- end
- lmx.restorables = { }
-end
-
--- command line
-
-if arg then
- if arg[1] == "--show" then if arg[2] then lmx.show (arg[2]) end
- elseif arg[1] == "--convert" then if arg[2] then lmx.convert(arg[2], arg[3] or "temp.html") end
- end
-end
diff --git a/tex/context/base/luat-lmx.tex b/tex/context/base/luat-lmx.tex
deleted file mode 100644
index cc7fa448f..000000000
--- a/tex/context/base/luat-lmx.tex
+++ /dev/null
@@ -1,16 +0,0 @@
-%D \module
-%D [ file=luat-lmx,
-%D version=2005.09.02,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=LMX Support,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Lua Support Macros (lmx)}
-
-\registerctxluafile{luat-lmx}{1.001}
diff --git a/tex/context/base/luat-log.lua b/tex/context/base/luat-log.lua
deleted file mode 100644
index 3704b3999..000000000
--- a/tex/context/base/luat-log.lua
+++ /dev/null
@@ -1,155 +0,0 @@
-if not modules then modules = { } end modules ['luat-log'] = {
- version = 1.001,
- comment = "companion to luat-lib.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This is a prelude to a more extensive logging module. For the sake
-of parsing log files, in addition to the standard logging we will
-provide an structured file. Actually, any logging that
-is hooked into callbacks will be \XML\ by default.
---ldx]]--
-
--- input.logger -> special tracing, driven by log level (only input)
--- input.report -> goes to terminal, depends on verbose, has banner
--- logs.report -> module specific tracing and reporting, no banner but class
-
-
-input = input or { }
-logs = logs or { }
-
---[[ldx--
-
This looks pretty ugly but we need to speed things up a bit.
---ldx]]--
-
-logs.levels = {
- ['error'] = 1,
- ['warning'] = 2,
- ['info'] = 3,
- ['debug'] = 4
-}
-
-logs.functions = {
- 'report', 'start', 'stop', 'push', 'pop', 'line', 'direct'
-}
-
-logs.callbacks = {
- 'start_page_number',
- 'stop_page_number',
- 'report_output_pages',
- 'report_output_log'
-}
-
-logs.tracers = {
-}
-
-logs.xml = logs.xml or { }
-logs.tex = logs.tex or { }
-
-logs.level = 0
-
-local write_nl, write, format = texio.write_nl or print, texio.write or io.write, string.format
-
-if texlua then
- write_nl = print
- write = io.write
-end
-
-function logs.xml.report(category,fmt,...) -- new
- write_nl(format("%s",category,format(fmt,...)))
-end
-function logs.xml.line(fmt,...) -- new
- write_nl(format("%s",format(fmt,...)))
-end
-
-function logs.xml.start() if logs.level > 0 then tw("<%s>" ) end end
-function logs.xml.stop () if logs.level > 0 then tw("%s>") end end
-function logs.xml.push () if logs.level > 0 then tw("" ) end end
-
-function logs.tex.report(category,fmt,...) -- new
- -- write_nl(format("%s | %s",category,format(fmt,...))) -- arg to format can be tex comment so .. .
- write_nl(category .. " | " .. format(fmt,...))
-end
-function logs.tex.line(fmt,...) -- new
- write_nl(format(fmt,...))
-end
-
-function logs.set_level(level)
- logs.level = logs.levels[level] or level
-end
-
-function logs.set_method(method)
- for _, v in pairs(logs.functions) do
- logs[v] = logs[method][v] or function() end
- end
- if callback and input[method] then
- for _, cb in pairs(logs.callbacks) do
- callback.register(cb, input[method][cb])
- end
- end
-end
-
-function logs.xml.start_page_number()
- write_nl(format("")
- write_nl("")
-end
-
-function logs.xml.report_output_pages(p,b)
- write_nl(format("", p))
- write_nl(format("", b))
- write_nl("")
-end
-
-function logs.xml.report_output_log()
-end
-
-function input.logger(...) -- assumes test for input.trace > n
- if input.trace > 0 then
- logs.report(...)
- end
-end
-
-function input.report(fmt,...)
- if input.verbose then
- logs.report(input.banner or "report",format(fmt,...))
- end
-end
-
-function input.reportlines(str) -- todo:
- for line in str:gmatch("(.-)[\n\r]") do
- logs.report(input.banner or "report",line)
- end
-end
-
-input.moreinfo = [[
-more information about ConTeXt and the tools that come with it can be found at:
-
-maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
-webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
-wiki : http://contextgarden.net
-]]
-
-function input.help(banner,message)
- if not input.verbose then
- input.verbose = true
- -- input.report(banner,"\n")
- end
- input.report(banner,"\n")
- input.report("")
- input.reportlines(message)
- if input.moreinfo and input.moreinfo ~= "" then
- input.report("")
- input.reportlines(input.moreinfo)
- end
-end
-
-logs.set_level('error')
-logs.set_method('tex')
diff --git a/tex/context/base/luat-lua.lua b/tex/context/base/luat-lua.lua
index 128be2f4b..61be6e9d6 100644
--- a/tex/context/base/luat-lua.lua
+++ b/tex/context/base/luat-lua.lua
@@ -23,7 +23,7 @@ if lua then do
end
function lua.flush(...)
- tex.sprint("\\directlua0{lua.flush_delayed(" .. table.concat({...},',') .. ")}")
+ tex.sprint("\\directlua0{lua.flush_delayed(",table.concat({...},','),")}")
end
end end
diff --git a/tex/context/base/luat-run.lua b/tex/context/base/luat-run.lua
new file mode 100644
index 000000000..09fce32c1
--- /dev/null
+++ b/tex/context/base/luat-run.lua
@@ -0,0 +1,69 @@
+if not modules then modules = { } end modules ['luat-run'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, rpadd = string.format, string.rpadd
+
+main = main or { }
+
+local start_actions = { }
+local stop_actions = { }
+
+function main.register_start_actions(...) table.insert(start_actions, ...) end
+function main.register_stop_actions (...) table.insert(stop_actions, ...) end
+
+main.show_tex_stat = main.show_tex_stat or function() end
+main.show_job_stat = main.show_job_stat or statistics.show_job_stat
+
+function main.start()
+ if logs.start_run then
+ logs.start_run()
+ end
+ for _, action in next, start_actions do
+ action()
+ end
+end
+
+function main.stop()
+ for _, action in next, stop_actions do
+ action()
+ end
+ if main.show_job_stat then
+ statistics.show(logs.report_job_stat)
+ end
+ if main.show_tex_stat then
+ for k,v in next, status.list() do
+ logs.report_tex_stat(k,v)
+ end
+ end
+ if logs.stop_run then
+ logs.stop_run()
+ end
+end
+
+function main.start_shipout_page()
+ logs.start_page_number()
+end
+
+function main.stop_shipout_page()
+ logs.stop_page_number()
+end
+
+function main.report_output_pages()
+end
+
+function main.report_output_log()
+end
+
+-- this can be done later
+
+callback.register('start_run', main.start)
+callback.register('stop_run' , main.stop)
+callback.register('report_output_pages', main.report_output_pages)
+callback.register('report_output_log' , main.report_output_log)
+callback.register('start_page_number' , main.start_shipout_page)
+callback.register('stop_page_number' , main.stop_shipout_page)
diff --git a/tex/context/base/luat-soc.lua b/tex/context/base/luat-soc.lua
new file mode 100644
index 000000000..1095ed087
--- /dev/null
+++ b/tex/context/base/luat-soc.lua
@@ -0,0 +1,11 @@
+-- This is just a loader. The package handler knows about the TEX tree.
+
+--~ require "luatex/lua/socket.lua"
+--~ require "luatex/lua/ltn12.lua"
+--~ require "luatex/lua/mime.lua"
+--~ require "luatex/lua/socket/http.lua"
+--~ require "luatex/lua/socket/url.lua"
+--~ require "luatex/lua/socket/tp.lua"
+--~ require "luatex/lua/socket/ftp.lua"
+
+-- "luatex/lua/socket/smtp.lua"
diff --git a/tex/context/base/luat-sta.lua b/tex/context/base/luat-sta.lua
index 15581222c..12fa18219 100644
--- a/tex/context/base/luat-sta.lua
+++ b/tex/context/base/luat-sta.lua
@@ -5,6 +5,8 @@ if not modules then modules = { } end modules ['luat-sta'] = {
license = "see context related readme files"
}
+-- this code is used in the updater
+
states = states or { }
states.data = states.data or { }
states.hash = states.hash or { }
@@ -31,27 +33,32 @@ end
function states.set_by_tag(tag,key,value,default,persistent)
local d, h = states.data[tag], states.hash[tag]
if d then
- local dkey, hkey = key, key
- local pre, post = key:match("(.+)%.([^%.]+)$")
- if pre and post then
- for k in pre:gmatch("[^%.]+") do
- local dk = d[k]
- if not dk then
- dk = { }
- d[k] = dk
+ if type(d) == "table" then
+ local dkey, hkey = key, key
+ local pre, post = key:match("(.+)%.([^%.]+)$")
+ if pre and post then
+ for k in pre:gmatch("[^%.]+") do
+ local dk = d[k]
+ if not dk then
+ dk = { }
+ d[k] = dk
+ end
+ d = dk
end
- d = dk
+ dkey, hkey = post, key
end
- dkey, hkey = post, key
- end
- if type(value) == nil then
- value = value or default
- elseif persistent then
- value = value or d[dkey] or default
- else
- value = value or default
+ if type(value) == nil then
+ value = value or default
+ elseif persistent then
+ value = value or d[dkey] or default
+ else
+ value = value or default
+ end
+ d[dkey], h[hkey] = value, value
+ elseif type(d) == "string" then
+ -- weird
+ states.data[tag], states.hash[tag] = value, value
end
- d[dkey], h[hkey] = value, value
end
end
@@ -171,7 +178,6 @@ end
--~ },
--~ }
-
--~ states.save("teststate", "update")
--~ states.load("teststate", "update")
diff --git a/tex/context/base/luat-sto.lua b/tex/context/base/luat-sto.lua
new file mode 100644
index 000000000..10de76b28
--- /dev/null
+++ b/tex/context/base/luat-sto.lua
@@ -0,0 +1,134 @@
+if not modules then modules = { } end modules ['luat-sto'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type, next = type, next
+local gmatch, format, write_nl = string.gmatch, string.format, texio.write_nl
+
+storage = storage or { }
+storage.min = 0 -- 500
+storage.max = storage.min - 1
+storage.noftables = storage.noftables or 0
+storage.nofmodules = storage.nofmodules or 0
+storage.data = { }
+storage.evaluators = { }
+
+local evaluators = storage.evaluators -- (evaluate,message,names)
+local data = storage.data
+
+function storage.register(...)
+ data[#data+1] = { ... }
+end
+
+-- evaluators .. messy .. to be redone
+
+function storage.evaluate(name)
+ evaluators[#evaluators+1] = name
+end
+
+function storage.finalize() -- we can prepend the string with "evaluate:"
+ for i=1,#evaluators do
+ local t = evaluators[i]
+ for i, v in next, t do
+ local tv = type(v)
+ if tv == "string" then
+ t[i] = loadstring(v)()
+ elseif tv == "table" then
+ for _, vv in next, v do
+ if type(vv) == "string" then
+ t[i] = loadstring(vv)()
+ end
+ end
+ elseif tv == "function" then
+ t[i] = v()
+ end
+ end
+ end
+end
+
+function storage.dump()
+ for i=1,#data do
+ local d = data[i]
+ local message, original, target, evaluate = d[1], d[2] ,d[3] ,d[4]
+ local name, initialize, finalize, code = nil, "", "", ""
+ for str in gmatch(target,"([^%.]+)") do
+ if name then
+ name = name .. "." .. str
+ else
+ name = str
+ end
+ initialize = format("%s %s = %s or {} ", initialize, name, name)
+ end
+ if evaluate then
+ finalize = "storage.evaluate(" .. name .. ")"
+ end
+ storage.max = storage.max + 1
+ if trace_storage then
+ logs.report('storage','saving %s in slot %s',message,storage.max)
+ code =
+ initialize ..
+ format("logs.report('storage','restoring %s from slot %s') ",message,storage.max) ..
+ table.serialize(original,name) ..
+ finalize
+ else
+ code = initialize .. table.serialize(original,name) .. finalize
+ end
+ lua.bytecode[storage.max] = loadstring(code)
+ end
+end
+
+-- we also need to count at generation time (nicer for message)
+
+if lua.bytecode then -- from 0 upwards
+ local i, b = storage.min, lua.bytecode
+ while b[i] do
+ storage.noftables = i
+ b[i]()
+ b[i] = nil
+ i = i + 1
+ end
+end
+
+statistics.register("stored bytecode data", function()
+ local modules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - 500)
+ local dumps = (storage.noftables > 0 and storage.noftables) or storage.max-storage.min + 1
+ return format("%s modules, %s tables, %s chunks",modules,dumps,modules+dumps)
+end)
+
+if lua.bytedata then
+ storage.register("lua/bytedata",lua.bytedata,"lua.bytedata")
+end
+
+-- wrong place, kind of forward reference
+
+function statistics.report_storage(whereto)
+ whereto = whereto or "term and log"
+ write_nl(whereto," ","stored tables:"," ")
+ for k,v in table.sortedpairs(storage.data) do
+ write_nl(whereto,format("%03i %s",k,v[1]))
+ end
+ write_nl(whereto," ","stored modules:"," ")
+ for k,v in table.sortedpairs(lua.bytedata) do
+ write_nl(whereto,format("%03i %s %s",k,v[2],v[1]))
+ end
+ write_nl(whereto," ","stored attributes:"," ")
+ for k,v in table.sortedpairs(attributes.names) do
+ write_nl(whereto,format("%03i %s",k,v))
+ end
+ write_nl(whereto," ","stored catcodetables:"," ")
+ for k,v in table.sortedpairs(catcodes.names) do
+ write_nl(whereto,format("%03i %s",k,v))
+ end
+ write_nl(whereto," ")
+end
+
+storage.shared = storage.shared or { }
+
+-- Because the storage mechanism assumes tables, we define a table for storing
+-- (non table) values.
+
+storage.register("storage/shared", storage.shared, "storage.shared")
diff --git a/tex/context/base/luat-tex.lua b/tex/context/base/luat-tex.lua
deleted file mode 100644
index 8560c528d..000000000
--- a/tex/context/base/luat-tex.lua
+++ /dev/null
@@ -1,588 +0,0 @@
--- filename : luat-zip.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-tex'] = 1.001
-
--- special functions that deal with io
-
-local format = string.format
-
-if texconfig and not texlua then
-
- input.level = input.level or 0
-
- if input.logmode() == 'xml' then
- function input.show_open(name)
- input.level = input.level + 1
- texio.write_nl("")
- end
- function input.show_close(name)
- texio.write(" ")
- input.level = input.level - 1
- end
- function input.show_load(name)
- texio.write_nl("") -- level?
- end
- else
- function input.show_open () end
- function input.show_close() end
- function input.show_load () end
- end
-
- function input.finders.generic(tag,filename,filetype)
- local foundname = input.find_file(filename,filetype)
- if foundname and foundname ~= "" then
- if input.trace > 0 then
- input.logger('+ finder: %s, file: %s', tag,filename)
- end
- return foundname
- else
- if input.trace > 0 then
- input.logger('- finder: %s, file: %s', tag,filename)
- end
- return unpack(input.finders.notfound)
- end
- end
-
- input.filters.dynamic_translator = nil
- input.filters.frozen_translator = nil -- not used here
- input.filters.utf_translator = nil
- input.filters.user_translator = nil
-
- function input.openers.text_opener(filename,file_handle,tag)
- local u = unicode.utftype(file_handle)
- local t = { }
- if u > 0 then
- if input.trace > 0 then
- input.logger('+ opener: %s (%s), file: %s',tag,unicode.utfname[u],filename)
- end
- local l
- if u > 2 then
- l = unicode.utf32_to_utf8(file_handle:read("*a"),u==4)
- else
- l = unicode.utf16_to_utf8(file_handle:read("*a"),u==2)
- end
- file_handle:close()
- t = {
- utftype = u, -- may go away
- lines = l,
- current = 0, -- line number, not really needed
- handle = nil,
- noflines = #l,
- close = function()
- if input.trace > 0 then
- input.logger('= closer: %s (%s), file: %s',tag,unicode.utfname[u],filename)
- end
- input.show_close(filename)
- t = nil
- end,
---~ getline = function(n)
---~ local line = t.lines[n]
---~ if not line or line == "" then
---~ return ""
---~ else
---~ local translator = input.filters.utf_translator
---~ return (translator and translator(line)) or line
---~ end
---~ end,
- reader = function(self)
- self = self or t
- local current, lines = self.current, self.lines
- if current >= #lines then
- return nil
- else
- current = current + 1
- self.current = current
- local line = lines[current]
- if not line then
- return nil
- elseif line == "" then
- return ""
- else
- translator = filters.utf_translator
- if translator then
- line = translator(line)
- translator = filters.user_translator
- if translator then
- line = translator(line)
- end
- end
- return line
- end
- end
- end
- }
- else
- if input.trace > 0 then
- input.logger('+ opener: %s, file: %s',tag,filename)
- end
- -- todo: file;name -> freeze / eerste regel scannen -> freeze
- local filters = input.filters
- t = {
- reader = function(self)
- local line = file_handle:read()
- if not line then
- return nil
- elseif line == "" then
- return ""
- else
- translator = filters.dynamic_translator or filters.utf_translator
- if translator then
- line = translator(line)
- translator = filters.user_translator
- if translator then
- line = translator(line)
- end
- end
- return line
- end
- end,
- close = function()
- if input.trace > 0 then
- input.logger('= closer: %s, file: %s',tag,filename)
- end
- input.show_close(filename)
- file_handle:close()
- t = nil
- end,
- handle = function()
- return file_handle
- end,
- noflines = function()
- t.noflines = io.noflines(file_handle)
- return t.noflines
- end
- }
- end
- return t
- end
-
- function input.openers.generic(tag,filename)
- if filename and filename ~= "" then
- local f = io.open(filename,"r")
- if f then
- input.show_open(filename)
- return input.openers.text_opener(filename,f,tag)
- end
- end
- if input.trace > 0 then
- input.logger('- opener: %s, file: %s',tag,filename)
- end
- return unpack(input.openers.notfound)
- end
-
- function input.loaders.generic(tag,filename)
- if filename and filename ~= "" then
- local f = io.open(filename,"rb")
- if f then
- input.show_load(filename)
- if input.trace > 0 then
- input.logger('+ loader: %s, file: %s',tag,filename)
- end
- local s = f:read("*a")
- if garbagecollector and garbagecollector.check then garbagecollector.check(#s) end
- f:close()
- if s then
- return true, s, #s
- end
- end
- end
- if input.trace > 0 then
- input.logger('- loader: %s, file: %s',tag,filename)
- end
- return unpack(input.loaders.notfound)
- end
-
- function input.finders.tex(filename,filetype)
- return input.finders.generic('tex',filename,filetype)
- end
- function input.openers.tex(filename)
- return input.openers.generic('tex',filename)
- end
- function input.loaders.tex(filename)
- return input.loaders.generic('tex',filename)
- end
-
-end
-
--- callback into the file io and related things; disabling kpse
-
-
-if texconfig and not texlua then do
-
- -- this is not the right place, because we refer to quite some not yet defined tables, but who cares ...
-
- ctx = ctx or { }
-
- function ctx.writestatus(a,b,c,...)
- if c then
- texio.write_nl(("%-15s: %s\n"):format(a,b:format(c,...)))
- else
- texio.write_nl(("%-15s: %s\n"):format(a,b)) -- b can have %'s
- end
- end
-
- -- this will become: ctx.install_statistics(fnc() return ..,.. end) etc
-
- local statusinfo, n = { }, 0
-
- function ctx.register_statistics(tag,pattern,fnc)
- statusinfo[#statusinfo+1] = { tag, pattern, fnc }
- if #tag > n then n = #tag end
- end
-
- function ctx.memused() -- no math.round yet -)
- -- collectgarbage("collect")
- local round = math.round or math.floor
- return string.format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
- end
-
- function ctx.show_statistics() -- todo: move calls
- local loadtime, register_statistics = input.loadtime, ctx.register_statistics
- if caches then
- register_statistics("used config path", "%s", function() return caches.configpath() end)
- register_statistics("used cache path", "%s", function() return caches.temp() or "?" end)
- end
- if status.luabytecodes > 0 and input.storage and input.storage.done then
- register_statistics("modules/dumps/instances", "%s/%s/%s", function() return status.luabytecodes-500, input.storage.done, status.luastates end)
- end
- if input.instance then
- register_statistics("input load time", "%s seconds", function() return loadtime(input.instance) end)
- end
- if ctx and input.hastimer(ctx) then
- register_statistics("startup time","%s seconds (including runtime option file processing)", function() return loadtime(ctx) end)
- end
- if job then
- register_statistics("jobdata time","%s seconds saving, %s seconds loading", function() return loadtime(job._save_), loadtime(job._load_) end)
- end
- if fonts then
- register_statistics("fonts load time","%s seconds", function() return loadtime(fonts) end)
- end
- if xml then
- register_statistics("xml load time", "%s seconds, lpath calls: %s, cached calls: %s", function()
- local stats = xml.statistics()
- return loadtime(xml), stats.lpathcalls, stats.lpathcached
- end)
- register_statistics("lxml load time", "%s seconds preparation, backreferences: %i", function()
- return loadtime(lxml), #lxml.self
- end)
- end
- if mptopdf then
- register_statistics("mps conversion time", "%s seconds", function() return loadtime(mptopdf) end)
- end
- if nodes then
- register_statistics("node processing time", "%s seconds including kernel", function() return loadtime(nodes) end)
- end
- if kernel then
- register_statistics("kernel processing time", "%s seconds", function() return loadtime(kernel) end)
- end
- if attributes then
- register_statistics("attribute processing time", "%s seconds", function() return loadtime(attributes) end)
- end
- if languages then
- register_statistics("language load time", "%s seconds, n=%s", function() return loadtime(languages), languages.hyphenation.n() end)
- end
- if figures then
- register_statistics("graphics processing time", "%s seconds including tex, n=%s", function() return loadtime(figures), figures.n or "?" end)
- end
- if metapost then
- register_statistics("metapost processing time", "%s seconds, loading: %s seconds, execution: %s seconds, n: %s", function() return loadtime(metapost), loadtime(mplib), loadtime(metapost.exectime), metapost.n end)
- end
- if status.luastate_bytes and ctx.memused then
- register_statistics("current memory usage", "%s", ctx.memused)
- end
- if nodes then
- register_statistics("cleaned up reserved nodes", "%s nodes, %s lists of %s", function() return nodes.cleanup_reserved(tex.count[24]) end) -- \topofboxstack
- end
- if status.node_mem_usage then
- register_statistics("node memory usage", "%s", function() return status.node_mem_usage end)
- end
- if languages then
- register_statistics("loaded patterns", "%s", function() return languages.logger.report() end)
- end
- if fonts then
- register_statistics("loaded fonts", "%s", function() return fonts.logger.report() end)
- end
- if status.cs_count then
- register_statistics("control sequences", "%s of %s", function() return status.cs_count, status.hash_size+status.hash_extra end)
- end
- if status.callbacks and xml then -- xml for being in context -)
- ctx.register_statistics("callbacks", "direct: %s, indirect: %s, total: %s%s", function()
- local total, indirect = status.callbacks, status.indirect_callbacks
- local pages = tex.count['realpageno'] - 1
- if pages > 1 then
- return total-indirect, indirect, total, format(" (%i per page)",total/pages)
- else
- return total-indirect, indirect, total, ""
- end
- end)
- else
- ctx.register_statistics("callbacks", "direct: %s, indirect: %s, total: %s", function()
- local total, indirect = status.callbacks, status.indirect_callbacks
- return total-indirect, indirect, total
- end)
- end
- if xml then -- so we are in mkiv, we need a different check
- register_statistics("runtime", "%s seconds, %i processed pages, %i shipped pages, %.3f pages/second", function()
- input.stoptiming(input.instance)
- local runtime = loadtime(input.instance)
- local shipped = tex.count['nofshipouts']
- local pages = tex.count['realpageno'] - 1
- local persecond = shipped / runtime
- return runtime, pages, shipped, persecond
- end)
- end
- for _, t in ipairs(statusinfo) do
- local tag, pattern, fnc = t[1], t[2], t[3]
- ctx.writestatus("mkiv lua stats", "%s - %s", tag:rpadd(n," "), pattern:format(fnc()))
- end-- input.expanded_path_list("osfontdir")
- end
-
-end end
-
-if texconfig and not texlua then
-
- texconfig.kpse_init = false
- texconfig.trace_file_names = input.logmode() == 'tex'
- texconfig.max_print_line = 100000
-
- -- if still present, we overload kpse (put it off-line so to say)
-
- input.starttiming(input.instance)
-
- if not input.instance then
-
- if not input.instance then -- prevent a second loading
-
- input.instance = input.reset()
- input.instance.progname = 'context'
- input.instance.engine = 'luatex'
- input.instance.validfile = input.validctxfile
-
- input.load()
-
- end
-
- if callback then
- callback.register('find_read_file' , function(id,name) return input.findtexfile(name) end)
- callback.register('open_read_file' , function( name) return input.opentexfile(name) end)
- end
-
- if callback then
- callback.register('find_data_file' , function(name) return input.findbinfile(name,"tex") end)
- callback.register('find_enc_file' , function(name) return input.findbinfile(name,"enc") end)
- callback.register('find_font_file' , function(name) return input.findbinfile(name,"tfm") end)
- callback.register('find_format_file' , function(name) return input.findbinfile(name,"fmt") end)
- callback.register('find_image_file' , function(name) return input.findbinfile(name,"tex") end)
- callback.register('find_map_file' , function(name) return input.findbinfile(name,"map") end)
- callback.register('find_ocp_file' , function(name) return input.findbinfile(name,"ocp") end)
- callback.register('find_opentype_file' , function(name) return input.findbinfile(name,"otf") end)
- callback.register('find_output_file' , function(name) return name end)
- callback.register('find_pk_file' , function(name) return input.findbinfile(name,"pk") end)
- callback.register('find_sfd_file' , function(name) return input.findbinfile(name,"sfd") end)
- callback.register('find_truetype_file' , function(name) return input.findbinfile(name,"ttf") end)
- callback.register('find_type1_file' , function(name) return input.findbinfile(name,"pfb") end)
- callback.register('find_vf_file' , function(name) return input.findbinfile(name,"vf") end)
-
- callback.register('read_data_file' , function(file) return input.loadbinfile(file,"tex") end)
- callback.register('read_enc_file' , function(file) return input.loadbinfile(file,"enc") end)
- callback.register('read_font_file' , function(file) return input.loadbinfile(file,"tfm") end)
- -- format
- -- image
- callback.register('read_map_file' , function(file) return input.loadbinfile(file,"map") end)
- callback.register('read_ocp_file' , function(file) return input.loadbinfile(file,"ocp") end)
---~ callback.register('read_opentype_file' , function(file) return input.loadbinfile(file,"otf") end)
- -- output
- callback.register('read_pk_file' , function(file) return input.loadbinfile(file,"pk") end)
- callback.register('read_sfd_file' , function(file) return input.loadbinfile(file,"sfd") end)
---~ callback.register('read_truetype_file' , function(file) return input.loadbinfile(file,"ttf") end)
---~ callback.register('read_type1_file' , function(file) return input.loadbinfile(file,"pfb") end)
- callback.register('read_vf_file' , function(file) return input.loadbinfile(file,"vf" ) end)
- end
-
- if input.aleph_mode == nil then environment.aleph_mode = true end -- some day we will drop omega font support
-
- if callback and input.aleph_mode then
- callback.register('find_font_file' , function(name) return input.findbinfile(name,"ofm") end)
- callback.register('read_font_file' , function(file) return input.loadbinfile(file,"ofm") end)
- callback.register('find_vf_file' , function(name) return input.findbinfile(name,"ovf") end)
- callback.register('read_vf_file' , function(file) return input.loadbinfile(file,"ovf") end)
- end
-
- if callback then
- callback.register('find_write_file' , function(id,name) return name end)
- end
-
- if callback and (not config or (#config == 0)) then
- callback.register('find_format_file' , function(name) return name end)
- end
-
- if callback and false then
- for k, v in pairs(callback.list()) do
- if not v then texio.write_nl("callback "..k.." is not set") end
- end
- end
-
- if callback then
-
- input.start_actions = { }
- input.stop_actions = { }
-
- function input.register_start_actions(f) table.insert(input.start_actions, f) end
- function input.register_stop_actions (f) table.insert(input.stop_actions, f) end
-
- --~ callback.register('start_run', function() for _, a in pairs(input.start_actions) do a() end end)
- --~ callback.register('stop_run' , function() for _, a in pairs(input.stop_actions ) do a() end end)
-
- end
-
- if callback then
-
- if input.logmode() == 'xml' then
-
- function input.start_page_number()
- texio.write_nl("")
- texio.write_nl("")
- end
-
- callback.register('start_page_number' , input.start_page_number)
- callback.register('stop_page_number' , input.stop_page_number )
-
- function input.report_output_pages(p,b)
- texio.write_nl(""..p.."")
- texio.write_nl(""..b.."")
- texio.write_nl("")
- end
- function input.report_output_log()
- end
-
- callback.register('report_output_pages', input.report_output_pages)
- callback.register('report_output_log' , input.report_output_log )
-
- function input.start_run()
- texio.write_nl("")
- texio.write_nl("")
- texio.write_nl("")
- end
- function input.stop_run()
- texio.write_nl("")
- end
- function input.show_statistics()
- for k,v in pairs(status.list()) do
- texio.write_nl("log",""..tostring(v).."")
- end
- end
-
- table.insert(input.start_actions, input.start_run)
- table.insert(input.stop_actions , input.show_statistics)
- table.insert(input.stop_actions , input.stop_run)
-
- else
- table.insert(input.stop_actions , input.show_statistics)
- end
-
- callback.register('start_run', function() for _, a in pairs(input.start_actions) do a() end end)
- callback.register('stop_run' , function() for _, a in pairs(input.stop_actions ) do a() end ctx.show_statistics() end)
-
- end
-
- end
-
- if kpse then
-
- function kpse.find_file(filename,filetype,mustexist)
- return input.find_file(filename,filetype,mustexist)
- end
- function kpse.expand_path(variable)
- return input.expand_path(variable)
- end
- function kpse.expand_var(variable)
- return input.expand_var(variable)
- end
- function kpse.expand_braces(variable)
- return input.expand_braces(variable)
- end
-
- end
-
-end
-
--- program specific configuration (memory settings and alike)
-
-if texconfig and not texlua then
-
- luatex = luatex or { }
-
- luatex.variablenames = {
- 'main_memory', 'extra_mem_bot', 'extra_mem_top',
- 'buf_size','expand_depth',
- 'font_max', 'font_mem_size',
- 'hash_extra', 'max_strings', 'pool_free', 'pool_size', 'string_vacancies',
- 'obj_tab_size', 'pdf_mem_size', 'dest_names_size',
- 'nest_size', 'param_size', 'save_size', 'stack_size',
- 'trie_size', 'hyph_size', 'max_in_open',
- 'ocp_stack_size', 'ocp_list_size', 'ocp_buf_size'
- }
-
- function luatex.variables()
- local t, x = { }, nil
- for _,v in pairs(luatex.variablenames) do
- x = input.var_value(v)
- if x and x:find("^%d+$") then
- t[v] = tonumber(x)
- end
- end
- return t
- end
-
- function luatex.setvariables(tab)
- for k,v in pairs(luatex.variables()) do
- tab[k] = v
- end
- end
-
- if not luatex.variables_set then
- luatex.setvariables(texconfig)
- luatex.variables_set = true
- end
-
- texconfig.max_print_line = 100000
- texconfig.max_in_open = 127
-
-end
-
--- some tex basics, maybe this will move to ctx
-
-if tex then
-
- local texsprint, texwrite = tex.sprint, tex.write
-
- if not cs then cs = { } end
-
- function cs.def(k,v)
- texsprint(tex.texcatcodes, "\\def\\" .. k .. "{" .. v .. "}")
- end
-
- function cs.chardef(k,v)
- texsprint(tex.texcatcodes, "\\chardef\\" .. k .. "=" .. v .. "\\relax")
- end
-
- function cs.boolcase(b)
- if b then texwrite(1) else texwrite(0) end
- end
-
- function cs.testcase(b)
- if b then
- texsprint(tex.texcatcodes, "\\firstoftwoarguments")
- else
- texsprint(tex.texcatcodes, "\\secondoftwoarguments")
- end
- end
-
-end
diff --git a/tex/context/base/luat-tmp.lua b/tex/context/base/luat-tmp.lua
deleted file mode 100644
index 1e3f55380..000000000
--- a/tex/context/base/luat-tmp.lua
+++ /dev/null
@@ -1,433 +0,0 @@
-if not modules then modules = { } end modules ['luat-tmp'] = {
- version = 1.001,
- comment = "companion to luat-lib.tex",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
---[[ldx--
-
This module deals with caching data. It sets up the paths and
-implements loaders and savers for tables. Best is to set the
-following variable. When not set, the usual paths will be
-checked. Personally I prefer the (users) temporary path.
Currently we do no locking when we write files. This is no real
-problem because most caching involves fonts and the chance of them
-being written at the same time is small. We also need to extend
-luatools with a recache feature.
---ldx]]--
-
-local format = string.format
-
-caches = caches or { }
-dir = dir or { }
-texmf = texmf or { }
-
-caches.path = caches.path or nil
-caches.base = caches.base or "luatex-cache"
-caches.more = caches.more or "context"
-caches.direct = false -- true is faster but may need huge amounts of memory
-caches.trace = false
-caches.tree = false
-caches.paths = caches.paths or nil
-caches.force = false
-caches.defaults = { "TEXMFCACHE", "TMPDIR", "TEMPDIR", "TMP", "TEMP", "HOME", "HOMEPATH" }
-
-function caches.temp()
- local cachepath = nil
- local function check(list,isenv)
- if not cachepath then
- for _, v in ipairs(list) do
- cachepath = (isenv and (os.env[v] or "")) or v or ""
- if cachepath == "" then
- -- next
- else
- cachepath = input.clean_path(cachepath)
- if lfs.isdir(cachepath) and file.iswritable(cachepath) then -- lfs.attributes(cachepath,"mode") == "directory"
- break
- elseif caches.force or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
- dir.mkdirs(cachepath)
- if lfs.isdir(cachepath) and file.iswritable(cachepath) then
- break
- end
- end
- end
- cachepath = nil
- end
- end
- end
- check(input.clean_path_list("TEXMFCACHE") or { })
- check(caches.defaults,true)
- if not cachepath then
- print("\nfatal error: there is no valid (writable) cache path defined\n")
- os.exit()
- elseif not lfs.isdir(cachepath) then -- lfs.attributes(cachepath,"mode") ~= "directory"
- print(format("\nfatal error: cache path %s is not a directory\n",cachepath))
- os.exit()
- end
- cachepath = input.normalize_name(cachepath)
- function caches.temp()
- return cachepath
- end
- return cachepath
-end
-
-function caches.configpath()
- return table.concat(input.instance.cnffiles,";")
-end
-
-function caches.hashed(tree)
- return md5.hex((tree:lower()):gsub("[\\\/]+","/"))
-end
-
---~ tracing:
-
---~ function caches.hashed(tree)
---~ tree = (tree:lower()):gsub("[\\\/]+","/")
---~ local hash = md5.hex(tree)
---~ if input.verbose then -- temp message
---~ input.report("hashing %s => %s",tree,hash)
---~ end
---~ return hash
---~ end
-
-function caches.treehash()
- local tree = caches.configpath()
- if not tree or tree == "" then
- return false
- else
- return caches.hashed(tree)
- end
-end
-
-function caches.setpath(...)
- if not caches.path then
- if not caches.path then
- caches.path = caches.temp()
- end
- caches.path = input.clean_path(caches.path) -- to be sure
- if lfs then
- caches.tree = caches.tree or caches.treehash()
- if caches.tree then
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more,caches.tree)
- else
- caches.path = dir.mkdirs(caches.path,caches.base,caches.more)
- end
- end
- end
- if not caches.path then
- caches.path = '.'
- end
- caches.path = input.clean_path(caches.path)
- if lfs and not table.is_empty({...}) then
- local pth = dir.mkdirs(caches.path,...)
- return pth
- end
- caches.path = dir.expand_name(caches.path)
- return caches.path
-end
-
-function caches.definepath(category,subcategory)
- return function()
- return caches.setpath(category,subcategory)
- end
-end
-
-function caches.setluanames(path,name)
- return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
-end
-
-function caches.loaddata(path,name)
- local tmaname, tmcname = caches.setluanames(path,name)
- local loader = loadfile(tmcname) or loadfile(tmaname)
- if loader then
- return loader()
- else
- return false
- end
-end
-
-function caches.is_writable(filepath,filename)
- local tmaname, tmcname = caches.setluanames(filepath,filename)
- return file.is_writable(tmaname)
-end
-
-function caches.savedata(filepath,filename,data,raw)
- local tmaname, tmcname = caches.setluanames(filepath,filename)
- local reduce, simplify = true, true
- if raw then
- reduce, simplify = false, false
- end
- if caches.direct then
- file.savedata(tmaname, table.serialize(data,'return',true,true,false)) -- no hex
- else
- table.tofile(tmaname, data,'return',true,true,false) -- maybe not the last true
- end
- local cleanup = input.boolean_variable("PURGECACHE", false)
- local strip = input.boolean_variable("LUACSTRIP", true)
- utils.lua.compile(tmaname, tmcname, cleanup, strip)
-end
-
--- here we use the cache for format loading (texconfig.[formatname|jobname])
-
---~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then
-if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and input and input.instance then
- if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc
- texconfig.formatname = caches.setpath("formats") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt")
-end
-
---[[ldx--
-
Once we found ourselves defining similar cache constructs
-several times, containers were introduced. Containers are used
-to collect tables in memory and reuse them when possible based
-on (unique) hashes (to be provided by the calling function).
-
-
Caching to disk is disabled by default. Version numbers are
-stored in the saved table which makes it possible to change the
-table structures without bothering about the disk cache.
-
-
Examples of usage can be found in the font related code.
---ldx]]--
-
-containers = { }
-containers.trace = false
-
-do -- local report
-
- local function report(container,tag,name)
- if caches.trace or containers.trace or container.trace then
- logs.report(format("%s cache",container.subcategory),"%s: %s",tag,name or 'invalid')
- end
- end
-
- local allocated = { }
-
- -- tracing
-
- function containers.define(category, subcategory, version, enabled)
- return function()
- if category and subcategory then
- local c = allocated[category]
- if not c then
- c = { }
- allocated[category] = c
- end
- local s = c[subcategory]
- if not s then
- s = {
- category = category,
- subcategory = subcategory,
- storage = { },
- enabled = enabled,
- version = version or 1.000,
- trace = false,
- path = caches.setpath(category,subcategory),
- }
- c[subcategory] = s
- end
- return s
- else
- return nil
- end
- end
- end
-
- function containers.is_usable(container, name)
- return container.enabled and caches.is_writable(container.path, name)
- end
-
- function containers.is_valid(container, name)
- if name and name ~= "" then
- local storage = container.storage[name]
- return storage and not table.is_empty(storage) and storage.cache_version == container.version
- else
- return false
- end
- end
-
- function containers.read(container,name)
- if container.enabled and not container.storage[name] then
- container.storage[name] = caches.loaddata(container.path,name)
- if containers.is_valid(container,name) then
- report(container,"loaded",name)
- else
- container.storage[name] = nil
- end
- end
- if container.storage[name] then
- report(container,"reusing",name)
- end
- return container.storage[name]
- end
-
- function containers.write(container, name, data)
- if data then
- data.cache_version = container.version
- if container.enabled then
- local unique, shared = data.unique, data.shared
- data.unique, data.shared = nil, nil
- caches.savedata(container.path, name, data)
- report(container,"saved",name)
- data.unique, data.shared = unique, shared
- end
- report(container,"stored",name)
- container.storage[name] = data
- end
- return data
- end
-
- function containers.content(container,name)
- return container.storage[name]
- end
-
-end
-
--- since we want to use the cache instead of the tree, we will now
--- reimplement the saver.
-
-local save_data = input.aux.save_data
-local load_data = input.aux.load_data
-
-input.cachepath = nil -- public, for tracing
-input.usecache = true -- public, for tracing
-
-function input.aux.save_data(dataname, check)
- save_data(dataname, check, function(cachename,dataname)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(cachename))
- else
- return file.join(cachename,dataname)
- end
- end)
-end
-
-function input.aux.load_data(pathname,dataname,filename)
- load_data(pathname,dataname,filename,function(dataname,filename)
- input.usecache = not toboolean(input.expansion("CACHEINTDS") or "false",true)
- if input.usecache then
- input.cachepath = input.cachepath or caches.definepath("trees")
- return file.join(input.cachepath(),caches.hashed(pathname))
- else
- if not filename or (filename == "") then
- filename = dataname
- end
- return file.join(pathname,filename)
- end
- end)
-end
-
--- we will make a better format, maybe something xml or just text or lua
-
-input.automounted = input.automounted or { }
-
-function input.automount(usecache)
- local mountpaths = input.clean_path_list(input.expansion('TEXMFMOUNT'))
- if table.is_empty(mountpaths) and usecache then
- mountpaths = { caches.setpath("mount") }
- end
- if not table.is_empty(mountpaths) then
- input.starttiming(input.instance)
- for k, root in pairs(mountpaths) do
- local f = io.open(root.."/url.tmi")
- if f then
- for line in f:lines() do
- if line then
- if line:find("^[%%#%-]") then -- or %W
- -- skip
- elseif line:find("^zip://") then
- input.report("mounting %s",line)
- table.insert(input.automounted,line)
- input.usezipfile(line)
- end
- end
- end
- f:close()
- end
- end
- input.stoptiming(input.instance)
- end
-end
-
--- store info in format
-
-input.storage = { }
-input.storage.data = { }
-input.storage.min = 0 -- 500
-input.storage.max = input.storage.min - 1
-input.storage.trace = false -- true
-input.storage.done = input.storage.done or 0
-input.storage.evaluators = { }
--- (evaluate,message,names)
-
-function input.storage.register(...)
- input.storage.data[#input.storage.data+1] = { ... }
-end
-
-function input.storage.evaluate(name)
- input.storage.evaluators[#input.storage.evaluators+1] = name
-end
-
-function input.storage.finalize() -- we can prepend the string with "evaluate:"
- for _, t in ipairs(input.storage.evaluators) do
- for i, v in pairs(t) do
- if type(v) == "string" then
- t[i] = loadstring(v)()
- elseif type(v) == "table" then
- for _, vv in pairs(v) do
- if type(vv) == "string" then
- t[i] = loadstring(vv)()
- end
- end
- end
- end
- end
-end
-
-function input.storage.dump()
- for name, data in ipairs(input.storage.data) do
- local evaluate, message, original, target = data[1], data[2], data[3] ,data[4]
- local name, initialize, finalize, code = nil, "", "", ""
- for str in target:gmatch("([^%.]+)") do
- if name then
- name = name .. "." .. str
- else
- name = str
- end
- initialize = format("%s %s = %s or {} ", initialize, name, name)
- end
- if evaluate then
- finalize = "input.storage.evaluate(" .. name .. ")"
- end
- input.storage.max = input.storage.max + 1
- if input.storage.trace then
- logs.report('storage','saving %s in slot %s',message,input.storage.max)
- code =
- initialize ..
- format("logs.report('storage','restoring %s from slot %s') ",message,input.storage.max) ..
- table.serialize(original,name) ..
- finalize
- else
- code = initialize .. table.serialize(original,name) .. finalize
- end
- lua.bytecode[input.storage.max] = loadstring(code)
- end
-end
-
--- we also need to count at generation time (nicer for message)
-
-if lua.bytecode then -- from 0 upwards
- local i = input.storage.min
- while lua.bytecode[i] do
- lua.bytecode[i]()
- lua.bytecode[i] = nil
- i = i + 1
- end
- input.storage.done = i
-end
diff --git a/tex/context/base/luat-tra.lua b/tex/context/base/luat-tra.lua
deleted file mode 100644
index 5314b48c6..000000000
--- a/tex/context/base/luat-tra.lua
+++ /dev/null
@@ -1,145 +0,0 @@
--- filename : luat-tra.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
--- the tag is kind of generic and used for functions that are not
--- bound to a variable, like node.new, node.copy etc (contrary to for instance
--- node.has_attribute which is bound to a has_attribute local variable in mkiv)
-
-if not versions then versions = { } end versions['luat-tra'] = 1.001
-
-debugger = { }
-
-local counters = { }
-local names = { }
-local getinfo = debug.getinfo
-local format = string.format
-
--- one
-
-local function hook()
- local f = getinfo(2,"f").func
- local n = getinfo(2,"Sn")
--- if n.what == "C" and n.name then print (n.namewhat .. ': ' .. n.name) end
- if f then
- local cf = counters[f]
- if cf == nil then
- counters[f] = 1
- names[f] = n
- else
- counters[f] = cf + 1
- end
- end
-end
-local function getname(func)
- local n = names[func]
- if n then
- if n.what == "C" then
- return n.name or ''
- else
- -- source short_src linedefined what name namewhat nups func
- local name = n.name or n.namewhat or n.what
- if not name or name == "" then name = "?" end
- return format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name)
- end
- else
- return "unknown"
- end
-end
-function debugger.showstats(printer,threshold)
- printer = printer or texio.write or print
- threshold = threshold or 0
- local total, grandtotal, functions = 0, 0, 0
- printer("\n") -- ugly but ok
- -- table.sort(counters)
- for func, count in pairs(counters) do
- if count > threshold then
- local name = getname(func)
- if not name:find("for generator") then
- printer(format("%8i %s", count, name))
- total = total + count
- end
- end
- grandtotal = grandtotal + count
- functions = functions + 1
- end
- printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
-end
-
--- two
-
---~ local function hook()
---~ local n = getinfo(2)
---~ if n.what=="C" and not n.name then
---~ local f = tostring(debug.traceback())
---~ local cf = counters[f]
---~ if cf == nil then
---~ counters[f] = 1
---~ names[f] = n
---~ else
---~ counters[f] = cf + 1
---~ end
---~ end
---~ end
---~ function debugger.showstats(printer,threshold)
---~ printer = printer or texio.write or print
---~ threshold = threshold or 0
---~ local total, grandtotal, functions = 0, 0, 0
---~ printer("\n") -- ugly but ok
---~ -- table.sort(counters)
---~ for func, count in pairs(counters) do
---~ if count > threshold then
---~ printer(format("%8i %s", count, func))
---~ total = total + count
---~ end
---~ grandtotal = grandtotal + count
---~ functions = functions + 1
---~ end
---~ printer(format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold))
---~ end
-
--- rest
-
-function debugger.savestats(filename,threshold)
- local f = io.open(filename,'w')
- if f then
- debugger.showstats(function(str) f:write(str) end,threshold)
- f:close()
- end
-end
-
-function debugger.enable()
- debug.sethook(hook,"c")
-end
-
-function debugger.disable()
- debug.sethook()
---~ counters[debug.getinfo(2,"f").func] = nil
-end
-
-function debugger.tracing()
- local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0
- if n > 0 then
- function debugger.tracing() return true end ; return true
- else
- function debugger.tracing() return false end ; return false
- end
-end
-
---~ debugger.enable()
-
---~ print(math.sin(1*.5))
---~ print(math.sin(1*.5))
---~ print(math.sin(1*.5))
---~ print(math.sin(1*.5))
---~ print(math.sin(1*.5))
-
---~ debugger.disable()
-
---~ print("")
---~ debugger.showstats()
---~ print("")
---~ debugger.showstats(print,3)
-
diff --git a/tex/context/base/luat-tre.lua b/tex/context/base/luat-tre.lua
deleted file mode 100644
index ed1ff59f8..000000000
--- a/tex/context/base/luat-tre.lua
+++ /dev/null
@@ -1,45 +0,0 @@
--- filename : luat-tre.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-tre'] = 1.001
-
--- \input tree://oeps1/**/oeps.tex
-
-do
-
- local done, found = { }, { }
-
- function input.finders.tree(specification,filetype)
- local fnd = found[specification]
- if not fnd then
- local spec = input.splitmethod(specification).path or ""
- if spec ~= "" then
- local path, name = file.dirname(spec), file.basename(spec)
- if path == "" then path = "." end
- local hash = done[path]
- if not hash then
- local pattern = path .. "/*" -- we will use the proper splitter
- hash = dir.glob(pattern)
- done[path] = hash
- end
- local pattern = "/" .. name:gsub("([%.%-%+])", "%%%1") .. "$"
- for k, v in pairs(hash) do
- if v:find(pattern) then
- found[specification] = v
- return v
- end
- end
- end
- fnd = unpack(input.finders.notfound)
- found[specification] = fnd
- end
- return fnd
- end
-
- input.openers.tree = input.openers.generic
- input.loaders.tree = input.loaders.generic
-
-end
diff --git a/tex/context/base/luat-uni.lua b/tex/context/base/luat-uni.lua
deleted file mode 100644
index ef57663bb..000000000
--- a/tex/context/base/luat-uni.lua
+++ /dev/null
@@ -1,21 +0,0 @@
--- filename : luat-uni.lua
--- comment : companion to luat-uni.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-uni'] = 1.001
-
-function unicode.utf8.split(str)
- local t = { }
- for snippet in str:utfcharacters() do
- t[#t+1] = snippet
- end
- return t
-end
-
-function unicode.utf8.each(str,fnc)
- for snippet in str:utfcharacters() do
- fnc(snippet)
- end
-end
diff --git a/tex/context/base/luat-uni.tex b/tex/context/base/luat-uni.tex
deleted file mode 100644
index 453c8e0d8..000000000
--- a/tex/context/base/luat-uni.tex
+++ /dev/null
@@ -1,33 +0,0 @@
-%D \module
-%D [ file=luat-uni,
-%D version=2006.04.25,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=Unicode Support,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Lua Support Macros (unicode)}
-
-\registerctxluafile{luat-uni}{1.001}
-
-% \defconvertedargument\ascii{ÀÁÂÃÄÅàáâãäå}
-%
-% \lua{ tex.print ("\ascii")}
-% \lua{ tex.print(unicode.utf8.reverse ("\ascii"))}
-% \lua{ tex.print(unicode.utf8.lower ("\ascii"))}
-% \lua{ tex.print(unicode.utf8.upper ("\ascii"))}
-% \lua{ tex.print(unicode.utf8.len ("\ascii"))}
-% \lua{ tex.print(table.getn(unicode.utf8.split("\ascii"))}}
-%
-% \lua{unicode.utf8.each("\ascii", function(chr) tex.print("["..chr.."]") end)}
-
-\let\UnicodeOne \gobbleoneargument
-\let\UnicodeTwo \gobbleoneargument
-\let\UnicodeThree\gobbleoneargument
-
-\endinput
diff --git a/tex/context/base/luat-zip.lua b/tex/context/base/luat-zip.lua
deleted file mode 100644
index 40386e570..000000000
--- a/tex/context/base/luat-zip.lua
+++ /dev/null
@@ -1,249 +0,0 @@
--- filename : luat-zip.lua
--- comment : companion to luat-lib.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
-if not versions then versions = { } end versions['luat-zip'] = 1.001
-
-local format = string.format
-
-if zip and input then
- zip.supported = true
-else
- zip = { }
- zip.supported = false
-end
-
-if not zip.supported then
-
- if not input then input = { } end -- will go away
-
- function zip.openarchive (...) return nil end -- needed ?
- function zip.closenarchive (...) end -- needed ?
- function input.usezipfile (...) end -- needed ?
-
-else
-
- -- zip:///oeps.zip?name=bla/bla.tex
- -- zip:///oeps.zip?tree=tex/texmf-local
-
- local function validzip(str)
- if not str:find("^zip://") then
- return "zip:///" .. str
- else
- return str
- end
- end
-
- zip.archives = { }
- zip.registeredfiles = { }
-
- function zip.openarchive(name)
- if not name or name == "" then
- return nil
- else
- local arch = zip.archives[name]
- if arch then
- return arch
- else
- local full = input.find_file(name) or ""
- local arch = (full ~= "" and zip.open(full)) or false
- zip.archives[name] = arch
- return arch
- end
- end
- end
-
- function zip.closearchive(name)
- if not name or name == "" and zip.archives[name] then
- zip.close(zip.archives[name])
- zip.archives[name] = nil
- end
- end
-
- -- zip:///texmf.zip?tree=/tex/texmf
- -- zip:///texmf.zip?tree=/tex/texmf-local
- -- zip:///texmf-mine.zip?tree=/tex/texmf-projects
-
- function input.locators.zip(specification) -- where is this used? startup zips (untested)
- specification = input.splitmethod(specification)
- local zipfile = specification.path
- local zfile = zip.openarchive(name) -- tricky, could be in to be initialized tree
- if input.trace > 0 then
- if zfile then
- input.logger('! zip locator, found: %s',specification.original)
- else
- input.logger('? zip locator, not found: %s',specification.original)
- end
- end
- end
-
- function input.hashers.zip(tag,name)
- input.report("loading zip file %s as %s",name,tag)
- input.usezipfile(tag .."?tree=" .. name)
- end
-
- function input.concatinators.zip(tag,path,name)
- if not path or path == "" then
- return tag .. '?name=' .. name
- else
- return tag .. '?name=' .. path .. "/" .. name
- end
- end
-
- function input.is_readable.zip(name)
- return true
- end
-
- function input.finders.zip(specification,filetype)
- specification = input.splitmethod(specification)
- if specification.path then
- local q = url.query(specification.query)
- if q.name then
- local zfile = zip.openarchive(specification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('! zip finder, path: %s',specification.path)
- end
- local dfile = zfile:open(q.name)
- if dfile then
- dfile = zfile:close()
- if input.trace > 0 then
- input.logger('+ zip finder, name: %s',q.name)
- end
- return specification.original
- end
- elseif input.trace > 0 then
- input.logger('? zip finder, path %s',specification.path)
- end
- end
- end
- if input.trace > 0 then
- input.logger('- zip finder, name: %s',filename)
- end
- return unpack(input.finders.notfound)
- end
-
- function input.openers.zip(specification)
- local zipspecification = input.splitmethod(specification)
- if zipspecification.path then
- local q = url.query(zipspecification.query)
- if q.name then
- local zfile = zip.openarchive(zipspecification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('+ zip starter, path: %s',zipspecification.path)
- end
- local dfile = zfile:open(q.name)
- if dfile then
- input.show_open(specification)
- return input.openers.text_opener(specification,dfile,'zip')
- end
- elseif input.trace > 0 then
- input.logger('- zip starter, path %s',zipspecification.path)
- end
- end
- end
- if input.trace > 0 then
- input.logger('- zip opener, name: %s',filename)
- end
- return unpack(input.openers.notfound)
- end
-
- function input.loaders.zip(specification)
- specification = input.splitmethod(specification)
- if specification.path then
- local q = url.query(specification.query)
- if q.name then
- local zfile = zip.openarchive(specification.path)
- if zfile then
- if input.trace > 0 then
- input.logger('+ zip starter, path: %s',specification.path)
- end
- local dfile = zfile:open(q.name)
- if dfile then
- input.show_load(filename)
- if input.trace > 0 then
- input.logger('+ zip loader, name: %s',filename)
- end
- local s = dfile:read("*all")
- dfile:close()
- return true, s, #s
- end
- elseif input.trace > 0 then
- input.logger('- zip starter, path: %s',specification.path)
- end
- end
- end
- if input.trace > 0 then
- input.logger('- zip loader, name: %s',filename)
- end
- return unpack(input.openers.notfound)
- end
-
- -- zip:///somefile.zip
- -- zip:///somefile.zip?tree=texmf-local -> mount
-
- function input.usezipfile(zipname)
- zipname = validzip(zipname)
- if input.trace > 0 then
- input.logger('! zip use, file: %s',zipname)
- end
- local specification = input.splitmethod(zipname)
- local zipfile = specification.path
- if zipfile and not zip.registeredfiles[zipname] then
- local tree = url.query(specification.query).tree or ""
- if input.trace > 0 then
- input.logger('! zip register, file: %s',zipname)
- end
- local z = zip.openarchive(zipfile)
- if z then
- local instance = input.instance
- if input.trace > 0 then
- input.logger("= zipfile, registering: %s",zipname)
- end
- input.starttiming(instance)
- input.aux.prepend_hash('zip',zipname,zipfile)
- input.aux.extend_texmf_var(zipname) -- resets hashes too
- zip.registeredfiles[zipname] = z
- instance.files[zipname] = input.aux.register_zip_file(z,tree or "")
- input.stoptiming(instance)
- elseif input.trace > 0 then
- input.logger("? zipfile, unknown: %s",zipname)
- end
- elseif input.trace > 0 then
- input.logger('! zip register, no file: %s',zipname)
- end
- end
-
- function input.aux.register_zip_file(z,tree)
- local files, filter = { }, ""
- if tree == "" then
- filter = "^(.+)/(.-)$"
- else
- filter = "^"..tree.."/(.+)/(.-)$"
- end
- if input.trace > 0 then
- input.logger('= zip filter: %s',filter)
- end
- local register, n = input.aux.register_file, 0
- for i in z:files() do
- local path, name = i.filename:match(filter)
- if path then
- if name and name ~= '' then
- register(files, name, path)
- n = n + 1
- else
- -- directory
- end
- else
- register(files, i.filename, '')
- n = n + 1
- end
- end
- input.logger('= zip entries: %s',n)
- return files
- end
-
-end
diff --git a/tex/context/base/lxml-ent.lua b/tex/context/base/lxml-ent.lua
new file mode 100644
index 000000000..c91d12706
--- /dev/null
+++ b/tex/context/base/lxml-ent.lua
@@ -0,0 +1,115 @@
+if not modules then modules = { } end modules ['lxml-ent'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub, find = string.format, string.gsub, string.find
+local utfchar = unicode.utf8.char
+
+--[[ldx--
+
We provide (at least here) two entity handlers. The more extensive
+resolver consults a hash first, tries to convert to next,
+and finaly calls a handler when defines. When this all fails, the
+original entity is returned.
+--ldx]]--
+
+xml.entities = xml.entities or { } -- xml.entity_handler == function
+
+function xml.entity_handler(e)
+ return format("[%s]",e)
+end
+
+local function toutf(s)
+ return utfchar(tonumber(s,16))
+end
+
+local function utfize(root)
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ -- test prevents copying if no match
+ if find(dk,".-;") then
+ d[k] = gsub(dk,"(.-);",toutf)
+ end
+ else
+ utfize(dk)
+ end
+ end
+end
+
+xml.utfize = utfize
+
+local function resolve(e) -- hex encoded always first, just to avoid mkii fallbacks
+ if find(e,"^#x") then
+ return utfchar(tonumber(e:sub(3),16))
+ elseif find(e,"^#") then
+ return utfchar(tonumber(e:sub(2)))
+ else
+ local ee = xml.entities[e] -- we cannot shortcut this one (is reloaded)
+ if ee then
+ return ee
+ else
+ local h = xml.entity_handler
+ return (h and h(e)) or "&" .. e .. ";"
+ end
+ end
+end
+
+local function resolve_entities(root)
+ if not root.special or root.tg == "@rt@" then
+ local d = root.dt
+ for k=1,#d do
+ local dk = d[k]
+ if type(dk) == "string" then
+ if find(dk,"&.-;") then
+ d[k] = gsub(dk,"&(.-);",resolve)
+ end
+ else
+ resolve_entities(dk)
+ end
+ end
+ end
+end
+
+xml.resolve_entities = resolve_entities
+
+function xml.utfize_text(str)
+ if find(str,"") then
+ return (gsub(str,"(.-);",toutf))
+ else
+ return str
+ end
+end
+
+function xml.resolve_text_entities(str) -- maybe an lpeg. maybe resolve inline
+ if find(str,"&") then
+ return (gsub(str,"&(.-);",resolve))
+ else
+ return str
+ end
+end
+
+function xml.show_text_entities(str)
+ if find(str,"&") then
+ return (gsub(str,"&(.-);","[%1]"))
+ else
+ return str
+ end
+end
+
+-- experimental, this will be done differently
+
+function xml.merge_entities(root)
+ local documententities = root.entities
+ local allentities = xml.entities
+ if documententities then
+ for k, v in next, documententities do
+ allentities[k] = v
+ end
+ end
+end
diff --git a/tex/context/base/lxml-ini.lua b/tex/context/base/lxml-ini.lua
index 6b8d014a7..0c40a4baf 100644
--- a/tex/context/base/lxml-ini.lua
+++ b/tex/context/base/lxml-ini.lua
@@ -6,10 +6,19 @@ if not modules then modules = { } end modules ['lxml-ini'] = {
license = "see context related readme files"
}
-local texsprint, texprint = tex.sprint or print, tex.print or print
+local utf = unicode.utf8
+
+local texsprint, texprint, utfchar = tex.sprint or print, tex.print or print, utf.char
local format, concat, insert, remove = string.format, table.concat, table.insert, table.remove
local type, next, tonumber = type, next, tonumber
+local ctxcatcodes = tex.ctxcatcodes
+local texcatcodes = tex.texcatcodes
+local vrbcatcodes = tex.vrbcatcodes
+
+local trace_setups = false trackers.register("lxml.setups", function(v) trace_setups = v end)
+local trace_loading = false trackers.register("lxml.loading", function(v) trace_loading = v end)
+
-- for the moment here
function table.insert_before_value(t,value,extra)
@@ -59,10 +68,11 @@ document.xml = document.xml or { }
lxml = lxml or { }
lxml.loaded = { }
lxml.myself = { }
+lxml.n = 0
-local loaded = lxml.loaded
-local myself = lxml.myself
-local stack = lxml.stack
+local loaded = lxml.loaded
+local myself = lxml.myself
+local stack = lxml.stack
lxml.self = myself -- be backward compatible for a while
@@ -88,22 +98,22 @@ do
local lf = lpeg.P("\n")
local space = lpeg.S(" \t\f\v")
local newline = crlf + cr + lf
- local spacing = space^0 * newline * space^0
+ local spacing = newline * space^0
local content = lpeg.C((1-spacing)^1)
local verbose = lpeg.C((1-(space+newline))^1)
+ -- local capture = (
+ -- newline^2 * lpeg.Cc("") / texprint +
+ -- newline * lpeg.Cc(" ") / texsprint +
+ -- content / texsprint
+ -- )^0
+
local capture = (
- newline^2 * lpeg.Cc("") / texprint +
- newline * lpeg.Cc(" ") / texsprint +
- content / texsprint
+ space^0 * newline^2 * lpeg.Cc("") / texprint +
+ space^0 * newline * space^0 * lpeg.Cc(" ") / texsprint +
+ content / texsprint
)^0
---~ local capture = (
---~ newline^2 * lpeg.Cc("") / function(s) texprint (tex.xmlcatcodes,s) end +
---~ newline * lpeg.Cc(" ") / function(s) texsprint(tex.xmlcatcodes,s) end +
---~ content / function(s) texsprint(tex.xmlcatcodes,s) end
---~ )^0
-
local forceraw, rawroot = false, nil
function lxml.startraw()
@@ -136,12 +146,12 @@ do
local function sprint(root)
if not root then
---~ rawroot = false
+ --~ rawroot = false
-- quit
else
local tr = type(root)
if tr == "string" then -- can also be result of lpath
---~ rawroot = false
+ --~ rawroot = false
capture:match(root)
elseif tr == "table" then
rawroot = forceraw and root
@@ -223,15 +233,15 @@ do
local aftercommand = ""
local capture = (
- newline / function( ) texsprint(tex.texcatcodes,linecommand .. "{}") end +
- verbose / function(s) texsprint(tex.vrbcatcodes,s) end +
- space / function( ) texsprint(tex.texcatcodes,spacecommand .. "{}") end
+ newline / function( ) texsprint(texcatcodes,linecommand,"{}") end +
+ verbose / function(s) texsprint(vrbcatcodes,s) end +
+ space / function( ) texsprint(texcatcodes,spacecommand,"{}") end
)^0
local function toverbatim(str)
- if beforecommand then texsprint(tex.texcatcodes,beforecommand .. "{}") end
+ if beforecommand then texsprint(texcatcodes,beforecommand,"{}") end
capture:match(str)
- if aftercommand then texsprint(tex.texcatcodes,aftercommand .. "{}") end
+ if aftercommand then texsprint(texcatcodes,aftercommand,"{}") end
end
function lxml.set_verbatim(before,after,obeyedline,obeyedspace)
@@ -249,23 +259,23 @@ do
-- local capture = (space^0*newline)^0 * capture * (space+newline)^0 * -1
local function toverbatim(str)
- if beforecommand then texsprint(tex.texcatcodes,beforecommand .. "{}") end
+ if beforecommand then texsprint(texcatcodes,beforecommand,"{}") end
-- todo: add this to capture
str = str:gsub("^[ \t]+[\n\r]+","")
str = str:gsub("[ \t\n\r]+$","")
capture:match(str)
- if aftercommand then texsprint(tex.texcatcodes,aftercommand .. "{}") end
+ if aftercommand then texsprint(texcatcodes,aftercommand,"{}") end
end
function lxml.verbatim(id,before,after)
local root = get_id(id)
if root then
- if before then texsprint(tex.ctxcatcodes,format("%s[%s]",before,root.tg)) end
+ if before then texsprint(ctxcatcodes,format("%s[%s]",before,root.tg)) end
-- serialize(root.dt,toverbatim,nil,nil,nil,true) -- was root
local t = { }
serialize(root.dt,function(s) t[#t+1] = s end,nil,nil,nil,true) -- was root
toverbatim(table.concat(t,""))
- if after then texsprint(tex.ctxcatcodes,after) end
+ if after then texsprint(ctxcatcodes,after) end
end
end
function lxml.inlineverbatim(id)
@@ -299,12 +309,12 @@ do
if str then
local a, b, c, d = parser:match(str)
if d then
- texsprint(tex.ctxcatcodes,format("\\xmlcontextdirective{%s}{%s}{%s}{%s}",a,b,c,d))
+ texsprint(ctxcatcodes,format("\\xmlcontextdirective{%s}{%s}{%s}{%s}",a,b,c,d))
end
end
end
- -- print(contextdirective("context-mathml-directive function reduction yes yes "))
+ -- print(contextdirective("context-mathml-directive function reduction yes "))
-- print(contextdirective("context-mathml-directive function "))
function lxml.main(id)
@@ -324,36 +334,46 @@ local xmltprint = xml.tprint
xml.originalload = xml.originalload or xml.load
+local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
+
function xml.load(filename)
- input.starttiming(xml)
- local xmldata = xml.convert((filename and input.loadtexfile(filename)) or "")
- input.stoptiming(xml)
+ lxml.n = lxml.n + 1
+ starttiming(xml)
+ local xmldata = xml.convert((filename and resolvers.loadtexfile(filename)) or "")
+ stoptiming(xml)
return xmldata
end
function lxml.load(id,filename)
+ lxml.n = lxml.n + 1
filename = commands.preparedfile(filename)
- if lxml.trace_load then
- ctx.writestatus("lxml","loading file: %s",filename)
+ if trace_loading then
+ commands.writestatus("lxml","loading file: %s",filename)
end
loaded[id] = xml.load(filename)
return loaded[id], filename
end
+function lxml.register(id,xmltable)
+ lxml.n = lxml.n + 1
+ loaded[id] = xmltable
+ return xmltable
+end
+
function lxml.include(id,pattern,attribute,recurse)
- input.starttiming(xml)
+ starttiming(xml)
xml.include(get_id(id),pattern,attribute,recurse,function(filename)
if filename then
filename = commands.preparedfile(filename)
- if lxml.trace_load then
- ctx.writestatus("lxml","including file: %s",filename)
+ if trace_loading then
+ commands.writestatus("lxml","including file: %s",filename)
end
- return input.loadtexfile(filename) or ""
+ return resolvers.loadtexfile(filename) or ""
else
return ""
end
end)
- input.stoptiming(xml)
+ stoptiming(xml)
end
function lxml.utfize(id)
@@ -373,7 +393,11 @@ function lxml.all(id,pattern)
-- xmltprint(xmlcollect(get_id(id),pattern))
traverse(get_id(id), lpath(pattern), function(r,d,k)
-- to be checked for root::
- xmlsprint(d[k])
+ if d then
+ xmlsprint(d[k])
+ else -- new, maybe wrong
+--~ xmlsprint(r)
+ end
return false
end)
end
@@ -522,7 +546,7 @@ function lxml.name(id) -- or remapped name? -> lxml.info, combine
local r = get_id(id)
local ns = r.rn or r.ns or ""
if ns ~= "" then
- texsprint(ns .. ":" .. r.tg)
+ texsprint(ns,":",r.tg)
else
texsprint(r.tg)
end
@@ -550,9 +574,9 @@ function lxml.concatrange(id,what,start,stop,separator,lastseparator) -- test th
if i == #t then
-- nothing
elseif i == #t-1 and lastseparator ~= "" then
- texsprint(tex.ctxcatcodes,lastseparator)
+ texsprint(ctxcatcodes,lastseparator)
elseif separator ~= "" then
- texsprint(tex.ctxcatcodes,separator)
+ texsprint(ctxcatcodes,separator)
end
end
end
@@ -580,7 +604,7 @@ function xml.command(root, command)
-- setup
local n = #myself + 1
myself[n] = root
- texsprint(tex.ctxcatcodes,format("\\xmlsetup{%i}{%s}",n,command))
+ texsprint(ctxcatcodes,format("\\xmlsetup{%i}{%s}",n,command))
elseif tc == "function" then
-- function
command(root)
@@ -600,11 +624,7 @@ function lxml.setaction(id,pattern,action)
end
end
-lxml.trace_setups = false
-lxml.trace_load = false
-
function lxml.setsetup(id,pattern,setup)
- local trace = lxml.trace_setups
if not setup or setup == "" or setup == "*" or setup == "-" or setup == "+" then
for rt, dt, dk in xmlelements(get_id(id),pattern) do
local dtdk = dt and dt[dk] or rt
@@ -614,17 +634,17 @@ function lxml.setsetup(id,pattern,setup)
if setup == "-" then
dtdk.command = false
if trace then
- texio.write_nl(format("lpath matched -> %s -> skipped", command))
+ logs.report("lxml","lpath matched -> %s -> skipped", command)
end
elseif setup == "+" then
dtdk.command = true
- if trace then
- texio.write_nl(format("lpath matched -> %s -> text", command))
+ if trace_setups then
+ logs.report("lxml","lpath matched -> %s -> text", command)
end
else
dtdk.command = command
- if trace then
- texio.write_nl(format("lpath matched -> %s -> %s", command, command))
+ if trace_setups then
+ logs.report("lxml","lpath matched -> %s -> %s", command, command)
end
end
end
@@ -637,46 +657,46 @@ function lxml.setsetup(id,pattern,setup)
local ns, tg = dtdk.rn or dtdk.ns, dtdk.tg
if b == "-" then
dtdk.command = false
- if trace then
+ if trace_setups then
if ns == "" then
- texio.write_nl(format("lpath matched -> %s -> skipped", tg))
+ logs.report("lxml","lpath matched -> %s -> skipped", tg)
else
- texio.write_nl(format("lpath matched -> %s:%s -> skipped", ns, tg))
+ logs.report("lxml","lpath matched -> %s:%s -> skipped", ns, tg)
end
end
elseif b == "+" then
dtdk.command = true
- if trace then
+ if trace_setups then
if ns == "" then
- texio.write_nl(format("lpath matched -> %s -> text", tg))
+ logs.report("lxml","lpath matched -> %s -> text", tg)
else
- texio.write_nl(format("lpath matched -> %s:%s -> text", ns, tg))
+ logs.report("lxml","lpath matched -> %s:%s -> text", ns, tg)
end
end
else
dtdk.command = a .. tg
- if trace then
+ if trace_setups then
if ns == "" then
- texio.write_nl(format("lpath matched -> %s -> %s", tg, dtdk.command))
+ logs.report("lxml","lpath matched -> %s -> %s", tg, dtdk.command)
else
- texio.write_nl(format("lpath matched -> %s:%s -> %s", ns, tg, dtdk.command))
+ logs.report("lxml","lpath matched -> %s:%s -> %s", ns, tg, dtdk.command)
end
end
end
end
else
- if trace then
- texio.write_nl(format("lpath pattern -> %s -> %s", pattern, setup))
+ if trace_setups then
+ logs.report("lxml","lpath pattern -> %s -> %s", pattern, setup)
end
for rt, dt, dk in xmlelements(get_id(id),pattern) do
local dtdk = (dt and dt[dk]) or rt
dtdk.command = setup
- if trace then
+ if trace_setups then
local ns, tg = dtdk.rn or dtdk.ns, dtdk.tg
if ns == "" then
- texio.write_nl(format("lpath matched -> %s -> %s", tg, setup))
+ logs.report("lxml","lpath matched -> %s -> %s", tg, setup)
else
- texio.write_nl(format("lpath matched -> %s:%s -> %s", ns, tg, setup))
+ logs.report("lxml","lpath matched -> %s:%s -> %s", ns, tg, setup)
end
end
end
@@ -722,7 +742,7 @@ local function command(root,pattern,cmd) -- met zonder ''
if type(m) == "table" then -- probably a bug
local n = #myself + 1
myself[n] = m
- texsprint(tex.ctxcatcodes,format("\\xmlsetup{%s}{%s}",n,cmd))
+ texsprint(ctxcatcodes,format("\\xmlsetup{%s}{%s}",n,cmd))
end
end)
end
@@ -739,98 +759,92 @@ end
xml.filters["function"] = dofunction
-do
+--~
+--~
+--~
+--~
+--~
+--~
+--~
+
+lxml.directives = { }
+
+local data = {
+ setup = { },
+ before = { },
+ after = { }
+}
- --~
- --~
- --~
- --~
- --~
- --~
- --~
-
- lxml.directives = { }
-
- local data = {
- setup = { },
- before = { },
- after = { }
- }
-
- function lxml.directives.load(filename)
- if texmf then
- local fullname = input.find_file(filename) or ""
- if fullname ~= "" then
- filename = fullname
- end
- end
- local root = xml.load(filename)
- for r, d, k in xmlelements(root,"directive") do
- local dk = d[k]
- local at = dk.at
- local attribute, value, element = at.attribute or "", at.value or "", at.element or '*'
- local setup, before, after = at.setup or "", at.before or "", at.after or ""
- if attribute ~= "" and value ~= "" then
- local key = format("%s::%s::%s",element,attribute,value)
- local t = data[key] or { }
- if setup ~= "" then t.setup = setup end
- if before ~= "" then t.before = before end
- if after ~= "" then t.after = after end
- data[key] = t
- end
+function lxml.directives.load(filename)
+ local fullname = resolvers.find_file(filename) or ""
+ if fullname ~= "" then
+ filename = fullname
+ end
+ local root = xml.load(filename)
+ for r, d, k in xmlelements(root,"directive") do
+ local dk = d[k]
+ local at = dk.at
+ local attribute, value, element = at.attribute or "", at.value or "", at.element or '*'
+ local setup, before, after = at.setup or "", at.before or "", at.after or ""
+ if attribute ~= "" and value ~= "" then
+ local key = format("%s::%s::%s",element,attribute,value)
+ local t = data[key] or { }
+ if setup ~= "" then t.setup = setup end
+ if before ~= "" then t.before = before end
+ if after ~= "" then t.after = after end
+ data[key] = t
end
end
+end
- function lxml.directives.setup(root,attribute,element)
- lxml.directives.handle_setup('setup',root,attribute,element)
- end
- function lxml.directives.before(root,attribute,element)
- lxml.directives.handle_setup('before',root,attribute,element)
- end
- function lxml.directives.after(root,attribute,element)
- lxml.directives.handle_setup('after',root,attribute,element)
- end
+function lxml.directives.setup(root,attribute,element)
+ lxml.directives.handle_setup('setup',root,attribute,element)
+end
+function lxml.directives.before(root,attribute,element)
+ lxml.directives.handle_setup('before',root,attribute,element)
+end
+function lxml.directives.after(root,attribute,element)
+ lxml.directives.handle_setup('after',root,attribute,element)
+end
- function lxml.directives.handle_setup(category,root,attribute,element)
- root = get_id(root)
- attribute = attribute
- if attribute then
- local value = root.at[attribute]
- if value then
- if not element then
- local ns, tg = root.rn or root.ns, root.tg
- if ns == "" then
- element = tg
- else
- element = ns .. ':' .. tg
- end
+function lxml.directives.handle_setup(category,root,attribute,element)
+ root = get_id(root)
+ attribute = attribute
+ if attribute then
+ local value = root.at[attribute]
+ if value then
+ if not element then
+ local ns, tg = root.rn or root.ns, root.tg
+ if ns == "" then
+ element = tg
+ else
+ element = ns .. ':' .. tg
end
- local setup = data[format("%s::%s::%s",element,attribute,value)]
+ end
+ local setup = data[format("%s::%s::%s",element,attribute,value)]
+ if setup then
+ setup = setup[category]
+ end
+ if setup then
+ texsprint(ctxcatcodes,format("\\directsetup{%s}",setup))
+ else
+ setup = data[format("%s::%s::*",element,attribute)]
if setup then
setup = setup[category]
end
if setup then
- texsprint(tex.ctxcatcodes,format("\\directsetup{%s}",setup))
- else
- setup = data[format("%s::%s::*",element,attribute)]
- if setup then
- setup = setup[category]
- end
- if setup then
- texsprint(tex.ctxcatcodes,format("\\directsetup{%s}",setup:gsub('%*',value)))
- end
+ texsprint(ctxcatcodes,format("\\directsetup{%s}",setup:gsub('%*',value)))
end
end
end
end
-
end
function xml.getbuffer(name) -- we need to make sure that commands are processed
@@ -844,16 +858,20 @@ function lxml.loadbuffer(id,name)
if not name or name == "" then
name = tex.jobname
end
- input.starttiming(xml)
+ starttiming(xml)
loaded[id] = xml.convert(buffers.collect(name or id,"\n"))
- input.stoptiming(xml)
+ stoptiming(xml)
return loaded[id], name or id
end
function lxml.loaddata(id,str)
- input.starttiming(xml)
+ starttiming(xml)
loaded[id] = xml.convert(str or "")
- input.stoptiming(xml)
+ stoptiming(xml)
+ return loaded[id], id
+end
+
+function lxml.loadregistered(id)
return loaded[id], id
end
@@ -862,143 +880,149 @@ end
lxml.set_verbatim("\\xmlcdatabefore", "\\xmlcdataafter", "\\xmlcdataobeyedline", "\\xmlcdataobeyedspace")
lxml.set_cdata()
-do
-
- local traced = { }
+local traced = { }
- function lxml.trace_text_entities(str)
- return str:gsub("&(.-);",function(s)
- traced[s] = (traced[s] or 0) + 1
- return "["..s.."]"
- end)
- end
+function lxml.trace_text_entities(str)
+ return str:gsub("&(.-);",function(s)
+ traced[s] = (traced[s] or 0) + 1
+ return "["..s.."]"
+ end)
+end
- function lxml.show_text_entities()
- for k,v in ipairs(table.sortedkeys(traced)) do
- local h = v:match("^#x(.-)$")
- if h then
- local d = tonumber(h,16)
- local u = unicode.utf8.char(d)
- texio.write_nl(format("entity: %s / %s / %s / n=%s",h,d,u,traced[v]))
- else
- texio.write_nl(format("entity: %s / n=%s",v,traced[v]))
- end
+function lxml.show_text_entities()
+ for k,v in ipairs(table.sortedkeys(traced)) do
+ local h = v:match("^#x(.-)$")
+ if h then
+ local d = tonumber(h,16)
+ local u = utfchar(d)
+ logs.report("lxml","entity: %s / %s / %s / n=%s",h,d,u,traced[v])
+ else
+ logs.report("lxml","entity: %s / n=%s",v,traced[v])
end
end
-
end
--- yes or no ...
+local error_entity_handler = function(s) return format("[%s]",s) end
+local element_entity_handler = function(s) return format("",s) end
-do
+function lxml.set_mkii_entityhandler()
+ xml.entity_handler = error_entity_handler
+ xml.set_text_cleanup()
+end
+function lxml.set_mkiv_entityhandler()
+ xml.entity_handler = element_entity_handler
+ xml.set_text_cleanup(xml.resolve_text_entities)
+end
+function lxml.reset_entityhandler()
+ xml.entity_handler = error_entity_handler
+ xml.set_text_cleanup()
+end
- local function with_elements_only(e,handle)
- if e and handle then
- local etg = e.tg
- if etg then
- if e.special and etg ~= "@rt@" then
- if resthandle then
- resthandle(e)
- end
- else
- local edt = e.dt
- if edt then
- for i=1,#edt do
- local e = edt[i]
- if type(e) == "table" then
- handle(e)
- with_elements_only(e,handle)
- end
+local function with_elements_only(e,handle)
+ if e and handle then
+ local etg = e.tg
+ if etg then
+ if e.special and etg ~= "@rt@" then
+ if resthandle then
+ resthandle(e)
+ end
+ else
+ local edt = e.dt
+ if edt then
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "table" then
+ handle(e)
+ with_elements_only(e,handle)
end
end
end
end
end
end
+end
- local function with_elements_only(e,handle,depth)
- if e and handle then
- local edt = e.dt
- if edt then
- depth = depth or 0
- for i=1,#edt do
- local e = edt[i]
- if type(e) == "table" then
- handle(e,depth)
- with_elements_only(e,handle,depth+1)
- end
+ local function with_elements_only(e,handle,depth)
+ if e and handle then
+ local edt = e.dt
+ if edt then
+ depth = depth or 0
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "table" then
+ handle(e,depth)
+ with_elements_only(e,handle,depth+1)
end
end
end
end
+end
- xml.with_elements_only = with_elements_only
+xml.with_elements_only = with_elements_only
- local function to_text(e)
- if e.command == nil then
- local etg = e.tg
- if etg and e.special and etg ~= "@rt@" then
- e.command = false -- i.e. skip
- else
- e.command = true -- i.e. no
- end
- end
- end
- local function to_none(e)
- if e.command == nil then
+local function to_text(e)
+ if e.command == nil then
+ local etg = e.tg
+ if etg and e.special and etg ~= "@rt@" then
e.command = false -- i.e. skip
+ else
+ e.command = true -- i.e. no
end
end
+end
+local function to_none(e)
+ if e.command == nil then
+ e.command = false -- i.e. skip
+ end
+end
- -- can be made faster: just recurse over whole table, todo
+-- can be made faster: just recurse over whole table, todo
- function lxml.set_command_to_text(id)
- xml.with_elements_only(get_id(id),to_text)
- end
+function lxml.set_command_to_text(id)
+ xml.with_elements_only(get_id(id),to_text)
+end
- function lxml.set_command_to_none(id)
- xml.with_elements_only(get_id(id),to_none)
- end
+function lxml.set_command_to_none(id)
+ xml.with_elements_only(get_id(id),to_none)
+end
- function lxml.get_command_status(id)
- local status, stack = {}, {}
- local function get(e,d)
- local ns, tg = e.ns, e.tg
- local name = tg
- if ns ~= "" then name = ns .. ":" .. tg end
- stack[d] = name
- local ec = e.command
- if ec == true then
- ec = "system: text"
- elseif ec == false then
- ec = "system: skip"
- elseif ec == nil then
- ec = "system: not set"
- elseif type(ec) == "string" then
- ec = "setup: " .. ec
- else -- function
- ec = tostring(ec)
- end
- local tag = table.concat(stack," => ",1,d)
- local s = status[tag]
- if not s then
- s = { }
- status[tag] = s
- end
- s[ec] = (s[ec] or 0) + 1
+function lxml.get_command_status(id)
+ local status, stack = {}, {}
+ local function get(e,d)
+ local ns, tg = e.ns, e.tg
+ local name = tg
+ if ns ~= "" then name = ns .. ":" .. tg end
+ stack[d] = name
+ local ec = e.command
+ if ec == true then
+ ec = "system: text"
+ elseif ec == false then
+ ec = "system: skip"
+ elseif ec == nil then
+ ec = "system: not set"
+ elseif type(ec) == "string" then
+ ec = "setup: " .. ec
+ else -- function
+ ec = tostring(ec)
end
- if id then
- xml.with_elements_only(get_id(id),get)
- return status
- else
- local t = { }
- for id, _ in pairs(loaded) do
- t[id] = lxml.get_command_status(id)
- end
- return t
+ local tag = table.concat(stack," => ",1,d)
+ local s = status[tag]
+ if not s then
+ s = { }
+ status[tag] = s
end
+ s[ec] = (s[ec] or 0) + 1
+ end
+ if id then
+ xml.with_elements_only(get_id(id),get)
+ return status
+ else
+ local t = { }
+ for id, _ in pairs(loaded) do
+ t[id] = lxml.get_command_status(id)
+ end
+ return t
end
-
end
local setups = { }
@@ -1011,23 +1035,23 @@ function lxml.installsetup(what,document,setup,where)
if sd[k] == setup then sd[k] = nil break end
end
if what == 1 then
- if lxml.trace_load then
- ctx.writestatus("lxml","prepending setup %s for %s",setup,document)
+ if trace_loading then
+ commands.writestatus("lxml","prepending setup %s for %s",setup,document)
end
insert(sd,1,setup)
elseif what == 2 then
- if lxml.trace_load then
- ctx.writestatus("lxml","appending setup %s for %s",setup,document)
+ if trace_loading then
+ commands.writestatus("lxml","appending setup %s for %s",setup,document)
end
insert(sd,setup)
elseif what == 3 then
- if lxml.trace_load then
- ctx.writestatus("lxml","inserting setup %s for %s before %s",setup,document,where)
+ if trace_loading then
+ commands.writestatus("lxml","inserting setup %s for %s before %s",setup,document,where)
end
table.insert_before_value(sd,setup,where)
elseif what == 4 then
- if lxml.trace_load then
- ctx.writestatus("lxml","inserting setup %s for %s after %s",setup,document,where)
+ if trace_loading then
+ commands.writestatus("lxml","inserting setup %s for %s after %s",setup,document,where)
end
table.insert_after_value(sd,setup,where)
end
@@ -1038,26 +1062,25 @@ function lxml.flushsetups(...)
for _, document in ipairs({...}) do
local sd = setups[document]
if sd then
- local tc = tex.ctxcatcodes
for k=1,#sd do
local v= sd[k]
if not done[v] then
- if lxml.trace_load then
- ctx.writestatus("lxml","applying setup %02i = %s to %s",k,v,document)
+ if trace_loading then
+ commands.writestatus("lxml","applying setup %02i = %s to %s",k,v,document)
end
- texsprint(tc,format("\\directsetup{%s}",v))
+ texsprint(ctxcatcodes,format("\\directsetup{%s}",v))
done[v] = true
end
end
- elseif lxml.trace_load then
- ctx.writestatus("lxml","no setups for %s",document)
+ elseif trace_loading then
+ commands.writestatus("lxml","no setups for %s",document)
end
end
end
function lxml.resetsetups(document)
- if lxml.trace_load then
- ctx.writestatus("lxml","resetting all setups for %s",document)
+ if trace_loading then
+ commands.writestatus("lxml","resetting all setups for %s",document)
end
setups[document] = { }
end
@@ -1067,8 +1090,8 @@ function lxml.removesetup(document,setup)
if s then
for i=1,#s do
if s[i] == setup then
- if lxml.trace_load then
- ctx.writestatus("lxml","removing setup %s for %s",setup,document)
+ if trace_loading then
+ commands.writestatus("lxml","removing setup %s for %s",setup,document)
end
remove(t,i)
break
@@ -1092,3 +1115,24 @@ function lxml.doifelsetext (id,pattern) commands.doifelse(found (get_id(id),pat
-- special case: "*" and "" -> self else lpath lookup
function lxml.doifelseempty(id,pattern) commands.doifelse(isempty(get_id(id),pattern ~= "" and pattern ~= nil)) end -- not yet done, pattern
+
+-- status info
+
+statistics.register("xml load time", function()
+ local n = lxml.n
+ if n > 0 then
+ local stats = xml.statistics()
+ return format("%s seconds, lpath calls: %s, cached calls: %s", statistics.elapsedtime(xml), stats.lpathcalls, stats.lpathcached)
+ else
+ return nil
+ end
+end)
+
+statistics.register("lxml load time", function()
+ local n = #lxml.self
+ if n > 0 then
+ return format("%s seconds preparation, backreferences: %i", statistics.elapsedtime(lxml),n)
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/lxml-ini.tex b/tex/context/base/lxml-ini.tex
index 0d03044b2..494e4f0b7 100644
--- a/tex/context/base/lxml-ini.tex
+++ b/tex/context/base/lxml-ini.tex
@@ -1,7 +1,7 @@
%D \module
%D [ file=lxml-ini,
%D version=2007.08.17,
-%D title=\CONTEXT\ \LUA\ based \XML\ Support,
+%D title=\CONTEXT\ \XML\ Support,
%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
@@ -11,8 +11,12 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context L-XML Macros (initialization)}
+\writestatus{loading}{ConTeXt XML Support / Initialization}
+\registerctxluafile{lxml-tab}{1.001}
+\registerctxluafile{lxml-pth}{1.001}
+\registerctxluafile{lxml-ent}{1.001}
+\registerctxluafile{lxml-mis}{1.001}
\registerctxluafile{lxml-ini}{1.001}
\unprotect
@@ -31,7 +35,7 @@
\def\xmldirectives #1{\ctxlua{lxml.directives.setup("#1")}}
\def\xmldirectivesbefore #1{\ctxlua{lxml.directives.before("#1")}}
\def\xmldirectivesafter #1{\ctxlua{lxml.directives.after("#1")}}
-\def\xmlfilter #1#2{\ctxlua{lxml.filter("#1","#2")}}
+\def\xmlfilter #1#2{\ctxlua{lxml.filter("#1",\!!bs#2\!!es)}}
\def\xmlfirst #1#2{\ctxlua{lxml.first("#1","#2")}}
\def\xmlflush #1{\ctxlua{lxml.flush("#1")}}
% \def\xmlcontent #1{\ctxlua{lxml.content("#1")}}
@@ -47,6 +51,7 @@
\def\xmlload #1#2{\ctxlua{lxml.load("#1","#2")}}
\def\xmlloadbuffer #1#2{\ctxlua{lxml.loadbuffer("#1","#2")}}
\def\xmlloaddata #1#2{\ctxlua{lxml.loaddata("#1",\!!bs#2\!!es)}}
+\def\xmlloadregistered #1#2{\ctxlua{lxml.loadregistered("#1")}}
\def\xmlloaddirectives #1{\ctxlua{lxml.directives.load("#1")}}
\def\xmlname #1{\ctxlua{lxml.name("#1")}}
\def\xmlnamespace #1{\ctxlua{lxml.namespace("#1")}}
@@ -130,6 +135,8 @@
\let\xmlregistersetup \xmlappendsetup
\let\xmlregisterdocumentsetup\xmlappenddocumentsetup
+\def\xmldocument{main}
+
\def\xmlregisteredsetups
{\xmlstarttiming
\xmlflushsetups
@@ -143,8 +150,8 @@
\xmldefaulttotext{#1}% after include
\xmlstoptiming}
-\def\xmlstarttiming{\ctxlua{input.starttiming(lxml)}}
-\def\xmlstoptiming {\ctxlua{input.stoptiming (lxml)}}
+\def\xmlstarttiming{\ctxlua{statistics.starttiming(lxml)}}
+\def\xmlstoptiming {\ctxlua{statistics.stoptiming (lxml)}}
\def\doxmlprocess#1#2#3#4%
{\begingroup
@@ -160,10 +167,11 @@
{\directsetup{#4}}%
\endgroup}
-\def\xmlprocessfile {\doxmlprocess\xmlload}
-\def\xmlprocessdata {\doxmlprocess\xmlloaddata}
-\def\xmlprocessbuffer{\doxmlprocess\xmlloadbuffer}
-\let\xmlprocess \xmlprocessfile
+\def\xmlprocessfile {\doxmlprocess\xmlload}
+\def\xmlprocessdata {\doxmlprocess\xmlloaddata}
+\def\xmlprocessbuffer {\doxmlprocess\xmlloadbuffer}
+\def\xmlprocessregistered{\doxmlprocess\xmlloadregistered}
+\let\xmlprocess \xmlprocessfile
% beware: \xmlmain takes the real root, so also processing
% instructions preceding the root element; well, in some
@@ -244,14 +252,6 @@
\def\inlinemessage #1{\dontleavehmode{\tttf#1}}
\def\displaymessage#1{\blank\inlinemessage{#1}\blank}
-% entities
-
-\def\xmlresolveentities
- {\ctxlua{xml.set_text_cleanup(xml.resolve_text_entities)}}
-
-\def\xmlkeepentities
- {\ctxlua{xml.set_text_cleanup()}}
-
\def\xmltraceentities
{\ctxlua{xml.set_text_cleanup(lxml.trace_text_entities)}%
\appendtoks\ctxlua{lxml.show_text_entities()}\to\everygoodbye}
@@ -268,6 +268,8 @@
% \setupxml[\c!method=mkiv,\c!default=\v!none] % mkiv only, undefined -> hidden
% \setupxml[\c!method=mkiv,\c!default=\v!text] % mkiv only, undefined -> text
+% \def\xmlctxdirective#1#2#3{\doif{#1}{clue}{\doif{#2}{page}}{\page[#3]}}
+
\chardef\xmlprocessingmode=0 % 0=mixed, 1=mkivonly, 2=mkivonly-default-text, 3=mkivonly-default-none
% \setupxml[method=mkiv,strip=yes,entities=yes,default=text]
@@ -276,26 +278,49 @@
\def\setupxml[#1]{\getparameters[\??xm][#1]\the\everysetupxml}
-\def\c!entities{entities}
+\def\c!entities{entities} % to be internationalized
\def\s!mkiv {mkiv}
\def\s!mkii {mkii}
+% entities
+
+\newif\ifautoXMLentities
+
+\def\xmlkeepentities{\ctxlua{lxml.reset_entityhandler()}}
+\def\xmlmkiientities{\ctxlua{lxml.set_mkii_entityhandler()}\autoXMLentitiestrue}
+\def\xmlmkiventities{\ctxlua{lxml.set_mkiv_entityhandler()}}
+
+\let\xmlresolveentities\xmlmkiventities % will become \xmlmkiventities
+
\letvalue{\??xm:1:\s!mkii }\zerocount
\letvalue{\??xm:1:\s!mkiv }\plusone
+
\letvalue{\??xm:2:\v!none }\plusone
\letvalue{\??xm:2:\v!text }\plustwo
\letvalue{\??xm:2:\v!hidden}\plusthree
+\letvalue{\??xm:ii:\v!yes }\xmlresolveentities
+\letvalue{\??xm:ii:\v!no }\xmlkeepentities
+\letvalue{\??xm:ii:\s!mkii}\xmlmkiientities
+\letvalue{\??xm:ii:\s!mkiv}\xmlmkiventities
+
+\letvalue{\??xm:iv:\v!yes }\xmlresolveentities
+\letvalue{\??xm:iv:\v!no }\xmlkeepentities
+\letvalue{\??xm:iv:\s!mkii}\xmlmkiventities
+\letvalue{\??xm:iv:\s!mkiv}\xmlmkiventities
+
\appendtoks
\chardef\xmlprocessingmode\executeifdefined{\??xm:1:\@@xmmethod}\zerocount
\ifcase\xmlprocessingmode
- % mkii
+ % mkii, permits both methods
+ \executeifdefined{\??xm:ii:\@@xmentities}\xmlkeepentities
\or
- % mkiv
-% \or
+ % mkiv, mkiv exclusively
\chardef\xmlprocessingmode\executeifdefined{\??xm:2:\@@xmdefault}\plusone
+ \executeifdefined{\??xm:iv:\@@xmentities}\xmlresolveentities
+ \else
+ % unset
\fi
- \doifelse\@@xmentities\v!yes\xmlresolveentities\xmlkeepentities
\ifcase\xmlprocessingmode
\ctxlua{characters.setmkiientities()}%
\else
@@ -306,7 +331,7 @@
{\ctxlua{xml.strip_cm_and_dt=false}}%
\to \everysetupxml
-\appendtoks\the\everysetupxml\to\everyjob
+\def\xmlinitialize{\the\everysetupxml}
\newcount\charactersactiveoffset \charactersactiveoffset="10000
diff --git a/tex/context/base/lxml-mis.lua b/tex/context/base/lxml-mis.lua
new file mode 100644
index 000000000..a117b1af9
--- /dev/null
+++ b/tex/context/base/lxml-mis.lua
@@ -0,0 +1,106 @@
+if not modules then modules = { } end modules ['lxml-mis'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat = table.concat
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, gsub = string.format, string.gsub
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+xml.escaped_pattern = escaped
+xml.unescaped_pattern = unescaped
+xml.cleansed_pattern = cleansed
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
diff --git a/tex/context/base/lxml-pth.lua b/tex/context/base/lxml-pth.lua
new file mode 100644
index 000000000..b1afc8d64
--- /dev/null
+++ b/tex/context/base/lxml-pth.lua
@@ -0,0 +1,1555 @@
+if not modules then modules = { } end modules ['lxml-pth'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
+local format, lower, gmatch, gsub, find = string.format, string.lower, string.gmatch, string.gsub, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers. Here we overload a previously defined
+function.
+--ldx]]--
+
+local trace_lpath = false
+
+if trackers then
+ trackers.register("xml.lpath", function(v) trace_lpath = v end)
+end
+
+local settrace = xml.settrace -- lxml-tab
+
+function xml.settrace(str,value)
+ if str == "lpath" then
+ trace_lpath = value or false
+ else
+ settrace(str,value) -- lxml-tab
+ end
+end
+
+--[[ldx--
+
We've now arrived at an intersting part: accessing the tree using a subset
+of and since we're not compatible we call it . We
+will explain more about its usage in other documents.
+--ldx]]--
+
+local lpathcalls = 0 -- statistics
+local lpathcached = 0 -- statistics
+
+xml.functions = xml.functions or { }
+xml.expressions = xml.expressions or { }
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+local actions = {
+ [10] = "stay",
+ [11] = "parent",
+ [12] = "subtree root",
+ [13] = "document root",
+ [14] = "any",
+ [15] = "many",
+ [16] = "initial",
+ [20] = "match",
+ [21] = "match one of",
+ [22] = "match and attribute eq",
+ [23] = "match and attribute ne",
+ [24] = "match one of and attribute eq",
+ [25] = "match one of and attribute ne",
+ [27] = "has attribute",
+ [28] = "has value",
+ [29] = "fast match",
+ [30] = "select",
+ [31] = "expression",
+ [40] = "processing instruction",
+}
+
+-- a rather dumb lpeg
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+-- instead of using functions we just parse a few names which saves a call
+-- later on
+
+local lp_position = P("position()") / "ps"
+local lp_index = P("index()") / "id"
+local lp_text = P("text()") / "tx"
+local lp_name = P("name()") / "(ns~='' and ns..':'..tg)" -- "((rt.ns~='' and rt.ns..':'..rt.tg) or '')"
+local lp_tag = P("tag()") / "tg" -- (rt.tg or '')
+local lp_ns = P("ns()") / "ns" -- (rt.ns or '')
+local lp_noequal = P("!=") / "~=" + P("<=") + P(">=") + P("==")
+local lp_doequal = P("=") / "=="
+local lp_attribute = P("@") / "" * Cc("(at['") * R("az","AZ","--","__")^1 * Cc("'] or '')")
+
+local lp_lua_function = C(R("az","AZ","--","__")^1 * (P(".") * R("az","AZ","--","__")^1)^1) * P("(") / function(t) -- todo: better . handling
+ return t .. "("
+end
+
+local lp_function = C(R("az","AZ","--","__")^1) * P("(") / function(t) -- todo: better . handling
+ if expressions[t] then
+ return "expressions." .. t .. "("
+ else
+ return "expressions.error("
+ end
+end
+
+local lparent = lpeg.P("(")
+local rparent = lpeg.P(")")
+local noparent = 1 - (lparent+rparent)
+local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
+local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
+
+-- if we use a dedicated namespace then we don't need to pass rt and k
+
+local lp_special = (C(P("name")+P("text")+P("tag"))) * value / function(t,s)
+ if expressions[t] then
+ if s then
+ return "expressions." .. t .. "(r,k," .. s ..")"
+ else
+ return "expressions." .. t .. "(r,k)"
+ end
+ else
+ return "expressions.error(" .. t .. ")"
+ end
+end
+
+local converter = lpeg.Cs ( (
+ lp_position +
+ lp_index +
+ lp_text + lp_name + -- fast one
+ lp_special +
+ lp_noequal + lp_doequal +
+ lp_attribute +
+ lp_lua_function +
+ lp_function +
+1 )^1 )
+
+-- expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1
+
+local template = [[
+ return function(expressions,r,d,k,e,dt,ns,tg,id,ps)
+ local at, tx = e.at or { }, dt[1] or ""
+ return %s
+ end
+]]
+
+local function make_expression(str)
+ str = converter:match(str)
+ return str, loadstring(format(template,str))()
+end
+
+local map = { }
+
+local space = S(' \r\n\t')
+local squote = S("'")
+local dquote = S('"')
+local lparent = P('(')
+local rparent = P(')')
+local atsign = P('@')
+local lbracket = P('[')
+local rbracket = P(']')
+local exclam = P('!')
+local period = P('.')
+local eq = P('==') + P('=')
+local ne = P('<>') + P('!=')
+local star = P('*')
+local slash = P('/')
+local colon = P(':')
+local bar = P('|')
+local hat = P('^')
+local valid = R('az', 'AZ', '09') + S('_-')
+local name_yes = C(valid^1 + star) * colon * C(valid^1 + star) -- permits ns:* *:tg *:*
+local name_nop = Cc("*") * C(valid^1)
+local name = name_yes + name_nop
+local number = C((S('+-')^0 * R('09')^1)) / tonumber
+local names = (bar^0 * name)^1
+local morenames = name * (bar^0 * name)^1
+local instructiontag = P('pi::')
+local spacing = C(space^0)
+local somespace = space^1
+local optionalspace = space^0
+local text = C(valid^0)
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local empty = 1-slash
+
+local is_eq = lbracket * atsign * name * eq * value * rbracket
+local is_ne = lbracket * atsign * name * ne * value * rbracket
+local is_attribute = lbracket * atsign * name * rbracket
+local is_value = lbracket * value * rbracket
+local is_number = lbracket * number * rbracket
+
+local nobracket = 1-(lbracket+rbracket) -- must be improved
+local is_expression = lbracket * C(((C(nobracket^1))/make_expression)) * rbracket
+
+local is_expression = lbracket * (C(nobracket^1))/make_expression * rbracket
+
+local is_one = name
+local is_none = exclam * name
+local is_one_of = ((lparent * names * rparent) + morenames)
+local is_none_of = exclam * ((lparent * names * rparent) + morenames)
+
+local stay = (period )
+local parent = (period * period ) / function( ) map[#map+1] = { 11 } end
+local subtreeroot = (slash + hat ) / function( ) map[#map+1] = { 12 } end
+local documentroot = (hat * hat ) / function( ) map[#map+1] = { 13 } end
+local any = (star ) / function( ) map[#map+1] = { 14 } end
+local many = (star * star ) / function( ) map[#map+1] = { 15 } end
+local initial = (hat * hat * hat ) / function( ) map[#map+1] = { 16 } end
+
+local match = (is_one ) / function(...) map[#map+1] = { 20, true , ... } end
+local match_one_of = (is_one_of ) / function(...) map[#map+1] = { 21, true , ... } end
+local dont_match = (is_none ) / function(...) map[#map+1] = { 20, false, ... } end
+local dont_match_one_of = (is_none_of ) / function(...) map[#map+1] = { 21, false, ... } end
+
+local match_and_eq = (is_one * is_eq ) / function(...) map[#map+1] = { 22, true , ... } end
+local match_and_ne = (is_one * is_ne ) / function(...) map[#map+1] = { 23, true , ... } end
+local dont_match_and_eq = (is_none * is_eq ) / function(...) map[#map+1] = { 22, false, ... } end
+local dont_match_and_ne = (is_none * is_ne ) / function(...) map[#map+1] = { 23, false, ... } end
+
+local match_one_of_and_eq = (is_one_of * is_eq ) / function(...) map[#map+1] = { 24, true , ... } end
+local match_one_of_and_ne = (is_one_of * is_ne ) / function(...) map[#map+1] = { 25, true , ... } end
+local dont_match_one_of_and_eq = (is_none_of * is_eq ) / function(...) map[#map+1] = { 24, false, ... } end
+local dont_match_one_of_and_ne = (is_none_of * is_ne ) / function(...) map[#map+1] = { 25, false, ... } end
+
+local has_attribute = (is_one * is_attribute) / function(...) map[#map+1] = { 27, true , ... } end
+local has_value = (is_one * is_value ) / function(...) map[#map+1] = { 28, true , ... } end
+local dont_has_attribute = (is_none * is_attribute) / function(...) map[#map+1] = { 27, false, ... } end
+local dont_has_value = (is_none * is_value ) / function(...) map[#map+1] = { 28, false, ... } end
+local position = (is_one * is_number ) / function(...) map[#map+1] = { 30, true, ... } end
+local dont_position = (is_none * is_number ) / function(...) map[#map+1] = { 30, false, ... } end
+
+local expression = (is_one * is_expression)/ function(...) map[#map+1] = { 31, true, ... } end
+local dont_expression = (is_none * is_expression)/ function(...) map[#map+1] = { 31, false, ... } end
+
+local self_expression = ( is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, true, "*", "*", ... } end
+local dont_self_expression = (exclam * is_expression) / function(...) if #map == 0 then map[#map+1] = { 11 } end
+ map[#map+1] = { 31, false, "*", "*", ... } end
+
+local instruction = (instructiontag * text ) / function(...) map[#map+1] = { 40, ... } end
+local nothing = (empty ) / function( ) map[#map+1] = { 15 } end -- 15 ?
+local crap = (1-slash)^1
+
+-- a few ugly goodies:
+
+local docroottag = P('^^') / function( ) map[#map+1] = { 12 } end
+local subroottag = P('^') / function( ) map[#map+1] = { 13 } end
+local roottag = P('root::') / function( ) map[#map+1] = { 12 } end
+local parenttag = P('parent::') / function( ) map[#map+1] = { 11 } end
+local childtag = P('child::')
+local selftag = P('self::')
+
+-- there will be more and order will be optimized
+
+local selector = (
+ instruction +
+-- many + any + -- brrr, not here !
+ parent + stay +
+ dont_position + position +
+ dont_match_one_of_and_eq + dont_match_one_of_and_ne +
+ match_one_of_and_eq + match_one_of_and_ne +
+ dont_match_and_eq + dont_match_and_ne +
+ match_and_eq + match_and_ne +
+ dont_expression + expression +
+ dont_self_expression + self_expression +
+ has_attribute + has_value +
+ dont_match_one_of + match_one_of +
+ dont_match + match +
+ many + any +
+ crap + empty
+)
+
+local grammar = P { "startup",
+ startup = (initial + documentroot + subtreeroot + roottag + docroottag + subroottag)^0 * V("followup"),
+ followup = ((slash + parenttag + childtag + selftag)^0 * selector)^1,
+}
+
+local function compose(str)
+ if not str or str == "" then
+ -- wildcard
+ return true
+ elseif str == '/' then
+ -- root
+ return false
+ else
+ map = { }
+ grammar:match(str)
+ if #map == 0 then
+ return true
+ else
+ local m = map[1][1]
+ if #map == 1 then
+ if m == 14 or m == 15 then
+ -- wildcard
+ return true
+ elseif m == 12 then
+ -- root
+ return false
+ end
+ elseif #map == 2 and m == 12 and map[2][1] == 20 then
+ -- return { { 29, map[2][2], map[2][3], map[2][4], map[2][5] } }
+ map[2][1] = 29
+ return { map[2] }
+ end
+ if m ~= 11 and m ~= 12 and m ~= 13 and m ~= 14 and m ~= 15 and m ~= 16 then
+ insert(map, 1, { 16 })
+ end
+ -- print(gsub(table.serialize(map),"[ \n]+"," "))
+ return map
+ end
+ end
+end
+
+local cache = { }
+
+function xml.lpath(pattern,trace)
+ lpathcalls = lpathcalls + 1
+ if type(pattern) == "string" then
+ local result = cache[pattern]
+ if result == nil then -- can be false which is valid -)
+ result = compose(pattern)
+ cache[pattern] = result
+ lpathcached = lpathcached + 1
+ end
+ if trace or trace_lpath then
+ xml.lshow(result)
+ end
+ return result
+ else
+ return pattern
+ end
+end
+
+function xml.cached_patterns()
+ return cache
+end
+
+-- we run out of locals (limited to 200)
+--
+-- local fallbackreport = (texio and texio.write) or io.write
+
+function xml.lshow(pattern,report)
+-- report = report or fallbackreport
+ report = report or (texio and texio.write) or io.write
+ local lp = xml.lpath(pattern)
+ if lp == false then
+ report(" -: root\n")
+ elseif lp == true then
+ report(" -: wildcard\n")
+ else
+ if type(pattern) == "string" then
+ report(format("pattern: %s\n",pattern))
+ end
+ for k=1,#lp do
+ local v = lp[k]
+ if #v > 1 then
+ local t = { }
+ for i=2,#v do
+ local vv = v[i]
+ if type(vv) == "string" then
+ t[#t+1] = (vv ~= "" and vv) or "#"
+ elseif type(vv) == "boolean" then
+ t[#t+1] = (vv and "==") or "<>"
+ end
+ end
+ report(format("%2i: %s %s -> %s\n", k,v[1],actions[v[1]],concat(t," ")))
+ else
+ report(format("%2i: %s %s\n", k,v[1],actions[v[1]]))
+ end
+ end
+ end
+end
+
+function xml.xshow(e,...) -- also handy when report is given, use () to isolate first e
+ local t = { ... }
+-- local report = (type(t[#t]) == "function" and t[#t]) or fallbackreport
+ local report = (type(t[#t]) == "function" and t[#t]) or (texio and texio.write) or io.write
+ if e == nil then
+ report("\n")
+ elseif type(e) ~= "table" then
+ report(tostring(e))
+ elseif e.tg then
+ report(tostring(e) .. "\n")
+ else
+ for i=1,#e do
+ report(tostring(e[i]) .. "\n")
+ end
+ end
+end
+
+--[[ldx--
+
An is converted to a table with instructions for traversing the
+tree. Hoever, simple cases are signaled by booleans. Because we don't know in
+advance what we want to do with the found element the handle gets three arguments:
+
+
+r : the root element of the data table
+d : the data table of the result
+t : the index in the data table of the result
+
+
+
Access to the root and data table makes it possible to construct insert and delete
+functions.
+--ldx]]--
+
+local functions = xml.functions
+local expressions = xml.expressions
+
+expressions.contains = string.find
+expressions.find = string.find
+expressions.upper = string.upper
+expressions.lower = string.lower
+expressions.number = tonumber
+expressions.boolean = toboolean
+
+expressions.oneof = function(s,...) -- slow
+ local t = {...} for i=1,#t do if s == t[i] then return true end end return false
+end
+
+expressions.error = function(str)
+ xml.error_handler("unknown function in lpath expression",str or "?")
+ return false
+end
+
+functions.text = function(root,k,n) -- unchecked, maybe one deeper
+ local t = type(t)
+ if t == "string" then
+ return t
+ else -- todo n
+ local rdt = root.dt
+ return (rdt and rdt[k]) or root[k] or ""
+ end
+end
+
+functions.name = function(d,k,n) -- ns + tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ if found then
+ local ns, tg = found.rn or found.ns or "", found.tg
+ if ns ~= "" then
+ return ns .. ":" .. tg
+ else
+ return tg
+ end
+ else
+ return ""
+ end
+end
+
+functions.tag = function(d,k,n) -- only tg
+ local found = false
+ n = n or 0
+ if not k then
+ -- not found
+ elseif n == 0 then
+ local dk = d[k]
+ found = dk and (type(dk) == "table") and dk
+ elseif n < 0 then
+ for i=k-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == -1 then
+ found = di
+ break
+ else
+ n = n + 1
+ end
+ end
+ end
+ else
+ for i=k+1,#d,1 do
+ local di = d[i]
+ if type(di) == "table" then
+ if n == 1 then
+ found = di
+ break
+ else
+ n = n - 1
+ end
+ end
+ end
+ end
+ return (found and found.tg) or ""
+end
+
+expressions.text = functions.text
+expressions.name = functions.name
+expressions.tag = functions.tag
+
+local function traverse(root,pattern,handle,reverse,index,parent,wildcard) -- multiple only for tags, not for namespaces
+ if not root then -- error
+ return false
+ elseif pattern == false then -- root
+ handle(root,root.dt,root.ri)
+ return false
+ elseif pattern == true then -- wildcard
+ local rootdt = root.dt
+ if rootdt then
+ local start, stop, step = 1, #rootdt, 1
+ if reverse then
+ start, stop, step = stop, start, -1
+ end
+ for k=start,stop,step do
+ if handle(root,rootdt,root.ri or k) then return false end
+ if not traverse(rootdt[k],true,handle,reverse) then return false end
+ end
+ end
+ return false
+ elseif root.dt then
+ index = index or 1
+ local action = pattern[index]
+ local command = action[1]
+ if command == 29 then -- fast case /oeps
+ local rootdt = root.dt
+ for k=1,#rootdt do
+ local e = rootdt[k]
+ local tg = e.tg
+ if e.tg then
+ local ns = e.rn or e.ns
+ local ns_a, tg_a = action[3], action[4]
+ local matched = (ns_a == "*" or ns == ns_a) and (tg_a == "*" or tg == tg_a)
+ if not action[2] then matched = not matched end
+ if matched then
+ if handle(root,rootdt,k) then return false end
+ end
+ end
+ end
+ elseif command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ if (command == 16 or command == 12) and index == 1 then -- initial
+ -- wildcard = true
+ wildcard = command == 16 -- ok?
+ index = index + 1
+ action = pattern[index]
+ command = action and action[1] or 0 -- something is wrong
+ end
+ if command == 11 then -- parent
+ local ep = root.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ else
+ local rootdt = root.dt
+ local start, stop, step, n, dn = 1, #rootdt, 1, 0, 1
+ if command == 30 then
+ if action[5] < 0 then
+ start, stop, step = stop, start, -1
+ dn = -1
+ end
+ elseif reverse and index == #pattern then
+ start, stop, step = stop, start, -1
+ end
+ local idx = 0
+ local hsh = { } -- this will slooow down the lot
+ for k=start,stop,step do -- we used to have functions for all but a case is faster
+ local e = rootdt[k]
+ local ns, tg = e.rn or e.ns, e.tg
+ if tg then
+ -- we can optimize this for simple searches, but it probably does not pay off
+ hsh[tg] = (hsh[tg] or 0) + 1
+ idx = idx + 1
+ if command == 30 then
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ n = n + dn
+ if n == action[5] then
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ break
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ else
+ local matched, multiple = false, false
+ if command == 20 then -- match
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 21 then -- match one of
+ multiple = true
+ for i=3,#action,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ elseif command == 22 then -- eq
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ matched = matched and e.at[action[6]] == action[7]
+ elseif command == 23 then -- ne
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = mached and e.at[action[6]] ~= action[7]
+ elseif command == 24 then -- one of eq
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] == action[#action]
+ elseif command == 25 then -- one of ne
+ multiple = true
+ for i=3,#action-2,2 do
+ local ns_a, tg_a = action[i], action[i+1]
+ if (ns_a == "*" or ns == ns_a) and (tg == "*" or tg == tg_a) then
+ matched = true
+ break
+ end
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[#action-1]] ~= action[#action]
+ elseif command == 27 then -- has attribute
+ local ns_a, tg_a = action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and e.at[action[5]]
+ elseif command == 28 then -- has value
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ matched = matched and edt and edt[1] == action[5]
+ elseif command == 31 then
+ local edt, ns_a, tg_a = e.dt, action[3], action[4]
+ if tg == tg_a then
+ matched = ns_a == "*" or ns == ns_a
+ elseif tg_a == '*' then
+ matched, multiple = ns_a == "*" or ns == ns_a, true
+ else
+ matched = false
+ end
+ if not action[2] then matched = not matched end
+ if matched then
+ matched = action[6](expressions,root,rootdt,k,e,edt,ns,tg,idx,hsh[tg] or 1)
+ end
+ end
+ if matched then -- combine tg test and at test
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ if wildcard then
+ if multiple then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ else
+ -- maybe or multiple; anyhow, check on (section|title) vs just section and title in example in lxml
+ if not traverse(e,pattern,handle,reverse,index,root) then return false end
+ end
+ end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 14 then -- any
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root) then return false end
+ end
+ elseif command == 15 then -- many
+ if index == #pattern then
+ if handle(root,rootdt,root.ri or k) then return false end
+ else
+ if not traverse(e,pattern,handle,reverse,index+1,root,true) then return false end
+ end
+ -- not here : 11
+ elseif command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,root,index+1) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif command == 40 and e.special and tg == "@pi@" then -- pi
+ local pi = action[2]
+ if pi ~= "" then
+ local pt = e.dt[1]
+ if pt and pt:find(pi) then
+ if handle(root,rootdt,k) then
+ return false
+ end
+ end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ elseif wildcard then
+ if not traverse(e,pattern,handle,reverse,index,root,true) then return false end
+ end
+ end
+ else
+ -- not here : 11
+ if command == 11 then -- parent
+ local ep = e.__p__ or parent
+ if index < #pattern then
+ if not traverse(ep,pattern,handle,reverse,index+1,root) then return false end
+ elseif handle(root,rootdt,k) then
+ return false
+ end
+ break -- else loop
+ end
+ end
+ end
+ end
+ end
+ end
+ return true
+end
+
+xml.traverse = traverse
+
+--[[ldx--
+
Next come all kind of locators and manipulators. The most generic function here
+is xml.filter(root,pattern). All registers functions in the filters namespace
+can be path of a search path, as in:
+
+
+local r, d, k = xml.filter(root,"/a/b/c/position(4)"
+
+--ldx]]--
+
+local traverse, lpath, convert = xml.traverse, xml.lpath, xml.convert
+
+xml.filters = { }
+
+function xml.filters.default(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.attributes(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ if ekat then
+ if arguments then
+ return ekat[arguments] or "", rt, dt, dk
+ else
+ return ekat, rt, dt, dk
+ end
+ else
+ return { }, rt, dt, dk
+ end
+end
+
+function xml.filters.reverse(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.count(root,pattern,everything)
+ local n = 0
+ traverse(root, lpath(pattern), function(r,d,t)
+ if everything or type(d[t]) == "table" then
+ n = n + 1
+ end
+ end)
+ return n
+end
+
+function xml.filters.elements(root, pattern) -- == all
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e then
+ t[#t+1] = e
+ end
+ end)
+ return t
+end
+
+function xml.filters.texts(root, pattern)
+ local t = { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local e = d[k]
+ if e and e.dt then
+ t[#t+1] = e.dt
+ end
+ end)
+ return t
+end
+
+function xml.filters.first(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end)
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.last(root,pattern)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt,dt,dk = r,d,k return true end, 'reverse')
+ return dt and dt[dk], rt, dt, dk
+end
+
+function xml.filters.index(root,pattern,arguments)
+ local rt, dt, dk, reverse, i = nil, nil, nil, false, tonumber(arguments or '1') or 1
+ if i and i ~= 0 then
+ if i < 0 then
+ reverse, i = true, -i
+ end
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk, i = r, d, k, i-1 return i == 0 end, reverse)
+ if i == 0 then
+ return dt and dt[dk], rt, dt, dk
+ end
+ end
+ return nil, nil, nil, nil
+end
+
+function xml.filters.attribute(root,pattern,arguments)
+ local rt, dt, dk
+ traverse(root, lpath(pattern), function(r,d,k) rt, dt, dk = r, d, k return true end)
+ local ekat = (dt and dt[dk] and dt[dk].at) or (rt and rt.at)
+ return (ekat and (ekat[arguments] or ekat[gsub(arguments,"^([\"\'])(.*)%1$","%2")])) or ""
+end
+
+function xml.filters.text(root,pattern,arguments) -- ?? why index, tostring slow
+ local dtk, rt, dt, dk = xml.filters.index(root,pattern,arguments)
+ if dtk then -- n
+ local dtkdt = dtk.dt
+ if not dtkdt then
+ return "", rt, dt, dk
+ elseif #dtkdt == 1 and type(dtkdt[1]) == "string" then
+ return dtkdt[1], rt, dt, dk
+ else
+ return xml.tostring(dtkdt), rt, dt, dk
+ end
+ else
+ return "", rt, dt, dk
+ end
+end
+
+function xml.filters.tag(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.tag(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+function xml.filters.name(root,pattern,n)
+ local tag = ""
+ traverse(root, lpath(pattern), function(r,d,k)
+ tag = xml.functions.name(d,k,n and tonumber(n))
+ return true
+ end)
+ return tag
+end
+
+--[[ldx--
+
For splitting the filter function from the path specification, we can
+use string matching or lpeg matching. Here the difference in speed is
+neglectable but the lpeg variant is more robust.
+--ldx]]--
+
+-- not faster but hipper ... although ... i can't get rid of the trailing / in the path
+
+local P, S, R, C, V, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc
+
+local slash = P('/')
+local name = (R("az","AZ","--","__"))^1
+local path = C(((1-slash)^0 * slash)^1)
+local argument = P { "(" * C(((1 - S("()")) + V(1))^0) * ")" }
+local action = Cc(1) * path * C(name) * argument
+local attribute = Cc(2) * path * P('@') * C(name)
+local direct = Cc(3) * Cc("../*") * slash^0 * C(name) * argument
+
+local parser = direct + action + attribute
+
+local filters = xml.filters
+local attribute_filter = xml.filters.attributes
+local default_filter = xml.filters.default
+
+-- todo: also hash, could be gc'd
+
+function xml.filter(root,pattern)
+ local kind, a, b, c = parser:match(pattern)
+ if kind == 1 or kind == 3 then
+ return (filters[b] or default_filter)(root,a,c)
+ elseif kind == 2 then
+ return attribute_filter(root,a,b)
+ else
+ return default_filter(root,pattern)
+ end
+end
+
+--~ slightly faster, but first we need a proper test file
+--~
+--~ local hash = { }
+--~
+--~ function xml.filter(root,pattern)
+--~ local h = hash[pattern]
+--~ if not h then
+--~ local kind, a, b, c = parser:match(pattern)
+--~ if kind == 1 then
+--~ h = { kind, filters[b] or default_filter, a, b, c }
+--~ elseif kind == 2 then
+--~ h = { kind, attribute_filter, a, b, c }
+--~ else
+--~ h = { kind, default_filter, a, b, c }
+--~ end
+--~ hash[pattern] = h
+--~ end
+--~ local kind = h[1]
+--~ if kind == 1 then
+--~ return h[2](root,h[2],h[4])
+--~ elseif kind == 2 then
+--~ return h[2](root,h[2],h[3])
+--~ else
+--~ return h[2](root,pattern)
+--~ end
+--~ end
+
+--[[ldx--
+
The following functions collect elements and texts.
+--ldx]]--
+
+-- still somewhat bugged
+
+function xml.collect_elements(root, pattern, ignorespaces)
+ local rr, dd = { }, { }
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk then
+ if ignorespaces and type(dk) == "string" and dk:find("[^%S]") then
+ -- ignore
+ else
+ local n = #rr+1
+ rr[n], dd[n] = r, dk
+ end
+ end
+ end)
+ return dd, rr
+end
+
+function xml.collect_texts(root, pattern, flatten)
+ local t = { } -- no r collector
+ traverse(root, lpath(pattern), function(r,d,k)
+ if d then
+ local ek = d[k]
+ local tx = ek and ek.dt
+ if flatten then
+ if tx then
+ t[#t+1] = xml.tostring(tx) or ""
+ else
+ t[#t+1] = ""
+ end
+ else
+ t[#t+1] = tx or ""
+ end
+ else
+ t[#t+1] = ""
+ end
+ end)
+ return t
+end
+
+function xml.collect_tags(root, pattern, nonamespace)
+ local t = { }
+ xml.traverse(root, xml.lpath(pattern), function(r,d,k)
+ local dk = d and d[k]
+ if dk and type(dk) == "table" then
+ local ns, tg = e.ns, e.tg
+ if nonamespace then
+ t[#t+1] = tg -- if needed we can return an extra table
+ elseif ns == "" then
+ t[#t+1] = tg
+ else
+ t[#t+1] = ns .. ":" .. tg
+ end
+ end
+ end)
+ return #t > 0 and {}
+end
+
+--[[ldx--
+
Often using an iterators looks nicer in the code than passing handler
+functions. The book describes how to use coroutines for that
+purpose (). This permits
+code like:
+
+
+for r, d, k in xml.elements(xml.load('text.xml'),"title") do
+ print(d[k])
+end
+
+
+
Which will print all the titles in the document. The iterator variant takes
+1.5 times the runtime of the function variant which is due to the overhead in
+creating the wrapper. So, instead of:
+
+
+function xml.filters.first(root,pattern)
+ for rt,dt,dk in xml.elements(root,pattern)
+ return dt and dt[dk], rt, dt, dk
+ end
+ return nil, nil, nil, nil
+end
+
+
+
We use the function variants in the filters.
+--ldx]]--
+
+local wrap, yield = coroutine.wrap, coroutine.yield
+
+function xml.elements(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), yield, reverse) end)
+end
+
+function xml.elements_only(root,pattern,reverse)
+ return wrap(function() traverse(root, lpath(pattern), function(r,d,k) yield(d[k]) end, reverse) end)
+end
+
+function xml.each_element(root, pattern, handle, reverse)
+ local ok
+ traverse(root, lpath(pattern), function(r,d,k) ok = true handle(r,d,k) end, reverse)
+ return ok
+end
+
+function xml.process_elements(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then
+ for i=1,#dkdt do
+ local v = dkdt[i]
+ if v.tg then handle(v) end
+ end
+ end
+ end)
+end
+
+function xml.process_attributes(root, pattern, handle)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local ek = d[k]
+ local a = ek.at or { }
+ handle(a)
+ if next(a) then -- next is faster than type (and >0 test)
+ ek.at = a
+ else
+ ek.at = nil
+ end
+ end)
+end
+
+--[[ldx--
+
We've now arrives at the functions that manipulate the tree.
+--ldx]]--
+
+function xml.inject_element(root, pattern, element, prepend)
+ if root and element then
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=1,#matches do
+ local m = matches[i]
+ local r, d, k, element, edt = m[1], m[2], m[3], m[4], nil
+ if element.ri then
+ element = element.dt[element.ri].dt
+ else
+ element = element.dt
+ end
+ if r.ri then
+ edt = r.dt[r.ri].dt
+ else
+ edt = d and d[k] and d[k].dt
+ end
+ if edt then
+ local be, af
+ if prepend then
+ be, af = xml.copy(element), edt
+ else
+ be, af = edt, xml.copy(element)
+ end
+ for i=1,#af do
+ be[#be+1] = af[i]
+ end
+ if r.ri then
+ r.dt[r.ri].dt = be
+ else
+ d[k].dt = be
+ end
+ else
+ -- r.dt = element.dt -- todo
+ end
+ end
+ end
+ end
+end
+
+-- todo: copy !
+
+function xml.insert_element(root, pattern, element, before) -- todo: element als functie
+ if root and element then
+ if pattern == "/" then
+ xml.inject_element(root, pattern, element, before)
+ else
+ local matches, collect = { }, nil
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ collect = function(r,d,k) matches[#matches+1] = { r, d, k, element } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ local r, d, k, element = m[1], m[2], m[3], m[4]
+ if not before then k = k + 1 end
+ if element.tg then
+ insert(d,k,element) -- untested
+--~ elseif element.dt then
+--~ for _,v in ipairs(element.dt) do -- i added
+--~ insert(d,k,v)
+--~ k = k + 1
+--~ end
+--~ end
+ else
+ local edt = element.dt
+ if edt then
+ for i=1,#edt do
+ insert(d,k,edt[i])
+ k = k + 1
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+xml.insert_element_after = xml.insert_element
+xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end
+xml.inject_element_after = xml.inject_element
+xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end
+
+function xml.delete_element(root, pattern)
+ local matches, deleted = { }, { }
+ local collect = function(r,d,k) matches[#matches+1] = { r, d, k } end
+ traverse(root, lpath(pattern), collect)
+ for i=#matches,1,-1 do
+ local m = matches[i]
+ deleted[#deleted+1] = remove(m[2],m[3])
+ end
+ return deleted
+end
+
+function xml.replace_element(root, pattern, element)
+ if type(element) == "string" then
+ element = convert(element,true)
+ end
+ if element and element.ri then
+ element = element.dt[element.ri]
+ end
+ if element then
+ traverse(root, lpath(pattern), function(rm, d, k)
+ d[k] = element.dt -- maybe not clever enough
+ end)
+ end
+end
+
+local function load_data(name) -- == io.loaddata
+ local f, data = io.open(name), ""
+ if f then
+ data = f:read("*all",'b') -- 'b' ?
+ f:close()
+ end
+ return data
+end
+
+function xml.include(xmldata,pattern,attribute,recursive,loaddata)
+ -- parse="text" (default: xml), encoding="" (todo)
+ -- attribute = attribute or 'href'
+ pattern = pattern or 'include'
+ loaddata = loaddata or load_data
+ local function include(r,d,k)
+ local ek, name = d[k], nil
+ if not attribute or attribute == "" then
+ local ekdt = ek.dt
+ name = (type(ekdt) == "table" and ekdt[1]) or ekdt
+ end
+ if not name then
+ if ek.at then
+ for a in gmatch(attribute or "href","([^|]+)") do
+ name = ek.at[a]
+ if name then break end
+ end
+ end
+ end
+ local data = (name and name ~= "" and loaddata(name)) or ""
+ if data == "" then
+ xml.empty(d,k)
+ elseif ek.at["parse"] == "text" then -- for the moment hard coded
+ d[k] = xml.escaped(data)
+ else
+ local xi = xml.convert(data)
+ if not xi then
+ xml.empty(d,k)
+ else
+ if recursive then
+ xml.include(xi,pattern,attribute,recursive,loaddata)
+ end
+ xml.assign(d,k,xi)
+ end
+ end
+ end
+ xml.each_element(xmldata, pattern, include)
+end
+
+function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space !
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dkdt = d[k].dt
+ if dkdt then -- can be optimized
+ local t = { }
+ for i=1,#dkdt do
+ local str = dkdt[i]
+ if type(str) == "string" then
+
+ if str == "" then
+ -- stripped
+ else
+ if nolines then
+ str = gsub(str,"[ \n\r\t]+"," ")
+ end
+ if str == "" then
+ -- stripped
+ else
+ t[#t+1] = str
+ end
+ end
+ else
+ t[#t+1] = str
+ end
+ end
+ d[k].dt = t
+ end
+ end)
+end
+
+local function rename_space(root, oldspace, newspace) -- fast variant
+ local ndt = #root.dt
+ for i=1,ndt or 0 do
+ local e = root[i]
+ if type(e) == "table" then
+ if e.ns == oldspace then
+ e.ns = newspace
+ if e.rn then
+ e.rn = newspace
+ end
+ end
+ local edt = e.dt
+ if edt then
+ rename_space(edt, oldspace, newspace)
+ end
+ end
+ end
+end
+
+xml.rename_space = rename_space
+
+function xml.remap_tag(root, pattern, newtg)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].tg = newtg
+ end)
+end
+function xml.remap_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ d[k].ns = newns
+ end)
+end
+function xml.check_namespace(root, pattern, newns)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ if (not dk.rn or dk.rn == "") and dk.ns == "" then
+ dk.rn = newns
+ end
+ end)
+end
+function xml.remap_name(root, pattern, newtg, newns, newrn)
+ traverse(root, lpath(pattern), function(r,d,k)
+ local dk = d[k]
+ dk.tg = newtg
+ dk.ns = newns
+ dk.rn = newrn
+ end)
+end
+
+function xml.filters.found(root,pattern,check_content)
+ local found = false
+ traverse(root, lpath(pattern), function(r,d,k)
+ if check_content then
+ local dk = d and d[k]
+ found = dk and dk.dt and next(dk.dt) and true
+ else
+ found = true
+ end
+ return true
+ end)
+ return found
+end
+
+--[[ldx--
+
The following helper functions best belong to the lmxl-ini
+module. Some are here because we need then in the mk
+document and other manuals, others came up when playing with
+this module. Since this module is also used in we've
+put them here instead of loading mode modules there then needed.
+--ldx]]--
+
+function xml.gsub(t,old,new)
+ local dt = t.dt
+ if dt then
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "string" then
+ dt[k] = gsub(v,old,new)
+ else
+ xml.gsub(v,old,new)
+ end
+ end
+ end
+end
+
+function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual
+ if d and k and d[k-1] and type(d[k-1]) == "string" then
+ local s = d[k-1]:match("\n(%s+)")
+ xml.gsub(dk,"\n"..string.rep(" ",#s),"\n")
+ end
+end
+
+function xml.serialize_path(root,lpath,handle)
+ local dk, r, d, k = xml.first(root,lpath)
+ dk = xml.copy(dk)
+ xml.strip_leading_spaces(dk,d,k)
+ xml.serialize(dk,handle)
+end
+
+--~ xml.escapes = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"' }
+--~ xml.unescapes = { } for k,v in pairs(xml.escapes) do xml.unescapes[v] = k end
+
+--~ function xml.escaped (str) return (gsub(str,"(.)" , xml.escapes )) end
+--~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end
+--~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>"
+
+local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs
+
+-- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg
+--
+-- 1021:0335:0287:0247
+
+-- 10 * 1000 * "oeps< oeps> oeps& asfjhalskfjh alskfjh alskfjh alskfjh ;al J;LSFDJ"
+--
+-- 1559:0257:0288:0190 (last one suggested by roberto)
+
+-- escaped = Cs((S("<&>") / xml.escapes + 1)^0)
+-- escaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+local normal = (1 - S("<&>"))^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local escaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 1000 * "oeps< oeps> oeps&" : gsub:lpeg == 0153:0280:0151:0080 (last one by roberto)
+
+-- unescaped = Cs((S("<")/"<" + S(">")/">" + S("&")/"&" + 1)^0)
+-- unescaped = Cs((((P("&")/"") * (P("lt")/"<" + P("gt")/">" + P("amp")/"&") * (P(";")/"")) + 1)^0)
+local normal = (1 - S"&")^0
+local special = P("<")/"<" + P(">")/">" + P("&")/"&"
+local unescaped = Cs(normal * (special * normal)^0)
+
+-- 100 * 5000 * "oeps oeps oeps " : gsub:lpeg == 623:501 msec (short tags, less difference)
+
+local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0)
+
+function xml.escaped (str) return escaped :match(str) end
+function xml.unescaped(str) return unescaped:match(str) end
+function xml.cleansed (str) return cleansed :match(str) end
+
+function xml.join(t,separator,lastseparator)
+ if #t > 0 then
+ local result = { }
+ for k,v in pairs(t) do
+ result[k] = xml.tostring(v)
+ end
+ if lastseparator then
+ return concat(result,separator or "",1,#result-1) .. (lastseparator or "") .. result[#result]
+ else
+ return concat(result,separator)
+ end
+ else
+ return ""
+ end
+end
+
+function xml.statistics()
+ return {
+ lpathcalls = lpathcalls,
+ lpathcached = lpathcached,
+ }
+end
+
+-- xml.set_text_cleanup(xml.show_text_entities)
+-- xml.set_text_cleanup(xml.resolve_text_entities)
+
+--~ xml.lshow("/../../../a/(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!(b|c)[@d='e']/f")
+--~ xml.lshow("/../../../a/!b[@d!='e']/f")
+
+--~ x = xml.convert([[
+--~
+--~ 01
+--~ 02
+--~ 03
+--~ OK
+--~ 05
+--~ 06
+--~ ALSO OK
+--~
+--~ ]])
+
+--~ xml.settrace("lpath",true)
+
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == 'ok']"))
+--~ xml.xshow(xml.first(x,"b[position() > 2 and position() < 5 and text() == upper('ok')]"))
+--~ xml.xshow(xml.first(x,"b[@n=='03' or @n=='08']"))
+--~ xml.xshow(xml.all (x,"b[number(@n)>2 and number(@n)<6]"))
+--~ xml.xshow(xml.first(x,"b[find(text(),'ALSO')]"))
+
+--~ str = [[
+--~
+--~
+--~ my secret
+--~
+--~ ]]
+
+--~ x = xml.convert([[
+--~ 0102xx03OK
+--~ ]])
+--~ xml.xshow(xml.first(x,"b[tag(2) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-1) == 'x']"))
+--~ xml.xshow(xml.first(x,"b[tag(-2) == 'x']"))
+
+--~ print(xml.filter(x,"b/tag(2)"))
+--~ print(xml.filter(x,"b/tag(1)"))
diff --git a/tex/context/base/lxml-tab.lua b/tex/context/base/lxml-tab.lua
new file mode 100644
index 000000000..a35e64270
--- /dev/null
+++ b/tex/context/base/lxml-tab.lua
@@ -0,0 +1,783 @@
+if not modules then modules = { } end modules ['lxml-tab'] = {
+ version = 1.001,
+ comment = "this module is the basis for the lxml-* ones",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
The parser used here is inspired by the variant discussed in the lua book, but
+handles comment and processing instructions, has a different structure, provides
+parent access; a first version used different trickery but was less optimized to we
+went this route. First we had a find based parser, now we have an based one.
+The find based parser can be found in l-xml-edu.lua along with other older code.
+
+
Expecially the lpath code is experimental, we will support some of xpath, but
+only things that make sense for us; as compensation it is possible to hook in your
+own functions. Apart from preprocessing content for we also need
+this module for process management, like handling and
+files.
Beware, the interface may change. For instance at, ns, tg, dt may get more
+verbose names. Once the code is stable we will also remove some tracing and
+optimize the code.
+--ldx]]--
+
+xml = xml or { }
+
+--~ local xml = xml
+
+local concat, remove, insert = table.concat, table.remove, table.insert
+local type, next, setmetatable = type, next, setmetatable
+local format, lower, find = string.format, string.lower, string.find
+
+--[[ldx--
+
This module can be used stand alone but also inside in
+which case it hooks into the tracker code. Therefore we provide a few
+functions that set the tracers.
+--ldx]]--
+
+local trace_remap = false
+
+if trackers then
+ trackers.register("xml.remap", function(v) trace_remap = v end)
+end
+
+function xml.settrace(str,value)
+ if str == "remap" then
+ trace_remap = value or false
+ end
+end
+
+--[[ldx--
+
First a hack to enable namespace resolving. A namespace is characterized by
+a . The following function associates a namespace prefix with a
+pattern. We use , which in this case is more than twice as fast as a
+find based solution where we loop over an array of patterns. Less code and
+much cleaner.
The next function also registers a namespace, but this time we map a
+given namespace prefix onto a registered one, using the given
+. This used for attributes like xmlns:m.
+
+
+xml.checkns("m","http://www.w3.org/mathml")
+
+--ldx]]--
+
+function xml.checkns(namespace,url)
+ local ns = parse:match(lower(url))
+ if ns and namespace ~= ns then
+ xml.xmlns[namespace] = ns
+ end
+end
+
+--[[ldx--
+
Next we provide a way to turn an into a registered
+namespace. This used for the xmlns attribute.
A namespace in an element can be remapped onto the registered
+one efficiently by using the xml.xmlns table.
+--ldx]]--
+
+--[[ldx--
+
This version uses . We follow the same approach as before, stack and top and
+such. This version is about twice as fast which is mostly due to the fact that
+we don't have to prepare the stream for cdata, doctype etc etc. This variant is
+is dedicated to Luigi Scarso, who challenged me with 40 megabyte files that
+took 12.5 seconds to load (1.5 for file io and the rest for tree building). With
+the implementation we got that down to less 7.3 seconds. Loading the 14
+ interface definition files (2.6 meg) went down from 1.05 seconds to 0.55.
+
+
Next comes the parser. The rather messy doctype definition comes in many
+disguises so it is no surprice that later on have to dedicate quite some
+ code to it.
+
+
+
+
+
+
+
+
+
+
+
The code may look a bit complex but this is mostly due to the fact that we
+resolve namespaces and attach metatables. There is only one public function:
+
+
+local x = xml.convert(somestring)
+
+
+
An optional second boolean argument tells this function not to create a root
+element.
+--ldx]]--
+
+xml.strip_cm_and_dt = false -- an extra global flag, in case we have many includes
+
+-- not just one big nested table capture (lpeg overflow)
+
+local nsremap, resolvens = xml.xmlns, xml.resolvens
+
+local stack, top, dt, at, xmlns, errorstr, entities = {}, {}, {}, {}, {}, nil, {}
+
+local mt = { __tostring = xml.text }
+
+function xml.check_error(top,toclose)
+ return ""
+end
+
+local strip = false
+local cleanup = false
+
+function xml.set_text_cleanup(fnc)
+ cleanup = fnc
+end
+
+local function add_attribute(namespace,tag,value)
+ if cleanup and #value > 0 then
+ value = cleanup(value) -- new
+ end
+ if tag == "xmlns" then
+ xmlns[#xmlns+1] = resolvens(value)
+ at[tag] = value
+ elseif namespace == "xmlns" then
+ xml.checkns(tag,value)
+ at["xmlns:" .. tag] = value
+ else
+ at[tag] = value
+ end
+end
+
+local function add_begin(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = stack[#stack] }
+ setmetatable(top, mt)
+ dt = top.dt
+ stack[#stack+1] = top
+ at = { }
+end
+
+local function add_end(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local toclose = remove(stack)
+ top = stack[#stack]
+ if #stack < 1 then
+ errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "")
+ elseif toclose.tg ~= tag then -- no namespace check
+ errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "")
+ end
+ dt = top.dt
+ dt[#dt+1] = toclose
+ dt[0] = top
+ if toclose.at.xmlns then
+ remove(xmlns)
+ end
+end
+
+local function add_empty(spacing, namespace, tag)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ local resolved = (namespace == "" and xmlns[#xmlns]) or nsremap[namespace] or namespace
+ top = stack[#stack]
+ dt = top.dt
+ local t = { ns=namespace or "", rn=resolved, tg=tag, at=at, dt={}, __p__ = top }
+ dt[#dt+1] = t
+ setmetatable(t, mt)
+ if at.xmlns then
+ remove(xmlns)
+ end
+ at = { }
+end
+
+local function add_text(text)
+ if cleanup and #text > 0 then
+ dt[#dt+1] = cleanup(text)
+ else
+ dt[#dt+1] = text
+ end
+end
+
+local function add_special(what, spacing, text)
+ if #spacing > 0 then
+ dt[#dt+1] = spacing
+ end
+ if strip and (what == "@cm@" or what == "@dt@") then
+ -- forget it
+ else
+ dt[#dt+1] = { special=true, ns="", tg=what, dt={text} }
+ end
+end
+
+local function set_message(txt)
+ errorstr = "garbage at the end of the file: " .. gsub(txt,"([ \n\r\t]*)","")
+end
+
+local P, S, R, C, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V
+
+local space = S(' \r\n\t')
+local open = P('<')
+local close = P('>')
+local squote = S("'")
+local dquote = S('"')
+local equal = P('=')
+local slash = P('/')
+local colon = P(':')
+local valid = R('az', 'AZ', '09') + S('_-.')
+local name_yes = C(valid^1) * colon * C(valid^1)
+local name_nop = C(P(true)) * C(valid^1)
+local name = name_yes + name_nop
+
+local utfbom = P('\000\000\254\255') + P('\255\254\000\000') +
+ P('\255\254') + P('\254\255') + P('\239\187\191') -- no capture
+
+local spacing = C(space^0)
+local justtext = C((1-open)^1)
+local somespace = space^1
+local optionalspace = space^0
+
+local value = (squote * C((1 - squote)^0) * squote) + (dquote * C((1 - dquote)^0) * dquote)
+local attribute = (somespace * name * optionalspace * equal * optionalspace * value) / add_attribute
+local attributes = attribute^0
+
+local text = justtext / add_text
+local balanced = P { "[" * ((1 - S"[]") + V(1))^0 * "]" } -- taken from lpeg manual, () example
+
+local emptyelement = (spacing * open * name * attributes * optionalspace * slash * close) / add_empty
+local beginelement = (spacing * open * name * attributes * optionalspace * close) / add_begin
+local endelement = (spacing * open * slash * name * optionalspace * close) / add_end
+
+local begincomment = open * P("!--")
+local endcomment = P("--") * close
+local begininstruction = open * P("?")
+local endinstruction = P("?") * close
+local begincdata = open * P("![CDATA[")
+local endcdata = P("]]") * close
+
+local someinstruction = C((1 - endinstruction)^0)
+local somecomment = C((1 - endcomment )^0)
+local somecdata = C((1 - endcdata )^0)
+
+local function entity(k,v) entities[k] = v end
+
+local begindoctype = open * P("!DOCTYPE")
+local enddoctype = close
+local beginset = P("[")
+local endset = P("]")
+local doctypename = C((1-somespace)^0)
+local elementdoctype = optionalspace * P("Packaging data in an xml like table is done with the following
+function. Maybe it will go away (when not used).
+--ldx]]--
+
+function xml.is_valid(root)
+ return root and root.dt and root.dt[1] and type(root.dt[1]) == "table" and not root.dt[1].er
+end
+
+function xml.package(tag,attributes,data)
+ local ns, tg = tag:match("^(.-):?([^:]+)$")
+ local t = { ns = ns, tg = tg, dt = data or "", at = attributes or {} }
+ setmetatable(t, mt)
+ return t
+end
+
+function xml.is_valid(root)
+ return root and not root.error
+end
+
+xml.error_handler = (logs and logs.report) or (input and logs.report) or print
+
+--[[ldx--
+
We cannot load an from a filehandle so we need to load
+the whole file first. The function accepts a string representing
+a filename or a file handle.
+--ldx]]--
+
+function xml.load(filename)
+ if type(filename) == "string" then
+ local f = io.open(filename,'r')
+ if f then
+ local root = xml.convert(f:read("*all"))
+ f:close()
+ return root
+ else
+ return xml.convert("")
+ end
+ elseif filename then -- filehandle
+ return xml.convert(filename:read("*all"))
+ else
+ return xml.convert("")
+ end
+end
+
+--[[ldx--
+
When we inject new elements, we need to convert strings to
+valid trees, which is what the next function does.
+--ldx]]--
+
+function xml.toxml(data)
+ if type(data) == "string" then
+ local root = { xml.convert(data,true) }
+ return (#root > 1 and root) or root[1]
+ else
+ return data
+ end
+end
+
+--[[ldx--
+
For copying a tree we use a dedicated function instead of the
+generic table copier. Since we know what we're dealing with we
+can speed up things a bit. The second argument is not to be used!
+--ldx]]--
+
+function copy(old,tables)
+ if old then
+ tables = tables or { }
+ local new = { }
+ if not tables[old] then
+ tables[old] = new
+ end
+ for k,v in pairs(old) do
+ new[k] = (type(v) == "table" and (tables[v] or copy(v, tables))) or v
+ end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+
+xml.copy = copy
+
+--[[ldx--
+
In serializing the tree or parts of the tree is a major
+actitivity which is why the following function is pretty optimized resulting
+in a few more lines of code than needed. The variant that uses the formatting
+function for all components is about 15% slower than the concatinating
+alternative.
+--ldx]]--
+
+-- todo: add when not present
+
+local fallbackhandle = (tex and tex.sprint) or io.write
+
+local function serialize(e, handle, textconverter, attributeconverter, specialconverter, nocommands)
+ if not e then
+ return
+ elseif not nocommands then
+ local ec = e.command
+ if ec ~= nil then -- we can have all kind of types
+ if e.special then
+ local etg, edt = e.tg, e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ return
+ else
+ -- no need to handle any further
+ end
+ end
+ end
+ local xc = xml.command
+ if xc then
+ xc(e,ec)
+ return
+ end
+ end
+ end
+ handle = handle or fallbackhandle
+ local etg = e.tg
+ if etg then
+ if e.special then
+ local edt = e.dt
+ local spc = specialconverter and specialconverter[etg]
+ if spc then
+ local result = spc(edt[1])
+ if result then
+ handle(result)
+ else
+ -- no need to handle any further
+ end
+ elseif etg == "@pi@" then
+ -- handle(format("%s?>",edt[1]))
+ handle("" .. edt[1] .. "?>")
+ elseif etg == "@cm@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@cd@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@dt@" then
+ -- handle(format("",edt[1]))
+ handle("")
+ elseif etg == "@rt@" then
+ serialize(edt,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ else
+ local ens, eat, edt, ern = e.ns, e.at, e.dt, e.rn
+ local ats = eat and next(eat) and { } -- type test maybe faster
+ if ats then
+ if attributeconverter then
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,attributeconverter(v))
+ end
+ else
+ for k,v in next, eat do
+ ats[#ats+1] = format('%s=%q',k,v)
+ end
+ end
+ end
+ if ern and trace_remap and ern ~= ens then
+ ens = ern
+ end
+ if ens ~= "" then
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s:%s %s>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s:%s>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local e = edt[i]
+ if type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ serialize(e,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s:%s>",ens,etg))
+ handle("" .. ens .. ":" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s:%s %s/>",ens,etg,concat(ats," ")))
+ handle("<" .. ens .. ":" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s:%s/>",ens,etg))
+ handle("<" .. ens .. ":" .. etg .. "/>")
+ end
+ end
+ else
+ if edt and #edt > 0 then
+ if ats then
+ -- handle(format("<%s %s>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. ">")
+ else
+ -- handle(format("<%s>",etg))
+ handle("<" .. etg .. ">")
+ end
+ for i=1,#edt do
+ local ei = edt[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ -- handle(format("%s>",etg))
+ handle("" .. etg .. ">")
+ else
+ if ats then
+ -- handle(format("<%s %s/>",etg,concat(ats," ")))
+ handle("<" .. etg .. " " .. concat(ats," ") .. "/>")
+ else
+ -- handle(format("<%s/>",etg))
+ handle("<" .. etg .. "/>")
+ end
+ end
+ end
+ end
+ elseif type(e) == "string" then
+ if textconverter then
+ handle(textconverter(e))
+ else
+ handle(e)
+ end
+ else
+ for i=1,#e do
+ local ei = e[i]
+ if type(ei) == "string" then
+ if textconverter then
+ handle(textconverter(ei))
+ else
+ handle(ei)
+ end
+ else
+ serialize(ei,handle,textconverter,attributeconverter,specialconverter,nocommands)
+ end
+ end
+ end
+end
+
+xml.serialize = serialize
+
+function xml.checkbom(root) -- can be made faster
+ if root.ri then
+ local dt, found = root.dt, false
+ for k=1,#dt do
+ local v = dt[k]
+ if type(v) == "table" and v.special and v.tg == "@pi" and find(v.dt,"xml.*version=") then
+ found = true
+ break
+ end
+ end
+ if not found then
+ insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } )
+ insert(dt, 2, "\n" )
+ end
+ end
+end
+
+--[[ldx--
+
At the cost of some 25% runtime overhead you can first convert the tree to a string
+and then handle the lot.
+--ldx]]--
+
+function xml.tostring(root) -- 25% overhead due to collecting
+ if root then
+ if type(root) == 'string' then
+ return root
+ elseif next(root) then -- next is faster than type (and >0 test)
+ local result = { }
+ serialize(root,function(s) result[#result+1] = s end)
+ return concat(result,"")
+ end
+ end
+ return ""
+end
+
+--[[ldx--
+
The next function operated on the content only and needs a handle function
+that accepts a string.
+--ldx]]--
+
+function xml.string(e,handle)
+ if not handle or (e.special and e.tg ~= "@rt@") then
+ -- nothing
+ elseif e.tg then
+ local edt = e.dt
+ if edt then
+ for i=1,#edt do
+ xml.string(edt[i],handle)
+ end
+ end
+ else
+ handle(e)
+ end
+end
+
+--[[ldx--
+
How you deal with saving data depends on your preferences. For a 40 MB database
+file the timing on a 2.3 Core Duo are as follows (time in seconds):
+
+
+1.3 : load data from file to string
+6.1 : convert string into tree
+5.3 : saving in file using xmlsave
+6.8 : converting to string using xml.tostring
+3.6 : saving converted string in file
+
+
+
The save function is given below.
+--ldx]]--
+
+function xml.save(root,name)
+ local f = io.open(name,"w")
+ if f then
+ xml.serialize(root,function(s) f:write(s) end)
+ f:close()
+ end
+end
+
+--[[ldx--
+
A few helpers:
+--ldx]]--
+
+function xml.body(root)
+ return (root.ri and root.dt[root.ri]) or root
+end
+
+function xml.text(root)
+ return (root and xml.tostring(root)) or ""
+end
+
+function xml.content(root) -- bugged
+ return (root and root.dt and xml.tostring(root.dt)) or ""
+end
+
+function xml.isempty(root, pattern)
+ if pattern == "" or pattern == "*" then
+ pattern = nil
+ end
+ if pattern then
+ -- todo
+ return false
+ else
+ return not root or not root.dt or #root.dt == 0 or root.dt == ""
+ end
+end
+
+--[[ldx--
+
The next helper erases an element but keeps the table as it is,
+and since empty strings are not serialized (effectively) it does
+not harm. Copying the table would take more time. Usage:
+
+
+dt[k] = xml.empty() or xml.empty(dt,k)
+
+--ldx]]--
+
+function xml.empty(dt,k)
+ if dt and k then
+ dt[k] = ""
+ return dt[k]
+ else
+ return ""
+ end
+end
+
+--[[ldx--
+
The next helper assigns a tree (or string). Usage:
+
+
+dt[k] = xml.assign(root) or xml.assign(dt,k,root)
+
+--ldx]]--
+
+function xml.assign(dt,k,root)
+ if dt and k then
+ dt[k] = (type(root) == "table" and xml.body(root)) or root
+ return dt[k]
+ else
+ return xml.body(root)
+ end
+end
diff --git a/tex/context/base/m-arabtex.tex b/tex/context/base/m-arabtex.tex
index af7213387..61e56e93a 100644
--- a/tex/context/base/m-arabtex.tex
+++ b/tex/context/base/m-arabtex.tex
@@ -21,7 +21,7 @@
% ......
% \stoparabic
-\writestatus{loading}{Context Font Macros / ArabTeX support}
+\writestatus{loading}{ConTeXt Font Macros / ArabTeX support}
%D At the \NTG\ 10\high{th} anniversary meeting Klaus Lagally
%D introduced the audience to arabic typesetting, and after
diff --git a/tex/context/base/m-chemic.mkii b/tex/context/base/m-chemic.mkii
new file mode 100644
index 000000000..e6980e1ff
--- /dev/null
+++ b/tex/context/base/m-chemic.mkii
@@ -0,0 +1,21 @@
+%D \module
+%D [ file=ppchtex (m-chemic),
+%D version=1997.03.19,
+%D title=\CONTEXT\ Extra Modules,
+%D subtitle=\PPCHTEX\ (Plain Pictex Context cHemie \TEX),
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten},
+%D suggestions={Tobias Burnus, Dirk Kuypers \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\ifx\psaxes\undefined \ifx\beginpicture\undefined
+ \usemodule[pictex]
+\fi \fi
+
+\input ppchtex.mkii \relax
+
+\endinput
diff --git a/tex/context/base/m-chemic.mkiv b/tex/context/base/m-chemic.mkiv
new file mode 100644
index 000000000..4cc1e3bd8
--- /dev/null
+++ b/tex/context/base/m-chemic.mkiv
@@ -0,0 +1,19 @@
+%D \module
+%D [ file=ppchtex (m-chemic),
+%D version=1997.03.19,
+%D title=\CONTEXT\ Extra Modules,
+%D subtitle=\PPCHTEX\ (Plain Pictex Context cHemie \TEX),
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten},
+%D suggestions={Tobias Burnus, Dirk Kuypers \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\usemodule[pictex] % we will get rid of this
+
+\input ppchtex.mkiv \relax
+
+\endinput
diff --git a/tex/context/base/m-chemic.tex b/tex/context/base/m-chemic.tex
index 25eb62db5..7bacf4a90 100644
--- a/tex/context/base/m-chemic.tex
+++ b/tex/context/base/m-chemic.tex
@@ -12,14 +12,6 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\ifx\directlua\undefined
- \ifx\psaxes\undefined \ifx\beginpicture\undefined
- \usemodule[pictex]
- \fi \fi
-\else
- \usemodule[pictex]
-\fi
-
-\input ppchtex.tex \relax
+\loadmarkfile{m-chemic}
\endinput
diff --git a/tex/context/base/m-database.tex b/tex/context/base/m-database.tex
index 6cb9a6b6c..c4fba132a 100644
--- a/tex/context/base/m-database.tex
+++ b/tex/context/base/m-database.tex
@@ -265,7 +265,7 @@
\fi}
\def\doprocessseparatedline
- {\doifnextcharelse\bgroup\xdoprocessseparatedline\ydoprocessseparatedline}
+ {\doifnextbgroupelse\xdoprocessseparatedline\ydoprocessseparatedline}
\def\dodoprocessseparatedline
{\doprocessseparatedline}
diff --git a/tex/context/base/m-educat.tex b/tex/context/base/m-educat.tex
index 38567bf4e..ddfb72ff4 100644
--- a/tex/context/base/m-educat.tex
+++ b/tex/context/base/m-educat.tex
@@ -18,39 +18,6 @@
\unprotect
-\startvariables dutch english
- german czech
- italian romanian
-
- answerarea: antwoordgebied answerarea
- answerarea answerarea
- answerarea answerarea
-
-\stopvariables
-
-\startelements dutch english
- german czech
- italian romanian
-
- answerspace: antwoordruimte answerspace
- answerspace answerspace
- answerspace answerspace
- answerlines: antwoordregels answerlines
- answerlines answerlines
- answerlines answerlines
-
-\stopelements
-
-\startcommands dutch english
- german czech
- italian romanian
-
- setupanswerarea: stelantwoordgebiedin setupanswerarea
- setupanswerarea setupanswerarea
- setupanswerarea setupanswerarea
-
-\stopcommands
-
\definesystemvariable{iv}
\definecolor [answerareacolor] [s=.90]
diff --git a/tex/context/base/m-gamma.tex b/tex/context/base/m-gamma.tex
deleted file mode 100644
index 05f5d3a42..000000000
--- a/tex/context/base/m-gamma.tex
+++ /dev/null
@@ -1,230 +0,0 @@
-%D \module
-%D [ file=m-gamma,
-%D version=2002.05.15,
-%D title=\CONTEXT\ Extra Modules,
-%D subtitle=Basic \OMEGA\ Support,
-%D author={Idris Samawi Hamid, Hans Hagen},
-%D date=\currentdate,
-%D copyright={PRAGMA-ADE, Idris Samawi Hamid}]
-%D
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D Most of this module is written by Idris Samawi Hamid.
-
-%D We define a couple of symbolic \OTP\ filters and
-%D sequences. First the filters:
-%D
-%D Todo: better names, no funny abbreviations.
-
-\definefiltersynonym [utf8 to unicode16] [inutf8]
-\definefiltersynonym [IdOCP] [id]
-\definefiltersynonym [BasicLatinTexUni] [lat2uni]
-\definefiltersynonym [BasicLatinUniToFont][uni2lat]
-\definefiltersynonym [GrTexUni] [grpo2uni]
-\definefiltersynonym [GrUniToFont] [uni2greek]
-\definefiltersynonym [ArabUni] [7arb2uni]
-\definefiltersynonym [BerberUni] [7ber2uni]
-\definefiltersynonym [UrduUni] [7urd2uni]
-\definefiltersynonym [AfghaPashtoUni] [7pas2uni]
-\definefiltersynonym [PakiPashtoUni] [7pap2uni]
-\definefiltersynonym [SindhiUni] [7snd2uni]
-\definefiltersynonym [TifinaghUni] [7tbe2uni]
-\definefiltersynonym [LatinBerberUni] [7lbe2uni]
-\definefiltersynonym [UniCUni] [uni2cuni]
-\definefiltersynonym [CUniArab] [cuni2oar]
-\definefiltersynonym [NoKeshidehCUniArab] [cuni2nar]
-
-%D Next we define the sequences.
-
-\definefiltersequence
- [NilOCP]
- [IdOCP]
-
-\definefiltersequence
- [BasicLatinOCP]
- [BasicLatinTexUni,BasicLatinUniToFont]
-
-\definefiltersequence
- [GreekOCP]
- [GrTexUni,GrUniToFont]
-
-\definefiltersequence
- [ArabicOCP]
- [ArabUni,UniCUni,CUniArab]
-
-\definefiltersequence
- [ArabicNoKeshidehOCP]
- [ArabUni,UniCUni,NoKeshidehCUniArab]
-
-\definefiltersequence
- [ArabicBerberOCP]
- [BerberUni,UniCUni,CUniArab]
-
-\definefiltersequence
- [TifinaghOCP]
- [TifinaghUni,BasicLatinUniToFont]
-
-\definefiltersequence
- [LatinBerberOCP]
- [LatinBerberUni,BasicLatinUniToFont]
-
-\definefiltersequence
- [UrduOCP]
- [UrduUni,UniCUni,CUniArab]
-
-\definefiltersequence
- [UrduNoKeshidehOCP]
- [UrduUni,UniCUni,NoKeshidehCUniArab]
-
-\definefiltersequence
- [AfghaPashtoOCP]
- [AfghaPashtoUni,UniCUni,CUniArab]
-
-\definefiltersequence
- [PakiPashtoOCP]
- [PakiPashtoUni,UniCUni,CUniArab]
-
-\definefiltersequence
- [SindhiOCP]
- [SindhiUni,UniCUni,CUniArab]
-
-%D We wrap a couple of languages in environmen tmacros.
-%D beware: this solution is far from perfect!
-%D
-%D Todo: better interface to directional primitives.
-%D
-%D Todo: proper language support (labels etc).
-
-\definestartstop
- [latin]
- [commands=%
- {\usefiltersequence[BasicLatinOCP]%
- \switchtobodyfont[omlgc]}]
-
-\definestartstop
- [greek]
- [commands=%
- {\usefiltersequence[GreekOCP]%
- \switchtobodyfont[omlgc]%
- \language=3\lefthyphenmin2\righthyphenmin=2}]
-
-\definestartstop
- [arab]
- [commands=%
- {\usefiltersequence[ArabicOCP]
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [smallarab]
- [commands=%
- {\usefiltersequence[ArabicNoKeshidehOCP]
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [latberber]
- [commands=%
- {\usefiltersequence[LatinBerberOCP]
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [tifinagh]
- [commands=%
- {\usefiltersequence[TifinaghOCP]
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [berber]
- [commands=%
- {\usefiltersequence[ArabicBerberOCP]
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [urdu]
- [commands=%
- {\usefiltersequence[UrduOCP]%
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [smallurdu]
- [commands=%
- {\usefiltersequence[UrduNoKeshidehOCP]%
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [pashto]
- [commands=%
- {\usefiltersequence[AfghaPashtoOCP]%
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [pashtop]
- [commands=%
- {\usefiltersequence[PakiPashtoOCP]%
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-\definestartstop
- [sindhi]
- [commands=%
- {\usefiltersequence[SindhiOCP]%
- \switchtobodyfont[omarb]%
- \textdir TRT\pardir TRT}]
-
-
-\let\typeout\message \input grlccode.tex
-
-%D We (pre)define a couple of fonts:
-
-\usetypescriptfile[type-omg]
-
-\usetypescript[OmegaArab]
-\usetypescript[OmegaLGC]
-
-%D Dangerous definitions:
-
-\startencoding[omega]
-
- \definecharacter textbraceleft {^^^^f07b}
- \definecharacter textbraceright {^^^^f07d}
- \definecharacter textbackslash {^^^^f05c}
- \definecharacter textbullet {{\clearocplists\mm\sy\char"0F}}
- \definecharacter dotlessi {^^^^0131}
- \definecharacter ssharp {^^^^00df}
-
-\stopencoding
-
-\enableencoding [omega]
-
-%D Some logo's:
-
-\unexpanded \def\OMEGA {{\switchtobodyfont[omlgc]^^^^03a9}}
-\unexpanded \def\OTP {\OMEGA TP}
-
-%D A few funny definitions:
-
-\def\#{^^^^f023}
-\def\${^^^^f024}
-\def\%{^^^^f025}
-\def\&{^^^^f026}
-
-%D I have no idea what this has to do with omega:
-
-\def\heshe {\lohi{he} {she}}
-\def\himher{\lohi{him}{her}}
-\def\hisher{\lohi{his}{her}}
-
-% Brrr
-
-\setuptolerance [verytolerant]
-
-\endinput
diff --git a/tex/context/base/m-mkii.mkiv b/tex/context/base/m-mkii.mkiv
new file mode 100644
index 000000000..cb0da6fcb
--- /dev/null
+++ b/tex/context/base/m-mkii.mkiv
@@ -0,0 +1,21 @@
+% todo
+
+\unprotect
+
+\writestatus\m!systems{loading some mkii compatibility hacks}
+
+% Compatibility for font-ini
+
+\let\normalxi=\xi
+
+\definebodyfontswitch [xii] [\!!twelvepoint]
+\definebodyfontswitch [xi] [\!!elevenpoint]
+\definebodyfontswitch [x] [\!!tenpoint]
+\definebodyfontswitch [ix] [\!!ninepoint]
+\definebodyfontswitch [viii] [\!!eightpoint]
+\definebodyfontswitch [vii] [\!!sevenpoint]
+\definebodyfontswitch [vi] [\!!sixpoint]
+
+\unexpanded\def\xi{\ifmmode\normalxi\else\elevenpoint\fi}
+
+\protect \endinput
diff --git a/tex/context/base/m-newmat.tex b/tex/context/base/m-newmat.tex
index c36119cd4..08ce33b4c 100644
--- a/tex/context/base/m-newmat.tex
+++ b/tex/context/base/m-newmat.tex
@@ -182,7 +182,7 @@
%D defined in Plain \TEX). It allows to get a math character
%D inserted as if it was a text character.
-\gdef\mathhexbox#1#2#3{\mathtext{$\m@th\mathchar"#1#2#3$}}
+\gdef\mathhexbox#1#2#3{\mathtext{$\mathsurround\zeropoint\mathchar"#1#2#3$}}
%D \macros
%D {boxed}
@@ -299,11 +299,11 @@
\def\simplestartsubarray#1%
{\vcenter\bgroup
- \baselineskip\fontdimen10 \scriptfont\tw@
- \advance\baselineskip\fontdimen12 \scriptfont\tw@
- \lineskip\thr@@\fontdimen8 \scriptfont\thr@@
+ \baselineskip\fontdimen10 \scriptfont\plustwo
+ \advance\baselineskip\fontdimen12 \scriptfont\plustwo
+ \lineskip\plusthree\fontdimen8 \scriptfont\plusthree
\lineskiplimit\lineskip
- \ialign\bgroup\ifx c#1\hfil\fi$\m@th\scriptstyle##$\hfil\crcr}
+ \ialign\bgroup\ifx c#1\hfil\fi$\mathsurround\zeropoint\scriptstyle##$\hfil\crcr}
\def\stopsubarray
{\crcr\egroup
@@ -326,8 +326,8 @@
\baselineskip6\ex@
\lineskip1.5\ex@
\lineskiplimit\lineskip
- \ialign\bgroup\hfil$\m@th\scriptstyle##$\hfil&&\thickspace\hfil
- $\m@th\scriptstyle##$\hfil\crcr}
+ \ialign\bgroup\hfil$\mathsurround\zeropoint\scriptstyle##$\hfil&&\thickspace\hfil
+ $\mathsurround\zeropoint\scriptstyle##$\hfil\crcr}
\def\stopsmallmatrix
{\crcr\egroup
diff --git a/tex/context/base/m-pictex.tex b/tex/context/base/m-pictex.tex
index 90bb7b339..abb81b76e 100644
--- a/tex/context/base/m-pictex.tex
+++ b/tex/context/base/m-pictex.tex
@@ -88,11 +88,14 @@
%D redefinition already took place. We save the original
%D meanings, so we can restores them afterwards.
-\let\normalnewdimen = \newdimen
-\let\normalnewskip = \newskip
+% \def\temporarynewdimen {\alloc@1\dimen\dimendef\insc@unt}
+% \def\temporarynewskip {\alloc@2\skip \skipdef \insc@unt}
-\def\temporarynewdimen {\alloc@1\dimen\dimendef\insc@unt}
-\def\temporarynewskip {\alloc@2\skip \skipdef \insc@unt}
+\let\normalnewdimen \newdimen
+\let\normalnewskip \newskip
+
+\let\temporarynewdimen\newdimen
+\let\temporarynewskip \newskip
%D Here comes the trick. Depending on how many \DIMENSIONS\ and
%D \SKIPS\ are allocated, the \type{\newdimen} assigns a
diff --git a/tex/context/base/m-subsub.tex b/tex/context/base/m-subsub.tex
index 3fc71cd50..4395ded8a 100644
--- a/tex/context/base/m-subsub.tex
+++ b/tex/context/base/m-subsub.tex
@@ -12,53 +12,6 @@
\unprotect
-\startvariables dutch english
- german czech
- italian romanian
-
- subsubsubsubsubsection: subsubsubsubsubparagraaf subsubsubsubsubsection
- unterunterunterunterunterabsatz podpodpodpodpodsekce
- sottosottosottosottosottocapoverso subsubsubsubsubsectiune
-
- subsubsubsubsubsubsection: subsubsubsubsubsubparagraaf subsubsubsubsubsubsection
- unterunterunterunterunterunterabsatz podpodpodpodpodpodsekce
- sottosottosottosottosottosottocapoverso subsubsubsubsubsubsectiune
-
- subsubsubsubsubsubsubsection: subsubsubsubsubsubsubparagraaf subsubsubsubsubsubsubsection
- unterunterunterunterunterunterunterabsatz podpodpodpodpodpodpodsekce
- sottosottosottosottosottosottosottocapoverso subsubsubsubsubsubsubsectiune
-
- subsubsubsubsubsubsubsubsection: subsubsubsubsubsubsubsubparagraaf subsubsubsubsubsubsubsubsection
- unterunterunterunterunterunterunterunterabsatz podpodpodpodpodpodpodpodsekce
- sottosottosottosottosottosottosottosottocapoverso subsubsubsubsubsubsubsubsectiune
-
-subsubsubsubsubsubsubsubsubsection: subsubsubsubsubsubsubsubsubparagraaf subsubsubsubsubsubsubsubsubsection
- unterunterunterunterunterunterunterunterunterabsatz podpodpodpodpodpodpodpodpodsekce
- sottosottosottosottosottosottosottosottosottocapoverso subsubsubsubsubsubsubsubsubsectiune
-
- subsubsubsubsubsubject: subsubsubsubsubonderwerp subsubsubsubsubsubject
- unterunterunterunterunterthema podpodpodpodpodtema
- sottosottosottosottosottoargomento subsubsubsubsubsubiect
-
- subsubsubsubsubsubsubject: subsubsubsubsubsubonderwerp subsubsubsubsubsubsubject
- unterunterunterunterunterunterthema podpodpodpodpodpodtema
- sottosottosottosottosottosottoargomento subsubsubsubsubsubsubiect
-
- subsubsubsubsubsubsubsubject: subsubsubsubsubsubsubonderwerp subsubsubsubsubsubsubsubject
- unterunterunterunterunterunterunterthema podpodpodpodpodpodpodtema
- sottosottosottosottosottosottosottoargomento subsubsubsubsubsubsubsubiect
-
- subsubsubsubsubsubsubsubsubject: subsubsubsubsubsubsubsubonderwerp subsubsubsubsubsubsubsubsubject
- unterunterunterunterunterunterunterunterthema podpodpodpodpodpodpodpodtema
- sottosottosottosottosottosottosottosottoargomento subsubsubsubsubsubsubsubsubiect
-
-subsubsubsubsubsubsubsubsubsubject: subsubsubsubsubsubsubsubsubonderwerp subsubsubsubsubsubsubsubsubsubject
- unterunterunterunterunterunterunterunterunterthema podpodpodpodpodpodpodpodpodtema
- sottosottosottosottosottosottosottosottosottoargomento subsubsubsubsubsubsubsubsubsubiect
-
-\stopvariables
-
-
\definesection[\s!section-8]
\definesection[\s!section-9]
\definesection[\s!section-10]
diff --git a/tex/context/base/m-timing.tex b/tex/context/base/m-timing.tex
index 5f543042a..f6b0348c8 100644
--- a/tex/context/base/m-timing.tex
+++ b/tex/context/base/m-timing.tex
@@ -33,185 +33,35 @@
\definecolor[usage:time] [darkblue]
\definecolor[usage:frame][darkgray]
-\startluacode
-do
-
- document = document or { }
- document.progress = document.progress or { }
-
- local defaultfilename = tex.jobname .. "-luatex-progress"
-
- local params = {
- "cs_count",
- "dyn_used",
- "elapsed_time",
- "luabytecode_bytes",
- "luastate_bytes",
- "max_buf_stack",
- "obj_ptr",
- "pdf_mem_ptr",
- "pdf_mem_size",
- "pdf_os_cntr",
- "pool_ptr",
- "str_ptr",
- }
-
- -- storage
-
- local last = os.clock()
- local data = { }
-
- function document.progress.save()
- local f = io.open((name or defaultfilename) .. ".lut","w")
- if f then
- f:write(table.serialize(data,true))
- f:close()
- data = { }
- end
- end
-
- function document.progress.store()
- local c = os.clock()
- local t = {
- elapsed_time = c - last,
- node_memory = tex.node_mem_status(),
- }
- for k, v in pairs(params) do
- if status[v] then t[v] = status[v] end
- end
- data[#data+1] = t
- last = c
- end
-
- -- conversion
+\ctxloadluafile{trac-tim}{}
- local processed = { }
-
- function document.progress.bot(name,tag)
- local d = document.progress.convert(name)
- return d.bot[tag] or 0
- end
- function document.progress.top(name,tag)
- local d = document.progress.convert(name)
- return d.top[tag] or 0
- end
- function document.progress.pages(name,tag)
- local d = document.progress.convert(name)
- return d.pages or 0
- end
- function document.progress.path(name,tag)
- local d = document.progress.convert(name)
- return d.paths[tag] or "origin"
- end
- function document.progress.nodes(name)
- local d = document.progress.convert(name)
- return d.names or { }
- end
- function document.progress.parameters(name)
- local d = document.progress.convert(name)
- return params -- shared
- end
+\startluacode
+local progress = goodies.progress
- function document.progress.convert(name)
- name = ((name ~= "") and name) or defaultfilename
- if not processed[name] then
- local names, top, bot, pages, paths, keys = { }, { }, { }, 0, { }, { }
- local data = io.loaddata(name .. ".lut")
- if data then data = loadstring(data) end
- if data then data = data() end
- if data then
- pages = #data
- if pages > 1 then
- local factor = 100
- for k,v in ipairs(data) do
- for k,v in pairs(v.node_memory) do
- keys[k] = true
- end
- end
- for k,v in ipairs(data) do
- local m = v.node_memory
- for k, _ in pairs(keys) do
- if not m[k] then m[k] = 0 end
- end
- end
- local function path(tag,subtag)
- local b, t, s = nil, nil, { }
- for k,v in ipairs(data) do
- local v = (subtag and v[tag][subtag]) or v[tag]
- if v then
- v = tonumber(v)
- if b then
- if v > t then t = v end
- if v < b then b = v end
- else
- t = v
- b = v
- end
- s[k] = v
- else
- s[k] = 0
- end
- end
- local tagname = subtag or tag
- top[tagname] = (string.format("%.3f",t)):gsub("%.000$","")
- bot[tagname] = (string.format("%.3f",b)):gsub("%.000$","")
- local delta = t-b
- if delta == 0 then
- delta = 1
- else
- delta = factor/delta
- end
- for k, v in ipairs(s) do
- s[k] = "(" .. k .. "," .. (v-b)*delta .. ")"
- end
- paths[tagname] = table.concat(s,"--")
- end
- for _, tag in pairs(params) do
- path(tag)
- end
- for tag, _ in pairs(keys) do
- path("node_memory",tag)
- names[#names+1] = tag
- end
- pages = pages - 1
- end
- end
- table.sort(names)
- processed[name] = {
- names = names,
- top = top,
- bot = bot,
- pages = pages,
- paths = paths,
- }
- end
- return processed[name]
+function progress.show(filename,parameters,nodes,other)
+ for n, name in pairs(parameters or progress.parameters(filename)) do
+ tex.sprint(tex.ctxcatcodes,string.format("\\ShowNamedUsage{%s}{%s}{%s}",filename or progress.defaultfilename,name,other or ""))
end
-
- function document.progress.show(filename,parameters,nodes,other)
- for n, name in pairs(parameters or document.progress.parameters(filename)) do
- tex.sprint(tex.ctxcatcodes,string.format("\\ShowNamedUsage{%s}{%s}{%s}",filename or defaultfilename,name,other or ""))
- end
- for n, name in pairs(nodes or document.progress.nodes(filename)) do
- tex.sprint(tex.ctxcatcodes,string.format("\\ShowNamedUsage{%s}{%s}{%s}",filename or defaultfilename,name,other or ""))
- end
+ for n, name in pairs(nodes or progress.nodes(filename)) do
+ tex.sprint(tex.ctxcatcodes,string.format("\\ShowNamedUsage{%s}{%s}{%s}",filename or progress.defaultfilename,name,other or ""))
end
-
end
\stopluacode
% \everyfirstshipout
-\appendtoks\ctxlua{document.progress.store()}\to\everystarttext
-\appendtoks\ctxlua{document.progress.store()}\to\everyshipout
-
-\ctxlua{table.insert(input.stop_actions, function() document.progress.save() end)}
+\startnotmode[no-timing]
+ \appendtoks\ctxlua{goodies.progress.store()}\to\everystarttext
+ \appendtoks\ctxlua{goodies.progress.store()}\to\everyshipout
+ \ctxlua{main.register_stop_actions(function() goodies.progress.save() end)}
+\stopnotmode
\def\ShowNamedUsage#1#2#3%
{\setbox\scratchbox\vbox\bgroup\startMPcode
begingroup ; save p, q, b, h, w ;
path p, q, b ; numeric h, w ;
- p := \ctxlua{tex.sprint(document.progress.path("#1","#2"))} ;
+ p := \ctxlua{tex.sprint(goodies.progress.path("#1","#2"))} ;
+% p := p shifted -llcorner p ;
if bbwidth(p) > 1 :
h := 100 ; w := 2 * h ;
w := \the\textwidth-3pt ; % correct for pen
@@ -221,7 +71,8 @@ end
draw b withcolor \MPcolor{usage:frame} ;
draw p withcolor \MPcolor{usage:line} ;
if ("#3" <> "") and ("#3" <> "#2") :
- q := \ctxlua{tex.sprint(document.progress.path("#1","#3"))} ;
+ q := \ctxlua{tex.sprint(goodies.progress.path("#1","#3"))} ;
+% q := q shifted -llcorner q ;
if bbwidth(q) > 1 :
q := q xstretched w ;
pickup pencircle scaled 1.5pt ; linecap := butt ;
@@ -236,16 +87,16 @@ end
\startlinecorrection
\box\scratchbox \endgraf
\hbox to \scratchdimen{\tttf\strut\detokenize{#2}\hss
- min:\ctxlua{tex.sprint(document.progress.bot("#1","\detokenize{#2}"))}, %
- max:\ctxlua{tex.sprint(document.progress.top("#1","\detokenize{#2}"))}, %
- pages:\ctxlua{tex.sprint(document.progress.pages("#1"))}%
+ min:\ctxlua{tex.sprint(goodies.progress.bot("#1","\detokenize{#2}"))}, %
+ max:\ctxlua{tex.sprint(goodies.progress.top("#1","\detokenize{#2}"))}, %
+ pages:\ctxlua{tex.sprint(goodies.progress.pages("#1"))}%
}%
\stoplinecorrection
\fi}
-\def\LoadUsage #1{\ctxlua{document.progress.convert("#1")}}
-\def\ShowUsage #1{\ctxlua{document.progress.show("#1",nil,nil,"elapsed_time")}}
-\def\ShowMemoryUsage#1{\ctxlua{document.progress.show("#1",nil,{}, "elapsed_time")}}
-\def\ShowNodeUsage #1{\ctxlua{document.progress.show("#1",{},nil, "elapsed_time")}}
+\def\LoadUsage #1{\ctxlua{goodies.progress.convert("#1")}}
+\def\ShowUsage #1{\ctxlua{goodies.progress.show("#1",nil,nil,"elapsed_time")}}
+\def\ShowMemoryUsage#1{\ctxlua{goodies.progress.show("#1",nil,{}, "elapsed_time")}}
+\def\ShowNodeUsage #1{\ctxlua{goodies.progress.show("#1",{},nil, "elapsed_time")}}
\endinput
diff --git a/tex/context/base/m-track.tex b/tex/context/base/m-track.tex
new file mode 100644
index 000000000..cfcbbabff
--- /dev/null
+++ b/tex/context/base/m-track.tex
@@ -0,0 +1,5 @@
+\doifnotmode{mkiv} {\endinput}
+
+\starttext
+ \showtrackers
+\stoptext
diff --git a/tex/context/base/m-translate.tex b/tex/context/base/m-translate.tex
index a11eef4bc..a9601bdd5 100644
--- a/tex/context/base/m-translate.tex
+++ b/tex/context/base/m-translate.tex
@@ -44,14 +44,14 @@
end
function translators.reset(s)
- input.filters.user_translator = nil
+ resolvers.filters.user_translator = nil
list, compiled = nil, nil
end
function translators.enable(s)
- input.filters.user_translator = translators.translate
+ resolvers.filters.user_translator = translators.translate
end
function translators.disable(s)
- input.filters.user_translator = nil
+ resolvers.filters.user_translator = nil
end
\stopluacode
diff --git a/tex/context/base/m-visual.tex b/tex/context/base/m-visual.tex
index c35e8a1a4..2be669d19 100644
--- a/tex/context/base/m-visual.tex
+++ b/tex/context/base/m-visual.tex
@@ -272,7 +272,6 @@
#2{#3}}
\let\normalPDFcode\PDFcode
-\let\normalspecial\special
\def\showlowlevelstream
{\def\PDFcode{\lowlevelstream\PDFcode\normalPDFcode}%
diff --git a/tex/context/base/math-ali.mkiv b/tex/context/base/math-ali.mkiv
new file mode 100644
index 000000000..f98eb11df
--- /dev/null
+++ b/tex/context/base/math-ali.mkiv
@@ -0,0 +1,1059 @@
+%D \module
+%D [ file=math-ali,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Math Alignments,
+%D author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=PRAGMA-ADE / Hans Hagen]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Math Alignments}
+
+\unprotect
+
+%D The code here has been moved from other files. Beware: the \MKII\ and
+%D \MKIV\ code is not gathered in files with the same name.
+
+%D \macros
+%D {\definemathalignment, setupmathalignment, startmathalignment}
+%D
+%D Modules may provide additional alignment features. The following
+%D mechanisms are provided by the core.
+
+% n>1 #### needed, strange # interaction in recurse
+
+\def\presetdisplaymath{\displ@y} % some day i will relocate the plain stuff
+
+\def\buildeqalign
+ {\scratchtoks\emptytoks
+ \dorecurse{\mathalignmentparameter\c!m}
+ {\ifnum\recurselevel>\plusone
+ \appendtoks
+ \tabskip\mathalignmentparameter\c!distance&\tabskip\zeropoint
+ \to\scratchtoks
+ \fi
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}%
+ \dorecurse{\numexpr\mathalignmentparameter\c!n-\plusone\relax}
+ {\normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}}%
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc}}}
+
+\def\forgetalign
+ {\tabskip\zeropoint\everycr\emptytoks}
+
+\let\firstineqalign\empty
+\let\nextineqalign \empty
+\let\leftofeqalign \empty
+\let\rightofeqalign\empty
+
+\def\mathineqalign#1{$\forgetalign\displaystyle{{}#1{}}$}
+\def\textineqalign#1{$\forgetalign#1$}
+
+\def\eqalign#1% why no halign here, probably because of displaywidth
+ {\null\,\vcenter
+ {\openup.25\bodyfontsize% was: \openup\jot
+ \mathsurround\zeropoint
+ \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##{}}$\hfil\crcr#1\crcr}%
+ }\,}
+
+% preamble is scanned for tabskips so we need the span to prevent an error message
+
+\chardef\eqalignmode\plusone
+
+\def\preparereqalignno
+ {\!!toksa{\strut\firstineqalign\hfil\leftofeqalign\span\mathineqalign{##}\rightofeqalign\tabskip\zeropoint}%
+ \!!toksb{&\nextineqalign\leftofeqalign\span\mathineqalign{##}\rightofeqalign\tabskip\zeropoint}%
+ \ifnum\mathraggedstatus=\plusone
+ \!!toksc{\hfil&\span\textineqalign{##}\tabskip\zeropoint}%
+ \else\ifnum\mathraggedstatus=\plusthree
+ \!!toksc{\hfil\tabskip\zeropoint\!!plus 1\!!fill&\span\textineqalign{##}\tabskip\zeropoint}%
+ \else
+ \!!toksc{\hfil\tabskip\centering&\llap{\span\textineqalign{##}}\tabskip\zeropoint}%
+ \fi\fi
+ \global\chardef\mathnumberstatus\zerocount
+ \buildeqalign
+ \presetdisplaymath
+ \tabskip\centering}
+
+\def\prepareleqalignno
+ {\!!toksa{\strut\firstineqalign\hfil\leftofeqalign\span\mathineqalign{##}\rightofeqalign\tabskip\zeropoint}%
+ \!!toksb{&\nextineqalign\leftofeqalign\span\mathineqalign{##}\rightofeqalign\tabskip\zeropoint}%
+ % problem: number is handled after rest and so ends up in the margin
+ \ifnum\mathraggedstatus=\plusone
+ \!!toksc{\hfil&\kern-\displaywidth\rlap{\span\textineqalign{##}}\tabskip\displaywidth}%
+ \else\ifnum\mathraggedstatus=\plusthree
+ \!!toksc{\hfil\tabskip\zeropoint\!!plus 1\!!fill&\kern-\displaywidth\span\mrlap{\span\textineqalign{##}}\tabskip\displaywidth}%
+ \else
+ \!!toksc{\hfil\tabskip\centering&\kern-\displaywidth\rlap{\span\textineqalign{##}}\tabskip\displaywidth}%
+ \fi\fi
+ \global\chardef\mathnumberstatus\zerocount
+ \buildeqalign
+ \presetdisplaymath
+ \tabskip\centering}
+
+\def\dobotheqalignno#1#2%
+ {\ifmmode
+ \displ@y % \let\doplaceformulanumber\relax % strange hack
+ \vcenter\bgroup
+ \let\finishalignno\egroup
+ \else
+ \let\finishalignno\relax
+ \fi
+ #1%
+ \halign \ifcase\eqalignmode \or to \displaywidth \fi \@EA {\the\scratchtoks\crcr#2\crcr}%
+ \finishalignno}
+
+\def\dobothaligneqalignno#1%
+ {\ifmmode
+ \displ@y
+ \global\chardef\mathnumberstatus\plusone
+ \ifcase\mathraggedstatus
+ \def\finishalignno{\crcr\egroup}%
+ \else
+ % we're in a mathbox
+ \vcenter\bgroup
+ \def\finishalignno{\crcr\egroup\egroup}%
+ \fi
+ \fi
+ #1%
+ \halign \ifcase\eqalignmode \or to \displaywidth \fi \@EA \bgroup\the\scratchtoks\crcr}
+
+\def\mrlap#1%
+ {\setbox\scratchbox\hbox{#1}%
+ \ifdim\wd\scratchbox>\mathnumbercorrection
+ \xdef\mathnumbercorrection{\the\wd\scratchbox}%
+ \fi
+ \box\scratchbox
+ \global\chardef\mathnumberstatus\plustwo}
+
+% \def\dobothaligneqalignno#1%
+% {\ifmmode
+% \displ@y
+% \global\chardef\mathnumberstatus\plusone
+% we're in a mathbox
+% \vcenter\bgroup
+% \def\finishalignno{\crcr\egroup\egroup}%
+% \else
+% \def\finishalignno{\crcr\egroup}%
+% \fi
+% #1%
+% \halign \ifcase\eqalignmode \or to \displaywidth \fi \@EA \bgroup\the\scratchtoks\crcr}
+
+\def\reqalignno {\dobotheqalignno \preparereqalignno}
+\def\leqalignno {\dobotheqalignno \prepareleqalignno}
+\def\alignreqalignno{\dobothaligneqalignno\preparereqalignno}
+\def\alignleqalignno{\dobothaligneqalignno\prepareleqalignno}
+\def\finishalignno {\crcr\egroup}
+
+\let \equalignno \reqalignno
+\let\aligneqalignno\alignreqalignno
+
+%D Here we implement the user interface part.
+
+\def\setupmathalignment
+ {\dodoubleempty\dosetupmathalignment}
+
+\def\dosetupmathalignment[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??eq#1][#2]%
+ \else
+ \getparameters[\??eq][#1]%
+ \fi}
+
+\let\currentmathalignment\empty
+
+\def\mathalignmentparameter#1%
+ {\executeifdefined{\??eq\currentmathalignment#1}{\executeifdefined{\??eq#1}\empty}}
+
+\setupmathalignment
+ [\c!n=2,
+ \c!m=1,
+ \c!distance=1em]
+
+\def\numberedeqalign
+ {\doifelse{\formulaparameter\c!location}\v!left\alignleqalignno\alignreqalignno}
+
+\def\doxxdoubleempty#1#2%
+ {\ifx#2[\expandafter\dodoxxdoubleempty\else\expandafter\noxxdoubleempty\fi#1#2}
+
+\def\dodoxxdoubleempty#1[#2]#3%
+ {\ifx#3[\else\expandafter\nonoxxdoubleempty\fi#1[#2]#3}
+
+\def\noxxdoubleempty #1{#1[][]}
+\def\nonoxxdoubleempty#1[#2]{#1[#2][]}
+
+\newcount\eqaligncolumn
+
+\def\firstineqalign{\global\eqaligncolumn\plusone}
+\def\nextineqalign {\global\advance\eqaligncolumn\plusone}
+\def\leftofeqalign {\getvalue{\??eq:\v!left :\number\eqaligncolumn}}
+\def\rightofeqalign{\getvalue{\??eq:\v!right:\number\eqaligncolumn}}
+
+\def\doseteqaligncolumn#1%
+ {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\empty
+ \letvalue{\??eq:\v!right:\number\eqaligncolumn}\empty
+ \doif{#1}\v!left {\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill}%
+ \doif{#1}\v!right {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}%
+ \doif{#1}\v!middle{\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill
+ \letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}}
+
+\def\dodoalignNC
+ {\gdef\doalignNC##1{#1}}
+
+\def\doalignNR[#1][#2]%
+ {\donestedformulanumber{#1}{#2}\crcr}
+
+%D \starttyping
+%D \placeformula[eqn0]\startformula \startalign[n=1] a\NR \stopalign \stopformula See \in[eqn0]
+%D \placeformula[eqn1]\startformula \startalign[n=1] a\NR \stopalign \stopformula See \in[eqn1]
+%D \placeformula \startformula \startalign[n=1] a\NR[eqn2] \stopalign \stopformula See \in[eqn2]
+%D \placeformula[eqn3]\startformula \startalign[n=1] a\NR[+] \stopalign \stopformula See \in[eqn3]
+%D \stoptyping
+
+% todo: pop in cell
+
+\def\dostartmathalignment[#1][#2]%
+ {% \begingroup not permitted ($$...assignments...\halign... )
+ \pushmacro\doalignNC
+ \edef\currentmathalignment{#1}%
+ \doifassignmentelse{#2}{\setupmathalignment[#1][#2]}\donothing
+ \def\NC{\doalignNC}%
+ \global\let\doalignNC\dodoalignNC
+ \def\EQ{&=}%
+ \def\NR{&\global\let\doalignNC\dodoalignNC\doxxdoubleempty\doalignNR}%
+ % amstex compatibility mode: (ugly, will disappear)
+ \def\notag{\def\\{&\crcr}}%
+ \doifelse{#2}{*}{\def\\{&\crcr}}{\def\\{&\doalignNR[+][]\crcr}}%
+ % end of compatibility mode
+ \eqaligncolumn\zerocount
+ \processcommacommand
+ [\mathalignmentparameter\c!align]
+ {\advance\eqaligncolumn\plusone\doseteqaligncolumn}% takes argument
+ % the real action
+ \global\eqaligncolumn\plusone
+ \numberedeqalign}
+
+\def\dostopmathalignment
+ {\finishalignno
+ \popmacro\doalignNC}
+
+\def\definemathalignment
+ {\dodoubleempty\dodefinemathalignment}
+
+\def\dodefinemathalignment[#1]% [#2]%
+ {\setvalue{\e!start#1}{\dodoubleempty\dostartmathalignment[#1]}%
+ \setvalue{\e!stop #1}{\dostopmathalignment}%
+ \setupmathalignment[#1]}% [#2]
+
+%D For the moment we only provide english commands.
+
+\definemathalignment[align] % default case (this is what amstex users expect)
+\definemathalignment[\v!mathalignment] % prefered case (this is cleaner, less clashing)
+
+%D \startbuffer
+%D \placeformula \startformula \eqalignno {
+%D a &= b & \formulanumber \cr
+%D c &= d \cr
+%D &= e \cr
+%D &= f & \formulanumber
+%D } \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign
+%D \NC a \EQ b \NR[+]
+%D \NC c \EQ d \NR
+%D \NC \EQ f \NR[for:demo-a-1]
+%D \NC \EQ g \NR[for:demo-a-2][a]
+%D \NC \EQ h \NR[for:demo-a-3][b]
+%D \NC \EQ i \NR
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign
+%D \NC a \EQ b \NR[+]
+%D \NC c \EQ d \NR
+%D \NC \EQ f \NR
+%D \NC \EQ g \NR
+%D \NC \EQ h \NR
+%D \NC \EQ i \NR[+]
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign
+%D a &= b \\
+%D c &= d \notag \\
+%D &= e \notag \\
+%D &= f \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign
+%D \NC a \NC \eq b \NR[+]
+%D \NC c \NC \neq d \NR
+%D \NC \NC \neq f \NR[for:demo-b-1]
+%D \NC \NC \geq g \NR[for:demo-b-2][a]
+%D \NC \NC \leq h \NR[for:demo-b-3][b]
+%D \NC \NC \neq i \NR
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[*]
+%D a &= b \\
+%D c &= d \\
+%D &= e \\
+%D &= f \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign
+%D x &= y \\
+%D a &= b \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[m=3]
+%D x &= y & x &= y & z &= t \\
+%D a &= b & p &= q & w &= s \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[m=3,distance=0pt]
+%D x &= y &= x &= y &= z &= t \\
+%D a &= b &= p &= q &= w &= s \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[n=5,distance=0pt]
+%D x &= yy &= xx &= yy &= zz \\
+%D a &= b &= p &= q &= w \\
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[n=3,align={left,middle,right}]
+%D \NC l \NC = \NC r \NR
+%D \NC left \NC = \NC right \NR
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[n=3,align={right,middle,left}]
+%D \NC l \NC = \NC r \NR
+%D \NC left \NC = \NC right \NR
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startalign[n=3,align={middle,middle,middle}]
+%D \NC l \NC = \NC r \NR
+%D \NC left \NC = \NC right \NR
+%D \stopalign \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula
+%D \startformula
+%D \startalign[n=3,align={middle,middle,middle}]
+%D \NC a \NC = \NC b \NR[+]
+%D \NC 2a \NC = \NC 2b \NR
+%D \stopalign
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula
+%D \startformulas
+%D \setupmathalignment[n=3,align={middle,middle,middle}]%
+%D \startformula
+%D \startalign
+%D \NC a \NC = \NC b \NR[+]
+%D \NC 2a \NC = \NC 2b \NR
+%D \stopalign
+%D \stopformula
+%D \startformula
+%D \startalign
+%D \NC a \NC = \NC b \NR[+]
+%D \NC 2a \NC = \NC 2b \NR
+%D \stopalign
+%D \stopformula
+%D \stopformulas
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula
+%D \startformulas
+%D \dorecurse{5}{\startformula
+%D \startalign[n=3,align={middle,middle,middle}]
+%D \NC a \NC = \NC b \NR[+]
+%D \NC 2a \NC = \NC 2b \NR
+%D \stopalign
+%D \stopformula}
+%D \stopformulas
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {definemathcases, setupmathcases, startmathcases}
+%D
+%D Another wish \unknown
+
+\def\setupmathcases
+ {\dodoubleempty\dosetupmathcases}
+
+\def\dosetupmathcases[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??ce#1][#2]%
+ \else
+ \getparameters[\??ce][#1]%
+ \fi}
+
+\let\currentmathcases\empty
+
+\def\mathcasesparameter#1%
+ {\executeifdefined{\??ce\currentmathcases#1}{\executeifdefined{\??ce#1}\empty}}
+
+\setupmathcases
+ [\c!distance=1em,
+ \c!numberdistance=2.5em,
+ \c!left={\left\{\,},
+ \c!right={\right.}]
+
+\def\dodocasesNC
+ {\gdef\docasesNC{\endmath&}}
+
+\let\docasesNR\doalignNR
+
+\def\dostartmathcases[#1][#2]%
+ {\begingroup
+ \edef\currentmathcases{#1}%
+ \doifassignmentelse{#2}{\setupmathcases[#1][#2]}\donothing
+ \mathcasesparameter\c!left
+ \vcenter\bgroup
+ \pushmacro\docasesNC
+ \let\endmath\relax
+ \def\NC{\docasesNC}%
+ \def\MC{\docasesNC\ifmmode\else$\def\endmath{$}\fi}%
+ \global\let\docasesNC\dodocasesNC
+ \def\NR{\unskip\endmath&\global\let\docasesNC\dodocasesNC\doxxdoubleempty\docasesNR}%
+ \normalbaselines
+ \mathsurround\zeropoint
+ \everycr\emptytoks
+ \tabskip\zeropoint
+ \global\eqaligncolumn\plusone
+ \halign\bgroup
+ $\mathcasesparameter\c!style##$\hfil
+ &\hskip\mathcasesparameter\c!distance\relax
+ \popmacro\docasesNC##\hfil
+ &\hskip\mathcasesparameter\c!numberdistance\relax
+ \let\formuladistance\!!zeropoint
+ \span\textineqalign{##}%
+ \crcr} % todo: number
+
+\def\dostopmathcases
+ {\crcr
+ \egroup
+ \popmacro\docasesNC
+ \egroup
+ \mathcasesparameter\c!right
+ \endgroup}
+
+\def\definemathcases
+ {\dodoubleempty\dodefinemathcases}
+
+\def\dodefinemathcases[#1]% [#2]%
+ {\setvalue{\e!start#1}{\dodoubleempty\dostartmathcases[#1]}%
+ \setvalue{\e!stop #1}{\dostopmathcases}%
+ \setupmathcases[#1]}% [#2]
+
+\definemathcases[cases]
+\definemathcases[\v!mathcases]
+
+%D \startbuffer
+%D \placeformula \startformula \startcases
+%D \NC 2 \NC $ y > 0 $ \NR
+%D \NC 7 \NC $ x = 7 $ \NR[+]
+%D \NC 4 \NC otherwise \NR
+%D \stopcases \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula x \startcases
+%D \NC 2 \NC $ y > 0 $ \NR[+]
+%D \NC 7 \NC $ x = 7 $ \NR
+%D \NC 4 \NC otherwise \NR
+%D \stopcases \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula \startcases
+%D \NC 2 \NC $ y > 0 $ \NR
+%D \NC 7 \NC $ x = 7 $ \NR
+%D \NC 4 \NC otherwise \NR
+%D \stopcases \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \placeformula \startformula x \startcases
+%D \NC 2 \NC $ y > 0 $ \NR
+%D \NC 7 \NC $ x = 7 $ \NR
+%D \NC 4 \NC otherwise \NR
+%D \stopcases \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {definemathmatrix, setupmathmatrix, startmathmatrix}
+%D
+%D Yet another one \unknown
+
+\def\setupmathmatrix
+ {\dodoubleempty\dosetupmathmatrix}
+
+\def\dosetupmathmatrix[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??mx#1][#2]%
+ \else
+ \getparameters[\??mx][#1]%
+ \fi}
+
+\let\currentmathmatrix\empty
+
+\def\mathmatrixparameter#1%
+ {\executeifdefined{\??mx\currentmathmatrix#1}{\executeifdefined{\??mx#1}\empty}}
+
+\setupmathmatrix
+ [\c!distance=1em,
+ \c!left=,
+ \c!right=,
+ \c!align=\v!middle]
+
+\def\dosetmatrixcolumn#1% hh: todo: \definematrixalign
+ {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
+ \letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil
+ \doif{#1}\v!left {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\relax
+ \letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil}%
+ \doif{#1}\v!right {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
+ \letvalue{\??eq:\v!right:\number\eqaligncolumn}\relax }%
+ \doif{#1}\v!middle{\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfil
+ \letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfil}}
+
+\def\buildmathmatrix % beware: etex only
+ {\scratchtoks\emptytoks
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}%
+ \dorecurse{\numexpr\scratchcounter-\plusone\relax}
+ {\normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}%
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc }}}
+
+\def\preparemathmatrix
+ {\!!toksa{\strut \firstineqalign\leftofeqalign \span
+ \textineqalign{\mathmatrixparameter\c!style ##}\rightofeqalign}%
+ \!!toksb{&\hskip\mathmatrixparameter\c!distance
+ \nextineqalign\leftofeqalign \span
+ \textineqalign{\mathmatrixparameter\c!style ##}\rightofeqalign}%
+ \!!toksc{&&\hskip\mathmatrixparameter\c!distance
+ \leftofeqalign \span
+ \textineqalign{\mathmatrixparameter\c!style ##}\rightofeqalign}%
+ \buildmathmatrix
+ \halign \@EA \bgroup\the\scratchtoks \crcr}
+
+\def\definemathmatrix
+ {\dodoubleempty\dodefinemathmatrix}
+
+\def\dodefinemathmatrix[#1]% [#2]%
+ {\setvalue{\e!start#1}{\dodoubleempty\dostartmathmatrix[#1]}%
+ \setvalue{\e!stop #1}{\dostopmathmatrix}%
+ \setupmathmatrix[#1]}% [#2]
+
+\definemathmatrix[matrix]
+\definemathmatrix[\v!mathmatrix]
+
+\def\dodomatrixNC
+ {\gdef\domatrixNC{\endmath&}}
+
+\def\installmathmatrixhandler#1#2%
+ {\setvalue{\??mx:#1}{#2}}
+
+% First alternative:
+%
+% \def\processlowhighmathmatrix#1%
+% {\def\mathmatrixleft
+% {\setbox\nextbox}
+% \def\mathmatrixright
+% {#1.5\dimexpr\nextboxdp-\nextboxht\relax
+% \hbox{$\mathmatrixparameter\c!left
+% \vcenter{\unvbox\nextbox}%
+% \mathmatrixparameter\c!right$}}%
+% \let\mathmatrixbox\vbox}
+%
+% \installmathmatrixhandler\v!high {\processlowhighmathmatrix\raise}
+% \installmathmatrixhandler\v!low {\processlowhighmathmatrix\lower}
+%
+% \installmathmatrixhandler\v!top {\processlowhighmathmatrix\raise}
+% \installmathmatrixhandler\v!bottom{\processlowhighmathmatrix\lower}
+%
+% \installmathmatrixhandler\v!lohi
+% {\def\mathmatrixleft {\mathmatrixparameter\c!left}%
+% \def\mathmatrixright{\mathmatrixparameter\c!right}%
+% \let\mathmatrixbox\vcenter}
+%
+% An alternative
+%
+% \let\mathmatrixleft \empty
+% \let\mathmatrixright\empty
+%
+% \def\processlowhighmathmatrix#1%
+% {\dowithnextbox
+% {#1.5\dimexpr\nextboxdp-\nextboxht\relax
+% \hbox{$\mathmatrixparameter\c!left
+% \vcenter{\unvbox\nextbox}%
+% \mathmatrixparameter\c!right$}}%
+% \vbox}
+%
+% \def\processlohimathmatrix
+% {\dowithnextbox
+% {\mathmatrixparameter\c!left
+% \vcenter{\unvbox\nextbox}%
+% \mathmatrixparameter\c!right}%
+% \vbox}
+%
+% \installmathmatrixhandler\v!high {\def\mathmatrixbox{\processlowhighmathmatrix\raise}}
+% \installmathmatrixhandler\v!low {\def\mathmatrixbox{\processlowhighmathmatrix\lower}}
+% \installmathmatrixhandler\v!top {\def\mathmatrixbox{\processlowhighmathmatrix\raise}}
+% \installmathmatrixhandler\v!bottom{\def\mathmatrixbox{\processlowhighmathmatrix\lower}}
+% \installmathmatrixhandler\v!lohi {\let\mathmatrixbox \processlohimathmatrix}
+%
+% Final version
+
+\let\mathmatrixleft \empty % experimental hook
+\let\mathmatrixright\empty % experimental hook
+
+\def\processlowhighmathmatrix#1#2%
+ {\dowithnextbox
+ {\scratchdimen\dimexpr(\nextboxdp-\nextboxht)/2 \ifcase#2\or+\mathaxisheight\textfont2\fi\relax
+ \ifcase#1\relax\or\lower\scratchdimen\or\or\raise\scratchdimen\fi
+ \hbox{$\mathmatrixparameter\c!left
+ \vcenter{\unvbox\nextbox}%
+ \mathmatrixparameter\c!right$}}%
+ \vbox}
+
+\installmathmatrixhandler\v!top {\def\mathmatrixbox{\processlowhighmathmatrix\plusthree\plusone }}
+\installmathmatrixhandler\v!high {\def\mathmatrixbox{\processlowhighmathmatrix\plusthree\zerocount}}
+\installmathmatrixhandler\v!lohi {\def\mathmatrixbox{\processlowhighmathmatrix\plustwo \zerocount}}
+\installmathmatrixhandler\v!low {\def\mathmatrixbox{\processlowhighmathmatrix\plusone \zerocount}}
+\installmathmatrixhandler\v!bottom{\def\mathmatrixbox{\processlowhighmathmatrix\plusone \plusone }}
+
+\def\dostartmathmatrix[#1][#2]%
+ {\begingroup
+ \edef\currentmathmatrix{#1}%
+ \doifassignmentelse{#2}{\setupmathmatrix[#1][#2]}\donothing
+ \null
+ \executeifdefined{\??mx:\mathmatrixparameter\c!location}{\getvalue{\??mx:\v!lohi}}%
+ \mathmatrixleft
+ \mathmatrixbox\bgroup
+ \pushmacro\domatrixNC
+ \let\endmath\relax
+ \def\NC{\domatrixNC}%
+ \def\MC{\domatrixNC\ifmmode\else$\def\endmath{$}\fi}%
+ \global\let\domatrixNC\dodomatrixNC
+ \def\NR{\endmath\global\let\domatrixNC\dodomatrixNC\crcr}%
+ \normalbaselines
+ \mathsurround\zeropoint
+ \everycr\emptytoks
+ \tabskip\zeropoint
+ \eqaligncolumn\zerocount % could be \scratchcounter
+ \processcommacommand[\mathmatrixparameter\c!align]{\advance\eqaligncolumn\plusone\dosetmatrixcolumn}%
+ \scratchcounter=\ifnum\eqaligncolumn>\zerocount \eqaligncolumn \else \plusone \fi
+ \global\eqaligncolumn\plusone
+ \preparemathmatrix } % uses scratchcounter
+
+\def\dostopmathmatrix
+ {\crcr
+ \mathstrut\crcr
+ \noalign{\kern-\baselineskip}%
+ \egroup
+ \popmacro\domatrixNC
+ \egroup
+ \mathmatrixright
+ \endgroup}
+
+%D \startbuffer
+%D \placeformula \startformula[-] \startmatrix
+%D \NC 1 \NC x \NC a \NR
+%D \NC 2 \NC y \NC b \NR
+%D \NC 3 \NC z \NC c \NR
+%D \stopmatrix \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \definemathmatrix[bmatrix][left={\left[\,},right={\,\right]}]
+%D
+%D \startbuffer
+%D \placeformula \startformula[-] \startbmatrix
+%D \NC 1 \NC x \NC a \NR
+%D \NC 2 \NC y \NC b \NR
+%D \NC 3 \NC z \NC c \NR
+%D \stopbmatrix \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D Taco added some code (dedicated to Aditya Mahajan) that gives more
+%D control over aligments:
+
+%D \startbuffer
+%D \startformula
+%D \startmatrix
+%D \NC a + x \NC = \NC a + d \NR
+%D \NC y \NC = \NC d \NR
+%D \stopmatrix
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \startbuffer
+%D \startformula
+%D \startmatrix [distance=3pt,align={right,left}]
+%D \NC a + x \NC = a + d \NR
+%D \NC y \NC = d \NR
+%D \stopmatrix
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \startbuffer
+%D \startformula
+%D \startmatrix [left=\left(,right=\right)]
+%D \NC a + x \NR
+%D \NC y \NR
+%D \stopmatrix
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D A bit more complex code:
+%D
+%D \startbuffer
+%D \startformula
+%D \text{Let }{\cal R} = \bigcup_{P_{X_1},P_{X_2}}
+%D \left\{ (R_1, R_2) :
+%D \startmatrix[distance=1em,align={left,left,right}]
+%D \NC R_1 \NC < I(X_1 ; Y \mid X_2) \NC R_1 \NR
+%D \NC \hfill Q_2 \NC < I(X_2 ; Y \mid X_1) \NC R_2 \NR
+%D \NC R_1 + R_2 \NC < I(X_1 ; Y) \NC R_1 + R_2 \NR
+%D \stopmatrix
+%D \right\}
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {startmatrices}
+%D
+%D Just a handy keystroke safer:
+
+\def\startmatrices
+ {\begingroup
+ \setupmathmatrix}
+
+\def\stopmatrices
+ {\endgroup}
+
+%D \startbuffer
+%D \startformula
+%D \startmatrix[left={\left(},right={\right)}]
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D =
+%D \startmatrix[left={\left(},right={\right)},location=low]
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D =
+%D \startmatrix[left={\left(},right={\right)},location=high]
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D \startformula
+%D \startmatrices[left={\left(},right={\right)}]
+%D \startmatrix
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D =
+%D \startmatrix[location=bottom]
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D =
+%D \startmatrix[location=top]
+%D \NC A \NC B \NR \NC C \NC D \NR
+%D \stopmatrix
+%D \stopmatrices
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+%D \macros
+%D {startintertext}
+%D
+%D Preliminary feature:
+%D
+%D {\em example code}
+
+\def\startintertext#1\stopintertext
+ {\noalign{\dointertext{#1}}}
+
+\def\intertext#1%
+ {\noalign{\dointertext{#1}}}
+
+\unexpanded\def\dointertext#1%
+ {\penalty\postdisplaypenalty
+ \afterdisplayspace
+ \vbox{\forgetall\noindent#1\par}%
+ \penalty\predisplaypenalty
+ \beforedisplayspace}
+
+% %D \macros
+% %D {substack}
+% %D
+% %D Preliminary code:
+% %D
+% %D \starttyping
+% %D \startformula
+% %D \sum_{%
+% %D \startsubstack
+% %D i = 1 \NR
+% %D i \neq n \NR
+% %D i \neq m
+% %D \stopsubstack
+% %D }a_i
+% %D \stopformula
+% %D \stoptyping
+
+% \def\startsubstack
+% {\begingroup
+% \null
+% \vcenter\bgroup
+% \pushmacro\domatrixNC
+% \let\stopmathmode\relax
+% \def\NC{\domatrixNC}%
+% \def\MC{\domatrixNC\startmathmode}%
+% \global\let\domatrixNC\dodomatrixNC
+% \def\NR
+% {\stopmathmode
+% \global\let\domatrixNC\dodomatrixNC
+% \crcr\noalign{\nointerlineskip}}%
+% \mathsurround\zeropoint
+% \everycr\emptytoks
+% \halign\bgroup\hfil$\scriptstyle\mathstrut##$\hfil\crcr}
+
+% \def\stopsubstack
+% {\crcr
+% \egroup
+% \popmacro\domatrixNC
+% \egroup
+% \endgroup}
+
+%D \macros
+%D {substack}
+%D
+%D Preliminary code:
+%D
+%D \startbuffer
+%D \startformula
+%D \sum_{%
+%D \startsubstack
+%D i = 1 \NR
+%D i \neq n \NR
+%D i \neq m
+%D \stopsubstack
+%D }a_i
+%D \stopformula
+%D \stopbuffer
+%D
+%D \getbuffer which was typed as \typebuffer
+%D
+%D Notice that these macros give the correct spacing for
+%D subscripts. Compare for example
+%D
+%D \startbuffer
+%D \startformula
+%D \sum_{\startsubstack a \NR b \NR \stopsubstack}
+%D \text{ and }
+%D \sum_{\scriptstyle a \atop \scriptstyle}
+%D \stopformula
+%D \typebuffer which gives \getbuffer
+
+\def\startsubstack
+ {\begingroup
+ \vcenter\bgroup
+ \baselineskip\mathstacktotal
+ \lineskip\mathstackvgap
+ \lineskiplimit\lineskip
+ \let\stopmathmode\relax
+ \def\NC{\domatrixNC}%
+ \def\MC{\domatrixNC\startmathmode}%
+ \global\let\domatrixNC\dodomatrixNC
+ \def\NR
+ {\stopmathmode
+ \global\let\domatrixNC\dodomatrixNC
+ \crcr}%
+ \mathsurround\zeropoint
+ \everycr\emptytoks
+ \halign\bgroup\hfil$\scriptstyle##$\hfil\crcr}
+
+\def\stopsubstack
+ {\crcr
+ \egroup
+ \egroup
+ \endgroup}
+
+%D \macros
+%D {bordermatrix}
+%D
+%D In \PLAIN\ \TEX\ the width of a parenthesis is stored in
+%D the \DIMENSION\ \type{\mathparentwd}. This value is derived from
+%D the width of \type{\tenrm B}, so let's take care of it now:
+
+\ifx\mathparentwd\undefined \newdimen\mathparentwd \fi
+
+\let\normalbordermatrix\bordermatrix
+
+\def\bordermatrix
+ {\begingroup
+ \setbox\scratchbox\hbox{\mr\char"239C}%
+ \global\mathparentwd\wd\scratchbox\relax
+ \endgroup
+ \normalbordermatrix}
+
+% to be tested
+%
+% \def\bordermatrix
+% {\begingroup\mr\global\mathparentwd\fontcharwd\font"239C\relax\endgroup
+% \normalbordermatrix}
+
+%D \macros{overset, underset}
+%D
+%D The macros \type{\overset} and \type{\underset} are provided by
+%D \AMS\ packages in \LATEX. These macro allows you to place a symbol
+%D above or below another symbol, irrespective of whether the other
+%D symbol is a relation or something else, and without influencing the
+%D spacing. For most cases there is a better way to do such things
+%D (declaring a math command with limop option, or using accents), but
+%D occasionally these macros can be useful, for example:
+%D
+%D \startbuffer
+%D \startformula
+%D \overset{*}{X} \underset{*}{X}
+%D \stopformula
+%D \stopbuffer
+%D \typebuffer \getbuffer
+%D
+%D Use these macros sparingly. Remember, \TEX\ was designed for
+%D mathematics, so there is usually a proper method for typesetting
+%D common math notation.
+
+%D These macros are a clearer version of \type{\binrel@} and
+%D \type{\binrel@@} macros in \AMSTEX\ packages.
+
+\def\preparebinrel#1%
+ {\begingroup
+ \setbox\scratchbox\hbox
+ {\thinmuskip 0mu
+ \medmuskip -1mu
+ \thickmuskip -1mu
+ \setbox\scratchbox\hbox{$#1\mathsurround\zeropoint$}%
+ \kern-\wd\scratchbox
+ ${}#1{}\mathsurround\zeropoint$}%
+ \normalexpanded
+ {\endgroup
+ \let\noexpand\currentbinrel
+ \ifdim\wd\scratchbox<\zeropoint
+ \mathbin
+ \else\ifdim\wd\scratchbox>\zeropoint
+ \mathrel
+ \else
+ \relax
+ \fi\fi}}
+
+\unexpanded\def\overset#1#2%
+ {\preparebinrel{#2}%
+ \currentbinrel{\mathop{\kern\zeropoint#2}\limits^{#1}}}
+
+\unexpanded\def\underset#1#2%
+ {\preparebinrel{#2}%
+ \currentbinrel{\mathop{\kern\zeropoint#2}\limits_{#1}}}
+
+\protect \endinput
+
+% \placeformula \startformula[-] \startmatrix
+% \NC 1 \NC x \NC a \NR
+% \NC 2 \NC y \NC b \NR
+% \NC 3 \NC z \NC c \NR
+% \stopmatrix \stopformula
+
+% \definemathmatrix[bordermatrix][left={\left[\,},right={\,\right]}]
+
+% \placeformula \startformula[-] \startbordermatrix
+% \NC 1 \NC x \NC a \NR
+% \NC 2 \NC y \NC b \NR
+% \NC 3 \NC z \NC c \NR
+% \stopbordermatrix \stopformula
diff --git a/tex/context/base/math-ams.tex b/tex/context/base/math-ams.tex
index 29fe19e0b..83070d01a 100644
--- a/tex/context/base/math-ams.tex
+++ b/tex/context/base/math-ams.tex
@@ -311,7 +311,7 @@
\stopmathcollection
\def\AMSwidehat#1%
- {\setbox\scratchbox\hbox{$\m@th#1$}%
+ {\setbox\scratchbox\hbox{$\mathsurround\zeropoint#1$}%
\ifdim\wd\scratchbox>2em
\mathaccent"0\purefamilyhex{mb}5B{#1}%
\else
@@ -319,7 +319,7 @@
\fi}
\def\AMSwidetilde#1%
- {\setbox\scratchbox\hbox{$\m@th#1$}%
+ {\setbox\scratchbox\hbox{$\mathsurround\zeropoint#1$}%
\ifdim\wd\scratchbox>2em
\mathaccent"0\purefamilyhex{mb}5D{#1}%
\else
diff --git a/tex/context/base/math-arr.mkii b/tex/context/base/math-arr.mkii
new file mode 100644
index 000000000..3b9abaa91
--- /dev/null
+++ b/tex/context/base/math-arr.mkii
@@ -0,0 +1,391 @@
+%D \module
+%D [ file=math-ext,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Arrows,
+%D author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Arrows}
+
+\unprotect
+
+%D These will be generalized! Is it still needed in \MKIV?
+
+%D We next define extensible arrows. Extensible arrows are arrows that
+%D change their length according to the width of the text to be placed
+%D above and below the arrow. Since we need to define a lot of arrows,
+%D we first define some helper macros. The basic idea is to measure
+%D the width of the box to be placed above and below the arrow, and
+%D make the \quotation{body} of the arrow as long as the bigger of the
+%D two widths.
+
+\def\mtharrfactor{1}
+\def\mtharrextra {0}
+
+\def\domthxarr#1#2#3#4#5% hm, looks like we do a double mathrel
+ {\begingroup
+ \def\mtharrfactor{1}%
+ \def\mtharrextra {0}%
+ \processaction[#1] % will be sped up
+ [ \v!none=>\def\mtharrfactor{0},
+ \v!small=>\def\mtharrextra{10},
+ \v!medium=>\def\mtharrextra{15},
+ \v!big=>\def\mtharrextra{20},
+ \v!normal=>,
+ \v!default=>,
+ \v!unknown=>\doifnumberelse{#1}{\def\mtharrextra{#1}}\donothing]%
+ \mathsurround\zeropoint
+ \muskip0=\thirdoffourarguments #2mu
+ \muskip2=\fourthoffourarguments #2mu
+ \muskip4=\firstoffourarguments #2mu
+ \muskip6=\secondoffourarguments #2mu
+ \muskip0=\mtharrfactor\muskip0 \advance\muskip0 \mtharrextra mu
+ \muskip2=\mtharrfactor\muskip2 \advance\muskip2 \mtharrextra mu
+ \setbox0\hbox{$\scriptstyle
+ \mkern\muskip4\relax
+ \mkern\muskip0\relax
+ #5\relax
+ \mkern\muskip2\relax
+ \mkern\muskip6\relax
+ $}%
+ \setbox4\hbox{#3\displaystyle}%
+ \dimen0\wd0
+ \ifdim\wd4>\dimen0 \dimen0\wd4 \fi
+ \setbox2\hbox{$\scriptstyle
+ \mkern\muskip4\relax
+ \mkern\muskip0\relax
+ #4\relax
+ \mkern\muskip2\relax
+ \mkern\muskip6\relax
+ $}%
+ \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
+ \setbox4\hbox to \dimen0{#3\displaystyle}%
+ \mathrel{\mathop{\hbox to \dimen0{\hss\copy4\hss}}\limits^{\box0}_{\box2}}
+ \endgroup}
+
+\let\domthxarrsingle\domthxarr
+
+%D There are some arrows which are created by stacking two arrows. The next
+%D macro helps in defining such \quotation{double arrows}.
+
+\def\domthxarrdouble#1#2#3#4#5#6#7% opt l r sp rs top bot
+ {\mathrel
+ {\scratchdimen.32ex\relax % was .22, todo: make configurable
+ \setbox0\hbox{$\domthxarr{#1}{#2}{#4}{\phantom{#6}}{#7}$}%
+ \setbox2\hbox{$\domthxarr{#1}{#3}{#5}{#6}{\phantom{#7}}$}%
+ \raise\scratchdimen\box0
+ \kern-\wd2
+ \lower\scratchdimen\box2}}
+
+%D \macros{definematharrow}
+%D
+%D Macro for defining new arrows. We can define two types of
+%D arrows|<|single arrows and double arrows. Single arrows are defined
+%D as
+%D
+%D \starttyping
+%D \definematharrow [xrightarrow] [0359] [\rightarrowfill]
+%D \stoptyping
+%D
+%D The first argument is the name of the arrow (\tex{xrightarrow} in
+%D this case.) The second argument consists of a set of 4 numbers and
+%D specify the spacing correction in math units~\type{mu}. These
+%D numbers define:
+%D
+%D \startlines
+%D 1st number: arrow||tip correction
+%D 2nd number: arrow||tip correction
+%D 3rd number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
+%D 4th number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
+%D \stoplines
+%D
+%D The third argument is the name of the extensible fill. The third
+%D argument is optional when the arrow is redefined later (this is
+%D useful for font specific tweaking of the skips.) For example,
+%D
+%D \startbuffer
+%D \math{\xrightarrow{above}}
+%D \definematharrow[xrightarrow][0000]
+%D \math{\xrightarrow{above}}
+%D \definematharrow[xrightarrow][55{50}{50}]
+%D \math{\xrightarrow{above}}
+%D \stopbuffer
+%D \typebuffer gives {\getbuffer}
+%D
+%D The double arrows are defined as follows
+%D
+%D \starttyping
+%D \definematharrow [xrightleftharpoons] [3095,0359]
+%D [\rightharpoonupfill,\leftharpoondownfill]
+%D \stoptyping
+%D
+%D The second and the third set of arguments consist of comma
+%D separated values. The first element of the second argument
+%D (\type{3095}) corresponds to the spacing correction of top arrow
+%D fill (\tex{rightarrowupfill}). Similarly, \type{0359} corresponds
+%D to bottom arrow fill \tex{leftharpoondownfill}). Stacking them on
+%D top of each other we get $\xrightleftharpoons[big]{above}{below}$.
+%D The following math arrows are defined
+%D
+%D \placetable[none]{}{\starttable[|l|m|]
+%D \NC \tex{xrightarrow } \NC \xrightarrow [big] \NC \NR
+%D \NC \tex{xleftarrow } \NC \xleftarrow [big] \NC \NR
+%D \NC \tex{xequal } \NC \xequal [big] \NC \NR
+%D \NC \tex{xRightarrow } \NC \xRightarrow [big] \NC \NR
+%D \NC \tex{xLeftarrow } \NC \xLeftarrow [big] \NC \NR
+%D \NC \tex{xLeftrightarrow } \NC \xLeftrightarrow [big] \NC \NR
+%D \NC \tex{xleftrightarrow } \NC \xleftrightarrow [big] \NC \NR
+%D \NC \tex{xmapsto } \NC \xmapsto [big] \NC \NR
+%D \NC \tex{xtwoheadrightarrow } \NC \xtwoheadrightarrow [big] \NC \NR
+%D \NC \tex{xtwoheadleftarrow } \NC \xtwoheadleftarrow [big] \NC \NR
+%D \NC \tex{xrightharpoondown } \NC \xrightharpoondown [big] \NC \NR
+%D \NC \tex{xrightharpoonup } \NC \xrightharpoonup [big] \NC \NR
+%D \NC \tex{xleftharpoondown } \NC \xleftharpoondown [big] \NC \NR
+%D \NC \tex{xleftharpoonup } \NC \xleftharpoonup [big] \NC \NR
+%D \NC \tex{xhookleftarrow } \NC \xhookleftarrow [big] \NC \NR
+%D \NC \tex{xhookrightarrow } \NC \xhookrightarrow [big] \NC \NR
+%D \NC \tex{xleftrightharpoons } \NC \xleftrightharpoons [big] \NC \NR
+%D \NC \tex{xrightleftharpoons } \NC \xrightleftharpoons [big] \NC \NR
+%D \stoptable}
+
+\def\definematharrow
+ {\doquadrupleargument\dodefinematharrow}
+
+\def\dodefinematharrow[#1][#2][#3][#4]% name type[none|both] template command
+ {\iffourthargument
+ \executeifdefined{dodefine#2arrow}\gobblethreearguments{#1}{#3}{#4}%
+ \else\ifthirdargument
+ \dodefinebotharrow{#1}{#2}{#3}%
+ \else\ifsecondargument
+ \redefinebotharrow{#1}{#2}{#3}%
+ \fi\fi\fi}
+
+\def\redefinebotharrow#1#2#3% real dirty, this overload!
+ {\doifdefined{#1}
+ {\pushmacro\dohandlemtharrow
+ \def\dohandlemtharrow[##1][##2]{\setvalue{#1}{\dohandlemtharrow[#2][##2]}}%
+ % == \def\dohandlemtharrow[##1][##2]{\dodefinebotharrow{#1}{#2}{##2}}%
+ \getvalue{#1}%
+ \popmacro\dohandlemtharrow}}
+
+\def\dodefinebotharrow#1#2#3%
+ {\setvalue{#1}{\dohandlemtharrow[#2][#3]}}
+
+\def\dohandlemtharrow
+ {\dotripleempty\doxmtharrow}
+
+\def\doxmtharrow[#1][#2][#3]% #3 == optional arg
+ {\def\dodoxmtharrow{\dododoxmtharrow[#1,\empty,\empty][#2,\empty,\empty][#3]}% {##1}{##2}
+ \dodoublegroupempty\dodoxmtharrow}
+
+\def\dododoxmtharrow[#1,#2,#3][#4,#5,#6][#7]#8#9% [3] is the optional arg
+ {\edef\!!stringa{#2}%
+ \ifx\!!stringa\empty
+ \ifsecondargument
+ \mathrel{\domthxarrsingle{#7}{#1}{#4}{#8}{#9}}%
+ \else
+ \mathrel{\domthxarrsingle{#7}{#1}{#4}{}{#8}}%
+ \fi
+ \else
+ \ifsecondargument
+ \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{#8}{#9}}%
+ \else
+ \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{}{#8}}%
+ \fi
+ \fi}
+
+% Adapted from amsmath.
+
+%D \macros{mtharrowfill,defaultmtharrowfill}
+%D
+%D To extend the arrows we need to define a \quotation{math arrow
+%D fill}. This command takes 8 arguments: the first four correspond
+%D the second argument of \tex{definematharrow} explained above. The
+%D other three specify the tail, body and head of the arrow. The last
+%D argument specifies the math-mode in which the arrow is drawn.
+%D \tex{defaultmtharrowfill} has values tweaked to match Latin Modern
+%D fonts. For fonts that are significantly different (e.g. cows) a
+%D different set of values need to be determined.
+
+\def\mtharrowfill#1#2#3#4#5#6#7#8%
+ {$\mathsurround 0pt
+ \thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip
+ \relax#8#5%
+ \mkern-#1mu
+ \cleaders\hbox{$#8\mkern -#2mu#6\mkern -#3mu$}\hfill
+ \mkern-#4mu#7$}
+
+\def\defaultmtharrowfill{\mtharrowfill 7227}
+
+%D We now define some arrow fills that will be used for defining the
+%D arrows. Plain \TEX\ already defines \tex{leftarrowfill} and
+%D \tex{rightarrowfill}. The \tex{defaultmtharrowfill} command defines an
+%D arrowfill that takes an argument (so that it can also be used
+%D with over and under arrows). However the Plain \TEX\ definitions of
+%D \tex{leftarrowfill} and \tex{rightarrowfill} do not take this extra
+%D argument. To be backward compatible with Plain \TEX, we define two
+%D arrowfills: \tex{specrightarrowfill} which takes an extra argument, and
+%D \tex{rightarrowfill} which does not.
+
+\def\specrightarrowfill {\defaultmtharrowfill \relbar \relbar \rightarrow}
+\def\specleftarrowfill {\defaultmtharrowfill \leftarrow \relbar \relbar}
+
+\def\rightarrowfill {\specrightarrowfill \textstyle}
+\def\leftarrowfill {\specleftarrowfill \textstyle}
+
+\def\equalfill {\defaultmtharrowfill \Relbar \Relbar \Relbar}
+\def\Rightarrowfill {\defaultmtharrowfill \Relbar \Relbar \Rightarrow}
+\def\Leftarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Relbar}
+\def\Leftrightarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Rightarrow}
+\def\leftrightarrowfill {\defaultmtharrowfill \leftarrow \relbar \rightarrow}
+\def\mapstofill {\defaultmtharrowfill{\mapstochar\relbar} \relbar \rightarrow}
+\def\twoheadrightarrowfill{\defaultmtharrowfill \relbar \relbar \twoheadrightarrow}
+\def\twoheadleftarrowfill {\defaultmtharrowfill \twoheadleftarrow \relbar \relbar}
+\def\rightharpoondownfill {\defaultmtharrowfill \relbar \relbar \rightharpoondown}
+\def\rightharpoonupfill {\defaultmtharrowfill \relbar \relbar \rightharpoonup}
+\def\leftharpoondownfill {\defaultmtharrowfill \leftharpoondown \relbar \relbar}
+\def\leftharpoonupfill {\defaultmtharrowfill \leftharpoonup \relbar \relbar}
+\def\hookleftfill {\defaultmtharrowfill \leftarrow \relbar{\relbar\joinrel\rhook}}
+\def\hookrightfill {\defaultmtharrowfill{\lhook\joinrel\relbar}\relbar \rightarrow}
+\def\relfill {\defaultmtharrowfill \relbar \relbar \relbar}
+
+\def\triplerelbar {\mathrel\equiv}
+\def\triplerelfill{\defaultmtharrowfill\triplerelbar\triplerelbar\triplerelbar}
+
+\def\singlebond{{\xrel}} % or \def\singlebond{{\xrel[2]}}
+\def\doublebond{{\xequal}}
+\def\triplebond{{\xtriplerel}}
+
+%D Now we define most commonly used arrows. These include arrows
+%D defined in \filename{amsmath.sty}, \filename{extarrows.sty},
+%D \filename{extpfel.sty} and \filename{mathtools.sty} packages for
+%D \LATEX\ (plus a few more).
+
+\definematharrow [xrightarrow] [0359] [\specrightarrowfill]
+\definematharrow [xleftarrow] [3095] [\specleftarrowfill]
+\definematharrow [xequal] [0099] [\equalfill]
+\definematharrow [xRightarrow] [0359] [\Rightarrowfill]
+\definematharrow [xLeftarrow] [3095] [\Leftarrowfill]
+\definematharrow [xLeftrightarrow] [0099] [\Leftrightarrowfill]
+\definematharrow [xleftrightarrow] [0099] [\leftrightarrowfill]
+\definematharrow [xmapsto] [3599] [\mapstofill]
+\definematharrow [xtwoheadrightarrow] [5009] [\twoheadrightarrowfill]
+\definematharrow [xtwoheadleftarrow] [0590] [\twoheadleftarrowfill]
+\definematharrow [xrightharpoondown] [0359] [\rightharpoondownfill]
+\definematharrow [xrightharpoonup] [0359] [\rightharpoonupfill]
+\definematharrow [xleftharpoondown] [3095] [\leftharpoondownfill]
+\definematharrow [xleftharpoonup] [3095] [\leftharpoonupfill]
+\definematharrow [xhookleftarrow] [3095] [\hookleftfill]
+\definematharrow [xhookrightarrow] [0395] [\hookrightfill]
+\definematharrow [xrel] [0099] [\relfill]
+\definematharrow [xtriplerel] [0099] [\triplerelfill]
+\definematharrow [xrightoverleftarrow] [0359,3095] [\specrightarrowfill,\specleftarrowfill]
+\definematharrow [xleftrightharpoons] [3399,3399] [\leftharpoonupfill,\rightharpoondownfill]
+\definematharrow [xrightleftharpoons] [3399,3399] [\rightharpoonupfill,\leftharpoondownfill]
+
+%D These arrows can be used as follows:
+%D
+%D \startbuffer
+%D \startformula \xrightarrow{stuff on top}\stopformula
+%D \startformula \xrightarrow{}{stuff on top}\stopformula
+%D \startformula \xrightarrow{stuff below}{}\stopformula
+%D \startformula \xrightarrow{stuff below}{stuff on top}\stopformula
+%D
+%D \startformula \xleftarrow [none]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [small]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [medium]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [big]{stuff below}{stuff on top}\stopformula
+%D \stopbuffer
+%D
+%D \typebuffer which gives \getbuffer
+
+%D \macros{definemathoverarrow,defineunderarrow}
+%D
+%D These macros for define math-overarrows are adapted from
+%D \filename{amsmath.sty}
+
+\def\definemathoverarrow
+ {\dotripleargument\dodefinemathoverarrow}
+
+\def\dodefinemathoverarrow[#1][#2][#3]%
+ {\ifthirdargument
+ \setvalue{#1}{\dohandlemathoverarrow[#2][#3]}%
+ \else
+ \setvalue{#1}{\dohandlemathoverarrow[\zeropoint][#2]}%
+ \fi}
+
+\def\dohandlemathoverarrow[#1][#2]%
+ {\mathpalette{\dodohandlemathoverarrow{#1}{#2}}}
+
+%D Note: \filename{math-pln.tex} has \type{\kern-\onepoint} and
+%D \filename{amsmath.sty} does not. We keep the kern amount
+%D configurable. This is useful for harpoons.
+
+\def\dodohandlemathoverarrow#1#2#3#4%
+ {\vbox{\ialign{##\crcr
+ #2#3\crcr
+ \noalign{\kern#1\nointerlineskip}%
+ $\mathsurround\zeropoint\hfil#3#4\hfil$\crcr}}}
+
+%D Now the under arrows
+
+\def\definemathunderarrow
+ {\dotripleargument\dodefinemathunderarrow}
+
+%D For underarrows the default kern is 0.3ex
+
+\def\dodefinemathunderarrow[#1][#2][#3]%
+ {\ifthirdargument
+ \setvalue{#1}{\dohandlemathunderarrow[#2][#3]}%
+ \else
+ \setvalue{#1}{\dohandlemathunderarrow[0.3ex][#2]}%
+ \fi}
+
+\def\dohandlemathunderarrow[#1][#2]%
+ {\mathpalette{\dodohandlemathunderarrow{#1}{#2}}}
+
+\def\dodohandlemathunderarrow#1#2#3#4%
+ {\vtop{\ialign{##\crcr
+ $\mathsurround\zeropoint\hfil#3#4\hfil$\crcr
+ \noalign{\nointerlineskip\kern#1}%
+ #2#3\crcr}}}
+
+%D Now we define the arrows
+
+\definemathoverarrow [overleftarrow] [\specleftarrowfill]
+\definemathoverarrow [overrightarrow] [\specrightarrowfill]
+\definemathoverarrow [overleftrightarrow] [\leftrightarrowfill]
+\definemathoverarrow [overtwoheadrightarrow] [\twoheadrightarrowfill]
+\definemathoverarrow [overtwoheadleftarrow] [\twoheadleftarrowfill]
+\definemathoverarrow [overrightharpoondown] [1pt] [\rightharpoondownfill]
+\definemathoverarrow [overrightharpoonup] [\rightharpoonupfill]
+\definemathoverarrow [overleftharpoondown] [1pt] [\leftharpoondownfill]
+\definemathoverarrow [overleftharpoonup] [\leftharpoonupfill]
+
+\definemathunderarrow [underleftarrow] [\specleftarrowfill]
+\definemathunderarrow [underrightarrow] [\specrightarrowfill]
+\definemathunderarrow [underleftrightarrow] [\leftrightarrowfill]
+\definemathunderarrow [undertwoheadrightarrow][\twoheadrightarrowfill]
+\definemathunderarrow [undertwoheadleftarrow] [\twoheadleftarrowfill]
+\definemathunderarrow [underrightharpoondown] [\rightharpoondownfill]
+\definemathunderarrow [underrightharpoonup] [\rightharpoonupfill]
+\definemathunderarrow [underleftharpoondown] [\leftharpoondownfill]
+\definemathunderarrow [underleftharpoonup] [\leftharpoonupfill]
+
+%D These can be used as follows:
+%D
+%D \startbuffer
+%D $\overleftarrow{A}$ $\overleftarrow{ABC}$
+%D $a_{\overleftarrow{A}}$ $b_{\overleftarrow{ABC}}$
+%D \stopbuffer
+%D \typebuffer which gives \getbuffer
+
+%D TODO: Possibly have a single arrow command define all the arrows.
+
+\protect \endinput
diff --git a/tex/context/base/math-arr.mkiv b/tex/context/base/math-arr.mkiv
new file mode 100644
index 000000000..5c6cfc294
--- /dev/null
+++ b/tex/context/base/math-arr.mkiv
@@ -0,0 +1,439 @@
+%D \module
+%D [ file=math-arr,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Arrows,
+%D author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Arrows}
+
+\unprotect
+
+%D These will be generalized! Is it still needed in \MKIV?
+
+\def\exmthfont#1{\symbolicsizedfont#1\plusone{MathExtension}}
+
+\def\domthfrac#1#2#3#4#5#6#7%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #6$}%
+ \setbox2\hbox{$#1 #7$}%
+ \dimen0\wd0
+ \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
+ \setbox4\hbox to \dimen0{\exmthfont#2#3\leaders\hbox{#4}\hss#5}%
+ \mathord{\vcenter{{\offinterlineskip
+ \hbox to \dimen0{\hss\box0\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\copy4\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\box2\hss}}}}%
+ \endgroup}
+
+\def\domthsqrt#1#2#3#4#5%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #5$}%
+ \dimen0=1.05\ht0 \advance\dimen0 1pt \ht0 \dimen0
+ \dimen0=1.05\dp0 \advance\dimen0 1pt \dp0 \dimen0
+ \dimen0\wd0
+ \setbox4\hbox to \dimen0{\exmthfont#2\leaders\hbox{#3}\hfill#4}%
+ \delimitershortfall=0pt
+ \nulldelimiterspace=0pt
+ \setbox2\hbox{$\left\delimiter"0270370 \vrule height\ht0 depth \dp0 width0pt
+ \right.$}%
+ \mathord{\vcenter{\hbox{\copy2
+ \rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}%
+ \endgroup}
+
+\def\mthfrac#1#2#3#4#5{\mathchoice
+ {\domthfrac\displaystyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\textstyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptstyle \scriptface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}}
+
+\def\mthsqrt#1#2#3{\mathchoice
+ {\domthsqrt\displaystyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\textstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptscriptstyle\textface {#1}{#2}{#3}}}
+
+% temp here
+
+%D We next define extensible arrows. Extensible arrows are arrows that
+%D change their length according to the width of the text to be placed
+%D above and below the arrow. Since we need to define a lot of arrows,
+%D we first define some helper macros. The basic idea is to measure
+%D the width of the box to be placed above and below the arrow, and
+%D make the \quotation{body} of the arrow as long as the bigger of the
+%D two widths.
+
+\def\mtharrfactor{1}
+\def\mtharrextra {0}
+
+\def\domthxarr#1#2#3#4#5% hm, looks like we do a double mathrel
+ {\begingroup
+ \def\mtharrfactor{1}%
+ \def\mtharrextra {0}%
+ \processaction[#1] % will be sped up
+ [ \v!none=>\def\mtharrfactor{0},
+ \v!small=>\def\mtharrextra{10},
+ \v!medium=>\def\mtharrextra{15},
+ \v!big=>\def\mtharrextra{20},
+ \v!normal=>,
+ \v!default=>,
+ \v!unknown=>\doifnumberelse{#1}{\def\mtharrextra{#1}}\donothing]%
+ \mathsurround\zeropoint
+ \muskip0=\thirdoffourarguments #2mu
+ \muskip2=\fourthoffourarguments #2mu
+ \muskip4=\firstoffourarguments #2mu
+ \muskip6=\secondoffourarguments #2mu
+ \muskip0=\mtharrfactor\muskip0 \advance\muskip0 \mtharrextra mu
+ \muskip2=\mtharrfactor\muskip2 \advance\muskip2 \mtharrextra mu
+ \setbox0\hbox{$\scriptstyle
+ \mkern\muskip4\relax
+ \mkern\muskip0\relax
+ #5\relax
+ \mkern\muskip2\relax
+ \mkern\muskip6\relax
+ $}%
+ \setbox4\hbox{#3\displaystyle}%
+ \dimen0\wd0
+ \ifdim\wd4>\dimen0 \dimen0\wd4 \fi
+ \setbox2\hbox{$\scriptstyle
+ \mkern\muskip4\relax
+ \mkern\muskip0\relax
+ #4\relax
+ \mkern\muskip2\relax
+ \mkern\muskip6\relax
+ $}%
+ \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
+ \setbox4\hbox to \dimen0{#3\displaystyle}%
+ \mathrel{\mathop{\hbox to \dimen0{\hss\copy4\hss}}\limits^{\box0}_{\box2}}
+ \endgroup}
+
+\let\domthxarrsingle\domthxarr
+
+%D There are some arrows which are created by stacking two arrows. The next
+%D macro helps in defining such \quotation{double arrows}.
+
+\def\domthxarrdouble#1#2#3#4#5#6#7% opt l r sp rs top bot
+ {\mathrel
+ {\scratchdimen.32ex\relax % was .22, todo: make configurable
+ \setbox0\hbox{$\domthxarr{#1}{#2}{#4}{\phantom{#6}}{#7}$}%
+ \setbox2\hbox{$\domthxarr{#1}{#3}{#5}{#6}{\phantom{#7}}$}%
+ \raise\scratchdimen\box0
+ \kern-\wd2
+ \lower\scratchdimen\box2}}
+
+%D \macros{definematharrow}
+%D
+%D Macro for defining new arrows. We can define two types of
+%D arrows|<|single arrows and double arrows. Single arrows are defined
+%D as
+%D
+%D \starttyping
+%D \definematharrow [xrightarrow] [0359] [\rightarrowfill]
+%D \stoptyping
+%D
+%D The first argument is the name of the arrow (\tex{xrightarrow} in
+%D this case.) The second argument consists of a set of 4 numbers and
+%D specify the spacing correction in math units~\type{mu}. These
+%D numbers define:
+%D
+%D \startlines
+%D 1st number: arrow||tip correction
+%D 2nd number: arrow||tip correction
+%D 3rd number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
+%D 4th number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
+%D \stoplines
+%D
+%D The third argument is the name of the extensible fill. The third
+%D argument is optional when the arrow is redefined later (this is
+%D useful for font specific tweaking of the skips.) For example,
+%D
+%D \startbuffer
+%D \math{\xrightarrow{above}}
+%D \definematharrow[xrightarrow][0000]
+%D \math{\xrightarrow{above}}
+%D \definematharrow[xrightarrow][55{50}{50}]
+%D \math{\xrightarrow{above}}
+%D \stopbuffer
+%D \typebuffer gives {\getbuffer}
+%D
+%D The double arrows are defined as follows
+%D
+%D \starttyping
+%D \definematharrow [xrightleftharpoons] [3095,0359]
+%D [\rightharpoonupfill,\leftharpoondownfill]
+%D \stoptyping
+%D
+%D The second and the third set of arguments consist of comma
+%D separated values. The first element of the second argument
+%D (\type{3095}) corresponds to the spacing correction of top arrow
+%D fill (\tex{rightarrowupfill}). Similarly, \type{0359} corresponds
+%D to bottom arrow fill \tex{leftharpoondownfill}). Stacking them on
+%D top of each other we get $\xrightleftharpoons[big]{above}{below}$.
+%D The following math arrows are defined
+%D
+%D \placetable[none]{}{\starttable[|l|m|]
+%D \NC \tex{xrightarrow } \NC \xrightarrow [big] \NC \NR
+%D \NC \tex{xleftarrow } \NC \xleftarrow [big] \NC \NR
+%D \NC \tex{xequal } \NC \xequal [big] \NC \NR
+%D \NC \tex{xRightarrow } \NC \xRightarrow [big] \NC \NR
+%D \NC \tex{xLeftarrow } \NC \xLeftarrow [big] \NC \NR
+%D \NC \tex{xLeftrightarrow } \NC \xLeftrightarrow [big] \NC \NR
+%D \NC \tex{xleftrightarrow } \NC \xleftrightarrow [big] \NC \NR
+%D \NC \tex{xmapsto } \NC \xmapsto [big] \NC \NR
+%D \NC \tex{xtwoheadrightarrow } \NC \xtwoheadrightarrow [big] \NC \NR
+%D \NC \tex{xtwoheadleftarrow } \NC \xtwoheadleftarrow [big] \NC \NR
+%D \NC \tex{xrightharpoondown } \NC \xrightharpoondown [big] \NC \NR
+%D \NC \tex{xrightharpoonup } \NC \xrightharpoonup [big] \NC \NR
+%D \NC \tex{xleftharpoondown } \NC \xleftharpoondown [big] \NC \NR
+%D \NC \tex{xleftharpoonup } \NC \xleftharpoonup [big] \NC \NR
+%D \NC \tex{xhookleftarrow } \NC \xhookleftarrow [big] \NC \NR
+%D \NC \tex{xhookrightarrow } \NC \xhookrightarrow [big] \NC \NR
+%D \NC \tex{xleftrightharpoons } \NC \xleftrightharpoons [big] \NC \NR
+%D \NC \tex{xrightleftharpoons } \NC \xrightleftharpoons [big] \NC \NR
+%D \stoptable}
+
+\def\definematharrow
+ {\doquadrupleargument\dodefinematharrow}
+
+\def\dodefinematharrow[#1][#2][#3][#4]% name type[none|both] template command
+ {\iffourthargument
+ \executeifdefined{dodefine#2arrow}\gobblethreearguments{#1}{#3}{#4}%
+ \else\ifthirdargument
+ \dodefinebotharrow{#1}{#2}{#3}%
+ \else\ifsecondargument
+ \redefinebotharrow{#1}{#2}{#3}%
+ \fi\fi\fi}
+
+\def\redefinebotharrow#1#2#3% real dirty, this overload!
+ {\doifdefined{#1}
+ {\pushmacro\dohandlemtharrow
+ \def\dohandlemtharrow[##1][##2]{\setvalue{#1}{\dohandlemtharrow[#2][##2]}}%
+ % == \def\dohandlemtharrow[##1][##2]{\dodefinebotharrow{#1}{#2}{##2}}%
+ \getvalue{#1}%
+ \popmacro\dohandlemtharrow}}
+
+\def\dodefinebotharrow#1#2#3%
+ {\setvalue{#1}{\dohandlemtharrow[#2][#3]}}
+
+\def\dohandlemtharrow
+ {\dotripleempty\doxmtharrow}
+
+\def\doxmtharrow[#1][#2][#3]% #3 == optional arg
+ {\def\dodoxmtharrow{\dododoxmtharrow[#1,\empty,\empty][#2,\empty,\empty][#3]}% {##1}{##2}
+ \dodoublegroupempty\dodoxmtharrow}
+
+\def\dododoxmtharrow[#1,#2,#3][#4,#5,#6][#7]#8#9% [3] is the optional arg
+ {\edef\!!stringa{#2}%
+ \ifx\!!stringa\empty
+ \ifsecondargument
+ \mathrel{\domthxarrsingle{#7}{#1}{#4}{#8}{#9}}%
+ \else
+ \mathrel{\domthxarrsingle{#7}{#1}{#4}{}{#8}}%
+ \fi
+ \else
+ \ifsecondargument
+ \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{#8}{#9}}%
+ \else
+ \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{}{#8}}%
+ \fi
+ \fi}
+
+% Adapted from amsmath.
+
+%D \macros{mtharrowfill,defaultmtharrowfill}
+%D
+%D To extend the arrows we need to define a \quotation{math arrow
+%D fill}. This command takes 8 arguments: the first four correspond
+%D the second argument of \tex{definematharrow} explained above. The
+%D other three specify the tail, body and head of the arrow. The last
+%D argument specifies the math-mode in which the arrow is drawn.
+%D \tex{defaultmtharrowfill} has values tweaked to match Latin Modern
+%D fonts. For fonts that are significantly different (e.g. cows) a
+%D different set of values need to be determined.
+
+\def\mtharrowfill#1#2#3#4#5#6#7#8%
+ {$\mathsurround 0pt
+ \thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip
+ \relax#8#5%
+ \mkern-#1mu
+ \cleaders\hbox{$#8\mkern -#2mu#6\mkern -#3mu$}\hfill
+ \mkern-#4mu#7$}
+
+\def\defaultmtharrowfill{\mtharrowfill 7227}
+
+%D We now define some arrow fills that will be used for defining the
+%D arrows. Plain \TEX\ already defines \tex{leftarrowfill} and
+%D \tex{rightarrowfill}. The \tex{defaultmtharrowfill} command defines an
+%D arrowfill that takes an argument (so that it can also be used
+%D with over and under arrows). However the Plain \TEX\ definitions of
+%D \tex{leftarrowfill} and \tex{rightarrowfill} do not take this extra
+%D argument. To be backward compatible with Plain \TEX, we define two
+%D arrowfills: \tex{specrightarrowfill} which takes an extra argument, and
+%D \tex{rightarrowfill} which does not.
+
+\def\specrightarrowfill {\defaultmtharrowfill \relbar \relbar \rightarrow}
+\def\specleftarrowfill {\defaultmtharrowfill \leftarrow \relbar \relbar}
+
+\def\rightarrowfill {\specrightarrowfill \textstyle}
+\def\leftarrowfill {\specleftarrowfill \textstyle}
+
+\def\equalfill {\defaultmtharrowfill \Relbar \Relbar \Relbar}
+\def\Rightarrowfill {\defaultmtharrowfill \Relbar \Relbar \Rightarrow}
+\def\Leftarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Relbar}
+\def\Leftrightarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Rightarrow}
+\def\leftrightarrowfill {\defaultmtharrowfill \leftarrow \relbar \rightarrow}
+\def\mapstofill {\defaultmtharrowfill{\mapstochar\relbar} \relbar \rightarrow}
+\def\twoheadrightarrowfill{\defaultmtharrowfill \relbar \relbar \twoheadrightarrow}
+\def\twoheadleftarrowfill {\defaultmtharrowfill \twoheadleftarrow \relbar \relbar}
+\def\rightharpoondownfill {\defaultmtharrowfill \relbar \relbar \rightharpoondown}
+\def\rightharpoonupfill {\defaultmtharrowfill \relbar \relbar \rightharpoonup}
+\def\leftharpoondownfill {\defaultmtharrowfill \leftharpoondown \relbar \relbar}
+\def\leftharpoonupfill {\defaultmtharrowfill \leftharpoonup \relbar \relbar}
+\def\hookleftfill {\defaultmtharrowfill \leftarrow \relbar{\relbar\joinrel\rhook}}
+\def\hookrightfill {\defaultmtharrowfill{\lhook\joinrel\relbar}\relbar \rightarrow}
+\def\relfill {\defaultmtharrowfill \relbar \relbar \relbar}
+
+\def\triplerelbar {\mathrel\equiv}
+\def\triplerelfill{\defaultmtharrowfill\triplerelbar\triplerelbar\triplerelbar}
+
+\def\singlebond{{\xrel}} % or \def\singlebond{{\xrel[2]}}
+\def\doublebond{{\xequal}}
+\def\triplebond{{\xtriplerel}}
+
+%D Now we define most commonly used arrows. These include arrows
+%D defined in \filename{amsmath.sty}, \filename{extarrows.sty},
+%D \filename{extpfel.sty} and \filename{mathtools.sty} packages for
+%D \LATEX\ (plus a few more).
+
+\definematharrow [xrightarrow] [0359] [\specrightarrowfill]
+\definematharrow [xleftarrow] [3095] [\specleftarrowfill]
+\definematharrow [xequal] [0099] [\equalfill]
+\definematharrow [xRightarrow] [0359] [\Rightarrowfill]
+\definematharrow [xLeftarrow] [3095] [\Leftarrowfill]
+\definematharrow [xLeftrightarrow] [0099] [\Leftrightarrowfill]
+\definematharrow [xleftrightarrow] [0099] [\leftrightarrowfill]
+\definematharrow [xmapsto] [3599] [\mapstofill]
+\definematharrow [xtwoheadrightarrow] [5009] [\twoheadrightarrowfill]
+\definematharrow [xtwoheadleftarrow] [0590] [\twoheadleftarrowfill]
+\definematharrow [xrightharpoondown] [0359] [\rightharpoondownfill]
+\definematharrow [xrightharpoonup] [0359] [\rightharpoonupfill]
+\definematharrow [xleftharpoondown] [3095] [\leftharpoondownfill]
+\definematharrow [xleftharpoonup] [3095] [\leftharpoonupfill]
+\definematharrow [xhookleftarrow] [3095] [\hookleftfill]
+\definematharrow [xhookrightarrow] [0395] [\hookrightfill]
+\definematharrow [xrel] [0099] [\relfill]
+\definematharrow [xtriplerel] [0099] [\triplerelfill]
+\definematharrow [xrightoverleftarrow] [0359,3095] [\specrightarrowfill,\specleftarrowfill]
+\definematharrow [xleftrightharpoons] [3399,3399] [\leftharpoonupfill,\rightharpoondownfill]
+\definematharrow [xrightleftharpoons] [3399,3399] [\rightharpoonupfill,\leftharpoondownfill]
+
+%D These arrows can be used as follows:
+%D
+%D \startbuffer
+%D \startformula \xrightarrow{stuff on top}\stopformula
+%D \startformula \xrightarrow{}{stuff on top}\stopformula
+%D \startformula \xrightarrow{stuff below}{}\stopformula
+%D \startformula \xrightarrow{stuff below}{stuff on top}\stopformula
+%D
+%D \startformula \xleftarrow [none]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [small]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [medium]{stuff below}{stuff on top}\stopformula
+%D \startformula \xleftarrow [big]{stuff below}{stuff on top}\stopformula
+%D \stopbuffer
+%D
+%D \typebuffer which gives \getbuffer
+
+%D \macros{definemathoverarrow,defineunderarrow}
+%D
+%D These macros for define math-overarrows are adapted from
+%D \filename{amsmath.sty}
+
+\def\definemathoverarrow
+ {\dotripleargument\dodefinemathoverarrow}
+
+\def\dodefinemathoverarrow[#1][#2][#3]%
+ {\ifthirdargument
+ \setvalue{#1}{\dohandlemathoverarrow[#2][#3]}%
+ \else
+ \setvalue{#1}{\dohandlemathoverarrow[\zeropoint][#2]}%
+ \fi}
+
+\def\dohandlemathoverarrow[#1][#2]%
+ {\mathpalette{\dodohandlemathoverarrow{#1}{#2}}}
+
+%D Note: \filename{math-pln.tex} has \type{\kern-\onepoint} and
+%D \filename{amsmath.sty} does not. We keep the kern amount
+%D configurable. This is useful for harpoons.
+
+\def\dodohandlemathoverarrow#1#2#3#4%
+ {\vbox{\ialign{##\crcr
+ #2#3\crcr
+ \noalign{\kern#1\nointerlineskip}%
+ $\mathsurround\zeropoint\hfil#3#4\hfil$\crcr}}}
+
+%D Now the under arrows
+
+\def\definemathunderarrow
+ {\dotripleargument\dodefinemathunderarrow}
+
+%D For underarrows the default kern is 0.3ex
+
+\def\dodefinemathunderarrow[#1][#2][#3]%
+ {\ifthirdargument
+ \setvalue{#1}{\dohandlemathunderarrow[#2][#3]}%
+ \else
+ \setvalue{#1}{\dohandlemathunderarrow[0.3ex][#2]}%
+ \fi}
+
+\def\dohandlemathunderarrow[#1][#2]%
+ {\mathpalette{\dodohandlemathunderarrow{#1}{#2}}}
+
+\def\dodohandlemathunderarrow#1#2#3#4%
+ {\vtop{\ialign{##\crcr
+ $\mathsurround\zeropoint\hfil#3#4\hfil$\crcr
+ \noalign{\nointerlineskip\kern#1}%
+ #2#3\crcr}}}
+
+%D Now we define the arrows
+
+\definemathoverarrow [overleftarrow] [\specleftarrowfill]
+\definemathoverarrow [overrightarrow] [\specrightarrowfill]
+\definemathoverarrow [overleftrightarrow] [\leftrightarrowfill]
+\definemathoverarrow [overtwoheadrightarrow] [\twoheadrightarrowfill]
+\definemathoverarrow [overtwoheadleftarrow] [\twoheadleftarrowfill]
+\definemathoverarrow [overrightharpoondown] [1pt] [\rightharpoondownfill]
+\definemathoverarrow [overrightharpoonup] [\rightharpoonupfill]
+\definemathoverarrow [overleftharpoondown] [1pt] [\leftharpoondownfill]
+\definemathoverarrow [overleftharpoonup] [\leftharpoonupfill]
+
+\definemathunderarrow [underleftarrow] [\specleftarrowfill]
+\definemathunderarrow [underrightarrow] [\specrightarrowfill]
+\definemathunderarrow [underleftrightarrow] [\leftrightarrowfill]
+\definemathunderarrow [undertwoheadrightarrow][\twoheadrightarrowfill]
+\definemathunderarrow [undertwoheadleftarrow] [\twoheadleftarrowfill]
+\definemathunderarrow [underrightharpoondown] [\rightharpoondownfill]
+\definemathunderarrow [underrightharpoonup] [\rightharpoonupfill]
+\definemathunderarrow [underleftharpoondown] [\leftharpoondownfill]
+\definemathunderarrow [underleftharpoonup] [\leftharpoonupfill]
+
+%D These can be used as follows:
+%D
+%D \startbuffer
+%D $\overleftarrow{A}$ $\overleftarrow{ABC}$
+%D $a_{\overleftarrow{A}}$ $b_{\overleftarrow{ABC}}$
+%D \stopbuffer
+%D \typebuffer which gives \getbuffer
+
+%D TODO: Possibly have a single arrow command define all the arrows.
+
+\protect \endinput
diff --git a/tex/context/base/math-def.mkiv b/tex/context/base/math-def.mkiv
new file mode 100644
index 000000000..9e6ad28c1
--- /dev/null
+++ b/tex/context/base/math-def.mkiv
@@ -0,0 +1,338 @@
+%D \module
+%D [ file=math-tex,
+%D version=2001.04.12,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Definitions,
+%D author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Definitions}
+
+\unprotect
+
+\ifx\mrfam\undefined \chardef\mrfam\plusone \fi
+
+\startluacode
+ mathematics.define()
+ mathematics.register_xml_entities()
+\stopluacode
+
+% special .. todo
+
+\mathcode`\ ="8000 \mathcode`\_="8000 \mathcode`\'="8000
+
+% will be attributes
+
+\setfalse \automathpunctuation
+
+\def\enablemathpunctuation {\settrue \automathpunctuation}
+\def\disablemathpunctuation{\setfalse\automathpunctuation}
+
+\def\v!autopunctuation{autopunctuation}
+
+\appendtoks
+ \doifelse{\mathematicsparameter\v!autopunctuation}\v!yes\enablemathpunctuation\disablemathpunctuation
+\to \everysetupmathematics
+
+\appendtoks
+ \ifconditional\automathpunctuation\dosetattribute{mathpunc}\plusone\fi
+\to \everymathematics
+
+\setupmathematics[\v!autopunctuation=\v!yes]
+
+% will go to math-ext
+
+\Umathchardef\braceld=0 \mrfam "FF07A
+\Umathchardef\bracerd=0 \mrfam "FF07B
+\Umathchardef\bracelu=0 \mrfam "FF07C
+\Umathchardef\braceru=0 \mrfam "FF07D
+
+% ctx specific
+
+\def\|{|} % still letter
+
+% The \mfunction macro is an alternative for \hbox with a
+% controlable font switch.
+
+\definemathcommand [arccos] [nolop] {\mfunction{arccos}}
+\definemathcommand [arcsin] [nolop] {\mfunction{arcsin}}
+\definemathcommand [arctan] [nolop] {\mfunction{arctan}}
+\definemathcommand [arg] [nolop] {\mfunction{arg}}
+\definemathcommand [cosh] [nolop] {\mfunction{cosh}}
+\definemathcommand [cos] [nolop] {\mfunction{cos}}
+\definemathcommand [coth] [nolop] {\mfunction{coth}}
+\definemathcommand [cot] [nolop] {\mfunction{cot}}
+\definemathcommand [csc] [nolop] {\mfunction{csc}}
+\definemathcommand [deg] [nolop] {\mfunction{deg}}
+\definemathcommand [det] [limop] {\mfunction{det}}
+\definemathcommand [dim] [nolop] {\mfunction{dim}}
+\definemathcommand [exp] [nolop] {\mfunction{exp}}
+\definemathcommand [gcd] [limop] {\mfunction{gcd}}
+\definemathcommand [hom] [nolop] {\mfunction{hom}}
+\definemathcommand [inf] [limop] {\mfunction{inf}}
+\definemathcommand [injlim] [limop] {\mfunction{inj\,lim}}
+\definemathcommand [ker] [nolop] {\mfunction{ker}}
+\definemathcommand [lg] [nolop] {\mfunction{lg}}
+\definemathcommand [liminf] [limop] {\mfunction{lim\,inf}}
+\definemathcommand [limsup] [limop] {\mfunction{lim\,sup}}
+\definemathcommand [lim] [limop] {\mfunction{lim}}
+\definemathcommand [ln] [nolop] {\mfunction{ln}}
+\definemathcommand [log] [nolop] {\mfunction{log}}
+\definemathcommand [median] [limop] {\mfunction{median}}
+\definemathcommand [max] [limop] {\mfunction{max}}
+\definemathcommand [min] [limop] {\mfunction{min}}
+\definemathcommand [mod] [limop] {\mfunction{mod}}
+\definemathcommand [div] [limop] {\mfunction{div}}
+\definemathcommand [projlim] [limop] {\mfunction{proj\,lim}}
+\definemathcommand [Pr] [limop] {\mfunction{Pr}}
+\definemathcommand [sec] [nolop] {\mfunction{sec}}
+\definemathcommand [sinh] [nolop] {\mfunction{sinh}}
+\definemathcommand [sin] [nolop] {\mfunction{sin}}
+\definemathcommand [sup] [limop] {\mfunction{sup}}
+\definemathcommand [tanh] [nolop] {\mfunction{tanh}}
+\definemathcommand [tan] [nolop] {\mfunction{tan}}
+
+\definemathcommand [integers] {{\mathblackboard Z}}
+\definemathcommand [reals] {{\mathblackboard R}}
+\definemathcommand [rationals] {{\mathblackboard Q}}
+\definemathcommand [naturalnumbers]{{\mathblackboard N}}
+\definemathcommand [complexes] {{\mathblackboard C}}
+\definemathcommand [primes] {{\mathblackboard P}}
+
+% using attributes
+
+\def\choosemathbig#1#2{\dosetattribute{mathsize}{#1}\left#2\right.\doresetattribute{mathsize}}
+
+\definemathcommand [big] {\choosemathbig\plusone }
+\definemathcommand [Big] {\choosemathbig\plustwo }
+\definemathcommand [bigg] {\choosemathbig\plusthree}
+\definemathcommand [Bigg] {\choosemathbig\plusfour }
+
+\definemathcommand [bigl] [open] [one] {\big}
+\definemathcommand [bigm] [rel] [one] {\big}
+\definemathcommand [bigr] [close] [one] {\big}
+\definemathcommand [Bigl] [open] [one] {\Big}
+\definemathcommand [Bigm] [rel] [one] {\Big}
+\definemathcommand [Bigr] [close] [one] {\Big}
+\definemathcommand [biggl] [open] [one] {\bigg}
+\definemathcommand [biggm] [rel] [one] {\bigg}
+\definemathcommand [biggr] [close] [one] {\bigg}
+\definemathcommand [Biggl] [open] [one] {\Bigg}
+\definemathcommand [Biggm] [rel] [one] {\Bigg}
+\definemathcommand [Biggr] [close] [one] {\Bigg}
+
+% special
+
+%AM: Optimize this! Add similar options for sums.
+
+\def\setoperatorlimits#1#2% operator limits
+ {\savenormalmeaning{#1}%
+ \def#1{\getvalue{normal\strippedcsname#1}#2}}
+
+\setoperatorlimits\int \intlimits
+\setoperatorlimits\iint \intlimits
+\setoperatorlimits\iiint \intlimits
+\setoperatorlimits\oint \intlimits
+\setoperatorlimits\oiint \intlimits
+\setoperatorlimits\oiiint \intlimits
+\setoperatorlimits\intclockwise \intlimits
+\setoperatorlimits\ointclockwise \intlimits
+\setoperatorlimits\ointctrclockwise \intlimits
+
+%D This is a temporary hack until we figure out how to do this correctly.
+
+\unexpanded\def\implies {\mathrel{\;\Longrightarrow\;}}
+\unexpanded\def\impliedby{\mathrel{\;\Longleftarrow\;}}
+\unexpanded\def\And {\mathrel{\;\internalAnd\;}}
+\unexpanded\def\iff {\;\Longleftrightarrow\;}
+
+% todo: virtual in math-vfu
+
+% \definemathcommand [mapsto] {\mapstochar\rightarrow}
+% \definemathcommand [hookrightarrow] {\lhook\joinrel\rightarrow}
+% \definemathcommand [hookleftarrow] {\leftarrow\joinrel\rhook}
+% \definemathcommand [bowtie] {\mathrel\triangleright\joinrel\mathrel\triangleleft}
+% \definemathcommand [models] {\mathrel|\joinrel=}
+% \definemathcommand [iff] {\;\Longleftrightarrow\;}
+
+% hm
+
+% ldots = 2026
+% vdots = 22EE
+% cdots = 22EF
+% ddots = 22F1
+% udots = 22F0
+
+% \def\PLAINldots{\ldotp\ldotp\ldotp}
+% \def\PLAINcdots{\cdotp\cdotp\cdotp}
+
+% \def\PLAINvdots
+% {\vbox{\baselineskip.4\bodyfontsize\lineskiplimit\zeropoint\kern.6\bodyfontsize\hbox{.}\hbox{.}\hbox{.}}}
+
+% \def\PLAINddots
+% {\mkern1mu%
+% \raise.7\bodyfontsize\vbox{\kern.7\bodyfontsize\hbox{.}}%
+% \mkern2mu%
+% \raise.4\bodyfontsize\relax\hbox{.}%
+% \mkern2mu%
+% \raise.1\bodyfontsize\hbox{.}%
+% \mkern1mu}
+
+% \definemathcommand [ldots] [inner] {\PLAINldots}
+% \definemathcommand [cdots] [inner] {\PLAINcdots}
+% \definemathcommand [vdots] [nothing] {\PLAINvdots}
+% \definemathcommand [ddots] [inner] {\PLAINddots}
+
+%D \starttyping
+%D $\sqrt[3]{10}$
+%D \stoptyping
+
+\def\rootradical{\Uroot 0 "221A } % can be done in char-def
+
+\def\root#1\of{\rootradical{#1}} % #2
+
+\unexpanded\def\sqrt{\doifnextoptionalelse\rootwithdegree\rootwithoutdegree}
+
+\def\rootwithdegree [#1]{\rootradical{#1}}
+\def\rootwithoutdegree {\rootradical {}}
+
+\def\PLAINmatrix#1%
+ {\null\,\vcenter{\normalbaselines\mathsurround\zeropoint
+ \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
+ \mathstrut\crcr\noalign{\kern-\baselineskip}
+ #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
+
+\definemathcommand [mathstrut] {\vphantom{(}}
+\definemathcommand [joinrel] {\mathrel{\mkern-3mu}}
+
+% \definemathcommand [matrix] {\PLAINmatrix}
+% \definemathcommand [over] {\normalover} % hack, to do
+
+\unexpanded\def\{{\mathortext\lbrace\letterleftbrace }
+\unexpanded\def\}{\mathortext\rbrace\letterrightbrace}
+
+%D The following colon related definitions are provided by Aditya
+%D Mahajan who derived them from \type {mathtools.sty} and \type
+%D {colonequals.sty}.
+
+%D \macros
+%D {centercolon, colonminus, minuscolon, colonequals, equalscolon,
+%D colonapprox, approxcolon, colonsim, simcolon, coloncolon,
+%D coloncolonminus, minuscoloncolon, coloncolonequals,
+%D equalscoloncolon, coloncolonapprox, approxcoloncolon,
+%D colonsim, simcoloncolon}
+%D
+%D In $a := b$ the colon is not vertically centered with the equal
+%D to. Also the distance between colon and equal to is a bit large.
+%D So, we define a vertically centered colon \tex {centercolon} and
+%D a few macros for colon and double colon relation symbols.
+%D
+%D \startlines
+%D \formula {A \centercolon B}
+%D \formula {A \colonminus B}
+%D \formula {A \minuscolon B}
+%D \formula {A \colonequals B}
+%D \formula {A \equalscolon B}
+%D \formula {A \colonapprox B}
+%D \formula {A \approxcolon B}
+%D \formula {A \colonsim B}
+%D \formula {A \simcolon B}
+%D \formula {A \coloncolon B}
+%D \formula {A \coloncolonminus B}
+%D \formula {A \minuscoloncolon B}
+%D \formula {A \coloncolonequals B}
+%D \formula {A \equalscoloncolon B}
+%D \formula {A \coloncolonapprox B}
+%D \formula {A \approxcoloncolon B}
+%D \formula {A \colonsim B}
+%D \formula {A \simcoloncolon B}
+%D \stoplines
+
+%D The next macros take care of the space between the colon and the
+%D relation symbol.
+
+\definemathcommand [colonsep] {\mkern-1.2mu}
+\definemathcommand [doublecolonsep] {\mkern-0.9mu}
+
+%D The next macro vertically centeres its contents.
+
+\def\@center@math#1%
+ {\vcenter{\hbox{$\mathsurround\zeropoint#1$}}}
+
+\def\@center@colon
+ {\mathpalette\@center@math{\colon}}
+
+%D Now we define all the colon relations.
+
+\definemathcommand [centercolon] [rel] {\@center@colon}
+\definemathcommand [colonminus] [rel] {\centercolon\colonsep\mathrel{-}}
+\definemathcommand [minuscolon] [rel] {\mathrel{-}\colonsep\centercolon}
+\definemathcommand [colonequals] [rel] {\centercolon\colonsep=}
+\definemathcommand [equalscolon] [rel] {=\centercolon\colonsep}
+\definemathcommand [colonapprox] [rel] {\centercolon\colonsep\approx}
+\definemathcommand [approxcolon] [rel] {\approx\centercolon\colonsep}
+\definemathcommand [colonsim] [rel] {\centercolon\colonsep\sim}
+\definemathcommand [simcolon] [rel] {\sim\centercolon\colonsep}
+
+\definemathcommand [coloncolon] [rel] {\centercolon\doublecolonsep\centercolon}
+\definemathcommand [coloncolonminus] [rel] {\coloncolon\colonsep\mathrel{-}}
+\definemathcommand [minuscoloncolon] [rel] {\mathrel{-}\colonsep\coloncolon}
+\definemathcommand [coloncolonequals] [rel] {\coloncolon\colonsep=}
+\definemathcommand [equalscoloncolon] [rel] {=\coloncolon\colonsep}
+\definemathcommand [coloncolonapprox] [rel] {\coloncolon\colonsep\approx}
+\definemathcommand [approxcoloncolon] [rel] {\approx\coloncolon\colonsep}
+\definemathcommand [colonsim] [rel] {\coloncolon\colonsep\sim}
+\definemathcommand [simcoloncolon] [rel] {\sim\coloncolon\colonsep}
+
+%D Goodies. We might move this elsewhere.
+
+\def\underleftarrow #1{\mathop{\Uunderdelimiter 0 "2190 {#1}}}
+\def\overleftarrow #1{\mathop{\Uoverdelimiter 0 "2190 {#1}}}
+\def\underrightarrow#1{\mathop{\Uunderdelimiter 0 "2192 {#1}}}
+\def\overrightarrow #1{\mathop{\Uoverdelimiter 0 "2192 {#1}}}
+
+% todo: \Udelimiterover, \Udelimiterunder
+
+\def\normaldoublebrace {\Umathaccents 0 0 "23DE 0 0 "23DF }
+\def\normaldoubleparent{\Umathaccents 0 0 "23DC 0 0 "23DD }
+
+\let\normaloverbrace \overbrace
+\let\normalunderbrace \underbrace
+\let\normaloverparent \overparent
+\let\normalunderparent \underparent
+\let\normalunderleftarrow \underleftarrow
+\let\normaloverleftarrow \overleftarrow
+\let\normalunderrightarrow\underrightarrow
+\let\normaloverrightarrow \overrightarrow
+
+\unexpanded\def\mathopwithlimits#1#2{\mathop{#1{#2}}\limits}
+\unexpanded\def\stackrel #1#2{\mathrel{\mathop{#2}\limits^{#1}}}
+
+\unexpanded\def\overbrace {\mathopwithlimits\normaloverbrace }
+\unexpanded\def\underbrace {\mathopwithlimits\normalunderbrace }
+\unexpanded\def\doublebrace {\mathopwithlimits\normaldoublebrace }
+\unexpanded\def\overparent {\mathopwithlimits\normaloverparent }
+\unexpanded\def\underparent {\mathopwithlimits\normalunderparent }
+\unexpanded\def\doubleparent {\mathopwithlimits\normaldoubleparent }
+\unexpanded\def\underleftarrow {\mathopwithlimits\normalunderleftarrow }
+\unexpanded\def\overleftarrow {\mathopwithlimits\normaloverleftarrow }
+\unexpanded\def\underrightarrow{\mathopwithlimits\normalunderrightarrow}
+\unexpanded\def\overrightarrow {\mathopwithlimits\normaloverrightarrow }
+
+% todo mathclass=punctuation ord
+
+% \Umathcode"02C="6 "0 "02C
+% \Umathcode"02E="0 "0 "02E
+
+% tricky .. todo
+
+\appendtoks
+ \def\over{\primitive\over}%
+\to \everymathematics
+
+\protect \endinput
diff --git a/tex/context/base/math-del.mkiv b/tex/context/base/math-del.mkiv
new file mode 100644
index 000000000..5ffda1919
--- /dev/null
+++ b/tex/context/base/math-del.mkiv
@@ -0,0 +1,63 @@
+%D \module
+%D [ file=math-del,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Delimiters,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Delimiters}
+
+\unprotect
+
+%D \macros
+%D {checkdelimiters, fakeleftdelimiter, fakerightdelimiter}
+%D
+%D Handy for non matching situations (as with mathml):
+%D
+%D \starttyping
+%D \checkdelimiters{... bla bla ...}
+%D \fakeleftdelimiter
+%D ... bla bla ...
+%D \fakerightdelimiter
+%D \stoptyping
+
+\newcount\delimitercount
+
+\def\leftfakedelimiter {\advance\delimitercount\minusone\gobbleoneargument}%
+\def\rightfakedelimiter{\advance\delimitercount\plusone \gobbleoneargument}%
+
+\def\checkdelimiters#1%
+ {\delimitercount\zerocount
+ \setbox\scratchbox\hbox\bgroup
+ \let\left \leftfakedelimiter
+ \let\right\rightfakedelimiter
+ $#1\expandafter$\expandafter
+ \egroup
+ \expandafter\delimitercount\the\delimitercount\relax}
+
+\def\fakeleftdelimiter {\ifnum\delimitercount>\zerocount\left .\fi}
+\def\fakerightdelimiter{\ifnum\delimitercount<\zerocount\right.\fi}
+
+%D The following macros are used in the MathML interpreter, so
+%D there is a good change of them never being documented for
+%D other usage.
+
+\let\normalordelimiter\secondoftwoarguments
+\let\normalorfiller \firstoftwoarguments
+
+\def\enabledelimiter {\let\normalordelimiter\secondoftwoarguments}
+\def\disabledelimiter{\let\normalordelimiter\firstoftwoarguments}
+
+\def\enablefiller {\let\normalorfiller\secondoftwoarguments}
+\def\disablefiller {\let\normalorfiller\firstoftwoarguments}
+
+\def\mathopnolimits#1{\mathop{\mr#1}\nolimits} % was \rm, which follows text fonts (used in mml parser)
+\def\mathopdolimits#1{\mathop{\mr#1}} % was \rm, which follows text fonts (used in mml parser)
+
+\protect \endinput
diff --git a/tex/context/base/math-dim.lua b/tex/context/base/math-dim.lua
new file mode 100644
index 000000000..a536f0309
--- /dev/null
+++ b/tex/context/base/math-dim.lua
@@ -0,0 +1,310 @@
+if not modules then modules = { } end modules ['math-dim'] = {
+ version = 1.001,
+ comment = "companion to math-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- Beware: only Taco really understands in depth what these dimensions do so
+-- if you run into problems ...
+
+local abs, next = math.abs, next
+
+mathematics = mathematics or { }
+
+local defaults = {
+ ['axis']={
+ ['default']={ "AxisHeight", "axis_height" },
+ },
+ ['accent_base_height']={
+ ['default']={ "AccentBaseHeight", "x_height" },
+ },
+ ['fraction_del_size']={
+ ['default']={ "0", "delim2" },
+ ['cramped_display_style']={ "0", "delim1" },
+ ['display_style']={ "0", "delim1" },
+ },
+ ['fraction_denom_down']={
+ ['default']={ "FractionDenominatorShiftDown", "denom2" },
+ ['cramped_display_style']={ "FractionDenominatorDisplayStyleShiftDown", "denom1" },
+ ['display_style']={ "FractionDenominatorDisplayStyleShiftDown", "denom1" },
+ },
+ ['fraction_denom_vgap']={
+ ['default']={ "FractionDenominatorGapMin", "default_rule_thickness" },
+ ['cramped_display_style']={ "FractionDenominatorDisplayStyleGapMin", "3*default_rule_thickness" },
+ ['display_style']={ "FractionDenominatorDisplayStyleGapMin", "3*default_rule_thickness" },
+ },
+ ['fraction_num_up']={
+ ['default']={ "FractionNumeratorShiftUp", "num2" },
+ ['cramped_display_style']={ "FractionNumeratorDisplayStyleShiftUp", "num1" },
+ ['display_style']={ "FractionNumeratorDisplayStyleShiftUp", "num1" },
+ },
+ ['fraction_num_vgap']={
+ ['default']={ "FractionNumeratorGapMin", "default_rule_thickness" },
+ ['cramped_display_style']={ "FractionNumeratorDisplayStyleGapMin", "3*default_rule_thickness" },
+ ['display_style']={ "FractionNumeratorDisplayStyleGapMin", "3*default_rule_thickness" },
+ },
+ ['fraction_rule']={
+ ['default']={ "FractionRuleThickness", "default_rule_thickness" },
+ },
+ ['limit_above_bgap']={
+ ['default']={ "UpperLimitBaselineRiseMin", "big_op_spacing3" },
+ },
+ ['limit_above_kern']={
+ ['default']={ "0", "big_op_spacing5" },
+ },
+ ['limit_above_vgap']={
+ ['default']={ "UpperLimitGapMin", "big_op_spacing1" },
+ },
+ ['limit_below_bgap']={
+ ['default']={ "LowerLimitBaselineDropMin", "big_op_spacing4" },
+ },
+ ['limit_below_kern']={
+ ['default']={ "0", "big_op_spacing5" },
+ },
+ ['limit_below_vgap']={
+ ['default']={ "LowerLimitGapMin", "big_op_spacing2" },
+ },
+
+--~ ['....']={
+--~ ['default']={ "DisplayOperatorMinHeight", "....." },
+--~ },
+
+ ['overbar_kern']={
+ ['default']={ "OverbarExtraAscender", "default_rule_thickness" },
+ },
+ ['overbar_rule']={
+ ['default']={ "OverbarRuleThickness", "default_rule_thickness" },
+ },
+ ['overbar_vgap']={
+ ['default']={ "OverbarVerticalGap", "3*default_rule_thickness" },
+ },
+ ['quad']={
+ ['default']={ "font_size(f)", "math_quad" },
+ },
+ ['radical_kern']={
+ ['default']={ "RadicalExtraAscender", "default_rule_thickness" },
+ },
+ ['radical_rule']={
+ ['default']={ "RadicalRuleThickness", "" },
+ },
+ ['radical_vgap']={
+ ['default']={ "RadicalVerticalGap", "default_rule_thickness+(abs(default_rule_thickness)/4)" },
+ ['display_style']={ "RadicalDisplayStyleVerticalGap", "default_rule_thickness+(abs(math_x_height)/4)" },
+ },
+ ['space_after_script']={
+ ['default']={ "SpaceAfterScript", "script_space" },
+ },
+ ['stack_denom_down']={
+ ['default']={ "StackBottomShiftDown", "denom2" },
+ ['cramped_display_style']={ "StackBottomDisplayStyleShiftDown", "denom1" },
+ ['display_style']={ "StackBottomDisplayStyleShiftDown", "denom1" },
+ },
+ ['stack_num_up']={
+ ['default']={ "StackTopShiftUp", "num3" },
+ ['cramped_display_style']={ "StackTopDisplayStyleShiftUp", "num1" },
+ ['display_style']={ "StackTopDisplayStyleShiftUp", "num1" },
+ },
+ ['stack_vgap']={
+ ['default']={ "StackGapMin", "3*default_rule_thickness" },
+ ['cramped_display_style']={ "StackDisplayStyleGapMin", "7*default_rule_thickness" },
+ ['display_style']={ "StackDisplayStyleGapMin", "7*default_rule_thickness" },
+ },
+ ['sub_shift_down']={
+ ['default']={ "SubscriptShiftDown", "sub1" },
+ },
+ ['sub_shift_drop']={
+ ['default']={ "SubscriptBaselineDropMin", "sub_drop" },
+ },
+ ['sub_sup_shift_down']={
+ ['default']={ "SubscriptShiftDown", "sub2" },
+ },
+ ['sub_top_max']={
+ ['default']={ "SubscriptTopMax", "abs(math_x_height*4)/5" },
+ },
+ ['subsup_vgap']={
+ ['default']={ "SubSuperscriptGapMin", "4*default_rule_thickness" },
+ },
+ ['sup_bottom_min']={
+ ['default']={ "SuperscriptBottomMin", "abs(math_x_height)/4" },
+ },
+ ['sup_shift_drop']={
+ ['default']={ "SuperscriptBaselineDropMax", "sup_drop" },
+ },
+ ['sup_shift_up']={
+ ['cramped_display_style']={ "SuperscriptShiftUpCramped", "sup3" },
+ ['cramped_script_script_style']={ "SuperscriptShiftUpCramped", "sup3" },
+ ['cramped_script_style']={ "SuperscriptShiftUpCramped", "sup3" },
+ ['cramped_text_style']={ "SuperscriptShiftUpCramped", "sup3" },
+ ['display_style']={ "SuperscriptShiftUp", "sup1" },
+ ['script_script_style']={ "SuperscriptShiftUp", "sup2" },
+ ['script_style']={ "SuperscriptShiftUp", "sup2" },
+ ['text_style']={ "SuperscriptShiftUp", "sup2" },
+ },
+ ['sup_sub_bottom_max']={
+ ['default']={ "SuperscriptBottomMaxWithSubscript", "abs(math_x_height*4)/5" },
+ },
+ ['underbar_kern']={
+ ['default']={ "UnderbarExtraDescender", "0" },
+ },
+ ['underbar_rule']={
+ ['default']={ "UnderbarRuleThickness", "default_rule_thickness" },
+ },
+ ['underbar_vgap']={
+ ['default']={ "UnderbarVerticalGap", "3*default_rule_thickness" },
+ },
+ ['connector_overlap_min']={
+ ['default']={ "MinConnectorOverlap", "0.25*default_rule_thickness" },
+ },
+ ['over_delimiter_vgap']={
+ ['default']={ "StretchStackGapBelowMin", "big_op_spacing1" },
+ },
+ ['over_delimiter_bgap']={
+ ['default']={ "StretchStackTopShiftUp", "big_op_spacing3" },
+ },
+ ['under_delimiter_vgap']={
+ ['default']={ "StretchStackGapAboveMin", "big_op_spacing2" },
+ },
+ ['under_delimiter_bgap']={
+ ['default']={ "StretchStackBottomShiftDown", "big_op_spacing4" },
+ },
+ ['radical_degree_before']={
+ ['default']={ "RadicalKernBeforeDegree", "(5/18)*quad" },
+ },
+ ['radical_degree_after']={
+ ['default']={ "RadicalKernAfterDegree", "(-10/18)*quad" },
+ },
+ ['radical_degree_raise']={
+ ['default']={ "RadicalDegreeBottomRaisePercent", "60" },
+ },
+}
+
+local styles = {
+ 'cramped_display_style',
+ 'cramped_script_script_style',
+ 'cramped_script_style',
+ 'cramped_text_style',
+ 'display_style',
+ 'script_script_style',
+ 'script_style',
+ 'text_style',
+}
+
+for k, v in next, defaults do
+ for _, s in next, styles do
+ if not v[s] then
+ v[s] = v.default
+ end
+ end
+end
+
+-- we cannot use a metatable because we do a copy (takes a bit more work)
+--
+-- local mt = { } setmetatable(defaults,mt)
+--
+-- mt.__index = function(t,s)
+-- texio.write_nl("GETTING " .. s)
+-- return t.default or t.text_style or 0
+-- end
+
+function mathematics.dimensions(dimens)
+ if dimens.SpaceAfterScript then
+ return { }, table.fastcopy(dimens)
+ elseif dimens.AxisHeight or dimens.axis_height then
+ local t = { }
+ local math_x_height = dimens.x_height or 10*65526
+ local math_quad = dimens.quad or 10*65526
+ local default_rule_thickness = dimens.FractionDenominatorGapMin or dimens.default_rule_thickness or 0.4*65526
+ dimens["0"] = 0
+ dimens["60"] = 60
+ dimens["0.25*default_rule_thickness"] = default_rule_thickness / 4
+ dimens["3*default_rule_thickness"] = 3 * default_rule_thickness
+ dimens["4*default_rule_thickness"] = 4 * default_rule_thickness
+ dimens["7*default_rule_thickness"] = 7 * default_rule_thickness
+ dimens["(5/18)*quad"] = (math_quad * 5) / 18
+ dimens["(-10/18)*quad"] = - (math_quad * 10) / 18
+ dimens["abs(math_x_height*4)/5"] = abs(math_x_height * 4) / 5
+ dimens["default_rule_thickness+(abs(default_rule_thickness)/4)"] = default_rule_thickness+(abs(default_rule_thickness) / 4)
+ dimens["default_rule_thickness+(abs(math_x_height)/4)"] = default_rule_thickness+(abs(math_x_height) / 4)
+ dimens["abs(math_x_height)/4"] = abs(math_x_height) / 4
+ dimens["abs(math_x_height*4)/5"] = abs(math_x_height * 4) / 5
+ dimens[""] = false
+ dimens["script_space"] = false -- at macro level
+ for variable, styles in next, defaults do
+ local tt = { }
+ for style, default in next, styles do
+ local one, two = default[1], default[2]
+ local value = dimens[one]
+ if value then
+ tt[style] = value
+ else
+ value = dimens[two]
+ if value == false then
+ tt[style] = nil
+ else
+ tt[style] = value or 0
+ end
+ end
+ end
+ t[variable] = tt
+ end
+ local d = {
+ AxisHeight = t . axis . text_style,
+ AccentBaseHeight = t . accent_base_height . text_style,
+ FractionDenominatorDisplayStyleGapMin = t . fraction_denom_vgap . display_style,
+ FractionDenominatorDisplayStyleShiftDown = t . fraction_denom_down . display_style,
+ FractionDenominatorGapMin = t . fraction_denom_vgap . text_style,
+ FractionDenominatorShiftDown = t . fraction_denom_down . text_style,
+ FractionNumeratorDisplayStyleGapMin = t . fraction_num_vgap . display_style,
+ FractionNumeratorDisplayStyleShiftUp = t . fraction_num_up . display_style,
+ FractionNumeratorGapMin = t . fraction_num_vgap . text_style,
+ FractionNumeratorShiftUp = t . fraction_num_up . text_style,
+ FractionRuleThickness = t . fraction_rule . text_style,
+ LowerLimitBaselineDropMin = t . limit_below_bgap . text_style,
+ LowerLimitGapMin = t . limit_below_vgap . text_style,
+ OverbarExtraAscender = t . overbar_kern . text_style,
+ OverbarRuleThickness = t . overbar_rule . text_style,
+ OverbarVerticalGap = t . overbar_vgap . text_style,
+ RadicalDisplayStyleVerticalGap = t . radical_vgap . display_style,
+ RadicalExtraAscender = t . radical_kern . text_style,
+ RadicalRuleThickness = t . radical_rule . text_style,
+ RadicalVerticalGap = t . radical_vgap . text_style,
+ RadicalKernBeforeDegree = t . radical_degree_before . display_style,
+ RadicalKernAfterDegree = t . radical_degree_after . display_style,
+ RadicalDegreeBottomRaisePercent = t . radical_degree_raise . display_style,
+ SpaceAfterScript = t . space_after_script . text_style,
+ StackBottomDisplayStyleShiftDown = t . stack_denom_down . display_style,
+ StackBottomShiftDown = t . stack_denom_down . text_style,
+ StackDisplayStyleGapMin = t . stack_vgap . display_style,
+ StackGapMin = t . stack_vgap . text_style,
+ StackTopDisplayStyleShiftUp = t . stack_num_up . display_style,
+ StackTopShiftUp = t . stack_num_up . text_style,
+ SubscriptBaselineDropMin = t . sub_shift_drop . text_style,
+ SubscriptShiftDown = t . sub_shift_down . text_style,
+ SubscriptTopMax = t . sub_top_max . text_style,
+ SubSuperscriptGapMin = t . subsup_vgap . text_style,
+ SuperscriptBaselineDropMax = t . sup_shift_drop . text_style,
+ SuperscriptBottomMaxWithSubscript = t . sup_sub_bottom_max . text_style,
+ SuperscriptBottomMin = t . sup_bottom_min . text_style,
+ SuperscriptShiftUp = t . sup_shift_up . text_style,
+ SuperscriptShiftUpCramped = t . sup_shift_up . cramped_text_style,
+ UnderbarExtraDescender = t . underbar_kern . text_style,
+ UnderbarRuleThickness = t . underbar_rule . text_style,
+ UnderbarVerticalGap = t . underbar_vgap . text_style,
+ UpperLimitBaselineRiseMin = t . limit_above_bgap . text_style,
+ UpperLimitGapMin = t . limit_above_vgap . text_style,
+ MinConnectorOverlap = t . connector_overlap_min . text_style,
+ StretchStackGapBelowMin = t . over_delimiter_vgap . text_style,
+ StretchStackTopShiftUp = t . over_delimiter_bgap . text_style,
+ StretchStackGapAboveMin = t . under_delimiter_vgap . text_style,
+ StretchStackBottomShiftDown = t . under_delimiter_bgap . text_style,
+ }
+ d.AccentBaseHeight = 0
+ -- texio.write_nl(table.serialize(d))
+ return t, d -- this might change
+ else
+ return { }, { }
+ end
+end
+
diff --git a/tex/context/base/math-dis.mkiv b/tex/context/base/math-dis.mkiv
new file mode 100644
index 000000000..3eed2b162
--- /dev/null
+++ b/tex/context/base/math-dis.mkiv
@@ -0,0 +1,20 @@
+%D \module
+%D [ file=math-ali,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Display,
+%D author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=PRAGMA-ADE / Hans Hagen]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Display}
+
+\unprotect
+
+% display spacing code will move here
+
+\protect \endinput
diff --git a/tex/context/base/math-ext.lua b/tex/context/base/math-ext.lua
new file mode 100644
index 000000000..52dce0255
--- /dev/null
+++ b/tex/context/base/math-ext.lua
@@ -0,0 +1,143 @@
+if not modules then modules = { } end modules ['math-ext'] = {
+ version = 1.001,
+ comment = "companion to math-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local trace_virtual = false trackers.register("math.virtual", function(v) trace_virtual = v end)
+
+mathematics = mathematics or { }
+characters = characters or { }
+
+mathematics.extras = mathematics.extras or { }
+characters.math = characters.math or { }
+
+local chardata = characters.data
+local mathdata = characters.math
+
+function mathematics.extras.add(unicode,t)
+ local min, max = mathematics.extrabase, mathematics.privatebase - 1
+ if unicode >= min and unicode <= max then
+ mathdata[unicode], chardata[unicode] = t, t
+ else
+ logs.report("math extra","extra U+%04X should be in range U+%04X - U+%04X",unicode,min,max)
+ end
+end
+
+function mathematics.extras.copy(tfmdata)
+ local math_parameters = tfmdata.math_parameters
+ local MathConstants = tfmdata.MathConstants
+ if (math_parameters and next(math_parameters)) or (MathConstants and next(MathConstants)) then
+ local characters = tfmdata.characters
+ for unicode, extradesc in next, mathdata do
+ -- always, because in an intermediate step we can have a non math font
+ local extrachar = characters[unicode]
+ local nextinsize = extradesc.nextinsize
+ if nextinsize then
+ for i=1,#nextinsize do
+ local nextslot = nextinsize[i]
+ local nextbase = characters[nextslot]
+ if nextbase then
+ local nextnext = nextbase and nextbase.next
+ if nextnext then
+ local nextchar = characters[nextnext]
+ if nextchar then
+ if trace_virtual then
+ logs.report("math extra","extra U+%04X in %s at %s maps on U+%04X (class: %s, name: %s)",unicode,file.basename(tfmdata.fullname),tfmdata.size,nextslot,extradesc.mathclass or "?",extradesc.mathname or "?")
+ end
+ characters[unicode] = nextchar
+ break
+ end
+ end
+ end
+ end
+ if not characters[unicode] then
+ for i=1,#nextinsize do
+ local nextbase = characters[nextinsize[i]]
+ if nextbase then
+ characters[unicode] = nextchar
+ break
+ end
+ end
+ end
+ end
+ end
+ else
+ -- let's not waste time on non-math
+ end
+end
+
+table.insert(fonts.tfm.mathactions,mathematics.extras.copy)
+
+-- 0xFE302 -- 0xFE320 for accents
+
+mathematics.extras.add(0xFE302, {
+ category="mn",
+ description="WIDE MATHEMATICAL HAT",
+ direction="nsm",
+ linebreak="cm",
+ mathclass="accent",
+ mathname="widehat",
+ mathstretch="h",
+ unicodeslot=0xFE302,
+ nextinsize={ 0x00302, 0x0005E },
+} )
+
+mathematics.extras.add(0xFE303, {
+ category="mn",
+ cjkwd="a",
+ description="WIDE MATHEMATICAL TILDE",
+ direction="nsm",
+ linebreak="cm",
+ mathclass="accent",
+ mathname="widetilde",
+ mathstretch="h",
+ unicodeslot=0xFE303,
+ nextinsize={ 0x00303, 0x0007E },
+} )
+
+-- 0xFE321 -- 0xFE340 for missing characters
+
+-- mathematics.extras.add(0xFE321, {
+-- category="sm",
+-- description="SHORT BAR",
+-- -- direction="on",
+-- -- linebreak="nu",
+-- mathclass="relation",
+-- mathname="mapstochar",
+-- unicodeslot=0xFE321,
+-- } )
+
+
+
+
+
+--~ mathematics.extras.add(0xFE304, {
+--~ category="sm",
+--~ description="TOP AND BOTTOM PARENTHESES",
+--~ direction="on",
+--~ linebreak="al",
+--~ mathclass="doubleaccent",
+--~ mathname="doubleparent",
+--~ unicodeslot=0xFE304,
+--~ accents={ 0x023DC, 0x023DD },
+--~ } )
+
+--~ mathematics.extras.add(0xFE305, {
+--~ category="sm",
+--~ description="TOP AND BOTTOM BRACES",
+--~ direction="on",
+--~ linebreak="al",
+--~ mathclass="doubleaccent",
+--~ mathname="doublebrace",
+--~ unicodeslot=0xFE305,
+--~ accents={ 0x023DE, 0x023DF },
+--~ } )
+
+--~ \Umathchardef\braceld="0 "1 "FF07A
+--~ \Umathchardef\bracerd="0 "1 "FF07B
+--~ \Umathchardef\bracelu="0 "1 "FF07C
+--~ \Umathchardef\braceru="0 "1 "FF07D
+
diff --git a/tex/context/base/math-ext.tex b/tex/context/base/math-ext.tex
deleted file mode 100644
index cf332ba00..000000000
--- a/tex/context/base/math-ext.tex
+++ /dev/null
@@ -1,437 +0,0 @@
-%D \module
-%D [ file=math-ext,
-%D version=2007.07.19,
-%D title=\CONTEXT\ Math Macros,
-%D subtitle=Extra Macros,
-%D author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
-%D date=\currentdate,
-%D copyright=\PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-%D These will be generalized!
-
-\def\exmthfont#1{\symbolicsizedfont#1\plusone{MathExtension}}
-
-\def\domthfrac#1#2#3#4#5#6#7%
- {\begingroup
- \mathsurround\zeropoint
- \setbox0\hbox{$#1 #6$}%
- \setbox2\hbox{$#1 #7$}%
- \dimen0\wd0
- \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
- \setbox4\hbox to \dimen0{\exmthfont#2#3\leaders\hbox{#4}\hss#5}%
- \mathord{\vcenter{{\offinterlineskip
- \hbox to \dimen0{\hss\box0\hss}%
- \kern \ht4%
- \hbox to \dimen0{\hss\copy4\hss}%
- \kern \ht4%
- \hbox to \dimen0{\hss\box2\hss}}}}%
- \endgroup}
-
-\def\domthsqrt#1#2#3#4#5%
- {\begingroup
- \mathsurround\zeropoint
- \setbox0\hbox{$#1 #5$}%
- \dimen0=1.05\ht0 \advance\dimen0 1pt \ht0 \dimen0
- \dimen0=1.05\dp0 \advance\dimen0 1pt \dp0 \dimen0
- \dimen0\wd0
- \setbox4\hbox to \dimen0{\exmthfont#2\leaders\hbox{#3}\hfill#4}%
- \delimitershortfall=0pt
- \nulldelimiterspace=0pt
- \setbox2\hbox{$\left\delimiter"0270370 \vrule height\ht0 depth \dp0 width0pt
- \right.$}%
- \mathord{\vcenter{\hbox{\copy2
- \rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}%
- \endgroup}
-
-\def\mthfrac#1#2#3#4#5{\mathchoice
- {\domthfrac\displaystyle \textface {#1}{#2}{#3}{#4}{#5}}
- {\domthfrac\textstyle \textface {#1}{#2}{#3}{#4}{#5}}
- {\domthfrac\scriptstyle \scriptface {#1}{#2}{#3}{#4}{#5}}
- {\domthfrac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}}
-
-\def\mthsqrt#1#2#3{\mathchoice
- {\domthsqrt\displaystyle \textface {#1}{#2}{#3}}
- {\domthsqrt\textstyle \textface {#1}{#2}{#3}}
- {\domthsqrt\scriptstyle \textface {#1}{#2}{#3}}
- {\domthsqrt\scriptscriptstyle\textface {#1}{#2}{#3}}}
-
-% temp here
-
-%D We next define extensible arrows. Extensible arrows are arrows that
-%D change their length according to the width of the text to be placed
-%D above and below the arrow. Since we need to define a lot of arrows,
-%D we first define some helper macros. The basic idea is to measure
-%D the width of the box to be placed above and below the arrow, and
-%D make the \quotation{body} of the arrow as long as the bigger of the
-%D two widths.
-
-\def\mtharrfactor{1}
-\def\mtharrextra {0}
-
-\def\domthxarr#1#2#3#4#5% hm, looks like we do a double mathrel
- {\begingroup
- \def\mtharrfactor{1}%
- \def\mtharrextra {0}%
- \processaction[#1] % will be sped up
- [ \v!none=>\def\mtharrfactor{0},
- \v!small=>\def\mtharrextra{10},
- \v!medium=>\def\mtharrextra{15},
- \v!big=>\def\mtharrextra{20},
- \v!normal=>,
- \v!default=>,
- \v!unknown=>\doifnumberelse{#1}{\def\mtharrextra{#1}}\donothing]%
- \mathsurround\zeropoint
- \muskip0=\thirdoffourarguments #2mu
- \muskip2=\fourthoffourarguments #2mu
- \muskip4=\firstoffourarguments #2mu
- \muskip6=\secondoffourarguments #2mu
- \muskip0=\mtharrfactor\muskip0 \advance\muskip0 \mtharrextra mu
- \muskip2=\mtharrfactor\muskip2 \advance\muskip2 \mtharrextra mu
- \setbox0\hbox{$\scriptstyle
- \mkern\muskip4\relax
- \mkern\muskip0\relax
- #5\relax
- \mkern\muskip2\relax
- \mkern\muskip6\relax
- $}%
- \setbox4\hbox{#3\displaystyle}%
- \dimen0\wd0
- \ifdim\wd4>\dimen0 \dimen0\wd4 \fi
- \setbox2\hbox{$\scriptstyle
- \mkern\muskip4\relax
- \mkern\muskip0\relax
- #4\relax
- \mkern\muskip2\relax
- \mkern\muskip6\relax
- $}%
- \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
- \setbox4\hbox to \dimen0{#3\displaystyle}%
- \mathrel{\mathop{\hbox to \dimen0{\hss\copy4\hss}}\limits^{\box0}_{\box2}}
- \endgroup}
-
-\let\domthxarrsingle\domthxarr
-
-%D There are some arrows which are created by stacking two arrows. The next
-%D macro helps in defining such \quotation{double arrows}.
-
-\def\domthxarrdouble#1#2#3#4#5#6#7% opt l r sp rs top bot
- {\mathrel
- {\scratchdimen.32ex\relax % was .22, todo: make configurable
- \setbox0\hbox{$\domthxarr{#1}{#2}{#4}{\phantom{#6}}{#7}$}%
- \setbox2\hbox{$\domthxarr{#1}{#3}{#5}{#6}{\phantom{#7}}$}%
- \raise\scratchdimen\box0
- \kern-\wd2
- \lower\scratchdimen\box2}}
-
-%D \macros{definematharrow}
-%D
-%D Macro for defining new arrows. We can define two types of
-%D arrows|<|single arrows and double arrows. Single arrows are defined
-%D as
-%D
-%D \starttyping
-%D \definematharrow [xrightarrow] [0359] [\rightarrowfill]
-%D \stoptyping
-%D
-%D The first argument is the name of the arrow (\tex{xrightarrow} in
-%D this case.) The second argument consists of a set of 4 numbers and
-%D specify the spacing correction in math units~\type{mu}. These
-%D numbers define:
-%D
-%D \startlines
-%D 1st number: arrow||tip correction
-%D 2nd number: arrow||tip correction
-%D 3rd number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
-%D 4th number: space (multiplied by \tex{matharrfactor} and advanced by \tex{matharrextra})
-%D \stoplines
-%D
-%D The third argument is the name of the extensible fill. The third
-%D argument is optional when the arrow is redefined later (this is
-%D useful for font specific tweaking of the skips.) For example,
-%D
-%D \startbuffer
-%D \math{\xrightarrow{above}}
-%D \definematharrow[xrightarrow][0000]
-%D \math{\xrightarrow{above}}
-%D \definematharrow[xrightarrow][55{50}{50}]
-%D \math{\xrightarrow{above}}
-%D \stopbuffer
-%D \typebuffer gives {\getbuffer}
-%D
-%D The double arrows are defined as follows
-%D
-%D \starttyping
-%D \definematharrow [xrightleftharpoons] [3095,0359]
-%D [\rightharpoonupfill,\leftharpoondownfill]
-%D \stoptyping
-%D
-%D The second and the third set of arguments consist of comma
-%D separated values. The first element of the second argument
-%D (\type{3095}) corresponds to the spacing correction of top arrow
-%D fill (\tex{rightarrowupfill}). Similarly, \type{0359} corresponds
-%D to bottom arrow fill \tex{leftharpoondownfill}). Stacking them on
-%D top of each other we get $\xrightleftharpoons[big]{above}{below}$.
-%D The following math arrows are defined
-%D
-%D \placetable[none]{}{\starttable[|l|m|]
-%D \NC \tex{xrightarrow } \NC \xrightarrow [big] \NC \NR
-%D \NC \tex{xleftarrow } \NC \xleftarrow [big] \NC \NR
-%D \NC \tex{xequal } \NC \xequal [big] \NC \NR
-%D \NC \tex{xRightarrow } \NC \xRightarrow [big] \NC \NR
-%D \NC \tex{xLeftarrow } \NC \xLeftarrow [big] \NC \NR
-%D \NC \tex{xLeftrightarrow } \NC \xLeftrightarrow [big] \NC \NR
-%D \NC \tex{xleftrightarrow } \NC \xleftrightarrow [big] \NC \NR
-%D \NC \tex{xmapsto } \NC \xmapsto [big] \NC \NR
-%D \NC \tex{xtwoheadrightarrow } \NC \xtwoheadrightarrow [big] \NC \NR
-%D \NC \tex{xtwoheadleftarrow } \NC \xtwoheadleftarrow [big] \NC \NR
-%D \NC \tex{xrightharpoondown } \NC \xrightharpoondown [big] \NC \NR
-%D \NC \tex{xrightharpoonup } \NC \xrightharpoonup [big] \NC \NR
-%D \NC \tex{xleftharpoondown } \NC \xleftharpoondown [big] \NC \NR
-%D \NC \tex{xleftharpoonup } \NC \xleftharpoonup [big] \NC \NR
-%D \NC \tex{xhookleftarrow } \NC \xhookleftarrow [big] \NC \NR
-%D \NC \tex{xhookrightarrow } \NC \xhookrightarrow [big] \NC \NR
-%D \NC \tex{xleftrightharpoons } \NC \xleftrightharpoons [big] \NC \NR
-%D \NC \tex{xrightleftharpoons } \NC \xrightleftharpoons [big] \NC \NR
-%D \stoptable}
-
-\def\definematharrow
- {\doquadrupleargument\dodefinematharrow}
-
-\def\dodefinematharrow[#1][#2][#3][#4]% name type[none|both] template command
- {\iffourthargument
- \executeifdefined{dodefine#2arrow}\gobblethreearguments{#1}{#3}{#4}%
- \else\ifthirdargument
- \dodefinebotharrow{#1}{#2}{#3}%
- \else\ifsecondargument
- \redefinebotharrow{#1}{#2}{#3}%
- \fi\fi\fi}
-
-\def\redefinebotharrow#1#2#3% real dirty, this overload!
- {\doifdefined{#1}
- {\pushmacro\dohandlemtharrow
- \def\dohandlemtharrow[##1][##2]{\setvalue{#1}{\dohandlemtharrow[#2][##2]}}%
- % == \def\dohandlemtharrow[##1][##2]{\dodefinebotharrow{#1}{#2}{##2}}%
- \getvalue{#1}%
- \popmacro\dohandlemtharrow}}
-
-\def\dodefinebotharrow#1#2#3%
- {\setvalue{#1}{\dohandlemtharrow[#2][#3]}}
-
-\def\dohandlemtharrow
- {\dotripleempty\doxmtharrow}
-
-\def\doxmtharrow[#1][#2][#3]% #3 == optional arg
- {\def\dodoxmtharrow{\dododoxmtharrow[#1,\empty,\empty][#2,\empty,\empty][#3]}% {##1}{##2}
- \dodoublegroupempty\dodoxmtharrow}
-
-\def\dododoxmtharrow[#1,#2,#3][#4,#5,#6][#7]#8#9% [3] is the optional arg
- {\edef\!!stringa{#2}%
- \ifx\!!stringa\empty
- \ifsecondargument
- \mathrel{\domthxarrsingle{#7}{#1}{#4}{#8}{#9}}%
- \else
- \mathrel{\domthxarrsingle{#7}{#1}{#4}{}{#8}}%
- \fi
- \else
- \ifsecondargument
- \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{#8}{#9}}%
- \else
- \mathrel{\domthxarrdouble{#7}{#1}{#2}{#4}{#5}{}{#8}}%
- \fi
- \fi}
-
-% Adapted from amsmath.
-
-%D \macros{mtharrowfill,defaultmtharrowfill}
-%D
-%D To extend the arrows we need to define a \quotation{math arrow
-%D fill}. This command takes 8 arguments: the first four correspond
-%D the second argument of \tex{definematharrow} explained above. The
-%D other three specify the tail, body and head of the arrow. The last
-%D argument specifies the math-mode in which the arrow is drawn.
-%D \tex{defaultmtharrowfill} has values tweaked to match Latin Modern
-%D fonts. For fonts that are significantly different (e.g. cows) a
-%D different set of values need to be determined.
-
-\def\mtharrowfill#1#2#3#4#5#6#7#8%
- {$\mathsurround 0pt
- \thickmuskip0mu\medmuskip\thickmuskip\thinmuskip\thickmuskip
- \relax#8#5%
- \mkern-#1mu
- \cleaders\hbox{$#8\mkern -#2mu#6\mkern -#3mu$}\hfill
- \mkern-#4mu#7$}
-
-\def\defaultmtharrowfill{\mtharrowfill 7227}
-
-%D We now define some arrow fills that will be used for defining the
-%D arrows. Plain \TEX\ already defines \tex{leftarrowfill} and
-%D \tex{rightarrowfill}. The \tex{defaultmtharrowfill} command defines an
-%D arrowfill that takes an argument (so that it can also be used
-%D with over and under arrows). However the Plain \TEX\ definitions of
-%D \tex{leftarrowfill} and \tex{rightarrowfill} do not take this extra
-%D argument. To be backward compatible with Plain \TEX, we define two
-%D arrowfills: \tex{specrightarrowfill} which takes an extra argument, and
-%D \tex{rightarrowfill} which does not.
-
-\def\specrightarrowfill {\defaultmtharrowfill \relbar \relbar \rightarrow}
-\def\specleftarrowfill {\defaultmtharrowfill \leftarrow \relbar \relbar}
-
-\def\rightarrowfill {\specrightarrowfill \textstyle}
-\def\leftarrowfill {\specleftarrowfill \textstyle}
-
-\def\equalfill {\defaultmtharrowfill \Relbar \Relbar \Relbar}
-\def\Rightarrowfill {\defaultmtharrowfill \Relbar \Relbar \Rightarrow}
-\def\Leftarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Relbar}
-\def\Leftrightarrowfill {\defaultmtharrowfill \Leftarrow \Relbar \Rightarrow}
-\def\leftrightarrowfill {\defaultmtharrowfill \leftarrow \relbar \rightarrow}
-\def\mapstofill {\defaultmtharrowfill{\mapstochar\relbar} \relbar \rightarrow}
-\def\twoheadrightarrowfill{\defaultmtharrowfill \relbar \relbar \twoheadrightarrow}
-\def\twoheadleftarrowfill {\defaultmtharrowfill \twoheadleftarrow \relbar \relbar}
-\def\rightharpoondownfill {\defaultmtharrowfill \relbar \relbar \rightharpoondown}
-\def\rightharpoonupfill {\defaultmtharrowfill \relbar \relbar \rightharpoonup}
-\def\leftharpoondownfill {\defaultmtharrowfill \leftharpoondown \relbar \relbar}
-\def\leftharpoonupfill {\defaultmtharrowfill \leftharpoonup \relbar \relbar}
-\def\hookleftfill {\defaultmtharrowfill \leftarrow \relbar{\relbar\joinrel\rhook}}
-\def\hookrightfill {\defaultmtharrowfill{\lhook\joinrel\relbar}\relbar \rightarrow}
-\def\relfill {\defaultmtharrowfill \relbar \relbar \relbar}
-
-\def\triplerelbar {\mathrel\equiv}
-\def\triplerelfill{\defaultmtharrowfill\triplerelbar\triplerelbar\triplerelbar}
-
-\def\singlebond{{\xrel}} % or \def\singlebond{{\xrel[2]}}
-\def\doublebond{{\xequal}}
-\def\triplebond{{\xtriplerel}}
-
-%D Now we define most commonly used arrows. These include arrows
-%D defined in \filename{amsmath.sty}, \filename{extarrows.sty},
-%D \filename{extpfel.sty} and \filename{mathtools.sty} packages for
-%D \LATEX\ (plus a few more).
-
-\definematharrow [xrightarrow] [0359] [\specrightarrowfill]
-\definematharrow [xleftarrow] [3095] [\specleftarrowfill]
-\definematharrow [xequal] [0099] [\equalfill]
-\definematharrow [xRightarrow] [0359] [\Rightarrowfill]
-\definematharrow [xLeftarrow] [3095] [\Leftarrowfill]
-\definematharrow [xLeftrightarrow] [0099] [\Leftrightarrowfill]
-\definematharrow [xleftrightarrow] [0099] [\leftrightarrowfill]
-\definematharrow [xmapsto] [3599] [\mapstofill]
-\definematharrow [xtwoheadrightarrow] [5009] [\twoheadrightarrowfill]
-\definematharrow [xtwoheadleftarrow] [0590] [\twoheadleftarrowfill]
-\definematharrow [xrightharpoondown] [0359] [\rightharpoondownfill]
-\definematharrow [xrightharpoonup] [0359] [\rightharpoonupfill]
-\definematharrow [xleftharpoondown] [3095] [\leftharpoondownfill]
-\definematharrow [xleftharpoonup] [3095] [\leftharpoonupfill]
-\definematharrow [xhookleftarrow] [3095] [\hookleftfill]
-\definematharrow [xhookrightarrow] [0395] [\hookrightfill]
-\definematharrow [xrel] [0099] [\relfill]
-\definematharrow [xtriplerel] [0099] [\triplerelfill]
-\definematharrow [xrightoverleftarrow] [0359,3095] [\specrightarrowfill,\specleftarrowfill]
-\definematharrow [xleftrightharpoons] [3399,3399] [\leftharpoonupfill,\rightharpoondownfill]
-\definematharrow [xrightleftharpoons] [3399,3399] [\rightharpoonupfill,\leftharpoondownfill]
-
-%D These arrows can be used as follows:
-%D
-%D \startbuffer
-%D \startformula \xrightarrow{stuff on top}\stopformula
-%D \startformula \xrightarrow{}{stuff on top}\stopformula
-%D \startformula \xrightarrow{stuff below}{}\stopformula
-%D \startformula \xrightarrow{stuff below}{stuff on top}\stopformula
-%D
-%D \startformula \xleftarrow [none]{stuff below}{stuff on top}\stopformula
-%D \startformula \xleftarrow [small]{stuff below}{stuff on top}\stopformula
-%D \startformula \xleftarrow [medium]{stuff below}{stuff on top}\stopformula
-%D \startformula \xleftarrow [big]{stuff below}{stuff on top}\stopformula
-%D \stopbuffer
-%D
-%D \typebuffer which gives \getbuffer
-
-%D \macros{definemathoverarrow,defineunderarrow}
-%D
-%D These macros for define math-overarrows are adapted from
-%D \filename{amsmath.sty}
-
-\def\definemathoverarrow
- {\dotripleargument\dodefinemathoverarrow}
-
-\def\dodefinemathoverarrow[#1][#2][#3]%
- {\ifthirdargument
- \setvalue{#1}{\dohandlemathoverarrow[#2][#3]}%
- \else
- \setvalue{#1}{\dohandlemathoverarrow[\zeropoint][#2]}%
- \fi}
-
-\def\dohandlemathoverarrow[#1][#2]%
- {\mathpalette{\dodohandlemathoverarrow{#1}{#2}}}
-
-%D Note: \filename{math-pln.tex} has \type{\kern-\onepoint} and
-%D \filename{amsmath.sty} does not. We keep the kern amount
-%D configurable. This is useful for harpoons.
-
-\def\dodohandlemathoverarrow#1#2#3#4%
- {\vbox{\ialign{##\crcr
- #2#3\crcr
- \noalign{\kern#1\nointerlineskip}%
- $\m@th\hfil#3#4\hfil$\crcr}}}
-
-%D Now the under arrows
-
-\def\definemathunderarrow
- {\dotripleargument\dodefinemathunderarrow}
-
-%D For underarrows the default kern is 0.3ex
-
-\def\dodefinemathunderarrow[#1][#2][#3]%
- {\ifthirdargument
- \setvalue{#1}{\dohandlemathunderarrow[#2][#3]}%
- \else
- \setvalue{#1}{\dohandlemathunderarrow[0.3ex][#2]}%
- \fi}
-
-\def\dohandlemathunderarrow[#1][#2]%
- {\mathpalette{\dodohandlemathunderarrow{#1}{#2}}}
-
-\def\dodohandlemathunderarrow#1#2#3#4%
- {\vtop{\ialign{##\crcr
- $\m@th\hfil#3#4\hfil$\crcr
- \noalign{\nointerlineskip\kern#1}%
- #2#3\crcr}}}
-
-%D Now we define the arrows
-
-\definemathoverarrow [overleftarrow] [\specleftarrowfill]
-\definemathoverarrow [overrightarrow] [\specrightarrowfill]
-\definemathoverarrow [overleftrightarrow] [\leftrightarrowfill]
-\definemathoverarrow [overtwoheadrightarrow] [\twoheadrightarrowfill]
-\definemathoverarrow [overtwoheadleftarrow] [\twoheadleftarrowfill]
-\definemathoverarrow [overrightharpoondown] [1pt] [\rightharpoondownfill]
-\definemathoverarrow [overrightharpoonup] [\rightharpoonupfill]
-\definemathoverarrow [overleftharpoondown] [1pt] [\leftharpoondownfill]
-\definemathoverarrow [overleftharpoonup] [\leftharpoonupfill]
-
-\definemathunderarrow [underleftarrow] [\specleftarrowfill]
-\definemathunderarrow [underrightarrow] [\specrightarrowfill]
-\definemathunderarrow [underleftrightarrow] [\leftrightarrowfill]
-\definemathunderarrow [undertwoheadrightarrow][\twoheadrightarrowfill]
-\definemathunderarrow [undertwoheadleftarrow] [\twoheadleftarrowfill]
-\definemathunderarrow [underrightharpoondown] [\rightharpoondownfill]
-\definemathunderarrow [underrightharpoonup] [\rightharpoonupfill]
-\definemathunderarrow [underleftharpoondown] [\leftharpoondownfill]
-\definemathunderarrow [underleftharpoonup] [\leftharpoonupfill]
-
-%D These can be used as follows:
-%D
-%D \startbuffer
-%D $\overleftarrow{A}$ $\overleftarrow{ABC}$
-%D $a_{\overleftarrow{A}}$ $b_{\overleftarrow{ABC}}$
-%D \stopbuffer
-%D \typebuffer which gives \getbuffer
-
-%D TODO: Possibly have a single arrow command define all the arrows.
-
-\protect \endinput
diff --git a/tex/context/base/math-for.mkiv b/tex/context/base/math-for.mkiv
new file mode 100644
index 000000000..87aeaa4e0
--- /dev/null
+++ b/tex/context/base/math-for.mkiv
@@ -0,0 +1,73 @@
+%D \module
+%D [ file=strc-mat,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Structure Macros,
+%D subtitle=Math Numbering,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA-ADE / Hans Hagen]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Structure Macros / Math Formulas}
+
+%D This module only provides the code for defining formulas and
+%D fetching parameters. The action takes place later.
+
+\unprotect
+
+\let\currentformula\s!unknown
+
+\def\formulaparameter #1{\csname\doformulaparameter{\??fm\currentformula}#1\endcsname}
+\def\formulaparameterhash#1{\doformulaparameterhash {\??fm\currentformula}#1}
+
+\def\doformulaparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doformulaparentparameter \csname#1\s!parent\endcsname#2\fi}
+\def\doformulaparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doformulaparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+
+\def\detokenizedformulaparameter#1{\detokenize\expandafter\expandafter\expandafter{\csname\??fm\currentformula#1\endcsname}}
+
+\def\doformulaparentparameter #1#2{\ifx#1\relax\s!empty\else\doformulaparameter #1#2\fi}
+\def\doformulaparentparameterhash#1#2{\ifx#1\relax \else\doformulaparameterhash#1#2\fi}
+
+\def\dosetformulaattributes#1#2% style color
+ {\edef\fontattributehash {\formulaparameterhash#1}%
+ \edef\colorattributehash{\formulaparameterhash#2}%
+ \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi
+ \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi}
+
+%D \macros
+%D {setupformulas}
+
+\newtoks \everysetupformulas
+
+\def\setupformulas
+ {\dodoubleempty\dosetupformulas}
+
+\def\dosetupformulas[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??fm#1][#2]%
+ \else
+ \getparameters[\??fm][#1]%
+ \fi
+ \the\everysetupformulas}
+
+%D Not yet cleanup up:
+
+%D \macros
+%D {setuptextformulas}
+%D
+%D This command sets up in||line math. Most features deals
+%D with grid snapping and are experimental.
+
+\newtoks \everysetuptextformulas
+
+\def\setuptextformulas
+ {\dosingleempty\dosetuptextformulas}
+
+\def\dosetuptextformulas[#1]%
+ {\getparameters[\??mt][#1]%
+ \the\everysetuptextformulas}
+
+\protect \endinput
diff --git a/tex/context/base/math-frc.mkii b/tex/context/base/math-frc.mkii
new file mode 100644
index 000000000..fa319bc4a
--- /dev/null
+++ b/tex/context/base/math-frc.mkii
@@ -0,0 +1,66 @@
+%D \module
+%D [ file=math-frc,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Fractions,
+%D author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Fractions}
+
+\unprotect
+
+\def\exmthfont#1{\symbolicsizedfont#1\plusone{MathExtension}}
+
+\def\domthfrac#1#2#3#4#5#6#7%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #6$}%
+ \setbox2\hbox{$#1 #7$}%
+ \dimen0\wd0
+ \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
+ \setbox4\hbox to \dimen0{\exmthfont#2#3\leaders\hbox{#4}\hss#5}%
+ \mathord{\vcenter{{\offinterlineskip
+ \hbox to \dimen0{\hss\box0\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\copy4\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\box2\hss}}}}%
+ \endgroup}
+
+\def\domthsqrt#1#2#3#4#5%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #5$}%
+ \dimen0=1.05\ht0 \advance\dimen0 1pt \ht0 \dimen0
+ \dimen0=1.05\dp0 \advance\dimen0 1pt \dp0 \dimen0
+ \dimen0\wd0
+ \setbox4\hbox to \dimen0{\exmthfont#2\leaders\hbox{#3}\hfill#4}%
+ \delimitershortfall=0pt
+ \nulldelimiterspace=0pt
+ \setbox2\hbox{$\left\delimiter"0270370 \vrule height\ht0 depth \dp0 width0pt
+ \right.$}%
+ \mathord{\vcenter{\hbox{\copy2
+ \rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}%
+ \endgroup}
+
+\def\mthfrac#1#2#3#4#5{\mathchoice
+ {\domthfrac\displaystyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\textstyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptstyle \scriptface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}}
+
+\def\mthsqrt#1#2#3{\mathchoice
+ {\domthsqrt\displaystyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\textstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptscriptstyle\textface {#1}{#2}{#3}}}
+
+% temp here
+
+\protect \endinput
diff --git a/tex/context/base/math-frc.mkiv b/tex/context/base/math-frc.mkiv
new file mode 100644
index 000000000..d40306199
--- /dev/null
+++ b/tex/context/base/math-frc.mkiv
@@ -0,0 +1,209 @@
+%D \module
+%D [ file=math-frc,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Fractions,
+%D author={Hans Hagen \& Taco Hoekwater},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Fractions}
+
+\unprotect
+
+%D \macros
+%D {frac, xfrac, xxfrac}
+%D
+%D This is another one Tobias asked for. It replaces the
+%D primitive \type {\over}. We also take the opportunity to
+%D handle math style restoring, which makes sure units and
+%D chemicals come out ok.
+%D The \type {\frac} macro kind of replaces the awkward \type
+%D {\over} primitive. Say that we have the following formulas:
+%D
+%D \startbuffer[sample]
+%D test $\frac {1}{2}$ test $$1 + \frac {1}{2} = 1.5$$
+%D test $\xfrac {1}{2}$ test $$1 + \xfrac {1}{2} = 1.5$$
+%D test $\xxfrac{1}{2}$ test $$1 + \xxfrac{1}{2} = 1.5$$
+%D \stopbuffer
+%D
+%D \typebuffer[sample]
+%D
+%D With the most straightforward definitions, we get:
+%D
+%D \startbuffer[code]
+%D \def\dofrac#1#2#3{\relax\mathematics{{{#1{#2}}\over{#1{#3}}}}}
+%D
+%D \def\frac {\dofrac\mathstyle}
+%D \def\xfrac {\dofrac\scriptstyle}
+%D \def\xxfrac{\dofrac\scriptscriptstyle}
+%D \stopbuffer
+%D
+%D \typebuffer[code] \getbuffer[code,sample]
+%D
+%D Since this does not work well, we can try:
+%D
+%D \startbuffer[code]
+%D \def\xfrac #1#2{\hbox{$\dofrac\scriptstyle {#1}{#2}$}}
+%D \def\xxfrac#1#2{\hbox{$\dofrac\scriptscriptstyle{#1}{#2}$}}
+%D \stopbuffer
+%D
+%D \typebuffer[code] \getbuffer[code,sample]
+%D
+%D This for sure looks better than:
+%D
+%D \startbuffer[code]
+%D \def\xfrac #1#2{{\scriptstyle \dofrac\relax{#1}{#2}}}
+%D \def\xxfrac#1#2{{\scriptscriptstyle\dofrac\relax{#1}{#2}}}
+%D \stopbuffer
+%D
+%D \typebuffer[code] \getbuffer[code,sample]
+%D
+%D So we stick to the next definitions (watch the local
+%D overloading of \type {\xfrac}).
+
+% \def\dofrac#1#2#3{\relax\mathematics{{{#1{#2}}\over{#1{#3}}}}}
+
+\def\dofrac#1#2#3{\relax\mathematics{\Ustack{{#1{#2}}\normalover{#1{#3}}}}}
+\def\nofrac #1#2{\relax\mathematics{\Ustack{{#1}\normalover{#2}}}}
+
+% \chardef\mathfracmode=0 $\frac{1}{2}$
+% \chardef\mathfracmode=1 $\frac{1}{2}$
+% \chardef\mathfracmode=2 $\frac{1}{2}$
+% \chardef\mathfracmode=3 $\frac{1}{2}$
+% \chardef\mathfracmode=4 $\frac{1}{2}$
+% \chardef\mathfracmode=5 $\frac{1}{2}$
+
+\chardef\mathfracmode=0 % 0=auto, 1=displaystyle, 2=textstyle, 3=scriptstyle, 4=scriptscriptstyle, 5=mathstyle
+
+\unexpanded\def\frac
+ {\ifcase\mathfracmode
+ \expandafter\nofrac
+ \or
+ \expandafter\dofrac\expandafter\displaystyle
+ \or
+ \expandafter\dofrac\expandafter\textstyle
+ \or
+ \expandafter\dofrac\expandafter\scriptstyle
+ \or
+ \expandafter\dofrac\expandafter\scriptscriptstyle
+ \else
+ \expandafter\dofrac\expandafter\mathstyle
+ \fi}
+
+\unexpanded\def\xfrac#1#2%
+ {\begingroup
+ \let\xfrac\xxfrac
+ \dofrac\scriptstyle{#1}{#2}%
+ \endgroup}
+
+\unexpanded\def\xxfrac#1#2%
+ {\begingroup
+ \dofrac\scriptscriptstyle{#1}{#2}%
+ \endgroup}
+
+%D The \type {xx} variant looks still ugly, so maybe it's
+%D best to say:
+
+\unexpanded\def\xxfrac#1#2%
+ {\begingroup
+ \dofrac\scriptscriptstyle{#1}{\raise.25ex\hbox{$\scriptscriptstyle#2$}}%
+ \endgroup}
+
+%D Something low level for scientific calculator notation:
+
+\unexpanded\def\scinot#1#2%
+ {#1\times10^{#2}}
+
+%D The next macro, \type {\ch}, is \PPCHTEX\ aware. In
+%D formulas one can therefore best use \type {\ch} instead of
+%D \type {\chemical}, especially in fractions.
+
+% let's see who complains ... \mathstyle is now a primitive
+%
+% \unexpanded\def\ch#1%
+% {\ifundefined\@@chemicalletter
+% \mathstyle{\rm#1}%
+% \else
+% \dosetsubscripts
+% \mathstyle{\@@chemicalletter{#1}}%
+% \doresetsubscripts
+% \fi}
+
+% \unexpanded\def\ch#1%
+% {\ifundefined\@@chemicalletter
+% \mathematics{\rm#1}%
+% \else
+% \dosetsubscripts
+% \mathematics{\@@chemicalletter{#1}}%
+% \doresetsubscripts
+% \fi}
+
+%D \macros
+%D {/}
+%D
+%D Just to be sure, we restore the behavior of some typical
+%D math characters.
+
+\bgroup
+
+\catcode`\/=\@@other \global \let\normalforwardslash/
+\catcode`\/=\@@active \doglobal\appendtoks\let/\normalforwardslash\to\everymathematics
+
+\egroup
+
+% to be checked:
+
+\def\exmthfont#1{\symbolicsizedfont#1\plusone{MathExtension}}
+
+\def\domthfrac#1#2#3#4#5#6#7%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #6$}%
+ \setbox2\hbox{$#1 #7$}%
+ \dimen0\wd0
+ \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
+ \setbox4\hbox to \dimen0{\exmthfont#2#3\leaders\hbox{#4}\hss#5}%
+ \mathord{\vcenter{{\offinterlineskip
+ \hbox to \dimen0{\hss\box0\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\copy4\hss}%
+ \kern \ht4%
+ \hbox to \dimen0{\hss\box2\hss}}}}%
+ \endgroup}
+
+\def\domthsqrt#1#2#3#4#5%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox0\hbox{$#1 #5$}%
+ \dimen0=1.05\ht0 \advance\dimen0 1pt \ht0 \dimen0
+ \dimen0=1.05\dp0 \advance\dimen0 1pt \dp0 \dimen0
+ \dimen0\wd0
+ \setbox4\hbox to \dimen0{\exmthfont#2\leaders\hbox{#3}\hfill#4}%
+ \delimitershortfall=0pt
+ \nulldelimiterspace=0pt
+ \setbox2\hbox{$\left\delimiter"0270370 \vrule height\ht0 depth \dp0 width0pt
+ \right.$}%
+ \mathord{\vcenter{\hbox{\copy2
+ \rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}%
+ \endgroup}
+
+\def\mthfrac#1#2#3#4#5{\mathchoice
+ {\domthfrac\displaystyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\textstyle \textface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptstyle \scriptface {#1}{#2}{#3}{#4}{#5}}
+ {\domthfrac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}}
+
+\def\mthsqrt#1#2#3{\mathchoice
+ {\domthsqrt\displaystyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\textstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptstyle \textface {#1}{#2}{#3}}
+ {\domthsqrt\scriptscriptstyle\textface {#1}{#2}{#3}}}
+
+% temp here
+
+\protect \endinput
diff --git a/tex/context/base/math-ini.lua b/tex/context/base/math-ini.lua
index 73b8852b3..5a6889410 100644
--- a/tex/context/base/math-ini.lua
+++ b/tex/context/base/math-ini.lua
@@ -1,4 +1,4 @@
-if not modules then modules = { } end modules ['math-ini'] = {
+if not modules then modules = { } end modules ['math-ext'] = {
version = 1.001,
comment = "companion to math-ini.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -6,443 +6,249 @@ if not modules then modules = { } end modules ['math-ini'] = {
license = "see context related readme files"
}
---[[ldx--
-
Math definitions. This code may move.
---ldx]]--
-
-- if needed we can use the info here to set up xetex definition files
-- the "8000 hackery influences direct characters (utf) as indirect \char's
+local utf = unicode.utf8
+
local texsprint, format, utfchar, utfbyte = tex.sprint, string.format, utf.char, utf.byte
-mathematics = mathematics or { }
-mathematics.data = mathematics.data or { }
-mathematics.slots = mathematics.slots or { }
+local trace_defining = false trackers.register("math.defining", function(v) trace_defining = v end)
-mathematics.classes = {
- ord = 0, -- mathordcomm mathord
- op = 1, -- mathopcomm mathop
- bin = 2, -- mathbincomm mathbin
- rel = 3, -- mathrelcomm mathrel
- open = 4, -- mathopencomm mathopen
- close = 5, -- mathclosecomm mathclose
- punct = 6, -- mathpunctcomm mathpunct
- alpha = 7, -- mathalphacomm firstofoneargument
- accent = 8,
- radical = 9,
- inner = 0, -- mathinnercomm mathinner
- nothing = 0, -- mathnothingcomm firstofoneargument
- choice = 0, -- mathchoicecomm @@mathchoicecomm
- box = 0, -- mathboxcomm @@mathboxcomm
- limop = 1, -- mathlimopcomm @@mathlimopcomm
- nolop = 1, -- mathnolopcomm @@mathnolopcomm
-}
+mathematics = mathematics or { }
-mathematics.classes.alphabetic = mathematics.classes.alpha
-mathematics.classes.unknown = mathematics.classes.nothing
-mathematics.classes.punctuation = mathematics.classes.punct
-mathematics.classes.normal = mathematics.classes.nothing
-mathematics.classes.opening = mathematics.classes.open
-mathematics.classes.closing = mathematics.classes.close
-mathematics.classes.binary = mathematics.classes.bin
-mathematics.classes.relation = mathematics.classes.rel
-mathematics.classes.fence = mathematics.classes.unknown
-mathematics.classes.diacritic = mathematics.classes.accent
-mathematics.classes.large = mathematics.classes.op
-mathematics.classes.variable = mathematics.classes.alphabetic
-mathematics.classes.number = mathematics.classes.nothing
+mathematics.extrabase = 0xFE000 -- here we push some virtuals
+mathematics.privatebase = 0xFF000 -- here we push the ex
-mathematics.families = {
- mr = 0, bs = 8,
- mi = 1, bi = 9,
- sy = 2, sc = 10,
- ex = 3, tf = 11,
- it = 4, ma = 12,
- sl = 5, mb = 13,
- bf = 6, mc = 14,
- nn = 7, md = 15,
+local families = {
+ tf = 0, it = 1, sl = 2, bf = 3, bi = 4, bs = 5, -- virtual fonts or unicode otf
}
-mathematics.families.letters = mathematics.families.mr
-mathematics.families.numbers = mathematics.families.mr
-mathematics.families.variables = mathematics.families.mi
-mathematics.families.operators = mathematics.families.sy
-mathematics.families.lcgreek = mathematics.families.mi
-mathematics.families.ucgreek = mathematics.families.mr
-mathematics.families.vargreek = mathematics.families.mi
-mathematics.families.mitfamily = mathematics.families.mi
-mathematics.families.calfamily = mathematics.families.sy
-
-mathematics.families[0] = mathematics.families.mr
-mathematics.families[1] = mathematics.families.mi
-mathematics.families[2] = mathematics.families.sy
-mathematics.families[3] = mathematics.families.ex
+local classes = {
+ ord = 0, -- mathordcomm mathord
+ op = 1, -- mathopcomm mathop
+ bin = 2, -- mathbincomm mathbin
+ rel = 3, -- mathrelcomm mathrel
+ open = 4, -- mathopencomm mathopen
+ close = 5, -- mathclosecomm mathclose
+ punct = 6, -- mathpunctcomm mathpunct
+ alpha = 7, -- mathalphacomm firstofoneargument
+ accent = 8, -- class 0
+ radical = 9,
+ xaccent = 10, -- class 3
+ topaccent = 11, -- class 0
+ botaccent = 12, -- class 0
+ under = 13,
+ over = 14,
+ delimiter = 15,
+ inner = 0, -- mathinnercomm mathinner
+ nothing = 0, -- mathnothingcomm firstofoneargument
+ choice = 0, -- mathchoicecomm @@mathchoicecomm
+ box = 0, -- mathboxcomm @@mathboxcomm
+ limop = 1, -- mathlimopcomm @@mathlimopcomm
+ nolop = 1, -- mathnolopcomm @@mathnolopcomm
+}
-function mathematics.mathcode(target,class,family,slot)
- if class <= 7 then
- return ("\\omathcode%s=\"%X%02X%04X "):format(target,class,family,slot)
- end
+mathematics.families = families
+mathematics.classes = classes
+
+classes.alphabetic = classes.alpha
+classes.unknown = classes.nothing
+classes.default = classes.nothing
+classes.punctuation = classes.punct
+classes.normal = classes.nothing
+classes.opening = classes.open
+classes.closing = classes.close
+classes.binary = classes.bin
+classes.relation = classes.rel
+classes.fence = classes.unknown
+classes.diacritic = classes.accent
+classes.large = classes.op
+classes.variable = classes.alphabetic
+classes.number = classes.alphabetic
+
+-- there will be proper functions soon (and we will move this code in-line)
+
+local function delcode(target,family,slot)
+ return format('\\Udelcode%s="%X "%X ',target,family,slot)
+end
+local function mathchar(class,family,slot)
+ return format('\\Umathchar "%X "%X "%X ',class,family,slot)
+end
+local function mathaccent(class,family,slot)
+ return format('\\Umathaccent "%X "%X "%X ',0,family,slot) -- no class
+end
+local function delimiter(class,family,slot)
+ return format('\\Udelimiter "%X "%X "%X ',class,family,slot)
end
-function mathematics.delcode(target,small_family,small_slot,large_family,large_slot)
- return ("\\odelcode%s=\"%02X%04X\"%02X%04X "):format(target,small_family,small_slot,large_family,large_slot)
+local function radical(family,slot)
+ return format('\\Uradical "%X "%X ',family,slot)
end
-function mathematics.radical(small_family,small_slot,large_family,large_slot)
- return ("\\radical%s=\"%02X%04X%\"02X%04X "):format(target,small_family,small_slot,large_family,large_slot)
+local function mathchardef(name,class,family,slot)
+ return format('\\Umathchardef\\%s "%X "%X "%X ',name,class,family,slot)
end
-function mathematics.mathchar(class,family,slot)
- return ("\\omathchar\"%X%02X%04X "):format(class,family,slot)
+local function mathcode(target,class,family,slot)
+ return format('\\Umathcode%s="%X "%X "%X ',target,class,family,slot)
end
-function mathematics.mathaccent(class,family,slot)
- return ("\\omathaccent\"%X%02X%04X "):format(class,family,slot)
+local function mathtopaccent(class,family,slot)
+ return format('\\Umathaccent "%X "%X "%X ',0,family,slot) -- no class
end
-function mathematics.delimiter(class,family,slot,largefamily,largeslot)
- return ("\\odelimiter\"%X%02X%04X\"%02X%04X "):format(class,family,slot,largefamily,largeslot)
+local function mathbotaccent(class,family,slot)
+ return format('\\Umathbotaccent "%X "%X "%X ',0,family,slot) -- no class
end
-function mathematics.mathchardef(name,class,family,slot) -- we can avoid this one
- return ("\\omathchardef\\%s\"%X%02X%04X "):format(name,class,family,slot)
+local function mathtopdelimiter(class,family,slot)
+ return format('\\Uoverdelimiter "%X "%X ',0,family,slot) -- no class
+end
+local function mathbotdelimiter(class,family,slot)
+ return format('\\Uunderdelimiter "%X "%X ',0,family,slot) -- no class
end
-function mathematics.setmathsymbol(name,class,family,slot,largefamily,largeslot,unicode)
- class = mathematics.classes[class] or class -- no real checks needed
- family = mathematics.families[family] or family
- -- \unexpanded ? \relax needed for the codes?
- local classes = mathematics.classes
- if largefamily and largeslot then
- largefamily = mathematics.families[largefamily] or largefamily
- if class == classes.radical then
- texsprint(("\\unexpanded\\xdef\\%s{%s }"):format(name,mathematics.radical(class,family,slot,largefamily,largeslot)))
- elseif class == classes.open or class == classes.close then
- texsprint(("\\unexpanded\\xdef\\%s{%s}"):format(name,mathematics.delimiter(class,family,slot,largefamily,largeslot)))
- end
- elseif class == classes.accent then
- texsprint(("\\unexpanded\\xdef\\%s{%s }"):format(name,mathematics.mathaccent(class,family,slot)))
- elseif unicode then
- -- beware, open/close and other specials should not end up here
- local ch = utfchar(unicode)
- if characters.filters.utf.private.escapes[ch] then
- texsprint(("\\xdef\\%s{\\char%s }"):format(name,unicode))
- else
- texsprint(("\\xdef\\%s{%s}"):format(name,ch))
- end
+local escapes = characters.filters.utf.private.escapes
+
+local function setmathsymbol(name,class,family,slot)
+ if class == classes.accent then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathaccent(class,family,slot)))
+ elseif class == classes.topaccent then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathtopaccent(class,family,slot)))
+ elseif class == classes.botaccent then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathbotaccent(class,family,slot)))
+ elseif class == classes.over then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathtopdelimiter(class,family,slot)))
+ elseif class == classes.under then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathbotdelimiter(class,family,slot)))
+ elseif class == classes.open or class == classes.close then
+ texsprint(delcode(slot,family,slot))
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,delimiter(class,family,slot)))
+ elseif class == classes.delimiter then
+ texsprint(delcode(slot,family,slot))
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,delimiter(0,family,slot)))
+ elseif class == classes.radical then
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,radical(family,slot)))
else
- texsprint(mathematics.mathchardef(name,class,family,slot))
+ -- beware, open/close and other specials should not end up here
+--~ local ch = utfchar(slot)
+--~ if escapes[ch] then
+--~ texsprint(format("\\xdef\\%s{\\char%s }",name,slot))
+--~ else
+ texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathchar(class,family,slot)))
+--~ end
end
end
--- direct sub call
-
-function mathematics.setmathcharacter(target,class,family,slot,largefamily,largeslot)
- class = mathematics.classes[class] or class -- no real checks needed
- family = mathematics.families[family] or family
- if largefamily and largeslot then
- largefamily = mathematics.families[largefamily] or largefamily
- texsprint(mathematics.delcode(target,family,slot,largefamily,largeslot))
- else
- texsprint(mathematics.mathcode(target,class,family,slot))
+local function setmathcharacter(class,family,slot,unicode,firsttime)
+ if not firsttime and class <= 7 then
+ texsprint(mathcode(slot,class,family,unicode or slot))
end
end
--- definitions (todo: expand commands to utf instead of codes)
-
-mathematics.trace = false -- false
+local function setmathsynonym(class,family,slot,unicode,firsttime)
+ if not firsttime and class <= 7 then
+ texsprint(mathcode(slot,class,family,unicode))
+ end
+ if class == classes.open or class == classes.close then
+ texsprint(delcode(slot,family,unicode))
+ end
+end
-function mathematics.define(slots)
- local slots = slots or mathematics.slots.current
- local setmathcharacter = mathematics.setmathcharacter
- local setmathsymbol = mathematics.setmathsymbol
- local trace = mathematics.trace
- local function report(k,m,c,f,i,fe,ie)
- local mc = mathematics.classes[m] or m
- if fe then
- logs.report("mathematics","a - %s:%s 0x%05X -> %s -> %s %s (%s %s) -> %s",mc,m,k,c,f,i,fe,ie,utfchar(k))
- elseif c then
- logs.report("mathematics","b - %s:%s 0x%05X -> %s -> %s %s -> %s",mc,m,k,c,f,i,utfchar(k))
- else
- logs.report("mathematics","c - %s:%s 0x%05X -> %s %s -> %s",mc,m,k,f,i,utfchar(k))
- end
+local function report(class,family,unicode,name)
+ local nametype = type(name)
+ if nametype == "string" then
+ logs.report("mathematics","%s:%s %s U+%05X (%s) => %s",classname,class,family,unicode,utfchar(unicode),name)
+ elseif nametype == "number" then
+ logs.report("mathematics","%s:%s %s U+%05X (%s) => U+%05X",classname,class,family,unicode,utfchar(unicode),name)
+ else
+ logs.report("mathematics","%s:%s %s U+%05X (%s)", classname,class,family,unicode,utfchar(unicode))
end
- for k,v in pairs(characters.data) do
- local m = v.mathclass
- -- i need to clean this up a bit
- if m then
- local c = v.mathname
- if c == false then
- -- no command
- local s = slots[k]
- if s then
- local f, i, fe, ie = s[1], s[2], s[3], s[4]
- if trace then
- report(k,m,c,f,i,fe,ie)
- end
- setmathcharacter(k,m,f,i,fe,ie)
+end
+
+-- there will be a combined \(math)chardef
+
+function mathematics.define(slots,family)
+ family = family or 0
+ family = families[family] or family
+ local data = characters.data
+ for unicode, character in next, data do
+ local symbol = character.mathsymbol
+ if symbol then
+ local other = data[symbol]
+ local class = other.mathclass
+ if class then
+ class = classes[class] or class -- no real checks needed
+ if trace_defining then
+ report(class,family,unicode,symbol)
end
- elseif c then
- local s = slots[k]
- if s then
- local f, i, fe, ie = s[1], s[2], s[3], s[4]
- if trace then
- report(k,m,c,f,i,fe,ie)
+ setmathsynonym(class,family,unicode,symbol)
+ end
+ local spec = other.mathspec
+ if spec then
+ for i, m in next, spec do
+ local class = m.class
+ if class then
+ class = classes[class] or class -- no real checks needed
+ setmathsynonym(class,family,unicode,symbol,i)
end
- setmathsymbol(c,m,f,i,fe,ie,k)
- setmathcharacter(k,m,f,i,fe,ie)
end
- elseif v.contextname then
- local s = slots[k]
- local c = v.contextname
- if s then
- local f, i, fe, ie = s[1], s[2], s[3], s[4]
- if trace then
- report(k,m,c,f,i,fe,ie)
+ end
+ end
+ local mathclass = character.mathclass
+ local mathspec = character.mathspec
+ if mathspec then
+ for i, m in next, mathspec do
+ local name = m.name
+ local class = m.class
+ if not class then
+ class = mathclass
+ elseif not mathclass then
+ mathclass = class
+ end
+ if class then
+ class = classes[class] or class -- no real checks needed
+ if name then
+ if trace_defining then
+ report(class,family,unicode,name)
+ end
+ setmathsymbol(name,class,family,unicode)
+ -- setmathcharacter(class,family,unicode,unicode,i)
+ else
+ name = class == classes.variable or class == classes.number and character.adobename
+ if name then
+ if trace_defining then
+ report(class,family,unicode,name)
+ end
+ -- setmathcharacter(class,family,unicode,unicode,i)
+ end
end
- -- todo: mathortext
- setmathsymbol(c,m,f,i,fe,ie,k)
- setmathcharacter(k,m,f,i,fe,ie)
+ setmathcharacter(class,family,unicode,unicode,i)
end
+ end
+ end
+ if mathclass then
+ local name = character.mathname
+ local class = classes[mathclass] or mathclass -- no real checks needed
+ if name == false then
+ if trace_defining then
+ report(class,family,unicode,name)
+ end
+ setmathcharacter(class,family,unicode)
else
- local a = v.adobename
- if a and m then
- local s, f, i, fe, ie = slots[k], nil, nil, nil, nil
- if s then
- f, i, fe, ie = s[1], s[2], s[3], s[4]
- elseif m == "variable" then
- f, i = mathematics.families.variables, k
- elseif m == "number" then
- f, i = mathematics.families.numbers, k
+ name = name or character.contextname
+ if name then
+ if trace_defining then
+ report(class,family,unicode,name)
end
- if f and i then
- if trace then
- report(k,m,a,f,i,fe,ie)
- end
- setmathcharacter(k,m,f,i,fe,ie)
+ setmathsymbol(name,class,family,unicode)
+ else
+ if trace_defining then
+ report(class,family,unicode,character.adobename)
end
end
+ setmathcharacter(class,family,unicode,unicode)
end
end
end
end
--- temporary here: will become separate
-
--- maybe we should define a nice virtual font so that we have
--- just the base n families repeated for different styles
-
-mathematics.slots.traditional = {
-
- [0x03B1] = { "lcgreek", 0x0B }, -- alpha
- [0x03B2] = { "lcgreek", 0x0C }, -- beta
- [0x03B3] = { "lcgreek", 0x0D }, -- gamma
- [0x03B4] = { "lcgreek", 0x0E }, -- delta
- [0x03B5] = { "lcgreek", 0x0F }, -- epsilon
- [0x03B6] = { "lcgreek", 0x10 }, -- zeta
- [0x03B7] = { "lcgreek", 0x11 }, -- eta
- [0x03B8] = { "lcgreek", 0x12 }, -- theta
- [0x03B9] = { "lcgreek", 0x13 }, -- iota
- [0x03BA] = { "lcgreek", 0x14 }, -- kappa
- [0x03BB] = { "lcgreek", 0x15 }, -- lambda
- [0x03BC] = { "lcgreek", 0x16 }, -- mu
- [0x03BD] = { "lcgreek", 0x17 }, -- nu
- [0x03BE] = { "lcgreek", 0x18 }, -- xi
- [0x03BF] = { "lcgreek", 0x6F }, -- omicron
- [0x03C0] = { "lcgreek", 0x19 }, -- pi
- [0x03C1] = { "lcgreek", 0x1A }, -- rho
--- [0x03C2] = { "lcgreek", 0x00 }, -- varsigma
- [0x03C3] = { "lcgreek", 0x1B }, -- sigma
- [0x03C4] = { "lcgreek", 0x1C }, -- tau
- [0x03C5] = { "lcgreek", 0x1D }, -- upsilon
--- [0x03C6] = { "lcgreek", 0x1E }, -- varphi
- [0x03C7] = { "lcgreek", 0x1F }, -- chi
- [0x03C8] = { "lcgreek", 0x20 }, -- psi
- [0x03C9] = { "lcgreek", 0x21 }, -- omega
-
- [0x0391] = { "ucgreek", 0x41 }, -- Alpha
- [0x0392] = { "ucgreek", 0x42 }, -- Beta
- [0x0393] = { "ucgreek", 0x00 }, -- Gamma
- [0x0394] = { "ucgreek", 0x01 }, -- Delta
- [0x0395] = { "ucgreek", 0x45 }, -- Epsilon
- [0x0396] = { "ucgreek", 0x5A }, -- Zeta
- [0x0397] = { "ucgreek", 0x48 }, -- Eta
- [0x0398] = { "ucgreek", 0x02 }, -- Theta
- [0x0399] = { "ucgreek", 0x49 }, -- Iota
- [0x039A] = { "ucgreek", 0x4B }, -- Kappa
- [0x039B] = { "ucgreek", 0x03 }, -- Lambda
- [0x039C] = { "ucgreek", 0x4D }, -- Mu
- [0x039D] = { "ucgreek", 0x4E }, -- Nu
- [0x039E] = { "ucgreek", 0x04 }, -- Xi
- [0x039F] = { "ucgreek", 0x4F }, -- Omicron
- [0x03A0] = { "ucgreek", 0x05 }, -- Pi
- [0x03A1] = { "ucgreek", 0x52 }, -- Rho
- [0x03A3] = { "ucgreek", 0x06 }, -- Sigma
- [0x03A4] = { "ucgreek", 0x54 }, -- Tau
- [0x03A5] = { "ucgreek", 0x07 }, -- Upsilon
- [0x03A6] = { "ucgreek", 0x08 }, -- Phi
- [0x03A7] = { "ucgreek", 0x58 }, -- Chi
- [0x03A8] = { "ucgreek", 0x09 }, -- Psi
- [0x03A9] = { "ucgreek", 0x0A }, -- Omega
-
- [0x03F5] = { "vargreek", 0x22 }, -- varepsilon
- [0x03D1] = { "vargreek", 0x23 }, -- vartheta
- [0x03D6] = { "vargreek", 0x24 }, -- varpi
- [0x03F1] = { "vargreek", 0x25 }, -- varrho
- [0x03C2] = { "vargreek", 0x26 }, -- varsigma
-
- -- varphi is part of the alphabet, contrary to the other var*s'
-
- [0x03C6] = { "vargreek", 0x27 }, -- varphi
- [0x03D5] = { "lcgreek", 0x1E }, -- phi
-
- [0x03F0] = { "lcgreek", 0x14 }, -- varkappa, not in tex fonts
-
- [0x0021] = { "mr", 0x21 }, -- !
- [0x0028] = { "mr", 0x28 }, -- (
- [0x0029] = { "mr", 0x29 }, -- )
- [0x002A] = { "sy", 0x03 }, -- *
- [0x002B] = { "mr", 0x2B }, -- +
- [0x002C] = { "mi", 0x3B }, -- ,
- [0x002D] = { "sy", 0x00 }, -- -
- [0x2212] = { "sy", 0x00 }, -- -
- [0x002E] = { "mi", 0x3A }, -- .
- [0x002F] = { "mi", 0x3D }, -- /
- [0x003A] = { "mr", 0x3A }, -- :
- [0x003B] = { "mr", 0x3B }, -- ;
- [0x003C] = { "mi", 0x3C }, -- <
- [0x003D] = { "mr", 0x3D }, -- =
- [0x003E] = { "mi", 0x3E }, -- >
- [0x003F] = { "mr", 0x3F }, -- ?
- [0x005C] = { "sy", 0x6E }, -- \
- [0x007B] = { "sy", 0x66 }, -- {
- [0x007C] = { "sy", 0x6A }, -- |
- [0x007D] = { "sy", 0x67 }, -- }
- [0x00AC] = { "sy", 0x3A }, -- lnot
- [0x00B1] = { "sy", 0x06 }, -- pm
- [0x00B7] = { "sy", 0x01 }, -- cdot
- [0x00D7] = { "sy", 0x02 }, -- times
- [0x00F7] = { "sy", 0x04 }, -- div
- [0x2022] = { "sy", 0x0F }, -- bullet
- [0x2111] = { "sy", 0x3D }, -- Im
- [0x2118] = { "mi", 0x7D }, -- wp
- [0x211C] = { "sy", 0x3C }, -- Re
- [0x2190] = { "sy", 0x20 }, -- leftarrow
- [0x2191] = { "sy", 0x22, "ex", 0x78 }, -- uparrow
- [0x2192] = { "sy", 0x21 }, -- rightarrow
- [0x2193] = { "sy", 0x23, "ex", 0x79 }, -- downarrow
- [0x2194] = { "sy", 0x24 }, -- leftrightarrow
- [0x2195] = { "sy", 0x6C, "ex", 0x3F }, -- updownarrow
- [0x2196] = { "sy", 0x2D }, -- nwarrow
- [0x2197] = { "sy", 0x25 }, -- nearrow
- [0x2198] = { "sy", 0x2E }, -- swarrow
- [0x2199] = { "sy", 0x26 }, -- searrow
- [0x21D0] = { "sy", 0x28 }, -- Leftarrow
- [0x21D1] = { "sy", 0x6C, "ex", 0x7E }, -- Uparrow
- [0x21D2] = { "sy", 0x29 }, -- Rightarrow
- [0x21D3] = { "sy", 0x2B, "ex", 0x7F }, -- Downarrow
- [0x21D4] = { "sy", 0x2C }, -- Leftrightarrow
- [0x21D5] = { "sy", 0x6D, "ex", 0x77 }, -- Updownarrow
- [0x2135] = { "sy", 0x40 }, -- aleph
- [0x2113] = { "mi", 0x60 }, -- ell
--- ...
- [0x2200] = { "sy", 0x38 }, -- forall
--- [0x2201] = { "sy", 0x00 }, -- complement
- [0x2202] = { "mi", 0x40 }, -- partial
- [0x2203] = { "sy", 0x39 }, -- exists
--- [0x2204] = { "sy", 0x00 }, -- not exists
- [0x2205] = { "sy", 0x3B }, -- empty set
--- [0x2206] = { "sy", 0x00 }, -- increment
- [0x2207] = { "sy", 0x72 }, -- nabla
- [0x2208] = { "sy", 0x32 }, -- in
- [0x2209] = { "sy", 0x33 }, -- ni
- [0x220F] = { "ex", 0x51 }, -- prod
- [0x2210] = { "ex", 0x60 }, -- coprod
- [0x2211] = { "ex", 0x50 }, -- sum
--- [0x2212] = { "sy", 0x00 }, -- -
- [0x2213] = { "sy", 0x07 }, -- mp
- [0x2215] = { "sy", 0x3D }, -- / AM: Not sure
- [0x2216] = { "sy", 0x6E }, -- setminus
- [0x2217] = { "sy", 0x03 }, -- *
- [0x2218] = { "sy", 0x0E }, -- circ
- [0x2219] = { "sy", 0x0F }, -- bullet
--- [0x221A] = { "sy", 0x70, "ex", 0x70 }, -- sqrt. AM: Check surd??
--- ...
- [0x221D] = { "sy", 0x2F }, -- propto
- [0x221E] = { "sy", 0x31 }, -- infty
- [0x2225] = { "sy", 0x6B }, -- parallel
- [0x2227] = { "sy", 0x5E }, -- wedge
- [0x2228] = { "sy", 0x5F }, -- vee
- [0x2229] = { "sy", 0x5C }, -- cap
- [0x222A] = { "sy", 0x5B }, -- cup
- [0x222B] = { "ex", 0x52 }, -- intop
--- ... other integrals
- [0x2236] = { "mr", 0x3A }, -- colon
- [0x223C] = { "sy", 0x18 }, -- sim
- [0x2243] = { "sy", 0x27 }, -- simeq
- [0x2248] = { "sy", 0x19 }, -- approx
- [0x225C] = { "ma", 0x2C }, -- triangleq
- [0x2261] = { "sy", 0x11 }, -- equiv
- [0x2264] = { "sy", 0x14 }, -- leq
- [0x2265] = { "sy", 0x15 }, -- geq
- [0x226A] = { "sy", 0x1C }, -- ll
- [0x226B] = { "sy", 0x1D }, -- gg
- [0x227A] = { "sy", 0x1E }, -- prec
- [0x227B] = { "sy", 0x1F }, -- succ
--- [0x227C] = { "sy", 0x16 }, -- preceq, AM:No see 2AAF
--- [0x227D] = { "sy", 0x17 }, -- succeq, AM:No see 2AB0
- [0x2282] = { "sy", 0x1A }, -- subset
- [0x2283] = { "sy", 0x1B }, -- supset
- [0x2286] = { "sy", 0x12 }, -- subseteq
- [0x2287] = { "sy", 0x13 }, -- supseteq
- [0x2293] = { "sy", 0x75 }, -- sqcap
- [0x2294] = { "sy", 0x74 }, -- sqcup
- [0x2295] = { "sy", 0x08 }, -- oplus
- [0x2296] = { "sy", 0x09 }, -- ominus
- [0x2297] = { "sy", 0x0A }, -- otimes
- [0x2298] = { "sy", 0x0B }, -- oslash
- [0x2299] = { "sy", 0x0C }, -- odot
- [0x22A4] = { "sy", 0x3E }, -- top
- [0x22A5] = { "sy", 0x3F }, -- bop
- [0x22C0] = { "ex", 0x56 }, -- bigwedge
- [0x22C1] = { "ex", 0x57 }, -- bigvee
- [0x22C2] = { "ex", 0x54 }, -- bigcap
- [0x22C3] = { "ex", 0x53 }, -- bigcup
- [0x22C4] = { "sy", 0x05 }, -- diamond
- [0x22C5] = { "sy", 0x01 }, -- cdot
- [0x22C6] = { "mi", 0x3F }, -- star
- [0x25B3] = { "sy", 0x34 }, -- triangle up
-
- [0x2220] = { "ma", 0x5C }, -- angle
- [0x2221] = { "ma", 0x5D }, -- measuredangle
- [0x2222] = { "ma", 0x5E }, -- sphericalangle
-
- [0x2245] = { "ma", 0x75 }, -- aproxeq
-
- [0x1D6A4] = { "mi", 0x7B }, -- imath
- [0x1D6A5] = { "mi", 0x7C }, -- jmath
-
- [0x0028] = { "mr", 0x28, "ex", 0x00 }, -- (
- [0x0029] = { "mr", 0x29, "ex", 0x01 }, -- )
- [0x002F] = { "mr", 0x2F, "ex", 0x0E }, -- /
- [0x003C] = { "sy", 0x3C, "ex", 0x0A }, -- <
- [0x003E] = { "sy", 0x3E, "ex", 0x0B }, -- >
- [0x005B] = { "mr", 0x5B, "ex", 0x02 }, -- [
- [0x005D] = { "mr", 0x5D, "ex", 0x03 }, -- ]
- [0x007C] = { "sy", 0x6A, "ex", 0x0C }, -- |
- [0x005C] = { "sy", 0x6E, "ex", 0x0F }, -- \
- [0x007B] = { "sy", 0x66, "ex", 0x08 }, -- {
- [0x007D] = { "sy", 0x67, "ex", 0x09 }, -- }
-
- [0x005E] = { "mr", 0x5E, "ex", 0x62 }, -- widehat
- [0x007E] = { "mr", 0x7E, "ex", 0x65 }, -- widetilde
-
- [0x2AAF] = { "sy", 0x16 }, -- preceq
- [0x2AB0] = { "sy", 0x17 }, -- succeq
-
- [0x2145] = { "mr", 0x44 },
- [0x2146] = { "mr", 0x64 },
- [0x2147] = { "mr", 0x65 },
-
- -- please let lm/gypre math show up soon
-
-}
-
-mathematics.slots.current = mathematics.slots.traditional
+-- needed for mathml analysis
function mathematics.utfmathclass(chr, default)
local cd = characters.data[utfbyte(chr)]
@@ -473,3 +279,42 @@ function mathematics.register_xml_entities()
end
end
end
+
+-- helpers
+
+function mathematics.big(tfmdata,unicode,n)
+ local t = tfmdata.characters
+ local c = t[unicode]
+ if c then
+ local next = c.next
+ while next do
+ if n <= 1 then
+ return next
+ else
+ n = n - 1
+ next = t[next].next
+ end
+ end
+ end
+ return unicode
+end
+
+-- plugins
+
+function mathematics.scaleparameters(t,tfmtable,delta)
+ local math_parameters = tfmtable.math_parameters
+ if math_parameters and next(math_parameters) then
+ delta = delta or 1
+ local _, mp = mathematics.dimensions(math_parameters)
+ for name, value in next, mp do
+ if name ~= "RadicalDegreeBottomRaisePercent" then
+ mp[name] = delta*value
+ else
+ mp[name] = value
+ end
+ end
+ t.MathConstants = mp
+ end
+end
+
+table.insert(fonts.tfm.mathactions,mathematics.scaleparameters)
diff --git a/tex/context/base/math-ini.mkii b/tex/context/base/math-ini.mkii
index 6b0cd71d7..7d87fb365 100644
--- a/tex/context/base/math-ini.mkii
+++ b/tex/context/base/math-ini.mkii
@@ -1,14 +1,681 @@
%D \module
%D [ file=math-ini,
-%D version=2008.01.02,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=Math Initializations,
-%D author=Hans Hagen,
+%D version=2001.04.12,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Initializations,
+%D author={Hans Hagen \& Taco Hoekwater},
%D date=\currentdate,
-%D copyright=PRAGMA]
+%D copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\endinput
+\writestatus{loading}{ConTeXt Math Macros / Initializations}
+
+% todo: make all definitions global since file loaded only once
+
+%D This module provides namespaces for math fonts, thereby
+%D permitting mixed usage of math fonts. Although not strictly
+%D needed, we also provide a family name mapping mechanism as
+%D used in the (original) AMS math definition files, but here
+%D these names can recursively be remapped and if needed,
+%D dynamically be changed. We've tried to minimize the number
+%D of definition commands and use plain \TEX\ definitions as
+%D fallback. We've tried to follow a couple of conventions
+%D from plain and AMS math in order to achieve backward
+%D compatinility. We also kept an eye on future usage of these
+%D modules in the perspective of MathML and unicode fonts.
+
+\unprotect
+
+\def\@ml@{@ml@} % math list (used for collection)
+\def\@mf@{@mf@} % math family
+%def\@mh@{@mh@} % math handler (not used)
+\def\@mt@{@mt@} % math token
+\def\@mc@{@mc@} % math collection
+
+\def\@@mathlimopcomm#1{\mathop{#1}} %no \limits
+\def\@@mathnolopcomm#1{\mathop{#1}\nolimits}
+\def\@@mathboxcomm #1{\dontleavehmode\hbox{$\mathsurround\zeropoint#1$}}
+
+\chardef\mathordcode = 0 \let\mathordcomm \mathord
+\chardef\mathopcode = 1 \let\mathopcomm \mathop
+\chardef\mathbincode = 2 \let\mathbincomm \mathbin
+\chardef\mathrelcode = 3 \let\mathrelcomm \mathrel
+\chardef\mathopencode = 4 \let\mathopencomm \mathopen
+\chardef\mathclosecode = 5 \let\mathclosecomm \mathclose
+\chardef\mathpunctcode = 6 \let\mathpunctcomm \mathpunct
+\chardef\mathalphacode = 7 \let\mathalphacomm \firstofoneargument
+\chardef\mathinnercode = 0 \let\mathinnercomm \mathinner
+\chardef\mathnothingcode= 0 \let\mathnothingcomm \firstofoneargument
+\chardef\mathlimopcode = 1 \let\mathlimopcomm \@@mathlimopcomm
+\chardef\mathnolopcode = 1 \let\mathnolopcomm \@@mathnolopcomm
+\chardef\mathchoicecode = 0 \let\mathchoicecomm \@@mathchoicecomm
+\chardef\mathboxcode = 0 \let\mathboxcomm \@@mathboxcomm
+
+\chardef\mathaccentcode = 8
+\chardef\mathradicalcode= 9
+
+\def\@@mathchoicecomm#1{[todo #1]}
+
+\def\puremathcode#1{\the\csname math#1code\endcsname}
+\def\puremathcomm#1{\csname math#1comm\endcsname}
+
+\newif\iftracemathcollection
+
+% Simple variant:
+%
+% \def\dohandlemathtoken#1%
+% {\csname\@mt@
+% \ifcsname\@mt@\mathcollection#1\endcsname
+% \mathcollection
+% \else\ifcsname\@mt@\nomathcollection#1\endcsname
+% \nomathcollection
+% \fi\fi
+% #1\endcsname}
+
+%D Because a command can have a different meaning in math
+%D and in text mode, we provide a selector. We also provide
+%D the pure alternatives as \type {\mathcharacter} and \type
+%D {\textcharacter}.
+
+% \ifx\dohandlecommand\undefined \wait \fi % troubles ! but not in mkiv so ...
+
+\let\mathcharacter\dohandlemathtoken
+\let\textcharacter\dohandlecommand % better \dohandletexttoken
+
+% More clever layout:
+%
+% \def\dohandlemathtoken#1%
+% {\csname
+% \ifmmode
+% \ifcsname\@mt@\mathcollection#1\endcsname
+% \@mt@\mathcollection
+% \else\ifcsname\@mt@\nomathcollection#1\endcsname
+% \@mt@\nomathcollection
+% \else\ifcsname\characterencoding#1\endcsname
+% \characterencoding
+% \else
+% \nocharacterencoding
+% \fi\fi\fi
+% \else
+% \ifcsname\characterencoding#1\endcsname
+% \characterencoding
+% \else
+% \nocharacterencoding
+% \fi
+% \fi
+% #1\endcsname}
+%
+% fallback to math when in text mode (handy for unicode vectors)
+
+\def\dohandlemathtoken#1%
+ {\csname
+ \ifmmode
+ \ifcsname\@mt@\mathcollection#1\endcsname
+ \@mt@\mathcollection
+ \else\ifcsname\@mt@\nomathcollection#1\endcsname
+ \@mt@\nomathcollection
+ \else\ifcsname\characterencoding#1\endcsname
+ \characterencoding
+ \else
+ \nocharacterencoding
+ \fi\fi\fi
+ \else
+ \ifcsname\characterencoding#1\endcsname
+ \characterencoding
+ \else\ifcsname\nocharacterencoding#1\endcsname
+ \nocharacterencoding
+ \else\ifcsname\@mt@\mathcollection#1\endcsname
+ \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\mathcollection
+ \else\ifcsname\@mt@\nomathcollection#1\endcsname
+ \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\nomathcollection
+ \else
+ \nocharacterencoding
+ \fi\fi\fi\fi
+ \fi
+ #1\endcsname}
+
+%D Now we redefine the text encoding handler.
+
+%D A better fallback:
+
+% Just ETEX which is the default nowadays.
+
+\def\dohandlemathtoken#1%
+ {\csname
+ \ifmmode
+ \ifcsname\@mt@\mathcollection:\outerencoding#1\endcsname
+ \@mt@\mathcollection:\outerencoding
+ \else\ifcsname\@mt@\mathcollection#1\endcsname
+ \@mt@\mathcollection
+ \else\ifcsname\@mt@\nomathcollection#1\endcsname
+ \@mt@\nomathcollection
+ \else\ifcsname\characterencoding#1\endcsname
+ \characterencoding
+ \else
+ \nocharacterencoding
+ \fi\fi\fi\fi
+ \else
+ \ifcsname\characterencoding#1\endcsname
+ \characterencoding
+ \else\ifcsname\nocharacterencoding#1\endcsname
+ \nocharacterencoding
+ \else\ifcsname\@mt@\mathcollection:\outerencoding#1\endcsname
+ \@mt@\mathcollection:\outerencoding
+ \else\ifcsname\@mt@\mathcollection#1\endcsname
+ \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\mathcollection
+ \else\ifcsname\@mt@\nomathcollection#1\endcsname
+ \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\nomathcollection
+ \else
+ \nocharacterencoding
+ \fi\fi\fi\fi\fi
+ \fi
+ #1\endcsname}
+
+\let\dohandlecommand\dohandlemathtoken
+
+\def\definefamilysynonym
+ {\dotripleempty\dodefinefamilysynonym}
+
+\def\dodefinefamilysynonym[#1][#2][#3]% [mathcollection] [] []
+ {\ifthirdargument
+ \setvalue{\@mf@#1#2}{#3}%
+ \else
+ \setvalue{\@mf@ #1}{#2}%
+ \fi}
+
+\let\mathsubfamily\empty
+
+\def\purefamily #1{\csname \truefamily{#1}\mathsubfamily\s!fam\endcsname}
+\def\purefamilyhex#1{\csname hex\truefamily{#1}\mathsubfamily\s!fam\endcsname}
+
+\def\truefamily#1%
+ {\ifcsname\@mf@\mathcollection#1\endcsname
+ \@EA\truefamily\csname\@mf@\mathcollection#1\endcsname
+ \else\ifcsname\@mf@#1\endcsname
+ \@EA\truefamily\csname\@mf@#1\endcsname
+ \else\ifcsname\@mf@\nomathcollection#1\endcsname
+ \@EA\truefamily\csname\@mf@\nomathcollection#1\endcsname
+ \else
+ #1%
+ \fi\fi\fi}
+
+\newif\ifdynamicmathfamilies \dynamicmathfamiliestrue % true per 2003.11.25; needed for mixed bold math
+
+\let\normalpurefamilyhex\purefamilyhex
+
+% todo: reset collection (tok legen) en opnieuw laden met true
+
+\def\definemathsymbol
+ {\dosixtupleempty\dodefinemathsymbol}
+
+\def\dodefinemathsymbol[#1][#2][#3][#4][#5][#6]%
+ {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
+ \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
+ \setevalue{\@mt@\mathcollection#1}%
+ {\ifsixthargument
+ \ifnum\puremathcode{#2}=\mathradicalcode
+ \radical"%
+ \else
+ \delimiter"%
+ \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+ \fi
+ \purefamilyhex{#3}\uchexnumbers{#4}%
+ \purefamilyhex{#5}\uchexnumbers{#6}\space
+ \else\iffourthargument
+ \ifnum\puremathcode{#2}=\mathaccentcode
+ \mathaccent\else\mathchar
+ \fi
+ "\ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+ \purefamilyhex{#3}\uchexnumbers{#4}\space
+ \fi\fi}%
+ \let\purefamilyhex\normalpurefamilyhex
+ \tracemathsymbol{#1}}
+
+\def\tracemathsymbol#1%
+ {\iftracemathcollection
+ {\endgraf
+ \hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}
+ \endgraf}%
+ \fi}
+
+\def\definemathcharacter
+ {\dosixtupleempty\dodefinemathcharacter}
+
+% \def\dodefinemathcharacter[#1][#2][#3][#4][#5][#6]%
+% {\setmathtoks
+% \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
+% \doifnumberelse{#1}
+% {\scratchcounter#1}
+% {\scratchcounter\@EA`\string#1}%
+% \appendetoks
+% \ifsixthargument
+% \delcode\the\scratchcounter="%
+% \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+% \purefamilyhex{#3}\uchexnumbers{#4}%
+% \purefamilyhex{#5}\uchexnumbers{#6}\space
+% \else\iffourthargument
+% \mathcode\the\scratchcounter="%
+% \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+% \purefamilyhex{#3}\uchexnumbers{#4}\space
+% \fi\fi\to\mathtoks
+% \let\purefamilyhex\normalpurefamilyhex
+% \tracemathcharacter{#1}}
+
+\newtoks\mathscratchtoks
+
+\def\definemathcharacter
+ {\chardef\mathcharactermode\zerocount
+ \dosixtupleempty\dodefinemathcharacter}
+
+\def\redefinemathcharacter
+ {\chardef\mathcharactermode\plusone
+ \dosixtupleempty\dodefinemathcharacter}
+
+\def\dodefinemathcharacter[#1][#2][#3][#4][#5][#6]%
+ {\ifcase\mathcharactermode
+ \setmathtoks
+ \or
+ \let\mathtoks\mathscratchtoks \mathtoks\emptytoks
+ \fi
+ \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
+ \doifnumberelse{#1}
+ {\scratchcounter#1}
+ {\scratchcounter\@EA`\string#1}%
+ \appendetoks
+ \ifsixthargument
+ \delcode\the\scratchcounter="%
+ \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+ \purefamilyhex{#3}\uchexnumbers{#4}%
+ \purefamilyhex{#5}\uchexnumbers{#6}\space
+ \else\iffourthargument
+ \mathcode\the\scratchcounter="%
+ \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
+ \purefamilyhex{#3}\uchexnumbers{#4}\space
+ \fi\fi
+ \to \mathtoks
+ \let\purefamilyhex\normalpurefamilyhex
+ \ifcase\mathcharactermode
+ \expandafter\tracemathcharacter
+ \or
+ \the\mathtoks
+ \mathtoks\emptytoks
+ \expandafter\gobbleoneargument
+ \fi{#1}} % maybe lookahead
+
+\def\tracemathcharacter#1%
+ {\iftracemathcollection
+ {\endgraf
+ \doifnumberelse{#1}
+ {\hbox{\tttf\rawcharacter{#1}~:~{\mathematics{\rawcharacter{#1}}}}}
+ {\hbox{\type{#1}~:~{\mathematics{#1}}}}
+ \endgraf}%
+ \fi}
+
+\def\definemathcommand
+ {\dotripleempty\dodefinemathcommand}
+
+\def\dodefinemathcommand[#1][#2][#3]#4% command class args meaning
+ {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
+ \ifthirdargument
+ \processaction
+ [#3]
+ [one=>\setvalue{\@mt@\mathcollection#1}##1{\puremathcomm{#2}{#4{##1}}},
+ two=>\setvalue{\@mt@\mathcollection#1}##1##2{\puremathcomm{#2}{#4{##1}{##2}}}]%
+ \else\ifsecondargument
+ \setvalue{\@mt@\mathcollection#1}{\puremathcomm{#2}{#4}}%
+ \else
+ \setvalue{\@mt@\mathcollection#1}{\puremathcomm{nothing}{#4}}%
+ \fi\fi
+ \tracemathcommand{#1}}
+
+\def\tracemathcommand#1%
+ {\iftracemathcollection
+ \endgraf\hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}\endgraf
+ \fi}
+
+\def\startmathcollection[#1]%
+ {\pushmacro\mathcollection
+ \setmathcollection{#1}}
+
+\def\setmathcollection#1%
+ {\edef\mathcollection{#1}%
+ \doifundefined{\@ml@\mathcollection}
+ {\expandafter\newtoks\csname\@ml@\mathcollection\endcsname}}
+
+\def\stopmathcollection
+ {\popmacro\mathcollection}
+
+\def\startrawmathcollection
+ {\startmathcollection}
+
+\def\stoprawmathcollection
+ {\stopmathcollection}
+
+\newtoks\mathtoks
+
+\def\setmathtoks
+ {\@EA\let\@EA\mathtoks\csname\@ml@\mathcollection\endcsname}
+
+\def\currentmathcollection{\mathcollection}
+
+\let\nomathcollection\s!default
+
+\def\enablemathcollection[#1]%
+ {\doifnot{#1}\s!default
+ {\setmathcollection\s!default
+ \the\csname\@ml@\mathcollection\endcsname}%
+ \setmathcollection{#1}%
+ \the\csname\@ml@\mathcollection\endcsname}
+
+% hook 'm into the font mechanism
+
+\definefilesynonym[\f!mathprefix\s!default][\f!mathprefix tex]
+
+\def\usemathcollection
+ {\dodoubleempty\dousemathcollection}
+
+\def\dousemathcollection[#1][#2]%
+ {\pushmacro\fontclass
+ \pushmacro\mathclass
+ \ifsecondargument
+ \edef\fontclass{#1}%
+ \edef\mathclass{#2}%
+ \else
+ \edef\mathclass{#1}%
+ \fi
+ \doinputonce{\truefilename{\f!mathprefix\mathclass}}%
+ \doifsomething\fontclass{\setevalue{\@mc@\fontclass\@mc@}{\mathclass}}%
+ \popmacro\mathclass
+ \popmacro\fontclass}
+
+\let\mathclass\nomathcollection
+
+\letvalue{\@mc@\@mc@}\nomathcollection
+
+% \def\autoenablemathcollection
+% {\doifdefinedelse{\@mc@\fontclass\@mc@}
+% {\enablemathcollection[\getvalue{\@mc@\fontclass\@mc@}]}
+% {\enablemathcollection[\s!default]}} % ? ? ?
+
+\def\autoenablemathcollection
+ {\expanded{\enablemathcollection[\executeifdefined{\@mc@\fontclass\@mc@}\nomathcollection]}}
+
+\appendtoks\autoenablemathcollection\to\mathstrategies
+
+\fetchruntimecommand \showmathcharacters {\f!mathprefix\s!run.mkii}
+\fetchruntimecommand \showmathtoken {\f!mathprefix\s!run.mkii}
+
+\def\resetmathcollection[#1]%
+ {\def\mathcollection{#1}%
+ \forgetdoingonce{\f!mathprefix\mathcollection}%
+ \setmathtoks
+ \ifx\mathtoks\relax\else\mathtoks\emptytoks\fi}
+
+%D \macros
+%D {ifmathpunctuation, enablemathpunctuation,
+%D definemathpunctuation}
+%D
+%D This will replace periods by comma's:
+%D
+%D \starttyping
+%D \definemathpunctuation . textcomma textperiod
+%D \definemathpunctuation , textcomma textcomma
+%D
+%D \appendtoks
+%D \redefinemathcharacter [.] [ord] [mi] ["3B]%
+%D \to \everymathpunctuation
+%D \stoptyping
+
+% \newif\ifmathpunctuation
+%
+% \def\enablemathpunctuation{\mathpunctuationtrue}
+%
+% \def\definemathpunctuation #1 #2 #3 %
+% {\appendtoks
+% \initializemathpunctuation{#1}{#2}{#3}%
+% \to\everymathematics}
+%
+% \def\initializemathpunctuation#1#2#3% sloowww
+% {\ifmathpunctuation % hm move this test to everymath, or better a separate token list
+% \mathcode`#1="8000
+% \defineactivecharacter #1 {\dohandlemathpunctuation{#2}{#3}}%
+% \fi}
+%
+% \unexpanded\def\dohandlemathpunctuation#1#2% \if fails in mathml interval
+% {\def\next{\csname\ifx\space\nexttoken#2\else#1\fi\endcsname}%
+% \futurelet\nexttoken\next}
+
+\newtoks\everymathpunctuation
+
+\def\enablemathpunctuation % can be called inside math, so after \everymathematics
+ {\the\everymathpunctuation
+ \appendtoksonce
+ \the\everymathpunctuation
+ \to\everymathematics}
+
+\def\definemathpunctuation #1 #2 #3 %
+ {\appendtoks
+ \initializemathpunctuation{#1}{#2}{#3}%
+ \to\everymathpunctuation}
+
+\def\initializemathpunctuation#1#2#3% sloowww
+ {\mathcode`#1="8000
+ \defineactivecharacter #1 {\dohandlemathpunctuation{#2}{#3}}}
+
+\unexpanded\def\dohandlemathpunctuation#1#2% \if fails in mathml interval
+ {\def\next{\csname\ifx\space\nexttoken#2\else#1\fi\endcsname}%
+ \futurelet\nexttoken\next}
+
+%D \startbuffer
+%D \enablemathpunctuation$(1,2) (1, 2) (1{,}2) \hbox{foo, not bar}$
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \blank{\getbuffer}\blank
+
+%D needed for sin, cos etc
+
+\def\mfunction #1{{\mr#1}}
+
+% \def\mlimitsfunction #1{\mathlimopcomm{{\mr#1}}
+% \def\mnolimitsfunction#1{\mathnolopcomm{{\mr#1}}
+
+%D Taco posted this solution as response to a mail by Olivier, so
+%D let's integrate it here.
+
+% \def\setmathfunctionstyle#1% rm ss tt
+% {\def\mfunction##1% no families, just scaling a la text
+% {\mathchoice
+% {\hbox{\csname#1\endcsname\tf ##1}}
+% {\hbox{\csname#1\endcsname\tf ##1}}
+% {\hbox{\csname#1\endcsname\tfx ##1}}
+% {\hbox{\csname#1\endcsname\tfxx##1}}}}
+
+\def\currentmscaledstyle{rm} % will be plugged into the typeface text=ss option
+
+\def\setmathfunctionstyle#1% rm ss tt
+ {\doifsomething{#1}
+ {\def\currentmscaledstyle{#1}%
+ \def\mathopnolimits##1{\mathop{\mscaledtext{##1}}\nolimits}%
+ \def\mfunction##1{\mscaledtext{##1}}}}
+
+\def\mscaledtext#1%
+ {\mathchoice
+ {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tfx #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tfxx#1}}}
+
+%D We can force the way functions are typeset by manipulating the text
+%D option:
+%D
+%D \starttyping
+%D \definetypeface[iwona][ss][sans][iwona][default][encoding=texnansi]
+%D \definetypeface[iwona][mm][math][iwona][default][encoding=texnansi,text=ss]
+%D \stoptyping
+%D
+%D This hooks into the math handler with:
+
+\appendtoks
+ \setmathfunctionstyle\currentmathtextstyle
+\to \everybodyfont
+
+%D Usage:
+%D
+%D \starttyping
+%D \setmathfunctionstyle\fontstyle % or {rm} or {ss} or ..
+%D \rm test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \ss test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \tt test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \stoptyping
+
+\edef\hexmrfam {0} \edef\hexbsfam {8}
+\edef\hexmifam {1} \edef\hexbifam {9}
+\edef\hexsyfam {2} \edef\hexscfam {A}
+\edef\hexexfam {3} \edef\hextffam {B}
+\edef\hexitfam {4} \edef\hexmafam {C}
+\edef\hexslfam {5} \edef\hexmbfam {D}
+\edef\hexbffam {6} \edef\hexmcfam {E}
+\edef\hexnnfam {7} \edef\hexmdfam {F}
+
+\definefamilysynonym [default] [letters] [mr]
+\definefamilysynonym [default] [operators] [sy]
+\definefamilysynonym [default] [lcgreek] [mi]
+\definefamilysynonym [default] [ucgreek] [mr]
+\definefamilysynonym [default] [vargreek] [mi]
+\definefamilysynonym [default] [mitfamily] [mi]
+\definefamilysynonym [default] [calfamily] [sy]
+
+\definefamilysynonym [default] [0] [mr]
+\definefamilysynonym [default] [1] [mi]
+\definefamilysynonym [default] [2] [sy]
+\definefamilysynonym [default] [3] [ex]
+
+\enablemathcollection[default]
+
+\usemathcollection [default] [tex]
+\usemathcollection [default] [ams]
+\usemathcollection [default] [uni]
+
+\enablemathcollection[default]
+
+%D Some goodies:
+
+\def\Angstrom{\nomathematics{\Aring}}
+
+%D Bold math:
+%D
+%D \starttyping
+%D \usetypescript [lucida] [texnansi]
+%D
+%D \definetypeface [boldmath] [rm] [serif]
+%D [lucida] [default] [encoding=texnansi]
+%D \definetypeface [boldmath] [tt] [mono]
+%D [lucida] [default] [encoding=texnansi]
+%D \definetypeface [boldmath] [ss] [sans]
+%D [lucida] [default] [encoding=texnansi]
+%D \definetypeface [boldmath] [mm] [boldmath]
+%D [lucida] [default] [encoding=texnansi]
+%D
+%D \switchtobodyfont[lucida,10pt]
+%D
+%D \showmathtoken{Gamma} $\Gamma \Delta \alpha \delta \zeta$
+%D
+%D \switchtobodyfont[boldmath,10pt]
+%D
+%D \showmathtoken{Gamma} $\Gamma \Delta \alpha \delta \zeta$
+%D \stoptyping
+
+%D \macros
+%D {nonknuthmode, donknuthmode}
+%D
+%D The underscore is frequently used in manuals but unfortunately \TEX\ prefers
+%D it to be a math specific character. And since computer modern fonts didn't
+%D have an underscore, one had to use commands to fake one. Nowadays we do
+%D have underscores in latin modern, and since all other fonts have them, we
+%D decided to get away from the restriction to use the underscore character in
+%D text mode.
+%D
+%D \starttyping
+%D \def\test#1{#1}
+%D
+%D \nonknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
+%D
+%D \donknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
+%D \stoptyping
+%D
+%D The result is as expected: the first line typesets ok, while the second
+%D one triggers an error message.
+
+\bgroup
+
+ \ifx\normalsuber\undefined \def\normalsuber{_} \fi
+ \ifx\normalsuper\undefined \def\normalsuper{^} \fi
+
+ \catcode`_=\active
+ \catcode`^=\active
+
+ \gdef\nonknuthmode
+ {\appendtoks\let_\normalsuber\let^\normalsuper\to\everymathematics
+ \mathcode`_="8000
+ \mathcode`^="8000
+ \catcode`_=\@@other
+ \catcode`^=\@@other
+ \let\nonknuthmode\relax}
+
+ \gdef\donknuthmode
+ {\catcode`_=\@@subscript
+ \catcode`^=\@@superscript}
+
+\egroup
+
+%D \macros
+%D {checkdelimiters, fakeleftdelimiter, fakerightdelimiter}
+%D
+%D Handy for non matching situations (as with mathml):
+%D
+%D \starttyping
+%D \checkdelimiters{... bla bla ...}
+%D \fakeleftdelimiter
+%D ... bla bla ...
+%D \fakerightdelimiter
+%D \stoptyping
+
+\newcount\delimitercount
+
+\def\leftfakedelimiter {\advance\delimitercount\minusone\gobbleoneargument}%
+\def\rightfakedelimiter{\advance\delimitercount\plusone \gobbleoneargument}%
+
+\def\checkdelimiters#1%
+ {\delimitercount\zerocount
+ \setbox\scratchbox\hbox\bgroup
+ \let\left \leftfakedelimiter
+ \let\right\rightfakedelimiter
+ $#1\expandafter$\expandafter
+ \egroup
+ \expandafter\delimitercount\the\delimitercount\relax}
+
+\def\fakeleftdelimiter {\ifnum\delimitercount>\zerocount\left .\fi}
+\def\fakerightdelimiter{\ifnum\delimitercount<\zerocount\right.\fi}
+
+%D Needed for unicode:
+
+\def\nulloperator{\mathortext{\mathop{\null}}{\null}}
+
+%D To be dealt with ...
+
+\mathcode`\ ="8000 % \space
+\mathcode`\'="8000 % ^\prime
+\mathcode`\_="8000 % \_
+
+\protect \endinput
+
+\tracemathcollectiontrue
+ \input math-tex \page
+\setupbodyfont[ams] \enablemathcollection[default] \input math-ams \page
+\setupbodyfont[lbr] \enablemathcollection[lbr] \input math-lbr \page
+\setupbodyfont[eul] \enablemathcollection[eul] \input math-eul \stoptext
diff --git a/tex/context/base/math-ini.mkiv b/tex/context/base/math-ini.mkiv
index 062631b39..b87096661 100644
--- a/tex/context/base/math-ini.mkiv
+++ b/tex/context/base/math-ini.mkiv
@@ -1,8 +1,8 @@
%D \module
%D [ file=math-ini,
%D version=2008.01.02,
-%D title=\CONTEXT\ Lua Macros,
-%D subtitle=Math Initializations,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Initializations,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
@@ -11,39 +11,549 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+\writestatus{loading}{ConTeXt Math Macros / Initializations}
+
+%D This module provides namespaces for math fonts, thereby
+%D permitting mixed usage of math fonts. Although not strictly
+%D needed, we also provide a family name mapping mechanism as
+%D used in the (original) AMS math definition files, but here
+%D these names can recursively be remapped and if needed,
+%D dynamically be changed. We've tried to minimize the number
+%D of definition commands and use plain \TEX\ definitions as
+%D fallback. We've tried to follow a couple of conventions
+%D from plain and AMS math in order to achieve backward
+%D compatinility. We also kept an eye on future usage of these
+%D modules in the perspective of MathML and unicode fonts.
+
\unprotect
+\ifx\v!compact\undefined \def\v!compact{compact} \fi
+
%D We move these definitions into the format:
% test [[\char948 \ctxlua{tex.sprint(utf.char(948))}]]
% test $[[\char948 \ctxlua{tex.sprint(utf.char(948))}]]$
\registerctxluafile{math-ini}{1.001}
+\registerctxluafile{math-dim}{1.001}
\registerctxluafile{math-ent}{1.001}
+\registerctxluafile{math-ext}{1.001}
+\registerctxluafile{math-vfu}{1.001}
+\registerctxluafile{math-map}{1.001}
+\registerctxluafile{math-noa}{1.001}
+
+\definesystemattribute[mathalph]
+\definesystemattribute[mathsize]
+\definesystemattribute[mathpunc]
+
+% todo: only in mmode
+
+% \def\setmathattribute#1#2{\dosetattribute{mathalph}{\ctxlua{tex.sprint(mathematics.sync_a_both (\number\dogetattribute{mathalph},"#1","#2"))}}}
+% \def\setmathalphabet #1{\dosetattribute{mathalph}{\ctxlua{tex.sprint(mathematics.sync_a_name (\number\dogetattribute{mathalph},"#1"))}}}
+% \def\setmathstyle #1{\dosetattribute{mathalph}{\ctxlua{tex.sprint(mathematics.sync_a_style(\number\dogetattribute{mathalph},"#1"))}}}
+
+\def\setmathattribute#1#2{\ctxlua{mathematics.sync_a_both ("#1","#2")}}
+\def\setmathalphabet #1{\ctxlua{mathematics.sync_a_name ("#1")}}
+\def\setmathstyle #1{\ctxlua{mathematics.sync_a_style("#1")}}
+
+\unexpanded\def\mr {\setmathattribute{regular}{tf}}
+
+\unexpanded\def\mathdefault {\setmathattribute{regular}{it}}
+\unexpanded\def\mathscript {\setmathalphabet{script}}
+\unexpanded\def\mathfraktur {\setmathalphabet{fraktur}}
+\unexpanded\def\mathblackboard{\setmathalphabet{blackboard}}
+
+\unexpanded\def\mathrm{\setmathattribute{rm}{tf}}
+\unexpanded\def\mathss{\setmathattribute{ss}{tf}}
+\unexpanded\def\mathtt{\setmathattribute{tt}{tf}}
+
+\unexpanded\def\mathtf{\setmathstyle{tf}}
+\unexpanded\def\mathbf{\setmathstyle{bf}}
+\unexpanded\def\mathsl{\setmathstyle{sl}}
+\unexpanded\def\mathit{\setmathstyle{it}}
+\unexpanded\def\mathbs{\setmathstyle{bs}}
+\unexpanded\def\mathbi{\setmathstyle{bi}}
+
+\let\tfmath\mathtf % maybe a grouped command
+\let\bfmath\mathbf
+\let\slmath\mathsl
+\let\itmath\mathit
+\let\bsmath\mathbs
+\let\bimath\mathbi
-% \registerctxluafile{math-def}{1.001}
-% \ctxlua{mathematics.traditional()}
+\let\Bbb\mathblackboard
-\ctxlua{mathematics.define()}
-\ctxlua{mathematics.register_xml_entities()}
+\unexpanded\def\frak {\ifmmode\expandafter\mathfraktur \fi}
+\unexpanded\def\cal {\ifmmode\expandafter\mathscript \fi}
+\unexpanded\def\bbd {\ifmmode\expandafter\mathblackboard\fi}
+\unexpanded\def\blackboard{\ifmmode\expandafter\mathblackboard\fi}
+\unexpanded\def\fraktur {\ifmmode\expandafter\mathfraktur \fi}
+\unexpanded\def\gothic {\ifmmode\expandafter\mathfraktur \fi}
+
+\unexpanded\def\mathcal #1{{\setmathalphabet{script}#1}} % for AMS compatibility
+\unexpanded\def\mathfrak#1{{\setmathalphabet{fraktur}#1}} % for AMS compatibility
+\unexpanded\def\mathbb #1{{\setmathalphabet{blackboard}#1}} % for AMS compatibility
+
+\let\normalmr\mr
+
+\prependtoks
+ \let\mr\normalmr
+ \let\rm\mathrm \let\ss\mathss \let\tt\mathtt
+ \let\tf\mathtf \let\bf\mathbf \let\it\mathit \let\sl\mathsl \let\bi\mathbi \let\bs\mathbs
+ \let\frak\mathfraktur \let\cal\mathscript \let\bbd\mathblackboard
+ \mathdefault
+\to \everymathematics
+
+%D \macros
+%D {boldsymbol}
+%D
+%D The math definition is inspired by amsmath.
+%D
+%D \startbuffer
+%D \definetypeface [boldmath] [mm] [boldmath] [latin-modern] [modern] [encoding=texnansi]
+%D
+%D $a \times b$ $a \boldsymbol{\times} b$
+%D \stopbuffer
+%D
+%D \typebuffer \start \getbuffer \stop
+
+\let\mathboldsymbol\relax % yet unsupported, will be
+
+\def\boldsymbol
+ {\mathortext\mathboldsymbol\bold}
+
+%D Helpers:
\def\utfmathclass #1{\ctxlua{tex.sprint(mathematics.utfmathclass ("#1"))}}
\def\utfmathstretch#1{\ctxlua{tex.sprint(mathematics.utfmathstretch("#1"))}}
\def\utfmathcommand#1{\ctxlua{tex.sprint(mathematics.utfmathcommand("#1"))}}
\def\utfmathfiller #1{\ctxlua{tex.sprint(mathematics.utfmathfiller ("#1"))}}
-\def\utfmathclassdefault #1#2{\ctxlua{
- tex.sprint(mathematics.utfmathclass("#1","#2"))
-}}
+% \def\utfmathclassdefault #1#2{\ctxlua{
+% tex.sprint(mathematics.utfmathclass("#1","#2"))
+% }}
+%
+% \def\utfmathcommanddefault#1#2#3{\ctxlua{
+% local cmd = mathematics.utfmathcommand("#1","") or ""
+% if cmd == "" then
+% commands.cs("#2","#3")
+% else
+% commands.cs(cmd)
+% end}}
+
+% % %
+
+\def\@@mathlimopcomm #1{\mathop{#1}} %no \limits
+\def\@@mathnolopcomm #1{\mathop{#1}\nolimits}
+\def\@@mathboxcomm #1{\dontleavehmode\hbox{$\mathsurround\zeropoint#1$}}
+\def\@@mathchoicecomm#1{[todo #1]}
+
+\chardef\mathordcode = 0 \let\mathordcomm \mathord
+\chardef\mathopcode = 1 \let\mathopcomm \mathop
+\chardef\mathbincode = 2 \let\mathbincomm \mathbin
+\chardef\mathrelcode = 3 \let\mathrelcomm \mathrel
+\chardef\mathopencode = 4 \let\mathopencomm \mathopen
+\chardef\mathclosecode = 5 \let\mathclosecomm \mathclose
+\chardef\mathpunctcode = 6 \let\mathpunctcomm \mathpunct
+\chardef\mathalphacode = 7 \let\mathalphacomm \firstofoneargument
+\chardef\mathinnercode = 0 \let\mathinnercomm \mathinner
+\chardef\mathnothingcode= 0 \let\mathnothingcomm \firstofoneargument
+\chardef\mathlimopcode = 1 \let\mathlimopcomm \@@mathlimopcomm
+\chardef\mathnolopcode = 1 \let\mathnolopcomm \@@mathnolopcomm
+\chardef\mathchoicecode = 0 \let\mathchoicecomm \@@mathchoicecomm
+\chardef\mathboxcode = 0 \let\mathboxcomm \@@mathboxcomm
+
+\chardef\mathaccentcode = 8
+\chardef\mathradicalcode= 9
+
+\def\puremathcode#1{\the\csname math#1code\endcsname}
+\def\puremathcomm#1{\csname math#1comm\endcsname}
+
+% \startlines
+% $\mathopnolimits{\rm d}x$
+% $\mathopnolimits{\kern\zeropoint \rm d}x$
+% $\puremathcomm{nolop}{\rm d}x$
+% $\puremathcomm{nolop}{\kern\zeropoint\rm d}x$
+% \blank
+% $\puremathcomm{nolop}{\mr d}x$
+% $\puremathcomm{nolop}{\kern\zeropoint\mr d}x$
+% $\mathop{\kern\zeropoint\mr d}x$
+% $\mathopnolimits{\kern\zeropoint d}x$
+% \stoplines
+
+\newif\iftracemathcollection
+
+% this will be sorted out:
+
+\let\mathcharacter \getvalue
+\let\textcharacter \getvalue
+\def\definefamilysynonym {\dotripleempty\dodefinefamilysynonym}
+\def\dodefinefamilysynonym [#1][#2][#3]{}
+\def\definemathsymbol {\dosixtupleempty\dodefinemathsymbol}
+\def\dodefinemathsymbol [#1][#2][#3][#4][#5][#6]{}
+\def\definemathcharacter {\dosixtupleempty\dodefinemathcharacter}
+\def\redefinemathcharacter {\dosixtupleempty\dodefinemathcharacter}
+\def\dodefinemathcharacter [#1][#2][#3][#4][#5][#6]{}
+\def\startmathcollection [#1]{}
+\def\setmathcollection #1{}
+\def\stopmathcollection {}
+\def\startrawmathcollection {}
+\def\stoprawmathcollection {}
+\def\setmathtoks {}
+\let\currentmathcollection \s!default
+\let\nomathcollection \s!default
+\let\mathcollection \s!default
+\def\enablemathcollection [#1]{}
+\def\usemathcollection {\dodoubleempty\dousemathcollection}
+\def\dousemathcollection [#1][#2]{}
+\let\mathclass \nomathcollection
+\let\autoenablemathcollection\relax
+\def\resetmathcollection [#1]{}
+
+\def\definemathcommand
+ {\dotripleempty\dodefinemathcommand}
+
+\def\dodefinemathcommand[#1][#2][#3]#4% command class args meaning
+ {\ifthirdargument
+ \processaction
+ [#3]
+ [one=>\unexpanded\setvalue{#1}##1{\puremathcomm{#2}{#4{##1}}},
+ two=>\unexpanded\setvalue{#1}##1##2{\puremathcomm{#2}{#4{##1}{##2}}}]%
+ \else\ifsecondargument
+ \unexpanded\setvalue{#1}{\puremathcomm{#2}{#4}}%
+ \else
+ \unexpanded\setvalue{#1}{\puremathcomm{nothing}{#4}}%
+ \fi\fi}
+
+%D Moved from font-ini.mkiv:
+%D
+%D \macros
+%D {mf,mbox,enablembox,mathop}
+%D
+%D Todo:
+
+\unexpanded\def\mf
+ {\csname\fontalternative\endcsname}
+
+\let\normalmathop\mathop
+
+\unexpanded\def\mathop
+ {\normalmathop
+ \bgroup
+ \let\rm\mf
+ \let\next=}
+
+\def\normalmbox
+ {\normalhbox\bgroup\mf
+ \dowithnextbox{\flushnextbox\egroup}\normalhbox}
+
+\def\mbox
+ {\ifmmode\normalmbox\else\normalhbox\fi}
+
+\def\enablembox
+ {\appendtoks
+ \ifx\normalhbox\undefined\let\normalhbox\hbox\fi
+ \let\hbox\mbox
+ \to\everymathematics}
+
+%D needed for sin, cos etc
+
+\def\mfunction#1{{\mr#1}}
+
+% \def\mlimitsfunction #1{\mathlimopcomm{{\mr#1}}
+% \def\mnolimitsfunction#1{\mathnolopcomm{{\mr#1}}
+
+%D Taco posted this solution as response to a mail by Olivier, so
+%D let's integrate it here.
+
+\def\currentmscaledstyle{rm} % will be plugged into the typeface text=ss option
+
+\def\setmathfunctionstyle#1% rm ss tt
+ {\doifsomething{#1}
+ {\def\currentmscaledstyle{#1}%
+ \def\mathopnolimits##1{\mathop{\mscaledtext{##1}}\nolimits}%
+ \def\mfunction##1{\mscaledtext{##1}}}}
+
+\def\mscaledtext#1%
+ {\mathchoice
+ {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tfx #1}}
+ {\hbox{\csname\currentmscaledstyle\endcsname\tfxx#1}}}
+
+%D We can force the way functions are typeset by manipulating the text
+%D option:
+%D
+%D \starttyping
+%D \definetypeface[iwona][ss][sans][iwona][default][encoding=texnansi]
+%D \definetypeface[iwona][mm][math][iwona][default][encoding=texnansi,text=ss]
+%D \stoptyping
+%D
+%D This hooks into the math handler with:
+
+\appendtoks
+ \setmathfunctionstyle\currentmathtextstyle
+\to \everybodyfont
+
+%D Usage:
+%D
+%D \starttyping
+%D \setmathfunctionstyle\fontstyle % or {rm} or {ss} or ..
+%D \rm test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \ss test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \tt test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
+%D \stoptyping
+
+%D Some goodies:
+
+\def\Angstrom{\nomathematics{\Aring}}
+
+%D \macros
+%D {nonknuthmode, donknuthmode}
+%D
+%D The underscore is frequently used in manuals but unfortunately \TEX\ prefers
+%D it to be a math specific character. And since computer modern fonts didn't
+%D have an underscore, one had to use commands to fake one. Nowadays we do
+%D have underscores in latin modern, and since all other fonts have them, we
+%D decided to get away from the restriction to use the underscore character in
+%D text mode.
+%D
+%D \starttyping
+%D \def\test#1{#1}
+%D
+%D \nonknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
+%D
+%D \donknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
+%D \stoptyping
+%D
+%D The result is as expected: the first line typesets ok, while the second
+%D one triggers an error message.
+
+\bgroup
+
+ \ifx\normalsuber\undefined \def\normalsuber{_} \fi
+ \ifx\normalsuper\undefined \def\normalsuper{^} \fi
+
+ \catcode`_=\active
+ \catcode`^=\active
+
+ \gdef\nonknuthmode
+ {\appendtoks\let_\normalsuber\let^\normalsuper\to\everymathematics
+ \mathcode`_="8000
+ \mathcode`^="8000
+ \catcode`_=\@@other
+ \catcode`^=\@@other
+ \let\nonknuthmode\relax}
+
+ \gdef\donknuthmode
+ {\catcode`_=\@@subscript
+ \catcode`^=\@@superscript}
+
+\egroup
+
+%D Needed for unicode:
+
+\def\nulloperator{\mathortext{\mathop{\null}}{\null}}
+
+%D To be dealt with ...
+
+\mathcode`\ ="8000 % \space
+\mathcode`\'="8000 % ^\prime
+\mathcode`\_="8000 % \_
+
+%D \macros
+%D {\setupmathematics}
+%D
+%D Configuration for integrals. (If needed we can speed this up and make it
+%D installable; no processaction is needed then).
+
+\newtoks\everysetupmathematics
+
+\def\setupmathematics
+ {\dosingleargument\dosetupmathematics}
+
+\def\dosetupmathematics[#1]%
+ {\getparameters[\??mo][#1]%
+ \the\everysetupmathematics}
+
+\def\mathematicsparameter#1{\ifcsname\??mo#1\endcsname\csname\??mo#1\endcsname\fi}
+
+%D Memory saver:
+
+\appendtoks
+ \doifelse{\mathematicsparameter\v!compact}\v!yes
+ {\ctxlua{fonts.vf.math.optional=true}}
+ {\ctxlua{fonts.vf.math.optional=false}}%
+\to \everysetupmathematics
+
+\setupmathematics
+ [\v!compact=no]
+
+%D \macros
+%D {enablemathpunctuation,disablemathpunctuation}
+%D
+%D \startbuffer
+%D \enablemathpunctuation$(1,2) (1, 2) (1{,}2) \hbox{foo, not bar}$
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \blank{\getbuffer}\blank
+
+\setfalse \automathpunctuation
+
+\def\enablemathpunctuation {\settrue \automathpunctuation}
+\def\disablemathpunctuation{\setfalse\automathpunctuation}
+
+\ifx\v!autopunctuation\undefined \def\v!autopunctuation{autopunctuation} \fi
+
+\appendtoks
+ \doifelse{\mathematicsparameter\v!autopunctuation}\v!yes\enablemathpunctuation\disablemathpunctuation
+\to \everysetupmathematics
+
+\appendtoks
+ \ifconditional\automathpunctuation\dosetattribute{mathpunc}\plusone\fi
+\to \everymathematics
+
+\setupmathematics
+ [\v!autopunctuation=\v!no]
+
+%D \macros
+%D {mathstyle}
+%D
+%D If one want to be sure that something is typeset in the
+%D appropriate style, \type {\mathstyle} can be used:
+%D
+%D \starttyping
+%D \mathstyle{something}
+%D \stoptyping
+
+% \def\mathstyle#1%
+% {\mathchoice
+% {\displaystyle #1}%
+% {\textstyle #1}%
+% {\scriptstyle #1}%
+% {\scriptscriptstyle#1}}
+%
+% We now have a primitive operation for this. As the
+% macro overloads a new primitive introduced in \LUATEX,
+% we need to use \type {\normalmathstyle} when we consult
+% the current math style.
+%
+% \let \mathstyle \Ustack % spoils cramped
+%
+% \let \mathstyle \firstofoneargument
+%
+% 0 = display
+% 1 = crampeddisplay
+% 2 = text
+% 3 = crampedtext
+% 4 = script
+% 5 = crampedscript
+% 6 = scriptscript
+% 7 = crampedscriptscript
+
+\def\uncramped#1%
+ {{\ifcase\normalmathstyle
+ \or \displaystyle \or
+ \or \textstyle \or
+ \or \scriptstyle \or
+ \or \scriptscriptstyle \fi
+ #1}}
+
+\def\cramped#1%
+ {{\ifcase\normalmathstyle
+ \crampeddisplaystyle \or \or % 0 -> 1
+ \crampedtextstyle \or \or % 2 -> 3
+ \crampedscriptstyle \or \or % 4 -> 5
+ \crampedscriptscriptstyle \fi % 6 -> 7
+ #1}}
+
+\def\triggermathstyle#1% #1 is number
+ {\ifcase#1\relax
+ \displaystyle \or
+ \crampeddisplaystyle \or
+ \textstyle \or
+ \crampedtextstyle \or
+ \scriptstyle \or
+ \crampedscriptstyle \or
+ \scriptscriptstyle \or
+ \crampedscriptscriptstyle \else
+ % error
+ \fi}
+
+\def\cramped#1%
+ {{\ifcase\normalmathstyle
+ \crampeddisplaystyle \or \or % 0 -> 1
+ \crampedtextstyle \or \or % 2 -> 3
+ \crampedscriptstyle \or \or % 4 -> 5
+ \crampedscriptscriptstyle \fi % 6 -> 7
+ #1}}
+
+%D Something similar can be used in the (re|)|definition
+%D of \type {\text}. This version is a variation on the one
+%D in the math module (see \type{m-math} and|/|or \type
+%D {m-newmat}).
+
+\unexpanded\def\mathtext
+ {\mathortext\domathtext\hbox}
+
+\def\domathtext#1%
+ {\mathchoice
+ {\dodomathtext\displaystyle\textface {#1}}%
+ {\dodomathtext\textstyle \textface {#1}}%
+ {\dodomathtext\textstyle \scriptface {#1}}%
+ {\dodomathtext\textstyle \scriptscriptface{#1}}}
+
+\def\dodomathtext#1#2#3% no \everymath !
+ %{\hbox{\everymath{#1}\switchtobodyfont [#2]#3}} % 15 sec
+ {\hbox{\everymath{#1}\setcurrentfontbody{#2}#3}} % 3 sec (no math)
+
+%D Because we may overload \type {\text} in other (structuring)
+%D macros, we say:
+
+\appendtoks \let\text\mathtext \to \everymathematics
+
+%D The next code is derived from plain \TEX.
+
+\newcount\interdisplaylinepenalty \interdisplaylinepenalty=100
+
+\newif\ifdt@p
+
+\def\displ@y
+ {\global\dt@ptrue
+ \openup\displayopenupvalue % was \openup\jot
+ \everycr
+ {\noalign
+ {\ifdt@p
+ \global\dt@pfalse
+ \ifdim\prevdepth>-\thousandpoint
+ \vskip-\lineskiplimit
+ \vskip\normallineskiplimit
+ \fi
+ \else
+ \penalty\interdisplaylinepenalty
+ \fi}}}
+
+\let\normaldispl@y\displ@y
+
+\def\displ@y{\resetdisplaymatheq\normaldispl@y}
+
+\def\m@th{\mathsurround\zeropoint} % obsolete
+
+%D Text in math:
+
+\def\mathortext
+ {\ifmmode
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+% \defineactivecharacter _ {\mathortext{_}{\_}} text_text $a^2$
-\def\utfmathcommanddefault#1#2#3{\ctxlua{
- local cmd = mathematics.utfmathcommand("#1","") or ""
- if cmd == "" then
- commands.cs("#2","#3")
- else
- commands.cs(cmd)
- end}}
+% force text mode, will be overloaded later
-% \let\math@normal@int\int \def\int{\math@normal@int\intlimits}
+\ifx\text\undefined \let\text\hbox \fi
\protect \endinput
diff --git a/tex/context/base/math-ini.tex b/tex/context/base/math-ini.tex
deleted file mode 100644
index 98738e500..000000000
--- a/tex/context/base/math-ini.tex
+++ /dev/null
@@ -1,688 +0,0 @@
-%D \module
-%D [ file=math-ini,
-%D version=2001.04.12,
-%D title=\CONTEXT\ Math Macros,
-%D subtitle=Basic Macros,
-%D author={Hans Hagen \& Taco Hoekwater},
-%D date=\currentdate,
-%D copyright=\PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-% todo: make all definitions global since file loaded only once
-
-%D This module provides namespaces for math fonts, thereby
-%D permitting mixed usage of math fonts. Although not strictly
-%D needed, we also provide a family name mapping mechanism as
-%D used in the (original) AMS math definition files, but here
-%D these names can recursively be remapped and if needed,
-%D dynamically be changed. We've tried to minimize the number
-%D of definition commands and use plain \TEX\ definitions as
-%D fallback. We've tried to follow a couple of conventions
-%D from plain and AMS math in order to achieve backward
-%D compatinility. We also kept an eye on future usage of these
-%D modules in the perspective of MathML and unicode fonts.
-
-\unprotect
-
-\def\@ml@{@ml@} % math list (used for collection)
-\def\@mf@{@mf@} % math family
-%def\@mh@{@mh@} % math handler (not used)
-\def\@mt@{@mt@} % math token
-\def\@mc@{@mc@} % math collection
-
-\def\@@mathlimopcomm#1{\mathop{#1}} %no \limits
-\def\@@mathnolopcomm#1{\mathop{#1}\nolimits}
-\def\@@mathboxcomm #1{\dontleavehmode\hbox{$\m@th#1$}}
-
-\chardef\mathordcode = 0 \let\mathordcomm \mathord
-\chardef\mathopcode = 1 \let\mathopcomm \mathop
-\chardef\mathbincode = 2 \let\mathbincomm \mathbin
-\chardef\mathrelcode = 3 \let\mathrelcomm \mathrel
-\chardef\mathopencode = 4 \let\mathopencomm \mathopen
-\chardef\mathclosecode = 5 \let\mathclosecomm \mathclose
-\chardef\mathpunctcode = 6 \let\mathpunctcomm \mathpunct
-\chardef\mathalphacode = 7 \let\mathalphacomm \firstofoneargument
-\chardef\mathinnercode = 0 \let\mathinnercomm \mathinner
-\chardef\mathnothingcode= 0 \let\mathnothingcomm \firstofoneargument
-\chardef\mathlimopcode = 1 \let\mathlimopcomm \@@mathlimopcomm
-\chardef\mathnolopcode = 1 \let\mathnolopcomm \@@mathnolopcomm
-\chardef\mathchoicecode = 0 \let\mathchoicecomm \@@mathchoicecomm
-\chardef\mathboxcode = 0 \let\mathboxcomm \@@mathboxcomm
-
-\chardef\mathaccentcode = 8
-\chardef\mathradicalcode= 9
-
-\def\@@mathchoicecomm#1{[todo #1]}
-
-\def\puremathcode#1{\the\csname math#1code\endcsname}
-\def\puremathcomm#1{\csname math#1comm\endcsname}
-
-\newif\iftracemathcollection
-
-% Simple variant:
-%
-% \def\dohandlemathtoken#1%
-% {\csname\@mt@
-% \ifcsname\@mt@\mathcollection#1\endcsname
-% \mathcollection
-% \else\ifcsname\@mt@\nomathcollection#1\endcsname
-% \nomathcollection
-% \fi\fi
-% #1\endcsname}
-
-%D Because a command can have a different meaning in math
-%D and in text mode, we provide a selector. We also provide
-%D the pure alternatives as \type {\mathcharacter} and \type
-%D {\textcharacter}.
-
-\ifx\dohandlecommand\undefined \wait \fi % troubles !
-
-\def\mathcharacter\dohandlemathtoken
-\def\textcharacter\dohandlecommand % better \dohandletexttoken
-
-% More clever layout:
-%
-% \def\dohandlemathtoken#1%
-% {\csname
-% \ifmmode
-% \ifcsname\@mt@\mathcollection#1\endcsname
-% \@mt@\mathcollection
-% \else\ifcsname\@mt@\nomathcollection#1\endcsname
-% \@mt@\nomathcollection
-% \else\ifcsname\characterencoding#1\endcsname
-% \characterencoding
-% \else
-% \nocharacterencoding
-% \fi\fi\fi
-% \else
-% \ifcsname\characterencoding#1\endcsname
-% \characterencoding
-% \else
-% \nocharacterencoding
-% \fi
-% \fi
-% #1\endcsname}
-%
-% fallback to math when in text mode (handy for unicode vectors)
-
-\def\dohandlemathtoken#1%
- {\csname
- \ifmmode
- \ifcsname\@mt@\mathcollection#1\endcsname
- \@mt@\mathcollection
- \else\ifcsname\@mt@\nomathcollection#1\endcsname
- \@mt@\nomathcollection
- \else\ifcsname\characterencoding#1\endcsname
- \characterencoding
- \else
- \nocharacterencoding
- \fi\fi\fi
- \else
- \ifcsname\characterencoding#1\endcsname
- \characterencoding
- \else\ifcsname\nocharacterencoding#1\endcsname
- \nocharacterencoding
- \else\ifcsname\@mt@\mathcollection#1\endcsname
- \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\mathcollection
- \else\ifcsname\@mt@\nomathcollection#1\endcsname
- \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\nomathcollection
- \else
- \nocharacterencoding
- \fi\fi\fi\fi
- \fi
- #1\endcsname}
-
-%D Now we redefine the text encoding handler.
-
-%D A better fallback:
-
-% Just ETEX which is the default nowadays.
-
-\def\dohandlemathtoken#1%
- {\csname
- \ifmmode
- \ifcsname\@mt@\mathcollection:\outerencoding#1\endcsname
- \@mt@\mathcollection:\outerencoding
- \else\ifcsname\@mt@\mathcollection#1\endcsname
- \@mt@\mathcollection
- \else\ifcsname\@mt@\nomathcollection#1\endcsname
- \@mt@\nomathcollection
- \else\ifcsname\characterencoding#1\endcsname
- \characterencoding
- \else
- \nocharacterencoding
- \fi\fi\fi\fi
- \else
- \ifcsname\characterencoding#1\endcsname
- \characterencoding
- \else\ifcsname\nocharacterencoding#1\endcsname
- \nocharacterencoding
- \else\ifcsname\@mt@\mathcollection:\outerencoding#1\endcsname
- \@mt@\mathcollection:\outerencoding
- \else\ifcsname\@mt@\mathcollection#1\endcsname
- \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\mathcollection
- \else\ifcsname\@mt@\nomathcollection#1\endcsname
- \strippedcsname\mathematics\expandafter\endcsname\csname\@mt@\nomathcollection
- \else
- \nocharacterencoding
- \fi\fi\fi\fi\fi
- \fi
- #1\endcsname}
-
-\let\dohandlecommand\dohandlemathtoken
-
-\def\definefamilysynonym
- {\dotripleempty\dodefinefamilysynonym}
-
-\def\dodefinefamilysynonym[#1][#2][#3]% [mathcollection] [] []
- {\ifthirdargument
- \setvalue{\@mf@#1#2}{#3}%
- \else
- \setvalue{\@mf@ #1}{#2}%
- \fi}
-
-\let\mathsubfamily\empty
-
-\def\purefamily #1{\csname \truefamily{#1}\mathsubfamily\s!fam\endcsname}
-\def\purefamilyhex#1{\csname hex\truefamily{#1}\mathsubfamily\s!fam\endcsname}
-
-\def\truefamily#1%
- {\ifcsname\@mf@\mathcollection#1\endcsname
- \@EA\truefamily\csname\@mf@\mathcollection#1\endcsname
- \else\ifcsname\@mf@#1\endcsname
- \@EA\truefamily\csname\@mf@#1\endcsname
- \else\ifcsname\@mf@\nomathcollection#1\endcsname
- \@EA\truefamily\csname\@mf@\nomathcollection#1\endcsname
- \else
- #1%
- \fi\fi\fi}
-
-\newif\ifdynamicmathfamilies \dynamicmathfamiliestrue % true per 2003.11.25; needed for mixed bold math
-
-\let\normalpurefamilyhex\purefamilyhex
-
-% todo: reset collection (tok legen) en opnieuw laden met true
-
-\def\definemathsymbol
- {\dosixtupleempty\dodefinemathsymbol}
-
-\def\dodefinemathsymbol[#1][#2][#3][#4][#5][#6]%
- {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
- \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
- \setevalue{\@mt@\mathcollection#1}%
- {\ifsixthargument
- \ifnum\puremathcode{#2}=\mathradicalcode
- \radical"%
- \else
- \delimiter"%
- \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
- \fi
- \purefamilyhex{#3}\uchexnumbers{#4}%
- \purefamilyhex{#5}\uchexnumbers{#6}\space
- \else\iffourthargument
- \ifnum\puremathcode{#2}=\mathaccentcode
- \mathaccent\else\mathchar
- \fi
- "\ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
- \purefamilyhex{#3}\uchexnumbers{#4}\space
- \fi\fi}%
- \let\purefamilyhex\normalpurefamilyhex
- \tracemathsymbol{#1}}
-
-\def\tracemathsymbol#1%
- {\iftracemathcollection
- {\endgraf
- \hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}
- \endgraf}%
- \fi}
-
-\def\definemathcharacter
- {\dosixtupleempty\dodefinemathcharacter}
-
-% \def\dodefinemathcharacter[#1][#2][#3][#4][#5][#6]%
-% {\setmathtoks
-% \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
-% \doifnumberelse{#1}
-% {\scratchcounter#1}
-% {\scratchcounter\@EA`\string#1}%
-% \appendetoks
-% \ifsixthargument
-% \delcode\the\scratchcounter="%
-% \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
-% \purefamilyhex{#3}\uchexnumbers{#4}%
-% \purefamilyhex{#5}\uchexnumbers{#6}\space
-% \else\iffourthargument
-% \mathcode\the\scratchcounter="%
-% \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
-% \purefamilyhex{#3}\uchexnumbers{#4}\space
-% \fi\fi\to\mathtoks
-% \let\purefamilyhex\normalpurefamilyhex
-% \tracemathcharacter{#1}}
-
-\newtoks\mathscratchtoks
-
-\def\definemathcharacter
- {\chardef\mathcharactermode\zerocount
- \dosixtupleempty\dodefinemathcharacter}
-
-\def\redefinemathcharacter
- {\chardef\mathcharactermode\plusone
- \dosixtupleempty\dodefinemathcharacter}
-
-\def\dodefinemathcharacter[#1][#2][#3][#4][#5][#6]%
- {\ifcase\mathcharactermode
- \setmathtoks
- \or
- \let\mathtoks\mathscratchtoks \mathtoks\emptytoks
- \fi
- \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
- \doifnumberelse{#1}
- {\scratchcounter#1}
- {\scratchcounter\@EA`\string#1}%
- \appendetoks
- \ifsixthargument
- \delcode\the\scratchcounter="%
- \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
- \purefamilyhex{#3}\uchexnumbers{#4}%
- \purefamilyhex{#5}\uchexnumbers{#6}\space
- \else\iffourthargument
- \mathcode\the\scratchcounter="%
- \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
- \purefamilyhex{#3}\uchexnumbers{#4}\space
- \fi\fi
- \to \mathtoks
- \let\purefamilyhex\normalpurefamilyhex
- \ifcase\mathcharactermode
- \expandafter\tracemathcharacter
- \or
- \the\mathtoks
- \mathtoks\emptytoks
- \expandafter\gobbleoneargument
- \fi{#1}} % maybe lookahead
-
-\def\tracemathcharacter#1%
- {\iftracemathcollection
- {\endgraf
- \doifnumberelse{#1}
- {\hbox{\tttf\rawcharacter{#1}~:~{\mathematics{\rawcharacter{#1}}}}}
- {\hbox{\type{#1}~:~{\mathematics{#1}}}}
- \endgraf}%
- \fi}
-
-\def\definemathcommand
- {\dotripleempty\dodefinemathcommand}
-
-\def\dodefinemathcommand[#1][#2][#3]#4% command class args meaning
- {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
- \ifthirdargument
- \processaction
- [#3]
- [one=>\setvalue{\@mt@\mathcollection#1}##1{\puremathcomm{#2}{#4{##1}}},
- two=>\setvalue{\@mt@\mathcollection#1}##1##2{\puremathcomm{#2}{#4{##1}{##2}}}]%
- \else\ifsecondargument
- \setvalue{\@mt@\mathcollection#1}{\puremathcomm{#2}{#4}}%
- \else
- \setvalue{\@mt@\mathcollection#1}{\puremathcomm{nothing}{#4}}%
- \fi\fi
- \tracemathcommand{#1}}
-
-\def\tracemathcommand#1%
- {\iftracemathcollection
- \endgraf\hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}\endgraf
- \fi}
-
-\def\startmathcollection[#1]%
- {\pushmacro\mathcollection
- \setmathcollection{#1}}
-
-\def\setmathcollection#1%
- {\edef\mathcollection{#1}%
- \doifundefined{\@ml@\mathcollection}
- {\expandafter\newtoks\csname\@ml@\mathcollection\endcsname}}
-
-\def\stopmathcollection
- {\popmacro\mathcollection}
-
-\def\startrawmathcollection
- {\startmathcollection}
-
-\def\stoprawmathcollection
- {\stopmathcollection}
-
-\newtoks\mathtoks
-
-\def\setmathtoks
- {\@EA\let\@EA\mathtoks\csname\@ml@\mathcollection\endcsname}
-
-\def\currentmathcollection{\mathcollection}
-
-\let\nomathcollection\s!default
-
-\def\enablemathcollection[#1]%
- {\doifnot{#1}\s!default
- {\setmathcollection\s!default
- \the\csname\@ml@\mathcollection\endcsname}%
- \setmathcollection{#1}%
- \the\csname\@ml@\mathcollection\endcsname}
-
-% hook 'm into the font mechanism
-
-\definefilesynonym[\f!mathprefix\s!default][\f!mathprefix tex]
-
-\def\usemathcollection
- {\dodoubleempty\dousemathcollection}
-
-\def\dousemathcollection[#1][#2]%
- {\pushmacro\fontclass
- \pushmacro\mathclass
- \ifsecondargument
- \edef\fontclass{#1}%
- \edef\mathclass{#2}%
- \else
- \edef\mathclass{#1}%
- \fi
- \doinputonce{\truefilename{\f!mathprefix\mathclass}}%
- \doifsomething\fontclass{\setevalue{\@mc@\fontclass\@mc@}{\mathclass}}%
- \popmacro\mathclass
- \popmacro\fontclass}
-
-\let\mathclass\nomathcollection
-
-\letvalue{\@mc@\@mc@}\nomathcollection
-
-% \def\autoenablemathcollection
-% {\doifdefinedelse{\@mc@\fontclass\@mc@}
-% {\enablemathcollection[\getvalue{\@mc@\fontclass\@mc@}]}
-% {\enablemathcollection[\s!default]}} % ? ? ?
-
-\def\autoenablemathcollection
- {\expanded{\enablemathcollection[\executeifdefined{\@mc@\fontclass\@mc@}\nomathcollection]}}
-
-\appendtoks\autoenablemathcollection\to\mathstrategies
-
-\fetchruntimecommand \showmathcharacters {\f!mathprefix\s!run}
-\fetchruntimecommand \showmathtoken {\f!mathprefix\s!run}
-
-\def\resetmathcollection[#1]%
- {\def\mathcollection{#1}%
- \forgetdoingonce{\f!mathprefix\mathcollection}%
- \setmathtoks
- \ifx\mathtoks\relax\else\mathtoks\emptytoks\fi}
-
-%D \macros
-%D {ifmathpunctuation, enablemathpunctuation,
-%D definemathpunctuation}
-%D
-%D This will replace periods by comma's:
-%D
-%D \starttyping
-%D \definemathpunctuation . textcomma textperiod
-%D \definemathpunctuation , textcomma textcomma
-%D
-%D \appendtoks
-%D \redefinemathcharacter [.] [ord] [mi] ["3B]%
-%D \to \everymathpunctuation
-%D \stoptyping
-
-% \newif\ifmathpunctuation
-%
-% \def\enablemathpunctuation{\mathpunctuationtrue}
-%
-% \def\definemathpunctuation #1 #2 #3 %
-% {\appendtoks
-% \initializemathpunctuation{#1}{#2}{#3}%
-% \to\everymathematics}
-%
-% \def\initializemathpunctuation#1#2#3% sloowww
-% {\ifmathpunctuation % hm move this test to everymath, or better a separate token list
-% \mathcode`#1="8000
-% \defineactivecharacter #1 {\dohandlemathpunctuation{#2}{#3}}%
-% \fi}
-%
-% \unexpanded\def\dohandlemathpunctuation#1#2% \if fails in mathml interval
-% {\def\next{\csname\ifx\space\nexttoken#2\else#1\fi\endcsname}%
-% \futurelet\nexttoken\next}
-
-\newtoks\everymathpunctuation
-
-\def\enablemathpunctuation % can be called inside math, so after \everymathematics
- {\the\everymathpunctuation
- \appendtoksonce
- \the\everymathpunctuation
- \to\everymathematics}
-
-\def\definemathpunctuation #1 #2 #3 %
- {\appendtoks
- \initializemathpunctuation{#1}{#2}{#3}%
- \to\everymathpunctuation}
-
-\def\initializemathpunctuation#1#2#3% sloowww
- {\mathcode`#1="8000
- \defineactivecharacter #1 {\dohandlemathpunctuation{#2}{#3}}}
-
-\unexpanded\def\dohandlemathpunctuation#1#2% \if fails in mathml interval
- {\def\next{\csname\ifx\space\nexttoken#2\else#1\fi\endcsname}%
- \futurelet\nexttoken\next}
-
-%D \startbuffer
-%D \enablemathpunctuation$(1,2) (1, 2) (1{,}2) \hbox{foo, not bar}$
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \blank{\getbuffer}\blank
-
-%D needed for sin, cos etc
-
-\def\mfunction #1{{\mr#1}}
-
-% \def\mlimitsfunction #1{\mathlimopcomm{{\mr#1}}
-% \def\mnolimitsfunction#1{\mathnolopcomm{{\mr#1}}
-
-%D Taco posted this solution as response to a mail by Olivier, so
-%D let's integrate it here.
-
-% \def\setmathfunctionstyle#1% rm ss tt
-% {\def\mfunction##1% no families, just scaling a la text
-% {\mathchoice
-% {\hbox{\csname#1\endcsname\tf ##1}}
-% {\hbox{\csname#1\endcsname\tf ##1}}
-% {\hbox{\csname#1\endcsname\tfx ##1}}
-% {\hbox{\csname#1\endcsname\tfxx##1}}}}
-
-\def\currentmscaledstyle{rm} % will be plugged into the typeface text=ss option
-
-\def\setmathfunctionstyle#1% rm ss tt
- {\doifsomething{#1}
- {\def\currentmscaledstyle{#1}%
- \def\mathopnolimits##1{\mathop{\mscaledtext{##1}}\nolimits}%
- \def\mfunction##1{\mscaledtext{##1}}}}
-
-\def\mscaledtext#1%
- {\mathchoice
- {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
- {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}}
- {\hbox{\csname\currentmscaledstyle\endcsname\tfx #1}}
- {\hbox{\csname\currentmscaledstyle\endcsname\tfxx#1}}}
-
-%D We can force the way functions are typeset by manipulating the text
-%D option:
-%D
-%D \starttyping
-%D \definetypeface[iwona][ss][sans][iwona][default][encoding=texnansi]
-%D \definetypeface[iwona][mm][math][iwona][default][encoding=texnansi,text=ss]
-%D \stoptyping
-%D
-%D This hooks into the math handler with:
-
-\appendtoks
- \setmathfunctionstyle\currentmathtextstyle
-\to \everybodyfont
-
-%D Usage:
-%D
-%D \starttyping
-%D \setmathfunctionstyle\fontstyle % or {rm} or {ss} or ..
-%D \rm test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
-%D \ss test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
-%D \tt test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
-%D \stoptyping
-
-\edef\hexmrfam {0} \edef\hexbsfam {8}
-\edef\hexmifam {1} \edef\hexbifam {9}
-\edef\hexsyfam {2} \edef\hexscfam {A}
-\edef\hexexfam {3} \edef\hextffam {B}
-\edef\hexitfam {4} \edef\hexmafam {C}
-\edef\hexslfam {5} \edef\hexmbfam {D}
-\edef\hexbffam {6} \edef\hexmcfam {E}
-\edef\hexnnfam {7} \edef\hexmdfam {F}
-
-\definefamilysynonym [default] [letters] [mr]
-\definefamilysynonym [default] [operators] [sy]
-\definefamilysynonym [default] [lcgreek] [mi]
-\definefamilysynonym [default] [ucgreek] [mr]
-\definefamilysynonym [default] [vargreek] [mi]
-\definefamilysynonym [default] [mitfamily] [mi]
-\definefamilysynonym [default] [calfamily] [sy]
-
-\definefamilysynonym [default] [0] [mr]
-\definefamilysynonym [default] [1] [mi]
-\definefamilysynonym [default] [2] [sy]
-\definefamilysynonym [default] [3] [ex]
-
-\enablemathcollection[default]
-
-\usemathcollection [default] [tex]
-\usemathcollection [default] [ams]
-\usemathcollection [default] [uni]
-
-\enablemathcollection[default]
-
-%D Some goodies:
-
-\def\Angstrom{\nomathematics{\Aring}}
-
-%D Bold math:
-%D
-%D \starttyping
-%D \usetypescript [lucida] [texnansi]
-%D
-%D \definetypeface [boldmath] [rm] [serif]
-%D [lucida] [default] [encoding=texnansi]
-%D \definetypeface [boldmath] [tt] [mono]
-%D [lucida] [default] [encoding=texnansi]
-%D \definetypeface [boldmath] [ss] [sans]
-%D [lucida] [default] [encoding=texnansi]
-%D \definetypeface [boldmath] [mm] [boldmath]
-%D [lucida] [default] [encoding=texnansi]
-%D
-%D \switchtobodyfont[lucida,10pt]
-%D
-%D \showmathtoken{Gamma} $\Gamma \Delta \alpha \delta \zeta$
-%D
-%D \switchtobodyfont[boldmath,10pt]
-%D
-%D \showmathtoken{Gamma} $\Gamma \Delta \alpha \delta \zeta$
-%D \stoptyping
-
-%D \macros
-%D {nonknuthmode, donknuthmode}
-%D
-%D The underscore is frequently used in manuals but unfortunately \TEX\ prefers
-%D it to be a math specific character. And since computer modern fonts didn't
-%D have an underscore, one had to use commands to fake one. Nowadays we do
-%D have underscores in latin modern, and since all other fonts have them, we
-%D decided to get away from the restriction to use the underscore character in
-%D text mode.
-%D
-%D \starttyping
-%D \def\test#1{#1}
-%D
-%D \nonknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
-%D
-%D \donknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
-%D \stoptyping
-%D
-%D The result is as expected: the first line typesets ok, while the second
-%D one triggers an error message.
-
-\bgroup
-
- \ifx\normalsuber\undefined \def\normalsuber{_} \fi
- \ifx\normalsuper\undefined \def\normalsuper{^} \fi
-
- \catcode`_=\active
- \catcode`^=\active
-
- \gdef\nonknuthmode
- {\appendtoks\let_\normalsuber\let^\normalsuper\to\everymathematics
- \mathcode`_="8000
- \mathcode`^="8000
- \catcode`_=\@@other
- \catcode`^=\@@other
- \let\nonknuthmode\relax}
-
- \gdef\donknuthmode
- {\catcode`_=\@@subscript
- \catcode`^=\@@superscript}
-
-\egroup
-
-%D \macros
-%D {checkdelimiters, fakeleftdelimiter, fakerightdelimiter}
-%D
-%D Handy for non matching situations (as with mathml):
-%D
-%D \starttyping
-%D \checkdelimiters{... bla bla ...}
-%D \fakeleftdelimiter
-%D ... bla bla ...
-%D \fakerightdelimiter
-%D \stoptyping
-
-\newcount\delimitercount
-
-\def\leftfakedelimiter {\advance\delimitercount\minusone\gobbleoneargument}%
-\def\rightfakedelimiter{\advance\delimitercount\plusone \gobbleoneargument}%
-
-\def\checkdelimiters#1%
- {\delimitercount\zerocount
- \setbox\scratchbox\hbox\bgroup
- \let\left \leftfakedelimiter
- \let\right\rightfakedelimiter
- $#1\expandafter$\expandafter
- \egroup
- \expandafter\delimitercount\the\delimitercount\relax}
-
-\def\fakeleftdelimiter {\ifnum\delimitercount>\zerocount\left .\fi}
-\def\fakerightdelimiter{\ifnum\delimitercount<\zerocount\right.\fi}
-
-% \def\scaledmathdelimiter#1#2%
-% {\begingroup
-% \scratchdimen\lineheight
-% \hbox{$\left#2\vbox\!!to#1\scratchdimen{}\right.\n@space$}%
-% \endgroup}
-%
-% \let\scaledmathdelimiter\@@dobig
-%
-% \def\scaledmathopen #1#2{\mathopen {\scaledmathdelimiter{#1}{#2}}}
-% \def\scaledmathclose#1#2{\mathclose{\scaledmathdelimiter{#1}{#2}}}
-
-%D Needed for unicode:
-
-\def\nulloperator{\mathortext{\mathop{\null}}{\null}}
-
-%D Plugins.
-
-\loadmarkfile{math-ini}
-
-\protect \endinput
-
-\tracemathcollectiontrue
- \input math-tex \page
-\setupbodyfont[ams] \enablemathcollection[default] \input math-ams \page
-\setupbodyfont[lbr] \enablemathcollection[lbr] \input math-lbr \page
-\setupbodyfont[eul] \enablemathcollection[eul] \input math-eul \stoptext
diff --git a/tex/context/base/math-inl.mkiv b/tex/context/base/math-inl.mkiv
new file mode 100644
index 000000000..acbf02de7
--- /dev/null
+++ b/tex/context/base/math-inl.mkiv
@@ -0,0 +1,357 @@
+%D \module
+%D [ file=math-inl,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Inline,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA-ADE / Hans Hagen]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Inline}
+
+\unprotect
+
+%D \macros
+%D {...}
+%D
+%D New and experimental: snapping big inline math!
+
+\newconditional\halfcrazymathlines % \settrue\halfcrazymathlines
+\newconditional\crazymathsnapping % \settrue\crazymathsnapping
+
+\appendtoks
+ \doifelse\@@mtgrid\v!yes \settrue\setfalse\crazymathsnapping
+ \doifelse\@@mtstep\v!halfline\settrue\setfalse\halfcrazymathlines
+\to \everysetuptextformulas
+
+\setuptextformulas
+ [\c!grid=\v!yes,
+ \c!step=\v!line]
+
+\newcount\crazymathhack
+
+\let\lastcrazymathline \!!zeropoint
+\let\lastcrazymathpage \!!zerocount
+\let\lastcrazymathprelines \!!zerocount
+\let\lastcrazymathpostlines\!!zerocount
+
+\def\crazymathtag{amh:\the\crazymathhack}
+\def\crazytexttag{\v!text:\lastcrazymathpage}
+
+\def\crazymathindent{\hskip\MPx\crazymathtag\hskip-\MPx\crazytexttag}
+
+\def\flushcrazymathbox
+ {\nextboxht\strutheight
+ \nextboxdp\strutdepth
+ \hbox{\iftracegridsnapping\ruledhbox\fi{\flushnextbox}}}
+
+\def\snappedinlineformula
+ {\dosingleempty\dosnappedinlineformula}
+
+%D \starttabulate[|Tl|l|]
+%D \NC - \NC half lines \NC \NR
+%D \NC + \NC full lines \NC \NR
+%D \NC = \NC force \NC \NR
+%D \NC < \NC force, minus pre \NC \NR
+%D \NC > \NC force, minus post \NC \NR
+%D \stoptabulate
+
+\def\inlinemathmargin{1pt}
+
+\settrue\autocrazymathsnapping
+
+% FROM NOW ON, CHANGES AS OPTIONS
+
+% TODO: SKYLINE (PREV LINE POS SCAN)
+
+% we can rewrite this in lua but maybe we don't need it
+% any more when we have proper snapping anyway
+
+\def\dosnappedinlineformula[#1]#2%
+ {\ifvmode\dontleavehmode\fi % tricky
+ \strut % prevents funny space at line break
+ \begingroup % interesting: \bgroup can make \vadjust disappear
+ \ifconditional\crazymathsnapping
+ \ifgridsnapping
+ \checktextbackgrounds % we need pos tracking, to be made less redundant
+ \donetrue
+ \else
+ \donefalse
+ \fi
+ \else
+ \donefalse
+ \fi
+ \!!doneafalse % forced or not auto
+ \!!donebfalse % too heigh
+ \!!donecfalse % too low
+ \!!donedfalse % less before
+ \!!doneefalse % less after
+ \ifdone
+ \setbox\nextbox\hbox{$#2$}%
+ \iftracegridsnapping
+ \setbox\nextbox\ruledhbox
+ {\incolortrue\localcolortrue
+ \backgroundline[gray]{\showstruts\strut\flushnextbox}}%
+ \fi
+ \def\docommand##1%
+ {\doif{##1}-{\settrue \halfcrazymathlines}%
+ \doif{##1}+{\setfalse\halfcrazymathlines}%
+ \doif{##1}={\!!doneatrue}%
+ \doif{##1}<{\!!donedtrue}%
+ \doif{##1}>{\!!doneetrue}}%
+ \processcommalist[#1]\docommand
+ \if!!doneb
+ \if!!donec \else
+ \setfalse\halfcrazymathlines
+ \fi
+ \else
+ \if!!donec
+ \setfalse\halfcrazymathlines
+ \fi
+ \fi
+ \donefalse
+ \if!!donea
+ \donetrue
+ \scratchdimen \nextboxht
+ \advance\scratchdimen .5\lineheight
+ \nextboxht\scratchdimen
+ \scratchdimen \nextboxdp
+ \advance\scratchdimen .5\lineheight
+ \nextboxdp\scratchdimen
+ \else\ifdim\nextboxht>\strutht
+ \donetrue
+ \else\ifdim\nextboxdp>\strutdp
+ \donetrue
+ \fi\fi\fi
+ \ifconditional\autocrazymathsnapping \else \if!!donea \else
+ % don't compensate, just snap to strut
+ \donefalse
+ % signal for next else, snap line to strut
+ \!!doneatrue
+ \fi \fi
+ \fi
+ \ifdone
+ % analyze height
+ \scratchdimen\inlinemathmargin
+ \advance\scratchdimen \strutht
+ \ifdim\nextboxht<\scratchdimen \else \!!donebtrue \fi
+ % analyze depth
+ \scratchdimen\inlinemathmargin
+ \advance\scratchdimen \strutdp
+ \ifdim\nextboxdp<\scratchdimen \else \!!donectrue \fi
+ % analyzed or forced
+ \ifdone
+ \global\advance\crazymathhack\plusone
+ \donefalse
+ \ifnum\MPp\crazymathtag=\lastcrazymathpage\relax
+ \ifdim\MPy\crazymathtag=\lastcrazymathline\relax
+ \donetrue
+ \fi
+ \fi
+ \ifnum\MPp\crazymathtag=\zerocount \donefalse \fi
+ \ifdim\MPy\crazymathtag=\zeropoint \donefalse \fi
+ \ifdone
+ % same page and same line
+ \else
+ \global\let\lastcrazymathprelines \!!zerocount
+ \global\let\lastcrazymathpostlines\!!zerocount
+ \xdef\lastcrazymathpage{\MPp\crazymathtag}%
+ \xdef\lastcrazymathline{\MPy\crazymathtag}%
+ \fi
+ \if!!doneb
+ % \getrawnoflines\nextboxht
+ \scratchdimen\nextboxht
+ \advance\scratchdimen-\strutht
+ \getnoflines\scratchdimen
+ \if!!doned \advance\noflines\minusone \fi
+ \scratchcounter\noflines
+ \advance\noflines-\lastcrazymathprelines\relax
+ \ifnum\noflines>\zerocount
+ \xdef\lastcrazymathprelines{\the\scratchcounter}%
+ \scratchdimen\noflines\lineheight
+ \ifconditional\halfcrazymathlines
+ \advance\scratchdimen-.5\lineheight
+ \fi
+ \advance\scratchdimen-\strutdepth
+ \setbox\scratchbox\null
+ \wd\scratchbox2\bodyfontsize
+ \ht\scratchbox\scratchdimen
+ \dp\scratchbox\strutdepth
+ %%% top correction code (see below)
+ \normalvadjust pre
+ {%\allowbreak % sometimes breaks spacing
+ \forgetall
+ \crazymathindent
+ \iftracegridsnapping
+ \setbox\scratchbox\hbox
+ {\incolortrue\localcolortrue\green
+ \ruledhbox{\box\scratchbox}}%
+ \fi
+ \box\scratchbox
+ \endgraf
+ \nobreak}%
+ \else\ifnum\scratchcounter>\zerocount
+ \normalvadjust pre
+ {\nobreak}%
+ \fi\fi
+ \fi
+ \if!!donec
+ % \getrawnoflines\nextboxdp
+ \scratchdimen\nextboxdp
+ \advance\scratchdimen-\strutdp
+ \getnoflines\scratchdimen
+ \if!!donee \advance\noflines\minusone \fi
+ \scratchcounter\noflines
+ \advance\noflines-\lastcrazymathpostlines\relax
+ \ifnum\noflines>\zerocount
+ \donetrue
+ \else\ifnum\lastcrazymathpostlines=\zerocount
+ \donetrue
+ \else
+ \donefalse
+ \fi\fi
+ \else
+ \donefalse
+ \fi
+ \ifdone
+ \xdef\lastcrazymathpostlines{\the\scratchcounter}%
+ \ifnum\lastcrazymathpostlines=\zerocount
+ \global\let\lastcrazymathpostlines\!!plusone
+ \fi
+ \hbox{\setposition\crazymathtag\flushcrazymathbox}%
+ \scratchdimen\noflines\lineheight
+ \advance\scratchdimen-\lineheight
+ \advance\scratchdimen+\strutheight
+ \ifdim\scratchdimen>\zeropoint \else
+ \scratchdimen\strutheight % todo : test for half lines
+ \fi
+ \ifconditional\halfcrazymathlines
+ \advance\scratchdimen-.5\lineheight
+ \fi
+ \setbox\scratchbox\null
+ \wd\scratchbox2\bodyfontsize
+ \ht\scratchbox\scratchdimen
+ \dp\scratchbox\strutdepth
+ \normalvadjust
+ {\forgetall
+ \crazymathindent
+ \iftracegridsnapping
+ \setbox\scratchbox\hbox
+ {\incolortrue\localcolortrue\color[blue]{\ruledhbox{\box\scratchbox}}}%
+ \fi
+ \box\scratchbox
+ \endgraf
+ % precaution: else we stick below the text bottom
+ \ifconditional\halfcrazymathlines
+ \allowbreak
+ \else
+ \vskip-\lineheight
+ \vskip \lineheight
+ \fi}%
+ \else
+ \hbox{\setposition\crazymathtag\flushcrazymathbox}%
+ \fi
+ \else
+ \flushcrazymathbox
+ \fi
+ \else\if!!donea
+ \flushcrazymathbox
+ \else
+ \mathematics{#2}%
+ \fi\fi
+ \endgroup}
+
+\let\tform\mathematics
+\let\gform\snappedinlineformula
+
+% test set:
+%
+% \startbuffer
+% Crazy math \gform {1+x} or \gform {\dorecurse {100} {1+} 1 =
+% 101} and even gore crazy \gform {2^{2^2}_{1_1}}
+% again\dorecurse {20} { and again} \gform {\sqrt {\frac
+% {x^{5^5}} {\frac {1} {2}}}} even gore\dorecurse {50} { and
+% gore} \tform {\dorecurse {12} {\gform {\sqrt {\frac
+% {x^{5^5}} {3}}}+\gform {\sqrt {\frac {x^{5^5}} {\frac {1}
+% {2}}}}+}x=10}\dorecurse{20} { super crazy math}: \tform
+% {\dorecurse {30} {\gform {\sqrt {\frac {x^{5^5}} {3}}}+
+% \gform {\sqrt {\frac {x^{5^5}} {\frac {1} {2}}}}+ }x = 10},
+% and we're\dorecurse {20} { done}!
+% \stopbuffer
+%
+% \setupcolors[state=start] \setuppapersize[S6][S6]
+%
+% \showgrid \tracegridsnappingtrue \showstruts
+%
+% \starttext
+% \setuplayout[grid=yes,lines=15]\getbuffer \page
+% \setuplayout[grid=yes,lines=16]\getbuffer \page
+% \setuplayout[grid=yes,lines=17]\getbuffer \page
+% \setuplayout[grid=yes,lines=18]\getbuffer \page
+% \setuplayout[grid=yes,lines=19]\getbuffer \page
+% \stoptext
+%
+% test
+%
+% \startregels
+% \gform[<]{35 \cdot p^{\frac{3}{4}} = 70}
+% \gform{12{,}4 \cdot d^3 = 200}
+% \gform{a \cdot x^b}.
+% \gform{12x^6 \cdot \negative 3x^4}
+% \gform{\frac{12x^6}{\negative 3x^4}}
+% \gform{(4x^2)^3}
+% \gform{4x \sqrt{x} \cdot 3x^2}
+% \gform{\frac{2x^4}{4x \sqrt{x}}}
+% \gform{y = a \cdot x^b}.
+% \gform{y_1 = \frac{15x^2}{x}}
+% \gform{y_2 = x \cdot \sqrt{x}}
+% \gform{y_3 = \frac{6x^3}{x^2}}
+% \gform[<]{y_4 = \left(2x^2\right)^{\frac{1}{2}}}
+% \gform{y_1 = \frac{4x^5}{x^2}}
+% \gform{y_2 = 4 \cdot \sqrt{x}}
+% \gform{y_3 = 4x^3}
+% \gform{y_4 = \frac{100x}{\sqrt{x}}}
+% \gform[<]{y_5 = 4 \cdot x^{\frac{1}{2}}}
+% \gform{y_6 = \frac{1}{2} x \cdot 4x^2}
+% \gform{y_7 = 2 \cdot x^3}
+% \gform{y_8 = 100 \cdot x^{\frac{1}{2}}}
+% \gform{4x^8 \cdot 8x^3}
+% \gform{\frac{4x^8}{8x^3}}
+% \gform{\left(\negative3x^4\right)^3}
+% \gform{x^3 \sqrt{x} \cdot 3x^2}
+% \gform{\frac{6x^3}{x^2 \sqrt{x}}}
+% \gform{\frac{6}{2x^4}}
+% \gform{\frac{1}{3x^6}}
+% \gform{\frac{12x^8}{4x^{10}}}
+% \gform{\frac{4}{\sqrt{x}}}
+% \gform{\frac{1}{2x \sqrt{x}}}
+% \gform{\frac{2{,}25}{p} = 0{,}35}
+% \gform{4{,}50 + \frac{300}{k} = 4{,}70}
+% \gform{\frac{1200}{k+12} - 42 = 6}
+% \stopregels
+
+%D \macros
+%D {enableautomath}
+%D
+%D The next one can be dangerous, but handy in controlled
+%D situations.
+
+\bgroup \catcode`\$=\active
+
+\gdef\enableautomath
+ {\catcode`\$=\active
+ \def$##1${\snappedinlineformula{##1}}}
+
+% \gdef\enableautomath
+% {\catcode`\$=\active
+% \def${\doifnextcharelse$\doautodmath\doautoimath}%
+% \def\doautoimath##1${\snappedinlineformula{##1}}%
+% \def\doautodmath$##1$${\startformula##1\stopformula}}
+
+\egroup
+
+\protect \endinput
diff --git a/tex/context/base/math-int.mkiv b/tex/context/base/math-int.mkiv
new file mode 100644
index 000000000..8ac2d4776
--- /dev/null
+++ b/tex/context/base/math-int.mkiv
@@ -0,0 +1,87 @@
+%D \module
+%D [ file=math-int,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Scripts,
+%D author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Integrals}
+
+\unprotect
+
+%D \startbuffer
+%D $\int_a^b f(x) dx$ and also
+%D $\iint_a^b f(x,y) dxdy$, $\iiint_a^b f(x,y) dxdy$,
+%D $\iiiint_a^b f(x) dx$
+%D \startformula
+%D \int_a^b f(x) dx \quad
+%D \iint_a^b f(x) dx \quad
+%D \iiint_a^b f(x) dx \quad
+%D \iiiint_a^b f(x) dx \quad
+%D \stopformula
+%D \stopbuffer
+%D
+%D Default: \getbuffer
+%D
+%D Displaylimits: \setupmathematics[integral=displaylimits] \getbuffer
+%D
+%D Limits: \setupmathematics[integral=limits] \getbuffer
+
+\chardef\intlimitcode\zerocount % 0 nolimits 1 displaylimits 2 limits
+
+\def\intlimits
+ {\ifcase\intlimitcode \nolimits \or \displaylimits \or \limits \fi}
+
+\ifx\v!integral\undefined \def\v!integral{integral} \fi
+
+\appendtoks
+ \processaction
+ [\mathematicsparameter\v!integral]
+ [ nolimits=>\chardef\intlimitcode\zerocount,
+ displaylimits=>\chardef\intlimitcode\plusone,
+ limits=>\chardef\intlimitcode\plustwo]%
+\to \everysetupmathematics
+
+\setupmathematics
+ [\v!integral=nolimits]
+
+%D More integrals (AM):
+
+\definemathcommand [iint] {\repeatintegral\plusone }
+\definemathcommand [iiint] {\repeatintegral\plustwo }
+\definemathcommand [iiiint] {\repeatintegral\plusthree}
+
+\def\repeatintegral#1%
+ {\scratchtoks\emptytoks
+ \let\dointlimits\donothing
+ \let\dodointlimits\intlimits
+ \dorecurse{#1}{\appendtoks \intop \dointkern \to \scratchtoks}
+ \appendtoks \intop \dointlimits \dodointlimits \to \scratchtoks
+ \edef\dodorepeatintegral{\the\scratchtoks}%
+ \futurelet\next\dorepeatintegral}
+
+%D If the \type{\limits} option is used after \type{\iint}, use
+%D \type{\mathop} and fudge the left hand space a bit to make the
+%D subscript visually centered.
+
+\def\dointkern
+ {\mkern-6mu\mathchoice{\mkern-3mu}{}{}{}}
+
+\def\dorepeatintegral
+ {\ifx\next\limits \dointlimitcorrection \else
+ \ifx\next\displaylimits \dointlimitcorrection \else
+ \ifx\next\nolimits \donothing \else
+ \ifcase\intlimitcode\else \dointlimitcorrection \fi\fi\fi\fi
+ \dodorepeatintegral}
+
+\def\dointlimitcorrection
+ {\mkern-7mu\mathchoice{\mkern-2mu}{}{}{}%
+ \mathop\bgroup\mkern7mu\mathchoice{\mkern2mu}{}{}{}\let\dointlimits\egroup}
+
+\protect \endinput
diff --git a/tex/context/base/math-lbr.tex b/tex/context/base/math-lbr.tex
index ecc3632b1..7ac7c3aff 100644
--- a/tex/context/base/math-lbr.tex
+++ b/tex/context/base/math-lbr.tex
@@ -394,12 +394,12 @@
\stopmathcollection
\def\LBRroot#1#2%
- {\setbox\z@\hbox{$\m@th#1\sqrt{#2}$}
- \dimen@\ht\z@ \advance\dimen@-\dp\z@
- \mkern5mu\raise.6\dimen@\copy\rootbox \mkern-7.5mu \box\z@}
+ {\setbox\zerocount\hbox{$\mathsurround\zeropoint#1\sqrt{#2}$}
+ \dimen@\ht\zerocount \advance\dimen@-\dp\zerocount
+ \mkern5mu\raise.6\dimen@\copy\rootbox \mkern-7.5mu \box\zerocount}
\def\LBRmatrix#1%
- {\null\,\vcenter{\normalbaselines\m@th
+ {\null\,\vcenter{\normalbaselines\mathsurround\zeropoint
\ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
\mathstrut\crcr\noalign{\kern-0.9\baselineskip}
#1\crcr\mathstrut\crcr\noalign{\kern-0.9\baselineskip}}}\,}
diff --git a/tex/context/base/math-map.lua b/tex/context/base/math-map.lua
new file mode 100644
index 000000000..0229790c2
--- /dev/null
+++ b/tex/context/base/math-map.lua
@@ -0,0 +1,365 @@
+if not modules then modules = { } end modules ['math-map'] = {
+ version = 1.001,
+ comment = "companion to math-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
Remapping mathematics alphabets.
+--ldx]]--
+
+-- oldstyle: not really mathematics but happened to be part of
+-- the mathematics fonts in cmr
+--
+-- persian: we will also provide mappers for other
+-- scripts
+
+-- todo: alphabets namespace
+-- maybe: script/scriptscript dynamic,
+
+local type, next = type, next
+
+mathematics = mathematics or { }
+
+-- we could use one level less and have tf etc be tables directly but the
+-- following approach permits easier remapping of a-a, A-Z and 0-9 to
+-- fallbacks; symbols is currently mostly greek
+
+mathematics.alphabets = {
+ regular = {
+ tf = {
+ digits = 0x00030,
+ ucletters = 0x00041,
+ lcletters = 0x00061,
+ symbols = {
+ [0x0391]=0x0391, [0x0392]=0x0392, [0x0393]=0x0393, [0x0394]=0x0394, [0x0395]=0x0395,
+ [0x0396]=0x0396, [0x0397]=0x0397, [0x0398]=0x0398, [0x0399]=0x0399, [0x039A]=0x039A,
+ [0x039B]=0x039B, [0x039C]=0x039C, [0x039D]=0x039D, [0x039E]=0x039E, [0x039F]=0x039F,
+ [0x03A0]=0x03A0, [0x03A1]=0x03A1, [0x03A3]=0x03A3, [0x03A4]=0x03A4, [0x03A5]=0x03A5,
+ [0x03A6]=0x03A6, [0x03A7]=0x03A7, [0x03A8]=0x03A8, [0x03A9]=0x03A9, [0x03B1]=0x03B1,
+ [0x03B2]=0x03B2, [0x03B3]=0x03B3, [0x03B4]=0x03B4, [0x03B5]=0x03B5, [0x03B6]=0x03B6,
+ [0x03B7]=0x03B7, [0x03B8]=0x03B8, [0x03B9]=0x03B9, [0x03BA]=0x03BA, [0x03BB]=0x03BB,
+ [0x03BC]=0x03BC, [0x03BD]=0x03BD, [0x03BE]=0x03BE, [0x03BF]=0x03BF, [0x03C0]=0x03C0,
+ [0x03C1]=0x03C1, [0x03C2]=0x03C2, [0x03C3]=0x03C3, [0x03C4]=0x03C4, [0x03C5]=0x03C5,
+ [0x03C6]=0x03C6, [0x03C7]=0x03C7, [0x03C8]=0x03C8, [0x03C9]=0x03C9, [0x03D1]=0x03D1,
+ [0x03D5]=0x03D5, [0x03D6]=0x03D6, [0x03F0]=0x03F0, [0x03F1]=0x03F1, [0x03F4]=0x03F4,
+ [0x03F5]=0x03F5, [0x2202]=0x2202, [0x2207]=0x2207,
+ },
+ },
+ it = {
+ ucletters = 0x1D434,
+ lcletters = { -- H
+ [0x00061]=0x1D44E, [0x00062]=0x1D44F, [0x00063]=0x1D450, [0x00064]=0x1D451, [0x00065]=0x1D452,
+ [0x00066]=0x1D453, [0x00067]=0x1D454, [0x00068]=0x0210E, [0x00069]=0x1D456, [0x0006A]=0x1D457,
+ [0x0006B]=0x1D458, [0x0006C]=0x1D459, [0x0006D]=0x1D45A, [0x0006E]=0x1D45B, [0x0006F]=0x1D45C,
+ [0x00070]=0x1D45D, [0x00071]=0x1D45E, [0x00072]=0x1D45F, [0x00073]=0x1D460, [0x00074]=0x1D461,
+ [0x00075]=0x1D462, [0x00076]=0x1D463, [0x00077]=0x1D464, [0x00078]=0x1D465, [0x00079]=0x1D466,
+ [0x0007A]=0x1D467,
+ },
+ symbols = {
+ [0x0391]=0x1D6E2, [0x0392]=0x1D6E3, [0x0393]=0x1D6E4, [0x0394]=0x1D6E5, [0x0395]=0x1D6E6,
+ [0x0396]=0x1D6E7, [0x0397]=0x1D6E8, [0x0398]=0x1D6E9, [0x0399]=0x1D6EA, [0x039A]=0x1D6EB,
+ [0x039B]=0x1D6EC, [0x039C]=0x1D6ED, [0x039D]=0x1D6EE, [0x039E]=0x1D6EF, [0x039F]=0x1D6F0,
+ [0x03A0]=0x1D6F1, [0x03A1]=0x1D6F2, [0x03A3]=0x1D6F4, [0x03A4]=0x1D6F5, [0x03A5]=0x1D6F6,
+ [0x03A6]=0x1D6F7, [0x03A7]=0x1D6F8, [0x03A8]=0x1D6F9, [0x03A9]=0x1D6FA, [0x03B1]=0x1D6FC,
+ [0x03B2]=0x1D6FD, [0x03B3]=0x1D6FE, [0x03B4]=0x1D6FF, [0x03B5]=0x1D700, [0x03B6]=0x1D701,
+ [0x03B7]=0x1D702, [0x03B8]=0x1D703, [0x03B9]=0x1D704, [0x03BA]=0x1D705, [0x03BB]=0x1D706,
+ [0x03BC]=0x1D707, [0x03BD]=0x1D708, [0x03BE]=0x1D709, [0x03BF]=0x1D70A, [0x03C0]=0x1D70B,
+ [0x03C1]=0x1D70C, [0x03C2]=0x1D70D, [0x03C3]=0x1D70E, [0x03C4]=0x1D70F, [0x03C5]=0x1D710,
+ [0x03C6]=0x1D711, [0x03C7]=0x1D712, [0x03C8]=0x1D713, [0x03C9]=0x1D714, [0x03D1]=0x1D717,
+ [0x03D5]=0x1D719, [0x03D6]=0x1D71B, [0x03F0]=0x1D718, [0x03F1]=0x1D71A, [0x03F4]=0x1D6F3,
+ [0x03F5]=0x1D716, [0x2202]=0x1D715, [0x2207]=0x1D6FB,
+ },
+ },
+ bf= {
+ digits = 0x1D7CE,
+ ucletters = 0x1D400,
+ lcletters = 0x1D41A,
+ symbols = {
+ [0x0391]=0x1D6A8, [0x0392]=0x1D6A9, [0x0393]=0x1D6AA, [0x0394]=0x1D6AB, [0x0395]=0x1D6AC,
+ [0x0396]=0x1D6AD, [0x0397]=0x1D6AE, [0x0398]=0x1D6AF, [0x0399]=0x1D6B0, [0x039A]=0x1D6B1,
+ [0x039B]=0x1D6B2, [0x039C]=0x1D6B3, [0x039D]=0x1D6B4, [0x039E]=0x1D6B5, [0x039F]=0x1D6B6,
+ [0x03A0]=0x1D6B7, [0x03A1]=0x1D6B8, [0x03A3]=0x1D6BA, [0x03A4]=0x1D6BB, [0x03A5]=0x1D6BC,
+ [0x03A6]=0x1D6BD, [0x03A7]=0x1D6BE, [0x03A8]=0x1D6BF, [0x03A9]=0x1D6C0, [0x03B1]=0x1D6C2,
+ [0x03B2]=0x1D6C3, [0x03B3]=0x1D6C4, [0x03B4]=0x1D6C5, [0x03B5]=0x1D6C6, [0x03B6]=0x1D6C7,
+ [0x03B7]=0x1D6C8, [0x03B8]=0x1D6C9, [0x03B9]=0x1D6CA, [0x03BA]=0x1D6CB, [0x03BB]=0x1D6CC,
+ [0x03BC]=0x1D6CD, [0x03BD]=0x1D6CE, [0x03BE]=0x1D6CF, [0x03BF]=0x1D6D0, [0x03C0]=0x1D6D1,
+ [0x03C1]=0x1D6D2, [0x03C2]=0x1D6D3, [0x03C3]=0x1D6D4, [0x03C4]=0x1D6D5, [0x03C5]=0x1D6D6,
+ [0x03C6]=0x1D6D7, [0x03C7]=0x1D6D8, [0x03C8]=0x1D6D9, [0x03C9]=0x1D6DA, [0x03D1]=0x1D6DD,
+ [0x03D5]=0x1D6DF, [0x03D6]=0x1D6E1, [0x03F0]=0x1D6DE, [0x03F1]=0x1D6E0, [0x03F4]=0x1D6B9,
+ [0x03F5]=0x1D6DC, [0x2202]=0x1D6DB, [0x2207]=0x1D6C1,
+ },
+ },
+ bi = {
+ ucletters = 0x1D468,
+ lcletters = 0x1D482,
+ symbols = {
+ [0x0391]=0x1D71C, [0x0392]=0x1D71D, [0x0393]=0x1D71E, [0x0394]=0x1D71F, [0x0395]=0x1D720,
+ [0x0396]=0x1D721, [0x0397]=0x1D722, [0x0398]=0x1D723, [0x0399]=0x1D724, [0x039A]=0x1D725,
+ [0x039B]=0x1D726, [0x039C]=0x1D727, [0x039D]=0x1D728, [0x039E]=0x1D729, [0x039F]=0x1D72A,
+ [0x03A0]=0x1D72B, [0x03A1]=0x1D72C, [0x03A3]=0x1D72E, [0x03A4]=0x1D72F, [0x03A5]=0x1D730,
+ [0x03A6]=0x1D731, [0x03A7]=0x1D732, [0x03A8]=0x1D733, [0x03A9]=0x1D734, [0x03B1]=0x1D736,
+ [0x03B2]=0x1D737, [0x03B3]=0x1D738, [0x03B4]=0x1D739, [0x03B5]=0x1D73A, [0x03B6]=0x1D73B,
+ [0x03B7]=0x1D73C, [0x03B8]=0x1D73D, [0x03B9]=0x1D73E, [0x03BA]=0x1D73F, [0x03BB]=0x1D740,
+ [0x03BC]=0x1D741, [0x03BD]=0x1D742, [0x03BE]=0x1D743, [0x03BF]=0x1D744, [0x03C0]=0x1D745,
+ [0x03C1]=0x1D746, [0x03C2]=0x1D747, [0x03C3]=0x1D748, [0x03C4]=0x1D749, [0x03C5]=0x1D74A,
+ [0x03C6]=0x1D74B, [0x03C7]=0x1D74C, [0x03C8]=0x1D74D, [0x03C9]=0x1D74E, [0x03D1]=0x1D751,
+ [0x03D5]=0x1D753, [0x03D6]=0x1D755, [0x03F0]=0x1D752, [0x03F1]=0x1D754, [0x03F4]=0x1D72D,
+ [0x03F5]=0x1D750, [0x2202]=0x1D74F, [0x2207]=0x1D735,
+ },
+ },
+ },
+ sansserif = {
+ tf = {
+ digits = 0x1D7E2,
+ ucletters = 0x1D5A0,
+ lcletters = 0x1D5BA,
+ },
+ it = {
+ ucletters = 0x1D608,
+ lcletters = 0x1D622,
+ },
+ bf = {
+ digits = 0x1D7EC,
+ ucletters = 0x1D5D4,
+ lcletters = 0x1D5EE,
+ symbols = {
+ [0x0391]=0x1D756, [0x0392]=0x1D757, [0x0393]=0x1D758, [0x0394]=0x1D759, [0x0395]=0x1D75A,
+ [0x0396]=0x1D75B, [0x0397]=0x1D75C, [0x0398]=0x1D75D, [0x0399]=0x1D75E, [0x039A]=0x1D75F,
+ [0x039B]=0x1D760, [0x039C]=0x1D761, [0x039D]=0x1D762, [0x039E]=0x1D763, [0x039F]=0x1D764,
+ [0x03A0]=0x1D765, [0x03A1]=0x1D766, [0x03A3]=0x1D768, [0x03A4]=0x1D769, [0x03A5]=0x1D76A,
+ [0x03A6]=0x1D76B, [0x03A7]=0x1D76C, [0x03A8]=0x1D76D, [0x03A9]=0x1D76E, [0x03B1]=0x1D770,
+ [0x03B2]=0x1D771, [0x03B3]=0x1D772, [0x03B4]=0x1D773, [0x03B5]=0x1D774, [0x03B6]=0x1D775,
+ [0x03B7]=0x1D776, [0x03B8]=0x1D777, [0x03B9]=0x1D778, [0x03BA]=0x1D779, [0x03BB]=0x1D77A,
+ [0x03BC]=0x1D77B, [0x03BD]=0x1D77C, [0x03BE]=0x1D77D, [0x03BF]=0x1D77E, [0x03C0]=0x1D77F,
+ [0x03C1]=0x1D780, [0x03C2]=0x1D781, [0x03C3]=0x1D782, [0x03C4]=0x1D783, [0x03C5]=0x1D784,
+ [0x03C6]=0x1D785, [0x03C7]=0x1D786, [0x03C8]=0x1D787, [0x03C9]=0x1D788, [0x03D1]=0x1D78B,
+ [0x03D5]=0x1D78D, [0x03D6]=0x1D78F, [0x03F0]=0x1D78C, [0x03F1]=0x1D78E, [0x03F4]=0x1D767,
+ [0x03F5]=0x1D78A, [0x2202]=0x1D789, [0x2207]=0x1D76F,
+ },
+ },
+ bi = {
+ ucletters = 0x1D63C,
+ lcletters = 0x1D656,
+ symbols = {
+ [0x0391]=0x1D790, [0x0392]=0x1D791, [0x0393]=0x1D792, [0x0394]=0x1D793, [0x0395]=0x1D794,
+ [0x0396]=0x1D795, [0x0397]=0x1D796, [0x0398]=0x1D797, [0x0399]=0x1D798, [0x039A]=0x1D799,
+ [0x039B]=0x1D79A, [0x039C]=0x1D79B, [0x039D]=0x1D79C, [0x039E]=0x1D79D, [0x039F]=0x1D79E,
+ [0x03A0]=0x1D79F, [0x03A1]=0x1D7A0, [0x03A3]=0x1D7A2, [0x03A4]=0x1D7A3, [0x03A5]=0x1D7A4,
+ [0x03A6]=0x1D7A5, [0x03A7]=0x1D7A6, [0x03A8]=0x1D7A7, [0x03A9]=0x1D7A8, [0x03B1]=0x1D7AA,
+ [0x03B2]=0x1D7AB, [0x03B3]=0x1D7AC, [0x03B4]=0x1D7AD, [0x03B5]=0x1D7AE, [0x03B6]=0x1D7AF,
+ [0x03B7]=0x1D7B0, [0x03B8]=0x1D7B1, [0x03B9]=0x1D7B2, [0x03BA]=0x1D7B3, [0x03BB]=0x1D7B4,
+ [0x03BC]=0x1D7B5, [0x03BD]=0x1D7B6, [0x03BE]=0x1D7B7, [0x03BF]=0x1D7B8, [0x03C0]=0x1D7B9,
+ [0x03C1]=0x1D7BA, [0x03C2]=0x1D7BB, [0x03C3]=0x1D7BC, [0x03C4]=0x1D7BD, [0x03C5]=0x1D7BE,
+ [0x03C6]=0x1D7BF, [0x03C7]=0x1D7C0, [0x03C8]=0x1D7C1, [0x03C9]=0x1D7C2, [0x03D1]=0x1D7C5,
+ [0x03D5]=0x1D7C7, [0x03D6]=0x1D7C9, [0x03F0]=0x1D7C6, [0x03F1]=0x1D7C8, [0x03F4]=0x1D7A1,
+ [0x03F5]=0x1D7C4, [0x2202]=0x1D7C3, [0x2207]=0x1D7A9,
+ },
+ },
+ },
+ monospaced = {
+ tf = {
+ digits = 0x1D7F6,
+ ucletters = 0x1D670,
+ lcletters = 0x1D68A,
+ },
+ },
+ blackboard = { -- ok
+ tf = {
+ digits = 0x1D7D8,
+ ucletters = { -- C H N P Q R Z
+ [0x00041]=0x1D538, [0x00042]=0x1D539, [0x00043]=0x02102, [0x00044]=0x1D53B, [0x00045]=0x1D53C,
+ [0x00046]=0x1D53D, [0x00047]=0x1D53E, [0x00048]=0x0210D, [0x00049]=0x1D540, [0x0004A]=0x1D541,
+ [0x0004B]=0x1D542, [0x0004C]=0x1D543, [0x0004D]=0x1D544, [0x0004E]=0x02115, [0x0004F]=0x1D546,
+ [0x00050]=0x02119, [0x00051]=0x0211A, [0x00052]=0x0211D, [0x00053]=0x1D54A, [0x00054]=0x1D54B,
+ [0x00055]=0x1D54C, [0x00056]=0x1D54D, [0x00057]=0x1D54E, [0x00058]=0x1D54F, [0x00059]=0x1D550,
+ [0x0005A]=0x02124,
+ },
+ lcletters = 0x1D552,
+ },
+ },
+ fraktur = { -- ok
+ tf= {
+ ucletters = { -- C H I R Z
+ [0x00041]=0x1D504, [0x00042]=0x1D505, [0x00043]=0x0212D, [0x00044]=0x1D507, [0x00045]=0x1D508,
+ [0x00046]=0x1D509, [0x00047]=0x1D50A, [0x00048]=0x0210C, [0x00049]=0x02111, [0x0004A]=0x1D50D,
+ [0x0004B]=0x1D50E, [0x0004C]=0x1D50F, [0x0004D]=0x1D510, [0x0004E]=0x1D511, [0x0004F]=0x1D512,
+ [0x00050]=0x1D513, [0x00051]=0x1D514, [0x00052]=0x0211C, [0x00053]=0x1D516, [0x00054]=0x1D517,
+ [0x00055]=0x1D518, [0x00056]=0x1D519, [0x00057]=0x1D51A, [0x00058]=0x1D51B, [0x00059]=0x1D51C,
+ [0x0005A]=0x02128,
+ },
+ lcletters = 0x1D51E,
+ },
+ bf = {
+ ucletters = 0x1D56C,
+ lcletters = 0x1D586,
+ },
+ },
+ script = {
+ tf= {
+ ucletters = { -- B E F H I L M R -- P 2118
+ [0x00041]=0x1D49C, [0x00042]=0x0212C, [0x00043]=0x1D49E, [0x00044]=0x1D49F, [0x00045]=0x02130,
+ [0x00046]=0x02131, [0x00047]=0x1D4A2, [0x00048]=0x0210B, [0x00049]=0x02110, [0x0004A]=0x1D4A5,
+ [0x0004B]=0x1D4A6, [0x0004C]=0x02112, [0x0004D]=0x02133, [0x0004E]=0x1D4A9, [0x0004F]=0x1D4AA,
+ [0x00050]=0x1D4AB, [0x00051]=0x1D4AC, [0x00052]=0x0211B, [0x00053]=0x1D4AE, [0x00054]=0x1D4AF,
+ [0x00055]=0x1D4B0, [0x00056]=0x1D4B1, [0x00057]=0x1D4B2, [0x00058]=0x1D4B3, [0x00059]=0x1D4B4,
+ [0x0005A]=0x1D4B5,
+ },
+ lcletters = { -- E G O -- L 2113
+ [0x00061]=0x1D4B6, [0x00062]=0x1D4B7, [0x00063]=0x1D4B8, [0x00064]=0x1D4B9, [0x00065]=0x0212F,
+ [0x00066]=0x1D4BB, [0x00067]=0x0210A, [0x00068]=0x1D4BD, [0x00069]=0x1D4BE, [0x0006A]=0x1D4BF,
+ [0x0006B]=0x1D4C0, [0x0006C]=0x1D4C1, [0x0006D]=0x1D4C2, [0x0006E]=0x1D4C3, [0x0006F]=0x02134,
+ [0x00070]=0x1D4C5, [0x00071]=0x1D4C6, [0x00072]=0x1D4C7, [0x00073]=0x1D4C8, [0x00074]=0x1D4C9,
+ [0x00075]=0x1D4CA, [0x00076]=0x1D4CB, [0x00077]=0x1D4CC, [0x00078]=0x1D4CD, [0x00079]=0x1D4CE,
+ [0x0007A]=0x1D4CF,
+ }
+ },
+ bf = {
+ ucletters = 0x1D4D0,
+ lcletters = 0x1D4EA,
+ },
+ },
+}
+
+local alphabets = mathematics.alphabets
+local attribs = { }
+
+for alphabet, styles in next, alphabets do
+ for style, data in next, styles do
+ -- let's keep the long names (for tracing)
+ local n = #attribs+1
+ data.attribute = n
+ data.alphabet = alphabet
+ data.style = style
+ attribs[n] = data
+ end
+end
+
+-- beware, these are shared tables (no problem since they're not
+-- in unicode)
+
+alphabets.regular.it.digits = alphabets.regular.tf.digits
+alphabets.regular.bi.digits = alphabets.regular.bf.digits
+
+alphabets.sansserif.tf.symbols = alphabets.regular.tf.symbols
+alphabets.sansserif.tf.digits = alphabets.regular.tf.digits
+alphabets.sansserif.it.symbols = alphabets.regular.tf.symbols
+alphabets.sansserif.bi.digits = alphabets.regular.bf.digits
+
+alphabets.monospaced.tf.symbols = alphabets.sansserif.tf.symbols
+alphabets.monospaced.it = alphabets.sansserif.tf
+alphabets.monospaced.bf = alphabets.sansserif.tf
+alphabets.monospaced.bi = alphabets.sansserif.bf
+
+alphabets.blackboard.tf.symbols = alphabets.regular.tf.symbols
+alphabets.blackboard.it = alphabets.blackboard.tf
+alphabets.blackboard.bf = alphabets.blackboard.tf
+alphabets.blackboard.bi = alphabets.blackboard.bf
+
+alphabets.fraktur.tf.digits = alphabets.regular.tf.digits
+alphabets.fraktur.tf.symbols = alphabets.regular.tf.symbols
+alphabets.fraktur.bf.digits = alphabets.regular.bf.digits
+alphabets.fraktur.bf.symbols = alphabets.regular.bf.symbols
+alphabets.fraktur.it = alphabets.fraktur.tf
+alphabets.fraktur.bi = alphabets.fraktur.bf
+
+alphabets.script.tf.digits = alphabets.regular.tf.digits
+alphabets.script.tf.symbols = alphabets.regular.tf.symbols
+alphabets.script.bf.digits = alphabets.regular.bf.digits
+alphabets.script.bf.symbols = alphabets.regular.bf.symbols
+alphabets.script.it = alphabets.script.tf
+alphabets.script.bi = alphabets.script.bf
+
+alphabets.tt = alphabets.monospaced
+alphabets.ss = alphabets.sansserif
+alphabets.rm = alphabets.regular
+alphabets.bb = alphabets.blackboard
+alphabets.fr = alphabets.fraktur
+alphabets.sr = alphabets.script
+
+alphabets.serif = alphabets.regular
+alphabets.type = alphabets.monospaced
+alphabets.teletype = alphabets.monospaced
+
+function mathematics.to_a_style(attribute)
+ local r = attribs[attribute]
+ return r and r.style or "tf"
+end
+
+function mathematics.to_a_name(attribute)
+ local r = attribs[attribute]
+ return r and r.alphabet or "regular"
+end
+
+-- of course we could do some div/mod trickery instead
+
+--~ function mathematics.sync_a_both(attribute,alphabet,style)
+--~ local data = alphabets[alphabet or "regular"] or alphabets.regular
+--~ data = data[style or "tf"] or data.tf
+--~ return data and data.attribute or attribute
+--~ end
+
+--~ function mathematics.sync_a_style(attribute,style)
+--~ local r = attribs[attribute]
+--~ local alphabet = r and r.alphabet or "regular"
+--~ local data = alphabets[alphabet][style]
+--~ return data and data.attribute or attribute
+--~ end
+
+--~ function mathematics.sync_a_name(attribute,alphabet)
+--~ local r = attribs[attribute]
+--~ local style = r and r.style or "tf"
+--~ local data = alphabets[alphabet][style]
+--~ return data and data.attribute or attribute
+--~ end
+
+local mathalph = attributes.private("mathalph")
+
+local texattribute = tex.attribute
+
+function mathematics.sync_a_both(alphabet,style)
+ local data = alphabets[alphabet or "regular"] or alphabets.regular
+ data = data[style or "tf"] or data.tf
+ texattribute[mathalph] = data and data.attribute or texattribute[mathalph]
+end
+
+function mathematics.sync_a_style(style)
+ local r = attribs[attribute]
+ local alphabet = r and r.alphabet or "regular"
+ local data = alphabets[alphabet][style]
+ texattribute[mathalph] = data and data.attribute or texattribute[mathalph]
+end
+
+function mathematics.sync_a_name(alphabet)
+ local r = attribs[attribute]
+ local style = r and r.style or "tf"
+ local data = alphabets[alphabet][style]
+ texattribute[mathalph] = data and data.attribute or texattribute[mathalph]
+end
+
+local issymbol = mathematics.alphabets.regular.tf.symbols
+
+function mathematics.remap_alphabets(attribute,char)
+ -- we could use a map[attribute][char] => newchar but first we have
+ -- to finish the table
+ local offset = attribs[attribute]
+ if offset then
+ local newchar
+ if char >= 0x030 and char <= 0x039 then
+ local o = offset.digits
+ newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x030 + o)
+ elseif char >= 0x041 and char <= 0x05A then
+ local o = offset.ucletters
+ newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x041 + o)
+ elseif char >= 0x061 and char <= 0x07A then
+ local o = offset.lcletters
+ newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x061 + o)
+ elseif issymbol[char] then
+ newchar = offset.symbols[char]
+ end
+ return newchar ~= char and newchar
+ end
+ return nil
+end
diff --git a/tex/context/base/math-mis.tex b/tex/context/base/math-mis.tex
deleted file mode 100644
index 1b1193fd4..000000000
--- a/tex/context/base/math-mis.tex
+++ /dev/null
@@ -1,49 +0,0 @@
-%D \module
-%D [ file=math-mis,
-%D version=2001.04.12,
-%D title=\CONTEXT\ Math Macros,
-%D subtitle=Miscelaneous Symbols,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=\PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-%D \starttyping
-%D \usemathcollection[mis]
-%D \stoptyping
-
-\def\styledmathcommand#1%
- {\mathchoice
- {\let\currentmathstyle\displaystyle#1}%
- {\let\currentmathstyle\textstyle#1}%
- {\let\currentmathstyle\scriptstyle#1}%
- {\let\currentmathstyle\scriptscriptstyle#1}}
-
-%D For Hong Feng:
-
-\def\geneq
- {\styledmathcommand\dogeneq}
-
-\def\dogeneq
- {\begingroup
- \setbox\scratchbox\hbox{$\currentmathstyle=$}%
- \hbox to \wd\scratchbox
- {\copy\scratchbox
- \hskip-\wd\scratchbox
- \hss\incolortrue\localcolortrue
- \color[white]{\vrule\!!height.6\ht\scratchbox\!!depth\zeropoint\!!width.2\wd\scratchbox}%
- \hss}%
- \endgroup}
-
-%D \startbuffer
-%D $a\string\geneq b^{a\string\geneq b^{a\string\geneq b}}$
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-
-\protect \endinput
diff --git a/tex/context/base/math-noa.lua b/tex/context/base/math-noa.lua
new file mode 100644
index 000000000..6cdcc0114
--- /dev/null
+++ b/tex/context/base/math-noa.lua
@@ -0,0 +1,336 @@
+if not modules then modules = { } end modules ['math-noa'] = {
+ version = 1.001,
+ comment = "companion to math-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- beware: this is experimental code and there will be a more
+-- generic (attribute value driven) interface too but for the
+-- moment this is ok
+
+local utf = unicode.utf8
+
+local set_attribute = node.set_attribute
+local has_attribute = node.has_attribute
+local mlist_to_hlist = node.mlist_to_hlist
+local font_of_family = node.family_font
+local fontdata = fonts.ids
+
+local format, rep = string.format, string.rep
+local utfchar, utfbyte = utf.char, utf.byte
+
+noads = noads or { }
+
+local trace_remapping = false trackers.register("math.remapping", function(v) trace_remapping = v end)
+local trace_processing = false trackers.register("math.processing", function(v) trace_processing = v end)
+local trace_analyzing = false trackers.register("math.analyzing", function(v) trace_analyzing = v end)
+
+local noad_ord = 0
+local noad_op_displaylimits = 1
+local noad_op_limits = 2
+local noad_op_nolimits = 3
+local noad_bin = 4
+local noad_rel = 5
+local noad_open = 6
+local noad_close = 7
+local noad_punct = 8
+local noad_inner = 9
+local noad_under = 10
+local noad_over = 11
+local noad_vcenter = 12
+
+-- obsolete:
+--
+-- math_ord = node.id("ord") -- attr nucleus sub sup
+-- math_op = node.id("op") -- attr nucleus sub sup subtype
+-- math_bin = node.id("bin") -- attr nucleus sub sup
+-- math_rel = node.id("rel") -- attr nucleus sub sup
+-- math_punct = node.id("punct") -- attr nucleus sub sup
+--
+-- math_open = node.id("open") -- attr nucleus sub sup
+-- math_close = node.id("close") -- attr nucleus sub sup
+--
+-- math_inner = node.id("inner") -- attr nucleus sub sup
+-- math_vcenter = node.id("vcenter") -- attr nucleus sub sup
+-- math_under = node.id("under") -- attr nucleus sub sup
+-- math_over = node.id("over") -- attr nucleus sub sup
+
+local math_noad = node.id("noad") -- attr nucleus sub sup
+
+local math_accent = node.id("accent") -- attr nucleus sub sup accent
+local math_radical = node.id("radical") -- attr nucleus sub sup left degree
+local math_fraction = node.id("fraction") -- attr nucleus sub sup left right
+
+local math_box = node.id("sub_box") -- attr list
+local math_sub = node.id("sub_mlist") -- attr list
+local math_char = node.id("math_char") -- attr fam char
+local math_text_char = node.id("math_text_char") -- attr fam char
+local math_delim = node.id("delim") -- attr small_fam small_char large_fam large_char
+local math_style = node.id("style") -- attr style
+local math_choice = node.id("choice") -- attr display text script scriptscript
+local math_fence = node.id("fence") -- attr subtype
+
+local simple_noads = table.tohash {
+ math_noad,
+}
+
+local all_noads = {
+ math_noad,
+ math_box, math_sub,
+ math_char, math_text_char, math_delim, math_style,
+ math_accent, math_radical, math_fraction, math_choice, math_fence,
+}
+
+noads.processors = noads.processors or { }
+
+local function process(start,what,n)
+ if n then n = n + 1 else n = 0 end
+ while start do
+ if trace_processing then
+ texio.write_nl(format("%s%s",rep(" ",n or 0),tostring(start)))
+ end
+ local id = start.id
+ local proc = what[id]
+ if proc then
+ proc(start,what,n)
+ elseif id == math_char or id == math_text_char or id == math_delim then
+ break
+ elseif id == math_style then
+ -- has a next
+ elseif id == math_noad then
+ local noad = start.nucleus if noad then process(noad,what,n) end -- list
+ noad = start.sup if noad then process(noad,what,n) end -- list
+ noad = start.sub if noad then process(noad,what,n) end -- list
+ elseif id == math_box or id == math_sub then
+ local noad = start.list if noad then process(noad,what,n) end -- list
+ elseif id == math_fraction then
+ local noad = start.num if noad then process(noad,what,n) end -- list
+ noad = start.denom if noad then process(noad,what,n) end -- list
+ noad = start.left if noad then process(noad,what,n) end -- delimiter
+ noad = start.right if noad then process(noad,what,n) end -- delimiter
+ elseif id == math_choice then
+ local noad = start.display if noad then process(noad,what,n) end -- list
+ noad = start.text if noad then process(noad,what,n) end -- list
+ noad = start.script if noad then process(noad,what,n) end -- list
+ noad = start.scriptscript if noad then process(noad,what,n) end -- list
+ elseif id == math_fence then
+ local noad = start.delim if noad then process(noad,what,n) end -- delimiter
+ elseif id == math_radical then
+ local noad = start.nucleus if noad then process(noad,what,n) end -- list
+ noad = start.sup if noad then process(noad,what,n) end -- list
+ noad = start.sub if noad then process(noad,what,n) end -- list
+ noad = start.left if noad then process(noad,what,n) end -- delimiter
+ noad = start.degree if noad then process(noad,what,n) end -- list
+ elseif id == math_accent then
+ local noad = start.nucleus if noad then process(noad,what,n) end -- list
+ noad = start.sup if noad then process(noad,what,n) end -- list
+ noad = start.sub if noad then process(noad,what,n) end -- list
+ noad = start.accent if noad then process(noad,what,n) end -- list
+ noad = start.bot_accent if noad then process(noad,what,n) end -- list
+ else
+ -- glue, penalty, etc
+ end
+ start = start.next
+ end
+end
+
+noads.process = process
+
+-- character remapping
+
+local attribute = attributes.private("mathalph")
+
+noads.processors.relocate = { }
+
+local function report_remap(tag,id,old,new,extra)
+ logs.report("math","remapping %s in font %s from U+%04X (%s) to U+%04X (%s)%s",tag,id,old,utfchar(old),new,utfchar(new),extra or "")
+end
+
+local remap_alphabets = mathematics.remap_alphabets
+local fcs = fonts.color.set
+
+noads.processors.relocate[math_char] = function(pointer)
+ local a = has_attribute(pointer,attribute)
+ if a and a > 0 then
+ local fam = pointer.fam
+ set_attribute(pointer,attribute,0)
+ local char = pointer.char
+ local newchar = remap_alphabets(a,char)
+ if newchar then
+ local id = font_of_family(fam)
+ local tfmdata = fontdata[id]
+ if tfmdata and tfmdata.characters[newchar] then -- we could probably speed this up
+ if trace_remapping then
+ report_remap("char",id,char,newchar)
+ end
+ if trace_analyzing then
+ fcs(pointer,"font:isol")
+ end
+ pointer.char = newchar
+ return
+ elseif trace_remapping then
+ report_remap("char",id,char,newchar," fails")
+ end
+ end
+ end
+ if trace_analyzing then
+ fcs(pointer,"font:medi")
+ end
+end
+
+noads.processors.relocate[math_text_char] = function(pointer)
+ if trace_analyzing then
+ fcs(pointer,"font:init")
+ end
+end
+
+noads.processors.relocate[math_delim] = function(pointer)
+ if trace_analyzing then
+ fcs(pointer,"font:fina")
+ end
+end
+
+function noads.relocate_characters(head,tail,style,penalties)
+ process(head,noads.processors.relocate)
+ return true
+end
+
+-- some resize options (this works ok because the content is
+-- empty and no larger next will be forced)
+--
+-- beware: we don't use \delcode but \Udelcode and as such have
+-- no large_fam; also, we need to check for subtype and/or
+-- small_fam not being 0 because \. sits in 0,0 by default
+--
+-- todo: just replace the character by an ord noad
+-- and remove the right delimiter as well
+
+local attribute = attributes.private("mathsize")
+
+noads.processors.resize = { }
+
+noads.processors.resize[math_fence] = function(pointer)
+ if pointer.subtype == 1 then -- left
+ local a = has_attribute(pointer,attribute)
+ if a and a > 0 then
+ set_attribute(pointer,attribute,0)
+ local d = pointer.delim
+ local df = d.small_fam
+ local id = font_of_family(df)
+ if id > 0 then
+ local ch = d.small_char
+ d.small_char = mathematics.big(fontdata[id],ch,a)
+ end
+ end
+ end
+end
+
+function noads.resize_characters(head,tail,style,penalties)
+ process(head,noads.processors.resize)
+ return true
+end
+
+-- respacing
+
+local attribute = attributes.private("mathpunc")
+
+noads.processors.respace = { }
+
+local chardata = characters.data
+
+-- only [nd,ll,ul][po][nd,ll,ul]
+
+noads.processors.respace[math_noad] = function(pointer)
+ if pointer.subtype == noad_ord then
+ local a = has_attribute(pointer,attribute)
+ if a and a > 0 then
+ set_attribute(pointer,attribute,0)
+ local current_nucleus = pointer.nucleus
+ if current_nucleus.id == math_char then
+ local current_char = current_nucleus.char
+ local fc = chardata[current_char]
+ fc = fc and fc.category
+ if fc == "nd" or fc == "ll" or fc == "lu" then
+ local next_noad = pointer.next
+ if next_noad and next_noad.id == math_noad and next_noad.subtype == noad_punct then
+ local next_nucleus = next_noad.nucleus
+ if next_nucleus.id == math_char then
+ local next_char = next_nucleus.char
+ local nc = chardata[next_char]
+ nc = nc and nc.category
+ if nc == "po" then
+ local last_noad = next_noad.next
+ if last_noad and last_noad.id == math_noad and last_noad.subtype == noad_ord then
+ local last_nucleus = last_noad.nucleus
+ if last_nucleus.id == math_char then
+ local last_char = last_nucleus.char
+ local lc = chardata[last_char]
+ lc = lc and lc.category
+ if lc == "nd" or lc == "ll" or lc == "lu" then
+ local ord = node.new(math_noad) -- todo: pool
+ ord.subtype, ord.nucleus, ord.sub, ord.sup, ord.attr = noad_ord, next_noad.nucleus, next_noad.sub, next_noad.sup, next_noad.attr
+ -- next_noad.nucleus, next_noad.sub, next_noad.sup, next_noad.attr = nil, nil, nil, nil
+ next_noad.nucleus, next_noad.sub, next_noad.sup = nil, nil, nil -- else crash with attributes ref count
+ --~ next_noad.attr = nil
+ ord.next = last_noad
+ pointer.next = ord
+ node.free(next_noad)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+
+function noads.respace_characters(head,tail,style,penalties)
+ noads.process(head,noads.processors.respace)
+ return true
+end
+
+-- the normal builder
+
+function noads.mlist_to_hlist(head,tail,style,penalties)
+ return mlist_to_hlist(head,style,penalties), true
+end
+
+tasks.new (
+ "math",
+ {
+ "normalizers",
+ "builders",
+ }
+)
+
+--~ tasks.appendaction("math", "normalizers", "noads.relocate_characters", nil, "nohead")
+--~ tasks.appendaction("math", "normalizers", "noads.resize_characters", nil, "nohead")
+--~ tasks.appendaction("math", "normalizers", "noads.respace_characters", nil, "nohead")
+--~ tasks.appendaction("math", "builders", "noads.mlist_to_hlist", nil, "notail")
+
+local actions = tasks.actions("math")
+
+local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
+
+function nodes.processors.mlist_to_hlist(head,style,penalties)
+ starttiming(noads)
+ local head, done = actions(head,nil,style,penalties)
+ stoptiming(noads)
+ return head, done
+end
+
+callback.register('mlist_to_hlist',nodes.processors.mlist_to_hlist)
+
+-- tracing
+
+statistics.register("math processing time", function()
+ if statistics.elapsedindeed(noads) then
+ return format("%s seconds", statistics.elapsedtime(noads))
+ end
+end)
diff --git a/tex/context/base/math-pln.mkii b/tex/context/base/math-pln.mkii
new file mode 100644
index 000000000..0bacc40a2
--- /dev/null
+++ b/tex/context/base/math-pln.mkii
@@ -0,0 +1,360 @@
+%D \module
+%D [ file=math-pln,
+%D version=2001.11.16,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Plain Helpers,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% \points should become \bodyfontsize
+
+%D This is a temporary module, some of this code will move to
+%D the other math modules.
+
+\writestatus{loading}{ConTeXt Math Macros / Plain Helpers}
+
+\unprotect
+
+\ifx\displ@y\undefined \let\displ@y\relax\fi
+
+\newbox\rootbox
+
+\def\root#1\of
+ {\setbox\rootbox\hbox{$\mathsurround\zeropoint\scriptscriptstyle{#1}$}%
+ \mathpalette\r@@t}
+
+\def\r@@t#1#2% will be overloaded
+ {\setbox\zerocount\hbox{$\mathsurround\zeropoint#1\sqrt{#2}$}\dimen@\ht\zerocount
+ \advance\dimen@-\dp\zerocount
+ \mkern5mu\raise.6\dimen@\copy\rootbox
+ \mkern-10mu\box\zerocount}
+
+\def\mathhexbox#1#2#3%
+ {\leavevmode
+ \hbox{$\mathsurround\zeropoint\mathchar"#1#2#3$}}
+
+\def\oalign#1%
+ {\leavevmode
+ \vtop
+ {\baselineskip\zeroskip \lineskip.25ex%
+ \ialign{##\crcr#1\crcr}}}
+
+\def\o@lign
+ {\lineskiplimit\zeropoint \oalign}
+
+\def\ooalign % chars over each other
+ {\lineskiplimit-\maxdimen
+ \oalign}
+
+\def\sh@ft#1% kern by #1 times the current slant
+ {\dimen@#1%
+ \kern\expandafter\withoutpt\the\slantperpoint
+ \dimen@}
+
+\def\dots
+ {\relax\ifmmode\ldots\else$\mathsurround\zeropoint\ldots\,$\fi}
+
+\def\hrulefill
+ {\leaders\hrule\hfill}
+
+\def\dotfill
+ {\cleaders\hbox{$\mathsurround\zeropoint \mkern1.5mu.\mkern1.5mu$}\hfill}
+
+\def\rightarrowfill
+ {$\mathsurround\zeropoint\smash-\mkern-7mu%
+ \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
+ \mkern-7mu\mathord\rightarrow$}
+
+\def\leftarrowfill
+ {$\mathsurround\zeropoint\mathord\leftarrow\mkern-7mu%
+ \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
+ \mkern-7mu\smash-$}
+
+% must go to math-tex
+
+\ifx\braceld\undefined
+ % mkii values
+ \mathchardef\braceld="37A
+ \mathchardef\bracerd="37B
+ \mathchardef\bracelu="37C
+ \mathchardef\braceru="37D
+\fi
+
+\def\downbracefill
+ {$\mathsurround\zeropoint\setbox\zerocount\hbox{$\braceld$}%
+ \braceld\leaders\vrule\!!height\ht\zerocount\!!depth\zeropoint\hfill\braceru
+ \bracelu\leaders\vrule\!!height\ht\zerocount\!!depth\zeropoint\hfill\bracerd$}
+
+\def\upbracefill
+ {$\mathsurround\zeropoint\setbox\zerocount\hbox{$\braceld$}%
+ \bracelu\leaders\vrule\!!height\ht\zerocount\!!depth\zeropoint\hfill\bracerd
+ \braceld\leaders\vrule\!!height\ht\zerocount\!!depth\zeropoint\hfill\braceru$}
+
+% hm, shouldn't that be \kern3\bodyfontsize
+
+\def\overbrace#1%
+ {\mathop{\vbox{\mathsurround\zeropoint\ialign{##\crcr\noalign{\kern3\points}
+ \downbracefill\crcr\noalign{\kern3\points\nointerlineskip}
+ $\hfil\displaystyle{#1}\hfil$\crcr}}}\limits}
+
+\def\underbrace#1%
+ {\mathop{\vtop{\mathsurround\zeropoint\ialign{##\crcr
+ $\hfil\displaystyle{#1}\hfil$\crcr\noalign{\kern3\points\nointerlineskip}
+ \upbracefill\crcr\noalign{\kern3\points}}}}\limits}
+
+\let\sp=^ % will become obsolete
+\let\sb=_ % will become obsolete
+
+\ifx\,\undefined \def\,{\mskip \thinmuskip } \fi
+\ifx\>\undefined \def\>{\mskip \medmuskip } \fi
+\ifx\;\undefined \def\;{\mskip \thickmuskip} \fi
+\ifx\!\undefined \def\!{\mskip-\thinmuskip } \fi
+\ifx\*\undefined \def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}} \fi
+
+% {\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
+
+\def\activemathquote{^\bgroup\prim@s}
+
+\def\prim@s
+ {\prime\futurelet\next\pr@m@s}
+
+\def\pr@m@s
+ {\ifx'\next
+ \@EA\pr@@@s
+ \else\ifx^\next
+ \@EAEAEA\pr@@@t
+ \else
+ \@EAEAEA\egroup
+ \fi\fi}
+
+\def\pr@@@s#1%
+ {\prim@s}
+
+\def\pr@@@t#1#2%
+ {#2\egroup}
+
+% {\catcode`\_=\active \global\let_=\_} % _ in math is either subscript or \_
+
+\let\activemathunderscore\_
+
+\def\relbar {\mathrel{\smash-}} % - has the same height as +
+\def\Relbar {\mathrel=}
+
+\def\Longrightarrow {\Relbar\joinrel\Rightarrow}
+\def\longrightarrow {\relbar\joinrel\rightarrow}
+\def\longleftarrow {\leftarrow\joinrel\relbar}
+\def\Longleftarrow {\Leftarrow\joinrel\Relbar}
+\def\longmapsto {\mapstochar\longrightarrow}
+\def\longleftrightarrow{\leftarrow\joinrel\rightarrow}
+\def\Longleftrightarrow{\Leftarrow\joinrel\Rightarrow}
+
+\def\overrightarrow#1%
+ {\vbox{\mathsurround\zeropoint\ialign{##\crcr
+ \rightarrowfill\crcr\noalign{\kern-\onepoint\nointerlineskip}
+ $\hfil\displaystyle{#1}\hfil$\crcr}}}
+
+\def\overleftarrow#1%
+ {\vbox{\mathsurround\zeropoint\ialign{##\crcr
+ \leftarrowfill\crcr\noalign{\kern-\onepoint\nointerlineskip}
+ $\hfil\displaystyle{#1}\hfil$\crcr}}}
+
+\def\skew#1#2#3%
+ {{\muskip\zerocount#1mu\divide\muskip\zerocount\plustwo \mkern\muskip\zerocount
+ #2{\mkern-\muskip\zerocount{#3}\mkern\muskip\zerocount}\mkern-\muskip\zerocount}{}}
+
+\def\choose{\atopwithdelims()}
+\def\brack {\atopwithdelims[]}
+\def\brace {\atopwithdelims\{\}}
+
+\def\mathpalette#1#2%
+ {\mathchoice
+ {#1\displaystyle {#2}}%
+ {#1\textstyle {#2}}%
+ {#1\scriptstyle {#2}}%
+ {#1\scriptscriptstyle{#2}}}
+
+\def\cong
+ {\mathrel{\mathpalette\@vereq\sim}} % congruence sign
+
+\def\@vereq#1#2%
+ {\lower.5\points\vbox{\lineskiplimit\maxdimen\lineskip-.5\points
+ \ialign{$\mathsurround\zeropoint#1\hfil##\hfil$\crcr#2\crcr=\crcr}}}
+
+\def\notin% can be mkiv'd
+ {\mathrel{\mathpalette\c@ncel\in}}
+
+\def\c@ncel#1#2%
+ {\mathsurround\zeropoint\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
+
+\def\rightleftharpoons%
+ {\mathrel{\mathpalette\rlh@{}}}
+
+\def\rlh@#1%
+ {\vcenter
+ {\mathsurround\zeropoint
+ \hbox
+ {\ooalign
+ {\raise2pt\hbox{$#1\rightharpoonup$}\crcr
+ $#1\leftharpoondown$}}}}
+
+\def\buildrel#1\over#2%
+ {\mathrel{\mathop{\kern\zerocount#2}\limits^{#1}}}
+
+\def\doteq
+ {\buildrel\textstyle.\over=}
+
+\ifx\mfunction\undefined \def\mfunction#1{\mathbin{\rm#1}} \fi
+
+\def\bmod
+ {\nonscript
+ \mskip-\medmuskip
+ \mkern5mu
+ \mfunction{mod}%
+ \penalty900
+ \mkern5mu
+ \nonscript
+ \mskip-\medmuskip}
+
+\def\pmod#1%
+ {\allowbreak
+ \mkern18mu
+ (\mfunction{mod}\,\,#1)}
+
+\def\cases#1%
+ {\left\{%
+ \,%
+ \vcenter
+ {\normalbaselines
+ \mathsurround\zeropoint
+ \ialign{$##\hfil$&\quad##\hfil\crcr#1\crcr}}%
+ \right.}
+
+\def\matrix#1%
+ {\null
+ \,%
+ \vcenter
+ {\normalbaselines\mathsurround\zeropoint
+ \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
+ \mathstrut\crcr\noalign{\kern-\baselineskip}
+ #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}%
+ \,}
+
+\def\pmatrix#1%
+ {\left(\matrix{#1}\right)}
+
+\newdimen\mathparentwd
+
+% \setbox0=\hbox{\tenex B} \mathparentwd=\wd0 % width of the big left (
+
+\def\bordermatrix#1%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox\zerocount\vbox
+ {\def\cr{\crcr\noalign{\kern2\points\global\let\cr\endline}}%
+ \ialign{$##$\hfil\kern2\points\kern\mathparentwd&\thinspace\hfil$##$\hfil
+ &&\quad\hfil$##$\hfil\crcr
+ \omit\strut\hfil\crcr\noalign{\kern-\baselineskip}%
+ #1\crcr\omit\strut\cr}}%
+ \setbox\plustwo\vbox
+ {\unvcopy\zerocount\global\setbox\plusone\lastbox}%
+ \setbox\plustwo\hbox
+ {\unhbox\plusone\unskip\global\setbox\plusone\lastbox}%
+ \setbox\plustwo\hbox
+ {$\kern\wd\plusone\kern-\mathparentwd\left(\kern-\wd\plusone
+ \global\setbox\plusone\vbox{\box\plusone\kern2\points}%
+ \vcenter{\kern-\ht\plusone\unvbox\zerocount\kern-\baselineskip}\,\right)$}%
+ \null
+ \;%
+ \vbox{\kern\ht\plusone\box\plustwo}%
+ \endgroup}
+
+% \def\openup{\afterassignment\@penup\dimen@=}
+%
+% \def\@penup{\advance\lineskip\dimen@
+% \advance\baselineskip\dimen@
+% \advance\lineskiplimit\dimen@}
+
+\def\openup
+ {\afterassignment\doopenup\scratchdimen=}
+
+\def\doopenup
+ {\advance\lineskip \scratchdimen
+ \advance\baselineskip \scratchdimen
+ \advance\lineskiplimit\scratchdimen}
+
+% \def\jot{.25\bodyfontsize} % plain tex: 3 pt (todo: better name and configurable)
+
+\def\displayopenupvalue{.25\bodyfontsize}
+
+\def\eqalign#1%
+ {\null
+ \,%
+ \vcenter
+ {\openup\displayopenupvalue % was \openup\jot
+ \mathsurround\zeropoint
+ \ialign
+ {\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr
+ #1\crcr}}%
+ \,}
+
+\def\@lign % restore inside \displ@y
+ {\tabskip\zeroskip
+ \everycr{}}
+
+\def\displaylines#1%
+ {\displ@y
+ \tabskip\zeroskip
+ \halign
+ {\hbox to \displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr
+ #1\crcr}}
+
+\def\eqalignno#1%
+ {\displ@y
+ \tabskip\centering
+ \halign to \displaywidth
+ {\hfil$\@lign\displaystyle{##}$\tabskip\zeroskip
+ &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
+ &\llap{$\@lign##$}\tabskip\zeroskip\crcr
+ #1\crcr}}
+
+\def\leqalignno#1%
+ {\displ@y
+ \tabskip\centering
+ \halign to \displaywidth
+ {\hfil$\@lign\displaystyle{##}$\tabskip\zeroskip
+ &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
+ &\kern-\displaywidth\rlap{$\@lign##$}\tabskip\displaywidth\crcr
+ #1\crcr}}
+
+% temporary here
+
+% \startcatcodetable \mthcatcodes
+% \setcatcodetable\ctxcatcodes
+% \catcode`\_ = 13
+% \catcode`\' = 13
+% \stopcatcodetable
+%
+% \letcatcodecommand \mthcatcodes `\_ \activemathunderscore
+% \letcatcodecommand \mthcatcodes `\' \activemathquote
+
+% \appendtoks \setcatcodetable\mthcatcodes \to \everymath : spoils xml
+
+% tricky, but some day we will reimplement math
+
+\bgroup
+ \catcode`\_ = 13
+ \catcode`\' = 13
+ \doglobal\appendtoks
+ \let_\activemathunderscore
+ \let'\activemathquote
+ \to \everymathematics
+\egroup
+
+% so far
+
+\protect \endinput
diff --git a/tex/context/base/math-pln.mkiv b/tex/context/base/math-pln.mkiv
new file mode 100644
index 000000000..23d7d935c
--- /dev/null
+++ b/tex/context/base/math-pln.mkiv
@@ -0,0 +1,298 @@
+%D \module
+%D [ file=math-pln,
+%D version=2001.11.16,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Plain Helpers,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This is a temporary module, some of this code will move to
+%D the other math modules. Much is copied from Plain \TEX.
+
+% \points should become \bodyfontsize
+
+\writestatus{loading}{ConTeXt Math Macros / Plain Helpers}
+
+\unprotect
+
+\ifx\displ@y\undefined \let\displ@y\relax\fi
+
+\def\oalign#1%
+ {\leavevmode
+ \vtop
+ {\baselineskip\zeroskip \lineskip.25ex%
+ \ialign{##\crcr#1\crcr}}}
+
+\def\o@lign
+ {\lineskiplimit\zeropoint \oalign}
+
+\def\ooalign % chars over each other
+ {\lineskiplimit-\maxdimen
+ \oalign}
+
+\def\sh@ft#1% kern by #1 times the current slant
+ {\dimen@#1%
+ \kern\expandafter\withoutpt\the\slantperpoint
+ \dimen@}
+
+\def\dots
+ {\relax\ifmmode\ldots\else$\mathsurround\zeropoint\ldots\,$\fi}
+
+\def\hrulefill
+ {\leaders\hrule\hfill}
+
+\def\dotfill
+ {\cleaders\hbox{$\mathsurround\zeropoint \mkern1.5mu.\mkern1.5mu$}\hfill}
+
+\def\rightarrowfill
+ {$\mathsurround\zeropoint\smash-\mkern-7mu%
+ \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
+ \mkern-7mu\mathord\rightarrow$}
+
+\def\leftarrowfill
+ {$\mathsurround\zeropoint\mathord\leftarrow\mkern-7mu%
+ \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
+ \mkern-7mu\smash-$}
+
+\let\sp=^ % will become obsolete
+\let\sb=_ % will become obsolete
+
+\ifx\,\undefined \def\,{\mskip \thinmuskip } \fi
+\ifx\>\undefined \def\>{\mskip \medmuskip } \fi
+\ifx\;\undefined \def\;{\mskip \thickmuskip} \fi
+\ifx\!\undefined \def\!{\mskip-\thinmuskip } \fi
+\ifx\*\undefined \def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}} \fi
+
+% {\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
+
+\def\activemathquote{^\bgroup\prim@s}
+
+\def\prim@s
+ {\prime\futurelet\next\pr@m@s}
+
+\def\pr@m@s
+ {\ifx'\next
+ \@EA\pr@@@s
+ \else\ifx^\next
+ \@EAEAEA\pr@@@t
+ \else
+ \@EAEAEA\egroup
+ \fi\fi}
+
+\def\pr@@@s#1%
+ {\prim@s}
+
+\def\pr@@@t#1#2%
+ {#2\egroup}
+
+% {\catcode`\_=\active \global\let_=\_} % _ in math is either subscript or \_
+
+\let\activemathunderscore\_
+
+\def\relbar {\mathrel{\smash-}} % - has the same height as +
+\def\Relbar {\mathrel=}
+
+\def\Longrightarrow {\Relbar\joinrel\Rightarrow}
+\def\longrightarrow {\relbar\joinrel\rightarrow}
+\def\longleftarrow {\leftarrow\joinrel\relbar}
+\def\Longleftarrow {\Leftarrow\joinrel\Relbar}
+\def\longmapsto {\mapstochar\longrightarrow}
+\def\longleftrightarrow{\leftarrow\joinrel\rightarrow}
+\def\Longleftrightarrow{\Leftarrow\joinrel\Rightarrow}
+
+\def\choose{\atopwithdelims()}
+\def\brack {\atopwithdelims[]}
+\def\brace {\atopwithdelims\{\}}
+
+\def\mathpalette#1#2%
+ {\mathchoice
+ {#1\displaystyle {#2}}%
+ {#1\textstyle {#2}}%
+ {#1\scriptstyle {#2}}%
+ {#1\scriptscriptstyle{#2}}}
+
+\def\cong
+ {\mathrel{\mathpalette\@vereq\sim}} % congruence sign
+
+\def\@vereq#1#2%
+ {\lower.5\points\vbox{\lineskiplimit\maxdimen\lineskip-.5\points
+ \ialign{$\mathsurround\zeropoint#1\hfil##\hfil$\crcr#2\crcr=\crcr}}}
+
+\def\notin
+ {\mathrel{\mathpalette\c@ncel\in}}
+
+\def\c@ncel#1#2%
+ {\mathsurround\zeropoint\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
+
+\def\rightleftharpoons
+ {\mathrel{\mathpalette\rlh@{}}}
+
+\def\rlh@#1%
+ {\vcenter
+ {\mathsurround\zeropoint
+ \hbox
+ {\ooalign
+ {\raise2pt\hbox{$#1\rightharpoonup$}\crcr
+ $#1\leftharpoondown$}}}}
+
+\def\buildrel#1\over#2%
+ {\mathrel{\mathop{\kern\zeropoint#2}\limits^{#1}}}
+
+\def\doteq
+ {\buildrel\textstyle.\over=}
+
+\ifx\mfunction\undefined \def\mfunction#1{\mathbin{\rm#1}} \fi
+
+\def\bmod
+ {\nonscript
+ \mskip-\medmuskip
+ \mkern5mu
+ \mfunction{mod}%
+ \penalty900
+ \mkern5mu
+ \nonscript
+ \mskip-\medmuskip}
+
+\def\pmod#1%
+ {\allowbreak
+ \mkern18mu
+ (\mfunction{mod}\,\,#1)}
+
+\def\cases#1%
+ {\left\{%
+ \,%
+ \vcenter
+ {\normalbaselines
+ \mathsurround\zeropoint
+ \ialign{$##\hfil$&\quad##\hfil\crcr#1\crcr}}%
+ \right.}
+
+\def\matrix#1%
+ {\null
+ \,%
+ \vcenter
+ {\normalbaselines\mathsurround\zeropoint
+ \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
+ \mathstrut\crcr\noalign{\kern-\baselineskip}
+ #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}%
+ \,}
+
+\def\pmatrix#1%
+ {\left(\matrix{#1}\right)}
+
+\newdimen\mathparentwd
+
+% \setbox0=\hbox{\tenex B} \mathparentwd=\wd0 % width of the big left (
+
+\def\bordermatrix#1%
+ {\begingroup
+ \mathsurround\zeropoint
+ \setbox\zerocount\vbox
+ {\def\cr{\crcr\noalign{\kern2\points\global\let\cr\endline}}%
+ \ialign{$##$\hfil\kern2\points\kern\mathparentwd&\thinspace\hfil$##$\hfil
+ &&\quad\hfil$##$\hfil\crcr
+ \omit\strut\hfil\crcr\noalign{\kern-\baselineskip}%
+ #1\crcr\omit\strut\cr}}%
+ \setbox\plustwo\vbox
+ {\unvcopy\zerocount\global\setbox\plusone\lastbox}%
+ \setbox\plustwo\hbox
+ {\unhbox\plusone\unskip\global\setbox\plusone\lastbox}%
+ \setbox\plustwo\hbox
+ {$\kern\wd\plusone\kern-\mathparentwd\left(\kern-\wd\plusone
+ \global\setbox\plusone\vbox{\box\plusone\kern2\points}%
+ \vcenter{\kern-\ht\plusone\unvbox\zerocount\kern-\baselineskip}\,\right)$}%
+ \null
+ \;%
+ \vbox{\kern\ht\plusone\box\plustwo}%
+ \endgroup}
+
+% \def\openup{\afterassignment\@penup\dimen@=}
+%
+% \def\@penup{\advance\lineskip\dimen@
+% \advance\baselineskip\dimen@
+% \advance\lineskiplimit\dimen@}
+
+\def\openup
+ {\afterassignment\doopenup\scratchdimen=}
+
+\def\doopenup
+ {\advance\lineskip \scratchdimen
+ \advance\baselineskip \scratchdimen
+ \advance\lineskiplimit\scratchdimen}
+
+% \def\jot{.25\bodyfontsize} % plain tex: 3 pt (todo: better name and configurable)
+
+\def\displayopenupvalue{.25\bodyfontsize}
+
+\def\eqalign#1%
+ {\null
+ \,%
+ \vcenter
+ {\openup\displayopenupvalue % was \openup\jot
+ \mathsurround\zeropoint
+ \ialign
+ {\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr
+ #1\crcr}}%
+ \,}
+
+\def\@lign % restore inside \displ@y
+ {\tabskip\zeroskip
+ \everycr{}}
+
+\def\displaylines#1%
+ {\displ@y
+ \tabskip\zeroskip
+ \halign
+ {\hbox to \displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr
+ #1\crcr}}
+
+\def\eqalignno#1%
+ {\displ@y
+ \tabskip\centering
+ \halign to \displaywidth
+ {\hfil$\@lign\displaystyle{##}$\tabskip\zeroskip
+ &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
+ &\llap{$\@lign##$}\tabskip\zeroskip\crcr
+ #1\crcr}}
+
+\def\leqalignno#1%
+ {\displ@y
+ \tabskip\centering
+ \halign to \displaywidth
+ {\hfil$\@lign\displaystyle{##}$\tabskip\zeroskip
+ &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
+ &\kern-\displaywidth\rlap{$\@lign##$}\tabskip\displaywidth\crcr
+ #1\crcr}}
+
+% temporary here
+
+% \startcatcodetable \mthcatcodes
+% \setcatcodetable\ctxcatcodes
+% \catcode`\_ = 13
+% \catcode`\' = 13
+% \stopcatcodetable
+%
+% \letcatcodecommand \mthcatcodes `\_ \activemathunderscore
+% \letcatcodecommand \mthcatcodes `\' \activemathquote
+
+% \appendtoks \setcatcodetable\mthcatcodes \to \everymath : spoils xml
+
+% tricky, but some day we will reimplement math
+
+\bgroup
+ \catcode`\_ = 13
+ \catcode`\' = 13
+ \doglobal\appendtoks
+ \let_\activemathunderscore
+ \let'\activemathquote
+ \to \everymathematics
+\egroup
+
+% so far
+
+\protect \endinput
diff --git a/tex/context/base/math-pln.tex b/tex/context/base/math-pln.tex
deleted file mode 100644
index ffa16c8f5..000000000
--- a/tex/context/base/math-pln.tex
+++ /dev/null
@@ -1,355 +0,0 @@
-%D \module
-%D [ file=math-pln,
-%D version=2001.11.16,
-%D title=\CONTEXT\ System Macros,
-%D subtitle=Efficient \PLAIN\ \TEX\ loading,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D This is a temporary module, some of this code will move to
-%D the other math modules.
-
-\unprotect
-
-\ifx\displ@y\unefined \let\displ@y\relax\fi
-\ifx\m@th \unefined \let\m@th \relax\fi
-
-\newbox\rootbox
-
-\def\root#1\of%
- {\setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#1}$}%
- \mathpalette\r@@t}
-
-\def\r@@t#1#2% will be overloaded
- {\setbox\z@\hbox{$\m@th#1\sqrt{#2}$}\dimen@\ht\z@
- \advance\dimen@-\dp\z@
- \mkern5mu\raise.6\dimen@\copy\rootbox
- \mkern-10mu\box\z@}
-
-\def\mathhexbox#1#2#3%
- {\leavevmode
- \hbox{$\m@th\mathchar"#1#2#3$}}
-
-\def\oalign#1%
- {\leavevmode
- \vtop
- {\baselineskip\z@skip \lineskip.25ex%
- \ialign{##\crcr#1\crcr}}}
-
-\def\o@lign
- {\lineskiplimit\z@ \oalign}
-
-\def\ooalign % chars over each other
- {\lineskiplimit-\maxdimen
- \oalign}
-
-\def\sh@ft#1% kern by #1 times the current slant
- {\dimen@#1%
- \kern\expandafter\withoutpt\the\slantperpoint
- \dimen@}
-
-\def\dots
- {\relax\ifmmode\ldots\else$\m@th\ldots\,$\fi}
-
-\def\hrulefill
- {\leaders\hrule\hfill}
-
-\def\dotfill
- {\cleaders\hbox{$\m@th \mkern1.5mu.\mkern1.5mu$}\hfill}
-
-\def\rightarrowfill
- {$\m@th\smash-\mkern-7mu%
- \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
- \mkern-7mu\mathord\rightarrow$}
-
-\def\leftarrowfill
- {$\m@th\mathord\leftarrow\mkern-7mu%
- \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
- \mkern-7mu\smash-$}
-
-% must go to math-tex
-
-\mathchardef\braceld="37A
-\mathchardef\bracerd="37B
-\mathchardef\bracelu="37C
-\mathchardef\braceru="37D
-
-\def\downbracefill
- {$\m@th\setbox\z@\hbox{$\braceld$}%
- \braceld\leaders\vrule\!!height\ht\z@\!!depth\z@\hfill\braceru
- \bracelu\leaders\vrule\!!height\ht\z@\!!depth\z@\hfill\bracerd$}
-
-\def\upbracefill
- {$\m@th\setbox\z@\hbox{$\braceld$}%
- \bracelu\leaders\vrule\!!height\ht\z@\!!depth\z@\hfill\bracerd
- \braceld\leaders\vrule\!!height\ht\z@\!!depth\z@\hfill\braceru$}
-
-\let\sp=^ % will become obsolete
-\let\sb=_ % will become obsolete
-
-\ifx\,\undefined \def\,{\mskip \thinmuskip } \fi
-\ifx\>\undefined \def\>{\mskip \medmuskip } \fi
-\ifx\;\undefined \def\;{\mskip \thickmuskip} \fi
-\ifx\!\undefined \def\!{\mskip-\thinmuskip } \fi
-\ifx\*\undefined \def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}} \fi
-
-% {\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
-
-\def\activemathquote{^\bgroup\prim@s}
-
-\def\prim@s
- {\prime\futurelet\next\pr@m@s}
-
-\def\pr@m@s
- {\ifx'\next
- \@EA\pr@@@s
- \else\ifx^\next
- \@EAEAEA\pr@@@t
- \else
- \@EAEAEA\egroup
- \fi\fi}
-
-\def\pr@@@s#1%
- {\prim@s}
-
-\def\pr@@@t#1#2%
- {#2\egroup}
-
-% {\catcode`\_=\active \global\let_=\_} % _ in math is either subscript or \_
-
-\let\activemathunderscore\_
-
-\def\relbar {\mathrel{\smash-}} % - has the same height as +
-\def\Relbar {\mathrel=}
-
-\def\Longrightarrow {\Relbar\joinrel\Rightarrow}
-\def\longrightarrow {\relbar\joinrel\rightarrow}
-\def\longleftarrow {\leftarrow\joinrel\relbar}
-\def\Longleftarrow {\Leftarrow\joinrel\Relbar}
-\def\longmapsto {\mapstochar\longrightarrow}
-\def\longleftrightarrow{\leftarrow\joinrel\rightarrow}
-\def\Longleftrightarrow{\Leftarrow\joinrel\Rightarrow}
-
-\def\overrightarrow#1%
- {\vbox{\m@th\ialign{##\crcr
- \rightarrowfill\crcr\noalign{\kern-\p@\nointerlineskip}
- $\hfil\displaystyle{#1}\hfil$\crcr}}}
-
-\def\overleftarrow#1%
- {\vbox{\m@th\ialign{##\crcr
- \leftarrowfill\crcr\noalign{\kern-\p@\nointerlineskip}
- $\hfil\displaystyle{#1}\hfil$\crcr}}}
-
-\def\overbrace#1%
- {\mathop{\vbox{\m@th\ialign{##\crcr\noalign{\kern3\p@}
- \downbracefill\crcr\noalign{\kern3\p@\nointerlineskip}
- $\hfil\displaystyle{#1}\hfil$\crcr}}}\limits}
-
-\def\underbrace#1%
- {\mathop{\vtop{\m@th\ialign{##\crcr
- $\hfil\displaystyle{#1}\hfil$\crcr\noalign{\kern3\p@\nointerlineskip}
- \upbracefill\crcr\noalign{\kern3\p@}}}}\limits}
-
-\def\skew#1#2#3%
- {{\muskip\z@#1mu\divide\muskip\z@\tw@ \mkern\muskip\z@
- #2{\mkern-\muskip\z@{#3}\mkern\muskip\z@}\mkern-\muskip\z@}{}}
-
-\def\n@space
- {\nulldelimiterspace\z@ \m@th}
-
-\def\choose{\atopwithdelims()}
-\def\brack {\atopwithdelims[]}
-\def\brace {\atopwithdelims\{\}}
-
-\def\mathpalette#1#2%
- {\mathchoice
- {#1\displaystyle {#2}}%
- {#1\textstyle {#2}}%
- {#1\scriptstyle {#2}}%
- {#1\scriptscriptstyle{#2}}}
-
-\def\cong%
- {\mathrel{\mathpalette\@vereq\sim}} % congruence sign
-
-\def\@vereq#1#2%
- {\lower.5\p@\vbox{\lineskiplimit\maxdimen\lineskip-.5\p@
- \ialign{$\m@th#1\hfil##\hfil$\crcr#2\crcr=\crcr}}}
-
-\def\notin%
- {\mathrel{\mathpalette\c@ncel\in}}
-
-\def\c@ncel#1#2%
- {\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
-
-\def\rightleftharpoons%
- {\mathrel{\mathpalette\rlh@{}}}
-
-\def\rlh@#1%
- {\vcenter
- {\m@th
- \hbox
- {\ooalign
- {\raise2pt\hbox{$#1\rightharpoonup$}\crcr
- $#1\leftharpoondown$}}}}
-
-\def\buildrel#1\over#2%
- {\mathrel{\mathop{\kern\z@#2}\limits^{#1}}}
-
-\def\doteq
- {\buildrel\textstyle.\over=}
-
-\ifx\mfunction\undefined \def\mfunction#1{\mathbin{\rm#1}} \fi
-
-\def\bmod
- {\nonscript
- \mskip-\medmuskip
- \mkern5mu
- \mfunction{mod}%
- \penalty900
- \mkern5mu
- \nonscript
- \mskip-\medmuskip}
-
-\def\pmod#1%
- {\allowbreak
- \mkern18mu
- (\mfunction{mod}\,\,#1)}
-
-\def\cases#1%
- {\left\{%
- \,%
- \vcenter
- {\normalbaselines
- \m@th
- \ialign{$##\hfil$&\quad##\hfil\crcr#1\crcr}}%
- \right.}
-
-\def\matrix#1%
- {\null
- \,%
- \vcenter
- {\normalbaselines\m@th
- \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
- \mathstrut\crcr\noalign{\kern-\baselineskip}
- #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}%
- \,}
-
-\def\pmatrix#1%
- {\left(\matrix{#1}\right)}
-
-\newdimen\p@renwd
-
-% \setbox0=\hbox{\tenex B} \p@renwd=\wd0 % width of the big left (
-
-\def\bordermatrix#1%
- {\begingroup
- \m@th
- \setbox\z@\vbox
- {\def\cr{\crcr\noalign{\kern2\p@\global\let\cr\endline}}%
- \ialign{$##$\hfil\kern2\p@\kern\p@renwd&\thinspace\hfil$##$\hfil
- &&\quad\hfil$##$\hfil\crcr
- \omit\strut\hfil\crcr\noalign{\kern-\baselineskip}%
- #1\crcr\omit\strut\cr}}%
- \setbox\tw@\vbox
- {\unvcopy\z@\global\setbox\@ne\lastbox}%
- \setbox\tw@\hbox
- {\unhbox\@ne\unskip\global\setbox\@ne\lastbox}%
- \setbox\tw@\hbox
- {$\kern\wd\@ne\kern-\p@renwd\left(\kern-\wd\@ne
- \global\setbox\@ne\vbox{\box\@ne\kern2\p@}%
- \vcenter{\kern-\ht\@ne\unvbox\z@\kern-\baselineskip}\,\right)$}%
- \null
- \;%
- \vbox{\kern\ht\@ne\box\tw@}%
- \endgroup}
-
-% \def\openup{\afterassignment\@penup\dimen@=}
-%
-% \def\@penup{\advance\lineskip\dimen@
-% \advance\baselineskip\dimen@
-% \advance\lineskiplimit\dimen@}
-
-\def\openup
- {\afterassignment\doopenup\scratchdimen=}
-
-\def\doopenup
- {\advance\lineskip \scratchdimen
- \advance\baselineskip \scratchdimen
- \advance\lineskiplimit\scratchdimen}
-
-% \def\jot{.25\bodyfontsize} % plain tex: 3 pt (todo: better name and configurable)
-
-\def\displayopenupvalue{.25\bodyfontsize}
-
-\def\eqalign#1%
- {\null
- \,%
- \vcenter
- {\openup\displayopenupvalue % was \openup\jot
- \m@th
- \ialign
- {\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr
- #1\crcr}}%
- \,}
-
-\def\@lign % restore inside \displ@y
- {\tabskip\z@skip
- \everycr{}}
-
-\def\displaylines#1%
- {\displ@y
- \tabskip\z@skip
- \halign
- {\hbox to \displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr
- #1\crcr}}
-
-\def\eqalignno#1%
- {\displ@y
- \tabskip\centering
- \halign to \displaywidth
- {\hfil$\@lign\displaystyle{##}$\tabskip\z@skip
- &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
- &\llap{$\@lign##$}\tabskip\z@skip\crcr
- #1\crcr}}
-
-\def\leqalignno#1%
- {\displ@y
- \tabskip\centering
- \halign to \displaywidth
- {\hfil$\@lign\displaystyle{##}$\tabskip\z@skip
- &$\@lign\displaystyle{{}##}$\hfil\tabskip\centering
- &\kern-\displaywidth\rlap{$\@lign##$}\tabskip\displaywidth\crcr
- #1\crcr}}
-
-% temporary here
-
-% \startcatcodetable \mthcatcodes
-% \setcatcodetable\ctxcatcodes
-% \catcode`\_ = 13
-% \catcode`\' = 13
-% \stopcatcodetable
-%
-% \letcatcodecommand \mthcatcodes `\_ \activemathunderscore
-% \letcatcodecommand \mthcatcodes `\' \activemathquote
-
-% \appendtoks \setcatcodetable\mthcatcodes \to \everymath : spoils xml
-
-% tricky, but some day we will reimplement math
-
-\bgroup
- \catcode`\_ = 13
- \catcode`\' = 13
- \doglobal\appendtoks
- \let_\activemathunderscore
- \let'\activemathquote
- \to \everymathematics
-\egroup
-
-% so far
-
-\protect \endinput
diff --git a/tex/context/base/math-run.mkii b/tex/context/base/math-run.mkii
new file mode 100644
index 000000000..afe5b18b4
--- /dev/null
+++ b/tex/context/base/math-run.mkii
@@ -0,0 +1,97 @@
+%D \module
+%D [ file=math-run,
+%D version=2001.23.04,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Runtime Macros,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=Hans Hagen \& Ton Otten]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Runtime Macros}
+
+\unprotect
+
+\ifx\showmathmodern\undefined \global\chardef\showmathmodern\zerocount \fi
+
+\gdef\showmathcharacters% nearly \showcharacters
+ {\par
+ \bgroup
+ \ifcase\showmathmodern\or\ifx\modern\undefined\chardef\showmathmodern\zerocount\fi\fi
+ \setuptextrules[\c!bodyfont=,\c!style=]
+ \starttextrule{math characters -- \currentmathcollection}
+ \whitespace
+ \dontcomplain
+ \forgetall
+ \def\startmathcollection[##1]{}
+ \let\stopmathcollection\relax
+ \dimen0\zeropoint
+ \dimen2\zeropoint
+ \def\definemathsymbol {\dosixtupleempty\dodefinemathsymbol}
+ \def\definemathcharacter{\dosixtupleempty\dodefinemathcharacter}
+ \def\definemathcommand {\dotripleempty \dodefinemathcommand}
+ %\newcounter\mathcolor
+ \def\dodefinemathsymbol[##1][##2][##3][##4][##5][##6]%
+ {%\doifcolorelse{math \purefamilyhex{##3}}{}
+ % {\increment\mathcolor
+ % \definecolor[math \purefamilyhex{##3}][\mathcolor]}%
+ \setbox0\hbox spread 1em{\mathematics{\getvalue{##1}{}{}{}}}%
+ \ifdim\wd0>\dimen0 \dimen0=\wd0 \fi
+ \setbox2\hbox spread 1em{\hbox to 1em{\tttf\purefamilyhex{##3}\hss}\box0 ##1}%
+ \ifdim\wd2>\dimen2 \dimen2=\wd2 \fi}
+ \def\dodefinemathcharacter[##1][##2][##3][##4][##5][##6]{}
+ \def\dodefinemathcommand [##1][##2][##3]##4{}
+ \readsysfile{\f!mathprefix tex}\donothing\donothing
+ \readsysfile{\f!mathprefix ams}\donothing\donothing
+ \edef\encwidth{\the\dimen0}
+ \dimen0=\hsize
+ \advance\dimen0 2em
+ \advance\dimen2 2em
+ \ifcase\showmathmodern\or\advance\dimen2 4em\fi
+ \divide \dimen0 by \dimen2 \advance\dimen0 1sp
+ \edef\enccols{\number\dimen0}
+ \startcolumns[\c!n=\enccols,\c!distance=2em]
+ \def\dodefinemathsymbol[##1][##2][##3][##4][##5][##6]%
+ {%\localcolortrue
+ %\color
+ % [math \purefamilyhex{##3}]
+ {\hbox
+ {\ifcase\showmathmodern\or
+ \hbox to \encwidth{\modern\let\mathcollection\nomathcollection\mathematics{\getvalue{##1}{}{}{}}\hss}%
+ \fi
+ \hbox to \encwidth{\mathematics{\getvalue{##1}{}{}{}}\hss}%
+ \hbox to 1em{\tttf\purefamilyhex{##3}\hss}##1}\par}}
+ \readsysfile{\f!mathprefix tex}\donothing\donothing
+ \readsysfile{\f!mathprefix ams}\donothing\donothing
+ \stopcolumns
+ \stoptextrule
+ \egroup}
+
+% \definecolor[math \purefamilyhex{mr}] [darkred]
+% \definecolor[math \purefamilyhex{mi}] [darkgreen]
+% \definecolor[math \purefamilyhex{sy}] [darkblue]
+% \definecolor[math \purefamilyhex{ex}] [darkmagenta]
+% \definecolor[math \purefamilyhex{nn}] [darkyellow]
+% \definecolor[math \purefamilyhex{ma}] [lightred]
+% \definecolor[math \purefamilyhex{mb}] [lightgreen]
+% \definecolor[math \purefamilyhex{mc}] [lightblue]
+% \definecolor[math \purefamilyhex{md}] [lightmagenta]
+
+\gdef\showmathtoken#1%
+ {\starttabulate[|lT|lT|lT|l|]
+ \NC token \NC #1 \NC \NR
+ \NC collection \NC \ifcsname\@mt@\mathcollection#1\endcsname
+ \mathcollection
+ \else\ifcsname\@mt@\nomathcollection#1\endcsname
+ \nomathcollection
+ \else
+ ?%
+ \fi\fi \NC \NR
+ \NC visualization \NC \mathematics{\getvalue{#1}} \NC \NR
+ \NC definition \NC \tttf \@EA\defconvertedcommand\@EA\ascii\csname\@mt@\mathcollection#1\endcsname \ascii \NC \NR
+ \stoptabulate}
+
+\protect \endinput
diff --git a/tex/context/base/math-run.tex b/tex/context/base/math-run.tex
deleted file mode 100644
index affa8d5af..000000000
--- a/tex/context/base/math-run.tex
+++ /dev/null
@@ -1,95 +0,0 @@
-%D \module
-%D [ file=math-run,
-%D version=2001.23.04,
-%D title=\CONTEXT\ Math Macros,
-%D subtitle=Runtime Macros,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright=Hans Hagen \& Ton Otten]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\unprotect
-
-\ifx\showmathmodern\undefined \global\chardef\showmathmodern\zerocount \fi
-
-\gdef\showmathcharacters% nearly \showcharacters
- {\par
- \bgroup
- \ifcase\showmathmodern\or\ifx\modern\undefined\chardef\showmathmodern\zerocount\fi\fi
- \setuptextrules[\c!bodyfont=,\c!style=]
- \starttextrule{math characters -- \currentmathcollection}
- \whitespace
- \dontcomplain
- \forgetall
- \def\startmathcollection[##1]{}
- \let\stopmathcollection\relax
- \dimen0\zeropoint
- \dimen2\zeropoint
- \def\definemathsymbol {\dosixtupleempty\dodefinemathsymbol}
- \def\definemathcharacter{\dosixtupleempty\dodefinemathcharacter}
- \def\definemathcommand {\dotripleempty \dodefinemathcommand}
- %\newcounter\mathcolor
- \def\dodefinemathsymbol[##1][##2][##3][##4][##5][##6]%
- {%\doifcolorelse{math \purefamilyhex{##3}}{}
- % {\increment\mathcolor
- % \definecolor[math \purefamilyhex{##3}][\mathcolor]}%
- \setbox0\hbox spread 1em{\mathematics{\getvalue{##1}{}{}{}}}%
- \ifdim\wd0>\dimen0 \dimen0=\wd0 \fi
- \setbox2\hbox spread 1em{\hbox to 1em{\tttf\purefamilyhex{##3}\hss}\box0 ##1}%
- \ifdim\wd2>\dimen2 \dimen2=\wd2 \fi}
- \def\dodefinemathcharacter[##1][##2][##3][##4][##5][##6]{}
- \def\dodefinemathcommand [##1][##2][##3]##4{}
- \readsysfile{\f!mathprefix tex}\donothing\donothing
- \readsysfile{\f!mathprefix ams}\donothing\donothing
- \edef\encwidth{\the\dimen0}
- \dimen0=\hsize
- \advance\dimen0 2em
- \advance\dimen2 2em
- \ifcase\showmathmodern\or\advance\dimen2 4em\fi
- \divide \dimen0 by \dimen2 \advance\dimen0 1sp
- \edef\enccols{\number\dimen0}
- \startcolumns[\c!n=\enccols,\c!distance=2em]
- \def\dodefinemathsymbol[##1][##2][##3][##4][##5][##6]%
- {%\localcolortrue
- %\color
- % [math \purefamilyhex{##3}]
- {\hbox
- {\ifcase\showmathmodern\or
- \hbox to \encwidth{\modern\let\mathcollection\nomathcollection\mathematics{\getvalue{##1}{}{}{}}\hss}%
- \fi
- \hbox to \encwidth{\mathematics{\getvalue{##1}{}{}{}}\hss}%
- \hbox to 1em{\tttf\purefamilyhex{##3}\hss}##1}\par}}
- \readsysfile{\f!mathprefix tex}\donothing\donothing
- \readsysfile{\f!mathprefix ams}\donothing\donothing
- \stopcolumns
- \stoptextrule
- \egroup}
-
-% \definecolor[math \purefamilyhex{mr}] [darkred]
-% \definecolor[math \purefamilyhex{mi}] [darkgreen]
-% \definecolor[math \purefamilyhex{sy}] [darkblue]
-% \definecolor[math \purefamilyhex{ex}] [darkmagenta]
-% \definecolor[math \purefamilyhex{nn}] [darkyellow]
-% \definecolor[math \purefamilyhex{ma}] [lightred]
-% \definecolor[math \purefamilyhex{mb}] [lightgreen]
-% \definecolor[math \purefamilyhex{mc}] [lightblue]
-% \definecolor[math \purefamilyhex{md}] [lightmagenta]
-
-\gdef\showmathtoken#1%
- {\starttabulate[|lT|lT|lT|l|]
- \NC token \NC #1 \NC \NR
- \NC collection \NC \ifcsname\@mt@\mathcollection#1\endcsname
- \mathcollection
- \else\ifcsname\@mt@\nomathcollection#1\endcsname
- \nomathcollection
- \else
- ?%
- \fi\fi \NC \NR
- \NC visualization \NC \mathematics{\getvalue{#1}} \NC \NR
- \NC definition \NC \tttf \@EA\defconvertedcommand\@EA\ascii\csname\@mt@\mathcollection#1\endcsname \ascii \NC \NR
- \stoptabulate}
-
-\protect \endinput
diff --git a/tex/context/base/math-scr.mkiv b/tex/context/base/math-scr.mkiv
new file mode 100644
index 000000000..43355679f
--- /dev/null
+++ b/tex/context/base/math-scr.mkiv
@@ -0,0 +1,215 @@
+%D \module
+%D [ file=math-scr,
+%D version=2007.07.19,
+%D title=\CONTEXT\ Math Macros,
+%D subtitle=Scripts,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Math Macros / Scripts}
+
+\unprotect
+
+%D \macros
+%D {super, sub}
+%D
+%D \TEX\ uses \type{^} and \type{_} for entering super- and
+%D subscript mode. We want however a bit more control than
+%D normally provided, and therefore provide \type {\super}
+%D and \type{sub}.
+
+\global\let\normalsuper=^
+\global\let\normalsuber=_
+
+\newcount\supersubmode
+
+\newevery\everysupersub \EverySuperSub
+
+\appendtoks \advance\supersubmode \plusone \to \everysupersub
+
+\appendtoks
+ \gridsupsubstyle
+\to \everysupersub
+
+\appendtoks
+ \doifelse\@@mtsize\v!small
+ {\let\gridsupsubstyle \scriptscriptstyle
+ \let\gridsupsubbodyfont \setsmallbodyfont}%
+ {\let\gridsupsubstyle \scriptstyle
+ \let\gridsupsubbodyfont \relax}%
+\to \everysetuptextformulas
+
+\setuptextformulas
+ [\c!size=\v!normal]
+
+\def\dogridsupsub#1#2%
+ {\begingroup
+ \setbox\nextbox\iftracegridsnapping\ruledhbox\else\hbox\fi
+ {\gridsupsubbodyfont
+ $\strut^{\the\everysupersub#1}_{\the\everysupersub#2}$}%
+ \nextboxht\strutheight
+ \nextboxdp\strutdepth
+ \flushnextbox
+ \endgroup}
+
+\def\gridsupsub
+ {\ifconditional\crazymathsnapping
+ \ifgridsnapping
+ \@EAEAEA\dogridsupsub
+ \else
+ \@EAEAEA\normalsupsub
+ \fi
+ \else
+ \@EA\normalsupsub
+ \fi}
+
+\def\normalsupsub#1#2%
+ {^{\the\everysupersub#1}_{\the\everysupersub#2}}
+
+\appendtoks
+ \let\gridsupsubstyle \relax
+ \let\gridsupsubbodyfont\relax
+ \let\gridsupsub \normalsupsub
+\to \everydisplay
+
+\def\super#1{^{\the\everysupersub#1}}
+\def\suber#1{_{\the\everysupersub#1}}
+\def\supsub#1#2{\super{#1}\suber{#2}}
+\def\subsup#1#2{\suber{#1}\super{#2}}
+
+%\def\super#1{\gridsupsub{#1}{}} %
+%\def\suber#1{\gridsupsub{}{#1}} %
+%
+%\def\supsub#1#2{\gridsupsub{#1}{#2}}
+%\def\subsup#1#2{\gridsupsub{#2}{#1}}
+
+\def\gridsuper#1{\gridsupsub{#1}{}}
+\def\gridsuber#1{\gridsupsub{}{#1}}
+
+% \let\sup\super % math char
+% \let\sub\suber
+
+% test set:
+%
+% \startbuffer
+% \sform{x\frac{1}{2}}
+% \sform{x\sup{\frac{1}{2}} + x\sup{2} + 2}
+% \sform{x\supsub{\frac{1}{2}}{\frac{1}{2}} + x\sup{2} + 2}
+% \stopbuffer
+%
+% \typebuffer
+%
+% \startlines
+% \getbuffer
+% \stoplines
+%
+% \startbuffer
+% $x\frac{1}{2}$
+% $x\sup{\frac{1}{2}} + x^2 + 2$
+% $x\supsub{\frac{1}{2}}{\frac{1}{2}} + x^2 + 2$
+% \stopbuffer
+%
+% \typebuffer
+%
+% \start
+% \enablesupersub
+% \enableautomath
+% \startlines
+% \getbuffer
+% \stoplines
+% \stop
+
+%D \macros
+%D {enablesupersub,enablesimplesupersub}
+%D
+%D We can let \type {^} and \type {_} act like \type {\super}
+%D and \type {\sub} by saying \type {\enablesupersub}.
+
+\bgroup
+\catcode`\^=\@@active
+\catcode`\_=\@@active
+\gdef\enablesupersub
+ {\catcode`\^=\@@active
+ \def^{\ifmmode\expandafter\super\else\expandafter\normalsuper\fi}%
+ \catcode`\_=\@@active
+ \def_{\ifmmode\expandafter\suber\else\expandafter\normalsuber\fi}}
+\egroup
+
+%D \macros
+%D {restoremathstyle}
+%D
+%D We can pick up the current math style by calling \type
+%D {\restoremathstyle}.
+
+\def\restoremathstyle
+ {\ifmmode
+ \ifcase\supersubmode
+ \textstyle
+ \or
+ \scriptstyle
+ \else
+ \scriptscriptstyle
+ \fi
+ \fi}
+
+%D These macros were first needed by Frits Spijker (also
+%D known as Gajes) for typesetting the minus sign that is
+%D keyed into scientific calculators.
+
+% This is the first alternative, which works okay for the
+% minus, but less for the plus.
+%
+% \def\dodoraisedmathord#1#2#3%
+% {\mathord{{#2\raise.#1ex\hbox{#2#3}}}}
+%
+% \def\doraisedmathord#1%
+% {\mathchoice
+% {\dodoraisedmathord5\tf #1}%
+% {\dodoraisedmathord5\tf #1}%
+% {\dodoraisedmathord4\tfx #1}%
+% {\dodoraisedmathord3\tfxx#1}}
+%
+% \def\negative{\doraisedmathord-}
+% \def\positive{\doraisedmathord+}
+%
+% So, now we use the monospaced signs, that we also
+% define as symbol, so that they can be overloaded.
+
+\def\dodoraisedmathord#1#2#3%
+ {\mathord{{#2\raise.#1ex\hbox{#2\symbol[#3]}}}}
+
+\def\doraisedmathord#1%
+ {\mathchoice
+ {\dodoraisedmathord5\tf {#1}}%
+ {\dodoraisedmathord5\tf {#1}}%
+ {\dodoraisedmathord4\tx {#1}}%
+ {\dodoraisedmathord3\txx{#1}}}
+
+\def\dodonumbermathord#1#2%
+ {\setbox\scratchbox\hbox{0}%
+ \mathord{\hbox to \wd\scratchbox{\hss#1\symbol[#2]\hss}}}
+
+\def\donumbermathord#1%
+ {\mathchoice
+ {\dodonumbermathord\tf {#1}}%
+ {\dodonumbermathord\tf {#1}}%
+ {\dodonumbermathord\tx {#1}}%
+ {\dodonumbermathord\txx{#1}}}
+
+\definesymbol[positive] [\getglyph{Mono}{+}]
+\definesymbol[negative] [\getglyph{Mono}{-}]
+\definesymbol[zeroamount][\getglyph{Mono}{-}]
+
+\def\negative {\doraisedmathord{negative}}
+\def\positive {\doraisedmathord{positive}}
+\def\zeroamount{\donumbermathord{zeroamount}}
+
+%D How negative such a symbol looks is demonstrated in:
+%D $\negative 10^{\negative 10^{\negative 10}}$.
+
+\protect \endinput
diff --git a/tex/context/base/math-tex.tex b/tex/context/base/math-tex.tex
index 752f113b7..c833db956 100644
--- a/tex/context/base/math-tex.tex
+++ b/tex/context/base/math-tex.tex
@@ -232,7 +232,7 @@
\stopmathcollection
\def\PLAINangle
- {{\vbox{\ialign{$\m@th\scriptstyle##$\crcr
+ {{\vbox{\ialign{$\mathsurround\zeropoint\scriptstyle##$\crcr
\not\mathrel{\mkern14mu}\crcr
\noalign{\nointerlineskip}
\mkern2.5mu\leaders\hrule height.34pt\hfill\mkern2.5mu\crcr}}}}
@@ -424,12 +424,12 @@
{\cdotp\cdotp\cdotp}
\def\PLAINvdots
- {\vbox{\baselineskip4\p@ \lineskiplimit\z@
- \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
+ {\vbox{\baselineskip.4\bodyfontsize\lineskiplimit\zeropoint
+ \kern.6\bodyfontsize\hbox{.}\hbox{.}\hbox{.}}}
\def\PLAINddots
- {\mkern1mu\raise7\p@\vbox{\kern7\p@\hbox{.}}\mkern2mu
- \raise4\p@\hbox{.}\mkern2mu\raise\p@\hbox{.}\mkern1mu}
+ {\mkern1mu\raise.7\bodyfontsize\vbox{\kern.7\bodyfontsize\hbox{.}}\mkern2mu
+ \raise.4\bodyfontsize\hbox{.}\mkern2mu\raise.1\bodyfontsize\hbox{.}\mkern1mu}
\startmathcollection[default]
@@ -521,7 +521,7 @@
\def\notsosqrt[#1]{\root#1\of}
-\unexpanded\def\sqrt{\doifnextcharelse[\notsosqrt\normalsqrt}
+\unexpanded\def\sqrt{\doifnextoptionalelse\notsosqrt\normalsqrt}
\def\PLAINbig {\@@dobig{0.85}}
\def\PLAINBig {\@@dobig{1.15}}
@@ -561,12 +561,12 @@
\stopmathcollection
\def\PLAINroot#1#2%
- {\setbox\z@\hbox{$\m@th#1\sqrt{#2}$}\dimen@\ht\z@
- \advance\dimen@-\dp\z@
- \mkern5mu\raise.6\dimen@\copy\rootbox \mkern-10mu\box\z@}
+ {\setbox\zerocount\hbox{$\mathsurround\zeropoint#1\sqrt{#2}$}\dimen@\ht\zerocount
+ \advance\dimen@-\dp\zerocount
+ \mkern5mu\raise.6\dimen@\copy\rootbox \mkern-10mu\box\zerocount}
\def\PLAINmatrix#1%
- {\null\,\vcenter{\normalbaselines\m@th
+ {\null\,\vcenter{\normalbaselines\mathsurround\zeropoint
\ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
\mathstrut\crcr\noalign{\kern-\baselineskip}
#1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
@@ -651,7 +651,7 @@
%D The next macro vertically centeres its contents.
\def\@center@math#1%
- {\vcenter{\hbox{$\m@th#1$}}}
+ {\vcenter{\hbox{$\mathsurround\zeropoint#1$}}}
\def\@center@colon
{\mathpalette\@center@math{\colon}}
@@ -712,7 +712,6 @@
\mkern7mu\mathchoice{\mkern2mu}{}{}{}%
\let\dointlimits\egroup}
-
\setupmathematics
[integral=nolimits]
diff --git a/tex/context/base/math-tim.tex b/tex/context/base/math-tim.tex
index de6561ba7..3b9aea103 100644
--- a/tex/context/base/math-tim.tex
+++ b/tex/context/base/math-tim.tex
@@ -1,6 +1,6 @@
%D \module
%D [ file=math-tim,
-%D version=2001.04.12,
+%D version=2001.04.12,
%D title=\CONTEXT\ Math Macros,
%D subtitle=Mathtime Specials,
%D author={Hans Hagen \& Taco Hoekwater},
@@ -13,24 +13,24 @@
\endinput % i will clean this up after taco has gone over it
-%D With thanks to Berthold Horn from YandY for providing me
-%D evaluation copies of the MathTimePlus fonts.
+%D With thanks to Berthold Horn from YandY for providing me
+%D evaluation copies of the MathTimePlus fonts.
% version 0 : Michael Spivak
% version 1 : Taco Hoekwater
% version 2 : Hans Hagen
-% version 3 : etc etc etc
+% version 3 : etc etc etc
\unprotect
%D We use the predefined spare families \type {\mcfam} and
-%D \type {\mdfam}.
+%D \type {\mdfam}.
\let\cafam\mcfam \let\hexcafam\hexmcfam
\let\gbfam\mdfam \let\hexgbfam\hexmdfam
\let\gkfam\mdfam \let\hexgkfam\hexmdfam
-% Why is this needed?
+% Why is this needed?
% \font\tenmd =mtgu at 10pt
% \font\sevenmd=mtgu at 7.6pt
@@ -38,7 +38,7 @@
% \font\tenmc =mtms at 10pt
% \font\sevenmc=mtms at 7.6pt
% \font\fivemc =mtms at 6pt
-%
+%
% \textfont \mcfam\tenmc \textfont \mdfam\tenmd
% \scriptfont \mcfam\sevenmc \scriptfont \mdfam\sevenmd
% \scriptscriptfont\mcfam\fivemc \scriptscriptfont\mdfam\fivemd
@@ -52,7 +52,7 @@
% \definealternativestyle[script] [\ca][\ca]
% \definealternativestyle[greek] [\gk][\gk]
-% \definealternativestyle[boldgreek][\gb][\gb]
+% \definealternativestyle[boldgreek][\gb][\gb]
% \definebodyfont
% [5pt,6pt,7pt,8pt,9pt,10pt,11pt,12pt,14.4pt] [rm]
@@ -60,9 +60,9 @@
% gk=mtgu sa 1,
% gb=mtgub sa 1]
-%D Since a font size is a rather fuzzy thing, it will be no
-%D surprise that the Math Times fonts have different specs
-%D than the Computer Modern Roman fonts.
+%D Since a font size is a rather fuzzy thing, it will be no
+%D surprise that the Math Times fonts have different specs
+%D than the Computer Modern Roman fonts.
%D
%D \starttabulate[|Bl|c|c|c|c|c|c|c|c|c|c|]
%D \NC Computer Modern\NC
@@ -71,9 +71,9 @@
%D 6.0\NC6.8\NC7.6\NC8.4\NC9.2\NC10.0\NC10.8\NC11.6\NC13.2\NC--\NC\NR
%D \stoptabulate
%D
-%D The following definitions presume the existence of \type
-%D {tio} and \type {tibio} font alternatives. Definitions for
-%D \type {\tf.} etc and \type {\sc} are left as they are.
+%D The following definitions presume the existence of \type
+%D {tio} and \type {tibio} font alternatives. Definitions for
+%D \type {\tf.} etc and \type {\sc} are left as they are.
%D moved code
@@ -100,10 +100,10 @@
\def\tildehex{7E}
\def\ddothex {7F}
-%D The \type {mtex} fonts need a recalculation of \type
+%D The \type {mtex} fonts need a recalculation of \type
%D {\p@renwd}, which in \CONTEXT\ is done automatically.
-%D The following definitions are mostly copied from the file
+%D The following definitions are mostly copied from the file
%D \type {mtmacs.tex}, which banner said:
%D
%D \starttyping
@@ -112,9 +112,9 @@
%D ALL RIGHTS RESERVED
%D \stoptyping
%D
-%D We reformatted the macros and changed a few bits and
-%D pieces. A further cleanup with regards to the scratch
-%D registers will be done later.
+%D We reformatted the macros and changed a few bits and
+%D pieces. A further cleanup with regards to the scratch
+%D registers will be done later.
\mathchardef\Gamma = "0130
\mathchardef\Delta = "0131
@@ -171,7 +171,7 @@
% like \rm (cf. the texbook page 290)
\def\ifdefaultfamelse#1#2%
- {\ifnum\fam=\m@ne\mathaccent#1\else\mathaccent#2\fi}
+ {\ifnum\fam=\minusone\mathaccent#1\else\mathaccent#2\fi}
\let\noaccents@\relax
@@ -190,10 +190,10 @@
\def\mathhexbox@#1#2#3%
{\relax
\ifmmode
- \mathpalette{}{\m@th\rm\mathchar"#1#2#3}%
+ \mathpalette{}{\mathsurround\zeropoint\rm\mathchar"#1#2#3}%
\else
\leavevmode
- \hbox{$\m@th\rm\mathchar"#1#2#3$}%
+ \hbox{$\mathsurround\zeropoint\rm\mathchar"#1#2#3$}%
\fi}
\def\dag {\edef\next@{0\daghex }\expandafter\mathhexbox@\next@}
@@ -204,16 +204,16 @@
\def\vdots%
{\vbox
- {\baselineskip4\p@
- \lineskiplimit\z@
- \kern6\p@\hbox{$\m@th.$}\hbox{$\m@th.$}\hbox{$\m@th.$}}}
+ {\baselineskip4\points
+ \lineskiplimit\zeropoint
+ \kern6\points\hbox{$\mathsurround\zeropoint.$}\hbox{$\mathsurround\zeropoint.$}\hbox{$\mathsurround\zeropoint.$}}}
\def\ddots%
{\mathinner
{\mkern1mu
- \raise7\p@\vbox{\kern 7\p@\hbox{$\m@th.$}}\mkern2mu
- \raise4\p@\hbox{$\m@th.$}\mkern2mu
- \raise \p@\hbox{$\m@th.$}\mkern1mu}}
+ \raise7\points\vbox{\kern 7\points\hbox{$\mathsurround\zeropoint.$}}\mkern2mu
+ \raise4\points\hbox{$\mathsurround\zeropoint.$}\mkern2mu
+ \raise \points\hbox{$\mathsurround\zeropoint.$}\mkern1mu}}
\def\hbar
{{\mathchoice
@@ -224,10 +224,10 @@
\mkern-6.3muh}}
\def\angle%
- {{\vbox{\ialign{$\m@th\scriptstyle##$\crcr
+ {{\vbox{\ialign{$\mathsurround\zeropoint\scriptstyle##$\crcr
\not\mathrel{\mkern14mu}\crcr
\noalign{\nointerlineskip}
- \mkern2.5mu\leaders\hrule height.48\p@\hfill\mkern2.5mu\crcr}}}}
+ \mkern2.5mu\leaders\hrule height.48\points\hfill\mkern2.5mu\crcr}}}}
\newdimen\amstexex
@@ -235,25 +235,25 @@
\def\varinjlim%
{\mathop{\vtop{\ialign{##\crcr
- \hfil\the\textfont\z@ lim\hfil\crcr
+ \hfil\the\textfont\zerocount lim\hfil\crcr
\noalign{\nointerlineskip}\rightarrowfill\crcr
\noalign{\nointerlineskip\kern-\amstexex}\crcr}}}}
\def\varprojlim%
{\mathop{\vtop{\ialign{##\crcr
- \hfil\the\textfont\z@ lim\hfil\crcr
+ \hfil\the\textfont\zerocount lim\hfil\crcr
\noalign{\nointerlineskip}\leftarrowfill\crcr
\noalign{\nointerlineskip\kern-\amstexex}\crcr}}}}
\def\varliminf{\mathop{\underbar {lim}}} % context-ified
\def\varlimsup{\mathop{\overstrike{lim}}} % context-ified
-\def\spdot {^{\hbox{\raise\amstexex\hbox{\the\textfont\z@ .}}}}
-\def\spddot {^{\hbox{\raise\amstexex\hbox{\the\textfont\z@ ..}}}}
-\def\spdddot {^{\hbox{\raise\amstexex\hbox{\the\textfont\z@ ...}}}}
-\def\spddddot{^{\hbox{\raise\amstexex\hbox{\the\textfont\z@....}}}}
+\def\spdot {^{\hbox{\raise\amstexex\hbox{\the\textfont\zerocount .}}}}
+\def\spddot {^{\hbox{\raise\amstexex\hbox{\the\textfont\zerocount ..}}}}
+\def\spdddot {^{\hbox{\raise\amstexex\hbox{\the\textfont\zerocount ...}}}}
+\def\spddddot{^{\hbox{\raise\amstexex\hbox{\the\textfont\zerocount....}}}}
-%D Here some code is merged in order to save strings.
+%D Here some code is merged in order to save strings.
\def\domultidot#1#2%
{\setbox0\hbox{$#1#2$}%
@@ -303,29 +303,29 @@
\fi}
\def\root#1\of#2%
- {\setbox\rootbox=\hbox{$\m@th\scriptscriptstyle{#1}$}%
+ {\setbox\rootbox=\hbox{$\mathsurround\zeropoint\scriptscriptstyle{#1}$}%
\mathpalette\r@@t{#2}}
\def\r@@t#1#2%
- {\setbox\z@=\hbox{$\uproot@\z@\leftroot\z@\m@th#1\sqrt{#2}$}%
- \dimen@\ht\z@\advance\dimen@-\dp\z@
+ {\setbox\zerocount\hbox{$\uproot@\zerocount\leftroot\zerocount\mathsurround\zeropoint#1\sqrt{#2}$}%
+ \dimen@\ht\zerocount\advance\dimen@-\dp\zerocount
\dimen@ii\dimen@
- \ifdim\dimen@>30\p@ \advance\dimen@ii-16\p@ \else
- \ifdim\dimen@>24\p@ \advance\dimen@ii -8\p@ \else
- \ifdim\dimen@>18\p@ \advance\dimen@ii -6\p@ \else
- \ifdim\dimen@>12\p@ \advance\dimen@ii -4\p@ \else
- \ifdim\dimen@>10\p@ \advance\dimen@ii -2\p@ \fi\fi\fi\fi\fi
- \setbox\tw@=\hbox{$\m@th#1\mskip\uproot@ mu$}%
- \advance\dimen@ii by1.667\wd\tw@
+ \ifdim\dimen@>30\points \advance\dimen@ii-16\points \else
+ \ifdim\dimen@>24\points \advance\dimen@ii -8\points \else
+ \ifdim\dimen@>18\points \advance\dimen@ii -6\points \else
+ \ifdim\dimen@>12\points \advance\dimen@ii -4\points \else
+ \ifdim\dimen@>10\points \advance\dimen@ii -2\points \fi\fi\fi\fi\fi
+ \setbox\plustwo=\hbox{$\mathsurround\zeropoint#1\mskip\uproot@ mu$}%
+ \advance\dimen@ii by1.667\wd\plustwo
\mkern-\leftroot@ mu\mkern5mu\raise.6\dimen@ii\copy\rootbox
- \mkern-8mu\mkern\leftroot@ mu\box\z@\leftroot\z@\uproot\z@}
+ \mkern-8mu\mkern\leftroot@ mu\box\zerocount\leftroot\zerocount\uproot\zerocount}
\def\space@.{\futurelet\space@\relax} \space@. % really needed ?
\def\jadjust%
- {\mkern-\tw@ mu}
+ {\mkern-\plustwo mu}
-%D For the moment the following code is left unchanged. It is
+%D For the moment the following code is left unchanged. It is
%D not used anyway.
\newif\ifsubscriptcorrection \subscriptcorrectionfalse
@@ -358,11 +358,11 @@
\else
\def\next@.%
{\ifx\next j%
- \mkern-\tw@ mu\else
+ \mkern-\plustwo mu\else
\ifx\next f%
- \mkern-\tw@ mu\else
+ \mkern-\plustwo mu\else
\ifx\next p%
- \mkern-\@ne mu\fi\fi\fi}%
+ \mkern-\plusone mu\fi\fi\fi}%
\fi
\next@.}
diff --git a/tex/context/base/math-vfu.lua b/tex/context/base/math-vfu.lua
new file mode 100644
index 000000000..35d18d77a
--- /dev/null
+++ b/tex/context/base/math-vfu.lua
@@ -0,0 +1,1534 @@
+if not modules then modules = { } end modules ['math-vfu'] = {
+ version = 1.001,
+ comment = "companion to math-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- All these math vectors .. thanks to Aditya and Mojca they become
+-- better and better.
+
+local type, next = type, next
+
+local trace_virtual = false trackers.register("math.virtual", function(v) trace_virtual = v end)
+local trace_timings = false trackers.register("math.timings", function(v) trace_timings = v end)
+
+fonts.enc.math = fonts.enc.math or { }
+
+local shared = { }
+
+fonts.vf.math = fonts.vf.math or { }
+fonts.vf.math.optional = false
+
+local push, pop, back = { "push" }, { "pop" }, { "slot", 1, 0x2215 }
+
+local function negate(main,unicode,basecode)
+ local characters = main.characters
+ if not characters[unicode] then
+ local basechar = characters[basecode]
+ if basechar then
+ local ht, wd = basechar.height, basechar.width
+ characters[unicode] = {
+ width = wd,
+ height = ht,
+ depth = basechar.depth,
+ italic = basechar.italic,
+ kerns = basechar.kerns,
+ commands = {
+ { "slot", 1, basecode },
+ push,
+ { "down", ht/5},
+ { "right", - wd/2},
+ back,
+ push,
+ }
+ }
+ end
+ end
+end
+
+--~ \Umathchardef\braceld="0 "1 "FF07A
+--~ \Umathchardef\bracerd="0 "1 "FF07B
+--~ \Umathchardef\bracelu="0 "1 "FF07C
+--~ \Umathchardef\braceru="0 "1 "FF07D
+
+local function brace(main,unicode,first,rule,left,right,rule,last)
+ local characters = main.characters
+ if not characters[unicode] then
+ characters[unicode] = {
+ horiz_variants = {
+ { extender = 0, glyph = first },
+ { extender = 1, glyph = rule },
+ { extender = 0, glyph = left },
+ { extender = 0, glyph = right },
+ { extender = 1, glyph = rule },
+ { extender = 0, glyph = last },
+ }
+ }
+ end
+end
+
+local function arrow(main,unicode,arrow,minus,isleft)
+ if isleft then
+ t = {
+ { extender = 0, glyph = arrow },
+ { extender = 1, glyph = minus },
+ }
+ else
+ t = {
+ { extender = 0, glyph = minus },
+ { extender = 1, glyph = arrow },
+ }
+ end
+--~ main.characters[unicode] = { horiz_variants = t }
+ main.characters[unicode].horiz_variants = t
+end
+
+local function parent(main,unicode,first,rule,last)
+ local characters = main.characters
+ if not characters[unicode] then
+ characters[unicode] = {
+ horiz_variants = {
+ { extender = 0, glyph = first },
+ { extender = 1, glyph = rule },
+ { extender = 0, glyph = last },
+ }
+ }
+ end
+end
+
+local push, pop, step = { "push" }, { "pop" }, 0.2 -- 0.1 is nicer but gives larger files
+
+local function make(main,id,size,n,m)
+ local characters = main.characters
+ local xu = main.parameters.x_height + 0.3*size
+ local xd = 0.3*size
+ local old, upslot, dnslot, uprule, dnrule = 0xFF000+n, 0xFF100+n, 0xFF200+n, 0xFF300+m, 0xFF400+m
+ local c = characters[old]
+ if c then
+ local w, h, d = c.width, c.height, c.depth
+ local thickness = h - d
+ local rulewidth = step*size -- we could use an overlap
+ local slot = { "slot", id, old }
+ local rule = { "rule", thickness, rulewidth }
+ local up = { "down", -xu }
+ local dn = { "down", xd }
+ local ht, dp = xu + 3*thickness, 0
+ if not characters[uprule] then
+ characters[uprule] = { width = rulewidth, height = ht, depth = dp, commands = { push, up, rule, pop } }
+ end
+ characters[upslot] = { width = w, height = ht, depth = dp, commands = { push, up, slot, pop } }
+ local ht, dp = 0, xd + 3*thickness
+ if not characters[dnrule] then
+ characters[dnrule] = { width = rulewidth, height = ht, depth = dp, commands = { push, dn, rule, pop } }
+ end
+ characters[dnslot] = { width = w, height = ht, depth = dp, commands = { push, dn, slot, pop } }
+ end
+end
+
+local function minus(main,id,size,unicode)
+ local characters = main.characters
+ local mu = size/18
+ local minus = characters[0x002D]
+ local width = minus.width - 5*mu
+ characters[unicode] = {
+ width = width, height = minus.height, depth = minus.depth,
+ commands = { push, { "right", -3*mu }, { "slot", id, 0x002D }, pop }
+ }
+end
+
+local function dots(main,id,size,unicode)
+ local characters = main.characters
+ local c = characters[0x002E]
+ local w, h, d = c.width, c.height, c.depth
+ local mu = size/18
+ local right3mu = { "right", 3*mu }
+ local right1mu = { "right", 1*mu }
+ local up1size = { "down", -.1*size }
+ local up4size = { "down", -.4*size }
+ local up7size = { "down", -.7*size }
+ local right2muw = { "right", 2*mu + w }
+ local slot = { "slot", id, 0x002E }
+ if unicode == 0x22EF then
+ local c = characters[0x022C5]
+ if c then
+ local w, h, d = c.width, c.height, c.depth
+ local slot = { "slot", id, 0x022C5 }
+ characters[unicode] = {
+ width = 3*w + 2*3*mu, height = h, depth = d,
+ commands = { push, slot, right3mu, slot, right3mu, slot, pop }
+ }
+ end
+ elseif unicode == 0x22EE then
+ -- weird height !
+ characters[unicode] = {
+ width = w, height = h+(1.4)*size, depth = 0,
+ commands = { push, push, slot, pop, up4size, push, slot, pop, up4size, slot, pop }
+ }
+ elseif unicode == 0x22F1 then
+ characters[unicode] = {
+ width = 3*w + 6*size/18, height = 1.5*size, depth = 0,
+ commands = {
+ push,
+ right1mu,
+ push, up7size, slot, pop,
+ right2muw,
+ push, up4size, slot, pop,
+ right2muw,
+ push, up1size, slot, pop,
+ right1mu,
+ pop
+ }
+ }
+ elseif unicode == 0x22F0 then
+ characters[unicode] = {
+ width = 3*w + 6*size/18, height = 1.5*size, depth = 0,
+ commands = {
+ push,
+ right1mu,
+ push, up1size, slot, pop,
+ right2muw,
+ push, up4size, slot, pop,
+ right2muw,
+ push, up7size, slot, pop,
+ right1mu,
+ pop
+ }
+ }
+ else
+ characters[unicode] = {
+ width = 3*w + 2*3*mu, height = h, depth = d,
+ commands = { push, slot, right3mu, slot, right3mu, slot, pop }
+ }
+ end
+end
+
+function fonts.vf.math.alas(main,id,size)
+ for i=0x7A,0x7D do
+ make(main,id,size,i,1)
+ end
+ brace (main,0x23DE,0xFF17A,0xFF301,0xFF17D,0xFF17C,0xFF301,0xFF17B)
+ brace (main,0x23DF,0xFF27C,0xFF401,0xFF27B,0xFF27A,0xFF401,0xFF27D)
+ parent(main,0x23DC,0xFF17A,0xFF301,0xFF17B)
+ parent(main,0x23DD,0xFF27C,0xFF401,0xFF27D)
+ negate(main,0x2260,0x003D)
+ dots(main,id,size,0x2026) -- ldots
+ dots(main,id,size,0x22EE) -- vdots
+ dots(main,id,size,0x22EF) -- cdots
+ dots(main,id,size,0x22F1) -- ddots
+ dots(main,id,size,0x22F0) -- udots
+ minus(main,id,size,0xFF501)
+ arrow(main,0x2190,0xFE190,0xFF501,true) -- left
+ arrow(main,0x2192,0xFE192,0xFF501,false) -- right
+end
+
+local reverse -- index -> unicode
+
+function fonts.basecopy(tfmtable)
+ local t, c, p = { }, { }, { }
+ for k, v in next, tfmtable do
+ t[k] = v
+ end
+ for k, v in next, tfmtable.characters do
+ c[k] = v
+ end
+ for k, v in next, tfmtable.parameters do
+ p[k] = v
+ end
+ t.characters, t.parameters = c, p
+ return t
+end
+
+function fonts.vf.math.define(specification,set)
+ if not reverse then
+ reverse = { }
+ for k, v in next, fonts.enc.math do
+ local r = { }
+ for u, i in next, v do
+ r[i] = u
+ end
+ reverse[k] = r
+ end
+ end
+ local name = specification.name -- symbolic name
+ local size = specification.size -- given size
+ local fnt, lst, main = { }, { }, nil
+ local start = (trace_virtual or trace_timings) and os.clock()
+--~ texio.write_nl("defining font " .. name .. " " .. size)
+ local okset, n = { }, 0
+ for s=1,#set do
+ local ss = set[s]
+ local ssname = ss.name
+ if ss.optional and fonts.vf.math.optional then
+ if trace_virtual then
+ logs.report("math virtual","loading font %s subfont %s with name %s at %s is skipped",name,s,ssname,size)
+ end
+ else
+ if ss.features then ssname = ssname .. "*" .. ss.features end
+ if ss.main then main = s end
+ local f, id = fonts.tfm.read_and_define(ssname,size)
+ if not f then
+ logs.report("math virtual","loading font %s subfont %s with name %s at %s is skipped, not found",name,s,ssname,size)
+ else
+ n = n + 1
+ okset[n] = ss
+ fnt[n] = f
+ lst[n] = { id = id, size = size }
+ if not shared[s] then shared[n] = { } end
+ if trace_virtual then
+ logs.report("math virtual","loading font %s subfont %s with name %s at %s as id %s using encoding %s",name,s,ssname,size,id,ss.vector or "none")
+ end
+ end
+ end
+ end
+ -- beware, fnt[1] is already passed to tex (we need to make a simple copy then .. todo)
+ main = fonts.basecopy(fnt[1])
+ main.name, main.fonts, main.virtualized, main.math_parameters = name, lst, true, { }
+ local characters, descriptions = main.characters, main.descriptions
+ main.parameters.x_height = main.parameters.x_height or 0
+ for s=1,n do
+ local ss, fs = okset[s], fnt[s]
+ if not fs then
+ -- skip, error
+ elseif ss.optional and fonts.vf.math.optional then
+ -- skip, redundant
+ else
+ local mm, fp = main.math_parameters, fs.parameters
+ if ss.extension then
+ mm.math_x_height = fp.x_height or 0 -- math_x_height height of x
+ mm.default_rule_thickness = fp[ 8] or 0 -- default_rule_thickness thickness of \over bars
+ mm.big_op_spacing1 = fp[ 9] or 0 -- big_op_spacing1 minimum clearance above a displayed op
+ mm.big_op_spacing2 = fp[10] or 0 -- big_op_spacing2 minimum clearance below a displayed op
+ mm.big_op_spacing3 = fp[11] or 0 -- big_op_spacing3 minimum baselineskip above displayed op
+ mm.big_op_spacing4 = fp[12] or 0 -- big_op_spacing4 minimum baselineskip below displayed op
+ mm.big_op_spacing5 = fp[13] or 0 -- big_op_spacing5 padding above and below displayed limits
+ -- logs.report("math virtual","loading and virtualizing font %s at size %s, setting ex parameters",name,size)
+ elseif ss.parameters then
+ main.parameters.x_height = fp.x_height or main.parameters.x_height
+ mm.x_height = mm.x_height or fp.x_height or 0 -- x_height height of x
+ mm.num1 = fp[ 8] or 0 -- num1 numerator shift-up in display styles
+ mm.num2 = fp[ 9] or 0 -- num2 numerator shift-up in non-display, non-\atop
+ mm.num3 = fp[10] or 0 -- num3 numerator shift-up in non-display \atop
+ mm.denom1 = fp[11] or 0 -- denom1 denominator shift-down in display styles
+ mm.denom2 = fp[12] or 0 -- denom2 denominator shift-down in non-display styles
+ mm.sup1 = fp[13] or 0 -- sup1 superscript shift-up in uncramped display style
+ mm.sup2 = fp[14] or 0 -- sup2 superscript shift-up in uncramped non-display
+ mm.sup3 = fp[15] or 0 -- sup3 superscript shift-up in cramped styles
+ mm.sub1 = fp[16] or 0 -- sub1 subscript shift-down if superscript is absent
+ mm.sub2 = fp[17] or 0 -- sub2 subscript shift-down if superscript is present
+ mm.sup_drop = fp[18] or 0 -- sup_drop superscript baseline below top of large box
+ mm.sub_drop = fp[19] or 0 -- sub_drop subscript baseline below bottom of large box
+ mm.delim1 = fp[20] or 0 -- delim1 size of \atopwithdelims delimiters in display styles
+ mm.delim2 = fp[21] or 0 -- delim2 size of \atopwithdelims delimiters in non-displays
+ mm.axis_height = fp[22] or 0 -- axis_height height of fraction lines above the baseline
+ -- logs.report("math virtual","loading and virtualizing font %s at size %s, setting sy parameters",name,size)
+ end
+ local vectorname = ss.vector
+ if vectorname then
+ local offset = 0xFF000
+ local vector = fonts.enc.math[vectorname]
+ local rotcev = reverse[vectorname]
+ if vector then
+ local fc, fd, si = fs.characters, fs.descriptions, shared[s]
+ local skewchar = ss.skewchar
+ for unicode, index in next, vector do
+ local fci = fc[index]
+ if not fci then
+ -- if trace_virtual then
+ logs.report("math virtual", "unicode point U+%04X has no index %04X in %s",unicode,index,vectorname)
+ -- end
+ else
+ local ref = si[index]
+ if not ref then
+ ref = { { 'slot', s, index } }
+ si[index] = ref
+ end
+ local kerns = fci.kerns
+ if kerns then
+ local width = fci.width
+ local krn = { }
+ for k=1,#kerns do
+ local rk = rotcev[k]
+ if rk then
+ krn[rk] = kerns[k]
+ end
+ end
+ if not next(krn) then
+ krn = nil
+ end
+ local t = {
+ width = width,
+ height = fci.height,
+ depth = fci.depth,
+ italic = fci.italic,
+ kerns = krn,
+ commands = ref,
+ }
+ if skewchar and kerns then
+ local k = kerns[skewchar]
+ if k then
+ t.top_accent = width/2 + k
+ end
+ end
+ characters[unicode] = t
+ else
+ characters[unicode] = {
+ width = fci.width,
+ height = fci.height,
+ depth = fci.depth,
+ italic = fci.italic,
+ commands = ref,
+ }
+ end
+ end
+ end
+ if ss.extension then
+ -- todo: if multiple ex, then 256 offsets per instance
+ local extension = fonts.enc.math["large-to-small"]
+ local variants_done = fs.variants_done
+ for index, fci in next, fc do -- the raw ex file
+ if type(index) == "number" then
+ local ref = si[index]
+ if not ref then
+ ref = { { 'slot', s, index } }
+ si[index] = ref
+ end
+ local t = {
+ width = fci.width,
+ height = fci.height,
+ depth = fci.depth,
+ italic = fci.italic,
+ commands = ref,
+ }
+ local n = fci.next
+ if n then
+ t.next = offset + n
+ elseif variants_done then
+ local vv = fci.vert_variants
+ if vv then
+ t.vert_variants = vv
+ end
+ local hv = fci.horiz_variants
+ if hv then
+ t.horiz_variants = hv
+ end
+ else
+ local vv = fci.vert_variants
+ if vv then
+ for i=1,#vv do
+ local vvi = vv[i]
+ vvi.glyph = vvi.glyph + offset
+ end
+ t.vert_variants = vv
+ end
+ local hv = fci.horiz_variants
+ if hv then
+ for i=1,#hv do
+ local hvi = hv[i]
+ hvi.glyph = hvi.glyph + offset
+ end
+ t.horiz_variants = hv
+ end
+ end
+ characters[offset + index] = t
+ end
+ end
+ fs.variants_done = true
+ for unicode, index in next, extension do
+ local cu = characters[unicode]
+ if cu then
+ cu.next = offset + index
+ --~ local n, c, d = unicode, cu, { }
+ --~ print("START", unicode)
+ --~ while n do
+ --~ n = c.next
+ --~ if n then
+ --~ print("NEXT", n)
+ --~ c = characters[n]
+ --~ if not c then
+ --~ print("EXIT")
+ --~ elseif d[n] then
+ --~ print("LOOP")
+ --~ break
+ --~ end
+ --~ d[n] = true
+ --~ end
+ --~ end
+ else
+ local fci = fc[index]
+ local ref = si[index]
+ if not ref then
+ ref = { { 'slot', s, index } }
+ si[index] = ref
+ end
+ local kerns = fci.kerns
+ if kerns then
+ local krn = { }
+ for k=1,#kerns do
+ krn[offset + k] = kerns[k]
+ end
+ characters[unicode] = {
+ width = fci.width,
+ height = fci.height,
+ depth = fci.depth,
+ italic = fci.italic,
+ commands = ref,
+ kerns = krn,
+ next = offset + index,
+ }
+ else
+ characters[unicode] = {
+ width = fci.width,
+ height = fci.height,
+ depth = fci.depth,
+ italic = fci.italic,
+ commands = ref,
+ next = offset + index,
+ }
+ end
+ end
+ end
+ end
+ end
+ end
+ mathematics.extras.copy(main) --not needed here (yet)
+ end
+ end
+ lst[#lst+1] = { id = font.nextid(), size = size }
+ fonts.vf.math.alas(main,#lst,size)
+ if trace_virtual or trace_timings then
+ logs.report("math virtual","loading and virtualizing font %s at size %s took %0.3f seconds",name,size,os.clock()-start)
+ end
+ main.has_italic = true
+ main.type = "virtual" -- not needed
+ mathematics.scaleparameters(main,main,1)
+ return main
+end
+
+function mathematics.make_font(name, set)
+ fonts.define.methods[name] = function(specification)
+ return fonts.vf.math.define(specification,set)
+ end
+end
+
+-- varphi is part of the alphabet, contrary to the other var*s'
+
+fonts.enc.math["large-to-small"] = {
+ [0x00028] = 0x00, -- (
+ [0x00029] = 0x01, -- )
+ [0x0005B] = 0x02, -- [
+ [0x0005D] = 0x03, -- ]
+ [0x0230A] = 0x04, -- lfloor
+ [0x0230B] = 0x05, -- rfloor
+ [0x02308] = 0x06, -- lceil
+ [0x02309] = 0x07, -- rceil
+ [0x0007B] = 0x08, -- {
+ [0x0007D] = 0x09, -- }
+ [0x027E8] = 0x0A, -- <
+ [0x027E9] = 0x0B, -- >
+ [0x0007C] = 0x0C, -- |
+--~ [0x0] = 0x0D, -- lVert rVert Vert
+-- [0x0002F] = 0x0E, -- /
+ [0x0005C] = 0x0F, -- \
+--~ [0x0] = 0x3A, -- lgroup
+--~ [0x0] = 0x3B, -- rgroup
+--~ [0x0] = 0x3C, -- arrowvert
+--~ [0x0] = 0x3D, -- Arrowvert
+ [0x02195] = 0x3F, -- updownarrow
+--~ [0x0] = 0x40, -- lmoustache
+--~ [0x0] = 0x41, -- rmoustache
+ [0x0221A] = 0x70, -- sqrt
+ [0x021D5] = 0x77, -- Updownarrow
+ [0x02191] = 0x78, -- uparrow
+ [0x02193] = 0x79, -- downarrow
+ [0x021D1] = 0x7E, -- Uparrow
+ [0x021D3] = 0x7F, -- Downarrow
+ [0x0220F] = 0x59, -- prod
+ [0x02210] = 0x61, -- coprod
+ [0x02211] = 0x58, -- sum
+ [0x0222B] = 0x5A, -- intop
+ [0x0222E] = 0x49, -- ointop
+ [0xFE302] = 0x62, -- widehat
+ [0xFE303] = 0x65, -- widetilde
+ [0x022C0] = 0x5E, -- bigwedge
+ [0x022C1] = 0x5F, -- bigvee
+ [0x022C2] = 0x5C, -- bigcap
+ [0x022C3] = 0x5B, -- bigcup
+ [0x02044] = 0x0E, -- /
+}
+
+fonts.enc.math["tex-ex"] = {
+ [0x0220F] = 0x51, -- prod
+ [0x0222B] = 0x52, -- intop
+ [0x02210] = 0x60, -- coprod
+ [0x02211] = 0x50, -- sum
+ [0x022C0] = 0x56, -- bigwedge
+ [0x022C1] = 0x57, -- bigvee
+ [0x022C2] = 0x54, -- bigcap
+ [0x022C3] = 0x53, -- bigcup
+ [0x02A04] = 0x55, -- biguplus
+ [0x02A02] = 0x4E, -- bigotimes
+ [0x02A01] = 0x4C, -- bigoplus
+ [0x02A03] = 0x4A, -- bigodot
+ [0x0222E] = 0x48, -- ointop
+ [0x02A06] = 0x46, -- bigsqcup
+}
+
+-- only math stuff is needed, since we always use an lm or gyre
+-- font as main font
+
+fonts.enc.math["tex-mr"] = {
+ [0x00393] = 0x00, -- Gamma
+ [0x00394] = 0x01, -- Delta
+ [0x00398] = 0x02, -- Theta
+ [0x0039B] = 0x03, -- Lambda
+ [0x0039E] = 0x04, -- Xi
+ [0x003A0] = 0x05, -- Pi
+ [0x003A3] = 0x06, -- Sigma
+ [0x003A5] = 0x07, -- Upsilon
+ [0x003A6] = 0x08, -- Phi
+ [0x003A8] = 0x09, -- Psi
+ [0x003A9] = 0x0A, -- Omega
+-- [0x00060] = 0x12, -- [math]grave
+-- [0x000B4] = 0x13, -- [math]acute
+-- [0x002C7] = 0x14, -- [math]check
+-- [0x002D8] = 0x15, -- [math]breve
+-- [0x000AF] = 0x16, -- [math]bar
+-- [0x00021] = 0x21, -- !
+-- [0x00028] = 0x28, -- (
+-- [0x00029] = 0x29, -- )
+-- [0x0002B] = 0x2B, -- +
+-- [0x0002F] = 0x2F, -- /
+-- [0x0003A] = 0x3A, -- :
+-- [0x02236] = 0x3A, -- colon
+-- [0x0003B] = 0x3B, -- ;
+-- [0x0003C] = 0x3C, -- <
+-- [0x0003D] = 0x3D, -- =
+-- [0x0003E] = 0x3E, -- >
+-- [0x0003F] = 0x3F, -- ?
+ [0x00391] = 0x41, -- Alpha
+ [0x00392] = 0x42, -- Beta
+ [0x02145] = 0x44,
+ [0x00395] = 0x45, -- Epsilon
+ [0x00397] = 0x48, -- Eta
+ [0x00399] = 0x49, -- Iota
+ [0x0039A] = 0x4B, -- Kappa
+ [0x0039C] = 0x4D, -- Mu
+ [0x0039D] = 0x4E, -- Nu
+ [0x0039F] = 0x4F, -- Omicron
+ [0x003A1] = 0x52, -- Rho
+ [0x003A4] = 0x54, -- Tau
+ [0x003A7] = 0x58, -- Chi
+ [0x00396] = 0x5A, -- Zeta
+-- [0x0005B] = 0x5B, -- [
+-- [0x0005D] = 0x5D, -- ]
+-- [0x0005E] = 0x5E, -- [math]hat -- the text one
+ [0x00302] = 0x5E, -- [math]hat -- the real math one
+-- [0x002D9] = 0x5F, -- [math]dot
+ [0x02146] = 0x64,
+ [0x02147] = 0x65,
+-- [0x002DC] = 0x7E, -- [math]tilde -- the text one
+ [0x00303] = 0x7E, -- [math]tilde -- the real one
+-- [0x000A8] = 0x7F, -- [math]ddot
+}
+
+fonts.enc.math["tex-mi"] = {
+ [0x1D6E4] = 0x00, -- Gamma
+ [0x1D6E5] = 0x01, -- Delta
+ [0x1D6E9] = 0x02, -- Theta
+ [0x1D6F3] = 0x02, -- varTheta (not present in TeX)
+ [0x1D6EC] = 0x03, -- Lambda
+ [0x1D6EF] = 0x04, -- Xi
+ [0x1D6F1] = 0x05, -- Pi
+ [0x1D6F4] = 0x06, -- Sigma
+ [0x1D6F6] = 0x07, -- Upsilon
+ [0x1D6F7] = 0x08, -- Phi
+ [0x1D6F9] = 0x09, -- Psi
+ [0x1D6FA] = 0x0A, -- Omega
+ [0x1D6FC] = 0x0B, -- alpha
+ [0x1D6FD] = 0x0C, -- beta
+ [0x1D6FE] = 0x0D, -- gamma
+ [0x1D6FF] = 0x0E, -- delta
+ [0x1D716] = 0x0F, -- epsilon TODO: 1D716
+ [0x1D701] = 0x10, -- zeta
+ [0x1D702] = 0x11, -- eta
+ [0x1D703] = 0x12, -- theta TODO: 1D703
+ [0x1D704] = 0x13, -- iota
+ [0x1D705] = 0x14, -- kappa
+ [0x1D718] = 0x14, -- varkappa, not in tex fonts
+ [0x1D706] = 0x15, -- lambda
+ [0x1D707] = 0x16, -- mu
+ [0x1D708] = 0x17, -- nu
+ [0x1D709] = 0x18, -- xi
+ [0x1D70B] = 0x19, -- pi
+ [0x1D70C] = 0x1A, -- rho
+ [0x1D70E] = 0x1B, -- sigma
+ [0x1D70F] = 0x1C, -- tau
+ [0x1D710] = 0x1D, -- upsilon
+ [0x1D719] = 0x1E, -- phi
+ [0x1D712] = 0x1F, -- chi
+ [0x1D713] = 0x20, -- psi
+ [0x1D714] = 0x21, -- omega
+ [0x1D700] = 0x22, -- varepsilon (the other way around)
+ [0x1D717] = 0x23, -- vartheta
+ [0x1D71B] = 0x24, -- varpi
+ [0x1D71A] = 0x25, -- varrho
+ [0x1D70D] = 0x26, -- varsigma
+ [0x1D711] = 0x27, -- varphi (the other way around)
+ [0x021BC] = 0x28, -- leftharpoonup
+ [0x021BD] = 0x29, -- leftharpoondown
+ [0x021C0] = 0x2A, -- righttharpoonup
+ [0x021C1] = 0x2B, -- rightharpoondown
+ -- 0x2C, -- lhook (hook for combining arrows)
+ -- 0x2D, -- rhook (hook for combining arrows)
+ [0x022B3] = 0x2E, -- triangleright (TODO: which one is right?)
+ [0x022B2] = 0x2F, -- triangleleft (TODO: which one is right?)
+-- [0x00041] = 0x30, -- 0
+-- [0x00041] = 0x31, -- 1
+-- [0x00041] = 0x32, -- 2
+-- [0x00041] = 0x33, -- 3
+-- [0x00041] = 0x34, -- 4
+-- [0x00041] = 0x35, -- 5
+-- [0x00041] = 0x36, -- 6
+-- [0x00041] = 0x37, -- 7
+-- [0x00041] = 0x38, -- 8
+-- [0x00041] = 0x39, -- 9
+--~ [0x0002E] = 0x3A, -- .
+ [0x0002C] = 0x3B, -- ,
+ [0x0003C] = 0x3C, -- <
+-- [0x0002F] = 0x3D, -- /, slash, solidus
+ [0x02044] = 0x3D, -- / AM: Not sure
+ [0x0003E] = 0x3E, -- >
+ [0x022C6] = 0x3F, -- star
+ [0x02202] = 0x40, -- partial
+-- [0x00041] = 0x41, -- A
+ [0x1D6E2] = 0x41, -- Alpha
+-- [0x00042] = 0x42, -- B
+ [0x1D6E3] = 0x42, -- Beta
+-- [0x00043] = 0x43, -- C
+-- [0x00044] = 0x44, -- D
+-- [0x00045] = 0x45, -- E
+ [0x1D6E6] = 0x45, -- Epsilon
+-- [0x00046] = 0x46, -- F
+-- [0x00047] = 0x47, -- G
+-- [0x00048] = 0x48, -- H
+ [0x1D6E8] = 0x48, -- Eta
+-- [0x00049] = 0x49, -- I
+ [0x1D6EA] = 0x49, -- Iota
+-- [0x0004A] = 0x4A, -- J
+-- [0x0004B] = 0x4B, -- K
+ [0x1D6EB] = 0x4B, -- Kappa
+-- [0x0004C] = 0x4C, -- L
+-- [0x0004D] = 0x4D, -- M
+ [0x1D6ED] = 0x4D, -- Mu
+-- [0x0004E] = 0x4E, -- N
+ [0x1D6EE] = 0x4E, -- Nu
+-- [0x0004F] = 0x4F, -- O
+ [0x1D6F0] = 0x4F, -- Omicron
+-- [0x00050] = 0x50, -- P
+ [0x1D6F2] = 0x50, -- Rho
+-- [0x00051] = 0x51, -- Q
+-- [0x00052] = 0x52, -- R
+-- [0x00053] = 0x53, -- S
+-- [0x00054] = 0x54, -- T
+ [0x1D6F5] = 0x54, -- Tau
+-- [0x00055] = 0x55, -- U
+-- [0x00056] = 0x56, -- V
+-- [0x00057] = 0x57, -- W
+-- [0x00058] = 0x58, -- X
+ [0x1D6F8] = 0x58, -- Chi
+-- [0x00059] = 0x59, -- Y
+-- [0x0005A] = 0x5A, -- Z
+ [0x1D6E7] = 0x5A, -- Zeta
+ [0x0266D] = 0x5B, -- flat
+ [0x0266E] = 0x5C, -- natural
+ [0x0266F] = 0x5D, -- sharp
+ [0x02323] = 0x5E, -- smile
+ [0x02322] = 0x5F, -- frown
+ [0x02113] = 0x60, -- ell
+-- [0x00061] = 0x61, -- a
+-- [0x00062] = 0x62, -- b
+-- [0x00063] = 0x63, -- c
+-- [0x00064] = 0x64, -- d
+-- [0x00065] = 0x65, -- e
+-- [0x00066] = 0x66, -- f
+-- [0x00067] = 0x67, -- g
+-- [0x00068] = 0x68, -- h
+ [0x0210E] = 0x68, -- plant constant
+-- [0x00069] = 0x69, -- i
+-- [0x0006A] = 0x6A, -- j
+-- [0x0006B] = 0x6B, -- k
+-- [0x0006C] = 0x6C, -- l
+-- [0x0006D] = 0x6D, -- m
+-- [0x0006E] = 0x6E, -- n
+-- [0x0006F] = 0x6F, -- o
+ [0x1D70A] = 0x6F, -- omicron
+-- [0x00070] = 0x70, -- p
+-- [0x00071] = 0x71, -- q
+-- [0x00072] = 0x72, -- r
+-- [0x00073] = 0x73, -- s
+-- [0x00074] = 0x74, -- t
+-- [0x00075] = 0x75, -- u
+-- [0x00076] = 0x76, -- v
+-- [0x00077] = 0x77, -- w
+-- [0x00078] = 0x78, -- x
+-- [0x00079] = 0x79, -- y
+-- [0x0007A] = 0x7A, -- z
+ [0x1D6A4] = 0x7B, -- imath (TODO: also 0131)
+ [0x1D6A5] = 0x7C, -- jmath (TODO: also 0237)
+ [0x02118] = 0x7D, -- wp
+ [0x020D7] = 0x7E, -- vec (TODO: not sure)
+-- 0x7F, -- (no idea what that could be)
+}
+
+fonts.enc.math["tex-ss"] = { }
+fonts.enc.math["tex-tt"] = { }
+fonts.enc.math["tex-bf"] = { }
+fonts.enc.math["tex-bi"] = { }
+fonts.enc.math["tex-fraktur"] = { }
+fonts.enc.math["tex-fraktur-bold"] = { }
+
+function fonts.vf.math.set_letters(font_encoding, name, uppercase, lowercase)
+ local enc = font_encoding[name]
+ for i = 0,25 do
+ enc[uppercase+i] = i + 0x41
+ enc[lowercase+i] = i + 0x61
+ end
+end
+
+function fonts.vf.math.set_digits(font_encoding, name, digits)
+ local enc = font_encoding[name]
+ for i = 0,9 do
+ enc[digits+i] = i + 0x30
+ end
+end
+
+fonts.enc.math["tex-sy"] = {
+ [0x0002D] = 0x00, -- -
+ [0x02212] = 0x00, -- -
+-- [0x02201] = 0x00, -- complement
+-- [0x02206] = 0x00, -- increment
+-- [0x02204] = 0x00, -- not exists
+--~ [0x000B7] = 0x01, -- cdot
+ [0x022C5] = 0x01, -- cdot
+ [0x000D7] = 0x02, -- times
+ [0x0002A] = 0x03, -- *
+ [0x02217] = 0x03, -- *
+ [0x000F7] = 0x04, -- div
+ [0x022C4] = 0x05, -- diamond
+ [0x000B1] = 0x06, -- pm
+ [0x02213] = 0x07, -- mp
+ [0x02295] = 0x08, -- oplus
+ [0x02296] = 0x09, -- ominus
+ [0x02297] = 0x0A, -- otimes
+ [0x02298] = 0x0B, -- oslash
+ [0x02299] = 0x0C, -- odot
+ [0x025EF] = 0x0D, -- bigcirc, Orb (either 25EF or 25CB) -- todo
+ [0x02218] = 0x0E, -- circ
+ [0x02219] = 0x0F, -- bullet
+ [0x02022] = 0x0F, -- bullet
+ [0x0224D] = 0x10, -- asymp
+ [0x02261] = 0x11, -- equiv
+ [0x02286] = 0x12, -- subseteq
+ [0x02287] = 0x13, -- supseteq
+ [0x02264] = 0x14, -- leq
+ [0x02265] = 0x15, -- geq
+ [0x02AAF] = 0x16, -- preceq
+-- [0x0227C] = 0x16, -- preceq, AM:No see 2AAF
+ [0x02AB0] = 0x17, -- succeq
+-- [0x0227D] = 0x17, -- succeq, AM:No see 2AB0
+ [0x0223C] = 0x18, -- sim
+ [0x02248] = 0x19, -- approx
+ [0x02282] = 0x1A, -- subset
+ [0x02283] = 0x1B, -- supset
+ [0x0226A] = 0x1C, -- ll
+ [0x0226B] = 0x1D, -- gg
+ [0x0227A] = 0x1E, -- prec
+ [0x0227B] = 0x1F, -- succ
+ [0x02190] = 0x20, -- leftarrow
+ [0x02192] = 0x21, -- rightarrow
+--~ [0xFE190] = 0x20, -- leftarrow
+--~ [0xFE192] = 0x21, -- rightarrow
+ [0x02191] = 0x22, -- uparrow
+ [0x02193] = 0x23, -- downarrow
+ [0x02194] = 0x24, -- leftrightarrow
+ [0x02197] = 0x25, -- nearrow
+ [0x02198] = 0x26, -- searrow
+ [0x02243] = 0x27, -- simeq
+ [0x021D0] = 0x28, -- Leftarrow
+ [0x021D2] = 0x29, -- Rightarrow
+ [0x021D1] = 0x2A, -- Uparrow
+ [0x021D3] = 0x2B, -- Downarrow
+ [0x021D4] = 0x2C, -- Leftrightarrow
+ [0x02196] = 0x2D, -- nwarrow
+ [0x02199] = 0x2E, -- swarrow
+ [0x0221D] = 0x2F, -- propto
+ [0x02032] = 0x30, -- prime
+ [0x0221E] = 0x31, -- infty
+ [0x02208] = 0x32, -- in
+ [0x0220B] = 0x33, -- ni
+ [0x025B3] = 0x34, -- triangle, bigtriangleup
+ [0x025BD] = 0x35, -- bigtriangledown
+ [0x00338] = 0x36, -- not
+-- 0x37, -- (beginning of arrow)
+ [0x02200] = 0x38, -- forall
+ [0x02203] = 0x39, -- exists
+ [0x000AC] = 0x3A, -- neg, lnot
+ [0x02205] = 0x3B, -- empty set
+ [0x0211C] = 0x3C, -- Re
+ [0x02111] = 0x3D, -- Im
+ [0x022A4] = 0x3E, -- top
+ [0x022A5] = 0x3F, -- bot, perp
+ [0x02135] = 0x40, -- aleph
+ [0x1D49C] = 0x41, -- script A
+ [0x0212C] = 0x42, -- script B
+ [0x1D49E] = 0x43, -- script C
+ [0x1D49F] = 0x44, -- script D
+ [0x02130] = 0x45, -- script E
+ [0x02131] = 0x46, -- script F
+ [0x1D4A2] = 0x47, -- script G
+ [0x0210B] = 0x48, -- script H
+ [0x02110] = 0x49, -- script I
+ [0x1D4A5] = 0x4A, -- script J
+ [0x1D4A6] = 0x4B, -- script K
+ [0x02112] = 0x4C, -- script L
+ [0x02133] = 0x4D, -- script M
+ [0x1D4A9] = 0x4E, -- script N
+ [0x1D4AA] = 0x4F, -- script O
+ [0x1D4AB] = 0x50, -- script P
+ [0x1D4AC] = 0x51, -- script Q
+ [0x0211B] = 0x52, -- script R
+ [0x1D4AE] = 0x53, -- script S
+ [0x1D4AF] = 0x54, -- script T
+ [0x1D4B0] = 0x55, -- script U
+ [0x1D4B1] = 0x56, -- script V
+ [0x1D4B2] = 0x57, -- script W
+ [0x1D4B3] = 0x58, -- script X
+ [0x1D4B4] = 0x59, -- script Y
+ [0x1D4B5] = 0x5A, -- script Z
+ [0x0222A] = 0x5B, -- cup
+ [0x02229] = 0x5C, -- cap
+ [0x0228E] = 0x5D, -- uplus
+ [0x02227] = 0x5E, -- wedge, land
+ [0x02228] = 0x5F, -- vee, lor
+ [0x022A2] = 0x60, -- vdash
+ [0x022A3] = 0x61, -- dashv
+ [0x0230A] = 0x62, -- lfloor
+ [0x0230B] = 0x63, -- rfloor
+ [0x02308] = 0x64, -- lceil
+ [0x02309] = 0x65, -- rceil
+ [0x0007B] = 0x66, -- {, lbrace
+ [0x0007D] = 0x67, -- }, rbrace
+ [0x027E8] = 0x68, -- <, langle
+ [0x027E9] = 0x69, -- >, rangle
+ [0x0007C] = 0x6A, -- |, mid, lvert, rvert
+ [0x02225] = 0x6B, -- parallel, Vert, lVert, rVert, arrowvert
+ [0x02195] = 0x6C, -- updownarrow
+ [0x021D5] = 0x6D, -- Updownarrow
+ [0x0005C] = 0x6E, -- \, backslash, setminus
+ [0x02216] = 0x6E, -- setminus
+ [0x02240] = 0x6F, -- wr
+ [0x0221A] = 0x70, -- sqrt. AM: Check surd??
+ [0x02A3F] = 0x71, -- amalg
+ [0x1D6FB] = 0x72, -- nabla
+-- [0x0222B] = 0x73, -- smallint (TODO: what about intop?)
+ [0x02294] = 0x74, -- sqcup
+ [0x02293] = 0x75, -- sqcap
+ [0x02291] = 0x76, -- sqsubseteq
+ [0x02292] = 0x77, -- sqsupseteq
+ [0x000A7] = 0x78, -- S
+ [0x02020] = 0x79, -- dagger, dag
+ [0x02021] = 0x7A, -- ddagger, ddag
+ [0x000B6] = 0x7B, -- P
+ [0x02663] = 0x7C, -- clubsuit
+ [0x02662] = 0x7D, -- diamondsuit
+ [0x02661] = 0x7E, -- heartsuit
+ [0x02660] = 0x7F, -- spadesuit
+ [0xFE321] = 0x37, -- mapstochar
+}
+
+-- The names in masm10.enc can be trusted best and are shown in the first
+-- column, while in the second column we show the tex/ams names. As usual
+-- it costs hours to figure out such a table.
+
+fonts.enc.math["tex-ma"] = {
+ [0x022A1] = 0x00, -- squaredot \boxdot
+ [0x0229E] = 0x01, -- squareplus \boxplus
+ [0x022A0] = 0x02, -- squaremultiply \boxtimes
+ [0x025A1] = 0x03, -- square \square \Box
+ [0x025A0] = 0x04, -- squaresolid \blacksquare
+ [0x000B7] = 0x05, -- squaresmallsolid \centerdot
+ [0x022C4] = 0x06, -- diamond \Diamond \lozenge
+ [0x029EB] = 0x07, -- diamondsolid \blacklozenge
+ [0x021BA] = 0x08, -- clockwise \circlearrowright
+ [0x021BB] = 0x09, -- anticlockwise \circlearrowleft
+ [0x021CC] = 0x0A, -- harpoonleftright \rightleftharpoons
+ [0x021CB] = 0x0B, -- harpoonrightleft \leftrightharpoons
+ [0x0229F] = 0x0C, -- squareminus \boxminus
+ [0x022A9] = 0x0D, -- forces \Vdash
+ [0x022AA] = 0x0E, -- forcesbar \Vvdash
+ [0x022A8] = 0x0F, -- satisfies \vDash
+ [0x021A0] = 0x10, -- dblarrowheadright \twoheadrightarrow
+ [0x0219E] = 0x11, -- dblarrowheadleft \twoheadleftarrow
+ [0x021C7] = 0x12, -- dblarrowleft \leftleftarrows
+ [0x021C9] = 0x13, -- dblarrowright \rightrightarrows
+ [0x021C8] = 0x14, -- dblarrowup \upuparrows
+ [0x021CA] = 0x15, -- dblarrowdwn \downdownarrows
+ [0x021BE] = 0x16, -- harpoonupright \upharpoonright \restriction
+ [0x021C2] = 0x17, -- harpoondownright \downharpoonright
+ [0x021BF] = 0x18, -- harpoonupleft \upharpoonleft
+ [0x021C3] = 0x19, -- harpoondownleft \downharpoonleft
+ [0x021A3] = 0x1A, -- arrowtailright \rightarrowtail
+ [0x021A2] = 0x1B, -- arrowtailleft \leftarrowtail
+ [0x021C6] = 0x1C, -- arrowparrleftright \leftrightarrows
+-- [0x021C5] = 0x00, -- \updownarrows (missing in lm)
+ [0x021C4] = 0x1D, -- arrowparrrightleft \rightleftarrows
+ [0x021B0] = 0x1E, -- shiftleft \Lsh
+ [0x021B1] = 0x1F, -- shiftright \Rsh
+ [0x021DD] = 0x20, -- squiggleright \leadsto \rightsquigarrow
+ [0x021AD] = 0x21, -- squiggleleftright \leftrightsquigarrow
+ [0x021AB] = 0x22, -- curlyleft \looparrowleft
+ [0x021AC] = 0x23, -- curlyright \looparrowright
+ [0x02257] = 0x24, -- circleequal \circeq
+ [0x0227F] = 0x25, -- followsorequal \succsim
+ [0x02273] = 0x26, -- greaterorsimilar \gtrsim
+ [0x02A86] = 0x27, -- greaterorapproxeql \gtrapprox
+ [0x022B8] = 0x28, -- multimap \multimap
+ [0x02234] = 0x29, -- therefore \therefore
+ [0x02235] = 0x2A, -- because \because
+ [0x02251] = 0x2B, -- equalsdots \Doteq \doteqdot
+ [0x0225C] = 0x2C, -- defines \triangleq
+ [0x0227E] = 0x2D, -- precedesorequal \precsim
+ [0x02272] = 0x2E, -- lessorsimilar \lesssim
+ [0x02A85] = 0x2F, -- lessorapproxeql \lessapprox
+ [0x02A95] = 0x30, -- equalorless \eqslantless
+ [0x02A96] = 0x31, -- equalorgreater \eqslantgtr
+ [0x022DE] = 0x32, -- equalorprecedes \curlyeqprec
+ [0x022DF] = 0x33, -- equalorfollows \curlyeqsucc
+ [0x0227C] = 0x34, -- precedesorcurly \preccurlyeq
+ [0x02266] = 0x35, -- lessdblequal \leqq
+ [0x02A7D] = 0x36, -- lessorequalslant \leqslant
+ [0x02276] = 0x37, -- lessorgreater \lessgtr
+ [0x02035] = 0x38, -- primereverse \backprime
+ -- [0x0] = 0x39, -- axisshort \dabar
+ [0x02253] = 0x3A, -- equaldotrightleft \risingdotseq
+ [0x02252] = 0x3B, -- equaldotleftright \fallingdotseq
+ [0x0227D] = 0x3C, -- followsorcurly \succcurlyeq
+ [0x02267] = 0x3D, -- greaterdblequal \geqq
+ [0x02A7E] = 0x3E, -- greaterorequalslant \geqslant
+ [0x02277] = 0x3F, -- greaterorless \gtrless
+ [0x0228F] = 0x40, -- squareimage \sqsubset
+ [0x02290] = 0x41, -- squareoriginal \sqsupset
+ -- wrong:
+ [0x022B3] = 0x42, -- triangleright \rhd \vartriangleright
+ [0x022B2] = 0x43, -- triangleleft \lhd \vartriangleleft
+ [0x022B5] = 0x44, -- trianglerightequal \unrhd \trianglerighteq
+ [0x022B4] = 0x45, -- triangleleftequal \unlhd \trianglelefteq
+ --
+ [0x02605] = 0x46, -- star \bigstar
+ [0x0226C] = 0x47, -- between \between
+ [0x025BC] = 0x48, -- triangledownsld \blacktriangledown
+ [0x025B6] = 0x49, -- trianglerightsld \blacktriangleright
+ [0x025C0] = 0x4A, -- triangleleftsld \blacktriangleleft
+ -- [0x0] = 0x4B, -- arrowaxisright
+ -- [0x0] = 0x4C, -- arrowaxisleft
+ [0x025B2] = 0x4D, -- triangle \triangleup \vartriangle
+ [0x025B2] = 0x4E, -- trianglesolid \blacktriangle
+ [0x025BC] = 0x4F, -- triangleinv \triangledown
+ [0x02256] = 0x50, -- ringinequal \eqcirc
+ [0x022DA] = 0x51, -- lessequalgreater \lesseqgtr
+ [0x022DB] = 0x52, -- greaterlessequal \gtreqless
+ [0x02A8B] = 0x53, -- lessdbleqlgreater \lesseqqgtr
+ [0x02A8C] = 0x54, -- greaterdbleqlless \gtreqqless
+ [0x000A5] = 0x55, -- Yen \yen
+ [0x021DB] = 0x56, -- arrowtripleright \Rrightarrow
+ [0x021DA] = 0x57, -- arrowtripleleft \Lleftarrow
+ [0x02713] = 0x58, -- check \checkmark
+ [0x022BB] = 0x59, -- orunderscore \veebar
+ [0x022BC] = 0x5A, -- nand \barwedge
+ [0x02306] = 0x5B, -- perpcorrespond \doublebarwedge
+ [0x02220] = 0x5C, -- angle \angle
+ [0x02221] = 0x5D, -- measuredangle \measuredangle
+ [0x02222] = 0x5E, -- sphericalangle \sphericalangle
+ -- [0x0] = 0x5F, -- proportional \varpropto
+ -- [0x0] = 0x60, -- smile \smallsmile
+ -- [0x0] = 0x61, -- frown \smallfrown
+ [0x022D0] = 0x62, -- subsetdbl \Subset
+ [0x022D1] = 0x63, -- supersetdbl \Supset
+ [0x022D3] = 0x64, -- uniondbl \doublecup \Cup
+ [0x00100] = 0x65, -- intersectiondbl \doublecap \Cap
+ [0x022CF] = 0x66, -- uprise \curlywedge
+ [0x022CE] = 0x67, -- downfall \curlyvee
+ [0x022CB] = 0x68, -- multiopenleft \leftthreetimes
+ [0x022CC] = 0x69, -- multiopenright \rightthreetimes
+ [0x02AC5] = 0x6A, -- subsetdblequal \subseteqq
+ [0x02AC6] = 0x6B, -- supersetdblequal \supseteqq
+ [0x0224F] = 0x6C, -- difference \bumpeq
+ [0x0224E] = 0x6D, -- geomequivalent \Bumpeq
+ [0x022D8] = 0x6E, -- muchless \lll \llless
+ [0x022D9] = 0x6F, -- muchgreater \ggg \gggtr
+ [0x0231C] = 0x70, -- rightanglenw \ulcorner
+ [0x0231D] = 0x71, -- rightanglene \urcorner
+ [0x024C7] = 0x72, -- circleR \circledR
+ [0x024C8] = 0x73, -- circleS \circledS
+ [0x022D4] = 0x74, -- fork \pitchfork
+ [0x02245] = 0x75, -- dotplus \dotplus
+ [0x0223D] = 0x76, -- revsimilar \backsim
+ [0x022CD] = 0x77, -- revasymptequal \backsimeq -- AM: Check this! I mapped it to simeq.
+ [0x0231E] = 0x78, -- rightanglesw \llcorner
+ [0x0231F] = 0x79, -- rightanglese \lrcorner
+ [0x02720] = 0x7A, -- maltesecross \maltese
+ [0x02201] = 0x7B, -- complement \complement
+ [0x022BA] = 0x7C, -- intercal \intercal
+ [0x0229A] = 0x7D, -- circlering \circledcirc
+ [0x0229B] = 0x7E, -- circleasterisk \circledast
+ [0x0229D] = 0x7F, -- circleminus \circleddash
+}
+
+fonts.enc.math["tex-mb"] = {
+ -- [0x0] = 0x00, -- lessornotequal \lvertneqq
+ -- [0x0] = 0x01, -- greaterornotequal \gvertneqq
+ [0x02270] = 0x02, -- notlessequal \nleq
+ [0x02271] = 0x03, -- notgreaterequal \ngeq
+ [0x0226E] = 0x04, -- notless \nless
+ [0x0226F] = 0x05, -- notgreater \ngtr
+ [0x02280] = 0x06, -- notprecedes \nprec
+ [0x02281] = 0x07, -- notfollows \nsucc
+ [0x02268] = 0x08, -- lessornotdbleql \lneqq
+ [0x02269] = 0x09, -- greaterornotdbleql \gneqq
+ -- [0x0] = 0x0A, -- notlessorslnteql \nleqslant
+ -- [0x0] = 0x0B, -- notgreaterorslnteql \ngeqslant
+ [0x02A87] = 0x0C, -- lessnotequal \lneq
+ [0x02A88] = 0x0D, -- greaternotequal \gneq
+ -- [0x0] = 0x0E, -- notprecedesoreql \npreceq
+ -- [0x0] = 0x0F, -- notfollowsoreql \nsucceq
+ [0x022E8] = 0x10, -- precedeornoteqvlnt \precnsim
+ [0x022E9] = 0x11, -- followornoteqvlnt \succnsim
+ [0x022E6] = 0x12, -- lessornotsimilar \lnsim
+ [0x022E7] = 0x13, -- greaterornotsimilar \gnsim
+ -- [0x0] = 0x14, -- notlessdblequal \nleqq
+ -- [0x0] = 0x15, -- notgreaterdblequal \ngeqq
+ [0x02AB5] = 0x16, -- precedenotslnteql \precneqq
+ [0x02AB6] = 0x17, -- follownotslnteql \succneqq
+ [0x02AB9] = 0x18, -- precedenotdbleqv \precnapprox
+ [0x02ABA] = 0x19, -- follownotdbleqv \succnapprox
+ [0x02A89] = 0x1A, -- lessnotdblequal \lnapprox
+ [0x02A8A] = 0x1B, -- greaternotdblequal \gnapprox
+ [0x02241] = 0x1C, -- notsimilar \nsim
+ [0x02247] = 0x1D, -- notapproxequal \ncong
+ -- [0x0] = 0x1E, -- upslope \diagup
+ -- [0x0] = 0x1F, -- downslope \diagdown
+ -- [0x0] = 0x20, -- notsubsetoreql \varsubsetneq
+ -- [0x0] = 0x21, -- notsupersetoreql \varsupsetneq
+ -- [0x0] = 0x22, -- notsubsetordbleql \nsubseteqq
+ -- [0x0] = 0x23, -- notsupersetordbleql \nsupseteqq
+ [0x02ACB] = 0x24, -- subsetornotdbleql \subsetneqq
+ [0x02ACC] = 0x25, -- supersetornotdbleql \supsetneqq
+ -- [0x0] = 0x26, -- subsetornoteql \varsubsetneqq
+ -- [0x0] = 0x27, -- supersetornoteql \varsupsetneqq
+ [0x0228A] = 0x28, -- subsetnoteql \subsetneq
+ [0x0228B] = 0x29, -- supersetnoteql \supsetneq
+ [0x02288] = 0x2A, -- notsubseteql \nsubseteq
+ [0x02289] = 0x2B, -- notsuperseteql \nsupseteq
+ [0x02226] = 0x2C, -- notparallel \nparallel
+ [0x02224] = 0x2D, -- notbar \nmid \ndivides
+ -- [0x0] = 0x2E, -- notshortbar \nshortmid
+ -- [0x0] = 0x2F, -- notshortparallel \nshortparallel
+ [0x022AC] = 0x30, -- notturnstile \nvdash
+ [0x022AE] = 0x31, -- notforces \nVdash
+ [0x022AD] = 0x32, -- notsatisfies \nvDash
+ [0x022AF] = 0x33, -- notforcesextra \nVDash
+ [0x022ED] = 0x34, -- nottriangeqlright \ntrianglerighteq
+ [0x022EC] = 0x35, -- nottriangeqlleft \ntrianglelefteq
+ [0x022EA] = 0x36, -- nottriangleleft \ntriangleleft
+ [0x022EB] = 0x37, -- nottriangleright \ntriangleright
+ [0x0219A] = 0x38, -- notarrowleft \nleftarrow
+ [0x0219B] = 0x39, -- notarrowright \nrightarrow
+ [0x021CD] = 0x3A, -- notdblarrowleft \nLeftarrow
+ [0x021CF] = 0x3B, -- notdblarrowright \nRightarrow
+ [0x021CE] = 0x3C, -- notdblarrowboth \nLeftrightarrow
+ [0x021AE] = 0x3D, -- notarrowboth \nleftrightarrow
+ [0x022C7] = 0x3E, -- dividemultiply \divideontimes
+ [0x02300] = 0x3F, -- diametersign \varnothing
+ [0x02204] = 0x40, -- notexistential \nexists
+ [0x1D538] = 0x41, -- A (blackboard A)
+ [0x1D539] = 0x42, -- B
+ [0x02102] = 0x43, -- C
+ [0x1D53B] = 0x44, -- D
+ [0x1D53C] = 0x45, -- E
+ [0x1D53D] = 0x46, -- F
+ [0x1D53E] = 0x47, -- G
+ [0x0210D] = 0x48, -- H
+ [0x1D540] = 0x49, -- I
+ [0x1D541] = 0x4A, -- J
+ [0x1D542] = 0x4B, -- K
+ [0x1D543] = 0x4C, -- L
+ [0x1D544] = 0x4D, -- M
+ [0x02115] = 0x4E, -- N
+ [0x1D546] = 0x4F, -- O
+ [0x02119] = 0x50, -- P
+ [0x0211A] = 0x51, -- Q
+ [0x0211D] = 0x52, -- R
+ [0x1D54A] = 0x53, -- S
+ [0x1D54B] = 0x54, -- T
+ [0x1D54C] = 0x55, -- U
+ [0x1D54D] = 0x56, -- V
+ [0x1D54E] = 0x57, -- W
+ [0x1D54F] = 0x58, -- X
+ [0x1D550] = 0x59, -- Y
+ [0x02124] = 0x5A, -- Z (blackboard Z)
+ [0x02132] = 0x60, -- hatwide \Finv
+ [0x02141] = 0x61, -- hatwider \Game
+ -- [0x0] = 0x62, tildewide
+ -- [0x0] = 0x63, tildewider
+ -- [0x0] = 0x64, Finv
+ -- [0x0] = 0x65, Gmir
+ [0x02127] = 0x66, -- Omegainv \mho
+ [0x000F0] = 0x67, -- eth \eth
+ [0x02242] = 0x68, -- equalorsimilar \eqsim
+ [0x02136] = 0x69, -- beth \beth
+ [0x02137] = 0x6A, -- gimel \gimel
+ [0x02138] = 0x6B, -- daleth \daleth
+ [0x022D6] = 0x6C, -- lessdot \lessdot
+ [0x022D7] = 0x6D, -- greaterdot \gtrdot
+ [0x022C9] = 0x6E, -- multicloseleft \ltimes
+ [0x022CA] = 0x6F, -- multicloseright \rtimes
+ -- [0x0] = 0x70, -- barshort \shortmid
+ -- [0x0] = 0x71, -- parallelshort \shortparallel
+ -- [0x02216] = 0x72, -- integerdivide \smallsetminus (2216 already part of tex-sy
+ -- [0x0] = 0x73, -- similar \thicksim
+ -- [0x0] = 0x74, -- approxequal \thickapprox
+ [0x0224A] = 0x75, -- approxorequal \approxeq
+ [0x02AB8] = 0x76, -- followsorequal \succapprox
+ [0x02AB7] = 0x77, -- precedesorequal \precapprox
+ [0x021B6] = 0x78, -- archleftdown \curvearrowleft
+ [0x021B7] = 0x79, -- archrightdown \curvearrowright
+ [0x003DC] = 0x7A, -- Digamma \digamma
+ [0x003F0] = 0x7B, -- kappa \varkappa
+ [0x1D55C] = 0x7C, -- k \Bbbk (blackboard k)
+ [0x0210F] = 0x7D, -- planckover2pi \hslash
+ [0x00127] = 0x7E, -- planckover2pi1 \hbar
+ [0x003F6] = 0x7F, -- epsiloninv \backepsilon
+}
+
+fonts.enc.math["tex-fraktur"] = {
+-- [0x1D504] = 0x41, -- A (fraktur A)
+-- [0x1D505] = 0x42, -- B
+ [0x0212D] = 0x43, -- C
+-- [0x1D507] = 0x44, -- D
+-- [0x1D508] = 0x45, -- E
+-- [0x1D509] = 0x46, -- F
+-- [0x1D50A] = 0x47, -- G
+ [0x0210C] = 0x48, -- H
+ [0x02111] = 0x49, -- I
+-- [0x1D50D] = 0x4A, -- J
+-- [0x1D50E] = 0x4B, -- K
+-- [0x1D50F] = 0x4C, -- L
+-- [0x1D510] = 0x4D, -- M
+-- [0x1D511] = 0x4E, -- N
+-- [0x1D512] = 0x4F, -- O
+-- [0x1D513] = 0x50, -- P
+-- [0x1D514] = 0x51, -- Q
+ [0x0211C] = 0x52, -- R
+-- [0x1D516] = 0x53, -- S
+-- [0x1D517] = 0x54, -- T
+-- [0x1D518] = 0x55, -- U
+-- [0x1D519] = 0x56, -- V
+-- [0x1D51A] = 0x57, -- W
+-- [0x1D51B] = 0x58, -- X
+-- [0x1D51C] = 0x59, -- Y
+ [0x02128] = 0x5A, -- Z (fraktur Z)
+-- [0x1D51E] = 0x61, -- a (fraktur a)
+-- [0x1D51F] = 0x62, -- b
+-- [0x1D520] = 0x63, -- c
+-- [0x1D521] = 0x64, -- d
+-- [0x1D522] = 0x65, -- e
+-- [0x1D523] = 0x66, -- f
+-- [0x1D524] = 0x67, -- g
+-- [0x1D525] = 0x68, -- h
+-- [0x1D526] = 0x69, -- i
+-- [0x1D527] = 0x6A, -- j
+-- [0x1D528] = 0x6B, -- k
+-- [0x1D529] = 0x6C, -- l
+-- [0x1D52A] = 0x6D, -- m
+-- [0x1D52B] = 0x6E, -- n
+-- [0x1D52C] = 0x6F, -- o
+-- [0x1D52D] = 0x70, -- p
+-- [0x1D52E] = 0x71, -- q
+-- [0x1D52F] = 0x72, -- r
+-- [0x1D530] = 0x73, -- s
+-- [0x1D531] = 0x74, -- t
+-- [0x1D532] = 0x75, -- u
+-- [0x1D533] = 0x76, -- v
+-- [0x1D534] = 0x77, -- w
+-- [0x1D535] = 0x78, -- x
+-- [0x1D536] = 0x79, -- y
+-- [0x1D537] = 0x7A, -- z
+}
+
+-- now that all other vectors are defined ...
+
+fonts.vf.math.set_letters(fonts.enc.math, "tex-mi", 0x1D434, 0x1D44E)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-ss", 0x1D5A0, 0x1D5BA)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-tt", 0x1D670, 0x1D68A)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-bf", 0x1D400, 0x1D41A)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-bi", 0x1D468, 0x1D482)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-fraktur", 0x1D504, 0x1D51E)
+fonts.vf.math.set_letters(fonts.enc.math, "tex-fraktur-bold", 0x1D56C, 0x1D586)
+
+fonts.vf.math.set_digits (fonts.enc.math, "tex-ss", 0x1D7E2)
+fonts.vf.math.set_digits (fonts.enc.math, "tex-tt", 0x1D7F6)
+fonts.vf.math.set_digits (fonts.enc.math, "tex-bf", 0x1D7CE)
+
+-- fonts.vf.math.set_digits (fonts.enc.math, "tex-bi", 0x1D7CE)
+
+-- todo: add ss, tt, bf etc vectors
+-- we can make ss tt etc an option
+
+-- rm-lmr5 : LMMathRoman5-Regular
+-- rm-lmbx5 : LMMathRoman5-Bold ]
+-- lmbsy5 : LMMathSymbols5-BoldItalic
+-- lmsy5 : LMMathSymbols5-Italic
+-- lmmi5 : LMMathItalic5-Italic
+-- lmmib5 : LMMathItalic5-BoldItalic
+
+mathematics.make_font ( "lmroman5-math", {
+ { name = "lmroman5-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr5.tfm", vector = "tex-mr" } ,
+ { name = "lmmi5.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy5.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam5.tfm", vector = "tex-ma" },
+ { name = "msbm5.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx5.tfm", vector = "tex-bf" } ,
+ { name = "lmroman5-bold", "tex-bf" } ,
+ { name = "lmmib5.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm5.tfm", vector = "tex-fraktur", optional=true },
+} )
+
+-- rm-lmr6 : LMMathRoman6-Regular
+-- rm-lmbx6 : LMMathRoman6-Bold
+-- lmsy6 : LMMathSymbols6-Italic
+-- lmmi6 : LMMathItalic6-Italic
+
+mathematics.make_font ( "lmroman6-math", {
+ { name = "lmroman6-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr6.tfm", vector = "tex-mr" } ,
+ { name = "lmmi6.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy6.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam5.tfm", vector = "tex-ma" },
+ { name = "msbm5.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx6.tfm", vector = "tex-bf" } ,
+ { name = "lmroman6-bold.otf", "tex-bf" } ,
+ { name = "lmmib5.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm6.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb6.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr7 : LMMathRoman7-Regular
+-- rm-lmbx7 : LMMathRoman7-Bold
+-- lmbsy7 : LMMathSymbols7-BoldItalic
+-- lmsy7 : LMMathSymbols7-Italic
+-- lmmi7 : LMMathItalic7-Italic
+-- lmmib7 : LMMathItalic7-BoldItalic
+
+mathematics.make_font ( "lmroman7-math", {
+ { name = "lmroman7-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr7.tfm", vector = "tex-mr" } ,
+ { name = "lmmi7.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy7.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam7.tfm", vector = "tex-ma" },
+ { name = "msbm7.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx7.tfm", vector = "tex-bf" } ,
+ { name = "lmroman7-bold.otf", "tex-bf" } ,
+ { name = "lmmib7.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm7.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb7.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr8 : LMMathRoman8-Regular
+-- rm-lmbx8 : LMMathRoman8-Bold
+-- lmsy8 : LMMathSymbols8-Italic
+-- lmmi8 : LMMathItalic8-Italic
+
+mathematics.make_font ( "lmroman8-math", {
+ { name = "lmroman8-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr8.tfm", vector = "tex-mr" } ,
+ { name = "lmmi8.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy8.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam7.tfm", vector = "tex-ma" },
+ { name = "msbm7.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx8.tfm", vector = "tex-bf" } ,
+ { name = "lmroman8-bold.otf", "tex-bf" } ,
+ { name = "lmmib7.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm8.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb8.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr9 : LMMathRoman9-Regular
+-- rm-lmbx9 : LMMathRoman9-Bold
+-- lmsy9 : LMMathSymbols9-Italic
+-- lmmi9 : LMMathItalic9-Italic
+
+mathematics.make_font ( "lmroman9-math", {
+ { name = "lmroman9-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr9.tfm", vector = "tex-mr" } ,
+ { name = "lmmi9.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy9.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx9.tfm", vector = "tex-bf" } ,
+ { name = "lmroman9-bold.otf", "tex-bf" } ,
+ { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans9-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono9-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm9.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb9.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr10 : LMMathRoman10-Regular
+-- rm-lmbx10 : LMMathRoman10-Bold
+-- lmbsy10 : LMMathSymbols10-BoldItalic
+-- lmsy10 : LMMathSymbols10-Italic
+-- lmex10 : LMMathExtension10-Regular
+-- lmmi10 : LMMathItalic10-Italic
+-- lmmib10 : LMMathItalic10-BoldItalic
+
+mathematics.make_font ( "lmroman10-math", {
+ { name = "lmroman10-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr10.tfm", vector = "tex-mr" } ,
+ { name = "lmmi10.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx10.tfm", vector = "tex-bf" } ,
+ { name = "lmroman10-bold.otf", "tex-bf" } ,
+ { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans10-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono10-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr12 : LMMathRoman12-Regular
+-- rm-lmbx12 : LMMathRoman12-Bold
+-- lmmi12 : LMMathItalic12-Italic
+
+mathematics.make_font ( "lmroman12-math", {
+ { name = "lmroman12-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr12.tfm", vector = "tex-mr" } ,
+ { name = "lmmi12.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx12.tfm", vector = "tex-bf" } ,
+ { name = "lmroman12-bold.otf", "tex-bf" } ,
+ { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans12-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono12-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- rm-lmr17 : LMMathRoman17-Regular
+
+mathematics.make_font ( "lmroman17-math", {
+ { name = "lmroman17-regular.otf", features = "virtualmath", main = true },
+ -- { name = "rm-lmr12.tfm", vector = "tex-mr" } ,
+ { name = "lmmi12.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+ -- { name = "rm-lmbx12.tfm", vector = "tex-bf" } ,
+ { name = "lmroman12-bold.otf", "tex-bf" } ,
+ { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
+ { name = "lmsans17-regular.otf", vector = "tex-ss", optional=true },
+ { name = "lmmono17-regular.otf", vector = "tex-tt", optional=true },
+ { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
+ { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
+} )
+
+-- pxr/txr messes up the accents
+
+mathematics.make_font ( "px-math", {
+ { name = "texgyrepagella-regular.otf", features = "virtualmath", main = true },
+ { name = "pxr.tfm", vector = "tex-mr" } ,
+ { name = "pxmi.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "pxsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "pxex.tfm", vector = "tex-ex", extension = true } ,
+ { name = "pxsya.tfm", vector = "tex-ma" },
+ { name = "pxsyb.tfm", vector = "tex-mb" },
+} )
+
+mathematics.make_font ( "tx-math", {
+ { name = "texgyretermes-regular.otf", features = "virtualmath", main = true },
+ { name = "txr.tfm", vector = "tex-mr" } ,
+ { name = "txmi.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "txsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "txex.tfm", vector = "tex-ex", extension = true } ,
+ { name = "txsya.tfm", vector = "tex-ma" },
+ { name = "txsyb.tfm", vector = "tex-mb" },
+} )
+
+mathematics.make_font ( "iwona-math", {
+ { name = "file:Iwona-Regular", features = "virtualmath", main = true },
+ { name = "mi-iwonari.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "sy-iwonarz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "ex-iwonar.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+} )
+
+mathematics.make_font ( "iwona-light-math", {
+ { name = "file:IwonaLight-Regular", features = "virtualmath", main = true },
+ { name = "mi-iwonali.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "sy-iwonalz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "ex-iwonal.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+} )
+
+mathematics.make_font ( "iwona-medium-math", {
+ { name = "file:IwonaMedium-Regular", features = "virtualmath", main = true },
+ { name = "mi-iwonami.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "sy-iwonamz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "ex-iwonam.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+} )
+
+mathematics.make_font ( "iwona-heavy-math", {
+ { name = "file:IwonaHeavy-Regular", features = "virtualmath", main = true },
+ { name = "mi-iwonahi.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "sy-iwonahz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
+ { name = "ex-iwonah.tfm", vector = "tex-ex", extension = true } ,
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+} )
+
+-- not ok, we need adapted vectors !
+
+mathematics.make_font ( "mathtimes-math", {
+ { name = "file:texgyretermes-regular.otf", features = "virtualmath", main = true },
+ { name = "mtmiz.tfm", vector = "tex-mi", skewchar=0x7F },
+ { name = "mtsyn.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
+ { name = "mtex.tfm", vector = "tex-ex", extension = true },
+ { name = "msam10.tfm", vector = "tex-ma" },
+ { name = "msbm10.tfm", vector = "tex-mb" },
+} )
diff --git a/tex/context/base/meta-ini.mkii b/tex/context/base/meta-ini.mkii
index cb59ed44b..ee7e8a38b 100644
--- a/tex/context/base/meta-ini.mkii
+++ b/tex/context/base/meta-ini.mkii
@@ -20,45 +20,21 @@
\unprotect
-\startmessages dutch library: metapost
- title: metapost
- 1: metapost bibliotheek -- wordt geladen
-\stopmessages
-
-\startmessages english library: metapost
- title: metapost
- 1: loading metapost library --
-\stopmessages
-
-\startmessages german library: metapost
- title: metapost
- 1: Lade metapost Bibliothek --
-\stopmessages
-
-\startmessages czech library: metapost
- title: metapost
- 1: loading metapost library --
-\stopmessages
-
-\startmessages italian library: metapost
- title: metapost
- 1: caricamento della libreria metapost --
-\stopmessages
-
-\startmessages norwegian library: metapost
- title: metapost
- 1: metapost bibliotek -- blir lest inn
-\stopmessages
-
-\startmessages romanian library: metapost
- title: metapost
- 1: se incarca biblioteca metapost --
-\stopmessages
-
-\startmessages french library: metapost
- title: metapost
- 1: chargement de la bibliothèque metapost --
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
%D This module extends the functionality of the support module
%D \type {supp-mps}, the module that is responsible for
@@ -69,49 +45,48 @@
\maxnofMPgraphics = 4000 % metafun disables the 4K boundary
-\appendtoks \runMPgraphicsfalse \to \everyfastmode
-\appendtoks \insertMPgraphicsfalse \to \everyfastmode
-\appendtoks \flushMPgraphics \to \everygoodbye % \everylastshipout
+\appendtoks \flushMPgraphics \to \everygoodbye % \everylastshipout
\def\@@MPG{@MPG@}
\startMPextensions
- if unknown context_tool: input mp-tool; fi;
- if unknown context_spec: input mp-spec; fi;
- if unknown context_grph: input mp-grph; fi;
+ if unknown context_tool: input mp-tool; fi;
+ if unknown context_spec: input mp-spec; fi;
+ if unknown context_grph: input mp-grph; fi;
\stopMPextensions
%D Since we want lables to follow the document settings, we
%D also set the font related variables.
-\startMPinitializations % scale is not yet ok
- defaultfont:="\truefontname{Regular}";
- defaultscale:=\the\bodyfontsize/10pt;
-\stopMPinitializations
-
-\beginNEWTEX
+\ifnum\texengine=\xetexengine
\startMPinitializations % scale is not yet ok
- defaultfont:="rm-lmtt10";
+ defaultfont:="rm-lmtt10";
+ defaultscale:=\the\bodyfontsize/10pt;
\stopMPinitializations
-\endNEWTEX
+\else
+ \startMPinitializations % scale is not yet ok
+ defaultfont:="\truefontname{Regular}";
+ defaultscale:=\the\bodyfontsize/10pt;
+ \stopMPinitializations
+\fi
%D In order to support fancy text features (like outline
%D fonts), we set:
\startMPextensions
- graphictextformat:="context";
- graphictextdirective "\the\everyMPTEXgraphic";
+ graphictextformat:="context";
+ graphictextdirective "\the\everyMPTEXgraphic";
\stopMPextensions
% \startMPextensions
-% textextdirective "\the\everyMPTEXgraphic";
+% textextdirective "\the\everyMPTEXgraphic";
% \stopMPextensions
%D A signal that we're in combines \CONTEXT||\METAFUN mode:
\startMPextensions
- string contextversion;
- contextversion:="\contextversion";
+ string contextversion;
+ contextversion:="\contextversion";
\stopMPextensions
%D Some safeguards:
diff --git a/tex/context/base/meta-ini.mkiv b/tex/context/base/meta-ini.mkiv
index 8d2f7a724..bcd82c4ed 100644
--- a/tex/context/base/meta-ini.mkiv
+++ b/tex/context/base/meta-ini.mkiv
@@ -15,46 +15,6 @@
\unprotect
-\startmessages dutch library: metapost
- title: metapost
- 1: metapost bibliotheek -- wordt geladen
-\stopmessages
-
-\startmessages english library: metapost
- title: metapost
- 1: loading metapost library --
-\stopmessages
-
-\startmessages german library: metapost
- title: metapost
- 1: Lade metapost Bibliothek --
-\stopmessages
-
-\startmessages czech library: metapost
- title: metapost
- 1: loading metapost library --
-\stopmessages
-
-\startmessages italian library: metapost
- title: metapost
- 1: caricamento della libreria metapost --
-\stopmessages
-
-\startmessages norwegian library: metapost
- title: metapost
- 1: metapost bibliotek -- blir lest inn
-\stopmessages
-
-\startmessages romanian library: metapost
- title: metapost
- 1: se incarca biblioteca metapost --
-\stopmessages
-
-\startmessages french library: metapost
- title: metapost
- 1: chargement de la bibliothèque metapost --
-\stopmessages
-
%D Instead of sharing code with \MKII, I decided to copy
%D the code. Otherwise maintainance becomes a pain and after all,
%D the \MKII\ code will not change.
@@ -77,6 +37,20 @@
\newtoks \everyMPgraphic % mp
\newtoks \everyMPTEXgraphic % tex
+% The next command is, of course, dedicated to Mojca, who
+% needs it for gnuplot. Anyway, the whole multiple engine
+% mechanism is to keep her gnuplot from interfering.
+
+\def\startMPdefinitions
+ {\dosinglegroupempty\dostartMPdefinitions}
+
+\long\def\dostartMPdefinitions#1#2\stopMPdefinitions
+ {\edef\currentMPgraphicinstance{#1}%
+ \ifx\currentMPgraphicinstance\empty
+ \let\currentMPgraphicinstance\defaultMPgraphicinstance
+ \fi
+ \global\MPinstancetoks\expandafter{\the\MPinstancetoks#2}}
+
\long\def\startMPextensions#1\stopMPextensions
{\global\MPextensions\expandafter{\the\MPextensions#1}}
@@ -110,31 +84,163 @@
\def\currentMPformat{metafun}
+% todo:
+%
+% \splitMPgraphicname[a::b] (\currentMPgraphicformat,\currentMPgraphicname)
+% \splitMPgraphicname[a] (\currentMPgraphicformat,\currentMPgraphicname)
+% \splitMPgraphicname[a::b::c] (\currentMPgraphicformat,\currentMPgraphicname)
+%
+% \resetMPformat[extrafun]
+%
+% MPinclusions etc only for metafun, randomseed for all
+%
+% todo: \resetMPformat[instance] -> unload and nil
+% todo: geen page stats
+% todo: textext in plain mp
+
+% test:
+%
+% \let\processMPgraphic\extendedprocessMPgraphic \setupcolors[state=start]
+%
+% \startMPdefinitions{metafun}
+% color MyColor ; MyColor = red ;
+% \stopMPdefinitions
+% \startuseMPgraphic{test1}
+% fill fullcircle scaled 1cm withcolor MyColor ;
+% \stopuseMPgraphic
+% \startuseMPgraphic{test2}
+% color MyColor ; MyColor = green ;
+% fill fullcircle scaled 1cm withcolor MyColor ;
+% \stopuseMPgraphic
+% \startuseMPgraphic{test3}
+% fill fullcircle scaled 1cm withcolor MyColor ;
+% \stopuseMPgraphic
+% \startuseMPgraphic{test4}
+% color MyColor ; MyColor = blue ;
+% \stopuseMPgraphic
+%
+% \useMPgraphic{metafun::test1}
+% \useMPgraphic{metafun::test2}
+% \useMPgraphic{metafun::test3}
+% \useMPgraphic{extrafun::test4}
+% \useMPgraphic{extrafun::test3}
+% \useMPgraphic{metafun::test3}
+% \useMPgraphic{nofun::test4}
+% \useMPgraphic{nofun::test3}
+%
+% \startMPcode
+% fill fullsquare scaled 1cm ;
+% \stopMPcode
+% \startMPcode{metafun}
+% fill fullsquare scaled 1cm withcolor MyColor ;
+% \stopMPcode
+
+\def\@@MPF{@MPF@}
+
+\def\MPinstancetoks{\csname\@@MPF::\currentMPgraphicinstance\endcsname}
+
+\def\defineMPinstance
+ {\dodoubleargument\dodefineMPinstance}
+
+\def\dodefineMPinstance[#1][#2]%
+ {\ifcsname\@@MPF::#1\endcsname\else\expandafter\newtoks\csname\@@MPF::#1\endcsname\fi
+ \MPinstancetoks\emptytoks % in case we redefine
+ \getparameters[\@@MPF#1][\s!format=mpost,\s!extensions=\v!no,\s!initializations=\v!no,#2]}
+
+\def\resetMPinstance[#1]%
+ {\writestatus\m!metapost{reset will be implemented when needed}}
+
+\def\defaultMPgraphicinstance{metafun}
+
+\def\splitMPgraphicname[#1]%
+ {\dosplitMPgraphicname[#1::::]}
+
+\def\dosplitMPgraphicname[#1::#2::#3]% instance ::
+ {\edef\currentMPgraphicname{#2}%
+ \ifx\currentMPgraphicname\empty
+ \edef\currentMPgraphicname{#1}%
+ \let\currentMPgraphicinstance\defaultMPgraphicinstance
+ \else
+ \edef\currentMPgraphicinstance{#1}%
+ \fi
+ \edef\currentMPgraphicformat{\csname\@@MPF\currentMPgraphicinstance\s!format\endcsname}}
+
+\def\currentMPgraphicinstance{\defaultMPgraphicinstance}
+\def\currentMPgraphicformat {\currentMPgraphicinstance}
+
+\defineMPinstance[metafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
+\defineMPinstance[extrafun][\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
+\defineMPinstance[metapost][\s!format=mpost]
+\defineMPinstance[nofun] [\s!format=mpost]
+
+\def\beginMPgraphicgroup#1%
+ {\begingroup
+ \splitMPgraphicname[#1]}
+
+\def\endMPgraphicgroup
+ {\endgroup}
+
+%
+
\newconditional \METAFUNinitialized
+% maybe we need to force black, i.e. fake nodes
+
\long\def\processMPgraphic#1% todo: extensions and inclusions outside beginfig
- {\blabelgroup
+ {\begingroup
\enableincludeMPgraphics
\the\everyMPgraphic
\presetMPdefinitions
\setMPrandomseed % this has to change
% we need to preexpand the token lists
\setbox\MPgraphicbox\hbox\bgroup
- \ifconditional\METAFUNinitialized
- \ctxlua { metapost.graphic(
- "\currentMPformat", \@EA\!!bs\the\MPinitializations;#1;\!!es,
- ""
- ) }%
- \else
- \ctxlua { metapost.graphic(
- "\currentMPformat", \@EA\!!bs\the\MPinitializations;\theMPrandomseed;#1;\!!es, % code
- \@EA\@EA\@EA\!!bs\@EA\the\@EA\MPextensions\@EA;\the\MPuserinclusions;\!!es % optional preamble
- ) }%
- \global\settrue\METAFUNinitialized
- \fi
+ \ctxlua{metapost.graphic("\currentMPformat", "\currentMPformat",
+ \@EA\!!bs\the\MPinitializations;\theMPrandomseed;#1;\!!es, % code
+ \@EA\@EA\@EA\!!bs\@EA\the\@EA\MPextensions\@EA;\the\MPuserinclusions;\!!es % optional preamble
+ )}%
+ \global\settrue\METAFUNinitialized
+ \global\MPextensions\emptytoks
+ \global\MPuserinclusions\emptytoks
\egroup
\placeMPgraphic
- \elabelgroup}
+ \endgroup}
+
+% ! ! ! ! begin temporary ! ! ! !
+
+\let\normalprocessMPgraphic\processMPgraphic
+
+\long\def\processMPgraphic#1% todo: extensions and inclusions outside beginfig
+ {\begingroup % needed?
+ \enableincludeMPgraphics
+ \the\everyMPgraphic
+ \presetMPdefinitions
+ \setMPrandomseed % this has to change
+ % we need to preexpand the token lists
+ \doifelsevalue{\@@MPF\currentMPgraphicinstance\s!extensions}\v!yes
+ {\settrue\includeMPextensions\letgvalue{\@@MPF\currentMPgraphicinstance\s!extensions}\v!no}
+ {\setfalse\includeMPextensions}%
+ \doifelsevalue{\@@MPF\currentMPgraphicinstance\s!initializations}\v!yes
+ {\settrue\includeMPinitializations\letgvalue{\@@MPF\currentMPgraphicinstance\s!initializations}\v!no}
+ {\setfalse\includeMPinitializations}%
+ \setbox\MPgraphicbox\hbox\bgroup
+ \normalexpanded{\noexpand\ctxlua{metapost.graphic("\currentMPgraphicinstance", "\currentMPgraphicformat",
+ \!!bs\ifconditional\includeMPinitializations\the\MPinitializations;\fi\theMPrandomseed;#1;\!!es,
+ \!!bs\ifconditional\includeMPextensions\the\MPextensions;\the\MPuserinclusions;\fi\the\MPinstancetoks;\!!es
+ )}}%
+ \egroup
+ \global\MPinstancetoks\emptytoks
+ \global\settrue\METAFUNinitialized % becomes obsolete
+ %\global\MPextensions\emptytoks % multipls instances
+ %\global\MPuserinclusions\emptytoks % multipls instances
+ \placeMPgraphic
+ \endgroup}
+
+\let\extendedprocessMPgraphic\processMPgraphic
+
+\let\processMPgraphic\normalprocessMPgraphic
+% \let\processMPgraphic\extendedprocessMPgraphic
+
+% ! ! ! ! end temporary ! ! ! !
\newif\ifsetMPrandomseed \setMPrandomseedtrue % false by default
@@ -150,10 +256,7 @@
\def\@@MPG{@MPG@}
\def\doifMPgraphicelse#1%
- {\blabelgroup
- \doifdefinedelse{\@@MPG#1}%
- {\elabelgroup\firstoftwoarguments}
- {\elabelgroup\secondoftwoarguments}}
+ {\ifcsname\@@MPG#1\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
\def\includeMPgraphic#1%
{\executeifdefined{\@@MPG#1};} % ; if not found
@@ -165,7 +268,6 @@
\let\MPdrawingdata\empty
\newif\ifMPdrawingdone \MPdrawingdonefalse
-\newif\ifMPshiftdrawing \MPshiftdrawingfalse
\def\resetMPdrawing
{\globallet\MPdrawingdata\empty
@@ -178,9 +280,25 @@
\def\popMPdrawing
{\globalpopmacro\MPdrawingdata}
-\def\getMPdrawing
+\def\getMPdrawing{\dosinglegroupempty\dogetMPdrawing}
+
+\def\nodogetMPdrawing#1%
+ {\ifMPdrawingdone
+ \expandafter\processMPgraphic\expandafter{\MPdrawingdata}%
+ \fi}
+
+\def\dostartMPcode
+ {\iffirstargument
+ \expandafter\dodogetMPdrawing
+ \else
+ \expandafter\nodogetMPdrawing
+ \fi}
+
+\def\dodogetMPdrawing#1%
{\ifMPdrawingdone
+ \beginMPgraphicgroup{#1::\s!dummy}% name does not matter
\expandafter\processMPgraphic\expandafter{\MPdrawingdata}%
+ \endMPgraphicgroup
\fi}
\def\startMPdrawing
@@ -199,7 +317,6 @@
\let\MPdrawingdata\empty
-\newif\ifMPdrawingdone \MPdrawingdonefalse
\newif\ifMPshiftdrawing \MPshiftdrawingfalse
\def\resetMPdrawing
@@ -233,24 +350,24 @@
\let\stopMPdrawing\relax
\long\def\startMPclip#1#2\stopMPclip
- {\blabelgroup
- \long\setgvalue{MPC:#1}{\ctxlua{metapost.getclippath(\!!bs#2\!!es)}}%
- \elabelgroup}
+ {\long\setgvalue{MPC:#1}{\ctxlua{metapost.getclippath(\!!bs#2\!!es)}}}
\let\stopMPclip\relax
\def\grabMPclippath#1#2#3#4#5% #5 is alternative
- {\blabelgroup
+ {\begingroup
\edef\width {#3\space}\let\overlaywidth \width
\edef\height{#4\space}\let\overlayheight\height
- \doifdefinedelse{MPC:#1}
- {\xdef\MPclippath{\getvalue{MPC:#1}}%
- \ifx\MPclippath\empty\xdef\MPclippath{#5}\fi
- \setxvalue{MPC:#1}{\MPclippath}}
- {\xdef\MPclippath{#5}}%
+ \ifcsname MPC:#1\endcsname
+ \xdef\MPclippath{\getvalue{MPC:#1}}%
+ \ifx\MPclippath\empty\xdef\MPclippath{#5}\fi
+ \setxvalue{MPC:#1}{\MPclippath}%
+ \else
+ \xdef\MPclippath{#5}%
+ \fi
% #2 : method is obsolete, only pdf now, we can always
% gsub the result to ps
- \elabelgroup}
+ \endgroup}
%D Next we will use these support macros.
@@ -268,6 +385,8 @@
defaultscale:=\the\bodyfontsize/10pt;
\stopMPinitializations
+% watch out, this is a type1 font because mp can only handle 8 bit fonts
+
\startMPinitializations % scale is not yet ok
defaultfont:="rm-lmtt10";
\stopMPinitializations
@@ -386,18 +505,36 @@
%D \stoptyping
\newcount\MPobjectcounter
-\newif \ifMPshiftdrawing \MPshiftdrawingfalse
\newbox \MPgraphicbox
+%newif \ifMPshiftdrawing \MPshiftdrawingfalse
+
+\chardef\MPboxmode\zerocount
+
+\def\doobeyMPboxdepth % mode = 1
+ {\setbox\MPgraphicbox\hbox{\hskip\MPllx\onebasepoint\raise\MPlly\onebasepoint\box\MPgraphicbox}}
+
+\def\doignoreMPboxdepth % mode = 2
+ {\normalexpanded
+ {\noexpand\doobeyMPboxdepth
+ \wd\MPgraphicbox\the\wd\MPgraphicbox
+ \ht\MPgraphicbox\the\ht\MPgraphicbox
+ \dp\MPgraphicbox\the\dp\MPgraphicbox}}
+
+\def\obeyMPboxdepth {\chardef\MPboxmode\plusone}
+\def\ignoreMPboxdepth{\chardef\MPboxmode\plustwo}
+\def\normalMPboxdepth{\chardef\MPboxmode\zerocount}
+
+% compatibility hack:
+
+\let\MPshiftdrawingtrue \ignoreMPboxdepth
+\let\MPshiftdrawingfalse\normalMPboxdepth
\def\placeMPgraphic
- {\ifMPshiftdrawing
- \edef\next
- {\wd\MPgraphicbox\the\wd\MPgraphicbox
- \ht\MPgraphicbox\the\ht\MPgraphicbox
- \dp\MPgraphicbox\the\dp\MPgraphicbox}%
- \setbox\MPgraphicbox\hbox
- {\hskip\MPllx\onebasepoint\raise\MPlly\onebasepoint\box\MPgraphicbox}%
- \next
+ {\ifcase\MPboxmode
+ \or % 1
+ \doobeyMPboxdepth
+ \or % 2
+ \doignoreMPboxdepth
\fi
\box\MPgraphicbox}
@@ -409,10 +546,10 @@
\getobject{MP}{#1}}
\long\def\handleuniqueMPgraphic#1#2#3%
- {\blabelgroup
+ {\begingroup
\def\@@meta{#1:}%
\extendMPoverlaystamp{#2}% incl prepare
- \ifundefined{\@@MPG\overlaystamp:#1}%
+ \ifcsname\@@MPG\overlaystamp:#1\endcsname\else
\enableincludeMPgraphics
\forgetall
\global\advance\MPobjectcounter\plusone
@@ -420,57 +557,51 @@
\setxvalue{\@@MPG\overlaystamp:#1}{\noexpand\reuseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}%
\fi
\getvalue{\@@MPG\overlaystamp:#1}%
- \elabelgroup}
+ \endgroup}
\long\def\startuniqueMPgraphic
- {\blabelgroup
- \dodoublegroupempty\dostartuniqueMPgraphic}
+ {\dodoublegroupempty\dostartuniqueMPgraphic}
\long\def\dostartuniqueMPgraphic#1#2#3\stopuniqueMPgraphic%
- {\long\setgvalue{\@@MPG#1}{\handleuniqueMPgraphic{#1}{#2}{#3}}%
- \elabelgroup}
+ {\long\setgvalue{\@@MPG#1}{\handleuniqueMPgraphic{#1}{#2}{#3}}}
\unexpanded\def\uniqueMPgraphic
{\dodoublegroupempty\douniqueMPgraphic}
\def\douniqueMPgraphic#1#2%
- {\blabelgroup
- \setupMPvariables[#1][#2]%
- \getvalue{\@@MPG#1}\empty
- \elabelgroup}
+ {\beginMPgraphicgroup{#1}%
+ \setupMPvariables[\currentMPgraphicname][#2]%
+ \getvalue{\@@MPG\currentMPgraphicname}\empty
+ \endMPgraphicgroup}
\let\stopuniqueMPcode \relax % so that we can use it in \expanded
\long\def\handleuseMPgraphic#1#2#3%
- {\blabelgroup
+ {\begingroup
\forgetall % check this
\def\@@meta{#1:}%
\prepareMPvariables{#2}%
\enableincludeMPgraphics
\processMPgraphic{#3}%
- \elabelgroup}
+ \endgroup}
\long\def\startuseMPgraphic
- {\blabelgroup
- \dodoublegroupempty\dostartuseMPgraphic}
+ {\dodoublegroupempty\dostartuseMPgraphic}
\long\def\dostartuseMPgraphic#1#2#3\stopuseMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}%
- \elabelgroup}
+ {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}}
\long\def\startusableMPgraphic % redundant but handy
- {\blabelgroup
- \dodoublegroupempty\dostartusableMPgraphic}
+ {\dodoublegroupempty\dostartusableMPgraphic}
\long\def\dostartusableMPgraphic#1#2#3\stopusableMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}%
- \elabelgroup}
+ {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}}
\let\stopuseMPgraphic \relax % so that we can use it in \expanded
\let\stopusableMPgraphic \relax % so that we can use it in \expanded
\long\def\handlereusableMPgraphic#1#2#3%
- {\blabelgroup
+ {\begingroup
\def\@@meta{#1:}%
\prepareMPvariables{#2}%
\enableincludeMPgraphics
@@ -478,15 +609,13 @@
\setobject{MP}{\number\MPobjectcounter}\hbox{\processMPgraphic{#3}}% was vbox, graphic must end up as hbox
\setxvalue{\@@MPG#1}{\noexpand\reuseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}%
\getvalue{\@@MPG#1}%
- \elabelgroup}
+ \endgroup}
\long\def\startreusableMPgraphic
- {\blabelgroup
- \dodoublegroupempty\dostartreusableMPgraphic}
+ {\dodoublegroupempty\dostartreusableMPgraphic}
\long\def\dostartreusableMPgraphic#1#2#3\stopreusableMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handlereusableMPgraphic{#1}{#2}{#3}}%
- \elabelgroup}
+ {\long\setgvalue{\@@MPG#1}{\handlereusableMPgraphic{#1}{#2}{#3}}}
\let\stopreusableMPgraphic \relax % so that we can use it in \expanded
@@ -494,10 +623,10 @@
{\dodoublegroupempty\douseMPgraphic}
\def\douseMPgraphic#1#2%
- {\blabelgroup
- \doifsomething{#2}{\setupMPvariables[#1][#2]}%
- \getvalue{\@@MPG#1}\empty
- \elabelgroup}
+ {\beginMPgraphicgroup{#1}%
+ \doifsomething{#2}{\setupMPvariables[\currentMPgraphicname][#2]}%
+ \getvalue{\@@MPG\currentMPgraphicname}\empty
+ \endMPgraphicgroup}
\let\reuseMPgraphic \useMPgraphic % we can save a setup here if needed
\let\reusableMPgraphic\reuseMPgraphic % we can save a setup here if needed
@@ -522,23 +651,21 @@
{\MPpageprefix\overlaywidth:\overlayheight:\overlaydepth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
\long\def\startuniqueMPpagegraphic
- {\blabelgroup
- \dodoublegroupempty\dostartuniqueMPpagegraphic}
+ {\dodoublegroupempty\dostartuniqueMPpagegraphic}
\long\def\dostartuniqueMPpagegraphic#1#2#3\stopuniqueMPpagegraphic
{\long\setgvalue{\@@MPG o:#1}{\handleuniqueMPgraphic{o:#1}{#2}{#3}}%
- \long\setgvalue{\@@MPG e:#1}{\handleuniqueMPgraphic{e:#1}{#2}{#3}}%
- \elabelgroup}
+ \long\setgvalue{\@@MPG e:#1}{\handleuniqueMPgraphic{e:#1}{#2}{#3}}}
\unexpanded\def\uniqueMPpagegraphic
{\dodoublegroupempty\douniqueMPpagegraphic}
\def\douniqueMPpagegraphic#1#2%
- {\blabelgroup
+ {\beginMPgraphicgroup{#1}%
\let\overlaystamp\overlaypagestamp
- \setupMPvariables[\MPpageprefix#1][#2]% prefix is new here
- \getvalue{\@@MPG\MPpageprefix#1}{}%
- \elabelgroup}
+ \setupMPvariables[\MPpageprefix\currentMPgraphicname][#2]% prefix is new here
+ \getvalue{\@@MPG\MPpageprefix\currentMPgraphicname}{}%
+ \endMPgraphicgroup}
%D One way of defining a stamp is:
%D
@@ -553,10 +680,10 @@
%D we introduce a dedicated expansion engine.
\def\prepareMPvariable#1%
- {\ifundefined{\@@framed\@@meta#1}%
- \doprepareMPvariable{\@@meta#1}%
- \else
+ {\ifcsname\@@framed\@@meta#1\endcsname
\doprepareMPvariable{\@@framed\@@meta#1}%
+ \else
+ \doprepareMPvariable{\@@meta#1}%
\fi}
% \startlines
@@ -637,15 +764,35 @@
%D For the moment, the next one is a private macro:
-% TODO ! ! ! ! ! !
-
\def\processMPbuffer
{\dosingleempty\doprocessMPbuffer}
+% this fails (keep):
+%
+% \def\doprocessMPbuffer[#1]%
+% {\doifelsenothing{#1}
+% {\doprocessMPbuffer[\jobname]}
+% {\processMPgraphic{\ctxlua{tex.sprint(tex.ctxcatcodes,buffers.collect("#1"))}}}} % "\\n"
+%
+% this works (keep):
+%
+% \def\doprocessMPbuffer[#1]%
+% {\doifelsenothing{#1}
+% {\doprocessMPbuffer[\jobname]} % #1 can be a list of buffers, otherwise we could use:
+% {\processMPgraphic{\ctxlua{tex.sprint(tex.ctxcatcodes,unpack(buffers.data["#1"]))}}}}
+%
+% this we use:
+
+\newtoks\mpbuffertoks
+
\def\doprocessMPbuffer[#1]%
{\doifelsenothing{#1}
{\doprocessMPbuffer[\jobname]}
- {\processMPgraphic{\ctxlua{tex.sprint(tex.ctxcatcodes,buffers.collect(string.split("#1",",")))}}}}
+ {\beginMPgraphicgroup{#1}%
+ % we need this trick because tex.sprint does not interprets newlines
+ \ctxlua{tex.toks.mpbuffertoks=buffers.collect("\currentMPgraphicname")}%
+ \processMPgraphic{\the\mpbuffertoks}%
+ \endMPgraphicgroup}}
\def\runMPbuffer
{\dosingleempty\dorunMPbuffer}
@@ -718,8 +865,22 @@
%D
%D The most simple case:
-\long\def\startMPcode#1\stopMPcode
- {\processMPgraphic{#1}}
+\def\startMPcode{\dosinglegroupempty\dostartMPcode}
+
+\def\dostartMPcode
+ {\iffirstargument
+ \expandafter\dodostartMPcode
+ \else
+ \expandafter\nodostartMPcode
+ \fi}
+
+\def\dodostartMPcode#1#2\stopMPcode
+ {\beginMPgraphicgroup{#1::\s!dummy}% name does not matter
+ \processMPgraphic{#2}%
+ \endMPgraphicgroup}
+
+\def\nodostartMPcode#1#2\stopMPcode
+ {\processMPgraphic{#2}}
\let\stopMPcode\relax
@@ -749,7 +910,7 @@
%D accomplished by:
\def\douseMPlibrary#1%
- {\ifundefined{\c!file\f!metapostprefix#1}%
+ {\ifcsname\c!file\f!metapostprefix#1\endcsname\else
\letvalueempty{\c!file\f!metapostprefix#1}%
\makeshortfilename[\truefilename{\f!metapostprefix#1}]%
\startreadingfile
@@ -839,7 +1000,7 @@
\to \everyMPgraphic
\appendtoks
- \expanded{\definecolor[currentcolor][\currentcolorname]}%
+ \normalexpanded{\noexpand\definecolor[currentcolor][\currentcolorname]}%
\to \everyMPgraphic
\appendtoks
@@ -1003,9 +1164,9 @@
\long\def\dostartMPcolor[#1][#2]#3\stopMPcolor % slow but sometimes handy
{\startnointerference
- \def\handleMPgraycolor{\expanded{\defineglobalcolor[#1][s=\!MPgMPa1,#2]}}%
- \def\handleMPrgbcolor {\expanded{\defineglobalcolor[#1][r=\!MPgMPa1,g=\!MPgMPa2,b=\!MPgMPa3,#2]}}%
- \def\handleMPcmykcolor{\expanded{\defineglobalcolor[#1][c=\!MPgMPa1,m=\!MPgMPa2,y=\!MPgMPa3,k=\!MPgMPa4,#2]}}%
+ \def\handleMPgraycolor{\normalexpanded{\noexpand\defineglobalcolor[#1][s=\!MPgMPa1,#2]}}%
+ \def\handleMPrgbcolor {\normalexpanded{\noexpand\defineglobalcolor[#1][r=\!MPgMPa1,g=\!MPgMPa2,b=\!MPgMPa3,#2]}}%
+ \def\handleMPcmykcolor{\normalexpanded{\noexpand\defineglobalcolor[#1][c=\!MPgMPa1,m=\!MPgMPa2,y=\!MPgMPa3,k=\!MPgMPa4,#2]}}%
\processMPgraphic{#3}%
\stopnointerference}
@@ -1095,12 +1256,10 @@
{\startreusableMPgraphic{\@@MPG#1@S@}#2\stopreusableMPgraphic}
\long\def\startstaticMPgraphic
- {\blabelgroup
- \dodoublegroupempty\dostartstaticMPgraphic}
+ {\dodoublegroupempty\dostartstaticMPgraphic}
\long\def\dostartstaticMPgraphic#1#2#3\stopstaticMPgraphic
- {\long\setgvalue{\@@MPG#1@S@}{\handlereusableMPgraphic{#1}{#2}{#3}}%
- \elabelgroup}
+ {\long\setgvalue{\@@MPG#1@S@}{\handlereusableMPgraphic{#1}{#2}{#3}}}
%D New:
diff --git a/tex/context/base/meta-pdf.lua b/tex/context/base/meta-pdf.lua
index 39f24aa5b..240778bfa 100644
--- a/tex/context/base/meta-pdf.lua
+++ b/tex/context/base/meta-pdf.lua
@@ -1,228 +1,94 @@
--- filename : meta-pdf.lua
--- comment : companion to meta-pdf.tex
--- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
--- copyright: PRAGMA ADE / ConTeXt Development Team
--- license : see context related readme files
-
--- This is the third version. Version 1 converted to Lua code,
--- version 2 gsubbed the file into TeX code, and version 3 uses
--- the new lpeg functionality and streams the result into TeX.
-
--- We will move old stuff to edu.
-
---~ old lpeg 0.4 lpeg 0.5
---~ 100 times test graphic 2.45 (T:1.07) 0.72 (T:0.24) 0.580 (0.560 no table) -- 0.54 optimized for one space (T:0.19)
---~ 100 times big graphic 10.44 4.30/3.35 nogb 2.914 (2.050 no table) -- 1.99 optimized for one space (T:0.85)
---~ 500 times test graphic T:1.29 T:1.16 (T:1.10 no table) -- T:1.10
-
-if not versions then versions = { } end versions['meta-pdf'] = 1.003
-
-mptopdf = { }
-mptopdf.parsers = { }
-mptopdf.parser = 'none'
-
-function mptopdf.reset()
- mptopdf.data = ""
- mptopdf.path = { }
- mptopdf.stack = { }
- mptopdf.texts = { }
- mptopdf.version = 0
- mptopdf.shortcuts = false
- mptopdf.resetpath()
-end
-
-function mptopdf.resetpath()
- mptopdf.stack.close = false
- mptopdf.stack.path = { }
- mptopdf.stack.concat = nil
- mptopdf.stack.special = false
-end
+if not modules then modules = { } end modules ['meta-pdf'] = {
+ version = 1.001,
+ comment = "companion to meta-pdf.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
-mptopdf.reset()
+-- Finally we used an optimized version. The test code can be found in
+-- meta-pdh.lua but since we no longer want to overload functione we
+-- use more locals now.
-function mptopdf.parsers.none()
- -- no parser set
-end
+local concat, format, gsub, find = table.concat, string.format, string.gsub, string.find
+local byte = string.byte
+local texsprint = tex.sprint
-function mptopdf.parse()
- mptopdf.parsers[mptopdf.parser]()
-end
+local ctxcatcodes = tex.ctxcatcodes
--- old code
+mptopdf = { }
+mptopdf.n = 0
-mptopdf.steps = { }
+local m_path, m_stack, m_texts, m_version, m_date, m_shortcuts = { }, { }, { }, 0, 0, false
-mptopdf.descapes = {
- ['('] = "\\\\char40 ",
- [')'] = "\\\\char41 ",
- ['"'] = "\\\\char92 "
-}
+local m_stack_close, m_stack_path, m_stack_concat = false, { }, nil
-function mptopdf.descape(str)
- str = str:gsub("\\(%d%d%d)",function(n)
- return "\\char" .. tonumber(n,8) .. " "
- end)
- return str:gsub("\\([%(%)\\])",mptopdf.descapes)
+local function resetpath()
+ m_stack_close = false
+ m_stack_path = { }
+ m_stack_concat = nil
end
-function mptopdf.steps.descape(str)
- str = str:gsub("\\(%d%d%d)",function(n)
- return "\\\\char" .. tonumber(n,8) .. " "
- end)
- return str:gsub("\\([%(%)\\])",mptopdf.descapes)
+local function resetall()
+ m_path, m_stack, m_texts, m_version, m_shortcuts = { }, { }, { }, 0, false
+ resetpath()
end
-function mptopdf.steps.strip() -- .3 per expr
- mptopdf.data = mptopdf.data:gsub("^(.-)%%+Page:.-%c+(.*)%s+%a+%s+%%+EOF.*$", function(preamble, graphic)
- local bbox = "0 0 0 0"
- for b in preamble:gmatch("%%%%%a+oundingBox: +(.-)%c+") do
- bbox = b
- end
- local name, version = preamble:gmatch("%%%%Creator: +(.-) +(.-) ")
- mptopdf.version = tostring(version or "0")
- if preamble:find("/hlw{0 dtransform") then
- mptopdf.shortcuts = true
- end
- -- the boundingbox specification needs to come before data, well, not really
- return bbox .. " boundingbox\n" .. "\nbegindata\n" .. graphic .. "\nenddata\n"
- end, 1)
- mptopdf.data = mptopdf.data:gsub("%%%%MetaPostSpecials: +(.-)%c+", "%1 specials\n", 1)
- mptopdf.data = mptopdf.data:gsub("%%%%MetaPostSpecial: +(.-)%c+", "%1 special\n")
- mptopdf.data = mptopdf.data:gsub("%%.-%c+", "")
-end
-
-function mptopdf.steps.cleanup()
- if not mptopdf.shortcuts then
- mptopdf.data = mptopdf.data:gsub("gsave%s+fill%s+grestore%s+stroke", "both")
- mptopdf.data = mptopdf.data:gsub("([%d%.]+)%s+([%d%.]+)%s+dtransform%s+exch%s+truncate%s+exch%s+idtransform%s+pop%s+setlinewidth", function(wx,wy)
- if tonumber(wx) > 0 then return wx .. " setlinewidth" else return wy .. " setlinewidth" end
- end)
- mptopdf.data = mptopdf.data:gsub("([%d%.]+)%s+([%d%.]+)%s+dtransform%s+truncate%s+idtransform%s+setlinewidth%s+pop", function(wx,wy)
- if tonumber(wx) > 0 then return wx .. " setlinewidth" else return wy .. " setlinewidth" end
- end)
- end
-end
+resetall()
-function mptopdf.steps.convert()
- mptopdf.data = mptopdf.data:gsub("%c%((.-)%) (.-) (.-) fshow", function(str,font,scale)
- mptopdf.texts[mptopdf.texts+1] = {mptopdf.steps.descape(str), font, scale}
- return "\n" .. #mptopdf.texts .. " textext"
- end)
- mptopdf.data = mptopdf.data:gsub("%[%s*(.-)%s*%]", function(str)
- return str:gsub("%s+"," ")
- end)
- local t
- mptopdf.data = mptopdf.data:gsub("%s*([^%a]-)%s*(%a+)", function(args,cmd)
- if cmd == "textext" then
- t = mptopdf.texts[tonumber(args)]
- return "mps.textext(" .. "\"" .. t[2] .. "\"," .. t[3] .. ",\"" .. t[1] .. "\")\n"
- else
- return "mps." .. cmd .. "(" .. args:gsub(" +",",") .. ")\n"
- end
- end)
-end
+-- code injection, todo: collect and flush packed using node injection
-function mptopdf.steps.process()
- assert(loadstring(mptopdf.data))() -- () runs the loaded chunk
+local function pdfcode(str) -- not used
+ texsprint(ctxcatcodes,"\\MPScode{",str,"}")
end
-
-function mptopdf.parsers.gsub()
- mptopdf.steps.strip()
- mptopdf.steps.cleanup()
- mptopdf.steps.convert()
- mptopdf.steps.process()
-end
-
--- end of old code
-
--- from lua to tex
-
-function mptopdf.pdfcode(str)
- tex.sprint(tex.ctxcatcodes,"\\PDFcode{" .. str .. "}")
-end
-
-function mptopdf.texcode(str)
- tex.sprint(tex.ctxcatcodes,str)
+local function texcode(str)
+ texsprint(ctxcatcodes,str)
end
-- auxiliary functions
-function mptopdf.flushconcat()
- if mptopdf.stack.concat then
- mptopdf.pdfcode(table.concat(mptopdf.stack.concat," ") .. " cm")
- mptopdf.stack.concat = nil
+local function flushconcat()
+ if m_stack_concat then
+ texsprint(ctxcatcodes,"\\MPScode{",concat(m_stack_concat," ")," cm}")
+ m_stack_concat = nil
end
end
-function mptopdf.flushpath(cmd)
- if #mptopdf.stack.path > 0 then
+local function flushpath(cmd)
+ -- faster: no local function
+ if #m_stack_path > 0 then
local path = { }
- if mptopdf.stack.concat then
- local sx, sy = mptopdf.stack.concat[1], mptopdf.stack.concat[4]
- local rx, ry = mptopdf.stack.concat[2], mptopdf.stack.concat[3]
- local tx, ty = mptopdf.stack.concat[5], mptopdf.stack.concat[6]
+ if m_stack_concat then
+ local sx, sy = m_stack_concat[1], m_stack_concat[4]
+ local rx, ry = m_stack_concat[2], m_stack_concat[3]
+ local tx, ty = m_stack_concat[5], m_stack_concat[6]
local d = (sx*sy) - (rx*ry)
- local function concat(px, py)
- return (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d
- end
- for _,v in ipairs(mptopdf.stack.path) do
- v[1],v[2] = concat(v[1],v[2])
+ -- local function mpconcat(px, py) -- move this inline
+ -- return (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d
+ -- end
+ for k=1,#m_stack_path do
+ local v = m_stack_path[k]
+ local px, py = v[1], v[2] ; v[1], v[2] = (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d -- mpconcat(v[1],v[2])
if #v == 7 then
- v[3],v[4] = concat(v[3],v[4])
- v[5],v[6] = concat(v[5],v[6])
+ local px, py = v[3], v[4] ; v[3], v[4] = (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d -- mpconcat(v[3],v[4])
+ local px, py = v[5], v[6] ; v[5], v[6] = (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d -- mpconcat(v[5],v[6])
end
- path[#path+1] = table.concat(v," ")
+ path[#path+1] = concat(v," ")
end
else
- for _,v in ipairs(mptopdf.stack.path) do
- path[#path+1] = table.concat(v," ")
+ for k=1,#m_stack_path do
+ path[#path+1] = concat(m_stack_path[k]," ")
end
end
- mptopdf.flushconcat()
- mptopdf.texcode("\\MPSpath{" .. table.concat(path," ") .. "}")
- if mptopdf.stack.close then
- mptopdf.texcode("\\MPScode{h " .. cmd .. "}")
+ flushconcat()
+ texcode("\\MPSpath{" .. concat(path," ") .. "}")
+ if m_stack_close then
+ texcode("\\MPScode{h " .. cmd .. "}")
else
- mptopdf.texcode("\\MPScode{" .. cmd .."}")
+ texcode("\\MPScode{" .. cmd .."}")
end
end
- mptopdf.resetpath()
-end
-
-if input and input.instance then
- function mptopdf.loaded(name)
- local ok, n
- mptopdf.reset()
- ok, mptopdf.data, n = input.loadbinfile(name, 'tex') -- we need a binary load !
- return ok
- end
-else
- function mptopdf.loaded(name)
- local f = io.open(name, 'rb')
- if f then
- mptopdf.reset()
- mptopdf.data = f:read('*all')
- f:close()
- return true
- else
- return false
- end
- end
-end
-
-if not mptopdf.parse then
- function mptopdf.parse() end -- forward declaration
-end
-
-function mptopdf.convertmpstopdf(name)
- if mptopdf.loaded(name) then
- input.starttiming(mptopdf)
- mptopdf.parse()
- mptopdf.reset()
- input.stoptiming(mptopdf)
- else
- tex.print("file " .. name .. " not found")
- end
+ resetpath()
end
-- mp interface
@@ -230,171 +96,133 @@ end
mps = mps or { }
function mps.creator(a, b, c)
- mptopdf.version = tonumber(b)
+ m_version = tonumber(b)
end
function mps.creationdate(a)
- mptopdf.date= a
+ m_date = a
end
function mps.newpath()
- mptopdf.stack.path = { }
+ m_stack_path = { }
end
function mps.boundingbox(llx, lly, urx, ury)
- mptopdf.texcode("\\MPSboundingbox{" .. llx .. "}{" .. lly .. "}{" .. urx .. "}{" .. ury .. "}")
+ texcode("\\MPSboundingbox{" .. llx .. "}{" .. lly .. "}{" .. urx .. "}{" .. ury .. "}")
end
function mps.moveto(x,y)
- mptopdf.stack.path[#mptopdf.stack.path+1] = {x,y,"m"}
+ m_stack_path[#m_stack_path+1] = {x,y,"m"}
end
function mps.curveto(ax, ay, bx, by, cx, cy)
- mptopdf.stack.path[#mptopdf.stack.path+1] = {ax,ay,bx,by,cx,cy,"c"}
+ m_stack_path[#m_stack_path+1] = {ax,ay,bx,by,cx,cy,"c"}
end
function mps.lineto(x,y)
- mptopdf.stack.path[#mptopdf.stack.path+1] = {x,y,"l"}
+ m_stack_path[#m_stack_path+1] = {x,y,"l"}
end
function mps.rlineto(x,y)
local dx, dy = 0, 0
- if #mptopdf.stack.path > 0 then
- dx, dy = mptopdf.stack.path[#mptopdf.stack.path][1], mptopdf.stack.path[#mptopdf.stack.path][2]
+ if #m_stack_path > 0 then
+ dx, dy = m_stack_path[#m_stack_path][1], m_stack_path[#m_stack_path][2]
end
- mptopdf.stack.path[#mptopdf.stack.path+1] = {dx,dy,"l"}
+ m_stack_path[#m_stack_path+1] = {dx,dy,"l"}
end
function mps.translate(tx,ty)
- mptopdf.pdfcode("1 0 0 0 1 " .. tx .. " " .. ty .. " cm")
+ texsprint(ctxcatcodes,"\\MPScode{1 0 0 0 1 ",tx," ",ty," cm}")
end
function mps.scale(sx,sy)
- mptopdf.stack.concat = {sx,0,0,sy,0,0}
+ m_stack_concat = {sx,0,0,sy,0,0}
end
function mps.concat(sx, rx, ry, sy, tx, ty)
- mptopdf.stack.concat = {sx,rx,ry,sy,tx,ty}
+ m_stack_concat = {sx,rx,ry,sy,tx,ty}
end
function mps.setlinejoin(d)
- mptopdf.pdfcode(d .. " j")
+ texsprint(ctxcatcodes,"\\MPScode{",d," j}")
end
function mps.setlinecap(d)
- mptopdf.pdfcode(d .. " J")
+ texsprint(ctxcatcodes,"\\MPScode{",d," J}")
end
function mps.setmiterlimit(d)
- mptopdf.pdfcode(d .. " M")
+ texsprint(ctxcatcodes,"\\MPScode{",d," M}")
end
function mps.gsave()
- mptopdf.pdfcode("q")
+ texsprint(ctxcatcodes,"\\MPScode{q}")
end
function mps.grestore()
- mptopdf.pdfcode("Q")
+ texsprint(ctxcatcodes,"\\MPScode{Q}")
end
-function mps.setdash(...)
+function mps.setdash(...) -- can be made faster, operate on t = { ... }
local n = select("#",...)
- mptopdf.pdfcode("[" .. table.concat({...}," ",1,n-1) .. "] " .. select(n,...) .. " d")
+ texsprint(ctxcatcodes,"\\MPScode{","[",concat({...}," ",1,n-1),"] ",select(n,...)," d}")
end
function mps.resetdash()
- mptopdf.pdfcode("[ ] 0 d")
+ texsprint(ctxcatcodes,"\\MPScode{[ ] 0 d}")
end
function mps.setlinewidth(d)
- mptopdf.pdfcode(d .. " w")
+ texsprint(ctxcatcodes,"\\MPScode{",d," w}")
end
function mps.closepath()
- mptopdf.stack.close = true
+ m_stack_close = true
end
function mps.fill()
- mptopdf.flushpath('f')
+ flushpath('f')
end
function mps.stroke()
- mptopdf.flushpath('S')
+ flushpath('S')
end
function mps.both()
- mptopdf.flushpath('B')
+ flushpath('B')
end
function mps.clip()
- mptopdf.flushpath('W n')
+ flushpath('W n')
end
function mps.textext(font, scale, str) -- old parser
local dx, dy = 0, 0
- if #mptopdf.stack.path > 0 then
- dx, dy = mptopdf.stack.path[1][1], mptopdf.stack.path[1][2]
+ if #m_stack_path > 0 then
+ dx, dy = m_stack_path[1][1], m_stack_path[1][2]
end
- mptopdf.flushconcat()
- mptopdf.texcode("\\MPStextext{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
- mptopdf.resetpath()
+ flushconcat()
+ texcode("\\MPStextext{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
+ resetpath()
end
---~ function mps.handletext(font,scale.str,dx,dy)
---~ local one, two = string.match(str, "^(%d+)::::(%d+)")
---~ if one and two then
---~ mptopdf.texcode("\\MPTOPDFtextext{"..font.."}{"..scale.."}{"..one.."}{"..two.."}{"..dx.."}{"..dy.."}")
---~ else
---~ mptopdf.texcode("\\MPTOPDFtexcode{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
---~ end
---~ end
-
-if false and ctx and ctx.aux and ctx.aux.definecolor then
-
- logs.report("mptopdf", "using attribute based mps colors")
-
- -- does not work due to Q-q mess-up
-
- function mps.setrgbcolor(r,g,b) -- extra check
- r, g, b = tonumber(r), tonumber(g), tonumber(b) -- needed when we use lpeg
- if r == 0.0123 and g < 0.1 then -- g is extra check
- mptopdf.texcode("\\doresetattribute{transparency}\\MPSspecial{" .. g*10000 .. "}{" .. b*10000 .. "}")
- elseif r == 0.123 and g < 0.1 then -- g is extra check
- mptopdf.texcode("\\doresetattribute{transparency}\\MPSspecial{" .. g* 1000 .. "}{" .. b* 1000 .. "}")
- else
- mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'rgb',r,g,b) .. "}")
- end
- end
-
- function mps.setcmykcolor(c,m,y,k)
- mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'cmyk',tonumber(c),tonumber(m),tonumber(y),tonumber(k)) .. "}")
- end
-
- function mps.setgray(s)
- mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'gray',tonumber(s)) .. "}")
- end
-
-else
-
- function mps.setrgbcolor(r,g,b) -- extra check
- r, g = tonumber(r), tonumber(g) -- needed when we use lpeg
- if r == 0.0123 and g < 0.1 then
- mptopdf.texcode("\\MPSspecial{" .. g*10000 .. "}{" .. b*10000 .. "}")
- elseif r == 0.123 and g < 0.1 then
- mptopdf.texcode("\\MPSspecial{" .. g* 1000 .. "}{" .. b* 1000 .. "}")
- else
- mptopdf.texcode("\\MPSrgb{" .. r .. "}{" .. g .. "}{" .. b .. "}")
- end
- end
-
- function mps.setcmykcolor(c,m,y,k)
- mptopdf.texcode("\\MPScmyk{" .. c .. "}{" .. m .. "}{" .. y .. "}{" .. k .. "}")
+function mps.setrgbcolor(r,g,b) -- extra check
+ r, g = tonumber(r), tonumber(g) -- needed when we use lpeg
+ if r == 0.0123 and g < 0.1 then
+ texcode("\\MPSspecial{" .. g*10000 .. "}{" .. b*10000 .. "}")
+ elseif r == 0.123 and g < 0.1 then
+ texcode("\\MPSspecial{" .. g* 1000 .. "}{" .. b* 1000 .. "}")
+ else
+ texcode("\\MPSrgb{" .. r .. "}{" .. g .. "}{" .. b .. "}")
end
+end
- function mps.setgray(s)
- mptopdf.texcode("\\MPSgray{" .. s .. "}")
- end
+function mps.setcmykcolor(c,m,y,k)
+ texcode("\\MPScmyk{" .. c .. "}{" .. m .. "}{" .. y .. "}{" .. k .. "}")
+end
+function mps.setgray(s)
+ texcode("\\MPSgray{" .. s .. "}")
end
function mps.specials(version,signal,factor) -- 2.0 123 1000
@@ -402,7 +230,7 @@ end
function mps.special(...) -- 7 1 0.5 1 0 0 1 3
local n = select("#",...)
- mptopdf.texcode("\\MPSbegin\\MPSset{" .. table.concat({...},"}\\MPSset{",2,n) .. "}\\MPSend")
+ texcode("\\MPSbegin\\MPSset{" .. concat({...},"}\\MPSset{",2,n) .. "}\\MPSend")
end
function mps.begindata()
@@ -414,43 +242,8 @@ end
function mps.showpage()
end
-mps.n = mps.newpath -- n
-mps.p = mps.closepath -- h
-mps.l = mps.lineto -- l
-mps.r = mps.rlineto -- r
-mps.m = mps.moveto -- m
-mps.c = mps.curveto -- c
-mps.hlw = mps.setlinewidth
-mps.vlw = mps.setlinewidth
-
-mps.C = mps.setcmykcolor -- k
-mps.G = mps.setgray -- g
-mps.R = mps.setrgbcolor -- rg
-
-mps.lj = mps.setlinejoin -- j
-mps.ml = mps.setmiterlimit -- M
-mps.lc = mps.setlinecap -- J
-mps.sd = mps.setdash -- d
-mps.rd = mps.resetdash
-
-mps.S = mps.stroke -- S
-mps.F = mps.fill -- f
-mps.B = mps.both -- B
-mps.W = mps.clip -- W
-
-mps.q = mps.gsave -- q
-mps.Q = mps.grestore -- Q
-
-mps.s = mps.scale -- (not in pdf)
-mps.t = mps.concat -- (not the same as pdf anyway)
-
-mps.P = mps.showpage
-
--- experimental
-
function mps.attribute(id,value)
- mptopdf.texcode("\\attribute " .. id .. "=" .. value .. " ")
--- mptopdf.texcode("\\dompattribute{" .. id .. "}{" .. value .. "}")
+ texcode("\\attribute " .. id .. "=" .. value .. " ")
end
-- lpeg parser
@@ -459,160 +252,178 @@ end
-- that MetaPost produces. It's my first real lpeg code, which may
-- show. Because the parser binds to functions, we define it last.
-do -- assumes \let\c\char
+local lpegP, lpegR, lpegS, lpegC, lpegCc, lpegCs = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs
+
+local digit = lpegR("09")
+local eol = lpegS('\r\n')^1
+local sp = lpegP(' ')^1
+local space = lpegS(' \r\n')^1
+local number = lpegS('0123456789.-+')^1
+local nonspace = lpegP(1-lpegS(' \r\n'))^1
+
+local spec = digit^2 * lpegP("::::") * digit^2
+local text = lpegCc("{") * (
+ lpegP("\\") * ( (digit * digit * digit) / function(n) return "c" .. tonumber(n,8) end) +
+ lpegP(" ") / function(n) return "\\c32" end + -- never in new mp
+ lpegP(1) / function(n) return "\\c" .. byte(n) end
+ ) * lpegCc("}")
+local package = lpegCs(spec + text^0)
+
+function mps.fshow(str,font,scale) -- lpeg parser
+ mps.textext(font,scale,package:match(str))
+end
+
+local cnumber = lpegC(number)
+local cstring = lpegC(nonspace)
+
+local specials = (lpegP("%%MetaPostSpecials:") * sp * (cstring * sp^0)^0 * eol) / mps.specials
+local special = (lpegP("%%MetaPostSpecial:") * sp * (cstring * sp^0)^0 * eol) / mps.special
+local boundingbox = (lpegP("%%BoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
+local highresboundingbox = (lpegP("%%HiResBoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
+
+local setup = lpegP("%%BeginSetup") * (1 - lpegP("%%EndSetup") )^1
+local prolog = lpegP("%%BeginProlog") * (1 - lpegP("%%EndProlog"))^1
+local comment = lpegP('%')^1 * (1 - eol)^1
+
+local curveto = ((cnumber * sp)^6 * lpegP("curveto") ) / mps.curveto
+local lineto = ((cnumber * sp)^2 * lpegP("lineto") ) / mps.lineto
+local rlineto = ((cnumber * sp)^2 * lpegP("rlineto") ) / mps.rlineto
+local moveto = ((cnumber * sp)^2 * lpegP("moveto") ) / mps.moveto
+local setrgbcolor = ((cnumber * sp)^3 * lpegP("setrgbcolor") ) / mps.setrgbcolor
+local setcmykcolor = ((cnumber * sp)^4 * lpegP("setcmykcolor") ) / mps.setcmykcolor
+local setgray = ((cnumber * sp)^1 * lpegP("setgray") ) / mps.setgray
+local newpath = ( lpegP("newpath") ) / mps.newpath
+local closepath = ( lpegP("closepath") ) / mps.closepath
+local fill = ( lpegP("fill") ) / mps.fill
+local stroke = ( lpegP("stroke") ) / mps.stroke
+local clip = ( lpegP("clip") ) / mps.clip
+local both = ( lpegP("gsave fill grestore")) / mps.both
+local showpage = ( lpegP("showpage") )
+local setlinejoin = ((cnumber * sp)^1 * lpegP("setlinejoin") ) / mps.setlinejoin
+local setlinecap = ((cnumber * sp)^1 * lpegP("setlinecap") ) / mps.setlinecap
+local setmiterlimit = ((cnumber * sp)^1 * lpegP("setmiterlimit") ) / mps.setmiterlimit
+local gsave = ( lpegP("gsave") ) / mps.gsave
+local grestore = ( lpegP("grestore") ) / mps.grestore
+
+local setdash = (lpegP("[") * (cnumber * sp^0)^0 * lpegP("]") * sp * cnumber * sp * lpegP("setdash")) / mps.setdash
+local concat = (lpegP("[") * (cnumber * sp^0)^6 * lpegP("]") * sp * lpegP("concat") ) / mps.concat
+local scale = ( (cnumber * sp^0)^6 * sp * lpegP("concat") ) / mps.concat
+
+local fshow = (lpegP("(") * lpegC((1-lpegP(")"))^1) * lpegP(")") * space * cstring * space * cnumber * space * lpegP("fshow")) / mps.fshow
+local fshow = (lpegP("(") * lpegCs( ( lpegP("\\(")/"\\050" + lpegP("\\)")/"\\051" + (1-lpegP(")")) )^1 )
+ * lpegP(")") * space * cstring * space * cnumber * space * lpegP("fshow")) / mps.fshow
+
+local setlinewidth_x = (lpegP("0") * sp * cnumber * sp * lpegP("dtransform truncate idtransform setlinewidth pop")) / mps.setlinewidth
+local setlinewidth_y = (cnumber * sp * lpegP("0 dtransform exch truncate exch idtransform pop setlinewidth") ) / mps.setlinewidth
+
+local c = ((cnumber * sp)^6 * lpegP("c") ) / mps.curveto -- ^6 very inefficient, ^1 ok too
+local l = ((cnumber * sp)^2 * lpegP("l") ) / mps.lineto
+local r = ((cnumber * sp)^2 * lpegP("r") ) / mps.rlineto
+local m = ((cnumber * sp)^2 * lpegP("m") ) / mps.moveto
+local vlw = ((cnumber * sp)^1 * lpegP("vlw")) / mps.setlinewidth
+local hlw = ((cnumber * sp)^1 * lpegP("hlw")) / mps.setlinewidth
+
+local R = ((cnumber * sp)^3 * lpegP("R") ) / mps.setrgbcolor
+local C = ((cnumber * sp)^4 * lpegP("C") ) / mps.setcmykcolor
+local G = ((cnumber * sp)^1 * lpegP("G") ) / mps.setgray
+
+local lj = ((cnumber * sp)^1 * lpegP("lj") ) / mps.setlinejoin
+local ml = ((cnumber * sp)^1 * lpegP("ml") ) / mps.setmiterlimit
+local lc = ((cnumber * sp)^1 * lpegP("lc") ) / mps.setlinecap
+
+local n = lpegP("n") / mps.newpath
+local p = lpegP("p") / mps.closepath
+local S = lpegP("S") / mps.stroke
+local F = lpegP("F") / mps.fill
+local B = lpegP("B") / mps.both
+local W = lpegP("W") / mps.clip
+local P = lpegP("P") / mps.showpage
+
+local q = lpegP("q") / mps.gsave
+local Q = lpegP("Q") / mps.grestore
+
+local sd = (lpegP("[") * (cnumber * sp^0)^0 * lpegP("]") * sp * cnumber * sp * lpegP("sd")) / mps.setdash
+local rd = ( lpegP("rd")) / mps.resetdash
+
+local s = ( (cnumber * sp^0)^2 * lpegP("s") ) / mps.scale
+local t = (lpegP("[") * (cnumber * sp^0)^6 * lpegP("]") * sp * lpegP("t") ) / mps.concat
- local byte = string.byte
- local digit = lpeg.R("09")
- local spec = digit^2 * lpeg.P("::::") * digit^2
- local text = lpeg.Cc("{") * (
- lpeg.P("\\") * ( (digit * digit * digit) / function(n) return "c" .. tonumber(n,8) end) +
- lpeg.P(" ") / function(n) return "\\c32" end + -- never in new mp
- lpeg.P(1) / function(n) return "\\c" .. byte(n) end
- ) * lpeg.Cc("}")
- local package = lpeg.Cs(spec + text^0)
+-- experimental
- function mps.fshow(str,font,scale) -- lpeg parser
- mps.textext(font,scale,package:match(str))
+local attribute = ((cnumber * sp)^2 * lpegP("attribute")) / mps.attribute
+local A = ((cnumber * sp)^2 * lpegP("A")) / mps.attribute
+
+local preamble = (
+ prolog + setup +
+ boundingbox + highresboundingbox + specials + special +
+ comment
+)
+
+local procset = (
+ lj + ml + lc +
+ c + l + m + n + p + r +
+ A +
+ R + C + G +
+ S + F + B + W +
+ vlw + hlw +
+ Q + q +
+ sd + rd +
+ t + s +
+ fshow +
+ P
+)
+
+local verbose = (
+ curveto + lineto + moveto + newpath + closepath + rlineto +
+ setrgbcolor + setcmykcolor + setgray +
+ attribute +
+ setlinejoin + setmiterlimit + setlinecap +
+ stroke + fill + clip + both +
+ setlinewidth_x + setlinewidth_y +
+ gsave + grestore +
+ concat + scale +
+ fshow +
+ setdash + -- no resetdash
+ showpage
+)
+
+-- order matters in terms of speed / we could check for procset first
+
+local captures_old = ( space + verbose + preamble )^0
+local captures_new = ( space + procset + preamble + verbose )^0
+
+local function parse(m_data)
+ if find(m_data,"%%%%BeginResource: procset mpost") then
+ captures_new:match(m_data)
+ else
+ captures_old:match(m_data)
end
-
end
-do
-
- local eol = lpeg.S('\r\n')^1
- local sp = lpeg.P(' ')^1
- local space = lpeg.S(' \r\n')^1
- local number = lpeg.S('0123456789.-+')^1
- local nonspace = lpeg.P(1-lpeg.S(' \r\n'))^1
-
- local cnumber = lpeg.C(number)
- local cstring = lpeg.C(nonspace)
-
- local specials = (lpeg.P("%%MetaPostSpecials:") * sp * (cstring * sp^0)^0 * eol) / mps.specials
- local special = (lpeg.P("%%MetaPostSpecial:") * sp * (cstring * sp^0)^0 * eol) / mps.special
- local boundingbox = (lpeg.P("%%BoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
- local highresboundingbox = (lpeg.P("%%HiResBoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
-
- local setup = lpeg.P("%%BeginSetup") * (1 - lpeg.P("%%EndSetup") )^1
- local prolog = lpeg.P("%%BeginProlog") * (1 - lpeg.P("%%EndProlog"))^1
- local comment = lpeg.P('%')^1 * (1 - eol)^1
-
- local curveto = ((cnumber * sp)^6 * lpeg.P("curveto") ) / mps.curveto
- local lineto = ((cnumber * sp)^2 * lpeg.P("lineto") ) / mps.lineto
- local rlineto = ((cnumber * sp)^2 * lpeg.P("rlineto") ) / mps.rlineto
- local moveto = ((cnumber * sp)^2 * lpeg.P("moveto") ) / mps.moveto
- local setrgbcolor = ((cnumber * sp)^3 * lpeg.P("setrgbcolor") ) / mps.setrgbcolor
- local setcmykcolor = ((cnumber * sp)^4 * lpeg.P("setcmykcolor") ) / mps.setcmykcolor
- local setgray = ((cnumber * sp)^1 * lpeg.P("setgray") ) / mps.setgray
- local newpath = ( lpeg.P("newpath") ) / mps.newpath
- local closepath = ( lpeg.P("closepath") ) / mps.closepath
- local fill = ( lpeg.P("fill") ) / mps.fill
- local stroke = ( lpeg.P("stroke") ) / mps.stroke
- local clip = ( lpeg.P("clip") ) / mps.clip
- local both = ( lpeg.P("gsave fill grestore")) / mps.both
- local showpage = ( lpeg.P("showpage") )
- local setlinejoin = ((cnumber * sp)^1 * lpeg.P("setlinejoin") ) / mps.setlinejoin
- local setlinecap = ((cnumber * sp)^1 * lpeg.P("setlinecap") ) / mps.setlinecap
- local setmiterlimit = ((cnumber * sp)^1 * lpeg.P("setmiterlimit") ) / mps.setmiterlimit
- local gsave = ( lpeg.P("gsave") ) / mps.gsave
- local grestore = ( lpeg.P("grestore") ) / mps.grestore
-
- local setdash = (lpeg.P("[") * (cnumber * sp^0)^0 * lpeg.P("]") * sp * cnumber * sp * lpeg.P("setdash")) / mps.setdash
- local concat = (lpeg.P("[") * (cnumber * sp^0)^6 * lpeg.P("]") * sp * lpeg.P("concat") ) / mps.concat
- local scale = ( (cnumber * sp^0)^6 * sp * lpeg.P("concat") ) / mps.concat
-
- local fshow = (lpeg.P("(") * lpeg.C((1-lpeg.P(")"))^1) * lpeg.P(")") * space * cstring * space * cnumber * space * lpeg.P("fshow")) / mps.fshow
- local fshow = (lpeg.P("(") *
- lpeg.Cs( ( lpeg.P("\\(")/"\\050" + lpeg.P("\\)")/"\\051" + (1-lpeg.P(")")) )^1 )
- * lpeg.P(")") * space * cstring * space * cnumber * space * lpeg.P("fshow")) / mps.fshow
-
- local setlinewidth_x = (lpeg.P("0") * sp * cnumber * sp * lpeg.P("dtransform truncate idtransform setlinewidth pop")) / mps.setlinewidth
- local setlinewidth_y = (cnumber * sp * lpeg.P("0 dtransform exch truncate exch idtransform pop setlinewidth") ) / mps.setlinewidth
-
- local c = ((cnumber * sp)^6 * lpeg.P("c") ) / mps.curveto -- ^6 very inefficient, ^1 ok too
- local l = ((cnumber * sp)^2 * lpeg.P("l") ) / mps.lineto
- local r = ((cnumber * sp)^2 * lpeg.P("r") ) / mps.rlineto
- local m = ((cnumber * sp)^2 * lpeg.P("m") ) / mps.moveto
- local vlw = ((cnumber * sp)^1 * lpeg.P("vlw")) / mps.setlinewidth
- local hlw = ((cnumber * sp)^1 * lpeg.P("hlw")) / mps.setlinewidth
-
- local R = ((cnumber * sp)^3 * lpeg.P("R") ) / mps.setrgbcolor
- local C = ((cnumber * sp)^4 * lpeg.P("C") ) / mps.setcmykcolor
- local G = ((cnumber * sp)^1 * lpeg.P("G") ) / mps.setgray
-
- local lj = ((cnumber * sp)^1 * lpeg.P("lj") ) / mps.setlinejoin
- local ml = ((cnumber * sp)^1 * lpeg.P("ml") ) / mps.setmiterlimit
- local lc = ((cnumber * sp)^1 * lpeg.P("lc") ) / mps.setlinecap
-
- local n = lpeg.P("n") / mps.newpath
- local p = lpeg.P("p") / mps.closepath
- local S = lpeg.P("S") / mps.stroke
- local F = lpeg.P("F") / mps.fill
- local B = lpeg.P("B") / mps.both
- local W = lpeg.P("W") / mps.clip
- local P = lpeg.P("P") / mps.showpage
-
- local q = lpeg.P("q") / mps.gsave
- local Q = lpeg.P("Q") / mps.grestore
-
- local sd = (lpeg.P("[") * (cnumber * sp^0)^0 * lpeg.P("]") * sp * cnumber * sp * lpeg.P("sd")) / mps.setdash
- local rd = ( lpeg.P("rd")) / mps.resetdash
-
- local s = ( (cnumber * sp^0)^2 * lpeg.P("s") ) / mps.scale
- local t = (lpeg.P("[") * (cnumber * sp^0)^6 * lpeg.P("]") * sp * lpeg.P("t") ) / mps.concat
-
- -- experimental
-
- local attribute = ((cnumber * sp)^2 * lpeg.P("attribute")) / mps.attribute
- local A = ((cnumber * sp)^2 * lpeg.P("A")) / mps.attribute
-
- local preamble = (
- prolog + setup +
- boundingbox + highresboundingbox + specials + special +
- comment
- )
-
- local procset = (
- lj + ml + lc +
- c + l + m + n + p + r +
- A +
- R + C + G +
- S + F + B + W +
- vlw + hlw +
- Q + q +
- sd + rd +
- t + s +
- fshow +
- P
- )
-
- local verbose = (
- curveto + lineto + moveto + newpath + closepath + rlineto +
- setrgbcolor + setcmykcolor + setgray +
- attribute +
- setlinejoin + setmiterlimit + setlinecap +
- stroke + fill + clip + both +
- setlinewidth_x + setlinewidth_y +
- gsave + grestore +
- concat + scale +
- fshow +
- setdash + -- no resetdash
- showpage
- )
-
- -- order matters in terms of speed / we could check for procset first
-
- local captures_old = ( space + verbose + preamble )^0
- local captures_new = ( space + procset + preamble + verbose )^0
-
- function mptopdf.parsers.lpeg()
- if mptopdf.data:find("%%%%BeginResource: procset mpost") then
- captures_new:match(mptopdf.data)
- else
- captures_old:match(mptopdf.data)
- end
- end
+-- main converter
+function mptopdf.convertmpstopdf(name)
+ resetall()
+ local ok, m_data, n = resolvers.loadbinfile(name, 'tex') -- we need a binary load !
+ if ok then
+ statistics.starttiming(mptopdf)
+ mptopdf.n = mptopdf.n + 1
+ parse(m_data)
+ resetall()
+ statistics.stoptiming(mptopdf)
+ else
+ tex.print("file " .. name .. " not found")
+ end
end
-mptopdf.parser = 'lpeg'
+
+-- status info
+
+statistics.register("mps conversion time",function()
+ local n = mptopdf.n
+ if n > 0 then
+ return format("%s seconds, %s conversions", statistics.elapsedtime(mptopdf),n)
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/meta-pdf.mkii b/tex/context/base/meta-pdf.mkii
index d1a803604..2099b0d37 100644
--- a/tex/context/base/meta-pdf.mkii
+++ b/tex/context/base/meta-pdf.mkii
@@ -1,8 +1,8 @@
%D \module
%D [ file=meta-pdf,
%D version=2006.06.07,
-%D title=\CONTEXT\ Support Macros,
-%D subtitle=\METAPOST\ to \PDF\ conversion,
+%D title=\METAPOST\ Graphics,
+%D subtitle=Conversion to \PDF,
%D author=Hans Hagen \& others (see text),
%D date=\currentdate,
%D copyright=\PRAGMA]
@@ -11,12 +11,171 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D Formerly known as supp-pdf.tex and supp-mpe.tex.
+
+%D We will clean up the color mess later.
+
+%D These macros are written as generic as possible. Some
+%D general support macro's are loaded from a small module
+%D especially made for non \CONTEXT\ use. In this module I
+%D use a matrix transformation macro written by Tanmoy
+%D Bhattacharya. Thanks to extensive testing by Sebastian
+%D Ratz I was able to complete this module within reasonable
+%D time. This module has support for \METAPOST\ extensions
+%D built in.
+%D
+%D Daniel H. Luecking came up with a better (more precise)
+%D transformation method. You can recognize his comment by
+%D his initials. (We keep the old code around because it's a
+%D nice illustration on how a module like this evolves.)
+
+% Beware, we cannot use 0pt here by defaukt since it may be
+% defined in the range \dimen 0 - 20 which we happen to use
+% as scratch registers; for this reason we start allocating
+% scratch registers > 20
+
+%D This module handles some \PDF\ conversion and insertions
+%D topics. By default, the macros use the \PDFTEX\ primitive
+%D \type{\pdfliteral} when available. Since \PDFTEX\ is now the
+%D default engine for \TEX\ distributions, we need a more complex
+%D test.
+
+\writestatus{loading}{MetaPost Graphics / MPS to PDF}
+
\unprotect
-%D These are the main macros.
+\ifx\PDFcode \undefined \let\PDFcode \gobbleoneargument \fi
+\ifx\PDFcomment\undefined \def\PDFcomment#1{\PDFcode{\letterpercent\space#1}} \fi
+
+%D First we define a handy constant:
+
+\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup
+
+%D \macros
+%D {pdfimage,pdfimages,pdfclippedimage}
+%D
+%D Starting with pdftex version 14, images are included more
+%D natural to the form embedding. This enables alternative
+%D images to be embedded.
+%D
+%D \starttyping
+%D \pdfimage {file}
+%D \pdfimages {high res file} {low res file}
+%D \stoptyping
+%D
+%D The first one replaces the pre||version||14 original,
+%D while the latter provides alternative images.
+%D
+%D The next macro is dedicated to Maarten Gelderman, who
+%D needed to paste prepared \PDF\ pages into conference
+%D proceedings.
+%D
+%D \starttyping
+%D \pdfclippedimage {file} {l} {r} {t} {b}
+%D \stoptyping
+
+\ifx\pdftexversion\undefined \else \ifnum\pdftexversion>13 % still relevant?
+
+ \def\pdfimage#1#%
+ {\dopdfimage{#1}}
+
+ \def\dopdfimage#1#2%
+ {\immediate\pdfximage#1{#2}%
+ \pdfrefximage\pdflastximage}
+
+ \def\pdfimages#1#%
+ {\dopdfimages{#1}}
+
+ \def\dopdfimages#1#2#3%
+ {\immediate\pdfximage#1{#2}%
+ \immediate\pdfobj{[ << /Image \the\pdflastximage\space0 R /DefaultForPrinting true >> ]}%
+ \immediate\pdfximage#1 attr {/Alternates \the\pdflastobj\space0 R}{#3}%
+ \pdfrefximage\pdflastximage}
+
+ \def\pdfclippedimage#1#% specs {file}{left}{right}{top}{bottom}
+ {\dopdfclippedimage{#1}}
+
+ \def\dopdfclippedimage#1#2#3#4#5#6%
+ {\bgroup
+ \pdfximage#1{#2}%
+ \setbox\scratchbox\hbox{\pdfrefximage\pdflastximage}%
+ \hsize\dimexpr\wd\scratchbox-#3-#4\relax
+ \vsize\dimexpr\ht\scratchbox-#5-#6\relax
+ \setbox\scratchbox\vbox to \vsize
+ {\vskip-#5\hbox to \hsize{\hskip-#3\box\scratchbox\hss}}%
+ \pdfxform\scratchbox
+ \pdfrefxform\pdflastxform
+ \egroup}
-\def\mkconvertMPtoPDF % #1#2#3%
- {\vbox\bgroup
+\fi \fi
+
+%D \macros
+%D {convertMPtoPDF}
+%D
+%D The next set of macros implements \METAPOST\ to \PDF\
+%D conversion. The traditional method is in the MkII file.
+
+%D The main conversion command is:
+%D
+%D \starttyping
+%D \convertMPtoPDF {filename} {x scale} {y scale}
+%D \stoptyping
+%D
+%D The dimensions are derived from the bounding box. So we
+%D only have to say:
+%D
+%D \starttyping
+%D \convertMPtoPDF{mp-pra-1.eps}{1}{1}
+%D \convertMPtoPDF{mp-pra-1.eps}{.5}{.5}
+%D \stoptyping
+
+%D \macros
+%D {makeMPintoPDFobject,lastPDFMPobject}
+%D
+%D For experts there are a few more options. When attributes
+%D are to be added, the code must be embedded in an object
+%D accompanied with the appropriate directives. One can
+%D influence this process with \type {\makeMPintoPDFobject}.
+%D
+%D This option defaults to~0, because \CONTEXT\ takes care
+%D of objects at another level, which saves some bytes.
+%D
+%D \starttabulate[|l|l|p|]
+%D \NC 0 \NC never \NC don't use an object \NC\NR
+%D \NC 1 \NC always \NC always use an object \NC\NR
+%D \NC 2 \NC optional \NC use object when needed \NC\NR
+%D \stoptabulate
+%D
+%D The last object number used is avaliable in the macro
+%D \type {\lastPDFMPobject}.
+
+\ifx\makeMPintoPDFobject \undefined \chardef\makeMPintoPDFobject \zerocount \fi
+\ifx\blackoutMPgraphic \undefined \chardef\blackoutMPgraphic \plusone \fi
+\ifx\everyMPtoPDFconversion\undefined \newtoks\everyMPtoPDFconversion \fi
+
+\let\lastPDFMPobject \!!zerocount
+\let\currentPDFresources\empty
+\let\setMPextensions \relax
+
+\def\PDFMPformoffset
+ {\ifx\objectoffset\undefined\zeropoint\else\objectoffset\fi}
+
+\def\resetMPvariables#1#2#3%
+ {\global\let\MPwidth \!!zeropoint
+ \global\let\MPheight\!!zeropoint
+ \global\let\MPllx \!!zerocount
+ \global\let\MPlly \!!zerocount
+ \global\let\MPurx \!!zerocount
+ \global\let\MPury \!!zerocount
+ \xdef\MPxscale {#2}\ifx\MPxscale\empty\let\MPxscale\!!plusone\fi
+ \xdef\MPyscale {#3}\ifx\MPyscale\empty\let\MPyscale\!!plusone\fi
+ \xdef\MPfilename {#1}}
+
+%D The main macro:
+
+\def\convertMPtoPDF#1#2#3%
+ {\resetMPvariables{#1}{#2}{#3}%
+ \vbox\bgroup
\forgetall
\offinterlineskip
\ifx\pdfdecimaldigits\undefined\else \pdfdecimaldigits=5 \fi % new
@@ -31,6 +190,12 @@
\ifcase\blackoutMPgraphic\or\PDFcode{0 g 0 G}\fi
\doprocessMPtoPDFfile}
+\def\processMPtoPDFfile#1#2#3% obsolete
+ {\resetMPvariables{#1}{#2}{#3}%
+ \bgroup
+ \let\finishMPgraphic\egroup
+ \doprocessMPtoPDFfile}
+
\def\doprocessMPtoPDFfile
{\setMPspecials
\setMPextensions
@@ -64,16 +229,764 @@
\egroup
\endinput}
-\def\mkprocessMPtoPDFfile % file xscale yscale / obsolete
+%D A common hook.
+
+\let\MPfshowcommand\empty
+
+%D Objects.
+
+\def\dopackageMPgraphic#1% #1 = boxregister
+ {\ifcase\makeMPintoPDFobject\or\or\ifx\currentPDFresources\empty\else
+ % an existing value of 2 signals object support (set elsewhere)
+ \chardef\makeMPintoPDFobject\plusone
+ \fi\fi
+ \ifcase\makeMPintoPDFobject
+ \box#1%
+ \or
+ \scratchdimen\PDFMPformoffset\relax
+ \ifdim\scratchdimen>\zeropoint % compensate for error
+ \setbox#1\vbox spread 2\scratchdimen
+ {\forgetall\vss\hbox spread 2\scratchdimen{\hss\box#1\hss}\vss}%
+ \fi
+ \setMPPDFobject{\currentPDFresources}{#1}%
+ \ifdim\scratchdimen>\zeropoint % compensate for error
+ \vbox to \MPheight
+ {\forgetall\vss\hbox to \MPwidth{\hss\getMPPDFobject\hss}\vss}%
+ \else
+ \getMPPDFobject
+ \fi
+ \global\let\currentPDFresources\empty
+ \else
+ \box#1%
+ \fi}
+
+\def\setMPPDFobject#1#2% resources boxnumber
+ {\ifx\pdfxform\undefined
+ \def\getMPPDFobject{\box#2}%
+ \else\ifx\pdftexversion\undefined
+ \def\getMPPDFobject{\box#2}%
+ \else\ifnum\pdftexversion<14
+ \def\getMPPDFobject{\box#2}%
+ \else
+ \ifx\everyPDFxform\undefined\else\the\everyPDFxform\fi
+ \immediate\pdfxform resources{#1}#2%
+ \edef\getMPPDFobject{\noexpand\pdfrefxform\the\pdflastxform}%
+ \fi\fi\fi}
+
+\let\getMPPDFobject\relax
+
+%D \macros
+%D {deleteMPgraphic,
+%D startMPresources,
+%D stopMPresources}
+
+\ifx\deleteMPgraphic\undefined
+ \def\deleteMPgraphic#1{}
+\fi
+
+\ifx\startMPresources\undefined
+ \let\startMPresources\relax
+ \let\stopMPresources\relax
+\fi
+
+%D We implement extensions by using the \METAPOST\ special
+%D mechanism. Opposite to \TEX's specials, the \METAPOST\ ones
+%D are flushed before or after the graphic data, but thereby
+%D are no longer connected to a position.
+%D
+%D We implement specials by overloading the \type {fill}
+%D operator. By counting the fills, we can let the converter
+%D treat the appropriate fill in a special way. The
+%D specification of the speciality can have two forms,
+%D determined by the setting of a boolean variable:
+%D
+%D \starttyping
+%D _inline_specials_ := false ; % comment like code (default)
+%D _inline_specials_ := true ; % command like code
+%D \stoptyping
+%D
+%D When the specification is embedded as comment, it looks
+%D like:
+%D
+%D \starttyping
+%D %%MetaPostSpecial
+%D \stoptyping
+%D
+%D The in||line alternative is more tuned for \POSTSCRIPT,
+%D since it permits us to define a macro \type {special}.
+%D
+%D \starttyping
+%D inline : special
+%D \stoptyping
+%D
+%D The \type {identifier} determines what to do, and the data
+%D can be used to accomplish this. A type~2 shading function
+%D has identifier~2. Alltogether, the number of parameters is
+%D specified in \type {size}. The \type {number} is the number
+%D of the fill that needs the special treatment. For a type~2
+%D and~3 shaded fill, the datablock contains the following
+
+%D data:
+%D
+%D \starttyping
+%D from to n inner_r g b x y outer_r g b x y
+%D from to n inner_r g b x y radius outer_r g b x y radius
+%D \stoptyping
+
+\newconditional\manyMPspecials \settrue\manyMPspecials
+
+%D In case of \PDF, we need to prepare resourcs.
+
+\newtoks\MPstartresources
+\newtoks\MPstopresources
+
+\def\startMPresources
+ {\the\MPstartresources}
+
+\def\stopMPresources
+ {\the\MPstopresources}
+
+%D Some day we may consider collecting local resources.
+
+\appendtoks
+ \global\let\currentPDFresources\empty % kind of redundant
+\to \MPstartresources
+
+% \appendtoks
+% \collectPDFresources
+% \global\let\currentPDFresources\collectedPDFresources
+% \to \MPstopresources
+
+\appendtoksonce
+ \the\everyPDFxform
+\to \MPstopresources
+
+%D Since colors are not subjected to transformations, we can
+%D only use colors as signal. In our case, we use a dummy colored
+%D path with a red color component of \type {0.n}, so \type
+%D {0.001} is the first path and \type {0.010} the tenth. Since
+%D \METAPOST strips trailing zeros, we have to padd the string.
+
+\newif\ifMPcmykcolors
+\newif\ifMPspotcolors
+
+\def\dohandleMPrgb #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
+\def\dohandleMPcmyk#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
+\def\dohandleMPgray #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
+\def\dohandleMPspot#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
+
+%D Specials:
+
+\settrue \manyMPspecials \newcount\nofMParguments \let\extraMPpathcode\empty
+
+\def\@@MP {@@MP}
+\def\@@MPSK{@MPSK@}
+
+\def\MPspecial{\@@MPSK\@@MPSK\gMPs\nofMParguments}
+
+\def\defineMPspecial#1#2%
+ {\setvalue{\@@MPSK\@@MPSK#1}{#2}}
+
+%D Special number~1 is dedicated to \CMYK\ support. If you
+%D want to know why: look at this:
+%D
+%D \startbuffer[mp]
+%D fill fullcircle xyscaled (3cm,1cm) withcolor \MPcolor{test} ;
+%D \stopbuffer
+%D
+%D \startbuffer[cmyk]
+%D \startcombination[4*1]
+%D {\definecolor[test][c=1,y=.3,k=.3] \processMPbuffer[mp]} {c=1 y=.3 k=.3}
+%D {\definecolor[test][c=.9,y=.15] \processMPbuffer[mp]} {c=.9 y=.15}
+%D {\definecolor[test][c=.25,y=.8] \processMPbuffer[mp]} {c=.25 y=.8}
+%D {\definecolor[test][c=.45,y=.1] \processMPbuffer[mp]} {c=.45 y=.1}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \placefigure
+%D {\CMYK\ support disabled,
+%D conversion to \RGB.}
+%D {\setupcolors[cmyk=nee,state=start]\getbuffer[cmyk]}
+%D
+%D \placefigure
+%D {\CMYK\ support enabled,
+%D no support in \METAPOST.}
+%D {\setupcolors[cmyk=ja,mpcmyk=nee,state=start]\getbuffer[cmyk]}
+%D
+%D \placefigure
+%D {\CMYK\ support enabled,
+%D no conversion to \RGB,
+%D support in \METAPOST}
+%D {\setupcolors[cmyk=ja,state=start]\getbuffer[cmyk]}
+
+\defineMPspecial{1}
+ {\ifMPcmykcolors
+ \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPcmykcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
+ \fi}
+
+\defineMPspecial{2}
+ {\ifMPspotcolors
+ \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPspotcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
+% \checkMPspot{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}%
+ \fi}
+
+% \def\checkMPspot#1#2#3#4%
+% {\expanded{\resolveMPspotcolor#1 #2 #3 #4}\end
+% \ifx\MPspotspace\MPresolvedspace
+% \edef\MPspotspacespec{/\MPspotspace\space}%
+% \doifinstringelse\MPspotspacespec\currentMPcolorspaces
+% \donothing\registerMPcolorspace
+% \fi}
+
+\let\revokeMPtransparencyspecial\relax
+
+\def\dohandleMPrgbcolor #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
+\def\dohandleMPcmykcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
+\def\dohandleMPgraycolor #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
+\def\dohandleMPspotcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
+
+%D Transparency support used specials 60 (rgb) and 61
+%D (cmyk).
+%D
+%D \startbufferFshade
+
+%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
+%D
+%D fill p rotated 90 withcolor transparent(1,.5,yellow) ;
+%D fill p rotated 210 withcolor transparent(1,.5,green) ;
+%D fill p rotated 330 withcolor transparent(1,.5,blue) ;
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection \processMPbuffer \stoplinecorrection
+%D
+%D One can also communicate colors between \CONTEXT\ and
+%D \METAPOST:
+%D
+%D \startbuffer
+%D \definecolor[tcyan] [c=1,k=.2,t=.5]
+%D \definecolor[tmagenta][m=1,k=.2,t=.5]
+%D \definecolor[tyellow] [y=1,k=.2,t=.5]
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
+%D
+%D fill p rotated 90 withcolor \MPcolor{tcyan} ;
+%D fill p rotated 210 withcolor \MPcolor{tmagenta} ;
+%D fill p rotated 330 withcolor \MPcolor{tyellow} ;
+%D \stopbuffer
+%D
+%D \startlinecorrection \processMPbuffer \stoplinecorrection
+%D
+%D We save all the three components needed in one macro,
+%D just to save hash space.
+
+\def\dohandleMPrgbtransparency #1#2#3#4#5{\execcolorR #1:#2:#3:#4:#5\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPcmyktransparency#1#2#3#4#5#6{\execcolorC#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPgraytransparency #1#2#3{\execcolorS #1:#2:#3\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPspottransparency#1#2#3#4#5#6{\execcolorP#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+
+\def\dorevokeMPtransparencyspecial
+ {\PDFcode{\PDFtransparencyresetidentifier\space gs}%
+ \let\revokeMPtransparencyspecial\relax}
+
+\defineMPspecial{3} % rgb
+ {\setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPrgbtransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs1}{\gMPs2}}}
+
+\defineMPspecial{4} % cmyk
+ {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPcmyktransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}}
+
+\defineMPspecial{5} % spot
+ {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPspottransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}%
+ }%\checkMPspot{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}
+
+%D Shading is an example of a more advanced graphic feature,
+%D but users will seldom encounter those complications. Here
+%D we only show a few simple examples, but many other
+%D alternatives are possible by setting up the functions built
+%D in \PDF\ in the appropriate way.
+%D
+%D Shading has to do with interpolation between two or more
+%D points or user supplied ranges. In \PDF, the specifications
+%D of a shade has to be encapsulated in objects and passed on
+%D as resources. This is a \PDF\ level 1.3. feature. One can
+%D simulate three dimensional shades as well and define simple
+%D functions using a limited set of \POSTSCRIPT\ primitives.
+%D Given the power of \METAPOST\ and these \PDF\ features, we
+%D can achieve superb graphic effects.
+%D
+%D Since everything is hidden in \TEX\ and \METAPOST\ graphics,
+%D we can stick to high level \CONTEXT\ command, as shown in
+%D the following exmples.
+%D
+%D \startbuffer
+%D \startuniqueMPgraphic{CircularShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D circular_shade(p,0,.2red,.9red) ;
+%D \stopuniqueMPgraphic
+%D
+%D \startuniqueMPgraphic{LinearShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D linear_shade(p,0,.2blue,.9blue) ;
+%D \stopuniqueMPgraphic
+%D
+%D \startuniqueMPgraphic{DuotoneShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D linear_shade(p,2,.5green,.5red) ;
+%D \stopuniqueMPgraphic
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D These graphics can be hooked into the overlay mechanism,
+%D which is available in many commands.
+%D
+%D \startbuffer
+%D \defineoverlay[demo 1][\uniqueMPgraphic{CircularShade}]
+%D \defineoverlay[demo 2][\uniqueMPgraphic {LinearShade}]
+%D \defineoverlay[demo 3][\uniqueMPgraphic {DuotoneShade}]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D These backgrounds can for instance be applied to \type
+%D {\framed}:
+%D
+%D \startbuffer
+%D \setupframed[width=3cm,height=2cm,frame=off]
+%D \startcombination[3*1]
+%D {\framed[backgroundachtergrond=demo 1]{\bfd \white Demo 1}} {}
+%D {\framed[backgroundachtergrond=demo 2]{\bfd \white Demo 2}} {}
+%D {\framed[backgroundachtergrond=demo 3]{\bfd \white Demo 3}} {}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D There are a few more alternatives, determined by the second
+%D parameter passed to \type {circular_shade} and alike.
+%D
+%D \def\SomeShade#1#2#3#4#5%
+%D {\startuniqueMPgraphic{Shade-#1}
+%D width := \overlaywidth ;
+%D height := \overlayheight ;
+%D path p ; p := unitsquare xscaled width yscaled height ;
+%D #2_shade(p,#3,#4,#5) ;
+%D \stopuniqueMPgraphic
+%D \defineoverlay[Shade-#1][\uniqueMPgraphic{Shade-#1}]%
+%D \framed[backgroundachtergrond=Shade-#1,width=2cm,height=2cm,frame=off]{}}
+%D
+%D \startlinecorrection
+%D \startcombination[5*1]
+%D {\SomeShade{10}{circular}{0}{.3blue}{.9blue}} {circular 0}
+%D {\SomeShade{11}{circular}{1}{.3blue}{.9blue}} {circular 1}
+%D {\SomeShade{12}{circular}{2}{.3blue}{.9blue}} {circular 2}
+%D {\SomeShade{13}{circular}{3}{.3blue}{.9blue}} {circular 3}
+%D {\SomeShade{14}{circular}{4}{.3blue}{.9blue}} {circular 4}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D \blank
+%D
+%D \startlinecorrection
+%D \startcombination[5*1]
+%D {\SomeShade{20}{circular}{0}{.9green}{.3green}} {circular 0}
+%D {\SomeShade{21}{circular}{1}{.9green}{.3green}} {circular 1}
+%D {\SomeShade{22}{circular}{2}{.9green}{.3green}} {circular 2}
+%D {\SomeShade{23}{circular}{3}{.9green}{.3green}} {circular 3}
+%D {\SomeShade{24}{circular}{4}{.9green}{.3green}} {circular 4}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D \blank
+%D
+%D \startlinecorrection
+%D \startcombination[4*1]
+%D {\SomeShade{30}{linear}{0}{.3red}{.9red}} {linear 0}
+%D {\SomeShade{31}{linear}{1}{.3red}{.9red}} {linear 1}
+%D {\SomeShade{32}{linear}{2}{.3red}{.9red}} {linear 2}
+%D {\SomeShade{33}{linear}{3}{.3red}{.9red}} {linear 3}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D These macros closely cooperate with the \METAPOST\ module
+%D \type {mp-spec.mp}, which is part of the \CONTEXT\
+%D distribution.
+%D
+%D The low level (\PDF) implementation is based on the \TEX\
+%D based \METAPOST\ to \PDF\ converter. Shading is supported
+%D by overloading the \type {fill} operator as implemented
+%D earlier. In \PDF\ type~2 and~3 shading functions are
+%D specified in terms of:
+%D
+%D \starttabulate[|Tl|l|]
+%D \NC /Domain \NC sort of meeting range \NC \NR
+%D \NC /C0 \NC inner shade \NC \NR
+%D \NC /C1 \NC outer shade \NC \NR
+%D \NC /N \NC smaller values, bigger inner circles \NC \NR
+%D \stoptabulate
+
+\newcount\currentPDFshade % 0 % global (document wide) counter
+
+% \def\dosetMPsomePDFshade#1#2% generic but needs refs
+% {\global\advance\currentPDFshade \plusone
+% \doPDFdictionaryobject{FDF}{ftn:Sh:\the\currentPDFshade}
+% {/FunctionType 2
+% /Domain [\gMPs1 \gMPs2]
+% /C0 [\MPshadeA]
+% /C1 [\MPshadeB]
+% /N \gMPs3}%
+% \doPDFgetobjectreference{FDF}{ftn:Sh:\the\currentPDFshade}\PDFobjectreference
+% \doPDFdictionaryobject{FDF}{obj:Sh:\the\currentPDFshade}
+% {/ShadingType #1
+% /ColorSpace /\MPresolvedspace
+% /Function \PDFobjectreference\space
+% /Coords [\MPshadeC]
+% /Extend [true true]}%
+% \doPDFgetobjectreference{FDF}{obj:Sh:\the\currentPDFshade}\PDFobjectreference
+% \appendtoPDFdocumentshades{/Sh\the\currentPDFshade\space\PDFobjectreference}%
+% \setxvalue{\@@MPSK#2}{\noexpand\dohandleMPshade{\the\currentPDFshade}}}
+
+\def\dosetMPsomePDFshade#1#2%
+ {\immediate\pdfobj
+ {<>}%
+ \immediate\pdfobj
+ {<>}%
+ \global\advance\currentPDFshade \plusone
+ \appendtoPDFdocumentshades{/Sh\the\currentPDFshade\space\the\pdflastobj\space0 R }%
+ \setxvalue{\@@MPSK#2}{\noexpand\dohandleMPshade{\the\currentPDFshade}}}
+
+\def\dosetMPlinearshade {\dosetMPsomePDFshade2}% #1
+\def\dosetMPcircularshade{\dosetMPsomePDFshade3}% #1
+
+\defineMPspecial{30}
+ {\expanded{\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
+ \expanded{\resolveMPrgbcolor{\gMPs{9}}{\gMPs{10}}{\gMPs{11}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs{12} \gMPs{13}}%
+ \dosetMPlinearshade{\gMPs{14}}}
+
+\defineMPspecial{31}
+ {\expanded{\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
+ \expanded{\resolveMPrgbcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs9 \gMPs{13} \gMPs{14} \gMPs{15}}%
+ \dosetMPcircularshade{\gMPs{16}}}
+
+\defineMPspecial{32}
+ {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \expanded{\resolveMPcmykcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
+ \dosetMPlinearshade{\gMPs{16}}}
+
+\defineMPspecial{33}
+ {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \expanded{\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
+ \dosetMPcircularshade{\gMPs{18}}}
+
+\defineMPspecial{34}
+ {\expanded{\resolveMPspotcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \expanded{\resolveMPspotcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
+ \dosetMPlinearshade{\gMPs{16}}}
+
+\defineMPspecial{35}
+ {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \expanded{\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
+ \dosetMPcircularshade{\gMPs{18}}}
+
+
+\newconditional\ignoreMPpath
+
+\def\dohandleMPshade#1%
+ {\revokeMPtransparencyspecial
+ \settrue\ignoreMPpath
+ \def\extraMPpathcode{/Sh#1 sh Q}%
+ \chardef\finiMPpath\zerocount
+ \PDFcode{q /Pattern cs}}
+
+%D Figure inclusion is kind of strange to \METAPOST, but when
+%D Santiago Muelas started discussing this with me, I was able
+%D to cook up a solution using specials.
+
+\defineMPspecial{10}
+ {\setxvalue{\@@MPSK\gMPs8}%
+ {\noexpand\handleMPfigurespecial{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}{\gMPs8}}}
+
+\def\handleMPfigurespecial#1#2#3#4#5#6#7#8% todo : combine with ext fig
+ {\global\letvalue{\@@MPSK#8}\empty
+ \vbox to \zeropoint
+ {\vss
+ \hbox to \zeropoint
+ {\ifcase\pdfoutput\or % will be hooked into the special driver
+ \doiffileelse{#7}
+ {\doifundefinedelse{mps:x:#7}
+ {\immediate\pdfximage\!!width\onebasepoint\!!height\onebasepoint{#7}%
+ \setxvalue{mps:x:#7}{\pdfrefximage\the\pdflastximage}}%
+ {\message{[reusing figure #7]}}%
+ \PDFcode{q #1 #2 #3 #4 #5 #6 cm}%
+ \rlap{\getvalue{mps:x:#7}}%
+ \PDFcode{Q}}
+ {\message{[unknown figure #7]}}%
+ \fi
+ \hss}}}
+
+%D An example of using both special features is the
+%D following.
+%D
+%D \starttyping
+%D \startMPpage
+%D externalfigure "hakker1b.png" scaled 22cm rotated 10 shifted (-2cm,0cm);
+%D externalfigure "hakker1b.png" scaled 10cm rotated -10 ;
+%D externalfigure "hakker1b.png" scaled 7cm rotated 45 shifted (8cm,12cm) ;
+%D path p ; p := unitcircle xscaled 15cm yscaled 20cm;
+%D path q ; q := p rotatedaround(center p,90) ;
+%D path r ; r := buildcycle(p,q) ; clip currentpicture to r ;
+%D path s ; s := boundingbox currentpicture enlarged 5mm ;
+%D picture c ; c := currentpicture ; currentpicture := nullpicture ;
+%D circular_shade(s,0,.2red,.9red) ;
+%D addto currentpicture also c ;
+%D \stopMPpage
+%D \stoptyping
+
+%D This is some experimental hyperlink driver that I wrote
+%D for Mark Wicks.
+
+\defineMPspecial{20}
+ {\setxvalue{\@@MPSK\gMPs6}%
+ {\noexpand\handleMPhyperlink{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}}
+
+\def\handleMPhyperlink#1#2#3#4#5#6%
+ {\global\letvalue{\@@MPSK#6}\empty
+ \setbox\scratchbox\hbox
+ {\setbox\scratchbox\null
+ \wd\scratchbox\dimexpr-#1\onebasepoint+#3\onebasepoint\relax
+ \ht\scratchbox\dimexpr-#2\onebasepoint+#4\onebasepoint\relax
+ \incolorfalse
+ \gotobox{\box\scratchbox}[#5]}%
+ \setbox\scratchbox\hbox
+ {\hskip\dimexpr\MPxoffset\onebasepoint+#1\onebasepoint\relax
+ \raise\dimexpr\MPyoffset\onebasepoint+#2\onebasepoint\relax
+ \box\scratchbox}%
+ \smashbox\scratchbox
+ \box\scratchbox}
+
+%D This special (number 50) passes positions to a tex file.
+%D This method uses a two||pass approach an (mis|)|used the
+%D context positioning macros. In \type {core-pos} we will
+%D implement the low level submacro needed.
+%D
+%D \startbuffer
+%D \definelayer[test]
+%D
+%D \setlayer
+%D [test]
+%D [x=\MPx{somepos-1},y=\MPy{somepos-1}]
+%D {Whatever we want here!}
+%D
+%D \setlayer
+%D [test]
+%D [x=\MPx{somepos-2},y=\MPy{somepos-2}]
+%D {Whatever we need there!}
+%D
+%D \startuseMPgraphic{oeps}
+%D draw fullcircle scaled 6cm withcolor red ;
+%D register ("somepos-1",1cm,2cm,center currentpicture) ;
+%D register ("somepos-2",4cm,3cm,(-1cm,-2cm)) ;
+%D \stopuseMPgraphic
+%D
+%D \framed[background=test,offset=overlay]{\useMPgraphic{oeps}}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D Here the width and height are not realy used, but one can
+%D imagine situations where tex has to work with values
+%D calculated by \METAPOST.
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D Later we will implement a more convenient macro:
+%D
+%D \starttyping
+%D \setMPlayer [test] [somepos-1] {Whatever we want here!}
+%D \setMPlayer [test] [somepos-2] {Whatever we need there!}
+%D \stoptyping
+
+\defineMPspecial{50} % x y width height label
+ {\dosavepositionwhd
+ {\gMPs5}%
+ {0}%
+ {\the\dimexpr-\MPllx\onebasepoint+\gMPs1\onebasepoint\relax}
+ {\the\dimexpr\gMPs2\onebasepoint-\scratchdimen+\MPury\onebasepoint\relax}%
+ {\the\dimexpr\gMPs3\onebasepoint\relax}%
+ {\the\dimexpr\gMPs4\onebasepoint\relax}%
+ {0pt}}
+
+%D A few auxiliary macros. This will move to colo-ini.
+
+\def\MPgrayspace{DeviceGray}
+\def\MPrgbspace {DeviceRGB}
+\def\MPcmykspace{DeviceCMYK}
+\let\MPspotspace\MPgrayspace
+
+\def\MPcmykBlack{0 0 0 0}
+\def\MPcmykWhite{0 0 0 1}
+
+\def\startMPcolorresolve
{\bgroup
- \let\finishMPgraphic\egroup
- \doprocessMPtoPDFfile}
+ \def\dostartgraycolormode##1%
+ {\global\let\MPresolvedspace\MPgrayspace
+ \xdef\MPresolvedcolor{##1}}%
+ \def\dostartrgbcolormode ##1##2##3%
+ {\global\let\MPresolvedspace\MPrgbspace
+ \xdef\MPresolvedcolor{##1 ##2 ##3}}%
+ \def\dostartcmykcolormode##1##2##3##4%
+ {\global\let\MPresolvedspace\MPcmykspace
+ \xdef\MPresolvedcolor{##1 ##2 ##3 ##4}}%
+ \def\dostartspotcolormode##1##2%
+ {\global\let\MPspotspace\empty % left over ?
+ \xdef\MPresolvedspace{##1}%
+ \xdef\MPresolvedcolor{##2}%
+ \global\let\MPspotspace\MPresolvedspace}% signal
+ \dostartgraycolormode\!!zerocount} % kind of hackery initialization
+
+\let\stopMPcolorresolve\egroup
+
+\def\resolveMPrgbcolor#1#2#3\to#4%
+ {\startMPcolorresolve
+ \execcolorR#1:#2:#3:0:0\od
+ \stopMPcolorresolve
+ \let#4\MPresolvedcolor}
+
+\def\resolveMPcmykcolor#1#2#3#4\to#5%
+ {\startMPcolorresolve
+ \execcolorC#1:#2:#3:#4:0:0\od
+ \stopMPcolorresolve
+ \let#5\MPresolvedcolor}
+
+\def\resolveMPgraycolor#1\end\to#2%
+ {\startMPcolorresolve
+ \execcolorS#1:0:0\od
+ \stopMPcolorresolve
+ \let#2\MPresolvedcolor}
+
+\def\resolveMPspotcolor#1#2#3#4\end\to#5%
+ {\startMPcolorresolve
+ \ifnum#2>\plusone
+ \checkmultitonecolor{#1}%
+ \fi
+ \execcolorP#1:#2:#3:#4:0:0\od
+ \stopMPcolorresolve
+ \let#5\MPresolvedcolor}
+
+%D \macros
+%D {dogetPDFmediabox}
+%D
+%D The next macro can be used to find the mediabox of a \PDF\
+%D illustration.
+%D
+%D \starttyping
+%D \dogetPDFmediabox
+%D {filename}
+%D {new dimen}{new dimen}{new dimen}{new dimen}
+%D \stoptyping
+%D
+%D Beware of dimen clashes: this macro uses the 5~default
+%D scratch registers! When no file or mediabox is found, the
+%D dimensions are zeroed.
+\def\dogetPDFmediabox#1#2#3#4#5%
+ {\bgroup
+ \def\PDFxscale{1}%
+ \def\PDFyscale{1}%
+ \uncatcodespecials
+ \endlinechar\minusone
+ \def\checkPDFtypepage##1/Type /Page##2##3\done%
+ {\ifx##2\relax
+ \else\if##2s% accept /Page and /Pages
+ \let\doprocessPDFline\findPDFmediabox
+ \else
+ \let\doprocessPDFline\findPDFmediabox
+ \fi\fi}%
+ \def\findPDFtypepage
+ {\expandafter\checkPDFtypepage\fileline/Type /Page\relax\done}%
+ \def\checkPDFmediabox##1/MediaBox##2##3\done%
+ {\ifx##2\relax \else
+ \setPDFmediabox##2##3\done
+ \fileprocessedtrue
+ \fi}%
+ \def\findPDFmediabox
+ {\expandafter\checkPDFmediabox\fileline/MediaBox\relax\done}%
+ \let\doprocessPDFline\findPDFtypepage
+ \doprocessfile\scratchread{#1}\doprocessPDFline
+ \egroup
+ \ifx\PDFxoffset\undefined
+ #2=\zeropoint
+ #3=\zeropoint
+ #4=\zeropoint
+ #5=\zeropoint
+ \else
+ #2=\PDFxoffset\onebasepoint
+ #3=\PDFyoffset\onebasepoint
+ #4=\PDFwidth
+ #5=\PDFheight
+ \fi}
+
+\def\setPDFboundingbox#1#2#3#4#5#6%
+ {\dimen0=#1\dimen0=#5\dimen0
+ \ScaledPointsToBigPoints{\number\dimen0}\PDFxoffset
+ \dimen0=#3\dimen0=#5\dimen0
+ \xdef\PDFwidth{\the\dimen0}%
+ \dimen0=#2\dimen0=#6\dimen0
+ \ScaledPointsToBigPoints{\number\dimen0}\PDFyoffset
+ \dimen0=#4\dimen0=#6\dimen0
+ \xdef\PDFheight{\the\dimen0}%
+ \global\let\PDFxoffset\PDFxoffset
+ \global\let\PDFyoffset\PDFyoffset}
+
+\def\setPDFmediabox#1[#2 #3 #4 #5]#6\done
+ {\dimen2=#2\onebasepoint\dimen2=-\dimen2 % \dimen2=-#2\onebasepoint also works since tex handles --
+ \dimen4=#3\onebasepoint\dimen4=-\dimen4 % \dimen4=-#3\onebasepoint also works since tex handles --
+ \dimen6=#4\onebasepoint\advance\dimen6 \dimen2
+ \dimen8=#5\onebasepoint\advance\dimen8 \dimen4
+ \setPDFboundingbox{\dimen2}{\dimen4}{\dimen6}{\dimen8}\PDFxscale\PDFyscale}
+
+%D End of soon obsolete code.
+
+\startMPinitializations
+ mp_shade_version := 2 ;
+\stopMPinitializations
+
+%D Here comes the traditional \MKII\ converter.
+%D
%D Because we want to test as fast as possible, we first
%D define the \POSTSCRIPT\ operators that \METAPOST\ uses.
%D We don't define irrelevant ones, because these are
%D skipped anyway.
-
+%D
%D The converter can be made a bit faster by replacing the
%D two test macros (the ones with the many \type {\if's}) by
%D a call to named branch macros (something \typ {\getvalue
@@ -1215,9 +2128,6 @@
%D
%D But, this one is still too inaccurate, so we now have:
-%D We cannot use \type {\beginETEX} here since in plain we
-%D get \type {\outer} problems, sigh.
-
%D DHL: Ideally, $r_x$, $r_y$, $s_x$, $s_y$ should be in macros, not
%D dimensions (they are scalar quantities after all, not lengths). I
%D suppose the authors decided to do calculations with integer
@@ -1726,7 +2636,7 @@
{\ifcase\inlineMPspecials\or
\advance\nofMParguments \minusone % pop the size
\fi
- \ifundefined\MPspecial
+ \ifundefined\MPspecial % beware, no real \if
\message{[unknown \MPspecial]}%
\else
\csname\MPspecial\endcsname
diff --git a/tex/context/base/meta-pdf.mkiv b/tex/context/base/meta-pdf.mkiv
index eded7d59d..23981815c 100644
--- a/tex/context/base/meta-pdf.mkiv
+++ b/tex/context/base/meta-pdf.mkiv
@@ -1,8 +1,8 @@
%D \module
%D [ file=meta-pdf,
-%D version=2006.29.09,
-%D title=\CONTEXT\ Support Macros,
-%D subtitle=\METAPOST\ to \PDF\ conversion,
+%D version=2006.06.07,
+%D title=\METAPOST\ Graphics,
+%D subtitle=Conversion to \PDF,
%D author=Hans Hagen \& others (see text),
%D date=\currentdate,
%D copyright=\PRAGMA]
@@ -11,10 +11,8 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\unprotect
+%D Formerly known as supp-pdf.tex and supp-mpe.tex.
-% Using test case at end of meta-pdf.tex:
-%
% \useMPgraphic{1}
% \testfeatureonce{250}{\setbox0\hbox{\convertMPtoPDF{test-mps-mpgraph.1}{1}{1}}}
%
@@ -26,10 +24,86 @@
\registerctxluafile{meta-pdf}{1.003}
-%D Plugin.
+%D We will clean up the color mess later.
+
+\writestatus{loading}{MetaPost Graphics / MPS to PDF}
+
+\unprotect
+
+\ifx\PDFcode \undefined \let\PDFcode \gobbleoneargument \fi
+\ifx\PDFcomment\undefined \def\PDFcomment#1{\PDFcode{\letterpercent\space#1}} \fi
+
+%D First we define a handy constant:
+
+\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup
+
+%D \macros
+%D {convertMPtoPDF}
+%D
+%D The next set of macros implements \METAPOST\ to \PDF\
+%D conversion. The traditional method is in the MkII file.
+%D
+%D The main conversion command is:
+%D
+%D \starttyping
+%D \convertMPtoPDF {filename} {x scale} {y scale}
+%D \stoptyping
+%D
+%D The dimensions are derived from the bounding box. So we
+%D only have to say:
+%D
+%D \starttyping
+%D \convertMPtoPDF{mp-pra-1.eps}{1}{1}
+%D \convertMPtoPDF{mp-pra-1.eps}{.5}{.5}
+%D \stoptyping
+
+%D \macros
+%D {makeMPintoPDFobject,lastPDFMPobject}
+%D
+%D For experts there are a few more options. When attributes
+%D are to be added, the code must be embedded in an object
+%D accompanied with the appropriate directives. One can
+%D influence this process with \type {\makeMPintoPDFobject}.
+%D
+%D This option defaults to~0, because \CONTEXT\ takes care
+%D of objects at another level, which saves some bytes.
+%D
+%D \starttabulate[|l|l|p|]
+%D \NC 0 \NC never \NC don't use an object \NC\NR
+%D \NC 1 \NC always \NC always use an object \NC\NR
+%D \NC 2 \NC optional \NC use object when needed \NC\NR
+%D \stoptabulate
+%D
+%D The last object number used is avaliable in the macro
+%D \type {\lastPDFMPobject}.
+
+\ifx\makeMPintoPDFobject \undefined \chardef\makeMPintoPDFobject \zerocount \fi
+\ifx\blackoutMPgraphic \undefined \chardef\blackoutMPgraphic \plusone \fi
+\ifx\everyMPtoPDFconversion\undefined \newtoks\everyMPtoPDFconversion \fi
+
+\let\lastPDFMPobject \!!zerocount
+\let\currentPDFresources\empty
+\let\setMPextensions \relax
+
+\def\PDFMPformoffset
+ {\ifx\objectoffset\undefined\zeropoint\else\objectoffset\fi}
-\def\mkconvertMPtoPDF % watch the transparency reset
- {\vbox\bgroup
+\def\resetMPvariables#1#2#3%
+ {\global\let\MPwidth \!!zeropoint
+ \global\let\MPheight\!!zeropoint
+ \global\let\MPllx \!!zerocount
+ \global\let\MPlly \!!zerocount
+ \global\let\MPurx \!!zerocount
+ \global\let\MPury \!!zerocount
+ \xdef\MPxscale {#2}\ifx\MPxscale\empty\let\MPxscale\!!plusone\fi
+ \xdef\MPyscale {#3}\ifx\MPyscale\empty\let\MPyscale\!!plusone\fi
+ \xdef\MPfilename {#1}}
+
+%D The main macro:
+
+\def\convertMPtoPDF#1#2#3% watch the transparency reset
+ {\resetMPvariables{#1}{#2}{#3}%
+ \vbox\bgroup
\forgetall
\offinterlineskip
%\ifcase\blackoutMPgraphic\or\PDFcode{0 g 0 G}\fi % fixed in mp
@@ -61,19 +135,657 @@
\dopackageMPgraphic\scratchbox
\egroup}
-\let\mkprocessMPtoPDFfile\mkconvertMPtoPDF
+\let\processMPtoPDFfile\convertMPtoPDF
+
+%D A common hook.
+
+\let\MPfshowcommand\empty
+
+%D Objects.
+
+\def\dopackageMPgraphic#1% #1 = boxregister
+ {\ifcase\makeMPintoPDFobject\or\or\ifx\currentPDFresources\empty\else
+ % an existing value of 2 signals object support (set elsewhere)
+ \chardef\makeMPintoPDFobject\plusone
+ \fi\fi
+ \ifcase\makeMPintoPDFobject
+ \box#1%
+ \or
+ \scratchdimen\PDFMPformoffset\relax
+ \ifdim\scratchdimen>\zeropoint % compensate for error
+ \setbox#1\vbox spread 2\scratchdimen
+ {\forgetall\vss\hbox spread 2\scratchdimen{\hss\box#1\hss}\vss}%
+ \fi
+ \setMPPDFobject{\currentPDFresources}{#1}%
+ \ifdim\scratchdimen>\zeropoint % compensate for error
+ \vbox to \MPheight
+ {\forgetall\vss\hbox to \MPwidth{\hss\getMPPDFobject\hss}\vss}%
+ \else
+ \getMPPDFobject
+ \fi
+ \global\let\currentPDFresources\empty
+ \else
+ \box#1%
+ \fi}
+
+\def\setMPPDFobject#1#2% resources boxnumber
+ {\ifx\pdfxform\undefined
+ \def\getMPPDFobject{\box#2}%
+ \else\ifx\pdftexversion\undefined
+ \def\getMPPDFobject{\box#2}%
+ \else\ifnum\pdftexversion<14
+ \def\getMPPDFobject{\box#2}%
+ \else
+ \ifx\everyPDFxform\undefined\else\the\everyPDFxform\fi
+ \immediate\pdfxform resources{#1}#2%
+ \edef\getMPPDFobject{\noexpand\pdfrefxform\the\pdflastxform}%
+ \fi\fi\fi}
+
+\let\getMPPDFobject\relax
+
+%D \macros
+%D {deleteMPgraphic,
+%D startMPresources,
+%D stopMPresources}
+
+\ifx\deleteMPgraphic\undefined
+ \def\deleteMPgraphic#1{}
+\fi
+
+\ifx\startMPresources\undefined
+ \let\startMPresources\relax
+ \let\stopMPresources\relax
+\fi
+
+%D We implement extensions by using the \METAPOST\ special
+%D mechanism. Opposite to \TEX's specials, the \METAPOST\ ones
+%D are flushed before or after the graphic data, but thereby
+%D are no longer connected to a position.
+%D
+%D We implement specials by overloading the \type {fill}
+%D operator. By counting the fills, we can let the converter
+%D treat the appropriate fill in a special way. The
+%D specification of the speciality can have two forms,
+%D determined by the setting of a boolean variable:
+%D
+%D \starttyping
+%D _inline_specials_ := false ; % comment like code (default)
+%D _inline_specials_ := true ; % command like code
+%D \stoptyping
+%D
+%D When the specification is embedded as comment, it looks
+%D like:
+%D
+%D \starttyping
+%D %%MetaPostSpecial
+%D \stoptyping
+%D
+%D The in||line alternative is more tuned for \POSTSCRIPT,
+%D since it permits us to define a macro \type {special}.
+%D
+%D \starttyping
+%D inline : special
+%D \stoptyping
+%D
+%D The \type {identifier} determines what to do, and the data
+%D can be used to accomplish this. A type~2 shading function
+%D has identifier~2. Alltogether, the number of parameters is
+%D specified in \type {size}. The \type {number} is the number
+%D of the fill that needs the special treatment. For a type~2
+%D and~3 shaded fill, the datablock contains the following
+
+%D data:
+%D
+%D \starttyping
+%D from to n inner_r g b x y outer_r g b x y
+%D from to n inner_r g b x y radius outer_r g b x y radius
+%D \stoptyping
+
+\newconditional\manyMPspecials \settrue\manyMPspecials
+
+%D In case of \PDF, we need to prepare resourcs.
+
+\newtoks\MPstartresources
+\newtoks\MPstopresources
+
+\def\startMPresources
+ {\the\MPstartresources}
+
+\def\stopMPresources
+ {\the\MPstopresources}
+
+%D Some day we may consider collecting local resources.
+
+\appendtoks
+ \global\let\currentPDFresources\empty % kind of redundant
+\to \MPstartresources
+
+% \appendtoks
+% \collectPDFresources
+% \global\let\currentPDFresources\collectedPDFresources
+% \to \MPstopresources
+
+\appendtoksonce
+ \the\everyPDFxform
+\to \MPstopresources
+
+%D Since colors are not subjected to transformations, we can
+%D only use colors as signal. In our case, we use a dummy colored
+%D path with a red color component of \type {0.n}, so \type
+%D {0.001} is the first path and \type {0.010} the tenth. Since
+%D \METAPOST strips trailing zeros, we have to padd the string.
+
+\newif\ifMPcmykcolors
+\newif\ifMPspotcolors
+
+\def\dohandleMPrgb #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
+\def\dohandleMPcmyk#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
+\def\dohandleMPgray #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
+\def\dohandleMPspot#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
+
+%D Specials:
+
+\settrue \manyMPspecials \newcount\nofMParguments \let\extraMPpathcode\empty
+
+\def\@@MP {@@MP}
+\def\@@MPSK{@MPSK@}
+
+\def\MPspecial{\@@MPSK\@@MPSK\gMPs\nofMParguments}
+
+\def\defineMPspecial#1#2%
+ {\setvalue{\@@MPSK\@@MPSK#1}{#2}}
+
+%D Special number~1 is dedicated to \CMYK\ support. If you
+%D want to know why: look at this:
+%D
+%D \startbuffer[mp]
+%D fill fullcircle xyscaled (3cm,1cm) withcolor \MPcolor{test} ;
+%D \stopbuffer
+%D
+%D \startbuffer[cmyk]
+%D \startcombination[4*1]
+%D {\definecolor[test][c=1,y=.3,k=.3] \processMPbuffer[mp]} {c=1 y=.3 k=.3}
+%D {\definecolor[test][c=.9,y=.15] \processMPbuffer[mp]} {c=.9 y=.15}
+%D {\definecolor[test][c=.25,y=.8] \processMPbuffer[mp]} {c=.25 y=.8}
+%D {\definecolor[test][c=.45,y=.1] \processMPbuffer[mp]} {c=.45 y=.1}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \placefigure
+%D {\CMYK\ support disabled,
+%D conversion to \RGB.}
+%D {\setupcolors[cmyk=nee,state=start]\getbuffer[cmyk]}
+%D
+%D \placefigure
+%D {\CMYK\ support enabled,
+%D no support in \METAPOST.}
+%D {\setupcolors[cmyk=ja,mpcmyk=nee,state=start]\getbuffer[cmyk]}
+%D
+%D \placefigure
+%D {\CMYK\ support enabled,
+%D no conversion to \RGB,
+%D support in \METAPOST}
+%D {\setupcolors[cmyk=ja,state=start]\getbuffer[cmyk]}
+
+\defineMPspecial{1}
+ {\ifMPcmykcolors
+ \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPcmykcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
+ \fi}
+
+\defineMPspecial{2}
+ {\ifMPspotcolors
+ \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPspotcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
+% \checkMPspot{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}%
+ \fi}
+
+% \def\checkMPspot#1#2#3#4%
+% {\normalexpanded{\noexpand\resolveMPspotcolor#1 #2 #3 #4}\end
+% \ifx\MPspotspace\MPresolvedspace
+% \edef\MPspotspacespec{/\MPspotspace\space}%
+% \doifinstringelse\MPspotspacespec\currentMPcolorspaces
+% \donothing\registerMPcolorspace
+% \fi}
+
+\let\revokeMPtransparencyspecial\relax
+
+\def\dohandleMPrgbcolor #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
+\def\dohandleMPcmykcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
+\def\dohandleMPgraycolor #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
+\def\dohandleMPspotcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
+
+%D Transparency support used specials 60 (rgb) and 61
+%D (cmyk).
+%D
+%D \startbufferFshade
+
+%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
+%D
+%D fill p rotated 90 withcolor transparent(1,.5,yellow) ;
+%D fill p rotated 210 withcolor transparent(1,.5,green) ;
+%D fill p rotated 330 withcolor transparent(1,.5,blue) ;
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection \processMPbuffer \stoplinecorrection
+%D
+%D One can also communicate colors between \CONTEXT\ and
+%D \METAPOST:
+%D
+%D \startbuffer
+%D \definecolor[tcyan] [c=1,k=.2,t=.5]
+%D \definecolor[tmagenta][m=1,k=.2,t=.5]
+%D \definecolor[tyellow] [y=1,k=.2,t=.5]
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D \startbuffer
+%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
+%D
+%D fill p rotated 90 withcolor \MPcolor{tcyan} ;
+%D fill p rotated 210 withcolor \MPcolor{tmagenta} ;
+%D fill p rotated 330 withcolor \MPcolor{tyellow} ;
+%D \stopbuffer
+%D
+%D \startlinecorrection \processMPbuffer \stoplinecorrection
+%D
+%D We save all the three components needed in one macro,
+%D just to save hash space.
+
+\def\dohandleMPrgbtransparency #1#2#3#4#5{\execcolorR #1:#2:#3:#4:#5\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPcmyktransparency#1#2#3#4#5#6{\execcolorC#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPgraytransparency #1#2#3{\execcolorS #1:#2:#3\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+\def\dohandleMPspottransparency#1#2#3#4#5#6{\execcolorP#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
+
+\def\dorevokeMPtransparencyspecial
+ {\PDFcode{\PDFtransparencyresetidentifier\space gs}%
+ \let\revokeMPtransparencyspecial\relax}
+
+\defineMPspecial{3} % rgb
+ {\setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPrgbtransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs1}{\gMPs2}}}
+
+\defineMPspecial{4} % cmyk
+ {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPcmyktransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}}
+
+\defineMPspecial{5} % spot
+ {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPspottransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}%
+ }%\checkMPspot{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}
+
+%D Shading is an example of a more advanced graphic feature,
+%D but users will seldom encounter those complications. Here
+%D we only show a few simple examples, but many other
+%D alternatives are possible by setting up the functions built
+%D in \PDF\ in the appropriate way.
+%D
+%D Shading has to do with interpolation between two or more
+%D points or user supplied ranges. In \PDF, the specifications
+%D of a shade has to be encapsulated in objects and passed on
+%D as resources. This is a \PDF\ level 1.3. feature. One can
+%D simulate three dimensional shades as well and define simple
+%D functions using a limited set of \POSTSCRIPT\ primitives.
+%D Given the power of \METAPOST\ and these \PDF\ features, we
+%D can achieve superb graphic effects.
+%D
+%D Since everything is hidden in \TEX\ and \METAPOST\ graphics,
+%D we can stick to high level \CONTEXT\ command, as shown in
+%D the following exmples.
+%D
+%D \startbuffer
+%D \startuniqueMPgraphic{CircularShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D circular_shade(p,0,.2red,.9red) ;
+%D \stopuniqueMPgraphic
+%D
+%D \startuniqueMPgraphic{LinearShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D linear_shade(p,0,.2blue,.9blue) ;
+%D \stopuniqueMPgraphic
+%D
+%D \startuniqueMPgraphic{DuotoneShade}
+%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
+%D linear_shade(p,2,.5green,.5red) ;
+%D \stopuniqueMPgraphic
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D These graphics can be hooked into the overlay mechanism,
+%D which is available in many commands.
+%D
+%D \startbuffer
+%D \defineoverlay[demo 1][\uniqueMPgraphic{CircularShade}]
+%D \defineoverlay[demo 2][\uniqueMPgraphic {LinearShade}]
+%D \defineoverlay[demo 3][\uniqueMPgraphic {DuotoneShade}]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+%D
+%D These backgrounds can for instance be applied to \type
+%D {\framed}:
+%D
+%D \startbuffer
+%D \setupframed[width=3cm,height=2cm,frame=off]
+%D \startcombination[3*1]
+%D {\framed[backgroundachtergrond=demo 1]{\bfd \white Demo 1}} {}
+%D {\framed[backgroundachtergrond=demo 2]{\bfd \white Demo 2}} {}
+%D {\framed[backgroundachtergrond=demo 3]{\bfd \white Demo 3}} {}
+%D \stopcombination
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D There are a few more alternatives, determined by the second
+%D parameter passed to \type {circular_shade} and alike.
+%D
+%D \def\SomeShade#1#2#3#4#5%
+%D {\startuniqueMPgraphic{Shade-#1}
+%D width := \overlaywidth ;
+%D height := \overlayheight ;
+%D path p ; p := unitsquare xscaled width yscaled height ;
+%D #2_shade(p,#3,#4,#5) ;
+%D \stopuniqueMPgraphic
+%D \defineoverlay[Shade-#1][\uniqueMPgraphic{Shade-#1}]%
+%D \framed[backgroundachtergrond=Shade-#1,width=2cm,height=2cm,frame=off]{}}
+%D
+%D \startlinecorrection
+%D \startcombination[5*1]
+%D {\SomeShade{10}{circular}{0}{.3blue}{.9blue}} {circular 0}
+%D {\SomeShade{11}{circular}{1}{.3blue}{.9blue}} {circular 1}
+%D {\SomeShade{12}{circular}{2}{.3blue}{.9blue}} {circular 2}
+%D {\SomeShade{13}{circular}{3}{.3blue}{.9blue}} {circular 3}
+%D {\SomeShade{14}{circular}{4}{.3blue}{.9blue}} {circular 4}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D \blank
+%D
+%D \startlinecorrection
+%D \startcombination[5*1]
+%D {\SomeShade{20}{circular}{0}{.9green}{.3green}} {circular 0}
+%D {\SomeShade{21}{circular}{1}{.9green}{.3green}} {circular 1}
+%D {\SomeShade{22}{circular}{2}{.9green}{.3green}} {circular 2}
+%D {\SomeShade{23}{circular}{3}{.9green}{.3green}} {circular 3}
+%D {\SomeShade{24}{circular}{4}{.9green}{.3green}} {circular 4}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D \blank
+%D
+%D \startlinecorrection
+%D \startcombination[4*1]
+%D {\SomeShade{30}{linear}{0}{.3red}{.9red}} {linear 0}
+%D {\SomeShade{31}{linear}{1}{.3red}{.9red}} {linear 1}
+%D {\SomeShade{32}{linear}{2}{.3red}{.9red}} {linear 2}
+%D {\SomeShade{33}{linear}{3}{.3red}{.9red}} {linear 3}
+%D \stopcombination
+%D \stoplinecorrection
+%D
+%D These macros closely cooperate with the \METAPOST\ module
+%D \type {mp-spec.mp}, which is part of the \CONTEXT\
+%D distribution.
+%D
+%D The low level (\PDF) implementation is based on the \TEX\
+%D based \METAPOST\ to \PDF\ converter. Shading is supported
+%D by overloading the \type {fill} operator as implemented
+%D earlier. In \PDF\ type~2 and~3 shading functions are
+%D specified in terms of:
+%D
+%D \starttabulate[|Tl|l|]
+%D \NC /Domain \NC sort of meeting range \NC \NR
+%D \NC /C0 \NC inner shade \NC \NR
+%D \NC /C1 \NC outer shade \NC \NR
+%D \NC /N \NC smaller values, bigger inner circles \NC \NR
+%D \stoptabulate
+
+\newcount\currentPDFshade % 0 % global (document wide) counter
+
+\def\dosetMPsomePDFshade#1#2%
+ {\immediate\pdfobj
+ {<>}%
+ \immediate\pdfobj
+ {<>}%
+ \global\advance\currentPDFshade \plusone
+ \appendtoPDFdocumentshades{/Sh\the\currentPDFshade\space\the\pdflastobj\space0 R }%
+ \setxvalue{\@@MPSK#2}{\noexpand\dohandleMPshade{\the\currentPDFshade}}}
+
+\def\dosetMPlinearshade {\dosetMPsomePDFshade2}% #1
+\def\dosetMPcircularshade{\dosetMPsomePDFshade3}% #1
+
+\defineMPspecial{30}
+ {\normalexpanded{\noexpand\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPrgbcolor{\gMPs{9}}{\gMPs{10}}{\gMPs{11}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs{12} \gMPs{13}}%
+ \dosetMPlinearshade{\gMPs{14}}}
+
+\defineMPspecial{31}
+ {\normalexpanded{\noexpand\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPrgbcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs9 \gMPs{13} \gMPs{14} \gMPs{15}}%
+ \dosetMPcircularshade{\gMPs{16}}}
+
+\defineMPspecial{32}
+ {\normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
+ \dosetMPlinearshade{\gMPs{16}}}
+
+\defineMPspecial{33}
+ {\normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
+ \dosetMPcircularshade{\gMPs{18}}}
+
+\defineMPspecial{34}
+ {\normalexpanded{\noexpand\resolveMPspotcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPspotcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
+ \dosetMPlinearshade{\gMPs{16}}}
+
+\defineMPspecial{35}
+ {\normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
+ \normalexpanded{\noexpand\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
+ \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
+ \dosetMPcircularshade{\gMPs{18}}}
+
+\newconditional\ignoreMPpath
+
+\def\dohandleMPshade#1%
+ {\revokeMPtransparencyspecial
+ \settrue\ignoreMPpath
+ \def\extraMPpathcode{/Sh#1 sh Q}%
+ \chardef\finiMPpath\zerocount
+ \PDFcode{q /Pattern cs}}
+
+\defineMPspecial{10}
+ {\setxvalue{\@@MPSK\gMPs8}%
+ {\noexpand\handleMPfigurespecial{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}{\gMPs8}}}
+
+\def\handleMPfigurespecial#1#2#3#4#5#6#7#8% todo : combine with ext fig
+ {\global\letvalue{\@@MPSK#8}\empty
+ \vbox to \zeropoint
+ {\vss
+ \hbox to \zeropoint
+ {\ifcase\pdfoutput\or % will be hooked into the special driver
+ \doiffileelse{#7}
+ {\doifundefinedelse{mps:x:#7}
+ {\immediate\pdfximage\!!width\onebasepoint\!!height\onebasepoint{#7}%
+ \setxvalue{mps:x:#7}{\pdfrefximage\the\pdflastximage}}%
+ {\message{[reusing figure #7]}}%
+ \PDFcode{q #1 #2 #3 #4 #5 #6 cm}%
+ \rlap{\getvalue{mps:x:#7}}%
+ \PDFcode{Q}}
+ {\message{[unknown figure #7]}}%
+ \fi
+ \hss}}}
+
+%D An example of using both special features is the
+%D following.
+%D
+%D \starttyping
+%D \startMPpage
+%D externalfigure "hakker1b.png" scaled 22cm rotated 10 shifted (-2cm,0cm);
+%D externalfigure "hakker1b.png" scaled 10cm rotated -10 ;
+%D externalfigure "hakker1b.png" scaled 7cm rotated 45 shifted (8cm,12cm) ;
+%D path p ; p := unitcircle xscaled 15cm yscaled 20cm;
+%D path q ; q := p rotatedaround(center p,90) ;
+%D path r ; r := buildcycle(p,q) ; clip currentpicture to r ;
+%D path s ; s := boundingbox currentpicture enlarged 5mm ;
+%D picture c ; c := currentpicture ; currentpicture := nullpicture ;
+%D circular_shade(s,0,.2red,.9red) ;
+%D addto currentpicture also c ;
+%D \stopMPpage
+%D \stoptyping
-% \def\TEXcode#1#2#3#4#5%
-% {\setbox\scratchbox\hbox
-% {\font\temp=#1\space at #2\onebasepoint
-% \temp
-% \MPfshowcommand{#3}}%
-% \setbox\scratchbox\hbox
-% {\hskip#4\onebasepoint
-% \raise#5\onebasepoint
-% \box\scratchbox}%
-% \smashbox\scratchbox
-% \box\scratchbox}
+\defineMPspecial{20}
+ {\setxvalue{\@@MPSK\gMPs6}%
+ {\noexpand\handleMPhyperlink{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}}
+
+\def\handleMPhyperlink#1#2#3#4#5#6%
+ {\global\letvalue{\@@MPSK#6}\empty
+ \setbox\scratchbox\hbox
+ {\setbox\scratchbox\null
+ \wd\scratchbox\dimexpr-#1\onebasepoint+#3\onebasepoint\relax
+ \ht\scratchbox\dimexpr-#2\onebasepoint+#4\onebasepoint\relax
+ \incolorfalse
+ \gotobox{\box\scratchbox}[#5]}%
+ \setbox\scratchbox\hbox
+ {\hskip\dimexpr\MPxoffset\onebasepoint+#1\onebasepoint\relax
+ \raise\dimexpr\MPyoffset\onebasepoint+#2\onebasepoint\relax
+ \box\scratchbox}%
+ \smashbox\scratchbox
+ \box\scratchbox}
+
+%D This special (number 50) passes positions to a tex file.
+%D This method uses a two||pass approach an (mis|)|used the
+%D context positioning macros. In \type {core-pos} we will
+%D implement the low level submacro needed.
+%D
+%D \startbuffer
+%D \definelayer[test]
+%D
+%D \setlayer
+%D [test]
+%D [x=\MPx{somepos-1},y=\MPy{somepos-1}]
+%D {Whatever we want here!}
+%D
+%D \setlayer
+%D [test]
+%D [x=\MPx{somepos-2},y=\MPy{somepos-2}]
+%D {Whatever we need there!}
+%D
+%D \startuseMPgraphic{oeps}
+%D draw fullcircle scaled 6cm withcolor red ;
+%D register ("somepos-1",1cm,2cm,center currentpicture) ;
+%D register ("somepos-2",4cm,3cm,(-1cm,-2cm)) ;
+%D \stopuseMPgraphic
+%D
+%D \framed[background=test,offset=overlay]{\useMPgraphic{oeps}}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D Here the width and height are not realy used, but one can
+%D imagine situations where tex has to work with values
+%D calculated by \METAPOST.
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D Later we will implement a more convenient macro:
+%D
+%D \starttyping
+%D \setMPlayer [test] [somepos-1] {Whatever we want here!}
+%D \setMPlayer [test] [somepos-2] {Whatever we need there!}
+%D \stoptyping
+
+\defineMPspecial{50} % x y width height label
+ {\dosavepositionwhd
+ {\gMPs5}%
+ {0}%
+ {\the\dimexpr-\MPllx\onebasepoint+\gMPs1\onebasepoint\relax}
+ {\the\dimexpr\gMPs2\onebasepoint-\scratchdimen+\MPury\onebasepoint\relax}%
+ {\the\dimexpr\gMPs3\onebasepoint\relax}%
+ {\the\dimexpr\gMPs4\onebasepoint\relax}%
+ {0pt}}
+
+%D A few auxiliary macros. This will move to colo-ini.
+
+\def\MPgrayspace{DeviceGray}
+\def\MPrgbspace {DeviceRGB}
+\def\MPcmykspace{DeviceCMYK}
+\let\MPspotspace\MPgrayspace
+
+\def\MPcmykBlack{0 0 0 0}
+\def\MPcmykWhite{0 0 0 1}
+
+\def\startMPcolorresolve
+ {\bgroup
+ \def\dostartgraycolormode##1%
+ {\global\let\MPresolvedspace\MPgrayspace
+ \xdef\MPresolvedcolor{##1}}%
+ \def\dostartrgbcolormode ##1##2##3%
+ {\global\let\MPresolvedspace\MPrgbspace
+ \xdef\MPresolvedcolor{##1 ##2 ##3}}%
+ \def\dostartcmykcolormode##1##2##3##4%
+ {\global\let\MPresolvedspace\MPcmykspace
+ \xdef\MPresolvedcolor{##1 ##2 ##3 ##4}}%
+ \def\dostartspotcolormode##1##2%
+ {\global\let\MPspotspace\empty % left over ?
+ \xdef\MPresolvedspace{##1}%
+ \xdef\MPresolvedcolor{##2}%
+ \global\let\MPspotspace\MPresolvedspace}% signal
+ \dostartgraycolormode\!!zerocount} % kind of hackery initialization
+
+\let\stopMPcolorresolve\egroup
+
+\def\resolveMPrgbcolor#1#2#3\to#4%
+ {\startMPcolorresolve
+ \execcolorR#1:#2:#3:0:0\od
+ \stopMPcolorresolve
+ \let#4\MPresolvedcolor}
+
+\def\resolveMPcmykcolor#1#2#3#4\to#5%
+ {\startMPcolorresolve
+ \execcolorC#1:#2:#3:#4:0:0\od
+ \stopMPcolorresolve
+ \let#5\MPresolvedcolor}
+
+\def\resolveMPgraycolor#1\end\to#2%
+ {\startMPcolorresolve
+ \execcolorS#1:0:0\od
+ \stopMPcolorresolve
+ \let#2\MPresolvedcolor}
+
+\def\resolveMPspotcolor#1#2#3#4\end\to#5%
+ {\startMPcolorresolve
+ \ifnum#2>\plusone
+ \checkmultitonecolor{#1}%
+ \fi
+ \execcolorP#1:#2:#3:#4:0:0\od
+ \stopMPcolorresolve
+ \let#5\MPresolvedcolor}
+
+\startMPinitializations
+ mp_shade_version := 2 ;
+\stopMPinitializations
% will be done better
@@ -152,4 +864,83 @@
\let\MPSgray\dohandleMPgray
\let\MPSspot\dohandleMPspot
+%D Test code:
+
+% \startMPcode
+% fill fullcircle scaled 3cm withcolor red ;
+% fill fullcircle scaled 2cm withcolor green ;
+% fill fullcircle scaled 1cm withcolor blue ;
+% currentpicture := currentpicture shifted (-4cm,0) ;
+% fill fullcircle scaled 3cm withcolor cmyk(0,0,1,0) ;
+% fill fullcircle scaled 2cm withcolor cmyk(0,1,0,0) ;
+% fill fullcircle scaled 1cm withcolor cmyk(0,0,1,0) ;
+% currentpicture := currentpicture shifted (-4cm,0) ;
+% draw fullcircle scaled 3cm dashed evenly ;
+% draw fullcircle scaled 2cm dashed withdots ;
+% draw origin withpen pencircle scaled 3mm;
+% currentpicture := currentpicture shifted (-4cm,0) ;
+% fill fullcircle scaled 2cm shifted (-.5cm,+.5cm) withcolor transparent(1,.5,red);
+% fill fullcircle scaled 2cm shifted (-.5cm,-.5cm) withcolor transparent(1,.5,red);
+% fill fullcircle scaled 2cm shifted (+.5cm,+.5cm) withcolor transparent(1,.5,green);
+% fill fullcircle scaled 2cm shifted (+.5cm,-.5cm) withcolor transparent(1,.5,cmyk(1,0,1,.5));
+% currentpicture := currentpicture shifted (12cm,-4cm) ;
+% draw "o e p s" infont defaultfont scaled 2 shifted (-1cm,0) ;
+% currentpicture := currentpicture shifted (-4cm,0) ;
+% % bug: shift
+% draw fullcircle scaled 3cm withpen pencircle yscaled 3mm xscaled 2mm rotated 30 ;
+% draw fullcircle scaled 2cm withpen pencircle yscaled 3mm xscaled 2mm rotated 20 withcolor red ;
+% filldraw fullcircle scaled 1cm withpen pencircle yscaled 3mm xscaled 2mm rotated 10 withcolor green ;
+% currentpicture := currentpicture shifted (-4cm,0) ;
+% % shade cannot handle shift
+% circular_shade(fullcircle scaled 3cm,0,.2red,.9green) ;
+% circular_shade(fullcircle scaled 3cm shifted(+4cm,0),0,cmyk(1,0,0,0),cmyk(0,1,0,0)) ;
+% filldraw boundingbox currentpicture enlarged -3cm withpen pencircle scaled 1pt withcolor .5white ;
+% \stopMPcode
+
+% We cannot use attributes for switching colors in mp literals because
+% grouping (qQ) interferes.
+
+\ifx\colorversion\undefined \else \ifnum\colorversion>\plusone
+
+ \def\dohandleMPgraycolor #1{\ctxlua{ctx.pdffinishtransparency()
+ ctx.pdfgrayliteral(\the\currentcolormodel,#1)}}
+ \def\dohandleMPrgbcolor #1#2#3{\ctxlua{ctx.pdffinishtransparency()
+ ctx.pdfrgbliteral (\the\currentcolormodel,#1,#2,#3)}}
+ \def\dohandleMPcmykcolor#1#2#3#4{\ctxlua{ctx.pdffinishtransparency()
+ ctx.pdfcmykliteral(\the\currentcolormodel,#1,#2,#3,#4)}}
+ \def\dohandleMPspotcolor#1#2#3#4{\ctxlua{ctx.pdffinishtransparency()
+ ctx.pdfspotliteral(\the\currentcolormodel,"#1",#2,"#3","#4")}}
+
+ % we can combine the next calls
+
+ \def\dohandleMPgraytransparency #1#2#3{\ctxlua{ctx.pdfgrayliteral(\the\currentcolormodel,#1)
+ ctx.pdftransparencyliteral(#2,#3)}}
+ \def\dohandleMPrgbtransparency #1#2#3#4#5{\ctxlua{ctx.pdfrgbliteral (\the\currentcolormodel,#1,#2,#3)
+ ctx.pdftransparencyliteral(#4,#5)}}
+ \def\dohandleMPcmyktransparency#1#2#3#4#5#6{\ctxlua{ctx.pdfcmykliteral(\the\currentcolormodel,#1,#2,#3,#4)
+ ctx.pdftransparencyliteral(#5,#6)}}
+ \def\dohandleMPspottransparency#1#2#3#4#5#6{\ctxlua{ctx.pdfspotliteral(\the\currentcolormodel,"#1",#2,"#3","#4")
+ ctx.pdftransparencyliteral(#5,#6)}}
+
+ \def\dohandleMPresettransparency {\ctxlua{ctx.pdffinishtransparency()}}
+
+ \def\resolveMPgraycolor #1\to#2{\ctxlua{ctx.resolvempgraycolor("\strippedcsname#2","MPresolvedspace",\number\currentcolormodel,#1)}}
+ \def\resolveMPrgbcolor #1#2#3\to#4{\ctxlua{ctx.resolvemprgbcolor ("\strippedcsname#4","MPresolvedspace",\number\currentcolormodel,#1,#2,#3)}}
+ \def\resolveMPcmykcolor#1#2#3#4\to#5{\ctxlua{ctx.resolvempcmykcolor("\strippedcsname#5","MPresolvedspace",\number\currentcolormodel,#1,#2,#3,#4)}}
+
+ \def\resolveMPspotcolor#1#2#3#4\to#5% unchecked
+ {\ctxlua{ctx.resolvempspotcolor("\strippedcsname#5","MPresolvedspace",\number\currentcolormodel,"#1",#2,"#3","#4")}%
+ \xdef\MPresolvedspace{#1}%
+ \xdef\MPresolvedcolor{#4}%
+ \global\let\MPspotspace\MPresolvedspace}
+
+ % used as callers
+
+ \let\MPSgray\dohandleMPgraycolor
+ \let\MPSrgb \dohandleMPrgbcolor
+ \let\MPScmyk\dohandleMPcmykcolor
+ \let\MPspot \dohandleMPspotcolor
+
+\fi \fi
+
\protect \endinput
diff --git a/tex/context/base/meta-pdf.tex b/tex/context/base/meta-pdf.tex
deleted file mode 100644
index 8bf976f97..000000000
--- a/tex/context/base/meta-pdf.tex
+++ /dev/null
@@ -1,1020 +0,0 @@
-%D \module
-%D [ file=meta-pdf,
-%D version=2006.06.07,
-%D title=\CONTEXT\ Support Macros,
-%D subtitle=\METAPOST\ to \PDF\ conversion,
-%D author=Hans Hagen \& others (see text),
-%D date=\currentdate,
-%D copyright=\PRAGMA]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-%D Formerly known as supp-pdf.tex and supp-mpe.tex.
-
-%D We will clean up the color mess later.
-
-%D These macros are written as generic as possible. Some
-%D general support macro's are loaded from a small module
-%D especially made for non \CONTEXT\ use. In this module I
-%D use a matrix transformation macro written by Tanmoy
-%D Bhattacharya. Thanks to extensive testing by Sebastian
-%D Ratz I was able to complete this module within reasonable
-%D time. This module has support for \METAPOST\ extensions
-%D built in.
-%D
-%D Daniel H. Luecking came up with a better (more precise)
-%D transformation method. You can recognize his comment by
-%D his initials. (We keep the old code around because it's a
-%D nice illustration on how a module like this evolves.)
-
-% Beware, we cannot use 0pt here by defaukt since it may be
-% defined in the range \dimen 0 - 20 which we happen to use
-% as scratch registers; for this reason we start allocating
-% scratch registers > 20
-
-%D This module handles some \PDF\ conversion and insertions
-%D topics. By default, the macros use the \PDFTEX\ primitive
-%D \type{\pdfliteral} when available. Since \PDFTEX\ is now the
-%D default engine for \TEX\ distributions, we need a more complex
-%D test.
-
-\writestatus{loading}{Context Support Macros / MPS to PDF}
-
-\unprotect
-
-\ifx\PDFcode \undefined \let\PDFcode \gobbleoneargument \fi
-\ifx\PDFcomment\undefined \def\PDFcomment#1{\PDFcode{\letterpercent\space#1}} \fi
-
-%D First we define a handy constant:
-
-\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup
-
-%D \macros
-%D {pdfimage,pdfimages,pdfclippedimage}
-%D
-%D Starting with pdftex version 14, images are included more
-%D natural to the form embedding. This enables alternative
-%D images to be embedded.
-%D
-%D \starttyping
-%D \pdfimage {file}
-%D \pdfimages {high res file} {low res file}
-%D \stoptyping
-%D
-%D The first one replaces the pre||version||14 original,
-%D while the latter provides alternative images.
-%D
-%D The next macro is dedicated to Maarten Gelderman, who
-%D needed to paste prepared \PDF\ pages into conference
-%D proceedings.
-%D
-%D \starttyping
-%D \pdfclippedimage {file} {l} {r} {t} {b}
-%D \stoptyping
-
-\ifx\pdftexversion\undefined \else \ifnum\pdftexversion>13 % still relevant?
-
- \def\pdfimage#1#%
- {\dopdfimage{#1}}
-
- \def\dopdfimage#1#2%
- {\immediate\pdfximage#1{#2}%
- \pdfrefximage\pdflastximage}
-
- \def\pdfimages#1#%
- {\dopdfimages{#1}}
-
- \def\dopdfimages#1#2#3%
- {\immediate\pdfximage#1{#2}%
- \immediate\pdfobj{[ << /Image \the\pdflastximage\space0 R /DefaultForPrinting true >> ]}%
- \immediate\pdfximage#1 attr {/Alternates \the\pdflastobj\space0 R}{#3}%
- \pdfrefximage\pdflastximage}
-
- \def\pdfclippedimage#1#% specs {file}{left}{right}{top}{bottom}
- {\dopdfclippedimage{#1}}
-
- \def\dopdfclippedimage#1#2#3#4#5#6%
- {\bgroup
- \pdfximage#1{#2}%
- \setbox\scratchbox\hbox{\pdfrefximage\pdflastximage}%
- \hsize\dimexpr\wd\scratchbox-#3-#4\relax
- \vsize\dimexpr\ht\scratchbox-#5-#6\relax
- \setbox\scratchbox\vbox to \vsize
- {\vskip-#5\hbox to \hsize{\hskip-#3\box\scratchbox\hss}}%
- \pdfxform\scratchbox
- \pdfrefxform\pdflastxform
- \egroup}
-
-\fi \fi
-
-%D \macros
-%D {convertMPtoPDF}
-%D
-%D The next set of macros implements \METAPOST\ to \PDF\
-%D conversion. The traditional method is in the MkII file.
-
-%D The main conversion command is:
-%D
-%D \starttyping
-%D \convertMPtoPDF {filename} {x scale} {y scale}
-%D \stoptyping
-%D
-%D The dimensions are derived from the bounding box. So we
-%D only have to say:
-%D
-%D \starttyping
-%D \convertMPtoPDF{mp-pra-1.eps}{1}{1}
-%D \convertMPtoPDF{mp-pra-1.eps}{.5}{.5}
-%D \stoptyping
-
-%D \macros
-%D {makeMPintoPDFobject,lastPDFMPobject}
-%D
-%D For experts there are a few more options. When attributes
-%D are to be added, the code must be embedded in an object
-%D accompanied with the appropriate directives. One can
-%D influence this process with \type {\makeMPintoPDFobject}.
-%D
-%D This option defaults to~0, because \CONTEXT\ takes care
-%D of objects at another level, which saves some bytes.
-%D
-%D \starttabulate[|l|l|p|]
-%D \NC 0 \NC never \NC don't use an object \NC\NR
-%D \NC 1 \NC always \NC always use an object \NC\NR
-%D \NC 2 \NC optional \NC use object when needed \NC\NR
-%D \stoptabulate
-%D
-%D The last object number used is avaliable in the macro
-%D \type {\lastPDFMPobject}.
-
-\ifx\makeMPintoPDFobject \undefined \chardef\makeMPintoPDFobject \zerocount \fi
-\ifx\blackoutMPgraphic \undefined \chardef\blackoutMPgraphic \plusone \fi
-\ifx\everyMPtoPDFconversion\undefined \newtoks\everyMPtoPDFconversion \fi
-
-\let\lastPDFMPobject \!!zerocount
-\let\currentPDFresources\empty
-\let\setMPextensions \relax
-
-\def\PDFMPformoffset
- {\ifx\objectoffset\undefined\zeropoint\else\objectoffset\fi}
-
-\def\resetMPvariables#1#2#3%
- {\global\let\MPwidth \!!zeropoint
- \global\let\MPheight\!!zeropoint
- \global\let\MPllx \!!zerocount
- \global\let\MPlly \!!zerocount
- \global\let\MPurx \!!zerocount
- \global\let\MPury \!!zerocount
- \xdef\MPxscale {#2}\ifx\MPxscale\empty\let\MPxscale\!!plusone\fi
- \xdef\MPyscale {#3}\ifx\MPyscale\empty\let\MPyscale\!!plusone\fi
- \xdef\MPfilename {#1}}
-
-%D The main macro:
-
-\def\convertMPtoPDF#1#2#3%
- {\resetMPvariables{#1}{#2}{#3}%
- \mkconvertMPtoPDF}
-
-\def\processMPtoPDFfile#1#2#3% obsolete
- {\resetMPvariables{#1}{#2}{#3}%
- \mkprocessMPtoPDFfile}
-
-%D A common hook.
-
-\let\MPfshowcommand\empty
-
-%D Objects.
-
-\def\dopackageMPgraphic#1% #1 = boxregister
- {\ifcase\makeMPintoPDFobject\or\or\ifx\currentPDFresources\empty\else
- % an existing value of 2 signals object support (set elsewhere)
- \chardef\makeMPintoPDFobject\plusone
- \fi\fi
- \ifcase\makeMPintoPDFobject
- \box#1%
- \or
- \scratchdimen\PDFMPformoffset\relax
- \ifdim\scratchdimen>\zeropoint % compensate for error
- \setbox#1\vbox spread 2\scratchdimen
- {\forgetall\vss\hbox spread 2\scratchdimen{\hss\box#1\hss}\vss}%
- \fi
- \setMPPDFobject{\currentPDFresources}{#1}%
- \ifdim\scratchdimen>\zeropoint % compensate for error
- \vbox to \MPheight
- {\forgetall\vss\hbox to \MPwidth{\hss\getMPPDFobject\hss}\vss}%
- \else
- \getMPPDFobject
- \fi
- \global\let\currentPDFresources\empty
- \else
- \box#1%
- \fi}
-
-\def\setMPPDFobject#1#2% resources boxnumber
- {\ifx\pdfxform\undefined
- \def\getMPPDFobject{\box#2}%
- \else\ifx\pdftexversion\undefined
- \def\getMPPDFobject{\box#2}%
- \else\ifnum\pdftexversion<14
- \def\getMPPDFobject{\box#2}%
- \else
- \ifx\everyPDFxform\undefined\else\the\everyPDFxform\fi
- \immediate\pdfxform resources{#1}#2%
- \edef\getMPPDFobject{\noexpand\pdfrefxform\the\pdflastxform}%
- \fi\fi\fi}
-
-\let\getMPPDFobject\relax
-
-%D \macros
-%D {deleteMPgraphic,
-%D startMPresources,
-%D stopMPresources}
-
-\ifx\deleteMPgraphic\undefined
- \def\deleteMPgraphic#1{}
-\fi
-
-\ifx\startMPresources\undefined
- \let\startMPresources\relax
- \let\stopMPresources\relax
-\fi
-
-%D We implement extensions by using the \METAPOST\ special
-%D mechanism. Opposite to \TEX's specials, the \METAPOST\ ones
-%D are flushed before or after the graphic data, but thereby
-%D are no longer connected to a position.
-%D
-%D We implement specials by overloading the \type {fill}
-%D operator. By counting the fills, we can let the converter
-%D treat the appropriate fill in a special way. The
-%D specification of the speciality can have two forms,
-%D determined by the setting of a boolean variable:
-%D
-%D \starttyping
-%D _inline_specials_ := false ; % comment like code (default)
-%D _inline_specials_ := true ; % command like code
-%D \stoptyping
-%D
-%D When the specification is embedded as comment, it looks
-%D like:
-%D
-%D \starttyping
-%D %%MetaPostSpecial
-%D \stoptyping
-%D
-%D The in||line alternative is more tuned for \POSTSCRIPT,
-%D since it permits us to define a macro \type {special}.
-%D
-%D \starttyping
-%D inline : special
-%D \stoptyping
-%D
-%D The \type {identifier} determines what to do, and the data
-%D can be used to accomplish this. A type~2 shading function
-%D has identifier~2. Alltogether, the number of parameters is
-%D specified in \type {size}. The \type {number} is the number
-%D of the fill that needs the special treatment. For a type~2
-%D and~3 shaded fill, the datablock contains the following
-
-%D data:
-%D
-%D \starttyping
-%D from to n inner_r g b x y outer_r g b x y
-%D from to n inner_r g b x y radius outer_r g b x y radius
-%D \stoptyping
-
-\newconditional\manyMPspecials \settrue\manyMPspecials
-
-%D In case of \PDF, we need to prepare resourcs.
-
-\newtoks\MPstartresources
-\newtoks\MPstopresources
-
-\def\startMPresources
- {\the\MPstartresources}
-
-\def\stopMPresources
- {\the\MPstopresources}
-
-%D Some day we may consider collecting local resources.
-
-\appendtoks
- \global\let\currentPDFresources\empty % kind of redundant
-\to \MPstartresources
-
-% \appendtoks
-% \collectPDFresources
-% \global\let\currentPDFresources\collectedPDFresources
-% \to \MPstopresources
-
-\appendtoksonce
- \the\everyPDFxform
-\to \MPstopresources
-
-%D Since colors are not subjected to transformations, we can
-%D only use colors as signal. In our case, we use a dummy colored
-%D path with a red color component of \type {0.n}, so \type
-%D {0.001} is the first path and \type {0.010} the tenth. Since
-%D \METAPOST strips trailing zeros, we have to padd the string.
-
-\newif\ifMPcmykcolors
-\newif\ifMPspotcolors
-
-\def\dohandleMPrgb #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
-\def\dohandleMPcmyk#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
-\def\dohandleMPgray #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
-\def\dohandleMPspot#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
-
-%D Specials:
-
-\settrue \manyMPspecials \newcount\nofMParguments \let\extraMPpathcode\empty
-
-\def\@@MP {@@MP}
-\def\@@MPSK{@MPSK@}
-
-\def\MPspecial{\@@MPSK\@@MPSK\gMPs\nofMParguments}
-
-\def\defineMPspecial#1#2%
- {\setvalue{\@@MPSK\@@MPSK#1}{#2}}
-
-%D Special number~1 is dedicated to \CMYK\ support. If you
-%D want to know why: look at this:
-%D
-%D \startbuffer[mp]
-%D fill fullcircle xyscaled (3cm,1cm) withcolor \MPcolor{test} ;
-%D \stopbuffer
-%D
-%D \startbuffer[cmyk]
-%D \startcombination[4*1]
-%D {\definecolor[test][c=1,y=.3,k=.3] \processMPbuffer[mp]} {c=1 y=.3 k=.3}
-%D {\definecolor[test][c=.9,y=.15] \processMPbuffer[mp]} {c=.9 y=.15}
-%D {\definecolor[test][c=.25,y=.8] \processMPbuffer[mp]} {c=.25 y=.8}
-%D {\definecolor[test][c=.45,y=.1] \processMPbuffer[mp]} {c=.45 y=.1}
-%D \stopcombination
-%D \stopbuffer
-%D
-%D \placefigure
-%D {\CMYK\ support disabled,
-%D conversion to \RGB.}
-%D {\setupcolors[cmyk=nee,state=start]\getbuffer[cmyk]}
-%D
-%D \placefigure
-%D {\CMYK\ support enabled,
-%D no support in \METAPOST.}
-%D {\setupcolors[cmyk=ja,mpcmyk=nee,state=start]\getbuffer[cmyk]}
-%D
-%D \placefigure
-%D {\CMYK\ support enabled,
-%D no conversion to \RGB,
-%D support in \METAPOST}
-%D {\setupcolors[cmyk=ja,state=start]\getbuffer[cmyk]}
-
-\defineMPspecial{1}
- {\ifMPcmykcolors
- \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPcmykcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
- \fi}
-
-\defineMPspecial{2}
- {\ifMPspotcolors
- \setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPspotcolor{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}}%
-% \checkMPspot{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}%
- \fi}
-
-% \def\checkMPspot#1#2#3#4%
-% {\expanded{\resolveMPspotcolor#1 #2 #3 #4}\end
-% \ifx\MPspotspace\MPresolvedspace
-% \edef\MPspotspacespec{/\MPspotspace\space}%
-% \doifinstringelse\MPspotspacespec\currentMPcolorspaces
-% \donothing\registerMPcolorspace
-% \fi}
-
-\let\revokeMPtransparencyspecial\relax
-
-\def\dohandleMPrgbcolor #1#2#3{\revokeMPtransparencyspecial\execcolorR #1:#2:#3:0:0\od}
-\def\dohandleMPcmykcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorC#1:#2:#3:#4:0:0\od}
-\def\dohandleMPgraycolor #1{\revokeMPtransparencyspecial\execcolorS #1:0:0\od}
-\def\dohandleMPspotcolor#1#2#3#4{\revokeMPtransparencyspecial\execcolorP#1:#2:#3:#4:0:0\od}
-
-%D Transparency support used specials 60 (rgb) and 61
-%D (cmyk).
-%D
-%D \startbufferFshade
-
-%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
-%D
-%D fill p rotated 90 withcolor transparent(1,.5,yellow) ;
-%D fill p rotated 210 withcolor transparent(1,.5,green) ;
-%D fill p rotated 330 withcolor transparent(1,.5,blue) ;
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection \processMPbuffer \stoplinecorrection
-%D
-%D One can also communicate colors between \CONTEXT\ and
-%D \METAPOST:
-%D
-%D \startbuffer
-%D \definecolor[tcyan] [c=1,k=.2,t=.5]
-%D \definecolor[tmagenta][m=1,k=.2,t=.5]
-%D \definecolor[tyellow] [y=1,k=.2,t=.5]
-%D \stopbuffer
-%D
-%D \typebuffer \getbuffer
-%D
-%D \startbuffer
-%D u := 2cm ; path p ; p := fullcircle scaled u shifted (u/4,0);
-%D
-%D fill p rotated 90 withcolor \MPcolor{tcyan} ;
-%D fill p rotated 210 withcolor \MPcolor{tmagenta} ;
-%D fill p rotated 330 withcolor \MPcolor{tyellow} ;
-%D \stopbuffer
-%D
-%D \startlinecorrection \processMPbuffer \stoplinecorrection
-%D
-%D We save all the three components needed in one macro,
-%D just to save hash space.
-
-\def\dohandleMPrgbtransparency #1#2#3#4#5{\execcolorR #1:#2:#3:#4:#5\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
-\def\dohandleMPcmyktransparency#1#2#3#4#5#6{\execcolorC#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
-\def\dohandleMPgraytransparency #1#2#3{\execcolorS #1:#2:#3\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
-\def\dohandleMPspottransparency#1#2#3#4#5#6{\execcolorP#1:#2:#3:#4:#5:#6\od\let\revokeMPtransparencyspecial\dorevokeMPtransparencyspecial}
-
-\def\dorevokeMPtransparencyspecial
- {\PDFcode{\PDFtransparencyresetidentifier\space gs}%
- \let\revokeMPtransparencyspecial\relax}
-
-\defineMPspecial{3} % rgb
- {\setxvalue{\@@MPSK\gMPs6}{\noexpand\dohandleMPrgbtransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs1}{\gMPs2}}}
-
-\defineMPspecial{4} % cmyk
- {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPcmyktransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}}
-
-\defineMPspecial{5} % spot
- {\setxvalue{\@@MPSK\gMPs7}{\noexpand\dohandleMPspottransparency{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs1}{\gMPs2}}%
- }%\checkMPspot{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}
-
-%D Shading is an example of a more advanced graphic feature,
-%D but users will seldom encounter those complications. Here
-%D we only show a few simple examples, but many other
-%D alternatives are possible by setting up the functions built
-%D in \PDF\ in the appropriate way.
-%D
-%D Shading has to do with interpolation between two or more
-%D points or user supplied ranges. In \PDF, the specifications
-%D of a shade has to be encapsulated in objects and passed on
-%D as resources. This is a \PDF\ level 1.3. feature. One can
-%D simulate three dimensional shades as well and define simple
-%D functions using a limited set of \POSTSCRIPT\ primitives.
-%D Given the power of \METAPOST\ and these \PDF\ features, we
-%D can achieve superb graphic effects.
-%D
-%D Since everything is hidden in \TEX\ and \METAPOST\ graphics,
-%D we can stick to high level \CONTEXT\ command, as shown in
-%D the following exmples.
-%D
-%D \startbuffer
-%D \startuniqueMPgraphic{CircularShade}
-%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
-%D circular_shade(p,0,.2red,.9red) ;
-%D \stopuniqueMPgraphic
-%D
-%D \startuniqueMPgraphic{LinearShade}
-%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
-%D linear_shade(p,0,.2blue,.9blue) ;
-%D \stopuniqueMPgraphic
-%D
-%D \startuniqueMPgraphic{DuotoneShade}
-%D path p ; p := unitsquare xscaled \overlaywidth yscaled \overlayheight ;
-%D linear_shade(p,2,.5green,.5red) ;
-%D \stopuniqueMPgraphic
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D These graphics can be hooked into the overlay mechanism,
-%D which is available in many commands.
-%D
-%D \startbuffer
-%D \defineoverlay[demo 1][\uniqueMPgraphic{CircularShade}]
-%D \defineoverlay[demo 2][\uniqueMPgraphic {LinearShade}]
-%D \defineoverlay[demo 3][\uniqueMPgraphic {DuotoneShade}]
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \getbuffer
-%D
-%D These backgrounds can for instance be applied to \type
-%D {\framed}:
-%D
-%D \startbuffer
-%D \setupframed[width=3cm,height=2cm,frame=off]
-%D \startcombination[3*1]
-%D {\framed[backgroundachtergrond=demo 1]{\bfd \white Demo 1}} {}
-%D {\framed[backgroundachtergrond=demo 2]{\bfd \white Demo 2}} {}
-%D {\framed[backgroundachtergrond=demo 3]{\bfd \white Demo 3}} {}
-%D \stopcombination
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D \startlinecorrection
-%D \getbuffer
-%D \stoplinecorrection
-%D
-%D There are a few more alternatives, determined by the second
-%D parameter passed to \type {circular_shade} and alike.
-%D
-%D \def\SomeShade#1#2#3#4#5%
-%D {\startuniqueMPgraphic{Shade-#1}
-%D width := \overlaywidth ;
-%D height := \overlayheight ;
-%D path p ; p := unitsquare xscaled width yscaled height ;
-%D #2_shade(p,#3,#4,#5) ;
-%D \stopuniqueMPgraphic
-%D \defineoverlay[Shade-#1][\uniqueMPgraphic{Shade-#1}]%
-%D \framed[backgroundachtergrond=Shade-#1,width=2cm,height=2cm,frame=off]{}}
-%D
-%D \startlinecorrection
-%D \startcombination[5*1]
-%D {\SomeShade{10}{circular}{0}{.3blue}{.9blue}} {circular 0}
-%D {\SomeShade{11}{circular}{1}{.3blue}{.9blue}} {circular 1}
-%D {\SomeShade{12}{circular}{2}{.3blue}{.9blue}} {circular 2}
-%D {\SomeShade{13}{circular}{3}{.3blue}{.9blue}} {circular 3}
-%D {\SomeShade{14}{circular}{4}{.3blue}{.9blue}} {circular 4}
-%D \stopcombination
-%D \stoplinecorrection
-%D
-%D \blank
-%D
-%D \startlinecorrection
-%D \startcombination[5*1]
-%D {\SomeShade{20}{circular}{0}{.9green}{.3green}} {circular 0}
-%D {\SomeShade{21}{circular}{1}{.9green}{.3green}} {circular 1}
-%D {\SomeShade{22}{circular}{2}{.9green}{.3green}} {circular 2}
-%D {\SomeShade{23}{circular}{3}{.9green}{.3green}} {circular 3}
-%D {\SomeShade{24}{circular}{4}{.9green}{.3green}} {circular 4}
-%D \stopcombination
-%D \stoplinecorrection
-%D
-%D \blank
-%D
-%D \startlinecorrection
-%D \startcombination[4*1]
-%D {\SomeShade{30}{linear}{0}{.3red}{.9red}} {linear 0}
-%D {\SomeShade{31}{linear}{1}{.3red}{.9red}} {linear 1}
-%D {\SomeShade{32}{linear}{2}{.3red}{.9red}} {linear 2}
-%D {\SomeShade{33}{linear}{3}{.3red}{.9red}} {linear 3}
-%D \stopcombination
-%D \stoplinecorrection
-%D
-%D These macros closely cooperate with the \METAPOST\ module
-%D \type {mp-spec.mp}, which is part of the \CONTEXT\
-%D distribution.
-%D
-%D The low level (\PDF) implementation is based on the \TEX\
-%D based \METAPOST\ to \PDF\ converter. Shading is supported
-%D by overloading the \type {fill} operator as implemented
-%D earlier. In \PDF\ type~2 and~3 shading functions are
-%D specified in terms of:
-%D
-%D \starttabulate[|Tl|l|]
-%D \NC /Domain \NC sort of meeting range \NC \NR
-%D \NC /C0 \NC inner shade \NC \NR
-%D \NC /C1 \NC outer shade \NC \NR
-%D \NC /N \NC smaller values, bigger inner circles \NC \NR
-%D \stoptabulate
-
-\newcount\currentPDFshade % 0 % global (document wide) counter
-
-% \def\dosetMPsomePDFshade#1#2% generic but needs refs
-% {\global\advance\currentPDFshade \plusone
-% \doPDFdictionaryobject{FDF}{ftn:Sh:\the\currentPDFshade}
-% {/FunctionType 2
-% /Domain [\gMPs1 \gMPs2]
-% /C0 [\MPshadeA]
-% /C1 [\MPshadeB]
-% /N \gMPs3}%
-% \doPDFgetobjectreference{FDF}{ftn:Sh:\the\currentPDFshade}\PDFobjectreference
-% \doPDFdictionaryobject{FDF}{obj:Sh:\the\currentPDFshade}
-% {/ShadingType #1
-% /ColorSpace /\MPresolvedspace
-% /Function \PDFobjectreference\space
-% /Coords [\MPshadeC]
-% /Extend [true true]}%
-% \doPDFgetobjectreference{FDF}{obj:Sh:\the\currentPDFshade}\PDFobjectreference
-% \appendtoPDFdocumentshades{/Sh\the\currentPDFshade\space\PDFobjectreference}%
-% \setxvalue{\@@MPSK#2}{\noexpand\dohandleMPshade{\the\currentPDFshade}}}
-
-\def\dosetMPsomePDFshade#1#2%
- {\immediate\pdfobj
- {<>}%
- \immediate\pdfobj
- {<>}%
- \global\advance\currentPDFshade \plusone
- \appendtoPDFdocumentshades{/Sh\the\currentPDFshade\space\the\pdflastobj\space0 R }%
- \setxvalue{\@@MPSK#2}{\noexpand\dohandleMPshade{\the\currentPDFshade}}}
-
-\def\dosetMPlinearshade {\dosetMPsomePDFshade2}% #1
-\def\dosetMPcircularshade{\dosetMPsomePDFshade3}% #1
-
-\defineMPspecial{30}
- {\expanded{\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
- \expanded{\resolveMPrgbcolor{\gMPs{9}}{\gMPs{10}}{\gMPs{11}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs{12} \gMPs{13}}%
- \dosetMPlinearshade{\gMPs{14}}}
-
-\defineMPspecial{31}
- {\expanded{\resolveMPrgbcolor{\gMPs4}{\gMPs5}{\gMPs6}}\to\MPshadeA
- \expanded{\resolveMPrgbcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs7 \gMPs8 \gMPs9 \gMPs{13} \gMPs{14} \gMPs{15}}%
- \dosetMPcircularshade{\gMPs{16}}}
-
-\defineMPspecial{32}
- {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
- \expanded{\resolveMPcmykcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
- \dosetMPlinearshade{\gMPs{16}}}
-
-\defineMPspecial{33}
- {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
- \expanded{\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
- \dosetMPcircularshade{\gMPs{18}}}
-
-\defineMPspecial{34}
- {\expanded{\resolveMPspotcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
- \expanded{\resolveMPspotcolor{\gMPs{10}}{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{14} \gMPs{15}}%
- \dosetMPlinearshade{\gMPs{16}}}
-
-\defineMPspecial{35}
- {\expanded{\resolveMPcmykcolor{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}}\to\MPshadeA
- \expanded{\resolveMPcmykcolor{\gMPs{11}}{\gMPs{12}}{\gMPs{13}}{\gMPs{14}}}\to\MPshadeB
- \edef\MPshadeC{\gMPs8 \gMPs9 \gMPs{10} \gMPs{15} \gMPs{16} \gMPs{17}}%
- \dosetMPcircularshade{\gMPs{18}}}
-
-
-\newconditional\ignoreMPpath
-
-\def\dohandleMPshade#1%
- {\revokeMPtransparencyspecial
- \settrue\ignoreMPpath
- \def\extraMPpathcode{/Sh#1 sh Q}%
- \chardef\finiMPpath\zerocount
- \PDFcode{q /Pattern cs}}
-
-%D Figure inclusion is kind of strange to \METAPOST, but when
-%D Santiago Muelas started discussing this with me, I was able
-%D to cook up a solution using specials.
-
-\defineMPspecial{10}
- {\setxvalue{\@@MPSK\gMPs8}%
- {\noexpand\handleMPfigurespecial{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}{\gMPs7}{\gMPs8}}}
-
-\def\handleMPfigurespecial#1#2#3#4#5#6#7#8% todo : combine with ext fig
- {\global\letvalue{\@@MPSK#8}\empty
- \vbox to \zeropoint
- {\vss
- \hbox to \zeropoint
- {\ifcase\pdfoutput\or % will be hooked into the special driver
- \doiffileelse{#7}
- {\doifundefinedelse{mps:x:#7}
- {\immediate\pdfximage\!!width\onebasepoint\!!height\onebasepoint{#7}%
- \setxvalue{mps:x:#7}{\pdfrefximage\the\pdflastximage}}%
- {\message{[reusing figure #7]}}%
- \PDFcode{q #1 #2 #3 #4 #5 #6 cm}%
- \rlap{\getvalue{mps:x:#7}}%
- \PDFcode{Q}}
- {\message{[unknown figure #7]}}%
- \fi
- \hss}}}
-
-%D An example of using both special features is the
-%D following.
-%D
-%D \starttyping
-%D \startMPpage
-%D externalfigure "hakker1b.png" scaled 22cm rotated 10 shifted (-2cm,0cm);
-%D externalfigure "hakker1b.png" scaled 10cm rotated -10 ;
-%D externalfigure "hakker1b.png" scaled 7cm rotated 45 shifted (8cm,12cm) ;
-%D path p ; p := unitcircle xscaled 15cm yscaled 20cm;
-%D path q ; q := p rotatedaround(center p,90) ;
-%D path r ; r := buildcycle(p,q) ; clip currentpicture to r ;
-%D path s ; s := boundingbox currentpicture enlarged 5mm ;
-%D picture c ; c := currentpicture ; currentpicture := nullpicture ;
-%D circular_shade(s,0,.2red,.9red) ;
-%D addto currentpicture also c ;
-%D \stopMPpage
-%D \stoptyping
-
-%D This is some experimental hyperlink driver that I wrote
-%D for Mark Wicks.
-
-\defineMPspecial{20}
- {\setxvalue{\@@MPSK\gMPs6}%
- {\noexpand\handleMPhyperlink{\gMPs1}{\gMPs2}{\gMPs3}{\gMPs4}{\gMPs5}{\gMPs6}}}
-
-\def\handleMPhyperlink#1#2#3#4#5#6%
- {\global\letvalue{\@@MPSK#6}\empty
- \setbox\scratchbox\hbox
- {\setbox\scratchbox\null
- \wd\scratchbox\dimexpr-#1\onebasepoint+#3\onebasepoint\relax
- \ht\scratchbox\dimexpr-#2\onebasepoint+#4\onebasepoint\relax
- \incolorfalse
- \gotobox{\box\scratchbox}[#5]}%
- \setbox\scratchbox\hbox
- {\hskip\dimexpr\MPxoffset\onebasepoint+#1\onebasepoint\relax
- \raise\dimexpr\MPyoffset\onebasepoint+#2\onebasepoint\relax
- \box\scratchbox}%
- \smashbox\scratchbox
- \box\scratchbox}
-
-%D This special (number 50) passes positions to a tex file.
-%D This method uses a two||pass approach an (mis|)|used the
-%D context positioning macros. In \type {core-pos} we will
-%D implement the low level submacro needed.
-%D
-%D \startbuffer
-%D \definelayer[test]
-%D
-%D \setlayer
-%D [test]
-%D [x=\MPx{somepos-1},y=\MPy{somepos-1}]
-%D {Whatever we want here!}
-%D
-%D \setlayer
-%D [test]
-%D [x=\MPx{somepos-2},y=\MPy{somepos-2}]
-%D {Whatever we need there!}
-%D
-%D \startuseMPgraphic{oeps}
-%D draw fullcircle scaled 6cm withcolor red ;
-%D register ("somepos-1",1cm,2cm,center currentpicture) ;
-%D register ("somepos-2",4cm,3cm,(-1cm,-2cm)) ;
-%D \stopuseMPgraphic
-%D
-%D \framed[background=test,offset=overlay]{\useMPgraphic{oeps}}
-%D \stopbuffer
-%D
-%D \typebuffer
-%D
-%D Here the width and height are not realy used, but one can
-%D imagine situations where tex has to work with values
-%D calculated by \METAPOST.
-%D
-%D \startlinecorrection
-%D \getbuffer
-%D \stoplinecorrection
-%D
-%D Later we will implement a more convenient macro:
-%D
-%D \starttyping
-%D \setMPlayer [test] [somepos-1] {Whatever we want here!}
-%D \setMPlayer [test] [somepos-2] {Whatever we need there!}
-%D \stoptyping
-
-\defineMPspecial{50} % x y width height label
- {\dosavepositionwhd
- {\gMPs5}%
- {0}%
- {\the\dimexpr-\MPllx\onebasepoint+\gMPs1\onebasepoint\relax}
- {\the\dimexpr\gMPs2\onebasepoint-\scratchdimen+\MPury\onebasepoint\relax}%
- {\the\dimexpr\gMPs3\onebasepoint\relax}%
- {\the\dimexpr\gMPs4\onebasepoint\relax}%
- {0pt}}
-
-%D A few auxiliary macros. This will move to colo-ini.
-
-\def\MPgrayspace{DeviceGray}
-\def\MPrgbspace {DeviceRGB}
-\def\MPcmykspace{DeviceCMYK}
-\let\MPspotspace\MPgrayspace
-
-\def\MPcmykBlack{0 0 0 0}
-\def\MPcmykWhite{0 0 0 1}
-
-\def\startMPcolorresolve
- {\bgroup
- \def\dostartgraycolormode##1%
- {\global\let\MPresolvedspace\MPgrayspace
- \xdef\MPresolvedcolor{##1}}%
- \def\dostartrgbcolormode ##1##2##3%
- {\global\let\MPresolvedspace\MPrgbspace
- \xdef\MPresolvedcolor{##1 ##2 ##3}}%
- \def\dostartcmykcolormode##1##2##3##4%
- {\global\let\MPresolvedspace\MPcmykspace
- \xdef\MPresolvedcolor{##1 ##2 ##3 ##4}}%
- \def\dostartspotcolormode##1##2%
- {\global\let\MPspotspace\empty % left over ?
- \xdef\MPresolvedspace{##1}%
- \xdef\MPresolvedcolor{##2}%
- \global\let\MPspotspace\MPresolvedspace}% signal
- \dostartgraycolormode\!!zerocount} % kind of hackery initialization
-
-\let\stopMPcolorresolve\egroup
-
-\def\resolveMPrgbcolor#1#2#3\to#4%
- {\startMPcolorresolve
- \execcolorR#1:#2:#3:0:0\od
- \stopMPcolorresolve
- \let#4\MPresolvedcolor}
-
-\def\resolveMPcmykcolor#1#2#3#4\to#5%
- {\startMPcolorresolve
- \execcolorC#1:#2:#3:#4:0:0\od
- \stopMPcolorresolve
- \let#5\MPresolvedcolor}
-
-\def\resolveMPgraycolor#1\end\to#2%
- {\startMPcolorresolve
- \execcolorS#1:0:0\od
- \stopMPcolorresolve
- \let#2\MPresolvedcolor}
-
-\def\resolveMPspotcolor#1#2#3#4\end\to#5%
- {\startMPcolorresolve
- \ifnum#2>\plusone
- \checkmultitonecolor{#1}%
- \fi
- \execcolorP#1:#2:#3:#4:0:0\od
- \stopMPcolorresolve
- \let#5\MPresolvedcolor}
-
-%D \macros
-%D {dogetPDFmediabox}
-%D
-%D The next macro can be used to find the mediabox of a \PDF\
-%D illustration.
-%D
-%D \starttyping
-%D \dogetPDFmediabox
-%D {filename}
-%D {new dimen}{new dimen}{new dimen}{new dimen}
-%D \stoptyping
-%D
-%D Beware of dimen clashes: this macro uses the 5~default
-%D scratch registers! When no file or mediabox is found, the
-%D dimensions are zeroed.
-
-\def\dogetPDFmediabox#1#2#3#4#5%
- {\bgroup
- \def\PDFxscale{1}%
- \def\PDFyscale{1}%
- \uncatcodespecials
- \endlinechar\minusone
- \def\checkPDFtypepage##1/Type /Page##2##3\done%
- {\ifx##2\relax
- \else\if##2s% accept /Page and /Pages
- \let\doprocessPDFline\findPDFmediabox
- \else
- \let\doprocessPDFline\findPDFmediabox
- \fi\fi}%
- \def\findPDFtypepage
- {\expandafter\checkPDFtypepage\fileline/Type /Page\relax\done}%
- \def\checkPDFmediabox##1/MediaBox##2##3\done%
- {\ifx##2\relax \else
- \setPDFmediabox##2##3\done
- \fileprocessedtrue
- \fi}%
- \def\findPDFmediabox
- {\expandafter\checkPDFmediabox\fileline/MediaBox\relax\done}%
- \let\doprocessPDFline\findPDFtypepage
- \doprocessfile\scratchread{#1}\doprocessPDFline
- \egroup
- \ifx\PDFxoffset\undefined
- #2=\zeropoint
- #3=\zeropoint
- #4=\zeropoint
- #5=\zeropoint
- \else
- #2=\PDFxoffset\onebasepoint
- #3=\PDFyoffset\onebasepoint
- #4=\PDFwidth
- #5=\PDFheight
- \fi}
-
-\def\setPDFboundingbox#1#2#3#4#5#6%
- {\dimen0=#1\dimen0=#5\dimen0
- \ScaledPointsToBigPoints{\number\dimen0}\PDFxoffset
- \dimen0=#3\dimen0=#5\dimen0
- \xdef\PDFwidth{\the\dimen0}%
- \dimen0=#2\dimen0=#6\dimen0
- \ScaledPointsToBigPoints{\number\dimen0}\PDFyoffset
- \dimen0=#4\dimen0=#6\dimen0
- \xdef\PDFheight{\the\dimen0}%
- \global\let\PDFxoffset\PDFxoffset
- \global\let\PDFyoffset\PDFyoffset}
-
-\def\setPDFmediabox#1[#2 #3 #4 #5]#6\done
- {\dimen2=#2\onebasepoint\dimen2=-\dimen2 % \dimen2=-#2\onebasepoint also works since tex handles --
- \dimen4=#3\onebasepoint\dimen4=-\dimen4 % \dimen4=-#3\onebasepoint also works since tex handles --
- \dimen6=#4\onebasepoint\advance\dimen6 \dimen2
- \dimen8=#5\onebasepoint\advance\dimen8 \dimen4
- \setPDFboundingbox{\dimen2}{\dimen4}{\dimen6}{\dimen8}\PDFxscale\PDFyscale}
-
-%D End of soon obsolete code.
-
-%D The plugins:
-
-\startMPinitializations
- mp_shade_version := 2 ;
-\stopMPinitializations
-
-\loadmarkfile{meta-pdf}
-
-%D Test code:
-
-% \startMPcode
-% fill fullcircle scaled 3cm withcolor red ;
-% fill fullcircle scaled 2cm withcolor green ;
-% fill fullcircle scaled 1cm withcolor blue ;
-% currentpicture := currentpicture shifted (-4cm,0) ;
-% fill fullcircle scaled 3cm withcolor cmyk(0,0,1,0) ;
-% fill fullcircle scaled 2cm withcolor cmyk(0,1,0,0) ;
-% fill fullcircle scaled 1cm withcolor cmyk(0,0,1,0) ;
-% currentpicture := currentpicture shifted (-4cm,0) ;
-% draw fullcircle scaled 3cm dashed evenly ;
-% draw fullcircle scaled 2cm dashed withdots ;
-% draw origin withpen pencircle scaled 3mm;
-% currentpicture := currentpicture shifted (-4cm,0) ;
-% fill fullcircle scaled 2cm shifted (-.5cm,+.5cm) withcolor transparent(1,.5,red);
-% fill fullcircle scaled 2cm shifted (-.5cm,-.5cm) withcolor transparent(1,.5,red);
-% fill fullcircle scaled 2cm shifted (+.5cm,+.5cm) withcolor transparent(1,.5,green);
-% fill fullcircle scaled 2cm shifted (+.5cm,-.5cm) withcolor transparent(1,.5,cmyk(1,0,1,.5));
-% currentpicture := currentpicture shifted (12cm,-4cm) ;
-% draw "o e p s" infont defaultfont scaled 2 shifted (-1cm,0) ;
-% currentpicture := currentpicture shifted (-4cm,0) ;
-% % bug: shift
-% draw fullcircle scaled 3cm withpen pencircle yscaled 3mm xscaled 2mm rotated 30 ;
-% draw fullcircle scaled 2cm withpen pencircle yscaled 3mm xscaled 2mm rotated 20 withcolor red ;
-% filldraw fullcircle scaled 1cm withpen pencircle yscaled 3mm xscaled 2mm rotated 10 withcolor green ;
-% currentpicture := currentpicture shifted (-4cm,0) ;
-% % shade cannot handle shift
-% circular_shade(fullcircle scaled 3cm,0,.2red,.9green) ;
-% circular_shade(fullcircle scaled 3cm shifted(+4cm,0),0,cmyk(1,0,0,0),cmyk(0,1,0,0)) ;
-% filldraw boundingbox currentpicture enlarged -3cm withpen pencircle scaled 1pt withcolor .5white ;
-% \stopMPcode
-
-% This code will move to meta-pdf.mkiv and the call to lua will move to the
-% converter code (saves a lua call). We will do this when we made the final
-% move to attribute bases color. Actually, we cannot use attributes for
-% switching colors in mp literals because grouping (qQ) interferes.
-
-\ifx\colorversion\undefined \else \ifnum\colorversion>\plusone
-
- \def\dohandleMPgraycolor #1{\ctxlua{ctx.pdffinishtransparency()
- ctx.pdfgrayliteral(\the\currentcolormodel,#1)}}
- \def\dohandleMPrgbcolor #1#2#3{\ctxlua{ctx.pdffinishtransparency()
- ctx.pdfrgbliteral (\the\currentcolormodel,#1,#2,#3)}}
- \def\dohandleMPcmykcolor#1#2#3#4{\ctxlua{ctx.pdffinishtransparency()
- ctx.pdfcmykliteral(\the\currentcolormodel,#1,#2,#3,#4)}}
- \def\dohandleMPspotcolor#1#2#3#4{\ctxlua{ctx.pdffinishtransparency()
- ctx.pdfspotliteral(\the\currentcolormodel,"#1",#2,"#3","#4")}}
-
- % we can combine the next calls
-
- \def\dohandleMPgraytransparency #1#2#3{\ctxlua{ctx.pdfgrayliteral(\the\currentcolormodel,#1)
- ctx.pdftransparencyliteral(#2,#3)}}
- \def\dohandleMPrgbtransparency #1#2#3#4#5{\ctxlua{ctx.pdfrgbliteral (\the\currentcolormodel,#1,#2,#3)
- ctx.pdftransparencyliteral(#4,#5)}}
- \def\dohandleMPcmyktransparency#1#2#3#4#5#6{\ctxlua{ctx.pdfcmykliteral(\the\currentcolormodel,#1,#2,#3,#4)
- ctx.pdftransparencyliteral(#5,#6)}}
- \def\dohandleMPspottransparency#1#2#3#4#5#6{\ctxlua{ctx.pdfspotliteral(\the\currentcolormodel,"#1",#2,"#3","#4")
- ctx.pdftransparencyliteral(#5,#6)}}
-
- \def\dohandleMPresettransparency {\ctxlua{ctx.pdffinishtransparency()}}
-
- \def\resolveMPgraycolor #1\to#2{\ctxlua{ctx.resolvempgraycolor("\strippedcsname#2","MPresolvedspace",\number\currentcolormodel,#1)}}
- \def\resolveMPrgbcolor #1#2#3\to#4{\ctxlua{ctx.resolvemprgbcolor ("\strippedcsname#4","MPresolvedspace",\number\currentcolormodel,#1,#2,#3)}}
- \def\resolveMPcmykcolor#1#2#3#4\to#5{\ctxlua{ctx.resolvempcmykcolor("\strippedcsname#5","MPresolvedspace",\number\currentcolormodel,#1,#2,#3,#4)}}
-
- \def\resolveMPspotcolor#1#2#3#4\to#5% unchecked
- {\ctxlua{ctx.resolvempspotcolor("\strippedcsname#5","MPresolvedspace",\number\currentcolormodel,"#1",#2,"#3","#4")}%
- \xdef\MPresolvedspace{#1}%
- \xdef\MPresolvedcolor{#4}%
- \global\let\MPspotspace\MPresolvedspace}
-
- % used as callers
-
- \let\MPSgray\dohandleMPgraycolor
- \let\MPSrgb \dohandleMPrgbcolor
- \let\MPScmyk\dohandleMPcmykcolor
- \let\MPspot \dohandleMPspotcolor
-
-\fi \fi
-
-\protect \endinput
diff --git a/tex/context/base/meta-pdh.lua b/tex/context/base/meta-pdh.lua
new file mode 100644
index 000000000..e05529cc8
--- /dev/null
+++ b/tex/context/base/meta-pdh.lua
@@ -0,0 +1,630 @@
+if not modules then modules = { } end modules ['meta-pdf'] = {
+ version = 1.001,
+ comment = "companion to meta-pdf.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This file contains the history of the converter. We keep it around as it
+-- relates to the development of luatex.
+
+-- This is the third version. Version 1 converted to Lua code,
+-- version 2 gsubbed the file into TeX code, and version 3 uses
+-- the new lpeg functionality and streams the result into TeX.
+
+-- We will move old stuff to edu.
+
+--~ old lpeg 0.4 lpeg 0.5
+--~ 100 times test graphic 2.45 (T:1.07) 0.72 (T:0.24) 0.580 (0.560 no table) -- 0.54 optimized for one space (T:0.19)
+--~ 100 times big graphic 10.44 4.30/3.35 nogb 2.914 (2.050 no table) -- 1.99 optimized for one space (T:0.85)
+--~ 500 times test graphic T:1.29 T:1.16 (T:1.10 no table) -- T:1.10
+
+-- only needed for mp output on disk
+
+local concat, format = table.concat, string.format
+
+local ctxcatcodes = tex.ctxcatcodes
+
+mptopdf = { }
+mptopdf.parsers = { }
+mptopdf.parser = 'none'
+mptopdf.n = 0
+
+function mptopdf.reset()
+ mptopdf.data = ""
+ mptopdf.path = { }
+ mptopdf.stack = { }
+ mptopdf.texts = { }
+ mptopdf.version = 0
+ mptopdf.shortcuts = false
+ mptopdf.resetpath()
+end
+
+function mptopdf.resetpath()
+ mptopdf.stack.close = false
+ mptopdf.stack.path = { }
+ mptopdf.stack.concat = nil
+ mptopdf.stack.special = false
+end
+
+mptopdf.reset()
+
+function mptopdf.parsers.none()
+ -- no parser set
+end
+
+function mptopdf.parse()
+ mptopdf.parsers[mptopdf.parser]()
+end
+
+-- old code
+
+mptopdf.steps = { }
+
+mptopdf.descapes = {
+ ['('] = "\\\\char40 ",
+ [')'] = "\\\\char41 ",
+ ['"'] = "\\\\char92 "
+}
+
+function mptopdf.descape(str)
+ str = str:gsub("\\(%d%d%d)",function(n)
+ return "\\char" .. tonumber(n,8) .. " "
+ end)
+ return str:gsub("\\([%(%)\\])",mptopdf.descapes)
+end
+
+function mptopdf.steps.descape(str)
+ str = str:gsub("\\(%d%d%d)",function(n)
+ return "\\\\char" .. tonumber(n,8) .. " "
+ end)
+ return str:gsub("\\([%(%)\\])",mptopdf.descapes)
+end
+
+function mptopdf.steps.strip() -- .3 per expr
+ mptopdf.data = mptopdf.data:gsub("^(.-)%%+Page:.-%c+(.*)%s+%a+%s+%%+EOF.*$", function(preamble, graphic)
+ local bbox = "0 0 0 0"
+ for b in preamble:gmatch("%%%%%a+oundingBox: +(.-)%c+") do
+ bbox = b
+ end
+ local name, version = preamble:gmatch("%%%%Creator: +(.-) +(.-) ")
+ mptopdf.version = tostring(version or "0")
+ if preamble:find("/hlw{0 dtransform") then
+ mptopdf.shortcuts = true
+ end
+ -- the boundingbox specification needs to come before data, well, not really
+ return bbox .. " boundingbox\n" .. "\nbegindata\n" .. graphic .. "\nenddata\n"
+ end, 1)
+ mptopdf.data = mptopdf.data:gsub("%%%%MetaPostSpecials: +(.-)%c+", "%1 specials\n", 1)
+ mptopdf.data = mptopdf.data:gsub("%%%%MetaPostSpecial: +(.-)%c+", "%1 special\n")
+ mptopdf.data = mptopdf.data:gsub("%%.-%c+", "")
+end
+
+function mptopdf.steps.cleanup()
+ if not mptopdf.shortcuts then
+ mptopdf.data = mptopdf.data:gsub("gsave%s+fill%s+grestore%s+stroke", "both")
+ mptopdf.data = mptopdf.data:gsub("([%d%.]+)%s+([%d%.]+)%s+dtransform%s+exch%s+truncate%s+exch%s+idtransform%s+pop%s+setlinewidth", function(wx,wy)
+ if tonumber(wx) > 0 then return wx .. " setlinewidth" else return wy .. " setlinewidth" end
+ end)
+ mptopdf.data = mptopdf.data:gsub("([%d%.]+)%s+([%d%.]+)%s+dtransform%s+truncate%s+idtransform%s+setlinewidth%s+pop", function(wx,wy)
+ if tonumber(wx) > 0 then return wx .. " setlinewidth" else return wy .. " setlinewidth" end
+ end)
+ end
+end
+
+function mptopdf.steps.convert()
+ mptopdf.data = mptopdf.data:gsub("%c%((.-)%) (.-) (.-) fshow", function(str,font,scale)
+ mptopdf.texts[mptopdf.texts+1] = {mptopdf.steps.descape(str), font, scale}
+ return "\n" .. #mptopdf.texts .. " textext"
+ end)
+ mptopdf.data = mptopdf.data:gsub("%[%s*(.-)%s*%]", function(str)
+ return str:gsub("%s+"," ")
+ end)
+ local t
+ mptopdf.data = mptopdf.data:gsub("%s*([^%a]-)%s*(%a+)", function(args,cmd)
+ if cmd == "textext" then
+ t = mptopdf.texts[tonumber(args)]
+ return "mps.textext(" .. "\"" .. t[2] .. "\"," .. t[3] .. ",\"" .. t[1] .. "\")\n"
+ else
+ return "mps." .. cmd .. "(" .. args:gsub(" +",",") .. ")\n"
+ end
+ end)
+end
+
+function mptopdf.steps.process()
+ assert(loadstring(mptopdf.data))() -- () runs the loaded chunk
+end
+
+function mptopdf.parsers.gsub()
+ mptopdf.steps.strip()
+ mptopdf.steps.cleanup()
+ mptopdf.steps.convert()
+ mptopdf.steps.process()
+end
+
+-- end of old code
+
+-- from lua to tex
+
+function mptopdf.pdfcode(str)
+ tex.sprint(ctxcatcodes,"\\PDFcode{" .. str .. "}") -- \\MPScode
+end
+
+function mptopdf.texcode(str)
+ tex.sprint(ctxcatcodes,str)
+end
+
+-- auxiliary functions
+
+function mptopdf.flushconcat()
+ if mptopdf.stack.concat then
+ mptopdf.pdfcode(concat(mptopdf.stack.concat," ") .. " cm")
+ mptopdf.stack.concat = nil
+ end
+end
+
+function mptopdf.flushpath(cmd)
+ -- faster: no local function and ipairs
+ if #mptopdf.stack.path > 0 then
+ local path = { }
+ if mptopdf.stack.concat then
+ local sx, sy = mptopdf.stack.concat[1], mptopdf.stack.concat[4]
+ local rx, ry = mptopdf.stack.concat[2], mptopdf.stack.concat[3]
+ local tx, ty = mptopdf.stack.concat[5], mptopdf.stack.concat[6]
+ local d = (sx*sy) - (rx*ry)
+ local function mpconcat(px, py)
+ return (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d
+ end
+ local stackpath = mptopdf.stack.path
+ for k=1,#stackpath do
+ local v = stackpath[k]
+ v[1],v[2] = mpconcat(v[1],v[2])
+ if #v == 7 then
+ v[3],v[4] = mpconcat(v[3],v[4])
+ v[5],v[6] = mpconcat(v[5],v[6])
+ end
+ path[#path+1] = concat(v," ")
+ end
+ else
+ local stackpath = mptopdf.stack.path
+ for k=1,#stackpath do
+ path[#path+1] = concat(stackpath[k]," ")
+ end
+ end
+ mptopdf.flushconcat()
+ mptopdf.texcode("\\MPSpath{" .. concat(path," ") .. "}")
+ if mptopdf.stack.close then
+ mptopdf.texcode("\\MPScode{h " .. cmd .. "}")
+ else
+ mptopdf.texcode("\\MPScode{" .. cmd .."}")
+ end
+ end
+ mptopdf.resetpath()
+end
+
+function mptopdf.loaded(name)
+ local ok, n
+ mptopdf.reset()
+ ok, mptopdf.data, n = resolvers.loadbinfile(name, 'tex') -- we need a binary load !
+ return ok
+end
+
+if not mptopdf.parse then
+ function mptopdf.parse() end -- forward declaration
+end
+
+function mptopdf.convertmpstopdf(name)
+ if mptopdf.loaded(name) then
+ mptopdf.n = mptopdf.n + 1
+ statistics.starttiming(mptopdf)
+ mptopdf.parse()
+ mptopdf.reset()
+ statistics.stoptiming(mptopdf)
+ else
+ tex.print("file " .. name .. " not found")
+ end
+end
+
+-- mp interface
+
+mps = mps or { }
+
+function mps.creator(a, b, c)
+ mptopdf.version = tonumber(b)
+end
+
+function mps.creationdate(a)
+ mptopdf.date= a
+end
+
+function mps.newpath()
+ mptopdf.stack.path = { }
+end
+
+function mps.boundingbox(llx, lly, urx, ury)
+ mptopdf.texcode("\\MPSboundingbox{" .. llx .. "}{" .. lly .. "}{" .. urx .. "}{" .. ury .. "}")
+end
+
+function mps.moveto(x,y)
+ mptopdf.stack.path[#mptopdf.stack.path+1] = {x,y,"m"}
+end
+
+function mps.curveto(ax, ay, bx, by, cx, cy)
+ mptopdf.stack.path[#mptopdf.stack.path+1] = {ax,ay,bx,by,cx,cy,"c"}
+end
+
+function mps.lineto(x,y)
+ mptopdf.stack.path[#mptopdf.stack.path+1] = {x,y,"l"}
+end
+
+function mps.rlineto(x,y)
+ local dx, dy = 0, 0
+ if #mptopdf.stack.path > 0 then
+ dx, dy = mptopdf.stack.path[#mptopdf.stack.path][1], mptopdf.stack.path[#mptopdf.stack.path][2]
+ end
+ mptopdf.stack.path[#mptopdf.stack.path+1] = {dx,dy,"l"}
+end
+
+function mps.translate(tx,ty)
+ mptopdf.pdfcode("1 0 0 0 1 " .. tx .. " " .. ty .. " cm")
+end
+
+function mps.scale(sx,sy)
+ mptopdf.stack.concat = {sx,0,0,sy,0,0}
+end
+
+function mps.concat(sx, rx, ry, sy, tx, ty)
+ mptopdf.stack.concat = {sx,rx,ry,sy,tx,ty}
+end
+
+function mps.setlinejoin(d)
+ mptopdf.pdfcode(d .. " j")
+end
+
+function mps.setlinecap(d)
+ mptopdf.pdfcode(d .. " J")
+end
+
+function mps.setmiterlimit(d)
+ mptopdf.pdfcode(d .. " M")
+end
+
+function mps.gsave()
+ mptopdf.pdfcode("q")
+end
+
+function mps.grestore()
+ mptopdf.pdfcode("Q")
+end
+
+function mps.setdash(...)
+ local n = select("#",...)
+ mptopdf.pdfcode("[" .. concat({...}," ",1,n-1) .. "] " .. select(n,...) .. " d")
+end
+
+function mps.resetdash()
+ mptopdf.pdfcode("[ ] 0 d")
+end
+
+function mps.setlinewidth(d)
+ mptopdf.pdfcode(d .. " w")
+end
+
+function mps.closepath()
+ mptopdf.stack.close = true
+end
+
+function mps.fill()
+ mptopdf.flushpath('f')
+end
+
+function mps.stroke()
+ mptopdf.flushpath('S')
+end
+
+function mps.both()
+ mptopdf.flushpath('B')
+end
+
+function mps.clip()
+ mptopdf.flushpath('W n')
+end
+
+function mps.textext(font, scale, str) -- old parser
+ local dx, dy = 0, 0
+ if #mptopdf.stack.path > 0 then
+ dx, dy = mptopdf.stack.path[1][1], mptopdf.stack.path[1][2]
+ end
+ mptopdf.flushconcat()
+ mptopdf.texcode("\\MPStextext{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
+ mptopdf.resetpath()
+end
+
+--~ function mps.handletext(font,scale.str,dx,dy)
+--~ local one, two = string.match(str, "^(%d+)::::(%d+)")
+--~ if one and two then
+--~ mptopdf.texcode("\\MPTOPDFtextext{"..font.."}{"..scale.."}{"..one.."}{"..two.."}{"..dx.."}{"..dy.."}")
+--~ else
+--~ mptopdf.texcode("\\MPTOPDFtexcode{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
+--~ end
+--~ end
+
+if false and ctx and ctx.aux and ctx.aux.definecolor then
+
+ logs.report("mptopdf", "using attribute based mps colors")
+
+ -- does not work due to Q-q mess-up
+
+ function mps.setrgbcolor(r,g,b) -- extra check
+ r, g, b = tonumber(r), tonumber(g), tonumber(b) -- needed when we use lpeg
+ if r == 0.0123 and g < 0.1 then -- g is extra check
+ mptopdf.texcode("\\doresetattribute{transparency}\\MPSspecial{" .. g*10000 .. "}{" .. b*10000 .. "}")
+ elseif r == 0.123 and g < 0.1 then -- g is extra check
+ mptopdf.texcode("\\doresetattribute{transparency}\\MPSspecial{" .. g* 1000 .. "}{" .. b* 1000 .. "}")
+ else
+ mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'rgb',r,g,b) .. "}")
+ end
+ end
+
+ function mps.setcmykcolor(c,m,y,k)
+ mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'cmyk',tonumber(c),tonumber(m),tonumber(y),tonumber(k)) .. "}")
+ end
+
+ function mps.setgray(s)
+ mptopdf.texcode("\\doresetattribute{transparency}\\dosetattribute{color}{" .. colors.register('color',nil,'gray',tonumber(s)) .. "}")
+ end
+
+else
+
+ function mps.setrgbcolor(r,g,b) -- extra check
+ r, g = tonumber(r), tonumber(g) -- needed when we use lpeg
+ if r == 0.0123 and g < 0.1 then
+ mptopdf.texcode("\\MPSspecial{" .. g*10000 .. "}{" .. b*10000 .. "}")
+ elseif r == 0.123 and g < 0.1 then
+ mptopdf.texcode("\\MPSspecial{" .. g* 1000 .. "}{" .. b* 1000 .. "}")
+ else
+ mptopdf.texcode("\\MPSrgb{" .. r .. "}{" .. g .. "}{" .. b .. "}")
+ end
+ end
+
+ function mps.setcmykcolor(c,m,y,k)
+ mptopdf.texcode("\\MPScmyk{" .. c .. "}{" .. m .. "}{" .. y .. "}{" .. k .. "}")
+ end
+
+ function mps.setgray(s)
+ mptopdf.texcode("\\MPSgray{" .. s .. "}")
+ end
+
+end
+
+function mps.specials(version,signal,factor) -- 2.0 123 1000
+end
+
+function mps.special(...) -- 7 1 0.5 1 0 0 1 3
+ local n = select("#",...)
+ mptopdf.texcode("\\MPSbegin\\MPSset{" .. concat({...},"}\\MPSset{",2,n) .. "}\\MPSend")
+end
+
+function mps.begindata()
+end
+
+function mps.enddata()
+end
+
+function mps.showpage()
+end
+
+mps.n = mps.newpath -- n
+mps.p = mps.closepath -- h
+mps.l = mps.lineto -- l
+mps.r = mps.rlineto -- r
+mps.m = mps.moveto -- m
+mps.c = mps.curveto -- c
+mps.hlw = mps.setlinewidth
+mps.vlw = mps.setlinewidth
+
+mps.C = mps.setcmykcolor -- k
+mps.G = mps.setgray -- g
+mps.R = mps.setrgbcolor -- rg
+
+mps.lj = mps.setlinejoin -- j
+mps.ml = mps.setmiterlimit -- M
+mps.lc = mps.setlinecap -- J
+mps.sd = mps.setdash -- d
+mps.rd = mps.resetdash
+
+mps.S = mps.stroke -- S
+mps.F = mps.fill -- f
+mps.B = mps.both -- B
+mps.W = mps.clip -- W
+
+mps.q = mps.gsave -- q
+mps.Q = mps.grestore -- Q
+
+mps.s = mps.scale -- (not in pdf)
+mps.t = mps.concat -- (not the same as pdf anyway)
+
+mps.P = mps.showpage
+
+-- experimental
+
+function mps.attribute(id,value)
+ mptopdf.texcode("\\attribute " .. id .. "=" .. value .. " ")
+-- mptopdf.texcode("\\dompattribute{" .. id .. "}{" .. value .. "}")
+end
+
+-- lpeg parser
+
+-- The lpeg based parser is rather optimized for the kind of output
+-- that MetaPost produces. It's my first real lpeg code, which may
+-- show. Because the parser binds to functions, we define it last.
+
+do -- assumes \let\c\char
+
+ local byte = string.byte
+ local digit = lpeg.R("09")
+ local spec = digit^2 * lpeg.P("::::") * digit^2
+ local text = lpeg.Cc("{") * (
+ lpeg.P("\\") * ( (digit * digit * digit) / function(n) return "c" .. tonumber(n,8) end) +
+ lpeg.P(" ") / function(n) return "\\c32" end + -- never in new mp
+ lpeg.P(1) / function(n) return "\\c" .. byte(n) end
+ ) * lpeg.Cc("}")
+ local package = lpeg.Cs(spec + text^0)
+
+ function mps.fshow(str,font,scale) -- lpeg parser
+ mps.textext(font,scale,package:match(str))
+ end
+
+end
+
+do
+
+ local eol = lpeg.S('\r\n')^1
+ local sp = lpeg.P(' ')^1
+ local space = lpeg.S(' \r\n')^1
+ local number = lpeg.S('0123456789.-+')^1
+ local nonspace = lpeg.P(1-lpeg.S(' \r\n'))^1
+
+ local cnumber = lpeg.C(number)
+ local cstring = lpeg.C(nonspace)
+
+ local specials = (lpeg.P("%%MetaPostSpecials:") * sp * (cstring * sp^0)^0 * eol) / mps.specials
+ local special = (lpeg.P("%%MetaPostSpecial:") * sp * (cstring * sp^0)^0 * eol) / mps.special
+ local boundingbox = (lpeg.P("%%BoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
+ local highresboundingbox = (lpeg.P("%%HiResBoundingBox:") * sp * (cnumber * sp^0)^4 * eol) / mps.boundingbox
+
+ local setup = lpeg.P("%%BeginSetup") * (1 - lpeg.P("%%EndSetup") )^1
+ local prolog = lpeg.P("%%BeginProlog") * (1 - lpeg.P("%%EndProlog"))^1
+ local comment = lpeg.P('%')^1 * (1 - eol)^1
+
+ local curveto = ((cnumber * sp)^6 * lpeg.P("curveto") ) / mps.curveto
+ local lineto = ((cnumber * sp)^2 * lpeg.P("lineto") ) / mps.lineto
+ local rlineto = ((cnumber * sp)^2 * lpeg.P("rlineto") ) / mps.rlineto
+ local moveto = ((cnumber * sp)^2 * lpeg.P("moveto") ) / mps.moveto
+ local setrgbcolor = ((cnumber * sp)^3 * lpeg.P("setrgbcolor") ) / mps.setrgbcolor
+ local setcmykcolor = ((cnumber * sp)^4 * lpeg.P("setcmykcolor") ) / mps.setcmykcolor
+ local setgray = ((cnumber * sp)^1 * lpeg.P("setgray") ) / mps.setgray
+ local newpath = ( lpeg.P("newpath") ) / mps.newpath
+ local closepath = ( lpeg.P("closepath") ) / mps.closepath
+ local fill = ( lpeg.P("fill") ) / mps.fill
+ local stroke = ( lpeg.P("stroke") ) / mps.stroke
+ local clip = ( lpeg.P("clip") ) / mps.clip
+ local both = ( lpeg.P("gsave fill grestore")) / mps.both
+ local showpage = ( lpeg.P("showpage") )
+ local setlinejoin = ((cnumber * sp)^1 * lpeg.P("setlinejoin") ) / mps.setlinejoin
+ local setlinecap = ((cnumber * sp)^1 * lpeg.P("setlinecap") ) / mps.setlinecap
+ local setmiterlimit = ((cnumber * sp)^1 * lpeg.P("setmiterlimit") ) / mps.setmiterlimit
+ local gsave = ( lpeg.P("gsave") ) / mps.gsave
+ local grestore = ( lpeg.P("grestore") ) / mps.grestore
+
+ local setdash = (lpeg.P("[") * (cnumber * sp^0)^0 * lpeg.P("]") * sp * cnumber * sp * lpeg.P("setdash")) / mps.setdash
+ local concat = (lpeg.P("[") * (cnumber * sp^0)^6 * lpeg.P("]") * sp * lpeg.P("concat") ) / mps.concat
+ local scale = ( (cnumber * sp^0)^6 * sp * lpeg.P("concat") ) / mps.concat
+
+ local fshow = (lpeg.P("(") * lpeg.C((1-lpeg.P(")"))^1) * lpeg.P(")") * space * cstring * space * cnumber * space * lpeg.P("fshow")) / mps.fshow
+ local fshow = (lpeg.P("(") *
+ lpeg.Cs( ( lpeg.P("\\(")/"\\050" + lpeg.P("\\)")/"\\051" + (1-lpeg.P(")")) )^1 )
+ * lpeg.P(")") * space * cstring * space * cnumber * space * lpeg.P("fshow")) / mps.fshow
+
+ local setlinewidth_x = (lpeg.P("0") * sp * cnumber * sp * lpeg.P("dtransform truncate idtransform setlinewidth pop")) / mps.setlinewidth
+ local setlinewidth_y = (cnumber * sp * lpeg.P("0 dtransform exch truncate exch idtransform pop setlinewidth") ) / mps.setlinewidth
+
+ local c = ((cnumber * sp)^6 * lpeg.P("c") ) / mps.curveto -- ^6 very inefficient, ^1 ok too
+ local l = ((cnumber * sp)^2 * lpeg.P("l") ) / mps.lineto
+ local r = ((cnumber * sp)^2 * lpeg.P("r") ) / mps.rlineto
+ local m = ((cnumber * sp)^2 * lpeg.P("m") ) / mps.moveto
+ local vlw = ((cnumber * sp)^1 * lpeg.P("vlw")) / mps.setlinewidth
+ local hlw = ((cnumber * sp)^1 * lpeg.P("hlw")) / mps.setlinewidth
+
+ local R = ((cnumber * sp)^3 * lpeg.P("R") ) / mps.setrgbcolor
+ local C = ((cnumber * sp)^4 * lpeg.P("C") ) / mps.setcmykcolor
+ local G = ((cnumber * sp)^1 * lpeg.P("G") ) / mps.setgray
+
+ local lj = ((cnumber * sp)^1 * lpeg.P("lj") ) / mps.setlinejoin
+ local ml = ((cnumber * sp)^1 * lpeg.P("ml") ) / mps.setmiterlimit
+ local lc = ((cnumber * sp)^1 * lpeg.P("lc") ) / mps.setlinecap
+
+ local n = lpeg.P("n") / mps.newpath
+ local p = lpeg.P("p") / mps.closepath
+ local S = lpeg.P("S") / mps.stroke
+ local F = lpeg.P("F") / mps.fill
+ local B = lpeg.P("B") / mps.both
+ local W = lpeg.P("W") / mps.clip
+ local P = lpeg.P("P") / mps.showpage
+
+ local q = lpeg.P("q") / mps.gsave
+ local Q = lpeg.P("Q") / mps.grestore
+
+ local sd = (lpeg.P("[") * (cnumber * sp^0)^0 * lpeg.P("]") * sp * cnumber * sp * lpeg.P("sd")) / mps.setdash
+ local rd = ( lpeg.P("rd")) / mps.resetdash
+
+ local s = ( (cnumber * sp^0)^2 * lpeg.P("s") ) / mps.scale
+ local t = (lpeg.P("[") * (cnumber * sp^0)^6 * lpeg.P("]") * sp * lpeg.P("t") ) / mps.concat
+
+ -- experimental
+
+ local attribute = ((cnumber * sp)^2 * lpeg.P("attribute")) / mps.attribute
+ local A = ((cnumber * sp)^2 * lpeg.P("A")) / mps.attribute
+
+ local preamble = (
+ prolog + setup +
+ boundingbox + highresboundingbox + specials + special +
+ comment
+ )
+
+ local procset = (
+ lj + ml + lc +
+ c + l + m + n + p + r +
+ A +
+ R + C + G +
+ S + F + B + W +
+ vlw + hlw +
+ Q + q +
+ sd + rd +
+ t + s +
+ fshow +
+ P
+ )
+
+ local verbose = (
+ curveto + lineto + moveto + newpath + closepath + rlineto +
+ setrgbcolor + setcmykcolor + setgray +
+ attribute +
+ setlinejoin + setmiterlimit + setlinecap +
+ stroke + fill + clip + both +
+ setlinewidth_x + setlinewidth_y +
+ gsave + grestore +
+ concat + scale +
+ fshow +
+ setdash + -- no resetdash
+ showpage
+ )
+
+ -- order matters in terms of speed / we could check for procset first
+
+ local captures_old = ( space + verbose + preamble )^0
+ local captures_new = ( space + procset + preamble + verbose )^0
+
+ function mptopdf.parsers.lpeg()
+ if mptopdf.data:find("%%%%BeginResource: procset mpost") then
+ captures_new:match(mptopdf.data)
+ else
+ captures_old:match(mptopdf.data)
+ end
+ end
+
+end
+
+mptopdf.parser = 'lpeg'
+
+-- status info
+
+statistics.register("mps conversion time",function()
+ local n = mptopdf.n
+ if n > 0 then
+ return format("%s seconds, %s conversions", statistics.elapsedtime(mptopdf),n)
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/meta-tex.mkii b/tex/context/base/meta-tex.mkii
index 5766f659f..bf733d550 100644
--- a/tex/context/base/meta-tex.mkii
+++ b/tex/context/base/meta-tex.mkii
@@ -191,7 +191,7 @@
\filtersometxt}
\long\def\filtersometxt#1\sometxt
- {\doifnextcharelse[\redofiltersometxt\dodofiltersometxt}
+ {\doifnextoptionalelse\redofiltersometxt\dodofiltersometxt}
% cleaner in mkiv
%
diff --git a/tex/context/base/metatex.tex b/tex/context/base/metatex.tex
new file mode 100644
index 000000000..c7ceb005d
--- /dev/null
+++ b/tex/context/base/metatex.tex
@@ -0,0 +1,145 @@
+%D \module
+%D [ file=metatex,
+%D version=2008.10.10,
+%D title=\METATEX,
+%D subtitle=\METATEX\ Format Generation,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=Hans Hagen / \CONTEXT\ Development Team]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This format is just a minimal layer on top of the \LUATEX\
+%D engine and will not provide high level functionality. It can
+%D be used as basis for dedicated (specialized) macro packages.
+%D
+%D A format is generated with the command;
+%D
+%D \starttyping
+%D luatools --make --compile metatex
+%D \stoptyping
+%D
+%D Remark: this is far from complete. We will gradually add
+%D more. Also, it's not yet clean what exactly will be part
+%D of it. This is a prelude to a configureable macro package.
+
+\catcode`\{=1 \catcode`\}=2 \catcode`\#=6
+
+\edef\metatexformat {\jobname}
+\edef\metatexversion{2007.04.03 13:01}
+
+\let\fmtname \metatexformat
+\let\fmtversion\metatexversion
+
+\ifx\normalinput\undefined \let\normalinput\input \fi
+
+\def\loadcorefile#1{\normalinput#1\relax}
+
+\loadcorefile{syst-ini.tex} % some basic commands and allocations that are expected down the line
+\loadcorefile{syst-pln.tex} % plain tex initializations of internal registers (no further code)
+
+\loadcorefile{luat-cod.tex} %
+\loadcorefile{luat-bas.tex} %
+\loadcorefile{luat-lib.tex} %
+
+% needs stripping:
+
+\loadcorefile{catc-ini.mkiv} % catcode table management
+\loadcorefile{catc-act.tex} % active character definition mechanisms
+\loadcorefile{catc-def.tex} % some generic catcode tables
+\loadcorefile{catc-ctx.tex} % a couple of context specific tables but expected by later modules
+\loadcorefile{catc-sym.tex} % some definitions related to \letter
+
+% helpers, maybe less
+
+\loadcorefile{syst-aux.tex} % a whole lot of auxiliary macros
+%loadcorefile{syst-lua.tex} % some helpers using lua instead
+%loadcorefile{syst-con.mkiv} % some rather basic conversions
+%loadcorefile{syst-fnt.mkiv}
+%loadcorefile{syst-str.mkiv}
+%loadcorefile{syst-rtp.mkiv}
+
+% not needed
+
+% \loadmarkfile{supp-fil}
+% \loadmarkfile{supp-dir}
+
+% characters
+
+\loadcorefile{char-utf.tex}
+\loadcorefile{char-ini.tex}
+\loadcorefile{char-enc.tex} % \registerctxluafile{char-enc}{1.001}
+
+% nodes
+
+\loadcorefile{node-ini.tex}
+%loadcorefile{node-fin.tex}
+%loadcorefile{node-par.tex}
+
+% attributes, not needed:
+
+%loadcorefile{attr-ini.tex}
+
+% regimes
+
+% \loadcorefile{regi-ini.mkiv}
+% \loadcorefile{regi-syn.tex}
+
+% languages
+
+% fonts
+
+% \loadcorefile{enco-ini.mkiv}
+% \loadcorefile{hand-ini.mkiv}
+
+\registerctxluafile{font-ini}{1.001}
+
+\registerctxluafile{node-fnt}{1.001}
+
+\registerctxluafile{font-enc}{1.001}
+\registerctxluafile{font-map}{1.001}
+\registerctxluafile{font-syn}{1.001}
+\registerctxluafile{font-tfm}{1.001}
+\registerctxluafile{font-afm}{1.001}
+\registerctxluafile{font-cid}{1.001}
+\registerctxluafile{font-ott}{1.001}
+\registerctxluafile{font-otf}{1.001}
+\registerctxluafile{font-otb}{1.001}
+\registerctxluafile{font-otn}{1.001}
+\registerctxluafile{font-ota}{1.001}
+\registerctxluafile{font-otp}{1.001}
+\registerctxluafile{font-otc}{1.001}
+%registerctxluafile{font-vf} {1.001}
+\registerctxluafile{font-def}{1.001}
+%registerctxluafile{font-ctx}{1.001}
+\registerctxluafile{font-xtx}{1.001}
+%registerctxluafile{font-fbk}{1.001}
+%registerctxluafile{font-ext}{1.001}
+\registerctxluafile{font-pat}{1.001}
+%registerctxluafile{font-chk}{1.001}
+
+%registerctxluafile{math-ini}{1.001}
+%registerctxluafile{math-dim}{1.001}
+%registerctxluafile{math-ent}{1.001}
+%registerctxluafile{math-ext}{1.001}
+%registerctxluafile{math-vfu}{1.001}
+%registerctxluafile{math-map}{1.001}
+%registerctxluafile{math-noa}{1.001}
+
+\registerctxluafile{task-ini}{1.001}
+
+%registerctxluafile{l-xml}{1.001} % needed for font database
+
+% plain
+
+%loadcorefile{syst-stp.tex} % stripped plain
+
+% why not ...
+
+\pdfoutput\plusone
+
+% done
+
+\errorstopmode \dump \endinput
diff --git a/tex/context/base/mlib-ctx.lua b/tex/context/base/mlib-ctx.lua
index 6ada8ad19..8109003ca 100644
--- a/tex/context/base/mlib-ctx.lua
+++ b/tex/context/base/mlib-ctx.lua
@@ -14,8 +14,8 @@ local sprint = tex.sprint
metapost = metapost or {}
metapost.defaultformat = "metafun"
-function metapost.graphic(mpsformat,str,preamble)
- local mpx = metapost.format(mpsformat or metapost.defaultformat)
+function metapost.graphic(instance,mpsformat,str,preamble)
+ local mpx = metapost.format(instance,mpsformat or metapost.defaultformat)
metapost.graphic_base_pass(mpx,str,preamble)
end
@@ -29,7 +29,7 @@ function metapost.filterclippath(result)
for o=1,#objects do
local object = objects[o]
if object.type == "start_clip" then
- return join(flushnormalpath(object.path,{ }),"\n")
+ return join(metapost.flushnormalpath(object.path,{ }),"\n")
end
end
end
@@ -37,3 +37,13 @@ function metapost.filterclippath(result)
end
return ""
end
+
+statistics.register("metapost processing time", function()
+ local n = metapost.n
+ if n > 0 then
+ return format("%s seconds, loading: %s seconds, execution: %s seconds, n: %s",
+ statistics.elapsedtime(metapost), statistics.elapsedtime(mplib), statistics.elapsedtime(metapost.exectime),n)
+ else
+ return nil
+ end
+end)
diff --git a/tex/context/base/mlib-pdf.lua b/tex/context/base/mlib-pdf.lua
index a12db3d82..9c5775a2d 100644
--- a/tex/context/base/mlib-pdf.lua
+++ b/tex/context/base/mlib-pdf.lua
@@ -6,10 +6,14 @@ if not modules then modules = { } end modules ['mlib-pdf'] = {
license = "see context related readme files",
}
-local format, join = string.format, table.concat
-local sprint = tex.sprint
+local format, concat = string.format, table.concat
+local texsprint = tex.sprint
local abs, sqrt, round = math.abs, math.sqrt, math.round
+local copy_node, write_node = node.copy, node.write
+
+local ctxcatcodes = tex.ctxcatcodes
+
metapost = metapost or { }
metapost.multipass = false
metapost.n = 0
@@ -52,35 +56,71 @@ function metapost.convert(result, trialrun, flusher, multipass)
return true -- done
end
-function metapost.comment(message)
- if message then
- sprint(tex.ctxcatcodes,format("\\MPLIBtoPDF{\\letterpercent\\space mps graphic %s: %s}", metapost.n, message))
+metapost.flushers = { }
+metapost.flushers.pdf = { }
+
+local savedliterals = nil
+
+local mpsliteral = nodes.register(node.new("whatsit",8))
+
+function metapost.flush_literal(d) -- \def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}}
+ if savedliterals then
+ local literal = copy_node(mpsliteral)
+ literal.data = savedliterals[d]
+ write_node(literal)
+ else
+ logs.report("metapost","problem flushing literal %s",d)
end
end
-metapost.flushers = { }
-metapost.flushers.pdf = { }
+function metapost.flush_reset()
+ savedliterals = nil
+end
+
+function metapost.flushers.pdf.comment(message)
+ if message then
+ message = format("%% mps graphic %s: %s", metapost.n, message)
+ if savedliterals then
+ local last = #savedliterals + 1
+ savedliterals[last] = message
+ texsprint(ctxcatcodes,"\\MPLIBtoPDF{",last,"}")
+ else
+ savedliterals = { message }
+ texsprint(ctxcatcodes,"\\MPLIBtoPDF{1}")
+ end
+ end
+end
function metapost.flushers.pdf.startfigure(n,llx,lly,urx,ury,message)
+ savedliterals = nil
metapost.n = metapost.n + 1
- sprint(tex.ctxcatcodes,format("\\startMPLIBtoPDF{%s}{%s}{%s}{%s}",llx,lly,urx,ury))
- if message then metapost.comment(message) end
+ texsprint(ctxcatcodes,format("\\startMPLIBtoPDF{%s}{%s}{%s}{%s}",llx,lly,urx,ury))
+ if message then metapost.flushers.pdf.comment(message) end
end
function metapost.flushers.pdf.stopfigure(message)
- if message then metapost.comment(message) end
- sprint(tex.ctxcatcodes,"\\stopMPLIBtoPDF")
+ if message then metapost.flushers.pdf.comment(message) end
+ texsprint(ctxcatcodes,"\\stopMPLIBtoPDF")
+ texsprint(ctxcatcodes,"\\ctxlua{metapost.flush_reset()}") -- maybe just at the beginning
end
function metapost.flushers.pdf.flushfigure(pdfliterals) -- table
if #pdfliterals > 0 then
- sprint(tex.ctxcatcodes,"\\MPLIBtoPDF{",join(pdfliterals,"\n"),"}")
+ pdfliterals = concat(pdfliterals,"\n")
+ if savedliterals then
+ local last = #savedliterals + 1
+ savedliterals[last] = pdfliterals
+ texsprint(ctxcatcodes,"\\MPLIBtoPDF{",last,"}")
+ else
+ savedliterals = { pdfliterals }
+ texsprint(ctxcatcodes,"\\MPLIBtoPDF{1}")
+ end
end
end
function metapost.flushers.pdf.textfigure(font,size,text,width,height,depth) -- we could save the factor
text = text:gsub(".","\\hbox{%1}") -- kerning happens in metapost (i have to check if this is true for mplib)
- sprint(tex.ctxcatcodes,format("\\MPLIBtextext{%s}{%s}{%s}{%s}{%s}",font,size,text,0,-number.dimenfactors.bp*depth))
+ texsprint(ctxcatcodes,format("\\MPLIBtextext{%s}{%s}{%s}{%s}{%s}",font,size,text,0,-number.dimenfactors.bp*depth))
end
local bend_tolerance = 131/65536
@@ -99,15 +139,15 @@ local function pen_characteristics(object)
end
end
-local function concat(px, py) -- no tx, ty here
+local function mpconcat(px, py) -- no tx, ty here / we can move this one inline if needed
return (sy*px-ry*py)/divider,(sx*py-rx*px)/divider
end
local function curved(ith,pth)
local d = pth.left_x - ith.right_x
- if abs(ith.right_x-ith.x_coord-d) <= bend_tolerance and abs(pth.x_coord-pth.left_x-d) <= bend_tolerance then
+ if abs(ith.right_x - ith.x_coord - d) <= bend_tolerance and abs(pth.x_coord - pth.left_x - d) <= bend_tolerance then
d = pth.left_y - ith.right_y
- if abs(ith.right_y-ith.y_coord-d) <= bend_tolerance and abs(pth.y_coord-pth.left_y-d) <= bend_tolerance then
+ if abs(ith.right_y - ith.y_coord - d) <= bend_tolerance and abs(pth.y_coord - pth.left_y - d) <= bend_tolerance then
return false
end
end
@@ -148,33 +188,35 @@ local function flushconcatpath(path, t, open)
for i=1,#path do
pth = path[i]
if not ith then
- t[#t+1] = format("%f %f m",concat(pth.x_coord,pth.y_coord))
+ t[#t+1] = format("%f %f m",mpconcat(pth.x_coord,pth.y_coord))
elseif curved(ith,pth) then
- local a, b = concat(ith.right_x,ith.right_y)
- local c, d = concat(pth.left_x,pth.left_y)
- t[#t+1] = format("%f %f %f %f %f %f c",a,b,c,d,concat(pth.x_coord, pth.y_coord))
+ local a, b = mpconcat(ith.right_x,ith.right_y)
+ local c, d = mpconcat(pth.left_x,pth.left_y)
+ t[#t+1] = format("%f %f %f %f %f %f c",a,b,c,d,mpconcat(pth.x_coord,pth.y_coord))
else
- t[#t+1] = format("%f %f l",concat(pth.x_coord, pth.y_coord))
+ t[#t+1] = format("%f %f l",mpconcat(pth.x_coord, pth.y_coord))
end
ith = pth
end
if not open then
local one = path[1]
if curved(pth,one) then
- local a, b = concat(pth.right_x,pth.right_y)
- local c, d = concat(one.left_x,one.left_y)
- t[#t+1] = format("%f %f %f %f %f %f c",a,b,c,d,concat(one.x_coord, one.y_coord))
+ local a, b = mpconcat(pth.right_x,pth.right_y)
+ local c, d = mpconcat(one.left_x,one.left_y)
+ t[#t+1] = format("%f %f %f %f %f %f c",a,b,c,d,mpconcat(one.x_coord, one.y_coord))
else
- t[#t+1] = format("%f %f l",concat(one.x_coord,one.y_coord))
+ t[#t+1] = format("%f %f l",mpconcat(one.x_coord,one.y_coord))
end
elseif #path == 1 then
-- special case .. draw point
local one = path[1]
- t[#t+1] = format("%f %f l",concat(one.x_coord,one.y_coord))
+ t[#t+1] = format("%f %f l",mpconcat(one.x_coord,one.y_coord))
end
return t
end
+metapost.flushnormalpath = flushnormalpath
+
metapost.specials = metapost.specials or { }
-- we have two extension handlers, one for pre and postscripts, and one for colors
@@ -287,7 +329,7 @@ function metapost.flush(result,flusher) -- pdf flusher, table en dan concat is s
end
local dl = currentobject.dash
if dl then
- local d = format("[%s] %i d",join(dl.dashes or {}," "),dl.offset)
+ local d = format("[%s] %i d",concat(dl.dashes or {}," "),dl.offset)
if d ~= dashed then
dashed = d
t[#t+1] = dashed
@@ -404,7 +446,7 @@ do
local flusher = {
startfigure = function()
t = { }
- sprint(tex.ctxcatcodes,"\\startnointerference")
+ texsprint(ctxcatcodes,"\\startnointerference")
end,
flushfigure = function(literals)
for i=1, #literals do
@@ -412,7 +454,7 @@ do
end
end,
stopfigure = function()
- sprint(tex.ctxcatcodes,"\\stopnointerference")
+ texsprint(ctxcatcodes,"\\stopnointerference")
end
}
@@ -428,9 +470,12 @@ function metapost.totable(result)
if figure then
local t = { }
local objects = figure:objects()
- for _, object in ipairs(objects) do
+ for o=1,#objects do
+ local object = objects[o]
local tt = { }
- for _, field in ipairs(mplib.fields(object)) do
+ local fields = mplib.fields(object)
+ for f=1,#fields do
+ local field = fields[f]
tt[field] = object[field]
end
t[#t+1] = tt
@@ -460,105 +505,3 @@ function metapost.colorconverter()
end
end
end
-
---~ -- obsolete code
---~
---~ -- the pen calculations are taken from metapost, first converted by
---~ -- taco from c to lua, and then optimized by hans, so all errors are his
---~
---~ local aspect_bound = 10/65536
---~ local aspect_default = 1/65536
---~ local eps = 0.0001
---~
---~ local function pyth(a,b)
---~ return sqrt(a*a + b*b) -- much faster than sqrt(a^2 + b^2)
---~ end
---~
---~ local function coord_range_x(h, dz) -- direction x
---~ local zlo, zhi = 0, 0
---~ for i=1, #h do
---~ local p = h[i]
---~ local z = p.x_coord
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ z = p.right_x
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ z = p.left_x
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ end
---~ return (zhi - zlo <= dz and aspect_bound) or aspect_default
---~ end
---~
---~ local function coord_range_y(h, dz) -- direction y
---~ local zlo, zhi = 0, 0
---~ for i=1, #h do
---~ local p = h[i]
---~ local z = p.y_coord
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ z = p.right_y
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ z = p.left_y
---~ if z < zlo then zlo = z elseif z > zhi then zhi = z end
---~ end
---~ return (zhi - zlo <= dz and aspect_bound) or aspect_default
---~ end
---~
---~ local function pen_characteristics(object)
---~ local p = object.pen[1]
---~ local x_coord, y_coord, left_x, left_y, right_x, right_y = p.x_coord, p.y_coord, p.left_x, p.left_y, p.right_x, p.right_y
---~ local wx, wy, width
---~ if right_x == x_coord and left_y == y_coord then
---~ wx = abs(left_x - x_coord)
---~ wy = abs(right_y - y_coord)
---~ else
---~ wx = pyth(left_x - x_coord, right_x - x_coord)
---~ wy = pyth(left_y - y_coord, right_y - y_coord)
---~ end
---~ if wy/coord_range_x(object.path, wx) >= wx/coord_range_y(object.path, wy) then
---~ width = wy
---~ else
---~ width = wx
---~ end
---~ sx, rx, ry, sy, tx, ty = left_x, left_y, right_x, right_y, x_coord, y_coord
---~ sx, rx, ry, sy = (sx-tx), (rx-ty), (ry-tx), (sy-ty) -- combine with previous
---~ if width ~= 1 then
---~ if width == 0 then
---~ sx, sy = 1, 1
---~ else
---~ rx, ry, sx, sy = rx/width, ry/width, sx/width, sy/width
---~ end
---~ end
---~ -- sx rx ry sy tx ty -> 1 0 0 1 0 0 is ok, but 0 0 0 0 0 0 not
---~ if true then
---~ if abs(sx) < eps then sx = eps end
---~ if abs(sy) < eps then sy = eps end
---~ else
---~ -- this block looks complicated but it only captures invalid transforms
---~ -- to be checked rx vs sx and so
---~ local det = sx/sy - ry/rx
---~ local aspect = 4*aspect_bound + aspect_default
---~ if abs(det) < aspect then
---~ local s
---~ if det >= 0 then
---~ s, aspect = 1, aspect - det
---~ else
---~ s, aspect = -1, -aspect - det -- - ?
---~ end
---~ local absrx, absry, abssy, abssx = abs(rx), abs(ry), abs(sy), abs(sx)
---~ if abssx + abssy >= absry + absrx then -- was yy
---~ if abssx > abssy then
---~ sy = sy + (aspect + s*abssx) / sx
---~ else
---~ sx = sx + (aspect + s*abssy) / sy
---~ end
---~ else
---~ if absry > absrx then
---~ rx = rx + (aspect + s*absry) / ry
---~ else
---~ ry = ry + (aspect + s*absrx) / rx
---~ end
---~ end
---~ end
---~ end
---~ divider = sx*sy - rx*ry
---~ return not (sx==1 and rx==0 and ry==0 and sy==1 and tx==0 and ty==0), width
---~ end
diff --git a/tex/context/base/mlib-pdf.tex b/tex/context/base/mlib-pdf.tex
index b7b8506ad..9a04d188f 100644
--- a/tex/context/base/mlib-pdf.tex
+++ b/tex/context/base/mlib-pdf.tex
@@ -15,7 +15,9 @@
\registerctxluafile{mlib-pdf}{1.001}
-\let\MPLIBtoPDF\pdfliteral
+% \let\MPLIBtoPDF\pdfliteral
+
+\def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}}
\def\MPLIBboundingbox#1#2#3#4%
{\xdef\MPllx{#1}%
@@ -26,7 +28,7 @@
\xdef\MPheight{\the\dimexpr#4\onebasepoint-#2\onebasepoint\relax}}
\def\startMPLIBtoPDF#1#2#3#4% watch the transparency reset
- {\hbox\bgroup
+ {\naturalhbox\bgroup
\MPLIBboundingbox{#1}{#2}{#3}{#4}%
\forgetall
\setbox\scratchbox\vbox\bgroup
diff --git a/tex/context/base/mlib-pps.lua b/tex/context/base/mlib-pps.lua
index 3d5187c0f..e210e4ee1 100644
--- a/tex/context/base/mlib-pps.lua
+++ b/tex/context/base/mlib-pps.lua
@@ -9,8 +9,13 @@ if not modules then modules = { } end modules ['mlib-pps'] = { -- prescript, pos
-- current limitation: if we have textext as well as a special color then due to
-- prescript/postscript overload we can have problems
-local format, concat, round = string.format, table.concat, math.round
+local format, gmatch, concat, round, match = string.format, string.gmatch, table.concat, math.round, string.match
local sprint = tex.sprint
+local tonumber, type = tonumber, type
+
+local ctxcatcodes = tex.ctxcatcodes
+
+local trace_textexts = false trackers.register("metapost.textexts", function(v) trace_textexts = v end)
colors = colors or { }
@@ -35,10 +40,11 @@ local colordata = { {}, {}, {}, {}, {} }
--~ => rest : r=123 g=n>10 b=whatever
function metapost.specials.register(str) -- only colors
- local size, content, n, class = str:match("^%%%%MetaPostSpecial: (%d+) (.*) (%d+) (%d+)$")
+ local size, content, n, class = match(str,"^%%%%MetaPostSpecial: (%d+) (.*) (%d+) (%d+)$")
if class then
+ -- use lpeg splitter
local data = { }
- for s in content:gmatch("[^ ]+") do
+ for s in gmatch(content,"[^ ]+") do
data[#data+1] = s
end
class, n = tonumber(class), tonumber(n)
@@ -110,7 +116,7 @@ function metapost.colorspec(cs)
end
function metapost.specials.tr(specification,object,result)
- local a, t = specification:match("^(.+),(.+)$")
+ local a, t = match(specification,"^(.+),(.+)$")
local before = a and t and function()
result[#result+1] = format("/Tr%s gs",transparencies.register('mp',a,t))
return object, result
@@ -122,23 +128,8 @@ function metapost.specials.tr(specification,object,result)
return object, before, nil, after
end
---~ -- possible speedup: hash registered colors
---~
---~ function metapost.specials.sp(specification,object,result) -- todo: color conversion
---~ local s = object.color[1]
---~ object.color = nil
---~ local before = function()
---~ local spec = specification:split(" ")
---~ ctx.registerspotcolor(spec[1])
---~ result[#result+1] = ctx.pdfcolor(colors.model,colors.register('color',nil,'spot',spec[1],spec[2],spec[3],s))
---~ return object, result
---~ end
---~ local after = function()
---~ result[#result+1] = "0 g 0 G"
---~ return object, result
---~ end
---~ return object, before, nil, nil
---~ end
+local specificationsplitter = lpeg.Ct(lpeg.splitat(" "))
+local colorsplitter = lpeg.Ct(lpeg.splitat(":"))
-- Unfortunately we cannot use cmyk colors natively because there is no
-- generic color allocation primitive ... it's just an rgbcolor color.. This
@@ -151,11 +142,11 @@ end
-- This is also an example of a simple plugin.
--~ function metapost.specials.cc(specification,object,result)
---~ object.color = specification:split(" ")
+--~ object.color = specificationsplitter:match(specification)
--~ return object, nil, nil, nil
--~ end
--~ function metapost.specials.cc(specification,object,result)
---~ local c = specification:split(" ")
+--~ local c = specificationsplitter:match(specification)
--~ local o = object.color[1]
--~ c[1],c[2],c[3],c[4] = o*c[1],o*c[2],o*c[3],o*c[4]
--~ return object, nil, nil, nil
@@ -176,7 +167,7 @@ function metapost.specials.fg(specification,object,result,flusher)
if sy == 0 then sy = 0.00001 end
local before = specification and function()
flusher.flushfigure(result)
- sprint(tex.ctxcatcodes,format("\\MPLIBfigure{%f}{%f}{%f}{%f}{%f}{%f}{%s}",sx,rx,ry,sy,tx,ty,specification))
+ sprint(ctxcatcodes,format("\\MPLIBfigure{%f}{%f}{%f}{%f}{%f}{%f}{%s}",sx,rx,ry,sy,tx,ty,specification))
return object, { }
end
return { } , before, nil, nil -- replace { } by object for tracing
@@ -210,22 +201,22 @@ function metapost.specials.cs(specification,object,result,flusher) -- spot color
nofshades = nofshades + 1
flusher.flushfigure(result)
result = { }
- local t = specification:split(" ")
+ local t = specificationsplitter:match(specification)
-- we need a way to move/scale
- local ca = t[4]:split(":")
- local cb = t[8]:split(":")
+ local ca = colorsplitter:match(t[4])
+ local cb = colorsplitter:match(t[8])
if round(ca[1]*10000) == 123 then ca = metapost.colorspec(ca) end
if round(cb[1]*10000) == 123 then cb = metapost.colorspec(cb) end
if type(ca) == "string" then
-- spot color, not supported, maybe at some point use the fallbacks
- sprint(tex.ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s %s %s}",
nofshades,
t[1], t[2], 0, 1, 1, "DeviceGray",
t[5], t[6], t[7], t[9], t[10], t[11]))
-- terrible hack, somehow does not work
--~ local a = ca:match("^([^ ]+)")
--~ local b = cb:match("^([^ ]+)")
---~ sprint(tex.ctxcatcodes,format("\\xMPLIBcircularshade{%s}{%s %s}{%s}{%s}{%s}{%s}{%s %s %s %s %s %s}",
+--~ sprint(ctxcatcodes,format("\\xMPLIBcircularshade{%s}{%s %s}{%s}{%s}{%s}{%s}{%s %s %s %s %s %s}",
--~ nofshades,
--~ --~ t[1], t[2], a, b, 1, "DeviceN",
--~ 0, 1, a, b, 1, "DeviceN",
@@ -250,7 +241,7 @@ function metapost.specials.cs(specification,object,result,flusher) -- spot color
ca[1], ca[2], ca[3] = a, a, a
cb[1], cb[2], cb[3] = b, b, b
end
- sprint(tex.ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f %.3f %.3f}{%.3f %.3f %.3f}{%s}{%s}{%s %s %s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f %.3f %.3f}{%.3f %.3f %.3f}{%s}{%s}{%s %s %s %s %s %s}",
nofshades,
t[1], t[2], ca[1], ca[2], ca[3], cb[1], cb[2], cb[3], 1, "DeviceRGB",
t[5], t[6], t[7], t[9], t[10], t[11]))
@@ -262,7 +253,7 @@ function metapost.specials.cs(specification,object,result,flusher) -- spot color
ca[1], ca[2], ca[3], ca[4] = 0, 0, 0, ca[1]
cb[1], cb[2], cb[3], ca[4] = 0, 0, 0, ca[1]
end
- sprint(tex.ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f %.3f %.3f %.3f}{%.3f %.3f %.3f %.3f}{%s}{%s}{%s %s %s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f %.3f %.3f %.3f}{%.3f %.3f %.3f %.3f}{%s}{%s}{%s %s %s %s %s %s}",
nofshades,
t[1], t[2], ca[1], ca[2], ca[3], ca[4], cb[1], cb[2], cb[3], cb[4], 1, "DeviceCMYK",
t[5], t[6], t[7], t[9], t[10], t[11]))
@@ -274,7 +265,7 @@ function metapost.specials.cs(specification,object,result,flusher) -- spot color
ca[1] = rgbtogray(ca[1],ca[2],ca[3])
cb[1] = rgbtogray(cb[1],cb[2],cb[3])
end
- sprint(tex.ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBcircularshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s %s %s}",
nofshades,
t[1], t[2], ca[1], cb[1], 1, "DeviceGray",
t[5], t[6], t[7], t[9], t[10], t[11]))
@@ -296,15 +287,15 @@ function metapost.specials.ls(specification,object,result,flusher)
nofshades = nofshades + 1
flusher.flushfigure(result)
result = { }
- local t = specification:split(" ")
+ local t = specificationsplitter:match(specification)
-- we need a way to move/scale
- local ca = t[4]:split(":")
- local cb = t[7]:split(":")
+ local ca = colorsplitter:match(t[4])
+ local cb = colorsplitter:match(t[7])
if round(ca[1]*10000) == 123 then ca = metapost.colorspec(ca) end
if round(cb[1]*10000) == 123 then cb = metapost.colorspec(cb) end
if type(ca) == "string" then
-- spot color, not supported, maybe at some point use the fallbacks
- sprint(tex.ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s}",
nofshades,
t[1], t[2], 0, 1, 1, "DeviceGray",
t[5], t[6], t[8], t[9]))
@@ -327,7 +318,7 @@ function metapost.specials.ls(specification,object,result,flusher)
ca[1], ca[2], ca[3] = a, a, a
cb[1], cb[2], cb[3] = b, b, b
end
- sprint(tex.ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f %.3f %.3f}{%.3f %.3f %.3f}{%s}{%s}{%s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f %.3f %.3f}{%.3f %.3f %.3f}{%s}{%s}{%s %s %s %s}",
nofshades,
t[1], t[2], ca[1], ca[2], ca[3], cb[1], cb[2], cb[3], 1, "DeviceRGB",
t[5], t[6], t[8], t[9]))
@@ -339,7 +330,7 @@ function metapost.specials.ls(specification,object,result,flusher)
ca[1], ca[2], ca[3], ca[4] = 0, 0, 0, ca[1]
cb[1], cb[2], cb[3], ca[4] = 0, 0, 0, ca[1]
end
- sprint(tex.ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f %.3f %.3f %.3f}{%.3f %.3f %.3f %.3f}{%s}{%s}{%s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f %.3f %.3f %.3f}{%.3f %.3f %.3f %.3f}{%s}{%s}{%s %s %s %s}",
nofshades,
t[1], t[2], ca[1], ca[2], ca[3], ca[4], cb[1], cb[2], cb[3], cb[4], 1, "DeviceCMYK",
t[5], t[6], t[8], t[9]))
@@ -351,7 +342,7 @@ function metapost.specials.ls(specification,object,result,flusher)
ca[1] = rgbtogray(ca[1],ca[2],ca[3])
cb[1] = rgbtogray(cb[1],cb[2],cb[3])
end
- sprint(tex.ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s}",
+ sprint(ctxcatcodes,format("\\MPLIBlinearshade{%s}{%s %s}{%.3f}{%.3f}{%s}{%s}{%s %s %s %s}",
nofshades,
t[1], t[2], ca[1], cb[1], 1, "DeviceGray",
t[5], t[6], t[8], t[9]))
@@ -373,10 +364,9 @@ end
local current_format, current_graphic
---~ metapost.first_box, metapost.last_box = 1000, 1100
-
+metapost.first_box = metapost.first_box or 1000
+metapost.last_box = metapost.last_box or 1100
metapost.textext_current = metapost.first_box
-metapost.trace_texttexts = false
metapost.multipass = false
function metapost.free_boxes()
@@ -393,49 +383,55 @@ end
function metapost.specials.tf(specification,object)
--~ print("setting", metapost.textext_current)
- local n, str = specification:match("^(%d+):(.+)$")
- if metapost.textext_current < metapost.last_box then
- metapost.textext_current = metapost.first_box + n - 1
- end
- if metapost.trace_texttexts then
- print("metapost", format("first pass: order %s, box %s",n,metapost.textext_current))
+ local n, str = match(specification,"^(%d+):(.+)$")
+ if n and str then
+ if metapost.textext_current < metapost.last_box then
+ metapost.textext_current = metapost.first_box + n - 1
+ end
+ if trace_textexts then
+ logs.report("metapost","first pass: order %s, box %s",n,metapost.textext_current)
+ end
+ sprint(ctxcatcodes,format("\\MPLIBsettext{%s}{%s}",metapost.textext_current,str))
+ metapost.multipass = true
end
- sprint(tex.ctxcatcodes,format("\\MPLIBsettext{%s}{%s}",metapost.textext_current,str))
- metapost.multipass = true
return { }, nil, nil, nil
end
function metapost.specials.ts(specification,object,result,flusher)
-- print("getting", metapost.textext_current)
- local n, str = specification:match("^(%d+):(.+)$")
- if metapost.trace_texttexts then
- print("metapost", format("second pass: order %s, box %s",n,metapost.textext_current))
- end
- local op = object.path
- local first, second, fourth = op[1], op[2], op[4]
- local tx, ty = first.x_coord , first.y_coord
- local sx, sy = second.x_coord - tx, fourth.y_coord - ty
- local rx, ry = second.y_coord - ty, fourth.x_coord - tx
- if sx == 0 then sx = 0.00001 end
- if sy == 0 then sy = 0.00001 end
- if not metapost.trace_texttexts then
- object.path = nil
- end
- local before = function() -- no need for function
- --~ flusher.flushfigure(result)
- --~ sprint(tex.ctxcatcodes,format("\\MPLIBgettext{%f}{%f}{%f}{%f}{%f}{%f}{%s}",sx,rx,ry,sy,tx,ty,metapost.textext_current))
- --~ result = { }
- result[#result+1] = format("q %f %f %f %f %f %f cm", sx,rx,ry,sy,tx,ty)
- flusher.flushfigure(result)
- if metapost.textext_current < metapost.last_box then
- metapost.textext_current = metapost.first_box + n - 1
+ local n, str = match(specification,"^(%d+):(.+)$")
+ if n and str then
+ if trace_textexts then
+ logs.report("metapost","second pass: order %s, box %s",n,metapost.textext_current)
end
- local b = metapost.textext_current
- sprint(tex.ctxcatcodes,format("\\MPLIBgettextscaled{%s}{%s}{%s}",b, metapost.sxsy(tex.wd[b],tex.ht[b],tex.dp[b])))
- result = { "Q" }
- return object, result
+ local op = object.path
+ local first, second, fourth = op[1], op[2], op[4]
+ local tx, ty = first.x_coord , first.y_coord
+ local sx, sy = second.x_coord - tx, fourth.y_coord - ty
+ local rx, ry = second.y_coord - ty, fourth.x_coord - tx
+ if sx == 0 then sx = 0.00001 end
+ if sy == 0 then sy = 0.00001 end
+ if not trace_textexts then
+ object.path = nil
+ end
+ local before = function() -- no need for function
+ --~ flusher.flushfigure(result)
+ --~ sprint(ctxcatcodes,format("\\MPLIBgettext{%f}{%f}{%f}{%f}{%f}{%f}{%s}",sx,rx,ry,sy,tx,ty,metapost.textext_current))
+ --~ result = { }
+ result[#result+1] = format("q %f %f %f %f %f %f cm", sx,rx,ry,sy,tx,ty)
+ flusher.flushfigure(result)
+ if metapost.textext_current < metapost.last_box then
+ metapost.textext_current = metapost.first_box + n - 1
+ end
+ local b = metapost.textext_current
+ sprint(ctxcatcodes,format("\\MPLIBgettextscaled{%s}{%s}{%s}",b, metapost.sxsy(tex.wd[b],tex.ht[b],tex.dp[b])))
+ result = { "Q" }
+ return object, result
+ end
+ return { }, before, nil, nil -- replace { } by object for tracing
+ else
+ return { }, nil, nil, nil -- replace { } by object for tracing
end
- return { }, before, nil, nil -- replace { } by object for tracing
end
function metapost.colorconverter()
@@ -689,24 +685,25 @@ do
end
---~ local factor = 65536*(7200/7227)
local factor = 65536*(7227/7200)
function metapost.edefsxsy(wd,ht,dp) -- helper for figure
- commands.edef("sx",(wd ~= 0 and 1/( wd /(factor))) or 0)
- commands.edef("sy",(wd ~= 0 and 1/((ht+dp)/(factor))) or 0)
+ local hd = ht + dp
+ commands.edef("sx",(wd ~= 0 and factor/wd) or 0)
+ commands.edef("sy",(hd ~= 0 and factor/hd) or 0)
end
function metapost.sxsy(wd,ht,dp) -- helper for text
- return (wd ~= 0 and 1/(wd/(factor))) or 0, (wd ~= 0 and 1/((ht+dp)/(factor))) or 0
+ local hd = ht + dp
+ return (wd ~= 0 and factor/wd) or 0, (hd ~= 0 and factor/hd) or 0
end
function metapost.text_texts_data()
local t, n = { }, 0
for i = metapost.first_box, metapost.last_box do
n = n + 1
- if metapost.trace_texttexts then
- print("metapost", format("passed data: order %s, box %s",n,i))
+ if trace_textexts then
+ logs.report("metapost","passed data: order %s, box %s",n,i)
end
if tex.box[i] then
t[#t+1] = format("_tt_w_[%i]:=%f;_tt_h_[%i]:=%f;_tt_d_[%i]:=%f;", n,tex.wd[i]/factor, n,tex.ht[i]/factor, n,tex.dp[i]/factor)
@@ -740,7 +737,7 @@ function metapost.graphic_base_pass(mpsformat,str,preamble)
local flushed = metapost.process(mpsformat, {
preamble,
"beginfig(1); ",
- "_trial_run_ := true ;",
+ "if unknown _trial_run_ : boolean _trial_run_ fi ; _trial_run_ := true ;",
str,
"endfig ;"
-- }, true, nil, true )
@@ -753,7 +750,7 @@ function metapost.graphic_base_pass(mpsformat,str,preamble)
if not flushed or not metapost.optimize then
-- tricky, we can only ask once for objects and therefore
-- we really need a second run when not optimized
- sprint(tex.ctxcatcodes,"\\ctxlua{metapost.graphic_extra_pass()}")
+ sprint(ctxcatcodes,"\\ctxlua{metapost.graphic_extra_pass()}")
end
else
metapost.process(mpsformat, {
@@ -782,17 +779,17 @@ end
function metapost.getclippath(data)
local mpx = metapost.format("metafun")
if mpx and data then
- input.starttiming(metapost)
- input.starttiming(metapost.exectime)
+ statistics.starttiming(metapost)
+ statistics.starttiming(metapost.exectime)
local result = mpx:execute(format("beginfig(1);%s;endfig;",data))
- input.stoptiming(metapost.exectime)
+ statistics.stoptiming(metapost.exectime)
if result.status > 0 then
print("error", result.status, result.error or result.term or result.log)
result = ""
else
result = metapost.filterclippath(result)
end
- input.stoptiming(metapost)
+ statistics.stoptiming(metapost)
sprint(result)
end
end
@@ -842,7 +839,7 @@ do -- not that beautiful but ok, we could save a md5 hash in the tui file !
local result = { }
if io.exists(mpyfile) then
local data = io.loaddata(mpyfile)
- for figure in data:gmatch("beginfig(.-)endfig") do
+ for figure in gmatch(data,"beginfig(.-)endfig") do
result[#result+1] = format("begingraphictextfig%sendgraphictextfig ;\n", figure)
end
io.savedata(mpyfile,concat(result,""))
diff --git a/tex/context/base/mlib-pps.tex b/tex/context/base/mlib-pps.tex
index 546b94f28..beaef044e 100644
--- a/tex/context/base/mlib-pps.tex
+++ b/tex/context/base/mlib-pps.tex
@@ -20,11 +20,6 @@
\immediate\pdfobj{<>}%
\appendtoPDFdocumentshades{/MpSh#1 \the\pdflastobj\space0 R }}
-% \def\xMPLIBcircularshade#1#2#3#4#5#6#7% nr domain color-a color-b ? colorspace oordinates
-% {\immediate\pdfobj{<>}%
-% \immediate\pdfobj{<>}%
-% \appendtoPDFdocumentshades{/MpSh#1 \the\pdflastobj\space0 R }}
-
\def\MPLIBlinearshade#1#2#3#4#5#6#7% nr domain color-a color-b ? colorspace oordinates
{\immediate\pdfobj{<>}%
\immediate\pdfobj{<>}%
@@ -50,20 +45,17 @@
% \pdfliteral{Q}}
\def\MPLIBgettextscaled#1#2#3%
- {\vbox to \zeropoint{\vss\hbox to \zeropoint{\scale[sx=#2,sy=#3]{\raise\dp#1\copy#1}\hss}}}
+ {\vbox to \zeropoint{\vss\hbox to \zeropoint{\black\scale[sx=#2,sy=#3]{\raise\dp#1\copy#1}\hss}}}
\def\MPLIBallocate#1%
{\newbox\MPLIBfirst
- \dorecurse{\numexpr#1-1\relax}{\newbox\MPLIBlast}%
+ \dorecurse{\numexpr#1-1\relax}{\let\MPLIBlast\relax\newbox\MPLIBlast}%
\MPLIBregister}
-\def\MPLIBregister
+\def\MPLIBregister % after allocate!
{\ctxlua{metapost.first_box, metapost.last_box = \number\MPLIBfirst, \number\MPLIBlast}}
-\appendtoks \MPLIBallocate{1000}\to \everydump
-\appendtoks \MPLIBregister \to \everyjob
-
\def\MPLIBgraphictext#1%
- {\startTEXpage[scale=10000]#1\stopTEXpage}
+ {\startTEXpage[\c!scale=10000]#1\stopTEXpage}
\protect \endinput
diff --git a/tex/context/base/mlib-run.lua b/tex/context/base/mlib-run.lua
index 1edd00be7..9a7ed6f39 100644
--- a/tex/context/base/mlib-run.lua
+++ b/tex/context/base/mlib-run.lua
@@ -23,7 +23,7 @@ if not modules then modules = { } end modules ['mlib-run'] = {
The directional helpers and pen analysis are more or less translated from the
code. It really helps that Taco know that source so well. Taco and I spent
quite some time on speeding up the and code. There is not
-much to gain, especially if on ekeeps in mind that when integrated in
+much to gain, especially if one keeps in mind that when integrated in
only a part of the time is spent in . Of course an integrated
approach is way faster than an external and processing time
nears zero.
@@ -33,13 +33,20 @@ local format = string.format
metapost = metapost or { }
+metapost.showlog = false
+metapost.lastlog = ""
+
+function metapost.resetlastlog()
+ metapost.lastlog = ""
+end
+
local function finder(name, mode, ftype)
if mode=="w" then
return name
- elseif input.aux.qualified_path(name) then
+ elseif file.is_qualified_path(name) then
return name
else
- return input.find_file(name,ftype)
+ return resolvers.find_file(name,ftype)
end
end
@@ -80,27 +87,27 @@ input %s ; dump ;
end
function metapost.make(name, target, version)
- input.starttiming(mplib)
+ statistics.starttiming(mplib)
target = file.replacesuffix(target or name, "mem")
local mpx = mplib.new ( table.merged (
metapost.parameters,
{
ini_version = true,
find_file = finder,
- job_name = file.stripsuffix(target),
+ job_name = file.removesuffix(target),
}
) )
if mpx then
- input.starttiming(metapost.exectime)
+ statistics.starttiming(metapost.exectime)
local result = mpx:execute(format(preamble,version or "unknown",name))
- input.stoptiming(metapost.exectime)
+ statistics.stoptiming(metapost.exectime)
mpx:finish()
end
- input.stoptiming(mplib)
+ statistics.stoptiming(mplib)
end
function metapost.load(name)
- input.starttiming(mplib)
+ statistics.starttiming(mplib)
local mpx = mplib.new ( table.merged (
metapost.parameters,
{
@@ -111,24 +118,24 @@ function metapost.load(name)
) )
local result
if mpx then
-if not mplib.pen_info then -- temp compatibility hack
- input.starttiming(metapost.exectime)
- result = mpx:execute("\\")
- input.stoptiming(metapost.exectime)
-end
+ if not mplib.pen_info then -- temp compatibility hack
+ statistics.starttiming(metapost.exectime)
+ result = mpx:execute("\\")
+ statistics.stoptiming(metapost.exectime)
+ end
else
result = { status = 99, error = "out of memory"}
end
- input.stoptiming(mplib)
+ statistics.stoptiming(mplib)
return mpx, result
end
function metapost.unload(mpx)
- input.starttiming(mplib)
+ statistics.starttiming(mplib)
if mpx then
mpx:finish()
end
- input.stoptiming(mplib)
+ statistics.stoptiming(mplib)
end
function metapost.reporterror(result)
@@ -143,6 +150,7 @@ function metapost.reporterror(result)
metapost.report("mp error: %s",(e=="" and "?") or e)
end
if not t and not e and l then
+ metapost.lastlog = metapost.lastlog .. "\n" .. l
metapost.report("mp log: %s",l)
else
metapost.report("mp error: unknown, no error, terminal or log messages")
@@ -153,21 +161,21 @@ function metapost.reporterror(result)
return true
end
-function metapost.checkformat(mpsinput, mpsformat)
+function metapost.checkformat(mpsinput, mpsformat, dirname)
mpsinput = file.addsuffix(mpsinput or "metafun", "mp")
- mpsformat = file.stripsuffix(file.basename(mpsformat or texconfig.formatname or tex.formatname or mpsinput))
- local mpsbase = file.stripsuffix(file.basename(mpsinput))
+ mpsformat = file.removesuffix(file.basename(mpsformat or texconfig.formatname or (tex and tex.formatname) or mpsinput))
+ local mpsbase = file.removesuffix(file.basename(mpsinput))
if mpsbase ~= mpsformat then
mpsformat = mpsformat .. "-" .. mpsbase
end
mpsformat = file.addsuffix(mpsformat, "mem")
- local pth = file.dirname(texconfig.formatname or "")
+ local pth = dirname or file.dirname(texconfig.formatname or "")
if pth ~= "" then
mpsformat = file.join(pth,mpsformat)
end
local the_version = environment.version or "unset version"
if lfs.isfile(mpsformat) then
- commands.writestatus("mplib","loading format: %s, name: %s", mpsinput, mpsformat)
+ commands.writestatus("mplib","loading '%s' from '%s'", mpsinput, mpsformat)
local mpx, result = metapost.load(mpsformat)
if mpx then
local result = mpx:execute("show mp_parent_version ;")
@@ -183,31 +191,28 @@ function metapost.checkformat(mpsinput, mpsformat)
end
end
else
- commands.writestatus("mplib","error in loading format: %s, name: %s", mpsinput, mpsformat)
+ commands.writestatus("mplib","error in loading '%s' from '%s'", mpsinput, mpsformat)
metapost.reporterror(result)
end
end
- commands.writestatus("mplib","making format: %s, name: %s", mpsinput, mpsformat)
+ commands.writestatus("mplib","making '%s' into '%s'", mpsinput, mpsformat)
metapost.make(mpsinput,mpsformat,the_version) -- somehow return ... fails here
if lfs.isfile(mpsformat) then
- commands.writestatus("mplib","loading format: %s, name: %s", mpsinput, mpsformat)
+ commands.writestatus("mplib","loading '%s' from '%s'", mpsinput, mpsformat)
return metapost.load(mpsformat)
else
- commands.writestatus("mplib","problems with format: %s, name: %s", mpsinput, mpsformat)
+ commands.writestatus("mplib","problems with '%s' from '%s'", mpsinput, mpsformat)
end
end
---~ if environment.initex then
---~ metapost.unload(metapost.checkformat("metafun"))
---~ end
-
-local mpxformats = {}
+local mpxformats = { }
-function metapost.format(name)
- local mpx = mpxformats[name]
+function metapost.format(instance,name)
+ name = name or instance
+ local mpx = mpxformats[instance]
if not mpx then
mpx = metapost.checkformat(name)
- mpxformats[name] = mpx
+ mpxformats[instance] = mpx
end
return mpx
end
@@ -231,26 +236,25 @@ function metapost.reset(mpx)
end
end
-metapost.showlog = false
-
function metapost.process(mpx, data, trialrun, flusher, multipass)
local converted, result = false, {}
if type(mpx) == "string" then
mpx = metapost.format(mpx) -- goody
end
if mpx and data then
- input.starttiming(metapost)
+ statistics.starttiming(metapost)
if type(data) == "table" then
for i=1,#data do
local d = data[i]
if d then
- input.starttiming(metapost.exectime)
+ statistics.starttiming(metapost.exectime)
result = mpx:execute(d)
- input.stoptiming(metapost.exectime)
+ statistics.stoptiming(metapost.exectime)
if not metapost.reporterror(result) then
if metapost.showlog then
local str = (result.term ~= "" and result.term) or "no terminal output"
if not str:is_empty() then
+ metapost.lastlog = metapost.lastlog .. "\n" .. str
metapost.report("mp log: %s",str)
end
end
@@ -263,21 +267,25 @@ function metapost.process(mpx, data, trialrun, flusher, multipass)
end
end
else
- input.starttiming(metapost.exectime)
+ statistics.starttiming(metapost.exectime)
result = mpx:execute(data)
- input.stoptiming(metapost.exectime)
+ statistics.stoptiming(metapost.exectime)
-- todo: error message
if not result then
metapost.report("mp error: no result object returned")
elseif result.status > 0 then
metapost.report("mp error: %s",(result.term or "no-term") .. "\n" .. (result.error or "no-error"))
- elseif metapost.showlog then
- metapost.report("mp info: %s",result.term or "no-term")
- elseif result.fig then
- converted = metapost.convert(result, trialrun, flusher, multipass)
+ else
+ if metapost.showlog then
+ metapost.lastlog = metapost.lastlog .. "\n" .. result.term
+ metapost.report("mp info: %s",result.term or "no-term")
+ end
+ if result.fig then
+ converted = metapost.convert(result, trialrun, flusher, multipass)
+ end
end
end
- input.stoptiming(metapost)
+ statistics.stoptiming(metapost)
end
return converted, result
end
@@ -289,3 +297,64 @@ end
function metapost.report(...)
logs.report("mplib",...)
end
+
+-- handy
+
+function metapost.directrun(formatname,filename,outputformat,astable,mpdata)
+ local fullname = file.addsuffix(filename,"mp")
+ local data = mpdata or io.loaddata(fullname)
+ if outputformat ~= "svg" then
+ outputformat = "mps"
+ end
+ if not data then
+ logs.simple("unknown file '%s'",filename or "?")
+ else
+ local mpx = metapost.checkformat(formatname,formatname,caches.setpath("formats"))
+ if not mpx then
+ logs.simple("unknown format '%s'",formatname or "?")
+ else
+ logs.simple("processing '%s'",(mpdata and (filename or "data")) or fullname)
+ local result = mpx:execute(data)
+ if not result then
+ logs.simple("error: no result object returned")
+ elseif result.status > 0 then
+ logs.simple("error: %s",(result.term or "no-term") .. "\n" .. (result.error or "no-error"))
+ else
+ if metapost.showlog then
+ metapost.lastlog = metapost.lastlog .. "\n" .. result.term
+ logs.simple("info: %s",result.term or "no-term")
+ end
+ local figures = result.fig
+ if figures then
+ local sorted = table.sortedkeys(figures)
+ if astable then
+ local result = { }
+ logs.simple("storing %s figures in table",#sorted)
+ for k, v in ipairs(sorted) do
+ if outputformat == "mps" then
+ result[v] = figures[v]:postscript()
+ else
+ result[v] = figures[v]:svg() -- (3) for prologues
+ end
+ end
+ return result
+ else
+ local basename = file.removesuffix(file.basename(filename))
+ for k, v in ipairs(sorted) do
+ local output
+ if outputformat == "mps" then
+ output = figures[v]:postscript()
+ else
+ output = figures[v]:svg() -- (3) for prologues
+ end
+ local outname = format("%s-%s.%s",basename,v,outputformat)
+ logs.simple("saving %s bytes in '%s'",#output,outname)
+ io.savedata(outname,output)
+ end
+ return #sorted
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/tex/context/base/mtx-context-arrange.tex b/tex/context/base/mtx-context-arrange.tex
new file mode 100644
index 000000000..9d0bb901b
--- /dev/null
+++ b/tex/context/base/mtx-context-arrange.tex
@@ -0,0 +1,105 @@
+% engine=luatex
+
+%D \module
+%D [ file=mtx-context-arrange,
+%D version=2009.03.21,
+%D title=\CONTEXT\ Extra Trickry,
+%D subtitle=Arrange Files,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This is a \TEXEXEC\ features that has been moved to \MKIV.
+
+% begin help
+%
+% usage: context --extra=arrange [options] list-of-files
+%
+% --sort : sort filenames first
+% --paperoffset=dimension : left-top-offset
+% --noduplex : singlesided (doublesided is default)
+% --backspace=dimension : extra left offset
+% --topspace=dimension : extra top offset
+% --marking : add cutmarks
+% --addempty=list : add empty pages at/after (comma separated list)
+% --printformat : 2UP, etc
+%
+% end help
+
+\doifdocumentargument {paperoffset} {
+ \definepapersize
+ [offset=\getdocumentargument{paperoffset}]
+}
+
+\doifdocumentargumentelse {noduplex} {yes} {
+ \setuppagenumbering
+ [alternative=doublesided]
+ \setdocumentargument{sided}{doublesided}
+} {
+ \setdocumentargument{sided}{singlesided}
+}
+
+\setdefaultdocumentargument {textwidth} {0cm}
+\setdefaultdocumentargument {backspace} {0cm}
+\setdefaultdocumentargument {topspace} {0cm}
+
+\setuplayout
+ [backspace=\getdocumentargument{backspace},
+ topspace=\getdocumentargument{topspace},
+ width=middle,
+ height=middle,
+ location=middle,
+ header=0pt,
+ footer=0pt]
+
+\doifdocumentargument {marking} {yes} {
+ \setuplayout
+ [marking=on]
+}
+
+\startluacode
+ local printformat = document.arguments.printformat or ""
+ if printformat == "" then
+ printformat = "normal"
+ elseif string.find(printformat,".*up") then
+ printformat = "2UP,\\v!rotated"
+ elseif string.find(printformat,".*down") then
+ printformat = "2DOWN,\\v!rotated"
+ elseif string.find(printformat,".*side") then
+ printformat = "2SIDE,\\v!rotated"
+ end
+ document.setargument("printformat",printformat)
+\stopluacode
+
+\setuparranging
+ [\getdocumentargument{sided},
+ \getdocumentargument{printformat}]
+
+\starttext
+
+\startluacode
+ local format = string.format
+ local fprint = function(...) tex.sprint(tex.ctxcatcodes,format(...)) end
+
+ if #document.files > 0 then
+ if document.arguments.sort then
+ table.sort(document.files)
+ end
+ local emptypages = document.arguments.addempty or ""
+ local textwidth = document.arguments.textwidth or "0cm"
+ for _, filename in ipairs(document.files) do
+ if not string.find(filename,"^mtx%-context%-") then
+ fprint("\\insertpages[%s][%s][width=%s]",filename,emptypages,textwidth)
+ end
+ end
+ else
+ fprint("no files given")
+ end
+\stopluacode
+
+\stoptext
+
diff --git a/tex/context/base/mtx-context-combine.tex b/tex/context/base/mtx-context-combine.tex
new file mode 100644
index 000000000..991e974ae
--- /dev/null
+++ b/tex/context/base/mtx-context-combine.tex
@@ -0,0 +1,146 @@
+% engine=luatex
+
+%D \module
+%D [ file=mtx-context-combine,
+%D version=2009.03.21,
+%D title=\CONTEXT\ Extra Trickry,
+%D subtitle=Combine Files,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This is a \TEXEXEC\ features that has been moved to \MKIV.
+
+% begin help
+%
+% usage: context --extra=combine [options] list-of-files
+%
+% --sort : sort filenames first
+% --paperoffset=dimension : left-top-offset
+% --nobanner : no footer etc
+% --combination : h*v or hxv
+% --paperformat : paper*print or paperxprint
+% --nobanner : no footerlines
+% --bannerheight : height of banner
+% --bannerstring : height of bannerstring
+%
+% end help
+
+\doifdocumentargumentelse {paperoffset} {
+
+ \setuplayout
+ [topspace=\getdocumentargument{paperoffset},
+ backspace=\getdocumentargument{paperoffset}]
+
+} {
+
+ \setuplayout
+ [topspace=0pt,
+ backspace=0pt]
+
+}
+
+\setuplayout
+ [header=0pt,
+ footer=0pt,
+ width=middle,
+ height=middle]
+
+\startluacode
+ local combination = document.arguments['combination'] or '2*2'
+ local nx, ny = string.match(combination,"^(%d+)%s*[%*x]%s*(%d+)$")
+ if not nx then
+ nx, ny = 2, 2
+ elseif not ny then
+ nx = tonumber(combination) or 2
+ ny = nx
+ else
+ nx = tonumber(nx) or 2
+ ny = tonumber(ny) or nx or 2
+ end
+ document.setargument("nx",nx)
+ document.setargument("ny",ny)
+\stopluacode
+
+\startluacode
+ local paperformat = document.arguments['paperformat'] or 'A4*A4'
+ paperformat = string.upper(paperformat)
+ local f, t = string.match(paperformat,"^(.-)%s*[%*xX]%s*(.-)$")
+ if not f then
+ f, t = "A4", "A4"
+ elseif not t then
+ t = f
+ end
+ document.setargument("from",f)
+ document.setargument("to",t)
+\stopluacode
+
+\setuppapersize
+ [\getdocumentargument{from}]
+ [\getdocumentargument{to}]
+
+\doifnotdocumentargument {bannerheight} {
+ \setuplayout
+ [footer=1cm]
+}
+
+\doifdocumentargumentelse {nobanner} {yes} {
+ \setuplayout
+ [footer=0cm]
+ \setupbackgrounds
+ [page]
+ [background=]
+} {
+ \definelayer
+ [page]
+ [width=\paperwidth,
+ height=\paperheight]
+
+ \setupbackgrounds
+ [page]
+ [background=page]
+}
+
+\setupexternalfigures
+ [directory=]
+
+\starttext
+
+\startluacode
+ local format = string.format
+ local fprint = function(...) tex.sprint(tex.ctxcatcodes,format(...)) end
+
+ if #document.files > 0 then
+ if document.arguments["sort"] then
+ table.sort(document.files)
+ end
+ local dobanner = not document.arguments["nobanner"]
+ local bannerheight = document.arguments["bannerheight"]
+ local nx = document.arguments.nx or 2
+ local ny = document.arguments.ny or 2
+ for _, filename in ipairs(document.files) do
+ if not string.find(filename,"^mtx%-context%-") then
+ -- could be a macro
+ local bannerstring = format("\\tttf\\detokenize{%s}\\quad\\quad\\currentdate\\quad\\quad\\pagenumber",file.basename(filename))
+ if dobanner then
+ if bannerheight then
+ fprint("\\setuptexttexts[{\\setlayerframed[page][preset=middlebottom][frame=off,height=%s]{%s}}]",bannerheight,bannerstring)
+ else
+ fprint("\\setupfootertexts[{%s}]",bannerstring)
+ end
+ end
+ fprint("\\combinepages[%s][nx=%s,ny=%s]",filename,nx,ny)
+ fprint("\\page")
+ end
+ end
+ else
+ fprint("no files given")
+ end
+\stopluacode
+
+\stoptext
+
diff --git a/tex/context/base/mtx-context-ideas.tex b/tex/context/base/mtx-context-ideas.tex
new file mode 100644
index 000000000..f1ef1d35f
--- /dev/null
+++ b/tex/context/base/mtx-context-ideas.tex
@@ -0,0 +1,54 @@
+% engine=luatex
+
+%D \module
+%D [ file=mtx-context-ideas,
+%D version=2009.03.21,
+%D title=\CONTEXT\ Extra Trickry,
+%D subtitle=Placeholder File,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% The hard coded goodies in texexec are now external. We also use this
+% opportunity to explore mixed tex/lua user interfacing so you will see
+% some old and new tricks here that might disappear or become extended.
+%
+% if users want to add their own ... go ahead but use a different
+% namespace:
+%
+% mtx-context-third-somename.tex
+% mtx-context-user-somename.tex
+
+% \startluacode
+% -- some day we might move the whole ui to lua
+% context = context or { }
+% function interfaces.tosetups(setups)
+% if not setups then
+% return ""
+% elseif type(setups) == "table" then
+% local t = { }
+% for k,v in next, setups do
+% t[k] = "{" .. v .. "}"
+% end
+% return table.concat(t,",")
+% else
+% return setups
+% end
+% end
+% function context.setuplayout(category,setups)
+% setups = setups or category
+% tex.sprint(string.format("\\setuplayout[%s]",interfaces.tosetups(setups))
+% end
+% local topspace = document.arguments["topspace"] or 0
+% if dimen(topspace) > dimen(0) then
+% context.setuplayout { topspace = dimen(topspace) }
+% end
+% local backspace = document.arguments["backspace"] or 0
+% if dimen(topspace) > dimen(0) then
+% context.setuplayout { backspace = dimen(backspace) }
+% end
+% \stopluacode
diff --git a/tex/context/base/mtx-context-listing.tex b/tex/context/base/mtx-context-listing.tex
new file mode 100644
index 000000000..5c978fc6a
--- /dev/null
+++ b/tex/context/base/mtx-context-listing.tex
@@ -0,0 +1,76 @@
+% engine=luatex
+
+%D \module
+%D [ file=mtx-context-listing,
+%D version=2008.11.10, % about that time i started playing with this
+%D title=\CONTEXT\ Extra Trickry,
+%D subtitle=Listing Files,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This is a \TEXEXEC\ features that has been moved to \MKIV.
+
+% begin help
+%
+% usage: context --extra=listing [options] list-of-files
+%
+% --sort : sort filenames first
+% --topspace=dimension : distance above first line
+% --backspace=dimension : distance before left margin
+% --pretty : pretty print comform suffix (temporarily disabled)
+%
+% end help
+
+\setupbodyfont
+ [11pt,tt]
+
+\setuplayout
+ [header=0cm,
+ footer=1.5cm,
+ width=middle,
+ height=middle]
+
+% todo: use \arguments{topspace}
+
+\startluacode
+ local topspace = document.arguments["topspace"] or 0
+ if dimen(topspace) > dimen(0) then
+ tex.sprint(string.format("\\setuplayout[topspace=%s]",dimen(topspace)))
+ end
+ local backspace = document.arguments["backspace"] or 0
+ if dimen(topspace) > dimen(0) then
+ tex.sprint(string.format("\\setuplayout[backspace=%s]",dimen(backspace)))
+ end
+\stopluacode
+
+\setuptyping
+ [lines=yes]
+
+\setuptyping
+ [option=color]
+
+\starttext
+
+\startluacode
+ if #document.files > 0 then
+ if document.arguments["sort"] then
+ table.sort(document.files)
+ end
+ for _, filename in ipairs(document.files) do
+ if not string.find(filename,"^mtx%-context%-") then
+ tex.sprint("\\page\n")
+ tex.sprint(string.format("\\setupfootertexts[\\detokenize{%s}][\\pagenumber]\n",file.basename(filename)))
+ tex.sprint(string.format("\\typefile{%s}",filename))
+ end
+ end
+ else
+ tex.sprint(tex.ctxcatcodes,"no files given")
+ end
+\stopluacode
+
+\stoptext
diff --git a/tex/context/base/mtx-context-timing.tex b/tex/context/base/mtx-context-timing.tex
new file mode 100644
index 000000000..51e6427f6
--- /dev/null
+++ b/tex/context/base/mtx-context-timing.tex
@@ -0,0 +1,46 @@
+% engine=luatex
+
+%D \module
+%D [ file=mtx-context-timing,
+%D version=2009.03.21,
+%D title=\CONTEXT\ Extra Trickry,
+%D subtitle=Timing Runs,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% begin help
+%
+% usage: context --extra=timing filename
+%
+% end help
+
+\enablemode[no-timing] \usemodule[timing]
+
+\setuplayout
+ [topspace=1cm,
+ bottomspace=.5cm,
+ header=0pt,
+ width=middle,
+ height=middle,
+ style=\tt]
+
+\setupfootertexts
+ [\getdocumentfilename{1}-luatex-progress.lut -- \pagenumber]
+
+\setupcolors
+ [state=start]
+
+\starttext
+
+ \doifsomething {\getdocumentfilename{1}} {
+ \LoadUsage{\getdocumentfilename{1}-luatex-progress}
+ \ShowUsage{\getdocumentfilename{1}-luatex-progress}
+ }
+
+\stoptext
+
diff --git a/tex/context/base/mult-chk.lua b/tex/context/base/mult-chk.lua
new file mode 100644
index 000000000..1c74d2e38
--- /dev/null
+++ b/tex/context/base/mult-chk.lua
@@ -0,0 +1,66 @@
+if not modules then modules = { } end modules ['mult-chk'] = {
+ version = 1.001,
+ comment = "companion to mult-chk.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+local type = type
+local texsprint = tex.sprint
+local ctxcatcodes = tex.ctxcatcodes
+
+interfaces = interfaces or { }
+
+interfaces.syntax = {
+ test = { keys = table.tohash { "a","b","c","d","e","f","g" } }
+}
+
+function interfaces.invalidkey(kind,key)
+ commands.writestatus("syntax","invalid key '%s' for '%s' in line %s",key,kind,tex.inputlineno)
+end
+
+function interfaces.setvalidkeys(kind,list)
+ local s = interfaces.syntax[kind]
+ if not s then
+ interfaces.syntax[kind] = {
+ keys = aux.settings_to_set(list)
+ }
+ else
+ s.keys = aux.settings_to_set(list)
+ end
+end
+
+function interfaces.addvalidkeys(kind,list)
+ local s = interfaces.syntax[kind]
+ if not s then
+ interfaces.syntax[kind] = {
+ keys = aux.settings_to_set(list)
+ }
+ else
+ aux.settings_to_set(list,s.keys)
+ end
+end
+
+local prefix, kind, keys
+
+local function set(key,value)
+ if keys and not keys[key] then
+ interfaces.invalidkey(kind,key)
+ else
+ texsprint(ctxcatcodes,format("\\setsomevalue{%s}{%s}{%s}",prefix,key,value))
+ end
+end
+
+local pattern = aux.make_settings_to_hash_pattern(set,true)
+
+function commands.getcheckedparameters(k,p,s)
+ if s and s ~= "" then
+ prefix, kind = p, k
+ keys = k and k ~= "" and interfaces.syntax[k].keys
+ pattern:match(s)
+ end
+end
+
+_gcp_ = commands.getcheckedparameters
diff --git a/tex/context/base/mult-chk.mkii b/tex/context/base/mult-chk.mkii
new file mode 100644
index 000000000..6299d0cda
--- /dev/null
+++ b/tex/context/base/mult-chk.mkii
@@ -0,0 +1,26 @@
+%D \module
+%D [ file=mult-chk,
+%D version=2009.04.13,
+%D title=\CONTEXT\ Multilingual Macros,
+%D subtitle=Checking,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Multilingual Macros / Checking}
+
+%D No checking in \MKII.
+
+\def\setvalidparameterkeys{\gobbleparameters} % forward reference, so no \let
+\def\addvalidparameterkeys{\gobbleparameters} % forward reference, so no \let
+
+\let\enablecheckparameters \relax
+\let\disablecheckparameters\relax
+
+\def\getcheckedparameters[#1]{\getparameters} % just ignore the checking
+
+\endinput
diff --git a/tex/context/base/mult-chk.mkiv b/tex/context/base/mult-chk.mkiv
new file mode 100644
index 000000000..7b40bd64a
--- /dev/null
+++ b/tex/context/base/mult-chk.mkiv
@@ -0,0 +1,103 @@
+%D \module
+%D [ file=mult-chk,
+%D version=2009.04.13,
+%D title=\CONTEXT\ Multilingual Macros,
+%D subtitle=Checking,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Multilingual Macros / Checking}
+
+%D This is very experimental code that eventually might be used
+%D once we have split the whole code base.
+
+%D \startbuffer
+%D \getcheckedparameters[MyTest][MyNamespace][a=1,b=2,c=3,d=4,crap=whatever]
+%D
+%D \MyNamespacea\quad
+%D \MyNamespaceb\quad
+%D \MyNamespacec\quad
+%D \MyNamespaced\quad
+%D crap is \ifdefined\MyNamespacecrap\else un\fi defined
+%D \stopbuffer
+%D
+%D \enablecheckparameters
+%D
+%D \setvalidparameterkeys[MyTest][a,b,c,d] \getbuffer \par
+%D \addvalidparameterkeys[MyTest][crap] \getbuffer \par
+
+\unprotect
+
+\registerctxluafile{mult-chk}{1.001}
+
+\def\setvalidparameterkeys{\dodoubleargument\dosetvalidparameterkeys}
+\def\addvalidparameterkeys{\dodoubleargument\doaddvalidparameterkeys}
+
+\def\dosetvalidparameterkeys[#1][#2]{\ctxlua{interfaces.setvalidkeys("#1",\!!bs#2\!!es)}}
+\def\doaddvalidparameterkeys[#1][#2]{\ctxlua{interfaces.addvalidkeys("#1",\!!bs#2\!!es)}}
+
+\def\getcheckedparametersyes[#1]#2[#3]#4[#5%
+ {\if\noexpand#5]%
+ \expandafter\gobblethreearguments
+ \else
+ \let\setsomevalue\dosetvalue
+ \expandafter\dogetcheckedparametersyes
+ \fi{#1}{#3}#5}
+
+\def\dogetcheckedparametersyes#1#2#3]%
+ {\ctxlua{_gcp_("#1","#2",\!!bs\detokenize{#3}\!!es)}}
+
+\def\getcheckedparametersnop[#1]#2[#3]#4[#5%
+ {\if\noexpand#5]%
+ \expandafter\gobbletwoarguments
+ \else
+ \let\setsomevalue\dosetvalue
+ \expandafter\dogetcheckedparametersnop
+ \fi{#3}#5}
+
+\def\dogetcheckedparametersnop#1#2]%
+ {\def\p!dogetparameter{\p!doassign#1}%
+ \xprocesscommaitem#2,],\@relax@}
+
+\def\disablecheckparameters{\let\getcheckedparameters\getcheckedparametersnop}
+\def\enablecheckparameters {\let\getcheckedparameters\getcheckedparametersyes}
+
+\disablecheckparameters
+
+\protect \endinput
+
+\starttext
+
+\testfeatureonce{10000}{\getcheckedparameters[test][xx][a=b,c= d, e = f]} % 0.20 seconds
+
+\enablecheckparameters
+
+\testfeatureonce{10000}{\getcheckedparameters[test][xx][a=b,c= d, e = f]} % 0.35 seconds
+
+\getcheckedparameters[test][xx][a=a]
+\getcheckedparameters[test][xx][b= b]
+\getcheckedparameters[test][xx][c = c]
+\getcheckedparameters[test][xx][d = d d , e = e ,f = f ]
+\getcheckedparameters[test][xx][g={oeps {oeps}}]
+\getcheckedparameters[test][xx][crap=whatever]
+
+\startlines
+[a:\getvalue{xxa}][a]
+[b:\getvalue{xxb}][b]
+[c:\getvalue{xxc}][c]
+[d:\getvalue{xxd}][d d ]
+[e:\getvalue{xxe}][e ]
+[f:\getvalue{xxf}][f ]
+[g:\getvalue{xxg}][\detokenize\expandafter{\xxg}]
+\stoplines
+
+\setvalidparameterkeys[test][crap]
+
+\getcheckedparameters[test][xx][crap=whatever]
+
+\stoptext
diff --git a/tex/context/base/mult-de.tex b/tex/context/base/mult-de.tex
index b408dad2f..8c47126fe 100644
--- a/tex/context/base/mult-de.tex
+++ b/tex/context/base/mult-de.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{nach}
\setinterfacevariable{all}{alles}
\setinterfacevariable{always}{immer}
+\setinterfacevariable{answerarea}{answerarea}
\setinterfacevariable{appendices}{anhaenge}
\setinterfacevariable{appendix}{anhang}
\setinterfacevariable{april}{April}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{lefthanging}
\setinterfacevariable{leftmargin}{linkerrand}
\setinterfacevariable{leftpage}{linkerseite}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legende}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{zeile}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normal}
\setinterfacevariable{nospacing}{nospacing}
\setinterfacevariable{not}{nicht}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nothanging}
\setinterfacevariable{nothyphenated}{nothyphenated}
\setinterfacevariable{november}{November}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{righthanging}
\setinterfacevariable{rightmargin}{rechterrand}
\setinterfacevariable{rightpage}{rechterseite}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{antiqua}
\setinterfacevariable{romannumerals}{roemischezahlen}
\setinterfacevariable{rotate}{drehe}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{unterunterunterunterthema}
\setinterfacevariable{subsubsubsubsubsection}{unterunterunterunterunterabsatz}
\setinterfacevariable{subsubsubsubsubsubject}{unterunterunterunterunterthema}
+\setinterfacevariable{subsubsubsubsubsubsection}{unterunterunterunterunterunterabsatz}
+\setinterfacevariable{subsubsubsubsubsubsubject}{unterunterunterunterunterunterthema}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{unterunterunterunterunterunterunterabsatz}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{unterunterunterunterunterunterunterthema}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{unterunterunterunterunterunterunterunterabsatz}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{unterunterunterunterunterunterunterunterthema}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{unterunterunterunterunterunterunterunterunterabsatz}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{unterunterunterunterunterunterunterunterunterthema}
\setinterfacevariable{sunday}{sonntag}
\setinterfacevariable{support}{support}
\setinterfacevariable{sym}{sym}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{fliesstext}
\setinterfaceconstant{bookmark}{bookmark}
\setinterfaceconstant{bottom}{unten}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{abstandunten}
\setinterfaceconstant{bottomframe}{untenrahmen}
\setinterfaceconstant{bottomoffset}{untenoffset}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{component}
\setinterfaceconstant{compoundhyphen}{compoundhyphen}
\setinterfaceconstant{compress}{compress}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{fortsetzen}
\setinterfaceconstant{contrastcolor}{kontrastfarbe}
\setinterfaceconstant{controls}{controls}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{fieldlayer}
\setinterfaceconstant{fieldoffset}{feldoffset}
\setinterfaceconstant{file}{datei}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusout}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{hoehe}
\setinterfaceconstant{hfactor}{hfaktor}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{hoffset}
\setinterfaceconstant{horoffset}{rumpfabstand}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{nummer}
\setinterfaceconstant{numbercolor}{nummernfarbe}
\setinterfaceconstant{numbercommand}{nummerbefehl}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{numberdistance}
\setinterfaceconstant{numbering}{nummerierung}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{nummernseperator}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{nummernstil}
\setinterfaceconstant{numberwidth}{numberwidth}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{seitenbegrenzung}
\setinterfaceconstant{pagecolor}{seitenfarbe}
\setinterfaceconstant{pagecommand}{seitenbefehl}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{seitennummer}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{pagestate}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{seitenstil}
\setinterfaceconstant{palet}{palette}
\setinterfaceconstant{paper}{papier}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{setzetrenner}
\setinterfaceconstant{position}{position}
\setinterfaceconstant{prefix}{prefix}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{voreinstellung}
\setinterfaceconstant{preview}{vorschau}
\setinterfaceconstant{previous}{vorige}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{reduktion}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{referenz}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{referieren}
\setinterfaceconstant{regionin}{regionin}
\setinterfaceconstant{regionout}{regionaus}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{liniendicke}
\setinterfaceconstant{samepage}{selbeseite}
\setinterfaceconstant{sample}{muster}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{format}
\setinterfaceconstant{scope}{bereich}
\setinterfaceconstant{screen}{raster}
\setinterfaceconstant{section}{abschnitt}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{abschnittsnummer}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{seperator}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{setups}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{yschritt}
% definitions for interface elements for language de
%
+\setinterfaceelement{answerlines}{answerlines}
+\setinterfaceelement{answerspace}{answerspace}
\setinterfaceelement{begin}{anfang}
\setinterfaceelement{complete}{vollende}
\setinterfaceelement{coupled}{verknuepft}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{settext}
\setinterfacecommand{settextvariable}{settextvariable}
\setinterfacecommand{setupalign}{stelleausrichtungein}
+\setinterfacecommand{setupanswerarea}{setupanswerarea}
\setinterfacecommand{setuparranging}{stelleanordnenein}
\setinterfacecommand{setupbackground}{stellehintergrundein}
\setinterfacecommand{setupbackgrounds}{stellehintergruendeein}
diff --git a/tex/context/base/mult-def.lua b/tex/context/base/mult-def.lua
index b0999fd2e..b447f2467 100644
--- a/tex/context/base/mult-def.lua
+++ b/tex/context/base/mult-def.lua
@@ -3571,6 +3571,16 @@ return {
["pe"]="بارگذاریتنظیم",
["ro"]="seteazaalinierea",
},
+ ["setupanswerarea"]={
+ ["cs"]="setupanswerarea",
+ ["de"]="setupanswerarea",
+ ["en"]="setupanswerarea",
+ ["fr"]="setupanswerarea",
+ ["it"]="setupanswerarea",
+ ["nl"]="stelantwoordgebiedin",
+ ["pe"]="setupanswerarea",
+ ["ro"]="setupanswerarea",
+ },
["setuparranging"]={
["cs"]="nastavusporadani",
["de"]="stelleanordnenein",
@@ -6912,6 +6922,12 @@ return {
["pe"]="پایین",
["ro"]="jos",
},
+ ["bottomafter"]={
+ ["en"]="bottomafter",
+ },
+ ["bottombefore"]={
+ ["en"]="bottombefore",
+ },
["bottomdistance"]={
["cs"]="vzdalenostspodku",
["de"]="abstandunten",
@@ -7182,6 +7198,9 @@ return {
["pe"]="فشردن",
["ro"]="compress",
},
+ ["connector"]={
+ ["en"]="connector",
+ },
["continue"]={
["cs"]="pokracovat",
["de"]="fortsetzen",
@@ -7642,6 +7661,9 @@ return {
["pe"]="پرونده",
["ro"]="fisier",
},
+ ["filtercommand"]={
+ ["en"]="filtercommand",
+ },
["focus"]={
["cs"]="zaostreni",
["de"]="focus",
@@ -7710,7 +7732,6 @@ return {
["it"]="coloreprimopiano",
["nl"]="voorgrondkleur",
["pe"]="رنگپیشزمینه",
-
["ro"]="foregroundcolor",
},
["foregroundstyle"]={
@@ -7973,6 +7994,9 @@ return {
["pe"]="پرکردنارتفاع",
["ro"]="hfil",
},
+ ["hidenumber"]={
+ ["en"]="hidenumber",
+ },
["hoffset"]={
["cs"]="hoffset",
["de"]="hoffset",
@@ -8853,6 +8877,12 @@ return {
["pe"]="فرمانشماره",
["ro"]="comandanumar",
},
+ ["numberconversion"]={
+ ["en"]="numberconversion",
+ },
+ ["numberconversionset"]={
+ ["en"]="numberconversionset",
+ },
["numberdistance"]={
["cs"]="numberdistance",
["de"]="numberdistance",
@@ -8873,6 +8903,15 @@ return {
["pe"]="شمارهگذاری",
["ro"]="numerotare",
},
+ ["numberorder"]={
+ ["en"]="numberorder",
+ },
+ ["numberprefix"]={
+ ["en"]="numberprefix",
+ },
+ ["numbersegments"]={
+ ["en"]="numbersegments",
+ },
["numberseparator"]={
["cs"]="oddelovaccisla",
["de"]="nummernseperator",
@@ -8883,6 +8922,15 @@ return {
["pe"]="جداکنندهشماره",
["ro"]="separatornumar",
},
+ ["numberseparatorset"]={
+ ["en"]="numberseparatorset",
+ },
+ ["numberset"]={
+ ["en"]="numberset",
+ },
+ ["numberstopper"]={
+ ["en"]="numberstopper",
+ },
["numberstyle"]={
["cs"]="stylcisla",
["de"]="nummernstil",
@@ -9073,6 +9121,12 @@ return {
["pe"]="فرمانصفحه",
["ro"]="comandapagina",
},
+ ["pageconversion"]={
+ ["en"]="pageconversion",
+ },
+ ["pageconversionset"]={
+ ["en"]="pageconversionset",
+ },
["pagenumber"]={
["cs"]="cislostranky",
["de"]="seitennummer",
@@ -9083,6 +9137,39 @@ return {
["pe"]="شمارهصفحه",
["ro"]="numarpagina",
},
+ ["pageprefix"]={
+ ["en"]="pageprefix",
+ },
+ ["pageprefixconnector"]={
+ ["en"]="pageprefixconnector",
+ },
+ ["pageprefixconversion"]={
+ ["en"]="pageprefixconversion",
+ },
+ ["pageprefixconversionset"]={
+ ["en"]="pageprefixconversionset",
+ },
+ ["pageprefixsegments"]={
+ ["en"]="pageprefixsegments",
+ },
+ ["pageprefixseparatorset"]={
+ ["en"]="pageprefixseparatorset",
+ },
+ ["pageprefixset"]={
+ ["en"]="pageprefixset",
+ },
+ ["pageprefixstopper"]={
+ ["en"]="pageprefixstopper",
+ },
+ ["pagesegments"]={
+ ["en"]="pagesegments",
+ },
+ ["pageseparatorset"]={
+ ["en"]="pageseparatorset",
+ },
+ ["pageset"]={
+ ["en"]="pageset",
+ },
["pagestate"]={
["cs"]="pagestate",
["de"]="pagestate",
@@ -9093,6 +9180,9 @@ return {
["pe"]="وضعیتصفحه",
["ro"]="pagestate",
},
+ ["pagestopper"]={
+ ["en"]="pagestopper",
+ },
["pagestyle"]={
["cs"]="stylstranky",
["de"]="seitenstil",
@@ -9183,6 +9273,27 @@ return {
["pe"]="پیشوند",
["ro"]="prefix",
},
+ ["prefixconnector"]={
+ ["en"]="prefixconnector",
+ },
+ ["prefixconversion"]={
+ ["en"]="prefixconversion",
+ },
+ ["prefixconversionset"]={
+ ["en"]="prefixconversionset",
+ },
+ ["prefixsegments"]={
+ ["en"]="prefixsegments",
+ },
+ ["prefixseparatorset"]={
+ ["en"]="prefixseparatorset",
+ },
+ ["prefixset"]={
+ ["en"]="prefixset",
+ },
+ ["prefixstopper"]={
+ ["en"]="prefixstopper",
+ },
["preset"]={
["cs"]="prednastaveni",
["de"]="voreinstellung",
@@ -9283,6 +9394,9 @@ return {
["pe"]="مرجع",
["ro"]="referinta",
},
+ ["referenceprefix"]={
+ ["en"]="referenceprefix",
+ },
["referencing"]={
["cs"]="odkazujici",
["de"]="referieren",
@@ -9593,6 +9707,9 @@ return {
["pe"]="نمونه",
["ro"]="exemplu",
},
+ ["saveinlist"]={
+ ["en"]="saveinlist",
+ },
["scale"]={
["cs"]="meritko",
["de"]="format",
@@ -9633,6 +9750,12 @@ return {
["pe"]="بخش",
["ro"]="sectiune",
},
+ ["sectionconversion"]={
+ ["en"]="sectionconversion",
+ },
+ ["sectionconversionset"]={
+ ["en"]="sectionconversionset",
+ },
["sectionnumber"]={
["cs"]="cislooddilu",
["de"]="abschnittsnummer",
@@ -9643,6 +9766,18 @@ return {
["pe"]="شمارهبخش",
["ro"]="numarsectiune",
},
+ ["sectionsegments"]={
+ ["en"]="sectionsegments",
+ },
+ ["sectionseparatorset"]={
+ ["en"]="sectionseparatorset",
+ },
+ ["sectionset"]={
+ ["en"]="sectionset",
+ },
+ ["sectionstopper"]={
+ ["en"]="sectionstopper",
+ },
["separator"]={
["cs"]="oddelovac",
["de"]="seperator",
@@ -10615,6 +10750,26 @@ return {
},
},
["elements"]={
+ ["answerlines"]={
+ ["cs"]="answerlines",
+ ["de"]="answerlines",
+ ["en"]="answerlines",
+ ["fr"]="answerlines",
+ ["it"]="answerlines",
+ ["nl"]="antwoordregels",
+ ["pe"]="answerlines",
+ ["ro"]="answerlines",
+ },
+ ["answerspace"]={
+ ["cs"]="answerspace",
+ ["de"]="answerspace",
+ ["en"]="answerspace",
+ ["fr"]="answerspace",
+ ["it"]="answerspace",
+ ["nl"]="antwoordruimte",
+ ["pe"]="answerspace",
+ ["ro"]="answerspace",
+ },
["begin"]={
["cs"]="zacatek",
["de"]="anfang",
@@ -11537,6 +11692,16 @@ return {
["pe"]="همواره",
["ro"]="totdeauna",
},
+ ["answerarea"]={
+ ["cs"]="answerarea",
+ ["de"]="answerarea",
+ ["en"]="answerarea",
+ ["fr"]="answerarea",
+ ["it"]="answerarea",
+ ["nl"]="antwoordgebied",
+ ["pe"]="answerarea",
+ ["ro"]="answerarea",
+ },
["appendices"]={
["cs"]="dodatky",
["de"]="anhaenge",
@@ -13227,6 +13392,16 @@ return {
["pe"]="صفحهچپ",
["ro"]="paginastanga",
},
+ ["lefttoright"]={
+ ["cs"]="lefttoright",
+ ["de"]="lefttoright",
+ ["en"]="lefttoright",
+ ["fr"]="lefttoright",
+ ["it"]="lefttoright",
+ ["nl"]="lefttoright",
+ ["pe"]="lefttoright",
+ ["ro"]="lefttoright",
+ },
["legend"]={
["cs"]="legenda",
["de"]="legende",
@@ -13807,6 +13982,9 @@ return {
["pe"]="بدون",
["ro"]="nu",
},
+ ["note"]={
+ ["en"]="note",
+ },
["nothanging"]={
["cs"]="nothanging",
["de"]="nothanging",
@@ -14447,6 +14625,16 @@ return {
["pe"]="صفحهراست",
["ro"]="paginadreapta",
},
+ ["righttoleft"]={
+ ["cs"]="righttoleft",
+ ["de"]="righttoleft",
+ ["en"]="righttoleft",
+ ["fr"]="righttoleft",
+ ["it"]="righttoleft",
+ ["nl"]="righttoleft",
+ ["pe"]="righttoleft",
+ ["ro"]="righttoleft",
+ },
["roman"]={
["cs"]="antikva",
["de"]="antiqua",
@@ -15137,6 +15325,86 @@ return {
["pe"]="زیرزیرزیرزیرزیرموضوع",
["ro"]="subsubsubsubsubsubiect",
},
+ ["subsubsubsubsubsubsection"]={
+ ["cs"]="podpodpodpodpodpodsekce",
+ ["de"]="unterunterunterunterunterunterabsatz",
+ ["en"]="subsubsubsubsubsubsection",
+ ["fr"]="soussoussoussoussoussoussection",
+ ["it"]="sottosottosottosottosottosottocapoverso",
+ ["nl"]="subsubsubsubsubsubparagraaf",
+ ["pe"]="زیرزیرزیرزیرزیرزیربخش",
+ ["ro"]="subsubsubsubsubsubsectiune",
+ },
+ ["subsubsubsubsubsubsubject"]={
+ ["cs"]="podpodpodpodpodpodtema",
+ ["de"]="unterunterunterunterunterunterthema",
+ ["en"]="subsubsubsubsubsubsubject",
+ ["fr"]="soussoussoussoussoussoussujet",
+ ["it"]="sottosottosottosottosottosottoargomento",
+ ["nl"]="subsubsubsubsubsubonderwerp",
+ ["pe"]="زیرزیرزیرزیرزیرزیرموضوع",
+ ["ro"]="subsubsubsubsubsubsubiect",
+ },
+ ["subsubsubsubsubsubsubsection"]={
+ ["cs"]="podpodpodpodpodpodpodsekce",
+ ["de"]="unterunterunterunterunterunterunterabsatz",
+ ["en"]="subsubsubsubsubsubsubsection",
+ ["fr"]="soussoussoussoussoussoussoussection",
+ ["it"]="sottosottosottosottosottosottosottocapoverso",
+ ["nl"]="subsubsubsubsubsubsubparagraaf",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیربخش",
+ ["ro"]="subsubsubsubsubsubsubsectiune",
+ },
+ ["subsubsubsubsubsubsubsubject"]={
+ ["cs"]="podpodpodpodpodpodpodtema",
+ ["de"]="unterunterunterunterunterunterunterthema",
+ ["en"]="subsubsubsubsubsubsubsubject",
+ ["fr"]="soussoussoussoussoussoussoussujet",
+ ["it"]="sottosottosottosottosottosottosottoargomento",
+ ["nl"]="subsubsubsubsubsubsubonderwerp",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیرموضوع",
+ ["ro"]="subsubsubsubsubsubsubsubiect",
+ },
+ ["subsubsubsubsubsubsubsubsection"]={
+ ["cs"]="podpodpodpodpodpodpodpodsekce",
+ ["de"]="unterunterunterunterunterunterunterunterabsatz",
+ ["en"]="subsubsubsubsubsubsubsubsection",
+ ["fr"]="soussoussoussoussoussoussoussoussection",
+ ["it"]="sottosottosottosottosottosottosottosottocapoverso",
+ ["nl"]="subsubsubsubsubsubsubsubparagraaf",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیرزیربخش",
+ ["ro"]="subsubsubsubsubsubsubsubsectiune",
+ },
+ ["subsubsubsubsubsubsubsubsubject"]={
+ ["cs"]="podpodpodpodpodpodpodpodtema",
+ ["de"]="unterunterunterunterunterunterunterunterthema",
+ ["en"]="subsubsubsubsubsubsubsubsubject",
+ ["fr"]="soussoussoussoussoussoussoussoussujet",
+ ["it"]="sottosottosottosottosottosottosottosottoargomento",
+ ["nl"]="subsubsubsubsubsubsubsubonderwerp",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیرزیرموضوع",
+ ["ro"]="subsubsubsubsubsubsubsubsubiect",
+ },
+ ["subsubsubsubsubsubsubsubsubsection"]={
+ ["cs"]="podpodpodpodpodpodpodpodpodsekce",
+ ["de"]="unterunterunterunterunterunterunterunterunterabsatz",
+ ["en"]="subsubsubsubsubsubsubsubsubsection",
+ ["fr"]="soussoussoussoussoussoussoussoussoussection",
+ ["it"]="sottosottosottosottosottosottosottosottosottocapoverso",
+ ["nl"]="subsubsubsubsubsubsubsubsubparagraaf",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیرزیرزیربخش",
+ ["ro"]="subsubsubsubsubsubsubsubsubsectiune",
+ },
+ ["subsubsubsubsubsubsubsubsubsubject"]={
+ ["cs"]="podpodpodpodpodpodpodpodpodtema",
+ ["de"]="unterunterunterunterunterunterunterunterunterthema",
+ ["en"]="subsubsubsubsubsubsubsubsubsubject",
+ ["fr"]="soussoussoussoussoussoussoussoussoussujet",
+ ["it"]="sottosottosottosottosottosottosottosottosottoargomento",
+ ["nl"]="subsubsubsubsubsubsubsubsubonderwerp",
+ ["pe"]="زیرزیرزیرزیرزیرزیرزیرزیرزیرموضوع",
+ ["ro"]="subsubsubsubsubsubsubsubsubsubiect",
+ },
["sunday"]={
["cs"]="nedele",
["de"]="sonntag",
diff --git a/tex/context/base/mult-def.tex b/tex/context/base/mult-def.tex
index c49e6ffac..cff9fb074 100644
--- a/tex/context/base/mult-def.tex
+++ b/tex/context/base/mult-def.tex
@@ -22,6 +22,14 @@
\setvalue{@interface@persian@}{pe}
\setvalue{@interface@romanian@}{ro}
-\input mult-\ifcsname @interface@\defaultinterface @\endcsname\csname @interface@\defaultinterface @\endcsname\else en\fi\relax
+% \def\userinterfacetag
+% {\ifcsname @interface@\defaultinterface @\endcsname\csname @interface@\defaultinterface @\endcsname\else en\fi}
+\def\userinterfacetag
+ {\ifcsname @interface@\currentinterface @\endcsname\csname @interface@\currentinterface @\endcsname\else en\fi}
+\def\userresponsestag
+ {\ifcsname @interface@\currentresponses @\endcsname\csname @interface@\currentresponses @\endcsname\else en\fi}
+
+\input mult-\userinterfacetag \relax
+\input mult-m\userresponsestag \relax
\protect \endinput
diff --git a/tex/context/base/mult-en.tex b/tex/context/base/mult-en.tex
index 1fdc9799e..16058f794 100644
--- a/tex/context/base/mult-en.tex
+++ b/tex/context/base/mult-en.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{after}
\setinterfacevariable{all}{all}
\setinterfacevariable{always}{always}
+\setinterfacevariable{answerarea}{answerarea}
\setinterfacevariable{appendices}{appendices}
\setinterfacevariable{appendix}{appendix}
\setinterfacevariable{april}{April}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{lefthanging}
\setinterfacevariable{leftmargin}{leftmargin}
\setinterfacevariable{leftpage}{leftpage}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legend}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{line}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normal}
\setinterfacevariable{nospacing}{nospacing}
\setinterfacevariable{not}{not}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nothanging}
\setinterfacevariable{nothyphenated}{nothyphenated}
\setinterfacevariable{november}{November}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{righthanging}
\setinterfacevariable{rightmargin}{rightmargin}
\setinterfacevariable{rightpage}{rightpage}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{roman}
\setinterfacevariable{romannumerals}{romannumerals}
\setinterfacevariable{rotate}{rotate}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{subsubsubsubsubject}
\setinterfacevariable{subsubsubsubsubsection}{subsubsubsubsubsection}
\setinterfacevariable{subsubsubsubsubsubject}{subsubsubsubsubsubject}
+\setinterfacevariable{subsubsubsubsubsubsection}{subsubsubsubsubsubsection}
+\setinterfacevariable{subsubsubsubsubsubsubject}{subsubsubsubsubsubsubject}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsection}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubject}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubsection}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubsubject}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubsubsection}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubsubsubject}
\setinterfacevariable{sunday}{sunday}
\setinterfacevariable{support}{support}
\setinterfacevariable{sym}{sym}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{bodyfont}
\setinterfaceconstant{bookmark}{bookmark}
\setinterfaceconstant{bottom}{bottom}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{bottomdistance}
\setinterfaceconstant{bottomframe}{bottomframe}
\setinterfaceconstant{bottomoffset}{bottomoffset}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{component}
\setinterfaceconstant{compoundhyphen}{compoundhyphen}
\setinterfaceconstant{compress}{compress}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{continue}
\setinterfaceconstant{contrastcolor}{contrastcolor}
\setinterfaceconstant{controls}{controls}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{fieldlayer}
\setinterfaceconstant{fieldoffset}{fieldoffset}
\setinterfaceconstant{file}{file}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusout}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{height}
\setinterfaceconstant{hfactor}{hfactor}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{hoffset}
\setinterfaceconstant{horoffset}{horoffset}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{number}
\setinterfaceconstant{numbercolor}{numbercolor}
\setinterfaceconstant{numbercommand}{numbercommand}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{numberdistance}
\setinterfaceconstant{numbering}{numbering}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{numberseparator}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{numberstyle}
\setinterfaceconstant{numberwidth}{numberwidth}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{pageboundaries}
\setinterfaceconstant{pagecolor}{pagecolor}
\setinterfaceconstant{pagecommand}{pagecommand}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{pagenumber}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{pagestate}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{pagestyle}
\setinterfaceconstant{palet}{palet}
\setinterfaceconstant{paper}{paper}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{placestopper}
\setinterfaceconstant{position}{position}
\setinterfaceconstant{prefix}{prefix}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{preset}
\setinterfaceconstant{preview}{preview}
\setinterfaceconstant{previous}{previous}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{reduction}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{reference}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{referencing}
\setinterfaceconstant{regionin}{regionin}
\setinterfaceconstant{regionout}{regionout}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{rulethickness}
\setinterfaceconstant{samepage}{samepage}
\setinterfaceconstant{sample}{sample}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{scale}
\setinterfaceconstant{scope}{scope}
\setinterfaceconstant{screen}{screen}
\setinterfaceconstant{section}{section}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{sectionnumber}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{separator}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{setups}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{ystep}
% definitions for interface elements for language en
%
+\setinterfaceelement{answerlines}{answerlines}
+\setinterfaceelement{answerspace}{answerspace}
\setinterfaceelement{begin}{begin}
\setinterfaceelement{complete}{complete}
\setinterfaceelement{coupled}{coupled}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{settextcontent}
\setinterfacecommand{settextvariable}{settextvariable}
\setinterfacecommand{setupalign}{setupalign}
+\setinterfacecommand{setupanswerarea}{setupanswerarea}
\setinterfacecommand{setuparranging}{setuparranging}
\setinterfacecommand{setupbackground}{setupbackground}
\setinterfacecommand{setupbackgrounds}{setupbackgrounds}
diff --git a/tex/context/base/mult-fr.tex b/tex/context/base/mult-fr.tex
index 1dc2b2b4f..11a305ac8 100644
--- a/tex/context/base/mult-fr.tex
+++ b/tex/context/base/mult-fr.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{apres}
\setinterfacevariable{all}{tout}
\setinterfacevariable{always}{toujours}
+\setinterfacevariable{answerarea}{answerarea}
\setinterfacevariable{appendices}{annexes}
\setinterfacevariable{appendix}{annexe}
\setinterfacevariable{april}{avril}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{lefthanging}
\setinterfacevariable{leftmargin}{margegauche}
\setinterfacevariable{leftpage}{pagegauche}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legende}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{ligne}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normal}
\setinterfacevariable{nospacing}{sansespacement}
\setinterfacevariable{not}{pas}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nonsuspendu}
\setinterfacevariable{nothyphenated}{nothyphenated}
\setinterfacevariable{november}{novembre}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{righthanging}
\setinterfacevariable{rightmargin}{margedroite}
\setinterfacevariable{rightpage}{pagedroite}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{roman}
\setinterfacevariable{romannumerals}{chiffresromains}
\setinterfacevariable{rotate}{oriente}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{soussoussoussoussujet}
\setinterfacevariable{subsubsubsubsubsection}{soussoussoussoussoussection}
\setinterfacevariable{subsubsubsubsubsubject}{soussoussoussoussoussujet}
+\setinterfacevariable{subsubsubsubsubsubsection}{soussoussoussoussoussoussection}
+\setinterfacevariable{subsubsubsubsubsubsubject}{soussoussoussoussoussoussujet}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{soussoussoussoussoussoussoussection}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{soussoussoussoussoussoussoussujet}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{soussoussoussoussoussoussoussoussection}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{soussoussoussoussoussoussoussoussujet}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{soussoussoussoussoussoussoussoussoussection}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{soussoussoussoussoussoussoussoussoussujet}
\setinterfacevariable{sunday}{dimanche}
\setinterfacevariable{support}{support}
\setinterfacevariable{sym}{sym}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{policecorps}
\setinterfaceconstant{bookmark}{marquepage}
\setinterfaceconstant{bottom}{inf}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{distanceinf}
\setinterfaceconstant{bottomframe}{cadreinf}
\setinterfaceconstant{bottomoffset}{decalageinf}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{composant}
\setinterfaceconstant{compoundhyphen}{compoundhyphen}
\setinterfaceconstant{compress}{compress}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{continue}
\setinterfaceconstant{contrastcolor}{coleurcontraste}
\setinterfaceconstant{controls}{controles}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{calquechamp}
\setinterfaceconstant{fieldoffset}{offsetchamp}
\setinterfaceconstant{file}{fichier}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusout}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{hauteur}
\setinterfaceconstant{hfactor}{facteurhauteur}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{decalagehauteur}
\setinterfaceconstant{horoffset}{horoffset}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{numero}
\setinterfaceconstant{numbercolor}{couleurnumero}
\setinterfaceconstant{numbercommand}{commandenumero}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{numberdistance}
\setinterfaceconstant{numbering}{numerotation}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{separateurnumbero}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{stylenumero}
\setinterfaceconstant{numberwidth}{numberwidth}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{limitespage}
\setinterfaceconstant{pagecolor}{couleurpage}
\setinterfaceconstant{pagecommand}{commandepage}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{numeropage}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{etatpage}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{stylepage}
\setinterfaceconstant{palet}{palette}
\setinterfaceconstant{paper}{papier}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{emplacementstopper}
\setinterfaceconstant{position}{position}
\setinterfaceconstant{prefix}{prefixe}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{prereglage}
\setinterfaceconstant{preview}{previsualisation}
\setinterfaceconstant{previous}{precedent}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{reduction}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{reference}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{referencing}
\setinterfaceconstant{regionin}{entreregion}
\setinterfaceconstant{regionout}{regionexterieure}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{epaisseurligne}
\setinterfaceconstant{samepage}{memepage}
\setinterfaceconstant{sample}{echantillon}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{echelle}
\setinterfaceconstant{scope}{scope}
\setinterfaceconstant{screen}{ecran}
\setinterfaceconstant{section}{section}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{numerosection}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{separateur}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{reglages}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{ystep}
% definitions for interface elements for language fr
%
+\setinterfaceelement{answerlines}{answerlines}
+\setinterfaceelement{answerspace}{answerspace}
\setinterfaceelement{begin}{debut}
\setinterfaceelement{complete}{complete}
\setinterfaceelement{coupled}{couple}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{settext}
\setinterfacecommand{settextvariable}{affectevariabletexte}
\setinterfacecommand{setupalign}{reglealignement}
+\setinterfacecommand{setupanswerarea}{setupanswerarea}
\setinterfacecommand{setuparranging}{reglearrangement}
\setinterfacecommand{setupbackground}{reglearriereplan}
\setinterfacecommand{setupbackgrounds}{reglearriereplans}
diff --git a/tex/context/base/mult-his.tex b/tex/context/base/mult-his.tex
index 40010499d..fe87d4bcf 100644
--- a/tex/context/base/mult-his.tex
+++ b/tex/context/base/mult-his.tex
@@ -33,7 +33,7 @@
%D message : floatblocks/13
%D variables : sorttype compress autohang
-\writestatus{loading}{Context Multilingual Macros / Initialization}
+\writestatus{loading}{ConTeXt Multilingual Macros / Initialization}
\unprotect
@@ -328,11 +328,7 @@
%D example of a library.
%D
%D \starttyping
-%D \startmessages english library: alfa
-%D title: something
-%D 1: first message
-%D 2: second (--) message --
-%D \stopmessages
+%D % messages moved
%D \stoptyping
%D
%D The first message is a simple one and can be shown with:
@@ -361,9 +357,7 @@
%D once. We can add messages to a library in the following way:
%D
%D \starttyping
-%D \startmessages english library: alfa
-%D 10: tenth message
-%D \stopmessages
+%D % messages moved
%D \stoptyping
%D
%D Because such definitions can take place in different
@@ -1141,9 +1135,7 @@
{\writeline\writebanner{\contextbanner}\writeline}
\edef\formatversion
- {\ifx\normalyear \undefined\the\year \else\the\normalyear \fi.%
- \ifx\normalmonth\undefined\the\month\else\the\normalmonth\fi.%
- \ifx\normalday \undefined\the\day \else\the\normalday \fi}
+ {\the\normalyear.\the\normalmonth.\the\normalday}
\ifx\contextversion\undefined
\def\contextversion {unknown}
@@ -1153,9 +1145,8 @@
\edef\contextversionnumber{\expandafter\contextversionnumber\contextversion\relax\space\contextmark}
\fi
-\ifx\undefined\normaldump
+\ifx\undefined\everydump
\newtoks\everydump
- \let\normaldump\dump
\def\dump{\the\everydump\normaldump}
\fi
diff --git a/tex/context/base/mult-ini.lua b/tex/context/base/mult-ini.lua
index 9133633eb..1eee9a656 100644
--- a/tex/context/base/mult-ini.lua
+++ b/tex/context/base/mult-ini.lua
@@ -6,47 +6,56 @@ if not modules then modules = { } end modules ['mult-ini'] = {
license = "see context related readme files"
}
-local format = string.format
+local format, gmatch = string.format, string.gmatch
interfaces = interfaces or { }
interfaces.messages = interfaces.messages or { }
interfaces.constants = interfaces.constants or { }
interfaces.variables = interfaces.variables or { }
-input.storage.register(false,"interfaces/messages", interfaces.messages, "interfaces.messages" )
-input.storage.register(false,"interfaces/constants", interfaces.constants, "interfaces.constants")
-input.storage.register(false,"interfaces/variables", interfaces.variables, "interfaces.variables")
+storage.register("interfaces/messages", interfaces.messages, "interfaces.messages" )
+storage.register("interfaces/constants", interfaces.constants, "interfaces.constants")
+storage.register("interfaces/variables", interfaces.variables, "interfaces.variables")
-function interfaces.setmessage(category,str)
+function interfaces.setmessages(category,str)
local m = interfaces.messages[category] or { }
- for k, v in str:gmatch("(%S+) *: *(.-) *[\n\r]") do
+ for k, v in gmatch(str,"(%S+) *: *(.-) *[\n\r]") do
m[k] = v:gsub("%-%-","%%s")
end
interfaces.messages[category] = m
end
+function interfaces.setmessage(category,tag,message)
+ local m = interfaces.messages[category]
+ if not m then
+ m = { }
+ interfaces.messages[category] = m
+ end
+ m[tag] = message:gsub("%-%-","%%s")
+end
+
function interfaces.getmessage(category,tag)
local m = interfaces.messages[category]
return (m and m[tag]) or "unknown message"
end
+local messagesplitter = lpeg.splitat(",")
+
function interfaces.makemessage(category,tag,arguments)
local m = interfaces.messages[category]
- m = (m and m[tag] ) or "unknown message"
+ m = (m and m[tag] ) or format("unknown message, category '%s', tag '%s'",category,tag)
if not m then
return m .. " " .. tag
elseif not arguments then
return m
- elseif arguments:find(",") then
- return format(m,unpack(arguments:splitchr(",")))
else
- return format(m,arguments)
+ return format(m,messagesplitter:match(arguments))
end
end
function interfaces.showmessage(category,tag,arguments)
local m = interfaces.messages[category]
- ctx.writestatus((m and m.title) or "unknown title",interfaces.makemessage(category,tag,arguments))
+ commands.writestatus((m and m.title) or "unknown title",interfaces.makemessage(category,tag,arguments))
end
function interfaces.setvariable(variable,given)
diff --git a/tex/context/base/mult-ini.mkii b/tex/context/base/mult-ini.mkii
index 8697057c8..c2bb40861 100644
--- a/tex/context/base/mult-ini.mkii
+++ b/tex/context/base/mult-ini.mkii
@@ -15,7 +15,7 @@
%D which we keep around as \type {mult-kep.tex} for sentimental
%D reasons. There you will find some more historic information.
-\writestatus{loading}{Context Multilingual Macros / Initialization}
+\writestatus{loading}{ConTeXt Multilingual Macros / Initialization}
\unprotect
@@ -438,7 +438,7 @@
{\definemessageconstant{#2}% handy for modules
\bgroup
\obeylines
- \doifundefined{\m!prefix!#2}{\setgvalue{\m!prefix!#2}{#2}}%
+ \ifcsname\m!prefix!#2\endcsname\else\setgvalue{\m!prefix!#2}{#2}\fi
\doifinsetelse{#1}{\currentresponses,all}
{\def\next
{\def\currentmessagelibrary{#2}%
@@ -460,6 +460,10 @@
\setxvalue{\??ms\currentmessagelibrary#1}{#2}%
\futurelet\next\getinterfacemessage}
+\def\setinterfacemessage#1#2#3%
+ {\ifcsname\m!prefix!#1\endcsname\else\setgvalue{\m!prefix!#1}{#1}\fi
+ \expandafter\def\csname\??ms#1#2\endcsname{#3}}
+
%D \macros
%D {ifshowwarnings, ifshowmessages}
%D
@@ -911,9 +915,7 @@
{\writeline\writebanner{\contextbanner}\writeline}
\edef\formatversion
- {\ifx\normalyear \undefined\the\year \else\the\normalyear \fi.%
- \ifx\normalmonth\undefined\the\month\else\the\normalmonth\fi.%
- \ifx\normalday \undefined\the\day \else\the\normalday \fi}
+ {\the\normalyear.\the\normalmonth.\the\normalday}
\ifx\contextversion\undefined
\def\contextversion {unknown}
@@ -923,9 +925,8 @@
\edef\contextversionnumber{\expandafter\contextversionnumber\contextversion\relax\space\contextmark}
\fi
-\ifx\undefined\normaldump
+\ifx\undefined\everydump
\newtoks\everydump
- \let\normaldump\dump
\def\dump{\the\everydump\normaldump}
\fi
diff --git a/tex/context/base/mult-ini.mkiv b/tex/context/base/mult-ini.mkiv
index c83a0b61d..2d1e2cc0e 100644
--- a/tex/context/base/mult-ini.mkiv
+++ b/tex/context/base/mult-ini.mkiv
@@ -15,7 +15,7 @@
%D which we keep around as \type {mult-kep.tex} for sentimental
%D reasons. There you will find some more historic information.
-\writestatus{loading}{Context Multilingual Macros / Initialization}
+\writestatus{loading}{ConTeXt Multilingual Macros / Initialization}
\unprotect
@@ -107,13 +107,14 @@
%D used more than once. Savings like this should of course be
%D implemented in english, just because \TEX\ is english.
-\def\!!width {width}
-\def\!!height {height}
-\def\!!depth {depth}
-\def\!!plus {plus}
-\def\!!minus {minus}
-\def\!!fill {fill}
-\def\!!to {to}
+\def\!!width {width}
+\def\!!height{height}
+\def\!!depth {depth}
+\def\!!plus {plus}
+\def\!!minus {minus}
+\def\!!fill {fill}
+\def\!!to {to}
+\def\!!spread{spread}
%D \macros
%D {defineinterfaceconstant,
@@ -240,8 +241,8 @@
\fi
-\ifx\currentinterface\undefined \let\currentinterface=\defaultinterface \fi
-\ifx\currentresponses\undefined \let\currentresponses=\defaultinterface \fi
+\ifx\currentinterface\undefined \let\currentinterface\defaultinterface \fi
+\ifx\currentresponses\undefined \let\currentresponses\defaultinterface \fi
%D \macros
%D {startinterface}
@@ -356,12 +357,16 @@
\doifinsetelse{#1}{\currentresponses,all}\dostartmessages\nostartmessages{#2}}
\def\dostartmessages#1#2\stopmessages
- {\ctxlua{interfaces.setmessage("#1",[[#2]])}%
+ {\ctxlua{interfaces.setmessages("#1",\!!bs#2\!!es)}%
\egroup}
\def\nostartmessages#1#2\stopmessages
{\egroup}
+\def\setinterfacemessage#1#2#3%
+ {\ifcsname\m!prefix!#1\endcsname\else\setgvalue{\m!prefix!#1}{#1}\fi
+ \ctxlua{interfaces.setmessage("#1","#2",\!!bs#3\!!es)}}
+
\unexpanded\def\setmessagetext #1#2{\edef\currentmessagetext{\ctxlua{tex.sprint(tex.ctxcatcodes,interfaces.getmessage("#1","#2"))}}}
\unexpanded\def\getmessage #1#2{\ctxlua{tex.sprint(tex.ctxcatcodes,interfaces.getmessage("#1","#2"))}}
\unexpanded\def\makemessage #1#2#3{\ctxlua{tex.sprint(tex.ctxcatcodes,interfaces.makemessage("#1","#2","#3"))}}
@@ -821,9 +826,7 @@
{\writeline\writebanner{\contextbanner}\writeline}
\edef\formatversion
- {\ifx\normalyear \undefined\the\year \else\the\normalyear \fi.%
- \ifx\normalmonth\undefined\the\month\else\the\normalmonth\fi.%
- \ifx\normalday \undefined\the\day \else\the\normalday \fi}
+ {\the\normalyear .\the\normalmonth.\the\normalday}
\ifx\contextversion\undefined
\def\contextversion {unknown}
@@ -833,9 +836,8 @@
\edef\contextversionnumber{\expandafter\contextversionnumber\contextversion\relax\space\contextmark}
\fi
-\ifx\undefined\normaldump
+\ifx\undefined\everydump
\newtoks\everydump
- \let\normaldump\dump
\def\dump{\the\everydump\normaldump}
\fi
diff --git a/tex/context/base/mult-it.tex b/tex/context/base/mult-it.tex
index e08d169d1..b62c5bdb3 100644
--- a/tex/context/base/mult-it.tex
+++ b/tex/context/base/mult-it.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{dopo}
\setinterfacevariable{all}{tutti}
\setinterfacevariable{always}{sempre}
+\setinterfacevariable{answerarea}{answerarea}
\setinterfacevariable{appendices}{appendici}
\setinterfacevariable{appendix}{appendice}
\setinterfacevariable{april}{aprile}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{lefthanging}
\setinterfacevariable{leftmargin}{marginesinistro}
\setinterfacevariable{leftpage}{paginasinistra}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legenda}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{riga}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normale}
\setinterfacevariable{nospacing}{nospacing}
\setinterfacevariable{not}{non}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nonsospeso}
\setinterfacevariable{nothyphenated}{nonsillabato}
\setinterfacevariable{november}{novembre}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{righthanging}
\setinterfacevariable{rightmargin}{marginedestro}
\setinterfacevariable{rightpage}{paginadestra}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{roman}
\setinterfacevariable{romannumerals}{numeriromani}
\setinterfacevariable{rotate}{ruota}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{sottosottosottosottoargomento}
\setinterfacevariable{subsubsubsubsubsection}{sottosottosottosottosottocapoverso}
\setinterfacevariable{subsubsubsubsubsubject}{sottosottosottosottosottoargomento}
+\setinterfacevariable{subsubsubsubsubsubsection}{sottosottosottosottosottosottocapoverso}
+\setinterfacevariable{subsubsubsubsubsubsubject}{sottosottosottosottosottosottoargomento}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{sottosottosottosottosottosottosottocapoverso}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{sottosottosottosottosottosottosottoargomento}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{sottosottosottosottosottosottosottosottocapoverso}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{sottosottosottosottosottosottosottosottoargomento}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{sottosottosottosottosottosottosottosottosottocapoverso}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{sottosottosottosottosottosottosottosottosottoargomento}
\setinterfacevariable{sunday}{domenica}
\setinterfacevariable{support}{supporto}
\setinterfacevariable{sym}{sim}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{fonttesto}
\setinterfaceconstant{bookmark}{segnalibro}
\setinterfaceconstant{bottom}{fondo}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{distanzafondo}
\setinterfaceconstant{bottomframe}{cornicefondo}
\setinterfaceconstant{bottomoffset}{offsetfondo}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{component}
\setinterfaceconstant{compoundhyphen}{compoundhyphen}
\setinterfaceconstant{compress}{compress}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{continua}
\setinterfaceconstant{contrastcolor}{colorecontrasto}
\setinterfaceconstant{controls}{controlli}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{fieldlayer}
\setinterfaceconstant{fieldoffset}{offsetcampo}
\setinterfaceconstant{file}{file}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusout}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{altezza}
\setinterfaceconstant{hfactor}{hfactor}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{hoffset}
\setinterfaceconstant{horoffset}{horoffset}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{numero}
\setinterfaceconstant{numbercolor}{colorenumero}
\setinterfaceconstant{numbercommand}{comandonumero}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{numberdistance}
\setinterfaceconstant{numbering}{numerazione}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{separatorenumero}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{stilenumero}
\setinterfaceconstant{numberwidth}{numberwidth}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{limitipagina}
\setinterfaceconstant{pagecolor}{colorepagina}
\setinterfaceconstant{pagecommand}{comandopagina}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{numeropagina}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{statopagina}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{stilepagina}
\setinterfaceconstant{palet}{tavolozza}
\setinterfaceconstant{paper}{carta}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{mettistopper}
\setinterfaceconstant{position}{posizione}
\setinterfaceconstant{prefix}{prefisso}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{preimpostato}
\setinterfaceconstant{preview}{anteprima}
\setinterfaceconstant{previous}{precedente}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{riduzione}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{riferimento}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{referencing}
\setinterfaceconstant{regionin}{entraregione}
\setinterfaceconstant{regionout}{esciregione}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{spessorelinea}
\setinterfaceconstant{samepage}{stessapagina}
\setinterfaceconstant{sample}{campione}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{scala}
\setinterfaceconstant{scope}{scope}
\setinterfaceconstant{screen}{schermo}
\setinterfaceconstant{section}{sezione}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{numerosezione}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{separatore}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{setups}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{ystep}
% definitions for interface elements for language it
%
+\setinterfaceelement{answerlines}{answerlines}
+\setinterfaceelement{answerspace}{answerspace}
\setinterfaceelement{begin}{inizio}
\setinterfaceelement{complete}{completo}
\setinterfaceelement{coupled}{accoppiato}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{settext}
\setinterfacecommand{settextvariable}{setvariabiletesto}
\setinterfacecommand{setupalign}{impostaallineamento}
+\setinterfacecommand{setupanswerarea}{setupanswerarea}
\setinterfacecommand{setuparranging}{impostaparranging}
\setinterfacecommand{setupbackground}{impostasfondo}
\setinterfacecommand{setupbackgrounds}{impostasfondi}
diff --git a/tex/context/base/mult-mcs.tex b/tex/context/base/mult-mcs.tex
new file mode 100644
index 000000000..bee7b777d
--- /dev/null
+++ b/tex/context/base/mult-mcs.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{neznama reference --}
+\setinterfacemessage{references}{3}{neznamy typ reference --}
+\setinterfacemessage{references}{2}{duplicitni reference -- na strane --}
+\setinterfacemessage{references}{4}{nedovolena reference --}
+\setinterfacemessage{references}{title}{reference}
+\setinterfacemessage{references}{30}{neznamy objekt --}
+\setinterfacemessage{references}{31}{duplicitni object --}
+\setinterfacemessage{references}{21}{dokument -- nacten}
+\setinterfacemessage{references}{22}{dokument -- neni interaktivni}
+\setinterfacemessage{references}{23}{obskurni (nejasna) reference -- (prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{system}
+\setinterfacemessage{systems}{41}{externi soubor -- ve skupine -- neexistuje}
+\setinterfacemessage{systems}{9}{-- nenalezeno/nezpracovano}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{nova verze pomocneho souboru, je treba druheho behu}
+\setinterfacemessage{systems}{21}{pomocny soubor necten}
+\setinterfacemessage{systems}{20}{vyznam (trideni) -- nacten}
+\setinterfacemessage{systems}{5}{makra z -- nactena}
+\setinterfacemessage{systems}{4}{prikaz -- je jiz definovan}
+\setinterfacemessage{systems}{27}{verze}
+\setinterfacemessage{systems}{26}{registry}
+\setinterfacemessage{systems}{25}{reference}
+\setinterfacemessage{systems}{24}{plovouci bloky}
+\setinterfacemessage{systems}{1}{nacteni pomocneho souboru odlozeno (typemode)}
+\setinterfacemessage{systems}{23}{-- upraveno na --}
+\setinterfacemessage{systems}{22}{pouzijte platny pomocny soubor}
+\setinterfacemessage{systems}{2}{-- nacteno}
+\setinterfacemessage{systems}{19}{vyznam (synonyma) -- nacten}
+\setinterfacemessage{systems}{18}{synonymum -- -- neexistuje}
+\setinterfacemessage{systems}{7}{makra z -- jsou jiz nactena}
+\setinterfacemessage{systems}{6}{zadna makra v -- nenalezena}
+\setinterfacemessage{systems}{14}{vynucena nova stranka v seznamu na --}
+\setinterfacemessage{systems}{15}{uklada se buffer --}
+\setinterfacemessage{systems}{16}{sazi se buffer --}
+\setinterfacemessage{systems}{17}{sazi se doslovny (verbatim) buffer --}
+\setinterfacemessage{systems}{13}{znacka -- definovana --}
+\setinterfacemessage{systems}{12}{pomosny soubor neni setriden, pouzijte texutil}
+\setinterfacemessage{systems}{11}{vytvarim jednoduchy pomocny soubor}
+\setinterfacemessage{systems}{10}{nepouzivejte em v --}
+\setinterfacemessage{floatblocks}{1}{-- precislovano / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- presunuto}
+\setinterfacemessage{floatblocks}{2}{-- ulozeno}
+\setinterfacemessage{floatblocks}{5}{poradi prizpusobeno}
+\setinterfacemessage{floatblocks}{4}{-- umisteno}
+\setinterfacemessage{floatblocks}{7}{pocet spodnich plovoucich objektu je omezen na --}
+\setinterfacemessage{floatblocks}{6}{pocet hornich plovoucich objektu je omezen na --}
+\setinterfacemessage{floatblocks}{9}{poradi naruseno}
+\setinterfacemessage{floatblocks}{8}{radku je mene nez --}
+\setinterfacemessage{floatblocks}{title}{plovouciobjekty}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{nedefinovano}
+\setinterfacemessage{floatblocks}{11}{nedan zadny blok}
+\setinterfacemessage{floatblocks}{10}{-- omezeno}
+\setinterfacemessage{interactions}{1}{pomer -- x -- (s x v)}
+\setinterfacemessage{interactions}{3}{neaktivni}
+\setinterfacemessage{interactions}{2}{aktivni}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{zadna strankova synchronizace (--) v hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interakce}
+\setinterfacemessage{interactions}{21}{-- kod vlozen}
+\setinterfacemessage{structures}{1}{zacatek oddilu (sekce) --}
+\setinterfacemessage{structures}{title}{struktury}
+\setinterfacemessage{structures}{2}{konec oddilu (sekce) --}
+\setinterfacemessage{linguals}{1}{vzory -- pro -- nacteny (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{deleni slov -- pro -- nacteno (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{zadne vzory -- pro -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{vzory pro -- nenacteny}
+\setinterfacemessage{linguals}{4}{zadne deleni slov -- pro -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{specificke volby jazyka [--] zavadeji -- (zavlecenou) mezeru}
+\setinterfacemessage{linguals}{6}{jazyk -- neni definovan}
+\setinterfacemessage{linguals}{9}{language -- is active}
+\setinterfacemessage{linguals}{8}{specificke volby jazyka [--] bez mezer pripojeny}
+\setinterfacemessage{linguals}{title}{jazyky}
+\setinterfacemessage{linguals}{10}{vzory --nacteny}
+\setinterfacemessage{regimes}{1}{kodovani --}
+\setinterfacemessage{regimes}{3}{nezname kodovani --}
+\setinterfacemessage{regimes}{2}{je nacteno kodovani --}
+\setinterfacemessage{regimes}{title}{kodovani}
+\setinterfacemessage{filters}{1}{filter -- is loaded}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{soubor -- neexistuje}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{kodovani --}
+\setinterfacemessage{encodings}{3}{nezname kodovani --}
+\setinterfacemessage{encodings}{2}{je nacteno kodovani --}
+\setinterfacemessage{encodings}{title}{kodovani}
+\setinterfacemessage{columns}{1}{je mozno pouze -- sloupcu}
+\setinterfacemessage{columns}{3}{problem, vypina se vyvazovani}
+\setinterfacemessage{columns}{2}{pouzijte \string\filbreak\space jako alternativu}
+\setinterfacemessage{columns}{5}{spodni plovouci objekt jeste neni podporovan}
+\setinterfacemessage{columns}{4}{horni plovouci objekt jeste neni podporovan}
+\setinterfacemessage{columns}{7}{vyvazovani ukonceno po 100 krocich}
+\setinterfacemessage{columns}{6}{-- plovouci objekt(y) odlozeny}
+\setinterfacemessage{columns}{9}{kontrola nerovnost}
+\setinterfacemessage{columns}{8}{vyvazeno v -- krocich}
+\setinterfacemessage{columns}{title}{sloupce}
+\setinterfacemessage{columns}{13}{siroky plovouci objekt je presunut nad sloupce}
+\setinterfacemessage{columns}{12}{plovouci objekt je presunut do nasledujiciho sloupce / --}
+\setinterfacemessage{columns}{11}{plovouci objekt je pro sloupec prilis siroky}
+\setinterfacemessage{columns}{10}{zbyl (mene nez) 1 radek}
+\setinterfacemessage{textblocks}{1}{nova verze, je treba druhy beh}
+\setinterfacemessage{textblocks}{3}{ctu bloky z --}
+\setinterfacemessage{textblocks}{2}{zapisuji bloky do --}
+\setinterfacemessage{textblocks}{5}{-- neni skryto}
+\setinterfacemessage{textblocks}{4}{je treba druhy beh}
+\setinterfacemessage{textblocks}{7}{-- skryto}
+\setinterfacemessage{textblocks}{6}{-- skryto a zpracovano}
+\setinterfacemessage{textblocks}{9}{-- nevysazeno}
+\setinterfacemessage{textblocks}{8}{-- vysazeno}
+\setinterfacemessage{textblocks}{title}{textovyblok}
+\setinterfacemessage{textblocks}{12}{-- preskoceno}
+\setinterfacemessage{textblocks}{11}{-- nacteno a vysazeno}
+\setinterfacemessage{textblocks}{10}{-- nacteno a zpracovano}
+\setinterfacemessage{symbols}{1}{nacita se soubor symbolu --}
+\setinterfacemessage{symbols}{title}{symboly}
+\setinterfacemessage{versions}{1}{postradam @+}
+\setinterfacemessage{versions}{3}{oznacene strany: --}
+\setinterfacemessage{versions}{2}{oznacuji se strany}
+\setinterfacemessage{versions}{title}{verze}
+\setinterfacemessage{specials}{1}{-- nacteno}
+\setinterfacemessage{specials}{3}{-- je resetovano}
+\setinterfacemessage{specials}{2}{neni dovoleno hlubsi zanoreni --}
+\setinterfacemessage{specials}{5}{nacita se definicni soubor --}
+\setinterfacemessage{specials}{4}{prikaz -- neexistuje}
+\setinterfacemessage{specials}{7}{neznamy ovladac (driver) --}
+\setinterfacemessage{specials}{6}{zanoreni neni dovoleno}
+\setinterfacemessage{specials}{title}{speciality}
+\setinterfacemessage{javascript}{1}{nacita se soubor skriptu --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{neznama preambule --}
+\setinterfacemessage{fonts}{1}{kodovani --}
+\setinterfacemessage{fonts}{3}{neznama varianta --}
+\setinterfacemessage{fonts}{2}{varianta -- je nactena}
+\setinterfacemessage{fonts}{5}{styl -- neni definovan}
+\setinterfacemessage{fonts}{4}{zakladni font -- neni definovan}
+\setinterfacemessage{fonts}{7}{neznamy format --}
+\setinterfacemessage{fonts}{6}{-- je nacten}
+\setinterfacemessage{fonts}{14}{bodyfont -- is defined (can better be done global)}
+\setinterfacemessage{fonts}{8}{styl -- definovan}
+\setinterfacemessage{fonts}{title}{zakladnifont}
+\setinterfacemessage{fonts}{10}{neznamy font --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{global file --}
+\setinterfacemessage{databases}{2}{local file --}
+\setinterfacemessage{databases}{4}{unknown file --}
+\setinterfacemessage{databases}{title}{databases}
+\setinterfacemessage{colors}{1}{system -- je globalne aktivovana}
+\setinterfacemessage{colors}{3}{-- neni definovana --}
+\setinterfacemessage{colors}{2}{system -- je lokalne activovana}
+\setinterfacemessage{colors}{5}{neznamy system --}
+\setinterfacemessage{colors}{4}{system -- je nacten}
+\setinterfacemessage{colors}{7}{palette -- neni k dispozici}
+\setinterfacemessage{colors}{6}{palette -- je k dispozici}
+\setinterfacemessage{colors}{9}{-- prostor barev neni podporovan}
+\setinterfacemessage{colors}{8}{specifikace -- v barve -- bude cerna}
+\setinterfacemessage{colors}{title}{barva}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{barva je prevedena na sed}
+\setinterfacemessage{colors}{10}{-- prostor barev je podporovan}
+\setinterfacemessage{layouts}{1}{vyska textu prizpusobena s -- na strane --}
+\setinterfacemessage{layouts}{3}{-- krat text odlozen}
+\setinterfacemessage{layouts}{2}{-- krat odlozeny text umisten}
+\setinterfacemessage{layouts}{5}{okrajove bloky neaktivni}
+\setinterfacemessage{layouts}{4}{okrajove bloky aktivni}
+\setinterfacemessage{layouts}{7}{pocita se misto pro logo}
+\setinterfacemessage{layouts}{6}{sada stran -- zpracovana (velikost --)}
+\setinterfacemessage{layouts}{9}{aktualne ne vice nez -- urovne/urovni vyctu}
+\setinterfacemessage{layouts}{8}{pocita se pozadi}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{svisla mezera -- neni povolena v pevnem radkovem rejstriku}
+\setinterfacemessage{layouts}{10}{-- a -- nedava dohromady 1.0}
+\setinterfacemessage{check}{1}{postradam '=' po '--' na radku --}
+\setinterfacemessage{check}{3}{-- -- nahrazuje makro, uzijte VERZALKY!}
+\setinterfacemessage{check}{2}{ocekavam -- argument(y) na radku --}
+\setinterfacemessage{check}{title}{kontrola}
+\setinterfacemessage{metapost}{1}{loading metapost library --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{synonymum souboru -- je jiz pouzito pro --}
+\setinterfacemessage{files}{title}{soubory}
+\setinterfacemessage{figures}{1}{obraz -- nelze nalezt}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{obraz -- nepritomen}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimenze obrazu -- nacteny primo z jeho souboru}
+\setinterfacemessage{figures}{6}{dimenze obrazu -- spocteny programem rlxtools}
+\setinterfacemessage{figures}{8}{obrazovy objekt -- je znovu pouzit}
+\setinterfacemessage{figures}{title}{obrazy}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mde.tex b/tex/context/base/mult-mde.tex
new file mode 100644
index 000000000..a80ac4306
--- /dev/null
+++ b/tex/context/base/mult-mde.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{unbekannte Referenz --}
+\setinterfacemessage{references}{3}{unbekannte Referenz Typ --}
+\setinterfacemessage{references}{2}{doppelte Referenz -- auf Seite --}
+\setinterfacemessage{references}{4}{illegale Referenz --}
+\setinterfacemessage{references}{title}{referenzen}
+\setinterfacemessage{references}{30}{unbekanntes Object --}
+\setinterfacemessage{references}{31}{doppeltes Object --}
+\setinterfacemessage{references}{21}{Dokument -- geladen}
+\setinterfacemessage{references}{22}{Dokument -- ist nicht aktiv}
+\setinterfacemessage{references}{23}{Obskure Referenz -- (Prefix=--)}
+\setinterfacemessage{documents}{1}{Blatt --}
+\setinterfacemessage{documents}{title}{Blaetter}
+\setinterfacemessage{documents}{2}{Nummer --}
+\setinterfacemessage{handlings}{1}{Font Verarbeitung --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{Font Verarbeitung -- ist geladen}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{system}
+\setinterfacemessage{systems}{41}{Externe Datei -- in Gruppe -- existiert nicht}
+\setinterfacemessage{systems}{9}{-- nicht gefunden/verarbeitet}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{Neue Version der Hilfsdatei, zweiter Durchlauf benoetigt}
+\setinterfacemessage{systems}{21}{Die Hilfsdatei ist nicht geladen}
+\setinterfacemessage{systems}{20}{Bedeutung (sortieren) von -- geladen}
+\setinterfacemessage{systems}{5}{Modul -- geladen}
+\setinterfacemessage{systems}{4}{Befehl -- ist bereits definiert}
+\setinterfacemessage{systems}{27}{Version}
+\setinterfacemessage{systems}{26}{Register}
+\setinterfacemessage{systems}{25}{Referenzen}
+\setinterfacemessage{systems}{24}{Fliessbloecke}
+\setinterfacemessage{systems}{1}{Laden der Hilfsdatei aufgeschoben (Eingabe-Modus)}
+\setinterfacemessage{systems}{23}{-- angeordnet auf --}
+\setinterfacemessage{systems}{22}{Benoetige gueltige Hilfsdateie}
+\setinterfacemessage{systems}{2}{-- geladen}
+\setinterfacemessage{systems}{19}{Bedeutung (synonyme) von -- geladen}
+\setinterfacemessage{systems}{18}{Synonym -- -- existiert nicht}
+\setinterfacemessage{systems}{7}{Modul -- bereits geladen}
+\setinterfacemessage{systems}{6}{Modul -- gefunden}
+\setinterfacemessage{systems}{14}{Erzwungendes Seitenumbruch in Liste bei --}
+\setinterfacemessage{systems}{15}{Speichere Buffer --}
+\setinterfacemessage{systems}{16}{Setzte Buffer --}
+\setinterfacemessage{systems}{17}{Setzte tippen-Buffer --}
+\setinterfacemessage{systems}{13}{Beschriftung -- definiert --}
+\setinterfacemessage{systems}{12}{Die Hilfdatei ist nicht sortiert, verwende texutil}
+\setinterfacemessage{systems}{11}{Erstelle einfache Hilfdatei}
+\setinterfacemessage{systems}{10}{Benutzte kein em in --}
+\setinterfacemessage{floatblocks}{1}{-- neu nummeriert / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- verschoben}
+\setinterfacemessage{floatblocks}{2}{-- gespeichert}
+\setinterfacemessage{floatblocks}{5}{Reihenfolge angepasst}
+\setinterfacemessage{floatblocks}{4}{-- plaziert}
+\setinterfacemessage{floatblocks}{7}{Anz. der unteren Gleitobjekte beschraengt auf --}
+\setinterfacemessage{floatblocks}{6}{Anz. der oberen Gleitobjekte beschraengt auf --}
+\setinterfacemessage{floatblocks}{9}{Reigenfolge gestoert}
+\setinterfacemessage{floatblocks}{8}{weniger als -- zeilen}
+\setinterfacemessage{floatblocks}{title}{Gleitobjektbloecke}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{undefiniert}
+\setinterfacemessage{floatblocks}{11}{kein Block gegeben}
+\setinterfacemessage{floatblocks}{10}{-- begrenzt}
+\setinterfacemessage{interactions}{1}{Seitenverhaeltnis -- x -- (B x H)}
+\setinterfacemessage{interactions}{3}{inaktiv}
+\setinterfacemessage{interactions}{2}{aktiv}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{keine Seitensynchronisation (--) im hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{Interaktion}
+\setinterfacemessage{interactions}{21}{-- Code eingefuegt}
+\setinterfacemessage{structures}{1}{Begin des Abschnittsblocks --}
+\setinterfacemessage{structures}{title}{struktur}
+\setinterfacemessage{structures}{2}{Ende des Abschnittsblocks --}
+\setinterfacemessage{linguals}{1}{Trennmuster -- fuer -- geladen (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{Trenndefinitionen -- fuer -- geladen (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{Keine Trennmuster -- fuer -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{Trennmuster fuer -- nicht geladen}
+\setinterfacemessage{linguals}{4}{Keine Trenndefinitionen -- fuer -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{Sprachenspezifische Option [--] fuegt eine Luecke von -- ein}
+\setinterfacemessage{linguals}{6}{Sprache -- ist undefiniert}
+\setinterfacemessage{linguals}{9}{Sprache -- ist aktiv}
+\setinterfacemessage{linguals}{8}{Sprachenspezifische Option [--] nahtlos hinzugefuegt}
+\setinterfacemessage{linguals}{title}{Sprache}
+\setinterfacemessage{linguals}{10}{Trennmuster --geladen}
+\setinterfacemessage{regimes}{1}{Kodierung --}
+\setinterfacemessage{regimes}{3}{Unbekannte Kodierung --}
+\setinterfacemessage{regimes}{2}{Kodierung -- ist geladen}
+\setinterfacemessage{regimes}{title}{Kodierung}
+\setinterfacemessage{filters}{1}{filter -- ist geladen}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{Datei -- existiert nicht}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{Kodierung --}
+\setinterfacemessage{encodings}{3}{Unbekannte Kodierung --}
+\setinterfacemessage{encodings}{2}{Kodierung -- ist geladen}
+\setinterfacemessage{encodings}{title}{Kodierung}
+\setinterfacemessage{columns}{1}{nur -- Spalten moeglich}
+\setinterfacemessage{columns}{3}{Problem, verwende [ausgleich=nein]}
+\setinterfacemessage{columns}{2}{benutzte \string\filbreak\space als Alternative}
+\setinterfacemessage{columns}{5}{Gleitobjekt unten ncoh nicht unterstuetzt}
+\setinterfacemessage{columns}{4}{Gleitobjekt oben ncoh nicht unterstuetzt}
+\setinterfacemessage{columns}{7}{ausgleich nach 100 Schritten abgebrocheb}
+\setinterfacemessage{columns}{6}{-- Gleitobjekt(e) verschoben}
+\setinterfacemessage{columns}{9}{Ausrichtung ueberpruefen}
+\setinterfacemessage{columns}{8}{ausgeglichen nach -- Schritt(en)}
+\setinterfacemessage{columns}{title}{Spalten}
+\setinterfacemessage{columns}{13}{breites Gleitobjekt an den Anfang der Spalten verschoben}
+\setinterfacemessage{columns}{12}{Gleitobjekt in naechste Zeile verschoben / --}
+\setinterfacemessage{columns}{11}{Gleitobjekt zu breit fuer Spalte}
+\setinterfacemessage{columns}{10}{(weniger als) 1 Zeile uebrig}
+\setinterfacemessage{textblocks}{1}{neue Version, zweiter Durchlauf benoetigt}
+\setinterfacemessage{textblocks}{3}{lese Bloecke von --}
+\setinterfacemessage{textblocks}{2}{schreibe Bloecke zu --}
+\setinterfacemessage{textblocks}{5}{-- nicht verborgen}
+\setinterfacemessage{textblocks}{4}{zweiter Durchlauf benoetigt}
+\setinterfacemessage{textblocks}{7}{-- verborgen}
+\setinterfacemessage{textblocks}{6}{-- verborgen und verarbeitet}
+\setinterfacemessage{textblocks}{9}{-- nicht gesetzt}
+\setinterfacemessage{textblocks}{8}{-- gesetzt}
+\setinterfacemessage{textblocks}{title}{textblock}
+\setinterfacemessage{textblocks}{12}{-- ausgelassen}
+\setinterfacemessage{textblocks}{11}{-- geladen und gesetzt}
+\setinterfacemessage{textblocks}{10}{-- geladen und verarbeitet}
+\setinterfacemessage{symbols}{1}{Lade Symboldatei --}
+\setinterfacemessage{symbols}{title}{Symbole}
+\setinterfacemessage{versions}{1}{fehlendes @+}
+\setinterfacemessage{versions}{3}{Ausgewaehlte Seiten: --}
+\setinterfacemessage{versions}{2}{Erstelle Seiten}
+\setinterfacemessage{versions}{title}{Version}
+\setinterfacemessage{specials}{1}{-- geladen}
+\setinterfacemessage{specials}{3}{-- ist zurueckgesetzt}
+\setinterfacemessage{specials}{2}{keine tiefere Verschachtelung erlaubt --}
+\setinterfacemessage{specials}{5}{lade Definitionsdatei --}
+\setinterfacemessage{specials}{4}{Befehl -- existiert nicht}
+\setinterfacemessage{specials}{7}{unbekante Driver --}
+\setinterfacemessage{specials}{6}{Verschachtelung nicht erlaubt}
+\setinterfacemessage{specials}{title}{spezielles}
+\setinterfacemessage{javascript}{1}{Lade Scriptdatei --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{unbekannte Preamble --}
+\setinterfacemessage{fonts}{1}{Kodierung --}
+\setinterfacemessage{fonts}{3}{Unbekannte Variante --}
+\setinterfacemessage{fonts}{2}{Variante -- ist geladen}
+\setinterfacemessage{fonts}{5}{Stil -- ist nicht definiert}
+\setinterfacemessage{fonts}{4}{Fliesstext -- ist nicht definiert}
+\setinterfacemessage{fonts}{7}{unbekanntes Format --}
+\setinterfacemessage{fonts}{6}{-- ist geladen}
+\setinterfacemessage{fonts}{14}{Fliesstext -- wurde definiert (besser waere globale Definition)}
+\setinterfacemessage{fonts}{8}{Stil -- definiert}
+\setinterfacemessage{fonts}{title}{Fliesstext}
+\setinterfacemessage{fonts}{10}{unbekanntes Font --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{globale Datei --}
+\setinterfacemessage{databases}{2}{lokale Datei --}
+\setinterfacemessage{databases}{4}{unbekannte Datei --}
+\setinterfacemessage{databases}{title}{Datenbank}
+\setinterfacemessage{colors}{1}{system -- ist global aktiviert}
+\setinterfacemessage{colors}{3}{-- ist undefiniert --}
+\setinterfacemessage{colors}{2}{system -- ist lokal aktiviert}
+\setinterfacemessage{colors}{5}{unbekanntes System --}
+\setinterfacemessage{colors}{4}{system -- ist geladen}
+\setinterfacemessage{colors}{7}{palette -- ist nicht verfuegbar}
+\setinterfacemessage{colors}{6}{palette -- ist verfuegbar}
+\setinterfacemessage{colors}{9}{-- Farbraum wird nicht unterstuetzt}
+\setinterfacemessage{colors}{8}{Spezifikation -- bei Farbe -- wird schwarz}
+\setinterfacemessage{colors}{title}{farbe}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{Farbe wird in Grau umgewandelt}
+\setinterfacemessage{colors}{10}{-- Farbraum wird unterstuetzt}
+\setinterfacemessage{layouts}{1}{Texthoehe angepasst mit -- auf Seite --}
+\setinterfacemessage{layouts}{3}{-- mal Text verschoben}
+\setinterfacemessage{layouts}{2}{-- mal verschobener Text plaziert}
+\setinterfacemessage{layouts}{5}{marginalbloecke inaktiv}
+\setinterfacemessage{layouts}{4}{marginalbloecke aktiv}
+\setinterfacemessage{layouts}{7}{berechne Platzbedarf des Logos}
+\setinterfacemessage{layouts}{6}{Unterseitenfolge -- verarbeitet (Groesse --)}
+\setinterfacemessage{layouts}{9}{z.Z. nicht mehr als -- Ebenen in Aufzaehlungen}
+\setinterfacemessage{layouts}{8}{berechne Hintergrund}
+\setinterfacemessage{layouts}{title}{Layout}
+\setinterfacemessage{layouts}{11}{Zwischenraum -- nicht im Grittermoduserlau}
+\setinterfacemessage{layouts}{10}{-- und -- ergeben zusammen nicht 1.0}
+\setinterfacemessage{check}{1}{Fehlendes '=' nach '--' in Zeile --}
+\setinterfacemessage{check}{3}{-- -- ersetzt ein Makro, verwende VERSALIEN!}
+\setinterfacemessage{check}{2}{-- Argument(e) in Zeile -- erwartet}
+\setinterfacemessage{check}{title}{check}
+\setinterfacemessage{metapost}{1}{Lade metapost Bibliothek --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{Dateisynonym -- wird bereits fuer -- benutzt}
+\setinterfacemessage{files}{title}{files}
+\setinterfacemessage{figures}{1}{Abbildung -- kann nicht gefunden werden}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{Abbildung -- wird nicht erstellt}
+\setinterfacemessage{figures}{5}{Dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{Dimensionen von -- geladen aus der Abbildungsdatei selbst}
+\setinterfacemessage{figures}{6}{Dimensionen von -- ausgerechnet durch rlxtools}
+\setinterfacemessage{figures}{8}{Abbildungobjekt -- wurde wiederverwandt}
+\setinterfacemessage{figures}{title}{Abbildungen}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-men.tex b/tex/context/base/mult-men.tex
new file mode 100644
index 000000000..8335d2911
--- /dev/null
+++ b/tex/context/base/mult-men.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{unknown reference --}
+\setinterfacemessage{references}{3}{unknown reference type --}
+\setinterfacemessage{references}{2}{duplicate reference -- on page --}
+\setinterfacemessage{references}{4}{illegal reference --}
+\setinterfacemessage{references}{title}{references}
+\setinterfacemessage{references}{30}{unknown object --}
+\setinterfacemessage{references}{31}{duplicate object --}
+\setinterfacemessage{references}{21}{document -- loaded}
+\setinterfacemessage{references}{22}{document -- is not interactive}
+\setinterfacemessage{references}{23}{obscure reference -- (prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{system}
+\setinterfacemessage{systems}{41}{external file -- in group -- does not exist}
+\setinterfacemessage{systems}{9}{-- not found/processed}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{new version of utility file, second pass needed}
+\setinterfacemessage{systems}{21}{no utility data is loaded}
+\setinterfacemessage{systems}{20}{meaning (sorts) of -- loaded}
+\setinterfacemessage{systems}{5}{module -- loaded}
+\setinterfacemessage{systems}{4}{command -- is already defined}
+\setinterfacemessage{systems}{27}{Version}
+\setinterfacemessage{systems}{26}{Registers}
+\setinterfacemessage{systems}{25}{References}
+\setinterfacemessage{systems}{24}{Floatblocks}
+\setinterfacemessage{systems}{1}{loading utility-file postponed (typemode)}
+\setinterfacemessage{systems}{23}{-- arranged at --}
+\setinterfacemessage{systems}{22}{use a valid utilityfile}
+\setinterfacemessage{systems}{2}{-- loaded}
+\setinterfacemessage{systems}{19}{meaning (synonyms) of -- loaded}
+\setinterfacemessage{systems}{18}{synonym -- -- does not exist}
+\setinterfacemessage{systems}{7}{module -- already loaded}
+\setinterfacemessage{systems}{6}{module -- not found}
+\setinterfacemessage{systems}{14}{forced newpage in list at --}
+\setinterfacemessage{systems}{15}{saving buffer --}
+\setinterfacemessage{systems}{16}{typesetting buffer --}
+\setinterfacemessage{systems}{17}{typesetting verbatim buffer --}
+\setinterfacemessage{systems}{13}{mark -- defined --}
+\setinterfacemessage{systems}{12}{the utility-file is not sorted, use texutil}
+\setinterfacemessage{systems}{11}{building simple util}
+\setinterfacemessage{systems}{10}{don't use em in --}
+\setinterfacemessage{floatblocks}{1}{-- renumbered / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- moved}
+\setinterfacemessage{floatblocks}{2}{-- saved}
+\setinterfacemessage{floatblocks}{5}{order adapted}
+\setinterfacemessage{floatblocks}{4}{-- placed}
+\setinterfacemessage{floatblocks}{7}{n of bottom floats limited to --}
+\setinterfacemessage{floatblocks}{6}{n of top floats limited to --}
+\setinterfacemessage{floatblocks}{9}{order disturbed}
+\setinterfacemessage{floatblocks}{8}{less than -- lines}
+\setinterfacemessage{floatblocks}{title}{floatblocks}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{undefined}
+\setinterfacemessage{floatblocks}{11}{no block given}
+\setinterfacemessage{floatblocks}{10}{-- limited}
+\setinterfacemessage{interactions}{1}{aspect ratio -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{inactive}
+\setinterfacemessage{interactions}{2}{active}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{no pagesynchronisation (--) in hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interaction}
+\setinterfacemessage{interactions}{21}{-- code inserted}
+\setinterfacemessage{structures}{1}{begin of sectionblock --}
+\setinterfacemessage{structures}{title}{structure}
+\setinterfacemessage{structures}{2}{end of sectionblock --}
+\setinterfacemessage{linguals}{1}{patterns -- for -- loaded (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{hyphenations -- for -- loaded (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{no patterns -- for -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{patterns for -- not loaded}
+\setinterfacemessage{linguals}{4}{no hyphenations -- for -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{language specific options [--] introduce a -- skip}
+\setinterfacemessage{linguals}{6}{language -- is undefined}
+\setinterfacemessage{linguals}{9}{language -- is active}
+\setinterfacemessage{linguals}{8}{language specific options [--] seamless appended}
+\setinterfacemessage{linguals}{title}{language}
+\setinterfacemessage{linguals}{10}{patterns --loaded}
+\setinterfacemessage{regimes}{1}{regime --}
+\setinterfacemessage{regimes}{3}{unknown regime --}
+\setinterfacemessage{regimes}{2}{regime -- is loaded}
+\setinterfacemessage{regimes}{title}{regime}
+\setinterfacemessage{filters}{1}{filter -- is loaded}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{file -- does not exist}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{coding --}
+\setinterfacemessage{encodings}{3}{unknown coding --}
+\setinterfacemessage{encodings}{2}{coding -- is loaded}
+\setinterfacemessage{encodings}{title}{encoding}
+\setinterfacemessage{columns}{1}{only -- columns possible}
+\setinterfacemessage{columns}{3}{problems, disable balancing}
+\setinterfacemessage{columns}{2}{use \string\filbreak\space as alternative}
+\setinterfacemessage{columns}{5}{bottom float not yet supported}
+\setinterfacemessage{columns}{4}{top float not yet supported}
+\setinterfacemessage{columns}{7}{balancing aborted after 100 steps}
+\setinterfacemessage{columns}{6}{-- float(s) postponed}
+\setinterfacemessage{columns}{9}{check raggedness}
+\setinterfacemessage{columns}{8}{balanced in -- step(s)}
+\setinterfacemessage{columns}{title}{columns}
+\setinterfacemessage{columns}{13}{wide float moved to top of columns}
+\setinterfacemessage{columns}{12}{float moved to next column / --}
+\setinterfacemessage{columns}{11}{float too wide for column}
+\setinterfacemessage{columns}{10}{(less than) 1 line left}
+\setinterfacemessage{textblocks}{1}{new version, second pass needed}
+\setinterfacemessage{textblocks}{3}{reading blocks from --}
+\setinterfacemessage{textblocks}{2}{writing blocks to --}
+\setinterfacemessage{textblocks}{5}{-- not hidden}
+\setinterfacemessage{textblocks}{4}{second pass needed}
+\setinterfacemessage{textblocks}{7}{-- hidden}
+\setinterfacemessage{textblocks}{6}{-- hidden and processed}
+\setinterfacemessage{textblocks}{9}{-- not typeset}
+\setinterfacemessage{textblocks}{8}{-- typeset}
+\setinterfacemessage{textblocks}{title}{textblocks}
+\setinterfacemessage{textblocks}{12}{-- skipped}
+\setinterfacemessage{textblocks}{11}{-- loaded and typeset}
+\setinterfacemessage{textblocks}{10}{-- loaded and processed}
+\setinterfacemessage{symbols}{1}{loading symbolset --}
+\setinterfacemessage{symbols}{title}{symbols}
+\setinterfacemessage{versions}{1}{missing @+}
+\setinterfacemessage{versions}{3}{selected pages: --}
+\setinterfacemessage{versions}{2}{marking pages}
+\setinterfacemessage{versions}{title}{version}
+\setinterfacemessage{specials}{1}{-- loaded}
+\setinterfacemessage{specials}{3}{-- is reset}
+\setinterfacemessage{specials}{2}{no deeper nesting is permitted --}
+\setinterfacemessage{specials}{5}{loading definition file --}
+\setinterfacemessage{specials}{4}{command -- does not exist}
+\setinterfacemessage{specials}{7}{unknown driver --}
+\setinterfacemessage{specials}{6}{nesting is not permitted}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{loading script set --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{unknown preamble --}
+\setinterfacemessage{fonts}{1}{coding --}
+\setinterfacemessage{fonts}{3}{unknown variant --}
+\setinterfacemessage{fonts}{2}{variant -- is loaded}
+\setinterfacemessage{fonts}{5}{style -- is not defined}
+\setinterfacemessage{fonts}{4}{bodyfont -- is not defined}
+\setinterfacemessage{fonts}{7}{unknown format --}
+\setinterfacemessage{fonts}{6}{-- is loaded}
+\setinterfacemessage{fonts}{14}{bodyfont -- is defined (can better be done global)}
+\setinterfacemessage{fonts}{8}{style -- defined}
+\setinterfacemessage{fonts}{title}{bodyfont}
+\setinterfacemessage{fonts}{10}{unknown font file --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{global file --}
+\setinterfacemessage{databases}{2}{local file --}
+\setinterfacemessage{databases}{4}{unknown file --}
+\setinterfacemessage{databases}{title}{databases}
+\setinterfacemessage{colors}{1}{system -- is global activated}
+\setinterfacemessage{colors}{3}{-- is not defined --}
+\setinterfacemessage{colors}{2}{system -- is local activated}
+\setinterfacemessage{colors}{5}{unknown system --}
+\setinterfacemessage{colors}{4}{system -- is loaded}
+\setinterfacemessage{colors}{7}{palette -- is not available}
+\setinterfacemessage{colors}{6}{palette -- is available}
+\setinterfacemessage{colors}{9}{-- color space is not supported}
+\setinterfacemessage{colors}{8}{specification -- at color -- becomes black}
+\setinterfacemessage{colors}{title}{color}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{color is converted to gray}
+\setinterfacemessage{colors}{10}{-- color space is supported}
+\setinterfacemessage{layouts}{1}{textheight adapted with -- at page --}
+\setinterfacemessage{layouts}{3}{-- times text postponed}
+\setinterfacemessage{layouts}{2}{-- times postponed text placed}
+\setinterfacemessage{layouts}{5}{marginblocks inactive}
+\setinterfacemessage{layouts}{4}{marginblocks active}
+\setinterfacemessage{layouts}{7}{calculating logospace}
+\setinterfacemessage{layouts}{6}{subpage set -- processed (size --)}
+\setinterfacemessage{layouts}{9}{currently no more than -- levels in itemizations}
+\setinterfacemessage{layouts}{8}{calculating backgrounds}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{spacing -- not permitted in gridmode}
+\setinterfacemessage{layouts}{10}{-- and -- don't add up to 1.0}
+\setinterfacemessage{check}{1}{missing or ungrouped '=' after '--' in line --}
+\setinterfacemessage{check}{3}{-- -- replaces a macro, use CAPITALS!}
+\setinterfacemessage{check}{2}{-- argument(s) expected in line --}
+\setinterfacemessage{check}{title}{check}
+\setinterfacemessage{metapost}{1}{loading metapost library --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{file synonym -- is already used for --}
+\setinterfacemessage{files}{title}{files}
+\setinterfacemessage{figures}{1}{figure -- can not be found}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{figure -- is not preset}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimensions of -- loaded from figurefile itself}
+\setinterfacemessage{figures}{6}{dimensions of -- calculated by rlxtools}
+\setinterfacemessage{figures}{8}{figureobject -- is reused}
+\setinterfacemessage{figures}{title}{figures}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mes.lua b/tex/context/base/mult-mes.lua
new file mode 100644
index 000000000..6d177fd8f
--- /dev/null
+++ b/tex/context/base/mult-mes.lua
@@ -0,0 +1,2005 @@
+return {
+ ["check"]={
+ ["1"]={
+ ["cs"]="postradam '=' po '--' na radku --",
+ ["de"]="Fehlendes '=' nach '--' in Zeile --",
+ ["en"]="missing or ungrouped '=' after '--' in line --",
+ ["fr"]="manquant ou dégroupé '=' après '--' à la ligne --",
+ ["it"]="'=' mancante o non raggruppato dopo '--' alla riga --",
+ ["nl"]="'=' ontbreekt of zonder {} na '--' in regel --",
+ ["no"]="manglende '=' etter '--' i linje --",
+ ["ro"]="lipseste '=' dupa '--' in linia --",
+ },
+ ["2"]={
+ ["cs"]="ocekavam -- argument(y) na radku --",
+ ["de"]="-- Argument(e) in Zeile -- erwartet",
+ ["en"]="-- argument(s) expected in line --",
+ ["fr"]="-- argument(s) attendu(s) à la ligne --",
+ ["it"]="-- argomento/i attesi alla riga --",
+ ["nl"]="-- argument(en) verwacht in regel --",
+ ["no"]="-- argument forventet i linje --",
+ ["ro"]="argumentul(ele) -- sunt asteptate in linia --",
+ },
+ ["3"]={
+ ["cs"]="-- -- nahrazuje makro, uzijte VERZALKY!",
+ ["de"]="-- -- ersetzt ein Makro, verwende VERSALIEN!",
+ ["en"]="-- -- replaces a macro, use CAPITALS!",
+ ["fr"]="-- -- remplace une macro, utilisez des MAJUSCULES !",
+ ["it"]="-- -- sostituisce una macro, usare le MAIUSCOLE!",
+ ["nl"]="-- -- vervangt een macro, gebruik HOOFDLETTERS!",
+ ["no"]="-- -- overskygger en makro, bruk STORE BOKSTAVER!",
+ ["ro"]="-- -- inlocuieste un macro, folositi MAJUSCULE!",
+ },
+ ["files"]={ "mult-sys.tex" },
+ ["title"]={
+ ["cs"]="kontrola",
+ ["de"]="check",
+ ["en"]="check",
+ ["fr"]="vérification",
+ ["it"]="controllo",
+ ["nl"]="controle",
+ ["no"]="kontroll",
+ ["ro"]="verificari",
+ },
+ },
+ ["colors"]={
+ ["1"]={
+ ["cs"]="system -- je globalne aktivovana",
+ ["de"]="system -- ist global aktiviert",
+ ["en"]="system -- is global activated",
+ ["fr"]="le système -- est globalement activé",
+ ["it"]="sistema -- attivato globalmente",
+ ["nl"]="systeem -- is globaal actief",
+ ["no"]="system -- er aktivert globalt",
+ ["ro"]="sistem -- este activata global",
+ },
+ ["10"]={
+ ["cs"]="-- prostor barev je podporovan",
+ ["de"]="-- Farbraum wird unterstuetzt",
+ ["en"]="-- color space is supported",
+ ["fr"]="-- l'espace de couleur est supporté",
+ ["it"]="spazio dei colori -- supportato",
+ ["nl"]="-- kleurruimte wordt ondersteund",
+ ["no"]="-- fargerom er støttet",
+ ["ro"]="spatiul de culoare -- este suportat",
+ },
+ ["11"]={
+ ["cs"]="barva je prevedena na sed",
+ ["de"]="Farbe wird in Grau umgewandelt",
+ ["en"]="color is converted to gray",
+ ["fr"]="la couleur est convertie en niveau de gris",
+ ["it"]="il colore ø convertito in grigio",
+ ["nl"]="kleur wordt vertaald in grijs",
+ ["no"]="fargen vil bli vist som grø",
+ ["ro"]="culoarea este convertita la gri",
+ },
+ ["12"]={
+ ["cs"]="-- is registered",
+ ["de"]="-- is registered",
+ ["en"]="-- is registered",
+ ["fr"]="-- est enregistré",
+ ["it"]="-- is registered",
+ ["nl"]="-- is geregistreerd",
+ ["no"]="-- is registered",
+ ["ro"]="-- is registered",
+ },
+ ["2"]={
+ ["cs"]="system -- je lokalne activovana",
+ ["de"]="system -- ist lokal aktiviert",
+ ["en"]="system -- is local activated",
+ ["fr"]="le système -- est localement activé",
+ ["it"]="sistema -- attivato localmente",
+ ["nl"]="systeem -- is lokaal actief",
+ ["no"]="system -- er aktivert lokalt",
+ ["ro"]="sistem -- este activata local",
+ },
+ ["3"]={
+ ["cs"]="-- neni definovana --",
+ ["de"]="-- ist undefiniert --",
+ ["en"]="-- is not defined --",
+ ["fr"]="-- n'est pas défini --",
+ ["it"]="-- non definito --",
+ ["nl"]="-- is niet gedefinieerd --",
+ ["no"]="-- er udefinert --",
+ ["ro"]="-- nu este definita --",
+ },
+ ["4"]={
+ ["cs"]="system -- je nacten",
+ ["de"]="system -- ist geladen",
+ ["en"]="system -- is loaded",
+ ["fr"]="le système -- est chargé",
+ ["it"]="sistema -- caricato",
+ ["nl"]="systeem -- wordt geladen",
+ ["no"]="system -- er lest inn",
+ ["ro"]="sistem -- este incarcata",
+ },
+ ["5"]={
+ ["cs"]="neznamy system --",
+ ["de"]="unbekanntes System --",
+ ["en"]="unknown system --",
+ ["fr"]="système -- inconnu",
+ ["it"]="sistema -- sconosciuto",
+ ["nl"]="onbekend systeem --",
+ ["no"]="ukjent system --",
+ ["ro"]="sistem -- necunoscuta",
+ },
+ ["6"]={
+ ["cs"]="palette -- je k dispozici",
+ ["de"]="palette -- ist verfuegbar",
+ ["en"]="palette -- is available",
+ ["fr"]="la palette -- est disponible",
+ ["it"]="tavolozza -- resa disponibile",
+ ["nl"]="palet -- is beschikbaar",
+ ["no"]="palett -- er tilgjengelig",
+ ["ro"]="paleta -- este disponibila",
+ },
+ ["7"]={
+ ["cs"]="palette -- neni k dispozici",
+ ["de"]="palette -- ist nicht verfuegbar",
+ ["en"]="palette -- is not available",
+ ["fr"]="le palette -- n'est pas disponible",
+ ["it"]="tavolozza -- non disponibile",
+ ["nl"]="palet -- is niet beschikbaar",
+ ["no"]="palett -- er ikke tilgjengelig",
+ ["ro"]="palette -- nu este disponibila",
+ },
+ ["8"]={
+ ["cs"]="specifikace -- v barve -- bude cerna",
+ ["de"]="Spezifikation -- bei Farbe -- wird schwarz",
+ ["en"]="specification -- at color -- becomes black",
+ ["fr"]="la spécification -- de la couleur -- devient noire",
+ ["it"]="specifica -- del colore -- convertita in nero",
+ ["nl"]="specificatie -- bij -- wordt zwart",
+ ["no"]="spesifikasjon -- for farge -- gir kun svart",
+ ["ro"]="specificatia -- la culoarea -- devine neagra",
+ },
+ ["9"]={
+ ["cs"]="-- prostor barev neni podporovan",
+ ["de"]="-- Farbraum wird nicht unterstuetzt",
+ ["en"]="-- color space is not supported",
+ ["fr"]="l'espace de couleur -- n'est pas supporté",
+ ["it"]="spazio dei colori -- non supportato",
+ ["nl"]="-- kleurruimte wordt niet ondersteund",
+ ["no"]="-- fargerom er ikke støttet",
+ ["ro"]="spatiul de culoare -- nu este suportat",
+ },
+ ["files"]={ "colo-ini.tex" },
+ ["title"]={
+ ["cs"]="barva",
+ ["de"]="farbe",
+ ["en"]="color",
+ ["fr"]="couleurs",
+ ["it"]="colore",
+ ["nl"]="kleur",
+ ["no"]="farge",
+ ["ro"]="culori",
+ },
+ },
+ ["columns"]={
+ ["1"]={
+ ["cs"]="je mozno pouze -- sloupcu",
+ ["de"]="nur -- Spalten moeglich",
+ ["en"]="only -- columns possible",
+ ["fr"]="seules -- colonnes possibles",
+ ["it"]="solo -- colonne possibili",
+ ["nl"]="maximaal -- kolommen",
+ ["no"]="maksimalt -- kolonner",
+ ["ro"]="este posibil numai -- coloane",
+ },
+ ["10"]={
+ ["cs"]="zbyl (mene nez) 1 radek",
+ ["de"]="(weniger als) 1 Zeile uebrig",
+ ["en"]="(less than) 1 line left",
+ ["fr"]="(moins de) 1 ligne restante",
+ ["it"]="(meno di) una riga rimasta",
+ ["nl"]="(minder dan) 1 regel over",
+ ["no"]="(mindre enn) 1 linje igjen",
+ ["ro"]="a mai ramas (mai putin de) 1 linie",
+ },
+ ["11"]={
+ ["cs"]="plovouci objekt je pro sloupec prilis siroky",
+ ["de"]="Gleitobjekt zu breit fuer Spalte",
+ ["en"]="float too wide for column",
+ ["fr"]="flottant mis à la largeur de la colonne",
+ ["it"]="oggetto mobile troppo ampio per la colonna",
+ ["nl"]="plaatsblok te breed voor kolom",
+ ["no"]="flytblokk for bredt for kolonna",
+ ["ro"]="blocul este prea lat pentru coloana",
+ },
+ ["12"]={
+ ["cs"]="plovouci objekt je presunut do nasledujiciho sloupce / --",
+ ["de"]="Gleitobjekt in naechste Zeile verschoben / --",
+ ["en"]="float moved to next column / --",
+ ["fr"]="flottant déplacé à la colonne suivante / --",
+ ["it"]="oggetto mobile spostata alla colonna successiva / --",
+ ["nl"]="plaatsblok verplaatst naar volgende kolom / --",
+ ["no"]="flytblokk forskjøvet til neste kolonne / --",
+ ["ro"]="blocul este mutat pe urmatoarea coloana / --",
+ },
+ ["13"]={
+ ["cs"]="siroky plovouci objekt je presunut nad sloupce",
+ ["de"]="breites Gleitobjekt an den Anfang der Spalten verschoben",
+ ["en"]="wide float moved to top of columns",
+ ["fr"]="flottant large déplacé dans la partie supérieure de la colonne",
+ ["it"]="oggetto mobile ampio spostato sopra le colonne",
+ ["nl"]="breed figuur geplaatst boven kolommen",
+ ["no"]="bred flytblokk forksjøvet til toppen av kolonnene",
+ ["ro"]="blocul lat este mutat in partea de sus a coloanelor",
+ },
+ ["2"]={
+ ["cs"]="pouzijte \\string\\filbreak\\space jako alternativu",
+ ["de"]="benutzte \\string\\filbreak\\space als Alternative",
+ ["en"]="use \\string\\filbreak\\space as alternative",
+ ["fr"]="utilisez \\string\\filbreak\\space en tant qu'alternative",
+ ["it"]="in alternativa, usare \\string\\filbreak",
+ ["nl"]="gebruik eventueel \\string\\filbreak",
+ ["no"]="bruk \\string\\filbreak\\space som et alternativ",
+ ["ro"]="folositi \\string\\filbreak\\space ca alternativa",
+ },
+ ["3"]={
+ ["cs"]="problem, vypina se vyvazovani",
+ ["de"]="Problem, verwende [ausgleich=nein]",
+ ["en"]="problems, disable balancing",
+ ["fr"]="problèmes, désactive l'équilibrage",
+ ["it"]="problemi, disabilitare il bilanciamento",
+ ["nl"]="probleempje, probeer [balanceren=nee]",
+ ["no"]="problemer, slår av balansering",
+ ["ro"]="probleme, se dezactiveaza alinierea",
+ },
+ ["4"]={
+ ["cs"]="horni plovouci objekt jeste neni podporovan",
+ ["de"]="Gleitobjekt oben ncoh nicht unterstuetzt",
+ ["en"]="top float not yet supported",
+ ["fr"]="flottant en partie supérieure pas encore supporté",
+ ["it"]="float in cima non ancora supportato",
+ ["nl"]="plaatsblok boven nog niet mogelijk",
+ ["no"]="flytblokker øverst er ikke støttet enda",
+ ["ro"]="cadrele top (top float) nu sunt inca suportate",
+ },
+ ["5"]={
+ ["cs"]="spodni plovouci objekt jeste neni podporovan",
+ ["de"]="Gleitobjekt unten ncoh nicht unterstuetzt",
+ ["en"]="bottom float not yet supported",
+ ["fr"]="flottant en partie inférieure pas encore supporté",
+ ["it"]="float in fondo non ancora supportato",
+ ["nl"]="plaatsblok onder nog niet mogelijk",
+ ["no"]="flytblokker nedert er ikke støttet enda",
+ ["ro"]="cadrele bottom (bottom float) nu sunt inca suportate",
+ },
+ ["6"]={
+ ["cs"]="-- plovouci objekt(y) odlozeny",
+ ["de"]="-- Gleitobjekt(e) verschoben",
+ ["en"]="-- float(s) postponed",
+ ["fr"]="-- flottant(s) reporté(s)",
+ ["it"]="-- float(s) posticipate",
+ ["nl"]="-- plaatsblok(en) opgeschort",
+ ["no"]="-- flytblokk forskjøvet",
+ ["ro"]="-- blocurile sunt amanate",
+ },
+ ["7"]={
+ ["cs"]="vyvazovani ukonceno po 100 krocich",
+ ["de"]="ausgleich nach 100 Schritten abgebrocheb",
+ ["en"]="balancing aborted after 100 steps",
+ ["fr"]="équilibrage abandonné après 100 pas",
+ ["it"]="bilanciamento annullato dopo 100 passi",
+ ["nl"]="balanceren afgebroken na 100 stappen",
+ ["no"]="balansering avbrutt etter 100 iterasjoner",
+ ["ro"]="alinierea este oprita dupa 100 de incercari",
+ },
+ ["8"]={
+ ["cs"]="vyvazeno v -- krocich",
+ ["de"]="ausgeglichen nach -- Schritt(en)",
+ ["en"]="balanced in -- step(s)",
+ ["fr"]="équilibré en -- pas",
+ ["it"]="bilanciamento in -- passo/i",
+ ["nl"]="gebalanceerd in -- stap(pen)",
+ ["no"]="balansert etter -- iterasjoner",
+ ["ro"]="aliniat in -- pas(i)",
+ },
+ ["9"]={
+ ["cs"]="kontrola nerovnost",
+ ["de"]="Ausrichtung ueberpruefen",
+ ["en"]="check raggedness",
+ ["fr"]="vérification des irrégularités",
+ ["it"]="controllare seghettamento",
+ ["nl"]="uitlijnen controleren!",
+ ["no"]="kontroller tekstlayout!",
+ ["ro"]="verificat alinierea",
+ },
+ ["files"]={ "page-ini.tex" },
+ ["title"]={
+ ["cs"]="sloupce",
+ ["de"]="Spalten",
+ ["en"]="columns",
+ ["fr"]="colonnes",
+ ["it"]="colonne",
+ ["nl"]="kolommen",
+ ["no"]="kolonner",
+ ["ro"]="coloane",
+ },
+ },
+ ["databases"]={
+ ["1"]={
+ ["cs"]="--",
+ ["de"]="--",
+ ["en"]="--",
+ ["fr"]="--",
+ ["it"]="--",
+ ["nl"]="--",
+ ["no"]="--",
+ ["ro"]="--",
+ },
+ ["2"]={
+ ["cs"]="local file --",
+ ["de"]="lokale Datei --",
+ ["en"]="local file --",
+ ["fr"]="fichier local --",
+ ["it"]="file locale --",
+ ["nl"]="lokaal bestand --",
+ ["no"]="lokal fil --",
+ ["ro"]="fisier local --",
+ },
+ ["3"]={
+ ["cs"]="global file --",
+ ["de"]="globale Datei --",
+ ["en"]="global file --",
+ ["fr"]="fichier global --",
+ ["it"]="file globale --",
+ ["nl"]="globaal bestand --",
+ ["no"]="global fil --",
+ ["ro"]="fisier global --",
+ },
+ ["4"]={
+ ["cs"]="unknown file --",
+ ["de"]="unbekannte Datei --",
+ ["en"]="unknown file --",
+ ["fr"]="fichier inconnu --",
+ ["it"]="file sconosciuto --",
+ ["nl"]="onbekend bestand --",
+ ["no"]="ukjent fil --",
+ ["ro"]="fisier necunoscut --",
+ },
+ ["files"]={ "core-dat.tex" },
+ ["title"]={
+ ["cs"]="databases",
+ ["de"]="Datenbank",
+ ["en"]="databases",
+ ["fr"]="bases de données",
+ ["it"]="database",
+ ["nl"]="database",
+ ["no"]="databaser",
+ ["ro"]="baze de date",
+ },
+ },
+ ["documents"]={
+ ["1"]={
+ ["de"]="Blatt --",
+ ["en"]="sheet --",
+ ["nl"]="sheet --",
+ },
+ ["2"]={
+ ["de"]="Nummer --",
+ ["en"]="number --",
+ ["nl"]="nummer --",
+ },
+ ["files"]={ "docs-bri.tex", "docs-she.tex" },
+ ["title"]={
+ ["de"]="Blaetter",
+ ["en"]="sheets",
+ ["nl"]="sheets",
+ },
+ },
+ ["encodings"]={
+ ["1"]={
+ ["cs"]="kodovani --",
+ ["de"]="Kodierung --",
+ ["en"]="coding --",
+ ["fr"]="encodage --",
+ ["it"]="codifica --",
+ ["nl"]="codering --",
+ ["no"]="koding --",
+ ["ro"]="codificarea --",
+ },
+ ["2"]={
+ ["cs"]="je nacteno kodovani --",
+ ["de"]="Kodierung -- ist geladen",
+ ["en"]="coding -- is loaded",
+ ["fr"]="l'encodage -- est chargé",
+ ["it"]="codifica -- caricata",
+ ["nl"]="codering -- wordt geladen",
+ ["no"]="koding -- er lest inn",
+ ["ro"]="codificarea -- este Encarcata",
+ },
+ ["3"]={
+ ["cs"]="nezname kodovani --",
+ ["de"]="Unbekannte Kodierung --",
+ ["en"]="unknown coding --",
+ ["fr"]="encodage -- inconnu",
+ ["it"]="codifica sconosciuta --",
+ ["nl"]="onbekende codering --",
+ ["no"]="ukjent koding --",
+ ["ro"]="codificarea -- este necunoscuta",
+ },
+ ["files"]={ "enco-ini.mkii" },
+ ["title"]={
+ ["cs"]="kodovani",
+ ["de"]="Kodierung",
+ ["en"]="encoding",
+ ["fr"]="encodage",
+ ["it"]="codifica",
+ ["nl"]="encoding",
+ ["no"]="koding",
+ ["ro"]="codificari",
+ },
+ },
+ ["figures"]={
+ ["1"]={
+ ["cs"]="obraz -- nelze nalezt",
+ ["de"]="Abbildung -- kann nicht gefunden werden",
+ ["en"]="figure -- can not be found",
+ ["fr"]="la figure -- ne peut être trouvée",
+ ["it"]="figura -- non trovata",
+ ["nl"]="figuur -- is niet te vinden",
+ ["ro"]="figura -- nu poate fi gasita",
+ },
+ ["2"]={
+ ["cs"]="obraz -- nepritomen",
+ ["de"]="Abbildung -- wird nicht erstellt",
+ ["en"]="figure -- is not preset",
+ ["fr"]="la figure -- n'est pas pré-sélectionnée",
+ ["it"]="la figura -- non è preimpostata",
+ ["nl"]="figuur -- wordt niet preset",
+ ["ro"]="figura -- nu este presetata",
+ },
+ ["3"]={
+ ["cs"]="dimensions of -- are determined externally",
+ ["de"]="dimensions of -- are determined externally",
+ ["en"]="dimensions of -- are determined externally",
+ ["fr"]="dimensions of -- are determined externally",
+ ["it"]="dimensions of -- are determined externally",
+ ["nl"]="maten van -- worden extern vastgesteld",
+ ["ro"]="dimensions of -- are determined externally",
+ },
+ ["4"]={
+ ["cs"]="dimenze obrazu -- nacteny primo z jeho souboru",
+ ["de"]="Dimensionen von -- geladen aus der Abbildungsdatei selbst",
+ ["en"]="dimensions of -- loaded from figurefile itself",
+ ["fr"]="les dimensions de -- chargées implicitement à partir du fichier de figure",
+ ["it"]="dimensioni di -- caricate dal file di immagini stesso",
+ ["nl"]="maten van -- geladen uit figuurfile zelf",
+ ["ro"]="dimensiunea figurii -- se incarca din fisierul insusi",
+ },
+ ["5"]={
+ ["cs"]="dimensions of -- are unknown",
+ ["de"]="Dimensions of -- are unknown",
+ ["en"]="dimensions of -- are unknown",
+ ["fr"]="dimensions of -- are unknown",
+ ["it"]="dimensions of -- are unknown",
+ ["nl"]="maten van -- zijn onbekend",
+ ["ro"]="dimensions of -- are unknown",
+ },
+ ["6"]={
+ ["cs"]="dimenze obrazu -- spocteny programem rlxtools",
+ ["de"]="Dimensionen von -- ausgerechnet durch rlxtools",
+ ["en"]="dimensions of -- calculated by rlxtools",
+ ["fr"]="les dimensions de -- calculées par rlxtools",
+ ["it"]="dimensioni di -- calcolate da rlxtools",
+ ["nl"]="maten van -- berekend door rlxtools",
+ ["ro"]="dimensiunea figurii -- este calculata de rlxtools",
+ },
+ ["8"]={
+ ["cs"]="obrazovy objekt -- je znovu pouzit",
+ ["de"]="Abbildungobjekt -- wurde wiederverwandt",
+ ["en"]="figureobject -- is reused",
+ ["fr"]="figureobject -- est réutilisé",
+ ["it"]="oggetto-figura -- riutilizzato",
+ ["nl"]="figuurobject -- wordt opnieuw gebruikt",
+ ["ro"]="obiectul figura -- este refolosit",
+ },
+ ["files"]={ "core-inc.mkii" },
+ ["title"]={
+ ["cs"]="obrazy",
+ ["de"]="Abbildungen",
+ ["en"]="figures",
+ ["fr"]="figures",
+ ["it"]="figure",
+ ["nl"]="figuren",
+ ["ro"]="figuri",
+ },
+ },
+ ["files"]={
+ ["1"]={
+ ["cs"]="synonymum souboru -- je jiz pouzito pro --",
+ ["de"]="Dateisynonym -- wird bereits fuer -- benutzt",
+ ["en"]="file synonym -- is already used for --",
+ ["fr"]="le synonyme de fichier -- est déjà utilisé pour --",
+ ["it"]="sinonimo file -- già in uso per --",
+ ["nl"]="file synoniem -- is al in gebruik voor --",
+ ["no"]="filesynonym -- er allerede brukt for --",
+ ["ro"]="sinonimul fisierelor -- este folosit deja pentru --",
+ },
+ ["files"]={ "core-fil.tex" },
+ ["title"]={
+ ["cs"]="soubory",
+ ["de"]="files",
+ ["en"]="files",
+ ["fr"]="fichiers",
+ ["it"]="file",
+ ["nl"]="files",
+ ["no"]="filer",
+ ["ro"]="fisiere",
+ },
+ },
+ ["filters"]={
+ ["1"]={
+ ["cs"]="filter -- is loaded",
+ ["de"]="filter -- ist geladen",
+ ["en"]="filter -- is loaded",
+ ["fr"]="le filtre -- est chargé",
+ ["it"]="filtro -- caricato",
+ ["nl"]="filter -- wordt geladen",
+ },
+ ["2"]={
+ ["cs"]="unknown filter --",
+ ["de"]="unknown filter --",
+ ["en"]="unknown filter --",
+ ["fr"]="filtre -- inconnu",
+ ["it"]="filtro sconosciuto --",
+ ["nl"]="onbekend filter --",
+ },
+ ["files"]={ "filt-ini.tex" },
+ ["title"]={
+ ["cs"]="filter",
+ ["de"]="filter",
+ ["en"]="filter",
+ ["fr"]="filtre",
+ ["it"]="filtri",
+ ["nl"]="filter",
+ },
+ },
+ ["floatblocks"]={
+ ["1"]={
+ ["cs"]="-- precislovano / -- => --",
+ ["de"]="-- neu nummeriert / -- => --",
+ ["en"]="-- renumbered / -- => --",
+ ["fr"]="-- renuméroté / -- => --",
+ ["it"]="-- rinumerato / -- => --",
+ ["nl"]="-- hernummerd / -- => --",
+ ["no"]="-- renummerert / -- => --",
+ ["ro"]="-- renumerotat / -- => --",
+ },
+ ["10"]={
+ ["cs"]="-- omezeno",
+ ["de"]="-- begrenzt",
+ ["en"]="-- limited",
+ ["fr"]="-- limité",
+ ["it"]="-- limitato",
+ ["nl"]="-- begrensd",
+ ["no"]="-- begrenset",
+ ["ro"]="-- limitat",
+ },
+ ["11"]={
+ ["cs"]="nedan zadny blok",
+ ["de"]="kein Block gegeben",
+ ["en"]="no block given",
+ ["fr"]="pas de bloc donné",
+ ["it"]="nessun oggetto specificato",
+ ["nl"]="geen blok opgegeven",
+ ["no"]="ingen blokk oppgitt",
+ ["ro"]="nu este dat nici un bloc",
+ },
+ ["12"]={
+ ["cs"]="nedefinovano",
+ ["de"]="undefiniert",
+ ["en"]="undefined",
+ ["fr"]="indéfini",
+ ["it"]="non definito",
+ ["nl"]="niet gedefinieerd",
+ ["no"]="udefinert",
+ ["ro"]="nedefinit",
+ },
+ ["13"]={
+ ["cs"]="there is nothing to split",
+ ["de"]="there is nothing to split",
+ ["en"]="there is nothing to split",
+ ["fr"]="there is nothing to split",
+ ["it"]="there is nothing to split",
+ ["nl"]="er is niets te splitsen",
+ ["no"]="there is nothing to split",
+ ["ro"]="there is nothing to split",
+ },
+ ["2"]={
+ ["cs"]="-- ulozeno",
+ ["de"]="-- gespeichert",
+ ["en"]="-- saved",
+ ["fr"]="-- sauvegardé",
+ ["it"]="-- salvato",
+ ["nl"]="-- bewaard",
+ ["no"]="-- lagret",
+ ["ro"]="-- salvat",
+ },
+ ["3"]={
+ ["cs"]="-- presunuto",
+ ["de"]="-- verschoben",
+ ["en"]="-- moved",
+ ["fr"]="-- déplacé",
+ ["it"]="-- mosso",
+ ["nl"]="-- verplaatst",
+ ["no"]="-- flyttet",
+ ["ro"]="-- mutat",
+ },
+ ["4"]={
+ ["cs"]="-- umisteno",
+ ["de"]="-- plaziert",
+ ["en"]="-- placed",
+ ["fr"]="-- placé",
+ ["it"]="-- sistemato",
+ ["nl"]="-- geplaatst",
+ ["no"]="-- plassert",
+ ["ro"]="-- plasat",
+ },
+ ["5"]={
+ ["cs"]="poradi prizpusobeno",
+ ["de"]="Reihenfolge angepasst",
+ ["en"]="order adapted",
+ ["fr"]="ordre adapté",
+ ["it"]="ordine aggiustato",
+ ["nl"]="volgorde aangepast",
+ ["no"]="rekkefølge tilpasset",
+ ["ro"]="ordinea adaptata",
+ },
+ ["6"]={
+ ["cs"]="pocet hornich plovoucich objektu je omezen na --",
+ ["de"]="Anz. der oberen Gleitobjekte beschraengt auf --",
+ ["en"]="n of top floats limited to --",
+ ["fr"]="n flottants de haut de page limité à --",
+ ["it"]="n di top floats limitato a --",
+ ["nl"]="maximaal -- boven",
+ ["no"]="maksimalt -- flytblokker øverst",
+ ["ro"]="nr. cadrelor de sus limitat la --",
+ },
+ ["7"]={
+ ["cs"]="pocet spodnich plovoucich objektu je omezen na --",
+ ["de"]="Anz. der unteren Gleitobjekte beschraengt auf --",
+ ["en"]="n of bottom floats limited to --",
+ ["fr"]="n flottants de bas de page limité à --",
+ ["it"]="n di bottom floats limitato a --",
+ ["nl"]="maximaal -- onder",
+ ["no"]="maksimalt -- flytblokker nederst",
+ ["ro"]="nr. blocurilor de jos limitat la --",
+ },
+ ["8"]={
+ ["cs"]="radku je mene nez --",
+ ["de"]="weniger als -- zeilen",
+ ["en"]="less than -- lines",
+ ["fr"]="moins de -- lignes",
+ ["it"]="meno di -- righe",
+ ["nl"]="minder dan -- regels",
+ ["no"]="mindre enn -- linjer",
+ ["ro"]="mai putin de -- linii",
+ },
+ ["9"]={
+ ["cs"]="poradi naruseno",
+ ["de"]="Reigenfolge gestoert",
+ ["en"]="order disturbed",
+ ["fr"]="ordre perturbé",
+ ["it"]="ordine disturbato",
+ ["nl"]="volgorde verstoord",
+ ["no"]="rekkefølge endret",
+ ["ro"]="ordinea deranjata",
+ },
+ ["files"]={ "page-flt.tex", "strc-flt.tex" },
+ ["title"]={
+ ["cs"]="plovouciobjekty",
+ ["de"]="Gleitobjektbloecke",
+ ["en"]="floatblocks",
+ ["fr"]="blocs de flottants",
+ ["it"]="oggetti mobili",
+ ["nl"]="plaatsblokken",
+ ["no"]="flytblokker",
+ ["ro"]="Blocuri",
+ },
+ },
+ ["fonts"]={
+ ["1"]={
+ ["cs"]="kodovani --",
+ ["de"]="Kodierung --",
+ ["en"]="coding --",
+ ["fr"]="encodage --",
+ ["it"]="codifica --",
+ ["nl"]="codering --",
+ ["no"]="koding --",
+ ["ro"]="codificarea --",
+ },
+ ["10"]={
+ ["cs"]="neznamy font --",
+ ["de"]="unbekanntes Font --",
+ ["en"]="unknown font file --",
+ ["fr"]="fichier de police -- inconnu",
+ ["it"]="file di font sconosciuto --",
+ ["nl"]="onbekende font file --",
+ ["no"]="ukjent fontfil --",
+ ["ro"]="fisier font necunoscut --",
+ },
+ ["14"]={
+ ["cs"]="bodyfont -- is defined (can better be done global)",
+ ["de"]="Fliesstext -- wurde definiert (besser waere globale Definition)",
+ ["en"]="bodyfont -- is defined (can better be done global)",
+ ["fr"]="policecorps -- est défini (une définition globale pourrait être plus adéquat)",
+ ["it"]="corpo del testo -- definito (sarebbe meglio globale)",
+ ["nl"]="korps -- is gedefinieerd (kan beter globaal plaatsvinden)",
+ ["no"]="bodyfont -- is defined (can better be done global)",
+ ["ro"]="bodyfont -- is defined (can better be done global)",
+ },
+ ["2"]={
+ ["cs"]="varianta -- je nactena",
+ ["de"]="Variante -- ist geladen",
+ ["en"]="variant -- is loaded",
+ ["fr"]="la variante -- est chargée",
+ ["it"]="variante -- caricata",
+ ["nl"]="variant -- wordt geladen",
+ ["no"]="variant -- er lest inn",
+ ["ro"]="varianta -- este incarcata",
+ },
+ ["3"]={
+ ["cs"]="neznama varianta --",
+ ["de"]="Unbekannte Variante --",
+ ["en"]="unknown variant --",
+ ["fr"]="variante -- inconnue",
+ ["it"]="variante sconosciuta --",
+ ["nl"]="onbekende variant --",
+ ["no"]="ukjent variant --",
+ ["ro"]="varianta necunoscuta --",
+ },
+ ["4"]={
+ ["cs"]="zakladni font -- neni definovan",
+ ["de"]="Fliesstext -- ist nicht definiert",
+ ["en"]="bodyfont -- is not defined",
+ ["fr"]="policecorps -- n'est pas définie",
+ ["it"]="corpo del testo -- non definito",
+ ["nl"]="korps -- is niet gedefinieerd",
+ ["no"]="hovedfont -- er ikke definert",
+ ["ro"]="corpul de litere -- nu este definit",
+ },
+ ["5"]={
+ ["cs"]="styl -- neni definovan",
+ ["de"]="Stil -- ist nicht definiert",
+ ["en"]="style -- is not defined",
+ ["fr"]="le style -- n'est pas défini",
+ ["it"]="stile -- non definito",
+ ["nl"]="stijl -- is niet gedefinieerd",
+ ["no"]="stil -- er ikke definert",
+ ["ro"]="stilul -- nu este definit",
+ },
+ ["6"]={
+ ["cs"]="-- je nacten",
+ ["de"]="-- ist geladen",
+ ["en"]="-- is loaded",
+ ["fr"]="-- est chargé",
+ ["it"]="-- caricato",
+ ["nl"]="-- wordt geladen",
+ ["no"]="-- er lest inn",
+ ["ro"]="-- este incarcat",
+ },
+ ["7"]={
+ ["cs"]="neznamy format --",
+ ["de"]="unbekanntes Format --",
+ ["en"]="unknown format --",
+ ["fr"]="format -- inconnu",
+ ["it"]="formato sconosciuto --",
+ ["nl"]="onbekend formaat --",
+ ["no"]="ukjent format --",
+ ["ro"]="format necunoscut --",
+ },
+ ["8"]={
+ ["cs"]="styl -- definovan",
+ ["de"]="Stil -- definiert",
+ ["en"]="style -- defined",
+ ["fr"]="style -- défini",
+ ["it"]="stile -- definito",
+ ["nl"]="stijl -- gedefinieerd",
+ ["no"]="stil -- definert",
+ ["ro"]="stilul -- definit",
+ },
+ ["files"]={ "font-ini.mkii", "font-ini.mkiv" },
+ ["title"]={
+ ["cs"]="zakladnifont",
+ ["de"]="Fliesstext",
+ ["en"]="bodyfont",
+ ["fr"]="corps de texte",
+ ["it"]="font del corpo",
+ ["nl"]="korps",
+ ["no"]="hovedfont",
+ ["ro"]="corp de litere",
+ },
+ },
+ ["handlings"]={
+ ["1"]={
+ ["cs"]="font handling --",
+ ["de"]="Font Verarbeitung --",
+ ["en"]="font handling --",
+ ["fr"]="manipulation -- de police",
+ ["it"]="font handling --",
+ ["nl"]="font afhandeling --",
+ ["no"]="font handling --",
+ ["ro"]="font handling --",
+ },
+ ["2"]={
+ ["cs"]="font handling -- is loaded",
+ ["de"]="Font Verarbeitung -- ist geladen",
+ ["en"]="font handling -- is loaded",
+ ["fr"]="la manipulation -- de police est chargée",
+ ["it"]="font handling -- is loaded",
+ ["nl"]="font afhandeling -- wordt geladen",
+ ["no"]="font handling -- is loaded",
+ ["ro"]="font handling -- is loaded",
+ },
+ ["3"]={
+ ["cs"]="unknown font handling --",
+ ["de"]="unknown font handling --",
+ ["en"]="unknown font handling --",
+ ["fr"]="manipulation -- inconnue de police",
+ ["it"]="unknown font handling --",
+ ["nl"]="onbekende font afhandeling --",
+ ["no"]="unknown font handling --",
+ ["ro"]="unknown font handling --",
+ },
+ ["files"]={ "hand-ini.mkii" },
+ ["title"]={
+ ["cs"]="handling",
+ ["de"]="handling",
+ ["en"]="handling",
+ ["fr"]="manipulation",
+ ["it"]="handling",
+ ["nl"]="handling",
+ ["no"]="handling",
+ ["ro"]="handling",
+ },
+ },
+ ["interactions"]={
+ ["1"]={
+ ["cs"]="pomer -- x -- (s x v)",
+ ["de"]="Seitenverhaeltnis -- x -- (B x H)",
+ ["en"]="aspect ratio -- x -- (b x h)",
+ ["fr"]="ratio d'aspect -- x -- (b x h)",
+ ["it"]="rapporto -- x -- (b x a)",
+ ["nl"]="aspect ratio -- x -- (b x h)",
+ ["no"]="forholdstall -- x -- (b x h)",
+ ["ro"]="aspectul -- x -- (b x h)",
+ },
+ ["2"]={
+ ["cs"]="aktivni",
+ ["de"]="aktiv",
+ ["en"]="active",
+ ["fr"]="actif",
+ ["it"]="attiva",
+ ["nl"]="actief",
+ ["no"]="aktiv",
+ ["ro"]="activ",
+ },
+ ["21"]={
+ ["cs"]="-- kod vlozen",
+ ["de"]="-- Code eingefuegt",
+ ["en"]="-- code inserted",
+ ["fr"]="-- code inseré",
+ ["it"]="codice -- inserito",
+ ["nl"]="-- code tussengevoegd",
+ ["no"]="-- kode satt inn / tilføyd",
+ ["ro"]="-- cod inserat",
+ },
+ ["3"]={
+ ["cs"]="neaktivni",
+ ["de"]="inaktiv",
+ ["en"]="inactive",
+ ["fr"]="inactif",
+ ["it"]="inattiva",
+ ["nl"]="niet actief",
+ ["no"]="inaktiv",
+ ["ro"]="inactiv",
+ },
+ ["4"]={
+ ["cs"]="zadna strankova synchronizace (--) v hmode",
+ ["de"]="keine Seitensynchronisation (--) im hmode",
+ ["en"]="no pagesynchronisation (--) in hmode",
+ ["fr"]="pas de synchronisation de page (--) dans le hmode",
+ ["it"]="sincronizzazione di pagina (--) non disponibile in hmode",
+ ["nl"]="geen paginasynchronisatie (--) in hmode",
+ ["no"]="ingen sidesynkronisering (--) i hmode",
+ ["ro"]="nu exista sincronizare pt. pagini (--) in hmode",
+ },
+ ["5"]={
+ ["cs"]="unknown attachment --",
+ ["de"]="unknown attachment --",
+ ["en"]="unknown attachment --",
+ ["fr"]="le fichier joint -- est inconnu",
+ ["it"]="unknown attachment --",
+ ["nl"]="onbekend attachment --",
+ ["no"]="unknown attachment --",
+ ["ro"]="unknown attachment --",
+ },
+ ["6"]={
+ ["cs"]="attachment file -- does not exist",
+ ["de"]="attachment file -- does not exist",
+ ["en"]="attachment file -- does not exist",
+ ["fr"]="le fichier joint -- n'existe pas",
+ ["it"]="attachment file -- does not exist",
+ ["nl"]="attachment file -- bestaat niet",
+ ["no"]="attachment file -- does not exist",
+ ["ro"]="attachment file -- does not exist",
+ },
+ ["files"]={ "core-int.tex", "spec-ini.tex" },
+ ["title"]={
+ ["cs"]="interakce",
+ ["de"]="Interaktion",
+ ["en"]="interaction",
+ ["fr"]="interaction",
+ ["it"]="interazione",
+ ["nl"]="interactie",
+ ["no"]="interaksjon",
+ ["ro"]="interactiuni",
+ },
+ },
+ ["javascript"]={
+ ["1"]={
+ ["cs"]="nacita se soubor skriptu --",
+ ["de"]="Lade Scriptdatei --",
+ ["en"]="loading script set --",
+ ["fr"]="chargement du jeu de script --",
+ ["it"]="caricamento dello script set --",
+ ["nl"]="script set -- wordt geladen",
+ ["no"]="leser inn scriptsett --",
+ ["ro"]="se incarca scriptul --",
+ },
+ ["2"]={
+ ["cs"]="neznama preambule --",
+ ["de"]="unbekannte Preamble --",
+ ["en"]="unknown preamble --",
+ ["fr"]="préambule -- inconnu",
+ ["it"]="preambolo sconosciuto --",
+ ["nl"]="onbekende preamble --",
+ ["no"]="ukjent 'preamble' --",
+ ["ro"]="preambul necunoscut --",
+ },
+ ["files"]={ "java-ini.tex" },
+ ["title"]={
+ ["cs"]="javascript",
+ ["de"]="javascript",
+ ["en"]="javascript",
+ ["fr"]="javascript",
+ ["it"]="javascript",
+ ["nl"]="javascript",
+ ["no"]="javascript",
+ ["ro"]="javascript",
+ },
+ },
+ ["layouts"]={
+ ["1"]={
+ ["cs"]="vyska textu prizpusobena s -- na strane --",
+ ["de"]="Texthoehe angepasst mit -- auf Seite --",
+ ["en"]="textheight adapted with -- at page --",
+ ["fr"]="hauteurtexte adaptée avec -- à la page --",
+ ["it"]="altezza del testo adattata con -- a pagina --",
+ ["nl"]="teksthoogte aangepast met -- op pagina --",
+ ["no"]="teksthøyde tilpasset med -- på side --",
+ ["ro"]="textheight adaptat cu -- la pagina --",
+ },
+ ["10"]={
+ ["cs"]="-- a -- nedava dohromady 1.0",
+ ["de"]="-- und -- ergeben zusammen nicht 1.0",
+ ["en"]="-- and -- don't add up to 1.0",
+ ["fr"]="-- et -- ne sont pas ajoutés à 1.0",
+ ["it"]="-- e -- non sommano a 1.0",
+ ["nl"]="-- en -- tellen niet op tot 1.0",
+ ["no"]="-- og -- er ikke 1.0 til sammen",
+ ["ro"]="-- si -- nu se adauga pana la 1.0",
+ },
+ ["11"]={
+ ["cs"]="svisla mezera -- neni povolena v pevnem radkovem rejstriku",
+ ["de"]="Zwischenraum -- nicht im Grittermoduserlau",
+ ["en"]="spacing -- not permitted in gridmode",
+ ["fr"]="espacement -- non permis en modegrille",
+ ["it"]="spaziatura -- non permessa in modo griglia",
+ ["nl"]="interlinie -- niet toegestaan in gridmode",
+ ["no"]="mellomrom -- ikke tillatt i gridmodus",
+ ["ro"]="spatierea -- nu este permisa in gridmode",
+ },
+ ["2"]={
+ ["cs"]="-- krat odlozeny text umisten",
+ ["de"]="-- mal verschobener Text plaziert",
+ ["en"]="-- times postponed text placed",
+ ["fr"]="-- times postponed text placed",
+ ["it"]="posizionato testo posticipato -- volte",
+ ["nl"]="-- maal uitgestelde tekst tussengevoegd",
+ ["no"]="-- ganger forskjøvet tekst plassert",
+ ["ro"]="textul amanat de -- ori a fost plasat",
+ },
+ ["3"]={
+ ["cs"]="-- krat text odlozen",
+ ["de"]="-- mal Text verschoben",
+ ["en"]="-- times text postponed",
+ ["fr"]="-- times text postponed",
+ ["it"]="testo posticipato -- volte",
+ ["nl"]="-- maal tekst plaatsen uitstellen",
+ ["no"]="-- ganger tekst forskjøvet",
+ ["ro"]="textul amanat de -- ori",
+ },
+ ["4"]={
+ ["cs"]="okrajove bloky aktivni",
+ ["de"]="marginalbloecke aktiv",
+ ["en"]="marginblocks active",
+ ["fr"]="blocsmarge actifs",
+ ["it"]="blocchi in margine attivi",
+ ["nl"]="margeblokken actief",
+ ["no"]="margblokker aktive",
+ ["ro"]="blocuri marginale active",
+ },
+ ["5"]={
+ ["cs"]="okrajove bloky neaktivni",
+ ["de"]="marginalbloecke inaktiv",
+ ["en"]="marginblocks inactive",
+ ["fr"]="blocsmarge inactifs",
+ ["it"]="blocchi in margine inattivi",
+ ["nl"]="margeblokken inactief",
+ ["no"]="margblokker inaktive",
+ ["ro"]="blocuri marginale inactive",
+ },
+ ["6"]={
+ ["cs"]="sada stran -- zpracovana (velikost --)",
+ ["de"]="Unterseitenfolge -- verarbeitet (Groesse --)",
+ ["en"]="subpage set -- processed (size --)",
+ ["fr"]="jeu de souspage -- traité (taille --)",
+ ["it"]="gruppo di sottopagine -- elaborato (dimensione --)",
+ ["nl"]="subpagina reeks -- verwerkt (aantal --)",
+ ["no"]="delside sett -- behandlet (størrelse --)",
+ ["ro"]="setul -- de subpagini procesat (dimensiunea --)",
+ },
+ ["7"]={
+ ["cs"]="pocita se misto pro logo",
+ ["de"]="berechne Platzbedarf des Logos",
+ ["en"]="calculating logospace",
+ ["fr"]="calcul de l'espace pour le logo",
+ ["it"]="calcolo dello spazio per logo",
+ ["nl"]="beeldmerken berekenen",
+ ["no"]="beregner plass for logo",
+ ["ro"]="se calculeaza spatiul pentru logo",
+ },
+ ["8"]={
+ ["cs"]="pocita se pozadi",
+ ["de"]="berechne Hintergrund",
+ ["en"]="calculating backgrounds",
+ ["fr"]="calcul des arrières-plans",
+ ["it"]="calcolo dello sfondo",
+ ["nl"]="achtergronden berekenen",
+ ["no"]="beregner bakgrunn",
+ ["ro"]="se calculeaza fundalurile",
+ },
+ ["9"]={
+ ["cs"]="aktualne ne vice nez -- urovne/urovni vyctu",
+ ["de"]="z.Z. nicht mehr als -- Ebenen in Aufzaehlungen",
+ ["en"]="currently no more than -- levels in itemizations",
+ ["fr"]="pas plus de -- niveaux pour l'instant dans les élémentarisations",
+ ["it"]="attualmente non più di -- livelli di elencazione",
+ ["nl"]="momenteel maximaal -- niveaus in opsommingen",
+ ["no"]="for øyeblikket maksimalt -- nivåer i opplisting",
+ ["ro"]="acum nu se supota mai mult de -- nivele de adancime la iteratii",
+ },
+ ["files"]={ "core-itm.tex", "page-bck.mkii", "page-bck.mkiv", "page-ini.tex", "page-log.tex", "strc-itm.tex" },
+ ["title"]={
+ ["cs"]="layout",
+ ["de"]="Layout",
+ ["en"]="layout",
+ ["fr"]="calque",
+ ["it"]="layout",
+ ["nl"]="layout",
+ ["no"]="layout",
+ ["ro"]="aranjamente",
+ },
+ },
+ ["linguals"]={
+ ["1"]={
+ ["cs"]="vzory -- pro -- nacteny (n=--,e=--,m=--)",
+ ["de"]="Trennmuster -- fuer -- geladen (n=--,e=--,m=--)",
+ ["en"]="patterns -- for -- loaded (n=--,e=--,m=--)",
+ ["fr"]="les motifs -- pour -- sont chargés (n=--,e=--,m=--)",
+ ["it"]="schemi -- per -- caricati (n=--,e=--,m=--)",
+ ["nl"]="afbreekpatronen -- voor -- geladen (n=--,e=--,m=--)",
+ ["no"]="orddelingsmønster -- for -- er lest inn (n=--,e=--,m=--)",
+ ["ro"]="sablonul -- pentru -- s-a incarcat (n=--,e=--,m=--)",
+ },
+ ["10"]={
+ ["cs"]="vzory --nacteny",
+ ["de"]="Trennmuster --geladen",
+ ["en"]="patterns --loaded",
+ ["fr"]="motifs -- chargés",
+ ["it"]="schemi -- caricati",
+ ["nl"]="patronen --geladen",
+ ["no"]="orddelingsmønster -- er lest inn",
+ ["ro"]="sabloanele -- incarcate",
+ },
+ ["2"]={
+ ["cs"]="zadne vzory -- pro -- (n=--,e=--,m=--) (--,--)",
+ ["de"]="Keine Trennmuster -- fuer -- (n=--,e=--,m=--) (--,--)",
+ ["en"]="no patterns -- for -- (n=--,e=--,m=--) (--,--)",
+ ["fr"]="pas de motifs -- pour -- (n=--,e=--,m=--) (--,--)",
+ ["it"]="niente schemi -- per -- (n=--,e=--,m=--) (--,--)",
+ ["nl"]="geen afbreekpatronen -- voor -- (n=--,e=--,m=--) (--,--)",
+ ["no"]="ingen orddelingsmønster -- for -- (n=--,e=--,m=--) (--,--)",
+ ["ro"]="nu exista sabloane -- pentru -- (n=--,e=--,m=--) (--,--)",
+ },
+ ["3"]={
+ ["cs"]="deleni slov -- pro -- nacteno (n=--,e=--,m=--)",
+ ["de"]="Trenndefinitionen -- fuer -- geladen (n=--,e=--,m=--)",
+ ["en"]="hyphenations -- for -- loaded (n=--,e=--,m=--)",
+ ["fr"]="hyphenations -- pour -- chargés (n=--,e=--,m=--)",
+ ["it"]="sillabazione -- per -- caricata (n=--,e=--,m=--)",
+ ["nl"]="afbreekdefinities -- voor -- geladen (n=--,e=--,m=--)",
+ ["no"]="orddelingsdefinisjon -- for -- er lest inn (n=--,e=--,m=--)",
+ ["ro"]="despartirea in silabe -- pentru -- s-a incarcat (n=--,e=--,m=--)",
+ },
+ ["4"]={
+ ["cs"]="zadne deleni slov -- pro -- (n=--,e=--,m=--)",
+ ["de"]="Keine Trenndefinitionen -- fuer -- (n=--,e=--,m=--)",
+ ["en"]="no hyphenations -- for -- (n=--,e=--,m=--)",
+ ["fr"]="pas d'hyphenations -- pour -- (n=--,e=--,m=--)",
+ ["it"]="niente sillabazione -- per -- (n=--,e=--,m=--)",
+ ["nl"]="geen afbreekdefinities -- voor -- (n=--,e=--,m=--)",
+ ["no"]="ingen orddelingsdefinisjon -- for -- (n=--,e=--,m=--)",
+ ["ro"]="nu exista despartire in silabe -- pentru -- (n=--,e=--,m=--)",
+ },
+ ["5"]={
+ ["cs"]="vzory pro -- nenacteny",
+ ["de"]="Trennmuster fuer -- nicht geladen",
+ ["en"]="patterns for -- not loaded",
+ ["fr"]="les motifs pour -- ne sont pas chargés",
+ ["it"]="schemi per -- non caricati",
+ ["nl"]="afbreekpatronen voor -- niet geladen",
+ ["no"]="orddelingsmønster for -- er ikke lest inn",
+ ["ro"]="sabloanele pentru -- nu sunt incarcate",
+ },
+ ["6"]={
+ ["cs"]="jazyk -- neni definovan",
+ ["de"]="Sprache -- ist undefiniert",
+ ["en"]="language -- is undefined",
+ ["fr"]="langue -- non définie",
+ ["it"]="lingua -- non definita",
+ ["nl"]="taal -- is niet gedefinieerd",
+ ["no"]="spràk -- er udefinert",
+ ["ro"]="limba -- nu este definita",
+ },
+ ["7"]={
+ ["cs"]="specificke volby jazyka [--] zavadeji -- (zavlecenou) mezeru",
+ ["de"]="Sprachenspezifische Option [--] fuegt eine Luecke von -- ein",
+ ["en"]="language specific options [--] introduce a -- skip",
+ ["fr"]="les options spécifiques de langue [--] introduisent un -- saut",
+ ["it"]="opzioni specifiche per la lingua [--] introducono un salto --",
+ ["nl"]="taal specifieke opties [--] introduceren een skip van --",
+ ["no"]="spràk spesifikk opsjon [--] introduserer et -- hopp",
+ ["ro"]="optiunile specifice ale limbii [--] introduc un spatiu --",
+ },
+ ["8"]={
+ ["cs"]="specificke volby jazyka [--] bez mezer pripojeny",
+ ["de"]="Sprachenspezifische Option [--] nahtlos hinzugefuegt",
+ ["en"]="language specific options [--] seamless appended",
+ ["fr"]="les options spécifiques de langue [--] sont ajoutés en douceur",
+ ["it"]="opzioni specifiche per la lingua [--] aggiunte trasparentemente",
+ ["nl"]="taal specifieke opties [--] naadloos toegevoegd",
+ ["no"]="spràk spesifikk opsjon [--] problemfritt tilføyd",
+ ["ro"]="optiunile specifice ale limbii [--] adaugate",
+ },
+ ["9"]={
+ ["cs"]="language -- is active",
+ ["de"]="Sprache -- ist aktiv",
+ ["en"]="language -- is active",
+ ["fr"]="la langue -- est active",
+ ["it"]="lingua -- attiva",
+ ["nl"]="taal -- is actief",
+ ["no"]="spràk -- er aktivt",
+ ["ro"]="limba -- este activa",
+ },
+ ["files"]={ "lang-ini.mkii", "lang-ini.mkiv" },
+ ["title"]={
+ ["cs"]="jazyky",
+ ["de"]="Sprache",
+ ["en"]="language",
+ ["fr"]="langue",
+ ["it"]="lingua",
+ ["nl"]="taal",
+ ["no"]="sprøk",
+ ["ro"]="limbi",
+ },
+ },
+ ["metapost"]={
+ ["1"]={
+ ["cs"]="loading metapost library --",
+ ["de"]="Lade metapost Bibliothek --",
+ ["en"]="loading metapost library --",
+ ["fr"]="chargement de la bibliothèque metapost --",
+ ["it"]="caricamento della libreria metapost --",
+ ["nl"]="metapost bibliotheek -- wordt geladen",
+ ["no"]="metapost bibliotek -- blir lest inn",
+ ["ro"]="se incarca biblioteca metapost --",
+ },
+ ["files"]={ "meta-ini.mkii", "meta-ini.mkiv" },
+ ["title"]={
+ ["cs"]="metapost",
+ ["de"]="metapost",
+ ["en"]="metapost",
+ ["fr"]="metapost",
+ ["it"]="metapost",
+ ["nl"]="metapost",
+ ["no"]="metapost",
+ ["ro"]="metapost",
+ },
+ },
+ ["references"]={
+ ["1"]={
+ ["cs"]="neznama reference --",
+ ["de"]="unbekannte Referenz --",
+ ["en"]="unknown reference --",
+ ["fr"]="réference -- inconnue",
+ ["it"]="riferimento sconosciuto --",
+ ["nl"]="onbekende verwijzing --",
+ ["no"]="ukjent referanse --",
+ ["ro"]="referinta necunoscuta --",
+ },
+ ["2"]={
+ ["cs"]="duplicitni reference -- na strane --",
+ ["de"]="doppelte Referenz -- auf Seite --",
+ ["en"]="duplicate reference -- on page --",
+ ["fr"]="réference -- dupliquée à la page --",
+ ["it"]="riferimento duplicato -- a pagina --",
+ ["nl"]="dubbele verwijzing -- op pagina --",
+ ["no"]="duplikat referanse -- pø side --",
+ ["ro"]="referinta duplicat -- la pagina --",
+ },
+ ["21"]={
+ ["cs"]="dokument -- nacten",
+ ["de"]="Dokument -- geladen",
+ ["en"]="document -- loaded",
+ ["fr"]="document -- chargé",
+ ["it"]="documento -- caricato",
+ ["nl"]="document -- geladen",
+ ["no"]="dokument -- er lest inn",
+ ["ro"]="documentul -- este incarcat",
+ },
+ ["22"]={
+ ["cs"]="dokument -- neni interaktivni",
+ ["de"]="Dokument -- ist nicht aktiv",
+ ["en"]="document -- is not interactive",
+ ["fr"]="le document -- n'est pas interactif",
+ ["it"]="il documento -- non ø interattivo",
+ ["nl"]="document -- is niet interactief",
+ ["no"]="dokument -- er ikke interaktivt",
+ ["ro"]="documentul -- nu este interactiv",
+ },
+ ["23"]={
+ ["cs"]="obskurni (nejasna) reference -- (prefix=--)",
+ ["de"]="Obskure Referenz -- (Prefix=--)",
+ ["en"]="obscure reference -- (prefix=--)",
+ ["fr"]="reference -- indéterminé (préfixe=--)",
+ ["it"]="riferimento ambiguo -- (prefisso=--)",
+ ["nl"]="onduidelijke verwijzing -- (prefix=--)",
+ ["no"]="obskur referanse -- (Prefix=--)",
+ ["ro"]="referinta obscura -- (prefix=--)",
+ },
+ ["3"]={
+ ["cs"]="neznamy typ reference --",
+ ["de"]="unbekannte Referenz Typ --",
+ ["en"]="unknown reference type --",
+ ["fr"]="type -- de réference inconnu",
+ ["it"]="riferimento di tipo sconosciuto --",
+ ["nl"]="type verwijzing -- onbekend",
+ ["no"]="ukjent referansetype --",
+ ["ro"]="tip necunoscut de referinta --",
+ },
+ ["30"]={
+ ["cs"]="neznamy objekt --",
+ ["de"]="unbekanntes Object --",
+ ["en"]="unknown object --",
+ ["fr"]="objet -- inconnu",
+ ["it"]="oggetto sconosciuto --",
+ ["nl"]="onbekend object --",
+ ["no"]="ukjent objekt --",
+ ["ro"]="obiect necunoscut --",
+ },
+ ["31"]={
+ ["cs"]="duplicitni object --",
+ ["de"]="doppeltes Object --",
+ ["en"]="duplicate object --",
+ ["fr"]="objet -- dupliqué",
+ ["it"]="oggetto duplicato --",
+ ["nl"]="dubbel object --",
+ ["no"]="duplikat objekt --",
+ ["ro"]="obiect duplicat --",
+ },
+ ["4"]={
+ ["cs"]="nedovolena reference --",
+ ["de"]="illegale Referenz --",
+ ["en"]="illegal reference --",
+ ["fr"]="réference -- inconnue",
+ ["it"]="riferimento illecito --",
+ ["nl"]="verboden verwijzing --",
+ ["no"]="ulovlig referanse --",
+ ["ro"]="referinta eronata --",
+ },
+ ["files"]={ "core-obj.tex", "core-ref.tex", "strc-ref.tex" },
+ ["title"]={
+ ["cs"]="reference",
+ ["de"]="referenzen",
+ ["en"]="references",
+ ["fr"]="réferences",
+ ["it"]="riferimenti",
+ ["nl"]="verwijzingen",
+ ["no"]="referanser",
+ ["ro"]="referinte",
+ },
+ },
+ ["regimes"]={
+ ["1"]={
+ ["cs"]="kodovani --",
+ ["de"]="Kodierung --",
+ ["en"]="regime --",
+ ["fr"]="encodage --",
+ ["it"]="codifica --",
+ ["nl"]="regime --",
+ ["no"]="koding --",
+ ["ro"]="codificarea --",
+ },
+ ["2"]={
+ ["cs"]="je nacteno kodovani --",
+ ["de"]="Kodierung -- ist geladen",
+ ["en"]="regime -- is loaded",
+ ["fr"]="l'encodage -- est chargé",
+ ["it"]="codifica -- caricata",
+ ["nl"]="regime -- wordt geladen",
+ ["no"]="koding -- er lest inn",
+ ["ro"]="codificarea -- este Encarcata",
+ },
+ ["3"]={
+ ["cs"]="nezname kodovani --",
+ ["de"]="Unbekannte Kodierung --",
+ ["en"]="unknown regime --",
+ ["fr"]="encodage -- inconnu",
+ ["it"]="codifica sconosciuta --",
+ ["nl"]="onbekend regime --",
+ ["no"]="ukjent koding --",
+ ["ro"]="codificarea -- este necunoscuta",
+ },
+ ["files"]={ "regi-ini.mkii" },
+ ["title"]={
+ ["cs"]="kodovani",
+ ["de"]="Kodierung",
+ ["en"]="regime",
+ ["fr"]="encodage",
+ ["it"]="codifica",
+ ["nl"]="regime",
+ ["no"]="koding",
+ ["ro"]="codificari",
+ },
+ },
+ ["specials"]={
+ ["1"]={
+ ["cs"]="-- nacteno",
+ ["de"]="-- geladen",
+ ["en"]="-- loaded",
+ ["fr"]="-- chargé",
+ ["it"]="-- caricato",
+ ["nl"]="-- geladen",
+ ["no"]="-- er lest inn",
+ ["ro"]="-- incarcat",
+ },
+ ["2"]={
+ ["cs"]="neni dovoleno hlubsi zanoreni --",
+ ["de"]="keine tiefere Verschachtelung erlaubt --",
+ ["en"]="no deeper nesting is permitted --",
+ ["fr"]="pas d'imbracations plus profondes ne sont permises --",
+ ["it"]="non ø permesso un annidamento maggiore --",
+ ["nl"]="verdere nesting is niet toegestaan --",
+ ["no"]="dypere 'nesting' er ikke tillatt --",
+ ["ro"]="nu este permis un nivel de imbricare mai mare --",
+ },
+ ["3"]={
+ ["cs"]="-- je resetovano",
+ ["de"]="-- ist zurueckgesetzt",
+ ["en"]="-- is reset",
+ ["fr"]="-- est remis à zéro",
+ ["it"]="-- reimpostato",
+ ["nl"]="-- gereset",
+ ["no"]="-- er tilbakestilt",
+ ["ro"]="-- s-a resetat",
+ },
+ ["4"]={
+ ["cs"]="prikaz -- neexistuje",
+ ["de"]="Befehl -- existiert nicht",
+ ["en"]="command -- does not exist",
+ ["fr"]="la commande -- n'existe pas",
+ ["it"]="il comando -- non esiste",
+ ["nl"]="commando -- bestaat niet",
+ ["no"]="kommando -- eksisterer ikke",
+ ["ro"]="comanda -- nu exista",
+ },
+ ["5"]={
+ ["cs"]="nacita se definicni soubor --",
+ ["de"]="lade Definitionsdatei --",
+ ["en"]="loading definition file --",
+ ["fr"]="chargement du fichier de définition --",
+ ["it"]="caricamento del file di definizione --",
+ ["nl"]="definitiefile -- wordt geladen",
+ ["no"]="leser inn definisjonsfil for --",
+ ["ro"]="se incarca fisierul de definitii --",
+ },
+ ["6"]={
+ ["cs"]="zanoreni neni dovoleno",
+ ["de"]="Verschachtelung nicht erlaubt",
+ ["en"]="nesting is not permitted",
+ ["fr"]="l'imbrication n'est pas permise",
+ ["it"]="annidamento non permesso",
+ ["nl"]="nesting is niet toegestaan",
+ ["no"]="'nesting' er ikke tillatt",
+ ["ro"]="imbricarea nu este permisa",
+ },
+ ["7"]={
+ ["cs"]="neznamy ovladac (driver) --",
+ ["de"]="unbekante Driver --",
+ ["en"]="unknown driver --",
+ ["fr"]="pilote -- inconnu",
+ ["it"]="driver sconosciuto --",
+ ["nl"]="onbekende driver --",
+ ["no"]="ukjent driver --",
+ ["ro"]="driver necunoscut --",
+ },
+ ["files"]={ "spec-ini.tex" },
+ ["title"]={
+ ["cs"]="speciality",
+ ["de"]="spezielles",
+ ["en"]="specials",
+ ["fr"]="specials",
+ ["it"]="specialitø",
+ ["nl"]="specials",
+ ["no"]="specials",
+ ["ro"]="specials",
+ },
+ },
+ ["structures"]={
+ ["1"]={
+ ["cs"]="zacatek oddilu (sekce) --",
+ ["de"]="Begin des Abschnittsblocks --",
+ ["en"]="begin of sectionblock --",
+ ["fr"]="début de blocsection --",
+ ["it"]="inizio del blocco (sezione) --",
+ ["nl"]="begin van sectieblok --",
+ ["no"]="starten av blokk -- (seksjon)",
+ ["ro"]="inceput de bloc sectiune --",
+ },
+ ["2"]={
+ ["cs"]="konec oddilu (sekce) --",
+ ["de"]="Ende des Abschnittsblocks --",
+ ["en"]="end of sectionblock --",
+ ["fr"]="fin de blocsection --",
+ ["it"]="fine del blocco (sezione) --",
+ ["nl"]="eind van sectieblok --",
+ ["no"]="slutten av blokk -- (seksjon)",
+ ["ro"]="sfarsit de bloc sectiune --",
+ },
+ ["files"]={ "core-sec.mkii", "core-sec.mkiv", "strc-sbe.tex" },
+ ["title"]={
+ ["cs"]="struktury",
+ ["de"]="struktur",
+ ["en"]="structure",
+ ["fr"]="structure",
+ ["it"]="struttura",
+ ["nl"]="structuur",
+ ["no"]="struktur",
+ ["ro"]="structuri",
+ },
+ },
+ ["symbols"]={
+ ["1"]={
+ ["cs"]="nacita se soubor symbolu --",
+ ["de"]="Lade Symboldatei --",
+ ["en"]="loading symbolset --",
+ ["fr"]="chargement du jeu de symbole --",
+ ["it"]="caricamento gruppo di simboli --",
+ ["nl"]="symboolset -- wordt geladen",
+ ["no"]="leser inn symbolsett --",
+ ["ro"]="se incarca setul de simboluri --",
+ },
+ ["files"]={ "symb-ini.tex" },
+ ["title"]={
+ ["cs"]="symboly",
+ ["de"]="Symbole",
+ ["en"]="symbols",
+ ["fr"]="symboles",
+ ["it"]="simboli",
+ ["nl"]="symbolen",
+ ["no"]="symboler",
+ ["ro"]="simboluri",
+ },
+ },
+ ["systems"]={
+ ["1"]={
+ ["cs"]="nacteni pomocneho souboru odlozeno (typemode)",
+ ["de"]="Laden der Hilfsdatei aufgeschoben (Eingabe-Modus)",
+ ["en"]="loading utility-file postponed (typemode)",
+ ["fr"]="chargement de fichier utilitaire reporté (typemode)",
+ ["it"]="caricamento dei file supplementari posticipato (typemode)",
+ ["nl"]="laden hulpfile uitgesteld (typemode)",
+ ["no"]="innlesning av hjelpefila utsatt (typemode)",
+ ["ro"]="se incarca utilitarul-fisierul este amanat (typemode)",
+ },
+ ["10"]={
+ ["cs"]="nepouzivejte em v --",
+ ["de"]="Benutzte kein em in --",
+ ["en"]="don't use em in --",
+ ["fr"]="n'utilisez pas em dans --",
+ ["it"]="non usare em in --",
+ ["nl"]="gebruik geen em in --",
+ ["no"]="ikke bruk em i --",
+ ["ro"]="nu folositi em in --",
+ },
+ ["11"]={
+ ["cs"]="vytvarim jednoduchy pomocny soubor",
+ ["de"]="Erstelle einfache Hilfdatei",
+ ["en"]="building simple util",
+ ["fr"]="construction util simple",
+ ["it"]="costruzione di un semplice supplemento",
+ ["nl"]="aanmaken basale hulpfile",
+ ["no"]="lager enkel hjelpefil",
+ ["ro"]="se creeaza un utilitar simplu",
+ },
+ ["12"]={
+ ["cs"]="pomosny soubor neni setriden, pouzijte texutil",
+ ["de"]="Die Hilfdatei ist nicht sortiert, verwende texutil",
+ ["en"]="the utility-file is not sorted, use texutil",
+ ["fr"]="le fichier utilitaire n'est pas trié, utilise texutil",
+ ["it"]="file di supplemento non ordinato, usare texutil",
+ ["nl"]="de hulpfile is niet gesorteerd, gebruik texutil",
+ ["no"]="hjelpefila er ikke sortert, bruk texutil",
+ ["ro"]="fisierul utilitar nu este sortat, folositi texutil",
+ },
+ ["13"]={
+ ["cs"]="znacka -- definovana --",
+ ["de"]="Beschriftung -- definiert --",
+ ["en"]="mark -- defined --",
+ ["fr"]="marquage -- defini --",
+ ["it"]="marcatura -- definita --",
+ ["nl"]="markering -- gedefinieerd --",
+ ["no"]="markering -- definert --",
+ ["ro"]="marcajul -- definit --",
+ },
+ ["14"]={
+ ["cs"]="vynucena nova stranka v seznamu na --",
+ ["de"]="Erzwungendes Seitenumbruch in Liste bei --",
+ ["en"]="forced newpage in list at --",
+ ["fr"]="nouvellepage forcée dans la liste à --",
+ ["it"]="nuova pagina obbligata in lista a --",
+ ["nl"]="geforceerde paginaovergang in lijst voor --",
+ ["no"]="tvunget sideskift i liste ved --",
+ ["ro"]="s-a fortat trecere pa pagina noua in lista la --",
+ },
+ ["15"]={
+ ["cs"]="uklada se buffer --",
+ ["de"]="Speichere Buffer --",
+ ["en"]="saving buffer --",
+ ["fr"]="sauvegarde du tampon (buffer) --",
+ ["it"]="salvataggio del buffer --",
+ ["nl"]="wegschrijven buffer --",
+ ["no"]="lagrer Buffer --",
+ ["ro"]="buffer salvat --",
+ },
+ ["16"]={
+ ["cs"]="sazi se buffer --",
+ ["de"]="Setzte Buffer --",
+ ["en"]="typesetting buffer --",
+ ["fr"]="composition du tampon (buffer) --",
+ ["it"]="composizione del buffer --",
+ ["nl"]="inlezen buffer --",
+ ["no"]="tegnsetter buffer --",
+ ["ro"]="buffer-ul -- s-a cules",
+ },
+ ["17"]={
+ ["cs"]="sazi se doslovny (verbatim) buffer --",
+ ["de"]="Setzte tippen-Buffer --",
+ ["en"]="typesetting verbatim buffer --",
+ ["fr"]="composition textuelle du tampon (buffer) --",
+ ["it"]="composizione verbatim del buffer --",
+ ["nl"]="verbatim inlezen buffer --",
+ ["no"]="tegnsetter verbatim-buffer --",
+ ["ro"]="se culege buffer-ul verbatim --",
+ },
+ ["18"]={
+ ["cs"]="synonymum -- -- neexistuje",
+ ["de"]="Synonym -- -- existiert nicht",
+ ["en"]="synonym -- -- does not exist",
+ ["fr"]="le synonyme -- -- n'existe pas",
+ ["it"]="sinonimo -- -- non esistente",
+ ["nl"]="synoniem -- -- bestaat niet",
+ ["no"]="synonym -- -- eksisterer ikke",
+ ["ro"]="sinonimul -- -- nu exista",
+ },
+ ["19"]={
+ ["cs"]="vyznam (synonyma) -- nacten",
+ ["de"]="Bedeutung (synonyme) von -- geladen",
+ ["en"]="meaning (synonyms) of -- loaded",
+ ["fr"]="signification (synonymes) de -- chargée",
+ ["it"]="significato (sinonimi) di -- caricato",
+ ["nl"]="betekenissen (synoniemen) van -- geladen",
+ ["no"]="betydning (synonymer) av -- er lest inn",
+ ["ro"]="intelesul (sinonimele) pentru -- incarcat",
+ },
+ ["2"]={
+ ["cs"]="-- nacteno",
+ ["de"]="-- geladen",
+ ["en"]="-- loaded",
+ ["fr"]="-- chargé",
+ ["it"]="-- caricato",
+ ["nl"]="-- geladen",
+ ["no"]="-- er lest inn",
+ ["ro"]="-- s-a incarcat",
+ },
+ ["20"]={
+ ["cs"]="vyznam (trideni) -- nacten",
+ ["de"]="Bedeutung (sortieren) von -- geladen",
+ ["en"]="meaning (sorts) of -- loaded",
+ ["fr"]="signification (tris) de -- chargée",
+ ["it"]="significato (specie) di -- caricato",
+ ["nl"]="betekenissen (sorteren) van -- geladen",
+ ["no"]="betydning (sorterer) av -- er lest inn",
+ ["ro"]="intelesul (ordinea) pentru -- incarcat",
+ },
+ ["21"]={
+ ["cs"]="pomocny soubor necten",
+ ["de"]="Die Hilfsdatei ist nicht geladen",
+ ["en"]="no utility data is loaded",
+ ["fr"]="pas de données utilitaires chargées",
+ ["it"]="nessuna informazione supplementare caricata",
+ ["nl"]="de hulpfile is niet geladen",
+ ["no"]="hjelpefila er ikke lest inn",
+ ["ro"]="nici o data utilitara nu este incarcata",
+ },
+ ["22"]={
+ ["cs"]="pouzijte platny pomocny soubor",
+ ["de"]="Benoetige gueltige Hilfsdateie",
+ ["en"]="use a valid utilityfile",
+ ["fr"]="utilise un fichier utilitaire valide",
+ ["it"]="usare un file supplementare valido",
+ ["nl"]="gebruik een goede hulpfile",
+ ["no"]="bruk en gyldig hjelpefil",
+ ["ro"]="folositi un fisier utilitar valid",
+ },
+ ["23"]={
+ ["cs"]="-- upraveno na --",
+ ["de"]="-- angeordnet auf --",
+ ["en"]="-- arranged at --",
+ ["fr"]="-- arrangé à --",
+ ["it"]="-- sistemato a --",
+ ["nl"]="-- gearrangeerd op --",
+ ["no"]="-- arrangert på --",
+ ["ro"]="-- aranjat la --",
+ },
+ ["24"]={
+ ["cs"]="plovouci bloky",
+ ["de"]="Fliessbloecke",
+ ["en"]="Floatblocks",
+ ["fr"]="blocsflottants",
+ ["it"]="Oggetti mobili",
+ ["nl"]="Plaatsblokken",
+ ["no"]="Flytblokker",
+ ["ro"]="Blocuri",
+ },
+ ["25"]={
+ ["cs"]="reference",
+ ["de"]="Referenzen",
+ ["en"]="References",
+ ["fr"]="Réferences",
+ ["it"]="Riferimenti",
+ ["nl"]="Verwijzingen",
+ ["no"]="Referanser",
+ ["ro"]="Referinte",
+ },
+ ["26"]={
+ ["cs"]="registry",
+ ["de"]="Register",
+ ["en"]="Registers",
+ ["fr"]="Registres",
+ ["it"]="Registri",
+ ["nl"]="Registers",
+ ["no"]="Registere",
+ ["ro"]="Registri",
+ },
+ ["27"]={
+ ["cs"]="verze",
+ ["de"]="Version",
+ ["en"]="Version",
+ ["fr"]="Version",
+ ["it"]="Versione",
+ ["nl"]="Versie",
+ ["no"]="Versjon",
+ ["ro"]="Versiune",
+ },
+ ["4"]={
+ ["cs"]="prikaz -- je jiz definovan",
+ ["de"]="Befehl -- ist bereits definiert",
+ ["en"]="command -- is already defined",
+ ["fr"]="la commande -- est déjà définie",
+ ["it"]="comando -- già definito",
+ ["nl"]="commando -- is al gedefinieerd",
+ ["no"]="kommando -- er allerede definert",
+ ["ro"]="comanda -- este deja definita",
+ },
+ ["41"]={
+ ["cs"]="externi soubor -- ve skupine -- neexistuje",
+ ["de"]="Externe Datei -- in Gruppe -- existiert nicht",
+ ["en"]="external file -- in group -- does not exist",
+ ["fr"]="le fichier externe -- du groupe -- n'existe pas",
+ ["it"]="il file esterno -- del gruppo -- non esiste",
+ ["nl"]="externe file -- in groep -- bestaat niet",
+ ["no"]="ekstern fil -- i gruppe -- eksisterer ikke",
+ ["ro"]="fisierul extern -- din grupul -- nu exista",
+ },
+ ["5"]={
+ ["cs"]="makra z -- nactena",
+ ["de"]="Modul -- geladen",
+ ["en"]="module -- loaded",
+ ["fr"]="module -- chargé",
+ ["it"]="macro del modulo -- caricate",
+ ["nl"]="module -- geladen",
+ ["no"]="makroene i modul -- er lest inn",
+ ["ro"]="macro-urile din modulul -- s-au incarcat",
+ },
+ ["6"]={
+ ["cs"]="zadna makra v -- nenalezena",
+ ["de"]="Modul -- gefunden",
+ ["en"]="module -- not found",
+ ["fr"]="module -- non trouvé",
+ ["it"]="nessuna macro trovata nel modulo --",
+ ["nl"]="geen module -- gevonden",
+ ["no"]="ingen makroer funnet i modul ---",
+ ["ro"]="nu s-au gasit macro-uri in modulul --",
+ },
+ ["7"]={
+ ["cs"]="makra z -- jsou jiz nactena",
+ ["de"]="Modul -- bereits geladen",
+ ["en"]="module -- already loaded",
+ ["fr"]="module -- déjà chargé",
+ ["it"]="macro del modulo -- già caricate",
+ ["nl"]="module -- reeds geladen",
+ ["no"]="makroene i modul -- er allerede lest inn",
+ ["ro"]="macro-urile din modulul -- s-au incarcat deja",
+ },
+ ["8"]={
+ ["cs"]="nova verze pomocneho souboru, je treba druheho behu",
+ ["de"]="Neue Version der Hilfsdatei, zweiter Durchlauf benoetigt",
+ ["en"]="new version of utility file, second pass needed",
+ ["fr"]="nouvelle version de fichier utilitaire, seconde passe nécessaire",
+ ["it"]="nuova versione del file supplementare, seconda passata necessaria",
+ ["nl"]="nieuwe versie hulpfile, tweede run nodig",
+ ["no"]="ny versjon av hjelpefil, andre gjennomkjøring nødvendig",
+ ["ro"]="o noua versiune de fisier utilitar, este necesara o noua trecere",
+ },
+ ["9"]={
+ ["cs"]="-- nenalezeno/nezpracovano",
+ ["de"]="-- nicht gefunden/verarbeitet",
+ ["en"]="-- not found/processed",
+ ["fr"]="-- non trouvé/traité",
+ ["it"]="-- non trovato/elaborato",
+ ["nl"]="-- niet gevonden/geplaatst",
+ ["no"]="-- ikke funnet/behandlet",
+ ["ro"]="-- nu este gasit/procesat",
+ },
+ ["91"]={
+ ["en"]="papertray --",
+ ["nl"]="papierlade --",
+ },
+ ["files"]={ "core-mis.tex", "page-ini.tex", "prag-gen.tex", "strc-mar.tex" },
+ ["title"]={
+ ["cs"]="system",
+ ["de"]="system",
+ ["en"]="system",
+ ["fr"]="système",
+ ["it"]="sistema",
+ ["nl"]="systeem",
+ ["no"]="system",
+ ["ro"]="sistem",
+ },
+ },
+ ["textblocks"]={
+ ["1"]={
+ ["cs"]="nova verze, je treba druhy beh",
+ ["de"]="neue Version, zweiter Durchlauf benoetigt",
+ ["en"]="new version, second pass needed",
+ ["fr"]="nouvelle version, une seconde passe est nécessaire",
+ ["it"]="nuova versione, seconda passata necessaria",
+ ["nl"]="nieuwe versie, tweede run nodig",
+ ["no"]="ny versjon, andre gjennomkjøring nødvendig",
+ ["ro"]="o noua versiune, este nevoie de inca o trecere",
+ },
+ ["10"]={
+ ["cs"]="-- nacteno a zpracovano",
+ ["de"]="-- geladen und verarbeitet",
+ ["en"]="-- loaded and processed",
+ ["fr"]="-- chargé et traité",
+ ["it"]="-- caricato ed elaborato",
+ ["nl"]="-- geladen en verwerkt",
+ ["no"]="-- lest inn og behandlet",
+ ["ro"]="-- incarcat si procesat",
+ },
+ ["11"]={
+ ["cs"]="-- nacteno a vysazeno",
+ ["de"]="-- geladen und gesetzt",
+ ["en"]="-- loaded and typeset",
+ ["fr"]="-- chargé et composé",
+ ["it"]="-- caricato e composto",
+ ["nl"]="-- geladen en geplaatst",
+ ["no"]="-- lest inn og tegnsatt",
+ ["ro"]="-- incarcat si cules",
+ },
+ ["12"]={
+ ["cs"]="-- preskoceno",
+ ["de"]="-- ausgelassen",
+ ["en"]="-- skipped",
+ ["fr"]="-- sauté",
+ ["it"]="-- saltato",
+ ["nl"]="-- overgeslagen",
+ ["no"]="-- utelatt",
+ ["ro"]="-- sarit peste",
+ },
+ ["2"]={
+ ["cs"]="zapisuji bloky do --",
+ ["de"]="schreibe Bloecke zu --",
+ ["en"]="writing blocks to --",
+ ["fr"]="ecriture des blocs vers --",
+ ["it"]="scrittura dei blocchi su --",
+ ["nl"]="wegschrijven blokken naar --",
+ ["no"]="skriver blokker til --",
+ ["ro"]="se scriu blocurile in --",
+ },
+ ["3"]={
+ ["cs"]="ctu bloky z --",
+ ["de"]="lese Bloecke von --",
+ ["en"]="reading blocks from --",
+ ["fr"]="lecture des blocs en provenance de --",
+ ["it"]="lettura dei blocchi da --",
+ ["nl"]="inlezen blokken uit --",
+ ["no"]="leser blokker fra --",
+ ["ro"]="se citesc blocurile din --",
+ },
+ ["4"]={
+ ["cs"]="je treba druhy beh",
+ ["de"]="zweiter Durchlauf benoetigt",
+ ["en"]="second pass needed",
+ ["fr"]="seconde passe nécessaire",
+ ["it"]="seconda passata necessaria",
+ ["nl"]="er is een tweede run nodig",
+ ["no"]="andre gjennomkjøring nødvendig",
+ ["ro"]="este nevoie de inca o trecere",
+ },
+ ["5"]={
+ ["cs"]="-- neni skryto",
+ ["de"]="-- nicht verborgen",
+ ["en"]="-- not hidden",
+ ["fr"]="-- non caché",
+ ["it"]="-- non nascosto",
+ ["nl"]="-- niet verborgen",
+ ["no"]="-- ikke skjult",
+ ["ro"]="-- nu este ascuns",
+ },
+ ["6"]={
+ ["cs"]="-- skryto a zpracovano",
+ ["de"]="-- verborgen und verarbeitet",
+ ["en"]="-- hidden and processed",
+ ["fr"]="-- caché et traité",
+ ["it"]="-- nascosto ed elaborato",
+ ["nl"]="-- verborgen en verwerkt",
+ ["no"]="-- skjult og behandlet",
+ ["ro"]="-- ascuns si procesat",
+ },
+ ["7"]={
+ ["cs"]="-- skryto",
+ ["de"]="-- verborgen",
+ ["en"]="-- hidden",
+ ["fr"]="-- caché",
+ ["it"]="-- nascosto",
+ ["nl"]="-- verborgen",
+ ["no"]="-- skjult",
+ ["ro"]="-- ascuns",
+ },
+ ["8"]={
+ ["cs"]="-- vysazeno",
+ ["de"]="-- gesetzt",
+ ["en"]="-- typeset",
+ ["fr"]="-- composé",
+ ["it"]="-- composto",
+ ["nl"]="-- gehandhaafd",
+ ["no"]="-- tegnsatt",
+ ["ro"]="-- cules",
+ },
+ ["9"]={
+ ["cs"]="-- nevysazeno",
+ ["de"]="-- nicht gesetzt",
+ ["en"]="-- not typeset",
+ ["fr"]="-- non composé",
+ ["it"]="-- non composto",
+ ["nl"]="-- niet gehandhaafd",
+ ["no"]="-- ikke tegnsatt",
+ ["ro"]="-- nu este cules",
+ },
+ ["files"]={ "core-blk.tex" },
+ ["title"]={
+ ["cs"]="textovyblok",
+ ["de"]="textblock",
+ ["en"]="textblocks",
+ ["fr"]="blocs de texte",
+ ["it"]="blocchi di testo",
+ ["nl"]="tekstblokken",
+ ["no"]="tekstblokker",
+ ["ro"]="blocuri de text",
+ },
+ },
+ ["verbatims"]={
+ ["1"]={
+ ["cs"]="soubor -- neexistuje",
+ ["de"]="Datei -- existiert nicht",
+ ["en"]="file -- does not exist",
+ ["fr"]="le fichier -- n'existe pas",
+ ["it"]="il file -- non esiste",
+ ["nl"]="file -- bestaat niet",
+ ["no"]="fil -- eksisterer ikke",
+ ["ro"]="fisierul -- nu exista",
+ },
+ ["files"]={ "core-ver.tex" },
+ ["title"]={
+ ["cs"]="verbatim",
+ ["de"]="verbatim",
+ ["en"]="verbatim",
+ ["fr"]="verbatim",
+ ["it"]="verbatim",
+ ["nl"]="typen",
+ ["no"]="verbatim",
+ ["ro"]="verbatim",
+ },
+ },
+ ["versions"]={
+ ["1"]={
+ ["cs"]="postradam @+",
+ ["de"]="fehlendes @+",
+ ["en"]="missing @+",
+ ["fr"]="@+ manquant",
+ ["it"]="@+ mancante",
+ ["nl"]="er mankeert een @+",
+ ["no"]="manglende @+",
+ ["ro"]="lipseste @+",
+ },
+ ["2"]={
+ ["cs"]="oznacuji se strany",
+ ["de"]="Erstelle Seiten",
+ ["en"]="marking pages",
+ ["fr"]="marquage des pages",
+ ["it"]="marcatura pagine",
+ ["nl"]="markeren pagina's",
+ ["no"]="markerer sider",
+ ["ro"]="pagini marcate",
+ },
+ ["3"]={
+ ["cs"]="oznacene strany: --",
+ ["de"]="Ausgewaehlte Seiten: --",
+ ["en"]="selected pages: --",
+ ["fr"]="pages sélectionnées : --",
+ ["it"]="pagine selezionate: --",
+ ["nl"]="geselecteerde pagina's: --",
+ ["no"]="valgte sider: --",
+ ["ro"]="pagini selectate: --",
+ },
+ ["files"]={ "core-int.tex" },
+ ["title"]={
+ ["cs"]="verze",
+ ["de"]="Version",
+ ["en"]="version",
+ ["fr"]="version",
+ ["it"]="version",
+ ["nl"]="versie",
+ ["no"]="versjon",
+ ["ro"]="versiuni",
+ },
+ },
+}
\ No newline at end of file
diff --git a/tex/context/base/mult-mfr.tex b/tex/context/base/mult-mfr.tex
new file mode 100644
index 000000000..ecfd88ecc
--- /dev/null
+++ b/tex/context/base/mult-mfr.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{réference -- inconnue}
+\setinterfacemessage{references}{3}{type -- de réference inconnu}
+\setinterfacemessage{references}{2}{réference -- dupliquée à la page --}
+\setinterfacemessage{references}{4}{réference -- inconnue}
+\setinterfacemessage{references}{title}{réferences}
+\setinterfacemessage{references}{30}{objet -- inconnu}
+\setinterfacemessage{references}{31}{objet -- dupliqué}
+\setinterfacemessage{references}{21}{document -- chargé}
+\setinterfacemessage{references}{22}{le document -- n'est pas interactif}
+\setinterfacemessage{references}{23}{reference -- indéterminé (préfixe=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{manipulation -- de police}
+\setinterfacemessage{handlings}{3}{manipulation -- inconnue de police}
+\setinterfacemessage{handlings}{2}{la manipulation -- de police est chargée}
+\setinterfacemessage{handlings}{title}{manipulation}
+\setinterfacemessage{systems}{title}{système}
+\setinterfacemessage{systems}{41}{le fichier externe -- du groupe -- n'existe pas}
+\setinterfacemessage{systems}{9}{-- non trouvé/traité}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{nouvelle version de fichier utilitaire, seconde passe nécessaire}
+\setinterfacemessage{systems}{21}{pas de données utilitaires chargées}
+\setinterfacemessage{systems}{20}{signification (tris) de -- chargée}
+\setinterfacemessage{systems}{5}{module -- chargé}
+\setinterfacemessage{systems}{4}{la commande -- est déjà définie}
+\setinterfacemessage{systems}{27}{Version}
+\setinterfacemessage{systems}{26}{Registres}
+\setinterfacemessage{systems}{25}{Réferences}
+\setinterfacemessage{systems}{24}{blocsflottants}
+\setinterfacemessage{systems}{1}{chargement de fichier utilitaire reporté (typemode)}
+\setinterfacemessage{systems}{23}{-- arrangé à --}
+\setinterfacemessage{systems}{22}{utilise un fichier utilitaire valide}
+\setinterfacemessage{systems}{2}{-- chargé}
+\setinterfacemessage{systems}{19}{signification (synonymes) de -- chargée}
+\setinterfacemessage{systems}{18}{le synonyme -- -- n'existe pas}
+\setinterfacemessage{systems}{7}{module -- déjà chargé}
+\setinterfacemessage{systems}{6}{module -- non trouvé}
+\setinterfacemessage{systems}{14}{nouvellepage forcée dans la liste à --}
+\setinterfacemessage{systems}{15}{sauvegarde du tampon (buffer) --}
+\setinterfacemessage{systems}{16}{composition du tampon (buffer) --}
+\setinterfacemessage{systems}{17}{composition textuelle du tampon (buffer) --}
+\setinterfacemessage{systems}{13}{marquage -- defini --}
+\setinterfacemessage{systems}{12}{le fichier utilitaire n'est pas trié, utilise texutil}
+\setinterfacemessage{systems}{11}{construction util simple}
+\setinterfacemessage{systems}{10}{n'utilisez pas em dans --}
+\setinterfacemessage{floatblocks}{1}{-- renuméroté / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- déplacé}
+\setinterfacemessage{floatblocks}{2}{-- sauvegardé}
+\setinterfacemessage{floatblocks}{5}{ordre adapté}
+\setinterfacemessage{floatblocks}{4}{-- placé}
+\setinterfacemessage{floatblocks}{7}{n flottants de bas de page limité à --}
+\setinterfacemessage{floatblocks}{6}{n flottants de haut de page limité à --}
+\setinterfacemessage{floatblocks}{9}{ordre perturbé}
+\setinterfacemessage{floatblocks}{8}{moins de -- lignes}
+\setinterfacemessage{floatblocks}{title}{blocs de flottants}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{indéfini}
+\setinterfacemessage{floatblocks}{11}{pas de bloc donné}
+\setinterfacemessage{floatblocks}{10}{-- limité}
+\setinterfacemessage{interactions}{1}{ratio d'aspect -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{inactif}
+\setinterfacemessage{interactions}{2}{actif}
+\setinterfacemessage{interactions}{5}{le fichier joint -- est inconnu}
+\setinterfacemessage{interactions}{4}{pas de synchronisation de page (--) dans le hmode}
+\setinterfacemessage{interactions}{6}{le fichier joint -- n'existe pas}
+\setinterfacemessage{interactions}{title}{interaction}
+\setinterfacemessage{interactions}{21}{-- code inseré}
+\setinterfacemessage{structures}{1}{début de blocsection --}
+\setinterfacemessage{structures}{title}{structure}
+\setinterfacemessage{structures}{2}{fin de blocsection --}
+\setinterfacemessage{linguals}{1}{les motifs -- pour -- sont chargés (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{hyphenations -- pour -- chargés (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{pas de motifs -- pour -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{les motifs pour -- ne sont pas chargés}
+\setinterfacemessage{linguals}{4}{pas d'hyphenations -- pour -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{les options spécifiques de langue [--] introduisent un -- saut}
+\setinterfacemessage{linguals}{6}{langue -- non définie}
+\setinterfacemessage{linguals}{9}{la langue -- est active}
+\setinterfacemessage{linguals}{8}{les options spécifiques de langue [--] sont ajoutés en douceur}
+\setinterfacemessage{linguals}{title}{langue}
+\setinterfacemessage{linguals}{10}{motifs -- chargés}
+\setinterfacemessage{regimes}{1}{encodage --}
+\setinterfacemessage{regimes}{3}{encodage -- inconnu}
+\setinterfacemessage{regimes}{2}{l'encodage -- est chargé}
+\setinterfacemessage{regimes}{title}{encodage}
+\setinterfacemessage{filters}{1}{le filtre -- est chargé}
+\setinterfacemessage{filters}{title}{filtre}
+\setinterfacemessage{filters}{2}{filtre -- inconnu}
+\setinterfacemessage{verbatims}{1}{le fichier -- n'existe pas}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{encodage --}
+\setinterfacemessage{encodings}{3}{encodage -- inconnu}
+\setinterfacemessage{encodings}{2}{l'encodage -- est chargé}
+\setinterfacemessage{encodings}{title}{encodage}
+\setinterfacemessage{columns}{1}{seules -- colonnes possibles}
+\setinterfacemessage{columns}{3}{problèmes, désactive l'équilibrage}
+\setinterfacemessage{columns}{2}{utilisez \string\filbreak\space en tant qu'alternative}
+\setinterfacemessage{columns}{5}{flottant en partie inférieure pas encore supporté}
+\setinterfacemessage{columns}{4}{flottant en partie supérieure pas encore supporté}
+\setinterfacemessage{columns}{7}{équilibrage abandonné après 100 pas}
+\setinterfacemessage{columns}{6}{-- flottant(s) reporté(s)}
+\setinterfacemessage{columns}{9}{vérification des irrégularités}
+\setinterfacemessage{columns}{8}{équilibré en -- pas}
+\setinterfacemessage{columns}{title}{colonnes}
+\setinterfacemessage{columns}{13}{flottant large déplacé dans la partie supérieure de la colonne}
+\setinterfacemessage{columns}{12}{flottant déplacé à la colonne suivante / --}
+\setinterfacemessage{columns}{11}{flottant mis à la largeur de la colonne}
+\setinterfacemessage{columns}{10}{(moins de) 1 ligne restante}
+\setinterfacemessage{textblocks}{1}{nouvelle version, une seconde passe est nécessaire}
+\setinterfacemessage{textblocks}{3}{lecture des blocs en provenance de --}
+\setinterfacemessage{textblocks}{2}{ecriture des blocs vers --}
+\setinterfacemessage{textblocks}{5}{-- non caché}
+\setinterfacemessage{textblocks}{4}{seconde passe nécessaire}
+\setinterfacemessage{textblocks}{7}{-- caché}
+\setinterfacemessage{textblocks}{6}{-- caché et traité}
+\setinterfacemessage{textblocks}{9}{-- non composé}
+\setinterfacemessage{textblocks}{8}{-- composé}
+\setinterfacemessage{textblocks}{title}{blocs de texte}
+\setinterfacemessage{textblocks}{12}{-- sauté}
+\setinterfacemessage{textblocks}{11}{-- chargé et composé}
+\setinterfacemessage{textblocks}{10}{-- chargé et traité}
+\setinterfacemessage{symbols}{1}{chargement du jeu de symbole --}
+\setinterfacemessage{symbols}{title}{symboles}
+\setinterfacemessage{versions}{1}{@+ manquant}
+\setinterfacemessage{versions}{3}{pages sélectionnées : --}
+\setinterfacemessage{versions}{2}{marquage des pages}
+\setinterfacemessage{versions}{title}{version}
+\setinterfacemessage{specials}{1}{-- chargé}
+\setinterfacemessage{specials}{3}{-- est remis à zéro}
+\setinterfacemessage{specials}{2}{pas d'imbracations plus profondes ne sont permises --}
+\setinterfacemessage{specials}{5}{chargement du fichier de définition --}
+\setinterfacemessage{specials}{4}{la commande -- n'existe pas}
+\setinterfacemessage{specials}{7}{pilote -- inconnu}
+\setinterfacemessage{specials}{6}{l'imbrication n'est pas permise}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{chargement du jeu de script --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{préambule -- inconnu}
+\setinterfacemessage{fonts}{1}{encodage --}
+\setinterfacemessage{fonts}{3}{variante -- inconnue}
+\setinterfacemessage{fonts}{2}{la variante -- est chargée}
+\setinterfacemessage{fonts}{5}{le style -- n'est pas défini}
+\setinterfacemessage{fonts}{4}{policecorps -- n'est pas définie}
+\setinterfacemessage{fonts}{7}{format -- inconnu}
+\setinterfacemessage{fonts}{6}{-- est chargé}
+\setinterfacemessage{fonts}{14}{policecorps -- est défini (une définition globale pourrait être plus adéquat)}
+\setinterfacemessage{fonts}{8}{style -- défini}
+\setinterfacemessage{fonts}{title}{corps de texte}
+\setinterfacemessage{fonts}{10}{fichier de police -- inconnu}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{fichier global --}
+\setinterfacemessage{databases}{2}{fichier local --}
+\setinterfacemessage{databases}{4}{fichier inconnu --}
+\setinterfacemessage{databases}{title}{bases de données}
+\setinterfacemessage{colors}{1}{le système -- est globalement activé}
+\setinterfacemessage{colors}{3}{-- n'est pas défini --}
+\setinterfacemessage{colors}{2}{le système -- est localement activé}
+\setinterfacemessage{colors}{5}{système -- inconnu}
+\setinterfacemessage{colors}{4}{le système -- est chargé}
+\setinterfacemessage{colors}{7}{le palette -- n'est pas disponible}
+\setinterfacemessage{colors}{6}{la palette -- est disponible}
+\setinterfacemessage{colors}{9}{l'espace de couleur -- n'est pas supporté}
+\setinterfacemessage{colors}{8}{la spécification -- de la couleur -- devient noire}
+\setinterfacemessage{colors}{title}{couleurs}
+\setinterfacemessage{colors}{12}{-- est enregistré}
+\setinterfacemessage{colors}{11}{la couleur est convertie en niveau de gris}
+\setinterfacemessage{colors}{10}{-- l'espace de couleur est supporté}
+\setinterfacemessage{layouts}{1}{hauteurtexte adaptée avec -- à la page --}
+\setinterfacemessage{layouts}{3}{-- times text postponed}
+\setinterfacemessage{layouts}{2}{-- times postponed text placed}
+\setinterfacemessage{layouts}{5}{blocsmarge inactifs}
+\setinterfacemessage{layouts}{4}{blocsmarge actifs}
+\setinterfacemessage{layouts}{7}{calcul de l'espace pour le logo}
+\setinterfacemessage{layouts}{6}{jeu de souspage -- traité (taille --)}
+\setinterfacemessage{layouts}{9}{pas plus de -- niveaux pour l'instant dans les élémentarisations}
+\setinterfacemessage{layouts}{8}{calcul des arrières-plans}
+\setinterfacemessage{layouts}{title}{calque}
+\setinterfacemessage{layouts}{11}{espacement -- non permis en modegrille}
+\setinterfacemessage{layouts}{10}{-- et -- ne sont pas ajoutés à 1.0}
+\setinterfacemessage{check}{1}{manquant ou dégroupé '=' après '--' à la ligne --}
+\setinterfacemessage{check}{3}{-- -- remplace une macro, utilisez des MAJUSCULES !}
+\setinterfacemessage{check}{2}{-- argument(s) attendu(s) à la ligne --}
+\setinterfacemessage{check}{title}{vérification}
+\setinterfacemessage{metapost}{1}{chargement de la bibliothèque metapost --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{le synonyme de fichier -- est déjà utilisé pour --}
+\setinterfacemessage{files}{title}{fichiers}
+\setinterfacemessage{figures}{1}{la figure -- ne peut être trouvée}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{la figure -- n'est pas pré-sélectionnée}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{les dimensions de -- chargées implicitement à partir du fichier de figure}
+\setinterfacemessage{figures}{6}{les dimensions de -- calculées par rlxtools}
+\setinterfacemessage{figures}{8}{figureobject -- est réutilisé}
+\setinterfacemessage{figures}{title}{figures}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mit.tex b/tex/context/base/mult-mit.tex
new file mode 100644
index 000000000..0efb03e90
--- /dev/null
+++ b/tex/context/base/mult-mit.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{riferimento sconosciuto --}
+\setinterfacemessage{references}{3}{riferimento di tipo sconosciuto --}
+\setinterfacemessage{references}{2}{riferimento duplicato -- a pagina --}
+\setinterfacemessage{references}{4}{riferimento illecito --}
+\setinterfacemessage{references}{title}{riferimenti}
+\setinterfacemessage{references}{30}{oggetto sconosciuto --}
+\setinterfacemessage{references}{31}{oggetto duplicato --}
+\setinterfacemessage{references}{21}{documento -- caricato}
+\setinterfacemessage{references}{22}{il documento -- non ø interattivo}
+\setinterfacemessage{references}{23}{riferimento ambiguo -- (prefisso=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{sistema}
+\setinterfacemessage{systems}{41}{il file esterno -- del gruppo -- non esiste}
+\setinterfacemessage{systems}{9}{-- non trovato/elaborato}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{nuova versione del file supplementare, seconda passata necessaria}
+\setinterfacemessage{systems}{21}{nessuna informazione supplementare caricata}
+\setinterfacemessage{systems}{20}{significato (specie) di -- caricato}
+\setinterfacemessage{systems}{5}{macro del modulo -- caricate}
+\setinterfacemessage{systems}{4}{comando -- già definito}
+\setinterfacemessage{systems}{27}{Versione}
+\setinterfacemessage{systems}{26}{Registri}
+\setinterfacemessage{systems}{25}{Riferimenti}
+\setinterfacemessage{systems}{24}{Oggetti mobili}
+\setinterfacemessage{systems}{1}{caricamento dei file supplementari posticipato (typemode)}
+\setinterfacemessage{systems}{23}{-- sistemato a --}
+\setinterfacemessage{systems}{22}{usare un file supplementare valido}
+\setinterfacemessage{systems}{2}{-- caricato}
+\setinterfacemessage{systems}{19}{significato (sinonimi) di -- caricato}
+\setinterfacemessage{systems}{18}{sinonimo -- -- non esistente}
+\setinterfacemessage{systems}{7}{macro del modulo -- già caricate}
+\setinterfacemessage{systems}{6}{nessuna macro trovata nel modulo --}
+\setinterfacemessage{systems}{14}{nuova pagina obbligata in lista a --}
+\setinterfacemessage{systems}{15}{salvataggio del buffer --}
+\setinterfacemessage{systems}{16}{composizione del buffer --}
+\setinterfacemessage{systems}{17}{composizione verbatim del buffer --}
+\setinterfacemessage{systems}{13}{marcatura -- definita --}
+\setinterfacemessage{systems}{12}{file di supplemento non ordinato, usare texutil}
+\setinterfacemessage{systems}{11}{costruzione di un semplice supplemento}
+\setinterfacemessage{systems}{10}{non usare em in --}
+\setinterfacemessage{floatblocks}{1}{-- rinumerato / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- mosso}
+\setinterfacemessage{floatblocks}{2}{-- salvato}
+\setinterfacemessage{floatblocks}{5}{ordine aggiustato}
+\setinterfacemessage{floatblocks}{4}{-- sistemato}
+\setinterfacemessage{floatblocks}{7}{n di bottom floats limitato a --}
+\setinterfacemessage{floatblocks}{6}{n di top floats limitato a --}
+\setinterfacemessage{floatblocks}{9}{ordine disturbato}
+\setinterfacemessage{floatblocks}{8}{meno di -- righe}
+\setinterfacemessage{floatblocks}{title}{oggetti mobili}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{non definito}
+\setinterfacemessage{floatblocks}{11}{nessun oggetto specificato}
+\setinterfacemessage{floatblocks}{10}{-- limitato}
+\setinterfacemessage{interactions}{1}{rapporto -- x -- (b x a)}
+\setinterfacemessage{interactions}{3}{inattiva}
+\setinterfacemessage{interactions}{2}{attiva}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{sincronizzazione di pagina (--) non disponibile in hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interazione}
+\setinterfacemessage{interactions}{21}{codice -- inserito}
+\setinterfacemessage{structures}{1}{inizio del blocco (sezione) --}
+\setinterfacemessage{structures}{title}{struttura}
+\setinterfacemessage{structures}{2}{fine del blocco (sezione) --}
+\setinterfacemessage{linguals}{1}{schemi -- per -- caricati (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{sillabazione -- per -- caricata (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{niente schemi -- per -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{schemi per -- non caricati}
+\setinterfacemessage{linguals}{4}{niente sillabazione -- per -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{opzioni specifiche per la lingua [--] introducono un salto --}
+\setinterfacemessage{linguals}{6}{lingua -- non definita}
+\setinterfacemessage{linguals}{9}{lingua -- attiva}
+\setinterfacemessage{linguals}{8}{opzioni specifiche per la lingua [--] aggiunte trasparentemente}
+\setinterfacemessage{linguals}{title}{lingua}
+\setinterfacemessage{linguals}{10}{schemi -- caricati}
+\setinterfacemessage{regimes}{1}{codifica --}
+\setinterfacemessage{regimes}{3}{codifica sconosciuta --}
+\setinterfacemessage{regimes}{2}{codifica -- caricata}
+\setinterfacemessage{regimes}{title}{codifica}
+\setinterfacemessage{filters}{1}{filtro -- caricato}
+\setinterfacemessage{filters}{title}{filtri}
+\setinterfacemessage{filters}{2}{filtro sconosciuto --}
+\setinterfacemessage{verbatims}{1}{il file -- non esiste}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{codifica --}
+\setinterfacemessage{encodings}{3}{codifica sconosciuta --}
+\setinterfacemessage{encodings}{2}{codifica -- caricata}
+\setinterfacemessage{encodings}{title}{codifica}
+\setinterfacemessage{columns}{1}{solo -- colonne possibili}
+\setinterfacemessage{columns}{3}{problemi, disabilitare il bilanciamento}
+\setinterfacemessage{columns}{2}{in alternativa, usare \string\filbreak}
+\setinterfacemessage{columns}{5}{float in fondo non ancora supportato}
+\setinterfacemessage{columns}{4}{float in cima non ancora supportato}
+\setinterfacemessage{columns}{7}{bilanciamento annullato dopo 100 passi}
+\setinterfacemessage{columns}{6}{-- float(s) posticipate}
+\setinterfacemessage{columns}{9}{controllare seghettamento}
+\setinterfacemessage{columns}{8}{bilanciamento in -- passo/i}
+\setinterfacemessage{columns}{title}{colonne}
+\setinterfacemessage{columns}{13}{oggetto mobile ampio spostato sopra le colonne}
+\setinterfacemessage{columns}{12}{oggetto mobile spostata alla colonna successiva / --}
+\setinterfacemessage{columns}{11}{oggetto mobile troppo ampio per la colonna}
+\setinterfacemessage{columns}{10}{(meno di) una riga rimasta}
+\setinterfacemessage{textblocks}{1}{nuova versione, seconda passata necessaria}
+\setinterfacemessage{textblocks}{3}{lettura dei blocchi da --}
+\setinterfacemessage{textblocks}{2}{scrittura dei blocchi su --}
+\setinterfacemessage{textblocks}{5}{-- non nascosto}
+\setinterfacemessage{textblocks}{4}{seconda passata necessaria}
+\setinterfacemessage{textblocks}{7}{-- nascosto}
+\setinterfacemessage{textblocks}{6}{-- nascosto ed elaborato}
+\setinterfacemessage{textblocks}{9}{-- non composto}
+\setinterfacemessage{textblocks}{8}{-- composto}
+\setinterfacemessage{textblocks}{title}{blocchi di testo}
+\setinterfacemessage{textblocks}{12}{-- saltato}
+\setinterfacemessage{textblocks}{11}{-- caricato e composto}
+\setinterfacemessage{textblocks}{10}{-- caricato ed elaborato}
+\setinterfacemessage{symbols}{1}{caricamento gruppo di simboli --}
+\setinterfacemessage{symbols}{title}{simboli}
+\setinterfacemessage{versions}{1}{@+ mancante}
+\setinterfacemessage{versions}{3}{pagine selezionate: --}
+\setinterfacemessage{versions}{2}{marcatura pagine}
+\setinterfacemessage{versions}{title}{version}
+\setinterfacemessage{specials}{1}{-- caricato}
+\setinterfacemessage{specials}{3}{-- reimpostato}
+\setinterfacemessage{specials}{2}{non ø permesso un annidamento maggiore --}
+\setinterfacemessage{specials}{5}{caricamento del file di definizione --}
+\setinterfacemessage{specials}{4}{il comando -- non esiste}
+\setinterfacemessage{specials}{7}{driver sconosciuto --}
+\setinterfacemessage{specials}{6}{annidamento non permesso}
+\setinterfacemessage{specials}{title}{specialitø}
+\setinterfacemessage{javascript}{1}{caricamento dello script set --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{preambolo sconosciuto --}
+\setinterfacemessage{fonts}{1}{codifica --}
+\setinterfacemessage{fonts}{3}{variante sconosciuta --}
+\setinterfacemessage{fonts}{2}{variante -- caricata}
+\setinterfacemessage{fonts}{5}{stile -- non definito}
+\setinterfacemessage{fonts}{4}{corpo del testo -- non definito}
+\setinterfacemessage{fonts}{7}{formato sconosciuto --}
+\setinterfacemessage{fonts}{6}{-- caricato}
+\setinterfacemessage{fonts}{14}{corpo del testo -- definito (sarebbe meglio globale)}
+\setinterfacemessage{fonts}{8}{stile -- definito}
+\setinterfacemessage{fonts}{title}{font del corpo}
+\setinterfacemessage{fonts}{10}{file di font sconosciuto --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{file globale --}
+\setinterfacemessage{databases}{2}{file locale --}
+\setinterfacemessage{databases}{4}{file sconosciuto --}
+\setinterfacemessage{databases}{title}{database}
+\setinterfacemessage{colors}{1}{sistema -- attivato globalmente}
+\setinterfacemessage{colors}{3}{-- non definito --}
+\setinterfacemessage{colors}{2}{sistema -- attivato localmente}
+\setinterfacemessage{colors}{5}{sistema -- sconosciuto}
+\setinterfacemessage{colors}{4}{sistema -- caricato}
+\setinterfacemessage{colors}{7}{tavolozza -- non disponibile}
+\setinterfacemessage{colors}{6}{tavolozza -- resa disponibile}
+\setinterfacemessage{colors}{9}{spazio dei colori -- non supportato}
+\setinterfacemessage{colors}{8}{specifica -- del colore -- convertita in nero}
+\setinterfacemessage{colors}{title}{colore}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{il colore ø convertito in grigio}
+\setinterfacemessage{colors}{10}{spazio dei colori -- supportato}
+\setinterfacemessage{layouts}{1}{altezza del testo adattata con -- a pagina --}
+\setinterfacemessage{layouts}{3}{testo posticipato -- volte}
+\setinterfacemessage{layouts}{2}{posizionato testo posticipato -- volte}
+\setinterfacemessage{layouts}{5}{blocchi in margine inattivi}
+\setinterfacemessage{layouts}{4}{blocchi in margine attivi}
+\setinterfacemessage{layouts}{7}{calcolo dello spazio per logo}
+\setinterfacemessage{layouts}{6}{gruppo di sottopagine -- elaborato (dimensione --)}
+\setinterfacemessage{layouts}{9}{attualmente non più di -- livelli di elencazione}
+\setinterfacemessage{layouts}{8}{calcolo dello sfondo}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{spaziatura -- non permessa in modo griglia}
+\setinterfacemessage{layouts}{10}{-- e -- non sommano a 1.0}
+\setinterfacemessage{check}{1}{'=' mancante o non raggruppato dopo '--' alla riga --}
+\setinterfacemessage{check}{3}{-- -- sostituisce una macro, usare le MAIUSCOLE!}
+\setinterfacemessage{check}{2}{-- argomento/i attesi alla riga --}
+\setinterfacemessage{check}{title}{controllo}
+\setinterfacemessage{metapost}{1}{caricamento della libreria metapost --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{sinonimo file -- già in uso per --}
+\setinterfacemessage{files}{title}{file}
+\setinterfacemessage{figures}{1}{figura -- non trovata}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{la figura -- non è preimpostata}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimensioni di -- caricate dal file di immagini stesso}
+\setinterfacemessage{figures}{6}{dimensioni di -- calcolate da rlxtools}
+\setinterfacemessage{figures}{8}{oggetto-figura -- riutilizzato}
+\setinterfacemessage{figures}{title}{figure}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mnl.tex b/tex/context/base/mult-mnl.tex
new file mode 100644
index 000000000..5c52f7aff
--- /dev/null
+++ b/tex/context/base/mult-mnl.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{onbekende verwijzing --}
+\setinterfacemessage{references}{3}{type verwijzing -- onbekend}
+\setinterfacemessage{references}{2}{dubbele verwijzing -- op pagina --}
+\setinterfacemessage{references}{4}{verboden verwijzing --}
+\setinterfacemessage{references}{title}{verwijzingen}
+\setinterfacemessage{references}{30}{onbekend object --}
+\setinterfacemessage{references}{31}{dubbel object --}
+\setinterfacemessage{references}{21}{document -- geladen}
+\setinterfacemessage{references}{22}{document -- is niet interactief}
+\setinterfacemessage{references}{23}{onduidelijke verwijzing -- (prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{nummer --}
+\setinterfacemessage{handlings}{1}{font afhandeling --}
+\setinterfacemessage{handlings}{3}{onbekende font afhandeling --}
+\setinterfacemessage{handlings}{2}{font afhandeling -- wordt geladen}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{systeem}
+\setinterfacemessage{systems}{41}{externe file -- in groep -- bestaat niet}
+\setinterfacemessage{systems}{9}{-- niet gevonden/geplaatst}
+\setinterfacemessage{systems}{91}{papierlade --}
+\setinterfacemessage{systems}{8}{nieuwe versie hulpfile, tweede run nodig}
+\setinterfacemessage{systems}{21}{de hulpfile is niet geladen}
+\setinterfacemessage{systems}{20}{betekenissen (sorteren) van -- geladen}
+\setinterfacemessage{systems}{5}{module -- geladen}
+\setinterfacemessage{systems}{4}{commando -- is al gedefinieerd}
+\setinterfacemessage{systems}{27}{Versie}
+\setinterfacemessage{systems}{26}{Registers}
+\setinterfacemessage{systems}{25}{Verwijzingen}
+\setinterfacemessage{systems}{24}{Plaatsblokken}
+\setinterfacemessage{systems}{1}{laden hulpfile uitgesteld (typemode)}
+\setinterfacemessage{systems}{23}{-- gearrangeerd op --}
+\setinterfacemessage{systems}{22}{gebruik een goede hulpfile}
+\setinterfacemessage{systems}{2}{-- geladen}
+\setinterfacemessage{systems}{19}{betekenissen (synoniemen) van -- geladen}
+\setinterfacemessage{systems}{18}{synoniem -- -- bestaat niet}
+\setinterfacemessage{systems}{7}{module -- reeds geladen}
+\setinterfacemessage{systems}{6}{geen module -- gevonden}
+\setinterfacemessage{systems}{14}{geforceerde paginaovergang in lijst voor --}
+\setinterfacemessage{systems}{15}{wegschrijven buffer --}
+\setinterfacemessage{systems}{16}{inlezen buffer --}
+\setinterfacemessage{systems}{17}{verbatim inlezen buffer --}
+\setinterfacemessage{systems}{13}{markering -- gedefinieerd --}
+\setinterfacemessage{systems}{12}{de hulpfile is niet gesorteerd, gebruik texutil}
+\setinterfacemessage{systems}{11}{aanmaken basale hulpfile}
+\setinterfacemessage{systems}{10}{gebruik geen em in --}
+\setinterfacemessage{floatblocks}{1}{-- hernummerd / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- verplaatst}
+\setinterfacemessage{floatblocks}{2}{-- bewaard}
+\setinterfacemessage{floatblocks}{5}{volgorde aangepast}
+\setinterfacemessage{floatblocks}{4}{-- geplaatst}
+\setinterfacemessage{floatblocks}{7}{maximaal -- onder}
+\setinterfacemessage{floatblocks}{6}{maximaal -- boven}
+\setinterfacemessage{floatblocks}{9}{volgorde verstoord}
+\setinterfacemessage{floatblocks}{8}{minder dan -- regels}
+\setinterfacemessage{floatblocks}{title}{plaatsblokken}
+\setinterfacemessage{floatblocks}{13}{er is niets te splitsen}
+\setinterfacemessage{floatblocks}{12}{niet gedefinieerd}
+\setinterfacemessage{floatblocks}{11}{geen blok opgegeven}
+\setinterfacemessage{floatblocks}{10}{-- begrensd}
+\setinterfacemessage{interactions}{1}{aspect ratio -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{niet actief}
+\setinterfacemessage{interactions}{2}{actief}
+\setinterfacemessage{interactions}{5}{onbekend attachment --}
+\setinterfacemessage{interactions}{4}{geen paginasynchronisatie (--) in hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- bestaat niet}
+\setinterfacemessage{interactions}{title}{interactie}
+\setinterfacemessage{interactions}{21}{-- code tussengevoegd}
+\setinterfacemessage{structures}{1}{begin van sectieblok --}
+\setinterfacemessage{structures}{title}{structuur}
+\setinterfacemessage{structures}{2}{eind van sectieblok --}
+\setinterfacemessage{linguals}{1}{afbreekpatronen -- voor -- geladen (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{afbreekdefinities -- voor -- geladen (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{geen afbreekpatronen -- voor -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{afbreekpatronen voor -- niet geladen}
+\setinterfacemessage{linguals}{4}{geen afbreekdefinities -- voor -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{taal specifieke opties [--] introduceren een skip van --}
+\setinterfacemessage{linguals}{6}{taal -- is niet gedefinieerd}
+\setinterfacemessage{linguals}{9}{taal -- is actief}
+\setinterfacemessage{linguals}{8}{taal specifieke opties [--] naadloos toegevoegd}
+\setinterfacemessage{linguals}{title}{taal}
+\setinterfacemessage{linguals}{10}{patronen --geladen}
+\setinterfacemessage{regimes}{1}{regime --}
+\setinterfacemessage{regimes}{3}{onbekend regime --}
+\setinterfacemessage{regimes}{2}{regime -- wordt geladen}
+\setinterfacemessage{regimes}{title}{regime}
+\setinterfacemessage{filters}{1}{filter -- wordt geladen}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{onbekend filter --}
+\setinterfacemessage{verbatims}{1}{file -- bestaat niet}
+\setinterfacemessage{verbatims}{title}{typen}
+\setinterfacemessage{encodings}{1}{codering --}
+\setinterfacemessage{encodings}{3}{onbekende codering --}
+\setinterfacemessage{encodings}{2}{codering -- wordt geladen}
+\setinterfacemessage{encodings}{title}{encoding}
+\setinterfacemessage{columns}{1}{maximaal -- kolommen}
+\setinterfacemessage{columns}{3}{probleempje, probeer [balanceren=nee]}
+\setinterfacemessage{columns}{2}{gebruik eventueel \string\filbreak}
+\setinterfacemessage{columns}{5}{plaatsblok onder nog niet mogelijk}
+\setinterfacemessage{columns}{4}{plaatsblok boven nog niet mogelijk}
+\setinterfacemessage{columns}{7}{balanceren afgebroken na 100 stappen}
+\setinterfacemessage{columns}{6}{-- plaatsblok(en) opgeschort}
+\setinterfacemessage{columns}{9}{uitlijnen controleren!}
+\setinterfacemessage{columns}{8}{gebalanceerd in -- stap(pen)}
+\setinterfacemessage{columns}{title}{kolommen}
+\setinterfacemessage{columns}{13}{breed figuur geplaatst boven kolommen}
+\setinterfacemessage{columns}{12}{plaatsblok verplaatst naar volgende kolom / --}
+\setinterfacemessage{columns}{11}{plaatsblok te breed voor kolom}
+\setinterfacemessage{columns}{10}{(minder dan) 1 regel over}
+\setinterfacemessage{textblocks}{1}{nieuwe versie, tweede run nodig}
+\setinterfacemessage{textblocks}{3}{inlezen blokken uit --}
+\setinterfacemessage{textblocks}{2}{wegschrijven blokken naar --}
+\setinterfacemessage{textblocks}{5}{-- niet verborgen}
+\setinterfacemessage{textblocks}{4}{er is een tweede run nodig}
+\setinterfacemessage{textblocks}{7}{-- verborgen}
+\setinterfacemessage{textblocks}{6}{-- verborgen en verwerkt}
+\setinterfacemessage{textblocks}{9}{-- niet gehandhaafd}
+\setinterfacemessage{textblocks}{8}{-- gehandhaafd}
+\setinterfacemessage{textblocks}{title}{tekstblokken}
+\setinterfacemessage{textblocks}{12}{-- overgeslagen}
+\setinterfacemessage{textblocks}{11}{-- geladen en geplaatst}
+\setinterfacemessage{textblocks}{10}{-- geladen en verwerkt}
+\setinterfacemessage{symbols}{1}{symboolset -- wordt geladen}
+\setinterfacemessage{symbols}{title}{symbolen}
+\setinterfacemessage{versions}{1}{er mankeert een @+}
+\setinterfacemessage{versions}{3}{geselecteerde pagina's: --}
+\setinterfacemessage{versions}{2}{markeren pagina's}
+\setinterfacemessage{versions}{title}{versie}
+\setinterfacemessage{specials}{1}{-- geladen}
+\setinterfacemessage{specials}{3}{-- gereset}
+\setinterfacemessage{specials}{2}{verdere nesting is niet toegestaan --}
+\setinterfacemessage{specials}{5}{definitiefile -- wordt geladen}
+\setinterfacemessage{specials}{4}{commando -- bestaat niet}
+\setinterfacemessage{specials}{7}{onbekende driver --}
+\setinterfacemessage{specials}{6}{nesting is niet toegestaan}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{script set -- wordt geladen}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{onbekende preamble --}
+\setinterfacemessage{fonts}{1}{codering --}
+\setinterfacemessage{fonts}{3}{onbekende variant --}
+\setinterfacemessage{fonts}{2}{variant -- wordt geladen}
+\setinterfacemessage{fonts}{5}{stijl -- is niet gedefinieerd}
+\setinterfacemessage{fonts}{4}{korps -- is niet gedefinieerd}
+\setinterfacemessage{fonts}{7}{onbekend formaat --}
+\setinterfacemessage{fonts}{6}{-- wordt geladen}
+\setinterfacemessage{fonts}{14}{korps -- is gedefinieerd (kan beter globaal plaatsvinden)}
+\setinterfacemessage{fonts}{8}{stijl -- gedefinieerd}
+\setinterfacemessage{fonts}{title}{korps}
+\setinterfacemessage{fonts}{10}{onbekende font file --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{globaal bestand --}
+\setinterfacemessage{databases}{2}{lokaal bestand --}
+\setinterfacemessage{databases}{4}{onbekend bestand --}
+\setinterfacemessage{databases}{title}{database}
+\setinterfacemessage{colors}{1}{systeem -- is globaal actief}
+\setinterfacemessage{colors}{3}{-- is niet gedefinieerd --}
+\setinterfacemessage{colors}{2}{systeem -- is lokaal actief}
+\setinterfacemessage{colors}{5}{onbekend systeem --}
+\setinterfacemessage{colors}{4}{systeem -- wordt geladen}
+\setinterfacemessage{colors}{7}{palet -- is niet beschikbaar}
+\setinterfacemessage{colors}{6}{palet -- is beschikbaar}
+\setinterfacemessage{colors}{9}{-- kleurruimte wordt niet ondersteund}
+\setinterfacemessage{colors}{8}{specificatie -- bij -- wordt zwart}
+\setinterfacemessage{colors}{title}{kleur}
+\setinterfacemessage{colors}{12}{-- is geregistreerd}
+\setinterfacemessage{colors}{11}{kleur wordt vertaald in grijs}
+\setinterfacemessage{colors}{10}{-- kleurruimte wordt ondersteund}
+\setinterfacemessage{layouts}{1}{teksthoogte aangepast met -- op pagina --}
+\setinterfacemessage{layouts}{3}{-- maal tekst plaatsen uitstellen}
+\setinterfacemessage{layouts}{2}{-- maal uitgestelde tekst tussengevoegd}
+\setinterfacemessage{layouts}{5}{margeblokken inactief}
+\setinterfacemessage{layouts}{4}{margeblokken actief}
+\setinterfacemessage{layouts}{7}{beeldmerken berekenen}
+\setinterfacemessage{layouts}{6}{subpagina reeks -- verwerkt (aantal --)}
+\setinterfacemessage{layouts}{9}{momenteel maximaal -- niveaus in opsommingen}
+\setinterfacemessage{layouts}{8}{achtergronden berekenen}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{interlinie -- niet toegestaan in gridmode}
+\setinterfacemessage{layouts}{10}{-- en -- tellen niet op tot 1.0}
+\setinterfacemessage{check}{1}{'=' ontbreekt of zonder {} na '--' in regel --}
+\setinterfacemessage{check}{3}{-- -- vervangt een macro, gebruik HOOFDLETTERS!}
+\setinterfacemessage{check}{2}{-- argument(en) verwacht in regel --}
+\setinterfacemessage{check}{title}{controle}
+\setinterfacemessage{metapost}{1}{metapost bibliotheek -- wordt geladen}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{file synoniem -- is al in gebruik voor --}
+\setinterfacemessage{files}{title}{files}
+\setinterfacemessage{figures}{1}{figuur -- is niet te vinden}
+\setinterfacemessage{figures}{3}{maten van -- worden extern vastgesteld}
+\setinterfacemessage{figures}{2}{figuur -- wordt niet preset}
+\setinterfacemessage{figures}{5}{maten van -- zijn onbekend}
+\setinterfacemessage{figures}{4}{maten van -- geladen uit figuurfile zelf}
+\setinterfacemessage{figures}{6}{maten van -- berekend door rlxtools}
+\setinterfacemessage{figures}{8}{figuurobject -- wordt opnieuw gebruikt}
+\setinterfacemessage{figures}{title}{figuren}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mno.tex b/tex/context/base/mult-mno.tex
new file mode 100644
index 000000000..676c2cb2c
--- /dev/null
+++ b/tex/context/base/mult-mno.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{ukjent referanse --}
+\setinterfacemessage{references}{3}{ukjent referansetype --}
+\setinterfacemessage{references}{2}{duplikat referanse -- pø side --}
+\setinterfacemessage{references}{4}{ulovlig referanse --}
+\setinterfacemessage{references}{title}{referanser}
+\setinterfacemessage{references}{30}{ukjent objekt --}
+\setinterfacemessage{references}{31}{duplikat objekt --}
+\setinterfacemessage{references}{21}{dokument -- er lest inn}
+\setinterfacemessage{references}{22}{dokument -- er ikke interaktivt}
+\setinterfacemessage{references}{23}{obskur referanse -- (Prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{system}
+\setinterfacemessage{systems}{41}{ekstern fil -- i gruppe -- eksisterer ikke}
+\setinterfacemessage{systems}{9}{-- ikke funnet/behandlet}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{ny versjon av hjelpefil, andre gjennomkjøring nødvendig}
+\setinterfacemessage{systems}{21}{hjelpefila er ikke lest inn}
+\setinterfacemessage{systems}{20}{betydning (sorterer) av -- er lest inn}
+\setinterfacemessage{systems}{5}{makroene i modul -- er lest inn}
+\setinterfacemessage{systems}{4}{kommando -- er allerede definert}
+\setinterfacemessage{systems}{27}{Versjon}
+\setinterfacemessage{systems}{26}{Registere}
+\setinterfacemessage{systems}{25}{Referanser}
+\setinterfacemessage{systems}{24}{Flytblokker}
+\setinterfacemessage{systems}{1}{innlesning av hjelpefila utsatt (typemode)}
+\setinterfacemessage{systems}{23}{-- arrangert på --}
+\setinterfacemessage{systems}{22}{bruk en gyldig hjelpefil}
+\setinterfacemessage{systems}{2}{-- er lest inn}
+\setinterfacemessage{systems}{19}{betydning (synonymer) av -- er lest inn}
+\setinterfacemessage{systems}{18}{synonym -- -- eksisterer ikke}
+\setinterfacemessage{systems}{7}{makroene i modul -- er allerede lest inn}
+\setinterfacemessage{systems}{6}{ingen makroer funnet i modul ---}
+\setinterfacemessage{systems}{14}{tvunget sideskift i liste ved --}
+\setinterfacemessage{systems}{15}{lagrer Buffer --}
+\setinterfacemessage{systems}{16}{tegnsetter buffer --}
+\setinterfacemessage{systems}{17}{tegnsetter verbatim-buffer --}
+\setinterfacemessage{systems}{13}{markering -- definert --}
+\setinterfacemessage{systems}{12}{hjelpefila er ikke sortert, bruk texutil}
+\setinterfacemessage{systems}{11}{lager enkel hjelpefil}
+\setinterfacemessage{systems}{10}{ikke bruk em i --}
+\setinterfacemessage{floatblocks}{1}{-- renummerert / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- flyttet}
+\setinterfacemessage{floatblocks}{2}{-- lagret}
+\setinterfacemessage{floatblocks}{5}{rekkefølge tilpasset}
+\setinterfacemessage{floatblocks}{4}{-- plassert}
+\setinterfacemessage{floatblocks}{7}{maksimalt -- flytblokker nederst}
+\setinterfacemessage{floatblocks}{6}{maksimalt -- flytblokker øverst}
+\setinterfacemessage{floatblocks}{9}{rekkefølge endret}
+\setinterfacemessage{floatblocks}{8}{mindre enn -- linjer}
+\setinterfacemessage{floatblocks}{title}{flytblokker}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{udefinert}
+\setinterfacemessage{floatblocks}{11}{ingen blokk oppgitt}
+\setinterfacemessage{floatblocks}{10}{-- begrenset}
+\setinterfacemessage{interactions}{1}{forholdstall -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{inaktiv}
+\setinterfacemessage{interactions}{2}{aktiv}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{ingen sidesynkronisering (--) i hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interaksjon}
+\setinterfacemessage{interactions}{21}{-- kode satt inn / tilføyd}
+\setinterfacemessage{structures}{1}{starten av blokk -- (seksjon)}
+\setinterfacemessage{structures}{title}{struktur}
+\setinterfacemessage{structures}{2}{slutten av blokk -- (seksjon)}
+\setinterfacemessage{linguals}{1}{orddelingsmønster -- for -- er lest inn (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{orddelingsdefinisjon -- for -- er lest inn (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{ingen orddelingsmønster -- for -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{orddelingsmønster for -- er ikke lest inn}
+\setinterfacemessage{linguals}{4}{ingen orddelingsdefinisjon -- for -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{spràk spesifikk opsjon [--] introduserer et -- hopp}
+\setinterfacemessage{linguals}{6}{spràk -- er udefinert}
+\setinterfacemessage{linguals}{9}{spràk -- er aktivt}
+\setinterfacemessage{linguals}{8}{spràk spesifikk opsjon [--] problemfritt tilføyd}
+\setinterfacemessage{linguals}{title}{sprøk}
+\setinterfacemessage{linguals}{10}{orddelingsmønster -- er lest inn}
+\setinterfacemessage{regimes}{1}{koding --}
+\setinterfacemessage{regimes}{3}{ukjent koding --}
+\setinterfacemessage{regimes}{2}{koding -- er lest inn}
+\setinterfacemessage{regimes}{title}{koding}
+\setinterfacemessage{filters}{1}{filter -- is loaded}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{fil -- eksisterer ikke}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{koding --}
+\setinterfacemessage{encodings}{3}{ukjent koding --}
+\setinterfacemessage{encodings}{2}{koding -- er lest inn}
+\setinterfacemessage{encodings}{title}{koding}
+\setinterfacemessage{columns}{1}{maksimalt -- kolonner}
+\setinterfacemessage{columns}{3}{problemer, slår av balansering}
+\setinterfacemessage{columns}{2}{bruk \string\filbreak\space som et alternativ}
+\setinterfacemessage{columns}{5}{flytblokker nedert er ikke støttet enda}
+\setinterfacemessage{columns}{4}{flytblokker øverst er ikke støttet enda}
+\setinterfacemessage{columns}{7}{balansering avbrutt etter 100 iterasjoner}
+\setinterfacemessage{columns}{6}{-- flytblokk forskjøvet}
+\setinterfacemessage{columns}{9}{kontroller tekstlayout!}
+\setinterfacemessage{columns}{8}{balansert etter -- iterasjoner}
+\setinterfacemessage{columns}{title}{kolonner}
+\setinterfacemessage{columns}{13}{bred flytblokk forksjøvet til toppen av kolonnene}
+\setinterfacemessage{columns}{12}{flytblokk forskjøvet til neste kolonne / --}
+\setinterfacemessage{columns}{11}{flytblokk for bredt for kolonna}
+\setinterfacemessage{columns}{10}{(mindre enn) 1 linje igjen}
+\setinterfacemessage{textblocks}{1}{ny versjon, andre gjennomkjøring nødvendig}
+\setinterfacemessage{textblocks}{3}{leser blokker fra --}
+\setinterfacemessage{textblocks}{2}{skriver blokker til --}
+\setinterfacemessage{textblocks}{5}{-- ikke skjult}
+\setinterfacemessage{textblocks}{4}{andre gjennomkjøring nødvendig}
+\setinterfacemessage{textblocks}{7}{-- skjult}
+\setinterfacemessage{textblocks}{6}{-- skjult og behandlet}
+\setinterfacemessage{textblocks}{9}{-- ikke tegnsatt}
+\setinterfacemessage{textblocks}{8}{-- tegnsatt}
+\setinterfacemessage{textblocks}{title}{tekstblokker}
+\setinterfacemessage{textblocks}{12}{-- utelatt}
+\setinterfacemessage{textblocks}{11}{-- lest inn og tegnsatt}
+\setinterfacemessage{textblocks}{10}{-- lest inn og behandlet}
+\setinterfacemessage{symbols}{1}{leser inn symbolsett --}
+\setinterfacemessage{symbols}{title}{symboler}
+\setinterfacemessage{versions}{1}{manglende @+}
+\setinterfacemessage{versions}{3}{valgte sider: --}
+\setinterfacemessage{versions}{2}{markerer sider}
+\setinterfacemessage{versions}{title}{versjon}
+\setinterfacemessage{specials}{1}{-- er lest inn}
+\setinterfacemessage{specials}{3}{-- er tilbakestilt}
+\setinterfacemessage{specials}{2}{dypere 'nesting' er ikke tillatt --}
+\setinterfacemessage{specials}{5}{leser inn definisjonsfil for --}
+\setinterfacemessage{specials}{4}{kommando -- eksisterer ikke}
+\setinterfacemessage{specials}{7}{ukjent driver --}
+\setinterfacemessage{specials}{6}{'nesting' er ikke tillatt}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{leser inn scriptsett --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{ukjent 'preamble' --}
+\setinterfacemessage{fonts}{1}{koding --}
+\setinterfacemessage{fonts}{3}{ukjent variant --}
+\setinterfacemessage{fonts}{2}{variant -- er lest inn}
+\setinterfacemessage{fonts}{5}{stil -- er ikke definert}
+\setinterfacemessage{fonts}{4}{hovedfont -- er ikke definert}
+\setinterfacemessage{fonts}{7}{ukjent format --}
+\setinterfacemessage{fonts}{6}{-- er lest inn}
+\setinterfacemessage{fonts}{14}{bodyfont -- is defined (can better be done global)}
+\setinterfacemessage{fonts}{8}{stil -- definert}
+\setinterfacemessage{fonts}{title}{hovedfont}
+\setinterfacemessage{fonts}{10}{ukjent fontfil --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{global fil --}
+\setinterfacemessage{databases}{2}{lokal fil --}
+\setinterfacemessage{databases}{4}{ukjent fil --}
+\setinterfacemessage{databases}{title}{databaser}
+\setinterfacemessage{colors}{1}{system -- er aktivert globalt}
+\setinterfacemessage{colors}{3}{-- er udefinert --}
+\setinterfacemessage{colors}{2}{system -- er aktivert lokalt}
+\setinterfacemessage{colors}{5}{ukjent system --}
+\setinterfacemessage{colors}{4}{system -- er lest inn}
+\setinterfacemessage{colors}{7}{palett -- er ikke tilgjengelig}
+\setinterfacemessage{colors}{6}{palett -- er tilgjengelig}
+\setinterfacemessage{colors}{9}{-- fargerom er ikke støttet}
+\setinterfacemessage{colors}{8}{spesifikasjon -- for farge -- gir kun svart}
+\setinterfacemessage{colors}{title}{farge}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{fargen vil bli vist som grø}
+\setinterfacemessage{colors}{10}{-- fargerom er støttet}
+\setinterfacemessage{layouts}{1}{teksthøyde tilpasset med -- på side --}
+\setinterfacemessage{layouts}{3}{-- ganger tekst forskjøvet}
+\setinterfacemessage{layouts}{2}{-- ganger forskjøvet tekst plassert}
+\setinterfacemessage{layouts}{5}{margblokker inaktive}
+\setinterfacemessage{layouts}{4}{margblokker aktive}
+\setinterfacemessage{layouts}{7}{beregner plass for logo}
+\setinterfacemessage{layouts}{6}{delside sett -- behandlet (størrelse --)}
+\setinterfacemessage{layouts}{9}{for øyeblikket maksimalt -- nivåer i opplisting}
+\setinterfacemessage{layouts}{8}{beregner bakgrunn}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{mellomrom -- ikke tillatt i gridmodus}
+\setinterfacemessage{layouts}{10}{-- og -- er ikke 1.0 til sammen}
+\setinterfacemessage{check}{1}{manglende '=' etter '--' i linje --}
+\setinterfacemessage{check}{3}{-- -- overskygger en makro, bruk STORE BOKSTAVER!}
+\setinterfacemessage{check}{2}{-- argument forventet i linje --}
+\setinterfacemessage{check}{title}{kontroll}
+\setinterfacemessage{metapost}{1}{metapost bibliotek -- blir lest inn}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{filesynonym -- er allerede brukt for --}
+\setinterfacemessage{files}{title}{filer}
+\setinterfacemessage{figures}{1}{figure -- can not be found}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{figure -- is not preset}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimensions of -- loaded from figurefile itself}
+\setinterfacemessage{figures}{6}{dimensions of -- calculated by rlxtools}
+\setinterfacemessage{figures}{8}{figureobject -- is reused}
+\setinterfacemessage{figures}{title}{figures}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mpe.tex b/tex/context/base/mult-mpe.tex
new file mode 100644
index 000000000..8335d2911
--- /dev/null
+++ b/tex/context/base/mult-mpe.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{unknown reference --}
+\setinterfacemessage{references}{3}{unknown reference type --}
+\setinterfacemessage{references}{2}{duplicate reference -- on page --}
+\setinterfacemessage{references}{4}{illegal reference --}
+\setinterfacemessage{references}{title}{references}
+\setinterfacemessage{references}{30}{unknown object --}
+\setinterfacemessage{references}{31}{duplicate object --}
+\setinterfacemessage{references}{21}{document -- loaded}
+\setinterfacemessage{references}{22}{document -- is not interactive}
+\setinterfacemessage{references}{23}{obscure reference -- (prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{system}
+\setinterfacemessage{systems}{41}{external file -- in group -- does not exist}
+\setinterfacemessage{systems}{9}{-- not found/processed}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{new version of utility file, second pass needed}
+\setinterfacemessage{systems}{21}{no utility data is loaded}
+\setinterfacemessage{systems}{20}{meaning (sorts) of -- loaded}
+\setinterfacemessage{systems}{5}{module -- loaded}
+\setinterfacemessage{systems}{4}{command -- is already defined}
+\setinterfacemessage{systems}{27}{Version}
+\setinterfacemessage{systems}{26}{Registers}
+\setinterfacemessage{systems}{25}{References}
+\setinterfacemessage{systems}{24}{Floatblocks}
+\setinterfacemessage{systems}{1}{loading utility-file postponed (typemode)}
+\setinterfacemessage{systems}{23}{-- arranged at --}
+\setinterfacemessage{systems}{22}{use a valid utilityfile}
+\setinterfacemessage{systems}{2}{-- loaded}
+\setinterfacemessage{systems}{19}{meaning (synonyms) of -- loaded}
+\setinterfacemessage{systems}{18}{synonym -- -- does not exist}
+\setinterfacemessage{systems}{7}{module -- already loaded}
+\setinterfacemessage{systems}{6}{module -- not found}
+\setinterfacemessage{systems}{14}{forced newpage in list at --}
+\setinterfacemessage{systems}{15}{saving buffer --}
+\setinterfacemessage{systems}{16}{typesetting buffer --}
+\setinterfacemessage{systems}{17}{typesetting verbatim buffer --}
+\setinterfacemessage{systems}{13}{mark -- defined --}
+\setinterfacemessage{systems}{12}{the utility-file is not sorted, use texutil}
+\setinterfacemessage{systems}{11}{building simple util}
+\setinterfacemessage{systems}{10}{don't use em in --}
+\setinterfacemessage{floatblocks}{1}{-- renumbered / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- moved}
+\setinterfacemessage{floatblocks}{2}{-- saved}
+\setinterfacemessage{floatblocks}{5}{order adapted}
+\setinterfacemessage{floatblocks}{4}{-- placed}
+\setinterfacemessage{floatblocks}{7}{n of bottom floats limited to --}
+\setinterfacemessage{floatblocks}{6}{n of top floats limited to --}
+\setinterfacemessage{floatblocks}{9}{order disturbed}
+\setinterfacemessage{floatblocks}{8}{less than -- lines}
+\setinterfacemessage{floatblocks}{title}{floatblocks}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{undefined}
+\setinterfacemessage{floatblocks}{11}{no block given}
+\setinterfacemessage{floatblocks}{10}{-- limited}
+\setinterfacemessage{interactions}{1}{aspect ratio -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{inactive}
+\setinterfacemessage{interactions}{2}{active}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{no pagesynchronisation (--) in hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interaction}
+\setinterfacemessage{interactions}{21}{-- code inserted}
+\setinterfacemessage{structures}{1}{begin of sectionblock --}
+\setinterfacemessage{structures}{title}{structure}
+\setinterfacemessage{structures}{2}{end of sectionblock --}
+\setinterfacemessage{linguals}{1}{patterns -- for -- loaded (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{hyphenations -- for -- loaded (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{no patterns -- for -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{patterns for -- not loaded}
+\setinterfacemessage{linguals}{4}{no hyphenations -- for -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{language specific options [--] introduce a -- skip}
+\setinterfacemessage{linguals}{6}{language -- is undefined}
+\setinterfacemessage{linguals}{9}{language -- is active}
+\setinterfacemessage{linguals}{8}{language specific options [--] seamless appended}
+\setinterfacemessage{linguals}{title}{language}
+\setinterfacemessage{linguals}{10}{patterns --loaded}
+\setinterfacemessage{regimes}{1}{regime --}
+\setinterfacemessage{regimes}{3}{unknown regime --}
+\setinterfacemessage{regimes}{2}{regime -- is loaded}
+\setinterfacemessage{regimes}{title}{regime}
+\setinterfacemessage{filters}{1}{filter -- is loaded}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{file -- does not exist}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{coding --}
+\setinterfacemessage{encodings}{3}{unknown coding --}
+\setinterfacemessage{encodings}{2}{coding -- is loaded}
+\setinterfacemessage{encodings}{title}{encoding}
+\setinterfacemessage{columns}{1}{only -- columns possible}
+\setinterfacemessage{columns}{3}{problems, disable balancing}
+\setinterfacemessage{columns}{2}{use \string\filbreak\space as alternative}
+\setinterfacemessage{columns}{5}{bottom float not yet supported}
+\setinterfacemessage{columns}{4}{top float not yet supported}
+\setinterfacemessage{columns}{7}{balancing aborted after 100 steps}
+\setinterfacemessage{columns}{6}{-- float(s) postponed}
+\setinterfacemessage{columns}{9}{check raggedness}
+\setinterfacemessage{columns}{8}{balanced in -- step(s)}
+\setinterfacemessage{columns}{title}{columns}
+\setinterfacemessage{columns}{13}{wide float moved to top of columns}
+\setinterfacemessage{columns}{12}{float moved to next column / --}
+\setinterfacemessage{columns}{11}{float too wide for column}
+\setinterfacemessage{columns}{10}{(less than) 1 line left}
+\setinterfacemessage{textblocks}{1}{new version, second pass needed}
+\setinterfacemessage{textblocks}{3}{reading blocks from --}
+\setinterfacemessage{textblocks}{2}{writing blocks to --}
+\setinterfacemessage{textblocks}{5}{-- not hidden}
+\setinterfacemessage{textblocks}{4}{second pass needed}
+\setinterfacemessage{textblocks}{7}{-- hidden}
+\setinterfacemessage{textblocks}{6}{-- hidden and processed}
+\setinterfacemessage{textblocks}{9}{-- not typeset}
+\setinterfacemessage{textblocks}{8}{-- typeset}
+\setinterfacemessage{textblocks}{title}{textblocks}
+\setinterfacemessage{textblocks}{12}{-- skipped}
+\setinterfacemessage{textblocks}{11}{-- loaded and typeset}
+\setinterfacemessage{textblocks}{10}{-- loaded and processed}
+\setinterfacemessage{symbols}{1}{loading symbolset --}
+\setinterfacemessage{symbols}{title}{symbols}
+\setinterfacemessage{versions}{1}{missing @+}
+\setinterfacemessage{versions}{3}{selected pages: --}
+\setinterfacemessage{versions}{2}{marking pages}
+\setinterfacemessage{versions}{title}{version}
+\setinterfacemessage{specials}{1}{-- loaded}
+\setinterfacemessage{specials}{3}{-- is reset}
+\setinterfacemessage{specials}{2}{no deeper nesting is permitted --}
+\setinterfacemessage{specials}{5}{loading definition file --}
+\setinterfacemessage{specials}{4}{command -- does not exist}
+\setinterfacemessage{specials}{7}{unknown driver --}
+\setinterfacemessage{specials}{6}{nesting is not permitted}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{loading script set --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{unknown preamble --}
+\setinterfacemessage{fonts}{1}{coding --}
+\setinterfacemessage{fonts}{3}{unknown variant --}
+\setinterfacemessage{fonts}{2}{variant -- is loaded}
+\setinterfacemessage{fonts}{5}{style -- is not defined}
+\setinterfacemessage{fonts}{4}{bodyfont -- is not defined}
+\setinterfacemessage{fonts}{7}{unknown format --}
+\setinterfacemessage{fonts}{6}{-- is loaded}
+\setinterfacemessage{fonts}{14}{bodyfont -- is defined (can better be done global)}
+\setinterfacemessage{fonts}{8}{style -- defined}
+\setinterfacemessage{fonts}{title}{bodyfont}
+\setinterfacemessage{fonts}{10}{unknown font file --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{global file --}
+\setinterfacemessage{databases}{2}{local file --}
+\setinterfacemessage{databases}{4}{unknown file --}
+\setinterfacemessage{databases}{title}{databases}
+\setinterfacemessage{colors}{1}{system -- is global activated}
+\setinterfacemessage{colors}{3}{-- is not defined --}
+\setinterfacemessage{colors}{2}{system -- is local activated}
+\setinterfacemessage{colors}{5}{unknown system --}
+\setinterfacemessage{colors}{4}{system -- is loaded}
+\setinterfacemessage{colors}{7}{palette -- is not available}
+\setinterfacemessage{colors}{6}{palette -- is available}
+\setinterfacemessage{colors}{9}{-- color space is not supported}
+\setinterfacemessage{colors}{8}{specification -- at color -- becomes black}
+\setinterfacemessage{colors}{title}{color}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{color is converted to gray}
+\setinterfacemessage{colors}{10}{-- color space is supported}
+\setinterfacemessage{layouts}{1}{textheight adapted with -- at page --}
+\setinterfacemessage{layouts}{3}{-- times text postponed}
+\setinterfacemessage{layouts}{2}{-- times postponed text placed}
+\setinterfacemessage{layouts}{5}{marginblocks inactive}
+\setinterfacemessage{layouts}{4}{marginblocks active}
+\setinterfacemessage{layouts}{7}{calculating logospace}
+\setinterfacemessage{layouts}{6}{subpage set -- processed (size --)}
+\setinterfacemessage{layouts}{9}{currently no more than -- levels in itemizations}
+\setinterfacemessage{layouts}{8}{calculating backgrounds}
+\setinterfacemessage{layouts}{title}{layout}
+\setinterfacemessage{layouts}{11}{spacing -- not permitted in gridmode}
+\setinterfacemessage{layouts}{10}{-- and -- don't add up to 1.0}
+\setinterfacemessage{check}{1}{missing or ungrouped '=' after '--' in line --}
+\setinterfacemessage{check}{3}{-- -- replaces a macro, use CAPITALS!}
+\setinterfacemessage{check}{2}{-- argument(s) expected in line --}
+\setinterfacemessage{check}{title}{check}
+\setinterfacemessage{metapost}{1}{loading metapost library --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{file synonym -- is already used for --}
+\setinterfacemessage{files}{title}{files}
+\setinterfacemessage{figures}{1}{figure -- can not be found}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{figure -- is not preset}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimensions of -- loaded from figurefile itself}
+\setinterfacemessage{figures}{6}{dimensions of -- calculated by rlxtools}
+\setinterfacemessage{figures}{8}{figureobject -- is reused}
+\setinterfacemessage{figures}{title}{figures}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-mro.tex b/tex/context/base/mult-mro.tex
new file mode 100644
index 000000000..3f52fbc70
--- /dev/null
+++ b/tex/context/base/mult-mro.tex
@@ -0,0 +1,198 @@
+\setinterfacemessage{references}{1}{referinta necunoscuta --}
+\setinterfacemessage{references}{3}{tip necunoscut de referinta --}
+\setinterfacemessage{references}{2}{referinta duplicat -- la pagina --}
+\setinterfacemessage{references}{4}{referinta eronata --}
+\setinterfacemessage{references}{title}{referinte}
+\setinterfacemessage{references}{30}{obiect necunoscut --}
+\setinterfacemessage{references}{31}{obiect duplicat --}
+\setinterfacemessage{references}{21}{documentul -- este incarcat}
+\setinterfacemessage{references}{22}{documentul -- nu este interactiv}
+\setinterfacemessage{references}{23}{referinta obscura -- (prefix=--)}
+\setinterfacemessage{documents}{1}{sheet --}
+\setinterfacemessage{documents}{title}{sheets}
+\setinterfacemessage{documents}{2}{number --}
+\setinterfacemessage{handlings}{1}{font handling --}
+\setinterfacemessage{handlings}{3}{unknown font handling --}
+\setinterfacemessage{handlings}{2}{font handling -- is loaded}
+\setinterfacemessage{handlings}{title}{handling}
+\setinterfacemessage{systems}{title}{sistem}
+\setinterfacemessage{systems}{41}{fisierul extern -- din grupul -- nu exista}
+\setinterfacemessage{systems}{9}{-- nu este gasit/procesat}
+\setinterfacemessage{systems}{91}{papertray --}
+\setinterfacemessage{systems}{8}{o noua versiune de fisier utilitar, este necesara o noua trecere}
+\setinterfacemessage{systems}{21}{nici o data utilitara nu este incarcata}
+\setinterfacemessage{systems}{20}{intelesul (ordinea) pentru -- incarcat}
+\setinterfacemessage{systems}{5}{macro-urile din modulul -- s-au incarcat}
+\setinterfacemessage{systems}{4}{comanda -- este deja definita}
+\setinterfacemessage{systems}{27}{Versiune}
+\setinterfacemessage{systems}{26}{Registri}
+\setinterfacemessage{systems}{25}{Referinte}
+\setinterfacemessage{systems}{24}{Blocuri}
+\setinterfacemessage{systems}{1}{se incarca utilitarul-fisierul este amanat (typemode)}
+\setinterfacemessage{systems}{23}{-- aranjat la --}
+\setinterfacemessage{systems}{22}{folositi un fisier utilitar valid}
+\setinterfacemessage{systems}{2}{-- s-a incarcat}
+\setinterfacemessage{systems}{19}{intelesul (sinonimele) pentru -- incarcat}
+\setinterfacemessage{systems}{18}{sinonimul -- -- nu exista}
+\setinterfacemessage{systems}{7}{macro-urile din modulul -- s-au incarcat deja}
+\setinterfacemessage{systems}{6}{nu s-au gasit macro-uri in modulul --}
+\setinterfacemessage{systems}{14}{s-a fortat trecere pa pagina noua in lista la --}
+\setinterfacemessage{systems}{15}{buffer salvat --}
+\setinterfacemessage{systems}{16}{buffer-ul -- s-a cules}
+\setinterfacemessage{systems}{17}{se culege buffer-ul verbatim --}
+\setinterfacemessage{systems}{13}{marcajul -- definit --}
+\setinterfacemessage{systems}{12}{fisierul utilitar nu este sortat, folositi texutil}
+\setinterfacemessage{systems}{11}{se creeaza un utilitar simplu}
+\setinterfacemessage{systems}{10}{nu folositi em in --}
+\setinterfacemessage{floatblocks}{1}{-- renumerotat / -- => --}
+\setinterfacemessage{floatblocks}{3}{-- mutat}
+\setinterfacemessage{floatblocks}{2}{-- salvat}
+\setinterfacemessage{floatblocks}{5}{ordinea adaptata}
+\setinterfacemessage{floatblocks}{4}{-- plasat}
+\setinterfacemessage{floatblocks}{7}{nr. blocurilor de jos limitat la --}
+\setinterfacemessage{floatblocks}{6}{nr. cadrelor de sus limitat la --}
+\setinterfacemessage{floatblocks}{9}{ordinea deranjata}
+\setinterfacemessage{floatblocks}{8}{mai putin de -- linii}
+\setinterfacemessage{floatblocks}{title}{Blocuri}
+\setinterfacemessage{floatblocks}{13}{there is nothing to split}
+\setinterfacemessage{floatblocks}{12}{nedefinit}
+\setinterfacemessage{floatblocks}{11}{nu este dat nici un bloc}
+\setinterfacemessage{floatblocks}{10}{-- limitat}
+\setinterfacemessage{interactions}{1}{aspectul -- x -- (b x h)}
+\setinterfacemessage{interactions}{3}{inactiv}
+\setinterfacemessage{interactions}{2}{activ}
+\setinterfacemessage{interactions}{5}{unknown attachment --}
+\setinterfacemessage{interactions}{4}{nu exista sincronizare pt. pagini (--) in hmode}
+\setinterfacemessage{interactions}{6}{attachment file -- does not exist}
+\setinterfacemessage{interactions}{title}{interactiuni}
+\setinterfacemessage{interactions}{21}{-- cod inserat}
+\setinterfacemessage{structures}{1}{inceput de bloc sectiune --}
+\setinterfacemessage{structures}{title}{structuri}
+\setinterfacemessage{structures}{2}{sfarsit de bloc sectiune --}
+\setinterfacemessage{linguals}{1}{sablonul -- pentru -- s-a incarcat (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{3}{despartirea in silabe -- pentru -- s-a incarcat (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{2}{nu exista sabloane -- pentru -- (n=--,e=--,m=--) (--,--)}
+\setinterfacemessage{linguals}{5}{sabloanele pentru -- nu sunt incarcate}
+\setinterfacemessage{linguals}{4}{nu exista despartire in silabe -- pentru -- (n=--,e=--,m=--)}
+\setinterfacemessage{linguals}{7}{optiunile specifice ale limbii [--] introduc un spatiu --}
+\setinterfacemessage{linguals}{6}{limba -- nu este definita}
+\setinterfacemessage{linguals}{9}{limba -- este activa}
+\setinterfacemessage{linguals}{8}{optiunile specifice ale limbii [--] adaugate}
+\setinterfacemessage{linguals}{title}{limbi}
+\setinterfacemessage{linguals}{10}{sabloanele -- incarcate}
+\setinterfacemessage{regimes}{1}{codificarea --}
+\setinterfacemessage{regimes}{3}{codificarea -- este necunoscuta}
+\setinterfacemessage{regimes}{2}{codificarea -- este Encarcata}
+\setinterfacemessage{regimes}{title}{codificari}
+\setinterfacemessage{filters}{1}{filter -- is loaded}
+\setinterfacemessage{filters}{title}{filter}
+\setinterfacemessage{filters}{2}{unknown filter --}
+\setinterfacemessage{verbatims}{1}{fisierul -- nu exista}
+\setinterfacemessage{verbatims}{title}{verbatim}
+\setinterfacemessage{encodings}{1}{codificarea --}
+\setinterfacemessage{encodings}{3}{codificarea -- este necunoscuta}
+\setinterfacemessage{encodings}{2}{codificarea -- este Encarcata}
+\setinterfacemessage{encodings}{title}{codificari}
+\setinterfacemessage{columns}{1}{este posibil numai -- coloane}
+\setinterfacemessage{columns}{3}{probleme, se dezactiveaza alinierea}
+\setinterfacemessage{columns}{2}{folositi \string\filbreak\space ca alternativa}
+\setinterfacemessage{columns}{5}{cadrele bottom (bottom float) nu sunt inca suportate}
+\setinterfacemessage{columns}{4}{cadrele top (top float) nu sunt inca suportate}
+\setinterfacemessage{columns}{7}{alinierea este oprita dupa 100 de incercari}
+\setinterfacemessage{columns}{6}{-- blocurile sunt amanate}
+\setinterfacemessage{columns}{9}{verificat alinierea}
+\setinterfacemessage{columns}{8}{aliniat in -- pas(i)}
+\setinterfacemessage{columns}{title}{coloane}
+\setinterfacemessage{columns}{13}{blocul lat este mutat in partea de sus a coloanelor}
+\setinterfacemessage{columns}{12}{blocul este mutat pe urmatoarea coloana / --}
+\setinterfacemessage{columns}{11}{blocul este prea lat pentru coloana}
+\setinterfacemessage{columns}{10}{a mai ramas (mai putin de) 1 linie}
+\setinterfacemessage{textblocks}{1}{o noua versiune, este nevoie de inca o trecere}
+\setinterfacemessage{textblocks}{3}{se citesc blocurile din --}
+\setinterfacemessage{textblocks}{2}{se scriu blocurile in --}
+\setinterfacemessage{textblocks}{5}{-- nu este ascuns}
+\setinterfacemessage{textblocks}{4}{este nevoie de inca o trecere}
+\setinterfacemessage{textblocks}{7}{-- ascuns}
+\setinterfacemessage{textblocks}{6}{-- ascuns si procesat}
+\setinterfacemessage{textblocks}{9}{-- nu este cules}
+\setinterfacemessage{textblocks}{8}{-- cules}
+\setinterfacemessage{textblocks}{title}{blocuri de text}
+\setinterfacemessage{textblocks}{12}{-- sarit peste}
+\setinterfacemessage{textblocks}{11}{-- incarcat si cules}
+\setinterfacemessage{textblocks}{10}{-- incarcat si procesat}
+\setinterfacemessage{symbols}{1}{se incarca setul de simboluri --}
+\setinterfacemessage{symbols}{title}{simboluri}
+\setinterfacemessage{versions}{1}{lipseste @+}
+\setinterfacemessage{versions}{3}{pagini selectate: --}
+\setinterfacemessage{versions}{2}{pagini marcate}
+\setinterfacemessage{versions}{title}{versiuni}
+\setinterfacemessage{specials}{1}{-- incarcat}
+\setinterfacemessage{specials}{3}{-- s-a resetat}
+\setinterfacemessage{specials}{2}{nu este permis un nivel de imbricare mai mare --}
+\setinterfacemessage{specials}{5}{se incarca fisierul de definitii --}
+\setinterfacemessage{specials}{4}{comanda -- nu exista}
+\setinterfacemessage{specials}{7}{driver necunoscut --}
+\setinterfacemessage{specials}{6}{imbricarea nu este permisa}
+\setinterfacemessage{specials}{title}{specials}
+\setinterfacemessage{javascript}{1}{se incarca scriptul --}
+\setinterfacemessage{javascript}{title}{javascript}
+\setinterfacemessage{javascript}{2}{preambul necunoscut --}
+\setinterfacemessage{fonts}{1}{codificarea --}
+\setinterfacemessage{fonts}{3}{varianta necunoscuta --}
+\setinterfacemessage{fonts}{2}{varianta -- este incarcata}
+\setinterfacemessage{fonts}{5}{stilul -- nu este definit}
+\setinterfacemessage{fonts}{4}{corpul de litere -- nu este definit}
+\setinterfacemessage{fonts}{7}{format necunoscut --}
+\setinterfacemessage{fonts}{6}{-- este incarcat}
+\setinterfacemessage{fonts}{14}{bodyfont -- is defined (can better be done global)}
+\setinterfacemessage{fonts}{8}{stilul -- definit}
+\setinterfacemessage{fonts}{title}{corp de litere}
+\setinterfacemessage{fonts}{10}{fisier font necunoscut --}
+\setinterfacemessage{databases}{1}{--}
+\setinterfacemessage{databases}{3}{fisier global --}
+\setinterfacemessage{databases}{2}{fisier local --}
+\setinterfacemessage{databases}{4}{fisier necunoscut --}
+\setinterfacemessage{databases}{title}{baze de date}
+\setinterfacemessage{colors}{1}{sistem -- este activata global}
+\setinterfacemessage{colors}{3}{-- nu este definita --}
+\setinterfacemessage{colors}{2}{sistem -- este activata local}
+\setinterfacemessage{colors}{5}{sistem -- necunoscuta}
+\setinterfacemessage{colors}{4}{sistem -- este incarcata}
+\setinterfacemessage{colors}{7}{palette -- nu este disponibila}
+\setinterfacemessage{colors}{6}{paleta -- este disponibila}
+\setinterfacemessage{colors}{9}{spatiul de culoare -- nu este suportat}
+\setinterfacemessage{colors}{8}{specificatia -- la culoarea -- devine neagra}
+\setinterfacemessage{colors}{title}{culori}
+\setinterfacemessage{colors}{12}{-- is registered}
+\setinterfacemessage{colors}{11}{culoarea este convertita la gri}
+\setinterfacemessage{colors}{10}{spatiul de culoare -- este suportat}
+\setinterfacemessage{layouts}{1}{textheight adaptat cu -- la pagina --}
+\setinterfacemessage{layouts}{3}{textul amanat de -- ori}
+\setinterfacemessage{layouts}{2}{textul amanat de -- ori a fost plasat}
+\setinterfacemessage{layouts}{5}{blocuri marginale inactive}
+\setinterfacemessage{layouts}{4}{blocuri marginale active}
+\setinterfacemessage{layouts}{7}{se calculeaza spatiul pentru logo}
+\setinterfacemessage{layouts}{6}{setul -- de subpagini procesat (dimensiunea --)}
+\setinterfacemessage{layouts}{9}{acum nu se supota mai mult de -- nivele de adancime la iteratii}
+\setinterfacemessage{layouts}{8}{se calculeaza fundalurile}
+\setinterfacemessage{layouts}{title}{aranjamente}
+\setinterfacemessage{layouts}{11}{spatierea -- nu este permisa in gridmode}
+\setinterfacemessage{layouts}{10}{-- si -- nu se adauga pana la 1.0}
+\setinterfacemessage{check}{1}{lipseste '=' dupa '--' in linia --}
+\setinterfacemessage{check}{3}{-- -- inlocuieste un macro, folositi MAJUSCULE!}
+\setinterfacemessage{check}{2}{argumentul(ele) -- sunt asteptate in linia --}
+\setinterfacemessage{check}{title}{verificari}
+\setinterfacemessage{metapost}{1}{se incarca biblioteca metapost --}
+\setinterfacemessage{metapost}{title}{metapost}
+\setinterfacemessage{files}{1}{sinonimul fisierelor -- este folosit deja pentru --}
+\setinterfacemessage{files}{title}{fisiere}
+\setinterfacemessage{figures}{1}{figura -- nu poate fi gasita}
+\setinterfacemessage{figures}{3}{dimensions of -- are determined externally}
+\setinterfacemessage{figures}{2}{figura -- nu este presetata}
+\setinterfacemessage{figures}{5}{dimensions of -- are unknown}
+\setinterfacemessage{figures}{4}{dimensiunea figurii -- se incarca din fisierul insusi}
+\setinterfacemessage{figures}{6}{dimensiunea figurii -- este calculata de rlxtools}
+\setinterfacemessage{figures}{8}{obiectul figura -- este refolosit}
+\setinterfacemessage{figures}{title}{figuri}
+%
+\endinput
\ No newline at end of file
diff --git a/tex/context/base/mult-nl.tex b/tex/context/base/mult-nl.tex
index 827b8fd80..30f0b36e6 100644
--- a/tex/context/base/mult-nl.tex
+++ b/tex/context/base/mult-nl.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{na}
\setinterfacevariable{all}{alles}
\setinterfacevariable{always}{altijd}
+\setinterfacevariable{answerarea}{antwoordgebied}
\setinterfacevariable{appendices}{bijlagen}
\setinterfacevariable{appendix}{bijlage}
\setinterfacevariable{april}{april}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{linkshangend}
\setinterfacevariable{leftmargin}{linkermarge}
\setinterfacevariable{leftpage}{linkerpagina}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legenda}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{regel}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normaal}
\setinterfacevariable{nospacing}{geenspatiering}
\setinterfacevariable{not}{niet}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{niethangend}
\setinterfacevariable{nothyphenated}{nietafgebroken}
\setinterfacevariable{november}{november}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{rechtshangend}
\setinterfacevariable{rightmargin}{rechtermarge}
\setinterfacevariable{rightpage}{rechterpagina}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{romaan}
\setinterfacevariable{romannumerals}{romeins}
\setinterfacevariable{rotate}{roteer}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{subsubsubsubonderwerp}
\setinterfacevariable{subsubsubsubsubsection}{subsubsubsubsubparagraaf}
\setinterfacevariable{subsubsubsubsubsubject}{subsubsubsubsubonderwerp}
+\setinterfacevariable{subsubsubsubsubsubsection}{subsubsubsubsubsubparagraaf}
+\setinterfacevariable{subsubsubsubsubsubsubject}{subsubsubsubsubsubonderwerp}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{subsubsubsubsubsubsubparagraaf}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubonderwerp}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubparagraaf}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubonderwerp}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubsubparagraaf}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubsubonderwerp}
\setinterfacevariable{sunday}{zondag}
\setinterfacevariable{support}{support}
\setinterfacevariable{sym}{sym}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{korps}
\setinterfaceconstant{bookmark}{bookmark}
\setinterfaceconstant{bottom}{onder}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{onderafstand}
\setinterfaceconstant{bottomframe}{onderkader}
\setinterfaceconstant{bottomoffset}{onderoffset}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{component}
\setinterfaceconstant{compoundhyphen}{koppelteken}
\setinterfaceconstant{compress}{comprimeren}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{doorgaan}
\setinterfaceconstant{contrastcolor}{contrastkleur}
\setinterfaceconstant{controls}{sturing}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{veldlaag}
\setinterfaceconstant{fieldoffset}{veldoffset}
\setinterfaceconstant{file}{file}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusuit}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{hoogte}
\setinterfaceconstant{hfactor}{hfactor}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{hoffset}
\setinterfaceconstant{horoffset}{rugoffset}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{nummer}
\setinterfaceconstant{numbercolor}{nummerkleur}
\setinterfaceconstant{numbercommand}{nummercommando}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{nummerafstand}
\setinterfaceconstant{numbering}{nummeren}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{nummerscheider}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{nummerletter}
\setinterfaceconstant{numberwidth}{nummerbreedte}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{paginaovergangen}
\setinterfaceconstant{pagecolor}{paginakleur}
\setinterfaceconstant{pagecommand}{paginacommando}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{paginanummer}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{paginastatus}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{paginaletter}
\setinterfaceconstant{palet}{palet}
\setinterfaceconstant{paper}{papier}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{plaatsafsluiter}
\setinterfaceconstant{position}{positie}
\setinterfaceconstant{prefix}{prefix}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{preset}
\setinterfaceconstant{preview}{preview}
\setinterfaceconstant{previous}{vorige}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{reductie}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{verwijzing}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{refereren}
\setinterfaceconstant{regionin}{gebiedin}
\setinterfaceconstant{regionout}{gebieduit}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{lijndikte}
\setinterfaceconstant{samepage}{zelfdepagina}
\setinterfaceconstant{sample}{monster}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{schaal}
\setinterfaceconstant{scope}{scope}
\setinterfaceconstant{screen}{raster}
\setinterfaceconstant{section}{sectie}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{sectienummer}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{scheider}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{setups}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{ystap}
% definitions for interface elements for language nl
%
+\setinterfaceelement{answerlines}{antwoordregels}
+\setinterfaceelement{answerspace}{antwoordruimte}
\setinterfaceelement{begin}{beginvan}
\setinterfaceelement{complete}{volledige}
\setinterfaceelement{coupled}{gekoppelde}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{steltekstinhoudin}
\setinterfacecommand{settextvariable}{kentekstvariabeletoe}
\setinterfacecommand{setupalign}{steluitlijnenin}
+\setinterfacecommand{setupanswerarea}{stelantwoordgebiedin}
\setinterfacecommand{setuparranging}{stelarrangerenin}
\setinterfacecommand{setupbackground}{stelachtergrondin}
\setinterfacecommand{setupbackgrounds}{stelachtergrondenin}
diff --git a/tex/context/base/mult-ro.tex b/tex/context/base/mult-ro.tex
index 297a57be9..ed3cf7e22 100644
--- a/tex/context/base/mult-ro.tex
+++ b/tex/context/base/mult-ro.tex
@@ -68,6 +68,7 @@
\setinterfacevariable{after}{dupa}
\setinterfacevariable{all}{tot}
\setinterfacevariable{always}{totdeauna}
+\setinterfacevariable{answerarea}{answerarea}
\setinterfacevariable{appendices}{apendixuri}
\setinterfacevariable{appendix}{apendix}
\setinterfacevariable{april}{aprilie}
@@ -237,6 +238,7 @@
\setinterfacevariable{lefthanging}{lefthanging}
\setinterfacevariable{leftmargin}{marginestanga}
\setinterfacevariable{leftpage}{paginastanga}
+\setinterfacevariable{lefttoright}{lefttoright}
\setinterfacevariable{legend}{legenda}
\setinterfacevariable{lesshyphenation}{lesshyphenation}
\setinterfacevariable{line}{linie}
@@ -295,6 +297,7 @@
\setinterfacevariable{normal}{normal}
\setinterfacevariable{nospacing}{nospacing}
\setinterfacevariable{not}{nu}
+\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nothanging}
\setinterfacevariable{nothyphenated}{nedespsilabe}
\setinterfacevariable{november}{noiembrie}
@@ -359,6 +362,7 @@
\setinterfacevariable{righthanging}{righthanging}
\setinterfacevariable{rightmargin}{marginedreapta}
\setinterfacevariable{rightpage}{paginadreapta}
+\setinterfacevariable{righttoleft}{righttoleft}
\setinterfacevariable{roman}{roman}
\setinterfacevariable{romannumerals}{numereromane}
\setinterfacevariable{rotate}{rotit}
@@ -428,6 +432,14 @@
\setinterfacevariable{subsubsubsubsubject}{subsubsubsubsubiect}
\setinterfacevariable{subsubsubsubsubsection}{subsubsubsubsubsectiune}
\setinterfacevariable{subsubsubsubsubsubject}{subsubsubsubsubsubiect}
+\setinterfacevariable{subsubsubsubsubsubsection}{subsubsubsubsubsubsectiune}
+\setinterfacevariable{subsubsubsubsubsubsubject}{subsubsubsubsubsubsubiect}
+\setinterfacevariable{subsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsectiune}
+\setinterfacevariable{subsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubiect}
+\setinterfacevariable{subsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubsectiune}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubsubiect}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsection}{subsubsubsubsubsubsubsubsubsectiune}
+\setinterfacevariable{subsubsubsubsubsubsubsubsubsubject}{subsubsubsubsubsubsubsubsubsubiect}
\setinterfacevariable{sunday}{duminica}
\setinterfacevariable{support}{suport}
\setinterfacevariable{sym}{sym}
@@ -520,6 +532,8 @@
\setinterfaceconstant{bodyfont}{fonttext}
\setinterfaceconstant{bookmark}{semncarte}
\setinterfaceconstant{bottom}{jos}
+\setinterfaceconstant{bottomafter}{bottomafter}
+\setinterfaceconstant{bottombefore}{bottombefore}
\setinterfaceconstant{bottomdistance}{distantajos}
\setinterfaceconstant{bottomframe}{framejos}
\setinterfaceconstant{bottomoffset}{offsetjos}
@@ -547,6 +561,7 @@
\setinterfaceconstant{component}{component}
\setinterfaceconstant{compoundhyphen}{compoundhyphen}
\setinterfaceconstant{compress}{compress}
+\setinterfaceconstant{connector}{connector}
\setinterfaceconstant{continue}{continua}
\setinterfaceconstant{contrastcolor}{culoarecontrast}
\setinterfaceconstant{controls}{controale}
@@ -593,6 +608,7 @@
\setinterfaceconstant{fieldlayer}{fieldlayer}
\setinterfaceconstant{fieldoffset}{offsetcamp}
\setinterfaceconstant{file}{fisier}
+\setinterfaceconstant{filtercommand}{filtercommand}
\setinterfaceconstant{focus}{focus}
\setinterfaceconstant{focusin}{focusin}
\setinterfaceconstant{focusout}{focusout}
@@ -626,6 +642,7 @@
\setinterfaceconstant{height}{inaltime}
\setinterfaceconstant{hfactor}{hfactor}
\setinterfaceconstant{hfil}{hfil}
+\setinterfaceconstant{hidenumber}{hidenumber}
\setinterfaceconstant{hoffset}{hoffset}
\setinterfaceconstant{horoffset}{offsetoriz}
\setinterfaceconstant{hyphen}{hyphen}
@@ -714,9 +731,17 @@
\setinterfaceconstant{number}{numar}
\setinterfaceconstant{numbercolor}{culoarenumar}
\setinterfaceconstant{numbercommand}{comandanumar}
+\setinterfaceconstant{numberconversion}{numberconversion}
+\setinterfaceconstant{numberconversionset}{numberconversionset}
\setinterfaceconstant{numberdistance}{numberdistance}
\setinterfaceconstant{numbering}{numerotare}
+\setinterfaceconstant{numberorder}{numberorder}
+\setinterfaceconstant{numberprefix}{numberprefix}
+\setinterfaceconstant{numbersegments}{numbersegments}
\setinterfaceconstant{numberseparator}{separatornumar}
+\setinterfaceconstant{numberseparatorset}{numberseparatorset}
+\setinterfaceconstant{numberset}{numberset}
+\setinterfaceconstant{numberstopper}{numberstopper}
\setinterfaceconstant{numberstyle}{stilnumar}
\setinterfaceconstant{numberwidth}{numberwidth}
\setinterfaceconstant{nx}{nx}
@@ -736,8 +761,22 @@
\setinterfaceconstant{pageboundaries}{marginipagina}
\setinterfaceconstant{pagecolor}{culoarepagina}
\setinterfaceconstant{pagecommand}{comandapagina}
+\setinterfaceconstant{pageconversion}{pageconversion}
+\setinterfaceconstant{pageconversionset}{pageconversionset}
\setinterfaceconstant{pagenumber}{numarpagina}
+\setinterfaceconstant{pageprefix}{pageprefix}
+\setinterfaceconstant{pageprefixconnector}{pageprefixconnector}
+\setinterfaceconstant{pageprefixconversion}{pageprefixconversion}
+\setinterfaceconstant{pageprefixconversionset}{pageprefixconversionset}
+\setinterfaceconstant{pageprefixsegments}{pageprefixsegments}
+\setinterfaceconstant{pageprefixseparatorset}{pageprefixseparatorset}
+\setinterfaceconstant{pageprefixset}{pageprefixset}
+\setinterfaceconstant{pageprefixstopper}{pageprefixstopper}
+\setinterfaceconstant{pagesegments}{pagesegments}
+\setinterfaceconstant{pageseparatorset}{pageseparatorset}
+\setinterfaceconstant{pageset}{pageset}
\setinterfaceconstant{pagestate}{pagestate}
+\setinterfaceconstant{pagestopper}{pagestopper}
\setinterfaceconstant{pagestyle}{stilpagina}
\setinterfaceconstant{palet}{paleta}
\setinterfaceconstant{paper}{hartie}
@@ -747,6 +786,13 @@
\setinterfaceconstant{placestopper}{punestopper}
\setinterfaceconstant{position}{pozitie}
\setinterfaceconstant{prefix}{prefix}
+\setinterfaceconstant{prefixconnector}{prefixconnector}
+\setinterfaceconstant{prefixconversion}{prefixconversion}
+\setinterfaceconstant{prefixconversionset}{prefixconversionset}
+\setinterfaceconstant{prefixsegments}{prefixsegments}
+\setinterfaceconstant{prefixseparatorset}{prefixseparatorset}
+\setinterfaceconstant{prefixset}{prefixset}
+\setinterfaceconstant{prefixstopper}{prefixstopper}
\setinterfaceconstant{preset}{preset}
\setinterfaceconstant{preview}{previzualizare}
\setinterfaceconstant{previous}{precendent}
@@ -757,6 +803,7 @@
\setinterfaceconstant{reduction}{reducere}
\setinterfaceconstant{ref}{ref}
\setinterfaceconstant{reference}{referinta}
+\setinterfaceconstant{referenceprefix}{referenceprefix}
\setinterfaceconstant{referencing}{referinta}
\setinterfaceconstant{regionin}{regiuneintrare}
\setinterfaceconstant{regionout}{regiuneiesire}
@@ -788,11 +835,18 @@
\setinterfaceconstant{rulethickness}{grosimerigla}
\setinterfaceconstant{samepage}{aceeasipagina}
\setinterfaceconstant{sample}{exemplu}
+\setinterfaceconstant{saveinlist}{saveinlist}
\setinterfaceconstant{scale}{scala}
\setinterfaceconstant{scope}{scop}
\setinterfaceconstant{screen}{ecran}
\setinterfaceconstant{section}{sectiune}
+\setinterfaceconstant{sectionconversion}{sectionconversion}
+\setinterfaceconstant{sectionconversionset}{sectionconversionset}
\setinterfaceconstant{sectionnumber}{numarsectiune}
+\setinterfaceconstant{sectionsegments}{sectionsegments}
+\setinterfaceconstant{sectionseparatorset}{sectionseparatorset}
+\setinterfaceconstant{sectionset}{sectionset}
+\setinterfaceconstant{sectionstopper}{sectionstopper}
\setinterfaceconstant{separator}{separator}
\setinterfaceconstant{set}{set}
\setinterfaceconstant{setups}{setups}
@@ -892,6 +946,8 @@
\setinterfaceconstant{ystep}{ystep}
% definitions for interface elements for language ro
%
+\setinterfaceelement{answerlines}{answerlines}
+\setinterfaceelement{answerspace}{answerspace}
\setinterfaceelement{begin}{inceput}
\setinterfaceelement{complete}{complet}
\setinterfaceelement{coupled}{cuplat}
@@ -1277,6 +1333,7 @@
\setinterfacecommand{settextcontent}{settextcontent}
\setinterfacecommand{settextvariable}{setvariabilatext}
\setinterfacecommand{setupalign}{seteazaalinierea}
+\setinterfacecommand{setupanswerarea}{setupanswerarea}
\setinterfacecommand{setuparranging}{seteazaaranjareapag}
\setinterfacecommand{setupbackground}{seteazafundal}
\setinterfacecommand{setupbackgrounds}{seteazafundaluri}
diff --git a/tex/context/base/mult-sys.tex b/tex/context/base/mult-sys.tex
index 407146901..0fb64d98a 100644
--- a/tex/context/base/mult-sys.tex
+++ b/tex/context/base/mult-sys.tex
@@ -15,7 +15,7 @@
%D system constants. By doing so we save lots of memory while
%D at the same time we prevent ourself from typing errors.
-\writestatus{loading}{Context Multilingual Macros / System}
+\writestatus{loading}{ConTeXt Multilingual Macros / System}
\unprotect
@@ -39,7 +39,7 @@
\definesystemconstant {arabic} \definesystemconstant {ar}
\definesystemconstant {catalan} \definesystemconstant {ca}
\definesystemconstant {chinese} \definesystemconstant {cn}
-\definesystemconstant {croation} \definesystemconstant {hr}
+\definesystemconstant {croatian} \definesystemconstant {hr}
\definesystemconstant {czech} \definesystemconstant {cs} \definesystemconstant {cz}
\definesystemconstant {danish} \definesystemconstant {da}
\definesystemconstant {dutch} \definesystemconstant {nl}
@@ -116,10 +116,16 @@
\definemessageconstant {textblocks}
\definemessageconstant {verbatims}
\definemessageconstant {versions}
+\definemessageconstant {metapost}
+\definemessageconstant {chemicals}
%D Net come some \CONTEXT\ constants, used in the definition
%D of private commands:
+\definesystemconstant {tex}
+\definesystemconstant {xml}
+\definesystemconstant {lua}
+
\definesystemconstant {next}
\definesystemconstant {pickup}
\definesystemconstant {ascii}
@@ -144,6 +150,12 @@
\definesystemconstant {section} \let\v!sectionlevel\s!section % for old times sake
\definesystemconstant {handler}
\definesystemconstant {counter}
+\definesystemconstant {single}
+\definesystemconstant {multi}
+
+\definesystemconstant {hasnumber}
+\definesystemconstant {hastitle}
+\definesystemconstant {hascaption}
%D A more experienced \TEX\ user will recognize the next four
%D constants. We need these because font-definitions are
@@ -184,6 +196,10 @@
\definesystemconstant {black}
\definesystemconstant {white}
+\definesystemconstant {format}
+\definesystemconstant {extensions}
+\definesystemconstant {initializations}
+
%D Just to be complete we define the standard \TEX\ units.
\definesystemconstant {cm}
@@ -210,8 +226,11 @@
\definesystemconstant {see}
\definesystemconstant {from}
\definesystemconstant {to}
-\definesystemconstant {page}
\definesystemconstant {line}
+\definesystemconstant {page}
+\definesystemconstant {realpage}
+\definesystemconstant {userpage}
+\definesystemconstant {subpage}
\definesystemconstant {synonym}
@@ -332,22 +351,11 @@
\def\!!twelvepoint {12pt}
\def\!!fourteenpointfour {14.4pt}
-\newdimen \onepoint \onepoint = 1pt
-\newdimen \onebasepoint \onebasepoint = 1bp
-\chardef \scaledpoint = 1
-
\let\onerealpoint\onepoint % needed for latex
-\newcount\medcard \medcard\!!medcard % used in font module
-\newcount\maxcard \maxcard\!!maxcard % used in font module
-
-\ifx\thousandpoint\undefined \newdimen\thousandpoint \fi
-
-\thousandpoint=1000pt
-
-%D Another optimization is:
-
-\let\points\onepoint
+% D Another optimization is:
+%
+% \let\points\onepoint
%D A rough test is:
%D
@@ -402,6 +410,7 @@
\definesystemvariable {ck} % Character Kerning
\definesystemvariable {cl} % kleur (CoLor setup)
\definesystemvariable {cn} % CollumN
+\definesystemvariable {cm} % CheMical
\definesystemvariable {co} % COmbinaties
\definesystemvariable {cp} % CliP
\definesystemvariable {cr} % kleur (ColoR)
@@ -438,9 +447,11 @@
\definesystemvariable {fm} % ForMules
\definesystemvariable {fn} % subformulas
\definesystemvariable {fp} % FilegroeP
+\definesystemvariable {fq} % Features
\definesystemvariable {fr} % ForM
\definesystemvariable {fs} % FileSynonym
\definesystemvariable {ft} % FonTs
+\definesystemvariable {fu} % FontSolution
\definesystemvariable {fv} % FontVariant
\definesystemvariable {fx} % FoXet
\definesystemvariable {ha} % HAng
@@ -484,6 +495,7 @@
\definesystemvariable {ln} % LijNen
\definesystemvariable {lo} % LOgos
\definesystemvariable {lt} % LiTeratuur
+\definesystemvariable {ls} % languageScript
\definesystemvariable {ly} % LaYout
\definesystemvariable {ma} % MargeAchtergrond
\definesystemvariable {mb} % MargeBlokken
@@ -492,14 +504,16 @@
\definesystemvariable {mk} % MarKering
\definesystemvariable {mt} % inline MaTh
\definesystemvariable {mo} % Math Options
-\definesystemvariable {nm} % Nummering
\definesystemvariable {mx} % MatriX
\definesystemvariable {ng} % parbuilders
+\definesystemvariable {nh} % new heads (structure)
+\definesystemvariable {nm} % Nummering
\definesystemvariable {np} % NaastPlaatsen
\definesystemvariable {nr} % Nummeren
\definesystemvariable {of} % OFfset
\definesystemvariable {oi} % OmlijndInstellingen
\definesystemvariable {ol} % OmLijnd
+\definesystemvariable {od} % Omlijnd Defaults (simple)
\definesystemvariable {on} % ONderstreep
\definesystemvariable {oo} % OpsOmmingen
\definesystemvariable {op} % OPsomming
@@ -786,63 +800,23 @@
% \ifinterfacetranslation \else % interfacetranslation is obsolete
-\startmessages dutch library: check
- title: controle
- 1: '=' ontbreekt of zonder {} na '--' in regel --
- 2: -- argument(en) verwacht in regel --
- 3: -- -- vervangt een macro, gebruik HOOFDLETTERS!
-\stopmessages
+% messages moved
-\startmessages english library: check
- title: check
- 1: missing or ungrouped '=' after '--' in line --
- 2: -- argument(s) expected in line --
- 3: -- -- replaces a macro, use CAPITALS!
-\stopmessages
+% messages moved
% 1: to be adapted
-\startmessages german library: check
- title: check
- 1: Fehlendes '=' nach '--' in Zeile --
- 2: -- Argument(e) in Zeile -- erwartet
- 3: -- -- ersetzt ein Makro, verwende VERSALIEN!
-\stopmessages
-
-\startmessages czech library: check
- title: kontrola
- 1: postradam '=' po '--' na radku --
- 2: ocekavam -- argument(y) na radku --
- 3: -- -- nahrazuje makro, uzijte VERZALKY!
-\stopmessages
-
-\startmessages italian library: check
- title: controllo
- 1: '=' mancante o non raggruppato dopo '--' alla riga --
- 2: -- argomento/i attesi alla riga --
- 3: -- -- sostituisce una macro, usare le MAIUSCOLE!
-\stopmessages
-
-\startmessages norwegian library: check
- title: kontroll
- 1: manglende '=' etter '--' i linje --
- 2: -- argument forventet i linje --
- 3: -- -- overskygger en makro, bruk STORE BOKSTAVER!
-\stopmessages
-
-\startmessages romanian library: check
- title: verificari
- 1: lipseste '=' dupa '--' in linia --
- 2: argumentul(ele) -- sunt asteptate in linia --
- 3: -- -- inlocuieste un macro, folositi MAJUSCULE!
-\stopmessages
-
-\startmessages french library: check
- title: vérification
- 1: manquant ou dégroupé '=' après '--' à la ligne --
- 2: -- argument(s) attendu(s) à la ligne --
- 3: -- -- remplace une macro, utilisez des MAJUSCULES !
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
% \fi
diff --git a/tex/context/base/node-dum.lua b/tex/context/base/node-dum.lua
new file mode 100644
index 000000000..274e0cdd6
--- /dev/null
+++ b/tex/context/base/node-dum.lua
@@ -0,0 +1,24 @@
+if not modules then modules = { } end modules ['node-dum'] = {
+ version = 1.001,
+ comment = "companion to luatex-*.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+nodes = nodes or { }
+
+function nodes.simple_font_dummy(head,tail)
+ return tail
+end
+
+function nodes.simple_font_handler(head)
+ local tail = node.slide(head)
+-- lang.hyphenate(head,tail)
+ head = nodes.process_characters(head,tail)
+ nodes.inject_kerns(head)
+ nodes.protect_glyphs(head)
+ tail = node.ligaturing(head,tail)
+ tail = node.kerning(head,tail)
+ return head
+end
diff --git a/tex/context/base/node-ext.lua b/tex/context/base/node-ext.lua
new file mode 100644
index 000000000..b098829cd
--- /dev/null
+++ b/tex/context/base/node-ext.lua
@@ -0,0 +1,30 @@
+if not modules then modules = { } end modules ['node-ext'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
Serializing nodes can be handy for tracing. Also, saving and
+loading node lists can come in handy as soon we are going to
+use external applications to process node lists.
+--ldx]]--
+
+function nodes.show(stack)
+-- texio.write_nl(table.serialize(stack))
+end
+
+function nodes.save(stack,name) -- *.ltn : luatex node file
+-- if name then
+-- file.savedata(name,table.serialize(stack))
+-- else
+-- texio.write_nl('log',table.serialize(stack))
+-- end
+end
+
+function nodes.load(name)
+-- return file.loaddata(name)
+-- -- todo
+end
diff --git a/tex/context/base/node-fin.lua b/tex/context/base/node-fin.lua
new file mode 100644
index 000000000..3810b7a85
--- /dev/null
+++ b/tex/context/base/node-fin.lua
@@ -0,0 +1,363 @@
+if not modules then modules = { } end modules ['node-fin'] = {
+ version = 1.001,
+ comment = "companion to node-fin.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this module is being reconstructed
+
+local next, type, format = next, type, string.format
+local texsprint = tex.sprint
+
+local ctxcatcodes = tex.ctxcatcodes
+
+local glyph = node.id('glyph')
+local glue = node.id('glue')
+local rule = node.id('rule')
+local whatsit = node.id('whatsit')
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+
+local has_attribute = node.has_attribute
+local copy_node = node.copy
+
+local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
+
+states = states or { }
+shipouts = shipouts or { }
+
+local numbers = attributes.numbers
+local trigger = attributes.private('trigger')
+local triggering = false
+
+-- these two will be like trackers
+
+function states.enabletriggering()
+ triggering = true
+end
+function states.disabletriggering()
+ triggering = false
+end
+
+--
+
+states.collected = states.collected or { }
+
+storage.register("states/collected", states.collected, "states.collected")
+
+local collected = states.collected
+
+function states.collect(str)
+ collected[#collected+1] = str
+end
+
+function states.flush()
+ if #collected > 0 then
+ for i=1,#collected do
+ texsprint(ctxcatcodes,collected[i]) -- we're in context mode anyway
+ end
+ collected = { }
+ states.collected = collected
+ end
+end
+
+function states.check()
+ texio.write_nl(concat(collected,"\n"))
+end
+
+-- we used to do the main processor loop here and call processor for each node
+-- but eventually this was too much a slow down (1 sec on 23 for 120 pages mk)
+-- so that we moved looping to the processor itself; this may lead to a bit of
+-- duplicate code once that we have more state handlers
+
+local function process_attribute(head,plugin) -- head,attribute,enabled,initializer,resolver,processor,finalizer
+ starttiming(attributes)
+ local done, used, ok = false, nil, false
+ local attribute = numbers[plugin.name] -- todo: plugin.attribute
+ local namespace = plugin.namespace
+ if namespace.enabled then
+ local processor = plugin.processor
+ if processor then
+ local initializer = plugin.initializer
+ local resolver = plugin.resolver
+ local inheritance = (resolver and resolver()) or -0x7FFFFFFF -- we can best use nil and skip !
+ if initializer then
+ initializer(namespace,attribute,head)
+ end
+ head, ok = processor(namespace,attribute,head,inheritance)
+ if ok then
+ local finalizer = plugin.finalizer
+ if finalizer then
+ head, ok, used = finalizer(namespace,attribute,head)
+ if used then
+ local flusher = plugin.flusher
+ if flusher then
+ local h, d = flusher(namespace,attribute,head,used)
+ head = h
+ end
+ end
+ end
+ done = true
+ end
+ end
+ end
+ stoptiming(attributes)
+ return head, done
+end
+
+nodes.process_attribute = process_attribute
+
+function nodes.install_attribute_handler(plugin)
+ return function(head)
+ return process_attribute(head,plugin)
+ end
+end
+
+-- a few handlers
+
+local current, current_selector, used, done = 0, 0, { }, false
+
+local function insert(n,stack,previous,head) -- there is a helper, we need previous because we are not slided
+ if n then
+ if type(n) == "function" then
+ n = n()
+ end
+ if n then
+ n = copy_node(n)
+ n.next = stack
+ if previous then
+ previous.next = n
+ else
+ head = n
+ end
+ previous = n -- ?
+ else
+ -- weird
+ end
+ end
+ return stack, head
+end
+
+function states.initialize(what, attribute, stack)
+ current, current_selector, used, done = 0, 0, { }, false
+end
+
+function states.finalize(namespace,attribute,head) -- is this one ok?
+ if current > 0 then
+ local nn = namespace.none
+ if nn then
+ local id = head.id
+ if id == hlist or id == vlist then
+ local list = head.list
+ if list then
+ local _, h = insert(nn,list,nil,list)
+ head.list = h
+ end
+ else
+ stack, head = insert(nn,head,nil,head)
+ end
+ return head, true, true
+ end
+ end
+ return head, false, false
+end
+
+local function process(namespace,attribute,head,inheritance,default) -- one attribute
+ local trigger = triggering and namespace.triggering and trigger
+ local stack, previous, done = head, nil, false
+ local nsdata, nsreviver, nsnone = namespace.data, namespace.reviver, namespace.none
+ while stack do
+ local id = stack.id
+ -- we need to deal with literals too (reset as well as oval)
+--~ if id == glyph or (id == whatsit and stack.subtype == 8) or (id == rule and stack.width ~= 0) or (id == glue and stack.leader) then -- or disc
+ if id == glyph or (id == rule and stack.width ~= 0) or (id == glue and stack.leader) then -- or disc
+ local c = has_attribute(stack,attribute)
+ if c then
+ if default and c == inheritance then
+ if current ~= default then
+ local data = nsdata[default] or nsreviver(default)
+ stack, head = insert(data,stack,previous,head)
+ current, done, used[default] = default, true, true
+ end
+ elseif current ~= c then
+ local data = nsdata[c] or nsreviver(c)
+ stack, head = insert(data,stack,previous,head)
+ current, done, used[c] = c, true, true
+ end
+ -- here ? compare selective
+ if id == glue then --leader
+ -- same as *list
+ local content = stack.leader
+ if content then
+ local savedcurrent = current
+ local ci = content.id
+ if ci == hlist or ci == vlist then
+ -- else we reset inside a box unneeded, okay, the downside is
+ -- that we trigger color in each repeated box, so there is room
+ -- for improvement here
+ current = 0
+ end
+ local ok = false
+ if trigger and has_attribute(stack,trigger) then
+ local outer = has_attribute(stack,attribute)
+ if outer ~= inheritance then
+ stack.leader, ok = process(namespace,attribute,content,inheritance,outer)
+ else
+ stack.leader, ok = process(namespace,attribute,content,inheritance,default)
+ end
+ else
+ stack.leader, ok = process(namespace,attribute,content,inheritance,default)
+ end
+ current = savedcurrent
+ done = done or ok
+ end
+ end
+ elseif default and inheritance then
+ if current ~= default then
+ local data = nsdata[default] or nsreviver(default)
+ stack, head = insert(data,stack,previous,head)
+ current, done, used[default] = default, true, true
+ end
+ elseif current > 0 then
+ stack, head = insert(nsnone,stack,previous,head)
+ current, done, used[0] = 0, true, true
+ end
+ elseif id == hlist or id == vlist then
+ local content = stack.list
+ if content then
+ local ok = false
+ if trigger and has_attribute(stack,trigger) then
+ local outer = has_attribute(stack,attribute)
+ if outer ~= inheritance then
+ stack.list, ok = process(namespace,attribute,content,inheritance,outer)
+ else
+ stack.list, ok = process(namespace,attribute,content,inheritance,default)
+ end
+ else
+ stack.list, ok = process(namespace,attribute,content,inheritance,default)
+ end
+ done = done or ok
+ end
+ end
+ previous = stack
+ stack = stack.next
+ end
+ -- we need to play safe
+-- i need a proper test set for this, maybe controlled per feature
+--~ if current > 0 then
+--~ stack, head = insert(nsnone,stack,previous,head)
+--~ current, current_selector, done, used[0] = 0, 0, true, true
+--~ end
+ return head, done
+end
+
+states.process = process
+
+-- we can force a selector, e.g. document wide color spaces, saves a little
+-- watch out, we need to check both the selector state (like colorspace) and
+-- the main state (like color), otherwise we get into troubles when a selector
+-- state changes while the main state stays the same (like two glyphs following
+-- each other with the same color but different color spaces e.g. \showcolor)
+
+local function selective(namespace,attribute,head,inheritance,default) -- two attributes
+ local trigger = triggering and namespace.triggering and trigger
+ local stack, previous, done = head, nil, false
+ local nsforced, nsselector = namespace.forced, namespace.selector
+ local nsdata, nsreviver, nsnone = namespace.data, namespace.reviver, namespace.none
+ while stack do
+ local id = stack.id
+ -- we need to deal with literals too (reset as well as oval)
+--~ if id == glyph or (id == whatsit and stack.subtype == 8) or (id == rule and stack.width ~= 0) or (id == glue and stack.leader) then -- or disc
+ if id == glyph or (id == rule and stack.width ~= 0) or (id == glue and stack.leader) then -- or disc
+ local c = has_attribute(stack,attribute)
+ if c then
+ if default and c == inheritance then
+ if current ~= default then
+ local data = nsdata[default] or nsreviver(default)
+ stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
+ current, done, used[default] = default, true, true
+ end
+ else
+ local s = has_attribute(stack,nsselector)
+ if current ~= c or current_selector ~= s then
+ local data = nsdata[c] or nsreviver(c)
+ stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
+ current, current_selector, done, used[c] = c, s, true, true
+ end
+ end
+ elseif default and inheritance then
+ if current ~= default then
+ local data = nsdata[default] or nsreviver(default)
+ stack, head = insert(data[nsforced or has_attribute(stack,nsselector) or nsselector],stack,previous,head)
+ current, done, used[default] = default, true, true
+ end
+ elseif current > 0 then
+ stack, head = insert(nsnone,stack,previous,head)
+ current, current_selector, done, used[0] = 0, 0, true, true
+ end
+ if id == glue then -- leader
+ -- same as *list
+ local content = stack.leader
+ if content then
+ local savedcurrent = current
+ local ci = content.id
+ if ci == hlist or ci == vlist then
+ -- else we reset inside a box unneeded, okay, the downside is
+ -- that we trigger color in each repeated box, so there is room
+ -- for improvement here
+ current = 0
+ end
+ local ok = false
+ if trigger and has_attribute(stack,trigger) then
+ local outer = has_attribute(stack,attribute)
+ if outer ~= inheritance then
+ stack.leader, ok = selective(namespace,attribute,content,inheritance,outer)
+ else
+ stack.leader, ok = selective(namespace,attribute,content,inheritance,default)
+ end
+ else
+ stack.leader, ok = selective(namespace,attribute,content,inheritance,default)
+ end
+ current = savedcurrent
+ done = done or ok
+ end
+ end
+ elseif id == hlist or id == vlist then
+ local content = stack.list
+ if content then
+ local ok = false
+ if trigger and has_attribute(stack,trigger) then
+ local outer = has_attribute(stack,attribute)
+ if outer ~= inheritance then
+ stack.list, ok = selective(namespace,attribute,content,inheritance,outer)
+ else
+ stack.list, ok = selective(namespace,attribute,content,inheritance,default)
+ end
+ else
+ stack.list, ok = selective(namespace,attribute,content,inheritance,default)
+ end
+ done = done or ok
+ end
+ end
+ previous = stack
+ stack = stack.next
+ end
+ -- we need to play safe, this is subptimal since now we end each box
+ -- even if it's not needed
+-- i need a proper test set for this, maybe controlled per feature
+--~ if current > 0 then
+--~ stack, head = insert(nsnone,stack,previous,head)
+--~ current, current_selector, done, used[0] = 0, 0, true, true
+--~ end
+ return head, done
+end
+
+states.selective = selective
+
+statistics.register("attribute processing time", function()
+ if statistics.elapsedindeed(attributes) then
+ return format("%s seconds",statistics.elapsedtime(attributes))
+ end
+end)
diff --git a/tex/context/base/node-fin.tex b/tex/context/base/node-fin.tex
new file mode 100644
index 000000000..787706ff2
--- /dev/null
+++ b/tex/context/base/node-fin.tex
@@ -0,0 +1,78 @@
+%D \module
+%D [ file=attr-ini,
+%D version=2007.06.06, % probably a bit older
+%D title=\CONTEXT\ Node Macros,
+%D subtitle=Finalizing,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA-ADE]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Node Support / Finalizing}
+
+% Objects are processed indepently \unknown\ actually we may
+% need a proper callback.
+
+\unprotect
+
+\registerctxluafile{node-fin}{1.001} % we might generalize this one
+
+\definesystemattribute[trigger] % feature inheritance
+
+\newbox\finalizedshipoutbox
+
+\def\finalizeobjectbox#1{\ctxlua{nodes.process_page(tex.box[\number#1])}}
+
+\def\finalizeshipoutbox#1% % hack till we have access to pdf backend
+ {\global\setbox\finalizedshipoutbox\hbox{#1}%
+ \finalizeobjectbox\finalizedshipoutbox
+ \hbox{\ctxlua{states.flush()}\box\finalizedshipoutbox}}
+
+% tricky stuff:
+
+\newcount\attributeboxcount
+
+\edef\startinheritattributes{\dosetattribute {trigger}{1}}
+\edef\stopinheritattributes {\doresetattribute{trigger}}
+
+\def\doattributedcopy {\afterassignment\dodoattributedcopy\attributeboxcount}
+\def\doattributedbox {\afterassignment\dodoattributedbox \attributeboxcount}
+
+\def\dodoattributedcopy
+ {\startinheritattributes
+ \ifvbox\attributeboxcount
+ \vbox{\unvcopy\attributeboxcount}%
+ \else
+ \hbox{\unhcopy\attributeboxcount}%
+ \fi
+ \stopinheritattributes}
+
+\def\dodoattributedbox
+ {\startinheritattributes
+ \ifvbox\attributeboxcount
+ \vbox{\unvbox\attributeboxcount}%
+ \else
+ \hbox{\unhbox\attributeboxcount}%
+ \fi
+ \stopinheritattributes}
+
+\def\enableattributeinheritance
+ {\ctxlua{states.enabletriggering()}%
+ \let\attributedcopy\doattributedcopy
+ \let\attributedbox \doattributedbox}
+
+\def\disableattributeinheritance
+ {\ctxlua{states.disabletriggering()}%
+ \let\attributedcopy\copy
+ \let\attributedbox \box}
+
+\disableattributeinheritance
+
+% \appendtoks
+% \enableattributeinheritance % will become default
+% \to\everyjob
+
+\protect \endinput
diff --git a/tex/context/base/node-fnt.lua b/tex/context/base/node-fnt.lua
new file mode 100644
index 000000000..3ad9060c3
--- /dev/null
+++ b/tex/context/base/node-fnt.lua
@@ -0,0 +1,206 @@
+if not modules then modules = { } end modules ['node-fnt'] = {
+ version = 1.001,
+ comment = "companion to font-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local next, type = next, type
+
+local trace_characters = false trackers.register("nodes.characters", function(v) trace_characters = v end)
+
+local glyph = node.id('glyph')
+
+local traverse_id = node.traverse_id
+local has_attribute = node.has_attribute
+
+local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
+
+fonts = fonts or { }
+fonts.tfm = fonts.tfm or { }
+fonts.ids = fonts.ids or { }
+
+local fontdata = fonts.ids
+
+-- some tests with using an array of dynamics[id] and processes[id] demonstrated
+-- that there was nothing to gain (unless we also optimize other parts)
+--
+-- maybe getting rid of the intermediate shared can save some time
+
+-- potential speedup: check for subtype < 256 so that we can remove that test
+-- elsewhere, danger: injected nodes will not be dealt with but that does not
+-- happen often; we could consider processing sublists but that might need mor
+-- checking later on; the current approach also permits variants
+
+if tex.attribute[0] < 0 then
+
+ texio.write_nl("log","!")
+ texio.write_nl("log","! Attribute 0 is reserved for ConTeXt's font feature management and has to be")
+ texio.write_nl("log","! set to zero. Also, some attributes in the range 1-255 are used for special")
+ texio.write_nl("log","! purposed so setting them at the TeX end might break the font handler.")
+ texio.write_nl("log","!")
+
+ tex.attribute[0] = 0 -- else no features
+
+end
+
+function nodes.process_characters(head)
+ -- either next or not, but definitely no already processed list
+ starttiming(nodes)
+ local usedfonts, attrfonts, done = { }, { }, false
+ local a, u, prevfont, prevattr = 0, 0, nil, 0
+ for n in traverse_id(glyph,head) do
+ local font, attr = n.font, has_attribute(n,0) -- zero attribute is reserved for fonts, preset to 0 is faster (first match)
+ if attr and attr > 0 then
+ if font ~= prevfont or attr ~= prevattr then
+ local used = attrfonts[font]
+ if not used then
+ used = { }
+ attrfonts[font] = used
+ end
+ if not used[attr] then
+ -- we do some testing outside the function
+ local tfmdata = fontdata[font]
+ local shared = tfmdata.shared
+ if shared then
+ local dynamics = shared.dynamics
+ if dynamics then
+ local d = shared.set_dynamics(font,dynamics,attr) -- still valid?
+ if d then
+ used[attr] = d
+ a = a + 1
+ end
+ end
+ end
+ end
+ prevfont, prevattr = font, attr
+ end
+ elseif font ~= prevfont then
+ prevfont, prevattr = font, 0
+ local used = usedfonts[font]
+ if not used then
+ local tfmdata = fontdata[font]
+ if tfmdata then
+ local shared = tfmdata.shared -- we need to check shared, only when same features
+ if shared then
+ local processors = shared.processes
+ if processors and #processors > 0 then
+ usedfonts[font] = processors
+ u = u + 1
+ end
+ end
+ else
+ -- probably nullfont
+ end
+ end
+ else
+ prevattr = attr
+ end
+ end
+ -- we could combine these and just make the attribute nil
+ if u == 1 then
+ local font, processors = next(usedfonts)
+ local n = #processors
+ if n > 0 then
+ local h, d = processors[1](head,font,false)
+ head, done = h or head, done or d
+ if n > 1 then
+ for i=2,n do
+ local h, d = processors[i](head,font,0) -- false)
+ head, done = h or head, done or d
+ end
+ end
+ end
+ elseif u > 0 then
+ for font, processors in next, usedfonts do
+ local n = #processors
+ local h, d = processors[1](head,font,false)
+ head, done = h or head, done or d
+ if n > 1 then
+ for i=2,n do
+ local h, d = processors[i](head,font,0) -- false)
+ head, done = h or head, done or d
+ end
+ end
+ end
+ end
+ if a == 1 then
+ local font, dynamics = next(attrfonts)
+ for attribute, processors in next, dynamics do -- attr can switch in between
+ local n = #processors
+ local h, d = processors[1](head,font,attribute)
+ head, done = h or head, done or d
+ if n > 1 then
+ for i=2,n do
+ local h, d = processors[i](head,font,attribute)
+ head, done = h or head, done or d
+ end
+ end
+ end
+ elseif a > 0 then
+ for font, dynamics in next, attrfonts do
+ for attribute, processors in next, dynamics do -- attr can switch in between
+ local n = #processors
+ local h, d = processors[1](head,font,attribute)
+ head, done = h or head, done or d
+ if n > 1 then
+ for i=2,n do
+ local h, d = processors[i](head,font,attribute)
+ head, done = h or head, done or d
+ end
+ end
+ end
+ end
+ end
+ stoptiming(nodes)
+ if trace_characters then
+ nodes.report(head,done)
+ end
+ return head, true
+end
+
+if node.protect_glyphs then
+
+ nodes.protect_glyphs = node.protect_glyphs
+ nodes.unprotect_glyphs = node.unprotect_glyphs
+
+else do
+
+ -- initial value subtype : X000 0001 = 1 = 0x01 = char
+ --
+ -- expected before linebreak : X000 0000 = 0 = 0x00 = glyph
+ -- X000 0010 = 2 = 0x02 = ligature
+ -- X000 0100 = 4 = 0x04 = ghost
+ -- X000 1010 = 10 = 0x0A = leftboundary lig
+ -- X001 0010 = 18 = 0x12 = rightboundary lig
+ -- X001 1010 = 26 = 0x1A = both boundaries lig
+ -- X000 1100 = 12 = 0x1C = leftghost
+ -- X001 0100 = 20 = 0x14 = rightghost
+
+
+ function nodes.protect_glyphs(head)
+ local done = false
+ for g in traverse_id(glyph,head) do
+ local s = g.subtype
+ if s == 1 then
+ done, g.subtype = true, 256
+ elseif s <= 256 then
+ done, g.subtype = true, 256 + s
+ end
+ end
+ return done
+ end
+
+ function nodes.unprotect_glyphs(head)
+ local done = false
+ for g in traverse_id(glyph,head) do
+ local s = g.subtype
+ if s > 256 then
+ done, g.subtype = true, s - 256
+ end
+ end
+ return done
+ end
+
+end end
diff --git a/tex/context/base/node-ini.lua b/tex/context/base/node-ini.lua
index 8b451124e..8185e3033 100644
--- a/tex/context/base/node-ini.lua
+++ b/tex/context/base/node-ini.lua
@@ -7,225 +7,68 @@ if not modules then modules = { } end modules ['node-ini'] = {
}
--[[ldx--
-
Access to nodes is what gives its power. Here we
-implement a few helper functions. These functions are rather optimized.
+
Most of the code that had accumulated here is now separated in
+modules.
We start with a registration system for atributes so that we can use the
+symbolic names later on.
+--ldx]]--
- local traverse_id = node.traverse_id
-
- function nodes.protect_glyphs(head)
- local done = false
- for g in traverse_id(glyph,head) do
- local s = g.subtype
- if s == 1 then
- done, g.subtype = true, 256
- elseif s <= 256 then
- done, g.subtype = true, 256 + s
- end
- end
- return done
- end
-
- function nodes.unprotect_glyphs(head)
- local done = false
- for g in traverse_id(glyph,head) do
- local s = g.subtype
- if s > 256 then
- done, g.subtype = true, s - 256
- end
- end
- return done
- end
-
-end end
-
-do
-
- local remove, free = node.remove, node.free
-
- function nodes.remove(head, current, free_too)
- local t = current
- head, current = remove(head,current)
- if t then
- if free_too then
- free(t)
- t = nil
- else
- t.next, t.prev = nil, nil
- end
- end
- return head, current, t
- end
-
---~ function nodes.remove(head, current, delete)
---~ local t = current
---~ if current == head then
---~ current = current.next
---~ if current then
---~ current.prev = nil
---~ end
---~ head = current
---~ else
---~ local prev, next = current.prev, current.next
---~ if prev then
---~ prev.next = next
---~ end
---~ if next then
---~ next.prev = prev
---~ end
---~ current = next -- not: or next
---~ end
---~ if t then
---~ if free_too then
---~ free(t)
---~ t = nil
---~ else
---~ t.next, t.prev = nil, nil
---~ end
---~ end
---~ return head, current, t
---~ end
-
+attributes = attributes or { }
- function nodes.delete(head,current)
- return nodes.remove(head,current,true)
- end
+attributes.names = attributes.names or { }
+attributes.numbers = attributes.numbers or { }
+attributes.list = attributes.list or { }
+attributes.unsetvalue = -0x7FFFFFFF
- nodes.before = node.insert_before -- broken
- nodes.after = node.insert_after
+storage.register("attributes/names", attributes.names, "attributes.names")
+storage.register("attributes/numbers", attributes.numbers, "attributes.numbers")
+storage.register("attributes/list", attributes.list, "attributes.list")
- function nodes.before(h,c,n)
- if c then
- if c == h then
- n.next = h
- n.prev = nil
- h.prev = n
- else
- local cp = c.prev
- n.next = c
- n.prev = cp
- if cp then
- cp.next = n
- end
- c.prev = n
- return h, n
- end
- end
- return n, n
- end
+local names, numbers, list = attributes.names, attributes.numbers, attributes.list
- function nodes.after(h,c,n)
- if c then
- local cn = c.next
- if cn then
- n.next = cn
- cn.prev = n
- else
- n.next = nil
- end
- c.next = n
- n.prev = c
---~ if c ~= h then
- return h, n
---~ end
- end
- return n, n
+function attributes.define(name,number) -- at the tex end
+ if not numbers[name] then
+ numbers[name], names[number], list[number] = number, name, { }
end
-
- function nodes.show_list(head, message)
- if message then
- texio.write_nl(message)
- end
- for n in node.traverse(head) do
- texio.write_nl(tostring(n))
- end
- end
-
end
--- will move
+--[[ldx--
+
We can use the attributes in the range 127-255 (outside user space). These
+are only used when no attribute is set at the \TEX\ end which normally
+happens in .
+--ldx]]--
-nodes.processors = { }
-nodes.processors.char = { }
-nodes.processors.char.proc = { }
+storage.shared.attributes_last_private = storage.shared.attributes_last_private or 127
-function nodes.report(t,done)
- if nodes.trace then -- best also test this before calling
- if done then
- if status.output_active then
- texio.write(format("<++ %s>",nodes.count(t)))
- else
- texio.write(format("<+ %s>",nodes.count(t)))
- end
- else
- if status.output_active then
- texio.write(format("<-- %s>",nodes.count(t)))
- else
- texio.write(format("<- %s>",nodes.count(t)))
- end
+function attributes.private(name) -- at the lua end (hidden from user)
+ local number = numbers[name]
+ if not number then
+ local last = storage.shared.attributes_last_private or 127
+ if last < 255 then
+ last = last + 1
+ storage.shared.attributes_last_private = last
end
+ number = last
+ numbers[name], names[number], list[number] = number, name, { }
end
+ return number
end
-do
-
- local function count(stack,flat)
- local n = 0
- while stack do
- local id = stack.id
- if not flat and id == hlist or id == vlist then
- local list = stack.list
- if list then
- n = n + 1 + count(list) -- self counts too
- else
- n = n + 1
- end
- else
- n = n + 1
- end
- stack = stack.next
- end
- return n
- end
-
- nodes.count = count
-
-end
+--[[ldx--
+
Access to nodes is what gives its power. Here we
+implement a few helper functions. These functions are rather optimized.
+--ldx]]--
--[[ldx--
When manipulating node lists in , we will remove
@@ -255,963 +98,136 @@ into the engine, but this is a not so natural extension.
also ignore the empty nodes. [This is obsolete!]
--ldx]]--
+nodes = nodes or { }
---[[ldx--
-
Serializing nodes can be handy for tracing. Also, saving and
-loading node lists can come in handy as soon we are going to
-use external applications to process node lists.
---ldx]]--
-
-function nodes.show(stack)
---~ texio.write_nl(table.serialize(stack))
-end
-
-function nodes.save(stack,name) -- *.ltn : luatex node file
---~ if name then
---~ file.savedata(name,table.serialize(stack))
---~ else
---~ texio.write_nl('log',table.serialize(stack))
---~ end
-end
-
-function nodes.load(name)
---~ return file.loaddata(name)
-end
-
--- node-cap.lua
-
---~ nodes.capture = { } -- somehow fails
-
---~ function nodes.capture.start(cbk)
---~ local head, tail = nil, nil
---~ callbacks.push(cbk, function(t)
---~ if tail then
---~ tail.next = t
---~ else
---~ head, tail = t, t
---~ end
---~ while tail.next do
---~ tail = tail.next
---~ end
---~ return false
---~ end)
---~ function nodes.capture.stop()
---~ function nodes.capture.stop() end
---~ function nodes.capture.get()
---~ function nodes.capture.get() end
---~ return head
---~ end
---~ callbacks.pop(cbk)
---~ end
---~ function nodes.capture.get() end -- error
---~ end
-
---~ nodes.capture.stop = function() end
---~ nodes.capture.get = function() end
-
--- node-gly.lua
-
-fonts = fonts or { }
-fonts.otf = fonts.otf or { }
-fonts.tfm = fonts.tfm or { }
-fonts.tfm.id = fonts.tfm.id or { }
-
-local tfm = fonts.tfm
-local otf = fonts.otf
-local tfmid = fonts.tfm.id
-
-do
-
- local has_attribute = node.has_attribute
- local traverse_id = node.traverse_id
-
- local pairs = pairs
-
- local starttiming, stoptiming = input.starttiming, input.stoptiming
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+local glyph = node.id('glyph')
+local glue = node.id('glue')
+local penalty = node.id('penalty')
+local kern = node.id('kern')
+local whatsit = node.id('whatsit')
- function nodes.process_characters(head)
- -- not ok yet; we need a generic blocker
- -- if status.output_active then
- if false then -- status.output_active then
- return head, false -- true
+local traverse_id = node.traverse_id
+local traverse = node.traverse
+local slide_nodes = node.slide
+local free_node = node.free
+local remove_node = node.remove
+
+function nodes.remove(head, current, free_too)
+ local t = current
+ head, current = remove_node(head,current)
+ if t then
+ if free_too then
+ free_node(t)
+ t = nil
else
- -- either next or not, but definitely no already processed list
- starttiming(nodes)
- local usedfonts, attrfonts, done = { }, { }, false
- -- todo: should be independent of otf
- local set_dynamics = otf.set_dynamics -- todo: font-var.lua so that we can global this one
- local a, u, prevfont, prevattr = 0, 0, nil, 0
- for n in traverse_id(glyph,head) do
- local font, attr = n.font, has_attribute(n,0) -- zero attribute is reserved for fonts, preset to 0 is faster (first match)
- if attr and attr > 0 then
- if font ~= prevfont or attr ~= prevattr then
- local used = attrfonts[font]
- if not used then
- used = { }
- attrfonts[font] = used
- end
- if not used[attr] then
- local d = set_dynamics(tfmid[font],attr) -- todo, script, language -> n.language also axis
- if d then
- used[attr] = d
- a = a + 1
- end
- end
- prevfont, prevattr = font, attr
- end
- elseif font ~= prevfont then
- prevfont, prevattr = font, 0
- local used = usedfonts[font]
- if not used then
- local data = tfmid[font]
- if data then
- local shared = data.shared -- we need to check shared, only when same features
- if shared then
- local processors = shared.processors
- if processors and #processors > 0 then
- usedfonts[font] = processors
- u = u + 1
- end
- end
- else
- -- probably nullfont
- end
- end
- else
- prevattr = attr
- end
- end
- -- we could combine these and just make the attribute nil
- if u > 0 then
- for font, processors in pairs(usedfonts) do
- local n = #processors
- if n == 1 then
- local h, d = processors[1](head,font,false)
- head, done = h or head, done or d
- else
- for i=1,#processors do
- local h, d = processors[i](head,font,false)
- head, done = h or head, done or d
- end
- end
- end
- end
- if a > 0 then -- we need to get rid of a loop here
- for font, dynamics in pairs(attrfonts) do
- for attribute, processors in pairs(dynamics) do -- attr can switch in between
- local n = #processors
- if n == 1 then
- local h, d = processors[1](head,font,attribute)
- head, done = h or head, done or d
- else
- for i=1,n do
- local h, d = processors[i](head,font,attribute)
- head, done = h or head, done or d
- end
- end
- end
- end
- end
- stoptiming(nodes)
- if nodes.trace then
- nodes.report(head,done)
- end
- return head, true
- end
- end
-
-end
-
--- vbox: grouptype: vbox vtop output split_off split_keep | box_type: exactly|aditional
--- hbox: grouptype: hbox adjusted_hbox(=hbox_in_vmode) | box_type: exactly|aditional
-
-do
-
- local has_attribute, set, attribute = node.has_attribute, node.set_attribute, tex.attribute
-
- function nodes.inherit_attributes(n) -- still ok ?
- if n then
- local i = 1
- while true do
- local a = attribute[i]
- if a < 0 then
- break
- else
- local ai = has_attribute(n,i)
- if not ai then
- set(n,i,a)
- end
- i = i + 1
- end
- end
+ t.next, t.prev = nil, nil
end
- end
-
+ end
+ return head, current, t
end
-function nodes.length(head)
- if head then
- local m = 0
- for n in node.traverse(head) do
- m = m + 1
- end
- return m
- else
- return 0
- end
+function nodes.delete(head,current)
+ return nodes.remove(head,current,true)
end
-lists = lists or { }
-chars = chars or { }
-words = words or { } -- not used yet
-
-callbacks.trace = false
-
-do
+nodes.before = node.insert_before -- broken
+nodes.after = node.insert_after
- kernel = kernel or { }
+-- we need to test this, as it might be fixed
- local starttiming, stoptiming = input.starttiming, input.stoptiming
- local hyphenate, ligaturing, kerning = lang.hyphenate, node.ligaturing, node.kerning
-
- function kernel.hyphenation(head,tail) -- lang.hyphenate returns done
- if head == tail then
- return head, tail, false
- else
- starttiming(kernel)
- local done = head ~= tail and hyphenate(head,tail)
- stoptiming(kernel)
- return head, tail, done
- end
- end
- function kernel.ligaturing(head,tail) -- node.ligaturing returns head,tail,done
- if head == tail then
- return head, tail, false
+function nodes.before(h,c,n)
+ if c then
+ if c == h then
+ n.next = h
+ n.prev = nil
+ h.prev = n
else
- starttiming(kernel)
- local head, tail, done = ligaturing(head,tail)
- stoptiming(kernel)
- return head, tail, done
- end
- end
- function kernel.kerning(head,tail) -- node.kerning returns head,tail,done
- if head == tail then
- return head, tail, false
- else
- starttiming(kernel)
- local head, tail, done = kerning(head,tail)
- stoptiming(kernel)
- return head, tail, done
- end
- end
-
-end
-
-callback.register('hyphenate' , function(head,tail) return tail end)
-callback.register('ligaturing', function(head,tail) return tail end)
-callback.register('kerning' , function(head,tail) return tail end)
-
-nodes.tasks = nodes.tasks or { }
-nodes.tasks.data = nodes.tasks.data or { }
-
-function nodes.tasks.new(name,list)
- local tasklist = sequencer.reset()
- nodes.tasks.data[name] = { list = tasklist, runner = false }
- for _, task in ipairs(list) do
- sequencer.appendgroup(tasklist,task)
- end
-end
-
-function nodes.tasks.appendaction(name,group,action,where,kind)
- local data = nodes.tasks.data[name]
- sequencer.appendaction(data.list,group,action,where,kind)
- data.runner = false
-end
-
-function nodes.tasks.prependaction(name,group,action,where,kind)
- local data = nodes.tasks.data[name]
- sequencer.prependaction(data.list,group,action,where,kind)
- data.runner = false
-end
-
-function nodes.tasks.removeaction(name,group,action)
- local data = nodes.tasks.data[name]
- sequencer.removeaction(data.list,group,action)
- data.runner = false
-end
-
-function nodes.tasks.showactions(name,group,action,where,kind)
- local data = nodes.tasks.data[name]
- logs.report("nodes","task %s, list:\n%s",name,sequencer.nodeprocessor(data.list))
-end
-
-function nodes.tasks.actions(name)
- local data = nodes.tasks.data[name]
- return function(head,tail)
- local runner = data.runner
- if not runner then
- if nodes.trace_tasks then
- logs.report("nodes","creating task runner '%s'",name)
+ local cp = c.prev
+ n.next = c
+ n.prev = cp
+ if cp then
+ cp.next = n
end
- runner = sequencer.compile(data.list,sequencer.nodeprocessor)
- data.runner = runner
+ c.prev = n
+ return h, n
end
- return runner(head,tail)
end
+ return n, n
end
-nodes.tasks.new (
- "processors",
- {
- "before", -- for users
- "normalizers",
- "characters",
- "words",
- "fonts",
- "lists",
- "after", -- for users
- }
-)
-
--- these definitions will move
-
-nodes.tasks.appendaction("processors", "normalizers", "nodes.normalize_fonts", nil)
-nodes.tasks.appendaction("processors", "characters", "chars.handle_mirroring", nil, "notail")
-nodes.tasks.appendaction("processors", "characters", "chars.handle_casing", nil, "notail")
-nodes.tasks.appendaction("processors", "characters", "chars.handle_breakpoints", nil, "notail")
-nodes.tasks.appendaction("processors", "words", "kernel.hyphenation", nil)
-nodes.tasks.appendaction("processors", "words", "languages.words.check", nil, "notail")
-nodes.tasks.appendaction("processors", "fonts", "nodes.process_characters", nil, "notail")
-nodes.tasks.appendaction("processors", "fonts", "nodes.protect_glyphs", nil, "nohead")
-nodes.tasks.appendaction("processors", "fonts", "kernel.ligaturing", nil)
-nodes.tasks.appendaction("processors", "fonts", "kernel.kerning", nil)
-nodes.tasks.appendaction("processors", "lists", "lists.handle_spacing", nil, "notail")
-nodes.tasks.appendaction("processors", "lists", "lists.handle_kerning", nil, "notail")
-
-
-local free = node.free
-
-local function cleanup_page(head) -- rough
- local prev, start = nil, head
- while start do
- local id, nx = start.id, start.next
- if id == disc or id == mark then
- if prev then
- prev.next = nx
- end
- if start == head then
- head = nx
- end
- local tmp = start
- start = nx
- free(tmp)
- elseif id == hlist or id == vlist then
- local sl = start.list
- if sl then
- start.list = cleanup_page(sl)
- end
- prev, start = start, nx
+function nodes.after(h,c,n)
+ if c then
+ local cn = c.next
+ if cn then
+ n.next = cn
+ cn.prev = n
else
- prev, start = start, nx
+ n.next = nil
end
+ c.next = n
+ n.prev = c
+ return h, n
end
- return head
-end
-
-nodes.cleanup_page_first = false
-
-function nodes.cleanup_page(head)
- if nodes.cleanup_page_first then
- head = cleanup_page(head)
- end
- return head, false
-end
-
-nodes.tasks.new (
- "shipouts",
- {
- "before", -- for users
- "normalizers",
- "finishers",
- "after", -- for users
- }
-)
-
-nodes.tasks.appendaction("shipouts", "normalizers", "nodes.cleanup_page", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_color", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_transparency", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_overprint", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_negative", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_effect", nil, "notail")
-nodes.tasks.appendaction("shipouts", "finishers", "shipouts.handle_viewerlayer", nil, "notail")
-
-local actions = nodes.tasks.actions("shipouts")
-
-function nodes.process_page(head) -- problem, attr loaded before node, todo ...
- return actions(head) -- no tail
+ return n, n
end
--- or just: nodes.process_page = nodes.tasks.actions("shipouts")
-
-
-do -- remove these
-
- local actions = nodes.tasks.actions("processors")
- local first_character = node.first_character
- local slide = node.slide
-
- local n = 0
-
- local function reconstruct(head)
- local t = { }
- local h = head
- while h do
- local id = h.id
- if id == glyph then
- t[#t+1] = utf.char(h.char)
- else
- t[#t+1] = "[]"
- end
- h = h.next
- end
- return table.concat(t)
- end
-
- local function tracer(what,state,head,groupcode,before,after,show)
- if not groupcode then
- groupcode = "unknown"
- elseif groupcode == "" then
- groupcode = "mvl"
- end
- n = n + 1
- if show then
- texio.write_nl(format("%s %s: %s, group: %s, nodes: %s -> %s, string: %s",what,n,state,groupcode,before,after,reconstruct(head)))
+function nodes.replace(head,current,new)
+ if current and next then
+ local p, n = current.prev, current.next
+ new.prev, new.next = p, n
+ if p then
+ p.next = new
else
- texio.write_nl(format("%s %s: %s, group: %s, nodes: %s -> %s",what,n,state,groupcode,before,after))
- end
- end
-
- function nodes.processors.pre_linebreak_filter(head,groupcode) -- todo: tail
- local first, found = first_character(head)
- if found then
- if callbacks.trace then
- local before = nodes.count(head,true)
- local head, tail, done = actions(head,slide(head))
- local after = nodes.count(head,true)
- if done then
- tracer("pre_linebreak","changed",head,groupcode,before,after,true)
- else
- tracer("pre_linebreak","unchanged",head,groupcode,before,after,true)
- end
- return (done and head) or true
- else
- local head, tail, done = actions(head,slide(head))
- return (done and head) or true
- end
- else
- if callbacks.trace then
- local n = nodes.count(head,false)
- tracer("pre_linebreak","no chars",head,groupcode,n,n)
- end
- return true
- end
- end
-
- function nodes.processors.hpack_filter(head,groupcode) -- todo: tail
- local first, found = first_character(head)
- if found then
- if callbacks.trace then
- local before = nodes.count(head,true)
- local head, tail, done = actions(head,slide(head))
- local after = nodes.count(head,true)
- if done then
- tracer("hpack","changed",head,groupcode,before,after,true)
- else
- tracer("hpack","unchanged",head,groupcode,before,after,true)
- end
- return (done and head) or true
- else
- local head, tail, done = actions(head,slide(head))
- return (done and head) or true
- end
- end
- if callbacks.trace then
- local n = nodes.count(head,false)
- tracer("hpack","no chars",head,groupcode,n,n)
- end
- return true
- end
-
-end
-
-callback.register('pre_linebreak_filter', nodes.processors.pre_linebreak_filter)
-callback.register('hpack_filter' , nodes.processors.hpack_filter)
-
-do
-
- -- beware, some field names will change in a next release of luatex
-
- local expand = table.tohash {
- "list", -- list_ptr & ins_ptr & adjust_ptr
- "pre", --
- "post", --
- "spec", -- glue_ptr
- "top_skip", --
- "attr", --
- "replace", -- nobreak
- "components", -- lig_ptr
- "box_left", --
- "box_right", --
- "glyph", -- margin_char
- "leader", -- leader_ptr
- "action", -- action_ptr
- "value", -- user_defined nodes with subtype 'a' en 'n'
- }
-
- -- page_insert: "height", "last_ins_ptr", "best_ins_ptr"
- -- split_insert: "height", "last_ins_ptr", "best_ins_ptr", "broken_ptr", "broken_ins"
-
- local ignore = table.tohash {
- "page_insert",
- "split_insert",
- "ref_count",
- }
-
- local dimension = table.tohash {
- "width", "height", "depth", "shift",
- "stretch", "shrink",
- "xoffset", "yoffset",
- "surround",
- "kern",
- "box_left_width", "box_right_width"
- }
-
- -- flat: don't use next, but indexes
- -- verbose: also add type
- -- can be sped up
-
- nodes.dimensionfields = dimension
- nodes.listablefields = expand
- nodes.ignorablefields = ignore
-
- -- not ok yet:
-
- function nodes.astable(n,sparse) -- not yet ok
- local f, t = node.fields(n.id,n.subtype), { }
- for i=1,#f do
- local v = f[i]
- local d = n[v]
- if d then
- if ignore[v] or v == "id" then
- -- skip
- elseif expand[v] then -- or: type(n[v]) ~= "string" or type(n[v]) ~= "number" or type(n[v]) ~= "table"
- t[v] = "pointer to list"
- elseif sparse then
- if (type(d) == "number" and d ~= 0) or (type(d) == "string" and d ~= "") then
- t[v] = d
- end
- else
- t[v] = d
- end
- end
- end
- t.type = node.type(n.id)
- return t
- end
-
- local nodefields = node.fields
- local nodetype = node.type
-
- -- under construction:
-
- local function totable(n,flat,verbose)
- local function to_table(n)
- local f = nodefields(n.id,n.subtype)
- local tt = { }
- for k=1,#f do
- local v = f[k]
- local nv = n[v]
- if nv then
- if ignore[v] then
- -- skip
- elseif expand[v] then
- if type(nv) == "number" or type(nv) == "string" then
- tt[v] = nv
- else
- tt[v] = totable(nv,flat,verbose)
- end
- elseif type(nv) == "table" then
- tt[v] = nv -- totable(nv,flat,verbose) -- data
- else
- tt[v] = nv
- end
- end
- end
- if verbose then
- tt.type = nodetype(tt.id)
- end
- return tt
+ head = new
end
if n then
- if flat then
- local t = { }
- while n do
- t[#t+1] = to_table(n)
- n = n.next
- end
- return t
- else
- local t = to_table(n)
- if n.next then
- t.next = totable(n.next,flat,verbose)
- end
- return t
- end
- else
- return { }
+ n.prev = new
end
+ free_node(current)
end
+ return head, current
+end
- nodes.totable = totable
-
- local function key(k)
- return ((type(k) == "number") and "["..k.."]") or k
- end
-
- -- not ok yet; this will become a module
+-- will move
- local function serialize(root,name,handle,depth,m)
- handle = handle or print
- if depth then
- depth = depth .. " "
- handle(("%s%s={"):format(depth,key(name)))
- else
- depth = ""
- local tname = type(name)
- if tname == "string" then
- if name == "return" then
- handle("return {")
- else
- handle(name .. "={")
- end
- elseif tname == "number"then
- handle("[" .. name .. "]={")
- else
- handle("t={")
- end
- end
- if root then
- local fld
- if root.id then
- fld = nodefields(root.id,root.subtype) -- we can cache these (todo)
+local function count(stack,flat)
+ local n = 0
+ while stack do
+ local id = stack.id
+ if not flat and id == hlist or id == vlist then
+ local list = stack.list
+ if list then
+ n = n + 1 + count(list) -- self counts too
else
- fld = table.sortedkeys(root)
- end
- if type(root) == 'table' and root['type'] then -- userdata or table
- handle(("%s %s=%q,"):format(depth,'type',root['type']))
- end
- for _,k in ipairs(fld) do
- if k == "ref_count" then
- -- skip
- elseif k then
- local v = root[k]
- local t = type(v)
- if t == "number" then
- if v == 0 then
- -- skip
- else
- handle(("%s %s=%s,"):format(depth,key(k),v))
- end
- elseif t == "string" then
- if v == "" then
- -- skip
- else
- handle(("%s %s=%q,"):format(depth,key(k),v))
- end
- elseif v then -- userdata or table
- serialize(v,k,handle,depth,m+1)
- end
- end
- end
- if root['next'] then -- userdata or table
- serialize(root['next'],'next',handle,depth,m+1)
+ n = n + 1
end
- end
- if m and m > 0 then
- handle(("%s},"):format(depth))
else
- handle(("%s}"):format(depth))
+ n = n + 1
end
+ stack = stack.next
end
-
- function nodes.serialize(root,name)
- local t = { }
- local function flush(s)
- t[#t+1] = s
- end
- serialize(root, name, flush, nil, 0)
- return table.concat(t,"\n")
- end
-
- function nodes.serializebox(n,flat,verbose)
- return nodes.serialize(nodes.totable(tex.box[n],flat,verbose))
- -- return nodes.serialize(tex.box[n])
- end
-
- function nodes.visualizebox(...)
- -- tex.sprint(tex.ctxcatcodes,"\\starttyping\n" .. nodes.serializebox(...) .. "\n\\stoptyping\n")
- tex.print(tex.ctxcatcodes,"\\starttyping")
- tex.print(nodes.serializebox(...))
- tex.print("\\stoptyping")
- end
-
- function nodes.list(head,n) -- name might change to nodes.type
- if not n then
- tex.print(tex.ctxcatcodes,"\\starttyping")
- end
- while head do
- local id = head.id
- tex.print(string.rep(" ",n or 0) .. tostring(head) .. "\n")
- if id == hlist or id == vlist then
- nodes.list(head.list,(n or 0)+1)
- end
- head = head.next
- end
- if not n then
- tex.print("\\stoptyping")
- end
- end
-
- function nodes.print(head,n)
- while head do
- local id = head.id
- texio.write_nl(string.rep(" ",n or 0) .. tostring(head))
- if id == hlist or id == vlist then
- nodes.print(head.list,(n or 0)+1)
- end
- head = head.next
- end
- end
-
- function nodes.check_for_leaks(sparse)
- local l = { }
- local q = node.usedlist()
- for p in node.traverse(q) do
- local s = table.serialize(nodes.astable(p,sparse),node.type(p.id))
- l[s] = (l[s] or 0) + 1
- end
- node.flush_list(q)
- for k, v in pairs(l) do
- texio.write_nl(format("%s * %s", v, k))
- end
- end
-
-end
-
-if not node.list_has_attribute then -- no longer needed
-
- function node.list_has_attribute(list,attribute)
- if list and attribute then
- for n in node.traverse(list) do
- local a = has_attribute(n,attribute)
- if a then return a end
- end
- end
- return false
- end
-
+ return n
end
-function nodes.pack_list(head)
- local t = { }
- for n in node.traverse(head) do
- t[#t+1] = tostring(n)
- end
- return t
-end
+nodes.count = count
-do
+-- new
- function nodes.leftskip(n)
- while n do
- local id = n.id
- if id == glue then
- if n.subtype == 8 then -- 7 in c/web source
- return (n.spec and n.spec.width) or 0
- else
- return 0
- end
- elseif id == whatsit then
- n = n.next
- elseif id == hlist then
- return n.width
- else
- break
- end
- end
- return 0
- end
- function nodes.rightskip(n)
- if n then
- n = node.slide(n)
- while n do
- local id = n.id
- if id == glue then
- if n.subtype == 9 then -- 8 in the c/web source
- return (n.spec and n.spec.width) or 0
- else
- return 0
- end
- elseif id == whatsit then
- n = n.prev
- else
- break
- end
- end
+function attributes.ofnode(n)
+ local a = n.attr
+ if a then
+ local names = attributes.names
+ a = a.next
+ while a do
+ local number, value = a.number, a.value
+ texio.write_nl(format("%s : attribute %3i, value %4i, name %s",tostring(n),number,value,names[number] or '?'))
+ a = a.next
end
- return false
- end
-
+ end
end
--- goodie
---
--- if node.valid(tex.box[0]) then print("valid node") end
-
---~ do
---~ local n = node.new(0,0)
---~ local m = getmetatable(n)
---~ m.__metatable = 'node'
---~ node.free(n)
-
---~ function node.valid(n)
---~ return n and getmetatable(n) == 'node'
---~ end
---~ end
+local left, space = lpeg.P("<"), lpeg.P(" ")
--- for the moment we put this here:
-
-do
-
- nodes.tracers = { }
- nodes.tracers.characters = { }
-
- local function collect(head,list,tag,n)
- n = n or 0
- local ok, fn = false, nil
- while head do
- local id = head.id
- if id == glyph then
- local f = head.font
- if f ~= fn then
- ok, fn = false, f
- end
- local c = head.char
- local d = tfmid[f].descriptions[c]
- local i = (d and d.index) or -1
- if not ok then
- ok = true
- n = n + 1
- list[n] = list[n] or { }
- list[n][tag] = { }
- end
- local l = list[n][tag]
- l[#l+1] = { c, f, i }
- elseif id == disc then
- -- skip
- else
- ok = false
- end
- head = head.next
- end
- end
-
- function nodes.tracers.characters.equal(ta, tb)
- if #ta ~= #tb then
- return false
- else
- for i=1,#ta do
- local a, b = ta[i], tb[i]
- if a[1] ~= b[1] or a[2] ~= b[2] or a[3] ~= b[3] then
- return false
- end
- end
- end
- return true
- end
- function nodes.tracers.characters.string(t)
- local tt = { }
- for i=1,#t do
- tt[i] = utf.char(t[i][1])
- end
- return table.concat(tt,"")
- end
- function nodes.tracers.characters.unicodes(t,decimal)
- local tt = { }
- for i=1,#t do
- if decimal then
- tt[i] = t[i][1]
- else
- tt[i] = format("%04X",t[i][1])
- end
- end
- return table.concat(tt," ")
- end
- function nodes.tracers.characters.indices(t,decimal)
- local tt = { }
- for i=1,#t do
- if decimal then
- tt[i] = t[i][3]
- else
- tt[i] = format("%04X",t[i][3])
- end
- end
- return table.concat(tt," ")
- end
- function nodes.tracers.characters.fonts(t)
- local f = t[1] and t[1][2]
- return (f and file.basename(tfmid[f].filename or "unknown")) or "unknown"
- end
-
- function nodes.tracers.characters.start()
- local npc = nodes.process_characters
- local list = { }
- function nodes.process_characters(head)
- local n = #list
- collect(head,list,'before',n)
- local h, d = npc(head)
- collect(head,list,'after',n)
- if #list > n then
- list[#list+1] = { }
- end
- return h, d
- end
- function nodes.tracers.characters.stop()
- tracers.list['characters'] = list
- lmx.set('title', 'ConTeXt Character Processing Information')
- lmx.set('color-background-one', lmx.get('color-background-yellow'))
- lmx.set('color-background-two', lmx.get('color-background-purple'))
- lmx.show('context-characters.lmx')
- lmx.restore()
- nodes.process_characters = npc
- end
- end
-
- local stack = { }
-
- function nodes.tracers.start(tag)
- stack[#stack+1] = tag
- local tracer = nodes.tracers[tag]
- if tracer and tracer.start then
- tracer.start()
- end
- end
- function nodes.tracers.stop()
- local tracer = stack[#stack]
- if tracer and tracer.stop then
- tracer.stop()
- end
- stack[#stack] = nil
- end
-
-end
+nodes.filterkey = left * (1-left)^0 * left * space^0 * lpeg.C((1-space)^0)
diff --git a/tex/context/base/node-ini.tex b/tex/context/base/node-ini.tex
index c033a1f7b..210f21229 100644
--- a/tex/context/base/node-ini.tex
+++ b/tex/context/base/node-ini.tex
@@ -1,8 +1,8 @@
%D \module
%D [ file=node-ini,
%D version=2006.08.20,
-%D title=\CONTEXT\ Character Macros,
-%D subtitle=Node Support (Initialization),
+%D title=\CONTEXT\ Node Macros,
+%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
@@ -11,10 +11,59 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Node Support (initialization)}
+\writestatus{loading}{ConTeXt Node Support / Initialization}
+
+\unprotect
+
+\newcount\filterstate \filterstate\plusone
-\registerctxluafile{node-seq}{1.001}
\registerctxluafile{node-ini}{1.001}
+\registerctxluafile{node-tst}{1.001}
+\registerctxluafile{node-tra}{1.001} % we might split it off (module)
+\registerctxluafile{node-seq}{1.001} % we might generalize this one
+\registerctxluafile{node-tsk}{1.001}
+\registerctxluafile{node-tex}{1.001}
+\registerctxluafile{node-res}{1.001}
+\registerctxluafile{node-pro}{1.001}
+\registerctxluafile{node-shp}{1.001}
+\registerctxluafile{node-ser}{1.001}
+\registerctxluafile{node-ext}{1.001}
+\registerctxluafile{node-inj}{1.001} % we might split it off
+
+\newtoks \attributesresetlist
+
+\ifdefined \v!global \else \def\v!global{global} \fi % for metatex
+
+\def\defineattribute
+ {\dodoubleempty\dodefineattribute}
+
+\def\dodefineattribute[#1][#2]% alternatively we can let lua do the housekeeping
+ {\expandafter\newattribute\csname @attr@#1\endcsname
+ \expandafter \xdef\csname :attr:#1\endcsname{\number\lastallocatedattribute}%
+ \ctxlua{attributes.define("#1",\number\lastallocatedattribute)}%
+ %\writestatus\m!systems{defining attribute #1 with number \number\lastallocatedattribute}%
+ \doifnotinset\v!global{#2}{\appendetoks\csname @attr@#1\endcsname\attributeunsetvalue\to\attributesresetlist}}
+
+\def\definesystemattribute
+ {\dodoubleempty\dodefinesystemattribute}
+
+\def\dodefinesystemattribute[#1][#2]% alternatively we can let lua do the housekeeping
+ {\scratchcounter\ctxlua{tex.print(attributes.private("#1"))}\relax
+ \global\expandafter\attributedef\csname @attr@#1\endcsname\scratchcounter
+ \expandafter \xdef\csname :attr:#1\endcsname{\number\scratchcounter}%
+ %\writestatus\m!systems{defining system attribute #1 with number \number\scratchcounter}%
+ \doifnotinset\v!global{#2}{\appendetoks\csname @attr@#1\endcsname\attributeunsetvalue\to\attributesresetlist}}
+
+% expandable so we can \edef them for speed
+
+\def\dosetattribute#1#2{\csname @attr@#1\endcsname#2\relax}
+\def\doresetattribute#1{\csname @attr@#1\endcsname\attributeunsetvalue}
+\def\dogetattribute #1{\number\csname @attr@#1\endcsname}
+\def\dogetattributeid#1{\csname :attr:#1\endcsname}
+
+\let\dompattribute\gobbletwoarguments
+
+\def\resetallattributes{\the\attributesresetlist}
% \appendtoks
% \ctxlua {
@@ -54,4 +103,4 @@
% \stoptracingnodes
% \stoptext
-\endinput
+\protect \endinput
diff --git a/tex/context/base/node-inj.lua b/tex/context/base/node-inj.lua
new file mode 100644
index 000000000..6ba21b39d
--- /dev/null
+++ b/tex/context/base/node-inj.lua
@@ -0,0 +1,608 @@
+if not modules then modules = { } end modules ['node-inj'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- tricky ... fonts.ids is not yet defined .. to be solved (maybe general tex ini)
+
+-- This is very experimental (this will change when we have luatex > .50 and
+-- a few pending thingies are available. Also, Idris needs to make a few more
+-- test fonts.
+
+local next = next
+
+local trace_injections = false trackers.register("nodes.injections", function(v) trace_injections = v end)
+
+fonts = fonts or { }
+fonts.tfm = fonts.tfm or { }
+fonts.ids = fonts.ids or { }
+
+local fontdata = fonts.ids
+
+local glyph = node.id('glyph')
+local kern = node.id('kern')
+
+local traverse_id = node.traverse_id
+local has_attribute = node.has_attribute
+local set_attribute = node.set_attribute
+local insert_node_before = node.insert_before
+local insert_node_after = node.insert_after
+
+local newkern = nodes.kern
+
+local markbase = attributes.private('markbase')
+local markmark = attributes.private('markmark')
+local markdone = attributes.private('markdone')
+local cursbase = attributes.private('cursbase')
+local curscurs = attributes.private('curscurs')
+local cursdone = attributes.private('cursdone')
+local kernpair = attributes.private('kernpair')
+
+local cursives = { }
+local marks = { }
+local kerns = { }
+
+-- currently we do gpos/kern in a bit inofficial way but when we
+-- have the extra fields in glyphnodes to manipulate ht/dp/wd
+-- explicitly i will provide an alternative; also, we can share
+-- tables
+
+function nodes.set_cursive(start,nxt,factor,rlmode,exit,entry,tfmstart,tfmnext)
+ local dx, dy = factor*(exit[1]-entry[1]), factor*(exit[2]-entry[2])
+ local ws, wn = tfmstart.width, tfmnext.width
+ local bound = #cursives + 1
+ set_attribute(start,cursbase,bound)
+ set_attribute(nxt,curscurs,bound)
+ cursives[bound] = { rlmode, dx, dy, ws, wn }
+ return dx, dy, bound
+end
+
+function nodes.set_pair(current,factor,rlmode,spec,tfmchr)
+ local x, y, w, h = factor*spec[1], factor*spec[2], factor*spec[3], factor*spec[4]
+ -- dy = y - h
+ if x ~= 0 or w ~= 0 or y ~= 0 or h ~= 0 then
+ local bound = has_attribute(current,kernpair)
+ if bound then
+ local kb = kerns[bound]
+ kb[2], kb[3], kb[4], kb[5] = kb[2] + x, kb[3] + y, kb[4] + w, kb[5] + h
+ else
+ bound = #kerns + 1
+ set_attribute(current,kernpair,bound)
+ kerns[bound] = { rlmode, x, y, w, h }
+ end
+ return x, y, w, h, bound
+ end
+ return x, y, w, h -- no bound
+end
+
+function nodes.set_kern(current,factor,rlmode,x,tfmchr)
+ local dx = factor*x
+ if dx ~= 0 then
+ local bound = #kerns + 1
+ set_attribute(current,kernpair,bound)
+ kerns[bound] = { rlmode, dx }
+ end
+ return dx, bound
+end
+
+function nodes.set_mark(start,base,factor,rlmode,ba,ma,index) --ba=baseanchor, ma=markanchor
+ local dx, dy = factor*(ba[1]-ma[1]), factor*(ba[2]-ma[2])
+ local bound = has_attribute(base,markbase)
+ if bound then
+ local mb = marks[bound]
+ if mb then
+ if not index then index = #mb + 1 end
+ mb[index] = { dx, dy }
+ set_attribute(start,markmark,bound)
+ set_attribute(start,markdone,index)
+ return dx, dy, bound
+ else
+ logs.report("nodes mark", "possible problem, U+%04X is base without data (id: %s)",base.char,bound)
+ end
+ end
+ index = index or 1
+ bound = #marks + 1
+ set_attribute(base,markbase,bound)
+ set_attribute(start,markmark,bound)
+ set_attribute(start,markdone,index)
+ marks[bound] = { [index] = { dx, dy } }
+ return dx, dy, bound
+end
+
+function nodes.trace_injection(head)
+ local function dir(n)
+ return (n<0 and "r-to-l") or (n>0 and "l-to-r") or ("unset")
+ end
+ local function report(...)
+ logs.report("nodes finisher",...)
+ end
+ report("begin run")
+ for n in traverse_id(glyph,head) do
+ if n.subtype < 256 then
+ local kp = has_attribute(n,kernpair)
+ local mb = has_attribute(n,markbase)
+ local mm = has_attribute(n,markmark)
+ local md = has_attribute(n,markdone)
+ local cb = has_attribute(n,cursbase)
+ local cc = has_attribute(n,curscurs)
+ report("char U+%05X, font=%s",n.char,n.font)
+ if kp then
+ local k = kerns[kp]
+ if k[3] then
+ report(" pairkern: dir=%s, x=%s, y=%s, w=%s, h=%s",dir(k[1]),k[2],k[3],k[4],k[5])
+ else
+ report(" kern: dir=%s, dx=%s",dir(k[1]),k[2])
+ end
+ end
+ if mb then
+ report(" markbase: bound=%s",mb)
+ end
+ if mm then
+ local m = marks[mm]
+ if mb then
+ local m = m[mb]
+ if m then
+ report(" markmark: bound=%s, index=%s, dx=%s, dy=%s",mm,j,m[1],m[2])
+ else
+ report(" markmark: bound=%s, missing index",mm)
+ end
+ else
+ m = m[1]
+ report(" markmark: bound=%s, dx=%s, dy=%s",mm,m[1],m[2])
+ end
+ end
+ if cb then
+ report(" cursbase: bound=%s",cb)
+ end
+ if cc then
+ local c = cursives[cc]
+ report(" curscurs: bound=%s, dir=%s, dx=%s, dy=%s",cc,dir(c[1]),c[2],c[3])
+ end
+ end
+ end
+ report("end run")
+end
+
+-- todo: reuse tables (i.e. no collection), but will be extra fields anyway
+
+function nodes.inject_kerns(head,tail,keep)
+ if trace_injections then
+ nodes.trace_injection(head)
+ end
+ local has_marks, has_cursives, has_kerns = next(marks), next(cursives), next(kerns)
+ if has_marks or has_cursives then
+ -- in the future variant we will not copy items but refs to tables
+ local done, ky, rl, valid, cx, wx = false, { }, { }, { }, { }, { }
+ for n in traverse_id(glyph,head) do
+ if n.subtype < 256 then
+ valid[#valid+1] = n
+ if has_kerns then -- move outside loop
+ local k = has_attribute(n,kernpair)
+ if k then
+ local kk = kerns[k]
+ if kk then
+ local x, y, w, h = kk[2], kk[3], kk[4], kk[5]
+ local dy = y - h
+ if dy ~= 0 then
+ ky[n] = dy
+ end
+ if w ~= 0 or x ~= 0 then
+ wx[n] = kk
+ end
+ rl[n] = kk[1] -- could move in test
+ end
+ end
+ end
+ end
+ end
+ if #valid > 0 then
+ -- we can assume done == true because we have cursives and marks
+ local cx = { }
+ if has_kerns and next(ky) then
+ for n, k in next, ky do
+ n.yoffset = k
+ end
+ end
+ -- todo: reuse t and use maxt
+ if has_cursives then
+ local n_cursbase, n_curscurs, p_cursbase, n, p, nf, tm = nil, nil, nil, nil, nil, nil, nil
+ -- since we need valid[n+1] we can also use a "while true do"
+ local t, d, maxt = { }, { }, 0
+ for i=1,#valid do -- valid == glyphs
+ n = valid[i]
+ if n.font ~= nf then
+ nf = n.font
+ tm = fontdata[nf].marks
+ -- maybe flush
+ maxt = 0
+ end
+ if not tm[n.char] then
+ n_cursbase = has_attribute(n,cursbase)
+ n_curscurs = has_attribute(n,curscurs)
+ if p_cursbase then
+ if p_cursbase == n_curscurs then
+ local c = cursives[n_curscurs]
+ if c then
+ local rlmode, dx, dy, ws, wn = c[1], c[2], c[3], c[4], c[5]
+ if rlmode >= 0 then
+ dx = dx - ws
+ else
+ dx = dx + wn
+ end
+ if dx ~= 0 then
+ cx[n] = dx
+ rl[n] = rlmode
+ end
+ -- if rlmode and rlmode < 0 then
+ dy = -dy
+ -- end
+ maxt = maxt + 1
+ t[maxt] = p
+ d[maxt] = dy
+ else
+ maxt = 0
+ end
+ end
+ elseif maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = t[i].yoffset + ny
+ end
+ maxt = 0
+ end
+ if not n_cursbase and maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = ny
+ end
+ maxt = 0
+ end
+ p_cursbase, p = n_cursbase, n
+ end
+ end
+ if maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = ny
+ end
+ maxt = 0
+ end
+ if not keep then
+ cursives = { }
+ end
+ end
+ if has_marks then
+ local p_markbase, n_markmark = nil, nil
+ for i=1,#valid do
+ local p = valid[i]
+ p_markbase = has_attribute(p,markbase)
+ if p_markbase then
+ local mrks = marks[p_markbase]
+ for n in traverse_id(glyph,p.next) do
+ n_markmark = has_attribute(n,markmark)
+ if p_markbase == n_markmark then
+ local index = has_attribute(n,markdone) or 1
+ local d = mrks[index]
+ if d then
+ -- local rlmode = d[3] -- not used
+ -- if rlmode and rlmode < 0 then
+ -- n.xoffset = p.xoffset + d[1]
+ -- else
+ n.xoffset = p.xoffset - d[1]
+ -- end
+ n.yoffset = p.yoffset + d[2]
+ end
+ else
+ break
+ end
+ end
+ end
+ end
+ if not keep then
+ marks = { }
+ end
+ end
+ -- todo : combine
+ if next(wx) then
+ for n, k in next, wx do
+ -- only w can be nil, can be sped up when w == nil
+ local rl, x, w = k[1], k[2] or 0, k[4] or 0
+ local wx = w - x
+ if rl < 0 then
+ if wx ~= 0 then
+ insert_node_before(head,n,newkern(wx))
+ end
+ if x ~= 0 then
+ insert_node_after (head,n,newkern(x))
+ end
+ else
+ -- if wx ~= 0 then
+ -- insert_node_after(head,n,newkern(wx))
+ -- end
+ if x ~= 0 then
+ insert_node_before(head,n,newkern(x))
+ end
+ end
+ end
+ end
+ if next(cx) then
+ for n, k in next, cx do
+ if k ~= 0 then
+ local rln = rl[n]
+ if rln and rln < 0 then
+ insert_node_before(head,n,newkern(-k))
+ else
+ insert_node_before(head,n,newkern(k))
+ end
+ end
+ end
+ end
+ if not keep then
+ kerns = { }
+ end
+ return head, true
+ elseif not keep then
+ kerns, cursives, marks = { }, { }, { }
+ end
+ elseif has_kerns then
+ -- we assume done is true because there are kerns
+ for n in traverse_id(glyph,head) do
+ local k = has_attribute(n,kernpair)
+ if k then
+ local kk = kerns[k]
+ if kk then
+ -- only w can be nil, can be sped up when w == nil
+ local rl, x, y, w = kk[1], kk[2] or 0, kk[3] or 0, kk[4] or 0
+ if y ~= 0 then
+ n.yoffset = y -- todo: h ?
+ end
+ local wx = w - x
+ if rl < 0 then
+ if wx ~= 0 then
+ insert_node_before(head,n,newkern(wx))
+ end
+ if x ~= 0 then
+ insert_node_after (head,n,newkern(x))
+ end
+ else
+ -- if wx ~= 0 then
+ -- insert_node_after(head,n,newkern(wx))
+ -- end
+ if x ~= 0 then
+ insert_node_before(head,n,newkern(x))
+ end
+ end
+ end
+ end
+ end
+ if not keep then
+ kerns = { }
+ end
+ return head, true
+ end
+ return head, false
+end
+
+-- -- -- KEEP OLD ONE, THE NEXT IS JUST OPTIMIZED -- -- --
+
+function nodes.XXXXXXXxinject_kerns(head,tail,keep)
+ if trace_injections then
+ nodes.trace_injection(head)
+ end
+ local has_marks, has_cursives, has_kerns = next(marks), next(cursives), next(kerns)
+ if has_marks or has_cursives then
+ -- in the future variant we will not copy items but refs to tables
+ local done, ky, valid, cx, wx = false, { }, { }, { }, { }
+ for n in traverse_id(glyph,head) do
+ if n.subtype < 256 then
+ valid[#valid+1] = n
+ if has_kerns then -- move outside loop
+ local k = has_attribute(n,kernpair)
+ if k then
+ local kk = kerns[k]
+ if kk then
+ local x, y, w, h = kk[2], kk[3], kk[4], kk[5]
+ local dy = y - h
+ if dy ~= 0 then
+ ky[n] = dy
+ end
+ if w ~= 0 or x ~= 0 then
+ wx[n] = kk
+ end
+ end
+ end
+ end
+ end
+ end
+ if #valid > 0 then
+ -- we can assume done == true because we have cursives and marks
+ local cx = { }
+ if has_kerns and next(ky) then
+ for n, k in next, ky do
+ n.yoffset = k
+ end
+ end
+ -- todo: reuse t and use maxt
+ if has_cursives then
+ local n_cursbase, n_curscurs, p_cursbase, n, p, nf, tm = nil, nil, nil, nil, nil, nil, nil
+ -- since we need valid[n+1] we can also use a "while true do"
+ local t, d, maxt = { }, { }, 0
+ for i=1,#valid do -- valid == glyphs
+ n = valid[i]
+ if n.font ~= nf then
+ nf = n.font
+ tm = fontdata[nf].marks
+ -- maybe flush
+ maxt = 0
+ end
+ if not tm[n.char] then
+ n_cursbase = has_attribute(n,cursbase)
+ n_curscurs = has_attribute(n,curscurs)
+ if p_cursbase then
+ if p_cursbase == n_curscurs then
+ local c = cursives[n_curscurs]
+ if c then
+ local rlmode, dx, dy, ws, wn = c[1], c[2], c[3], c[4], c[5]
+ if rlmode >= 0 then
+ dx = dx - ws
+ else
+ dx = dx + wn
+ end
+ if dx ~= 0 then
+if rlmode < 0 then
+ cx[n] = -dx
+else
+ cx[n] = dx
+end
+ end
+ -- if rlmode and rlmode < 0 then
+ dy = -dy
+ -- end
+ maxt = maxt + 1
+ t[maxt] = p
+ d[maxt] = dy
+ else
+ maxt = 0
+ end
+ end
+ elseif maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = t[i].yoffset + ny
+ end
+ maxt = 0
+ end
+ if not n_cursbase and maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = ny
+ end
+ maxt = 0
+ end
+ p_cursbase, p = n_cursbase, n
+ end
+ end
+ if maxt > 0 then
+ local ny = n.yoffset
+ for i=maxt,1,-1 do
+ ny = ny + d[i]
+ t[i].yoffset = ny
+ end
+ maxt = 0
+ end
+ if not keep then
+ cursives = { }
+ end
+ end
+ if has_marks then
+ local p_markbase, n_markmark = nil, nil
+ for i=1,#valid do
+ local p = valid[i]
+ p_markbase = has_attribute(p,markbase)
+ if p_markbase then
+ local mrks = marks[p_markbase]
+ for n in traverse_id(glyph,p.next) do
+ n_markmark = has_attribute(n,markmark)
+ if p_markbase == n_markmark then
+ local index = has_attribute(n,markdone) or 1
+ local d = mrks[index]
+ if d then
+ local d1, d2 = d[1], d[2]
+ if d1 ~= 0 then
+ n.xoffset = p.xoffset - d[1]
+ end
+ if d2 ~= 0 then
+ n.yoffset = p.yoffset + d[2]
+ end
+ end
+ else
+ break
+ end
+ end
+ end
+ end
+ if not keep then
+ marks = { }
+ end
+ end
+ -- todo : combine
+ if next(wx) then
+ for n, k in next, wx do
+ -- only w can be nil, can be sped up when w == nil
+ local rl, x, w = k[1], k[2] or 0, k[4] or 0
+ local wx = w - x
+ if rl < 0 then
+ if wx ~= 0 then
+ insert_node_before(head,n,newkern(wx))
+ end
+ if x ~= 0 then
+ insert_node_after (head,n,newkern(x))
+ end
+ else
+ -- if wx ~= 0 then
+ -- insert_node_after(head,n,newkern(wx))
+ -- end
+ if x ~= 0 then
+ insert_node_before(head,n,newkern(x))
+ end
+ end
+ end
+ end
+ if next(cx) then
+ for n, k in next, cx do
+ insert_node_before(head,n,newkern(k))
+ end
+ end
+ if not keep then
+ kerns = { }
+ end
+ return head, true
+ elseif not keep then
+ kerns, cursives, marks = { }, { }, { }
+ end
+ elseif has_kerns then
+ -- we assume done is true because there are kerns
+ for n in traverse_id(glyph,head) do
+ local k = has_attribute(n,kernpair)
+ if k then
+ local kk = kerns[k]
+ if kk then
+ -- only w can be nil, can be sped up when w == nil
+ local rl, x, y, w = kk[1], kk[2] or 0, kk[3] or 0, kk[4] or 0
+ if y ~= 0 then
+ n.yoffset = y -- todo: h ?
+ end
+ local wx = w - x
+ if rl < 0 then
+ if wx ~= 0 then
+ insert_node_before(head,n,newkern(wx))
+ end
+ if x ~= 0 then
+ insert_node_after (head,n,newkern(x))
+ end
+ else
+ -- if wx ~= 0 then
+ -- insert_node_after(head,n,newkern(wx))
+ -- end
+ if x ~= 0 then
+ insert_node_before(head,n,newkern(x))
+ end
+ end
+ end
+ end
+ end
+ if not keep then
+ kerns = { }
+ end
+ return head, true
+ end
+ return head, false
+end
diff --git a/tex/context/base/node-par.lua b/tex/context/base/node-par.lua
index 7dd95ea5d..f275a1035 100644
--- a/tex/context/base/node-par.lua
+++ b/tex/context/base/node-par.lua
@@ -11,7 +11,7 @@ parbuilders.constructors = parbuilders.constructors or { }
parbuilders.names = parbuilders.names or { }
parbuilders.attribute = attributes.numbers['parbuilder'] or 999
-input.storage.register(false, "parbuilders.names", parbuilders.names, "parbuilders.names")
+storage.register("parbuilders.names", parbuilders.names, "parbuilders.names")
-- store parbuilders.names
diff --git a/tex/context/base/node-par.tex b/tex/context/base/node-par.tex
index 2e628c066..7f7ca9977 100644
--- a/tex/context/base/node-par.tex
+++ b/tex/context/base/node-par.tex
@@ -1,5 +1,5 @@
%D \module
-%D [ file=core-spa,
+%D [ file=node-par,
%D version=2008.09.30,
%D title=\CONTEXT\ Node Macros,
%D subtitle=Paragraph Building,
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Core Macros / Paragraph Building}
+\writestatus{loading}{ConTeXt Node Macros / Paragraph Building}
%D This is very experimental, undocumented, subjected to changes, etc. just as
%D the underlying interfaces.
@@ -30,7 +30,7 @@
\registerctxluafile{node-par}{1.001}
-\defineattribute[parbuilder]
+\definesystemattribute[parbuilder]
\newcount\nofparbuilders
diff --git a/tex/context/base/node-pro.lua b/tex/context/base/node-pro.lua
new file mode 100644
index 000000000..575941fe5
--- /dev/null
+++ b/tex/context/base/node-pro.lua
@@ -0,0 +1,155 @@
+if not modules then modules = { } end modules ['node-pro'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local utf = unicode.utf8
+local format, concat = string.format, table.concat
+
+local trace_callbacks = false trackers.register("nodes.callbacks", function(v) trace_callbacks = v end)
+
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+local glyph = node.id('glyph')
+local disc = node.id('disc')
+local mark = node.id('mark')
+
+local slide_nodes = node.slide
+local free_node = node.free
+local first_character = node.first_character
+
+nodes.processors = nodes.processors or { }
+
+-- vbox: grouptype: vbox vtop output split_off split_keep | box_type: exactly|aditional
+-- hbox: grouptype: hbox adjusted_hbox(=hbox_in_vmode) | box_type: exactly|aditional
+
+lists = lists or { }
+chars = chars or { }
+words = words or { } -- not used yet
+
+-- or just:
+--
+-- nodes.process_page = tasks.actions("shipouts")
+
+local actions = tasks.actions("processors")
+
+local n = 0
+
+local function reconstruct(head)
+ local t = { }
+ local h = head
+ while h do
+ local id = h.id
+ if id == glyph then
+ t[#t+1] = utf.char(h.char)
+ else
+ t[#t+1] = "[]"
+ end
+ h = h.next
+ end
+ return concat(t)
+end
+
+local function tracer(what,state,head,groupcode,before,after,show)
+ if not groupcode then
+ groupcode = "unknown"
+ elseif groupcode == "" then
+ groupcode = "mvl"
+ end
+ n = n + 1
+ if show then
+ texio.write_nl(format("%s %s: %s, group: %s, nodes: %s -> %s, string: %s",what,n,state,groupcode,before,after,reconstruct(head)))
+ else
+ texio.write_nl(format("%s %s: %s, group: %s, nodes: %s -> %s",what,n,state,groupcode,before,after))
+ end
+end
+
+nodes.processors.enabled = true -- thsi will become a proper state (like trackers)
+
+function nodes.processors.pre_linebreak_filter(head,groupcode) -- todo: tail
+ local first, found = first_character(head)
+ if found then
+ if trace_callbacks then
+ local before = nodes.count(head,true)
+ local head, tail, done = actions(head,slide_nodes(head))
+ local after = nodes.count(head,true)
+ if done then
+ tracer("pre_linebreak","changed",head,groupcode,before,after,true)
+ else
+ tracer("pre_linebreak","unchanged",head,groupcode,before,after,true)
+ end
+ return (done and head) or true
+ else
+ local head, tail, done = actions(head,slide_nodes(head))
+ return (done and head) or true
+ end
+ elseif trace_callbacks then
+ local n = nodes.count(head,false)
+ tracer("pre_linebreak","no chars",head,groupcode,n,n)
+ end
+ return true
+end
+
+function nodes.processors.hpack_filter(head,groupcode) -- todo: tail
+ local first, found = first_character(head)
+ if found then
+ if trace_callbacks then
+ local before = nodes.count(head,true)
+ local head, tail, done = actions(head,slide_nodes(head))
+ local after = nodes.count(head,true)
+ if done then
+ tracer("hpack","changed",head,groupcode,before,after,true)
+ else
+ tracer("hpack","unchanged",head,groupcode,before,after,true)
+ end
+ return (done and head) or true
+ else
+ local head, tail, done = actions(head,slide_nodes(head))
+ return (done and head) or true
+ end
+ elseif trace_callbacks then
+ local n = nodes.count(head,false)
+ tracer("hpack","no chars",head,groupcode,n,n)
+ end
+ return true
+end
+
+callback.register('pre_linebreak_filter', nodes.processors.pre_linebreak_filter)
+callback.register('hpack_filter' , nodes.processors.hpack_filter)
+
+local actions = tasks.actions("finalizers")
+
+function nodes.processors.post_linebreak_filter(head,groupcode) -- todo: tail
+ local first, found = first_character(head)
+ if found then
+ if trace_callbacks then
+ local before = nodes.count(head,true)
+ local head, tail, done = actions(head,slide_nodes(head))
+ local after = nodes.count(head,true)
+ if done then
+ tracer("finalizer","changed",head,groupcode,before,after,true)
+ else
+ tracer("finalizer","unchanged",head,groupcode,before,after,true)
+ end
+ return (done and head) or true
+ else
+ local head, tail, done = actions(head,slide_nodes(head))
+ return (done and head) or true
+ end
+ elseif trace_callbacks then
+ local n = nodes.count(head,false)
+ tracer("finalizer","no chars",head,groupcode,n,n)
+ end
+ return true
+end
+
+callback.register('post_linebreak_filter', nodes.processors.post_linebreak_filter)
+
+statistics.register("h-node processing time", function()
+ if statistics.elapsedindeed(nodes) then
+ return format("%s seconds including kernel", statistics.elapsedtime(nodes))
+ end
+end)
diff --git a/tex/context/base/node-res.lua b/tex/context/base/node-res.lua
new file mode 100644
index 000000000..c8d815be4
--- /dev/null
+++ b/tex/context/base/node-res.lua
@@ -0,0 +1,110 @@
+if not modules then modules = { } end modules ['node-res'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local gmatch, format = string.gmatch, string.format
+local copy_node, free_node, new_node = node.copy, node.free, node.new
+
+--[[ldx--
+
The next function is not that much needed but in we use
+for debugging node management.
+--ldx]]--
+
+nodes = nodes or { }
+
+local reserved = { }
+
+function nodes.register(n)
+ reserved[#reserved+1] = n
+ return n
+end
+
+function nodes.cleanup_reserved(nofboxes) -- todo
+ nodes.tracers.steppers.reset() -- todo: make a registration subsystem
+ local nr, nl = #reserved, 0
+ for i=1,nr do
+ free_node(reserved[i])
+ end
+ if nofboxes then
+ local tb = tex.box
+ for i=0,nofboxes do
+ local l = tb[i]
+ if l then
+ free_node(tb[i])
+ nl = nl + 1
+ end
+ end
+ end
+ reserved = { }
+ return nr, nl, nofboxes -- can be nil
+end
+
+function nodes.usage()
+ local t = { }
+ for n, tag in gmatch(status.node_mem_usage,"(%d+) ([a-z_]+)") do
+ t[tag] = n
+ end
+ return t
+end
+
+local pdfliteral = nodes.register(new_node("whatsit",8)) pdfliteral.mode = 1
+local disc = nodes.register(new_node("disc"))
+local kern = nodes.register(new_node("kern",1))
+local penalty = nodes.register(new_node("penalty"))
+local glue = nodes.register(new_node("glue"))
+local glue_spec = nodes.register(new_node("glue_spec"))
+local glyph = nodes.register(new_node("glyph",0))
+local textdir = nodes.register(new_node("whatsit",7))
+
+function nodes.glyph(fnt,chr)
+ local n = copy_node(glyph)
+ if fnt then n.font = fnt end
+ if chr then n.char = chr end
+ return n
+end
+function nodes.penalty(p)
+ local n = copy_node(penalty)
+ n.penalty = p
+ return n
+end
+function nodes.kern(k)
+ local n = copy_node(kern)
+ n.kern = k
+ return n
+end
+function nodes.glue(width,stretch,shrink)
+ local n, s = copy_node(glue), copy_node(glue_spec)
+ s.width, s.stretch, s.shrink = width, stretch, shrink
+ n.spec = s
+ return n
+end
+function nodes.glue_spec(width,stretch,shrink)
+ local s = copy_node(glue_spec)
+ s.width, s.stretch, s.shrink = width, stretch, shrink
+ return s
+end
+function nodes.disc()
+ return copy_node(disc)
+end
+function nodes.pdfliteral(str)
+ local t = copy_node(pdfliteral)
+ t.data = str
+ return t
+end
+function nodes.textdir(dir)
+ local t = copy_node(textdir)
+ t.dir = dir
+ return t
+end
+
+statistics.register("cleaned up reserved nodes", function()
+ return format("%s nodes, %s lists of %s", nodes.cleanup_reserved(tex.count["lastallocatedbox"]))
+end) -- \topofboxstack
+
+statistics.register("node memory usage", function() -- comes after cleanup !
+ return status.node_mem_usage
+end)
diff --git a/tex/context/base/node-seq.lua b/tex/context/base/node-seq.lua
index 2fd4f81aa..2794c34b9 100644
--- a/tex/context/base/node-seq.lua
+++ b/tex/context/base/node-seq.lua
@@ -6,12 +6,28 @@ if not modules then modules = { } end modules ['node-seq'] = {
license = "see context related readme files"
}
--- we assume namespace usage, i.e. unique names for functions
+--[[ldx--
+
Here we implement a mechanism for chaining the special functions
+that we use in to deal with mode list processing. We
+assume that namespaces for the functions are used, but for speed we
+use locals to refer to them when compiling the chain.
+--ldx]]--
-local format, concat = string.format, table.concat
+local format, gsub, concat, gmatch = string.format, string.gsub, table.concat, string.gmatch
sequencer = sequencer or { }
+local function validaction(action)
+ local g = _G
+ for str in gmatch(action,"[^%.]+") do
+ g = g[str]
+ if not g then
+ return false
+ end
+ end
+ return true
+end
+
function sequencer.reset()
return {
list = { },
@@ -34,18 +50,18 @@ function sequencer.appendgroup(t,group,where)
list[group] = { }
end
-function sequencer.prependaction(t,group,action,where,kind)
+function sequencer.prependaction(t,group,action,where,kind,force)
local g = t.list[group]
- if g then
+ if g and (force or validaction(action)) then
table.remove_value(g,action)
table.insert_before_value(g,where,action)
t.kind[action] = kind
end
end
-function sequencer.appendaction(t,group,action,where,kind)
+function sequencer.appendaction(t,group,action,where,kind,force)
local g = t.list[group]
- if g then
+ if g and (force or validaction(action)) then
table.remove_value(g,action)
table.insert_after_value(g,where,action)
t.kind[action] = kind
@@ -56,9 +72,9 @@ function sequencer.setkind(t,action,kind)
t.kind[action] = kind
end
-function sequencer.removeaction(t,group,action)
+function sequencer.removeaction(t,group,action,force)
local g = t.list[group]
- if g then
+ if g and (force or validaction(action)) then
table.remove_value(g,action)
end
end
@@ -75,7 +91,7 @@ function sequencer.compile(t,compiler)
end
local function localize(str)
- return str:gsub("%.","_")
+ return (gsub(str,"%.","_"))
end
local template = [[
@@ -96,12 +112,12 @@ function sequencer.tostring(t)
calls[#calls+1] = format(" %s(...) -- %s %i", localized, group, i)
end
end
- return template:format(concat(vars,"\n"),concat(calls,"\n"))
+ return format(template,concat(vars,"\n"),concat(calls,"\n"))
end
local template = [[
%s
-return function(head,tail)
+return function(head,tail,...)
local ok, done = false, false
%s
return head, tail, done
@@ -117,15 +133,16 @@ function sequencer.nodeprocessor(t)
local localized = localize(action)
vars[#vars+1] = format("local %s = %s",localized,action)
if kind[action] == "nohead" then
- calls[#calls+1] = format(" ok = %s(head,tail) done = done or ok -- %s %i",localized,group,i)
+ calls[#calls+1] = format(" ok = %s(head,tail,...) done = done or ok -- %s %i",localized,group,i)
elseif kind[action] == "notail" then
- calls[#calls+1] = format(" head, ok = %s(head,tail) done = done or ok -- %s %i",localized,group,i)
+ calls[#calls+1] = format(" head, ok = %s(head,tail,...) done = done or ok -- %s %i",localized,group,i)
else
- calls[#calls+1] = format(" head, tail, ok = %s(head,tail) done = done or ok -- %s %i",localized,group,i)
+ calls[#calls+1] = format(" head, tail, ok = %s(head,tail,...) done = done or ok -- %s %i",localized,group,i)
end
end
end
- return template:format(concat(vars,"\n"),concat(calls,"\n"))
+ local processor = format(template,concat(vars,"\n"),concat(calls,"\n"))
+ return processor
end
--~ hans = {}
diff --git a/tex/context/base/node-ser.lua b/tex/context/base/node-ser.lua
new file mode 100644
index 000000000..65c071c00
--- /dev/null
+++ b/tex/context/base/node-ser.lua
@@ -0,0 +1,274 @@
+if not modules then modules = { } end modules ['node-ser'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- beware, some field names will change in a next releases
+-- of luatex; this is pretty old code that needs an overhaul
+
+local type, format, concat = type, string.format, table.concat
+
+local ctxcatcodes = tex.ctxcatcodes
+
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+
+local traverse = node.traverse
+local node_fields = node.fields
+local node_type = node.type
+
+local expand = table.tohash {
+ "list", -- list_ptr & ins_ptr & adjust_ptr
+ "pre", --
+ "post", --
+ "spec", -- glue_ptr
+ "top_skip", --
+ "attr", --
+ "replace", -- nobreak
+ "components", -- lig_ptr
+ "box_left", --
+ "box_right", --
+ "glyph", -- margin_char
+ "leader", -- leader_ptr
+ "action", -- action_ptr
+ "value", -- user_defined nodes with subtype 'a' en 'n'
+}
+
+-- page_insert: "height", "last_ins_ptr", "best_ins_ptr"
+-- split_insert: "height", "last_ins_ptr", "best_ins_ptr", "broken_ptr", "broken_ins"
+
+local ignore = table.tohash {
+ "page_insert",
+ "split_insert",
+ "ref_count",
+}
+
+local dimension = table.tohash {
+ "width", "height", "depth", "shift",
+ "stretch", "shrink",
+ "xoffset", "yoffset",
+ "surround",
+ "kern",
+ "box_left_width", "box_right_width"
+}
+
+-- flat: don't use next, but indexes
+-- verbose: also add type
+-- can be sped up
+
+nodes.dimensionfields = dimension
+nodes.listablefields = expand
+nodes.ignorablefields = ignore
+
+-- not ok yet:
+
+function nodes.astable(n,sparse) -- not yet ok
+ local f, t = node_fields(n.id,n.subtype), { }
+ for i=1,#f do
+ local v = f[i]
+ local d = n[v]
+ if d then
+ if ignore[v] or v == "id" then
+ -- skip
+ elseif expand[v] then -- or: type(n[v]) ~= "string" or type(n[v]) ~= "number" or type(n[v]) ~= "table"
+ t[v] = "pointer to list"
+ elseif sparse then
+ if (type(d) == "number" and d ~= 0) or (type(d) == "string" and d ~= "") then
+ t[v] = d
+ end
+ else
+ t[v] = d
+ end
+ end
+ end
+ t.type = node_type(n.id)
+ return t
+end
+
+-- under construction:
+
+local function totable(n,flat,verbose)
+ -- todo: no local function
+ local function to_table(n,flat,verbose)
+ local f = node_fields(n.id,n.subtype)
+ local tt = { }
+ for k=1,#f do
+ local v = f[k]
+ local nv = n[v]
+ if nv then
+ if ignore[v] then
+ -- skip
+ elseif expand[v] then
+ if type(nv) == "number" or type(nv) == "string" then
+ tt[v] = nv
+ else
+ tt[v] = totable(nv,flat,verbose)
+ end
+ elseif type(nv) == "table" then
+ tt[v] = nv -- totable(nv,flat,verbose) -- data
+ else
+ tt[v] = nv
+ end
+ end
+ end
+ if verbose then
+ tt.type = node_type(tt.id)
+ end
+ return tt
+ end
+ if n then
+ if flat then
+ local t = { }
+ while n do
+ t[#t+1] = to_table(n,flat,verbise)
+ n = n.next
+ end
+ return t
+ else
+ local t = to_table(n)
+ if n.next then
+ t.next = totable(n.next,flat,verbose)
+ end
+ return t
+ end
+ else
+ return { }
+ end
+end
+
+nodes.totable = totable
+
+local function key(k)
+ return ((type(k) == "number") and "["..k.."]") or k
+end
+
+-- not ok yet; this will become a module
+
+local function serialize(root,name,handle,depth,m)
+ handle = handle or print
+ if depth then
+ depth = depth .. " "
+ handle(format("%s%s={",depth,key(name)))
+ else
+ depth = ""
+ local tname = type(name)
+ if tname == "string" then
+ if name == "return" then
+ handle("return {")
+ else
+ handle(name .. "={")
+ end
+ elseif tname == "number" then
+ handle("[" .. name .. "]={")
+ else
+ handle("t={")
+ end
+ end
+ if root then
+ local fld
+ if root.id then
+ fld = node_fields(root.id,root.subtype) -- we can cache these (todo)
+ else
+ fld = table.sortedkeys(root)
+ end
+ if type(root) == 'table' and root['type'] then -- userdata or table
+ handle(format("%s %s=%q,",depth,'type',root['type']))
+ end
+ for f=1,#fld do
+ local k = fld[f]
+ if k == "ref_count" then
+ -- skip
+ elseif k then
+ local v = root[k]
+ local t = type(v)
+ if t == "number" then
+ if v == 0 then
+ -- skip
+ else
+ handle(format("%s %s=%s,",depth,key(k),v))
+ end
+ elseif t == "string" then
+ if v == "" then
+ -- skip
+ else
+ handle(format("%s %s=%q,",depth,key(k),v))
+ end
+ elseif v then -- userdata or table
+ serialize(v,k,handle,depth,m+1)
+ end
+ end
+ end
+ if root['next'] then -- userdata or table
+ serialize(root['next'],'next',handle,depth,m+1)
+ end
+ end
+ if m and m > 0 then
+ handle(format("%s},",depth))
+ else
+ handle(format("%s}",depth))
+ end
+end
+
+function nodes.serialize(root,name)
+ local t = { }
+ local function flush(s)
+ t[#t+1] = s
+ end
+ serialize(root, name, flush, nil, 0)
+ return concat(t,"\n")
+end
+
+function nodes.serializebox(n,flat,verbose,name)
+ return nodes.serialize(nodes.totable(tex.box[n],flat,verbose),name)
+end
+
+function nodes.visualizebox(...)
+ tex.print(ctxcatcodes,"\\starttyping")
+ tex.print(nodes.serializebox(...))
+ tex.print("\\stoptyping")
+end
+
+function nodes.list(head,n) -- name might change to nodes.type
+ if not n then
+ tex.print(ctxcatcodes,"\\starttyping")
+ end
+ while head do
+ local id = head.id
+ tex.print(string.rep(" ",n or 0) .. tostring(head) .. "\n")
+ if id == hlist or id == vlist then
+ nodes.list(head.list,(n or 0)+1)
+ end
+ head = head.next
+ end
+ if not n then
+ tex.print("\\stoptyping")
+ end
+end
+
+function nodes.print(head,n)
+ while head do
+ local id = head.id
+ texio.write_nl(string.rep(" ",n or 0) .. tostring(head))
+ if id == hlist or id == vlist then
+ nodes.print(head.list,(n or 0)+1)
+ end
+ head = head.next
+ end
+end
+
+function nodes.check_for_leaks(sparse)
+ local l = { }
+ local q = node.usedlist()
+ for p in traverse(q) do
+ local s = table.serialize(nodes.astable(p,sparse),node_type(p.id))
+ l[s] = (l[s] or 0) + 1
+ end
+ node.flush_list(q)
+ for k, v in next, l do
+ texio.write_nl(format("%s * %s", v, k))
+ end
+end
+
diff --git a/tex/context/base/node-shp.lua b/tex/context/base/node-shp.lua
new file mode 100644
index 000000000..0383d8c40
--- /dev/null
+++ b/tex/context/base/node-shp.lua
@@ -0,0 +1,66 @@
+if not modules then modules = { } end modules ['node-shp'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local hlist = node.id('hlist')
+local vlist = node.id('vlist')
+local disc = node.id('disc')
+local mark = node.id('mark')
+
+local free_node = node.free
+
+local function cleanup_page(head) -- rough
+ local prev, start = nil, head
+ while start do
+ local id, nx = start.id, start.next
+ if id == disc or id == mark then
+ if prev then
+ prev.next = nx
+ end
+ if start == head then
+ head = nx
+ end
+ local tmp = start
+ start = nx
+ free_node(tmp)
+ elseif id == hlist or id == vlist then
+ local sl = start.list
+ if sl then
+ start.list = cleanup_page(sl)
+ prev, start = start, nx
+ else
+ if prev then
+ prev.next = nx
+ end
+ if start == head then
+ head = nx
+ end
+ local tmp = start
+ start = nx
+ free_node(tmp)
+ end
+ else
+ prev, start = start, nx
+ end
+ end
+ return head
+end
+
+nodes.cleanup_page_first = false
+
+function nodes.cleanup_page(head)
+ if nodes.cleanup_page_first then
+ head = cleanup_page(head)
+ end
+ return head, false
+end
+
+local actions = tasks.actions("shipouts")
+
+function nodes.process_page(head) -- problem, attr loaded before node, todo ...
+ return actions(head) -- no tail
+end
diff --git a/tex/context/base/node-tex.lua b/tex/context/base/node-tex.lua
new file mode 100644
index 000000000..563e6a397
--- /dev/null
+++ b/tex/context/base/node-tex.lua
@@ -0,0 +1,54 @@
+if not modules then modules = { } end modules ['node-tex'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+kernel = kernel or { }
+
+local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
+local hyphenate, ligaturing, kerning = lang.hyphenate, node.ligaturing, node.kerning
+
+function kernel.hyphenation(head,tail) -- lang.hyphenate returns done
+ if head == tail then
+ return head, tail, false
+ else
+ -- starttiming(kernel)
+ -- local done = hyphenate(head,tail)
+ -- stoptiming(kernel)
+ -- return head, tail, done
+ return head, tail, hyphenate(head,tail)
+ end
+end
+
+function kernel.ligaturing(head,tail) -- node.ligaturing returns head,tail,done
+ if head == tail then
+ return head, tail, false
+ else
+ -- starttiming(kernel)
+ -- local head, tail, done = ligaturing(head,tail)
+ -- stoptiming(kernel)
+ -- return head, tail, done
+ return ligaturing(head,tail)
+ end
+end
+
+function kernel.kerning(head,tail) -- node.kerning returns head,tail,done
+ if head == tail then
+ return head, tail, false
+ else
+ -- starttiming(kernel)
+ -- local head, tail, done = kerning(head,tail)
+ -- stoptiming(kernel)
+ -- return head, tail, done
+ return kerning(head,tail)
+ end
+end
+
+callback.register('hyphenate' , false)
+callback.register('ligaturing', false)
+callback.register('kerning' , false)
diff --git a/tex/context/base/node-tra.lua b/tex/context/base/node-tra.lua
new file mode 100644
index 000000000..ef13499f9
--- /dev/null
+++ b/tex/context/base/node-tra.lua
@@ -0,0 +1,399 @@
+if not modules then modules = { } end modules ['node-tra'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+
This is rather experimental. We need more control and some of this
+might become a runtime module instead.
+--ldx]]--
+
+local utf = unicode.utf8
+local format, match, concat, utfchar = string.format, string.match, table.concat, utf.char
+
+local ctxcatcodes = tex.ctxcatcodes
+
+fonts = fonts or { }
+fonts.tfm = fonts.tfm or { }
+fonts.ids = fonts.ids or { }
+
+nodes = nodes or { }
+nodes.tracers = nodes.tracers or { }
+nodes.tracers.characters = nodes.tracers.characters or { }
+nodes.tracers.steppers = nodes.tracers.steppers or { }
+
+local glyph = node.id('glyph')
+local disc = node.id('disc')
+local glue = node.id('glue')
+local kern = node.id('kern')
+local whatsit = node.id('whatsit')
+
+local copy_node_list = node.copy_list
+local hpack_node_list = node.hpack
+local free_node_list = node.flush_list
+local first_character = node.first_character
+local node_type = node.type
+local traverse_nodes = node.traverse
+
+local texsprint = tex.sprint
+local fontdata = fonts.ids
+
+function nodes.tracers.characters.collect(head,list,tag,n)
+ n = n or 0
+ local ok, fn = false, nil
+ while head do
+ local id = head.id
+ if id == glyph then
+ local f = head.font
+ if f ~= fn then
+ ok, fn = false, f
+ end
+ local c = head.char
+ local i = fontdata[f].indices[c] or 0
+ if not ok then
+ ok = true
+ n = n + 1
+ list[n] = list[n] or { }
+ list[n][tag] = { }
+ end
+ local l = list[n][tag]
+ l[#l+1] = { c, f, i }
+ elseif id == disc then
+ -- skip
+ else
+ ok = false
+ end
+ head = head.next
+ end
+end
+
+function nodes.tracers.characters.equal(ta, tb)
+ if #ta ~= #tb then
+ return false
+ else
+ for i=1,#ta do
+ local a, b = ta[i], tb[i]
+ if a[1] ~= b[1] or a[2] ~= b[2] or a[3] ~= b[3] then
+ return false
+ end
+ end
+ end
+ return true
+end
+
+function nodes.tracers.characters.string(t)
+ local tt = { }
+ for i=1,#t do
+ tt[i] = utfchar(t[i][1])
+ end
+ return concat(tt,"")
+end
+
+function nodes.tracers.characters.unicodes(t,decimal)
+ local tt = { }
+ for i=1,#t do
+ local n = t[i][1]
+ if n == 0 then
+ tt[i] = "-"
+ elseif decimal then
+ tt[i] = n
+ else
+ tt[i] = format("U+%04X",n)
+ end
+ end
+ return concat(tt," ")
+end
+
+function nodes.tracers.characters.indices(t,decimal)
+ local tt = { }
+ for i=1,#t do
+ local n = t[i][3]
+ if n == 0 then
+ tt[i] = "-"
+ elseif decimal then
+ tt[i] = n
+ else
+ tt[i] = format("U+%04X",n)
+ end
+ end
+ return concat(tt," ")
+end
+
+function nodes.tracers.characters.start()
+ local npc = nodes.process_characters
+ local list = { }
+ function nodes.process_characters(head)
+ local n = #list
+ nodes.tracers.characters.collect(head,list,'before',n)
+ local h, d = npc(head)
+ nodes.tracers.characters.collect(head,list,'after',n)
+ if #list > n then
+ list[#list+1] = { }
+ end
+ return h, d
+ end
+ function nodes.tracers.characters.stop()
+ tracers.list['characters'] = list
+ lmx.set('title', 'ConTeXt Character Processing Information')
+ lmx.set('color-background-one', lmx.get('color-background-yellow'))
+ lmx.set('color-background-two', lmx.get('color-background-purple'))
+ lmx.show('context-characters.lmx')
+ lmx.restore()
+ nodes.process_characters = npc
+ tasks.restart("processors", "characters")
+ end
+ tasks.restart("processors", "characters")
+end
+
+local stack = { }
+
+function nodes.tracers.start(tag)
+ stack[#stack+1] = tag
+ local tracer = nodes.tracers[tag]
+ if tracer and tracer.start then
+ tracer.start()
+ end
+end
+function nodes.tracers.stop()
+ local tracer = stack[#stack]
+ if tracer and tracer.stop then
+ tracer.stop()
+ end
+ stack[#stack] = nil
+end
+
+-- experimental
+
+local collection, collecting, messages = { }, false, { }
+
+function nodes.tracers.steppers.start()
+ collecting = true
+end
+
+function nodes.tracers.steppers.stop()
+ collecting = false
+end
+
+function nodes.tracers.steppers.reset()
+ for i=1,#collection do
+ local c = collection[i]
+ if c then
+ free_node_list(c)
+ end
+ end
+ collection, messages = { }, { }
+end
+
+function nodes.tracers.steppers.nofsteps()
+ return tex.write(#collection)
+end
+
+function nodes.tracers.steppers.glyphs(n,i)
+ local c = collection[i]
+ if c then
+ tex.box[n] = hpack_node_list(copy_node_list(c))
+ end
+end
+
+function nodes.tracers.steppers.features()
+-- local f = first_character(collection[1])
+-- if f then -- something fishy with first_character
+ local f = collection[1]
+ while f do
+ if f.id == glyph then
+ local tfmdata, t = fontdata[f.font], { }
+ for feature, value in table.sortedpairs(tfmdata.shared.features) do
+ if feature == "number" or feature == "features" then
+ -- private
+ elseif type(value) == "boolean" then
+ if value then
+ t[#t+1] = format("%s=yes",feature)
+ else
+ -- skip
+ end
+ else
+ t[#t+1] = format("%s=%s",feature,value)
+ end
+ end
+ if #t > 0 then
+ texsprint(ctxcatcodes,concat(t,", "))
+ else
+ texsprint(ctxcatcodes,"no features")
+ end
+ return
+ end
+ f = f.next
+ end
+end
+
+function nodes.tracers.fontchar(font,char)
+ local n = nodes.glyph()
+ n.font, n.char, n.subtype = font, char, 256
+ node.write(n)
+end
+
+function nodes.tracers.steppers.codes(i,command)
+ local c = collection[i]
+ while c do
+ local id = c.id
+ if id == glyph then
+ if command then
+ texsprint(ctxcatcodes,format("%s{%s}{%s}",command,c.font,c.char))
+ else
+ texsprint(ctxcatcodes,format("[%s:U+%04X]",c.font,c.char))
+ end
+ elseif id == whatsit and (c.subtype == 6 or c.subtype == 7) then
+ texsprint(ctxcatcodes,format("[%s]",c.dir))
+ else
+ texsprint(ctxcatcodes,format("[%s]",node_type(id)))
+ end
+ c = c.next
+ end
+end
+
+function nodes.tracers.steppers.messages(i,command,split)
+ local list = messages[i] -- or { "no messages" }
+ if list then
+ for i=1,#list do
+ local l = list[i]
+ if split then
+ local a, b = match(l,"^(.-)%s*:%s*(.*)$")
+ texsprint(ctxcatcodes,format("%s{%s}{%s}",command,a or l,b or ""))
+ else
+ texsprint(ctxcatcodes,format("%s{%s}",command,l))
+ end
+ end
+ end
+end
+
+-- hooks into the node list processor (see otf)
+
+function nodes.tracers.steppers.check(head)
+ if collecting then
+ nodes.tracers.steppers.reset()
+ local n = copy_node_list(head)
+ nodes.inject_kerns(n,nil,true)
+ nodes.protect_glyphs(n) -- can be option
+ collection[1] = n
+ end
+end
+
+function nodes.tracers.steppers.register(head)
+ if collecting then
+ local nc = #collection+1
+ if messages[nc] then
+ local n = copy_node_list(head)
+ nodes.inject_kerns(n,nil,true)
+ nodes.protect_glyphs(n) -- can be option
+ collection[nc] = n
+ end
+ end
+end
+
+function nodes.tracers.steppers.message(str,...)
+ str = format(str,...)
+ if collecting then
+ local n = #collection + 1
+ local m = messages[n]
+ if not m then m = { } messages[n] = m end
+ m[#m+1] = str
+ end
+ return str -- saves an intermediate var in the caller
+end
+
+-- this will be reorganized:
+
+function nodes.show_list(head, message)
+ if message then
+ texio.write_nl(message)
+ end
+ for n in traverse(head) do
+ texio.write_nl(tostring(n))
+ end
+end
+
+function nodes.check_glyphs(head,message)
+ local t = { }
+ for g in traverse_id(glyph,head) do
+ t[#t+1] = format("U+%04X:%s",g.char,g.subtype)
+ end
+ if #t > 0 then
+ logs.report(message or "nodes","%s glyphs: %s",#t,concat(t," "))
+ end
+ return false
+end
+
+function nodes.tosequence(start,stop)
+ if start then
+ local t = { }
+ while start do
+ if start.id == glyph then
+ t[#t+1] = format("U+%04X:%s",start.char,utfchar(start.char))
+ else
+ t[#t+1] = match(tostring(start),": (%S+)")
+ end
+ if start == stop then
+ break
+ else
+ start = start.next
+ end
+ end
+ return concat(t," ")
+ else
+ return ""
+ end
+end
+
+function nodes.report(t,done)
+ if done then
+ if status.output_active then
+ texio.write(format("<++ %s>",count(t)))
+ else
+ texio.write(format("<+ %s>",count(t)))
+ end
+ else
+ if status.output_active then
+ texio.write(format("<-- %s>",count(t)))
+ else
+ texio.write(format("<- %s>",count(t)))
+ end
+ end
+end
+
+function nodes.pack_list(head)
+ local t = { }
+ for n in traverse(head) do
+ t[#t+1] = tostring(n)
+ end
+ return t
+end
+
+function nodes.ids_to_string(head)
+ local t, last_id, last_n = { }, nil, 0
+ for n in traverse_nodes(head) do
+ local id = n.id
+ if not last_id then
+ last_id, last_n = id, 1
+ elseif last_id == id then
+ last_n = last_n + 1
+ else
+ if last_n > 1 then
+ t[#t+1] = format("[%s*%s]",last_n,node_type(last_id) or "?")
+ else
+ t[#t+1] = format("[%s]",node_type(last_id) or "?")
+ end
+ last_id, last_n = id, 1
+ end
+ end
+ if not last_id then
+ t[#t+1] = "no nodes"
+ elseif last_n > 1 then
+ t[#t+1] = format("[%s*%s]",last_n,node_type(last_id) or "?")
+ else
+ t[#t+1] = format("[%s]",node_type(last_id) or "?")
+ end
+ return concat(t," ")
+end
diff --git a/tex/context/base/node-tsk.lua b/tex/context/base/node-tsk.lua
new file mode 100644
index 000000000..f20c544c4
--- /dev/null
+++ b/tex/context/base/node-tsk.lua
@@ -0,0 +1,113 @@
+if not modules then modules = { } end modules ['node-tsk'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local trace_tasks = false trackers.register("tasks", function(v) trace_tasks = v end)
+
+tasks = tasks or { }
+tasks.data = tasks.data or { }
+
+function tasks.new(name,list)
+ local tasklist = sequencer.reset()
+ tasks.data[name] = { list = tasklist, runner = false }
+ for l=1,#list do
+ sequencer.appendgroup(tasklist,list[l])
+ end
+end
+
+function tasks.restart(name,group)
+ local data = tasks.data[name]
+ if data then
+ data.runner = false
+ end
+end
+
+function tasks.appendaction(name,group,action,where,kind)
+ local data = tasks.data[name]
+ if data then
+ sequencer.appendaction(data.list,group,action,where,kind)
+ data.runner = false
+ end
+end
+
+function tasks.prependaction(name,group,action,where,kind)
+ local data = tasks.data[name]
+ if data then
+ sequencer.prependaction(data.list,group,action,where,kind)
+ data.runner = false
+ end
+end
+
+function tasks.removeaction(name,group,action)
+ local data = tasks.data[name]
+ if data then
+ sequencer.removeaction(data.list,group,action)
+ data.runner = false
+ end
+end
+
+function tasks.showactions(name,group,action,where,kind)
+ local data = tasks.data[name]
+ if data then
+ logs.report("nodes","task %s, list:\n%s",name,sequencer.nodeprocessor(data.list))
+ end
+end
+
+function tasks.actions(name)
+ local data = tasks.data[name]
+ if data then
+ return function(head,tail,...)
+ local runner = data.runner
+ if not runner then
+ if trace_tasks then
+ logs.report("nodes","creating task runner '%s'",name)
+ end
+ runner = sequencer.compile(data.list,sequencer.nodeprocessor)
+ data.runner = runner
+ end
+ return runner(head,tail,...)
+ end
+ else
+ return nil
+ end
+end
+
+tasks.new (
+ "processors",
+ {
+ "before", -- for users
+ "normalizers",
+ "characters",
+ "words",
+ "fonts",
+ "lists",
+ "after", -- for users
+ }
+)
+
+tasks.new (
+ "finalizers",
+ {
+ "before", -- for users
+ "normalizers",
+-- "characters",
+-- "finishers",
+ "fonts",
+-- "lists",
+ "after", -- for users
+ }
+)
+
+tasks.new (
+ "shipouts",
+ {
+ "before", -- for users
+ "normalizers",
+ "finishers",
+ "after", -- for users
+ }
+)
diff --git a/tex/context/base/node-tst.lua b/tex/context/base/node-tst.lua
new file mode 100644
index 000000000..e8b1146f8
--- /dev/null
+++ b/tex/context/base/node-tst.lua
@@ -0,0 +1,108 @@
+if not modules then modules = { } end modules ['node-tst'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+function nodes.leftskip(n)
+ while n do
+ local id = n.id
+ if id == glue then
+ if n.subtype == 8 then -- 7 in c/web source
+ return (n.spec and n.spec.width) or 0
+ else
+ return 0
+ end
+ elseif id == whatsit then
+ n = n.next
+ elseif id == hlist then
+ return n.width
+ else
+ break
+ end
+ end
+ return 0
+end
+
+function nodes.rightskip(n)
+ if n then
+ n = slide_nodes(n)
+ while n do
+ local id = n.id
+ if id == glue then
+ if n.subtype == 9 then -- 8 in the c/web source
+ return (n.spec and n.spec.width) or 0
+ else
+ return 0
+ end
+ elseif id == whatsit then
+ n = n.prev
+ else
+ break
+ end
+ end
+ end
+ return false
+end
+
+function nodes.somespace(n,all)
+ if n then
+ local id = n.id
+ if id == glue then
+ return (all or (n.spec.width ~= 0)) and glue
+ elseif id == kern then
+ return (all or (n.kern ~= 0)) and kern
+ elseif id == glyph then
+ local category = chardata[n.char].category
+ -- maybe more category checks are needed
+ return (category == "zs") and glyph
+ end
+ end
+ return false
+end
+
+function nodes.somepenalty(n,value)
+ if n then
+ local id = n.id
+ if id == penalty then
+ if value then
+ return n.penalty == value
+ else
+ return true
+ end
+ end
+ end
+ return false
+end
+
+function nodes.is_display_math(head)
+ local n = head.prev
+ while n do
+ local id = n.id
+ if id == penalty then
+ elseif id == glue then
+ if n.subtype == 6 then -- above_display_short_skip
+ return true
+ end
+ else
+ break
+ end
+ n = n.prev
+ end
+ n = head.next
+ while n do
+ local id = n.id
+ if id == penalty then
+ elseif id == glue then
+ if n.subtype == 7 then -- below_display_short_skip
+ return true
+ end
+ else
+ break
+ end
+ n = n.next
+ end
+ return false
+end
diff --git a/tex/context/base/norm-alo.tex b/tex/context/base/norm-alo.tex
new file mode 100644
index 000000000..d47f49037
--- /dev/null
+++ b/tex/context/base/norm-alo.tex
@@ -0,0 +1,36 @@
+%D \module
+%D [ file=norm-alo,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\ALEPH\ and \OMEGA,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This file will become obsolete!
+
+% omega primitives
+
+\let\textdir = \textdir
+\let\pagedir = \pagedir
+\let\mathdir = \mathdir
+\let\pardir = \pardir
+\let\bodydir = \bodydir
+\let\leftghost = \leftghost
+\let\rightghost = \rightghost
+\let\localleftbox = \localleftbox
+\let\localrightbox = \localrightbox
+\let\localinterlinepenalty = \localinterlinepenalty
+\let\localbrokenpenalty = \localbrokenpenalty
+
+% aleph primitives
+
+\let\boxdir = \boxdir
+\let\pagebottomoffset = \pagebottomoffset
+\let\pagerightoffset = \pagerightoffset
+
+\endinput
diff --git a/tex/context/base/norm-ctx.tex b/tex/context/base/norm-ctx.tex
new file mode 100644
index 000000000..707705d89
--- /dev/null
+++ b/tex/context/base/norm-ctx.tex
@@ -0,0 +1,16 @@
+%D \module
+%D [ file=norm-ctx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\ALEPH\ and \OMEGA,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D A few more might end up here (like the weird ones in syst-ini).
+
+\let\normalreqno = \normaleqno
diff --git a/tex/context/base/norm-etx.tex b/tex/context/base/norm-etx.tex
new file mode 100644
index 000000000..3edd8e7ef
--- /dev/null
+++ b/tex/context/base/norm-etx.tex
@@ -0,0 +1,79 @@
+%D \module
+%D [ file=norm-etx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\ETEX,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% etex primitives
+
+\let \normalbotmarks = \botmarks
+\let \normalclubpenalties = \clubpenalties
+\let \normalcurrentgrouplevel = \currentgrouplevel
+\let \normalcurrentgrouptype = \currentgrouptype
+\let \normalcurrentifbranch = \currentifbranch
+\let \normalcurrentiflevel = \currentiflevel
+\let \normalcurrentiftype = \currentiftype
+\let \normaldetokenize = \detokenize
+\let \normaldimexpr = \dimexpr
+\let \normaldisplaywidowpenalties = \displaywidowpenalties
+\let \normaleTeXVersion = \eTeXVersion
+\let \normaleTeXminorversion = \eTeXminorversion
+\let \normaleTeXrevision = \eTeXrevision
+\let \normaleTeXversion = \eTeXversion
+\let \normaleveryeof = \everyeof
+\let \normalfirstmarks = \firstmarks
+\let \normalfontchardp = \fontchardp
+\let \normalfontcharht = \fontcharht
+\let \normalfontcharic = \fontcharic
+\let \normalfontcharwd = \fontcharwd
+\let \normalglueexpr = \glueexpr
+\let \normalglueshrink = \glueshrink
+\let \normalglueshrinkorder = \glueshrinkorder
+\let \normalgluestretch = \gluestretch
+\let \normalgluestretchorder = \gluestretchorder
+\let \normalgluetomu = \gluetomu
+\let \normalifcsname = \ifcsname
+\let \normalifdefined = \ifdefined
+\let \normaliffontchar = \iffontchar
+\let \normalinteractionmode = \interactionmode
+\let \normalinterlinepenalties = \interlinepenalties
+\let \normallastlinefit = \lastlinefit
+\let \normallastnodetype = \lastnodetype
+\let \normalmarks = \marks
+\let \normalmuexpr = \muexpr
+\let \normalmutoglue = \mutoglue
+\let \normalnumexpr = \numexpr
+\let \normalpagediscards = \pagediscards
+\let \normalparshapedimen = \parshapedimen
+\let \normalparshapeindent = \parshapeindent
+\let \normalparshapelength = \parshapelength
+\let \normalpredisplaydirection = \predisplaydirection
+\let \normalprotected = \protected
+\let \normalreadline = \readline
+\let \normalsavinghyphcodes = \savinghyphcodes
+\let \normalsavingvdiscards = \savingvdiscards
+\let \normalscantokens = \scantokens
+\let \normalshowgroups = \showgroups
+\let \normalshowifs = \showifs
+\let \normalshowtokens = \showtokens
+\let \normalsplitbotmarks = \splitbotmarks
+\let \normalsplitdiscards = \splitdiscards
+\let \normalsplitfirstmarks = \splitfirstmarks
+\let \normaltopmarks = \topmarks
+\let \normaltracingassigns = \tracingassigns
+\let \normaltracinggroups = \tracinggroups
+\let \normaltracingifs = \tracingifs
+\let \normaltracingnesting = \tracingnesting
+\let \normaltracingscantokens = \tracingscantokens
+\let \normalunexpanded = \unexpanded
+\let \normalunless = \unless
+\let \normalwidowpenalties = \widowpenalties
+
+\endinput
diff --git a/tex/context/base/norm-ltx.tex b/tex/context/base/norm-ltx.tex
new file mode 100644
index 000000000..c83a49b90
--- /dev/null
+++ b/tex/context/base/norm-ltx.tex
@@ -0,0 +1,177 @@
+%D \module
+%D [ file=norm-ltx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\LUATEX,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This file will become obsolete!
+
+% luatex primitives
+
+\let \normalUdelcode = \Udelcode
+\let \normalUdelcodenum = \Udelcodenum
+\let \normalUdelimiter = \Udelimiter
+\let \normalUmathaccent = \Umathaccent
+\let \normalUmathaccents = \Umathaccents
+\let \normalUmathaxis = \Umathaxis
+\let \normalUmathbinbinspacing = \Umathbinbinspacing
+\let \normalUmathbinclosespacing = \Umathbinclosespacing
+\let \normalUmathbininnerspacing = \Umathbininnerspacing
+\let \normalUmathbinopenspacing = \Umathbinopenspacing
+\let \normalUmathbinopspacing = \Umathbinopspacing
+\let \normalUmathbinordspacing = \Umathbinordspacing
+\let \normalUmathbinpunctspacing = \Umathbinpunctspacing
+\let \normalUmathbinrelspacing = \Umathbinrelspacing
+\let \normalUmathbotaccent = \Umathbotaccent
+\let \normalUmathchar = \Umathchar
+\let \normalUmathchardef = \Umathchardef
+\let \normalUmathcharnum = \Umathcharnum
+\let \normalUmathclosebinspacing = \Umathclosebinspacing
+\let \normalUmathcloseclosespacing = \Umathcloseclosespacing
+\let \normalUmathcloseinnerspacing = \Umathcloseinnerspacing
+\let \normalUmathcloseopenspacing = \Umathcloseopenspacing
+\let \normalUmathcloseopspacing = \Umathcloseopspacing
+\let \normalUmathcloseordspacing = \Umathcloseordspacing
+\let \normalUmathclosepunctspacing = \Umathclosepunctspacing
+\let \normalUmathcloserelspacing = \Umathcloserelspacing
+\let \normalUmathcode = \Umathcode
+\let \normalUmathcodenum = \Umathcodenum
+\let \normalUmathconnectoroverlapmin = \Umathconnectoroverlapmin
+\let \normalUmathfractiondelsize = \Umathfractiondelsize
+\let \normalUmathfractiondenomdown = \Umathfractiondenomdown
+\let \normalUmathfractiondenomvgap = \Umathfractiondenomvgap
+\let \normalUmathfractionnumup = \Umathfractionnumup
+\let \normalUmathfractionnumvgap = \Umathfractionnumvgap
+\let \normalUmathfractionrule = \Umathfractionrule
+\let \normalUmathinnerbinspacing = \Umathinnerbinspacing
+\let \normalUmathinnerclosespacing = \Umathinnerclosespacing
+\let \normalUmathinnerinnerspacing = \Umathinnerinnerspacing
+\let \normalUmathinneropenspacing = \Umathinneropenspacing
+\let \normalUmathinneropspacing = \Umathinneropspacing
+\let \normalUmathinnerordspacing = \Umathinnerordspacing
+\let \normalUmathinnerpunctspacing = \Umathinnerpunctspacing
+\let \normalUmathinnerrelspacing = \Umathinnerrelspacing
+\let \normalUmathlimitabovebgap = \Umathlimitabovebgap
+\let \normalUmathlimitabovekern = \Umathlimitabovekern
+\let \normalUmathlimitabovevgap = \Umathlimitabovevgap
+\let \normalUmathlimitdownbgap = \Umathlimitdownbgap
+\let \normalUmathlimitdownkern = \Umathlimitdownkern
+\let \normalUmathlimitdownvgap = \Umathlimitdownvgap
+\let \normalUmathopbinspacing = \Umathopbinspacing
+\let \normalUmathopclosespacing = \Umathopclosespacing
+\let \normalUmathopenbinspacing = \Umathopenbinspacing
+\let \normalUmathopenclosespacing = \Umathopenclosespacing
+\let \normalUmathopeninnerspacing = \Umathopeninnerspacing
+\let \normalUmathopenopenspacing = \Umathopenopenspacing
+\let \normalUmathopenopspacing = \Umathopenopspacing
+\let \normalUmathopenordspacing = \Umathopenordspacing
+\let \normalUmathopenpunctspacing = \Umathopenpunctspacing
+\let \normalUmathopenrelspacing = \Umathopenrelspacing
+\let \normalUmathoperatorsize = \Umathoperatorsize
+\let \normalUmathopinnerspacing = \Umathopinnerspacing
+\let \normalUmathopopenspacing = \Umathopopenspacing
+\let \normalUmathopopspacing = \Umathopopspacing
+\let \normalUmathopordspacing = \Umathopordspacing
+\let \normalUmathoppunctspacing = \Umathoppunctspacing
+\let \normalUmathoprelspacing = \Umathoprelspacing
+\let \normalUmathordbinspacing = \Umathordbinspacing
+\let \normalUmathordclosespacing = \Umathordclosespacing
+\let \normalUmathordinnerspacing = \Umathordinnerspacing
+\let \normalUmathordopenspacing = \Umathordopenspacing
+\let \normalUmathordopspacing = \Umathordopspacing
+\let \normalUmathordordspacing = \Umathordordspacing
+\let \normalUmathordpunctspacing = \Umathordpunctspacing
+\let \normalUmathordrelspacing = \Umathordrelspacing
+\let \normalUmathoverbarkern = \Umathoverbarkern
+\let \normalUmathoverbarrule = \Umathoverbarrule
+\let \normalUmathoverbarvgap = \Umathoverbarvgap
+\let \normalUmathoverdelimiterbgap = \Umathoverdelimiterbgap
+\let \normalUmathoverdelimitervgap = \Umathoverdelimitervgap
+\let \normalUmathpunctbinspacing = \Umathpunctbinspacing
+\let \normalUmathpunctclosespacing = \Umathpunctclosespacing
+\let \normalUmathpunctinnerspacing = \Umathpunctinnerspacing
+\let \normalUmathpunctopenspacing = \Umathpunctopenspacing
+\let \normalUmathpunctopspacing = \Umathpunctopspacing
+\let \normalUmathpunctordspacing = \Umathpunctordspacing
+\let \normalUmathpunctpunctspacing = \Umathpunctpunctspacing
+\let \normalUmathpunctrelspacing = \Umathpunctrelspacing
+\let \normalUmathquad = \Umathquad
+\let \normalUmathradicaldegreeafter = \Umathradicaldegreeafter
+\let \normalUmathradicaldegreebefore = \Umathradicaldegreebefore
+\let \normalUmathradicaldegreeraise = \Umathradicaldegreeraise
+\let \normalUmathradicalkern = \Umathradicalkern
+\let \normalUmathradicalrule = \Umathradicalrule
+\let \normalUmathradicalvgap = \Umathradicalvgap
+\let \normalUmathrelbinspacing = \Umathrelbinspacing
+\let \normalUmathrelclosespacing = \Umathrelclosespacing
+\let \normalUmathrelinnerspacing = \Umathrelinnerspacing
+\let \normalUmathrelopenspacing = \Umathrelopenspacing
+\let \normalUmathrelopspacing = \Umathrelopspacing
+\let \normalUmathrelordspacing = \Umathrelordspacing
+\let \normalUmathrelpunctspacing = \Umathrelpunctspacing
+\let \normalUmathrelrelspacing = \Umathrelrelspacing
+\let \normalUmathspaceafterscript = \Umathspaceafterscript
+\let \normalUmathstackdenomdown = \Umathstackdenomdown
+\let \normalUmathstacknumup = \Umathstacknumup
+\let \normalUmathstackvgap = \Umathstackvgap
+\let \normalUmathsubshiftdown = \Umathsubshiftdown
+\let \normalUmathsubshiftdrop = \Umathsubshiftdrop
+\let \normalUmathsubsupshiftdown = \Umathsubsupshiftdown
+\let \normalUmathsubsupvgap = \Umathsubsupvgap
+\let \normalUmathsubtopmax = \Umathsubtopmax
+\let \normalUmathsupbottommin = \Umathsupbottommin
+\let \normalUmathsupshiftdrop = \Umathsupshiftdrop
+\let \normalUmathsupshiftup = \Umathsupshiftup
+\let \normalUmathsupsubbottommax = \Umathsupsubbottommax
+\let \normalUmathunderbarkern = \Umathunderbarkern
+\let \normalUmathunderbarrule = \Umathunderbarrule
+\let \normalUmathunderbarvgap = \Umathunderbarvgap
+\let \normalUmathunderdelimiterbgap = \Umathunderdelimiterbgap
+\let \normalUmathunderdelimitervgap = \Umathunderdelimitervgap
+\let \normalUoverdelimiter = \Uoverdelimiter
+\let \normalUradical = \Uradical
+\let \normalUroot = \Uroot
+\let \normalUunderdelimiter = \Uunderdelimiter
+\let \normalattribute = \attribute
+\let \normalattributedef = \attributedef
+\let \normalcatcodetable = \catcodetable
+\let \normalclearmarks = \clearmarks
+\let \normalcrampeddisplaystyle = \crampeddisplaystyle
+\let \normalcrampedscriptscriptstyle = \crampedscriptscriptstyle
+\let \normalcrampedscriptstyle = \crampedscriptstyle
+\let \normalcrampedtextstyle = \crampedtextstyle
+\let \normalformatname = \formatname
+\let \normalifabsdim = \ifabsdim
+\let \normalifabsnum = \ifabsnum
+\let \normalifprimitive = \ifprimitive
+\let \normalinitcatcodetable = \initcatcodetable
+\let \normallatelua = \latelua
+\let \normalluaescapestring = \luaescapestring
+\let \normalluastartup = \luastartup
+\let \normalluatexdatestamp = \luatexdatestamp
+\let \normalluatexrevision = \luatexrevision
+\let \normalluatexversion = \luatexversion
+\let \normalnokerns = \nokerns
+\let \normalnoligs = \noligs
+\let \normalpageleftoffset = \pageleftoffset
+\let \normalpagetopoffset = \pagetopoffset
+\let \normalpostexhyphenchar = \postexhyphenchar
+\let \normalposthyphenchar = \posthyphenchar
+\let \normalpreexhyphenchar = \preexhyphenchar
+\let \normalprehyphenchar = \prehyphenchar
+\let \normalprimitive = \primitive
+\let \normalsavecatcodetable = \savecatcodetable
+\let \normalscantextokens = \scantextokens
+\let \normalsuppressfontnotfounderror = \suppressfontnotfounderror
+\let \normalsuppressifcsnameerror = \suppressifcsnameerror
+\let \normalsuppresslongerror = \suppresslongerror
+\let \normalsynctex = \synctex
+
+\endinput
diff --git a/tex/context/base/norm-ptx.tex b/tex/context/base/norm-ptx.tex
new file mode 100644
index 000000000..992fd38ff
--- /dev/null
+++ b/tex/context/base/norm-ptx.tex
@@ -0,0 +1,130 @@
+%D \module
+%D [ file=norm-ptx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\PDFTEX,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\let \normalefcode = \efcode
+\let \normalexpanded = \expanded
+\let \normalifincsname = \ifincsname
+\let \normalifpdfabsdim = \ifpdfabsdim
+\let \normalifpdfabsnum = \ifpdfabsnum
+\let \normalifpdfprimitive = \ifpdfprimitive
+\let \normalleftmarginkern = \leftmarginkern
+\let \normalletterspacefont = \letterspacefont
+\let \normallpcode = \lpcode
+\let \normalpdfadjustspacing = \pdfadjustspacing
+\let \normalpdfannot = \pdfannot
+\let \normalpdfcatalog = \pdfcatalog
+\let \normalpdfcolorstack = \pdfcolorstack
+\let \normalpdfcolorstackinit = \pdfcolorstackinit
+\let \normalpdfcompresslevel = \pdfcompresslevel
+\let \normalpdfcopyfont = \pdfcopyfont
+\let \normalpdfcreationdate = \pdfcreationdate
+\let \normalpdfdecimaldigits = \pdfdecimaldigits
+\let \normalpdfdest = \pdfdest
+\let \normalpdfdestmargin = \pdfdestmargin
+\let \normalpdfdraftmode = \pdfdraftmode
+\let \normalpdfeachlinedepth = \pdfeachlinedepth
+\let \normalpdfeachlineheight = \pdfeachlineheight
+\let \normalpdfendlink = \pdfendlink
+\let \normalpdfendthread = \pdfendthread
+\let \normalpdffirstlineheight = \pdffirstlineheight
+\let \normalpdffontattr = \pdffontattr
+\let \normalpdffontexpand = \pdffontexpand
+\let \normalpdffontname = \pdffontname
+\let \normalpdffontobjnum = \pdffontobjnum
+\let \normalpdffontsize = \pdffontsize
+\let \normalpdfforcepagebox = \pdfforcepagebox
+\let \normalpdfgamma = \pdfgamma
+\let \normalpdfgentounicode = \pdfgentounicode
+\let \normalpdfglyphtounicode = \pdfglyphtounicode
+\let \normalpdfhorigin = \pdfhorigin
+\let \normalpdfignoreddimen = \pdfignoreddimen
+\let \normalpdfimageapplygamma = \pdfimageapplygamma
+\let \normalpdfimagegamma = \pdfimagegamma
+\let \normalpdfimagehicolor = \pdfimagehicolor
+\let \normalpdfimageresolution = \pdfimageresolution
+\let \normalpdfincludechars = \pdfincludechars
+\let \normalpdfinclusioncopyfonts = \pdfinclusioncopyfonts
+\let \normalpdfinclusionerrorlevel = \pdfinclusionerrorlevel
+\let \normalpdfinfo = \pdfinfo
+\let \normalpdfinsertht = \pdfinsertht
+\let \normalpdflastannot = \pdflastannot
+\let \normalpdflastlinedepth = \pdflastlinedepth
+\let \normalpdflastlink = \pdflastlink
+\let \normalpdflastobj = \pdflastobj
+\let \normalpdflastxform = \pdflastxform
+\let \normalpdflastximage = \pdflastximage
+\let \normalpdflastximagecolordepth = \pdflastximagecolordepth
+\let \normalpdflastximagepages = \pdflastximagepages
+\let \normalpdflastxpos = \pdflastxpos
+\let \normalpdflastypos = \pdflastypos
+\let \normalpdflinkmargin = \pdflinkmargin
+\let \normalpdfliteral = \pdfliteral
+\let \normalpdfmapfile = \pdfmapfile
+\let \normalpdfmapline = \pdfmapline
+\let \normalpdfminorversion = \pdfminorversion
+\let \normalpdfmovechars = \pdfmovechars
+\let \normalpdfnames = \pdfnames
+\let \normalpdfnoligatures = \pdfnoligatures
+\let \normalpdfnormaldeviate = \pdfnormaldeviate
+\let \normalpdfobj = \pdfobj
+\let \normalpdfobjcompresslevel = \pdfobjcompresslevel
+\let \normalpdfoptionalwaysusepdfpagebox = \pdfoptionalwaysusepdfpagebox
+\let \normalpdfoptionpdfinclusionerrorlevel = \pdfoptionpdfinclusionerrorlevel
+\let \normalpdfoptionpdfminorversion = \pdfoptionpdfminorversion
+\let \normalpdfoutline = \pdfoutline
+\let \normalpdfoutput = \pdfoutput
+\let \normalpdfpageattr = \pdfpageattr
+\let \normalpdfpagebox = \pdfpagebox
+\let \normalpdfpageheight = \pdfpageheight
+\let \normalpdfpageref = \pdfpageref
+\let \normalpdfpageresources = \pdfpageresources
+\let \normalpdfpagesattr = \pdfpagesattr
+\let \normalpdfpagewidth = \pdfpagewidth
+\let \normalpdfpkmode = \pdfpkmode
+\let \normalpdfpkresolution = \pdfpkresolution
+\let \normalpdfprimitive = \pdfprimitive
+\let \normalpdfprotrudechars = \pdfprotrudechars
+\let \normalpdfpxdimen = \pdfpxdimen
+\let \normalpdfrandomseed = \pdfrandomseed
+\let \normalpdfrefobj = \pdfrefobj
+\let \normalpdfrefxform = \pdfrefxform
+\let \normalpdfrefximage = \pdfrefximage
+\let \normalpdfreplacefont = \pdfreplacefont
+\let \normalpdfrestore = \pdfrestore
+\let \normalpdfretval = \pdfretval
+\let \normalpdfsave = \pdfsave
+\let \normalpdfsavepos = \pdfsavepos
+\let \normalpdfsetmatrix = \pdfsetmatrix
+\let \normalpdfsetrandomseed = \pdfsetrandomseed
+\let \normalpdfstartlink = \pdfstartlink
+\let \normalpdfstartthread = \pdfstartthread
+\let \normalpdftexbanner = \pdftexbanner
+\let \normalpdftexrevision = \pdftexrevision
+\let \normalpdftexversion = \pdftexversion
+\let \normalpdfthread = \pdfthread
+\let \normalpdfthreadmargin = \pdfthreadmargin
+\let \normalpdftracingfonts = \pdftracingfonts
+\let \normalpdftrailer = \pdftrailer
+\let \normalpdfuniformdeviate = \pdfuniformdeviate
+\let \normalpdfuniqueresname = \pdfuniqueresname
+\let \normalpdfvorigin = \pdfvorigin
+\let \normalpdfxform = \pdfxform
+\let \normalpdfxformname = \pdfxformname
+\let \normalpdfximage = \pdfximage
+\let \normalpdfximagebbox = \pdfximagebbox
+\let \normalquitvmode = \quitvmode
+\let \normalrightmarginkern = \rightmarginkern
+\let \normalrpcode = \rpcode
+\let \normaltagcode = \tagcode
+
+\endinput
diff --git a/tex/context/base/norm-tex.tex b/tex/context/base/norm-tex.tex
new file mode 100644
index 000000000..61f9740ef
--- /dev/null
+++ b/tex/context/base/norm-tex.tex
@@ -0,0 +1,351 @@
+%D \module
+%D [ file=norm-etx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\TEX,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D Since \LUATEX\ can generate these lists internally it started
+%D to make sense to cleanup this \type {\normalstuff} for \MKII\ as
+%D well. The tables are generated with a \LUA\ script.
+
+% tex primitives
+
+% Beware, we already redefined \dump, \outer and \everyjob !
+
+% \normal = \
+% \normal- = \-
+% \normal/ = \/
+\let \normalabove = \above
+\let \normalabovedisplayshortskip = \abovedisplayshortskip
+\let \normalabovedisplayskip = \abovedisplayskip
+\let \normalabovewithdelims = \abovewithdelims
+\let \normalaccent = \accent
+\let \normaladjdemerits = \adjdemerits
+\let \normaladvance = \advance
+\let \normalafterassignment = \afterassignment
+\let \normalaftergroup = \aftergroup
+\let \normalatop = \atop
+\let \normalatopwithdelims = \atopwithdelims
+\let \normalbadness = \badness
+\let \normalbaselineskip = \baselineskip
+\let \normalbatchmode = \batchmode
+\let \normalbegingroup = \begingroup
+\let \normalbelowdisplayshortskip = \belowdisplayshortskip
+\let \normalbelowdisplayskip = \belowdisplayskip
+\let \normalbinoppenalty = \binoppenalty
+\let \normalbotmark = \botmark
+\let \normalbox = \box
+\let \normalboxmaxdepth = \boxmaxdepth
+\let \normalbrokenpenalty = \brokenpenalty
+\let \normalcatcode = \catcode
+\let \normalchar = \char
+\let \normalchardef = \chardef
+\let \normalcleaders = \cleaders
+\let \normalclosein = \closein
+\let \normalcloseout = \closeout
+\let \normalclubpenalty = \clubpenalty
+\let \normalcopy = \copy
+\let \normalcount = \count
+\let \normalcountdef = \countdef
+\let \normalcr = \cr
+\let \normalcrcr = \crcr
+\let \normalcsname = \csname
+\let \normalday = \day
+\let \normaldeadcycles = \deadcycles
+\let \normaldef = \def
+\let \normaldefaulthyphenchar = \defaulthyphenchar
+\let \normaldefaultskewchar = \defaultskewchar
+\let \normaldelcode = \delcode
+\let \normaldelimiter = \delimiter
+\let \normaldelimiterfactor = \delimiterfactor
+\let \normaldelimitershortfall = \delimitershortfall
+\let \normaldimen = \dimen
+\let \normaldimendef = \dimendef
+\let \normaldirectlua = \directlua
+\let \normaldiscretionary = \discretionary
+\let \normaldisplayindent = \displayindent
+\let \normaldisplaylimits = \displaylimits
+\let \normaldisplaystyle = \displaystyle
+\let \normaldisplaywidowpenalty = \displaywidowpenalty
+\let \normaldisplaywidth = \displaywidth
+\let \normaldivide = \divide
+\let \normaldoublehyphendemerits = \doublehyphendemerits
+\let \normaldp = \dp
+% \normaldump = \dump
+\let \normaledef = \edef
+\let \normalelse = \else
+\let \normalemergencystretch = \emergencystretch
+\let \normalend = \end
+\let \normalendcsname = \endcsname
+\let \normalendgroup = \endgroup
+\let \normalendinput = \endinput
+\let \normalendlinechar = \endlinechar
+\let \normaleqno = \eqno
+\let \normalerrhelp = \errhelp
+\let \normalerrmessage = \errmessage
+\let \normalerrorcontextlines = \errorcontextlines
+\let \normalerrorstopmode = \errorstopmode
+\let \normalescapechar = \escapechar
+\let \normaleverycr = \everycr
+\let \normaleverydisplay = \everydisplay
+\let \normaleveryhbox = \everyhbox
+% \normaleveryjob = \everyjob
+\let \normaleverymath = \everymath
+\let \normaleverypar = \everypar
+\let \normaleveryvbox = \everyvbox
+\let \normalexhyphenchar = \exhyphenchar
+\let \normalexhyphenpenalty = \exhyphenpenalty
+\let \normalexpandafter = \expandafter
+\let \normalfam = \fam
+\let \normalfi = \fi
+\let \normalfinalhyphendemerits = \finalhyphendemerits
+\let \normalfirstmark = \firstmark
+\let \normalfloatingpenalty = \floatingpenalty
+\let \normalfont = \font
+\let \normalfontdimen = \fontdimen
+\let \normalfontname = \fontname
+\let \normalfuturelet = \futurelet
+\let \normalgdef = \gdef
+\let \normalglobal = \global
+\let \normalglobaldefs = \globaldefs
+\let \normalhalign = \halign
+\let \normalhangafter = \hangafter
+\let \normalhangindent = \hangindent
+\let \normalhbadness = \hbadness
+\let \normalhbox = \hbox
+\let \normalhfil = \hfil
+\let \normalhfill = \hfill
+\let \normalhfilneg = \hfilneg
+\let \normalhfuzz = \hfuzz
+\let \normalhoffset = \hoffset
+\let \normalholdinginserts = \holdinginserts
+\let \normalhrule = \hrule
+\let \normalhsize = \hsize
+\let \normalhskip = \hskip
+\let \normalhss = \hss
+\let \normalht = \ht
+\let \normalhyphenation = \hyphenation
+\let \normalhyphenchar = \hyphenchar
+\let \normalhyphenpenalty = \hyphenpenalty
+\let \normalif = \if
+\let \normalifcase = \ifcase
+\let \normalifcat = \ifcat
+\let \normalifdim = \ifdim
+\let \normalifeof = \ifeof
+\let \normaliffalse = \iffalse
+\let \normalifhbox = \ifhbox
+\let \normalifhmode = \ifhmode
+\let \normalifinner = \ifinner
+\let \normalifmmode = \ifmmode
+\let \normalifnum = \ifnum
+\let \normalifodd = \ifodd
+\let \normaliftrue = \iftrue
+\let \normalifvbox = \ifvbox
+\let \normalifvmode = \ifvmode
+\let \normalifvoid = \ifvoid
+\let \normalifx = \ifx
+\let \normalignorespaces = \ignorespaces
+\let \normalimmediate = \immediate
+\let \normalindent = \indent
+% \normalinput = \input
+\let \normalinputlineno = \inputlineno
+\let \normalinsert = \insert
+\let \normalinsertpenalties = \insertpenalties
+\let \normalinterlinepenalty = \interlinepenalty
+\let \normaljobname = \jobname
+\let \normalkern = \kern
+\let \normallanguage = \language
+\let \normallastbox = \lastbox
+\let \normallastkern = \lastkern
+\let \normallastpenalty = \lastpenalty
+\let \normallastskip = \lastskip
+\let \normallccode = \lccode
+\let \normalleaders = \leaders
+\let \normalleft = \left
+\let \normallefthyphenmin = \lefthyphenmin
+\let \normalleftskip = \leftskip
+\let \normalleqno = \leqno
+\let \normallet = \let
+\let \normallimits = \limits
+\let \normallinepenalty = \linepenalty
+\let \normallineskip = \lineskip
+\let \normallineskiplimit = \lineskiplimit
+\let \normallong = \long
+\let \normallooseness = \looseness
+\let \normallower = \lower
+\let \normallowercase = \lowercase
+\let \normalmag = \mag
+\let \normalmark = \mark
+\let \normalmathaccent = \mathaccent
+\let \normalmathbin = \mathbin
+\let \normalmathchar = \mathchar
+\let \normalmathchardef = \mathchardef
+\let \normalmathchoice = \mathchoice
+\let \normalmathclose = \mathclose
+\let \normalmathcode = \mathcode
+\let \normalmathinner = \mathinner
+\let \normalmathop = \mathop
+\let \normalmathopen = \mathopen
+\let \normalmathord = \mathord
+\let \normalmathpunct = \mathpunct
+\let \normalmathrel = \mathrel
+\let \normalmathsurround = \mathsurround
+\let \normalmaxdeadcycles = \maxdeadcycles
+\let \normalmaxdepth = \maxdepth
+\let \normalmeaning = \meaning
+\let \normalmedmuskip = \medmuskip
+\let \normalmessage = \message
+\let \normalmiddle = \middle
+\let \normalmkern = \mkern
+\let \normalmonth = \month
+\let \normalmoveleft = \moveleft
+\let \normalmoveright = \moveright
+\let \normalmskip = \mskip
+\let \normalmultiply = \multiply
+\let \normalmuskip = \muskip
+\let \normalmuskipdef = \muskipdef
+\let \normalnewlinechar = \newlinechar
+\let \normalnoalign = \noalign
+\let \normalnoboundary = \noboundary
+\let \normalnoexpand = \noexpand
+\let \normalnoindent = \noindent
+\let \normalnolimits = \nolimits
+\let \normalnonscript = \nonscript
+\let \normalnonstopmode = \nonstopmode
+\let \normalnulldelimiterspace = \nulldelimiterspace
+\let \normalnullfont = \nullfont
+\let \normalnumber = \number
+\let \normalomit = \omit
+\let \normalopenin = \openin
+\let \normalopenout = \openout
+\let \normalor = \or
+% \normalouter = \outer
+\let \normaloutput = \output
+\let \normaloutputpenalty = \outputpenalty
+\let \normalover = \over
+\let \normaloverfullrule = \overfullrule
+\let \normaloverline = \overline
+\let \normaloverwithdelims = \overwithdelims
+\let \normalpagedepth = \pagedepth
+\let \normalpagefilllstretch = \pagefilllstretch
+\let \normalpagefillstretch = \pagefillstretch
+\let \normalpagefilstretch = \pagefilstretch
+\let \normalpagegoal = \pagegoal
+\let \normalpageshrink = \pageshrink
+\let \normalpagestretch = \pagestretch
+\let \normalpagetotal = \pagetotal
+\let \normalpar = \par
+\let \normalparfillskip = \parfillskip
+\let \normalparindent = \parindent
+\let \normalparshape = \parshape
+\let \normalparskip = \parskip
+\let \normalpatterns = \patterns
+\let \normalpausing = \pausing
+\let \normalpenalty = \penalty
+\let \normalpostdisplaypenalty = \postdisplaypenalty
+\let \normalpredisplaypenalty = \predisplaypenalty
+\let \normalpredisplaysize = \predisplaysize
+\let \normalpretolerance = \pretolerance
+\let \normalprevdepth = \prevdepth
+\let \normalprevgraf = \prevgraf
+\let \normalradical = \radical
+\let \normalraise = \raise
+\let \normalread = \read
+\let \normalrelax = \relax
+\let \normalrelpenalty = \relpenalty
+\let \normalright = \right
+\let \normalrighthyphenmin = \righthyphenmin
+\let \normalrightskip = \rightskip
+\let \normalromannumeral = \romannumeral
+\let \normalscriptfont = \scriptfont
+\let \normalscriptscriptfont = \scriptscriptfont
+\let \normalscriptscriptstyle = \scriptscriptstyle
+\let \normalscriptspace = \scriptspace
+\let \normalscriptstyle = \scriptstyle
+\let \normalscrollmode = \scrollmode
+\let \normalsetbox = \setbox
+\let \normalsetlanguage = \setlanguage
+\let \normalsfcode = \sfcode
+\let \normalshipout = \shipout
+\let \normalshow = \show
+\let \normalshowbox = \showbox
+\let \normalshowboxbreadth = \showboxbreadth
+\let \normalshowboxdepth = \showboxdepth
+\let \normalshowlists = \showlists
+\let \normalshowthe = \showthe
+\let \normalskewchar = \skewchar
+\let \normalskip = \skip
+\let \normalskipdef = \skipdef
+\let \normalspacefactor = \spacefactor
+\let \normalspaceskip = \spaceskip
+\let \normalspan = \span
+\let \normalspecial = \special
+\let \normalsplitbotmark = \splitbotmark
+\let \normalsplitfirstmark = \splitfirstmark
+\let \normalsplitmaxdepth = \splitmaxdepth
+\let \normalsplittopskip = \splittopskip
+\let \normalstring = \string
+\let \normaltabskip = \tabskip
+\let \normaltextfont = \textfont
+\let \normaltextstyle = \textstyle
+\let \normalthe = \the
+\let \normalthickmuskip = \thickmuskip
+\let \normalthinmuskip = \thinmuskip
+\let \normaltime = \time
+\let \normaltoks = \toks
+\let \normaltoksdef = \toksdef
+\let \normaltolerance = \tolerance
+\let \normaltopmark = \topmark
+\let \normaltopskip = \topskip
+\let \normaltracingcommands = \tracingcommands
+\let \normaltracinglostchars = \tracinglostchars
+\let \normaltracingmacros = \tracingmacros
+\let \normaltracingonline = \tracingonline
+\let \normaltracingoutput = \tracingoutput
+\let \normaltracingpages = \tracingpages
+\let \normaltracingparagraphs = \tracingparagraphs
+\let \normaltracingrestores = \tracingrestores
+\let \normaltracingstats = \tracingstats
+\let \normaluccode = \uccode
+\let \normaluchyph = \uchyph
+\let \normalunderline = \underline
+\let \normalunhbox = \unhbox
+\let \normalunhcopy = \unhcopy
+\let \normalunkern = \unkern
+\let \normalunpenalty = \unpenalty
+\let \normalunskip = \unskip
+\let \normalunvbox = \unvbox
+\let \normalunvcopy = \unvcopy
+\let \normaluppercase = \uppercase
+\let \normalvadjust = \vadjust
+\let \normalvalign = \valign
+\let \normalvbadness = \vbadness
+\let \normalvbox = \vbox
+\let \normalvcenter = \vcenter
+\let \normalvfil = \vfil
+\let \normalvfill = \vfill
+\let \normalvfilneg = \vfilneg
+\let \normalvfuzz = \vfuzz
+\let \normalvoffset = \voffset
+\let \normalvrule = \vrule
+\let \normalvsize = \vsize
+\let \normalvskip = \vskip
+\let \normalvsplit = \vsplit
+\let \normalvss = \vss
+\let \normalvtop = \vtop
+\let \normalwd = \wd
+\let \normalwidowpenalty = \widowpenalty
+\let \normalwrite = \write
+\let \normalxdef = \xdef
+\let \normalxleaders = \xleaders
+\let \normalxspaceskip = \xspaceskip
+\let \normalyear = \year
+
+\endinput
diff --git a/tex/context/base/norm-xtx.tex b/tex/context/base/norm-xtx.tex
new file mode 100644
index 000000000..3da944656
--- /dev/null
+++ b/tex/context/base/norm-xtx.tex
@@ -0,0 +1,18 @@
+%D \module
+%D [ file=norm-xtx,
+%D version=2009.03.19,
+%D title=\CONTEXT\ Norm Macros,
+%D subtitle=\XETEX,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright=PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% xetex primitives
+
+% nothing yet (also defined pdftex primitives)
+
+\endinput
diff --git a/tex/context/base/page-app.tex b/tex/context/base/page-app.tex
index 6e477903c..005ea6dd4 100644
--- a/tex/context/base/page-app.tex
+++ b/tex/context/base/page-app.tex
@@ -1,7 +1,7 @@
%D \module
%D [ file=page-app, % from meta-fig
%D version=1998.01.15,
-%D title=\CONTEXT\ Core Macros,
+%D title=\CONTEXT\ Page Macros,
%D subtitle=Independent page building,
%D author=Hans Hagen,
%D date=\currentdate,
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context Page Macros / Applications}
+\writestatus{loading}{ConTeXt Page Macros / Applications}
%D The fitting page code is moved from \type {meta-fig} to
%D here.
diff --git a/tex/context/base/page-bck.mkii b/tex/context/base/page-bck.mkii
new file mode 100644
index 000000000..0b4ad779a
--- /dev/null
+++ b/tex/context/base/page-bck.mkii
@@ -0,0 +1,593 @@
+%D \module
+%D [ file=page-bck, % copied from main-001
+%D version=1997.03.31,
+%D title=\CONTEXT\ Page Macros,
+%D subtitle=Backgrounds,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Page Macros / Backgrounds}
+
+% \chardef\kindofpagetextareas=1 will isolate graphics from backgrounds
+
+\unprotect
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+%D \macros
+%D {recalculatebackgrounds}
+%D
+%D We use a couple of switches so that we can minimize the
+%D amount of background calculations. The main switch is set
+%D by the recalculate directive.
+%D
+%D \starttyping
+%D \recalculatebackgrounds
+%D \stoptyping
+%D
+%D Other modules may not directly set the switches
+%D themselves.
+
+\newif\ifnewbackground
+\newif\ifsomebackground
+
+%D For special purposes, users can question the \type
+%D {*background} mode. This mode is only available when
+%D typesetting the pagebody.
+%D
+%D \starttyping
+%D \startmode[*background] ...
+%D \stoptyping
+
+\appendtoks
+ \ifsomebackground \ifnewbackground \setsystemmode\v!background \fi \fi
+\to \everybeforepagebody
+
+%D \macros
+%D {addmainbackground, addtextbackground,
+%D addpagebackground, addprintbackground}
+%D
+%D Apart from the previously mentioned directive, the
+%D interface between this module and the other modules
+%D is made up by four macros that add background to parts of
+%D the layout.
+%D
+%D \starttyping
+%D \addmainbackground
+%D \addtextbackground
+%D \addpagebackground
+%D \addprintbackground
+%D \stoptyping
+
+%D To minimize calculations, we keep track of the state of the
+%D background of each area. A previous implementation did
+%D check each call to the background calculation macro, but
+%D using an intermediate usage flag instead of testing each
+%D time saves about 3\% on a run with a couple of backgrounds.
+%D (On the 824 pages maps bibliography runtime went down from
+%D 309 to 299 seconds.)
+
+\def\checkbackground#1%
+ {\edef\!!stringe{\??ma#1}%
+ \doifelsevaluenothing{\!!stringe\c!background }
+ {\doifelsevaluenothing{\!!stringe\c!foregroundcolor}
+ {\doifelsevalue{\!!stringe\c!frame }\v!on\!!doneatrue
+ {\doifelsevalue{\!!stringe\c!leftframe }\v!on\!!doneatrue
+ {\doifelsevalue{\!!stringe\c!rightframe}\v!on\!!doneatrue
+ {\doifelsevalue{\!!stringe\c!topframe }\v!on\!!doneatrue
+ {\doifelsevalue{\!!stringe\c!bottomframe }\v!on\!!doneatrue
+ \!!doneafalse}}}}}
+ \!!doneatrue}
+ \!!doneatrue
+ \if!!donea
+ \setusage \!!stringe
+ \else
+ \resetusage\!!stringe
+ \fi}
+
+\def\ifsomebackgroundfound#1%
+ {\ifusage{\??ma#1}}
+
+% \def\doifsomebackgroundelse#1#2#3%
+% {\ifusage{\??ma#1}#2\else#3\fi}
+
+\def\doifsomebackgroundelse#1%
+ {\ifusage{\??ma#1}%
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+%D The background mechanism falls back on the \type {\framed}
+%D macro. This means that all normal frame and overlay
+%D features can be used.
+
+\def\addsomebackground#1#2#3#4% area box width height / zero test added
+ {\ifsomebackgroundfound#1\ifdim#3>\zeropoint\ifdim#4>\zeropoint
+ \doifvaluesomething{\??ma#1\c!setups}{\setups[\getvalue{\??ma#1\c!setups}]}% should not produce funny spaces !
+ \setbox#2\vbox\fastlocalframed
+ [\??ma#1]
+ [\c!component=#1,\c!strut=\v!no,\c!offset=\v!overlay,\c!setups=,%
+ \c!width=#3,\c!height=#4]
+ {\dp#2\zeropoint\box#2}%
+ \fi\fi\fi}
+
+%D There are quite some backgrounds. At the bottom layer,
+%D there is the {\em paper} background. This one is only
+%D used for special purposes, like annotations to documents.
+
+\def\addprintbackground#1%
+ {\addsomebackground
+ \v!paper#1\printpaperwidth\printpaperheight}
+
+%D The page backgrounds can be put behind the {\em left
+%D page}, the {\em right page} or {\em each page}. As with
+%D the paper background, these are calculated on each page.
+
+\def\addpagebackground#1%
+ {\doifbothsidesoverruled
+ {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
+ {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
+ {\addsomebackground\v!leftpage #1\paperwidth\paperheight}%
+ \addsomebackground\v!page #1\paperwidth\paperheight}
+
+%D Then there are the 25 areas that make up the layout: {\em
+%D top, header, text, footer, bottom} times {\em left edge,
+%D left margin, text, right margin, right edge}. These are
+%D only recalculated when they change or when the \type
+%D {status} is set to \type {repeat}.
+
+\newbox\leftbackground
+\newbox\rightbackground
+
+\def\addmainbackground#1% todo: dimension spec
+ {\ifsomebackground
+ \ifnewbackground \setbackgroundboxes \fi
+ \setbox#1\vbox
+ {\offinterlineskip
+ \doifmarginswapelse
+ {\copy\leftbackground}{\copy\rightbackground}%
+ \box#1}%
+ \fi}
+
+%D Finaly there is an aditional {\em text} background, again
+%D useful for special purposes only. This one is calculated
+%D each time. The hidden backgrounds are not meant for users!
+
+\newconditional\hiddenbackgroundenabled
+
+\def\addtextbackground#1%
+ {\ifconditional\hiddenbackgroundenabled
+ \addsomebackground\v!hidden#1\makeupwidth\textheight % mine !
+ \fi
+ \addsomebackground\v!text#1\makeupwidth\textheight}
+
+%D The next couple of macros implement the area backgrounds.
+%D As said, these are cached in dedicated boxes. The offsets
+%D and depth of the page are used for alignment purposes.
+
+\newdimen\pageoffset % bleed
+\newdimen\pagedepth
+
+\let\pagebackgroundhoffset\!!zeropoint
+\let\pagebackgroundvoffset\!!zeropoint
+\let\pagebackgrounddepth \!!zeropoint
+
+% \def\setbackgroundboxes
+% {\showmessage\m!layouts8\empty
+% \setbackgroundbox\leftbackground\relax
+% \ifdoublesided
+% \setbackgroundbox\rightbackground\doswapmargins
+% \fi
+% \doifnot\@@mastatus\v!herhaal{\global\newbackgroundfalse}}
+
+%D We need a bit more clever mechanism in order to handle
+%D layers well. This means that we cannot calculate both
+%D background at the same time since something may have
+%D changed halfway a page.
+
+\chardef\newrightbackground\zerocount
+\chardef\newleftbackground \zerocount
+
+\def\recalculatebackgrounds
+ {\global\newbackgroundtrue}
+
+\def\setbackgroundboxes
+ {\ifnewbackground
+ \global\chardef\newrightbackground\plusone
+ \global\chardef\newleftbackground\plusone
+ \global\setbox\leftbackground\emptybox
+ \global\setbox\rightbackground\emptybox
+ \fi
+ \doifbothsides
+ {\ifcase\newleftbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\leftbackground\relax
+ \global\chardef\newleftbackground\zerocount
+ \global\chardef\newrightbackground\zerocount
+ \fi}
+ {\ifcase\newleftbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\leftbackground\relax
+ \global\chardef\newleftbackground\zerocount
+ \fi}
+ {\ifcase\newrightbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\rightbackground\doswapmargins
+ \global\chardef\newrightbackground\zerocount
+ \fi}%
+ \ifx\@@mastate\v!repeat\else\global\newbackgroundfalse\fi}
+
+\def\addmainbackground#1% todo: dimension spec
+ {\ifsomebackground
+ \setbackgroundboxes
+ \setbox#1\vbox
+ {\offinterlineskip
+ \doifmarginswapelse
+ {\copy\leftbackground}
+ {\copy\rightbackground}
+ \box#1}%
+ \fi}
+
+\def\setbackgroundoffsets
+ {\ifsomebackground \ifnewbackground
+ \global\let\pagebackgroundhoffset\!!zeropoint
+ \global\let\pagebackgroundvoffset\!!zeropoint
+ \global\let\pagebackgrounddepth \!!zeropoint
+ \doifsomebackgroundelse{\v!text\v!text}\donetrue\donefalse
+ \ifdone\else\doifsomebackgroundelse\v!text\donetrue\donothing\fi
+ \ifdone
+ \bgroup
+ \scratchdimen\getvalue{\??ma\v!page\c!offset}%
+ \doifsomebackgroundelse{\v!top\v!text}\donothing
+ {\doifsomebackgroundelse{\v!bottom\v!text}\donothing
+ {\xdef\pagebackgroundhoffset{\the\scratchdimen}}}%
+ \doifsomebackgroundelse{\v!text\v!rightedge}\donothing
+ {\doifsomebackgroundelse{\v!text\v!leftedge}\donothing
+ {\xdef\pagebackgroundvoffset{\the\scratchdimen}%
+ \scratchdimen\getvalue{\??ma\v!page\c!depth}%
+ \xdef\pagebackgrounddepth{\the\scratchdimen}}}%
+ \egroup
+ \fi
+ \fi \fi}
+
+\appendtoks \setbackgroundoffsets \to \everybeforepagebody
+
+\newconditional\swapbackgroundmargins \settrue\swapbackgroundmargins
+
+\def\setbackgroundbox#1#2%
+ {\global\setbox#1\vbox
+ {\dontcomplain
+ \swapmargins
+ \ifconditional\swapbackgroundmargins
+ \doifmarginswapelse \donothing
+ {\swapmacros\v!rightmargin\v!leftmargin
+ \swapmacros\v!rightedge \v!leftedge}%
+ \fi
+ \calculatereducedvsizes
+ \offinterlineskip
+ #2\relax
+ \vskip\dimexpr-\topheight-\topdistance\relax
+ \dodopagebodybackground\v!top\topheight
+ \vskip\topdistance
+ \dodopagebodybackground\v!header\headerheight
+ \vskip\headerdistance
+ \dodopagebodybackground\v!text\textheight
+ \vskip\footerdistance
+ \dodopagebodybackground\v!footer\footerheight
+ \vskip\bottomdistance
+ \dodopagebodybackground\v!bottom\bottomheight
+ \vfilll}%
+ \smashbox#1}
+
+\def\dodopagebodybackground#1#2%
+ {\ifdim#2>\zeropoint % added, faster
+ \setbox\scratchbox\vbox to #2
+ \bgroup\hbox\bgroup
+ % \swapmargins
+ \goleftonpage
+ \dododopagebodybackground\leftedgewidth #2#1\v!leftedge
+ \hskip\leftedgedistance
+ \dododopagebodybackground\leftmarginwidth #2#1\v!leftmargin
+ \hskip\leftmargindistance
+ \dododopagebodybackground\makeupwidth #2#1\v!text
+ \hskip\rightmargindistance
+ \dododopagebodybackground\rightmarginwidth#2#1\v!rightmargin
+ \hskip\rightedgedistance
+ \dododopagebodybackground\rightedgewidth #2#1\v!rightedge
+ \egroup\egroup
+ \wd\scratchbox\zeropoint
+ \box\scratchbox\relax
+ \fi}
+
+\def\dododopagebodybackground#1#2#3#4% width height pos pos
+ {\ifsomebackgroundfound{#3#4}%
+ \ifdim#2>\zeropoint\relax
+ \ifdim#1>\zeropoint\relax
+ \doifvaluesomething{\??ma#3#4\c!setups}{\setups[\getvalue{\??ma#3#4\c!setups}]}% should not produce funny spaces !
+ \fastlocalframed
+ [\??ma#3#4]
+ [\c!component=#3-#4,\c!offset=\v!overlay,\c!setups=]
+ {\vbox to #2{\vss\hbox to#1{\hss\getvalue{\??ma#3#4\c!command}\hss}\vss}}%
+ \else
+ \hskip#1%
+ \fi
+ \else
+ \hskip#1%
+ \fi
+ \else
+ \hskip#1%
+ \fi}
+
+%D The background mechanism is quite demanding in terms or
+%D resources. We used to delay these definitions till runtime
+%D usage, but since today's \TEX's are large, we now do the
+%D work on forehand.
+%D
+%D \starttyping
+%D \setupbackgrounds [settings]
+%D \setupbackgrounds [paper,page,text,..] [settings]
+%D \setupbackgrounds [top,...] [leftedge,...] [settings]
+%D \stoptyping
+%D
+%D \showsetup{setupbackgrounds}
+%D
+%D Because the number of arguments runs from one to three,
+%D we need to check for it.
+
+\def\setupbackgrounds
+ {\dotripleempty\dosetupbackgrounds}
+
+\def\dosetupbackgrounds[#1][#2][#3]%
+ {\ifthirdargument
+ \global\somebackgroundtrue
+ \def\docommand##1%
+ {\doifinsetelse{##1}{\v!paper,\v!page,\v!leftpage,\v!rightpage}
+ {\getparameters[\??ma##1][#3]\checkbackground{##1}}
+ {\def\dodocommand####1{\getparameters[\??ma##1####1][#3]\checkbackground{##1####1}}%
+ \processcommalist[#2]\dodocommand}}%
+ \processcommalist[#1]\docommand
+ \else\ifsecondargument
+ \global\somebackgroundtrue
+ \doifcommonelse{#1}{\v!text,\v!hidden,\v!paper,\v!page,\v!leftpage,\v!rightpage}
+ {\def\docommand##1{\getparameters[\??ma##1][#2]\checkbackground{##1}}%
+ \processcommalist[#1]\docommand}%
+ {\setupbackgrounds
+ [#1]%
+ [\v!leftedge,\v!leftmargin,\v!text,\v!rightmargin,\v!rightedge]%
+ [#2]}%
+ \else\iffirstargument
+ \getparameters[\??ma][#1]%
+ \fi\fi\fi
+ \doifelsevalue{\??ma\v!page\c!offset}\v!overlay
+ {\global\pageoffset\zeropoint}
+ {\global\pageoffset\getvalue{\??ma\v!page\c!offset}}%
+ \global\pagedepth\getvalue{\??ma\v!page\c!depth}%
+ \xdef\pagebackgroundoffset{\the\pageoffset}%
+ \xdef\pagebackgrounddepth {\the\pagedepth }%
+ \doifelse\@@mastate\v!stop
+ {\global\newbackgroundfalse}
+ {\global\newbackgroundtrue }}
+
+\let\pagebackgroundoffset\!!zeropoint
+\let\pagebackgrounddepth \!!zeropoint
+
+%D Each areas (currently there are $1+3+25+1=30$ of them)
+%D has its own low level framed object associated.
+
+\presetlocalframed [\??ma\v!paper]
+\presetlocalframed [\??ma\v!page]
+\presetlocalframed [\??ma\v!leftpage]
+\presetlocalframed [\??ma\v!rightpage]
+
+\copyparameters
+ [\??ma\v!paper\c!frame][\??ma\v!page]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!paper\c!background][\??ma\v!page]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!page\c!frame][\??ma\v!page]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!page\c!background][\??ma\v!page]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!leftpage\c!frame][\??ma\v!leftpage]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!leftpage\c!background][\??ma\v!leftpage]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!rightpage\c!frame][\??ma\v!rightpage]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+\copyparameters
+ [\??ma\v!rightpage\c!background][\??ma\v!rightpage]
+ [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
+
+%D We save some keying by defining the areas using
+%D intermediate commands. The inheritance macro makes sure
+%D that copies are efficient.
+
+\def\dodocommand#1#2%
+ {\copylocalframed
+ [\??ma#1#2][\??ma\v!page]%
+ \getparameters
+ [\??ma#1#2]
+ [\c!background=,\c!frame=,\c!color=,\c!screen=\@@rsscreen,
+ \c!bottomframe=,\c!topframe=,\c!leftframe=,\c!rightframe=]%
+ \inheritparameter[\??ma][#1#2\c!color][\v!page\c!color]%
+ \inheritparameter[\??ma][#1#2\c!screen][\v!page\c!screen]%
+ \inheritparameter[\??ma][#1#2\c!framecolor][\v!page\c!framecolor]%
+ \inheritparameter[\??ma][#1#2\c!backgroundcolor][\v!page\c!backgroundcolor]%
+ \inheritparameter[\??ma][#1#2\c!backgroundscreen][\v!page\c!backgroundscreen]}
+
+%D The stand alone text area inherits from the page too.
+
+\dodocommand\v!text \empty
+\dodocommand\v!hidden\empty
+
+%D We now define all 25 main areas in a row.
+
+\def\docommand#1%
+ {\dodocommand#1\v!leftedge
+ \dodocommand#1\v!leftmargin
+ \dodocommand#1\v!text
+ \dodocommand#1\v!rightmargin
+ \dodocommand#1\v!rightedge}
+
+\docommand\v!top
+\docommand\v!header
+\docommand\v!text
+\docommand\v!footer
+\docommand\v!bottom
+
+%D We need some cleanup now.
+
+\let\dodocommand\relax \let\docommand\relax
+
+%D We now set up the individual areas to use reasonable
+%D defaults.
+
+\setupbackgrounds
+ [\c!state=\c!start]
+
+\setupbackgrounds
+ [\v!paper,\v!page,\v!leftpage,\v!rightpage]
+ [\c!frame=\v!off,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ \c!background=,
+ \c!screen=\@@rsscreen,
+ \c!color=,
+ %\c!frameoffset=\getvalue{\??ma\v!page\c!offset},
+ %\c!backgroundoffset=\getvalue{\??ma\v!page\c!offset},
+ \c!offset=\!!zeropoint, % later set to \v!overlay, watch out !
+ \c!depth=\!!zeropoint]
+
+\def\docommand#1%
+ {\inheritparameter[\??ma][#1\c!frameoffset][\v!page\c!offset]%
+ \inheritparameter[\??ma][#1\c!backgroundoffset][\v!page\c!offset]}
+
+\docommand\v!paper
+\docommand\v!page
+\docommand\v!leftpage
+\docommand\v!rightpage
+
+%D Again we clean up temporary macros.
+
+\let\docommand\relax
+
+%D The hidden layer can be populated by extending the
+%D following comma separated list. This only happens in core
+%D modules.
+
+% todo page-2 .. page+2 achter pagina -> bleed
+% spread-2 .. spread+2 achter spread -> spread (repeat 2 times)
+
+\def\enablehiddenbackground
+ {\global\settrue\hiddenbackgroundenabled
+ \global\somebackgroundtrue
+ \recalculatebackgrounds}
+
+\def\disablehiddenbackground
+ {\global\setfalse\hiddenbackgroundenabled}
+
+\def\hiddenbackground
+ {\v!text-2,\v!text-1,\v!foreground,\v!text+1,\v!text+2}
+
+\setupbackgrounds
+ [\v!hidden]
+ [\c!background=\hiddenbackground]
+
+% The next series is used in local (for instance floating)
+% backgrounds.
+
+\presetlocalframed
+ [\??ma\v!local]
+
+\def\localbackground
+ {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2}
+
+\defineoverlay[\v!local-2][\positionoverlay{\v!local-2}]
+\defineoverlay[\v!local-1][\positionoverlay{\v!local-1}]
+\defineoverlay[\v!local+1][\positionoverlay{\v!local+1}]
+\defineoverlay[\v!local+2][\positionoverlay{\v!local+2}]
+
+\def\addlocalbackgroundtobox
+ {\ifconditional\hiddenbackgroundenabled
+ \expandafter\doaddlocalbackground
+ \else
+ \resetglobal \expandafter\gobbleoneargument
+ \fi}
+
+\def\doaddlocalbackground#1%
+ {\dodoglobal\setbox#1\hbox
+ {\fastlocalframed % \localframed
+ [\??ma\v!local]
+ [\c!component=local,\c!frame=\v!off,\c!offset=\v!overlay,\c!setups=,%
+ \c!location=\v!keep,% when we use \localframed instead of \fastlocalframed
+ \c!background=\localbackground]%
+ {\registerMPlocaltextarea{\box#1}}}%
+ \resetglobal % redundant
+ \doglobal\increment\localpositionnumber\relax} % afterwards !
+
+% Test how previous macro behaves with depth:
+%
+% \startcolumnset
+% \input tufte
+% \placefigure{none}{\framed[lines=5]{xxx}}
+% \input tufte
+% \placefigure{none}{\starttabulate\NC test\nc test\NC\NR\stoptabulate}
+% \input tufte
+% \stopcolumnset
+
+%D Because we haven't really set up backgrounds yet, we set
+%D the main efficiency switch to false.
+
+\somebackgroundfalse
+
+\protect \endinput
+
+%D Removed \quote {features}:
+%D
+%D \starttyping
+%D \startinteraction
+%D \doifmarginswapelse
+%D {\copy\leftbackground}
+%D {\copy\rightbackground}%
+%D \stopinteraction
+%D \stoptyping
+%D
+%D \starttyping
+%D \edef\setpagebackgrounddepth%
+%D {\dp#2=\the\dp#2}%
+%D \setbox#2=\vbox\localframed[\??ma#1]{...}
+%D \setpagebackgrounddepth
+%D \stoptyping
diff --git a/tex/context/base/page-bck.mkiv b/tex/context/base/page-bck.mkiv
new file mode 100644
index 000000000..2522c882d
--- /dev/null
+++ b/tex/context/base/page-bck.mkiv
@@ -0,0 +1,521 @@
+%D \module
+%D [ file=page-bck, % copied from main-001
+%D version=1997.03.31,
+%D title=\CONTEXT\ Page Macros,
+%D subtitle=Backgrounds,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Page Macros / Backgrounds}
+
+% \chardef\kindofpagetextareas=1 will isolate graphics from backgrounds
+
+\unprotect
+
+%D \macros
+%D {recalculatebackgrounds}
+%D
+%D We use a couple of switches so that we can minimize the
+%D amount of background calculations. The main switch is set
+%D by the recalculate directive.
+%D
+%D \starttyping
+%D \recalculatebackgrounds
+%D \stoptyping
+%D
+%D Other modules may not directly set the switches
+%D themselves.
+
+\newif\ifnewbackground
+\newif\ifsomebackground
+
+%D For special purposes, users can question the \type
+%D {*background} mode. This mode is only available when
+%D typesetting the pagebody.
+%D
+%D \starttyping
+%D \startmode[*background] ...
+%D \stoptyping
+
+\appendtoks
+ \ifsomebackground \ifnewbackground \setsystemmode\v!background \fi \fi
+\to \everybeforepagebody
+
+%D \macros
+%D {addmainbackground, addtextbackground,
+%D addpagebackground, addprintbackground}
+%D
+%D Apart from the previously mentioned directive, the
+%D interface between this module and the other modules
+%D is made up by four macros that add background to parts of
+%D the layout.
+%D
+%D \starttyping
+%D \addmainbackground
+%D \addtextbackground
+%D \addpagebackground
+%D \addprintbackground
+%D \stoptyping
+
+%D To minimize calculations, we keep track of the state of the
+%D background of each area. A previous implementation did
+%D check each call to the background calculation macro, but
+%D using an intermediate usage flag instead of testing each
+%D time saves about 3\% on a run with a couple of backgrounds.
+%D (On the 824 pages maps bibliography runtime went down from
+%D 309 to 299 seconds.)
+
+\let\currentotrbackground\empty
+
+\def\@@docheckbackground#1#2%
+ {\ifcsname\currentotrbackground#1\endcsname
+ \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\!!doneatrue\fi
+ \fi}
+
+\def\@@nocheckbackground#1#2%
+ {\ifcsname\currentotrbackground#1\endcsname
+ \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\else\!!doneatrue\fi
+ \fi}
+
+\def\checkbackground#1%
+ {\edef\currentotrbackground{\??ma#1}%
+ \begingroup
+ \!!doneafalse
+ \if!!donea\else\@@nocheckbackground\c!background \empty
+ \if!!donea\else\@@docheckbackground\c!frame \v!on
+ \if!!donea\else\@@nocheckbackground\c!foregroundcolor\empty
+ \if!!donea\else\@@docheckbackground\c!leftframe \v!on
+ \if!!donea\else\@@docheckbackground\c!rightframe \v!on
+ \if!!donea\else\@@docheckbackground\c!topframe \v!on
+ \if!!donea\else\@@docheckbackground\c!bottomframe \v!on \fi\fi\fi\fi\fi\fi\fi
+ \if!!donea
+ \endgroup\setusage \currentotrbackground
+ \else
+ \endgroup\resetusage\currentotrbackground
+ \fi}
+
+\def\ifsomebackgroundfound#1%
+ {\ifusage{\??ma#1}}
+
+\def\doifsomebackgroundelse#1%
+ {\ifusage{\??ma#1}%
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+%D The background mechanism falls back on the \type {\framed}
+%D macro. This means that all normal frame and overlay
+%D features can be used.
+
+\def\addsomebackground#1#2#3#4% area box width height / zero test added
+ {\ifsomebackgroundfound#1\ifdim#3>\zeropoint\ifdim#4>\zeropoint
+ \ifcsname\??ma#1\c!setups\endcsname % to be done
+ \doifvaluesomething{\??ma#1\c!setups}{\setups[\getvalue{\??ma#1\c!setups}]}% should not produce funny spaces !
+ \fi
+ \setbox#2\vbox\fastlocalframed
+ [\??ma#1]
+ [\c!component=#1,\c!width=#3,\c!height=#4]% are width and height used?
+ {\dp#2\zeropoint\box#2}%
+ \fi\fi\fi}
+
+%D There are quite some backgrounds. At the bottom layer,
+%D there is the {\em paper} background. This one is only
+%D used for special purposes, like annotations to documents.
+
+\def\addprintbackground#1%
+ {\addsomebackground\v!paper#1\printpaperwidth\printpaperheight}
+
+%D The page backgrounds can be put behind the {\em left
+%D page}, the {\em right page} or {\em each page}. As with
+%D the paper background, these are calculated on each page.
+
+\def\addpagebackground#1%
+ {\doifbothsidesoverruled
+ {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
+ {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
+ {\addsomebackground\v!leftpage #1\paperwidth\paperheight}%
+ \addsomebackground\v!page #1\paperwidth\paperheight}
+
+%D Then there are the 25 areas that make up the layout: {\em
+%D top, header, text, footer, bottom} times {\em left edge,
+%D left margin, text, right margin, right edge}. These are
+%D only recalculated when they change or when the \type
+%D {status} is set to \type {repeat}.
+
+\newbox\leftbackground
+\newbox\rightbackground
+
+\def\addmainbackground#1% todo: dimension spec
+ {\ifsomebackground
+ \ifnewbackground \setbackgroundboxes \fi
+ \setbox#1\vbox
+ {\offinterlineskip
+ \doifmarginswapelse{\copy\leftbackground}{\copy\rightbackground}%
+ \box#1}%
+ \fi}
+
+%D Finaly there is an aditional {\em text} background, again
+%D useful for special purposes only. This one is calculated
+%D each time. The hidden backgrounds are not meant for users!
+
+\newconditional\hiddenbackgroundenabled
+
+\def\addtextbackground#1%
+ {\ifconditional\hiddenbackgroundenabled
+ \addsomebackground\v!hidden#1\makeupwidth\textheight % mine !
+ \fi
+ \addsomebackground\v!text#1\makeupwidth\textheight}
+
+%D The next couple of macros implement the area backgrounds.
+%D As said, these are cached in dedicated boxes. The offsets
+%D and depth of the page are used for alignment purposes.
+
+\newdimen\pageoffset % bleed
+\newdimen\pagedepth
+
+\let\pagebackgroundhoffset\!!zeropoint
+\let\pagebackgroundvoffset\!!zeropoint
+\let\pagebackgrounddepth \!!zeropoint
+
+% \def\setbackgroundboxes
+% {\showmessage\m!layouts8\empty
+% \setbackgroundbox\leftbackground\relax
+% \ifdoublesided
+% \setbackgroundbox\rightbackground\doswapmargins
+% \fi
+% \doifnot\@@mastatus\v!herhaal{\global\newbackgroundfalse}}
+
+%D We need a bit more clever mechanism in order to handle
+%D layers well. This means that we cannot calculate both
+%D background at the same time since something may have
+%D changed halfway a page.
+
+\chardef\newrightbackground\zerocount
+\chardef\newleftbackground \zerocount
+
+\def\recalculatebackgrounds
+ {\global\newbackgroundtrue}
+
+\def\setbackgroundboxes
+ {\ifnewbackground
+ \global\chardef\newrightbackground\plusone
+ \global\chardef\newleftbackground\plusone
+ \global\setbox\leftbackground\emptybox
+ \global\setbox\rightbackground\emptybox
+ \fi
+ \doifbothsides
+ {\ifcase\newleftbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\leftbackground\relax
+ \global\chardef\newleftbackground\zerocount
+ \global\chardef\newrightbackground\zerocount
+ \fi}
+ {\ifcase\newleftbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\leftbackground\relax
+ \global\chardef\newleftbackground\zerocount
+ \fi}
+ {\ifcase\newrightbackground \else
+ % \showmessage\m!layouts8\empty
+ \setbackgroundbox\rightbackground\doswapmargins
+ \global\chardef\newrightbackground\zerocount
+ \fi}%
+ \ifx\@@mastate\v!repeat\else\global\newbackgroundfalse\fi}
+
+\def\addmainbackground#1% todo: dimension spec
+ {\ifsomebackground
+ \setbackgroundboxes
+ \setbox#1\vbox
+ {\offinterlineskip
+ \doifmarginswapelse{\copy\leftbackground}{\copy\rightbackground}%
+ \box#1}%
+ \fi}
+
+\def\setbackgroundoffsets
+ {\ifsomebackground \ifnewbackground
+ \global\let\pagebackgroundhoffset\!!zeropoint
+ \global\let\pagebackgroundvoffset\!!zeropoint
+ \global\let\pagebackgrounddepth \!!zeropoint
+ \doifsomebackgroundelse{\v!text\v!text}\donetrue\donefalse
+ \ifdone\else\doifsomebackgroundelse\v!text\donetrue\donothing\fi
+ \ifdone
+ \bgroup
+ \scratchdimen\getvalue{\??ma\v!page\c!offset}%
+ \doifsomebackgroundelse{\v!top\v!text}\donothing
+ {\doifsomebackgroundelse{\v!bottom\v!text}\donothing
+ {\xdef\pagebackgroundhoffset{\the\scratchdimen}}}%
+ \doifsomebackgroundelse{\v!text\v!rightedge}\donothing
+ {\doifsomebackgroundelse{\v!text\v!leftedge}\donothing
+ {\xdef\pagebackgroundvoffset{\the\scratchdimen}%
+ \scratchdimen\getvalue{\??ma\v!page\c!depth}%
+ \xdef\pagebackgrounddepth{\the\scratchdimen}}}%
+ \egroup
+ \fi
+ \fi \fi}
+
+\appendtoks \setbackgroundoffsets \to \everybeforepagebody
+
+\newconditional\swapbackgroundmargins \settrue\swapbackgroundmargins
+
+\def\setbackgroundbox#1#2%
+ {\global\setbox#1\vbox
+ {\dontcomplain
+ \swapmargins
+ \ifconditional\swapbackgroundmargins
+ \doifmarginswapelse \donothing
+ {\swapmacros\v!rightmargin\v!leftmargin
+ \swapmacros\v!rightedge \v!leftedge}%
+ \fi
+ \calculatereducedvsizes
+ \offinterlineskip
+ #2\relax
+ \vskip\dimexpr-\topheight-\topdistance\relax
+ \dodopagebodybackground\v!top\topheight
+ \vskip\topdistance
+ \dodopagebodybackground\v!header\headerheight
+ \vskip\headerdistance
+ \dodopagebodybackground\v!text\textheight
+ \vskip\footerdistance
+ \dodopagebodybackground\v!footer\footerheight
+ \vskip\bottomdistance
+ \dodopagebodybackground\v!bottom\bottomheight
+ \vfilll}%
+ \smashbox#1}
+
+\def\dodopagebodybackground#1#2%
+ {\ifdim#2>\zeropoint % added, faster
+ \setbox\scratchbox\vbox to #2
+ \bgroup\hbox\bgroup
+ % \swapmargins
+ \goleftonpage
+ \dododopagebodybackground\leftedgewidth #2#1\v!leftedge
+ \hskip\leftedgedistance
+ \dododopagebodybackground\leftmarginwidth #2#1\v!leftmargin
+ \hskip\leftmargindistance
+ \dododopagebodybackground\makeupwidth #2#1\v!text
+ \hskip\rightmargindistance
+ \dododopagebodybackground\rightmarginwidth#2#1\v!rightmargin
+ \hskip\rightedgedistance
+ \dododopagebodybackground\rightedgewidth #2#1\v!rightedge
+ \egroup\egroup
+ \wd\scratchbox\zeropoint
+ \box\scratchbox\relax
+ \fi}
+
+\def\dododopagebodybackground#1#2#3#4% width height pos pos
+ {\ifsomebackgroundfound{#3#4}%
+ \ifdim#2>\zeropoint\relax
+ \ifdim#1>\zeropoint\relax
+ \ifcsname\??ma#3#4\c!setups\endcsname % to be done
+ \doifvaluesomething{\??ma#3#4\c!setups}{\setups[\getvalue{\??ma#3#4\c!setups}]}% should not produce funny spaces !
+ \fi
+ \fastlocalframed
+ [\??ma#3#4]
+ [\c!component=#3-#4]
+ {\vbox to #2{\vss\hbox to#1{\hss\getvalue{\??ma#3#4\c!command}\hss}\vss}}%
+ \else
+ \hskip#1%
+ \fi
+ \else
+ \hskip#1%
+ \fi
+ \else
+ \hskip#1%
+ \fi}
+
+%D The background mechanism is quite demanding in terms or
+%D resources. We used to delay these definitions till runtime
+%D usage, but since today's \TEX's are large, we now do the
+%D work on forehand.
+%D
+%D \starttyping
+%D \setupbackgrounds [settings]
+%D \setupbackgrounds [paper,page,text,..] [settings]
+%D \setupbackgrounds [top,...] [leftedge,...] [settings]
+%D \stoptyping
+%D
+%D \showsetup{setupbackgrounds}
+%D
+%D Because the number of arguments runs from one to three,
+%D we need to check for it.
+
+\def\setupbackgrounds
+ {\dotripleempty\dosetupbackgrounds}
+
+\def\dosetupbackgrounds[#1][#2][#3]%
+ {\ifthirdargument
+ \global\somebackgroundtrue
+ \def\docommand##1%
+ {\doifinsetelse{##1}{\v!paper,\v!page,\v!leftpage,\v!rightpage}
+ {\getparameters[\??ma##1][#3]\checkbackground{##1}}
+ {\def\dodocommand####1{\getparameters[\??ma##1####1][#3]\checkbackground{##1####1}}%
+ \processcommalist[#2]\dodocommand}}%
+ \processcommalist[#1]\docommand
+ \else\ifsecondargument
+ \global\somebackgroundtrue
+ \doifcommonelse{#1}{\v!text,\v!hidden,\v!paper,\v!page,\v!leftpage,\v!rightpage}
+ {\def\docommand##1{\getparameters[\??ma##1][#2]\checkbackground{##1}}%
+ \processcommalist[#1]\docommand}%
+ {\setupbackgrounds
+ [#1]%
+ [\v!leftedge,\v!leftmargin,\v!text,\v!rightmargin,\v!rightedge]%
+ [#2]}%
+ \else\iffirstargument
+ \getparameters[\??ma][#1]%
+ \fi\fi\fi
+ \doifelsevalue{\??ma\v!page\c!offset}\v!overlay
+ {\global\pageoffset\zeropoint}
+ {\global\pageoffset\getvalue{\??ma\v!page\c!offset}}%
+ \global\pagedepth\getvalue{\??ma\v!page\c!depth}%
+ \xdef\pagebackgroundoffset{\the\pageoffset}%
+ \xdef\pagebackgrounddepth {\the\pagedepth }%
+ \doifelse\@@mastate\v!stop
+ {\global\newbackgroundfalse}
+ {\global\newbackgroundtrue }}
+
+\let\pagebackgroundoffset\!!zeropoint
+\let\pagebackgrounddepth \!!zeropoint
+
+%D Each areas (currently there are $1+3+25+1=30$ of them)
+%D has its own low level framed object associated.
+
+\def\installsomebackground#1#2{\inheritlocalframed[\??ma#1#2][\??od]}
+
+\installsomebackground \v!paper \empty
+\installsomebackground \v!page \empty
+\installsomebackground \v!leftpage \empty
+\installsomebackground \v!rightpage \empty
+
+%D The stand alone text area inherits from the page too.
+
+\installsomebackground \v!text \empty
+\installsomebackground \v!hidden \empty
+
+%D We save some keying by defining the areas using a helper:
+
+\def\docommand#1%
+ {\installsomebackground#1\v!leftedge
+ \installsomebackground#1\v!leftmargin
+ \installsomebackground#1\v!text
+ \installsomebackground#1\v!rightmargin
+ \installsomebackground#1\v!rightedge}
+
+\docommand \v!top
+\docommand \v!header
+\docommand \v!text
+\docommand \v!footer
+\docommand \v!bottom
+
+%D We need some cleanup now.
+
+\let\docommand\relax
+
+%D We now set up the individual areas to use reasonable
+%D defaults.
+
+\installsomebackground \v!paper \empty
+\installsomebackground \v!page \empty
+\installsomebackground \v!leftpage \empty
+\installsomebackground \v!rightpage \empty
+
+\getparameters
+ [\??ma\v!page]
+ [\c!offset=\!!zeropoint, % hm, so we need to force overlay elsewhere
+ \c!depth=\!!zeropoint]
+
+%D General setup:
+
+\setupbackgrounds
+ [\c!state=\c!start]
+
+%D The hidden layer can be populated by extending the
+%D following comma separated list. This only happens in core
+%D modules.
+
+% todo page-2 .. page+2 achter pagina -> bleed
+% spread-2 .. spread+2 achter spread -> spread (repeat 2 times)
+
+\def\enablehiddenbackground
+ {\global\settrue\hiddenbackgroundenabled
+ \global\somebackgroundtrue
+ \recalculatebackgrounds}
+
+\def\disablehiddenbackground
+ {\global\setfalse\hiddenbackgroundenabled}
+
+\def\hiddenbackground
+ {\v!text-2,\v!text-1,\v!foreground,\v!text+1,\v!text+2}
+
+\setupbackgrounds
+ [\v!hidden]
+ [\c!background=\hiddenbackground]
+
+% The next series is used in local (for instance floating)
+% backgrounds.
+
+\installsomebackground \v!local \empty % not really a background, invisible for users
+
+\getparameters
+ [\??ma\v!local]
+ [\c!component=local,
+ \c!background=\localbackground]
+
+\def\localbackground
+ {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2}
+
+\defineoverlay[\v!local-2][\positionoverlay{\v!local-2}]
+\defineoverlay[\v!local-1][\positionoverlay{\v!local-1}]
+\defineoverlay[\v!local+1][\positionoverlay{\v!local+1}]
+\defineoverlay[\v!local+2][\positionoverlay{\v!local+2}]
+
+\def\addlocalbackgroundtobox
+ {\ifconditional\hiddenbackgroundenabled
+ \expandafter\doaddlocalbackground
+ \else
+ \resetglobal \expandafter\gobbleoneargument
+ \fi}
+
+\def\doaddlocalbackground#1%
+ {\dodoglobal\setbox#1\hbox{\fastlocalframed[\??ma\v!local][]{\registerMPlocaltextarea{\box#1}}}%
+ \resetglobal % redundant
+ \doglobal\increment\localpositionnumber\relax} % afterwards !
+
+% Test how previous macro behaves with depth:
+%
+% \startcolumnset
+% \input tufte
+% \placefigure{none}{\framed[lines=5]{xxx}}
+% \input tufte
+% \placefigure{none}{\starttabulate\NC test\nc test\NC\NR\stoptabulate}
+% \input tufte
+% \stopcolumnset
+
+%D Because we haven't really set up backgrounds yet, we set
+%D the main efficiency switch to false.
+
+\somebackgroundfalse
+
+\protect \endinput
+
+%D Removed \quote {features}:
+%D
+%D \starttyping
+%D \startinteraction
+%D \doifmarginswapelse
+%D {\copy\leftbackground}
+%D {\copy\rightbackground}%
+%D \stopinteraction
+%D \stoptyping
+%D
+%D \starttyping
+%D \edef\setpagebackgrounddepth%
+%D {\dp#2=\the\dp#2}%
+%D \setbox#2=\vbox\localframed[\??ma#1]{...}
+%D \setpagebackgrounddepth
+%D \stoptyping
diff --git a/tex/context/base/page-bck.tex b/tex/context/base/page-bck.tex
deleted file mode 100644
index 10123fec6..000000000
--- a/tex/context/base/page-bck.tex
+++ /dev/null
@@ -1,615 +0,0 @@
-%D \module
-%D [ file=page-bck, % copied from main-001
-%D version=1997.03.31,
-%D title=\CONTEXT\ Page Macros,
-%D subtitle=Backgrounds,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Page Macros / Backgrounds}
-
-% \chardef\kindofpagetextareas=1 will isolate graphics from backgrounds
-
-\unprotect
-
-\startmessages dutch library: layouts
- 8: achtergronden berekenen
-\stopmessages
-
-\startmessages english library: layouts
- 8: calculating backgrounds
-\stopmessages
-
-\startmessages german library: layouts
- 8: berechne Hintergrund
-\stopmessages
-
-\startmessages czech library: layouts
- 8: pocita se pozadi
-\stopmessages
-
-\startmessages italian library: layouts
- 8: calcolo dello sfondo
-\stopmessages
-
-\startmessages norwegian library: layouts
- 8: beregner bakgrunn
-\stopmessages
-
-\startmessages romanian library: layouts
- 8: se calculeaza fundalurile
-\stopmessages
-
-\startmessages french library: layouts
- 8: calcul des arrières-plans
-\stopmessages
-
-%D \macros
-%D {recalculatebackgrounds}
-%D
-%D We use a couple of switches so that we can minimize the
-%D amount of background calculations. The main switch is set
-%D by the recalculate directive.
-%D
-%D \starttyping
-%D \recalculatebackgrounds
-%D \stoptyping
-%D
-%D Other modules may not directly set the switches
-%D themselves.
-
-\newif\ifnewbackground
-\newif\ifsomebackground
-
-%D For special purposes, users can question the \type
-%D {*background} mode. This mode is only available when
-%D typesetting the pagebody.
-%D
-%D \starttyping
-%D \startmode[*background] ...
-%D \stoptyping
-
-\appendtoks
- \ifsomebackground \ifnewbackground \setsystemmode\v!background \fi \fi
-\to \everybeforepagebody
-
-%D \macros
-%D {addmainbackground, addtextbackground,
-%D addpagebackground, addprintbackground}
-%D
-%D Apart from the previously mentioned directive, the
-%D interface between this module and the other modules
-%D is made up by four macros that add background to parts of
-%D the layout.
-%D
-%D \starttyping
-%D \addmainbackground
-%D \addtextbackground
-%D \addpagebackground
-%D \addprintbackground
-%D \stoptyping
-
-%D To minimize calculations, we keep track of the state of the
-%D background of each area. A previous implementation did
-%D check each call to the background calculation macro, but
-%D using an intermediate usage flag instead of testing each
-%D time saves about 3\% on a run with a couple of backgrounds.
-%D (On the 824 pages maps bibliography runtime went down from
-%D 309 to 299 seconds.)
-
-\def\checkbackground#1%
- {\edef\!!stringe{\??ma#1}%
- \doifelsevaluenothing{\!!stringe\c!background }
- {\doifelsevaluenothing{\!!stringe\c!foregroundcolor}
- {\doifelsevalue{\!!stringe\c!frame }\v!on\!!doneatrue
- {\doifelsevalue{\!!stringe\c!leftframe }\v!on\!!doneatrue
- {\doifelsevalue{\!!stringe\c!rightframe}\v!on\!!doneatrue
- {\doifelsevalue{\!!stringe\c!topframe }\v!on\!!doneatrue
- {\doifelsevalue{\!!stringe\c!bottomframe }\v!on\!!doneatrue
- \!!doneafalse}}}}}
- \!!doneatrue}
- \!!doneatrue
- \if!!donea
- \setusage \!!stringe
- \else
- \resetusage\!!stringe
- \fi}
-
-\def\ifsomebackgroundfound#1%
- {\ifusage{\??ma#1}}
-
-% \def\doifsomebackgroundelse#1#2#3%
-% {\ifusage{\??ma#1}#2\else#3\fi}
-
-\def\doifsomebackgroundelse#1%
- {\ifusage{\??ma#1}%
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-%D The background mechanism falls back on the \type {\framed}
-%D macro. This means that all normal frame and overlay
-%D features can be used.
-
-\def\addsomebackground#1#2#3#4% area box width height / zero test added
- {\ifsomebackgroundfound#1\ifdim#3>\zeropoint\ifdim#4>\zeropoint
- \doifvaluesomething{\??ma#1\c!setups}{\setups[\getvalue{\??ma#1\c!setups}]}% should not produce funny spaces !
- \setbox#2\vbox\fastlocalframed
- [\??ma#1]
- [\c!component=#1,\c!strut=\v!no,\c!offset=\v!overlay,\c!setups=,%
- \c!width=#3,\c!height=#4]
- {\dp#2\zeropoint\box#2}%
- \fi\fi\fi}
-
-%D There are quite some backgrounds. At the bottom layer,
-%D there is the {\em paper} background. This one is only
-%D used for special purposes, like annotations to documents.
-
-\def\addprintbackground#1%
- {\addsomebackground
- \v!paper#1\printpaperwidth\printpaperheight}
-
-%D The page backgrounds can be put behind the {\em left
-%D page}, the {\em right page} or {\em each page}. As with
-%D the paper background, these are calculated on each page.
-
-\def\addpagebackground#1%
- {\doifbothsidesoverruled
- {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
- {\addsomebackground\v!rightpage#1\paperwidth\paperheight}
- {\addsomebackground\v!leftpage #1\paperwidth\paperheight}%
- \addsomebackground\v!page #1\paperwidth\paperheight}
-
-%D Then there are the 25 areas that make up the layout: {\em
-%D top, header, text, footer, bottom} times {\em left edge,
-%D left margin, text, right margin, right edge}. These are
-%D only recalculated when they change or when the \type
-%D {status} is set to \type {repeat}.
-
-\newbox\leftbackground
-\newbox\rightbackground
-
-\def\addmainbackground#1% todo: dimension spec
- {\ifsomebackground
- \ifnewbackground \setbackgroundboxes \fi
- \setbox#1\vbox
- {\offinterlineskip
- \doifmarginswapelse
- {\copy\leftbackground}{\copy\rightbackground}%
- \box#1}%
- \fi}
-
-%D Finaly there is an aditional {\em text} background, again
-%D useful for special purposes only. This one is calculated
-%D each time. The hidden backgrounds are not meant for users!
-
-\newconditional\hiddenbackgroundenabled
-
-\def\addtextbackground#1%
- {\ifconditional\hiddenbackgroundenabled
- \addsomebackground\v!hidden#1\makeupwidth\textheight % mine !
- \fi
- \addsomebackground\v!text#1\makeupwidth\textheight}
-
-%D The next couple of macros implement the area backgrounds.
-%D As said, these are cached in dedicated boxes. The offsets
-%D and depth of the page are used for alignment purposes.
-
-\newdimen\pageoffset % bleed
-\newdimen\pagedepth
-
-\let\pagebackgroundhoffset\!!zeropoint
-\let\pagebackgroundvoffset\!!zeropoint
-\let\pagebackgrounddepth \!!zeropoint
-
-% \def\setbackgroundboxes
-% {\showmessage\m!layouts8\empty
-% \setbackgroundbox\leftbackground\relax
-% \ifdoublesided
-% \setbackgroundbox\rightbackground\doswapmargins
-% \fi
-% \doifnot\@@mastatus\v!herhaal{\global\newbackgroundfalse}}
-
-%D We need a bit more clever mechanism in order to handle
-%D layers well. This means that we cannot calculate both
-%D background at the same time since something may have
-%D changed halfway a page.
-
-\chardef\newrightbackground\zerocount
-\chardef\newleftbackground \zerocount
-
-\def\recalculatebackgrounds
- {\global\newbackgroundtrue}
-
-\def\setbackgroundboxes
- {\ifnewbackground
- \global\chardef\newrightbackground\plusone
- \global\chardef\newleftbackground\plusone
- \global\setbox\leftbackground\emptybox
- \global\setbox\rightbackground\emptybox
- \fi
- \doifbothsides
- {\ifcase\newleftbackground \else
- % \showmessage\m!layouts8\empty
- \setbackgroundbox\leftbackground\relax
- \global\chardef\newleftbackground\zerocount
- \global\chardef\newrightbackground\zerocount
- \fi}
- {\ifcase\newleftbackground \else
- % \showmessage\m!layouts8\empty
- \setbackgroundbox\leftbackground\relax
- \global\chardef\newleftbackground\zerocount
- \fi}
- {\ifcase\newrightbackground \else
- % \showmessage\m!layouts8\empty
- \setbackgroundbox\rightbackground\doswapmargins
- \global\chardef\newrightbackground\zerocount
- \fi}%
- \ifx\@@mastate\v!repeat\else\global\newbackgroundfalse\fi}
-
-\def\addmainbackground#1% todo: dimension spec
- {\ifsomebackground
- \setbackgroundboxes
- \setbox#1\vbox
- {\offinterlineskip
- \doifmarginswapelse
- {\copy\leftbackground}
- {\copy\rightbackground}
- \box#1}%
- \fi}
-
-\def\setbackgroundoffsets
- {\ifsomebackground \ifnewbackground
- \global\let\pagebackgroundhoffset\!!zeropoint
- \global\let\pagebackgroundvoffset\!!zeropoint
- \global\let\pagebackgrounddepth \!!zeropoint
- \doifsomebackgroundelse{\v!text\v!text}\donetrue\donefalse
- \ifdone\else\doifsomebackgroundelse\v!text\donetrue\donothing\fi
- \ifdone
- \bgroup
- \scratchdimen\getvalue{\??ma\v!page\c!offset}%
- \doifsomebackgroundelse{\v!top\v!text}\donothing
- {\doifsomebackgroundelse{\v!bottom\v!text}\donothing
- {\xdef\pagebackgroundhoffset{\the\scratchdimen}}}%
- \doifsomebackgroundelse{\v!text\v!rightedge}\donothing
- {\doifsomebackgroundelse{\v!text\v!leftedge}\donothing
- {\xdef\pagebackgroundvoffset{\the\scratchdimen}%
- \scratchdimen\getvalue{\??ma\v!page\c!depth}%
- \xdef\pagebackgrounddepth{\the\scratchdimen}}}%
- \egroup
- \fi
- \fi \fi}
-
-\appendtoks \setbackgroundoffsets \to \everybeforepagebody
-
-\newconditional\swapbackgroundmargins \settrue\swapbackgroundmargins
-
-\def\setbackgroundbox#1#2%
- {\global\setbox#1\vbox
- {\dontcomplain
- \swapmargins
- \ifconditional\swapbackgroundmargins
- \doifmarginswapelse \donothing
- {\swapmacros\v!rightmargin\v!leftmargin
- \swapmacros\v!rightedge \v!leftedge}%
- \fi
- \calculatereducedvsizes
- \offinterlineskip
- #2\relax
- \vskip\dimexpr-\topheight-\topdistance\relax
- \dodopagebodybackground\v!top\topheight
- \vskip\topdistance
- \dodopagebodybackground\v!header\headerheight
- \vskip\headerdistance
- \dodopagebodybackground\v!text\textheight
- \vskip\footerdistance
- \dodopagebodybackground\v!footer\footerheight
- \vskip\bottomdistance
- \dodopagebodybackground\v!bottom\bottomheight
- \vfilll}%
- \smashbox#1}
-
-\def\dodopagebodybackground#1#2%
- {\ifdim#2>\zeropoint % added, faster
- \setbox\scratchbox\vbox to #2
- \bgroup\hbox\bgroup
- % \swapmargins
- \goleftonpage
- \dododopagebodybackground\leftedgewidth #2#1\v!leftedge
- \hskip\leftedgedistance
- \dododopagebodybackground\leftmarginwidth #2#1\v!leftmargin
- \hskip\leftmargindistance
- \dododopagebodybackground\makeupwidth #2#1\v!text
- \hskip\rightmargindistance
- \dododopagebodybackground\rightmarginwidth#2#1\v!rightmargin
- \hskip\rightedgedistance
- \dododopagebodybackground\rightedgewidth #2#1\v!rightedge
- \egroup\egroup
- \wd\scratchbox\zeropoint
- \box\scratchbox\relax
- \fi}
-
-\def\dododopagebodybackground#1#2#3#4% width height pos pos
- {\ifsomebackgroundfound{#3#4}%
- \ifdim#2>\zeropoint\relax
- \ifdim#1>\zeropoint\relax
- \doifvaluesomething{\??ma#3#4\c!setups}{\setups[\getvalue{\??ma#3#4\c!setups}]}% should not produce funny spaces !
- \fastlocalframed
- [\??ma#3#4]
- [\c!component=#3-#4,\c!offset=\v!overlay,\c!setups=]
- {\vbox to #2{\vss\hbox to#1{\hss\getvalue{\??ma#3#4\c!command}\hss}\vss}}%
- \else
- \hskip#1%
- \fi
- \else
- \hskip#1%
- \fi
- \else
- \hskip#1%
- \fi}
-
-%D The background mechanism is quite demanding in terms or
-%D resources. We used to delay these definitions till runtime
-%D usage, but since today's \TEX's are large, we now do the
-%D work on forehand.
-%D
-%D \starttyping
-%D \setupbackgrounds [settings]
-%D \setupbackgrounds [paper,page,text,..] [settings]
-%D \setupbackgrounds [top,...] [leftedge,...] [settings]
-%D \stoptyping
-%D
-%D \showsetup{setupbackgrounds}
-%D
-%D Because the number of arguments runs from one to three,
-%D we need to check for it.
-
-\def\setupbackgrounds
- {\dotripleempty\dosetupbackgrounds}
-
-\def\dosetupbackgrounds[#1][#2][#3]%
- {\ifthirdargument
- \global\somebackgroundtrue
- \def\docommand##1%
- {\doifinsetelse{##1}{\v!paper,\v!page,\v!leftpage,\v!rightpage}
- {\getparameters[\??ma##1][#3]\checkbackground{##1}}
- {\def\dodocommand####1{\getparameters[\??ma##1####1][#3]\checkbackground{##1####1}}%
- \processcommalist[#2]\dodocommand}}%
- \processcommalist[#1]\docommand
- \else\ifsecondargument
- \global\somebackgroundtrue
- \doifcommonelse{#1}{\v!text,\v!hidden,%
- %\v!linkertekst,\v!rechtertekst,%
- \v!paper,\v!page,\v!leftpage,\v!rightpage}
- {\def\docommand##1{\getparameters[\??ma##1][#2]\checkbackground{##1}}%
- \processcommalist[#1]\docommand}%
- {\setupbackgrounds
- [#1]%
- [\v!leftedge,\v!leftmargin,\v!text,\v!rightmargin,\v!rightedge]%
- [#2]}%
- \else\iffirstargument
- \getparameters[\??ma][#1]%
- \fi\fi\fi
- \doifelsevalue{\??ma\v!page\c!offset}\v!overlay
- {\global\pageoffset\zeropoint}
- {\global\pageoffset\getvalue{\??ma\v!page\c!offset}}%
- \global\pagedepth\getvalue{\??ma\v!page\c!depth}%
- \xdef\pagebackgroundoffset{\the\pageoffset}%
- \xdef\pagebackgrounddepth {\the\pagedepth }%
- \doifelse\@@mastate\v!stop
- {\global\newbackgroundfalse}
- {\global\newbackgroundtrue }}
-
-\let\pagebackgroundoffset\!!zeropoint
-\let\pagebackgrounddepth \!!zeropoint
-
-\appendtoks\global\newbackgroundfalse\to\everyjob
-
-%D Each areas (currently there are $1+3+25+1=30$ of them)
-%D has its own low level framed object associated.
-
-\presetlocalframed [\??ma\v!paper]
-\presetlocalframed [\??ma\v!page]
-\presetlocalframed [\??ma\v!leftpage]
-\presetlocalframed [\??ma\v!rightpage]
-
-\copyparameters
- [\??ma\v!paper\c!frame][\??ma\v!page]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!paper\c!background][\??ma\v!page]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!page\c!frame][\??ma\v!page]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!page\c!background][\??ma\v!page]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!leftpage\c!frame][\??ma\v!leftpage]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!leftpage\c!background][\??ma\v!leftpage]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!rightpage\c!frame][\??ma\v!rightpage]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-\copyparameters
- [\??ma\v!rightpage\c!background][\??ma\v!rightpage]
- [\c!offset,\c!depth,\c!radius,\c!corner,\c!color,\c!screen]
-
-%D We save some keying by defining the areas using
-%D intermediate commands. The inheritance macro makes sure
-%D that copies are efficient.
-
-\def\dodocommand#1#2%
- {\copylocalframed
- [\??ma#1#2][\??ma\v!page]%
- \getparameters
- [\??ma#1#2]
- [\c!background=,\c!frame=,\c!color=,\c!screen=\@@rsscreen,
- \c!bottomframe=,\c!topframe=,\c!leftframe=,\c!rightframe=]%
- \inheritparameter[\??ma][#1#2\c!color][\v!page\c!color]%
- \inheritparameter[\??ma][#1#2\c!screen][\v!page\c!screen]%
- \inheritparameter[\??ma][#1#2\c!framecolor][\v!page\c!framecolor]%
- \inheritparameter[\??ma][#1#2\c!backgroundcolor][\v!page\c!backgroundcolor]%
- \inheritparameter[\??ma][#1#2\c!backgroundscreen][\v!page\c!backgroundscreen]}
-
-%D The stand alone text area inherits from the page too.
-
-\dodocommand\v!text \empty
-%dodocommand\v!linkertekst \empty
-%dodocommand\v!rechtertekst\empty
-\dodocommand\v!hidden \empty
-
-%D We now define all 25 main areas in a row.
-
-\def\docommand#1%
- {\dodocommand#1\v!leftedge
- \dodocommand#1\v!leftmargin
- \dodocommand#1\v!text
- \dodocommand#1\v!rightmargin
- \dodocommand#1\v!rightedge}
-
-\docommand\v!top
-\docommand\v!header
-\docommand\v!text
-\docommand\v!footer
-\docommand\v!bottom
-
-%D We need some cleanup now.
-
-\let\dodocommand\relax \let\docommand\relax
-
-%D We now set up the individual areas to use reasonable
-%D defaults.
-
-\setupbackgrounds
- [\c!state=\c!start]
-
-\setupbackgrounds
- [\v!paper,\v!page,\v!leftpage,\v!rightpage]
- [\c!frame=\v!off,
- \c!radius=.5\bodyfontsize,
- \c!corner=\v!rectangular,
- \c!background=,
- \c!screen=\@@rsscreen,
- \c!color=,
- %\c!frameoffset=\getvalue{\??ma\v!page\c!offset},
- %\c!backgroundoffset=\getvalue{\??ma\v!page\c!offset},
- \c!offset=\!!zeropoint, % later set to \v!overlay, watch out !
- \c!depth=\!!zeropoint]
-
-\def\docommand#1%
- {\inheritparameter[\??ma][#1\c!frameoffset][\v!page\c!offset]%
- \inheritparameter[\??ma][#1\c!backgroundoffset][\v!page\c!offset]}
-
-\docommand\v!paper
-\docommand\v!page
-\docommand\v!leftpage
-\docommand\v!rightpage
-
-%D Again we clean up temporary macros.
-
-\let\docommand\relax
-
-%D The hidden layer can be populated by extending the
-%D following comma separated list. This only happens in core
-%D modules.
-
-% todo page-2 .. page+2 achter pagina -> bleed
-% spread-2 .. spread+2 achter spread -> spread (repeat 2 times)
-
-\def\enablehiddenbackground
- {\global\settrue\hiddenbackgroundenabled
- \global\somebackgroundtrue
- \recalculatebackgrounds}
-
-\def\disablehiddenbackground
- {\global\setfalse\hiddenbackgroundenabled}
-
-\def\hiddenbackground
- {\v!text-2,\v!text-1,\v!foreground,\v!text+1,\v!text+2}
-
-\setupbackgrounds
- [\v!hidden]
- [\c!background=\hiddenbackground]
-
-% The next series is used in local (for instance floating)
-% backgrounds.
-
-\presetlocalframed
- [\??ma\v!local]
-
-\def\localbackground
- {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2}
-
-\defineoverlay[\v!local-2][\positionoverlay{\v!local-2}]
-\defineoverlay[\v!local-1][\positionoverlay{\v!local-1}]
-\defineoverlay[\v!local+1][\positionoverlay{\v!local+1}]
-\defineoverlay[\v!local+2][\positionoverlay{\v!local+2}]
-
-\def\addlocalbackgroundtobox
- {\ifconditional\hiddenbackgroundenabled
- \expandafter\doaddlocalbackground
- \else
- \resetglobal \expandafter\gobbleoneargument
- \fi}
-
-\def\doaddlocalbackground#1%
- {\dodoglobal\setbox#1\hbox
- {\fastlocalframed % \localframed
- [\??ma\v!local]
- [\c!component=local,\c!frame=\v!off,\c!offset=\v!overlay,\c!setups=,%
- \c!location=\v!keep,% when we use \localframed instead of \fastlocalframed
- \c!background=\localbackground]%
- {\registerMPlocaltextarea{\box#1}}}%
- \resetglobal % redundant
- \doglobal\increment\localpositionnumber\relax} % afterwards !
-
-% Test how previous macro behaves with depth:
-%
-% \startcolumnset
-% \input tufte
-% \placefigure{none}{\framed[lines=5]{xxx}}
-% \input tufte
-% \placefigure{none}{\starttabulate\NC test\nc test\NC\NR\stoptabulate}
-% \input tufte
-% \stopcolumnset
-
-%D Because we haven't really set up backgrounds yet, we set
-%D the main efficiency switch to false.
-
-\somebackgroundfalse
-
-\protect \endinput
-
-%D Removed \quote {features}:
-%D
-%D \starttyping
-%D \startinteraction
-%D \doifmarginswapelse
-%D {\copy\leftbackground}
-%D {\copy\rightbackground}%
-%D \stopinteraction
-%D \stoptyping
-%D
-%D \starttyping
-%D \edef\setpagebackgrounddepth%
-%D {\dp#2=\the\dp#2}%
-%D \setbox#2=\vbox\localframed[\??ma#1]{...}
-%D \setpagebackgrounddepth
-%D \stoptyping
diff --git a/tex/context/base/page-flt.tex b/tex/context/base/page-flt.tex
index a0b297981..91cb25e6b 100644
--- a/tex/context/base/page-flt.tex
+++ b/tex/context/base/page-flt.tex
@@ -1,7 +1,7 @@
%D \module
%D [ file=page-flt,
%D version=2000.10.20,
-%D title=\CONTEXT\ OTR Macros,
+%D title=\CONTEXT\ Page Macros,
%D subtitle=Floating Bodies,
%D author=Hans Hagen,
%D date=\currentdate,
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context OTR Macros / Floating Bodies}
+\writestatus{loading}{ConTeXt Page Macros / Floating Bodies}
%D Some of the sidefloat settings should move to page-sid; now it's quite
%D fuzzy the way the variables are set/reset.
@@ -19,169 +19,24 @@
\unprotect
\ifx\addlocalbackgroundtobox\undefined \def\addlocalbackgroundtobox{\resetglobal\gobbleoneargument} \fi
-
-% naar supp-box.tex
-
-\def\voidbox{\box\voidb@x}
-
-\def\spreadhbox#1% rebuilds \hbox{}
- {\bgroup
- \ifhbox#1\relax
- \setbox2\voidbox
- \unhbox#1%
- \doloop
- {\unpenalty\unskip\unpenalty\unskip\unpenalty\unskip
- \setbox0\lastbox
- \ifvoid0
- \exitloop
- \else
- \setbox2\hbox
- {\ifhbox0 \spreadhbox0\else\box0\fi
- \ifvoid2 \else\hss\unhbox2\fi}%
- \fi}%
- \ifvoid2\else\unhbox2\fi
- \else
- \box#1%
- \fi
- \egroup}
\def\placefloats{\doflushfloats} % keep this one
-\startmessages dutch library: floatblocks
- title: plaatsblokken
- 1: -- hernummerd / -- => --
- 2: -- bewaard
- 3: -- verplaatst
- 4: -- geplaatst
- 5: volgorde aangepast
- 6: maximaal -- boven
- 7: maximaal -- onder
- 8: minder dan -- regels
- 9: volgorde verstoord
- 10: -- begrensd
- 11: geen blok opgegeven
- 12: niet gedefinieerd
- 13: er is niets te splitsen
-\stopmessages
-
-\startmessages english library: floatblocks
- title: floatblocks
- 1: -- renumbered / -- => --
- 2: -- saved
- 3: -- moved
- 4: -- placed
- 5: order adapted
- 6: n of top floats limited to --
- 7: n of bottom floats limited to --
- 8: less than -- lines
- 9: order disturbed
- 10: -- limited
- 11: no block given
- 12: undefined
- 13: there is nothing to split
-\stopmessages
-
-\startmessages german library: floatblocks
- title: Gleitobjektbloecke
- 1: -- neu nummeriert / -- => --
- 2: -- gespeichert
- 3: -- verschoben
- 4: -- plaziert
- 5: Reihenfolge angepasst
- 6: Anz. der oberen Gleitobjekte beschraengt auf --
- 7: Anz. der unteren Gleitobjekte beschraengt auf --
- 8: weniger als -- zeilen
- 9: Reigenfolge gestoert
- 10: -- begrenzt
- 11: kein Block gegeben
- 12: undefiniert
- 13: there is nothing to split
-\stopmessages
-
-\startmessages czech library: floatblocks
- title: plovouciobjekty
- 1: -- precislovano / -- => --
- 2: -- ulozeno
- 3: -- presunuto
- 4: -- umisteno
- 5: poradi prizpusobeno
- 6: pocet hornich plovoucich objektu je omezen na --
- 7: pocet spodnich plovoucich objektu je omezen na --
- 8: radku je mene nez --
- 9: poradi naruseno
- 10: -- omezeno
- 11: nedan zadny blok
- 12: nedefinovano
- 13: there is nothing to split
-\stopmessages
-
-\startmessages italian library: floatblocks
- title: oggetti mobili
- 1: -- rinumerato / -- => --
- 2: -- salvato
- 3: -- mosso
- 4: -- sistemato
- 5: ordine aggiustato
- 6: n di top floats limitato a --
- 7: n di bottom floats limitato a --
- 8: meno di -- righe
- 9: ordine disturbato
- 10: -- limitato
- 11: nessun oggetto specificato
- 12: non definito
- 13: there is nothing to split
-\stopmessages
-
-\startmessages norwegian library: floatblocks
- title: flytblokker
- 1: -- renummerert / -- => --
- 2: -- lagret
- 3: -- flyttet
- 4: -- plassert
- 5: rekkefølge tilpasset
- 6: maksimalt -- flytblokker øverst
- 7: maksimalt -- flytblokker nederst
- 8: mindre enn -- linjer
- 9: rekkefølge endret
- 10: -- begrenset
- 11: ingen blokk oppgitt
- 12: udefinert
- 13: there is nothing to split
-\stopmessages
-
-\startmessages romanian library: floatblocks
- title: Blocuri
- 1: -- renumerotat / -- => --
- 2: -- salvat
- 3: -- mutat
- 4: -- plasat
- 5: ordinea adaptata
- 6: nr. cadrelor de sus limitat la --
- 7: nr. blocurilor de jos limitat la --
- 8: mai putin de -- linii
- 9: ordinea deranjata
- 10: -- limitat
- 11: nu este dat nici un bloc
- 12: nedefinit
- 13: there is nothing to split
-\stopmessages
-
-\startmessages french library: floatblocks
- title: blocs de flottants
- 1: -- renuméroté / -- => --
- 2: -- sauvegardé
- 3: -- déplacé
- 4: -- placé
- 5: ordre adapté
- 6: n flottants de haut de page limité à --
- 7: n flottants de bas de page limité à --
- 8: moins de -- lignes
- 9: ordre perturbé
- 10: -- limité
- 11: pas de bloc donné
- 12: indéfini
- 13: there is nothing to split
-\stopmessages
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
\def\floatparameter #1{\csname\??fl\currentfloat#1\endcsname}
\def\floatcaptionparameter#1{\csname\??kj\currentfloat#1\endcsname}
@@ -395,8 +250,6 @@
\hsize\localhsize
\fi}
-\newevery \everyinsidefloat \relax
-
\appendtoks
\everyinsidefloat\emptytoks % in case it's called earlier
\dogetfloatdata
@@ -618,6 +471,7 @@
\c!leftframe=\@@bkleftframe,
\c!rightframe=\@@bkrightframe,
\c!frameoffset=\@@bkframeoffset,
+ \c!framecolor=\@@bkframecolor,
%\c!local=\@@bklocal,
\c!textmethod=\@@bktextmethod,
\c!sidemethod=\@@bksidemethod,
@@ -687,32 +541,6 @@
% \setupfloat[...][leftmargindistance=1cm,default={left,none}]
-% \def\redodefinefloat[#1][#2][#3]% same label/number
-% {\presetlocalframed[\??fl#1]%
-% \copylocalframed[\??fl#1][\??fl#3]%
-% \copyparameters[\??fl#1][\??fl#3]
-% [\c!width,\c!height,%\c!local,
-% \c!maxwidth,\c!maxheight,\c!minwidth,
-% \c!margin,\c!sidespacebefore,\c!sidespaceafter,\c!sidealign,
-% \c!leftmargindistance,\c!rightmargindistance,\c!criterium,
-% \c!leftmargin,\c!rightmargin,\c!innermargin,\c!outermargin,
-% \c!frame,\c!radius,\c!corner,\c!location,\c!background,\c!framecolor,
-% \c!backgroundscreen,\c!backgroundcolor,\c!backgroundoffset,
-% \c!topframe,\c!bottomframe,\c!leftframe,\c!rightframe,
-% \c!frameoffset,\c!pageboundaries,\c!default,
-% \c!textmethod,\c!sidemethod,\c!method]%
-% \copyparameters[\??kj#1][\??kj#3]
-% [\c!location,\c!before,\c!inbetween,\c!after,
-% \c!spacebefore,\c!spaceinbetween,\c!spaceafter,
-% \c!width,\c!headstyle,\c!headcolor,\c!style,\c!color,
-% \c!textstyle,\c!textcolor,\c!minwidth,
-% \c!align,\c!number,\c!way,\c!blockway,\c!setups,
-% \c!leftmargin,\c!rightmargin,\c!innermargin,\c!outermargin,
-% \c!sectionnumber,\c!separator,\c!stopper,\c!suffix,\c!distance,\c!conversion]%
-% \definenumber[#1][#3]%
-% \presetlabeltext[#1=\labeltext{#3}]%
-% \dodefinefloatcommands[#1][#2]}
-
\def\redodefinefloat[#1][#2][#3]% same label/number
{\presetlocalframed[\??fl#1]%
\copylocalframed[\??fl#1][\??fl#3]%
@@ -906,7 +734,7 @@
\fi
\else
\global\savednoffloats\zerocount
- \global\setbox\floatbox\box\voidb@x
+ \global\setbox\floatbox\emptybox
\fi}
\def\uncenteredfloatbox
@@ -2126,257 +1954,8 @@
\fi
\global\insidefloatfalse}
-\newif\ifmargeblokken
-
-\def\dosetupmarginblocks[#1]%
- {\getparameters[\??mb][#1]%
- \doifelse\@@mbstate\v!start
- {\showmessage\m!layouts4\empty
- \margeblokkentrue
- \let\somenextfloat\dosomenextfloat
- \let\startmarginblock\dostartmarginblock
- \let\stopmarginblock\dostopmarginblock}%
- {\showmessage\m!layouts5\empty
- \margeblokkenfalse
- \def\somenextfloat[##1]%
- {\someelsefloat[##1,\v!here]}%
- \let\startmarginblock\dontstartmargeblok
- \let\stopmarginblock\dontstopmargeblok}}
-
-\def\setupmarginblocks
- {\dosingleargument\dosetupmarginblocks}
-
-\newbox\marginbox
-
-\def\dosomenextfloat[#1]%
- {\global\setbox\marginbox\vbox
- {\hsize\@@mbwidth
- \unvcopy\marginbox
- \ifvoid\marginbox\else\expandafter\@@mbinbetween\fi
- \box\floatbox\filbreak}%
- \ifdim\ht\marginbox>\textheight
- \dosavefloatinfo
- \else
- \doinsertfloatinfo
- \fi}
-
-\newbox\preparedmarginbox
-
-\def\reshapemargin
- {\ifdim\ht\preparedmarginbox>\zeropoint
- \beginofshapebox
- \unvbox\preparedmarginbox
- \endofshapebox
- \reshapebox
- {\box\shapebox}%
- \setbox\preparedmarginbox\vbox to \textheight
- {\@@mbtop
- \flushshapebox
- \@@mbbottom}%
- \fi}
-
-\def\plaatsrechtermargeblok
- {\hskip\rightmarginwidth}
-
-\def\plaatslinkermargeblok
- {\hskip\leftmarginwidth}
-
-\def\checkmargeblokken
- {\ifvoid\marginbox\else\docheckmargeblokken\fi}
-
-\def\docheckmargeblokken % erg inefficient
- {\setbox\preparedmarginbox\vbox
- {\forgetall
- \splittopskip\topskip
- \ifvoid\marginbox\else
- \ifdim\ht\marginbox>\textheight
- \vsplit\marginbox to \textheight
- \else
- \unvbox\marginbox
- \fi
- \fi}%
- \reshapemargin
- \setbox\preparedmarginbox\vbox
- {\@@mbbefore\box\preparedmarginbox\@@mbafter}%
- \def\rightmarginbox
- {\def\plaatsrechtermargeblok
- {\setbox\preparedmarginbox\hbox to \rightmarginwidth
- {\@@mbleft\box\preparedmarginbox\@@mbright}%
- \vsmashbox\preparedmarginbox
- \box\preparedmarginbox}}%
- \def\leftmarginbox
- {\def\plaatslinkermargeblok
- {\setbox\preparedmarginbox\hbox to \leftmarginwidth
- {\@@mbright\box\preparedmarginbox\@@mbleft}%
- \vsmashbox\preparedmarginbox
- \box\preparedmarginbox}}%
- \processaction % traag
- [\@@mblocation]
- [ \v!inmargin=>\doifbothsidesoverruled\rightmarginbox\rightmarginbox\leftmarginbox,
- \v!middle=>\doifbothsidesoverruled\rightmarginbox\leftmarginbox\rightmarginbox,
- \v!left=>\leftmarginbox,
- \v!right=>\rightmarginbox,
- \s!unknown=>\setbox\preparedmarginbox\hbox{}]}
-
-\def\dostartmarginblock % 2 maal \vbox ivm \unvbox elders
- {\global\setbox\marginbox\vtop\bgroup\vbox\bgroup
- \hsize\@@mbwidth
- \ifvoid\marginbox\else
- \unvbox\marginbox
- \@@mbinbetween
- \fi
- \setupalign[\@@mbalign]%
- \dostartattributes\??mb\c!style\c!color{}%
- \begstrut\ignorespaces}
-
-\def\dostopmarginblock
- {\unskip\endstrut
- \dostopattributes
- \egroup
- \egroup}
-
-\def\dontstartmargeblok
- {\@@mbbefore
- \bgroup
- \dostartattributes\??mb\c!style\c!color\empty}
-
-\def\dontstopmargeblok
- {\dostopattributes
- \egroup
- \@@mbafter}
-
-\newcounter\nofpostponedblocks
-
-\newif\ifinpostponing
-
-\newevery\everytopofpage\relax
-
-\appendtoks \the\everytopofpage \to\everystarttext
-\appendtoks\global\everytopofpage\emptytoks\to\everystoptext
-
-% \startpostponing [pagenumber] [+pageoffset]
-%
-% \startpostponing[2]
-% PAGE 2 \blank
-% \stoppostponing
-%
-% \startpostponing[+1]
-% PAGE +1 \blank
-% \stoppostponing
-%
-% \startpostponing[+2]
-% PAGE +2 \blank
-% \stoppostponing
-%
-% \starttext \dorecurse{4}{\input tufte \page} \stoptext
-
-\newtoks \postponedpageblocks
-\newcounter\nofpostponedpageblocks
-
-% \ifinpostponing: handhaven, want gebruikt in stijlen ! ! ! ! !
-
-\def\flushpagefloats
- {\doifoddpageelse
- {\ifvoid\collectedleftpagefloats
- \ifvoid\collectedrightpagefloats\else
- \unvbox\collectedrightpagefloats
- \page
- %\the\everytopofpage
- \fi
- \fi}
- {\ifvoid\collectedleftpagefloats\else
- \unvbox\collectedleftpagefloats
- \page
- %\the\everytopofpage
- \fi
- \ifvoid\collectedrightpagefloats\else
- \unvbox\collectedrightpagefloats
- \page
- %\the\everytopofpage
- \fi}%
- \ifvoid\collectedpagefloats\else
- % message
- \unvbox\collectedpagefloats
- \fi}
-
-% \def\flushrestfloats
-% {\doif\@@bkcache\v!no\doflushfloats}
-
-% \let\flushrestfloats\relax
-
-\def\dopostponeblock
- {\bgroup % new may 2004
- \setsystemmode\v!postponing % new may 2004
- \the\everytopofpage
-% \flushrestfloats
- \flushpagefloats
- \donefalse
- \ifinpostponing \else
- \ifcase\nofpostponedblocks \else \donetrue \fi
- \ifcase\nofpostponedpageblocks \else \donetrue \fi
- \fi
- \ifdone
- \bgroup % we need the color/font switch, else problems inside split verbatim
- \setnormalcatcodes % postponing in verbatim
- \pushpostponedpagecolor
- \restoreglobalbodyfont % The \nof-test is
- \global\pagetotal\zeropoint % recently added and
- \global\inpostponingtrue % definitely needed else
- \the\postponedpageblocks % we can loose or disorder
- \dorecurse\nofpostponedblocks % floats; anyhow, this
- {\getbuffer[pbuf-\recurselevel]}% % mechanism is still
- \doflushfloats % new but potential dangerous % suboptimal and needs a
- \doglobal\newcounter\nofpostponedblocks % proper analysis
- \global\inpostponingfalse
- \poppostponedpagecolor
- \egroup
- \fi
- \egroup} % new may 2004
-
-\def\getpostponedblock#1#2%
- {\doif{#1}\realfolio{\getbuffer[rbuf-#2]}} % no \ifnum, avoid \fi
-
-% beware, \dosingleempty conflicts with buffers (feeds back the \par)
-
-\setvalue{\e!start\v!postponing}%
- {\bgroup
- \obeylines
- \doifnextcharelse[%
- {\egroup\nodostartpostponing}{\egroup\dodostartpostponing}}
-
-\def\nodostartpostponing[#1]%
- {\doglobal\increment\nofpostponedpageblocks
- \bgroup % a little bit of misusing grouping
- \doifinstring{+}{#1}\advance \realpageno#1\relax % ugly but efficient
- \doglobal\appendetoks\noexpand\getpostponedblock
- {\realfolio}{\nofpostponedpageblocks}\to\postponedpageblocks
- \egroup
- \showmessage\m!layouts3\nofpostponedpageblocks
- \dostartbuffer[rbuf-\nofpostponedpageblocks]%
- [\e!start\v!postponing][\e!stop\v!postponing]}
-
-\def\dodostartpostponing
- {\doglobal\increment\nofpostponedblocks
- \showmessage\m!layouts3\nofpostponedblocks
- \expanded{\dostartbuffer[pbuf-\nofpostponedblocks][\e!start\v!postponing][\e!stop\v!postponing]}}
-
\def\dooutput{\sidefloatoutput} % redefinition of \dooutput
-\setupmarginblocks
- [\c!state=\v!start,
- \c!location=\v!inmargin,
- \c!width=\rightmarginwidth,
- \c!style=,
- \c!color=,
- \c!align=,
- \c!left=,
- \c!right=,
- \c!top=,
- \c!inbetween=\blank,
- \c!bottom=\vfill,
- \c!before=,
- \c!after=]
-
\definefloat
[\v!figure]
[\v!figures]
@@ -2447,6 +2026,7 @@
\c!bottomframe=,
\c!leftframe=,
\c!rightframe=,
+ \c!framecolor=,
\c!frameoffset=\!!zeropoint,
\c!before=,
\c!after=,
diff --git a/tex/context/base/page-flw.tex b/tex/context/base/page-flw.tex
index 1a8ffd3c4..3eb867a78 100644
--- a/tex/context/base/page-flw.tex
+++ b/tex/context/base/page-flw.tex
@@ -1,7 +1,7 @@
%D \module
%D [ file=page-flw,
%D version=2003.04.19, % from test-002 (1997) profile experiment
-%D title=\CONTEXT\ OTR Macros,
+%D title=\CONTEXT\ Page Macros,
%D subtitle=Text Flows,
%D author=Hans Hagen,
%D date=\currentdate,
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{Context OTR Macros / Text Flows}
+\writestatus{loading}{ConTeXt Page Macros / Text Flows}
%D This is high experimental and especially flushing may change (proper
%D spacing is the driving force here).
diff --git a/tex/context/base/page-imp.tex b/tex/context/base/page-imp.tex
index a16f0031f..e4ece04a6 100644
--- a/tex/context/base/page-imp.tex
+++ b/tex/context/base/page-imp.tex
@@ -1,7 +1,7 @@
%D \module
%D [ file=page-imp, % was: core-pag,
%D version=1998.01.15,
-%D title=\CONTEXT\ Core Macros,
+%D title=\CONTEXT\ Page Macros,
%D subtitle=Pagebody Building (Imposition),
%D author=Hans Hagen,
%D date=\currentdate,
@@ -13,7 +13,7 @@
% much of this can more to run time loading !
-\writestatus{loading}{Context Core Macros / Pagebody Building}
+\writestatus{loading}{ConTeXt Page Macros / Pagebody Building}
\unprotect
@@ -115,13 +115,26 @@
% moved code:
+% \def\myshipout#1%
+% {\beforeshipout % voor de pagebody dus !
+% \dontshowcomposition
+% \ifarrangingpages\@EA\actualarrange\else\@EA\actualshipout\fi
+% {\thisisrealpage\realfolio#1}%
+% \gotonextrealpage
+% \aftershipout}
+
+\def\installpagehandler#1#2% % a handler takes one argument: something to be boxed
+ {\setvalue{\??pp:\c!method:#1}{#2}} % and shipped out (don't depend on the exact package)
+
+\installpagehandler\v!normal
+ {\ifarrangingpages\expandafter\actualarrange\else\expandafter\actualshipout\fi}
+
\def\myshipout#1%
- {\beforeshipout % voor de pagebody dus !
- \dontshowcomposition
- \ifarrangingpages\@EA\actualarrange\else\@EA\actualshipout\fi
- {\thisisrealpage\realfolio#1}%
- \gotonextrealpage
- \aftershipout}
+ {\beforeshipout % voor de pagebody dus !
+ \dontshowcomposition
+ \executeifdefined{\??pp:\c!method:\@@ppmethod}\gobbleoneargument{\thisisrealpage\realfolio#1}%
+ \gotonextrealpage
+ \aftershipout}
\newbox\postponedcontent
diff --git a/tex/context/base/page-ini.mkii b/tex/context/base/page-ini.mkii
new file mode 100644
index 000000000..e5c3aa41a
--- /dev/null
+++ b/tex/context/base/page-ini.mkii
@@ -0,0 +1,1555 @@
+%D \module
+%D [ file=page-ini,
+%D version=2000.10.20,
+%D title=\CONTEXT\ Page Macros,
+%D subtitle=Initializations,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Page Macros / Initializations}
+
+% still a dutch/english mess
+
+%D This class of modules implements the output routines and
+%D floating body support. Although the modules are relatively
+%D new, the code herein is rather old. This reordering was
+%D needed when column sets were implemented and sharing code
+%D started to make sense.
+
+%D The history shows from the code, since both column
+%D mechanism use a different way of looping over columns.
+
+\unprotect
+
+\def\m!otr{otr}
+
+\chardef\normalpagebox=255
+
+\newbox\pagebox
+
+\ifx\recalculatelayout\undefined
+
+ \let \recalculatelayout \relax
+
+\fi
+
+\ifx\recalculatelogos\undefined
+
+ \let \recalculatelogos \relax
+ \let \addlogobackground \gobbleoneargument %
+
+\fi
+
+\ifx\recalculatebackgrounds\undefined
+
+ \let \recalculatebackgrounds \relax
+ \let \addmainbackground \gobbleoneargument %
+ \let \addtextbackground \gobbleoneargument %
+ \let \addpagebackground \gobbleoneargument %
+ \let \addprintbackground \gobbleoneargument %
+ \let \addstatusinfo \gobbleoneargument %
+
+\fi
+
+\ifx\realpageno\undefined
+
+ \countdef\realpageno = 0 \realpageno = 1
+ \countdef\userpageno = 1 \userpageno = 1
+ \countdef\subpageno = 2 \subpageno = 0 % !!
+ \countdef\arrangeno = 3 \arrangeno = 0 % !!
+
+ \let\pageno\userpageno
+
+\fi
+
+\ifx\realfolio\undefined
+
+ \def\realfolio{\the\realpageno}
+
+\fi
+
+\newcount\nofshipouts
+
+\appendtoks
+ \global\advance\nofshipouts\plusone
+\to \everyaftershipout
+
+% principle:
+%
+% multiple otr's
+%
+% (1) single column, simple routine (old one)
+% (2) multi column, collect and split routine (old one)
+% (3) multi column, page by page (new one, needed for taco)
+% (4) single column, spread handling (for fun)
+% (5) multi column, page by page, spread handling (as challenge)
+%
+% common components
+%
+% (1) float placement
+% (2) float flushing
+% (3) page body building
+% (4) ...
+%
+% ort
+%
+% + balancing
+% - mixed / one / multi / balancetofit
+% + backgrounds
+% + pre / post
+% + distances / heights
+% + ragged / baseline / normal
+% - pos sync
+% - last page
+%
+% - itemize / subtexts -> old mechanism
+%
+% floats
+%
+% - top / bottom / side / page / column / spead
+% - flush / packed flush / current page / next page / area
+%
+% footnotes
+%
+% + carry over pre column / local to column
+% + last column / pre last column / each column
+% - multiple classes
+% - area / page / end
+%
+% areas
+%
+% - top / bottom / mid in spread
+%
+% IMPORTANT
+%
+% switchtobodyfont in between ivm top
+
+% floats:
+%
+% tricky in balancing mode, a la huidige multi columns
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+\ifx\dosetuplayout\undefined % overloaded in page-lay !
+
+ \def\setuplayout{\dodoubleempty\getparameters[\??ly]}
+
+\fi
+
+\ifx\mkprocesscolumncontents\undefined\let\mkprocesscolumncontents\gobbleoneargument\fi
+\ifx\mkprocesspagecontents \undefined\let\mkprocesspagecontents \gobbleoneargument\fi
+\ifx\mkprocessboxcontents \undefined\let\mkprocessboxcontents \gobbleoneargument\fi
+
+\def\normalejectpenalty{-\plustenthousand } \let\ejectpenalty\normalejectpenalty
+\def\normalsuperpenalty{-\plustwentythousand} \let\superpenalty\normalsuperpenalty
+
+%D In case we're not running \ETEX, we need to bypass a
+%D couple of primitives.
+
+% ONE = single column
+% MUL = multi column
+% SET = columns sets
+
+\def\@@OTR{OTR}
+
+\let\OTRdefault\empty
+
+\def\OTRcommand#1%
+ {\csname\@@OTR
+ \ifcsname\@@OTR\OTRidentifier\strippedcsname#1\endcsname
+ \OTRidentifier
+ \else\ifcsname\@@OTR\OTRdefault\strippedcsname#1\endcsname % fallback
+ \OTRdefault
+ \fi\fi
+ \strippedcsname#1\endcsname}
+
+% obsolete
+
+\def\installotr#1% andere naam, beter \connectotr of zo
+ {\def\OTRidentifier{#1}}
+
+\def\activateotr#1#2%
+ {\def\OTRidentifier{#1}%
+ \def\OTRdefault {#2}}
+
+%D The initialization of the \type {\hsize} and \type {\vsize}
+%D depends on the OTR used.
+
+\def\setvsize {\OTRcommand\setvsize}
+\def\sethsize {\OTRcommand\sethsize}
+\def\finalsidefloatoutput {\OTRcommand\finalsidefloatoutput}
+\def\dopagecontents {\OTRcommand\dopagecontents}
+
+\def\dosettopinserts {\OTRcommand\dosettopinserts}
+\def\dosetbotinserts {\OTRcommand\dosetbotinserts}
+\def\dotopinsertions {\OTRcommand\dotopinsertions}
+\def\dobotinsertions {\OTRcommand\dobotinsertions}
+\def\dosetbothinserts {\OTRcommand\dosetbothinserts}
+
+\def\doflushfloats {\OTRcommand\doflushfloats}
+\def\flushfloatbox {\OTRcommand\flushfloatbox}
+\def\docheckiffloatfits {\OTRcommand\docheckiffloatfits}
+
+\def\someherefloat {\OTRcommand\someherefloat}
+\def\somefixdfloat {\OTRcommand\somefixdfloat}
+\def\somepagefloat {\OTRcommand\somepagefloat}
+\def\sometopsfloat {\OTRcommand\sometopsfloat}
+\def\somebotsfloat {\OTRcommand\somebotsfloat}
+\def\somesidefloat {\OTRcommand\somesidefloat}
+
+\def\flushsavedfloats {\OTRcommand\flushsavedfloats}
+
+\def\synchronizehsize {\OTRcommand\synchronizehsize}
+
+\def\gotonextpage {\OTRcommand\gotonextpage }
+\def\gotonextpageX{\OTRcommand\gotonextpageX} % will become obsolete
+
+% beter een \installotr#1 met #1 = macro en auto test
+
+\newif \iftraceotr
+\newif \ifinotr
+\newtoks \mainoutput
+\newcount\otrlevel
+
+% When issuing two \par\penalty-\plustenthousand's, only the first
+% triggers the otr; obscure feature or optimization?
+
+\def\outputcounter{-100010} % -10010
+
+\def\doinvokeoutput
+ {\iftraceotr
+ \expandafter\dodotracedoutput
+ \else
+ \expandafter\dodoinvokeoutput
+ \fi}
+
+\def\outputmessage#1#2#3%
+ {\iftraceotr\writestatus\m!otr{#1 #2 \number#3}\fi}
+
+\def\dodoinvokeoutput#1%
+ {\outputmessage+{special}{#1}%
+ \bgroup\par\penalty#1\relax\egroup
+ \outputmessage-{special}{#1}}
+
+\def\dodotracedoutput#1%
+ {\outputmessage+{traced}{#1/\the\outputpenalty}%
+ \writestatus\m!otr{c:\number\mofcolumns,v:\the\vsize,g:\the\pagegoal,t:\the\pagetotal}%
+ \dodoinvokeoutput{#1}%
+ \writestatus\m!otr{c:\number\mofcolumns,v:\the\vsize,g:\the\pagegoal,t:\the\pagetotal}%
+ \outputmessage-{traced}{#1/\the\outputpenalty}}
+
+\def\installoutput#1#2% \invoke \action
+ {\decrement\outputcounter
+ \edef#1{\noexpand\doinvokeoutput{\outputcounter}}%
+ \setvalue{\@@OTR\outputcounter}{#2}}
+
+\def\invokeoutputroutine
+ {\outputmessage+{trying}\outputpenalty
+ \executeifdefined{\@@OTR\the\outputpenalty}\dodonormaloutput
+ \outputmessage-{trying}\outputpenalty}
+
+\def\dodonormaloutput
+ {\outputmessage+{normal}\outputpenalty
+ \the\OTRcommand\output
+ \outputmessage-{normal}\outputpenalty}
+
+\mainoutput{\invokeoutputroutine} \output{\inotrtrue\the\mainoutput}
+
+%D Some hooks:
+
+\output{\inotrtrue\the\everybeforeoutput\the\mainoutput\the\everyafteroutput}
+
+\ifx\pagediscards\undefined \let\pagediscards\relax \fi
+
+\installoutput\synchronizeoutput % maybe add pagediscards
+ {\ifvoid\normalpagebox\else
+ \unvbox\normalpagebox
+ \pagediscards % maybe not needed ?
+ \fi}
+
+\installoutput\discardpage
+ {\setbox\scratchbox\box\normalpagebox}
+
+%D In order to force consistent use of variables, we
+%D predefine a lot of them here.
+
+%D The next two registers can be used to store pre column
+%D material as well as footnotes or so.
+
+\newbox\precolumnbox \newdimen\precolumnboxheight
+\newbox\postcolumnbox \newdimen\postcolumnboxheight
+
+%D We reserve a counter for the number of columns as well as
+%D the current column. Both are not to be changed by users!
+
+\newcount\nofcolumns \nofcolumns = 1
+\newcount\mofcolumns \mofcolumns = 1
+
+\chardef\maxnofcolumns = 50
+\chardef\allocatednofcolumns = 0
+
+%D The next dimensions reports the final column height
+
+\newdimen\finalcolumnheights
+\newcount\finalcolumnlines
+
+%D During initialization the temporary boxes are allocated.
+%D This enables us to use as much columns as we want, without
+%D exhausting the pool of boxes too fast. We could have packed
+%D them in one box, but we've got enough boxes.
+%D
+%D Two sets of boxes are declared, the txtboxes are used for
+%D the text, the topboxes are for moved column floats.
+
+\def\@col@{@col@}
+
+\def\initializecolumns#1%
+ {\ifnum#1>\maxnofcolumns
+ \showmessage\m!columns1\maxnofcolumns
+ \nofcolumns\maxnofcolumns
+ \else
+ \nofcolumns#1\relax
+ \fi
+ \ifnum\nofcolumns>\allocatednofcolumns
+ \dorecurse\nofcolumns
+ {\ifnum\recurselevel>\allocatednofcolumns\relax
+ % \newbox\next \letgvalue{\@col@-\recurselevel-t}=\next
+ \@EA\newbox\csname\@col@-\recurselevel-t\endcsname % text
+ \@EA\newbox\csname\@col@-\recurselevel-f\endcsname % foot
+ \@EA\newbox\csname\@col@-\recurselevel-h\endcsname % top insert
+ \@EA\newbox\csname\@col@-\recurselevel-l\endcsname % top insert
+ \fi}%
+ \global\chardef\allocatednofcolumns=\nofcolumns
+ \fi}
+
+\def\firstcolumnbox {\columntextbox\plusone}
+\def\currentcolumnbox {\columntextbox\mofcolumns}
+\def\lastcolumnbox {\columntextbox\nofcolumns}
+
+\def\firsttopcolumnbox {\columntopbox \plusone}
+\def\currenttopcolumnbox{\columntopbox \mofcolumns}
+\def\lasttopcolumnbox {\columntopbox \nofcolumns}
+
+\def\columntextbox#1{\csname\@col@-\number#1-t\endcsname}
+\def\columnfootbox#1{\csname\@col@-\number#1-f\endcsname}
+\def\columntopbox #1{\csname\@col@-\number#1-h\endcsname}
+\def\columnbotbox #1{\csname\@col@-\number#1-l\endcsname}
+
+\def\columnsettextbox{\global\setbox\columntextbox}
+\def\columnsetfootbox{\global\setbox\columnfootbox}
+\def\columnsettopbox {\global\setbox\columntopbox}
+\def\columnsetbotbox {\global\setbox\columnbotbox}
+
+\def\columngettextbox{\copy\columntextbox}
+\def\columngetfootbox{\copy\columnfootbox}
+\def\columngettopbox {\copy\columntopbox}
+\def\columngetbotbox {\copy\columnbotbox}
+
+\def\columnerasetextboxes{\dorecurse\allocatednofcolumns{\columnsettextbox\recurselevel\emptybox}}
+\def\columnerasefootboxes{\dorecurse\allocatednofcolumns{\columnsetfootbox\recurselevel\emptybox}}
+\def\columnerasetopboxes {\dorecurse\allocatednofcolumns{\columnsettopbox \recurselevel\emptybox}}
+\def\columnerasebotboxes {\dorecurse\allocatednofcolumns{\columnsetbotbox \recurselevel\emptybox}}
+
+%D Without going in details we present two macro's which handle
+%D the columns. The action which is transfered by the the first
+%D and only parameter can do something with \type
+%D {\currentcolumnbox}. In case of the mid columns, \type
+%D {\firstcolumnbox} and \type {\lastcolumnbox} are handled
+%D outside these macro's.
+
+\def\dohandlecolumn#1%
+ {\mofcolumns\recurselevel
+ \let\currentcolumn\recurselevel
+ #1\relax}
+
+\def\dohandleallcolumns#1%
+ {\dorecurse\nofcolumns{\dohandlecolumn{#1}}}
+
+\def\dohandlerevcolumns#1%
+ {\dostepwiserecurse\nofcolumns\plusone\minusone{\dohandlecolumn{#1}}}
+
+\def\dohandlemidcolumns#1%
+ {\dohandleallcolumns
+ {\ifnum\recurselevel>\plusone
+ \ifnum\recurselevel<\nofcolumns
+ \dohandlecolumn{#1}%
+ \fi
+ \fi}}
+
+%D This register can be used as a temporary storage for page
+%D content.
+
+\newbox\restofpage
+
+%D Features.
+
+\newif\ifintermediatefootnotes
+\newif\ifcarryoverfootnotes %\carryoverfootnotestrue
+\newif\iflastcolumnfootnotes %\lastcolumnfootnotestrue
+\newif\ifbalancecolumns %\balancecolumnstrue
+\newif\ifbalancetoheight %\balancetoheighttrue
+\newif\ifforcecolumngrid \forcecolumngridtrue
+\newif\ifstretchcolumns \stretchcolumnsfalse
+\newif\ifinheritcolumns \inheritcolumnsfalse
+\newif\ifheightencolumns \heightencolumnsfalse
+
+\newif\ifbalancingcolumns
+\newif\ifcollectingcontent
+\newif\ifcolumnoverflow
+\newif\iffinalflushingfloats
+\newif\ifpackflushedfloats \packflushedfloatstrue % for the moment
+
+\newdimen\intercolumnwidth
+\newdimen\localcolumnwidth
+\newdimen\savedpagetotal
+
+\chardef\columndirection=0 % 0:lr 1:rl
+
+\def\minbalancetoplines {1}
+\def\minfreecolumnlines {2}
+
+\newif\ifrecentercolumnbox \recentercolumnboxtrue
+\newif\ifrerecentercolumnbox \rerecentercolumnboxtrue
+\newif\ifpackcolumnfloats \packcolumnfloatstrue
+
+\newbox\collectedpagefloats
+\newbox\collectedleftpagefloats
+\newbox\collectedrightpagefloats
+
+%D The \type {\ifdim} test is needed, because otherwise the
+%D last line of a text end up on top of the baseline instead of
+%D on the baseline, as is the case with preceding pages.
+%D Also, a \type {\vfil} better than a \type {\vfill}.
+
+% to be replaced by \page[now] \page[final] / merged
+
+% \def\eject {\par\penalty-\plustenthousand } % == {\par\break} % plain
+% \def\supereject {\par\penalty-\plustwentythousand} % also plain
+
+\def\eject {\par\ifvmode\penalty\ejectpenalty\fi\resetpagebreak} % == {\par\break} % plain
+\def\supereject {\par\ifvmode\penalty\superpenalty\fi\resetpagebreak} % also plain
+
+\def\doejectpage {\par\ifvmode\ifdim\pagetotal>\pagegoal\else\normalvfil\fi\fi} % pg set to \textheight
+\def\ejectpage {\doejectpage\eject}
+\def\superejectpage{\doejectpage\supereject}
+
+\ifx\bye\undefined \def\bye{\par\vfill\supereject\end} \fi % plain tex command
+
+% floats
+%
+% \def\ejectinsert
+% {\flushnotes
+% \bgroup
+% \noftopfloats\plusthousand
+% \nofbotfloats\zerocount
+% \doflushfloats
+% \egroup}
+
+\def\ejectinsert
+ {\flushnotes
+ \bgroup
+ \noftopfloats\plusthousand
+ \nofbotfloats\zerocount
+ % this is needed in case a float that has been stored
+ % ends up at the current page; this border case occurs when
+ % the calculated room is 'eps' smaller that the room available
+ % when just flushing; so now we have (maybe optional):
+ \pagebaselinecorrection
+ % alas, this is tricky but needed (first surfaced in prikkels)
+ \doflushfloats
+ \egroup}
+
+\def\ejectdummypage
+ {\endgraf \ifvmode
+ \ejectinsert
+ \hardespatie % will be different
+ \vfill
+ \gotonextpage
+ \fi}
+
+\def\beforefinaloutput
+ {}
+
+\def\afterfinaloutput
+ {\forgetall
+ \vskip\zeropoint\relax
+ \ifvoid\normalpagebox \else
+ \unvbox\normalpagebox
+ \penalty\outputpenalty
+ \fi
+ % not really needed, replaced by \flushsavedfloats
+ \ifnum\outputpenalty>\superpenalty \else % better use a proper otr signal
+ \dosupereject
+ \fi
+ % but does not hurt either (we're still in the otr!)
+ \inpagebodytrue % needed for enabling \blank !
+ \flushsavedfloats % was \dosetbothinserts; only otr one !
+ \setvsize % this is needed for interacting components, like floats and multicolumns
+ \adaptfuzzypagegoal} % watch this hack!
+
+\def\dofinaloutput#1#2% \vbox: prevents spurious spaces in every..pagebody
+ {\beforefinaloutput
+ \the\everybeforeshipout % brrr not in shipout
+ \ifspecialbasedsettings
+ \myshipout{\hbox{\hbox to \zeropoint{\the\pageboundsettings}%
+ \hbox{\vbox{\dopagebody#1#2\setpagecounters}}}}%
+ \else
+ \the\pageboundsettings
+ \myshipout{\hbox{\vbox{\dopagebody#1#2\setpagecounters}}}%
+ \fi
+ \the\everyaftershipout
+ \afterfinaloutput
+ \popproperties} % ... and here ...
+
+\def\donofinaloutput#1#2%
+ {\beforefinaloutput
+ \the\everybeforeshipout
+ \setpagecounters
+ \message{[-\the\realpageno]}%
+ \setbox\scratchbox\hbox
+ {%\the\everyshipout % still needed here ?
+ \dopagebody#1#2}%
+ \deadcycles\zerocount
+ \gotonextrealpage
+ \the\everyaftershipout
+ \afterfinaloutput
+ \popproperties} % ... and here
+
+% beware: \ifprocessingpages is in use
+
+\ifx\checkpageversion\undefined \let\checkpageversion\relax \fi % todo: hook into \everybeforeshipout
+\ifx\doflushspread \undefined \let\doflushspread \relax \fi % todo
+
+\def\finaloutput#1#2%
+ {\checkpageversion
+ \ifprocessingpages
+ \ifpageselected
+ \@EAEAEA\dofinaloutput
+ \else
+ \@EAEAEA\donofinaloutput
+ \fi
+ \else
+ \ifpageselected
+ \@EAEAEA\donofinaloutput
+ \else
+ \@EAEAEA\dofinaloutput
+ \fi
+ \fi#1#2%
+ \resetselectiepagina
+ \incrementpagenumber
+ \checkpagedimensions
+ \ifnum\outputpenalty>\superpenalty \else
+ \dosupereject
+ \fi
+ \doflushspread
+ \dopostponeblock}
+
+\def\dooutput
+ {\finaloutput\unvbox\normalpagebox}
+
+\maxdeadcycles=1000
+
+% will be installable tracer; better use chardef
+
+% this needs a real cleanup
+
+\def\doplaceversiontext#1#2%
+ {\doifsomething{#2}
+ {\defconvertedcommand\ascii{#2}%
+ \space#1:\space\ascii\space
+ \!!doneatrue}}
+
+\def\placeversioninfo % nog engels maken
+ {\ifcase\conceptmode
+ % 0 : nothing
+ \or
+ % 1 : simple
+ \vskip\!!sixpoint
+ \hbox to \makeupwidth
+ {\infofont
+ \v!concept:\space\currentdate
+ \hss\reportpagedimensions}%
+ \else
+ % 2/3 : extensive
+ \vskip\!!sixpoint
+ \hbox to \makeupwidth
+ {\infofont
+ \getmessage\m!systems{27}:\space\currentdate\space
+ \doplaceversiontext\v!project \currentproject
+ \doplaceversiontext\v!product \currentproduct
+ \doplaceversiontext\v!component\currentcomponent
+ \if!!donea\else\space\v!file:\space\jobname\fi
+ \hss\reportpagedimensions}%
+ \fi}
+
+% tot hier
+
+\def\doversion[#1]%
+ {\chardef\conceptmode\zerocount
+ \overfullrule\zeropoint
+ \processaction % \v!final=>
+ [#1]
+ [ \v!concept=>\chardef\conceptmode\plusone, % simple banner
+ \v!file=>\chardef\conceptmode\plustwo, % full banner
+ \v!temporary=>\chardef\conceptmode\plusthree % full banner plus
+ \overfullrule5\points]} % info in the margin
+
+\def\version
+ {\dosingleargument\doversion}
+
+\def\addstatusinfo
+ {\ifcase\conceptmode
+ \@EA\gobbleoneargument
+ \else
+ \@EA\doaddstatusinfo
+ \fi}
+
+\def\doaddstatusinfo#1%
+ {\setbox#1\vbox to \paperheight
+ {\vsmashbox#1\box#1%
+ \offinterlineskip
+ \vskip\topspace
+ \hsize\paperwidth
+ \hfill\hbox{\placetestinfo\hskip.5cm}\vss
+ \settexthoffset\hskip\texthoffset % brrrr
+ %\tlap{\placeversioninfo}\vskip.5cm
+ \vbox to 1cm{\vss\placeversioninfo\vss}}}
+
+\def\dotestinfo#1#2#3%
+ {\ifinpagebody\else\ifnum\conceptmode=\plusthree
+ \begingroup
+ \defconvertedcommand\ascii{#3}%
+ \xdef\extratestinfo
+ {#2\space\ascii}%
+ \gdef\totaltestinfo
+ {\global\setbox#1\vbox
+ {\unvbox#1\relax
+ \infofont \setupinterlinespace
+ \hbox
+ {\strut
+ \expanded{\doboundtext{\extratestinfo}{12em}{..}}%
+ \quad}}}%
+ \endgroup
+ \ifinner
+ \aftergroup\totaltestinfo
+ \else
+ \totaltestinfo
+ \fi
+ \fi\fi}
+
+% this will be inserts some day
+
+% \installinsertion\referenceinfobox
+% \installinsertion\registerinfobox
+% \installinsertion\floatinfobox
+
+\newbox\referenceinfobox
+\newbox\registerinfobox
+\newbox\floatinfobox
+
+\def\referenceinfo{\dotestinfo\referenceinfobox}
+\def\registerinfo {\dotestinfo\registerinfobox}
+\def\floatinfo {\dotestinfo\floatinfobox}
+
+\def\placetestinfo
+ {\vbox to \makeupheight
+ {\forgetall
+ \infofont
+ \hsize10em
+ \ifvoid\floatinfobox\else
+ \strut \getmessage\m!systems{24}%
+ \vskip\!!sixpoint
+ \unvbox\floatinfobox
+ \vskip\!!twelvepoint
+ \fi
+ \ifvoid\referenceinfobox\else
+ \strut \getmessage\m!systems{25}%
+ \vskip\!!sixpoint
+ \unvbox\referenceinfobox
+ \vskip\!!twelvepoint
+ \fi
+ \ifvoid\registerinfobox\else
+ \strut \getmessage\m!systems{26}%
+ \vskip\!!sixpoint
+ \unvbox\registerinfobox
+ \fi
+ \vss}}
+
+\version[\v!final]
+
+% bewaren tvb documentatie
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.2\hsize
+% \vsize=2\hsize
+% \ruledvbox to \vsize{\input tufte \par}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern0pt}\hss
+% \ruledvbox to \vsize{\input tufte \par\vfill}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth\vfill}}
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.18\hsize
+% \vsize=2.5\hsize
+% \setbox0=\vbox{\input tufte\relax}%
+% \ruledvbox to \vsize{\unvcopy0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern0pt}\hss
+% \ruledvbox to \vsize{\unvcopy0\vfill}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0\vfill}}
+
+\newtoks\afterpage \newtoks\aftereverypage
+\newtoks\beforepage \newtoks\beforeeverypage
+
+\chardef\showgridstate=0
+
+\def\showgrid
+ {\dosingleempty\doshowgrid}
+
+\def\doshowgrid[#1]%
+ {\chardef\showgridstate \plusone % downward compatible default
+ \chardef\gridboxlinemode \plusone
+ \chardef\gridboxlinenomode\plusone
+ \processallactionsinset
+ [#1]%
+ [ \v!reset=>\chardef\showgridstate \zerocount,
+ \v!bottom=>\chardef\showgridstate \plusone,
+ \v!top=>\chardef\showgridstate \plustwo,
+ \v!none=>\chardef\gridboxlinemode \zerocount,
+ \v!all=>\chardef\gridboxlinemode \plusone,
+ \v!lines=>\chardef\gridboxlinemode \plustwo,
+ \v!frame=>\chardef\gridboxlinemode \plusthree,
+ \v!nonumber=>\chardef\gridboxlinenomode\zerocount,
+ \v!right=>\chardef\gridboxlinenomode\plusone,
+ \v!left=>\chardef\gridboxlinenomode\plustwo]}
+
+\def\buildpagebox#1%
+ {\setbox#1\vbox to \paperheight
+ {\hsize\paperwidth
+ \vskip\topspace
+ \doifbothsides
+ {\hskip\backspace}
+ {\hskip\backspace}
+ {\hskip\paperwidth \hskip-\backspace \hskip-\makeupwidth}%
+ \box#1}%
+ \dp#1\zeropoint}
+
+% \newif\ifpagebodyornaments \pagebodyornamentstrue
+%
+% \appendtoks
+% \global\pagebodyornamentstrue
+% \to \everyaftershipout
+
+\newif\ifarrangingpages \arrangingpagesfalse
+
+\chardef\pageornamentstate\zerocount % 0=on 1=one-off 2=always-off
+
+\def\pagebodyornamentstrue {\chardef\pageornamentstate\zerocount} % for a while
+\def\pagebodyornamentsfalse{\chardef\pageornamentstate\plusone} % for a while
+
+\appendtoks
+ \ifcase\pageornamentstate\or
+ \chardef\pageornamentstate\zerocount
+ \fi
+\to \everyaftershipout
+
+\let\poparrangedpages\relax
+\let\pusharrangedpage\relax
+
+\ifx\shiftprintpagebox\undefined
+ \let\shiftprintpagebox\gobbleoneargument
+ \let\shiftpaperpagebox\gobbleoneargument
+\fi
+
+\ifx\registerpageposition\undefined
+ \let\registerpageposition\gobbleoneargument
+\fi
+
+\def\reportarrangedpage#1%
+ {\showmessage\m!systems
+ {23}{\the\realpageno.\the\pageno\ifnum\subpageno>0 .\the\subpageno\fi,#1}}
+
+\newif\ifsavepagebody \newbox\savedpagebody
+
+% beware, \??ly is used before defined, i.e. bad module design
+
+\setuplayout[\c!method=\v!normal]
+
+\def\buildpagebody#1#2%
+ {\ifsavepagebody\global\setbox\savedpagebody\fi
+ \vbox
+ {\beginrestorecatcodes
+ \forgetall % igv problemen, check: \boxmaxdepth\maxdimen
+ \boxmaxdepth\maxdimen % new
+ \dontcomplain
+ % the following plugin uses and sets pagebox; beware: this
+ % will change and is for my (hh) personal experiments
+ \executeifdefined{\??ly\c!method\@@lymethod}%
+ {\getvalue{\??ly\c!method\v!normal}}#1#2%
+ % the finishing touch
+ \ifcase\pageornamentstate
+ \addpagebackground \pagebox
+ \fi
+ \registerpageposition\pagebox
+ \ifarrangingpages
+ \shiftpaperpagebox \pagebox % \v!paper
+ \else
+ \clippagebox \pagebox
+ \addpagecutmarks \pagebox
+ \replicatepagebox \pagebox
+ \scalepagebox \pagebox
+ \mirrorpaperbox \pagebox
+ \orientpaperbox \pagebox
+ \addpagecolormarks \pagebox
+ \centerpagebox \pagebox
+ \addprintbackground\pagebox
+ \mirrorprintbox \pagebox
+ \orientprintbox \pagebox
+ \shiftprintpagebox \pagebox % \v!page
+ \offsetprintbox \pagebox
+ \negateprintbox \pagebox
+ \fi
+ \box\pagebox
+ \endrestorecatcodes}%
+ \ifsavepagebody\copy\savedpagebody\fi}
+
+\setvalue{\??ly\c!method\v!normal}#1#2%
+ {\setbox\pagebox\vbox
+ {\offinterlineskip
+ \ifcase\pageornamentstate
+ \bgroup % else footnotes get inconsistent font/baseline
+ \dostartattributes\??ly\c!style\c!color\empty
+ \offinterlineskip
+ \gettextboxes
+ \dostopattributes
+ \egroup
+ \fi
+ \getmainbox#1#2}% including footnotes
+ \ifcase\pageornamentstate
+ \addmainbackground \pagebox
+ \addlogobackground \pagebox
+ \fi
+ \buildpagebox \pagebox
+ \addstatusinfo \pagebox}
+
+\def\finishpagebox#1%
+ {\ifarrangingpages
+ \addpagecutmarks #1%
+ \addpagecolormarks#1%
+ \centerpagebox #1%
+ \mirrorprintbox #1%
+ \orientprintbox #1%
+ \offsetprintbox #1%
+ \negateprintbox #1%
+ \fi}
+
+\appendtoks \restoreglobalbodyfont \to \everybeforepagebody
+\appendtoks \restorecolumnsettings \to \everybeforepagebody
+
+\ifx\nestednewbox\undefined \newbox\nestednextbox \fi
+
+\prependtoks \let\nextbox\nestednextbox \to \everybeforepagebody
+
+\def\dopagebody#1#2%
+ {%\getallmarks % now in following token register
+ \the\everybeforepagebody
+ \starttextproperties
+ \gotonextsubpage % nog eens: als in pagina (tbv standaard opmaak)
+ \dontshowboxes % dan hier blokkeren en verderop resetten
+% \shipoutfacingpage
+ \checkreferences
+ \checkmargeblokken
+ \the\beforeeverypage
+ \flushtoks\beforepage
+ \inpagebodytrue\buildpagebody#1#2%
+ \flushtoks\afterpage
+ \the\aftereverypage
+ \resetpagebreak
+ %updatelistreferences % now in aftereverypage
+ \resetlayouttextlines % will go to \aftereverypage
+ \stoptextproperties
+ \the\everyafterpagebody}
+
+\newtoks\pageboundsettings
+
+\prependtoks \initializepaper \to \pageboundsettings
+
+% not here
+
+\newif\ifpagebreakdisabled \pagebreakdisabledfalse
+
+% \chardef\testpagemethod=0 % todo: \testnewpage[method=,lines=,voffset=]
+%
+% \def\testpage {\dotripleempty\dotestpage[\plusone]}
+% \def\testpageonly{\dotripleempty\dotestpage[\plustwo]}
+%
+% \def\dotestpage[#1][#2][#3]%
+% {%\relax % needed before \if
+% \endgraf
+% \ifpagebreakdisabled
+% % do nothing
+% \else
+% %ifnum#1=\plusone\synchronizeoutput\fi
+% \ifdim\pagegoal<\maxdimen \relax
+% \ifdim\pagetotal<\pagegoal \relax
+% \scratchdimen\lineheight
+% \multiply\scratchdimen#2\relax
+% \advance\scratchdimen \pagetotal
+% \ifdim\lastskip<\parskip
+% \advance\scratchdimen \parskip
+% \fi
+% \ifthirdargument
+% \advance\scratchdimen#3\relax
+% \fi
+% \ifcase\testpagemethod
+% \ifdim\scratchdimen>.99\pagegoal
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or
+% \advance\scratchdimen-\pagegoal
+% \ifdim\scratchdimen>-\lineheight
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or
+% \getnoflines\pagegoal
+% \advance\scratchdimen-\noflines\lineheight \relax
+% \ifdim\scratchdimen>-\lineheight
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or % same as 0 but more accurate
+% \advance\scratchdimen-10\s!sp\relax
+% \ifdim\scratchdimen>\pagegoal
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \fi
+% \else
+% % force page break / new
+% % \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \else
+% \ifnum#1=\plusone\goodbreak\fi
+% \fi
+% \fi}
+
+\chardef\testpagemethod \zerocount % todo: \testnewpage[method=,lines=,voffset=]
+\chardef\testpagetrigger\zerocount
+
+\def\testpage {\dotripleempty\dotestpage[\plusone ]} %
+\def\testpageonly{\dotripleempty\dotestpage[\plustwo ]} % no penalties added to the mvl
+\def\testpagesync{\dotripleempty\dotestpage[\plusthree]} % force sync
+
+\def\dotestpage[#1][#2][#3]% don't change, only add more methods
+ {\relax % needed before \if
+ \ifpagebreakdisabled
+ \endgraf
+ \else
+ % new from here
+ \ifcase\testpagetrigger
+ \endgraf
+ \or
+ \ifvmode
+ \dosomebreak\allowbreak
+ \else % indeed?
+ \vadjust{\allowbreak}%
+ \endgraf
+ \fi
+ \fi
+ % till here
+ \ifdim\pagegoal<\maxdimen \relax
+ \ifdim\pagetotal<\pagegoal \relax
+ \scratchdimen\lineheight
+ \multiply\scratchdimen#2\relax
+ \advance\scratchdimen \pagetotal
+ \ifdim\lastskip<\parskip
+ \advance\scratchdimen \parskip
+ \fi
+ \ifthirdargument
+ \advance\scratchdimen#3\relax
+ \fi
+ \ifcase\testpagemethod
+ \ifdim\scratchdimen>.99\pagegoal
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or
+ \advance\scratchdimen-\pagegoal
+ \ifdim\scratchdimen>-\lineheight
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or
+ \getnoflines\pagegoal
+ \advance\scratchdimen-\noflines\lineheight \relax
+ \ifdim\scratchdimen>-\lineheight
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or % same as 0 but more accurate
+ \advance\scratchdimen-10\s!sp\relax
+ \ifdim\scratchdimen>\pagegoal
+ \penalty-\!!tenthousand\relax
+ \fi
+ \fi
+ \else
+ \ifnum#1=\plusthree
+ \flushpagesofar
+ \fi
+ \fi
+ \else
+ \ifnum#1=\plusone\goodbreak\fi
+ \fi
+ \fi}
+
+\def\flushpagesofar
+ {\endgraf
+ \ifdim\pagetotal>\pagegoal
+ \ifdim\dimexpr\pagetotal-\pageshrink\relax>\pagegoal
+ \goodbreak % \penalty0
+ \else
+ \page
+ \fi
+ \else
+ \fi}
+
+\def\testcolumn
+ {\dodoubleempty\dotestcolumn}
+
+\def\dotestcolumn[#1][#2]%
+ {%\relax % needed before \if !
+ \endgraf
+ \ifdim\pagegoal<\maxdimen \ifdim\pagetotal<\pagegoal % \relax
+ \scratchdimen\pagegoal
+ \advance\scratchdimen-\pagetotal
+ \ifdim\lastskip<\parskip
+ \advance\scratchdimen \parskip
+ \fi
+ \ifsecondargument
+ \advance\scratchdimen#2%
+ \fi
+ \getrawnoflines\scratchdimen % raw !
+ % \message{[\number#1>\number\noflines ?}\wait
+ \ifnum#1>\noflines
+ \column
+ \fi
+ \else
+ \penalty-\!!tenthousand % untested ! ! \column
+ \fi \fi}
+
+\let\resetcurrentsectionmarks\relax
+
+% was: \resetsectionmarks\firstsection, zie \handlepagebreak
+
+\def\page{\pagebreak} % the short form of \pagebreak (mult-com one)
+
+\def\resetpagebreak
+ {\global\pagebreakdisabledfalse}
+
+\def\simplifypagebreak
+ {\def\dopagebreak[##1]{\goodbreak}}
+
+\def\disablepagebreaks
+ {\def\dopagebreak[##1]{}}
+
+\def\executepagebreakhandler#1%
+ {\edef\@@pagespecification{#1}%
+ \doifdefinedelse{\??pe:\@@pagespecification}
+ {\getvalue{\??pe:\@@pagespecification}}
+ {\doifdefinedelse{\??pe::\@@pagespecification}
+ {\executepagebreakhandlers{\getvalue{\??pe::\@@pagespecification}}}
+ {\getvalue{\??pe:\s!unknown}}}}
+
+\long\def\installpagebreakhandler#1#2%
+ {\long\setvalue{\??pe:#1}{#2}}
+
+% \definecomplexorsimple\pagebreak
+
+% \def\simplepagebreak
+% {\executepagebreakhandler\v!ja}
+
+% \def\complexpagebreak[#1]% if empty, do nothing and avoid processing,
+% {\flushnotes % see head's; watch how we group
+% \doifsomething{#1}{\bgroup\executepagebreakhandlers{#1}\egroup}}
+
+\unexpanded\def\pagebreak
+ {\dosingleempty\dopagebreak}
+
+\def\dopagebreak[#1]% so, page ornaments are reset after a pagebreak command, unless set
+ {\bgroup
+ \edef\prevrealpageno{\the\realpageno}%
+ \ifcase\pageornamentstate \or
+ % disable reset after shipout
+ \global\chardef\pageornamentstate\plustwo
+ \fi
+ \iffirstargument % or if empty i.e. []
+ \flushnotes\executepagebreakhandlers{#1}%
+ \else % so, no pagebreak when \pagebreak[] ! ! !
+ \flushnotes\executepagebreakhandler\v!yes
+ \fi
+ \ifnum\prevrealpageno<\realpageno
+ \global\chardef\pageornamentstate\zerocount
+ \fi
+ \egroup}
+
+\def\executepagebreakhandlers#1%
+ {\processcommacommand[#1]\executepagebreakhandler}
+
+\installpagebreakhandler \s!dummy
+ {\ejectinsert
+ \gotonextpage
+ \ejectdummypage}
+
+\installpagebreakhandler \v!frame
+ {\page\bgroup\showframe\page[\v!empty]\egroup}
+
+\installpagebreakhandler \s!unknown
+ {\doifinstringelse{+}\@@pagespecification
+ {\ejectinsert
+ \gotonextpage
+ \dorecurse\@@pagespecification\ejectdummypage}
+ {\doifnumberelse\@@pagespecification
+ {\ejectinsert
+ \gotonextpage
+ \doloop
+ {\ifnum\userpageno<\@@pagespecification\relax
+ \ejectdummypage
+ \else
+ \exitloop
+ \fi}}
+ {}}}
+
+\installpagebreakhandler \s!default
+ {} % do nothing if empty
+
+\installpagebreakhandler \v!reset
+ {% better not: \global\chardef\pageornamentstate\zerocount
+ \resetpagebreak}
+
+\installpagebreakhandler \v!disable
+ {\global\pagebreakdisabledtrue}
+
+\installpagebreakhandler \v!yes
+ {\ifpagebreakdisabled\else
+ \ejectinsert
+ \gotonextpage
+ \ifinsidecolumns % this will move to MUL
+ \ejectpage % anders soms geen overgang
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!makeup % ??
+ {\ifpagebreakdisabled\else
+ \eject
+ \fi}
+
+\installpagebreakhandler \v!blank
+ {\ifcase\pageornamentstate
+ \global\chardef\pageornamentstate\plusone
+ \fi}
+
+\installpagebreakhandler \v!no
+ {\ifpagebreakdisabled\else
+ \dosomebreak\nobreak
+ \fi}
+
+\installpagebreakhandler \v!preference
+ {\ifpagebreakdisabled\else
+ \ifinsidecolumns % this will move to MUL
+ \dosomebreak\goodbreak
+ \else
+ \testpage[3][\zeropoint]%
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!bigpreference
+ {\ifpagebreakdisabled\else
+ \ifinsidecolumns % this will move to MUL
+ \dosomebreak\goodbreak
+ \else
+ \testpage[5][\zeropoint]%
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!empty
+ {\ejectinsert
+ \gotonextpage
+ \doifnotvalue{\??tk\v!header\c!state}\v!stop{\setupheader[\c!state=\v!empty]}%
+ \doifnotvalue{\??tk\v!footer\c!state}\v!stop{\setupfooter[\c!state=\v!empty]}%
+ \ejectdummypage}
+
+\installpagebreakhandler \v!left
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \doifbothsidesoverruled{}{\resetcurrentsectionmarks\ejectdummypage}{}}
+
+\installpagebreakhandler \v!right
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \doifbothsidesoverruled{}{}{\resetcurrentsectionmarks\ejectdummypage}}
+
+\installpagebreakhandler \v!even
+ {\page
+ \doifoddpageelse{\resetcurrentsectionmarks\ejectdummypage}\donothing}
+
+\installpagebreakhandler \v!odd
+ {\page
+ \doifoddpageelse\donothing{\resetcurrentsectionmarks\ejectdummypage}}
+
+\installpagebreakhandler \v!quadruple % not yet ok inside columnsets
+ {\ifdoublesided
+ \!!counta\realpageno
+ \!!countb\realpageno
+ \divide\!!counta 4
+ \divide\!!countb 2
+ \ifnum\!!counta=\!!countb
+ \else
+ \executepagebreakhandler\v!yes
+ \executepagebreakhandler\v!empty
+ \executepagebreakhandler\v!empty
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!last
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \relax
+ \doifbothsidesoverruled
+ {\shipoutfacingpage}
+ {}
+ {\noheaderandfooterlines \ejectdummypage}%
+ \filluparrangedpages}
+
+\installpagebreakhandler \v!lastpage % handy for backpage preceded by empty pages
+ {\executepagebreakhandler\v!yes
+ \ifdoublesided
+ \executepagebreakhandler\v!left
+ \executepagebreakhandler\v!empty
+ \executepagebreakhandler\v!empty
+ \fi}
+
+\installpagebreakhandler \v!start
+ {\globallet\shipout\normalshipout}
+
+\installpagebreakhandler \v!stop
+ {\globallet\shipout\noshipout}
+
+% nb: \executepagebreakhandler\v!hoofd in other ones
+
+\installpagebreakhandler \v!header
+ {\doifnotvalue{\??tk\v!header\c!state}\v!stop{\setupheader[\c!state=\v!empty]}}
+
+\installpagebreakhandler \v!footer
+ {\doifnotvalue{\??tk\v!footer\c!state}\v!stop{\setupfooter[\c!state=\v!empty]}}
+
+% \definepagebreak
+% [chapter]
+% [yes,header,right]
+%
+% \setuphead
+% [chapter]
+% [page=chapter,
+% header=empty,
+% footer=chapter]
+%
+% \definepagebreak % untested
+% [lastpage]
+% [left,{empty,right},{empty,left}]
+
+% public page handler, beware: definepage already in use (core-ref)
+%
+% \definepagebreak[instance][forsure]
+% \definepagebreak[forsure][yes,+4]
+
+\def\definepagebreak
+ {\dodoubleargument\dodefinepagebreak}
+
+\def\dodefinepagebreak[#1][#2]% non recursive, meant for simple mappings
+ {\setvalue{\??pe::#1}{#2}}
+
+% hier nog uti blokkeren
+
+% don't change this / test case:
+%
+% \setupbackgrounds[state=repeat]
+% \setupbackgrounds[text][text][background=whatever]
+% \couplepage[chapter][before={\defineoverlay[whatever][ON]}]
+% \setuphead[chapter][before={\pagetype[chapter]}]
+% \chapter{First} \page test \chapter{second} \page test
+
+\long\def\installcolumnbreakhandler#1#2#3% #1=otr-id #2=tag
+ {\long\setvalue{\??cn:#1:#2}{#3}}
+
+\def\definecolumnbreak
+ {\dodoubleargument\dodefinecolumnbreak}
+
+\def\dodefinecolumnbreak[#1][#2]% non recursive, meant for simple mappings
+ {\setvalue{\??cn::#1}{#2}}
+
+%\def\columnbreak
+% {\dosingleempty\docolumnbreak}
+%
+%\def\docolumnbreak[#1]%
+% {\expanded{\nextcolumn[\executeifdefined{\??cn::#1}{#1}]}}
+
+\definecomplexorsimple\columnbreak
+
+\def\simplecolumnbreak
+ {\executecolumnbreakhandler\v!yes}
+
+\def\complexcolumnbreak[#1]% if empty, do nothing and avoid processing
+ {\doifsomething{#1}{\executecolumnbreakhandlers{#1}}}
+
+\def\executecolumnbreakhandlers#1%
+ {\processcommacommand[#1]\executecolumnbreakhandler}
+
+\def\executecolumnbreakhandler#1% here no commalist
+ {\edef\@@columnspecification{#1}%
+ \doifdefinedelse{\??cn:\OTRidentifier:\@@columnspecification}
+ {\getvalue{\??cn:\OTRidentifier:\@@columnspecification}}
+ {\doifdefinedelse{\??cn::\@@columnspecification}
+ {\executecolumnbreakhandlers{\getvalue{\??cn::\@@columnspecification}}}
+ {\getvalue{\??cn:\OTRidentifier:\s!unknown}}}}
+
+%let\nextcolumn\columnbreak
+\let\column \columnbreak
+
+% We don't want spurious last pages (due to left over marks):
+
+\def\noshipout
+ {\writestatus\m!systems{ignoring further shipouts}%
+ \global\advance\realpageno\minusone % else no flush of resources
+ \dowithnextbox{\deadcycles\zerocount}}
+
+% \def\doignorerestoftext
+% {\ifarrangingpages \else \ifnum\textlevel>\zerocount \else
+% \globallet\shipout\noshipout
+% \fi \fi}
+%
+% better:
+
+\def\doignorerestoftext
+ {\ifarrangingpages \else \ifnum\textlevel=\plusone
+ \globallet\shipout\noshipout
+ \fi \fi}
+
+\let\ignorerestoftext\donothing
+
+\prependtoks % only ignore in a symmetrical doc
+ \globallet\ignorerestoftext\doignorerestoftext
+\to \everystarttext
+
+% \appendtoks
+% \ignorerestoftext
+% \to \everylastshipout
+
+\newif\ifpageselected \pageselectedtrue
+\newif\ifselectingpages \selectingpagesfalse
+\newif\ifprocessingpages\processingpagestrue
+
+\let\pageselection \empty
+\let\currentpageselection\empty
+\let\aftershipout \relax
+\let\beforeshipout \relax
+
+\def\dodobeforeshipout#1%
+ {\global\let\beforeshipout\relax
+ \getvalue{\??pg#1\c!before}}
+
+\def\dobeforeshipout
+ {\doifsomething\currentpageselection
+ {\processcommacommand[\currentpageselection]\dodobeforeshipout}}
+
+\def\dododoaftershipout#1%
+ {\global\let\aftershipout\relax
+ \global\let\currentpageselection\empty
+ \getvalue{\??pg#1\c!after}}
+
+\def\dodoaftershipout#1%
+ {\doifelsevalue{\??pg#1\c!option}\v!doublesided
+ {\doifbothsidesoverruled
+ {\dododoaftershipout{#1}}
+ {\dododoaftershipout{#1}}
+ {}}
+ {\dododoaftershipout{#1}}}
+
+\def\doaftershipout
+ {\doifsomething\currentpageselection
+ {\processcommacommand[\currentpageselection]\dodoaftershipout}}
+
+% Dit wordt eigenlijk nooit en moet worden vervangen door
+% het meer algemene mechanisme.
+
+\def\dopagetype[#1]%
+ {\edef\desoortpagina{#1}%
+ \ifx\desoortpagina\empty \else
+ \@EA\doglobal\@EA\addtocommalist\@EA{\desoortpagina}\currentpageselection
+ \ifselectingpages
+ \fullexpandtwoargsafter\doifcommon\desoortpagina\pageselection
+ {\global\pageselectedtrue}%
+ \fi
+ \gdef\beforeshipout{\dobeforeshipout}%
+ \gdef\aftershipout {\doaftershipout}%
+ \fi}
+
+\def\pagetype
+ {\dosingleargument\dopagetype}
+
+\def\docouplepage[#1][#2]%
+ {\getparameters
+ [\??pg]
+ [\c!before=,
+ \c!after=,
+ \c!option=,
+ #2]%
+ \def\docommand##1%
+ {\getparameters
+ [\??pg##1]
+ [\c!before=\@@pgbefore,
+ \c!after=\@@pgafter,
+ \c!option=\@@pgoption]}%
+ \processcommalist[#1]\docommand}%
+
+\def\couplepage
+ {\dodoubleargument\docouplepage}
+
+\def\doprocesspage[#1][#2]%
+ {\processaction
+ [#2]
+ [\v!yes=>\global\processingpagestrue,
+ \v!no=>\global\processingpagesfalse]%
+ \gdef\pageselection{#1}%
+ \global\selectingpagestrue
+ \global\pageselectedfalse}
+
+\def\processpage
+ {\dodoubleargument\doprocesspage}
+
+\def\resetselectiepagina
+ {\ifselectingpages
+ \doifbothsidesoverruled{\global\pageselectedfalse}{}{\global\pageselectedfalse}%
+ \fi}
+
+\newif\ifregistertextareas
+\newif\iftracetextareas
+
+\newbox\registertextbox
+
+% \def\registeredtextarea#1#2#3% #1=lower-dp #2=correct-ht #3=box
+% {\hbox{\box#3}}
+
+\def\enabletextarearegistration{\global\registertextareastrue}
+
+\def\registeredtextarea#1#2#3% #1=lower-dp #2=correct-ht #3=box
+ {\hbox\bgroup
+ \ifregistertextareas \ifx\registerMPtextarea\undefined \else
+ \setbox\registertextbox\null
+ \wd\registertextbox\wd#3%
+ \ht\registertextbox\ht#3%
+ \dp\registertextbox\dp#3%
+ \ifcase#1\or % 1
+ \setbox\registertextbox\hbox{\lower\strutdp\box\registertextbox}%
+ \fi
+ \ifcase#2\or % 1
+ \setbox\registertextbox\hbox{\raise\topskip\hbox{\lower\strutht\box\registertextbox}}%
+ \dp\registertextbox\strutdp
+ \fi
+ \dp\registertextbox\strutdp % needed
+ %\setbox\registertextbox\hbox
+ % {\iftracetextareas\gray\boxrulewidth2pt\ruledhbox\fi
+ % {\registerMPtextarea{\box\registertextbox}}}%
+ \setbox\registertextbox\hbox
+ {\registerMPtextarea{\box\registertextbox}}%
+ \smashbox\registertextbox
+ \box\registertextbox
+ \fi \fi
+ \box#3%
+ \egroup}
+
+%D \macros
+%D {setupoppositeplacing,startopposite}
+%D
+%D \starttyping
+%D \starttext
+%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
+%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
+%D \stoptext
+%D \stoptyping
+
+% Moved from page-mar.tex, made english, cleaned up, but still to be
+% redesigned
+
+\newbox\facingpage
+
+\def\setupoppositeplacing
+ {\dodoubleargument\getparameters[\??np]}
+
+\def\startopposite
+ {\dowithnextboxcontent
+ {\hsize\makeupwidth}%
+ {\global\setbox\facingpage\vbox
+ {\ifvoid\facingpage
+ \@@npbefore
+ \else
+ \@@npinbetween
+ \unvbox\facingpage
+ \fi
+ \box\nextbox}}%
+ \vbox\bgroup}
+
+\def\stopopposite
+ {\egroup}
+
+\def\finishfacingpage
+ {\ifvoid\facingpage\else
+ \global\setbox\facingpage\vbox to \makeupheight
+ {\unvbox\facingpage
+ \@@npafter
+ \vss}%
+ \fi}
+
+\def\shipoutfacingpage
+ {\doif\@@npstate\v!start
+ {\ifvoid\facingpage\else
+ \ifnum\realpageno>\plusone
+ \bgroup
+ \chardef\pageornamentstate\plusone
+ \finishfacingpage
+ \myshipout{\buildpagebody\box\facingpage}%
+ \egroup
+ \else
+ \global\setbox\facingpage\emptybox
+ \fi
+ \fi}}
+
+\setupoppositeplacing
+ [\c!state=\v!start,
+ \c!before=,
+ \c!inbetween=\blank,
+ \c!after=]
+
+\protect \endinput
diff --git a/tex/context/base/page-ini.mkiv b/tex/context/base/page-ini.mkiv
new file mode 100644
index 000000000..4aedf171e
--- /dev/null
+++ b/tex/context/base/page-ini.mkiv
@@ -0,0 +1,1549 @@
+%D \module
+%D [ file=page-ini,
+%D version=2000.10.20,
+%D title=\CONTEXT\ Page Macros,
+%D subtitle=Initializations,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt Page Macros / Initializations}
+
+% still a dutch/english mess
+
+%D This class of modules implements the output routines and
+%D floating body support. Although the modules are relatively
+%D new, the code herein is rather old. This reordering was
+%D needed when column sets were implemented and sharing code
+%D started to make sense.
+
+%D The history shows from the code, since both column
+%D mechanism use a different way of looping over columns.
+
+\unprotect
+
+\def\m!otr{otr}
+
+\chardef\normalpagebox=255
+
+\newbox\pagebox
+
+\ifx\recalculatelayout\undefined
+
+ \let \recalculatelayout \relax
+
+\fi
+
+\ifx\recalculatelogos\undefined
+
+ \let \recalculatelogos \relax
+ \let \addlogobackground \gobbleoneargument %
+
+\fi
+
+\ifx\recalculatebackgrounds\undefined
+
+ \let \recalculatebackgrounds \relax
+ \let \addmainbackground \gobbleoneargument %
+ \let \addtextbackground \gobbleoneargument %
+ \let \addpagebackground \gobbleoneargument %
+ \let \addprintbackground \gobbleoneargument %
+ \let \addstatusinfo \gobbleoneargument %
+
+\fi
+
+\ifx\realpageno\undefined
+
+ \countdef\realpageno = 0 \realpageno = 1
+ \countdef\userpageno = 1 \userpageno = 1
+ \countdef\subpageno = 2 \subpageno = 0 % !!
+ \countdef\arrangeno = 3 \arrangeno = 0 % !!
+
+ \let\pageno\userpageno
+
+\fi
+
+\ifx\realfolio\undefined
+
+ \def\realfolio{\the\realpageno}
+
+\fi
+
+\newcount\nofshipouts
+
+\appendtoks
+ \global\advance\nofshipouts\plusone
+\to \everyaftershipout
+
+% principle:
+%
+% multiple otr's
+%
+% (1) single column, simple routine (old one)
+% (2) multi column, collect and split routine (old one)
+% (3) multi column, page by page (new one, needed for taco)
+% (4) single column, spread handling (for fun)
+% (5) multi column, page by page, spread handling (as challenge)
+%
+% common components
+%
+% (1) float placement
+% (2) float flushing
+% (3) page body building
+% (4) ...
+%
+% ort
+%
+% + balancing
+% - mixed / one / multi / balancetofit
+% + backgrounds
+% + pre / post
+% + distances / heights
+% + ragged / baseline / normal
+% - pos sync
+% - last page
+%
+% - itemize / subtexts -> old mechanism
+%
+% floats
+%
+% - top / bottom / side / page / column / spead
+% - flush / packed flush / current page / next page / area
+%
+% footnotes
+%
+% + carry over pre column / local to column
+% + last column / pre last column / each column
+% - multiple classes
+% - area / page / end
+%
+% areas
+%
+% - top / bottom / mid in spread
+%
+% IMPORTANT
+%
+% switchtobodyfont in between ivm top
+
+% floats:
+%
+% tricky in balancing mode, a la huidige multi columns
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+% messages moved
+
+\ifx\dosetuplayout\undefined % overloaded in page-lay !
+
+ \def\setuplayout{\dodoubleempty\getparameters[\??ly]}
+
+\fi
+
+\ifx\mkprocesscolumncontents\undefined\let\mkprocesscolumncontents\gobbleoneargument\fi
+\ifx\mkprocesspagecontents \undefined\let\mkprocesspagecontents \gobbleoneargument\fi
+\ifx\mkprocessboxcontents \undefined\let\mkprocessboxcontents \gobbleoneargument\fi
+
+\def\normalejectpenalty{-\plustenthousand } \let\ejectpenalty\normalejectpenalty
+\def\normalsuperpenalty{-\plustwentythousand} \let\superpenalty\normalsuperpenalty
+
+%D In case we're not running \ETEX, we need to bypass a
+%D couple of primitives.
+
+% ONE = single column
+% MUL = multi column
+% SET = columns sets
+
+\def\@@OTR{OTR}
+
+\let\OTRdefault\empty
+
+\def\OTRcommand#1%
+ {\csname\@@OTR
+ \ifcsname\@@OTR\OTRidentifier\strippedcsname#1\endcsname
+ \OTRidentifier
+ \else\ifcsname\@@OTR\OTRdefault\strippedcsname#1\endcsname % fallback
+ \OTRdefault
+ \fi\fi
+ \strippedcsname#1\endcsname}
+
+% obsolete
+
+\def\installotr#1% andere naam, beter \connectotr of zo
+ {\def\OTRidentifier{#1}}
+
+\def\activateotr#1#2%
+ {\def\OTRidentifier{#1}%
+ \def\OTRdefault {#2}}
+
+%D The initialization of the \type {\hsize} and \type {\vsize}
+%D depends on the OTR used.
+
+\def\setvsize {\OTRcommand\setvsize}
+\def\sethsize {\OTRcommand\sethsize}
+\def\finalsidefloatoutput {\OTRcommand\finalsidefloatoutput}
+\def\dopagecontents {\OTRcommand\dopagecontents}
+
+\def\dosettopinserts {\OTRcommand\dosettopinserts}
+\def\dosetbotinserts {\OTRcommand\dosetbotinserts}
+\def\dotopinsertions {\OTRcommand\dotopinsertions}
+\def\dobotinsertions {\OTRcommand\dobotinsertions}
+\def\dosetbothinserts {\OTRcommand\dosetbothinserts}
+
+\def\doflushfloats {\OTRcommand\doflushfloats}
+\def\flushfloatbox {\OTRcommand\flushfloatbox}
+\def\docheckiffloatfits {\OTRcommand\docheckiffloatfits}
+
+\def\someherefloat {\OTRcommand\someherefloat}
+\def\somefixdfloat {\OTRcommand\somefixdfloat}
+\def\somepagefloat {\OTRcommand\somepagefloat}
+\def\sometopsfloat {\OTRcommand\sometopsfloat}
+\def\somebotsfloat {\OTRcommand\somebotsfloat}
+\def\somesidefloat {\OTRcommand\somesidefloat}
+
+\def\flushsavedfloats {\OTRcommand\flushsavedfloats}
+
+\def\synchronizehsize {\OTRcommand\synchronizehsize}
+
+\def\gotonextpage {\OTRcommand\gotonextpage }
+\def\gotonextpageX{\OTRcommand\gotonextpageX} % will become obsolete
+
+% beter een \installotr#1 met #1 = macro en auto test
+
+\newif \iftraceotr
+\newif \ifinotr
+\newtoks \mainoutput
+\newcount\otrlevel
+
+% When issuing two \par\penalty-\plustenthousand's, only the first
+% triggers the otr; obscure feature or optimization?
+
+\def\outputcounter{-100010} % -10010
+
+\def\doinvokeoutput
+ {\iftraceotr
+ \expandafter\dodotracedoutput
+ \else
+ \expandafter\dodoinvokeoutput
+ \fi}
+
+\def\outputmessage#1#2#3%
+ {\iftraceotr\writestatus\m!otr{#1 #2 \number#3}\fi}
+
+\def\dodoinvokeoutput#1%
+ {\outputmessage+{special}{#1}%
+ \bgroup\par\penalty#1\relax\egroup
+ \outputmessage-{special}{#1}}
+
+\def\dodotracedoutput#1%
+ {\outputmessage+{traced}{#1/\the\outputpenalty}%
+ \writestatus\m!otr{c:\number\mofcolumns,v:\the\vsize,g:\the\pagegoal,t:\the\pagetotal}%
+ \dodoinvokeoutput{#1}%
+ \writestatus\m!otr{c:\number\mofcolumns,v:\the\vsize,g:\the\pagegoal,t:\the\pagetotal}%
+ \outputmessage-{traced}{#1/\the\outputpenalty}}
+
+\def\installoutput#1#2% \invoke \action
+ {\decrement\outputcounter
+ \edef#1{\noexpand\doinvokeoutput{\outputcounter}}%
+ \setvalue{\@@OTR\outputcounter}{#2}}
+
+\def\invokeoutputroutine
+ {\outputmessage+{trying}\outputpenalty
+ \executeifdefined{\@@OTR\the\outputpenalty}\dodonormaloutput
+ \outputmessage-{trying}\outputpenalty}
+
+\def\dodonormaloutput
+ {\outputmessage+{normal}\outputpenalty
+ \the\OTRcommand\output
+ \outputmessage-{normal}\outputpenalty}
+
+\mainoutput{\invokeoutputroutine} \output{\inotrtrue\the\mainoutput}
+
+%D Some hooks:
+
+\output{\inotrtrue\the\everybeforeoutput\the\mainoutput\the\everyafteroutput}
+
+\ifx\pagediscards\undefined \let\pagediscards\relax \fi
+
+\installoutput\synchronizeoutput % maybe add pagediscards
+ {\ifvoid\normalpagebox\else
+ \unvbox\normalpagebox
+ \pagediscards % maybe not needed ?
+ \fi}
+
+\installoutput\discardpage
+ {\setbox\scratchbox\box\normalpagebox}
+
+%D In order to force consistent use of variables, we
+%D predefine a lot of them here.
+
+%D The next two registers can be used to store pre column
+%D material as well as footnotes or so.
+
+\newbox\precolumnbox \newdimen\precolumnboxheight
+\newbox\postcolumnbox \newdimen\postcolumnboxheight
+
+%D We reserve a counter for the number of columns as well as
+%D the current column. Both are not to be changed by users!
+
+\newcount\nofcolumns \nofcolumns = 1
+\newcount\mofcolumns \mofcolumns = 1
+
+\chardef\maxnofcolumns = 50
+\chardef\allocatednofcolumns = 0
+
+%D The next dimensions reports the final column height
+
+\newdimen\finalcolumnheights
+\newcount\finalcolumnlines
+
+%D During initialization the temporary boxes are allocated.
+%D This enables us to use as much columns as we want, without
+%D exhausting the pool of boxes too fast. We could have packed
+%D them in one box, but we've got enough boxes.
+%D
+%D Two sets of boxes are declared, the txtboxes are used for
+%D the text, the topboxes are for moved column floats.
+
+\def\@col@{@col@}
+
+\def\initializecolumns#1%
+ {\ifnum#1>\maxnofcolumns
+ \showmessage\m!columns1\maxnofcolumns
+ \nofcolumns\maxnofcolumns
+ \else
+ \nofcolumns#1\relax
+ \fi
+ \ifnum\nofcolumns>\allocatednofcolumns
+ \dorecurse\nofcolumns
+ {\ifnum\recurselevel>\allocatednofcolumns\relax
+ % \newbox\next \letgvalue{\@col@-\recurselevel-t}=\next
+ \@EA\newbox\csname\@col@-\recurselevel-t\endcsname % text
+ \@EA\newbox\csname\@col@-\recurselevel-f\endcsname % foot
+ \@EA\newbox\csname\@col@-\recurselevel-h\endcsname % top insert
+ \@EA\newbox\csname\@col@-\recurselevel-l\endcsname % top insert
+ \fi}%
+ \global\chardef\allocatednofcolumns=\nofcolumns
+ \fi}
+
+\def\firstcolumnbox {\columntextbox\plusone}
+\def\currentcolumnbox {\columntextbox\mofcolumns}
+\def\lastcolumnbox {\columntextbox\nofcolumns}
+
+\def\firsttopcolumnbox {\columntopbox \plusone}
+\def\currenttopcolumnbox{\columntopbox \mofcolumns}
+\def\lasttopcolumnbox {\columntopbox \nofcolumns}
+
+\def\columntextbox#1{\csname\@col@-\number#1-t\endcsname}
+\def\columnfootbox#1{\csname\@col@-\number#1-f\endcsname}
+\def\columntopbox #1{\csname\@col@-\number#1-h\endcsname}
+\def\columnbotbox #1{\csname\@col@-\number#1-l\endcsname}
+
+\def\columnsettextbox{\global\setbox\columntextbox}
+\def\columnsetfootbox{\global\setbox\columnfootbox}
+\def\columnsettopbox {\global\setbox\columntopbox}
+\def\columnsetbotbox {\global\setbox\columnbotbox}
+
+\def\columngettextbox{\copy\columntextbox}
+\def\columngetfootbox{\copy\columnfootbox}
+\def\columngettopbox {\copy\columntopbox}
+\def\columngetbotbox {\copy\columnbotbox}
+
+\def\columnerasetextboxes{\dorecurse\allocatednofcolumns{\columnsettextbox\recurselevel\emptybox}}
+\def\columnerasefootboxes{\dorecurse\allocatednofcolumns{\columnsetfootbox\recurselevel\emptybox}}
+\def\columnerasetopboxes {\dorecurse\allocatednofcolumns{\columnsettopbox \recurselevel\emptybox}}
+\def\columnerasebotboxes {\dorecurse\allocatednofcolumns{\columnsetbotbox \recurselevel\emptybox}}
+
+%D Without going in details we present two macro's which handle
+%D the columns. The action which is transfered by the the first
+%D and only parameter can do something with \type
+%D {\currentcolumnbox}. In case of the mid columns, \type
+%D {\firstcolumnbox} and \type {\lastcolumnbox} are handled
+%D outside these macro's.
+
+\def\dohandlecolumn#1%
+ {\mofcolumns\recurselevel
+ \let\currentcolumn\recurselevel
+ #1\relax}
+
+\def\dohandleallcolumns#1%
+ {\dorecurse\nofcolumns{\dohandlecolumn{#1}}}
+
+\def\dohandlerevcolumns#1%
+ {\dostepwiserecurse\nofcolumns\plusone\minusone{\dohandlecolumn{#1}}}
+
+\def\dohandlemidcolumns#1%
+ {\dohandleallcolumns
+ {\ifnum\recurselevel>\plusone
+ \ifnum\recurselevel<\nofcolumns
+ \dohandlecolumn{#1}%
+ \fi
+ \fi}}
+
+%D This register can be used as a temporary storage for page
+%D content.
+
+\newbox\restofpage
+
+%D Features.
+
+\newif\ifintermediatefootnotes
+\newif\ifcarryoverfootnotes %\carryoverfootnotestrue
+\newif\iflastcolumnfootnotes %\lastcolumnfootnotestrue
+\newif\ifbalancecolumns %\balancecolumnstrue
+\newif\ifbalancetoheight %\balancetoheighttrue
+\newif\ifforcecolumngrid \forcecolumngridtrue
+\newif\ifstretchcolumns \stretchcolumnsfalse
+\newif\ifinheritcolumns \inheritcolumnsfalse
+\newif\ifheightencolumns \heightencolumnsfalse
+
+\newif\ifbalancingcolumns
+\newif\ifcollectingcontent
+\newif\ifcolumnoverflow
+\newif\iffinalflushingfloats
+\newif\ifpackflushedfloats \packflushedfloatstrue % for the moment
+
+\newdimen\intercolumnwidth
+\newdimen\localcolumnwidth
+\newdimen\savedpagetotal
+
+\chardef\columndirection=0 % 0:lr 1:rl
+
+\def\minbalancetoplines {1}
+\def\minfreecolumnlines {2}
+
+\newif\ifrecentercolumnbox \recentercolumnboxtrue
+\newif\ifrerecentercolumnbox \rerecentercolumnboxtrue
+\newif\ifpackcolumnfloats \packcolumnfloatstrue
+
+\newbox\collectedpagefloats
+\newbox\collectedleftpagefloats
+\newbox\collectedrightpagefloats
+
+%D The \type {\ifdim} test is needed, because otherwise the
+%D last line of a text end up on top of the baseline instead of
+%D on the baseline, as is the case with preceding pages.
+%D Also, a \type {\vfil} better than a \type {\vfill}.
+
+% to be replaced by \page[now] \page[final] / merged
+
+% \def\eject {\par\penalty-\plustenthousand } % == {\par\break} % plain
+% \def\supereject {\par\penalty-\plustwentythousand} % also plain
+
+\def\eject {\par\ifvmode\penalty\ejectpenalty\fi\resetpagebreak} % == {\par\break} % plain
+\def\supereject {\par\ifvmode\penalty\superpenalty\fi\resetpagebreak} % also plain
+
+\def\doejectpage {\par\ifvmode\ifdim\pagetotal>\pagegoal\else\normalvfil\fi\fi} % pg set to \textheight
+\def\ejectpage {\doejectpage\eject}
+\def\superejectpage{\doejectpage\supereject}
+
+\ifx\bye\undefined \def\bye{\par\vfill\supereject\end} \fi % plain tex command
+
+% floats
+%
+% \def\ejectinsert
+% {\flushnotes
+% \bgroup
+% \noftopfloats\plusthousand
+% \nofbotfloats\zerocount
+% \doflushfloats
+% \egroup}
+
+\def\ejectinsert
+ {\flushnotes
+ \bgroup
+ \noftopfloats\plusthousand
+ \nofbotfloats\zerocount
+ % this is needed in case a float that has been stored
+ % ends up at the current page; this border case occurs when
+ % the calculated room is 'eps' smaller that the room available
+ % when just flushing; so now we have (maybe optional):
+ \pagebaselinecorrection
+ % alas, this is tricky but needed (first surfaced in prikkels)
+ \doflushfloats
+ \egroup}
+
+\def\ejectdummypage
+ {\endgraf \ifvmode
+ \ejectinsert
+ \hardespatie % will be different
+ \vfill
+ \gotonextpage
+ \fi}
+
+\def\beforefinaloutput
+ {}
+
+\def\afterfinaloutput
+ {\forgetall
+ \vskip\zeropoint\relax
+ \ifvoid\normalpagebox \else
+ \unvbox\normalpagebox
+ \penalty\outputpenalty
+ \fi
+ % not really needed, replaced by \flushsavedfloats
+ \ifnum\outputpenalty>\superpenalty \else % better use a proper otr signal
+ \dosupereject
+ \fi
+ % but does not hurt either (we're still in the otr!)
+ \inpagebodytrue % needed for enabling \blank !
+ \flushsavedfloats % was \dosetbothinserts; only otr one !
+ \setvsize % this is needed for interacting components, like floats and multicolumns
+ \adaptfuzzypagegoal} % watch this hack!
+
+\def\dofinaloutput#1#2% \vbox: prevents spurious spaces in every..pagebody
+ {\beforefinaloutput
+ \the\everybeforeshipout % brrr not in shipout
+ \the\pageboundsettings
+ \myshipout{\hbox{\vbox{\dopagebody#1#2\setpagecounters}}}%
+ \the\everyaftershipout
+ \afterfinaloutput
+ \popproperties} % ... and here ...
+
+\def\donofinaloutput#1#2%
+ {\beforefinaloutput
+ \the\everybeforeshipout
+ \setpagecounters
+ \message{[-\the\realpageno]}%
+ \setbox\scratchbox\hbox
+ {%\the\everyshipout % still needed here ?
+ \dopagebody#1#2}%
+ \deadcycles\zerocount
+ \gotonextrealpage
+ \the\everyaftershipout
+ \afterfinaloutput
+ \popproperties} % ... and here
+
+% beware: \ifprocessingpages is in use
+
+\ifx\checkpageversion\undefined \let\checkpageversion\relax \fi % todo: hook into \everybeforeshipout
+\ifx\doflushspread \undefined \let\doflushspread \relax \fi % todo
+
+\def\finaloutput#1#2%
+ {\checkpageversion
+ \ifprocessingpages
+ \ifpageselected
+ \@EAEAEA\dofinaloutput
+ \else
+ \@EAEAEA\donofinaloutput
+ \fi
+ \else
+ \ifpageselected
+ \@EAEAEA\donofinaloutput
+ \else
+ \@EAEAEA\dofinaloutput
+ \fi
+ \fi#1#2%
+ \resetselectiepagina
+ \incrementpagenumber
+ \checkpagedimensions
+ \ifnum\outputpenalty>\superpenalty \else
+ \dosupereject
+ \fi
+ \doflushspread
+ \dopostponeblock}
+
+\def\dooutput
+ {\finaloutput\unvbox\normalpagebox}
+
+\maxdeadcycles=1000
+
+% will be installable tracer; better use chardef
+
+% this needs a real cleanup
+
+\def\doplaceversiontext#1#2%
+ {\doifsomething{#2}
+ {\defconvertedcommand\ascii{#2}%
+ \space#1:\space\ascii\space
+ \!!doneatrue}}
+
+\def\placeversioninfo % nog engels maken
+ {\ifcase\conceptmode
+ % 0 : nothing
+ \or
+ % 1 : simple
+ \vskip\!!sixpoint
+ \hbox to \makeupwidth
+ {\infofont
+ \v!concept:\space\currentdate
+ \hss\reportpagedimensions}%
+ \else
+ % 2/3 : extensive
+ \vskip\!!sixpoint
+ \hbox to \makeupwidth
+ {\infofont
+ \getmessage\m!systems{27}:\space\currentdate\space
+ \doplaceversiontext\v!project \currentproject
+ \doplaceversiontext\v!product \currentproduct
+ \doplaceversiontext\v!component\currentcomponent
+ \if!!donea\else\space\v!file:\space\jobname\fi
+ \hss\reportpagedimensions}%
+ \fi}
+
+% tot hier
+
+\def\doversion[#1]%
+ {\chardef\conceptmode\zerocount
+ \overfullrule\zeropoint
+ \processaction % \v!final=>
+ [#1]
+ [ \v!concept=>\chardef\conceptmode\plusone, % simple banner
+ \v!file=>\chardef\conceptmode\plustwo, % full banner
+ \v!temporary=>\chardef\conceptmode\plusthree % full banner plus
+ \overfullrule5\points]} % info in the margin
+
+\def\version
+ {\dosingleargument\doversion}
+
+\def\addstatusinfo
+ {\ifcase\conceptmode
+ \@EA\gobbleoneargument
+ \else
+ \@EA\doaddstatusinfo
+ \fi}
+
+\def\doaddstatusinfo#1%
+ {\setbox#1\vbox to \paperheight
+ {\vsmashbox#1\box#1%
+ \offinterlineskip
+ \vskip\topspace
+ \hsize\paperwidth
+ \hfill\hbox{\placetestinfo\hskip.5cm}\vss
+ \settexthoffset\hskip\texthoffset % brrrr
+ %\tlap{\placeversioninfo}\vskip.5cm
+ \vbox to 1cm{\vss\placeversioninfo\vss}}}
+
+\def\dotestinfo#1#2#3%
+ {\ifinpagebody\else\ifnum\conceptmode=\plusthree
+ \begingroup
+ \defconvertedcommand\ascii{#3}%
+ \xdef\extratestinfo
+ {#2\space\ascii}%
+ \gdef\totaltestinfo
+ {\global\setbox#1\vbox
+ {\unvbox#1\relax
+ \infofont \setupinterlinespace
+ \hbox
+ {\strut
+ \expanded{\doboundtext{\extratestinfo}{12em}{..}}%
+ \quad}}}%
+ \endgroup
+ \ifinner
+ \aftergroup\totaltestinfo
+ \else
+ \totaltestinfo
+ \fi
+ \fi\fi}
+
+% this will be inserts some day
+
+% \installinsertion\referenceinfobox
+% \installinsertion\registerinfobox
+% \installinsertion\floatinfobox
+
+\newbox\referenceinfobox
+\newbox\registerinfobox
+\newbox\floatinfobox
+
+\def\referenceinfo{\dotestinfo\referenceinfobox}
+\def\registerinfo {\dotestinfo\registerinfobox}
+\def\floatinfo {\dotestinfo\floatinfobox}
+
+\def\placetestinfo
+ {\vbox to \makeupheight
+ {\forgetall
+ \infofont
+ \hsize10em
+ \ifvoid\floatinfobox\else
+ \strut \getmessage\m!systems{24}%
+ \vskip\!!sixpoint
+ \unvbox\floatinfobox
+ \vskip\!!twelvepoint
+ \fi
+ \ifvoid\referenceinfobox\else
+ \strut \getmessage\m!systems{25}%
+ \vskip\!!sixpoint
+ \unvbox\referenceinfobox
+ \vskip\!!twelvepoint
+ \fi
+ \ifvoid\registerinfobox\else
+ \strut \getmessage\m!systems{26}%
+ \vskip\!!sixpoint
+ \unvbox\registerinfobox
+ \fi
+ \vss}}
+
+\version[\v!final]
+
+% bewaren tvb documentatie
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.2\hsize
+% \vsize=2\hsize
+% \ruledvbox to \vsize{\input tufte \par}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern0pt}\hss
+% \ruledvbox to \vsize{\input tufte \par\vfill}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth\vfill}}
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.18\hsize
+% \vsize=2.5\hsize
+% \setbox0=\vbox{\input tufte\relax}%
+% \ruledvbox to \vsize{\unvcopy0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern0pt}\hss
+% \ruledvbox to \vsize{\unvcopy0\vfill}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0\vfill}}
+
+\newtoks\afterpage \newtoks\aftereverypage
+\newtoks\beforepage \newtoks\beforeeverypage
+
+\chardef\showgridstate=0
+
+\def\showgrid
+ {\dosingleempty\doshowgrid}
+
+\def\doshowgrid[#1]%
+ {\chardef\showgridstate \plusone % downward compatible default
+ \chardef\gridboxlinemode \plusone
+ \chardef\gridboxlinenomode\plusone
+ \processallactionsinset
+ [#1]%
+ [ \v!reset=>\chardef\showgridstate \zerocount,
+ \v!bottom=>\chardef\showgridstate \plusone,
+ \v!top=>\chardef\showgridstate \plustwo,
+ \v!none=>\chardef\gridboxlinemode \zerocount,
+ \v!all=>\chardef\gridboxlinemode \plusone,
+ \v!lines=>\chardef\gridboxlinemode \plustwo,
+ \v!frame=>\chardef\gridboxlinemode \plusthree,
+ \v!nonumber=>\chardef\gridboxlinenomode\zerocount,
+ \v!right=>\chardef\gridboxlinenomode\plusone,
+ \v!left=>\chardef\gridboxlinenomode\plustwo]}
+
+\def\buildpagebox#1%
+ {\setbox#1\vbox to \paperheight
+ {\hsize\paperwidth
+ \vskip\topspace
+ \doifbothsides
+ {\hskip\backspace}
+ {\hskip\backspace}
+ {\hskip\paperwidth \hskip-\backspace \hskip-\makeupwidth}%
+ \box#1}%
+ \dp#1\zeropoint}
+
+% \newif\ifpagebodyornaments \pagebodyornamentstrue
+%
+% \appendtoks
+% \global\pagebodyornamentstrue
+% \to \everyaftershipout
+
+\newif\ifarrangingpages \arrangingpagesfalse
+
+\chardef\pageornamentstate\zerocount % 0=on 1=one-off 2=always-off
+
+\def\pagebodyornamentstrue {\chardef\pageornamentstate\zerocount} % for a while
+\def\pagebodyornamentsfalse{\chardef\pageornamentstate\plusone} % for a while
+
+\appendtoks
+ \ifcase\pageornamentstate\or
+ \chardef\pageornamentstate\zerocount
+ \fi
+\to \everyaftershipout
+
+\let\poparrangedpages\relax
+\let\pusharrangedpage\relax
+
+\ifx\shiftprintpagebox\undefined
+ \let\shiftprintpagebox\gobbleoneargument
+ \let\shiftpaperpagebox\gobbleoneargument
+\fi
+
+\ifx\registerpageposition\undefined
+ \let\registerpageposition\gobbleoneargument
+\fi
+
+\def\reportarrangedpage#1%
+ {\showmessage\m!systems
+ {23}{\the\realpageno.\the\pageno\ifnum\subpageno>0 .\the\subpageno\fi,#1}}
+
+\newif\ifsavepagebody \newbox\savedpagebody
+
+% beware, \??ly is used before defined, i.e. bad module design
+
+\setuplayout[\c!method=\v!normal]
+
+\def\buildpagebody#1#2%
+ {\ifsavepagebody\global\setbox\savedpagebody\fi
+ \vbox
+ {\beginrestorecatcodes
+ \forgetall % igv problemen, check: \boxmaxdepth\maxdimen
+ \boxmaxdepth\maxdimen % new
+ \dontcomplain
+ % the following plugin uses and sets pagebox; beware: this
+ % will change and is for my (hh) personal experiments
+ \executeifdefined{\??ly\c!method\@@lymethod}%
+ {\getvalue{\??ly\c!method\v!normal}}#1#2%
+ % the finishing touch
+ \ifcase\pageornamentstate
+ \addpagebackground \pagebox
+ \fi
+ \registerpageposition\pagebox
+ \ifarrangingpages
+ \shiftpaperpagebox \pagebox % \v!paper
+ \else
+ \clippagebox \pagebox
+ \addpagecutmarks \pagebox
+ \replicatepagebox \pagebox
+ \scalepagebox \pagebox
+ \mirrorpaperbox \pagebox
+ \orientpaperbox \pagebox
+ \addpagecolormarks \pagebox
+ \centerpagebox \pagebox
+ \addprintbackground\pagebox
+ \mirrorprintbox \pagebox
+ \orientprintbox \pagebox
+ \shiftprintpagebox \pagebox % \v!page
+ \offsetprintbox \pagebox
+ \negateprintbox \pagebox
+ \fi
+ \box\pagebox
+ \endrestorecatcodes}%
+ \ifsavepagebody\copy\savedpagebody\fi}
+
+\setvalue{\??ly\c!method\v!normal}#1#2%
+ {\setbox\pagebox\vbox
+ {\offinterlineskip
+ \ifcase\pageornamentstate
+ \bgroup % else footnotes get inconsistent font/baseline
+ \dostartattributes\??ly\c!style\c!color\empty
+ \offinterlineskip
+ \gettextboxes
+ \dostopattributes
+ \egroup
+ \fi
+ \getmainbox#1#2}% including footnotes
+ \ifcase\pageornamentstate
+ \addmainbackground \pagebox
+ \addlogobackground \pagebox
+ \fi
+ \buildpagebox \pagebox
+ \addstatusinfo \pagebox}
+
+\def\finishpagebox#1%
+ {\ifarrangingpages
+ \addpagecutmarks #1%
+ \addpagecolormarks#1%
+ \centerpagebox #1%
+ \mirrorprintbox #1%
+ \orientprintbox #1%
+ \offsetprintbox #1%
+ \negateprintbox #1%
+ \fi}
+
+\appendtoks \restoreglobalbodyfont \to \everybeforepagebody
+\appendtoks \restorecolumnsettings \to \everybeforepagebody
+
+\ifx\nestednewbox\undefined \newbox\nestednextbox \fi
+
+\prependtoks \let\nextbox\nestednextbox \to \everybeforepagebody
+
+\def\dopagebody#1#2%
+ {%\getallmarks % now in following token register
+ \the\everybeforepagebody
+ \starttextproperties
+ \gotonextsubpage % nog eens: als in pagina (tbv standaard opmaak)
+ \dontshowboxes % dan hier blokkeren en verderop resetten
+% \shipoutfacingpage
+ \checkmargeblokken
+ \the\beforeeverypage
+ \flushtoks\beforepage
+ \inpagebodytrue\buildpagebody#1#2%
+ \flushtoks\afterpage
+ \the\aftereverypage
+ \resetpagebreak
+ %updatelistreferences % now in aftereverypage
+ \resetlayouttextlines % will go to \aftereverypage
+ \stoptextproperties
+ \the\everyafterpagebody}
+
+\newtoks\pageboundsettings
+
+\prependtoks \initializepaper \to \pageboundsettings
+
+% not here
+
+\newif\ifpagebreakdisabled \pagebreakdisabledfalse
+
+% \chardef\testpagemethod=0 % todo: \testnewpage[method=,lines=,voffset=]
+%
+% \def\testpage {\dotripleempty\dotestpage[\plusone]}
+% \def\testpageonly{\dotripleempty\dotestpage[\plustwo]}
+%
+% \def\dotestpage[#1][#2][#3]%
+% {%\relax % needed before \if
+% \endgraf
+% \ifpagebreakdisabled
+% % do nothing
+% \else
+% %ifnum#1=\plusone\synchronizeoutput\fi
+% \ifdim\pagegoal<\maxdimen \relax
+% \ifdim\pagetotal<\pagegoal \relax
+% \scratchdimen\lineheight
+% \multiply\scratchdimen#2\relax
+% \advance\scratchdimen \pagetotal
+% \ifdim\lastskip<\parskip
+% \advance\scratchdimen \parskip
+% \fi
+% \ifthirdargument
+% \advance\scratchdimen#3\relax
+% \fi
+% \ifcase\testpagemethod
+% \ifdim\scratchdimen>.99\pagegoal
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or
+% \advance\scratchdimen-\pagegoal
+% \ifdim\scratchdimen>-\lineheight
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or
+% \getnoflines\pagegoal
+% \advance\scratchdimen-\noflines\lineheight \relax
+% \ifdim\scratchdimen>-\lineheight
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \or % same as 0 but more accurate
+% \advance\scratchdimen-10\s!sp\relax
+% \ifdim\scratchdimen>\pagegoal
+% \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \fi
+% \else
+% % force page break / new
+% % \vfill\eject % \penalty-\!!tenthousand\relax
+% \fi
+% \else
+% \ifnum#1=\plusone\goodbreak\fi
+% \fi
+% \fi}
+
+\chardef\testpagemethod \zerocount % todo: \testnewpage[method=,lines=,voffset=]
+\chardef\testpagetrigger\zerocount
+
+\def\testpage {\dotripleempty\dotestpage[\plusone ]} %
+\def\testpageonly{\dotripleempty\dotestpage[\plustwo ]} % no penalties added to the mvl
+\def\testpagesync{\dotripleempty\dotestpage[\plusthree]} % force sync
+
+\def\dotestpage[#1][#2][#3]% don't change, only add more methods
+ {\relax % needed before \if
+ \ifpagebreakdisabled
+ \endgraf
+ \else
+ % new from here
+ \ifcase\testpagetrigger
+ \endgraf
+ \or
+ \ifvmode
+ \dosomebreak\allowbreak
+ \else % indeed?
+ \vadjust{\allowbreak}%
+ \endgraf
+ \fi
+ \fi
+ % till here
+ \ifdim\pagegoal<\maxdimen \relax
+ \ifdim\pagetotal<\pagegoal \relax
+ \scratchdimen\lineheight
+ \multiply\scratchdimen#2\relax
+ \advance\scratchdimen \pagetotal
+ \ifdim\lastskip<\parskip
+ \advance\scratchdimen \parskip
+ \fi
+ \ifthirdargument
+ \advance\scratchdimen#3\relax
+ \fi
+ \ifcase\testpagemethod
+ \ifdim\scratchdimen>.99\pagegoal
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or
+ \advance\scratchdimen-\pagegoal
+ \ifdim\scratchdimen>-\lineheight
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or
+ \getnoflines\pagegoal
+ \advance\scratchdimen-\noflines\lineheight \relax
+ \ifdim\scratchdimen>-\lineheight
+ \penalty-\!!tenthousand\relax
+ \fi
+ \or % same as 0 but more accurate
+ \advance\scratchdimen-10\s!sp\relax
+ \ifdim\scratchdimen>\pagegoal
+ \penalty-\!!tenthousand\relax
+ \fi
+ \fi
+ \else
+ \ifnum#1=\plusthree
+ \flushpagesofar
+ \fi
+ \fi
+ \else
+ \ifnum#1=\plusone\goodbreak\fi
+ \fi
+ \fi}
+
+\def\flushpagesofar
+ {\endgraf
+ \ifdim\pagetotal>\pagegoal
+ \ifdim\dimexpr\pagetotal-\pageshrink\relax>\pagegoal
+ \goodbreak % \penalty0
+ \else
+ \page
+ \fi
+ \else
+ \fi}
+
+\def\testcolumn
+ {\dodoubleempty\dotestcolumn}
+
+\def\dotestcolumn[#1][#2]%
+ {%\relax % needed before \if !
+ \endgraf
+ \ifdim\pagegoal<\maxdimen \ifdim\pagetotal<\pagegoal % \relax
+ \scratchdimen\pagegoal
+ \advance\scratchdimen-\pagetotal
+ \ifdim\lastskip<\parskip
+ \advance\scratchdimen \parskip
+ \fi
+ \ifsecondargument
+ \advance\scratchdimen#2%
+ \fi
+ \getrawnoflines\scratchdimen % raw !
+ % \message{[\number#1>\number\noflines ?}\wait
+ \ifnum#1>\noflines
+ \column
+ \fi
+ \else
+ \penalty-\!!tenthousand % untested ! ! \column
+ \fi \fi}
+
+\let\resetcurrentsectionmarks\relax
+
+% was: \resetsectionmarks\firstsection, zie \handlepagebreak
+
+\def\page{\pagebreak} % the short form of \pagebreak (mult-com one)
+
+\def\resetpagebreak
+ {\global\pagebreakdisabledfalse}
+
+\def\simplifypagebreak
+ {\def\dopagebreak[##1]{\goodbreak}}
+
+\def\disablepagebreaks
+ {\def\dopagebreak[##1]{}}
+
+\def\executepagebreakhandler#1%
+ {\edef\@@pagespecification{#1}%
+ \doifdefinedelse{\??pe:\@@pagespecification}
+ {\getvalue{\??pe:\@@pagespecification}}
+ {\doifdefinedelse{\??pe::\@@pagespecification}
+ {\executepagebreakhandlers{\getvalue{\??pe::\@@pagespecification}}}
+ {\getvalue{\??pe:\s!unknown}}}}
+
+\long\def\installpagebreakhandler#1#2%
+ {\long\setvalue{\??pe:#1}{#2}}
+
+% \definecomplexorsimple\pagebreak
+
+% \def\simplepagebreak
+% {\executepagebreakhandler\v!ja}
+
+% \def\complexpagebreak[#1]% if empty, do nothing and avoid processing,
+% {\flushnotes % see head's; watch how we group
+% \doifsomething{#1}{\bgroup\executepagebreakhandlers{#1}\egroup}}
+
+\unexpanded\def\pagebreak
+ {\dosingleempty\dopagebreak}
+
+\def\dopagebreak[#1]% so, page ornaments are reset after a pagebreak command, unless set
+ {\bgroup
+ \edef\prevrealpageno{\the\realpageno}%
+ \ifcase\pageornamentstate \or
+ % disable reset after shipout
+ \global\chardef\pageornamentstate\plustwo
+ \fi
+ \iffirstargument % or if empty i.e. []
+ \flushnotes\executepagebreakhandlers{#1}%
+ \else % so, no pagebreak when \pagebreak[] ! ! !
+ \flushnotes\executepagebreakhandler\v!yes
+ \fi
+ \ifnum\prevrealpageno<\realpageno
+ \global\chardef\pageornamentstate\zerocount
+ \fi
+ \egroup}
+
+\def\executepagebreakhandlers#1%
+ {\processcommacommand[#1]\executepagebreakhandler}
+
+\installpagebreakhandler \s!dummy
+ {\ejectinsert
+ \gotonextpage
+ \ejectdummypage}
+
+\installpagebreakhandler \v!frame
+ {\page\bgroup\showframe\page[\v!empty]\egroup}
+
+\installpagebreakhandler \s!unknown
+ {\doifinstringelse{+}\@@pagespecification
+ {\ejectinsert
+ \gotonextpage
+ \dorecurse\@@pagespecification\ejectdummypage}
+ {\doifnumberelse\@@pagespecification
+ {\ejectinsert
+ \gotonextpage
+ \doloop
+ {\ifnum\userpageno<\@@pagespecification\relax
+ \ejectdummypage
+ \else
+ \exitloop
+ \fi}}
+ {}}}
+
+\installpagebreakhandler \s!default
+ {} % do nothing if empty
+
+\installpagebreakhandler \v!reset
+ {% better not: \global\chardef\pageornamentstate\zerocount
+ \resetpagebreak}
+
+\installpagebreakhandler \v!disable
+ {\global\pagebreakdisabledtrue}
+
+\installpagebreakhandler \v!yes
+ {\ifpagebreakdisabled\else
+ \ejectinsert
+ \gotonextpage
+ \ifinsidecolumns % this will move to MUL
+ \ejectpage % anders soms geen overgang
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!makeup % ??
+ {\ifpagebreakdisabled\else
+ \eject
+ \fi}
+
+\installpagebreakhandler \v!blank
+ {\ifcase\pageornamentstate
+ \global\chardef\pageornamentstate\plusone
+ \fi}
+
+\installpagebreakhandler \v!no
+ {\ifpagebreakdisabled\else
+ \dosomebreak\nobreak
+ \fi}
+
+\installpagebreakhandler \v!preference
+ {\ifpagebreakdisabled\else
+ \ifinsidecolumns % this will move to MUL
+ \dosomebreak\goodbreak
+ \else
+ \testpage[3][\zeropoint]%
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!bigpreference
+ {\ifpagebreakdisabled\else
+ \ifinsidecolumns % this will move to MUL
+ \dosomebreak\goodbreak
+ \else
+ \testpage[5][\zeropoint]%
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!empty
+ {\ejectinsert
+ \gotonextpage
+ \doifnotvalue{\??tk\v!header\c!state}\v!stop{\setupheader[\c!state=\v!empty]}%
+ \doifnotvalue{\??tk\v!footer\c!state}\v!stop{\setupfooter[\c!state=\v!empty]}%
+ \ejectdummypage}
+
+\installpagebreakhandler \v!left
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \doifbothsidesoverruled{}{\resetcurrentsectionmarks\ejectdummypage}{}}
+
+\installpagebreakhandler \v!right
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \doifbothsidesoverruled{}{}{\resetcurrentsectionmarks\ejectdummypage}}
+
+\installpagebreakhandler \v!even
+ {\page
+ \doifoddpageelse{\resetcurrentsectionmarks\ejectdummypage}\donothing}
+
+\installpagebreakhandler \v!odd
+ {\page
+ \doifoddpageelse\donothing{\resetcurrentsectionmarks\ejectdummypage}}
+
+\installpagebreakhandler \v!quadruple % not yet ok inside columnsets
+ {\ifdoublesided
+ \!!counta\realpageno
+ \!!countb\realpageno
+ \divide\!!counta 4
+ \divide\!!countb 2
+ \ifnum\!!counta=\!!countb
+ \else
+ \executepagebreakhandler\v!yes
+ \executepagebreakhandler\v!empty
+ \executepagebreakhandler\v!empty
+ \fi
+ \fi}
+
+\installpagebreakhandler \v!last
+ {\ejectinsert
+ \gotonextpageX % will become \gotonextpage
+ \relax
+ \doifbothsidesoverruled
+ {\shipoutfacingpage}
+ {}
+ {\noheaderandfooterlines \ejectdummypage}%
+ \filluparrangedpages}
+
+\installpagebreakhandler \v!lastpage % handy for backpage preceded by empty pages
+ {\executepagebreakhandler\v!yes
+ \ifdoublesided
+ \executepagebreakhandler\v!left
+ \executepagebreakhandler\v!empty
+ \executepagebreakhandler\v!empty
+ \fi}
+
+\installpagebreakhandler \v!start
+ {\globallet\shipout\normalshipout}
+
+\installpagebreakhandler \v!stop
+ {\globallet\shipout\noshipout}
+
+% nb: \executepagebreakhandler\v!hoofd in other ones
+
+\installpagebreakhandler \v!header
+ {\doifnotvalue{\??tk\v!header\c!state}\v!stop{\setupheader[\c!state=\v!empty]}}
+
+\installpagebreakhandler \v!footer
+ {\doifnotvalue{\??tk\v!footer\c!state}\v!stop{\setupfooter[\c!state=\v!empty]}}
+
+% \definepagebreak
+% [chapter]
+% [yes,header,right]
+%
+% \setuphead
+% [chapter]
+% [page=chapter,
+% header=empty,
+% footer=chapter]
+%
+% \definepagebreak % untested
+% [lastpage]
+% [left,{empty,right},{empty,left}]
+
+% public page handler, beware: definepage already in use (core-ref)
+%
+% \definepagebreak[instance][forsure]
+% \definepagebreak[forsure][yes,+4]
+
+\def\definepagebreak
+ {\dodoubleargument\dodefinepagebreak}
+
+\def\dodefinepagebreak[#1][#2]% non recursive, meant for simple mappings
+ {\setvalue{\??pe::#1}{#2}}
+
+% hier nog uti blokkeren
+
+% don't change this / test case:
+%
+% \setupbackgrounds[state=repeat]
+% \setupbackgrounds[text][text][background=whatever]
+% \couplepage[chapter][before={\defineoverlay[whatever][ON]}]
+% \setuphead[chapter][before={\pagetype[chapter]}]
+% \chapter{First} \page test \chapter{second} \page test
+
+\long\def\installcolumnbreakhandler#1#2#3% #1=otr-id #2=tag
+ {\long\setvalue{\??cn:#1:#2}{#3}}
+
+\def\definecolumnbreak
+ {\dodoubleargument\dodefinecolumnbreak}
+
+\def\dodefinecolumnbreak[#1][#2]% non recursive, meant for simple mappings
+ {\setvalue{\??cn::#1}{#2}}
+
+%\def\columnbreak
+% {\dosingleempty\docolumnbreak}
+%
+%\def\docolumnbreak[#1]%
+% {\expanded{\nextcolumn[\executeifdefined{\??cn::#1}{#1}]}}
+
+\definecomplexorsimple\columnbreak
+
+\def\simplecolumnbreak
+ {\executecolumnbreakhandler\v!yes}
+
+\def\complexcolumnbreak[#1]% if empty, do nothing and avoid processing
+ {\doifsomething{#1}{\executecolumnbreakhandlers{#1}}}
+
+\def\executecolumnbreakhandlers#1%
+ {\processcommacommand[#1]\executecolumnbreakhandler}
+
+\def\executecolumnbreakhandler#1% here no commalist
+ {\edef\@@columnspecification{#1}%
+ \doifdefinedelse{\??cn:\OTRidentifier:\@@columnspecification}
+ {\getvalue{\??cn:\OTRidentifier:\@@columnspecification}}
+ {\doifdefinedelse{\??cn::\@@columnspecification}
+ {\executecolumnbreakhandlers{\getvalue{\??cn::\@@columnspecification}}}
+ {\getvalue{\??cn:\OTRidentifier:\s!unknown}}}}
+
+%let\nextcolumn\columnbreak
+\let\column \columnbreak
+
+% We don't want spurious last pages (due to left over marks):
+
+\def\noshipout
+ {\writestatus\m!systems{ignoring further shipouts}%
+ \global\advance\realpageno\minusone % else no flush of resources
+ \dowithnextbox{\deadcycles\zerocount}}
+
+% \def\doignorerestoftext
+% {\ifarrangingpages \else \ifnum\textlevel>\zerocount \else
+% \globallet\shipout\noshipout
+% \fi \fi}
+%
+% better:
+
+\def\doignorerestoftext
+ {\ifarrangingpages \else \ifnum\textlevel=\plusone
+ \globallet\shipout\noshipout
+ \fi \fi}
+
+\let\ignorerestoftext\donothing
+
+\prependtoks % only ignore in a symmetrical doc
+ \globallet\ignorerestoftext\doignorerestoftext
+\to \everystarttext
+
+% \appendtoks
+% \ignorerestoftext
+% \to \everylastshipout
+
+\newif\ifpageselected \pageselectedtrue
+\newif\ifselectingpages \selectingpagesfalse
+\newif\ifprocessingpages\processingpagestrue
+
+\let\pageselection \empty
+\let\currentpageselection\empty
+\let\aftershipout \relax
+\let\beforeshipout \relax
+
+\def\dodobeforeshipout#1%
+ {\global\let\beforeshipout\relax
+ \getvalue{\??pg#1\c!before}}
+
+\def\dobeforeshipout
+ {\doifsomething\currentpageselection
+ {\processcommacommand[\currentpageselection]\dodobeforeshipout}}
+
+\def\dododoaftershipout#1%
+ {\global\let\aftershipout\relax
+ \global\let\currentpageselection\empty
+ \getvalue{\??pg#1\c!after}}
+
+\def\dodoaftershipout#1%
+ {\doifelsevalue{\??pg#1\c!option}\v!doublesided
+ {\doifbothsidesoverruled
+ {\dododoaftershipout{#1}}
+ {\dododoaftershipout{#1}}
+ {}}
+ {\dododoaftershipout{#1}}}
+
+\def\doaftershipout
+ {\doifsomething\currentpageselection
+ {\processcommacommand[\currentpageselection]\dodoaftershipout}}
+
+% Dit wordt eigenlijk nooit en moet worden vervangen door
+% het meer algemene mechanisme.
+
+\def\dopagetype[#1]%
+ {\edef\desoortpagina{#1}%
+ \ifx\desoortpagina\empty \else
+ \@EA\doglobal\@EA\addtocommalist\@EA{\desoortpagina}\currentpageselection
+ \ifselectingpages
+ \fullexpandtwoargsafter\doifcommon\desoortpagina\pageselection
+ {\global\pageselectedtrue}%
+ \fi
+ \gdef\beforeshipout{\dobeforeshipout}%
+ \gdef\aftershipout {\doaftershipout}%
+ \fi}
+
+\def\pagetype
+ {\dosingleargument\dopagetype}
+
+\def\docouplepage[#1][#2]%
+ {\getparameters
+ [\??pg]
+ [\c!before=,
+ \c!after=,
+ \c!option=,
+ #2]%
+ \def\docommand##1%
+ {\getparameters
+ [\??pg##1]
+ [\c!before=\@@pgbefore,
+ \c!after=\@@pgafter,
+ \c!option=\@@pgoption]}%
+ \processcommalist[#1]\docommand}%
+
+\def\couplepage
+ {\dodoubleargument\docouplepage}
+
+\def\doprocesspage[#1][#2]%
+ {\processaction
+ [#2]
+ [\v!yes=>\global\processingpagestrue,
+ \v!no=>\global\processingpagesfalse]%
+ \gdef\pageselection{#1}%
+ \global\selectingpagestrue
+ \global\pageselectedfalse}
+
+\def\processpage
+ {\dodoubleargument\doprocesspage}
+
+\def\resetselectiepagina
+ {\ifselectingpages
+ \doifbothsidesoverruled{\global\pageselectedfalse}{}{\global\pageselectedfalse}%
+ \fi}
+
+\newif\ifregistertextareas
+\newif\iftracetextareas
+
+\newbox\registertextbox
+
+% \def\registeredtextarea#1#2#3% #1=lower-dp #2=correct-ht #3=box
+% {\hbox{\box#3}}
+
+\def\enabletextarearegistration{\global\registertextareastrue}
+
+\def\registeredtextarea#1#2#3% #1=lower-dp #2=correct-ht #3=box
+ {\hbox\bgroup
+ \ifregistertextareas \ifx\registerMPtextarea\undefined \else
+ \setbox\registertextbox\null
+ \wd\registertextbox\wd#3%
+ \ht\registertextbox\ht#3%
+ \dp\registertextbox\dp#3%
+ \ifcase#1\or % 1
+ \setbox\registertextbox\hbox{\lower\strutdp\box\registertextbox}%
+ \fi
+ \ifcase#2\or % 1
+ \setbox\registertextbox\hbox{\raise\topskip\hbox{\lower\strutht\box\registertextbox}}%
+ \dp\registertextbox\strutdp
+ \fi
+ \dp\registertextbox\strutdp % needed
+ %\setbox\registertextbox\hbox
+ % {\iftracetextareas\gray\boxrulewidth2pt\ruledhbox\fi
+ % {\registerMPtextarea{\box\registertextbox}}}%
+ \setbox\registertextbox\hbox
+ {\registerMPtextarea{\box\registertextbox}}%
+ \smashbox\registertextbox
+ \box\registertextbox
+ \fi \fi
+ \box#3%
+ \egroup}
+
+%D \macros
+%D {setupoppositeplacing,startopposite}
+%D
+%D \starttyping
+%D \starttext
+%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
+%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
+%D \stoptext
+%D \stoptyping
+
+% Moved from page-mar.tex, made english, cleaned up, but still to be
+% redesigned
+
+\newbox\facingpage
+
+\def\setupoppositeplacing
+ {\dodoubleargument\getparameters[\??np]}
+
+\def\startopposite
+ {\dowithnextboxcontent
+ {\hsize\makeupwidth}%
+ {\global\setbox\facingpage\vbox
+ {\ifvoid\facingpage
+ \@@npbefore
+ \else
+ \@@npinbetween
+ \unvbox\facingpage
+ \fi
+ \box\nextbox}}%
+ \vbox\bgroup}
+
+\def\stopopposite
+ {\egroup}
+
+\def\finishfacingpage
+ {\ifvoid\facingpage\else
+ \global\setbox\facingpage\vbox to \makeupheight
+ {\unvbox\facingpage
+ \@@npafter
+ \vss}%
+ \fi}
+
+\def\shipoutfacingpage
+ {\doif\@@npstate\v!start
+ {\ifvoid\facingpage\else
+ \ifnum\realpageno>\plusone
+ \bgroup
+ \chardef\pageornamentstate\plusone
+ \finishfacingpage
+ \myshipout{\buildpagebody\box\facingpage}%
+ \egroup
+ \else
+ \global\setbox\facingpage\emptybox
+ \fi
+ \fi}}
+
+\setupoppositeplacing
+ [\c!state=\v!start,
+ \c!before=,
+ \c!inbetween=\blank,
+ \c!after=]
+
+\protect \endinput
diff --git a/tex/context/base/page-ini.tex b/tex/context/base/page-ini.tex
deleted file mode 100644
index 61cd91b2b..000000000
--- a/tex/context/base/page-ini.tex
+++ /dev/null
@@ -1,2034 +0,0 @@
-%D \module
-%D [ file=page-ini,
-%D version=2000.10.20,
-%D title=\CONTEXT\ Page Macros,
-%D subtitle=Initializations,
-%D author=Hans Hagen,
-%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
-%C
-%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
-%C details.
-
-\writestatus{loading}{Context Page Macros / Initializations}
-
-% still a dutch/english mess
-
-%D This class of modules implements the output routines and
-%D floating body support. Although the modules are relatively
-%D new, the code herein is rather old. This reordering was
-%D needed when column sets were implemented and sharing code
-%D started to make sense.
-
-%D The history shows from the code, since both column
-%D mechanism use a different way of looping over columns.
-
-\unprotect
-
-% message will be distributed
-
-\startmessages dutch library: systems
- title: systeem
- 1: laden hulpfile uitgesteld (typemode)
- 2: -- geladen
-% 3: probeer LaTeX eens
- 4: commando -- is al gedefinieerd
- 5: module -- geladen
- 6: geen module -- gevonden
- 7: module -- reeds geladen
- 8: nieuwe versie hulpfile, tweede run nodig
- 9: -- niet gevonden/geplaatst
- 10: gebruik geen em in --
- 11: aanmaken basale hulpfile
- 12: de hulpfile is niet gesorteerd, gebruik texutil
- 13: markering -- gedefinieerd --
- 14: geforceerde paginaovergang in lijst voor --
- 15: wegschrijven buffer --
- 16: inlezen buffer --
- 17: verbatim inlezen buffer --
- 18: synoniem -- -- bestaat niet
- 19: betekenissen (synoniemen) van -- geladen
- 20: betekenissen (sorteren) van -- geladen
- 21: de hulpfile is niet geladen
- 22: gebruik een goede hulpfile
- 23: -- gearrangeerd op --
- 24: Plaatsblokken
- 25: Verwijzingen
- 26: Registers
- 27: Versie
-\stopmessages
-
-\startmessages english library: systems
- title: system
- 1: loading utility-file postponed (typemode)
- 2: -- loaded
-% 3: try LaTeX
- 4: command -- is already defined
- 5: module -- loaded
- 6: module -- not found
- 7: module -- already loaded
- 8: new version of utility file, second pass needed
- 9: -- not found/processed
- 10: don't use em in --
- 11: building simple util
- 12: the utility-file is not sorted, use texutil
- 13: mark -- defined --
- 14: forced newpage in list at --
- 15: saving buffer --
- 16: typesetting buffer --
- 17: typesetting verbatim buffer --
- 18: synonym -- -- does not exist
- 19: meaning (synonyms) of -- loaded
- 20: meaning (sorts) of -- loaded
- 21: no utility data is loaded
- 22: use a valid utilityfile
- 23: -- arranged at --
- 24: Floatblocks
- 25: References
- 26: Registers
- 27: Version
-\stopmessages
-
-\startmessages german library: systems
- title: system
- 1: Laden der Hilfsdatei aufgeschoben (Eingabe-Modus)
- 2: -- geladen
-% 3: Versuche LaTeX
- 4: Befehl -- ist bereits definiert
- 5: Modul -- geladen
- 6: Modul -- gefunden
- 7: Modul -- bereits geladen
- 8: Neue Version der Hilfsdatei, zweiter Durchlauf benoetigt
- 9: -- nicht gefunden/verarbeitet
- 10: Benutzte kein em in --
- 11: Erstelle einfache Hilfdatei
- 12: Die Hilfdatei ist nicht sortiert, verwende texutil
- 13: Beschriftung -- definiert --
- 14: Erzwungendes Seitenumbruch in Liste bei --
- 15: Speichere Buffer --
- 16: Setzte Buffer --
- 17: Setzte tippen-Buffer --
- 18: Synonym -- -- existiert nicht
- 19: Bedeutung (synonyme) von -- geladen
- 20: Bedeutung (sortieren) von -- geladen
- 21: Die Hilfsdatei ist nicht geladen
- 22: Benoetige gueltige Hilfsdateie
- 23: -- angeordnet auf --
- 24: Fliessbloecke
- 25: Referenzen
- 26: Register
- 27: Version
-\stopmessages
-
-\startmessages czech library: systems
- title: system
- 1: nacteni pomocneho souboru odlozeno (typemode)
- 2: -- nacteno
-% 3: zkuste LaTeX
- 4: prikaz -- je jiz definovan
- 5: makra z -- nactena
- 6: zadna makra v -- nenalezena
- 7: makra z -- jsou jiz nactena
- 8: nova verze pomocneho souboru, je treba druheho behu
- 9: -- nenalezeno/nezpracovano
- 10: nepouzivejte em v --
- 11: vytvarim jednoduchy pomocny soubor
- 12: pomosny soubor neni setriden, pouzijte texutil
- 13: znacka -- definovana --
- 14: vynucena nova stranka v seznamu na --
- 15: uklada se buffer --
- 16: sazi se buffer --
- 17: sazi se doslovny (verbatim) buffer --
- 18: synonymum -- -- neexistuje
- 19: vyznam (synonyma) -- nacten
- 20: vyznam (trideni) -- nacten
- 21: pomocny soubor necten
- 22: pouzijte platny pomocny soubor
- 23: -- upraveno na --
- 24: plovouci bloky
- 25: reference
- 26: registry
- 27: verze
-\stopmessages
-
-\startmessages italian library: systems
- title: sistema
- 1: caricamento dei file supplementari posticipato (typemode)
- 2: -- caricato
-% 3: provare LaTeX
- 4: comando -- già definito
- 5: macro del modulo -- caricate
- 6: nessuna macro trovata nel modulo --
- 7: macro del modulo -- già caricate
- 8: nuova versione del file supplementare, seconda passata necessaria
- 9: -- non trovato/elaborato
- 10: non usare em in --
- 11: costruzione di un semplice supplemento
- 12: file di supplemento non ordinato, usare texutil
- 13: marcatura -- definita --
- 14: nuova pagina obbligata in lista a --
- 15: salvataggio del buffer --
- 16: composizione del buffer --
- 17: composizione verbatim del buffer --
- 18: sinonimo -- -- non esistente
- 19: significato (sinonimi) di -- caricato
- 20: significato (specie) di -- caricato
- 21: nessuna informazione supplementare caricata
- 22: usare un file supplementare valido
- 23: -- sistemato a --
- 24: Oggetti mobili
- 25: Riferimenti
- 26: Registri
- 27: Versione
-\stopmessages
-
-\startmessages norwegian library: systems
- title: system
- 1: innlesning av hjelpefila utsatt (typemode)
- 2: -- er lest inn
-% 3: forsøker LaTeX
- 4: kommando -- er allerede definert
- 5: makroene i modul -- er lest inn
- 6: ingen makroer funnet i modul ---
- 7: makroene i modul -- er allerede lest inn
- 8: ny versjon av hjelpefil, andre gjennomkjøring nødvendig
- 9: -- ikke funnet/behandlet
- 10: ikke bruk em i --
- 11: lager enkel hjelpefil
- 12: hjelpefila er ikke sortert, bruk texutil
- 13: markering -- definert --
- 14: tvunget sideskift i liste ved --
- 15: lagrer Buffer --
- 16: tegnsetter buffer --
- 17: tegnsetter verbatim-buffer --
- 18: synonym -- -- eksisterer ikke
- 19: betydning (synonymer) av -- er lest inn
- 20: betydning (sorterer) av -- er lest inn
- 21: hjelpefila er ikke lest inn
- 22: bruk en gyldig hjelpefil
- 23: -- arrangert på --
- 24: Flytblokker
- 25: Referanser
- 26: Registere
- 27: Versjon
-\stopmessages
-
-\startmessages romanian library: systems
- title: sistem
- 1: se incarca utilitarul-fisierul este amanat (typemode)
- 2: -- s-a incarcat
-% 3: incercati LaTeX
- 4: comanda -- este deja definita
- 5: macro-urile din modulul -- s-au incarcat
- 6: nu s-au gasit macro-uri in modulul --
- 7: macro-urile din modulul -- s-au incarcat deja
- 8: o noua versiune de fisier utilitar, este necesara o noua trecere
- 9: -- nu este gasit/procesat
- 10: nu folositi em in --
- 11: se creeaza un utilitar simplu
- 12: fisierul utilitar nu este sortat, folositi texutil
- 13: marcajul -- definit --
- 14: s-a fortat trecere pa pagina noua in lista la --
- 15: buffer salvat --
- 16: buffer-ul -- s-a cules
- 17: se culege buffer-ul verbatim --
- 18: sinonimul -- -- nu exista
- 19: intelesul (sinonimele) pentru -- incarcat
- 20: intelesul (ordinea) pentru -- incarcat
- 21: nici o data utilitara nu este incarcata
- 22: folositi un fisier utilitar valid
- 23: -- aranjat la --
- 24: Blocuri
- 25: Referinte
- 26: Registri
- 27: Versiune
-\stopmessages
-
-\startmessages french library: systems
- title: système
- 1: chargement de fichier utilitaire reporté (typemode)
- 2: -- chargé
-% 3: try LaTeX
- 4: la commande -- est déjà définie
- 5: module -- chargé
- 6: module -- non trouvé
- 7: module -- déjà chargé
- 8: nouvelle version de fichier utilitaire, seconde passe nécessaire
- 9: -- non trouvé/traité
- 10: n'utilisez pas em dans --
- 11: construction util simple
- 12: le fichier utilitaire n'est pas trié, utilise texutil
- 13: marquage -- defini --
- 14: nouvellepage forcée dans la liste à --
- 15: sauvegarde du tampon (buffer) --
- 16: composition du tampon (buffer) --
- 17: composition textuelle du tampon (buffer) --
- 18: le synonyme -- -- n'existe pas
- 19: signification (synonymes) de -- chargée
- 20: signification (tris) de -- chargée
- 21: pas de données utilitaires chargées
- 22: utilise un fichier utilitaire valide
- 23: -- arrangé à --
- 24: blocsflottants
- 25: Réferences
- 26: Registres
- 27: Version
-\stopmessages
-
-\startmessages dutch library: layouts
- title: layout
- 1: teksthoogte aangepast met -- op pagina --
- 2: -- maal uitgestelde tekst tussengevoegd
- 3: -- maal tekst plaatsen uitstellen
- 4: margeblokken actief
- 5: margeblokken inactief
- 6: subpagina reeks -- verwerkt (aantal --)
-% 7: beeldmerken berekenen
-% 8: achtergronden berekenen
- 10: -- en -- tellen niet op tot 1.0
- 11: interlinie -- niet toegestaan in gridmode
-\stopmessages
-
-\startmessages english library: layouts
- title: layout
- 1: textheight adapted with -- at page --
- 2: -- times postponed text placed
- 3: -- times text postponed
- 4: marginblocks active
- 5: marginblocks inactive
- 6: subpage set -- processed (size --)
-% 7: calculating logospace
-% 8: calculating backgrounds
- 10: -- and -- don't add up to 1.0
- 11: spacing -- not permitted in gridmode
-\stopmessages
-
-\startmessages german library: layouts
- title: Layout
- 1: Texthoehe angepasst mit -- auf Seite --
- 2: -- mal verschobener Text plaziert
- 3: -- mal Text verschoben
- 4: marginalbloecke aktiv
- 5: marginalbloecke inaktiv
- 6: Unterseitenfolge -- verarbeitet (Groesse --)
-% 7: berechne Platz des Logo
-% 8: berechne Hintergrund
- 10: -- und -- ergeben zusammen nicht 1.0
- 11: Zwischenraum -- nicht im Grittermoduserlau
-\stopmessages
-
-\startmessages czech library: layouts
- title: layout
- 1: vyska textu prizpusobena s -- na strane --
- 2: -- krat odlozeny text umisten
- 3: -- krat text odlozen
- 4: okrajove bloky aktivni
- 5: okrajove bloky neaktivni
- 6: sada stran -- zpracovana (velikost --)
-% 7: pocita se misto pro logo
-% 8: pocita se pozadi
- 10: -- a -- nedava dohromady 1.0
- 11: svisla mezera -- neni povolena v pevnem radkovem rejstriku
-\stopmessages
-
-\startmessages italian library: layouts
- title: layout
- 1: altezza del testo adattata con -- a pagina --
- 2: posizionato testo posticipato -- volte
- 3: testo posticipato -- volte
- 4: blocchi in margine attivi
- 5: blocchi in margine inattivi
- 6: gruppo di sottopagine -- elaborato (dimensione --)
-% 7: calcolo dello spazio per logo
-% 8: calcolo dello sfondo
- 10: -- e -- non sommano a 1.0
- 11: spaziatura -- non permessa in modo griglia
-\stopmessages
-
-\startmessages norwegian library: layouts
- title: layout
- 1: teksthøyde tilpasset med -- på side --
- 2: -- ganger forskjøvet tekst plassert
- 3: -- ganger tekst forskjøvet
- 4: margblokker aktive
- 5: margblokker inaktive
- 6: delside sett -- behandlet (størrelse --)
-% 7: beregner plass for logo
-% 8: beregner bakgrunn
- 10: -- og -- er ikke 1.0 til sammen
- 11: mellomrom -- ikke tillatt i gridmodus
-\stopmessages
-
-\startmessages romanian library: layouts
- title: aranjamente
- 1: textheight adaptat cu -- la pagina --
- 2: textul amanat de -- ori a fost plasat
- 3: textul amanat de -- ori
- 4: blocuri marginale active
- 5: blocuri marginale inactive
- 6: setul -- de subpagini procesat (dimensiunea --)
-% 7: se calculeaza spatiul pentru logo
-% 8: se calculeaza fundalurile
- 10: -- si -- nu se adauga pana la 1.0
- 11: spatierea -- nu este permisa in gridmode
-\stopmessages
-
-\startmessages french library: layouts
- title: calque
- 1: hauteurtexte adaptée avec -- à la page --
- 2: -- times postponed text placed
- 3: -- times text postponed
- 4: blocsmarge actifs
- 5: blocsmarge inactifs
- 6: jeu de souspage -- traité (taille --)
-% 7: calculating logospace
-% 8: calculating backgrounds
- 10: -- et -- ne sont pas ajoutés à 1.0
- 11: espacement -- non permis en modegrille
-\stopmessages
-
-\def\m!otr{otr}
-
-\chardef\normalpagebox=255
-
-\newbox\pagebox
-
-\ifx\recalculatelayout\undefined
-
- \let \recalculatelayout \relax
-
-\fi
-
-\ifx\recalculatelogos\undefined
-
- \let \recalculatelogos \relax
- \let \addlogobackground \gobbleoneargument %
-
-\fi
-
-\ifx\recalculatebackgrounds\undefined
-
- \let \recalculatebackgrounds \relax
- \let \addmainbackground \gobbleoneargument %
- \let \addtextbackground \gobbleoneargument %
- \let \addpagebackground \gobbleoneargument %